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 WAs 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



Sample input:
2 5
1 WA
1 AC
2 WA
2 AC
2 WA


Sample output:
2 2

Submission status: Accepted

Solution code:
nm = list(map(int, (input().split())))
if nm[1] == 0:
    print(0, 0)

else:    
    ans_dict = {}
    ans_list = [input().split() for i in range(nm[1])]
    for i in range(len(ans_list)):
        key_val = ans_list[i][0]

        try:
            ans_dict[key_val].append(ans_list[i][1])
        except:
            ans_dict[key_val] = [ans_list[i][1]]
    ans_cnt = 0
    wa_cnt = 0
    for key_val in ans_dict.keys():
        check_list = ans_dict[key_val]

        if "AC" in check_list:
            ans_cnt += 1
        else:
            pass
        try:
            wa_cnt += len(check_list[:check_list.index("AC")])
        except:
            pass
    print(ans_cnt, wa_cnt)

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int, input().split())
record = np.zeros(n)
penalty = np.zeros(n)
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if record[p]:
        continue
    else:
        if s == "AC":
            record[p] = 1
        elif s == "WA":
            penalty[p] += 1

ans1 = int(sum(record))
ans2 = int(np.dot(record, penalty))
print(ans1, ans2)

Submission status: Accepted

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

p = [0]*(n+1)
q = [False]*(n+1)

for _ in range(m) :
  v,s = input().split()
  v = int(v)
  if q[v] : continue
  if s[0] == 'A' : q[v] = True
  else : p[v] += 1

print(sum(q), sum(p[i] for i in range(n+1) if q[i]))

Submission status: Accepted

Solution code:
import sys
from functools import reduce

n, m = map(int, input().split())
ps = [r.split() for r in sys.stdin.read().split('\n') if r != '']
log = []
for i in range(0, n):
    log.append([])
for j in range(0, m):
    i = int(ps[j][0])
    log[i-1].append(ps[j][1])
wacount = sum(map(lambda l: l.index('AC'), filter(lambda e: e.count('AC') > 0, log)))
print(len(list(filter(lambda e: e.count('AC') > 0, log))),
        wacount)

Submission status: Accepted

Solution code:
N, M = [int(num) for num in input().split(' ')]

ans = [0 for i in range(N)]
done = [False for i in range(N)]

suc = 0

for j in range(M):
	# p is 0 indexed
	p, S = [num for num in input().split(' ')]
	p = int(p)
    
	if done[p-1] == False:
		if S == 'AC':
			done[p-1]=True
			suc+=1
		else:
			ans[p-1]+=1
	else: # done[p-1] == True
		if S == 'AC':
			pass
		else:
			pass

pen = 0
for i, ans_i in enumerate(ans):
	if done[i]==True: pen+=ans_i

print('{} {}'.format(suc, pen))

Submission status: Accepted

Solution code:
import numpy as np
N,M=map(int,input().split())
A=[]
for i in range(M):
  A.append(tuple(map(str,input().split())))
check=np.zeros((N,2))
for i in range(M):
  if check[int(A[i][0])-1,0]==0:
    if A[i][1]=='WA':
      check[int(A[i][0])-1,1]+=1
    elif A[i][1]=='AC':
      check[int(A[i][0])-1,0]+=1
for i in range(N):
  if check[i,0]==0:
    check[i,1]=0
sum=check.sum(axis=0)
print(int(sum[0]),int(sum[1]))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
AC=[0]*(N+1)
WA=[0]*(N+1)
W=0
A=0
for i in range(M):
    p,s=input().split()
    p=int(p)
    if AC[p]==0:

        if s=='WA':
            WA[p]+=1

        else:
            AC[p]=1
            A+=1

for i in range(N+1):
    if AC[i]==1:
        W+=WA[i]
print(A,W)

Submission status: Accepted

Solution code:
N ,M = map(int, input().split())
ps = [list(input().split()) for i in range(M)]

