Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
(n,),*t=[map(int,t.split())for t in open(0)]
n+=1
*e,=eval('[],'*n)
q=[n]
f=[-1]*n
for v,w,c in t:e[v]+=w*n+c,;e[w]+=v*n+c,
for v in q:
 f[v//n]=v%n&1
 for w in e[v//n]:q+=[w+v%n]*(f[w//n]<0)
print(*f[1:])

Fixed submission:
from collections import*
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for v,w,c in zip(t[::3],t[1::3],t[2::3]):
  e[v-1].append((w-1,c))
  e[w-1].append((v-1,c))
q=deque([(0,0)])
f=[0]+[-1]*~-n
while q:
  v,c=q.pop()
  for w,d in e[v]:
    if-1<f[w]:continue
    d=(c+d)%2
    f[w]=d
    q.append((w,d))
print(*f)

Buggy python submission (verdict: Runtime Error):
(n,),*t=[map(int,t,split())for t in open(0)]
*e,=eval('[],'*-~n)
q=[(1,0)]
f=[-1]*n
for v,w,c in t=:e[v]+=(w,c),;e[w]+=(v,c),
for v,c in q:
 f[v-1]=c%2
 for w,d in e[v]:q+=[(w,c+d)]*(f[w-1]<0)
print(*f)

Fixed submission:
from collections import*
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for v,w,c in zip(t[::3],t[1::3],t[2::3]):
  e[v-1].append((w-1,c))
  e[w-1].append((v-1,c))
q=deque([(0,0)])
f=[0]+[-1]*~-n
while q:
  v,c=q.pop()
  for w,d in e[v]:
    if-1<f[w]:continue
    d=(c+d)%2
    f[w]=d
    q.append((w,d))
print(*f)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input());e=[[]for _ in[0]*-~n];q=[(1,0)];f=[-1]*n;exec('v,w,c=map(int,input().split());e[v]+=(w,c),;e[w]+=(v,c),;'*~-n)
while q:
 v,c=q.pop();f[v-1]=c%2
 for w,d in e[v]:q+=[(w,c+d)]*(f[w-1]<0)
print(*f)

Fixed submission:
from collections import*
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for v,w,c in zip(t[::3],t[1::3],t[2::3]):
  e[v-1].append((w-1,c))
  e[w-1].append((v-1,c))
q=deque([(0,0)])
f=[0]+[-1]*~-n
while q:
  v,c=q.pop()
  for w,d in e[v]:
    if-1<f[w]:continue
    d=(c+d)%2
    f[w]=d
    q.append((w,d))
print(*f)

Buggy python submission (verdict: Runtime Error):
n=int(input());e=[[]for _ in[0]*-~n];q=[(1,0)];f=[-1]*n
while n>1:v,w,c=map(int,input().split());e[v]+=(w,c),;e[w]+=(v,c),;n-=1
while q:
 v,c=q.pop();f[v-1]=c%2
 for w,d in e[v]:q+=(w,c+d),*(f[w-1]<0)
print(*f)

Fixed submission:
from collections import*
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n)]
for v,w,c in zip(t[::3],t[1::3],t[2::3]):
  e[v-1].append((w-1,c))
  e[w-1].append((v-1,c))
q=deque([(0,0)])
f=[0]+[-1]*~-n
while q:
  v,c=q.pop()
  for w,d in e[v]:
    if-1<f[w]:continue
    d=(c+d)%2
    f[w]=d
    q.append((w,d))
print(*f)
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n=map(int,input().split())
a=0
for i in range(0,n+1,r):
    for j in range(0,n+1,g):
        k=n-i-j
        if k>=0 and not k%b:
            a+=1
print(a)

Fixed submission:
r,g,b,n=map(int,input().split())
a=0
for i in range(0,n+1,r):
    for j in range(0,n+1,g):
        k=n-i-j
        if k>=0 and not k%b:
            a+=1
