akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x, y;
string s;
ll res = 0;

// < ----------- func eh ---------------- ? //


// <------------- Start of main() -------------------> //

void MAIN() {
	vll val = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	cin>>k;
	cout<<val[k-1];
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(n) begin(n),end(n)
using ll = long long;
using P = pair<int,int>;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i,n) cin >> x[i] >> y[i];
    if(n==1) {cout << 1 << endl; return 0;}
    int ans = 1e9;
    rep(i,n) {
        rep(j,n) {
            if(i==j) continue;
            ll dx = x[j] - x[i];
            ll dy = y[j] - y[i];
            int cnt = 0;
            rep(k,n){
                rep(l,n) {
                    if(k==l) continue;
                    if(dx==x[l]-x[k] && dy==y[l]-y[k]) cnt++;
                }
            }
            ans = min(ans, n-cnt);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<stack>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
struct Edge {
    int src, dst;
    int rev;
    bool use;
    Edge(int s, int d): src(s), dst(d) {}
    Edge(int s, int d, int r, bool u): src(s), dst(d), rev(r), use(u) {};
};
typedef vector<vector<Edge> > Graph;
Graph G;
void add_edge(int x, int y) {
    G[x].push_back(Edge(x, y, G[y].size(), false));
    G[y].push_back(Edge(y, x, G[x].size()-1, false));
}
vector<Edge> eularianCycle() { // [(0->x), (x->y), ..., (z->0)]
    int N = G.size(), cnt = 0;
    for (int i=0; i<N; i++) {
	cnt += G[i].size();
	if (G[i].size()%2) return vector<Edge>(); // odd degree vertex
    }
    vector<int> iter(N);
    vector<Edge> ret;
    stack<Edge> S;
    S.push(Edge(-1, 0));

    while (!S.empty()) {
	Edge e = S.top();
	if (iter[e.dst] < (int)G[e.dst].size()) {
	    Edge &f = G[e.dst][iter[e.dst]++];
	    if (!f.use) {
		f.use = G[f.dst][f.rev].use = true;
		S.push(f);
	    }
	} else {
	    S.pop();
	    ret.push_back(e);
	}
    }
    if ((int)ret.size() != (cnt>>1)+1) return vector<Edge>(); // not connected
    ret.pop_back(); reverse(ret.begin(), ret.end());
    return ret;
}


int N, M;
int J[100011];
bool ban[1000011];
bool three() {
    for (int t=1; t<=2; t++) {
	REP (s, N) if ((J[s]&t) == t) {
	    VI ord;
	    ord.push_back(s);
	    for (int i=0; i<(int)ord.size(); i++) {
		int v = ord[i];
		EACH (e, G[v]) if (!ban[e->dst] && (J[e->dst]&t) == 0) {
		    J[e->dst] |= t;
		    ord.push_back(e->dst);
		}
	    }
	    break;
	}
    }
//    rprintf("%d", J, J+N);

    REP (i, N) if (!ban[i] && J[i] == 1) return true;
    return false;
}

void MAIN() {
    scanf("%d%d", &N, &M);
    G.resize(N);
    REP (i, M) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	add_edge(x, y);
    }

    auto a = eularianCycle();
    bool yes = false;
    if (!a.empty()) {
	int rem = 0;
	int cnt = 0;
	REP (i, N) if (G[i].size() > 2u) {
	    rem++;
	    J[i] = rem;
	    ban[i] = true;
	    cnt += G[i].size()-2;
	}
	
	if (cnt == 4 && rem == 2) {
	    yes = three();
	} else if (cnt >= 4) {
	    yes = true;
	}
    }

    puts(yes? "Yes": "No");
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 11728
import math
import sys
if __name__ == "__main__":
    x = int(input())

    for i in range(1, int(math.sqrt(x)) + 1):
        if x % i == 0:
            sm = i
            lg = x // i

            for a in range(1, 10 ** 5 + 1):
                b = a - sm
                if a ** 4 + a ** 3 * b + a ** 2 * b ** 2 + a * b ** 3 + b ** 4 == lg:
                    print(a, b)
                    sys.exit(0)

Measured memory_bytes: 68636
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		long X = sc.nextLong();
		
		if (N == 1) {
			System.out.println(Math.abs(X - sc.nextLong()));
			return;
		}
		
		List<Long> cityList = new ArrayList<>();
		
		cityList.add(X);
		for (int i = 0; i < N; i++) {
			cityList.add(sc.nextLong());
		}
		Collections.sort(cityList, Collections.reverseOrder());

		long lastDiff = Math.abs(cityList.get(0) - cityList.get(1));
		long minNum = Math.abs(cityList.get(cityList.size() - 1));

		for (long k = lastDiff; k >= 1; k--) {
			for (int i = 0; i < N + 1; i++) {
				if (!(Math.abs(cityList.get(i)) % k == minNum % k)) {
					break;
				}
				if (i == N) {
					System.out.println(k);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 60176
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld",&n);
  scanf("%s",s);
  result = 1;
  rep(i,n-1){
    if(s[i]!=s[i+1]) result++;
  }
  printf("%lld", result);
  
  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int[] A = new int[2000];
	static int n;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		
		for (int i = 0; i < n; i++) {
			A[i] = sc.nextInt();
		}

		int q, m;
		q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			m = sc.nextInt();
			if(solve(0, m))
				System.out.println("yes");
			else
				System.out.println("no");
		}
	}

	private static boolean solve(int i, int m) {
		if (m == 0)
			return true;
		if (i >= n) 
			return false;
		boolean ans = solve(i + 1, m) || solve(i + 1, m - A[i]);
		return ans;
	}

}



Measured memory_bytes: 26728
function Main(input){
  A = input.split(' ').map(n => parseInt(n)).sort((a, b) => a - b);
  min = 200;
  for (i = 0; i < A.length; i++) {
    for (j = i + 1; j < A.length; j++) {
      sum = A[i] + A[j];
      if (sum < min) {
        min = sum;
      }
    }
  }
  console.log(min);
}

Main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 7372
import math

h, n = map(int, input().split())
a = [0] * n
b = [0] * n
#print(a, b)
for i in range(n):
    a[i], b[i] = map(int, input().split())

#print(a)
#print(b)
INF = int(1e10)
dp = [[INF] * (h+1) for i in range(n+1)]
for i in range(h+1):
    dp[0][i] = math.ceil(i / a[0]) * b[0]
for i in range(n):
    dp[i][0] = 0
for i in range(n):
    for j in range(h+1):
        if j < a[i]:
            dp[i+1][j] = min(math.ceil(j / a[i]) * b[i], dp[i][j])
        else:
            dp[i+1][j] = min(dp[i][j], dp[i+1][j - a[i]] + b[i])
#print(dp)
print(dp[n][h])

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  // 周期性に着目
  bool exist = false;
  for (int i = 1; i <= B; i++) {
    int a;
    a = (A * i) % B;
    if (a == C) {
      exist = true;
      break;
    }
  }
  exist
    ? cout << "YES" << endl
    : cout << "NO" << endl;
}

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

int main(void) {
    string s;
    cin >> s;
    if(strncmp(&s[0], "ABC", 3) == 0) {
        cout << "ARC\n";
    } else {
        cout << "ABC\n";
    }
    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int X = sc.nextInt();

        System.out.println(solve(A, B, X) ? "YES" : "NO");

        sc.close();
    }

    static boolean solve(int A, int B, int X) {
        return X >= A && X <= A + B;
    }
}

