peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Wrong Answer
from sys import stdin
from collections import deque
N=list(map(int,stdin.readline().strip().split()))[0]

t=0
data = [list(map(int,stdin.readline().rstrip().split())) for _ in range(N)]

data=sorted(data,key=lambda x:(x[1],x[0]))
d=deque(data)
final_task, final_time = d.pop()
while(len(d)!=0):
    A,B=d.popleft()
    if B<=t or t<final_time:
        t+=A
    else:
        print("No")
        exit()
t+=final_task
if t<=final_time:
    print("Yes")
else:print("No")
# Judge status: Accepted
H,W=map(int,input().split())
if min(H,W)==1:
    print(1)
elif W%2==0:
    print(int((W/2)*H))
else:
    if H%2==0:
        print(int(((W-1)/2+1+(W-1)/2)*H/2))
    else:
        print(int(((W-1)/2+1+(W-1)/2)*(H-1)/2+(W-1)/2+1))
# Judge status: Accepted
from collections import Counter

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

c = Counter(a)

allsum = 0
for k,v in c.items():
    allsum += k*v
    
ans = []

for i in range(q):
    bi,ci = list(map(int,input().split()))
    allsum += ci*c[bi] - bi*c[bi]
    c[ci] = c[ci] + c[bi]
    c[bi] = 0
    ans.append(allsum)
    
for i in ans:
    print(i)
# Judge status: Accepted
n,m=map(int,input().split())
for i in range(m):
    print(i+1,n-i-((i>=m/2) & ~n))
# Judge status: Wrong Answer
a,b,c,d = map(int,input().split())

d1 = a-b; d2 = c-b

if d1 < 0:
    d1 = -d1
if d2 < 0:
    d2 = -d2

if d1 <= d and d2 <= d:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n, x = map(int, input().split())
a = list(map(int, input().split()))

sort_a = sorted(a)
count = 0
if x > sum(a):
  count-=1
for i in sort_a:
  if x >= i:
    count+=1
    x-=i
  else:
    print(count)
    exit()
print(count)
# Judge status: Wrong Answer
s = input()
a = s.count("a")
b = s.count("b")
c = s.count("c")
k = (a > 0) + (b > 0) + (c > 0)
if k == 1:
  print("NO")
  exit()
if k == 2:
  if len(s) == 2:
    print("YES")
  else:
    print("NO")
  exit()
minabc = sorted([a, b, c])[0]
a = max(0, a - minabc)
b = max(0, b - minabc)
c = max(0, c - minabc)
# print(a, b, c, k)
k = (a > 0) + (b > 0) + (c > 0)
if k == 1:
  print("YES")
  exit()
if k == 2:
  if a + b + c == 2:
    print("YES")
  else:
    print("NO")
# Judge status: Accepted
x, y, z = map(int, input().split())
print("{} {} {}".format(z, x, y))
# Judge status: Accepted
N=int(input())
f=[0 for i in range(10001)]


for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            tmp=x**2+y**2+z**2+x*y+y*z+z*x
            if tmp >10000:
                continue
            f[tmp]+=1

for i in range(1,N+1):
    print(f[i])
# Judge status: Wrong Answer
N,M=map(int,input().split())
BA=[[0,0] for _ in range(N)]

for i in range(N):
    BA[i][1],BA[i][0] = map(int,input().split())

BA.sort(reverse=True)

ans=0
d=0
for i in range(N):
    if BA[i][1]<=M-d:
        ans+=BA[i][0]
        d+=1
    if d==M:
        break

print(ans)
# Judge status: Accepted
num = input().split(" ")
monster = int(num[0])
atk = int(num[1])
hpoints = list(input().split(" "))
hpoints_i = [int(i) for i in hpoints]

hpoints_i.sort(reverse=True)

result = sum(hpoints_i[atk:])
print(result)
# Judge status: Accepted
D = int(input())
cs = list(map(int, input().split()))
ss = [list(map(int, input().split())) for _ in range(D)]

ts = []
for i in range(D):
    t = 1
    ts.append(t)

for t in ts:
    print(t)
