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

struct SegmentTree {
    SegmentTree(vector<int> v, int ini) {
        int sz = v.size();
        n = 1;
        while (n < sz)
            n *= 2;
        node.resize(2 * n - 1, ini);

        for (int i = 0; i < sz; i++) {
            node[i + n - 1] = v[i];
        }
        for (int i = n - 2; i >= 0; i--) {
            node[i] = max(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    void update(int k, int val) {
        k += n - 1;
        node[k] = val;
        while (k > 0) {
            k = (k - 1) / 2;
            node[k] = max(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    //[a, b) の範囲。
    int query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0)
            r = n;

        if (r <= a || b <= l)
            return -1;
        if (a <= l && r <= b)
            return node[k];

        int vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
        int vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
        return max(vl, vr);
    }

private:
    int n;
    vector<int> node;
};

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> XD(N);
    for (int i = 0; i < N; i++) {
        cin >> XD[i].first >> XD[i].second;
    }

    sort(XD.begin(), XD.end());
    vector<int> X(N), D(N);
    for (int i = 0; i < N; i++) {
        tie(X[i], D[i]) = XD[i];
    }

    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        v[i] = i + 1;
    }
    SegmentTree seg(v, 0);
    for (int i = N - 2; i >= 0; i--) {
        int reach = lower_bound(X.begin(), X.end(), X[i] + D[i]) - X.begin();
        int r = seg.query(i, reach);
        seg.update(i, r);
    }

    vector<ll> dp(N + 1, 0);
    ll mod = 998244353;
    dp[N] = 1;
    for (int i = N - 1; i >= 0; i--) {
        dp[i] = (dp[i] + dp[i + 1]) % mod;
        dp[i] = (dp[i] + dp[seg.query(i, i + 1)]) % mod;
    }

    cout << dp[0] << endl;
}


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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 3e3 + 5;
int comb[MAX][MAX], memo[MAX][MAX];

inline int add(int a, int b, int mod) {
	a += b;
	if(a >= mod) {
		a -= mod;
	}
	return a;
}

inline int sub(int a, int b, int mod) {
	a -= b;
	if(0 > a) {
		a += mod;
	}
	return a;
}

inline int mult(int a, int b, int mod) {
	return (1LL * a * b) % mod;
}

inline int f_exp(int x, int exp, int mod) {
	if(exp == 0) {
		return 1;
	}
	else if(exp & 1) {
		return mult(x, f_exp(x, exp - 1, mod), mod);
	}
	return f_exp(mult(x, x, mod), exp / 2, mod);
}

inline int phi(int x) {
	return x - 1;
}

int S(int n, int k, const int &mod) {
	if(k > n) {
		return 0;
	}
	else if(n == 0 && k == 0) {
		return 1;
	}
	else if(k == 0) {
		return 0;
	}

	int &ans = memo[n][k];
	if(~ans) {
		return ans;
	}

	ans = add(mult(k, S(n - 1, k, mod), mod), S(n - 1, k - 1, mod), mod);
	return ans;
}

inline int kernel(int n, int k, int mod) {
	return add(mult(k + 1, S(n, k + 1, mod), mod), S(n, k, mod), mod);
}

int n;
int ways(int x, int mod) {
	int total = 1;
	fori(i, 1, x + 1) {
		int cur = mult(kernel(x, i, mod), f_exp(2, (n - x) * i, mod), mod);

		total = add(total, cur, mod);
	}

	total = mult(total, f_exp(2, f_exp(2, n - x, phi(mod)), mod), mod);

	return total;
}

int main() {
	memset(memo, -1, sizeof memo);

	int mod;
	scanf("%d %d", &n, &mod);

	fori(i, 0, MAX) {
		fori(j, 0, i + 1) {
			if(i == j || j == 0) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = add(comb[i - 1][j], comb[i - 1][j - 1], mod);
			}
		}
	}

	int ans = 0;

	fori(i, 0, n + 1) {
		int cur = mult(comb[n][i], ways(i, mod), mod);

		if(i % 2 == 0) {
			ans = add(ans, cur, mod);
		}
		else {
			ans = sub(ans, cur, mod);
		}
	}

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

	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
using namespace std;
 
int main() {
	int n, yen;
	cin >> n >> yen;
	yen = yen / 1000;
 
	int money_x = -1, money_y = -1, money_z = -1;
 
	for (int x = 0; x <= n; ++x) {
		for (int y = 0; y <= n - x; ++y) {
			int z = n - x - y;
			if ((10 * x) + (5 * y) + z == yen) {
				money_x = x;
				money_y = y;
				money_z = z;
				break;
			}
		}
	}
 
	cout << money_x << ' ' << money_y << ' ' << money_z << endl;
 
	return 0;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	
	std::vector<int> p(n);
	for (int i = 0; i < n; ++i) {
		cin >> p.at(i);
	}
	
	int count = 0;
	for (int i = 1; i<n-1; ++i) {
		if (max({p.at(i-1), p.at(i), p.at(i+1)}) != p.at(i) && min({p.at(i-1), p.at(i), p.at(i+1)}) != p.at(i)) {
			count++;
		}
	}
	
	cout << count << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

int main() {
    ll n, k;
    cin >> n >> k;

    vl w(k+1);
    exrep(x, 1, k) {
        w[x] = modpow(k/x, n);
    }

    vl v(k+1);  // v[x] : GCDがxになる組み合わせの数
    for(ll x = k; x >= 1; x--) {
        ll u = 0;
        for(ll i = 2*x; i <= k; i += x) {
            u += v[i];
            u %= mod;
        }
        v[x] = (w[x] + mod - u)%mod;
    }

    ll ans = 0;
    exrep(x, 1, k) {
        ans += x*v[x];
        ans %= mod;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 4756
#include <iostream>
#include <string>
using namespace std;
 
int main() {
	int X, Y; cin >> X >> Y;
 
	int sum = 0;
	if (X == 1) sum += 300000; if (Y == 1) sum += 300000;
	if (X == 2) sum += 200000; if (Y == 2) sum += 200000;
	if (X == 3) sum += 100000; if (Y == 3) sum += 100000;
	if (X == 1 && Y == 1) sum += 400000;
 
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3644
/**    epsileer 27 July 2019  17:28:22  **/    
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef pair<LL,LL> PII;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define TEST int t = 1; while(t--) solve()

void solve(){
    LL a,b; cin>>a>>b;
    if((a+b)%2){
        cout<<"IMPOSSIBLE";
    }
    else{
        cout<<(a+b)/2;
    }
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST;
return 0;
}  

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll n;cin >> n;
	ll ac = 0;
	ll wa = 0;
	ll tle = 0;
	ll re = 0;

	REP(i, n){
		string str;cin >> str;
		if(str == "AC")ac++;
		if(str == "WA")wa++;
		if(str == "TLE")tle++;
		if(str == "RE")re++;
	}

	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;


	return 0;
}


Measured memory_bytes: 3656
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt(sc)
	b := nextInt(sc)
	t := nextInt(sc)

	var answer int
	for i := 1; (i * a) <= t; i++ {
		answer += b
	}
	fmt.Println(answer)

}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using Grid = vector<string>;

int	main()
{
	int	H, W;
	int	v_d[4] = {-1, 0, 0, 1};
	int h_d[4] = {0, -1, 1, 0};
	cin >> H >> W;
	Grid grid(H);
	for (int i = 0; i < H; ++i) {
		cin >> grid.at(i);
	}
	bool is_paintable = true;
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (grid.at(i).at(j) == '.')
				continue;
			int	count = 0;
			for (int k = 0; k < 4; ++k) {
				int n_i = i + v_d[k];
				int	n_j = j + h_d[k];
				if (n_i < 0 || H <= n_i || n_j < 0 || W <= n_j) continue;
				if (grid.at(n_i).at(n_j) == '#')
					++count;
			}
			if (count == 0) {
				is_paintable = false;
				break;
			}
		}
	}
	if (is_paintable)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}	
	
		



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int arr[3], fives=0, sevens=0, i;
    for(i=0; i<3; i++)
    {
        scanf("%d",&arr[i]);
        if(arr[i]==5)
        fives++;
        else if(arr[i]==7)
        sevens++;
    }
    if(fives==2&&sevens==1)
    printf("YES\n");
    else printf("NO\n");
    return 0;
}

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

#define loop(n) for(int  i= 0 ; i< (n) ; i++)
#define ll long long
#define vi vector<int>
#define inf 1000000009

using namespace std;

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

    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';

