qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    penalty = dict()
    penalty_cnt = 0
    ans = set()
    for _ in range(m):
        num, result = input().split()
        if result == 'AC':
            ans.add(num)
        elif num not in ans:
            if num not in penalty:
                penalty[num] = 1
            else:
                penalty[num] += 1
    ans = list(ans)
    for i in range(len(ans)):
        penalty_cnt += penalty[ans[i]]
    print(len(ans), penalty_cnt)

if __name__ == '__main__':
    main()

Fixed code:
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    penalty = dict()
    penalty_cnt = 0
    ans = set()
    for _ in range(m):
        num, result = input().split()
        if result == 'AC':
            ans.add(num)
            if num not in penalty:
                penalty[num] = 0
        elif num not in ans:
            if num not in penalty:
                penalty[num] = 1
            else:
                penalty[num] += 1
    ans = list(ans)
    for i in range(len(ans)):
        penalty_cnt += penalty[ans[i]]
    print(len(ans), penalty_cnt)

if __name__ == '__main__':
    main()
Buggy code:
import sys
input = sys.stdin.readline
from itertools import groupby
from operator import itemgetter
def print_ans(N, M, ar):
    """Test Case
    >>> print_ans(2, 5, [['1', 'WA'], ['1', 'AC'], ['2', 'WA'], ['2', 'AC'], ['2', 'WA']])
    2 2
    >>> print_ans(100000, 3, [['7777', 'AC'], ['7777', 'AC'], ['7777', 'AC']])
    1 0
    >>> print_ans(6, 0, [])
    0 0
    """
    correct = 0
    wrong = 0
    if M == 0:
        print(0, 0)
    else:
        for (k, g) in groupby(ar, key=itemgetter(0)):
            tmp_wrong = 0
            ac_flg = False
            for item in g:
                if item[1] == "AC":
                    correct += 1
                    ac_flg = True
                    break
                else:
                    tmp_wrong += 1
            if ac_flg == True:
                wrong += tmp_wrong
        #print("{} {}".format(correct, wrong))
        #print(str(correct) + " " + str(wrong))

if __name__ == '__main__':
    N, M = map(int, input().rstrip().split())
    if M == 0:
        ar = []
    else:
        ar = [list(map(str, input().rstrip().split())) for i in range(M)]
    print_ans(N, M, ar)

Fixed code:
import sys
input = sys.stdin.readline
from itertools import groupby
from operator import itemgetter
def print_ans(N, M, ar):
    """Test Case
    >>> print_ans(2, 5, [['1', 'WA'], ['2', 'WA'], ['2', 'AC'], ['2', 'WA'], ['1', 'AC']])
    2 2
    >>> print_ans(100000, 3, [['7777', 'AC'], ['7777', 'AC'], ['7777', 'AC']])
    1 0
    >>> print_ans(6, 0, [])
    0 0
    """
    correct = 0
    wrong = 0
    ar = sorted(ar, key=itemgetter(0))
    if M == 0:
        print(0, 0)
    else:
        for (k, g) in groupby(ar, key=itemgetter(0)):
            tmp_wrong = 0
            ac_flg = False
            for item in g:
                if item[1] == "AC":
                    correct += 1
                    ac_flg = True
                    break
                else:
                    tmp_wrong += 1
            if ac_flg == True:
                wrong += tmp_wrong
        print("{} {}".format(correct, wrong))
if __name__ == '__main__':
    N, M = map(int, input().rstrip().split())
    if M == 0:
        ar = []
    else:
        ar = [list(map(str, input().rstrip().split())) for i in range(M)]
    print_ans(N, M, ar)
Buggy code:
    import sys
    input = sys.stdin.readline
    n, m = map(int, input().split())
    a = list(input().split() for _ in range(m))
    flag = [0]*2*n
    if m == 0:
        print("{} {}".format(0, 0))
        exit()
    miss = 0
    correct = 0
    for i in range(m):
        if flag[int(a[i][0])] == 0:
            if a[i][1] == "WA":
                miss += 1
            elif a[i][1] == "AC":
                correct += 1
                flag[int(a[i][0])] = 1
    print("{} {}".format(correct, miss))