ac = [0 for i in range(N)]
wa = [0 for i in range(N)]

for i in range(M):
    s = int(ps[i][0])-1
    if ps[i][1] == "WA" and ac[s] == 0:
        wa[s] += 1

    if ps[i][1] == "AC" and ac[s] == 0:
        ac[s] = 1

for i in range(N):
    if ac[i] == 0:
        wa[i] = 0

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

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    ans = [False for _ in range(N)]
    wa_list = [0 for _ in range(N)]
    ac = 0
    wa = 0
    for _ in range(M):
        i, result = input().split()
        i = int(i)
        if result == "AC":
            if ans[i-1] == False:
                ac += 1
                ans[i - 1] = True
                wa += wa_list[i-1]
        else:
            if ans[i - 1] == False:
                wa_list[i - 1] += 1
    if sum(ans) == 0:
        wa = 0
    print(ac, wa)
    return 0
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m = map(int, input().split(' '))
problem = [0] * n
ok=0
pen=0
i=0

while i < m:
    p, result = input().split(' ')
    p = int(p) - 1
    if problem[p] < 0:
        pass
    else:
        if result == 'WA':
            problem[p] += 1
        else:
            ok += 1
            pen += problem[p]
            problem[p] = -1
    i+=1
print('{} {}'.format(ok, pen))

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split(' ')))
AC_total = 0
WA_total = 0
ac_list = [False] * N
wa_list = [0] * N
for i in range(M):
    p, s = input().split(' ')
    p = int(p) - 1
    if not ac_list[p]:
        if s == 'WA':
            wa_list[p] += 1
        else:
            AC_total += 1
            WA_total += wa_list[p]
            ac_list[p] = True
print('{} {}'.format(AC_total, WA_total))

Submission status: Accepted

Solution code:
import sys
from functools import reduce

n, m = map(int, input().split())
ps = [r.split() for r in sys.stdin.read().split('\n') if r != '']
ps.sort(key=lambda t: int(t[0]))
log = []
for i in range(0, n):
    log.append([])
for j in range(0, m):
    i = int(ps[j][0])
    log[i-1].append(ps[j][1])
wacount = sum(map(lambda l: l.index('AC'), filter(lambda e: e.count('AC') > 0, log)))
print(len(list(filter(lambda e: e.count('AC') > 0, log))),
        wacount)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
p = [0]*M
S = [0]*M
for i in range(M):
    p[i],S[i] = input().split()
q = [int(s)-1 for s in p]
X = [0]*N
Y = [0]*N
A = 0
B = 0
for i in range(M):
    if S[i] == "AC":
        if Y[q[i]]==0:
            Y[q[i]]+=1
            A += 1
            B += X[q[i]]
    else:
        if Y[q[i]]==0:
            X[q[i]] += 1
print(str(A)+" "+str(B))

Submission status: Accepted

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

list = [True for i in range(n)]
cnt = [0 for i in range(n)]
for i in range(m):
	tmp, s = input().split()
	p = int(tmp)
	if s == "AC":
		list[p-1] = False
	elif s == "WA":
		if list[p-1]:
			cnt[p-1] += 1

for i in range(n):
	if list[i]:
		cnt[i] = 0

print(list.count(False), sum(cnt))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
p = []
s = []
ac = [0 for i in range(n)]
wa = [0 for i in range(n)]
for i in range(m):
    p_i,s_i = input().split()
    if ac[int(p_i)-1] == 0:
        if s_i == "WA":
            wa[int(p_i)-1] += 1
        elif s_i == "AC":
            ac[int(p_i)-1] += 1
for i in range(n):
    if ac[i] == 0 and wa[i] > 0:
        wa[i] = 0
print(sum(ac),sum(wa))