# Judge status: Wrong Answer
n = int(input())
t1 = n%1000
t2 = (int(n/1000) + 1)*1000 - n
if t1 < t2:
  print(t1)
else:
  print(t2)
# Judge status: Accepted
def resolve():
    A, B, C = map(int, input().split())
    cnt = 0
    while True:
        if A%2 == 1 or B%2 == 1 or C%2 == 1:
            break
        elif A==B and B==C:
            cnt = -1
            break
        Atmp = A
        Btmp = B
        Ctmp = C
        A = (Btmp+Ctmp)/2
        B = (Atmp+Ctmp)/2
        C = (Atmp+Btmp)/2
        cnt += 1
    print(cnt)
resolve()
# Judge status: Accepted
# ABC_129 C

def stairs(n, a):
    dp = [0 for _ in range(n+1)]
    dp[0] = 1
    if 1 not in a:
        dp[1] = 1
    for i in range(2, n+1):
        if i in a:
            continue
        dp[i] = dp[i-1] + dp[i-2]
            
    result = dp[n] % 1000000007

    print(result)

    
n, m = list(map(int, input().split()))
a = set(int(input()) for _ in range(m))


if __name__ == '__main__':
    stairs(n, a)
# Judge status: Wrong Answer
d=int(input())
result='Christams'
n=25
while n>=22:
    if n>d:
        result+=' Eve'
    n-=1
print(result)
# Judge status: Accepted
X, Y = map(int, input().split())
ans = 1

while True:
  X *= 2
  if X > Y:
    print(ans)
    exit()
  ans += 1
# Judge status: Accepted
#ABC147
a = list(map(int,input().split()))
print("bust" if sum(a)>=22 else "win")
# Judge status: Accepted
n = int(input())
# n < 100000
res = n

for i in range(n+1):
    c = 0
    t = i
    while t > 0:
        c += t % 6
        t //= 6
    t = n - i
    while t > 0:
        c += t % 9
        t //= 9
    if res > c:
        res = c

print(res)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0

for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else:
        val = b[i] - a[i]
        if a[i+1] - val <= 0:
            ans += a[i] + a[i+1]
        else:
            ans += b[i]
            a[i+1] = a[i+1] - val

print(ans)
# Judge status: Accepted
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over= reduce(mul,range(n,n-r,-1))
    under = reduce(mul,range(1,r + 1))
    return over // under


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

ae = [0,0]
ans = 0

for i in range(N):
    ae[A[i] % 2] += 1
for i in range(1,ae[1] + 1,2):
    ans += cmb(ae[1] ,i)
ans *= 2 ** ae[0]

if P == 1:
    print(ans)
else:
    print(2 ** N - ans)
# Judge status: Accepted
A = input()
import math
times = math.ceil(len(A)/2)
count = 0
for i in range(times):
  if A[i] != A[len(A)-1-i]:
    count += 1
print(count)
# Judge status: Accepted
s=input()
k=int(input())
ans=''
for c in s:
    t=ord('z')-ord(c)+1
    if t<26 and t<=k:
        k-=t
        ans+='a'
    else:
        ans+=c
if k>0:
    ans=ans[:-1]+chr(ord('a')+(ord(ans[-1])-ord('a')+k)%26)
print(ans)
# Judge status: Accepted
N, K = (int(x) for x in input().split())
S = input()

S = S[:K-1] +S[K-1].lower() +S[K:]
print(S)
# Judge status: Wrong Answer
x = [0] * 5
x = input().split()
x = [int(_) for _ in x]
print(x)

for i in range(5):
    if x[i] == 0:
        ans = i
        print(ans+1)
        break
# Judge status: Wrong Answer
A1, A2, A3 = map(int, input().split())
if (A1 + A2 + A3) <= 21:
    print("Win")
else:
    print("bust")
# Judge status: Wrong Answer
a,b=map(int,input().split())

if a>b:
  print(b)
else:
  print(a)
# Judge status: Wrong Answer
s = input()
keyence = ["k", "e", "y", "e", "n", "c", "e"]
idx = 0
for i in range(len(s)):
    if s[i] == keyence[idx]:
        idx += 1
    if idx == len(keyence):
        print("YES")
        exit()

