Problem:
 Score : 300 points    Problem Statement Takahashi participated in a contest on AtCoder.  The contest had N problems.  Takahashi made M submissions during the contest.  The i -th submission was made for the p_i -th problem and received the verdict S_i ( AC or WA ).  The number of Takahashi's correct answers is the number of problems on which he received an AC once or more.  The number of Takahashi's penalties is the sum of the following count for the problems on which he received an AC once or more: the number of WA s received before receiving an AC for the first time on that problem.  Find the numbers of Takahashi's correct answers and penalties.      Constraints  N , M , and p_i are integers.  1 \leq N \leq 10^5  0 \leq M \leq 10^5  1 \leq p_i \leq N  S_i is AC or WA .         Input Input is given from Standard Input in the following format:  N  M  p_1  S_1  :  p_M  S_M       Output Print the number of Takahashi's correct answers and the number of Takahashi's penalties.        Sample Input 1 2 5
1 WA
1 AC
2 WA
2 AC
2 WA      Sample Output 1 2 2  In his second submission, he received an AC on the first problem for the first time. Before this, he received one WA on this problem.  In his fourth submission, he received an AC on the second problem for the first time. Before this, he received one WA on this problem.  Thus, he has two correct answers and two penalties.       Sample Input 2 100000 3
7777 AC
7777 AC
7777 AC      Sample Output 2 1 0  Note that it is pointless to get an AC more than once on the same problem.       Sample Input 3 6 0      Sample Output 3 0 0

Solution (Python):
n,m=map(int,(input().split()))

import numpy as np
p = [0] * m
s = [''] * m
mat=[]

for i in range(m):
    p[i],s[i]=input().split()
    mat.append([p[i],s[i]])






kariwa=[0]*n
wa=[0]*n
anstrue=[False]*n

for i in range(m):
    if mat[i][1] == "WA" and anstrue[int(mat[i][0])-1]==False:
        kariwa[int(mat[i][0])-1]+=1
    elif mat[i][1] == "AC" and anstrue[int(mat[i][0])-1]==False:
        anstrue[int(mat[i][0])-1]=True
        wa[int(mat[i][0])-1]=kariwa[int(mat[i][0])-1]

print(sum(anstrue),sum(wa))

Solution (Python):
n,m=map(int,input().split())
d=[ input().split() for i in range(m)]
ans=[[0,0] for i in range(m+n+1)]
count=0
ac=0
wa=0

for i in range(m):
  if count!=d[i][0]:
    count=int(d[i][0])
  if d[i][1]=="WA" and ans[count][0]==0:
    ans[count][1]+=1
  elif d[i][1]=="AC" and ans[count][0]==0:
    ans[count][0]+=1
for i in range(n+m+1):
  ac+=int(ans[i][0])
  if int(ans[i][0])>=1:
    wa+=int(ans[i][1])
print(ac,wa)

Solution (Python):
N, M = map(int, input().split())
AC = [0 for i in range(N)]
WA = [0 for i in range(N)]
for i in range(M):
    p, v = input().split()
    p = int(p) - 1
    if v == "WA" and AC[p] == 0:
        WA[p] += 1
    elif v == "AC":
        AC[p] = 1

C = sum(AC)
F = 0
for i in range(N):
    if AC[i]: F += WA[i]
print(C, F)

Solution (Python):



N,M=map(int, input().split())
ifACL=[0]*N
cWAL=[0]*N
psL=[]
AC=0
WA=0
p=0
s=0
for _ in range(M):
  p,s=map(str, input().split())
  p=int(p)
  if ifACL[p-1]==0 and s=="WA":
    cWAL[p-1]+=1
  elif ifACL[p-1]==0 and s=="AC":
    AC+=1
    WA+=cWAL[p-1]
    ifACL[p-1]=1

print(AC,WA)

Solution (Python):
N,M = map(int,input().split())

nAC = 0
nWA = 0
result_dic = {}

for i in range(M):
    pi, si = input().split()
    
    if pi not in result_dic.keys():

        if si == "AC":
            result_dic[pi] = [si,0]
            nAC += 1
        else:
            result_dic[pi] = [si,1]
    else:
        pi_res = result_dic[pi][0]
        if pi_res == "AC":
            pass
        elif pi_res == "WA":
            if si == "AC":
                nWA += result_dic[pi][1]
                nAC += 1
                result_dic[pi] = [si,0]
            elif si == "WA":
                result_dic[pi][1] += 1


print(nAC,nWA)

Solution (Python):
n, m = map(int, input().split())
p = []
s = []
seikai = [0]*(n+1)
penalty = [0]*(n+1)

for i in range(m):
    a,b = input().split()
    p.append(int(a))
    s.append(b)

