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 sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# 最大公約数 
def gcd(a, b):
  if a < b:
      a, b = b, a
  while a % b != 0:
      a, b = b, a % b
  return b

# 最小公倍数
def lcm(a, b):
  y = a*b / gcd(a, b)
  return int(y)

n, m = MAP()


L = []
for i in range(m):
  l = S_LIST()
  L.append(l)

# wa

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


for i in range(m):
  p = int(L[i][0])-1
  ans = L[i][1]
  if ans == "WA":
    # まだacない
    if ac[p] == 0:
      wa[p] = wa[p] + 1
  # acあった
  if ans == "AC":
    ac[p] = 1

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


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


# for p in range(1, n+1):
#   if L[i][0] == str(p):
#     for i in range(m):
#       if L[i][1] == "WA":
#         wa += 1

#     for i in range(m):
#       if L[i][1] == "AC":
#         ac += 1
#   print(wa)
#   print(ac)

Submission status: Accepted

Solution code:
import sys
import numpy as np

n, m = input().split()
i = [input() for i in range(int(m))]

n_l = [False] * int(n)
w_l = [0] * int(n)

for i_s in i:
    p, c = i_s.split()
    p = int(p) - 1
    if n_l[p] == 1:
        continue

    if c == "AC":
        n_l[p] = True
    else:
        w_l[p] += 1

n_l = np.array(n_l)
w_l = np.array(w_l)
w_l = w_l[n_l]

print("{} {}".format(n_l.sum(), w_l.sum()))

Submission status: Accepted

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

q=['WA' for i in range(n)]
w=[0 for i in range(n)]
ans=0
pen=0
for i in range(m):
    p,s=input().split()
    pi=int(p)-1
    if s=='AC' and q[pi]=='WA':
        ans+=1
        pen+=(w[pi])
        q[pi]='AC'
    else:
        w[pi]+=1
        

        
print(ans,pen)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
N = a[0]
M = a[1]

list = []
for i in range(M):
  a,b=input().split()
  list.append((int(a), b))

bool_ac = []
ac_sum = 0
wa = []
wa_sum = 0
for i in range(N):
  bool_ac.append(0)
  wa.append(0)


for i in range(M):
  j = list[i][0] - 1
  if list[i][1] == "AC" and bool_ac[j] != 1:
    bool_ac[j] = 1
    ac_sum += 1
    wa_sum += wa[j]
  elif list[i][1] == "WA":
    if bool_ac[j] == 0:
      wa[j] += 1

print(ac_sum, end=" "), print(wa_sum)

Submission status: Accepted

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

WA = [0 for i in range(N+1)]
AC = [0 for i in range(N+1)]

for i in range(M):
    if PS[i][1] == "WA":
        if AC[PS[i][0]] == 0:
            WA[PS[i][0]] += 1
    else:
        AC[PS[i][0]] = 1

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

print(str(cor)+" "+str(pen))

Submission status: Accepted

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

a = [0]*(n+10)
w = [0]*(n+10)

for i in range(0, m):
    p, s = input().split()
    p = int(p)
    if ((s == "AC")&(a[p] == 0)):
        a[p] += 1
    if ((s == "WA")&(a[p] == 0)):
        w[p] += 1
ac = 0
wa = 0
for i in range(0, n+10):
    ac += a[i]
    if a[i]==1:
        wa += w[i]
print(str(ac)+" "+str(wa))

Submission status: Accepted

Solution code:
N,M=map(int,input().split())
if (M == 0):
    print(0,0)
    exit()
wacount = [0] * N
account = [0] * N
for idx in range(M):
    p,s=input().split()
    if (s =="WA" and account[int(p) -1] == 0):
        wacount[int(p) -1] += 1
    if (s == 'AC' and account[int(p)-1] == 0):
        account[int(p) -1] += 1

for idx in range(N):
    if (account[idx] == 0):
        wacount[idx] = 0
