Hammoudeh, Rimawi, and Raghad recently started a band. Hammoudeh plays the guitar, Rimawi plays the piano, and Raghad plays the bass. Laith is the band's composer, and he wrote them a song. Let's represent this song as a sequence of non-negative integers $a_1$, $a_2$,..., $a_n$.
At the $i^{th}$ moment of the song, Hammoudeh plays the note $a_i$ modulo 4. So if $a$ = {5, 7, 2}, Hammoudeh plays the notes {1, 3, 2} in this order. Similarly, Rimawi plays the note $a_i$ modulo 5, and Raghad plays the note $a_i$ modulo 8.
The band only recently started practicing, so our three musicians have some limitations. If the last note that Hammoudeh played was $j$, and he wants to play some note $p$, he can only play it if $| j - p | <= k_1$. Similarly, Rimawi can only play two notes in a row if the absolute difference between them is less than or equal to $k_2$, and Raghad can only play two notes in a row if the absolute difference between them is less than or equal to $k_3$.
After Laith sent them the song, the band discovered that they might not be able to play the whole song (since Laith is a horrible composer). Can you help them find the longest part of the song that they can play? Given a song as described above, find the longest non-empty subarray of that song such that the band can play all of it.
Recall that a non-empty subarray of an array a is an array that can be obtained by deleting some, possibly zero elements from the beginning of $a$, and some, possibly zero elements from the end of $a$.
The first line of the input contains a single integer n ,$(1\leq n \leq 2 \times 10^5)$ - the number of elements in the array.$ \\ $
The second line contains three integers $k_1, k_2$ and $k_3$ $(0\leq k_1 <4),( 0\leq k_2 < 5),( 0\leq k_3 < 8)$.$ \\ $
The third line contains $n$ integers, $a_1$, $a_2$,..., $a_n$ $(1 \leq a_i \leq 10^9)$.
Print two integers $f$ and $l$, the first and last index of the subarray. If there are multiple answers you are free to print any of them.
For the first test case each artists' notes will be:$\\ $
Hammoudeh: 1 0 2 0 0 1 0 1$\\ $
Rimawi : 4 4 0 4 2 3 4 0$\\ $
Raghad : 1 4 2 4 4 5 4 5$\\ $
The longest consecutive notes will be from index 4 to index 7
Input | Output |
---|---|
8 2 2 2 9 4 10 4 12 13 4 5 Copy
|
4 7 Copy
|