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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef pair<ll,P>  PP;
typedef vector<ll> Vector;
typedef vector<Vector> DVector;
typedef priority_queue<PP, vector<PP>, greater<PP>> PPQueue;

#define fi          first
#define se          second
#define sfi         se.fi
#define sse         se.se
#define pb          push_back
#define INF         INT_MAX
#define MOD         1000000007
#define bcnt        __builtin_popcount
#define all(x)      (x).begin(),(x).end()
#define uni(x)      x.erase(unique(all(x)),x.end())
#define ub(x,y)     (upper_bound(all(x),y)-x.begin())
#define lb(x,y)     (lower_bound(all(x),y)-x.begin())
#define rep(i,n)    repl(i,0,n-1)
#define usort(x)    sort(all(x))
#define dsort(x)    sort(all(x),greater<ll>())
#define mkp(x,y)    make_pair(x,y)
#define mmax(x,y)   (x>y?x:y)
#define mmin(x,y)   (x<y?x:y)
#define maxch(x,y)  x=mmax(x,y)
#define minch(x,y)  x=mmin(x,y)
#define exist(x,y)  (find(all(x),y)!=x.end())
#define each(itr,v) for(auto itr:v)
#define repl(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++)
DVector dp(1001,Vector(1001,INF));
Vector a(100),b(100),c(100);
ll n,ma,mb;
bool jd = false;
void dfs(ll cnt,ll ta, ll tb, ll tc){
  if(cnt == n || dp[ta][tb] < tc)return;
  dp[ta][tb] = tc;
  if(ta > 0 && tb > 0 && ta * mb == tb * ma){
    jd = true;
    return;
  }
  dfs(cnt+1,ta,tb,tc);
  dfs(cnt+1,ta+a[cnt+1],tb+b[cnt+1],tc+c[cnt+1]);
}


