Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02640 (python)

Fixed submission:
X, Y = map(int, input().split()) 
ans = 'No'
for a in range(X + 1):
	b=X-a
	if 2 * a + 4 * b == Y:
		ans = 'Yes' 
print(ans)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split()) ans = 'No'
for a in range(X + 1):
	b=X-a
	if 2 * a + 4 * b == Y:
		ans = 'Yes' 
print(ans)

Buggy submission (verdict: Runtime Error):
X, Y = map(int, input().split()) ans = 'No'
for a in range(X + 1):
  b=X-a
  if 2 * a + 4 * b == Y:
	ans = 'Yes' 
print(ans)
Problem p02658 (python)

Fixed submission:
def main():
  N = int(input())
  A = list(map(int,input().split()))
  if 0 in A:
    return 0
  ans = 1
  for i in A:
    ans*=i
    if ans > 10**18:
      return -1
  return ans
print(main())

Buggy submission (verdict: Runtime Error):
def main():
	N = int(input())
    A = list(map(int,input().split()))
    if 0 in A:
      return 0
    ans = 1
    for i in A:
      if ans > 10**18:
        return -1
      ans*=i
    return ans
print(main())

Buggy submission (verdict: Runtime Error):
N - int(input())
A = list(map(int,input().split()))
ans = 1
for i in A:
  ans*=i
if ans > 10**18:
  ans = -1
print(ans)
Problem p02755 (python)

Fixed submission:
import math

A, B = map(int,input().split()) 

def func():
    b = B*10
    for i in range(b,2*b):
        if math.floor(i*0.08) == A and math.floor(i*0.1) == B:
            return i
    return -1
    
print(func())

Buggy submission (verdict: Runtime Error):
A, B = map(int,input().split()) 

def func():
    b = B*10
    for i in range(b,2*b):
        if math.floor(i*0.08) == A and math.floor(i*0.1) == B:
            return i
    return -1
    
print(func())
Problem p02756 (python)

Fixed submission:
S = input()
Q = int(input())
P = [input().split() for i in range(Q)]

count = 0
left = ""
right = ""
for query in P:
    if query[0]=="1":
        count+=1
    else:
        if query[1]=="1":
            if count%2==0:
                left+=query[2]
            else:
                right+=query[2]
        else:
            if count%2==0:
                right+=query[2]
            else:
                left+=query[2]
                
S = left[::-1]+S+right
if count%2==1:
    S=S[::-1]
    
print(S)

Buggy submission (verdict: Runtime Error):
S = input()
Q = int(input())
P = [input().split() for i in range(Q)]

count = 0

for query in P:
    if query[0]=="1":
        count+=1
    else:
        if query[1]=="1":
            if count%2==0:
                S=query[2]+S
            else:
                S=S+query[2]
        else:
            if count%2==0:
                S=S+query[2]
            else:
                S=query[2]+S
if count%2==1:
    S=S[::-1]
    
print(S)
Problem p03069 (python)

Fixed submission:
N=int(input())
S=list(map(int,input().replace('#','1').replace('.','0')))
 
cum=[0]
for i in range(N):
  cum.append(cum[-1]+S[i])
  
ans=10**20
for i in range(N+1):
  b = cum[i]
  w = N-i-(cum[-1]-cum[i])
  ans = min(ans,b+w)
  
print(ans)

Buggy submission (verdict: Runtime Error):
def main():
  N = map(int,input.split())
  S = input()
  black = S.count('#')
  white = S.count('.')

  if black == N or white == N:
    print(0)
    return 
 	
  B = [0]*(N+1)
  W = [0]*(N+1)
  for i in range(N):
    if S[i] == '#':
      B[i+1] = 1
    elif W[i] == '.':
      W[i+1] = 1
  
  for i in range(1,N+1):
    B[i]+=B[i-1]
    W[i]+=W[i-1]
  ans = float('inf')
  for i in range(1,N+1):
    ans = min(ans, B[i]+white-W[i])
  
main()
Problem p03244 (python)

Fixed submission:
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
D1 = defaultdict(int)
D2 = defaultdict(int)

for i in range(0,N,2):
  D1[A[i]]+=1
