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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

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

// 2 dimentional vector
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]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    k*=n;
    Vec a(n);
    map<ll,Vec> idx;
    //xが現れるのはv番目
    rep(i,n){
        cin>>a[i];
        idx[a[i]].pb(i);
    }

    //i番目は次に現れるのは自分含めてw[i]個
    Vec w(n);

    Each(kv,idx){
        ll s=kv.se.size();
        kv.se.pb(kv.se[0]+n);
        rep(i,s){
            w[kv.se[i]]=kv.se[i+1]-kv.se[i]+1;
        }
    }

    const ll inf = LLONG_MAX/3;
    const ll L = 60;

    VV nx{w};
    //i番目を処理した次の数字はw[i]つ先
    rep(_,L){
        //直前のベクトル
        Vec &x = nx.back();
        Vec y(n);
        rep(i,n){
            //inf超えないようにする
            y[i]=min(inf,x[i]+x[(i+x[i])%n]);
        }
        nx.pb(y);
    }

    ll cur = 0;
    for(int i=L;i>=0;i--){
        if(cur+nx[i][cur%n]<=k){
            cur+=nx[i][cur%n];
        }
    }
    if(cur==k){
        return 0;
    }
    Vec ans;
    set<ll> has;
    REP(i,cur%n,n){
        if(has.count(a[i])){
            while(1){
                ll l = ans.back();
                ans.pop_back();
                has.erase(l);
                if(l==a[i])break;
            }
        }else{
            ans.pb(a[i]);
            has.insert(a[i]);
        }
    }
    rep(i,ans.size()){
        cout<<ans[i];
        if(i<int(ans.size())-1)
            cout<<" ";
        else
            cout<<endl;
    }
    return  0;
}


Measured memory_bytes: 132836
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;
ll gcd(ll a, ll b) {
  if (b == 0) {
	  return a;
	}
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

int main() {
  ll n, m;
  cin >> n >> m;
  vector <ll> a(n);
  REP(i, n) {
	cin >> a[i];
	a[i] /= 2;
  }
  ll l = 1;
  REP(i, n) {
	l = lcm(l, a[i]);
	if (l > m) {
		cout << 0 << endl;
		return 0;
	  }
  }
  REP(i, n) {
	if (l / a[i] % 2 == 0) {
		cout << 0 << endl;
		return 0;
	  }
  }
  cout << (m / l + 1) / 2 << endl;
  return 0;
}


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

int main(){

 int N; cin>>N;
 string S; cin>>S;
 int R=0;
 rep(i,N) if(S[i]=='R') R++;
 int ans=R;
 rep(i,R) if(S[i]=='R') ans--;
 cout<<ans<<endl;
 
 return 0;
}


Measured memory_bytes: 3716
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
#include <cmath>
#include <stack>
#include <bitset>
#include <queue>

using namespace std;

#define int long long
#define MAX 1e18

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

    if(s.size() <= k) {
        cout << s << endl;
        return 0;
    }

    cout << s.substr(0, k) << "..." << endl;
    return 0;
}

Measured memory_bytes: 3608
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

int main()
{
	int k,x;
	cin>>k>>x;
	for(int i=x-k+1;i<=x+k-1;i++) cout<<i<<' ';
	cout<<endl;
	return 0;
}

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

using namespace std;

const int N = 5000000;
const int MOD = 1000000007;
typedef long long ll;

int n , m, fact[N+1],inv[N+1];

ll mul(ll a , ll b){
  return (a*b)%MOD;
}

ll adl(ll a , ll b){
  return (a+b)%MOD;
}

ll fast(ll a , ll b){
  if(!b)return 1ll;
  ll res = fast(a,b/2);
  res = mul(res,res);
  if(b&1) return mul(res,a);
  return res;
}

ll nck(ll n , ll k){
  return mul(fact[n],mul(inv[k],inv[n-k]));
}
ll pnk(ll n , ll k){
  return mul(fact[n],inv[n-k]);
}


int main(){
  cin >> n >> m;
  fact[0] = 1;
  inv[0] = fast(fact[0],MOD-2);
  for(int i = 1 ; i <= N;++i){
    fact[i] = mul(i,fact[i-1]);
    inv[i] = fast(fact[i],MOD-2);
  }
  ll perm = pnk(m,n);
  ll total = mul(perm,perm);
  ll res = 0;
  for (int i = 1; i <= n; ++i){
    ll tmp = mul(nck(n,i),pnk(m-i,n-i));
    if(i%2 == 0) tmp = adl(mul(tmp,-1),MOD);
    res = adl(res,tmp);
  }
  res = mul(res,perm);
  ll fn = (total-res+MOD)%MOD;
  cout << fn << endl;
  return 0;
}

