Harryxun/stf_run huggingface dataset:
n,m=map(int,input().split())
a=list(map(int,input().split()))
mm=[0,2,5,5,4,5,6,3,7,6]

dp=[0]
m = [mm[i] for i in range(n) if i in a]
for i in range(1,n+1):
    tres=[-10**10]
    for sm in m:
        if i - sm >= 0:
            tres.append(dp[i-sm]+1)
    dp.append(max(tres))
k=dp[n]
res = []
a.sort(reverse=True)
while n > 0:
    for sa in a:
        if dp[n-mm[sa]]==dp[n]-1:
            res.append(sa)
            n -= mm[sa]
            break

print("".join(map(str,res)))

### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
mm=[0,2,5,5,4,5,6,3,7,6]

dp=[0]
m = [mm[i] for i in range(10) if i in a]
for i in range(1,n+1):
    tres=[-10**10]
    for sm in m:
        if i - sm >= 0:
            tres.append(dp[i-sm]+1)
    dp.append(max(tres))
k=dp[n]
res = []
a.sort(reverse=True)
while n > 0:
    for sa in a:
        if n-mm[sa] >= 0 and dp[n-mm[sa]]==dp[n]-1:
            res.append(sa)
            n -= mm[sa]
            break

print("".join(map(str,res)))
if r-l >= 2019:  # 2019の倍数がある
    ans = 0
elif r-l >= 673:  # 673の倍数,3の倍数がある
    ans = 0
elif l <= 2019 and 2019 <= r:  # 2019がある
    ans = 0
elif l <= 673 and 673 <= r and r-l >= 3:  # 673があって,3の倍数もある
    ans = 0
elif r-l >= (r % 2019):  # lとrの間に2019の倍数がある
    ans = 0
elif r-l >= (r % 673) and r-l >= 3:  # lとrの間に673の倍数があって,3の倍数もある
    ans = 0
else:
    ans = (l*(l+1)) % 2019

print(ans)

### FIXED CODE ###

l, r = list(map(int, input().split()))
# b = list(map(int, input().split()))
# 2019=3*673
ans = 2019
for i in range(l, r+1):
    for j in range(i+1, r+1):
        if (i*j) % 2019 == 0:
            print(0)
            exit()
        else:
            if (i*j) % 2019 < ans:
                ans = (i*j) % 2019

print(ans)
n=int(input())
a=[]
for i in range(n):
  b=int(input())
  a.append(b)
s=a.copy()
for i in range(n):
  if s[i]==max(s):
    print(s[i])
  else:
    del s[i]
    print(max(s))

### FIXED CODE ###

n=int(input())
a=[]
for i in range(n):
  b=int(input())
  a.append(b)
s=a.copy()
a=sorted(a,reverse=True)

if a[0]==a[1]:
  for i in range(n):
    print(a[0])
  exit()
for i in range(n):
  if s[i]==a[0]:
    print(a[1])
  else:
    print(a[0])
#!/usr/bin/env python3
# import time


def main():
    # from scipy.special import comb
    from math import factorial

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

    num_lst = [0] * (N + 1)
    for a in A:
        num_lst[a] += 1

    ans = 0
    for num in num_lst:
        # ans += comb(num, 2, exact=True)
        if num >= 2:
            ans += int(factorial(num) / 2 / factorial(num - 2))
        else:
            ans += 0

    # start = time.time()
    for a in A:
        print(ans - (num_lst[a] - 1))
    # end = time.time() - start
    # print(f'{end:6f}', '[sec]')


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
def main():
    import time

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

    num_lst = [0] * (N + 1)
    for a in A:
        num_lst[a] += 1

    ans = 0
    for num in num_lst:
        # ans += comb(num, 2, exact=True)
        ans += num * (num - 1) // 2

    start = time.time()
    for a in A:
        print(ans - (num_lst[a] - 1))
    end = time.time() - start
    # print(f'{end:6f}', 's')


if __name__ == '__main__':
    main()
S = input()

subStringList = []
length = len(S)

for i in range(length) :
    for j in range(1,length+1):
        if (i+j <= length) :
            subStringList.append(S[i:i+j])
        else:
            break


for s in subStringList[:]:
    for letter in s:
        if (not(letter in "ATGC")):
            subStringList.remove(s)
            break

print(len(max(subStringList)))


### FIXED CODE ###

S = input()

subStringList = [S]
length = len(S)

counter = 0
before = 1