print("NO")
# Judge status: Accepted
N = input()
if N[0] == "9" or N[1] == "9":
  print("Yes")
else:
  print("No")
# Judge status: Accepted
n,m = map(int,input().split())
a = list(map(int,input().split()))

check = sum(a) /4/m
count = 0
for i in range(n):
  if a[i] >= check:
    count += 1

if count >= m:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
a,b,c = map(int, input().split())
if (b > a and b < c) or (b < a and b > c):
  print('No')
else:
  print('Yes')
# Judge status: Accepted
X, K, D = map(int,input().split())

ans = 0
ref = abs(X) // D

if ref >= K:
    ans = abs(X) - K * D
else:
    ans = abs(X) - ref * D
    K = K - ref
    if K % 2 == 1:
        ans = abs(ans - D)
    else:
        pass

print(ans)
# Judge status: Accepted
from collections import*
s=input()

c=Counter(s)

if (c["S"]==0 and c["N"]>0) or (c["N"]==0 and c["S"]>0) or (c["E"]==0 and c["W"]>0) or (c["W"]==0 and c["E"]>0):
    print("No")
else:
    print("Yes")
# Judge status: Accepted
H = int(input())

tmp = 1
counter = 0

while tmp <= H:
    tmp = tmp*2 
    counter += 1

print(tmp - 1)
# Judge status: Wrong Answer
N,M = map(int, input().split())
A = list(map(int, input().split()))
task = 0
for i in range(M):
    task += A[i]
answer = task
if answer > 0:
    print(N - task)
else:
    print(-1)
# Judge status: Wrong Answer
a, b = map(int, input().split())
A = int(pow(a, b))
B = int(pow(b, a))
if A > B:
    print(A)
else:
    print(B)
# Judge status: Accepted
N = int(input())
H = list(map(int, input().split()))

h = H[0]

for i in range(N):
    if H[i] >= h:
        h=H[i]
    elif H[i]-h == -1:
        continue
    else:
        print('No')
        exit()

print('Yes')
# Judge status: Accepted
n, k = input().split()
n = int(n)
k = int(k)
listnum = input().split()
newlist = []
sumnum = 0

listnum = [int(n) for n in listnum]
newlist = sorted(listnum)
for b in range(k):
    sumnum = sumnum + newlist[b]
print(sumnum)
# Judge status: Wrong Answer
N, M=map(int, input().split())
mod=10**9+7
pre=-1
hole=[]
for i in range(M):
  a=int(input())
  hole.append(a-1-pre)
  pre=a
hole.append(N-pre)

  

dp=[0]*(N+3)
dp[1]=1
dp[2]=1
for i in range(3,N+3):
  dp[i]=(dp[i-1]+dp[i-2])%mod
if len(hole)==1:
  print(dp[N+1])
  
#print(dp)
#print(hole)
ans=1
for h in hole:
  ans*=dp[h]
  ans%=mod
  
print(ans)
# Judge status: Accepted
def main():
    x, a, b = (int(i) for i in input().split())
    day = -a+b
    if day <= 0:
        print("delicious")
    elif day <= x:
        print("safe")
    else:
        print("dangerous")


if __name__ == '__main__':
    main()
# Judge status: Accepted
import numpy as np

r=int(input())

print(2*r*np.pi)
# Judge status: Accepted
#ABC-118-B
N, M = map(int, input().split())
memo = [0]*(M+1)

for _ in range(N):
    Ki, *A = map(int, input().split())
    for item in A:
        memo[int(item)] += 1

ans = 0
for i in range(1, M+1):
    if memo[i] == N:
        ans += 1

print(ans)
# Judge status: Accepted
s = input()
n = len(s)
a = [0]*(n+1)
yama = []
tani = []

for i in range(n):
	if s[i] == '<':
		a[i+1] = a[i] + 1

for i in range(n)[::-1]:
	if s[i] == '>':
		a1 = a[i+1] + 1
		if i != 0:
			if s[i-1] == '<':
				a[i] = max(a[i], a1)
			else:
				a[i] = a1
		else:
			a[i] = a1

