akhauriyash/Code-Regression huggingface dataset:
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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;}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    ll sum = 0;
    rep(i,2,n)sum ^= a[i];
    debug(sum);
    ll d = a[0] + a[1];
    if((d + sum) & 1){
        cout << -1 << "\n";
        return 0;
    }
    ll x = (d - sum) / 2;
    ll ans = x;
    const ll LOG = 64;
    if((x & sum) != 0){
        debug(x, sum);
        cout << -1 << "\n";
        return 0;
    }
    rrep(i, LOG, 0){
        if((sum >> i) & 1){
            if((ans | (1LL << i)) <= a[0])ans |= (1LL << i);
        }
    }
    debug(x, ans);
    cout << ((a[0] >= ans && ans > 0) ? a[0] - ans : -1) << "\n";
}

Measured memory_bytes: 3572
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 20000


int main(){
	char a[N + 1];
	char b[N + 1];
	char c[N + 1];
	f(i, N + 1)a[i] = 0;
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	scanf("%s", a);
	scanf("%s", b);
	scanf("%s", c);
  ans=0;
	f(i, n){
		if (a[i] == b[i] && a[i] == c[i])continue;
		else if (a[i] == b[i])ans++;
		else if (a[i] == c[i])ans++;
		else if (c[i] == b[i])ans++;
		else ans += 2;
	}
	printf("%lld\n", ans);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

ll modmul(ll a, ll b) {
    ll res = (a % DIV) * (b % DIV);
    return res % DIV;
}

ll modeadd(ll a, ll b) {
    ll res = (a % DIV) + (b % DIV);
    return res % DIV;
}
int main() {
    ll N, S; cin >> N >> S;
    vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(S + 1, vector<ll>(3)));
    vector<int> a(N); for (int i = 0; i < N; i++) cin >> a[i];
    dp[0][0][0] = 1;
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j <= S; j++) {
            dp[i + 1][j][0] += dp[i][j][0];
            dp[i + 1][j][0] %= DIV;
            if (j + a[i] < S) {
                dp[i + 1][j + a[i]][1] += modmul(i + 1, dp[i][j][0]);
                dp[i + 1][j + a[i]][1] %= DIV;
            }
            else if (j + a[i] == S) {
                dp[i + 1][j + a[i]][2] += modmul(modmul(i + 1, N - i), dp[i][j][0]);
                dp[i + 1][j + a[i]][2] %= DIV;
            }

            dp[i + 1][j][1] += dp[i][j][1];
            if (j + a[i] < S) {
                dp[i + 1][j + a[i]][1] += dp[i][j][1];
                dp[i + 1][j + a[i]][1] %= DIV;
            }
            else if (j + a[i] == S) {
                dp[i + 1][j + a[i]][2] += modmul(N - i, dp[i][j][1]);
                dp[i + 1][j + a[i]][2] %= DIV;
            }

            dp[i + 1][j][2] += dp[i][j][2];
            dp[i + 1][j][2] %= DIV;

        }
    }
    cout << dp[N][S][2] << endl;
}


Measured memory_bytes: 493056
#include<stdio.h>
int main(void){
  char s[3];
  int i,aa=0,bb=0,cc=0;
  scanf("%s",s);
  for(i=0;i<3;i++){
    if(s[i]=='a') aa++;
    if(s[i]=='b') bb++;
    if(s[i]=='c') cc++;    
  }
  if(aa==1&&bb==1&&cc==1)
    printf("Yes");
  else printf("No");
  return 0;
}

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

int main(){
	
	int n; cin>>n;
	vector<pair<int,int>> a(n);
	for(int i=0; i<n; i++){
		int a0; cin >> a0;
		a.at(i) = {a0,i};
		
	}
	sort(a.begin(),a.end());
	for(auto i:a) cout << i.second+1 << endl;
	
}

Measured memory_bytes: 1664
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  unless (n == 0) $ do
    solve <$> replicateM n f >>= mapM_ putStrLn
    main
  where
    f = g <$> getLine
    g s = let (as, bs) = break (/= '.') s
              l = length as
          in (l, if l == 0 then s else replicate (l - 1) ' ' ++ '+':bs)

solve :: [(Int, String)] -> [String]
solve ss = f [] ss
  where
    f st [] = map snd . reverse $ st
    f st ((i,x):xs) = let (as, bs) = span (\(j, _) -> i < j) st
                      in if null as
                         then f ((i,x):st) xs
                         else f ((i,x):(map (\(u, v) -> (u, insPipe i v)) as ++ bs)) xs

insPipe :: Int -> String -> String
insPipe i s = let (as, (_:bs)) = splitAt (i - 1) s
              in as ++ '|':bs



Measured memory_bytes: 63520
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#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 trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
ll gcd(ll a, ll b){return (b == 0 ? a : gcd(b, a%b));}
ll exp(ll a,ll b,ll m){
    if(b==0LL) return 1LL;
    if(b==1LL) return mod(a,m);
    ll k = mod(exp(a,b/2,m),m);
    if(b&1LL){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
 
}

const int MAXN = 200100;

int get(char c){
  if(c=='R')return 0;
  if(c=='G')return 1;
  return 2;
}
int s[MAXN];
int pre[MAXN][3];
int32_t main(){
  fastio;
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    char c;
    cin>>c;
    s[i] = get(c);
    for(int j=0;j<3;j++)pre[i][j]= pre[i-1][j];
      pre[i][s[i]]++;
  }

  int res=0;
  for(int i=1;i<=n;i++){
      for(int j=2;j<i;j++){
        // um cara em (qq,j,i);
        if(s[i]==s[j])continue;
        res+=pre[j-1][3-s[i]-s[j]];
        if(2*j-i>0 && s[2*j - i]==3-s[i]-s[j])res--;
      }
  }
  cout<<res<<endl;
  // Math -> gcd it all // chack MAXN // check ll
  //did you check N=1? Did you mix up N,M?
}

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


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