for i in range(m):
    if s[i] == 'AC':
        seikai[p[i]] = 1
    elif s[i] == 'WA' and seikai[p[i]]==0:
        penalty[p[i]] = penalty[p[i]]+1

for i in range(n+1):
    penalty[i] = penalty[i] * seikai[i]

c = sum(seikai)
d = sum(penalty)

print(c, end=' ')
print(d)

Solution (Python):


import bisect
import math

N, M = (int(v) for v in input().split())

seen = {}
WA = {}

acs = 0
was = 0

for i in range(M):
    q, tmp = input().split()
    if tmp == "AC":
        if q not in seen:
            acs += 1
            if q not in WA:
                WA[q] = 0
            was += WA[q]
            seen[q] = 1
    else:
        if q not in WA:
            WA[q] = 1
        else:
            WA[q] += 1

print (acs, was)

Solution (Python):
n, m = input().split()
a = [False] * int(n)
penalty = [0] * int(n)
AC = 0
WA = 0
for i in range(int(m)):
  p, s = input().split()
  if(s == "AC" and a[int(p) - 1] == False):
    a[int(p) - 1] = True
    WA += penalty[int(p) - 1]
    AC += 1
  if(s == "WA" and a[int(p) - 1] == False):
    penalty[int(p) - 1] += 1

print(AC, WA)

Solution (Python):
n, m = map(int, input().split())

import numpy as np

contest = np.zeros((2, n), dtype=int)

for i in range(m):
  a = list(input().split())
  t_num = int(a[0]) - 1
  if a[1] == "AC":
    if contest[0, t_num] == 0:
      contest[0, t_num] = 1
  else:
    if contest[0, t_num] == 0:
      contest[1, t_num] += 1

contest[1,:] = contest[0,:]*contest[1,:]

ans = np.sum(contest, axis = 1)
print(ans[0], ans[1])

Solution (Python):
from sys import stdin as s
n,m=map(int,s.readline().split())
l=[0]*n
wa=[0]*n
cor,pen=0,0
for i in range(m):
  x,y=s.readline().split()
  x=int(x)-1
  if y=="AC":
    l[x]=1
  elif not l[x]:
    wa[x]+=1
for i in range(n):
  if l[i]:
    cor+=1
    pen+=wa[i]
print(cor,pen)

Solution (Python):
import string
N,M=map(int,input().split())
A=list(range(N))
B=list(range(N))
for i in range(N):
 A[i]=0
for i in range(N):
 B[i]=0
CL=0
PN=0
for i in range(M):
 P,s=input().split()
 p=int(P)
 if A[p-1]==0:
  if s=="WA":
   B[p-1]+=1
  else:
   CL+=1
   PN+=B[p-1]
   A[p-1]=1
print("{0} {1}".format(CL,PN))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10000000)

N, M = map(int, input().split())

ac_set = set()
wa_dict = {}

for i in range(M):
    p, s = input().split()

    
    if s == 'AC':
        ac_set.add(p)
    elif s == 'WA':
        if p not in ac_set:
            if wa_dict.get(p) is None:
                wa_dict[p] = 1
            else:
                wa_dict[p] += 1
    else:
        pass

ac_count = len(ac_set)
wa_count = 0

for k, v in wa_dict.items():
    if k in ac_set:
        
        wa_count += v

print('{} {}'.format(ac_count, wa_count))

Solution (Python):
n, m = map(int, input().split())
ans = 0
lstn = [False for i in range(n)]
lstc = [0 for i in range(n)]
for i in range(m):
  p, s = input().split()
  pp = int(p)
  status = lstn[pp-1]
  if not status:
    if s == "WA":
      lstc[pp-1] += 1
    else:
      lstn[pp-1] = True
seikai = lstn.count(True)
for i in range(len(lstn)):
  tf = lstn[i]
  if tf:
    ans += lstc[i]
print(seikai, ans)

Solution (Python):
N, M = map(int, input().split())
pS = [input().split() for _ in range(M)]

p = [int(i[0]) for i in pS]
S = [i[1] for i in pS]

aced = [False for _ in range(N)]
penalty = [0 for _ in range(N)]


for i in range(M):
    if not aced[int(pS[i][0])-1]:
        if pS[i][1] == 'WA':
            penalty[int(pS[i][0])-1] += 1
            
        if pS[i][1] == 'AC':
            aced[int(pS[i][0])-1] = True


penaltyCount = 0
for i in range(N):
    if aced[i]:
        penaltyCount += penalty[i]

print(aced.count(True), penaltyCount)

