akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

/**
 *
 * @author HP
 */
public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n  = s.nextInt();
        int m  = s.nextInt();
        int limit = s.nextInt();

        int a[] = new int[n];
        long sumA[] = new long[n+1];
        int b[] = new int[m];
        long sumB[] = new long[m+1];

        for(int i = 1; i <= n; ++i) {
            a[i-1] =  s.nextInt();
            sumA[i] = sumA[i-1] + a[i-1];
//            System.out.println(sumA[i]);
        }

        for(int i = 1; i <= m; ++i) {
            b[i-1] =  s.nextInt();
            sumB[i] = sumB[i-1] + b[i-1];
//            System.out.println(sumB[i]);
        }

        int j = m;
        int ans = 0;
        for(int i = 0; i <= n; i++) {
            if(sumA[i] > limit) {
                break;
            }
            while(limit - sumA[i] < sumB[j]) {
                j--;
            }
            ans = Math.max(ans,i+j);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 65852
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int dp[100001];
ll n, a[1000], k;

void solve(ll x)
{
    // cout << x;
    ll f=0;
    if (dp[x]!=-1)
    {
        return;
    }
    for (int i = 0; i < n; ++i)
    {
        if (x>=a[i])
        {
            f=1;
            solve(x-a[i]);
            if (dp[x-a[i]]==0)
            {
                dp[x]=1;
                return;
            }
        }
    }
        dp[x]=0;
    


}

int main()
{

    cin >> n>> k;
    for (int i = 0; i < 100001; ++i)
    {
        dp[i]=-1; 
    }
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    solve(k);
    if (dp[k]==1)
    {
        cout << "First\n";
    }
    else
    {
        cout << "Second\n";
    }
}

Measured memory_bytes: 3712
/*input
10 10
158260522 877914575 602436426 24979445 861648772 623690081 433933447 476190629 262703497 211047202
*/
 
 
 
#include <bits/stdc++.h>
using namespace std;
 
 
 
#define int long long int
#define rep(i,n) \
    for(int i = 0; i < n; i++)
#define rep2(i, a, b) \
    for(int i = a; i < b; i++)
#define all(c) \
    c.begin(), c.end()
#define init(arr, num) \
    memset(arr, num, sizeof(arr))
#define fast\
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inputFile \
    freopen("input.txt", "r", stdin); 
#define outputFile \
    freopen("output.txt", "w", stdout);
#define modM 1000000007
#define PI 3.1415926535897932
#define F first
#define S second  
#define pb push_back  
#define INF 3e18
#ifdef gaviria
#define TRACE
#endif
#ifdef TRACE
#define trace(...) _f(#VA_ARGS, __VA_ARGS_)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cout << name << " : " << arg1 << std::endl;
 
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}
#else
#define trace(...)
#endif
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< ll, ll > ii;
typedef unordered_set<int> usi;
 
 
 
ll n,i,j,k,m,c;
vector<int> a;
int check(int mid)
{
    int m=0;
    

    for(auto g:a)
    {
        m+= (g/mid);
        if(g%mid==0)
            m--;
    }
    if(m<=k)
        return 1;
    else return 0;

}

void solve()
{


cin>>n>>k;


int high=0;
rep(i,n)
{
    cin>>j;
    high=max(high,j);
    a.push_back(j);
}
int ans=high;
int l=1;
int mid=0;
while(l<=high)
{
    mid=(l+high)>>1;

    if(check(mid))
    {ans=mid;
        high=mid-1;
    }
    else l=mid+1;


}

cout<<ans;

}
 
 
 
 
 
signed main()
{// inputFile;


    fast;
    int T = 1;
    // cin >> T;
    ll h=T;
    while(T--){
 
        solve();
        cout<<endl;
 
     
        
        
 
    }
    
    
    return 0;
 
}

