akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <map>	
#include <cstdlib>
#include <algorithm>
#include <queue>
using namespace std;

map<vector<int>,int> done;
vector<int> an;
int n;


int bfs(vector<int> p){
	
	queue< vector<int> > Q;
	Q.push(p);
	done[p] = 0;
	while(Q.size()){

		vector<int> q = Q.front(); Q.pop();
		int curC = done[q];
		if( curC >= 4 ) continue;
		int counter = 0, flag = 0;
		for(int i = 0 ; i < n ; i++){
			for(int j = i+1 ; j < n ; j++){
				reverse(q.begin()+i,q.begin()+j+1);
				if( !done.count(q) ){
					//for(int j = 0 ; j < q.size() ; j++) cout << q[j] << " "; cout << endl;
					done[q] = curC + 1;
					Q.push(q);
				}
				reverse(q.begin()+i,q.begin()+j+1);
			}
		}
	}
}

int curAns = 0;

vector<int> c;
map<vector<int>,int> done2;

int dfs(int depth,int lim){
	if( depth > lim ) return 0;
	if( done2[c] ) return 0;
	else done2[c] = true;
	
	if( done.count(c) ){
		curAns = min(curAns,depth+done[c]);
		return 0;
	}
	if( curAns <= depth || depth  >= n - 5) return 0;
	
	for(int i = 0 ; i < n ; i++){
		for(int j = i+1 ; j < n ; j++){
			reverse(c.begin()+i,c.begin()+j+1);
			dfs(depth+1,lim);
			reverse(c.begin()+i,c.begin()+j+1);
		}
	}
}

int main(){
	
	cin >> n;
	vector<int> v(n);
	for(int i = 0 ; i < n ; i++) cin >> v[i];
	
	an = v;
	sort(an.begin(),an.end());
	bfs(an); 
	curAns = 12;
	c = v;
	done2.clear();dfs(0,1);
	done2.clear();dfs(0,2);
	done2.clear();dfs(0,3);
	done2.clear();dfs(0,4);
	done2.clear();dfs(0,5);
	cout << curAns << endl;
}

Measured memory_bytes: 49248
"use strict";
    
const main = arg => {
    const T = parseInt(arg.split("\n")[0]);
    const B = parseInt(arg.split("\n")[1]);
    const H = arg.split("\n")[2];
    
    console.log(((T + B) * H) / 2);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

long long n;
vector<vector<long long> > d(n, vector<long long>(n));

void warshall_floyd(long long n){
    for(long long k = 0;k < n;k++){ /*経由する頂点*/
        for(long long i = 0;i < n;i++){ /*始点*/
            for(long long j = 0;j < n;j++){ /*終点*/
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]); /*距離*/
            }
        }
    }
}

int main(){
    
    cin >> n;
    
    vector<vector<long long> > a(n, vector<long long>(n));
    
    for(long long i = 0; i < n; i++){
        for(long long j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }

    d = a;

    warshall_floyd(n);

    if(d != a){
        printf("-1\n");
        return 0;
    }

    vector<vector<long long> > b(n, vector<long long>(n, 0));
    for(long long k = 0; k < n; k++){
        for(long long i = 0; i < n; i++){
            for(long long j = 0; j < n; j++){
                if(i != j and j != k and k != i and a[i][j] == a[i][k] + a[k][j]) b[i][j] = 1;
            }
        }
    }

    long long sum = 0;

    for(long long i = 0; i < n; i++){
        for(long long j = 0; j < n; j++){
            if(b[i][j] == 0) sum += a[i][j];
        }
    }
    
    printf("%lld\n", sum/2);
    return 0;
}

Measured memory_bytes: 5816
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;

constexpr int INF = 1 << 25;
constexpr int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  unordered_set<string> dict;
  string cmd, str;
  REP(i, n) {
    cin >> cmd >> str;
    if (cmd == "insert") {
      dict.insert(str);
    } else {
      cout << (dict.find(str) != dict.end() ? "yes" : "no") << endl;
    }
  }
}



Measured memory_bytes: 32200
n = int(input())
k = int(input())
x_n = list(map(int, input().split()))

res = 0
for i in range(len(x_n)):
    if x_n[i] > (k / 2):
        res = res + abs(x_n[i] - k) * 2
    else:
        res = res + 2 * x_n[i]

print(res)


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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 3e5 + 5, INF = 0x3f3f3f3f;

int main() {
	int n, k; rd(n, k);
	vector<int> a(n);
	for (int& i : a) rd(i);

	sort(a.begin(), a.end());
	
	ll ans = 0;
	for (int i = 0; i < min(n, k); i++) ans += a[i];
	printf("%lld\n", ans);

}

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

int main() {
  int a[3];
  
  cin >> a[0]>>a[1]>>a[2];
  if(a[0]+a[1]+a[2] >= 22){
    cout << "bust";
  } else{
    cout << "win";
  }
  return 0;
}

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

