peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N=int(input())
L=[]
for i in range(N):
    A, B=list(map(int,input().split()))
    L.append((A,B))
L1=sorted(L,key=lambda x: x[0])
L2=sorted(L,key=lambda x: x[1])
if N%2==1:
    n=N//2
    print(L2[n][1] -L1[n][0]+1)
else:
    n=N//2
    m=(L1[n-1][1]+L1[n][1])/2
    print(L2[n-1][1]+L2[n][1]-L1[n-1][0]-L1[n][0]+1)
# Judge status: Accepted
from collections import Counter

N = int(input())
S = input()
SC = Counter(S)
mod = 10**9 + 7
ans = 1
for key, value in SC.items():
    ans *= (value+1)
    ans %= mod
print(ans-1)
# Judge status: Wrong Answer
l = []
flag = 0
for i in range(3):
  for j in input().split():
    l.append(j)
n = int(input())
for i in range(n):
  a = input()
  if a in l:
    l[l.index(a)] = 0
if l[0:3] == 0 or l[3:6] == 0 or l[6:9] == 0:
  flag = 1
if l[0::3] == 0 or l[1::3] == 0 or l[2::3] == 0:
  flag = 1
if l[0::4] == 0 or l[2::2] == 0:
  flag = 1
if flag:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
#!/usr/bin/env python
# coding: utf-8

# In[7]:


import math


# In[13]:


N,D = map(int, input().split())
X = []
for _ in range(N):
    X.append(list(map(int, input().split())))


# In[14]:


ans = 0
for i in range(N-1):
    for j in range(i+1,N):
        dist = sum((X[i][k]-X[j][k])**2 for k in range(D))
        if math.sqrt(dist)%1 == 0:
            ans += 1
print(ans)


# In[ ]:
# Judge status: Accepted
n = int(input())

keta = 1
for i in range(1, 18):
    t = 26*(26**i-1)//25
    if n <= t:
        break
    else:
        keta += 1

n -= 26*(26**(keta-1)-1)//25
n -= 1

