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:
def main():
    N, M = [int(s) for s in input().split()]
    p = []
    S = []
    for i in range(M):
        s_pn, Sn = input().split()
        p.append(int(s_pn))
        S.append(Sn)

    cleared = {}
    ng = {}
    for i in range(M):
        if S[i] == 'AC':
            cleared[p[i]] = True
        elif S[i] == 'WA':
            if p[i] not in cleared:
                if p[i] not in ng:
                    ng[p[i]] = 1
                else:
                    ng[p[i]] += 1

    ng_count = 0
    for pn in cleared.keys():
        if pn in ng:
            ng_count += ng[pn]
    print(len(cleared), ng_count)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

idx = list(range(N+1))
wa = [0] * (N + 1)
AC = 0
WA = 0
for i in range(len(ps)):
    if idx[int(ps[i][0])] != "AC":
        if ps[i][1] == "AC":
            AC += 1
            idx[int(ps[i][0])] = "AC"
        else:
            wa[int(ps[i][0])] += 1

for i in range(N+1):
    if idx[i] == "AC":
        WA += wa[i] 

print(str(AC) + " " + str(WA))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
sl=[]
pl=[]
pena=0
ac=0
ac_p=[]
wa={}
acdic={}

for i in range(m):
    #p,s=map(str,input().split())
    li = input().split()
    p=int(li[0])
    s=li[1]
    #p=int(p)
    if s=="WA":
        wa[p]=wa.get(p,0)+1
    else:#もしACなら
        #acdic[p]=True
        if acdic.get(p,False)==False:
            ac+=1
            acdic[p]=True
            pena+=wa.get(p,0)

print("{0} {1}".format(ac,pena))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
AC = 0
WA = 0
ACdata = [0]*100001
WAdata = [0]*100001
for i in range(M):
    x, y = map(str,input().split())

    if ACdata[int(x)] == 1:
        continue
    if y == 'WA':
        WAdata[int(x)] += 1
    else:
        AC += 1
        ACdata[int(x)] = 1
        WA += WAdata[int(x)]
print(AC,WA)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
P = []
S = []
for i in range(M):
    p, s = input().split()
    P += [int(p)]
    S += [s]

CA = 0
PN = 0
d = {key:0 for key in P}
for i in range(len(P)):
    if d[P[i]] >= 0:
        if S[i] == "WA":
            d[P[i]] += 1
        elif S[i] == "AC":
            PN += d[P[i]]
            CA += 1
            d[P[i]] = -1

print(CA, PN)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
list_point = ["NN"] * (N + 1)
list_wa = [0] * (N + 1)
for x in range(M):
    point,state = input().split()
    point = int(point)
    if(list_point[point]!='AC' and state == 'AC'):
        list_point[point]=state
    elif(list_point[point]!='AC' and state == 'WA'):
        list_wa[point] += 1
#print(list_point)
#print(list_wa)
sum_wa =0
for x in range(N+1):
    if(list_point[x] == "AC"):
        sum_wa += list_wa[x]
print(list_point.count('AC'),sum_wa)
#print(' ',sum(list_wa))

Submission status: Accepted

Solution code:
from fractions import gcd
# from datetime import date, timedelta
# from heapq import *
import heapq
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors





def main():
    
    n, m = map(int, input().split())
    ps = [list(input().split()) for i in range(m)]

    c = 1
    ac, wa = 0, 0
    d = defaultdict(int)
    dwa = defaultdict(int)
    for i in range(m):
        if ps[i][1] == "AC" and d[int(ps[i][0])] == 0:
            ac += 1
            d[int(ps[i][0])] = 1
            wa += dwa[int(ps[i][0])]
        elif ps[i][1] == "WA" and d[int(ps[i][0])] == 0:
            # wa += 1
            dwa[int(ps[i][0])]+=1
    print(ac,wa)

    # n, k = map(int, input().split())
    # a = list(map(int, input().split()))
    # a.sort()

            
    
    # l = [1, 2, 3, 4, 5, 6]
    # dmax = defaultdict(int)
    # dmin = defaultdict(int)
    # d = defaultdict(int)
    # for i in itertools.combinations(l, 2):
    #     dmax[max(i)] += 1
    #     dmin[min(i)] += 1
    #     d[max(i) - min(i)] += 1
    
    # print(dmax)
    # print(dmin)
    # print(d)
                
        




    


