akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
const int N = 2e5 + 5;
const int inf = 2e9;
typedef std :: pair <int, int> pii;
typedef long long ll;
inline int Get() {
	char ch;
	while ((ch = getchar()) < '0' || ch > '9');
	int Num = ch - '0';
	while ((ch = getchar()) >= '0' && ch <= '9')
		Num = (Num << 3) + (Num << 1) + ch - '0';
	return Num;
}
char s[N];
int n, que[N], qn, fa[N], dep[N], top[N], sze[N];
int cnt, a[N], preL[N], preR[N], low[N], height[N];
pii tr[N];
int tot, first[N], next[N << 1], end[N << 1];
inline int AddEdge(int x, int y) {
	next[++tot] = first[x], first[x] = tot, end[tot] = y;
	next[++tot] = first[y], first[y] = tot, end[tot] = x;
}
inline pii merge(const pii &a, const pii &b) {
	pii c;
	if (a.first == b.first) c.first = c.second = a.first;
	else 
		if (a.first > b.first) c.first = a.first, c.second = std :: max(a.second, b.first);
		else c.first = b.first, c.second = std :: max(a.first, b.second);
	return c;
}
int main() {
	n = Get();
	for (int i = 1; i < n; ++i) AddEdge(Get(), Get());
	scanf("%s", s + 1);
	
	que[qn = 1] = 1;
	for (int ql = 1, u; u = que[ql], ql <= qn; ++ql)
		for (int k = first[u], v; v = end[k], k; k = next[k])
			if (v != fa[u]) fa[v] = u, que[++qn] = v;
	
	for (int qr = qn, u; u = que[qr], qr; --qr) {
		sze[u] = s[u] == '1', dep[u] = 0, tr[u] = std :: make_pair(0, 0);
		for (int k = first[u], v; v = end[k], k; k = next[k])
			if (v != fa[u]) {
				sze[u] += sze[v], dep[u] = std :: max(dep[u], dep[v] + 1);
				
				if (tr[v].first + 1 > tr[u].first) tr[u].second = tr[u].first, tr[u].first = tr[v].first + 1;
				else if (tr[v].first + 1 > tr[u].second) tr[u].second = tr[v].first + 1;
			}
	}
	
	top[1] = 0;
	for (int ql = 1, u; u = que[ql], ql <= qn; ++ql) {		
		if (top[u] > tr[u].first) tr[u].second = tr[u].first, tr[u].first = top[u];
		else if (top[u] > tr[u].second) tr[u].second = top[u];
	
		cnt = 0;
		for (int k = first[u], v; v = end[k], k; k = next[k]) if (v != fa[u]) a[++cnt] = v;
		
		preL[0] = top[u] + 1, preR[cnt + 1] = 0;    
		for (int i = 1, v; v = a[i], i <= cnt; ++i) preL[i] = std :: max(preL[i - 1], tr[v].first + 2);
		for (int i = cnt, v; v = a[i], i >= 1; --i) preR[i] = std :: max(preR[i + 1], tr[v].first + 2);
		for (int i = 1, v; v = a[i], i <= cnt; ++i) top[v] = std :: max(preL[i - 1], preR[i + 1]);
	}
	
	for (int i = 1; i <= n; ++i) low[i] = inf, height[i] = std :: min(tr[i].first - 1, tr[i].second + 1);
	for (int i = 1; i <= n; ++i) if (fa[i] && sze[i]) low[fa[i]] = std :: min(low[fa[i]], dep[i] + 1); 
	for (int i = 1; i <= n; ++i) if (sze[1] - sze[i]) low[i] = std :: min(low[i], top[i]);
	
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (s[i] == '1') low[i] = 0;
		if (low[i] <= height[i]) ans += height[i] - low[i] + 1;
	}
	
	printf("%lld\n", ans + 1);
}

Measured memory_bytes: 13696
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    int a[n], x;
    for (int i = 0; i < n; i++) {
        cin >> x;
        a[i] = x;
    }
    int cur = 0, cnt = 1, tmp;
    while (a[cur] != -1 && a[cur] != 2) {
        tmp = cur;
        cur = a[cur] - 1;
        a[tmp] = -1;
        cnt++;
    }
    if (a[cur] == 2) {
        cout << cnt << endl;
    }else{
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define double long double
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

/*int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}
*/


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
    int x;
    cin>>x;
    x^=1;
    cout<<x<<endl;
}


return 0;
}





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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define INF (int)1e8
#define EPS 1e-9

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

int main() {
  int N, M;
  cin >> N >> M;
  int num[N] = {0};
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    num[a - 1]++, num[b - 1]++;
  }

  rep(i, N) cout << num[i] << endl;
}

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

const int MAX = 5e5 + 5;
int n, m;
char s[MAX];
set <int> pos[26];