resolve()

Fixed code:
def resolve():
    import sys
    input = sys.stdin.readline
    n, m = map(int, input().split())
    if m == 0:
        print("{} {}".format(0, 0))
        exit()

    a = list(input().split() for _ in range(m))
    flag = [[0] * n for i in range(2)]
    miss = 0
    correct = 0
    for i in range(m):
        if flag[0][int(a[i][0]) - 1] == 0:
            if a[i][1] == "WA":
                flag[1][int(a[i][0]) - 1] += 1
            elif a[i][1] == "AC":
                correct += 1
                miss += flag[1][int(a[i][0]) - 1]
                flag[0][int(a[i][0]) - 1] = 1
    print("{} {}".format(correct, miss))
resolve()
Buggy code:
from functools import reduce
N, M = list(map(int, input().split()))
ps_list = [input().split() for _ in range(M)]

result = {}
for row in ps_list:
  if not row[0] in result:
    result[row[0]] = {
        "AC": 0,
        "WA": 0
    }
  if result[row[0]]["AC"] > 0:
    continue
  else:
    result[row[0]][row[1]] = result[row[0]][row[1]] + 1

print(result)
ac = 0
wa = 0
for k,v in result.items():
  ac = ac + v["AC"]
  if v["AC"] = 0:
    continue
  wa = wa + v["WA"]
print(ac, wa)

Fixed code:
from functools import reduce
N, M = list(map(int, input().split()))
ps_list = [input().split() for _ in range(M)]

result = {}
for row in ps_list:
  if not row[0] in result:
    result[row[0]] = {
        "AC": 0,
        "WA": 0
    }
  if result[row[0]]["AC"] > 0:
    continue
  else:
    result[row[0]][row[1]] = result[row[0]][row[1]] + 1

ac = 0
wa = 0
for k,v in result.items():
  ac = ac + v["AC"]
  if v["AC"] == 0:
    continue
  wa = wa + v["WA"]
print(ac, wa)
Buggy code:
N,M=map(int,input().split()) 
L=[list(input().split()) for i in range(M)]
W=[0]*N
A=[0]*N
a=0
w=0
for i in range(M):
  if L[i][1]=="AC":
    A[int(L[i][0])-1]=1
    
  elif L[i][1]=="WA" and A[int(L[i][0])-1]==0:
    W[int(L[i][0])-1]+=1
#for i in A:
  #a+=i
#for i in W:
  #w+=i
for i in range(n):
  if A[i]>0:
    a+=1
    w+=W[i]
print(a,w)



Fixed code:
N,M=map(int,input().split()) 
L=[list(input().split()) for i in range(M)]
W=[0]*N
A=[0]*N
a=0
w=0
for i in range(M):
  if L[i][1]=="AC":
    A[int(L[i][0])-1]=1
    
  elif L[i][1]=="WA" and A[int(L[i][0])-1]==0:
    W[int(L[i][0])-1]+=1
#for i in A:
  #a+=i
#for i in W:
  #w+=i
for i in range(N):
  if A[i]>0:
    a+=1
    w+=W[i]
print(a,w)
Buggy code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
problems = [False] * N
AC = [0] * N
WA = [0] * N
for _ in range(M):
    p, S = sr().split(); p = int(p) - 1
    if not problems[p] and S == 'WA':
        WA[p] += 1
    if not problems[p] and S == 'AC':
        problems[p] = True
        AC += 1

AC_total = sum(AC)
WA_total = sum(y for x, y in zip(AC, WA) if x)
print(AC_total, WA_total)


Fixed code:
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
problems = [False] * N
AC = [0] * N
WA = [0] * N
for _ in range(M):
    p, S = sr().split(); p = int(p) - 1
    if not problems[p] and S == 'WA':
        WA[p] += 1
    if not problems[p] and S == 'AC':
        problems[p] = True
        AC[p] += 1

