Harryxun/stf_run huggingface dataset:
N=int(input())
a=list(map(int,input().split()))
def u(x,y):
    if x%y==0:
        return y
    else:
        return u(y,x&y)
b=list(range(N-1))
for i in range(1,N):
    b[i-1]=u(a[i-1],a[i])
print(int(b[N-2]))

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
def u(x,y):
    if x%y==0:
        return y
    else:
        return u(y,x%y)
b=list(range(N))
b[0]=a[0]
for i in range(1,N):
    b[i]=u(b[i-1],a[i])
print(int(b[N-1]))
N = int(input())
S = input()
for i in S:
	m = (ord(i) - ord('A') + N) % 26
    ans += chr(m +ord('A'))
print(ans)

### FIXED CODE ###

N = int(input())
S = input()
ans = str()
for i in S:
	m = (ord(i) - ord('A') + N) % 26
	ans += chr(m + ord('A'))
print(ans)
S = input()
K = int(input())
firstNot1 = [i for i in range(len(S)) if S[i] != '1'][0]

print('1' if firstNot1 >= K else S[firstNot1])


### FIXED CODE ###

S = input()
K = int(input())
firstNot1 = ([i for i in range(len(S)) if S[i] != '1'] + [len(S)])[0]

print('1' if firstNot1 >= K else S[firstNot1])
N, M = map(int, input().split())
s = []
for i in range(M):
    s.append(list(map(int, input().split())))
p = list(map(int, input().split()))

switch = [['0'], ['1']]

for i in range(N-1):
    tmp = []
    for j in switch:
        tmp.append(j+['0'])
        tmp.append(j+['1'])
    switch = tmp #スイッチのonoffのマップ化

ans = 0

for i in switch:
    false = 0
    for j in range(M):
        cnt = 0 #onの個数
        for k in range(s[j][0]):
            if i[s[j][1+k]-1] == '1':
                cnt += 1
            if cnt%2 != p[j]:
                false += 1 #条件に合っていなかったらfalseに加算する
        if false == 0:
            ans += 1 #全て条件を満たしていたらansに加算する
print(ans)

### FIXED CODE ###

