peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
from fractions import gcd
a, b, c, d = map(int, input().split())
lcm = (c*d)//gcd(c, d)
ac = (a-1)//c
bc = b//c
ad = (a-1)//d
bd = b//d
acd = (a-1)//lcm
bcd = b//lcm
abc = bc-ac
abd = bd-ad
abcd = bcd-acd
print((b-a+1)-abc-abd+abcd)
# Judge status: Accepted
s = str(input().rstrip())
if s in ["hi"*x for x in range(1, 6)]:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
s = input()
n = len(s)
ans = 100000
for i in range(n-2):
    x = 100 * int(s[i]) + 10 * int(s[i+1]) + int(s[i+2])
    diff = abs(x - 753) 
    ans = min(ans,diff)
print(ans)
# Judge status: Wrong Answer
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split())) + [0]

print(sum(b) + sum(c) - c[a[-1]-1])
# Judge status: Wrong Answer
from itertools import accumulate
N,Q = map(int,input().split())
S = str(input())
lr = [list(map(int,input().split())) for _ in range(Q)]
sl = [0]*N
for i in range(N):
  if S[i:i+2] == "AC":
    sl[i] = 1
slr = [0]+list(accumulate(sl))
ans = 0
for l,r in lr:
  l -= 1
  r -= 1
  ans = slr[r]-slr[l]
  if r < N:
    if slr[r] == slr[r-1]:
      ans -= 1
  if slr[l] != slr[l-1]:
    ans += 1
  print(ans)
# Judge status: Accepted
a, b, c, k = map(int, input().split())

if k <= a:
    print(k)
elif a < k <= (a + b):
    print(a)
else:
    print(2*a-k+b)
# Judge status: Accepted

def main():
    n = int(input())
    a = int(input())
    n = n % 500
    if n <= a:
        print("Yes")
    else:
        print("No")

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

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

print((n + m) % 24)
# Judge status: Accepted
# ABC 057: A – Remaining Time
a, b = [int(s) for s in input().split()]
print(a + b if a + b <= 23 else a + b - 24)
# Judge status: Wrong Answer
def main():
  s = input()
  
  answer = 0
  
  while (not "0" in s) or (not "1" in s):
    answer += s.count("10")
    s.replace("10", "")
    answer += s.count("01")
    s.replace("01", "")
  
  print(answer)


if __name__ == "__main__":
  main()
# Judge status: Accepted
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))
n,k = iim()
h = []
for _ in range(n):
    h.append(ii())
h.sort()

ans = float('INF')
for i in range(n-k+1):
#    print(i,i+k-1,h[i],h[i+k-1])
    ans = min(ans,h[i+k-1]-h[i])
print(ans)
# Judge status: Accepted
a, b = map(int, input().split())

n = 0
    
if a * 12.5 < (b+1) * 10 and b * 10 < (a+1) * 12.5:
    while n < a * 12.5 or n < b * 10:
        n += 1
    else:
        print(n)
else:
    print('-1')
# Judge status: Accepted
N = int(input())
s = sorted([sorted(input()) for _ in range(N)])
total = 0
count = 1
for i in range(N-1):
    if s[i] == s[i+1]:
        count += 1
    else:
        total += count * (count - 1) / 2
        count = 1
total += count * (count - 1) / 2
print(int(total))
# Judge status: Accepted
a,b =input().split()
a,b= int(a), int(b)
print('Yes' if 500*a>=b else 'No')
# Judge status: Accepted
n=int(input())
s=input()
ans=0
for i in range(1,n):
    a=set(s[:i])
    b=set(s[i:])
    cnt = 0
    for i in a:
        for j in b:
            if i == j:
                cnt += 1
                break
        ans=max(cnt,ans)
print(ans)
# Judge status: Accepted
S=input()
T=input()
s=len(S)
t=len(T)
A=[]


