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:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
sys.setrecursionlimit(10**9)
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def 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)
    return divisors
def is_prime(n):
    if n == 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0: return False 
    return True
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n + 1, i): is_prime[j] = False
    return [i for i in range(n+1) if is_prime[i]]
def sieve_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime
def run_length_encode(s):
    count = 1
    code = []
    target = s[0]
    for i in range(1, len(s)):
        if target == s[i]: count += 1
        else:
            code.append((target, count))
            target = s[i]
            count = 1
    code.append((target, count))
    return code

N,M = imn()
PS = [input().split() for _ in range(M)]
AC = set()
WA = {}
for i in range(M):
    if PS[i][1] == 'AC':
        AC.add(PS[i][0])
    else:
        if PS[i][0] not in AC:
            if PS[i][0] not in WA:
                WA[PS[i][0]] = 1
            else:
                WA[PS[i][0]] += 1
WA_cnt = 0
for k, v in WA.items():
    if k in AC:
        WA_cnt += v

print(len(AC), WA_cnt, sep=' ')

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
n,m=map(int,input().split())
ps=[list(input().split()) for i in range(m)]
li=[[0,0] for i in range(n+1)] 
wa=0
ans=0
# print(ps)
for i in range(m):
    if li[int(ps[i][0])][0]==0:
        if ps[i][1]=="AC":
            li[int(ps[i][0])][0]+=1
        else:
            li[int(ps[i][0])][1]+=1
    else:
        continue
for i in range(n+1):
    if li[i][0]==0:
        continue
    else:
        ans+=1
        wa+=li[i][1]
print(ans)
print(wa)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
Accepted=[0]*N
Penalty=[0]*N
for i in range(M):
    p,S=input().split()
    p=int(p)
    if Accepted[p-1]==0 and S=="WA":
        Penalty[p-1]+=1
    elif Accepted[p-1]==0 and S=="AC":
        Accepted[p-1]=1
total_Accepted=sum(Accepted)
total_Penalty=0
for i in range(N):
  if Accepted[i-1]==1:
    total_Penalty+=Penalty[i-1]
print(total_Accepted,total_Penalty)

Submission status: Accepted

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

freq = {}
for i in range(m):
  p, s = input().split()
  if not p in freq:
    freq[p] = [0, 0]
  if freq[p][0] == 0:
    freq[p][['AC', 'WA'].index(s)] += 1

print(sum(c for c, w in freq.values() if c > 0), sum(w for c, w in freq.values() if c > 0))

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
a = [0]*(n+1)
ans1 = 0
ans2 = 0
for i in range(m):
  p,s = map(str, input().split())
  p = int(p)
  if s == "WA":
    if a[p] != -1:
      a[p] += 1
  else:
    if a[p] != -1:
      ans1 += 1
      ans2 += a[p]
      a[p] = -1
print(ans1,ans2)

Submission status: Accepted

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

lst2 = [0]*n #01
lst3 = [0]*n #pena

for i,j in lst1:
    i = int(i)-1
    if lst2[i] == 0:
        if j == "WA":
            lst3[i] += 1
        else:
            lst2[i] = 1
        
        
pena = 0
for i in range(n):
    if lst2[i]  == 1:
        pena += lst3[i]
print(sum(lst2),pena)

Submission status: Accepted

Solution code:
N, M = [int(x) for x in input().split()]
ans = [0] * N
pen = [0] * N
for _ in range(M):
    ps, S = [x for x in input().split()]
    p = int(ps)-1
    if S == 'WA':
        if ans[p] == 0:
            pen[p] += 1
    else:
        ans[p] = 1
ans1 = 0
ans2 = 0
for a, p in zip(ans, pen):
    ans1 += a
    ans2 += (a*p)
print(ans1, ans2)

Submission status: Accepted

Solution code:
N, K= [int(x) for x in input().split()]
t = [[] for i in range(N)]
for i in range(K):
  q,ans = input().split()
  t[int(q)-1].append(ans)

wa = 0
ac = 0
for i in t:
  w_tmp = 0
  for j in i:
    if j == "WA":
      w_tmp += 1
    elif j== "AC":
      ac += 1
      wa += w_tmp
      break
print(ac,wa)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
submits = [tuple(input().split()) for _ in range(M)]
accepted = {i: 0 for i in range(1, N+1)}
ACs = 0
WAs = 0
for p, S in submits:
    p = int(p)
    if accepted[p] < 0: continue
    if S == 'AC':
        ACs += 1
        WAs += accepted[p]
        accepted[p] = -1
    else:
        accepted[p] += 1
print(ACs, WAs)

Submission status: Accepted

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

success = 0
fail = 0
check = {}
for i in range(m):
    p, s = input().split()
    if s == "WA":
        if p in check:
            if check[p] < 0:
                pass
            else:
                check[p] += 1
        else:
            check[p] = 1
    else:
        if p in check:
            if check[p] < 0:
                continue
            fail += check[p]
        check[p] = -1
        success += 1