Solution (Python):
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    PS = [(int(p), s) for p, s in (input().split() for _ in [0] * M)]

    taka = [['WA', 0] for _ in [0] * (N + 1)]
    for p, s in PS:
        if taka[p][0] == 'AC':
            continue
        taka[p][0] = s
        if s == 'WA':
            taka[p][1] += 1
    ac, wa = 0, 0
    for a, b in taka:
        if a == 'AC':
            ac += 1
            wa += b
    print(ac, wa)


main()

Solution (Python):
N, M = map(int, input().split())
P = [0] * M
S = ["a"] * M
flg = [0] * N
C = 0
D = 0
E = [0] * N

for i in range(M):
	tmp, S[i] = map(str, input().split())
	P[i] = int(tmp)

	if S[i]=="AC":
		if flg[P[i]-1]==0:
			C += 1
			flg[P[i]-1] = 1
			E[P[i]-1] = 0
	elif S[i]=="WA":
		if flg[P[i]-1]==0:
			D += 1
			E[P[i]-1] += 1

print(C, D-sum(E))

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline






















def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,M = inputMap()
	ansrs_AC = [0 for i in range(N)]
	ansrs_WA = [0 for i in range(N)]
	ans1 = 0
	ans2 = 0
	for i in range(M):
		inp = input()
		inp = inp[:-1]
		p, S = inp.split(" ")
		pp = int(p)
		if S == "AC":
			if ansrs_AC[pp-1] == 1:
				continue
			else:
				ansrs_AC[pp-1] = 1
		else:
			if ansrs_AC[pp-1] == 1:
				continue
			else:
				ansrs_WA[pp-1] += 1

	for i in range(N):
		if ansrs_AC[i] == 1:
			ans1 += 1
			ans2 += ansrs_WA[i]
	print("{} {}".format(ans1, ans2))

if __name__ == "__main__":
	main()

Solution (Python):
n, m = map(int, input().split())

tmp = [0] * n
wa = [0] * n
ac = [0] * n

for _ in range(m):
    p, s = input().split()
    p = int(p)
    p = p - 1
    
    
    
    
    if s == 'WA':
        if ac[p] == 0:
            tmp[p] += 1
        
    if s == 'AC':
        if ac[p] == 0:
            ac[p] = 1
            wa[p] = tmp[p]
        
print("{} {}".format(sum(ac), sum(wa)))

Solution (Python):
n, m = map(int, input().split())


p = [0]*m
p_tmp = "0"
s = [0]*m
check = [0]*n
memory_penalty = [0]*n
for i in range(m):
  p_tmp, s[i] = (map(str, input().split()))
  p[i] = int(p_tmp)
  
  
  
for i in range(n):
  check[i] = 0
  memory_penalty[i] = 0
  
num_correct = 0
num_penalty = 0

for i in range(m):
  if( check[ p[i]-1 ] == 0 and s[i] == "WA"):
    memory_penalty[ p[i]-1 ] = memory_penalty[ p[i]-1 ] + 1
  elif( check[ p[i]-1 ] == 0 and s[i] == "AC"):
    num_correct = num_correct + 1
    num_penalty = num_penalty + memory_penalty[ p[i]-1 ]
    check[p[i]-1] = 1

print(num_correct, num_penalty)

Solution (Python):
import sys
inputs = sys.stdin.readlines()
n, m = map(int, inputs[0].split())
acs = [0]*n
was = [0]*n
for X in inputs[1:]:
    p, s = X.split()
    p = (int(p)-1)
    if acs[p] == 0:
        if s == 'AC':
            acs[p] = 1
        else:
            was[p] += 1

print(*[sum(acs), sum(w for a, w in zip(acs, was) if a)])

Solution (Python):
def main():
    N, M = list(map(int, input().split()))

    lst = [[0] for _ in range(N)]
    for i in range(M):
        p, S = input().split()
        p = int(p) -1

        if lst[p][-1] == 0:
            lst[p][-1] = S
        elif lst[p][-1] != 'AC':
            lst[p].append(S)

    clear_count = 0
    penalty_count = 0
    for l in lst:
        if l[-1] == 'AC':
            clear_count += 1
            for j in l:
                if j == 'WA':
                    penalty_count += 1

    print(clear_count, penalty_count)

if __name__ == "__main__":
    main()

Solution (Python):
from collections import defaultdict
n,m=map(int,input().split())
ps=[list(input().split()) for _ in range(m)]
ac=0
wa=0
d=defaultdict(int)
a=defaultdict(int)
for p,s in ps:
  if s=="WA":
    d[p]+=1
  elif s=="AC":
    if a[p]!=1:
      a[p]=1
      ac+=1
      wa+=d[p]
print("{} {}".format(ac,wa))

Solution (Python):
N,M= map(int, input().split())
p = [0]*M
S = [0]*M
for i in range(M):
    _, S[i] = input().split()
    p[i] = int(_)


