akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<cstdlib>
const int N=2e5+3,K=18;
std::vector<int>g1[N],g2[N];
int n,rt1,rt2,d1[N],d2[N],fa[N][K],ans;
inline int Lca(int u,int v){
	if(d2[u]<d2[v])std::swap(u,v);
	for(int j=K-1;~j;j--)if(d2[fa[u][j]]>=d2[v])
	  u=fa[u][j];
	if(u==v)return u;
	for(int j=K-1;~j;j--)if(fa[u][j]!=fa[v][j])
	  u=fa[u][j],v=fa[v][j];
	return fa[u][0];
}
void Dfs2(int u){
	int v;
	for(int j=1;j<K;j++)fa[u][j]=fa[fa[u][j-1]][j-1];
	for(int i=0;i<g2[u].size();i++)if((v=g2[u][i])!=fa[u][0])
	  d2[v]=d2[u]+1,fa[v][0]=u,Dfs2(v);
}
void Dfs1(int u,int fa){
	int v;
	if(d1[u]>=d2[u])return;
	for(int i=0;i<g1[u].size();i++){
	  v=g1[u][i];
	  if(d2[u]+d2[v]-2*d2[Lca(u,v)]>2)exit(0*puts("-1"));
	}
	ans=std::max(ans,d2[u]);
	for(int i=0;i<g1[u].size();i++)if((v=g1[u][i])!=fa)
	  d1[v]=d1[u]+1,Dfs1(v,u);
}
int main(){
	int u,v;
	scanf("%d%d%d",&n,&rt1,&rt2);
	for(int i=1;i<n;i++)
	  scanf("%d%d",&u,&v),g1[u].push_back(v),g1[v].push_back(u);
	for(int i=1;i<n;i++)scanf("%d%d",&u,&v),g2[u].push_back(v),g2[v].push_back(u);
	Dfs2(rt2);
	Dfs1(rt1,0);
	printf("%d\n",ans*2);
	return 0;
}

Measured memory_bytes: 54244
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] lines = br.readLine().split(" ");
        int a = Integer.parseInt(lines[0]);
        int b = Integer.parseInt(lines[1]);
        System.out.println(a * b + " " + (a + b) * 2);
    }

}

Measured memory_bytes: 24148
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}




