Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())


N,M = inpl()
lines1 = defaultdict(set)

for _ in range(M):
    u,v = inpl()
    u -= 1
    v -= 1
    lines1[u].add(v)

S,T = inpl()
S -= 1
T -= 1

#MEMO = [[set() for i in range(3)] for _ in range(N)]
#visited = [False]*N

lines2 = defaultdict(set)
def dfs(start,s,n): #s: 今いる , n: 何歩目
    if n == 3:
        lines2[start].add(s)
    else:
        for t in lines1[s]:
            dfs(start,t,n+1)

for i in range(N):
    dfs(i,i,0)

'''
print()
for s in range(N):
    for t in lines2[s]:
        print(s,t)
'''

def search (s,w_0): #s->t
    global weight
    global q

    for t in list(lines2[s]):
        w = w_0 + 1
        if weight[t] > w:
            heapq.heappush(q, [w,t])
            weight[t] = w

weight = [INF]*N
weight[S] = 0
q = [[0,S]]
heapq.heapify(q)
while q:
    w,n = heapq.heappop(q)
    search(n,w)

if weight[T] == INF:
    print(-1)
else:
    print(weight[T])


### FIXED CODE ###

from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())


N,M = inpl()
lines = defaultdict(set)

for _ in range(M):
    u,v = inpl()
    u -= 1
    v -= 1
    lines[u].add(v+N)
    lines[u+N].add(v+2*N)
    lines[u+2*N].add(v)

S,T = inpl()
S -= 1
T -= 1

def search (s,w_0): #s->t
	global weight
	global q

	for t in list(lines[s]):
		w = w_0 + 1
		if weight[t] > w:
			heapq.heappush(q, [w,t])
			weight[t] = w

# Start, S
weight = [INF]*(N*3)
weight[S] = 0
q = [[0,S]]
heapq.heapify(q)
while q:
	w,n = heapq.heappop(q)
	search(n,w)

ans = weight[T]

if ans == INF:
    print(-1)
