Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s=input()
k=int(input())
for i in range(len(s)):
    if s[i]!='1':
        a=s[i]
        break
print(1 if s[0:k]=='1'*k else a)

Fixed submission:
s=input()
k=int(input())
a=1
for i in range(len(s)):
    if s[i]!='1':
        a=s[i]
        break
print(1 if k<=len(s) and s[0:k]=='1'*k else a)
Buggy python submission (verdict: Runtime Error):
a=input()
b=0
for i in range(4)
    if a[i]=="+":
        b+=1
    else:
        b-=1
print(b)


Fixed submission:
a=input()
b=0
for i in range(4):
    if a[i]=="+":
        b+=1
    else:
        b-=1
print(b)

Buggy python submission (verdict: Runtime Error):
a=input()
b=0
for i while(4)
    if a[i]=="+":
        b+=1
    else:
        b-=1
print(b)

Fixed submission:
a=input()
b=0
for i in range(4):
    if a[i]=="+":
        b+=1
    else:
        b-=1
print(b)
Buggy python submission (verdict: Runtime Error):
n=input()
a=len(n)
p=0
m=0
while True:
    m+=int(n[p])
    p+=1
    if m==a:
        break
if int(n)%m==0:
    print('Yes')
else:
    print('No')

Fixed submission:
n=input()
p=0
m=0
while True:
    m+=int(n[p])
    p+=1
    if p==len(n):
        break
if int(n)%m==0:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
a=int(input())
if a<=1000:
    print("ABD"+(a-999))
else:
    print("ABC"+a)

Fixed submission:
a=int(input())
if a>=1000:
    print("ABD")
else:
    print("ABC")
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input.split()))
print(max(a[0]+a[1],a[0]-a[1],a[0]*a[1]))


Fixed submission:
a=list(map(int,input().split()))
print(max(a[0]+a[1],a[0]-a[1],a[0]*a[1]))

Buggy python submission (verdict: Runtime Error):
a=int(input())
print(max(a[0]+a[1],a[0]-a[1],a[0]*a[1]))

Fixed submission:
a=list(map(int,input().split()))
print(max(a[0]+a[1],a[0]-a[1],a[0]*a[1]))
Buggy python submission (verdict: Runtime Error):
a=list(mao(int,input().split()))
if a[1]>=a[0]:
    print(a[0])
else:
    print(a[0]-1)

Fixed submission:
a=list(map(int,input().split()))
if a[1]>=a[0]:
    print(a[0])
else:
    print(a[0]-1)
Buggy python submission (verdict: Runtime Error):
a=input()b=700
if a[0]=="o":
    b+=100
if a[1]=="o":
    b+=100
if a[2]=="o":
    b+=100
print(b)

Fixed submission:
a=input()
b=700
if a[0]=="o":
    b+=100
if a[1]=="o":
    b+=100
if a[2]=="o":
    b+=100
print(b)
Buggy python submission (verdict: Runtime Error):
n=input()
l=len(n)
a,b=0,0
while True:
    b+=n[a]
    a+=1
    if a==l:
      break
print(b)

Fixed submission:
a=input()
b=0
for i in range(len(a)):
    b+=int(a[i])
print(max((len(a)-1)*9+int(a[0])-1,b))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
b,c=0,0
for i in range(n):
    if i%2==0:
        b+=a[-i]
    else:
        c+=a[-i]
print(b-a)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
b,c=0,0
for i in range(n):
    if i%2==1:
        b+=a[-i-1]
    else:
        c+=a[-i-1]
print(c-b)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
s=input()
for i in range(a):
    if s[i]=='-':
        print('No')
        sys.exit()
if  s[a]!='-':
    print('No')
    sys.exit()
for i in range(b):
    if s[i+a+1]=='-':
        print('No')
        sys.exit()
print('Yes')

Fixed submission:
import sys
a,b=map(int,input().split())
s=input()
for i in range(a):
    if s[i]=='-':
        print('No')
        sys.exit()
if  s[a]!='-':
    print('No')
    sys.exit()
for i in range(b):
    if s[i+a+1]=='-':
        print('No')
        sys.exit()
print('Yes')
Buggy python submission (verdict: Runtime Error):
import math
a,b=map(int,input())
print(math.ceil((a+b)/2))

