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

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

for i in range(0,m-n+1):
    if m%(n+i) == 0:
        print(int(m/(n+i)))
        break

### FIXED CODE ###

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

i_m = m
import math
root_m = int(math.sqrt(m))

m_s = []
for i in range(2,root_m+1):
    while m%i == 0:
        m_s.append(i)
        m = int(m/i)
        if m == 1:
            break
    if m ==1:
        break

if m_s == []:
    if n == 1:
        print(i_m)
    else:
        print(1)

else:
    for i in range(0,i_m-n+1):
        if i_m%(n+i) == 0:
            print(int(i_m/(n+i)))
            break
### BUGGY CODE ###

def solve(i,m):
    global n
    global A
    if m == 0 :
        return True
 #   elif m < 0:
 #       return False
    elif i >= n :
        return False
    else:
        return (solve(i+1,m) or solve(i+1,m-A[i]))

global n
global A
n = int(input())
A = [ int( val ) for val in input().rstrip().split( ' ' ) ]
#A.sort(reverse = True)
input()     # don't use the num of ans pattern. dumping!
ans = [ int( val ) for val in input().rstrip().split( ' ' ) ]
for x in ans:
    if(solve(0,x) == True):
        print('yes')
    else:
        print('no')

### FIXED CODE ###

is_able_make = [False]*2000

input()

A = [ int( val ) for val in input().rstrip().split( ' ' ) ]
q = int(input())
M = [ int( val ) for val in input().rstrip().split( ' ' ) ]

for i in A:
    for j in range(2000-i,0,-1):
        if is_able_make[j] == True:
            is_able_make[i+j] = True
    is_able_make[i] = True

for x in M:
    if(is_able_make[x] == True):
        print('yes')
    else:
        print('no')
### BUGGY CODE ###

from collections import deque

s = input()
t = input()

def restr(string):
    result = []
    for i in range(len(string)):
        tmp = [i]
        for j in range(i+1, len(string)):
            if string[i] == string[j]:
                tmp.append(j)
        if len(tmp) > 1:
            result.append(tmp)
    return result

print('Yes' if restr(s) == restr(t) else 'No')


### FIXED CODE ###

from collections import defaultdict

def a(s):
    dic = defaultdict(list)
    for i, ch in enumerate(s):
        dic[ch].append(i)
    return sorted(list(dic.values()))

s = input()
t = input()
print('Yes' if a(s) == a(t) else 'No')
### BUGGY CODE ###

S=input()
QN=int(input())

for i in range(QN):
    op=input()
    if op[0]=='1':
        S=S[::-1]
    else:
        if op[2]=='1':
            S=op[4]+S
        else:
            S=S+op[4]

print(S)

### FIXED CODE ###

S=input()
QN=int(input())
front=''
rear=''
rev=False

for i in range(QN):
    op=input()
    if op[0]=='1':
        rev=not(rev)
    else:
        if op[2]=='1':
            if rev:
                rear+=op[4]
            else:
                front+=op[4]
        else:
            if rev:
                front+=op[4]
            else:
                rear+=op[4]

if rev:
    print(rear[::-1]+S[::-1]+front)
else:
    print(front[::-1]+S+rear)
### BUGGY CODE ###

card_num, gate_num = map(int, input().split())
table = []
count = 0
for k in range(card_num):
    table.append(0)

for i in range(gate_num):
    start_num, end_num = map(int, input().split())
    for j in range(start_num-1, end_num):
        table[j] += 1

for l in range(card_num):
    if table[l] == gate_num:
        count += 1

print(count)

### FIXED CODE ###

# 先頭の最大と最後尾の最小を求める
card_num, gate_num = map(int, input().split())
lmax, rmin = map(int, input().split()) # 最初の入力がlの最大とrの最小
for i in range(1, gate_num):
    l, r = map(int, input().split())
    lmax = max(lmax, l) # lmaxにlmaxとlの大きい方
    rmin = min(rmin, r) # rminにrminとrの小さい方
print(max(0, rmin-lmax+1)) # 0かrmin-lmax+1の大きい方を出力
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

N = int(input())
XD = [[int(i) for i in input().split()] for _ in range(N)]
XD.sort()
MOD = 998244353
sorted_X = [X for X,_ in XD]

edge = [[] for _ in range(N)]

from bisect import bisect_left

parent = [-1] * N

for i in range(N-1, -1, -1):
    idx = bisect_left(sorted_X, XD[i][0] + XD[i][1])
    for j in range(i+1, idx):
        if parent[j] < 0:
            parent[j] = i

