peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
a, b, k = map(int, input().split())
s = []
for i in range(1, min(a, b) + 1):
	if a % i == 0 and b % i == 0:
		s.append(i)
print(s[len(s)-k])
# Judge status: Accepted
s = int(input())
l = []
l.append(s)

for i in range(10000000):

    if s%2 == 0:
        s //= 2

    else:
        s = s*3+1 

    if s in l:
        print(i+2)
        break

    l.append(s)
# Judge status: Accepted
n = int(input())
lst = list(map(int, input().split()))
print('Yes' if 2 * max(lst) < sum(lst) else 'No')
# Judge status: Accepted
import math as m
A,B,C,D=map(int,input().split())
A-=1
g=C*D//m.gcd(C,D)
x=B//C-A//C
y=B//D-A//D
z=B//g-A//g
print(B-A-x-y+z)
# Judge status: Accepted
N = int(input())
A = list(map(int,input().split()))
M = 1000
S = 0
for i in range(N-1):
  M+=S*A[i]
  S = 0
  if A[i+1]>=A[i]:
    tmp=M//A[i]
    M -= tmp*A[i]
    S+=tmp
M+=S*A[-1]
S = 0
print(M)
# Judge status: Accepted
N, K = map(int, input().split())
mod = N%K
gyaku = K-mod
print(min(mod, gyaku))
# Judge status: Accepted
s = str(input())
t = str(input())
L = []
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j] == '?' or s[i+j] == t[j]:
            continue
        else:
            break
    else:
        ns = s[:i] + t + s[i+len(t):]
        ns = ns.replace('?', 'a')
        L.append(ns)
L.sort()
if L:
    print(L[0])
else:
    print('UNRESTORABLE')
# Judge status: Accepted
S = input()

while 2 <= len(S):
    S = S[:len(S)-2]
    center = int(len(S)/2)

    if S[:center] == S[center:]:
        print(int(len(S)))
        break
# Judge status: Wrong Answer

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

xmin=(x[n-1]-x[0])*2

for i in range(n-k):
    x1=abs(x[i])+abs(x[i+k-1]-x[i])
    x2=abs(x[i+k-1])+abs(x[i+k-1]-x[i])
    xmin=min(xmin,x1,x2)

print(xmin)
# Judge status: Accepted
N = int(input())
L = [0]*(N+1)
L[0] = 2
L[1] = 1
for i in range(2,N+1):
  L[i] = L[i-1] + L[i-2]
print(L[N])
# Judge status: Wrong Answer
S,T=list(input().split())
A,B=list(map(int,input().split()))
U=input()
D=dict()
D[S]=A
D[T]=B
D[U]-=1
print(*list(D.values()))
# Judge status: Accepted
import math
import numpy as np
N,D = map(int,input().split())
X = np.array([list(map(int,input().split())) for n in range(N)])
ans = 0

for n in range(N):
  for m in range(N):
    d = 0
    for x,y in zip(X[n],X[m]):
      d += (x-y)**2
    if math.sqrt(d).is_integer() and d != 0:
      ans+=1
        
print(ans//2)
# Judge status: Accepted
k=int(int(input()))
a,b=map(int,input().split())
f=0
for i in range(a,b+1):
    if i%k==0:
        print("OK")
        f=1
        break
if f==0:
    print("NG")
# Judge status: Accepted
s = input()
t = input()
k = 0
for i in range(len(s)):
    x = s[i:] + s[:i]
    if x == t:
        k=1
        break
if k==1:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
A, B, C = map(int, input().split())

if A == B and B == C:
    print(-1)
elif A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    print(0)
else:
    step = 0
    while True:
        step += 1
        nA = B // 2 + C // 2
        nB = A // 2 + C // 2
        nC = A // 2 + B // 2
        A, B, C = nA, nB, nC
        if A % 2 != 0 or B % 2 != 0 or C % 2 != 0:
            print(step)
            break
# Judge status: Wrong Answer
S=input()
L=set(S)
print('Yes' if len(S)==len(L) else "No")
# Judge status: Accepted
n = input()

if n[0] == n[1] and n[1] == n[2]:
    print("Yes")
elif n[1] == n[2] and n[2] == n[3]:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
N, K = map(int, input().split())
D = list(map(int, input().split()))
available = [i for i in range(10) if i not in D]

values = available.copy()
idx = int(values[0] == 0)

while True:
  base = values[idx] * 10
  for a in available:
    n = base + a
    if n >= N:
      print(n)
      quit()
    values.append(n)
  idx += 1
# Judge status: Wrong Answer
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int, read().split()))

