peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
N,M,Q = map(int,input().split())
abcd = [list(map(int,input().split())) for i in range(Q)]
 
import itertools
 
A = list(itertools.combinations_with_replacement(range(1,M+1),N))
answer = 0
 
for i in range(len(A)):
    ans = 0
    for j in range(Q):
        if A[i][ abcd[j][1]-1 ] - A[i][ abcd[j][0]-1 ] == abcd[j][2]:
            ans += abcd[j][3]  
    answer = max(answer,ans)
    
print(answer)
# Judge status: Wrong Answer



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


if a*2<=b<=a*4:
	print('Yes')
else:
	print('No')
# Judge status: Accepted
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
d = abs(a-b)

if d <= t*(v - w):
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
import math
A,B,H,M = list(map(int,input().split()))
Q = 30*H - 6*M
L = (A**2 + B**2 - 2*A*B*math.cos(math.radians(Q)))**(1/2)
print(L)
# Judge status: Wrong Answer
A,B,K = [int(i) for i in input().split()]

if K >= A:
    A = 0
    K = K-A
else:
    A = A-K
if K >= B:
    B = 0
else:
    B = B-K
    
print(A,B)
# Judge status: Wrong Answer
from collections import deque

X = input()
stack = deque([X[0]])
before = X[0]
for i in range(1, len(X)):
    if X[i] == 'S':
        stack.appendleft(X[i])

    if X[i] == 'T':
        if stack:
            check = stack.popleft()
        if check == 'T':
            stack.appendleft(check)
            stack.appendleft(X[i])

print(len(stack))
# Judge status: Accepted
A, B = map(int, input().split())

if A >= 13:
    print(B)
elif A >= 6:
    print(B//2)
else:
    print(0)
# Judge status: Accepted
N = int(input())

c = []
for i in range(10):
    c.append([0] * 10)

for i in range(N):
    s = str(i+1)
    i1 = int(s[0])
    i2 = int(s[-1])
    c[i1][i2] += 1
    
total = 0
for i in range(10):
    for j in range(10):
        total += c[i][j] * c[j][i]
        
print(total)
# Judge status: Wrong Answer
w,h,x,y=map(int,input().split())
a=min(x*h,h*w-x*h)
b=min(y*w,h*w-y*w)

if 2*h==y and 2*w==x:
    print(max(a,b),1)
else:
    print(max(a,b),0)
# Judge status: Wrong Answer
def main():
    import numpy as np
    a, b, x = map(int, input().split())
    if b < a:
        theta = np.arctan(2 * (b / a - x / a ** 3)) / np.pi * 180
        print(theta)
    else:
        theta = np.arctan(a * b ** 2 / 2 / x) / np.pi * 180
        print(theta)


if __name__ == '__main__':
    main()
# Judge status: Accepted
# ABC108A

k = int(input())
odd = k // 2
if k % 2 == 1:
    odd += 1
print(odd * (k-odd))
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))

A.sort()

m=A[-1]
B=[0 for i in range(0,N-1)]
for i in range(0,N-1):
    B[i]=min(A[i],m-A[i])

r=max(B)
if r in A:
    print(m,r)
else:
    print(m,m-r)
# Judge status: Accepted
a = list(input())
b = list(input())

if a[:] == b[::-1]:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
# -*- coding: utf-8 -*-
# A

import sys
from collections import defaultdict, deque
from heapq import heappush, heappop
import math
import bisect
input = sys.stdin.readline

# 再起回数上限変更
# sys.setrecursionlimit(1000000)

n, x, t = map(int, input().split())

print(math.ceil(n / x)*t)
# Judge status: Accepted
N=int(input())
L=list(map(int,input().split()))
L=sorted(L)
K=0
for i in range(N):
	K+=L[i*2+N]
print(K)
# Judge status: Accepted
s = list(input())
ans = 'NO'
for i in range(len(s)):
    if ''.join(s[:i] + s[len(s)-7+i:]) == 'keyence':
        ans = 'YES'
        break