using namespace std;

const int N=110;
const int inf=1e6+100;
int vis[N];
char s[N];
struct node
{
    int cnt,low,high;
}S[N];
bool cmp(node n1,node n2)
{
    return n1.cnt>n2.cnt;
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",s);
        int len=strlen(s);
        S[i].low=inf;
        for(int j=0;j<len;j++)
        {
            if(s[j]=='(') S[i].cnt++;else S[i].cnt--;
            S[i].low=min(S[i].low,S[i].cnt);
            S[i].high=S[i].cnt-S[i].low;
        }
    }
    int now=0,flag=1;
    sort(S+1,S+1+n,cmp);
    int p=1;
    for(;p<=n&&S[p].cnt>0;p++);
    S[0].high=-inf,S[0].low=-inf;
    for(int i=1;i<p;i++)
    {
        int ff=0,tt=0;
        for(int j=1;j<p;j++)
        {
            if(!vis[j]&&(S[j].low+now>=0))
            {
                ff=1;
                if(S[j].low>S[tt].low)
                {
                    tt=j;
                }
            }
        }
        if(!ff)
        {
            printf("No\n");
            return 0;
        }
        vis[tt]=1;
        now+=S[tt].cnt;
    }
    for(int i=p;i<=n;i++)
    {
        int ff=0,tt=0;
        for(int j=p;j<=n;j++)
        {
            if(!vis[j]&&(S[j].low+now>=0))
            {
                ff=1;
                if(S[j].high>S[tt].high)
                {
                    tt=j;
                }
            }
        }
        if(!ff)
        {
            printf("No\n");
            return 0;
        }
        vis[tt]=1;
        now+=S[tt].cnt;
    }
    if(now==0) printf("Yes\n");else printf("No\n");
    return 0;
}

Measured memory_bytes: 3152
import numpy as np

N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = np.array([tuple(map(int, input().split())) for _ in range(N)])

cnt = 0
for i in range(N):
    if sum(B * A[i]) + C > 0:
        cnt += 1
print(cnt)



Measured memory_bytes: 27136
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");

  //   String nyu=sc.nextLine();
//int[] num=new int[6];
int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);
//int C=Integer.parseInt(nyu[2]);


if(B%A==0){

System.out.println(A+B) ;
}else{
System.out.println(B-A) ;

}
	}
}

Measured memory_bytes: 23764
import sys
def input():
    return sys.stdin.readline()[:-1]
M,D = map(int,input().split(' '))

cnt = 0
for i in range(1,M+1):
    for j in range(1,D+1):
        dd = j // 10
        d  = j % 10
        if dd>=2 and d>=2 and d*dd==i:
            cnt += 1
print(cnt)

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

int main()
{
  int n;
  string s;
  cin >> n >> s;
  reverse(begin(s), end(s));
  
  int lb = 0, ub = s.size() / 3 + 10;
  while (ub - lb > 1){
    int md = (lb + ub) / 2;
    int ci = 0, cio = 0, cioi = 0;
    for (int i = 0; i < s.size(); i++){
      if (s[i] == 'I'){
        if (ci + cio + cioi < md) ci++;
        else if (cio > 0) cio--, cioi++;
      }
      else if (s[i] == 'O'){
        if (ci > 0) ci--, cio++;
      }
      else if (s[i] == 'J'){
        if (cio > 0) cio--, cioi++;
      }
    }
    (cioi >= md ? lb : ub) = md;
  }
  
  cout << lb << endl;
}

Measured memory_bytes: 3980
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    s=[chomp(readline()) for i in 1:n]
    println(length(collect(Set(s))))
end
main()

Measured memory_bytes: 193312
n=int(input())
a=list(map(int,input().split()))
sum=[0,]*n
sum[0]=a[0]
min=5000000000
for i in range(1,n):
    sum[i]=a[i]+sum[i-1]
fin=sum[n-1]
sub=[0,]*n
for i in range(0,n):
    sub[i]=fin-sum[i]
for i in range(0,n-1):
    if abs(sub[i]-sum[i]) < min:
        min = abs(sub[i]-sum[i])
print(str(min))