if __name__ == '__main__':
    main()

Submission status: Accepted

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

c_l = [0 for i in range(N)]
a = 0
w = 0

for i in range(M):
  p,s = input().split()
  p = int(p)
  if c_l[p-1] != -1:
    if s == "AC":
      a += 1
      w += c_l[p-1]
      c_l[p-1] = -1
    else:
      c_l[p-1] += 1
print("{} {}".format(a,w))

Submission status: Accepted

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

if m == 0:
  print('0 0')
else:
  # 逆順にすると、各問題に関して、最後にACになったもの以降のWAの数がWAのカウント対象。
  outputs = reversed([input().split(' ') for i in range(m)])

  problem_ac = set()  # ACになった問題番号のセット
  problem_wa = {}  # 問題番号:WAの数
  for o in outputs:
    num = o[0]
    result = o[1]
    if result == 'AC':
      if num in problem_ac:  # ACの後に再度ACになっている場合を考慮
        problem_wa[num] = 0
      problem_ac.add(num)
    else:  # WC
      if num in problem_ac:
        problem_wa[num] = problem_wa[num] + 1 if num in problem_wa.keys() else 1
  # print('{} {}'.format(str(problem_ac), str(problem_wa)))
  ac_count = len(problem_ac)
  wa_count = sum(problem_wa.values()) if len(problem_wa) > 0 else 0
  print('{} {}'.format(ac_count, wa_count))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
lis = [tuple(map(str,input().split())) for i in range(M)]
ans = [0]*N
answ = [0]*N
ansin = [0]*N
for i in range(0,M):
    an = lis[i][1]
    if an == 'AC':
        ans[int(lis[i][0])-1] = 1
    elif an == 'WA' and ans[int(lis[i][0])-1] == 0:
        answ[int(lis[i][0])-1] += 1
for i in range(N):
    if ans[i] == 1:
        ansin[i] = answ[i]
print(sum(ans),end=' ')
print(sum(ansin))

Submission status: Accepted

Solution code:
import numpy as np

NM=np.array(input().split(" "),dtype=np.int32)

result={}
tmp=[]

for i in range(NM[1]):
    s=input().split(" ")
    result.setdefault(s[0],[]).append(s[1])

corrects=0
penalty=0
keys=result.keys()

for k in keys:
    L=result[k]
    if('AC' in L):
        idx=L.index('AC')
    else:
        idx=-1
    if(idx==-1):
        continue
    else:
        penalty+=idx
        corrects+=1

print("{} {}".format(corrects,penalty))

Submission status: Accepted

Solution code:
import numpy as np
n, m = list(map(int, input().split()))
p = np.zeros(m, dtype=np.int64)
s = np.zeros(m, dtype=np.bool)
for i in range(m):
    _p, _s = input().split()
    p[i] = int(_p) - 1
    s[i] = _s[0] == 'A'
isAc = np.zeros(n, dtype=np.bool)
waCount = np.zeros(n, dtype=np.int64)
for i in range(m):
    question = p[i]
    isAc[question] = isAc[question] or s[i]
    if (not isAc[question]) and (not s[i]):
        waCount[question] += 1
for j in range(n):
    if not isAc[j]:
        waCount[j] = 0
acCount = np.count_nonzero(isAc)
waSum = np.sum(waCount)
print('{} {}'.format(acCount, waSum))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
t=[0]*(N+1)
e=[0]*(N+1)
for i in range(M):
  p,s=input().split()
  if t[int(p)]==0 and s=="WA":
    e[int(p)]+=1
  if t[int(p)]==0 and s=="AC":
    t[int(p)]=1