print(ans)
# Judge status: Accepted
a,b = map(int,input().split())
if a*b % 2 == 0:
  print('Even')
else:
  print('Odd')
# Judge status: Wrong Answer
# Beginner 50 C
import copy

N, x = map(int, input().split())
A = list(map(int, input().split()))
B = copy.deepcopy(A)

for i in range(N-1):
    if A[i] + A[i+1] > x:
        if A[i] > A[i+1]:
            A[i] = x - A[i+1]
        else:
            A[i+1] = x - A[i]

cnt = sum(B) - sum(A)
print(cnt)
# Judge status: Wrong Answer
n = int(input())
l = []
for _ in range(n):
    d1,d2 = map(int,input().split())
    l.append(d1)
    l.append(d2)

for i in range(len(l)-2):
    if l[i] == l[i+1] == l[i+2] == 3:
        print ('Yes')
        exit ()
print ('No')
# Judge status: Accepted
n,k=map(int,input().split())
h=[int(input()) for _ in range(n)]
h.sort()
INF=2*10**9
ans=INF
for i in range(n-k+1):
	diff=h[i+k-1]-h[i]
	if ans>diff:
		ans=diff
		if ans==0:
			print(0)
			exit()
print(ans)
# Judge status: Wrong Answer
import math
from functools import reduce
from itertools import product
K=int(input())
gcd=0.
K=range(K)
for i,j,k in product(K,K,K):
            gcd+=reduce(math.gcd,(i+1,j+1,k+1))
print(gcd)
# Judge status: Accepted
import bisect
from collections import deque
N=int(input())
a=deque([int(input())])
for _ in range(N-1):
  num=int(input())
  if num<=a[0]:
    a.appendleft(num)
  else:
    a[bisect.bisect_left(a, num)-1]=num
print(len(a))
# Judge status: Accepted
def main():
    MOD = 10**9 + 7
    n, k = map(int, input().split())
    ans = 0
    for x in range(k, n+2):
        ans +=  (n+2)*(n+1)//2 - (n-x+2)*(n-x+1)//2 - (x+1)*x//2 + 1
        ans %= MOD
    print(ans)

if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
N = int(input())
Q = [list(map(int, input().split())) for _ in range(N)]
dp = [[0]*3 for i in range(N)]
dp[0][0] = Q[0][0]
dp[0][1] = Q[0][1]
dp[0][2] = Q[0][2]

print(dp)
for i in range(1, N):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + Q[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + Q[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + Q[i][2]
print(max(dp[-1]))
# Judge status: Wrong Answer
α=input()
if α=='A' or 'B' or 'C' or 'D' or 'E' or 'F' or 'G' or 'H' or 'I' or 'J' or 'K' or 'L' or 'M' or 'N' or 'O' or'P' or 'Q' or 'R' or 'S' or 'T' or 'U' or 'V' or 'W' or 'X' or 'Y' or 'Z':
  print('A')
elif α=='a' or 'b' or 'c' or 'd' or 'e' or 'f' or 'g' or 'h' or 'i' or 'j' or 'k' or 'l' or 'm' or 'n' or 'o' or'p' or 'q' or 'r' or 's' or 't' or 'u' or 'v' or 'w' or 'x' or 'y' or 'z':
  print('a')
# Judge status: Accepted
a,b,c = map(int, input().split())
k =int(input())

cnt = 0
while b<=a:
    cnt += 1
    b *= 2
while c <= b:
    cnt += 1
    c *= 2
    
if cnt <= k:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
N = int(input())
*h, = map(int, input().split())
dp = [float("inf") for _ in range(N)]
dp[0] = 0
for i in range(N - 1):
	dp[i + 1] = dp[i] + abs(h[i + 1] - h[i])
	if i < N - 2:
		dp[i + 2] =dp[i + 2], dp[i] + abs(h[i + 2] - h[i])
print(dp[N - 1])
# Judge status: Wrong Answer
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

if A <= B:
    print("YES" if A + V * T >= B + W * T else "NO")
else:
    print("YES" if A - V * T >= B - W * T else "NO")
# Judge status: Accepted
from collections import defaultdict
d = defaultdict(int)

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

for i in range(1, 1000+1):
  t = 0
  for s in range(1, i+1):
    t += s * (1 / i)

  d[i] = t

ans = 0
t = 0

for index, i in enumerate(li):
  t += d[i]

  if index > K-1:
    t -= d[li[index-K]]

  if ans < t:
    ans = t

print(ans)
# Judge status: Wrong Answer
n,k=map(int,input().split())
l=list(map(int,input().split()))
sorted(l)
sum=0
for i in range(k):
  sum+=l[i]
print(sum)
# Judge status: Wrong Answer
n, d = map(int, input().split())

print((n + d * 2) / (d * 2 + 1))
# Judge status: Accepted
n=int(input())
ac=0
wa=0
tle=0
re=0

for i in range(n):
    x=input()
    if x == 'AC':
        ac+=1
    elif x == 'WA':
        wa+=1
    elif x == 'TLE':
        tle+=1
    elif x == 'RE':
        re+=1

print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))
# Judge status: Accepted
N = int(input())
h = list(map(int, input().split())) #1-index