Measured memory_bytes: 28712
/*
	Created by : imay_10
	" It won't be EASY, but I'll make it "
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
const int mod = 1e9+7;
const ll inf = 1e18;
const double pi = 3.1415926535897932384626;

// Utility for fast exponentiation
ll mpow(ll a,ll b,ll m){
    ll res=1;
    //a%=m;
    while(b){
    	if(b%2) res=res*a%m;
		a=a*a%m;
		b/=2;
	}
	return res;
}

// Utility for GCD Calculation
ll gcd(ll a,ll b){
	if(b==0) return a;
	return gcd(b,a%b);
}

void solve(){
	//code
	int n;
	cin>>n;
	if(n>=30) cout<<"Yes";
	else cout<<"No";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	solve();
 	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n;
  cin>>n;
  string s;
  cin>>s;
  string s1,s2;
  int i;
  for(i=0;i<n/2;i++){
  	s1=s1+s[i];
  	
  }
  for(i=n/2;i<n;i++){
  	s2=s2+s[i];
  }
  
  string f1=s1+s1;
  string f2=s2+s2;
  if(f1==s){
  	cout<<"Yes"<<endl;
  }
  
  else if(f2==s){
  	cout<<"Yes"<<endl;
  	
  }
  
  else{
  	cout<<"No"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3652
n,k=map(int,input().split())
v=[int(i) for i in input().split()]
ans=[]

for i in range(min(n,k)+1):
    for j in range(min(n,k)-i+1):
        d=k-i-j
        l=v[0:i]
        r=v[n-j:n]
        p=r+l
        q=[]
        s=sum(p)
        for x in p:
            if x<0:
                q.append(x)
        q.sort()
        for x in range(min(len(q),d)):
            s-=q[x]
        ans.append(s)
        
print(max(ans))






Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

class union_find {
	private :
		vector<u64> roots;

	public :
		union_find(const u64 numel) {
			roots.resize(numel);
			iota(roots.begin(), roots.end(), 0);
		}

		u64 root(u64 x) {
			if(roots[x] != x) {
				roots[x] = root(roots[x]);
			}
			return  roots[x];
		}

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

		void unite(u64 x, u64 y) { 
			x = root(x);
			y = root(y);
			if (x != y) {
                roots[x] = y;
            };


		}
};

int main() {
	u64 N, M;
	cin >> N >> M;

    union_find friends(N);

    for(u64 i=0; i<M; i++){
        u64 A, B;
        cin >> A >> B;
        A--; B--;

        friends.unite(A, B);
    }
    
    vector<u64> num_friends(N);
    for(u64 i=0; i<N; i++) {
        num_friends[friends.root(i)]++;
    }

    u64 ans = *max_element(num_friends.begin(), num_friends.end());

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


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

struct SP
{
  string S;
  int P;
  int idx;
};

int main()
{
  int N;
  cin >> N;
  vector<SP> _sp(N);
  auto * const sp = &_sp[0];
  for (int i = 0; i < N; ++i)
  {
    cin >> sp[i].S >> sp[i].P;
    sp[i].idx = i + 1;
  }
  sort(sp, sp + N, [](const SP & lhs, const SP & rhs){
    if (lhs.S < rhs.S)
      return true;
    else if (lhs.S == rhs.S)
      return lhs.P > rhs.P;
    else
      return false;
  });
  for (auto x : _sp)
    cout << x.idx << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

		int N = scanner.nextInt();
		int Weight[] = new int[N];
		int S1 = 0;
		int S2 = 0;
		int Number = 0;
		int data[] = new int[N];
		for (int i = 0;i < N; i++) {
			int x = scanner.nextInt();
			Weight[i] = x;
		}

		for (int i = 0; i < N; i++) {
			S1 = 0;
			for (int j = 0; j < i; j++) {
				S1 += Weight[j];
			}
			S2 = 0;
			for (int k = i; k < N; k++) {
				//System.out.println("どうかな" + Weight[k]);
				S2 += Weight[k];
				//System.out.println("1個ずつ" + S2);
			}
			// 			System.out.println("S1は" + S1);
			// 			System.out.println("S2は" + S2);
			if (S2 - S1 >= 0) {
				Number = S2 - S1;
			} else {
				Number = S1 - S2;
			}
			data[i] = Number;
			// 			System.out.println(data[i]);
		}

		//		for (int i=0; i<data.length; i++) {
		//			if (min > data[i]) {	//現在の最小値よりも小さい値が出たら
		//				min = data[i];	//変数minに値を入れ替える
		//			}
		//		}
		//		System.out.println(min);
		// 最小値を求める
		int min = data[0];
		for(int i = 0; i < data.length; i++)
			min = Math.min(min,data[i]);
		System.out.println(min);
	}
}

Measured memory_bytes: 22732
#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<ll>ans;
void dfs(ll step , ll dig , ll now , bool zero)
{
	if(step == 0){
        if(now == 0) return ;
    	ans.push_back(now);
      	return ;
    }
    if(zero){
        for (int i = 0 ; i <= 9 ; i++){
            dfs(step - 1 , i , now * 10 + i , i == 0);
        }
        return ;
    }

	if(dig != 0) dfs(step - 1 , dig - 1 , now * 10 + dig - 1 , zero);
  	if(dig != 9) dfs(step - 1 , dig + 1 , now * 10 + dig + 1 , zero);
  	dfs(step - 1 , dig , now * 10 + dig , zero);
  //	cout << " 现在在第 " << step << "层 , 现在的数字是" << dig << " 现在的总值为" << now << endl;
 	return ;
}
int main()
{
	for (int i = 0; i <= 3 ; i++){
    	dfs(9 , i , i , i == 0);
    }
	sort(ans.begin() , ans.end() );
	ll k; cin >> k;
  	cout << ans[k - 1] << endl;

}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define ll long long
#define str string
#define sonic ios_base::sync_with_stdio(0)
using namespace std;
int main(){
	sonic;
	ll n,m,cnt=0;
	cin>>n>>m;
	ll  a[n];
	for(ll i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]>=m){
			cnt++;
		}
	}
	cout<<cnt;
}

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

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

  if(abs(a-x)>abs(b-x)){
    cout << 'B' << endl;
  }
  else{
    cout << 'A' << endl;
  }

return 0;  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>

int q;
long long int a, b;

int main(){
	scanf("%d", &q);
	for(int i=0; i<q; ++i){
		scanf("%lld %lld", &a, &b);
		if(a > b) std::swap(a, b);
		long long int t = (long long int)(std::sqrt(a*b) - 1e-6);
		long long int ans = 2 * t;
		if(t != 0 && t == a * b / t) --ans;
		if(a <= t) --ans;
		if(t*(t+1) == a*b) --ans;
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 128
w,h,n=map(int,input().split())

max_x=w
min_x=0
max_y=h
min_y=0
for i in range(n):
    x,y,a=map(int,input().split())
    if a==1:
        min_x=max(x,min_x)
    if a==2:
        max_x=min(x,max_x)
    if a==3:
        min_y=max(y,min_y)
    if a==4:
        max_y=min(y,max_y)
wid=max_x-min_x if max_x>=min_x else 0
hei=max_y-min_y if max_y>=min_y else 0
print(wid*hei)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  int ans = 1 << 30;
  int p[4], t[4];
  for (int i = 0; i < 4; i++) {
    cin >> p[i];
  }
  for (int i = 0 ;i < 4; i++) {
    cin >> t[i];
  }
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      for (int k = 0; k <= 100; k++) {
        for (int l = 0; l <= 100; l++) {
          if (t[0] * i + t[1] * j + t[2] * k + t[3] * l < n) continue;
          ans = min(ans, p[0] * i + p[1] * j + p[2] * k + p[3] * l);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3152
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}


//for(int i = ; i < ; i++){}

int main(){
  string s;
  cin>>s;
  int a[26];
  for(int i = 0; i < 26; i++) a[i]=0;
  for(int i = 0; i < s.length(); i++){
    a[s[i]-'a']++;
  }
  int ans=100;
  for(int i = 0; i < 26; i++){
    if(a[i]==0) {
      ans=i;
      break;
    }
  }
  if(ans == 100) cout<<"None"<<endl;
  else cout<<(char)('a'+ans)<<endl;
  return 0;
}




Measured memory_bytes: 512
N,K=map(int,input().split())
A=list(map(int,input().split()))
N1=0
N2=0
for i in range(N):
  for j in range(N):
    if(i<j and A[i]>A[j]):
      N1+=1
    if(A[i]>A[j]):
      N2+=1
print((N1*K+K*(K-1)//2*N2)%(10**9+7))

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNING

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
char in[100010];
int main()
{
	int n,i,j,sum=0;char pr;
	scanf("%d%c%s",&n,&in[0],in);
	pr=in[0];sum+=1;
	for(i=1;i<n;i++)
	{
		if(in[i]!=pr)
		{
			sum+=1;
			pr=in[i];
		}
	}
	printf("%d\n",sum);
	return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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,k;cin>>n>>k;
  cout<<(n+k-3)/(k-1);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
long long N, W;
std::vector<long long> w, v;
std::vector<std::vector<long long>> dp;//dp[i][j]はi番目以降から重さがj以下となるように選んだときの価値
long long rec(int i, int j){
    long long res;
    if(dp[i][j] >= 0) return dp[i][j];
    if(i == N) res = 0;
    else if(j < w[i]) res = rec(i + 1, j);
    else{
        res = std::max(rec(i + 1, j), rec(i + 1, j - w[i]) + v[i]);
    }
    dp[i][j] = res;
    return dp[i][j];
}
int main(){
    std::cin >> N >> W;
    w.resize(N);
    v.resize(N);
    dp.resize(N + 1, std::vector<long long>(W + 1, -1));
    for(int i = 0; i < N; i++) std::cin >> w[i] >> v[i];
    std::cout << rec(0, W) << std::endl;
}

Measured memory_bytes: 80256
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))

d = []
for i in range(m - 1):
  d.append(x[i+1] - x[i])
d.sort()

ans = 0
for i in range(m - n):
  ans += d[i]
  
print(ans)

Measured memory_bytes: 13960
using System;

namespace C___Walk_on_Multiplication_Table
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var min = N - 1;

            for (long i = 1; i <= Math.Ceiling(Math.Sqrt(N)); i++)
                if (N % i == 0)
                    min = Math.Min(min, (i - 1) + (N / i - 1));

            Console.WriteLine(min);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define faster_io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define mem(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define ll long long
#define pb push_back
#define pll pair<ll, ll>
using namespace std;
const ll N = 1e6 + 7, M = 1e5 + 7, mod = 1e9 + 7, inf = 1e18 + 7;
ll tc, n, m, q, a, b, c, d, i, j, k, l, sum, cnt;
ll ar[N];
string s;
vector < ll > vec;

int main()
{
    cin >> n >> m;
    if(n < m)
        swap(n, m);
    for(i = 1; i <= n; i++)
        cout << m;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define INF 1000000
using namespace std;
string odd = "", even = "";
int cnt = 0;
string S,T;
void check_odd(int s_pos, int t_pos)
{
	bool tmp_flag = false;
	for(int i=t_pos; i<T.size(); i++)
	{
		if(s_pos >= odd.size()) break;
		if(odd[s_pos] != T[i]) continue;
		s_pos++;
		t_pos = i+1;
		cnt++;
		tmp_flag = true;
		break;
	}
	if(tmp_flag) check_odd(s_pos, t_pos);
}
void check_even(int s_pos, int t_pos)
{
	bool tmp_flag = false;
	for(int i=t_pos; i<T.size(); i++)
	{
		if(s_pos >= even.size()) break;
		if(even[s_pos] != T[i]) continue;
		s_pos++;
		t_pos = i+1;
		cnt++;
		tmp_flag = true;
		break;
	}
	if(tmp_flag) check_even(s_pos, t_pos);
}
int main()
{
	cin >> S >> T;
	rep(i, S.size())
	{
		if(i % 2) odd += S[i];
		else even += S[i];
	}
	bool flag = false;
	check_odd(0,0);
	if(cnt == odd.size()) flag = true;
	cnt = 0;
	check_even(0,0);
	if(cnt == even.size()) flag = true;
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;	
	
	return 0;
}



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

int main()
{
    std::string s,t;
    std::cin >> s >> t;

    for (int i = 0; i < s.length(); i++) {
       if (s[i] != t[i]) {
           std::cout << "No" << std::endl;
           return 0;
       }
    }
    std::cout << "Yes" << std::endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cleaner codes please <3
//fresh start
//4/26/2020

int main(){
int days,assg,sum=0;
cin>>days>>assg;
for(int i=0;i<assg;i++){
    int n;
    cin>>n;
    sum+=n;
}
if(sum>days)cout<<-1;
else{
    cout<<days-sum;
}

    return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<ll,int>;
using graph = vector<vector<P>>;
template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define endl "\n"
#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
vector<ll> divisor(ll n){
  vector<ll> list;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  
  vector<ll> divs = divisor(n);
  sort(ALL(divs));

  int len = (int)divs.size();
  ll res = 0;
  REP(i,len){
    if(divs[i]*(divs[i]+1) >= n){
      break;
    }else{
      res += (n-divs[i])/divs[i];
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3656
n, m = map(int, input().split())
a = [list(map(int, input().split())) for i in range(n)]
b = [int(input()) for i in range(m)]
for i in range(n):
    c = 0
    for j in range(m):
        c += a[i][j] * b[j]
    print(c)


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

int main()
{
  char c;
  cin >> c;
  if(c == 'A') cout << 'T' << endl;
  else if(c == 'T') cout << 'A' << endl;
  else if(c == 'G') cout << 'C' << endl;
  else cout << 'G' << endl;
  return 0;
}


Measured memory_bytes: 3676
{-# LANGUAGE ScopedTypeVariables #-}

import           Control.Applicative
import           Data.Functor
import           Text.Printf

main :: IO ()
main = do
  [x,y] :: [Int] <- fmap read . words <$> getLine
  if x == 0 && y == 0
    then pure ()
    else do
    if x > y
      then printf "%d %d\n" y x
      else printf "%d %d\n" x y
    main



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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 1e9 + 9;
const ll linf  = 1ll * inf * inf;
const int N = 500000 + 7;
const int M = 30;
const int multipleTest = 0;
const double pi = acos(-1);

int n, a[N];

void solve() {
    cin >> n;
    rep(i, 0, n) cin >> a[i];
    sort(a, a + n);
    int mx = a[n - 1];

    int best = -inf;

    rep(i, 0, n - 1) {
        if (mx & 1) {
            if (abs(a[i] * 2ll - mx) < abs(best * 2ll - mx)) {
                best = a[i];
            }
        } else {
            if (abs(a[i] - mx / 2) < abs(best - mx / 2)) {
                best = a[i];
            }
        }
    }

    cout << mx << ' ' << best << '\n';
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
#endif
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    for(int i = 0; i < Test; ++i) {
        //		printf("Case #%d: ", i + 1);
        solve();
    }
#ifdef _LOCAL_
    cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<string>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<math.h>
#include<utility>
using namespace std;

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

    if(a > b){
        cout << "a > b" << endl;
    } else if(a < b){
        cout << "a < b" << endl;
    } else {
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC(T, v) static_cast<T>(v)
#define SI(v) SC(int, v.size())
#define SL(v) SC( LL, v.size())
#define RF(e, v) for(auto & e: v)
#define ei else if
#define UR assert(false)

// ---- ----

int n, m, a[20][20], b[20], c;

int main() {
	cin >> n >> m >> c;
	inc(j, m) { cin >> b[j]; }
	
	inc(i, n) {
	inc(j, m) {
		cin >> a[i][j];
	}
	}
	
	int ans = 0;
	inc(i, n) {
		int s = c;
		inc(j, m) { s += a[i][j] * b[j]; }
		if(s > 0) { ans++; }
	}
	
	cout << ans << endl;
	
	return 0;
}


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

void circumcenter(double x1, double y1, double x2, double y2, double x3,
                  double y3, double &cx, double &cy) {
  double a1, b1, c1, a2, b2, c2;
  a1 = x2 - x1;
  b1 = y2 - y1;
  c1 = x2 * x2 - x1 * x1 + y2 * y2 - y1 * y1;
  a2 = x3 - x2;
  b2 = y3 - y2;
  c2 = x3 * x3 - x2 * x2 + y3 * y3 - y2 * y2;
  cx = (b2 * c1 - b1 * c2) / (2.0 * (a1 * b2 - a2 * b1));
  cy = (a1 * c2 - a2 * c1) / (2.0 * (a1 * b2 - a2 * b1));
}

int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;++i){
        double x1, y1, x2, y2, x3, y3;
        cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        double px, py, r;
        circumcenter(x1,y1,x2,y2,x3,y3,px,py);
        r = sqrt((px-x1)*(px-x1) + (py-y1)*(py-y1));
        printf("%.3f %.3f %.3f\n",px,py,r);
    }

    return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int a,b;
char mp[105][105];
int main(){
	cin>>a>>b;
	for(int i=1;i<=50;i++){
		for(int j=1;j<=100;j++){
			mp[i][j]='.';
		}
	}
	for(int i=51;i<=100;i++){
		for(int j=1;j<=100;j++){
			mp[i][j]='#';
		}
	}
	a--;b--;
	for(int i=1;i<=49&&b;i+=2){
		for(int j=1;j<=100&&b;j++){
			if(mp[i-1][j]!='#'&&mp[i][j-1]!='#'){
				mp[i][j]='#';b--;
			}
		}
	}
	for(int i=52;i<=100&&a;i+=2){
		for(int j=1;j<=100&&a;j++){
			if(mp[i-1][j]!='.'&&mp[i][j-1]!='.'){
				mp[i][j]='.';a--;
			}
		}
	}
	puts("100 100");
	for(int i=1;i<=100;i++){
		puts(mp[i]+1);
	}
	return 0;
}


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

using llint = long long int;

struct Cake
{
    llint x, y, z;
    llint total() const { return x + y + z; }
};

llint accume(std::vector<Cake>& cakes, int M)
{
    std::partial_sort(cakes.begin(), cakes.begin() + M, cakes.end(),
                      [](const Cake& lhs, const Cake& rhs){ return lhs.total() > rhs.total(); });
    llint val = 0;
    for (int i = 0; i < M; ++i)
        val += cakes[i].total();
    return val;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    int N, M;
    std::cin >> N >> M;
    std::vector<Cake> cakes;
    cakes.resize(N);
    for (int i = 0; i < N; ++i) {
        Cake& cake = cakes[i];
        std::cin >> cake.x >> cake.y >> cake.z;
    }
    llint max = 0, tmp;
    int x = 2;
    while (x--) {
        int y = 2;
        while (y--) {
            int z = 2;
            while (z--) {
                tmp = accume(cakes, M);
                if (tmp > max) max = tmp;
                std::for_each(cakes.begin(), cakes.end(), [](Cake& cake) { cake.z *= -1; });
            }
            std::for_each(cakes.begin(), cakes.end(), [](Cake& cake) { cake.y *= -1; });
        }
        std::for_each(cakes.begin(), cakes.end(), [](Cake& cake) { cake.x *= -1; });
    }
    std::cout << max << std::endl;
    return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b,c,x,y;
	cin >> a >> b >> c >> x >> y;
	ll ans = 0;
	if(a + b > 2 * c){
		int abBuy = min(x,y);
		ans += 2 * c * abBuy;
		x -= abBuy;
		y -= abBuy;
	}
	if(x > 0){
		if(a > 2 * c){
			ans += 2 * c * x;
		}else{
			ans += a * x;
		}
	}
	if(y > 0){
		if(b > 2 * c){
			ans += 2 * c * y;
		}else{
			ans += b * y;
		}
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>

using namespace std;

int
main()
{
        string S;

        cin >> S;
        int array[26];
        memset(array, 0, sizeof(int) * 26);

        for(int i = 0; i < S.size(); i++) {
                int j = int(S[i]) - int('a');
                if(array[j] == 0) {
                        array[j] = 1;
                }
        }

        for(int i = 0; i < 26; i++) {
                if (array[i] == 0) {
                        char ans;
                        ans = i + 'a';
                        cout << ans << endl;
                        return 0;
                }
        }
        cout << "None" << endl;

}

Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
  int price;
  int have;
  int a;
  int b;
  int c;
  int m;
  int n;
  int x;
  while(1)
    {
      scanf("%d %d", &price, &have);
      
      x = have - price;
      
      a = x / 1000;
      m = x % 1000;
      b = m / 500;
      n = m % 500;
      c = n / 100;
      

      
      if(price == 0 && have == 0)
	{
	  break;
	}
      printf("%d %d %d\n",c,b,a);

    }
      
      return 0;
}

Measured memory_bytes: 600
/*----------------by syr----------------*/
/*

         iii                  ii
     rBQBBBBBBE       BBR iBBBBQBBL     XBBBBBBQBBBBB
   iBBQJ    7BBB      BBsSBBr   BBQ      i      cBBB
  rBBU       iBBw     BBBQi     HBBi           KBBi
  BBH         BB5    iBBB       isL          wBB5
 GBB         iBBi    6BB                   iBBB
 BBQ         BQB     BBD                  QBBi
 BBB        BQB     iQBi                1BBv
 sBBg     wBBB      QBB               iBBB
  7BBBBBBBBBi       BBR              wBBBBBBBBBBBBB
     irvi           ii               ii    i i iii
                i5U
               BBB
               BB7
              1BB
      iPBBBBBKBBR    JBR1       rQBO   BR  UBQP  iBBQi
    7BBBGs7sXBBBi     QBBr     gBBE   rBB BB2BB7HBZQBB
   QBBi      sBQ       BBB   iBBB     SQBBR  BBBB  cBQ
  gBQ        BBg        BBB KBBi      MBBH   BBB   BBs
 iBBv       iBBi         QBBBL        BBR   pBB   iBB
 pBB        BBB         iBBBB        iBB    BBL   KBB
 MBB       BBBR        BBB JBBi      DBR   iBQ    BBL
 GBB     7BBBB2      PBBH   BBBi     BQr   DBB   iBB
  BQBXwgBBP BB7    1BBB      BBQ7   1BB    BBc   BBB
   2BBBBw   BB    EBBS        QBBi  HBa   iBB    BB7
*/
#include<bits/stdc++.h>

