#abc268c. [abc268_c]Chinese Restaurant
[abc268_c]Chinese Restaurant
题目描述
Person , Person , , and Person are sitting around a turntable in their counterclockwise order, evenly spaced. Dish is in front of Person on the table.
You may perform the following operation or more times:
- Rotate the turntable by one -th of a counterclockwise turn. As a result, the dish that was in front of Person right before the rotation is now in front of Person .
When you are finished, Person is happy if Dish is in front of Person , Person , or Person .
Find the maximum possible number of happy people.
What is ? For an integer and a positive integer , denotes the integer between and (inclusive) such that is a multiple of . (It can be proved that such is unique.)
约束条件
- 如果 ,则
- 输入中的所有值都是整数。
输入
从标准输入读入输入数据。
输入格式如下:
输出
将结果输出到标准输出。
示例输入 1
4
1 2 0 3
示例输出 1
4
下图展示了一次操作后的桌子状态。
这里有四个满意的人:
- 人 0 满意,因为盘子 0 在人 3 的前面 ();
- 人 1 满意,因为盘子 1 在人 1 的前面 ();
- 人 2 满意,因为盘子 2 在人 2 的前面 ();
- 人 3 满意,因为盘子 3 在人 0 的前面 ()。
不能有五个或更多满意的人,因此答案是 4。
示例输入 2
3
0 1 2
示例输出 2
3
示例输入 3
10
3 9 6 1 7 2 8 0 5 4
示例输出 3
5