Ashmuz, who follows with his new rights n n members a 1 , a 2 , … , a n , a 1 , a 2 …
- User
Ashmuz, who follows with his new rights n n members a 1 , a 2 , … , a n , a 1 , a 2 ,...,a n , has bought integers, eagerly showed his sequence to Keshi. But Keshi told Ashmuz in a counter-move that the number of 42 sequences is small! So they decided to change the sequence by performing some operations so that the number of 42s will increase.
They can perform the following operations:
In each operation, Ashmes can choose a prefix from the sequence and subtract one unit from it. In each operation, the draw can select an extension of the sequence and subtract one unit from it. Description of the image
In this question, you should help Ashmuz and Kashi and calculate the maximum possible number of repetitions of 42 by taking the input of the initial sequence.
Pay attention that the order and number of operations are arbitrary and the sequence numbers may become negative after performing an operation.
input In the first line of the input, the number n n represents the length of the sequence. 1 ≤ n ≤ 1437 1≤n≤1437
In the second line of the input, n n integer called a 1 , a 2 , … , a n , a 1 , a 2 ,...,a n , which shows the initial state of the sequence. 1 ≤ a i ≤ 1 0 9 1≤a i ≤10 9
output In the only output line, you should print the maximum possible number of repetitions of 42 after performing the desired number of operations.
examples Sample entry 1 3 43 42 43 Plain text Sample output 1 3 Plain text In this example, if Ashmose performs an operation on the prefix of length 1 and Kashi on the prefix of length 1, all members of the sequence will be 42.
Sample input 2 7 37 42 45 45 45 42 37 Plain text Sample output 2 4 Plain text In this example, if Ashmes performs three operations on the prefix of length 5, the sequence will be a
[ 34 , 39 , 42 , 42 , 42 , 42 , 37 ] a=[34,39,42,42,42,42,37] will be converted, the number of 42 of which is 4. It can be shown that no matter how we do the operation, the number of 42s will not be more than 4.
Sample entry 3 7 45 50 44 5 46 44 45 Plain text Sample output 3 5 write in c++
- Assistant