for i in range(N+1):
  if t[i]==0:
    e[i]=0
print(sum(t),sum(e))

Submission status: Accepted

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

count_wa = [0]*n
flag_ac = [False]*n
for i in l:
    if not flag_ac[int(i[0])-1]:
        if i[1] == "AC":
            flag_ac[int(i[0])-1] = True 
        elif i[1] == "WA":
            count_wa[int(i[0])-1] += 1

for i in range(n):
    if not flag_ac[i]:
        count_wa[i] = 0

print(sum(flag_ac), sum(count_wa))

Submission status: Accepted

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

question = [False for i in range(N)]
solved = [False for i in range(N)]
for i in range(M):
    posi = ps[i][0]-1
    if ps[i][1] =='AC':
        solved[posi] = True
pena = 0
AC = 0

for i in range(M):
    posi = ps[i][0]-1
    if ps[i][1] =='AC' and question[posi]==False:
        AC+=1
        question[posi] = True
    if ps[i][1] =='WA' and question[posi] == False and solved[posi]==True:
        pena+=1
        
print(AC,pena)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
n, m = input().split()
n = int(n)
m = int(m)
results = []
for i in range(m):
    results.append(list(input().split()))

wa = 0
ac = 0

dic = {}
for q, a in results:
    if q not in dic.keys():
        dic[q] = {"ac": False, "wa": 0}
    if dic[q]["ac"] is True:
        pass
    elif dic[q]["ac"] is False and a == "WA":
        dic[q]["wa"] += 1
    elif dic[q]["ac"] is False and a == "AC":
        ac += 1
        dic[q]["ac"] = True
for x in dic.keys():
    if dic[x]["ac"] is True:
        wa += dic[x]["wa"]

print(ac, wa)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
wa = [0] * n
ac = [0] * n
ps = []
score = 0
pena = 0
for _ in range(m):
    ps = input().split()
    if ps[1] == 'WA':
        wa[int(ps[0])-1] += 1
    else:
        if ac[int(ps[0])-1] == 0:
            score += 1
            pena += wa[int(ps[0])-1]
            ac[int(ps[0])-1] += 1
print(score, pena)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
A=[[0 for i in range(2)] for j in range(N+1)]
for i in range(M):
    p,s=input().split()
    p=int(p)
    if s=="AC": A[p][0]=1
    if s=="WA" and A[p][0]==0: A[p][1]+=1
AC=0
Pen=0
for row in A:
    AC+=row[0]
    Pen+=row[0]*row[1]
print(AC, Pen)

Submission status: Accepted

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

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

ps = [ list(input().split()) for _ in range(m) ]

ac_count_list = [0]*n
wa_count_list = [0]*n
wa_count = 0

for i in range(m):
    q = int(ps[i][0])
    if ps[i][1] == "AC":
        if ac_count_list[q-1] == 0:
            ac_count_list[q-1] = 1
            wa_count += wa_count_list[q-1]
        else:
            pass
    else:
        if ac_count_list[q-1]==0:
            wa_count_list[q-1] += 1