Fixed submission:
print((sum(map(int,input().split()))+1)//2)

Buggy python submission (verdict: Runtime Error):
import math
print(math.ceil((a+b)/2))

Fixed submission:
print((sum(map(int,input().split()))+1)//2)

Buggy python submission (verdict: Runtime Error):
import math
print(math.ceil(a+b)/2)

Fixed submission:
print((sum(map(int,input().split()))+1)//2)
Buggy python submission (verdict: Runtime Error):
ab=input(),0 
if a[0]=='1':
    b+=1
if a[1]=='1':
    b+=1
if a[2]=='1':
    b+=1
print(b)

Fixed submission:
a,b=input(),0 
if a[0]=='1':
    b+=1
if a[1]=='1':
    b+=1
if a[2]=='1':
    b+=1
print(b)
Buggy python submission (verdict: Runtime Error):
s=input()
for i in range(len(s)-1):
    if s[i]=="A" anf s[i+1]=="C":
        print('Yes')
        exit()
print('No')

Fixed submission:
s=input()
for i in range(len(s)-1):
    if s[i]=="A" and s[i+1]=="C":
        print('Yes')
        exit()
print('No')
Buggy python submission (verdict: Runtime Error):
print(sum(list(input())))

Fixed submission:
a=input()
b=0
for i in range(6):
    if int(a[i])==1:
        b+=1
print(b)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=10**100
for i in range(n)
  t=sum(list(map(int,input().split())))
  ans=min(ans,t)
print(ans)

Fixed submission:
n=int(input())
ans=10**100
for i in range(n):
  t=sum(list(map(int,input().split())))
  ans=min(ans,t)
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=10*100
for i in range(n)
  ans=min(ans,sum(list(map(int,input().split()))))
print(ans)


Fixed submission:
n=int(input())
ans=10**100
for i in range(n):
  t=sum(list(map(int,input().split())))
  ans=min(ans,t)
print(ans)

Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=10*100
for i in range(n)
  ans=min(ans,sum(map(int,input().split())))
print(ans)

Fixed submission:
n=int(input())
ans=10**100
for i in range(n):
  t=sum(list(map(int,input().split())))
  ans=min(ans,t)
print(ans)

Buggy python submission (verdict: Runtime Error):
print(min([int(input()) for _ in [0]*int(input())],key=lambda x:x[0]+x[1]))

Fixed submission:
n=int(input())
ans=10**100
for i in range(n):
  t=sum(list(map(int,input().split())))
  ans=min(ans,t)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
inf=10**5
n,m,R=map(int,input().split())
r=list(map(int,input().split()))
d=[[inf]*n for i in range(n)]
for i in range(n):
    d[i][i]=0
ans=inf
for i in range(m):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in itertools.permutations(r):
    preans=0
    for j in range(R-1):
        preans+=d[i[j]-1][i[j+1]-1]
    ans=min(ans,preans)
print(ans)

Fixed submission:
import itertools
inf=10**8
n,m,R=map(int,input().split())
r=list(map(int,input().split()))
d=[[inf]*n for i in range(n)]
for i in range(n):
    d[i][i]=0
ans=inf
for i in range(m):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])
for i in itertools.permutations(r):
    preans=0
    for j in range(R-1):
        preans+=d[i[j]-1][i[j+1]-1]
    ans=min(ans,preans)
print(ans)
Buggy python submission (verdict: Runtime Error):
if input()[0]==input()[2]:
    print('Yes')
else:
    print('No')

Fixed submission:
a=input()
if a[0]==a[2]:
    print('Yes')
else:
    print('No')
Buggy python submission (verdict: Runtime Error):
import sys
def gcd(m,n):
    x=max(m,n)
    y=min(m,n)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z
def lcm(m,n):
    return int(m*n/gcd(m,n))
n=int(input())
a=[]
if n==1:
    print(int(input()))
    sys.exit()
for i in range(n):
    a.append(int(input()))
b=lcm(a[0],a[1])
for i in range(n-2):
    b=lcm(b,a[i+2])
print(b)

Fixed submission:
import fractions
from functools import reduce
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
n=int(input())
print(lcm_list([int(input()) for i in range(n)]))
Buggy python submission (verdict: Runtime Error):
n=int(input())
edge=[[] for i in range(n)]
for i in range(n-1):
    x,y,z=map(int,input().split())
    edge[x-1].append([y-1,z])
    edge[y-1].append([x-1,z])
q,k=map(int,input().split())
dist=[-1]*n
def dfs(node,d):
    dist[node]=d
    for i in edge[node]:
        if dist[i[0]]==-1:
            dfs(i[0],d+i[1])
dfs(k-1,0)
for i in range(q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
n=int(input())
edge=[[] for i in range(n)]
for i in range(n-1):
    x,y,z=map(int,input().split())
    edge[x-1].append([y-1,z])
    edge[y-1].append([x-1,z])
q,k=map(int,input().split())
dist=[-1]*n
def dfs(node,d):
    dist[node]=d
    for i in edge[node]:
        if dist[i[0]]==-1:
            dfs(i[0],d+i[1])
dfs(k-1,0)
for i in range(q):
    x,y=map(int,input().split())
    print(dist[x-1]+dist[y-1])
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().sprit()))
print((a[0]-1)*(a[1]-1))

