Harryxun/stf_run huggingface dataset:
N = int(input())
a = list(map(int, input().split())) 

b = list(accumulate(a))
ma = b[-1]
mi = 10**10
for sunuke in b:
    arai = ma - sunuke
    if abs(sunuke - arai) < mi:
        mi = abs(sunuke - arai)
print(mi)

### FIXED CODE ###

from itertools import accumulate

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

b = list(accumulate(a))
ma = b[-1]
mi = 10**10
for sunuke in b[:N-1]:
    arai = ma - sunuke
    if abs(sunuke - arai) < mi:
        mi = abs(sunuke - arai)
print(mi)
# 再帰制限に引っかかった場合に外す
# import sys
# sys.setrecursionlimit(100000)
nCr = {}
def cmb(n, r):
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]


n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

maxvalue = -1
ans = -1
for num in lsnum:
    val = cmb(ma,num)
    if(ma == num):
        continue
    if maxvalue < val:
        maxvalue = val
        ans = [ma, num]
print (ans[0], ans[1])


### FIXED CODE ###

import sys

n = input()
n= int(n)
ls = input().split()
lsnum = list(map(int,ls))
ma = max(lsnum)

minvalue = 10000000000
ans = -1
for num in lsnum:
    if num == ma:
        continue
    value = abs(ma-num*2)
    if minvalue >= value:
        minvalue = value
        ans = [ma, num]
print (ans[0], ans[1])
N = int(input())

def cnt(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '357') else 0
    for c in '357':
        ret += cnt(s+c)
    return ret

pritn(cnt('0'))

### FIXED CODE ###

N = int(input())

def cnt(s):
    if int(s) > N:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '357') else 0
    for c in '357':
        ret += cnt(s+c)
    return ret

print(cnt('0'))
N = I()
A = LI()
B = [0]*(10**5+1)
for a in A:
    B[a] += 1

print(sum(B[i] != 0 for i in range(10**5+1))-(sum(max(0,B[i]-1) for i in range(10**5+1)) % 2))


### FIXED CODE ###

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
A = LI()
B = sorted(set(A))
d = {}
for b in B:
    d[b] = 0
for a in A:
    d[a] += 1

C = [d[b] for b in B]

ans = len(B)
x = sum(c-1 for c in C)
if x % 2 == 1:
    ans -= 1

print(ans)
ex = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == 0 and c == 0:
        break
    for i in ex:
        for j in ex:
            for k in ex:
                if eval( "((("+a+k+b+")"+j+c+")"+i+d+")") == 10:
                    print "(((",a,k,b,")",j,c,")",i,d,")"
                    flag = 1
                    break
    if flag == 1:
        break
    for i in ex:
        for j in ex:
            for k in ex:
                if eval( "(("+a+k+b+")"+i+"("+c+j+d+"))" ) == 10:
                    print "((",a,k,b,")",i,"(",c,j,d,"))"
                    flag = 1
                    break
    if flag == 1:
        break
    else:
        print 0

### FIXED CODE ###

op = ["+", "-", "*"]
while True:
    a, b, c, d = map(str, raw_input().split())
    if a == "0" and c == "0":
        break
    n = [0,1,2,3]
    q = [a,b,c,d]
    flag = 0
    for ii in n:
        m = [0,1,2,3]
        m.remove(ii)
        for jj in m:
            l = [0,1,2,3]
            l.remove(ii);l.remove(jj)
            for kk in l:
                o = [0,1,2,3]
                o.remove(ii);o.remove(jj);o.remove(kk)
                for ll in o:
                    for i in op:
                        for j in op:
                            for k in op:
                                if eval( "((("+q[ii]+k+q[jj]+")"+j+q[kk]+")"+i+q[ll]+")") == 10:
                                    print "(((",q[ii],k,q[jj],")",j,q[kk],")",i,q[ll],")"
                                    flag = 1
                                    break
                                if eval( "(("+q[ii]+k+q[jj]+")"+i+"("+q[kk]+j+q[ll]+"))" ) == 10:
                                    print "((",q[ii],k,q[jj],")",i,"(",q[kk],j,q[ll],"))"
                                    flag = 1
                                    break
                            if flag == 1:
                                break
                        if flag == 1:
                            break
                    if flag == 1:
                        break
                if flag == 1:
                    break
            if flag == 1:
                break
        if flag == 1:
            break
    if flag == 0:
        print 0