Submission status: Accepted

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


    cntA = 0
    cntW = 0
    for i,a in enumerate(p):
        flg = 0
        cnt=0
        for j,s in enumerate(a):
            if  s == 'WA':
                cnt += 1
            elif s == 'AC':
                cntA += 1
                cntW+=cnt
                break
    print(str(cntA) + ' ' + str(cntW))
    # print(cntA)
    # print(cntW)
if __name__=='__main__':
    main()

Submission status: Accepted

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

acList = [False] * n
waList = [0] * n
waCount = 0
for i in range(m):
  p, s = map(str, input().split())
  p = int(p) - 1 # インデックスの調整
  if acList[p]:
    continue
  if s == 'WA':
    waList[p] += 1
    continue
  waCount += waList[p]
  acList[p] = True

print(sum(acList), waCount)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
penas = [0] * N
acs, pena = set(), 0
for _ in range(M):
    p, stat = input().split()
    p = int(p) - 1
    if stat == "AC" and p not in acs:
        acs.add(p)
        pena += penas[p]
    else:
        penas[p] += 1
print(len(acs), pena)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
pis=[]
wa,ac={},{}
for i in range(M):
    p  = input().split()
    pis += [(int(p[0]),p[1])]
for p in pis:
    wa[p[0]]=0
    ac[p[0]]=0
if __name__ == '__main__':
   for p in pis:
      if ac[p[0]]<1:
         if p[1]=='WA':
              wa[p[0]]+=1
         elif p[1]=='AC':
              ac[p[0]]=1
   for p in pis:
      if ac[p[0]]<1:
        wa[p[0]]=0
   a=sum(ac.values())
   w=sum(wa.values())
   print('{} {}'.format(a,w))

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline()[:-1]

N,M = map(int,input().split(' '))
L = []
for i in range(M):
    L.append(list(map(str, input().split())))
VISITED = [0]*N
AC = 0
p = 0
for i in range(M):
    n,s = L[i]
    n = int(n) - 1
    if VISITED[n]==-1:
        continue
    if s=='AC':
        p += VISITED[n]
        VISITED[n] = -1
        AC += 1
    else:
        VISITED[n] += 1
print(AC,p)

Submission status: Accepted

Solution code:
n,m=[int(x) for x in input().split()]
right=[0]*(n+1)
wrong=[0]*(n+1)
d=dict()
pnt=0
crt=0
for i in range(0,m):
    a,v=[x for x in input().split()]
    a=int(a)
    if right[a]==0:
        if v=='AC':
            right[a]=1
            pnt+=wrong[a]
            crt+=1
        else:
            wrong[a]+=1

print(crt,pnt)

Submission status: Accepted

Solution code:

import numpy as np
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))


N,M=acinput()
d=[[]for i in range(N+1)]
for i in range(M):
    p, s = input().split(" ")
    p=int(p)
    d[p].append(s)

#d=sorted(d,key=lambda x:x[1])

pen=0

nsolve=0
for sd in d:
    #ssd=sorted(sd)
    #print(sd)
    pem_tmp = 0
    for ssd in sd:
    
        if ssd=="AC":
            nsolve+=1
            pen+=pem_tmp
            break
        else:
            pem_tmp+=1

print(nsolve,pen)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
s,p = [False]*N, [0]*N
for i in range(M):
  tmp = input().split()
  pi,Si = int(tmp[0])-1, tmp[1]
  s[pi] |= Si == "AC"
  p[pi] += 1 if not s[pi] else 0
print(sum(s), sum([pi for si,pi in zip(s,p) if si]))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = {}
ac = 0
wa = 0
flag = False
for i in range(M):
    p, s = input().split()
    if p not in ans:
        if s == "AC":
            ans[p] = []
            ans[p].append("AC")
        else:
            ans[p] = []
            ans[p].append("WA")
    else:
            if s == "WA":
                ans[p].append("WA")
            elif s == "AC":
                ans[p].append("AC")