Fixed submission:
a=list(map(int,input().split()))
print((a[0]-1)*(a[1]-1))
Buggy python submission (verdict: Runtime Error):
a,b,c=input().split()
a,b,c=str.apper(a),str.apper(b),str.apper(c)
print(a[0]+b[0]+c[0])

Fixed submission:
a,b,c=input().split()
a,b,c=str.upper(a),str.upper(b),str.upper(c)
print(a[0]+b[0]+c[0])
Buggy python submission (verdict: Runtime Error):
n=input()
a=0
for i in range(1,10**5):
  a+=i
  if a>=n:
    break
print(i)

Fixed submission:
n=int(input())
a=0
for i in range(1,10**5):
  a+=i
  if a>=n:
    break
print(i)

Buggy python submission (verdict: Runtime Error):
n=input()
a=[]
for i in range(1,10**5):
  a+=i
  if a>=n:
    break
print(i)

Fixed submission:
n=int(input())
a=0
for i in range(1,10**5):
  a+=i
  if a>=n:
    break
print(i)

Buggy python submission (verdict: Runtime Error):
n=input()
a=[]
for i in range(1,10**5):
  a+=i
  if a>=n:
    break
print(i_

Fixed submission:
n=int(input())
a=0
for i in range(1,10**5):
  a+=i
  if a>=n:
    break
print(i)
Buggy python submission (verdict: Time Limit Exceeded):
a=1
for i in range(1,int(input())+1):
  a*=i
print(a%(10**9+7))

Fixed submission:
import math
print(math.factorial(int(input()))%(10**9+7))
Buggy python submission (verdict: Runtime Error):
s=list(input())
for i in range(5):
    print(s[i],end='')
print(' ',end='')
for i in range(7):
    print(i+6,end='')
print(' ',end='')
for i in range(5):
    print(s[i+13],end'')

Fixed submission:
s=list(input())
for i in range(5):
    print(s[i],end='')
print(' ',end='')
for i in range(7):
    print(s[i+6],end='')
print(' ',end='')
for i in range(5):
    print(s[i+14],end='')
Buggy python submission (verdict: Runtime Error):
a,b,c=input().split()
if b=='+':
    print(a+c)
else:
    print(a-c)

Fixed submission:
a,b,c=input().split()
if b=='+':
    print(int(a)+int(c))
else:
    print(int(a)-int(c))
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=int(input())
s=sum(a)
for i in range(m):
    p,x=map(int,input().split())
    print(s-a[p]+x)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=int(input())
s=sum(a)
for i in range(m):
    p,x=map(int,input().split())
    print(s-a[p-1]+x)
Buggy python submission (verdict: Runtime Error):
s=input()
while s:
    if s[-5:]=='erase':
        for i in range(5):
            s.pop()
    elif s[-5:]=='dream':
        for i in range(5):
            s.pop()
    elif s[-6:]=='eraser':
        for i in range(6):
            s.pop()
    elif s[-7:]=='dreamer':
        for i in range(7):
            s.pop()
    else:
        print('NO')
print('YES')

Fixed submission:
s=input()[::-1]
i=0
while i<len(s):
    if i+5<=len(s) and s[i:i+5]=='esare':
        i+=5
    elif i+5<=len(s) and s[i:i+5]=='maerd':
        i+=5
    elif i+6<=len(s) and s[i:i+6]=='resare':
        i+=6
    elif i+7<=len(s) and s[i:i+7]=='remaerd':
        i+=7
    elif i<len(s):
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
while s:
    if s[-5:]=='erase':
        s=s[:-5]
    elif s[-5:]=='dream':
        s=s[:-5]
    elif s[-6:]=='eraser':
        s=s[:-6]
    elif s[-7:]=='dreamer':
        s=s[:-7]
    else:
        print('NO')
print('YES')

Fixed submission:
s=input()[::-1]
i=0
while i<len(s):
    if i+5<=len(s) and s[i:i+5]=='esare':
        i+=5
    elif i+5<=len(s) and s[i:i+5]=='maerd':
        i+=5
    elif i+6<=len(s) and s[i:i+6]=='resare':
        i+=6
    elif i+7<=len(s) and s[i:i+7]=='remaerd':
        i+=7
    elif i<len(s):
        print('NO')
        exit()
print('YES')

Buggy python submission (verdict: Runtime Error):
def test(t):
    if len(t)==len(s):
        print('YES')
        exit()
    if s[len(t):len(t)+5]=='dream':
        test(t+'dream')
    if s[len(t):len(t)+7]=='dreamer':
        test(t+'dreamer')
    if s[len(t):len(t)+5]=='erase':
        test(t+'erase')
    if s[len(t):len(t)+6]=='eraser':
        test(t+'eraser')
s=input()
test('')
print('NO')

Fixed submission:
s=input()[::-1]
i=0
while i<len(s):
    if i+5<=len(s) and s[i:i+5]=='esare':
        i+=5
    elif i+5<=len(s) and s[i:i+5]=='maerd':
        i+=5
    elif i+6<=len(s) and s[i:i+6]=='resare':
        i+=6
    elif i+7<=len(s) and s[i:i+7]=='remaerd':
        i+=7
    elif i<len(s):
        print('NO')
        exit()
print('YES')
Buggy python submission (verdict: Runtime Error):
a=list(map(int,input().split()))
print(a[1]+(a[0]-1)*(a[1]-1)

Fixed submission:
a,b=map(int,input().split())
print(b*(b-1)**(a-1))
Buggy python submission (verdict: Runtime Error):
s=input()
a,b,n=0,0,len(s)
for i in range(n):
    if s[i]==T:
        if a==0:
            b+=1
        else:
            a-=1
    else:
        a+=1
print(n-2*a)

Fixed submission:
s=input()
a,b,n=0,0,len(s)
for i in range(n):
    if s[i]=='T':
        if a==0:
            b+=1
        else:
            a-=1
            b-=1
    else:
        a+=1
        b+=1
print(b)
Buggy python submission (verdict: Runtime Error):
a=int(input())
ans=1;
ok=True
for i in range(a):
    c=int(input())
    ans*=c
    if ans>10**18:
        ans=-1
        break
print(ans)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
INF=10**18
ans=1
a.sort()
for i in a:
    ans*=i
    if ans>INF:
        ans=-1
        break
print(ans)

Buggy python submission (verdict: Runtime Error):
a=input()
ans=1;
ok=True
for i in range(a):
    c=input()
    ans*=c
    if ans>1000000000000000000:
        ok=False
        break
if ok:
    print(ans)
else :
    print(-1)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
INF=10**18
ans=1
a.sort()
for i in a:
    ans*=i
    if ans>INF:
        ans=-1
        break
print(ans)

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

ans = 1
for i in range(N):
    ans *= A[i]

if ans <= 1e18: print(ans)
else: print(-1)

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

ans = 1
flg = True

if 0 in A: print(0)
else:
    for i in range(N):
        ans *= A[i]
        if ans > 1e18:
            flg = False
            break

    if flg: print(ans)
    else:print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

syurui = []
for i in range(N):
    S = input()
    if S in syurui: continue
    else: syurui.append(S)

print(len(syurui))


Fixed submission:

N = int(input())

L = []
for i in range(N):
    L.append(input())

LL = sorted(L)

ans = 1
for i in range(N-1):
    if LL[i+1] != LL[i]: ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())

p = [int(e) for e in input().split()]

windows = []

for i in range(0,N-K+1):
    windows.append(sum(p[i:i+K]))

print((K + max(windows))/2)

Fixed submission:
from copy import copy
N, K = map(int, input().split())

p = [int(e) for e in input().split()]

now_sum = sum(p[0:K])
now_max = copy(now_sum)


for i in range(K,N):
    now_sum = now_sum - p[i - K] + p[i]
    if now_sum > now_max:
        now_max = copy(now_sum)

print((K + now_max)/2)
Buggy python submission (verdict: Runtime Error):
N = int(input())
D = list(map(int,input().split()))

if D[0] != 0: print(0)
elif D[0] == 0 and D[1] == 0: print(0)
elif N == 1; print(0)
else:
  flg = True
  D.sort()
  A = []
  a = 1
  c = 0
  for i in range(1,N):
    if D[i] == D[i-1] + 1:
      A.append(a)
      a = 1
      c += 1
    elif D[i] == D[i-1]:
      a += 1
    else:
      flg = False
      break
  
  A.append(a)
  c += 1

  ans = 1

  if flg:
    for i in range(1,c):
      ans *= (A[i-1]%998244353)**A[i]
    print(ans%998244353)

  else:
    print(0)
  




Fixed submission:
from copy import copy
N = int(input())
D = list(map(int,input().split()))

H = copy(D)
H.sort()



if D[0] != 0: print(0)
elif H[0] == 0 and H[1] == 0: print(0)
else:
  D.sort()
  flg = True
  A = []
  a = 1
  c = 0
  for i in range(1,N):
    if D[i] == D[i-1] + 1:
      A.append(a)
      a = 1
      c += 1
    elif D[i] == D[i-1]:
      a += 1
    else:
      flg = False
      break
  
  A.append(a)
  c += 1

  ans = 1

  if flg:
    for i in range(1,c):
      ans *= (A[i-1]%998244353)**A[i]
    print(ans%998244353)

  else:
    print(0)
Buggy python submission (verdict: Runtime Error):
A, B = map(int, input().split())
 
if A>=B:
  C = A%B
else:
  C = B%A
 
count = 0
 
now = 0
 
a = 2
 
while C >= a*a:
  if C%a == 0:
    if a != now:
      count += 1
      now = a
    C /= a
  else:
    a +=1
 
if C > 2 & C != now:
  count +=1
 
count += 1
 
print(count)

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


A_yaku = []

now = 0

a = 2

while A >= a*a:
  if A%a == 0:
    if a != now:
      A_yaku.append(a)
      now = a
    A /= a
  else:
    a +=1

if A != now and A != 1:
  A_yaku.append(A)

B_yaku = []

now = 0

a = 2

while B >= a*a:
  if B%a == 0:
    if a != now:
      B_yaku.append(a)
      now = a
    B /= a
  else:
    a +=1

if B != now and B != 1:
  B_yaku.append(B)

count = 0

if(len(A_yaku) >= len(B_yaku)):
  for i in range(0,len(B_yaku)):
    if(B_yaku[i] in A_yaku):
      count += 1
else:
  for i in range(0,len(A_yaku)):
    if(A_yaku[i] in B_yaku):
      count += 1

count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long A,B;

    cin >> A >> B;

    long long C;

    if(A>=B){
        C = A%B;
    }else{
        C = B%A;
    }

    long long count = 0LL;

    long long now = 0; 
    long long a = 2;

    vector<int> yakusu;
    while(C >= a*a){
        if(C%a == 0){
            if (a != now){
                count++;
                yakusu.push_back(a);
                now = a;
            }
            C /= a;
        }else{
            a++;
        }
    }

    if(std::count(yakusu.begin(), yakusu.end(), C) == 0) count++;

    count++;

    cout << count << endl;
    return 0;


}

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