ans = sum(a)
print(ans)
# Judge status: Accepted
N = int(input())
B = 0
for i in range(N):
  A = 0
  for j in range(i+1):
     if (i+1) % (j+1) == 0:
        A += 1
  if A == 8 and (i+1) % 2 == 1:
    B += 1
print(B)
# Judge status: Accepted
#!/usr/bin/env python3
n = int(input())
s = input()
e = [0]*n
w = [0]*n
for i in range(n):  
    if s[n-1-i] == "E":e[i] = e[i-1]+1
    else: e[i] = e[i-1]
    if s[i] == "W":w[i] = w[i-1]+1
    else: w[i] = w[i-1]
#print(e,w,s)
ans = e[n-2]
for i in range(1,n):
    #print(i,ans)
    if i == n-1:
        ans = min(ans,w[i-1])
    else: ans = min(ans,w[i-1]+e[n-2-i])
print(ans)
# Judge status: Wrong Answer
N, T = map(int,input().split())
ans = 10000
for _ in range(N):
  c,t = map(int,input().split())
if t <= T:
  ans = min(ans,c)

print("TLE" if ans==10000 else ans)
# Judge status: Wrong Answer
n,m=map(int,input().split())
l={}
for i in range(m):
    p,q=map(int,input().split())
    if not p in l:
        l[p]=1
    else:
        l[p]+=1
    if not q in l:
        l[q] = 1
    else:
        l[q] += 1
for k,v in sorted(l.items()):
    print(v)
# Judge status: Accepted
n=int(input())
l=sorted(list(map(int,input().split())),reverse=1)
from heapq import heapify, heappop, heappush
h=[-l[0]]

ans=0
for i in range(1,n):
    p=-heappop(h)
    ans+=p
    heappush(h,-l[i])
    heappush(h,-l[i])
print(ans)
# Judge status: Accepted
from fractions import gcd
from functools import reduce
n,x=list(map(int,input().split()))
X=list(map(int,input().split()))
Y=[abs(X[i]-x) for i in range(n)]
print(reduce(gcd,Y))
# Judge status: Wrong Answer
N = input()
N = reversed(N)
cnt = 0
up = False
for s in N:
    n = int(s)
    if up:
        n += 1
        up = False
    if n <= 5:
        cnt += n
    elif n == 10:
        up = True
    else:
        cnt += 10 - n
        up = True
if up:
    cnt += 1
print(cnt)
# Judge status: Accepted
w,h,x,y = map(int, input().split())
ans = 0
if w/2 == x and h/2 == y:
    ans = 1

print(w*h/2, ' ', ans)
# Judge status: Wrong Answer
n = int(input())
ab = [[] for _ in range(n)]
az = [None] * n
bz = [None] * n
task = set()
flag = True
for i in range(n):
    ab[i] = list(map(int, input().split()))
    az[i], bz[i] = ab[i]


for a, b in ab:
    if (a, b) in task:
        flag = False
    else:
        task.add((a, b))
    if a > b:
        flag = False

if sum(az) > max(bz):
    flag = False
else:
    flag = True

print("Yes") if flag else print("No")
# Judge status: Accepted
N=int(input())
A=list(map(int,input().split()))
B=sum(A)
b=0
ans=202020202020
for a in A:
    b+=a
    ans=min(ans,abs(B-b*2))
print(ans)
# Judge status: Accepted
# MAX = int(1e6)+2


n = int(input())
lis = list(map(int,input().split()))
lis.sort()
MAX = lis[-1]
lis2 = [0]*(MAX+1)
# lis.sort()
# m = max(lis)
ans = 0

for num in lis:
    for i in range(num, MAX+1, num):
            lis2[i] += 1

for j in set(lis):
    if lis2[j] == 1:
        ans += 1
print(ans)
# Judge status: Accepted
s = input()
if s[0] == s[1] == s[2] or s[1] == s[2] == s[3]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
s = str(input())
l = []
left, right = 0, 0
for c in s:
    if c == ')':
        if l == []:
            left += 1
        else:
            l.pop()
    else:
        l.append(1)
