NEED HELP IN PERIODIC

Let's define a periodic infinite sequence S (0-indexed) with period K using the formula Si=(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?

Example Input
3
3
-1 -1 -1
5
1 -1 -1 4 1
4
4 6 7 -1
Example Output
inf
4
impossible
anyone please give some hint to solve this problem
Topic archived. No new replies allowed.