Harryxun/stf_run huggingface dataset:
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007

def main():

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


if __name__ == '__main__':
    main()


### FIXED CODE ###

# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()

def main():
    N, K = map(int, input().split())
    dt = N//K
    ans = min(abs(N - dt * K), abs(N - (dt+1)*K))
    print(ans)


if __name__ == '__main__':
    main()
n=int(input())
ans=0
for i in range(n):
    ans+=(eval(input().replace(' ','-')[::-1]))+1
print(ans)

### FIXED CODE ###

n=int(input())
sum=0
for i in range(n):
  l,r = [int(j) for j in input().split()]
  sum+=r-l+1
print(sum)
def calc(a, b):
    if (a * b) % 2 == 0:
        print('Even')
    else:
        print('Odd')
 
calc(a, b)

### FIXED CODE ###

a, b = map(int, input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")
# coding: utf-8
import sys


def main(argv=sys.argv):

  inputs_ = list(input())

    string_ = []

    for input_ in inputs_:

        if input_ == 'B':

            if not string_ == []:
              
                string_.pop(-1)

        else:

            string_.append(input_)

    print(''.join(string_))

    return 0


if __name__ == '__main__':
    sys.exit(main())


### FIXED CODE ###

# coding: utf-8
import sys


def main(argv=sys.argv):
  
    inputs_ = list(input())

    string_ = []

    for input_ in inputs_:

        if input_ == 'B':

            if not string_ == []:
              
                string_.pop(-1)

        else:

            string_.append(input_)

    print(''.join(string_))

    return 0


if __name__ == '__main__':
    sys.exit(main())
N = int(input())
A = list(map(int, input().split()))

cnt =0

while True:
    if [i for i in A if i%2 == 1]:
        break
    A = [i/2 for i in A if i%2 ==0]
    cnt += 1
    
prnt(cnt)


### FIXED CODE ###

S = input()
print(S.count('1'))
test

### FIXED CODE ###

D,T,S = [int(i) for i in input().split()]
out = 'Yes' if D <= T * S else 'No'
print(out)
s = [int(input()) for i in range(3)]
target = s[2]
if s[0] >= s[1]:
  long = s[0]
  short = s[1]
else:
  long = s[1]
  short = s[0]

for i in range(short):
  if long * i >= target:
    print(str(i+1))
    return

### FIXED CODE ###

s = [int(input()) for i in range(3)]
target = s[2]
if s[0] >= s[1]:
  long = s[0]
  short = s[1]
else:
  long = s[1]
  short = s[0]
 
for i in range(short):
  if long * (i+1) >= target:
    print(str(i+1))
    break
N=int(input())
W=list(map(int, input().split()))

output=abs(W[0]-sum(W[1:]))
for i in range(2, N-1):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output<temp:
    output=temp.copy()
    
print(output)

### FIXED CODE ###

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

output=abs(W[0]-sum(W[1:]))
for i in range(2, N):
  temp=abs(sum(W[:i])-sum(W[i:]))
  if output>temp:
    output=temp
    
print(output)
import numpy as np
_,p = [list(map(int, s.split())) for s in open(0)]
lcm = np.lcm.reduce(p)
x = 1e9 + 7
ans = 0
for q in p:
    ans += int((lcm/q)%x)
print(int(ans%x))

### FIXED CODE ###

from fractions import gcd
from functools import reduce

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

def lcm_mod(a, mod=-1):
    x = a[0]
    if mod == -1:
        for i in range(1, len(a)):
            x = (x * a[i]) // gcd(x, a[i])
    else:
        for i in range(1, len(a)):
            x *= (a[i] * mod_inv(gcd(x, a[i]), P)) % P
    return x

_,a = [list(map(int, s.split())) for s in open(0)]

P = 10**9 + 7
N = max(a)

lcm_ = lcm_mod(a, P)

ans = 0
for x in a:
    ans += int((lcm_*mod_inv(x,P))%P)
print(int(ans%P))
X,K,D = map(int,input().split())
X = abs(X)

if X <= K * D :
  if abs(X % D -D) < X % D :
    answer = abs(X % D -D)
  else :
    answer = X % D
else :
  answer = X - K * D
  

### FIXED CODE ###

S = list(input())
count = 0
max_count =0
for i in S :
    if(i=='R'):
        count = count + 1
    else :
        if(max_count < count) :
            max_count = count
            count = 0
if(max_count < count) :
    max_count = count

print(max_count)
a, b = map(int, input().split())
c = a % 2
d = b % 2
if c + d = 2:
  print(Odd)
else:
  print(Even)
 

### FIXED CODE ###

a, b = map(int, input().split())
c = a % 2
d = b % 2
if c + d == 2:
  print('Odd')
else:
  print('Even')
H,W = input().split(" ")
h,w = input().spplit(" ")

print((H-h) * (W-w))

### FIXED CODE ###

H,W = map(int,input().split(" "))
h,w = map(int,input().split(" "))

print((H-h)*(W-w))
import itertools
import numpy as np

N, M, X = map(int, input().split())
items = np.array([list(map(int, input().split())) for _ in range(N)], dtype=np.int32)

out = 10**18
for c in itertools.product([False, True], repeat=M):
    tmp = np.sum(items[np.where(c)], axis=0)
    if np.any(tmp):
      if M == np.count_nonzero(tmp[1:] >= X):
        out = min(out, tmp[0])
if out == 10**18:
  print(-1)
else:
  print(out) 

### FIXED CODE ###

import itertools
import numpy as np

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

items = np.array([list(map(int, input().split())) for _ in range(N)])

min_v = 10**18
for n in range(1, N+1):
  for c in itertools.combinations(range(N), n):
    tmp = np.sum(items[[c]], axis=0)
    c = tmp[0]
    a = tmp[1:]
    if M == np.count_nonzero(a >= X):
      min_v = min(min_v, c)
if min_v == 10**18:
  print(-1)
else:
  print(min_v)
n,m=map(int,input().split())
a=[0]*m
b=[0]*m
for i in range(m):
  a[i],b[i]=map(int,input().split())
c=[0]*m
for i in range(m):
  if a[i]==1:
    c[b[i]-1] |= 1
  if b[i]==n:
    c[a[i]-1] |= 2
print("POSSIBLE" if max(c)==3 else "IMPOSSIBLE")

### FIXED CODE ###

n,m=map(int,input().split())
a=[0]*m
b=[0]*m
for i in range(m):
  a[i],b[i]=map(int,input().split())
c=[0]*max(n,m)
for i in range(m):
  if a[i]==1:
    c[b[i]-1] |= 1
  if b[i]==n:
    c[a[i]-1] |= 2
print("POSSIBLE" if max(c)==3 else "IMPOSSIBLE")
n, y = map(int, input().split())

for a in range(n+1):
    for b in range(n-a+1):
        c = n-a-b
            
        if(and 10000*a + 5000*b + 1000*c == y):
            print(a, b, c)
            quit()

print("-1 -1 -1")

### FIXED CODE ###

N, Y = map(int, input().split())
break_flag = False

for i in range(N + 1):
    
    for j in range(i, N + 1):
        a, b, c = i, j - i, N - j
        
        if(10000 * a + 5000 * b + 1000 * c == Y):
            print(a, b, c)
            
            break_flag = True
            break
    
    if break_flag: break

if not break_flag: print('-1 -1 -1')
S = int(input())
ls = list(S)
if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
  print('Bad')
else:
  print('Good')

### FIXED CODE ###

#数字でも文字列として扱える。intにすると左一桁目から0がある場合存在しないものとなるので注意
s = input()
if s[0] == s[1] or s[1] == s[2] or s[2] == s[3]:
  print('Bad')
else:
  print('Good')
def bisearch(li,target):
    l=0
    r=len(li)-1
    if(target<li[0][0]):
        return li[m][0]-target+li[m][1]
    if(li[-1][0]<target):
        return target-li[-1][0]+li[-1][1]
    while(l<=r):
        m=int((l+r)/2)
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1


inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q


for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1
        

for i in x:
    print(bisearch(li,i))

### FIXED CODE ###

def bisearch(li,target):
    l=0
    r=len(li)-1
    while(l<=r):        
        m=int((l+r)/2)
        if(m==len(li)-1):
            return target-li[m][0]+li[m][1]
        if(li[m][0]<target and target<li[m+1][0]):
            return min(target-li[m][0]+li[m][1],li[m+1][0]-target+li[m+1][1])
        if(m==0 and target<li[0][0]):
            return li[0][0]-target+li[0][1]
        if(target<li[m][0]):
            r = m-1
        else:
            l = m+1

inf = 10**15
A,B,Q = [int(x) for x in input().split()]
s = [0]*(A+1)
t = [0]*(B+1)
x = [0]*Q

for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())
s[-1] = inf
t[-1] = inf

