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 collections

N, M = map(int, input().split())
WA_CNT = {}
CLEAR = {}
for i in range(M):
    P, S = input().split()
    if P in CLEAR:
        continue
    if S == "AC":
        CLEAR[P] = 1
        continue

    if not P in WA_CNT:
        WA_CNT[P] = 0
    WA_CNT[P] += 1


num = len(CLEAR)
try_num = 0
for i in CLEAR:
    if i in WA_CNT:
        try_num += WA_CNT[i]
print("{} {}".format(num, try_num))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
k=[0]*(n+1)
wa_count=0
ac_count=0
for i in range(m):
    p,s=map(str,input().split())
    if s== "AC":
        if k[int(p)]!=-1:
            wa_count=wa_count+k[int(p)]
            k[int(p)]=-1
            ac_count += 1
    else:
        if k[int(p)]!=-1:
            k[int(p)]+= 1
            
ac=str(ac_count)
wa=str(wa_count)
print(ac+" "+wa)

Submission status: Accepted

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

for _ in range(m):
    sub = input().split()
    p, s = int(sub[0]), sub[1]
    lst = prb[p]
    if lst[-1] == 1:
        pass
    elif s == "WA":
        lst.append(0)
    elif s == "AC":
        lst.append(1)
    prb[p] = lst

ac_prb = [lst for lst in prb if lst[-1] == 1]
ac_num = len(ac_prb)
pe_num = -2*ac_num

for prb in ac_prb:
    pe_num += len(prb)

print(ac_num, pe_num)

Submission status: Accepted

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

resultdict = {}
count_ans,count_pena = 0,0

for sub in PS :
    resultdict.setdefault(sub[0],{"AC":0, "WA":0})
    if resultdict[sub[0]]["AC"] == 0 :
        resultdict[sub[0]][sub[1]] += 1

for v in resultdict.values() :
    count_ans += v["AC"]
    if v["AC"] == 1 :
        count_pena += v["WA"]

print(count_ans,count_pena)

Submission status: Accepted

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

ans = [0] * N
AC = 0
WA = 0

for P in Q:
    p = int(P[0])
    S = P[1]
    if ans[p - 1] == "END":
        continue
    if S == "WA":
        ans[p - 1] += 1
    if S == "AC":
        WA += ans[p - 1]
        AC += 1
        ans[p - 1] = "END"


print(AC, WA)

Submission status: Accepted

Solution code:
N,M = map(int, input().split())
r = {}
a = {}
for i in range(M):
    l = input().split()
    p = int(l[0])
    q = l[1]
    w = q + str(p)
    if r.get(p) == 'AC':
        pass
    else:
        r.update([(p, q)])
        if a.get(w) != None:
            a[w] += 1
        else:
            a.update([(w, 1)])
ks = [k for k, v in r.items() if v == 'AC']
wa = 0
ac = 0
for i in ks:
    wk = 'WA' + str(i)
    ak = 'AC' + str(i)
    if a.get(wk) != None:
        wa += a[wk]
    ac += a[ak]
print(ac, wa)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
#if 'AC':{1:-1}
#if 'WA'*2:{1:2}
problems = {}
correct = 0
penalty = 0
for i in range(M):
    p,s = map(str,input().split())
    p = int(p)
   
    if p not in problems.keys():
        if s == 'AC':
            problems[p] = -1
            correct += 1
        else: #if s == 'WA' and not ACed yet 
            problems[p] = 1
    else: 
        if s == 'AC' and problems[p] != -1: #first AC
            penalty += problems[p]
            problems[p] = -1
            correct += 1
        elif s == 'WA' and problems[p] != -1:
            problems[p] += 1
            
print(correct,penalty)

Submission status: Accepted

Solution code:
from collections import defaultdict

n, m = map(int, input().split())
ac_dict = defaultdict(int)
wa_dict = defaultdict(int)
ac_p, wa_p = set(), set()
for _ in range(m):
    p, s = input().split()
    p = int(p)
    if s == 'AC':
        ac_p.add(p)
        ac_dict[p] = 1
    elif ac_dict[p] != 1:
        wa_p.add(p)
        wa_dict[p] += 1

wa = 0
for pi in ac_p:
    wa += wa_dict[pi]

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

Submission status: Accepted

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

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

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

    if s=="AC":
        ac[p]=True
    else:
        if not ac[p]:
            wa[p]+=1