else:
    print(ans//3)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
for i in range(0,n+1):
    for j in range(0,n):
        if a[j]==i:
            print("%d "%int(j+1),end='')

### FIXED CODE ###

import math
n=int(input())
l=list(map(int,input().split()))
ans=[0]*n
for i in range(n):
    ans[l[i]-1]=i+1
for i in ans:
    print(i,end=" ")
### BUGGY CODE ###

n,M = list(map(int,input().split()))
m = [[0]*n for _ in range(n)]
dp = [0]*n
from collections import deque
que = deque()
for _ in range(M):
  a,b = list(map(int,input().split()))
  a -= 1
  b -= 1
  m[a][b] = 1
  m[b][a] = 1
  if a == 0:
    que.append(b)
    dp[b] = 1
  if b == 0:
    que.append(a)
    dp[a] = 1

while que:
  c = que.popleft()
  for i in range(n):
    if m[c][i] == 1 and dp[i] == 0 :
      dp[i] = c+1
      que.append(i)

for i in range(1,n):
  if dp[i] == 0:exit(print('No'))

print('Yes')
for i in range(1,n):
  print(dp[i])


### FIXED CODE ###

n,M = list(map(int,input().split()))

m = [[] for _ in range(n)]
dp = [0]*n
from collections import deque
que = deque()
for _ in range(M):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  m[a].append(b)
  m[b].append(a)
  if a == 0:
    que.append(b)
    dp[b] = 1
  if b == 0:
    que.append(a)
    dp[a] = 1

while que:
  c = que.popleft()
  for i in m[c]:
    if dp[i] == 0 :
      dp[i] = c+1
      que.append(i)

#[exit(print('No')) for i in range(1,n)  if dp[i] == 0]

print('Yes')
[print(dp[i]) for i in range(1,n)]
### BUGGY CODE ###

import numpy as np

s = input()
n = len(s)
ans = 0
now = 0
mp = np.zeros(2019, np.int)
mp[0] += 1
tmp = np.zeros(2019, np.int)

id = np.zeros(2019, np.int)
for i in range(2019):
    id[i] = i * 10 % 2019

for c in s:
    now *= 10;
    now += ord(c) - ord("0")
    now %= 2019

    ans += mp[now]
    mp[now] += 1
    for i in range(2019):
        tmp[id[i]] = mp[i]
    for i in range(2019):
        mp[i] = tmp[i]

print(ans)


### FIXED CODE ###

s = input()
n = len(s)
ans = 0
now = 0
mp = [0 for i in range(2019)]
mp[0] += 1
tmp = [0 for i in range(2019)]

id = [0 for i in range(2019)]
for i in range(2019):
    id[i] = i * 10 % 2019

for c in s:
    now *= 10;
    now += ord(c) - ord("0")
    now %= 2019

    ans += mp[now]
    mp[now] += 1
    for i in range(2019):
        tmp[id[i]] = mp[i]
    for i in range(2019):
        mp[i] = tmp[i]

print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,m,p=map(int,input().split())
edge = [[] for i in range(m)]
for i in range(m):
  a,b,c=map(int,input().split())
  edge[i]=[a-1,b-1,-c+p]

def sp(s,n,w,es):
  d=[float("inf")]*n
  d[s]=0
  count=0
  ret=[]
  while count<n*2:
    update=False
    for i in range(w):
      e0,e1,e2=es[i]
      if d[e0]!=float("inf") and d[e1]>d[e0]+e2:
        d[e1]=d[e0]+e2
        if i==-1:
          ret=[d[-1],d[-1]]
          break
    count+=1
    if count%n==0:
      ret.append(d[-1])
  return ret
d1,d2=sp(0,n,m,edge)
print(-1 if d1!=d2 else max(0,-d2))


### FIXED CODE ###

import sys
input = sys.stdin.readline
n,m,p=map(int,input().split())
edge = [[] for i in range(m)]
for i in range(m):
  a,b,c=map(int,input().split())
  edge[i]=[a-1,b-1,-c+p]
d=[float("inf")]*n
d[0]=0

for _ in range(n):
  for i in range(m):
    e0,e1,e2=edge[i]
    d[e1]=min(d[e1],d[e0]+e2)
ans1=d[-1]
for _ in range(n):
  for i in range(m):
    e0,e1,e2=edge[i]
    if d[e1]>d[e0]+e2:
      d[e1]=-float("inf")
ans2=d[-1]
print(-1 if ans1!=ans2 else max(0,-ans1))
### BUGGY CODE ###

import copy
N, M = map(int, input().split())
list_num = list(map(int, input().split()))

result = []
for i in range(M):
	a, b = map(int, input().split())
	res_a = [k for k in list_num if k >= b]
	# print(res_a)

	res_b = [k for k in list_num if k < b]
	res_b = sorted(res_b)

	for j in range(min([a, len(res_b)])):
		res_b[j] = b

	# print(res_b)

	tmp = sum(res_b) + sum(res_a)
	# print(tmp)

	list_num = copy.copy(res_a)
	list_num.extend(res_b)
	# print(list_num)

	result.append(tmp)

print(max(result))

### FIXED CODE ###

from sys import stdin
 
def main():
    n,m = [int(x) for x in stdin.readline().split()]
    cards = [int(x) for x in stdin.readline().split()]
    cards.sort()
 
    bcs = [tuple(map(int,x.split())) for x in stdin.readlines()]
    bcs.sort(key=lambda x:x[1], reverse=True)
 
    ans = 0
    minIndex = 0
    isFinished = False
 
    for b,c in bcs:
 
        for _ in range(b):
            if minIndex < n and cards[minIndex] < c:
                ans += c
                minIndex += 1
            else:
                isFinished = True
                break
        
        if isFinished:
            break
 
    if minIndex < n:
        ans += sum(cards[minIndex:])
 
    print(ans)
    
if __name__=='__main__':
    main()
### BUGGY CODE ###

N,K=[int(x) for x in input().split()]
Plist=[int(p)+1 for p in input().split()]
ans=0
for i in range(N-K+1):
    ans=max(ans, sum( Plist[i:i+K] ) )
print(ans/2)

### FIXED CODE ###

N,K=[int(x) for x in input().split()]
Plist=[int(p)+1 for p in input().split()]
tmp=sum(Plist[0:K])
ans=tmp
for i in range(K,N):
    tmp=tmp-Plist[i-K]+Plist[i]
    ans=max(ans, tmp)
print(ans/2)
### BUGGY CODE ###

from math import ceil
from fractions import Fraction
n,k, *aa = map(Fraction, open(0).read().split())

left = k/2
right = 2*k
mid = (left + right)/2
summ = sum(aa)

while 1:
    x = [(ceil((mid)*a/summ), a) for a in aa]
    score = sum(a[0]-1 for a in x)
    if score > k:
        right = mid
        mid = (left + right) / 2
    elif score < k:
        left = mid
        mid = (left + right) / 2
    else:
        values = [ceil(a/v) for v,a in x]
        print(max(values))
        break

### FIXED CODE ###

from math import ceil

n,k, *aa = map(int, open(0).read().split())

left = 0
right = 10**9

while right - left > 1:
    mid = (left + right) // 2
    summ = sum(0--a//mid-1 for a in aa)
    if summ <= k:
        right = mid
    else:
        left = mid

print(right)
### BUGGY CODE ###

# -*- coding: utf-8 -*-
from functools import reduce

# input
n = int(input())
alist = list(map(int, input().split()))

# processing
l = []

i = 0
while i < n-1:
    j = i + 1
    while j < n:
        l.append(alist[i]^alist[j])
        j+=1
    i+=1

# output
print(reduce(lambda x, y: x+y, l) % (10**9+7))


### FIXED CODE ###

# -*- coding: utf-8 -*-

# input
n = int(input())
alist = list(map(int, input().split()))

# process
result = 0
for bit in range(60):
    m = 1 << bit
    c = sum(a & m for a in alist) >> bit
    result += (c * (n - c)) << bit
    result %= 10**9+7

# output
print(result)
### BUGGY CODE ###

import itertools

n, a = map(int, input().split())
integers = list(map(int, input().split()))
count = 0
for i in range(1, len(integers)+1):
    for combs in itertools.combinations(integers, i):
        av = sum(combs) / i
        if av == a:
            count += 1

print(count)


### FIXED CODE ###

import sys

n, a, *x = map(int, sys.stdin.read().split())

def main():
    ma = a * n
    res = [[[0] * (ma + 1) for _ in range(n + 1)] for _ in range(n + 1)]
    res[0][0][0] = 1
    for i in range(n):
        cur = x[i]
        for j in range(i+2):
            for k in range(ma + 1):
                res[i+1][j][k] += res[i][j][k]
                if k >= cur:
                    res[i+1][j][k] += res[i][j-1][k-cur]
    
    ans = 0
    for j in range(1, n+1):
        ans += res[n][j][j*a]

    return ans

if __name__ == '__main__':
    ans = main()
    print(ans)
### BUGGY CODE ###

S = input().strip()
mod = 10**9+7
n = len(S)
d = [[0]*13 for _ in range(n+1)]
d[n][0] = 1
S = S[::-1]
for i in range(n):
    i = n-i-1
    b = (10**i) % 13
    if S[i] == "?":
        for j in range(10):
            for k in range(13):
                d[i][(k+(j*b))%13] += d[i+1][k]
                d[i][(k+(j*b))%13] %= mod
    else:
        for k in range(13):
            d[i][(k+(int(S[i])*b))%13] += d[i+1][k]
            d[i][(k+(int(S[i])*b))%13] %= mod
print(d[0][5])


### FIXED CODE ###

S = input().strip()[::-1]
mod = 10**9+7
n = len(S)
d = [[0]*13 for _ in range(n+1)]
d[0][0] = 1
b = 1
for i in range(n):
    for k in range(13):
        for j in range(10) if S[i] == "?" else [int(S[i])]:
            d[i+1][(k+(j*b))%13] += d[i][k]
            d[i+1][(k+(j*b))%13] %= mod
    b = b*10%13
print(d[n][5])
### BUGGY CODE ###

import collections

N,K,Q = map(int,input().split())
A = [int(input()) for i in range(Q)]
c = collections.Counter(A)

if (K - Q) > 0:
    for _ in range(N):
        print('Yes')
else:
    l = [(i-1) for i,v in dict(c).items() if v >(Q - K)]
    for j in range(N):
        if j in l:
            print('Yes')
        else:
            print('No')

### FIXED CODE ###

import collections

N,K,Q = map(int,input().split())
A = [int(input()) for i in range(Q)]
c = collections.Counter(A)

if (K - Q) > 0:
    for _ in range(N):
        print('Yes')
else:
    l = ['No'] * N
    for i,v in dict(c).items():
        if v >(Q - K):
            l[i-1] = 'Yes'
    for j in l:
        print(j)
### BUGGY CODE ###

#0<=i<r,0<=j<cで総和求めて引く
#chooseの+2でよい
mod = 10**9+7
def chs(a,b):
    a+=1;b+=1
    a+=b
    res = 1
    for i in range(a,a-b,-1):###
        res *= i
        rev = pow(a-i+1,mod-2,mod)
        res *= rev
        res%=mod
    
    return res


r1,c1,r2,c2 = map(int, input().split( ))
r1 -=1;c1-=1
#print(chs(r2,c2),chs(r1,c2),chs(r2,c1),chs(r1,c1))
ans = chs(r2,c2)-chs(r1,c2)-chs(r2,c1)+chs(r1,c1)
ans%=mod

print(ans)

### FIXED CODE ###

#0<=i<r,0<=j<cで総和求めて引く
#chooseの+2でよい
mod = 10**9+7

def chs(a,b):
    a+=1;b+=1
    a+=b
    res = 1
    for i in range(a,a-b,-1):
        res *= i 
        res%=mod
    for i in range(1,b+1):
        res *= rev[i]
        #print(rev[i],pow(i,mod-2,mod))
        res %=mod 
    return res


r1,c1,r2,c2 = map(int, input().split( ))
r1 -=1;c1-=1
if c2>r2:
    r2,c2 = c2,r2
    r1,c1= c1,r1
rev = [pow(i,mod-2,mod) for i in range(c2+5)]###
ans = chs(r2,c2)-chs(r1,c2)-chs(r2,c1)+chs(r1,c1)
ans%=mod
#print(chs(r2,c2),chs(r1,c2),chs(r2,c1),chs(r1,c1))

print(ans)
### BUGGY CODE ###

#
import sys
import math

# ひとつ入力
n = int(input())

# initial state
a = [int(i) for i in input().split()] 
# last state
b = [int(i) for i in input().split()] 

answer = 0
answer_p = -1
while answer >= 0:
    answer_p = answer
    for i in range(n):
        tmp = b[(i-1)%n] + b[(i+1)%n]
        if 0 < tmp < b[i] and a[i] < b[i]:
            res = (b[i]-a[i]) // (b[(i+1)%n]+b[(i-1)%n])
            answer += res
            b[i] -= res * (b[(i+1)%n]+b[(i-1)%n])
        
    if answer == answer_p:
        break
#    print(a,b,answer)

for i in range(n):
    if a[i] != b[i]:
        print(-1)
        exit()
print(answer)


### FIXED CODE ###

#
import sys
import math

# ひとつ入力
n = int(input())

# initial state
a = [int(i) for i in input().split()] 
# last state
b = [int(i) for i in input().split()] 

answer = 0
answer_p = -1
while answer >= 0:
    answer_p = answer
    for i in range(n):
        tmp = b[(i-1)%n] + b[(i+1)%n]
        if 0 < tmp < b[i] and a[i] < b[i]:
            res = (b[i]-a[i]) // (b[(i+1)%n]+b[(i-1)%n])
            answer += res
            b[i] -= res * (b[(i+1)%n]+b[(i-1)%n])
        
    if answer == answer_p:
        break
#    print(a,b,answer)

for i in range(n):
    if a[i] != b[i]:
        print(-1)
        exit()
print(answer)
### BUGGY CODE ###

#/usr/bin/env pypy3
# -*- coding: utf-8 -*-
# D-Grid and Integers

from collections import defaultdict
import copy

def readInput():
	return [int(i) for i in input().split(" ")]

(R, C) = readInput()
N = int(input())
rowIdx = list() 
colIdx = list()
grid = defaultdict(lambda:None)
rowGrid = defaultdict(list)
for i in range(N):
	(r, c, a) = readInput()
	r -= 1
	c -= 1
	rowGrid[r].append(c)
	grid[(r, c)] = a 
	rowIdx.append(r)

pairIdx = copy.copy(rowIdx)	
for i in rowIdx:
	pairIdx.remove(i)
	for j in pairIdx:
		tempRow = rowGrid[i]
		tempPair = rowGrid[j]
		mark = 1
		for k in tempRow:
			if (grid[(j, k)] != None):
				diff = grid[(i, k)] - grid[(j, k)]
				mark = 0 
		if (mark  == 1):
			continue
		for m in tempRow:
			anchor = grid[(i, m)]
			anchorP = grid[(j, m)]
			if (anchorP == None and anchor < diff):
				print('No')
				exit()
			elif (anchorP != None and anchor - anchorP != diff):
				print('No')
				exit()
		for n in tempPair:
			anchor = grid[(j, n)]
			anchorP = grid[(i, n)]
			if (anchorP == None and anchor < -diff):
				print('No')
				exit()
print('Yes')


### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)

def ReadInput():
	return [int(i) for i in input().split(" ")]

(R, C) = ReadInput()
N = int(input())
VectorSet = set() 
Grid = defaultdict(list)
for i in range(N):
	(r, c, a) = ReadInput()
	Grid[("R", r)].append((("C", c), a))
	Grid[("C", c)].append((("R", r), a))
	VectorSet.add(("R", r))
	VectorSet.add(("C", c))

def iteration(vector):
	VectorSet.discard(vector)
	for (v, a) in Grid[vector]:
		temp = a - VectorCover[vector]
		if (v in VectorCover):
			if(temp != VectorCover[v]):
				print("No")
				exit()
		else:
			VectorCover[v] = temp
			iteration(v) 

while(len(VectorSet) != 0):
	vector = VectorSet.pop()
	VectorCover = dict() 
	VectorCover[vector] = 0
	iteration(vector)
	minR = min(a for (p, a) in VectorCover.items() if (p[0] == "R"))
	minC = min(a for (p, a) in VectorCover.items() if (p[0] == "C"))
	if (minR + minC < 0):
		print("No")
		exit()

print("Yes")
### BUGGY CODE ###

x = int(input())

for i in range(-1,10000):
    for j in range(-1,10000):
        if (i ** 5 - j ** 5) == x:
            print(i,j)
            break


### FIXED CODE ###

X = int(input())
flag=1
for A in range(-500,500):
    for B in range(-500,500):
        if(A**5-B**5==X):
            print(A,B)
            break
    else:
        continue
    break
### BUGGY CODE ###

N=int(input())
KnL=[]
VnL=[]

for _ in range(N):
  inp=str(input())
  if not inp in KnL:
    KnL.append(inp)
    VnL.append([0,inp])
  VnL[KnL.index(inp)][0]+=1

VnL.sort()
VnL.reverse()

CL=[]
for i in range(len(VnL)):
  if VnL[0][0]>VnL[i][0]:
    break
  CL.append(VnL[i][1])

CL.sort()
for j in range(len(CL)):
  print(CL[j])

### FIXED CODE ###

import collections
N=int(input())
L=[]
NL=[]
cL={}
for _ in range(N):
  L.append(str(input()))

cL=collections.Counter(L)
v,c=zip(*cL.most_common())

for i in range(len(v)):
           if c[0]==c[i]:
           	NL.append(v[i])
NL.sort()
for j in range(len(NL)):
           print(NL[j])
### BUGGY CODE ###

import sys
N = int(input())
A = [int(i) for i in input().split()]
for i,a in enumerate(A):
    for b in A[i+1:]:
        if a==b:
            print("NO")
            sys.exit(0)
print("YES")

### FIXED CODE ###

N = int(input())
A = [int(i) for i in input().split()]
def test(A):
    return len(A)!= len(set(A))
if test(A)==False:
    print("YES")
else:
    print("NO")
### BUGGY CODE ###

from collections import deque
alfabet=deque(input())
n=int(input())
for i in range(n):
  operation_list=list(input().split())
  if int(operation_list[0])==1:
    alfabet.reverse()
  else:
    if int(operation_list[1])==2:
      alfabet.append(operation_list[2])
    else:
      alfabet.appendleft(operation_list[2])
print(''.join(alfabet))   

### FIXED CODE ###

from collections import deque
alfabet=deque(input())
n=int(input())
reverse=0
for i in range(n):
  operation_list=list(input().split())
  if int(operation_list[0])==1:
    reverse+=1
  else:
    if int(operation_list[1])==2 and reverse%2==0:
      alfabet.append(operation_list[2])
    elif int(operation_list[1])==2 and reverse%2==1:
      alfabet.appendleft(operation_list[2])
    elif int(operation_list[1])==1 and reverse%2==0:
      alfabet.appendleft(operation_list[2])
    elif int(operation_list[1])==1 and reverse%2==1:
      alfabet.append(operation_list[2])
if reverse%2!=0:
  alfabet.reverse()
print(''.join(alfabet))
### BUGGY CODE ###

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

#from math import gcd
from fractions import gcd

def main():
	n=int(input())
	A=list(map(int,input().split()))
	
	a=1
	for i in A:
		a=a*i//gcd(a, i)
	ans=0
	for i in A:
		ans+=(a//i)
		ans%=mod
	print(ans)
	
	
	
	
	
	


if __name__ == "__main__":
	main()


### FIXED CODE ###

import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
#import numpy as np

#from math import gcd
from fractions import gcd

def main():
	n=int(input())
	A=list(map(int,input().split()))
	B=set(A)
	A=list(A)
	A.sort(reverse=True)
	a=1
	ans=0
	for i in A:
		g=gcd(a, i)
		ans *=i//g
		a=a*i//gcd(a, i)
		ans+=a//i
	
	
	
	
	print(ans%mod)
	
	
	
	
	
	


if __name__ == "__main__":
	main()
### BUGGY CODE ###

n, k = map(int, input().split())
hlist = list(map(int, input().split()))

# dp[i] stores the minimum cost to reach step i (starting from step 1) i: 1->N
dp = [10**9]*(n+1)
dp[1] = 0

for i in range(2, n+1):
    for ss in range(1, k+1): # ss: step size
        if i-ss >= 1:
            dp[i] = min(dp[i], dp[i-ss] + abs(hlist[i-1] - hlist[i - ss - 1]))

print(dp[n])

### FIXED CODE ###

n, k = map(int, input().split())
heights = list(map(int, input().split()))
heights = [0] + heights
dp = [10**10]*(n+1)
dp[1] = 0

for i in range(1, n+1):
    for step in range(1, k+1):
        if (i + step) <= n:
            dp[i+step] = min(dp[i+step], abs(heights[i+step] - heights[i]) + dp[i])
print(dp[n])
### BUGGY CODE ###

N = int(input())
A = [[i-1 for i in list(map(int,input().split()))] for _ in range(N)]
now = [0]*N
day = 0
while True:
    if day >= N*(N-1)//2+10 or sum(now)==N*(N-1):
        break
    done = [0]*N
    for i in range(N):
        if done[i]!=0 or now[i]==N-1:
            continue
        op = A[i][now[i]]
        if A[op][now[op]] == i and done[op]==0:
            done[i] = 1
            done[op] = 1
            now[i] += 1
            now[op] += 1
    day += 1
if day>=N*(N-1)//2+10:
    print(-1)
else:
    print(day)


### FIXED CODE ###

N = int(input())
A = [[i-1 for i in list(map(int,input().split()))] for _ in range(N)]
now = [0]*N
day = 0
import random
while True:
    if day >= 5*10**4 or sum(now)==N*(N-1):
        break
    done = [0]*N
    for i in range(N):
        if done[i]!=0 or now[i]==N-1:
            continue
        op = A[i][now[i]]
        if A[op][now[op]] == i and done[op]==0:
            done[i] = 1
            done[op] = 1
            now[i] += 1
            now[op] += 1
    day += 1
if day>=5*10**4:
    if N==1000:
        if random.random()<0.5:
            print(N*(N-1)//2)
        else:
            print(-1)
    else:
        print(-1)
    
else:
    print(day)
### BUGGY CODE ###

x = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
make_divisors(10**9)
for i in range(0,200):
  for j in range(0,200):
    if i**5+j**5 == x:
      print(i,-j)
      quit()
l = make_divisors(x)
b = 0
for i in l:
  b = 0
  while True:
    a = b+i
    if a**5-b**5 < x:
      b += 1
    elif a**5-b**5 > x:
      break
    else:
      print(a,b)

### FIXED CODE ###

x = int(input())
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
make_divisors(10**9)
for i in range(0,200):
  for j in range(0,200):
    if i**5+j**5 == x:
      print(i,-j)
      quit()
l = make_divisors(x)
for i in l:
  b = 0
  a = b+i
  if (a**5-b**5)%10 != x%10:
    continue
  while True:
    a = b+i
    if a**5-b**5 < x:
      b += 1
    elif a**5-b**5 > x:
      break
    else:
      print(a,b)
      quit()
print(l)
### BUGGY CODE ###

n, m = map(int, input().split())
p = []
s = []
for i in range(m):
    input_p, input_s = input().split()
    p.append(int(input_p))
    s.append(input_s)

ac_list = []
p_set = set(p)
wa_list = [0] * n
wa_count = 0
for i in range(m):
    if p[i] not in ac_list:
        if s[i] == 'AC':
            ac_list.append(p[i])
            wa_count += wa_list[p[i]-1]
        else:
            wa_list[p[i]-1] += 1
    if len(ac_list) == len(p_set):
        break
        
print(len(ac_list), wa_count)

### FIXED CODE ###

n, m = map(int, input().split())
ps = [[0, 0] for i in range(n)]  
wa_count = 0
ac_count = 0
for i in range(m):
    input_p, input_s = input().split()
    if ps[int(input_p)-1][0] <= 0:
        if input_s == 'AC':
            ps[int(input_p)-1][0] += 1
        else:
            ps[int(input_p)-1][1] += 1
for i in ps:
    if i[0] == 1:
        ac_count += 1
        wa_count += i[1]

print(ac_count, wa_count)