Measured memory_bytes: 42696
N = int(input())
A = list(map(int, input().split()))
DO, DE = {}, {}
L, M = [], []
for i in range(N//2):
  if A[2*i] in DO:
    DO[A[2*i]] += 1
  else:
    DO[A[2*i]] = 1
  if A[2*i+1] in DE:
    DE[A[2*i+1]] += 1
  else:
    DE[A[2*i+1]] = 1
for i in DO:
  L.append([DO[i], i])
for j in DE:
  M.append([DE[j], j])
l, m = len(L)-1, len(M)-1
L.sort()
M.sort()
if L[l][1] != M[m][1]:
  S = N - L[l][0] - M[m][0]
else:
  if l == 0 and m == 0:
    S = N // 2
  else:
    if L[l][0] - L[l-1][0] >= M[m][0] - M[m-1][0]:
      S = N - L[l][0] - M[m-1][0]
    else:
      S = N - L[l-1][0] - M[m][0]
print(S)

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

#define INF 0x7fffffff

int main() {
	int	a,b,c,i,j,k,n,m,x,y,ans1 , ans = 0;
	string	str;

	cin >> n >> x >> y;

	vector< vector<int> > aa(n+1, vector<int>(n+1));
	for(i=1;i<=n-1;i++) {
		for(j=i+1;j<=n;j++) {
			aa[i][j] = j - i;
			if ((i<=x) && (y<=j)) {
				aa[i][j] = j - i - (y-x) + 1;
			} else if ((x<=i) && (y<=j)) {
				aa[i][j] = min( aa[i][j] , (i-x+1+(j-y)) );
			} else if ((x<=i) && (j<=y)) {
				aa[i][j] = min( aa[i][j] , (i-x+1+(y-j)) );
			} else if ((i<=x) && (j<=y)) {
				aa[i][j] = min( aa[i][j] , (x-i+1+(y-j)) );
			}
		}
	}
/*
	for(i=1;i<=n;i++) {
		for(j=1;j<=n;j++) {
			cout << aa[i][j] << " ";
		}
		cout << endl;
	}
*/
	vector<int> an(n+1);
	for(i=1;i<=n-1;i++) {
		for(j=i+1;j<=n;j++) {
			 an[aa[i][j]]++;
		}
	}
	for(i=1;i<n;i++) {
		cout << an[i] << endl;
	}

}


Measured memory_bytes: 16000
n = int(input())
S = list(input().split())
cnt = [0, 0, 0, 0]
for i in range(n):
    if S[i] == "G":
        cnt[0] += 1
    elif S[i] == "W":
        cnt[1] += 1
    elif S[i] == "P":
        cnt[2] += 1
    else:
        cnt[3] += 1
if 0 in cnt:
    print("Three")
else:
    print("Four")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;
//using namespace boost::multiprecision;

int modpow(int a, int p){
    if(p == 0) return 1;

    if(p % 2 == 1){
        ll tmp = a;

        tmp = tmp * modpow(a, p - 1) % MODN;

        return tmp;
    }else{
        ll tmp = modpow(a, p / 2);

        tmp = tmp * tmp % MODN;

        return tmp;
    }
}

class ModInt{
public:
    long long n;
    int p;

    ModInt(){
    }

    //値と割る値を受け取って、オブジェクトを返す
    ModInt(long long _n, int _p){
        p = _p;
        n = _n % _p;

        //負の値を受け取ったときには正の値に戻す
        if(n < 0){
            n += p;
        }
    }

    ModInt operator+(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n += a.n;

        if(tmp.n > tmp.p){
            tmp.n -= tmp.p;
        }
        
        return tmp;
    }

    ModInt operator-(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n -= a.n;

        if(tmp.n < 0){
            tmp.n += tmp.p;
        }

        return tmp;
    }

    ModInt operator*(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = (tmp.n * a.n) % tmp.p;

        return tmp;
    }

    int modpow(int b, int k){
        if(k == 0){
            return 1;
        }else if(k % 2 == 1){
            long long tmp = b;
            tmp = tmp * modpow(b, k - 1) % p;
            
            return tmp;
        }else{
            long long tmp = modpow(b, k / 2);
            return tmp * tmp % p;
        }
    }

    int modinv(int b){
        return modpow(b, p - 2);
    }

    ModInt operator/(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = tmp.n * modinv(a.n) % tmp.p;
        return tmp;
    }
};


int main(){

    int n,k;
    cin >> n >> k;

    vector<vector<ModInt>> pascal(2001, vector<ModInt>(2001));

    rep(i, 2001){
        pascal[i][0] = ModInt(1, MODN);
    }

    pascal[1][1] = ModInt(1,MODN);

    for(int i = 2; i <= 2000; i++){
        for(int j = 1; j <= i; j++){
            if(i == j){
                pascal[i][j] = ModInt(1,MODN);
            }else{
                pascal[i][j] = pascal[i - 1][j - 1] + pascal[i - 1][j];
            }
        }
    }

    for(int i = 1;i <= k; i++){

        ll ans = 0;
        ll tmpp = n - k - (i - 1);

        if(tmpp >= 0){

            ModInt tmp1 = pascal[n - k + 1][i];
            
            ModInt tmp2 = pascal[k - 1][i - 1];

            //cerr << tmp1.n << " ";
            //cerr << tmp2.n << endl;

            ll tmp = tmp1.n * tmp2.n % MODN;

            ans  = tmp;
        }

        cout << ans << endl;

    }

    return 0;
}

Measured memory_bytes: 62848
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<queue> 
#include<stack>
#include<cstdio>

using namespace std;

struct Node{
	int key;
	Node *parent, *left, *right;	
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}
	
	z->parent = y;
	
	if(y == NIL){
		root = z;
	}else{
		if(z->key < y->key){
			y->left = z;
		}else{
			y->right = z;
		}
	}
}