a=0
b=0

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

print(a,b,sep=" ")

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
dp=[0]*(n+1)
charge=[0]*(n+1)
cnt=0
ans=0
for i in range(m):
  q=input()
  if dp[int(q[:-3])]!="A" and q[-2]=="W":
    dp[int(q[:-3])]="W"
    charge[int(q[:-3])]+=1
  elif dp[int(q[:-3])]!="A" and q[-2]=="A":
    dp[int(q[:-3])]="A"
    ans+=1
    cnt+=charge[int(q[:-3])]
    charge[int(q[:-3])]=0
print(ans,cnt)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(100000)


def main():
    n, m = [int(i) for i in input().strip().split()]
    accepted = [False] * (n + 1)
    WA_cnt = [0] * (n + 1)
    for _ in range(m):
        p, s = input().strip().split()
        p = int(p)
        if accepted[p]:
            continue
        else:
            if s == "AC":
                accepted[p] = True
            elif s == "WA":
                WA_cnt[p] += 1
    ac = 0
    wa = 0
    for res, cnt in zip(accepted, WA_cnt):
        if res:
            ac += 1
            wa += cnt

    print(ac, wa)

    return


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float("inf")


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    ac = [0 for _ in range(N)]
    for i in set(x[0] for x in zip(p, S) if x[1] == "AC"):
        ac[i - 1] = 1
    wa = 0
    for x in zip(p, S):
        ac[x[0] - 1] &= x[1] == "WA"
        wa += ac[x[0] - 1]
    return f'{len(set(x[0] for x in zip(p,S) if x[1] == "AC"))} {wa}'


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    p = [int()] * (M)  # type: "List[int]"
    S = [str()] * (M)  # type: "List[str]"
    for i in range(M):
        p[i] = int(next(tokens))
        S[i] = next(tokens)
    print(f"{solve(N, M, p, S)}")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from collections import defaultdict


def mapt(fn, *args):
    return tuple(map(fn, *args))

  
def main():
    n, m = mapt(int, input().split(" "))
    # if m == 0: print(0, 0); exit()
    ac = defaultdict(int)
    pena = defaultdict(int)
    for _ in range(m):
        index, symbol = input().split(" ")
        index = int(index)
        index -= 1
        if ac[index]: continue

        if symbol == "AC": ac[index] = 1
        elif symbol == "WA": pena[index] += 1
    # print(ac, pena)
    AC = PENA = 0
    for i in range(n):
        AC += ac[i]
        if ac[i]: PENA += pena[i]
    print(AC, PENA)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = map( int, input().split() )
p = []
s = []
for _ in range( m ):
    p_i, s_i = input().split()
    p.append( int( p_i ) )
    s.append( str( s_i ) )

aced = [ False for _ in range( n ) ]
wa_cnt = [ 0 for _ in range( n ) ]

for i in range( m ):
    if s[ i ] == "AC":
        aced[ p[ i ] - 1 ] = True
    elif aced[ p[ i ] - 1 ] == False:
        wa_cnt[ p[ i ] - 1 ] += 1

ac_cnt = 0
penalty = 0

for i in range( n ):
    if aced[ i ] == True:
        ac_cnt += 1
        penalty += wa_cnt[ i ]

print( ac_cnt, penalty )

Submission status: Accepted

Solution code:
import sys, bisect, math, itertools, string, queue, copy
import numpy as np
import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n,m = inpm()

P = []
S = []
for i in range(m):
    tmp = input().split()
    P.append(int(tmp[0]))
    S.append(tmp[1])

AC = [0]*100001
WA = [0]*100001

for i in range(m):
    if S[i] == 'AC':
        AC[P[i]] = 1
    elif S[i] == 'WA' and AC[P[i]] != 1:
        WA[P[i]] += 1

cnt_ac = 0
cnt_wa = 0
for i in range(1,n+1):
    if AC[i] == 1:
        cnt_ac += 1
        cnt_wa += WA[i]

print(cnt_ac,cnt_wa)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, M = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    S = tuple(tuple(input().split()) for i in range(M)) #改行行列
    l=[0]*N
    was=[0]*N
    for p,s in S:
        p=int(p)-1
        if s=="AC":
            l[p]=1
        else:
            if not l[p]:
                was[p]+=1
    wa=0
    for i in range(N):
        if l[i]:
            wa+=was[i]
            
    print(sum(l),wa)




