akhauriyash/Code-Regression huggingface dataset:
unittest
{
	assert( [ "5 3", "-30 -10 10 20 50" ].parse.expand.solve == 40 );
	assert( [ "3 2", "10 20 30" ].parse.expand.solve == 20 );
	assert( [ "1 1", "0" ].parse.expand.solve == 0 );
	assert( [ "8 5", "-9 -7 -4 -3 1 2 3 4" ].parse.expand.solve == 10 );
}



import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nk = input.front.split.to!( long[] );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	
	return tuple( nk[ 1 ], xs );
}

auto solve( long k, long[] xs )
{
	auto d = long.max;
	
	// 連続したロウソクK本を取るパターンを全検索
	for( auto i = 0; i + k <= xs.length; i++ )
	{
		auto ss = xs[ i .. i + k ];
		
		// 全ロウソク間の距離
		auto dm = ( ss[ 0 ] - ss[ $ - 1 ] ).abs;
		
		// 座標 0 から端のロウソクまでの距離
		auto db = min( ss[ 0 ].abs, ss[ $ - 1 ].abs );
		
		// 最短距離を取る
		d = min( d, dm + db );
	}
	
	return d;
}


Measured memory_bytes: 7012
#include <iostream>

using namespace std;

typedef long long ll;

ll solve (ll n, ll a, ll b) {
  if (a % 2 == b % 2) {
    return (b - a) / 2;
  }

  ll lft = a + solve(n, 1, b - a);
  ll rgt = n - b + 1 + solve(n, a + (n - b + 1), n);
  return min(lft, rgt);
}