Measured memory_bytes: 21204
#include<iostream>

int main() {
	int N = 0;
	int H[20];
	int count = 1;
	int j = 0;
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> H[i];
	}

	for (int i = 0; i < N; i++) {
		if (H[0] <= H[i]) {
			for (j = i - 1; j > 0; j--) {
				if (H[j] <= H[i]) {
					continue;
				}
				else {
					break;
				}
			}
			if (j == 0) {
				count++;
			}
		}
	}

	std::cout << count << std::endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<deque>
int main (){
    std::cin.tie(0); 
	std::ios::sync_with_stdio(false);
    long long N;std::cin>>N;
    //N--;  //1 start.
    long long m;
    std::deque<char> ans;
    
    while (N!=0){
        m=(N-1) % 26;
        ans.push_front((char)(m+97));
        N = (N-1) / 26;
    }

    while (!ans.empty()){
        std::cout<<ans.front();
        ans.pop_front();
    }
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;

    if(a>=(-100) && a<=100 && b>=(-100) && b<=100 && c>=(-100) && c<=100)
    {
        if(c>=a && b>=c)
        {


                     cout<<"Yes"<<endl;

        }
        else
        {
               cout<<"No"<<endl;
        }

    }
    else
        return 0;
}

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

const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,1,0,-1 };
int main() {
	int D; cin >> D;
	while (D--) {
		int N; cin >> N;
		vector<vector<char>>field(N, vector<char>(N, ' '));
		int way = 3;
		int nx = 0;
		int ny = N - 1;
		bool flag = true;
		while (flag) {
			field[ny][nx] = '#';
			if (N == 1)break;
			for (int i = 0; i < 2; ++i) {
				int nextx = nx + dx[way];
				int nexty = ny + dy[way];
				if (nextx >= 0 && nextx < N&&nexty >= 0 && nexty < N) {
					bool aok = true;
					for (int w = -1; w <= 1; ++w) {
						int nextway = (way + 4 + w) % 4;
						int next2x = nextx + dx[nextway];
						int next2y = nexty + dy[nextway];
						if (next2x >= 0 && next2x < N&&next2y >= 0 && next2y < N) {
							if (field[next2y][next2x] == '#') {
								aok = false;
							}
						}
					}
					if(!aok){
						if(i==1)flag = false;
						
					}
					else {
						nx = nextx;
						ny = nexty;
						break;
					}
				}
				way = (way + 3) % 4;
			}
			
		}
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				cout << field[i][j];
			}
			cout << endl;
		}
		if(D)cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    s[3]='8';
    cout<<s<<endl;
}