#define int                 long long
#define pb                  push_back
#define all(v)              v.begin(),v.end()
#define INF                 (int)1e14
#define speed               ios_base::sync_with_stdio(false);cin.tie(NULL);cout.flush()
#define MOD                 (int)(998244353)
#define fi                  first
#define se                  second
#define sq(a)               a*a
#define ld                  long double
#define Error(x)            cout<< #x << " = " << (x) <<endl;
#define Error2(a,b)         cout<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define Error3(a,b,c)       cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" ) = ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<")\n";
#define Error4(a,b,c,d)     cout<<"("<<#a<<" , "<<#b<<" , "<<#c<<" , "<<#d<<" ) = \
                            ( "<<(a)<<" , "<<(b)<<" , "<<(c)<<" , "<<(d)<<")\n";
#define popcount            __builtin_popcountll
#define ign                 cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define PI                  acos(-1.0)

int abso(int a) { return a>0 ? a : (-a); }
int cdiv(int a,int b) { return a/b + ( (a%b) > 0 ); }
int mul(int a,int b) { int res=0; while(b){ if(b&1) res=(res+a)%MOD; a=(a+a)%MOD; b=b/2; } return res; }
int bexp(int a,int b) { int res=1; while(b){ if(b&1) res=mul(res,a); a=mul(a,a); b=b/2; } return res; }
int inv(int a) { return bexp(a,MOD-2); }

int power(int a,int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=res*a;
        a=a*a;
        b=b>>1;
    }
    return res;
}

void solve() {
    int a,b,c;
    cin>>a>>b>>c;
    int left=a-b;
    if(left>=c) {
        cout<<0<<"\n";
    } else {
        cout<<c-left<<"\n";
    }

}

