Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

S = input()
S = list(S)
s = list(reversed(S))
def check(s):
  if len(s) >= 6:

    j1 = ''.join(s[:5])
    j2 = ''.join(s[:6])
    j3 = ''.join(s[:7])
  elif len(s) == 5:
    j1 = ''.join(s[:5])
    j2 = ''.join(s[:6])
    j3 = ''
  else:
    j1 = ''.join(s[:5])
    j2 = ''
    j3 = ''  
  if (j1 == 'esare') or (j1 == 'maerd'):
    x =  ''.join(s[5:])
    return x
  elif j2 == 'resare':
    x = ''.join(s[6:])
    return x
  elif j3 == 'remaerd':
    x = ''.join(s[:7])
    return x
  else:
    return 'no'

while True:
  s = list(check(s))
  if s == list('no'):
    print('NO')
    break
  if s == []:
    print('YES')
    break




### FIXED CODE ###

S = input()
S = list(S)
s = ''.join(list(reversed(S)))
def main(s):
  l = ["resare", "esare","remaerd", "maerd"]
  for i in l:
    s = s.replace(i, '')
  return s
if main(s) == '':
  print('YES')
elif main(s) != '':
  print('NO')
### BUGGY CODE ###

N = int(input())
A = list(map(int, input().split()))
prd = 1
flag = False
if (0 in A):
  print(0)
else:
  for i in range(len(A)):
    prd = prd * A[i]
    if (prd > 10**18):
      flag = True
  if (flag):
    print(-1)
  else:
    print(prd)

### FIXED CODE ###

def main():
  N = int(input())
  A = list(map(int, input().split()))
  if 0 in A:
    print(0)
    return
  prd = 1
  for a in A:
    prd *= a
    if prd > 1000000000000000000:
      print(-1)
      return
  print(prd)

main()
### BUGGY CODE ###

from math import ceil

# 位置xにあるゴミをi番目に拾うときの、追加コスト
def E(i, x):
    if i > 2:
        return (2 * i + 1) * x
    else:
        return 5 * x

N, X = map(int, input().split())
xs = list(map(int, input().split()))

# ロボット台数kを全て試す
ans = float('inf')
for k in range(1, N + 1):
    cost = (N + k) * X
    for i, x in enumerate(reversed(xs), 1):
        # 1台あたりのゴミ数は、できるだけ少なくしたい
        cost += E(ceil(i / k), x)
    ans = min(ans, cost)

print(ans)


### FIXED CODE ###

from itertools import accumulate
from math import ceil

N, X = map(int, input().split())
xs = list(map(int, input().split()))

accXs = [0] + list(accumulate(reversed(xs)))

# ロボット台数kを全て試す
ans = float('inf')
for k in range(1, N + 1):
    cost = (N + k) * X

    # i番目に拾うゴミについて、追加コストをまとめて計算する
    cost += 5 * (accXs[k] - accXs[0])

    m = ceil(N / k)
    for i in range(2, m):
        cost += (2 * i + 1) * (accXs[i * k] - accXs[(i - 1) * k])

    cost += (2 * m + 1) * (accXs[N] - accXs[(m - 1) * k])

    ans = min(ans, cost)

print(ans)
### BUGGY CODE ###

#import sys
#input = sys.stdin.readline

def main():
    s = input()
    q = int(input())
    is_rev = False
    for _ in range(0, q):
        query = input()
        if len(query) == 1:
            is_rev = not is_rev
        else:
            query = query.split(' ')
            query = [int(query[0]), int(query[1]), query[2]]
            if (query[1] == 1 and is_rev) or (query[1] == 2 and not is_rev):
                s = s + query[2]
            else:
                s = query[2] + s
    if is_rev:
        print(s[::-1])
    else:
        print(s)

main()

### FIXED CODE ###

#import sys
#input = sys.stdin.readline

def main():
    s = input()
    q = int(input())
    is_rev = False
    l = ''
    r = ''
    for _ in range(0, q):
        query = input()
        if len(query) == 1:
            is_rev = not is_rev
        else:
            query = query.split(' ')
            query = [int(query[0]), int(query[1]), query[2]]
            if (query[1] == 1 and is_rev) or (query[1] == 2 and not is_rev):