print(a)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=0
for i in range(1,int(n**.5)+1):
    if i==n%(n//i-1):
        a+=n//i-1
print(a)

Fixed submission:
n=int(input())
a=0
for i in range(1,int(n**.5+1)):t=n//i-1;a+=t*(t and i==n%t)
print(a)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=0
for i in range(1,int(n**.5)+1):
    if i==n%(n//i-1):
        a+=n//i-1
print(a)

Fixed submission:
n=int(input())
a=0
for i in range(1,int(n**.5+1)):t=n//i-1;a+=t*(t and i==n%t)
print(a)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=0
for i in range(1,int(n**.5)+1):
    if i==n%(n//i-1):
        a+=n//i-1
print(a)

Fixed submission:
n=int(input())
a=0
for i in range(1,int(n**.5+1)):t=n//i-1;a+=t*(t and i==n%t)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import*;n,*t=map(int,open(0).read().split());b=csgraph.dijkstra;c=csr_matrix(([1]*~-n,(t[::2],t[1::2])),[n+1]*2);print('SFeicrosntd'[b(c,0,b(c,0,1)[1:].argmax()+1)[1:].max()%3!=1::2])

Fixed submission:
from collections import*
def s(s):
  f=[1]*-~n
  f[s]=0
  q=deque([(s,0)])
  while q:
    t,c=q.popleft()
    for v in e[t]:
      if f[v]:
        f[v]=0
        q.append((v,c+1))
  return t,c
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
  e[a].append(b)
  e[b].append(a)
print('SFeicrosntd'[s(s(1)[0])[1]%3!=1::2])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse import*;n,*t=map(int,open(0).read().split());b=csgraph.dijkstra;c=csr_matrix(([1]*~-n,(t[::2],t[1::2])),[n+1]*2);print('SFeicrosntd'[b(c,0,b(c,0,1)[1:].argmax()+1)[1:].max()%3!=1::2])

Fixed submission:
from collections import*
def s(s):
  f=[1]*-~n
  f[s]=0
  q=deque([(s,0)])
  while q:
    t,c=q.popleft()
    for v in e[t]:
      if f[v]:
        f[v]=0
        q.append((v,c+1))
  return t,c
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
  e[a].append(b)
  e[b].append(a)
print('SFeicrosntd'[s(s(1)[0])[1]%3!=1::2])

Buggy python submission (verdict: Runtime Error):
from scipy.sparse import*;n,*t=map(int,open(0).read().split());print('SFeicrosntd'[csgraph.dijkstra(csr_matrix(([1]*~-n,(t[::2],t[1::2])),[n+1]*2),0)[1:,1:].max()%3!=1::2])

Fixed submission:
from collections import*
def s(s):
  f=[1]*-~n
  f[s]=0
  q=deque([(s,0)])
  while q:
    t,c=q.popleft()
    for v in e[t]:
      if f[v]:
        f[v]=0
        q.append((v,c+1))
  return t,c
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
  e[a].append(b)
  e[b].append(a)
print('SFeicrosntd'[s(s(1)[0])[1]%3!=1::2])

Buggy python submission (verdict: Runtime Error):
from collections import*
def s():
 global a,b;f,q=[1]*-~n,deque([(a,0)])
 while q:
  a,b=q.popleft()
  for v in e[a]:q+=[(v,b+1)]*f[v];f[v]=0
n,*t=map(int,open(0).read().split())
e=[[]for _ in[0]*-~n]
for a,b in zip(t[::2],t[1::2]):e[a]+=b,;e[b]+=a,
s(),s()
print('SFeicrosntd'[b%3!=1::2])

Fixed submission:
from collections import*
def s(s):
  f=[1]*-~n
  f[s]=0
  q=deque([(s,0)])
  while q:
    t,c=q.popleft()
    for v in e[t]:
      if f[v]:
        f[v]=0
        q.append((v,c+1))
  return t,c
n,*t=map(int,open(0).read().split())
e=[[]for _ in range(n+1)]
for a,b in zip(t[::2],t[1::2]):
  e[a].append(b)
  e[b].append(a)
print('SFeicrosntd'[s(s(1)[0])[1]%3!=1::2])
Buggy python submission (verdict: Runtime Error):
from numpy import*;v,c=loadtxt(open(0),'i',skiprows=1);i=v>c;print(sum(v[i]-c[i]))

Fixed submission:
n,*t=map(int,open(0).read().split());print(sum((x-y)*(x>y)for x,y in zip(t[:n],t[n:])))

Buggy python submission (verdict: Runtime Error):
from numpy import*;v,c=loadtxt(open(0),skiprows=1);i=v>c;print(sum(v[i]-c[i]))

Fixed submission:
n,*t=map(int,open(0).read().split());print(sum((x-y)*(x>y)for x,y in zip(t[:n],t[n:])))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from fractions import gcd
    def update(k,x):
        k+=N0-1
        data[k]=x
        while k+1:
            k=~-k//2
            data[k]=gcd(data[2*k+1],data[2*k+2])
    def query(l,r):
        L,R=l+N0,r+N0
        s=0
        while L<R:
            if R&1:
                R-=1
                s=gcd(s,data[R-1])
            if L&1:
                s=gcd(s,data[L-1])
                L+=1
            L>>=1
            R>>=1
        return s
    n,*a=map(int,open(0).read().split())
    N0=2**(n-1).bit_length()
    data=[0]*2*N0
    for i in range(n):
        update(i,a[i])
    print(max(gcd(query(0,i),query(i+1,n))for i in range(n)))
if __name__=='__main__':
    main()

Fixed submission:
from fractions import*
def update(k,x):
    k+=N0-1
    data[k]=x
    while k+1:
        k=~-k//2
        data[k]=gcd(data[2*k+1],data[2*k+2])
def query(l,r):
    L,R=l+N0,r+N0
    s=0
    while L<R:
        if R&1:
            R-=1
            s=gcd(s,data[R-1])
        if L&1:
            s=gcd(s,data[L-1])
            L+=1
        L>>=1
        R>>=1
    return s
n,*a=map(int,open(0).read().split())
N0=2**(n-1).bit_length()
data=[0]*2*N0
for i in range(n):
    update(i,a[i])
print(max(gcd(query(0,i),query(i+1,n))for i in range(n)))
Buggy python submission (verdict: Time Limit Exceeded):
_,s=open(0);a=s.count('.'),
for i in s:a+=a[-1]+(i<'.'or-1),
print(min(a))

Fixed submission:
_,s=open(0);c=s.count('.');a=[c]
for i in s:c+=i<'.'or-1;a+=c,
print(min(a))
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
*s,=input()
g=[]
t=1
for i in range(1,n):
 if s[i]==s[i-1]:t+=1
 else:g.append(t);t=1
g.append(t)
for i in range(1,len(g)):g[i]+=g[i-1]
g=[0]+g+[g[-1]]
print(max(g[i]-g[max(0,i-2*k-1)]for i in range(s[0]=='1',len(g),2))

Fixed submission:
n,k=map(int,input().split())
*s,=input()
g=[]
t=1
for i in range(1,n):
    if s[i]==s[i-1]:
        t+=1
    else:
        g.append(t)
        t=1
g.append(t)
for i in range(1,len(g)):
    g[i]+=g[i-1]
g=[0]+g+[g[-1]]
a=0
for i in range(s[0]=='1',len(g),2):
    a=max(a,g[i]-g[max(0,i-2*k-1)])
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
def solve(p,q):
  return sorted(i+j for i in p for j in q)[-k:]
x,y,z,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in solve(solve(a,b),c)[::-1]:
  print(i)

Fixed submission:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))

Buggy python submission (verdict: Time Limit Exceeded):
I=lambda:map(int,input().split());*_,k=I();s=lambda*a:sorted(i+j for i in I()for j in a)[:-k-1:-1];print(*s(*s(*I())))

Fixed submission:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))

