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())
ques = [0] * N
ans = 0
pen = 0
for i in range(M):
    a, b = map(str, input().split())
    if ques[int(a)-1] >= 0 and b == "WA":
        ques[int(a)-1] += 1
    elif ques[int(a)-1] >= 0 and b == "AC":
        ans += 1
        pen += ques[int(a)-1]
        ques[int(a)-1] = -1
        
print(ans, pen)

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

ac_list = [0 for _ in range(N)]
wa_list = [0 for _ in range(N)]

for i in range(M):
    if ac_list[int(L[i][0]) - 1] != 1:
        if L[i][1] == 'AC':
            ac_list[int(L[i][0]) - 1] = 1
        else:
            wa_list[int(L[i][0]) - 1] += 1

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

print(sum(ac_list), wrong)

Solution (Python):
n, m = map(int, input().split())
ans = [False for _ in range(n)]
f = [0 for _ in range(n)]
t = 0
fsum = 0
for i in range(m):
    a, b = input().split()
    if not ans[int(a) - 1]:
        if b == 'AC':
            t += 1
            ans[int(a) - 1] = True
            fsum += f[int(a) - 1]
        else:
            f[int(a) - 1] += 1
print(t, fsum)

Solution (Python):

























N, M = map(int, input().split())
ARR = []

for i in range(M):
    index, value = input().split()
    ARR.append([int(index), value])


def calculate(n, m, arr):
    acResult = [-1 for i in range(n)]
    waResult = [0 for i in range(n)]

    for index in range(m):
        i = arr[index][0] - 1
        if arr[index][1] == 'AC':
           if acResult[i] == -1:
               acResult[i] = index
           else:
               if acResult[i] > index:
                   acResult[i] = index

    for index in range(m):
        i = arr[index][0] - 1
        if arr[index][1] == 'WA':
            if index < acResult[i] and acResult[i] > -1:
                waResult[i] = waResult[i] + 1


    result1 = 0
    result2 = 0
    for index,ac in enumerate(acResult):
        if ac > -1:
            result1 = result1 + 1
            result2 = result2 + waResult[index]



    print(result1,result2)

calculate(N, M, ARR)

Solution (Python):

import sys


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    from collections import defaultdict
    ac = set()
    wcc = defaultdict(int)
    for pp, ss in zip(p, S):
        if pp in ac:
            continue
        if ss == 'WA':
            wcc[pp] += 1
        else:
            ac.add(pp)
    print(len(ac), sum((c for p, c in wcc.items() if p in ac), 0))



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    p = [int()] * (M)  
    S = [str()] * (M)  
    for i in range(M):
        p[i] = int(next(tokens))
        S[i] = next(tokens)
    solve(N, M, p, S)

if __name__ == '__main__':
    main()

Solution (Python):
n,m = map(int,input().split())
a = [0]*n
AC,WA=0,0
for i in range(m):
    x,y = input().split()
    x = int(x)
    if a[x-1]!=-1 and y=="WA":
        a[x-1]+=1
    if a[x-1]!=-1 and y=="AC":
        WA+=a[x-1]
        AC+=1
        a[x-1]=-1
print(AC,WA)

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

ans_list = [[0 for i in range(2)] for j in range(n)]

for i in range(m):
    p_num = int(p_list[i][0])
    if ans_list[p_num-1][0] != 1:
        if p_list[i][1] == "WA":
            ans_list[p_num-1][1]  =  ans_list[p_num-1][1] + 1
        else:
            ans_list[p_num-1][0]  = 1
count1 = 0
count2 = 0
for i in range(n):
    if ans_list[i][0] == 1:
        count1 += 1
        count2 += ans_list[i][1]
print(count1,count2)

Solution (Python):
N,M = map(int,input().split())
P = []
S = []
for _ in range(M):
  p,s = map(str,input().split())
  P.append(int(p))
  S.append(s)
ac = ['WA']*N
wa = [0]*N

for i in range(M):
  if S[i] == 'WA':
    if ac[P[i]-1] == 'WA':
      wa[P[i]-1] += 1
  else:
    ac[P[i]-1] = 'AC'