using namespace std;

#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;

int n, m;
int a[maxn];
ll ans;
ll f[maxn], g[maxn];

void add(ll *arr, int l, int r, int k){
	if(l > r)
		return;
	arr[l] += k;
	arr[r + 1] -= k;
	return;
}

int main(){
	scanf("%d%d", &n, &m);
	FOR(i, 0, n){
		scanf("%d", a + i);
		if(!i)
			continue;
		int x = a[i - 1], y = a[i];
		if(x <= y){
			add(f, x + 1, y, - x - 1);
			add(g, x + 1, y, 1);
		}else{
			add(f, x + 1, m, - x - 1);
			add(g, x + 1, m, 1);
			add(f, 1, y, m - x - 1);
			add(g, 1, y, 1);
		}
	}
	REP(i, 1, m){
		f[i] += f[i - 1];
		g[i] += g[i - 1];
	}
	REP(i, 1, m){
		ans = max(ans, f[i] + i * g[i]);
	}
	ans = -ans;
	ll res = 0;
	FOR(i, 1, n){
		int x = a[i - 1], y = a[i];
		if(x <= y)
			ans += y - x;
		else{
			ans += m - x + y;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

/*
4 6
1 5 1 4
*/

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

int h,w,k;
char board[11][1001];
int psum[11][1001];

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

	cin >> h >> w >> k;

	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin >> board[i][j];
		}
	}

	for(int j=1;j<=w;j++)
	{
		for(int i=1;i<=h;i++)
		{
			if(board[i][j]=='1')
			{
				psum[i][j] = psum[i-1][j] + 1;
			}
			else
			{
				psum[i][j] = psum[i-1][j];
			}
		}
	}

	int res = 1e9;
	for(int i=0;i<(1<<h);i++)
	{
		int pos = 0;
		int cnt = 0;
		int arr[11];
		memset(arr,0,sizeof(arr));
		vector <pair<int,int>> v;
		for(int j=0;j<h;j++)
		{
			if(i&(1<<j))
			{
				cnt++;
				v.push_back(make_pair(pos,j+1));
				pos = j + 1;
			}
		}
		if(pos!=h)
		{
			v.push_back(make_pair(pos,h));
		}
		//cout << i << ' ' << pos << ' ' << v.size() << '\n';
		bool ok = true;
		for(int j=1;j<=w;j++)
		{
			bool iscut = false;
			for(int idx=0;idx<v.size();idx++)
			{
				int xx = psum[v[idx].second][j] - psum[v[idx].first][j];
				if(xx > k)
				{
					ok = false;
					break;
				}
				else if(arr[idx] + xx > k)
				{
					iscut = true;
				}
				arr[idx] += xx;
			}
			if(!ok)
			{
				break;
			}
			if(iscut)
			{
				cnt++;
				memset(arr,0,sizeof(arr));
				for(int idx=0;idx<v.size();idx++)
				{
					int xx = psum[v[idx].second][j] - psum[v[idx].first][j];
					arr[idx] += xx;
				}
			}
		}
		if(ok)
		{
			res = min(res,cnt);
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,k,i;
    cin>>n>>k;
    int a[n];
    for (i=0;i<n;i++)
        cin>>a[i];
    int ans=1;
    n-=k;
    if (n%(k-1)==0)
        ans+=n/(k-1);
    else
        ans+=n/(k-1)+1;
    cout<<ans<<endl;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
    static List<String> list;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int M = scan.nextInt();
        int sum = 0;
        List<Integer> list1 = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        for(int i = 0; i < M; i++){
            int a = scan.nextInt();
            int b = scan.nextInt();
            list1.add(a);
            list2.add(b);
        }
        list = new ArrayList<>();
        //ここで全列挙を行う
        f(N, "1");
        int count = 0;
        for(int i = 0; i < list.size(); i++){
            count = 0;
            for(int m = 0; m < N-1; m++){
                int cur = list.get(i).charAt(m) - '0';
                int next = list.get(i).charAt(m+1) - '0';
                if(list1.contains(cur)){
                    for(int j = 0; j < M; j++){
                        if(list1.get(j) == cur && list2.get(j) == next){
                            count++;
                        }
                    }
                }
                
                if(list2.contains(cur)){
                    for(int j = 0; j < M; j++){
                        if(list1.get(j) == next && list2.get(j) == cur){
                            count++;
                            break;
                        }
                    }
                }
            }
            
            if(count == N-1){
                //System.out.println(list.get(i) + " count : " + count);
                sum++;
            }
        }
        System.out.println(sum);
    }
    
    public static void f(int N, String str){
        if(str.length() == N){
            list.add(str);
        }
        for(int i = 2; i <= N; i++){
            if(!str.contains(Integer.toString(i))){
                f(N, str+Integer.toString(i));
            }
        }
    }
}

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

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

using namespace std;
using ll = long long;

template<typename T>
T pown(T b, ll e) {
    if(e == 0) return 1;
    T p = pown(b, e / 2);
    if(e % 2 == 0) return p * p;
    return p * p * b;
}

template<const int mod>
struct Intmod {
    ll a;
    Intmod(ll a = 0): a(((a % mod) + mod) % mod) {}

    Intmod operator-() const {return Intmod(-a);}

    Intmod& operator+=(const Intmod b) {
        if((a += b.a) >= mod) a -= mod;
        return *this;
    }
    Intmod& operator+=(const ll b) {
        if((a += b) >= Intmod(mod).a) a -= mod;
        return *this;
    }
    Intmod& operator-=(const Intmod b) {
        if((a -= b.a) < 0) a += mod;
        return *this;
    }
    Intmod& operator-=(const ll b) {
        if((a -= Intmod(b).a) < 0) a += mod;
        return *this;
    }
    Intmod& operator*=(const Intmod b) {
        (a *= b.a) %= mod;
        return *this;
    }
    Intmod& operator*=(const ll b) {
        (a *= Intmod(b).a) %= mod;
        return *this;
    }

    template<typename T> Intmod operator+(const T b) const {return Intmod(*this) += b;}
    template<typename T> Intmod operator-(const T b) const {return Intmod(*this) -= b;}
    template<typename T> Intmod operator*(const T b) const {return Intmod(*this) *= b;}

    // Valid for prime mod. pown() needs to be included.
    int i = 0;
    Intmod inv() {
        if(a == 0) throw "Inverse of zero does not exist.";
        if(!i) i = pown(*this, mod - 2).a;
        return Intmod(i);
    }
    Intmod& operator/=(const Intmod b) {return *this *= b.inv();}
    Intmod& operator/=(const ll b) {return *this *= Intmod(b).inv();}
    template<typename T> Intmod operator/(const T b) const {return Intmod(*this) /= b;}
};
template<const int mod> Intmod<mod> operator+(const ll b, Intmod<mod> a) {return a += b;}
template<const int mod> Intmod<mod> operator-(const ll b, Intmod<mod> a) {return a -= b;}
template<const int mod> Intmod<mod> operator*(const ll b, Intmod<mod> a) {return a *= b;}
template<const int mod> Intmod<mod> operator/(const ll b, Intmod<mod> a) {return a /= b;} //Valid for prime mod.

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

    const int MOD = 1000000007;
    int n;
    cin >> n;

    Intmod<MOD> ans = 1, pow9 = 1, pow8 = 1;

    rep(i, n) {
        ans *= 10;
    }
    rep(i, n) {
        pow9 *= 9;
    }
    rep(i, n) {
        pow8 *= 8;
    }
    ans -= pow9 * 2;
    ans += pow8;

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

    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N;
vector<int> Plus, Minus;
vector<int> Zero;
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if(a > 0) Plus.push_back(a);
        else if(a < 0) Minus.push_back(a);
        else Zero.push_back(a);
    }
    while(!Zero.empty()) {
        if(Plus.empty()) Plus.push_back(0);
        else Minus.push_back(0);
        Zero.pop_back();
    }
    cerr << Plus.size() << " "<< Minus.size() << endl;
    if(Plus.empty()) {
        int ans = 0;
        sort(Minus.begin(), Minus.end(), greater<int>());
        for(int i = 0; i < Minus.size(); i++) {
            ans -= Minus[i];
        }
        ans += Minus[0] * 2;
        cout << ans << endl;
        int now = Minus[0];
        for(int i = 1; i < Minus.size(); i++) {
            cout << now << " " << Minus[i] << endl;
            now -= Minus[i];
        }
        return 0;
    }
    if(Minus.empty()) {
        sort(Plus.begin(), Plus.end());
        int ans = 0;
        for(int i = 0; i < Plus.size(); i++) ans += Plus[i];
        ans -= 2 * Plus[0];
        cout << ans << endl;
        int now = Plus[0];
        for(int i = 1; i + 1 < Plus.size(); i++) {
            cout << now << " " << Plus[i] << endl;
            now -= Plus[i];
        }
        cout << Plus.back() << " " << now << endl;
        return 0;
    }
    int ans = 0;
    for(int i = 0; i < Plus.size(); i++) ans += Plus[i];
    for(int i = 0; i < Minus.size(); i++) ans -= Minus[i];
    cout << ans << endl;
    int now = Minus[0];
    for(int i = 0; i + 1 < Plus.size(); i++) {
        cout << now << " " << Plus[i] << endl;
        now -= Plus[i];
    }
    cout << Plus.back() << " " << now << endl;
    now = Plus.back() - now;
    for(int i = 1; i < Minus.size(); i++) {
        cout << now << " " << Minus[i] << endl;
        now -= Minus[i];
    }
    return 0;
}


Measured memory_bytes: 2428