q_a = [0]*N
ans = [0,0]
for i in range(M):
    if S[i] == "AC" and q_a[p[i]-1] == 0:
        q_a[p[i]-1] = 1
        ans[0]+= 1

p_count = 0
i=0
while i<M:
    if q_a[p[i]-1]:
        if S[i] == "WA":
            p_count += 1
        else:
            ans[1] += p_count
            p_count = 0
            q_a[p[i]-1] = 0
    i += 1

print(*ans)

Solution (Python):
N, M = map(int, input().split(" "))

P = []
S = []

clear = 0

q = {}
c = set()

for i in range(M):
    sss = input().split(" ")
    p = int(sss[0])
    s = sss[1]
    P.append(p)
    S.append(s)

    if p not in c:
        if s == "AC":
            clear += 1
            c.add(p)

        if s == "WA":
            q[p] = q.get(p, 0) + 1

warng = sum([
    q[k]
    for k in c
    if k in q
])

print("{} {}".format(clear, warng))

Solution (Python):
n, m = map(int, input().split())

ans = {str(i): [0, 0] for i in range(1, n + 1)}
for i in range(m):
    
    p, s = input().split()
    if s == 'WA' and ans[p][0] == 0:
        ans[p][1] += 1
    elif s == 'WA' and ans[p][0] == 1:
        pass
    elif s == 'AC' and ans[p][0] == 0:
        ans[p][0] = 1
    elif s == 'AC' and ans[p][0] == 1:
        pass

sum_ac = 0
sum_wa = 0
for x, y in ans.values():
    sum_ac += x
    if x == 1:
        sum_wa += y

print(sum_ac, sum_wa)

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline






















def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	N,M = inputMap()
	ansrs_AC = [0 for i in range(N)]
	ansrs_WA = [0 for i in range(N)]
	ans1 = 0
	ans2 = 0
	for i in range(M):
		inp = input()
		inp = inp[:-1]
		p, S = inp.split(" ")
		pp = int(p)
		if S == "AC":
			if ansrs_AC[pp-1] == 1:
				continue
			else:
				ansrs_AC[pp-1] = 1
		else:
			if ansrs_AC[pp-1] == 1:
				continue
			else:
				ansrs_WA[pp-1] += 1

	for i in range(N):
		if ansrs_AC[i] == 1:
			ans1 += 1
			ans2 += ansrs_WA[i]
	print("{} {}".format(ans1, ans2))

if __name__ == "__main__":
	main()

Solution (Python):
N, M = map(int, input().split())
p = []
s = []
for _ in range(M):
	tp,ts = map(str,input().split())
	p.append(int(tp))
	s.append(ts)

cnt = [0] * (N+1)
flg = [0] * (N+1)
cnt_AC = 0
cnt_WA = 0
for i in range(M):
	cp = p[i]
	if flg[cp] == 1:
		continue
	else:
		if s[i] == 'AC':
			cnt_AC += 1
			cnt_WA += cnt[cp]
			flg[cp] = 1
		else:
			cnt[cp] += 1
print(cnt_AC, end = " ")
print(cnt_WA)

Solution (Python):
N,M = map(int,input().split())
ps = []
for i in range(M):
	P,S = map(str,input().split())
	ps.append((int(P),S))

p_flag = [0]*N
ans_flag = [0]*N
cnt_ans = 0
cnt_p = 0
p_cnt_flag = [0]*N
for i in range(M):
	if(p_flag[ps[i][0]-1] == 0 and ps[i][1] == "WA"):
		p_cnt_flag[ps[i][0]-1]+=1
	if(ans_flag[ps[i][0]-1] == 0 and ps[i][1] == "AC"):
		cnt_ans+=1
		ans_flag[ps[i][0]-1]+=1
		p_flag[ps[i][0]-1]+=1
		cnt_p+=p_cnt_flag[ps[i][0]-1]
print(cnt_ans,cnt_p)

Solution (Python):
N,M=map(int,input().split())
P=[0]*M
S=[0]*M
cor=[0]*N
ac,wa=0,0
for i in range(M):
    P[i],S[i]=input().split()
    P[i]=int(P[i])
    if(S[i]=="AC"):
        cor[P[i]-1]+=1
    else:
        pass
for i in range(M):
    if(cor[P[i]-1]>=1 and S[i]=="WA"):
        wa+=1
    elif(cor[P[i]-1]>=1 and S[i]=="AC"):
        cor[P[i]-1]=0
        ac+=1
    else:
        pass
print("{0} {1}".format(ac,wa))

Solution (Python):
N, M = map(int, input().split())
question_list = []
score_list = []

for i in range(M):
  q,s = input().split()
  question_list.append(int(q))
  score_list.append(s)

