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())
d = {}
for _ in range(m):
    p,s = input().split()
    try:
        d[int(p)].append(s)
    except:
        d[int(p)] = [s]
T = 0
pe = 0
for key in d:
    if "AC" in d[key]:
        T += 1
        pe += d[key].index("AC")

print(T,pe)

Solution (Python):
n,m = map(int,input().split())
pS = [[i for i in map(str,input().split())] for j in range(m)]
acd = [False for i in range(n)]
WA = [0 for i in range(n)]

for i in range(m):
  if pS[i][1]=="AC":
    acd[int(pS[i][0])-1]=True
  if acd[int(pS[i][0])-1]==False and pS[i][1]=="WA":
    WA[int(pS[i][0])-1] += 1

acds = sum(acd)
WAs = sum([WA[i] for i in range(n) if acd[i]==True])
print(str(acds) + ' ' + str(WAs))

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

p, s = [], []
result = [0] * (n + 1)
wa = [0] * (n + 1)

for _ in range(m):
    tmpp, tmps = map(str, input().split())
    p.append(int(tmpp)), s.append(tmps)

for i in range(m):
    if result[p[i]] == 0:
        if s[i] == "AC":
            result[p[i]] = 1

        else:
            wa[p[i]] += 1

ac = sum(result)
wa = sum(wa[i] for i in range(n + 1) if result[i] == 1)

print(ac, wa)

Solution (Python):
import collections


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

    count = collections.defaultdict(int)
    count_sccess = collections.defaultdict(bool)

    for _ in range(M):
        p, S = input().split()
        p = int(p)

        if S == "WA" and not count_sccess[p]:
            count[p] += 1
        if S == "AC" and not count_sccess[p]:
            count[p] += 0
            count_sccess[p] = True

    ans1 = 0
    ans2 = 0
    for a, b in zip(count, count_sccess):
        if count_sccess[b]:
            ans1 += 1
            ans2 += count[a]

    print(ans1, ans2)


main()

Solution (Python):


from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt
from fractions import gcd

def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas



N, M = mulinputs()
datas = dict()
for i in range(1,N+1):
    datas[i] = []

while True:
    try:
        pi, Si = input().split()
        datas[int(pi)].append(Si)
    except EOFError:
        break

ac_cnt = 0
wa_cnt = 0
for v in datas.values():
    if 'AC' in v:
        ac_cnt += 1
        for judge in v:
            if judge == 'AC':
                break
            wa_cnt += 1

print(ac_cnt, wa_cnt)

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

ls.sort(key=lambda x:int(x[0]))

idx = 1
w=0
a=0
wp=0
for i in range(m):
    if idx<int(ls[i][0]):
        wp = 0
        idx = int(ls[i][0])
    if idx==int(ls[i][0]):
        if ls[i][1]=='WA':
            wp += 1
        else:
            w += wp
            wp = 0
            a += 1
            idx += 1

print(a,w)

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math
import sys
import bisect

mod = 10**9+7
sys.setrecursionlimit(mod) 

def LI(): return list(map(int, sys.stdin.readline().split()))

N, M = LI()
ps = [0 for i in range(M)]
for i in range(M):
    p,s = input().split()
    p = int(p)
    p -= 1
    s = str(s)
    ps[i] = [p,s]


tmp = 0
ans = [[0,0] for i in range(N)] 
for i in range(M):
    p, s = ps[i]
    if ans[p][0]:
        pass
    else:
        if s == "AC":
            ans[p][0] = 1
        else:
            ans[p][1] += 1

anss = [0, 0]
for i in range(N):
    if ans[i][0]:
        anss[0] += 1
        anss[1] += ans[i][1]

print(anss[0], anss[1])

Solution (Python):
def main():
    n,m=map(int,input().split())
    L=[list(input().split()) for _ in range(m)]
    AC=[0]*n
    WA=[0]*n
    for l in L:
        i = int(l[0])-1
        if AC[i]<1:
            if l[1]=='WA':
                WA[i] += 1
            else:
                AC[i]=1
    print(AC.count(1),sum([i*j for i,j in zip(AC,WA)]))
main()

Solution (Python):
n, m = map(int, input().split())
l = [False] * n
res = [0] * n

ac = 0
wa = 0

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

    if(l[p-1]):
        continue
    
    if(s=="AC"):
        l[p-1] = True
        ac += 1
        wa += res[p-1]
        continue

    res[p-1] += 1


