Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
r=int(input())
g=int(input())
print(int(g*2−r))

Fixed submission:
r=int(input())
g=int(input())
print(2*g-r)

Buggy python submission (verdict: Runtime Error):
r=int(input())
g=int(input())
print(g*2−r)

Fixed submission:
r=int(input())
g=int(input())
print(2*g-r)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
graph=[[0 for _ in range(m)] for _ in range(m)]
for i in range(m):
  graph[ab[i][0]-1][ab[i][1]-1]=1
  graph[ab[i][1]-1][ab[i][0]-1]=1
visited=[0 for _ in range(m)]

def dfs(v):
  visited[v]=1
  for v2 in range(n):
    if graph[v][v2]==0:
      continue
    if visited[v2]==1:
      continue
    dfs(v2)

ans=0

for i in range(m):
  graph[ab[i][0]-1][ab[i][1]-1]=0
  graph[ab[i][1]-1][ab[i][0]-1]=0
  for j in range(n):
    visited[j]=0
  dfs(0)
  bridge=0
  for j in range(n):
    if visited[j]==0:
      bridge=1
  if bridge==1:
    ans+=1
  graph[ab[i][0]-1][ab[i][1]-1]=1
  graph[ab[i][1]-1][ab[i][0]-1]=1
print(ans)

Fixed submission:
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
graph=[[0 for _ in range(n)] for _ in range(n)]
for i in range(m):
  graph[ab[i][0]-1][ab[i][1]-1]=1
  graph[ab[i][1]-1][ab[i][0]-1]=1
visited=[0 for _ in range(n)]

def dfs(v):
  visited[v]=1
  for v2 in range(n):
    if graph[v][v2]==0:
      continue
    if visited[v2]==1:
      continue
    dfs(v2)

ans=0

