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:
n, m = map(int, input().split())
p = [0]*n
num_wa = [0]*n
wa = 0
for i in range(m):
    a, b= map(str, input().split())
    if 0 == p[int(a)-1] and b == "AC":
        p[int(a)-1] = 1
        wa += num_wa[int(a)-1]
    elif 0 == p[int(a)-1] and b == "WA":
        num_wa[int(a)-1] += 1
print(sum(p), wa)

Submission status: Accepted

Solution code:
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

def main():
    n,m = mi()

    t = [[] for i in range(n+1)]

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

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


    accnt = 0
    wacnt = 0

    for i in range(1,n+1):
        if not t[i]:
            continue
        wtmp = 0
        flag = False
        for k in t[i]:
            if k == "AC":
                accnt+=1
                flag = True
                break
            else:
                wtmp+=1
        if flag:
            wacnt+=wtmp

    print(accnt,wacnt)






main()

Submission status: Accepted

Solution code:
import numpy as np
def main():
    nm = list(map(int, input().split()))
    p = np.zeros(nm[0], dtype=int)
    ac = np.zeros_like(p)
    for i in range(nm[1]):
        ps = input().split()
        if ac[int(ps[0])-1] == 0:
            if ps[1] == "WA":
                p[int(ps[0])-1] += 1
            elif ps[1] == "AC":
                ac[int(ps[0])-1] += 1

    print(np.sum(ac), np.sum(p[ac == 1]))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
d = {}
e = {}
a = 0
b = 0
for _ in range(m):
    p, s = input().split()
    if p in d:
        continue
    else:
        if s == 'WA':
            if p in e:
                e[p] += 1
            else:
                e[p] = 1
        else:
            d[p] = 'AC'
            a += 1
            if p in e:
                b += e[p]
print(a,b)

Submission status: Accepted

Solution code:
N, M = map(int,input().split())
p = []
S = []
for i in range(M):
    a, b = map(str,input().split())
    a = int(a)
    p.append(a)
    S.append(b)
ac_ans = 0
pn_ans = 0
tmp_dict = dict()
ac_dict = dict()
pn_dict = dict()
for i in range(N):
    ac_dict[i] = 0
    pn_dict[i] = 0
    tmp_dict[i] = 0

for i in range(M):
    if S[i] == "AC":
        tmp_dict[p[i]-1] = pn_dict[p[i]-1]
        if ac_dict[p[i]-1] == 0:
            ac_dict[p[i]-1] += 1
        else:
            pass
    else:
        if ac_dict[p[i]-1] == 0:
            pn_dict[p[i]-1] += 1
        else:
            pass
for i in range(N):
    ac_ans += ac_dict[i]
for i in range(N):
    pn_ans += tmp_dict[i]
ac_ans = str(ac_ans)
pn_ans = str(pn_ans)
print(ac_ans + " " + pn_ans)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
a_list = []
b_list = ["f"] * (10**5+1)
count_ac = 0
count_wa = 0
for i in range(m):
    a,b = map(str, input().split())
    a_list.append((int(a),b))
for i in range(m):
    if a_list[i][1] == "WA" and b_list[a_list[i][0]] == "f":
        count_wa += 1
    if a_list[i][1] == "AC":
        if b_list[a_list[i][0]] == "f":
            count_ac += 1
        b_list[a_list[i][0]] = "t"
for i in range(m):
    if b_list[a_list[i][0]] == "f" and a_list[i][1] == "WA":
        count_wa -= 1
print(count_ac,count_wa)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
N, M = map(int, input().split(' '))


ac, wa_list = 0, [0 for _ in range(N)]
solved = [False for _ in range(N)]
for _ in range(M):
    p, s = input().split(' ')
    p = int(p) - 1

    if solved[p]:
        continue

    else:
        if s == 'AC':
            solved[p] = True
            ac += 1

        elif s == 'WA':
            wa_list[p] += 1

wa = sum([wa for wa, s in zip(wa_list, solved) if s])

print(ac, wa)

Submission status: Accepted

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

a = 0

for s,t in ans:
    if t== 'WA' and ac[int(s)-1] == 0:
        penali[int(s)-1] += 1
    if t == 'AC':
        if ac[int(s)-1] == 0:
            a +=1
        ac[int(s)-1] = 1

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