AC_total = sum(AC)
WA_total = sum(y for x, y in zip(AC, WA) if x)
print(AC_total, WA_total)
Buggy code:
n,m=map(int,input().split())
l=list(input().split() for _ in range(m))
l=sorted(l,key=lambda x:x[0])
ll=[l[i][0] for i in range(m)]
import itertools
for (k,g) in itertools.groupby(l,key=lambda x:x[0]):
    lll.append(list(g))
a=0
w=0
for i in range(len(lll)):
    for j in lll[i]:
        if j[1]=="WA":
            w+=1
        elif j[1]=="AC":
            a+=1
            break
print(a,w)


Fixed code:
n,m=map(int,input().split())
l=list(input().split() for _ in range(m))
l=sorted(l,key=lambda x:x[0])
import itertools
lll=[]
for (k,g) in itertools.groupby(l,key=lambda x:x[0]):
    lll.append(list(g))
a=0
w=0
for i in range(len(lll)):
    for j in lll[i]:
        if j[1]=="AC":
            a+=1
            w+=lll[i].index(j)
            break
print(a,w)
Buggy code:
params = input().split(' ')
n = eval(params[1])

penaltyCount = [0] * eval(params[0])

penalties = 0
points = 0

for i in range(n):
    submission = input().split(' ')
    p = eval(submission[0])
    status = submission[1]
    
    if penaltyCount[p] == -1:
        continue

    if status == 'AC':
        penaltyCount += penaltyCount[p]
        penaltyCount[p] = -1
        points += 1
    else:
        penaltyCount[p] += 1


print(points, penalties)


Fixed code:
params = input().split(' ')
m = eval(params[0])
n = eval(params[1])

penaltyCount = []

for i in range(m):
    penaltyCount.append(0)

penalties = 0
points = 0

for i in range(n):
    submission = input().split(' ')
    p = eval(submission[0])-1
    status = submission[1]
    
    if penaltyCount[p] == -1:
        continue

    if status == 'AC':
        penalties += penaltyCount[p]
        penaltyCount[p] = -1
        points += 1
    else:
        penaltyCount[p] += 1


print(points, penalties)
Buggy code:
N,M=map(int,input().split())
p=[]
S=[]
for i in range(M):
  p0,S0=map(int,input().split())
  p+=[p0]
  S+=[S0]
awlist=[0 for i in range(N)]
walist=[0 for i in range(N)]
wacount=0
account=0
for i in range(M):
  if s[i]=='WA' and awlist[s[i]]==0:
    walist[s[i]]+=1
  elif s[i]=='AC' and awlist[s[i]]==0:
    account+=1
    awlist[s[i]]=1
    wacount+=walist[s[i]]
Answer=[account,wacount]
print(*Answer)

Fixed code:
N,M=map(int,input().split())
p=[]
s=[]
for i in range(M):
  p0,S0=map(str,input().split())
  p0=int(p0)-1
  p+=[p0]
  s+=[S0]
awlist=[0 for i in range(N)]
walist=[0 for i in range(N)]
wacount=0
account=0
for i in range(M):
  if s[i]=='WA' and awlist[p[i]]==0:
    walist[p[i]]+=1
  elif s[i]=='AC' and awlist[p[i]]==0:
    account+=1
    awlist[p[i]]=1
    wacount+=walist[p[i]]
Answer=[account,wacount]
print(*Answer)
Buggy code:




def main():
    n,m = map(int,input().split())
    d = dict()
    for i in range(m):
        a,b = input().split()
        a = int(a)
        if a not in d:
            d[a] = [0]
        if d[a][-1] != "AC":
            d[a].append(b)
    ac = 0
    pe = 0
    print(d)
    for i in d.values():
        #print(i)
        if i[-1] == "AC":
            ac += 1
        pe += i.count("WA")
    print(ac,pe)








if __name__ == '__main__':
    main()


Fixed code:




def main():
    n,m = map(int,input().split())
    d = dict()
    for i in range(m):
        a,b = input().split()
        a = int(a)
        if a not in d:
            d[a] = [0]
        if d[a][-1] != "AC":
            d[a].append(b)
    ac = 0
    pe = 0
    #print(d)
    for i in d.values():
        #print(i)
        if i[-1] == "AC":
            ac += 1
            pe += i.count("WA")
    print(ac,pe)