Buggy python submission (verdict: Time Limit Exceeded):
I=lambda:map(int,input().split());*_,k=I();s='sorted(i+j for i in I()for j in %s)[:-k-1:-1]';*a,=I();b=eval(s%'a');print(*eval(s%'b'))

Fixed submission:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))

Buggy python submission (verdict: Time Limit Exceeded):
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];S=sorted;print(*s(s(S(I()),S(I())),I()))

Fixed submission:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))

Buggy python submission (verdict: Time Limit Exceeded):
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[-k:];print(*s(s(I(),I()),I())[::-1])

Fixed submission:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))

Buggy python submission (verdict: Time Limit Exceeded):
I=lambda:tuple(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))

Fixed submission:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))

Buggy python submission (verdict: Time Limit Exceeded):
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))

Fixed submission:
I=lambda:list(map(int,input().split()));x,y,z,k=I();s=lambda a,b:sorted(i+j for i in a for j in b)[:-k-1:-1];print(*s(s(I(),I()),I()))
Buggy python submission (verdict: Runtime Error):
I=input;n,q=map(int,I().split());s=' %s '%I();l,r=0,n+1
for t,_,d in eval('I(),'*q)[::-1]:L,R=d<'R',d>'L';l+=t==s[l+1]*L-(t==s[l])*R;r+=t==s[r]*L-(t==s[r-1])*R
print(max(0,r-l-1))

Fixed submission:
def solve(mid,g):
    for t,d in zip(z[::2],z[1::2]):
        if s[mid]==t:
            mid-=(d<'R')or-1
    return mid==g
