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

from collections import Counter

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

    retu = Counter()
    gyo = Counter()

    ipt = [[] for _ in range(H)]

    for _ in range(M):
        a, b = map(int, input().split())
        retu[a-1] += 1
        gyo[b-1] += 1
        ipt[a-1].append(b-1)

    rm = retu.most_common()
    rmm = rm[0][1]
    gm = gyo.most_common()
    gmm = gm[0][1]

    for r in rm:
        if r[1] < rmm:
            break
        for g in gm:
            if g[1] < gmm:
                break

            if g[0] not in ipt[r[0]]:
                return rmm+gmm
    
    return rmm+gmm-1

print(solver())

### FIXED CODE ###

from collections import Counter

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

    retu = Counter()
    gyo = Counter()

    ipt = [set() for _ in range(H)]

    for _ in range(M):
        a, b = map(int, input().split())
        retu[a-1] += 1
        gyo[b-1] += 1
        ipt[a-1].add(b-1)

    rm = retu.most_common()
    rmm = rm[0][1]
    gm = gyo.most_common()
    gmm = gm[0][1]

    for r in rm:
        if r[1] < rmm:
            break
        for g in gm:
            if g[1] < gmm:
                break

            if g[0] not in ipt[r[0]]:
                return rmm+gmm
    
    return rmm+gmm-1

print(solver())
### BUGGY CODE ###

N=int(input())
A=list(map(int,input().split()))
for k in range(N):
    count=0
    n=A.pop(k)
    for i in range(N-2):
        for j in range(i+1,N-1):
            if A[i]==A[j]:
                count+=1
    print(count)
    A.insert(k,n)

        

### FIXED CODE ###

from itertools import combinations
N=int(input())
A=list(map(int,input().split()))
B=[0]*(N+1)
ans=0
for i in range(N):
    B[A[i]]+=1
for i in range(1,N+1):
    ans+=B[i]*(B[i]-1)//2
for k in range(0,N):
    print(ans-B[A[k]]+1)
### BUGGY CODE ###

N=int(input())
A=[int(_) for _ in input().split()]
B=[]
for i in range(N):
  for j in range(N):
    if A[i]%A[j]==0:
      B.append(i)
C=([x for x in set(B) if B.count(x) < 2])
print(len(C))

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



from collections import Counter
def gcd(a, b):
    while b: a, b = b, a % b
    return a
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i * i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += i % 2 + (3 if i % 3 == 1 else 1)
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k
 
    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return ret
  
n=int(readline())
a=list(map(int,readline().split()))  
A=set(a)
ans=0
c=Counter(a)
for i in a:
  if c[i]>=2:
    continue
  chk=set(divisors(i))
  if chk&A=={i}:
    ans+=1
print(ans)
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

for _ in range(Q):
    a , b = map(int,input().split())
    a = a - 1
    point[a] += b

def dfs(now , prev = -1):
    for next in graph[now]:
        if next == prev:
            continue
        point[next] += point[now]
        dfs(next , now)

dfs(0)
print(*point)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 6)
def input():
    return sys.stdin.readline()[:-1]
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)
    graph[b - 1].append(a - 1)

for _ in range(Q):
    a , b = map(int,input().split())
    a = a - 1
    point[a] += b

def dfs(now , prev = -1):
    for next in graph[now]:
        if next == prev:
            continue
        point[next] += point[now]
        dfs(next , now)

dfs(0)
print(*point)
### BUGGY CODE ###

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

for _ in range(M):
  B, C = map(int,input().split())
  for _ in range(B):
    CardList.append(C)
CardList = sorted(CardList)
FinalList = CardList[-N:]

print(sum(FinalList))

### FIXED CODE ###

n,m = map(int, input().split())
List = list(map(int, input().split()))
List.sort()
cand = []
for _ in range(m):
  b,c = map(int,input().split())
  cand.append((b,c))
bc = sorted(cand, key=lambda x: x[1], reverse=True)
i = 0
for b, c in bc:
    while b:
        if i < n and List[i] < c:
            List[i] = c
            b -= 1
        else:
            break
        i += 1
print(sum(List))
### BUGGY CODE ###

k = int(input())
a =7
for i in range(k+1):
  if a%k ==0:
    print(i+1)
    break
  i +=1
  a = a + 7*10**(i)
