akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, begin, end) for(int i = begin; i < (end); i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
 
int main(){
	int n;
	cin >> n;
  	vector<int> a(n);
  	rep(i, 0, n) cin >> a[i];
  
  	int dp[100005];
  	dp[1] = abs(a[0] - a[1]);
  
  	rep(i, 2, n){
      	int diff1 = abs(a[i] - a[i-1]);
      	int diff2 = abs(a[i] - a[i-2]);
    	dp[i] = min(abs(diff1 + dp[i-1]), abs(diff2 + dp[i-2]));
    }
  
  	cout << dp[n-1] << endl;
}	

Measured memory_bytes: 1024
#include<iostream>
#include<set>
#include<string>

using namespace std;

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

    set<string> values;
    string value;
    for (int i = 0; i < n; i++) {
        cin >> value;
        values.insert(value);
    }

    cout << values.size() << endl;
    return 0;
}


Measured memory_bytes: 15656
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main()
{
	while ( true )
	{
		int n; cin>>n;
		if ( n == 0 )
			break;
		vector<pair<int,long long> > E;

		for ( int i=0; i<n; i++ )
		{
			int a, b, c;
			cin>>a>>b>>c;
			int j;
			for ( j=0; j<(int)E.size(); j++ )
				if ( E[j].first==a )
					break;
			if ( j==(int)E.size() )
				E.push_back( make_pair(a,0ll) );
			E[j].second += (long long)b*c;
		}
		bool f = false;
		for ( int i=0; i<(int)E.size(); i++ )
			if ( E[i].second >= 1000000 )
				cout << E[i].first << endl,
				f = true;
		if ( ! f )
			cout << "NA" << endl;
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[n];
    int b[n];
    long c[n];
    vector<set<pair<int,long> > >tree(n+1);
    for(int i=0;i<n-1;i++){
        cin >> a[i]>>b[i]>>c[i];
        tree[a[i]].insert(make_pair(b[i],c[i]));
        tree[b[i]].insert(make_pair(a[i],c[i]));
    }
    int q,k;
    cin >> q >> k;
    vector<long>distance(n+1,-1);
    distance[k]=0;
    queue<int>que;
    que.push(k);
    
    long ans[q];
    int x[q];
    int y[q];
    for(int i=0;i<q;i++){
        cin >> x[i] >> y[i];
       
    }

    while(!que.empty()){
        int cur = que.front();
        que.pop();
        // cout << cur<<endl;
        for(auto j:tree[cur]){
            if(distance[j.first] == -1){
                que.push(j.first);
                distance[j.first] = distance[cur] + j.second;
                // cout << j.first<<endl;
            }
        }
    }

    for(int i=0;i<q;i++){
         ans[i] = distance[x[i]] + distance[y[i]];
    }
    for(int i=0;i<q;i++)cout<<ans[i]<<endl;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;
using T = std::tuple<int,int,int,int>;

int H, W;
int A[510][510];
std::vector<T> lg;

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

    std::cin >> H >> W;

    for(int i=1;i<=H;++i){
        for(int j=1;j<=W;++j){
            std::cin >> A[i][j];
        }
    }

    if(H == 1){
        for(int i=1;i+1<=W;++i){
            if(A[1][i] & 1){
                A[1][i] -= 1;
                A[1][i+1] += 1;
                lg.emplace_back(1, i, 1, i + 1);
            }
        }
    }else if(W == 1){
        for(int i=1;i+1<=H;++i){
            if(A[i][1] & 1){
                A[i][1] -= 1;
                A[i+1][1] += 1;
                lg.emplace_back(i, 1, i + 1, 1);
            }
        }
    }else{
        int y = 1, x = 1, dx = +1, t = 0;
        while(t < H * W - 1){
            int ny = y, nx = x + dx;
            if(nx <= 0 || nx > W){
                ny = y + 1;
                nx = x;
                dx = -dx;
            }

            if(A[y][x] & 1){
                A[y][x] -= 1;
                A[ny][nx] += 1;
                lg.emplace_back(y, x, ny, nx);
            }

            y = ny;
            x = nx;
            t += 1;
        }
    }

    printf("%d\n", (int)lg.size());

    for(auto &t : lg){
        int y1, x1, y2, x2;
        std::tie(y1, x1, y2, x2) = t;

        printf("%d %d %d %d\n", y1, x1, y2, x2);
    }
}


Measured memory_bytes: 5232
#include <stdio.h>

int main(void)
{
	int hist[101] = {}, n, i, max = 0;
	
	while(scanf("%d",&n) != EOF){
				hist[n]++;
	}
	for(i = 1;i <= 100;i++){
		if(hist[i] > max){
			max = hist[i];
		}
	}
	for(i = 1;i <= 100;i++){
		if(max == hist[i]){
			printf("%d\n",i);
		}
	}
	
	return 0;
}
	
	

Measured memory_bytes: 596
my $str = <STDIN>;
chomp $str;
my ($N, $A, $B) = split(/\s/,$str);

$str = <STDIN>;
chomp $str;

my $i = 0, $j = 0;
my $a = 0, $b = 0;

foreach (split//, $str) {
    if ($_ ne "c" && $i + $j < $A + $B) {
        if ($_ eq "a") {
            print "Yes\n";
            $i++;
            next;
        }
        if ($_ eq "b" && $j < $B) {
            print "Yes\n";
            $j++;
            next;
        } 
    }
    print "No\n";
}

Measured memory_bytes: 9600
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] x = new int[input.Length];
            int mem = 0;
            for (int i = 0; i < input.Length; i++)
            {
                x[i] = Int32.Parse(input[i]);
                if (x[i] == 0)
                {
                    mem = i+1;
                    break;
                }
            }
            Console.WriteLine(mem);
        }
    }
    
}