    char o1 , o2 , o3 ;
    for(int i = 0 ;  i < 2 ; i++){
        if(i==0)o1='+';
        else o1 = '-' ;
        for(int o  = 0 ; o < 2 ; o++){
            if(o==0)o2='+';
            else o2 = '-' ;
            for(int j = 0 ; j < 2 ; j++){
                if(j==0)o3='+';
                else o3 = '-' ;

                int ans = a ;
                if(o1=='+')ans+=b ;
                else ans-= b;


                if(o2=='+')ans+=c ;
                else ans-= c;


                if(o3=='+')ans+=d ;
                else ans-= d;

                if(ans==7){
                    cout<<a<<o1<<b<<o2<<c<<o3<<d<<'='<<'7';
                    return 0 ;
                }
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll N, M; std::cin >> N >> M;

  if ( N >= M/2 ) std::cout << M/2 << std::endl;
  else {
    std::cout << N + (M-2*N)/4 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
def count(A,B):
    counter=0
    for i in range(len(A)):
        if A[i]==B[i]:
            counter+=1
    return len(A)-counter
 
S = input()
T = input()
t = len(T)
s = len(S)
_min = float('inf')
for i in range(s-t+1):
    _min = min(_min,count(S[i:i+t],T))
print(_min)

Measured memory_bytes: 67236
if __name__ == '__main__':
    x, y, z, k = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))

    bc = []
    for bb in b:
        for cc in c:
            bc.append(bb + cc)
    bc.sort()

    from bisect import bisect_left

    def C(x):
        # count "abc >= x"
        ret = 0
        for aa in a:
            idx = bisect_left(bc, x - aa)
            ret += len(bc) - idx
        return ret

    lb = 0
    ub = (10 ** 10) * 3 + 1
    while ub - lb > 1:
        mid = (ub + lb) // 2
        if C(mid) >= k:
            lb = mid
        else:
            ub = mid

    kth = lb

    l = []
    for aa in a:
        idx = bisect_left(bc, kth - aa)
        for i in range(idx, len(bc)):
            l.append(aa + bc[i])

    l.sort(reverse=True)
    l = l[:k]
    for ll in l:
        print(ll)


Measured memory_bytes: 196748
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    m = min(A)
    mi = A.index(m)
    c = 0
    c += (N - 1) // (K - 1)
    if (N - 1) % (K - 1) > 0: c += 1
    print(c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 13880
#include<iostream>
using namespace std;
int main(){
	int n, m;
	while (cin >> n >> m && n || m){
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				if ((i + j) % 2 == 0)cout << '#';
				else cout << '.';
			}
			cout << endl;
		}cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int INF = 10001000;
const int MAX_N = 810;
const int MAX_M = 810;
int N,M,k;
string a[MAX_N];
int sx,sy;
int d[MAX_N][MAX_M];

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

void bfs(){
    queue<P> que;

    rep(i,N){
        rep(j,M){
            d[i][j] = INF;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy] = 0;

    while(que.size()){
        P p = que.front(); que.pop();
        rep(i,4){
            int nx = p.first+dx[i], ny = p.second+dy[i];
            if(0<=nx && nx<N && 0<=ny && ny<M && a[nx][ny]!='#' && d[nx][ny]==INF){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
}


int main() {
    cin >> N >> M >> k;
    rep(i,N)cin >> a[i];
    rep(i,N){
        rep(j,M){
            if(a[i][j]=='S'){
                sx = i; sy = j;
            }
        }
    }

    bfs();

    int dist = 99999;
    rep(i,N){
        rep(j,M){
            if(d[i][j]<=k){
                int tmp = min(min(i,N-1-i),min(j,M-1-j));
                if(tmp<dist)dist = tmp;
            }
        }
    }

    int ans = 1;
    ans += ceil((double)dist/k);

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


Measured memory_bytes: 3584
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int n;
    cin >> n;
    vi a(n);
    for (auto &x : a)
        cin >> x;
    ll ans = 0, max = 0;
    for (auto &x : a) {
        if (x < max) {
            ans += max - x;
            x = max;
        }
        max = std::max(max, (ll)x);
    }
    cout << ans << "\n";
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


Measured memory_bytes: 3964
#include <stdio.h>
#include <string.h>

#define MAXLINE 200
#define MAXCHAR 100

int main (void)
{
  char taro[MAXCHAR] = {'\0'};
  char hanako[MAXCHAR] = {'\0'};
  int n;

  int score_taro = 0;
  int score_hanako = 0;
  
  scanf("%d", &n);
  
  while(n--)
	{
	  scanf("%s %s\n", taro, hanako);
	  int c;
	  c = strcmp( taro, hanako);
	  if (c > 0)
		{
		  score_taro += 3;
		}
	  else if (c < 0)
		{
		  score_hanako += 3;
		}
	  else
		{
		  score_taro += 1;
		  score_hanako += 1;
		}
	}
  printf("%d %d\n", score_taro, score_hanako);

  return 0;
  
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N;

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

  cin >> N;
  vector< ll > a(N);
  REP(i, N) {
    cin >> a[i];
  }

  ll ans = 0ll;
  REP(i, N) {
    if (i == 0) {
      ans += a[0] / 2;
      a[0] %= 2;
      continue;
    }

    ans += (a[i] + a[i - 1]) / 2;
    if (a[i] > 0) {
      a[i] = (a[i] + a[i - 1]) % 2;
    }
    // debug(a[i]);
    // debug(i+1);
    // debug(ans);
    // cout << endl;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
#include <map>
#include <stack>
#include <string>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(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;
typedef pair<int,int> P;
typedef vector<int> vi;
stack<vi> st;
map<string,vi> mp;
int main(){
	int m,n;
	cin>>m;
	rep(i,m){
		string name;
		int lb,ub;
		cin>>name>>lb>>ub;
		for(int k=lb;k<=ub;k++) mp[name].pb(k);
	}
	cin>>n;
	rep(i,n){
		string c;
		cin>>c;
		if(c=="+"){
			vi b=st.top();st.pop();
			vi a=st.top();st.pop();
			vi r;
			rep(i,a.size()) rep(j,b.size()) r.pb((a[i]+b[j])%256);
			sort(all(r));
			r.erase(unique(all(r)),r.end());
			st.push(r);
		}else if(c=="-"){
			vi b=st.top();st.pop();
			vi a=st.top();st.pop();
			vi r;
			rep(i,a.size()) rep(j,b.size()) r.pb((a[i]-b[j]+256)%256);
			sort(all(r));
			r.erase(unique(all(r)),r.end());
			st.push(r);
		}else if(c=="*"){
			vi b=st.top();st.pop();
			vi a=st.top();st.pop();
			vi r;
			rep(i,a.size()) rep(j,b.size()) r.pb((a[i]*b[j])%256);
			sort(all(r));
			r.erase(unique(all(r)),r.end());
			st.push(r);
		}else if(c=="/"){
			vi b=st.top();st.pop();
			vi a=st.top();st.pop();
			vi r;
			rep(j,b.size()) if(b[j]==0){
				cout << "error\n";
				return 0;
			}
			rep(i,a.size()) rep(j,b.size()) r.pb((a[i]/b[j])%256);
			sort(all(r));
			r.erase(unique(all(r)),r.end());
			st.push(r);
		}else if(mp.count(c)){
			st.push(mp[c]);
		}else{
			st.push(vi(1,stoi(c)));
		}
	}
	cout << "correct\n";
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1000000000
using namespace std;
using ll = long long;
int main()
{
    int n;
    cin >> n;
    int tmp = n;
    int num = 0;
    while(tmp){
        num += tmp % 10;
        tmp /= 10;
    }
    if(n%num == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int d = 1;
        for(int i = 0; i < n; i++){
            if(d < k){
                d = d*2;
            } else {
                d = d + k;
            }
        }
        System.out.print(d);
    }
}

Measured memory_bytes: 23508
N = int(input())
task = [tuple(map(int, input().split())) for _ in range(N)]
task.sort(key=lambda x:x[1])
done_task = 0
flag = 0
for i in range(N):
  done_task += task[i][0]
  if done_task <= task[i][1]:
    continue
  else:
    flag = 1
    break

if(flag == 1):
  print("No")
else:
  print("Yes")
  

Measured memory_bytes: 31840
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_end().to_owned()
}

fn main() {
    let (n, m, x) = read!(isize, isize, isize);
    let list = read!([isize]; n);

    let mut can = vec![];
    
    for i in 0..(1 << n) {
        let mut score = vec![0; m as usize + 1];
        for j in 0..n as usize {
            if (i>>j) & 1 == 1 {
                for k in 0..m as usize+1 {
                    score[k] += list[j][k];
                }
            }
        }
        if *score[1..].iter().min().unwrap() >= x {
            can.push(score[0]);
        }
    }
    
    if can.is_empty() {
        println!("-1");
    } else {
        println!("{}", can.iter().min().unwrap());
    }
}


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

int main() {
  
  int a, b; cin >> a >> b;
  
  if (a < b) {
    cout << "a < b" << endl;
  }
  else if (a == b) {
    cout << "a == b" << endl;
  }
  else {
    cout << "a > b" << endl;
  }
  
}


Measured memory_bytes: 3088
using System;
using System.Collections.Generic;
using System.ComponentModel.Design.Serialization;
using System.Linq;

namespace ABC154D
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] NK = ReadLong();
            long N = NK[0];
            long K = NK[1];

            long[] p = ReadLong();
            double[] e = new double[N];
            for (int i = 0; i < N; i++)
            {
                e[i] = (p[i] + 1) / 2.0;
            }

            double ans = 0;
            double first = 0;
            for (int i = 0; i < K; i++)
            {
                first += e[i];
            }
            ans = first;

            for (long i = K; i < N; i++)
            {
                first = first - e[i - K] + e[i];
                if (first > ans) ans = first;
            }

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

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


Measured memory_bytes: 36700
lis = [int(input()) for _ in range(5)]
ans_fla_lis = []

for x in lis:
    if x%10 == 0:
        ans_fla_lis.append(0)
    else:
        ans_fla_lis.append(10-(x%10))
axo = ans_fla_lis.pop(ans_fla_lis.index(max(ans_fla_lis)))
print(sum(lis) + sum(ans_fla_lis))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int x, y, z;
  cin >> x >> y >> z;
  printf("%d %d %d\n", z, x, y);
  return 0;
}

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

#define int long long
#define all(x) x.begin(), x.end()

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

    int x, n;
    cin >> x >> n;
    vector<int> v(104);
    for (auto& i : v) i = 1;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        v[a] = false;
    }
    vector<int> ans;
    for (int i = 0; i < 105; i++)
        if (v[i]) ans.push_back(i);
    auto it = upper_bound(all(ans), x);
    int up = (*it);
    it--;
    auto mid = (*it);
    int res = up;
    if (abs(x - mid) <= abs(x - up)) res = mid;
    cout << res << endl;
}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	getline(cin,s);
	string t=s;
	for(int i=0;i<t.size();i++)
	{
		for(int j=0;j<t.size();j++)
		{
			t.erase(i,j);
			if(t.compare("keyence")==0){
				cout<<"YES\n";
				return 0;
			}
			t=s;
		}
	}
	cout<<"NO\n";
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s[3];
    for(int i=0;i<3;i++) cin >> s[i];

    int count = 0;
    for(int i=0;i<n;i++){
        set<char> set1={};
        for(int j=0;j<3;j++){
            set1.insert(s[j][i]);
        }
        count += set1.size()-1;
    }
    cout << count << endl;
}


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

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

    int p[n];
    for(int i=0; i<n;i++){
        cin >> p[i];
    }

    int count=0;

    for(int i=1;i<n-1;i++){
        if(p[i]>p[i-1] && p[i]<p[i+1]) count++;
        else if(p[i]<p[i-1] && p[i]>p[i+1]) count++;
    }

    cout << count << endl;

    return 0;
}


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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
typedef long long ll;
const int  INF = 1000000000;


int main() {
	int n, ma, mb;
	cin >> n >> ma >> mb;
	int a[45], b[45], c[45];
	REP(i, n) {
		cin >> a[i] >> b[i] >> c[i];
	}
	int dp[50][500][500];
	REP(i, 50)REP(j, 500)REP(k, 500)dp[i][j][k] = INF;
	dp[0][0][0] = 0;
	REP(i, n) {
		REP(j, 500) {
			REP(k, 500) {
				if (dp[i][j][k] == INF) continue;
				dp[i + 1][j + a[i]][k + b[i]] = min(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
				dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
			}
		}
	}
	int res = INF;
	FOR(i, 1, 50) {
		int d = ma * i, e = mb * i;
		if (d > 499 || e > 499) break;
		res = min(res, dp[n][d][e]);
	}
	if (res == INF)cout << -1 << endl;
	else cout << res << endl;
	return 0;
}

Measured memory_bytes: 49024
#include <iostream>
using namespace std;
using ll = long long;

ll min(ll x,ll y){
	if(x<y){
		return x;
	}else{
		return y;
	}
}

int main(){
	int N;
	ll array[100010]={};
	ll wa[100010]={};
	
	
	cin >> N;
	for(int i=1;i<=N;i++){
		cin >> array[i];
	}
	wa[1]=array[1];
	//奇数がマイナス
	
	
	ll answer=0;
	for(int i=1;i<=N;i++){
		if(i%2!=0){//奇数
			if(wa[i]>=0){
				answer+=wa[i]+1;
				wa[i]=-1;
			}
			wa[i+1]=array[i+1]+wa[i];
		}else{
			if(wa[i]<=0){
				answer+=abs(wa[i])+1;
				wa[i]=1;
			}
			wa[i+1]=array[i+1]+wa[i];
		}
	}
	
	for(int i=0;i<100010;i++){
		wa[i]=0;
	}
	wa[1]=array[1];
	
	ll answer_2=0;
	for(int i=1;i<=N;i++){
		if(i%2==0){//偶数
			if(wa[i]>=0){
				answer_2+=wa[i]+1;
				wa[i]=-1;
			}
			wa[i+1]=array[i+1]+wa[i];
		}else{
			if(wa[i]<=0){
				answer_2+=abs(wa[i])+1;
				wa[i]=1;
			}
			wa[i+1]=array[i+1]+wa[i];
		}
	}
	
	cout << min(answer,answer_2) << endl;
	
	return 0;
}


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

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

  int x;
  cin >> x;

  cout << ((x / 100 * 5) >= (x % 100)) << endl;

  return (0);
}


Measured memory_bytes: 3620
#include <iostream>
#include <math.h>
#include <stdio.h>
#define llint long long

using namespace std;

llint n, l;
llint t[3005];

int main(void)
{
	cin >> n >> l;
	for(int i = 1; i <= n; i++) cin >> t[i];
	
	double ansx = 0, ansy = 0;
	llint all = n*(n-1)*(n-2)/6;
	
	double sumx = 0, sumy = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i >= j) continue;
			sumx += cos(M_PI*(t[i]+t[j])/l) * (n-j);
			sumy += sin(M_PI*(t[i]+t[j])/l) * (n-j);
		}
	}
	ansx += sumx / all, ansy += sumy / all; 
	
	sumx = 0, sumy = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i >= j) continue;
			sumx += cos(M_PI*(t[i]+t[j])/l) * (i-1);
			sumy += sin(M_PI*(t[i]+t[j])/l) * (i-1);
		}
	}
	ansx += sumx / all, ansy += sumy / all;
	
	sumx = 0, sumy = 0;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			if(i >= j) continue;
			sumx += cos(M_PI*(t[i]+t[j])/l + M_PI) * (j-i-1);
			sumy += sin(M_PI*(t[i]+t[j])/l + M_PI) * (j-i-1);
		}
	}
	ansx += sumx / all, ansy += sumy / all;
	
	printf("%.11f %.11f\n", ansx, ansy);
	
	return 0;
}

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