for i,par in enumerate(parent):
    if par < 0:
        continue
    edge[par].append(i)

def cnt(node):
    if not edge[node]:
        return 2
    
    res = 1
    for v in edge[node]:
        res = (res * cnt(v)) % MOD
    res += 1

    return res % MOD

ans = 1
for i,par in enumerate(parent):
    if par < 0:
        ans = (ans * cnt(i)) % MOD

print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
from bisect import bisect_left

N = int(input())
XD = [[int(i) for i in input().split()] for _ in range(N)]
XD.sort()
MOD = 998244353

def make():
    edge = [[] for _ in range(N)]
    parent = [-1] * N
    MAXIDX = N
    sorted_X = [X for X,_ in XD]
    for i in range(N-1, -1, -1):
        idx = bisect_left(sorted_X, XD[i][0] + XD[i][1])
        for j in range(i+1, min(idx, MAXIDX)):
            if parent[j] < 0:
                parent[j] = i
        if idx >= MAXIDX:
            MAXIDX = i + 1
    for i,par in enumerate(parent):
        if par < 0:
            continue
        edge[par].append(i)
    
    return parent, edge

parent, edge = make()

def cnt(node):
    if not edge[node]:
        return 2

    res = 1
    for v in edge[node]:
        res = (res * cnt(v)) % MOD
    res += 1

    return res % MOD

def main():
    ans = 1
    for i,par in enumerate(parent):
        if par < 0:
            ans = (ans * cnt(i)) % MOD

    print(ans)

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

from collections import Counter

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

Blist = list(map(lambda x: x%M, [sum(Alist[:i]) for i in range(len(Alist)+1)]))
Blist.sort()

c = Counter(Blist)

values, counts = zip(*c.most_common())
ans = 0
for count in counts:
    ans += int(count * (count - 1) / 2)

print(ans)

### FIXED CODE ###

from collections import Counter

N, M = map(int, input().split())
Alist = list(map(int, input().split()))
Blist = [0]
for i in range(len(Alist)):
    Blist.append((Blist[-1] + Alist[i])%M)

c = Counter(Blist)

ans = 0
for key, val in c.items():
    ans += val * (val - 1) / 2

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

import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N, M = [int(x) for x in input().split()]
AB = []
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a - 1, b - 2))

AB.sort(key=lambda x: -x[0])

cnt = 0
while len(AB) != 0:
    cut = AB[0][0]
    # print("AB:{}, cut:{}".format(AB, cut))
    # print(AB)
    newAB = []
    for (a,b) in AB:
        if a <= cut and cut <= b:
            pass
        else:
            newAB.append((a, b))
    AB = newAB
    cnt += 1

print(cnt)


### FIXED CODE ###

N, M = [int(x) for x in input().split()]

AB = []
for i in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a, b))

AB.sort(key=lambda x: x[1])

ans = 0
while len(AB) != 0:
    cut = AB[0][1]
    newAB = []
    ans += 1
    for a, b in AB:
        if a < cut:
            pass
        else:
            newAB.append((a, b))
    AB = newAB

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

N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    x, y, z = map(int, input().split(" "))
    C.append(x)
    S.append(y)
    F.append(z)

ans = []
for j in range(N-1):
    temp = S[j]+C[j]
    temp2 = 0
    k = j
    while k < (N-1-1):
        if temp < S[k+1]:
            temp = S[k+1]
        else:
            temp2 = S[k+1]
            while temp2 < temp:
                temp2 += F[k+1]
            temp = temp2
        temp += C[k+1]
        k += 1
    ans.append(temp)

for l in range(N-1):
    print(ans[l])
    
print("0")

### FIXED CODE ###

N = int(input())
C = []
S = []
F = []
for i in range(N-1):
    x, y, z = map(int, input().split(" "))
    C.append(x)
    S.append(y)
    F.append(z)

for j in range(N-1):
    ans = 0
    for k in range(j, N-1):
        if ans < S[k]:
            ans = S[k]
        if ans%F[k] != 0:
            ans += F[k]-ans%F[k]
        ans += C[k]
    print(ans)
print(0)
### BUGGY CODE ###

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

b = []
for a in A:
    b.append(a)
    b.reverse()

print(*b)

### FIXED CODE ###

from collections import deque
n = int(input())
A = list(map(int,input().split()))

b = deque()
for i,a in enumerate(A):
    if i % 2 == 0:
        b.append(a)
    elif i % 2 == 1:
        b.appendleft(a)

