Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
R,C,K=map(int,input().split())
value=[[0]*(C+1) for i in range(R+1)]
for i in range(K):
  r,c,v=map(int,input().split())
  value[r][c]=v
DP0=[[0]*(C+1) for i in range(R+1)]
DP1=[[0]*(C+1) for i in range(R+1)]
DP2=[[0]*(C+1) for i in range(R+1)]
DP3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    v=value[i][j]
    DP0[i][j]=max(DP0[i][j-1],DP1[i-1][j],DP2[i-1][j],DP3[i-1][j])
    DP1[i][j]=max(DP0[i-1][j]+v,DP1[i-1][j]+v,DP2[i-1][j]+v,
                  DP3[i-1][j]+v,DP1[i][j-1],DP0[i][j-1]+v)
    DP2[i][j]=max(DP1[i][j-1]+v,DP2[i][j-1])
    DP3[i][j]=max(DP2[i][j-1]+v,DP3[i][j-1])

    
print(max(DP0[R][C],DP1[R][C],DP2[R][C],DP3[R][C]))

Fixed submission:
R,C,K=map(int,input().split())
value=[[0]*(C+1) for i in range(R+1)]
for i in range(K):
  r,c,v=map(int,input().split())
  value[r][c]=v
DP0=[[0]*(C+1) for i in range(R+1)]
DP1=[[0]*(C+1) for i in range(R+1)]
DP2=[[0]*(C+1) for i in range(R+1)]
DP3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    v=value[i][j]
    a=DP0[i][j-1]
    b=DP1[i][j-1]
    c=DP1[i-1][j]
    d=DP2[i-1][j]
    e=DP3[i-1][j]
    f=DP2[i][j-1]
    DP0[i][j]=max(a,c,d,e)
    DP1[i][j]=max(DP0[i-1][j]+v,c+v,d+v,e+v,b,a+v)
    DP2[i][j]=max(b+v,f)
    DP3[i][j]=max(f+v,DP3[i][j-1])

print(max(DP0[R][C],DP1[R][C],DP2[R][C],DP3[R][C]))

Buggy python submission (verdict: Time Limit Exceeded):
R,C,K=map(int,input().split())
value=[[0]*(C+1) for i in range(R+1)]
for i in range(K):
  r,c,v=map(int,input().split())
  value[r][c]=v
DP0=[[0]*(C+1) for i in range(R+1)]
DP1=[[0]*(C+1) for i in range(R+1)]
DP2=[[0]*(C+1) for i in range(R+1)]
DP3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    DP0[i][j]=max(DP0[i][j-1],DP1[i-1][j],DP2[i-1][j],DP3[i-1][j])
    DP1[i][j]=max(DP0[i-1][j]+value[i][j],DP1[i-1][j]+value[i][j],DP2[i-1][j]+value[i][j],
                  DP3[i-1][j]+value[i][j],DP1[i][j-1],DP0[i][j-1]+value[i][j])
    DP2[i][j]=max(DP1[i][j-1]+value[i][j],DP2[i][j-1])
    DP3[i][j]=max(DP2[i][j-1]+value[i][j],DP3[i][j-1])

    
print(max(DP0[R][C],DP1[R][C],DP2[R][C],DP3[R][C]))

Fixed submission:
R,C,K=map(int,input().split())
value=[[0]*(C+1) for i in range(R+1)]
for i in range(K):
  r,c,v=map(int,input().split())
  value[r][c]=v
DP0=[[0]*(C+1) for i in range(R+1)]
DP1=[[0]*(C+1) for i in range(R+1)]
DP2=[[0]*(C+1) for i in range(R+1)]
DP3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
  for j in range(1,C+1):
    v=value[i][j]
    a=DP0[i][j-1]
    b=DP1[i][j-1]
    c=DP1[i-1][j]
    d=DP2[i-1][j]
    e=DP3[i-1][j]
    f=DP2[i][j-1]
    DP0[i][j]=max(a,c,d,e)
    DP1[i][j]=max(DP0[i-1][j]+v,c+v,d+v,e+v,b,a+v)
    DP2[i][j]=max(b+v,f)
    DP3[i][j]=max(f+v,DP3[i][j-1])

