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

N = int(input())
S = list(map(int, input().split()))
b = []
for i in range(N):
  if (i + N) % 2 == 0:
    b.append(S[i])
  else:
    b.insert(0, S[i])
for i in range(N - 1):
  print(b[i], end = ' ')
print(b[N - 1])

### FIXED CODE ###

N = int(input())
S = list(map(int, input().split()))
b = [0 for i in range(N)]
if N % 2 == 0:
  for i in range(N):
    if i % 2 == 0:
      b[(N + i) // 2] = S[i]
    else:
      b[(N - i) // 2] = S[i]
else:
  b[N // 2] = S[0]
  for i in range(1, N):
    if i % 2 == 1:
      b[(N + i) // 2] = S[i]
    else:
      b[(N - i) // 2] = S[i]
for i in range(N - 1):
  print(b[i], end = ' ')
print(b[N - 1])
### BUGGY CODE ###

n = int(input())
h = list(map(int, input().split()))
c = 0
for i in range(n-1):
    tmp = 0
    for j in range(i, n-1):
        if h[j] >= h[j+1]:
            tmp += 1
        else:
            break
    c = max(tmp, c)
print(c)


### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
dp = [0] * n
for i in range(1, n):
    if h[i-1] >= h[i]:
        dp[i] = dp[i-1] + 1
print(max(dp))
### BUGGY CODE ###

n = int(input())
a = list(map(int, input().split()))
a.sort()
 
dp = [True] * n
for i in range(n):
    for j in range(n):
        if i==j:
            continue
            
        if dp[j]:
            if a[j]%a[i]==0:
                dp[j] = False

cnt = 0
for i in range(n):
    if dp[i]:
        cnt += 1

print(cnt)

### FIXED CODE ###

from collections import Counter


n = int(input())
a = list(map(int, input().split()))
c = Counter(a) # Count num and construct dictionary
c = sorted(c.items(), key=lambda x:x[0]) # align key
ans = 0
isOK = [True] * (10**6+1)

for k, v in c:
    if not isOK[k]:
        continue

    if v > 1:
        for i in range(k, len(isOK), k):
            isOK[i] = False
        continue

    ans += 1
    for i in range(2*k, len(isOK), k):
        isOK[i] = False

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

import queue
N=int(input())
A=sorted([int(i) for i in input().split()],reverse=True)
B=[2**(len(bin(i))-2) for i in A]
R=[0 for i in range(N)]
D=dict()
for i in range(N):
    if not(A[i] in D):
        D[A[i]]=queue.Queue()
    D[A[i]].put(i)
ans=0
for i in range(N):
    if R[i]==1:
        continue
    if (B[i]-A[i]) in D:
        flag=1
        if not(D[B[i]-A[i]].empty()):
            itmp=D[A[i]].get()
            j=D[B[i]-A[i]].get()
            #R[i]=1
            R[j]=1
            #print(i,j)
            ans+=1
print(ans)



### FIXED CODE ###

N=int(input())
A=sorted([int(i) for i in input().split()],reverse=True)
B=[2**(len(bin(i))-2) for i in A]
D=dict()
for i in range(N):
    if not(A[i] in D):
        D[A[i]]=1
    else:
        D[A[i]]+=1
ans=0
for i in range(N):
    if D[A[i]]<=0:
        continue
    if B[i]==2*A[i]:
        if D[A[i]]>=2:
            D[A[i]]-=2
            ans+=1
    else:
        if (B[i]-A[i]) in D:
            if D[B[i]-A[i]]!=0:
                D[A[i]]-=1
                D[B[i]-A[i]]-=1
                ans+=1
print(ans)
### BUGGY CODE ###

N = int(input())
results = []
for i in range(1,N+1):
    for j in range(1,N+1):
        if i+j == N:
            si = str(i)
            sj = str(j)
            count1 = 0
            for x in si:
                count1 += int(x)
            for y in sj:
                count1 += int(y)
            results.append(count1)
print(min(results))

### FIXED CODE ###

N = int(input())
results = []
for i in range(1,N):
    results.append(sum(map(int,str(i))) + sum(map(int,str(N-i))))
print(min(results))
### BUGGY CODE ###

A,B,K = map (int, input().split())
l = []
for i in range(A,B+1):
    if i < A+K or B - K < i:
        l.append(i)

for i in l:
    print(i)

### FIXED CODE ###

A,B,K = map (int, input().split())
l = []
if A+K > B+1:
    for i in range(A,B+1):
        if i < A+K or B - K < i:
            l.append(i)
else :
    for i in range(A,A+K):
        if i < A+K or B - K < i:
            l.append(i)
if A+K-1 >= B - K+1:
    for i in range(A+K,B+1):
        l.append(i)
else :
    for i in range(B-K+1,B+1):
        l.append(i)


for i in l:
    print(i)
### BUGGY CODE ###

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


sum = 0
while(n > a):
    n = n-a-b
    sum += a
if n < 0:
    print(sum)
else:    
    print(sum+n)


### FIXED CODE ###

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

sum = n//(a+b)*a
res = n%(a+b)
sum += min(res,a)

print(sum)
### BUGGY CODE ###

N = int(input())
S = input()

S1, S2 = S[:N], S[N:][::-1]

dic = {}
keys = []
Ans = 0

for i in range(2 ** N):
    red, blue, red2, blue2 = "", "", "", ""
    # 半分ずつbit全探索
    bits = bin(2 ** N + i)[3:]
    for j in range(N):
        if bits[j] == "0":
            red += S1[j]
            red2 += S2[j]
        else:
            blue += S1[j]
            blue2 += S2[j]
    # あとで数える際に使うので記録しておく
    keys.append(red2 + "-" + blue2)
    # 半分全列挙
    key = red + "-" + blue
    if key not in dic.keys():
        dic[key] = 1
    else:
        dic[key] += 1

for key in keys:
    Ans += dic.get(key, 0)

print(Ans)


### FIXED CODE ###

N = int(input())
S = input()

S1, S2 = S[:N], S[N:][::-1]

dic = {}
keys = []
Ans = 0

for i in range(2 ** N):
    red, blue, red2, blue2 = "", "", "", ""
    # 半分ずつbit全探索
    bits = bin(2 ** N + i)[3:]
    for j in range(N):
        if bits[j] == "0":
            red += S1[j]
            red2 += S2[j]
        else:
            blue += S1[j]
            blue2 += S2[j]
    # あとで数える際に使うので記録しておく
    keys.append(red2 + "-" + blue2)
    # 半分全列挙
    key = red + "-" + blue
    if key not in dic.keys():
        dic[key] = 1
    else:
        dic[key] += 1

for key in keys:
    Ans += dic.get(key, 0)

print(Ans)
### BUGGY CODE ###

N, A, B, K = map(int, input().split())
maxAB = max(A, B)
minAB = min(A, B)
ans = 0


def cmb(n, r):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return fac[n] * finv[r] * finv[n-r] % mod


mod = 998244353  # 問題によって変える、ここは素数でないとうまく動かない
N_cmb = 0
N_cmb += N  # 入力の制約によって変えるところ、nCrの計算で欲しいnの最大値
fac = [1, 1]  # 階乗テーブル
finv = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for ZZZ in range(2, N_cmb + 1):
    fac.append((fac[-1] * ZZZ) % mod)
    inverse.append(mod-inverse[mod % ZZZ]*(mod//ZZZ) % mod)
    finv.append((finv[-1] * inverse[-1]) % mod)

for i in range(N+1):
    j = (K - maxAB * i) // minAB
    if (K - maxAB * i) % minAB == 0 and 0 <= j <= N:
        #print(i, j)
        for h in range(min(i, j)+1):
            if i + j - h <= N:
                #print(cmb(N, h), cmb(N - h, i - h), cmb(N - i, j - h))
                ans += ((cmb(N, h) * cmb(N - h, i - h)) %
                        mod) * cmb(N - i, j - h)
                ans %= mod
print(ans)


### FIXED CODE ###

N, A, B, K = map(int, input().split())
maxAB = max(A, B)
minAB = min(A, B)
ans = 0


def cmb(n, r):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return fac[n] * finv[r] * finv[n-r] % mod


mod = 998244353  # 問題によって変える、ここは素数でないとうまく動かない
N_cmb = 0
N_cmb += N  # 入力の制約によって変えるところ、nCrの計算で欲しいnの最大値
fac = [1, 1]  # 階乗テーブル
finv = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for ZZZ in range(2, N_cmb + 1):
    fac.append((fac[-1] * ZZZ) % mod)
    inverse.append(mod-inverse[mod % ZZZ]*(mod//ZZZ) % mod)
    finv.append((finv[-1] * inverse[-1]) % mod)

for i in range(min(N+1, K//maxAB+1)):
    j = (K - maxAB * i) // minAB
    if (K - maxAB * i) % minAB == 0 and 0 <= j <= N:
        #print(i, j)
        ans += cmb(N, i) * cmb(N, j) % mod
        ans %= mod
print(ans)
### BUGGY CODE ###

def main():
    N = int(input())

    dp = [1] * (N+1)
    for i in range(2, N+1):
        for j in range(i, N+1, i):
            dp[j] = dp[j] + 1
    ans = 0
    for i in range(1, N+1):
        ans = ans + dp[i] * i
    print(ans)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    N = int(input())

    dp = [1] * (N+1)
    for i in range(2, N+1):
        for j in range(i, N+1, i):
            dp[j] = dp[j] + 1
    ans = 0
    for i in range(1, N+1):
        ans = ans + dp[i] * i
    print(ans)

main()
### BUGGY CODE ###

import bisect
import sys
input=sys.stdin.readline
N=int(input())

cnt=0
L=[]
for i in range(N):
    n=int(input())
    L.append(n)
#print(L)
Q=[-1,10**10]
for i in range(N):
    if bisect.bisect_left(Q,L[i])==1:
        Q.insert(1,L[i])
    #elif bisect.bisect_left(Q,L[i])==len(Q)-1:
        #Q.insert(len(Q)-1,L[i])
    else:
        Q[bisect.bisect_left(Q,L[i])-1]=L[i]
    #print(Q)
print(len(Q)-2)

### FIXED CODE ###

import bisect
import sys
input=sys.stdin.readline
from collections import deque
N=int(input())

cnt=0
L=[]
for i in range(N):
    n=int(input())
    L.append(n)
#print(L)
Q=[-1,10**10]
Q=deque()
#Q.appendleft(10**10)
#print(Q)
for i in range(N):
    if bisect.bisect_left(Q,L[i])==0:
        Q.appendleft(L[i])
    #elif bisect.bisect_left(Q,L[i])==len(Q)-1:
        #Q.insert(len(Q)-1,L[i])
    else:
        Q[bisect.bisect_left(Q,L[i])-1]=L[i]
#print(Q)
print(len(Q))
### BUGGY CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()
 
n,m = na()
a = na()

import heapq

aa = []
for k in a:
  heapq.heappush(aa, k)

for i in range(m):
    b,c = na()
    for j in range(b):
      p = heapq.heappop(aa)
      if p >= c:
        heapq.heappush(aa, p)
        break
      else:
        heapq.heappush(aa, c)

ans = 0
for i in range(n):
  ans += heapq.heappop(aa)

print(ans)

### FIXED CODE ###

import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,m = na()
a = na()

bc = [na() for i in range(m)]
bc.sort(key=lambda x:x[1])

for b,c in bc[::-1]:
  a.extend([c]*b)
  if len(a)>2*n:
    break

a.sort(reverse=True)
print(sum(a[:n]))
### BUGGY CODE ###

n, m, k = map(int, input().split())
# tmp = m
mod = 998244353
ans = m * pow(m-1, n-1, mod)
ans %= mod
ncm = 1
for i in range(k):
    ncm *= n-1-i
    ncm *= pow(i+1, mod-2, mod)
    ans += m * pow(m-1, n-i-2, mod) * ncm
    ans %= mod
print(ans)


### FIXED CODE ###

n, m, k = map(int, input().split())
# tmp = m
mod = 998244353
ans = m * pow(m-1, n-1, mod)
ans %= mod
ncm = 1
ncm_list = [0 for _ in range(k)]
for i in range(k):
    ncm *= n-1-i
    ncm *= pow(i+1, mod-2, mod)
    ncm %= mod
    ncm_list[i] = ncm

powm_list = [0 for _ in range(k)]
tmp = m * pow(m-1, n-k-1, mod)
if k != 0:
    powm_list[k-1] = tmp
    for i in range(k-2, -1, -1):
        tmp *= (m-1)
        tmp %= mod
        powm_list[i] = tmp

for i in range(k):
    ans += ncm_list[i] * powm_list[i]
    ans %= mod

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

import sys
#import numpy as np
#import math
#from fractions import Fraction
#import itertools
#import heapq

h,w,k=map(int,input().split())
s = [list(map(int, input())) for _ in range(h)]
res=0
ans=10**9
for i in range(2**(h-1)):
    p=1
    partation=[-1]*(h-1)

    for j in range(h-1):
        if i &(1<<j):
            partation[j]=1
            p+=1
    g=[0]*p
    res=0
    l=0
    while l<w:
        m=0
        for j in range(h):
            g[m]+=s[j][l]
            if g[m]>k:
                res+=1
                g=[0]*p
                break
            if j<h-1 and partation[j]==1:
                m+=1
        else:
            l+=1
    res+=p-1
    if res<ans:
        ans=res
print(ans)

### FIXED CODE ###

import sys
#import numpy as np
#import math
#from fractions import Fraction
#import itertools
#import heapq

h,w,k=map(int,input().split())
s = [list(map(int, input())) for _ in range(h)]
res=0
ans=10**9
for i in range(2**(h-1)):
    p=1
    partation=[-1]*(h-1)

    for j in range(h-1):
        if i &(1<<j):
            partation[j]=1
            p+=1
    g=[0]*p
    res=0
    l=r=0
    f=False
    while r<w:
        m=0
        for j in range(h):
            g[m]+=s[j][r]
            if g[m]>k:
                res+=1
                g=[0]*p
                if l==r:
                  f=True
                l=r
                break
            if j<h-1 and partation[j]==1:
                m+=1
        else:
            r+=1
        if f:
          break
    else:
      res+=p-1
      if res<ans:
          ans=res
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()

cnt = 0
R, B, G = [], [], []
for i in range(N):
    if S[i] == "R":
        R.append(i)
    elif S[i] == "B":
        B.append(i)
    else:
        G.append(i)

for r in R:
    for b in B:
        for g in G:
            l = sorted([r, b, g])
            if l[2]-l[1] != l[1]-l[0]:
                cnt += 1
# print(R, G, B)
print(cnt)


### FIXED CODE ###

N = int(input())
S = input()

ans = S.count("R")*S.count("B")*S.count("G")
for i in range(N):
    for d in range(N):
        j = i+d
        k = j+d
        if k < N:
            if S[i] != S[j] and S[k] != S[j] and S[k] != S[i]:
                ans -= 1
print(ans)
### BUGGY CODE ###

N,M = [int(x) for x in input().split()]
map = [[0 for j in range(N+1)] for i in range(N+1)]
li_e = []

def dfs(v,li_gr,flg):
    if(not flg[v]):
        flg[v] = True
        li_gr.append(v)
        for u,exist in enumerate(map[v]):
            if(exist == 1 and not flg[u]):
                dfs(u,li_gr,flg)

for i in range(M):
    A,B = [int(x) for x in input().split()]
    map[A][B] = 1
    map[B][A] = 1
    li_e.append((A,B))

for i in range(M):
    flg = [False]*(N+1)
    li_gr = []
    A = li_e[i][0]
    B = li_e[i][1]
    map[A][B] = 0
    map[B][A] = 0
    for j in range(1,N+1):
        if(not flg[j]):
            li_gr.append([])
            dfs(j,li_gr[-1],flg)
    ans = 0
    grps = len(li_gr)
    for p in range(grps):
        for q in range(p+1,grps):
            ans += len(li_gr[p])*len(li_gr[q])
    print(ans)


### FIXED CODE ###

import sys
#sys.setrecursionlimit(1000000)

class UnionFind():
    def __init__(self,n):
        self.parent = [-1 for _ in range(n)]

    def size(self,x):
        return -self.parent[self.find(x)]

    def find(self,x):
        if(self.parent[x]<0):
            return x
        else:
            self.parent[x]=self.find(self.parent[x])
            return self.parent[x]

    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if(x == y):
            return False
        if(self.size(x)<self.size(y)):
            self.parent[y]+=self.parent[x]
            self.parent[x]=y
        else:
            self.parent[x]+=self.parent[y]
            self.parent[y]=x
        return True

    def same(self,x,y):
        return self.find(x)==self.find(y)

N,M = [int(x) for x in input().split()]
A = [0]*M
B = [0]*M
ans = [0]*M
for i in range(M):
    A[i],B[i] = [int(x) for x in input().split()]
ans[M-1] = int(N*(N-1)/2)
uni = UnionFind(N)
for i in range(M-1,0,-1):
    ans[i-1]=ans[i]
    if(not uni.same(A[i]-1,B[i]-1)):
        ans[i-1]-=uni.size(A[i]-1)*uni.size(B[i]-1)
        uni.unite(A[i]-1,B[i]-1)
for i in ans:
    print(i)
### BUGGY CODE ###

N,K=map(int,input().split())
h=[int(x) for x in input().split()]
h.extend([0]*(N+1000))
dp=[float('inf')]*(len(h))
dp[0] = 0
for i in range(N):
  for j in range(1,K+1):
    dp[i+j]=min(dp[i+j],dp[i]+abs(h[i] - h[i+j]))
     
print(dp[N-1])

### FIXED CODE ###

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

dp=[float('inf')]*N
dp[0] = 0

for i, hi in enumerate(h):
  if i > 0:
    x = max(0,i-K)
    dp[i]=min([dpj + abs(hi-hj) for dpj, hj in zip(dp[x:i], h[x:i])])
     
print(dp[N-1])
### BUGGY CODE ###

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

if A[0] != 0:
    print(0)
    exit()
if A.count(0) != 1:
    print(0)
    exit()

k = max(A)

count = 1
result = 1
Re = 1
while True:

    Back = Re
    Re = A.count(count)

    result *= (Back ** Re) % 998244353
    result %= 998244353

    count += 1

    if result == 0:
        print(0)
        exit()

    if k < count:
        break

print(result)








### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
k = max(A)

def pow_k(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % 998244353
        x *= x % 998244353
        n //= 2

    return K * x % 998244353


R = [0] * (k + 1)
result = 1
for i in A:
    R[i] += 1

if A[0] != 0 or R[0] != 1:
    print(0)
    exit()

for j in range(k):
    result *= pow_k(R[j], R[j + 1])

    if result == 0:
        print(0)
        exit()

print(result % 998244353)
### BUGGY CODE ###

n = int(input())
s = input()

ans = 0
for j in range(n):
    for i in range(j + ans):
        while (i + ans < n) & (i + ans < j):
            if (s[i:i+ans+1] == s[j:j+ans+1]):
                ans += 1
            else:
                break
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
i = 0
j = 0
r = 0
while i < n:
    if s[i:j] in s[j:]:
        r = max(r, j - i)
        j += 1
    else:
        i += 1
print(r)
### BUGGY CODE ###

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

b = x[0]
for i in range(x[0]+1, x[1]+1):
    b = b^i

print(b)

### FIXED CODE ###

x = list(map(int, input().split()))
a = [x[0]-1, x[1]]
ans = 0
for i in a:
    n = i%4
    if n == 1:
        as1 = 1
    elif n == 2:
        as1 = 1^i
    elif n == 3:
        as1 = 0
    else:
        as1 = 0^i
    ans = ans^as1

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

s = input()
ans = 0
for _ in range(500000):
    temp1 = s.count("01")
    ans += temp1
    s = s.replace("01", "")
    temp2 = s.count("10")
    ans += temp2
    s = s.replace("10", "")
    if temp1 == 0 and temp2 == 0:
        break
    
print(ans*2)


### FIXED CODE ###


s = input()

blue = s.count("1")
red = s.count("0")

print(2*min(blue, red))
### BUGGY CODE ###

S=input()
N=len(S)
mod=[0 for i in range(2019)]
mod2=0
for i in range(N-1,-1,-1): 
  s=int(S[i])*(10**(N-1-i))
  mod2+=s%2019
  mod2=mod2%2019
  mod[mod2]+=1
ans=0
for i in range(2019):
  k=mod[i]
  if i==0:
    if k>=2:
      ans+=k*(k-1)//2+k
    else:
      ans+=k
  else:
    if k>=2:
      ans+=k*(k-1)//2
print(ans) 

### FIXED CODE ###

import numpy as np
S=input()
N=len(S)
mod=[0 for i in range(2019)]
mod2=0
ten=1
for i in range(N-1,-1,-1): 
  s=int(S[i])*ten
  mod2+=np.mod(s,2019)
  mod2=np.mod(mod2,2019)
  mod[mod2]+=1
  ten=(ten*10)%2019
ans=0
for i in range(2019):
  k=mod[i]
  if i==0:
    if k>=2:
      ans+=k*(k-1)//2+k
    else:
      ans+=k
  else:
    if k>=2:
      ans+=k*(k-1)//2
print(ans)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

n, q = [int(item) for item in input().split()]
for i in range(q):
    v, w = [int(item) - 1 for item in input().split()]
    while v != w:
        if v > w:
            v = (v - 1) // n
        else:
            w = (w - 1) // n
    print(v + 1)

### FIXED CODE ###

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

ans = ""
n, q = [int(item) for item in input().split()]
if n == 1:
    for i in range(q):
        v, w = [int(item) for item in input().split()]
        print(min(v, w))
    exit()

for i in range(q):
    v, w = [int(item) - 1 for item in input().split()]
    while v != w:
        if v > w:
            v = (v - 1) // n
        else:
            w = (w - 1) // n
    print(v + 1)
### BUGGY CODE ###

drc = [(0, 1), (1, 0)]


def dfs(r, c):
    ret = []
    for dr, dc in drc:
        nr, nc = r + dr, c + dc
        if nr < H and nc < W and board[nr][nc].isdigit():
            cand = dfs(nr, nc)
            if len(cand) > len(ret) or (len(cand) == len(ret) and cand > ret):
                ret = cand
    return [board[r][c]] + ret


while True:
    W, H = map(int, input().split())
    if not (W | H):
        break
    board = [input() for _ in range(H)]
    ans = ''
    for r in range(H):
        for c in range(W):
            if board[r][c].isdigit() and board[r][c] != '0':
                cand = ''.join(dfs(r, c))
                # print(cand)
                if len(cand) > len(ans) or (len(cand) == len(ans) and cand > ans):
                    ans = cand
    print(ans)

### FIXED CODE ###

drc = [(0, 1), (1, 0)]


def dfs(r, c):
    if (r, c) in memo:
        return memo[r, c]
    ret = ''
    for dr, dc in drc:
        nr, nc = r + dr, c + dc
        if nr < H and nc < W and board[nr][nc].isdigit():
            cand = dfs(nr, nc)
            if len(cand) > len(ret) or (len(cand) == len(ret) and cand > ret):
                ret = cand
    memo[r, c] = board[r][c] + ''.join(ret)
    return board[r][c] + ret


while True:
    W, H = map(int, input().split())
    if not (W | H):
        break
    board = [input() for _ in range(H)]
    memo = dict()
    ans = ''
    for r in range(H):
        for c in range(W):
            if board[r][c].isdigit() and board[r][c] != '0':
                cand = dfs(r, c)
                if len(cand) > len(ans) or (len(cand) == len(ans) and cand > ans):
                    ans = cand
    print(ans)
### BUGGY CODE ###

K=int(input())
queue=[1,2,3,4,5,6,7,8,9]
for i in range(K-1):
    t=queue.pop(0)
    if t%10!=0:
        queue.append(t*10+t%10-1)
    queue.append(t*10+t%10)
    if t%10!=9:
        queue.append(t*10+t%10+1)
print(queue[0])

### FIXED CODE ###

K=int(input())
queue=[1,2,3,4,5,6,7,8,9]
count=0
for i in range(K-1):
    t=queue[i]
    if t%10!=0:
        queue.append(t*10+pow(t,1,10)-1)
    queue.append(t*10+pow(t,1,10))
    if t%10!=9:
        queue.append(t*10+pow(t,1,10)+1)
print(queue[K-1])
### BUGGY CODE ###

from itertools import accumulate
import numpy as np

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

for q in range(min(42,k)):
  b = [0]*(n+1)
  for i in range(n):
    l = max(0, i-a[i])
    r = min(i+a[i]+1, n)
    b[l] += 1
    if r <= n-1: b[r] -= 1
  
  a = list(accumulate(b))
  a = a[:-1]
   
  if np.all(a == n):
    break

print(*a)

### FIXED CODE ###

#%%time
from itertools import accumulate
import numpy as np
from numba import njit

n, k = map(int, input().split())
a = np.array(list(map(int, input().split())), dtype=np.int64)

@njit
def loop1(a):
  #b = [0]*(n+1)
  b = np.zeros(n+1, dtype=np.int64)
  for i in range(n):
    l = max(0, i-a[i])
    r = min(i+a[i]+1, n)
    b[l] += 1
    if r <= n-1: b[r] -= 1
  
  b = np.cumsum(b)[:-1]
  return b
  #a = list(accumulate(b))
  #a = a[:-1]
   
  #if np.all(a == n):
   # break

for q in range(min(42, k)):
  a = loop1(a)
    
print(*a)
### BUGGY CODE ###

import numpy as np
S=input()
N=len(S)

mats=np.zeros((10, 2019, 2019))
for i in range(2019):
  for j in range(10):
    tmp=(i*10+j)%2019
    mats[j][tmp][i]+=1
    
out=0
dp=np.zeros(2019)
dp[int(S[0])]=1
for i in range(1, N):
    dp=np.dot(mats[int(S[i])], dp)
    dp[int(S[i])]+=1
    out+=dp[0]
print(int(out))

### FIXED CODE ###

MOD=2019
S=input()
N=len(S)
nums=[0]*N
nums[-1]=int(S[-1])%MOD
for i in range(-2, -N-1, -1):
  nums[i]=(int(S[i])*pow(10, -(i+1), MOD)+nums[i+1])%MOD

a=[0]*2019
for i in range(N):
  a[nums[i]]+=1
  
print(a[0]+sum([(a[i]*(a[i]-1))//2 for i in range(2019)]))
### BUGGY CODE ###

n = int(input())
emp = list()
count = 0

for a in range(n)[1:]:
    for b in range(n)[1:]:
        if a + b == n:
            for i in str(a)+str(b):
                count += int(i)
            emp.append(count)

print(min(emp))

### FIXED CODE ###

def findSumOfDigits(n):
    sum =0
    while n > 0:
        sum += n % 10
        n = n//10
    return sum

N = int(input())
examples = list()

for i in range((N//2)+1)[1:]:
    A = i
    B = N - i
    total = findSumOfDigits(A) + findSumOfDigits(B)
    examples.append(total)

print(min(examples))