Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
X=(input())
ans=0
pre=[]
pre=X
    
while True:
    X=X.replace("ST","")
    if pre==X:
        break
    else:
        pre=X

print(len(X))


Fixed submission:
X=list(input())
N=len(X)
count=0

for x in X:
    if x=="S":
        count+=1
    else:
        if count>0:
            count-=1
            N-=2
print(N)

Buggy python submission (verdict: Time Limit Exceeded):
X=input()
pre="a"
while True:
    X=X.replace("ST","")
    if pre==X:
        break
    else:
        pre=X

print(len(X))


Fixed submission:
X=list(input())
N=len(X)
count=0

for x in X:
    if x=="S":
        count+=1
    else:
        if count>0:
            count-=1
            N-=2
print(N)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
s=input()
K=int(input())

ans=[]
#122
for item in s[:len(s)-1]:
    cost=(123-ord(item))
    if K>=cost:
        K-=cost
        ans.append("a")
    else:
        ans.append(item)

last=ord(s[-1])
if last+K>122:
    ans.append(chr(last+K-26))
else:
    ans.append(chr(last+K))

print("".join(ans))
    

Fixed submission:
s=list(input())
N=int(input())

apple=lambda c:ord(c)-ord("a")+1

l=[]
for i in range(len(s)):
    s[i]=apple(s[i])
    dif=27-s[i]
    if s[i]==1:
        pass
    elif dif<=N:
        N-=dif
        s[i]=1

s[-1]-=1
s[-1]=(s[-1]+N)%26
s[-1]+=1

kiss = lambda c: chr(c+96)
for i in range(len(s)):
    s[i]=kiss(s[i])

print("".join(s))
Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
N,A=map(int,input().split())

l=list(map(int,input().split()))
l.sort()
ans=[]

def dfs(num,i,count):
    num+=l[i]
    count+=1
    if num==A*count and num!=0:
        ans.append("A")#ここ何とかすれば終わり
    if num>A*count:
        return
    if i==len(l)-1:
        pass
    else:
        dfs(num,i+1,count)
    num-=l[i]
    count-=1
    if i==len(l)-1:
        pass
    else:
        dfs(num,i+1,count)

dfs(0,0,0)
print(len(ans))


Fixed submission:
# coding: utf-8
# Your code here!
N,A=map(int,input().split())

X=list(map(int,input().split()))

dp=[[0]*2501 for i in range(50)]

for x in X:
    for i in range(49)[::-1]:
        for index,item in enumerate(dp[i]):
            if item!=0:
                dp[i+1][index+x]+=dp[i][index]
    dp[0][x]+=1

ans=0
for i in range(50):
    ans+=dp[i][A*(i+1)]

print(ans)
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!
s=input()
judge=True

if s[0]==s[1] or s[1]==s[2] or s[0]==s[1]:
    print(0,2)
else:
    for i in range(3,len(s)):
        if s[i-2]==s[i-1] or s[i-2]==s[i]:
            print(i-2,i)
            judge=False
            break
    
    if judge:    
        print(-1,-1)

Fixed submission:
# coding: utf-8
# Your code here!
s=input()
N=len(s)
judge=True

if N<3:
    if s[0]==s[1]:
        print(1,2)
    else:
        print(-1,-1)
    
elif (s[0]==s[1] and s[0]!=s[2]) or (s[0]==s[2] and s[0]!=s[1]) or (s[1]==s[2] and s[1]!=s[0]):
    print(1,3)
    
elif (s[-3]==s[-2] and s[-3]!=s[-1])or (s[-3]==s[-1] and s[-3]!=s[-2])or (s[-2]==s[-1] and s[-2]!=s[-3]):
    print(N-2,N)
    
else:
    for i in range(2,N):
        if (s[i-2]==s[i-1] and s[i-2]!=s[i]) or (s[i-2]==s[i] and s[i-2]!=s[i-1]) or (s[i-1]==s[i] and s[i-1]!=s[i-2]):
            print(i-1,i+1)
            judge=False
            break
    
    if judge:
        print(-1,-1)
Buggy python submission (verdict: Runtime Error):
def bekijou(a,x):
  MOD = 1000000009
  ret = 1
  for _ in range(x):
    ret *= a
    ret %= MOD
    
