#abc268c. [abc268_c]Chinese Restaurant

[abc268_c]Chinese Restaurant

题目描述

Person 00, Person 11, \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)modN(i+1) \bmod N.

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

What is amodma \bmod m? For an integer aa and a positive integer mm, amodma \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.)

约束条件

  • 3N2×1053 \leq N \leq 2 \times 10^5
  • 0piN10 \leq p_i \leq N-1
  • 如果 iji \neq j,则 pipjp_i \neq p_j
  • 输入中的所有值都是整数。

输入

从标准输入读入输入数据。

输入格式如下:

NN p0p_0 \ldots pN1p_{N-1}

输出

将结果输出到标准输出。


示例输入 1

4
1 2 0 3

示例输出 1

4

下图展示了一次操作后的桌子状态。

这里有四个满意的人:

  • 人 0 满意,因为盘子 0 在人 3 的前面 (=(01)mod4=(0-1) \bmod 4);
  • 人 1 满意,因为盘子 1 在人 1 的前面 (=1=1);
  • 人 2 满意,因为盘子 2 在人 2 的前面 (=2=2);
  • 人 3 满意,因为盘子 3 在人 0 的前面 (=(3+1)mod4=(3+1) \bmod 4)。

不能有五个或更多满意的人,因此答案是 4。

示例输入 2

3
0 1 2

示例输出 2

3

示例输入 3

10
3 9 6 1 7 2 8 0 5 4

示例输出 3

5