ans = ""
for i in range(keta):
    t = 26**i
    ans = chr(ord('a')+(n//t)%26)+ans
print(ans)
# Judge status: Wrong Answer
from collections import Counter
N, M = map(int, input().split())
R = []
for i in range(M):
  R += list(map(int, input().split()))
R = Counter(R)
for i in R.values():
  print(i)
# Judge status: Accepted
# input
S = input()

# check
fl = True
for i, s in enumerate(S):
    if (
            ((i + 1) % 2 == 0 and s not in ["L", "U", "D"]) or
            ((i + 1) % 2 == 1 and s not in ["R", "U", "D"])
    ):
        fl = False
        break
        
if fl is True:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
S = [c for c in input()]
while len(S):
    S.pop()
    if len(S) % 2 == 0 and S[:len(S)//2] == S[len(S)//2:]:
        print(len(S[:len(S)//2+1]))
        exit()
# Judge status: Accepted
import sys
import math
import bisect

def solve(s):
    return len(s) == len(set(list(s)))

def main():
    s = input()
    if solve(s):
        print('yes')
    else:
        print('no')

if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
if n <1000:
  print("ABC")
else:
  print("ABD")
# Judge status: Accepted
# 問題C
import numpy as np
import warnings
warnings.filterwarnings('ignore')

N = int(input())
h = np.array([list(map(int, input().split())) for _ in range(N)])

h = h.reshape(N, 3)

dp = np.array([[0] * h.shape[1]] * h.shape[0])
dp[0, :] = h[0, :]
for i in range(1, N):
    dp[i, 0] = max(dp[i-1, 1], dp[i-1, 2])+h[i, 0]
    dp[i, 1] = max(dp[i-1, 0], dp[i-1, 2])+h[i, 1]
    dp[i, 2] = max(dp[i-1, 0], dp[i-1, 1])+h[i, 2]

print(max(dp[-1, ]))
# Judge status: Accepted
import bisect
from collections import deque
N = int(input())
A = deque([])
for i in range(N):
  A.append(int(input()))

dp = deque([])
l = len(A)
for i,a in enumerate(A):
  pos = bisect.bisect_left(dp, a)-1
  if pos<0:
    dp.appendleft(a)
  else:
    dp[pos] = a

print(len(dp))
# Judge status: Accepted
def solve():
  N = int(input())
  A = [int(input()) for _ in range(N)]
  ans = A[0]//2
  A[0] = A[0]%2
  for i in range(1,N):
    ans += (A[i]+A[i-1])//2
    if (A[i]+A[i-1])//2>0:
      A[i] = (A[i]+A[i-1])%2
  return ans
print(solve())
# Judge status: Wrong Answer
N = int(input())
a = list(map(int,input().split()))
num = [0 for i in range(9)]
for i in a:
    if i >= 3200:
        num[8] += 1
    else:
        num[i//400] += 1

zero = num[:8].count(0)
print(8-zero, end = ' ')
print(8-zero + num[8])
# Judge status: Wrong Answer
S = input() #ここで標準入力
print (type(S), S)
# Judge status: Accepted
x = int(input())
ans = (x//11) * 2

y = x % 11

if 6 < y:
    ans += 2
elif 1 <= y <= 6:
    ans += 1
    
print(ans)
# Judge status: Wrong Answer
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for i in range(M):
    bc = list(map(int, input().split()))
    BC.append(bc)
BC.sort(key = lambda x : x[1])
irekae = []
count = 0
i = 0
while count < N:
    tmpb = BC[M-1-i][0]
    tmpc = BC[M-1-i][1]
    irekae += [tmpc for i in range(tmpb)]
    count += tmpb
    i += 1

ans = A + irekae
ans.sort(reverse = True)
print(sum(ans[:N]))
# Judge status: Accepted
# | Its_Rashid | #
a , b = map(int , input().split())
print(0 if a % b == 0 else 1)
# Judge status: Accepted
N,Y = input().split()
N = int(N)
Y_k=int(Y)/1000

answer = [-1,-1,-1]
for i in range(N+1):
    for j in range(N+1 - i):
        k = N-i-j
        if 10*i + 5*j + 1*k == Y_k:
            answer = [i,j,k]

print(answer[0],answer[1],answer[2])
# Judge status: Accepted
def getInput():
    return [int(i) for i in input().rstrip().split(' ')]
N, M = getInput()
A = getInput()
_4M = sum(A) / (4*M)
A.sort(reverse=True)
cnt = 0
for i in A:
    if i >= _4M:
        cnt += 1
print('Yes') if cnt >= M else print('No')
# Judge status: Accepted
N = int(input())
a = [int(i) for i in input().split()]
ans = 0
for i in range(N):
    if (i%2==0) and (a[i]%2 == 1):
        ans += 1
print(ans)
# Judge status: Wrong Answer
k=int(input())
a,b=map(int,input().split())

for i in range(a,b+1):
    if i%k==0:
        print("NG")
        break
else:
    print("OK")
# Judge status: Accepted
K = int(input())
S = input()

if len(S) >  K:
    a = S[0:K] + '...'
    print(a)
else:
    print(S[0:K])
# Judge status: Accepted
a_list = [int(x) for x in input().split()]
ans = "bust" if sum(a_list) >= 22 else "win"
print(ans)
# Judge status: Wrong Answer
import fractions

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

x = fractions.gcd(a,b)
if x == 1:
    print(1)
    exit()
ans = []

i = 2
y = int(x**0.5)
while True:
    if x%i == 0:
        x //= i
        ans.append(i)
        i = 2
        y = int(x**0.5)
    elif i >= y:
        ans.append(x)
        break
    else:
        i += 1

print(len(set(ans))+1)
# Judge status: Accepted
s = input()
if "".join(s.split("hi")) == "":
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 0
for i in range(n):
  ans += (p:=min(a[i],b[i]))
  ans += (q:=min(a[i+1],b[i]-p))
  a[i+1] -= q
print(ans)
# Judge status: Accepted
n = int(input())

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))

ans = 0
for i in range(n):
    
    ans += b_list[a_list[i]-1]
    #print(b_list[a_list[i]-1])
    if i == 0:
        continue
    else:
        if a_list[i] == a_list[i-1]+1:
            #print(a_list[i-1]-1)
            #print(c_list[a_list[i-1]-1])
            ans += c_list[a_list[i-1]-1]

print(ans)
# Judge status: Wrong Answer
k,a,b=map(int,input().split())
if b<a+2:
    print(1+k)
else:
    if k<=a:
        print(1+k)
    else:
        if (k-a-1)%2==0:
            print(b+(b-a)*(k-a-1)//2)
        else:
            print(b+(b-a)*(k-a-1)//2)
# Judge status: Accepted
from math import gcd, ceil


def lcm(a, b):
    return (a*b)//gcd(a, b)


n, m = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] = a[i]//2

lcm_v = a[0]
for i in range(1, n):
    lcm_v = lcm(lcm_v, a[i])

ok = True
for aa in a:
    if (lcm_v//aa) % 2 != 1:
        ok = False
        break
ans = 0
if ok:
    ans = ((m//lcm_v)+1)//2
print(ans)
# Judge status: Wrong Answer
n=int(input())
a,b=[],[]
for _ in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
ans,temp=0,0
for i in range(n-1):
    temp2=b[i]+b[i]*(a[i]//b[i])-a[i]
    temp+=temp2
    ans+=temp2
    a[i+1]+=temp
ans+=b[n-1]+b[n-1]*(a[n-1]//b[n-1])-a[n-1]
print(ans)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())

left = int(a * b * 4)
right = int(int(c - a - b)*int(c - a - b))

if left < right:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n = int(input())
h = [0] + list(map(int, input().split()))
dp = [10**10 for i in range(n+1)]
dp[0] = dp[1] = 0
for i in range(1, n+1):
    if i + 1 <= n:
        dp[i+1] = min(dp[i+1], dp[i]+abs(h[i] - h[i+1]))
    if i + 2 <= n:
        dp[i+2] = min(dp[i+2], dp[i]+abs(h[i] - h[i+2]))
print(dp[n])
# Judge status: Accepted
N = int(input())
a = [int(input()) for _ in range(N)]
now = 1
cnt = 0
while now != 2 and cnt <= N:
    now = a[now-1]
    cnt += 1
if cnt > N:
    print(-1)
else:
    print(cnt)
# Judge status: Accepted
#!/usr/bin/env python3
from collections import deque
N, K = map(int, input().split())
D = list(map(int, input().split()))

init = [str(i) for i in range(10) if i not in D and i != 0]
use = [str(i) for i in range(10) if i not in D]
q = deque(init)
ans = []
while q:
    num = q.pop()
    if int(num) >= N:
        ans.append(num)
        continue
    for u in use:
        q.append(num + u)

print(min(list(map(int, ans))))
# Judge status: Accepted
S=input()

ans='Yes'
for i in range(len(S)):
  if (i%2==1) and (S[i] not in {'L','U','D'}):ans='No'
  if (i%2==0) and (S[i] not in {'R','U','D'}):ans='No'
print(ans)
# Judge status: Accepted
N = int(input())
pulls = []
minus = []

for _ in range(N):
    x, y = map(int, input().split())
    pulls += [x+y]
    minus += [x-y]

pulls.sort()
minus.sort()
print(max(pulls[-1] - pulls[0], minus[-1] - minus[0]))
# Judge status: Accepted
import sys

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

num = 1

if 0 in A:
    print(0)
    sys.exit()

for i in range(N):
    num *= A[i]
    if num > (10 ** 18):
        print(-1)
        sys.exit()

print(num)
# Judge status: Wrong Answer
S = input()

s = 'A'+S[9].upper() + 'C'
print(s)
# Judge status: Accepted
n, x = map(int, input().split())
l = list(map(int, input().split()))
d = 0
e = 1
for i in l:
  d = d + i
  if d  <= x:
    e += 1
print(e)
# Judge status: Accepted
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
import bisect
def main():
    N, R = MI()
    if N >= 10:
        print(R)
    else:
        print(R + 1000 - 100 * N)

if __name__ == "__main__":
    main()
# Judge status: Accepted
k,n = map(int,input().split())
l= list(map(int,input().split()))
li = []

for i in range(n):
  if i != n-1:
    li.append(l[n-i-1]-l[n-i-2])
  else:
    li.append(k-l[n-1]+l[0])

li.sort(reverse=True)
print(k-li[0])
# Judge status: Wrong Answer
n,m=map(int,input().split())
if 2*n>m:
    print(n//2)
else:
    print(n+(m-2*n)//4)
# Judge status: Accepted
# -*- coding: utf-8 -*-
import math
n = int(input())
a = list(map(int, input().split()))
a.sort()
q = 1
f = 0
for i in a:
    q *= i
    if q > 10**18:
        f = 1
        break
if f == 1:
    print(-1)
else:
    print(q)
# Judge status: Accepted
import numpy as np

H,N = list(map(int, input().split()))
As = []
Bs = []
for _ in range(N):
    a, b = list(map(int, input().split()))
    As.append(a)
    Bs.append(b)
As = np.array(As)
Bs = np.array(Bs)

dp = np.full((H+1), np.inf)
dp[0] = 0

for c in range(1,H+1):
    dp[c] = np.amin(dp[np.maximum(c - As, 0)] + Bs)

print(int(dp[-1]))
# Judge status: Wrong Answer
N, K, Q = map(int, input().split())
A = ""
for i in range(Q):
  A += input()

res = []
for i in range(1, N + 1):
  if K - Q + A.count(str(i)) > 0:
    res.append("Yes")
  else:
    res.append("No")

for r in res:
  print(r)
# Judge status: Accepted
n, c, k = map(int, input().split())
T = sorted(int(input()) for _ in range(n))

counter = 1
start = -1
wating_num = 0
for t in T:
  if start < 0:
    start = t
  if t - start > k or wating_num + 1 > c:
    counter += 1
    wating_num = 0
    start = t
  wating_num += 1
print(counter)
# Judge status: Accepted
def main():
  n = int(input())
  wlist = list(map(int, input().split()))
  min_diff = float('inf')
  for i in range(1, n):
    s1 = sum(wlist[:i])
    s2 = sum(wlist[i:])
    diff = abs(s1-s2)
    if min_diff > diff:
      min_diff = diff
  print(min_diff)
main()
# Judge status: Accepted
x=[int(_) for _ in input().split(" ")]

for i in range(5):
  if x[i] == 0:
    ans = i+1
    
print(ans)
# Judge status: Accepted
N = int(input())
A = N*(N+1)//2-N
print(A)
# Judge status: Accepted

if __name__ == '__main__':
    N = int(input())
    for i in range(1, N+1):
        sumn = i *(i+1)//2
        if(N <= sumn):
            for j in range(1, i+1):
                if j == sumn-N:
                    continue
                print(j)
            exit()
# Judge status: Wrong Answer
n = input()
for i in range(len(n)):
    if n[-i-1] != "9":
        if i == -len(n): print(int(n[0])+9*(len(n)-1))
        else: print(int(n[i])-1+9*(len(n)-1))
        break
else: print(9*len(n))
# Judge status: Accepted
N,K=map(int, input().split())
A=list(map(int, input().split()))

def f(A):
  D=[0]*(N+1)
  for j in range(N):
    mi=max(j-A[j],0)
    ma=min(j+A[j],N-1)
    D[mi]+=1
    D[ma+1]-=1   
  for i in range(1,N):
    D[i]+=D[i-1]
  A=D[:-1]
  return A 

for i in range(min(K,42)):
  A=f(A)
print(*A)
# Judge status: Accepted
n = int(input())
 
a = n//500
b = (n - a * 500) //5
ans = a * 1000 + b * 5
print(ans)
# Judge status: Wrong Answer
x,y,z = map(int,input().split())

ans = int(x/(y+z))
if x%(y+z)-z >= 0:
    ans -= 1
print(ans)
# Judge status: Wrong Answer
s = input().rstrip()

if ('N' in s and 'S' in s) or ('W' in s and 'E' in s):
    if ('N' in s and 'S' in s) or ('W' in s and 'E' in s):
        print('Yes')
        exit()

print('No')
# Judge status: Accepted
import math
a,b,x = map(int,input().split())
if x>=(a**2)*b/2:
  y = 2*b-2*x/(a**2)
  print(math.degrees(math.atan2(y,a)))
else:
  y = 2*x/(a*b)
  print(90-math.degrees(math.atan2(y,b)))
# Judge status: Accepted
import math

a, b, c, d = [float(n) for n in input().split()]

if math.ceil(a/d) >= math.ceil(c/b):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a, b = map(int, input().split())
if a <= 5:
    print(0)
elif a <= 12:
    print(b//2)
else:
    print(b)
# Judge status: Wrong Answer
import numpy as np
N,L  = map(int,input().split())
L_list=np.array(range(1,N+1))+L-1
if (0 in L_list):
    print(sum(L_list))
    exit()
if(N<abs(L)):
    print(sum(L_list)-L_list[N-1])
    exit()
else:
    print(sum(L_list)-L_list[0])
    exit()
# Judge status: Accepted
N, M, X, Y = map(int, input().split())
x = list(map(int, input().split())) + [X]
y = list(map(int, input().split())) + [Y]

if X < Y and max(x) < min(y):
    print("No War")
else:
    print("War")
# Judge status: Accepted
n = int(input())
a = [int(x) for x in input().split()]

cnt = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
        a[i] *= -1

a.sort()

if cnt % 2 != 0:
    a[0] *= -1

print(sum(a))
# Judge status: Wrong Answer
S = 'sardine'

x = 'x' * len(S)

output = x
print(output)
# Judge status: Accepted
from math import *
n,d=map(int,input().split())
c=0
for i in range(n):
    x,y=map(int,input().split())
    s=sqrt(x**2+y**2)
    if(s<=d):
        c=c+1
print(c)
# Judge status: Accepted
N, K = map(int, input().split())
P = list(map(int, input().split()))
P.sort()
ans = sum(P[:K])
print(ans)
# Judge status: Accepted
from heapq import heappush, heappop

N, M = map(int, input().split())
AtoB = [[] for _ in range(M+1)]
for i in range(N):
    A, B = map(int, input().split())
    if A > M:
        continue
    AtoB[A].append(B)

# A が小さい順に増えていく
result = 0
que = [] # ヒープ
for Bs in AtoB:
    for B in Bs:
        heappush(que, -B) # Python3 のヒープはデフォルトで小さい順
    if que:
        result -= heappop(que)
print(result)
# Judge status: Accepted
N ,K = map(int,input().split())
if N%K == 0:
  print(0)
else:
  print(1)
# Judge status: Accepted
days = ["SUN","MON","TUE","WED","THU","FRI","SAT"]
day = input()
# このdayが何番目かを出して7からひく
print(7 - days.index(day))
# Judge status: Wrong Answer
n = int(input())
As = list(map(int,input().split()))
sum = 0
step =0

try:
    for i in range(len(As)):
        if As[i] < As[i + 1]:
            step = As[i + 1] - As[i]
            As[i] += step
            sum += step 
except IndexError:
    pass

print(sum)
# Judge status: Wrong Answer
n=list(input())
t=n[0]
cnt=0
for i in range(1,len(n)-1):
    if t==n[i]:
        cnt+=1
if cnt>=3:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N,K = map(int,input().split())


sum = 0
for k in range(K,N+2):
    # sum(arr[0:0+k]), sum([l-,l])
    s1 = ((0 + k-1) * k) // 2
    s2 = (((N - k + 1) + N) * k) // 2
    sum = sum + (s2 - s1 + 1)

print(sum % (1000000000 + 7))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split(" ")))

list = []
sim=0
for i in range(N-1):
  if A[i]<A[i+1]:
    list.append(1)
  if A[i]>A[i+1]:
    list.append(0)
  if A[i]==A[i+1]:
    sim+=1

print(list)

i = 0
count = 0

while i<N-2-sim:
  if list[i] != list[i+1]:
    count += 1
    i+=1
  i+=1

print(count + 1)
# Judge status: Accepted
S = input()
test = ""
tmp = 0
for i in range(1, len(S)):
    j = -1 * i
    test = S[:j]
    tmp = len(test) // 2
    if len(test) % 2 == 0 and test[0:tmp] == test[tmp:]:
        print(len(test))
        exit()
# Judge status: Wrong Answer
N = int(input())
ans = 1000000
for i in range(1, N+1):
    A = i
    B = N - i
    Asum = sum(map(int, str(A)))
    Bsum = sum(map(int, str(B)))
    if ans > (Asum + Bsum):
        ans = Asum + Bsum
print(ans)
# Judge status: Wrong Answer
N = int(input())

dp = [[0]*3 for _ in range(N+1)]

for i in range(1, N):
  a, b, c = map(int, input().split())
  dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a
  dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b
  dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c

print(max(dp[N][0], dp[N][1], dp[N][2]))
# Judge status: Wrong Answer
from bisect import bisect_left
from itertools import accumulate

N, M = map(int, input().split())
shop = [list(map(int, input().split())) for _ in range(N)]
shop.sort(key=lambda x: x[0])

money_sum = (list(accumulate([i[0] * i[1] for i in shop])))
drink_sum = (list(accumulate([i[1] for i in shop])))

drink = 0
money = 0

idx = bisect_left(drink_sum, M)

drink = drink_sum[idx - 1]
money = money_sum[idx - 1]

for _ in range(shop[idx][1]):
    if drink == M:
        break
    else:
        drink += 1
        money += shop[idx][0]

print(money)
# Judge status: Wrong Answer
def main():
    a, b = map(int, input().split())

    print(min(a, b))


if __name__ == "__main__":
    main()
# Judge status: Accepted
n,k=map(int,input().split())
a=list(map(int,input().split()))

for i in range(n-k):
    if a[k+i]>a[i]:
        print("Yes")
    else:
        print("No")
# Judge status: Wrong Answer
N=int(input())
A=list(map(int, input().split()))
MOD=7+10**9
ans=0
for i in range(len(A)-1):
    for j in range(i+1,len(A)):
        print(A[i],A[j])
        ai= A[i] % MOD
        aj=A[j] % MOD
        ans = ans +ai*aj % MOD
print(ans%MOD)
# Judge status: Accepted
s = input()
while True:
    s = s[:-1]
    if s[0:len(s)//2] == s[len(s)//2:]:
        print(len(s))
        exit()
# Judge status: Accepted
N,M=map(int,input().split())
A=[0]*N;p=0;q=M
for i in range(N):
  a,b=map(int,input().split())
  A[i]=[b,a]

A.sort(key=lambda x: x[1])
#print(A)
i=0
while q>0:
  if q>=A[i][0]:
    p=p+A[i][0]*A[i][1]
    q=q-A[i][0]
    i=i+1
  else:
    p=p+q*A[i][1]
    q=q-q
    break
print(p)
# Judge status: Wrong Answer
s,t = input().split()
print(t, end=" ")
print(s)
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
ans = [0] * N
index = []
M = 0
for i in range(N-1,-1,-1):
    if sum(A[i:N:i+1]) % 2 == 0:
        ans[i] = 0
    else:
        ans[i] = 1
        index.append(i+1)
        M += 1
print(M,*index,sep='\n')
# Judge status: Accepted
n, m = map(int, input().split())
ac = {}
wa = {}
for _ in range(m):
    p, s = input().split()
    p = int(p)
    if s == 'AC':
        ac[p] = 1
    else:
        if not ac.get(p, 0):
            wa[p] = wa.get(p, 0) + 1
pen = 0
for p in ac:
    pen += wa.get(p, 0)
print(len(ac), pen)
# Judge status: Accepted
# abc120_b.py
import fractions 
from functools import reduce
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

A, B, K = map(int,input().split())
cnt = 0
_max = gcd(A,B)
while _max>=0:
    if A%_max==0 and B%_max==0:
        cnt += 1
        if cnt == K:
            print(_max)
            exit()
    _max -=1
# Judge status: Accepted
A, B, C = map(int, input().split())
print(['NO', 'YES'][B - A == C - B])
# Judge status: Accepted
def main():
    N = int(input())
    total = [i for i in range(1, N+1)]
    print(sum(total))


if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
string = input()
flag = True
 
num = len(string)
if num % 2 == 0:
  for i in range(num //  2 - 1):
    if string[2*i:2*(i+1)] != "hi":
      flag = False
      break
else:
  flag = False
 
if flag:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
def main():
    n = int(input())

    if n <= 999:
        print('ABC')
    else:
        print('ABD')


if __name__ == '__main__':
    main()
# Judge status: Accepted
s = input()
x = s[:3] + "8" + s[4:]
print(x)
# Judge status: Accepted
_string = input()

if _string == "AAA" or _string == "BBB":
    print("No")
else:
    print("Yes")
# Judge status: Accepted
s = input()
prev = s[0]
n = len(s)
cnt= 0
L = [0]*(n+1)
R = [0]*(n+1)
for i in range(n):
    if s[i] =="<":
        cnt+=1
    else:
        cnt=0
    L[i+1] = cnt
s= s[::-1]
for i in range(n):
    if s[i] ==">":
        cnt+=1
    else:
        cnt=0
    R[i+1] = cnt
ans = 0
for i in range(n+1):
    ans+=max(L[i],R[-i-1])
print(ans)
# Judge status: Wrong Answer
a1,a2,a3=map(int,input().split())
print('win' if a1+a2+a3<22 else 'Burst')
# Judge status: Wrong Answer
n = int(input())

x = (10**9 + 7)

for i in range(1,n+1):
  n = n * i
  
  
if n < x:
  print(n)
  
elif n >=x :
  print(n % x)
# Judge status: Accepted
a,b,c=map(int,input().split())
cnt=3

if a==b:
    cnt-=1

if b==c:
    cnt-=1

if c==a:
    cnt-=1

if a==b==c:
    cnt+=1

print(cnt)
# Judge status: Wrong Answer
s=input()
key="keyence"
li=[]
for i in range(len(key)):
  li.append([key[:i],key[i:]])
  
for i in li:
  if i[0] in s and i[1] in s:
    print("YES")
    break
else:
  print("NO")
# Judge status: Accepted
import sys
N = int(input())
W = []
for i in range(N):
    W.append(input())
if len(set(W)) != len(W):
    print("No")
else:
    for i in range(len(W)-1):
        if W[i][-1] != W[i+1][0]:
            print("No")
            sys.exit()
    print("Yes")
# Judge status: Accepted
c1 = list(input())
c2 = list(input())
c1.reverse()
if c1 == c2:
  print("YES")
else:
  print("NO")
# Judge status: Accepted
N,K=map(int,input().split())
p=list(map(int,input().split()))
p.sort()
print(sum(p[:K]))
# Judge status: Accepted
from collections import deque
X = input()

scan = deque()

for c in X:
    # print(scan)
    if c == 'S':
        scan.append(c)
    else:
        if not scan or scan[-1] == 'T':
            scan.append('T')
        else:
            scan.pop()
print(len(scan))
# Judge status: Accepted
n = int(input())
A = list(map(int, input().split()))
mydict = {}
total = 0
for a in A:
    mydict[a] = mydict[a] + 1 if a in mydict else 1
    total += a

q = int(input())
for i in range(0, q):
    b, c = map(int, input().split())
    if b in mydict:
        if not c in mydict:
            mydict[c] = 0
        total += (c - b) * mydict[b]
        mydict[c] += mydict[b]
        mydict[b] = 0
    print(total)
# Judge status: Accepted
n=int(input())

a=[int(x) for x in input().split()]

i=0
ans=0
saigo=0
k=1
kosuu=n

while i<=n-1:
    if a[i]!=k:
        ans+=1
        kosuu-=1
    else:
        saigo=a[i]
        k+=1
    i+=1

if kosuu==0:
    print(-1)
    exit()

if kosuu==saigo:
    print(ans)
else:
    print(-1)
# Judge status: Accepted
from fractions import gcd
a = 1
n = int(input())
for i in range (n):
    h = int(input())
    a = a*h // gcd(a,h)
print(a)