a, p = map(int, input().split())
print((3*a+p)//2)
S = input()
T = input()
if S == T:
    print("Yes")
    exit()
for i in range(N):
    S = S[-1] + S[0 : len(S) - 1]
    if S == T:
        print("Yes")
        exit()
print("No")


### FIXED CODE ###

N = input()
if int(N) % sum([int(N[i]) for i in range(len(N))]) == 0:
    print("Yes")
else:
    print("No")
import numpy as np
from numba import jit
@jit
def main():
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    A=np.array(a)
    l,r=0,0
    for i in range(min(41,k)):
        B=np.zeros(n+1,dtype=np.int64)
        for x,y in enumerate(list(A)):
            l=max(0,x-y)
            r=min(n,x+y+1)
            B[l]+=1
            B[r]-=1
        A=np.cumsum(B[:-1])
    print(*A,sep=' ')

if __name__ == '__main__':
    main()

### FIXED CODE ###

import numpy as np
from numba import jit
@jit(cache = True)
def solve(n,k,A):
    l,r=0,0
    for i in range(k):
        B=np.zeros(n+1,dtype=np.int64)
        for x,y in enumerate(list(A)):
            l=max(0,x-y)
            r=min(n,x+y+1)
            B[l]+=1
            B[r]-=1
        A=np.cumsum(B[:-1])
        if A[A==n].size==n:
            break
    return A
n,k=map(int,input().split())
a=list(map(int,input().split()))
A=np.array(a)
X=solve(n,k,A)
print(*X,sep=' ')
X, Y, Z = map(int, input().split())
print(f"{Z} {X} {Y}")


### FIXED CODE ###

X, Y, Z = map(int, input().split())
print(Z, X, Y)
# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

MOD = 10**9+7


def solve3():
    L = input()[:-1]
    # dp[smaller?][上からi桁目まで見た] = 何通りあるか?
    dp = [0]*2
    dp[0] = 1  # 0

    for i, c in enumerate(L):
        tmp = [0]*2
        tmp[0] = dp[0]*(int(c)+1)
        tmp[1] = dp[1]*3+dp[0]*int(c)

        tmp[0] %= MOD
        tmp[1] %= MOD
        dp = tmp
    print(sum(dp[-1]) % MOD)


solve3()


### FIXED CODE ###

# -*- coding: utf-8 -*-
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

MOD = 10**9+7


def solve2():
    L = input()[:-1]
    int_L = int(L, 2)
    ans = 1  # (0,0)のぶん
    for l in range(1, int_L+1):  # 10**6
        bit_cnt = bin(l).count("1")  # 遅そうO(len(bin(l)))
        ans += pow(2, bit_cnt, MOD)
        ans %= MOD
    print(ans)


def solve3():
    L = input()[:-1]
    # dp[smaller?][上からi桁目まで見た] = 何通りあるか?
    dp = [[0]*2 for _ in range(len(L)+1)]
    dp[0][0] = 1  # 0

    for i, c in enumerate(L):
        dp[i+1][0] = dp[i][0]*(int(c)+1)
        dp[i+1][1] = dp[i][1]*3+dp[i][0]*int(c)

        dp[i+1][0] %= MOD
        dp[i+1][1] %= MOD
    print(sum(dp[-1]) % MOD)


solve3()
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A.sort()
B.sort()
C.sort()
ans = 0
for i in range(N):
    for j in range(N):
        if A[i] < B[j]:
            for k in range(N):
                if B[j] < C[N-1-k]:
                    ans += 1
                else:
                    break
print(ans)

### FIXED CODE ###

N = int(input())
ans = 0
for i in range(100000):
    if i**2 <= N:
        ans = i**2
print(ans)
from fractions import gcd
N, M = map(int, input().split())
S = input()
T = input()
gcd_ = gcd(N, M)
lcm = N * M // gcd_
s_ = lcm//N
t_ = lcm // M

X = ["0"] * (lcm*2)
for i in range(N):
    #print(i, i * s_)
    X[i * s_] = S[i]
ans = True
for i in range(M):
    if X[i * t_] != "0" and T[i] != X[i * t_]:
        ans = False
        break
    else:
        X[i * t_] = T[i]
if ans:
    print(lcm)
else:
    print("-1")
"""
ans = True
if gcd_ != 1:
    for i in range(gcd_):
        # print(i)
        if S[s_ * i] != T[t_ * i]:
            ans = False
            # break
if ans:
    print(lcm)
else:
    print(-1)
"""


### FIXED CODE ###

#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,M=MI()
    S=ST()
    T=ST()
    lcm = N*M//(gcd(N,M))
    ans = defaultdict(str)
    for i,s in enumerate(S):
        ans[i*lcm//N] = s
    for i,t in enumerate(T):
        if(ans[i*lcm//M] not in (t,"")):
            print(-1)
            return 
    print(lcm)
if __name__ == '__main__':
    main()
n,m = map(int,input().split())
a =list(map(int,input().split()))
b = sorted(a,reverse='True')n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
b = sorted(a,reverse=True)
c = sum(a)
if(b[m-1]>=c/(4*m)):
  print('Yes')
else:
  print("No")

### FIXED CODE ###

n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [0]*n
b = sorted(a,reverse=True)
c = sum(a)
if(b[m-1]>=c/(4*m)):
  print('Yes')
else:
  print("No")
N, M, X, Y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

if X < max(xlist):
    xmax = max(xlist)
else:
    xmax = X

if Y > min(ylist):
    ymax = min(ylist)
else:
    ymin = Y

if xmax + 1 <= ymin:
    print("No War")
else:
    print("War")

### FIXED CODE ###

N, M, X, Y = map(int, input().split())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))

if X < max(xlist):
    xmax = max(xlist)
else:
    xmax = X

if Y > min(ylist):
    ymin = min(ylist)
else:
    ymin = Y

if xmax + 1 <= ymin:
    print("No War")
else:
    print("War")
a = [input() for i in range(2)]
b = a[1]
x = int(max(b))-int(min(b))
print(x)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
A.sort()
print(abs(A[0]-A[-1]))
while True:
    table = input()
    if table[0] == 0:
        break
    print(sum(table))



### FIXED CODE ###

while True:
  x = sum(map(int, input()))

  if x == 0:
    break

  print(x)
A, B = map(input().split())

ans = 0
for i in range(2):
    if A >= B:
        ans += A
        A -= 1
    else:
        ans += B
        B -= 1
print(ans)

### FIXED CODE ###

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

ans = 0
for i in range(2):
    if A >= B:
        ans += A
        A -= 1
    else:
        ans += B
        B -= 1
print(ans)
input_datainput()

a=input_data[0]
b=input_data[1]
c=input_data[2]
d=input_data[3]

if a==b :
    if c==d and a!=c :
            output="yes"
    
else :
        if a==c and b==d :
            output="yes"
    
        elif a==d and b==c :
            output="yes"
        
        else :
            output="no"
        
print(output)

### FIXED CODE ###

input_data=input()
 
a=input_data[0]
b=input_data[1]
c=input_data[2]
d=input_data[3]
 
if a==b :
    if c==d and a!=c :
            output="Yes"
    else :
        output="No"
    
else :
        if a==c and b==d :
            output="Yes"
    
        elif a==d and b==c :
            output="Yes"
        
        else :
            output="No"
           
print(output)
import sys
input=sys.stdin.readline
a,b=int(input())
if (a+b)%2==0:
  print((a+b)/2)
else:
  print('impossible')


### FIXED CODE ###

a,b=map(int, input().split())
print (int((a+b)/2) if (a+b)%2 == 0 else "IMPOSSIBLE")
import bisect
from collections import deque

n = int(input())
lis = deque()

ans = 0
for i in range(n):
    a = int(input())
    if i == 0:
        lis.append(a)
        continue
    l = bisect.bisect_left(lis,a)
    r = bisect.bisect_right(lis,a)
    if l != r and l != 0:#同じものがある&更新できる色がないなら追加
        lis.insert(r,a)
        
    elif l == 0:#最小値追加
        lis.appendleft(a)
    else:#最大値更新
        lis[r-1] = a
print(len(lis))

### FIXED CODE ###

import bisect
from collections import deque

n = int(input())
lis = deque()

ans = 0
for i in range(n):
    a = int(input())
    if i == 0:
        lis.append(a)
        continue
    l = bisect.bisect_left(lis,a)
    r = bisect.bisect_right(lis,a)
    if l != r :#同じものがある
        if l > 0:#他の色の最大値が上書きできる
            lis[l-1]=a
        elif r ==  len(lis):#全部の色の最大値とaが同じなら追加
            lis.append(a)
        else:#どこかの中に挿入
            lis.appendleft(a)
    elif l == 0:#最小値追加
        lis.appendleft(a)
    else:#最大値更新
        lis[r-1] = a
print(len(lis))
l = input().split()

if l[0]==l[1]:
    return "H"
else:
    return "D"

### FIXED CODE ###

l = raw_input().split(" ")

if l[0]==l[1]:
    print "H"
else:
    print "D"
import sys
sys.setrecursionlimit(10**6)

def main():
    H,W = map(int, input().split())

    S = ["" for _ in range(H)]
    for i in range(H):
        S[i] = input()

    INF = float("inf")
    dp = [[INF for _ in range(H*W)] for _ in range(H*W)]

    for i in range(H):
        for j in range(W):
            
            if j != W-1 and S[i][j] == "." and S[i][j+1] == ".":
                dp[(H*i)+j][(H*i)+j+1] = 1
                dp[(H*i)+j+1][(H*i)+j] = 1

            if i != H-1 and S[i][j] == "." and S[i+1][j] == ".":
                dp[(H*i)+j][(H*(i+1))+j] = 1
                dp[(H*(i+1))+j][(H*i)+j] = 1
        
            dp[(H*i)+j][(H*i)+j] = 0


    N = H*W
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

    ans = 0
    for i in range(N):
        for j in range(N):
            if dp[i][j] != INF:
                ans = max(ans, dp[i][j])
    
    print(ans)

if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

def main():
    H,W = map(int, input().split())

    S = ["" for _ in range(H)]
    for i in range(H):
        S[i] = input()

    INF = float("inf")
    N = H*W
    dp = [[INF for _ in range(N)] for _ in range(N)]

    for i in range(H):
        for j in range(W):
            
            if j != W-1 and S[i][j] == "." and S[i][j+1] == ".":
                dp[(W*i)+j][(W*i)+j+1] = 1
                dp[(W*i)+j+1][(W*i)+j] = 1

            if i != H-1 and S[i][j] == "." and S[i+1][j] == ".":

                dp[(W*i)+j][(W*(i+1))+j] = 1
                dp[(W*(i+1))+j][(W*i)+j] = 1
        
            dp[(W*i)+j][(W*i)+j] = 0


    N = H*W
    for k in range(N):
        for i in range(N):
            for j in range(N):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])

    ans = 0
    for i in range(N):
        for j in range(N):
            if dp[i][j] != INF:
                ans = max(ans, dp[i][j])
    
    print(ans)

