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

N,Q = map(int, input().split())
L = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
cnt = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    cnt[p-1] += x


flag = [-1]*N
q = [0]
flag[0] = 1
while q:
    temp = q.pop(0)
    for i in L[temp]:
        if flag[i] < 0:
            q.append(i)
            cnt[i] += cnt[temp]
            flag[i] = 1
            
print(*cnt)

### FIXED CODE ###

N,Q = map(int, input().split())
L = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)
cnt = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    cnt[p-1] += x

flag = [1]*N
q = [0]
while q:
    temp = q.pop()
    flag[temp] = 0
    for i in L[temp]:
        if flag[i]:
            q.append(i)
            cnt[i] += cnt[temp]
            
print(*cnt)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
a=sorted(a)
b=sorted(b)
c=sorted(c)
c.reverse()

ans=0
max1=n-1

for x in range(n):
  maxC=c[x]
  min1=0
  while max1-min1>1:
    zantei=(max1+min1)//2
    if b[zantei]>=maxC:
      max1=zantei
    else:
      min1=zantei
  if b[max1]<maxC:
    ch=max1
  elif b[min1]>=maxC:
    continue
  else:
    
    ch=min1
  
  for y in range(ch+1):
    maxB=b[y]
    max2=n-1
    min2=0
    while max2-min2>1:
      zantei1=(max2+min2)//2
      if a[zantei1]>=maxB:
        max2=zantei1
      else:
        min2=zantei1
    if a[max2]<maxB:
      ch1=max2
    else:
      ch1=min2
      
    ans+=ch1+1
    
print(ans)
      

### FIXED CODE ###

def bs_left(list, target):
    low = 0
    high = len(list)

    while low < high:
        mid = (low + high) // 2
        if target > list[mid]:
            low = mid + 1
        else:
            high = mid
    return low

def bs_right(list, target):
    low = 0
    high = len(list)
    while low < high:
        mid = (low + high) // 2
        if target < list[mid]:
            high = mid
        else:
            low = mid + 1
    return low

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

ans = 0
for b in B:
    ans += (bs_left(A, b) * (n - bs_right(C, b)))
print(ans)
### BUGGY CODE ###

N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    flag = False
    t, x, y = map(int, input().split())
    for a in range(t - pre_t + 1):
        for b in range(t - pre_t + 1 - a):
            if pre_x + a - b == x:
                for c in range(t - pre_t + 1  - a - b):
                    d = t - pre_t - a - b - c
                    if pre_y + c - d == y:
                        count += 1
                        flag = True
                        break
            if flag:
                break
        if flag:
            break
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

N = int(input())
pre_t = 0
pre_x = 0
pre_y = 0
count = 0
for _ in range(N):
    flag = False
    t, x, y = map(int, input().split())
    for a in range(t - pre_t + 1):
        b = pre_x - x + a
        if b >= 0:
            for c in range(t - pre_t + 1  - a - b):
                d = t - pre_t - a - b - c
                if pre_y + c - d == y:
                    count += 1
                    flag = True
                    break
        if flag:
            break
    pre_t = t
    pre_x = x
    pre_y = y
if count == N:
    print("Yes")
else:
    print("No")
### BUGGY CODE ###

MOD = 10**9+7

k = int(input())
s = input()
MAX = k + len(s)

factorial = [0] * (MAX + 1)
factorial[0] = 1
for i in range(1, MAX + 1):
    factorial[i] = factorial[i-1] * i
    factorial[i] %= MOD


ifactorial = [0] * (MAX + 1)
ifactorial[MAX] = pow(factorial[MAX], MOD - 2, MOD)
for i in range(MAX, 0, -1):
    ifactorial[i - 1] = ifactorial[i] * i
    ifactorial[i - 1] %= MOD

pow25 = [1] * (k + 1)
pow26 = [1] * (k + 1)
for i in range(k):
    pow25[i + 1] = pow25[i] * 25
    pow25[i + 1] %= MOD
    pow26[i + 1] = pow26[i] * 26
    pow26[i + 1] %= MOD


def combination(n, k):
    ret = factorial[n] * ifactorial[k] * ifactorial[n - k]
    return ret % MOD