Node* find(Node *x, int k){
	while(x != NIL && k != x->key){
		if(k < x->key){
			x = x->left;
		}else{
			x = x->right;
		}
	}
	return x;
}

void inorder(Node *u){
	if(u == NIL) return;
	inorder(u->left);
	cout<<" "<<u->key;
	inorder(u->right);
}
void preorder(Node *u){
	if(u == NIL) return;
	cout<<" "<<u->key;
	preorder(u->left);
	preorder(u->right);
}

int main(){
	int n;
	cin>>n;
	
	string str;
	for(int i=0; i<n; i++ ){
		cin>>str;
		if(str[0] == 'i'){
			int k;
			scanf("%d",&k);
			insert(k);
		}else if(str[0] == 'f'){
			int k;
			scanf("%d",&k);
			if(find(root,k) != NIL){
				cout<<"yes"<<endl;
			}else{
				cout<<"no"<<endl;
			}
		}else{
			inorder(root);
			cout<<endl;
			preorder(root);
			cout<<endl;
		}
	}
	
	return 0;
}

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

#define ll long long
#define all(x) (x).begin(), (x).end()
const long long INF = 1LL << 60;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //(i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

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

    // 入力
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    // 処理
    int train = min(a, b);
    int bus   = min(c, d);

    // 出力
    cout << train + bus << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
a_s = [int(v) for v in input().split()]
#print(a_s)

c_s = [a_s[i] - (i+1) for i in range(0, n)]
#print(c_s)

c_s.sort()
#print(c_s)

med = c_s[n // 2]
d_s = [abs(c - med) for c in c_s]
#print(d_s)
ans = sum(d_s)
print(ans)

Measured memory_bytes: 27684
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e18
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  while(1){
    int a, b;
    string op;
    cin >> a >> op >> b;
    if(op=="?")
      break;
    if (op == "+")
      cout << a + b << endl;
    else if(op=="-")
      cout << a - b << endl;
    else if(op=="*")
      cout << a * b << endl;
    else
      cout << a / b << endl;
  }

  return 0;
}



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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N, M; cin >> N >> M;
    vector<ll> h(N), ma(N, 0);
    rep(i, N) cin >> h[i];
    rep(i, M){
        int a, b; cin >> a >> b;
        a--; b--;
        ma[a] = max(ma[a], h[b]);
        ma[b] = max(ma[b], h[a]);
    }

    int res = 0;
    rep(i, N){
        if(h[i] > ma[i]) res++;
    }

    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int intpow(int x,int y){
  double a=x,b=y;
  return pow(a,b);
}//(x,y) xをy乗する

main(){
    int n,m;
    for (int i=0;i<3000;i++){
        cin >> n >> m;
        if (n==0&&n==m) return 0;
        if (n>m) swap(n,m);
        cout << n << " " << m << endl;
    }
}




Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Test | diff Test.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Test.cpp && ./a.out

