akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;

typedef long long ll;

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<ll> lv(n);
  for (int i = 0; i < n; ++i) {
    cin >> lv[i];
  }
  sort(lv.begin(), lv.end(), greater<ll>());


  // nCrの事前計算
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (i == j || j == 0) {
        choose[i][j] = 1;
        continue;
      }
      if (i > 0) choose[i][j] += choose[i-1][j];
      if (j > 0) choose[i][j] += choose[i-1][j-1];
    }
  }
  ll sum = 0;
  ll last = -1;
  int count = 0;
  int start = -1;
  for (int i = 0; i < n; ++i) {
    ll v = lv[i];
    if (v != last) {
      if (i >= a) break;
      count = 0;
      start = i;
    }
    ++count;
    last = v;
    if (i < a) {
      sum += last;
    }
  }
  double ans_avg = (double) sum / (double)a;
  printf("%f\n", ans_avg);

  // cout << count << " " << start << " " << last << endl;
  ll ans = 0;
  for (int i = 0; i < min(count, b-a+1); ++i) {
    if (start > 0 && i > 0) break;
    if (a-start+i > count) break;
    ll c = choose[count][a-start+i];
    // cout << i << " " << count << " " << a-start+i << " " << c << endl;
    ans += c;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  int a, b;
  cin >> a >> b;
  int tmp = (a+b)/2;
  if ((a+b) % 2 == 0) {
    cout << tmp << endl;
  } else {
    cout <<"IMPOSSIBLE" << endl;
  }
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main() {
    
    ll n;
    cin >> n;
    ll a, b;
    for (int i = (int)sqrt(n) + 1; i >= 1; i--) {
        if (n % i == 0) {
            a = i;
            b = n / i;
            break;
        }
    }
    
    string sa = to_string(a);
    string sb = to_string(b);
    ll ans;
    
    if (sa.size() > sb.size()) {
        ans = sa.size();
    } else {
        ans = sb.size();
    }
    cout << ans << endl;
    
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        Scanner scanner = new Scanner(System.in);

        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int D = scanner.nextInt();

        //Not merged case
        if (B <= C || D <= A) {
            System.out.print(0);
            return;
        }

        //One range is in the other range
        if (A <= C && D <= B) {
            System.out.print(D - C);
            return;
        }
        if (C <= A && B <= D) {
            System.out.print(B - A);
        }

        //Merged two range
        if (A < C && B < D) {
            System.out.print(B - C);
            return;
        }

        if (C < A && D < B){
            System.out.print(D - A);
        }
    }
}

Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#define For(i,a,b) for(int i=(a);i<(b);i++)
#define Rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	Rep(i, N) {
		cin >> a[i];
		a[i] %= 2;
	}
	sort(a.begin(), a.end());
	int n = upper_bound(a.begin(), a.end(), 0) - a.begin();
	if ((N - n) % 2 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
struct UnionFind {
    vector<int> par, siz;
    UnionFind(int n) {
        par.resize(n);
        siz.resize(n, 1);
        for (int i = 0; i < n; i++)
            par[i] = i;
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    bool unite(int u, int v) {
        u = find(u), v = find(v);
        if (u == v)
            return false;
        if (siz[u] < siz[v])
            swap(u, v);
        par[v] = u;
        siz[u] += siz[v];
        return true;
    }
    bool same(int u, int v) { return find(u) == find(v); }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1);
    map<int, int> mp1, mp2;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[n] ^= a[i];
        mp1[a[i]]++;
    }
    mp1[a[n]]++;
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        b[n] ^= b[i];
        mp2[b[i]]++;
    }
    mp2[b[n]]++;
    int id = 0;
    for (auto it = mp1.begin(); it != mp1.end(); it++) {
        if (it->second != mp2[it->first]) {
            cout << -1 << endl;
            return 0;
        }
        it->second = id;
        id++;
    }
    UnionFind uf(id);
    int res = 0;
    for (int i = 0; i <= n; i++) {
        if (a[i] != b[i]) {
            res++;
            uf.unite(mp1[a[i]], mp1[b[i]]);
        }
    }
    map<int, int> mp;
    for (int i = 0; i < id; i++) {
        mp[uf.find(i)]++;
    }
    for (auto it = mp.begin(); it != mp.end(); it++) {
        if (it->second > 1 && !uf.same(it->first, mp1[a[n]])) {
            res++;
        }
    }
    if (a[n] != b[n]) {
        res--;
    }
    cout << res << endl;
}

Measured memory_bytes: 15872
#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(){
	int n;
	ll c,k;
	cin >> n >> c >> k;
	vector<ll> t(n);
	rep(i,n) cin >> t[i];
	sort(t.begin(),t.end());
	ll bus = 1;
	ll time = 0;
	ll kazu = 0;
	ll s = t[0];
	int i = 0;
	while(i < n){
		if(t[i]-s>k||kazu>=c){
			bus++;
			s=t[i];
			kazu = 1;
			i++;
		}
		else{
			kazu++;
			i++;
		}
	}
	cout << bus << endl;
}

