import java.util.*; public class Rand_bob { public static Scanner in; public static int p, n[]; public static void main(String[] args) { in = new Scanner(System.in); p = in.nextInt(); int lim = (int)Math.ceil(p/40.)+1; n = new int[p]; for (int i = 0; i < p; i++) { n[i] = in.nextInt(); } int[] ab, ac, bc; // "x" in a(g1)b(g2)x, a(g1)x(g2)c, x(g1)b(g2)c int[] count; // # occurrences of a(g1)b(g2)c int[] start; // first occurrence of a(g1)b(g2)c ab = new int[100]; ac = new int[100]; bc = new int[100]; count = new int[1000]; start = new int[1000]; // Over all correlations, the earliest so far: int bests = p, bestg1 = p, bestg2 = p, besta = -1, bestb = -1, bestc = -1; for (int g1 = 1; g1 < p; g1++) { // gap between a and b for (int g2 = 1; g2 < p-g1; g2++) { // gap between b and c Arrays.fill(ab,-1); Arrays.fill(ac,-1); Arrays.fill(bc,-1); Arrays.fill(count,0); Arrays.fill(start,0); for (int i = 0; i < p-g1-g2; i++) { int a = n[i], b = n[i+g1], c = n[i+g1+g2]; // all three arrays should be consistent: if (ab[a*10+b] == -1 && bc[b*10+c] == -1 && ac[a*10+c] == -1) { ab[a*10+b] = c; bc[b*10+c] = a; ac[a*10+c] = b; count[a*100+b*10+c] = 1; start[a*100+b*10+c] = i; // first occurrence of this triple } else { if (ab[a*10+b] == c && bc[b*10+c] == a && ac[a*10+c] == b) { count[a*100+b*10+c]++; } else { // kill counts for inconsistent count[a*100+b*10+c] = -p; if (ab[a*10+b] >= 0) count[a*100+b*10+ab[a*10+b]] = -p; if (bc[b*10+c] >= 0) count[bc[b*10+c]*100+b*10+c] = -p; if (ac[a*10+c] >= 0) count[a*100+ac[a*10+c]*10+c] = -p; } } } // now we have to find the earliest starting location: int min = p; for (int i = 0; i < 10; i++) { for (int j = 0; j < 10; j++) { if (ab[i*10+j] >= 0) { int c = ab[i*10+j]; int s = start[i*100+j*10+c]; int t = count[i*100+j*10+c]; if (t >= lim && s <= bests) { if (s < bests || (s == bests && g1 < bestg1)) { bests = s; besta = i; bestb = j; bestc = c; bestg1 = g1; bestg2 = g2; } } } } } } } if (bests == p) { System.out.println("random sequence"); } else { System.out.println("triple correlation "+besta+"("+bestg1+")"+bestb +"("+bestg2+")"+bestc+" found"); } } }