n,q,s,*z=open(0).read().split()
n,q=int(n),int(q)
s=' %s '%s
ok=0
ng=n+1
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid,0):
        ok=mid
    else:
        ng=mid
a=ok
ok=n+1
ng=0
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid,n+1):
        ok=mid
    else:
        ng=mid
print(max(0,ok-a-1))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import*
n,q=map(int,input().split())
s=input()
f=defaultdict(list)
for i,c in enumerate(s):
    f[c].append(i)
l=[1]*n
for _ in range(q):
    t,d=input().split()
    for i in f[t]:
        if d=='L':
            if i-1>=0:
                l[i-1]+=l[i]
        else:
            if i+1<n:
                l[i+1]+=l[i]
        l[i]=0
print(sum(l))

Fixed submission:
def solve(mid,g):
    for t,d in zip(z[::2],z[1::2]):
        if s[mid]==t:
            mid-=(d<'R')or-1
    return mid==g
n,q,s,*z=open(0).read().split()
n,q=int(n),int(q)
s=' %s '%s
ok=0
ng=n+1
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid,0):
        ok=mid
    else:
        ng=mid
a=ok
ok=n+1
ng=0
while abs(ok-ng)>1:
    mid=(ok+ng)//2
    if solve(mid,n+1):
        ok=mid
    else:
        ng=mid
print(max(0,ok-a-1))
Buggy python submission (verdict: Runtime Error):
print('TCGA'[id('')%5])

Fixed submission:
print({'A':'T','T':'A','C':'G','G':'C'}[input()])
Buggy python submission (verdict: Time Limit Exceeded):
I=lambda:map(int,input().split());n,q=I();s=input();a=0,
for i in range(n):a+=a[i]+(s[i-1:i+1]=='AC'),
while q:l,r=I();print(a[r]-a[l]);q-=1

Fixed submission:
n,q=map(int,input().split())
s=input()
a=[0]*n
for i in range(n):
    if i:
        a[i]=a[i-1]+(s[i-1:i+1]=='AC')
for _ in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])

Buggy python submission (verdict: Runtime Error):
I=input
n,q=map(int,I())
s=I()
a=[0]
for i in range(n):a+=[a[i]+(s[i-1:i+1]=='AC')]
for _ in[0]*q:l,r=map(int,I());print(a[r]-a[l])

Fixed submission:
n,q=map(int,input().split())
s=input()
a=[0]*n
for i in range(n):
    if i:
        a[i]=a[i-1]+(s[i-1:i+1]=='AC')
for _ in range(q):
    l,r=map(int,input().split())
    print(a[r-1]-a[l-1])
Buggy python submission (verdict: Runtime Error):
a=b=c=d=e=f=0;g=1;exec('a,b,c,d,e,f,g=b,e,e-d,f,g,g-c,(g*4-b-c-d-a*3))%(10**9+7);'*int(input()));print(g)

Fixed submission:
n=int(input())
A,C,G,T,M=0,1,2,3,10**9+7
r=range
dp=[[[[0]*4for k in r(4)]for j in r(4)]for i in r(n+1)]
dp[0][T][T][T]=1
for i in r(1,n+1):
  for j in r(4):
    for k in r(4):
      for l in r(4):
        for m in r(4):
          if any(t==(k,l,m)for t in((A,G,C),(A,C,G),(G,A,C)))or(j,l,m)==(A,G,C)or(j,k,m)==(A,G,C):continue
          dp[i][k][l][m]=(dp[i][k][l][m]+dp[i-1][j][k][l])%M
print(sum(dp[n][i][j][k]for i in r(4)for j in r(4)for k in r(4))%M)
Buggy python submission (verdict: Runtime Error):
n,*c=map(int,open(0).readlines())
l=[-1]*n
b=[]
for i in range(n):
  b.append(l[c[i]])
  l[c[i]]=i
dp=[1]+[0]*n
for i in range(1,n):
  dp[i]=dp[i-1]
  if c[i]!=c[i-1]and b[i]>-1:
    dp[i]=(dp[i]+dp[b[i]])%(10**9+7)
print(dp[-2])

Fixed submission:
n,*c=map(int,open(0).readlines())
l=[-1]*2**18
b=[]
for i in range(n):
  b.append(l[c[i]])
  l[c[i]]=i
dp=[1]+[0]*n
for i in range(1,n):
  dp[i]=dp[i-1]
  if c[i]!=c[i-1]and b[i]>-1:
    dp[i]=(dp[i]+dp[b[i]])%(10**9+7)