li = []
a = b = 0
while(a<A or b<B):
    if(s[a]<t[b]):
        li.append([s[a],min(abs(t[b]-s[a]),abs(t[b-1]-s[a]))])
        a+=1
    else:
        li.append([t[b],min(abs(t[b]-s[a]),abs(t[b]-s[a-1]))])
        b+=1

for i in x:
    print(bisearch(li,i))
import numpy as np
import fractions
import functools
N, X = map(int, input().split())
x = np.array(sorted(list(map(int, input().split()))))
x = np.insert(x, np.where(x > X)[0], X)
x = np.diff(x)
print(functools.reduce(fractions.gcd, x))

### FIXED CODE ###

import numpy as np
import fractions
import functools
N, X = map(int, input().split())
x = np.array(sorted(list(map(int, input().split()))))
x =  np.insert(x, np.where(x > X)[0][0], X) if len(np.where(x > X)[0]) > 0 else np.append(x, X)
x = np.diff(x)
print(functools.reduce(fractions.gcd, x))
x=int(input(''))
y=[0]*x
for i in range(x):
  y[i]=input('')
a=0
w=0
t=0
r=0
for i in range(x):
  if y[i]==AC:
    a=a+1
  elif y[i]==WA:
    w=w+1
  elif y[i]==TLE:
    t=t+1
  else:
    r=r+1
