akhauriyash/Code-Regression huggingface dataset:
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>

using namespace std;

#define rep(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool smin(T &a, const T &b)   { return a > b ? a = b : a;    }
template<typename T> inline bool smax(T &a, const T &b)   { return a < b ? a = b : a;    }

typedef long long LL;

const int N = (int) 1e3 + 3, mod = (int) 0;
int a[N];
int main() {
	int n;
	cin >> n;
	int sum = 0;
	for (int j = 0; j < n; ++j) {
		cin >> a[j];
		sum += a[j];
	}
	int res = (sum % 10 == 0 ? 0 : sum);
	for (int j = 0; j < n; ++j)
		res = max(res, ((sum - a[j]) % 10 == 0 ? 0 : sum - a[j]));
	cout << res << endl;
}










Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;



int main() {
    int n, m, q;
    while(cin >> n >> m >> q, n){
        vector<bitset<50>> v(m);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                v[j].set(i);
            }
        }
        bitset<50> b;
        for (int i = 0; i < q; ++i) {
            string s, t;
            cin >> s >> t;
            for (int j = 0; j < n; ++j) {
                if(s[j] == '1') b[j].flip();
            }

            for (int j = 0; j < n; ++j) {
                for (int k = 0; k < m; ++k) {
                    if(b[j] && t[k] == '0') v[k][j] = false;
                    if(!b[j] && t[k] == '1') v[k][j] = false;
                }
            }
        }
        for (int i = 0; i < m; ++i) {
            if(v[i].count() == 1){
                for (int j = 0; j < n; ++j) {
                    if(v[i][j]) {
                        if(j >= 10) printf("%c", j-10+'A');
                        else printf("%d", j);
                        break;
                    }
                }
            }else printf("?");
        }
        puts("");
    }
    return 0;
}


Measured memory_bytes: 3352
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		int[][] h = new int[r+1][c+1];
		
		for(int i = 0; i < r; i++) {
			int rsum = 0;
			for(int j = 0; j < c; j++) {
				int tmp = sc.nextInt();
				rsum += tmp;
				h[i][j] = tmp;
			}
			h[i][c] = rsum;
		}
		
		for(int i = 0; i < c+1; i++) {
			int rsum = 0;
			for(int j = 0; j < r; j++) {
				rsum += h[j][i];
			}
			h[r][i] = rsum;
		}
		
		for(int i = 0; i < r+1; i++) {
			for(int j = 0; j < c; j++) {
				System.out.print(h[i][j] + " ");
			}
			System.out.println(h[i][c]);
		}
	}
}


Measured memory_bytes: 41528
#include <bits/stdc++.h>
#define lli long long int
#define MAX 1000000000
using namespace std;

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

    string s, t;
    bool flag = true;
    cin>>s>>t;
    for(int i=0; i<s.length(); i++){
        if(s[i]!=t[i]){
            flag = false;
            break;
        }
    }
    if(flag)
        cout<<"Yes";
    else
        cout<<"No";

    return 0;
}


Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  ll n;
	string s, t;
	cin >> n >> s >> t;

	for (ll i = 0; i < n; i++) {
		if (s.substr(i) == t.substr(0, n - i)) {
			cout << n + i << endl;
			return 0;
		}
	}
	cout << 2 * n << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int Linear(int S[],int k,int n); //Linear search

int n,q,S[10000],T[500];
int NIL=-1;
int key;
int i,j; 

main(){
  int c=0,k=0;

  scanf("%d",&n); //inpput n integers of S
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  
  scanf("%d",&q); //input q integers of T
  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
  }

  for(j=0 ; j<q ; j++){   
  key = T[j];
  k = Linear(S,key,n); 
    if (k==1)	c++; //add c if the number inside S is as same as one key of T
  }
  
  printf("%d",c);  // ouput of C
  printf("\n");
  return 0;
}

int Linear(int S[],int k,int n){ //search the same value as "T-key" in S
    
  for(i=0 ; i<n ; i++){  //S loop
    if(S[i]==k){
      return 1; //add the number of the same value in S and T
    }
  
  }
return 0;
}

