Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys, itertools
input = sys.stdin.readline

n = int(input())
ll = []
for i in range(n):
  a = int(input())
  for j in range(a):
    x, y = map(int, input().split())
  ll.append([i, x-1, y])

ans = 0

for p in itertools.product([1,0], repeat=n):
  ok = 1
  for l in ll:
    if p[l[0]] == 1 and p[l[1]] != l[2]:
      ok = 0
      break
  if ok:
    ans = max(ans, sum(p))

print(ans)

Fixed submission:
n = int(input())
la, lxy = [], []
for i in range(n):
  a = int(input())
  la.append(a)
  xy = []
  for j in range(a):
    xy.append(list(map(int, input().split())))
  lxy.append(xy)

lb = []
for i in range(2**n):
  lb += [str(bin(i))[2:].zfill(n)]
lc = [sum(int(j) for j in i) for i in lb]
lc, lb = zip(*sorted(zip(lc, lb), reverse=True))
lb = [[int(j) for j in i] for i in lb]

for l in lb:
  ok = 1
  for i in range(n):
    a = la[i]
    for j in range(a):
      x, y = lxy[i][j]
      if l[i] == 1 and l[x-1] != y:
        ok = 0
        break
  if ok:
    print(sum(int(k) for k in l))
    break
else:
  print(0)

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

l = []
for i in range(2**n,,-1):
  l += ['{:0=3}'.format(int(str(bin(i))[2:]))]

print(l)

Fixed submission:
n = int(input())
la, lxy = [], []
for i in range(n):
  a = int(input())
  la.append(a)
  xy = []
  for j in range(a):
    xy.append(list(map(int, input().split())))
  lxy.append(xy)

lb = []
for i in range(2**n):
  lb += [str(bin(i))[2:].zfill(n)]
lc = [sum(int(j) for j in i) for i in lb]
lc, lb = zip(*sorted(zip(lc, lb), reverse=True))
lb = [[int(j) for j in i] for i in lb]

for l in lb:
  ok = 1
  for i in range(n):
    a = la[i]
    for j in range(a):
      x, y = lxy[i][j]
      if l[i] == 1 and l[x-1] != y:
        ok = 0
        break
  if ok:
    print(sum(int(k) for k in l))
    break
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
n,*l=map(int,open(0).read().split());a=0;M=10**9+7
for i in range(60):t=sum(j>>i&1 for j in l);a+=t*(n-t)*pow(2,i,M)
print(a%M)

Fixed submission:
M=10**9+7
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(60):
  t=sum((l[j]>>i)%2 for j in range(n))
  a+=(t*(n-t)<<i)%M
print(a%M)

Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(60):
  t=sum(j>>i&1 for j in l)
  a+=(t*(n-t)<<i)%M
print(a%M)

Fixed submission:
M=10**9+7
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(60):
  t=sum((l[j]>>i)%2 for j in range(n))
  a+=(t*(n-t)<<i)%M
print(a%M)

Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(60):
  t=sum((l[j]>>i)%2 for j in range(n))
  a+=(t*(n-t)<<i)%M
print(a%M)

Fixed submission:
M=10**9+7
n=int(input())
l=list(map(int,input().split()))
a=0
for i in range(60):
  t=sum((l[j]>>i)%2 for j in range(n))
  a+=(t*(n-t)<<i)%M
print(a%M)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
l=list(map(int,input().split()))
print(*[l.index(i+1)+1 for i in range(n)])

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

ll = []
for i, j in enumerate(l):
  ll.append([i+1, j])
ll.sort(key=lambda x:x[1])

la = []
for i in range(n):
  la.append(ll[i][0])

