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 (Python):
s = input()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print(str(i+1)+" "+str(i+2))
        break
    if (i != len(s)-2) and (s[i]==s[i+2]):
        print(str(i+1)+" "+str(i+3))
        break
else:
    print("-1 -1")

Solution (Python):
from itertools import combinations as comb
s=input()
l=[]
for i in comb(set(s),2):
  a,b=i
  l.extend([a+b+a,b+a+b])
for i in set(s):
  l.extend([i+i])
for i in l:
  a,b=i,len(i)
  c=s.find(a)
  if c!=-1:
    print(c+1,c+b)
    break
else:
  print(-1,-1)

Solution (Python):
import sys
s = input()
a = 'qwertyuiopasdfghjklzxcvbnm'
for i in a:
    for n in range(len(s)-1):
        if i+i == s[n:n+2]:
            print(n+1,n+2)
            sys.exit()
    for n in range(len(s)-2):
        if i == s[n] and i == s[n+2]:
            print(n+1,n+3)
            sys.exit()
print(-1,-1)

Solution (Python):
S=input()
N=len(S)
for i in range(N-1):
    if S[i]==S[i+1]:
        print(i+1,i+2)
        exit()
for i in range(N-2):
    if S[i]==S[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)

Solution (Python):
ss = input()

iChars = {}
for i, s in enumerate(ss, 1):
    iPrev = iChars.get(s, -2)
    if i - iPrev <= 2:
        print(iPrev, i)
        break
    iChars[s] = i
else:
    print('-1 -1')

Solution (Python):
ss = input()

iChars = {}
for i, s in enumerate(ss, 1):
    iPrev = iChars.get(s, -2)
    if i - iPrev <= 2:
        print(iPrev, i)
        break
    iChars[s] = i
else:
    print('-1 -1')

Solution (Python):
ss = input()

iChars = {}
for i, s in enumerate(ss, 1):
    iPrev = iChars.get(s, -2)
    if i - iPrev <= 2:
        print(iPrev, i)
        break
    iChars[s] = i
else:
    print('-1 -1')

Solution (Python):
ss = input()

iChars = {}
for i, s in enumerate(ss, 1):
    iPrev = iChars.get(s, -2)
    if i - iPrev <= 2:
        print(iPrev, i)
        break
    iChars[s] = i
else:
    print('-1 -1')

Solution (Python):
import sys
s = list(raw_input())

l = len(s)

if l == 2:
	if s[0] == s[1]:
		print "1 2"
		sys.exit()

	else:
		print '-1 -1'
		sys.exit()

for i in range(l-2):
	t = []
	for j in range(3):
		if s[i + j] in t:
			print i+1,i+3
			sys.exit()
		else :
			t.append(s[i + j])

print "-1 -1"

Solution (Python):
from collections import Counter

S = input()

for i in range(len(S) - 1):
    s = S[i:i+3]
    for v in Counter(s).values():
        if v >= 2:
            print(i+1, i+len(s))
            exit()

print(-1, -1)

Solution (Python):
from collections import Counter

s = input()
a = Counter(s[0:0+3]).values()

for i in range(len(s) - 1):
    for j in (2, 3):
        for v in Counter(s[i:i+j]).values():
            if v >= 2:
                print(i+1, i+j)
                exit()

print(-1, -1)

Solution (Python):
from collections import Counter

s = input()

for i in range(len(s) - 2):
    for v in Counter(s[i:i+3]).values():
        if v >= 2:
            print(i+1, i+3)
            exit()

for i in range(len(s) - 1):
    for v in Counter(s[i:i+2]).values():
        if v >= 2:
            print(i+1, i+2)
            exit()

print(-1, -1)

Solution (Python):
s = input()
p2 = s[0]
p1 = s[1]
ans = "-1 -1"
if p2 == p1 :
  ans = '1 2'
else:
  for i in range(2,len(s)):
    if p2 == s[i] or p1 == s[i]:
      ans = str(i-1)+" "+str(i+1)
      break
    p2 = s[i-1]
    p1 = s[i]
print(ans)

Solution (Python):
s=input().rstrip()
for i in range(len(s)):
  if 1 <= i and (s[i-1] == s[i]):
    print(i,i+1)
    exit()
  if 2 <= i and (s[i-2] == s[i]):
    print(i-1,i+1)
    exit()
print(-1,-1)

Solution (Python):
n=input()
f = 0
if len(n)==2 :
    if n[0]==n[1]:
        print(1,2)
        f = 1