int main()
{
  int n;
  scanf("%d",&n);
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    scanf("%d",&(a[i]));
  }
  for(int i=0;i<n;i++){
    scanf("%d",&(b[i]));
  }
  vector<int> ans;
  bool F=0;
  while(1){
    int t=1;
    while(t<=51){
      bool c[51][51]={0};
      for(int x=0;x<=50;x++){
	c[x][x]=1;
	for(int y=1;y<t;y++){
	  c[x][x%y]=1;
	}
	for(int y=0;y<ans.size();y++){
	  c[x][x%ans[y]]=1;
	}
      }
      for(int z=0;z<=50;z++){
	for(int x=0;x<=50;x++){
	  for(int y=0;y<=50;y++){
	    c[x][y]|=(c[x][z]&&c[z][y]);
	  }
	}
      }
      bool G=1;
      for(int i=0;i<n;i++){
	G&=c[a[i]][b[i]];
      }
      if(G==1)break;
      t++;
    }
    if(t==52){
      break;
    }
    if(t==1){
      F=1;
      break;
    }
    ans.push_back(t-1);
  }
  long long S=0;
  if(F){
    for(int i=0;i<ans.size();i++){
      S|=(1ll<<ans[i]);
    }
  }
  else{
    S=-1;
  }
  printf("%lld\n",S);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
    ll n;
    cin >> n;
    //cout << "n=" << n << endl;
    ll sum = n*(n+1)/2;
    ll nx;
    nx = n / 3;
    //cout << "nx=" << nx << endl;
    ll sum3 = nx*3*(nx+1)/2;
    nx = n / 5;
    //cout << "nx=" << nx << endl;
    ll sum5 = nx*5*(nx+1)/2;
    nx = n / 15;
    //cout << "nx=" << nx << endl;
    ll sum15 = nx*15*(nx+1)/2;
    ll ans = sum - (sum3 + sum5 - sum15);
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    int N,M;
    cin >> N >> M;
    vector<int> A(N);
    priority_queue<pair<int,int>> Q;
    REP(i,N){
        cin >> A[i];
        Q.push(make_pair(A[i],i));
    }
    while(!Q.empty() && M > 0){
        auto o = Q.top();Q.pop();
        int x = o.first; int y = o.second;
        x /= 2;
        A[y] = x;
        Q.push(make_pair(x,y));
        --M;
    }
    if(M >= 1){
        sort ALL(A);
      	reverse ALL(A);
        REP(i,N){
            if(M <= 0) break;
            --M;
            A[i] /= 2;
        }
    }
    ll ans = 0;
    REP(i,N){ans += A[i];}
    cout << ans << endl;
}