if __name__ == '__main__':
    main()
Buggy code:
n,m=map(int,input().split())
ac=[0]*(n+1)
wa=0
for i in range(m+1):
  p,c=input().split()
  if c=='AC' and ac[int(p)]==0:
    ac[int(p)]=1
  elif c=='WA' and ac[int(p)]==0:
    wa+=1
print(ac.count(1),wa)

Fixed code:
n,m=map(int,input().split())
ac=[0]*(n+1)
wa=0
for i in range(m):
  p,c=input().split()
  if c=='WA' and ac[int(p)]!=1:
    ac[int(p)]-=1
  elif c=='AC' and ac[int(p)]!=1:
    wa+=abs(ac[int(p)])
    ac[int(p)]=1
print(ac.count(1),wa)
Buggy code:
N,M = map(int,input().split())
a = 0
w = 0
lis = [[] for i in range(N)]
for i in range(M):
  p,s = map(int,input().split())
  p = int(p)
  lis[p - 1].append(s)
for j in range(N):
  if lis[j].count("AC") > 0:
    a += 1
    w += lis[j].index("AC")

    
print(a,w)



Fixed code:
N,M = map(int,input().split())
a = 0
w = 0
lis = [[] for _ in range(N)]
for i in range(M):
  p,s = map(str,input().split())
  p = int(p)
  lis[p - 1].append(s)
for j in range(N):
  if lis[j].count("AC") > 0:
    a += 1
    w += lis[j].index("AC")

    
print(a,w)
Buggy code:
n, m = map(int, input().split())

penalty = [0] * n
isAC = [False] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "WA":
        if not isAC[p]:
            penalty[p] += 1
    else:
        isAC[p] = True
for i in range(n)
    if not isAC[i]:
        penalty[i] = 0
print(sum(isAC), sum(penalty))

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

penalty = [0] * n
isAC = [False] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == "WA":
        if not isAC[p]:
            penalty[p] += 1
    else:
        isAC[p] = True
for i in range(n):
    if not isAC[i]:
        penalty[i] = 0
print(sum(isAC), sum(penalty))
Buggy code:
n,m = (int(x) for x in input().split())
memo = [0]*n
pena = [0]*n
ans2 = 0
for i in range(m):
    p,s = (str(x) for x in input().split())
    p = int(p)
    if s=="AC":
        memo[p-1] = 1
    elif s=="WA":
        if memo[p-1]==0:
            pena[p-1] += 1

for j in range(p):
    if memo[j]==1:
        ans2 += pena[j]

print("{} {}".format(sum(memo),ans2))

Fixed code:
n,m = (int(x) for x in input().split())
memo = [0]*n
pena = [0]*n
ans2 = 0
for i in range(m):
    p,s = (str(x) for x in input().split())
    p = int(p)
    if s=="AC":
        memo[p-1] = 1
    elif s=="WA":
        if memo[p-1]==0:
            pena[p-1] += 1

for j in range(n):
    if memo[j]==1:
        ans2 += pena[j]

print("{} {}".format(sum(memo),ans2))
Buggy code:
n,m=map(int,input().split())
d=dict()
c=0
p=0
for _ in range(m):
    a,b=map(str,input().split())
    if a not in d:
        if b=="WA":
            d[a]=["WA",1]
        else:
            c+=1
            d[a]=["AC",1]
    else:
        if b=="WA":
            if d[a][0]=="AC":
                continue
            else:
                d[a][1]+=1
        else:
            print(d[a][0])
            if d[a][0]=="AC":
                continue
            c+=1
            #print(d[a][1])
            d[a][0]="AC"
            p+=d[a][1]
#print(d)
print(c,p)


Fixed code:
n,m=map(int,input().split())
d=dict()
c=0
p=0
for _ in range(m):
    a,b=map(str,input().split())
    if a not in d:
        if b=="WA":
            d[a]=["WA",1]
        else:
            c+=1
            d[a]=["AC",1]
    else:
        if b=="WA":
            if d[a][0]=="AC":
                continue
            else:
                d[a][1]+=1
        else:
            #print(d[a][0])
            if d[a][0]=="AC":
                continue
            c+=1
            #print(d[a][1])
            d[a][0]="AC"
            p+=d[a][1]