right = len(l)
print('(' * left + s + ')' * right)
# Judge status: Wrong Answer
S=int(input())

#S=x1y2-x2y1
#S+x2y1=x1y2
#S+y1=10**9y2 (x1=10**9, x2=1)
#S+y1が10**9の倍数になるようにy1を決める
Y1=10**9-S%(10**9)
Y2=(S+Y1)//(10**9)
print(10**9,Y1,1,Y2,0,0)
# Judge status: Accepted
ans = input()
q = int(input())
r = 0
p = ""
for i in range(q):
    d = input().split()
    if len(d)==1:
        r += 1
    else:
        f = int(d[1])
        c = d[2]
        if (f+r)%2 == 1:
            p += c
        else:
            ans += c
ans = p[::-1] + ans
if r%2:
    ans = ans[::-1]
print(ans)
# Judge status: Accepted
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

def gcd(a, b):
    while b: a, b = b, a % b
    return a

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

def prime_factorize(m):
    pf={}
    for i in range(2, int(m**0.5)+1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf

a,b = map(int, input().split())
g = gcd(a,b)
pf = prime_factorize(g)
print(len(pf.keys()) + 1)
# Judge status: Accepted
import sys
input = sys.stdin.readline
A, B, C = [int(x) for x in input().split()]
if A <= C <= B:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
a,b,x = map(int, input().split())
import math
if 2*x <= a**2 *b:
    print(math.degrees(math.atan((a*b**2)/(2*x))))
else:
    print(math.degrees(math.atan((2*a**2*b -2*x)/(a**3))))
# Judge status: Accepted
let = set(input())
print({True: 'Yes', False: 'No'}[len(let) == 2])
# Judge status: Wrong Answer
s=input()
f=int(s[:2])
b=int(s[2:4])

if (b>=13 or b==00)and f>=13 :
    print('NA')
elif (b>=13 or b==00)and f<=12 :
    print('MMYY')
elif b<=12 and (f>=13 or f==00) :
    print('YYMM')
else:
    print('AMBIGUOUS')
# Judge status: Wrong Answer
from collections import defaultdict

blue=int(input())
blueList = []

for i in range(blue):
  blueList.append(input())

red=int(input())
redList = []

for i in range(red):
  redList.append(input())

dict = defaultdict(int)

for b in blueList:
  dict[b] += 1

for r in redList:
  dict[r] -= 1

max = -10000

for s in dict:
  if dict[s] > max:
    max = dict[s]
  
print(max)
# Judge status: Wrong Answer
N = int(input())
INT_LIST_SORETED = sorted([int(s) for s in input().split()])
SECOND_INT_LIST_MAX = [val for idx, val in enumerate(INT_LIST_SORETED)
                       if idx >= N and idx % 2 == 0]
print(sum(SECOND_INT_LIST_MAX))
# Judge status: Wrong Answer
n = int(input())
s = input()
ans = s
if s.count(")") == 0:
	ans += ")"*(s.count("("))
	print (ans)
	exit()
if s.count("(") == 0:
	ans = "("*(s.count(")")) + ans
	print (ans)
	exit()
lef2 = s.rindex(")")
rit2 = s.index("(")

ans = s
ans += ")"*(n-(lef2+1))
ans = "("*rit2 + ans
lef = ans.count("(")
rit = ans.count(")")
if lef > rit:
	ans += ")"*(lef-rit)
	print (ans)
elif lef == rit:
	print (ans)
else:
	ans = "("*(rit-lef) + ans
	print (ans)
# Judge status: Accepted
K = int(input())
A,B = map(int, input().split())

for num in range(A, B+1, 1):
  if num % K == 0:
    print('OK')
    break
else:
  print('NG')
# Judge status: Wrong Answer
x,y,z = map(int,input().split())
tmp = x
x = y
y = tmp
print(x,y,z)
tmp = x
x = z
z = tmp

print(x,y,z)
# Judge status: Wrong Answer
N = int(input())
lst = [[0 for i in range(10)]for j in range(10)]
ans = 0
for i in range(N):
    tmp = list(str(i))
    lst[int(tmp[0])][int(tmp[-1])]+=1
for i in range(10):
    for j in range(10):
        if i == 0 or j == 0:
            continue
        if i == j:
            ans+=lst[i][j]**2
        else:
            ans+=lst[i][j]*lst[j][i]
print(ans)
# Judge status: Accepted
def main():
  input_name = input()
  print(input_name[0:3])


if __name__=='__main__':
  main()
# Judge status: Accepted
w = str(input())
count = 0
for i in w:
    if w.count(i) % 2 == 0:
        pass
    else:
        count = 1
        break
print("Yes" if count == 0 else "No")
# Judge status: Accepted
a, b, c = map(int, input().split())
if a == b == c:
  print(1)
elif a == b or b == c or c == a:
  print(2)
else:
  print(3)
# Judge status: Accepted
d, n = map(int, input().split())
if n == 100:
  n += 1
print((100**d)*n)
# Judge status: Accepted
s = list(input())
ss = s[::]

for i in range(len(s)):
	if len(ss) == 1:
		break
		
	ss.pop()
	if len(ss) % 2 == 0:
		n = len(ss) // 2
		if ss[:n] == ss[n:]:
			break

if len(ss) == 1:
	print(-1)
else:
	print(len(ss))
# Judge status: Accepted
from collections import defaultdict
def solve():
    S = input()
    counter = defaultdict(int)

    for ch in S:
        counter[ch] += 1
    
    vals = sorted([counter["a"],counter["b"],counter["c"]])

    if vals[1] - vals[0] <= 1 and vals[2] - vals[0] <= 1:
        print('YES')
    else:
        print('NO')
        
if __name__ == '__main__':
    solve()
# Judge status: Wrong Answer
N = int(input())

count = 0
while N > 0:
    digit = N % 10
    N //= 10
    count += 1

if count == 2:
    print('pon')
elif count == 1:
    print('hon')
elif count == 3:
    print('bon')
# Judge status: Accepted

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

total = 0
for a in range(N+1):
    
    for b in range(N+1-a):
        
        c = N -a -b
            
        total = a*10000 + b*5000 + c*1000 
        if (total == Y) and (a+b+c==N) and (c>=0):
            print(a, b, c)
            exit()
        
print(-1,-1,-1)
# Judge status: Accepted
x, a, b = map(int, input().split())

print('A' if abs(x-a) < abs(x-b) else 'B')
# Judge status: Accepted
n=int(input())
for i in range(1,10):
    if n<=i*111:
        print(i*111)
        break
    else:
        pass
# Judge status: Wrong Answer
n=int(input())
s=sorted([int(input()) for _ in range(n)],reverse=True)

for i in range(n,0,-1):
    ss=sum(s[:i])
    if ss%10>0:
        print(ss)
        break
else:
    print(0)
# Judge status: Accepted
n = int(input())
al = list(map(int, input().split()))

ans = sum(al)**2
for a in al:
    ans -= a**2

mod = 10**9+7
print((ans//2)%mod)
# Judge status: Accepted
N = input()
s = 0
for n in N:
    s += int(n)
if s % 9 == 0:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
def main():
    n, m = map(int, input().split())
    num_list = list(map(int, input().split()))

    vote_num = sum(num_list)

    count = 0

    for i in range(n):
        if vote_num * 1/(4*m) <= num_list[i]:
            count += 1

    print('Yes' if count >= m else 'No')

if __name__ == '__main__':
    main()
# Judge status: Accepted
from collections import Counter


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

ans = 0
for k, v in Counter(a).items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v

print(ans)
# Judge status: Accepted
[N,K] = list(map(int,input().split()))
if N<K:
    print(1)
else:
    i=N
    j=0
    while i>=K:
        i = i/K
        j=j+1
    print(j+1)
# Judge status: Accepted
n, m, k = map(int, input().split())

for x in range(n+1):
    for y in range(m+1):
        num_of_blacks = x*m + y*n - 2*x*y
        if num_of_blacks == k:
            print('Yes')
            exit()
print('No')
# Judge status: Accepted
def main():
    import sys
    input = sys.stdin.readline
    n,m = map(int,input().split())
    l = list(map(int,input().split()))
    dp = [0]+ [100000000000]*(n-1)

    for i in range(1,n):
        
        for j in range(1,m+1):
            if i-j >= 0:
                dp[i] = min(dp[i],dp[i-j]+abs(l[i]-l[i-j]))
        
    print(dp[n-1])

if __name__ == "__main__":
    main()
# Judge status: Accepted
a,b,c,d=map(int,input().split())

if a<=c and b<=d:
    if b-c>0:
        print(b-c)
    else:
        print(0)    
elif a>=c and b>=d:
    if d-a>0:
        print(d-a)
    else:
        print(0)
elif a<=c and b>=d:
    print(d-c)
elif a>=c and b<=d:
    print (b-a)
# Judge status: Accepted
n,k=map(int,input().split())
ans=0
for i in range(k,n+2):
    a=0.5*i*(i-1)
    b=0.5*n*(n+1)-0.5*(n-i)*(n-i+1)
    ans+=int(b-a+1)


print(ans%(10**9+7))
# Judge status: Wrong Answer
n = int(input())
a_s = list(map(int, input().split()))

ans = 0

for i in range(n):
    for j in range(i+1, n):
        ans += int(a_s[i] * a_s[j] % (1e9 + 7))

print(ans)
# Judge status: Wrong Answer
N,M = map(int,input().split())

lc = list(map(int,input().split()))
lc.sort()
#print(lc)
diff = []
for i in range(M-1):
    diff.append(lc[i+1]-lc[i])
    
#print(diff)
diff.sort()
diff_min = diff[:M-N]
print(sum(diff_min))
# Judge status: Accepted
n = input()
digit = len(n) - 1
if n.count('9') == len(n):
    print(9*len(n))
else:
    if digit > 0:
        if n[1:].count('9') == len(n[1:]):
            print(9*digit + int(n[0]))
        else:
            print(9*digit + int(n[0])-1)
    else:
        print(n[0])
# Judge status: Accepted
def main():
    MAX = 100010
    n,k = map(int,input().split())
    m = {}
    for x in range(100010):
        m[x] = 0
    for x in range(n):
        a,b = map(int,input().split())
        m[a] += b
    if k == 0:
        print(m.keys()[0])
        return
    for key,value in m.items():
        k-=value
        if k <= 0:
            print(key)
            return

if __name__ == '__main__':
    main()
# Judge status: Accepted
N, M = map(int, input().split())

a = [0] * N
b = [0] * N
for i in range(N):
    a[i],b[i] = map(int,input().split())
c = [0] * M
d = [0] * M
for i in range(M):
    c[i],d[i] = map(int,input().split())

for i in range(N):
    MIN = 10**9
    for j in range(M):
        if abs(a[i]-c[j])+abs(b[i]-d[j]) < MIN:
            MIN = abs(a[i]-c[j])+abs(b[i]-d[j])
            cnt = j+1
    print(cnt)
# Judge status: Accepted
n, m, x, y = map(int, input().split())
X = list(map(int, input().split()))
Y = list(map(int, input().split()))
for i in range(x + 1, y + 1):
    if max(X) < i and min(Y) >= i:
        print("No War")
        exit()
print("War")
# Judge status: Accepted
a,b= input().split()

print(str(min(int(a),int(b)))*int(str(max(int(a),int(b)))))
# Judge status: Wrong Answer
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = np.array(readline().split(), dtype=np.int32)
b = np.array(readline().split(), dtype=np.int32)
c = np.array(readline().split(), dtype=np.int32)

a.sort()
b.sort()
c.sort()

cnt_a = np.searchsorted(a, b, side='left')
cnt_c = np.searchsorted(c, -b, side='left')
 
answer = (cnt_a * cnt_c).sum()
print(answer)
# Judge status: Wrong Answer
n = int(input())
a = [input() for _ in range(n)]
a_dict = {i:0 for i in set(a)}

for i in a:
    for j in a_dict:
        if i == j:
            a_dict[j] += 1

ans = []
for key, value in a_dict.items():
    if value == max(a_dict.values()):
        ans.append(key)
ans.sort()
print(ans)