#                s = s + query[2]
                r += query[2]
            else:
#                s = query[2] + s
                l += query[2]
    if is_rev:
        print(r[::-1] + s[::-1] + l)
    else:
        print(l[::-1] + s + r)

main()
### BUGGY CODE ###

import heapq as hp
n = int(input())
a = list(map(int, input().split()))
hp.heapify(a)
ans = 0
while len(a) > 0:
    b = hp.heappop(a)
    if b in a:
         ans += -1
    a = [i for i in a if i % b != 0]
    ans += 1
print(ans)


### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = max(a)
che = [1 for i in range(b)]
for i in a:
    if che[i-1] == 1:
        c = b // i
        for j in range(2,c+1):
            che[i*j-1] = 0
        che[i-1] = 2
    elif che[i-1] == 2:
        che[i-1] = 0
ans = 0
for i in a:
    if che[i-1] == 2:
        ans += 1
print(ans)
### BUGGY CODE ###

import math
from scipy.misc import comb
#from scipy.special import comb

def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


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

if (2*Y-X)%3!=0 and (2*X-Y)%3!=0:
  print(0)
else:
  P=(2*X-Y)//3
  Q=(2*Y-X)//3
  #maxi=
  ans=comb((P+Q),P,(10**9+7))
  #ans=combinations((P+Q),P)
  print(ans)

### FIXED CODE ###

def framod(x,p=10**9+7):
  a=1
  for i in range(1,x+1):
    a = (a*i)%p
  return a
#############################################
X,Y=map(int,input().split())
p=10**9+7

if (X+Y)%3!=0:
  print(0)
else:
  a = (2*X-Y)//3
  b = (2*Y-X)//3
  t = a+b
  if a<0 or b<0:
    print(0)
  else:
    S=framod(t)
    T=pow(framod(a),p-2,p)
    U=pow(framod(b),p-2,p)
    print(((S*T)%p)*U%p)
### BUGGY CODE ###

S=input()
S_len=len(S)
Word=['eraser','erase','dreamer','dream']

while True:
    if len(S)<4:
        break
    else:
        for i in Word:
            S = S.replace(i,"")
        if len(S)==S_len: #一つも文字が含まれなかった時break
            break
           
if len(S)==0:
    print('YES')
else:
    print('NO')

### FIXED CODE ###

S=input()
Word=['eraser','erase','dreamer','dream']

while True:
    S_len=len(S)
    if S_len<5:
        break
    else:
        for i in Word:
            S = S.replace(i,"")
        if len(S)==S_len: #一つも文字が消えなかった時break
            break
           
if len(S)==0:
    print('YES')