dp = [float('inf')]*(N)

def chmin(a,b):
    if a >= b:
        return b
    else:
        return a

dp[0] = 0
for i in range(1,N):
    dp[i] = chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    
    if i >= 2:
        dp[i] = chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]))
    
print(dp[N-1])
# Judge status: Accepted
a, b = map(int, input().split())
s = input()
cnt = 0
y = ['0','1','2','3','4','5','6','7','8','9']

for i in range(a+b+1):
    if i == a:
        if s[a] == '-':
            cnt +=1
    else:
        if s[i] in y:
            cnt += 1
        
if cnt == (a+b+1):
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
k,x=map(int,input().split())
if 500*k>x:
  print("Yes")
if 500*x<x:
  print("No")
# Judge status: Accepted
n=int(input())
a=[]
for i in range(n):
  a.append(list(input().split()))
for i in range(0,n):
  a[i].append(i+1)
for i in range(0,len(a)):
  a[i][1]=int(a[i][1])
a.sort(key=lambda x:(x[0],-x[1]),reverse = False)
for i in range(0,n):
  print(a[i][2])
# Judge status: Wrong Answer
import sys

input = sys.stdin.readline
N = int(input())
S = list(input().strip())
S = S[::-1]

ans = 0
for i in range(N-2):
    if S[i] == ".":
        if S[i+1] == "." and S[i+2] == "#":
            S[i+2] = "."
            ans += 1
        if S[i+1] == "#":
            ans += 1
    elif S[i] == "#" and S[i+1] == "." and S[i+2] == "#":
        ans += 1
print(ans)
# Judge status: Wrong Answer
N=int(input())
K=int(input())
X=int(input())
Y=int(input())

print(X*K+(N-K)*Y)
# Judge status: Accepted
A, B, M = map(int, input().split())

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

m = [0] * M
x = [0] * M
y = [0] * M
for i in range (M):
    x[i], y[i], m[i] = map(int, input().split())
    

discount = [0] * M
for i in range(M):
    discount[i] = a[x[i]-1] + b[y[i]-1] - m[i]
    
    
discount_ab = min(a) + min (b)
if discount_ab > min(discount):
    print(min(discount))
else:
    print(discount_ab)
# Judge status: Wrong Answer
from math import sqrt

N = int(input())

prime = 2
total_count = 0

def different_nums(count, num=1):
  if count - num == 0:
    return 1
  elif count - num > 0:
    return 1 + different_nums(count - num, num + 1)
  else:
    return 0
  


while N != 1:
  count = 0
  rooted_N = sqrt(N)
  
  if prime > rooted_N:
    total_count = 1
    break
  while N % prime == 0:
    N = N // prime
    count += 1
  total_count += different_nums(count)
  if prime == 2:
    prime = 3
  else:
    prime += 2

  
