Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a=0
b=0
if m==0:
    print(0,0)
    exit()
p = [[str(i) for i in input().split()] for _ in range(m)]

c = sorted(p,key=lambda x:x[0])

now = c[0][0]
d = 1
aa=0
bb=0
f = 0

for i in c:
    if i[0] == now:
        if i[1]=='AC':
            if d:
                a += 1
                f = 1
                d = 0
        else:
            if not f:
                bb+=1
    else:
        now = i[0]
        d = 1
        if f:
            b += bb
            f = 0
            bb = 0
        if i[1]=='AC':
            if d:
                a+=1
                f=1
                d = 0
        else:
            if not f:
                bb+=1
    else:
        now = i[0]
        d = 1
	if f:
            b += bb
            f = 0
            bb = 0
        if i[1]=='AC':
            if d:
                a+=1
                f=1
                d = 0
        else:
            if not f:
                bb+=1
b += bb
print(a,b)


Fixed submission:
n,m = map(int,input().split())
a=0
b=0
if m==0:
    print(0,0)
    exit()
p = [[str(i) for i in input().split()] for _ in range(m)]

c = sorted(p,key=lambda x:x[0])

now = c[0][0]
d = 1
aa=0
bb=0
f = 0

for i in c:
    if i[0] == now:
        if i[1]=='AC':
            if d:
                a += 1
                f = 1
                d = 0
        else:
            if not f:
                bb+=1
    else:
        now = i[0]
        d = 1
        if f:
            b += bb
            f = 0
        bb = 0
        if i[1]=='AC':
            if d:
                a+=1
                f=1
                d = 0
        else:
            if not f:
                bb+=1
if f:
  b+=bb
print(a,b)

Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
a=0
b=0
if m==0:
    print(0,0)
    exit()
p = [[str(i) for i in input().split()] for _ in range(m)]

c = sorted(p,key=lambda x:x[0])

now = c[0][0]
d = 1
aa=0
bb=0
f = 0
print(now)
for i in c:
    if i[0] == now:
        if i[1]=='AC':
            if d:
                a += 1
                f = 1
                d = 0
        else:
            if not f:
                bb+=1
    else:
        now = i[0]
        d = 1
        if f:
            b += bb
            f = 0
            bb = 0
        if i[1]=='AC':
            if d:
                a+=1
                f=1
                d = 0
        else:
            if not f:
                bb+=1
    else:
        now = i[0]
        d = 1
	if f:
            b += bb
            f = 0
            bb = 0
        if i[1]=='AC':
            if d:
                a+=1
                f=1
                d = 0
        else:
            if not f:
                bb+=1
b += bb
print(a,b)


Fixed submission:
n,m = map(int,input().split())
a=0
b=0
if m==0:
    print(0,0)
    exit()
p = [[str(i) for i in input().split()] for _ in range(m)]

c = sorted(p,key=lambda x:x[0])

now = c[0][0]
d = 1
aa=0
bb=0
f = 0

for i in c:
    if i[0] == now:
        if i[1]=='AC':
            if d:
                a += 1
                f = 1
                d = 0
        else:
            if not f:
                bb+=1
    else:
        now = i[0]
        d = 1
        if f:
            b += bb
            f = 0
        bb = 0
        if i[1]=='AC':
            if d:
                a+=1
                f=1
                d = 0
        else:
            if not f:
                bb+=1
if f:
  b+=bb
print(a,b)