for j in range(N):
  if ac[j] == 'WA':
    wa[j] = 0
print(ac.count('AC'),sum(wa))

Solution (Python):
N, M = map(int, input().split())
penalty = [0] * N
AC = [False] * N

for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if S == "AC":
        AC[p] = True
    else:
        if not AC[p]:
            penalty[p] += 1

for i in range(N):
    if not AC[i]:
        penalty[i] = 0 

print("{} {}".format(sum(AC), sum(penalty)))

Solution (Python):
n,m=map(int,input().split())
p=[]
s=[]
ac=["WA"]*n
wa=[0]*n
for i in range(m):
	pp,ss=input().split()
	p.append(int(pp))
	s.append(ss)
for i in range(m):
	if s[i]=="AC":
		ac[p[i]-1]="AC"
	else:
		if ac[p[i]-1]=="WA":
			wa[p[i]-1]+=1
for i in range(n):
	if ac[i]=="WA":
		wa[i]=0
print(ac.count("AC"),sum(wa))

Solution (Python):
n, m = map(int, input().split())
ps = [list(map(str, input().split())) for _ in range(m)]

str_l = ['WA'] * n
int_l = [0] * n

for pp, s in ps:
    p = int(pp)-1
    if s == 'AC':
        str_l[p] = 'AC'
    else:
        if str_l[p] != 'AC':
            int_l[p] += 1

num = 0
ac = 0
for i in range(n):
    if str_l[i] == 'AC':
        num += int_l[i]
        ac += 1
print(ac, num)

Solution (Python):
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
pen=0
for i in range(M):
  p,S=input().split()
  if S=="AC":
    A[int(p)-1]=1
  elif S == "WA" and A[int(p)-1] == 0:
    B[int(p)-1] += 1
penalty=[A[i]*B[i] for i in range(N)]
print(sum(A),sum(penalty))

Solution (Python):
n, m = map(int, input().split())
ps = [list(map(str, input().split())) for _ in range(m)]


str_l = ['WA'] * n

int_l = [0] * n

num = 0
ac = 0
for pp, s in ps:
    p = int(pp)-1
    if s == 'AC':
        str_l[p] = 'AC'
    else:
        if str_l[p] != 'AC':
            int_l[p] += 1

for i in range(n):
    if str_l[i] == 'AC':
        num += int_l[i]
        ac += 1

print(ac, num)

Solution (Python):
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
pen=0
for i in range(M):
  p,S=input().split()
  if S=="AC":
    A[int(p)-1]=1
  elif S == "WA" and A[int(p)-1] == 0:
    B[int(p)-1] += 1
penalty=[A[i]*B[i] for i in range(N)]
print(sum(A),sum(penalty))

Solution (Python):
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N, M = rl()
S = []
for i in range(M):
    p, s = rs().split()
    S.append((int(p), s))
ans = 0
pena = 0
penas = [0] * (N+1)
flags = [False] * (N+1)
for p, s in S:
    if flags[p]: continue
    if s == 'AC':
        flags[p] = True
        pena += penas[p]
        ans += 1
    else:
        penas[p] += 1
print(ans, pena)

Solution (Python):
N,M=map(int,input().split())
A=[0]*N
B=[0]*N
pen=0
for i in range(M):
  p,S=input().split()
  if S=="AC":
    A[int(p)-1]=1
  elif S=="WA" and A[int(p)-1]==0:
    B[int(p)-1] += 1
penalty=[A[i]*B[i] for i in range(N)]
print(sum(A),sum(penalty))

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


for ind in range(m):
    p, s = input().split()
    p = int(p)
    if s == "WA" and success[p] == 0:
        penalty[p] += 1
    elif s == "AC":
        success[p] = 1
penalty = [penalty[ind] * success[ind] for ind in range(n+1)]
print("{} {}".format(sum(success), sum(penalty)))

Solution (Python):
n,m = map(int, input().split())
P,S=[],[]
A = {}
ac,wa = 0,0
for i in range(m):
  p,s=input().split()
  P.append(int(p))
  S.append(s)
for i in range(m):
  num = P[i]
  res = A.get(num)[0] if A.get(num)!=None else False
  
  if S[i]=='AC':
    if res==False:
      ac += 1
      A[num] = (True, A.get(num)[1]) if A.get(num)!=None else (True,0)
  else:
    if res==False:
      A[num] = (False,A.get(num)[1]+1) if A.get(num)!=None else (False,1)

for a in A.values():
  if a[0]:
    wa += a[1]
print(ac,wa)

Solution (Python):
n, m = [int(_) for _ in input().split()]
ps_dict = {}
for i in range(m):
    p_, s = input().split()
    p = int(p_)
    if not p in ps_dict.keys():
        ps_dict[p] = [s]
    else:
        ps_dict[p].append(s)

res_ac = 0
res_wa = 0
for k, v in ps_dict.items():
    for i, vi in enumerate(v):
        if vi == 'AC':
            res_ac += 1
            res_wa += i
            break
print(res_ac, res_wa)

Solution (Python):
import sys
input = sys.stdin.readline
n,m = map(int,input().split())
wc = [0]*n
ac = [0]*n
wa = 0
for _ in range(m):
  p,s = input().split()
  if ac[int(p)-1] == 0:
    if s == "AC":
      ac[int(p)-1] = 1
      wa += wc[int(p)-1]
    else:
      wc[int(p)-1] += 1
print("{} {}".format(sum(ac),wa))

Solution (Python):
n,m=map(int,input().split())
ps=[list(input().split()) for i in range(m)]
pen=[0]*n
rig=[0]*n

for i in range(m):
  if ps[i][1] == "AC":
    rig[int(ps[i][0])-1]=1
  else:
    if rig[int(ps[i][0])-1] == 0:
      pen[int(ps[i][0])-1]+=1

cnt1,cnt2=0,0
for i in range(n):
  if rig[i]==1:
    cnt1+=rig[i]
    cnt2+=pen[i]
    
print(str(cnt1)+" "+str(cnt2))

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

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

penalty, clear=0,0
for i,tf in enumerate(ac): 
  if tf:
    penalty += wa[i] 
    clear += 1
print(clear, penalty)

Solution (Python):
import numpy as np
n,m=map(int,input().split())
p=[list(input().split()) for _ in range(m)]
a=[0]*(n+1)
w=[0]*(n+1)
for i in range(m):
    if a[int(p[i][0])]==0 and p[i][1]=='AC':
        a[int(p[i][0])]+=1
    if a[int(p[i][0])]==0 and p[i][1]=='WA':
        w[int(p[i][0])]+=1
a=np.array(a)
w=np.array(w)
aw=a*w
print(sum(a),sum(aw))

Solution (Python):
n, m = map(int, input().split())
p = [0]*m
s = [0]*m
for i in range(m):
    p[i], s[i] = map(str, input().split())
    p[i] = int(p[i])

flag = [0]*n
wa_count_list = [0]*n
wa_count = 0
for i in range(m):
    if s[i] == "WA" and flag[p[i]-1] == 0:
        wa_count_list[p[i]-1] += 1
    elif s[i] == "AC" and flag[p[i]-1] == 0:
        flag[p[i]-1] = 1
    else:
        continue

for i in range(n):
    if flag[i] == 1:
        wa_count += wa_count_list[i]
    else:
        continue

print(flag.count(1), wa_count)

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

penalty, clear=0,0
for i,tf in enumerate(ac):
  if tf:
    penalty += wa[i]
    clear += 1
print('%d %d'%(clear,penalty))

Solution (Python):
N, M = map(int, input().split())
PS = [[x for x in input().split()] for _ in range(M)]
tmp = [0] * (10**5+1)
ac = wa = 0

for P, S in PS:
    if tmp[int(P)]==-1:
        continue
    if S=='WA':
        tmp[int(P)] += 1
    elif S=='AC':
        ac+=1
        wa+=tmp[int(P)]
        tmp[int(P)] = -1
        
