This page is still under construction.

Parts of this page are still being built. What you see may change.

Winter Olympic Games

Time limit5sMemory limit1024 MB

Summary
Replace one contiguous block of a binary string (possibly empty) by a single 1, empty block inserts without deleting, to make the resulting string lexicographically largest.
Level

Medium7 of 10

Topics
Greedy, String, Brute force, Implementation
Solved
No attempts yet

Problem

A Soohorang plush toy

The photo has nothing to do with the problem. Soohorang is cute anyway.

The women's final of the winter curling tournament is being played on a frozen duck pond. The Korean team and the Jwepan team are fighting over the last point.

NN curling stones lie on the pond in one line, ordered by distance from the target. The leftmost stone is closest to the target and the rightmost stone is farthest. Each stone belongs either to the Korean team (1) or to the Jwepan team (0), so the layout is a binary string ss of length NN.

After long practice the Korean team learned one move. Given a few shouts, Yeongmi sweeps away a block of consecutive stones and puts a single stone of her own team where that block was. In other words, the team picks one interval of the string and replaces that interval with the single character 1. The interval may be the whole string, and it may be empty. When the interval is empty, one 1 is inserted at that spot and the string gets one character longer.

The team performs this operation exactly once and wants the resulting string to be lexicographically greatest. Find which interval to pick.

A string s=s1s2…sns = s_1 s_2 \dots s_n of length nn is lexicographically greater than a string t=t1t2…tmt = t_1 t_2 \dots t_m of length mm when one of the following holds.

  • For some ii, s1=t1s_1 = t_1, s2=t2s_2 = t_2, …\dots, si−1=ti−1s_{i-1} = t_{i-1} and si>tis_i > t_i.
  • n>mn > m and s1=t1s_1 = t_1, s2=t2s_2 = t_2, …\dots, sm=tms_m = t_m.

Input

The first line contains the number of stones NN.

The second line contains a string of length NN made only of 0 and 1. It gives the owner of each stone, from the stone closest to the target to the one farthest from it. No space or quotation mark appears between the characters.

Output

Print two integers SS and LL separated by a space. They mean that Yeongmi swept away the LL stones right after the SS-th character and put a single stone of her own team in their place. (0≤S0 \le S, L≤NL \le N)

If several pairs (S,L)(S, L) produce the lexicographically greatest string, print the one with the smallest SS, and if several of those remain, print the one with the smallest LL among them.

Constraints

  • 1≤N≤1061 \le N \le 10^6

Examples3

  1. Example 1

    Input
    8
    10101101
    
    Expected output
    1 3
    
  2. Example 2

    Input
    5
    11111
    
    Expected output
    0 0
    
  3. Example 3

    Input
    4
    1101
    
    Expected output
    2 1