else:
  print("-1")


### FIXED CODE ###

k = int(input())
if k % 2 == 0 or k%5==0:
    print(-1)
    exit()
a = 7
ans = 1
while True:
    if a % k == 0:
        print(ans)
        exit()
    a = (a*10+7) % k
    ans += 1
### BUGGY CODE ###

N,K=list(map(int,input().split()))
dp_list=[10**10]*110000
h=list(map(int,input().split()))
dp_list[0]=0
for i in range(N):
    for j in range(1,K+1):
        k=i+j
        if k<N:
            # if dp_list[j] is None:dp_list[j]=abs(h[j]-h[i])+dp_list[i]
            dp_list[k]=min(dp_list[k],abs(h[k]-h[i])+dp_list[i])
print(dp_list[N-1])



### FIXED CODE ###

import numpy as np
N,K=list(map(int,input().split()))
dp_list=np.full(N,10**10,dtype=int)
h=list(map(int,input().split()))
h=np.array(h)
dp_list[0]=0
for i in range(1,N):
        dp_list[i:i+K] = np.fmin(dp_list[i:i+K], dp_list[i-1] + np.abs(h[i:i+K] - h[i-1]))
print(dp_list[-1])
### BUGGY CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
import collections
count_dict = collections.Counter(a)
# print(count_dict.most_common())
ans = 0
for i in range(len(count_dict) - k):
    ans += count_dict.most_common()[len(count_dict)-i-1][1]
print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
a = list(map(int, input().split()))
import collections
count_dict = collections.Counter(a)
# print(count_dict.most_common())
ans = 0
unique = count_dict.most_common()
for i in range(len(count_dict) - k):
    ans += unique[len(count_dict)-i-1][1]
print(ans)
### BUGGY CODE ###