for val in ans.values():
    count = 0
    for i in val:
        if flag != True:
            if i == "WA":
                count += 1
            if i == "AC":
                ac += 1
                wa += count
                flag = True
    flag = False
print(ac, wa)

Submission status: Accepted

Solution code:
import collections
n, m = [int(i) for i in input().split()]
ps = [[i for i in input().split()] for _ in range(m)]

fails = collections.defaultdict(int)
acstatus = collections.defaultdict(bool)

successct, failct = 0,0
for p, s in ps:
    if s == "AC":
        if not acstatus[p]:
            failct += fails[p]
            acstatus[p] = True
            successct += 1
    else:
        fails[p] += 1
print(successct, failct)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
scores = []
for _ in range(m):
    num, r = input().split()
    scores.append([num, r])

answers = [0] * (n + 1)
penalties = [0] * (n + 1)
ac = set()
for num, r in scores:
    n = int(num)
    if r == 'AC':
        answers[n] = 1
        ac.add(n)
    elif r == 'WA' and answers[n] == 0:
        penalties[n] += 1

ans = sum(answers)
p = 0
for a in ac:
    p += penalties[a]

print(ans, p)

Submission status: Accepted

Solution code:
n, m = map(int, input().split(" "))
nac = 0
npe = 0
cp = 0
is_ac = [False]*n
np_list = [0]*n
for i in range(m):
  p_s, s = input().split(" ")
  p = int(p_s)-1
  cis_ac = is_ac[p]
  
  if cis_ac:
    continue
  if s == "AC":
    nac += 1
    is_ac[p]=True
  else:
    np_list[p] += 1

for i, a in enumerate(is_ac):
  if a:
    npe += np_list[i]
print(str(nac)+" "+str(npe))

Submission status: Accepted

Solution code:
n, m = map(int, input().split(' '))
problem = [0] * n
ok=0
pen=0
i=0

while i < m:
    p, result = input().split(' ')
    p = int(p) - 1
    if problem[p] < 0:
        pass
    else:
        if result == 'WA':
            problem[p] += 1
        else:
            ok += 1
            pen += problem[p]
            problem[p] = -1
    i+=1
print('{} {}'.format(ok, pen))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
qaw = [[0,0] for i in range(n)]
x = 0
y = 0
for i in range(m):
  p,s = input().split()
  p = int(p)-1
  if s == "AC":
    qaw[p][0] = 1
  elif qaw[p][0] == 0:
    qaw[p][1] += 1
for q in qaw:
  if q[0] == 1:
    x += 1
    y += q[1]
print(x,y)

Submission status: Accepted

Solution code:
n,m=map(int, input().split())
li_1=list(range(m))
li_2=list(range(m))
pr=list(range(n))
wr=list(range(n))
wa=0
ac=0
for i in range(n):
    pr[i]=0
    wr[i]=0
for i in range(m):
    li_1[i],li_2[i]=map(str, input().split())
    li_1[i]=int(li_1[i])

for i in range(m):
    if li_2[i]=='AC':
        a=li_1[i]-1
        if pr[a]==0:
            wa=wr[a]+wa
            pr[a]=1
            ac=ac+1
    else:
        a = li_1[i] - 1
        wr[a]=wr[a]+1
print(ac,wa)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ac_count = 0
penalty_count = 0
all_number_list = dict()
ac_number_list = dict()
for i in range(M):
    temp_number, temp_result = map(str, input().split())
    if temp_number in all_number_list :
        if temp_number not in ac_number_list :
            temp_count = all_number_list[temp_number]
            if temp_result == 'AC' :
                ac_number_list[temp_number] = temp_count
            else :
                all_number_list[temp_number] = temp_count + 1
    else :
        if temp_result == 'AC' :
            all_number_list[temp_number] = 0
            ac_number_list[temp_number] = 0
        else :
            all_number_list[temp_number] = 1

