Harryxun/stf_run huggingface dataset:
N, C = map(int, input().split())
INF = float("inf")
D = []
for i in range(C):
    D.append(list(map(int, input().split())))
c = []
for i in range(N):
    c.append([n - 1 for n in list(map(int, input().split()))])

# 前計算
cost = [[0 for _ in range(3)] for _ in range(C)]
for i in range(N):
    for j in range(N):
        for k in range(C):
            cost[(i + j) % 3][k] += D[c[i][j]][k]

ans = INF
for i in range(C):
    for j in range(C):
        if i == j:
            continue
        for k in range(C):
            if k in (i, j):
                continue
            ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k])

print(ans)


### FIXED CODE ###

from copy import deepcopy
# 多次元配列を作成する
def make_multi_list(initial, degree):
    ans = [initial for _ in range(degree[-1])]
    for d in reversed(degree[:-1]):
        ans = [deepcopy(ans) for _ in range(d)]
    return ans


N, C = map(int, input().split())
INF = float("inf")
D = []
for i in range(C):
    D.append(list(map(int, input().split())))
c = []
for i in range(N):
    c.append([n - 1 for n in list(map(int, input().split()))])

# 前計算
cost = make_multi_list(0, [3, C])
for i in range(N):
    for j in range(N):
        for k in range(C):
            cost[(i + j) % 3][k] += D[c[i][j]][k]

ans = INF
for i in range(C):
    for j in range(C):
        if i == j:
            continue
        for k in range(C):
            if k in (i, j):
                continue
            ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k])

print(ans)
import sys
from itertools import permutations

N,C = map(int,input().split())
D = [list(map(int,sys.stdin.readline().split())) for _ in range(C)]
grids = [list(map(int,sys.stdin.readline().split())) for _ in range(N)]

ans = float('inf')
for cmb in permutations([i for i in range(1,C+1)],3):
  tmp_ans = 0
  for j, row in enumerate(grids):
    for i, val in enumerate(row):
      if val != cmb[(i+j+2)%3]: tmp_ans += D[val-1][cmb[(i+j+2)%3]-1]
      #print(i, j, val, cmb, tmp_ans)
  ans = min(tmp_ans, ans)
  #print(ans, tmp_ans, cmb)
print(ans)

### FIXED CODE ###

[print('ABC') if int(input()) < 1000 else print('ABD')]
n = int(input())
a_list = list(map(int, input().split()))
cnt = 0
even = True

while(even)
	for i in range(n):
  		if a_list[i] % 2 != 0
        	even = False
            break
        else:
          a_list[i] /= 2
    cnt += 1
          
print(cnt)

### FIXED CODE ###

n = int(input())
a_list = list(map(int, input().split()))
cnt = 0
even = True

while(even):
    for i in range(n):
        if a_list[i] % 2 != 0:
            even = False
            break
        else:
          a_list[i] /= 2
    cnt += 1

