Problem:
Score : 400 points

Problem Statement

Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.

You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.

Constraints

2 ≦ |s| ≦ 10^5

s consists of lowercase letters.

Partial Score

200 points will be awarded for passing the test set satisfying 2 ≦ N ≦ 100.

Input

The input is given from Standard Input in the following format:

s

Output

If there exists no unbalanced substring of s, print -1 -1.

If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print a b. If there exists more than one such substring, any of them will be accepted.

Sample Input 1

needed

Sample Output 1

2 5

The string s_2 s_3 s_4 s_5 = eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.

Sample Input 2

atcoder

Sample Output 2

-1 -1

The string atcoder contains no unbalanced substring.

Solution in C# (Mono 4.6.2.0) (judge verdict: Wrong Answer)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Collections;
public class Remainder
{

  static long div = 1000000007;

    static public void Main()
    {
        var S = Console.ReadLine();
        var N = S.Length;
        var cum = new int[26,N];
        var que = new Queue<int>[26];
        for(int i = 0;i < 26;i++){
          que[i] = new Queue<int>();
        }
      
        for(int i = 0;i < N;i++){
          var cast = ((int)S[i])%97;
          cum[cast,i]++;
          que[cast].Enqueue(i);
        }
        
        for(int i = 0;i < 26;i++){
          for(int j = 1;j < N;j++){
            cum[i,j] += cum[i,j-1];
          }
        }
        //答えがあるかどうかのフラグ
      　var flag = false;
        var a = -1;
        var b = -1;
        //アルファベット順にキューから取り出し二分探索する
        for(int i = 0;i < 26;i++){
          while(que[i].Count > 0){
            //累積和の左側を計算
            var left  = que[i].Dequeue();
            var lsum = 0;
            if(left > 0){
              lsum = cum[i,left-1];
            }
            
            var count = 1;
            var right = left+(int)Math.Pow(2,count)-1;
            
            while(right < N){
              //累積和を計算
              var csum = cum[i,right]-lsum;
              //過半数を超えているか
              if(csum > (int)Math.Pow(2,count-1)){
                flag = true;
                a = left;
                b = right;
                break;
              }
              count++;
              right = left+(int)Math.Pow(2,count)-1;
            }
            
            if((cum[i,N-1]-lsum) > (N+1)/2){
              a = left;
              b = right;
              flag = true;
            }
            
            if(flag){
              break;
            }
          }
          if(flag){
            break;
          }
        }
        
        if(flag){
          Console.WriteLine((a+1)+" "+(b+1));
        }else{
          Console.WriteLine(-1+" "+-1);
        }
        

    }

}