#abc268c. [abc268_c]Chinese Restaurant

[abc268_c]Chinese Restaurant

Problem Statement

Person 00, Person 11, ldots\\ldots, and Person (N1)(N-1) are sitting around a turntable in their counterclockwise order, evenly spaced. Dish pip_i is in front of Person ii on the table.
You may perform the following operation 00 or more times:

  • Rotate the turntable by one NN-th of a counterclockwise turn. As a result, the dish that was in front of Person ii right before the rotation is now in front of Person (i+1)bmodN(i+1) \\bmod N.

When you are finished, Person ii is happy if Dish ii is in front of Person (i1)bmodN(i-1) \\bmod N, Person ii, or Person (i+1)bmodN(i+1) \\bmod N.
Find the maximum possible number of happy people.

What is abmodma \\bmod m? For an integer aa and a positive integer mm, abmodma \\bmod m denotes the integer xx between 00 and (m1)(m-1) (inclusive) such that (ax)(a-x) is a multiple of mm. (It can be proved that such xx is unique.)

Constraints

  • 3leqNleq2times1053 \\leq N \\leq 2 \\times 10^5
  • 0leqpileqN10 \\leq p_i \\leq N-1
  • pineqpjp_i \\neq p_j if ineqji \\neq j.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN p0p_0 ldots\\ldots pN1p_{N-1}

Output

Print the answer.


Sample Input 1

4
1 2 0 3

Sample Output 1

4

The figure below shows the table after one operation.

Here, there are four happy people:

  • Person 00 is happy because Dish 00 is in front of Person 3(=(01)bmod4)3\\ (=(0-1) \\bmod 4);
  • Person 11 is happy because Dish 11 is in front of Person 1(=1)1\\ (=1);
  • Person 22 is happy because Dish 22 is in front of Person 2(=2)2\\ (=2);
  • Person 33 is happy because Dish 33 is in front of Person 0(=(3+1)bmod4)0\\ (=(3+1) \\bmod 4).

There cannot be five or more happy people, so the answer is 44.


Sample Input 2

3
0 1 2

Sample Output 2

3

Sample Input 3

10
3 9 6 1 7 2 8 0 5 4

Sample Output 3

5