print(cnt - 1)
n = int(input())
l=list(map(int ,input().split()))
print((max(l)-min(l))

### FIXED CODE ###

n = int(input())
l=list(map(int ,input().split()))
print(max(l)-min(l))
A=int(input())
B=int(input())
C=int(input())
if A==B and A!=C: print('Yes')
if A==C and A!=B: print('Yes')
if B==C and B!=A: print('Yes')
else: print('No')

### FIXED CODE ###

A,B,C = input().split()
if A==B and A!=C or B==C and B!=A or C==A and C!=B:
    print("Yes")
else:
    print("No")
import sys
N=int(input())
table=[]
for i in range(N):
    x,y=map(int,input().split())
    table.append((x,y))
L=[0,0]
for x,y in table:
    L[(x+y)%2]=1
if sum(L)==2:
    print(-1)
    sys.exit()
def f(x,y,m):
    s=m
    a=''
    if x>=0:
        a+='R'*x
        s-=x
    else:
        a+='L'*abs(x)
        s-=abs(x)
    if y>=0:
        a+='U'*y
        s-=y
    else:
        a+='D'*abs(y)
        s-=abs(y)
    a+='LR'*s
    return a
if L[0]==1:
    m=40
    d=[1]*40
    ans=[]
    for x,y in table:
        ans.append(f(x,y,m))
else:
    m=39
    d=[1]*39
    ans=[]
    ans=[]
    for x,y in table:
        ans.append(f(x,y,m))

print(m)
print(' '.join(map(str,d)))
for s in ans:
    print(s)

### FIXED CODE ###

import sys
N=int(input())
table=[]
for i in range(N):
    x,y=map(int,input().split())
    table.append((x,y))
L=[0,0]
for x,y in table:
    L[(x+y)%2]=1
if sum(L)==2:
    print(-1)
    sys.exit()
def f(a,b):
    pas=''
    s=a[::-1]
    t=b[::-1]
    A=[0]*31
    B=[0]*31
    for i in range(len(s)):
        if s[i]=='1':
            A[i]=1
    for i in range(len(t)):
        if t[i]=='1':
            B[i]=1
    n=31
    for i in range(n):
        if A[i]==0 and B[i]==0:
            pas+='L'
        if A[i]==0 and B[i]==1:
            pas+='D'
        if A[i]==1 and B[i]==0:
            pas+='U'
        if A[i]==1 and B[i]==1:
            pas+='R'
        
    return pas
if L[0]==1:
    m=32
    d=[1]+[pow(2,i) for i in range(31)]
    ans=[]
    S=[]
    for x,y in table:
        S.append((x-1,y))
    for x,y in S:
        a='R'
        u=(x+y+(pow(2,31)-1))//2
        v=(x-y+(pow(2,31)-1))//2
        u=bin(u)[2:]
        v=bin(v)[2:]
        a+=f(u,v)
        ans.append(a)       
else:
    m=31
    d=[pow(2,i) for i in range(31)]
    ans=[]
    S=table
    for x,y in S:
        a=''
        u=(x+y+(pow(2,31)-1))//2
        v=(x-y+(pow(2,31)-1))//2
        u=bin(u)[2:]
        v=bin(v)[2:]
        a+=f(u,v)
        ans.append(a)      

print(m)
print(' '.join(map(str,d)))
for s in ans:
    print(s)
import heapq
 
def FUNCTION(A, M):
    heapq.heapify(A)
    for i in range(M):
        heapq.heappush(A, int(heapq.heappop(A) / 2))
        print (A)
    return -sum(A)

N = list(map(int, (input().split(' '))))
A = list(map(lambda x: x*(-1), map(int, (input().split(' ')))))
print(FUNCTION(A, N[1]))

### FIXED CODE ###

import heapq

N = list(map(int, (input().split(' '))))
A = list(map(lambda x: x*(-1), map(int, (input().split(' ')))))

heapq.heapify(A)
for i in range(N[1]):
    heapq.heappush(A, int(heapq.heappop(A) / 2))

print(-sum(A))
N = int(input())

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

sum_water = sum(A)
A = A[1:] + A[0:3]
X = []
for i in range(N):
    tmp=sum_water
    for j in range((N-1)//2):
        tmp-=A[i+j*2]*2
    X.append(tmp)
for i in range(len(X)-1):
    print(X[i], end="")
    print(" ", end="")
print(X[-1])

### FIXED CODE ###

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

sum_water = sum(A)

tmp=sum_water
for j in range((N-1)//2):
    tmp-=A[j*2+1]*2
print(tmp, end="")
print(" ", end="")

for i in A[:-1]:
    tmp = 2*i - tmp
    print(tmp, end="")
    print(" ", end="")
d,t,s == map(int, input().split())

tmp = d/s

if tmp <= t:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

d,t,s = map(int, input().split())

tmp = d/s

if tmp <= t:
    print("Yes")
else:
    print("No")
x=int(input())
if x==0:
    print('1')
else:
    print('0

### FIXED CODE ###

x=int(input())
if x==0:
    print('1')
else:
    print('0')
X, Y, Z = map(int, input().split())
print(X + Y + Z)

### FIXED CODE ###

print(input().count("1"))
n,m = map(int,input().split())

inf = float("inf")
ans = [inf]*n**2
for _ in range(m):
    a,b = map(int,input().split())
    C = list(map(int,input().split()))
    res = 0
    for c in C:
        res |= 2**(c-1)
    ans[res] = a

aa = []
for i,a in enumerate(ans):
    if a == inf:continue
    aa.append([i,a])

for i,a in aa:
    for j,b in aa:
        ans[i|j] = min(ans[i|j],a+b)
print(ans[-1])

### FIXED CODE ###

n,m = map(int,input().split())
vals = []
inf = float("inf")
res = [inf]*2**n

for i in range(m):
	a,b = map(int,input().split())
	C = list(map(int,input().split()))
	cur = 0
	for c in C:
		cur |= 2**(c-1)
	res[cur] = min(res[cur],a)

ans = []
for i,r in enumerate(res):
	if res[i] == inf:
		continue
	ans.append([i,r])


for i,a in ans:
	for j in range(2**n):
		res[i|j] = min(res[i|j],res[i]+res[j])

if res[-1] == inf:
	print(-1)
else:
	print(res[-1])
N = input()
N = list[N[0],N[1]]
if '9' in N:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

N = input()

if N[0] == '9' or N[1] == '9':
  print('Yes')
else:
  print('No')
def main():
    N, K = (int(i) for i in input().split())
    H = [int(i) for i in input().split()]
    H.sort()
    ans = 10**12
    for i in range(N-K+1):
        ans = min(ans, H[i+K-1] - H[i])

    print(ans)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    N, K = (int(i) for i in input().split())
    h = [int(input()) for i in range(N)]
    h.sort()
    ans = 10**9 + 7
    for i in range(N-(K-1)):
        ans = min(ans,h[i+(K-1)] - h[i])
    print(ans)
if __name__ == "__main__":
    main()
n = int(input())

def fact(n):
    if n == 0:
        return 1
    return n * fact(n - 2)


s = list(str(fact(n)))
print(s)
c = 0
i = len(s) - 1
while s[i] == "0":
    c += 1
    i -= 1
print(c)

### FIXED CODE ###

# v=[]
# num=251
# for i in range(num):
#     if i==0 or i==1:
#         v.append(1)
#     else:
#         v.append(i*v[i-2])
        
# for i in range(0,num,2):
#     print(i,v[i],end=' ')
#     print()

n=int(input())
if n%2!=0:
    print(0)
else:
    ans=n//10
    n=n//10
    i=1
    while(1):
        ans+=n//(5**i)
        if n//(5**i)==0:
            break
        i+=1
        
        
    print(ans)
def solve(n, m, NUM):
    for i in range(len(m)):
        if n[NUM + i] is not m[i]:
            return -1
    return 1


N, M = [int(i) for i in input().split()]
n_pic = [input() for i in range(N)]
m_pic = [input() for i in range(M)]
num = 0
if M is 1:
    for n in n_pic:
        if -1 is not n.find(m_pic[0]):
            print('Yes')
            exit()
    print('No')
    exit()

for n in range(len(n_pic)):
    for n_len in range(N - M + 1):
        while -1 is not solve(n_pic[n+num], m_pic[num], n_len):
            num += 1
            print(num)
            if num is M:
                print('Yes')
                exit()
        num = 0
print('No')


### FIXED CODE ###

def solve(n, m, NUM):
    for i in range(len(m)):
        if n[NUM + i] is not m[i]:
            return -1
    return 1


N, M = [int(i) for i in input().split()]
n_pic = [input() for i in range(N)]
m_pic = [input() for i in range(M)]
num = 0
if M is 1:
    for n in n_pic:
        if -1 is not n.find(m_pic[0]):
            print('Yes')
            exit()
    print('No')
    exit()

for n in range(N - M + 1):
    for n_len in range(N - M + 1):
        while -1 is not solve(n_pic[n + num], m_pic[num], n_len):
            num += 1
            if num is M:
                print('Yes')
                exit()
        num = 0
print('No')
s=input()
ans=0
cur=0
ACGT=set("A","C","G","T")
for ss in s:
  if ss in ACGT:
    cur+=1
  else:
    ans=max(cur,ans)
    cur=0
print(max(ans,cur))



### FIXED CODE ###

S=input()
SS=S+"X"
ACGT=["A","C","G","T"]
m=0
for i in range(len(S)):
  j=0
  while SS[i+j] in ACGT:
    j+=1   
  m=max(m,j)
print(m)
a,b=(int(x) for x in input().split())
print(a)
print(b)

am=int(100/8*a)
al=int(100/8*(a+1))
if (a%4)==0:
       al=al-1

bm=int(10*b)
bl=int(10*(b+1))-1

print (am,al)
print (bm,bl)
for ia in range(am,al+1):
       for ib in range(bm,bl+1):
       		if ia==ib:
       			print (ia)
       			exit()
      
print -1

### FIXED CODE ###

a,b=(int(x) for x in input().split())

for i in range(1,1010):
#	print (i)
	ia=int(i*0.08)
	ib=int(i*0.1)
#	print (ia,ib)
	if ia==a and ib==b:
		print (i)
		exit()
else:
	print (-1)
import math

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

not_replaced_max = A[0]

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

# def divisor(n):
#     limit = int(math.sqrt(n))
#     for i in range(2, limit):
#         if n % i == 0:
#             result.append(i)
#     return result

# def merge(A, B):

# divisor_list = divisor(A[1])
# for i in range(1, N):
#     not_replaced_max = gcd(not_replaced_max, A[i])
# print(replaced_max)
#
A.sort()

def func(n):
    limit = int(math.sqrt(n))
    divisor = []
    for i in range(1, limit):
        if n % i == 0:
            divisor.append(i)
    return divisor

def merge(A, B):
    divisor_list = [a for a in A]
    for b in B:
        if b not in A:
            divisor_list.append(b)
    return divisor_list

divisor_list = merge(func(A[0], A[1]))
divisor_list.sort(reverse=True)
is_end = False
for d in divisor_list:
    count = 0
    for a in A:
        if a % d != 0:
            count += 1
            if count > 1:
                break
    if count == 0 or is_end:
        print(d)
    else:
        is_end = True


### FIXED CODE ###

import math

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

gcd_list = [0 for _ in range(N)]

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

for i in range(1, N):
    gcd_list[i] = gcd(gcd_list[i-1], A[i-1])
last_gcd = 0
for i in range(N-2, -1, -1):
    last_gcd = gcd(last_gcd, A[i+1])
    gcd_list[i] = gcd(last_gcd, gcd_list[i])

print(max(gcd_list))
import sys
s=list(input())
if s[0]!='A':
    break
count=0
for i in range(2,len(s)-2):
    if s[i]=='C':
        count+=1

if count==1:
    s.remove('A')
    s.remove('C')    
    res=''.join(s)
    print('AC' if res.islower()==True else 'WA') #str.islower():全部小文字ならTrue

else:
    print('WA')

### FIXED CODE ###

s=list(input())
count=0
if s[0]!='A':
    count+=2
for i in range(2,len(s)-1):
    if s[i]=='C':
        count+=1

if count==1:
    s.remove('A')
    s.remove('C')    
    res=''.join(s)
    print('AC' if res.islower()==True else 'WA') #str.islower():全部小文字ならTrue

else:
    print('WA')
p,q,r = map(int(input().split()))
print(min((p+q),(p+r),(q+r)))

### FIXED CODE ###

p,q,r = map(int,input().split())
print(min(p+q, q+r, r+p))
def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]


for i in range(32):
    x = '{:0>6}'.format(bin(i).split('b')[1])
    s=list(x)
    s= [int(s) for s in s]
    if check(m) == 1:
            inc +=1
    
print(inc)

### FIXED CODE ###

def add(s,d):
     sum=0
     for i in d[1:]:
          sum+=s[i] 
     return sum

def check(m):
    for i in range(m):
        if add(s, d[i]) % 2 == p[i]:
            pass
        else :
            return -1
    return 1
        
        
d = []
s=[]
inc=0

n, m = (int(x) for x in input().split())
for i in range(m):
    i = [int(i) for i in input().split()] 
    d.append(i)
p = [int(i) for i in input().split()]

r = 2 ** n

for i in range(r):
    x = str(bin(i).split('b')[1]).zfill(n + 1)
    s=list(x)
    s= [int(s) for s in s]
    if check(m) == 1:
            inc +=1
    
print(inc)
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
ai=0
bi=0
for i in range(n+m):
  ans+=1
  if n-ai==0:
    k-=b[bi]
    bi+=1
  elif m-bi==0:
    k-=a[ai]
    ai+=1
  elif a[ai]>b[bi]:
    k-=b[bi]
    bi+=1
  elif b[bi]>a[ai]:
    k-=a[ai]
    ai+=1
  else:
    if n==ai+2:
      k-=b[bi]
      bi+=1
    elif m==bi+2:
      k-=a[ai]
      ai+=1
    elif a[ai+1]>=b[bi+1]:
      k-=b[bi]
      bi+=1
    elif a[ai+1]<b[bi+1]:
      k-=a[ai]
      ai+=1
  if k<0:
    ans-=1
    break
print(ans)

### FIXED CODE ###

n,m,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
b=list(map(int,input().split()))
t=sum(b)
j=m-1
ans=0
for i in range(n+1):
  t+=a[i]
  while j>=0 and t>k:
    t-=b[j]
    j-=1
  if t>k:
    break
  ans=max(ans,j+i+1) 
print(ans)
N = int(input())
S = input()

if N >= 1 and N <=100:
	def S.islower():
	if True:
      T = S[0:N / 2 - 1]
    else:
 
if (T + T in s):
  print('Yes')
else:
  print('No')

### FIXED CODE ###

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

T = S[0:int(N) // 2]
W = S[int(N) // 2:int(N) + 1] 

if T == W:
	print('Yes')
else:
	print('No')
x = int(input())
u = 0

def b(x,u):
    if x>=5:
        x-=5
        u+=5
        b(x,u)
    else:
        print(u)

def a(x,u):
    if x>=500:
        x-=500
        u+=1000
        a(x,u)
    else:
        b(x,u)

a(x,u)


### FIXED CODE ###

x = int(input())
u = 0
def a(x,u):
    if x>=500:
        u+=1000 * (x // 500)
        x = x % 500
        a(x,u)
    elif x>=5:
        u+=5 * (x // 5)
        x = x % 5
        a(x,u)
    else:
        print(u)
a(x,u)
N = int(input())
 
if N == 1:
	answer = "Hello World"
	print(answer)
elif N == 2:
	A = input(int())
    B = input(int())
	answer = A + B
	print(int(answer))

### FIXED CODE ###

N = int(input())

if N == 1:
	answer = "Hello World"
	print(answer)
elif N == 2:
	A = int(input())
	B = int(input())
	answer = A + B
	print(answer)
# D - Xor Sum 2

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

l,r = 0,1 # l<rの場合を考える
tmp_xor = A[l] ^ A[r]
tmp_sum = A[l] + A[r]
ans = N

while 1:
    if tmp_xor == tmp_sum:
        ans += r-l # 先頭l以上、末尾rの部分数列の個数
        r += 1
        if r == N:
            break
        tmp_xor = tmp_xor ^ A[r]
        tmp_sum += A[r]
    elif l+1 < r:
        tmp_sum -= A[l]
        tmp_xor = tmp_xor ^ A[l]
        l += 1
    else:
        l = r
        r += 1
        if r == N:
            break
        tmp_xor = A[l] ^ A[r]
        tmp_sum = A[l] + A[r]

print(ans)

### FIXED CODE ###

# D - Xor Sum 2

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

if N == 1:
    print(1)
    exit()

l,r = 0,1 # l<rの場合を考える
tmp_xor = A[l] ^ A[r]
tmp_sum = A[l] + A[r]
ans = N

while 1:
    if tmp_xor == tmp_sum:
        ans += r-l # 先頭l以上、末尾rの部分数列の個数
        r += 1
        if r == N:
            break
        tmp_xor = tmp_xor ^ A[r]
        tmp_sum += A[r]
    elif l+1 < r:
        tmp_sum -= A[l]
        tmp_xor = tmp_xor ^ A[l]
        l += 1
    else:
        l = r
        r += 1
        if r == N:
            break
        tmp_xor = A[l] ^ A[r]
        tmp_sum = A[l] + A[r]

print(ans)
a=input()
b=input()
if len(a)+1=len(b) and a==b[0:a]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a=input()
b=input()
if len(a)+1==len(b) and b[:len(a)]==a:
  print("Yes")
else:
  print("No")
import sys
import math
input = sys.stdin.readline
a, b, x = [int(x) for x in input().strip().split()]
if x >= a ** 2 * b / 2:
    theta = math.degrees(math.atan(2 * (a ** 2 * b - x) / (a ** 3)))
else:
    theta = math.degrees(math.atan(a * (b ** 2) / (2 * x)))
print(theta)s

### FIXED CODE ###

import sys
import math
input = sys.stdin.readline
a, b, x = [int(x) for x in input().strip().split()]
if x >= a ** 2 * b / 2:
    theta = math.degrees(math.atan(2 * (a ** 2 * b - x) / (a ** 3)))
else:
    theta = math.degrees(math.atan(a * (b ** 2) / (2 * x)))
print(theta)
while true:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    for i in range(a):
        print('#' * b)
    print()

### FIXED CODE ###

while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break
    for i in range(a):
        print('#' * b)
    print()
N = int(input())
H = list(map(int,input.split()))
ANS = True
for i in range(1,N):
    if H[N-i] >= H[N-i-1]:
        continue
    else if (H[N-i] - H[N-i-1]) == -1:
        H[N-i-1] += 1
    else:
        ANS = False
        break
if ANS:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

ABC = list(map(int,input().split()))
A = ABC[0]
B = ABC[1]
C = ABC[2]
if (A>(B+C)):
    print(0)
else:
    D = A-B
    a = C - D
    print(a)
N = int(input())
kuku= [1, 2, 3, 4, 5, 6, 7, 8, 9]
c = 0

for a in kuku:
    for b in kuku:
        if a*b == N:
            c+=1
if c>=1:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

a,b =  (int(x) for x in input().split())
if a<10 and b<10:
    print (a*b)
else:
    print('-1')
import itertools
n,k = input().split
a = list(map(int,input().split()))

comb = itertools.combinations(a,3)

l = []
for i in comb:
  l.append(list(i))
  
A = []
one = [1]*len(l)
for i in range(len(l)):
  for j in range(3):
    one[i]*=l[i][j]
    A.append(one[i])
    
l_max = max(one)
waru = 10**9 + 7

mod = l_max % waru
print(mod)



### FIXED CODE ###

import sys
 
n, k = map(int, input().split())
a = [int(x) for x in input().split()]
mod = pow(10, 9)+7
zero = 0
plus = []
minus = []
for i in range(n):
  if a[i] == 0:
    zero += 1
  elif a[i] > 0:
    plus.append(a[i])
  else:
    minus.append(a[i])
 
P, M = len(plus), len(minus)
plus.sort(reverse=True)
minus.sort()
ans = 1
if n == k:
  for i in range(n):
    ans *= a[i]
    ans %= mod
elif P+M < k:
  ans = 0
elif P == 0:
  if zero and k%2:
    ans = 0
  else:
    if k%2:
      minus.reverse()
    for i in range(k):
      ans *= minus[i]
      ans %= mod
else:
  q = 0
  if k%2:
    ans *= plus[0]
    ans %= mod
    q = 1
  judge = []
  for i in range((len(plus)-q)//2):
    judge.append(plus[2*i+q]*plus[2*i+q+1])
  for i in range(len(minus)//2):
    judge.append(minus[2*i]*minus[2*i+1])
  judge.sort(reverse=True)
  for i in range(k//2):
    ans *= (judge[i]%mod)
    ans %= mod
 
print(ans)
a, p = map(int, input().split())

apple = 3 * a + b
pie = apple // 2

print(pie)

### FIXED CODE ###

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

apple = 3 * a + p
pie = apple // 2

print(pie)
from sys import stdin
import math
 
A, B = [x for x in input().split()]
A = int(A)
B = round(B*100)
 
print(A*B/100)


### FIXED CODE ###

#!/usr/bin/env python3
A, B = [s for s in input().split()]
A = int(A)
B = round(float(B) * 100)
 
print(str(A * B // 100))
n=int(input())
s=list(input() for _ in range(n))
m,i,f,both=0,0,0,0

for i in range(n):
    m +=s[i].count("AB")
    if s[i][0]=="B":
        i +=1
    if s[i][-1]=="A":
        f +=1


if both!=0:
    if i!=0 and f!=0:
        print(m+both+min(i,f)-1)
    else:
        print(m+both+min(i,f))

else:
    print(min(i,f))


### FIXED CODE ###

n,k=list(map(int,input().split()))
print(n-k+1)
s=input()
a=s//1000
b=(s-a*1000)//100
c=(s-a*1000-b*100)//10
d=s-a*1000-b*100-c*10
if a==b :
    print"Bad"
    elif b==c:
        print"Bad"
    elif c==d:
        print"Bad"
else:
    print"Good"

### FIXED CODE ###

s=int(input())
a=s//1000
b=(s-a*1000)//100
c=(s-a*1000-b*100)//10
d=s-a*1000-b*100-c*10
if a==b :
    print("Bad")
elif b==c:
    print("Bad")
elif c==d:
    print("Bad")
else:
    print("Good")
N = int(input())
S = input()

# 右全部#にする

b = S.count('W')

ans = 10**9
cost = 0
for c in S:
    if c == '.':
        # 今見てる所以降全部白にする事を考える
        w -= 1
        # まだ見てない白の数 + 今まで白にした黒のコストが答え候補
        if w + cost < ans:
            ans = w + cost
    else:
        # 今見てる所が黒の場合、白の個数は減らない
        if w + cost< ans:
            ans = w + cost
        # 以降の計算に向けてコストを1増やす
        cost += 1

print(ans)

### FIXED CODE ###

import bisect
N = int(input())
S = input()
# 右全部#
b = []
w = []
for i in range(N):
    if S[i] == '#':
        b.append(i)
    if S[i] == '.':
        w.append(i)

kouho = []
for i in range(0,N+1):
    cost = 0
    #iより右にある白の数
    cost += len(w) - bisect.bisect_left(w,i)
    #iより左にある黒の数
    cost += bisect.bisect_left(b,i)
    
    if cost >= 0:
        kouho.append(cost)

print(min(kouho))
import numpy as np
while 1:
    global a,c
    c = np.array([[0]*14]*14)
    a = np.array([[0]*14]*14)
    a[1:-1,1:-1] = [list(map(int,list(input()))) for i in range(12)]


    def dfs(x,y,n):
        if c[x][y] == 0 and a[x][y] == 1:
            c[x][y] = n
            [dfs(x+i, y+j, n) for i,j in [(-1,0),(1,0),(0,-1),(0,1)]]


    [[dfs(x,y,12*x + y) for x in range(1,12+1)] for y in range(1,12+1)]
    flat = [a for b in c for a in b]
    print(len(set(flat)) - 1)
    dump = input()
    #if input() ==


### FIXED CODE ###

state = 1
while(state):
    a = [[0 for i in range(12)] for j in range(12)]
    for i in range(12):
        a[i] = [int(i) for i in list(input())]
    try:
        _ = input()
    except EOFError:
        state = 0

    def erase(y,x):
        if a[y][x] != 0:
            a[y][x] = 0
            if x-1 > -1:
                erase(y,x-1)
            if x+1 < 12:
                erase(y,x+1)
            if y-1 > -1:
                erase(y-1,x)
            if y+1 < 12:
                erase(y+1,x)

    count = 0
    for i in range(12):
        for j in range(12):
            if a[i][j] != 0:
                count += 1
                erase(i,j)
    print(count)