if n % 2 == 1:
    b.reverse()
print(*b)
### BUGGY CODE ###

n=int(input())
s=[int(input()) for i in range(n)]
#print(n,s)

max=0
t=[0]
for j in range(n):
    for i in range(len(t)):
        t.append(t[i]+s[j])
        if max < t[i]+s[j] and (t[i]+s[j])%10 !=0:
          max = t[i]+s[j]

print(max)

### FIXED CODE ###

n=int(input())
s=[int(input()) for i in range(n)]
#print(n,s)
t=[[float('-inf') for i in range(10000+1)] for i in range(n+1)]

t[0][0]=0
for j in range(1,n+1):
    t[j]=t[j-1]
    tmp=[]
    for i in range(10000+1):
        if t[j-1][i]>=0:
            tmp.append(t[j-1][i])
    for i in tmp:
        t[j][i+s[j-1]]=i+s[j-1]

for i in range(len(t[n])):
    if t[n][i]%10==0:
        t[n][i]=0

print(max(t[n]))
### BUGGY CODE ###

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, K = map(int, input().split())
h = list(map(int, input().split()))
#= [input(), input()]

dp = [0] * N

dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    t = [dp[i - 1] + abs(h[i] - h[i - 1])]
    for j in range(2, min(K + 1, i + 1)):
        tt = dp[i - j] + abs(h[i] - h[i - j])
        t.append(tt)

    dp[i] = min(t)

print(dp[-1])

### FIXED CODE ###

#import
#import math
#import numpy as np
#= int(input())
#= input()
N, K = map(int, input().split())
h = list(map(int, input().split()))
#= [input(), input()]

dp = [0] * N

dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    t = dp[i - 1] + abs(h[i] - h[i - 1])
    for j in range(2, min(K + 1, i + 1)):
        tt = dp[i - j] + abs(h[i] - h[i - j])
        t = min(t, tt)

    dp[i] = t

print(dp[-1])
### BUGGY CODE ###

N,K=[int(s) for s in input().split()]
A=[int(s) for s in input().split()]
F=[int(s) for s in input().split()]
A.sort()
F.sort(reverse=1)


def success(x):
  suc_sum=0
  for i in range(N):
    a=x//F[i]
    if A[i]>a:
      suc_sum+=A[i]-a
  if suc_sum<=K:
    return True
  else:
    return False

def bisearch():
  bi_max=10**12
  bi_a=0
  bi_b=bi_max
  while bi_b-bi_a>1:
    c=(bi_a+bi_b)//2
    if success(c):
      bi_a,bi_b=[bi_a,c]
    else:
      bi_a,bi_b=[c,bi_b]
  return [bi_a,bi_b]

a,b=bisearch()
if success(a):
  print(a)
else:
  print(b)    

### FIXED CODE ###

import math
N,K=[int(s) for s in input().split()]
ls1=[int(s) for s in input().split()]
ls2=[int(s) for s in input().split()]
ls1.sort()
ls2.sort()
M=max([ls1[i]*ls2[N-1-i] for i in range(N)])
#print(M)
###aまで下げることが可能か？
def pos(a):
  s=0
  for i in range(N):
    s+=max([0,math.ceil(ls1[i]-a/ls2[N-1-i])])
  if s>K:
    return 0
  else:
    return 1
x=0
y=M//2
z=M
while z-x>1:
  if pos(y)==1:
    z=y
  else:
    x=y
  y=(x+z)//2
#  print(x,y,z)
if pos(y)==1:
  print(y)
else:
  print(z)
### BUGGY CODE ###

def main():
    N=int(input())
    S=input()
    ans=0
    for i in range(N-2):
        for j in range(i+1,N-1):
            if S[i]!=S[j]:
                k1=S[j+1:].count(S[i])
                k2=S[j+1:].count(S[j])
                ans=ans+len(S[j+1:])-k1-k2
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)

main()

### FIXED CODE ###

def main():
    N=int(input())
    S=input()
    k1=S.count("R")
    k2=S.count("B")
    ans=k1*k2*(len(S)-k1-k2)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if j+(j-i)<N and S[i]!=S[j]:
                if S[j+(j-i)]!=S[i] and S[j+(j-i)]!=S[j]:
                    ans-=1
    print(ans)
main()
### BUGGY CODE ###

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

ans = 0

for i in range(n - 1):
    for j in range(i + 1, n):
        ans += (a[i] * a[j]) % (10**9 + 7)