print(sum(ac_count_list),wa_count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ans = []
ans_0 = []
for i in range(m):
    ans_0 = list(map(str, input().split()))
    ans.append(ans_0)
list0 = []
listpen = []
for j in range(n):
    list0.append(0)
for k in range(n):
    listpen.append(0)
sei = 0
pen = 0
for lis in ans:
    if list0[int(lis[0])-1] == 0:
        if lis[1] == "AC":
            sei += 1
            list0[int(lis[0])-1] = 1
        else:
            listpen[int(lis[0])-1] += 1
    else:
        pass
for l in range(n):
    if list0[l] == 1:
        pen += listpen[l]
print(str(sei)+" "+str(pen))

Submission status: Accepted

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

WAs = [0]*(N+1)
flags = [0]*(N+1)

AC = 0
WA = 0

for i in range(M):
  if X[i][1] == 'AC':
    if flags[int(X[i][0])] == 0:
      AC += 1
      WA += WAs[int(X[i][0])]
      flags[int(X[i][0])] = 1
  if X[i][1] == 'WA':
    if flags[int(X[i][0])] == 0:
      WAs[int(X[i][0])] += 1
      
print(AC,WA,sep=' ')

Submission status: Accepted

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

for i in range(m):
    t1, t2 = input().split()
    ss.append([t1, t2])

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

t = ''
ac = 0
wa = 0
awa = 0
cIsSolved = False
for s in ss:
    if s[0] != t:
        t = s[0]
        cIsSolved = False
        wa = 0
    if s[1] == 'AC' and not cIsSolved:
        cIsSolved = True
        ac += 1
        awa += wa
    if s[1] == 'WA' and not cIsSolved:
        wa += 1
print(ac, awa)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split())
    a = [0] * N
    w = [0] * N

    for _ in range(M):
        p, s = map(str, input().split())
        if a[int(p) - 1] == 1:
            continue
        if s == "AC":
            a[int(p) - 1] = 1
        elif s == "WA":
            w[int(p) - 1] += 1

    wa = 0
    for i in range(N):
        if a[i] == 1:
            wa += w[i]

    print(sum(a), wa)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
cor = [[0] * 2 for i in range(N)]

for i in range(M):
    p, s = input().split()
    p = int(p)
    if(cor[p-1][1] != 1):
        if s == "AC":
            cor[p-1][1] = 1
        elif s == "WA":
            cor[p-1][0] += 1

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = 0
b = 0
sp = dict()
for _ in range(M):
    s, p = input().split()
    if int(s) not in sp.keys():
        sp[int(s)] = [p]
    else:
        sp[int(s)].append(p)
        
a = 0
b = 0
for i, result in sp.items():
    if "AC" in result:
        a += 1
        b += result.index("AC")
    else:
        continue
print(a, b)

Submission status: Accepted

Solution code:
import sys


def main():
    tmp = str(input()).split(" ")
    n = int(tmp[0])
    m = int(tmp[1])
    p = []
    s = []
    for i in range(m):
        tmp = str(input()).split(" ")
        p.append(int(tmp[0]))
        s.append(str(tmp[1].replace("\n", "")))
    cnt = [[0, 0, False] for i in range(n)]
    for i, j in zip(p, s):
        if j == "WA" and not cnt[i-1][2]:
            cnt[i-1][1] += 1
        elif j == "AC" and not cnt[i-1][2]:
            cnt[i-1][0] = 1
            cnt[i-1][2] = True
    accnt = 0
    wacnt = 0
    for i in range(n):
        accnt += cnt[i][0]
        if cnt[i][2]:
            wacnt += cnt[i][1]
    print(str(accnt) + " " + str(wacnt))


if __name__ == '__main__':
    input = sys.stdin.readline
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

AC = np.array([0]*N)
WA = np.array([0]*N)

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


print(sum(AC),sum(AC*WA))

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
P = []
S = []
result = {}
num_result = {}

for i in range(M):
    p,s = map(str, input().split())
    P.append(int(p))
    S.append(s)

ac = 0
wa = 0

for i in range(M):
    if S[i] == 'AC':
        if P[i] in result:
            if result[P[i]] == 'WA':
                ac += 1
                result[P[i]] = 'AC'
        else:
            result[P[i]] = 'AC'
            ac += 1
    elif S[i] == 'WA':
        if P[i] in result:
            if result[P[i]] == 'WA':
                num_result[P[i]] += 1
        else:
            result[P[i]] = 'WA'
            num_result[P[i]] = 1

for item in num_result:
    if result[item] != 'WA':
        wa += num_result[item]

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
p=[]
S=[]
d={"WA":-1,"AC":1}
for _ in range(M):
    i,j= input().split()
    p.append(int(i)-1)
    S.append(d[j])
    
