Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N,M,P = map(int,input().split())
E = []
for i in range(M):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  c=-c+P
  E.append([a,b,c])
  
def BellmanFord(s,g):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(N)]
  dist[s]=0
  rout=[]
  
  #辺の緩和
  for i in range(N*N):
    for edge in E:
      if dist[edge[1]] > dist[edge[0]] + edge[2]:
        dist[edge[1]] = dist[edge[0]] + edge[2]
        if i==N*N-1 and edge[1]==g: return -1
  
  return max(0,-dist[g])
print(BellmanFord(0,N-1))

Fixed submission:
N,M,P = map(int,input().split())
E = []
for i in range(M):
  a,b,c=map(int,input().split())
  a-=1
  b-=1
  c=-c+P
  E.append([a,b,c])
  
def BellmanFord(s,g):
  #グラフの初期化
  inf=float("inf")
  dist=[inf for i in range(N)]
  dist[s]=0
  rout=[]
  
  #辺の緩和
  for i in range(N):
    for edge in E:
      if dist[edge[1]] > dist[edge[0]] + edge[2]:
        dist[edge[1]] = dist[edge[0]] + edge[2]
        if i==N-1: dist[edge[1]]=-inf
  for i in range(N):
    for edge in E:
      if dist[edge[1]] > dist[edge[0]] + edge[2]:
        dist[edge[1]] = dist[edge[0]] + edge[2]
  if dist[g] == -inf:return -1
  return max(0,-dist[g])
print(BellmanFord(0,N-1))
Buggy python submission (verdict: Runtime Error):
S=input()
sf=int(S[:2])
sb=int(S[3:])
if 1<=sf and sf<=12:
  if 1<=sb and sb<=12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1<=sb and sb<=12:
    print("YYMM")
  else:
    print("NA")

Fixed submission:
N,K=map(int,input().split())
ans=0
for i in range(N):
  p=i+1
  q=1/N
  while p<K:
    p*=2
    q*=1/2
  ans+=q

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import copy
import fractions
N=int(input())
A=list(map(int,input().split()))
ans=[]
def dfs(A):
  l=[]
  if len(A)==1:
    return A[0]
  for i in range(0,len(A),2):
    if i+1 != len(A):
      l.append(fractions.gcd(A[i],A[i+1]))
    else:
      l.append(A[i])
  return dfs(l)
  
  
for i in range(N):
  s=copy.deepcopy(A)
  s.pop(i)
  ans.append(dfs(s))

print(max(ans))

Fixed submission:
import copy
import fractions
N=int(input())
A=list(map(int,input().split()))
ans=[]
L=[0 for i in range(N)]
R=[0 for i in range(N)]
for i in range(N):
  if i != 0:
    L[i]=fractions.gcd(L[i-1],A[i-1])
    R[N-1-i]=fractions.gcd(R[N-i],A[N-i])

for i in range(N):
  ans.append(fractions.gcd(L[i],R[i]))

print(max(ans))

Buggy python submission (verdict: Runtime Error):
import copy
import fractions
N=int(input())
A=list(map(int,input().split()))
ans=[]
def dfs(A):
  l=[]
  if len(A)==1:
    return A[0]
  for i in range(0,len(A),2):
    l.append(fractions.gcd(A[i],A[i+1]))
  return dfs(l)
  
  
for i in range(N):
  s=copy.deepcopy(A)
  s.pop(i)
  ans.append(dfs(s))

print(max(ans))

Fixed submission:
import copy
import fractions
N=int(input())
A=list(map(int,input().split()))
ans=[]
L=[0 for i in range(N)]
R=[0 for i in range(N)]
for i in range(N):
  if i != 0:
    L[i]=fractions.gcd(L[i-1],A[i-1])
    R[N-1-i]=fractions.gcd(R[N-i],A[N-i])

for i in range(N):
  ans.append(fractions.gcd(L[i],R[i]))

