akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
Int n;
vector<Int> mg(vector<Int> a,vector<Int> b){
  vector<Int> c(n);
  for(Int i=0;i<n;i++) c[i]=a[b[i]];
  return c;
}

vector<Int> vpow(vector<Int> a,Int k){
  vector<Int> c(n);
  iota(c.begin(),c.end(),0);
  while(k){
    if(k&1) c=mg(c,a);
    a=mg(a,a);
    k>>=1;
  }
  return c;
}

void print(vector<Int> v){
  for(Int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<v[i]+1;
  }
  cout<<endl;
}

signed main(){
  Int k;
  cin>>n>>k;
  vector<Int> p(n),q(n),x(n),y(n);
  for(Int i=0;i<n;i++) cin>>p[i];
  for(Int i=0;i<n;i++) cin>>q[i];
  for(Int i=0;i<n;i++){
    p[i]--;q[i]--;
    x[p[i]]=i;
    y[q[i]]=i;
  }
  k--;
  if(k==0){
    print(p);
    return 0;
  }
  if(k==1){
    print(q);
    return 0;
  }  
  auto qxyp=mg(q,mg(x,mg(y,p)));
  auto xqpy=mg(x,mg(q,mg(p,y)));

  vector<vector<Int> > vs;
  vs.emplace_back(mg(q,mg(p,y)));
  vs.emplace_back(q);
  vs.emplace_back(mg(q,x));
  vs.emplace_back(mg(q,mg(x,y)));
  vs.emplace_back(y);
  vs.emplace_back(mg(p,y));

  Int a=(k+2)/6,b=(k-1)/6,c=k%6;
  auto ans=mg(vpow(qxyp,a),mg(vs[c],vpow(xqpy,b)));

  print(ans);
  return 0;
}


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

template<typename T> T in() { abort(); return T(); }
template<> std::string in() { std::string str; std::cin >> str; return str; }
template<> int in() { int x; scanf("%d", &x); return x; }

template<typename T> void out(T x) { abort(); }
template<> void out(const char* x) { printf("%s\n", x); }
template<> void out(std::string x) { std::cout << x << std::endl; }
template<> void out(int x) { printf("%d\n", x); }
template<> void out(long x) { printf("%ld\n", x); }

template<typename T>
T pow(T x, long n) {
  T res = 1;
  T p = x;
  while( n != 0 ) {
    if( n & 0x01 ) res *= p;
    p *= p;
    n >>= 1;
  }
  return res;
}

template<long P = 1000000007>
class Mod {
public:
  Mod() : a(0) {}
  Mod(long x) : a(x) {}
  long get() { return a; }
  Mod operator + (Mod x) { return Mod<P>((a + x.get()) % P); }
  Mod operator += (Mod x) { a = (a + x.get()) % P; return *this; }
  Mod operator - (Mod x) { return Mod<P>((a + P - x.get()) % P); }
  Mod operator -= (Mod x) { a = (a + P - x.a) % P; return *this; }
  Mod operator * (Mod x) { return Mod<P>((a * x.get()) % P); }
  Mod operator *= (Mod x) { a = (a * x.a) % P; return *this; }
  Mod operator / (Mod x) { return *this * pow(x, P - 2); }
  Mod operator /= (Mod x) { a = (*this * pow(x, P - 2)); return *this; }
private:
  long a;
};



std::string str;

Mod<> dp[512][512];
Mod<> power[512][512]; // x ^ k
Mod<> powersum[512][512];
long xs[512];
long ys[512];