print(ac, wa)

Solution (Python):
n,m = map(int,input().split())
ps = []
for i in range(m):
    p,s = input().split()
    ps.append([int(p),s])
ps.sort(key=lambda x:x[0])
d = {}
t = 0
ac = 0
wa = 0

for res in ps:
    if t != res[0]:
        if res[1] == "WA":
            d[res[0]] = d.get(res[0],0) + 1
        else:
            ac += 1
            wa += d.get(res[0],0)
            t = res[0]

print(ac,wa)

Solution (Python):


n,m=map(int,input().split())
ps=[0]*(n+1)
ac=0
wa=0

for i in range(m):
    p,s=input().split()
    p=int(p)
    if ps[p]>0:continue
    if s=='WA':
        ps[p]-=1
    else:
        wa+=-ps[p]
        ps[p]=1
        ac+=1
print(*[ac,wa])

Solution (Python):
n, m = [int(i) for i in input().split()]
wrong_count = [0 for i in range(n)]
correct_count = [0 for i in range(n)]
for i in range(m):
    p, s = input().split()
    if s == 'AC':
        correct_count[int(p)-1] = 1
    elif correct_count[int(p)-1] == 0:
        wrong_count[int(p)-1] += 1
penalty_count = sum([wrong_count[i] for i in range(n) if correct_count[i] == 1])
print(sum(correct_count), penalty_count)

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

nn = [ [0, 0] for i in range(n)]
ps = []
for i in range(m):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        if nn[p - 1][0] == 0:
            nn[p - 1][0] += 1
        else:
            pass
    else:
        if nn[p - 1][0] == 0:
            nn[p - 1][1] += 1
        else:
            pass

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

print(str(ac) + " " + str(wa))

Solution (Python):

n, m = map(int, input().split())
data = [input().split() for i in range(m)]
check = [False] * (n + 1)
tmp_wa = [0] * (n + 1)
ac = 0
wa = 0

for i in range(m):
    if data[i][1] == 'WA':
        if check[int(data[i][0])]:
            continue
        else:
            tmp_wa[int(data[i][0])] += 1
    else:
        if check[int(data[i][0])]:
            continue
        else:
            check[int(data[i][0])] = True
            wa += tmp_wa[int(data[i][0])]
            ac += 1

print('{} {}'.format(ac, wa))

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

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

AC, WA = 0, 0

for q in L:
    tmp_ac = 0
    tmp_wa = 0
    for a in q:
        if a == 'WA':
            tmp_wa += 1
        if a == 'AC':
            tmp_ac += 1
            break
    if tmp_ac == 1:
        AC += 1
        WA += tmp_wa

print(AC, WA)

Solution (Python):
n,m = map(int, input().split())
ac = [0] * n
wa = [0] * n

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

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

print(ans1,ans2)

Solution (Python):
N, M=map(int, input().split())
lst=[input().split() for _ in range(M)]
AC=[False for _ in range(N)]
WA=[0 for _ in range(N)]
for p, S in lst:
  p=int(p)-1
  if S=="AC":
    AC[p]=True
  if S=="WA" and not AC[p]:
    WA[p]+=1
for i in range(N):
  if not AC[i]:
    WA[i]=0
print(sum(AC), sum(WA))

Solution (Python):

N, M=(int(i) for i in input().split())
P=[[int(j)-1  if i==0 else j for i, j in enumerate(input().split())] for  _ in range(M)]
ac="AC"
wa="WA"
flag=[0]*N
ans=0
pe=0

for i in range(M):
    if flag[P[i][0]]!=-1 and P[i][1]==ac:
        ans+=1
        pe+=flag[P[i][0]]
        flag[P[i][0]]=-1
    elif flag[P[i][0]]!=-1 and P[i][1]==wa:
        flag[P[i][0]]+=1
        
print(ans,pe)

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

check = [[] for i in range(n)]

for i in range(m):
    s = int(li[i][0])
    check[s-1].append(li[i][1])
    
for i in range(n):
    if len(check[i]) > 0:
        for j in range(len(check[i])):
            if check[i][j] == "WA":
                ans[1] += 1
            elif check[i][j] == "AC":
                ans[0] += 1
                break
        else:
            ans[1] -= len(check[i])

print(*ans)

Solution (Python):