import sys
sys.setrecursionlimit(3000)
import queue

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
H, W = map(int, input().split())
field = [input() for _ in range(H)]

dist = [[-1] * W for _ in range(W)]
que = queue.Queue()
que.put((0, 0))
dist[0][0] = 0

while not que.empty():
  y, x = que.get()
  for i in range(4):
    ny, nx = y + dy[i], x + dx[i]
    if nx < 0 or nx >= W or ny < 0 or ny >= H:
      continue
    if field[ny][nx] == '#':
      continue
    if dist[ny][nx] != -1:
      continue
    dist[ny][nx] = dist[y][x] + 1
    que.put((ny, nx))
    
count = 0
for y in range(H):
  for x in range(W):
    if field[y][x] == '#':
      count += 1
      
if dist[H - 1][W - 1] != -1:
  print(H * W - count - dist[H - 1][W - 1] - 1)
else:
  print(-1)

### FIXED CODE ###

from collections import deque

R,C = list(map(int,input().split()))
Sx,Sy = 0,0
Gx,Gy = R-1,C-1
Mize = [input() for _ in range(R)]
dd = [[1, 0], [-1, 0], [0, 1], [0, -1]]

def bfs():
    d = [[float('inf')] * C for i in range(R)]
    q = deque([])
    d[Sx][Sy] = 0
    q.append((Sx,Sy))
    while(len(q) != 0):
        x,y = q.popleft()
        if x == Gx and y == Gy:
            break
        for dx,dy in dd:
            
            if -1<x+dx<R and -1<y+dy<C and Mize[x+dx][y+dy]=='.' and d[x+dx][y+dy] == float('inf'):
                q.append([x+dx,y+dy])
                d[x+dx][y+dy] = d[x][y] + 1
    return d[Gx][Gy]

white = sum([m.count('#') for m in Mize])
need = bfs()
if need == float('inf'):
    print(-1)
else:
    print(R*C-white-need-1)
a, b, c = map(int, input().split())

if max(a,b,c) == sum(a,b,c)-max(a,b,c):
  print("Yes")
else:
  print("No")

### FIXED CODE ###

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

if max(a,b,c) == (a+b+c)-max(a,b,c):
  print("Yes")
else:
  print("No")
W,H,x,y,r = map(int,raw_input())
if x + r <= w and y + r <= H:
  print "Yes"
else:
  print "No"

### FIXED CODE ###

W,H,x,y,r = map(int,raw_input().split(" "))
if x + r <= W and y + r <= H and x - r >= 0 and y - r >= 0:
  print "Yes"
else:
  print "No"
N, K = map(int, input().split())
A = tuple(map(int, input().split()))

costs = [0] * (N + 1)

if K <= N:
    for i in range(1, K+1):
        loc = A[loc - 1]
    print(loc)

else:
    loc = 1
    for i in range(1, K+1):
        loc = A[loc - 1]

        if costs[loc] > 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= offset
    K %= loop

    for _ in range(K):
        loc = A[loc - 1]
    print(loc)

### FIXED CODE ###

N, K = map(int, input().split())
A = tuple(map(lambda n: int(n) - 1, input().split()))

costs = [-1] * N
loc = 0

if K <= N:
    for i in range(K):
        loc = A[loc]
    print(loc + 1)

else:
    costs[loc] = 0
    for i in range(1, K):
        loc = A[loc]

        if costs[loc] >= 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= i
    K %= loop

    for _ in range(K):
        loc = A[loc]
    print(loc + 1)