for i in range(len(n)-2) :
    vis = {}
    t = 0 
    for j in range(i , i+3) :
        
        if n[j] in vis :
            vis[n[j]]+=1

        else:
            vis[n[j]] = 1
    for j in vis :
        if vis[j]>=2:
            print(i+1 , i+3)
            f = 1
            break
    if f==1:break
if not f :
    print(-1 , -1)

Solution (Python):
s = input()
ans = s[0]
OK = True
for i in range(1,len(s)):
    ans += s[i]
    if len(ans)==2 and ans[0]==ans[1]:
        print('{0} {1}'.format(i,i+1))
        OK=False
        break
    if len(ans)==3:
        if ans[0]==ans[2] or ans[1]==ans[2]:
            OK=False
            print('{0} {1}'.format(i-1,i+1))
        else:
            ans = ans[1:3]
if OK:
    print('-1 -1')

Solution (Python):
import re
repatter = re.compile(r"([a-z]).?\1")
s = input()
matchObj = repatter.search(s)
if matchObj:
    print(matchObj.start()+1, matchObj.end())
else:
    print(-1, -1)

Solution (Python):
s = input()
L = len(s)
for i in range(L-2) :
    if s[i+1] == s[i] or s[i+2] == s[i] :
        print(i+1, i+3)
        exit()
else :
    if s[L-2] == s[L-1] :
        print(L-1, L)
    else :
        print(-1, -1)

Solution (Python):
s = input()
n = len(s)
ans = -1, -1
for i in range(n-1):
    if s[i] == s[i+1]:
        ans = [i+1, i+2]
    elif i < n -2 and s[i] == s[i+2]:
        ans = [i+1, i+3]

print(ans[0], ans[1])

Solution (Python):
S = input()
l = len(S)
if l == 2:
    if S[0] == S[1]:
        print(1, 2)
        quit()
    else:
        print(-1, -1)
        quit()
else:
    for i in range(l-2):
        if S[i] == S[i+1]:
            print(i+1, i+2)
            quit()
        elif S[i+1] == S[i+2]:
            print(i+2, i+3)
            quit()
        elif S[i] == S[i+2]:
            print(i+1, i+3)
            quit()

print(-1, -1)

Solution (Python):
a = input()
n = len(a)
ansa = -1
ansb = -1
for i in range(n-1):
    if a[i] ==a[i+1]:
        ansa = i
for j in range(n-2):
    if a[j] ==a[j+2]:
        ansb = j
if ansa != -1:
    print(ansa+1,ansa+2)
elif ansb != -1:
    print(ansb+1,ansb+3)
else:
    print(-1,-1)

Solution (Python):
s = input()
n = len(s)
for i in range(n-1):
    if s[i] == s[i+1]:
        print(i+1,i+2)
        exit()
for i in range(n-2):
    if s[i] == s[i+2]:
        print(i+1, i+3)
        exit()
print(-1,-1)

Solution (Python):

def solve(s):
    if len(s) == 2 and s[0] == s[1]:
        return 1, 2
    for l in range(len(s) - 2):
        a, b, c = sorted(s[l : l + 3])
        if a == b or b == c:
            return l + 1, l + 3
    return -1, -1
print(*solve(input()))

Solution (Python):

s = list(input())

ans = [-1, -1]
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        ans = [i + 1, i + 2]
        break
    if i < len(s) - 2 and s[i] == s[i + 2]:
        ans = [i + 1, i + 3]
print(ans[0], ans[1])

Solution (Python):
S=input()+"X"
N=len(S)
A,B=-1,-1

for i in range(N-2):
    if S[i] == S[i+1]:
        A,B=i+1,i+2
    if S[i] == S[i+2]:
        A,B=i+1,i+3

print(A,B)

Solution (Python):
s = list(input())
a =[]
n = len(s)
for i in range(1,n):
    if len(a) == 0:
        a.append(1)
    if s[i] == s[i-1]:
        a[-1] += 1
    else:
        a.append(1)
if a[0] == n:
    print(1,n)
    exit()
if max(a) > 1:
    for i in range(len(a)):
        if a[i] >1:
            if i == len(a)-1:
                print(n-a[i],n)
            else:
                print(sum(a[0:i])+1,sum(a[0:i+1])+1)
            exit()

else:
    for i in range(n-2):
        if s[i] == s[i+2]:
            print(i+1,i+3)
            exit()


    print(-1,-1)

Solution (Python):
import string

S = input()

for a in string.ascii_lowercase:
    pre = -1
    for i, s in enumerate(S):
        if s == a:
            if pre != -1 and i - pre <= 2:
                print(pre+1, i+1)
                exit()
            else:
                pre = i