if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans, pen = 0, 0
for i in range(n):
    if ac[i]:
        ans += 1
        pen += wa[i]
print(ans, pen)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
if m != 0:
    l = [list(input().split()) for i in range(m)]
    p,s = [list(i) for i in zip(*l)]
t = [0] * n
ac = 0
wa = 0
for i in range(m):
    if s[i] == 'WA' and t[int(p[i])-1] != 'AC':
        t[int(p[i])-1] += 1
    elif s[i] == 'AC' and t[int(p[i])-1] != 'AC':
        ac += 1
        wa += t[int(p[i])-1]
        t[int(p[i])-1] = 'AC'
    else:
        pass
print(ac,wa)

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict

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

is_ac = [False] * N
wa = [0] * N

for i in range(M):
    p, S = input().split()
    n = int(p) - 1
    if not is_ac[n] and S == "AC":
        is_ac[n] = True
    if not is_ac[n] and S == "WA":
        wa[n] += 1

cnt_ac = is_ac.count(True)
cnt_wa = 0
for i in range(N):
    if is_ac[i]:
        cnt_wa += wa[i]
print(cnt_ac, cnt_wa)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[0 for i in range(n)]
penalty=[0 for i in range(n)]
acc=0
for i in range(m):
  a,b=input().split()
  a=int(a)
  a-=1

  if (p[a]==0 or p[a]=='WA') and b=='AC':
    acc+=1
    p[a]='AC'
  elif (p[a]==0 or p[a]=='WA') and b=='WA':
    penalty[a]+=1
    p[a]='WA'

for i in range(n):
  if p[i] == 'WA' or p[i] == 0:
    penalty[i]=0

print(acc,sum(penalty))

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
a=[[0,0] for _ in range(n+1)]
x=[]
for i in range(m):
    x.append(list(input().split()))
    x[i][0]=int(x[i][0])
for i in range(m):
    if x[i][1]=="AC":
        a[x[i][0]][1]=1
    else:
        if a[x[i][0]][1]==1:
            continue
        else:
            a[x[i][0]][0]+=1
c=0
d=0
for i in range(n+1):
    c+=a[i][1]
    if a[i][1]:
        d+=a[i][0]
print(c,d)

Submission status: Accepted

Solution code:

n, m = (int(x) for x in input().split())

# 0 = まだACなし, 1 = AC済み
ans_list = [0] * (n + 1)
# 誤った回数が記録され、ACのタイミングで加算
WA_list = [0] * (n + 1)

ans = 0
penalty = 0

for id in range(m):
    # listを紐付けて要素を抜き出すことができる
    query = list(map(str, input().split()))
    # ACだった場合
    if query[1] == 'AC':
        if ans_list[int(query[0])] == 0 :
            ans_list[int(query[0])] = 1
            ans += 1
            penalty = penalty + WA_list[int(query[0])]
    # WAだった場合 
    else:
        if ans_list[int(query[0])] == 0 :
            WA_list[int(query[0])] += 1

print("{0} {1}".format(ans, penalty))

Submission status: Accepted

Solution code:
def main():
  N, M = list(map(lambda n: int(n), input().split(" ")))
  if M == 0:
    print("0 0")
    return 0

  AC = [0] * N
  WA = [0] * N

  for i in range(M):
    tmp = input().split(" ")
    No = int(tmp[0]) - 1
    if tmp[1] == "AC":
      AC[No - 1] = 1
    if tmp[1] == "WA" and AC[No - 1] == 0:
      WA[No - 1] += 1
  
  totAC = sum(AC)
  totWA = sum([AC[i] * WA[i] for i in range(len(AC))])
  print(totAC, end=" ")
  print(totWA)
    
main()

Submission status: Accepted

Solution code:
import numpy as np

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

P = []
S = []

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

AC = np.zeros(N)
WA = np.zeros(N)

for i in range(M):
    if AC[P[i]-1] == 0:
        if S[i] == 'WA':
            WA[P[i]-1] += 1
        else:
            AC[P[i]-1] += 1

WA[AC == 0] = 0

print(int(sum(AC)), int(sum(WA)))

Submission status: Accepted

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

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

for _ in range(m):
    p, s = input().split()
    p = int(p)
    if ac_done[p-1]:
        continue
    else:
        if s == 'AC':
            ac += 1
            wa += l[p-1]
            ac_done[p-1] = True
        else:
            l[p-1] += 1 

