Harryxun/stf_run huggingface dataset:
# coding: utf-8
# Your code here!
import itertools
import math
from scipy import special

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

for i in range(1,K+1):
    b = special.comb(K-1, i-1, True)
    r = special.comb(N-K+1, i, True)
    print(int(b * r % (math.pow(10, 9) + 7)))

### FIXED CODE ###

# coding: utf-8
# Your code here!
from operator import mul
from functools import reduce

def cmb(n, r):
	if n < r:
		return 0
	r = min(n - r, r)
	if r == 0:
		return 1
	numer = reduce(mul, range(n, n - r, -1))
	denom = reduce(mul, range(1, r + 1))
	return numer // denom % INF

N,K = map(int,input().split())
INF = 10**9 + 7
for i in range(1,K+1):
    print(cmb(K-1, i-1) * cmb(N-K+1, i) % INF)
def minimumChar(S,T): 
    n, m = len(S), len(T) 
    ans = sys.maxsize 
    for i in range(m - n + 1): 
        minRemovedChar = 0
        for j in range(n): 
            if (S[j] != T[i + j]): 
                minRemovedChar += 1
        ans = min(minRemovedChar, ans) 
    return ans 
      
S=input()
T=input()

print(minimumChar(S, T)) 

### FIXED CODE ###

import sys
def minimumChar(T,S): 
    n, m = len(T), len(S) 
    ans = sys.maxsize 
    for i in range(m - n + 1): 
        minRemovedChar = 0
        for j in range(n): 
            if (T[j] != S[i + j]): 
                minRemovedChar += 1
        ans = min(minRemovedChar, ans) 
    return ans 
      
S=input()
T=input()

print(minimumChar(T,S))
N,X = map(int, raw_input().split())
A = [0]*N
B = [0]*N
A[0] = 1
B[0] = 1
for i in range(1,N):
  A[i] = 2*A[i-1]+3
  B[i] = 2*B[i-1]+1

def f(N,X):
  if N==0:
    return 1
  if X<=1:
    return 0
  if X<=1+A[N-1]:
    return f(N-1, X-1)
  if X<=1+A[N-1]+1:
    return B[N-1]+1
  if X<=1+A[N-1]+1+A[N-1]:
    return B[N-1]+1+f(N-1, X-2-A[N-1])
  if X<=1+A[N-1]+1+A[N-1]<=1:
    return 2*B[N-1]+1
  print N,X

print f(N,X)


### FIXED CODE ###

N,X = map(int, raw_input().split())
A = [0]*N
B = [0]*N
A[0] = 1
B[0] = 1
for i in range(1,N):
  A[i] = 2*A[i-1]+3
  B[i] = 2*B[i-1]+1

def f(N,X):
  if N==0:
    return 1
  if X<=1:
    return 0
  if X<=1+A[N-1]:
    return f(N-1, X-1)
  if X<=1+A[N-1]+1:
    return B[N-1]+1
  if X<=1+A[N-1]+1+A[N-1]:
    return B[N-1]+1+f(N-1, X-2-A[N-1])
  if X<=1+A[N-1]+1+A[N-1]+1:
    return 2*B[N-1]+1
  print N,X

print f(N,X)
A=int(input())
B=int(input())
C=int(input())
D=B//A-C
if D>0:
  print(C)