pena = 0
for i in penali:
    pena += i

print(a, pena)

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from heapq import heapify, heappop, heappush
from sys import stdin

def main():
    n, m = map(int, input().split())
    ac_status = defaultdict(int)
    wa_count = defaultdict(int)
    for _ in range(m):
        p, s = input().split()
        p = int(p)
        if s == "AC":
            ac_status[p] = 1
        else:
            if ac_status[p] != 1:
                wa_count[p] += 1
    ac = len([v for v in ac_status.values() if v == 1])
    wa = sum([v for k,v in wa_count.items() if ac_status[k] == 1])
    #print(ac_status)
    #print(wa_count)
    print(ac, wa)


input = lambda: stdin.readline().rstrip()
main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict as dd, deque

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

solved = set()
penals = dd(int)

for _ in range(m):
    p,s = input().split()
    p = int(p)
    if s == 'AC':
        solved.add(p)
    else:
        if p not in solved:
            penals[p] += 1

print(len(solved), sum(penals[p] for p in penals if p in solved))

Submission status: Accepted

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


for _ in range(m):
    p, s = input().split()
    p = int(p) - 1
    d[p].append(s)

ac_cnt, w_cnt = 0, 0
for l in d:
    if len(l) != 0 and "AC" in l:
        w_cnt += l.index("AC")

    if "AC" in l:
        ac_cnt += 1

print(ac_cnt, w_cnt)

Submission status: Accepted

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

correct = [0 for _ in range(n)]
penal = [0 for _ in range(n)]

for i in range(m):
    if s[i] == 'AC':
        correct[p[i]-1] = 1
    else:
        if correct[p[i]-1] != 1:
            penal[p[i]-1] += 1

for i, cor in enumerate(correct):
    if cor == 0:
        penal[i] = 0


c = sum(correct)
pen = sum(penal)
print(c, pen)

Submission status: Accepted

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

AC = [False] * (N + 1)
WA = [0] * (N + 1)
for _ in range(M):
    p, s = input().split()
    p = int(p)
    if s == "AC":
        AC[p] = True
    if s == "WA" and not AC[p]:
        WA[p] += 1

cnt = 0
for a, w in zip(AC, WA):
    if a:
        cnt += w

print(sum(AC), cnt)

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
q_re = set()
ac = 0
wa = 0
dic_wa = {}
for i in range(m):
    q, re = input().split()
    if(re == "WA" and q not in q_re): 
        if(q not in dic_wa): dic_wa[q] = 1
        else: dic_wa[q] += 1
    if(re == "AC" and q not in q_re): 
        ac += 1
        q_re.add(q)
        if(q in dic_wa): wa += dic_wa[q]
print(ac, wa)

Submission status: Accepted

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

CorrectAnswer = [0] * N
Penalties     = [0] * N

p = []
S = []
for i in range(M):
    inp = input()
    x,y = inp.split()
    x   = int(x)
#     p.append(x)
#     S.append(y)
    
    #checking 1st timers?
    if CorrectAnswer[x-1] == 1:
        pass
        #         CorrectAnswer[x-1] = 1
    else:
        if y == 'AC':
            CorrectAnswer[x-1] = 1
        else:
            Penalties[x-1] += 1

penalties = 0
for i in range(N):
    penalties += CorrectAnswer[i] * Penalties[i]
print(sum(CorrectAnswer), penalties)

Submission status: Accepted

Solution code:
n,m = map(int, input().split(" "))
ac = 0
wa = 0
en_li = [[] for i in range(n)]
print
for i in range(m):
    a, b = input().split(' ')
    en_li[int(a)-1].append(b)
ac = 0
wa = 0
for i in en_li:
    if 'AC' in i:
        wa += i.index('AC')
        ac += 1
print(ac, wa)

Submission status: Accepted

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

    ac_count = 0
    wa_count = 0

    if M == 0:
        print('{} {}'.format(ac_count, wa_count))
        exit()

    result_list = []

    for i in range(N):
        result_list.append([i+1, 0, 0])

    for i in range(M):
        str_list = input().split()
        if result_list[int(str_list[0])-1][1] == 1:
            continue
        if str_list[1] == 'AC':
            result_list[int(str_list[0])-1][1] = 1
        if str_list[1] == 'WA' and result_list[int(str_list[0])-1][1] == 0:
            result_list[int(str_list[0])-1][2] += 1

    for i in range(N):
        if result_list[i][1] == 1:
            ac_count +=1
            wa_count += result_list[i][2]

    print('{} {}'.format(ac_count, wa_count))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def num():
    return int(input())