print(-1, -1)

Solution (Python):
S=input()
a=0
for i in range(len(S)-2):
  if S[i]==S[i+1] or S[i]==S[i+2] or S[i+1]==S[i+2]:
    a=1
    print(i+1,i+3)
    break

if a==0:
 if len(S)>1 and S[-1]==S[-2]:
  print(len(S)-1,len(S))
 else:
  print(-1,-1)

Solution (Python):
def judge(str):
    for i in range(len(str) - 2):
        if str[i] == str[i + 2]:
            print(i + 1, i + 3)
            return
    
    for i in range(len(str) - 1):
        if str[i] == str[i + 1]:
            print(i + 1, i + 2)
            return

    print(-1, -1)
    return

s = input()
judge(s)

Solution (Python):
d={}
for i,c in enumerate(input(),1):
    if c in d and i-d[c]<=2:
        print(d[c],i)
        break
    d[c]=i
else:
    print(-1,-1)

Solution (Python):


s = raw_input()

flag = 0
if s[0] == s[1]:
    print "1 2"
    flag = 1
else:
    for i in range(2, len(s)):
        if s[i] == s[i - 1]:
            print(str(i) + " " + str(i + 1))
            flag = 1
            break
        elif s[i] == s[i - 2]:
            print(str(i - 1) + " " + str(i + 1))
            flag = 1
            break
        else:
            continue
if flag == 0:
    print "-1 -1"

Solution (Python):
s = input()
a, b = -1, -1

if len(s) == 2 and s[0] == s[1]:
    a, b = 1, 2
elif len(s) > 1:
    for i in range(len(s)-2):
        if s[i] == s[i+1]:
            a, b = i+1, i+2
            break
        if s[i] == s[i+2]:
            a, b = i+1, i+3
            break
print(a, b)

Solution (Python):
s = input()
slist = list(s)
slen = len(slist)
res = [-1,-1]
for i in range(slen):
    if i + 1 <= slen - 1:
        if slist[i] == slist[i+1]:
            res = [i+1,i+2]
            break
    if i + 2 <= slen - 1:
        if slist[i] == slist[i+2]:
            res = [i+1,i+3]
            break
print(res[0],res[1])

Solution (Python):
s = input()
if len(s)==2:
    if s[0]==s[1]:
        print(1,2)
    else:
        print(-1,-1)
    exit()
for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print(i+1,i+2)
        exit()
for i in range(len(s)-2):
    if s[i] == s[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)

Solution (Python):



import re
import sys

def main() :
	s=sys.stdin.read()
	
	for pattern in [r"([a-z])\1", r"([a-z])[a-z]\1"] :
		mo=re.search(pattern, s)
		if mo :
			print "%d %d"%(mo.start()+1, mo.end())
			return
	
	print "-1 -1"

if __name__=="__main__" :
	main()

Solution (Python):
s = input()
n = len(s)
def solve():
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            return (i + 1, i + 2)
    for i in range(n - 2):
        if s[i] == s[i + 2]:
            return (i + 1, i + 3)
    return (-1, -1)
a, b = solve()
print(a, b)

Solution (Python):
import sys

def finish(a, b):
    print('%d %d' % (a, b))
    sys.exit()

s = raw_input().strip()
if s[0] == s[1]:
    finish(1, 2)
for i in range(2, len(s)):
    a, b, c = s[i - 2], s[i - 1], s[i]
    if a == b or a == c or b == c:
        finish(i - 1, i + 1)
finish(-1, -1)

Solution (Python):



from __future__ import division, print_function, absolute_import, unicode_literals

s = input()
isFound = False

for i, (a, b) in enumerate(zip(s[:-1], s[1:])):
    if a == b:
        isFound = True
        start, end = i+1, i+2
        break

for i, (a, b) in enumerate(zip(s[:-2], s[2:])):
    if a == b:
        isFound = True
        start, end = i+1, i+3
        break

if isFound is False:
    print("-1 -1")
else:
    print("{} {}".format(start, end))

Solution (Python):
y=raw_input()
f=0
if len(y)==1:
    print -1,-1
elif len(y)==2:
    if y[0]==y[1]:
        print 1,2
    else:
        print -1,-1
else:
    for i in range(len(y)-2):
        if y[i]==y[i+1] or y[i+1]==y[i+2] or y[i+2]==y[i]:
            print i+1,i+3
            f=1
            break
    if f!=1:
        print -1,-1

Solution (Python):
s = raw_input()
if s[0] == s[1]:
    print("1 2")
    exit()
    