n=int(input())
ret = 0
sum = bekijou(9,n)
MOD = 1000000009
ret = (2 * sum) % MOD
ret += MOD - bekijou(8,n)
ret = bekijou(10,n) + MOD - ret
print(ret)

Fixed submission:
def bekijou(a,x):
  MOD = 1000000007
  ret = 1
  for _ in range(x):
    ret *= a
    ret %= MOD
  return ret
    
n=int(input())
MOD = 1000000007
ret = (bekijou(10,n)+MOD-((2*bekijou(9,n)) % MOD)+bekijou(8,n))%MOD
print(ret)
Buggy python submission (verdict: Time Limit Exceeded):
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while 1:
    now += 1
    x = (x*10 +7) % k
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break


Fixed submission:
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while 1:
    now += 1
    x = (x*10 +7) % k
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break
    else:
      ok[x] = 1

Buggy python submission (verdict: Runtime Error):
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while now+=1:
    x = (x*10 +7) % k
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break


Fixed submission:
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while 1:
    now += 1
    x = (x*10 +7) % k
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break
    else:
      ok[x] = 1

Buggy python submission (verdict: Runtime Error):
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while now+=1:
    x = x*10 +7
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break

Fixed submission:
k = int(input())
ok = [0]*k
x=7 % k
ok[x] = 1
if x == 0:
  print(1)
else:
  now = 1
  while 1:
    now += 1
    x = (x*10 +7) % k
    if ok[x] == 1:
      print(-1)
      break
    elif x == 0:
      print(now)
      break
    else:
      ok[x] = 1
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

def gcd(a,b):
    while b:
        a, b = b, a % b
    return a

ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        #ans = ans + i #(i,i,i)
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = gcd(i,j)
                ans = ans + gcd(ij,k)

print(ans)


Fixed submission:
n = int(input())

def gcd(a,b):
    while b:
        a, b = b, a % b
    return a

ans = 0
if n == 1:
    ans = 1
else:
    for i in range(n):
        i = i + 1
        #ans = ans + i #(i,i,i)
        for j in range(n):
            j = j + 1
            for k in range(n):
                k = k + 1
                ij = gcd(i,j)
                ans = ans + gcd(ij,k)

