[Solution] Rings solution codeforces

Rings solution codeforces


Somewhere in a parallel Middle-earth, when Saruman caught Frodo, he only found nn rings. And the ii-th ring was either gold or silver. For convenience Saruman wrote down a binary string ss of nn characters, where the ii-th character was 0 if the ii-th ring was gold, and 1 if it was silver.

Saruman has a magic function ff, which takes a binary string and returns a number obtained by converting the string into a binary number and then converting the binary number into a decimal number. For example, f(001010)=10,f(111)=7,f(11011101)=221f(001010)=10,f(111)=7,f(11011101)=221.

Saruman, however, thinks that the order of the rings plays some important role. He wants to find 22 pairs of integers (l1,r1),(l2,r2)(l1,r1),(l2,r2), such that:

  • 1l1n1≤l1≤n1r1n1≤r1≤nr1l1+1n2r1−l1+1≥⌊n2⌋
  • 1l2n1≤l2≤n1r2n1≤r2≤nr2l2+1n2r2−l2+1≥⌊n2⌋
  • Pairs (l1,r1)(l1,r1) and (l2,r2)(l2,r2) are distinct. That is, at least one of l1l2l1≠l2 and r1r2r1≠r2 must hold.
  • Let tt be the substring s[l1:r1]s[l1:r1] of ss, and ww be the substring s[l2:r2]s[l2:r2] of ss. Then there exists non-negative integer kk, such that f(t)=f(w)kf(t)=f(w)⋅k.

Here substring s[l:r]s[l:r] denotes slsl+1sr1srslsl+1…sr−1sr, and x⌊x⌋ denotes rounding the number down to the nearest integer.

Help Saruman solve this problem! It is guaranteed that under the constraints of the problem at least one solution exists.

Input

Each test contains multiple test cases.

The first line contains one positive integer tt (1t1031≤t≤103), denoting the number of test cases. Description of the test cases follows.

The first line of each test case contains one positive integer nn (2n21042≤n≤2⋅104) — length of the string.

The second line of each test case contains a non-empty binary string of length nn.

It is guaranteed that the sum of nn over all test cases does not exceed 105105.

Output Rings solution codeforces

For every test case print four integers l1l1r1r1l2l2r2r2, which denote the beginning of the first substring, the end of the first substring, the beginning of the second substring, and the end of the second substring, respectively.

If there are multiple solutions, print any.

Example Rings solution codeforces
input Rings solution codeforces

Copy
7
6
101111
9
111000111
8
10000000
5
11011
6
001111
3
101
30
100000000000000100000000000000
output

Copy
3 6 1 3
1 9 4 9
5 8 1 4
1 5 3 5
1 6 2 4
1 2 2 3
1 15 16 30
Note

In the first testcase f(t)=f(1111)=15f(t)=f(1111)=15f(w)=f(101)=5f(w)=f(101)=5.

In the second testcase f(t)=f(111000111)=455f(t)=f(111000111)=455f(w)=f(000111)=7f(w)=f(000111)=7.

In the third testcase f(t)=f(0000)=0f(t)=f(0000)=0f(w)=f(1000)=8f(w)=f(1000)=8.

In the fourth testcase f(t)=f(11011)=27f(t)=f(11011)=27f(w)=f(011)=3f(w)=f(011)=3.

In the fifth testcase f(t)=f(001111)=15f(t)=f(001111)=15f(w)=f(011)=3f(w)=f(011)=3.

Solution: Click here

Rings solution codeforcessolution codeforcescodeforces solutioncodeforces freshersonline

Leave a Comment