Problem p02802 (python)

Fixed submission:
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)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
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
            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)

Buggy submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
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
            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)

Buggy submission (verdict: Runtime Error):
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)