print(ac,wa)

Solution (Python):
D=[]
N,M=map(int,input().split())
cnt_ac=0
cnt_wa=0
if M!=0:
  for i in range(M):
    p,S=input().split()
    D.append((int(p),S))
ac=[0]*N
wa=[0]*N
for i in range(M):
  if D[i][1]=="WA" and ac[(D[i][0]-1)]==0:
    wa[(D[i][0]-1)]+=1
  elif D[i][1]=="AC" and ac[D[i][0]-1]==0:
    ac[(D[i][0]-1)]+=1
for i in range(N):
  if ac[i]==1:
    cnt_ac+=1
    cnt_wa+=wa[i]
print(cnt_ac,cnt_wa)

Solution (Python):
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)


args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N, M = input([int, 2])
    PS = input([[str, 2], M])

    ans = {}
    for p, s in PS:
        if not p in ans:
            ans[p] = [0, 0]
        if s == "AC":
            ans[p][0] = 1
        if s == "WA" and ans[p][0] == 0:
            ans[p][1] += 1
    ac, pen = 0, 0
    for v in ans.values():
        if v[0] == 0:
            continue
        ac += 1
        pen += v[1]
    print(ac, pen)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Solution (Python):
n,m = map(int,input().split())
L = [0]*n
AC = 0
WA = 0
tmp = [0]*n
for i in range(m):
	x,y = input().split()
	x = int(x)
	if L[x-1] == 0:
		if y == "WA":
			tmp[x-1] += 1
		else:
			AC += 1
			WA += tmp[x-1]
			L[x-1]=1
print(AC,WA)

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

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

ac = [-1 for _ in range(n)]
wa = [0 for _ in range(n)]
ans_ac = 0
ans_wa = 0
for i in range(m):
	if ps[i][1] == 'WA':
		if ac[ps[i][0]] == -1:
			wa[ps[i][0]] += 1
	else:
		if ac[ps[i][0]] == -1:
			ac[ps[i][0]] = 1
			ans_ac += 1

for i in range(n):
	if ac[i] != -1:
		ans_wa += wa[i]
print(ans_ac,ans_wa)

Solution (Python):
n,m=map(int,input().split())
l1=[list(input().split()) for i in range(m)]
l2=["WA"]*n
l3=[0]*n
account=0
wacount=0
for i in range(m):
  if l1[i][1]=="WA" and l2[int(l1[i][0])-1]=="WA":
    wacount+=1
    l3[int(l1[i][0])-1]+=1
  if l1[i][1]=="AC":
    l2[int(l1[i][0])-1]="AC"

for i in range(n):
  if l2[i]=="AC":
    account+=1
  else:
    wacount-=l3[i]
print(account,wacount)

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

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

Solution (Python):
n,m=map(int,input().split())
a=[0]*(n+1)
b=[0]*(n+1)
for i in range(m):
  p,s=input().split()
  p=int(p)
  if a[p]==0:
      if s=="AC":
        a[p]=1
      else:
        b[p]+=1
for i in range(n+1):
    if a[i]==0:
        b[i]=0
print(sum(a),sum(b))

Solution (Python):


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

ac = {i+1:0 for i in range(N)}
wa = {i+1:0 for i in range(N)}

for p, S in pS:
  p = int(p)
  if S=="AC":
    ac[p] = 1
  if S=="WA" and ac[p]==0:
    wa[p] += 1

wa = {i+1:acv*wav for i,[acv,wav] in enumerate(zip(ac.values(), wa.values()))}

print(sum(ac.values()), sum(wa.values()))

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

ac_count = 0
ac_status = [False]*n
pn_count = 0
wa_count = [0]*n
for i in range(m):
    p,s = input().split()

    if(s == 'AC'):
        if(ac_status[int(p)-1] == False):
            ac_status[int(p)-1] = True
            ac_count = ac_count + 1
            pn_count = pn_count + wa_count[int(p)-1]
    if(s == 'WA'):
        wa_count[int(p)-1] = wa_count[int(p)-1] + 1

