peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
#067_C
n=int(input())
a=list(map(int,input().split()))
cs=[a[0] for _ in range(n)]
for i in range(n-1):
    cs[i+1]=cs[i]+a[i+1]
abs_cs=[abs(2*cs[i]-cs[-1]) for i in range(n-1)]
print(min(abs_cs))
# Judge status: Accepted
N=int(input())
a=list()
for _ in range(N):
  A,B=map(int,input().split())
  a.append((B,A))
a.sort()
t=0
for i in range(N):
  t+=a[i][1]
  if t>a[i][0]:
    print("No")
    exit()
print("Yes")
# Judge status: Accepted
n, m, x, y = map(int, input().split())
x_l = list(map(int, input().split()))
y_l = list(map(int, input().split()))

ans = 'War'
for z in range(x + 1, y + 1):
  if x < z <= y:
    if all([i < z for i in x_l]) and all([i >= z for i in y_l]):
      ans = 'No War'
      break

print(ans)
# Judge status: Accepted
from fractions import gcd

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

left = [0]*n
right= [0]*n

for i in range(n-1):
  left[i+1] = gcd(left[i],A[i])
  right[n-i-2] = gcd(right[n-i-1],A[n-i-1])

ans = 0
for i in range(n):
  ans = max(ans, gcd(left[i],right[i]))
print(ans)
# Judge status: Accepted

