
The CS Nerd knows that playing music can impress girls, so he decides to learn how to play some passionate piano solos in order to impress the girl. He thinks that pieces with fast moving notes are fun to play and will make the girl think he is a piano virtuoso. In particular, he has a liking for the super chord.
A piano's notes are numbered starting from
- Choose the first note of the chord. This can be any note.
- Repeat the following steps from the starting note: Jump right
notes, then notes, then notes, then notes. - These steps can be repeated in the reverse order from the starting note by jumping left (i.e. left down
, then , then , then ).
A consecutive sequence of notes is considered to be a super sequence if every single note in the sequence is part of the same super chord. For example, the sequences
The CS Nerd finds a manuscript with
Constraints
For 20% of the points,
For an additional 30% of the points,
Input Specification
The first line of input will contain two space-separated integers:
Output Specification
On a single line, output the length of the longest super sequence after the CS Nerd changes up to
Sample Input
5 1
3
4
2
5
8
Sample Output
4
Explanation for Sample Output
The CS Nerd can change the
Comments
Does the super chord have to start from the lowest note, or can it start from any note. IE: super chord 1 = 1 5 8 11 13. Is 5 8 11 a super chord?
How is 11, 5, 1, 1, 17, 32 a super sequence?
All of the notes are in the same super chord.