for i in range(m):
  graph[ab[i][0]-1][ab[i][1]-1]=0
  graph[ab[i][1]-1][ab[i][0]-1]=0
  for j in range(n):
    visited[j]=0
  dfs(0)
  bridge=0
  for j in range(n):
    if visited[j]==0:
      bridge=1
  if bridge==1:
    ans+=1
  graph[ab[i][0]-1][ab[i][1]-1]=1
  graph[ab[i][1]-1][ab[i][0]-1]=1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    if 4*h*n-N*n-N*h!=0 and (N*h*n)%(4*h*n-N*n-N*h)==0 and (N*h*n)//(4*h*n-N*n-N*h)>0:
      print(h,n,(N*h*n)//(4*h*n-N*n-N*h))
      exit()

Fixed submission:
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    if 4*h*n-N*n-N*h>0:
      if (N*h*n)%(4*h*n-N*n-N*h)==0:
        print(h,n,(N*h*n)//(4*h*n-N*n-N*h))
        exit()

Buggy python submission (verdict: Runtime Error):
N=int(input())
for h in range(3501):
  for n in range(3501):
    if (N*h*n)%(4*h*n-N*n-N*h)==0:
      print(h,n,(N*h*n)%(4*h*n-N*n-N*h))

Fixed submission:
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    if 4*h*n-N*n-N*h>0:
      if (N*h*n)%(4*h*n-N*n-N*h)==0:
        print(h,n,(N*h*n)//(4*h*n-N*n-N*h))
        exit()
Buggy python submission (verdict: Runtime Error):
print(''.join(list(input())[1::2])

Fixed submission:
print(''.join(list(input())[::2]))
Buggy python submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
print("A" if |x-a|<|x-b| else "B")

Fixed submission:
x,a,b=map(int,input().split())
print("A" if abs(x-a)<abs(x-b) else "B")
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())
s=[]
for i in range(0,101):
  if a<=i<=b and c<=i<=d:
    s.append(i)
print(max(s)-min(s))

Fixed submission:
a,b,c,d=map(int,input().split())
s=[]
for i in range(0,101):
  if a<=i<=b and c<=i<=d:
    s.append(i)
print(0 if len(s)==0 else max(s)-min(s))
Buggy python submission (verdict: Runtime Error):
def dfs(now_node,parent_node,dist):
  depth[now_node]=dist
  for next_node,w in graph[now_node]:
    if next_node==parent_node:
      continue
    dfs(next_node,now_node,dist+w)

n=int(input())
graph=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b,c=map(int,input().split())
  graph[a].append((b,c))
  graph[b].append((a,c))
  
q,k=map(int,input().split())
depth=[-1]*(n+1)
dfs(k,0,0)
for _ in range(q):
  x,y=map(int,input().split())
  print(depth[x]+depth[y])

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

def dfs(now_node,parent_node,dist):
  depth[now_node]=dist
  for next_node,w in graph[now_node]:
    if next_node==parent_node:
      continue
    dfs(next_node,now_node,dist+w)

n=int(input())
graph=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b,c=map(int,input().split())
  graph[a].append((b,c))
  graph[b].append((a,c))
  
q,k=map(int,input().split())
depth=[-1]*(n+1)
dfs(k,0,0)
for _ in range(q):
  x,y=map(int,input().split())
  print(depth[x]+depth[y])
Buggy python submission (verdict: Runtime Error):
s=input()
for i in reversed(range(0,len(s)-1,2)):
  if s[:len(s)//2]==s[len(s)//2:]:
    print(len(s))
    break
  else:
    s=[:len(s)-2]

Fixed submission:
s=input()
ans=0
for i in range(1,len(s)//2):
  if s[0:i]==s[i:2*i]:
    ans=i
print(ans*2)
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for _ in range(n)]
print(a[0] if len(a)==1 else max(a)-min(a))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
print(max(a)-min(a))

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for _ in range(n)]
print(max(a)-min(a))

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
print(max(a)-min(a))
Buggy python submission (verdict: Runtime Error):
a,b=map(int,inpuy().split())
print((a+b)%24)

Fixed submission:
a,b=map(int,input().split())
print((a+b)%24)

Buggy python submission (verdict: Runtime Error):
print((int(input())+int(input()))%24)

Fixed submission:
a,b=map(int,input().split())
print((a+b)%24)
Buggy python submission (verdict: Runtime Error):
x=int(input())
n=0
while 2x>n*n+n:
  n+=1
print(n)

Fixed submission:
x=int(input())
n=0
while 2*x>n*n+n:
  n+=1
print(n)
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
p=1
for i in range(1,n+1):
  p*=i
print(p%(10**9+7))

Fixed submission:
n=int(input())
p=1
for i in range(1,n+1):
  p*=i
  p=p%(10**9+7)
print(p)
Buggy python submission (verdict: Runtime Error):
a,b,c,d=map(iint,input().split())
print(a*b if a*b>c*d else c*d)

Fixed submission:
a,b,c,d=map(int,input().split())
print(a*b if a*b>c*d else c*d)
Buggy python submission (verdict: Time Limit Exceeded):
n,x,*a=map(int,open(0).read().split())
ans=0
if a[0]>x:
  ans=a[0]-x
  a[0]=x
for i in range(n-1):
  while a[i+1]+a[i]>x:
    a[i+1]-=1
    ans+=1
print(ans)

Fixed submission:
n,x,*a=map(int,open(0).read().split())
ans=0
if a[0]>x:
  ans=a[0]-x
  a[0]=x
for i in range(n-1):
  if a[i+1]+a[i]>x:
    d=a[i+1]+a[i]-x
    a[i+1]-=d
    ans+=d
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print("Yes" if a+b+c=2*max(a,b,c) else "No")

Fixed submission:
a,b,c=map(int,input().split())
print("Yes" if a+b+c==2*max(a,b,c) else "No")
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
t,a=[0]*n,[0]*n
for i in range(n):
  t[i],a[i]=map(int,input().split())
tt,aa=t[0],a[0]
for i in range(1,n):
  j=0
  while 1:
    j+=1
    if t[i]*j>=tt and a[i]*j>=aa:
      tt=t[i]*j
      aa=a[i]*j
      break
print(aa+tt)

Fixed submission:
n=int(input())
t,a=[0]*n,[0]*n
for i in range(n):
  t[i],a[i]=map(int,input().split())
tt,aa=t[0],a[0]
for i in range(1,n):
  tt=t[i]*max((tt+t[i]-1)//t[i],(aa+a[i]-1)//a[i])
  aa=a[i]*max((tt+t[i]-1)//t[i],(aa+a[i]-1)//a[i])
print(aa+tt)
Buggy python submission (verdict: Runtime Error):
https://atcoder.jp/contests/abc150/submitinput()
s = input()
ans = 0
while 1:
    pos = s.find('ABC')
    if pos == -1:
        break
    ans += 1
    s = s[pos + 3:]
print(ans)

Fixed submission:
input()
s = input()
ans = 0
while 1:
    pos = s.find('ABC')
    if pos == -1:
        break
    ans += 1
    s = s[pos + 3:]
print(ans)
Buggy python submission (verdict: Runtime Error):
n,a,b=map(int,input()split())

if n*a>b:
  return b

else:
  return n*a

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

if li[0]*li[1]>li[2]:
  print(li[2])
else:
  print(li[0]*li[1])
Buggy python submission (verdict: Runtime Error):
t=list(input())

for i in range(1,4):
  s=t
  if s[0]==s[i]:
    z=s[0]
    s.pop(i)
    s.pop(0)
    if z!=s[0] and s[0]==s[1]:
      print("Yes")
      
print("No")

Fixed submission:
s=list(input())

s.sort()
if s[0]==s[1] and s[2]==s[3] and s[1]!=s[2]:
  print("Yes")
else:
  print("No")

Buggy python submission (verdict: Runtime Error):
t=list(input())

for i in range(1,4):
  s=t
  if s[0]==s[i]:
    z=s[0]
    s.pop(i)
    s.pop(0)
    if z=!s[0] and s[0]==s[1]:
      print("Yes")
      
print("No")
    

Fixed submission:
s=list(input())

s.sort()
if s[0]==s[1] and s[2]==s[3] and s[1]!=s[2]:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
from math import trunc
import sys
import copy
from collections import deque
import collections
import itertools
stdin = sys.stdin
import math

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

s = [0 for _ in range(2000)]
s[0] = 1
s[3] = 1
s[4] = 1
s[5] = 1

if n < 6:
    print(s[n])
    exit(0)

for i in range(6, 2001):
    s[i] = s[i-3] + s[i-1]
    s[i] %= mod
    if i==n:
        break

print(s[n])


Fixed submission:
from math import trunc
import sys
import copy
from collections import deque
import collections
import itertools
stdin = sys.stdin
import math

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()

s = [0 for _ in range(2001)]
s[0] = 1
s[3] = 1
s[4] = 1
s[5] = 1

if n < 6:
    print(s[n])
    exit(0)

for i in range(6, 2001):
    s[i] = s[i-3] + s[i-1]
    s[i] %= mod
    if i==n:
        break

print(s[n])
Buggy python submission (verdict: Runtime Error):
import sys
import copy
from collections import deque
import collections
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m, k = na()

a = na()
b = na()

num_books = 0
sum_time = 0
for i in a:
    if sum_time+i > k:
        break
    num_books += 1
    sum_time += i
# print(num_books)


res = num_books
ia = num_books - 1
ib = 0
if num_books==0 and b[ib] > k:
    print(0)
    exit(0)
while ib < len(b):
    if sum_time < k:
        sum_time += b[ib]
        ib += 1
        num_books += 1
    else:
        sum_time -= a[ia]
        ia -= 1
        num_books -= 1
    if sum_time <= k:
        res = max(res, num_books)

print(res)


Fixed submission:
import sys
import copy
from collections import deque
import collections
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m, k = na()

a = na()
b = na()

num_books = 0
sum_time = 0
for i in a:
    if sum_time+i > k:
        break
    num_books += 1
    sum_time += i
# print(num_books)


res = num_books
ia = num_books - 1
ib = 0
if num_books==0 and b[ib] > k:
    print(0)
    exit(0)
while ib < len(b):
    if sum_time < k:
        sum_time += b[ib]
        ib += 1
        num_books += 1
    else:
        if ia == -1:
            break
        sum_time -= a[ia]
        ia -= 1
        num_books -= 1
    if sum_time <= k:
        res = max(res, num_books)

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
import copy
from collections import deque
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
maxr = 10**18
_ = ni()
a = na()
res = 1
for item in a:
    res *= item

print(res if res <= maxr else -1)



Fixed submission:
import sys
import copy
from collections import deque
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
maxr = 10**18
_ = ni()
a = na()
res = 1

if 0 in a:
    print(0)
    exit(0)

for item in a:
    res *= item
    if res > maxr:
        print(-1)
        exit(0)

print(res)
Buggy python submission (verdict: Runtime Error):
a,b,c=sorted(map(int,input()))
print(10*c+a+b)


Fixed submission:
a,b,c=sorted(map(int,input().split()))
print(10*c+a+b)
Buggy python submission (verdict: Runtime Error):
import numpy as np
ans=0
n=int(input())
li=list(map(int,input().split()))
for i in range(1,n):
    L=li
    k=np.cumsum(L[:i])
    ans+=k*li[i]
print(ans%(10**9+7))

Fixed submission:
import itertools
ans=0
n=int(input())
li=list(map(int,input().split()))
L=list(itertools.accumulate(li))
for i in range(1,n):
    ans+=L[i-1]*li[i]
print(ans%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
ans=0
n=int(input())
li=list(map(int,input().split()))
for i in range(1,n):
    k=sum(li[:i])
    ans+=k*li[i]
print(ans%(10**9+7))

Fixed submission:
import itertools
ans=0
n=int(input())
li=list(map(int,input().split()))
L=list(itertools.accumulate(li))
for i in range(1,n):
    ans+=L[i-1]*li[i]
print(ans%(10**9+7))

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

ans=0
n=int(input())
li=list(map(int,input().split()))
for i in range(1,n):
    k=list(itertools.accumulate(li[:i]))[-1]
    ans+=k*li[i]
print(ans%(10**9+7))

Fixed submission:
import itertools
ans=0
n=int(input())
li=list(map(int,input().split()))
L=list(itertools.accumulate(li))
for i in range(1,n):
    ans+=L[i-1]*li[i]
print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
s=input()
c=0
mc=0
for i in s:
  if i='R':
    c+=1
    mc=c
  else:
    c=0
print(max(c,mc))

Fixed submission:
s=input()
c=0
mc=0
for i in s:
  if i=='R':
    c+=1
    mc=c
  else:
    c=0
print(max(c,mc))
Buggy python submission (verdict: Runtime Error):
l,r,d=map(int,input.split())
ans=0
for i in range(l,r+1):
  if i%d==0:
    ans+=1
print(ans)

Fixed submission:
l,r,d=map(int,input().split())
ans=0
for i in range(l,r+1):
  if i%d==0:
    ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a=int(input())
b=int(input())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))


Fixed submission:
import math
a,b=map(int,input().split())
def lcm(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm(a, b))
Buggy python submission (verdict: Runtime Error):
x=int(input())
y=int(input())

if(x%2==0 or y%2==0):
    print("Even")
else:
    print("Odd")

Fixed submission:
x,y=map(int,input().split())

if(x%2==0 or y%2==0):
    print("Even")
else:
    print("Odd")

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

if(x%2==0 or y%2==0):
    print("Even")
else:
    print("Odd")

Fixed submission:
x,y=map(int,input().split())

if(x%2==0 or y%2==0):
    print("Even")
else:
    print("Odd")
Buggy python submission (verdict: Time Limit Exceeded):
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m=map(int,input().split())
uf=UnionFind(n)
for _ in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)

dic=uf.all_group_members()
max_size=0
for ss in dic.values():
  max_size=max(max_size,len(ss))

print(max_size)

Fixed submission:
n,m=map(int,input().split())
par = [-1]*(n+1)
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x]) #経路圧縮
        return par[x]
def same(x,y):
    return find(x) == find(y)
def unite(x,y):
    x = find(x)
    y = find(y)
    if x == y:
      return 0
    else:
      if par[x] > par[y]:
        x,y = y,x
      par[x] += par[y]
      par[y] = x
def size(x):
    return -par[find(x)]

max_size=0
for _ in range(m):
  a,b=map(int,input().split())
  unite(a,b)
  
print(-min(par))
Buggy python submission (verdict: Runtime Error):
import math
n,k=map(int,input().split())
log=list(map(int,input().split()))
a=0
b=max(log)
c=(a+b)//2
while True:
  div=0
  for i in range(n):
    div+=math.ceil(log[i]/c)-1
  if div<=k:
    b=c
    c=(a+b)//2
  else:
    a=c
    c=(a+b)//2
    
  if c==a or c==b:
    break
print(b)

Fixed submission:
import math
n,k=map(int,input().split())
log=list(map(int,input().split()))
a=0
b=max(log)
if b==1:
  print(1)
  exit()
c=(a+b)//2
while True:
  div=0
  for i in range(n):
    div+=math.ceil(log[i]/c)-1
  if div<=k:
    b=c
    c=(a+b)//2
  else:
    a=c
    c=(a+b)//2
    
  if c==a or c==b:
    break
print(b)

Buggy python submission (verdict: Runtime Error):
import math
n,k=map(int,input().split())
a=list(map(int,input().split()))
a=1
b=max(a)
c=(a+b)//2
while True:
  div=0
  for i in range(n):
    div+=math.ceil(a[i]/c)-1
  if div<=k:
    b=c
    c=(a+b)//2
  else:
    a=c
    c=(a+b)//2
    
  if c==a or c==b:
    break
print(b)

Fixed submission:
import math
n,k=map(int,input().split())
log=list(map(int,input().split()))
a=0
b=max(log)
if b==1:
  print(1)
  exit()
c=(a+b)//2
while True:
  div=0
  for i in range(n):
    div+=math.ceil(log[i]/c)-1
  if div<=k:
    b=c
    c=(a+b)//2
  else:
    a=c
    c=(a+b)//2
    
  if c==a or c==b:
    break
print(b)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
cc=1
for j in range(k):
  cc*=A[j]

for i in range(k,n):
  pp=A[i]*cc//A[i-k]
  if pp>cc:print('Yes')
  else:print('No')
  
  cc=pp

Fixed submission:
x=int(input())

if x<600:
  print(8)
elif x<800:
  print(7)
elif x<1000:print(6)
elif x<1200:print(5)
elif x<1400:print(4)
elif x<1600:print(3)
elif x<1800:print(2)
else:print(1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k=map(int,input().split())
A=list(map(int,input().split()))
cc=1
for j in range(k):
  cc*=A[j]

for i in range(k,n):
  pp=A[i]*cc//A[i-k]
  if pp>cc:print('Yes')
  else:print('No')
  
  cc=pp

Fixed submission:
from collections import deque

n,k=map(int,input().split())
A=deque(list(map(int,input().split())))


for i in range(k,n):
  if A[i]>A[i-k]:print('Yes')
  else:print('No')

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

n,k=map(int,input().split())
A=list(map(int,input().split()))
rn=np.array([1]*n)
for i in range(n):
  rn[i:min(n,i+k)]=rn[i:min(n,i+k)]*A[i]
  
for i in range(k,n):
  if rn[i-1]<rn[i]:print('Yes')
  else:print('No')

Fixed submission:
from collections import deque

n,k=map(int,input().split())
A=deque(list(map(int,input().split())))


for i in range(k,n):
  if A[i]>A[i-k]:print('Yes')
  else:print('No')
Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(input())
def str2int(z):
  flag=1
  a=0
  for i in reversed(x):
    if i=='1':a+=flag
    flag*=2
  return a
 
popc=x.count('1')
x=str2int(x)
fl_1=x%(popc-1)
fl_0=x%(popc+1)
cc=[]
for i in range(n):
  if ((x>>i)&1):
    mod=(fl_1-(2**i)%(popc-1))%(popc-1)
  else:mod=(fl_0+(2**i)%(popc+1))%(popc+1)
  #print('mod : %s'%mod)
  cnt=1
  while mod!=0:
    pp=bin(mod).count("1")
    mod%=pp
    cnt+=1
  cc.append(cnt)
  
for c in reversed(cc):
  print(c)

Fixed submission:
n=int(input())
x=list(input())
def str2int(z):
  flag=1
  a=0
  for i in reversed(x):
    if i=='1':a+=flag
    flag*=2
  return a
 
popc=x.count('1')
z=str2int(x)
if popc-1!=0:
  fl_1=z%(popc-1)
fl_0=z%(popc+1)

for i in range(n):
  if x[i]=='1':
    if popc-1==0:
      print(0)
      continue
    mod=(fl_1-pow(2,n-1-i,popc-1))%(popc-1)
  else:mod=(fl_0+pow(2,n-1-i,popc+1))%(popc+1)
  #print('mod : %s'%mod)
  cnt=1
  while mod!=0:
    pp=bin(mod).count("1")
    mod%=pp
    cnt+=1
  print(cnt)

Buggy python submission (verdict: Runtime Error):
n=int(input())
x=list(input())
def str2int(z):
  flag=1
  a=0
  for i in reversed(x):
    if i=='1':a+=flag
    flag*=2
  return a

popc=x.count('1')
x=str2int(x)

cc=[]
for i in range(n):
  if ((x>>i)&1):
    mod=(x-2**i)%(popc-1)
  else:mod=(x+2**i)%(popc+1)
  #print('mod : %s'%mod)
  cnt=1
  while mod!=0:
    pp=bin(mod).count("1")
    mod%=pp
    cnt+=1
  cc.append(cnt)
  
for c in reversed(cc):
  print(c)


Fixed submission:
n=int(input())
x=list(input())
def str2int(z):
  flag=1
  a=0
  for i in reversed(x):
    if i=='1':a+=flag
    flag*=2
  return a
 
popc=x.count('1')
z=str2int(x)
if popc-1!=0:
  fl_1=z%(popc-1)
fl_0=z%(popc+1)

for i in range(n):
  if x[i]=='1':
    if popc-1==0:
      print(0)
      continue
    mod=(fl_1-pow(2,n-1-i,popc-1))%(popc-1)
  else:mod=(fl_0+pow(2,n-1-i,popc+1))%(popc+1)
  #print('mod : %s'%mod)
  cnt=1
  while mod!=0:
    pp=bin(mod).count("1")
    mod%=pp
    cnt+=1
  print(cnt)
Buggy python submission (verdict: Runtime Error):
from itertools import product
h,w,k=map(int,input().split())
idxs=[]
cols=[0]*w
clis=[]
al=0
k_score=0
def nir(x):
  if x=='#':return 1
  else:return 0
  
for _ in range(h):
  tmp=list(map(nir, list(input())))
  clis.append(tmp)
  idxs.append(sum(tmp))
  al+=sum(tmp)
  for q in range(w):
    cols[q]+=tmp[q]
uu=product((0,1),repeat=h+w)
for bits in uu:
  idd=[]
  coll=[]
  for i in range(h):
    if bits[i]==1:idd.append(i)
  
  for i in range(w):
    if bits[i+h]==1:coll.append(i)
  
  s=al
  if not coll:
    for x in idd:s-=idxs[x]
  elif not idd:
    for y in coll:s-=cols[y]
  else:
    for x in idd:s-=idxs[x]
    for y in coll:s-=cols[y]
    for x in idd:
      for y in coll:
        s+=clis[x][y]
        
  if s==k:k_score+=1
    
print(k_score)

Fixed submission:
n=int(input())
s=n%1000
if s==0:s=1000
print(1000-s)
Buggy python submission (verdict: Runtime Error):
from itertools import product
h,w,k=map(int,input().split())
idxs=[]
cols=[0]*w
al=0

def nir(x):
  if x=='#':return 1
  else:return 0
  
for _ in range(h):
  tmp=list(map(nir, list(input())))
  idxs.append(sum(tmp))
  al+=sum(tmp)
  for q in range(w):
    cols[q]+=tmp[q]
    
for bits in product((0,1),repeat=h+w):
  

Fixed submission:
from itertools import product
h,w,k=map(int,input().split())
idxs=[]
cols=[0]*w
clis=[]
al=0
k_score=0
def nir(x):
  if x=='#':return 1
  else:return 0
  
for _ in range(h):
  tmp=list(map(nir, list(input())))
  clis.append(tmp)
  idxs.append(sum(tmp))
  al+=sum(tmp)
  for q in range(w):
    cols[q]+=tmp[q]
uu=product((0,1),repeat=h+w)
for bits in uu:
  idd=[]
  coll=[]
  for i in range(h):
    if bits[i]==1:idd.append(i)
  
  for i in range(w):
    if bits[i+h]==1:coll.append(i)
  
  s=al
  if not coll:
    for x in idd:s-=idxs[x]
  elif not idd:
    for y in coll:s-=cols[y]
  else:
    for x in idd:s-=idxs[x]
    for y in coll:s-=cols[y]
    for x in idd:
      for y in coll:
        s+=clis[x][y]
        
  if s==k:k_score+=1
    
print(k_score)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
print(sum(a)-min(a))

Fixed submission:
from collections import deque
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)

between=deque([a[0]])
score=0
for i in range(1,n):
  score+=between.popleft()
  between.extend([a[i],a[i]])
  
print(score)