signed main() {
    speed;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    while(t--) {
        solve();
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main(void){
    int H, A;
    cin >> H >> A;
    if(H%A == 0){
        cout << H/A << endl;
    }else{
        cout << H/A + 1 << endl;
    }
    return 0;
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


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

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


i64 solve(i64 n, i64 y, i64 a_sum, vector<i64> a){
    vector<vector<i64>> dp(n + 1, vector<i64>(6, 0));
    dp[0][0] = 1;
    for(i64 i = 0; i < n; ++i){
        i64 sum = 0;
        for(i64 j = i; j < n; ++j){
            sum += a[j];
            if(sum + y >= a_sum / 5){
                for(i64 k = 0; k < 5; ++k)
                    dp[j + 1][k + 1] += dp[i][k];
            }
        }
    }
    return dp.back()[5];
}


signed main(){

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

    i64 n, y;
    cin >> n >> y;
    vector<i64> a(n);
    for(auto& x : a)
        cin >> x;
    i64 sum = 0;
    for(i64 i = 0; i < n; ++i){
        sum += a[i];
        a.push_back(a[i]);
    }
    i64 ans = 0;
    for(i64 i = 0; i < n; ++i){
        vector<i64> b;
        for(i64 j = 0; j < n; ++j)
            b.emplace_back(a[i + j]);
        ans += solve(n, y, sum, b);
    }

    cout << ans / 5 << endl;
}



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

int main() {
int a,b;
float sum, sub,mult;
cin >>a>>b;
 sum=a+b;
 sub=a-b;
 mult=a*b;
 if (sum >=sub && sum>= mult)
 
 {cout<< sum<<endl;
 
 }
 
 
 
 else if (sub >=sum && sub>= mult)
 {cout<< sub<<endl;
 
}
 
 
 
 else
 
 {cout<< mult<<endl;
 }
 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long N;
long long f(int n) {
	long long r = f(n-1);
	for (int i = 2; i <= N; ++ i) {
		(r += N-1 + f(n-1-i)) %= mod;
	}
	//cerr << n << " " << r << endl;
	return r;
}
int main() {
	cin >> N;
	vector<long long> dp(N+1, -1);
	vector<long long> sumdp(2*N+3, 0);
	for (int i = 0; i <= N+2; ++ i) sumdp[i] = i;
	dp[0] = 1;
	dp[1] = N;
	sumdp[N+1] = sumdp[N] + dp[1];
	for (int n = 2; n <= N; ++ n) {
		dp[n] = dp[n-1];
		(dp[n] += (N-1) * (N-1)) %= mod;
		// sum dp[n-1-N] .. dp[n-1-2]
		(dp[n] += (sumdp[N+n-3] - sumdp[n-2] + mod)) %= mod;
		/*for (int i = 2; i <= N; ++ i) {
			int j = n-1-i;
			// (dp[n] += (j >= 0 ? dp[j] : 1)) %= mod;
		}*/
		(sumdp[N+n] = sumdp[N+n-1] + dp[n]) %= mod;
		// cerr << dp[n] << endl;
	}
	cout << dp[N] << endl;
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

int main()
{

    ll n, s = 0;
    vector<ll> v;
    map<ll,ll> m;
    cin >> n;
    for(ll i = 0; i < n; i++)
    {

        ll x;
        cin >> x;
        if(m[x]==0) v.pb(x);
        m[x]++;
    }
    for(ll i =0; i < v.size(); i++)
    {

        ll x = v[i];
        if(m[x] > x)
            s+=m[x]-x;
        else if(m[x] < x)
            s+=m[x];
    }
    cout << s;
}


Measured memory_bytes: 7028
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    forn(i, 0, n) cin >> a[i];
    forn(i, 0, n) cin >> b[i];
    ll ops = accumulate(all(b), 0ll) - accumulate(all(a), 0ll);
    ll need = 0, have = 0;
    forn(i, 0, n) if (b[i] < a[i]) {
        need += (a[i] - b[i]);
    } else have += (b[i] - a[i]) / 2;
    cout << (ops >= need && have >= need ? "Yes\n" : "No\n");
}


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

int main() {
	int H, W, C[26] = {}, X2 = 0, X1 = 0;
	string A;
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> A;
		for (int j = 0; j < W; j++) {
			C[A[j] - 97]++;
		}
	}
	for (int i = 0; i < 26; i++) {
		if (C[i] % 2 == 1) X1++;
		else if (C[i] % 4 == 2) X2++;
	}
	if (H % 2 == 0 && W % 2 == 0) {
		if (X2 == 0 && X1 == 0) cout << "Yes";
		else cout << "No";
	}
	if (H % 2 == 0 && W % 2 == 1) {
		if (X2 <= H / 2 && X1 == 0) cout << "Yes";
		else cout << "No";
	}
	if (H % 2 == 1 && W % 2 == 0) {
		if (X2 <= W / 2 && X1 == 0) cout << "Yes";
		else cout << "No";
	}
	if (H % 2 == 1 && W % 2 == 1) {
		if (X2 < (H + W) / 2 && X1 == 1) cout << "Yes";
		else cout << "No";
	}
}

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

int cmp( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}

int main(void) {
    int n;
    scanf("%d", &n);
    int a[n], b[n];
    for(int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
        b[i] = a[i];
    }
    qsort(b, sizeof(b)/sizeof(int), sizeof(int), cmp);
    
    for(int i = 0; i < n; i++) {
        if(a[i] != b[n-1]) {
            printf("%d\n", b[n-1]);
        } else {
            printf("%d\n", b[n-2]);
        }
    }
    return 0;
}


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

#define PI acos(-1)
#define _fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007
#define mxx 1000000
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;

int tc;


void solve(){

    int n,k,x,s=0;
    vector<int>v;
    cin>>n>>k;
    for(int i=1; i<=n; i++){
        cin>>x;
        v.push_back(x);
    }
    sort(all(v));
    for(int i=0; i<k; i++)s+=v[i];
    cout<<s<<endl;
}

int main()
{

    _fastIO;

    //cin>>tc; while(tc--)
    solve();

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    // cout << fixed << setprecision(10);
    string S;
    cin >> S;
    bool flag = false;

    if(S == "hi")
    {
        flag = true;
    }
    else if(S == "hihi")
    {
        flag = true;
    }
    else if(S == "hihihi")
    {
        flag = true;
    }
    else if(S == "hihihihi")
    {
        flag = true;
    }
    else if(S == "hihihihihi")
    {
        flag = true;
    }

    if(flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<pii, lint> ppl;
typedef pair<lint, lint> pll;
typedef complex<double> xy_t;
typedef vector<lint> poly;

template<class T> struct  SegTree{
    typedef  function<T(T, T)> F;
    int n = 1;
    vector<T> node;
    T et;
    F f, g;

    SegTree(int n_, T et_, F f_, F g_):
    et(et_), f(f_), g(g_){
        while(n < n_) n *= 2;
        node.resize(n*2-1, et);
    }

    void update(int i, T x){
        i += n-1;
        node[i] = g(node[i], x);
        while(i){
            i = (i-1) / 2;
            node[i] = f(node[i*2+1], node[i*2+2]);
        }
    }

    T query(int a, int b){
        T vl = et, vr = et;
        for(a+=n-1, b+=n-1; a<b; a=(a-1)/2, b=(b-1)/2){
            if(!(a&1)) vl = f(vl, node[a++]);
            if(!(b&1)) vr = f(node[--b], vr);
        }
        return f(vl, vr);
    }
};

int main(){
    int n;
    scanf("%d", &n);
    lint cnt[n+1];
    rep(i, n+1) cnt[i] = 0LL;
    rep(i, n){
        int a;
        scanf("%d", &a);
        ++cnt[a];
    }

    sort(cnt, cnt+n+1);
    SegTree<lint> st(n+1, 0LL, plus<lint>(), plus<lint>());
    rep(i, n+1) st.update(i, cnt[i]);
    For(k, 1, n+1){
        lint low = 0;
        lint high = n + 1;
        while(high - low > 1){
            lint mid = (high + low) / 2;
            int id = upper_bound(cnt, cnt+n+1, mid) - cnt;
            (st.query(0, id) + mid*(n+1-id) >= mid*k ? low : high) = mid;
        }
        printf("%lld\n", low);
    }
}

Measured memory_bytes: 11392
def main():
    N, M = map(int, input().split())
    matrix = [[0] * N for _ in range(N)]

    for _ in range(M):
        a, b = map(int, input().split())
        matrix[a-1][b-1] = 1
        matrix[b-1][a-1] = 1

    def dfs(v, used):
        if False not in used:
            return 1

        ans = 0
        for i in range(N):
            if not matrix[v][i]:
                continue
            if used[i]:
                continue

            used[i] = True
            ans += dfs(i, used)
            used[i] = False

        return ans

    used = [False] * N
    used[0] = True

    print(dfs(0, used))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import math

n = int(input())
xy = [list(map(float, input().split())) for _ in range(n)]

ret = 100000000
def update(px, py):
    global ret
    r = 0
    for p in range(n):
        r = max(r, math.hypot(px - xy[p][0], py - xy[p][1]))
    ret = min(ret, r)

for i in range(n):
    x1 = xy[i][0]
    y1 = xy[i][1]
    for j in range(i + 1, n):
        x2 = xy[j][0]
        y2 = xy[j][1]
        update((x1 + x2) / 2, (y1 + y2) / 2)
        for k in range(j + 1, n):
            x3 = xy[k][0]
            y3 = xy[k][1]

            d = 2 * (y1 - y3) * (x1 - x2) - 2 * (y1 - y2) * (x1 - x3)
            if d != 0:
                px = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
                py = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
                update(px, py)

print(ret)


Measured memory_bytes: 9324
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
int cnt=0,ans=0;
cin>>s;
for (int i=0;i<3;i++)
if (s[i]=='o')
cnt++;
ans=700+cnt*100;
cout<<ans<<endl;
system("pause");
return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    cin >> n;
    vector<int> arr(n, 0);
    for(int i = 0; i < n; i++) {
        cin >> arr[i];
        arr[i] -= i;
    }
    sort(arr.begin(), arr.end());
    ll ans = 0;
    ll m = arr[n/2];
    for(int i = 0; i < n; i++)
        ans += llabs(m-arr[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#pragma region atcoder
//These are for segment tree
/*int op(int a, int b){return max(a, b);}
int e(){return -1;}
bool f(int v){ return v < target;}
*/
#pragma endregion
#pragma region macros
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vl = vector<ll>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n - 1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#pragma endregion
#pragma region debug for var, v, vv
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){cout << endl;int cnt = 0;for(const auto& v : vv){cout << cnt << "th : "; view(v); cnt++;} cout << endl;}
#pragma endregion

const ll mod = 1000000007;
const int inf = 1001001001;
const ll INF = 1001001001001001001;
const int MAX = 2000005;

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; }
ll modpow(ll a, ll p){ll ret = 1; while(p){if(p & 1){ret = ret * a % mod;} a = a * a % mod; p >>= 1;} return ret;}

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

/*-----------------------------------------------------------------------------------------------------*/
int cnt = 0;
vector<int> used;
void dfs(vvi &G, int v){
	used[v] = cnt;
	for(int nv : G[v]){
		if(used[nv] != -1) continue;
		dfs(G, nv);
	}
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m; cin >> n >> m;
	vvi G(n);
	used.resize(n, -1);
	rep(i,m){
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i,n){
		if(used[i] != -1) continue;
		cnt++;
		dfs(G, i);
	}
	cout << cnt - 1 << endl;
}

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

const int N = 1010;

typedef pair<int, int> P;

#define fir first
#define sec second

vector<P> G[N];

bool mark[N][N], mp[N][N], vis[N]; int ct[N][N];

int rt, n; 

void dfs(int u, int type) {
    vis[u] = 1;
    if (mp[rt][u] && !mark[rt][u]) ct[rt][u] |= 1;
    if (!type) {
        for (auto v : G[u]) if (!vis[v.sec])
            mark[u][v.sec] = 1, dfs(v.sec, type), mark[u][v.sec] = 0;
    } else for (int i = G[u].size() - 1; i >= 0; i--) if (!vis[G[u][i].sec])
        mark[u][G[u][i].sec] = 1, dfs(G[u][i].sec, type), mark[u][G[u][i].sec] = 0;
}

inline void clr() {
    for (int i = 1; i <= n; i++) vis[i] = 0;
}

inline void solve(int u) {
    rt = u, clr(), dfs(u, 0), clr(), dfs(u, 1);
    for (int i = 1; i <= n; i++) if (vis[i]) ct[i][u] |= 2;
}

int ans[N * 200];

int main() {
    int m; scanf("%d%d", &n, &m);
    for (int i = 1, a, b; i <= m; i++) scanf("%d%d", &a, &b), G[a].push_back(P(i, b)), mp[a][b] = 1;
    for (int i = 1; i <= n; i++) sort(G[i].begin(), G[i].end());
    for (int i = 1; i <= n; i++) solve(i);
    for (int i = 1; i <= n; i++) for (auto v : G[i]) 
        if (ct[i][v.sec] != 0 && ct[i][v.sec] != 3) ans[v.fir] = 1;
    for (int i = 1; i <= m; i++) puts(ans[i] ? "diff" : "same");

}

Measured memory_bytes: 13480
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <cmath>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;

int main(int argc, char const* argv[])
{
  string s;
  cin >> s;
  s = s.substr(0, s.size() - 2);
  while(s.size() != 2){
    bool flag = true;
    for(int i = 0; i < s.size() / 2; i++){
      if(s[i] != s[i + s.size() / 2]){
        flag = false;
        break;
      }
    }
    if(flag){
      cout << s.size() << endl;
      return 0;
    }
    s = s.substr(0, s.size() - 2);
  }
  cout << 2 << endl;
	return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n:usize,
        s: [String; n]
    }

    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for i in 0..n {
        let st = s[i].as_ref();
        match st {
            "AC"=> { ac += 1;}
            "WA" => {wa += 1;}
            "TLE" => {tle += 1;}
            "RE" => {re += 1;}
            _=>{}
        }
    }
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


Measured memory_bytes: 7856
#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
using Graph = vector<vector<int>>; // グラフ型
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

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

int main() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);


    int n;
    cin >> n;
    vector<int> a(n, 0);

    FOR(i, 1, n-1){
        int x  = 0;
        cin >> x;
        a[x-1]++;
    }

    REP(i, n){
        cout <<  a[i] << "\n"; 
    }
    return 0;



}


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

bool is_prime[50001];

void sieve() {
  for(int i=0;i<50001;i++) {
    is_prime[i] = true;
  }

  is_prime[0] = is_prime[1] = false;

  for(int i=2;i<50001;i++) {
    if(is_prime[i]) {
      for(int j=2*i;j<50001;j+=i) {
        is_prime[j] = false;
      }
    }
  }
}

int main() {
  int n;
  sieve();
  while(cin >> n) {
    if(n==0)break;
    int ans = 0;
    for(int i=2;i<=n/2;i++) {
      if(is_prime[i]) {
        if(is_prime[n-i]) {
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}

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

int main() {
  unsigned long long N;
  std::cin >> N;
  std::vector<unsigned> cnt((N + 1) / 2);
  for (unsigned i = 0; i < N; ++i) {
    unsigned tmp;
    std::cin >> tmp;
    if (tmp % 2 == N % 2) {
      std::cout << 0;
      return 0;
    }
    ++cnt[tmp / 2];
  }
  if (N % 2 == 0 && cnt[0] != 2) {
    std::cout << 0;
    return 0;
  }
  if (N % 2 == 1 && cnt[0] != 1) {
    std::cout << 0;
    return 0;
  }
  for (unsigned i = 1; i < (N + 1) / 2; ++i) {
    if (cnt[i] != 2) {
      std::cout << 0;
      return 0;
    }
  }
  unsigned long long ans = 1u;
  for (unsigned i = 0; i < N / 2; ++i) {
    ans *= 2u;
    ans %= 1000000007;
  }
  std::cout << ans;
  return 0;
}

Measured memory_bytes: 384
using System;

namespace AtCoderBeginnerContest142_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            int N = int.Parse(NK[0]);
            int K = int.Parse(NK[1]);
            string[] hStrs = Console.ReadLine().Split(' ');

            int ans = 0;
            for(int i=0; i<N; i++)
            {
                int tmp = int.Parse(hStrs[i]);
                if(tmp>= K)
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
            //Console.ReadKey();
        }
    }
}


Measured memory_bytes: 15584
#include<iostream>//atcoder143B
using namespace std;
int main(void)
{
	int n,d[100],a,i,j,all=0;
	cin>>n;
	for(a=0;a<n;a++) cin>>d[a];
	for(i=0;i<n-1;i++){
		for(j=i+1;j<n;j++){
			all+=d[i]*d[j];
		}
	}
	cout<<all<<endl;
	return 0;
}

Measured memory_bytes: 384
using System;

class main{
  public static void Main(string[] args){
    string weather = Console.ReadLine();
    int cnt = 0;
    int days = 0;
    
    for(int i = 0; i < weather.Length; i++){
      if (weather[i] == 'R'){
        cnt++;
        days = cnt; 
      }
      else 
        cnt = 0;
    }
    Console.WriteLine(days);
  }
}

Measured memory_bytes: 25916
import sys
N = int(input())
A = list(map(int, input().split()))
A.sort()
if A[-1] == 0:
    print(0)
    sys.exit(0)
ans = A[0]
for i in range(1, N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        sys.exit(0)
print(ans)

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

struct LIDS_F2 {
	int rsz;
	int rank = 0;
	vector<vector<int>> R;
	LIDS_F2(int row_size) : rsz(row_size), R(rsz, vector<int>(rsz)) {
		for(int i = 0; i < rsz; i++) R[i][i] = 1;
	}

	int Rv_i(vector<int>& v, int i) {
		int rv = 0;
		for(int j = 0; j < rsz; j++) rv ^= R[i][j] * v[j];
		return rv;
	}

	bool is_indep(vector<int>& v) {
		assert(v.size() == rsz);
		for(int i = rank; i < rsz; i++) if (Rv_i(v, i)) return true;
		return false;
	}

	void add_row(int from, int to) {
		for(int j = 0; j < rsz; j++) R[to][j] ^= R[from][j];
	}

	bool add(vector<int>& v) {
		assert(v.size() == rsz);
		vector<int> t(rsz);
		for(int i = 0; i < rsz; i++) t[i] = Rv_i(v, i);
		int r = rank;
		for(; r < rsz; r++) if (t[r]) break;
		if (r == rsz) return false;
		if (r != rank) add_row(r, rank);
		for(int i = 0; i < rsz; i++) if (i != rank && t[i]) add_row(rank, i);
		rank++;
		return true;
	}
};

int main() {
	int t;
	cin >> t;
	rep(z, t) {
		int n;
		cin >> n;
		vector<ll> a(n);
		rep(i, n) cin >> a[i];
		string s;
		cin >> s;
		LIDS_F2 d(62);
		int ans = 0;
		for(int i = n - 1; i >= 0; i--) {
			vector<int> v;
			rep(k, 62) v.push_back(a[i] >> k & 1);
			if (s[i] == '0') d.add(v);
			else if (d.is_indep(v)) {
				ans = 1;
				break;
			}
		}
		cout << ans << endl;
	}
}


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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N;
vector<ll> n(4);

// dp[i][j][k]: 3個の皿がi枚、2個の皿がj枚、1個の皿がk枚、0個の皿がS-i-j-k枚 のときに、無くなるまでの期待値
// dp[i][j][k] = ... は右辺に自身を含むので、あらかじめ移項・展開しておく
double dp[400][400][400];

signed main() {
  cin >> N;
  rep(i, N) {
    ll x;
    cin >> x;
    n[x]++;
  }
  rep(i, 400) rep(j, 400) rep(k, 400) {
    if (i+j+k==0) { dp[i][j][k] = 0; continue; }
    if (i+j+k > N) continue;
    double p = 1.0;
    if (i > 0) p += (double)i/N * dp[i-1][j+1][k];
    if (j > 0) p += (double)j/N * dp[i][j-1][k+1];
    if (k > 0) p += (double)k/N * dp[i][j][k-1];
    p *= N;
    p /= i+j+k;
    dp[i][j][k] = p;
  }
  printf("%.10f\n", dp[n[3]][n[2]][n[1]]);
  return 0;
}


Measured memory_bytes: 376704
function main(input){
	var num = input.split(" "); 
  	var a = parseInt(num[0]);
  	var b = parseInt(num[1]);
	var allPiece = 3*a + b;
  	var allPi = Math.floor(allPiece/2);
    
    console.log(allPi);
}


main(require("fs").readFileSync("/dev/stdin", "utf8"))

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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;


const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

string s;

int main(){
	cin >> s;
	string ans;
	string sub;
	rep (i, s.size()) {
		if (s[i] == ',') {
			ans += sub;
			ans += ' ';
			sub = "";
		} else {
			sub += s[i];
		}
	}
	ans += sub;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, K) = readLine()!!.split(" ").map(String::toInt)

    fun calc(n: Int): Int {
        return if (n <= K - 1) {
            calc(n * 2)
        } else {
            n
        }
    }

    val result = DoubleArray(N)
    for (i in 1..N) {
        val c = calc(i) / i
        result[i - 1] = 1 / c.toDouble() / N.toDouble()
    }

    result.sum().let(::println)

}

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

constexpr auto DictSize = ((1 << 26) - 1)/3;

bool dict[DictSize];

int myhash(char* str){
    int n = strlen(str);
    int num = 0;
    for (int i = 0; i != n; ++i){
        num *= 4;
        if (str[i] == 'C'){
            num += 1;
        }else if (str[i] == 'G'){
            num += 2;
        }else if (str[i] == 'T'){
            num += 3;
        }
    }
    num += ((1 << (2*n)) - 4) / 3;
    return num;
}


int main()
{
    ios::sync_with_stdio(false);
    memset(dict, false, DictSize);
    int n = 0;
    cin >> n;
    char command[7];
    char str[13];
    for (int i = 0; i != n; ++i){
        cin >> command >> str;
        if (command[0] == 'i'){
            dict[myhash(str)] = true;
        }else if(dict[myhash(str)]){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25024
/*
 * created   : 2019-08-04 23:49:50
 * accepted  : 2019-08-04 23:49:50
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int a, b;
  cin >> a >> b;
  // a - k = b - k
  // a - b = 0

  // -a + k = b - k
  // 2 * k = b + a

  // a - k = -b + k
  // a + b = 2 * k

  // -a + k = -b + k
  // a = b
  int ans = -1;
  if (a == b) {
    ans = 0;
  }
  else if ((a + b) % 2 == 0) {
    ans = (a + b) / 2;
  }
  if (ans == -1) {
    cout << "IMPOSSIBLE" << "\n";
    return;
  }
  cout << ans << "\n";
}

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


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
  lint N,M;
  cin >> N >> M;
  priority_queue<lint> A;
  rep(i,N){
    lint X;
    cin >> X;
    A.push(X);
  }
  rep(i,M){
    lint X=A.top()/2;
    A.pop();
    A.push(X);
  }
  lint ans=0;
  while (!A.empty()) {
    ans+=A.top();
    A.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD1 = 1000000007;
const ll MOD2 = 1000000021;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

int N;
ll A[101];
bool dead[101];
ll ans;

void dfs (int pos, ll now) {
    if (pos == N+1) {
        ans = max(ans, now);
        return;
    }
    if (dead[pos]) {
        dfs(pos+1, now);
        return;
    }
    dfs(pos+1, now+A[pos]);
    if (A[pos] >= 0) return;
    bool tmp[100];
    for (int i = pos; i <= N; i++) tmp[i] = dead[i];
    for (int i = pos; i <= N; i += pos) {
        dead[i] = true;
    }
    ll cnt = 0;
    for (int i = pos; i <= N; i++) {
        if (!dead[i] && A[i] > 0) cnt += A[i];
    }
    if (now+cnt > ans) dfs(pos+1, now);
    for (int i = pos; i <= N; i++) dead[i] = tmp[i];
}

int main() {
    cin >> N;
    rep(i,N) cin >> A[i+1];
    dfs(1, 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>
 
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;
 
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
 
int main(void){
  int N;
  cin>>N;
  cin.ignore();
  while(N--){
    string buf;
    getline(cin,buf);
    int M;
    cin>>M;
    cin.ignore();
    string::iterator it = buf.begin();
    while(M--){
      /*
      {
      int dist = distance(buf.begin(),it);
      REP(i,buf.size()){
        if(i==dist)putchar('^');
        putchar(buf[i]);
      }
      if(it==buf.end())putchar('^');
      putchar('\n');
      }
      */
      string command;
      getline(cin,command);
      if(command=="forward char"&&it!=buf.end()) it++;
      if(command=="backward char"&&it!=buf.begin()) it--;
      if(command=="forward word"){
        while(it!=buf.end()&&*it==' ')it++;
        while(it!=buf.end()&&*it!=' ')it++;
      }
      if(command=="backward word"){
        if(it!=buf.begin())it--;
        while(it!=buf.begin()&&(*it)==' ')it--;
        while(it!=buf.begin()&&(*it)!=' ')it--;
        if(*it==' ') it++;
      }
      if(command=="delete char"&&it!=buf.end()) it = buf.erase(it);
      if(command=="delete word"){
        string::iterator it2 = it; 
        while(it2!=buf.end()&&*it2==' ')it2++;
        if(it2!=buf.end()){
          while(it2!=buf.end()&&*it2!=' ')it2++;
          //if(it2!=buf.end())it2++;
          it = buf.erase(it,it2);
        }
      }
      if(command.find("insert",0)!=string::npos){
        string ins = command.substr(8);
        string::iterator ir = ins.end()-1;
        ins.erase(ir);
        //cout<<ins<<endl;
        REP(i,ins.size()){
          it = buf.insert(it,ins[i]);
          it++;
        }
      }
    }
    int dist = distance(buf.begin(),it);
    REP(i,buf.size()){
      if(i==dist)putchar('^');
      putchar(buf[i]);
    }
    if(it==buf.end())putchar('^');
    putchar('\n');
  }
  return 0;
}

Measured memory_bytes: 3148
/*
 * 2576.cc: Doctor Course Is Recommended
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_DN = 13;
const int MAX_X = 20;
const int MAX_Y = 10;

/* typedef */

/* global variables */

int p1s[MAX_X], p2s[MAX_Y];
int sum1s[MAX_X + 1], sum2s[MAX_Y + 1];

/* subroutines */

/* main */

int main() {
  int dn, x, y;
  cin >> dn;

  cin >> x;
  int p1n = 0;
  for (int i = 0; i < x; i++) {
    string s;
    int pi;
    cin >> s >> pi;
    if (s == "D") p1s[p1n++] = pi;
  }
  sort(p1s, p1s + p1n, greater<int>());

  cin >> y;
  int p2n = 0;
  for (int i = 0; i < y; i++) {
    string s;
    int pi;
    cin >> s >> pi;
    if (s == "DD") p2s[p2n++] = pi;
  }
  sort(p2s, p2s + p2n, greater<int>());
  //printf("p1n=%d, p2n=%d\n", p1n, p2n);

  sum1s[0] = sum2s[0] = 0;
  for (int i = 0; i < p1n; i++) sum1s[i + 1] = sum1s[i] + p1s[i];
  for (int i = 0; i < p2n; i++) sum2s[i + 1] = sum2s[i] + p2s[i];
  
  int maxsum = 0;

  for (int i = 0; i <= p2n && i * 2 <= dn; i++) {
    int j = min(p1n, dn - i * 2);
    int sum = sum1s[j] + sum2s[i];
    if (maxsum < sum) maxsum = sum;
  }

  printf("%d\n", maxsum);
  return 0;
}

Measured memory_bytes: 1224
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
 
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut a: [u64; n],
    }

    let mut max = 0;
    let mut index = 0;
    for (i, n) in a.iter().enumerate() {
        if max < *n {
            max = *n;
            index = i+1;
        }
    }

    a.sort();
    let second = a[n-2];

    //println!("hey");
    for i in 1..n+1 {
        if i == index {
            println!("{}", second);
        } else {
            println!("{}", max);
        }
    }
}


Measured memory_bytes: 7676
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007


template <class T>
void print(vector<T> arr)
{
	cout << "start printing the vector\n";
	for (auto u : arr)
		cout << u << " ";
	cout << "\n";
}

template <class T>
void print_mat(vector<vector<T>> a)
{
	cout << "start printing the matrix\n";
	for (auto v : a)
	{
		for (auto e : v)
		{
			cout << e << " ";
		}
		cout << "\n";
	}
}

/******************************************
* NUMBER THEORY ;) *
******************************************/



ll powermod(ll x, ll y)
{
	ll res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % mod;
		y = y >> 1;
		x = (x * x) % mod;
	}
	res %= mod;
	return res;
}
ll factmod(ll n)
{
	ll res = 1;
	while (n > 1)
	{
		res = (res * ((n / mod) % 2 ?  mod - 1 : 1)) % mod;
		for (ll i = 2; i <= n % mod; ++i)
			res = (res * i) % mod;
		n /= mod;
	}
	res %= mod;
	return res;
}



void solve()
{
	ll n;
	cin >> n;
	if (n >= 400 and n <= 599)
	{
		cout << 8 << "\n";
	}
	else if (n >= 600 and n <= 799)
	{
		cout << 7 << "\n";
	}
	else if (n >= 800 and n <= 999)
	{
		cout << 6 << "\n";
	}
	else if (n >= 1000 and n <= 1199)
	{
		cout << 5 << "\n";
	}
	else if (n >= 1200 and n <= 1399)
	{
		cout << 4 << "\n";
	}
	else if (n >= 1400 and n <= 1599)
	{
		cout << 3 << "\n";
	}
	else if (n >= 1600 and n <= 1799)
	{
		cout << 2 << "\n";
	}
	else if (n >= 1800 and n <= 1999)
	{
		cout << 1 << "\n";
	}

}

int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// ll t;
	// cin >> t;
	// while (t--)
	// {
	solve();
	// }

	return 0;
}

Measured memory_bytes: 3628
while True:
  count = int(input())
  if count == 0:break
  else:
    a,b,c,d = [],[],[],[]
    for i in range(count):
      g = map(str,raw_input().split())
      a.append(g[0])
      b.append(g[1])
    tugi = int(input())
    for j in range(tugi):
      r = raw_input()
      for x in range(count):
        if r[0] == a[x]:
          c.append(b[x])
          break
      else: c.append(r[0])
    print ''.join(c)
      

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

using namespace std;

int a[111], d[111111];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < k + 1; i++) {
		for (int j = 0; j < n; j++)
			if (i >= a[j]) d[i] |= d[i - a[j]] ^ 1;
	}
	cout << (d[k] ? "First" : "Second") << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <limits.h>