maru_flag = [0] * N
pena_flag = [0] * N
for i in range(M):
  if score_list[i] == "AC":
    maru_flag[question_list[i] - 1] = 1

  if maru_flag[question_list[i] - 1] != 1 and score_list[i] == "WA":
    pena_flag[question_list[i] - 1] += 1

for i in range(N):
  if maru_flag[i] != 1 and pena_flag[i] > 0:
    pena_flag[i] = 0

print(str(sum(maru_flag)) + " " + str(sum(pena_flag)))

Solution (Python):
n,m=map(int,input().split())
p=[]
s=[]
for c in range(m):
    k=input().split()
    p.append(int(k[0])-1)
    s.append(k[1])
a=[0]*n
w=[0]*n
for c in range(m):
    if a[p[c]]==1:
        continue
    if s[c]=="AC":
        a[p[c]]=1
    else:
        w[p[c]]+=1
u=0
for c in range(n):
    if a[c]==1:
        u+=w[c]
print(sum(a),u)

Solution (Python):

N,M=map(int,input().split())
pSlist=[0]*(N+1)
ansA=0
ansWA=0
for i in range(M):
    p,S=map(str,input().split())
    p=int(p)
    if S=="WA" and pSlist[p]!=-1:
        pSlist[p]=pSlist[p]+1
    elif S=="AC" and pSlist[p]!=-1:
        ansA=ansA+1
        ansWA=ansWA+pSlist[p]
        pSlist[p]=-1
print(ansA,ansWA)

Solution (Python):
_,M = map(int,input().split())
result = {}
for i in range(M):
    P, Q = input().split()
    if P not in result:
        result[P] = [Q]
    else:
        if result[P][-1]=='AC':
            pass
        else:
            result[P].append(Q)
AC = 0
WA = 0
numbers = list(result.values())
for i in range(len(numbers)):
    AC += numbers[i].count('AC')
    if numbers[i][-1]=='WA':
        pass
    else:
        WA += numbers[i].count('WA')
        
print(AC,WA)

Solution (Python):
from operator import itemgetter

n, m = map(int, input().split())

an = [0]*n

sc = 0
er = 0

for i in range(m):
    t, s = map(str, input().split())
    p = int(t)-1
    if (an[p] != m+1 and s == "AC"):
        sc += 1
        er += an[p]
        an[p] = m+1
    elif (an[p] != m+1 and s == "WA"):
        an[p] += 1


print("{} {}".format(sc, er))

Solution (Python):
n,m=[int(x) for x in input().split()]
a=[0 for _ in range(n)]
b=[0 for _ in range(n)]
xg=0
for _ in range(m):
  p,q=input().split()
  
  if q=="AC": 
    
    rg=a[int(p)-1]
    if rg==0: a[int(p)-1]=1; xg+=b[int(p)-1]
  else : 
    
    b[int(p)-1]+=1
print(sum(a),xg)

Solution (Python):

input_data = input().split()
n, m = map(int, input_data)


col_list = [0 for i in range(n)]
penal_list = [0 for i in range(n)]


col = 0

penal = 0


for i in range(m):
  input_data = input().split()
  
  
  chk_index = int(input_data[0]) - 1
  
  
  if(col_list[chk_index] == 1):
    continue
  if(input_data[1] == "AC"):
    col_list[chk_index] = 1
  else:
    penal_list[chk_index] += 1


for i,v in enumerate(col_list):
  if(v == 1):
    col += 1
    penal += penal_list[i]

print(str(col) + " " + str(penal))

Solution (Python):
n, m = map(int, input().split())
p = [0]*n
num_wa = [0]*n
wa = 0
for i in range(m):
    a, b= map(str, input().split())
    if 0 == p[int(a)-1] and b == "AC":
        p[int(a)-1] = 1
        wa += num_wa[int(a)-1]
    elif 0 == p[int(a)-1] and b == "WA":
        num_wa[int(a)-1] += 1
print(sum(p), wa)

Solution (Python):
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def main():
    n,m = mi()

    t = [[] for i in range(n+1)]

    for i in range(m):
        p,s = input().split()
        p = int(p)
        t[p].append(s)

    if m == 0:
        print("0 0")
        exit()


    accnt = 0
    wacnt = 0

    for i in range(1,n+1):
        if not t[i]:
            continue
        wtmp = 0
        flag = False
        for k in t[i]:
            if k == "AC":
                accnt+=1
                flag = True
                break
            else:
                wtmp+=1
        if flag:
            wacnt+=wtmp

    print(accnt,wacnt)






main()