ac_count = len(ac_number_list)
penalty_count = sum(ac_number_list.values())
print('{} {}'.format(ac_count, penalty_count))

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
a = {str(i):[] for i in range(1,N+1)}
AC,WA = 0,0
for i in range(M):
    P,S = [x for x in input().split()]
    a[P].append(S)
for i in a:
    if 'AC' not in a[i]:
        continue
    for x in a[i]:
        if x == 'AC':
            AC+=1
            break
        WA +=1
print(AC,WA)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ps = [[0, 0] for i in range(n)]  
wa_count = 0
ac_count = 0
for i in range(m):
    input_p, input_s = input().split()
    if ps[int(input_p)-1][0] <= 0:
        if input_s == 'AC':
            ps[int(input_p)-1][0] += 1
        else:
            ps[int(input_p)-1][1] += 1
for i in ps:
    if i[0] == 1:
        ac_count += 1
        wa_count += i[1]

print(ac_count, wa_count)

Submission status: Accepted

Solution code:
def solve(n, m, p_list, s_list):

    res_ac = 0
    res_wa = 0

    ac_dict = dict()
    wa_dict = dict()

    for i in range(m):
        p = p_list[i]
        s = s_list[i]

        if s == "AC":
            if p not in ac_dict.keys():
                ac_dict[p] = 1
                res_ac += 1
                if p in wa_dict.keys():
                    res_wa += wa_dict[p]
        else:
            if p not in wa_dict.keys():
                wa_dict[p] = 1
            else:
                wa_dict[p] += 1
    return str(res_ac) + " " + str(res_wa)


def main():
    n, m = map(int, input().split())
    p_list = [0] * m
    s_list = ["AC"] * m
    for i in range(m):
        p, s = input().split()
        p_list[i] = int(p)
        s_list[i] = s
    res = solve(n, m, p_list, s_list)
    print(res)


def test():
    assert solve(2, 5, [1, 1, 2, 2, 2], ["WA", "AC", "WA", "AC", "WA"]) == "2 2"
    assert solve(100000, 3, [7777, 7777, 7777], ["AC", "AC", "AC"]) == "1 0"
    assert solve(6, 0, [], []) == "0 0"


if __name__ == "__main__":
    test()
    main()

Submission status: Accepted

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

wa = [0 for _ in range(n)]
ac = set()

for i, j in ps:
    if j == "AC":
        ac.add(i)
    else:
        if i not in ac:
            wa[int(i) - 1] += 1

for k in range(n):
    if str(k + 1) not in ac:
        wa[k] = 0

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

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]
submissions = {str(i):[] for i in range(1,N+1)}
AC,WA = 0,0
for i in range(M):
    P,S = [j for j in input().split()]
    submissions[P].append(S)
for i in submissions:
    if 'AC' not in submissions[i]:
        continue
    for j in submissions[i]:
        if j == 'AC':
            AC+=1
            break
        WA +=1
print(AC,WA)

Submission status: Accepted

Solution code:
n,m = list(map(int, input().split()))
ac = {}
wa = {}
wrong = 0
for i in range(m):
  p,s  = list(map(str, input().split()))
  if s == "AC":
    if p not in ac:
      ac[p] = 1
      if p in wa:
        wrong += wa[p]
  elif s == "WA":
    if p not in ac:
      if p not in wa:
        wa[p] = 1
      else:
        wa[p] += 1
print("{} {}".format(len(ac),wrong))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
AC = 0
WA = 0
ACflag = [False for i in range(n)]
thisWA = [0 for i in range(n)]
for i in range(m):
    p,S = map(str, input().split())
    if ACflag[int(p)-1] == False:
        if S == 'AC':
            AC+=1
            ACflag[int(p)-1] = True
        if S == 'WA':
            thisWA[int(p)-1]+=1
            
for i in range(n):
    if ACflag[i] == True:
        WA+=thisWA[i]