for i in xrange(2,len(s)):
    if s[i] == s[i-1] or s[i] == s[i-2]:
        print(str(i-1) + " " + str(i+1)) 
        exit()
print ("-1 -1")

Solution (Python):


NO_SOL = (-1, -1)





def search_unbalanced_substr(s):
    n = len(s)
    
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            return i, i + 1
    
    for i in range(n - 2):
        if s[i] == s[i + 2]:
            return i, i + 2
    
    return NO_SOL


def main():
    ans = search_unbalanced_substr(input())
    if ans == NO_SOL:
        print(*ans)
    else:
        print(*(i + 1 for i in ans))


if __name__ == '__main__':
    main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**9

s = input()
l = len(s)
f = True
for i in range(l-2):
    if s[i] == s[i+1] or s[i] == s[i+2] or s[i+1] == s[i+2]:
        print('{0} {1}'.format(i+1, i+3))
        f = False
        break
if f:
    if l > 1 and s[-1] == s[-2]:
        print('{0} {1}'.format(l-1, l))
    else:
        print('-1 -1')

Solution (Python):
s = raw_input()
N = len(s)

A, B = -1,-1

for i in range(N - 1):
  if s[i] == s[i+1]:
    A, B = i + 1, i + 2

for i in range(N - 2):
  if s[i] == s[i+2]:
    A, B = i + 1, i + 3

print A, B

Solution (Python):

 
def count_char_max(text):
 
  a = "abcdefghijklmnopqrstuvwxyz"
  l = [0] * 26
 
  for i in text:
 
    ascNum = ord(i.lower()) - 97
 
    if ascNum < 0 or 25 < ascNum:
      continue
 
    l[ascNum] += 1
 
  return max(l)
 
s = raw_input()

for i in range(len(s) - 1):

  if (s[i] == s[i + 1]):
    print "%d %d" % (i + 1, i + 2)
    quit()

for i in range(len(s) - 2):

  if (count_char_max(s[i:i+3]) == 2):
    print "%d %d" % (i + 1, i + 3)
    quit()

print "-1 -1"

Solution (Python):
import sys

s = sys.stdin.readline().strip()
n = len(s)

def solve(s, n):
    for i in range(0, n - 1):
        if s[i] == s[i + 1]:
            print i+1, i+2
            return

    for i in range(0, n - 2):
        if s[i] == s[i + 2]:
            print i+1, i+3
            return

    print -1, -1

solve(s, n)

Solution (Python):
s=raw_input()
n=len(s)
if n==2:
    if s[0]==s[1]:
        print 1,2
        quit()
    else:
        print -1,-1
        quit()
for i in xrange(n-2):
    if s[i]==s[i+1] or s[i]==s[i+2] or s[i+1]==s[i+2]:
        print i+1,i+3
        quit()
print -1,-1

Solution (Python):

s = list(input())
n = len(s)

for i in range(n - 1):
    if s[i] == s[i + 1]:
        print(i + 1, i + 2)
        exit()

alp = [chr(i) for i in range(97, 97+26)]

for j in range(26):
    num = [0] * n

    for i in range(n):
        if s[i] == alp[j]:
            num[i] += 1

    start = 0
    end = 3

    while True:
        
        

        if start >= n or end > n:
            break

        if num[start] == 0:
            start += 1
            end += 1
            continue

        if sum(num[start:end]) > (end - start) / 2:
            print(start + 1, end)
            exit()

        if sum(num[start:end]) > (end - start) / 2 - 1:
            end += 1

        else:
            start += 1
            if end - start < 3:
                end += 1

print(-1, -1)

Solution (Python):
from collections import Counter
 
S = raw_input()
 
if len(S) == 2:
    if S[0] == S[1]:
        print 1, 2
    else:
        print -1, -1
else:
    for i in range(len(S)):
        T = S[i:i+3]
        if max(Counter(T).values()) >= 2:
            print i+1, i+3
            break
    else:
        print -1, -1

Solution (Python):
from collections import deque
S = [ord(a)-97 for a in raw_input()]
N = len(S)
for c in xrange(26):
	L = deque()
	for i in xrange(N-1):
		if S[i] == c:
			l = i
			break
	else:
		continue
	cnt = 1
	lenL = 0
	for r in xrange(l+1,N):
		if S[r] == c:
			cnt += 1
			L.append(r)
			lenL += 1
			if cnt * 2 > r - l + 1:
				print l+1,r+1
				quit()
		while cnt * 2 < r - l + 1 and lenL > 0:
			l = L.popleft()
			lenL -= 1
			cnt -= 1
print -1,-1

Solution (Python):