print(total_count)
# Judge status: Wrong Answer
a =  int(input())
b =  int(input())
c =  int(input())
print((a+b) * c / 2)
# Judge status: Accepted
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [i-1 for i in a]
visited = [-1]*n
route = []
now = 0
hop = 0
while visited[now] == -1:
    visited[now]=hop
    route.append(now)
    now = a[now]
    hop+=1
loop_st = 0
for r in route:
    if r==now: break
    loop_st+=1
loop = route[loop_st:]
if k < len(route):
    print(route[k]+1)
else:
    print(loop[(k-loop_st)%len(loop)]+1)
# Judge status: Accepted
s, t = map(str, input().split())
a, b = map(int, input().split())
u = input()
if u == s:
  a -= 1
else:
  b -= 1
print(' '.join((str(a), str(b))))
# Judge status: Accepted
import fractions

N = int(input())

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

A = sorted(A)

a = A.pop(0)
for i in A:
    a = fractions.gcd(a, i)
    
print(a)
# Judge status: Wrong Answer
N,M = map(int,input().split())
S = [0]*M
C = [0]*M
for i in range(M):
    S[i],C[i] = map(int,input().split())
answer = -1

for i in range(10**(N-1),10**N):
    numstr = str(i)
    count = 0
    for j in range(M):
        if int(numstr[S[j]-1]) != C[j]:
            break
        else:
            count += 1
    if count == N:
        answer = i
        break
    else:
        answer = -1
        
print(answer)
# Judge status: Accepted
a=int(input())
b=input()
if a>=3200:
    print(b)
else:
    print('red')
# Judge status: Accepted
S = input()
S = S.replace("/","")
int_S = int(S)
print("Heisei" if int_S <= 20190430 else "TBD")
# Judge status: Accepted
s=input()

if 12<int(s[:2]) or 0==int(s[:2]):
    if 12>=int(s[2:])>=1:
        print("YYMM")
    else:
        print("NA")
elif 1<=int(s[:2])<=12:
    if 12>=int(s[2:])>=1:
        print("AMBIGUOUS")
    else:
        print("MMYY")