print(*la)
Buggy python submission (verdict: Runtime Error):
)from fractions import *
a,b=map(int,input().split())
g=gcd(a,b)
l=[g]
for i in range(2,int(g**.5)+1):
  if g%i<1: l+=[i,g//i]
c=1
for i in sorted(l):
  if g<2: break
  if g%i<1: c+=1
  while g%i<1: g//=i
print(c)

Fixed submission:
from fractions import *
a,b=map(int,input().split())
g=gcd(a,b)
l=[g]
for i in range(2,int(g**.5)+1):
  if g%i<1: l+=[i,g//i]
c=1
for i in sorted(l):
  if g<2: break
  if g%i<1: c+=1
  while g%i<1: g//=i
print(c)
Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
l = [int(input())-1 for _ in range(q)]
l.sort()
 
for i in range(n):
  cnt = 0
  if l and l[0] == i:
    while l and l[0] == i:
      l.pop(0)
      cnt += 1
  print(('No','Yes')[k > q - cnt])

Fixed submission:
n, k, q = map(int, input().split())
l = [int(input())-1 for _ in range(q)]
l.sort()

for i in range(n):
  cnt = 0
  if l and l[0] == i:
    while l and l[0] == i:
      l.pop(0)
      cnt += 1
  print(('No','Yes')[k > q - cnt])

Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
l = [int(input())-1 for _ in range(q)]

for i in range(n):
  print(('No','Yes')[k > q - l.count(i)])

Fixed submission:
n, k, q = map(int, input().split())
l = [int(input())-1 for _ in range(q)]
l.sort()

for i in range(n):
  cnt = 0
  if l and l[0] == i:
    while l and l[0] == i:
      l.pop(0)
      cnt += 1
  print(('No','Yes')[k > q - cnt])

Buggy python submission (verdict: Time Limit Exceeded):
n, k, q = map(int, input().split())
l = [k]*n
for _ in range(q):
  a = int(input())-1
  l = list(map(lambda x:x-1, l))
  l[a] += 1
for i in l:
  print(('No','Yes')[i>0])

Fixed submission:
n, k, q = map(int, input().split())
l = [int(input())-1 for _ in range(q)]
l.sort()

for i in range(n):
  cnt = 0
  if l and l[0] == i:
    while l and l[0] == i:
      l.pop(0)
      cnt += 1
  print(('No','Yes')[k > q - cnt])
Buggy python submission (verdict: Time Limit Exceeded):
f = lambda:map(int,input().split())
n,m = f()
l = sorted(f())
for _ in range(m):
  l.append(l.pop()//2)
  l.sort()
print(sum(l))

Fixed submission:
f = lambda:map(int,input().split())
_,m = f()
l = list(map(lambda x:-x,f()))
import heapq as hq
hq.heapify(l)
for i in range(m):
  p = -hq.heappop(l)//2
  hq.heappush(l,-p)
print(-sum(l))
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = map(int, input().split())

ans = l[0] + l[-1]
for i in range(n-2):
  ans += min(l[i], l[i+1])
print(ans)

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

ans = l[0] + l[-1]
for i in range(n-2):
  ans += min(l[i], l[i+1])
print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
f=lambda:map(int,sys.stdin.readline().split())
n,q=f()
g=[[] for _ in range(n)]
for i in range(n-1):
  a,b=f()
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]
c=[0]*n
for i in range(q):
  v,x=f()
  c[v-1]+=x
def dfs(v,p=-1):
  for i in g[v]:
    if i==p: continue
    c[i]+=c[v]
    dfs(i,v)
dfs(0)
print(*c)

Fixed submission:
import sys
f=lambda:map(int,sys.stdin.readline().split())
n,q=f()
g=[[] for _ in range(n)]
for i in range(n-1):
  a,b=f()
  g[a-1]+=[b-1]
  g[b-1]+=[a-1]
c=[0]*n
for i in range(q):
  v,x=f()
  c[v-1]+=x
b=[0]+[1]*(n-1)
s=[0]
while s:
  t=s.pop()
  for i in g[t]:
    if b[i]:
      c[i]+=c[t]
      s+=[i]
      b[i]=0
print(*c)
Buggy python submission (verdict: Runtime Error):
k,x=int(input())
print(*[i for i in range(x-k+1,x+k)])

Fixed submission:
k, x = map(int, input().split())
print(*list(range(x-k+1, x+k)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = []
for i in range(n):
  l.append(''.join(sorted(input())))
s = set(l)

from math import factorial as f
def c(n, k):
  return f(n)//(f(n-k)*f(k)) if n>=k else 0

print(sum(c(l.count(a), 2) for a in s))

Fixed submission:
n = int(input())
l = []
for i in range(n):
  l.append(''.join(sorted(input())))
l.sort()

cnt = 0
ans = 0
for i in range(n-1):
  if l[i+1] == l[i]:
    cnt += 1
    ans += cnt
  else:
    cnt = 0
print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
l = []
for i in range(n):
  l.append(''.join(sorted(input())))
s = set(l)

def f(k):
  return k*f(k-1) if k>1 else 1
def c(n, k):
  return f(n)//(f(n-k)*f(k)) if n>=k else 0

print(sum(c(l.count(a), 2) for a in s))

Fixed submission:
n = int(input())
l = []
for i in range(n):
  l.append(''.join(sorted(input())))
l.sort()

cnt = 0
ans = 0
for i in range(n-1):
  if l[i+1] == l[i]:
    cnt += 1
    ans += cnt
  else:
    cnt = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7
s=input()
r=range
dp=[[0]*13,[0]*13]
dp[0][0]=1
t=0
for c in s:
  for i in r(13):
    if c=='?':
      for j in r(10):
        dp[t^1][(i*10+j)%13]+=dp[t][i]
    else:
      dp[t^1][(i*10+int(c))%13]+=dp[t][i]
  dp[t]=[0]*13
  t^=1
  for i in r(13): dp[t][i]%=M
print(dp[len(s)%2][5])

Fixed submission:
M=10**9+7
s=input()
r=range
dp=[[0]*13,[0]*13]
dp[0][0]=1
t=0
for c in s:
  for i in r(13):
    if c=='?':
      for j in r(10):
        dp[t^1][(i*10+j)%13]+=dp[t][i]
    else:
      dp[t^1][(i*10+int(c))%13]+=dp[t][i]
  dp[t]=[0]*13
  t^=1
  for i in r(13): dp[t][i]%=M
print(dp[len(s)%2][5])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = [int(input()) for _ in range(n)]

for i in range(n):
  li = l[:i] + l[i+1:]
  print(max(li))

Fixed submission:
n = int(input())
l = [int(input()) for _ in range(n)]
ls = sorted(l)

for i in range(n):
  print(ls[-1] if l[i] != ls[-1] else ls[-2])
Buggy python submission (verdict: Time Limit Exceeded):
l,r=map(int,input().split())
m=[i%2019 for i in range(l,r+1)]
print(0 if r-l>671 else min(i*j%2019 for i in m for j in m if i<j))

Fixed submission:
mod = 2019
l, r = map(int, input().split())

if r//mod - l//mod > 0:
  print(0)
else:
  l %= mod
  r %= mod
  ans = mod - 1
  for i in range(l+1, r+1):
    for j in range(l, i):
      ans = min(i*j%mod, ans)
  print(ans)

Buggy python submission (verdict: Runtime Error):
L,R=map(int,input().split())
M=2019;l,r=L%M,R%M
print([min(i*j%M for i in range(l+1,r+1) for j in range(l,i)),0][R//M-L//M>0])

Fixed submission:
mod = 2019
l, r = map(int, input().split())

if r//mod - l//mod > 0:
  print(0)
else:
  l %= mod
  r %= mod
  ans = mod - 1
  for i in range(l+1, r+1):
    for j in range(l, i):
      ans = min(i*j%mod, ans)
  print(ans)

Buggy python submission (verdict: Runtime Error):
L,R=map(int,input().split())
M=2019;l,r=L%M,R%M
print([min(i*j%M for i in range(l,r) for j in range(i+1,r+1)),0][R//M-L//M>0])

Fixed submission:
mod = 2019
l, r = map(int, input().split())

if r//mod - l//mod > 0:
  print(0)
else:
  l %= mod
  r %= mod
  ans = mod - 1
  for i in range(l+1, r+1):
    for j in range(l, i):
      ans = min(i*j%mod, ans)
  print(ans)
Buggy python submission (verdict: Runtime Error):
M=10**9+7
f=input
n,m=map(int,f().split())
s,t,u=0,1,int(f())
for i in range(n):
  if i==u-1:
    s,t=t,0
    try: u=int(f())
    except: pass
  else: s,t=t,(s+t)%M
print(t)

Fixed submission:
mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 0
t1 = 1

for i in range(1,n+1):
  if l == [] or i != l[0]:
    t0 = (t2+t1)%mod
  else:
    l.pop(0)
    t0 = 0
  t2 = t1
  t1 = t0

print(t0)

Buggy python submission (verdict: Time Limit Exceeded):
M=10**9+7
n,m=map(int,input().split())
l=[int(input())-1 for _ in range(m)]
s,t=0,1
for i in range(n):
  if i in l: s,t=t,0
  else: s,t=t,(s+t)%M
print(t)

Fixed submission:
mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 0
t1 = 1

for i in range(1,n+1):
  if l == [] or i != l[0]:
    t0 = (t2+t1)%mod
  else:
    l.pop(0)
    t0 = 0
  t2 = t1
  t1 = t0

print(t0)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 1
t1 = 0 if 1 in l else 1

if n == 1:
  print(1)
else:
  for i in range(2,n+1):
    if l == [] or i != l[0]:
      t0 = 0 if i in l else (t2+t1)%mod
    else:
      l.pop(0)
      t0 = 0
    t2 = t1
    t1 = t0
  print(t0)

Fixed submission:
mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 0
t1 = 1

for i in range(1,n+1):
  if l == [] or i != l[0]:
    t0 = (t2+t1)%mod
  else:
    l.pop(0)
    t0 = 0
  t2 = t1
  t1 = t0

print(t0)

Buggy python submission (verdict: Runtime Error):
mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 1
t1 = 0 if 1 in l else 1

for i in range(2,n+1):
  t0 = 0 if i in l else (t2+t1)%mod
  t2 = t1
  t1 = t0

print(t0)

Fixed submission:
mod = 10**9+7
n, m = map(int, input().split())
l = [int(input()) for _ in range(m)]

t2 = 0
t1 = 1

for i in range(1,n+1):
  if l == [] or i != l[0]:
    t0 = (t2+t1)%mod
  else:
    l.pop(0)
    t0 = 0
  t2 = t1
  t1 = t0

print(t0)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
f=lambda:map(int,sys.stdin.readline().split())
n,m=f()
l=sorted(f())
s=[]
t=0
for i in range(m):
  b,c=f()
  s+=[c]*b
  t+=b
s.sort(reverse=1)
a=0
for i in range(n):
  if i<t: a+=max(l[i],s[i])
  else: a+=l[i]
print(a)

Fixed submission:
import sys
f=lambda:map(int,sys.stdin.readline().split())
n,m=f()
la=sorted(f())
ll=sorted([list(f()) for _ in range(m)],key=lambda k:-k[1])
ls=[]
t=0
for b,c in ll:
  if t+b>n:
    ls+=[c]*(n-t)
    t=n
    break
  ls+=[c]*b
  t+=b
ls.sort(reverse=1)
a=0
for i in range(n):
  if i<t: a+=max(la[i],ls[i])
  else: a+=la[i]
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
f=lambda:map(int,sys.stdin.readline().split())
n,m=f()
l=sorted(f())
s=[]
t=0
for i in range(m):
  b,c=f()
  s+=[c]*b
  t+=b
s.sort(reverse=1)
a=0
for i in range(n):
  if i<t: a+=max(l[i],s[i])
  else: a+=l[i]
print(a)

Fixed submission:
import sys
f=lambda:map(int,sys.stdin.readline().split())
n,m=f()
la=sorted(f())
ll=sorted([list(f()) for _ in range(m)],key=lambda k:-k[1])
ls=[]
t=0
for b,c in ll:
  if t+b>n:
    ls+=[c]*(n-t)
    t=n
    break
  ls+=[c]*b
  t+=b
ls.sort(reverse=1)
a=0
for i in range(n):
  if i<t: a+=max(la[i],ls[i])
  else: a+=la[i]
print(a)
Buggy python submission (verdict: Runtime Error):
s = input()

l = 0<int(s[:2])<13
r = 0<int(s[2:])<13

if l = 1:
  print('AMBIGUOUS' if r = 1 else 'MMYY')
else:
  print('YYMM' if r = 1 else 'NA')

Fixed submission:
s = input()

l = 0<int(s[:2])<13
r = 0<int(s[2:])<13

if l == 1:
  print('AMBIGUOUS' if r == 1 else 'MMYY')
else:
  print('YYMM' if r == 1 else 'NA')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

def gcd(x,y):
  while y:
    x, y = y, x%y
  return x

ans = 0
for i in range(n):
  g = l[0] if i > 0 else l[1]
  for j in range(1,n):
    if j != i:
      g = gcd(g, l[j])
  ans = max(ans, g)

print(ans)

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

def gcd(x,y):
  while y:
    x, y = y, x%y
  return x

ll, lr = [0]*n, [0]*n
ll[0], lr[n-1] = a[0], a[n-1]
for i in range(1,n):
  ll[i] = gcd(ll[i-1], a[i])
  lr[n-i-1] = gcd(lr[n-i], a[n-i-1])

print(max(ll[n-2], lr[1], *[gcd(l,r) for l,r in zip(ll[:n-2], lr[2:])]))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int, input().split()))

def gcd(x,y):
  while y:
    x, y = y, x%y
  return x

ans = 0
for i in range(n):
  g = l[0] if i > 0 else l[1]
  for j in range(1,n):
    if j != i:
      g = gcd(g, l[j])
  ans = max(ans, g)

print(ans)

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

def gcd(x,y):
  while y:
    x, y = y, x%y
  return x

ll, lr = [0]*n, [0]*n
ll[0], lr[n-1] = a[0], a[n-1]
for i in range(1,n):
  ll[i] = gcd(ll[i-1], a[i])
  lr[n-i-1] = gcd(lr[n-i], a[n-i-1])

print(max(ll[n-2], lr[1], *[gcd(l,r) for l,r in zip(ll[:n-2], lr[2:])]))
Buggy python submission (verdict: Time Limit Exceeded):
f = lambda : map(int,input().split())
n, q = f()
s = input()
ln = [0]*n
for i in range(n-1):
  if s[i:i+2] == 'AC':
    ln[i] = 1
for _ in range(q):
  l, r = f()
  print(sum(ln[l-1:r-1]))

Fixed submission:
f = lambda : map(int,input().split())
n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())
n, q = f()
s = input()
for _ in range(q):
  l, r = f()
  ans = 0
  for i in range(l-1,r-1):
    if s[i:i+2] == 'AC':
      ans += 1
  print(ans)

Fixed submission:
f = lambda : map(int,input().split())
n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
f = lambda : map(int,input().split())
n, q = f()
s = input()
for _ in range(q):
  l, r = f()
  ans = 0
  for i in range(l-1,r-1):
    if s[i:i+2] == 'AC':
      ans += 1
  print(ans)

Fixed submission:
f = lambda : map(int,input().split())
n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())
n, q = f()
s = input()
for _ in range(q):
  l, r = f()
  print(s[l-1:r].count('AC'))

Fixed submission:
f = lambda : map(int,input().split())
n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
f = lambda : map(int,input().split())
n, q = f()
s = input()
for _ in range(q):
  l, r = f()
  print(s[l-1:r].count('AC'))

Fixed submission:
f = lambda : map(int,input().split())
n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
f = lambda : map(int,input().split())
n, q = f()
s = input()
for _ in range(q):
  l, r = f()
  print(s[l-1:r].count('AC'))

Fixed submission:
f = lambda : map(int,input().split())
n, q = f()
s = input()

cnt = 0
ln = [0]*n
for i in range(1,n):
  if s[i-1:i+1] == 'AC':
    cnt += 1
  ln[i] = cnt
for _ in range(q):
  l, r = f()
  print(ln[r-1]-ln[l-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ls = list(map(int,list(s)))
lt = []
for i in range(len(s)-1):
  lt.append(ls[i]+ls[i+1])

ans = 0
while 1 in lt:
  flg = 1
  n = len(ls)
  for i in range(1,n):
    if flg == 1 and lt[n-i-1] == 1:
      ls.pop(n-i)
      ls.pop(n-i-1)
      ans += 2
      flg = 0
    elif flg == 0:
      flg = 1
  lt = []
  for i in range(len(ls)-1):
  	lt.append(ls[i]+ls[i+1])
print(ans)

Fixed submission:
s = input()
print(min(s.count('0'),s.count('1'))*2)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
ls = list(map(int,list(s)))
lt = []
for i in range(len(s)-1):
  lt.append(ls[i]+ls[i+1])

ans = 0
while 1 in lt:
  flg = 1
  lf = [1]*len(ls)
  for i in range(len(lt)):
    if flg == 1 and lt[i] == 1:
      lf[i] = 0
      lf[i+1] = 0
      ans += 2
      flg = 0
    elif flg == 0:
      flg = 1
  ls = [ls[i] for i,f in enumerate(lf) if f>0]
  lt = []
  for i in range(len(ls)-1):
  	lt.append(ls[i]+ls[i+1])

print(ans)

Fixed submission:
s = input()
print(min(s.count('0'),s.count('1'))*2)

Buggy python submission (verdict: Runtime Error):
s = input()
ls = list(int(s))

ans = 0
lf = [1]*n
while '01' in s or '10' in s:
  for i in range(len(ls)):
    if sum(ls[i:i+2]) == 1:
      lf[i] = 0
      lf[i+1] = 0
      ans += 1
  ls,lf = *[s,f for s,f in zip(ls,lf) if lf[i]>0]
print(ans)

Fixed submission:
s = input()
print(min(s.count('0'),s.count('1'))*2)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
l = sorted([int(input()) for _ in range(n)])
print(min(l[i+k]-l[i] for i in range(n-k+1))) 

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
l = sorted([int(input()) for _ in range(n)])
print(min(l[i+k-1]-l[i] for i in range(n-k+1)))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
l = sorted([int(input()) for _ in range(n)])
print(min(l[i+2]-l[i] for i in range(n-k+1)))

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
l = sorted([int(input()) for _ in range(n)])
print(min(l[i+k-1]-l[i] for i in range(n-k+1)))
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = list(input().split())
ll,lr = l[::2],l[1::2]
dl,dr = {},{}
for i in ll: dl[i] = dl.get(i,0)+1
for j in lr: dr[j] = dr.get(j,0)+1
ltl = sorted(dl.items(),key=lambda k:-k[1])
ltr = sorted(dr.items(),key=lambda k:-k[1])
if ltl[0][0] != ltr[0][0]:
  print(n-ltl[0][1]-ltr[0][1])
elif len(ltl)<2:
  print(n//2)
else:
  print(n-ltl[0][1]-max(lt1[1][1],ltr[1][1]))

Fixed submission:
n = int(input())
l = list(input().split())
ll,lr = l[::2],l[1::2]
dl,dr = {},{}
for i in ll: dl[i] = dl.get(i,0)+1
for j in lr: dr[j] = dr.get(j,0)+1
ltl = sorted(dl.items(),key=lambda k:-k[1])
ltr = sorted(dr.items(),key=lambda k:-k[1])
if ltl[0][0] != ltr[0][0]:
  print(n-ltl[0][1]-ltr[0][1])
elif len(ltl)<2:
  print(n//2)
else:
  print(n-ltl[0][1]-max(ltl[1][1],ltr[1][1]))
Buggy python submission (verdict: Runtime Error):
h, w = map(int, input().split())

ll = [list(input()) for _ in range(h)]
lh = [h for h in ll if '#' in h]
lw = zip(*[w for w in zip(*lh) if '#' in w])

for l in lw:
  print(''.join(l))

Fixed submission:
n, i = map(int,input().split())
print(n-i+1)
Buggy python submission (verdict: Runtime Error):
s=input()[:int(input())].replace('1','')
print([s[0],1][s==''])

Fixed submission:
s = input()
if set(s[:int(input())])=={'1'}:
  print(1)
else:
  for i in s:
    if int(i) > 1:
      print(int(i))
      break

Buggy python submission (verdict: Runtime Error):
print(input()[:int(input())].replace('1','')[0]or 1)

Fixed submission:
s = input()
if set(s[:int(input())])=={'1'}:
  print(1)
else:
  for i in s:
    if int(i) > 1:
      print(int(i))
      break
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
l = list(l[i]-i for i in range(n))
m = 10**15
for i in set(l):
  m = min(m,sum(abs(j-i) for j in l))
print(m)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l = list(l[i]-i for i in range(n))
import statistics as st
m = int(st.median(l))
print(sum(abs(m-i) for i in l))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
l = list(map(int,input().split()))
l = list(l[i]-i for i in range(n))
m = 10**15
for i in range(min(l),max(l)+1):
  m = min(m,sum(abs(j-i) for j in l))
print(m)

Fixed submission:
n = int(input())
l = list(map(int,input().split()))
l = list(l[i]-i for i in range(n))
import statistics as st
m = int(st.median(l))
print(sum(abs(m-i) for i in l))
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
a=n
for i in range(n):
  a=min(a,s[:i].count('W')+s[i+1:].count('E'))
print(a)

Fixed submission:
n=int(input())
s=input()
t=s[1:].count('E')
a=t
for i in range(n-1):
  t+=(s[i]=='W')-(s[i+1]=='E')
  a=min(a,t)
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
w=input()
n=int(input())
import itertools as it
s={w}
for i,j in it.product(range(len(w)),repeat=2):
  if i<=j: s.add(w[i:j+1])
print(sorted(s)[n-1])

Fixed submission:
w=input();n=int(input())
print(sorted({w[j:j+i+1] for i in range(n) for j in range(len(w)-i)})[n-1])
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())

for i in range(a, b+1):
  if i<a+k or b-k<i:
    print(i)

Fixed submission:
a,b,k = map(int,input().split())

if b-a < 2*k:
  for i in range(a, b+1):
    print(i)
else:
  for i in range(k):
    print(a+i)
  for i in range(k):
    print(b-k+1+i)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(input().split())
print('YNeos'[a+b<c::2])

Fixed submission:
a,b,c=map(int,input().split())
print('YNeos'[a+b<c::2])
Buggy python submission (verdict: Runtime Error):
n=int(input())
d={'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n): d[input()[0]]+=1
import itertools as it
print(sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3)))

Fixed submission:
n=int(input())
from collections import *
d=Counter()
for _ in range(n): d[input()[0]]+=1
import itertools as it
print(sum(d[s]*d[t]*d[r] for s,t,r in it.combinations('MARCH',3)))