dic = {}
ans = 0

for i in range(n):
  ans += 1
  try:
    dic[a[i]] += 1
    if dic[a[i]] == a[i]:
      ans -= a[i]
  except KeyError:
    dic[a[i]] = 1
    if dic[a[i]] == a[i]:
      ans -= a[i]

print(dic)
print(ans)
# Judge status: Accepted
n=int(input())
l=[2,1]

for i in range(2,100):
    t=l[i-1]+l[i-2]
    l.append(t)

print(l[n])
# Judge status: Accepted
from collections import Counter
import sys
n = int(input())
a = Counter(list(map(int,input().split())))

lis = sorted(a.items(), key = lambda z: z[0], reverse = True)
ans = []
for i in lis:
    if len(ans) == 0 and i[1] >= 4:
        print(i[0]**2)
        sys.exit()
    elif i[1] >= 2 and len(ans) <= 1:
        ans.append(i[0])
    else:
        pass
if len(ans) == 2:
    print(ans[0] * ans[1])
else:
    print(0)
# Judge status: Wrong Answer
from collections import deque
s = input()
q = int(input())

s = deque(s)
t = 0
for _ in range(q):
  query = list(map(str, input().split()))
  if query[0] == "1": t = 1 - t
  else:
    if t == 0:
      if query[1] == "1": s.appendleft(query[2])
      elif query[1] == "2": s.append(query[2])
    elif t == 1:
      if query[1] == "1": s.append(query[2])
      elif query[1] == "2": s.appendleft(query[2])
if query[0] == "1":print("".join(s)[::-1])
else: print("".join(s))
# Judge status: Accepted
import bisect
N = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))
cnt = [0]*N
for i in range(N):
    cnt[i] = cnt[i-1] + bisect.bisect_left(A,B[i])
ans = 0
for i in range(N):
    target = bisect.bisect_left(B,C[i])
    if target > 0:
        ans += cnt[target-1]
print(ans)
# Judge status: Wrong Answer
q,h,s,d=map(int,input().split())
n=int(input())
 
l=min(q*n*8,h*n*4,s*n*2,d*n)
if l != d*n:
    print(l/2)
else:
    m=min(q*4,h*2,s)
    print((d*(n-1)/2)+m if n%2==1 else l/2)
# Judge status: Accepted
N, K = map(int, input().split())
S = list(input())
S[K-1] = S[K-1].lower()
print("".join(S))
# Judge status: Accepted
import math

n, d = map(int, input().split())
print(math.ceil(n / (d * 2 + 1)))
# Judge status: Wrong Answer
def main():
    S=input()
    K=int(input())
    for i in S:
        if i!='1':
            print(i)
            exit()
main()
# Judge status: Accepted
a,b,c = map(int,input().split())
if a+b >= c:
  print("Yes")
else:
  print("No")
# Judge status: Accepted
S = input()
if S == "Sunny":
  print("Cloudy")
elif S == "Cloudy":
  print("Rainy")
elif S == "Rainy":
  print("Sunny")
# Judge status: Accepted
n = int(input())
w = list(input() for _ in range(n))
ans = True
w2 = set(w)
if len(w) != len(w2):
    ans = False
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        ans = False
if ans:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
n = int(input())
s = [i for i in input()]

import collections
ans = 0
for i in range(1, n):
    #print(s[:i], s[i:])
    c1 = collections.Counter(s[:i])
    c2 = collections.Counter(s[i:])
    p = c1.keys() & c2.keys()
    #print(p)
    if len(p) > ans:
        ans = len(p)