print(dp[-2])
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=0
for i in range(40):
    j=2**i
    x,y=-(-a//(j*2))*j*2,b//(j*2)*j*2
    if x>=y:
        t=0
        for p in range(a,b+1):
            t+=p&j>0
        #print(t)
    else:
        t=(y-x)//2
        t+=min(j,x-a)
        t+=max(0,b-y-j+1)
    c+=t%2*j
print(c)

Fixed submission:
a,b=map(int,input().split())
c=0
for i in range(40):
    j=2**i
    x,y=-(-a//(j*2))*j*2,b//(j*2)*j*2
    """
    if x>=y:
        t=0
        for p in range(a,b+1):
            t+=p&j>0
    else:
    """
    t=(y-x)//2
    t+=min(j,x-a)
    t+=max(0,b-y-j+1)
    c+=t%2*j
print(c)

Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
c=0
for i in range(40):
    j=2**i
    x,y=-(-a//(j*2))*j*2,b//(j*2)*j*2
    if x>=y:
        t=0
        for p in range(a,b+1):
            t+=p&j>0
    else:
        t=(y-x)//2
        for p in range(a,x):
            t+=p&j>0
        for p in range(y,b+1):
            t+=p&j>0
    c+=t%2*j
print(c)

Fixed submission:
a,b=map(int,input().split())
c=0
for i in range(40):
    j=2**i
    x,y=-(-a//(j*2))*j*2,b//(j*2)*j*2
    """
    if x>=y:
        t=0
        for p in range(a,b+1):
            t+=p&j>0
    else:
    """
    t=(y-x)//2
    t+=min(j,x-a)
    t+=max(0,b-y-j+1)
    c+=t%2*j
print(c)
Buggy python submission (verdict: Runtime Error):
from bisect import*
A,B=abs,bisect
a,b,q,*l=map(int,open(0).read().split())
f=2**60
s,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]
for x in l[a+b:]:
  m=f
  i,j=B(s,x),B(t,x)
  for v in s[i-1,i+1]:
    for w in t[j-1,j+1]:
      m=min(m,A(x-v)+A(v-w),A(x-w)+A(w-v))
  print(m)

Fixed submission:
from bisect import*
A,B=abs,bisect
a,b,q,*l=map(int,open(0).read().split())
f=2**60
s,t=[-f]+l[:a]+[f],[-f]+l[a:a+b]+[f]
for x in l[a+b:]:
  m=f
  i,j=B(s,x),B(t,x)
  for v in s[i-1:i+1]:
    for w in t[j-1:j+1]:
      m=min(m,A(x-v)+A(v-w),A(x-w)+A(w-v))
  print(m)
Buggy python submission (verdict: Runtime Error):
n,m,*a=map(int,open(0).read().split())
d=[0]+[-1]*n
for i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)
print(d[n])

Fixed submission:
n,m,*a=map(int,open(0).read().split())
d=[]
for i,j in((7,3),(9,6),(8,7),(6,6),(5,5),(4,4),(3,5),(1,2),(2,5)):
    if i in a:
        d.append((i,j))
dp=[0]*-~n
for i in range(1,n+1):
    for j,k in d:
        if i-k<0 or i-k!=0 and not dp[i-k]:continue
        dp[i]=max(dp[i],dp[i-k]*10+j)
print(dp[n])

Buggy python submission (verdict: Runtime Error):
n,m,*a=map(int,open(0).read().split())
d=[0]+[-1]*n
for i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)
print(d[n])

Fixed submission:
n,m,*a=map(int,open(0).read().split())
d=[]
for i,j in((7,3),(9,6),(8,7),(6,6),(5,5),(4,4),(3,5),(1,2),(2,5)):
    if i in a:
        d.append((i,j))
dp=[0]*-~n
for i in range(1,n+1):
    for j,k in d:
        if i-k<0 or i-k!=0 and not dp[i-k]:continue
        dp[i]=max(dp[i],dp[i-k]*10+j)
print(dp[n])
Buggy python submission (verdict: Runtime Error):
input();s=map(int,input().split());print('YNeos'[sum(s)-max(s)*2<1::2])

Fixed submission:
input();*s,=map(int,input().split());print('YNeos'[sum(s)-max(s)*2<1::2])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
f=[0]*n
d=[list(map(int,input().split()))+[i]for i in range(n)]
t=sorted(d,key=lambda x:(x[0]-x[1],-x[0]))
a=sorted(d,key=lambda x:(x[0]-x[1],-x[1]))
sumt=suma=0
while t:
    x=t.pop(0)
    while t and f[x[2]]:
        x=t.pop(0)
    if not f[x[2]]:
        sumt+=x[0]
    f[x[2]]=1
    if a:
        y=a.pop(0)
        while a and f[y[2]]:
            y=a.pop(0)
        if not f[y[2]]:
            suma+=y[1]
        f[y[2]]=1
print(sumt-suma)

Fixed submission:
n=int(input())
d=sorted([list(map(int,input().split()))for _ in[0]*n],key=lambda x:sum(x))[::-1]
t=d[::2]
a=d[1::2]
print(sum(v[0]for v in t)-sum(v[1]for v in a))
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
v,n=map(int,input().split())
n+=v-1
es=[[int(x)for x in input().split()]for _ in range(n)]
outs={}
ins={}
for v1,v2 in es:
    outs[v1]=outs.get(v1,[])+[v2]
    ins[v2]=ins.get(v2,0)+1
q=deque(v1 for v1 in range(v)if not ins.get(v1,0))
res=[]
p=[0]*-~v
while q:
    v1=q.popleft()
    res.append(v1)
    for v2 in outs.get(v1,[]):
        ins[v2]-=1
        if ins[v2]==0:
            q.append(v2)
            p[v2]=v1
for t in p[1:]:print(t)

Fixed submission:
from collections import defaultdict, deque

v, n = map(int, input().split())
n += v -1
es = [[int(x) for x in input().split()] for _ in range(n)]

outs = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(v) if ins[v1] == 0)
res = []
f = [0]*(v+1)
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
            f[v2] = v1