print('AC x {0}\nWA x {1}\nTLE x {2}\nRE x {r}'.format(a,w,t,r))
  

### FIXED CODE ###

x=int(input(''))
y=[0]*x
for i in range(x):
  y[i]=input('')
a=0
w=0
t=0
r=0
for i in range(x):
  if y[i]=='AC':
    a=a+1
  elif y[i]=='WA':
    w=w+1
  elif y[i]=='TLE':
    t=t+1
  else:
    r=r+1
print('AC x {0}\nWA x {1}\nTLE x {2}\nRE x {3}'.format(a,w,t,r))
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)

    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    cnt = [0]*N
    visited = [0]*N

    for _ in range(N-1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        G[a].add(b)
        G[b].add(a)

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

    visited[0]=1
    st = [0]
    while st:
        v = st.pop()
        for u in G[v]:
            if visited[u]:
                continue
            visited[u] = 1
            cnt[u] += cnt[v]
            st.append(u)    

    print(*cnt)

if __name__ == '__main__':
    main()



### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)

N, Q = map(int, input().split())
G = [set() for _ in range(N)]
cnt = [0]*N
visited = [0]*N

def dfs(start_node):
    for i in G[start_node]:
        if visited[i]==0:
            visited[i]=1
            cnt[i] += cnt[start_node]
            dfs(i)

for _ in range(N-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].add(b)
    G[b].add(a)

for i in range(Q):
    node, x = map(int, input().split())
    node -= 1
    cnt[node] += x

visited[0]=1
#dfs(0)
st = [0]
while st:
    v = st.pop()
    for u in G[v]:
        if visited[u]: continue
        visited[u] = 1
        cnt[u] += cnt[v]
        st.append(u)    

ans = map(str, cnt)
print(' '.join(ans))
def solve(i, cost, know, x, a):
    global res
    if i == len(a):
        for j in range(m):
            if know[j] < x:
                return
        res = min(res, cost)
        return
    solve(i + 1, cost, know, x, a)
    for j in range(m):
        know[j] += a[i][j + 1]
    solve(i + 1, cost + a[i][0], know, x, a)
    for j in range(m):
        know[j] -= a[i][j + 1]
fin = open('input.txt', 'r')
n, m, x = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
know = [0] * (m)
res = 10 ** 7
solve(0, 0, know, x, a)
print(res if res != 10 ** 7 else - 1)

### FIXED CODE ###

def solve(i, cost, know, x, a):
    global res
    if i == len(a):
        for j in range(m):
            if know[j] < x:
                return
        res = min(res, cost)
        return
    solve(i + 1, cost, know, x, a)
    for j in range(m):
        know[j] += a[i][j + 1]
    solve(i + 1, cost + a[i][0], know, x, a)
    for j in range(m):
        know[j] -= a[i][j + 1]
n, m, x = [int(i) for i in input().split()]
a = [[int(i) for i in input().split()] for j in range(n)]
know = [0] * (m)
res = 10 ** 7
solve(0, 0, know, x, a)
print(res if res != 10 ** 7 else - 1)
in_list = input().split()
A, B, K = int(in_list[0]), int(in_list[1]), int(in_list[2])

for k in range(K):
  if A > 0:
    A -= 1
  elif B > 0:
    B -= 1
  elif:
    pass

print(A, B)


### FIXED CODE ###

a = input().split()
print(a[1]+a[0])
from collections import deque
import numpy as np


def solve():
    H, W = map(int, input().split())
    maze = ['' for _ in range(H)]
    for i in range(H):
        maze[i] = list(input())
    maze = np.array(maze)
    black_l = list(zip(*np.where(maze=='#')))
    que = deque([])
    for x, y in black_l:
        que.append([y, x])
    ans = 0
    
    while len(que) > 0:
        a = len(que)
        for _ in range(a):
            target = que.pop()
            if target[0] != 0:
                if maze[target[0]-1][target[1]] == '.':
                    maze[target[0]-1][target[1]] = '#'
                    que.append([target[0]-1, target[1]])
            if target[0] != H - 1:
                if maze[target[0]+1][target[1]] == '.':
                    maze[target[0]+1][target[1]] = '#'
                    que.append([target[0]+1, target[1]])
            if target[1] != 0:
                if maze[target[0]][target[1]-1] == '.':
                    maze[target[0]][target[1]-1] = '#'
                    que.append([target[0], target[1]-1])
            if target[1] != W - 1:
                if maze[target[0]][target[1]+1] == '.':
                    maze[target[0]][target[1]+1] = '#'
                    que.append([target[0], target[1]+1])
        ans += 1
    
    print(ans-1)


if __name__ == '__main__':
    solve()

### FIXED CODE ###

from collections import deque


def solve():
    H, W = map(int, input().split())
    grid = [['' for _ in range(W)] for _ in range(H)]
    que = deque()
    for i in range(H):
        grid[i] = list(input())
        for j in range(W):
            if grid[i][j] == '#':
                que.append([i, j])
    
    xy = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    ans = 0
    while que:
        n = len(que)
        for _ in range(n):
            y, x = que.popleft()
            for i in range(4):
                xi = x - xy[i][0]
                yi = y - xy[i][1]
                if 0 <= xi <= W-1 and 0 <= yi <= H-1:
                    if grid[yi][xi] == '.':
                        grid[yi][xi] = '#'
                        que.append([yi, xi])
        ans += 1
    print(ans-1)


if __name__ == '__main__':
    solve()
N, M = list(map(int, input().split()))

for i in range(M/N+1):
  k = i + N
  if M % k == 0:
    print(int(M/k))
    break

print(1)

### FIXED CODE ###

N, M = list(map(int, input().split()))
tmp=0

if N==1:
  print(M)
  tmp=1
else:
  for i in range(int(M**0.8)+1):
    k = i + N
    if M % k == 0:
      print(int(M/k))
      tmp=1
      break

if tmp==0:
  print(1)
import sys
import numpy as np
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, q = na()
a, b = [0]*n, [0]*n
G = [[] for i in range(n)]
for i in range(n-1):
        a, b = na()
        G[a-1].append(b-1)

seen = [0] * n
counter = [0] * n
for i in range(q):
        p, x = na()
        seen = np.zeros(n)
        counter[p-1] += x

visit = [False] * n
visit[0] = True
stack = [0]

while stack:
        parent = stack.pop()
        for child in G[parent]:
                if visit[child]:
                        None
                else:
                        visit[child] = True
                        counter[child] += counter[parent]
                        stack.append(child)

print(*counter)

### FIXED CODE ###

import sys
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, q = na()
a, b = [0]*n, [0]*n
G = [[] for i in range(n)]
for i in range(n-1):
        a, b = na()
        G[a-1].append(b-1)
        G[b-1].append(a-1)

counter = [0] * n
for i in range(q):
        p, x = na()
        counter[p-1] += x

visit = [False] * n
visit[0] = True
stack = [0]

while stack:
        parent = stack.pop()
        for child in G[parent]:
                if visit[child]:
                        None
                else:
                        visit[child] = True
                        counter[child] += counter[parent]
                        stack.append(child)

print(*counter)
S = input()
ans = 'ABC'
if S = 'ABC':
  ans = 'ARC'
print(ans)

### FIXED CODE ###

S = input()
ans = 'ABC'
if S == 'ABC':
  ans = 'ARC'
print(ans)
# coding: utf-8
import time
import re
import math
import fractions

def main():
    N,K=map(int,input().split())
    for i in range(1,K+1):
        if N-K+1-i>0:
            l=math.factorial(N-K+1)/(math.factorial(i)*math.factorial(N-K+1-i))
            r=math.factorial(K-i+i-1)/(math.factorial(K-i)*math.factorial(i-1))
            print(int(l*r%(1e9+7)))
        else:
            print(1)
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global N,A,B,C,D,memo,mx,mn,temp

### FIXED CODE ###

# coding: utf-8
import re
import math
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)