import math
s = int(input())
for i in range(s,2*s):
  if i%2==0:
    continue
  for k in range(3,round(math.sqrt(s))+1,2):
    t = 1
    if i%k ==0:
      t = 0
      break
  if t ==1:
    print(i)
    break
  
  

### FIXED CODE ###

import math
s = int(input())
if s ==2:
  print(2)
else:
  for i in range(s,2*s):
    if i%2==0:
      continue
    for k in range(3,round(math.sqrt(s))+1,2):
      t = 1
      if i%k ==0:
        t = 0
        break
    if t ==1:
      print(i)
      break
N,K = map(int,input().split())
S = list(input())

if len(S) == 1:
    print(1)
elif len(S) == 2:
    print(2)
elif S[0] == '0':
    LA = [0]
    LB = [0]
    for i in range(1,N-1):
        if (S[i] != S[i+1]) & (S[i] == '0'):
            LA.append(i+1)
        elif (S[i] != S[i+1]) & (S[i] == '1'):
            LB.append(i)
    LB.append(N-1)
    ANS = 0
    for i in range(len(LA)-K):
        J = LB[i+K]-LA[i]+1
        if J > ANS:
            ANS = J
    print(ANS)
else:
    LA = [0]
    LB = []
    for i in range(1,N-1):
        if (S[i] != S[i+1]) & (S[i] == '0'):
            LA.append(i+1)
        elif (S[i] != S[i+1]) & (S[i] == '1'):
            LB.append(i)
    LB.append(N-1)
    ANS = 0
    if K > len(LB)-1:
        print(len(S))
    else:
        for i in range(len(LA)-K):
            J = LB[i+K]-LA[i]+1
            if J > ANS:
                ANS = J
        print(ANS)

### FIXED CODE ###

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

if len(S) == 1:
    print(1)
elif len(S) == 2:
    print(2)
elif S[0] == '0':
    LA = [0]
    LB = [0]
    for i in range(0,N-1):
        if (S[i] != S[i+1]) & (S[i] == '0'):
            LA.append(i+1)
    for i in range(1,N-1):
        if (S[i] != S[i+1]) & (S[i] == '1'):
            LB.append(i)
    LB.append(N-1)
    ANS = 0
    if K >= len(LB)-1:
        print(N)
    else:
        for i in range(len(LB)-K):
            J = LB[i+K]-LA[i]+1
            if J > ANS:
                ANS = J
        print(ANS)
else:
    LA = [0]
    LB = []
    for i in range(0,N-1):
        if (S[i] != S[i+1]) & (S[i] == '0'):
            LA.append(i+1)
        elif (S[i] != S[i+1]) & (S[i] == '1'):
            LB.append(i)
    LB.append(N-1)
    ANS = 0
    if K >= len(LB)-1:
        print(N)
    else:
        for i in range(len(LB)-K):
            J = LB[i+K]-LA[i]+1
            if J > ANS:
                ANS = J
        print(ANS)
s = input()

if s ='AAA' or s = 'BBB':
    print('No')
else:
    print('Yes')

### FIXED CODE ###

s = input()

if s == 'AAA' or s == 'BBB':
    print('No')
else:
    print('Yes')
A, B = map(int, input().split())

n = 1
c = 0

while n < B:
	n = n + A -1
	c = c+1
    
print(c)

### FIXED CODE ###

S=input()
T=input()

score=0

if S[0] == T[0]:
  	score=score+1
if S[1] == T[1]:
  	score=score+1
if S[2] == T[2]:
	score=score+1
 
print(score)
N = int(input())

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

a.reverse()

A = []
B = []

for x in range(0,N+1,2):
    A.append(a[x])

for y in range(1,N,2):
    B.append(a[y])
    

print(sum(A)-sum(B))

### FIXED CODE ###

N = int(input())

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

a.reverse()

A = []
B = []

for x in range(0,N,2):
    A.append(a[x])
    
        
for y in range(1,N,2):
    B.append(a[y])
    