N, M = map(int, input().split())
P = [ [] for i in range(N+1) ]

wa = 0
ac = 0

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

for i in range(1, N+1):
  tmp_ac = 0
  tmp_wa = 0

  for s in P[i]:
    if s == "WA" and not tmp_ac > 0:
      tmp_wa += 1
    elif s == "AC" and not tmp_ac > 0:
      tmp_ac += 1

  if tmp_ac > 0:
    wa += tmp_wa
    ac += tmp_ac

print(ac, wa)

Solution (Python):
n,m = map(int,input().split())
ps = []
for i in range(m):
    ppss = [i for i in input().split()]
    ps.append(ppss)
ac = [0 for i in range(n)]
wa = [0 for i in range(n)]
for i in range(m):
    if ps[i][1] == 'AC':
        ac[int(ps[i][0])-1] = 1
    else:
        if ac[int(ps[i][0])-1] != 1:
            wa[int(ps[i][0])-1] += 1
for i in range(n):
    if ac[i] != 1:
        wa[i] = 0
print(sum(ac),sum(wa))

Solution (Python):
n_m = list(map(lambda x: int(x), input().split(" ")))
N = n_m[0]
M = n_m[1]

result_dict = {}

for i in range(M):
    p_s = input().split(" ")
    P = int(p_s[0])
    S = p_s[1]
    if P in result_dict:
        if result_dict[P][0] == 1:
            continue
        elif S == "AC":
            result_dict[P][0] = 1
        else:
            result_dict[P][1] += 1
    else:
        if S == "AC":
            result_dict[P] = [1, 0]
        else:
            result_dict[P] = [0, 1]

ac_count = 0
wa_count = 0
for v in result_dict.values():
    if v[0] == 0:
        continue
    ac_count += 1
    wa_count += v[1]

result = "{} {}".format(ac_count, wa_count)
print(result)

Solution (Python):
n1,m1 = map(int,input().split())
dic = [0 for i in range(n1)]
se = set()
for i in range(m1):
    n,m = input().split()
    if n not in se and m == "WA":
        dic[int(n)-1] += 1
    else:
        se.add(n)
print(len(se),sum([dic[int(i)-1] for i in se]))

Solution (Python):
N, M = map(int, input().split())
P = []
S = []
T = [0 for i in range(N)]
U = [0 for i in range(N)]
ACs = 0
WAs = 0
for i in range(M):
  p, s = input().split()
  p = int(p)
  P.append(p)
  S.append(s)
for i in range(M):
  if S[i] == "AC":
    if U[P[i]-1] != 1:
      U[P[i]-1] += 1
      ACs += 1
      WAs += T[P[i]-1]
  else:
    T[P[i]-1] += 1
print(ACs, WAs)

Solution (Python):
import numpy as np
N, M =[int(i) for i in input().split()]
isfinish=[0]*N
isfail=[0]*N
for i in range(M):
    p, S = input().split()
    p=int(p)
    if isfinish[p-1]==1:
        continue
    elif S=="AC" and isfinish[p-1]==0:
        isfinish[p-1] = 1
    elif S=="WA" and isfinish[p-1]==0:
        isfail[p-1] +=1

isfinish=np.array(isfinish)
isfail=np.array(isfail)
print(str(sum(isfinish)) + " "+ str(sum(isfail[isfinish==1])))

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

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

for i in range(m):
    if que[p[i]] == False:
        if s[i] == "WA":
            wan[p[i]] += 1
        else:
            que[p[i]] = True

for i in range(len(que)):
    if que[i] == True:
        ac += 1
        wa += wan[i]

print(ac,wa)

Solution (Python):
n, m = map(int, input().split())
p = []
s = []
for i in range(m):
    pp, ss = input().split()
    p.append(int(pp) - 1)
    s.append(ss)

acs = [0] * n
was = [0] * n
for i in range(m):
    if s[i] == 'AC':
        acs[p[i]] = 1
    else:
        if acs[p[i]] == 0:
            was[p[i]] += 1
for i in range(n):
    if acs[i] == 0:
        was[i] = 0
print("{} {}".format(sum(acs), sum(was)))

Solution (Python):

n, m = map(int,input().split())
plst = []
result = []
for _ in range(m):
    p, s = input().split()
    p = int(p)
    plst.append(p)
    result.append(s)