print(success, fail)

Submission status: Accepted

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


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

    ac_list = [False] * N
    wa_counts = [0] * N
    total_wa = 0

    for _ in range(M):
        p, s = input().split()
        p = int(p) - 1
        if ac_list[p]:
            continue
        if s == "AC":
            ac_list[p] = True
            total_wa += wa_counts[p]
            continue
        else:
            wa_counts[p] += 1

    print(sum(ac_list), total_wa)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
na = [0]*n
nw = [0]*n

for i in range(m):
    a,b = input().split()

    if b == "AC":
        na[int(a)-1] = 1
    elif b == "WA":
        if na[int(a)-1] == 0:
            nw[int(a)-1] += 1
count = 0
print(sum(na),end="")
for i in range(n):
    if na[i] == 1:
        count += nw[i]
print(" {}".format(count))

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
p =[]
S =[]
for i in range(M):
    p1, S1 = map(str,input().split())
    p.append(int(p1))
    S.append(S1)
    
wa = [0] * (N+1)
ac = [0] * (N+1)
answ = 0
for i in range(M):
    if S[i] == "AC" and ac[p[i]] == 0:
        answ += wa[p[i]]
        ac[p[i]] = 1
    else:
        wa[p[i]] += 1

ans = [str(sum(ac)), str(answ)]

print(" ".join(ans))

Submission status: Accepted

Solution code:
n, nSubms = map(int, input().split())
waCnt = [0] * (n + 1)
ac = [0] * (n + 1)
for _ in range(nSubms):
    id, res = input().split()
    id = int(id)
    if res == 'WA':
        if not ac[id]:
            waCnt[id] += 1
    elif res == 'AC':
        if not ac[id]:
            ac[id] = 1
    else:
        raise Exception
for i in range(n + 1):
    if waCnt[i] and not ac[i]:
        waCnt[i] = 0
print('%d %d' % (sum(ac), sum(waCnt)))

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
arr = [0] * (n + 1)
arr2 = [0] * (n + 1)
corr = 0
pen = 0
for i in range(m):
    p, s = map(str, input().split())
    if s == 'AC':
        arr[int(p)] = 1
    else:
        if arr[int(p)] == 0:
            arr2[int(p)] -= -1
for i in range(n + 1):
    if arr[i] == 1:
        corr -= -1
        pen += arr2[i]
print(corr, pen)

Submission status: Accepted

Solution code:
import numpy as np
n, m = map(int,input().split())
questions = [0 for i in range(n)]
clear = [0 for i in range(n)]
for i in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'WA':
        if clear[p-1] == 0:
            questions[p-1] += 1
    else:
        clear[p-1] = 1
questions = np.array(questions)
print(sum(clear), questions[np.where(np.array(clear) == 1)[0]].sum())

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
p = [0]*M
S = [0]*M
for i in range(M):
    l = input().split()
    p[i] = int(l[0])
    S[i] = l[1]
# print(N, M, p, S)
ans = {(x + 1): [0, 0] for x in range(N)}
# print(ans)
for i in range(M):
    a = p[i]
    b = S[i]
    if b == 'AC':
        ans[a][0] += 1
    else:
        if ans[a][0] == 0:
            ans[a][1] += 1
# print(ans)
ac = 0
wa = 0
for i in range(1, N + 1):
    if ans[i][0] > 0:
        ac += 1
        wa += ans[i][1]

print(ac, wa)

Submission status: Accepted

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

ans = 0
clear = 0

chk = [0]*(n+1)

for i in range(m):
    p,s = input().split()
    p = int(p)
    if chk[p] >=0:
        if s=="WA":
            chk[p]+=1
        elif s =="AC":
            ans += chk[p]
            chk[p]=-1
            clear+=1

print(str(clear)+" "+str(ans))

Submission status: Accepted

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

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

# print(p, s)

acSet = set()
acCnt = 0
waCnt = 0
waTempMap = [0]*(n+1)

for i in range(m):
    prob = p[i]
    res = s[i]

    if res == 'AC':
       if prob not in acSet:
           acSet.add(prob)
           acCnt += 1
           waCnt += waTempMap[prob]
    else:
        waTempMap[prob] += 1
        # waCnt += 1

print(acCnt, waCnt)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
l = [0 for i in range(N)]
cnt = [0 for i in range(N)]
for i in range(M):
    p,s = map(str, input().split())
    p = int(p)-1
    if s == "AC":
        l[p] = 1
    elif s == "WA":
        if l[p] == 0:
            cnt[p] += 1

mis = 0
for i in range(N):
    if l[i] == 1:
        mis += cnt[i]
print(sum(l), mis)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline

n, m = [int(item) for item in input().split()]
ok = [False] * n
cnt = [0] * n
submit = []
was = 0
ans = 0
for i in range(m):
    p, s = input().split()
    p = int(p) - 1
    if not ok[p] and s == "WA":
        cnt[p] += 1
    elif not ok[p] and s == "AC":
        ans += 1
        was += cnt[p]
        ok[p] = True 