print(sum(A)-sum(B))
# 2125
# 方針．f(n)を求めるのがlog(N)で終わりそうだから普通に素直に実装すればいいのでは？
N = int(input())
X = list(input())

# i番目のビットを反転させて,
# やってることは似てるはずなのになんかうまく行かない
dic={}
bn00 = X.count('1')
x00 = int(''.join(X),2)

for i in range(N):
    # ちゃんともとに戻してね，ということで本のビット
    b = int(X[i]) & 1
    bn = b ^ 1
    if bn:
        bn0 = bn00 + 1
    else:
        bn0 = bn00 - 1
    x0 = x00 % bn0
    xi = x0 - b * pow(2,N-1-i,bn0) + bn * pow(2,N-1-i,bn0)
    xi %= bn0
    num = xi
    count = 1
    while num > 0:
        p = format(num,'b').count('1')
        num = num % p
        count += 1
    print(count)


### FIXED CODE ###

# 2125
# 方針．f(n)を求めるのがlog(N)で終わりそうだから普通に素直に実装すればいいのでは？
# ただし最初だけは別に実装する必要がある
N = int(input())
X = list(input())

# i番目のビットを反転させて,
# やってることは似てるはずなのになんかうまく行かない
dic={}
bn00 = X.count('1')
x00 = int(''.join(X),2)
aa = x00 % (bn00+1)
if bn00-1==0:
    bb = 0
else:
    bb = x00 % (bn00-1)
for i in range(N):
    # ちゃんともとに戻してね，ということで本のビット
    b = int(X[i]) & 1
    bn = b ^ 1
    if bn:
        bn0 = bn00 + 1
        x0 = aa
    else:
        bn0 = bn00 - 1
        x0 = bb
    if bn0==0: # ビットが全く立っていないつまり0の時，0%0はエラーを起こすので，n%0もエラーを起こす
        print(0)
        continue
    if b: # もとのビットが立っている場合は減らす，ここの計算量が一番重いので計算量を削減してみる
        xi = x0 - b * pow(2,N-1-i,bn0)
    if bn:
        xi = x0 + bn * pow(2, N - 1 - i, bn0)
    xi %= bn0
    num = xi
    count = 1
    while num > 0:
        p = format(num,'b').count('1') # 10進数を２進数にかえるなら，これがいいのかも,int(str(i),2)を使うっていう手もあるけど周りくどい
        num = num % p
        count += 1
    print(count)
# -*- coding: utf-8 -*-

import sys

def length(a, b):
    return ((a[0] - b[0])**2 + (a[1] - b[1])**2)**0.5

def solve_sim_equ(a, b, c, d, e, f):
    '''
    From Problem 0004.
    This function solves following equation.
    ax + by = c
    dx + ey = f
    '''
    if a==0 and d==0:
        if b==0 and e==0:
            return 0., 0.
        if b != 0:
            return 0., c/b+0.
        else:
            return 0., f/e+0.
    elif b==0 and e==0:
        if a != 0:
            return 0., d/a+0.
        else:
            return 0., a/d+0.

    if b == 0:
        a, d = d, a
        b, e = e, b
        c, f = f, c
    g = e / b
    x = (g*c - f) / (g*a - d)
    y = (c - a*x) / b
    return x+0., y+0.


def circumscribed_circle(x, y, z):
    def get_equ_coef(p, q):
        h_x = (p[0] + q[0]) / 2
        h_y = (p[1] + q[1]) / 2
        a = q[1] - p[1]
        b = p[0] - q[0]
        c = b * h_x - a * h_y
        return b, -a, c
    coef = get_equ_coef(x, y) + get_equ_coef(y, z)
    center = solve_sim_equ(*coef)
    r = length(center, x)
    return center, r


def main():
    N = int(input())
    for i in range(N):
        vs = [float(v) for v in input().split()]
        a = (vs[0], vs[1])
        b = (vs[2], vs[3])
        c = (vs[4], vs[5])
        center, r = circumscribed_circle2(a, b, c)
        print('{0:.3f} {1:.3f} {2:.3f}'.format(center[0], center[1], r))