A_yaku = []

now = 0

a = 2

while A >= a*a:
  if A%a == 0:
    if a != now:
      A_yaku.append(a)
      now = a
    A /= a
  else:
    a +=1

if A != now and A != 1:
  A_yaku.append(A)

B_yaku = []

now = 0

a = 2

while B >= a*a:
  if B%a == 0:
    if a != now:
      B_yaku.append(a)
      now = a
    B /= a
  else:
    a +=1

if B != now and B != 1:
  B_yaku.append(B)

count = 0

if(len(A_yaku) >= len(B_yaku)):
  for i in range(0,len(B_yaku)):
    if(B_yaku[i] in A_yaku):
      count += 1
else:
  for i in range(0,len(A_yaku)):
    if(A_yaku[i] in B_yaku):
      count += 1

count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
	K = int(input())
print('ACL' * K)

Fixed submission:
K = int(input())
print('ACL' * K)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
hlist = [0] * H
wlist = [0] * W
hw = [[0 for _ in range(W)] for _ in range(H)]
for i in range(M):
    h, w = map(int, input().split())
    hlist[h - 1] += 1
    wlist[w - 1] += 1
    hw[h - 1][w - 1] = 1

hmax = max(hlist)
wmax = max(wlist)
hmaxlist = [i for i, v in enumerate(hlist) if v == hmax]
wmaxlist = [i for i, v in enumerate(wlist) if v == wmax]
cnt = -1
for i in hmaxlist:
    bf = False
    for j in wmaxlist:
        if hw[i][j] != 1:
            cnt = 0
            bf = True
            break
    if bf:
        break