Solution (Python):
import numpy as np
def main():
    nm = list(map(int, input().split()))
    p = np.zeros(nm[0], dtype=int)
    ac = np.zeros_like(p)
    for i in range(nm[1]):
        ps = input().split()
        if ac[int(ps[0])-1] == 0:
            if ps[1] == "WA":
                p[int(ps[0])-1] += 1
            elif ps[1] == "AC":
                ac[int(ps[0])-1] += 1

    print(np.sum(ac), np.sum(p[ac == 1]))

if __name__ == '__main__':
    main()

Solution (Python):
n,m = map(int,input().split())
d = {}
e = {}
a = 0
b = 0
for _ in range(m):
    p, s = input().split()
    if p in d:
        continue
    else:
        if s == 'WA':
            if p in e:
                e[p] += 1
            else:
                e[p] = 1
        else:
            d[p] = 'AC'
            a += 1
            if p in e:
                b += e[p]
print(a,b)

Solution (Python):
N, M = map(int,input().split())
p = []
S = []
for i in range(M):
    a, b = map(str,input().split())
    a = int(a)
    p.append(a)
    S.append(b)
ac_ans = 0
pn_ans = 0
tmp_dict = dict()
ac_dict = dict()
pn_dict = dict()
for i in range(N):
    ac_dict[i] = 0
    pn_dict[i] = 0
    tmp_dict[i] = 0

for i in range(M):
    if S[i] == "AC":
        tmp_dict[p[i]-1] = pn_dict[p[i]-1]
        if ac_dict[p[i]-1] == 0:
            ac_dict[p[i]-1] += 1
        else:
            pass
    else:
        if ac_dict[p[i]-1] == 0:
            pn_dict[p[i]-1] += 1
        else:
            pass
for i in range(N):
    ac_ans += ac_dict[i]
for i in range(N):
    pn_ans += tmp_dict[i]
ac_ans = str(ac_ans)
pn_ans = str(pn_ans)
print(ac_ans + " " + pn_ans)

Solution (Python):
n, m = map(int, input().split())
a_list = []
b_list = ["f"] * (10**5+1)
count_ac = 0
count_wa = 0
for i in range(m):
    a,b = map(str, input().split())
    a_list.append((int(a),b))
for i in range(m):
    if a_list[i][1] == "WA" and b_list[a_list[i][0]] == "f":
        count_wa += 1
    if a_list[i][1] == "AC":
        if b_list[a_list[i][0]] == "f":
            count_ac += 1
        b_list[a_list[i][0]] = "t"
for i in range(m):
    if b_list[a_list[i][0]] == "f" and a_list[i][1] == "WA":
        count_wa -= 1
print(count_ac,count_wa)

Solution (Python):

N, M = map(int, input().split(' '))


ac, wa_list = 0, [0 for _ in range(N)]
solved = [False for _ in range(N)]
for _ in range(M):
    p, s = input().split(' ')
    p = int(p) - 1

    if solved[p]:
        continue

    else:
        if s == 'AC':
            solved[p] = True
            ac += 1

        elif s == 'WA':
            wa_list[p] += 1

wa = sum([wa for wa, s in zip(wa_list, solved) if s])

print(ac, wa)

Solution (Python):
n, m = map(int, input().split())
ans = [list(input().split()) for i in range(m)]
ac = [0 for i in range(n)]
penali = [0 for i in range(n)]

a = 0

for s,t in ans:
    if t== 'WA' and ac[int(s)-1] == 0:
        penali[int(s)-1] += 1
    if t == 'AC':
        if ac[int(s)-1] == 0:
            a +=1
        ac[int(s)-1] = 1

for i in range(n):
    if ac[i] == 0:
        penali[i] = 0

pena = 0
for i in penali:
    pena += i

print(a, pena)

Solution (Python):
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

def main():
    n, m = map(int, input().split())
    ac_status = defaultdict(int)
    wa_count = defaultdict(int)
    for _ in range(m):
        p, s = input().split()
        p = int(p)
        if s == "AC":
            ac_status[p] = 1
        else:
            if ac_status[p] != 1:
                wa_count[p] += 1
    ac = len([v for v in ac_status.values() if v == 1])
    wa = sum([v for k,v in wa_count.items() if ac_status[k] == 1])
    
    
    print(ac, wa)


input = lambda: stdin.readline().rstrip()
main()

Solution (Python):
N, M = map(int, input().split())
l = [0 for _ in range(N)]
AC = 0
WA = 0
for _ in range(M):
  p, S = input().split()
  p = int(p) - 1
  if l[p] != None and S == "WA":
    l[p] += 1
  if l[p] != None and S == "AC":
    AC += 1
    WA += l[p]
    l[p] = None
print(AC, WA)

Solution (Python):
from collections import defaultdict as dd, deque

n,m = map(int,input().split())

solved = set()
penals = dd(int)