for i in range(s-t+1):
  word=S[i:i+t]
  a=0
  for j in range(t):
    if word[j]==T[j]:
      a+=1
    else:
      a+=0
  A.append(t-a)

print(min(A))
# Judge status: Accepted
S = input()
T = input()
N, M = len(S), len(T)
ma = 0
for i in range(N-M+1):
    c = 0
    for j in range(M):
        if S[i+j] == T[j]:
            c += 1
    ma = max(ma, c)

print(M - ma)
# Judge status: Accepted
def abc141d():
    import heapq
    n, m = map(int, input().split())
    a = list(map(lambda x: -int(x), input().split()))
    heapq.heapify(a)
    for _ in range(m):
        v = -heapq.heappop(a)
        v = v//2
        heapq.heappush(a, -v)
    print(abs(sum(a)))

abc141d()
# Judge status: Accepted
A,B,C=map(int,input().split())
X=min(A,B,C)
Z=max(A,B,C)
Y=A+B+C-(X+Z)

if (X*Y*Z)%2==0:
    print(0)
else:
    print(X*Y)
# Judge status: Wrong Answer
k, a, b = map(int, input().split())
ans = 0
if a >= b:
    ans += k+1
else:
    if k <= a:
        ans += k+1
    else:
        ans += a
        k -= a - 1
        if k % 2 == 1:
            ans += 1
            k -= 1
        ans += (k // 2)*(b - a)


        # ans = max(ans, k+1)

print(int(ans))
# Judge status: Accepted
#B - すぬけ君の塗り絵 2 イージー

W,H,N = list(map(int,input().split()))

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

up = H
down = 0
left = 0
right = W

for l in xya:
  if l[2] == 1 and l[0] > left:
    left = l[0]
  elif l[2] == 2 and l[0] < right:
    right = l[0]
  elif l[2] == 3 and l[1] > down:
    down = l[1]
  elif l[2] == 4 and l[1] < up:
    up = l[1]
    
if left >= right or down >= up:
  area = 0
else:
  area = (up-down)*(right-left)
  
print(area)
# Judge status: Accepted
a, b = map(int, input().split())
if a < 10 and b < 10:
    print(a*b)
else:
    print(-1)
# Judge status: Wrong Answer
def main():
    N = int(input())
    res = N*(N-1)/2
    print(int(res))
    
main()
# Judge status: Wrong Answer
from math import ceil
from fractions import gcd


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

def num(l,r,x):
    return r//x-ceil(l/x)+1

def lcm(x,y):
    return x*y//gcd(x,y)

cn=num(a,b,c)
dn=num(a,b,d)
cdn=num(a,b,lcm(min(c,d),max(c,d)))

ans=(b-a+1)-(cn+dn-cdn)
print(ans)
# Judge status: Wrong Answer
N=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)