print(ans)
# Judge status: Accepted
#!python3

# import numpy as np


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


def main():
    x = 4 * a * b
    y = c - a - b
    if y >= 0 and x < y ** 2:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()
# Judge status: Accepted
L = int(input())
l = L / 3

print(l ** 3)
# Judge status: Wrong Answer
N,K=map(int,input().split())
a=list(map(int,input().split()))
d=[0]*N
ans=0
for i in range(N):
    d[a[i]-1]+=1
d.sort(reverse=True)
if len(d)>K:
    ans =sum(d[K:-1])
print(ans)
# Judge status: Wrong Answer
s = input()
l = s.split()


count = 0

if l[0] != l[1]:
  count += 1
if l[1] != l[2]:
  count += 1
if l[2] != l[0]:
  count += 1
  
print(int(count/2))
# Judge status: Wrong Answer
n = input()
for i in range(1,25):
  for j in range(1,15):
    if i*4+j*7==n:
      print("Yes")
      exit()
print("No")
# Judge status: Wrong Answer
S, T = map(str, input().split())
print(S+T)
# Judge status: Accepted
N = int(input())
d = list(map(int, input().split()))
d.sort()
n = N // 2 -1
print(d[n+1] - d[n])
# Judge status: Accepted
n = int(input())
a = list(map(int, input().split()))
flag = True
count = 0
while 1:
    for i in range(n):
        if a[i] % 2 != 0:
            flag = False
            break
        a[i] /= 2
    if not flag:
        break
    count += 1
print(count)
# Judge status: Accepted
S = input()
s = set(S)

if len(S) == len(s):
    print("yes")
else:
    print("no")
# Judge status: Wrong Answer
n,a,b=map(int,input().split())
ca,cb=0,0
s=input()
for i in range(n):
    if s[i]=="a":
        if ca<a+b:
            print("Yes")
            ca+=1
    elif s[i]=="b":
        if ca<a+b and cb<b:
            print("Yes")
            ca+=1;cb+=1
        else: print("No")
    else: print("No")
# Judge status: Accepted
mod = 10**9+7

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

def comb(n, r):
    c = 1
    for i in range(r):
        c *= n-i
        c %= mod

    d = 1
    for i in range(1, r+1):
        d *= i
        d %= mod

    return (c * pow(d, mod-2, mod)) % mod

ans = pow(2, n, mod) - 1 - comb(n, a) - comb(n, b)

ans %= mod

print(ans)
# Judge status: Wrong Answer
n, x = map(int, input().split())
l = input().split()
for i in range(n):
    l[i] = int(l[i])

cnt = 1
sum = 0
for i in range(n):
    if sum > x:
        break
    sum += l[i]
    cnt += 1
    
print(cnt)
# Judge status: Wrong Answer
K,S=map(int,input().split())
ans=1
a=max(0,S-2*K)
for i in range(a,K+1):
  if i>S:
    break
  for j in range(a,K+1):
    if i+j>S :
      break
    if S-i+j<=K :
      ans+=1

print(ans)
# Judge status: Accepted
n = int(input())
s = input()
t = input()

for i in range(n, 2*n+1):
    if s[n - (2*n-i):] == t[:2*n-i]:
        print(i)
        exit()
# Judge status: Accepted
import math

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

ans = math.ceil((n-1)/(k-1))
print(ans)
# Judge status: Accepted
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = list(map(list, (zip(*AB))))
A = sorted(AB[0])
B = sorted(AB[1])
if N % 2 == 0:
    m = N // 2
    left = (A[m] + A[m-1])
    right = (B[m] + B[m-1])
    print(right - left + 1)
else :
    m = N // 2
    print((B[m] - A[m]) + 1)
# Judge status: Accepted
import math
N, D = map(int, input().split())
X = [[int(x) for x in input().split()] for i in range(N)]
count = 0
for i in range(N):
    for j in range(i+1, N):
        sum = 0
        for d in range(D):
            sum += pow(X[i][d]-X[j][d], 2)
        if math.sqrt(sum)%1==0:
            count += 1
