#include #include using namespace std; const int MAXSIZE = 1000; int main() { int p, n[MAXSIZE]; cin >> p; int lim = ceil(p/40.)+1; for (int i = 0; i < p; i++) { cin >> n[i]; } int ab[100], ac[100], bc[100]; // "x" in a(g1)b(g2)x, a(g1)x(g2)c, x(g1)b(g2)c int count[MAXSIZE]; // # occurrences of a(g1)b(g2)c int start[MAXSIZE]; // first occurrence of a(g1)b(g2)c // 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 for(int i=0; i<100; i++) ab[i] = ac[i] = bc[i] = -1; for(int i=0; i= 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) { cout << "random sequence" << endl; } else { cout << "triple correlation " << besta << "(" << bestg1 << ")" << bestb << "(" << bestg2 << ")" << bestc << " found" << endl; } }