print(max(DP0[R][C],DP1[R][C],DP2[R][C],DP3[R][C]))
Buggy python submission (verdict: Time Limit Exceeded):
import math
N,K=map(int,input().split())
import heapq
A=list(map(int,input().split()))

h=[(-A[i],1) for i in range(len(A))]
heapq.heapify(h)
for i in range(K):
  a=heapq.heappop(h)
  b=a[0]
  c=a[1]
  heapq.heappush(h,(c*b/(c+1),c+1))


ans=heapq.heappop(h)
print(math.ceil(-ans[0]))


Fixed submission:
import math
N,K=map(int,input().split())
import heapq
A=list(map(int,input().split()))

def isok(x):
  c=0
  for i in range(N):
    c+=math.ceil(A[i]/x)-1
  if c<=K:
    return True
  else:
    return False
start=0
end=max(A)
mid=(start+end)//2
while end-start>1:
  mid=(start+end)//2
  if isok(mid)==True:
    end=mid
  else:
    start=mid
print(end)

Buggy python submission (verdict: Time Limit Exceeded):
import math
N,K=map(int,input().split())
import heapq
A=list(map(int,input().split()))
h=[]
for i in range(len(A)):
  heapq.heappush(h,(-A[i],1))
for i in range(K):
  a=heapq.heappop(h)
  b=a[0]
  c=a[1]
  heapq.heappush(h,(c*b/(c+1),c+1))


ans=heapq.heappop(h)
print(math.ceil(-ans[0]))

Fixed submission:
import math
N,K=map(int,input().split())
import heapq
A=list(map(int,input().split()))

def isok(x):
  c=0
  for i in range(N):
    c+=math.ceil(A[i]/x)-1
  if c<=K:
    return True
  else:
    return False
start=0
end=max(A)
mid=(start+end)//2
while end-start>1:
  mid=(start+end)//2
  if isok(mid)==True:
    end=mid
  else:
    start=mid
print(end)
Buggy python submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(N-1)]
for i in range(N-1):
  if A[i]<A[i+1]:
    B[i]=1
B=[0]+B
money=1000
tmp=0
up=[]
down=[]
for i in range(N-1):
  if B[i]==0 and B[i+1]==1:
    up.append(i)
  if B[i]==1 and B[i+1]==0:
    down.append(i)
   
if up:
  if down==[]:
    down.append(N-1)
  if down!=[] and down[-1]<up[-1]:
    down.append(N-1)

for i in range(len(up)):
  k=bisect.bisect_left(down,up[i])
  print(k)
  money+=(A[down[k]]-A[up[i]])*(money//A[up[i]])     
print(money)


Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(N-1)]
for i in range(N-1):
  if A[i]<A[i+1]:
    B[i]=1
B=[0]+B
money=1000
tmp=0
up=[]
down=[]
for i in range(N-1):
  if B[i]==0 and B[i+1]==1:
    up.append(i)
  if B[i]==1 and B[i+1]==0:
    down.append(i)
import bisect   
if up:
  if down==[]:
    down.append(N-1)
  if down!=[] and down[-1]<up[-1]:
    down.append(N-1)