ans = 0
for i in range(k + 1):
    tmp = combination(i + len(s) - 1, len(s) - 1)
    tmp *= pow25[i]
    tmp %= MOD
    # tmp *= pow(25, i, MOD)
    tmp *= pow26[k - i]
    # tmp *= pow(26, k - i, MOD)
    tmp %= MOD
    ans += tmp
    ans %= MOD
print(ans)


### FIXED CODE ###

MOD = 10**9+7

k = int(input())
s = input()
MAX = k + len(s)

factorial = [0] * (MAX + 1)
factorial[0] = 1
for i in range(1, MAX + 1):
    factorial[i] = factorial[i-1] * i % MOD


ifactorial = [0] * (MAX + 1)
ifactorial[MAX] = pow(factorial[MAX], MOD - 2, MOD)
for i in range(MAX, 0, -1):
    ifactorial[i - 1] = ifactorial[i] * i % MOD

pow25 = [1] * (k + 1)
pow26 = [1] * (k + 1)
for i in range(k):
    pow25[i + 1] = pow25[i] * 25
    pow25[i + 1] %= MOD
    pow26[i + 1] = pow26[i] * 26
    pow26[i + 1] %= MOD


def combination(n, k):
    ret = factorial[n] * ifactorial[k] * ifactorial[n - k]
    return ret % MOD


ans = 0
for i in range(k + 1):
    tmp = combination(i + len(s) - 1, len(s) - 1)
    tmp *= pow25[i]
    tmp %= MOD
    # tmp *= pow(25, i, MOD)
    tmp *= pow26[k - i]
    # tmp *= pow(26, k - i, MOD)
    tmp %= MOD
    ans += tmp
    ans %= MOD
print(ans)
### BUGGY CODE ###

N = int(input())
S = input()
ans = 0

letters_dict = {}

for i in range(N):
    for j in range(i + 1, N):
        key = S[i:j + 1]
        if key not in letters_dict:
            letters_dict[key] = i
        else:
            ans = max(ans, min(len(key), i - letters_dict[key]))

print(ans)

### FIXED CODE ###

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

dp = [[0] * N for _ in range(N)]

for j in range(N):
    if S[j] == S[-1]:
        dp[-1][j] = 1

