Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
x=list(map(int, input().split()))
ll=(len(x)-1)//2

for i in range(n):
    xx=x.copy()
    del xx[i]
    xx=sorted(xx,reverse=True)
    print(xx[ll])

Fixed submission:
n=int(input())
x=list(map(int, input().split()))
xx=sorted(x,reverse=True)
ll=(len(x)-1)//2
for i in range(n):
    if x[i]<xx[ll]:
        print(xx[ll])
    else:
        print(xx[ll+1])
Buggy python submission (verdict: Runtime Error):
from bisect import bisect

n=int(input())
a=sorted(list(map(int,input().split())))

x=a[-1]

if n%2==0:
  mid=x//2
else
  mid=x//2+1

if mid in a:
  print(x,mid)
else:
  inx=bisect(a,mid)
  if a[inx]-mid>=mid-a[inx-1]:
    print(x,a[inx-1])
  else:
    print(x,a[inx])

Fixed submission:
from bisect import bisect

n=int(input())
a=sorted(list(map(int,input().split())))

x=a[-1]
if n%2==0:
  mid=x//2
  if mid in a:
    print(x,mid)
  else:
    inx=bisect(a,mid)
    if a[inx]-mid>=mid-a[inx-1]:
      print(x,a[inx-1])
    else:
      print(x,a[inx])
else:
  mid=x//2+1
  if mid in a:
    print(x,mid)
  else:
    inx=bisect(a,mid)
    if a[inx]-mid>=mid-a[inx-1]:
      print(x,a[inx-1])
    else:
      print(x,a[inx])