status = [False for _ in range(N)]

wa = [0 for _ in range(N)]
ac = 0
for i in range(M):
    if not status[p[i]]:
        if S[i]==-1:
            wa[p[i]] += 1
        else:
            ac += 1
            status[p[i]] = True
    else:
        pass
wa2 = 0 
for i in range(N):
    if status[i]:
        wa2 += wa[i]
print(ac,wa2)

Submission status: Accepted

Solution code:
from collections import Counter
def counter(li, n):
    count = Counter()
    count.update(li)
    return count[n]
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
li_AC = [0]*N
count_WA = [0]*N
count_WA_total = 0
for i in range(M):
    p, S = input().split()
    p = int(p)
    if li_AC[p-1] == 0:
        if S == "AC":
            li_AC[p-1] = 1
            count_WA_total += count_WA[p-1]
        if S == "WA":
            count_WA[p-1] += 1
print(counter(li_AC, 1), count_WA_total)

Submission status: Accepted

Solution code:
R = lambda : input().split()

n, m = map(int, R())
a = [False] * n
b = [0] * n
for _ in range(m):
  p, s = R()
  p = int(p) - 1
  if s == 'AC':
    a[p] = True
  elif not a[p]:
    b[p] += 1
b =  [y for x, y in zip(a, b) if x]
print(len(b), sum(b))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
l=[input().split() for _ in range(m)]
arr=[]
ac,wa=0,0
acl=[False for _ in range(n)]
for r in l:
  p,s=int(r[0])-1,r[1]
  if s=='AC' and acl[p]==False:
    arr.append([p,s])
    acl[p]=True
  elif s=='WA' and acl[p]==False:
    arr.append([p,s])
    
for r in arr:
  p,s=r
  if s=='WA' and acl[p]:
    wa+=1
  elif s=='AC':
    ac+=1
    
print(ac,wa)

Submission status: Accepted

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

for _ in range(m):
    p, s = input().split()
    if (not ac[int(p)]) and s == 'WA':
        wa[int(p)] += 1
    elif s == 'AC':
        ac[int(p)] = 1
sw = 0
for i in range(n+1):
    sw += ac[i] * wa[i]
print(sum(ac), sw)

Submission status: Accepted

Solution code:
n, m = [int(_) for _ in input().split()]
l = []
AC = 0
WA = 0
for i in range(m):
    l.append(input().split())
d = {}
for i in range(n):
    d[i + 1] = 0
for i in range(m):
    p, s = l[i]
    p = int(p)
    if s == 'WA':
        if d[p] != -1:
            d[p] += 1
    else:
        if d[p] != -1:
            AC += 1
            WA += d[p]
            d[p] = -1
    # print(d)
    # print(AC, WA)
print(AC, WA)

Submission status: Accepted

Solution code:
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
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 NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

class Comb:
    def __init__(self,n,mo=10**9+7):
        self.fac=[0]*(n+1)
        self.inv=[1]*(n+1)
        self.fac[0]=1
        self.fact(n)
        for i in range(1,n+1):
            self.fac[i]=i*self.fac[i-1]%mo
            self.inv[n]*=i
            self.inv[n]%=mo
        self.inv[n]=pow(self.inv[n],mo-2,mo)
        for i in range(1,n):
            self.inv[n-i]=self.inv[n-i+1]*(n-i+1)%mo
        return
    
    def fact(self,n):
        return self.fac[n]
        
    def invf(self,n):
        return self.inv[n]

    def comb(self,x,y):
        if y<0 or y>x:
            return 0
        return self.fac[x]*self.inv[x-y]*self.inv[y]%mo

show_flg=False
show_flg=True


ans=0

n,m=LI()

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


for i in range(n):
    if a[i]==0:
        w[i]=0

print(sum(a),sum(w))

Submission status: Accepted

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