def nums():
    return list(map(int,input().split()))

import itertools as iter
import math
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N,M = nums()
AC = set()
WA = {}
for _ in range(M):
    pi,si = input().split()
    if si == "AC":
        AC.add(pi)
    else:
        if not (pi in WA.keys()) and not pi in AC:
            WA[pi] = 1
        else:
            if not (pi in AC):
                WA[pi] += 1

for problem in WA.keys():
    if not (problem in AC):
        WA[problem] = 0
ACnum = len(AC)
WAnum = sum(WA.values())
print(ACnum,WAnum)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
l = [[False,0] for _ in range(n+1)]
p = 0
c = 0
for i in range(m):
  pi,si = input().split()
  pi = int(pi)
  si = str(si)
  if l[pi][0] == False:
    if si == "AC":
      c += 1
      l[pi][0] = True
      p += l[pi][1]
    else:
      l[pi][1] += 1
print(c,p)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
p = []
S = []
p_count = 0
a_count = 0
for i in range(m):
    temp1,temp2 = input().split()
    p.append(int(temp1))
    S.append(temp2)
n_table = [0 for i in range(n)]
n_wa_table = [0 for i in range(n)]
for p,s in zip(p,S):
    if s == "AC":
        n_table[p-1] = 1
    if s == "WA" and n_table[p-1] == 0:
        n_wa_table[p-1] += 1
a_count = n_table.count(1)
wai = [i for i, x in enumerate(n_table) if x == 1]
for i in wai:
    p_count += n_wa_table[i]
print(a_count,p_count)

Submission status: Accepted

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

ac_list = [0] * N
wa_list = [0] * N

for p, S in questions:
    if S == 'AC':
        ac_list[p - 1] = 1
    else:
        if ac_list[p - 1] == 1:
            continue
        wa_list[p - 1] += 1

for i in range(N):
    if ac_list[i] == 0:
        wa_list[i] = 0

print(sum(ac_list), sum(wa_list))

Submission status: Accepted

Solution code:
N,M = list(map(int, input().split()))
p = []
s = []
for i in range(M):
  temp = list(map(str, input().split()))
  p_temp = int(temp[0])
  p.append(p_temp)
  s.append(temp[1])

ac_list = []
ac_num = 0
wa_num = 0
ques_list = []
wa_list = []
for i in range(N):
  ques_list.append(0)
  wa_list.append(0)

for i in range(M):
  if(s[i]=="AC" and ques_list[p[i]-1]==0):
    ac_num += 1
    ques_list[p[i]-1] = 1
  elif(s[i]=="WA" and ques_list[p[i]-1]==0):
    wa_list[p[i]-1] += 1
    
for i in range(N):
  if(ques_list[i]==1):
    wa_num += wa_list[i]
    
print(ac_num, wa_num)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
queans = []
wa = [0] * N
ac = [0] * N
for i in range(M):
  a,b=input().split()
  queans.append((int(a), b))
for i in range(M):
  Q = queans[i][0]
  A = queans[i][1]
  if(A == 'AC'):
    ac[Q-1] = 1 
  else:
    if(ac[Q-1] != 1):
      wa[Q-1] += 1
      
acsum = 0
wasum = 0
for j in range(N):
  acsum += ac[j]
  if(ac[j] != 0):
    wasum += wa[j]

print(acsum, wasum)

Submission status: Accepted

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

ac_set = set()
wa_cnt = {}
for i in range(M):
    p, s = input().split()
    if s == 'WA' :
        wa_cnt.setdefault(p, 0)
        if p not in ac_set:
            wa_cnt[p] += 1
    else :
        ac_set.add(p)
        
wa_sum = 0
for k, v in wa_cnt.items():
    if k in ac_set:
        wa_sum += v
print(len(ac_set),wa_sum)

Submission status: Accepted

Solution code:
# 2020/01/12
# AtCoder Beginner Contest 151 - C

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