print(ac,wa)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
a = [False] * N
w = [0] * N
for i in range(M):
    p, S = input().split()
    if S == 'AC':
        a[int(p)-1] = True
    elif not a[int(p)-1]:
        w[int(p)-1] += 1
print(a.count(True), sum([w[i] if a[i] else 0 for i in range(N)]))

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    P = [0] * M
    S = [""] * M
    for i in range(M):
        PS = input().split()
        P[i], S[i] = int(PS[0]), PS[1]

    AC = [False] * (N + 1)
    WA = [0] * (N + 1)
    n_AC = 0
    n_WA = 0
    for p, s in zip(P, S):
        if AC[p]:
            continue
        if s == "AC":
            n_AC += 1
            AC[p] = True
            n_WA += WA[p]
        else:
            WA[p] += 1

    print(n_AC, n_WA)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
lst = [input().split() for _ in range(M)]
pe = [0] * N #結果的なWA数
wa = [0] * N #現在のWA数（ACしたら-1）

for l in lst:
    if l[1] == "WA" and wa[int(l[0])-1] != -1:
        #未ACでWA
        wa[int(l[0])-1] += 1
    if l[1] == "AC" and wa[int(l[0])-1] != -1:
        #はじめてAC
        pe[int(l[0])-1] = wa[int(l[0])-1]
        wa[int(l[0])-1] = -1

ans = []
ans.append(str(wa.count(-1)))
ans.append(str(sum(pe)))
print(" ".join(ans))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
PS = [input().split() for _ in range(M)]
Pena = [0] * (N+1)
pena = 0
ac = 0
for p, s in PS:
    p = int(p)
    if s == "AC":
        if Pena[p] >= 0:
            ac += 1
            pena += Pena[p]
            Pena[p] = -999999999
    else:
        Pena[p] += 1
print(ac, pena)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
prob = [0]*n
AC = 0
WA = 0
for _ in range(m):
    p, s = input().split()
    p = int(p)
    if prob[p-1] == -1:
        continue
    if s == 'WA':
        prob[p-1] += 1
    else:
        WA += prob[p-1]
        AC += 1
        prob[p-1] = -1
print(AC, WA)

Submission status: Accepted

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

for i in range(m):
    p,s = input().split()
    p = int(p)
    if ac[p-1]:
        continue
    
    if s == "WA":
        wa[p-1] += 1
    else:
        ac[p-1] = True
        count_ac += 1
        count_wa += wa[p-1]
        
print(count_ac,count_wa)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
corret_list = [False] * (N+1)
wa_number = [0] * (N+1)
true_ans = 0
penalty = 0
for _ in range(M):
    P, S = input().split()
    P = int(P)
    if S == 'AC':
        if not corret_list[P]:
            true_ans += 1
            corret_list[P] = True
            continue
        else:
            continue
    else:
        if not corret_list[P]:
            wa_number[P] += 1
            continue
for i in range(len(corret_list)):
    if corret_list[i]:
        penalty += wa_number[i]
print(true_ans, penalty)

Submission status: Accepted

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

ac = [False] * N
wa = [0] * N
for _ in range(M):
    p, S = input().split()
    p = int(p) - 1
    if S == 'AC':
        ac[p] = True
    else:
        if not ac[p]:
            wa[p] += 1

a = 0
b = 0
for i in range(N):
    if ac[i]:
        a += 1
        b += wa[i]
print(*[a, b])

Submission status: Accepted

Solution code:
from collections import defaultdict

def main():
    N, M = map(int, input().split())
    a = [input().split() for _ in range(M)]
    ac_count = [0] * (N + 1)
    wa_count = defaultdict(lambda:0)
    ac, wa = 0, 0

    for q_no, ans in a:
        q_no = int(q_no)
        if ac_count[q_no] == 0:
            if ans == "AC":
                ac_count[q_no] = 1
                ac += 1
                wa += wa_count.get(q_no, 0)
            else:
                wa_count[q_no] += 1
    
    print(ac, wa)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

AC=[0]*(N+1)
WA=[0]*(N+1)
ans=0
for _ in range(M):
    p,s=input().split()
    p=int(p)
    if AC[p]==0:
       if s=='AC':
            AC[p]=1
            ans+=WA[p]
       else:
            WA[p]+=1
print(sum(AC),ans)

Submission status: Accepted