for _ in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'AC':
        solved.add(p)
    else:
        if p not in solved:
            penals[p] += 1

print(len(solved), sum(penals[p] for p in penals if p in solved))

Solution (Python):
n, m = map(int, input().split())
d = [[] for i in range(n)]    


for _ in range(m):
    p, s = input().split()
    p = int(p) - 1
    d[p].append(s)

ac_cnt, w_cnt = 0, 0
for l in d:
    if len(l) != 0 and "AC" in l:
        w_cnt += l.index("AC")

    if "AC" in l:
        ac_cnt += 1

print(ac_cnt, w_cnt)

Solution (Python):
n,m  = list(map(int, input().split()))
p, s = [None for _ in range(m)],[None for _ in range(m)]
for i in range(m):
    p[i], s[i] = input().split()
p = list(map(int, p))

correct = [0 for _ in range(n)]
penal = [0 for _ in range(n)]

for i in range(m):
    if s[i] == 'AC':
        correct[p[i]-1] = 1
    else:
        if correct[p[i]-1] != 1:
            penal[p[i]-1] += 1

for i, cor in enumerate(correct):
    if cor == 0:
        penal[i] = 0


c = sum(correct)
pen = sum(penal)
print(c, pen)

Solution (Python):
N,M = [int(i) for i in input().split()]
nes = ['0'] * M
for i in range(M) :
    li = input().split()
    nes[i] = li
sum_ac = 0
sum_wa = 0
l = [0] * (N+1)
for i in range(N+1) :
    l[i] = True
r = [0] * (N+1)
rr = [0] * (N+1)
for i in range(M) :
    if nes[i][1] == "AC" :
        if l[int(nes[i][0])] :
            sum_ac+=1
            r[int(nes[i][0])]+=1
            l[int(nes[i][0])] = False
    if nes[i][1] == "WA" :
        if l[int(nes[i][0])] :
            sum_wa +=1
            rr[int(nes[i][0])] += 1
for i in range(1,N+1) :
    if r[i] == 0 :
        sum_wa -= rr[i]
print(sum_ac,sum_wa)

Solution (Python):
N, M = map(int, input().split())

AC = [False] * (N + 1)
WA = [0] * (N + 1)
for _ in range(M):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        AC[p] = True
    if s == "WA" and not AC[p]:
        WA[p] += 1

cnt = 0
for a, w in zip(AC, WA):
    if a:
        cnt += w

print(sum(AC), cnt)

Solution (Python):
n, m = map(int, input().split())
q_re = set()
ac = 0
wa = 0
dic_wa = {}
for i in range(m):
    q, re = input().split()
    if(re == "WA" and q not in q_re): 
        if(q not in dic_wa): dic_wa[q] = 1
        else: dic_wa[q] += 1
    if(re == "AC" and q not in q_re): 
        ac += 1
        q_re.add(q)
        if(q in dic_wa): wa += dic_wa[q]
print(ac, wa)

Solution (Python):
inp = input()
N,M = inp.split()
N,M = int(N), int(M)

CorrectAnswer = [0] * N
Penalties     = [0] * N

p = []
S = []
for i in range(M):
    inp = input()
    x,y = inp.split()
    x   = int(x)


    
    
    if CorrectAnswer[x-1] == 1:
        pass
        
    else:
        if y == 'AC':
            CorrectAnswer[x-1] = 1
        else:
            Penalties[x-1] += 1

penalties = 0
for i in range(N):
    penalties += CorrectAnswer[i] * Penalties[i]
print(sum(CorrectAnswer), penalties)

Solution (Python):
n,m = map(int, input().split(" "))
ac = 0
wa = 0
en_li = [[] for i in range(n)]
print
for i in range(m):
    a, b = input().split(' ')
    en_li[int(a)-1].append(b)
ac = 0
wa = 0
for i in en_li:
    if 'AC' in i:
        wa += i.index('AC')
        ac += 1
print(ac, wa)

Solution (Python):
def main():
    N, M = map(int, input().split())

    ac_count = 0
    wa_count = 0

    if M == 0:
        print('{} {}'.format(ac_count, wa_count))
        exit()

    result_list = []

    for i in range(N):
        result_list.append([i+1, 0, 0])

    for i in range(M):
        str_list = input().split()
        if result_list[int(str_list[0])-1][1] == 1:
            continue
        if str_list[1] == 'AC':
            result_list[int(str_list[0])-1][1] = 1
        if str_list[1] == 'WA' and result_list[int(str_list[0])-1][1] == 0:
            result_list[int(str_list[0])-1][2] += 1

    for i in range(N):
        if result_list[i][1] == 1:
            ac_count +=1
            wa_count += result_list[i][2]

    print('{} {}'.format(ac_count, wa_count))