else:
  print(B//A)

### FIXED CODE ###

A,B,C=map(int,input().split())
D=B//A-C
if D>0:
  print(C)
else:
  print(B//A)
n = int(input())
a = [int(input()) for i in range(n)]
m_num = max(a)
m_index = [i for i, x in enumerate(a) if x == m_num]
m2_num = sorted(set(a))[-2]

for i in range(n):
  if i in m_index:
    print(m2_num)
  else:
    print(m_num)

### FIXED CODE ###

n = int(input())
a = [int(input()) for i in range(n)]
m_num = max(a)
m_index = [i for i, x in enumerate(a) if x == m_num]

if len(m_index) > 1:
  for i in range(n):
    print(m_num)
else:
  if len(a) == 1:
    print(a[0])
  else:
    m2_num = sorted(a)[-2]
    for i in range(n):
      if (i in m_index):
        print(m2_num)
      else:
        print(m_num)
a=input().split()
b=map(int,a)
maximum=max(b)
minimum=min(b)
print(maximum-minimum)

### FIXED CODE ###

q=input()
a=input().split()
b=[int(i) for i in a]
maximum=max(b)
minimum=min(b)
print(maximum-minimum)
S = input()
str = ''

for w in S:
  if w == 'B':
    if str[-1] == '0':
      str = str.rstrip('0')
    elif str[-1] == '1':
      str = str.rstrip('1')
  elif w == '0':
    str += '0'
  elif w == '1':
    str += '1'
print(str)

### FIXED CODE ###

S = input()
str = ''

for w in S:
  if w == 'B':
    if str == '':
      continue
    else:
      str = str[:-1]
  elif w == '0':
    str += '0'
  elif w == '1':
    str += '1'
print(str)
s=str(input())
print(s.replace("2017"."2018"))


### FIXED CODE ###

s=str(input())
print(s.replace("2017","2018"))
n,a,b,c,d=map(int,input().split())
res=list(input())
if c<d:
    for i in range(1,n):
        if res[i-1]=="#" and res[i]=="#":
            print("No")
            exit()
    print("Yes")
    exit()

for i in range(b,d+1):
    if i<=n-4:
        continue
    if res[i+2]=="." and res[i+1]=="." and res[i]==".":
        print("Yes")
        exit()
print("No")
exit()


### FIXED CODE ###

n,a,b,c,d=map(int,input().split())
res=list(input())
if c<d:
    for i in range(a,d+1):
        if res[i-1]=="#" and res[i]=="#":
            print("No")
            exit()
    print("Yes")
    exit()

for i in range(b,d+1):
    if i==1:
        continue
    if res[i-2]=="." and res[i-1]=="." and res[i]==".":
        print("Yes")
        exit()
    if res[i-1]=="#" and res[i]=="#":
        print("No")
        exit()
        
print("No")
exit()
n=int(input())
a=input()
b=input()
c=input()
tim = 0
for i in range(n):
    if a[i] == b[i] and b[i] != c[i]:
        tim+=1
    elif b[i] == c[i] and c[i] != a[i]:
        tim+=1
    elif c[i] == a[i] and a[i] != b[i]:
        tim+=1
    elif c[i] == a[i] and a[i] == b[i]:
        tim+=0
    else:
        tim+=2
print(tim)

### FIXED CODE ###

n,a,b = (int(i) for i in input().split())
x=min(a,b)
y=a+b-n
if y < 0:
    y=0
print(x,y)
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

mod = 10**9+7

N = int(input())
graph = [set() for i in range(N)]

for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    graph[u].add((v,w))
    graph[v].add((u,w))


res = [None for i in range(N)]

# v は今見ている頂点，p はｖの親
def dfs(node,p,color): # Depth First Serch
    res[node] = color
    for new_node,w in graph[node]:
        if new_node == p:
            continue
        if w % 2 == 1:dfs(new_node,node,1-color)
        else:dfs(new_node,node,color)
#tree 探索　
# vは頂点，ｐは親
dfs(0,-1,0)

for i in range(N):
    print(res[i])


### FIXED CODE ###

# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys



mod = 10**9+7
sys.setrecursionlimit(mod)

N = int(input())
graph = [set() for i in range(N+1)]

for i in range(N-1):
    u,v,w = map(int,input().split())
    u -= 1
    v -= 1
    w = w % 2
    graph[u].add((v,w))
    graph[v].add((u,w))


res = [None for i in range(N+1)]

# v は今見ている頂点，p はｖの親
def dfs(node,p,color): # Depth First Serch
    res[node] = color
    for new_node,w in graph[node]:
        if new_node == p:
            pass
        else:
            if w == 1:dfs(new_node,node,1-color)
            else:dfs(new_node,node,color)
#tree 探索　
# vは頂点，ｐは親
dfs(0,-1,0)

for i in range(N):
    print(res[i])
s=input()
if s='SUN'
  print(7)
if s='MON'
  print(6)
if s='TUE'
  print(5)
if s='WED'
  print(4)
if s='THU'
  print(3)
if s='FRI'
  print(2)
if s='AST'
  print(1)

### FIXED CODE ###

s=input()
if s=="SUN":
  print(7)
if s=="MON":
  print(6)
if s=="TUE":
  print(5)
if s=="WED":
  print(4)
if s=="THU":
  print(3)
if s=="FRI":
  print(2)
if s=="SAT":
  print(1)
N, M = map(int, input().split())
A = [input() for i in range(M)]

if(sum(A) = N):
  print('0')
elif(sum(A) > N):
  print(N - sum(A))
else:
  print('-1')

### FIXED CODE ###

N, M = map(int, input().split())
A = input().split()
B = [ ]
for i in range(M):
  B.append(int(A[i]))
if(sum(B) == N):
  print('0')
elif(sum(B) < N):
  print(N - sum(B))
else:
  print('-1')
a,b = mmap(int,input().split())
print(a-b+1)


### FIXED CODE ###

a,b = map(int,input().split())
print(a-b+1)
#6727236

ソースコード 

Copy
Copy
Tmp = []
Tmp = input().rstrip().split(' ')
 
nN = int(Tmp[0])
nT = int(Tmp[1])
 
nCost = 1001
nAns = 0
 
for i in range(nN):
  Tmp = input().rstrip().split(' ')
 
  nTmpCost = int(Tmp[0])
  nTmpT = int(Tmp[1])
  
  if nTmpT <= nT and nTmpCost < nCost:
    nCost = nTmpCost
    nAns = i+1

if nAns == 0:
  print('TLE')
else:
  print(nCost)
 

### FIXED CODE ###

Tmp = []
Tmp = input().rstrip().split(' ')
 
nN = int(Tmp[0])
nT = int(Tmp[1])
 
nCost = 1001
nAns = 0
 
for i in range(nN):
  Tmp = input().rstrip().split(' ')
 
  nTmpCost = int(Tmp[0])
  nTmpT = int(Tmp[1])
  
  if nTmpT <= nT and nTmpCost < nCost:
    nCost = nTmpCost
    nAns = i+1

if nAns == 0:
  print('TLE')
else:
  print(nCost)
a=input()
b=""
for i in range(a,0,-1):
  b+=a[i]
if a==b:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a=input()
b=""
for i in range(1,len(a)+1):
  b+=a[-i]
if a==b:
  print("Yes")
else:
  print("No")
S=[]
for char in input():
  S.append(char)

#route 2
C2=0
for n in range(int(len(S))+1):
  if n%2==0:
    if S[n]==0:
      S[n]=1
      C2+=1
  else:
    if S[n]==1:
      S[n]=0
      C2+=1
      
#route 1
C1=0
for i in range(int(len(S))+1):
  if i%2==0:
    if S[i]==1:
      S[i]=0
      C1+=1
  else:
    if S[i]==0:
      S[i]=1
      C1+=1

if C1>=C2:
  print(C1)
else:
  print(C2)

  
    
    
      

### FIXED CODE ###

S=[]
for char in input():
  S.append(char)
#route 1
C1=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='1':
      C1+=1
  else:
    if S[i]=='0':
      C1+=1

#route 2
C2=0
for n in range(len(S)):
  if n%2==0:
    if S[n]=='0':
      C2+=1
  else:
    if S[n]=='1':
      C2+=1

if C2>=C1:
  print(C1)
else:
  print(C2)
print("Yes" if list(filter(lambda x:x%2==0,map(int, input().split()))) "No")


### FIXED CODE ###

a,b=map(int, input().split())
print('Yes' if a * b % 2 == 1 else 'No')
A = float(input("Enter A: "))
B= float(input("Enter B: "))

print(int(A*B))

### FIXED CODE ###

A, B = map(str, input().split()) # take the input in one line
A = int(A) # convert A into integer
C = B[0]+B[2]+B[3]
C = int(C)
print(A*C//100) # printing the output

# time complixity O(1)
N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        c = []
        for i in list(set(a)):
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N = int(input())
a = list(map(int,input().split()))
a.sort()
flag = True
if len(set(a)) == 1 and a[0] == 0:
    #print('Yes')
    pass
elif N % 3 == 0:
    if len(set(a)) == 3:
        b = list(set(a))
        c = []
        for i in b:
            c.append(a.count(i))
        if a[0] != 0 and c[0] == c[1] and  c[1] == c[2] and c[2] == N//3 and b[0]^b[1]^b[2] == 0:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    elif len(set(a)) == 2:
        if a[0] == 0 and a.count(a[0])*2 == a.count(a[N-1]) and a.count(a[N-1]) == N//3*2:
            #print('Yes')
            pass
        else:
            #print('No')
            flag = False
    else:
        #print('No')
        flag = False
else:
    #print('No')
    flag = False
if flag:
    print('Yes')
else:
    print('No')
import math
n=int(input())
l=[int(input()) for i in range(5)]
print(math.ceil(n/min(l)+4)


### FIXED CODE ###

import math
n=int(input())
l=[int(input()) for i in range(5)]
print(math.ceil(n/min(l))+4)
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = ls[input()]
nans =[]
for i in range (3):
  if n[i] == "1":
    nans.append("9")
    else:
      nans.append("1")
print("".join(nans))
    


### FIXED CODE ###

#! /usr/bin/env python3
# -*- coding: utf-8 -*-


n = list(input())
nans =[]
for i in range (3):
    if n[i] == "1":
        nans.append("9")
    else:
        nans.append("1")
print("".join(nans))
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  a-=1
  b-=1
  G[a].append(b)
  G[b].append(a)
color=[-1]*N  
def dfs(x):
  for i in G[x]:
    if color[i]==-1:
      color[i]=1^color[x]
      dfs(i)
    elif color[i]==color[x]:
      print((N*(N-1))//2-M)
      exit()
color[0]=0
dfs(0)
b=0
for i in range(N):
  b+=color[i]
print(b*(N-b)-M)
      
     
      

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
N,M=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
  a,b=map(int,input().split())
  a-=1
  b-=1
  G[a].append(b)
  G[b].append(a)
color=[-1]*N  
def dfs(x):
  for i in G[x]:
    if color[i]==-1:
      color[i]=1^color[x]
      dfs(i)
    elif color[i]==color[x]:
      print((N*(N-1))//2-M)
      exit()
color[0]=0
dfs(0)
b=0
for i in range(N):
  b+=color[i]
print(b*(N-b)-M)
import numpy as np


def div(n, d):
    if d == 2:
        return format(n, "b")[::-1].find("1")
    cnt = 0
    while n % d == 0:
        n //= d
        cnt += 1
    return cnt


n = int(input())

arr2 = []
arr5 = []
for _ in range(n):
    x = round(float(input()) * 10**9)
    arr2.append(div(x, 2))
    arr5.append(div(x, 5))

arr2 = np.array(arr2)
arr5 = np.array(arr5)
shape = arr2.shape[0]

arr2 = (arr2 + np.zeros([shape, shape], np.int64)).astype(np.int32)
arr5 = (arr5 + np.zeros([shape, shape], np.int64)).astype(np.int32)

arr2 = np.tril(arr2 + arr2.T)
arr2 -= arr2.T
arr5 = np.tril(arr5 + arr5.T)
arr5 -= arr5.T

result = (arr2 >= 18).astype(np.int32) + (arr5 >= 18).astype(np.int32)

print(np.sum(result >= 2))

### FIXED CODE ###

def div(n, d):
    cnt = 0
    while n % d == 0 and cnt < 18:
        n //= d
        cnt += 1
    return cnt


n = int(input())
dp = [[0]*19 for _ in range(19)]

ans = 0
for _ in range(n):
    x = round(float(input()) * pow(10, 9))
    two = div(x, 2)
    five = div(x, 5)
    ans += dp[18 - two][18 - five]
    for i in range(two + 1):
        for j in range(five + 1):
            dp[i][j] += 1

print(ans)
import sys
input = sys.stdin.readline

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

class Node():
    def __init__(self):
        self.children = []
        self.count = 0

G = [Node() for _ in range(N)]
for _ in range(N-1):
    p, c = map(int, input().split())
    G[p-1].children.append(c-1)

for _ in range(Q):
    p, x = map(int, input().split())
    G[p-1].count += x

def add_count(v):
    for child in G[v].children:
        G[child].count += G[v].count
        add_count(child)

add_count(0)

counts = [node.count for node in G]
print(*counts)

### FIXED CODE ###

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

# 遅延評価で加えてあげるだけ

N,Q = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

value = [0] * (N+1)
for p,x in PX:
    value[p] += x
    
q = [(1,0)]
while q:
    x,parent = q.pop()
    value[x] += value[parent]
    for y in graph[x]:
        if y == parent:
            continue
        q.append((y,x))

answer = ' '.join(map(str,value[1:]))
print(answer)
n = int(input())
a = input()
if a[0:int(n/2)]==a[int(n/2):n]:
	print("Yes")
else:
	print("No")

### FIXED CODE ###

a = input()
print(int(a)*int(a))
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in range(1,n+1):
  b.append(a[i] - a[i-1])
b.append(k - a[n] + a[0])
b = sorted(b)

print(sum(b:[:n])

### FIXED CODE ###

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

for i in range(1,n):
  b.append(a[i] - a[i - 1])
b.append(k - a[n-1] + a[0])

b = sorted(b)
print(sum(b[:n-1]))
n,l = input().split()
n = int(n)
l = int(l)
temp = input()
h = temp.split()
for i,item in enumerate(h):
    h[i] = int(item)

dp = [0]
for i,height in enumerate(h):
    temp = max(h)
    start = i-l if i-l >= 0 else 0
    for k in range(start,i):
        temp_step = abs(height - h[k])
        step = temp if temp < temp_step else temp_step + dp[k]
        temp = temp_step

    if i != 0:
        dp.append(step)


print(dp.pop())




### FIXED CODE ###


n = int(input())
temp = input()
h = temp.split()
for i,item in enumerate(h):
    h[i] = int(item)
dp = [0]
for i,height in enumerate(h):
    if i >=2:
        step1 = dp[i - 1] + abs(height - h[i-1])
        step2 = dp[i-2] + abs(height - h[i-2])
        dp.append(step1 if step1 <= step2 else step2)
    elif i == 1:
        dp.append(abs(height - h[i-1]))

print(dp.pop())
X = int(input())

if X => 30:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

X = int(input())
 
if X >= 30:
  print('Yes')
else:
  print('No')
N, K = map(int, input().split())                                                As = list(map(int, input().split()))
Fs = list(map(int, input().split()))                                                                                                                            As.sort()
As.reverse()                                                                    Fs.sort()
arr = []                                                                        M = 0
for a, f in zip(As, Fs):
    af = a*f                                                                        arr.append((af, a, f))                                                          M = af if af > M else M                                                     
f = -1                                                                          t = M                                                                           while f + 1 < t:
    m = f + (t-f) // 2
    k = K
    for AF, A, F in arr:                                                                d = A - m // F                                                                  if d > k:
            f = m
            break
        k -= d
    else:
        t = m

print(t)

### FIXED CODE ###

import math
N, K = map(int, input().split())
As = list(map(int, input().split()))
Fs = list(map(int, input().split()))

As.sort()
As.reverse()
Fs.sort()
arr = []
M = 0
for a, f in zip(As, Fs):
    af = a*f
    arr.append((af, a, f))
    M = af if af > M else M

f = -1
t = M
while f + 1 < t:
    m = f + math.ceil((t-f) / 2)
    k = K
    for AF, A, F in arr:
        d = A - m // F
        d = d if d >= 0 else 0
        if d > k:
            f = m
            break
        k -= d
    else:
        t = m

print(t)
sikaku = input()
sikaku_list = sikaku.split(' ')
sikaku_a = int(sikaku_list[0])
sikaku_b = int(sikaku_list[1])
menseki = sikaku_a * sikaku_b
syui = (sikaku_a + sikaku_b) * 2
print(menseki, ' '. syui)



### FIXED CODE ###

a,b = map(int, input().split())
print(a * b, (a + b) *2)
S = int(input())
K = int(input())

lst = []
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst[0])
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
#print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])

### FIXED CODE ###

S = int(input())
K = int(input())

lst = [0]*100
while S > 0:
    lst.append(S%10)
    S //= 10 # 必須
lst.reverse()
#print(lst)
j = 0
n = 0
while lst[j] == 1:
    n = j+1
    j += 1
#print('n =',n)
if K <= n:
    print(1)
else:
    print(lst[n])
a, b = map(int, input().split())

c = a * b

if c % 2 == 0:
  print('Even')
  else:
    print('Odd')

### FIXED CODE ###

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

i = a*b

if i%2 == 0:
  print('Even')
else:
  print('Odd')
n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
    exit()
a.sort()
left,right=0,a[n-1]
mid=right
while abs(right-left)>2:
    mid=(left+right)//2
    temp=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: left=mid
    else: right=mid
mid-=1
while True:
    temp=0
    flag=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: mid+=1
    else:
        flag=1
        break
    if flag: break
print(mid)

### FIXED CODE ###


n,k=map(int,input().split())
a=list(map(int,input().split()))
if k==0:
    print(max(a))
    exit()
a.sort()
left,right=0,a[n-1]
mid=right
while abs(right-left)>2:
    mid=(left+right)//2
    temp=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: left=mid
    else: right=mid
mid-=1
if mid<=0: mid=1
while True:
    temp=0
    flag=0
    for i in range(n-1,-1,-1):
        if a[i]<=mid: break
        temp+=a[i]//mid
    if temp>k: mid+=1
    else:
        flag=1
        break
    if flag: break
print(mid)
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
h, w, n = map(int, input().split())
#h, w, n = map(int, in1.split())

idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]
while idx1 < n:
    x = input().split()
    #x = in2[idx1].split()
    ab[idx1][0] = int(x[0])
    ab[idx1][1] = int(x[1])
    idx1 += 1

black_cnt = [0] * 10
black_cnt[0] = (h - 2) * (w - 2)

for idx1 in range(len(in2)):
    if ab[idx1][0] < 3:
        s = 0
    else:
        s = ab[idx1][0] - 3
    if ab[idx1][0] > h - 2:
        l = h - 2
    else:
        l = ab[idx1][0]
    Rrange = range(s, l)
    if ab[idx1][1] < 3:
        s = 0
    else:
        s = ab[idx1][1] - 3
    if ab[idx1][1] > w - 2:
        l = h - 2
    else:
        l = ab[idx1][1]
    Crange = range(s, l)

    for nowRow in Rrange:
        for nowCol in Crange:
            w_black = 0
            for idx2 in range(idx1):
                if nowRow < ab[idx2][0] <= nowRow + 3 and nowCol < ab[idx2][1] <= nowCol + 3:
                    w_black += 1
            black_cnt[w_black]     -= 1
            black_cnt[w_black + 1] += 1

for idx1 in range(len(black_cnt)):
    print(black_cnt[idx1])


### FIXED CODE ###

#in1 = '4 5 8'
#in2 = ['1 1', '1 4', '1 5', '2 3', '3 1', '3 2', '3 4', '4 4']
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
#in1 = '1000000000 1000000000 0'
#h, w, n = map(int, in1.split())
h, w, n = map(int, input().split())

idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]

black_cnt = [0] * 10
black_cnt[0] = (h - 2) * (w - 2)

if n != 0:
    while idx1 < n:
        x = input().split()
        #x = in2[idx1].split()
        ab[idx1] = [int(x[0]), int(x[1])]
        idx1 += 1

    myDict = {}
    for abitem in ab:
        if abitem[0] < 3:
            sr = 0
        else:
            sr = abitem[0] - 3
        if abitem[0] > h - 3:
            lr = h - 2
        else:
            lr = abitem[0]
        if abitem[1] < 3:
            sc = 0
        else:
            sc = abitem[1] - 3
        if abitem[1] > w - 3:
            lc = w - 2
        else:
            lc = abitem[1]

        for nowRow in range(sr, lr):
            for nowCol in range(sc, lc):
                key = str(nowRow) + ',' + str(nowCol)
                if key in myDict:
                    myDict[key] += 1
                else:
                    myDict[key] = 1

    for bcnt in myDict.values():
        black_cnt[bcnt] += 1
        black_cnt[0]    -= 1

for item in black_cnt:
    print(item)
from collections import*
from itertools import*
n,c=map(int,input().split())
cost=defaultdict(int)
for i in range(1,c+1):
    for k,v in enumerate(map(int,input().split())):
        cost[(k+1,i)]=v
#print(cost)

dwatta=defaultdict(list)
l=set()
for i in range(n):
    for j,v in enumerate(map(int,input().split())):
        mod=(i+j+2)%3
        dwatta[mod]+=[(v,(i,j))]
        l.add(v)
#print(l)
#print(dwatta) #割った値、座標、色
c=[]
for i in combinations(l,3):
    for s in permutations(i):
        ccc=0
        for k,v in dwatta.items():
            for f,t in enumerate([v]):
                for a,b in t:
                    if a!=s[f]:
                        ccc+=cost[(a,s[f])]
        c.append(ccc)
print(min(c))
        
            

### FIXED CODE ###

from itertools import*
n,c=map(int,input().split())
cost=[list(map(int,input().split()))for i in range(c)]
d=[[0]*c for i in range(3)]
for i in range(n):
    for j,v in enumerate(map(int,input().split())):
        d[(i+j)%3][v-1]+=1
print(min(sum(cost[j][cmb[i]]*d[i][j]for j in range(c)for i in range(3))for cmb in permutations(range(c),3)))