print(hmax + wmax + cnt)

Fixed submission:
H, W, M = map(int, input().split())
hlist = [0] * H
wlist = [0] * W
hw = set()
for i in range(M):
    h, w = map(int, input().split())
    hlist[h - 1] += 1
    wlist[w - 1] += 1
    hw.add((h - 1, w - 1))

hmax = max(hlist)
wmax = max(wlist)
hmaxlist = [i for i, v in enumerate(hlist) if v == hmax]
wmaxlist = [i for i, v in enumerate(wlist) if v == wmax]
cnt = -1
for i in hmaxlist:
    bf = False
    for j in wmaxlist:
        if not (i, j) in hw:
            cnt = 0
            bf = True
            break
    if bf:
        break

print(hmax + wmax + cnt)

Buggy python submission (verdict: Time Limit Exceeded):
H, W, M = map(int, input().split())
hlist = [0] * H
wlist = [0] * W
hw = [[0 for _ in range(W)] for _ in range(H)]
for i in range(M):
    h, w = map(int, input().split())
    hlist[h - 1] += 1
    wlist[w - 1] += 1
    hw[h - 1][w - 1] = 1

hmax = max(hlist)
wmax = max(wlist)
hmaxlist = [i for i, v in enumerate(hlist) if v == hmax]
wmaxlist = [i for i, v in enumerate(wlist) if v == wmax]
cnt = -1
for i in hmaxlist:
    bf = False
    for j in wmaxlist:
        if hw[i][j] != 1:
            cnt = 0
            bf = True
            break
    if bf:
        break

