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):
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('01-handmade-05.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, M = read_int_list()
    p = [0] * M
    S = [''] * M
    for i in range(M):
      l = read_str_list()
      p[i] = int(l[0])
      S[i] = l[1]
      
    correct, penalties = 0, 0
    f = set()  
    r = set()    
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in r:
          r.add(p[i])

      if S[i] == 'WA':
        if p[i] not in r and p[i] in f:
          r.add(p[i])

      if S[i] == 'AC':
        if p[i] not in f:
          f.add(p[i])
          correct += 1
      
      if S[i] == 'WA':
        if p[i] not in f and p[i] in r:
          penalties += 1

    print(correct, penalties)

main()


import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('01-handmade-05.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, M = read_int_list()
    p = [0] * M
    S = [''] * M
    for i in range(M):
      l = read_str_list()
      p[i] = int(l[0])
      S[i] = l[1]
      
    correct, penalties = 0, 0
    f = set()  
    r = set()    
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in r:
          r.add(p[i])

      if S[i] == 'AC':
        if p[i] not in f:
          f.add(p[i])
          correct += 1
      if S[i] == 'WA':
        if p[i] not in f and p[i] in r:
          penalties += 1

    print(correct, penalties)

main()


import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('c1.in')


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


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    N, M = read_int_list()
    p = [0] * M
    S = [''] * M
    for i in range(M):
      l = read_str_list()
      p[i] = int(l[0])
      S[i] = l[1]
      
    r = set()
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in r:
          r.add(p[i])

    correct, penalties = 0, 0
    f = set()  
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in f:
          f.add(p[i])
          correct += 1
      # print(p[i], S[i], f, r)
      
      if S[i] == 'WA':
        if p[i] not in f and p[i] in r:
          penalties += 1

    print(correct, penalties)


def main0():
    N, M = read_int_list()
    p = [0] * M
    S = [''] * M
    for i in range(M):
      l = read_str_list()
      p[i] = int(l[0])
      S[i] = l[1]
      
    r = set()
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in r:
          r.add(p[i])

    correct = len(r)
    penalties = 0
    f = set()  
    for i in range(M):
      if S[i] == 'AC':
        if p[i] not in f:
          f.add(p[i])
      
      if S[i] == 'WA':
        if p[i] not in f and p[i] in r:
          penalties += 1

    print(correct, penalties)


def main1():
    N, M = read_int_list()
    correct = 0
    penalties = 0
    WA = [0] * (N + 1)
    AC = [0] * (N + 1)
    for i in range(M):
      l = read_str_list()
      p = int(l[0])
      S = l[1]

      if S == 'AC':
        AC[p] += 1
      if S == 'WA':
        WA[p] += 1

      if S == 'AC' and AC[p] == 1:
        correct += 1
        penalties += WA[p]
      
      # print(AC[1:], WA[1:])

    print(correct, penalties)

main1()


Verdicts: Wrong Answer

Wrong Answer

Accepted