print(count)
# Judge status: Wrong Answer
S = list(input())
S[3] = "8"
print(S[::])
# Judge status: Accepted
# 129 B-Balance
N = int(input())
W =list(map(int, input().split()))
ans = abs((W[0]-sum(W[1:N])))
for i in range(2,N):
    if abs(sum(W[0:i])-sum(W[i:N])) < ans:
        ans = abs(sum(W[0:i])-sum(W[i:N]))
print(ans)
# Judge status: Wrong Answer
input()
from collections import *
c=Counter(map(int,input().split()))
l=sorted(-k for k,v in c.items() if v>1)
print(0 if len(l)<2 else l[0]*l[1])
# Judge status: Wrong Answer
import math
a,b,x=map(int,input().split()) 
aa=min(0,2*a**2*b-2*x)
bb=a**3
print(math.degrees(math.atan2(aa,bb)))
# Judge status: Wrong Answer
def resolve():
	a, b = map(int, input().split())
	ans = 0
	for i in range(a, b):
		v = str(i)
		if v == v[::-1]:
			ans += 1
	print(ans)
resolve()
# Judge status: Wrong Answer
X,Y,Z=map(int,input().split())

for i in range(1,X):
  if (Y+Z)*i+Z > X:
    print(i)
    break
# Judge status: Wrong Answer
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
if len(A) == 1:
    print(min(A, B))
    exit()

m = A[-1]+A[-2]
i = 0
j = -2
while i != N*-1:
    i -= 1
    j -= 1
    if m > B[i]:
        m -= B[i]
        ans += B[i]
    else:
        ans += m
        m = 0
    try:
        m += A[j]
    except:
        break


print(ans)
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    A[i] = A[i] - i - 1

A = sorted(A)