int main() {
  int n = in<int>();
  int c = in<int>();

  for(int i = 0; i < n; ++i) xs[i] = in<int>();
  for(int i = 0; i < n; ++i) ys[i] = in<int>();

  for(int i = 1; i < 512; ++i) {
    Mod<> t = 1;
    for(int j = 0; j < 512; ++j) {
      power[i][j] = t;
      t *= i;
    }
  }

  for(int j = 0; j < 512; ++j) {
    Mod<> sum = 0;
    powersum[0][j] = 0;
    for(int i = 1; i < 512; ++i) {
      powersum[i][j] = sum;
      sum += power[i][j];
    }
  }
  
  // for(int i = 1; i < 512 ++i) {
  //   Mod<> t = 1;
  //   Mod<> sum = 0;
  //   for(int j = 0; j < 512; ++j) {
  //     powersum[i][j] = sum;
  //     t *= i;
  //     sum += t;
  //   }
  // }

  
  // for(int i = 0; i < n; ++i) {
  //   power[i][0] = 1;
  //   for(int j = 1; j <= c; ++j) {
  //     power[i][j] = power[i][j-1] * xs[i];
  //   }
  // }

 

  for(int j = 0; j <= c; ++j) {
    dp[0][j] = powersum[ys[0] + 1][j] - powersum[xs[0]][j];
  }

  for(int i = 1; i < n; ++i) {
    for(int j = 0; j <= c; ++j) {
      Mod<> sum = 0;
      for(int k = 0; k <= j; ++k) {
        sum += (powersum[ys[i] + 1][j-k] - powersum[xs[i]][j-k]) * dp[i-1][k];
      }
      dp[i][j] = sum;
    }
  }

  // for(int i = 0; i <= c; ++i) {
  //   for(int j = 0; j <= n; ++j) {
  //     printf("%ld ", dp[j][i].get());
  //   }
  //   puts("");
  // }
  
  out(dp[n-1][c].get());
  
  return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  ll n,k;
  cin>>n>>k;
  ll a[200100];
  rep(i,n)cin>>a[i];

  int start=0;
  for(int i=0;i<n-k;i++){
    if(a[i]<a[i+k]){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }

  return 0;
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    string w;
    cin >> w;

    map<ll, ll> m;
    rep (i, w.size()) {
        m[w[i]-'0']++;
    }

    for (auto it : m) {
        if(it.second%2 == 1) {
            No;
            return 0;
        }
    }

    Yes;
    return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  string S;
  cin >> S;
  int N = S.size();
  int K;
  cin >> K;
  
  vector<vector<ll>> dp1(N, vector<ll>(K+1, 0)); // N以下確定
  vector<vector<ll>> dp2(N, vector<ll>(K+1, 0)); // N以下未確定

  int num = S[0] - '0';
  dp1[0][1] = num -1; // 1 ~ S[i]-1
  dp1[0][0] = 1; // 0
  dp2[0][1] = 1; // S[i]

  // dp2の更新
  for(int i = 0; i < N-1; i++){
    int num = S[i+1] - '0'; 
    if(num == 0){
      for(int j = 0; j <= K; j++){
        dp2[i+1][j] += dp2[i][j];
      } 
    } else { 
      for(int j = 0; j <= K; j++){
        if(j+1<=K) dp2[i+1][j+1] += dp2[i][j]; // S[i]
        if(j+1<=K) dp1[i+1][j+1] += dp2[i][j] * (num -1); // 1 ~ S[i] -1
        dp1[i+1][j] += dp2[i][j]; // 0
      }
    }
  }

  for(int i = 0; i < N-1; i++){
    for(int j = 0; j <= K; j++){
      if(j+1<=K) dp1[i+1][j+1] += dp1[i][j] * 9; // 1 ~ 9;
      dp1[i+1][j] += dp1[i][j]; // 0
    }
  }


  cout << dp1[N-1][K] + dp2[N-1][K] << endl;


}

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

int main() {
    ll r,g,b,n;
    cin>>r>>g>>b>>n;
    ll ans=0;
    for(int i=0;r*i<=n;i++) {
        ll x=n-r*i;
        for(int j=0; g*j<=x;j++) {
            ll y=x-g*j;
            if(y%b==0){
              ans++;
            }
        }
    }

    cout<<ans<<endl;
}

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

int main(void){
    int n;
    cin >> n;
    int keta=0;
    int cnt=0;
    for(int i=1;i<=n;i++){
        int keta=1,tmp=i;
        while(1){
            tmp = tmp/10;
            if(tmp==0){
                break;
            }
            keta++;
        }
        if(keta%2 == 1){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(void){
  int n, i, x = 0, max = x;
  string s;
  cin >> n >> s;
  for(i = 0; i < n; i++){
    if(s[i] == 'I') x++;
    else x--;
    if(x > max) max = x;
  }
  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = [int(x) for x in input().split()]
ans = 0
near_a = 1000000
for i in range(N):
    temp = T - H[i] *0.006
    if near_a > abs(A - temp):
        near_a = abs(A - temp)
        ans = i + 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void) {
	int x, y;
	while(1){
		scanf("%d %d", &x, &y);
		if(x==0 && y==0){
			break;
		}else if(x<=y){
			printf("%d %d\n", x, y);
		}else{
			printf("%d %d\n", y, x);
		}
	}
	
	return 0;
}



Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#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; }

typedef long long ll;

using namespace std;


template <class Monoid>
class SegmentTree
{
public:
  using Func = function<Monoid(Monoid, Monoid)>;
  const Func F;
  const Monoid M1;
  int sz;
  vector<Monoid> seg;

  SegmentTree(int n,const Func fu, const Monoid &m1): F(fu) , M1(m1) {init(n);}
  void init(int n)
  {
      sz= 1;
      while (sz < n) sz *= 2;
      seg.assign(sz * 2, M1);
  }
  void update(int k,const Monoid &x)
  {
    k+=sz;
    seg[k]=x;
    while(k>>=1)
    {
      seg[k]=F(seg[k*2],seg[k*2+1]);
    }
  }
  Monoid query(int l,int r)
  {
    Monoid L=M1,R=M1;
    l+=sz;r+=sz;
    for(;l<r;l>>=1,r>>=1)
    {
      if(l&1)L=F(L,seg[l++]);
      if(r&1)R=F(seg[--r],R);
    }
    return F(L,R);
  }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,k;cin>>n>>k;
  vector<ll>x;
  for(ll i=1;i*i<=n;i++){
    x.push_back(i);
    if(i*i!=n)x.push_back(n/i+1);//半開
    if((i+1)*(i+1)>n)x.push_back(i+1);
  }
  sort(all(x));
  x.erase(unique(all(x)),x.end());
  ll sz=x.size();
  vector<ll>dp(sz-1);
  dp[0]=1;
  ll mod=1e9+7;
  rep(i,k){
    rep(j,sz-2){
      dp[j+1]+=dp[j];
      dp[j+1]%=mod;
    }
    reverse(all(dp));
    rep(j,sz-1){
      
      dp[j]*=x[j+1]-x[j];
      dp[j]%=mod;
    }
  }
  ll res=0;
  rep(i,sz-1){
    res+=dp[i];
  }
  cout<<res%mod<<endl;

  return 0;

}


Measured memory_bytes: 1400
use proconio::input;

const MOD: i64 = 1_000_000_007;

fn main() {
    input!(n: i64);

    let mpow = |base, exp| (0..exp).fold(1_i64, |acc, _| acc * base % MOD);
    let ans = mpow(10, n) + mpow(8, n) - 2 * mpow(9, n);
    let ans = ans.rem_euclid(MOD);

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


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

string s, t;
bool bl;
bool ans = false;

int main() {
  cin >> s >> t;
  s += s;
  rep (i, t.size()) {
    bl = true;
    rep (j, t.size()) {
      if (s[i+j] != t[j]) bl = false;
    }
    if (bl) ans = true;
  }
  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3584
#!/usr/bin/env python
# coding: utf-8

# In[15]:


N,M = map(int, input().split())
ks = []
for _ in range(M):
    ks.append(list(map(int, input().split())))
p = list(map(int, input().split()))


# In[16]:


ans = 0
for s in range(2**N):
    s_bit = format(s,"010b")
    for i,item in enumerate(ks):
        cnt = 0
        for x in item[1:]:
            if s_bit[10-x] == "1":
                cnt += 1
        if cnt%2 != p[i]:
            break
    else:
        ans += 1
        continue
print(ans)


# In[ ]:






Measured memory_bytes: 88244
import java.io.*;
import java.util.*;

public class Main {
	public static void main (String[] args) throws IOException{
		FastScanner sc = new FastScanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int n = sc.nextInt();
		int max = Math.max(h,w);
		int p = (int)Math.ceil(1.0*n/max);
		System.out.println(p);
	}
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;
		FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}
		FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}
		String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}

Measured memory_bytes: 22612
__DEUBG__ = 0


from collections import Counter

N, K = map(int, input().split())
balls = map(int, input().split())

balls = Counter(balls)
b2 = sorted(balls.items(), key=lambda item: item[1], reverse=True)

uniq_num = len(balls)

if __DEUBG__:
    print('\n'*2)
    print(len(balls))
    print(balls)
    print(b2)

if uniq_num <= K:
    print(0)
else:
    total = 0
    for i in range(uniq_num-K):
        tmp = b2.pop()
        if __DEUBG__:
            print(tmp)
        total += tmp[-1]
    print(total)

Measured memory_bytes: 41500
import java.util.Scanner;

public class Main{
	
	private static long gcd(long m, long n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
	
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt(),A=sc.nextInt(),B=sc.nextInt();
		if(N*A<=B) {
			System.out.println(N*A);
		}else {
			System.out.println(B);
		}
		
		
		
		
		
		
		
		
		
		
	
		
		
}
}




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

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> parent;

    //-1で初期化。最初はすべてバラバラ
    UnionFind(int N){
        parent = vector<int>(N,-1);
    }

    //Aがどのグループに属しているか(Aの根)を調べる
    int root(int A){
        if(parent[A] < 0) return A;
        return parent[A]=root(parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A){
        return -parent[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B) {
    //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        //既にくっついているからくっつけない
        if(A == B) return false; 

        //大きいほう(A)に小さいほう(B)をくっつける
        //大小が逆ならひっくり返す
        if(size(A) < size(B)) swap(A,B);

        //Aのサイズを更新する
        parent[A] += parent[B];
        //Bの親をAに変更する
        parent[B] = A;

        return true;
    }

    //AとBが同じグループならtrueを返す
    bool same(int A, int B){
        return root(A)==root(B);
    } 
};
 
int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);

    int n;
    cin>>n;
    UnionFind X(100100);
    vector<vector<int>> vy(100100);
    vector<vector<int>> vx(100100);
    for (int i = 0; i < n;i++){
        int x, y;
        cin >> x >> y;
        vx[x].push_back(y);
        vy[y].push_back(x);
    }
    for (int i = 0; i < 100100;i++){
        if(vy[i].size()>1){
            for (int j = 1; j < vy[i].size();j++){
                X.connect(vy[i][0], vy[i][j]);
            }
        }
    }
    ll ans = 0;
    bool used[100100] = {};
    for (int i = 1; i < 100100;i++){
        if(!used[X.root(i)] && X.size(i)>1){
            used[X.root(i)] = true;
            bool visited[100100] = {};//count y
            ll y = 0, cnt=0;
            for (int j = 1; j < 100100;j++){
                if(X.same(i,j)){
                    for (auto k:vx[j]){
                        if(!visited[k]){
                            visited[k] = true;
                            y++;
                        }
                        cnt++;
                    }
                }
            }
            ans += y * X.size(i) - cnt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 8704
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int a= sc.nextInt(), b =sc.nextInt();
        int ans = b%a==0?a+b:b-a;
        System.out.println(ans);
    }
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/11  Problem: ABC 088 D / Link: http://abc088.contest.atcoder.jp/tasks/abc088_d  ----- */

inline bool IN(int y, int x, int H, int W) { return (0 <= y && y < H && 0 <= x && x < W); }

int bfs2D(pair<int, int> s, pair<int, int> t, int Height, int Width, VS & masu) {
	vector<vector<int> > d(Height, vector<int>(Width, 1e9));


	d[s.first][s.second] = 0;
	queue<pair<int, pair<int, int>>>q;
	q.push(make_pair(0, s));

	while (!q.empty()) {
		pair<int, pair<int, int>>a = q.front(); q.pop();
		int dist = a.first; pair<int, int> pos = a.second;
		if (d[pos.first][pos.second] < dist)continue;
		FOR(k, 0, 4) { //辺が存在するかはチェックしてないよ
			int ny = pos.first + DY[k]; int nx = pos.second + DX[k];
			if (IN(ny, nx, Height, Width)) {
				if (masu[ny][nx] == '.')// 辺の チェックしてるよ
					if (d[ny][nx] > d[pos.first][pos.second] + 1) {
						d[ny][nx] = d[pos.first][pos.second] + 1;
						q.push(make_pair(d[ny][nx], pair<int, int>(ny, nx)));
					}
			}
		}
	}

	return d[t.first][t.second]; // (int)
}
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	LL H, W; cin >> H >> W;
	vector<string> a(H);
	for (int i = 0; i < H; ++i) {
		cin >> a[i];
	}

	
	LL ans = 0LL;
	FOR(i, 0, H) {
		FOR(j, 0, W) {
			if (a[i][j] == '.')ans++;
		}
	}
	
	int res = bfs2D(PII(0, 0), PII(H - 1, W - 1), H, W, a);
	ans -= res+1;
	
	cout << (res==1e9?-1:ans) << "\n";

	return 0;
}


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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;
    vector<bool> ma(n, false);
    for (int i = 0; i < k; ++i)
    {
        int il;
        cin >> il;
        for (int j = 0; j < il; ++j)
        {
            int x;
            cin >> x;
            --x;
            ma[x] = true;
        }
    }
    int odp = 0;
    for (int i = 0; i < n; ++i)
        odp += ma[i];
    cout << n - odp;
    return 0;
}


Measured memory_bytes: 3656
n,m,q=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(q)]
ans=0
for i1 in range(1,m+1):
  for i2 in range(i1,m+1):
    for i3 in range(i2,m+1):
      for i4 in range(i3,m+1):
        for i5 in range(i4,m+1):
          for i6 in range(i5,m+1):
            for i7 in range(i6,m+1):
              for i8 in range(i7,m+1):
                for i9 in range(i8,m+1):
                  for i10 in range(i9,m+1):
                    tmp=0
                    arrs=[0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]
                    for a,b,c,d in arr:
                      if arrs[b]-arrs[a]==c:
                        tmp+=d
                    ans=max(ans,tmp)
print(ans)

Measured memory_bytes: 77340
import java.util.*;
 
public class Main{
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();  
      int b = sc.nextInt();  
      int c = sc.nextInt();  
      int x = sc.nextInt();  
      
      int count=0;
      
      for(int i = 0; i<=a ; i++){
       
        for(int j = 0; j<=b ; j++){
             
             for(int k = 0; k<=c ; k++){
                 
         	     if( 500*i + 100*j + 50*k == x){
            		count += 1;

            		
        	     }
             }   
         }
      }
    System.out.println(count);
  }
}

Measured memory_bytes: 35588
// abc048_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int H, W;
    cin >> H >> W;
    vector<string> S(2*H);
    REP(i, H){
        cin >> S[2*i];
        S[2*i+1] = S[2*i];
    }

    REP(i, 2*H) print(S[i]);


    return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = {}
for _ in range(N):
    a, b = map(int, input().split())
    if not a in A:
        A[a] = 0
    A[a] += b

c = 0
for a in sorted(A.keys()):
    c += A[a]
    if c >= K:
        print(a)
        break


Measured memory_bytes: 10588
package main

import "fmt"

func main() {
	var x1, y1, x2, y2, x3, y3, x4, y4 int
	fmt.Scan(&x1, &y1, &x2, &y2)
	dx := x2 - x1
	dy := y2 - y1
	x3 = x2 - dy
	y3 = y2 + dx
	x4 = x3 - dx
	y4 = y3 - dy
	fmt.Println(x3, y3, x4, y4)

}


Measured memory_bytes: 512
#include<stdio.h>

void makefibonatti(int *,int);

void makefibonatti(int *fibo,int n)
{
  int i;
  
  fibo[0] = 1;
  fibo[1] = 1;
  for(i=2;i<=n;i++)
    fibo[i] = fibo[i-2] + fibo[i-1];
}

int main()
{
  int n;
  int Fibo[44];

  scanf("%d",&n);

  makefibonatti(Fibo,n);

  printf("%d\n",Fibo[n]);

  return 0;
}



Measured memory_bytes: 2064
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <string.h>
#include <math.h>

using namespace std;

int main(){
	int N;
	bool result = false;
	cin >> N;

	for (int i = 0; i <= N / 4; ++i){
		for (int j = 0; j <= N / 7; ++j){
			if (i * 4 + j * 7 == N){
				result = true;
				break;
			}
		}
	}
	if (result)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int main()
{
    int x,y,z,a=0,b = 0;
    while(scanf("%d,%d,%d",&x,&y,&z)!=EOF)
    {
        if(x*x+y*y==z*z) a++;
        if(x==y) b++;
    }
    printf("%d\n%d\n",a,b);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll N, K;
  cin >> N >> K;

  if(N>K) N = N%K;

  ll x = N;
  ll y = K-N;

  cout << min(x, y) << endl;
  
  return 0;
}



Measured memory_bytes: 256
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N;
  cin >> N;
  vector<int> a(N);

  map<int, int> m;
  rep(i, N) {
    cin >> a[i];
    m[a[i]]++;
  }

  if (len(m) == 1) {
    if (N == a[0] + 1 || N >= a[0] * 2)
      cout << "Yes\n";
    else
      cout << "No\n";
  } else if (len(m) == 2) {
    sort(all(a));
    int A = a[N - 1];
    if (a[N - 1] - a[0] != 1) {
      cout << "No\n";
      return 0;
    }
    int mn = m[a[0]], mx = m[a[N - 1]];
    if (mn < A && (A - mn) * 2 <= mx)
      cout << "Yes\n";
    else
      cout << "No\n";

  } else {
    cout << "No\n";
  }
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define pi pair<int,int>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout<<#x<<": "<<x<<endl
#define clr(x,v) memset(x, v, sizeof(x))
#define dblout(x) cout << setprecision(x) << fixed;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const double eps = 1e-9;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;

ll fpow(ll x, ll y)
{
    ll res = 1;
    while(y > 0)
    {
        if(y & 1)
            res = (res % mod * x % mod) % mod;
        x = (x % mod * x % mod) % mod;
        y >>= 1;
    }
    return res;
}

void cp()
{
    ll n;
    cin >> n;
    ll ans = fpow(10, n);
    ans = (ans - 2 * fpow(9, n) + 2 * mod) % mod;
    ans = (ans + fpow(8, n)) % mod;
    cout << ans << endl;
}

int main()
{
    FASTIO;
    int t;
    t = 1;
    // cin >> t;
    while(t--)
    {
        cp();
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=21,M=(1ll<<N)+5,mod=1e9+7;
ll dp[M],arr[N][N];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    for(ll i=0;i<n;i++)for(ll j=0;j<n;j++)cin>>arr[i][j];
    dp[0]=1;
    for(ll mask=0;mask<(1ll<<n)-1;mask++){
        ll a=__builtin_popcountll(mask);
        for(ll b=0;b<n;b++){
            if(arr[a][b] && !(mask&(1<<b))){
                dp[mask^(1ll<<b)]+=dp[mask];
                dp[mask^(1ll<<b)]%=mod;
            }
        }
    }
    cout<<dp[(1ll<<n)-1];
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
    using namespace std;
     
    
    #define int long long
     
    const int N = 505;
     
    int n, k, sum = 0;
    int a[N];
     
    int check(int x)
    {
    	int reqd = 0;
    	vector<int> v;
    	for(int i = 1; i <= n; i++)
    	{
    		int cur = a[i] % x;
    		v.push_back(cur);
    	}
    	sort(v.begin(), v.end());
    	int l = 0, r = v.size() - 1;
    	int rem = 0;
    	while(l <= r)
    	{
    		if(rem <= 0)
    		{
    			rem += v[l];
    			reqd += v[l];
    			l++;
    		}
    		else
    		{
    			rem -= (x - v[r]);
    			reqd += (x - v[r]);
    			r--;
    		}
    	}
    	if(reqd > 2 * k)
    		return 0;
    	if(rem != 0)
    		return 0;
    	return 1;
    }
     
    int32_t main()
    {
    	
    	cin >> n >> k;
    	for(int i = 1; i <= n; i++)
    	{
    		cin >> a[i];
    		sum += a[i];
    	}
    	int ans = 1;
    	for(int i = 1; i * i <= sum; i++)
    	{
    		if(sum % i == 0)
    		{
    			if(check(i))
    				ans = max(ans, i);
    			if(check(sum / i))
    				ans = max(ans, sum / i);
    		}
    	}
    	cout << ans;
    	return 0;
    }

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int array[] = new int[N];
		int msum = 0;
		int mmin = 100000;

		for(int i = 0; i < N; i++) {
			array[i] = sc.nextInt();
			msum += array[i];
			if(mmin > array[i]) {
				mmin = array[i];
			}else {
				mmin = mmin;
			}
		}
		System.out.println((X-msum)/mmin + N);
	}

}


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

int main() {
    int n;
    cin >> n;
    int64_t power = 1;
    rep(i, n){
        power *= (i+1);
        power %= 1000000007;
    }
    cout << power << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;



bool gooddis(long long int n) {

	long long int a = 0;

	while (n >= a * a) {
		if (n == a * a)return true;
		a++;
	}

	return false;
}



vector<pair<long long int, long long int>> getPrimeElements(long long int num) {

	long long int firstnum = num;

	vector<pair<long long int, long long int>> result;
	pair<long long int, long long int> wk;

	if (num % 2 == 0) {
		wk.first = 2;
		wk.second = 0;
		while (num % 2 == 0) {
			wk.second++;
			num /= 2;
		}

		result.push_back(wk);
	}

	long long int waru = 3;

	while (true) {

		if (num % waru == 0) {
			wk.first = waru;
			wk.second = 0;
			while (num % waru == 0) {
				wk.second++;
				num /= waru;
			}

			result.push_back(wk);
		}
		waru += 2;

		if (waru * waru > num) break;

	}

	if (num != 1) {
		wk.first = num;
		wk.second = 1;
		result.push_back(wk);

	}

	return result;
}


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

	vector<long long int> a(n);
	vector<long long int> b(n);
	vector<long long int> c(n);
	
	for (auto& i : a)cin >> i;
	for (auto& i : b)cin >> i;
	for (auto& i : c)cin >> i;

	sort(a.begin(), a.end());
	//sort(b.begin(), b.end());
	sort(c.begin(), c.end());

	long long int ans = 0;


	for (auto& i : b) {

		long long int small, big;

		auto iter = lower_bound(a.begin(),a.end(), i);
		small = iter - a.begin();

		iter = upper_bound(c.begin(), c.end(), i);
		big = c.end() - iter;
		
		ans += small * big;
	}

	cout << ans << endl;


	 
	return 0;

}




Measured memory_bytes: 2560
fun main(args: Array<String>) {

    val list = readLine()!!.split(" ").map(String::toInt)

    val K = list[0]
    val X = list[1]

//    入力値判定
     if(K * 500 >= X) {
        println("Yes")
    } else if(K * 500 <= X) {
        println("No")
    }
}

Measured memory_bytes: 37796
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(a)			(a).begin(),(a).end()
#define REP(i, n)		for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)	for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF				(1000 * 1000 * 1000 * 2)
#define MOD				(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)		(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)		(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)	((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)		(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)		(!IsOdd((x)))						
#define M_PI			3.14159265358979323846
typedef long long		ll;
typedef pair<int, int>	P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	int N;
	cin >> N;

	static int F[100][10];
	static int P[100][11];
	REP(i, N) {
		REP(j, 10) {
			cin >> F[i][j];
		}
	}
	REP(i, N) {
		REP(j, 11) {
			cin >> P[i][j];
		}
	}

	int ans = -INF;
	for (int bitMap = 1; bitMap < (1 << 10); bitMap++) {
		int ansOne = 0;
		REP(i, N) {
			int eigyouCnt = 0;
			REP(j, 10) {
				if ((bitMap & 1 << j) && F[i][j]) {
					eigyouCnt++;
				}
			}
			ansOne += P[i][eigyouCnt];
		}
		ans = max(ans, ansOne);
	}

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


Measured memory_bytes: 256
<?php


[$N, $M, $R] = fscanf(STDIN, "%d%d%d");
$target = fscanf(STDIN, str_repeat("%d", $R));
$map = array_fill(1, $N, []);
for ($i = 0; $i < $M; $i++) {
    [$A, $B, $C] = fscanf(STDIN, "%d%d%d");
    $map[$A][$B] = $C;
    $map[$B][$A] = $C;
}

$dmap = [];
//for($target as $value){
for ($value = 1; $value <= $N; $value++) {

    $start = $value;
    $dmap[$start] = [];
    $dmap[$start][$start] = 0;
    $nowmap = &$dmap[$start];
    $queue = new SplQueue();
    insertQueue($start, 0);
    while ($queue->count() > 0) {
        $data = $queue->dequeue();
        if ($nowmap[$data[0]] == $data[1]) {
            insertQueue($data[0], $data[1]);
        }
//        var_dump($queue->count());
    }


}
$min = PHP_INT_MAX;
for ($k = 0; $k < $R; $k++) {
    $dp = array_fill(0, 2 ** $R, array_fill(0, $R, PHP_INT_MAX));
    $dp[0][0] = 0;
    for ($i = 0; $i < $R; $i++) {
        $dp[2 ** $i][$i] = 0;
    }
    for($i=0;$i<$R;$i++){
        check(2**$R-1,$i);
    }


//    for ($i = 0; $i < 2 ** $R; $i++) {
//        for ($j = 0; $j < $R; $j++) {
//            if($dp[$i][$j]===PHP_INT_MAX){
//                check($i,$j);
//            }
//        }
//    }

            //            if (($i & 1 << $j) > 0) {
//                for ($l = 0; $l < $R; $l++) {
//                    if($dp[$i - 2 ** $j][$l] === PHP_INT_MAX){
//
//                    }
//                    $dp[$i][$j] = min($dp[$i][$j],
//                        $dp[$i - 2 ** $j][$l]
//                        + $dmap[$target[$j]][$target[$l]]);
//                }
//            }

    $min = min($min, min($dp[2**$R-1]));
    $target[] = $target[0];
    unset($target[0]);
    $target = array_values($target);
}


echo $min;

function insertQueue($target, $dist){
    global $nowmap, $map, $queue;
    foreach($map[$target] as $key => $value){
        if(!isset($nowmap[$key]) || $nowmap[$key] > $dist + $value) {
            $nowmap[$key] = $dist + $value;
            $queue->enqueue([$key, $dist + $value]);
        }
    }
    return 0;
}

function check($i,$j)
{
    global $dp, $R, $dmap, $target;
    if (($i & 1 << $j) > 0) {
        for ($l = 0; $l < $R; $l++) {
            if ($dp[$i - 2 ** $j][$l] === PHP_INT_MAX) {
                check($i - 2 ** $j, $l);
            }
            $dp[$i][$j] = min($dp[$i][$j],
                $dp[$i - 2 ** $j][$l]
                + $dmap[$target[$j]][$target[$l]]);


        }

    }
}

Measured memory_bytes: 22120
#500
X, Y, A, B, C = map(int,input().split())
p0 = list(map(int,input().split()))
q0 = list(map(int,input().split()))
r0 = list(map(int,input().split()))
p = sorted(p0, reverse = True); p.append(0)
q = sorted(q0, reverse = True); q.append(0)
r = sorted(r0, reverse = True); r.append(0)

happy = 0
i = 0
j = 0
k = 0
red = 0
green = 0
white = 0

for _ in range(X+Y):
    if max(p[i], q[j], r[k]) == r[k]:
        happy += r[k]
        white += 1
        k += 1
    elif max(p[i], q[j], r[k]) == p[i]:
        if red < X:
            happy += p[i]
            red += 1
            i += 1
        elif q[j] >r[k] and green < Y:
            happy += q[j]
            green += 1
            j += 1
        else:
            happy += r[k]
            white += 1
            k += 1
    else:
        if green < Y:
            happy += q[j]
            green += 1
            j += 1
        elif p[i] >r[k] and red < X:
            happy += p[i]
            red += 1
            i += 1
        else:
            happy += r[k]
            white += 1
            k += 1
            
print(happy)

Measured memory_bytes: 23328
#include<stdio.h>

int S[10000];
int T[500];

int search(int* S, int n, int* T, int q){
    int i,j;
    int ans = 0;
    for(i=0; i<q;i++){
        for(j=0;j<n;j++){
            if(S[j]==T[i]){
                ans++;
                break;
            }
        }
    }
    return ans;
}


int main(void){
    int n,q;
    int i;
    scanf("%d", &n);
    for(i=0;i<n;i++){
        scanf("%d", &S[i]);
    }
    scanf("%d", &q);
    for(i=0;i<q;i++){
        scanf("%d", &T[i]);
    }
    
    printf("%d\n", search(S,n,T,q));
    return 0;
}

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

int main() {
  vector<vector<int>> T(3, vector<int> (3));
  for(int i=0; i<3; i++){
    int a, b, c; cin>>a>>b>>c;
    T.at(i)={a, b, c};
  }
  vector<int> A(3);
  vector<int> B(3);
  A[0]=0;
  A[1]=T[1][0]-T[0][0];
  A[2]=T[2][0]-T[0][0];
  B[0]=T[0][0];
  B[1]=B[0]+(T[0][1]-T[0][0]);
  B[2]=B[0]+(T[0][2]-T[0][0]);
  bool yes=1;
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(T[i][j]!=A[i]+B[j]) yes=0;
    }
  }
  if(yes) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

typedef long long int ll;


using namespace std;

int main(){
	int c1,c2,c3;
	while(cin>>c1>>c2>>c3){
		vector<int> a(11,1);
		a[c1]=0;
		a[c2]=0;
		a[c3]=0;
		int cnt=0;
		for(int i=1; i<11; i++){
			if(a[i]&&c1+c2+i<=20){
				cnt++;
			}
		}
		//cout<<cnt<<endl;
		if(cnt>=4)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1184
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

const ll INF=1e9;

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

  ll N;
  cin>>N;
  vector<ll> A(N),B(N);
  rep(i,N) cin>>A[i]>>B[i];

  vector<ll> S=A;
  vector<ll> E=B;
  sort(S.begin(),S.end());
  sort(E.begin(),E.end());

  if(N%2){
    int l=-1,r=-1;
    for(int i=0;i<N;i++){
      int z=lower_bound(E.begin(),E.end(),S[i])-E.begin();
      int w=N-(upper_bound(S.begin(),S.end(),S[i])-S.begin());
      if(2*z<N&&2*w<N){
        l=S[i];
        break;
      }
    }
    r=l;
    for(int i=0;i<N;i++){
      if(l>=E[i]) continue;
      int z=lower_bound(E.begin(),E.end(),E[i])-E.begin();
      int w=N-(upper_bound(S.begin(),S.end(),E[i])-S.begin());
      if(2*z<N&&2*w<N) r=E[i];
      else break;
    }

    ll ans=r-l+1;
    cout<<ans<<endl;
  }else{
    ll al=-1,ar=-1;
    {
      int l=-1,r=-1;
      for(int i=0;i<N;i++){
        int z=lower_bound(E.begin(),E.end(),S[i])-E.begin();
        int w=N-(upper_bound(S.begin(),S.end(),S[i])-S.begin());
        if(2*z<N&&2*w<=N){
          l=S[i];
          break;
        }
      }
      r=l;
      for(int i=0;i<N;i++){
        if(l>=E[i]) continue;
        int z=lower_bound(E.begin(),E.end(),E[i])-E.begin();
        int w=N-(upper_bound(S.begin(),S.end(),E[i])-S.begin());
        if(2*z<N&&2*w<=N) r=E[i];
        else break;
      }
      al=l;ar=r;
    }

    ll bl=-1,br=-1;
    {
      int l=-1,r=-1;
      for(int i=0;i<N;i++){
        int z=lower_bound(E.begin(),E.end(),S[i])-E.begin();
        int w=N-(upper_bound(S.begin(),S.end(),S[i])-S.begin());
        if(2*z<=N&&2*w<N){
          l=S[i];
          break;
        }
      }
      r=l;
      for(int i=0;i<N;i++){
        if(l>=E[i]) continue;
        int z=lower_bound(E.begin(),E.end(),E[i])-E.begin();
        int w=N-(upper_bound(S.begin(),S.end(),E[i])-S.begin());
        if(2*z<=N&&2*w<N) r=E[i];
        else break;
      }
      bl=l;br=r;
    }

    ll ans=(ar+br)-(al+bl)+1;
    cout<<ans<<endl;
  }



  return 0;
}


Measured memory_bytes: 9532
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
  int i,oblack=0,owhite=0,eblack=0,ewhite=0,ocolor,ecolor,emax,omax,num;
  int emin,omin,N;
  char str[100005],*p,s[100005];
  
  fgets(str,sizeof(str),stdin);
  p=strtok(str," \n");
  strcpy(s,p);
  N=strlen(s);
  
  for(i=0;i<N;i++){
    if(i%2==0 && s[i]=='0'){
      eblack++;
    }else if(i%2==0){
      ewhite++;
    }
    
    if(i%2==1 && s[i]=='0'){
      oblack++;
    }else if(i%2==1){
      owhite++;
    }
  }
  
  if(eblack>=ewhite){
    emax=eblack,ecolor=0;
    emin=ewhite;
  }else{
    emax=ewhite,ecolor=1;
    emin=eblack;
  }
  
  if(oblack>=owhite){
    omax=oblack,ocolor=0;
    omin=owhite;
  }else{
    omax=owhite,ocolor=1;
    omin=oblack;
  }
  
  if(emax==emin || omax==emin){
    num=emin+omin;
    printf("%d\n",num);
    return 0;
  }
  
  if(ecolor!=ocolor){
    num=emin+omin;
  }else if(emax>=omax){
    num=emin+omax;
  }else if(emax<omax){
    num=emax+omin;
  }
  
  printf("%d\n",num);
  
  
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 +7;

int main(){
    lli h,w,x,y;
    cin >> h >> w >> x >> y;
    cout << (long double)h*w/2 << " ";
    if(2*x == h and 2*y == w){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long int
int main(void){
	ll A,B,C,ans=0;
	scanf("%lld%lld%lld",&A,&B,&C);
	while(1){
		if(A%2==1 || B%2==1 || C%2==1)break;
		if(A==B && B==C){
			ans = -1;
			break;
		}
		ans++;
		ll a=A,b=B,c=C;
		A = (b+c)/2;
		B = (a+c)/2;
		C = (a+b)/2;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 128
/*
 * ID: ITP2_1_D
 * Problem: Vector 2
 */

#include <stdio.h>
#include <stdlib.h>

struct _child {
    int value;
    struct _child* child;
};

struct _parent {
    struct _child* child;
    struct _child* last;
};

int main(void)
{
    struct _parent *data;

    int slots, commands;
    scanf("%d %d", &slots, &commands);
    data = malloc(slots * sizeof(struct _parent));
    if (!data) {
        printf("malloc error at _parent\n");
        exit(1);
    }

    int i;
    for (i = 0; i < slots; i++) {
        data[i].child = NULL;
        data[i].last = NULL;
    }

    for (i = 0; i < commands; i++) {
        int slot, command;
        scanf("%d %d", &command, &slot);

        switch (command) {
                int value;
                struct _child *p, *q, *r;
            case 0:
                scanf("%d", &value);
                p = malloc(sizeof(struct _child));
                if (!p) {
                    printf("malloc error at _child\n");
                    exit(1);
                }
                p->value = value;
                p->child = NULL;

                q = data[slot].last;
                if (q) {
                    q->child = p;
                } else {
                    data[slot].child = p;
                }
                data[slot].last = p;
                break;

            case 1:
                q = data[slot].child;
                while (q) {
                    printf("%d", q->value);
                    q = q->child;
                    if (q)
                        putchar(' ');
                }
                printf("\n");
                break;

            case 2:
                q = data[slot].child;
                while (q) {
                    r = q->child;
                    free(q);
                    q = r;
                }
                data[slot].child = NULL;
                data[slot].last = NULL;
                break;
        }
    }

    return 0;
}



Measured memory_bytes: 17420
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int f(int S) {
  vector<bool> mem(2000000,false);
  int cnt = 1;
  while(true) {
    if(mem[S]) return cnt;
    mem[S] = true;
    cnt++;
    if(S % 2 == 0) S /= 2;
    else S = 3 * S + 1;
  }
  return -1;
}

int main() {
  int S;
  cin>>S;
  cout << f(S) << endl;
  return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

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

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

ll arr[51][51];
// ll dp[51][51][100001];
ll res[51][51];
ll mul[51][51];

ll MOD = 1e9+7;

void multiply(ll a[][51], ll b[][51], ll n) {
    
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            mul[i][j] = 0;
            for(int l = 0; l < n; l++) {
                mul[i][j] = (mul[i][j] + a[i][l]*b[l][j]) % MOD;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            a[i][j] = mul[i][j];
        }
    }
}

int main() {
    int n;
    ll K;
    cin >> n >> K;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> arr[i][j];
        }
    }

    // ------------dp-approach
    // for(int k = 0; k <= K; k++) {
    //     for(int i = 0; i < n; i++) {
    //         for(int j = 0; j < n; j++) {
    //             if(k == 0 && i == j) {
    //                 dp[i][j][k] = 1;
    //             }    
    //             else if(k == 1 && arr[i][j]) {
    //                 dp[i][j][k] = 1;
    //             }
    //             else {
    //                 for(int a = 0; a < n; a++) {
    //                     if(arr[i][a]) {
    //                         dp[i][j][k] = (dp[i][j][k] + dp[a][j][k-1]) % MOD;
    //                     }
    //                 }
    //             }
    //         }
    //     }
    // }
    // ll ans = 0;
    // for(int i = 0; i < n; i++) {
    //     for(int j = 0; j < n; j++) {
    //         ans = (ans + dp[i][j][K]) % MOD;
    //     }
    // }
    // cout << ans << "\n";

    // -----------divide-and-conquer
    for(int i = 0; i < n; i++) {
        res[i][i] = 1;
    }

    while(K > 0) {
        if(K%2) {
            multiply(res, arr, n);
        }
        multiply(arr, arr, n);
        K /= 2;
    }

    ll ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            ans = (ans + res[i][j]) % MOD;
        }
    }
    cout << ans << "\n";
    
	return 0;
}


Measured memory_bytes: 3500