akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<vector<pair<int, int>>> xy(n);
    REP(i, n){
        ll ai;
        cin >> ai;
        REP(j, ai){
            ll x, y;
            cin >> x >> y;
            x--;
            xy.at(i).emplace_back(x, y);
        }
    }

    ll ans = 0;
    REP(s, 1 << n){
        bool is_ok = true;
        REP(i, n){
            if(((s >> i) & 1) == 0){ continue; }
            for(const auto& tmp : xy.at(i)){
                const int xi = (s >> tmp.first) & 1;
                if((xi == 1 && tmp.second != 1) || (xi == 0 && tmp.second == 1)){
                    is_ok = false;
                    break;
                }
            }
        }
        if(is_ok){
            ll num1 = 0;
            REP(i, n){
                num1 += (s >> i) & 1;
            }
            ans = max(ans, num1);
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(int argc, char *argv[])
{
	int i;
	int N, K;

	cin >> N >> K;
	int target[N];

   
	for (i = 0; i < N; i++) {
		cin >> target[i];
	}

	if ((N - 1) % (K - 1) == 0)
		cout << (N - 1) / (K - 1) << "\n";
	else
		cout << (N - 1) / (K - 1) + 1 << "\n";

	return 0;
}


Measured memory_bytes: 640
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int l = 0, r = n - 1;
    char lc, rc;
    cout << 0 << endl;
    string s; cin >> s;
    if(s[0] == 'V'){ return 0; }
    lc = s[0];
    cout << n - 1 << endl;
    cin >> s;
    if(s[0] == 'V'){ return 0; }
    rc = s[0];
    while(1){
        int piv = (l + r) / 2;
        cout << piv << endl;
        cin >> s;
        if(s[0] == 'V'){ return 0; }
        int len = piv - l;
        if((s[0] != lc) ^ (len & 1)){
            r = piv;
        }else{
            l = piv;
            lc = s[0];
        }
    }
}


Measured memory_bytes: 852
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int a, b, c;
	bool ispossible = false;
	scanf("%d%d%d", &a, &b, &c);
	for (int i = 1; i < b + 1; ++i) {
		if ((a * i) % b == c)ispossible = true;
	}

	printYN(ispossible);
	return 0;
}


Measured memory_bytes: 128
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut counts = vec![0; 31];
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    input.clear();
    io::stdin().read_line(&mut input)?;
    let n_s: Vec<i32> = input
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<i32>().unwrap())
        .collect();
    input.clear();

    for &n in &n_s {
        let s = format!("{:b}", n);
        let mut index = 1;
        for x in s.chars().rev() {
            if x == '1' {
                let i = counts.len() - index;
                counts[i] += 1;
            }
            index += 1;
        }
    }

    let mut result = String::new();
    for &n in &n_s {
        let mut temp = counts.clone();
        let s = format!("{:b}", n);
        let mut index = 1;
        for x in s.chars().rev() {
            if x == '1' {
                let i = counts.len() - index;
                temp[i] -= 1;
            }
            index += 1;
        }

        let mut r = String::new();
        for x in temp {
            if x % 2 == 1 {
                r.push('1');
            } else {
                r.push('0');
            }
        }
        if result.len() == 0 {
            result.push_str(&i64::from_str_radix(&r, 2).unwrap().to_string());
        } else {
            result.push_str(" ");
            result.push_str(&i64::from_str_radix(&r, 2).unwrap().to_string());
        }
    }
    println!("{}", result);
    Ok(())
}


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