print(max(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
LR=[list(map(int,input().split())) for i in range(Q)]
I = []
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    I.append(1)
  else:
    I.append(0)
      
for i in range(Q):
  l=LR[i][0]-1
  r=LR[i][1]-1
  s=I[l:r]
  print(s.count(1))

Fixed submission:
N,Q=map(int,input().split())
S=input()
LR=[list(map(int,input().split())) for i in range(Q)]
I = [0 for i in range(N)]
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    I[i+1]=I[i]+1
  else:
    I[i+1]=I[i]
      
for i in range(Q):
  l=LR[i][0]-1
  r=LR[i][1]-1
  print(I[r]-I[l])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
LR=[list(map(int,input().split())) for i in range(Q)]
for i in range(Q):
  l=LR[i][0]-1
  r=LR[i][1]-1
  ans=0
  s=S[l:r+1]
  
  print(s.count("AC"))

Fixed submission:
N,Q=map(int,input().split())
S=input()
LR=[list(map(int,input().split())) for i in range(Q)]
I = [0 for i in range(N)]
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    I[i+1]=I[i]+1
  else:
    I[i+1]=I[i]
      
for i in range(Q):
  l=LR[i][0]-1
  r=LR[i][1]-1
  print(I[r]-I[l])

Buggy python submission (verdict: Time Limit Exceeded):
N,Q=map(int,input().split())
S=input()
LR=[list(map(int,input().split())) for i in range(Q)]
I=[]
for i in range(N-1):
  if S[i:i+2]=="AC":
    I.append(i)
for i in range(Q):
  l=LR[i][0]-1
  r=LR[i][1]-1
  ans=0
  for j in range(len(I)):
    if l<=I[j] and I[j]+1<=r:
        ans+=1
    if r<I[j]:
      break
  print(ans)

Fixed submission:
N,Q=map(int,input().split())
S=input()
LR=[list(map(int,input().split())) for i in range(Q)]
I = [0 for i in range(N)]
for i in range(N-1):
  if S[i]=="A" and S[i+1]=="C":
    I[i+1]=I[i]+1
  else:
    I[i+1]=I[i]
      
for i in range(Q):
  l=LR[i][0]-1
  r=LR[i][1]-1
  print(I[r]-I[l])
Buggy python submission (verdict: Time Limit Exceeded):
S=list(input())
ans=0
while 1:
  flag=0
  for i in range(len(S)-1):
    if S[i:i+2]==["0","1"] or S[i:i+2]==["1","0"]:
      del S[i:i+2]
      ans+=2
      flag=1
  
  if flag==0:
    break
print(ans)

Fixed submission:
S=list(input())
sum0=0
for i in range(len(S)):
  if S[i]=="0":
    sum0+=1
 
print(2*min(sum0,len(S)-sum0))
Buggy python submission (verdict: Time Limit Exceeded):
S = input()

suma,sumc,sumq=0,0,0
maxC=S.count("C")
maxQ=S.count("?")
mod=10**9+7  
ans=0

for i,s in enumerate(S):
  if s=="A":
    suma+=1
  elif s=="C":
    sumc+=1
  elif s=="?":
    sumq+=1
  
  if i==0 or i==len(S):
    continue
    
  if s=="?":
    k=maxQ-1
    ans+=suma*(maxC-sumc)*(3**k)%mod
    ans+=(sumq-1)*(maxC-sumc)*(3**(k-1))%mod
    ans+=suma*(maxQ-sumq)*(3**(k-1))%mod
    ans+=(sumq-1)*(maxQ-sumq)*(3**(k-2))%mod
  elif s=="B":
    k=maxQ
    ans+=suma*(maxC-sumc)*(3**k)%mod
    ans+=sumq*(maxC-sumc)*(3**(k-1))%mod
    ans+=suma*(maxQ-sumq)*(3**(k-1))%mod
    ans+=sumq*(maxQ-sumq)*(3**(k-2))%mod
  
print(int(ans%mod))

Fixed submission:
S = input()
mod=10**9+7

suma,sumc,sumq=0,0,0
maxC=S.count("C")%mod
maxQ=S.count("?")%mod
ans1,ans2,ans3,ans4=0,0,0,0

for i,s in enumerate(S):
  if s=="A":
    suma+=1
    suma%=mod
  elif s=="C":
    sumc+=1
    sumc%=mod
  elif s=="?":
    sumq+=1
    sumq%=mod
  
  if i==0 or i==len(S):
    continue
  
  if s=="?":
    ans2+=suma    *(maxC-sumc)%mod
    ans3+=(sumq-1)*(maxC-sumc)%mod
    ans3+=suma    *(maxQ-sumq)%mod
    ans4+=(sumq-1)*(maxQ-sumq)%mod
  elif s=="B":
    ans1+=suma*(maxC-sumc)%mod
    ans2+=sumq*(maxC-sumc)%mod
    ans2+=suma*(maxQ-sumq)%mod
    ans3+=sumq*(maxQ-sumq)%mod
    
ans1*=3**maxQ%mod
ans2*=3**(maxQ-1)%mod
ans3*=3**(maxQ-2)%mod
ans4*=3**(maxQ-3)%mod
ans=ans1+ans2+ans3+ans4
print(int(ans%mod))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
A,B_i,C,Q=[],[],[],[]

suma,sumc,sumq=0,0,0
for i,s in enumerate(S):
  if s=="A":
    suma+=1
  elif s=="C":
    sumc+=1
  elif s=="?":
    sumq+=1
    B_i.append(i)
  elif s=="B":
    B_i.append(i)
    
  A.append(suma)
  C.append(sumc)
  Q.append(sumq)
  
mod=10**9+7  
ans=0
for i in B_i:
  if i==0 or i==len(S):
    continue
  k=Q[-1]-Q[i]+Q[i-1]
  ans+=A[i-1]*(C[-1]-C[i])*(3**k)%mod
  ans+=Q[i-1]*(C[-1]-C[i])*(3**(k-1))%mod
  ans+=A[i-1]*(Q[-1]-Q[i])*(3**(k-1))%mod
  ans+=Q[i-1]*(Q[-1]-Q[i])*(3**(k-2))%mod
  
print(int(ans%mod))

Fixed submission:
S = input()
mod=10**9+7

suma,sumc,sumq=0,0,0
maxC=S.count("C")%mod
maxQ=S.count("?")%mod
ans1,ans2,ans3,ans4=0,0,0,0

for i,s in enumerate(S):
  if s=="A":
    suma+=1
    suma%=mod
  elif s=="C":
    sumc+=1
    sumc%=mod
  elif s=="?":
    sumq+=1
    sumq%=mod
  
  if i==0 or i==len(S):
    continue
  
  if s=="?":
    ans2+=suma    *(maxC-sumc)%mod
    ans3+=(sumq-1)*(maxC-sumc)%mod
    ans3+=suma    *(maxQ-sumq)%mod
    ans4+=(sumq-1)*(maxQ-sumq)%mod
  elif s=="B":
    ans1+=suma*(maxC-sumc)%mod
    ans2+=sumq*(maxC-sumc)%mod
    ans2+=suma*(maxQ-sumq)%mod
    ans3+=sumq*(maxQ-sumq)%mod
    
ans1*=3**maxQ%mod
ans2*=3**(maxQ-1)%mod
ans3*=3**(maxQ-2)%mod
ans4*=3**(maxQ-3)%mod
ans=ans1+ans2+ans3+ans4
print(int(ans%mod))
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A.sort()

def binary(l,i):
  r=N-1
  while l<r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N)):
    if x >= abs(A[j]-i):
      res = A[j]     
      x=abs(A[j]-i)
  return res


