Chef and Periodic Sequence
All submissions for this problem are available.###Read problems statements in [Hindi](http://www.codechef.com/download/translated/S191ATST/hindi/PERIODIC.pdf), [Mandarin chinese](http://www.codechef.com/download/translated/S191ATST/mandarin/PERIODIC.pdf), [Russian](http://www.codechef.com/download/translated/S191ATST/russian/PERIODIC.pdf), [Vietnamese](http://www.codechef.com/download/translated/S191ATST/vietnamese/PERIODIC...) and [Bengali](http://www.codechef.com/download/translated/S191ATST/bengali/PERIODIC.pdf) as well. Let's define a periodic infinite sequence $S$ ($0$-indexed) with period $K$ using the formula $S_i = (i \% K) + 1$. Chef has found a sequence of positive integers $A$ with length $N$ buried underground. He suspects that it is a contiguous subsequence of some periodic sequence. Unfortunately, some elements of $A$ are unreadable. Can you tell Chef the longest possible period $K$ of an infinite periodic sequence which contains $A$ (after suitably filling in the unreadable elements) as a contiguous subsequence? ### Input - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $A_1, A_2, \dots, A_N$. Unreadable elements are denoted by $-1$. ### Output For each test case, print a single line. - If the period can be arbitrarily large, this line should contain a single string `"inf"`. - Otherwise, if $A$ cannot be a contiguous subsequence of a periodic sequence, it should contain a single string `"impossible"`. - Otherwise, it should contain a single integer — the maximum possible period. ### Constraints - $1 \le T \le 100$ - $2 \le N \le 10^5$ - the sum of $N$ over all test cases does not exceed $10^6$ - for each valid $i$, $1 \le A_i \le 10^6$ or $A_i = -1$ ### Subtasks **Subtask #1 (50 points):** - $2 \le N \le 1,000$ - the sum of $N$ over all test cases does not exceed $10,000$ **Subtask #2 (50 points):** original constraints ### Example Input ``` 3 3 -1 -1 -1 5 1 -1 -1 4 1 4 4 6 7 -1 ``` ### Example Output ``` inf 4 impossible ```
|Tags||easy-medium, gcd, kingofnumbers, pattern, sequences, snck1a19, taran_1407|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.