int main()
{
	int a, b, c, d;
	int p;

	scanf("%d%d%d%d%d", &a, &b, &c, &d, &p);

	if (p <= c){
		printf("%d\n", min(p * a, b));
	}
	else {
		printf("%d\n", min(p * a, b + (p - c) * d));
	}

	return (0);
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 200100
ll N,A,B;
vi V,breaks;
ll a;
ll fw[MAXN];
ll MOD = 1e9+7;

void update(ll x, ll y, ll v){
	++y;
	for (;y;y-=y&(-y)){fw[y]+=v;fw[y]%=MOD;}
	for (;x;x-=x&(-x)){fw[x]=(fw[x]+MOD-v)%MOD;}
}

ll query(ll x){
	++x;
	ll res=0;
	for (;x<=MAXN;x+=x&(-x)){res += fw[x];res %= MOD;}
	return res;
}

int main(){
	cin>>N>>A>>B;
	if (A > B)swap(A,B); // A is small
	V.pb(0);
	for (ll i=1;i<=N;++i){cin>>a;V.pb(a);}
	V.pb(LONG_LONG_MAX);
	for (ll i=1;i<N;++i){
		if (V[i+1] - V[i] < A)breaks.pb(i);
		if (V[i+2] - V[i] < A){
			cout<<0;return 0;
		}
	}
	// for (auto i:breaks)cout<<i<<' ';
	ll lastbreak = -1;
	if (SZ(breaks))lastbreak = breaks.back();
	breaks.pb(N+1);
	// for (auto i : breaks)cout<<i<<' ';
	update(0,0,1);
	for (ll i=0;i<=N;++i){
		ll t = query(i);
		// cout<<i<<' '<<t<<'\n';
		// Last update
		ll last_update = *ub(ALL(breaks), i)+1;
		ll first_update = lb(ALL(V), V[i] + B)-V.begin();
		// assert(V[i+1] - V[i-1] >= A);
		// cout<<V[i]+B<<'\n';
		if (i==0)first_update=1;
		if (first_update <= last_update)update(first_update,last_update,t);
	}
	ll ans = 0;
	for (ll i=0;i<=N;++i){
		// Whether or not there are any issues after the thing
		if (i < lastbreak)continue;
		if (i > 1 && i < N && V[i+1] - V[i-1] < A)continue;
		ans += query(i);
		ans %= MOD;
	}
	cout<<ans;
}


Measured memory_bytes: 2804
a, b = map(int, input().split())
ass = 1 if ((100/8 * (a+1))-int(100/8 * (a+1))) else 0
asss = 1 if ((100/8 * a)-int(100/8 * a)) else 0
bss = 1 if ((100/10 * (b+1))-int(100/10 * (b+1))) else 0
bsss = 1 if ((100/10 * b)-int(100/10 * b)) else 0
As = set(range(int(100/8 * a)+asss, int(100/8 * (a+1))+ ass))
Bs = set(range(int(100/10 * b)+bsss, int(100/10 * (b+1))+bss))
if As & Bs:
    print(min(As&Bs))
else:
    print(-1)
   


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 #define NMAX 100005
using namespace std;
const long long MOD=1e9+7;
long long dp[NMAX][2];
vector <int> graf[NMAX];
int n;
void dfs(int nod,int tata)
{
    for(int i=0;i<(int)graf[nod].size();i++)
    {
        int to=graf[nod][i];
        if(to!=tata)
        {
            dfs(to,nod);
            dp[nod][1]*=dp[to][0];
            dp[nod][1]%=MOD;
            dp[nod][0]*=(dp[to][0]+dp[to][1]);
            dp[nod][0]%=MOD;
        }
    }
}
int main()
{
    int x,y;
    cin>>n;
    for(int i=1;i<=n-1;i++)
    {
        cin>>x>>y;
        graf[x].push_back(y);
        graf[y].push_back(x);
    }
    for(int i=1;i<=n;i++)
        dp[i][0]=dp[i][1]=1;
    dfs(1,0);
    cout<<(dp[1][0]+dp[1][1])%MOD;
    return 0;
}

Measured memory_bytes: 14208
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> products;
  rep(i, n) loop(j, i + 1, n) products.push_back(a[i] * a[j]);
  sort(all(products));
  for (int i = products.size() - 1; i >= 0; i--) {
    string s;
    s = to_string(products[i]);
    bool flag = true;
    rep(j, s.size() - 1) {
      if (s[j + 1] - s[j] != 1) flag = false;
    }
    // cout << s << endl;
    if (flag) {
      cout << products[i] << endl;
      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}



Measured memory_bytes: 7076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
string S;cin>>S;
  vector<char>a(S.size());
  rep(i,S.size()){a.at(i)='x';}
  rep(i,S.size()){cout<<a.at(i);}
  cout<<endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>

int main (void){

	int W,H,x,y,r;

	while(scanf("%d %d %d %d %d",&W,&H,&x,&y,&r) != EOF){

	if(x-r<0 || x+r>W || y-r<0 || y+r>H){
		printf("No\n");
	}else{
		printf("Yes\n");
	}
	}
return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

const ll base = 1e6;
int D;
int C[30];
int S[400][30];

ll score(vector<int>& t)
{
  vector<int> last(30, 0);
  ll s = 0LL;
  REP(i,D){
    s += S[i][t[i]];
    last[t[i]] = (i+1);
    REP(j,26){
      s -= C[j] * (i+1-last[j]);
    } 
  }
  return s;
}

vector<int> init(int sub)
{
  vector<int> t(D);
  REP(i,D) t[i] = (i+sub)%26;
  return t;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rand365(0, 364);
  uniform_int_distribution<> rand26(0, 25);

  cin >> D;
  REP(i,26) cin >> C[i];
  REP(i,D) REP(j,26) cin >> S[i][j];

  auto T = init(0);
  ll max_score = 0LL;
  REP(sub,26){
    auto tmp = init(sub);
    ll sc = max(base+score(tmp), 0LL);
    if(max_score<sc){
      max_score = sc;
      T = tmp;
    }
  }
  
  int ti = clock();
  while(clock() - ti < 190 * CLOCKS_PER_SEC / 100){ 
    int d = rand365(mt);
    int q = rand26(mt);
    int old = T[d];
    T[d] = q;
    ll tmp = max(base + score(T), 0LL);
    if(max_score<tmp){
      max_score = tmp;
    }else{
      T[d] = old;
    }
  }
  REP(i,D) cout << T[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int m, int nmi, int nma) {
    VI P(m);
    REP(i, m) cin >> P[i];
    RSORT(P);
    P.EB(0);
    PII ans = MP(abs(P[nmi] - P[nmi - 1]), nmi);
    FOR(i, nmi, nma) {
        int dif = abs(P[i] - P[i + 1]);
        if (dif >= ans.first) {
            ans = MP(dif, i + 1);
        }
    }
    cout << ans.second << endl;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    while (cin >> m >> a >> b, m) {
        solve(m, a, b);
        //return 0;
    }
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int W, H;
ll p[100010], q[100010];
ll r[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> W >> H;
  ll ans = 0;
  for (int i = 0; i < W; i++) {
    cin >> p[i];
    ans += p[i];
  }
  for (int i = 0; i < H; i++) {
    cin >> q[i];
    ans += q[i];
  }
  sort(p, p + W);
  sort(q, q + H);
  for (int i = 0; i < W; i++) {
    if (i == 0) r[i] = p[i];
    else r[i] = r[i - 1] + p[i];
  }
  for (int i = 0; i < H; i++) {
    int pos = lower_bound(p, p + W, q[i]) - p;
    ans += (W - pos) * q[i];
    if (pos - 1 >= 0) ans += r[pos - 1];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

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


void bottom(string str,string& ans){
	if(str.size() == 1){
		ans = str;
		return;
	}

	string next;

	for(int i=0;i<str.size()-1;i++){
		next.push_back((str[i]-'0'+str[i+1]-'0') % 10 + '0');
	}

	bottom(next,ans);
}

int main(){
	string str;
	while(cin>>str){
		string res;
		bottom(str,res);
		cout << res << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
ll exp(ll taban, ll us) {
    ll carpan = taban % mod;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % mod;
        temp /= 2;
        carpan = (carpan*carpan) % mod;
    }
    return res;
}
ll ebob(ll a, ll b){
	if(!a)return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a, b);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	double n; cin>>n;
	cout<<fixed<<setprecision(10)<<(n/3) * (n/3) * (n/3)<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

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

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll L, R;
    cin >> L >> R;

    if (R - L >= 2018) {
        print(0);
    } else {
        L %= 2019, R %= 2019;

        int ans = 2018;
        FOR(i, L, R + 1) FOR(j, i + 1, R + 1) {
            ans = min(ans, i * j % 2019);
        }
        print(ans);
    }
    
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int ar[100002][2];
int check(int i)
{
	if(i<=2)
	return ar[i][1];
	if(ar[i][1]!=-1)
    return ar[i][1];
	int p = check(i-1);
	int q = check(i-2);
    if(p+abs(ar[i][0]-ar[i-1][0])<abs(ar[i][0]-ar[i-2][0])+q)
	ar[i][1]=p+abs(ar[i][0]-ar[i-1][0]);
	else
	ar[i][1]=q+abs(ar[i][0]-ar[i-2][0]); 
    return ar[i][1];
}
int main()
{
	int n;
	cin>>n;
	//int ar[n];
	for(int i=0;i<n;i++)
	{
		cin>>ar[i][0];
	}
	for(int i=0;i<n;i++)
	ar[i][1]=-1;
		ar[1][1]=abs(ar[1][0]-ar[0][0]);
	ar[2][1]=abs(ar[2][0]-ar[0][0]);
    int res=check(n-1);
    cout<<res;
    return 0;
}

Measured memory_bytes: 5760
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = Integer.parseInt(scanner.next());
        int b = Integer.parseInt(scanner.next());
        int c = Integer.parseInt(scanner.next());

        Set<Integer> anSet = new HashSet();
        anSet.add(a);
        anSet.add(b);
        anSet.add(c);
        System.out.print(anSet.size());
    }
}


Measured memory_bytes: 21972
N = int(input())
koho = [1]
i=1
while True:
    if i > 1e6:
        break
    i *= 6
    koho.append(i)
i=1
while True:
    if i > 1e6:
        break
    i *= 9
    koho.append(i)

dp = [0] * (N+1)
for i in range(1, N+1):
    tmp = []
    for k in koho:
        if k > i:
            continue
        tmp.append(dp[i - k] + 1)
    dp[i] = min(tmp)
print(dp[N])

Measured memory_bytes: 3828
#include <stdio.h>
#include <stdbool.h>

int weight[10] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 };

int FuncCmpWeight(const int left);

int main(void)
{
	int w;
	int i, j;
	bool flag;

	while (scanf("%d", &w) != EOF) {
		flag = false;
		for (i = 0; i < 10; i++) {
			if (w & (1 << i)) {
				if (flag == true) putchar(' ');
				printf("%d", (1 << i));
				flag = true;
			}
		}
		putchar('\n');
	}

	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
using namespace std;
using ll = long long;
//------------------- mod ----------------------
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

//----------------combination---------//
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
}com(5000);

int main()
{
  // input
  int n, k;
  cin >> n >> k;

  // solve
  vector<mint> ans;
  rep2(i,1,k+1){
    // red:n-k
    // blue:k
    mint a = com(n-k+1,i);
    mint b = com(k-1,i-1);
    ans.emplace_back(a*b);
  }

  // output
  rep(i,ans.size()) cout << ans[i] << endl;

  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
using Edge = pair<int, long long>;
using Graph = vector<vector<Edge>>;

vector<int> color;
void dfs(const Graph &G, int v, int c) {
    color[v] = c;
    
    for(auto e : G[v]) {
        if(color[e.first] != -1) continue;
        
        if(e.second % 2) dfs(G, e.first, 1 - c);
        else dfs(G, e.first, c);
    }
}

int main() {
    int N; cin >> N;
    
    Graph G(N);
    for(int i = 0; i < N - 1; ++i) {
        int a, b;
        long long w;
        cin >> a >> b >> w;
        --a, --b;
        G[a].push_back(Edge(b, w));
        G[b].push_back(Edge(a, w));
    }
    color.assign(N, -1);
    dfs(G, 0, 0);
    for(int i = 0; i < N; ++i) cout << color[i] << endl;
}


Measured memory_bytes: 9600
#include<stdio.h>

int main(void){
	int time,h,m,s;
	scanf("%d",&time);
	h = (time-time%3600)/3600;
	m = (time-h*3600-(time-h*3600)%60)/60;
	s = (time-h*3600)%60;
	printf("%d:%d:%d\n",h,m,s);
return 0;
}

Measured memory_bytes: 592
while
  n = gets
  if ! n then
    exit
  end
  n=n.chomp.to_i

  ls = gets.chomp.split(' ').map { | x | x.to_i}

  count = 0
  r = 0.upto(ls.size-1).to_a
  r.combination(3).uniq.each { | a,b,c |
    aa,bb,cc = [ls[a],ls[b],ls[c]].sort { | x,y | y <=> x}
#    p [[a,b,c], [aa,bb,cc]]
#    p [a,b,c]
    if (aa < bb+cc && aa != bb && aa != cc && bb != cc) then
#      p [a,b,c]
      count = count + 1
    end
  }
  puts count

end



Measured memory_bytes: 30680
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <sys/timeb.h>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define FOR(NAME, START, NUM) for (ll NAME = START; NAME < (NUM); NAME++)
#define REP(NAME, NUM) for (ll NAME = 0; NAME < (NUM); NAME++)
#define BREP(NAME, NUM) for (ll NAME = (NUM)-1; NAME >= 0; NAME--)
#define ALL(NAME) (NAME).begin(), (NAME).end()
const ll LINF = 1e18;
const int INF = 1e9;
const int mod = 1e9+7;

int main(){
  ll n,p,x,cnt = 0;
  cin >> n;
  vector<int> a(n);
  vector<int> tf(n);
  
  REP(i, n){
	cin >> a[i];
  }
  
  BREP(i, n){
	if((i+1)*2 > n){
	  tf[i] =  a[i];
	}
	
	else{
	  x = (i+1)*2;
	  p = 0;
	  while(x <= n){
		p += tf[x-1];
		x += (i+1);
	  }
	  
	  p = p%2;
	  
	  if(p == a[i]){
		tf[i] = 0;
	  }
	  
	  else{
		tf[i] = 1;
	  }
	}
	if(tf[i] == 1)cnt++;
  }
  
  cout << cnt << endl;
  
  REP(i, n){
	if(tf[i] == 1){
	  cout << i+1 << " ";
	}
  }

  cout << endl;
}


Measured memory_bytes: 2432
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<float> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	for (int i = 0; i < N-1; i++) {
		a[i + 1] = (a[i] + a[i + 1]) / 2;
	}
	cout << a[N-1] << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10 * TEN(n-1); }

vector<int> H;
int N;

string solve(void) {
    for(int i = 1;i < N;i++) {
        if(H[i] > H[i-1])
            H[i]--;
    }

    for(int i = 1;i < N;i++) {
        if(H[i-1] > H[i]) {
            return "No";
        }
    }

    return "Yes";
}
int main(void) {
    cin>>N;

    for(int i = 0;i < N;i++) {
        int h;
        cin>>h;
        H.push_back(h);
    }

    cout<<solve()<<endl;

    return 0;
}




Measured memory_bytes: 892
S = input()
N = len(S)
ans = 'Yes'

#回文判定1
if S != S[::-1]:
  ans = 'No'

#回文判定2
tmp = S[:int((N-1)/2)]
if tmp != tmp[::-1]:
  ans = 'No'

#回文判定2
tmp = S[int((N+3)/2-1):]
if tmp != tmp[::-1]:
  ans = 'No'

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
using namespace std;
class union_find{
private:
    vector<int>parent;
    vector<int>rank;
    int cnt;
public:   
    union_find(int vertex_num)
    {
        parent.resize(vertex_num);
        rank.resize(vertex_num);
        cnt = vertex_num;
        for(int i = 0; i < vertex_num; ++i){
            parent[i] = i;
            rank[i] = 0;
        }
    }
    int get_root(int n)
    {
        if(parent[n] == n){
            return n;
        }else{
            return get_root(parent[n]);
        }
    }
    void unite(int a, int b)
    {
        int root_a=get_root(a),root_b=get_root(b);
        if(root_a == root_b) return;
        if(rank[root_a] < rank[root_b]){
            parent[root_a] = root_b;
            cnt--;
        }else if(rank[root_a] > rank[root_b]){
            parent[root_b] = root_a;
            cnt--;
        }else{
            parent[root_a] = root_b;
            ++rank[root_b];
            cnt--;
        }
    }
    int get_cnt()
    {
        return cnt;
    }
};

int main()
{
    int n, m, ans = 0;
    cin >> n >> m;
    vector<vector<int>>a(m,vector<int>(2));
    for(int i = 0; i < m; ++i){
        cin >> a[i][0] >> a[i][1];
        a[i][0]--;
        a[i][1]--;
    }
    for(int i = 0; i < m; ++i){
        union_find uf(n);
        for(int j = (i % m), k = 0;k < m-1; j = ((j + 1) % m), k++){
            uf.unite(a[j][0], a[j][1]);//１組抜かしてそのcntを調べたい
        }
        if(uf.get_cnt() != 1) ans++;
    }
    cout << ans << endl;   
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int binarySearch(int n, int *s, int key) {
    int r,l;
    l = 0;
    r = n;
    while( r > l+1 ) {
        int m = ( r + l )/2;
        if ( s[m] >  key ) r = m;
        else l = m;
    }
    return s[l] == key;
}


int main(){
    int cou = 0;
    int n;
    int i,s[100000];

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

    int q;
    int t;

    scanf("%d",&q);
    for(i = 0; i < q; i++) {
        scanf("%d",&t);
        cou += binarySearch(n,s,t);
    }

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



Measured memory_bytes: 2156
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main{

    public static void main(String[] args) throws Exception{
        BufferedReader bf =new BufferedReader( new InputStreamReader(System.in));
        int n = Integer.parseInt(bf.readLine());
        //System.out.println(n);
        while(n != 0) {
            Score s = new Score();
            for (int i = 0; i < n; i++){
                String new_line = bf.readLine();
                String[] data = new_line.split(" ");
                int a = Integer.parseInt(data[0]);
                int b = Integer.parseInt(data[1]);
                s.openCard(a,b);
                //System.out.println("a = " + a + "  b = " + b);
            }
            s.print();
            n = Integer.parseInt(bf.readLine());
        }
        //System.out.print("finish");
    }
}

class Score{
    int A=0 ,B =0;
    public Score(){
    }
    public void openCard(int a, int b){
        if(a>b){
            A += (a+b);
            return;
        }
        if(b > a){
            B += (a+b);
            return;
        }
        A += a;
        B += b;
    }
    public void print(){
        System.out.println(A+" "+B);
    }
}

Measured memory_bytes: 34180
N=int(input())
shougen=[(0,0) for i in range(0,N)]
for i in range(0,N):
    A=int(input())
    honest=0
    unkind=0
    for j in range(0,A):
        x,y=map(int,input().split())
        if y==0:
            unkind+=2**(x-1)
        else:
            honest+=2**(x-1)
    shougen[i]=(honest,unkind)

ans=0
for i in range(0,2**N):
    honest=i
    unkind=2**N-1-i
    check=True
    test=0
    for j in range(0,N):
        if (i>>j)&1 ==1:
            test+=1
            x,y=shougen[j]
            if (honest-x)^x!=honest or (unkind-y)^y!=unkind:
                check=False
    if check:
        if test>ans:
            ans=test

print(ans)

Measured memory_bytes: 41836
S = input()
SL = list(S)

if SL[0] == SL[1] and SL[1] == SL[2]:
    print('No')
elif SL[0] == SL[1] and SL[2] == SL[3]:
    print('Yes')
elif SL[0] == SL[2] and SL[1] == SL[3]:
    print('Yes')
elif SL[0] == SL[3] and SL[1] == SL[2]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int K, Q;
  int d[SIZE];

  scanf("%d%d", &K, &Q);

  for (int i = 0; i < K; i++) {
    scanf("%d", d + i);
  }

  for (int i = 0; i < Q; i++) {
    int N, X, M;
    scanf("%d%d%d", &N, &X, &M);

    ll sum = 0;
    ll ans = N - 1;

    for (int j = 0; j < K; j++) {
      int num = (N - 1) / K + ((N - 1) % K >= (j + 1));
      sum += (ll)(d[j] % M) * num;

      if (d[j] % M == 0) ans -= num;
    }

    sum += X % M;
    ans -= sum / M;

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

  return 0;
}


Measured memory_bytes: 256
// ALDS1_1_B gcd
#include <iostream>
using namespace std;

void gcd(int x, int y){
    int temp;
    if(x<y){
        temp = y;
        y = x;
        x = temp;
    }

    if(x%y == 0){cout << y << endl;}
    else{gcd(y,x%y);}
}

int main(){
    int x,y;
    cin >> x >> y;
    gcd(x,y);
    return 0;
}


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

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

    int n, x, t;
    std::cin >> n >> x >> t;
    std::cout << t * ((n + x - 1) / x);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define ff(i, x, y) for(int i = x;i <= y;i++)
#define fs(i, x, y) for(int i = x;i >= y;i--)
using namespace std;
typedef long long ll;
int a[100010], b[100010], n;
typedef pair<int, int> pii;
pii p[100010];
map<int, int>mp;
map<int, int>rk;
int main() {
    scanf("%d", &n);
    ff(i, 1, n) {
        scanf("%d", &a[i]);
        mp[a[i]] = i;
        p[i].second = a[i];
    }
    ff(i, 1, n) {
        scanf("%d", &b[i]);
        p[i].first = b[i];
    }
    sort(a + 1, a + 1 + n);
    sort(b + 1, b + 1 + n);
    sort(p + 1, p + 1 + n);
    int pan = 1, temp = 0, pos = 1, pan2 = 1;
    ff(i, 1, n) {
        rk[a[i]] = i;
        if(b[i] < a[i])
            pan = 0;
        int ti = 0;
        while(1) {
            if(pos > n)
                break;
            if(b[i] >= a[pos]) {
                pos++;
                ti++;
            }
            else
                break;
        }
        if(ti > 1)
            temp = 1;
    }
    ff(i, 1, n)
    mp[rk[p[i].second]] = i;
    if(pan == 0) {
        printf("No");
    }
    else if(temp == 1)
            printf("Yes");
    else {
        int ti = 0, posnow = 1;
        while(1) {
            if(rk[p[posnow].second] != posnow) {
                ti++;
                int ne = mp[posnow];
                swap(p[posnow].second, p[ne].second);
                swap(mp[posnow], mp[rk[p[posnow].second]]);
                posnow = ne;
            }
            else
                break;
        }
        if(ti != n - 1)
            printf("Yes");
        else
            printf("No");
    }
    return  0;
}


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

int main() {
	int N, A[100];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A, A + N);
	cout << A[N - 1] - A[0] << endl;
} 


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


using namespace std;

using ll = long long;


ll gcd(ll x, ll y) {
    if (x < y) {
        ll t = y;
        y = x;
        x = t;
    }

    while (y != 0) {
        ll t = x % y;
        x = y;
        y = t;
    }
    return x;
}


ll lcm(ll x, ll y) {
    return (x * y) / gcd(x, y);
}


ll count(ll x) {
    ll cnt = 0;
    while (x > 0 && x % 2 == 0) {
        x /= 2;
        cnt++;
    }
    return cnt;
}


int main() {
    ll M;
    int N;
    cin >> N >> M;
    vector<ll> A(N);
    vector<ll> A_copy(N);

    for (ll i = 0; i < N; i++) {
        cin >> A[i];
        A[i] /= 2;
        A_copy[i] = A[i];
    }

    while (A_copy[0] % 2 == 0) {
        for (ll i = 0; i < N; i++) {
            A_copy[i] /= 2;
        }
    }
    for (ll i = 0; i < N; i++) {
        if (A_copy[i] % 2 == 0) {
            cout << "0" << endl;
            return 0;
        }
    }

    ll A_lcm = 1;
    for (ll i = 0; i < N; i++) {
        A_lcm = lcm(A_lcm, A[i]);
    }

    ll ans = (M / A_lcm + 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "C"
int cnt[1001];
void fact(int u){
    int i=2;
    while(i*i<=u){
        while(u%i==0){
            u/=i;
            cnt[i]++;
        }
        i++;
    }
    if(u>1) cnt[u]++;
}
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    int n;
    read(n);
    FOR(i, 2, n) fact(i);
    ll ans=1;
    FOR(i, 1, n) ans=(ans*(cnt[i]+1))%1000000007;
    write(ans);
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
const int N=200005;
vector<int> vp[N];
int v[N*2],nxt[N*2],point[N],bs;
int vis[N],sv[N],tp[N],ans[N],tot;
void addedge(int x,int y)
{
    bs++;v[bs]=y;nxt[bs]=point[x];point[x]=bs;
    bs++;v[bs]=x;nxt[bs]=point[y];point[y]=bs;
}
void dfs0(int x,int bh)
{
    vis[x]=1;tp[x]=bh;
    for (int p=point[x];p;p=nxt[p])
     if (!vis[v[p]]) dfs0(v[p],bh);
}
void dfs1(int x)
{
    if (!vp[tp[x]].size()) sv[++tot]=tp[x];
    vis[x]=1;vp[tp[x]].push_back(x);
    for (int p=point[x];p;p=nxt[p])
     if (!vis[v[p]]) dfs1(v[p]);
}
int main()
{
  //  freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,j,n,m,k,l;
    scanf("%d%d%d",&n,&k,&l);
    memset(point,0,sizeof(point));bs=0;
    for (i=1;i<=k;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        addedge(x,y);
    }
    memset(vis,0,sizeof(vis));
    for (i=1,m=0;i<=n;i++) if (!vis[i]) dfs0(i,++m);
    
    memset(point,0,sizeof(point));bs=0;
    for (i=1;i<=l;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        addedge(x,y);
    }
    memset(vis,0,sizeof(vis));
    for (i=1,tot=0;i<=n;i++)
     if (!vis[i])
     {
          dfs1(i);
          for (j=1;j<=tot;j++)
          {
                int tp=sv[j],sz=vp[tp].size();
                for (k=0;k<sz;k++) ans[vp[tp][k]]=sz;
                vp[tp].clear();
          }
          tot=0;
     }
    
    for (i=1;i<=m;i++)
    {
        int sz=vp[i].size();
        for (j=0;j<sz;j++) ans[vp[i][j]]=sz;
    }
    for (i=1;i<n;i++) printf("%d ",ans[i]);
    printf("%d\n",ans[n]);
    
    return 0;
}


Measured memory_bytes: 15872
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int A, B, C;
	
	cin >> A >> B >> C;

	if (B<A)
	{
		cout << 0 << endl;
	}
	else
	{
		int d = B / A;
		if (d >= C)
		{
			cout << C << endl;
		}
		else
		{
			cout << d << endl;
		}
	}



	
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const INF: u32 = 1000000000;
const LINF: u64 = 1000000000000000000;

fn main(){
	let (a, b, c, d): (i32, i32, i32, i32) = (read(), read(), read(), read());
	
	let mut ans = 0;
	if a < b { ans += a; } else { ans += b; }
	if c < d { ans += c; } else { ans += d; }
	
	println!("{}", ans);
}


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

using namespace std;
typedef long long ll ;
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define pb push_back

ll p=1e9+7 ;

int main()
{
	int T=1;
	// cin >> T ;

	while(T--)
	{
		int n,m ;
		cin>>n>>m ;
		string t ;
		bool a[n][m] ;
		rep(i,0,n)
		{
			cin>>t ;
			rep(j,0,m)
			{
				if(t[j]=='.')
					a[i][j]=1 ;
				else
					a[i][j]=0 ;
			}
		}

		ll dp[n][m] ;
		dp[0][0]=1 ;

		rep(i,0,n)
		{
			rep(j,0,m)
			{
				if(i||j) dp[i][j] = 0 ;
				if(i>0)
					dp[i][j] = dp[i-1][j] ;
				if(j>0)
					dp[i][j] = (dp[i][j]+dp[i][j-1])%p ;
				if(!a[i][j])
					dp[i][j]=0 ;
			}
		}
		cout<<dp[n-1][m-1]<<endl ;
	}	
	return 0;
}

Measured memory_bytes: 12316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define H 2000000

int  parent(int);
int  left(int);
int  right(int);
void maxHeapify(int);
int  heapExtractMax(void);
void maxHeapInsert(int);
void heapIncreaseKey(int,int);

int n=0;
int A[H];

int main(){

 int i;
 int key;
 char str[8];

 while(1){
 scanf("%s",str);
 if( strcmp(str,"end")==0 ) break;

 if( strcmp(str,"insert")==0 ){
 scanf("%d",&key); 
 maxHeapInsert(key);
 }

 if( strcmp(str,"extract")==0 ){
 printf("%d\n",heapExtractMax());
 }
}

 return 0;
}

int parent(int i){
 return i / 2;
}

int left(int i){
 return 2 * i;
}

int right(int i){
 return 2 * i + 1;
}

void maxHeapify(int i){

  int l;
  int r;
  int tmp;
  int largest;

  l = left(i);
  r = right(i);

  if(l<=n && A[l]>A[i]){
    largest = l;
  }

  else{
    largest = i;
  }

  if(r<=n && A[r]>A[largest]){
    largest = r;
  }

  if(largest!=i){
    tmp = A[i];
    A[i] = A[largest];
    A[largest] = tmp;
    maxHeapify(largest);
  }
}

int heapExtractMax(void){

  int max;

  if(n < 1){
    fprintf(stderr,"heap underflow\n");
    exit(1);
  }

  max = A[1];
  A[1] = A[n];
  n--;
  maxHeapify(1);
  return max;
}

void maxHeapInsert(int key){
  n = n + 1;
  A[n] = -1;
  heapIncreaseKey(n,key);
}

void heapIncreaseKey(int i, int key){

  int tmp;
  
  if(key < A[i]){
    fprintf(stderr,"new key is smaller than current key\n");
    exit(1);
  }
  A[i] = key;
  while(i>1 && A[parent(i)] < A[i]){
    tmp = A[i];
    A[i] = A[parent(i)];
    A[parent(i)] = tmp;
    i = parent(i);
  }
}

Measured memory_bytes: 4692
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> a;
  for(int i = 0; n > i; i++){
    int tmp;cin>>tmp;
    a.push_back(tmp);
  }
  vector<int> ans;
  while(a.size()){
    int dou = -1;
    for(int i = 0; a.size() > i; i++){
      if(i+1==a[i])dou=i;
    }
    if(dou == -1){
      cout << -1 << endl;
      return 0;
    }
    ans.push_back(a[dou]);
    a.erase(a.begin()+dou);
  }
  reverse(ans.begin(),ans.end());
  for(int i = 0; ans.size() > i; i++){
    cout << ans[i] << endl;
  }
}

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

using namespace std;

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

  int x;
  cin >> x;
  int n;
  cin >> n;
  int res = 1e9;
  map<int, int> kek;
  for (int i = 0; i < n; ++i) {
    int y;
    cin >> y;
    kek[y] = 1;
  }
  for (int i = -1000; i <= 1000; ++i) {
    if (kek[i] == 0) {
      if (abs(res - x) > abs(i - x)) {
        res = i;
      } else if (abs(res - x) == abs(i - x) and res > i) {
        res = i;
      }
    }
  }
  cout << res;

  return 0;
}


Measured memory_bytes: 3744
N = int(input())
X = list(map(int, input().split()))
Y = list(enumerate(X))
Y.sort(key=lambda x:x[1])
mid = [Y[N//2-1][1], Y[N//2][1]]
ans = [-1] * N
for i, y in Y:
  if y <= mid[0]:
    ans[i] = mid[1]
  else:
    ans[i] = mid[0]

print(*ans, sep='\n')

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}

// 空のベクトルを二つ渡す。N (>=2) 以下の素数を primes に順番に入れる。
void prime_vectors(int N, vector<int>& primes, vector<bool>& is_prime){
    primes = {};
    is_prime = {};
    for(int i=0; i<=N; i++){
        is_prime.push_back(true);
    }

    primes.push_back(2);
    for(int j=4; j<=N; j+=2){
        is_prime[j] = false;
    }

    int i;
    for(i=3; i*i<=N; i+=2){
        if(!is_prime[i]) continue;
        primes.push_back(i);
        for(int j=2*i; j<=N; j+=i){
            is_prime[j] = false;
        }
    }

    for(; i<=N; i+=2){
        if(is_prime[i]){
            primes.push_back(i);
        }
    }
}

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n, m;
    cin >> n >> m;

    vector<int> s(m+1, 0);
    vector<int> k(m+1);
    for(int i=1; i<=m; i++){
        cin >> k[i];
        for(int j=1; j<=k[i]; j++){
            int sij;
            cin >> sij;
            s[i] += (1<<(sij-1));
        }
    }
    vector<int> p(m+1);
    for(int i=1; i<=m; i++){
        cin >> p[i];
    }

    int n_on = 0;
    for(int i=0; i<(1<<n); i++){
        int l;
        for(l=1; l<=m; l++){
            // 電球 l について
            int cond = __builtin_popcount(s[l] & i);
            if(cond % 2 != p[l]){
                break;
            }
        }

        if(l == m+1){
            // 全部 on だった
            n_on++;
        }
    }
    cout << n_on << endl;
    return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <stack>
#include<cstdlib>
using namespace std;

int main (){
    int n,m;
    stack<int> operand;
    string g;

    while(cin >> g){
        if (g == "+") {
            n = operand.top();
            operand.pop();
            m = operand.top();
            operand.pop();
            operand.push(m + n);
        }
        else if (g == "-") {
            n = operand.top();
            operand.pop();
            m = operand.top();
            operand.pop();
            operand.push(m - n);
        }
        else if (g == "*") {
            n = operand.top();
            operand.pop();
            m = operand.top();
            operand.pop();
            n = m * n;
            operand.push(n);
        }
        else {
            operand.push(atoi(g.c_str()));
        }
    }
    cout << operand.top() << endl;
    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;
void print() {cout << endl;}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " ";print(forward<Tail>(tail)...);}
template <class T> void print(vector<T> &vec) {for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " ";} cout << endl;}
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec);}}


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int ans = 0;
    
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    if (K<= A) {
        ans = K;
    }
    else if (K <= A+B) {
        ans = A;
    }
    else {
        ans = A-(K-A-B);
    }
    cout << ans << endl;
    
    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc167/abc167_b && sh shellscripts/test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc167/abc167_b && sh shellscripts/etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc167/abc167_b && sh shellscripts/submit_cpp.sh
*/


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;

signed main(){
  int n;
  cin >> n;
  int a = n / 1000000000;
  int b = n % 1000000000/100000000;
  int c = n % 100000000/10000000;
  int d = n % 10000000/1000000;
  int e = n % 1000000/100000;
  int f = n % 100000/10000;
  int g = n % 10000/1000;
  int h = n % 1000/100;
  int i = n % 100/10;
  int j = n % 10;
  int AAA = a + b + c + d + e + f + g + h + i + j;
  if(n % AAA == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256