if __name__ == '__main__':
    main()

### FIXED CODE ###

# -*- coding: utf-8 -*-

import sys

def length(a, b):
    return ((a[0] - b[0])**2 + (a[1] - b[1])**2)**0.5

def solve_sim_equ(a, b, c, d, e, f):
    '''
    From Problem 0004.
    This function solves following equation.
    ax + by = c
    dx + ey = f
    '''
    if a==0 and d==0:
        if b==0 and e==0:
            return 0., 0.
        if b != 0:
            return 0., c/b+0.
        else:
            return 0., f/e+0.
    elif b==0 and e==0:
        if a != 0:
            return 0., d/a+0.
        else:
            return 0., a/d+0.

    if b == 0:
        a, d = d, a
        b, e = e, b
        c, f = f, c
    g = e / b
    x = (g*c - f) / (g*a - d)
    y = (c - a*x) / b
    return x+0., y+0.


def circumscribed_circle(x, y, z):
    def get_equ_coef(p, q):
        h_x = (p[0] + q[0]) / 2
        h_y = (p[1] + q[1]) / 2
        a = q[1] - p[1]
        b = p[0] - q[0]
        c = b * h_x - a * h_y
        return b, -a, c
    coef = get_equ_coef(x, y) + get_equ_coef(y, z)
    center = solve_sim_equ(*coef)
    r = length(center, x)
    return center, r


def main():
    N = int(input())
    for i in range(N):
        vs = [float(v) for v in input().split()]
        a = (vs[0], vs[1])
        b = (vs[2], vs[3])
        c = (vs[4], vs[5])
        center, r = circumscribed_circle(a, b, c)
        print('{0:.3f} {1:.3f} {2:.3f}'.format(center[0], center[1], r))


if __name__ == '__main__':
    main()
# coding: utf-8

a, b, c, d = map(int, input().split())
alice_time = [x for x in range(a, b+1)]
bob_time = [x for x in range(c, d+1)]
pushed_time = set(alice_time) & set(bob_time)

if len(pushed_time) == 0:
  print(0)
else:
  print(pushed_time - 1)

### FIXED CODE ###

# coding: utf-8

a, b, c, d = map(int, input().split())
alice_time = [x for x in range(a, b+1)]
bob_time = [x for x in range(c, d+1)]
pushed_time = set(alice_time) & set(bob_time)

if len(pushed_time) == 0:
  print(0)
else:
  print(len(pushed_time) - 1)
a,b,c,d = map(int, input().split())

if (b > c) or (a > d):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

x = int(input())
print("ACL" * x)
def phyonkichi(p, n):
    yoko = 0
    tate = 1
    if n[-1] == '0':
        n = 10
    else:
        n = int(n[-1])
    s = dic[n]
    p_lis = [(p[yoko]+a[yoko], p[tate]+a[tate]) for a in jump]
    s_lis = [(s[yoko]+a[yoko], s[tate]+a[tate]) for a in sprinkler]
    c_lis = []
    for v in list(set(p_lis) & set(s_lis)):
        if 0 <= v[yoko] <= 9 and 0 <= v[tate] <= 9:
            c_lis.append(v)
    else:
        if not c_lis:
            return
            
    for v in c_lis:
        if not v in res:
            res.append(v)
            if phyonkichi(v, str(n+1)): return True
            del res[-1]
        else:
            print v, res
            print 'OK'
            return True
        
        
jump = [(2,-1),(2,0),(2,1),
        (-1,-2),(0,-2),(1,-2),
        (-2,1),(-2,0),(-2,-1),
        (-1,2),(0,2),(1,2)]

sprinkler = [(0,0),(1,0),(1,-1),
             (0,-1),(-1,-1),(-1,0),
             (-1,1),(0,1),(1,1)]