rui = list(set(plst))
tmps = [[] for _ in range(len(rui))]
dic = dict(zip(rui, tmps))

for p, s in zip(plst, result):
    dic[p].append(s)

ac = 0
wa = 0

for item in dic.values():
    if 'AC' in item:
        ac += 1
        for l in item:
            if l == 'AC':
                break
            else:
                wa += 1
print(ac, wa)

Solution (Python):
n,m=map(int,input().split())
x=[list(input().split()) for i in range(m)]
a=0
p=0
x.sort(key=lambda x:x[0])
t='a'
for i in range(m):
  if t!=x[i][0]:
    w=0
    t=x[i][0]
    f=1
  if f:
    if x[i][1]=='AC':
      a+=1
      p+=w
      f=0
    else:
      w+=1
print(a,p)

Solution (Python):
n,m=map(int,input().split())
a=[]
for i in range(m):
    x,y=input().split()
    a.append([int(x),y])
check=[False]*n
ans=[0]*n
for i in a:
    if check[i[0]-1]==True:
        continue
    else:
        if i[1]=="AC":
            check[i[0]-1]=True
        else:
            if check[i[0]-1]!=True:
                ans[i[0]-1]+=1
total=0
for i in range(n):
    if check[i]==True:
        total+=ans[i]
print(check.count(True),total)

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

p = [0] * M
k = [""] * M

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

ans = [0]*N
pen = [0]*N
accept = 0
pena = 0
for i in range(M):
    if k[i] == "WA" and ans[p[i]] == 0:
        pen[p[i]] += 1
    elif k[i] == "AC" and ans[p[i]] == 0:
        pena += pen[p[i]]
        ans[p[i]] = 1
        accept += 1
        
print(str(accept) + " " + str(pena))

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

n_list=[0]*N
p_list=[0]*N

ac_cnt=0
wa_cnt=0


for i in range(M):
    p,S=input().split()
    p=int(p)
    if S=="WA":
        p_list[p-1]+=1
    else:
        if n_list[p-1]==0:
            n_list[p-1]=1
            ac_cnt+=1
            wa_cnt+=p_list[p-1]

print(ac_cnt,wa_cnt)

Solution (Python):

import re
import math




n,m=map(int,input().split())
MAP={}
PS=[]
for a in range(m):
    s,t=input().split()
    if(not s in MAP):MAP[s]=[]
    MAP[s].append(t)
ac=0
wa=0
for a,b in MAP.items():
    if(not "AC" in MAP[a]):continue
    for c in b:
        if(c=="WA"):
            wa+=1
        else:
            ac+=1
            break
print(ac,wa)

Solution (Python):
N, M = map(int, input().split())
isAC = [0]*N
ac = 0
WA = [0]*N
for _ in range(M):
    p, s = input().split()
    p = int(p)
    if not isAC[p-1]:
        if s == 'AC':
            isAC[p-1] = 1
            ac += 1
        else:
            WA[p-1] += 1
    
wa = sum([i*j for i, j in zip(isAC, WA)])
print(ac, wa)

Solution (Python):
from math import factorial
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def MS(): return map(str, input().split())

YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']



show_flg = True

p = None
XY = None
N = None


def main():
    N, M = MI()
    ans = 0
    p = [0] * M
    S = [0] * M
    dic = {}
    

    for i in range(M):
        p[i], S[i] = MS()
        dic[p[i]] = {'AC': False, 'WA': 0}

    for i in range(M):
        if S[i] == 'WA' and dic[p[i]]['AC'] is False:
            dic[p[i]]['WA'] += 1
        elif S[i] == 'AC':
            dic[p[i]]['AC'] = True

    AC = 0
    WA = 0
    for key in dic.keys():
        if dic[key]['AC']:
            AC += 1
            WA += dic[key]['WA']

    print(AC, WA)


if __name__ == '__main__':
    main()

Solution (Python):
n,m=map(int,input().split())
p=[]
s=[]
for i in range(m):
	P,S=input().split()
	P=int(P)-1
	p.append(P)
	s.append(S)

wa=[0 for i in range(n)]
ac=[0 for i in range(n)]
for i in range(m):
	if s[i]=="AC":
		ac[p[i]]+=1
	else:
		if ac[p[i]]==0:
			wa[p[i]]+=1

sum_ac=0
pena=0
for i in range(n):
	if ac[i]!=0:
		sum_ac+=1
		pena+=wa[i]