print(A[-1],binary(1,A[-1]/2))

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()

def binary(l,i):
  r=N-1
  while l<=r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N-1)):
    if x >= abs(A[j]-i):
      res = A[j]     
      x=abs(A[j]-i)
  return res


print(A[-1],binary(1,A[-1]/2))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)

def binary(l,i):
  r=N-1
  while l<=r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N)):
    if x >= abs(A[j]-i):
      res = A[j]
      x=abs(A[j]-i)
  return res

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
maximum=0
for i in range(N-1):
  c = binary(i+1,A[i]/2)
  cmb_i=cmb(A[i],c)
  if maximum<cmb_i:
    ans1=A[i];ans2=c
    maximum=cmb_i

print(ans1,ans2)
  
    

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
A.sort()

def binary(l,i):
  r=N-1
  while l<=r:
    m=(l+r)//2
    if A[m]==i:
      return A[m]
    elif A[m]>i:
      r=m-1
    else:
      l=m+1
  x=abs(A[m]-i)
  for j in range(max(0,m-2),min(m+3,N-1)):
    if x >= abs(A[j]-i):
      res = A[j]     
      x=abs(A[j]-i)
  return res


print(A[-1],binary(1,A[-1]/2))
Buggy python submission (verdict: Runtime Error):
S_d,T = list(input()),list(input())

if len(S_d) < len(T):
  print("UNRESTORABLE");exit()

flag = 1
for i in range(-len(T),-len(S_d)-1,-1):
  key = 0
  for j in range(len(T)):
    if S_d[i+j]=="?" or S_d[i+j]==T[j]:
      key+=1
    else:
      break
  if key == len(T):
    st=len(S_d)+i
    break
  else:
    st=-1