print(ans, was)

Submission status: Accepted

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

miss=0

li=[0 for j in range(n)]
li1=[0 for j in range(n)]

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

    
print(sum(li),miss)

Submission status: Accepted

Solution code:
n,m=[int(i) for i in input().split()]
arr=[0 for i in range(n+1)]
wa=[0 for i in range(n+1)]
ac=0
for i in range(m):
    p,s=input().split()
    p=int(p)
    if arr[p]==1:
        pass
    else:
        if s=='WA':
            wa[p]+=1
        else:
            ac+=1
            arr[p]=1
pen=0
for i in range(n+1):
    if arr[i]==1:
        pen+=wa[i]
print(ac,pen)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ans = set()
WA = [0] * N
flag = [0] * N
for i in range(M):
    q, result = input().split()
    if result == "AC":
        ans.add(int(q))
        flag[int(q)-1] = 1
    else:
        if not int(q) in ans:
            WA[int(q)-1] += 1

WA_tot = 0        
for i in range(N):
    if flag[i] == 1:
        WA_tot += WA[i]
print(len(ans), WA_tot)

Submission status: Accepted

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

dwa = {}
dac = {}
ansac = 0
answa = 0

for m in range(m):
  p, s = map(str, input().split())
  p = int(p)
  if s == 'WA':
    if p in dwa:
      dwa[p] += 1
    else:
      dwa[p] = 1
  if s == 'AC' and p not in dac:
    ansac += 1
    dac[p] = 1
    if p in dwa:
      answa += dwa[p]
    
print(ansac, answa)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
p=[0]*M
S=["a"]*M

x=[0]*N
y=[0]*N
for i in range(M):
  p[i],S[i]=input().split()
  k=int(p[i])-1
  if x[k]==0:
    if S[i]=="WA":
      y[k]+=1
    else:
      x[k]=1
z=sum(x)
w=0
for i in range(N):
  if x[i]==1:
    w+=y[i]
print(z,w)

Submission status: Accepted

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

problem = [False] * n
count_wa = [0] * n


for _ in range(m):
    num, res = input().split()
    num = int(num) - 1

    if res == 'AC':
        problem[num] = True

    else:
        if problem[num] == False:
            count_wa[num] += 1
        else:
            continue

a = sum(problem)
b = 0

for i in range(n):
    if problem[i] == True:
        b += count_wa[i]

print(a, b)

Submission status: Accepted

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

def main():
    ac = 0
    wa = 0
    dic = {}
    cleared = {}
    for p,s in PS:
        if s == "AC" and p not in cleared:
            cleared[p] = True
            if p in dic:
                wa += dic[p]
            ac += 1
        else:
            if p in dic:
                dic[p] += 1
            else:
                dic[p] = 1
    print(ac,wa)
    return 


if __name__ == "__main__":
    main()

Submission status: Accepted

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

problems = [0] * N
ans = [0, 0]

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

print(" ".join(map(str, ans)))

Submission status: Accepted

Solution code:
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

import itertools as it

N, M = two_int()

AC_dicts={}
WA_dicts={}

for i in range(M):
    p, s = input().split()
    
    if p in AC_dicts:
        continue
    
    if s =="AC":
        AC_dicts[p] = 1
        continue
    
    if p not in WA_dicts:
        WA_dicts[p] = 1
    else:
        WA_dicts[p] += 1

wa_sums = 0
for k in AC_dicts.keys():
    if k in WA_dicts:
        wa_sums += WA_dicts[k]



ac_sums = 0
for k,v in AC_dicts.items():
    ac_sums += v


print(str(ac_sums) +" " + str(wa_sums) )

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
D = {}
for i in range(M):
  p, S = map(str, input().split())
  p = p
  if p in D:
    if S == "AC":
      D[p][1] = 1
    if D[p][1] == 0:
      D[p][0] += 1
  else:
    if S == "WA":
      D[p] = [1, 0]
    else:
      D[p] = [0, 1]
SUM41 = 0
SUM42 = 0
for i in D:
  if D[i][1] == 1:
    SUM41 += D[i][0]
    SUM42 += 1
print(SUM42, SUM41)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
p = [False for _ in range(n + 1)]
ze = [0 for _ in range(n + 1)]
ac = 0
wa = 0

for i in range(m):
    string = input().split()
    prob = int(string[0])
    res = string[1]
    if p[prob]:
        pass
    elif res == "AC":
        p[prob] = True
        wa += ze[prob]
        ac += 1
    else:
        ze[prob] += 1

print(ac, wa)

Submission status: Accepted

Solution code:
from collections import defaultdict
N, M = map(int, input().split())

subs = defaultdict(list)
for i in range(M):
    p, s = map(str, input().split())
    p = int(p)
    subs[p].append(s)

ac = 0
pena = 0
for k, v in subs.items():
    wa = 0
    for a in v:
        if a == 'AC':
            ac += 1
            pena += wa
            break
        wa += 1

print(ac, pena)