#print(d)
print(c,p)
Buggy code:
n, m = map(int, input().split())
l = [[0,0] for i in range(n)]
for i in range(m):
    p, m = input().split()
    if l[int(p)-1][0] == 0:
        if m == 'WA':
            l[int(p)-1][1] = l[int(p)-1][1] + 1
        else:
            l[int(p)-1][0] = 1
ac = 0
wa = 0
for i in range(n):
    if l[i][0] == 1:
        ac = ac + 1
        wa = wa + l[i][0]
print(str(ac) + ' ' + str(wa))

Fixed code:
n, m = map(int, input().split())
l = [[0,0] for i in range(n)]
for i in range(m):
    p, m = input().split()
    if l[int(p)-1][0] == 0:
        if m == 'WA':
            l[int(p)-1][1] = l[int(p)-1][1] + 1
        else:
            l[int(p)-1][0] = 1
ac = 0
wa = 0
for i in range(n):
    if l[i][0] == 1:
        ac = ac + 1
        wa = wa + l[i][1]
print(str(ac) + ' ' + str(wa))
Buggy code:
    N,M = map(int, input().split())
	ac = [0]*N
	wa = [0]*N
	for i in range(M):
		p,s = input().split()
		if s == 'AC':
			if ac[int(p) - 1] != 0:
				continue
			else:	
				ac[int(p) - 1] = 1
		else:
			if ac[int(p) - 1] != 0:
				continue
			else:
				wa[int(p) - 1] += 1
	AC,WA = 0,0

	for i in range(N):
		AC += ac[i]
		if ac[i] >= 1:
			WA += wa[i]
	print(AC,WA)




Fixed code:
N,M = map(int, input().split())
ac = [0]*N
wa = [0]*N
for i in range(M):
	p,s = input().split()
	if s == 'AC':
		if ac[int(p) - 1] != 0:
			continue
		else:	
			ac[int(p) - 1] = 1
	else:
		if ac[int(p) - 1] != 0:
			continue
		else:
			wa[int(p) - 1] += 1
AC,WA = 0,0

for i in range(N):
  AC += ac[i]
  if ac[i] >= 1:
    WA += wa[i]
print(AC,WA)
Buggy code:
N, M = list(map(int, input().split()))
AC = [0] * N
WA = [0] * N
for i in range(M):
  p, S = input().split()
  p = int(p)
  if(S == "AC"):
    AC[p] = 1
  elif(AC[p] == 0):
    WA[p] += 1
print(sum(AC), sum(WA))

Fixed code:
N, M = list(map(int, input().split()))
AC = [0] * N
WA = [0] * N
for i in range(M):
  p, S = input().split()
  p = int(p)
  if(S == "AC"):
    AC[p-1] = 1
  elif(AC[p-1] == 0):
    WA[p-1] += 1
for i in range(N):
  if(AC[i] == 0):
    WA[i] = 0
print(sum(AC), sum(WA))
Buggy code:
#151c
n,w=map(int,input().split())
ac=0
wa=0
wa_cnt=0
ac_flg=[0]*n
for i in range(w):
	p=int(input())-1
	s=input()
	if ac_flg[p]==1:
		continue
	else:
		if s=='AC':
			ac_flg[p]=1
			ac+=1
			wa+=wa_cnt
		else:
			wa_cnt+=1
print(ac,wa)

Fixed code:
#151c
n,w=map(int,input().split())
ac=0
wa=[0]*n
wa_cnt=[0]*n
ac_flg=[0]*n
for i in range(w):
	p,s=input().split()
	p=int(p)-1
	if ac_flg[p]==1:
		continue
	else:
		if s=='AC':
			ac_flg[p]=1
			ac+=1
			wa[p] =wa_cnt[p]
			#wa_cnt=0
		else:
			wa_cnt[p]+=1

wa_ans=0
for i in range(n):
	wa_ans+=wa[i]

print(ac,wa_ans)
Buggy code:
n,m=map(int,input().split())

