UKSPC Practice Problems » Am I sorted?
 Source

driver.c
,driver.cpp
, ordriver.java
 Input
 standard input
 Output
 standard output
We say that an array A[0..m1] of m real numbers is ksorted if for every i=0..m1 such that i+k<m the following holds: A[i]<= A[i+k]. k is a positive integer. For example, an increasing sequence of any length is 1sorted. Sequence 2,1,4,3,6,5,8,7 is 2sorted and also 4sorted, but not 1sorted.
Given a sequence of n numbers your task is to find the smallest k>1 such that the sequence is ksorted. If such k does not exist we say that the sequence is 0sorted. Input consists of a number of lines starting with the value of m<10000 followed by m numbers, one per line. Numbers may be repeated. Output gives the smallest value of k.
Example Input
 8
 2.0
 1
 4.0
 3.0
 6
 5
 8.0
 7.0
Example Output
 2
Example Input
 5
 10
 8
 6
 4
 2
Example Input
 0