print(sum_ac,end=' ')
print(pena)

Solution (Python):
n,m = map(int, input().split())
flag = [False] * (10**5 + 100)
wa = [0] * (10**5 + 100)
for i in range(m):
    p, s = map(str, input().split())
    p = int(p)

    if flag[p] == False:
        if s == "AC":
            flag[p] = True
        else:
            wa[p] += 1

ans = 0
for i in range(10**5+1):
    if flag[i]:
        ans += wa[i]
print(sum(flag), ans)

Solution (Python):


import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    wa_list = [0] * N
    penalty = 0
    ac = 0
    for _ in range(M):
        p, S = i2s().split(' ')
        p = int(p) - 1
        if wa_list[p] >= 0:
            if S == 'WA':
                wa_list[p] += 1
            else:
                penalty += wa_list[p]
                wa_list[p] = -1
                ac += 1
    print(ac, penalty)
    return

main()

Solution (Python):
N,M=map(int,input().split())
seiseki=[[0]*N for _ in range(2)]
for i in range(M):
  p,S=input().split()
  p=int(p)
  if seiseki[1][p-1]==0:
    if S=='WA':
      seiseki[0][p-1]+=1
    else:
      seiseki[1][p-1]=1
AC=sum(seiseki[1])
WA=0
for i in range(N):
  if seiseki[1][i]==1:
    WA+=seiseki[0][i]
print(AC,WA)

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

no,prob=[0]*n,[-1]*n
for i in range(m):
  p,s=int(PS[i][0]),PS[i][1]
  if s=='AC': prob[p-1]=1
  if s=='WA' and prob[p-1]==-1: no[p-1]+=1
pena,ans=0,0
for i,p in enumerate(prob):
  if p==1:
    pena+=no[i]
    ans+=1
print(ans,pena)

Solution (Python):
n,m=input().strip().split(" ")
n,m=[int(n),int(m)]
f=[0 for _ in range(n+1)]
f1=[0 for _ in range(n+1)]
for i in range(m):
    a,b=input().strip().split(" ")
    a,b=[int(a),str(b)]
    if b=="AC":
        f[a]=1
    elif b=="WA":
        if f[a]==0:
            f1[a]+=1
su=0
for i in range(n+1):
    if f[i]==1:
        su+=f1[i]
print(sum(f),su)

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

lac = [0] * (n+1)
lwa = [0] * (n+1)

for i in range(m):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        lac[p] += 1
    else:
        if lac[p] == 0:
            lwa[p] += 1

ans = 0
pnl = 0

for i in range(1, n+1):
    if lac[i] > 0:
        ans += 1
        pnl += lwa[i]

print("{} {}".format(ans, pnl))

Solution (Python):
def main():
  N, M = map(int, input().split())
  
  correct = [0] * N
  penalty = [0] * N
  pena = 0
  
  for _ in range(M):
    pi, si = input().split()
    pi = int(pi)
    
    if si == 'WA' and correct[pi-1] == 0:
      penalty[pi-1] += 1
    elif si =='AC' and correct[pi-1] == 0:
      correct[pi-1] = True
      pena += penalty[pi-1]

  print(sum(correct), pena)       

main()

Solution (Python):
N,M = map(int,input().split())
PS = [list(input().split()) for _ in range(M)]
l = [False]*N
k = [False]*N
for p,s in PS:
  p=int(p)
  if s=='AC':
    k[p-1]=True
pena = 0
for p,s in PS:
  p = int(p)
  if s=='AC':
    if not l[p-1]:
      l[p-1]=True
  if s=='WA':
    if (not l[p-1])and(k[p-1]):
      pena+=1
      
ans = sum(l)
print(ans,pena)

Solution (Python):
n, m = map(int, input().split())
good = [0] * n
pena = [0] * n
for i in range(m):
	pi, si = map(str, input().split())
	pi = int(pi)
	if si == "AC":
		good[pi - 1] = 1
	elif si == "WA" and good[pi - 1] == 0:
		pena[pi - 1] += 1

sum_good = 0
sum_pena = 0
for i in range(n):
	if good[i] >= 1:
		sum_good += 1
		sum_pena += pena[i]

print(sum_good, sum_pena)