Measured memory_bytes: 3968
#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 rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define ld double
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
#define ps(x,y) fixed<<setprecision(y)<<x
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
    return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
    out << "[";
    for (auto it = a.begin(); it != a.end(); ++it) {
        if (it != a.begin())
            out << ", ";
        out << *it;
    }
    return out << "]";
}
const int N=301;
ld dp[N][N][N];
int main()
{
    boost;
    ll n,i,j,x,t,y,z,k;
    cin>>n;
    x=y=z=0;
    for(i=0;i<n;i++){
        cin>>t;
        if(t==1) x++;
        else if(t==2) y++;
        else z++;
    }
    dp[0][0][0]=0;
    for(k=0;k<N;k++){
        for(j=0;j<N;j++){
            for(i=0;i<N;i++){
                if(i+j+k > n || i+j+k == 0) continue;
                ld a, b, c;
                a = 1.0*i/(i+j+k);
                b = 1.0*j/(i+j+k);
                c = 1.0*k/(i+j+k);
                if(i>0) dp[i][j][k]+=a*dp[i-1][j][k];
                if(j>0) dp[i][j][k]+=b*dp[i+1][j-1][k];
                if(k>0) dp[i][j][k]+=c*dp[i][j+1][k-1];
                dp[i][j][k]+=1.0*n/(i+j+k);
            }
        }
    }
    cout<<ps(dp[x][y][z],10);
}


Measured memory_bytes: 213248
#include <bits/stdc++.h>
using namespace std;
 
using ll = int64_t;
constexpr ll mod = ll(1e9 + 7);
 