#include <algorithm>

using namespace std;

long long int sum = 0;


void merge(int A[],int left,int mid, int right){
	int n1 = mid - left;
	int n2 = right - mid;
	int L[n1+1],R[n2+1];
	for(int i = 0; i < n1; i++) L[i] = A[left + i];
	for(int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] =  INT_MAX;

	int i = 0, j = 0;
	for(int k = left;k < right; k++){
		if(L[i] < R[j]){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
			sum += n1 - i;
		}
	}
}

void mergeSort(int A[],int left,int right){
	if(left+1 < right){
		int mid = (left+right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int main(){
	int n;
	scanf("%d",&n);
	int A[n];
	for(int i = 0; i < n; i++) scanf("%d",&A[i]);

	mergeSort(A,0,n);

	printf("%lld\n",sum);

}



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

using namespace std;

long long get (long long a, long long b) {
  if (b == 0) return -a;
  return 2LL * b * (a / b) + get(b, a % b);
}

int main() {
  long long n, x;
  cin >> n >> x;
  cout << n + get(min(x, n - x), max(x, n - x)) << endl;
  return 0;
}



Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
int main(){
    LL a,b,c;
    vector<LL> ary_ans(3);
    cin >> a >> b >> c;
    ary_ans[0] = c;
    ary_ans[1] = a;
    ary_ans[2] = b;

    cout << ary_ans[0] << " " << ary_ans[1] << " " << ary_ans[2] << endl;


    return 0;
}

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

using namespace std;

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) cout << "YES" <<endl;
    else cout <<"NO" << endl;

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val inputList = readLine()!!.split(' ').map { it.toInt() }
    val evenCount = inputList[0]
    val oddCount = inputList[1]
    // evenCountから2つ選ぶ
    val selectFromEven = evenCount * (evenCount-1) / 2
    // oddCountから2つ選ぶ
    val selectFromOdd = oddCount * (oddCount-1) / 2
    val totalSelectCount = selectFromEven + selectFromOdd
    println(totalSelectCount.toString())
}


Measured memory_bytes: 36212