def make_divisors(n):
    div=set()
    i = 1
    ap=div.add
    while i*i <= n:
        if n % i == 0:
            ap(i)
            ap(n//i)
        i += 1
    return div-{n}
def main():
    from collections import Counter
    n,*a=map(int,open(0).read().split())
    d=Counter(a)
    s=set(a)
    c=0
    for t in s:
        if d[t]<2:
            for t in make_divisors(t):
                if t in s:break
            else:c+=1
    print(c)
main()


### FIXED CODE ###

m=8**7
c=[0]*m
for a in[*open(0)][1].split():c[int(a)]+=1
i=r=0
while~i+m:
 i+=1;r+=c[i]==1
 if c[i]:c[::i]=[0]*-(-m//i)
print(r)
### BUGGY CODE ###

import sys
import numpy as np
H, W = map(int, input().split())
S = [line.strip("\n") for line in sys.stdin]

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = np.zeros((H, W), dtype=int)
trailRight = np.zeros((H, W), dtype=int)
trailUp = np.zeros((H, W), dtype=int)
trailDown = np.zeros((H, W), dtype=int)

for i in range(H):  # 各行について下に見ていく
    for j in range(W):  # その行の各列について右に見ていく
        if S[i][j] == '#':
            pass  # そのマスに置いたとき照らすのは0マス(置けないので)
        else:
            if i == 0 and j == 0:  # 左上
                trailLeft[i][j] = 1
                trailUp[i][j] = 1
            elif i == 0:  # 最上行
                trailLeft[i][j] = trailLeft[i][j - 1] + 1
                trailUp[i][j] = 1
            elif j == 0:  # 最左列
                trailLeft[i][j] = 1
                trailUp[i][j] = trailUp[i - 1][j] + 1
            else:
                trailLeft[i][j] = trailLeft[i][j - 1] + 1
                trailUp[i][j] = trailUp[i - 1][j] + 1

        k = H - i - 1  # H-1 to 0
        l = W - j - 1  # W-1 to 0
        # 左上に見ていく
        if S[k][l] == "#":
            pass
        else:
            if k == H - 1 and l == W - 1:  # 右下
                trailRight[k][l] = 1
                trailDown[k][l] = 1
            elif k == H - 1:  # 最下行
                trailRight[k][l] = trailRight[k][l + 1] + 1
                trailDown[k][l] = 1
            elif l == W - 1:  # 最右列
                trailRight[k][l] = 1
                trailDown[k][l] = trailDown[k + 1][l] + 1
            else:
                trailRight[k][l] = trailRight[k][l + 1] + 1
                trailDown[k][l] = trailDown[k + 1][l] + 1

print(np.max(trailLeft + trailRight + trailUp + trailDown - 3))


### FIXED CODE ###

# can't AC without numpy, Python array handling with for is SLOW
import numpy as np
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
S = (np.array(S) == ".") * 1

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = np.zeros((H, W), dtype=int)
trailRight = np.zeros((H, W), dtype=int)
trailUp = np.zeros((H, W), dtype=int)
trailDown = np.zeros((H, W), dtype=int)

for i in range(H):
    if i == 0:
        trailUp[i] = S[i]
        trailDown[H - i - 1] = S[H - i - 1] * 1
    else:
        trailUp[i] = (trailUp[i - 1] + 1) * S[i]
        trailDown[H - i - 1] = (trailDown[H - i] + 1) * S[H - i - 1]

for j in range(W):
    if j == 0:
        trailLeft[:, j] = S[:, j]
        trailRight[:, W - j - 1] = S[:, W - j - 1] * 1
    else:
        trailLeft[:, j] = (trailLeft[:, j - 1] + 1) * S[:, j]
        trailRight[:, W - j - 1] = (trailRight[:, W - j] + 1) * S[:, W - j - 1]

print(np.max(trailLeft + trailRight + trailUp + trailDown - 3))
### BUGGY CODE ###

X = int(input())

def prime_list(X):
    N = X
    flg = True
    while flg :
        for i in range(2,int(N**(1/2))+1):
            if N % i == 0:
                N = N + 1
                flg = True
                break
            else:
                flg = False
    return N



print(prime_list(X))

### FIXED CODE ###

import math
X = int(input())

def prime_list(X):
    N = X
    while True :
        for i in range(2,int(math.sqrt(N))+1):
            if N % i == 0:
                N = N + 1
                break
        else:
            break
    return N



print(prime_list(X))
### BUGGY CODE ###

N= int(input())
Alist = list(map(int, input().split())) 
res = 1
if N % 2 ==0:
    for i in range(0,N//2):
        if Alist.count(2*i+1) != 2:
            print(0)
            exit()
    for j in range(1,N//2+1):
        res = res*2 % (10**9+7)
    print(res)

elif N % 2 ==1:
    if Alist.count(0) != 1:
        print(0)
        exit()
    else:
        for i in range(1,(N+1)//2):
            if Alist.count(2*i) != 2:
                print(0)
                exit()
    for j in range(1,(N+1)//2):
        res = res*2 % (10**9+7)
    print(res)

### FIXED CODE ###

from collections import Counter

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

count = Counter(Alist)
res = 1
if N % 2 ==0:
    for i in range(1,N,2):
        if count[i] != 2:
            print(0)
            exit()
else:
    if count[0] != 1:
        print(0)
        exit()
    else:
        for i in range(2,N,2):
            if count[i] != 2:
                print(0)
                exit()
print(2**(N//2) % (10**9+7))
### BUGGY CODE ###

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

num=[]
for i in range(n):
    num.append(int(input()))
    
for i in range(n):
    print(max(num[:i]+num[i+1:]))

### FIXED CODE ###

import sys
input = sys.stdin.readline
import numpy as np
n = int(input()) 
num = [input() for _ in range(n)] 
num = np.array(num).astype("int64")
#ma=max(num)
#ind=num.index(ma)
sorted_num=sorted(num)
ma=sorted_num[-1]
ma2=sorted_num[-2]
for i in range(n):
    if ma != num[i]:
        print(str(ma).strip())
    else:
        print(str(ma2).strip())
### BUGGY CODE ###

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = two_int()
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    if S not in dicts[P]:
        dicts[P].append(S)
    


#各県でsort
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])



import bisect

for i in inputs:
    P,S=i
    pref_str=str(P)
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_str.zfill(6)+city_str.zfill(6))

### FIXED CODE ###

def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))
import sys
input = sys.stdin.readline

N,M = two_int()

inputs =[]

dicts={}

for i in range(M):
    P,S = input().split()
    S=int(S)
    inputs.append([P,S])
    
    if P not in dicts:
        dicts[P]=[]
    
    dicts[P].append(S)
    


#各県でsort
pref_strs={}
for k, v in dicts.items():
    dicts[k]=sorted(dicts[k])
    pref_strs[k]=k.zfill(6)

import bisect

for i in inputs:
    P,S=i
    
    city_index = bisect.bisect_right(dicts[P], S)
    city_str=str(city_index)
    
    print(pref_strs[P]+city_str.zfill(6))
### BUGGY CODE ###

# -*- coding:utf-8 -*-
N = int(input())
a = list(map(int, input().split()))
b = sum(a)
minimum = float('inf')
for tmp in range(1,N):
    c = sum(a[tmp:len(a)])
    d = abs(b-2*c)
    minimum = min(minimum, d)
print(minimum)

### FIXED CODE ###

# -*- coding:utf-8 -*-
N = int(input())
a = list(map(int, input().split()))
b = sum(a)
c = 0
minimum = float('inf')
for tmp in range(0,N-1):
    c += a[tmp]    
    d = abs(c-(b-c))
    minimum = min(minimum, d)
print(minimum)
### BUGGY CODE ###

import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
Max = sys.maxsize
from math import factorial

def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


n,k = m()

s = [[] for i in range(n)]

for i in range(n-1):
	a,z = m()
	s[a-1].append(z-1)
	s[z-1].append(a-1)

co = k * cmb(k-1,len(s[0]),mod)
co %= mod

def dfs(tree,now,be):
	global co,d
	if len(tree[now]) != 1:
		ma = k - 2
		mm = len(tree[now]) - 1
		co *= cmb(ma,mm,mod)
		co %= mod
		for i in range(mm+1):
			if s[now][i] != be:
				dfs(tree,s[now][i],now)


for i in range(len(s[0])):
	dfs(s,s[0][i],0)


print(co)

### FIXED CODE ###

import sys,collections as cl,bisect as bs,math
sys.setrecursionlimit(100000)
Max = sys.maxsize
from math import factorial

def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    return g1[n] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


n,k = m()

s = [[] for i in range(n)]

for i in range(n-1):
	a,z = m()
	s[a-1].append(z-1)
	s[z-1].append(a-1)

co = k * cmb(k-1,len(s[0]),mod)
co %= mod

def dfs(tree,now,be):
	global co,d
	if len(tree[now]) != 1:
		ma = k - 2
		mm = len(tree[now]) - 1
		co *= cmb(ma,mm,mod)
		co %= mod
		for i in range(mm+1):
			if s[now][i] != be:
				dfs(tree,s[now][i],now)


for i in range(len(s[0])):
	dfs(s,s[0][i],0)


print(co)
### BUGGY CODE ###

def wf(d):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        d[i][j] = min(d[i][j],d[i][k]+d[k][j])
  return d

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

d = [[float('inf') for i in range(N)] for i in range(N)]
for _ in range(M):
  a,b,c = map(int,input().split())
  d[a-1][b-1] = c
  d[b-1][a-1] = c

for i in range(N):
  d[i][i] = 0

wf(d)

from collections import deque

ans = float('inf')
for start_i in Rs:
  q = deque()
  q.append([start_i-1,0,[start_i-1]])
  while len(q) > 0:
    prv_node, prv_cost, done = q.pop()

    min_cost = float('inf')
    min_nodes = []
    for r in Rs:
      r -= 1
      if r in done: continue
      if min_cost > d[prv_node][r]:
        min_cost = d[prv_node][r]
        min_nodes = [r]
      elif min_cost == d[prv_node][r]:
        min_cost = d[prv_node][r]
        min_nodes.append(r)
    
    for node in min_nodes:      
      if len(done)+1 == R:
        if ans > prv_cost+min_cost: ans = prv_cost+min_cost
      else: q.append([node, prv_cost+min_cost, done+[node]])

print(ans)

### FIXED CODE ###

import sys, copy
from itertools import permutations

def wf(d):
  for k in range(N):
    for i in range(N):
      for j in range(N):
        d[i][j] = min(d[i][j],d[i][k]+d[k][j])
  return d

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

d = [[float('inf') for i in range(N)] for i in range(N)]
for _ in range(M):
  a,b,c = map(int,sys.stdin.readline().split())
  d[a-1][b-1] = c
  d[b-1][a-1] = c

for i in range(N):
  d[i][i] = 0

wf(d)

ans = float('inf')
for prm in permutations(Rs, R):
  ans = min(ans, sum([d[prm[i-1]-1][prm[i]-1] for i in range(1,R)]))
print(ans)
### BUGGY CODE ###

import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

k = ri()
a = k%10
if a in [1, 3, 7, 9]:
    s = 7
    while s%k:
        s = s*10 + 7
    print(math.ceil(math.log10(s)))
else:
    print(-1)




### FIXED CODE ###

import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

k = ri()
a = k%10
if a in [1, 3, 7, 9]:
    s = 7
    cnt = 1
    while s%k:
        s = s*10 + 7
        s %= k
        cnt += 1
    print(cnt)
else:
    print(-1)
### BUGGY CODE ###

n = int(input())
ans = 0
s = str(n)
l = len(s)

N = [0 for i in range(l)]

for i in range(l):
    N[i] = int(s[-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)


### FIXED CODE ###


ans = 0
s = input()
l = len(s)

N = [0 for i in range(l)]

for i in range(l):
    N[i] = int(s[-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)
### BUGGY CODE ###

N_n_osatsu, Y_sum_money = map(int, input().split())

if N_n_osatsu*1000 > Y_sum_money or N_n_osatsu*10000 < Y_sum_money:
    print("-1 -1 -1")
    exit()

rest_money = Y_sum_money
n_each_osatsu_list = [] # 万札、五千円札、千円札の枚数の2重リスト

for n_10000 in range(int(Y_sum_money/10000 +1)): # 万札枚数。0枚からスタート
    rest_money = Y_sum_money - 10000*n_10000
    if rest_money == 0: # 万札だけで目標金額になる場合
        n_each_osatsu_list.append([n_10000, 0, 0])
        break
    if rest_money < 0: # もう万札が追加できない場合
        break
    for n_5000 in range(int(rest_money/5000 + 1)): # 万札枚数決定後に5000円の枚数を探索。5000円0枚からスタート
        if (rest_money - n_5000*5000) >= 0:
            n_1000 = int((rest_money - n_5000*5000)/1000)
            n_each_osatsu_list.append([n_10000, n_5000, n_1000])

n_sum_osatsu_list = [sum(x) for x in n_each_osatsu_list] # お札合計枚数のリスト

try:
    print(*n_each_osatsu_list[n_sum_osatsu_list.index(N_n_osatsu)], sep=" ")
except:
    print("-1 -1 -1")

### FIXED CODE ###

N_n_osatsu, Y_sum_money = map(int, input().split())

rest_money = Y_sum_money
rest_n_osatsu = N_n_osatsu
n_each_osatsu_list = [] # 万札、五千円札、千円札の枚数の2重リスト

def skip_search(rest_money, rest_n_osatsu):  # 明らかに無理な場合、処理をスキップ。これを入れないと制限時間超過
    if rest_n_osatsu*1000 > rest_money or rest_n_osatsu*10000 < rest_money:
        return True

for n_10000 in range(int(Y_sum_money/10000 +1)): # 万札枚数。0枚からスタート
    rest_money = Y_sum_money - 10000*n_10000
    rest_n_osatsu = N_n_osatsu - n_10000
    if skip_search(rest_money, rest_n_osatsu):
        break

    if rest_money == 0: # 万札だけで目標金額になる場合
        n_each_osatsu_list.append([n_10000, 0, 0])
        break

    for n_5000 in range(int(rest_money/5000 + 1)): # 万札枚数決定後に5000円の枚数を探索。5000円0枚からスタート
        rest_money = Y_sum_money - 10000*n_10000 - 5000*n_5000
        rest_n_osatsu = N_n_osatsu - n_10000 - n_5000
        if skip_search(rest_money, rest_n_osatsu):
            break
        n_1000 = int(rest_money/1000)
        n_each_osatsu_list.append([n_10000, n_5000, n_1000])

n_sum_osatsu_list = [sum(x) for x in n_each_osatsu_list] # お札合計枚数のリスト

try:
    print(*n_each_osatsu_list[n_sum_osatsu_list.index(N_n_osatsu)], sep=" ")
except:
    print("-1 -1 -1")