while True:
    w, h = map(int, raw_input().split(' '))
    if w == 0 and h == 0: break
    N = int(raw_input())
    lis = raw_input().split(' ')
    c_lis = [lis[i:i+2] for i in range(0, 20, 2)]
    dic = {}
    res = []
    for i, c in enumerate(c_lis):
        dic[i+1] = (int(c[0]), int(c[1]))
    else:
        if not phyonkichi((w, h), '1'):
            print 'NA'

### FIXED CODE ###

def phyonkichi(p, n):
    yoko = 0
    tate = 1
    s = dic[n]
    p_lis = [(p[yoko]+a[yoko], p[tate]+a[tate]) for a in jump]
    s_lis = [(s[yoko]+a[yoko], s[tate]+a[tate]) for a in sprinkler]
    c_lis = []
    for v in list(set(p_lis) & set(s_lis)):
        if 0 <= v[yoko] <= 9 and 0 <= v[tate] <= 9:
            c_lis.append(v)
    if c_lis:
        if n == N:
            print 'OK'
            return True
        else:
            for v in c_lis:
                if phyonkichi(v, n+1): return True
    else:
        return
        
jump = [(2,-1),(2,0),(2,1),
        (-1,-2),(0,-2),(1,-2),
        (-2,1),(-2,0),(-2,-1),
        (-1,2),(0,2),(1,2)]

sprinkler = [(0,0),(1,0),(1,-1),
             (0,-1),(-1,-1),(-1,0),
             (-1,1),(0,1),(1,1)]

while True:
    w, h = map(int, raw_input().split(' '))
    if w == 0 and h == 0: break
    N = int(raw_input())
    lis = raw_input().split(' ')
    lis = [lis[i:i+2] for i in range(0, 2*N, 2)]
    dic = {}
    for i, c in enumerate(lis):
        dic[i+1] = (int(c[0]), int(c[1]))
    else:
        if not phyonkichi((w, h), 1):
            print 'NA'
def C_IrohasObsession():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    D_tmp = []
    for x in range(10):
        if x not in D:
            D_tmp.append(x)
    for x in range(len(D_tmp)):
        ans = D_tmp[-1] * (10**(x+1))
    if N > ans:
        ans = D_tmp[1] * (10 ** len(str(N-1)))
    else:
        ans = 0
        for i_1 in D_tmp:
            if ans > N: break
            ans = i_1
            if len(str(N)) <= len(str(ans)): continue
            for i_10 in D_tmp:
                if ans > N: break
                ans = i_10 * 10 + i_1
                if len(str(N)) <= len(str(ans)): continue
                for i_100 in D_tmp:
                    if ans > N: break
                    ans = i_100 * 100 + i_10 * 10 + i_1
                    if len(str(N)) <= len(str(ans)): continue
                    for i_1000 in D_tmp:
                        if ans > N: break
                        ans = i_1000 * 1000 + i_100 * 100 + i_10 * 10 + i_1
    print(ans)

if __name__ == "__main__":
    C_IrohasObsession()

### FIXED CODE ###

def C_IrohasObsession():
    N, K = map(int, input().split())
    D = list(map(int, input().split()))
    ans = 0
    for x in range(N, 100000):
        for y in str(x):
            if int(y) in D:
                break
        else:
            ans = int(x)
            break
    print(ans)

if __name__ == "__main__":
    C_IrohasObsession()
a, b = map(int, input().split())

if a <= 0 and b => 0:
    print("Zero")
elif a > 0 and b > 0:
    print('Positive')
elif a < 0 and b < 0:
    if (b - a + 1) % 2:
        print('Negative')
    else:
        print('Positive')
        

### FIXED CODE ###

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

if a <= 0 and b >= 0:
    print("Zero")
elif a > 0 and b > 0:
    print('Positive')
elif a < 0 and b < 0:
    if (b - a + 1) % 2:
        print('Negative')
    else:
        print('Positive')
n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)

n+=1

A = []
for i in range(n):
    A.append([int(j) for j in input()])