Measured memory_bytes: 5308
#include <bits/stdc++.h>
#include <algorithm>
#include<string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B;
    cin >> A >> B;
    if (A + B == 24) {
        cout << 0 << endl;
    } else if (A + B > 24) {
        cout << ((A + B) - 24) << endl;
    } else {
        cout << A + B << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0

for i in range(n):
    s = input()
    if s == 'AC':
        ac += 1
    elif s == 'WA':
        wa += 1
    elif s == 'TLE':
        tle += 1
    else:
        re += 1

print('AC x ' + str(ac))
print('WA x ' + str(wa))
print('TLE x ' + str(tle))
print('RE x ' + str(re))


Measured memory_bytes: 9192
#include <stdio.h>

int main(void) {
	int n;
	int ans;

	scanf("%d", &n);

	ans = 0;
	while (n > 1) {
		ans++;
		n = (n - 1) / 3 + 1;
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Washoum
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        inputClass in = new inputClass(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DFlippingSigns solver = new DFlippingSigns();
        solver.solve(1, in, out);
        out.close();
    }

    static class DFlippingSigns {
        public void solve(int testNumber, inputClass sc, PrintWriter out) {
            int n = sc.nextInt();
            long sum = 0;
            int nb = 0;
            int[] tab = new int[n];
            for (int i = 0; i < n; i++) {
                tab[i] = sc.nextInt();
                sum += Math.abs(tab[i]);
                if (tab[i] <= 0) {
                    nb++;
                }
            }
            if (nb % 2 == 0) {
                out.println(sum);
            } else {
                int min = Integer.MAX_VALUE;
                for (int i = 0; i < n; i++) {
                    min = Math.min(min, Math.abs(tab[i]));
                }
                out.println(sum - 2 * min);
            }
        }

    }

    static class inputClass {
        BufferedReader br;
        StringTokenizer st;

        public inputClass(InputStream in) {

            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 42724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    string a, b, c; cin >> a >> b >> c;
    char turn = 'a';
    int i_a=0, i_b=0, i_c=0;
    while (1) {
        if (turn == 'a') {
            if (i_a == a.size()) {
                puts("A");
                return 0;
            }
            turn = a.at(i_a);i_a++;
        }
        else if (turn == 'b') {
            if (i_b == b.size()) {
                puts("B");
                return 0;
            }
            turn = b.at(i_b); i_b++;
        }
        else { // c
            if (i_c == c.size()) {
                puts("C");
                return 0;
            }
            turn = c.at(i_c); i_c++;
        }
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

signed main() {
	int x, y; cin >> x >> y;
	int ans = 0;
	if (x == 3) ans += 100000;
	else if (x == 2) ans += 200000;
	else if (x == 1) ans += 300000;
	if (y == 3) ans += 100000;
	else if (y == 2) ans += 200000;
	else if (y == 1) ans += 300000;
	if (x == 1 && y == 1) ans += 400000;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
using ll = long long;
const char newl = '\n';
#define var auto

vector< ll > xs, ys, rs, cs;
int dp[1 << 24];

bool is_top(int k, int bit) {
  auto pow2 = [](ll a) {
    return a * a;
  };
  for (int i = 0; i < k; i += 1) {
    if (bit & (1 << i)) continue;
    if (pow2(rs[i] + rs[k]) > pow2(xs[i] - xs[k]) + pow2(ys[i] - ys[k])) {
      return false;
    }
  }

  return true;
}

int dfs(int n, int bit) {
  int &res = dp[bit];

  if (~res) return res;
  res = 0;

  for (int i = 0; i < n; i += 1) {
    if (bit & (1 << i)) continue;
    if (!is_top(i, bit)) continue;

    for (int j = 0; j < i; j += 1) {
      if (bit & (1 << j)) continue;
      if (!is_top(j, bit)) continue;
      if (cs[i] != cs[j]) continue;

      chmax(res, dfs(n, bit | (1 << i) | (1 << j)) + 2);
    }
  }

  return res;
}

void solver(int n) {
  xs = ys = rs = cs = vector< ll >(n);

  for (int i = 0; i < n; i += 1) {
    cin >> xs[i] >> ys[i] >> rs[i] >> cs[i];
  }

  memset(dp, -1, sizeof(dp));
  cout << dfs(n, 0) << endl;
}

signed main(){
  int n;
  
  while (cin >> n, n) {
    solver(n);
  }
}



Measured memory_bytes: 68704
n, m = map(int, input().split())

l = [list(map(int, input().split())) for _ in range(n)]
l.sort(key= lambda x: x[0])

c = 0
ans = 0
for a, b in l:
  if m-c <= b:
    ans += a * (m-c)
    break
  else:
    c += b
    ans += a * b

print(ans)

Measured memory_bytes: 29024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>  
#include<cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<climits>
#include<typeinfo>
#include<utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10);


int main() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int ta, tb;


	if (c%b == 0)ta = c / b;
	else ta = c / b + 1;

	if (a%d == 0)tb = a / d;
	else tb = a / d + 1;

	if (ta <= tb)cout << "Yes" << endl;
	else cout << "No" << endl;





	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://beta.atcoder.jp/contests/abc097/tasks/abc097_b

int main() {
    int X; cin >> X;
    vector<int> expo(X+5);
    expo[1] = 1;

    for (int b = 2; b <= X; b++) {
        int v = b * b;
        while(v <= X) {
            expo[v] = 1;
            v *= b;
        }
    }

    for (int i = X; i > 0; i--) if (expo[i]){
            cout << i << "\n";
            return 0;
    }

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef ONLINE_JUDGE
#define trace(...)
#endif

using LL = long long;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int a, b; cin >> a >> b;
	int k = a + b;
	if (k & 1) {
		cout << "IMPOSSIBLE\n";
	} else {
		cout << (k >> 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define llong long long
#define mp make_pair
#define f first
#define s second

using namespace::std;

int main()
{
    ios::sync_with_stdio(false);
    ifstream fin("input.txt");
    llong a, b, c, d, N, a1, b1, c1, d1;
    cin >> a >> b >> c >> d >> N;
    llong answ = 0;
    a1 = 8 * a;
    b1 = 4 * b;
    c1 = 2 * c;
    d1 = d;
    int min_ = min(min(min(a1, b1), c1), d1);
    answ = min_ * (N / 2);
    if (N % 2 == 1) {
        answ += min(min(a1, b1), c1) / 2;
    }
    cout << answ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int a, b, c, cnt = 0;
    cin >> a >> b >> c;
    if (a==b) cnt++;
    if (b==c) cnt++;
    if (c==a) cnt++;
    if (cnt == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    char a[100050];
    int b[100050];
    memset(b,0,sizeof(b));
    int k=0;
    int n,m;
    scanf("%d%d",&n,&m);
    scanf("%s",a);

    int ci=0;
    int x,y;
    int i,j;

    for(i=0;i<n;i++)
    {
        if(a[i]=='A'&&i+1<n)
            if(a[i+1]=='C')
            ci++;b[i]=ci;
    }


    for(i=0;i<m;i++)
    {
        scanf("%d%d",&x,&y);
        ci=b[y-1]-b[x-1];
        if(a[y-1]=='A')
        if(y<n&&a[y]=='C')
            ci--;
        if(a[x-1]=='A')
        if(x<n&&a[x]=='C')
            ci++;
        printf("%d\n",ci);
    }
    return 0;
}

Measured memory_bytes: 1280
k,n = gets.chomp.split(' ').map(&:to_i)
a = gets.chomp.split(' ').map(&:to_i)
s = []

(1..(n-1)).each do |i|
     s.push(a[i]-a[i-1])
end

s.push(k+a[0]-a[n-1])
l = s.max
puts k-l
 

Measured memory_bytes: 18364
#include<stdio.h>
int main()
{
	int a[100][100];
	int b[100];
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	} 
	for(int i = 0;i<m;i++)                                                                               
	{
		scanf("%d",&b[i]);
	}
	int c[100]={0};
	for(int i = 0;i<n;i++)
	{
		for(int j = 0;j<m;j++)
		{
			c[i]+=a[i][j]*b[j];
		}
	}
	for(int i = 0;i<n;i++)
	{
		printf("%d\n",c[i]);
	}
	return 0;
	
} 


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

int main() {
    int n;
    cin >> n;
    vector<int64_t> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    vector<int> toNextMin(n, n + 10);
    bool existsOne = true;
    while (existsOne) {
        existsOne = false;
        int cur = 1;
        for (int i = n - 1; i >= 0; i--) {
            if (A[i] & 1 == 1) {
                toNextMin[i] = min(toNextMin[i], cur);
                cur = 1;
            } else {
                cur++;
            }
            A[i] >>= 1;
            existsOne = existsOne || A[i] > 0;
        }
    }
    int64_t ans = 0;
    int cur = 0;
    for (int i = n - 1; i >= 0; i--) {
        cur = min(cur + 1, toNextMin[i]);
        ans += cur;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int popcount(T n) { return n ? 1 + popcount(n & (n - 1)) : 0; }
#endif
#ifdef __GNUC__
template <class T> int popcount(T n);
template <> int popcount(unsigned int n) { return n ? __builtin_popcount(n) : 0; }
template <> int popcount(int n) { return n ? __builtin_popcount(n) : 0; }
template <> int popcount(unsigned long long n) { return n ? __builtin_popcountll(n) : 0; }
template <> int popcount(long long n) { return n ? __builtin_popcountll(n) : 0; }
#endif

#define rep (i, n) for (int i = 0; i < (int)n; ++i)
#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CL(arr, val) memset(arr, val, sizeof(arr))


template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };
bool valid_pos(int x, int y, int w, int h) { return 0 <= x && x < w && 0 <= y && y < h; }

template <class T> void print(T a, int n, int br = 1, const string& deli = ", ") { cout << "{ "; for (int i = 0; i < n; ++i) { cout << a[i]; if (i + 1 != n) cout << deli; } cout << " }"; while (br--) cout << endl; }
template <class T> void print(const vector<T>& v, int br = 1, const string& deli = ", ") { print(v, v.size(), br, deli); }


int main()
{
    ll a, b;
    cin >> a >> b;
    ll low = max(2LL, a - b), upper = a + b;

    static bool is_prime[1000100];
    static int prev_e[1000100];
    for (ll i = 2; i * i <= upper; ++i)
        is_prime[i] = true;
    for (int i = 0; i <= 2 * b; ++i)
        prev_e[i] = 1000000;

    for (ll i = 2; i * i <= upper; ++i)
    {
        if (is_prime[i])
        {
            for (ll j = 2 * i; j * j <= upper; j += i)
                is_prime[j] = false;

            for (ll j = (low + i - 1) / i * i; j <= upper; j += i)
            {
                if (prev_e[j - low] == -1)
                    continue;

                int e = 0;
                for (ll num = j; num % i == 0; num /= i)
                    ++e;

                if (e > prev_e[j - low])
                    prev_e[j - low] = -1;
                else
                    prev_e[j - low] = e;
            }
        }
    }

    int res = 0;
    for (ll i = low; i <= upper; ++i)
        if (prev_e[i - low] >= 1)
            ++res;

    cout << res << endl;
}

Measured memory_bytes: 5712
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define print(n) cout<<n<<endl
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
const int M=200111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};


struct UnionFind {
	vector<int> par;
	UnionFind(int n) : par(n, -1) { }

	int root(int x) {
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y); // merge technique
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x) {
		return -par[root(x)];
	}
};

vvl comb(int n, int r) {
	vvl v(n + 1,vl(n + 1, 0));
	for (int i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int j = 1; j < v.size(); j++) {
		for (int k = 1; k < j; k++) {
			v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
		}
	}
	return v;
}

void sosu(ll x,bool f[]){
	ll y=x;
	for(ll i=2;i<=sqrt(y);i++){
		if(x%i==0){
			x/=i;
			f[i]=true;
			i--;
		}
	}
}

ll __gcd(ll x,ll y){
	if(x<y)swap(x,y);
	while(1){
		ll tmp=x%y;
		x=y;
		y=tmp;
		if(y==0)break;
	}
	return x;
}

int keta(ll a){
	int ke=1;
	while(a/=10)ke++;
	return ke;
}

int main(){
	ll h,ans=0;
	cin>>h;
	ll sum=0;
	while(h>0){
		h/=2;
		sum++;
	}
	rep(i,0,sum)ans+=(ll)pow(2,i);
	print(ans);



}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
using pi=pair<int,int>;
signed main(){
  int a,b,c,x,r=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;++i)for(int j=0;j<=b;++j)for(int k=0;k<=c;++k)if(500*i+100*j+50*k==x)++r;
  cout<<r;
}


Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
X=[0]*(N+1)
for i,a in enumerate(A):
    X[i+1]=X[i]+a
l,r=0,X[-1]
for x in X:
    if x>=X[-1]//2:
        r=x
        break
    l=x
print(min(X[-1]-2*l,2*r-X[-1]))

Measured memory_bytes: 26220
#include<stdio.h>
int main(void)
{
	int n;
	scanf("%d", &n);

	char s[100], t[100];

	scanf("%s %s", &s, &t);
	int i;
	for (i = 0; i < n; i++)
		printf("%c%c", s[i], t[i]);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;

int n, k;

signed main() {
  // freopen("in", "r", stdin);
  while(~scanf("%d%d",&n,&k)) {
    if(n % k == 0) printf("0\n");
    else printf("1\n");
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll x,a=100;
    int year=0;
    cin>>x;
    while(a<x)
    {
        a=(double)(a*1.01);
        year++;
    }
    cout<<year<<endl;
    return 0;
}


Measured memory_bytes: 3624
# coding:utf-8

import sys

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N, W = LI()
L = [LI() for _ in range(N)]
V = 0
for i in range(N): V += L[i][1]

# dp[v]: 価値vを詰め込んだナップザックの重量の最小値
dp = [INF] * (V + 1)
dp[0] = 0
for weight, value in L:
    for v in range(V + 1)[::-1]:
        if v - value < 0:
            continue
        dp[v] = min(dp[v], dp[v - value] + weight)

for i in range(V + 1)[::-1]:
    if dp[i] != INF and dp[i] <= W:
        print(i)
        exit()


Measured memory_bytes: 94164
#include<iostream>

using namespace std;

int main(void){
  int a[10],b[3]={0}, c, d, i;
  for(i = 0;i<10;i++){
    cin >> a[i];
  }
  i=0;
  for(c=0;c<3;c++){
  for(i=0;i<10;i++){
    if(a[i] > b[c]){
      b[c] = a[i];
      d=i;
    }
  }
  a[d] = 0;
  }
  i=0;
  for(i=0;i<3;i++) cout << b[i] << endl;
}

Measured memory_bytes: 3056
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == '1') cout << 9 ;
    else cout << 1;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int ans = -1;
  if(a < 10 && b < 10){
    ans = a * b;
  }
  
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int D;
int main(){
	scanf("%d",&D);
	if(D == 22) puts("Christmas Eve Eve Eve");
	else if(D == 23) puts("Christmas Eve Eve");
	else if(D == 24) puts("Christmas Eve");
	else puts("Christmas");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define loop(i,n) rep(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> p(n+1,k-q);
    loop(i,q){
        int a;
        cin >> a;
        ++p[a];
    }
    rep(i,1,1+n){
        cout << ((p[i]>0)?"Yes":"No") << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;

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

    int A, B, C, D;
    string s;
    cin>>s;
    char c[] = {s[0], '\0'};
    A = atoi(c);
    c[0] = s[1];
    B = atoi(c);
    c[0] = s[2];
    C = atoi(c);
    c[0] = s[3];
    D = atoi(c);

    char n = 0;
    while (n <= 0b111) {
        int ans = A;
        ans += (n & 1<<2) ? B : -B;
        ans += (n & 1<<1) ? C : -C;
        ans += (n & 1<<0) ? D : -D;
        if (ans == 7) {
            cout<<A<<((n & 1<<2) ? '+' : '-')<<B<<((n & 1<<1) ? '+' : '-')<<C<<((n & 1) ? '+' : '-')<<D<<"=7"<<endl;
            break;
        }
        n++;
    }
    return 0;
}

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

int main()
{
	double x;
	
	while(scanf("%lf", &x) != EOF){
		x = x / 9.8;
		x = x * x * 4.9;
		int i;
		for(i = 1; i * 5 - 5 < x; i++);
		cout << i << endl;
	}
	return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

string solve(string s){
	vector<int> a;
	vector<int> b;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'a'){
			a.push_back(i);
		} else {
			b.push_back(i);
		}
	}
	string dp[s.size() + 1];
	for(int j = a.size() - 1; j >= 0; j--){
		int ok = 0;
		for(int i = j; i < a.size(); i++){
			if(b[i] < a[i]) ok = 1;
		}
		if(!ok){
			dp[j] = "";
			int lastb = 0;
			for(int i = j; i < a.size(); i++){
				if(a[i] >= lastb){
					lastb = b[i];
					dp[j] += "ab";
				}
			}
		} else {
			int lasta = j;
			vector<pair<int, string> > z;
			string addon;
			for(int i = j; i < a.size(); i++){
				if(i == j || b[i] < lasta){
					if(b[i] < a[i]){
						lasta = a[i];
						z.push_back({a[i], "a"});
						z.push_back({b[i], "b"});
					}
				} else {
					addon = dp[i];
					break;
				}
			}
			string f;
			sort(z.begin(), z.end());
			for(int i = 0; i < z.size(); i++){
				f += z[i].second;
			}
			dp[j] = f + addon;
			if(dp[j+1] > dp[j]){
				dp[j] = dp[j+1];
			}
		}
	}
	return dp[0];
}
int main(){
	int n;
	string s;
	cin >> n >> s;
	cout << solve(s) << '\n';
}


Measured memory_bytes: 17300
#include<iostream>
#include<vector>
typedef long long ll;
using namespace std;
int main() {
	ll N;
	cin >> N;
	vector<ll>a(N);
	for (ll i = 0; i < N; i++) {
		cin >> a[i];
	}
	ll dp[10001];
	for (ll i = 0; i <=10000; i++) {
		dp[i] = 0;
	}
  	dp[0]=1;
	for (ll i = 0; i < N; i++) {
		for (ll j = 10000; j >= 0; j--) {
			if (dp[j]&&a[i] + j <= 10000)
              dp[j + a[i]] =1;
			}
    }
    ll x=0;
	for (ll i = 0; i <=10000; i++) {
		if (dp[i]&&i%10!=0)x=i;
    }
       cout<<x<<endl;
}













Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<vector>

//とちゅう

void print(std::vector<unsigned long long>m,int N,int W){
    for(int i=0;i<N;++i){
        for(int j=0;j<W;++j){
            std::cout<<m[i*W+j]<<",";
        }
        std::cout<<std::endl;
    }
}

int main(){
    int N,W;
    std::cin>>N>>W;
    std::vector<int>w(N);
    std::vector<unsigned long long>cost(N);
    w.shrink_to_fit();
    std::vector<unsigned long long>dp(N*(W+1),0);
    dp.shrink_to_fit();
    for(int i=0;i<N;++i){
        std::cin>>w[i]>>cost[i];
    }
    for(int i=0;i<(W+1);++i){
        if(w[0]<=i){
            dp[0*(W+1)+i]=cost[0];
        }else{
            dp[0*(W+1)+i]=0;
        }
    }
    // print(dp,N,W+1);

    for(int i=1;i<N;++i){
        for(int j=0;j<W+1;++j){
            if(j<w[i]){
                dp[i*(W+1)+j]=dp[(i-1)*(W+1)+j];
            }else{
                dp[i*(W+1)+j]=std::max(dp[(i-1)*(W+1)+j],dp[(i-1)*(W+1)+(j-w[i])]+cost[i]);
            }
        }
    }
    // print(dp,N,W+1);
    std::cout<<dp[N*(W+1)-1]<<std::endl;
}

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

using namespace std;

double solve(double a, double b, double h, double m)
{
    double res;
    double mrad = 2 * M_PI * (m / 60);
    double hrad = 2 * M_PI * (h / 12) + mrad / 12;
    double diff = abs(hrad - mrad);
    double drad = diff > M_PI ? 2 * M_PI - diff : diff;
    double s = 2 * a * b * cos(drad);
    res = sqrt(a*a + b*b - s);
    return res;
}

int main(void)
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    cout << setprecision(20) <<  solve(a, b, h, m) << endl;
}

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


def solve(H, W, K, C):
    from itertools import compress, product
    def f(hs, ws):
        k = 0
        for h in range(H):
            if h in hs:
                continue
            for w in range(W):
                if w in ws:
                    continue
                if C[h][w] == "#":
                    k += 1
        return k == K
    ans = 0
    for hs in (set(compress(range(H), p)) for p in product([True, False], repeat=H)):
        for ws in (set(compress(range(W), p)) for p in product([True, False], repeat=W)):
            if f(hs, ws):
                ans += 1
    return ans

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    H, W, K = map(int, input().split())
    C = [input() for _ in range(H)]
    print(solve(H, W, K, C))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 69124
#include<bits/stdc++.h>
using namespace std;
int n, a[114514];
int main(){
  cin >> n; for(int i=0;i<n;i++) cin >> a[i];
  sort(&a[0], &a[n]);
  int ok = 0, ng = n;
  while(ng-ok>1){
    int mid = (ok + ng) / 2;
    if (a[mid]*2 <= a[n-1]) ok = mid;
    else ng = mid;
  }
  int x = a[ok];
  if (ok+1<n && a[n-1]-a[ok]*2 > a[ok+1]*2-a[n-1]) x = a[ok+1];
  cout << a[n-1] << " " << x << endl;
}
    

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

const int MAX_P = 200000; //max
bool prime[MAX_P+1];

void Eratosthenes(void){
  for(int i=2;i<=MAX_P;i++)
    prime[i]=true;
  
  for(int i=2;i*i<=MAX_P;i++)
    if(prime[i])  
      for(int j=i;i*j<=MAX_P;j++)
	prime[i*j]=false;
}


bool calc(){
  int m,p;
  vector<int> vec;
  
  scanf("%d%d",&m,&p);
  if(m==-1) return false;
  
  for(int i=m+1;i<m+500;i++){
    for(int j=i;j<m+500;j++){
      if(prime[i] && prime[j])
      vec.push_back(i+j);
    }
  }

  sort(vec.begin(),vec.end());
  
  printf("%d\n",vec[p-1]);
  
  
  return true;
}
  
int main(){

  Eratosthenes();
  
  while(calc());
  
  return 0;
}

Measured memory_bytes: 3432
import heapq

def minus(x):
    y = int(x)
    return y*(-1)

N , K = map(int,input().split())
h_list = list(map(minus,input().split()))
ans = 0
heapq.heapify(h_list)

for i in range(N):
    if (heapq.heappop(h_list)*(-1) < K):
        break

    else:
        ans += 1


print(ans)

Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL N;
	cin >> N;
	VLL A(N);
	LL sum = 0;
	for (LL n = 0; n < N; n++) {
		cin >> A[n];
		sum += A[n];
	}
	LL ans = N - 1;
	for (LL n = N - 2; n >= 0; n--) {
		LL crit = abs(sum - A[ans] * N);
		LL comp = abs(sum - A[n] * N);
		if (crit >= comp)ans = n;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
string s;
bool A[200000];
int main()
{
    cin>>s;
    int x, y;
    x = y = 0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i] == '1')
            x++;
        else
            y++;
    }
    cout<<min(x,y)*2;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main() {
    int D, N; cin >> D >> N;
    int S = 1; for (int i = 0; i < D; i++) S *= 100;
    if (N <= 99) cout << S * N << endl;
    else cout << S * 101 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

#define rep(i,n) for(i=0;i<n;i++)
#define size 10000

int main(){
  int n,s[size],q,t[size];
  int i,j,k;
  int count=0;

  cin >> n;
  rep(i,n)
    cin >> s[i];
  cin >> q;
  rep(j,q)
    cin >> t[j];

  rep(j,q)
    rep(i,n)
      if(s[i]==t[j]){
	count++;
	break;
      }

  cout << count << endl;

  return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <cmath>
#include <algorithm>

using namespace std;

const int INF = 1e6;

int main(){
    int a, b, q;  cin >> a >> b >> q;
    vector<long long> s(a), t(b);
    for (int i=0; i<a; i++){
        cin >> s[i];
    }
    for (int i=0; i<b; i++){
        cin >> t[i];
    }
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());

    for (int i=0; i<q; i++){
        long long x;
        cin >> x;
        auto iter1 = lower_bound(s.begin(), s.end(), x);
        auto iter2 = lower_bound(t.begin(), t.end(), *iter1);
        auto iter3 = max(t.begin(), iter2-1);
        auto iter4 = max(s.begin(), iter1-1);
        auto iter5 = lower_bound(t.begin(), t.end(), *iter4);
        auto iter6 = max(t.begin(), iter5-1);
        long long ans = abs(*iter1-x)+abs(*iter2-*iter1);
        ans = min(ans, abs(*iter1-x)+abs(*iter3-*iter1));
        ans = min(ans, abs(*iter4-x)+abs(*iter5-*iter4));
        ans = min(ans, abs(*iter4-x)+abs(*iter6-*iter4));
        auto _iter1 = lower_bound(t.begin(), t.end(), x);
        auto _iter2 = lower_bound(s.begin(), s.end(), *_iter1);
        auto _iter3 = max(s.begin(), _iter2-1);
        auto _iter4 = max(t.begin(), _iter1-1);
        auto _iter5 = lower_bound(s.begin(), s.end(), *_iter4);
        auto _iter6 = max(s.begin(), _iter5-1);
        ans = min(ans, abs(*_iter1-x)+abs(*_iter2-*_iter1));
        ans = min(ans, abs(*_iter1-x)+abs(*_iter3-*_iter1));
        ans = min(ans, abs(*_iter4-x)+abs(*_iter5-*_iter4));
        ans = min(ans, abs(*_iter4-x)+abs(*_iter6-*_iter4));

        cout << ans << endl;
    }
}


Measured memory_bytes: 2944
from collections import deque
n=int(input())
G=[[]for i in range(n)]
U=[0]*(n-1)
V=[0]*(n-1)
A=[0]*(n-1)
D=[]
for i in range(n-1):
  U[i],V[i],w=map(int,input().split())
  U[i]=U[i]-1
  V[i]=V[i]-1
  A[i]=U[i]*10**5+V[i]
  w=w%2
  G[U[i]].append([V[i],w])
  G[V[i]].append([U[i],w])
  D.append([A[i],0])
C=[0]*n
VV=[0]*n
d=deque([0])
while len(d)>0:
  x=d[0]
  d.popleft()
  for i in range(len(G[x])):
    if VV[G[x][i][0]]==0:
      VV[G[x][i][0]]=1
      d.append(G[x][i][0])
      if G[x][i][1]==0:
        C[G[x][i][0]]=C[x]
      else:
        C[G[x][i][0]]=(C[x]+1)%2
for i in range(n):
  print(C[i])

Measured memory_bytes: 59348
# AGC028A - Two Abbreviations
from fractions import gcd


def main():
    n, m = tuple(map(int, input().rstrip().split()))
    S, T = tuple(input().rstrip() for _ in range(2))
    g = gcd(n, m)
    flg = S[:: n // g] == T[:: m // g]
    print(n // g * m if flg else -1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 5340
#include<iostream>
#include<cctype>
#include<string>
using namespace std;
typedef string::const_iterator State;

int number(State &begin);
int factor(State &begin);
int term(State &begin);
int expression(State &begin);

int expression(State &begin){
    int ret = term(begin);

    while(1){
        if(*begin == '+'){
            begin++;
            ret += term(begin);
        }else if(*begin == '-'){
            begin++;
            ret -= term(begin);
        }else{
            break;
        }
    }

    return ret;
}

int term(State &begin){
    int ret = factor(begin);

    while(1){
        if(*begin == '*'){
            begin++;
            ret *= factor(begin);
        }else if(*begin == '/'){
            begin++;
            ret /= factor(begin);
        }else{
            break;
        }
    }

    return ret;
}

int factor(State &begin){
    if(*begin == '('){
        begin++;    // (
        int ret = expression(begin);
        begin++;    // )
        return ret;
    }else{
        return number(begin);
    }
}

int number(State &begin){
    int ret = 0;

    while(isdigit(*begin)){
        ret = ret*10 + (*begin - '0');
        begin++;
    }

    return ret;
}

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

    for(int i = 0; i < n; i++){
        string s;
        getline(cin, s);

        State begin = s.begin();
        int ans = expression(begin);
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N,R,d;
    cin >> N >> R >> d;
    int ans = 0;
    for(int i = N; i<= R;++i){
      if (i % d == 0) ans+= 1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> G(H);
  for(int i=0; i<H; i++){
    cin >> G[i];
  }
  int ans = inf;
  for(int bit=0; bit<(1<<H-1); bit++){
    int cnt_H = __builtin_popcount(bit);
    vector<int> sum(cnt_H+1,0);
    int cnt_W = 0;
    bool can = true;
    for(int i=0; i<W; i++){
      int now = 0;
      vector<int> temp(cnt_H+1,0);
      for(int j=0; j<H; j++){
        if(G[j][i] == '1'){
          temp[now]++;
        }
        if(bit & (1<<j)){
          now++;
        }
      }
      for(int j=0; j<cnt_H+1; j++){
        if(temp[j] > K) can = false;
        if(sum[j]+temp[j] > K){
          cnt_W++;
          for(int k=0; k<cnt_H+1; k++){
            sum[k] = temp[k];
          }
          break;
        }else{
          sum[j] += temp[j];
        }
      }
    }
    if(can){
      // cout << bit << " " << cnt_W << endl;
      chmin(ans,cnt_W+cnt_H);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;
 
fn main() {
  input! {
    n: usize
  }
  
  let mut a = 1;
  let mut b = n;
  let mut min = usize::max_value();
  while a <= b {
    if n % a == 0 {
      min = std::cmp::min(min, (a - 1) + (n / a - 1));
    }
    a += 1;
    b = n / a;
  }
  
  println!("{}", min);
}

Measured memory_bytes: 2140
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)
//static const int INFTY = (1<<20);


//ABC152_c
int main() {
	int n;
	cin >> n;
	vector<int> vec(n);
	rep(i, n) {
		cin >> vec.at(i);
	}
	int ans = 1;
	int mn = vec.at(0);
	for (int i=1; i<n; i++) {
		mn = min(mn, vec.at(i-1));
		if (vec.at(i) <= mn) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <limits.h>
#define INF 0x10000000 

int n, distance[10][10], used[10], nodes;
int dijkstra(int start);

int main()
{
	int i, j, a, b, c, min, city;
	while(1) {
		/* reset the array */
		nodes = 0;
		for(i = 0; i < 10; i++) {
			for(j = 0; j < 10; j++) distance[i][j] = INF;
		}
		/* input */
		scanf("%d", &n);
		if(!n) break;
		for(i = 0; i < n; i++) {
			scanf("%d %d %d", &a, &b, &c);
			distance[a][b] = c;
			distance[b][a] = c;
			if(a + 1 > nodes) nodes = a + 1;
			if(b + 1 > nodes) nodes = b + 1;
		}
		/* Dijkstra */
		min = INF;
		for(i = 0; i < nodes; i++) {
			if(min > dijkstra(i)) {
				min = dijkstra(i);
				city = i;
			}
		}
		printf("%d %d\n", city, min);
	}
	return 0;
}

int dijkstra(int start)
{
	int time, d[10], u, i, j, min = 0;
	for(i = 0; i < 10; i++) {
		used[i] = 0;
		d[i] = INF;
	}
//	printf("start = %d\n", start);
	while(1) {
		d[start] = 0;
		u = -1;
		for(i = 0; i < nodes; i++) {
			if(!used[i] && (u == -1 || d[i] < d[u])) u = i;
		}
//		printf("u = %d\n", u);
		if(u == -1) break;
		used[u] = 1;
		for(i = 0; i < nodes; i++) {
			if(d[i] > d[u] + distance[u][i]) d[i] = d[u] + distance[u][i];
		}
	}
//	for(i = 0; i < nodes; i++) 	printf("d[%d] = %d\n", i, d[i]);
	for(i = 0; i < nodes; i++) {
		min += d[i];
	}
	return min;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
ll gcd(ll a, ll b);
int main(){
cin.tie(0);
string k;
int n,result[4]={0,0,0,0};
  cin >>n;
  for(int i=1;i<=n;i++){
    cin >>k;
    if(k=="AC")result[0]++;
    else if(k=="WA")result[1]++;
    else if(k=="TLE")result[2]++;
    else if(k=="RE")result[3]++;
  }
cout <<"AC x "<<result[0]<<endl;
  cout <<"WA x "<<result[1]<<endl;
  cout <<"TLE x "<<result[2]<<endl;
  cout <<"RE x "<<result[3]<<endl;
return 0;
}






ll gcd(ll a, ll b){

   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }

}


Measured memory_bytes: 3596
#include <stdio.h>

int main() {
	char s[11];
	scanf("%s", s);

	if (s[0] == 'Y'&&s[1] == 'A'&&s[2] == 'K'&&s[3] == 'I') {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	string S; cin >> S;

	int ans = 0;
	REP(i,4) {
		if(S[i] == '+') ans++;
		else ans--;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;

void file(bool opt)
{
	if (opt&&fopen("in.txt", "r"))
	{
		freopen("in.txt", "r", stdin);
		//freopen("out.txt", "w", stdout);
	}
}

long long L, A, B;
long long mod;
long long ans = 0;
long long powt[19];
struct mat {
	int val[3][3];
	mat() { memset(val, 0, sizeof val); }
	void init(int i)
	{
		memset(val, 0, sizeof val);
		val[0][0] = powt[i] % mod, val[1][0] = val[1][1]= val[2][2] = 1;
		val[2][1]=B%mod;
	}
}a,res;

mat operator*(mat a, mat b)
{
	mat c;
	for (int i = 0; i<3; i++)
		for (int j = 0; j<3; j++)
			for (int k = 0; k<3; k++)
				c.val[i][j] = (c.val[i][j] + 1ll * a.val[i][k] * b.val[k][j]) % mod;
	return c;
}

void poww(long long L,long long R,int d)
{
	long long n = (R - L) / B + 1;
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < 3; j++)
			res.val[i][j] = (i == j);

	a.init(d);

	while (n)
	{
		if (n & 1)res = res * a;
		n >>= 1;
		a = a*a;
	}
	ans = (1ll * ans*res.val[0][0]%mod + L % mod*res.val[1][0] % mod + res.val[2][0]) % mod;
}

int main()
{
	cin >> L >> A >> B >> mod;
	powt[0] = 1;
	for (int i = 1; i <= 18; i++)
		powt[i] = powt[i - 1] * 10ll;

	long long ed = A + B * (L - 1);

	for (int d = 1; d <= 18; d++)
	{
		if (A < powt[d])
		{
			long long R = (powt[d] - 1 - A) / B * B + A;
			R = min(R, ed);
			poww(A, R, d);
			if (R == ed)break;
			A = R + B;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e1 + 5);

int n;
ll x[MAX_N], y[MAX_N];

map<pair<ll, ll>, int> cnt;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  if (n == 1) {
    printf("%d\n", 1);
    return 0;
  }

  for (int i = 0; i < n; ++i) {
    scanf("%lld %lld", &(x[i]), &(y[i]));
  }

  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ll diff_x = x[i] - x[j];
      ll diff_y = y[i] - y[j];

      cnt[make_pair(diff_x, diff_y)] += 1;
      cnt[make_pair(-1LL * diff_x, -1LL * diff_y)] += 1;
    }
  }

  int tmp_max = -1;

  for (auto &e: cnt) {
    tmp_max = max(tmp_max, e.second);
  }

  printf("%d\n", n - 1 - tmp_max + 1);

  return 0;
}


Measured memory_bytes: 384