print(ans % (10**9 + 7))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7
ans = 0
v = sum(a)

for i in range(n - 1):
    v -= a[i]
    ans += a[i]*v

print(ans % mod)
### BUGGY CODE ###

n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0
for i in range(1,n):
    dp[i] = min(dp[j]+abs(h[i]-h[j]) for j in range(max(0,i-k),i))
print(dp[-1])

### FIXED CODE ###

def solve():
  n,k = map(int,input().split())
  h = list(map(int,input().split()))
  dp = [float("inf")]*n
  dp[0] = 0
  for i in range(0,n-1):
    for j in range(1,k+1):
      if (i-j)>=-1:
        dp[i+1]=min(dp[i+1],dp[i+1-j]+abs(h[i+1]-h[i+1-j]))
  print(dp[-1])
solve()
### BUGGY CODE ###

s = input()
length = len(s)
cnt = 0
for i in range(length-3):
    for j in range(i+4,length+1):
        cur_num = int(s[i:j])
        # print(cur_num)
        if cur_num % 2019 == 0:
            cnt += 1
print(cnt)

### FIXED CODE ###

s = input()
n = len(s)
p = 2019
ans = 0

num_rem = [0] * p
t = 1
mod = 0
num_rem[mod] = 1
for i in range(n):
    mod = (mod + int(s[-i-1])*t)%p
    num_rem[mod] += 1
    t = (10*t)%p
for m in num_rem:
    ans += (m*(m-1))//2
print(ans)
### BUGGY CODE ###

import numpy as np
from numba import jit
@jit


def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    l = np.array(l)

    tot = 0
    for i in range(n):
        tot += (l[i] * (np.sum(l[i + 1:n], dtype='int64') % (10 ** 9 + 7))) % (10 ** 9 + 7)

    print(tot % (10 ** 9 + 7))


if __name__ == "__main__":
    main()

### FIXED CODE ###



def main():
    n = int(input().strip())
    l = list(map(int, input().split()))
    stack = [0]*n

    totstack = 0
    for i in range(n-1):
        totstack += l[n-i-1]
        stack[n-i-2] = totstack

    tot = 0
    for i in range(n):
        tot += (l[i] * (stack[i] % (10 ** 9 + 7))) % (10 ** 9 + 7)

    print(tot % (10 ** 9 + 7))


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

from scipy.sparse import*
n,*t=map(int,open(0).read().split())
*u,=range(n+1)
a=csgraph.johnson(csr_matrix(([0]*n+t[3::3],(u[1:]+t[1::3],u[:-1]+t[2::3])),[n+1]*2),1,1)[n]
print(int(a)if a<1e18else-1)

### FIXED CODE ###

from heapq import*
n,_,*t=map(int,open(0).read().split())
e=[[]for _ in'_'*n]
for l,r,c in zip(*[iter(t)]*3):e[l-1]+=(c,r-1),
for i in range(n-1):e[i+1]+=(0,i),
d=[0]+[1e18]*n
q=[(0,0)]
while q:
  c,v=heappop(q)
  for b,w in e[v]:
    if b+c<d[w]:
      d[w]=b+c
      heappush(q,(b+c,w))
print(-(d[-2]>1e17)or d[-2])
### BUGGY CODE ###

import bisect
n=int(input())
lists=list(map(int,input().split()))
listss=sorted(lists)

count=0

for i in range(n):
    for j in range(n):
        if i!=j:
            a=listss[i]+listss[j]
            # abs(lists[i]-lists[j]<a<b+cとなるものの個数を求める)
        
            index1= bisect.bisect_left(listss, abs(listss[j]-listss[i])+1)
            index2=bisect.bisect_right(listss,listss[i]+listss[j]-1)

            count+=(index2-index1)
            x=abs(listss[j]-listss[i])
            if  x+1<=listss[i]:
                count-=1
            if x+1<=listss[j]:
                count-=1