Solution (Python):
N,M = map(int,input().split())
ps = [input().split() for i in range(M)]
from collections import defaultdict
acs = set()
penas = defaultdict(lambda: 0)
for p,s in ps:
    if p in acs: continue
    if s=='AC':
        acs.add(p)
    else:
        penas[p] += 1

pena = 0
for p in acs:
    pena += penas[p]
print(len(acs), pena)

Solution (Python):

N, M = map(int, input().split())
flags = [0] * (N+1)
submit_count = [0] * (N+1)
true_answer = 0
penalty = 0

for _ in range(M):
    pi, Si = input().split()
    pi = int(pi)
    if Si == "AC":
        if flags[pi] == 0:
            flags[pi] = 1
            true_answer += 1
            penalty += submit_count[pi]
        else:
            pass
    else:
        if flags[pi] == 0:
            submit_count[pi] += 1
        else:
            pass
        
print(true_answer, penalty)

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

result_AC = [False]*N 
correct_num = 0
penalty_num = 0
penalty_list = [0]*N

for _ in range(0, M):
  p, S = input().split(" ")
  p = int(p) - 1
  
  if(result_AC[p]):
    continue
  
  else:
    
    if S == 'AC':
      result_AC[p] = True
      correct_num += 1
      penalty_num += penalty_list[p]
    
    else:
      penalty_list[p] += 1

print(correct_num, penalty_num)

Solution (Python):
import sys
sys.setrecursionlimit(4100000)

import math

import logging

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


def resolve():
    N, M = [int(x) for x in sys.stdin.readline().split()]
    pS_list = [[x for x in sys.stdin.readline().split()] for _ in range(M)]

    aced_list = [False for _ in range(N)]
    penal_list = [0 for _ in range(N)]
    for p, s in pS_list:
        p = int(p) - 1
        if s == 'AC':
            aced_list[p] = True
        else:
            if not aced_list[p]:
                penal_list[p] += 1

    for i in range(N):
        if not aced_list[i]:
            penal_list[i] = 0

    print(sum(aced_list), sum(penal_list))


if __name__ == "__main__":
    resolve()




import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 5
1 WA
1 AC
2 WA
2 AC
2 WA"""
        output = """2 2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """100000 3
7777 AC
7777 AC
7777 AC"""
        output = """1 0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """6 0"""
        output = """0 0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """2 5
1 WA
1 AC
2 WA
2 WA
2 WA"""
        output = """1 1"""
        self.assertIO(input, output)

Solution (Python):

import sys 
input = sys.stdin.readline

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

penalties=[0]*N
penalty=0
flag=[True]*N
for i in range(M):
    if flag[p[i]]:
        if S[i] == "WA":
            penalties[p[i]] += 1
        else:
            flag[p[i]] = False

corrects = 0
for i in range(N):
    if not flag[i]:
        corrects += 1
        penalty += penalties[i]

print(corrects)
print(penalty)

Solution (Python):

import sys


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    x = [0] * N

    ac = 0
    wa = 0

    for i in range(M):
        if x[p[i]-1] >= 0:
            if S[i] == "AC":
                ac += 1
                wa += x[p[i]-1]
                x[p[i]-1] = -1
            else:
                x[p[i]-1] += 1
    print(ac, wa)


    return



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())
ac=[0 for i in range(n+1)]
wa=[0 for i in range(n+1)]
for i in range(m):
    s,t=input().split()
    if t=="WA":
        if ac[int(s)]==0:
            wa[int(s)]+=1
    else:
        if ac[int(s)]==0:
            ac[int(s)]+=1
s=0
for i in range(n+1):
   s+=ac[i]*wa[i]
print(str(sum(ac))+" "+str(s))

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

myAC = [0 for n in range(N+1)]
myWA = [0 for n in range(N+1)]

ansAC = 0
ansWA = 0


for m in range(M):
    a,  b = map(str, input().split())
    a = int(a)
    if b == 'WA' and myAC[a] != 1:
        myWA[a] += 1
        
    if b == 'AC' and myAC[a] != 1:
        myAC[a] = 1
        ansWA += myWA[a]
        ansAC += 1



print(ansAC,ansWA)

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


def main():
    N, M = map(int, input().split())
    ps = []
    for i in range(M):
        p, s = input().split()
        ps.append((int(p), s))
    ac = [0]*(10**5)
    pena = [0]*(10**5)
    for p, s in ps:
        if s == "WA":
            if ac[p] == 0:
                pena[p] += 1
        if s == "AC":
            ac[p] = 1
    p = 0
    for i in range(len(ac)):
        if ac[i] == 1:
            p += pena[i]
    print(ac.count(1), p)