int main() {
	scanf("%d%s%d", &n, s + 1, &m);

	for(int i = 1; i <= n; i++)
		pos[s[i] - 'a'].insert(i);

	while(m--) {
		int op; scanf("%d", &op);

		if(op == 1) {
			int p; char w[5];
			scanf("%d%s", &p, w);

			if(s[p] == w[0])
				continue;

			auto &st = pos[s[p] - 'a'];

			assert(st.find(p) != st.end());
			st.erase(st.find(p));

			auto &nst = pos[w[0] - 'a'];
			nst.insert(p);

			s[p] = w[0];
		}

		else {
			int l, r; scanf("%d%d", &l, &r);

			int ans = 0;
			for(int i = 0; i < 26; i++) {
				auto it = pos[i].lower_bound(l);

				if(it != pos[i].end() && *it <= r)
					ans++;
			}

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

	return 0;
}

Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int r, g, b;
    cin >> r >> g >> b;
    cout << (((g * 10 + b) % 4 == 0) ? "YES" : "NO") << endl;
}

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

map< pair<int, int>, int> M;

int f1(int i)
{
    int ans = 0;

    while(i)
        ans = i % 10, i /= 10;

    return ans;
}

int f2(int i)
{
    return i % 10;
}

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

    int N;
    cin >> N;

    for(int i=1; i<=N; i++)
        M[{f1(i), f2(i)}]++;

    long long ans = 0;

    for(int i=1; i<=9; i++)
    {
        ans += 1LL * M[{i, i}] * M[{i, i}];

        for(int j=i+1; j<=9; j++)
            ans += 2LL * M[{i, j}] * M[{j, i}];
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
n, d = map(int, input().split())
lists = []
cnt = 0

for i in range(n):
  x, y = map(int, input().split())
  lists.append([x, y])
  

for j in range(n):
  l = (lists[j][0] ** 2 + lists[j][1] ** 2) ** (1 / 2)
  if l <= d:
    cnt += 1
  # else:
  #   continue

print(cnt)

Measured memory_bytes: 39512
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define ic_a int a;cin>>a;
#define ic_b int b;cin>>b;
#define ic_s string s;cin>>s;
#define Rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000
using ll = long long;
using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;
typedef long double ld;
const ld eps = 1.0e-10; // 許容される誤差
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int keta(int n) {
	int sum = 0;
	while (n != 0) {
		sum += n % 10; n /= 10;
	}
	return sum;//Nanashi,tRue,wai
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */
ld mysqrtl(ld x)
{
	ld a = sqrtl((double)x); // 近似値
	do {
		a = (a + x / a) / 2.0L;
	} while (fabsl(x - a * a) > eps);
	return a;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);

}

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

//平方根を求める。sqrtより精度が高い。
//epsを変えて誤差を調整する。
int main(void) {
	Rapid_pleaseAC_fast;
	llint ans = 0, n = 0, m = 0, count = 0, sum = 0;
	llint k, a, b;
	bool check = false;
	string ss;
	vector<llint> array;
	vector<char> ch;
	cin >> k>>a>>b;
	for (int i = a; i <= b; i++) {
		if (i % k == 0) {
			cout << "OK" << endl;
			break;
		}
		if (i == b)cout << "NG" << endl;
	}
	

	please AC;
}


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

#define lli long long unsigned

lli x;

int main(){
    cin >> x;

    lli ans;
    ans = (x/11)*2;
    x -= 11*(ans/2);

    if(x % 11 > 0 and x % 11 < 7)ans+=1;
    else if(x % 11 > 6) ans += 2;

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, l, r) for(int i = l; i <= r; ++i)
const int N = 200000 + 5;
const int M = 30 + 5;
const int inf = 1000000000 + 1;
struct node{
    int a, b;
}a[N], b[N];
int n, m, T, cnt, ans, S[N], mx[M], dp[N][M];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
bool cmp1(node x, node y){
    return 1ll * x.b * y.a - 1ll * x.a * y.b < x.a - y.a;
}
bool cmp2(node x, node y){
    return x.b < y.b;
}
int main(){
    cnt = read(), T = read();
    rep(i, 1, cnt){
        a[i].a = read(), a[i].b = read();
        if(!a[i].a) b[++m] = a[i];
        else a[++n] = a[i];
    }
    sort(a + 1, a + n + 1, cmp1), sort(b + 1, b + m + 1, cmp2);
    rep(i, 0, n) rep(j, 0, M - 5) dp[i][j] = mx[j] = inf;
    dp[0][0] = mx[0] = 0;
    rep(i, 1, n){
        rep(j, 1, M - 5) if(1ll * (mx[j - 1] + 1) * (a[i].a + 1) + a[i].b <= T){
            dp[i][j] = (mx[j - 1] + 1) * (a[i].a + 1) + a[i].b;
        }
        rep(j, 1, M - 5) mx[j] = min(mx[j], dp[i][j]);
    } 
    rep(i, 1, m) S[i] = min(S[i - 1] + b[i].b + 1, inf);
    ans = upper_bound(S + 1, S + m + 1, T) - S - 1;
    rep(i, 1, n) rep(j, 1, M - 5) if(dp[i][j] < inf){
        int P = upper_bound(S + 1, S + m + 1, T - dp[i][j]) - S;
        ans = max(ans, j + P - 1);
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 32508
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn accum_sum(inputs: &Vec<i64>) -> Vec<i64> {
    let mut ret: Vec<i64> = vec![0; inputs.len()];
    ret[0] = inputs[0];
    for i in 1..inputs.len() {
        ret[i] = ret[i - 1] + inputs[i];
    }
    return ret;
}

fn main() {
    let _n: i32 = read();
    let a: Vec<i64> = read_vec();
    // let a:Vec<i64> = vec![5, 1, 3, 5, 10, 7, 4, 9, 2, 8];
    // let a:Vec<i64> = vec![3, 2, 4, 1, 2];
    // let a:Vec<i64> = vec![10, 71, 84, 33, 6, 47, 23, 25, 52, 64];
    // let a:Vec<i64> = vec![1, 2, 3, 1000000000, 4, 5, 6];
    let accum = accum_sum(&a);
    // println!("{:?}", accum);

    let mut s: usize = 0;
    let mut t: usize = 1;
    let mut best_split1 = vec![0; a.len()];
    while s < a.len() {
        while t < a.len() && accum[s] > accum[t] - accum[s] {
            best_split1[t] = s;
            t += 1;
        }
        if  t == a.len() {
            break;
        }
        s += 1;
    }
    // println!("before {:?}", best_split1);
    for t in 1..best_split1.len() {
        let s = best_split1[t];
        if s == 0 {
            continue;
        }
        if (accum[t] - accum[s] - accum[s]).abs() > (accum[t] - accum[s-1] - accum[s-1]).abs() {
            best_split1[t] = s - 1;
        }
    }
    // println!("after {:?}", best_split1);

    let mut s: usize = a.len() - 1;
    let mut t: usize = a.len() - 1;
    let mut best_split2 = vec![0; a.len()];
    'outer: loop {
        while accum[a.len() - 1] - accum[s] > accum[s] - accum[t] {
            best_split2[t] = s;
            if  t == 0 {
                break 'outer;
            }
            t -= 1;
        }
        s -= 1;
    }
    // println!("before {:?}", best_split2);
    for t in 1..best_split2.len() {
        let s = best_split2[t];
        if s == 0 {
            continue;
        }
        if (accum[a.len() - 1] - accum[s] - accum[s] + accum[t]).abs() >
           (accum[a.len() - 1] - accum[s + 1] - accum[s + 1] + accum[t]).abs() {
            best_split2[t] = s + 1;
        }
    }
    // println!("after {:?}", best_split2);

    let mut min_elem:i64 = 1000000000000000000;
    for t in 1..a.len() - 1 {
        let s1 = best_split1[t];
        let s2 = best_split2[t];
        // println!("{0} {1} {2}", s1, t, s2);
        let mut sums = vec![0; 4];
        sums[0] = accum[s1];
        sums[1] = accum[t] - accum[s1];
        sums[2] = accum[s2] - accum[t];
        sums[3] = accum[a.len() - 1] - accum[s2];
        if let Some(max) = sums.iter().max() {
            if let Some(min) = sums.iter().min() {
                // println!("{:?}", sums);
                // println!("max: {0} min: {1}", max, min);
                min_elem = std::cmp::min(min_elem, max - min);
            }
        }
    }
    println!("{:?}", min_elem);
}


Measured memory_bytes: 15092
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll a, b, q; cin >> a >> b >> q;
    vi s(a+2, (1LL<<60)), t(b+2, (1LL<<60));
    repf(i, a) cin >> s[i]; s[0] *= -1;
    repf(i, b) cin >> t[i]; t[0] *= -1;

    rep(cnt, q){
        ll x; cin >> x;

        // xを始点に東西で最短距離の神社と寺を探す。
        ll EsIdx = lower_bound(all(s), x)-s.begin();
        ll EtIdx = lower_bound(all(t), x)-t.begin();
        ll WsIdx = (s[EsIdx] == x ? EsIdx : EsIdx-1);
        ll WtIdx = (t[EtIdx] == x ? EtIdx : EtIdx-1);

        // (E,E), (E,W), (W,E), (W,W)の4パターンを試して最小値を出力
        ll ans = INFLL;
        
        // (E,E)
        if(s[EsIdx] != (1LL<<60) && t[EtIdx] != (1LL<<60)) chmin(ans, abs(max(s[EsIdx], t[EtIdx])-x));

        // (W,W)
        if(s[WsIdx] != -(1LL<<60) && t[WtIdx] != -(1LL<<60)) chmin(ans, abs(min(s[WsIdx], t[WtIdx])-x));

        // (E,W)(W,E)
        if(s[EsIdx] != (1LL<<60) && t[WtIdx] != -(1LL<<60)) chmin(ans, min(abs(x-s[EsIdx]), abs(x-t[WtIdx]))*2+max(abs(x-s[EsIdx]), abs(x-t[WtIdx])));
        if(s[WsIdx] != -(1LL<<60) && t[EtIdx] != (1LL<<60)) chmin(ans, min(abs(x-s[WsIdx]), abs(x-t[EtIdx]))*2+max(abs(x-s[WsIdx]), abs(x-t[EtIdx])));
        cout << ans << endl;
    }
}

Measured memory_bytes: 4748
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////
/////////////////////////


int main() {

    int n, m;
    I2(n,m);

    int res = 1000000;
    for(int i = 1;i<=n;i++){
        int x,y;
        I2(x, y);
        if( y <= m)res = min(res, x);
    }
    if(res == 1000000) cout<<"TLE"<<endl;
    else cout<<res<<Endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,f[1000009],lef,rig;
string s,h;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>s>>h;
	if(h.size()<=s.size()){
		cout<<"No";
		return 0;
	}
	for(i=0; i<s.size(); i++){
		if(s[i]!=h[i]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3656
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Console;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] input = In.ReadToEnd().Split(new[] { " ", "\n", "\r" },
        StringSplitOptions.RemoveEmptyEntries);

    T Get<T>(Func<string, T> parser) => parser(input[idx++]);

    public string S => Get(s => s);
    public char C => Get(char.Parse);
    public int I => Get(int.Parse);
    public long L => Get(long.Parse);
    public double F => Get(double.Parse);
    public decimal D => Get(decimal.Parse);
    public BigInteger B => Get(BigInteger.Parse);

    T[] Gets<T>(int n, Func<string, T> parser)
        => input.Skip((idx += n) - n).Take(n).Select(parser).ToArray();

    public string[] Ss(int n) => Gets(n, s => s);
    public char[] Cs(int n) => Gets(n, char.Parse);
    public int[] Is(int n) => Gets(n, int.Parse);
    public long[] Ls(int n) => Gets(n, long.Parse);
    public double[] Fs(int n) => Gets(n, double.Parse);
    public decimal[] Ds(int n) => Gets(n, decimal.Parse);
    public BigInteger[] Bs(int n) => Gets(n, BigInteger.Parse);

    public void Write<T>(params T[] xs) => WriteLine(string.Join(" ", xs));
    public void Write(params object[] xs) => WriteLine(string.Join(" ", xs));
}

#region Library

static class Extentions
{
}

#endregion

static class Program
{
    public static void Main()
    {
        var sw = new StreamWriter(OpenStandardOutput()) { NewLine = "\n" };
#if DEBUG
        sw.AutoFlush = true;
#else
        sw.AutoFlush = false;
#endif
        SetOut(sw);
        Solve(new IO());
        Out.Flush();
    }

    static void Solve(IO io)
    {
        var n = io.I;
        var a = io.I;

        io.Write(n * n - a);
    }
}

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

ll solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> A[i];
    }
    ll ans = 0;
    if ( A[0] != 0 ) return -1;
    for ( int i = 1; i < N; i++ ) {
        if ( A[i] > A[i-1] + 1 ) return -1;
        else if ( A[i] == A[i-1] + 1 ) ans++;
        else ans += A[i];
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  vl L(N);
  rep(i, N) cin >> L[i];

  ll tot = accumulate(L.begin(), L.end(), 0);

  rep(i, N){
    if(tot - L[i] <= L[i]){
      cout << "No\n";
      return 0;
    }
  }

  cout << "Yes\n";
  
  return 0;
}


Measured memory_bytes: 3628
lines = readlines.map(&:strip).map{|line| line.split.map(&:to_i)}

n, m = lines.shift
gates = lines

gate = lines[0]
gates.each do |lower, upper|
  gate[0] = lower if gate[0] < lower
  gate[1] = upper if gate[1] > upper
end

# puts gate.inspect

puts ((gate[0]..gate[1]).to_a & (1..n).to_a).count





Measured memory_bytes: 23900
import sys
N = int(input())
A = list(map(int, input().split()))
a = min(A)
b = a
while True:
    for _a in A:
        _b = _a % a
        if _b > 0 and _b < a:
            b = _b
    if b == a:
        print(a)
        sys.exit()
    a = b


Measured memory_bytes: 20132
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>

void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    bool flag = true;
    for (int i = 0; i < 3; i++) {
        if (S[i] == S[i + 1])
            flag = false;
    }
    if (flag) {
        cout << "Good" << endl;
    } else {
        cout << "Bad" << endl;
    }
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
     
    int main()
    {
    	char S[10];
    	scanf("%s", S);
     
    	int ans = 0;
    	for (int i = 0; i < 4; ++i) {
    		if (S[i] == '+') ++ans;
    		else --ans;
    	}
    	printf("%d\n", ans);
    	return 0;
    }

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {

	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int counter = 0;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++) {
				if (500 * i + 100 * j + 50 * k == X) counter++;
			}
		}
	}
	cout << counter << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N,K;cin>>N>>K;
  if(1<2*K-N)
    cout<<-1<<endl;
  else{
  if(N%2==1){
  int64_t k=(N-1)/2;
    for(int64_t i=0;i<=k;i++)
      cout<<K+2*i<<" "<<K+N+k-i<<" "<<K+2*N+i<<endl;
    for(int64_t i=0;i<k;i++)
      cout<<K+2*i+1<<" "<<K+2*N-1-i<<" "<<K+2*N+i+k+1<<endl;
  }else{
  int64_t k=N/2;
    for(int64_t i=0;i<=k-1;i++)
      cout<<K+2*i<<" "<<K+N+k-i<<" "<<K+2*N+i<<endl;
    for(int64_t i=0;i<k-1;i++)
      cout<<K+2*i+1<<" "<<K+N+N+i-2*i-1<<" "<<K+2*N-k+N+i<<endl;
    cout<<K+N-1<<" "<<K+N<<" "<<K+3*N-1<<endl;
  }
  }
  return 0;
}