for t in f[1:]:
    print(t)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict, deque

v, n = map(int, input().split())
n += v -1
es = [[int(x) for x in input().split()] for _ in range(n)]
f = [[]for _ in range(v+1)]
for a, b in es:
    f[b] += [a]

outs = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(v) if ins[v1] == 0)
res = []
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)

for i in range(1, v+1):
    j = res.index(i) - 1
    if res[j] and not res[j] in f[i]:j -= 1
    print(res[j])

Fixed submission:
from collections import defaultdict, deque

v, n = map(int, input().split())
n += v -1
es = [[int(x) for x in input().split()] for _ in range(n)]

outs = defaultdict(list)
ins = defaultdict(int)
for v1, v2 in es:
    outs[v1].append(v2)
    ins[v2] += 1

q = deque(v1 for v1 in range(v) if ins[v1] == 0)
res = []
f = [0]*(v+1)
while q:
    v1 = q.popleft()
    res.append(v1)
    for v2 in outs[v1]:
        ins[v2] -= 1
        if ins[v2] == 0:
            q.append(v2)
            f[v2] = v1
for t in f[1:]:
    print(t)
Buggy python submission (verdict: Runtime Error):
s=input();print(eval(s[:2]+'*'+s[2:-2])//2)

Fixed submission:
a,b,_=map(int,input().split())
print(a*b//2)
Buggy python submission (verdict: Runtime Error):
import heapq as h;I=lambda:list(map(int,input().split()));n,k=I();z=[i*2+1for i in range(n)];s=sorted([I()for _ in[0]*n],key=lambda x:-x[1]);q=[];v=T=0;l=[0]*-~n
for a in s[:k]:
 if l[a[0]]:h.heappush(q,a[1])
 else:A+=z[v];v+=1
 l[a[0]]=1;A+=a[1]
T=A
for a in s[k:]:
 if not q:break
 if l[a[0]]^1:l[a[0]]=1;t=h.heappop(q);T=T-t+a[1]+z[v];v+=1;A=max(A,T)
print(A)

Fixed submission:
import heapq
n,k=map(int,input().split())
z=[0,1]
for i in range(1,n):
    z.append(z[i]+2)
s=sorted([list(map(int,input().split()))for _ in range(n)],key=lambda x:-x[1])
q=[]
v=0
ans=0
l=[0]*-~n
for a in s[:k]:
    if not l[a[0]]:
        v+=1
        ans+=z[v]
    else:
        heapq.heappush(q,a[1])
    l[a[0]]=1
    ans+=a[1]
tem=ans
for a in s[k:]:
    if not q:break
    if l[a[0]]:continue
    l[a[0]]=1
    v+=1
    t=heapq.heappop(q)
    tem=tem-t+a[1]+z[v]
    ans=max(ans,tem)
print(ans)