# Calc
acstat = [0] * (n+1)
wa_acm = [0] * (n+1)

wk_p = -1
ac_cnt = 0
wa_cnt = 0
for i in range(m):
    p, s = input().split()
    inp = int(p)
    if s == "AC":
        if acstat[inp] == 0:
            ac_cnt = ac_cnt + 1
            wa_cnt = wa_cnt + wa_acm[inp]
            acstat[inp] = 1
        
    elif s == "WA":
        if acstat[inp] == 0:
            wa_acm[inp] = wa_acm[inp] + 1

# Output
print(ac_cnt, wa_cnt)

Submission status: Accepted

Solution code:
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def my_round(a,dig=0):
    p = 10 ** dig
    return (a * p * 2 + 1) // 2 / p

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

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

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def prime_fact(a): #素因数分解
    sqrt = math.sqrt(a)
    res = []
    i = 2
    if is_prime(a):
        res.append(a)
    else:
        while a!=1:
            while a%i==0:
                res.append(i)
                a //= i
            i += 1
    return res

def main():
    n,m = map(int,input().split())
    p = []
    s = []
    for i in range(m):
        a,b = input().split()
        p.append(int(a) - 1)
        s.append(b)
    ac = [[0,False] for i in range(n)]
    for i in range(m):
        if ac[p[i]][1]:
            continue
        else:
            if s[i] == 'WA':
                ac[p[i]][0] += 1
            else:
                ac[p[i]][1] = True
    ans = 0
    pena = 0
    for i in range(n):
        if ac[i][1]:
            ans += 1
            pena += ac[i][0]
    print(ans,pena)
    return

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n,m = map(int, input().split())
s = [list(map(str, input().split())) for i in range(m)]
k = {}
for i in range(m):
    k[s[i][0]]=[]

for i in range(m):
    k[s[i][0]].append(s[i][1])

pena =0
ac =0

for i in k.keys():
    if "AC" not in k[str(i)]:
       continue
    else:
        for j in k[str(i)]:
            if j== "AC":
                ac+= 1
                break
            else: 
                pena+=1

print(ac,pena)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M=list(map(int, input().split()))
problem = []
result  = []
for _ in range(M):
    str_list = input().split(' ')
    problem.append(int(str_list[0]))
    result.append(str_list[1])

#first_AC = [False]*N
#pena     = [0]*N
first_AC = [0 for i in range(N)]
pena     = [0 for i in range(N)]
for (p, r) in zip(problem, result):
    if first_AC[p-1]==0:
        if r=='WA':
            pena[p-1] += 1
        elif r=='AC':
            first_AC[p-1]=1
collect    = sum(first_AC)
temp       = [x * y for (x, y) in zip(first_AC, pena)]
total_pena = sum(temp)
#print('%d %d' % (collect, total_pena))
print(str(collect)+' ', end='')
print(total_pena)

Submission status: Accepted

Solution code:
def main():
    n, m = list(map(int, input().split()))
    p = []
    s = []
    for i in range(m):
        a, b = input().split()
        p.append(int(a))
        s.append(b)
    buff = {}
    memo = set()
    wans = 0
    for i in range(m):
        
        if p[i] in memo:
            continue
        else:
            if s[i] == "AC":
                if p[i] in buff:
                    wans += buff[p[i]]
                memo.add(p[i])
            else:
                if p[i] in buff:
                    buff[p[i]] = buff[p[i]] + 1
                else:
                    buff[p[i]] = 1
    print(len(memo), wans)
if __name__ == "__main__":
    main()

Submission status: Accepted

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

AC_flags = [[0, 0] for _ in range(N)]

for p, s in zip(P, S):
    if AC_flags[p - 1][0] == 0 and s == "WA":
        AC_flags[p - 1][1] += 1
    elif AC_flags[p - 1][0] == 0 and s == "AC":
        AC_flags[p - 1][0] += 1

sum_ac, sum_wa = 0, 0
for ac, wa in AC_flags:
    if ac == 1:
        sum_ac += ac
        sum_wa += wa
    else:
        pass

print(sum_ac, sum_wa)

Submission status: Accepted

Solution code:
import numpy as np

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

ac = np.zeros(N, dtype = np.int64)
wa = np.zeros(N, dtype = np.int64)

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

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

