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):
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
            print("1!")
        elif S[i] == 1 and flag_ac == 0:
            AC_sum += 1
            WA_sum += WA
            WA = 0
            flag_ac = 1
            print("2!")
        print(flag_p)
            
    else:
        flag_p = p[i]
        flag_ac = 0
        WA_sum += WA
        WA = 0
        if S[i] == 0 and flag_ac == 0:
            WA += 1
            print("3!")
        elif S[i] == 1 and flag_ac == 0:
            AC_sum += 1
            WA_sum += WA
            flag_ac = 1
            print("4!")
        print(flag_p)

print(AC_sum, WA_sum)

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.append(p_S[i][0])
    S.append(p_S[i][1]=='AC')

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
            WA = 0
            flag_ac = 1
    else:
        flag_p = p[i]
        flag_ac = 0
        WA_sum = WA
        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)

N, M = map(int, input().split())
for _ in range(M):
    p, S = input().split()
p = map(int, p)

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

for i in range(M):
  if flag_p == p[i]:
    if S[i] == 'WA':
      WA += 1
    elif S[i] == 'AC' and flag_ac == 0:
      AC_sum += 1
      WA_sum += WA
      flag_ac = 1
      
  else:
    WA = 0
    flag = p[i]
    if S[i] == 'WA':
      WA += 1
    elif S[i] == 'AC' and flag_ac == 0:
      AC_sum += 1
      WA_sum += WA
      flag_ac = 1
    
print(AC_sum. WA_sum)

N, M = map(int, input().split())
p_S = []
for _ in range(M):
    p_S.append(input().split())
    
p = []
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
            WA = 0
            flag_ac = 1
            
    else:
        flag_p = p[i]
        flag_ac = 0
        WA_sum += WA
        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)

n,m=map(int,input().split())
ac=[0]*n
wa=[0]*n
for i 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
        

AC=0
WA=0
for i in range(n):
    AC += ac[i]
    if ac[i] == 1:
      WA += wa[i]
print("{} {}".format(AC,WA))

Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted