Harryxun/stf_run huggingface dataset:
MOD = 10**9 + 7

N,K = map(int,input().split())
A = list(map(int,input().split()))
B = A*2
d = []

for i in range(N*2):
  num = B[i]
  target = B[i+1:]
  d.append(len([n for n in target if num > n]))
  
d_each = sum(d[:N]) - sum(d[N:])
first = sum(d[N:])
print(int( K/2*((2*first)+((K-1)*d_each)) )%MOD)


### FIXED CODE ###

M,D = map(int,input().split())
count = 0
for m in range(1,M+1):
  for d in range(20,D+1):
    d_10 = d//10
    d_1 = d-10*d_10
    if d_10>=2 and d_1>=2 and d_10*d_1 == m:
      count += 1
print(count)
# -*- coding: utf-8 -*-


s = set(input())
if s in {{'N', 'S'}, {'W', 'E'}, {'N', 'W', 'S', 'N'}}:
    print('Yes')
else:
    print('No')

    

### FIXED CODE ###

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

s=set(input())
if s in [{'W','E'},{'N','S'},{'N','E','W','S'}]:
  print('Yes')
else:
  print('No')
from math import sqrt as r
a, b, c = map(int, input().split())
n = r(a) + r(b)
if (a + b + 2 * r(a * b)) * a * b < a * b * c:
    print("Yes")
else:
    print("No")
#print(n)
#print(r(c))


### FIXED CODE ###

k = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

i = int(input())
print(k[i - 1])
import sys
from collections import defaultdict as dd
from collections import deque as dq
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

table = [[] for _ in range(N + 1)]
sta = []
for x in range(1, N + 1):
  Q = dq([])
  Q.append((x, 0))
  vis = set()
  while len(Q):
    y, n = Q.popleft()
    if n == 3:
      table[x].append(y)
      continue
    for q in e[y]:
      if q in vis: continue
      vis.add(q)
      Q.append((q, n + 1))
  sta.append((len(table[x]), x))
sta.sort()
nm = [0] * 3
for x in range(1, N + 1): nm[x % 3] += 1

res = [0] * (N + 1)

while nm[0]:
  _, x = sta.pop()
  res[x] = nm[0] * 3
  nm[0] -= 1

while nm[1]:
  _, x = sta.pop()
  ng = 0
  for y in table[x]:
    if res[y] % 3 == 1:
      ng = 1
      break
  if ng: continue
  res[x] = (nm[1] - 1) * 3 + 1
  nm[1] -= 1

while nm[2]:
  _, x = sta.pop()
  ng = 0
  for y in table[x]:
    if res[y] % 3 == 2:
      ng = 1
      break
  if ng: continue
  res[x] = (nm[2] - 1) * 3 + 2
  nm[2] -= 1

print(*res[1: ])

### FIXED CODE ###

import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())
e = dd(list)
for _ in range(N - 1):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)

cl = [0] * (N + 1)
vis = set()
def dfs(x):
  global cl
  global vis
  vis.add(x)
  for y in e[x]:
    if y in vis: continue
    cl[y] = (cl[x] + 1) % 2
    dfs(y)

dfs(1)
bl = cl.count(1)
wh = N - bl
res = [0] * (N + 1)
nm = [[] for _ in range(3)]
for i in range(1, N + 1): nm[i % 3].append(i)
#print(cl)
if bl <= N // 3:
  for i in range(1, N + 1):
    if cl[i]:
      res[i] = nm[0].pop()
    else:
      if len(nm[1]): res[i] = nm[1].pop()
      elif len(nm[2]): res[i] = nm[2].pop()
      else: res[i] = nm[0].pop()
  print(*res[1: ])
  exit(0)
if wh <= N // 3:
  for i in range(1, N + 1):
    if cl[i] == 0:
      res[i] = nm[0].pop()
    else:
      if len(nm[1]): res[i] = nm[1].pop()
      elif len(nm[2]): res[i] = nm[2].pop()
      else: res[i] = nm[0].pop()
  print(*res[1: ])
  exit(0)
#print(nm)
#print(cl, nm)
f = 0
for i in range(1, N + 1):
  if cl[i]:
    if len(nm[1]):
      res[i] = nm[1].pop()
    else:
      res[i] = nm[0].pop()
  else:
    if len(nm[2]):
      res[i] = nm[2].pop()
    else:
      res[i] = nm[0].pop()

print(*res[1: ])
import math
N, K = map(int,input().split())
for i in range(1,K+1):
    ans = (math.factorial(K-1) // (math.factorial(K-1-i+1)*math.factorial(i-1))) * (math.factorial(N-K) // (math.factorial(N-K-i)*math.factorial(i)))
    tans = int(ans % (10**9+7))
    print(tans)

### FIXED CODE ###

import math
N, K = map(int,input().split())
for i in range(1,K+1):
    if N-K+1-i >= 0:
        ans = (math.factorial(K-1) // (math.factorial(K-1-i+1)*math.factorial(i-1))) * (math.factorial(N-K+1) // (math.factorial(N-K+1-i)*math.factorial(i)))
        tans = int(ans % (10**9+7))
        print(tans)
    else:
        print(0)
S = input()
res = 0
for i in range(4):
    if S[i] == ‘+’:
        res += 1
    else:
        res -= 1
print(res)


### FIXED CODE ###

S = input()
res = 0
for i in range(4):
    if S[i] == '+':
        res += 1
    else:
        res -= 1
print(res)
N, M = map(int, input().split())

l = []

for i in range(N):
    l.append(list(map(int, input().split())))

lis = [[] for i in range(N)]

for i in range(N):
    lis[l[i][0] - 1].append(l[i][1])
    lis[l[i][1] - 1].append(l[i][0])

print(lis)

# 隣接行列
# list = [[0 for c in range(M)] for r in range(N)]
#
# for i in range(M):
#     tmp_n, tmp_m = map(int, input().split())
#     list[tmp_n - 1][tmp_m - 1] = 1
#
#
# def dot(index1, index2):
#     results = [[0 for c in range(M)] for r in range(N)]
#     for (i, j) in zip(index1, zip(*index2)):
#         print(i,j)
#     return results



# 再起関数
# def travel(now, nextnodes, visited):
#     ends.append(visited)
#     visited.append(now + 1)
#     for node in nextnodes:
#         if node in visited:
#             continue
#         travel(node - 1, lis[node - 1], visited[:])
#
#
# travel(0, lis[0], [])

que = [[0, lis[0], []]]
ends = []
while que:
    now, nextnodes, visited = que.pop()
    ends.append(visited)
    visited.append(now + 1)
    for node in nextnodes:
        if node in visited:
            continue
        que.append([node - 1, lis[node - 1], visited[:]])

print(len(list(filter(lambda i: len(i) is 3, ends))))

### FIXED CODE ###

N, M = map(int, input().split())

l = []

for i in range(M):
    l.append(list(map(lambda x: int(x) - 1, input().split())))

lis = [[] for i in range(N)]

for i in range(M):
    lis[l[i][0]].append(l[i][1])
    lis[l[i][1]].append(l[i][0])


# 隣接行列
# list = [[0 for c in range(M)] for r in range(N)]
#
# for i in range(M):
#     tmp_n, tmp_m = map(int, input().split())
#     list[tmp_n - 1][tmp_m - 1] = 1
#
#
# def dot(index1, index2):
#     results = [[0 for c in range(M)] for r in range(N)]
#     for (i, j) in zip(index1, zip(*index2)):
#         print(i,j)
#     return results



# 再起関数
# def travel(now, nextnodes, visited):
#     ends.append(visited)
#     visited.append(now + 1)
#     for node in nextnodes:
#         if node in visited:
#             continue
#         travel(node - 1, lis[node - 1], visited[:])
#
#
# travel(0, lis[0], [])

que = [[0, lis[0], []]]
ends = []

while que:
    now, nextnodes, visited = que.pop()
    ends.append(visited)
    visited.append(now)
    for node in nextnodes:
        if node in visited:
            continue
        que.append([node, lis[node], visited[:]])

print(len(list(filter(lambda ii: len(ii) is N, ends))))
l = ["p","p","h","b","h","h","p","h","p","h"]
n = input()
print(l[int(n[2])] + "on")

### FIXED CODE ###

l = ["p","p","h","b","h","h","p","h","p","h"]
n = input()
print(l[int(n[-1])] + "on")
from collections import deque

D = deque()
N = int(input())

for i in range(N):
	c, s = input().split()
	if c == "insert":
		d.append(s)
	elif c == "find":
		if (s in d):
			print(Yes)
		else:
			print(No)

### FIXED CODE ###

from collections import deque

D = set()
N = int(input())

for i in range(N):
	c, s = input().split()
	if c == "insert":
		D.add(s)
	elif c == "find":
		if (s in D):
			print("yes")
		else:
			print("no")
n = int(input())
a = list(map(int,input().split()));
q = int(input())
aa = 0;
for i in range(n):
    aa += a[i];

b = [input().split() for l in range(q)]

bu = [None]*(100000);

for i in range(10000):
    bu[i] = a.count(i);
    
for x in range(q):
    c = int(b[x][0])
    d = int(b[x][1])
    aa += (d-c)*(bu[c]);
    bu[d] += bu[c];
    bu[c] = 0;
    
print(aa);

### FIXED CODE ###


n = int(input())
a = list(map(int,input().split()));
q = int(input())
aa = 0;
for i in range(n):
    aa += a[i];

b = [input().split() for l in range(q)]

bu = [0]*(100000);

for i in range(n):
    bu[a[i]-1] += 1;
    
for x in range(q):
    c = int(b[x][0])
    d = int(b[x][1])
    aa += (d-c)*(bu[c-1]);
    bu[d-1] += bu[c-1];
    bu[c-1] = 0;
    print(aa);
n = int(input())
start = 1
for i in range(2, n+1):
    start *= i
    start %= MOD
print(start)

### FIXED CODE ###

MOD = 10**9 + 7
n = int(input())
start = 1
for i in range(2, n+1):
    start *= i
    start %= MOD
print(start)
#解答例
N,M=map(int,input().split())
A=list(map(int,input().split()))#使える数字の種類
weight=[0,2,5,5,4,5,6,3,7,6]#作るのに何本必要か、また0は作れないので0になっている
dp=[-1]*(N+1)#とりあえずこれくらい確保しておけばok
dp[0]=0#0本では0しか作れない
#dp[i]はちょうどi本で作れる最高の数を入れることにする
for i in range(N+1):#N本あるから、一本ずつ増やしていって最大N本
    if dp[i] == -1:continue
    for a in A:
        if i+weight[a]<N+1:#今あるi本にa本を加えてもN本を超えないか
            dp[i+weight[a]]=max(dp[i+weight[a]],dp[i]*10+a)#今まで作ったi+weight[a]のときのdpの値と、今作ったdp[i]*10+aの値を比べ、大きい方を格納する
                                                           #なぜdp[i]*10+aになるのかに関しては、右から数字を追加していく場合のみを考えることで、重複せずに全通り試せるから
                                                        　 #もし一通りもなかった場合、-1が格納されたままになるため問題がない
print(dp[N])

### FIXED CODE ###

#解答例
N,M=map(int,input().split())
A=list(map(int,input().split()))#使える数字の種類
weight=[0,2,5,5,4,5,6,3,7,6]#作るのに何本必要か、また0は作れないので0になっている
dp=[-1]*(N+1)#とりあえずこれくらい確保しておけばok
dp[0]=0#0本では0しか作れない
#dp[i]はちょうどi本で作れる最高の数を入れることにする
for i in range(N+1):#N本あるから、一本ずつ増やしていって最大N本
    for a in A:
        if i+weight[a]<N+1:#今あるi本にa本を加えてもN本を超えないか
            dp[i+weight[a]]=max(dp[i+weight[a]],dp[i]*10+a)#今まで作ったi+weight[a]のときのdpの値と、今作ったdp[i]*10+aの値を比べ、大きい方を格納する
                                                           #なぜdp[i]*10+aになるのかに関しては、右から数字を追加していく場合のみを考えることで、重複せずに全通り試せるから
print(dp[N])
N = int(input())
R = int(input())
if N < 10:
    print(R+100*(10-N))
else:
    print(R)


### FIXED CODE ###

N,R= map(int,input().split())
if N < 10:
    print(R+100*(10-N))
else:
    print(R)
'''
def gcd(a,b):
    if a<b:
     c=a
     a=b
     b=c

    c=a%b

    if c==0:
     return b
    else:
     return gcd(b,c)
'''

def gcd(a,b):
    return a if b == 0 else gcd(b,a%b)

def lcm(e,f):
    c=gcd(e,f)
    return e/c*f



n=int(input())
t=[0]*n

for lop2 in range(n):
    t[lop2]=int(input())

ans=t[0]

for lop in range(1,n):
    ans=lcm(ans,t[lop])
print(int(ans))


### FIXED CODE ###

'''
def gcd(a,b):
    if a<b:
     c=a
     a=b
     b=c

    c=a%b

    if c==0:
     return b
    else:
     return gcd(b,c)
'''

def gcd(a,b):
    return a if b == 0 else gcd(b,a%b)

def lcm(e,f):
    c=gcd(e,f)
    g=e*f
    return g//c



n=int(input())
t=[0]*n

for lop2 in range(n):
    t[lop2]=int(input())

ans=t[0]

for lop in range(1,n):
    ans=lcm(ans,t[lop])
print(int(ans))
n = int(input())
s = input()

if n % 2 == 1:
    print("No")
else:
    if s[:(n//2)] == x[(n//2):]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

n = int(input())
s = input()

if n % 2 == 1:
    print("No")
else:
    if s[:(n//2)] == s[(n//2):]:
        print("Yes")
    else:
        print("No")
a,b=map(int,input().split())
c=a+b
d=a-b
e=a*b
print(sum(c,d,e))

### FIXED CODE ###

a,b=map(int,input().split())
c=a+b
d=a-b
e=a*b
print(max(c,d,e))
T = input()
PD = list(T)

for i in range(len(PD)):
  if PD[i] == '?':
    if i == 0 and P[1] in ('D','?'):
      PD[i] = 'P'
    elif i == len(PD):
      PD[i] = 'D'
    elif PD[i-1] == 'D' and PD[i+1] in ('D','?'):
      PD[i] = 'P'
    elif PD[i+1] == 'D':
      PD[i] = 'P'
    else:
      PD[i] = 'D'
      
print(''.join(PD))

### FIXED CODE ###

T = input()
print(T.replace('?','D'))
import itertools
n=int(input())
la=[]
for _ in range(n):
  d=int(input())
  for dd in d:
    x,y=map(int,input().split())
    la.append([_,x-1,y])
ans=0
for i in itertools.product([0,1],repeat=n):
  s=sum(list(i))
  for l in la:
    if i[l[0]]==1 and i[l[1]]!=l[2]:
      break
  else:
    ans=max(ans,s)
print(ans)

### FIXED CODE ###

import itertools
n=int(input())
la=[]
for _ in range(n):
  d=int(input())
  for dd in range(d):
    x,y=map(int,input().split())
    la.append([_,x-1,y])
ans=0
for i in itertools.product([0,1],repeat=n):
  s=sum(list(i))
  for l in la:
    if i[l[0]]==1 and i[l[1]]!=l[2]:
      break
  else:
    ans=max(ans,s)
print(ans)
n,k = map(int,input().split())
h = list(ap(int,input().split()))
print(len([0 for x in h if x >= k]))


### FIXED CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
print(len([0 for x in h if x >= k]))
o = input()
e = input()
ans = ""
for i in o:
  ans += o[i]
  ans += e[i]
print(ans)

### FIXED CODE ###

o = input()
e = input()
ans = ""
for i in range(len(o)):
  ans += o[i]
  if len(e) > i:
    ans += e[i]
print(ans)
a,b = map(int,input().split())

print(a * B)

### FIXED CODE ###

a,b = map(int,input().split())

print(a * b)
s = input()
n = len(s)
k = int(input())
for i in range(k):
    if i == n:
        break

    if s[i] != '1':
        ans = int(s[i])
        break
    else:
        continue
if ans:
    print(ans)
else:
    print(1)

### FIXED CODE ###

s = input()
n = len(s)
k = int(input())
ans = None
for i in range(k):
    if i == n:
        break

    if s[i] != '1':
        ans = int(s[i])
        break
    else:
        continue
if ans:
    print(ans)
else:
    print(1)
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


N, K = map(int, input().split())

if N == 2:
    if K == 0:
        print(1)
        print(1, 2)
    else:
        print(-1)
else:
    cmb = combinations_count(N-1, 2)
    if cmb < K or K < N - 2:
        print(-1)
    else:
        d = cmb - K
        edges = []
        for i in range(1, d+1):
            edges.append((i, i+1))
        for j in range(1, N - d):
            edges.append((i+1, i+1+j))
        print(N-1)
        for e in edges:
            print(*e)



### FIXED CODE ###

import math

N, K = map(int, input().split())

upper = (N-1)*(N-2) // 2
if upper < K:
    print(-1)
else:
    diff = upper - K
    edges = []
    for i in range(2, N+1):
        edges.append((1, i))
    j = 2
    while diff > 0:
        k = j + 1
        while k <= N and diff > 0:
            edges.append((j, k))
            k += 1
            diff -= 1
        j += 1
    print(len(edges))
    for e in edges:
        print(*e)
import math
x, y = map(int, input().split())
if (2*x-y)%3 != 0 or (-x+2*y)%3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (-x+2*y)//3
print(math.factorial(a+b)//(math.factorial(a)*math.factorial(b))%(10**9+7))


### FIXED CODE ###

import math
x, y = map(int, input().split())
if (2*x-y)%3 != 0 or (-x+2*y)%3 != 0:
    print(0)
    exit()
a = (2*x-y)//3
b = (-x+2*y)//3
if a < 0 or b < 0:
    print(0)
    exit()
def comb(n, r, mod):
    r = min(r, n-r)
    numer = denom = 1
    for i in range(1, r+1):
        numer = numer * (n+1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom, mod-2, mod) % mod
print(comb(a+b, a, 10**9+7))
H,W = input().split()
H = int(H)
W = int(W)

shw = [list(map(str, input())) for _ in range(W)]

        

for i in range(1,H-1):
    for j in range(1,W-1):
        if shw[i][j] == str('#'):
            if shw[i][j] != shw[i+1][j] and shw[i][j] != shw[i][j+1] and shw[i][j] != shw[i-1][j] and shw[i][j] != shw[i][j-1]:
                print("No")
                exit()
print("Yes")

### FIXED CODE ###

H,W=map(int,input().split())
S=["."+input()+"." for i in range(H)]
S=["."*(W+2)]+S+["."*(W+2)]
flag=0
for i in range(H):
    for j in range(W):
        if S[i][j]=="#":
            if S[i-1][j]=="." and S[i+1][j]=="." and S[i][j-1]=="." and S[i][j+1]==".":
                flag=1
print("Yes" if flag==0 else "No")
x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(1,101)]
b = list(set(a) - set(p))
for i in range(len(b)):
  if x <= b[i]:
    if abs(b[i-1]-x) <= abs(b[i]-x):
      print(b[i-1])
      exit(0)
    else:
      print(b[i])
      exit(0)
print(x-b[-1])

### FIXED CODE ###

x, n = map(int, input().split())
if n == 0:
  print(x)
  exit(0)
p = list(map(int, input().split()))
a = [i for i in range(201)]
b = sorted(list(set(a) - set(p)))
min_v = 1000
min_id = 0
for i in range(len(b)):
  if abs(x - b[i]) < min_v:
    min_v = abs(x - b[i])
    min_id = i
print(b[min_id])
from copy import deepcopy

N = int(input())
A = list(map(int, input().split()))

index = [i for i in range(N)]
index = sorted(index, key=lambda i: A[i], reverse=True)


def LorR(index, res):
    i = index[0]
    dist = max(i, N - 1 - i)
    end = False
    cand1 = cand2 = 0
    while not end:
        j = i + dist
        if 0 <= j and j < N and not res[j]:
            r = deepcopy(res)
            r[j] = True
            cand1 = A[i] * dist + loop(index[1:], r)
            end = True

        j = i - dist
        if 0 <= j and j < N and not res[j]:
            r = deepcopy(res)
            r[j] = True
            cand2 = A[i] * dist + loop(index[1:], r)
            end = True

        dist -= 1
    return max(cand1, cand2)


def loop(index, res):
    if not index:
        return 0

    return LorR(index, res)


print(loop(index, [False] * N))


### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))

A = sorted([(val, pos) for pos, val in enumerate(A)], reverse=True)

dp = [0]
for i, (val, pos) in enumerate(A):
    ldp = [e + val * abs(pos - (i - r)) for r, e in enumerate(dp)]
    rdp = [e + val * abs(N - 1 - r - pos) for r, e in enumerate(dp)]
    dp = [max(L, R) for L, R in zip(ldp + [0], [0] + rdp)]

print(max(dp))
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define endl "\n"
#define deb(x) cerr << #x << ":" << x << "\n"

ll n,k,mod=1e9+7,ans=0;

ll fastMod(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b&1)res=(res*a)%mod;
        b/=2;
        a=(a*a)%mod;
    }
    return res;
}

void solve(){    
    cin>>n>>k;
    vector<ll> v(k+1);
    for(int i=k;i>0;i--){
        v[i]=fastMod(k/i,n);
        for(int j=2*i;j<=k;j+=i){
            v[i]=(v[i]-v[j]+mod)%mod;
        }
    }
    for(int i=1;i<=k;i++){
        ll val=(v[i]*i)%mod;
        ans=(ans+val)%mod;
    }
    cout<<ans%mod;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


### FIXED CODE ###

n,k=[int(x) for x in input().split()]
ans=0
l=[0]*(k+1)
i=k
mod=1000000007
while i>0:
    l[i]=pow(k//i,n,mod)
    j=2*i
    while j<=k:
        l[i]=(l[i]-l[j]+mod)%mod
        j+=i
    i-=1
for i in range(1,k+1):
    ans+=(l[i]*i)%mod
print(ans%mod)
s=int(input())
t='CODEFESTIVAL2016'
ans=0
for i in range(16):
  if s[i]!=t[i]:
    ans+=1
print(ans)


### FIXED CODE ###

s=input()
t='CODEFESTIVAL2016'
ans=0
for i in range(16):
  if s[i]!=t[i]:
    ans+=1
print(ans)
def main() :
    W, H, x, y, r = [int(i) for i in input().split()]

   if ((x-r)>=0) and ((x+r)<=W) and ((y-r)>=0) and ((y+r)<=H) :
        print("Yes")
    else :
        print("No")

if __name__ == '__main__' :
    main()

### FIXED CODE ###

def main() :
    W, H, x, y, r = [int(i) for i in input().split()]

    if (r <= x <= W-r) and (r <= y <= H-r) :
        print("Yes")
    else :
        print("No")

if __name__ == '__main__' :
    main()
stack = [i for i in input().split()]

op = ['+', '*', '-']
while True:
    a = stack.pop()
    if a in op:
        l = stack.pop()
        r = stack.pop()
        stack.append(eval(l + a + r))
    if len(stack) == 1:
        break
print (stack[0])

### FIXED CODE ###

i = [i for i in input().split()]


op = ['+', '*', '-']
stack = []

for j in i:
    if j in op:
        r = stack.pop()
        l = stack.pop()
        stack.append(str(eval(l + j + r)))
    else:
        stack.append(j)
print (stack[0])
if __name__ == "__main__":
	N, M = map(int, input().split())
	prob_list = [0] * (N+1)
	wa = 0
	for i in range(M):
		p, s = input().split()
		p = int(p)
		if s == "AC":
			prob_list[p] = 1
		else:
			if prob_list[p] == 0:
				wa += 1
		# print(prob_list)
	ac = 0
	for i in range(N+1):
		ac += prob_list[i]
	print(f"{ac} {wa}")


### FIXED CODE ###

if __name__ == "__main__":
	N, M = map(int, input().split())
	ac_list = [0] * (N+1)
	wa_list = [0] * (N + 1)
	for i in range(M):
		p, s = input().split()
		p = int(p)
		if s == "AC":
			ac_list[p] = 1
		else:
			if ac_list[p] == 0:
				wa_list[p] += 1
		# print(prob_list)
	ac = 0
	wa = 0
	for i in range(N+1):
		ac += ac_list[i]
		if ac_list[i] == 1:
			wa += wa_list[i]
	print("{0} {1}".format(ac, wa))
import math 
import bisect
import heapq
from collections import deque

n = int(input())
h = map(int,input().split())

l = [0] * n
l[0] = 0
for i in range(1,n):
    l[i] = l[i-1] + 1 if h[i-1] >= h[i] else 0

print(max(l))


### FIXED CODE ###

import math 
import bisect
import heapq
from collections import deque

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

l = [0] * n
l[0] = 0
for i in range(1,n):
    l[i] = l[i-1] + 1 if h[i-1] >= h[i] else 0

print(max(l))
N = int(input())
a = map(int,input().split())
k = 1
for i in a:
    k*=i
l = 0
while k%2 == 0:
    l += 1
    k /= 2
print (l)


### FIXED CODE ###

N = int(input())
a = map(int,input().split())
k = 0
for i in a:
    while i%2 == 0:
        k+=1
        i/=2
print(k)
import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)
ans=0
for i in range(x):
    _p,_r=heapq.heappop(p),heapq.heappop(r)
    if _p<_r:
        ans-=_p
        heapq.heappush(r,_r)
    else:
        ans-=_r
        heapq.heappush(p,_p)
for i in range(y):
    _q,_r=heapq.heappop(q),heapq.heappop(r)
    if _q<_r:
        ans-=_q
        heapq.heappush(r,_r)
    else:
        ans-=_r
        heapq.heappush(q,_q)
print(ans)
    


### FIXED CODE ###

import heapq
x,y,a,b,c=map(int,input().split())
def _int(x):
    return -int(x)
p=list(map(_int,input().split()))
q=list(map(_int,input().split()))
r=list(map(_int,input().split()))
heapq.heapify(p)
heapq.heapify(q)
heapq.heapify(r)

ans=[]
heapq.heapify(ans)
for i in range(x):
    _p=heapq.heappop(p)
    heapq.heappush(ans,-_p)
for i in range(y):
    _q=heapq.heappop(q)
    heapq.heappush(ans,-_q)
#ansは小さい順、rは大きい順
for i in range(x+y):
    if len(r)==0:break
    _ans=heapq.heappop(ans)
    _r=-heapq.heappop(r)
    if _r>=_ans:
        heapq.heappush(ans,_r)
    else:
        heapq.heappush(ans,_ans)
        break
print(sum(ans))
N = int(input())
S = input()
if N%2==1:
    print('No')
else:
    for i in range(N//2):
        S1 += S[i]
    for j in range(N//2,N):
        S2 += S[j]
    if S1==S2:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

N = int(input())
S = input()
S1 = ''
S2 = ''
if N%2==1:
    print('No')
else:
    for i in range(N//2):
        S1 += S[i]
    for j in range(N//2,N):
        S2 += S[j]
    if S1==S2:
        print('Yes')
    else:
        print('No')
H, W, m = map(int, input().split())
hs = [0] * (H+1)
ws = [0] * (W+1)
fs = [[0]*(W+1) for i in range(H+1)]
for i in range(m):
    hi,wi = map(int, input().split())
    hs[hi-1] += 1
    ws[wi-1] += 1
    fs[hi-1][wi-1] += 1

N = 10**6
Hs = [h*N+i for i,h in enumerate(hs)]
Ws = [w*N+i for i,w in enumerate(ws)]
Hs.sort(reverse=True)
Ws.sort(reverse=True)

mx = 0
cnt = 0
for h_ in Hs:
    nh, ih = divmod(h_,N)
    for w_ in Ws:
        nw, iw = divmod(w_,N)
        mx = max(mx,nh+nw-fs[ih][iw])
        cnt += 1
        if cnt > m:
            print(mx)
            exit()
print(mx)

### FIXED CODE ###

H, W, m = map(int, input().split())
hs = [0] * (H+1)
ws = [0] * (W+1)
from collections import defaultdict
d = defaultdict(bool)
N = 10**6
for i in range(m):
    hi,wi = map(int, input().split())
    hi -= 1
    wi -= 1
    hs[hi] += 1
    ws[wi] += 1
    d[hi*10**6+wi] = True

hmx = max(hs)
hset = set()
for i,h in enumerate(hs):
    if h == hmx:
        hset.add(i)
wmx = max(ws)
wset = set()
for j, w in enumerate(ws):
    if w == wmx:
        wset.add(j)

flg = False
ans = 0
cnt = 0
for i in hset:
    for j in wset:
        ans = max(ans, hmx+wmx-d[i*N+j]) 
        if cnt >= m:
            flg = True
            break
        cnt += 1
    if flg:break

print(ans)