if N % 2 == 1:
    m = A[N//2]
else:
    m = (A[N//2] + A[N//2 - 1]) // 2

ans = 0
for i in range(N):
    ans += abs(A[i] - m)

print(ans)
# Judge status: Accepted
N = int(input())

n = 0
for i in range(1, N+1):
    if i % 5 != 0 and i % 3 != 0:
        n += i
print(n)
# Judge status: Accepted
N, M = map(int, input().split())
mp1 = [input() for _ in range(N)]
mp2 = [input() for _ in range(M)]

for i in range(N-M+1):
  for j in range(N-M+1):
    f = 1
    for k in range(M):
      for l in range(M):
        if mp2[k][l] != mp1[i+k][j+l]:
          f = 0
          break
      if f == 0:
        break
    if f == 1:
      print('Yes')
      exit()
      
print('No')
# Judge status: Accepted
# input()
# int(input())
# map(int,input().split())
# list(map(int,input().split()))
# [input() for _ in range(n)]

import collections
import math

n = int(input())

c = collections.Counter()
i=2
nn = n
while nn!=1:
  #print(i)
  if i>math.sqrt(nn):
    c[nn]+=1
    break
  if nn%i==0:
    c[i]+=1
    nn = nn // i
  else:
    i += 1
#print(c)

ans = 0
for i in c.keys():
  j = 1
  while j<=c[i]:
    ans+=1
    c[i]-=j
    j+=1

if n==1:
  ans = 0

print(ans)
# Judge status: Accepted
A, V = list(map(int, input().split()))
B, W = list(map(int, input().split()))
T = int(input())


if V*T >= W*T+abs(B-A):
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
s = int(input())

tmp = s
MAX_m = 1000001
ans = [0] * MAX_m
for i in range(1, MAX_m):
    if tmp % 2 == 0:
        tmp /= 2
    else:
        tmp = 3*tmp + 1
    
    if tmp in ans:
        print(i+1)
        exit()
    else:
        ans[i] = tmp
# Judge status: Wrong Answer
import sys
N = int(input())
ans = 0
def dfs(n):
    print(n)
    if n == N:
        sys.exit()
    if n > N:
        return

    dfs(n+4)
    dfs(n+7)

dfs(0)
print('No')
# Judge status: Accepted
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import defaultdict

N = int(input())

def prime_factorize(n):
  ret = []
  for i in range(2, int(n ** (1 / 2)) + 1):
    if i > n:break
    while n % i == 0:
      n //= i
      ret.append(i)
  if n != 1:
    ret.append(n)
  return ret

dic = defaultdict(int)
lis = prime_factorize(N)
for num in lis:
    dic[num] += 1

ans = 0

for v in dic.values():
    i = 1
    while v >= i:
        v -= i
        i += 1   
    ans += i - 1
print(ans)
# Judge status: Accepted
n = sum(map(int, input()))
print(10 if n == 1 else n)
# Judge status: Accepted
s=input('')
t=input('')

c=0
b=0
for a in s:
    if a!=t[b]:
        c=c+1
    b=b+1

print(c)
# Judge status: Accepted
n, k = map(int, input().split())
a = [int(i) for i in input().split()]


lst = []
visit_now = 1
visit_list = [-1] * (n + 1)
cnt = 0

while visit_list[visit_now - 1] == -1:
    visit_list[visit_now - 1] = cnt
    lst.append(visit_now)
    visit_now = a[visit_now - 1]
    cnt += 1

start = visit_list[visit_now - 1]
loop_num = cnt - start

if k <= start:
    ans = lst[k]
else:
    k -= start
    k %= loop_num
    ans = lst[start + k]

print(ans)
# Judge status: Wrong Answer
N,K,Q = map(int,input().split())
A=[0]*Q
for i in range(Q):
    A[i]=int(input())

sanka=[0]*N
for i in range(Q):
    sanka[A[i]-1] +=1

for j in range(N):
    sanka[j]=sanka[j]+K-Q

print(sanka)

for k in range(N):
    if sanka[k]>=1:
        print('Yes')
    else:
        print('No')
# Judge status: Accepted
import math
n = int(input())

ans = (math.factorial(n)) % (10 ** 9 + 7)
print(ans)
# Judge status: Wrong Answer
from math import gcd

n, m = map(int, input().split())
print(gcd(*divmod(m, n)))
# Judge status: Wrong Answer
n = int(input())
s = [input() for i in range(n)]
s.sort(reverse=True)
l = set(s)
ms = len(s) - len(l)
if len(l) == 1:
    print(s[0])
    exit()
elif len(l) == n:
    s.sort()
    print("\n".join(s))
    exit()

ans = 0
ans_l = []
for i in l:
    sc = s.count(i)
    if sc > ans:
        ans_l = [i]
        ans = sc
    elif sc == ans:
        ans_l.append(i)
      
print("\n".join(ans_l))
# Judge status: Accepted
S = input()
mod = [0] * 2019
mod[0] = 1 
d = 1
n = 0
for i in reversed(S):
  n += int(i) * d
  n %= 2019
  d *= 10
  d %= 2019
  mod[n % 2019] += 1
ans = 0
for j in range(2019):
  ans += mod[j] * (mod[j] - 1) // 2
print(ans)
# Judge status: Accepted
n=int(input())
q=[]
for _ in range(n):
    d_1,d_2=map(int,input().split())
    if d_1==d_2:
        q.append(1)
    else:
        q.append(0)
for i in range(n-2):
    if q[i]==q[i+1]==q[i+2]==1:
        print("Yes")
        exit()
print("No")
# Judge status: Accepted
n, a, b, c, d = map(int, input().split())
s = input()
if "##" in s[min(a,b):max(c,d)]:
    print("No")
    exit()
if c < d:
    print("Yes")
else:
    if "..." in s[b-2:d+1]:
        print("Yes")
    else:
        print("No")
# Judge status: Accepted
n=int(input())
A=list(map(int,input().split()))
R=[0]*n
for a in A:
  R[a-1]+=1
for r in R:
  print(r)
# Judge status: Accepted
s = input()
n = len(s)
ans = 0
for i in range(n//2):
    if s[i] != s[n-1-i]:
        ans += 1
print(ans)
# Judge status: Accepted
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-TwoAnagrams.py
#
s = input()
t = input()

s_sorted = sorted(s)
t_sorted = sorted(t, reverse=True)

for i in range(min(len(s), len(t))):
    if s_sorted[i] == t_sorted[i]:
        continue
    elif ord(s_sorted[i]) < ord(t_sorted[i]):
        print("Yes")
        exit()
    else:
        print("No")
        exit()

if len(s) < len(t):
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
m, n, k = map(int, input().split())
l = []
for i in range(1,n+1):
    for j in range(1,n+1):
        l.append(i*m + j*n -2*i*j)

# print(l)

if k in l:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
n,m,k=map(int,input().split())
d1=k%n
d2=k%m
if d1==0 or d2==0:
  print('Yes')
elif d1==m or d2==n:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
alpha = input()
if alpha.isupper():
    print('A')
else:
    print('a')
# Judge status: Wrong Answer
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]
dics = Counter(sorted(s))

lists = dics.most_common()

print(lists[0][1])
maxc = lists[0][1]

for word,cnt in lists:
	if maxc == cnt:
		print(word)
# Judge status: Accepted
N,W=map(int,input().split())
listN=[[0 for i in range(W+1)] for k in range(N+1)]
for i in range(N):
  w,v=map(int,input().split())
  for k in range(1,W+1):
    if k>=w:
      listN[i+1][k]=max(listN[i][k],listN[i][k-w]+v)
    else:
      listN[i+1][k]=listN[i][k]     
ans=listN[N][W]
print(ans)
# Judge status: Accepted
N = int(input())
S = input()

cd = []
q = []
for s in S:
    if q and q[-1]=="(":
        if s==")":
            q.pop()
        else:
            q.append(s)
    else:
        q.append(s)
sl = []
sr = []
for s in q:
    if s==")":
        sl.append("(")
    else:
        sr.append(")")

print("".join(sl)+S+"".join(sr))
# Judge status: Accepted
X, Y, Z = map(int,input().split())
X, Y = Y, X
X, Z = Z, X
print(X,Y,Z)
# Judge status: Wrong Answer
n,q = [int(x) for x in input().split()]
s = input()

t = [0]*(n+1)
for i in range(n):
    t[i+1] = t[i] + (1 if s[i:i+2] == "AC" else 0)

print(t)
for _ in range(q):
    l,r = [int(x) for x in input().split()]
    print(t[r-1]-t[l-1])
# Judge status: Wrong Answer
string = input()

length = len(string)

result = ""

for l in range(0, length-1):
    if string[l] != 'B':
        if string[l+1] != 'B':
            result += string[l]

result += string[length-1]

print(result)
# Judge status: Wrong Answer
import itertools
N, M, Q = map(int, input().split())
a = [None for _ in range(Q)]
b = [None for _ in range(Q)]
c = [None for _ in range(Q)]
d = [None for _ in range(Q)]
for i in range(Q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

ans = 0
elements = list(range(1, M+1))
for combination in itertools.combinations_with_replacement(elements, N):
    score = 0
    for i in range(Q):
        print(combination, b[i], a[i])
        if combination[b[i]-1] - combination[a[i]-1] == c[i]:
            score += d[i]
    ans = max(score, ans)
print(ans)
# Judge status: Wrong Answer
# cording:utf-8

# xを入力
x = int(input())

# xが0なら
if x == 0:
    # 1を出力
    print("0")
elif x == 1:
    # 0を出力
    print("1")
# Judge status: Accepted
S = input()
s1,s2 = int(S[0:2]),int(S[2:4])

def f(n):
  if n >= 1 and n <= 12:
    return True
  else:
    return False

if f(s1) and f(s2):
  print("AMBIGUOUS")
elif f(s1) and (s2 > 12 or s2 ==0):
  print("MMYY")
elif f(s2) and (s1 > 12 or s1 ==0):
  print("YYMM")
else:
  print("NA")
# Judge status: Wrong Answer
from math import log
x = int(input())
y = round((log(x/100))/(log(1.01)))
print(y)
# Judge status: Accepted
a, b = map(int, input().split())
c = 1
ans = 0

while c < b:
    c += a-1
    ans += 1

print(ans)
# Judge status: Wrong Answer
N = int(input())

cnt = 0
for a in range(1,N):
  for b in range(1,N):
    str_a = str(a)
    str_b = str(b)
    if str_a[0] == str_b[-1] and str_b[0] == str_a[-1]:
      cnt += 1
      #print(a,b)
print(cnt)
# Judge status: Accepted
a, b, x = map(int, input().split())
if a%x == 0:
    print((b//x+1) - (a//x))
else:
    print((b//x+1) - (a//x+1))
# Judge status: Accepted
a,b,c=map(int,input().split())

print(max(0,c-(a-b)))
# Judge status: Accepted
n = input()
a = n.find("A")
z = n.rfind("Z")
print(z-a+1)
# Judge status: Wrong Answer
# C - Walk on Multiplication Table

N = int(input())
start = [1, 1]
end = [0, 0]
for i in range(1, int(N ** (1 / 2))):
    if N % i == 0:
        end[0] = i
        end[1] = N // i

print((end[0] - start[0]) + (end[1] - start[1]))
# Judge status: Wrong Answer
n=input()
p=input()
p=p.split()
q=[]
for i in range(len(p)):
    if min(p[:i+1])==p[i]:
        q.append(p[i])
print(len(q))
# Judge status: Wrong Answer
from fractions import gcd
import sys

N, X = map(int, input().split())
x = list(map(int, input().split()))
if N == 1:
    print(abs(x[0] - X))
    sys.exit()
x = list(map(lambda y: y - X, x))
x.append(0)
x.sort()
dif = list()
for i in range(N - 1):
    dif.append(x[i + 1] - x[i])
print(gcd(min(dif), max(dif)))
# Judge status: Wrong Answer

def check(dest,start):
    tmp = dest[1] - start[1] + dest[2] - start[2] - (dest[0] - start[0])
    if tmp <= 0 and tmp%2 == 0 :
        return True
    else:
        return False

n = int(input())
start = [0,0,0]
for i in range(n):
    dest = list(map(int, input().split()))
    if check(dest,start):
        start = dest
    else:
        print("No")
        exit()

print("Yes")
# Judge status: Wrong Answer
N = input()
S = input()

for A in range (int(N)-1):
    print(S.count(str(A+1),A,int(N)-2))
# Judge status: Wrong Answer
import sys
from heapq import heapify

def main():
    N,M = map(int, input().split())
    PY_input = []
    PY = [[] for i in range(N+1)]
    for _ in range(M):
        p, y = map(int, sys.stdin.readline().split())
        PY_input.append((p, y))
        PY[p].append(y)

    for i in PY:
        heapify(i)

    for p, y in PY_input:
        print("{:06}{:06}".format(p, PY[p].index(y)+1))



if __name__ == "__main__":
    main()
# Judge status: Wrong Answer
a, b, n = map(int, input().split())
 
ans = 0
for i in range(n):
  t = int(a * i / b) - a * int(i/b)
  if t > ans:
    ans = t

print(int(ans))
# Judge status: Accepted
N = int(input())
table = []
for i in range(N):
    X,L = map(int,input().split())
    table.append((X-L,X+L))
table = sorted(table, key=lambda x:x[1])

cur = 0
l_cur, r_cur = table[0]
ans = N
for i in range(1,N):
    l,r = table[i]
    if r_cur > l:
        ans -= 1
    else:
        l_cur, r_cur = l,r
print(ans)
# Judge status: Wrong Answer
W,H,x,y = list(map(int,input().split()))
M = W*H/2
ans = 0
if x == W//2 or y == H//2:
    ans = 1
if x == 0 or y == 0:
    ans = 0
print(M,ans)
# Judge status: Accepted
# coding: utf-8
import sys

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

N, M = lr()
L = 0; R = 10 ** 6
for _ in range(M):
    l, r = lr()
    if l > L:
        L = l
    if r < R:
        R = r

answer = max(0, R - L + 1)
print(answer)