def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 

 
#main

N,blue=map(int,input().split())
fac=fac_list(N,mod)
red=N-blue
for a in range(1,blue+1):
    if red+1<a:
        num=0
    else:
        num=fac[red+1]*pow(fac[red+1-a]*fac[a],mod-2,mod)
        num*=fac[blue-(a-1+1)+a-1]*pow(fac[blue-(a-1+1)]*fac[a-1],mod-2,mod)
    print(num%mod)
import sys
from copy import copy
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353


def two(x):
    return "0" * (h - 1 - len(bin(x)[2:])) + bin(x)[2:]


h, w, k = map(int, input().split())
S = []
ans = inf
for i in range(h):
    S.append(input().strip())
# for way_cut in range(1 << (h - 1)):
for way_cut in range(2,3):
    way_cut = two(way_cut)
    number_cut_horizontal = way_cut.count("1")
    number_cut_vertical = 0
    CUT = [-1]
    for i in range(len(way_cut)):
        if way_cut[i] == '1':
            CUT.append(i)
    CUT.append(len(way_cut))
    SUM = [0] * (w)
    PRE = [0] * (w)
    for col in range(w):
        for i in range(1, len(CUT)):
            for between in range(CUT[i - 1] + 1, CUT[i] + 1):
                SUM[i] += 1 if S[between][col] == "1" else 0
        isok = True
        for i in range(1, len(CUT)):
            if PRE[i] + SUM[i] > k:
                isok = False
        if not isok:
            number_cut_vertical += 1
            PRE = copy(SUM)
            SUM = [0]*(w)
            # recheck
            for i in range(1, len(CUT)):
                if PRE[i] > k:
                    number_cut_vertical = inf
                    break
        else:
            for i in range(1, len(CUT)):
                PRE[i] += SUM[i]
                SUM[i] = 0
    ans = min(ans, number_cut_vertical + number_cut_horizontal)