print('{} {}'.format(AC, WA))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AC_flag = [False]*N
WA_count = [0]*N
for m in range(M):
    P,S = map(str,input().split())
    p = int(P)
    if AC_flag[p-1] == False and S == "AC":
        AC_flag[p-1] = True
    elif AC_flag[p-1] == False and S == "WA":
        WA_count[p-1] += 1

AC = 0
WA = 0
for n in range(N):
  if AC_flag[n] == True:
    AC += 1
    WA += WA_count[n]
#print(AC_flag,WA_count)
print(*[AC,WA])

Submission status: Accepted

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

p_list=[0]*(n+1)
cnt=[0]*(n+1)
ans=0
plt=0
for i in range(m):
    p,s=map(str,input().split())
    if s == "WA":
        cnt[int(p)] += 1;
    if s == "AC":
        if p_list[int(p)] == 0:
                ans+=1
                plt+=cnt[int(p)]
                p_list[int(p)] += 1
        
print(str(ans) + " " + str(plt))

Submission status: Accepted

Solution code:
from operator import itemgetter


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

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

l = []
for i in range(m):
    p, s = map(str, input().split())
    l.append([int(p), s])
l.sort(key = itemgetter(0))

numAC = 0
numWA = 0
countWA = 0
AC = False
last = l[0][0]

for i in range(m):
    if last == l[i][0]:
        if AC:
            continue
        elif l[i][1] == "AC":
            numAC += 1
            numWA += countWA
            AC = True
        else:
            countWA += 1
    else:
        last = l[i][0]
        AC = False
        if l[i][1] == "AC":
            numAC += 1
            AC = True
        else:
            countWA = 1

print(numAC, numWA)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
tocni = [0 for i in range(n + 1)]
correct = wrong = 0
for i in range(m):
    p, s = map(str, input().split())
    p = int(p)
    if s == "AC" and tocni[p] != 1:
        correct += 1
        wrong -= tocni[p]
        tocni[p] = 1
    if s == "WA" and tocni[p] != 1:
        tocni[p] -= 1
print(correct, wrong)

Submission status: Accepted

Solution code:
#python3
from collections import defaultdict
n,m = map(int, input().split())
a = []
dic = defaultdict(list)
for _ in range(m):
  x,y = map(str, input().split())
  dic[int(x)].append(y)

acc=0
for j in dic.values():
  if 'AC' in j:
    acc+=1;


cnt=0
for li in dic.values():
  if 'AC' in li:
    for j in li:
      if j == 'AC':
        break
      cnt+=1

ans = str(acc) + ' ' + str(cnt)
print(ans)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split(' ')))
r = [0] * N
pp = [0] * N

pena = 0
co = 0

for i in range(M):
  pi, Si = input().split(' ')
  p = int(pi)
  if r[p-1] == 0:
    if Si == 'WA':
      pp[p-1] += 1
    else:
      co += 1
      pena += pp[p-1]
      r[p-1] = 1

print (str(co) + ' ' + str(pena))

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from copy import deepcopy
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = float('INF')
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


n, m = LI()
ac_set = set()
ac = 0
wa = 0
D = defaultdict(int)
for _ in range(m):
    p, s = LS()
    if s == 'AC':
        if p not in ac_set:
            ac_set.add(p)
            wa += D[p]
            ac += 1
    else:
        if p not in ac_set:
            D[p] += 1


print(ac, wa)

Submission status: Accepted

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

RES = []

for i in range(M):
    RES.append(list(input().split()))

WA = [0]*(M+N)
ACed = [0]*(N+M)
tmp_num = [0]*(M+N)
tmp = 0
for i in range(M):
    num = int(RES[i][0])
    if RES[i][1] == "WA" and not ACed[num]:
        tmp_num[num] += 1
    elif RES[i][1] == "WA" and ACed[num]:
        tmp += 1
    else:
        ACed[num] = 1
        WA[num] = tmp_num[num]