print(int(np.sum(ac)), int(np.sum(wa)))

Submission status: Accepted

Solution code:
import sys
import math
import functools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, m = na()
p = [0] * (n+1)
c = 0
penalty = [0] * (n+1)
ans2 = 0
for _ in range(m):
    ps = stdin.readline().rstrip().split(" ")
    pi, si = int(ps[0]), ps[1]
    if p[pi]==0:
        if si == "AC":
            p[pi] = 1
            ans2 += penalty[pi]
        else:
            penalty[pi]+=1
print(sum(p), ans2)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
l = []
for i in range(M):
  l.append(list(map(str, input().split())))
for i in range(M):
  l[i][0] = int(l[i][0])
check_l = [0] * N
temp_penalty = [0] * N

penalty = 0
ans_count = 0

for i in range(M):
  if check_l[l[i][0]-1] == 0:
    if l[i][1] == 'AC':
      check_l[l[i][0]-1] = 1
      ans_count += 1
      penalty += temp_penalty[l[i][0]-1]
    else:
      temp_penalty[l[i][0]-1] += 1

print(ans_count, penalty)

Submission status: Accepted

Solution code:
N,M = map(int,input().split())
AC = {}
WA = {}
for i in range(M):
    prb ,ans = input().split()
    if ans == "AC":
        AC[prb] = 1
    else:
        if (prb in WA) == False and (prb in AC) ==  False:
            WA[prb] = 1
        else:
            if (prb in AC) ==  False:
                WA[prb] +=1
wa = 0
for i,v in WA.items():
    if (i in AC):
        wa += v
print("{} {}".format(len(AC),wa))

Submission status: Accepted

Solution code:
N, M = map(int,input().split()) # 複数の数字を変数に格納
List = [list(map(str,input().split())) for i in range(M)]

ac = [0]*N
wa = [0]*N

for i in range(M):
    num = int(List[i][0])-1
    result = List[i][1]
    if ac[num] == 0:
        if result == 'AC':
            ac[num] = 1
        else:
            wa[num] += 1

total_ac = 0
total_wa = 0

for i in range(N):
    if ac[i] == 1:
        total_ac += ac[i]
        total_wa += wa[i]
    
print(total_ac, total_wa)

Submission status: Accepted

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

ans_list = [["WA", 0] for i in range(N)]

AC_count = 0
for i in range(M):
    p, S = map(str, input().split())
    p = int(p)
    if S == "WA":
        if ans_list[p-1][0] == 'WA':
            ans_list[p-1][1] += 1
        else:
            pass
    else:
        if ans_list[p-1][0] == 'WA':
            ans_list[p-1][0] = 'AC'
            AC_count += 1
        else:
            pass

WA_count = 0
for i in range(N):
    if ans_list[i][0] == 'AC':
        WA_count += ans_list[i][1]

print(AC_count, WA_count)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun Jan 12 21:16:15 2020

