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):
listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]

ans = [0] * N
pena = [0] * N

for i in range(1, M):
    num=listA[i][0] -1
    res=listA[i][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1                      
        
print('%d %d' % (sum(ans), sum(pena) ))

listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]
ans = [0] * N
pena = [0] * N
        
        
for i in range(1, M):
    num=listA[i][0] -1
    res=listA[i][1]
    if res=="WA" and ans[num] == 0:
        pena[num] =  pena[num]+1
    if res=="AC":
        ans[num] = ans[num] + 1
        
print('%d %d' % (sum(ans), sum(pena) ))


listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]

ans = []
pena = []
for i in range(N): 
    ans.insert(0,0)
    pena.insert(0,0)
for i in range(M):
    num=listA[i+1][0] -1
    res=listA[i+1][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1   
print(sum(ans),sum(pena))
    

listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]

ans = [0] * N
pena = [0] * N



listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]
ans = [0] * N
pena = [0] * N
        
        
for i in range(1, M-1):
    num=listA[i][0] -1
    res=listA[i][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1                      
        
print('%d %d' % (sum(ans), sum(pena) ))

listA=[] 
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
        
N = listA[0][0]
M = listA[0][1]

ans = [0] * N
pena = [0] * N

for i in range(M):
    num=listA[i+1][0] -1
    res=listA[i+1][1]
    if(res=="WA" and ans[num] == 0):
        pena[num] =  pena[num]+1
    if(res=="AC"):
        ans[num] = ans[num] + 1            
        
print('%d %d' % (sum(ans), sum(pena) ))

listA=[] 
while True:
    try:
        listA.append(input().split())
    except:
        break;
        
N = int(listA[0][0])
M = int(listA[0][1])

ans = [0] * N
pena = [0] * N

for i in range(1, M+1):
    num=int(listA[i][0]) -1
    res=listA[i][1]
    if res=="WA" and ans[num] == 0:
        pena[num] =  pena[num]+1
    if res=="AC" and ans[num] == 0:
        ans[num] = 1
        
print('%d %d' % (sum(ans), sum(x*y for x,y in zip(ans,pena)  ) ))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Accepted