ac_cnt=[False]*n
wa_cnt=[0]*n

p=int(p-1)

for _ in range(m):
    a,b=input().split()
    if b == "AC":
        ac_cnt[a] == True
    else:
        if ac_cnt[a] == False:
            wa_cnt[a] += 1
a=0
b=0

for i in range(n):
    if ac_cnt[a]:
        a += 1
        b += wa_cnt[i]

print(a,b)

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

ac_cnt=[False]*n
wa_cnt=[0]*n

for _ in range(m):
    a,b=input().split()
    a=int(a)-1
    if b == "AC":
        ac_cnt[a] = True
    else:
        if ac_cnt[a] == False:
            wa_cnt[a] += 1
c=0
d=0

for i in range(n):
    if ac_cnt[i]:
        c += 1
        d += wa_cnt[i]

print(c,d)
Buggy code:
n, m = [int(i) for i in input().split(' ')]
wa = [0] * n
ac = [0] * n
for _ in range(m):
    problem, status = input().split(' ')
    problem = int(problem) - 1
    if status == 'WA':
        if ac[problem] == 0:
            wa[problem] += 1
        continue
    ac[problem] = 1

no_ac = sum(ac)
no_wa = sum(wa)

Fixed code:
n, m = [int(i) for i in input().split(' ')]
wa = [0] * n
ac = [0] * n
for _ in range(m):
    problem, status = input().split(' ')
    problem = int(problem) - 1
    if status == 'WA':
        if ac[problem] == 0:
            wa[problem] += 1
        continue
    ac[problem] = 1

no_ac = 0
no_wa = 0

for i in range(n):
    if ac[i] == 1:
        no_ac += 1
        no_wa += wa[i]

print(str(no_ac) + ' ' + str(no_wa))
Buggy code:
n, m = map(int, input().split())

result = set()
wr = {}
c_cnt = 0
w_cnt = 0
for i in range(m):
    p, s = input().split()
    if (p in result):
        continue

    if (s == 'AC'):
        result.add(p)
        w_cnt = wr.get(p, 0)
    else:
        wr[p] = wr.get(p, 0) + 1

print('{} {}'.format(len(result), w_cnt))


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

result = set()
wr = {}
c_cnt = 0
w_cnt = 0
for i in range(m):
    p, s = input().split()
    if (p in result):
        continue

    if (s == 'AC'):
        result.add(p)
        w_cnt = wr.get(p, 0) + w_cnt
    else:
        wr[p] = wr.get(p, 0) + 1

print('{} {}'.format(len(result), w_cnt))
Buggy code:
N, M = map(int, input().split())
accepted = [0] * N
penalties = [0] * N
for _ in range(M):
    p, ac = input().split()
    p, ac = int(p), ac == "AC"
    accepted[p] |= ac
    penalties[p] += not accepted[p]
print(sum(accepted), sum(p for ac, p in zip(accepted, penalties) if ac))


Fixed code:
N, M = map(int, input().split())
accepted = [0] * N
penalties = [0] * N
for _ in range(M):
    p, ac = input().split()
    p, ac = int(p) - 1, ac == "AC"
    accepted[p] |= ac
    penalties[p] += not accepted[p]
print(sum(accepted), sum(p for ac, p in zip(accepted, penalties) if ac))
Buggy code:
n,m = map(int,input().split())
ps = [0] * m
p = [0] * m
s = [0] * m
for i in range(m):
    ps[i] = list(map(str,input().split()))
if m = 0:
    print(0,0)
    exit()
cp=int(ps[0][0])
countA = [0] * n
countW = 0
cn = 0
for item in ps:
    if item[1] == 'AC':
        countA[int(item[0])-1] = 1
        countW += cn
        cp += 1
        cn = 0
    else:
        cn+=1
print(sum(countA),countW)

Fixed code:
n,m = map(int,input().split())
ps = [0] * m
for i in range(m):
    ps[i] = list(map(str,input().split()))
if m == 0:
    print(0,0)
    exit()
countA = [0] * n
countW = [0] * n
cn = 0
for item in ps:
    if item[1] == 'AC' and countA[int(item[0])-1] == 0:
        countA[int(item[0])-1] = 1
        cn += countW[int(item[0])-1]
    else:
        countW[int(item[0])-1] += 1
print(sum(countA),cn)
Buggy code:
N,M = list(map(int,input().split()))
colect_quest = [0]*N
WA_quest = [0]*N
for i in range(M):
    pi,si = list(map(str,input().split()))
    pi = int(pi)
    if si == "AC":
        colect_quest[pi] = 1
    if si == "WA" and colect_quest[pi] != 1:
        WA_quest[pi] += 1
    
print(sum(colect_quest),sum(WA_quest))

Fixed code:
N,M = list(map(int,input().split()))
colect_quest = [0]*N
WA_quest = [0]*N
for i in range(M):
    pi,si = list(map(str,input().split()))
    pi = int(pi)
    if si == "AC":
        colect_quest[pi-1] = 1
    if si == "WA" and colect_quest[pi-1] != 1:
        WA_quest[pi-1] += 1
WA_count = 0
for i in range(len(WA_quest)):
    if colect_quest[i] == 1 :
        WA_count += WA_quest[i] 
print(sum(colect_quest),WA_count)
Buggy code:
n, m = map(int, input().split())
AC = [0] * n
WA = [0] * n

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == 'AC': and a[p] == 0:
        AC[p] += 1
        w += W[p]
    elif s == 'WA' and a[p] == 0:
        WA[p] += 1

print(sum(a), w)


Fixed code:
n, m = map(int, input().split())
AC = [0] * n
WA = [0] * n
w = 0

for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if s == 'AC' and AC[p] == 0:
        AC[p] += 1
        w += WA[p]
    elif s == 'WA' and AC[p] == 0:
        WA[p] += 1

print(sum(AC), w)
Buggy code:
n,m = map(int,input().split())


correct = [0] * (n+1)
wrong = [0] * (n+1)



for _ in range(m):
    problem,result_text = input().split()
    problem = int(problem)
    
    if result_text == "AC":
        correct[problem]=1
        
    
    if result_text == "WA":
        if correct[problem] == 0:
            wrong[problem] += 1
    

for _ in range(len(wrong)):
    if correct[problem] == 0:
        wrong[problem] = 0



print ( sum(correct), sum(wrong) )

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


correct = [0] * (n+1)
wrong = [0] * (n+1)



for _ in range(m):
    problem,result_text = input().split()
    problem = int(problem)
    
    if result_text == "AC":
        correct[problem]=1
        
    
    if result_text == "WA":
        if correct[problem] == 0:
            wrong[problem] += 1
    

for problem in range(n+1):
    if correct[problem] == 0:
        wrong[problem] = 0



print ( sum(correct), sum(wrong) )
Buggy code:

def solve(N, M, A):

    Unsolve = [0]*(N+1)
    Solved = []
    ac = 0
    wa = 0
    for i in range(M):
        if A[i][0] not in Solved:
            if A[i][1] == 'WA':
                Unsolve[A[i][0]] += 1
            elif A[i][1] == 'AC':
                Solved.append(A[i][0])
                wa += Unsolve[A[i][0]]
                ac += 1
    return ac, wa

def main():
    N, M = map(int, input().split())
    A = [list(x for x in input().split()) for _ in range(M)]
    ans = solve(N, M, A)
    print(*ans)

if __name__ == "__main__":
    main()

Fixed code:

def solve(N, M, A):

    A = [[int(x[0]), x[1]] for x in A]

    Unsolve = [0]*(N+1)
    Solved = set()
    ac = 0
    wa = 0
    for i in range(M):
        if A[i][0] not in Solved:
            if A[i][1] == 'WA':
                Unsolve[A[i][0]] += 1
            elif A[i][1] == 'AC':
                Solved.add(A[i][0])
                wa += Unsolve[A[i][0]]
                ac += 1

    return ac, wa

def main():
    N, M = map(int, input().split())
    A = [list(x for x in input().split()) for _ in range(M)]
    ans = solve(N, M, A)
    print(*ans)

if __name__ == "__main__":
    main()