print(count//6)

### FIXED CODE ###

import bisect
n=int(input())
lists=list(map(int,input().split()))
lists=sorted(lists)

cnt=0
import math
for i in range(n):
    for j in range(i+1,n):
        #i<j 
        x=lists[i]
        y=lists[j]
        left=i 
        right=j 
        index=bisect.bisect_right(lists,y-x)
        cnt+=min(j-i-1,j-index)

print(cnt)
### BUGGY CODE ###

N = int(input()) + 1
S = " "+input()
d = [[0]*N for _ in range(N)]
r = 0
for i in range(N):
    for j in range(i-1,0,-1):
        d[i][j] = d[i-1][j-1] + 1 if S[i] == S[j] else 0
        r = max(r, min(d[i][j], i-j))
print(r)


### FIXED CODE ###

N = int(input()) + 1
S = " "+input()
d = [[0]*N for _ in range(N)]
r = 0
for i in range(N):
    for j in range(i-1,0,-1):
        d[i][j] = d[i-1][j-1] + 1 if S[i] == S[j] else 0
        r = max(r, min(d[i][j], i-j))
print(r)
### BUGGY CODE ###

class Dict(object):

    m1 = 2 ** 24 - 1
    m2 = 3

    def __init__(self):
        self._dict = ["" for _ in range(self.m1)]

    def insert(self, k):
        i = 0

        while True:
            ix = self._h(k, i)
            if self._dict[ix] == "":
                self._dict[ix] = k
                return
            else:
                i += 1

    def find(self, k):
        i = 0

        while True:
            ix = self._h(k, i)
            if self._dict[ix] == k:
                return ix
            elif self._dict[ix] == "":
                return -1
            else:
                i += 1

    def _h(self, k, i):
        return self._h1(k) + i * self._h2(k)

    def _h1(self, k):
        return k % self.m1

    def _h2(self, k):
        return k % self.m2 + 1


def to_int(s):
    _s = s[::]

    ret = 0
    i = 1
    for e in _s:
        if e == 'A':
            ret += 1 * i
        elif e == 'C':
            ret += 2 * i
        elif e == 'G':
            ret += 3 * i
        elif e == 'T':
            ret += 4 * i
        i *= 4

    return ret


if __name__ == '__main__':
    n = int(input())

    d = Dict()

    for _ in range(n):
        cmd, val = input().split()

        if cmd == "insert":
            d.insert(to_int(val))
        else:
            ans = "yes" if d.find(to_int(val)) != -1 else "no"
            print(ans)

### FIXED CODE ###

M = 1046527
L = 14
H = [""] * M
 
def getChar(ch):
    if ch == 'A':
        return 1
    elif ch == 'C':
        return 2
    elif ch == 'G':
        return 3
    elif ch == 'T':
        return 4
    else:
        return 0
 
def getKey(strings):
    Sum = 0
    p = 1
    for i in xrange(len(strings)):
        Sum += p * getChar(strings[i])
        p *= 5
 
    return Sum
 
def h1(key):
    return key % M
 
def h2(key):
    return 1 + (key % (M-1))
 
def find(strings):
    key = getKey(strings)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == strings:
            return 1
        elif len(H[h]) == 0:
            return 0
        else:
            i += 1
    return 0
 
def insert(strings):
    key = getKey(strings)
    i = 0
    while True:
        h = (h1(key) + i * h2(key)) % M
        if H[h] == strings:
            return 1
        elif len(H[h]) == 0:
            H[h] = strings
            return 0
        else:
            i += 1
    return 0
 
def main():
    n = input()
    for i in xrange(n):
        com = raw_input().split()
        if com[0][0] == 'i':
            insert(com[1])
        else:
            if find(com[1]):
                print 'yes'
            else:
                print 'no'
    return 0
 
main()
### BUGGY CODE ###

def resolve():
    n = int(input())
    s = input()
    rlist = []
    glist = []
    blist = []
    for i in range(n):
        if s[i] == "R":
            rlist.append(i)
        elif s[i] == "G":
            glist.append(i)
        else:
            blist.append(i)
    ans = 0
    for i in range(len(rlist)):

        for j in range(len(glist)):
            r = rlist[i]
            ng = 0
            g = glist[j]
            s = sorted([r, g])
            r = s[0]
            g = s[1]
            if (r-(g-r)) in blist:
                ng += 1
            if (g+(g-r)) in blist:
                ng += 1
            if (r+g) % 2 == 0 and (r+g)//2 in blist:
                ng += 1
            ans += len(blist)-ng
    print(ans)
resolve()

### FIXED CODE ###

def resolve():
    n = int(input())
    s = input()
    rlist = []
    glist = []
    blist = []
    for i in range(n):
        if s[i] == "R":
            rlist.append(i)
        elif s[i] == "G":
            glist.append(i)
        else:
            blist.append(i)
    blist = set(blist)
    ans = 0
    for i in range(len(rlist)):

        for j in range(len(glist)):
            r = rlist[i]
            ng = 0
            g = glist[j]
            s = sorted([r, g])
            r = s[0]
            g = s[1]
            if (r-(g-r)) in blist:
                ng += 1
            if (g+(g-r)) in blist:
                ng += 1
            if (r+g) % 2 == 0 and (r+g)//2 in blist:
                ng += 1
            ans += len(blist)-ng
    print(ans)
resolve()
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
import numpy as np
MAX = max(A)
BIG = 10**9+7
L = len(bin(MAX)[2:])
ans = 0
for j in range(L):
    zero = 0
    one = 0
    for i in range(N):
        if (A[i] >> j) & 1:
            one+=1
        else:
            zero+=1
    ans += ((zero*one)%BIG)*pow(2,j,BIG)
    ans = ans%BIG
print(ans)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
MAX = max(A)
BIG = 10**9+7
L = len(bin(MAX)[2:])
ans = 0
for j in range(L):
    zero = 0
    one = 0
    for i in range(N):
        if (A[i] >> j) & 1:
            one+=1
        else:
            zero+=1
    ans += ((zero*one)%BIG)*pow(2,j,BIG)
    ans = ans%BIG
print(ans)
### BUGGY CODE ###

n, k = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0,0) #index調整