print(ans)


### FIXED CODE ###

import sys
from copy import copy
input = sys.stdin.readline
'''
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
for test in range(int(input())):
'''
inf = 100000000000000000  # 1e17
mod = 998244353


def two(x):
    return "0" * (h - 1 - len(bin(x)[2:])) + bin(x)[2:]


h, w, k = map(int, input().split())
S = []
ans = inf
for i in range(h):
    S.append(input().strip())
for way_cut in range(1 << (h - 1)):
    way_cut = two(way_cut)
    number_cut_horizontal = way_cut.count("1")
    number_cut_vertical = 0
    CUT = [-1]
    for i in range(len(way_cut)):
        if way_cut[i] == '1':
            CUT.append(i)
    CUT.append(len(way_cut))
    SUM = [0] * (w)
    PRE = [0] * (w)
    for col in range(w):
        for i in range(1, len(CUT)):
            for between in range(CUT[i - 1] + 1, CUT[i] + 1):
                SUM[i] += 1 if S[between][col] == "1" else 0
        isok = True
        for i in range(1, len(CUT)):
            if PRE[i] + SUM[i] > k:
                isok = False
        if not isok:
            number_cut_vertical += 1
            PRE = copy(SUM)
            SUM = [0]*(w)  # leave out
            # recheck
            for i in range(1, len(CUT)):
                if PRE[i] > k:
                    number_cut_vertical = inf
                    break
        else:
            for i in range(1, len(CUT)):
                PRE[i] += SUM[i]
                SUM[i] = 0
    ans = min(ans, number_cut_vertical + number_cut_horizontal)
print(ans)
from  math import factorial
N = int(input())
N2=math.factorial(N)

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

### FIXED CODE ###

import math
N = int(input())
N2=math.factorial(N)

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