else:
    print('NO')
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
if n % 2 == 1:
    if a.count(0) > 1:
        print(0)
    else:
        a.remove(0)
        for i in list(set(a)):
            if a.count(i) != 2:
                print(0)
                exit()
        print(2 ** ((n - 1) // 2))
else:
    if a.count(0) > 0:
        print(0)
    else:
        for i in list(set(a)):
            if a.count(i) != 2:
                print(0)
                exit()
        print(2 ** (n // 2))

### FIXED CODE ###

import collections

n = int(input())
a = list(map(int, input().split()))
ac = collections.Counter(a)
if n % 2 == 1:
    for i in ac:
        if i == 0:
            if ac[i] != 1:
                print(0)
                exit()
        else:
            if ac[i] != 2:
                print(0)
                exit()
    print((2 ** (n // 2)) % (10 ** 9 + 7))
else:
    for i in ac:
        if i == 0:
            if ac[i] != 0:
                print(0)
                exit()
        else:
            if ac[i] != 2:
                print(0)
                exit()
    print((2 ** (n // 2)) % (10 ** 9 + 7))
### BUGGY CODE ###

n,k = map(int,input().split())
sai = list(map(int,input().split()))
sai = list(map(lambda x:(x+1)/2,sai))
kai = []

for nn in range(n-k+1):
    kai.append(sum(sai[nn:nn+k]))

print(max(kai))

### FIXED CODE ###

n,k = map(int,input().split())
li = list(map(int,input().split()))
li = list(map(lambda x:(x+1)/2,li))

wk = 0
nn = n-k

for i in range(0,k):
    wk += li[i]
kwk = wk
for j in range(nn):
    wk = wk - li[j]
    wk = wk + li[j+k]
    kwk = max(wk,kwk)
 
print(kwk)
### BUGGY CODE ###

import numpy as np
from pprint import pprint
H,W = map(int,input().split())

def cal(l):
    ll = l.copy()
    ll.append('#')
    vol = [-100 for j in range(len(ll))]
    i = 0
    while i <= len(ll)-1:
        cnt = 0
        while (ll[i] != '#' and i <= len(ll)-1):
            cnt += 1
            i += 1
            # print(i)

        for j in range(i-cnt,i):
            vol[j] = cnt

        i += 1
        # print(i)
    return vol[:-1]

ver = [] # 縦
hori = [] # 横
fmap = []

for h in range(H):
    # print(h,fmap)
    l = list(input())
    #print(l)
    hori.append(cal(l))
    fmap.append(l)

fmap = np.array(fmap)
fmap = fmap.T.tolist()
#print(fmap)

for w in range(W):
    ver.append(cal(fmap[w]))

ans = 0
#pprint(np.array(hori))
#pprint(np.array(ver).T)
for h in range(H):
    for w in range(W):
        s = hori[h][w]+ver[w][h]
        if s > ans:
            ans = s
print(ans-1)



### FIXED CODE ###

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

def cal(l):
    ll = list(l)
    ll.append('#')
    vol = [-100 for j in range(len(ll))]
    i = 0
    while i <= len(ll)-1:
        cnt = 0
        while (ll[i] != '#' and i <= len(ll)-1):
            cnt += 1
            i += 1

        for j in range(i-cnt,i):
            vol[j] = cnt

        i += 1
    return vol[:-1]

ver = [] # 縦
hori = [] # 横
fmap = []

for h in range(H):
    l = list(input())
    hori.append(cal(l))
    fmap.append(l)



new_map = []
for i in range(len(fmap[0])):
    mini_l = []
    for j in range(len(fmap)):
        mini_l.append(fmap[j][i])
    new_map.append(mini_l)

fmap = new_map    

for w in range(W):
    ver.append(cal(fmap[w]))

ans = 0

for h in range(H):
    for w in range(W):
        s = hori[h][w]+ver[w][h]
        if s > ans:
            ans = s
print(ans-1)
### BUGGY CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    while int(l) != int(r):
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += math.ceil(a / test) - 1

        if sum > K:
            l = test
        elif sum < K:
            r = test
        else:# sum == K
            r = test

    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += math.ceil(a / int(l)) - 1
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()

### FIXED CODE ###

# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50


def run():
    N, K = map(int, sysread().split())
    A = list(map(int, sysread().split()))

    l = 0
    r = 10**9
    while int(l) != int(r):
        #print(l, r)
        test = (l + r) / 2
        sum = 0
        for a in A:
            sum += math.ceil(a / test) - 1

        if sum > K:
            l = test
        elif sum < K:
            r = test
        else:# sum == K
            r = test
        if int(r) == r and r-l < 1:
            print(int(r))
            return

    if int(l) == 0:
        print(1)
        return
    if int(l) == l:
        sum = 0
        for a in A:
            sum += math.ceil(a / int(l)) - 1
        if sum == K:
            print(int(l))
            return

    print(int(l)+1)

if __name__ == "__main__":
    run()
### BUGGY CODE ###

p_list = {}

def get_min_p(offset, length, k, arr):
  key = "{}:{}".format(offset, k)
  if key in p_list: return p_list[key]

  if k == 1:
    p_list[key] = sum(arr[offset:offset + length])
  elif k == 2:
    min_diff = float('inf')
    p = 0
    for i in range(1, length):
      a = sum(arr[offset:offset + i])
      b = sum(arr[offset + i:])
      if abs(a - b) < min_diff:
        min_diff = abs(a - b)
        p = max(a, b)
      #print("arr:{}, i:{}, p:{}".format(
      #  arr[offset:offset + length], i, p))
    p_list[key] = p
  else:
    e = len(arr) - k + 2
    p = [float('inf')] * e
    for i in range(1, e):
      #print("p:{}, i:{}".format(p, i))
      a = get_min_p(offset + i, length - i, k - 1, arr)
      b = sum(arr[offset:offset + i])
      p[i] = max(a, b)
    p_list[key] = min(p)
  return p_list[key]

n, k = map(int, input().split())
a = [int(input()) for i in range(n)]

print(get_min_p(0, n, k, a))

### FIXED CODE ###

def check(p, k, arr):
  subtotal = 0
  num_of_tracks = 1
  for a in arr:
    subtotal += a
    if subtotal > p:
      num_of_tracks += 1
      if num_of_tracks > k: return False
      subtotal = a
  return True

n, k = map(int, input().split())
arr = [int(input()) for i in range(n)]

min_p = max(arr)
max_p = sum(arr)
while min_p < max_p:
  mid_p = (min_p + max_p) // 2
  if check(mid_p, k, arr):
    max_p = mid_p
  else:
    min_p = mid_p + 1

print(min_p)
### BUGGY CODE ###

S = int(input())

x1, y2 = 0, 0
y1, x2, x3, y3 = 0, 0, 0, 0

for i in range(1, int(S ** 0.5) + 1):
  x2 = i
  if S / x2 > 1000000000:
    continue
  Y = S / x2
  y3 = int(Y) + 2
  x3 = x2 // 2
  if x3 == 0:
    y1 = 2
  else:
    y1 = (Y - y3) * x2 / x3
  if y1 == int(y1):
    break

print("{} {} {} {} {} {}".format(x1, y1, x2, y2, x3, y3))

### FIXED CODE ###

S = int(input())
MOD = 10 ** 9
x1, y1, x2, y2 = 0, 0, MOD, 1
y3 = S // MOD
if S % MOD != 0:
  y3 += 1
x3 = x2 * y3 - S

print("{} {} {} {} {} {}".format(x1, y1, x2, y2, x3, y3))
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=[]
for i in range(60):
	p=0
	for j in range(n):
		if a[j]%2==1:
			p+=1
		a[j]//=2
	cnt.append(p)
ans=0
for i in range(60):
	ans+=(n-cnt[i])*cnt[i]*(2**i)
	ans%=10**9+7
print(ans)

### FIXED CODE ###

import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
mod=10**9+7
cnt=[]
q=set()
for i in range(n):
	q.add(i)
for i in range(60):
	p=0
	l=[]
	for j in q:
		if a[j]%2==1:
			p+=1
		a[j]//=2
		if a[j]==0:
			l.append(j)
	for j in range(len(l)):
		q.remove(l[j])
	cnt.append(p)
ans=0
for i in range(60):
	ans+=(n-cnt[i])*cnt[i]*(2**i)
	ans%=mod
print(ans)
### BUGGY CODE ###

import numpy as np
# your code goes here
def hanten(C, X, V):
	return (C*np.ones(X.shape[0])-X)[::-1], V[::-1]

def solv(N, C, X, V):
	return max(solv1(N, C, X, V, 0), solv2(N, C, X, V))

def solv1(N, C, X, V, pos):
	r = 0
	rbuf = 0
	#print(X, V)
	for i in range(N):
		rbuf += V[i] - (X[i]-pos)
		pos = X[i]
		if(rbuf > r):
			r = rbuf
	return r

def solv2(N, C, X, V):
	r = 0
	rbuf = 0
	pos = 0
	VV = V.copy()
	for i in range(N):
		rbuf += V[i] - (X[i]-pos)
		pos = X[i]
		VV[i] = 0
		Xbuf, Vbuf = hanten(C, X, VV)
		rbufbuf = rbuf + solv1(N, C, Xbuf, Vbuf, -pos)
		#print(Xbuf, Vbuf, pos, rbufbuf)
		if(rbufbuf > r):
			r = rbufbuf
	return r
	
def main():
	buf = input().split()
	N = int(buf[0])
	C = int(buf[1])
	X = np.zeros(N)
	V = np.zeros(N)
	for i in range(N):
		buf = input().split()
		X[i] = int(buf[0])
		V[i] = int(buf[1])
	
	r1 = solv2(N, C, X, V)
	X, V = hanten(C, X, V)
	r2 = solv2(N, C, X, V)
	print(int(max(r1, r2)))

main()

### FIXED CODE ###

import numpy as np
def hanten(C, X, V):
	return (C*np.ones(X.shape[0])-X)[::-1], V[::-1]

def solv2(N, X, V):
	r = 0
	rbuf = 0
	pos = 0
	Vsum = V.copy()
	for i in range(N):
		rbuf += V[i] - (X[i]-pos)
		pos = X[i]
		if(rbuf > r):
			r = rbuf
		Vsum[i] = r
	return Vsum

def solv(N, C, X, V):
	r = 0
	rbuf1 = 0
	pos = 0
	ibuf = 0
	iX, iV = hanten(C, X, V) 
	iv = solv2(N, iX, iV)
	#print(iv)
	for i in range(N):
		rbuf1 += V[i] - 2*(X[i]-pos)
		rbuf2 = iv[N-(i+2)]
		if(i == N-1):
			rbuf2 = 0
		rbuf = rbuf1 + rbuf2
		pos = X[i]
		#print(rbuf, rbufbuf)
		if(rbuf > r):
			r = rbuf
	return max(r, iv[-1])
	
def main():
	buf = input().split()
	N = int(buf[0])
	C = int(buf[1])
	X = np.zeros(N)
	V = np.zeros(N)
	for i in range(N):
		buf = input().split()
		X[i] = int(buf[0])
		V[i] = int(buf[1])
	r1 = solv(N, C, X, V)
	X, V = hanten(C, X, V)
	r2 = solv(N, C, X, V)
	print(int(max(r1, r2)))
	#print(solv2(N, X, V))
main()# your code goes here
### BUGGY CODE ###

import sys
input=sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    m = min(A)
    xi = A.index(m)
    for a in range(0, m*2+1, 2):
        B = A.copy()
        ans = [0]*N
        B[(xi-1)%N] -= a//2
        B[xi] -= a//2
        ans[xi] = a
        for i in range(xi+1, xi+N):
            x = B[(i-1)%N]*2
            if B[i%N]-x//2 < 0:
                break
            B[(i-1)%N] -= x//2
            B[i%N] -= x//2
            ans[i%N] += x
            if sum(B) == 0:
                print(*ans)
                return

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    ans = [0]*N
    ans[0] = sum(A)
    for i in range(1,N,2):
        ans[0] -= 2*A[i]
    for i in range(1,N):
        ans[i] = 2*A[i-1]-ans[i-1]
    print(*ans)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

n= int(input())
s = [input()for i in range(n)]
t = set(s)
t=sorted(t)
ans =[]
for i in t:
    ans.append(s.count(i))
mx = max(ans)
for i in range(len(t)):
    if mx == ans[i]:
        print(t[i])

### FIXED CODE ###

from collections import Counter

def print_cnt(l):
    counter = Counter(l)
    max_cnt = counter.most_common(1)[0][1]
    ret = [v for v,c in counter.most_common() if c == max_cnt] # 最多２個以上にするなら ～if c > 1 and c == max_cnt
    ret=sorted(ret)
    for a in ret:
        print(a)


n = int(input())
print_cnt([input()for i in range(n)])
### BUGGY CODE ###

N,K = map(int, input().split())
X = [int(x) for x in input().split()]

ref = []
for i in range(N-K+1):
    ref.append(X[i:i+K])

List = []
for j in range(N-K+1):
    if X[j]<=0 and X[j+K-1]>=0:
        List.append(X[j+K-1]-X[j]+min(abs(X[j]),X[j+K-1]))
    else:
        List.append(max(abs(X[j]),abs(X[j+K-1])))

print(min(List))

### FIXED CODE ###

N,K = map(int, input().split())
X = [int(x) for x in input().split()]

List = []
for j in range(N-K+1):
    if X[j]<=0 and X[j+K-1]>=0:
        List.append(X[j+K-1]-X[j]+min(abs(X[j]),X[j+K-1]))
    else:
        List.append(max(abs(X[j]),abs(X[j+K-1])))

print(min(List))
### BUGGY CODE ###

import re
N,Q = map(int,input().split())
S = input()
for i in range(Q):
    l,r = map(int,input().split())
    print(len(re.findall('AC',S[l-1:r])))

### FIXED CODE ###

N,Q = map(int,input().split())
S = input()
lst = [0] * (N+1)
before = ''
count = 0
for i in range(len(S)-1):
    if S[i:i+2] == 'AC':
        count += 1
    lst[i+2] = count
for i in range(Q):
    l,r = map(int,input().split())
    print(lst[r]-lst[l])
### BUGGY CODE ###

def isort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j -= g
            cnt += 1
        a[j + g] = v

# input data
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))

# determine m, g
g = [1]
m = 1
while True:
    x = 3 * g[m - 1] + 1
    if x >= n: break
    g.append(x)
    m += 1
g = g[::-1]

# 1 output m
print(m)
# 2 output g
print(' '.join(map(str, g)))

# sort it
cnt = 0
for i in range(m):
    isort(a, n, g[i])

# 3 output cnt
print(cnt)
# 4 output sorted a
for i in range(n):
    print(a[i])

### FIXED CODE ###

import sys
 
def isort(a, n, g):
    global cnt
    for i in range(g, n):
        v = a[i]
        j = i - g
        while j >= 0 and a[j] > v:
            a[j + g] = a[j]
            j -= g
            cnt += 1
        a[j + g] = v
 
# input data
n = int(sys.stdin.readline())
a = []
for i in range(n):
    a.append(int(sys.stdin.readline()))
 
# determine m, g
g = [1]
m = 1
while True:
    x = 3 * g[m - 1] + 1
    if x >= n: break
    g.append(x)
    m += 1
g = g[::-1]
 
# 1 output m
print(m)
# 2 output g
print(' '.join(map(str, g)))
 
# sort it
cnt = 0
for i in range(m):
    isort(a, n, g[i])
 
# 3 output cnt
print(cnt)
# 4 output sorted a
print('\n'.join(map(str, a)))
### BUGGY CODE ###

a,b=map(int,input().split())
if b==1:
  a=a-10**str(a).count('0')
ans=[a]
for i in range(1000000000):
  ans.append(abs(ans[i]-b))
print(min(ans))

### FIXED CODE ###

a,b=map(int,input().split())
ans=[a,a%b]
for i in range(10000):
    ans.append(abs(ans[i]-b))
print(min(ans))
### BUGGY CODE ###

N = int(input())
T = list(map(int, input().split()))
V = [0] + list(map(int, input().split())) + [0]

Tc = [0, 0] + [sum(T[:i + 1]) for i in range(N)] + [sum(T)]

ans = 0
for i in range(sum(T) * 2):
    t1, t2 = i * 0.5, (i + 1) * 0.5
    maxV1, maxV2 = [], []
    for j in range(N + 2):
        for t, maxV in [(t1, maxV1), (t2, maxV2)]:
            if t <= Tc[j]:
                maxV.append(V[j] + (Tc[j] - t))
            elif Tc[j] < t <= Tc[j + 1]:
                maxV.append(V[j])
            else:
                maxV.append(V[j] + (t - Tc[j + 1]))
    ans += 0.25 * (min(maxV1) + min(maxV2))

print(ans)


### FIXED CODE ###

N = int(input())
T = list(map(int, input().split()))
V = [0] + list(map(int, input().split())) + [0]

Tc = [0, 0] + [sum(T[:i + 1]) for i in range(N)] + [sum(T)]

ans = 0
for i in range(sum(T) * 2):
    t1, t2 = i * 0.5, (i + 1) * 0.5
    maxV1, maxV2 = [], []
    for j in range(N + 2):
        for t, maxV in [(t1, maxV1), (t2, maxV2)]:
            if t <= Tc[j]:
                maxV.append(V[j] + (Tc[j] - t))
            elif Tc[j] < t <= Tc[j + 1]:
                maxV.append(V[j])
            else:
                maxV.append(V[j] + (t - Tc[j + 1]))
    ans += 0.25 * (min(maxV1) + min(maxV2))

print(ans)