print(sum(account),sum(wacount))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
a=[]
ac_list = [0]*N
wa_list= [0]*N
count_wa = 0
for i in range(M):
    p,s=input().split()
    p = int(p) - 1
    if ac_list[p] == 0:
        if s == 'WA':
            wa_list[p] += 1
        else:
            ac_list[p] = 1
for i in range(N):
    if ac_list[i] == 1:
        count_wa += wa_list[i]

print(sum(ac_list),count_wa)

Submission status: Accepted

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

pn_num=0
WA_list=[0]*N
AC_list=[0]*N

for _ in range(M):
    pi,Si=input().split()
    pi=int(pi)
        
    if Si=='AC':
        if AC_list[pi-1]==0:
            pn_num+=WA_list[pi-1]
            AC_list[pi-1]=1
    
    else:
        WA_list[pi-1]+=1
    
print(sum(AC_list),pn_num)

Submission status: Accepted

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

lac = [0] * n
lwa = [0] * n

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

lwa = [x * y for x, y in zip(lac, lwa)]
print(sum(lac), sum(lwa))

Submission status: Accepted

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

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

WAs = [0] * n
correct = 0
penalty = 0
for i in range(m):
    p, s = input().strip().split(' ')
    p = int(p) - 1
    if WAs[p] == -1:
        continue
    if s == 'AC':
        penalty += WAs[p]
        correct += 1
        WAs[p] = -1
    else:
        WAs[p] += 1

print(correct, penalty)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#other's code
N,M=map(int,input().split())
 
ac = 0
wa = 0
aclist = {}
walist = {}

for i in range(N):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]

print(ac,wa,sep=" ")

Submission status: Accepted

Solution code:
a,b=map(int,input().split())
wa={i:0 for i in range(1,a+1)}
ac={i:0 for i in range(1,a+1)}
g=0
pe=0
if b==0:
    print("0 0")
    g=1
for i in range(b):
    c,d=input().split()
    
    if d=="WA" and ac[int(c)]==0:
        wa[int(c)]+=1
        
    if d=="AC" and ac[int(c)]==0:
        pe+=wa[int(c)]
        ac[int(c)]=1
    
        
f=0
h=0
if g==0:
    
    print(str(sum(ac.values()))+" "+str(pe))

Submission status: Accepted

Solution code:
s=[]
lis=[]
N,M=map(int, input().split())
wacount=0
account=0
count=0
zero=0
flag=1
cur=0
changeflag=1
#s=[list(input()) for i in range(2)] 
#for range(M):
#print(N,M)
 
for i in range(M):
     lis=input().split()
     #print(lis)
     lis[0]=int(lis[0])
     lis.append(i)
     #print(lis)
     s.append(lis)
 
s2=sorted(s,key=lambda x:x[0])
sorted(s2,key=lambda x:x[2])
j=1
for i in range(len(s2)):
    if s2[i][0]>j:
        j=s2[i][0]
        flag=1
        count=0
    if (s2[i][0]==j)and(flag==1):
        if s2[i][1]=="WA":
            count=count+1
        elif s2[i][1]=="AC":
            account=account+1
            wacount=wacount+count
            flag=0
            count=0
                
print(account,wacount)

Submission status: Accepted

Solution code:
from collections import defaultdict

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

ac = set()
wa = defaultdict(int)
ttl_wa = 0

for _ in range(M):
    pi, st = input().split()
    pi = int(pi)

    if st == 'AC':
        if pi not in ac:
            ac.add(pi)
            ttl_wa += wa[pi]
    else: # st == 'WA'
        wa[pi] += 1

print(len(ac), ttl_wa)

Submission status: Accepted

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

for _ in range(M):
  p_str, s = map(str, input().split())
  p = int(p_str)
  if ac[p-1] == 1:
    continue
  if s == 'AC':
    ac[p-1] = 1
  if s == 'WA':
    wa[p-1] += 1

result = [x * y for (x, y) in zip(ac, wa)]
AC = sum(ac)
WA = sum(result)

print(AC, WA)

Submission status: Accepted