Measured memory_bytes: 27340
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, M = map(int, sys.stdin.readline().rstrip().split())
    PY = []
    for i in range(M):
        P, Y = map(int, sys.stdin.readline().rstrip().split())
        PY.append([Y, P, i + 1])
    PY.sort()

    # cnt: key=県, value=すでに幾つの市がその県に属しているか
    # res: [市の番号, 県の番号, 順番]
    cnt = {}
    res = []
    for y, p, i in PY:
        if p not in cnt:
            cnt[p] = 1
        else:
            cnt[p] += 1
        res.append([i, p, cnt[p]])

    res.sort()
    for i, p, x in res:
        print('{:06}{:06}'.format(p, x))


Measured memory_bytes: 80344
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int dp[31][1<<16], a[30][16], b[30][16], d1[30], d2[30];
int po[16];

int bit_cnt(int bit){
	int ans = 0;
	while(bit > 0){
		ans += bit%2;
		bit /= 2;
	}
	return ans;
}

void init(){
	fill((int*)dp, (int*)(dp+31), -INF);
	dp[0][0] = 0;
	fill(d1, d1+30, 0);
	fill(d2, d2+30, 0);
	int tmp = 0;
	po[0] = 1;
	repi(i,1,16)po[i] = po[i-1]*2;
	sort(po, po+16, greater<int>());
}

signed main(){
	while(1){
		int n, c;
		scanf("%lld%lld", &n, &c);
		if(n == 0 and c == 0)break;
		init();
		rep(i,n)rep(j,16)scanf("%lld", &a[i][j]);
		rep(i,c)rep(j,16)scanf("%lld", &b[i][j]);
		rep(i,n)rep(j,16)d1[i] += a[i][j]*po[j];
		rep(i,c)rep(j,16)d2[i] += b[i][j]*po[j];
		
		rep(i,n)rep(j,1<<16){
			if(dp[i][j] == -INF)continue;
			rep(k,c){
				int bit = j | d1[i];
				int bit2 = bit & d2[k];
				bit -= bit2;
				chmax(dp[i+1][bit], dp[i][j]+bit_cnt(bit2));
			}
		}
		
		int ans = 0;
		rep(i,1<<16)chmax(ans, dp[n][i]);
		printf("%lld\n", ans);
	}
	return 0;
}





Measured memory_bytes: 19152
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;/*10^12*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
////////////////////////////////////////

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    ll a,b,c;cin>>a>>b>>c;
    ll k;cin>>k;
    ll ans=a-b;
    if(k%2==1)ans*=-1;
    cout<<ans<<endl;
    
    return 0;
}

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

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>

////多倍長整数, cpp_intで宣言
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

#pragma gcc target ("avx2")
#pragma gcc optimization ("Ofast")
#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1e9 + 7;
constexpr long double eps = 1e-6;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int a;
	scanf("%d", &a);
	printf("%d\n", a + a* a + a* a* a);

	Please AC;
}

Measured memory_bytes: 3800
/**
*
* Author: MARS
* Lang: GNU C++14
*
**/

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

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >

typedef unsigned long long ull;
typedef long double ldbl;
typedef long long ll;
typedef double dbl;

const ldbl E = 2.71828182845904523536;
const ldbl pi = acos(-1);
const dbl eps = 1e-9;
const ll mod = 1e9+7;
const ll inf = 1LL<<30;

/** /////////// ** Code ** /////////// **/

const int N=111;
int a1[N] , a2[N];
int sum1[N] , sum2[N];