print(ac_count, pn_count)

Solution (Python):
n,m=map(int,input().split())
ac=[0]*(n+1)
wa=[0]*(n+1)
for i in range(m):
  p,s=input().split()
  if ac[int(p)]!=1:
    if s=='WA':
      wa[int(p)]=wa[int(p)]+1
    else:
      ac[int(p)]=1
for i in range(n+1):
  if ac[i]==0:
    wa[i]=0
print(sum(ac),sum(wa))

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

submit = []
for i in range(m):
    temp = [x for x in input().split()]
    submit.append(temp)

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

for i in range(m):
    result = submit[i][1]
    question = int(submit[i][0])

    if result == 'AC' and ac[question] == 0:
        ac[question] = 1
    elif result == 'WA' and ac[question] == 0:
        wa[question] += 1

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

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

Solution (Python):
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m = iim()
jud = [False for i in range(n)]
pen = [0 for i in range(n)]

for j in range(m):
    p,s = ism()
    p = int(p) - 1
    if jud[p] == False:
        if s == 'AC':
            jud[p] = True
        elif s == 'WA':
            pen[p] += 1

ans = jud.count(True)
cpn = 0
for k in range(n):
    if jud[k] == True:
        cpn += pen[k]

print(ans,cpn)

Solution (Python):
n,m = map(int,input().split())
p_lists = [list(map(str,input().split())) for _ in range(m)]



AC_count = 0
WA_count = 0

AC_question = set()
WA_question = dict()

for p_list in p_lists:
    if p_list[0] in AC_question:
        continue

    if p_list[1] == 'AC':
        AC_count += 1

        if p_list[0] in WA_question:
            WA_count += WA_question[p_list[0]]

        AC_question.add(p_list[0])

    if p_list[1] == 'WA':
        if p_list[0] in WA_question:
            WA_question[p_list[0]] = WA_question[p_list[0]] + 1
        else:
            WA_question[p_list[0]] = 1

print(AC_count, WA_count)

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

d = {}
d_W = {}

for i in range(1, M+1):
    p, S = list(map(str, input().split()))
    if S == "WA":
        if p not in d_W.keys():
            d_W[p] = 1
        else:
            d_W[p] += 1
    else:
        if p not in d_W.keys():
            d[p] = 0
        elif p not in d.keys():
            d[p] = d_W[p]

print(len(d), sum(d.values()))

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

WA_count = 0
AC_count = 0
Penal = 0
d = {}
d_W = {}

for i in range(1, M+1):
    p, S = list(map(str, input().split()))
    if S == "WA":
        if p not in d_W.keys():
            d_W[p] = 1
        else:
            d_W[p] += 1
    else:
        if p not in d_W.keys():
            d[p] = 0
        elif p not in d.keys():
            d[p] = d_W[p]

    
    
    
    
    
    
    
    
        
        
        
        
        
        
        

print(len(d), sum(d.values()))

Solution (Python):
n,m=map(int,input().split())
ps=[list(input().split()) for i in range(m)]
pen=[0]*n
rig=[0]*n

for i in range(m):
  if ps[i][1] == "AC":
    rig[int(ps[i][0])-1]=1
  else:
    if rig[int(ps[i][0])-1] == 0:
      pen[int(ps[i][0])-1]+=1

cnt1,cnt2=0,0
for i in range(n):
  if rig[i]==1:
    cnt1+=rig[i]
    cnt2+=pen[i]
    
print(str(cnt1)+" "+str(cnt2))

Solution (Python):
import sys
n,m = map(int,input().split())
ma = [list(input().split()) for _ in range(m)]
if len(ma) == 0:
    print(0,0)
    sys.exit()



li = [[False,0,0] for _ in range(n)]



for m in ma:
    ind = int(m[0])-1
    st =  m[1]
    if st == 'WA' and li[ind][0] == False:
        li[ind][2] += 1
    elif st == 'AC' and li[ind][0] == False:
        li[ind][1] += 1
        li[ind][0] = True