for i in range(N - 2, -1, -1):
    for j in range(N - 1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
    if S[i] == S[-1]:
        dp[i][-1] = 1

ans = 0
for i in range(N):
    for j in range(N):
        ans = max(ans, min(dp[i][j], abs(i - j)))

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

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
p = [True] * (10 ** 6 + 1)
s = list(set(a))

for x in s:
    t = x * 2
    #print(t)
    while t <= 10 ** 6:
        p[t] = False
        t += x
ans = 0
for x in a:
    #print(x)
    if c[x] == 1 and p[x] == True:
        ans += 1
print(ans)

### FIXED CODE ###

from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
p = [True] * (10 ** 6 + 1)
s = list(set(a))
for x in s:
    t = x * 2
    while t <= 10 ** 6:
        p[t] = False
        t += x
ans = 0
for x in a:
    if c[x] == 1 and p[x] == True:
        ans += 1
print(ans)
### BUGGY CODE ###

# input here
_INPUT = """\
5
3 3 3 3 3
"""

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    Springboard = []
    for i in range(1,len(A)):
    # 自分より前に自分より身長が高い人がいないとき
        if max(A[:i+1]) == A[i]:
            Springboard.append(0)
     # 自分より前に自分より身長が高い人がいるとき
        else:
            Springboard.append(max(A[:i]) - A[i])

    print(sum(Springboard))

if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools

    # sys.stdin = io.StringIO(_INPUT)
    main()

### FIXED CODE ###

# input here
_INPUT = """\
5
3 3 3 3 3
"""

def main():
    N = int(input())
    A = list(map(int, input().split()))
    
    Springboard = []
    max = A[0]
    for i in range(1,len(A)):
    # 自分より前に自分より身長が高い人がいないとき
        if max < A[i]:
            max = A[i]
            Springboard.append(0)
     # 自分より前に自分より身長が高い人がいるとき
        else:
            Springboard.append(max - A[i])

    print(sum(Springboard))

if __name__ == '__main__':
    import io
    import sys
    import math
    import itertools

    # sys.stdin = io.StringIO(_INPUT)
    main()
### BUGGY CODE ###

def gcd(a,b):
    i = 1
    temp = 1
    while(i <= b):
        if(a % i == 0 and b % i == 0):
            temp = i
        i = i + 1
    print temp

l = raw_input().split()
if(int(l[0]) > int(l[1])):
    gcd(int(l[0]),int(l[1]))
else:
    gcd(int(l[1]),int(l[0]))


### FIXED CODE ###

def gcd(a,b):
    if(b):
        return gcd(b,a%b)
    return a

l = raw_input().split()
if(int(l[0]) > int(l[1])):
    print gcd(int(l[0]),int(l[1]))
else:
    print gcd(int(l[1]),int(l[0]))
### BUGGY CODE ###

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    A.sort()
    B.sort()
    C.sort()

    ans = 0
    left = 0
    for a in A:
        right = left
        while left < N and a >= B[left]:
            left += 1
        if N <= left:
            break
        for b in B[left:]:
            while right < N and b >= C[right]:
                right += 1
            if N <= right:
                break
            ans += N-right
    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    B = [int(i) for i in input().split()]
    C = [int(i) for i in input().split()]
    A.sort()
    B.sort()
    C.sort()

    def is_ok1(mid, S, K):
        if K <= S[mid]:
            return True
        else:
            return False

    def is_ok2(mid, S, K):
        if K < S[mid]:
            return True
        else:
            return False

    def binary_search_meguru(S, K, is_ok):
        left = -1
        right = N
        while right - left > 1:
            mid = left + ((right - left) // 2)
            if is_ok(mid, S, K):
                right = mid
            else:
                left = mid
        return right

    ans = 0
    for b in B:
        a = binary_search_meguru(A, b, is_ok1)
        c = binary_search_meguru(C, b, is_ok2)
        ans += a * (N-c)
    print(ans)


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

import sys
n = int(input())
cnt = 0
flag = 1
i = 0
for i in range(1,sys.maxsize):
  if i < 10:
    cnt += 1
  else:
    s = str(i)
    sn = len(s)
    judge = 0
    sj = int(s[0])
    sj1 = int(s[1])
    if sj in (sj1,sj1 + 1,sj1 - 1):
      for j in range(1,sn):
        sj = int(s[j])
        sj1 = int(s[j-1])
        if sj in (sj1,sj1 + 1,sj1 - 1):
          judge += 0
        else:
          judge += 1
    else:
      judge += 1
    if judge == 0:
      cnt += 1

  if n == cnt:
    print(i)
    exit()





### FIXED CODE ###

k = int(input())
 
table = [1, 2, 3, 4, 5, 6, 7, 8, 9]
for i in table:
  if len(table) > k:
    break
  x = i % 10
  for j in range(max(0, x - 1), min(x + 2, 10)):
    table.append(i * 10 + j)


print(table[k - 1])
### BUGGY CODE ###

N,P = map(int,input().split(sep=" "))
S = input()
count=0
for i in range(0,N,1):
    for j in range(i,N,1):
        tmp = int(S[i:j+1])
        if tmp%P == 0:
            count += 1

print(count)


### FIXED CODE ###

import sys

N, P = map(int, input().split())
A = input()

ans = 0

if 10 % P == 0:
    for r in range(len(A)):
        if int(A[r]) % P == 0:
            ans += r + 1
    print(ans)
    sys.exit()


A = "0" + A[::-1]

S = [0] * len(A)
cnt = [0] * P
cnt[0] = 1

for i in range(len(A) - 1):
    S[i + 1] = (S[i] + int(A[i + 1]) * pow(10, i, P)) % P
    cnt[S[i + 1] % P] += 1
# print(S, cnt)

# ans = cnt[0] * (cnt[0] - 1) // 2
for c in cnt:
    ans += c * (c - 1) // 2
print(ans)
### BUGGY CODE ###

s=[int(i) for i in input()]
s.reverse()

a=0
l=[0 for i in range(2019)]
l[0]=1
for i in range(len(s)):
  a+=s[i]*(10**i)
  a%=2019
  l[a]+=1

answer=0
for i in range(2019):
  answer+=l[i]*(l[i]-1)//2
  
print(answer)

### FIXED CODE ###

s=[int(i) for i in input()]
s.reverse()

a=0
l=[0 for i in range(2019)]
l[0]=1
b=0.1
for i in range(len(s)):
  b=int(b*10)
  b%=2019
  a+=s[i]*b
  a%=2019
  l[a]+=1

answer=0
for i in range(2019):
  answer+=l[i]*(l[i]-1)//2
  
print(answer)
### BUGGY CODE ###

from collections import deque
A =input()
S = deque(A)
H = 0
Q = int(input())
Qlist = []
for i in range(Q):
    op = list((map(str,input().split())))
    if len(op) ==1:
        H +=1
    else:
        if op[1] =='1':
            if H%2 == 0:
                S.appendleft(op[2])
            else:
                S.append(op[2]) 
        else:
            if H%2 == 0:
                S.append(op[2])
            else:
                S.appendleft(op[2])
if H%2 == 1:
    A = S[-1]
    for i in range(1,len(S)):
        A += S[-i-1]
else:
    A = S[0]
    for i in range(1,len(S)):
        A += S[i]
print(A)

### FIXED CODE ###

from collections import deque
S= deque(input())
Q = int(input())
ba = 1
for i in range(Q):
    Query =list(map(str,input().split()))
    Query0 = Query[0]
    if Query[0] == '1':
        ba *= -1
    else:
        if Query[1] == '1' and ba ==1:
            S.appendleft(Query[2])
        elif Query[1] == '1' and ba ==-1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==1:
            S.append(Query[2])
        elif Query[1] == '2' and ba ==-1:
            S.appendleft(Query[2])
if ba == -1:
    S.reverse()
mojieru = ''.join(S)
print(mojieru)
### BUGGY CODE ###

N,K = map(int,input().split())
if N%K==0:
    print(0)
else:
    while abs(N-K) < N:
        N = abs(N-K)
    print(N)

### FIXED CODE ###

N,K = map(int,input().split())
if N>=K:
    N = N%K
    while abs(N-K) < N:
        N = abs(N-K)
    print(N)
else:
    if K >= 2*N:
        print(N)
    else:
        N = K%N
        print(N)
### BUGGY CODE ###

# Bugged

n = int(input())
s = []
for i in range(n):
    s.append(int(input()))

    import numpy as np

ss = sorted(s ,reverse=True)
l  = len(s)
f = 2**l-1
for i in range(2**l):
    ff = list(map(int,list(format(f,'b').zfill(3))))
    a = np.sum(np.array(ff)*np.array(ss))
    if ( a%10!=0 or a==0):
        print(a)
        break
    f-=1

### FIXED CODE ###

# Bugged

n = int(input())
s = []
for i in range(n):
    s.append(int(input()))

a = []
for ss in s:
    if ( ss%10!=0 ):
        a.append(ss)
ssum = sum(s)
if ( ssum%10!=0 ):
    print(ssum)
else:
    if ( len(a)==0 ):
        print(0)
    else:
        print(ssum-min(a))
### BUGGY CODE ###

def resolve():
    import sys
    import math

    readline = sys.stdin.readline

    N = int(readline())

    for i in range(1, N + 1):
        ans = 0
        li = int(math.sqrt(i) // 1)
        for x in range(1, li):
            xx = x * x
            for y in range(1, li):
                yy = y * y
                xy = x * y
                x_y = x + y
                value = (x_y) ** 2 - 4 * (xx + yy + xy - i)
                if value <= 0:
                    continue
                cal = math.sqrt(value)
                z1 = (-(x_y) + cal) / 2
                z2 = (-(x_y) - cal) / 2
                if (1
                        and 1 <= z1
                        and z1 % 1 == 0):
                    ans += 1
                if (1
                        and 1 <= z2
                        and z2 % 1 == 0):
                    ans += 1
        print(ans)


resolve()


### FIXED CODE ###

import sys


def resolve():
    import numpy as np

    readline = sys.stdin.readline

    N = int(readline())

    f = np.zeros(10001, np.int64)

    for x in range(1, 101):
        for y in range(1, 101):
            for z in range(1, 101):
                n = x * x + y * y + z * z + x * y + y * z + z * x
                if n > 10000:
                    continue
                f[n] += 1
    for i in range(1, N + 1):
        print(f[i])

resolve()
### BUGGY CODE ###

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd,numbers)
K=int(input())
a=1
b=1
c=1
sum_abc=0
if 1<=K<=200:
    for c in range(1,K+1):
        for b in range(1,K+1):
            for a in range(1,K+1):
                sum_abc+=gcd(a,b,c)
                a+=1
            b+=1
        c+=1
    print(sum_abc)

### FIXED CODE ###

import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd,numbers)
K=int(input())
a=1
c=1
if 1<=K<=200:
    sum_abc=K*(K+1)/2
    sum_abc=int(sum_abc)
    for a in range(1,K+1):
        for c in range(1,K+1):
            if a==c:
                c+=1
            else:
                d=math.gcd(a,c)
                d=3*d
                sum_abc=sum_abc+d
                c+=1
        a+=1
    if K>=3:
        i=1
        j=2
        k=3
        for k in range(3,K+1):
            for j in range(2,k):
                for i in range(1,j):
                    e=gcd(i,j,k)
                    e=6*e
                    sum_abc=sum_abc+e
                    i+=1
                j+=1
            k+=1
    print(sum_abc)
### BUGGY CODE ###

R,G,B,N=map(int,input().split())

cnt =0

# R*r + G*g + B*b == N

rm =int(N/R)
gm =int(N/G)
bm = int(N/B)

for r in range(rm+1):
    for g in range(gm+1):
        if R*r + G*g > N :
                break
        for b in range(bm+1):
            if R*r + G*g + B*b > N :
                break
            if R*r + G*g + B*b == N :
                cnt +=1
print(cnt)



### FIXED CODE ###

R,G,B,N=map(int,input().split())

#R*r+G*g+B*b==n
ir=int(N/R)+1
ig=int(N/G)+1
ib=int(N/B)+1
s=0
for r in range(ir):
    for g in range(ig):
        if(R*r+G*g>N):
            break;
        if((N-R*r-G*g)%B==0):
            s+=1
print(s)
### BUGGY CODE ###

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

A = sorted(list(map(int, input().split())), reverse=True)

B = []
for i in range(M):
    b, c = map(int, input().split())
    B.append([b, c])

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

cnt = 0
ans = 0
a = 0
b = 0
while True:
    if b <= M-1 and A[a] <= B[b][1]:
        for k in range(B[b][0]):
            ans += B[b][1]
            cnt += 1
            if cnt == N:
                print(ans)
                break
        b += 1
    elif a <= N-1:
        cnt += 1
        ans += A[a]
        if cnt == N:
            print(ans)
            break
        a += 1

### FIXED CODE ###

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

A = sorted(list(map(int, input().split())), reverse=True)

B = []
for i in range(M):
    b, c = map(int, input().split())
    B.append([b, c])

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

cnt = 0
ans = 0
a = 0
b = 0
while True:
    if b <= M-1 and A[a] <= B[b][1]:
        n = min(B[b][0], N-cnt)
        ans += B[b][1]*n
        cnt += n
        if cnt == N:
            print(ans)
            break
        b += 1
    elif a <= N-1:
        cnt += 1
        ans += A[a]
        if cnt == N:
            print(ans)
            break
        a += 1
### BUGGY CODE ###

from sys import stdin

temp_ans = []


def problem_a(input_string):
    S = int(input_string[0].rstrip())
    N = input_string[1].rstrip()
    N_l = len(N)
    global temp_ans
    for i in range(N_l)[::-1]:
        temp_ans += N[i]
        #print(temp_ans)
        for s in temp_ans:
            #print(s)
            if N[i] not in s:
                temp_ans.append(N[i]+s)
    #print(temp_ans)
    return len(temp_ans) % (10**9 + 7)


def main():
    input_line = stdin.readlines()
    answer = problem_a(input_line)
    print(answer)


if __name__ == '__main__':
    main()


### FIXED CODE ###

from sys import stdin
import math
import itertools


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

# これだと、O(n*n)
"""
temp_ans = []


def problem_a(input_string):
    S = int(input_string[0].rstrip())
    N = input_string[1].rstrip()
    N_l = len(N)
    global temp_ans
    for i in range(N_l)[::-1]:
        temp_ans += N[i]
        #print(temp_ans)
        for s in temp_ans:
            #print(s)
            if N[i] not in s:
                temp_ans.append(N[i]+s)
    #print(temp_ans)
    return len(temp_ans) % (10**9 + 7)
"""


def problem_a(input_string):
    S = int(input_string[0].rstrip())
    N = input_string[1].rstrip()
    #print(S)
    dic = {}
    c = 0
    for i in range(S)[::-1]:
        if N[i] not in dic:
            dic[N[i]] = 1
            #c += i+1
        else:
            dic[N[i]] += 1

    c = 1
    for key, value in dic.items():
        c *= (value+1)
    c -= 1
    """
    c += 2**len(dic.keys())-1
    #print(c)
    #c += S
    for key, value in dic.items():
        if value > 1:
            #c -= (value-1)
            c += 2**(len(dic.keys()))-1
            #print(c)
    #for key, value in dic.items():
    for key, value in dic.items():
        if value > 1:
            if len(dic.keys()) != S:
                c -= 2**(S-len(dic.keys())-1)
    """
            #print(c)
        #else:
    #c += (S-len(dic.keys()))
    """
    s_N = sorted(N)
    for i in range(S-1):
        if s_N[i] != s_N[i+1]:
            c += 2**(i+2)
    """
    """
    for key, value in dic.items():
        if value > 1:
            c += 2**(len(dic.items())-value)
        else:
            c += 2**(len(dic.items())-value)
    """
    #combinations_count(len(, r)

    return c % (10**9 + 7)


def main():
    input_line = stdin.readlines()
    answer = problem_a(input_line)
    print(answer)


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

# 偶数回目は前に入れる
n = int(input())
l = list(map(int, input().split()))
ans = []
for i in range(n):
  if i == 0:
    ans.append(l[i])
    continue

  if n % 2 == 0:
    if not i % 2 == 0:
      ans.insert(0, l[i])
    else:
      ans.append(l[i])
  else:
    if not i % 2 == 0:
      ans.append(l[i])
    else:
      ans.insert(0, l[i])

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

### FIXED CODE ###

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

even, odd = [], []

for i in range(n):
  if i % 2 == 0:
    even.append(l[i])
  else:
    odd.append(l[i])

if n % 2 == 0:
  ans = odd[::-1] + even
else:
  ans = even[::-1] + odd
ans = map(str, ans)
print(' '.join(ans))
### BUGGY CODE ###

s=list(input())

k=int(input())

ans = []

for alf in s:
    if alf == 'a':
        ans = ans + ['a']
    else:
        if 123 - ord(alf) <= k:
            k -= 123 - ord(alf)
            ans = ans + ['a']
        else:
            ans = ans + [alf]
if 0 < k:
    amari = (ord(ans[-1])-97+k)%26
    ans[-1] = chr(amari+97)
    
print(''.join(map(str,ans)))

### FIXED CODE ###

s=list(input())

k=int(input())

ans = []

for alf in s:
    if alf == 'a':
        ans.append('a')
    else:
        if 123 - ord(alf) <= k:
            k -= 123 - ord(alf)
            ans.append('a')
        else:
            ans.append(alf)
if 0 < k:
    amari = (ord(ans[-1])-97+k)%26
    ans[-1] = chr(amari+97)
    
print(''.join(map(str,ans)))
### BUGGY CODE ###

inf = 1000*500*500
D = []
c = []
d = {}
N,C = map(int,input().split())
for i in range(C):
    D.append(list(map(int,input().split())))
for i in range(N):
    c.append(list(map(int,input().split())))

for C1 in range(C):
    for C2 in range(C):
        for C3 in range(C):
            if C1 != C2 and C2 != C3 and C3 != C1:
                d[(C1+1,C2+1,C3+1)]=0
            else:
                d[C1+1,C2+1,C3+1]=inf

for i in range(N):
    for j in range(N):
        for C1 in range(C):
            for C2 in range(C):
                for C3 in range(C):
                    if (i+j)%3==0:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C1]
                    elif (i+j)%3==1:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C2]
                    else:
                        d[(C1+1,C2+1,C3+1)]+=D[c[i][j]-1][C3]

l = []
for x in d:
    l.append(d[x])
print(min(l))


### FIXED CODE ###

import numpy as np
D = []
c = []
d0 = {}
d1 = {}
d2 = {}

N,C = map(int,input().split())
a = np.zeros((3,C))
for i in range(C):
    D.append(list(map(int,input().split())))
for i in range(N):
    c.append(list(map(int,input().split())))

D = np.array(D)
c = np.array(c)

for i in range(N):
    for j in range(N):
        a[(i+j)%3] += D[c[i][j]-1]

l = []
for C1 in range(C):
    for C2 in range(C):
        for C3 in range(C):
            if C1 != C2 and C2 != C3 and C3 != C1:
                l.append(a[0][C1]+a[1][C2]+a[2][C3])

print(int(min(l)))