Measured memory_bytes: 1784
#include <stdio.h>

int W, H, x, y, r;
int main(){
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if (H - r >= y && y - r >= 0 && W - r >= x && x >= 0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2092
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<cstring>
#include<algorithm> 
using namespace std;
const double pai=3.1415926535;

int main()
{
	double res;
	int r;
	cin>>r;
	res=pai*2*r;
	printf("%.20lf",res);
}
 

Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
int a[100010],n,j;
int main()
{
   double distance,time,speed;
   cin >> distance >> time >> speed;
   double realtime=distance/speed;
   if(realtime<=time)
    cout << "Yes" << endl;
else cout << "No" << endl;
   
}

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

#define ll long long int

using namespace std;

int main() {
    ll x, n;
    cin >> x >> n;
    vector<ll> P(n);
    for (auto & p : P) cin >> p;
    vector<bool> Q(102, true);

    for (auto p : P) Q[p] = false;

    ll res = 100000;

    for (ll i = 0; i <= 101; ++i) {
        if (!Q[i]) continue;

        if (abs(x-i) < abs(x-res)) {
            res = i;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main(void){
	int num[6] = {0};
	for(int i = 0; i < 6; i++){
		scanf("%d", &num[i]);getchar();
	}
	if(num[4] - num[0] > num[5]){
		printf(":(\n");
	}else{
		printf("Yay!\n");
	}
	return 0;
}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

//0-indexed
template <class T>
class SegmentTree
{
	int size;
	T def;
	vector<T> data;
	function<T(T, T)> f;

public:
	SegmentTree<T>(int _size, T _def, function<T(T, T)> _f) : f(_f), def(_def), size(1)
	{
		while (size < _size)
			size <<= 1;
		data = vector<T>(size * 2, def);
	}
	//bottom-up implementation
	//query for[l, r)
	T query(int l, int r)
	{
		T L = def, R = def;
		for (l += size, r += size; l < r; l >>= 1, r >>= 1)
		{
			if (l & 1)
				L = f(L, data[l++]);
			if (r & 1)
				R = f(data[--r], R);
		}
		return f(L, R);
	}
	void update(int idx, T val)
	{
		idx += size;
		data[idx] = val;
		while (idx > 1)
		{
			idx >>= 1;
			data[idx] = f(data[2 * idx], data[2 * idx + 1]);
		}
	}
	T operator[](int idx)
	{
		return data[idx + size];
	}
};

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		vector<tuple<int, int, long long>> lrc(m);
		long long inf =0x3f3f3f3f3f3f3f3f;
		for(int i=0; i < m; i++){
			int l, r;
			long long c;
			cin >> l >> r >> c;
			lrc[i] = make_tuple(l-1, r-1, c);
		}
		sort(lrc.begin(), lrc.end());
		SegmentTree<long long> st(n, inf, [](long long a, long long b){return min(a, b);});
		st.update(0, 0);
		for(int i=0; i < m; i++){
			int l, r;
			long long c;
			tie(l, r, c) = lrc[i];
			st.update(r, min(st[r], st.query(l, r+1) + c));
		}
		if(st[n-1] >= inf)cout << -1 << endl;
		else cout << st[n-1] << endl;

	};
};

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

Measured memory_bytes: 3840
from networkx import*
(n,m),*t=[[*map(int,t.split())]for t in open(0)]
g=Graph()
g.add_edges_from(t)
try:a,b=map(len,algorithms.bipartite.sets(g));a*=b
except:a=n*~-n//2
print(a-m)

Measured memory_bytes: 162684
/*
方針として、
x軸かy軸が同じ点の集まりに対して、全(x,y)の格子点が作成される
ので、その点の集まりを作成すればよい

集まりはUnionFindで確認する。
要素は、x軸およびy軸
点(x,y)があると、そのx軸とy軸を統合する。
*/

#include <iostream>
#include <unordered_map>

using namespace std;

const char X = 'x';
const char Y = 'y';

// 軸オブジェクト
struct Axis {
  char name; // x軸かy軸か
  long long value; // 軸の座標
  // unordered_map のキーにするため実装(hashも下で実装している)
  bool operator==(const Axis& other) const { // 2個めのconstの意味は、constメンバ関数。内部でthisが変化しないので、constオブジェクトからも呼び出せるようになる
    return name == other.name && value == other.value;
  }
  bool operator!=(const Axis& other) const {
    return !(*this == other);
  }
  string to_s() const { //TODO: << に渡す型は本当は何か？
    return to_string(name) + ":" + to_string(value);
  }
};
namespace std{ //TODO: この書き方面倒くさい… hash()定義するのにstruct外って変じゃない？
    template<>
    class hash<Axis>{
        public:
        size_t operator () ( const Axis &p ) const{ return p.value << 2 + (p.name == X ? 1 : 0);}
        //TODO:どうhash作る？ ひとまずnameは2個しかないので、最終ビットに追加
        //別に一意になる必要はないが、衝突が少ない程良いmapになるはず
    };
}
// 領域
struct Area {
  int x; // x軸の数
  int y; // y軸の数
};
// union find実装
struct UnionFind {
  unordered_map<Axis, Axis> parents;
  unordered_map<Axis, Area> areas; // 領域はrootのみに持たせる。あとで領域ごとに計算するため。

  void add(Axis axis) { // Axisはintみたいな値型とみなして、ポインタ渡しはしない。他の関数も同じ
    if (parents.find(axis) != parents.end()) { //containsがc++17までないので、その代わり
      return;
    }

    parents[axis] = axis;
    areas[axis] = { // 初回はルートになるので、領域を持たせる
      axis.name == X ? 1 : 0,
      axis.name == Y ? 1 : 0};
  }

  void unite(Axis a, Axis b) {
    const Axis& ra = root(a);
    const Axis& rb = root(b);

    if (ra == rb) {
      return;
    }

    parents[rb] = ra;

    // 親になるほうに領域を統合して、他方は削除する
    areas[ra].x += areas[rb].x;
    areas[ra].y += areas[rb].y;
    areas.erase(rb);
  }

  Axis root(Axis a) {
    if (parents[a] != a) {
      parents[a] = root(parents[a]);
    }

    return parents[a];
  }
};

int main() {
  UnionFind uf;
  long long n;
  int x,y;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    cin >> y;
    Axis ax = {X, x};
    Axis ay = {Y, y};
    uf.add(ax); // x軸追加
    uf.add(ay); // y軸追加
    uf.unite(ax, ay); // x,y を統合
  }

  long long all_points = 0; // 全操作完了後の点の数
  for (const pair<const Axis, Area>& p : uf.areas) {
    //TODO:debug cout << "axis:" << p.first.to_s() << " area:" << p.second.x << ", " << p.second.y << endl;
    all_points += 1LL * p.second.x * p.second.y; //x*yがintをオーバーフローする可能性があるので、long long型にしておく
  }

  long long result = all_points - n; // もともとあったn個を引いたのが、作成された数

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 8868
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
#include <numeric>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9+7;
const int mod= 1e9 + 7;



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

	int N; cin >> N;
	vector<vector<int>> G(N);
	vector<pair<int, int>> vp;
	for (int i = 1; i < N; i ++ ) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
		vp.emplace_back(a, b);
	}
	int K = 0;
	map<pair<int, int>, int> mp;

	vector<int> cs(N, 0);
	vector<bool> used(N, false);

	queue<int> que;

	used[0] = 1;
	que.emplace(0);


	while (!que.empty()) {
		int v = que.front(); que.pop();
		K = max(K, int(G[v].size()));
		int cur = 1;

		for (int u : G[v]) {
			if (used[u])continue;
			if (cs[v] == cur)cur++;
			cs[u] = mp[make_pair(u, v)] = mp[make_pair(v, u)] = cur++;
			used[u] = true;
			que.emplace(u);
		}
	}


	cout << K << endl;
	for (auto p : vp)cout << mp[p] << endl;




	return 0;
}


Measured memory_bytes: 19704
#include<stdio.h>
int main(void) {
	int a, b, c; 
	scanf("%d %d %d",&a,&b,&c);
	if(a == 1)
		if(b == 1)
			printf("Open\n");
		else
			printf("Close\n");
	else
		if(c == 1)
			printf("Open\n");
		else
			printf("Close\n");
	return 0;
}

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

if A == B:
    if A == C:
        print("No")
    else:
        print("Yes")
elif A == C:
    if A == B:
        print("No")
    else:
        print("Yes")
elif B == C:
    if A == B:
        print("No")
    else:
        print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int H, W;
  std::cin >> H >> W;
  vvi r = vv(H, W, 0, int);
  vvi b = vv(H, W, 0, int);
  string s;
  vvi p = vv(H, W, 0, int);
  for(int i=0;i<H;i++) {
    std::cin >> s;
    for(int j=0;j<W;j++) p[i][j] = (s[j]=='#'?1:0);
  }
  for(int i=0;i<H;i++) for(int j=0;j<W;j++) if((j==0||i%2==0)&&j!=W-1) r[i][j] = 1;
  for(int i=0;i<H;i++) for(int j=0;j<W;j++) if((j==W-1||i%2==1)&&j!=0) b[i][j] = 1;
  for(int i=0;i<H;i++) for(int j=0;j<W;j++) if(p[i][j]==1) r[i][j] = b[i][j] = 1;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) std::cout << (r[i][j]==1?"#":".");
    std::cout << '\n';
  }
  std::cout << '\n';
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) std::cout << (b[i][j]==1?"#":".");
    std::cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


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

    for(int i=1; i<=N; ++i){
        cin >> a[i];
    }

    int ans = 0;
    for(int i=1; i<=N; ++i){
        if(i % 2 == 1 && a[i] % 2 == 1) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
q = gets.to_i
lr = q.times.map{gets.chomp.split(" ").map(&:to_i)}
m = lr.flatten.max
n = Array.new(m+1,1)
n[0..1] = [0,0]
p = 0
Math.sqrt(m).floor.times do
  p = n.index(1)
  n[p] = 2
  for i in p..m/p
    n[i*p] = 0
  end
end
for i in 0..m
  if n[m-i] != 0 && n[(m-i+1)/2] != 0
    n[m-i] = 1
  else
    n[m-i] = 0
  end
end
t = Array.new(m+1,0)
u = n.count(1)
(u-1).times do |i|
  p = n.index(1)
  n[p] = 0
  t[p..(n.index(1)-1)] = t[p..(n.index(1)-1)].map{|num|num = i+1}
end
t[n.index(1)..m] = t[n.index(1)..m].map{|num|num = u}
for i in 0..q-1
  puts t[lr[i][1]] - t[lr[i][0]-1]
end

Measured memory_bytes: 83380
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;
int n,f[500010];
char s[500010];
int main()
{
	scanf("%d",&n);
	scanf("%s",s+1);
	int cnt=0,mx=0,k=0;
	s[0]=0;
	for (int i=1;i<=n;i++)
	{
		f[i]=f[i-1];
		if (s[i]=='0')
		{
			if (s[i-1]=='0')
			{
				cnt=0;
				mx=0;
			}
			k=i-1;
		}
		else
		{
			if (s[i-1]=='0')
			{
				f[i]=max(f[i],mx+cnt);
				cnt=0;
				mx=0;
			}
			if (k>0 && s[k]!='0')
			{
				f[i]=max(f[i],f[k-1]+cnt+1);
			}
			mx=max(mx,f[i-1]-cnt);
			cnt++;
		}
		//cerr<<i<<" "<<cnt<<" "<<mx<<endl; 
		//cerr<<i<<" "<<f[i]<<endl;
	}
	printf("%d\n",f[n]);
    return 0;
}
//只愿君心似我心，定不负相思意。
//——李之仪《卜算子·我住长江头》

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

int main() {
  int N,count=0; cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++) cin >> L.at(i);

  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      for(int k=0; k<N; k++){
        if(i!=j && j!=k && k!=i) {
          if(L.at(i) != L.at(j) && L.at(j) != L.at(k) && L.at(k) != L.at(i)){
            if(L.at(i) + L.at(j) > L.at(k) && L.at(j) + L.at(k) > L.at(i) && L.at(k) + L.at(i) > L.at(j)){
            count++;
            }
          }
        }
      }
    }
  }
  int ans = count /6;
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const auto PI=acos(-1);
int main()
{
    long long int A,B,H,M;
    cin>>A>>B>>H>>M;
    long double Hour=360/12.00;
    long double Min=360/60.00;
    long double angel=fabs((H*Hour+M*0.5)-Min*M);
    long double C=(A*A)+(B*B)-(2.00*A*B*cos(angel*(PI/180)));
    cout<<setprecision(12)<<fixed<<sqrt(C)<<endl;

    return 0;
}