Solution code:
N,M,*f = open(0).read().split()
N = int(N)
M = int(M)
pS = [f[i*2:i*2+2] for i in range(M)]
accepted = [0] * (N+1)
wrong = [0] * (N+1)
penalty = [0] * (N+1)
for p,S in pS:
    i = int(p)
    if accepted[i] == 0:
        if S == 'AC':
            penalty[i] = wrong[i]
            accepted[i] = 1
        else:
            wrong[i] += 1
print(sum(accepted),sum(penalty))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
p = [0] * M
S = ['a'] * M
for i in range(M):
    p[i], S[i] = input().split()
    p[i] = int(p[i])

ansac = pen = 0
answa = [0] * N
flg = [0] * N

for i in range(M):
    if flg[p[i]-1] == 1:
        continue
    if S[i] == 'WA':
        answa[p[i]-1] += 1
    elif S[i] == 'AC':
        ansac += 1
        pen += answa[p[i]-1]
        flg[p[i]-1] = 1

print(ansac, pen)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
p = [0] * M
S = ['a'] * M
for i in range(M):
    p[i], S[i] = input().split()
    p[i] = int(p[i])

answa = 0
flg = [0] * N

for i in range(M):
    if flg[p[i]-1] == 1:
        continue
    if S[i] == 'WA':
        flg[p[i]-1] -= 1
    elif S[i] == 'AC':
        answa -= flg[p[i]-1]
        flg[p[i]-1] = 1

print(flg.count(1), answa)

Submission status: Accepted

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

ac_cnt = 0
wa_cnt = 0
d = {}

for _ in range(m):
  p, s = input().split()
  if p not in d:
    d[p] = [s]
  else:
    d[p].append(s)
    
for i in d:
  if 'AC' in d[i]:
    ac_cnt += 1
    wa_cnt += d[i].index('AC')
print(ac_cnt, wa_cnt)

Submission status: Accepted

Solution code:
import sys
N, M = map(int, input().split())
ac = [0] * N
wa = [0] * N

for _ in range(M):
    p, s = sys.stdin.readline().split()
    p = int(p) - 1
    if s == "AC":
        ac[p] = 1
    else:
        if not ac[p]:
            wa[p] += 1
acnum = sum(ac)
wanum = sum([c for i, c in enumerate(wa) if ac[i] == 1])
print(acnum, wanum)

Submission status: Accepted

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

C={}
acc=0
wac=0
for i in range(m):
    p0,s = input().split()
    
    p = int(p0)
    if p in C :
        if C[p]!=-1:
            C[p]+=1
    else:
        C[p]=1

    if s=="AC" and C[p]!=-1:
        acc+=1
        wac+=C[p]-1
        C[p]=-1
        

print( acc, wac )

Submission status: Accepted

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

for  i in range(M):
    p,S=map(str,input().split())
    p=int(p)
    if S=='AC':
        acs[p-1]=1
    elif S=='WA' and acs[p-1]==0: 
        wa[p-1]+=1
for i in range(N):
    if acs[i]==0:
        wa[i]=0
ans=[sum(acs),sum(wa)]
print(*ans)

Submission status: Accepted

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

print(a.count(1),wa)

Submission status: Accepted

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

ac = wa = 0
ac_lis = [False] * N
wa_cnt = [0] * N
for _ in range(M):
  p, s = input().split()
  p = int(p) - 1

  if s == "AC":
    if not ac_lis[p]:
      ac += 1
      wa += wa_cnt[p]
      ac_lis[p] = True
  else:
    if not ac_lis[p]:
      wa_cnt[p] += 1

print(ac, wa)

Submission status: Accepted

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

AC=[0]*(N+1)
WA=[0]*(N+1)
ans=0
for _ in range(M):
    p,s=input().split()
    p=int(p)
    if AC[p]==0:
       if s=='AC':
            AC[p]=1
            ans+=WA[p]
       else:
            WA[p]+=1
print(sum(AC),ans)

Submission status: Accepted

Solution code:
n,m=list(map(int,input().split()))
ps=[input().split() for _ in range(m)]
plst=[0]*n
penlst=[0]*n
pen=0
ans=0

for p,s in ps:
    p=int(p)-1
    if plst[p]:
        continue
    if s=='AC':
        ans+=1
        pen+=penlst[p]
        plst[p]=1
    else:
        penlst[p]+=1

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

Submission status: Accepted

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