T = [0] * (N + 1)
A = 0
W = [0] * (N + 1)

ans = [0,0]

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

for i in range(M):
  p = PS[i][0]
  s = PS[i][1]

  if T[p] == 0:
    if s == "AC":
      A += 1
      T[p] = "AC"
    elif s == "WA":
      W[p] += 1
      T[p] = "WA"
      
  elif T[p] == "AC":
    continue

  elif T[p] == "WA":
    if s == "AC":
      T[p] = "AC"
      A += 1
    elif s == "WA":
      W[p] += 1

w = 0

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

Submission status: Accepted

Solution code:
from itertools import compress

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

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

print(sum(ac), sum(c for c in compress(wa, ac)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
hist = []
nm = list(map(int, input().split()))
for i in range(nm[1]):
    a,b=input().split()
    hist.append((int(a), b))

ac = [0] * nm[0]
wa = [0] * nm[0]

for i in range(nm[1]):
    if hist[i][1] == "AC":
        if ac[hist[i][0]-1] != 1:
            ac[hist[i][0]-1] = 1
    elif hist[i][1] == "WA":
        if ac[hist[i][0]-1] != 1:
            wa[hist[i][0]-1] = wa[hist[i][0]-1] + 1


for i in range(nm[0]):
    wa[i] = wa[i] * ac[i]

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

N, M = map(int, input().split())
P = list()
S = list()
for i in range(M):
    p, s = map(str, input().split())
    P.append(int(p))
    S.append(s)

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

ac_list = [0] * N
wa_list = [0] * N
for i in range(M):
    if S[i] == 'AC' and ac_list[P[i] - 1] == 0:
        ac_list[P[i] - 1] = 1
        ac += 1
    elif S[i] == 'WA' and ac_list[P[i] - 1] == 0:
        wa_list[P[i] - 1] += 1

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

print(ac, penalty)

Submission status: Accepted

Solution code:
N, M = [int(i) for i in input().split()]
ans_list = [list(input().split()) for i in range(M)]
ref_list = [0]*N
pena_list = [0]*N
for i, j in ans_list:
    if ref_list[int(i)-1]==0:
        if j == "AC":
            ref_list[int(i)-1]=1
        else:
            pena_list[int(i)-1] = pena_list[int(i)-1]+1
ok_count = 0
pena_num = 0
for i in ref_list:
    if int(i) == 1:
        ok_count += 1
for i, j in zip(ref_list, pena_list):
    if i==1:
        pena_num += j
print(ok_count, pena_num)

Submission status: Accepted

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

ac = 0
wa = 0
problems = [[0,0] for _ in range(n)]
for i in l:
    if i[1] == 'WA' and problems[int(i[0])-1][0] == 0:
        problems[int(i[0])-1][1] += 1
    elif i[1] == 'AC' and problems[int(i[0])-1][0] == 0:
        problems[int(i[0])-1][0] = 1
    else:
        pass


for i in problems:
    ac += i[0]
    wa += i[1] if i[0] > 0 else 0
    
print(ac,wa)

Submission status: Accepted

Solution code:
i = list(map(int, input().split()))
accept = [0] * i[0]
miss = [0] * i[0]
# print(accept)
for j in range(i[1]):
    s = input().split()
    if(accept[int(s[0]) - 1] == 1):
        # print("already")
        print('',end='')
        pass
    elif(s[1] == 'AC'):
        accept[int(s[0]) - 1] = 1
    else:
        miss[int(s[0]) - 1] += 1

for j in range(i[0]):
    if(accept[j] == 0):
        miss[j] = 0
print(sum(accept), sum(miss))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
di = {}
pe = 0
ac = 0
for i in range(M):
    inp = input().split(" ")
    if inp[1] == "WA":
        if inp[0] in di:
            if di[inp[0]] >= 1:
                di[inp[0]] += 1
        else:
            di[inp[0]] = 1
            
            
    else:
        if inp[0] in di:
            pe += di[inp[0]]
            di[inp[0]] = 0
        di[inp[0]] = 0
        
for v in di.values():
    if v == 0:
        ac += 1
print(str(ac)+" "+str(pe))

Submission status: Accepted

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

key = [0]*n
wa = [0]*n
for i in range(m):
    p, s = map(str, input().split())
    p = int(p)
    if s == "WA":
        if key[p-1]:
            continue
        else:
            wa[p-1] = wa[p-1]+1
    if s == "AC":
        if key[p-1]:
            continue
        else:
            key[p-1] = True
ac = sum(key)
wan = 0
for i in range(n):
    if key[i]:
        wan += wa[i]
print(ac, wan)

Submission status: Accepted

Solution code:
import sys

def resolve():
    input = sys.stdin.readline
    N,M=map(int,input().rstrip().split())
    Q=[list(input().rstrip().split()) for _ in range(M)]

    c=[0 for _ in range(N)]
    flag=[0 for _ in range(N)]

    for i in range(M):
        if Q[i][1]=="WA" and flag[int(Q[i][0])-1]==0:
            c[int(Q[i][0])-1]+=1
        if Q[i][1]=="AC":
            flag[int(Q[i][0])-1]=1
    
    #ans=sum(c)
    #ansAC=sum(flag)
    
    ans=0
    ansAC=0
    for i in range(N):
        if flag[i]==1:
           ans+=c[i]
        ansAC+=flag[i]
    #print(int(ansAC), int(ans))
    print('{:.15g}'.format(ansAC),'{:.15g}'.format(ans))


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)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Submission status: Accepted

Solution code:

a,b = map(int,input().split())
dp = [0]*(100010)
qp = [0]*(100010)
for i in range(b):
    ta,tb = map(str,input().split())
    ta = int(ta)
    if qp[ta] == 0 :
        if tb == 'WA':
            dp[ta]+=1
        else :
            qp[ta]=1
ANS = 0
for i, j in zip(dp,qp):
    ANS += i*j
print(sum(qp),ANS)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
d = {}
P = {}
for i in range(1,N+1):
    d[i] = 0
    P[i] = 0
for i in range(M):
    p,s = map(str,input().split())
    q = int(p)
    if d[q] == 1:
        continue
    else:
        if s == 'AC':
            d[q] = 1
        else:
            P[q] += 1
ans1 = 0
ans2 = 0
for i in range(1,N+1):
    if d[i] == 1:
        ans1 += 1
        ans2 += P[i]
print(ans1,ans2)

Submission status: Accepted

Solution code:
n, m = (int(i) for i in input().split())
p = [None] * m
s = [None] * m
for i in range(m):
    p[i], s[i] = (j for j in input().split())
    p[i] = int(p[i])
    
pena = [0] * n
ac   = [0] * n

for i in range(m):
    q_index = p[i]-1
    if s[i] == 'AC': 
        ac[q_index] = 1
    if s[i] == 'WA':
        if ac[q_index] == 0: pena[q_index] += 1
        
ac_num = 0
pena_num = 0
for i in range(n):
    if ac[i] == 1:
        ac_num += 1
        pena_num += pena[i]

print(ac_num, pena_num)

Submission status: Accepted

Solution code:
N,M = list(map(int,input().split(" ")))
dic = {}
Acount = 0
Wcount = 0
tmp_w = {}
for i in range(M):
    x1,y1=[i for i in input().split(" ")]
    if x1 in dic:
        if dic[x1] == "WA" and y1 == "AC":
            Acount += 1
            Wcount = Wcount + tmp_w[x1]
            dic[x1] = y1
        elif dic[x1] == "WA" and y1 == "WA":
            tmp_w[x1] = tmp_w[x1] + 1
    else:
        if y1 == "AC":
            Acount += 1
            dic[x1] = y1
        else:
            tmp_w[x1] = 1
            dic[x1] = y1
print(Acount,Wcount)