while (not(counter == before)):
    before = counter
    for s in subStringList[:]:
        for letter in s:
            if (not(letter in "ATGC")):
                subStringList += s.split(letter)
                subStringList.remove(s)
                counter = len(subStringList)
                break

print(len(max(subStringList,key=len)))
print ('A B C = ?')
a,b,c = input(),input(),input()

if (int(a) + int(b) >= int(c)):
    print ('Yes')
else:
    print ('No')

### FIXED CODE ###

a,b,c = input().split()

if (int(a) + int(b) >= int(c)):
    print ('Yes')
else:
    print ('No')
n, k = map(int, input().split())
import math
def kai(x):
  if x == 0:
    return 1
  else:
    return math.factorial(x)
  
for i in range(1, k+1):
  print((kai(k-1)*kai(n-k+1)/(kai(i-1)*kai(k-i)*kai(i)*kai(n-k+1-i))) % (10**9 +7))




### FIXED CODE ###

n, k = map(int, input().split())
import math
mod = (10**9) +7
def kai(x):
  if x == 0:
    return 1
  elif x < 0:
    return 1
  else:
    return math.factorial(x)
  
for i in range(1, k+1):
  if n - k  + 1 >= i:
    result = (kai(k-1)*kai(n-k+1))//(kai(i-1)*kai(k-i)*kai(i)*kai(n-k+1-i))
    result2 = result % mod
    print(result2)
  else:
    print(0)
N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))

for i in range(N):
    if V[i] <= C[i]:
        continue
    Max = Max + V[i] - C[i]
print(Max)

### FIXED CODE ###

N = int(input())
V = list(map(int,input().split()))
C = list(map(int,input().split()))
Max = 0

#先頭
for i in range(N):
    if V[i] <= C[i]:
        continue
    X,Y = V[i],C[i]
    tmpMax = X - Y
    for j in range(i+1,N):
        if V[j] <= C[j]:
            continue
        if Max < (X + V[j]) - (Y + C[j]):
            X = X + V[j]
            Y = Y + C[j]
            tmpMax = X - Y
    if Max < tmpMax:
        Max = tmpMax
        
print(Max)
import sys
import itertools
import numpy as np

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

N = readline().decode().strip()
K = int(readline())
cnt = 0
tmp = 0

for i in N:
    if i == '1':
        cnt += 1
        continue
    else:
        tmp = i
        break
ans = N[tmp-1] if K <= cnt else tmp

print(ans)


### FIXED CODE ###

import sys
import itertools
import numpy as np

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

N = readline().decode().strip()
K = int(readline())
cnt = 0
tmp = 0

for i in N:
    if i == '1':
        cnt += 1
        continue
    else:
        tmp = int(i)
        break
ans = N[tmp-1] if K <= cnt else tmp

print(ans)
b= input()

if b=='A':
  b='T'
elif b=='T':
  b='A'
elif b=='G':
  b='C':
elif b=='C':
  b='G'
print(b)

### FIXED CODE ###

b = input()

if b.find('A') == 0:
    ac = b.replace('A','T')
elif b.find('T') == 0:
    ac = b.replace('T','A')
elif b.find('G') == 0:
    ac = b.replace('G','C')
elif b.find('C') == 0:
    ac = b.replace('C','G')

print(ac)
import sys
import math

def main():
    a, b, k = [int(x) for x in sys.stdin.read().split()]
    query_range = list(range(a, b + 1))
    print(a, b)
    exit()
    if a == b:
        res = query_range
    elif k >= math.ceil((b - a + 1) / 2):
        res = query_range
    else:
        res = query_range[:k] + query_range[-k:]

    for i in res:
        print(i)
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

import sys

a, b, k = map(int, sys.stdin.readline().split())

def main():
    if k >= b - a + 1:
        res = list(range(a, b+1))
    else:
        res = set(range(a, a+k)) | set(range(b, b-k, -1))
        res = sorted(res)
    return res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')
s = input()
alphabet = list('abcdefghijklmnopqrstuvwxyz')
print(alphabet[alphabet.index(s)+1])


### FIXED CODE ###

s = input()
alphabet = list('abcdefghijklmnopqrstuvwxyz')
print(alphabet[alphabet.index(s)+1])
if B == 1:
  print(A)
  exit()
C = A*B
D = []
for i in range(1,int(math.sqrt(C))):
  if A % i == 0 and B % i == 0:
    A = A // i
    B = B // i
    D.append(i)
    C = A*B