if __name__ == "__main__":
    main()
N = int(input())
L = [2, 1]
for i in range(2, N+1):
    l = L[i-1] + L[i - 2]
    L.append(l)
print(l)

### FIXED CODE ###

N = int(input())
L = [2, 1]
for i in range(2, N+1):
    l = L[i-1] + L[i - 2]
    L.append(l)
print(L[N])
try:
	X= int(input())
  	if(X>=400 and X<=599):
    	print(8)
  	elif(X>599 and X<800):
    	print(7)
    elif(X>=800 and X<1000):
      	print(6)
    elif(X>=1000 and X<1200):
      	print(5)
    elif(X>=1200 and X<1400):
      	print(4)
    elif(X>=1400 and X<1600):
      	print(3)
    elif(X>=1600 and X<1800):
      	print(2)
    elif(X>=1800 and X<2000):
      	print(1)
except EOFError as e:
  print("")

### FIXED CODE ###

X= int(input())
if(X>=400 and X<=599):
	print(8)
elif(X>599 and X<800):
    print(7)
elif(X>=800 and X<1000):
    print(6)
elif(X>=1000 and X<1200):
    print(5)
elif(X>=1200 and X<1400):
    print(4)
elif(X>=1400 and X<1600):
    print(3)
elif(X>=1600 and X<1800):
    print(2)