Solution code:
from itertools import groupby
N, M  =map(int, input().split())
ps = [[] for i in range(M)]
for i in range(M):
    ps[i] = list(input().split())
if M == 0:
    print(0,0)
    exit()
newps = sorted(ps,key=lambda i:i[0]) 
newpslist = list([list(g) for k, g in groupby(newps, key = lambda i:i[0])])
countAC = 0
counterror = 0
for group in newpslist:
    subcounterror = 0
    for subgroup in group:
        if subgroup[1] == 'WA':
            subcounterror += 1
        else:
            countAC += 1
            counterror += subcounterror
            break    
print(countAC, counterror)

Submission status: Accepted

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

a = [0] * (n+1)
b = [0] * (n+1)

c = 0

for i in [0]*(m):

    s = input().split()

    if a[int(s[0])] == 0:
        if s[1] == "AC":
            a[int(s[0])] = 1
            c += b[int(s[0])]
        else:
            b[int(s[0])] += 1

print(sum(a), c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
F_str = input().split()
F = [int(f) for f in F_str]
N = F[0]
M = F[1]

WA_list = [0 for _ in range(N)]
AC_list = [0 for _ in range(N)]

for i in range(M):
    S_str = input().split()
    S = [str(s) for s in S_str]
    if(S[1] == "AC"):
        AC_list[int(S[0])-1] = 1
    elif(AC_list[int(S[0])-1] != 1):
        WA_list[int(S[0])-1] += 1

WA_count = 0
AC_count = 0

for i in range(N):
    if(AC_list[i] == 1):
        AC_count += 1
        WA_count += WA_list[i]

print(AC_count, WA_count)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
li = []
for i in range(m):
  li.append(list(input().split()))
li_a = [0 for i in range(n)]
li_b = [0 for i in range(n)]
a = 0
b = 0
for j in range(m):
  if li[j][1] == "WA":
    li_b[int(li[j][0])-1] += 1
  elif li[j][1] == "AC" and li_a[int(li[j][0])-1] == 0:
    a += 1
    b += li_b[int(li[j][0])-1]
    li_a[int(li[j][0])-1] += 1
print(a, b)

Submission status: Accepted

Solution code:
from collections import OrderedDict
n, m = map(int,input().split())

aclist = [0]*n
walist = [0]*n
ac = 0
wa = 0
for i in range(m):
  pp, s = input().split()
  p = int(pp) - 1
  if s == 'AC' and not aclist[p]:
    aclist[p] = 1
    ac += 1
    wa += walist[p]
  else:
    walist[p] += 1
  

print(ac, wa)

Submission status: Accepted

Solution code:
N, M = list(map(int, input().split()))
lst = [input().split() for lst in range(M)]
pn = 0
lst_pn = []
lst_cr = []
for _ in range(N):
  lst_pn.append(0)
  lst_cr.append(0)
cr = 0
for i in lst:
  a = int(i[0])
  if lst_cr[a-1] == 1:
    continue
  elif i[1] == "WA":
    lst_pn[a-1] += 1
  elif i[1] == "AC":
    cr += 1
    lst_cr[a-1] += 1
    pn += lst_pn[a-1]
print(cr, pn)

Submission status: Accepted

Solution code:
def main():
    n, m = [int(i) for i in input().split()]
    wa = [0]*n
    ac = [0]*n
    
    for _ in range(m):
        p, s = input().split()
        if s == "WA":
            if ac[int(p)-1] == 0:
                wa[int(p)-1] += 1
        else:
            ac[int(p)-1] += 1
    
    print(n-ac.count(0), sum([wa[i] for i in range(n) if ac[i] >= 1]))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
init = input().split(" ")
n = int(init[0])
m = int(init[1])

class problem():
  right_or_wrong = 0
  mistake = 0
  
  def set_right(self):
    self.right_or_wrong = 1
  
  def set_wrong(self):
    self.mistake += 1
  
  def check(self, result):
    if result == "AC":
      self.set_right()
    elif result == "WA" and self.right_or_wrong == 0:
      self.set_wrong()

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

result = {}
for i in range(m):
  score = input().split(" ")
  p = int(score[0])
  s = score[1]
  if p not in result:
    result[p] = problem()
  result[p].check(s)

ans = [0, 0]
for v in result.values():
  if v.right_or_wrong == 1:
    ans[0] += 1
    ans[1] += v.mistake

print(" ".join([str(i) for i in ans]))

Submission status: Accepted

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

ok, ng = (0, 0)
oks = set()
ngdict = dict()
for _ in range(M):
    pp, S = input().split()
    p = int(pp)
    if p in oks:
        continue
    if S == 'AC':
        ok += 1
        ng += ngdict.get(pp, 0)
        oks.add(p)
    else:
        ngdict[pp] = ngdict.get(pp, 0) + 1

print('{} {}'.format(ok, ng))

Submission status: Accepted

Solution code:
n,m=input().split()
n=int(n)
m=int(m)
x=[False for i in range(n)]
count=[0 for i in range(n)]
for i in range(m):
  p,s=input().split()
  p=int(p)
  if(not x[p-1]):
    if(s=="AC"):
      x[p-1]=True
    else:
      count[p-1]=count[p-1]+1
ans=0
ans2=0
for i in range(n):
  if(x[i]):
    ans+=1
    ans2+=count[i]
print(ans,ans2)

Submission status: Accepted

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

an1=0
an2=0
li=[0]*n

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

for i in range(m):
    p,s=map(str,input().split())
    p=int(p)
    
    if s=="WA":
        if li[p-1]!=-1:
            li[p-1]+=1
    else:
        if li[p-1]!=-1:
            an1+=1
            an2+=li[p-1]
            li[p-1]=-1

print(an1,an2)

Submission status: Accepted

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

AC = [False] * (N+1)
WA_cnt = [0] * (N+1)

penal = 0
for _ in range(M):
    p,s = map(str,input().split())
    p = int(p)
    if AC[p]:
        continue
    if s == "WA":
        WA_cnt[p] += 1
    else:
        AC[p] = True
        penal += WA_cnt[p]

ac = sum(AC)
print(ac, penal)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AC = 0
WA = 0
lis = [0] * N
for i in range(M):
  a,b = input().split()
  if lis[int(a)-1] < 0:
    pass
  elif b == 'AC':
    WA += lis[int(a)-1]
    AC += 1
    lis[int(a)-1] = -1
  else:
    lis[int(a)-1] += 1
print(AC, WA)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
ps = []
for i in range(m):
    p, s = input().split()
    ps.append([int(p), s])
flag = [False for _ in range(n)]
ac = [0 for _ in range(n)]
wa = [0 for _ in range(n)]
i = 0
sumac = 0
sumwa = 0

for i in range(m):
    p = ps[i][0]
    s = ps[i][1]
    if s == "WA" and ac[p - 1] == 0:
        wa[p - 1] += 1
    elif s == "AC" and ac[p - 1] == 0:
        ac[p - 1] += 1
        sumac += 1
        sumwa += wa[p - 1]

print(str(sumac) + " " + str(sumwa))

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
A = [input().split() for i in range(M)]
problems = {}
rejected = [0]*(N+1)
reject_count = 0
for P, S in A:
    P = int(P)
    if not problems.get(P):
        if S != 'AC':
            rejected[P] += 1
        else:
            problems[P] = S
for i in range(N+1):
    if problems.get(i):
        reject_count += rejected[i]
print(len(problems), reject_count)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
cnt1=[0]*(n+1)
cnt2=[0]*(n+1)
for _ in range(m):
  p,s=map(str,input().split())
  p=int(p)
  if cnt1[p]==1:
    continue
  else:
    if s=='AC':
      cnt1[p]=1
    else:
      cnt2[p]+=1
ans1=0
ans2=0
for i in range(1,n+1):
  if cnt1[i]==1:
    ans1+=1
    ans2+=cnt2[i]
print(ans1,ans2)

Submission status: Accepted

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

PS = {}
for _ in range(m):
    p, s = input().split()
    try:
        PS[int(p)].append(s)
    except KeyError:
        PS[int(p)] = [s]

a, b = 0, 0
for S in PS.values():
    if "AC" in S:
        for s in S:        
            if s == "AC":
                a += 1
                break
            if s == "WA":
                b += 1

print(a, b)

Submission status: Accepted

Solution code:
import numpy as np

N,M = map(int,input().split())
OK = np.zeros(N, dtype = int)
NG = np.zeros(N, dtype = int)
for i in range(M):
    p,s = map(str,input().split())
    p = int(p)
    if s == 'AC':
        s = 1
        OK[p-1]=1
    else:
        if OK[p-1]==0:
            NG[p-1]+=1
    
cOK = sum(OK)
cNG = sum(NG[OK==1])

print(cOK, cNG)

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
p=[];s=[]
if m==0:
    print(0,0)
    exit()
for i in range(m):
    x,y=input().split()
    p.append(int(x))
    s.append(y)
ac=0
wa=0
t=[0]*(n+1)
wf=[0]*(n+1)
for i in range(m):
    if t[p[i]]>=1:
        continue
    elif s[i]=="WA":
        wf[p[i]]+=1
    elif s[i]=="AC":
        t[p[i]]+=1
        ac+=1
        wa+=wf[p[i]]
print(ac,wa)

Submission status: Accepted

Solution code:
#import pysnooper
#import numpy
#import os,re,sys,operator
#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left,bisect_right
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial
#import sys
#from fractions import gcd
setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
c=[False]*n
cnt=[0]*n
ac,pena=0,0
for i in range(m):
    p,s=input().split()
    p=int(p)-1
    if not c[p] and s=="AC":
        pena+=cnt[p]
        c[p]=True
    elif s=="WA":
        cnt[p]+=1

print(c.count(True),pena)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m = [int(i) for i in input().split()]
wa = [0]*n
ac = [0]*n

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

print(n-ac.count(0), sum([wa[i] for i in range(n) if ac[i] >= 1]))

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
lis_ac = [None] * N
lis_wa = [0] * N
ac = 0
wa = 0
for i in range(M):
    a,b = map(str,input().split())
    a = int(a)
    if b == 'AC' and lis_ac[a-1] == None:
        lis_ac[a-1] = 'AC'
        ac += 1
        wa += lis_wa[a-1]
    elif b == 'AC' and lis_ac[a-1] == 'AC':
        continue
    elif b == 'WA' and lis_ac[a-1] == 'AC':
        continue
    else:
        lis_wa[a-1] += 1
print(ac,wa)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a=[0]*n
w=[0]*n
ac=0
wc=0
for _ in range(m):
    p,s=input().split()
    p=int(p)-1
    if a[p]==0:
        if s=="AC":
            a[p]=1
            ac+=1
            wc+=w[p]
        else:
            w[p]+=1
print(ac,wc)

Submission status: Accepted

Solution code:
from collections import defaultdict
d = defaultdict(int)

N,M = map(int,input().split())
li = []
for m in range(M):
  x,y = input().split()
  li.append([int(x), y])

sets = set()

ac = 0
wa = 0

for i in li:
  if i[1] == 'AC':
    if i[0] not in sets:
      sets.add(i[0])
      ac += 1
      wa += d[i[0]]

  else:
    if i[0] not in sets:
      d[i[0]] += 1

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

Submission status: Accepted

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


ac = 0
wa = 0
aclist = {}
walist = {}

count_WA=0
for i in range(N):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(M):
    a,b=input().split()
    a=int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]