for i in range(m):
    p,s =  map(str,input().split())
    p = int(p)
    if s == "AC" and a[p-1] !=-1:
        ac +=1
        wa += a[p-1]
        a[p-1] = -1
    elif s =="WA" and a[p-1] != -1:
        a[p-1] += 1
print(ac,wa)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AC = N*[0]
WA = N*[0]

for m in range(M):
  P,S = input().split()
  P = int(P)-1
  
  if AC[P]==1:
    continue
  if S=="WA":
    WA[P]+=1
  else:
    AC[P]=1

wa = 0 
for a,w in zip(AC,WA):
  wa+=w*a

print(sum(AC),wa)

Submission status: Accepted

Solution code:
import sys
input()
ac,wa={*()},{}
nc=np=0
for ln in sys.stdin:
    p,S=ln.split()
    if p in ac:
        continue
    if p not in wa:
        wa[p]=0
    if S=='AC':
        ac.add(p)
        nc+=1
        np+=wa[p]
    else:
        wa[p]+=1

print(nc,np)

Submission status: Accepted

Solution code:
import sys
input()
d={}
nc=np=0
for ln in sys.stdin:
    p,S=ln.split()
    if p not in d:
        d[p]=[0,0]
    if not d[p][0]:
        if S=='AC':
            d[p][0]=1
            nc+=1
            np+=d[p][1]
        else:
            d[p][1]+=1

print(nc,np)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
AC = set()
WA = {}

for _ in range(M):
	p, S = input().split()
	p = int(p)
	if S == 'AC':
		AC.add(p)
	else:
		if p not in AC:
			if p in WA:
				WA[p] += 1
			else:
				WA[p] = 1
wa = 0
for k, v in WA.items():
	if k in AC:
		wa += v

print(len(AC), wa)

Submission status: Accepted

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

acdic = {}

wadic = [0] * 10 ** 5

ac = 0
wa = 0

for ps in PS:
    p = int(ps[0])
    s = ps[1]

    if not p in acdic:
        if s == "WA":
            wadic[p] += 1
        else:
            ac += 1
            acdic[p] = True
            wa += wadic[p]


print(ac, wa)

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
List = []
for i in range (M):
  List.append(list(map(str, input().split())))
resList= [False]*N
res = 0
waList = [0]*N
for i in range(M):
  if resList[int(List[i][0])-1] == False:
    if List[i][1] == "AC":
      resList[int(List[i][0])-1] = True
      res += waList[int(List[i][0])-1] 
    else:
      waList[int(List[i][0])-1] += 1
print(resList.count(True),res)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
ac = 0
pena = 0
count = [0 for _ in range(N+1)]
for _ in range(M):
  p, S = input().split()
  p = int(p)
  if S == 'AC':
    if count[p] > -1:
      pena += count[p]
      ac += 1
    count[p] = -10**5-1
  else:
    count[p] += 1
  
print(ac, pena)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline
_, m = map(int, input().split())

d = {}
for _ in range(m):
    p, s = input().split()
    p = int(p)
    if p in d:  # やっている(やった)問題
        if d[p][0]:  # AC済の問題だった場合
            continue
        if s == "WA":
            d[p][1] += 1
        else:
            d[p][0] = True
    else:  #  初めての問題
        if s == "WA":
            d[p] = [False, 1]  # 中身：AC判定と、ACまでのWAの数
        else:
            d[p] = [True, 0]

cnt_ac = 0
cnt_wa = 0
for v in d.values():
    if v[0]:
        cnt_ac += 1
        cnt_wa += v[1]

print(cnt_ac, cnt_wa)

Submission status: Accepted

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

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

solved = [False] * (n + 1)
wa = [0] * (n + 1)

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


ac = 0
pe = 0

for i in range(1, n+1):
    if solved[i]:
        ac += 1
        pe += wa[i]

print(ac, pe)

Submission status: Accepted

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

dic = {}
for p, s in pss:
    if p not in dic:
        dic[p] = (0, 0)
    ac, wa = dic[p]
    if ac == 0 and s == 'AC':
        dic[p] = (ac + 1, wa)
    elif ac == 0 and s == 'WA':
        dic[p] = (ac, wa + 1)

dic = {k:dic[k] for k in dic if dic[k][0] == 1}

ac = sum(dic[k][0] for k in dic)
wa = sum(dic[k][1] for k in dic)
print(ac, wa)