if st==-1:
  print(UNRESTORABLE)
else:
  for i in range(len(S_d)):
    if st <= i and i < st+len(T):
      print(T[i-st],end="")
    elif S_d[i]=="?":
      print("a",end="")
    else:
      print(S_d[i],end="")
      

Fixed submission:
S_d,T = list(input()),list(input())

if len(S_d) < len(T):
  print("UNRESTORABLE");exit()

flag = 1
for i in range(-len(T),-len(S_d)-1,-1):
  key = 0
  for j in range(len(T)):
    if S_d[i+j]=="?" or S_d[i+j]==T[j]:
      key+=1
    else:
      break
  if key == len(T):
    st=len(S_d)+i
    break
  else:
    st=-1

if st==-1:
  print("UNRESTORABLE")
else:
  for i in range(len(S_d)):
    if st <= i and i < st+len(T):
      print(T[i-st],end="")
    elif S_d[i]=="?":
      print("a",end="")
    else:
      print(S_d[i],end="")

Buggy python submission (verdict: Runtime Error):
S_d,T = list(input()),list(input())

if len(S_d) < len(T):
  print("UNRESTORABLE");exit()

flag = 1
for i in range(-len(T),-len(S_d)-1,-1):
  key = 0
  for j in range(len(T)):
    if S_d[i+j]=="?" or S_d[i+j]==T[j]:
      key+=1
  if key == len(T):
    st=len(S_d)+i
    break
  else:
    st=-1

if st==-1:
  print(UNRESTORABLE)
else:
  for i in range(len(S_d)):
    if st <= i and i < st+len(T):
      print(T[i-st],end="")
    elif S_d[i]=="?":
      print("a",end="")
    else:
      print(S_d[i],end="")
      

Fixed submission:
S_d,T = list(input()),list(input())

if len(S_d) < len(T):
  print("UNRESTORABLE");exit()

flag = 1
for i in range(-len(T),-len(S_d)-1,-1):
  key = 0
  for j in range(len(T)):
    if S_d[i+j]=="?" or S_d[i+j]==T[j]:
      key+=1
    else:
      break
  if key == len(T):
    st=len(S_d)+i
    break
  else:
    st=-1

if st==-1:
  print("UNRESTORABLE")
else:
  for i in range(len(S_d)):
    if st <= i and i < st+len(T):
      print(T[i-st],end="")
    elif S_d[i]=="?":
      print("a",end="")
    else:
      print(S_d[i],end="")
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())
a_g=[];b_g=[]
for i in range(N):
  a_g.append(list(input()))
for i in range(M):
  b_g.append(list(input()))

for i in range(N-M):
  for j in range(N-M):
    flag=1
    for k in range(M):
      for l in range(M):
        if a_g[k+i][l+j] != b_g[k][l]:
          flag=0
          l=M;k=M
    if flag:
      print("Yes");exit()
print("No")

Fixed submission:
N,M = map(int,input().split())
a_g=[];b_g=[]
for i in range(N):
  a_g.append(list(input()))
for i in range(M):
  b_g.append(list(input()))

for i in range(N-M+1):
  for j in range(N-M+1):
    flag=1
    for k in range(M):
      for l in range(M):
        if a_g[k+i][l+j] != b_g[k][l]:
          flag=0
          break
    if flag:
      print("Yes");exit()
print("No")
Buggy python submission (verdict: Runtime Error):
import collections
N=int(input())
A=collections.Counter(list(map(int,input().split())))
if N%2==0:
  for i in range(0,N,2):
    if i%2==0 and A[i]==0:
      pass
    elif i%2==a and A[i]==2:
      pass
    else:
        print(0);exit(0)
else:
  for i in range(N):
    if i==0 and A[i]==1:
      continue
    if i%2==0 and A[i]==2:
      pass
    elif i%2==1 and A[i]==0:
      pass
    else:
      print(0);exit(0)