/*

 5/27/2020

 9:30-

 */

const int MAX_N=1e2+10;
LL wws[MAX_N],vs[MAX_N],W;
int N;

const LL Inf=1e13;
LL dp[MAX_N][MAX_N][MAX_N*3];
void solve() {
  REPE(i,N)REPE(j,N)REPE(k,N*3) dp[i][j][k]=-Inf;
  dp[0][0][0]=0;
  LL w0=wws[0];
  REP(i,N)REP(j,N)REPE(k,N*3) {
    SMAX(dp[i+1][j+1][k+wws[i]-w0],dp[i][j][k]+vs[i]);
    SMAX(dp[i+1][j][k],dp[i][j][k]);
  }
  LL res=0;
  REPE(j,N)REPE(k,N*3) if(dp[N][j][k]>=0&&w0*j+k<=W) {
    SMAX(res,dp[N][j][k]);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;

  cin>>N>>W;
  REP(i,N) cin>>wws[i]>>vs[i];
  solve();

  return 0;
}


Measured memory_bytes: 28800
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define P pair<int,int>
#define PI 3.141592653589793
const int INF = 1001001001;
const ll MX = 1e18;
const int mod = 1000000007;
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}


int main() {
	int s;
	cin >> s;
	vector<int> dp(s+1);
	dp[0] = 1;
	int x = 0;
	for (int i = 1; i <= s;i++) {
		if (i >= 3) {
			x += dp[i - 3];
			x %= mod;
			dp[i] += x;
			dp[i] %= mod;
		}
	}
	cout << dp[s] << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define all(x) (x).begin(),(x).end()
const int INF=500+5;
const int N=4000+5;
const ll oo=1e18+5;
const ll mod=998244353;

int n,m;
vector<int> xs,ys;
int ban[N][N][4];
int used[N][N];
int a[N],b[N],c[N],d[N],e[N],f[N];

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

void bfs(int x,int y){
	queue<pair<int,int>> Q;
	Q.push({x,y});
	used[x][y]=1;
	while(!Q.empty()){
		int u=Q.front().first;
		int v=Q.front().second;
		Q.pop();
		for(int dir=0;dir<4;++dir){
			if(ban[u][v][dir]) continue;
			int new_u=u+dx[dir];
			int new_v=v+dy[dir];
			if(new_u>=0&&new_u<=(int)xs.size()&&new_v>=0&&new_v<=(int)ys.size()){
				if(!used[new_u][new_v]){
					used[new_u][new_v]=1;
					Q.push({new_u,new_v});
				}
			}
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		cin>>a[i]>>b[i]>>c[i];
		xs.push_back(a[i]);
		xs.push_back(b[i]);
		ys.push_back(c[i]);
	}
	for(int i=1;i<=m;++i){
		cin>>d[i]>>e[i]>>f[i];
		xs.push_back(d[i]);
		ys.push_back(e[i]);
		ys.push_back(f[i]);
	}
	sort(all(xs));
	sort(all(ys));
	xs.resize(unique(all(xs))-xs.begin());
	ys.resize(unique(all(ys))-ys.begin());
	for(int i=1;i<=n;++i){
		int id_a=lower_bound(all(xs),a[i])-xs.begin();
		int id_b=lower_bound(all(xs),b[i])-xs.begin();
		int id_c=lower_bound(all(ys),c[i])-ys.begin();
		for(int j=id_a+1;j<=id_b;++j) ban[j][id_c][1]=1,ban[j][id_c+1][2]=1;
	}
	for(int i=1;i<=m;++i){
		int id_d=lower_bound(all(xs),d[i])-xs.begin();
		int id_e=lower_bound(all(ys),e[i])-ys.begin();
		int id_f=lower_bound(all(ys),f[i])-ys.begin();
		for(int j=id_e+1;j<=id_f;++j) ban[id_d][j][3]=1,ban[id_d+1][j][0]=1;
	}
	int x=lower_bound(all(xs),0)-xs.begin();
	int y=lower_bound(all(ys),0)-ys.begin();
	bfs(x,y);
	for(int i=0;i<=(int)xs.size();++i){
		if(used[i][0]||used[i][(int)ys.size()]){
			return cout<<"INF",0;
		}
	}
	for(int i=0;i<=(int)ys.size();++i){
		if(used[0][i]||used[(int)xs.size()][i]){
			return cout<<"INF",0;
		}
	}
	ll ans=0;
	for(int i=1;i<(int)xs.size();++i){
		for(int j=1;j<(int)ys.size();++j){
			if(used[i][j]) ans+=1ll*(xs[i]-xs[i-1])*(ys[j]-ys[j-1]);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 183496
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

large pack(long long y, long long x) {
    return (y << 32) | x;
}

int main()
{
    int h, w, m; // 300'000 x 300'000, and 300'000
    cin >> h >> w >> m;
    auto target_pos = unordered_set<large>(m);
    auto x_counter = map<int, int>{};
    auto y_counter = map<int, int>{};
    for (auto i = 0; i < m; ++i) {
        int y, x;
        cin >> y >> x;
        x_counter[x]++;
        y_counter[y]++;
        target_pos.emplace(pack(y, x));
    }

    auto xcnt = 0;
    auto ycnt = 0;
    for (auto [x, cnt] : x_counter) {
        xcnt = max(xcnt, cnt);
    }
    for (auto [y, cnt] : y_counter) {
        ycnt = max(ycnt, cnt);
    }
    auto atmost = xcnt + ycnt;

    auto x_max_pos = vector<int>{};
    for (auto [x, cnt] : x_counter) {
        if (cnt == xcnt) x_max_pos.push_back(x);
    }
    auto y_max_pos = vector<int>{};
    for (auto [y, cnt] : y_counter) {
        if (cnt == ycnt) y_max_pos.push_back(y);
    }

    auto found = false;
    for (auto x : x_max_pos) {
        for (auto y : y_max_pos) {
            auto itr = target_pos.find(pack(y, x));
            if (itr == target_pos.end()) {
                found = true;
                break;
            }
        }
    }


    cout << (xcnt + ycnt - (found ? 0 : 1)) << endl;
    return 0;
}


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

bool check(vector<P> s) {
  int h = 0;
  for (auto p : s) {
      int b = h+p.first;
      if (b < 0) return false;
      h += p.second;
  }
  return true;
}
 
int main() {
  int n;
  cin >> n;
  int total = 0;
  vector<P> ls, rs;
  rep(i,n) {
    int b = 0, h = 0;
    string s;
    cin >> s;
    for (char c : s) {
      if (c == '(') ++h; else --h;
      b = min(b,h);
    }
    if (h > 0) ls.emplace_back(b,h);
    else rs.emplace_back(b-h,-h);
    total += h;
  }
  sort(ls.rbegin(), ls.rend());
  sort(rs.rbegin(), rs.rend());
  if (check(ls) && check(rs) && total == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 18924
def find_power(n):
    # 0!からn!までのびっくりを出してくれる関数
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(10**9+7)
    return powlist
def find_inv_power(n):
    #0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist
def combi(a,b,n,r,mod):
    if n<r:
        return 0
    elif n>=r:
        return (a[n]*b[r]*b[n-r])%(mod)
x,y=map(int,input().split())
power=find_power(1000000)
invpower=find_inv_power(1000000)
if (2*x-y)%3==0 and (2*y-x)%3==0:
    if (2*x-y)>=0 and (2*y-x)>=0:
        a=(2*y-x)//3
        b=(2*x-y)//3
        print(combi(power,invpower,a+b,b,10**9+7))
    else:
        print(0)
else:
    print(0)
    

Measured memory_bytes: 121716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    ll a, b;
    cin >> a >> b;
    rep(i, 1, 1e5){
        if(a == (ll)(i*0.08) && b == (ll)(i*0.1)){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 100100;
int a[maxn];
int b[maxn];

int main() {
    #ifdef LOCAL
    assert(freopen("c.in", "r", stdin));
    #else
    #endif
    int w, h;
    cin >> w >> h;
    forn (i, w)
        cin >> a[i];
    forn (i, h)
        cin >> b[i];
    sort(a, a + w);
    sort(b, b + h);
    int pa = 0, pb = 0;
    ll res = 0;
    while (pa < w || pb < h) {
        if (pb == h || (pa != w && a[pa] <= b[pb])) {
            res += a[pa] * (ll(h + 1) - pb);
            ++pa;
        } else {
            res += b[pb] * (ll(w + 1) - pa);
            ++pb;
        }
    }
    cout << res << '\n';
}


Measured memory_bytes: 1024
#line 1 "ALDS1_3_A.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A&lang=jp"
#line 1 "/Users/knaga/programming/procon_library/macro/macros.hpp"



/*
@title Macro
@category template
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;

template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 >& p) {
  os << "{" <<p.first << ", " << p.second << "}";
  return os;
}
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;

const double PI = acos(-1.0);

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";


#line 1 "/Users/knaga/programming/procon_library/data_structure/stack.hpp"


#line 4 "/Users/knaga/programming/procon_library/data_structure/stack.hpp"
/*
@title stack
*/
template< typename T >
class Stack{
  public:
    int N;
    int top = 0;
    T data[20000];
    Stack(int sz):N(sz), top(0){}
    void push(int x){
        if(isFull()){
            cerr << "これ以上入りません" << endl;
            return;
        }
        data[top] = x;
        top++;
    }
    int pop(){
        if(isEmpty()){
            cerr << "中身は空です" << endl;
            return -1;
        }
        top--;
        return data[top];
    }
    bool isFull(){
        return top >= N;
    }
    bool isEmpty(){
        return top == 0;
    }
    void show(){
        dump(top);
        for(int i = 0; i < top;i++){
            cerr << data[i] << " ";
        }
        cerr << endl;
    }
};

#line 4 "ALDS1_3_A.test.cpp"

int main(){
    Stack<int> S(1000);
    string c;
    while(cin >> c){
        if(c == "+"){
            int a = S.pop();
            int b = S.pop();
            S.push(b + a);
        }
        else if(c == "-"){
            int a = S.pop();
            int b = S.pop();
            S.push(b - a);
        }
        else if(c == "*"){
            int a = S.pop();
            int b = S.pop();
            S.push(b * a);
        }
        else{
            int x = stoi(c);
            S.push(x);
        }
    }
    cout << S.pop() << endl;
}



Measured memory_bytes: 3240
k = int(input())

ans = []
def add(t,d,v):
  if d == 0:
    ans.append(v)
  else:
    if t != 0:
      add(t-1, d-1, v+str(t-1))    
    add(t, d-1, v+str(t))
    if t != 9:
      add(t+1, d-1, v+str(t+1))
  
for d in range(10):
  for t in range(1,10):
    add(t,d,str(t))
  if len(set(ans)) > k:
    break

ans = [int(a) for a in ans]
ans = sorted(list(set(ans)))
print(ans[k-1])  

Measured memory_bytes: 32360
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
using Graphl = vector<vector<ll>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
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; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const long long minusINF = -(1LL << 40);
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    int n; cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    rep(cx, 101)
    {
        rep(cy, 101)
        {
            int H = 1;
            rep(i, n) if (h[i] > 0) H = h[i] + abs(cx - x[i]) + abs(cy - y[i]);
            int ok = 1;
            rep(i, n) if (max(H - abs(cx - x[i]) - abs(cy - y[i]), 0) != h[i]) ok = 0;
            if (ok)
            {
                printf("%d %d %d\n", cx, cy, H);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	double angka;
	double tempSum=0.0000;
	scanf("%lf", &angka);
	for(long long int i=1;i<=angka;i++){
		double tempI=0;
		if((i%3==0)||(i%5==0)){
			continue;
		}
		else{
			tempI=i/10.000;
			tempSum+=tempI;
		}
		//printf("Hasil angka %lld dengan hasil temp %lf dengan tempI %lf\n", i, tempSum, tempI);
	}
	long long int hasil=tempSum*10;
	printf("%lld\n", hasil);
	return 0;
}

Measured memory_bytes: 1748
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <bits/stdc++.h>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

int main() {
    string A,B;
    int a=read(),b=read();
    for (re int i=1;i<=a;++i) A+=b+'0';
    for (re int i=1;i<=b;++i) B+=a+'0';
    if (A<B) cout<<A<<endl;
    else cout<<B<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  double w, h, x, y;
  cin >> w >> h >> x >> y;
  cout << w*h/2 << " ";
  if(x == w/2 && y == h/2)
    cout << 1 << endl;
  else
    cout << 0 << endl;
}

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


void reverse(char *s, int len){
  char tmp;
  if (len > 1){
    tmp = s[0];
    s[0] = s[len-1];
    s[len-1] = tmp;
    reverse(s+1, len-2);
  }
}

int main(){
  char buf[21];

  while(scanf("%s", buf) == 1){
    reverse(buf, strlen(buf));
    printf("%s\n", buf);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#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 srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,p;
    cin >> n >> p;
    ll st = 0;
    vl vec(n);
    rep(i,n){
        ll w,b;
        cin >> w >> b;
        vec[i] = (100-p)*w+p*b;
        st -= p*b;
    }
    sort(all(vec));
    int ans = 0;
    for(;;++ans){
        if(st >= 0){
            break;
        }
        st += vec[n-1-ans];
    }
    cout << ans << "\n";
    return 0;
}


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    REP(a, A + 1)
    {
        REP(b, B + 1)
        {
            REP(c, C + 1)
            {
                if (500 * a + 100 * b + 50 * c == X)
                    ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	int n, x;
	cin >> n >> x;

	vector<int> l(n);

	rep(i, n)
	{
		cin >> l[i];
	}

	int ans = 1;
	int tmp=0;

	rep(i, n)
	{
		if (tmp + l[i] <= x)
		{
			ans++;

		}
		tmp += l[i];
	}

	cout << ans << endl;

}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0): x(x),y(y){}

  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }

  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }

  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }

};

//rad は角度をラジアンで持たせること
Point rotate(Point a,double rad){ return Point(cos(rad)*a.x - sin(rad)*a.y,sin(rad)*a.x + cos(rad)*a.y); }

const double DINF = 1e20;
int n;
Point ps[2][1010],tmp[1010];

inline double getDist(Point p){ return sqrt(p.x*p.x+p.y*p.y); }

bool comp_arg(const double &a,const double &b) { return !equals(fabs(a),fabs(b)) && fabs(a) < fabs(b); }

void compute(){
  Point grv[2] = {Point(),Point()};
  rep(i,2) rep(j,n) grv[i] = grv[i] + ps[i][j];
  rep(i,2) grv[i] = grv[i] / (double)n;
  rep(i,2) rep(j,n) ps[i][j] = ps[i][j] - grv[i];
  sort(ps[0],ps[0]+n);
  sort(ps[1],ps[1]+n);

  vector<double> arg_buf;
  rep(i,n) rep(j,n) {
    double dist[2] = { getDist(ps[0][i]), getDist(ps[1][j]) };
    if( !equals(dist[0],dist[1]) ) continue;
    double arg = atan2(ps[0][i].y,ps[0][i].x) - atan2(ps[1][j].y,ps[1][j].x);
    arg_buf.push_back(arg);
  }

  sort(arg_buf.begin(),arg_buf.end(),comp_arg);
  arg_buf.erase(unique(arg_buf.begin(),arg_buf.end()),arg_buf.end());

  rep(i,(int)arg_buf.size()){
    double arg = arg_buf[i];
    rep(j,n) tmp[j] = rotate(ps[1][j],arg);
    sort(tmp,tmp+n);
    bool failed = false;
    rep(j,n) if( !( tmp[j] == ps[0][j] ) ) { failed = true; break; }
    if( !failed ) { printf("%.11lf\n",fabs(arg)); break; }
  }

}

int main(){
  while( cin >> n, n ){
    rep(i,2) rep(j,n) cin >> ps[i][j].x >> ps[i][j].y;
    compute();
  }
  return 0;
}

Measured memory_bytes: 3360
import java.util.Scanner;

class Main{
	static int n;
	static long ans = 1000000000;
	static int[] memo;
	static int[] dp;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		int ans = n + m/2;
		System.out.print(ans);
	}
}







class Pair implements Comparable{
	int from;
	int end;
	int dis;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return dis - otherpair.dis;
	}
}


Measured memory_bytes: 21204
#include<iostream>
#include<vector>
#include<string>
#define ll long long
using namespace std;

int main(){
    ll a,b,k;
    cin>>a>>b>>k;
    if(k>=a){
        k=k-a;
        a=0;
    }else{
        cout<<a-k<<" "<<b<<endl;
        return 0;
    }
    if(k>=b){
        b=0;
    }else{
        b=b-k;
    }
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <random>
#include <chrono>
#include <algorithm>
#define rep(i, x) for(ll i = 0; i < x; i++)
using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9+7;
const ll N = 5e5+5, inf = 1e9+5000;
ll add(ll x, ll y) { x += y; if (x >= MOD) return x - MOD; return x; }
ll sub(ll x, ll y) { x -= y; if (x < 0) return x + MOD; return x; }
ll mult(ll x, ll y) { return (x * y) % MOD; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int x; cin >> x;
  int kyu = 8;
  for (int i = 400; i < 2000; i+=200) {
    if (x < i+200) {
      cout << kyu << endl;
      break;
    }
    kyu--;
  }

  return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<string> dp[n + 1][n + 1];
    dp[1][1].emplace_back("a");
    for (int i = 2; i <= n; i++) {
        for (int k = 1; k <= i; k++) {
            vector<string> next;
            for (auto s: dp[i - 1][k]) {
                for (int l = 0; l < (int)s.size(); l++) {
                    next.emplace_back(s + s[l]);
                }
            }
            for (auto s: dp[i - 1][k - 1]) {
                set<char> sc;
                for (auto c: s) {
                    sc.emplace(c);
                }
                next.emplace_back(s + char('a' + sc.size()));
            }
            dp[i][k] = next;
        }
    }
    set<string> ans;
    for (auto s: dp[n]) {
        for (auto a: s) {
            ans.emplace(a);
        }
    }
    for (auto a: ans) {
        cout << a << endl;
    }
    return 0;
}


Measured memory_bytes: 294436
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    std::string s;std::cin>>s;
    if(s=="zyxwvutsrqponmlkjihgfedcba"){
        std::cout<<-1<<'\n';
    }
    if(s.size()<26u){
        std::vector<lint>ckd(26);
        for(char c:s)ckd.at(c-'a')++;
        for(lint i=0;i<26;i++){
            if(ckd.at(i))continue;
            std::cout<<s<<char('a'+i)<<'\n';
            return 0;
        }
    }else{
        std::vector<lint>ckd(26);
        for(lint i=24;i>=0;i--){
            ckd.at(s.at(i+1)-'a')++;
            if(s.at(i)>s.at(i+1))continue;
            for(lint j=s.at(i)-'a'+1;j<26;j++){
                if(!ckd.at(j))continue;
                std::cout<<s.substr(0,i)<<char('a'+j)<<'\n';
                return 0;
            }
        }
    }
}


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

int main() {

    vector<int> result (51);

    for (int a = 0; a < 10; a++) {
        for (int b = 0; b < 10; b++) {
            for (int c = 0; c < 10; c++) {
                for (int d = 0; d < 10; d++) {
                    result[a+b+c+d] += 1;
                }
            }
        }
    }

    int n;
    while (cin >> n) {
        cout << result[n] << endl;
    }
     
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int pt[123456], n, m, p[123456], q[123456];
void f() {
	for (int i = 1; i <= n; i++)pt[i] = i;
	return;
}
int root(int i) {
	if (pt[i] == i)return i;
	else return pt[i] = root(pt[i]);
}
void unite(int a, int b) {
	pt[root(b)] = root(a);
	root(b);
	return;
}
signed main() {
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> p[i];
		q[p[i]] = i;
	}
	f();
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		unite(a, b);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)if (root(q[i]) == root(i))ans++;
	cout << ans << endl;
}

Measured memory_bytes: 2560
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as U

-- n := V.length v + 1
-- v ! i = 表が i 枚、裏が n - i 枚出る確率
solve :: U.Vector Double -> U.Vector Double
solve ps = U.foldl' step (U.singleton 1) ps
  where
    step !vec !p = U.zipWith (\u v -> p * u + (1 - p) * v) (0 `U.cons` vec) (vec `U.snoc` 0)

main = do
  n :: Int <- readLn
  -- 1 <= n <= 2999, n is odd
  ps :: U.Vector Double <- U.fromListN n . map (read . BS.unpack) . BS.words <$> BS.getLine
  let result = solve ps
  -- U.length result == n + 1
  print $ U.sum $ U.drop (n `quot` 2 + 1) result


Measured memory_bytes: 2428
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int N;
	cin >> N;
	int x = (to_string(N)).length();//xはNの桁数
	ll cnt = 0;
	for (int i = 0; i < x - 1; i += 2) {
		cnt += ll(9 * pow(10, i));
	}
	if (x % 2 != 0) {
		cnt += (N - ll(pow(10, x - 1)) + 1);
	}
	cout << cnt << endl;
	return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  string s;
  cin >> s;

  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }
}


Measured memory_bytes: 3620
import java.io._
import scala.io.StdIn.{readInt, readLine}

object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }

  def insert(tree:Node, key:Node) = {
    val keyNode = key
    def getNodeToInsert(node:Node):Node =
      if(node.key > keyNode.key) {
        if(node.left == null) node
        else getNodeToInsert(node.left)
      } else {
        if(node.right == null) node
        else getNodeToInsert(node.right)
      }

    val target = getNodeToInsert(tree)

    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }

  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }

  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<100) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }

  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)

    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 286768