print(ac,wa,sep=" ")

Submission status: Accepted

Solution code:
s=list(map(int,input().split()))
ans=[list(map(str,input().split())) for i in range(s[1])]
ac=[0]*s[0]
wa=[0]*s[0]
a=0
b=0
c=0
for i in range(s[1]):
  c=int(ans[i][0])-1
  if ac[c]==0:
    if ans[i][1]=='WA':
      wa[c]+=1
    else:
      a+=1
      b+=wa[c]
      ac[c]=1
print(a,b)

Submission status: Accepted

Solution code:
# 誤読したか？

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N, M = read_ints()
from collections import defaultdict
flgs = [False] * N  # N問をACしたか
n_wa_ls = [0] * N


for _ in range(M):
    p, s = input().split()
    p = int(p) - 1
    if flgs[p]:
        continue
    if s == 'AC':
        flgs[p] = True
    elif s == 'WA':
        n_wa_ls[p] += 1

n_wa = 0
for i in range(N):
    if flgs[i]:
        n_wa += n_wa_ls[i]

print(sum(flgs), n_wa)

Submission status: Accepted

Solution code:
def main():
    N, M = map(int, input().split(" "))
    ac = 0
    wa = 0
    answer = ["C"] * N  # C: 適当な初期値
    for _ in range(M):
        ps = input().split(" ")
        p = int(ps[0]) - 1
        if not answer[p][-1] == "A":
            answer[p] = answer[p] + ps[1][0]
    if M > 0:
        for a in answer:
            if a[-1] == "A":
                ac += 1
                wa += (len(a) - 2)
    print(ac, wa)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