#print(A)

ans = n*m


for subset in subsets:
    cur_ans = len(subset)
    #print(subset)
    tmp = []
    col = 0
    subset.append(1000000000)
    running_sum = [0 for i in range(len(subset)+10)]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr] and row_ptr+1 < len(subset):
                row_ptr += 1
            #print(subset, row, row_ptr, running_sum)    
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                #print(dict(update_at = (row,col)), running_sum)
                col -= 1
                
                running_sum = [0 for i in range(len(subset)+10)]
                cur_ans += 1
                
            
            
        col += 1                
    #print(subset, cur_ans)
    ans = min(ans, cur_ans)
print(ans)


### FIXED CODE ###

n, m, k = [int(i) for i in input().split()]

subsets = []
splits = [i for i in range(1, n)]
n -= 1
for i in range(2**n):
    x = []
    for j in range(n):
        if i&(1<<j):
            x.append(j)
    subsets.append(x)
n+=1
A = []
for i in range(n):
    A.append([int(j) for j in input()])
ans = n*m
for subset in subsets:
    cur_ans = len(subset)
    tmp = []
    col = 0
    subset.append(100000)
    running_sum = [0 for i in range(len(subset))]    
    while col<m:
        row_ptr = 0    
        for row in range(n):
            if row > subset[row_ptr]:
                row_ptr += 1
            running_sum[row_ptr] += A[row][col]
            if running_sum[row_ptr] > k:
                col -= 1
                running_sum = [0 for i in range(len(subset))]
                cur_ans += 1
                break
                
        col += 1                
        if cur_ans >= ans:
          break
    ans = min(ans, cur_ans)
print(ans)
print(int(input()**2)

### FIXED CODE ###

print(int(input())**2)
n,k =map(int,input().split())

test = n

while True:
  zet = abs(test-k)
  if zet == 0:
    print(zet)
    break
  if zet > test:
    print(f)
    break
  test = zet

### FIXED CODE ###

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

syou = n//k

zet = abs(n-k*syou)
if zet == 0:
  print(zet)
else:
  zet1 = abs(n-k*(syou+1))
  if zet > zet1:
    print(zet1)
  else: 
    print(zet)
n = int(input())
h = list(map(int, input().split()))
cnt = 0
move_cnt = []
for i in range(n-1):
   if h[i] >= h[i+1]:
      cnt += 1
      move_cnt.append(cnt)
   else:
      cnt = 0
print(max(move_cnt))

### FIXED CODE ###

n = int(input())
h = list(map(int, input().split()))
cnt = 0
ans = 0
for i in range(n-1):
   if h[i] >= h[i+1]:
      cnt += 1
      ans = max(ans, cnt)
   else:
      cnt = 0
print(ans)
N,M = map(int,input().split())

D = {}
m = M
for i in range(2, int(M**0.5)+2):
    while m % i == 0:
        D[i] = D.get(i,0)+1
        m = m//i
if D == {}:
    D[M] = 1

d = []
for v in D.values():
    d.append(v)

tmp = [0] * len(d)
for i in range(len(d)):
    tmp[i] = (math.factorial(N-1+d[i]) // (math.factorial(N-1)*math.factorial(d[i])))%(10**9 + 7)

ans = 1
for i in range(len(tmp)):
    ans = ans*tmp[i]%(10**9 +7)
print(ans)


### FIXED CODE ###

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

m = M
f = {}
while m%2==0:
    f[2] = f.get(2,0)+1
    m = m//2

l = int(m**0.5)+1
k = 3
while m != 1:
    if k>l:
        f[m] = f.get(m,0)+1
        break
    while m%k==0:
        f[k] = f.get(k,0)+1
        m = m//k
    k+=2
ans = 1
for k in f:
    for i in range(N-1+f[k],N-1,-1):
        ans = (ans * i) 
    for i in range(f[k]):
        ans = ans // (i+1)
    ans = ans % ((10**9)+7)
print(ans)