Winter Olympic Games
Time limit5sMemory limit1024 MB
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

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.
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 of length .
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 of length is lexicographically greater than a string of length when one of the following holds.
- For some , , , , and .
- and , , , .
Input
The first line contains the number of stones .
The second line contains a string of length 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 and separated by a space. They mean that Yeongmi swept away the stones right after the -th character and put a single stone of her own team in their place. (, )
If several pairs produce the lexicographically greatest string, print the one with the smallest , and if several of those remain, print the one with the smallest among them.