print(sum( a[N//3:2*N//3] ))
# Judge status: Wrong Answer
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n, T = map(int, input().split())
cost = False
for i in range(n):
    c, t = map(int, input().split())
    if t > T:
        pass
    else:
        if i == 0:
            cost = c
        else:
            if cost > c:
                cost = c
if cost == False:
    print("TLE")
else:
    print(cost)
# Judge status: Accepted
X = int(input())

flg = 0
for i in range(-200,200):
  if flg == 1:
    break

  for j in range(-200,200):
      if i**5 - j **5 == X:
        print(i,j)
        flg = 1
        break
# Judge status: Accepted
a, b, c, d = input()
if a == b == c or b == c == d:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N,M = map(int,input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
cd = [tuple(map(int,input().split())) for _ in range(M)]

for a,b in ab:
    tmp = []
    for c,d in cd:
        tmp.append(abs(a-c)+abs(b-d))
    
    print(tmp.index(min(tmp))+1)
# Judge status: Accepted
N, A, B, C, D = map(int, input().split())
S = input()

if "##" in S[B: D - 1]:
    print("No")
    exit()
elif "##" in S[A: C - 1]:
    print("No")
    exit()

if D < C:
    if not "..." in S[B - 2: D + 1]:
        print("No")
        exit()

print("Yes")
# Judge status: Wrong Answer
s = list(input())
l = len(s)
if l == 1:
    print('YES')
elif l == 2:
    tmp = len(set(s))
    if tmp == 2:
        print('YES')
    else:
        print('NO')
elif l == 3:
    tmp = len(set(s))
    if tmp == 3:
        print('YES')
    else:
        print('NO')
else:
    tmp = len(set(s))
    if tmp == 1 or tmp == 2:
        print('NO')
    else:
        print('YES')
# Judge status: Wrong Answer
c = input()

if c == 'a' or c == 'b' or c == 'c' or c == 'd' or c == 'e':
    print('vowel')
else:
    print('consonant')
# Judge status: Wrong Answer
A,B,C=map(int,input().split())
if A==B and A !=C:
    print("No")
elif A==C and A!=B:
    print("No")
elif B==C and B !=A:
    print("No")
else:
    print("Yes")
# Judge status: Wrong Answer
r, g, b = map(int, input().split())
x = r * 100 + g * 10 + b
if x % 4 == 0:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
import fileinput

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

if n >= 10:
    print(r)
else:
    rr = r + 100 * (10 - n)
    print(rr)
# Judge status: Accepted
def resolve():
    n = input()
    l = len(n)
    if n[1:] == "9" * (l-1): #c9999...99のとき
        print(int(n[0]) + 9*(l-1))
    else:
        print((int(n[0])-1) + (9*(l-1)))
resolve()
# Judge status: Wrong Answer
N,M = map(int,input().split())
A = [int(input()) for m in range(M)]
dp = (N+1)*[0]
dp[0] = 1
dp[1] = 1

for n in range(1,N+1):
  if n in A:
    dp[n] = 0
  else:
    dp[n] = (dp[n-2]+dp[n-1])%(10**9+7)

print(dp[N])
# Judge status: Accepted
s=input()
t=input()

li=[]

for i in range(0,len(s)-len(t)+1):
    li.append(s[i:i+len(t)])

maxi=0
for w in li:
    count=0
    for k in range(len(t)):
        if(w[k]==t[k]):
            count+=1
    maxi=max(maxi,count)
print(len(t)-maxi)
# Judge status: Accepted
n = int(input())
print(sum(len(str(i)) % 2 for i in range(1, n + 1)))
# Judge status: Accepted
import sys

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

L = []
for _ in range(N):
    A,B = map(int, input().split())
    L.append([A,B])

L = sorted(L, key=lambda x: x[0])

sum = 0
for i in range(len(L)):
    l = L[i]
    if l[1]<M:
        M = M - l[1]
        sum = sum + l[0]*l[1]
    else:
        sum = sum + l[0]*M
        print(sum)
        sys.exit()      

print(sum)
# Judge status: Wrong Answer
a,b = input().split()
a = int(a)
b = int(b)
c = 0
for i in range(10000):
    d = c*0.08
    e = c*0.1
    d = int(d)
    e = int(e)
    if d == a and e == b:
        print(c)
        break
    elif c == 10000:
        print('-1')
    else:
        c += 1
# Judge status: Accepted
a, b = map(int, input().split())
s = 0
for i in range(b - a):
    s += i
print(s-a)
# Judge status: Accepted
K, X  = map(int,input().split())
money = K * 500
if money >= X:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
N = input()
print sum(sorted(map(int, raw_input().split()))[N::2])
# Judge status: Accepted
k,a,b = list(map(int, input().split()))

# 2手かけて増えるのが2枚以下なら地道に増やす
if b-a <= 2:
    print(1+k)
else:
    k -= a-1
    q,r = divmod(k,2)
    print(a+q*(b-a)+r)
# Judge status: Accepted
from math import ceil
h,a = map(int,input().split())

print(ceil(h/a))
# Judge status: Wrong Answer
a=list(input())
b=list(input())
c=list(input())
order='a'
while True:
  if order=='a':
    order=a[0]
    if len(a)==1:
      print('A')
      break
    else:
      a=a[1:]
  elif order=='b':
    order=b[0]
    if len(b)==1:
      print('B')
      break
    else:
      b=b[1:]
  elif order=='c':
    order=c[0]
    if len(c)==1:
      print('C')
      break
    else:
      c=c[1:]
# Judge status: Accepted
T = input()
T = T.replace("?", "D")
print(T)
# Judge status: Wrong Answer
S,T=input().split()
A,B=map(int,input().split())
U=input()

d={S:A,T:B}

d[U]-=1

for i in list(d.values()):
    print(i, end=" ")
# Judge status: Wrong Answer
N = int(input())
d = list(map(int,input().split()))
if len(d) % 2 == 1:
  print(0)
else:
  D = sorted(d)
  n = len(d) // 2 - 1 
  print(D[n+1] - D[n] - 1)
# Judge status: Wrong Answer
H = int(input()) # 初めのモンスターのヒットポイント
atCount = 0 # 攻撃回数

nthPow = H
n = 0

while nthPow > 1:
  nthPow = int(nthPow / 2)
  n = n + 1
print(n)
print(2 ** (n + 1) - 1)
# Judge status: Wrong Answer
n, k = map(int, input().split())
a = n % k
b = a - (n + a) % k
if a < b:
    print(a)
else:
    print(b)
# Judge status: Accepted
a,b,c = map(int,input().split())
if a == b == c:
    print(1)
elif a != b and b != c and c != a:
    print(3)
else:
    print(2)
# Judge status: Accepted
import math
n,d = map(int,input().split())
a = [list(map(int,input().split())) for i in range(n)]
cnt=0
for i in range(n):
    for j in range(i+1,n):
        sum = 0
        for k in range(d):
            tmp = abs(a[i][k]-a[j][k])
            sum+=tmp**2
        sum = math.sqrt(sum)
        if sum % 1 == 0: 
          cnt += 1
print(cnt)
# Judge status: Accepted
N,K=map(int,input().split())
alist=list(map(int,input().split()))

for i in range(K,N):
  if alist[i]>alist[i-K]:
    print("Yes")
  else:
    print("No")
# Judge status: Accepted

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

from operator import add
from itertools import accumulate

L = list(accumulate(A, add))

ans = float("inf")
for i in range(N-1):
  x = L[i]
  y = L[N-1] - L[i]
  ans = min(ans, abs(x-y))

print(ans)
# Judge status: Accepted
import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

N,M = map(int,input().split())
a = list(map(lambda a: int(a)//2, input().split()))
g = lcm(*a)
if any([g // item % 2 == 0 for item in a]):
    print(0)
else:
    ans = M//g
    ans = max(math.ceil(ans/2),0)   
    print(ans)
# Judge status: Accepted
i=list(map(int,input().split()))
if i[0]>i[1]:
  a=str(i[1])*i[0]
else:
  a=str(i[0])*i[1]
print(a)
# Judge status: Accepted
K = int(input())
total = 0
 
def gcd(a, b):
    if(a > b):
        a, b = b, a
 
    while(b > 0):
        r = a % b
        a = b
        b = r
 
    return a
 
 
for a in range(1, K+1):
    for b in range(1, K+1):
        res = gcd(a, b)
        for c in range(1, K+1):
           total += gcd(res, c)
 
 
print(total)
# Judge status: Accepted
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * pow(i+1, mod - 2, mod) % mod
    return res

n, a, b = map(int, input().split())
mod = 10 ** 9 + 7
all_patern = pow(2, n, mod) - 1
minus_a = combination(n, a)
minus_b = combination(n, b)
print((all_patern - minus_a - minus_b) % mod)
# Judge status: Wrong Answer
s = input()
t = input()

change_dict = {}
ans = "Yes"
for c_s, c_t in zip(s, t):
    if c_t in change_dict and change_dict[c_t] != c_s:
        ans = "No"
        break
    change_dict[c_t] = c_s
print(ans)
# Judge status: Wrong Answer
ans = []
A, B, C = map(int, input().split())
ans.append(A)
ans.append(B)
ans.append(C)
if ans.count(5) == 2 and ans.count(7) == 1:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7


def main():
  N, K = map(int, readline().split())
  ans = math.log(1,2)
  print(math.ceil(ans))
  
  
  
if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr(), dtype=np.int32)
A -= np.arange(1, N+1)
answer = np.abs(A - np.median(A)).sum()
print(answer)
# Judge status: Wrong Answer
# -*- coding: <encoding name> -*-

n = int(input())
l = list(map(int, input().split()))
s = sum(l)
print('Yes' if (n - 1) < s else 'No')
# Judge status: Accepted
A, B, C = map(int, input().split())

if A % 2 == 0 or B % 2 == 0 or C % 2 == 0:
    print(0)
else:
    a = abs((A // 2) * B * C - ((A + 1) // 2) * B * C)
    b = abs(A * (B // 2) * C - A * ((B + 1) // 2) * C)
    c = abs(A * B * (C // 2) - A * B * ((C + 1) // 2))
    print(min(a, b, c))
# Judge status: Wrong Answer
import numpy as np

S=input()

s = [st for st in S]
if len(np.unique(s)) == 3:
  print("YES")
else:
  print("NO")
# Judge status: Accepted

def main():
    n = int(input())
    nums = list(range(1,n+1))
    ans = 0
    for num in nums:
        cnt = n//num
        curr_sum = cnt*(2*num+(cnt-1)*num)//2
        ans += curr_sum
    print(ans)


if __name__ == "__main__":
    main()
# Judge status: Accepted
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))
ans = []
for i in range(n):
    s = abs(a-(t-h[i]*0.006))
    ans.append([s,i+1])
ans.sort()
print(ans[0][1])
# Judge status: Accepted
p = []

for i in range(5):
    p.append(int(input()))

far = int(input())
res = True

for x in range(len(p)):
    for xx in range(x+1, len(p)):
        if p[xx] - p[x] > far:
            res = False

if res:
    print('Yay!')
else:
    print(':(')
# Judge status: Accepted
s = input()
l = [chr(ord('a') + i) for i in range(26)]
for i in l:
    if i not in s:
        print(i)
        exit()
print("None")
# Judge status: Accepted
n = int(input())
a = set(input().split())
print('YES' if len(a) == n else 'NO')
# Judge status: Accepted
N, A, B = map(int, input().split())
S = list(input())
a = 0 # 予選通過人数
b = 0 # 海外
for i in range(N):
    ans = 'No'
    if S[i] == 'a':
        if a < A + B:
            ans = 'Yes'
            a += 1
    elif S[i] == 'b':
        if a < A + B and b < B:
            ans = 'Yes'
            a += 1
            b += 1
    print(ans)
# Judge status: Accepted
K, X = [int(n) for n in input().split()]
print('Yes' if 500*K >= X else 'No')
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
b=sorted(a)
cnt=0
for i in range(n):
  if a[i]==b[i]:cnt+=1
if cnt>=n-3:print('YES')
else:print('NO')
# Judge status: Accepted
S = input()
T = input()
lenS = len(S)
lenT = len(T)

for i in range(lenS - lenT, -1, -1):
    flag = True
    for ii in range(lenT):
        if S[i+ii] == '?' or S[i+ii] == T[ii]:
            continue
        else:
            flag = False
            break
    if flag == True:
        print((S[:i] + T + S[i + lenT:]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')
# Judge status: Wrong Answer
def slove(n, m):
    if (m - n*2) >= 0:
        tmp = (m - n * 2) // 4 + n
    else:
        tmp = 0
    return tmp

if __name__ == "__main__":
    n, m = [int(i) for i in input().split()]
    print(slove(n, m))
# Judge status: Accepted
*s,a=map(int,input()+'000')
for i in range(len(s)-1):
  if s[i]>5or s[i]>4<s[i+1]:
    s[i+1]+=1
    a+=10-s[i]
  else:
    a+=s[i]
print(a)
# Judge status: Wrong Answer
n, k = map(int,input().split())
array = []
if k == 1:
    array.append(0)
else:
    for i in range(0,3):
        n = abs(n-k)
        array.append(n)
min_n = min(array)
print(min_n)
# Judge status: Accepted
mod=10**9+7
x=[0]+[0]
for i in range(1,2*10**5+10):
  x.append((x[-1]+i)%mod)

ans=0


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


for i in range(k,n+2):
  ans+=(i*(n+n+1-i)//2)-x[i]+1
  ans%=mod
  
print(ans)
# Judge status: Wrong Answer
from bisect import bisect

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

x=a[-1]
if n%2==0:
  mid=x//2
  if mid in a:
    print(x,mid)
  else:
    inx=bisect(a,mid)
    if a[inx]-mid>=mid-a[inx]:
      print(x,a[inx])
    else:
      print(x,a[inx-1])
else:
  mid=x//2+1
  if mid in a:
    print(x,mid)
  else:
    inx=bisect(a,mid)
    if a[inx]-mid>=mid-a[inx-1]:
      print(x,a[inx-1])
    else:
      print(x,a[inx])
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))

cnt = 0
for i in range(N):
    if (i+1) % 2 == 1 and a[i] % 2 == 1:
        cnt += 1

print(cnt)
# Judge status: Wrong Answer
# 154
 
S, T = input().split()
A, B = map(int, input().split())
U = input()
 
if len(U) == len(S):
    A -= 1
else:
    B -= 1
print(int(A),int(B))
# Judge status: Accepted
from collections import Counter
n,m=map(int,input().split())
d=Counter(list(map(int,input().split())))
for i in range(m):
    b,c=map(int,input().split())
    if c in d.keys():
        d[c]+=b
    else:
        d[c]=b
d=sorted(d.items(),reverse=True)
check=n
ans=0
for i in d:
    if i[1]<check:
        check-=i[1]
        ans+=(i[0]*i[1])
    else:
        ans+=(i[0]*check)
        print(ans)
        break
# Judge status: Accepted

l=list(map(int,input().split()))
l.sort()
print(l[2]*10+l[1]+l[0])
# Judge status: Accepted
a,b,x=map(int,input().split())
A=a//x
B=b//x
ans=B-A
if a%x==0:
    ans+=1
print(ans)
# Judge status: Wrong Answer
a, b, c = map(int, input().split())
K = int(input())

print(a + b + c * K)
# Judge status: Accepted
def main():
    n, a, b, c, d = map(int, input().split())
    s = input()
    r = 'Yes'
    if ('##' in s[a-1:c]) or ('##' in s[b-1:d]):
        r = 'No'
    else:
        if (c>d) and not ('...' in s[b-2:d+1]):
            r = 'No'
    print(r)

main()
# Judge status: Accepted
from math import ceil
H,W=map(int,input().split())

if (H!=1)and(W!=1):
    print(ceil((H*W)/2))
else:
    print("1")
# Judge status: Accepted
n=int(input())
b=list(map(int,input().split()))
a=[0]*n
a[0]=b[0]
for i in range(n-1):
  a[i+1]=b[i]
  if a[i]>b[i]:
    a[i]=b[i]

print(str(sum(a)))
# Judge status: Wrong Answer
s = [int(x) for x in input().split("/")]

if s[1] < 4:
  print("Heisei")
elif s[1] == 4 and s[2] < 30:
  print("Heisei")
else:
  print("TBD")
# Judge status: Wrong Answer
n = list(input())
m = list(input())

if n == m[0:-2]:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
N=int(input())
print(("ABD{}" if N//1000 else "ABC{}").format(((N-1)%999)+1))
# Judge status: Wrong Answer
x, y = map(int, input().split())

if x == y:
    ans = 0
elif x < y:
    ans = y - x
else:
    ans = x - y + 2
print(ans)
# Judge status: Accepted
N = int(input())
pro = 1
for i in range(1,N+1):
    pro = pro*i % (10**9+7)

print(pro)
# Judge status: Accepted
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    from collections import Counter
    c = Counter(A)
    li = [(k, v) for k, v in c.items() if v >= 2]
    li.sort(reverse=True)
    if li and li[0][1] >= 4:
        print(li[0][0] * li[0][0])
    elif len(li) <= 1:
        print(0)
    else:
        print(li[0][0] * li[1][0])


if __name__ == '__main__':
    main()
# Judge status: Accepted
print('YNeos'[len(set([0 if i==2 else [1,2][i in [4,6,9,11]] for i in list(map(int,input().split()))]))!=1::2])
# Judge status: Accepted
import math
N, D = map(int,input().split())
X = [list(map(int, input().split())) for _ in range(N)]

def check(i, j):
    dis = 0
    for k in range(D):
        dis += (X[i][k] - X[j][k])**2
    
    if int(math.sqrt(dis))**2 == dis:
        return 1
    else:
        return 0

ans = 0
for i in range(N):
    for j in range(i+1, N):
        ans += check(i, j)
print(ans)
# Judge status: Accepted
S = input()
T = input()
ls, lt = len(S), len(T)    

ans = 'UNRESTORABLE'
for i in range(ls-lt+1):
    for j in range(lt):
      if S[i+j] not in (T[j], '?'):
        break       
    else:
      ans = (S[:i]+T+S[i+lt:]).replace('?','a')
   
print(ans)
# Judge status: Accepted
#!/usr/bin/env python3
import heapq
n,m = map(int,input().split())
a = [-int(_) for _ in input().split()]
heapq.heapify(a)
ans = 0
for _ in range(m):
    min_ = heapq.heappop(a)
    min_ /= 2
    heapq.heappush(a,min_)
print(-sum(int(i) for i in a))
# Judge status: Wrong Answer
#ABC044B
n=input()
a=[]
for i in range(len(n)):
     a.append(n[i])
sum_=0
for i2 in range(len(a)):
    sum_=sum_+a.count(a[i2])%2

if sum_ == 0:
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
from fractions import gcd
n=int(input())
a=list(map(int,input().split()))
b=1
for i in a:
  b=gcd(b,i)
ans=0
for i in a:
  ans+=(b//i)
print(ans%(10**9+7))
# Judge status: Accepted
import math
N = int(input())

if N%2 == 0:
    print(1/2)
else:
    print(math.ceil(N/2)/N)
# Judge status: Wrong Answer
s = list(input())
K = int(input())
n = len(s)
for i in range(n-1):
    m = ord('z') - ord(s[i]) + 1
    if m <= K:
        s[i] = 'a'
        K -= m
s[n-1] = chr((ord(s[n-1])+K-97)%26+97)
print(''.join(s))
# Judge status: Accepted
A, B, X = list(map(int,input().split()))
if A <= X and A+B >= X:
    print('YES')
else:
    print('NO')
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
B = []
C = []

for _ in range(Q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

S = sum(A)
memory = [0] * 100001
for num in A:
    memory[num] += 1

for i in range(Q):
    S += (C[i] - B[i]) * memory[B[i]]
    print(S)
    memory[C[i]] += memory[B[i]]
    memory[B[i]] = 0
# Judge status: Accepted
import sys
n,m = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(m)]
a = ls[0][0]
b = ls[0][1]
for j in range(1,m):
    a = max(a,ls[j][0])
    b = min(b,ls[j][1])
    if b-a<0:
        print(0)
        sys.exit()
print(b-a+1)