Digital row#3029

Digital row

3 seconds
256 megabytes
Very hard

Once upon a time, a boy named Vova, who had just learned to count and write, decided to practice these skills by writing down all natural numbers starting from one in a continuous sequence on a sheet of paper. His older brother, Petya, noticed this infinite sequence of digits, which we'll call :

Figure №1. Digital sequence.

Petya, who is interested in programming, wanted to explore the properties of this sequence. For any given pair of integers where i \leq j, a substring of the sequence is defined as the sequence of digits S_i S_{i+1} \dots S_j. For instance, the pair corresponds to the substring , and the pair corresponds to the substring .

Figure №2. Examples of substrings.

A pattern is defined as a string consisting of digits from to , and the characters and . A string is said to match the pattern if can be derived from by replacing each with a single digit and each with any sequence of digits, which can also be empty.

Petya's task is to find a substring of the sequence that matches the given pattern . For example, the pattern ?1*1 is matched by substrings corresponding to the pairs , , , , , , , and so on. Help Petya solve this intriguing challenge!

Figure №3. Description of the second example.

Input

The first line of the input file contains a single natural number (1 \leq N \leq 20) – the length of the string .

The second line of the input file contains one string , consisting of characters: digits from to , and .

Output

The output should be a single line containing two integers and , separated by a space, where is a pair such that the corresponding substring of the sequence matches the pattern .

If there are multiple pairs that match the pattern , output the smallest pair. A pair (i_1, j_1) is considered smaller than (i_2, j_2) if i_1 < i_2 or i_1 = i_2 and j_1 < j_2.

If no substring of the sequence matches the pattern , output 0 0.

Examples

Example 1

Loading
Loading