Measured memory_bytes: 3588
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

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

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++;
	cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////


int main(){
	int N, x; vi a;
	scan(N, x);
	a.resize(N);
	FOR(i,0,N) scan(a[i]);
	sort(all(a));
	int ans=0;
	FOR(i,0,N){
		if(x >= a[i]){
			ans++;
			x -= a[i];
		}
	}
	if(x > 0 && ans==N) ans--;
	printf("%d",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int tmp=0;
    vector<int> a(N,0);
    for(int i=1;i<N;i++){
        cin>>tmp;
        a[tmp-1]++;
    }
    
    for(int i=0;i<N;i++){
        cout<<a[i]<<endl;
    }
    return 0;
}


Measured memory_bytes: 4000
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let k: usize = scan(tokens);
    if k % 2 == 1 || k > n * n / 2 {
        println!("0");
        return;
    }
    let k = k / 2;
    let modulo: usize = 1_000_000_007;
    let mut dp: Vec<Vec<Vec<usize>>> = vec![vec![vec![0; k + 1]; n + 1]; 2];
    dp[0][0][0] = 1;
    for a in 1..n + 1 {
        for b in 0..n + 1 {
            for c in 0..k + 1 {
                let mut tmp: usize = 0;
                if b <= c {
                    if b != 0 {
                        tmp += dp[(a - 1) & 1][b - 1][c - b];
                    }
                    tmp += (2 * b + 1) * dp[(a - 1) & 1][b][c - b];
                    if b < n {
                        tmp += (b + 1) * (b + 1) * dp[(a - 1) & 1][b + 1][c - b];
                    }
                }
                dp[a & 1][b][c] = tmp % modulo;
            }
        }
    }
    println!("{}", dp[n & 1][0][k]);
}