for i in range(1,N,2):
  D2[A[i]]+=1
  
D1_sorted = sorted(D1.items(), key=lambda x:x[1], reverse = True) + [(-1,0)]
D2_sorted = sorted(D2.items(), key=lambda x:x[1], reverse = True) + [(-1,0)]
i, j = 0, 0
while i < len(D1_sorted) -1 and j < len(D2_sorted) -1:
  if D1_sorted[i][0] != D2_sorted[j][0]:
    break
  elif D1_sorted[i][1] > D2_sorted[j][1]:
    j+=1
  elif D1_sorted[i][1] < D2_sorted[j][1]:
    i+=1
  else:
    if D1_sorted[i+1][1] > D2_sorted[j+1][1]:
      i+=1
    else:
      j+=1

print(N-D1_sorted[i][1]-D2_sorted[j][1])

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
D1 = defaultdict(int)
D2 = defaultdict(int)

for i in range(0,N,2):
  D1[A[i]]+=1
for i in range(1,N,2):
  D2[A[i]]+=1
  
D1_sorted = sorted(D1.items(), key=lambda x:x[1], reverse = True) + [-1,0]
D2_sorted = sorted(D2.items(), key=lambda x:x[1], reverse = True) + [-1,0]

i, j = 0, 0
while i < len(D1_sorted) -1 and j < len(D2_sorted) -1:
  if D1_sorted[i][0] != D2_sorted[j][0]:
    break
  elif D1_sorted[i][1] > D2_sorted[j][1]:
    j+=1
  elif D1_sorted[i][1] < D2_sorted[j][1]:
    i+=1
  else:
    if D1_sorted[i+1][1] > D2_sorted[j+1][1]:
      i+=1
    else:
      j+=1

print(N-D1_sorted[i][1]-D2_sorted[j][1])
Problem p03282 (python)

Fixed submission:
N = input()
K = int(input())
ans = '1'
for i in range(K):
  if i >= len(N):
    break
  if N[i] != '1':
    ans = N[i]
    break
print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
K = int(input())
ans = '1'
for i in range(K):
  if i >= len(N):
    break
  if N[i] != '1':
    ans = N[i]
  	break
print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
K = int(input())
if len(N) == 1:
  print(N[0])
elif K = 1:
  print(N[0])
elif N[0] == '1':
  print(N[1])
else:
  print(N[0])

Buggy submission (verdict: Runtime Error):
N = input()
K = int(input())
if N[0] == '1':
  print(N[1])
else:
  print(N[0])
Problem p03311 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
  A[i]-= i+1