acd = dict()
pcd = dict()
ac = 0
pc = 0
for i in range(M):
    p, S = input().split(' ')
    if p not in acd:
        if S == 'AC':
            acd[p] = 1
            ac += 1
            if p in pcd:
                pc += pcd[p]
        else:
            if p not in pcd:
                pcd[p] = 1
            else:
                pcd[p] += 1

print("{} {}".format(ac, pc))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

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

    # print(ac)
    # print(wa)
    print(sum(ac.values()), sum(wa.values()))


if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
p = []
S = []
for i in range(M):
    pp, SS = map(str, input().split())
    p.append(pp)
    S.append(SS)

a = []
for i in range(M):
    a.append(int(p[i]))

AC = 0
P = 0

Q = []
R = []
for i in range(N):
    Q.append(0)
    R.append(0)

for i in range(M):
    index = a[i] - 1
    if Q[index] == 0 and S[i] == 'AC':
        AC = AC + 1
        Q[index] = 1
    elif Q[index] == 0 and S[i] == 'WA':
        R[a[i] - 1] = R[a[i] - 1] + 1

for i in range(N):
    if Q[i] == 0:
        P = P
    else: P = P + R[i]

print(AC, P)

Submission status: Accepted

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

#data = [[N+1]*3 for i in range(M)]
data = []
for i in range(1, M+1):
    p,S = map(str, input().split())
    s = 0
    if S == 'AC':
        s = 1
    data.append([int(i),int(p),int(s)])