Measured memory_bytes: 256
from operator import mul
from functools import reduce

def comb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

N,P=map(int,input().split())
A=list(map(lambda x:int(x)%2,input().split()))
A0,A1=A.count(0),A.count(1)
if P==1:
    if not A1:
        print(0)
        exit()
value0=0
for i in range(0,A0+1):
    value0+=comb(A0, i)
value1=(1 if not P else 0)
for i in range(2-P,A1+1,2):
    value1+=comb(A1, i)
print(value0*value1)


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using ll = int_fast64_t;


int main(){
        ll n;
        scanf("%ld", &n);
        std::vector<std::vector<ll>> links(n, std::vector<ll>(0));
        for(ll i=0; i<n-1; i++){
                ll a, b;
                scanf("%ld %ld", &a, &b);
                links[a-1].push_back(b-1);
                links[b-1].push_back(a-1);
        }

        std::vector<ll>  df(n), ds(n), used(n, 0);

        df[0] = 0;
        std::queue<ll> que;
        que.push(0);
        while(!que.empty()){
                ll s = que.front(); que.pop();
                used[s] = 1;
                for(ll t: links[s]){
                        if(used[t]) continue;
                        df[t] = df[s]+1;
                        que.push(t);
                }
        }

        for(ll i=0; i<n; i++) used[i]=0;
        ds[n-1] = 0;
        que.push(n-1);
        while(!que.empty()){
                ll s = que.front(); que.pop();
                used[s] = 1;
                for(ll t: links[s]){
                        if(used[t]) continue;
                        ds[t] = ds[s]+1;
                        que.push(t);
                }
        }

        ll fen = 0, sun = 0;
        for(ll i=0; i<n; i++){
                //printf("%ld %ld\n", df[i], ds[i]);
                if(df[i]<=ds[i]) fen++;
                else sun++;
        }

        //printf("%ld %ld\n", fen, sun);
        if(fen>sun) puts("Fennec");
        else puts("Snuke");
        return 0;
}

Measured memory_bytes: 8576
inpl = lambda: list(map(int,input().split()))
N, K = inpl()
S = input()

def get_sequence(arr):
    if len(arr) == 0:
        return []
    result = []
    n = 1
    prev = arr[0]
    for c in arr[1:]:
        if c == prev:
            n += 1
        else:
            result.append([prev,n])
            prev = c
            n = 1
    result.append([prev,n])
    return result

seq = get_sequence(S)
lengths = [ x[1] for x in seq ]
if seq[0][0] == '0':
    lengths.insert(0,0)
if seq[-1][0] == '0':
    lengths.append(0)

L = (len(lengths)-1)//2
if L <= K:
    print(N)
else:
    ans = sum(lengths[:2*K+1])
    now = ans
    for i in range(L-K):
        now += sum(lengths[2*(K+i)+1:2*(K+i)+3])-sum(lengths[2*i:2*(i+1)])
        ans = max(ans,now)
    print(ans)

Measured memory_bytes: 14488
#include <iostream>
#include <cmath>
#include <algorithm>
typedef long long ll;
using namespace std;