ok_count = 0
ng_count = 0
for l in li:
    if l[0]:
        ok_count += l[1]
        ng_count += l[2]
print(ok_count,ng_count)

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

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

for i in range(m):
    a,b=input().split()
    a=int(a)-1
    if not ac[a]:
        if b=="WA":
            wa[a]+=1
        else:
            ac[a]=1
a=0
w=0
for i in range(n):
    if ac[i]:
        a+=1
        w+=wa[i]
print(a,w)

Solution (Python):
import copy
N,M=map(int,input().split())
ans={}
for i in range(M):
    p,S=map(str,input().split())
    ans.setdefault(p,[]).append(S)

ac=0
wa=0

for i in ans.keys():
    wa_count=0
    for j in ans[i]:
        if j=="WA":
            wa_count+=1
        elif j=="AC":
            ac+=1
            wa+=wa_count
            break
print(ac,wa)

Solution (Python):
import sys

n, m = map(int, sys.stdin.readline().split())
pv = []
for _ in range(m):
    p, s = sys.stdin.readline().split()
    p = int(p) - 1
    v = 1 if s == 'AC' else 0
    pv.append((p, v))

def main():
    wa = [0] * n
    ac = [0] * n
    for p, v in pv:
        wa[p] += (ac[p] | v) ^ 1
        ac[p] |= v
    for p in range(n): wa[p] *= ac[p]
    print(sum(ac), sum(wa))

if __name__ ==  '__main__':
    main()

Solution (Python):

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



acdic={}
wadic={}
for i in range(n):
    acdic[i+1]=False
    wadic[i+1]=0

acnum=0
wanum=0
for i in range(m):
    p,s=map(str,input().split())
    p=int(p)
    if s=="AC" and acdic[p]==False :
        acnum+=1
        acdic[p]=True
        wanum+=wadic[p]
    else:
        wadic[p]=wadic[p]+1

print("{0} {1}".format(acnum,wanum))

Solution (Python):

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



acdic={}
wadic={}
for i in range(n):
    acdic[i+1]=False
    wadic[i+1]=0

acnum=0
wanum=0
for i in range(m):
    p,s=map(str,input().split())
    p=int(p)
    if s=="AC" and acdic[p]==False :
        acnum+=1
        acdic[p]=True
        wanum+=wadic[p]
    else:
        wadic[p]=wadic[p]+1

print("{0} {1}".format(acnum,wanum))

Solution (Python):
n, m = map(int, input().split())
list_pS = []
for _ in range(m):
  list_pS.append(input().split())

flag_correct = [False]*(n+1)
count_correct = 0
list_count_pena = [0]*(n+1)
count_pena = 0
for i,ans in enumerate(list_pS):
  if ans[1] == 'AC':
    if not(flag_correct[int(ans[0])]):
      count_correct +=1 
      flag_correct[int(ans[0])] = True
  if ans[1] == 'WA':
    if not(flag_correct[int(ans[0])]):
      list_count_pena[int(ans[0])] +=1

for i,pena in enumerate(flag_correct):
  if flag_correct[i]:
    count_pena += list_count_pena[i]
      
print(count_correct, count_pena)

Solution (Python):
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

n, m = MI()

ac = 0
wa = 0
acp = [False] * (n+1)
wap = [0] * (n+1)
for i in range(m):
    id, result = MS()
    id = int(id)
    if acp[id]:
        continue

    if result == "WA":
        wap[id] += 1
    else:
        acp[id] = True
        ac += 1
        wa += wap[id]

print(ac, wa)

Solution (Python):
def countnumber(l):
  for i in range(l):
    p,s=input().split()
    p=int(p)
    if x[p-1]==0:
      if s=="WA":
        y[p-1]+=1
      else:
        x[p-1]+=1
  X=sum(x)
  Y=0
  for i in range(n):
    if x[i]==1:
      Y+=y[i]
  return X,Y

n,m=map(int,input().split())
x=[0]*n
y=[0]*n
result1,result2=countnumber(m)

print(result1,result2)

Solution (Python):