def check(string):
    if(len(set(string)) <= 2):
        return True
    else:
        return False

if __name__ == '__main__':
    s = input()
    l = len(s)
    if(l == 2 and len(set(s)) == 2):
        print("-1 -1")
    elif(l == 2 and len(set(s)) == 1):
        print("1 2")
    else:
        for j in range(l - 2):
            if(check(s[j:j+3])):
                print(j + 1, ' ', j + 3)
                break
            elif(j == l - 3):
                print("-1 -1")

Solution (Python):
S = input()

alp = list(map(lambda x: chr(x), range(ord('a'), ord('z')+1)))
def solve():
    for c in alp:
        cand = S.find(c*2)
        if cand != -1:
            return (cand, cand+1)
        for i in alp:
            cand = S.find(c+i+c)
            if cand != -1:
                return (cand, cand+2)

res = solve()
if res is None:
    print('-1 -1')
else:
    print(res[0]+1, res[1]+1)

Solution (Python):
import sys
S = input().strip()

for i in range(2,4):
    for j in range(0,len(S)+1-i):
        s = S[j:j+i]
        for k in set(s):
            if s.count(k)*2 > len(s):
                print(j+1,j+i)
                sys.exit(0)

print(-1,-1)

Solution (Python):
s = raw_input().strip()
d = dict()
for i, c in enumerate(s):
    if c in d:
        if i - d[c] <= 2:
            print d[c] + 1, i + 1
            quit()
    d[c] = i
print -1, -1

Solution (Python):
import bisect
import sys
import math
import itertools
sys.setrecursionlimit(10000)

INF = float('inf')


def i():
    return int(raw_input())
def ii():
    return map(int,raw_input().split(" "))
def s():
    return raw_input()
def ss():
    return raw_input().split(" ")
def slist():
    return list(raw_input())


def join(s):
    return ''.join(s)


def piter(n,m):
    return itertools.permutations(n,m)
def citer(n,m):
    return itertools.combinations(n,m)


def modc(a,b,m):
    c = 1
    for i in xrange(b):
        c = c * (a - i) % m
        c = c * modinv(i + 1,m) % m
    return c
 
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
 
def modinv(a, m):
    (inv, q, gcd_val) = gcd(a, m)
    return inv % m


def index(a, x):
    
    i = bisect_left(a, x)
    if i != len(a) and a[i] == x:
        return i
    return -1


def memoize(f):
    cache = {}
    def helper(*args):
        if args not in cache:
            cache[(args)] = f(*args)
        return cache[args]
    return helper

@memoize
def nck(a,b,m):
    b = min([a-b,b])
    if (b>a or b<0 or a<0):
        return 0
    elif a == 0:
        return 1
    return (nck(a-1,b-1,m)+nck(a-1,b,m)) % m



s=slist()
n=len(s)
if s[n-2]==s[n-1]:
    print n-1,n
else:
    for i in range(n-2):
    
        if s[i]==s[i+1]:
            print i+1,i+2
            break
        elif s[i]==s[i+2]:
            print i+1,i+3
            break
    else:
        print -1,-1

Solution (Python):
import string
S = input()
N = len(S)

for i in range(N):
    if i < N-1 and S[i] == S[i+1]:
        print(i+1, i+2)
        quit()
    elif i < N-2 and S[i] == S[i+2]:
        print(i+1, i+3)
        quit()
print(-1, -1)

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

S = s()
L = len(S)

if L == 2:
    if S[0] == S[1]:
        print 1, 2
    else:
        print -1, -1
else:
    for i in xrange(L - 2):
        if len(set(S[i:i + 3])) < 3:
            print i + 1, i + 2 + 1
            break
    else:
        print -1, -1

Solution (Python):
S = str(input())

for k in range(len(S)-1):
    if S[k] == S[k+1]:
        print(k+1,k+2)
        exit()

for k in range(len(S)-2):
    if S[k] == S[k+2]:
        print(k+1,k+3)
        exit()

print(-1,-1)

Solution (Python):



def func():
    S = input()
    for idx in range(len(S)):
        if idx > 0:
            if S[idx] == S[idx-1]:
                print("{} {}".format(idx, idx+1))
                return
        if idx > 1:
            if S[idx] == S[idx-2]:
                print("{} {}".format(idx-1, idx+1))
                return
    print("-1 -1")

func()

Solution (Python):
S=input()
N=len(S)
A,B=-1,-1
for i in range(N-1):
    if S[i] == S[i+1]:
        A,B=i+1,i+2
for i in range(N-2):
    if S[i] == S[i+2]:
        A,B=i+1,i+3
print(A,B)