print(pow(2,N//2,10**9+7 ))

Fixed submission:
import collections
N=int(input())
A=collections.Counter(list(map(int,input().split())))
if N%2==0:
  for i in range(0,N,2):
    if i%2==0 and A[i]==0:
      pass
    elif i%2==1 and A[i]==2:
      pass
    else:
        print(0);exit(0)
else:
  for i in range(N):
    if i==0 and A[i]==1:
      continue
    if i%2==0 and A[i]==2:
      pass
    elif i%2==1 and A[i]==0:
      pass
    else:
      print(0);exit(0)
print(pow(2,N//2,10**9+7 ))

Buggy python submission (verdict: Runtime Error):
import collections
N=int(input())
A=collections.Counter(list(map(int,input().split())))
if N%2==0:
  for i in range(0,N,2):
    if i%2==0 and A[i]==0:
      pass
    elif i%2==a and A[i]==2:
      pass
    else:
        print(0);exit()
else:
  for i in range(N):
    if i==0 and A[i]==1:
      continue
    if i%2==0 and A[i]==2:
      pass
    elif i%2==1 and A[i]==0:
      pass
    else:
      print(0);exit()
print(pow(2,N//2,10**9+7 ))

Fixed submission:
import collections
N=int(input())
A=collections.Counter(list(map(int,input().split())))
if N%2==0:
  for i in range(0,N,2):
    if i%2==0 and A[i]==0:
      pass
    elif i%2==1 and A[i]==2:
      pass
    else:
        print(0);exit(0)
else:
  for i in range(N):
    if i==0 and A[i]==1:
      continue
    if i%2==0 and A[i]==2:
      pass
    elif i%2==1 and A[i]==0:
      pass
    else:
      print(0);exit(0)
print(pow(2,N//2,10**9+7 ))

Buggy python submission (verdict: Runtime Error):
import collections
N=int(input())
A=collections.Counter(list(map(int,input().split())))
if N%2==0:
  for i in range(0,N,2):
    if i%2==0 and A[i]==0:
      pass
    elif i%2==a and A[i]==2:
      pass
    else:
        print(0);exit()
  print(2**(N//2))
else:
  for i in range(N):
    if i==0:
      if A[i]!=1:
        print(0);exit()
    elif i%2==0 and A[i]==2:
      pass
    elif i%2==1 and A[i]==0:
      pass
    else:
      print(0);exit()
  print(2**(N//2))

Fixed submission:
import collections
N=int(input())
A=collections.Counter(list(map(int,input().split())))
if N%2==0:
  for i in range(0,N,2):
    if i%2==0 and A[i]==0:
      pass
    elif i%2==1 and A[i]==2:
      pass
    else:
        print(0);exit(0)
else:
  for i in range(N):
    if i==0 and A[i]==1:
      continue
    if i%2==0 and A[i]==2:
      pass
    elif i%2==1 and A[i]==0:
      pass
    else:
      print(0);exit(0)
print(pow(2,N//2,10**9+7 ))
Buggy python submission (verdict: Runtime Error):
IN = iter(Input.split('\n')).__next__
def input():
    return IN()
#ここから先

S=input()
T=[]

l=-1
while l>=-len(S):
    if S[l]=="r":
        if l-2<-len(S):
            print("NO");break
        elif S[l-2]=="s":
            T+="eraser"[::-1]
            l-=6
        else:
            T+="dreamer"[::-1]
            l-=7
    elif S[l]=="e":
        T+="erase"[::-1]
        l-=5
    elif S[l]=="m":
        T+="dream"[::-1]
        l-=5
    else:
        print("NO");break
        
if S=="".join(T[::-1]):
    print("YES")


Fixed submission:
S=input()
T=[]

l=-1
while l-2>=-len(S):
    k=S[l:l-3:-1]
    if k=="mae":
        T+="dream"[::-1]
        l-=5
    elif k=="rem":
        T+="dreamer"[::-1]
        l-=7
    elif k=="esa":
        T+="erase"[::-1]
        l-=5
    elif k=="res":
        T+="eraser"[::-1]
        l-=6
    else:
        break
if S=="".join(T[::-1]):
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
S=list(input())
ans=0
for i in range(2**(len(S)-1)):
  bin_i= format(i, 'b')
  bin_i=str(bin_i.zfill(len(S)-1))
  s=0
  l=int(S[0])
  for j,k in enumerate(bin_i):
    if k=="0":
      l=l*10+int(S[j+1])
    else:
      s+=l
      l=int(S[j+1])
      
    if j==len(S)-2:
        s+=l
  ans+=s
print(ans)

Fixed submission:
S=list(input())
ans=0

for x in range(2**(len(S)-1)):
  bin_x = str(format(x,str(len(S)-1)+"b"))[::-1]
  
  l=0
  res=0
  for r,i in enumerate(bin_x):
    if i == "1":
      res+=int("".join(S[l:r+1]))
      l=r+1
  res+=int("".join(S[l:len(S)]))
  ans+=res
print(ans)
Buggy python submission (verdict: Runtime Error):
a = list(input())
ans = []
for b in a:
    if  b == "0":
        ans.append("0")
    elif b == "1":
        ans.append("1")
    else:
        ans.pop()
print("".join(ans))

Fixed submission:
a = list(input())
ans = []
for b in a:
    if  b == "0":
        ans.append("0")
    elif b == "1":
        ans.append("1")
    elif len(ans) != 0:
        ans.pop()
print("".join(ans))
Buggy python submission (verdict: Runtime Error):
S = input()
if len(S)==2 and s[0]==s[1]:
    print(1,2);exit()
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]:
        print(i+1,i+3);exit()
print("-1 -1")

Fixed submission:
S = input()
if len(S)==2 and S[0]==S[1]:
    print(1,2);exit()
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]:
        print(i+1,i+3);exit()
print("-1 -1")

Buggy python submission (verdict: Runtime Error):
[InternetShortcut]
URL=https://atcoder.jp/contests/abc043/custom_test
import collections

S = list(input())
n = collections.Counter(S).most_common()[0][1]
for i in range(2, min(2*n,len(S)+1)):
    for j in range(0,len(S)-(i-1)):
        s = S[j:j+i]
        s_com = collections.Counter(s).most_common()
        for com in s_com:
            if com[1] >= i//2+1:
                print(j,j+i);exit()
            elif com[1] <i//2+1:
                break

print("-1 -1")

Fixed submission:
S = input()
if len(S)==2 and S[0]==S[1]:
    print(1,2);exit()
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]:
        print(i+1,i+3);exit()
print("-1 -1")
Buggy python submission (verdict: Time Limit Exceeded):
N,M = map(int,input().split())
XY = [list(map(int,input().split())) for i in range(M)]
Q = [1 for i in range(N)]

dp = [[0 for i in range(N)] for i in range(M+1)] #dp[m][n]
dp[0][0]=1

for i in range(1,M+1):
  x=XY[i-1][0]
  y=XY[i-1][1]
  for j in range(N):
    dp[i][j]=dp[i-1][j]

  if dp[i-1][x-1]>=1:
    if Q[x-1]==1:
      dp[i][x-1]=0
    else:
      dp[i][x-1]=1
    dp[i][y-1]=dp[i-1][y-1]+1
  Q[x-1]-=1
  Q[y-1]+=1
  
ans=0
for i in range(N):
  if dp[M][i]>=1:
    ans+=1
print(ans)

Fixed submission:
N,M = map(int,input().split())
XY = [list(map(int,input().split())) for i in range(M)]
Q = [1 for i in range(N)]

dp = [0 for i in range(N)] #dp[m][n]
dp[0]=1

for i in range(1,M+1):
  x=XY[i-1][0]
  y=XY[i-1][1]

  if dp[x-1]>=1:
    if Q[x-1]==1:
      dp[x-1]=0
    else:
      dp[x-1]=1
    dp[y-1]+=1
  Q[x-1]-=1
  Q[y-1]+=1
  
ans=0
for i in range(N):
  if dp[i]>=1:
    ans+=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import itertools

N,L= map(int,input().split())
S = [input() for i in range(N)]
ans= ""
for i in S:
    ans = ans+i 
for i in itertools.permutations(S):
    tmp = ""
    for j in i:
        tmp = tmp + j
    if tmp < ans:
        ans = tmp
print(ans)
 

Fixed submission:
N,L= map(int,input().split())
S = [input() for i in range(N)]
S.sort()
for a in S:
    print(a,end ="")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
res=0
for i in range(1,n+1):
  for j in range(i,n+1,i):
    res+=j
print(res)


Fixed submission:
n=int(input())
res=0
for i in range(1,n+1):
  ahaha=n//i
  res+=(i+ahaha*i)*ahaha//2
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
res=0
table=[1]*(n+1)
for i in range(2,n+1):
  for j in range(i,n+1,i):
    table[j]+=1
  res+=table[i]*i
print(res+1)


Fixed submission:
n=int(input())
res=0
for i in range(1,n+1):
  ahaha=n//i
  res+=(i+ahaha*i)*ahaha//2
print(res)