if __name__ == '__main__':
    main()

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

Solution (Python):
n, m = map(int, input().split())
ps = [list(input().split()) for _ in range(m)]
ps.sort(key=lambda x: x[0])

correct, penalty = 0, 0
last_c, is_solved = 1, False
tmp_pen = 0
for ps_i in ps:
  p, s = ps_i
  if (p != last_c):
    tmp_pen = 0
    is_solved = False
    last_c = p
    if (is_solved):
      continue
    elif (s == "WA"):
      tmp_pen += 1
    else:
      correct += 1
      penalty += tmp_pen
      is_solved = True
  else:
    if (is_solved):
      continue
    elif (s == "WA"):
      tmp_pen += 1
    else:
      correct += 1
      penalty += tmp_pen
      is_solved = True
print(correct, penalty)

Solution (Python):

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

cnt_ac = 0
cnt_wa = 0
ac_set = set()
wa_dict = dict()

for i in range(m):
    str_list = input().split()
    p = int(str_list[0])
    s = str_list[1]
    if p not in ac_set:
        if s == 'AC':
            cnt_ac = cnt_ac + 1
            if p in wa_dict:
                cnt_wa = cnt_wa + wa_dict[p]
            ac_set.add(p)
        else:
            if p in wa_dict:
                wa_dict[p] = wa_dict[p] + 1
            else:
                wa_dict[p] = 1

print(str(cnt_ac) + ' ' + str(cnt_wa))

Solution (Python):
n,m=map(int,input().split())
d={}
for i in range(m):
    p,s=map(str,input().split())
    if p not in d:
        d[p]=[s,1]
    elif d[p][0]=="WA":
        d[p][0]=s
        d[p][1]+=1
ans=[0,0]
for i in d:
    if d[i][0]=="AC":
        ans[0]+=1
        ans[1]+=d[i][1]-1
print(*ans)

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

ans_ac = 0
ans_wa = 0
flag = 0
number = 0
ok = ["n" for i in range(n)]
count_wa = [0 for i in range(n)]
count = 0
for i in range(m):
    if ok[int(ps[i][0])-1] == "n":
        if ps[i][1] == "WA":
            count_wa[int(ps[i][0])-1] += 1
        else:
            ans_ac += 1
            ans_wa += count_wa[int(ps[i][0])-1]
            ok[int(ps[i][0])-1] = "OK"
 
 
    
print(ans_ac,ans_wa)

Solution (Python):
import sys
input = sys.stdin.readline
N, M = [int(x) for x in input().split()]
p = []
S = []
for _ in range(M):
    temp = input().rstrip().split()
    p.append(int(temp[0]))
    S.append(temp[1])
dic = {}
for i in range(N):
    dic[i + 1] = []
for i, j in zip(p, S):
    dic[i].append(j)
AC = 0
WA = 0
for k in dic.keys():
    temp = dic[k]
    WA_count = 0
    for j in temp:
        if j == "WA":
            WA_count += 1
        else:
            AC += 1
            WA += WA_count
            break
print(AC, WA)

Solution (Python):
N,M = map(int,input().split())
pS = [list(input().split()) for _ in range(M)]
lis = [0]*N
pena = [0]*N
for p,S in pS:
    p = int(p)-1
    if S == "AC":
        lis[p] = 1
    else:
        if lis[p] == 0:
            pena[p] += 1
pe = 0
for i in range(N):
    if lis[i]:
        pe += pena[i]

print(sum(lis), pe)

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

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

for i in range(len(PSs)):
    PSs[i][0] = int(PSs[i][0])

is_ac = [False for i in range(n)]

ac = int()
wa = [0 for i in range(n)]
for i in range(len(PSs)):
    if PSs[i][1] == 'AC' and not is_ac[PSs[i][0]-1]:
        ac += 1
        is_ac[PSs[i][0]-1] = True
    
    if PSs[i][1] == 'WA' and is_ac[PSs[i][0]-1] == False:
        wa[PSs[i][0]-1] += 1





pen = int()
for i in range(n):
    if is_ac[i] == True:
        pen += wa[i]
        

print(ac, pen)