Measured memory_bytes: 4352
/*
 * 16-07-15_ARC078_C.cpp
 *
 *  Created on: 2017/07/15
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>
#include<limits.h>
using namespace std;

typedef long long ll;
const int INF=INT_MAX;

int main(){
	int N;
	ll a[2*112345];
	ll sum=0;
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> a[i];
		sum += a[i];
	}
	ll ans = INF;
	ll x=0;
	for(int i=0;i<N-1;i++){
		x += a[i];
		ans = min(ans,abs(2*x-sum));
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

#include <atcoder/modint>
#include <atcoder/convolution>

int main() {
	int N, M;
	cin >> N >> M;
	
	vector<int> a(N), b(M);
	REP(i, N) scanf("%d", &a[i]);
	REP(i, M) scanf("%d", &b[i]);
	
	auto c = atcoder::convolution(a, b);
	REP(i, N + M - 1) printf("%d%c", c[i], " \n"[i + 1 == N + M - 1]);
	
	return 0;
}


Measured memory_bytes: 19016
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>
#include <functional>
#include <map>
#include <cstdlib>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int select(vector<int>& v){
    int ret = 0;
    for(int i=1; i<v.size(); i++){
        if(v[i] < v[ret]) ret = i;
    }
    return ret;
}

void fwd(string& A, Vvec<int>& dp){
    for(int i=A.size()-1; i>=0; i--){
        for(int k=0; k<26; k++) dp[i][k] = dp[i+1][k];
        int j = A[i] - 'a';
        int s = select(dp[i]);
        dp[i][j] = dp[i][s] + 1;
    }
}

string bwd(string& A, Vvec<int>& dp){
    string ans;
    int k = select(dp[0]);
    for(int i=0; i<A.size(); i++){
        if(A[i]-'a' != k) continue;
        ans += static_cast<char>('a'+k);
        k = select(dp[i+1]);
    }
    ans += static_cast<char>('a'+k);
    return ans;
}

int main()
{
    string A;
    cin >> A;
    Vvec<int> dp(A.size()+1, vector<int>(26, 1));

    fwd(A, dp);
    string ans = bwd(A, dp);

    cout << ans << endl;
}

Measured memory_bytes: 27012
#include <bits/stdc++.h>
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
int n,dp[2003][2003],a[6003],ans,tg,MX[2003],cur;
int A[100004],B[100004],C[100004],t;
void add(int x,int y,int z){if(dp[x][y]<z)A[t]=x,B[t]=y,C[t++]=z;}
int main(){
	cin>>n;
	for(int i=1;i<=3*n;i++)scanf("%d",&a[i]);
	memset(dp,-1,sizeof(dp));
	memset(MX,-1,sizeof(MX));
	dp[a[1]][a[2]]=dp[a[2]][a[1]]=MX[a[1]]=MX[a[2]]=cur=0;
	for(int i=3;i<3*n;i+=3){
		if(a[i]==a[i+1]&&a[i]==a[i+2]){tg++;continue;}
		t=0;
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i+1]>a[i+2])swap(a[i+1],a[i+2]);
		if(a[i]>a[i+1])swap(a[i],a[i+1]);
		if(a[i]==a[i+1]||a[i+1]==a[i+2])for(int j=1;j<=n;j++){
			if(a[i]==a[i+1]){
				if(dp[j][a[i]]>=0)add(j,a[i+2],dp[j][a[i]]+1);
			}else if(dp[j][a[i+1]]>=0)add(j,a[i],dp[j][a[i+1]]+1);
		}
		if(dp[a[i]][a[i]]>=0)add(a[i+1],a[i+2],dp[a[i]][a[i]]+1);
		if(dp[a[i+1]][a[i+1]]>=0)add(a[i],a[i+2],dp[a[i+1]][a[i+1]]+1);
		if(dp[a[i+2]][a[i+2]]>=0)add(a[i],a[i+1],dp[a[i+2]][a[i+2]]+1);
		add(a[i],a[i+1],cur),add(a[i+1],a[i+2],cur),add(a[i],a[i+2],cur);
		for(int k=1;k<=n;k++)if(MX[k]>=0)add(a[i],k,MX[k]),add(a[i+1],k,MX[k]),add(a[i+2],k,MX[k]);
		for(int j=0;j<t;j++)if(dp[A[j]][B[j]]<C[j])
			dp[A[j]][B[j]]=dp[B[j]][A[j]]=C[j],MX[A[j]]=max(MX[A[j]],C[j]),MX[B[j]]=max(MX[B[j]],C[j]),cur=max(cur,C[j]);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++)ans=max(ans,dp[i][j]);
		if(dp[i][i]>=0)if(i==a[3*n])ans=max(ans,dp[i][i]+1);
	}
	printf("%d",ans+tg);
}

Measured memory_bytes: 19580
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false); cin.tie(0) ;
using ll = long long ;
const int N = 1010;
const int INF = 1e9 + 10 ;
int n, m;
vector<vector<int> > graph;
vector<int> vis; 
ll dp[100010];
int dfs(int x){
    if ( vis[x] ) return 0;
    if ( dp[x] != -1 ) return dp[x] ;
    int ans = 0 ; 
    for(int v : graph[x]){
        if ( !vis[v] )
            ans = max(ans, 1 + dfs(v));
    }
    return dp[x] = ans;
}
int main(){
    fastio 
    memset(dp, -1, sizeof dp) ;
    cin >> n >> m ; 
    graph.resize(n + 1) ;
    vis.resize(n + 1) ;
    for(int i = 0; i < m; i++){
        int x , y ;
        cin >> x >> y ; 
        graph[x].push_back(y) ;
    }
    int ans = 0 ; 
    for(int i = 1; i <= n; i++){
        if ( !vis[i] ){
            ans = max(ans, dfs(i));
        }
    }
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n, a, b;
  cin >> n;
  if(n == 1){
    cout << "Hello World" << endl;
    return 0;
  }
  cin >> a >> b;
  cout << a + b << endl;
  return 0;
}

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

using namespace std;

using ll = long long;

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

    constexpr ll n = 50;
    array<ll, n> d;
    for (int i = 0; i < n; ++i) d[i] = i;

    ll k;
    cin >> k;

    if (n <= k) {
        ll tm = k / n;
        for (int i = 0; i < n; ++i) d[i] += n * tm - tm * (n - 1);
        k %= n;
    }
    for (int i = 0; i < k; ++i) d[i] += n - (k - 1);
    for (int i = k; i < n; ++i) d[i] -= k;

    cout << n << '\n';
    for (int i = 0; i < n; ++i)
        cout << d[i] << " \n"[i == n - 1];

    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math

sys.setrecursionlimit(10 ** 7)

from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, q = map(int, readline().split())

a = [0 for _ in range(q)]
b = [0 for _ in range(q)]
c = [0 for _ in range(q)]
d = [0 for _ in range(q)]

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, readline().split())

A = [1]
ans = 0
def dfs():
    if len(A) == n + 1:
        acc = 0
        for i in range(q):
            if A[b[i]] - A[a[i]] == c[i]:
                acc += d[i]
        global ans
        ans = max(ans, acc)
        return
    A.append(A[-1])
    while A[-1] <= m:
        dfs()
        A[-1] += 1
    A.pop()

dfs()
print(ans)

Measured memory_bytes: 9392
import Data.Bits
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
main=print.solve.unfoldr(B.readInt.B.dropWhile isSpace)=<<B.getContents
solve(n:as)=f 0 0 0 0 where
  vs=V.fromList as
  f s x l r
    |r>=n=let k=(r-l)in s+k*(k+1)`div`2
    |x .&. a==0=f s(xor x a)l(r+1)
    |otherwise=f(s+r-l)(xor x$vs V.! l)(l+1)r
    where a=vs V.! r

Measured memory_bytes: 13956
#include <stdio.h>

typedef struct { char suit, value; } Card;

void bubble(Card A[], int N) {
  int i,j;
  Card t;
  for(i = 0; i<N; i++) {
    for(j = N-1; j >= i; j--) {
      if(A[j].value < A[j-1].value) {
        t = A[j]; A[j] = A[j-1]; A[j-1] = t;
      }
    }
  }
}

void selection(Card A[], int N) {
  int i,j,minj;
  Card t;
  for(i=0;i<N;i++) {
    minj = i;
    for(j=i; j<N; j++) {
      if(A[j].value < A[minj].value) minj = j;
    }
    t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(i>0) printf(" ");
      printf("%c%d",A[i].suit,A[i].value);
  }
  printf("\n");
}

int isStable(Card C1[], Card C2[], int N) {
  int i;
  for(i=0; i<N; i++) {
    if(C1[i].suit != C2[i].suit) return 0;
  }
  return 1;
}

/* オリジナル関数を追加 */
void str2Card(Card *t,char str[]) {
    t->suit  = str[0];
    t->value = str[1] - '0';
}