def myAnswer(N:int,M:int,p:list,S:list) -> None:
   ac = 0
   wa = 0
   dic = {}
   for key,value in zip(p,S):
      if(key in dic.keys()):
         dic[key].append(value)
      else:
         dic[key] = [value]
   for values in dic.values():
      if(("AC" in values)):
         for v in values:
            if(v == "AC"):
               ac+=1
               break
            else:
               wa+=1
   print(ac,wa)

def modelAnswer():
   tmp=1
def main():
   N, M = map(int,input().split())
   p =[]
   S = []
   for _ in range(M):
      tmp = list(map(str,input().split()))
      p.append(tmp[0])
      S.append(tmp[1])
   myAnswer(N,M,p[:],S[:])
if __name__ == '__main__':
   main()

Solution (Python):
n, m = map(int, input().split())
wa = [0]*(n+1)
ac = [0]*(n+1)
for i in range(m):
    p, s = input().split()
    p = int(p)
    if ac[p]:
        continue
    if s == 'WA':
        wa[p] += 1
    else:
        ac[p] = 1

a, b = 0, 0
for c, w in zip(ac, wa):
    if c == 0:
        continue
    a += 1
    b += w
print(a, b)

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

ans = 0
penalty = 0

for i in range(M):
    p, S = input().split()
    if p in solve_problem:
        continue

    if S == 'AC':
        solve_problem.add(p)
        ans += 1
        penalty += WA[int(p)-1]
    if S == 'WA':
        WA[int(p)-1] += 1

print('{} {}'.format(ans, penalty))

Solution (Python):
import math

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

d = {}
for i in range(1, n + 1):
    d[i] = {"AC": False, "WA": 0}

acc, wac = 0, 0
for _ in range(m):
    q, m = input().split(" ")
    q = int(q)

    if not d[q]["AC"]:
        if m == "WA":
            d[q]["WA"] += 1
        elif m == "AC":
            d[q]["AC"] = True
            acc += 1
            wac += d[q]["WA"]

print(acc, wac)

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

ans_num = 0
for i in range(M):
    p,s = input().split()
    p = int(p) - 1
    
    if S[p] < 0 and s=='AC':
        S[p] = -S[p] - 1 
        ans_num+=1
    
    elif S[p] < 0 and s=='WA':
        S[p] -= 1
penalty_num=0
for s in S:
    if s<0:
        continue
    penalty_num += s
print(ans_num, penalty_num)

Solution (Python):
n,m=map(int,input().split())
ac=[0 for i in range(n)]
l=[0 for i in range(n)]
for i in range(m):
    p,s=input().split()
    p2=int(p)
    if s=="AC":
        ac[p2-1]=1
    elif ac[p2-1]==0:
        l[p2-1]+=1
ans1=sum(ac)
ans2=0
for i in range(n):
    if ac[i]>0:
        ans2+=l[i]
print(ans1,ans2)

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

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

sl = set()
ans = 0
pen = 0
WA = [0 for _ in range(N)]
for i in range(M):
    p, S = input().split()
    if p in sl:
        continue

    if S == 'AC':
        ans += 1
        sl.add(p)
        pen += WA[int(p) - 1]
    else:
        WA[int(p) - 1] += 1

print(ans, pen)

Solution (Python):

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

data = {}
ps = [0] * N
ACs = []

num_ac = 0
num_wa = 0


for i in range(M):
    p, S = input().split()
    p = int(p) - 1

    if ps[p] == 0:
        ps[p] = 1
        data[p] = {'AC':0, 'WA':0}

    if S == 'AC' and data[p]['AC'] == 0:
        ACs.append(p)
        data[p]['AC'] += 1
        num_ac += 1
        num_wa += data[p]['WA']

    if S == 'WA' and data[p]['AC'] == 0:
        data[p][S] += 1

print(num_ac, num_wa)

Solution (Python):


n,m=map(int,input().split())
acs=[0]*n
was=[0]*n

for i in range(m):
    p,s=input().split()
    p=int(p)
    if s=="AC":
        acs[p-1]+=1
    else:
        if not acs[p-1]:
            was[p-1]+=1