Measured memory_bytes: 4164
N, D = gets.chomp.split(" ").map(&:to_i)
X = []
N.times do |i|
  X << gets.chomp.split(" ").map(&:to_i)
end

cnt = 0
0.upto(N-2) do |i|
  (i+1).upto(N-1) do |j|
    d2 = X[i].zip(X[j]).map { |y, z| (y - z)**2 }.inject(:+)
    d = Math.sqrt(d2)
    cnt += 1 if d == d.to_i
  end
end
puts cnt


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

ll inf=9223372036854775806,mod=1000000007;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,j,k=0,m;
	bool q,w=false;
	string s,t;
	cin>>s>>t;
	for (i=0;i<s.size()-t.size()+1;i++){
		q=true;
		for (j=i;j<t.size()+i;j++){
			if (s[j]!='?'&&s[j]!=t[j-i]){
				q=false;
				break;
			}
		}
		if (q==true){
			w=true;
			m=i;
		}
	}
	if (w==false){
		cout<<"UNRESTORABLE";
	}
	else {
		for(i=0;i<m;i++){
			if (s[i]=='?'){
				cout<<"a";
			}
			else {
				cout<<s[i];
			}
		}
		cout<<t;
		for (i=m+t.size();i<s.size();i++){
			if (s[i]=='?'){
				cout<<"a";
			}
			else{
				cout<<s[i];
			}
		}
	}
 	return 0;
}

Measured memory_bytes: 256