int main() {
  int n;
  cin >> n;
  vll a(n);
  REP(i,n) cin >> a[i];
  ll am=a[0];
  ll ans=0;
  REP(i,n) {
    if(a[i]<am) {
      ans+=am-a[i];
    } else {
      am=a[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4824
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}
int gcd(int a, int b) {
	if (a%b == 0)return b;
	else return gcd(b,a%b);
}

signed main(void)
{
	int n, x;
	cin >> n >> x;
	vector<int>p(n);
	rep(i, n) {
		int sub;
		cin >> sub;
		p[i] = abs(x - sub);
	}
	int ans = p[0];
	rep(i, n) {
		ans = gcd(ans, p[i]);
	}
	print(ans);

}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <math.h>
#include <map>
#include <queue>
#include <set>
#include <stack>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<x<<endl
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
typedef long long ll;
using namespace std;
const int MAXN=1e5+50;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
//::iterator it;
int main()
{
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    ll n,k;
    cin>>n>>k;
    n%=k;
    ll ans=min(n,abs(n-k));
    cout<<ans<<endl;
    return 0;
}
/*

*/

 
 

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

int main() {
  int N,v1,v2,v3,v4;
  
  cin >> N;
  
  v1 = N/10;
  v2 = v1/10;
  v3 = v2/10;
  
  if(v1%10==v2%10){
    if(N%10==v1%10 || v2%10==v3%10){
      cout << "Yes" << endl;
    }
    else
      cout << "No" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String ans = "D";
		
		if(a.equals(b)){
		    ans = "H";
		}
		System.out.println(ans);
    }
}


Measured memory_bytes: 35756
using System;
using System.Linq;

class D
{
	static void Main()
	{
		Console.ReadLine();
		var d = Console.ReadLine().Select((c, i) => new { c, i }).ToLookup(_ => _.c, _ => _.i);

		var r = 0;
		foreach (var i1 in d.Select(g => g.First()))
			foreach (var i2 in d.Select(g => g.FirstOrDefault(x => x > i1)).Where(x => x > 0))
				foreach (var g3 in d.Where(g => g.Last() > i2))
					r++;
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
int visited[1000001];
int main()
{
	int n,i=1;
	scanf("%d",&n);
	visited[n]=1;
	while(1)
	{
		if(n%2==0)
			n/=2;
		else
			n=3*n+1;
		i++;
		if(visited[n])
			break;
		visited[n]=1;
	}
	printf("%d",i);
	return 0;
}

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

int main(){
    int H, W;
    while(cin >> H >> W,!(H==0&&W==0)){
        for(int h = 0; h < H; h++){
            for(int w = 0; w < W; w++){
                if(h == 0 || h == H-1){
                    cout << "#";
                }else if(w == 0 || w == W-1){
                    cout << "#";
                }else{
                    cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3104
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include<bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'

const int N = 200005;
int n, a[N], sum;
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1 ; i <= n ; ++ i){
		cin >> a[i];
		sum += abs(a[i] - a[i - 1]);
	}
	sum += abs(a[n]);
	for(int i = 1 ; i <= n ; i ++){
		if(a[i] >= a[i - 1] && a[i] <= a[i + 1]) cout << sum << endl;
		else if(a[i] <= a[i - 1] && a[i] >= a[i + 1]) cout << sum << endl;
		else cout << sum - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]) + abs(a[i - 1] - a[i + 1]) << endl;
	}
}


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

int main() {
    int N;
    string S;
    cin >> N >> S;

    int res = 0;
    for (int i = 0; i <= N - 3; i++) {
        string t = S.substr(i, 3);
        if (t == "ABC") res++;
    }

    cout << res << endl;
    return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int n;

int main() {
	cin >> n;
	
	cout << "AB" << (n < 1000 ? "C" : "D") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 typedef long long ll;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;

 int main() {
     ll N, M;
     cin >> N >> M;
     cout << abs((N - 2) * (M - 2)) << endl;
 }


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;
ll const MAX_N = 510000;
ll const MOD = 1000000007;

ll const MAX_V = 100;

struct edge {
    ll to, cost;
};
vector<edge> G[MAX_V];

ll d[MAX_V];             // 距離計算
typedef pair<ll, ll> P;  // first: 最短距離, second: 頂点番号

void dijkstra(ll s, ll V) {
    // greater<P>を指定することで、firstが小さい順から取り出せる
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d, d + V, INF);

    // 始点をpushする
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        // cout << "----" << endl;
        // for (ll i = 0; i < V; i++) cout << i << ": " << d[i] << ", ";
        // cout << endl;

        priority_queue<P, vector<P>, greater<P>> que_tmp = que;
        while (!que_tmp.empty()) {
            // cout << que_tmp.top().first << ", " << que_tmp.top().second <<
            // endl;
            que_tmp.pop();
        }

        P p = que.top();
        que.pop();

        // 優先度が最も高い頂点の番号を調べる
        ll v = p.second;

        // push時の最短距離から、dが更新されていたら
        // dが確定したとみなし無視
        if (d[v] < p.first) continue;

        for (ll i = 0; i < G[v].size(); i++) {
            edge e = G[v][i];

            // 仮の最短距離と頂点の組をpush
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    ll H, W;
    cin >> H >> W;
    // vector<vector<ll>> c(9, vector<ll>(9, 0));
    vector<vector<ll>> A(H, vector<ll>(W, 0));
    rep(i, 10) {
        rep(j, 10) {
            ll c;
            cin >> c;
            edge et = {j, c};
            G[i].push_back(et);
        }
    }

    rep(i, H) {
        rep(j, W) { cin >> A[i][j]; }
    }

    ll ans = 0;
    rep(i, H) {
        rep(j, W) {
            // cout << "i:" << i << ", j" << j << endl;
            if (A[i][j] == -1) {
                continue;
            }
            dijkstra(A[i][j], 10);
            ans += d[1];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3928
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    int n, k, ans = 1;
    cin >> n >> k;
    repi(i,n,0){
        ans = min(ans * 2,ans + k);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<long long int>
#define vi  vector<int>
#define vpi vector<pair<int,int>>
#define prec fixed<<setprecision(12)
#define set(x) __builtin_popcount(x)
#define ffs(x) __builtin_ffs(x)
#define clz(x) __builtin_clz(x)
#define inf 1000000007
#define linf 1000000000000000007
#define a(v) v.begin(),v.end()
void fast(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
}


int main(){
	fast;
    int n;
    cin >> n;
    cout << prec << 2*(3.141)*n;
    
}


Measured memory_bytes: 3740
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i < n; i++){
        int x;
        cin >> x;
        a[i] = x;
    }
    sort(a.begin(), a.end());
    int p = (a[0] + a[n-1]) / 2;
    while(true){
        int sum = 0;
        for (int j = 0; j < n; j++){
            sum += (p - a[j])*(p - a[j]);
        }
        int lsum = 0;
        for (int j = 0; j < n; j++){
            lsum += ((p-1) - a[j])*((p-1) - a[j]);
        }
        if (lsum < sum){
            p--;
            continue;
        }
        int rsum = 0;
        for (int j = 0; j < n; j++){
            rsum += ((p+1) - a[j])*((p+1) - a[j]);
        }
        if (rsum < sum){
            p++;
            continue;
        }
        cout << sum << endl;
        break;
    }
}


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

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
        prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}


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

    cout << S.substr(0, 3) << endl;



    return 0;    
}



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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    ll N;
    cin >> N;
    auto f = [](ll n){
        ll count = 1;
        while(n>=10){
            ++count;
            n /= 10;
        }
        return count;
    };
    ll total = 0;
    REP(i, 1, N+1){
        if(f(i)%2==1){
            ++total;
        }
    }
    cout << total << endl;
}


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

int main() {
    int N,a[101];
    cin >> N;
    for (int i=0; i<N; i++) cin >> a[i];
    
    sort(a, a + N, greater<int>());
    int Alice = 0;
    int Bob = 0;
    
    for(int i=0; i<N; i++){
        if(i%2==0) Alice += a[i];
        else Bob += a[i];
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
import sys

i,j = input().split()

matrixa = []

for _ in range(int(i)):
    matrixa += [[int(n) for n in sys.stdin.readline().split()]]

matrixb =[ int(num) for num in sys.stdin.readlines() ]

matrixc = [ 0 for _ in range(int(i))]

for n in range(int(i)):
    for a,b in zip(matrixa[n],matrixb):
        matrixc[n] += a*b
for c in matrixc:
    print(c)


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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int num[185];

int main() {
    REP(i, 185) { num[i] = i * i; }
    int n;
    while (cin >> n, n) {
        int cnt = 0;
        FOR(i, 1, 185) {
            int mi = num[i];
            if (mi == n) {
                cnt++;
            } else if (mi > n) {
                break;
            }
            FOR(j, i, 185) {
                int mj = mi + num[j];
                if (mj == n) {
                    cnt++;
                } else if (mj > n) {
                    break;
                }
                FOR(k, j, 185) {
                    int mk = mj + num[k];
                    if (mk == n) {
                        cnt++;
                    } else if (mk > n) {
                        break;
                    }
                    FOR(l, k, 185) {
                        int ml = mk + num[l];
                        if (ml == n) {
                            cnt++;
                        } else if (ml > n) {
                            break;
                        }
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}

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

using namespace std;

const int MAXN = 300 + 10;
const int MOD = 998244353;

int n0, k;
string s;
int n1[MAXN];
int f[MAXN][MAXN][MAXN];

void add(int &a, int b) {
    a = (a + b) % MOD;
}

int main() {
    cin >> s >> k;
    n0 = 0;
    int cnt1 = 0;
    for(int i = 0; i < s.length(); ++i) {
        if (s[i] == '0') {
            n0++; n1[n0] = cnt1; cnt1 = 0;
        }
        else cnt1++;
    }
    n0++; n1[n0] = cnt1;
    
    for(int i = n1[1]; i <= s.length(); ++i) f[1][i - n1[1]][0] = 1;
    for(int i = 2; i <= n0; ++i) {
        for(int paid = 0; paid <= s.length(); ++paid) {
            int x = 0;
            for(int owe = paid; owe <= s.length(); ++owe) {
                add(x, f[i - 1][owe][paid]);
                add(f[i][owe][paid], x);
            }
        }
            
        for(int owe = 0; owe <= s.length(); ++owe)
            for(int paid = 0; paid <= owe; ++paid) {
                if (f[i - 1][owe][paid] == 0) continue;
                
                for(int j = 1; j <= n1[i]; ++j)
                    if (paid + j <= owe)
                        add(f[i][owe][paid + j], f[i - 1][owe][paid]);
            }
    }
    
    int res = 0;
    for(int paid = 0; paid <= min(k, (int)(s.length())); ++paid)
        add(res, f[n0][paid][paid]);
    
    cout << res << "\n";
}

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

int main()
{
	int N, A, B, C, X;
	cin >> N >> A >> B >> C >> X;
	while (N+A+B+C+X!=0) {
		int y[10002];
		for (int i = 1; i <= N; i++) {
			cin >> y[i];
		}
		int i = 1, t=1;
		for (t=0; t <= 10000; t++) {
			if (y[i] == X) {
				i++;
			}
			if (i == N + 1) {
				cout << t << endl; break;
			}
			X = (A*X + B) % C;
		}
		if (t > 10000) {
			cout << -1 << endl;
		}
		cin >> N >> A >> B >> C >> X;
	}
    return 0;
}


Measured memory_bytes: 3080
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();

        String str1 = str.replaceAll("apple","り");
        String str2 = str1.replaceAll("peach","ぴ");

        String str3 = str2.replaceAll("り","peach");
        String str4 = str3.replaceAll("ぴ","apple");

        System.out.println(str4);
    }
}


Measured memory_bytes: 25944
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> pii;
typedef std::pair<long long, long long> pll;

using namespace std;

const long long MOD = 1000000007;

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

	int n;
	cin >> n;

	ll p[61] = {0};
	rep(i, n) {
		ll a;
		cin >> a;

		ll t = 1;
		rep(j, 61) {
			if (a&(t)) ++p[j];

			t = t << 1;
		}
	}

	ll ans = 0;
	ll k = 1;
	rep(i, 61) {
		ll x = p[i] * (n - p[i]);

		ans += (k%MOD)*(x%MOD);
		ans %= MOD;

		k = k << 1;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define EPS (1e-9)
#define INF (1e17)
#define PI (acos(-1))
//const double PI = acos(-1);
//const double EPS = 1e-15;
//long long INF=(long long)1E17;
#define i_7 (long long)(1e9+7)
//#define i_7 998'244'353
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
long long po(long a, long b){
    if(b==0){
        return 1;
    }
    
    long long z = po(a,b/2);
    z = mod(z*z);
    if(b%2!=0){
        z = mod(a*z);
    }
    return z;
}
 
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=std::sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}
 
long long gcd_(long long a, long long b){
  if(a<b){
    std::swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
//using namespace std;
//using namespace boost::multiprecision;
//using namespace __gnu_pbds;

int main(){
  using namespace std;
  int n, m;
  cin>>n>>m;
  int a[m], b[m];
  REP(i, m) cin>>a[i]>>b[i];
  
  typedef pair<int, int> P;
  vector<P> ab;
  REP(i, m) ab.push_back(P(a[i], b[i]));
  auto cmp = [](P l, P r) -> bool{
    return l.second < r.second;
  };
  sort(ALL(ab), cmp);
  
  int x = 0;
  int ans = 0;
  REP(i, m){
    int ta = ab[i].first;
    int tb = ab[i].second;
    if(x <= 0){
      x = tb - 1;
      ans++;
    }else{
      if(ta <= x){
        continue;
      }else{
        x = tb - 1;
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5160
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f3f;
const int maxn = 1e5+500;
ll T,n,m;
int s[1005][1005];
int ct[1005];
int judge(){
	for(int i=1;i<=n;i++)
		if(ct[i]<n-1){
			return 1;
		}
	return 0;		
}

int vis[maxn];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=0;j<n-1;j++){
			scanf("%d",&s[i][j]);
		}
		ct[i] = 0;
	}
	int cnt = 0;
	while(judge()){
		int flag=0;
		for(int i=1;i<=n;i++)
			vis[i] = 0;
		for(int i=1;i<=n;i++){
			int now = s[i][ct[i]];
			if(ct[i]>=n-1)
				continue;
			if(vis[now]){
				vis[i] = 1;
				continue;
			}
			if(vis[i])
				continue;
			if(i==s[now][ct[now]]&&!vis[i]&&!vis[now]){
				vis[i] = 1;
				vis[now]=1;
				ct[i]++;
				ct[now]++;
				flag = 1;
			}
		}
		if(!flag){
			printf("-1\n");
			return 0;
		}
		cnt++;
	}
	printf("%d\n",cnt);
	
}


Measured memory_bytes: 4224
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from itertools import product

    h, w, k = map(int, readline().split())
    c = [list(input()) for _ in range(h)]

    ans = 0

    for row_bit in product(range(2), repeat=h):
        for col_bit in product(range(2), repeat=w):
            cnt = 0
            for row in range(h):
                for col in range(w):
                    if c[row][col] == "#" and (row_bit[row] and col_bit[col]):
                        cnt += 1
            if cnt == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68224
cnt = [0] * 4

for i in range(3):
    a, b = map(int, input().split())
    cnt[a - 1] += 1
    cnt[b - 1] += 1

cnt.sort()
if cnt[-1] == 3:
    print("NO")
elif cnt[0] == 0:
    print("NO")
else:
    print("YES")


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

int main(){
  int N,M;
  cin >> N >> M;
  int a[N];
  rep(i,N) a[i]=-1;
  int cnt=0;
  vector<vector<int>> vv(N);
  rep(i,M){
    int x,y,z;
    cin >> x >> y >> z;
    x--;y--;
    vv[x].push_back(y);
    vv[y].push_back(x);
  }
  queue<int> q;
  int i=0;
  int f=0;
  while(i<N){
    if(a[i]==-1){
      q.push(i);
      cnt++;
      a[i]=cnt;
      while(!q.empty()){
        int n=q.front();
        q.pop();
        for(int x:vv[n]){
          if(a[x]==-1){
            q.push(x);
            a[x]=cnt;
          }
        }
      }
    }
    i++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 6904
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

H,W,M = m()

data = []

setx = [0 for i in range(W)]
sety = [0 for i in range(H)]

for i in range(M):
    a,b = m()
    a -= 1
    b -= 1
    setx[b] += 1
    sety[a] += 1
    data.append([a,b])


mx = max(setx)
my = max(sety)
ans = 0
cox = 0
coy = 0
ans = my+mx
co = 0
for i in range(W):
    if setx[i] == mx:
        cox += 1
for i in range(H):
    if sety[i] == my:
        coy += 1
count = cox * coy
for po in data:
    if setx[po[1]]+sety[po[0]] == ans:
        co += 1
if co == count:
    ans -= 1
print(ans)

Measured memory_bytes: 117760
# Aizu Problem 0015: National Budget
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


N = int(input())
for n in range(N):
    a = int(input())
    b = int(input())
    budget = a + b
    print(budget if len(str(budget)) <= 80 else "overflow")

Measured memory_bytes: 7612
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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;}
#define DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

pair< vector<char>, vector<int> > RunLengthEncoding(vector<char> s) {
    int len=1;
    vector<char> c;
    vector<int> l;
    s.push_back('$');
    for (int i=1; i<s.size(); i++) {
        if (s[i] != s[i-1]) {
            c.push_back(s[i-1]);
            l.push_back(len);
            len = 1;
        } else len++;
    }
    return make_pair(c, l);
} 

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    V<char> s(n); REP(i, n) cin >> s[i];
    P<V<char>, V<int> > rle = RunLengthEncoding(s);
    cout << rle.first.size() << '\n';
    return 0;
}


Measured memory_bytes: 1528
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        t: [i64; n],
        v: [i64; n],
    }

    let mut lim = vec![];

    for i in 0..n {
        for _ in 0..t[i] {
            lim.push(v[i]);
        }
    }

    let mut tbl = vec![vec![None; lim.len()]; 100 + 1];
    let ans = solve(0, 0, &lim, &mut tbl);
    println!("{}", ans);
}

fn solve(t: i64, v: i64, lim: &[i64], tbl: &mut Vec<Vec<Option<f64>>>) -> f64 {
    if t as usize  >= lim.len() {
        return if v == 0 { 0.0 } else { -1.0 };
    }

    if v < 0 || t > 0 && v > lim[t as usize] {
        return -1.0;
    }

    if let Some(ret) = tbl[v as usize][t as usize] {
        return ret;
    }

    let mut ans = -1.0_f64;
    for &dv in &[-1, 0, 1] {
        if v + dv > lim[t as usize] {
            continue;
        }

        let cur = solve(t + 1, v + dv, lim, tbl);
        if cur < 0.0 {
            continue;
        }

        let dd = (v + v + dv) as f64 / 2.0 +
            if dv == 0 && v + 1 <= lim[t as usize] {0.25} else {0.0};

        ans = ans.max(cur + dd);
    }

    tbl[v as usize][t as usize] = Some(ans);
    ans
}


Measured memory_bytes: 47740
n, m, l = gets.split.map(&:to_i)
a, b = [], []
n.times {a << gets.split.map(&:to_i)}
m.times {b << gets.split.map(&:to_i)}

a.each do |row|
  c = Array.new(l, 0)
  row.each_with_index do |x, i|
    l.times {|j| c[j] += x * b[i][j]}
  end
  puts c.join(" ")
end


Measured memory_bytes: 7336
import sys
import itertools

# import numpy as np

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

W, H, x, y, r = map(int, readline().split())

print('Yes' if 0 <= x - r and x + r <= W and 0 <= y - r and y + r <= H else 'No')



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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
using Graph = vector<vector<ll>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1 << 29;
/****** define constant end ********/

/****** define variable start ******/
ll n, k;
/******* define variable end *******/

ll solve() {
  cin >> n >> k;
  ll amari = n % k;
  ll kouho = abs(n % k - k);
  cout << min(amari, kouho) << endl;
  return 0;
}
int main() {
  // clock_t start = clock();
  cout << std::fixed << std::setprecision(10);
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll end_solve = solve();
  /*
  clock_t end = clock();
  const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
  1000.0; printf("time %lf[ms]\n", time);
  */

  return (int)end_solve;
}


Measured memory_bytes: 256
#include<cstdio>
#include<map>
#include<string>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

int main(){
  for(int N,M,K,L;scanf("%d %d %d %d",&N,&M,&K,&L),N;){
    map<string,int> m;
    for(int i=0;i<N;i++){
      char name[11];
      int x;
      scanf("%s %d",name,&x);
      m[name]=x;
    }
    map<string,int> idx;
    vector<int> votes;
    for(auto e:m){
      auto s=idx.size();
      idx[e.first]=s;
      votes.push_back(e.second);
    }
    vector<int> fav(M);
    for(auto &e:fav){
      char name[11];
      scanf("%s",name);
      e=idx[name];
    }
    set<int> sfav(begin(fav),end(fav));
    sort(begin(fav),end(fav),[&](int a,int b){
	return (votes[a]!=votes[b])?votes[a]>votes[b]:a<b;
      });
    int l=0,h=min(M,K)+1;
    while(h-l>1){
      int mid=(l+h)/2;
      int vl=0,vh=2e9+9;
      while(vh-vl>1){
	int vm=(vh+vl)/2;
	long long nv=0;
	for(int i=0;i<mid;i++){
	  nv+=max(0,vm-votes[fav[i]]);
	}
	if(nv>L){
	  vh=vm;
	}else{
	  vl=vm;
	}
      }
      auto vmap=votes;
      vector<int> vc(begin(fav),begin(fav)+mid);
      int rl=L;
      for(auto e:vc){
	vmap[e]=max(vl,vmap[e]);
	rl-=max(0,vl-votes[e]);
      }
      sort(begin(vc),end(vc),[&](int a,int b){
	  return (vmap[a]!=vmap[b])?vmap[a]<vmap[b]:a>b;
	});
      for(int i=0;i<rl;i++){
	vmap[vc[i]]++;
      }
      vector<int> rank(N);
      iota(begin(rank),end(rank),0);
      sort(begin(rank),end(rank),[&](int a,int b){
	  return (vmap[a]!=vmap[b])?vmap[a]>vmap[b]:a<b;
	});
      int ri=0;
      for(int i=0;i<K;i++){
	ri+=sfav.count(rank[i]);
      }
      if(ri>=mid){
	l=mid;
      }else{
	h=mid;
      }
    }
    printf("%d\n",l);
  }
}

Measured memory_bytes: 24256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int n;

struct UnionFind {
    vector<int> par, cnt;

    UnionFind(int n): par(n, -1), cnt(n) {}
    int find(int x) {
        if (par[x]<0) return x;
        return par[x] = find(par[x]);
    }
    bool same(int i, int j) {
        // iとjが同じグループかどうかを判別する
        return find(i) == find(j);
    }
    int size(int x) {
        return -par[find(x)];
    }

    bool unite(int x, int y) {
        // iとjを併合する
        x = find(x);
        y = find(y);
        bool ok = (-par[x]>cnt[x] || -par[y]>cnt[y]);
        if (x == y) {
            cnt[x]++;
        } else if (par[x] > par[y]) {
            par[y] += par[x];
            par[x] = y;
            cnt[y] += cnt[x]+1;
        } else {
            par[x] += par[y];
            par[y] = x;
            cnt[x] += cnt[y]+1;
        }
        return ok;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while (true) {
        cin >> n;
        if (n == 0) break;
        V<double> x(n), y(n), z(n), r(n);
        for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> z[i] >> r[i];
        priority_queue< P<double, P<int, int> > > pq;
        UnionFind uni(n);
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if ((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j]) <= (r[i] + r[j]) * (r[i] + r[j])) {
                    uni.unite(i, j);
                } else {
                    pq.push(make_pair(-(sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]) + (z[i] - z[j]) * (z[i] - z[j])) - (r[i] + r[j])), make_pair(i, j)));
                }
            }
        }

        double ans = 0;
        while (!pq.empty()) {
            P<double, P<int, int> > q = pq.top(); pq.pop();
            if (!uni.same(q.second.first, q.second.second)) {
                uni.unite(q.second.first, q.second.second);
                ans -= q.first;
            }
        }
        cout << fixed << setprecision(3) << ans << '\n';
    }
    return 0;
}



Measured memory_bytes: 3372
#include <stdio.h>
#include <string.h>
 
void insert(int);
int hpEM(void);
void hpIK(int); 
void maxHp(int i);
int parentNode(int i);
int leftChild(int i);
int rightChild(int i);
 
int A[2000001];
int heap_size;
 
int main(){
 
  int i, key;
  char com[8];
 
  while(scanf("%s",com), strcmp(com,"end")){
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    if(com[0]=='e'){
      printf("%d\n",hpEM());
    }
  }
 
  return 0;
 
}
 
void insert(int key){
 
  heap_size++;
  A[heap_size] = -1;
  hpIK(key);
 
}
 
void hpIK(int key){
 
  int i = heap_size, tmp;
 
  if(key < A[i]){
      return;
  }
  A[i] = key;
  while(i > 1 && A[parentNode(i)] < A[i]){
    tmp = A[parentNode(i)];
    A[parentNode(i)] = A[i];
    A[i] = tmp;
    i = parentNode(i);
  }
 
}
 
int hpEM(void){
 
  int max;
  if(heap_size < 1){
      return;
  }
  max = A[1];
  A[1] = A[heap_size];
  heap_size--;
  maxHp(1);
  return max;
 
}
  
void maxHp(int i){
    int l = leftChild(i);
    int r = rightChild(i);
    int largest, tmp;
      
    if(l <= heap_size && A[l] > A[i]){
        largest = l;    
    }else{
        largest = i;
    }
    if(r <= heap_size && A[r] > A[largest]){
        largest = r;    
    }
    if(largest != i){
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        maxHp(largest);
    }
}
 
int parentNode(int i){
    return (int)i/2;
}
  
int leftChild(int i){
    return 2*i;
}
  
int rightChild(int i){
    return 2*i+1;
}

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

int main() {
    vector<vector<char>> c(3,vector<char>(3));
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++)
        cin >> c.at(i).at(j);
    }   
    cout << c.at(0).at(0) << c.at(1).at(1) << c.at(2).at(2) << endl;
}

Measured memory_bytes: 256
n = int(input())

xyh = [list(map(int,input().split()))for i in range(n)]
i = 0
while i<n:
    if xyh[i][2]==0:
        xyh.pop(i)
        n -= 1
    else: i += 1

if(n==1):
    print(*xyh[0])
    exit()

for i in range(101):
    for j in range(101):
        base = xyh[0][2]+abs(xyh[0][0]-i)+abs(xyh[0][1]-j)
        for k in range(1, n):
            if base!=xyh[k][2]+abs(xyh[k][0]-i)+abs(xyh[k][1]-j): break
        else:
            print(i, j, base)
            exit()

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

int main() 
{
  int i,S,L;
  cin >> i;
  vector<int> vec(i);

  for (int j = 0; j < i; j++) 
  {
    cin >> vec.at(j);
  }
  S = 1;
  L = vec.at(0);
  for(int j =1; j<i ;j++)
  {
    if(L<=vec.at(j))
    {
      S++;
      L = vec.at(j);
    }
  }
    cout << S <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>

// #define     _DEBUG_01

#ifdef _DEBUG_01
#define     MAX_PRIME_NUMBER     100
#else
#define     MAX_PRIME_NUMBER     1000000
#endif

using namespace std;

unsigned int MyGCD(const unsigned int, const unsigned int);

int main(){
	vector <int> PrimeNumber;
	vector <int> input_a, input_d, input_n;
	int i, j;
	int a, d, n, cnt;

	// 素数表の作成
	PrimeNumber.push_back(2);
	for(i=3;i <= ((int)(MAX_PRIME_NUMBER));i+=2){
		// i の平方根を求める
		const int rooti = (int)sqrt((double)i);
		// i を素数表に加える
		PrimeNumber.push_back(i);
		// 3 以上 i^(1/2) 以下の素数で i を割った余りをチェック
		for(j=1;(j < (int)PrimeNumber.size()) && (PrimeNumber[j] <= rooti);j++){
			if((i % PrimeNumber[j]) == 0){				// 余りが 0 になることがあれば
				PrimeNumber.pop_back();					// i を素数表から削除して
				break;									// 内側のループから抜ける
			}
		}
	}

#ifdef _DEBUG_01
	// 素数表を出力して終了
	cout << PrimeNumber[0];
	for(i=1;i < (int)PrimeNumber.size();i++){
		cout << "," <<PrimeNumber[i];
	}
	cout << endl;

	return 0;
#endif

	// 入力ループ
	cin >> a >> d >> n;
	for(cnt=0;(a > 0) && (d > 0) && (n > 0);cnt++){
		// a と d が互いに素であるかチェック
		if(MyGCD((unsigned int)a, (unsigned int)d) != 1){
			cerr << a << "と" << d << "は互いに素ではありません" << endl;
			cin >> a >> d >> n;
			continue;
		}

		// 入力値を蓄える
		input_a.push_back(a);
		input_d.push_back(d);
		input_n.push_back(n);

		// 入力
		cin >> a >> d >> n;
	}

	// 条件を満たす素数を求め、出力する
	for(i=0;i<cnt;i++){
		int how_many_prime_numbers = 0, p;
		// 等差数列の各項が素数かどうかチェック
		for(j=input_a[i];how_many_prime_numbers<input_n[i];j+=input_d[i]){
			int a = 0, b = (int)PrimeNumber.size() - 1, m;
			// 素数表を検索
			while(a<=b){
				m = (a + b) / 2;
				if(PrimeNumber[m] == j){
					p = j;
					how_many_prime_numbers++;
					break;
				}else if(PrimeNumber[m] > j){
					b = m - 1;
				}else if(PrimeNumber[m] < j){
					a = m + 1;
				}
			}
		}
		// 結果を出力する
		cout << p << endl;
	}

	return 0;
}

unsigned int MyGCD(const unsigned int a, const unsigned int b){
	unsigned int s = ((a >= b) ? a : b), t = ((a >= b) ? b : a);
	unsigned int buf;

	while((s % t) != 0){
		buf = s % t;
		s = t;
		t = buf;
	}

	return t;
}

Measured memory_bytes: 1592
#include<iostream>
using namespace std;
int main()
{
    string s,t,u;
    int a,b;
    while(cin>>s>>t>>a>>b>>u)
    {
        if(s==t)
        {
           break;
        }
        else if(s==u)
        {
            cout<<a-1<<" "<<b<<endl;
        }
        else if(t==u)
        {
            cout<<a<<" "<<b-1<<endl;
        }

    }
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    int A[100];
    int ans=0;

    rep(i,N) cin>>A[i];

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

    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int main (){
    int n, k;
    cin >> n >> k;
    int ans = 1;
    for (int i = 0; i < n; i++){
        if (ans<=k){
            ans *= 2;
        } else {
            ans += k;
        }
    }
    cout << ans << endl;
    return 0;
}



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

//-------------------------------------------------
//--Segment tree
//-------------------------------------------------
template<typename T>
class SegmentTree
{
private:
    using F = function<T(T,T)>;
    ::std::vector<T> btree;
    F f, _update;
    T e;
    int n;
public:
    SegmentTree(int _n, F f, T e, F g=[](T a,T b){return b;})
         : f(f),e(e),_update(g)
    {
        init(_n);
    }
    SegmentTree(const ::std::vector<T> &v, F f, T e, F g=[](T a,T b){return b;})
         : f(f),e(e),_update(g)
    {
        int _n = v.size();
        init(_n);
        for(int i=0; i<_n; i++) btree[i+n-1] = v[i];
        build();
    }
    void init(int _n){
        n = 1;
        while(_n>n) n<<=1;
        btree.resize(2*n-1, e);
    }
    void build(){
        for(int i=n-2; i>=0; i--) btree[i] = f(btree[2*i+1], btree[2*i+2]);
    }
    void update(int k, T a){
        k += n-1;
        btree[k] = _update(btree[k], a);
        while(k>0){
            --k>>=1;
            btree[k] = f(btree[2*k+1], btree[2*k+2]);
        }
    }
    T query(int a, int b){
        T L=e, R=e;
        a+=n-1; b+=n-1;
        while(a<b){
            if (!(a & 1)) L=f(L, btree[a++]);
            if (!(b & 1)) R=f(btree[--b], R);
            a>>=1; b>>=1;
        }
        return f(L, R);
    }
    T operator[](int k){return btree[k+n-1];}
};

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vi a(n);
    rep(i,n) cin>>a[i];
    SegmentTree<int> seg(a, [](int x,int y){return min(x,y);}, n+1);
    int ans=0;
    rep(i,n){
        if (seg.query(0,i+1)==a[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3072