Buggy python submission (verdict: Runtime Error):
s=input()
print('Yes' if s.count('a')==1 and s.count('b')==1 and s.count('c')==1 else 'No'

Fixed submission:
s=input()
print('Yes' if s.count('a')==1 and s.count('b')==1 and s.count('c')==1 else 'No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=list(map(int,input().split()))

print('Three' if len(list(set(s))))==3 else 'Four')

Fixed submission:
n=int(input())
s=input().split()
print('Four' if 'Y' in s else 'Three')
Buggy python submission (verdict: Runtime Error):
n=int(input())
d={'M':0,'A':0,'R':0,'C':0,'H':0}
for i in range(n):
  s=input()
  if s[0]=='M':
    d['M']+=1
  if s[0]=='A':
    d['A']+=1
  if s[0]=='R':
    d['R']+=1
  if s[0]=='C':
    d['C']+=1
  if s[0]=='H':
    d['H']+=1

ans=0
for i,j,k in combinations('MARCH',3):
  ans+=d[i]*d[j]*d[k]

print(ans)

Fixed submission:
n=int(input())
s=[input() for i in range(n)]
cnt1,cnt2,cnt3,cnt4,cnt5=0,0,0,0,0
for i in s:
    if i[0]=='M':
        cnt1+=1
    elif i[0]=='A':
        cnt2+=1
    elif i[0]=='R':
        cnt3+=1
    elif i[0]=='C':
        cnt4+=1
    elif i[0]=='H':
        cnt5+=1
print(cnt1*cnt2*cnt3+cnt1*cnt2*cnt4+cnt1*cnt2*cnt5+cnt1*cnt3*cnt4+cnt1*cnt3*cnt5+cnt1*cnt4*cnt5+cnt2*cnt3*cnt4+cnt2*cnt3*cnt5+cnt2*cnt4*cnt5+cnt3*cnt4*cnt5)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=int(input())
x=n%a
print('Yes' if a<=x else 'No')

Fixed submission:
n=int(input())
a=int(input())
print('Yes' if n%500 <= a else 'No')
Buggy python submission (verdict: Runtime Error):
from bisect import bisect

n,h=map(int,input().split())
a=[]
b=[]
a_max=0
b_max=0
for i in range(n):
  x,y=map(int,input().split())
  a.append(x)
  b.append(y)
  a_max=max(a_max,x)
  b_max=max(b_max,y)

if a.index(a_max)==b.index(b_max):
  a=sorted(a)
  a_max=a[-2]

b=sorted(b)
lim_inx=bisect(b,a_max)

cnt=0
total=0
inx=n-1
while total<=h:
  if inx>=lim_inx:
    total+=b[inx]
    cnt+=1
    inx-=1
  else:
    if (h-total)%a_max==0:
      cnt+=(h-total)//a_max
    else:
      cnt+=(h-total)//a_max+1
    print(cnt)
    exit()
print(cnt)

Fixed submission:
from bisect import bisect

n,h=map(int,input().split())
b=[]
a_max=0
for i in range(n):
  x,y=map(int,input().split())
  b.append(y)
  a_max=max(a_max,x)

b=sorted(b)
lim_inx=bisect(b,a_max)

cnt=0
total=0
inx=n-1
while total<h:
  if inx>=lim_inx:
    total+=b[inx]
    cnt+=1
    inx-=1
  else:
    if (h-total)%a_max==0:
      cnt+=(h-total)//a_max
    else:
      cnt+=(h-total)//a_max+1
    print(cnt)
    exit()
print(cnt)
Buggy python submission (verdict: Runtime Error):
def eratosthenes(n):
 is_p=[1]*n
 p_list=[]

 is_p[0]=0
 is_p[1]=0

 for i in range(2,n):
  if is_p[i]:
   p_list.append(i)
   for j in range(i*i,n,i):
    is_p[j] = 0

 return is_p, p_list

lim=10**5+1
is_p, p_list=eratosthenes(lim)

q=int(input())

'''
b=[0]
for i in range(1,lim+1):
 if is_p[i-1] and is_p[i//2]:
  b.append(b[i-1]+1)
 else:
  b.append(b[i-1])
'''
a = [0] * (10**4+2)
for i in range(3, 10**4+1, 2):
    if is_p[i] and is_p[(i+1)//2]:
        a[i] = 1
for i in range(1, 10**4+1):
    a[i+1] += a[i]

for i in range(q):
 l,r=map(int,input().split())
# print(b[r+1]-b[l])
 print(a[r]-a[l-1])

Fixed submission:
def factorization(n):
 p=2
 fcr=[]
 while p*p<=n:
  while n%p==0:
   fcr.append(p)
   n//=p
  p+=1
 if n>1:
  fcr.append(n)
 return fcr

q=int(input())

cnt=1
p_list=[1]
q_list=[0]
for i in range(3,10**5+1,2):
 a=factorization(i)
 b=factorization((i+1)//2)

 if len(a)==len(b)==1:
  cnt+=1
  q_list.append(1)
 else:
  q_list.append(0)

 p_list.append(cnt)

for i in range(q):
 l,r=map(int,input().split())

 c=p_list[r//2]-p_list[l//2]
 if q_list[l//2]==1:
  print(c+1)
 else:
  print(c)

Buggy python submission (verdict: Runtime Error):
def eratosthenes(n):
 is_p=[1]*n
 p_list=[]

 is_p[0]=0
 is_p[1]=0

 for i in range(2,n):
  if is_p[i]:
   p_list.append(i)
   for j in range(i*i,n,i):
    is_p[j] = 0

# return p_list
 return is_p

q=int(input())

lim=10**2+1
is_p=eratosthenes(lim)

#print(is_p)

b=[0]
for i in range(1,lim+1):
 if is_p[i-1]==1 and is_p[i//2]==1:
  b.append(b[i-1]+1)
 else:
  b.append(b[i-1])

#print(b)

for i in range(q):
 l,r=map(int,input().split())
 print(b[r+1]-b[l])

Fixed submission:
def factorization(n):
 p=2
 fcr=[]
 while p*p<=n:
  while n%p==0:
   fcr.append(p)
   n//=p
  p+=1
 if n>1:
  fcr.append(n)
 return fcr

q=int(input())

cnt=1
p_list=[1]
q_list=[0]
for i in range(3,10**5+1,2):
 a=factorization(i)
 b=factorization((i+1)//2)

 if len(a)==len(b)==1:
  cnt+=1
  q_list.append(1)
 else:
  q_list.append(0)

 p_list.append(cnt)

for i in range(q):
 l,r=map(int,input().split())

 c=p_list[r//2]-p_list[l//2]
 if q_list[l//2]==1:
  print(c+1)
 else:
  print(c)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    cnt+=c_l[i] if c_l[i]<i else cnt+=c_l[i]-i
print(cnt)

Fixed submission:
a,b=map(int,input().split())
print((a+b)//2 if (a+b)/2 == (a+b)//2 else (a+b)//2+1)
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    cnt+=c_l[i] if c_l[i]<i else cnt+=c_l[i]-i
print(cnt)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    if c_l[i]<i:
        cnt+=c_l[i]
    else:
        cnt+=c_l[i]-i
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
cnt=0
for i in a_s:
    if a.count(i)<i:
        cnt+=a.count(i)
    elif a.count(i)>i:
        cnt+=a.count(i)-i
print(cnt)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    if c_l[i]<i:
        cnt+=c_l[i]
    else:
        cnt+=c_l[i]-i
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
cnt=0
for i in a_s:
    if a.count(i)<i:
        cnt+=a.count(i)
    elif a.count(i)>i:
        cnt+=a.count(i)-i
print(cnt)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
a_s=list(set(a))
c_l=Counter(a)

cnt=0
for i in a_s:
    if c_l[i]<i:
        cnt+=c_l[i]
    else:
        cnt+=c_l[i]-i
print(cnt)
Buggy python submission (verdict: Runtime Error):
r,g=map(int,input().split())
print((2*g)-r)

Fixed submission:
r=int(input())
g=int(input())
print((2*g)-r)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
for a in range(n//2,3501):
 for b in range(n//2,3501):
  if 4*a*b-n*b-a*n==0:
   continue
  c=(n*a*b)/(4*a*b-n*b-a*n)
  if c==int(c) and c>=1:
    print(a,b,int(c))
    exit()

Fixed submission:
n=int(input())
for a in range(n//4+1,3501):
 for b in range((n*a)//(4*a-n),3501):
  if 4*a*b-n*b-a*n==0:
   continue
  c=(n*a*b)/(4*a*b-n*b-a*n)
  if c==int(c) and c>=1:
    print(a,b,int(c))
    exit()
Buggy python submission (verdict: Runtime Error):
import itertools
from scipy.sparse.csgraph import floyd_warshall

N,M,R=map(int,input().split())
r=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(M)]

s=[[float('inf') for i in range(N)] for i in range(N)]
for i in range(M):
    a,b,c=l[i]
    s[a-1][b-1]=c
    s[b-1][a-1]=c
for i in range(N):
    s[i][i]=0

s=floyd_warshall(s)
#print(s)
ans=10**9
for i in itertools.permutations(r):
#    print(i)
    temp_ans=0
    for j in range(R-1):
        temp_ans+=s[i[j]-1][i[j+1]-1]
    ans=min(ans,temp_ans)
print(int(ans))

Fixed submission:
import itertools
from scipy.sparse.csgraph import floyd_warshall

N,M,R=map(int,input().split())
r=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(M)]

s=[[float('inf') for i in range(N)] for i in range(N)]
for i in range(M):
    a,b,c=l[i]
    s[a-1][b-1]=c
    s[b-1][a-1]=c
for i in range(N):
    s[i][i]=0

s=floyd_warshall(s)
#print(s)
ans=10**9
for i in itertools.permutations(r):
#    print(i)
    temp_ans=0
    for j in range(R-1):
        temp_ans+=s[i[j]-1][i[j+1]-1]
    ans=min(ans,temp_ans)
print(int(ans))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(map(int,input().split()))
ans=1
d={}
for i in range(n):
    d[i]=a.count(i)
for i in range(1,n-1):
    cnt=d[i-1]+d[i]+d[i+1]
    ans=max(ans,cnt)
print(ans)

Fixed submission:
from collections import Counter

n=int(input())
a=list(map(int,input().split()))
ans=1
counter=Counter(a)
for i in range(1,n-1):
    ans=max(ans,counter[i-1]+counter[i]+counter[i+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n):
    if p[i]==i+1:
        cnt+=1
        x=1
        if i==n:
            break
        while True:
            if p[i+x]!=i+1:
                temp_v=p[i+x]
                p[i+x]=p[i]
                p[i]=temp_v
                break
            else:
                x+=1
print(cnt)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n):
    if p[i]==i+1:
        cnt+=1
        x=1
        if i==n-1:
            break
        while True:
            if p[i+x]!=i+1:
                temp_v=p[i+x]
                p[i+x]=p[i]
                p[i]=temp_v
                break
            else:
                x+=1
print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n):
    if p[i]==i+1:
        cnt+=1
        x=1
        while True:
            if p[i+x]!=i+1:
                temp_v=p[i+x]
                p[i+x]=p[i]
                p[i]=temp_v
                break
            else:
                x+=1
print(cnt)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
cnt=0
for i in range(n):
    if p[i]==i+1:
        cnt+=1
        x=1
        if i==n-1:
            break
        while True:
            if p[i+x]!=i+1:
                temp_v=p[i+x]
                p[i+x]=p[i]
                p[i]=temp_v
                break
            else:
                x+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

n=int(input())
t=[int(input()) for i in range(n)]

for i in range(0,n-1):
    lcm=(t[i]*t[i+1]//gcd(t[i],t[i+1]))
    t[i+1]=lcm
print(lcm)

Fixed submission:
from fractions import gcd

n=int(input())
t=[int(input()) for i in range(n)]

lcm=t[0]
for i in range(n-1):
    lcm=(t[i]*t[i+1]//gcd(t[i],t[i+1]))
    t[i+1]=lcm
print(lcm)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

n=int(input())
t=[int(input()) for i in range(n)]

for i in range(1,n):
    lcm=(t[i]*t[i-1]//gcd(t[i],t[i-1]))
    t[i]=lcm
print(lcm)

Fixed submission:
from fractions import gcd

n=int(input())
t=[int(input()) for i in range(n)]

lcm=t[0]
for i in range(n-1):
    lcm=(t[i]*t[i+1]//gcd(t[i],t[i+1]))
    t[i+1]=lcm
print(lcm)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
from sys import stdin
nii=lambda:map(int,stdin.readline().split())

n=int(input())

row,col,w=[],[],[]
for i in range(n-1):
  a,b,c=nii()
  row.append(a-1)
  col.append(b-1)
  w.append(c)

q,k=nii()
k-=1

g=csr_matrix((w,(row,col)),shape=(n,n))
d=dijkstra(g,indices=k,directed=False)

for i in range(q):
  x,y=nii()
  x-=1
  y-=1
  print(int(d[x]+d[y]))

Fixed submission:
from collections import deque

n=int(input())

tree=[[] for i in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    a-=1;b-=1
    tree[a].append([b,c])
    tree[b].append([a,c])

q,k=map(int,input().split())
k-=1

dist=[-1 for i in range(n)]
dist[k]=0
que=deque()
que.append(k)
while que:
    x=que.popleft()
    for p in tree[x]:
        if dist[p[0]]==-1:
            que.append(p[0])
            dist[p[0]]=dist[x]+p[1]
ans=[]
for i in range(q):
    x,y=map(int,input().split())
    x-=1;y-=1
    ans.append(dist[x]+dist[y])

for i in ans:
    print(i)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
print((n-1)*(m-1))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))

cnt1,cnt2=0,0
for i in a:
    if i%2!=0:
        cnt1+=1
    if i%4==0:
        cnt2+=1
print('Yes' if cnt2>=cnt1 or (len(a)%2!=0 and cnt2+1>=cnt1) else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra

n,m=map(int,input().split())
ro,co,w=[],[],[]
for i in range(m):
    a,b=map(int,input().split())
    ro.append(a-1)
    co.append(b-1)
    w.append(1)

g=csr_matrix((w,(ro,co)),shape=(n,n))
d=dijkstra(g,directed=False,indices=0)
if d[-1]==2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Fixed submission:
from collections import deque

n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]

sx=0
gx=n-1

tree=[[] for i in range(n)]
for i in l:
    tree[i[0]-1].append(i[1]-1)
    tree[i[1]-1].append(i[0]-1)

dist=[-1 for i in range(n)]
dist[sx]=0

que=deque()
que.append(sx)

while que:
    x=que.popleft()

    if x==gx and dist[gx]==2:
        print('POSSIBLE')
        exit()
    elif x==gx and dist[gx]!=2:
        print('IMPOSSIBLE')
        exit()

    for j in tree[x]:
        if dist[j]==-1:
            que.append(j)
            dist[j]=dist[x]+1

print('IMPOSSIBLE')
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split())

cnt=0
l=[]
for i in a:
  p=i//400
  if p<=7:
    l.append(p)
  else:
    cnt+=1

d=len(set(l))
if d==0:
  d+=1
print(d,d+cnt)

Fixed submission:
n=int(input())
a_l=list(map(int,input().split()))
a,b,c,d,e,f,g,h=0,0,0,0,0,0,0,0
cnt=0
for i in a_l:
    if i<400*1:
        a+=1
    elif 400*1<=i<400*2:
        b+=1
    elif 400*2<=i<400*3:
        c+=1
    elif 400*3<=i<400*4:
        d+=1
    elif 400*4<=i<400*5:
        e+=1
    elif 400*5<=i<400*6:
        f+=1
    elif 400*6<=i<400*7:
        g+=1
    elif 400*7<=i<400*8:
        h+=1
    else:
        cnt+=1
ans=0
for i in [a,b,c,d,e,f,g,h]:
    if i!=0:
        ans+=1
if ans!=0:
    print(ans, ans+cnt)
else:
    print(1,cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split())

cnt=0
l=[]
for i in a:
  p=i//400
  if p<=7:
    l.append(p)
  else:
    cnt+=1

def=len(set(l))
if def==0:
  def+=1
print(def,def+cnt)

Fixed submission:
n=int(input())
a_l=list(map(int,input().split()))
a,b,c,d,e,f,g,h=0,0,0,0,0,0,0,0
cnt=0
for i in a_l:
    if i<400*1:
        a+=1
    elif 400*1<=i<400*2:
        b+=1
    elif 400*2<=i<400*3:
        c+=1
    elif 400*3<=i<400*4:
        d+=1
    elif 400*4<=i<400*5:
        e+=1
    elif 400*5<=i<400*6:
        f+=1
    elif 400*6<=i<400*7:
        g+=1
    elif 400*7<=i<400*8:
        h+=1
    else:
        cnt+=1
ans=0
for i in [a,b,c,d,e,f,g,h]:
    if i!=0:
        ans+=1
if ans!=0:
    print(ans, ans+cnt)
else:
    print(1,cnt)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=s

c=s.count('()')
while c!=0:
  s=list(s)

  i=0
  n_s=''
  while i<=len(s)-1:
    if s[i]=='(' and s[i+1]==')':
      i+=2
    else:
      n_s+=s[i]
      i+=1

  s=''.join(n_s)
  c=s.count('()')

c_a=s.count('(')
c_b=s.count(')')

ans='('*c_b+ans+')'*c_a
print(ans)

Fixed submission:
n=int(input())
s=input()
ans=s
s+='#'

c=s.count('()')
while c!=0:
  s=list(s)

  i=0
  n_s=''
  while i<=len(s)-1:
    if s[i]=='(' and s[i+1]==')':
      i+=2
    else:
      n_s+=s[i]
      i+=1

  s=''.join(n_s)
  c=s.count('()')

c_a=s.count('(')
c_b=s.count(')')

ans='('*c_b+ans+')'*c_a
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=s

c=s.count('()')
while c!=0:
  s=list(s)
  i=0
  while i<=len(s)-1:
    if s[i]=='(' and s[i+1]==')':
      del s[i]
      del s[i+1]
    else:
      i+=1
  s=''.join(s)
  c=s.count('()')

c_a=s.count('(')
c_b=s.count(')')

ans='('*c_b+ans+')'*c_a
print(ans)

Fixed submission:
n=int(input())
s=input()
ans=s
s+='#'

c=s.count('()')
while c!=0:
  s=list(s)

  i=0
  n_s=''
  while i<=len(s)-1:
    if s[i]=='(' and s[i+1]==')':
      i+=2
    else:
      n_s+=s[i]
      i+=1

  s=''.join(n_s)
  c=s.count('()')

c_a=s.count('(')
c_b=s.count(')')

ans='('*c_b+ans+')'*c_a
print(ans)
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
a=[4,6,9,11]
print('Yes' if x==y==2 or (x in a and y in a) or (x not in a and y not in a))

Fixed submission:
x,y=map(int,input().split())
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
print('#'*(w+2))
for i in range(h):
  print('#'+input()+'#')
print('#'+(w+2))

Fixed submission:
h,w=map(int,input().split())
print('#'*(w+2))
for i in range(h):
    print('#'+input()+'#')
print('#'*(w+2))
Buggy python submission (verdict: Runtime Error):
from bisect import bisect_left

n,k=map(int,input().split())

l=[]
for i in range(n):
  a,b=nii()
  l.append([a,b])

l.sort(key=lambda x:x[0])

a_l=[]
b_l=[]
for a,b in l:
  a_l.append(a)
  b_l.append(b)

b_rui=[0]
for i in range(1,n+1):
  b_rui.append(b_rui[i-1]+b_l[i-1])
b_rui=b_rui[1:]

inx=bisect_left(b_rui,k)
print(a_l[inx])

Fixed submission:
n,k=map(int,input().split())
d={}
for i in range(n):
    a,b=map(int,input().split())
    if a in d.keys():
        d[a]+=b
    else:
        d[a]=b
l=sorted(d.keys())
cnt=0
for i in l:
    cnt+=d[i]
    if cnt>=k:
        print(i)
        exit()
Buggy python submission (verdict: Runtime Error):
from collections import Counter

n=int(input())
c=Counter(input())
for i in range(n-1):
    c&=Counter(input())
s=''
for k,v in sorted(count.items()):
    s+=k*v
print(s)

Fixed submission:
from collections import Counter

n=int(input())
count=Counter(input())
for i in range(n-1):
    t_count=Counter(input())
    for c_k in count.keys():
        if c_k in t_count.keys():
            count[c_k]=min(count[c_k],t_count[c_k])
        else:
            count[c_k]=0
s=''
for c_k in sorted(count.keys()):
    s+=c_k*count[c_k]
print(s)
Buggy python submission (verdict: Time Limit Exceeded):
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z==s:
                cnt+=1
print(cnt)

Fixed submission:
k,s=map(int,input().split())
cnt=0
for x in range(k+1):
    for y in range(k+1):
        if 0<=s-(x+y)<=k:
            cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
x,y=map(int,input().split())
if 0<=x<=y or x<=0<=y<=-x or x<=y<=0:
    print(y-x)
elif y<=-x<=0<=x:
    print(-y-x+1)
elif y<=x<=0 or o<=y<=x:
    print(x-y+2)
else:
    print(y+x+1)

Fixed submission:
x,y=map(int,input().split())
cnt=0
if x<0<y or y<=0<=x:
    cnt=1
elif 0<y<x or y<x<0:
    cnt=2
print(abs(abs(x)-abs(y))+cnt)
Buggy python submission (verdict: Runtime Error):
a,b,c=input().split()
print(a+c if b=='+' else a-c)

Fixed submission:
A, op, B = input().split()
if op == '+':
    print(int(A) + int(B))
else:
    print(int(A) - int(B))
Buggy python submission (verdict: Runtime Error):
w, h, n = map(int,input().split())

y_min = 0
y_max = h

x_min = 0
x_max = w

for i in range(n):
  x, y, a = map(int,input().split())

  if a == 1:
    x_min = max(x_min, x)

  if a == 2:
    x_max = min(x_max, x)

  if a == 3:
    y_min = max(y_min, y)

  if a == 4:
    y_max = min(y_max, y)

white = (y_max - y_min) * (x_max - x_min)
if (y_max - y_min)>=0 and (x_max - x_min)>=0:
  print(max(white, 0))
else:
  print(0)

Fixed submission:
s=input()

ans=0
bef=s[0]
for i in s[1:]:
  if bef!=i:
    ans+=1
  bef=i
print(ans)

Buggy python submission (verdict: Runtime Error):
w, h, n = map(int,input().split())

#とりうるx,yの範囲
y_min = 0
y_max = h

x_min = 0
x_max = w

for i in range(n):
  x, y, a = map(int,input().split())

  if a == 1:
    x_min = max(x_min, x)

  if a == 2:
    x_max = min(x_max, x)

  if a == 3:
    y_min = max(y_min, y)

  if a == 4:
    y_max = min(y_max, y)

white = (y_max - y_min) * (x_max - x_min)
if (y_max - y_min)>=0 and (x_max - x_min)>=0:
  print(max(white, 0))
else:
  print(0)

Fixed submission:
s=input()

ans=0
bef=s[0]
for i in s[1:]:
  if bef!=i:
    ans+=1
  bef=i
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
s=input()
t=input()
for i in range(n):
 if s[-i-1:]==t[:i+1]:
  cnt=i+1
print(2*n-cnt)

Fixed submission:
n=int(input())
s=input()
t=input()
cnt=0
for i in range(n):
 if s[-i-1:]==t[:i+1]:
  cnt=max(cnt,i+1)
print(2*n-cnt)
Buggy python submission (verdict: Runtime Error):
s=input()
a='CODEFESTIVAL2016'
cnt=0
for i in range(len(s)):
    if s[i]!=a[i]:
        cnt+=1
print(ans)

Fixed submission:
s=input()
a='CODEFESTIVAL2016'
cnt=0
for i in range(len(s)):
    if s[i]!=a[i]:
        cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
h,w=map(int,input().split())
for i in range(h):
    s=input()
    print(s+'\n'+s)

Fixed submission:
x=input()

c_s=0
c_t=0

for i in x:
  if i=='S':
    c_s+=1
  else:
    if c_s==0:
      c_t+=1
    else:
      c_s-=1

print(c_s+c_t)
Buggy python submission (verdict: Runtime Error):
sa=input()
sb=input()
sc=input()

t='a'
while True:
  if t=='a':
    if sa=='':
      print('A')
      exit()
    t=sa[0]
    sa=sa[1:]
  if t=='b':
    if sb=='':
      print('B')
    t=sb[0]
    sb=sb[1:]
  if t=='c':
    if sc=='':
      print('C')
      exit()
    t=sc[0]
    sc=sc[1:]

Fixed submission:
sa=input()
sb=input()
sc=input()

t='a'
while True:
  if t=='a':
    if sa=='':
      print('A')
      exit()
    t=sa[0]
    sa=sa[1:]
  if t=='b':
    if sb=='':
      print('B')
      exit()
    t=sb[0]
    sb=sb[1:]
  if t=='c':
    if sc=='':
      print('C')
      exit()
    t=sc[0]
    sc=sc[1:]

Buggy python submission (verdict: Runtime Error):
a, b, c = [int(input()) for i in range(3)]

a_list = list(a)
b_list = list(b)
c_list = list(c)

def decide_turn(list):
    next_turn = list[0]
    del list[0]
    return next_turn

next_turn = decide_turn(a_list)

while 1 > 0:
    if next_turn == a:
        if a_list:
            next_turn = decide_turn(a_list)
        else:
            print('A')
            break
    elif next_turn == b:
        if b_list:
            next_turn = decide_turn(b_list)
        else:
            print('B')
            break
    else:
        if c_list:
            next_turn = decide_turn(c_list)
        else:
            print('C')
            break

Fixed submission:
sa=input()
sb=input()
sc=input()

t='a'
while True:
  if t=='a':
    if sa=='':
      print('A')
      exit()
    t=sa[0]
    sa=sa[1:]
  if t=='b':
    if sb=='':
      print('B')
      exit()
    t=sb[0]
    sb=sb[1:]
  if t=='c':
    if sc=='':
      print('C')
      exit()
    t=sc[0]
    sc=sc[1:]