int main() {
	ll A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	if((V-W)*T>=abs(A-B)) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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

using namespace std;
double II(double val)
{
	if (val < 0) return -val;
	return val;
}
int main()
{
	double N, T, A;
	double H[1000];
	double ans = 312313;
	double temp;
	int i;
	int num;
	cin >> N;
	cin >> T >> A;
	for (i = 0; i < N; i++) {
		cin >> H[i];
		temp = II((T - A) - H[i] * 0.006);
		ans = min(ans, temp);
		if (ans == temp) num = i;
	}
	cout << num + 1 << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        int mod = 1000000000 + 7;

        //絶対値の差は、最大でN-1, 最小で0(全体が奇数のとき)
        //絶対値の差は、最大でN-1, 最小で1(全体が偶数のとき)

        int N = int.Parse(Console.ReadLine());
        int[] A = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        
        bool isOK = false;

        if (N % 2 == 0)
        {
            //チェックする必要のある数は、1, 3, 5, ..., N - 1 の合計 N/2 個
            int[] tmp = new int[N / 2];

            foreach(var x in A)
            {
                tmp[x / 2]++;
            }

            if (tmp.All(itm => itm == 2)) isOK = true;
        }
        else
        {
            //チェックする必要のある数は、0, 2, 4, 6, ... N - 1 の合計 N/2 + 1 個
            int[] tmp = new int[N / 2 + 1];
            foreach (var x in A)
            {
                tmp[x / 2]++;
            }

            if (tmp.Skip(1).All(itm => itm == 2) && tmp[0] == 1) isOK = true;
        }


        if (isOK == false)
        {
            Console.WriteLine(0);
            return;
        }
        else
        {
            int ans = 1;
            for(int i = 0; i < N /2; i++)
            {
                ans *= 2;
                ans %= mod;
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 20320
#include<stdio.h>
#include<stdlib.h>
int a[100005];
int asc(const void* x, const void* y)
{
	if (a[*(int*)x] > a[*(int*)y])return 1;
	if (a[*(int*)x] < a[*(int*)y])return -1;
	return 0;
}
int main()
{
	int n;
	scanf("%d", &n);
	int i;
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int b[100005];
	for (i = 0; i < n; i++)
		b[i] = i;
	qsort(b, n, sizeof(int), asc);
	for (i = 0; i < n - 1; i++)
		printf("%d ", b[i] + 1);
	printf("%d\n", b[n - 1] + 1);
	return 0;
}

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

long long func(long long X){
  return log10(X)+1;
}
    
int main() {
  long long min_F=100000000;
  long long N;
  cin >> N;
  for(int i=1;i<=sqrt(N);i++){
    if(N%i!=0){
      continue;
    }
    long long A=max((long long)i,N/i);
    long long F=func(A);
    min_F=min(min_F,F);
  }
  cout << min_F << endl;
} 

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

#define inf 0x3f3f3f3f
#define INF 1000111000111000111LL
#define mod 1000000007
#define endl '\n'
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
#define all(cc) (cc).begin(),(cc).end()
using lli = long long int ;
using pii = pair<int, int> ;
using vi = vector<int> ;
using vb = vector<bool> ;
using vvi = vector<vector<int>> ;
using vlli = vector<long long int> ;
using vpii = vector<pair<int, int>> ;

int main()
  {
    ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
    lli n, W, sum=0, ans=0, idx=1, w1=0, w2=0, w3=0, w4=0 ;
    cin>> n >> W ;
    vlli w(n), v(n) ;
    vector<vector<lli>> weight(5) ;
    map<lli, lli> cnc, ncn ;
    for(int i=0 ; i<n ; i++)
      {
        cin>> w[i] >> v[i] ;
        sum+=w[i] ;
        if(!cnc[w[i]])
          {
            cnc[w[i]]=idx ;
            ncn[idx++]=w[i] ;
          }
      }
    for(int i=0 ; i<n ; i++)
      weight[cnc[w[i]]].pb(v[i]) ;
    for(int i=1 ; i<=4 ; i++)
      {
        weight[i].pb(0) ;
        sort(weight[i].begin(), weight[i].end()) ;
        reverse(weight[i].begin()+1, weight[i].end()) ;
      }
    for(lli i=0 ; i<weight[1].size() ; i++)
      {
        w1+=weight[1][i] ; w2=w3=w4=0 ;
        for(lli j=0 ; j<weight[2].size() ; j++)
          {
            w2+=weight[2][j] ; w3=w4=0 ;
            for(lli k=0 ; k<weight[3].size() ; k++)
              {
                w3+=weight[3][k] ; w4=0 ;
                for(lli l=0 ; l<weight[4].size() ; l++)
                  {
                    w4+=weight[4][l] ;
                    if(i*ncn[1]+j*ncn[2]+k*ncn[3]+l*ncn[4]<=W)
                      ans=max(ans, w1+w2+w3+w4) ;
                  }
              }
          }
      }
    cout<< ans ;
  }


Measured memory_bytes: 764
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val inputs = readLine()!!.split(" ").map { it.toInt() }

    // 何の倍数なのか判定を残さなくてはいけないのは大変では．．．
    // 効率的に残したい いや 毎回すべて判定でも行ける！

    // WA 2つ -> -1 のケースが有りうるのか？？ これはありえない WA は解消
    // TLE 8つ 2111ms で 111ms を解消できない（これならアルゴリズム的にはあっているはず，あとは kotlin の記述方法依存か）

    var ans = IntArray(n) { 0 }
    var num = 0
    val ansIndex = mutableListOf<Int>()

    for (i in n-1 downTo 0) {
        var sum = 0

        // これで少しは早くなる？
        if (i+1 <= (n+1)/2) {
            var start = i+1
            while (start <= n) {
                sum += ans[start-1]
                start += i+1

            }
        }

        if(sum % 2 != inputs[i]) {
            ans[i] += 1
            num += 1
            ansIndex.add(i+1)
        }
    }

    println(num)
    if(num != 0) {
        val out = ansIndex.joinToString(" ")
        println(out)
    }
}

Measured memory_bytes: 79464
N = int(input())
A = list(map(int, input().split()))
a_dict = {}
for a in A:
  if a in a_dict.keys():
    a_dict[a] += 1
  else:
    a_dict[a] = 1
ans = sum(A)
Q = int(input())
for i in range(Q):
  b, c = map(int, input().split())
  if not(b in a_dict.keys()):
    print(ans)
    continue
  num = a_dict.pop(b)
  ans += (c - b)*num
  print(ans)
  if c in a_dict.keys():
    a_dict[c] += num
  else:
    a_dict[c] = num
  

Measured memory_bytes: 20632
N, K, Q = list(map(int, input().split()))
points = [K for x in range(N)]
points = list(map(lambda x: x-Q, points))
for i in range(Q):
    s = int(input())
    points[s-1] += 1

for point in points:
    if point <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 7856
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    long long n,y;
    cin >> n >> y;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            for(int k=0;k<=n-i-j;k++){
                if(i+j+k==n&&10000*i+5000*j+1000*k==y){
                    cout << i << ' ' << j << ' ' << k << endl;
                    return 0;
                }
            }
        }
    }
    cout << "-1 -1 -1" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (int r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
#define mp(a, b) make_pair(a, b)
int main(){
	ll n, d, a;
	cin>>n>>d>>a;
	vector<ll>pre(n, 0);
	vector<pair<ll,ll>>A(n);
	rep(i,0,n)cin>>A[i].first>>A[i].second;
	sort be(A);
	ll x=0, ANS=0;
	d*=2;
	rep(i,0,n){
		A[i].second-=x;
		if(A[i].second>0){
			ll l=i, r=n-1, ans=i, need=(A[i].second+a-1)/a;
			ANS+=need;
			x+=need*a;
			while(r>=l){
				int m=l+(r-l)/2;
				if(A[i].first+d>=A[m].first){
					ans=m;
					l=m+1;
				}else{
					r=m-1;
				}
			}
			pre[ans]+=need*a;
		}
		x-=pre[i];
	}
	cout<<ANS<<"\n";
}


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

const long long N = 1000ll * 1000 * 1000 * 1000 + 5;
const int X = 90;

vector <int> ans;
int get(long long x, int y) {
	return (x >> y) & 1;
}
int main() {
	long long n;
	cin >> n;
	for (int i = 1; i <= X; i++) {
		ans.push_back(i);
	}
	int x = 0;
	for (x = 0; x <= X; x++) {
		if (n >= (1ll << x)) {
			n -= (1ll << x);
		//	ans.push_back(x + 1);
		}
		else {
			break;
		}
	}
//	cout << x << endl;
	for (int i = 0; i < x; i++) {
		if (get(n, i)) {
			ans.push_back(X - i);
		}
		ans.push_back(i + 1);
	}
	cout << ans.size() << endl;
	for (int i = 0; i < ans.size(); i++) {
		cout << ans[i] << " ";
	}
	return 0;
}


Measured memory_bytes: 256
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
// #define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
// #define    ff                       first
// #define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppl                      pair < int , pii>              
#define    sp(x)                    setprecision(x)




#define F first 
#define S second 
#define MAX 1000003 

  
typedef long long ll; 
const int mod = 1000000007; 
  
int prime[MAX]; 
unordered_map<int, int> max_map; 
  
int power(int a, int n) 
{ 
    if (n == 0) 
        return 1; 
    int p = power(a, n / 2) % mod; 
    p = (p * p) % mod; 
    if (n & 1) 
        p = (p * a) % mod; 
    return p; 
} 
  

void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (int i = 2; i < MAX; i++) { 
        if (prime[i] == 0) { 
            for (int j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 
  
 
ll lcmModuloM(const int* ar, int n) 
{ 
  
    for (int i = 0; i < n; i++) { 
        int num = ar[i]; 
        unordered_map<int, int> temp; 
  
        while (num > 1) { 

            int factor = prime[num]; 
  
            // Increase count of factor in temp 
            temp[factor]++; 
  
            // Reduce num by its prime factor 
            num /= factor; 
        } 
  
        for (auto it : temp) { 
  
            max_map[it.first] = max(max_map[it.first], it.second); 
        } 
    } 
  
    ll ans = 1; 
  
    for (auto it : max_map) { 
  
        ans = (ans * power(it.F, it.S)) % mod; 
    } 
  
    return ans; 
} 
  

int32_t main()
{
    speed upp
    sieve(); 
    int n,l,ans=0,x;
    cin>>n;
    int arr[n]; 
    f(i,0,n-1)
        cin>>arr[i];
    
    l=lcmModuloM(arr, n); 
    // cout<<l<<endl;
    f(i,0,n-1)
    {
        x=(1LL*l*power(arr[i],mod-2))%mod;
        ans=(ans+x)%mod;
    }
    cout<<ans;
}

Measured memory_bytes: 8576
let n = stdin.ReadLine() |>  int
let l = stdin.ReadLine().Split() |> Array.map int
let sd = Array.sort l
let mutable count = 0L

for i in 2..(n-1) do
 for j in 1..(i-1) do
  let rec f low high =
   match (high - low)/2 with
   | 0 -> high
   | _ -> let mid = (high + low)/2
          if (sd.[mid] + sd.[j]) > sd.[i] then f low mid else f mid high
  if (sd.[j-1] + sd.[j]) <= sd.[i] then () else
   let sakai = f -1 (j - 1)
   count <- count + (int64 j) - (int64 sakai)

count
|>stdout.WriteLine

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  int n,i;
  cin >> n >> i;
  cout << n - i + 1 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
int main(){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(0 <= x - r && W >= x + r && 0 <= y - r && H >= y + r)
      {printf("Yes\n");}
      else{printf("No\n");};  
    return 0;
}


Measured memory_bytes: 2680
n = int(input())
a = [int(input()) for _ in range(n)]
b = a[:]
first = max(a)
idx = b.index(first)
b[idx] = 0
second = max(b)

for i in range(n):
    if a[i] == first:
        print(second)
    else:
        print(first)


Measured memory_bytes: 18308
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	int sum = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '.')  sum++;
	}
	ans = sum;
	for (int i = 0; i < N; i++) {
		if (S[i] == '.')sum--;
		else sum++;
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <queue>

using namespace std;
using sl = signed long;
using sll = signed long long;
using ll = long long;

int main(int argc, char *argv[])
{
	int N;
	cin >> N;
	//vector<int> h;
	int *student = new int[(N+1)];
	fill_n(student, N+1, 0);
	for(int i =0;i<N;i++){
		int tmp;
		cin >> tmp;
		//h.push_back(tmp);
		student[tmp] = i+1;
	}
	for(int i=1;i<=N;i++){
		cout << student[i] << " ";
	}
	delete[] student;

	return 0;
}

Measured memory_bytes: 1152
import java.io.BufferedReader
import java.io.InputStreamReader

fun isPrime(n: Int): Boolean =
    when (n) {
        0 -> false
        1 -> false
        else -> (2..Math.sqrt(n.toDouble()).toInt()).all { n % it != 0 }
    }

fun main(args: Array<String>) {
    BufferedReader(InputStreamReader(System.`in`))
            .readText()
            .trim()
            .split(regex = """\s+""".toRegex())
            .map { it.toInt() }
            .drop(n = 1)
            .filter { isPrime(it) }
            .count()
            .let { println(it) }
}



Measured memory_bytes: 35080
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
typedef long long ll;
ll a,b,p;
void addm(ll &x,ll y){
	x+=y;
	x%=p;
}
int d(ll x){
	int ret=0;
	while(x) x/=10,ret++;
	return ret;
}
ll power(ll base,ll ex){
	ll ret=1,po=base;
	while(ex){
		if(ex%2) ret=ret*po%p;
		po=po*po%p;
		ex/=2;
	}
	return ret;
}
ll bit[1000002];
ll sum(int x){
	ll s=0;
	while(x>0){
		addm(s,bit[x]);
		x-=(x&-x);
	}
	return s;
}
void add(int x,ll ad){
	while(x<=b){
		addm(bit[x],ad);
		x+=(x&-x);
	}
}
int main(){
	while(true){
		cin>>a>>b>>p;
		if(a==0) break;
		if(b>=1e6){
			if(d(a)<d(b)){
				ll p10=1;
				while(p10<=a) p10*=10;
				cout<<(power(2,b-p10+1)+power(2,p10-a)-2+p*2)%p<<endl;
			}else{
				cout<<(power(2,b-a+1)-1+p)%p<<endl;
			}
			continue;
		}else{
			rep(i,b+1) bit[i]=0;
			for(int i=a;i<=b;i++){
				int p10=1;
				int pp=1;
				rep(j,d(i)-1) pp*=10;
				ll ad=0;
				while(p10<=i){
					ad+=sum(i/pp)-sum(p10-1);
//					show(i/pp);
//					show(ad);
					p10*=10;
					pp/=10;
				}
				ad=(ad%p+p+1)%p;
//				show(ad);
				add(i,ad);
//				printf("sum[%d]=%d\n",i,sum(i));
			}
			cout<<sum(b)<<endl;
		}
	}
}

Measured memory_bytes: 8604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    
           long long n,d;
           cin >>n>>d;
  long long k=d*d;

   long long cnt=0;
    for (int i = 1; i <=n; i++) {
       vector<long long> vec(2);  
      cin>> vec[0]>>vec[1];
      long long a=vec[0]*vec[0]+vec[1]*vec[1];
      if(a<=k)cnt++;
        
    }
cout<<cnt<<endl;
  
}

Measured memory_bytes: 3612
#include<stdio.h>
#define MAX 2000000000
#define INFTY (1<<30)

void maxHeapify(int);
void insert(int);
void increaseKey(int, int);
int heapExtractMax(void);

int H, A[MAX];

void maxHeapify(int i){
  int l, r, large,keep;
  l = 2*i;
  r = 2*i+1;
  if( l <= H && A[l] > A[i] ) large = l;
  else large = i;
  if( r <= H && A[r] > A[large] ) large = r;
  if( large != i){
    keep = A[i];
    A[i] = A[large];
    A[large] = keep;
    maxHeapify(large);
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H, key);
}

void increaseKey(int i, int key){
  int c;
  if(key < A[i]) return;
  A[i] = key;
  while (i > 1 && A[i/2] < A[i]) {
    c = A[i/2];
    A[i/2] = A[i];
    A[i] = c;
    i = i/2;
  }
}

int heapExtractMax(){
  int max;
  if( H < 1 ) return -INFTY;
  max = A[1];
  A[1] = A[H];
  H--;
  maxHeapify(1);
  return max;
}

int main(){
  int key;
  A[H] = -INFTY;
  char com[10];

  while(1){
    scanf("%s", com);
    if(com[0] == 'e' && com[1] == 'n' ) break;
    if(com[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n", heapExtractMax());
    }
  }
  return 0;
}


Measured memory_bytes: 5568
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,k,s;
  cin>>n>>k>>s;
  
  rep(i,n){
    if(i<k){
      cout<<s<<' ';
    }else{
      cout<<((s+1)%(int)(1e9))<<' ';
    }
  }

  cout<<endl;
  
}

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

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

int p[3], q[2];
int res = 1E8;

int main(int argc, char *argv[])
{
  rep(i, 3) cin >> p[i];
  rep(i, 2) cin >> q[i];

  rep(i, 3) rep(j, 2) res = min(res, p[i] + q[j] - 50);

  cout << res << endl;
  
  return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod =1000000007;




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

	VI a(n+10,0);
	REP(i, m) {
		int b, c;
		cin >> b >> c;
		a[b - 1]++;
		a[c]--;
	}
	FOR(i, 1, n + 2) {
		a[i] = a[i] + a[i - 1];
	}


	int ans = 0;
	REP(i, n+1) {
		if (a[i] == m)ans++;
	}

	cout << ans << endl;

}



Measured memory_bytes: 640
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using ll = long long;
using namespace std;

const long long MOD = 1000000007;
const ll LINF = 1LL << 50;


int main() {
  int N;
  cin >> N;
  vector<int> AN(N);
  REP(n,N) cin >> AN[n];

  int dist = 100000000;
  int ans = 100000000;
  for (int num = -100; num <= 100; num++){
    int tmp = 0;
    REP(n,N) tmp += (AN[n]-num)*(AN[n]-num);
    if (tmp < dist){
      dist = tmp;
      ans = num;
    }
  }

  cout << dist << endl;
}


Measured memory_bytes: 3552
import java.util.*;
import java.math.*;

class Main {
  public static void main(String[] args){
  Scanner stdIn = new Scanner(System.in);
  int n = stdIn.nextInt();
  int[] v = new int[n];
  int[] c = new int[n];
  int count = 0;
  for(int i = 0;i<n;i++) {
    v[i] = stdIn.nextInt();
  }
  for(int i = 0;i<n;i++) {
    c[i] = stdIn.nextInt();
  }
  for(int i = 0;i<n;i++) {
    int k = v[i] - c[i];
    if(k>0) count += k;
  }
  System.out.println(count);
}
}

Measured memory_bytes: 21844
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = Counter(A)

cnt = 0
for i in set(A):
  I = C[i]
  if I == i:
    continue
  elif I > i:
    cnt += I - i
  else :
    cnt += I
  
print(cnt)

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

using namespace std;

int main() {
  int d, n;

  cin >> d >> n;

  if(d==0){
    if(n==100){
      cout<<101<<endl;
      return 0;
    }
    cout<<n<<endl;
    return 0;
  }

  if(d==1){
    if(n==100){
      cout<<10100<<endl;
      return 0;      
    }
    cout<<n*100<<endl;
    return 0;
  }
  if(d==2){
    if(n==100){
      cout<<1010000<<endl;
      return 0;      
    }
    cout<<n*10000<<endl;
    return 0;
  }
  
}


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

int main(){
    int k, s;
    cin >> k >> s;

    long long ans = 0;

    for(int x = 0; x <= k; x++){
        // 枝狩り
        if(x > s || s-x > 2*k)  continue;
        for(int y = 0; y <= k; y++){
            int z = s-x-y;
            if(0 <= z && z <= k)    ans++;
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int n;
int a,b;
int i;
scanf("%d%d%d", &n, &a, &b);
int res[3] = {0};
for(i = 0; i < n; i++){
int s;
scanf("%d", &s);
if(s<=a){
res[0]++;
}else if(s>=b+1){
res[2]++;
}else{
res[1]++;
}
}
int min = res[0];
for(i = 1; i<3;i++){
   if(res[i] <min){
    min = res[i];
}
}
printf("%d",min);
}

Measured memory_bytes: 128
//解説あり
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <stack>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int) (v).size()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int h, w, k, ans = 1000000000;
char s[15][1005];
int a[15][1005];

int main(void) {
  cin >> h >> w >> k;
  rep(i, 0, h) scanf("%s", s[i]);
  rep(i, 0, h) rep(j, 0, w) if (s[i][j] == '1') a[i][j+1] = 1;
  
  rep(i, 0, h) rep(j, 1, w+1) a[i][j] += a[i][j-1];
  
  for(int S=0; S<(1<<(h-1)); S++) {
    int c = 0, s = 0;
    rep(i, 1, w+1) {
      int sum = 0, sum_line = 0;
      rep(j, 0, h) {
        sum += a[j][i] - a[j][s];
        sum_line += a[j][i] - a[j][i-1];
        if (sum_line>k) c = 1000000000;
        if (sum>k) {
          c++;
          sum = sum_line =0;
          s = i-1;
          break;
        }
        if ((S>>j) & 1) sum = sum_line = 0;
      }
    }
    //for (int i=0; i<h-1; i++) if ((S>>i)&1) c++;
    c += __builtin_popcount(S);
    ans = min(ans, c);
  
  }
  
  
  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int>a(Q);
  for(int i=0;i<Q;i++){
    cin >> a[i];
  }
  
  vector<int>b(N,K);
  for(int i=0;i<Q;i++){
    b[a[i] - 1]++;
  }
  
  
  for(int i=0;i<N;i++){
    if(b[i] > Q) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}

    
  

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;


int main() {
    char s[5];
    cin>>s;
    bool can=false;
    if(s[0]!=s[1]&&s[2]!=s[1]&&s[3]!=s[2]){
        can=true;
    }

    if(can){
        cout<<"Good"<<endl;
    }else{
        cout<<"Bad"<<endl;
    }


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  int ans=0;
  for(int i=0;i<n;i++)
  {
      cin>>a[i];
      ans=ans^a[i];
  }
   for(int i=0;i<n;i++)
      {
        a[i]=ans^a[i];
        cout<<a[i]<<" ";
      } 
      cout<<endl;
  return 0;
}

Measured memory_bytes: 4404
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template <class T>inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}

int main()
{
    int n,m;
    ll k;
    cin >> n >> m >> k;
    vector<ll> a_;
    vector<ll> b_;
    ll tmp=0;
    REP(i,n){
        int a;
        cin >> a;
        if(tmp>k){
            continue;
        }
        tmp+=a;
        if(tmp<=k){
            a_.push_back(tmp);
        }
    }
    tmp=0;
    REP(i,m){
        int b;
        cin >> b;
        if (tmp > k)
        {
            continue;
        }
        tmp += b;
        if (tmp <= k)
        {
            b_.push_back(tmp);
        }
    }
    ll ans=0;
    if(a_.size()==0){
        cout << b_.size() << endl;
        return 0;
    }
    if(b_.size()==0){
        cout << a_.size() << endl;
        return 0;
    }
    int b = 0;
    IREP(i,a_.size()){
        if(a_[i]+b_[b]<=k){
            if (b == b_.size() - 1)
            {
                ans = max(ans, i + 1 + b+1);
                continue;
            }
            b++;
            i++;
        }
        else
        {
            ans = max(ans, i + 1 + b);
        }
    }
    int a=0;
    IREP(i, b_.size())
    {
        if (a_[a] + b_[i] <= k)
        {
            if(a==a_.size()-1){
                ans = max(ans, i + 1 + a+1);
                continue;
            }
            a++;
            i++;
        }
        else
        {
            ans = max(ans, i + 1 + a);
        }
    }
    cout << ans << endl;
}


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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

const int mod = 1000000007;
struct mint {
    long long x;
    mint(long long x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(long long t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    int N;
    cin >> N;
    vector<int> A(N, 0);
    rep(i, N) cin >> A[i];

    mint cnt = 1;
    vector<int> state{0, 0, 0};

    for (int i = 0; i < N; i++) {
        mint c = 0;
        for (int j = 0; j < 3; j++) {
            if (state[j] == A[i]) c += 1;
        }

        cnt *= c;

        for (int j = 0; j < 3; j++) {
            if (state[j] == A[i]) {
                state[j] += 1;
                break;
            }
        }

        // d(A[i]);
        // d(cnt.x);
        // dump(state);
    }

    cout << cnt.x << endl;
    return 0;
}


Measured memory_bytes: 3704