print(sum(ACed),end=" ")
print(sum(WA))

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split()))
AC_list = [[0] * 2 for i in range(N)]
WA_count = 0
AC_count = 0
for i in range(M):
    A = list(input().split())
    if AC_list[int(A[0])-1][0] == 1:
        pass
    else:
        if A[1] == "AC":
            AC_list[int(A[0])-1][0] = 1
        else:
            AC_list[int(A[0])-1][1] += 1
for i in range(N):
    if AC_list[i][0] == 1:
        if 0 < AC_list[i][1]:
            WA_count += AC_list[i][1]
        AC_count += 1
print(AC_count,WA_count)

Submission status: Accepted

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

A = [0] * N
Pen = [0] * N

for i, j in zip(p, S):
    if A[i] == 0 and j == "AC":
        A[i] = 1
    elif A[i] == 0 and j == "WA":
        Pen[i] += 1
    elif A[i] == 1:
        continue

penalty = 0
for i in range(N):
    if A[i] == 1:
        penalty += Pen[i]
print(sum(A), penalty)

Submission status: Accepted

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

l = [list(input().split()) for _ in range(M)]

answers = {}
wrongs = {}

for a in l:
    if a[1] == "AC":
        answers[a[0]] = a[1]
    elif a[1] == "WA":
        # 正解後は数えない
        if not a[0] in answers and not a[0] in wrongs:
            wrongs[a[0]] = 1
        elif not a[0] in answers and a[0] in wrongs:
            wrongs[a[0]] = wrongs[a[0]] + 1

# 集計
wc = 0
for k, v in wrongs.items():
    if k in answers.keys():
        wc += v
result = [len(answers.keys()), wc]

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

Submission status: Accepted

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

if M == 0:
    print(0,0)
    exit()

pS = [list(input().split()) for _ in range(M)]
ACed = [0] * (N+1)
pena_memo = [0] * (N+1)
n_pena = [0] * (N+1)

for i in range(M):
    if ACed[int(pS[i][0])] == 0:
        if pS[i][1] == "AC":
            ACed[int(pS[i][0])] = 1
            n_pena[int(pS[i][0])] = pena_memo[int(pS[i][0])]
        else:
            pena_memo[int(pS[i][0])] += 1

print(sum(ACed), sum(n_pena))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
ac = {str(i): 0 for i in range(n+1)}
wa = {str(i): 0 for i in range(n+1)}
ok = 0
ng = 0

for _ in range(m):
    p, s = input().split()
    if ac[p] == 0:
        if s == "AC":
            ac[p] += 1
            ok += 1
            if wa[p] > 0:
                ng += wa[p]
        else:
            wa[p] += 1

print(ok, ng)

Submission status: Accepted

Solution code:
n, m = map(int, input().split(' '))
ans = {}

p = {} 
p_ = 0
for i in range(m):
  arr = list( input().split(' '))
  if not arr[0] in ans :
    if not arr[0] in p:
      p[arr[0]] = 0
    if arr[1] == 'WA':
      p[arr[0]] += 1
    if arr[1] == 'AC':
      ans[arr[0]] = 0
      p_ += p[arr[0]]
      p.pop(arr[0])
      
      
print(len(ans),p_)

Submission status: Accepted

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

aclist={}
wclist={}

p=0
ac=wa=0

for i in [input() for i in range(m)]:
    x,y=i.split()
    if not aclist.get(x):
        if y=='AC':
            aclist[x] = aclist.get(x,0) +1
            ac+=1
        elif y=='WA':
            wclist[x] = wclist.get(x,0) +1
            wa+=1
    
for k,v in wclist.items():
    if not aclist.get(k):
        wa-=v

print(ac,wa)

Submission status: Accepted

Solution code:
mondai, kaitou = map(int, input().split())