int main(void) {
  Card C1[100], C2[100];
  int N,i;
  char str[3];

  scanf("%d",&N);
  for(i=0;i<N; i++) {
    scanf("%s",str);
    str2Card(&C1[i],str);
  }

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

  bubble(C1,N);
  selection(C2,N);

  print(C1,N);
  printf("Stable\n");
  print(C2,N);
  if(isStable(C1,C2,N)) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}


Measured memory_bytes: 2056
import java.util.*;
import java.util.stream.Collectors;


public class Main {
    public static void main(String[] args) {

        Scanner in=new Scanner(System.in);

        int N = in.nextInt();
        int ans=0;
        
        for(int i=0;i<N;i++){
        	int a=in.nextInt();
        	
        	for(;a%2==0;a/=2)
        		ans++;
        	
        }
        
        System.out.println(ans);


    }

}


Measured memory_bytes: 37600
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll calc(int X) {
    vll dp(X + 1);
    ll p = 1000000007;
    dp[0] = 1;
    dp[1] = 1;
    REP(i, 2, X + 1) {
        dp[i] += (dp[i - 1] + dp[i - 2]) % p;
        dp[i] %= p;
    }
    return dp[X];
}

const int MAX = 1100000;
const int MOD = 1000000007;

ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll COM(ll n, ll k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int X, Y;
    ll p = 1000000007;
    cin >> X >> Y;
    if ((X + Y) % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int N = (X + Y) / 3;
    int cnt = 0;
    rep(i, N) {
        if (X * 2 == Y) break;
        X -= 2;
        Y -= 1;
        if (X < 0 || Y < 0) {
            cout << 0 << endl;
            return 0;
        }
        cnt++;
    }
    COMinit();
    cout << COM(N, cnt) << endl;
    return 0;
}

Measured memory_bytes: 25984
# -*- coding: utf-8 -*-
import sys

x =int(input())

app = []
for i in range(0,10000):
    app.append(i**5)

flag = False
store=[]
for i in app:
    for j in app:
        if i - j == x:
            store.append(i**(1/5))
            store.append(j**(1/5))
            flag = True
            break
        elif -i - j == x:
            store.append(i**(1/5))
            store.append(j**(1/5))
            flag = True
            break
        elif -i + j == x:
            store.append(i**(1/5))
            store.append(j**(1/5))
            flag = True
            break
        elif i + j == x:
            store.append(i**(1/5))
            store.append(j**(1/5))
            flag = True
            break
    if flag:
        break

x1 = int(store[0])
y1 = int(store[1])

if (-x1)**5 - y1**5 ==x:
    x1 = x1
    y1 = y1
elif x1**5 - (-y1)**5 ==x:
    x1 = x1
    y1 = -y1
elif (-x1)**5 - (-y1)**5 ==x:
    x1 = -x1
    y1 = -y1
    
print(str(x1) + " " +str(y1) )

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

int main() {
	int q;
	std::cin >> q;
	std::vector<int> vec;
	for (auto i = 0; i < q; ++i) {
		int t;
		std::cin >> t;
		switch (t) {
		case 0:
			std::cin >> t;
			vec.push_back(t);
			break;
		case 1:
			std::cin >> t;
			std::cout << vec[t] << "\n";
			break;
		default:
			vec.pop_back();
		}
	}
}


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

bool test(int a) {
  return a > 0 && a <= 12;
}

int main()
{
  int S;
  cin >> S;
  int f = S / 100;
  int b = S % 100;
  if (test(f) && test(b)) {
    cout << "AMBIGUOUS";
  } else if (test(f) && !test(b)) {
    cout << "MMYY";
  } else if (!test(f) && test(b)) {
    cout << "YYMM";
  } else if (!test(f) && !test(b)) {
    cout << "NA";
  }
  cout << endl;
  return 0;
}


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

int main() {
    char b;
    cin >> b;
    if (b == 'A') cout << 'T' << endl;
    if (b == 'T') cout << 'A' << endl;
    if (b == 'C') cout << 'G' << endl;
    if (b == 'G') cout << 'C' << endl;
}

Measured memory_bytes: 256
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c<=32)c=_buff.get();return c;}
ll qpow(ll x,ll k){return k==0?1:1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
int n,a[1011];
vector<int> v;
void print(int l,int r)
{
	if(l>r)return;
	if(l==r)
	{
		v.PB(l);
	}
	else if(l%2==r%2)
	{
		v.PB(r-1);
		print(l,r-2);
	}
	else if(l==1)v.PB(1),print(1,r-1);
	else if(r==n)v.PB(n),print(l,r-1);
	else assert(false);
}
ll solve(bool f,bool o)
{
	ll ret=0;
	int mx=a[1];
	for(int i=1;i<=n;i++)
	{
		mx=max(mx,a[i]);
		if(i%2==f)
		{
			ret+=max(0,a[i]);
		}
	}
	
	if(!o)return mx<=0?mx:ret;
	else
	{
		int pre=n;
		if(mx<=0)
		{
			for(int i=n;i>=1;i--)
			{
				if(a[i]==mx)
				{
					print(i+1,n);
					print(1,i-1);
					break;
				}
			}
		}
		else
		{
			for(int i=n;i>=1;i--)
			{
				if(i%2==f&&a[i]>0)
				{
					print(i+1,pre);
					pre=i-1;
				}
			}
			print(1,pre);
		}
		cout<<(mx<=0?mx:ret)<<endl;
		cout<<v.size()<<endl;
		for(int i=0;i<v.size();i++)cout<<v[i]<<endl;
	}
}

int main()
{
	geti(n);
	for(int i=1;i<=n;i++)geti(a[i]);
	ll ans0=solve(0,0);
	ll ans1=solve(1,0);
	if(ans0>ans1)solve(0,1);
	else solve(1,1);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
typedef long long ll;
using namespace std;
const ll mod =1e9 + 7; 
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m;
int s,flag,fr,en;
char ch[200005],a[600005],c[2];
int main(){
	int i,j,op,x;
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    scanf("%s",ch+1);
	n=strlen(ch+1),s=read();
    for(i=s+1;i<=s+n;i++) a[i]=ch[i-s];
    fr=s+1,en=s+n;
    for(i=1;i<=s;i++){
    	op=read();
    	if(op==1) flag^=1;
    	else{
    		x=read()-1;
    		if((x^flag)==1) scanf("%s",c),a[++en]=c[0];
    		else scanf("%s",c),a[--fr]=c[0];
    	}
    }
    if(!flag) for(i=fr;i<=en;i++) printf("%c",a[i]);
    else for(i=en;i>=fr;i--) printf("%c",a[i]);
}

Measured memory_bytes: 896
#include <cstdio>  
#include <algorithm>  
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
#define maxn (int)1e5+500
int a[5][5];
int main()
{
	while (~scanf("%d%d%d", &a[0][0],&a[0][1],&a[0][2]))
	{
		for (int i = 1; i < 3; i++)
			scanf("%d%d%d", &a[i][0], &a[i][1], &a[i][2]);
		int key = 1,s;

		s = a[1][0] - a[0][0];
		if (s != a[1][1] - a[0][1] || s != a[1][2] - a[0][2])
			key = 0;
		s = a[2][0] - a[1][0];
		if (s != a[2][1] - a[1][1] || s != a[2][2] - a[1][2])
			key = 0;
		s = a[2][0] - a[0][0];
		if (s != a[2][1] - a[0][1] || s != a[2][2] - a[0][2])
			key = 0;

		s = a[0][0] - a[0][1];
		if (s != a[1][0] - a[1][1] || s != a[2][0] - a[2][1])
			key = 0;
		s = a[0][0] - a[0][2];
		if (s != a[1][0] - a[1][2] || s != a[2][0] - a[2][2])
			key = 0;
		s = a[0][1] - a[0][2];
		if (s != a[1][1] - a[1][2] || s != a[2][1] - a[2][2])
			key = 0;

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

Measured memory_bytes: 256