# Judge status: Wrong Answer
def main():
	a = int(input())
	b= int(input())
	h = int(input())
	t = abs(a-b)
	ar = a*h + ((t*h)//2)
	print(ar)
if __name__=="__main__":
	main()
# Judge status: Accepted
s = input()
if s[-1] != 's':
    print(s+'s')
else:
    print(s+'es')
# Judge status: Wrong Answer
w = input()
beau = {}
for i in range(len(w)):
    if not w[i] in beau:
        beau[w[i]] = 1
    else:
        beau[w[i]] += 1
num = sum(map(lambda x: x%2,list(beau.values())))
if num == 0:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
import collections
n=int(input())
s=list(input())
s=collections.Counter(s)
ans=1
for i in s:
  ans*=s[i]+1
  ans%=10**9+7
print(ans-1)
# Judge status: Accepted
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import string

s = set(input().strip())
alpha = set(string.ascii_lowercase)
s = sorted(list(alpha - s))
if s:
    print(s[0])
else:
    print('None')
# Judge status: Wrong Answer
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
import math
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
from collections import deque
inf = 10 ** 15
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
suma = sum(a)
sumb = sum(b)
count = sumb-suma
subsum = 0
if count < 0:
    print('No')
    sys.exit()
for i in range(n):
    subsum += abs(a[i]-b[i])
if subsum <= 3*count:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
S = input()
print("Yes" if len(S) == 3 else "No")
# Judge status: Accepted
x = int(input())

if 400 <= x <= 599:
    print(8)

if 600 <= x <= 799:
    print(7)

if 800 <= x <= 999:
    print(6)

if 1000 <= x <= 1199:
    print(5)

if 1200 <= x <= 1399:
    print(4)

if 1400 <= x <= 1599:
    print(3)

if 1600 <= x <= 1799:
    print(2)

if 1800 <= x <= 1999:
    print(1)
# Judge status: Accepted
mod = 1000000007
N, K = map(int, input().split())

S = [0]
for i in range(N):
	S.append(S[i]+i+1)

r = 1

for i in range(K, N+1):
	up = S[N]-S[N-i]
	low = S[i-1]
	r = (r+(up-low+1))%mod

print(r)
# Judge status: Accepted
x,y=map(int,input().split())
a=1
k=pow(y,0.5)
for i in range(1,int(k)+1):
    if y%i==0:
        if i*x<=y:
            a=max(a,i)
        if (y//i)*x<=y:
            a=max(a,y//i)
print(a)
# Judge status: Accepted
A, B, C = map(int, input().split())
N = int(input())

print(max(A, B, C) * (2 ** N - 1) + A + B + C)
# Judge status: Accepted
S=input()
sk="keyence"
N=len(S)
Nsk=len(sk)

k=0
ans="NO"
if N>=Nsk:
    for i in range(Nsk):
        temp=S[0:i]+S[N-Nsk+i:]
        if temp==sk:
            ans="YES"
    
print(ans)
# Judge status: Wrong Answer
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

cnt = 0
for a, b in zip(A, B):
    if a > b:
        cnt += (a-b)*2
    else:
        cnt -= (b-a)

print("No" if cnt>0 else "Yes")
# Judge status: Accepted
S = input()
N = len(S)

count1 = 0
count2 = 0
for i in range(N):
    ex = str(i % 2)
    if S[i] == ex:
        count1 += 1
    else:
        count2 += 1
print(min(count1, count2))
# Judge status: Wrong Answer
N = int(input())
a = set([int(c) for c in input().split()])
a = sorted(list(a))
X = a[-1]//2+1
m = 10**9
x = 0
for i in range(N-1):
  if abs(a[i]-X)<m:
    m = abs(a[i]-X)
    x = i
print(a[-1],a[x])
# Judge status: Wrong Answer
k = int(input())
t = (k/2)**2

if k % 2 == 0:
    print(t)
else:
    print(round(t))
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n):
    if i%2==0:
        if a[i]%2==1:
            ans += 1
print(ans)
# Judge status: Accepted
X = int(input())

x = X % 100
tmp = (x // 5) * 105
if x % 5 != 0:
    tmp += 100 + (x % 5)
if tmp > X:
    print(0)
else:
    print(1)
# Judge status: Accepted
w=input()
for i in range(0,len(w)):
  if w.count(w[i])%2==1:
    print("No")
    exit()
print("Yes")
# Judge status: Accepted
W,H,N = map(int,input().split())
XYA = [tuple(map(int,input().split())) for _ in range(N)]

xmin = 0
ymin = 0
xmax = W
ymax = H
for x,y,a in XYA:
  if a == 1:
    xmin = max(x,xmin)
  elif a == 2:
    xmax = min(x,xmax)
  elif a == 3:
    ymin = max(y,ymin)
  else:
    ymax = min(y,ymax)
#print(xmax,xmin,ymax,ymin)
print(max(xmax-xmin,0)*max(ymax-ymin,0))
# Judge status: Wrong Answer
N = int(input())
A = list(map(int,input().split()))
a = 0
S = 0
num = 1
for i in range(1,N):
    if A[i] - A[i - 1] == 0:
        a = 0
    elif A[i] - A[i - 1] > 0:
        a = 1
    else:
        a = 2
    if S == 0:
        S = a
    elif S != a:
        num += 1
        S = 0
print(num)
# Judge status: Accepted
n = int(input())
A = [0]*10**7

for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            A[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1

print(*A[1:n+1],sep='\n')
# Judge status: Wrong Answer
import math

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

bottle = a * b
water = x / a

if water <= bottle / 2:
  a2 = 2 * water / b
  ans = math.degrees(math.atan(b / a2))
  
else:
  b2 = 2 * water / a - b
  water2 = water - (b2 * a)
  b3 = water2 / a
  ans = math.degrees(math.atan(b3 / a))
  
print(ans)
# Judge status: Accepted
def main():
    n=int(input())
    s=[]
    for i in range(n):
        si=list(input())
        si.sort()
        s.append(si)
    s.sort()
    s.append("X")
    cnt=1
    ans=0
    for i in range(n):
        if s[i]==s[i+1]:
            cnt+=1
        else:
            ans+=cnt*(cnt-1)//2
            cnt=1
    print(ans)
if __name__=="__main__":
    main()
# Judge status: Wrong Answer
N,K=map(int,input().split())
M=N+1;L=K-1
print((M**3+5*M+2*L**3+3*(1-M)*L**2-(5+3*M)*L)/6%1000000007)
# Judge status: Wrong Answer
from collections import Counter
def main():
    a=int(input())
    tmp=0
    x = [input() for _ in range(a)]
    x.sort()
    count=Counter(x)
    for i in count.most_common():
        if tmp <= i[1]:
            print(i[0])
            tmp=i[1]
        else:
            break

main()
# Judge status: Wrong Answer
import sys,queue,math,copy
from functools import reduce
from fractions import gcd
input = sys.stdin.readline
LI = lambda : [int(x) for x in input().split()]
LI_2 = lambda : [int(x) / 2 for x in input().split()]

lcm = lambda a : reduce(lambda x, y : x * y // gcd(x,y), a)
N,M = LI()
A = LI_2()
c = lcm(A)
for i in A:
    if (c // i) % 2 == 0:
        print (0)
        exit (0)
print (math.ceil((M//c) / 2))
# Judge status: Accepted
n,p=map(int,input().split())
a=list(map(lambda x:int(x)%2,input().split()))
d=[0]*n
if p==1:
    if a[0]==1:
        d[0]=1
    else:
        d[0]=0
else:
    if a[0]==1:
        d[0]=1
    else:
        d[0]=2
for i in range(1,n):
    if a[i]==0:
        d[i]=d[i-1]+d[i-1]
    else:
        d[i]=d[i-1]+(2**i-d[i-1])
print(d[n-1])
# Judge status: Accepted
a,b,c,k = map(int,input().split())
ans = a - b
if k % 2 == 0:
    print(ans)
else:
    print(-ans)
# Judge status: Accepted
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B = map(int, readline().split())

    vec = [A, B, A-1, B-1]
    vec.sort(reverse=True)

    print(sum(vec[:2]))

    return


if __name__ == '__main__':
    main()
# Judge status: Accepted
N,K=map(int,input().split())
H=list(map(int,input().split()))
newlist=sorted(H,reverse=True)
del newlist[0:K]
print(sum(newlist))
# Judge status: Accepted
a,b,c = map(int,input().split())
if a < c < b or b < c < a:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N = int(input())
C = list(input())
cnt_r = 0
for c in C:
    if c == "R":
        cnt_r += 1
for i in range(cnt_r):
    if C[i] == "R":
        cnt_r -= 1
print(cnt_r)
# Judge status: Wrong Answer
# -*- coding: utf-8 -*-

n=int(input())
c = 0
if n > 100:
    c = int((n * n/100.0) + 8)
else:
    for i in range(1,n+1):
        for j in range(1,n+1):
            if int(str(i)[0]) == int(str(j)[-1]) and int(str(i)[-1]) == int(str(j)[0]):
                c+=1
print(c)
# Judge status: Accepted
N, K = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

A.sort(key=lambda x: x[0])

cnt = 0

for ab in A:
    a = ab[0]
    b = ab[1]

    cnt += b
    if cnt >= K:
        print(a)
        exit()
# Judge status: Accepted
import itertools
import math
import fractions
import functools
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()
subs = []
for i in range(1,n):
    subs.append(h[i]-h[i-1])

amount = [0]*(n)
sums = 0
for i in range(0,len(subs)):
    sums += subs[i]
    amount[i+1] = sums


minimum = 10**10
for i in range(k-1,n):
    minimum = min(minimum,amount[i]-amount[i-k+1])

print(minimum)
# Judge status: Accepted
S = input()

a = S.count('a')
b = S.count('b')
c = S.count('c')

if abs(a-b) <= 1 and abs(a-c) <= 1 and abs(b-c) <= 1:
    print("YES")
else:
    print("NO")
# Judge status: Accepted

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

if max(a,c) <= min(b,d):
    print(min(b,d)-max(a,c))
else:
    print(0)
# Judge status: Wrong Answer
s=input()
f=int(s[:2])
b=int(s[2:4])

if b>=13 or b==0:
    print('NA')
elif f>=13:
    print('YYMM')
else:
    print('AMBIGUOUS')
# Judge status: Wrong Answer
N = int(input())

FACTOR = 10 ** 9 + 7

num = 1
for i in range(1, N+1):
    num *= i
    k, r = divmod(num, FACTOR)
    num = r

k, r = divmod(num, FACTOR)
print(r)
# Judge status: Accepted
N, M = map(int, input().split())
N, M = min(N, M), max(N, M)
if M == 1:
    print(1)
elif N == 1:
    print(M-2)
else:
    print((M-2)*(N-2))
# Judge status: Accepted
import sys
x=int(input())

for j in range(1,361):
    for k in range(1,361):
        if 360*k==x*j:
            print(j)
            sys.exit()
# Judge status: Accepted
X, Y = map(int, input().split())

num = X
cnt = 0
for i in range(1000):
    if(num > Y):
        break
    num = num * 2
    cnt += 1
print(cnt)
# Judge status: Wrong Answer
import sys
import collections

N=input().split()

list1=input().split()

list1=[int(i) for i in list1]

X=int(N[0])

Y=int(N[1])

aaa=[]

#print(len(set(list1)))

int1=len(set(list1))

if int1<=Y:
    print(0)
    sys.exit()

c = collections.Counter(list1)

CCC=sorted(c.items(), key=lambda x:x[1])

print(CCC)

#print(int1)

int2=0

for i in CCC:
    #print(i)
    if int1>Y:
        int2=int2+i[1]
        int1=int1-1
    else:
        break

print(int2)
# Judge status: Accepted
w,h,n = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(n)]

xmin,xmax,ymin,ymax = 0,w,0,h

for a in A:
  if a[2] == 1:
    xmin = max(xmin, a[0])
  if a[2] == 2:
    xmax = min(xmax, a[0])
  if a[2] == 3:
    ymin = max(ymin, a[1])
  if a[2] == 4:
    ymax = min(ymax, a[1])
    
S = (xmax-xmin) * (ymax-ymin)
if S < 0 or xmin > xmax or ymin > ymax:
  S = 0
print(S)
# Judge status: Accepted
n,D = map(int,input().split())
X  =[]
for _ in range(n):
    x = list(map(int,input().split()))
    X.append(x)
ans = 0
for i in range(n):
    for j in range(i+1,n):
        val = 0
        for d in range(D):
            val += (X[i][d]-X[j][d])**2
        val = val**0.5
        if val.is_integer():
            ans += 1
print(ans)
# Judge status: Wrong Answer
import collections
N = int(input())
lsA = list(map(int,input().split()))
counterA = collections.Counter(lsA)
ans = 0
for i in counterA.keys():
    if i == counterA[i]:
        continue
    ans += min(counterA[i],abs(i-counterA[i]))
print(ans)
# Judge status: Wrong Answer
if __name__ == "__main__":
    n, x = map(int, input().split())
    a = list(map(int, input().split()))

    if sum(a) == x:
        print(n)
        exit()

    a.sort()

    ans = 0
    tmp = 0
    for aa in a:
        if tmp < x and aa <= x-tmp:
            tmp += aa
            ans += 1
        if tmp == x:
            print(ans)
            exit()
    if ans > 0:
        ans -= 1

    print(ans)
# Judge status: Accepted
n,a,b,c,d=map(int,input().split())
s=input()

if c<d:
    if s[a-1:d].find("##")!=-1:
        print("No")
    else:
        print("Yes")

else:
    if s[a-1:c].find("##")!=-1:
        print("No")
    else:
        if s[b-2:d+1].find("...")!=-1:
            print("Yes")
        else:
            print("No")