Measured memory_bytes: 644
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, D, A, XH):
    XH.sort()

    q = deque()
    ans = 0
    dmg = 0
    for x, h in XH:
        while q and q[0][0] < x:
            _, d = q.popleft()
            dmg -= d
        if h <= dmg:
            continue
        a = -(-(h - dmg) // A)
        ans += a
        q.append((x+2*D, a*A))
        dmg += a*A
    return ans


def main():
    N, D, A = read_int_n()
    XH = [read_int_n() for _ in range(N)]
    print(slv(N, D, A, XH))


if __name__ == '__main__':
    main()


Measured memory_bytes: 100796
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    vector<ll> cnt(3, 0);
    string rgb = "RGB";
    for (auto& c : S) {
        rep(i, 0, 3) {
            if (c == rgb[i]) {
                ++cnt[i];
            }
        }
    }
    ll ans = 0;
    rep(i, 0, N) {
        rep(j, 0, 3) {
            if (S[i] == rgb[j]) {
                --cnt[j];
            }
        }
        rep(j, 0, i) {
            if (S[j] == S[i]) {
                continue;
            }
            int dist = i - j;
            rep(k, 0, 3) {
                if (S[i] != rgb[k] && S[j] != rgb[k]) {
                    ans += cnt[k] - (i + dist < N && S[i + dist] == rgb[k] ? 1 : 0);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3200
use proconio::input;

fn main() {
    input!(n: usize, xy: [(i64, i64); n]);
    let p = (xy[0].0 + xy[0].1).abs() % 2;
    if !xy.iter().all(|&(x, y)| (x + y).abs() % 2 == p) {
        println!("{}", -1);
        std::process::exit(0);
    }

    let arms: Vec<_> = std::iter::successors(Some(1i64), |x| Some(x * 2))
        .take_while(|&x| x <= 2_000_000_000)
        .collect::<Vec<_>>()
        .into_iter()
        .rev()
        .collect();
    println!("{}", arms.len() + if p == 0 { 1 } else { 0 });
    if p == 0 {
        print!("{} ", 1);
    }
    println!(
        "{}",
        arms.iter()
            .map(|&x| x.to_string())
            .fold("".to_string(), |acc, s| if acc.is_empty() {
                s
            } else {
                acc + " " + s.as_str()
            })
    );
    for (mut x, mut y) in xy {
        if p == 0 {
            print!("L");
            x += 1;
        }
        assert!((x + y).abs() % 2 == 1);
        for d in arms.iter().copied() {
            match (0 < x + y, 0 < x - y) {
                (true, true) => {
                    print!("R");
                    x -= d;
                }
                (true, false) => {
                    print!("U");
                    y -= d;
                }
                (false, false) => {
                    print!("L");
                    x += d;
                }
                (false, true) => {
                    print!("D");
                    y += d;
                }
            }
        }
        println!("");
        assert!(x == 0 && y == 0);
    }
}


Measured memory_bytes: 2244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=200005,INF=1<<30;

struct UF{
    int n;
    vector<int> par,size;
    
    void init(int n_){
        n=n_;
        par.assign(n,-1);
        size.assign(n,1);
        
        for(int i=0;i<n;i++){
            par[i]=i;
        }
    }
    
    int root(int a){
        if(par[a]==a) return a;
        else return par[a]=root(par[a]);
    }
    
    void unite(int a,int b){
        if(root(a)!=root(b)){
            size[root(a)]+=size[root(b)];
            par[root(b)]=root(a);
        }
    }
    
    bool check(int a,int b){
        return root(a)==root(b);
    }
};

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,Q;cin>>N>>Q;
    UF uf;
    uf.init(N);
    
    while(Q--){
        int t,a,b;cin>>t>>a>>b;
        //a--;b--;
        if(t){
            if(uf.check(a,b)) cout<<1<<"\n";
            else cout<<0<<"\n";
        }else{
            uf.unite(a,b);
        }
    }
}


Measured memory_bytes: 4668
import sys
N=int(input())
A=[int(input()) for i in range(N)]
A=sorted(A,reverse=True)
L=[0]*30
M=[0]*30
for a in A:
    s=bin(a)[2:]
    s=s[::-1]
    t=0
    for i in range(len(s)):
        if s[i]=='1':
            L[i]+=1
            if t==0:
                M[i]+=1
                t=1
ans=0
for i in range(29,-1,-1):
    if L[i]%2==1:
        if M[i]==0:
            print(-1)
            sys.exit()
        ans+=1
        if i!=0:
            for j in range(i):
                L[j]+=1
        #print(i,ans)
print(ans)

Measured memory_bytes: 53080
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
int main(){
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<ii>intv(n);
	for(int i=0;i<n;i++){
		int x,l; cin>>x>>l;
		intv[i]={x+l,x-l};
	}
	sort(intv.begin(),intv.end());
	int ans=1, prev=0;
	for(int i=1;i<n;i++){
		if(intv[i].second>=intv[prev].first){
			ans++;
			prev=i;
		}
	}	
	cout<<ans<<'\n';
	return 0;
}

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

int main(){
	string str;
	cin>>str;
	
	long long ans=0;
	string cf="CODEFESTIVAL2016";
	for(int  i=0;i<16;++i){
		if(str[i]!=cf[i]){
			++ans;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[100][100];
int color[100];
int time;
int d[100], f[100];

void visit(int u)
{
    int v;

    color[u] = GRAY;
    d[u] = ++time;
    for (v = 0; v < n; v++)
    {
        if (M[u][v] == 0)
            continue;
        if (color[v] == WHITE)
            visit(v);
    }
    color[u] = BLACK;
    f[u] = ++time;
}

void dfs()
{
    int u;

    for (u = 0; u < n; u++)
        {
            color[u] = WHITE;
        }
    time = 0;

    for (u = 0; u < n; u++)
    {
        if (color[u] == WHITE)
            visit(u);
    }
}

int main()
{
    int u, v, k;
    int i, j;

    scanf("%d", &n);
    for (i = 0; i < n; i++)
        {
            for (j = 0; j < n; j++)
                    {
                        M[i][j] = 0;
                    }
        }

    for (i = 0; i < n; i++)
    {
        scanf("%d%d", &u, &k);
        for (j = 0; j < k; j++)
        {
            scanf("%d", &v);
            M[u - 1][v - 1] = 1;
        }
    }

    dfs();
    for (i = 0; i < n; i++)
        printf("%d %d %d\n", i + 1, d[i], f[i]);

    return 0;
}



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

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    if(a%2==0){if(a%3!=0 && a%5!=0){cout << "DENIED" << endl;
                                   return 0;}}
    
  }
  cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using ll = long long;
using vll = vector<ll>;
const ll INF = 1e15 + 5;
int main() {
	int n, W; cin >> n >> W;
	vi w(n), v(n);
	for (int i = 0; i < n; i++){
		cin >> w[i] >> v[i];
	}
	vll dp(W + 5, -INF);
	dp[0] = 0;
	for (int i = 0; i < n; i++){
		for (int j = W; j >= 0; j--){
			if (j - w[i] < 0) continue;
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
		}
	}
	ll mx = 0;
	for (int i = 0; i <= W; i++) mx = max(mx, dp[i]);
	cout << mx << endl;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int R[200000];
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> R[i];
    }
    int minv = R[0];
    int maxv = R[1] - R[0];
    for (int j = 1; j < n; j++)
    {
        if (minv > R[j])
        {
            minv = R[j];
        }
        else if (maxv < R[j] - minv)
        {
            maxv = R[j] - minv;
        }
    }
    cout << maxv << endl;
}



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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >> N;
    
    cout << N*(N+1)/2 << endl;
}


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

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

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    string s;
    cin >> s;

    rep(i, s.size()) {
        if ((i+1) % 2 != 0 && !(s[i]=='R' || s[i]=='U' || s[i]== 'D')) {
            cout << "No" << endl;
            return 0;
        }
        if ((i+1) % 2 == 0 && !(s[i]=='L' || s[i]=='U' || s[i]== 'D')) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char x[210000];
int main(void){
    int sl,amin,zmax,i;
    scanf("%s",&x);
    sl=strlen(x);
    for(i=0;i<sl;i++){
        if(x[i]=='A'){
            amin=i;
            break;
        }
    }
    for(i=0;i<sl;i++){
        if(x[i]=='Z'){
            zmax=i;
        }
    }
    printf("%d\n",zmax-amin+1);
    return 0;
}



Measured memory_bytes: 384
#include <string>
#include <iostream>

using namespace std;

string S;
int c[26];

int main(){
  cin>>S;
  for(int i=0;i<26;i++)c[i]=0;
  for(int i=0;i<S.length();i++)c[S[i]-'a']++;
  int f=1;
  for(int i=0;i<26;i++) if(c[i]%2!=0)f=0;
  if(f) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(x)     		(x).begin(),(x).end()
#define ub    			upper_bound
#define lb 				lower_bound
#define ins				insert
#define int 			long long
#define endl			'\n'
#define ff              first
#define ss              second
#define ull				unsigned long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define si 				set<int>
#define usi 			unordered_set<int>		
#define mii             map<int,int>
#define umii			unordered_map<int ,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,a,n)		for(int i=a;i<n;++i)
#define repd(i,a,n)		for(int i=a;i>n;--i)
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define deb(x)			cout<<#x <<"="<<x<<endl;
#define deb2(x,y)		cout<<#x<<"="<<x<<"  "<<#y<<"="<<y<<endl;
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int Pow(int a,int b){int res=1;while(b>0){if(b&1)res*=a;a*=a;b/=2;}return res;}
int MPow(int a,int  b){int res=1;while(b>0){if(b&1)res=(res*a)%Mod;a=(a*a)%Mod;b/=2;}return res%Mod;}
int log(int x){return 64-__builtin_clzll(x)-1;}

void c_p_p()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
}
struct Node
{
	int a,b,c,d;
	
};
bool cmp(Node A,Node B)
{
	return A.a<B.a;
}
const int Max=1e5+1;

int32_t main()
{
	c_p_p();
	int l,r,d;
	cin>>l>>r>>d;
	int ans=0;
	for(int i=d;i<=r;i=i+d)
	{
		if(i>=l)++ans;
	}
	cout<<ans;
	return 0;
}
	

Measured memory_bytes: 3640
import sys
import math
 
sys.setrecursionlimit(10 ** 8)
input = sys.stdin.readline
 
def main():
  K = int(input())
  s = list(map(int, input().split()))
  prod = 1
  a = 10 ** 18
  if 0 in s:
    print(0)
    sys.exit()
  for k in range(K):
    prod = prod * s[k]
    if prod > a:
      print(-1)
      sys.exit()
  
  print(prod)

if __name__ == '__main__':
  main()

Measured memory_bytes: 21924
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    String t[] = new String[n];
    int s[] = new int[n];
    Data []d = new Data[n];
    
    for (int i=0; i<n; i++){
      t[i] = sc.next();
      s[i] = Integer.parseInt(sc.next());
    }
    
    String pt = sc.next();
    int ip = 0;
    
    for(int i= 0; i < n; i++) {
      d[i] = new Data(t[i], s[i]);
      if(t[i].equals(pt)){
        ip = i;
      }
    }
    
    int ans = 0;
    for(int i = ip+1; i < n; i++){
      ans += s[i];
    }
    
    System.out.println(ans);
    
  }
  
  public static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    }
  }
}

class Data{
    private String a;
    private int b;
    public Data(String a, int b) {
        this.a = a;
        this.b = b;
    }
    public String getA() {
        return a;
    }
    public int getB() {
        return b;
    }
}


Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=105;
char s[N];LL k; 
int main() {
    scanf("%s",s);
    LL num=0;
    for (LL i=0;i<strlen(s);i++) {
        if (s[i]=='1') num++;
        else break;
    }
    scanf("%lld",&k);
    if (k<=num) cout<<1;
    else cout<<s[num];
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,mt;
    cin>>n>>mt;
    int c[100],t[100];
    bool tle=true;
    int mc=9999;
    for(int i=0;i<n;i++){
        cin>>c[i]>>t[i];
        if(t[i]<=mt){
            tle=false;
            mc=min(mc,c[i]);
        }
    }
    if(tle==true)puts("TLE");
    else cout<<mc<<endl;
    return 0;
}

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

int	get_g(int i, vector<int> &grp) {
	if (i==grp.at(i)) return i;
	return get_g(grp.at(i), grp);
}

int     main() {
	int N, M;
	cin >>N >>M;
	vector<vector<int>> L(N+1);
	for (int i=1; i<=N; i++) {
		int K;
		cin >>K;
		for (int j=0; j<K; j++) {
			int LL;
			cin >>LL;
			LL +=100000;
			// Member: i speaks Language LL
			L.at(i).push_back(LL);
		}
	}
	// NN: Number of nodes
	// M: Number of links
	int NN=200000;
	// Data store
	// p: Original value for each position
	// grp: Group#
	// grp_depth: Steps to the group root
	//vector<int> p(NN+1, 0);
	vector<int> grp(NN+1, 0);
	vector<int> grp_depth(NN+1, 0);
	// Read data for each node
	// Initialize group# as each own
	for (int i=1; i<=NN; i++) {
		grp.at(i)=i;
	}
	// Grouping
	for (int i=1; i<=N; i++) {
		for (int j=0; j<L.at(i).size(); j++) {
			int xx=i;
			int yy=L.at(i).at(j);
			xx=get_g(xx, grp);
			yy=get_g(yy, grp);
			// Already in same group, do nothing
			if (xx==yy) continue;
			// Put into one group
			if (grp_depth.at(xx)==grp_depth.at(yy)) {
				// Groups have same height
				// Merge into less-number-group
				grp.at(max(xx, yy)) = get_g(min(xx, yy), grp);
				grp_depth.at(min(xx, yy))++;
			} else if (grp_depth.at(xx)>grp_depth.at(yy)) {
				// x is higher
				// Merge into x so that the hight will not increase
				// (height for y will be +1)
				grp.at(yy) = xx;
			} else
				// y is higher
				// Merget into y
				grp.at(xx) = yy;
		}
	}
	int G=get_g(1, grp);
	for (int i=2; i<=N; i++) {
		if (G==get_g(i, grp))
			continue;
		else {
			cout <<"NO" <<endl;
			return 0;
		}
	}
	cout <<"YES" <<endl;
	return 0;
};


Measured memory_bytes: 7296
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        if ((a.charAt(2) == a.charAt(3)) && (a.charAt(4) == a.charAt(5))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
vector<int> G[200010];
int add[200010];
int ans[200010];
void dfs(int x = 0, int p = -1, int num = 0) {
    num += add[x];
    ans[x] = num;
    for(auto& to: G[x]) {
        if(to == p) continue;
        dfs(to, x, num);
    }

}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    rep(i, Q) {
        int p, x;
        cin >> p >> x;
        p--;
        add[p] += x;
    }
    dfs();
    rep(i, N) {
        if(i != 0) cout << " ";
        cout << ans[i]; 
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 26968
//B - Candies:  
//Assunto: 
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, auxS1 = 0, auxS2, soma = 0;
    cin >> n;
    int grid[2][n];
    loop(i, 0, n) cin >> grid[0][i];
    loop(i, 0, n) cin >> grid[1][i];
    loop(i, 0, n) {
        auxS1 += grid[0][i];
        auxS2 = 0;
        loop(j, i, n) {
            auxS2 += grid[1][j];
        }
        soma = max(soma, auxS1+auxS2);
    }
    cout << soma << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100010];
int main(){
	int n;
	ll sum=0;
	cin >> n;
	for(int i=1;i<=n;i++){
		int x;
		cin >> x;
		a[x]++;
		sum+=x;
	}
	int q;
	cin >> q;
	while(q--){
		int b,c;
		cin >> b >> c;
		sum+=(c-b)*a[b];
		a[c]+=a[b];
		a[b]=0;
		cout << sum << endl;
	} 
	return 0;
}

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

int main()
{
	int K, S;
	cin >> K >> S;

	uint64_t result = 0;
	for(int x=0; x<=K; x++){
		for(int y=0; y<=K; y++){
			int z = S - x - y;
			if(0 <= z && z <= K){
				result++;
			}
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 256
import math
import collections
def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N=int(input())
strings=[str(sorted(input())) for a in range(N)]
c=collections.Counter(strings)
tp=c.most_common()
sums=0
for thing in tp:
    if thing[1]!=1:
        sums=sums+combinations_count(thing[1],2)
    else:break

print(sums)

Measured memory_bytes: 30560
#include <bits/stdc++.h>
using namespace std;
int main() {
    int A,B;
    cin >> A >> B;

    int ans = 0;
    if (A==1) {
       if (B == 2) {
           ans = 3;
       } else if (B == 3) {
           ans = 2;
       }
    } else if (A==2) {
       if (B == 1) {
           ans = 3;
       } else if (B == 3) {
           ans = 1;
       }
    } else if (A==3) {
       if (B == 1) {
           ans = 2;
       } else if (B == 2) {
           ans = 1;
       }
    }


    cout << ans << endl;


}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 1e+5;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

void solve() {
    ll x, y;
    cin >> x >> y;
    int c = 0;
    while (x <= y) {
        ++c;
        x *= 2;
    }
    cout << c << endl;
}

int main() {
    solve();
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;



int main(){
    int n;
    cin >> n;
    vector<vector<P>>v(n);
    rep(i,n){
        int a;
        cin >> a;
        rep(j,a){
            int x,y;
            cin >> x >> y;
            x--;
            v[i].push_back({x,y});
        }
    }
    int ans = 0;
    for(int bit = 0;bit<(1<<n);bit++){
        bool flag = true;
        rep(i,n){
            if(!((bit>>i)&1))continue;
            rep(j,v[i].size()){
                int x,y;
                x = v[i][j].first;
                y = v[i][j].second;
                if(((bit>>x)&1)!=y)flag=false;
            }
        }
        if(flag){
            int now = __builtin_popcount(bit);
            chmax(ans,now);
        }

    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int N;
  while(scanf("%d", &N) && N){
    int res = N+1, k;
    bool f = false;
    rep(i, N){
      scanf("%d", &k);
      if(k == 0) res--;
      else if(k > 1) f = 1;
    }
    if(f) printf("%d\n", res); else puts("NA");
  }
  return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  int a[m];
  int i;
  int sum=0;
  for(i=0;i<m;i++)
  {
    cin>>a[i];
    sum=sum+a[i];
  }
  if(sum>n)
    cout<<-1;
  else
    cout<<n-sum;
  return 0;
}

Measured memory_bytes: 3628
// B - Bishop
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll H,W;

ll solve(){
	if(H<W) swap(H,W);
	if(W==1) return 1L;
	return H*(W/2) + (W%2? (H+2-1)/2: 0);
}

int main(){
	cin>>H>>W;
	cout<< solve() <<endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<long long int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<long long>());
  long long int b = 0;
  long long int c = 0;
  for(int i = 0; i < n; i++){
    if(a[i] == a[i+1]){
      if(b == 0){
        b = a[i];
        i++;
      }
      else if(c == 0){
        c = a[i];
        break;
      }
    }
  }
  cout << b*c << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Team{
  int id;
  int solve;
  int time;
  int wa[20];
  Team(int n){
    id = n;
    solve = 0;
    time = 0;
    REP(i, 20) wa[i] = 0;
  }
  bool operator < (const Team& t) const {
    if(solve != t.solve) return solve > t.solve;
    if(time != t.time) return time < t.time;
    return id > t.id;
  }
};

int main(){
  int M, T, P, R;
  while(cin >> M >> T >> P >> R && M){
    vector<Team> teams;
    REP(i, T) teams.push_back(Team(i + 1));
    REP(i, R){
      int m, t, p, j;
      cin >> m >> t >> p >> j;
      if(j == 0){
        teams[t - 1].time += m + teams[t - 1].wa[p - 1] * 20;
        teams[t - 1].solve ++;
      }else{
        teams[t - 1].wa[p - 1] += 1;
      }
    }
    sort(teams.begin(), teams.end());
    REP(i, teams.size()){
      if(i != 0) {
        if(teams[i - 1].time == teams[i].time && teams[i - 1].solve == teams[i].solve) cout <<"=";
        else cout << ",";
      }
      cout << teams[i].id;
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
use std::collections::HashMap;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn solve(s: &str) -> &str {
    let mut dic = HashMap::new();
    for c in s.chars() {
        let count = dic.entry(c).or_insert(0);
        *count += 1;
    }
    if dic.values().all(|c| c % 2 == 0) {
        "Yes"
    } else {
        "No"
    }
}

fn main() {
    input!(s: String);
    println!("{}", solve(&s));
}


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

#define ll long long
#define ld long double
#define xx first
#define yy second
#define vi vector<int>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()

#define MAX 400005

ll dp[3000]={0};

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

    string s;
    cin >> s;

    dp[2019]=1;
    dp[0]=1;

    ll cur = 0, pw=1, ans=0;
    for(int i=s.size()-1;i>=0;i--)   
    {
        ll tm = pw*(s[i]-'0');
        cur+=tm;
        cur%=2019;

        ans+= dp[cur];
        dp[cur]++;

        // cout << cur << endl;

        pw*=10;
        pw%=2019;
    }

    cout << ans << endl;

    return 0;
}

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

#define ALL(a) (a).begin(). (a).end()

using namespace std;

int other(int x, int y){
	if(x > y)return other(y,x);
	if(x == 0 && y == 1)return 2;
	if(x == 0 && y == 2)return 1;
	if(x == 1 && y == 2)return 0;
}

int main(){
	while(true){
		string str; cin >> str;
		if(str == "0")break;
		vector<int> b(str.size());
		for(int i = 0; i < str.size(); i++){
			switch(str[i]){
				case 'r':
					b[i] = 0;
					break;
				case 'g':
					b[i] = 1;
					break;
				case 'b':
					b[i] = 2;
					break;
			}
		}
		int ans = -1;
		queue<vector<int> > q;
		map<vector<int> , int> m;
		q.push(b);
		m[b] = 0;
		while(!q.empty()){
			auto t = q.front();
			q.pop();
			int c = t[0];
			bool flag = true;
			for(auto e : t){
				if(e != c){
					flag =false;
					break;
				}
			}
			if(flag){
				ans = m[t];
				break;
			}
			
			for(int i = 1; i < t.size(); i++){
				auto tt = t;
				if(t[i] != t[i-1]){
					tt[i] = tt[i-1] = other(t[i], t[i-1]);
				}
				if(m.find(tt) == m.end()){
					q.push(tt);
					m[tt] = m[t]+1;
				}
			}
		}
		if(ans == -1){
			cout << "NA" << endl;
		}
		else{
			cout << ans << endl;
		}
	}

	return 0;
}



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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << 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...);
}

const int N = 200005;


void solve()
{
	int n, d;
	cin >> n >> d;
	int cnt = 0;
	loop(i, 0, n)
	{
		int x, y;
		cin >> x >> y;
		x *= x; y *= y;
		int c = x + y;
		double dis = sqrt(c);

		if (dis <= d) cnt++;
	}
	cout << cnt << endl;

	return;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt",  "r",  stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 3696
/*-----------------------------------------------,
|  __                                       __   |
| |  |--.-----.---.-.----.----.-----.-----.|  |_ |
| |  _  |  -__|  _  |  __|  __|  -__|  _  ||   _||
| |_____|_____|___._|____|____|_____|   __||____||
|                                   |__|         |
`-----------------------------------------------*/
#include<algorithm>
#include<array>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
typedef long long ll; typedef long double ld ;using namespace std;
#define INF 1000000000000
#define MOD 10000007
#define ALL(name) (name).begin(),(name).end()
#define REP(counter, limit) for (long long counter = 0; counter < limit; counter++)
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }
int lcm(int a, int b) { return a * b / gcd(a, b); }
bool primenum(int a) { if (a == 1) { return false; }if (a == 2) { return true; }if (a % 2 == 0) { return false; }for (int i = 3; i < sqrt(a) + 1; i += 2) { if (a != i) { if (a % i == 0) { return false; } } }return true; }
struct setupios{setupios(){ios::sync_with_stdio(0);cin.tie(nullptr); /*cout<<fixed<<setprecision(20);*/};}setupios;
int main() {

  int a,b;
  string s;
  cin>>a>>b>>s;
  REP(i,a){
    if(!(s[i]>='0')){
      cout<<"No"<<endl;
      cerr<<"type1"<<endl;
      return 0;
    }
  }
  if(!(s[a]=='-')){
    cout<<"No"<<endl;
    cerr<<"-"<<endl;
    return 0;
  }
  REP(i,b){
    if(!(s[i+a+1]>='0')){
      cout<<"No"<<endl;
      cerr<<"type2"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;
int MOD = 1e9 + 7;

int64 inv(int64 a, int64 mod) {
  a %= mod;
  int64 v[] = { 0, 1, mod };
  int64 u[] = { 1, 0, a };
  while (v[2] != 1) {
    if (v[2] < u[2]) {
      int64 tmp[] = { v[0], v[1], v[2] };
      v[0] = u[0]; v[1] = u[1]; v[2] = u[2];
      u[0] = tmp[0]; u[1] = tmp[1]; u[2] = tmp[2];
      continue;
    }
    int64 coe = v[2] / u[2];
    for (int i = 0; i < 3; ++i) v[i] = v[i] - u[i] * coe;
  }
  return v[0] < 0 ? v[0] + mod : v[0];
}

int64 pow(int64 a, int64 p, int64 mod) {
  a %= mod;
  int64 ret = a;
  while (p > 1) {
    if (p % 2) {
      ret = (ret * ret) % mod;
      ret = (ret * a) % mod;
    } else {
      ret = (ret * ret) % mod;
    }
    p /= 2;
  }
  return ret;
}

int main() {
  //cout << fixed << setprecision(15);
  int N;
  cin >> N;
  int cnt1 = 0;
  int cnt2 = 0;
  int cnt4 = 0;
  int tmp;
  rep(i, N) {
    cin >> tmp;
    if (tmp % 4 == 0) ++cnt4;
    else if (tmp % 2 == 0) ++cnt2;
    else  ++cnt1;
  }

  if (cnt2 == 0 && (cnt1 <= cnt4+1)) cout << "Yes" << "\n";
  else if ((cnt1 <= cnt4)) cout << "Yes" << "\n";
  else cout << "No" << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

string arr[10];

int32_t main()
{
	c_p_c();
	int n, m, k; cin >> n >> m >> k;

	for (int i = 0; i < n; ++i)
		cin >> arr[i];

	int final = inf;

	for (int i = 0; i < (1 << (n - 1)); ++i)
	{
		vi ids;

		ids.pb(-1);

		for (int id = 0; id < n - 1; ++id)
			if ((i >> id) & 1)
				ids.pb(id);

		int ans = ids.size();
		ans--;

		//cout<<i<<' '<<ans<<' ';

		ids.pb(n - 1);
		bool can = 1;

		vi v[10];

		for (int j = 0; j < m; ++j)
		{
			for (int i = 0; i + 1 < ids.size(); ++i)
			{
				int cur = 0;
				for (int id = ids[i] + 1; id <= ids[i + 1]; ++id)
					cur += (arr[id][j] == '1');

				if (cur > k)
				{
					can = 0;
					break;
				}

				v[i].pb(cur);
			}

			if (!can)
				break;
		}

		if (!can)
			continue;

		int pre[10] = {};
		int prt = ans + 1;

		for (int j = 0; j < m; ++j)
		{
			int cut = 0;
			for (int i = 0; i < prt; ++i)
			{
				pre[i] += v[i][j];

				if (pre[i] > k)
					cut = 1;
			}

			if (cut)
			{
				for (int i = 0; i < prt; ++i)
				{
					pre[i] = v[i][j];
				}
				ans++;
			}
		}

		//cout << i << ' ' << ans << '\n';

		final = min(final, ans);
	}

	cout << final << '\n';
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
    int n;
    cin >> n;
    bool flag = false;
    rep2(i, 1, 500000) {
        if(floor(i * 1.08) == n) {
            cout << i << endl;
            flag = true;
            break;
        }
    }
    if(!flag)
        cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 256
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_3_A&lang=jp
所要時間は15分程度。一つ目の例題をACしてしまえばやるだけといいった印象。
着席位置は{中央x中央}
*/


#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<complex>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;
using std::abs;
using std::complex;

#define INF 999999999;
#define MOD 1000000007

using ulli = unsigned long long int;

//#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

using Comp = complex<double>;

int n;
double x1, y1n, x2, y2, x3, y3, x4, y4;

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

    scanf("%d", &n);
    for(int i = 0; i < n; i++){
            scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1n, &x2, &y2, &x3, &y3, &x4, &y4);
            //printf("%f %f %f %f %f %f %f %f", x1, y1n, x2, y2, x3, y3, x4, y4);
            Comp ab = Comp(x2-x1, y2-y1n);
            Comp cd = Comp(x4-x3, y4 - y3);
            double s = ab.real() * cd.imag() - ab.imag()*cd.real();
            //dbug(s)
            if(abs(s) < 0.0000000001) printf("YES\n");
            else printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

template<long long mod> struct modint {
    long long x;
    modint(long long x=0) : x((x%mod+mod)%mod) {}
    static int get_mod() { return mod; }
    modint &operator+=(const modint &a) {
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator-=(const modint &a) {
        if((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    modint &operator*=(const modint &a) {
        x = (int) (1LL * x * a.x % mod);
        return *this;
    }
    modint &operator/=(const modint &a) {
        *this *= a.inv();
        return *this;
    }
    modint operator-() const { return modint(-x); }
    modint operator+(const modint &a) const { return modint(*this) += a; }
    modint operator-(const modint &a) const { return modint(*this) -= a; }
    modint operator*(const modint &a) const { return modint(*this) *= a; }
    modint operator/(const modint &a) const { return modint(*this) /= a; }
    bool operator==(const modint &a) const { return x == a.x; }
    bool operator!=(const modint &a) const { return x != a.x; }
    modint pow(long long t) const {
        if (!t) return 1;
        modint<mod> a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    modint inv() const {
        return pow(mod-2);
    }
    friend std::ostream &operator<<(std::ostream &os, const modint &a) { return os << a.x; }
    friend std::istream &operator>>(std::istream &is, modint &a) {
        long long t;
        is >> t;
        a = modint<mod>(t);
        return (is);
    }
};
//const long long mod = 998244353;
const long long mod = 1000000007;
using mint = modint<mod>;

int main(){
    int n,k;
    std::cin >> n >> k;
    std::vector<int> a(n,0);
    rep(i,n) std::cin >> a[i];

    mint ans = 0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(a[i]>a[j]) ans += 1;
        }
    }

    mint cnt = 0;
    std::sort(a.begin(),a.end());
    for(int i=0; i<n; i++){
        for(int j=0; j<i; j++){
            if(a[i]>a[j]) cnt += 1;
        }
    }

    std::cout << ans*k + cnt*k*(k-1)/2 << "\n";
    return 0;
}


Measured memory_bytes: 3612