@author: masat
"""

N, M = map(int, input().split())
p_list = []
s_list = []
for i in range(M):
    p, s = input().split()
    p_list.append(int(p))
    if s == "AC":
        s_list.append(True)
    else:
        s_list.append(False)

#問題番号ごとにひとつずつ、合計でN個の空のリストを用意する。
bucket_list = []
for i in range(N):
    bucket_list.append([])

"""
p_listのi番目の問題番号を取り出し、
bucket_listの対応する番号（問題番号-1）のリストに
s_listのi番目の結果をappendする。
"""
for i in range(M):
    bucket_list[p_list[i]-1].append(s_list[i])

"""
"""
accepted_answer = 0
penalty = 0

for i in range(N):
    penalty_candidate = 0
    for k in bucket_list[i]:
        if k:
            accepted_answer += 1
            penalty += penalty_candidate
            break
        else:
            penalty_candidate += 1

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

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
sub_ls = []
for i in range(m):
    p, s = list(map(str, input().split()))
    p = int(p)-1
    sub_ls.append([p,s])
ac_cnt = []
wa_cnt = []
for i in range(n):
    ac_cnt.append(0)
    wa_cnt.append(0)
#print(ac_cnt, wa_cnt)
for i in range(m):
    if ac_cnt[sub_ls[i][0]] == 0:
        #print(sub_ls[i][1], ac_cnt[i])
        if sub_ls[i][1] == "AC":
            ac_cnt[sub_ls[i][0]] = 1
        else:
            wa_cnt[sub_ls[i][0]]+=1
ac_sum = 0
wa_sum = 0
for i in range(n):
    #print(ac_cnt[i], wa_cnt[i])
    ac_sum+=ac_cnt[i]
    if ac_cnt[i] == 1:
        wa_sum+=wa_cnt[i]
print(ac_sum, wa_sum)

Submission status: Accepted

Solution code:
n,m= map(int, input().split()) 
judge=[0]*n
cor=0
pen=0
inf=10**6

for i in range(m):
  a,s = input().split()
  a=int(a)
  if s=='WA':
    judge[a-1]+=1
    
  else:
    if judge[a-1]>-1:
      cor+=1
      pen+=judge[a-1]
      judge[a-1]=-inf

print(cor,pen)

Submission status: Accepted

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

AC = [0]*(n+1)
WA = [0]*(n+1)

for i in range(m):
  p_number, p_status = input().split()
  p_number =int(p_number)
  if (p_status =='WA') & (AC[p_number]==0):
    WA[p_number]+=1
  if (p_status =='AC') & (AC[p_number]==0):
    AC[p_number] +=1

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

print(sum(AC), sum(WA))
#print(AC,WA)

Submission status: Accepted

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

from collections import defaultdict
d = defaultdict(list)
ab = [tuple(input().split()) for i in range(m)]

nAC = 0
nWA = 0


for a,b in ab:
    a = int(a)


    if len(d[a]) == 0:
        flag = 0
        num = 0
        d[a].append((flag, num))
    else:
        flag, num = d[a]


    if flag == 1:
        continue

    if flag == 0 and b == 'AC':
        flag = 1

    if flag == 0 and b == 'WA':
        num += 1

    d[a] = (flag, num)


for flag, num in d.values():
    if flag == 1:
        nAC += 1
        nWA += num

print(nAC, nWA)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
lis = []
clis = set()
for _ in range(m):
    x, y = input().split()
    x = int(x)
    if y == "AC":
        clis.add(x)
    elif x in clis:
        continue
    else:
        lis.append(x)
count = 0
for i in lis:
    if i in clis:
        count += 1
print(len(clis), count)

Submission status: Accepted

Solution code:
n,m = map(int,input().split())
a = [[0,0,0]]*m
for i in range(m):
    a[i] = input().split() + [i]

a.sort()
ac = 0
wa = 0
tmp = "dummy"
tmp2 = 9999

for x,y,z in a:
    if y == "AC" and x != tmp:
        ac += 1
        tmp = x
        tmp2 = z
    elif y == "AC" and x == tmp:
        continue
    elif y == "WA" and x != tmp:
        continue
    elif y == "WA" and x == tmp:
        if z < tmp2:
            wa += 1
        else:
            continue

print(ac,wa)

Submission status: Accepted

Solution code:
import math
import sys


(N, M) = list(map(int,input().split()))
# print(N,M)
nwa = 0
nac = 0

ac = [ "" for _ in range(N+1)]
wa = [ 0 for _ in range(N+1)]
for i in range(0,M):
    (x,S)  = input().split()
    p = int(x)
    # print(p,S)
    if ac[p] == "AC":
        continue
    if S == "AC":
        nac = nac + 1
        ac[p] = "AC"
    else:
        wa[p] = wa[p] + 1

# print(ac,wa)
for i in range(1,N+1):
    if ac[i] == "AC":
        nwa = nwa + wa[i]

print(nac,nwa)

Submission status: Accepted

Solution code:
from sys import stdin

if __name__ == '__main__':
    N, M = [ int(x) for x in stdin.readline().rstrip().split() ]
    probs = {}
    for i in range(M):
        a, b = [x for x in stdin.readline().rstrip().split()]
        s = (a, b)
        if not s in probs:
            probs[s] = 0
        if b == 'AC':
            probs[s] = 1
        else:
            if (a, 'AC') in probs:
                pass
            else:
                probs[s] += 1

    AC = 0
    WA = 0

    for key, value in probs.items():
        if key[1] == 'WA':
            if (key[0], 'AC') in probs:
                WA += value
        else:
            AC += 1
    print(AC, WA)

Submission status: Accepted

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

AC=[0]*N
WA=[0]*N
OK = 0
NG = 0
for i in range(M):
    p,S=input().split() 
    p = int(p)
    
    if AC[p-1] == 0:        
        if S=='AC':
            AC[p-1]=1
            OK+=1        
        else:
            WA[p-1]+=1
    
for i in range(N):
    if AC[i]==1:
        NG +=WA[i]
        
print(OK,NG)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

N, M = map(int, input().split())
plist = [[] for i in range(N)]
for i in range(M):
    p, S = input().split()
    # plist の i 番目の要素: 問題 i-1 に対する提出結果のリスト
    plist[int(p) - 1].append(str(S))
# print(N, M)
# print(plist)

count_AC = 0
sum_penalty = 0
for l in plist:
    penalty = 0
    if 'AC' in l:
        count_AC += 1
        penalty = l.index('AC')
    sum_penalty += penalty

print(count_AC, sum_penalty)

Submission status: Accepted

Solution code:
N, M = map(int, input().split())
pS = {}
for i in range(N):
    pS[i] = [0, 0, 0]  # is_ac, penatly, AC

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

AC = 0
penatly = 0
for i in range(N):
    if pS[i][0] == 1:
        penatly += pS[int(i)][1]
        AC += pS[int(i)][2]
print(AC, penatly)

Submission status: Accepted

Solution code:
l = {}
aac = 0
awa = 0
n, m = map(int, input().split())
for _ in range(m):
  pi, si = input().split()
  pi = int(pi)
  ac, wa = l.get(pi, (False, 0))
  if si == 'AC' or ac:
    l[pi] = (True, wa)
  else:
    l[pi] = (False, wa + 1)

for iac,iwa in l.values():
  if iac:
    aac += 1
    awa += iwa

print("%d %d" % (aac, awa))

Submission status: Accepted

Solution code:
import collections
import itertools as it
import math
import numpy as np

# A = input()
# A = int(input())
# A = map(int, input().split())
# A = list(map(int, input().split()))
# A = [int(input()) for i in range(N)]
#
# c = collections.Counter()

N, M = map(int, input().split())
nAC = [False for i in range(N)]
nWA  = [0 for i in range(N)]

for i in range(M):
    p, S = map(str, input().split())
    p = int(p) - 1

    if S == 'AC':
        if nAC[p]:
            pass
        else:
            nAC[p] = True
    else: #WA
        if nAC[p]:
            pass
        else:
            nWA[p] += 1

for i in range(N):
    if nAC[i]:
        pass
    else:
        nWA[i] = 0

print(sum(nAC), sum(nWA))

Submission status: Accepted

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

ls_ac = [0] * n
ls_ng = [0] * n
ac = 0
ng = 0


for i in range(m):
    p = int(ls[i][0])
    if ls[i][1] == "AC":
        if ls_ac[p - 1] == 0:
            ac += 1
            ng += ls_ng[p - 1]
            ls_ac[p - 1] = 1
    elif ls[i][1] == "WA":
        if ls_ac[p - 1] == 0:
            ls_ng[p - 1] += 1

print(ac, ng)

Submission status: Accepted

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

D = [0] * N
W = [0] * N
for p, S in ps:
  p = int(p) - 1
  if D[p] == 0:
    if S == "WA":
      W[p] += 1
    else:
      D[p] = 1

cnt = 0
for i in range(N):
  if D[i] == 1:
    cnt += W[i]

print(sum(D), cnt)

Submission status: Accepted

Solution code:
# import itertools
# import math

# N = int(input())
# S = input()
N, M = map(int, input().split())
# A = list(map(int, input().split()))

ans_p = [0] * N
ans_s = [0] * N

for i in range(M):
    input_sp = input().split()
    P = int(input_sp[0]) - 1
    S = input_sp[1]

    if S == 'AC':
        ans_s[P] = 1
    elif S == 'WA' and ans_s[P] == 0:
        ans_p[P] += 1

for i in range(len(ans_p)):
    if ans_s[i] == 0 and ans_p[i] != 0:
        ans_p[i] = 0

print(str(sum(ans_s)) + " " + str(sum(ans_p)))