int main () {
  ios::sync_with_stdio(0); cin.tie(0);
 
  int TT = 1;
  // cin >> TT;
  while (TT--) {
    ll N;
    cin >> N;
    for (ll n = 1; n <= N; ++n) {
      ll ans = 0;
      for (ll x = 1; x*x <= n; ++x) {
        for (ll y = 1; x*x + y*y + x*y <= n; ++y) {
          for (ll z = 1; x*x + y*y + z*z + x*y + y*z + z*x <= n; ++z) {
            if (x*x+y*y+z*z + x*y + y*z + z*x == n) {
//              cout << x << " " << y << " " << z << endl;
              ++ans;
            }
          }
        }
      }
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 3656
import Control.Monad
import Control.Applicative

solve :: [Int] -> String
solve [-1, _, _] = "F"
solve [_, -1, _] = "F"
solve [a, b, c]
    | 80 <= (a+b) = "A"
    | 65 <= (a+b) = "B"
    | 50 <= (a+b) = "C"
    | 30 <= (a+b) && 50 <= c = "C"
    | 30 <= (a+b) = "D"
    | otherwise = "F"

main =
    mapM_ putStrLn =<< map solve . takeInputs . lines <$> getContents
    where
    takeInputs :: [String] -> [[Int]]
    takeInputs = takeWhile (not . all (== -1)) . map (map read . words) 


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

int main(){
    int i,j;
    int n,k;
    while(1){
        cin>>n>>k;
        if(n==0) break;
        VI v(n+2,0);
        v[n+1]=-100;
        for(i=0;i<k;i++){
            int x;
            cin>>x;
            v[x]=1;
        }
        int ans=0;
        int r=0;
        int ng=0;
        while(ng<=v[0]){
            r++;
            ng+=(1-v[r]);
        }
        int l=1;
        //cout<<l<<" "<<r<<endl;
        ans=max(ans,r-l);
        for(int l=2;l<=n;l++){
            ng-=1-v[l-1];
            while(ng<=v[0]){
                r++;
                ng+=(1-v[r]);
            }
            ans=max(ans,r-l);
            //cout<<l<<" "<<r<<endl;
        }
        cout<<min(n,ans)<<endl;
    }


}


Measured memory_bytes: 3548
import java.util.Scanner;
class Main{
  public static void main(String[] arg){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int q = sc.nextInt();
    int[] c = new int[n];
    for(int i = 0; i < q; i++){
      c[sc.nextInt() - 1]++;
    }
    int a = q - k;
    for(int i = 0; i < n; i++){
      if(c[i] > a){
        System.out.println("Yes");
      }else{
      System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 56256
program ABC163D
    implicit none
    integer(8)::N,K,ans,m,i
    read*,N,K
    m=10**9+7
    ans=0
    do i=K,N+1
        ans=ans+-1*i**2+(N+1)*i+1
        ans=mod(ans,m)
    end do

    print'(i0)',ans
end program ABC163D

Measured memory_bytes: 2920
var n,sum,i,p:longint; 
    f:array[1..5] of longint;
    s:string;
begin
	readln(n);
	str(n,s);
	sum:=0;
	f[1]:=9; f[2]:=0; f[3]:=900; f[4]:=0; f[5]:=90000;
	for i:=1 to length(s) - 1 do sum:=sum + f[i];
	if length(s) mod 2 = 1 then 
	  begin    
      p:=1;
      for i:=1 to length(s) - 1 do p:=p * 10;
      sum:= sum + n - p + 1;
	  end;
	writeln(sum);
end.

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

struct med{
	int time;
	int value;
	double rate;
}f[11];

int cmp(med a,med b){
	return a.rate>b.rate;
}

int main(){
	/*
	int i,T,N,value=0;
	scanf("%d%d",&T,&N);
	for(i=0;i<N;i++){
		scanf("%d%d",&f[i].time,&f[i].value);
		f[i].rate=f[i].value/f[i].time;
	}
	sort(f,f+N,cmp);
	i=0;
	while(i<N){
		if((T-f[i].time)>=0){
			value += f[i].value;
			T -= f[i].time;
		}
		i++;
	}
	printf("%d",value);
	*/
	
	//test3//
	int N,i,count,flag;
	scanf("%d",&N);
	int a[N];
	for(i=0;i<N;i++){
		scanf("%d",&a[i]);
	}
	sort(a,a+N);
	count = 0;
	for(i=0;i<N;i++){
		flag=1;
		while(a[i]==a[i+1]){
			flag++;
			i++;
		}
		if(flag%2==1){
			count++;
		}
	}
	printf("%d",count);
	//test3//
	
	return 0;
} 

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

int main() {
  int x;
  cin >> x;
  if(x==2){
    cout << 2;
    return 0;
  }
  for (int n = x;; n++) {
    if (n % 2 == 0)
      continue;
    bool flg = false;
    for (int j = 3; j * j <= n; j += 2) {
      if (n % j == 0){
        flg = true;
        break;
      }
    }
    if(flg){
      continue;
    }
    cout << n;
    break;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int n;
double dp[305][305][305];

double rec(int c1, int c2, int c3) {
	if (dp[c1][c2][c3] >= 0) return dp[c1][c2][c3];
	if (!c1 && !c2 && !c3) return 0.0;
	
	double res = 0.0;
	res += (double) n / (c1 + c2 + c3);
	if (c1 > 0) res += rec(c1-1, c2, c3) * c1 / (c1 + c2 + c3);
	if (c2 > 0) res += rec(c1+1, c2-1, c3) * c2 / (c1 + c2 + c3);
	if (c3 > 0) res += rec(c1, c2+1, c3-1) * c3 / (c1 + c2 + c3);
	return dp[c1][c2][c3] = res;
}

int main() {
	cin >> n;
	vector<int> cnt(3, 0);
	rep (i, n) {
		int a;
		cin >> a;
		cnt[a - 1]++;
	}

	memset(dp, -1, sizeof(dp));

	rec(cnt[0], cnt[1], cnt[2]);

	printd(dp[cnt[0]][cnt[1]][cnt[2]]);
  return 0;
}

Measured memory_bytes: 222080
#include <bits/stdc++.h>
using namespace std;
    
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i, n) for (int i = 0; i < n; i++)
#define repn(i, a, b) for (int i = a;i<=b;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define mem(x) memset(x, 0, sizeof(x))
#define ritr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define pai pair < int, int> 
#define pal pair < ll, ll> 
#define vi vector <int> 
#define vl vector < ll > 
#define vpai vector < pii > 

const int mod = 1e9+7;
const int INF = INT_MAX;
const int sze = 3005;

void solve() {
    int n,k;
    cin>>n>>k;
    ll arr[n];
    rep(i,n) cin>>arr[i];
    ll ans=1;
    int l=0,r=n-1,f=0;
    sort(arr,arr+n);
    if(k&1){
        ans=(ans*arr[r])%mod;
        r--;
        if(ans<0) f=1;
        k--;
    }
    while(k){
        ll left=arr[l]*arr[l+1];
        ll right=arr[r]*arr[r-1];
        if(f){
            ans=(ans*(right%mod))%mod;
            r-=2;
        }else{
            if(right>=left){
                ans=(ans*(right%mod))%mod;
                r-=2;
            }else{
                ans=(ans*(left%mod))%mod;
                l+=2;
            }
        }
        k-=2;
    }
    cout<<(ans+mod)%mod<<endl;
}

int main() {
    IOS;

    int t = 1;
    // cin >> t;
    while (t--) {
       solve();
    }

  return 0;
}

Measured memory_bytes: 5224
#include <stdio.h>  
int main(void)
{
	int a, b, c, d, x;
	scanf("%d", &x);
    a = x/1000;
    b = (x/100)%10;
    c = (x/10)%10;
    d = x%10;
    if(a+b+c+d == 7)printf("%d+%d+%d+%d=7", a, b, c, d);
    else if(a+b+c-d == 7)printf("%d+%d+%d-%d=7", a, b, c, d);
    else if(a+b-c+d == 7)printf("%d+%d-%d+%d=7", a, b, c, d);
    else if(a+b-c-d == 7)printf("%d+%d-%d-%d=7", a, b, c, d);
    else if(a-b+c+d == 7)printf("%d-%d+%d+%d=7", a, b, c, d);
    else if(a-b+c-d == 7)printf("%d-%d+%d-%d=7", a, b, c, d);
    else if(a-b-c+d == 7)printf("%d-%d-%d+%d=7", a, b, c, d);
    else if(a-b-c-d == 7)printf("%d-%d-%d-%d=7", a, b, c, d);
    printf("\n");
    return 0;
}

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

int compare(const void *a,const void *b){
	return *(int*)a - *(int*)b;
}

int main(){
	int N;
	scanf("%d",&N);
	
	long long int a[N];
	long long int b,ans=0,tmp;
	int i;
	for(i=0;i<N;i++){
		scanf("%lld",&a[i]);
		a[i]-=(i+1);
	}
	
	qsort(a,N,sizeof(long long int),compare);
	
	b=a[N/2];
	
	for(i=0;i<N;i++){
		tmp=a[i]-b;
		if(tmp<0) tmp=-tmp;
		ans+=tmp;
	}
	
	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n; cin>>n;
    int ans=0;
    for(int i=2; i<=n; ++i){
        int a=i*i;
        while(a<=n){
            ans=max(ans, a);
            a*=i;
        }
    }
    if(n==1) ans=1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3580
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
int main(){
	int n;
	while (~S(d, n), n)
	{
		int dp[3001] = { 1 };
		int i = 0;
		for (; i < n; i++)
		{
			int a, b;
			fscanf(stdin, "%d%d", &a, &b);
			int j=1001;
			for (; j >= 0; j--)
			{
				int k = 1;
				for (; k <= b; k++) dp[j + a*k] += dp[j];
			}
		}
		int m;
		S(d, m);
		while (m--) S(d, i), P(d, dp[i]);
	}
	return 0;
}

Measured memory_bytes: 624
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#define INFTY 1000000000
using namespace std;
bool list[100][100];
int ti[100];
int n;

void bfs(int now){
	queue<int> next;
	next.push(now);
	while(next.size()!=0){
		now=next.front();	next.pop();
		for(int i=0;i<n;i++){
			if(list[now][i]&&ti[i]==INFTY){
				ti[i]=ti[now]+1;
				next.push(i);
			}
		}
	}
}

int main(){
	for(int i=0;i<100;i++){
		for(int j=0;j<100;j++)	list[i][j]=false;
		ti[i]=INFTY;
	}
	cin>>n;
	int id,num,ne;
	for(int i=0;i<n;i++){
		cin>>id>>num;
		id--;
		for(int j=0;j<num;j++){
			cin>>ne;
			list[id][ne-1]=true;
		}
	}
	ti[0]=0;	bfs(0);
	for(int i=0;i<n;i++){
		cout<<i+1<<" "<<((ti[i]==INFTY)?(-1):ti[i])<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
// Problem : C - Divide the Problems
// Contest : AtCoder - AtCoder Beginner Contest 132
// URL : https://atcoder.jp/contests/abc132/tasks/abc132_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vlli vector<int>
#define slli set<int>
#define mlli map<int,int>
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fint fast;test
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;

void solve(){
	int n;
	cin>>n;
	int arr[n];
	FOR(i,n)cin>>arr[i];
	sort(arr,arr+n);
	int M=arr[n/2];
	int m=arr[(n/2)-1];
	cout<<M-m;	
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
using namespace std;
#define ll long long  int
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)


using namespace std;
int main() 
{
    string arr,brr;
    ll i,j;
    cin>>arr>>brr;
    ll l1,l2;
    l1=arr.length();
    l2=brr.length();
    ll dp[l1+1][l2+1];
    for(i=0;i<=l1;i++)
    {
    	for(j=0;j<=l2;j++)
    	{
    		if(i==0||j==0)
    			dp[i][j]=0;
    		else if(arr[i-1]==brr[j-1])
    			dp[i][j]=dp[i-1][j-1]+1;
    		else
    			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    	}
    }
    i=l1;
    j=l2;
    string ans;
    while(i>0&&j>0)
    {
         if(dp[i][j]==dp[i-1][j-1]+1&&dp[i][j]==dp[i-1][j]+1&&dp[i][j]==dp[i][j-1]+1)
         {
         	ans+=arr[i-1];
         	i--;
         	j--;
         }
         else if(dp[i][j-1]>dp[i-1][j])
         	j--;
         else
         	i--;
    }
    for(i=0;i<ans.length()/2;i++)
         swap(ans[i],ans[ans.length()-1-i]);
    cout<<ans;
    return 0;
}

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

signed main(){
  
  int n;
  cin>>n;
  
  int ans = 0;

  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    ans^=a;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007 
#define pb push_back
//#define mp make_pair
#define INF 2000000011LL
#define INFLL 1000000000000000011LL
#define eps 1e-9
#define pp pair < pair<ll,ll> , ll> 
#define fo(i,j,k) for(int i=j;i<=k;i++)
#define foll(i,j,k) for(ll i=j;i<=k;i++)
#define clr(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vll vector<ll>
#define sz(a) a.size()
#define len(a) a.length()
#define all(a) a.begin(),a.end()
#define io_file freopen("Contest/input_file.in", "r", stdin); freopen("Contest/output_file.in", "w", stdout)

const int MAXN = 2e5+5;
using namespace std;
ll power(ll x, ll y)
{
  ll res = 1;
  while(y>0)
  {
    if(y&1)
       {
         res = (res*x)%mod;
        }
     x = (x*x)%mod;
     y = y>>1;
  }
    return res;
}
// std::vector<ll> divi[100004];
// void divisor(int n)
// {
//    for(ll i=1;i<=n;i++)
//    {
//      for(ll j=i;j<=n;j+=i)
//      {
//        divi[j].pb(i);
//      }
//    }
// }



int cnt[26];

vector<int>dp[51][51];
ll cost[51][51];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    int len = to_string(n).length();
    string s = to_string(n);
    ll ans = 9*(len-1);
    string sx = string(len-1,'9');
    
    for(int i=0;i<=s[0]-'0';i++)
    {
      char c = i + '0';
      if(stoll(string(1,c) + sx) <= stoll(s) )
      {
        ans = i + 9*(len-1); 
      }
    }
    cout<<ans<<endl;
    return 0;

}



Measured memory_bytes: 384
#include <cstdio>
#include <vector>
#include <cmath>
#include <stack>
#include <cassert>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
using namespace std;

/**
 * @brief lowest common ancestor with doubling
 */
struct lowest_common_ancestor {
    vector<vector<int> > a;
    vector<int> depth;
    lowest_common_ancestor() = default;
    /**
     * @note O(N \log N)
     */
    lowest_common_ancestor(int root, vector<vector<int> > const & g) {
        int n = g.size();
        int log_n = 1 + floor(log2(n));
        a.resize(log_n, vector<int>(n, -1));
        depth.resize(n, -1);
        {
            auto & parent = a[0];
            stack<int> stk;
            depth[root] = 0;
            parent[root] = -1;
            stk.push(root);
            while (not stk.empty()) {
                int x = stk.top(); stk.pop();
                for (int y : g[x]) if (depth[y] == -1) {
                    depth[y] = depth[x] + 1;
                    parent[y] = x;
                    stk.push(y);
                }
            }
        }
        repeat (k, log_n-1) {
            repeat (i, n) {
                if (a[k][i] != -1) {
                    a[k+1][i] = a[k][a[k][i]];
                }
            }
        }
    }
    /**
     * @brief find the LCA of x and y
     * @note O(log N)
     */
    int operator () (int x, int y) const {
        int log_n = a.size();
        if (depth[x] < depth[y]) swap(x,y);
        repeat_reverse (k, log_n) {
            if (a[k][x] != -1 and depth[a[k][x]] >= depth[y]) {
                x = a[k][x];
            }
        }
        assert (depth[x] == depth[y]);
        assert (x != -1);
        if (x == y) return x;
        repeat_reverse (k, log_n) {
            if (a[k][x] != a[k][y]) {
                x = a[k][x];
                y = a[k][y];
            }
        }
        assert (x != y);
        assert (a[0][x] == a[0][y]);
        return a[0][x];
    }
    /**
     * @brief find the descendant of x for y
     */
    int descendant (int x, int y) const {
        assert (depth[x] < depth[y]);
        int log_n = a.size();
        repeat_reverse (k, log_n) {
            if (a[k][y] != -1 and depth[a[k][y]] >= depth[x]+1) {
                y = a[k][y];
            }
        }
        assert (a[0][y] == x);
        return y;
    }
};

int main() {
    int n; scanf("%d", &n);
    vector<vector<int> > g(n);
    repeat (i, n) {
        int edges; scanf("%d", &edges);
        while (edges --) {
            int j; scanf("%d", &j);
            g[i].push_back(j);
            g[j].push_back(i);
        }
    }
    constexpr int root = 0;
    lowest_common_ancestor lca(root, g);
    int query; scanf("%d", &query);
    while (query --) {
        int x, y; scanf("%d%d", &x, &y);
        printf("%d\n", lca(x, y));
    }
    return 0;
}

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

int main() {
	int A, B;
	cin >>A >>B;
	string S;
	cin >>S;
	for (int i=0; i<S.size(); i++) {
		if (A==i) {
			if ('-'!=S.at(i)) {
				cout <<"No" <<endl;
				return 0;
			}
		} else if ('-'==S.at(i)) {
			cout <<"No" <<endl;
			return 0;
		}
	}
	cout <<"Yes" <<endl;
	return 0;
}



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

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

int main(void){
  int n,k,a[200005],count[200005]={0},l=0,j,ans=0;
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    count[a[i]]++;
  }
  qsort(count, n+1, sizeof(int),cmp);
  for(int i=n;i>=0;i--){
    if(count[i]>0){
      l++;
      j=i;
    }
  }
  for(int i=j;i<=j+l-k-1;i++){
    ans+=count[i];
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 3892
count = [0 for _ in range(26)]

while True:
    try:
        s = input()
    except:
        break
    for i in range(len(s)):
        m = ord(s[i]) - ord('A')
        if m >= 0 and m < 26:
            count[m] += 1
        m = ord(s[i]) - ord('a')
        if m >= 0 and m < 26:
            count[m] += 1

for i in range(26):
    print(chr(i + ord('a')),":",count[i])
    


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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    if(n<=599){
        cout << 8 << endl;
        return 0;
    }else if(n<= 799){
        cout << 7 << endl;
        return 0;
    }else if(n<= 999){
        cout << 6 << endl;
        return 0;
    }else if(n<= 1199){
        cout << 5 << endl;
        return 0;
    }else if(n<= 1399){
        cout << 4 << endl;
        return 0;
    } else if(n<= 1599){
        cout << 3 << endl;
        return 0;
    } else if(n<= 1799){
        cout << 2 << endl;
        return 0;
    } else{
        cout << 1 << endl;
        return 0;
    } 
}

Measured memory_bytes: 3628
a,b,c,x,y=[int(i) for i in input().split()]

#直接買ったほうが安いとき

if a+b<c*2:
    print(a*x+b*y)
    
#AピザよりもABピザ２枚のほうが安い
elif a+b>=c*2:
    if x-y>0 and a<=2*c:
        print(2*c*y+(x-y)*a)
    elif y-x>0 and b<=2*c:
        print(2*c*x+(y-x)*b)
    elif x-y>0:
        print(x*2*c)
    else:
        print(y*2*c)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define sc second
#define mod 1000000007
using namespace std;
ll n, v[400001], a, b, c, d;
string s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b>>c>>d;
    bool turn=1;
    while(a>0 && c>0)
    {
        if(turn==1)
            c-=b;
        else
            a-=d;
        turn=!turn;
    }
    if(c<=0)
        return cout<<"Yes", 0;
    else if(a<=0)
        return cout<<"No", 0;
    return 0;
}


Measured memory_bytes: 3652
import java.util.*;

class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        
       int cash = 1000;
       int count = 1;
        while (cash * count < n) {
            count++;
        }
        
        int payment = cash * count - n;
        System.out.println(payment);
    }
}
            

Measured memory_bytes: 35828
#include<stdio.h>

static const int N = 1000;

void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(){
  int n, i, j, key;
  int A[N+1];
  scanf("%d", &n);

  for ( i = 1; i <= n; i++ ) scanf("%d", &A[i]);
  
  for ( i = 1; i <= n; i++ ) {
    key = A[i];
    j = i - 1;
    while (j > 0 && A[j] > key) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    trace(A, n);
  }
  return 0;
}



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

using namespace std;

using ll = long long;

string s, t;
vector<vector<int>> memo;

// s[i, ), t[j, ) の共通部分列で最大のサイズを求める
int Solve(size_t i, size_t j) {
    if (s.size() <= i || t.size() <= j) return memo[i][j] = 0;
    if (memo[i][j] != -1) return memo[i][j];

    int res = 0;
    if (s[i] == t[j]) res = 1 + Solve(i + 1, j + 1);
    else res = max(Solve(i + 1, j), Solve(i, j + 1));

    return memo[i][j] = res;
}

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

    cin >> s >> t;
    memo.resize(s.size() + 1, vector<int>(t.size() + 1, -1));

    Solve(0, 0);
    string ans;
    for (size_t i = 0, j = 0; i < s.size() && j < t.size(); ) {
        if (s[i] == t[j]) { ans += s[i]; ++i; ++j; }
        else if (memo[i + 1][j] < memo[i][j + 1]) ++j;
        else ++i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 37120
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <algorithm>

#define int_inf 1000000000
#define ll_inf	100000000000000000000000

using namespace std;
bool operator <(vector<int> &v1, vector<int> &v2){
	for(int i=0; i<v1.size(); i++){
		if(v1[i]<v2[i]) return true;
		if(v1[i]>v2[i]) return false;
	}
}


int n;
vector<int> a;

set<vector<int> > s;

void find(vector<int> v, int done){
	if(done==n-1){
		//sort(v.begin(), v.end());
		for(int i=0; i<n; i++){
			if(v[i]%2==0) break;
			else if(i==n-1) return;
		}
		/*for(int i=0; i<n; i++) cout<<v[i]<<" ";
		cout<<endl;*/
		s.insert(v);
	}
	else{
		v[done+1]=a[done+1]-1;
		find(v, done+1);
		v[done+1]=a[done+1];
		find(v, done+1);
		v[done+1]=a[done+1]+1;
		find(v, done+1);
	}
}
long long pow(int a){
	if(a==1) return 3;
	else return 3*pow(a-1);
}
int main(){
	cin >> n;
	a.resize(n);
	for(int i=0; i<n; i++) cin >> a[i];
	vector<int> v;
	v.resize(n);
	find(v, -1);
	
	cout << s.size() << endl;
	return 0;
}	


Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  long long a, b, k;
  
  cin >> a >> b >> k;
  
  if(k >= a){
    k -= a;
    a = 0;
  }
  else{
    a -= k;
    k = 0;
  }
  
  b -= k;
  
  if(b < 0)
    b = 0;
  
  cout << a << ' ' << b << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

struct dinitz_t {
  int n, source, sink; vector<vector<int>> adj;
  struct edge { int u; lint flow, cap; }; vector<edge> edges;
  dinitz_t(int _n, int _source, int _sink)
    : n(_n), source(_source), sink(_sink), adj(n) {}
  int add_edge(int a, int b, lint abcap, lint bacap = 0) {
    int result = edges.size();
    adj[a].push_back(edges.size());edges.push_back({b, 0LL, abcap});
    adj[b].push_back(edges.size());edges.push_back({a, 0LL, bacap});
    return result;
  }
  vector<int> mindist, position;
  bool bfs() {
    queue<int> q;
    fill(mindist.begin(), mindist.end(), INT_MAX/2);
    mindist[source] = 0; q.push(source);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      for (int edid : adj[v]) { edge &ed = edges[edid];
	if (ed.flow < ed.cap && mindist[ed.u] > mindist[v] + 1) {
	  mindist[ed.u] = mindist[v] + 1; q.push(ed.u);
	}
      }
    }
    return mindist[sink] < n;
  }
  lint dfs(int v, lint maxf) {
    if (v == sink) return maxf;
    for (int &pos = position[v]; pos < (int)adj[v].size(); ++pos) {
      int edid = adj[v][pos];
      edge &ed = edges[edid], &reved = edges[edid^1];
      if (ed.flow < ed.cap && mindist[ed.u] == mindist[v] + 1) {
	lint f = dfs(ed.u, min(maxf, ed.cap - ed.flow));
	if (f > 0) { ed.flow += f; reved.flow -= f; return f; }
      }
    }
    return 0;
  }
  lint maxflow() {
    lint result = 0; mindist.resize(n); position.resize(n);
    while (bfs()) {
      lint extra;
      fill(position.begin(), position.end(), 0);
      do {
        extra = dfs(source, LLONG_MAX); result += extra;
      } while (extra > 0);
    }
    return result;
  }
};

int main() {
  int n;
  scanf("%d", &n);
  vector<int> values(n + 1);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &values[i]);
  dinitz_t maxflow(n + 2, 0, n + 1);
  lint baseline = 0;
  for (int i = 1; i <= n; ++i) {
    if (values[i] < 0) {
      maxflow.add_edge(0, i, -values[i]);
    } else {
      maxflow.add_edge(i, n + 1, values[i]);
      baseline += values[i];
    }
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 2 * i; j <= n; j += i)
      maxflow.add_edge(i, j, LLONG_MAX / 4);
  lint loss = maxflow.maxflow();
  lint result = baseline - loss;
  printf("%lld\n", result);
  return 0;
}


Measured memory_bytes: 256
n=int(input())
p=[]
for i in range(n):
  s=input()
  p.append(s[0])
m=p.count("M")
a=p.count("A")
r=p.count("R")
c=p.count("C")
h=p.count("H")
print(m*a*r+m*a*h+m*a*c+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)

Measured memory_bytes: 3872
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))


def count2(n):
    # 素因数分解したときに2が何個あるか
    ret = 0
    while n & 1 == 0:
        n >>= 1
        ret += 1
    return ret


C = list(map(count2, A))
C.sort()
C = deque(C)

order = []
while C:
    order.append(C.popleft())
    if C:
        order.append(C.pop())
ok = True
for a, b in zip(order[:-1], order[1:]):
    ok &= a + b >= 2
if ok:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 24088
s = list(input())
n = len(s)
mod = 2019

d=[0]*(n+1)
k=1
for i in range(n):
    d[i+1]=d[i]+k*int(s[n-i-1])
    d[i+1]%=mod
    k*=10
    k%=mod

count = [0]*mod
for i in range(n+1):
    count[d[i]] += 1

ans = 0
for i in range(mod):
    c = count[i]
    ans += c*(c-1) // 2

print(ans)


Measured memory_bytes: 17800
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;


signed main()
{
    int a,b;
    cin>>a>>b;
    if(a*b<=0)cout<<"Zero"<<endl;
    else if(a>0 && b>0)cout<<"Positive"<<endl; 
    else{
        if((abs(abs(a)-abs(b))+1)%2==0)cout<<"Positive"<<endl;
        else cout<<"Negative"<<endl;
    }
}


Measured memory_bytes: 256
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}



main(){
    ios
    int n=in();
    vec x,y,t;
    rep(i,n){
        t.pb(in()),x.pb(in()),y.pb(in());
    }
    bool f=1;
    int pre=0,a=0,b=0;
    rep(i,n){
        int T=t[i]-pre;
        int d=abs(a-x[i])+abs(b-y[i]);
        if(((d^T)&1)==1) f=0;
        if(T<d) f=0;
        a=x[i],b=y[i],pre=t[i];
    }
    cout << (f? "Yes":"No") << endl;
}



Measured memory_bytes: 1644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int E, Y;
    cin >> E >> Y;
    if (E == 0) {
        if (Y <= 1911) {
            cout << "M" << Y - 1867 << "\n";
        } else if (Y <= 1925) {
            cout << "T" << Y - 1911 << "\n";
        } else if (Y <= 1988) {
            cout << "S" << Y - 1925 << "\n";
        } else {
            cout << "H" << Y - 1988 << "\n";
        }
    } else if (E == 1) {
        cout << 1867 + Y << "\n";
    } else if (E == 2) {
        cout << 1911 + Y << "\n";
    } else if (E == 3) {
        cout << 1925 + Y << "\n";
    } else {
        cout << 1988 + Y << "\n";
    }
    return 0;
}


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

using namespace std;

#define N 10000

long long a[N + 1];
long long b[N + 1];

int main(){
	long long sum_a, sum_b, x_a, x_b;
	int n, i;

	scanf("%d", &n);

	for (i = 1; i <= n; i++){
		scanf("%lld", a + i);
	}

	for (i = 1; i <= n; i++){
		scanf("%lld", b + i);
	}

	sum_a = sum_b = 0;

	for (i = 1; i <= n; i++){
		sum_a += a[i];
		sum_b += b[i];
	}

	if (sum_b - sum_a >= 0){
		x_a = x_b = sum_b - sum_a;

		for (i = 1; i <= n; i++){
			if (a[i] < b[i]){
				if (a[i] % 2 != b[i] % 2){
					x_b--;
					b[i]++;
				}

				x_a -= (b[i] - a[i]) / 2;
				a[i] = b[i];
			}
			else if (a[i] > b[i]){
				x_b -= (a[i] - b[i]);
				b[i] = a[i];
			}
		}
		
		if (x_a >= 0 and x_b >= 0 and x_b == 2 * x_a){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 384
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

	public void Proc()
	{

        int clockCount = int.Parse(Reader.ReadLine());

        long[] inpt = new long[clockCount];
        for (int i = 0; i < clockCount; i++) {
            inpt[i] = long.Parse(Reader.ReadLine());            
        }

        if(clockCount == 1) {
            Console.WriteLine(inpt[0]);
            return;
        }
        long tmp = inpt[0];
        for (int i = 1; i < clockCount; i++) {
            tmp = GetKoubai(tmp, inpt[i]);
        }
        Console.WriteLine(tmp);
    }


    private long GetKoubai(long num1, long num2) {
        if(num1%num2==0) {
            return num1;
        }
        long kouyaku = GetKouyaku(num1, num2);

        long tmp1 = num1 / kouyaku;
        long tmp2 = num2 / kouyaku;
        return tmp1 * tmp2 * kouyaku;
    }

    private long GetKouyaku(long num1, long num2) {
        if(num1%num2==0) {
            return num2;
        }
        return GetKouyaku(num2, num1 % num2);
    }


    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



5
2
5
10
1000000000000000000
1000000000000000000


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}


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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

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

    sort(red.begin(),red.end());
    sort(blue.begin(),blue.end());

    int count=0;
    for(const auto& b : blue){
        int d=N*2;
        int ri=-1;
        for(int i=0;i<N;i++){
            int x=b.first-red[i].first;
            int y=b.second-red[i].second;
            int m=std::min(x,y);
            if(0<m&&y<d){
                d=y;
                ri=i;
            }
        }
        if(ri>=0){
            red[ri]={N*2,N*2};
            count++;
        }
    }

    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h> 

int main(){
 
  int s[5],i,j,tmp;
  
  scanf("%d %d %d %d %d",&s[0],&s[1],&s[2],&s[3],&s[4]);

    for (i = 0; i < 4; i++) {
        for (j = 4; j > i; j--) {
            if (s[j - 1] < s[j]) {  
                tmp = s[j];        
                s[j] = s[j - 1];
                s[j - 1]= tmp;
            }
        }   
   
    }
   

  printf("%d %d %d %d %d\n",s[0],s[1],s[2],s[3],s[4]);

    return 0;
}

Measured memory_bytes: 596
#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__) << "] "

typedef long long LL;

const int INF = 0x3f3f3f3f;


int main(void) {
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    LL h;
    cin >> h;

    cout << (LL)pow(2, int(log2(h))+1)-1 << endl;

    return 0;
}



Measured memory_bytes: 256
import scala.io.StdIn.{readInt,readLine}

object Main {

  def exchange(a:Array[Int],i:Int,j:Int) = {
    val temp = a(i)
    a(i) = a(j)
    a(j) = temp
  }

  def partition(a:Array[Int],p:Int,r:Int) = {
    val x = a(r)
    var i = (p-1)
    for(j<-p until r) {
      if(a(j) <= x) {
        i+=1
        exchange(a,i,j)
      }
    }
    exchange(a,i+1,r)
    i+1
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    val pivot = partition(a,0,n-1)
    val list = a.zipWithIndex.map{ e =>
      if(e._2==pivot) "["+e._1.toString + "]" else e._1.toString
    }.mkString(" ")
    println(list)
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H + 2, vector<char>(W + 2, '.'));
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      if (S.at(i).at(j) == '#') {
        cout << '#';
      }
      else {
        int k = 0;
        for (int m = -1; m <= 1; m++) {
          for (int n = -1; n <= 1; n++) {
            if (S.at(i + m).at(j + n) == '#') k++;
          }
        }
        cout << k;
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define mp make_pair 
using namespace std;
int rez;
int a,b;
int main(){
    cin >> a;
    while(a>0){
        if(a%10==1) rez++;
        a/=10;
    }
    cout<<rez;
}

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

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

    long res=0, cnt=0;
    string t;
    for(char c: s) {
        if (c=='A') {
            cnt=(t.size()<=1 ? cnt+1 : 1);
            t="A";
        }
        else if (c=='B') {
            if (t=="A") {
                t+=c;
            }
            else {
               cnt=0;
               t="";
            }
        }
        else if (c=='C') {
            if (t=="AB") {
                res+=cnt;
                t="A";
            }
            else {
                cnt=0;
                t="";
            }
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 644