#abc268c. [abc268_c]Chinese Restaurant
[abc268_c]Chinese Restaurant
Problem Statement
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.)
Constraints
- if .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
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 is happy because Dish is in front of Person ;
- Person is happy because Dish is in front of Person ;
- Person is happy because Dish is in front of Person ;
- Person is happy because Dish is in front of Person .
There cannot be five or more happy people, so the answer is .
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