for j in range(1,int(math.sqrt(C))):
  if A % j == 0 and B % j == 0:
    A = A // j
    B = B // j
    D.append(j)
    C = A*B
for k in range(1,int(math.sqrt(C))):
  if A % k == 0 and B % k == 0:
    A = A // k
    B = B // k
    D.append(k)
    C = A*B
p = np.prod(D)
if p != 0:
  C = C*p
print(C)

### FIXED CODE ###

import math
import numpy as np
A,B = list(map(int,input().split()))
if A == 1:
  print(B)
  exit()
if B == 1:
  print(A)
  exit()
C = A*B
D = []
for i in range(int(math.sqrt(C)),1,-1):
  if A % i == 0 and B % i == 0:
    D.append(i)
    A = A // i
    B = B // i
    C = A*B
if len(D) != 0:
  p = np.prod(D)
  C = C*p
print(C)
#d-even relation
#ふかさ優先探索の実装
#再起関数の実装を行う
n=int(input())
visitedlist=[-1 for  i in range(n)]
lists=[tuple(map(int,input().split())) for i in range(n-1)]
kilist=[[] for i in range(n)]
for i in lists:
    kilist[i[0]-1].append(i[1:])
    kilist[i[1]-1].append(i[0:3:2])
visitedlist[0]=1
anslist=[0 for i in range(n)]
#開始地点1のところは0を基準としている
#1には初めに訪れる
def search(i):
        flag=0
        for j in kilist[i-1]:
            if visitedlist[j[0]-1]<0:
                visitedlist[j[0]-1]=1
                flag+=1
                anslist[j[0]-1]=anslist[i-1]+j[1]
        if flag>0:    
            for k in kilist[i-1]:
                return search(k[0])           
search(1)
print(anslist)

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000)

n=int(input())
visitedlist=[-1 for  i in range(n)]
kilist=[[] for i in range(n)]
anslist=[0 for i in range(n)]
searchedlist=[-1 for i in range(n)]
for i in range(n-1):
        a,b,c=map(int,input().split())
        kilist[a-1].append((b,c))
        kilist[b-1].append((a,c))
def search(i):
        searchedlist[i-1]=1
        visitedlist[i-1]=1
        flag=0
        for j in kilist[i-1]:
            if visitedlist[j[0]-1]<0:
                visitedlist[j[0]-1]=1
                flag+=1
                anslist[j[0]-1]=anslist[i-1]+j[1]
        else:
            pass

        if flag>0:    
            for k in kilist[i-1]:
                if searchedlist[k[0]-1]==-1:
                    search(k[0])