int main()
{
    int n; scanf("%d",&n);
    for(int i=1 ; i<=n ; i++){
        scanf("%d",&a1[i]);
        sum1[i]=sum1[i-1]+a1[i];
    }

    for(int i=1 ; i<=n ; i++){
        scanf("%d",&a2[i]);
        sum2[i]=sum2[i-1]+a2[i];
    }


    int ans=0;

    for(int i=1 ; i<=n ; i++){
        int x=sum1[i]+sum2[n]-sum2[i-1];
        ans=max(x,ans);
    }


    printf("%d",ans);

    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

ll comb[51][51];

void Comb() {
  for (int i = 0; i < 51; ++i) {
    for (int j = 0; j <= i; ++j) {
      if (j == 0 || i == j) {
        comb[i][j] = 1;
      } else {
        comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
      }
    }
  }
}

int main() {
  Comb();
  int n, a, b;
  cin >> n >> a >> b;
  vector<ll> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
  }
  sort(v.begin(), v.end(), greater<ll>());
  ll ans = 0;
  ll id = v[0];
  int num = 1;
  bool flag = 0;
  for (int i = 0; i < a; ++i) {
    ans += v[i];
    if (i) {
      if (id == v[i]) {
        num++;
      } else {
        id = v[i];
        num = 1;
        flag = 1;
      }
    }
  }
  int count = 0;
  for (int i = 0; i < n; ++i) {
    if (v[i] == id)
      count++;
  }
  cout << fixed;
  cout << setprecision(7) << ld(ans) / a << endl;
  if (flag)
    cout << comb[count][num] << endl;
  else {
    ll ret = 0;
    for (int i = a; i <= b; ++i) {
      ret += comb[count][i];
      if (count == i)
        break;
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 256
n = int(input())
t_score, h_score = 0, 0
for _ in range(n):
    taro, hanako = input().split()
    if taro > hanako:
        t_score += 3
    elif hanako > taro:
        h_score += 3
    else:
        t_score += 1
        h_score += 1
print(t_score, h_score)


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

char a[100010], b[100010];
int na, nb, q, s[2][2][100010];

void sum(int n, char *b, int t){
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < 2; j++) s[t][j][i] = s[t][j][i - 1];
		s[t][(b[i] == 'B')][i]++;
	}
}

int main(){
	scanf("%s%s", a + 1, b + 1);
	na = strlen(a + 1);
	nb = strlen(b + 1);
	sum(na, a, 0);
	sum(nb, b, 1);
	scanf("%d", &q);
	for(int a, b, c, d; q--; ){
		scanf("%d%d%d%d", &a, &b, &c, &d); a--; c--;
		puts(((s[0][0][b] - s[0][0][a] - s[0][1][b] + s[0][1][a] -
			   s[1][0][d] + s[1][0][c] + s[1][1][d] - s[1][1][c] + 300000) % 3) ? "NO" : "YES");
	}
}

Measured memory_bytes: 2304
#include<iostream>
using namespace std;
int main() {
	int s1, s2;
	while (cin >> s1 >> s2&&s1 != 0&&s2 != 0) {
		int a[5];
		a[0] = s1 + s2;
		for (int i = 1; i < 5; i++) {
			cin >> s1 >> s2;
			a[i] = s1 + s2;
		}
		char b;
		int max=0;
		for (int i = 0; i < 5; i++) {
			if (max<a[i])
			{
				max = a[i];
				b = (char)(int)'A' + i;
			}
		}
		cout << b <<" "<<max<< endl;
	}
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1 LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int X;cin >> X;
    if(X >= 30){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3672
#include<iostream>


#include<algorithm>
using namespace std;

long long int q, h, s, d;
long long int n;


int main() {
	long long int min;
	cin >> q >> h >> s >> d;
	cin >> n;
	long long int a[4] = { 8 * q,4 * h,2*s,d };
	sort(a, a + 4);
	if (n % 2 == 0) {
		min = (n / 2) * a[0];
	}
	else {
		if (a[0] == d) {
			min = (((n - 1) / 2) * a[0]) + (a[1] / 2);

		}
		else {
			min = (((n - 1) / 2) * a[0])+(a[0]/2);
		}
	}
	cout << min << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

int n, m, k;
ll fac[900100];
ll fnv[900100];
ll f[600100];
ll p[600100];

ll po(ll a, ll n) {
    if (!n) return 1;
    ll t = po(a,n/2);
    return t*t%MOD*(n%2?a:1)%MOD;
}

ll comb(ll n, ll r) {
    if (r<0||r>n) return 0;
    return fac[n]*fnv[r]%MOD*fnv[n-r]%MOD;
}

int main() {
    int i;
    scanf("%d%d%d",&n,&m,&k);
    fac[0] = 1; for (i=1;i<=n+m+k;i++) fac[i]=fac[i-1]*i%MOD;
    for (i=0;i<=n+m+k;i++) fnv[i]=po(fac[i],MOD-2);
    f[m+k] = comb(m+k,m); for (i=m+k-1;i>=0;i--) f[i] = (MOD+1)/2*(f[i+1]+comb(i,i-m)+comb(i,k))%MOD;
    p[0] = 1; for (i=1;i<=m+k;i++) p[i]=p[i-1]*3%MOD;
    ll ans = 0;
    for (i=0;i<=m+k;i++) ans = ans+comb(n-1+i,n-1)*p[m+k-i]%MOD*f[i]%MOD;
    printf("%lld\n",ans%MOD);

    return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <climits>
#define ll long long
#define INF INT_MAX 
using namespace std;
int main(){
	string s;
	cin >> s;
	int count[26];
	for(int i=0;i<26;i++){
		count[i] = 0;
	}
	for(int i=0;i<s.size();i++){
		count[s[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		if(count[i]%2==1){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
N = int(input())
S = input()

b = [0] * N
w = [0] * N

for i, s in enumerate(S):
    if s == "#":
        b[i] += 1
    elif s == ".":
        w[i] += 1

def accmulate(arr):
    N = len(arr)
    cs = [0]*(N+1)
    for i in range(N):
        cs[i+1] = cs[i] + arr[i]
    return cs

# [l,r)
def query(cs, l, r):
    return cs[r] - cs[l]

b = accmulate(b)
w = accmulate(w)
ans = N

for k in range(N+1):
    res = b[k] + (w[N] - w[k])
    ans = min(ans, res)
    
print(ans)

Measured memory_bytes: 20488
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
using namespace std;

struct Node{
    int key;
    Node *right,*left,*parent;
};

Node *root,*NIL;

Node *find(Node *u, int k){
    while(u!=NIL&&k!=u->key){
        if(k<u->key)u=u->left;
        else u=u->right;
    }
    return u;
}

void insert(int k){
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node *)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while(x!=NIL){
        y=x;
        if(z->key<x->key){
            x=x->left;
        }else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NIL){
        root=z;
    }else {
        if(z->key<y->key){
            y->left=z;
        }else{
            y->right=z;
        }
    }
}

void inorder(Node *u){
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preoder(Node *u){
    if(u==NIL)return;
    printf(" %d",u->key);
    preoder(u->left);
    preoder(u->right);
}
int main(){
    int i,n,x;
    string com;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        cin>>com;
        if(com[0]=='f'){
            scanf("%d",&x);
            Node *t=find(root,x);
            if(t!=NIL)printf("yes\n");
            else printf("no\n");
        }else if(com=="insert"){
            scanf("%d",&x);
            insert(x);
        }else if(com=="print"){
            inorder(root);
            printf("\n");
            preoder(root);
            printf("\n");
        }
    }
    return 0;
}



Measured memory_bytes: 26620
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define Endl endl
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)
ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll mod = 1;
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
bool isvalid(ll x,ll y,ll n, ll m) { return (x>=0&&x<n&&y>=0&&y<m); }
vector<ll>v[100011];

int main() {
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll x;
    cin>>x;

    if(x>=400 and x<=599){
        cout<<'8';

    }else if(x>=600 and x<=799){
        cout<<'7';
    }else if(x>=800 and x<=999){
        cout<<'6';

    }else if(x>=1000 and x<=1199){
        cout<<'5';
    }else if(x>=1200 and x<=1399){
        cout<<'4';
    }else if(x>=1400 and x<=1599){
        cout<<'3';
    }else if(x>=1600 and x<=1799){
        cout<<'2';
    }else{
        cout<<'1';
    }

    return 0;
}

Measured memory_bytes: 5996
N,M = map(int,input().split(' '))

An = [ input() for _ in range(N)]
Bn = [ input() for _ in range(M)]
flag = False
for i in range(N-M+1):
    for j in range(N-M+1):
        for s in range(M):
            a = An[i+s][j:j+M]
            b =Bn[s]
            if An[i+s][j:j+M] != Bn[s]:
                break
            if s == M-1:
                flag = True
print('Yes' if flag else 'No')

Measured memory_bytes: 38896
#include<stdio.h>
int main()
{
    int r,d,x,j;
    scanf("%d%d%d",&r,&d,&x);
    j=x;
    for(int i=x;i<x+10;i++)
    {
        j=r*j-d;
        printf("%d\n",j);
    }

}


Measured memory_bytes: 256
s = gets.chomp
array = s.split("").map {|c| 2**(c.ord - 97) }

ret = 0
while array.length > 1 do
    r = array[0]
    (1..(array.length-1)).each do |i|
        r = r & array[i]
        break if r == 0
    end
    if r != 0
        break
    else
        ret+=1
        next_array = []
        (0..(array.length-2)).each do |i|
            next_array.push(array[i] | array[i+1])
        end
        array = next_array
    end
end
puts ret


Measured memory_bytes: 14372
#include<iostream>
#include<string>
#include<stdio.h>
#include<cstring>
#include<math.h>
using namespace std;
int main()
{
	double d,t,m;
	cin>>d>>t>>m;
	double p=d/m;
	if(p<=t)cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 3716
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	deque<char> dq;
	rep(i,s.size()){
		if(s[i] == '0') dq.push_back('0');
		else if(s[i] == '1') dq.push_back('1');
		else{
			if(!dq.empty()) dq.pop_back();
		}
	}
	for(auto p : dq) cout << p;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

int main(){
    int N;cin>>N;
    int A[100010],cost[100010],sum=0;
    //cost[i] iからi+1に移動するコスト
    A[0]=A[N+1]=0;
    for(int i=1;i<=N;i++){
        cin>>A[i];
        cost[i-1]=abs(A[i]-A[i-1]);
        sum+=cost[i-1];
    }
    cost[N]=abs(A[N+1]-A[N]);
    sum+=cost[N];
    for(int i=1;i<=N;i++){
        if((A[i]-A[i-1])*(A[i]-A[i+1])<=0)cout<<sum<<endl;
        else cout<<sum-cost[i-1]-cost[i]+abs(A[i-1]-A[i+1])<<endl;
    }
    return 0;
}

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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
bool check(int x, vector<string>v) {
	int table[] = { 5,7,5,7,7 };
	int idx = 0, tmp = 0;
	rep(i, x, v.size()) {
		tmp += v[i].size();
		if (tmp == table[idx]) {
			idx++;
			tmp = 0;
		}
		else if (tmp > table[idx]) {
			return false;
		}
		if (idx == 5) {
			return true;
		}
	}
	return false;
}
signed main() {
	int n;
	while (cin >> n, n) {
		vector<int>v; vector<string>s; v.push_back(0);
		rep(i, 0, n) {
			string t;
			cin >> t;
			s.push_back(t);
			v.push_back(t.size());
		}
		rep(i, 1, n + 1) {
			v[i] += v[i - 1];
		}
		int ans;
		for (ans = 0; ans < n + 1; ans++) {
			rep(j, ans, n + 1) {
				int x = v[j] - v[ans];
				if (x > 31)continue;
				else if (x == 31 && check(ans, s))goto there;
			}
		}

	there:; cout << ans + 1 << endl;
		dumpc(v);

	}
	return 0;
}

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

int main(){
  int a;
  while(cin >> a, a>=0){
    vector<int> ans;
    if(a==0)ans.push_back(0);
    while(a){
      ans.push_back( a%4 );
      a/=4;
    }
    reverse(ans.begin(),ans.end());
    for(int i=0;i<(int)ans.size();i++) cout << ans[i]; cout << endl;
  }
}

Measured memory_bytes: 1212
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline



def acinput():
    return list(map(int, input().split(" ")))


S=list(input())
T=list(input())

N=len(S)-1
#print(S,N)
if S[:N]==T[:N]:
    print("Yes")
else:
    print("No")




Measured memory_bytes: 27084
#include <iostream>
#include <set>

int main()
{
  unsigned N,M;
  std::set<unsigned> islands_from_1, islands_to_N;
  std::cin >> N >> M;
  for (unsigned ii=0; ii<M; ++ii) {
    unsigned a, b;
    std::cin >> a >> b;
    if (a==1)
      islands_from_1.insert(b);
    else if (b==N)
      islands_to_N.insert(a);
  }

  for (const unsigned& a : islands_from_1) {
    if (islands_to_N.find(a) != islands_to_N.end()) {
	std::cout << "POSSIBLE" << std::endl;
	return 0;
    }
  }
  std::cout << "IMPOSSIBLE" << std::endl;
  
  return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  cin.tie(0); 

  string s;
  for (int i = 0; i < 3; ++i) {
    string a;
    cin >> a;
    s += toupper(a[0]);
  }
  cout << s << "\n";
}


Measured memory_bytes: 3568
#include <iostream>
#include <stdio.h>
#include <utility>

#define MAX_N 100

void select_sort(int*,int);

int A[MAX_N+1];
int count_swap = 0;


int main(){
    int n;
    scanf("%d",&n);
    for(int i = 0; i < n; i++){
        scanf("%d",&A[i]);
    }
    select_sort(A,n);
    for(int i = 0; i < n; i++){
        if(i<(n-1))printf("%d ",A[i]);
        if(i == (n-1)) printf("%d\n",A[i]);
    }
    printf("%d\n",count_swap);
    
}

void select_sort(int* a,int n){
    for(int i = 0; i < (n-1); i++){
        int a_min = MAX_N;
        int a_min_idx = MAX_N + 1;
        //A[a_min_idx] = MAX_N + 1;
//        printf("A[a_min_idx]'s address %d count_swap's address %d\n",&A[a_min_idx],&count_swap);//why do those two addresses become same?
        for(int j = i+1; j <n; j++){
            if(A[j] < a_min){
                a_min = A[j];
                a_min_idx = j;
            }
        }
        if(A[i] > A[a_min_idx]){
            std::swap(A[i],A[a_min_idx]);
            count_swap++;
        }

    }
}

Measured memory_bytes: 3188
<?php
list($n, $m, $k) = ints();
for ($i = 0; $i <= $n; ++$i) {
    for ($j = 0; $j <= $m; ++$j) {
        $cnt = $i * $m + $j * $n - 2 * $i * $j;
        if ($cnt === $k) exit('Yes');
    }
}
echo 'No';
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16192
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,m = map(int,readline().split())
mod = 10**9+7

class Combination:
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        f = 1
        self.fac = fac = [f]
        for i in range(1, n_max+1):
            f = f * i % mod
            fac.append(f)
        f = pow(f, mod-2, mod)
        self.facinv = facinv = [f]
        for i in range(n_max, 0, -1):
            f = f * i % mod
            facinv.append(f)
        facinv.reverse()

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def C(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def P(self, n, r):
        if not 0 <= r <= n: return 0
        return self.fac[n] * self.facinv[n-r] % self.mod
      
f = Combination(m, mod)
ans = 0
for k in range(m+1):
  chk = f.C(n,k)*f.P(m,k)*pow(f.P(m-k,n-k),2,mod)%mod
  ans += pow(-1,k)*chk
  ans %= mod
print(ans)

Measured memory_bytes: 119644
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int res = 0;
	int n, t;
	vector <int> p;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		cin >> t;
		p.push_back(t);
	}

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

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 384
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;



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

	cin >> N;
	vector<char>c(N);
	vector<int>v(N);
	vector<pair<int, int>>vp;
	for (int i = 0; i < N; i++) {
		cin >> c[i] >> v[i];
		if (c[i] == 'y') {
			vp.push_back({ v[i],i });
		}
	}
	int ans = 0;
	sort(vp.begin(), vp.end());
	vector<int>used(N);
	for (auto i : vp) {
		if (used[i.second])continue;
		ans++;
		int l = i.second, r = i.second;
		while (l>=0) {
			if (v[l] >= i.first&&c[l]=='y') {
				used[l] = 1;
				l--;
				continue;
			}
			else if (v[l] >= i.first&&c[l] == 'n') {
				break;
			}
			else {
				l--;
			}
		}
		while (r < N) {
			if (v[r] >= i.first&&c[r] == 'y') {
				used[r] = 1;
				r++;
				continue;
			}
			else if (v[r] >= i.first&&c[r] == 'n') {
				break;
			}
			else {
				r++;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
using namespace std;

int main(){
	while(1){
		int m[5],a[5];
		cin>>m[0]>>a[0];
		if(m[0]==0&&a[0]==0) break;
		rep(i,1,5) cin>>m[i]>>a[i];
		pair<int,int> data[5];
		rep(i,0,5){
			data[i].first=m[i]+a[i];
			data[i].second=i;
		}
		sort(data,data+5);
		char c='A'+data[4].second;
		cout<<c<<" "<<data[4].first<<endl;
	}
}

Measured memory_bytes: 1160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;

struct Compare
{
	bool operator()(const pint& a, const pint& b)
	{
		return a.first > b.first
			|| a.first == b.first && a.second < b.second;
	}
};
int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m), n|m)
	{
		pint p[100];
		for (int i = 0; i < m; ++i)
			p[i] = pint(0, i+1);
		while (n--)
		{
			for (int i = 0; i < m; ++i)
			{
				int t;
				scanf("%d", &t);
				p[i].first += t;
			}
		}
		sort(p, p+m, Compare());
		for (int i = 0; i < m-1; ++i)
			printf("%d ", p[i].second);
		printf("%d\n", p[m-1].second);
	}
}

Measured memory_bytes: 888
#include<cmath>
#include<iostream>
#include<algorithm>
#include <string>
#include <stdexcept>
using namespace std; 
int main(){
  int a,b,c,d,e;
 	cin >>a;
 if(a%2==0) cout << a*(a-1)/2-(a/2*(a/2-1));
  else cout << a*(a-1)/2-((a-1)/2*(((a-1)/2)-1))/2-((((a-1)/2)+1)*(a-1)/2)/2;
  	
  
}

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

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

  set<string> dict;
  for(int i=0;i<n;i++){
    string command, word;
    cin >> command;
    if(command=="insert"){
      cin >> word;
      dict.insert(word);
    }else{
      cin >> word;
      if(dict.count(word)>0) cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 32128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
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 FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n, k;
    cin >> n >> k;
    int ans = k;
    REP(i,n-1) ans *= k-1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int INF = 2000000000;
const ll mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int main(){
	int N; cin >> N;
	if(N%1000==0) cout << 0 << endl;
	else cout << 1000-(N%1000) << endl;
	return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define ALL(obj) (obj).begin(),(obj).end()

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

vector<int> dy = { 0,0,1,-1 };
vector<int> dx = { 1,-1,0,0 };

template<class T> void corner(bool flg, T hoge) {
	if (flg) {
		cout << hoge << endl;
		exit(0);
	}
	else return;
}

template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {
	o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;
}

template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

void YN(bool flg) {
	cout << ((flg) ? "YES" : "NO") << endl;
}

void Yn(bool flg) {
	cout << ((flg) ? "Yes" : "No") << endl;
}

void yn(bool flg) {
	cout << ((flg) ? "yes" : "no") << endl;
}

int main() {
	ll N, M; cin >> N;
	M = (ll)pow(2, N);
	V<ll> A(M),ans(M,0); REP(i, M) cin >> A[i];
	V<P<ll, ll>> dp(M);
	REP(i, M) dp[i] = { i,0 };
	for(int i = 0; i < M-1; ++i){
		for(int j = 0; j < N; ++j){
			if (i & (1 << j)) continue;
			int k = i ^ (1 << j);
			map<int, int> mp;
			mp[dp[i].first] = 1;
			mp[dp[i].second] = 1;
			mp[dp[k].first] = 1;
			mp[dp[k].second] = 1;
			V<P<ll, int>> ord;
			for (auto u : mp) ord.push_back({ A[u.first],u.first });
			sort(ALL(ord),greater<P<ll,int>>());
			dp[k] = { ord[0].second,ord[1].second};
		}
	}
	FOR(i, 1, M) ans[i] = A[dp[i].first] + A[dp[i].second];
	FOR(i, 1, M) ans[i] = max(ans[i], ans[i - 1]);
	FOR(i, 1, M) cout << ans[i] << endl;
	

	return 0;
}



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

void maxHeapify(int i,vector<ll> &array){
    int n = array.size() - 1;
    int li = 2 * i,ri = 2 * i +1,large_index=i;
    if(li <= n && array.at(li) > array.at(i)){
        large_index = li;
    }
    if(ri <= n && array.at(ri) > array.at(large_index)){
        large_index = ri;
    }
    if(large_index != i){
        swap(array.at(i),array.at(large_index));
        maxHeapify(large_index,array);
    }
}

void insert(ll key,vector<ll> &array){
    array.push_back(key);
    int i = array.size() - 1;
    while(i > 1 && array.at(i) > array.at(i / 2)){
        swap(array.at(i),array.at(i/2));
        i = i/2;
    }
}

int extract(vector<ll> &array){
    if(array.size() < 2) return -1;
    int n = array.size() - 1;
    ll max = array.at(1);
    array.at(1) = array.at(n);
    array.pop_back();
    maxHeapify(1,array);
    return max;
}

int main(){
    vector<ll> array(1,0);
    while(true){
        string s;
        cin >> s;
        if(s == "insert"){
            //cout << "!!!" << endl;
            int num;
            cin >> num;
            insert(num,array);
        }
        if(s == "extract"){
            int m = extract(array);
            if( m != -1) printf("%d\n",m);
        }
        if(s == "end") break;
    }
}


Measured memory_bytes: 11108
using System;
using System.Collections.Generic;
using System.Linq;

public static class Solution
{
    public static void Main()
    {
        var s = Console.ReadLine();
        int max = 0;
        int count = 0;
        foreach (var c in s)
        {
            if (c == 'R')
            {
                count++;
            }
            else
            {
                count = 0;
            }

            max = Math.Max(max, count);
        }

        Console.WriteLine(max);
    }
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define max(a, b) (a>b?a:b)

int main() {
	int n, Q, c, q;
	set<int> card;
	cin >> n >> Q;
	rep(i, n) {
		cin >> c;
		card.insert(c);
	}
	int ma = *(--card.end());
	rep(i, Q) {
		cin >> q;
		
		if(q==1) {
			cout << "0" << endl;
			continue;
		}
		int ans = 0;
		for(int s=q; s<ma+q; s+=q) {
			set<int>::iterator it = card.lower_bound(s);
			if(it!=card.begin()) {
				int val = *(--it) % q;
				ans = max(ans, val);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
	int N;
	string S;
	cin >> N >> S;
	int count_r = 0;
	int count_g = 0;
	int count_b = 0;
	for(int i = 0; i < N; i++) {
		if(S[i] == 'R') { count_r++; }
		if(S[i] == 'G') { count_g++; }
		if(S[i] == 'B') { count_b++; }
	}
int64_t sum = count_r * count_g * count_b;
	for(int i = 0; i < N; i++) {
		for(int j = i + 1; j + (j - i) < N; j++) {
			int k = j + (j - i);
			if(S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) {
				sum--;
			}
		}
	}
	cout << sum << endl;
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 107;

int n, x;
int a[MAXN];

void init ();
void input ();
void work ();



int main ()
{
	init ();
	input ();
	work ();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	cin >> n >> x;
	lpi ( i, 1, n ) cin >> a[i];
}

void work ()
{
	// main work

	sort ( a + 1, a + 1 + n );

	int ans = 0;
	lpi ( i, 1, n ) {
		if ( a[i] > x ) break;
		x -= a[i];
		++ans;
	}
	if ( ans == n && x ) --ans;

	cout << ans << endl;
}

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

rnum=s.count("R")
gnum=s.count("G")
bnum=s.count("B")

#３つがすべて違う組の数

dif=rnum*gnum*bnum

#どれか２つ以上が同じ組の数

two=n*(n-1)*(n-2)//6-dif
# print(dif)
# print(two)
#j-i=k-jの組
straid=0
samax=n//2

for i in range(1,samax+1):
    for j in range(n-2*i):
        a=list(s[j:j+2*i+1:i])
        a.sort()
        if a==["B","G","R"]:
            straid+=1
            
# print(straid)
ans=two+straid
print(n*(n-1)*(n-2)//6-ans)


Measured memory_bytes: 68812
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll N= 5e5+2;
vector<ll>st[4*N+2];
ll n,m;
string s;

void build(ll node, ll L, ll R)
{
	if(L==R)
	{
		for(ll i=0;i<26;i++)
		{
			st[node][i]=0;
		}
		st[node][s[L]-'a']++;
		return;
	}
	ll M=(L + R)/2;
	build(node*2, L, M);
	build(node*2 + 1, M + 1, R);
	for(ll i=0;i<26;i++)
	{
		st[node][i]=st[node*2][i] + st[2*node+1][i];
	}
	return ;
}

vector<ll> Query(ll node, ll L, ll R, ll i, ll j)
{
	vector<ll>em(26,0);
	if(j<L || i>R)
		return em;
	if(i<=L && R<=j)
		return st[node];
	ll M = (L + R)/2;
	vector<ll> left=Query(node*2, L, M, i, j);
	vector<ll> right=Query(node*2 + 1, M + 1, R, i, j);
	vector<ll> cur(26,0);
	for(ll ii=0;ii<26;ii++)
	{
		cur[ii]=left[ii]+right[ii];
	}
	return cur;
}

void pUpdate(ll node, ll L, ll R, ll pos, ll val)
{
	if(L == R)
	{
		st[node][s[L]-'a']--;
		s[L]=val;
		st[node][s[L]-'a']++;
		return;
	}
	ll M = (L + R)/2;
	if(pos <= M)
		pUpdate(node*2, L, M, pos, val);
	else
		pUpdate(node*2 + 1, M + 1, R, pos, val);
	for(ll i=0;i<26;i++)
	{
		st[node][i]=st[node*2][i] + st[2*node+1][i];
	}
	return ;
}


int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	cin>>n;
 	cin>>s;
 	for(ll i=0;i<=4*n;i++)
 	{
 		st[i].assign(26,0);
 	}
 	build(1,0,n-1);
 	cin>>m;
 	for(ll i=0;i<m;i++)
 	{
 		
 		ll t;
 		cin>>t;
 		// cerr<<t<<endl;
 		if(t==1)
 		{
 			ll x;
 			char y;
 			cin>>x>>y;
 			pUpdate(1,0,n-1,x-1,y);
 		}
 		else
 		{
 			ll x,y;
 			cin>>x>>y;
 			ll f=0;
 			vector<ll>ans=Query(1,0,n-1,x-1,y-1);
 			for(ll xx:ans)
 			{
 				if(xx>0)f++;
 			}
 			cout<<f<<endl;
 		}
 		//cerr<<i<<endl;
 	}
    return 0;
}

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

int main(){
    long long n;
    long long median;

    cin >> n;

    median = n/2;

    long long x;
    vector <long long> v;
    vector <long long> result;

    for(long long i = 0; i < n; i++){
        cin >> x;
        v.push_back(x);
    }

    vector <long long> v_copy;

    long long median_v;

     v_copy = v;
     sort(v_copy.begin(), v_copy.end());

    for(long long i = 0; i < v.size(); i++){


        x = v[i];
       
        median_v = v_copy[median-1];
        if(x <= median_v){
            result.push_back(v_copy[median]);
        }
        else{
            result.push_back(v_copy[median-1]);
        }
    }

    for(long long i = 0; i < result.size(); i++){
        printf("%lld\n", result[i]);
    }
    

}

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

int main(){
	int N; cin>>N;
	vector<int> A(N); rep(i, N) cin>>A[i];
	int r = 0, n = *max_element(A.begin(), A.end());
	int half = n/2;
	rep(i, N){
		if(A[i] == n) continue;
		if(abs(half - r) > abs(half - A[i])) r = A[i];
	}
	cout<< n <<" "<< r <<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string a,b,c;
int main()
{
	cin>>a>>b;
	for(int i=0;i<a.size()+b.size();i++)
	{
		c+=a[i];
		c+=b[i];
	}
	for(int i=0;i<a.size()+b.size();i++)cout<<c[i];
	cout<<endl;

	
	return 0;
}

Measured memory_bytes: 256