ac,wa=0,0
for i in range(n):
    if acs[i]:
        ac+=1
        wa+=was[i]

print(ac,wa)

Solution (Python):
n,m = map(int,input().split())
ac = 0
wa = 0
acbox = [0]*(n+1) 
wabox = [0]*(n+1)
for i in range(m):
  p,q = input().split()
  p = int(p)
  if q == "WA":
    if acbox[p] == 0:
      wabox[p] += 1
  else:
    if acbox[p] == 0:
      ac += 1
      wa += wabox[p]
      acbox[p] =+ 1
print(ac,wa)

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

for _ in range(m):
  p, s = input().split()
  if submit.get(p, -1) == -1:
    submit[p] = [0, 0]
  if (submit[p])[0] == 0:
    if s == 'AC':
      (submit[p])[0] += 1
    else:
      (submit[p])[1] += 1
      
ac = 0
wa = 0
for i in submit.values():
  if i[0] > 0:
    ac += i[0]
    wa += i[1]

print(ac, wa)

Solution (Python):
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''
N,M = map(int,input().split())
sub = [ -1 for _ in range(N) ]
penalty = 0
score = 0
for _ in range(M):
	p , s = map(str,input().split())
	p = int(p)
	if s=='WA':
		if sub[p-1]==-1:
			sub[p-1]=1
		elif sub[p-1]>=1:
			sub[p-1]+=1
	elif s=='AC':
		if sub[p-1]==-1:
			score+=1
			sub[p-1]=0
		elif sub[p-1]>=1:
			penalty+=sub[p-1]
			score+=1
			sub[p-1]=0
print(score,penalty)

Solution (Python):
n, m = [int(x) for x in input().split()]

skip_flag = [False] * (n + 1)
wa_count_list = [0] * (n + 1)

ac = 0
wa = 0

for _ in range(m):
    p, s = input().split()
    p = int(p)

    if skip_flag[p]:
        continue

    if s == "AC":
        ac += 1
        wa += wa_count_list[p]
        skip_flag[p] = True
    elif s == "WA":
        wa_count_list[p] += 1

print(ac, wa)

Solution (Python):
n, m = map(int, input().split())
l = [0 for _ in range(n+1)]
ans = 0
penalty = 0
for _ in range(m):
    p, s = input().split()
    p = int(p)
    if l[p] >= 0:
        if s == 'WA':
            l[p] += 1
        else:
            ans += 1
            penalty += l[p]
            l[p] = -1
print(ans, penalty)

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

wa = [0] * N
w = 0
ac = set()
for i in range(M):
    if S[i] == "AC":
        if p[i] in ac:
            pass
        else:
            ac.add(p[i])
            w += wa[p[i] - 1]
    else:
        wa[p[i] - 1] += 1
print(len(ac), w)

Solution (Python):
n, m = map(int, input().split())
l = [0] * n
ac, wa = 0, 0
for i in range(m):
    p, s = input().split()
    p = int(p)
    if l[p - 1] != -1 and s == "AC":
        ac += 1
        wa += l[p - 1]
        l[p - 1] = -1
    if l[p - 1] != -1 and s == "WA":
        l[p - 1] += 1
print(ac, wa)

Solution (Python):
n,m = map(int,input().split())
a = [0]*n
AC,WA=0,0
for i in range(m):
    x,y = input().split()
    x = int(x)
    if a[x-1]!=-1 and y=="WA":
        a[x-1]+=1
    if a[x-1]!=-1 and y=="AC":
        WA+=a[x-1]
        AC+=1
        a[x-1]=-1
print(AC,WA)

Solution (Python):
N, M = map(int, input().split())
P = [0] * 10**5
score, penalty = 0, 0
for i in range(M):
    p, s = map(str, input().split())
    p = int(p)
    if s == 'AC' and P[p-1] != -1:
        penalty += P[p-1]
        score += 1
        P[p-1] = -1
    elif P[p-1] != -1:
        P[p-1] += 1
print(score, penalty)