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,3,2,3,0,1,2,3,2,0,3,2,1,0,3,0,2,0,3,1,2,3,0,2,3,2,1,3,2,0,3,2,3,1,0,2,0,3,0,1,3,0,3,2,1,0,3,1,0,1,2,3}, {0,1,0,2,0,1,3,1,2,1,0,2,1,2,3,1,0,1,2,0,1,0,3,2,0,2,1,0,2,0,3,0,1,2,3,2,0,3,2,1,3,2,3,0,2,3,1,2,0,3,0,2,0,1,3,2,0,2,1,0,2,3,1,0,1,2,0,1,0,3,0,2,1,3,1,0,3,1,2,3,1,3,0,1,3,2,1,0,3,0,1,0,2,3,1,0,3,1,3,2,0,1,3,1,2,1,3,0,2,3,1,2,3,2,0,3,2,1,3,2,3,0,1,2,1,3,1,0,2,0,1,0,2,3,2,1,2,0,3,1,3,2,1,3,0,1,3,1,2,3,1,0,3,2,1,2,3,2,0,1,3,2,1,3,1,0,2,3,1,3,0,3,1,2,0,1,3,0,1,0,2,1,0,3,1,0,1,2,3,0,3,1,3,2,0,2,3,2,0,1,0,3,0,2,1,3,1,0,3,1,2,3,1,3,0,1,3,2,1,0,3,0,1,0,2,3,1,0,1,2,0,1,3,2,0,2,1,2,0,3,1,0,2,1,0,1,3,0,1,2,0,1,0,3,2,1,2,0,2,3,1,3,2,3,0,1,2,3,2,0,3,2,1,0,3,0,2,0,3,1,2,3,0,2,3,2,1,3,2,0,3,2,3,1,0,2,0,3,0,1,3,0,3,2,1,0,3,1,0,1,2,3}}; int i, j, k, lim, mot[1000000], code[1000000], tt, s, x; void date(){ fflush(stdout); system("date \"+\%d/\%m/\%Y \%H/\%M/\%S\""); } int ceil32(int a, int b){ return (a+b-1)/b; } int rep(int *m, int i, int n, int d, int plus, int lon){ int x, y; for(; (x = ceil32(lon*n+plus, d)) <= i+1; lon++){ for(y = i-lon; (y >= 0) && (m[y] == m[y+lon]); y--); if(i-y >= x) return 0; } return 1; }//*/ void usage(){ printf("Usage: ch_rep lim\n"); exit(0); } int main(int ac, char **av){ if(ac != 2) usage(); lim = atoi(av[1]); for(*code = x = 0; ;) if(!rep(code, x, 6, 5, 1, 1)){ ici: while(code[x] == 5) if(!x--){ printf("OK\n"); return 1; } code[x]++; }else{ for(k = 0; k < 312; k++){ mot[312*x+k] = morph[code[x]][k]; if(!rep(mot, 312*x+k, 5, 4, 1, 9)){ printf("non\n"); return 0; } } if(x == lim-1) goto ici; else code[++x] = 0; } }