for i in range(len(up)):
  k=bisect.bisect_left(down,up[i])
  money+=(A[down[k]]-A[up[i]])*(money//A[up[i]])     
print(money)

Buggy python submission (verdict: Runtime Error):
A=list(map(int,input().split()))
B=[0 for i in range(N-1)]
for i in range(N-1):
  if A[i]<A[i+1]:
    B[i]=1
B=[0]+B
money=1000
tmp=0
up=[]
down=[]
for i in range(N-1):
  if B[i]==0 and B[i+1]==1:
    up.append(i)
  if B[i]==1 and B[i+1]==0:
    down.append(i)
   
if up:
  if down==[]:
    down.append(N-1)
  if down!=[] and down[-1]<up[-1]:
    down.append(N-1)

for i in range(len(up)):
  k=bisect.bisect_left(down,up[i])
  print(k)
  money+=(A[down[k]]-A[up[i]])*(money//A[up[i]])     
print(money)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(N-1)]
for i in range(N-1):
  if A[i]<A[i+1]:
    B[i]=1
B=[0]+B
money=1000
tmp=0
up=[]
down=[]
for i in range(N-1):
  if B[i]==0 and B[i+1]==1:
    up.append(i)
  if B[i]==1 and B[i+1]==0:
    down.append(i)
import bisect   
if up:
  if down==[]:
    down.append(N-1)
  if down!=[] and down[-1]<up[-1]:
    down.append(N-1)

for i in range(len(up)):
  k=bisect.bisect_left(down,up[i])
  money+=(A[down[k]]-A[up[i]])*(money//A[up[i]])     
print(money)
Buggy python submission (verdict: Runtime Error):
N=int(input())
X=input()
X10=int(X,2)
one=X.count('1')
a=X10%(one-1)
b=X10%(one+1)
c=one-1
d=one+1
def popcount(n):
  c=format(n,'b').count('1')
  return n%c
def f(n):
  count=0
  while n>0:
    n=popcount(n)
    count+=1
  return count

for i in range(N):
  if X[i]=='1':
    Y=(a-pow(2,N-i-1,c))%c
    print(f(Y)+1)
  if X[i]=='0':
    Y=(b+pow(2,N-i-1,d))%d
    print(f(Y)+1)

Fixed submission:
N=int(input())
X=input()
X10=int(X,2)
one=X.count('1')
def popcount(n):
  c=format(n,'b').count('1')
  if c!=0:
    return n%c
  else:
    return 0
def f(n):
  count=0
  while n>0:
    n=popcount(n)
    count+=1
  return count
if one==1:
  e=X10%2
  for i in range(N):
    if X[i]=='0':
      Y=e+pow(2,N-i-1,2)
      print(f(Y)+1)
     
    elif X[i]=='1':
      print(0)
if one==0:
  for i in range(N):
    print(1)
if one>1:
  a=X10%(one-1)
  b=X10%(one+1)
  c=one-1
  d=one+1
  for i in range(N):
    if X[i]=='1':
      Y=(a-pow(2,N-i-1,c))%c
      print(f(Y)+1)
    if X[i]=='0':
      Y=(b+pow(2,N-i-1,d))%d
      print(f(Y)+1)

Buggy python submission (verdict: Runtime Error):
N=int(input())
X=input()
X10=int(X,2)
one=X.count('1')
a=X10%(one-1)
b=X10%(one+1)
c=one-1
d=one+1
def popcount(n):
  c=format(n,'b').count('1')
  if c==0:
    print(n)
  return n%c
def f(n):
  count=0
  while n>0:
    n=popcount(n)
    count+=1
  return count

for i in range(N):
  if X[i]=='1':
    Y=(a-pow(2,N-i-1,c))%c
    print(f(Y)+1)
  if X[i]=='0':
    Y=(b+pow(2,N-i-1,d))%d
    print(f(Y)+1)
 

Fixed submission:
N=int(input())
X=input()
X10=int(X,2)
one=X.count('1')
def popcount(n):
  c=format(n,'b').count('1')
  if c!=0:
    return n%c
  else:
    return 0
def f(n):
  count=0
  while n>0:
    n=popcount(n)
    count+=1
  return count
if one==1:
  e=X10%2
  for i in range(N):
    if X[i]=='0':
      Y=e+pow(2,N-i-1,2)
      print(f(Y)+1)
     
    elif X[i]=='1':
      print(0)
if one==0:
  for i in range(N):
    print(1)
if one>1:
  a=X10%(one-1)
  b=X10%(one+1)
  c=one-1
  d=one+1
  for i in range(N):
    if X[i]=='1':
      Y=(a-pow(2,N-i-1,c))%c
      print(f(Y)+1)
    if X[i]=='0':
      Y=(b+pow(2,N-i-1,d))%d
      print(f(Y)+1)
Buggy python submission (verdict: Runtime Error):
N,M=map(int,input().split())
list=[0 for i in range(5*10**5+1)]
mod=10**9+7
list[0]=1
for i in range(len(list)-1):
  list[i+1]=list[i]*(i+1)%mod
def c(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)*pow(list[n],mod-2,mod)
  return a
def p(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)
  return a
ans=pow(p(M,N),2)
g=pow(list[M-N],mod-2,mod)
g2=pow(g,2,mod)
nn=list[N]
mm=list[M]
nmg=nn*mm*g2%mod
for i in range(1,N+1):
  ans+=nmg*pow(list[N-i],mod-2,mod)*pow(list[i],mod-2,mod)*list[M-i]*(-1)**i
  ans%=mod
print(ans)


Fixed submission:
a=int(input())
print(int(a+a**2+a**3))
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
list=[0 for i in range(5*10**5+1)]
mod=10**9+7
list[0]=1
for i in range(len(list)-1):
  list[i+1]=list[i]*(i+1)%mod
def c(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)*pow(list[n],mod-2,mod)
  return a
def p(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)
  return a
ans=pow(p(M,N),2)
g=pow(list[M-N],mod-2,mod)
g2=pow(g,2,mod)
nn=list[N]
mm=list[M]
nmg=nn*mm*g2%mod
for i in range(1,N+1):
  ans+=nmg*pow(list[N-i],mod-2,mod)*pow(list[i],mod-2,mod)*list[M-i]*(-1)**i
  ans%=mod
print(ans)

Fixed submission:
N,M=map(int,input().split())
list=[0 for i in range(5*10**5+1)]
mod=10**9+7
list[0]=1
for i in range(len(list)-1):
  list[i+1]=list[i]*(i+1)%mod
def c(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)*pow(list[n],mod-2,mod)
  return a
def p(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)
  return a
ans=pow(p(M,N),2)
g=pow(list[M-N],mod-2,mod)
g2=pow(g,2,mod)
nn=list[N]
mm=list[M]
nmg=nn*mm*g2%mod
for i in range(1,N+1):
  ans+=nmg*pow(list[N-i],mod-2,mod)*pow(list[i],mod-2,mod)*list[M-i]*(-1)**i
  ans%=mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
list=[0 for i in range(5*10**5+1)]
mod=10**9+7
list[0]=1
for i in range(len(list)-1):
  list[i+1]=list[i]*(i+1)%mod
def c(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)*pow(list[n],mod-2,mod)
  return a
def p(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)
  return a
ans=p(M,N)**2
for i in range(1,N+1):
  ans+=c(N,i)*(-1)**i*p(M,i)*p(M-i,N-i)**2%mod
  ans%=mod
print(ans)

Fixed submission:
N,M=map(int,input().split())
list=[0 for i in range(5*10**5+1)]
mod=10**9+7
list[0]=1
for i in range(len(list)-1):
  list[i+1]=list[i]*(i+1)%mod
def c(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)*pow(list[n],mod-2,mod)
  return a
def p(m,n):
  a=list[m]*pow(list[m-n],mod-2,mod)
  return a
ans=pow(p(M,N),2)
g=pow(list[M-N],mod-2,mod)
g2=pow(g,2,mod)
nn=list[N]
mm=list[M]
nmg=nn*mm*g2%mod
for i in range(1,N+1):
  ans+=nmg*pow(list[N-i],mod-2,mod)*pow(list[i],mod-2,mod)*list[M-i]*(-1)**i
  ans%=mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
c=1
for i in range(N):
  c=c*A[i]
if c>10**18:
  print(-1)
else:
  print(c)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
c=1
if 0 in A:
  print(0)
else: 
  for i in range(N):
    c=c*A[i]
    if c>10**18:
      c=-1
      break
    
  print(c)
Buggy python submission (verdict: Runtime Error):
N=int(input())
mod=10**9+7
Azero=0
Bzero=0
both=0
plus={}
minus={}
import math
for i in range(N):
  A,B=map(int,input().split())
  if A==0 and B==0:
    both+=1
  elif A==0 and B!=0:
    Azero+=1
  elif A!=0 and B==0:
    Bzero+=1
  else:
    K=math.gcd(A,B)
    A=int(A/K)
    B=int(B/K)
    if A/B>0:
      if A<0:
        A,B=-A,-B
      if (A,B) in plus:
        plus[(A,B)]+=1
      else:
        plus[(A,B)]=1
    else:
      if A<0:
        A,B=-A,-B
      if (A,B) in minus:
        minus[(A,B)]+=1
      else:
        minus[(A,B)]=1

L=[]
if Azero>0 and Bzero>0:
  L.append((Azero,Bzero))
for k,v in plus.items():
  if (k[1],-k[0]) in minus:
    L.append((v,minus[(k[1],-k[0])]))
ans=0
for i in range(len(L)):
  N-=L[i][0]+L[i][1]
N-=both
c=1

for i in range(len(L)):
  c*=(pow(2,L[i][0],mod)+pow(2,L[i][1],mod)-1)
  c%=mod

ans=(c*pow(2,N,mod)-1)%mod

print(ans+both)

Fixed submission:
N,M=map(int,input().split())
g=[[] for _ in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  g[A-1].append(B-1)
  g[B-1].append(A-1)
from collections import deque  
queue = deque([0])
d = [None] * N
d[0] = 0 
while queue:
  v = queue.popleft()
  for i in g[v]:
    if d[i] is None:
      d[i] = d[v] + 1
      queue.append(i)
  
l=[0]*(N-1)
for i in range(1,N):
  for j in g[i]:
    if d[j]==(d[i]-1):
      l[i-1]=j+1
      break
if 0 in l:
  print('No')
else:
  print('Yes')
  for i in range(len(l)):
    print(l[i])
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[[0 for i in range(N)] for j in range(N)] 
P=[0 for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  P[A-1]+=1
  P[B-1]+=1
  if H[A-1]>H[B-1]:
    L[A-1][B-1]+=1
  if H[B-1]>H[A-1]:  
    L[B-1][A-1]+=1

count=0 
for i in range(N):
  if P[i]==sum(L[i]):
    count+=1
print(count)

Fixed submission:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0 for i in range(N)] 
P=[0 for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  P[A-1]+=1
  P[B-1]+=1
  if H[A-1]>H[B-1]:
    L[A-1]+=1
  if H[B-1]>H[A-1]:  
    L[B-1]+=1

count=0 
for i in range(N):
  if P[i]==L[i]:
    count+=1
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[[0 for i in range(N)] for j in range(N)] 
for i in range(M):
  A,B=map(int,input().split())
  L[A-1][B-1]+=1
  L[B-1][A-1]+=1
count=[0 for i in range(N)]

for i in range(N):
  for j in range(N):
    if L[i][j]!=0 and H[i]>H[j]:
      count[i]+=1
c=0
for i in range(N):
  if count[i]==(N-L[i].count(0)):
    c+=1
print(c)

Fixed submission:
N,M=map(int,input().split())
H=list(map(int,input().split()))
L=[0 for i in range(N)] 
P=[0 for i in range(N)]
for i in range(M):
  A,B=map(int,input().split())
  P[A-1]+=1
  P[B-1]+=1
  if H[A-1]>H[B-1]:
    L[A-1]+=1
  if H[B-1]>H[A-1]:  
    L[B-1]+=1

count=0 
for i in range(N):
  if P[i]==L[i]:
    count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
S=input()
D=defaultdict(int)
D[0]=1
n=0
i=0
a=[0]*len(S)
for s in S[::-1]:
  n+=int(s)*10**i
  a[i]=n%2019
  i+=1


for i in range(len(a)):
  D[a[i]]+=1

ans=sum([i*(i-1)//2 for i in D.values()])
print(ans)     

Fixed submission:
from collections import defaultdict
S=input()
D=defaultdict(int)
D[0]=1
n=0
i=0
a=[0]*len(S)
b=1
for s in S[::-1]:
  n+=int(s)*b
  a[i]=n%2019
  i+=1
  b=(b*10)%2019


for i in range(len(a)):
  D[a[i]]+=1

ans=sum([i*(i-1)//2 for i in D.values()])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict
S=input()
D=defaultdict(int)
D[0]=1
s=0
a=[0]*len(S)
for i in range(len(S)):
  s+=int(S[len(S)-i-1])*10**i
  a[i]=s%2019


for i in range(len(a)):
  D[a[i]]+=1

ans=sum([i*(i-1)//2 for i in D.values()])
print(ans)  

Fixed submission:
from collections import defaultdict
S=input()
D=defaultdict(int)
D[0]=1
n=0
i=0
a=[0]*len(S)
b=1
for s in S[::-1]:
  n+=int(s)*b
  a[i]=n%2019
  i+=1
  b=(b*10)%2019


for i in range(len(a)):
  D[a[i]]+=1

ans=sum([i*(i-1)//2 for i in D.values()])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
s=int(S[len(S)-1])
a=[0,s]
for i in range(1,len(S)):
  s+=int(S[len(S)-i-1])*10**i
  a.append(s%2019)
q={}
for i in range(len(a)):
  if a[i] in q:
    q[a[i]]+=1
  else:
    q[a[i]]=1
c=0

for value in q.values():
  c+=value*(value-1)/2
print(int(c))

Fixed submission:
from collections import defaultdict
S=input()
D=defaultdict(int)
D[0]=1
n=0
i=0
a=[0]*len(S)
b=1
for s in S[::-1]:
  n+=int(s)*b
  a[i]=n%2019
  i+=1
  b=(b*10)%2019


for i in range(len(a)):
  D[a[i]]+=1

ans=sum([i*(i-1)//2 for i in D.values()])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
count=0
for i in range(len(S)):
  for j in range(i+1,len(S)):
    if int(S[i:j+1])%2019==0:
      count+=1
print(count)

Fixed submission:
from collections import defaultdict
S=input()
D=defaultdict(int)
D[0]=1
n=0
i=0
a=[0]*len(S)
b=1
for s in S[::-1]:
  n+=int(s)*b
  a[i]=n%2019
  i+=1
  b=(b*10)%2019


for i in range(len(a)):
  D[a[i]]+=1

ans=sum([i*(i-1)//2 for i in D.values()])
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
S=input()
r=S.count('R')
g=S.count('G')
b=S.count('B')
c=0
for i in range(N):
  for j in range(i+1,N):
    h=2*j-i
    if h<=N-1:
      if S[i]!=S[j] and S[i]!=S[h] and S[j]!=S[h]:
        c+=1
ans=r*g*b-c
print(ans)

Fixed submission:
import math
K=int(input())
c=0
for i in range(1,K+1):
  for j in range(i,K+1):
    for k in range(j,K+1):
      a=math.gcd(i,j)
      b=math.gcd(a,k)
      if i==j==k:
        c+=b
      elif i==j or j==k:
        c+=3*b
      else:
        c+=6*b
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
r=S.count('R')
g=S.count('G')
b=S.count('B')
c=0
for i in range(N):
  for j in range(i+1,N):
    if 2*j-i<=N-1:
      if S[i]!=S[j] and S[i]!=S[2*j-i] and S[j]!=S[2*j-i]:
        c+=1
ans=r*g*b-c
print(ans)

Fixed submission:
N=int(input())
S=input()
r=S.count('R')
g=S.count('G')
b=S.count('B')
c=0
for i in range(N):
  for j in range(i+1,N):
    h=2*j-i
    if h>=N:
      break
    if S[i]!=S[j] and S[i]!=S[h] and S[j]!=S[h]:
      c+=1
ans=r*g*b-c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
r=S.count('R')
g=S.count('G')
b=S.count('B')
c=0
for i in range(N):
  for j in range(i+1,N):
    if 2*j-i<=N-1:
      if S[i]!=S[j] and S[i]!=S[2*j-i] and S[j]!=S[2*j-i]:
        c+=1
ans=r*g*b-c
print(ans)

Fixed submission:
N=int(input())
S=input()
r=S.count('R')
g=S.count('G')
b=S.count('B')
c=0
for i in range(N):
  for j in range(i+1,N):
    h=2*j-i
    if h>=N:
      break
    if S[i]!=S[j] and S[i]!=S[h] and S[j]!=S[h]:
      c+=1
ans=r*g*b-c
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=input()
count=0
for i in range(N):
  for j in range(1,N-i//2):
    if (0<=i<=N-1 and 0<=i+j<=N-1 and 0<=i+2*j<=N-1):
      if S[i]!=S[i+j] and S[i+j]!=S[i+2*j] and S[i]!=S[i+2*j]:
        count+=1

r=0
g=0
for i in range(N):
  if S[i]=='R':
    r+=1
  if S[i]=='G':
    g+=1
print(r*g*(N-r-g)-count)

Fixed submission:
N=int(input())
S=input()
r=S.count('R')
g=S.count('G')
b=S.count('B')
c=0
for i in range(N):
  for j in range(i+1,N):
    h=2*j-i
    if h>=N:
      break
    if S[i]!=S[j] and S[i]!=S[h] and S[j]!=S[h]:
      c+=1
ans=r*g*b-c
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=int(input())
for i in range(N):
  A=list(map(str,input().split()))
  if A[0]=='1':
     S=S[::-1]
  else:
     if A[1]=='1':
       S=A[2]+S
     if A[1]=='2':
       S=S+A[2]
print(S)


Fixed submission:
from collections import deque
S=input()
N=int(input())
q=deque([S[i] for i in range(len(S))])

c=0
for i in range(N):
  A=list(map(str,input().split()))
  if A[0]=='1':
     c+=1
     c%=2
  else:
     if (c+int(A[1]))%2==1:
       q.appendleft(A[2])
     if (c+int(A[1]))%2==0:
       q.append(A[2])
s=''
if c==0:
  for i in range(len(q)):
    r=q.popleft()
    s+=r
if c==1:
  for i in range(len(q)):
    d=q.pop()
    s+=d
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
P=list(map(int,input().split()))

R=[]
for i in range(len(P)-K+1):
  R.append(sum(P[i:i+K]))
m=max(R) 
l=(m+K)/2
print(l)

Fixed submission:
N,K=map(int,input().split())
p=list(map(int,input().split()))
p=[(1+i)/2 for i in p]
ans=sum(p[0:K])
A=[ans]

for i in range(N-K):
  ans-=p[i]
  ans+=p[K+i]
  A.append(ans)
print(max(A))
Buggy python submission (verdict: Runtime Error):
N=int(input())
P=[0,0,0,0,0,0,0,0,0,0]
L=copy.deepcopy(P)
M=[L]*10
count=0
for i in range(1,N+1):
  a=int(str(i)[0])
  b=int(str(i)[-1])
  if L[b][a]!=0:
    count+=2*L[b][a]+1
  L[a][b]+=1

print(count)
    
  

Fixed submission:
N=int(input())
A=[[0 for i in range(10)] for j in range(10)]
for i in range(1,N+1):
  i=str(i)
  ii=len(i)
  A[int(i[0])][int(i[ii-1])]+=1
ans=0
for i in range(10):
  for j in range(10):
    ans+=A[i][j]*A[j][i]
print(ans)
Buggy python submission (verdict: Runtime Error):
N,K,M=map(int,input().split())
An=list(map(int,input().split()))
rest=M*N-sum(An)
if rest<=K:
        print(max(rest,0))
else:
        print(-1)

Fixed submission:
print(chr(ord(input())+1))
Buggy python submission (verdict: Runtime Error):
X=int(input())
if x==2:
  print(2)
else:
  for i in range(X,10**6):
    for j in range(2,i):
      if i%j==0:
        break
      if j==i-1:
        print(i)
        exit()


Fixed submission:
X=int(input())
if X==2:
  print(2)
else:
  for i in range(X,10**6):
    for j in range(2,i):
      if i%j==0:
        break
      if j==i-1:
        print(i)
        exit()
Buggy python submission (verdict: Runtime Error):
A1,A2,A3=map(int,input.split())
if A1+A2+A3>=22:
  print('bust')
else:
  print('win')

Fixed submission:
A1,A2,A3=map(int,input().split())
if A1+A2+A3>=22:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Runtime Error):
S=input()
n=len(str(S))
if n%2=1:
  count=0
  m=int((n-1)/2)
  for i in range(0,m):
    if S[i]!=S[n-i-1]:
      count+=1
else:
  count=0
  m=int(n/2)
  for i in range(0,m):
    if S[i]!=S[n-i-1]:
      count+=1
      
print(count)


  

Fixed submission:
S=input()
n=len(str(S))
if n%2==1:
  count=0
  m=int((n-1)/2)
  for i in range(0,m):
    if S[i]!=S[n-i-1]:
      count+=1
else:
  count=0
  m=int(n/2)
  for i in range(0,m):
    if S[i]!=S[n-i-1]:
      count+=1
      
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A=[format(A[i],'b').rjust(61,'0') for i in range(N)]
zero=[0 for i in range(61)]

for i in range(N):
   for j in range(61):
       if A[i][j]=='0':
         zero[60-j]+=1

mod=10**9+7       
ans=0
for i in range(61):
   ans+=(zero[i]*(N-zero[i]))%mod*pow(2,i,mod)
   ans%=mod
print(ans)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
  X=1<<i
  n=len([1 for a in A if a&X])
  ans+=X*n*(N-n)%mod
  ans%=mod
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A=list(map(int,input().split()))
A=[format(A[i],'b').rjust(61,'0') for i in range(N)]
zero=[0 for i in range(61)]
one=[0 for i in range(61)]
for i in range(N):
   for j in range(61):
       if A[i][j]=='0':
         zero[60-j]+=1
       if A[i][j]=='1':
         one[60-j]+=1
mod=10**9+7       
ans=0
for i in range(61):
   ans+=zero[i]*one[i]*pow(2,i,mod)
   ans%=mod
print(ans)
       

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
mod=10**9+7
ans=0
for i in range(60):
  X=1<<i
  n=len([1 for a in A if a&X])
  ans+=X*n*(N-n)%mod
  ans%=mod
print(ans)
Buggy python submission (verdict: Runtime Error):
N=int(input())
x=round(N/1.08)+1
if round(x*1.08)=N:
  print(x)
else:
  print(':(')

Fixed submission:
N=int(input())
import math
X=int(N//1.08+1)
if N//1.08==N/1.08:
  print(N/1.08)
else:
  if math.floor(X*1.08)==N:
    print(X)
  else:
    print(':(')