int main () {
  ll n, a, b;
  cin >> n >> a >> b;

  cout << solve(n, a, b) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <limits>
#include <vector>

int cnt = 0;

void merge(std::vector<int>* A, int left, int mid, int right) {
  std::vector<int> L(A->begin() + left, A->begin() + mid);
  std::vector<int> R(A->begin() + mid, A->begin() + right);
  L.push_back(std::numeric_limits<int>::max());
  R.push_back(std::numeric_limits<int>::max());
  int i = 0, j = 0;
  for (int k = left; k < right; ++k) {
    cnt++;
    if (L[i] <= R[j]) {
      (*A)[k] = L[i];
      i = i + 1;
    } else {
      (*A)[k] = R[j];
      j = j + 1;
    }
  }
}

void mergeSort(std::vector<int>* A, int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  std::vector<int> ss;
  int n;
  std::cin >> n;
  for (int i = 0; i < n; i ++) {
    int s;
    std::cin >> s;
    ss.push_back(s);
  }
  mergeSort(&ss, 0, n);
  for (int i = 0; i < n; ++i) {
    std::cout << ss[i] << (i == n - 1 ? "\n" : " ");
  }
  std::cout << cnt << std::endl;
}

Measured memory_bytes: 8596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x=0,a,n,ans=0;
  cin>>n;
  for(int i2=0;i2<n;i2++){
    cin>>x;
    int y=sqrt(x);
    a=0;
    for(int i=2; i<=y;i++){
      if(x==2) break;
      if(x%i==0){
	a=1;
	break;
      }
    }
    if(a==0){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
  
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

#define rep(i, n) FOR(i, 0, n)
#define FOR(i, x, n) for (int i = (x); i < (n); ++i)
#define all(v) (v).begin(), (v).end()

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

int main() {
    ll n;
    cin >> n;
    string s;
    while (n > 0) {
        n--;
        s += (n % 26) + 'a';
        n /= 26;
    }
    reverse(all(s));
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>

using namespace std;

int main(){
    int arr[3] = {0};
    cin >> arr[0] >> arr[1] >> arr[2];
    sort(arr, arr + 3);
    int ans = 0;
    if(arr[0] % 2 == arr[1] % 2){
        ans += (arr[1] - arr[0]) / 2;
        ans += (arr[2] - arr[1]);
        cout << ans;
    }else{
        if(arr[0] % 2 == arr[2] % 2){
            arr[0]++;
            arr[2]++;
            cout << 1 + (arr[2] - arr[1]) / 2 + (arr[2] - arr[0]) / 2;
        }else{
            arr[1]++;
            arr[2]++;
            cout << 1 +(arr[2] - arr[1]) / 2 + (arr[2] - arr[0]) / 2;;
        }
    }

    return 0;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int divCount=0;
		int matchCnt=0;

		for (int i = 1; i <= N; i += 2) {
			divCount=0;
			for (int j = 1; j <= i; j += 2) {
              if(i%j==0){
            	  divCount++;
              }
			}
			if(divCount==8){
				matchCnt++;
			}
		}
		
		System.out.println(matchCnt);
	}
}

Measured memory_bytes: 21844
#include <iostream>


using namespace std;

int main() 
{
  int H1,M1,H2,M2,K;
  cin >> H1;
  cin >> M1;
  cin >> H2;
  cin >> M2;
  cin >> K;

  //時を計算して分に換算
  int AnsH = (H2-H1)*60;

  //分を計算
  int AnsM = M2-M1-K;

  //分の合計値を以て答えとする
  int ans = AnsH + AnsM;

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
/*
 * A.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100;
const int MAX_P = 5;
const string ans[] = { "Isono-kun", "Nakajima-kun", "Hikiwake-kun" };

enum { H_DEF, H_STO, H_ATT };

/* typedef */

/* global variables */

int hs[2][MAX_N], pws[2];

/* subroutines */

inline int s2h(string &s) {
  if (s == "mamoru") return H_DEF;
  if (s == "tameru") return H_STO;
  return H_ATT;
}

/* main */

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < 2; i++)
    for (int j = 0; j < n; j++) {
      string s;
      cin >> s;
      hs[i][j] = s2h(s);
    }

  int win = 2;
  for (int i = 0; i < n; i++) {
    //printf("%d: %d(%d) - %d(%d)\n", i, hs[0][i], pws[0], hs[1][i], pws[1]);

    int atc[2], def[2];
    for (int j = 0; j < 2; j++)
      switch (hs[j][i]) {
      case H_ATT:
	if (pws[j] == 0) atc[j] = def[j] = -1;
	else atc[j] = pws[j], def[j] = 0;
	pws[j] = 0;
	break;
      case H_STO:
	atc[j] = def[j] = 0;
	if (pws[j] < MAX_P) pws[j]++;
	break;
      case H_DEF:
	atc[j] = 0, def[j] = MAX_P - 1;
	break;
      }

    if (atc[0] > def[1] && atc[1] > def[0]) {
      if (atc[0] > atc[1]) { win = 0; break; }
      if (atc[1] > atc[0]) { win = 1; break; }
    }
    else {
      if (atc[0] > def[1]) { win = 0; break; }
      if (atc[1] > def[0]) { win = 1; break; }
    }
  }

  cout << ans[win] << endl;
  return 0;
}

Measured memory_bytes: 1212
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n, x = LI()
m = [I() for _ in range(n)]
m.sort()
ans = n
x -= sum(m)
ans += x // m[0]
print(ans)

Measured memory_bytes: 38384
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc;
	static PrintWriter out;
	public static void main(String[] args){
		sc = new FastScanner();
		out = new PrintWriter(System.out);
//		solve();
		out.println(solve());
		out.flush();
	}

	static int solve(){
		int N = sc.nextInt();
		int T = sc.nextInt();
		int A = sc.nextInt();
		double min = Integer.MAX_VALUE;
		double tmp = 0;
		int idx = 0;
		for(int i=1;i<=N;i++){
			tmp = Math.abs(A- (T - sc.nextInt() * 0.006));
			if(tmp < min){
				idx = i;
				min = tmp;
			}
		}
		return idx;
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22484
// #include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    long n;
    cin >> n;
    char s[n];
    cin >> s;
    // scanf("%s", &s);
    long right_e = 0;
    for (long i = 1; i < n; i++) right_e += (s[i] == 'E');
    long min_count = right_e;
    // long left_w = 0;
    for (long i = 1; i < n; i++) {
        if (!min_count) break;
        right_e -= s[i] == 'E';
        right_e += s[i - 1] == 'W';
        min_count = min(min_count, right_e);
    }
    // cout << min_count << endl;
    cout << min_count << '\n';

    return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;

int n;
int p[50];
int check(int *p,int n){
    bool ans = true;
    for(int i=0;i<(n-1);i++){
        if(p[i] > p[i+1]){
            ans = false;
        }
    }
    return ans;
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> p[i];
    }    
    bool ans = false;
    if(check(p,n)){
        ans = true;
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            int tmp;
            tmp = p[i];
            p[i] = p[j];
            p[j] = tmp;
            if(check(p,n)){
                ans = true;
            }
            p[j] = p[i];
            p[i] = tmp;
        }
    }
    if(ans){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>

using namespace std;

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF		(1000000)
#define Rep(i,n) for(int i = 0; i < (n); i++ )

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define	show(x)	 copy( (x).begin(), (x).end(), ostream_iterator<int>(cout, ",") );	// container<int>を全て表示

using namespace std;

typedef long long ll;

//constant
//--------------------------------------------
const double EPS = 1e-10;
//const double PI  = acos(-1.0);

ll kaijo( ll N )
{
	// 階乗
	if( N == 0 ) return 1;
	return N * kaijo(N - 1);
}

map<ll, ll> prime_factor(ll N)
{
	// 素因数分解
	map<ll, ll> ret;
	for( ll i = 2; i * i <= N; i++ ){
		while( N % i == 0 ){
			ret[i]++;
			N /= i;
		}
	}
	if(N != 1) ret[N] = 1;
	return ret;
}

ll gcd( ll a, ll b )
{
	// a >= b
	if( b > a ) swap(a, b);
	if( b == 0 ) return a;
	return gcd( a % b, b );
}

ll lcm( ll a, ll b )
{
	return a * b / gcd(a, b);
}

ll max( ll a, ll b )
{
	if( a > b ) return a;
	return b;
}
ll min( ll a, ll b )
{
	if( a > b ) return b;
	return a;
}

class UnionFind
{
public:
	vector<int> parent;
	vector<int> rank;

	UnionFind(int n)
	{
		Rep(i, n){
			parent.push_back(i);
			rank.push_back(1);
		}
	}
	int root(int x)
	{
		if( parent[x] != x ) parent[x] = root(parent[x]);
		return parent[x];
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if( rx == ry ) return;
		if( rank[rx] > rank[ry] ){
			parent[ry] = rx;
			rank[rx] += rank[ry];
		}
		if( rank[rx] <= rank[ry] ){
			parent[rx] = ry;
			rank[ry] += rank[rx];
		}
	}
};

int main()
{
	ll N = 0;
	ll ans = 0;
	string S = "";

	cin >> N >> S;

	ll index = 0;
	ll tmp = 0;
	ll max_val = -10000000;
	Rep(i, N){
		if(S[i] == 'E'){
			tmp++;
		}
		else{
			tmp--;
		}

		if(max_val < tmp){
			max_val = tmp;
			index = i;
		}
	}
	Rep(i, N){
		if(i == index) continue;
		char dir = S[index];

		if(i < index){
			// left side
			if(dir == 'W' && S[i] == 'W') ans++;
			else if(dir == 'E' && S[i] == 'W') ans++;
		}
		else{
			// right side
			if(dir == 'W' && S[i] == 'E') ans++;
			else if(dir == 'E' && S[i] == 'E') ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 900
import math
a,b,h,m = map(int , input().split())
long_needle =(5 * m)/60 + h * 5  
sort_needle = m
ans = math.sqrt(a**2 + b **2 - 2*a*b*math.cos(abs(math.pi*(long_needle-sort_needle))/30))
print(ans)


Measured memory_bytes: 9412
#! python3
# simple_calculator.py

operations  = {'+': lambda a, b: a+b,
               '-': lambda a, b: a-b,
               '*': lambda a, b: a*b,
               '/': lambda a, b: int(a/b)}

while True:
    a, op, b = input().split(' ')
    if op == '?': break
    print(operations[op](int(a), int(b)))


Measured memory_bytes: 5600
#include <iostream>
#include <list>

using namespace std;

int main(int argc, char *argv[]) {
	int N, H;
	cin >> N >> H;

	long amax = 0;
	list<long> b;
	for (int i = 0; i < N; i++) {
		long ai, bi;
		cin >> ai >> bi;
		b.push_back(bi);
		if (amax < ai) amax = ai;
	}

	b.sort(greater<long>());

	int atk = 0;
	for (long bi : b) {
		if (bi < amax) break;
		if (H <= 0) break;
		H -= bi;
		atk++;
	}

	if (H > 0)
		atk += (H + amax - 1) / amax;

	cout << atk << endl;

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=INF,ans=1,aa[220000],o=0;
pair<int,int> pp[220000];
string s,ss[220000];
char ch[220000];
float fl[220000],fcnt=2;
queue<int> que;
signed main(){
    cin>>n>>m;
    if(m-n>=2019){
        cout<<0<<endl;
    }else{
        for(int i=n;i<m;i++){
            for(int j=i+1;j<m+1;j++){
                cnt=min(cnt,(i*j)%2019);
            }
        }
        cout<<cnt<<endl;
    }
}

Measured memory_bytes: 10444
# abc118 B
n, m = gets.split.map(&:to_i)

x = Array.new(m, 0)

n.times do
  _, *aa = gets.split.map(&:to_i)
  aa.each do |a|
    x[a-1] += 1
  end
end

p x.count{|xx|xx == n}


Measured memory_bytes: 1788
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  string s,t;
  cin>>s>>t;
  cout<<t<<s<<endl;


}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] W = new int[N];
		int s1=0;
		int s2=0;
		int sum=0;
		int min=101;
		int k=0;
		
		for(int i=0;i<N;i++) {
			W[i]=sc.nextInt();
			sum+=W[i];
		}
		
		int j=0;
		
		for(int i=0;i<N;i++) {
			k+=W[i];
			j=sum-k;
			if(Math.abs(j-k)<min) {
				min=Math.abs(j-k);
			}
		}
		
		System.out.println(min);
		sc.close();
	}
}


Measured memory_bytes: 22996
/* “Whether you think you can or you think you can’t, you’re right” - Henry Ford */

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define pb push_back
#define pl pair<ll, ll>
#define vl vector<ll>
#define vi vector<int>
#define endl '\n'

template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

void solve() {
    ll n; cin >> n;
    vl v(n); cin >> v;
    vl suf(n + 2, 0);
    for(int i = n - 1; ~i; i--) {
        suf[i + 1] = (suf[i + 2] + v[i]) % mod;
    }
    ll ans = 0;
    for(int i = 0; i < n - 1; i++) {
        (ans += v[i] * suf[i + 2]) %= mod;
    }
    cout << ans << endl;
}

int main()
{
    fast;
    ll t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 6360
n,w = map(int,input().split())
import collections
dic = collections.defaultdict(list)
w_min = float('inf')
for _ in range(n):
    a,b = map(int,input().split())
    dic[a].append(b)
    dic[a].sort(reverse = True)
    w_min = min(w_min,a)

sum_dic = collections.defaultdict(list)
for key,li in dic.items():
    if len(sum_dic[key])==0:
        sum_dic[key].append(0)
    for l in li:
        sum_dic[key].append(sum_dic[key][-1] + l)
ans = 0

for i in range(4):
    if len(sum_dic[w_min+i])==0:
        sum_dic[w_min+i].append(0)

for i,v1 in enumerate(sum_dic[w_min]):
        for j,v2 in enumerate(sum_dic[w_min+1]):
            for k,v3 in enumerate(sum_dic[w_min+2]):
                for l,v4 in enumerate(sum_dic[w_min+3]):
                    if (i+j+k+l)*w_min + j+2*k+3*l<=w:
                        ans = max(ans,v1+v2+v3+v4)
print(ans)

Measured memory_bytes: 73792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}

ll h, w, k;


int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin>>h>>w>>k;

    vector<string> s(h);

    for (int i = 0; i < h; i++){
        cin>>s[i];
    }

    int ans = INT_MAX;
    for (int i = 0; i < 1<<(h-1); i++){
        int set = 0, bit = i, cuts = 0;
        while (bit){
            set+=bit&1;
            bit>>=1;
        }
        cuts += set;

        int ok = 1;
        for (int j = 0; j < w; j++){
            vector<int> cur(set+1,0);
            int blk = 0;
            for (int l = 0; l < h; l++){
                cur[blk] += (s[l][j]=='1');
                if ((i>>l)&1){
                    blk++;
                }
            }
            for (int l = 0; l <= set; l++){
                if (cur[l] > k){
                    ok = 0;
                }
            }
            if (!ok) break;
        }
        if (!ok) continue;

        vector<int> sums(set+1,0);
        for (int j = 0; j < w; j++){
            vector<int> cur(set+1,0);
            int blk = 0;
            for (int l = 0; l < h; l++){
                cur[blk] += (s[l][j]=='1');
                if ((i>>l)&1){
                    blk++;
                }
            }
            int cut = 0;
            for (int l = 0; l <= set; l++){
                if (sums[l] + cur[l] > k){
                    cut++;
                }
            }
            if (cut){
                sums = cur;
                cuts++;
            }
            else{
                for (int l = 0; l <= set; l++){
                    sums[l] += cur[l];
                }
            }
        }
        ans = min(ans, cuts);
    }


    cout<<ans<<"\n";

    return 0;
    
}



Measured memory_bytes: 256