print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
if m%2+n%2<2:
  print(n*m//2)
else:
  print(max(n*(m//2)+(n//2+1))


Fixed submission:
n,m=map(int,input().split())
if m==1 or n==1:
  print(1)
elif m%2+n%2<2:
  print(n*m//2)
else:
  print(n*(m//2)+(n//2+1))

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
if n%2==0:
  tmp=n
  n=m
  m=tmp
print(max(n*(m//2)+(n%2)*(n//2+1))


Fixed submission:
n,m=map(int,input().split())
if m==1 or n==1:
  print(1)
elif m%2+n%2<2:
  print(n*m//2)
else:
  print(n*(m//2)+(n//2+1))
Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
MAXH = H+1
DP = [float("inf")]*MAXH
DP[0] = 0
a = []
b = []
for i in range(N):
  A,B = map(int,input().split())
  a.append(A)
  b.append(B) 
for i in range(MAXH):
  if DP[i] == float("inf"):
    continue    
  for j in range(N):
        DP[min(i+a[j],H)] = min(DP[min(i+a[j],H)],DP[i]+b[j])
print(DP[H])


Fixed submission:
H,N = map(int,input().split())
MAXH = H+1
DP = [float("inf")]*MAXH
DP[0] = 0
a = [0]*N
b = [0]*N
for i in range(N):
  a[i],b[i] = map(int,input().split())
for i in range(MAXH):
  if DP[i] == float("inf"):
    continue    
  for j in range(N):
        DP[min(i+a[j],H)] = min(DP[min(i+a[j],H)],DP[i]+b[j])
print(DP[H])

Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
MAXH = H+1
DP = [float("inf")]*MAXH
DP[0] = 0
a = [0]*N
b = [0]*N
for i in range(N):
  a[i],b[i] = map(int,input().split())
for i in range(MAXH):
  if DP[i] == float("inf"):
    continue    
  for j in range(N):
        DP[min(i+a[j],H)] = min(DP[min(i+a[j],H)],DP[i]+b[j])
print(DP[H])


Fixed submission:
H,N = map(int,input().split())
MAXH = H+1
DP = [float("inf")]*MAXH
DP[0] = 0
a = [0]*N
b = [0]*N
for i in range(N):
  a[i],b[i] = map(int,input().split())
for i in range(MAXH):
  if DP[i] == float("inf"):
    continue    
  for j in range(N):
        DP[min(i+a[j],H)] = min(DP[min(i+a[j],H)],DP[i]+b[j])
print(DP[H])

Buggy python submission (verdict: Time Limit Exceeded):
H,N = map(int,input().split())
MAXH = H+10000
DP = [float("inf")]*MAXH
DP[0] = 0
a = [0]*N
b = [0]*N
for i in range(N):
  a[i],b[i] = map(int,input().split())
for i in range(MAXH):
  if DP[i] == float("inf"):
    continue    
  for j in range(N):
        DP[min(i+a[j],H)] = min(DP[min(i+a[j],H)],DP[i]+b[j])
print(DP[H])

Fixed submission:
H,N = map(int,input().split())
MAXH = H+1
DP = [float("inf")]*MAXH
DP[0] = 0
a = [0]*N
b = [0]*N
for i in range(N):
  a[i],b[i] = map(int,input().split())
for i in range(MAXH):
  if DP[i] == float("inf"):
    continue    
  for j in range(N):
        DP[min(i+a[j],H)] = min(DP[min(i+a[j],H)],DP[i]+b[j])
print(DP[H])
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
if n<10 && m<10 :
  print(n*m)
else :
  print(-1)


Fixed submission:
n,m=map(int,input().split())
if n<10 and m<10 :
  print(n*m)
else :
  print(-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[n//2+1]-a[n//2])

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[n//2]-a[n//2-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[n/2+1]-a[n/2])


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[n//2]-a[n//2-1])

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a=sort(a)
print(a[n/2+1]-a[n/2])


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a.sort()
print(a[n//2]-a[n//2-1])
Buggy python submission (verdict: Runtime Error):
n=input()
a=list(map(int,input().split()))
n=sum(x<0 for x in a)
a=[map(abs,a)]
s=sum(a) if n%2==0 else sum(a)-min(a)*2
print(s)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[abs(x) for x in a]
ret=0
for i in range(n):
  if a[i]!=b[i]:
    ret+=1
ans=sum(b)
if ret%2:
  ans-=2*min(b)
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a=list(map(lambda x: abs(x),a))
neg_sum=sum(x<0 for x in a)
m = min(a)
s=sum(a)
s-=m if neg_sum%2
print(s)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=[abs(x) for x in a]
ret=0
for i in range(n):
  if a[i]!=b[i]:
    ret+=1
ans=sum(b)
if ret%2:
  ans-=2*min(b)
print(ans)
Buggy python submission (verdict: Runtime Error):
a=[int(input()) for i in range(5)]
k=int(input())
if abs(a[0]-a[5])>k:
  print(":(")
else:
  print("Yay!")

Fixed submission:
a=[int(input()) for i in range(5)]
k=int(input())
if abs(a[0]-a[4])>k:
  print(":(")
else:
  print("Yay!")
Buggy python submission (verdict: Runtime Error):
ret=0
m=10
for _ in range(6):
  y=int(input())
  ret+=(y+9)//10
  if y%10!=0:
    m=min(m,y%10)
print(ret-(10-m))

Fixed submission:
ret=0
m=10
for _ in range(5):
  y=int(input())
  ret+=(y+9)//10*10
  if y%10!=0:
    m=min(m,y%10)
print(ret-(10-m))
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
cnt=0
for i in range(min(a,b)):
  if i%a==0 && j%a==0:
    cnt+=1
  if cnt==c:
    print(i)
    break

Fixed submission:
a,b,k=map(int,input().split())
ret=0;
for i in reversed(range(min(a,b)+1)):
  if a%i==0 and b%i==0:
    ret+=1
  if ret==k:
    print(i)
    break
Buggy python submission (verdict: Runtime Error):
print(input().count(2))

Fixed submission:
print(input().count('2'))
Buggy python submission (verdict: Runtime Error):
N = input()
if N%2 == 1:
  N*=2
print(N)

Fixed submission:
N=int(input())
if N%2==1 :
  N*=2
print(N)
Buggy python submission (verdict: Runtime Error):
n=input()
a=list(map(int,input().split()))
print(a.max()-a.min())

Fixed submission:
n=input()
a=list(map(int,input().split()))
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
N=input();print('YNeos'[int(N)%sum(map(int,n))!=0::2])


Fixed submission:
N=input();a=list(map(int,N));print('YNeos'[int(N)%sum(a)!=0::2])
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input())
print(min(a,b))

Fixed submission:
a,b=map(int,input().split())
print(a if a<=b else a-1)
Buggy python submission (verdict: Runtime Error):
a=int(input());b=int(input());c=int(input());d=int(input());print(min(a,b)+min(c+d))

Fixed submission:
print(min(int(input()),int(input()))+min(int(input()),int(input())))

Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
print(min(a,b)+min(c,d))

Fixed submission:
print(min(int(input()),int(input()))+min(int(input()),int(input())))
Buggy python submission (verdict: Runtime Error):
N=input()
D,X=map(int,input().split())
for i range(N):
  X+=(D-1+int(input()))//D
print(X)

Fixed submission:
N=int(input())
D,X=map(int,input().split())
for i in range(N):
  a=int(input())
  X+=(D-1+a)//a
print(X)
Buggy python submission (verdict: Runtime Error):
b=int(input())
a=[for i in range(b)]
r=int(input())
c=[for i in range(r)]
cnt=0
for i in range(b):
  cnt=max(cnt,a.count(a[i])-c.count(a[i]))
print(cnt)

Fixed submission:
b=int(input())
a=[input() for i in range(b)]
r=int(input())
c=[input() for i in range(r)]
cnt=0
for i in range(b):
  cnt=max(cnt,a.count(a[i])-c.count(a[i]))
print(cnt)
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
ret=0
for i in range(n):
  s=str(i)
  c=list(map(int,list(s)))
  cnt=sum(c)
  if cnt>=a && cnt<=b:
    ret+=cnt
print(ret)


Fixed submission:
n,a,b=map(int,input().split())
ret=0
for i in range(n+1):
  s=str(i)
  c=list(map(int,list(s)))
  cnt=sum(c)
  if cnt>=a and cnt<=b:
    ret+=i
print(ret)
Buggy python submission (verdict: Runtime Error):
print(input.count('1'))

Fixed submission:
print(input().count('1'))
Buggy python submission (verdict: Runtime Error):
n,z,w=map(int,input().split())
a[] = map(int,input().split())
print(max(abs(a[-1]-w,a[-1]-a[-2]))

Fixed submission:
n,z,w=map(int,input().split())
a = list(map(int,input().split()))
t = 0
if n>1 :t = abs(a[-1]-a[-2])
print(max(abs(a[-1]-w),t))
Buggy python submission (verdict: Runtime Error):
print("YNEOS"[input()!=input()[::-1])

Fixed submission:
print("YNEOS"[input()!=input()[::-1]::2])
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
print("ABlriocwen"[not abs(a-b)>1 :: 2])

Fixed submission:
a,b = map(int,input().split())
print("ABlriocwen"[not abs(a-b)>1 :: 2])
Buggy python submission (verdict: Runtime Error):
n = int(input())
ng =0 ok=n
while abs(ok-ng)>1:
  mid=(ok+ng)//2
  if mid*(1+mid)//2>=n:
    ok=mid
  else:
    ng = mid
if ok != n:
  ok+=1
print(ok)

Fixed submission:
n = int(input())
ng =0
ok=n
while abs(ok-ng)>1:
  mid=(ok+ng)//2
  if mid*(1+mid)//2>=n:
    ok=mid
  else:
    ng = mid
print(ok)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[]
b=[]
ret = 0
for i in range(n):
  a[i],b[i]=map(int,input().split())
for i in range(n):
  ret+=b[-1-i]-(ret+a[-1-i])%b[-1-i]
print(ret)

Fixed submission:
n=int(input())
a=[]
b=[]
ret = 0
for i in range(n):
  s,t=map(int,input().split())
  a+=[s]
  b+=[t]
for i in range(n):
  ret+=(b[-1-i]-(ret+a[-1-i])%b[-1-i])%b[-1-i]
print(ret)
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
ret=0
for i in range(n-1):
  ret+=min(a*(x[i+1]-x[i]),b)
print ret

Fixed submission:
n,a,b=map(int,input().split())
x=list(map(int,input().split()))
ret=0
for i in range(n-1):
  ret+=min(a*(x[i+1]-x[i]),b)
print(ret)
Buggy python submission (verdict: Runtime Error):
import sys
s=reverse(input())
l=list(["maerd","remaerd","esare","resare"]
for i in range len(s):
  ok=0
  for j in range l:
    if s[i:len(j)] == j:
      ok=1
      i += len(j)
      break
  if ok == 0:
    print("NO")
    sys.exit()
print("YES")


Fixed submission:
import sys
s=input()
s=s[::-1]
l=list(["maerd","remaerd","esare","resare"])
i=0
while i < len(s):
  ok=0
  for j in l:
    if s[i:i+len(j)] == j:
      ok=1
      i += len(j)
      break
  if ok == 0:
    print("NO")
    sys.exit()
print("YES")
Buggy python submission (verdict: Runtime Error):
n,x=map(int,input().split())
a=list(map(int,input().split()))
ret=0
if a[0]>x:
  ret+=a[0]-x
  a[0]-=x
for i in range(1:n):
  if a[i]+a[i-1]>x:
    ret+=a[i]+a[i-1]-x
    a[i]=a[i]+a[i-1]-x
print(ret)

Fixed submission:
n,x=map(int,input().split())
a=list(map(int,input().split()))
ret=0
if a[0]>x:
  ret+=a[0]-x
  a[0]-=a[0]-x
for i in range(n-1):
  if a[i+1]+a[i]>x:
    ret+=a[i+1]+a[i]-x
    a[i+1]-=a[i+1]+a[i]-x
print(ret)
Buggy python submission (verdict: Runtime Error):
import sys
n=int(input())
s=input()
t=input()
if s == t:
  print len(s)
  sys.exit()
for i in range(1,n):
  tmp=s+t[-1*i:]
  if tmp[-n:] == t:
    print n+i
    sys.exit()


Fixed submission:
import sys
n=int(input())
s=input()
t=input()
if s == t:
  print(n)
  sys.exit()
for i in range(1,n+1):
  tmp=s+t[-1*i:]
  if tmp[-n:] == t:
    print(n+i)
    sys.exit()
Buggy python submission (verdict: Runtime Error):
s=input()
t="CODEFESTIVAL2016"
ret=0
for i range(s.len()):
  if s[i] != t[i]:
    ret+=1
print(ret)

Fixed submission:
s=input()
t="CODEFESTIVAL2016"
ret=0
for i in range(len(s)):
  if s[i] != t[i]:
    ret+=1
print(ret)
Buggy python submission (verdict: Runtime Error):
s=input()
sc=0
tc=0
for i in s:
  if i=="S":
    sc+=1
  elif sc!=0:
    sc-=1
  else tc+=1
print(tc+sc)

Fixed submission:
s=input()
sc=0
tc=0
for i in s:
  if i=='S':
    sc+=1
  elif sc!=0:
    sc-=1
  else :tc+=1
print(tc+sc)
Buggy python submission (verdict: Runtime Error):
s=input()
t=input()
u=input()
a=b=c=0
now = 0
while 1:
  if now == 0:
    if s[a] == 'a':
      now = 0
    elif s[a] == 'b':
      now = 1
    else:
      now = 2
    a+=1
    if a==len(s):
      print('A')
      break
  elif now == 1:
    if s[b] == 'a':
      now = 0
    elif s[b] == 'b':
      now = 1
    else:
      now = 2
    b+=1
    if b==len(t):
      print('B')
      break
  else:
    if s[c] == 'a':
      now = 0
    elif s[c] == 'b':
      now = 1
    else:
      now = 2
    c+=1
    if c==len(u):
      print('C')
      break


Fixed submission:
s=input()
t=input()
u=input()
a=b=c=0
now = 0
while 1:
  if now == 0:
    if a==len(s):
      print('A')
      break
    if s[a] == 'a':
      now = 0
    elif s[a] == 'b':
      now = 1
    else:
      now = 2
    a+=1
  elif now == 1:
    if b==len(t):
      print('B')
      break
    if t[b]=='a':
      now = 0
    elif t[b]== 'b':
      now = 1
    else:
      now = 2
    b+=1
  else:
    if c==len(u):
      print('C')
      break
    if u[c]== 'a':
      now = 0
    elif u[c]== 'b':
      now = 1
    else:
      now = 2
    c+=1

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
t=input()
u=input()
a=b=c=0
now = 0
while 1:
  if now == 0:
    if s[a] == 'a':
      now = 0
    elif s[a] == 'b':
      now = 1
    else:
      now = 2
    if a==len(s):
      print('A')
      break
  elif now == 1:
    if s[b] == 'a':
      now = 0
    elif s[b] == 'b':
      now = 1
    else:
      now = 2
    if b==len(t):
      print('B')
      break
  else:
    if s[c] == 'a':
      now = 0
    elif s[c] == 'b':
      now = 1
    else:
      now = 2
    if c==len(u):
      print('C')
      break

Fixed submission:
s=input()
t=input()
u=input()
a=b=c=0
now = 0
while 1:
  if now == 0:
    if a==len(s):
      print('A')
      break
    if s[a] == 'a':
      now = 0
    elif s[a] == 'b':
      now = 1
    else:
      now = 2
    a+=1
  elif now == 1:
    if b==len(t):
      print('B')
      break
    if t[b]=='a':
      now = 0
    elif t[b]== 'b':
      now = 1
    else:
      now = 2
    b+=1
  else:
    if c==len(u):
      print('C')
      break
    if u[c]== 'a':
      now = 0
    elif u[c]== 'b':
      now = 1
    else:
      now = 2
    c+=1
Buggy python submission (verdict: Runtime Error):
N = int(input())

S = 'abcdefghijklmnopqrstuvwxyz'

def bite(X):
    s = 0
    t = 0
    while t < X:
        t = t + 26**(s+1)
        s = s + 1
    return s

B = bite(N)
X = N
L = []
for i in range(B-1):
    L.append(X//(26**(B-i-1)))
    X = X - (X//(26**(B-i-1)))*(26**(B-i-1))
L.append(X)

ans = ''
for i in range(B):
    ans = ans + S[L[i]-1]
    
print(ans)

Fixed submission:
N = int(input())

S = 'abcdefghijklmnopqrstuvwxyz'

def bite(X):
    s = 0
    t = 0
    while t < X:
        t = t + 26**(s+1)
        s = s + 1
    return s


B = bite(N)
X = N
L = []
for i in range(B):
    if X%26 != 0:
        L.append(X%26)
        X = (X-X%26)//26
    else:
        L.append(26)
        X = (X - 26)//26

L.reverse()

ans = ''
for i in range(B):
    ans = ans + S[L[i]-1]

    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [input() for i in range(N)]

def put_item(table, item):
    for i in range(0, len(table)):
        if table[i][0] == item:
            table[i][1] = table[i][1] + 1
            return 
    table.append([item, 1])

def histogram(data):
    result = []
    for i in range(0, len(data)):
        put_item(result, data[i])
    return result

T = []
for i in range(N):
    T.append(S[i])
    
    
print(len(histogram(T)))

Fixed submission:
N = int(input())
S = [input() for i in range(N)]

def histogram_sorted(data):
    table = []
    prev = data[0]
    c = 1 
    for i in range(1,len(data)):
        if prev == data[i]:
            c=c+1
        else:
            table.append([prev,c])
            prev = data[i]
            c = 1
    table.append([prev,c]) 
    return table

T = []
for i in range(N):
    T.append(S[i])
    
    
print(len(histogram_sorted(sorted(T))))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
A = list(map(int, input().split()))
for i in range(1,N+1):
    print(A.count(i))

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

B=sorted(A)

def histogram_sorted(data):
    table = []
    prev = data[0] 
    c = 1
    for i in range(1,len(data)):
        if prev == data[i]:
            c=c+1
        else:
            table.append([prev,c])
            prev = data[i]
            c = 1
    table.append([prev,c])
    return table

X = histogram_sorted(B)

X.append([0,0])

c=0
for i in range(1,N+1):
    if X[c][0] == i:
        print(X[c][1])
        c = c+1
    else:
        print(0)
Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


sum = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for k in range(1,K+1):
      sum = sum + gcd(i,j,k)
      
print(sum)
             

Fixed submission:
K = int(input())

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


sum = 0
for i in range(1,K+1):
  for j in range(i+1,K+1):
    for k in range(j+1,K+1):
      sum = sum + 6*gcd(i,j,k)
      
for i in range(1,K+1):
  for j in range(i+1,K+1):
     sum = sum + 6*math.gcd(i,j)
      
sum = sum + K*(K+1)//2

print(sum)