sorted_data = sorted(data, key=lambda x:(x[1], x[0]))

before = 0
is_ac = False
ac_num = 0
wa_num = 0
tmp = 0
for val in sorted_data:
    if before == val[1]:
        if is_ac:
            continue
        else:
            if val[2] == 1:
                ac_num += 1
                wa_num += tmp
                is_ac = True
            else:
                tmp += 1
    else:
        is_ac = False
        before = val[1]
        tmp = 0
        if val[2] == 1:
            ac_num += 1
            is_ac = True
        else:
            tmp += 1

print(str(ac_num)+' '+str(wa_num))

Submission status: Accepted

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

ac = 0
wa = [0 for i in range(N)]
ansed = set()
for psn in ps:
    if psn[1] == 'AC':
        if psn[0] not in ansed:
            ac += 1
            ansed.add(psn[0])
    else:
        if psn[0] not in ansed:
            wa[int(psn[0])-1] += 1
for i in range(N):
    if str(i+1) not in ansed:
        wa[i] = 0

print(ac, sum(wa))

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
ac = 0
wa = 0
aclist = {}
walist = {}
for i in range(n):
    aclist[i + 1] = 0
    walist[i + 1] = 0

for i in range(m):
    a,b = input().split()
    a = int(a)
    if aclist[a] == 1:
        continue
    elif b == 'WA':
        walist[a] += 1
    elif b == 'AC':
        aclist[a] += 1
        ac += 1
        wa += walist[a]
        
