Problem: 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 `WA`s received before receiving an `AC` for the first time on that problem.  Find the numbers of Takahashi's correct answers and penalties.

Submission attempts (in order):
N, M = map(int, input().split())
acc = [False] * N
pen = 0
for _ in range(M):
	p, S = input().split()
	p = int(p) - 1
	if S[0] == 'A':
		acc[p] = True
	else:
		if not acc[p]:
            pen += 1
print('{} {}'.format(sum(acc), pen))

N, M = map(int, input().split())
acc = [False] * N
pen = 0
for _ in range(M):
  p, S = input().split()
  p = int(p) - 1
  if S[0] == 'A':
    acc[p] = True
  else:
  	if not acc[p]:
      pen += 1
print('{} {}'.format(sum(acc), pen))


import numpy as np

def main():
    # N, M = map(int, input().split())
    # PS = {}
    
    #     row = input().split()
    #     row[0] = int(row[0])
    #     if row[0] not in PS:
    #         PS[row[0]] = [row[1]]
    #     else:
    #         PS[row[0]].append(row[1])

    # n_correct = 0
    # n_penalty = 0
    # for p in PS:
    #     if 'AC' in PS[p]:
    #         n_correct += 1
    #         for result in PS[p]:
    #             if result == 'AC':
    #                 break
    #             if result == 'WA':
    #                 n_penalty += 1
    
    # print('{} {}'.format(n_correct, n_penalty))

    N, M = map(int, input().split())
    accepted = [False] * N
    penalties = [0] * N
    for _ in range(M):
        q, res = input().split()
        q = int(q) - 1
        if res[0] == 'A':
            accepted[q] = True
        else:
            penalties[q] += 1

    s_acc = 0
    s_pen = 0
    for i in range(N):
        if accepted[i]:
            s_acc += 1
            s_pen += penalties[i]

    print('{} {}'.format(s_acc, s_pen))
    

if __name__ == '__main__':
    main()

import numpy as np

def main():
    # N, M = map(int, input().split())
    # PS = {}
    
    #     row = input().split()
    #     row[0] = int(row[0])
    #     if row[0] not in PS:
    #         PS[row[0]] = [row[1]]
    #     else:
    #         PS[row[0]].append(row[1])

    # n_correct = 0
    # n_penalty = 0
    # for p in PS:
    #     if 'AC' in PS[p]:
    #         n_correct += 1
    #         for result in PS[p]:
    #             if result == 'AC':
    #                 break
    #             if result == 'WA':
    #                 n_penalty += 1
    
    # print('{} {}'.format(n_correct, n_penalty))

    
    N, M = map(int, input().split())
    acc = [False] * (N+1)
    pen = [0] * (N+1)
    for _ in range(M):
        p, S = input().split()
        p = int(p)
        if S[0] == 'A':
            acc[p] = True
        else:
            pen[p] += 1
    pen = 0
    for i in range(1, N+1):
        if not acc[p]:
            pen += pen[p]
    print('{} {}'.format(sum(acc), pen))

    

if __name__ == '__main__':
    main()

import numpy as np

def main():
    N, M = map(int, input().split())
    acc = [False] * (N+1)
    pen = [0] * (N+1)
    for _ in range(M):
        p, S = input().split()
        p = int(p)
        if S[0] == 'A':
            acc[p] = True
        else:
            if not acc[p]:
                pen[p] += 1
    n_pen = 0
    for i in range(1, N+1):
        if acc[i]:
            n_pen += pen[i]
    print('{} {}'.format(sum(acc), n_pen))

    

if __name__ == '__main__':
    main()

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Accepted