n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
print(-(-n // min(a, b, c, d, e)) + 4)
# Judge status: Accepted
n = int(input())
a = list(map(int,input().split()))
ans = True
for i in a:
  if i % 2 == 0:
    if not (i % 3 == 0 or i % 5 == 0):
      ans = False
      break
if ans:
  print('APPROVED')
else:
  print('DENIED')
# Judge status: Wrong Answer
import sys
s = int(input())
if not ( 1 <= s <= 100 ): sys.exit()
array = [s]

for I in range(1,10 ** 6 + 1):
    if array[ I - 1 ] % 2 == 0:
        if array[I - 1]//2 in array:
            print(I)
            sys.exit()
        array.append(array[(I - 1)]//2)     
    else:
        if (3 * array[I - 1]) + 1 in array:
            print(I)
            sys.exit()
        array.append((3 * array[(I - 1)]) + 1)
# Judge status: Wrong Answer
A, B, C, D = map(int, input().split())

if C//B > A//D or B >= C:
    print('Yes')
else:
    print('No')
# Judge status: Wrong Answer
a, b = map(int, input().split());
a_y = [];
b_y = [];

for i in range(2,114514):
  if a > 1:
    if a % i == 0:
      a = a // i;
      a_y.append(i);
  else:
    break;
    
for i in range(2,114514):
  if b > 1:
    if b % i == 0:
      b = b // i;
      b_y.append(i);
  else:
    break;

y = a_y + b_y;
y = list(set(y));

ans = 1;

for i in y:
  ans = ans * i;

print(ans)
# Judge status: Wrong Answer
n,k = map(int,input().split())
l = [list(map(int,input().split())) for i in range(n)]
l.sort()
count = 0
for i,j in l:
  if j < count:
    count += j
  else:
    print(i)
    exit()
# Judge status: Wrong Answer
a,b,c,d=input()
x=int(a+b)
y=int(c+d)
if 1<=x<=12 and 1<=y<=12:
  print('AMBIGUOUS')
elif 1<=x<=12 and 0<=y<=99:
  print('MMYY')
elif 0<=x<=99 and 1<=x<12:
  print('YYMM')
else:
  print('NA')
# Judge status: Wrong Answer
s = list(input())
s[3] = "8"
print(s)
# Judge status: Accepted
S = str(input())
if S[2] == S[3] and S[4] == S[5]:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
from fractions import gcd
A, B = map(int, input().split())
print(A*B/gcd(A, B))
# Judge status: Accepted
a='abcdefghijklmnopqrstuvwxyz'
al=[l for l in a]
s=input()
print(al[a.index(s)+1])
# Judge status: Wrong Answer
N = int(input())
number = []
for i in range(N):
    number.append(int(input()))
    
if N == 2:
    print(number[0])
    print(number[1])
    exit()
    
if N == 3:
    print(max(number[1:]))
    print(max(number[2:]))
    print(max(number[:2]))    
    exit()
    
print(max(number[1:]))
for i in range(1,N-1):
    max_low = max(number[:i])
    max_upp = max(number[i+1:])
    print(max(max_low,max_upp))
print(max(number[:-1]))
# Judge status: Accepted
# ABC155 C
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(str, input().split())
nl = lambda: list(map(int, input().split()))
from collections import defaultdict as dd
from operator import itemgetter
n=ni()
d=dd(int)
# s=[si() for i in range(n)]
for i in range(n):
    s=input()
    d[s]+=1

mv=0
for k,v in d.items():
    mv=max(mv,v)
ans=set()
for k,v in d.items():
    if mv==v:
        ans.add(k)
ans=list(ans)
ans.sort()
for aaa in ans:
    print(aaa)
# Judge status: Accepted
n, m = map(int, input().split())

if n % 2 == 1:
    for i in range(1, m+1):
        print(i, n-i)
else:
    for i in range(1, m+1):
        if (n - i - i) > (n // 2):
            print(i, n-i)
        else:
            print(i+1, n-i)
# Judge status: Wrong Answer
n = int(input())

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

A.sort()

sum=0
for i in range(n, n+n):
    sum+=A[i]
print(sum)
# Judge status: Wrong Answer
import math
X = int(input())
print(int(math.sqrt(X)))
# Judge status: Accepted
n=int(input())
max=0
for i in range(1,n+1):
    if i**2<=n:
        if i**2>max:
            max=i**2
    else:
        break
print(max)
# Judge status: Accepted
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if v==w:
    print('NO')
    exit()
c=abs(a-b)/(v-w)
print('YES' if 0<=c and c<=t else 'NO')
# Judge status: Accepted
import sys

stdin = sys.stdin

mod = 1000000007

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

ans = 0
for i in range(61):
	z, o = [0] * 2
	for j in range(n):
		if a[j] & (1 << i):
			o += 1
		else:
			z += 1
	ans += z * o * (2 ** i)
	ans %= mod

print(ans)
# Judge status: Wrong Answer
X,Y = map(int, input().split())
import math


if X != 1:
    tmp1 = math.floor(math.log((Y/X),2))
    print(tmp1 + 1)
if X == 1 :
    tmp2 = math.floor(math.log((Y/X),2))
    print(tmp2)
# Judge status: Wrong Answer
a,b,c = map(int,input().split())

if a != b != c:
    print(3)
if a == b and a != c and b != c: 
    print(2)
if b == c and b != a and c != a:
    print(2)
if a == c and a != b and c != b:
    print(2)
if a == b == c:
    print(1)
# Judge status: Accepted
n=int(input())
ans=0
i=2
while i*i<=n:
    cnt=0
    while n%i==0:
        n//=i
        cnt+=1
    j=0
    # print(i,cnt)
    for k in range(1,cnt+1):
        if (k*(k+1))//2<=cnt:
            j=max(j,k)
    ans+=j
    i+=1
# print('n',n)
if n>1:
    ans+=1
print(ans)
# Judge status: Accepted
from collections import defaultdict

w = list(input())

alphabet_count_dict = defaultdict(int)

for c in w:
    alphabet_count_dict[c] += 1

for k, v in alphabet_count_dict.items():
    if v % 2 == 1:
        print("No")
        exit()

print("Yes")
# Judge status: Accepted
n, m = map(int, input().split())
list_AB = [ list(map(int,input().split(" "))) for i in range(m)]
list_MAP = [0]*(n+1)

for l in list_AB:
    l.sort()
    if l[0] == 1:
        list_MAP[l[1]] += 1
    if l[1] == n:
        list_MAP[l[0]] += 1

ans = "IMPOSSIBLE"

for num in list_MAP:
    if num > 1:
        ans = "POSSIBLE"

print(ans)
# Judge status: Wrong Answer
s=input()
t = set(s)
if len(t) != 3:
    if len(t)==1:
        print("YES")
    else:
        print("NO")
else:
    a = s.count("a")
    b = s.count("b")
    c = s.count("c")
    M = max(a,b,c)
    m = min(a,b,c)
    if M - m >1 :
        print("NO")
    else:
        print("YES")
# Judge status: Accepted
n = int(input())
print((n - 1) * n // 2)
# Judge status: Wrong Answer
A, B = map(int, input().split())
print(A + B if A + B <= 24 else (A + B) % 24)
# Judge status: Accepted
x,y=map(int,input().split())
if 0<=x<y or x<y<=0:
    print(y-x)
elif 0<y<x or y<x<0:
    print(2+x-y)
elif x<0<y or y<0<x:
    print(1+abs(x+y))

if x==0 and y<0 :
    print(abs(y)+1)
if y==0 and x>0:
    print(x+1)
# Judge status: Wrong Answer
n, a, b = map(int, input().split())

if (b - a) % 2 == 0:
    print(int((b-a)/2))
else:
    print(min(a-1, n-b)+1+int((b-a-1)/2))
# Judge status: Wrong Answer
N=int(input())
S=input()
tmp=""
for i in range(len(S)):
  chtmp=ord(S[i])+N
  if(chtmp>ord('Z')):
    chtmp-=ord('A')
  tmp+=chr(chtmp)
print(tmp)
# Judge status: Accepted
def main():
    a, b = map(int, input().split())

    str_ba = str(b) * a
    str_ab = str(a) * b

    if str_ab > str_ba:
        print(str_ba)
    else:
        print(str_ab)


if __name__ == '__main__':
    main()
# Judge status: Accepted
import math
n=int(input())
l1=math.ceil(math.log(n,6))
l2=math.ceil(math.log(n,9))
dp=[i for i in range(n+1)]
for i in range(1,l1+1):
    for j in range(n):
        if j+6**i<n+1:
            dp[j+6**i]=min(dp[j]+1,dp[j+6**i])
for i in range(1,l1+1):
    for j in range(n):
        if j+9**i<n+1:
            dp[j+9**i]=min(dp[j]+1,dp[j+9**i])
print(dp[-1])
# Judge status: Wrong Answer
x,y=map(int,input().split())
if abs(x) == abs(y):
    print(1)
elif x>=0 and y >=0 and x<y:
    print(abs(x-y))
elif x>= 0 and y >= 0 and x>y:
    print(y+x+1)
elif x<=0 and y<=0 and x<y:
    print(y-x)
else:
    print(abs(x-y)+2)
# Judge status: Accepted
N,K = list(map(int,input().split()))

a=N//K

p=abs(N-a*K)
m=abs(N-(a+1)*K)

if p>m:
  print(m)
else:
  print(p)
# Judge status: Accepted
N = int(input())
C = [list(map(int,input().split())) for _ in range(N-1)]

for i in range(N-1):
    now = 0
    for j in range(i,N-1):
        now = max(C[j][1], -(-now//C[j][2])*C[j][2])
        now += C[j][0]
    print(now)
print(0)
# Judge status: Accepted
a, b, c = map(int, input().split())
if a % 2 == 1 and b % 2 == 1 and c % 2 == 1:
    print(a*b*c//max(a, b, c))
else:
    print(0)
# Judge status: Accepted
N = int(input())

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

A.sort(reverse=True)

gain = 0

n = 1
while n <= N-1:
  if n % 2:
    gain += A[(n-1)//2]
    # print(f'{n}, added {A[(n-1)//2]}')
  else:
    gain += A[(n+1)//2]
    # print(f'{n}, added {A[(n+1)//2]}')
  n += 1

print(gain)
# Judge status: Accepted
K = int(input())

#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

ans = 0
for i in range(1, K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      ans += gcd(gcd(i, j), k)

print(ans)
# Judge status: Accepted
N, K = map(int, input().split())
P = 0

for i in range(1, N+1):
    if i >= K:
        P += (N-i+1) / N
        break

    else:
        n = 1
        while i*n < K:
            n *= 2
        P += 1 / (N*n)


print(P)
# Judge status: Wrong Answer
s = input()
n = len(s)
dp = [0]*(n+1)
t = 0
for e,i in enumerate(s,1):
    if i=='<' :
        dp[e]=dp[e-1]+1
print(dp)
t = 0
for e in range(n-1,-1,-1):
    i = s[e]
    print(t)
    if i=='>' :
        dp[e]=max(dp[e],dp[e+1]+1)
# print(dp)
print(sum(dp))
# Judge status: Accepted
# coding: utf-8
# Your code here!
s = list(input())
Flg = True
if len(s) % 2 == 1:
    Flg = False
for i in range(len(s)-1):
    if i % 2 == 0:
        if s[i] == 'h' and s[i+1] == 'i':
            pass
        else:
            Flg = False
if Flg:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
n=input()
op_cnt=len(n)-1
for i in range(2**op_cnt):
  op=["-"]*op_cnt
  for j in range(op_cnt):
    if ((i>>j)&1):
      op[j]="+"
  formula=""
  for p_n, p_o in zip(n, op + [""]): 
      formula += (p_n + p_o)
  if eval(formula) == 7:
      print(formula + "=7")
      break
# Judge status: Accepted

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A, B = [], []
    for _ in range(N):
        a, b = ZZ()
        A.append(a)
        B.append(b)
    A.sort()
    B.sort()
    midA = A[N//2] if N%2 == 1 else (A[N//2-1] + A[N//2])
    midB = B[N//2] if N%2 == 1 else (B[N//2-1] + B[N//2])
    print(midB-midA+1)

    return

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer

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

T = []

for i in range(N):
  a, b = map(int, input().split())
  T.append((a, b))

T.sort(key=lambda x: (-x[1], -x[0]))

j = 0
ans = 0
for i in range(N):
  days, money = map(int, T[i])
  if j + days <= M:
    ans += money
    j += 1
  i += 1

print(ans)
# Judge status: Accepted
from sys import maxsize

n = int(input())
s = input()

count_e = [0]
count_w = [0]
for i in range(1, n+1):
    if s[i-1] == 'E':
        count_e.append(count_e[i-1]+1)
        count_w.append(count_w[i-1])
    else:
        count_e.append(count_e[i-1])
        count_w.append(count_w[i-1]+1)

min = maxsize
for i in range(n):
    val = count_w[i] + count_e[n] - count_e[i+1]
    if val < min:
        min = val

print(min)
# Judge status: Wrong Answer
N = int(input())
A = [0]*N
for i in range (N):
    A[i] = int(input()) 

max1 = 0
max2 = 0
for i in range (N):
    if A[i] >= max1:
        max1 = A[i]
    elif A[i] >= max2:
        max2 = A[i]

for i in range (N):
    if A[i] == max1:
        print(max2)
    else:
        print(max1)
# Judge status: Accepted
#!/usr/bin/env python3

def main():
    r = int(input())
    print(r * r)


main()
# Judge status: Accepted
a,b = map(int,input().split())
for i in range(1,10000):
  if int(i*0.08) == a and int(i*0.1) == b:
    print(i)
    break
else:
  print(-1)
# Judge status: Accepted
#ran time eerror
from collections import Counter 

d = int(input())
l = []
for k in range(d):
  r = input()
   
  l.append(Counter(r))

oi = l[0]

for g in range(1,d):
    oi = oi & l[g]
    
    
print("".join(sorted(oi.elements())))
# Judge status: Wrong Answer
a,b = map(int,input().split())
div = 10e9+7

if abs(a-b)>1:
    print(0)
else:
    print(a*b*2//div)
# Judge status: Accepted
# -*- coding: utf-8 -*-

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

h = list(map(int, input().split()))

s = set()

for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] == h[b-1]:
        s.add(a)
        s.add(b)
    elif h[a-1] > h[b-1]:
        s.add(b)
    else:
        s.add(a)

print(n-len(s))
# Judge status: Accepted
n, k, s = map(int, input().split())
if s == 10**9:
    print(*([10**9] * k + [1] * (n - k)))
else:
    print(*([s] * k + [10**9] * (n - k)))
# Judge status: Accepted
n=int(input())
R=[]
for i in range(n):
  s,p=input().split()
  R.append([s,100-int(p),i+1])
R.sort()
for r in R:
  print(r[2])
# Judge status: Accepted
N = int(input())
T, X, Y = 0, 0, 0

can_reach = True
for i in range(N):
  next_T, next_X, next_Y = map(int, input().split())
  
  z = next_T - T - abs(X - next_X) - abs(Y - next_Y)
  if z >= 0 and z % 2 == 0:
    T, X, Y = next_T, next_X, next_Y
  else:
    can_reach = False
    break
    
if can_reach:
  print('Yes')
else:
  print('No')
# Judge status: Accepted
l,r,d=map(int, input().split()) #a1 a2 a3

ans=0
for i in range(l,r+1):
  if i%d==0:
    ans+=1
print(ans)
# Judge status: Accepted
n,m = map(int,input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
ans = "No"
for i in range(n-m+1):
    for j in range(n-m+1):
        flag = True
        for k in range(m):
            if a[i+k][j:j+m]!=b[k]:
                flag = False
                break
        if flag:
            ans = "Yes"
            break
print(ans)
# Judge status: Accepted
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1) * (-tmp_min // 2))

print(-sum(a))
# Judge status: Accepted
N,M=map(int,input().split())
a=list(map(int,input().split()))
lst=[]
for i in range(M):
  b=list(map(int,input().split()))
  if a[b[0]-1]>a[b[1]-1]:
    lst.append(b[1])
  elif a[b[0]-1]==a[b[1]-1]:
    lst.append(b[0])
    lst.append(b[1])
  else:
    lst.append(b[0])
print(N-len(set(lst)))
# Judge status: Wrong Answer
def iroha():
    a, b, c = map(int, input().split())
    if a == b == c:
        print(1)
    elif a != b != c:
        print(3)
    else:
        print(2)

if __name__ == "__main__":
    iroha()
# Judge status: Wrong Answer
s = input()+"2"
k = int(input())

for i,j in enumerate(s):
    if j != "1":
        now = i
        break

if s == "1"*len(s):
    print(1)
else:
    if k < now:
        print(1)
    else:
        print(s[now])
# Judge status: Accepted
N = int(input())
A = list(map(int, input().split()))

li = []

for i in range(N-1):
    if A[i+1] - A[i] > 0:
       li.append('+')
    elif A[i+1] - A[i] < 0:
        li.append('-')
    else:
        pass
# print(li)
ans = 1
p = 0
m = 0
for i in li:
    if i == '+':
        p = 1
    elif i == '-':
        m = 1
    if p == 1 & m == 1:
        ans += 1
        p = 0
        m = 0
print(ans)
# Judge status: Accepted
n = input()
n = n[::-1]
n += '0'
cnt = 0
dp = [[float('inf')] * 2 for _ in range(len(n) + 1)]
dp[0][0] = 0
dp[0][1] = 1
for i in range(len(n)):
    a = int(n[i])
    dp[i + 1][0] = min(dp[i][0] + a, dp[i][1] + a + 1)
    dp[i + 1][1] = min(dp[i][0] + 10 - a, dp[i][1] + 10 - (a + 1))
print(min(dp[len(n)][0], dp[len(n)][1]))
# Judge status: Wrong Answer
s = input()
print('2017'+s[4:])
# Judge status: Accepted
import math
n,d = map(int,input().split())
print(math.ceil(n/(d*2+1)))
# Judge status: Accepted
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
gross_vote = sum(A)
A_pop = [i for i in A if i>=gross_vote/4/M]
if len(A_pop)>=M:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import sys
input = sys.stdin.readline

n = int(input())

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

c = [0] * (10**6+1)
for i in a:
    c[i] += 1

uni = []
a = list(set(a))

for i in a:
    if c[i] == 1:
        uni.append(i)

b = [0 for _ in range(10**6+1)]

for i in a:
    for j in range(i*2, 10**6+1, i):
        b[j] = 1

cnt = 0
for i in uni:
    if b[i] == 0:
        cnt += 1

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

sum_list = sum(A_list)
n = sum_list*0.25*M

a = 0
for i in A_list:
    if i>=n:
        a+=1

if a>=M:
    print('Yes')
else:
    print('Yes')
# Judge status: Wrong Answer
a,b=list(map(int,input().split()))
print(a,b)
# Judge status: Accepted
M,a =-float("inf"),0
for X,L in sorted(zip(*[iter(map(int,open(0).read().split()[1:]))]*2),key=sum):
 l,r=X-L,X+L
 if M<=l:a+=1;M=r
print(a)
# Judge status: Wrong Answer
n=int(input())
d=list(map(int,input().split()))
ans=0
for k in range(max(d)):
    dn=0
    for i in d:
        if i<k:
            dn+=1
        else:
            pass
    if dn==len(d)/2:
        ans+=1
print(ans)
# Judge status: Wrong Answer
s = input()
ans = 0
flg = 0
for i in range(len(s)):
  if s[i] == 'A' and flg == 0:
    ans += 1
    flg = 1
  elif flg == 1 and s[i] == 'Z':
    flg = 2
    ans += 1
  elif flg == 1:
    ans += 1
print(ans)
# Judge status: Accepted
I = list(map(int, open(0).read().split()))
print("Yay!" if I[4] - I[0] <= I[5] else ":(")
# Judge status: Accepted
N = int(input())
T, A = map(int, input().split())
list1 = []
H = list(map(int, input().split()))
X = [abs(T-h*0.006-A) for h in H]
print(X.index(min(X))+1)
# Judge status: Accepted
s=  input()
print(s[:3] + '8' + s[4:])
# Judge status: Accepted
O = input()
E = input()
for o, e in zip(O, E):
    print(o, e, end='', sep='')
if len(O) != len(E):
    print(O[-1])
# Judge status: Wrong Answer
import math

a,b = map(int, input().split())
n= math.floor(math.log2(b/a))
print(n+1)
# Judge status: Accepted
from fractions import gcd
import math

def test(a,b):
  x = gcd(a,b)
  s = []
  for i in range(2, int(math.sqrt(x)) + 1):
    while x % i == 0:
      s.append(i)
      x //= i

  s.append(x)
  s.append(1)

  return list(set(s))

def main():

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

  num = []

  num = test(a, b)
  print(len(num))

if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
s = list(input())
t = list(input())
for i in range(len(s)):
    if s == t:
        print('Yes')
        exit(0)
    a = s[-1]
    s.pop(0)
    s.append(a)
print('No')
# Judge status: Accepted
a,b,c,d = map(int,input().split())
while a > 0 and c > 0:
    a -= d
    c -= b
if c <= 0:
    print('Yes')
else:
    print('No')
# Judge status: Accepted
passw = input()
if passw[0] == passw[1] or passw[1] == passw[2] or passw[2] == passw[3]: print("Bad")
else: print("Good")
# Judge status: Accepted
# -*- coding: utf-8 -*-
n=int(input())
namelist=[]
name=''
while n>0:
  n-=1
  namelist.append(chr(ord('a')+n%26))
  n=int(n/26)
for i in namelist[::-1]:
  name+=i
print(name)
# Judge status: Wrong Answer
a,b,c=map(int,input().split())
print(max([10*a+b,a+10*b,10*b+c,b+10*c,10*a+c,a+10*c]))
# Judge status: Wrong Answer
A,B,N= list(map(int, input().split()))
print(min(B-1,N))
# Judge status: Accepted
from collections import*
a=deque([1,2,3,4,5,6,7,8,9])
k=int(input())
for _ in range(k):
  i=a.popleft()
  if i%10>0:a.append(10*i+i%10-1)
  a.append(10*i+i%10)
  if i%10<9:a.append(10*i+i%10+1)
print(i)
# Judge status: Wrong Answer
n, x, y = map(int, input().split())

def count(k, n):
  counter = 0
  for i in range(1, n):
    for j in range(i+1, n+1):
      if i <= x and y <= j:
        if k == ((j - i) - (y - x) + 1):
          counter += 1
      else:
        if k == (j - i):
          counter += 1
  return counter

def main():
  for k in range(1, n):
    print(count(k, n))
    
if __name__ == '__main__':
  main()
# Judge status: Wrong Answer
n=int(input())

list=[]
for i in range(n):
 x,l=map(int,input().split())
 list.append([x-l+1,x+l-1])
list=sorted(list,key=lambda x:x[1])

cnt=0
min=-10**10
for r,l in list:
 if min<r:
  cnt+=1
  min=l
print(cnt)
# Judge status: Accepted
N, A, B = map(int, input().split()) 
how_many = N // (A+B)
r = N % (A+B)
if r >= A:
    print(A*how_many + A)
else:
    print(A*how_many + r)
# Judge status: Wrong Answer
n, k =map(int, input().split())
a = list(map(int, input().split()))
if n == k:
    print(1)
elif k == 2:
    print(n - 1)
else:
    print(int(n / (k - 1)))
# Judge status: Accepted
n = int(input())
p = [int(i) for i in input().split()]
i = 0
ans = 0
while i < n:
    if i < n - 1:
        if p[i] == i + 1:
            p[i], p[i+1] = p[i+1], p[i]
            ans += 1
    elif p[i] == i + 1:
        ans += 1
    i += 1
print(ans)
# Judge status: Accepted
S = input()
T = input()
count = 0

for i in range(len(S)):
  if S[i] != T[i]:
    count += 1

print(count)
# Judge status: Wrong Answer
n = int(input())
price = n *25 / 27
p = price.is_integer()
if p == True:
    print(price // 1)
elif p == False:
    print(":(")
# Judge status: Accepted
# -*- coding: utf-8 -*-
n = int(input())
s = input()

x = [0 for _ in range(n + 1)]
for i in range(n):
    if s[i] == 'I':
        x[i + 1] = x[i] + 1 
    else:
        x[i + 1] = x[i] - 1
print(max(x))
# Judge status: Accepted
A, B = map(int, input().split())

if max(A, B) > 8:
  print(':(')
else:
  print('Yay!')
# Judge status: Accepted
n = int(input())
p = list(map(int,input().split()))
ans = 0
for j in range(n-2):
	if p[j] < p[j+1] < p[j+2] or p[j+2] < p[j+1] < p[j]:
		ans += 1
print(ans)
# Judge status: Accepted
s = input().split('/')
if int(s[0]) >= 2020:
    print('TBD')
elif int(s[0]) == 2019 and int(s[1]) >= 5:
    print('TBD')
else:
    print('Heisei')
# Judge status: Wrong Answer
n = int(input())
W = list(map(int,input().split()))
ans = sum(W)
for t in range(1,100):
  x = 0
  y = 0
  for w in W:
    if w<=t:
      x+=w
    else:
      y+=w
  ans = min(ans,abs(x-y))
print(ans)
# Judge status: Accepted
import re
print(len(max("".join(re.sub(r"[^ATCG]", " ", input())).split(" "), key=lambda x: len(x))))
# Judge status: Wrong Answer
from numpy import *;i=int32;q=searchsorted;n,*x=map(int,open(0).read().split());A,B,c=i(x[:n]),i(x[n:]),0;
for k in range(1,30):
  a,b=sort(hstack((A%(1<<k),A%(1<<k)-2**k))),B%(1<<k);c+=(sum(q(a,2**k-b)-q(a,2**(k-1)-b)))%2<<k-1
print(c)
# Judge status: Accepted
s = input()
if s[len(s)-1] == 's':
    print(s+'es')
else:
    print(s+'s')
# Judge status: Wrong Answer
import math
n,d=map(int,input().split())
l=[]
ans=0
cnt=0
for i in range(n):
    l.append(list(map(int,input().split())))

for i in range (n-1):
    for j in range(d):
        ans+=((l[i][j])-(l[i+1][j]))**2
    if float.is_integer(math.sqrt(ans))==True:
        cnt+=1
print(cnt)
# Judge status: Accepted
x,y=map(int,input().split())

tei=x*2
kou=x*4

if y%2==0 and tei<=y and kou>=y:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
S = input()
if S[5:7] == "12>=5":
  print("TBD")
else:
  print("Heisei")
# Judge status: Wrong Answer
s = input()
ans=0
for i in range(len(s)//2):
    if s[i] != s[-i]:
        ans+=1

print(ans)
# Judge status: Accepted
#

import sys
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    print(min(N%K, abs(K-N%K)))
    
    
    
if __name__=="__main__":
    main()