dp = [1<<64] * (n+1)
dp[1] = 0

for i in range(2,n+1):
    for j in range(1,k+1):
        if i - j >= 1:
            dp[i] = min(dp[i-j]+abs(h[i]-h[i-j]), dp[i])
        else:
            break
            
print(dp[n])

### FIXED CODE ###

import numpy as np

n, k = map(int, input().split())
h = np.array([0] + list(map(int, input().split()))) # index調整
dp = np.zeros(n+1,dtype=np.int)

for i in range(2,n+1):
    start = 1 if i - k < 1 else i - k
    dp[i] = min((dp[start:i]+np.abs(h[i]-h[start:i])))            
print(dp[n])
### BUGGY CODE ###

import math

k = int(input())

result = 0

for a in range(1, k+1):
  for b in range(1, k+1):
    for c in range(1, k+1):
      n = math.gcd(a, b)
      m = math.gcd(n, c)
      result += m

print(result)

### FIXED CODE ###

import math
import itertools

k = int(input())
result = 0

for a in range(1, k+1):
  for b in range(a+1, k+1):
    for c in range(b+1, k+1):
      r = math.gcd(math.gcd(a, b), c)
      r *= 6
      result += r

for a in range(1, k+1):
  for b in range(a+1, k+1):
    r = math.gcd(a, b)
    r *= 6
    result += r
    
for a in range(1, k+1):
  result += a

print(result)
### BUGGY CODE ###

from math import ceil

N, K = map(int, input().split())
A = list(map(int, input().split()))
# N, K = 2*10**5, 1
# A = [10**9]*N

def solve(x):
    m = 0
    for a in A:
        m += a//x - (a%x == 0)
    # print(x, m)
    return m <= K

ok, ng = max(A), 0
while abs(ok-ng > 0.1**6):
    mid = (ok+ng)/2
    # print(mid)
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ceil(mid))

### FIXED CODE ###

BIG = 10**10

N, K = map(int, input().split())
A = list(map(int, input().split()))
# N, K = 2*10**5, 2*10**5
# A = [10**9]*N

def solve(x):
    m = 0
    for a in A:
        m += -(-(a//x))
    # print(x, m)
    return m > K

A = [a*BIG for a in A]

# c = 0
ok, ng = 0, max(A)
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    # print(mid)
    if solve(mid):
        ok = mid
    else:
        ng = mid
    # c += 1

# print(c)

print(-(-ok//BIG))
### BUGGY CODE ###

n = int(input())
lst = [0,1,2,3,4,5,4,3,2,1]
ans = 0

for _ in range(len(str(n))+1):
    num = n%10
    ans += lst[num]
    if num > 5:
        n = n//10 +1
    elif num < 5:
        n = n//10
    else:
        if (n//10)%10 > 4:
            n = n//10 +1
        else:
            n = n//10

print(ans)


### FIXED CODE ###

n = input()
N = []
ans = 0
l = len(str(n))

for i in range(l):
    N.append(int(n[-i-1]))
N.append(0)

for i in range(l+1):
    if N[i]<5:
        ans += N[i]
    elif N[i]>5:
        ans += 10-N[i]
        N[i+1] += 1
    elif N[i+1]>4:
        ans += 10-N[i]
        N[i+1] += 1
    else:
        ans += N[i]

print(ans)