print(hmax + wmax + cnt)

Fixed submission:
H, W, M = map(int, input().split())
hlist = [0] * H
wlist = [0] * W
hw = set()
for i in range(M):
    h, w = map(int, input().split())
    hlist[h - 1] += 1
    wlist[w - 1] += 1
    hw.add((h - 1, w - 1))

hmax = max(hlist)
wmax = max(wlist)
hmaxlist = [i for i, v in enumerate(hlist) if v == hmax]
wmaxlist = [i for i, v in enumerate(wlist) if v == wmax]
cnt = -1
for i in hmaxlist:
    bf = False
    for j in wmaxlist:
        if not (i, j) in hw:
            cnt = 0
            bf = True
            break
    if bf:
        break

print(hmax + wmax + cnt)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = a[-1]

while r - l > 0:
    mid = (r + l) // 2
    cnt = 0
    for i in a:
        cnt += i // mid
    if cnt <= K:
        r = mid
    else:
        l = mid + 1

print(r)

Fixed submission:
import math
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 0
r = a[-1] + 1

while r - l > 1:
    mid = (r + l) // 2
    cnt = 0
    for i in a:
        cnt += (i - 1) // mid
    if cnt <= K:
        r = mid
    else:
        l = mid
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = input()
ncnt = X.count('1')

for i in range(N):
    tmp = X
    tmpcnt = ncnt
    cnt = 0
    if tmp[i] == '0':
        tmp = tmp[:i] + '1' + tmp[i + 1:]
        tmpcnt += 1
    else:
        tmp = tmp[:i] + '0' + tmp[i + 1:]
        tmpcnt -= 1
    f = int(tmp, 2)
    while True:
        if f == 0:
            break

        m, d = divmod(f, tmpcnt)
        cnt += 1
        f = d
        tmpcnt = bin(f).count('1')
    print(cnt)


Fixed submission:
n = int(input())
s = input()
x = [0] * n

def pcnt(x):
    return bin(x).count('1')

def f(x):
    if x == 0: return 0
    return f(x % pcnt(x)) + 1

for i in range(n):
    x[i] = int(s[i])

pc = sum(x)
ans = [0] * n
for b in range(2):
    npc = pc
    if b == 0:
        npc += 1
    else:
        npc -= 1

    if npc <= 0: continue

    r0 = 0
    for i in range(n):
        r0 = (r0 * 2) % npc
        r0 += x[i]

    k = 1
    for i in range(n - 1, -1, -1):
        if x[i] == b:
            r = r0
            if b == 0:
                r = (r + k) % npc
            else:
                r = (r - k + npc) % npc
            ans[i] = f(r) + 1
        k = (k * 2) % npc

for i in ans:
    print(i)