print(ac, wa)

Submission status: Accepted

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

AC = [0]*(N+1)
wa = [0]*(N+1)
WA = 0

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

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

print(sum(AC[1:]), WA)

Submission status: Accepted

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

problem = [0] * n
count = [0] * n

penal = 0

for i in range(m):
    p, x = map(str, input().split())
    p = int(p) - 1
    if x == "AC":
        if problem[p] == 0:
            problem[p] = 1
    elif x == "WA":
        if problem[p] == 0:
            count[p] += 1

for i in range(n):
    if problem[i] == 0:
        count[i] = 0

print("{}".format(sum(problem)) + " {}".format(sum(count)))

Submission status: Accepted

Solution code:
import numpy as np
import sys
input = sys.stdin.readline

N, M = list(map(int, input().split()))
ac = np.zeros(N, dtype=np.int)
wa = np.zeros(N, dtype=np.int)
for n in range(M):
    p, S = input().split()
    p = int(p)
    if ac[p - 1] == 1:
        continue
    if S == 'AC':
        ac[p - 1] = 1
    else:
        wa[p - 1] += 1
wa = str(sum(wa * ac))
ac = str(sum(ac))
ans = ac + ' ' + wa
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

acs = [0] * N
was = [0] * N 

for i in range(M):
    p, s = input().split()
    j = int(p) - 1
    if s == 'AC':
        acs[j] = 1
    elif s == 'WA':
        if acs[j] == 0:
            was[j] += 1

ac, wa = 0, 0
for i in range(N):
    ac += acs[i]
    if acs[i]:
        wa += was[i]

print(ac, wa)

Submission status: Accepted

Solution code:
def main():
    N, M= map(int, input().split())
    
    acList = [False] * N
    waList = [0] * N
    waCount = 0

    for _ 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)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n,m=map(int,input().split())
A=0
W=0
li=[0]*n
w=[0]*n
for i in range(m):
    p,s=map(str,input().split())
    p=int(p)
    if s=="AC" and li[p-1]==0:
        li[p-1]+=1
        A+=1
        W+=w[p-1]
    else:
        w[p-1]+=1
print(A,W)

Submission status: Accepted

Solution code:
import sys

N, M = map(int, input().split())
if M == 0:
    print(0, 0)
    sys.exit()

p_S = []
for _ in range(M):
    p_S.append(input().split())
    
p = []
S = []


for i in range(M):
    p_S[i][0] = int(p_S[i][0])
    p_S[i][1] = int(p_S[i][1] =='AC')
    
p_S.sort(key=lambda x: x[0])

for i in range(M):
    p.append(p_S[i][0])
    S.append(p_S[i][1])

p = list(map(int, p))
S = list(map(int, S))

flag_p = p[0]
flag_ac = 0
AC_sum = 0
WA_sum = 0
WA = 0

for i in range(M):

    if flag_p == p[i]:
        if S[i] == 0 and flag_ac == 0:
            WA += 1
        elif S[i] == 1 and flag_ac == 0:
            AC_sum += 1
            WA_sum += WA
            flag_ac = 1
    else:
        flag_p = p[i]
        flag_ac = 0
        WA = 0
        if S[i] == 0 and flag_ac == 0:
            WA += 1
        elif S[i] == 1 and flag_ac == 0:
            AC_sum += 1
            WA_sum += WA
            flag_ac = 1

print(AC_sum, WA_sum)

Submission status: Accepted

Solution code:
import sys

N, M = [int(x) for x in sys.stdin.readline().rstrip().split(" ")]

count = [0 for x in range(N + 1)]

ac = 0
pena = 0


for i in range(M):
	p, S = sys.stdin.readline().rstrip().split(" ")
	p = int(p)
	if count[p] >= 0:
		if S == "AC":
			ac += 1
			pena += count[p]
			count[p] = -1
		else:
			count[p] += 1

print("%d %d" % (ac, pena))