int main(){
  cin.sync_with_stdio(false);
  cin >> n >> ma >> mb;
  rep(i,n)cin >> a[i] >> b[i] >> c[i];
  dfs(0,0,0,0);
  dfs(0,a[0],b[0],c[0]);
  ll mn = INF;
  repl(i,1,1000)if(ma*i <= 1000 & mb*i <= 1000)minch(mn,dp[ma*i][mb*i]);
  cout << (jd ? mn : -1) << endl;
}


Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
#include <numeric>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main(){
	ll n; cin >> n;
    vector<int> v;
    for(int i=0; i<n; ++i){
        int a; cin >> a;
        v.push_back(a);
    }
    int sum = accumulate(v.begin(), v.end(), 0);
    sort(v.begin(), v.end());
    if(sum%10==0){
        for(int i=0; i<n; ++i){
            if((sum-v[i])%10!=0){
                sum-=v[i];
                break;
            }
            if(i==n-1) sum=0;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

struct Point { double x, y; };

void Koch(int n, Point a, Point b)
{
    if (n == 0) return;
    
    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;

    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;

    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    Koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    Koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    Koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    Koch(n - 1, t, b);
}

int main()
{
    Point a, b;
    int n;

    scanf("%d", &n);

    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);
    Koch(n, a, b);
    printf("%.8f %.8f\n", b.x, b.y);

    return 0;
}


Measured memory_bytes: 2732
using System ;

namespace Program{
 class Program{
  
  static int []par = new int[100005];
  static void Main(string []args){
   string []buff = Console.ReadLine().Split(' ');
    
   int N = int.Parse(buff[0]); 
   int M = int.Parse(buff[1]);
    
   for(int i = 0 ;i <= N ;i++) par[i] = i ;
    

    
    
   for(int i = 0 ; i < M ;i++){
     buff = Console.ReadLine().Split(' ');
     int X = int.Parse(buff[0]) ;
     int Y = int.Parse(buff[1]) ;
     if( root(X) == X && root(Y) == Y){
       unite(X,Y);
     }else if( root(X) == X){
       unite(Y,X); 
     }else{
       unite(X,Y); 
     }

   }
    
   for(int i = 1 ;i <= N ;i++)par[i] = root(i);
    
   int []c = new int[N];
    
   for(int i =0  ;i < N ;i++){
     c[i] = par[i + 1];
   }
    
   Array.Sort(c);
   int x = c[0];

   int count = 1 ;
    
   for(int i = 1 ; i < N ;i++){

     if( x != c[i]){
       count++;
       x = c[i];
     }
   }
    
   Console.WriteLine(count) ;
  }
   
  static int root( int x){
     if( par[x] == x) return x ;
     par[x] = root(par[x]) ;
     return par[x] ;
  }
   
  static void unite( int x ,int y){
    int rootX = root(x);
    int rootY = root(y);
    if( rootX == rootY )return ;
    par[rootY] = rootX ;
  }
 }
}

Measured memory_bytes: 16052
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define rush() int T;scanf("%d",&T);while(T--)
#define mm(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define sc(a) scanf("%d",&a)
#define sc2(a,b) scanf("%d%d",&a,&b)
#define pf(a) printf("%d\n",a)
#define pf2(a,b) printf("%d %d\n",a,b)
#define p_f(a) printf("%d ",a)
#define pyn(a) if(a)puts("Yes");else puts("No");
#define fi first
#define se second
#define db double
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const db eps=1e-9;
int n,a[5][5],f[5][5];
map<int,pii>m;
bool flag;
bool safe()
{
    if(f[1][1]&&f[1][2]&&f[1][3])return true;
    if(f[2][1]&&f[2][2]&&f[2][3])return true;
    if(f[3][1]&&f[3][2]&&f[3][3])return true;
    if(f[1][1]&&f[2][1]&&f[3][1])return true;
    if(f[1][2]&&f[2][3]&&f[3][3])return true;
    if(f[1][3]&&f[2][3]&&f[3][3])return true;
    if(f[1][1]&&f[2][2]&&f[3][3])return true;
    if(f[1][3]&&f[2][2]&&f[1][3])return true;
    return false;
}
int main()
{
    rep(i,1,3)rep(j,1,3)sc(a[i][j]),m[a[i][j]]={i,j};
    sc(n);
    rep(i,1,n){
        int x;sc(x);
        if(m.find(x)!=m.end()){
            int r=m[x].fi,c=m[x].se;
            f[r][c]=1;
        }
    }
    if(safe())flag=true;
    pyn(flag);
    return 0;
}


Measured memory_bytes: 256
def main():
    A, B, M = [int(i) for i in input().split()]
    a = [int(i) for i in input().split()]
    b = [int(i) for i in input().split()]
    
    p = []
    for i in range(M):
        x, y, c = [int(i) for i in input().split()]
        p.append(a[x - 1] + b[y - 1] - c)
    
    print(min([min(p), min(a) + min(b)]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 18488
import Control.Monad
import Control.Monad.ST
import qualified Data.Array as A
import qualified Data.Array.ST as ST
import qualified Data.Array.Unboxed as AU
import Data.Bits
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.Int
import qualified Data.IntMap as IM
import Data.List
import qualified Data.Map as M
import Data.Maybe
import Data.Ord
import qualified Data.Set as S
import Data.Time
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

putListWithSpace :: Show a => [a] -> IO ()
putListWithSpace [a] = putStr $ show a
putListWithSpace (a:as) = do
  putStr $ show a
  putStr " "
  putListWithSpace as

main = do
  [n, m] <- readInt
  as <- concat <$> readInts m
  print $ solve as n

solve as n = f 0 1 1 as n `mod` (10 ^ 9 + 7)

f x0 x1 now (a:as) n
  | n == now = x0 + x1
  | now == a = f x1 0 (now + 1) as n
  | otherwise = f x1 (x0 + x1) (now + 1) (a : as) n
f x0 x1 now [] n
  | n == now = x0 + x1
  | otherwise = f x1 (x0 + x1) (now + 1) [] n

Measured memory_bytes: 55932
#include <stdio.h>
#include <string.h>
#define M 36

typedef struct {
  char mark;
  int value;
}Card;

void BubbleSort(Card *, int);
void SelectionSort(Card *, int);
void disply(Card *, int);
int isStable(Card *, Card *, int);

int main(){
  Card C1[M+1], C2[M+1];
  int i, N;

  scanf("%d",&N);

//文字列と数字をそれぞれ格納
  for(i = 0; i < N; i++){
    scanf(" %c%d", &C1[i].mark, &C1[i].value);
  }

  for(i = 0 ;i < N; i++) C2[i] = C1[i];

  BubbleSort(C1, N);
  disply(C1, N);
  printf("Stable\n");

  SelectionSort(C2, N);
  disply(C2, N);

  if( isStable(C1, C2, N) == 0 ) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}

/*1 BubbleSort(C, N)
2   for i = 0 to N-1
3     for j = N-1 downto i+1
4       if C[j].value < C[j-1].value
5         C[j] と C[j-1] を交換*/
void BubbleSort(Card C1[], int N){
  int i, j;
  Card tmp;
  for(i = 0;i < N; i++){
    for(j = N-1; j > i; j--){
      if(C1[j].value < C1[j-1].value){
        tmp = C1[j];
        C1[j] = C1[j-1];
        C1[j-1] = tmp;
      }
    }
  }
}

/*7 SelectionSort(C, N)
8   for i = 0 to N-1
9     minj = i
10    for j = i to N-1
11      if C[j].value < C[minj].value
12        minj = j
13    C[i] と C[minj] を交換*/
void SelectionSort(Card C2[], int N){
  int i, j, minj;
  Card tmp;
  for(i = 0; i < N; i++){
    minj = i;
    for(j = i; j < N; j++){
      if(C2[j].value < C2[minj].value) minj = j;
    }
    tmp = C2[i];
    C2[i] = C2[minj];
    C2[minj] = tmp;
  }
}

void disply(Card C[], int N)
{
  int i;

  for( i = 0 ; i < N ; i++ ){
    if( i > 0 ) printf(" ");
    printf("%c%d", C[i].mark, C[i].value);
  }
  printf("\n");
}

/*1 isStable(in, out)
2   for i = 0 to N-1
3     for j = i+1 to N-1
4       for a = 0 to N-1
5         for b = a+1 to N-1
6           if in[i] と in[j] の数字が等しい && in[i] == out[b] && in[j] == out[a]
7             return false
8 return true*/
int isStable(Card C1[], Card C2[], int N){
  int i;

  for(i = 0; i < N; i++)
  if(C1[i].mark != C2[i].mark ) return 1;
  return 0;
}



Measured memory_bytes: 2104
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
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;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n,k;cin>>n>>k;
    vl x(n);rep(i,n)cin>>x[i];

    ll ans=INF;
    rep(i,n-k+1){
        chmin(ans,abs(x[i])+abs(x[i]-x[i+k-1]));
        chmin(ans,abs(x[i+k-1])+abs(x[i]-x[i+k-1]));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 0;
//----------------------//
 
int cnt[2123456][26];
 
int main() {
	string s; cin >> s;
	
	REP(i, s.size()) cnt[i][s[i]-'a']++;
	
	for (int i = s.size() - 1; i > 0; i--) {
		REP(j, 26) cnt[i - 1][j] += cnt[i][j];
	}
	
	ll ans = 1;
	REP(i, s.size()) {
		REP(j, 26) if (s[i] != j + 'a') {
			ans += cnt[i + 1][j];
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 20996
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define end(x) prev(x.end());
# define all(x) x.begin(), x.end()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

template<class T> void umin(T &a, T b) { a = min(a, b); }
template<class T> void umax(T &a, T b) { a = max(a, b); }

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

const int mod = 1e9+7;
const int N = 2e5+5;

void solve(){
	string s;
	cin>>s;
	ll ans=0;
	//1 2 5 
	// 0 0 125
	// 1 1 1+2+5
	// 1 0 1+25
	// 0 1 12+5
	for(ll mask=0;mask<(1<<(sz(s)-1));++mask){
		ll res=(ll)(s[0]-'0');
		//ll prev=ans;
		for(ll j=sz(s)-2,i=1;j>=0;--j,++i){
			if((mask&(1<<j))){
				ans+=res;
				res=s[i]-'0';
			}
			else res=res*1LL*10+(ll)(s[i]-'0');
		}
		ans+=res;
	}	
	cout<<ans;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 3584
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define emp emplace
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n,A[MAXN],sum[MAXN];
const ll MOD=1e9+7;
ll qexp(ll x, ll e){
	if(e==0)return 1;
	ll half=qexp(x,e/2);
	half*=half;
	half%=MOD;
	if(e&1)half*=x,half%=MOD;
	return half;
}
ll mul_inv(ll x) { return qexp(x,MOD-2); }
int main()
{
	FAST
	cin>>n;
	FOR(i,0,n)cin>>A[i];
	sum[1]=0;
	FOR(i,2,n+5){
		sum[i]=sum[i-1]+mul_inv(i);sum[i]%=MOD;
	}
	ll ans=0;
	FOR(i,0,n){
		ans+=sum[i+1]*A[i]%MOD;ans%=MOD;
		ans+=sum[n-i]*A[i]%MOD;ans%=MOD;
		ans+=A[i];ans%=MOD;
	}
	ll f=1;
	FOR(i,2,n+1)f*=i,f%=MOD;
	ans*=f;ans%=MOD;
	cout<<ans;
}


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

#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)

#define si(a)               scanf("%d", &a)
#define sii(a,b)            scanf("%d %d", &a, &b)
#define siii(a,b,c)         scanf("%d %d %d", &a, &b, &c)

#define CLR(a)              memset(a, 0, sizeof(a))
#define SET(a)              memset(a, -1, sizeof(a))

#define PI                  acos(-1.0)

#define pb                  push_back
#define mp                  make_pair
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for(int i=0; i<n; i++)
#define FOR1(i, n)          for(int i=1; i<=n; i++)
#define ROF(i, n)           for(int i=n-1; i>=0; i--)
#define ROF1(i, n)          for(int i=n; i>=1; i--)
#define LOOP(i, x, y)       for(int i=x; i<=y; i++)
#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long              LL;
typedef unsigned long long     ULL;
typedef vector<int>            VI;
typedef pair<int, int>         PII;
typedef pair<string, int>      PSI;
typedef pair<char, int>        PCI;

const int MAX = 100005;
const LL LMAX = 12158598925;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int kx[] = {1, 1, 2, 2, -1, -1, -2, -2};
int ky[] = {2, -2, 1, -1, 2, -2, 1, -1};

vector <int> graph[MAX], topSortedList;
bool vis[MAX];
int dp[MAX];

void DFS(int src)
{
    vis[src] = true;

    int sz = graph[src].size();
    for(int i=0; i<sz; i++){
        int z = graph[src][i];
        if(!vis[z])
            DFS(z);
    }

    topSortedList.pb(src);
}

int solve()
{
    int mx = -1;
    for(int i=0; i<topSortedList.size(); i++){
        int u = topSortedList[i];

        int sz = graph[u].size();
        for(int j=0; j<sz; j++){
            int z = graph[u][j];
            if(dp[u] < dp[z] + 1)
                dp[u] = dp[z] + 1;
            mx = max(mx, dp[u]);
        }
    }
    return mx;
}

int main()
{
//    READ;
//    WRITE;
    int n, m; sii(n, m);
    while(m--){
        int u, v; sii(u, v);
        graph[u].pb(v);
    }

    for(int i=1; i<=n; i++)
        if(!vis[i])
            DFS(i);

    int ans = solve();
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 8824
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    int nn = n % 100;
    int q = nn / 5;
    int r = nn % 5;
    n -= 105 * q;
    if (r > 0) n -= (100 + r);
    puts((n >= 0) ? "1" : "0");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
signed main(){
int a,b,c;
  cin>>a>>b>>c;
  if(abs(b-c)%2==1)
    cout<<min((b+c-1)/2,(a*2-b-c+1)/2);
  else
    cout<<abs(b-c)/2;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <unordered_set>
using namespace std;
typedef long long ll;
int N;
ll arr[100005];
unordered_set <int> irrelevant;
int main(){
    cin >> N;
    for (int i=0; i<N; i++) scanf("%lld", &arr[i]);
    int cont = 0;
    for (int i=0; i<64; i++){
        cont = 0;
        for (int j=0; j<N; j++) {
            if ((arr[j] & (1LL << i))) cont++;
        }
        if (cont % 2 == 1){
            irrelevant.insert(i);
            for (int j=0; j<N; j++){
                arr[j] &= (~(1LL<<i));
            }
        }
    }
    int idx = 0;
    for (int i=62; i>=0; i--){
        int maxInd = idx;
        ll maxEle = INT_MIN;
        for (int j=idx; j<N; j++){
            if ((arr[j] & (1LL << i)) && maxEle < arr[j]) {
                maxEle = arr[j];
                maxInd = j;
            }
        }
        if (maxEle == INT_MIN) continue;
        swap(arr[idx], arr[maxInd]);
        for (int j=0; j<N; j++){
            if (j != idx && (arr[j] & (1LL << i))) arr[j] ^= maxEle;
        }
        idx++;
    }
    ll ans = 0;
    for (int i=0; i<N; i++){
        ans ^= arr[i];
    }
    ans *= 2;
    for (auto it: irrelevant){
        ans += (1LL<<(it));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		int[] h = new int[n];
		for(int i=0;i<n;i++) {
			h[i] = in.nextInt();
		}
		for(int i=0;i<n;i++) {
			a[i] = Integer.MAX_VALUE;
		}
		a[0] = 0;
		for(int i=0;i<n;i++) {
			if(i<n-1)a[i+1] = Math.min(a[i+1], a[i]+Math.abs(h[i]-h[i+1]));
			if(i<n-2)a[i+2] = Math.min(a[i+2], a[i]+Math.abs(h[i]-h[i+2]));
		}
		System.out.println(a[n-1]);
	}
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define mem(a, b) memset(a, b, sizeof(a))

const int MOD = 1000000007;
const int MAX = (int) 1e9;
const double PI = 3.141592653589793238462643383279502884;

template <typename T, typename U>
T max(T x, U y) {
    return x > y ? x : y;
}

template <typename T, typename U>
T min(T x, U y) {
    return x < y ? x : y;
}

template<typename T>
void debug(string msg, T t) {
	cout << msg << ": " << t << "\n";
}

int toDigit(char c) { return c - '0'; }

int h, w, k, ans;
char g[6][6];

int main() {

	cin >> h >> w >> k;

	for(int r = 0; r < h; r++) {
		for(int c = 0; c < w; c++) {
			cin >> g[r][c];
		}
	}

	// for every combination of rows and columns
	for(int mask = 0; mask < (1 << (h + w)); mask++) {
		int totalBlack = 0;
		// for every row
		for(int i = 0; i < h; i++) {
			// for every column
			for(int j = 0; j < w; j++) {
				if(g[i][j] == '#') {
					if(((1 << (j + h)) & mask | (1 << i) & mask) == 0) {
						totalBlack++;
					}
				}
			}
		}

		if(totalBlack == k) {
			ans++;
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3604
/*
* @Author: Kabid
* @Date:   {{create_time}}
* @Last Modified by:   Kabid
* @Last Modified time: 2020-09-19 13:00:03
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');

int t;       //test cases
ll i, j;	 //iterators
ll n, k , p, q,  d, m, c, c1, c2, d1; //variables;
ll mx = LLONG_MIN, mn = LLONG_MAX;		// max min
string s, s1, s2;		// string
ll a [1000001], b [200001] , mox [200001];	// array
map <int, int > mp;
vector <vector<ll>> vc;
vector <ll> v;
set <ll> st;
bool r;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//cin >> t; q = t;
	t = 1;
	while (t--) {


		/*cin >> s;
		n = s.size();
		for (i = n - 1; i > 0; i--) {
			for (j = i - 1; j >= 0; j--) {
				if (s[i] > s[j]) {
					swap(s[i], s[j]);
					cout << s << endl;
					break;
				}
			}
			if(j!=-1) break;
		}
		if (i == 0) {
			cout << "no answer" << endl;
		}*/
		cin >> n;
		//n=s.size();
		p = n;
		while (n) {
			c += n % 10;
			n /= 10;
			//cout << n <<' '<<c<< endl;
			
		}
		if (p % c) {
			cout << "No" << endl;
		}
		else {
			cout << "Yes" << endl;
		}
		//c = 0;
	}


	return 0;

}

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

void solve()
{
	string s,t;
	cin >> s >> t;
	int size = s.size();
	int count = 0;
	for(int i=0; i<size; i++){
		if(s[i]!= t[i]) count++;
	}
	cout << count << "\n";
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int t =1;
	while(t--){
		solve();		
	}
	return 0;
}


Measured memory_bytes: 3884
use std::collections::BinaryHeap;

const INF: i64 = 1 << 50;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let h: usize = sc.read();
    let w: usize = sc.read();
    let board: Vec<Vec<char>> = (0..h).map(|_| sc.chars()).collect();

    let mut heap = BinaryHeap::new();
    let mut dist = vec![vec![INF; w]; h];
    if board[0][0] == '#' {
        dist[0][0] = 1;
        heap.push((-1, 0, 0));
    } else {
        dist[0][0] = 0;
        heap.push((0, 0, 0));
    }

    while let Some((_, i, j)) = heap.pop() {
        let inverse = board[i][j] == '#';
        if i + 1 < h {
            let next_cost = dist[i][j]
                + if !inverse && board[i + 1][j] == '#' {
                    1
                } else {
                    0
                };
            if dist[i + 1][j] > next_cost {
                dist[i + 1][j] = next_cost;
                heap.push((-next_cost, i + 1, j));
            }
        }
        if j + 1 < w {
            let next_cost = dist[i][j]
                + if !inverse && board[i][j + 1] == '#' {
                    1
                } else {
                    0
                };
            if dist[i][j + 1] > next_cost {
                dist[i][j + 1] = next_cost;
                heap.push((-next_cost, i, j + 1));
            }
        }
    }
    println!("{}", dist[h - 1][w - 1]);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=1e6+5,M=2e6+5,MOD=1e9+7,OO=1e9;


int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();

	int n ; 
	ll k ;

	scanf("%d %lld",&n,&k);
	map<int,ll>occ;
	for(int i=0,x,y;i<n;i++){
		scanf("%d %d",&x,&y);
		occ[x]+=y;
	}	

	ll curr = 0;

	for(auto p : occ){
		curr+=p.second;
		if(curr>=k){
			return !printf("%d\n",p.first);
		}
	}
}


Measured memory_bytes: 4224
#include<stdio.h>
#include<math.h>

int main(){

	int a,b,c;
	int i,j=0;

	scanf("%d %d %d",&a,&b,&c);

	for(i=a;i<=b;i++){
		if(c%i==0){
			j+=1;
		}
	}

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

	return 0;
}

Measured memory_bytes: 596
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[100],b[100],c,d,e,f,m,n;
  while(cin>>n>>m&&n+m){
    c=d=0;
    for(i=0;i<n;i++){
      cin>>a[i];
      c+=a[i];
    }
    for(i=0;i<m;i++){
      cin>>b[i];
      d+=b[i];
    }
    e=f=101;
    for(i=0;i<n;i++){
      for(j=0;j<m;j++){
	if(c+b[j]-a[i]==d+a[i]-b[j]){
	  if(e+f>a[i]+b[j]){
	    e=a[i];
	    f=b[j];
	  }
	}
      }
    }
    if(e==101&&f==101)
      cout<<-1<<endl;
    else
      cout<<e<<" "<<f<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
A,B,C,K = map(int,input().split())

score = 0

if K >= A:
  score += A
  K -= A
else:
  score += K
  print(score)
  exit()

if K >= B:
  K -= B
else:
  print(score)
  exit()

if K >= C:
  score -= C
else:
  score -= K
print(score)
  

Measured memory_bytes: 9128
import java.io.*;
import java.util.*;
import java.awt.geom.*;

public class Main {
    Scanner sc;
    Main() {
        sc = new Scanner(System.in);
    }

    double ax1;
    double ay1;
    double ax2;
    double ay2;
    double bx1;
    double by1;
    double bx2;
    double by2;
    boolean init() {
        if (!sc.hasNext()) return false;
        double x1, y1, x2, y2;
        ax1 = sc.nextDouble();
        ay1 = sc.nextDouble();
        ax2 = sc.nextDouble();
        ay2 = sc.nextDouble();
        bx1 = sc.nextDouble();
        by1 = sc.nextDouble();
        bx2 = sc.nextDouble();
        by2 = sc.nextDouble();
        return true;
    }

    void run() {
        while (init()) {
            if (ax2 >= bx1 && bx2 >= ax1 && ay2 >= by1 && by2 >= ay1) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 12000
use std::io::stdin;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim()
        .split_whitespace()
        .map(|x| x.parse().ok().unwrap())
        .collect()
}

fn main() {
    let v: Vec<u32> = read_vec();
    let (n, x) = (v[0], v[1]);
    let m = (0..n).map(|_| read::<u32>());
    let (min, at_least) = m.fold((1000, 0), |(min, at_least), m| {
        let min = if m < min { m } else { min };
        let at_least = at_least + m;
        (min, at_least)
    });
    let ans = (x - at_least) / min + n;

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    int X, Y;
    cin >> X >> Y;
    map<int, int> mp;
    mp[1] = 300000;
    mp[2] = 200000;
    mp[3] = 100000;
    if (X == 1 && Y == 1) {
        cout << 1000000 << endl;
    } else {
        cout << mp[X] + mp[Y] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	int flag=0;
	if(a>b){
		if(c>b&&c<a){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	if(a<b){
		if(c>a&&c<b){
			printf("Yes\n");
		}
		else{
			printf("No\n");			
		}
	}
	return 0;
}

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

int main(){
  char s;
  int sum = 0;
  int ans;
  
  for(int i = 0; i <= 200000; i++){
    cin >> s;
    if((int)s >= 48){
      sum += ((int)s-48);
      s = (char)47;
    }else{
      break;
    }
  }
  //printf("\n");
  ans = sum % 9;
  //printf("%d, %d\n", sum, ans);
  if(ans == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

#define MAX 100005
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define ull long long
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define nl '\n'
#define zai <<' '<<
#define all(a) a.begin(),a.end()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int INF=1e9+7;
ull dp[MAX+5];
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,W,w,v;
	cin >> n >> W;
	memset(dp,INF,sizeof dp);
	dp[0]=0;
	for(int i=0;i<n;i++){
		cin >> w >> v;
		for(int j=MAX-1;j>=v;j--){
			dp[j]=min(dp[j],dp[j-v]+w);
		}
	}
	ull ans=0;
	for(int i=0;i<MAX;i++){
		if(dp[i]<=W)ans=i;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
import Control.Monad
import Data.List

main :: IO ()
main = do
  as <- replicateM 5 readLn :: IO [Int]
  let dms = map (\x -> ((x`div`10)*10,(x-1)`mod`10)) as
      sortedDms = sortBy (\(_,x) (_,y) -> compare x y) dms
      (s:ss) = map (\(x,y) -> (x,(y+1)`mod`10)) sortedDms
      ss2 = map (\(x,y) -> (if y==0 then x else x+10)) ss
  print $ fst s + snd s + sum ss2

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

#define FOR(i, j, n) for (int i(j); i < n; ++i)
#define FORR(v, c) for (auto &v : c)
#define F first
#define S second
#define SQ(x) (x)*(x)
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define dbg(x) std::cerr<<#x<<" = " << (x) << std::endl
#define pnl(x) std::cout << x << '\n'
#define pns(x) std::cout << x << ' '
#define read(x) std::cin >> x
#define read2(x,y) std::cin >> x >> y
#define read3(x, y, z) std::cin >> x >> y >> z
#define read4(a, b, c, d) std::cin >> a >> b >> c >> d
#define readv(v) FORR(c,v) read(c)

struct Arrete { int v, c;};
struct Point {int x, y; double distance(Point other) const {return sqrt(SQ(x-other.x)+SQ(y-other.y));}};

typedef	std::vector<int>	vi;
typedef std::pair<int,int>	ii;
typedef std::vector<std::string>	vs;
typedef std::vector<ii>	vii;
typedef std::vector<Arrete>	vg;
typedef std::vector<long long>	vl;
typedef	long long ll;

const int	NB_D = 4;
const int	DY[] = {-1, 1, 0, 0};
const int	DX[] = {0, 0, -1, 1};

int		main(void)
{
	std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
	std::string a, b, c;
	read3(a,b,c);
	std::cout << a[0]<<b[1]<<c[2]<<std::endl;
}



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

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; (i)<(n); ++(i))
#define rep1(i, n) for(int i = 1; (i)<(n); ++(i))
#define rev_rep(i, n) for(int i = (n) - 1; (i) >= 0; --(i))
#define range(a, i, b) for(int i = (a); (i) < (b); ++(i))
#define dump(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()
#define readl(N) ll N; cin >> N
#define readlv(N, vec) vector<ll> vec(N); rep(i, N){cin >> vec[i];}
#define greater_than [](ll l, ll r){return l > r;}
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair);
template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec);
template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::pair<T1, T2>& pair){
  os << '(' << pair.first << ',' << pair.second << ')';
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(ll i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}

template<class T1, class T2>
std::ostream& operator << (std::ostream& os, std::map<T1, T2>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

template<class T>
std::ostream& operator << (std::ostream& os, std::set<T>& mp){
  std::size_t n = mp.size();
  if(n == 0){
    return os;
  }
  os << " ";
  for(auto && x:mp){
    os << x << " ";
  }
  os << std::endl;
  return os;
}

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

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){
  vector<int> x(4);
  rep(i, 4){
    char c;
    cin >> c;
    x[i] = c - '0';
  }
  // dump(x);

  for(int mask = 0; mask < (1 << 4); mask++){
    ll r = x[0];
    rep1(i, 4){
      if(mask & (1 << i)){
        r += x[i];
      }else{
        r -= x[i];
      }
    }
    // dump(r);
    if(r == 7){
      cout << x[0];
      rep1(i, 4){
        if(mask & (1 << i)){
          cout << "+";
        }else{
          cout << "-";
        }
        cout << x[i];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}
#endif


Measured memory_bytes: 256
function main( str ){
      var result = "yes";
      for( var i=0; i<str.length; i++ ){
        var cnt = 0;
        for( var k=0; k<str.length; k++ ){
          if( str[i] == str[k] ) cnt++;
        }
        if( cnt > 1 ) result = "no";
      }
      console.log( result );
    }
     
    main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

int dx[] = {0, -1, 1, 0};
int dy[] = {-1, 0, 0, 1};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int res = 0;
    for( int i = 0; i <= n; ++i ) {
        for( int j = 0; j <= n; ++j ) {
            if( !( ( n - ( i * r + j * g ) ) % b ) && n - ( i * r + j * g ) >= 0 ) ++res;
        }
    }
    cout << res << endl;
    return 0;
}


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

int N, Q;
queue< pair<string, int> > U; //queue of <name, time>

int main() {
  cin >> N >> Q; // read n: number of processes, q:quantum

  string label;
  int t; // name and time
  for (int n=0; n<N; ++n) {    
    cin >> label >> t; // read label (p1, p2, ...) and time
    U.push( pair<string, int>(label, t) );
  }

  int S = 0; // Track the time taken
  int H; // holder variable
  
  while (! U.empty() ) {
    H = U.front().second;
    if (H <= Q) {
      S += H;
      cout << U.front().first << " " << S << endl;
      U.pop();
    }
    else {
      U.push( pair<string, int> (U.front().first, H - Q));
      U.pop();
      S += Q;
    }
  }
}
  

Measured memory_bytes: 4400
#include<cstdio>

int main() {
	char s[111];
	scanf("%s", s);
	
	char ch;
	if (s[0]=='A') ch = 'T';
	else
	if (s[0]=='C') ch = 'G';
	else
	if (s[0]=='G') ch = 'C';
	else
		ch = 'A';
	printf("%c\n", ch);
	
	return 0;
}

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

using pii = pair<int, int>;
using ll  = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " : " << x << endl

template <class T>
bool set_min(T &a, const T &b) {
    return a > b ? a = b, true : false;
}
template <class T>
bool set_max(T &a, const T &b) {
    return a < b ? a = b, true : false;
}
// vector
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &a : v) is >> a;
    return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &t : v) os << "\t" << t;
    return os << endl;
}
// pair
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
    return os << "<" << v.first << ", " << v.second << ">";
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;



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


    int H, W, K; cin >> H >> W >> K;
    vector<string> S(H); cin >> S;
    int ans = INF;

    int aaaa = 0;
    rep(h, H) rep(w, W) aaaa += S[h][w] == '1';
    if(aaaa <= K) ans = 0;
    
    rep(bit, (1 << (H - 1))) {
      vector<int> shs, ehs;

      int eh = -1;
      while(true) {
	int sh = eh + 1;
	while(eh < H and bit & (1 << (++eh)));
	if(eh == H) break;
	shs.push_back(sh);
	ehs.push_back(eh);
      }
      int tans = shs.size() - 1;
      vector<int> cnts(shs.size());
      bool flg2 = false;
      rep(w, W) {
	vector<int> ncnts(shs.size());
	bool flg = false;
	rep(i, shs.size()) {	
	  for(int y = shs[i]; y <= ehs[i]; y++) {
	    ncnts[i] += S[y][w] == '1';
	    flg |= cnts[i] + ncnts[i] > K;
	    if(ncnts[i] > K) goto FAIL;
	  }	  
	}	
	if(flg) {
	  rep(i, shs.size()) cnts[i] = 0;
	  tans += 1;
	}
	rep(i, shs.size()) cnts[i] += ncnts[i];
      }      
      rep(i, shs.size()) flg2 |= cnts[i] > 0;
      if(flg2) tans += 1;
      // debug(tans - 1);
      set_min(ans, tans - 1);
    FAIL:;
    }
    set_max(ans, 0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static ArrayList<Integer> list = new ArrayList<>();
    static int n;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        makeNum(0, new boolean[n], 0);
        int p = 0;
        for (int i = 0; i < n; i++) {
            p *= 10;
            p += sc.nextInt();
        }
        int q = 0;
        for (int i = 0; i < n; i++) {
            q *= 10;
            q += sc.nextInt();
        }
        int a = getIdx(p);
        int b = getIdx(q);
        System.out.println(Math.abs(a - b));
    }
    
    static int getIdx(int x) {
        for (int i = 0; i < list.size(); i++) {
            if (x == list.get(i)) {
                return i + 1;
            }
        }
        return 0;
    }
    
    static void makeNum(int idx, boolean[] used, int value) {
        if (idx >= n) {
            list.add(value);
        }
        for (int i = 0; i < n; i++) {
            if (!used[i]) {
                used[i] = true;
                makeNum(idx + 1, used, value * 10 + i + 1);
                used[i] = false;
            }
        }
    }
}

Measured memory_bytes: 24532
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ii>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 200003;
ll i,j,h,w,n,a,b;
vi v;
ll fact[N],dp[N],inv[N];
ll nCr(ll a,ll b,ll c,ll d)
{
    ll r = d - b;
    ll n = r + c - a;
    return ((fact[n] * inv[r]) % mod * inv[n - r]) % mod;
}
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    rep(i,0,N){
        fact[i] = (i == 0 ? 1 : (fact[i - 1] * i) % mod);
        inv[i] = modexp(fact[i],mod - 2);
    }
    cin>>h>>w>>n;
    rep(i,0,n){
        cin>>a>>b;
        v.pb({a,b});
    }
    v.pb({h,w});
    sort(all(v));
    rep(i,0,n + 1){
        dp[i] = nCr(1,1,v[i].f,v[i].se);
        rep(j,0,i) if(v[j].f <= v[i].f && v[j].se <= v[i].se)
            dp[i] = (dp[i] - (dp[j] * nCr(v[j].f,v[j].se,v[i].f,v[i].se)) % mod + mod) % mod;
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 4608
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}


void Main()
{
    int n,m;cin>>n>>m;
    vector<vector<LL>> x(n);
    REP(i,n){
        x[i].resize(3);
        cin>>x[i][0]>>x[i][1]>>x[i][2];
    }

    LL result = 0;
    REP(bit,(1<<3)){
        //dump(bit)
        
        priority_queue<LL> pq;

        REP(i,n){
            LL tmp = 0;
            REP(j,3){
                if(bit & (1<<j)){
                    tmp += x[i][j];
                }
                else{
                    tmp -= x[i][j];
                }
            }
            pq.push(tmp);
            //dump(tmp)
        }

        LL sum = 0;
        REP(i,m){
            sum += pq.top();
            pq.pop();
        }

        result = max(result,sum);
    }
    cout << result << endl;

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int A, B, C;
    cin >> A >> B >> C;
    bool YN = false;
    for (int i = 1; i <= 100; i++)
    {
        if ((A * i) % B == C)
        {
            YN = true;
            break;
        }
    }
    
    if (YN)
    {
        cout << "YES" << endl;
    }else
    {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
n,a,b = map(int,input().split())
s = input()
for i in s:
    if i == "a":
        if a+b > 0:
            print("Yes")
            a -= 1
        else:
            print("No")
    if i == "b":
        if a+b > 0 and b > 0:
            print("Yes")
            b -= 1
        else:
            print("No")
    if i == "c": print("No")


Measured memory_bytes: 4244