# 問題ごとのクリア管理
clearNo = [0] * (mondai+1)
# 問題ごとのWrong
wrong = [0] * (mondai+1)
cleard = 0
pena = 0
# 解答数分繰り返す
kaitous = [input().split() for _ in range(kaitou)]
for i in kaitous:
    qNo = int(i[0])
    result = i[1]
    if clearNo[qNo] == 1:
        continue
    else:
        if result == 'WA':
            wrong[qNo] += 1
        else:
            clearNo[qNo] = 1
            cleard += 1
            pena += wrong[qNo]

print(str(cleard) + ' ' + str(pena))

Submission status: Accepted

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


array_flag = [False] * N
array_cnt = [0] * N
for i in p:
    (pos, result) = i.split()
    pos = int(pos) - 1
    
    if result == 'AC':
        array_flag[pos] = True
    else:
        if array_flag[pos] == True:
            continue
        else:
            array_cnt[pos] += 1

answerd_cnt = 0
penalty_cnt = 0
for i in range(len(array_flag)):
    if array_flag[i] == True:
        answerd_cnt += 1
        penalty_cnt += array_cnt[i]

print(answerd_cnt, penalty_cnt)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
d={}
ans=0
pen=0

for i in range(m):
  s=input().split()
  if s[0] not in d:
    if s[1]=='WA':
      d[s[0]]=[0,1,1]
    else:
      d[s[0]]=[1,0,1]
      d[s[0]][2]*=0
  else:
    if s[1]=='WA' and d[s[0]][2]==1:
      d[s[0]][1]+=1
    elif s[1]=='AC' and d[s[0]][2]==1:
      d[s[0]][0]+=1
      d[s[0]][2]*=0

for i in d:
  if d[i][2]==0:
    pen+=d[i][1]
  ans+=d[i][0]    
print(ans,pen)

Submission status: Accepted

Solution code:
from sys import stdin
N,M = map(int, input().split())
#pS = [stdin.readline().split() for _ in range(n)]
#print(pS)
AC=[0]*N
WA=[0]*N
#print(AC,WA)
for _ in range(M):
    p,S=stdin.readline().split()
#    print('p={},S={}'.format(p,S))
    if S=='AC':
#        print('SはAC')
        if AC[int(p)-1]==0:
#            print('問題{}でACはまだないのでACに1加えます'.format(p,))
            AC[int(p)-1]+=1
        else:
#            print('問題{}で既にACがあるのでACには1加えません'.format(p,))
            pass
    elif S=='WA':
#        print('SはWA')
        if AC[int(p)-1]==0:
#            print('問題{}でACはまだないのでWAに1加えます'.format(p,))
            WA[int(p)-1]+=1
        else:
#            print('問題{}で既にACがあるのでWAに1加えません'.format(p,))
            pass
for i in range(N):
    if AC[i]==0:
        WA[i]=0
#print(AC,WA)
print(sum(AC), sum(WA))

Submission status: Accepted

Solution code:
N,M = [int(i) for i in input().split()]

submissions = {str(i):[] for i in range(1,N+1)}

AC,WA = 0,0

for i in range(M):

    P,S = [j for j in input().split()]

    submissions[P].append(S)

for i in submissions:

    if 'AC' not in submissions[i]:

        continue

    for j in submissions[i]:

        if j == 'AC':

            AC+=1

            break

        WA +=1

print(AC,WA)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a=0
b=0
if m==0:
    print(0,0)
    exit()
p = [[str(i) for i in input().split()] for _ in range(m)]

c = sorted(p,key=lambda x:x[0])

now = c[0][0]
d = 1
aa=0
bb=0
f = 0

for i in c:
    if i[0] == now:
        if i[1]=='AC':
            if d:
                a += 1
                f = 1
                d = 0
        else:
            if not f:
                bb+=1
    else:
        now = i[0]
        d = 1
        if f:
            b += bb
            f = 0
        bb = 0
        if i[1]=='AC':
            if d:
                a+=1
                f=1
                d = 0
        else:
            if not f:
                bb+=1
if f:
  b+=bb
print(a,b)