search(2)
for i in anslist:
    print(i%2)
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
ans = 1
ansb = 1
if K % 2 == 0:
    for i in range(K//2):
        if A[0]*A[1] >= A[-1]*A[-2]:
            ans *= A[0]*A[1]
            A.pop(0)
            A.pop(1)
        elif A[0]*A[1] < A[-1]*A[-2]:
            ans *= A[-1]*A[-2]
            A.pop(-1)
            A.pop(-2)
elif K == 1:
    ans = A[-1]
elif K % 2 == 1 and K != 1:
    B = list.copy(A)
    for i in range(K//2):
        if A[0]*A[1] >= A[-1]*A[-2]:
            ans *= A[0]*A[1]
            A.pop(0)
            A.pop(0)
        elif A[0]*A[1] < A[-1]*A[-2]:
            ans *= A[-1]*A[-2]
            A.pop(-1)
            A.pop(-1)
    ans *= A[-1]
    for i in range(K//2):
        if B[0]*B[1] <= B[-1]*B[-2]:
            ansb *= B[0]*B[1]
            B.pop(0)
            B.pop(0)
        elif B[0]*B[1] > B[-1]*B[-2]:
            ansb *= B[-1]*B[-2]
            B.pop(-1)
            B.pop(-1)
    ansb *= B[-1]
    ans = max(ans,ansb)
print(ans%(7+10**9))
        

### FIXED CODE ###

from collections import deque #両端から取り出すのが速い
N,K = map(int,input().split())
A = list(map(int,input().split()))
pos = []
neg = []
for a in A:
    if a >= 0:
        pos.append(a)
    else:
        neg.append(-a)
pos = deque(sorted(pos))
neg = deque(sorted(neg))
mod = 10**9+7
ans = 1
sign = 1
if K%2 == 1: #Kが奇数の時pos（ある場合）から必ず１つ取る
    if len(pos) > 0:
        ans = ans*pos.pop() % mod
    else:
        ans = ans*neg.popleft() % mod
        sign *= -1
    K -= 1
while K > 0: #偶数の場合と奇数の残りの処理
    if len(pos) == 1 and len(neg) == 1:
        ans = ans*-neg.pop()*pos.pop() % mod
    elif sign == 1:#通常バージョン
        if len(pos) < 2 or (len(neg) >= 2 and pos[-2]*pos[-1] < neg[-2]*neg[-1]):
            ans = ans*neg.pop()*neg.pop() % mod
        else:
            ans = ans*pos.pop()*pos.pop() % mod
    else:#奇数の前処理で負になっている場合(最終結果も負になるので小さくしたい)
        if len(pos) < 2 or (len(neg) >= 2 and pos[-2]*pos[-1] < neg[-2]*neg[-1]):
            ans = ans*neg.popleft()*neg.popleft() % mod
        else:
            ans = ans*pos.popleft()*pos.popleft() % mod
    K -= 2
ans = ans*sign % mod
print(ans)
s=input()
ss=s[1:-1]

if s[0]=="A" and  ss.count("C")==1:
      s[0]="a"
      s=list(s)
      s.remove("C")
      if ''.join(s).islower():
            print("AC")
else:
      print("WA")


### FIXED CODE ###

s=input()
if s[0]!="A":
      print("WA")
      exit()
if s[2:-1].count("C")!=1:
      print("WA")
      exit()

s=list(s)
s[0]="a"
s.remove("C")
if "".join(s).islower():
      print('AC')
else:
      print("WA")
import math
import collections

n = int(input())
d = list(map(int,input().split()))
MOD = 998244353

if d[0]!=0:
  print(0)
  exit()
  
#print(n,d)
cnt = dict(collections.Counter(d))

ans = 1
for i in range(len(dict(cnt))-1):
  val_1 = cnt[i]
  val_2 = cnt[i+1]
  ans *= val_1**val_2

print(ans%MOD)

### FIXED CODE ###

import collections
 
n = int(input())
d = list(map(int,input().split()))
MOD = 998244353
#頂点1が0でないとだめ
if d[0]!=0:
  print(0)
  exit()
  
#同じ長さの位置に何個頂点があるか
cnt = dict(collections.Counter(d))
#頂点1だけが0じゃないとだめ
if cnt[0]==1:
  m = max(cnt)
  #一番大きい数字までにちゃんとすべての数字が揃ってないとだめ
  for i in range(m):
    if i not in cnt:
      print(0)
      exit()
  ans = 1
  for i in range(m):
    val_1 = cnt[i]
    val_2 = cnt[i+1]
    ans *= (val_1**val_2)%MOD
 
  print(ans%MOD)
else:
  print(0)
a=list(map(int,input().split()))
K=int(input)
maxa=a.pop(a.index(max(a)))
print((maxa*(2**K))+sum(a))

### FIXED CODE ###

a=list(map(int,input().split()))
K=int(input())
maxa=a.pop(a.index(max(a)))
print((maxa*(2**K))+sum(a))
a = input()
b = input()

print(a+b)

### FIXED CODE ###

inp = str(input()).split(" ")
print(inp[1]+inp[0])
n = int(input())

#1行ずつ読んでやる方がスマートだけど、とりあえず見た目わかりやすい方で

t = [0] * n
x = [0] * n
y = [0] * n

t[0] = 0
x[0] = 0
y[0] = 0

for i in range(n):
    t[i+1],x[i+1],y[i+1] = map(int,input().split())

### FIXED CODE ###

n = int(input())

#1行ずつ読んでやる方がスマートだけど、とりあえず見た目わかりやすい方で

t = [0] * (n+1)
x = [0] * (n+1)
y = [0] * (n+1)

t[0] = 0
x[0] = 0
y[0] = 0

for i in range(n):
    t[i+1],x[i+1],y[i+1] = map(int,input().split())

aFlg = True #ダメとなるまでは見なしOK

for i,tm in enumerate(t):
  xm = 0
  ym = 0
  if i > 0:
    if x[i] > x[i-1]:
      xm = x[i] - x[i-1]
    else:
      xm = x[i-1] - x[i]

    if y[i] > y[i-1]:
      ym = y[i] - y[i-1]
    else:
      ym = y[i-1] - y[i]

    if xm + ym > (t[i] - t[i-1]):  #動きすぎ
      aFlg = False
      break
    elif ((t[i] - t[i-1]) - (xm+ym))%2 == 1:  #そこには止まれない
      aFlg = False
      break

if aFlg:
  print('Yes')
else:
  print('No')
import sys
sys.setrecursionlimit(250000)

from scipy.special import comb
# a = comb(n, r)

def main():
    # a,b,c,d = map(int, input().split())
    n = int(input())

    sum = 10**n - 9**n*2 + 8**n
    # temp = (10 ** 9 + 7)
    # sum = 0
    # if n >= 2:
    #     for i in range(2, n+1):
    #         a = int(comb(i, 2)) * 2
    #         a = (a * 8**(i-2)) % temp
    #         sum = sum + a
    # else:
    #     print(0)

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

main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(250000)

from scipy.special import comb
# a = comb(n, r)

def main():
    # a,b,c,d = map(int, input().split())
    n = int(input())

    sum = 10**n - 9**n*2 + 8**n
    # temp = (10 ** 9 + 7)
    # sum = 0
    # if n >= 2:
    #     for i in range(2, n+1):
    #         a = int(comb(i, 2)) * 2
    #         a = (a * 8**(i-2)) % temp
    #         sum = sum + a
    # else:
    #     print(0)

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

main()
for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        m_max = 0
        for k in range(1, int(log10(n)) + 1):
            m = (n // (10**k)) * (n % (10**k))
            if m >= m_max:
                m_max = m
        n = m_max
        j += 1
    print(j)

### FIXED CODE ###

from math import log10

for i in range(int(input())):
    n = int(input())
    j = 0
    while n >= 10:
        n = max((n // (10**k)) * (n % (10**k)) for k in range(1, int(log10(n)) + 1))
        j += 1
    print(j)
from math import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)


### FIXED CODE ###

from fractions import gcd

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

forward = []
backward = [0 for x in range(n)]

if n == 2:
    print(max(a[0], a[1]))
    exit(0)

for i in range(n):
    if i == 0:
        forward.append(a[i])
    else:
        forward.append(gcd(forward[i - 1], a[i]))


for i in range(n - 1, -1, -1):
    if i == n - 1:
        backward[i] = a[i]
    else:
        backward[i] = gcd(backward[i + 1], a[i])


ans = 1

for i in range(n):
    if i == 0:
        ans = max(ans, backward[1])
    elif i == n - 1:
        ans = max(ans, forward[n - 2])
    else:
        ans = max(ans, gcd(forward[i - 1], backward[i + 1]))

print(ans)
K = int(input())
S = str(input())
l = len(S)
ST = str()
if K >= l:
  for i in range(l):
    ST += str(S[i])
  print(ST)
else:
  for i in range(K):
    ST += str(S[i])
  print(ST +'...')

### FIXED CODE ###

N = str(input())
l = len(N)
e = int(N[l-1])
if e == 3:
  print('bon')
elif e in [0,1,6,8]:
  print('pon')
else:
  print('hon')
n = int(input())
for  i in range(1, 10):
	if n % i == 0 and (n // i) < 10:
    	print('Yes')
        break
else:
	print('No')

### FIXED CODE ###

n = int(input())
for i in range(1, 10):
    if n % i == 0 and (n // i) < 10:
        print('Yes')
        break
else:
    print('No')
S = list(input())
S_len = len(S)

for i in range(S_len-1):
    S[i+1]
def dfs(S):
    slen = len(S)
    for i in range(slen -1 ):
        if S[i] != S[i+1]:
            del S[i:i+2]
            dfs(S)
            break;
    End_len = len(S)
    ans = S_len - End_len
    return ans

if __name__ == '__main__':
    print(dfs(S))

### FIXED CODE ###

s = input()
count_0 = s.count('0')
count_1 = s.count('1')
print(2*min(count_0,count_1))
params = input().split(' ')
n = eval(params[1])

AC = set()
WA = {}

penalties = 0
points = 0

for i in range(n):
    submission = input().split(' ')
    p = eval(submission[0])
    status = submission[1]
    
    if p in AC:
        continue
    
    if status == 'AC':
        AC.add(p)
        points += 1
        penalties += getPenalties(p)
    
    elif p in WA:
        WA[p] += 1

    else:
        WA[p] = 1
    


def getPenalties(x):
    if x in WA:
        return WA[x]
    return 0

### FIXED CODE ###

params = input().split(' ')
m = eval(params[0])
n = eval(params[1])

penaltyCount = []

for i in range(m):
    penaltyCount.append(0)

penalties = 0
points = 0

for i in range(n):
    submission = input().split(' ')
    p = eval(submission[0])-1
    status = submission[1]
    
    if penaltyCount[p] == -1:
        continue

    if status == 'AC':
        penalties += penaltyCount[p]
        penaltyCount[p] = -1
        points += 1
    else:
        penaltyCount[p] += 1


print(points, penalties)
N,K = map(int,input().split())
V = list(map(int,input().split()))

value = max_value = 0
for j in range(K//2):
    for i in range(K-j+1):
        if i == K-j:
            value = V[:K-j]
        else:
            value = V[:i]+V[-(K-j-i):]
        value.sort()
        
        if value[j] > 0:
            s = sum([i for i in value if i>0])
        else:
            s = sum(value[j:])
                
        if  s > max_value:
            max_value = s

print(max_value)

### FIXED CODE ###

N,K = map(int,input().split())
V = list(map(int,input().split()))

value = max_value = 0
for j in range(K//2+1):
    for i in range(K-j+1):
        if K-j >= N:
            value = V
        else:
            if i == K-j:
                value = V[:K-j]
            else:
                value = V[:i]+V[-(K-j-i):]
        value.sort()
        # print(i,j,value)


        jj = min(len(value)-1,j)
        if value[jj] <= 0:
            s = sum(value[jj:])
        else:
            s = sum([i for i in value if i>0])

        if  s > max_value:
            max_value = s
print(max_value)
n = 10**2
k = [0]*10**2
for x in range(1,10):
    for y in range(1,10):
        for z in range(1,10):
            for i in range(n+1):
                if (x+y+z)**2 -(x*y+y*z+z*x) == i:
                    k[i-1] += 1
for i in range(int(input())):
    print(k[i])

### FIXED CODE ###

n = 10**4
ans = [0]*10**4
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            a = (x+y+z)**2 -(x*y+y*z+z*x)
            if a <= n:
                ans[a-1] += 1
for i in range(int(input())):
    print(ans[i])
import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i and a[0][0] < c:
        x, y = a[0]
        if i < y:
            a[0] = x, y - i
            i = 0
        else:
            heapq.heappop(a)
            i -= y
    if i < b
        heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))


### FIXED CODE ###

import heapq
from itertools import repeat, starmap
from operator import mul

R = lambda: map(int, input().split())
n, m = R()
a = list(zip(R(), repeat(1)))
heapq.heapify(a)
for _ in range(m):
    b, c = R()
    i = b
    while i:
        x, y = a[0]
        if x >= c:
            break
        heapq.heappop(a)
        d = min(i, y)
        i -= d
        y -= d
        if y:
            heapq.heappush(a, (x, y))
    heapq.heappush(a, (c, b - i))
print(sum(starmap(mul, a)))
x,n = map(int,input().split())

p = list(map(int,input().split()))
s = []

for i in range(101):
  if i not in p:
    s.append(i)

    
if s == [0]:
  print(0)

else:
  

  k = abs(x-s[0])
  del s[0]
  for j in range(100-n):
    if abs(x-s[j]) < k:
      k = abs(x-s[j])
    else:
      answer = s[j-1]
      break
  else:
    answer = s[100-n-1]
  print(answer)




    

### FIXED CODE ###

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

for i in range(5):
  if p[i] == 0:
    x = i + 1
    
print(x)
N = list(input())

N.reverse()

ans = 0
flag = False

for i,s in enumerate(N):
    n = int(s)
    
    if flag:
        n += 1
    
    if n<5:
        ans += n
        flag = False
    elif n>5:
        ans += 10-n
        flag = True
    else:
        if i==N-1:
            ans += n
            flag = False
            
        if int(N[i+1])<5:
            ans += n
            flag = False
        else:
            ans += 10-n
            flag = True

if flag:
    ans += 1
    
print(ans)
        
        
    
    

### FIXED CODE ###


N = list(input())

N.reverse()

ans = 0
flag = False
L = len(N)
for i,s in enumerate(N):
    n = int(s)
    
    if flag:
        n += 1
    
    if n<5:
        ans += n
        flag = False
    elif n>5:
        ans += 10-n
        flag = True
    else:
        if i==L-1:
            ans += n
            flag = False
            break
            
        if int(N[i+1])<5:
            ans += n
            flag = False
        else:
            ans += 10-n
            flag = True

if flag:
    ans += 1
    
print(ans)