if __name__ == '__main__':
    main()

Solution (Python):
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

import itertools as iter
import math
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,M = nums()
AC = set()
WA = {}
for _ in range(M):
    pi,si = input().split()
    if si == "AC":
        AC.add(pi)
    else:
        if not (pi in WA.keys()) and not pi in AC:
            WA[pi] = 1
        else:
            if not (pi in AC):
                WA[pi] += 1

for problem in WA.keys():
    if not (problem in AC):
        WA[problem] = 0
ACnum = len(AC)
WAnum = sum(WA.values())
print(ACnum,WAnum)

Solution (Python):
n,m = map(int,input().split())
l = [[False,0] for _ in range(n+1)]
p = 0
c = 0
for i in range(m):
  pi,si = input().split()
  pi = int(pi)
  si = str(si)
  if l[pi][0] == False:
    if si == "AC":
      c += 1
      l[pi][0] = True
      p += l[pi][1]
    else:
      l[pi][1] += 1
print(c,p)

Solution (Python):
n,m = map(int,input().split())
p = []
S = []
p_count = 0
a_count = 0
for i in range(m):
    temp1,temp2 = input().split()
    p.append(int(temp1))
    S.append(temp2)
n_table = [0 for i in range(n)]
n_wa_table = [0 for i in range(n)]
for p,s in zip(p,S):
    if s == "AC":
        n_table[p-1] = 1
    if s == "WA" and n_table[p-1] == 0:
        n_wa_table[p-1] += 1
a_count = n_table.count(1)
wai = [i for i, x in enumerate(n_table) if x == 1]
for i in wai:
    p_count += n_wa_table[i]
print(a_count,p_count)

Solution (Python):
N, M = list(map(int, input().split()))
questions = []
for i in range(M):
    p, S = list(input().split())
    questions.append([int(p), S])

ac_list = [0] * N
wa_list = [0] * N

for p, S in questions:
    if S == 'AC':
        ac_list[p - 1] = 1
    else:
        if ac_list[p - 1] == 1:
            continue
        wa_list[p - 1] += 1

for i in range(N):
    if ac_list[i] == 0:
        wa_list[i] = 0

print(sum(ac_list), sum(wa_list))

Solution (Python):
N,M = list(map(int, input().split()))
p = []
s = []
for i in range(M):
  temp = list(map(str, input().split()))
  p_temp = int(temp[0])
  p.append(p_temp)
  s.append(temp[1])

ac_list = []
ac_num = 0
wa_num = 0
ques_list = []
wa_list = []
for i in range(N):
  ques_list.append(0)
  wa_list.append(0)

for i in range(M):
  if(s[i]=="AC" and ques_list[p[i]-1]==0):
    ac_num += 1
    ques_list[p[i]-1] = 1
  elif(s[i]=="WA" and ques_list[p[i]-1]==0):
    wa_list[p[i]-1] += 1
    
for i in range(N):
  if(ques_list[i]==1):
    wa_num += wa_list[i]
    
print(ac_num, wa_num)

Solution (Python):
N, M = map(int, input().split())
queans = []
wa = [0] * N
ac = [0] * N
for i in range(M):
  a,b=input().split()
  queans.append((int(a), b))
for i in range(M):
  Q = queans[i][0]
  A = queans[i][1]
  if(A == 'AC'):
    ac[Q-1] = 1 
  else:
    if(ac[Q-1] != 1):
      wa[Q-1] += 1
      
acsum = 0
wasum = 0
for j in range(N):
  acsum += ac[j]
  if(ac[j] != 0):
    wasum += wa[j]

print(acsum, wasum)

Solution (Python):
N, M = list(map(int,input().split()))

ac_set = set()
wa_cnt = {}
for i in range(M):
    p, s = input().split()
    if s == 'WA' :
        wa_cnt.setdefault(p, 0)
        if p not in ac_set:
            wa_cnt[p] += 1
    else :
        ac_set.add(p)
        
wa_sum = 0
for k, v in wa_cnt.items():
    if k in ac_set:
        wa_sum += v
print(len(ac_set),wa_sum)

Solution (Python):




n, m = map(int,input().split())


acstat = [0] * (n+1)
wa_acm = [0] * (n+1)

wk_p = -1
ac_cnt = 0
wa_cnt = 0
for i in range(m):
    p, s = input().split()
    inp = int(p)
    if s == "AC":
        if acstat[inp] == 0:
            ac_cnt = ac_cnt + 1
            wa_cnt = wa_cnt + wa_acm[inp]
            acstat[inp] = 1
        
    elif s == "WA":
        if acstat[inp] == 0:
            wa_acm[inp] = wa_acm[inp] + 1


print(ac_cnt, wa_cnt)