A.sort()
total = sum(A)
mean1 = total//N
mean2 = total//N + 1
med1 = A[N//2]
#med2 = A[N//2+1]
ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0 
for a in A:
  ans1+=abs(a-mean1)
  ans2+=abs(a-mean2)
  ans3+=abs(a-med1)
  #ans4+=abs(a-med2)
print(min([ans1,ans2,ans3]))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
for i in range(N):
  A[i]-= i+1
A.sort()
total = sum(A)
mean1 = total//N
mean2 = total//N + 1
med1 = A[N//2]
med2 = A[N//2+1]
ans1 = 0
ans2 = 0
ans3 = 0
ans4 = 0 
for a in A:
  ans1+=abs(a-mean1)
  ans2+=abs(a-mean2)
  ans3+=abs(a-med1)
  ans4+=abs(a-med2)
print(min([ans1,ans2,ans3,ans4]))
Problem p03436 (python)

Fixed submission:
from collections import deque
H, W = map(int,input().split())
G = [input() for _ in range(H)]
white = 0
dist = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = set()
for line in G:
  white+=line.count('.')

D = deque()
D.append((0,0,1))
rout = -1
while D:
  h, w, c = D.popleft()
  if h == H-1 and w == W-1:
    rout = c
    break
  if (h, w) in visited or G[h][w] == '#':
    continue
  else:
    visited.add((h, w))
  for dh, dw in dist:
    if (0<=h+dh<H) and (0<=w+dw<W):
      if (h+dh, w+dw) not in visited and G[h+dh][w+dw] != '#':
        D.append((h+dh, w+dw, c+1))
        
if rout == -1:
  print(rout)
else:
  print(white-rout)

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int,input().split())
G = [input() for _ in range(H)]
white = 0
dist = [(-1, 0), (1, 0), (0, -1), (0, 1)]
visited = set()
for line in G:
  white+=line.count('.')

D = deque()
D.append((0,0,1))
rout = -1
while D:
  h, w, c = D.popleft()
  if h == H-1 and w == W-1:
    rout = c
    break
  if (h, w) in visited or G[h][w] == '#':
    continue
  else:
    visited.add((h, w))
  for dh, dw in dist:
    if (0<=h+dh<H) and (0<=w+dw<W):
      if (h+dh, w+dw) not in visited and G[h+dh][w+dh] != '#':
        D.append((h+dh, w+dw, c+1))
        
if rout == -1:
  print(rout)
else:
  print(white-rout)
Problem p03457 (python)

Fixed submission:
N = int(input())
T = [0]
X = [0]
Y = [0]
for i in range(N):
    t,x,y = map(int,input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

flag = True
for i in range(N):
    time = T[i+1]-T[i]
    dist = abs(X[i+1]-X[i])+abs(Y[i+1]-Y[i])
    if time < dist or (dist%2!=time%2):
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
T = []
X = []
Y = []
T[0] = X[0] = Y[0] = 0
for i in range(N):
    t,x,y = map(int,input().split())
    T.append(t)
    X.append(x)
    Y.append(y)

flag = True
for i in range(N):
    time = T[i+1]-T[i]
    dist = abs(X[i+1]-X[i])+abs(Y[i+1]-Y[i])
    if time < dist or (dist%2!=time%2):
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')
Problem p03476 (python)

Fixed submission:
B = [False]*100005
C = [0]*100005
for i in range(2,100001):
    if not B[i]:
      	for j in range(i+i,100001,i):
          	B[j]=True
for i in range(3,100001,2):
    if not B[i] and not B[(i+1)//2]:
        C[i]+=1
for i in range(3,100001):
    C[i]=C[i]+C[i-1]
    
N = int(input())
for _ in range(N):
    a, b = map(int,input().split())
    print(C[b]-C[a-1])

Buggy submission (verdict: Runtime Error):
B = [False]*10005
C = [0]*10005
for i in range(2,10001):
    if not B[i]:
      	for j in range(i+i,10001,i):
          	B[j]=True
for i in range(3,10001,2):
    if not B[i] and not B[(i+1)//2]:
        C[i]+=1
for i in range(3,10001):
    C[i]=C[i]+C[i-1]
    
N = int(input())
for _ in range(N):
    a, b = map(int,input().split())
    print(C[b]-C[a])

Buggy submission (verdict: Runtime Error):
B = [False]*10005
C = [0]*10005
for i in range(2,10001):
    if not B[i]:
      	for j in range(i+i,10001,i):
          	B[j]=True
for i in range(3,10001,2):
    if not B[i] and not B[(i+1)//2]:
        C[i]+=1
for i in range(3,10001):
    C[i]=C[i]+C[i-1]
    
N = int(input())
for _ in range(N):
    a, b = map(int,input().split())
    print(C[b]-C[a-1])

Buggy submission (verdict: Runtime Error):
B = [False]*10010
C = [0]*10010
for i in range(2,10005):
    if not B[i]:
        j = i+i
        while j < 10005:
            B[j]= True
            j+=i
for i in range(3,10005,2):
    if not B[i] and not B[(i+1)//2]:
        C[i]+=1
for i in range(3,10005):
    C[i]=C[i]+C[i-1]
    
N = int(input())
for _ in range(N):
    a, b = map(int,input().split())
    print(C[b]-C[a-1])

Buggy submission (verdict: Runtime Error):
B = [False]*10010
C = [0]*10010
for i in range(2,10005):
    if not B[i]:
        j = i+i
        while j < 10005:
            B[j]= True
            j+=i
for i in range(3,10005,2):
    if not B[i] and not int(B[(i+1)/2]):
        C[i]+=1
for i in range(3,10005):
    C[i]=C[i]+C[i-1]
    
N = int(input())
for _ in range(N):
    a, b = map(int,input().split())
    print(C[b]-C[a-1])

Buggy submission (verdict: Runtime Error):
B = [False]*10010
C = [0]*10010
for i in range(2,10005):
    if not B[i]:
        j = i+i
        while j < 10005:
            B[j]= True
            j+=i
for i in range(3,10005,2):
    if not B[i] and not B[(i+1)//2]:
        C[i]+=1
for i in range(3,10005):
    C[i]=C[i]+C[i-1]
    
N = int(input())
for _ in range(N):
    a, b = map(int,input().split())
    print(C[b]-C[a-1])

Buggy submission (verdict: Runtime Error):
B = [False]*10010
C = [0]*10010
for i in range(2,10005):
    if !B[i]:
        j = i+i
        while j < 10005:
            B[j]= True
            j+=i
for i in range(3,10005,2):
    if !B[i] and !B[(i+1)//2]:
        C[i]+=1
for i in range(3,10005):
    C[i]=C[i]+C[i-1]
    
N = int(input())
for _ in range(N):
    a, b = map(int,input().split())
    print(c[b]-c[a-1])
Problem p03614 (python)

Fixed submission:
N = int(input())
P = list(map(int,input().split()))
L = [False]*N
for i in range(N):
  if P[i] == i+1:
    L[i] = True
ans = 0
i = 0
while i < N:
  if L[i]:
    if i<N-1 and L[i+1]:
      ans+=1
      i+=1
    else:
      ans+=1
  i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int,input().split()))
L = [False]*N
for i in range(N):
  if P[i] == i+1:
    L = True
ans = 0
for i in range(N):
  if L[i]:
    if i<N-1 and L[i+1]:
      ans+1
      i+=1
    else:
      ans+=1
print(ans)
Problem p03645 (python)

Fixed submission:
def main():
  N, M = map(int,input().split())
  fromOne = set()
  toM = set()
  for i in range(M):
    a, b = map(int,input().split())
    if a == 1:
      fromOne.add(b)
    elif b == N:
      toM.add(a)
  return 'POSSIBLE' if fromOne & toM else 'IMPOSSIBLE'
print(main())

Buggy submission (verdict: Runtime Error):
def main():
  N, M = map(int,input().split())
  fromOne = set()
  toM = set()
  for i in range(N):
    a, b = map(int,input().split())
    if a == 1:
      fromOne.add(b)
    elif b == M:
      toM.add(a)
  return 'POSSIBLE' if fromOne & toM else 'IMPOSSIBLE'
print(main())
Problem p03659 (python)

Fixed submission:
N = int(input())
A = [0]+list(map(int,input().split()))
for i in range(1,N+1):
  A[i] = A[i]+A[i-1]
ans = float('inf')
for i in range(1,N):
  ans = min(ans, abs(A[N]-2*A[i]))
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [0]+list(map(int,input().split()))
for i in range(1,N+1):
  A[i] = A[i]+A[i-1]
ans = float('inf')
for i in range(1,N):
  ans = min(ans, ans(A[N]-2*A[i]))
print(ans)
Problem p03779 (python)

Fixed submission:
X = int(input())
t = 1
for t in range(1,X+1):
  total = t*(t+1)/2
  if total>=X:
    break
print(t)

Buggy submission (verdict: Runtime Error):
X = int(input())
for t in range(1,X):
  total = t*(t+1)/2
  if total>=X:
    break
print(t)

Buggy submission (verdict: Runtime Error):
X = int(input())
for t in range(1:X):
  total = t*(t+1)/2
  if total>=X:
    print(t)
   	break
Problem p02555 (python)

Fixed submission:
s = int(input())

if s >= 3:
    red = [None]*s
    red[0]= 0
    red[1]= 0
    red[2]= 0
    for x in range(3,s):
        red[x] = (red[x-1] + red[x-3] + 1) % 1000000007
    print((red[s-3]+1) % 1000000007)

else:
    print(0)

Buggy submission (verdict: Runtime Error):
s = int(input())
red = [None]*s
red[0]= 0
red[1]= 0
red[2]= 0

for x in range(3,s):
    red[x] = (red[x-1] + red[x-3] + 1) % 1000000007
    
print((red[s-3]+1) % 1000000007)
Problem p02608 (python)

Fixed submission:
import math
con = 0;
n = int(input())
a = [0]*n

m = int(math.sqrt(n) // 1);
for x in range(1,m+1):
    for y in range(1,m+1):
        for z in range(1,m+1):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x;
            if s <= n:
                a[s-1] += 1;


for v in range(n):
    print(a[v]);

Buggy submission (verdict: Runtime Error):
import math
con = 0;
n = int(input())
nn = n**4
a = [0]*nn

m = int(math.sqrt(n) // 1);
for x in range(1,m+1):
    for y in range(1,m+1):
        for z in range(1,m+1):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x;
            a[s-1] += 1;


for v in range(n):
    print(a[v]);

Buggy submission (verdict: Runtime Error):
import math
con = 0;
n = int(input())
nn = n**2
a = [0]*nn

m = int(math.sqrt(n) // 1);
for x in range(1,m+1):
    for y in range(1,m+1):
        for z in range(1,m+1):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x;
            a[s-1] += 1;


for v in range(n):
    print(a[v]);
Problem p02630 (python)

Fixed submission:

n = int(input())
a = list(map(int,input().split()));
q = int(input())
aa = 0;
for i in range(n):
    aa += a[i];

b = [input().split() for l in range(q)]

bu = [0]*(100000);

for i in range(n):
    bu[a[i]-1] += 1;
    
for x in range(q):
    c = int(b[x][0])
    d = int(b[x][1])
    aa += (d-c)*(bu[c-1]);
    bu[d-1] += bu[c-1];
    bu[c-1] = 0;
    print(aa);

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()));
q = int(input())
aa = 0;
for i in range(n):
    aa += a[i];

b = [input().split() for l in range(q)]

bu = [0]*(100000);

for i in range(100000):
    bu[i] = a.count(i);
    
for x in range(q):
    c = int(b[x][0])
    d = int(b[x][1])
    aa += (d-c)*(bu[c]);
    bu[d] += bu[c];
    bu[c] = 0;
    print(aa);

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()));
q = int(input())
aa = 0;
for i in range(n):
    aa += a[i];

b = [input().split() for l in range(q)]

bu = [None]*(100000);

for i in range(100000):
    bu[i] = a.count(i);
    
for x in range(q):
    c = int(b[x][0])
    d = int(b[x][1])
    aa += (d-c)*(bu[c]);
    bu[d] += bu[c];
    bu[c] = 0;
    print(aa);

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()));
q = int(input())
aa = 0;
for i in range(n):
    aa += a[i];

b = [input().split() for l in range(q)]

bu = [None]*(100000);

for i in range(10000):
    bu[i] = a.count(i);
    
for x in range(q):
    c = int(b[x][0])
    d = int(b[x][1])
    aa += (d-c)*(bu[c]);
    bu[d] += bu[c];
    bu[c] = 0;
    print(aa);

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()));
q = int(input())
aa = 0;
for i in range(n):
    aa += a[i];

b = [input().split() for l in range(q)]

bu = [None]*(100000);

for i in range(10000):
    bu[i] = a.count(i);
    
for x in range(q):
    c = int(b[x][0])
    d = int(b[x][1])
    aa += (d-c)*(bu[c]);
    bu[d] += bu[c];
    bu[c] = 0;
    
print(aa);
Problem p02641 (python)

Fixed submission:
x, n = map(int, input().split());
if n == 0:
    print(x);
elif n == 1:
    b = int(input());
    if b == x:
        print(x-1);
    else:
        print(x);
else:
    a = list(map(int,input().split()));
    
    for i in range(n):
        if a.count(x-i) == 0:
            ooo = 1;
            break;
        if a.count(x+i) == 0:
            ooo = 2;
            break;
        
            
    if ooo == 1:
        print(x-i);
    else:
        print(x+i);

Buggy submission (verdict: Runtime Error):
x, n = map(int, input().split());
if n == 0:
    print(x);
if n == 1:
    b = int(input());
    if b == x:
        print(x-1);
    else:
        print(x);
else:
    a = list(map(int,input().split()));
    
    for i in range(n):
        if a.count(x-i) == 0:
            ooo = 1;
            break;
        if a.count(x+i) == 0:
            ooo = 2;
            break;
        
            
    if ooo == 1:
        print(x-i);
    else:
        print(x+i);

Buggy submission (verdict: Runtime Error):
x, n = map(int, input().split());
if n == 0:
    print(x);
else:
    a = list(map(int,input().split()));
    
    for i in range(n):
        if a.count(x-i) == 0:
            ooo = 1;
            break;
        if a.count(x+i) == 0:
            ooo = 2;
            break;
            
    if ooo == 1:
        print(x-i);
    else:
        print(x+i);
Problem p02719 (python)

Fixed submission:
n,k = map(int,input().split());
i = 0;
if n == k:
    print(0);
elif n < k:
    print(min(n,k-n));
else:
    v = (n - k)%k;
    if v*2 >= k:
        print(k-v);
    else:
        print(v);

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split());

if n == k:
    print(0);
elif n > k:
    n = n - k;
    a = [n];
    i = 0;
    while True:
        n = n-k;
        if n < 0:
            break;
        a.append(n);
        i += 1;
else:
    n = k - n;
    a = [n];
    i = 0;
    while True:
        n = n-k;
        if n < 0:
            break;
        a.append(n);
        i += 1;

if a[i] <= (-1)*n:
    print(a[i]);
else:
    print((-1)*n);
Problem p02718 (python)

Fixed submission:
import numpy as np

n, m = map(int, input().split())
a = np.array(list(map(int, input().split())) )

a = a / sum(a)
a = (a >= 1/(4*m))
if sum(a)>=m:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
import numpy as np

n, m = map(int, input().split())
a = np.array(list(map(int, input().split())) )

a = a / sum(a)
a = (a >= 1/(4*m))
if sum(a)>=m:
    print('Yes')
else:
    print('No')
Problem p02719 (python)

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

def solve():
    global n, k
    n = n - (k * (n // k))
    pre = n
    while True:
        n = min(n, abs(n-k))
        if n == pre:
            break
        pre = n
    return n

print(solve())

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

n = n % k
print(min(abs(n - k)), n)
Problem p02761 (python)

Fixed submission:
def main():
    n, m = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(m)]
    
    ans = [-1]* n
    for s, c in sc:
        s -= 1 
        if ans[s] == -1or ans[s] == c:
            ans[s] = c
        else:
            print(-1)
            return
        
    if ans[0] == -1 and n >1:
        ans[0] = 1
    elif ans[0] == 0:
        if n == 1:
            print(0)
        else:
            print(-1)
        return
    
    print(''.join(list(map(str, ans))).replace('-1', '0'))
    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, m = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(m)]
    
    sc = sorted(sc)
    ans = ''
    pre_s =  -1
    pre_c = sc[0][1]
    for s, c  in sc:
        if pre_s == s and pre_c == c:
            continue
        if (s == 1 and c == 0) or (pre_s == s and pre_c != c):
            print('-1')
            return
        if pre_s == -1 and s != 1:
            ans += str(1)
            pre_s += 2
        i = s - pre_s - 1
        ans += str(0) * i
        ans += str(c)
        pre_s = s
        pre_c = c
    ans += str(0) * (n - pre_s)
        
    print(int(ans))
    
if __name__ == '__main__':
    main()
Problem p02802 (python)

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

ac = [0]*(n+1)
wa = [0]*(n+1)

for _ in range(m):
    a, b = input().split()
    a = int(a)
    if b == 'AC':
        ac[a] = 1
    else: 
        if ac[a] == 0:
            wa[a] = wa[a] + 1

for i in range(n+1):
    wa[i] = wa[i] * ac[i]

print(sum(ac), sum(wa))

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

ac = [0]*(n+1)
wa = [0]*(n+1)

for _ in range(m):
    a, b = input().split()
    a = int(a)
    if b == 'AC':
        ac[a] = 1
    else: 
        if ac[a] == 0:
            wa[a] = wa[a] + 1

for i in range(n+1):
    wa[a] = wa[a] * ac[a]

print(sum(ac), sum(wa))