elif(X>=1800 and X<2000):
    print(1)
X,Y=map(int,input().split())
print(X+y/2)

### FIXED CODE ###

X,Y=map(int,input().split())
print(X+Y//2)
N = int(raw_input())
a = raw_input()
aa = a.split(" ")
aaa = []
for i in range(len(aa)):
	aaa.append((i+1,int(aa[i])))

ctr = 0

for (a,b) in aaa:
	if (b,a) in aaa:
		aaa.remove((a,b))
		aaa.remove((b,a))
		ctr = ctr + 1

print(str(ctr))

### FIXED CODE ###

s = raw_input()
s2 = s[:4] + " " + s[4:]
print(s2)
a,b,c=map(int,raw_input().split())
if b-a==c-b:
  print "YES"
else:
  ptint"NO"

### FIXED CODE ###

a,b,c=map(int,raw_input().split())
if b-a==c-b:
  print "YES"
else:
  print"NO"
3 4 10 40

### FIXED CODE ###

import math

A, B, H, M = map(int, input().split())

H += M/60
theta = abs(H/6 - M/30) * math.pi

x = math.sqrt((A * math.sin(theta))**2 + (B - A * math.cos(theta))**2)
print(x)
W, H, x, y = map(int, input().split())

area = (W * H) / 2
div = 0
if W // 2 == x and H // 2 == y:
    div = 1

print(area, div)


### FIXED CODE ###

X, A = map(int, input().split())
if X < A:
    print(0)
else:
    print(10)
A.append(input().split())
A.append(input().split())
A.append(input().split())
N = int(input())
b = [input() for _ in range(N)]

# 2次元配列として処理
for i in range(N):
  for j in range(3):
    if b[i] in A[j]: A[j][A[j].index(b[i])] = True
    
if (A[0][0] and A[1][0] and A[2][0]) or (A[0][1] and A[1][1] and A[2][1]) or (A[0][2] and A[1][2] and A[2][2]) or (A[0][0] and A[0][1] and A[0][2]) or (A[1][0] and A[1][1] and A[1][2]) or (A[2][0] and A[2][1] and A[2][2]) or (A[0][0] and A[1][1] and A[2][2]) or (A[0][2] and A[1][1] and A[2][0]): print('Yes')
else: print('No')

### FIXED CODE ###

A = []
A += input().split()
A += input().split()
A += input().split()
N = int(input())
b = [input() for _ in range(N)]
 
for i in range(N):
  if b[i] in A:
    A[A.index(b[i])] = '.'
    
if (A[0] == '.' and A[3] == '.' and A[6] == '.') or (A[1] == '.' and A[4] == '.' and A[7] == '.') or (A[2] == '.' and A[5] == '.' and A[8] == '.') or (A[0] == '.' and A[1] == '.' and A[2] == '.') or (A[3] == '.' and A[4] == '.' and A[5] == '.') or (A[6] == '.' and A[7] == '.' and A[8] == '.') or (A[0] == '.' and A[4] == '.' and A[8] == '.') or (A[2] == '.' and A[4] == '.' and A[6] == '.'): print('Yes')
else: print('No')
A, B, C = map(int, input().split())
print(max(C - (A-B), 0)

### FIXED CODE ###

A, B, C = map(int, input().split())
print(max(C - (A-B), 0))
N=int(input())
S=list(input())
T=list(input())  
sum=""
for i in range(N):
  sum= sum+S[i]+T[i]
print(sum)

### FIXED CODE ###

N=int(input())
S,T=input().split()
sum=""
for i in range(N):
  sum+=S[i]
  sum+=T[i]
print(sum)
import fractions

A,B=[int(x) for x in input().rstrip().split()]

print(A*B//(fraction.gcd(A,B)))

### FIXED CODE ###

a,b=[int(x) for x in input().rstrip().split()]

def gcd(m,n):
    x=max(m,n)
    y=min(m,n)

    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z
def lcm(m,n):
    return int(m*n/gcd(m,n))
print(lcm(a,b))
n,x = map(int,input().split())
A = sorted(map(int,input().split()))
ans = 0
for i in range(n):
  x -= A[i]
  ans += 1
  if x = 0:
    ans -= 1
    break
print(ans)


### FIXED CODE ###

n,x = map(int,input().split())
a = sorted(list(map(int,input().split())))
for i in range(n):
  x = x-a[i]
  if x<0:
    break
if i == n-1 and x == 0:
  i += 1
print(i)
# code-festival-2017-qualcC - Inserting 'x'
def main():
    S = input().rstrip()
    ans, l, r = 0, 0, len(S) - 1
    while l != r:
        if S[l] == S[r]:
            l += 1
            r -= 1
        else:
            ans += 1
            if S[l] == "x":
                l += 1
            elif S[r] == "x":
                r -= 1
            else:
                print(-1)
                return
    print(ans)


if __name__ == "__main__":
    main()

### FIXED CODE ###

# code-festival-2017-qualcC - Inserting 'x'
from collections import deque


def main():
    S = deque(list(input().rstrip()))
    ans = 0
    while len(S) >= 2:
        l, r = S[0], S[-1]
        if l == r:
            S.popleft(), S.pop()
        else:
            ans += 1
            if l == "x":
                S.append("x")
            elif r == "x":
                S.appendleft("x")
            else:
                print(-1)
                return
    print(ans)


if __name__ == "__main__":
    main()
import bisect
A, B, Q =  map(int, (input().split(' ')))

a_list = [-100001]+[int(input()) for _ in range(A)] + [100001]
b_list = [-100001]+[int(input()) for _ in range(B)] + [100001]
for _ in range(Q):
    x = int(input())
    right_s = abs(x - a_list[bisect.bisect_left(a_list, x)])
    right_t = abs(x - b_list[bisect.bisect_left(b_list, x)])
    left_s = abs(x - a_list[bisect.bisect_right(a_list, x)-1])
    left_t = abs(x - b_list[bisect.bisect_right(b_list, x)-1])
    print(
            min(
                max(left_t, left_s),
                max(right_t, right_s),
                left_t + (left_t + right_s),
                left_s + (left_s + right_t),
                right_t + (right_t + left_s),
                right_s + (right_s + left_t)
            )
    )


### FIXED CODE ###

import bisect
A, B, Q =  map(int, (input().split(' ')))
power = 10**11+1
a_list = [-power]+[int(input()) for _ in range(A)] + [power]
b_list = [-power]+[int(input()) for _ in range(B)] + [power]
for _ in range(Q):
    x = int(input())
    right_s = abs(x - a_list[bisect.bisect_left(a_list, x)])
    right_t = abs(x - b_list[bisect.bisect_left(b_list, x)])
    left_s = abs(x - a_list[bisect.bisect_right(a_list, x)-1])
    left_t = abs(x - b_list[bisect.bisect_right(b_list, x)-1])
    print(
            min(
                max(left_t, left_s),
                max(right_t, right_s),
                left_t + (left_t + right_s),
                left_s + (left_s + right_t),
                right_t + (right_t + left_s),
                right_s + (right_s + left_t)
            )
    )
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()], 
             dtype = 'int64')
A = A - np.arange(N) - 1
B = np.abs(A - np.reshape(A, (-1, 1)))
print(np.sum(B, axis=1).min())

### FIXED CODE ###

import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
A = np.sort(A - np.arange(N) - 1)
b = A[N//2]
print(np.sum(np.abs(A - b)))
import sys

def main():
    input = sys.stdin.readline
    S = str(input().strip())

    if len(S) % 2 == 1:
        mid = (len(S) - 1) // 2
        for i in range(mid):
            if S[mid] != S[mid + i] or S[mid] != S[mid -i]:
                ans = mid + i
                break
    else:
        midr = len(S) // 2
        midl = midr - 1
        for i in range(midr):
            if S[midr] != S[midr + i] or S[midr] != S[midl - i]:
                ans = midr + i
                break

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys

def main():
    input = sys.stdin.readline
    S = str(input().strip())
    L = len(S)

    i = 0
    if L % 2 == 1:
        mid = (L - 1) // 2
        m = S[mid]
        while i <= mid and S[mid-i] == S[mid+i] == m:
            i += 1

        print(mid + i)
    else:
        mid =  (L - 1) // 2
        m0 = S[mid]
        m1 = S[mid+1]
        while i <= mid and S[mid-i] == S[mid+i+1] == m0 == m1:
            i += 1

        print(mid + i + 1)


if __name__ == '__main__':
    main()
import collections
num = input()
a = [input() for i in range(num)]
clist = collections.Counter(a)
print(len(clist))

### FIXED CODE ###

import collections
num = int(input())
a = [input() for i in range(num)]
clist = collections.Counter(a)
print(len(clist))
A, B = map(int, raw_input().split())
ans = 0
for i in range(A, B+1):
    ans ^= i
    # print(ans, i)
print(ans)


### FIXED CODE ###

A, B = map(int, input().split())
ans = 0
cnt = 0
def f(arg):
    ans = 0
    if arg < 0:
        return 0
    for pos in range(1, 41):
        # ループする数
        loop = 1 << pos
        # cnt = sum([int((n & v) / v) for n in range(arg+1)])
        cnt = int((arg + 1) / loop) * (loop >> 1)
        cnt += max(0, (arg + 1) % (loop) - (loop >> 1))
        ans += cnt%2 * (loop>>1)
        # print(arg, pos, loop, cnt, ans)
        if loop > arg:
            break
    return ans
print(f(A-1)^f(B))
N = int(input())
A = []
for i in range(1,46):
  for j in range(1,46):
    for k in range(1,46):
      A.append(i**2+j**2+k**2+i*j+i*k+j*k)
A = sorted(A)
B = [0]*N
for i in range(N):
  if A[i] < N:
    B[A[i]] += 1
C = B[1:]
[print(i) for i in C]

### FIXED CODE ###

L,R,d = map(int, input().split())
X = L//d
Y = R//d
if L%d == 0 and R%d == 0:
  if L>R:
    print(X-Y+1)
  else:
    print(Y-X+1)
else:
  if L >R:
    print(X-Y)
  else:
    print(Y-X)
N, K = map(int, input().split())
print(min(N%K, K(N%K)))


### FIXED CODE ###

N, K = map(int, input().split())
print(min(N%K, K-(N%K)))