akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using db = double;
using vi = vector<int>;
#define pb push_back
#define fir first
#define sec second

const ll mod = 998244353; 

const int maxn = 10006; 

ll f[2][maxn]; 
char a[maxn], b[maxn]; 
ll fac[maxn*2]; 
ll ifac[maxn*2]; 
ll inv[maxn*2]; 

ll C(int x, int y) {
	return fac[x] * ifac[y] % mod * ifac[x-y] % mod; 
}

int main() {
	scanf( "%s", a ); 
	scanf( "%s", b ); 
	int n = strlen(a); 
	int s1=0, s2=0; 
	for (int i = 0; i < n; ++i) 
		if (a[i] == '1') {
			if (b[i] == '1') s1++; 
			else s2++; 
		}
	inv[1] = fac[0] = fac[1] = ifac[0] = ifac[1] = 1; 
	for (int i = 2; i <= n*2; ++i) {
		inv[i] = mod / i * (mod - inv[mod % i]) % mod; 
		fac[i] = fac[i-1] * i % mod; 
		ifac[i] = ifac[i-1] * inv[i] % mod; 
	}
	memset(f, 0, sizeof(f)); 
	f[0][0] = 1; 
	int t = 0; 
	for (int i = 1; i <= s2; ++i) f[0][i] = f[0][i-1]*i*i % mod; 
	ll ans = f[0][s2] * C(s1+s2,s2) % mod * fac[s1] % mod * fac[s1] % mod; 
	//cout<<s1<<' '<<s2<<' '<<C(s1+s2,s2)<<' '<<ans<<endl; 
	for (int i = 1; i <= s1; ++i) {
		t = 1-t; 
		f[t][0] = 0; 
		for (int j = 1; j <= s2; ++j) {
			f[t][j] = (f[1-t][j]*i*j + f[t][j-1]*j*j) % mod; 
			//printf( "f[%d][%d]=%lld\n",i,j,f[t][j]); 
		}
		ans = (ans + f[t][s2] * C(s1+s2,i+s2) % mod * C(s1,i) % mod * fac[s1-i] % mod * fac[s1-i] % mod) % mod; 
	}
	cout<<ans<<endl; 
}


Measured memory_bytes: 896
#include<cstdio>
#include<cstring>
using namespace std;
char a[55],b[55];
int main()
{
	scanf("%s",a);
	scanf("%s",b);
	int pre=60;
	for(int i=0;i<strlen(a);i++)
	{
		int pd=1;
		for(int j=0;j<strlen(b);j++)
		    if(a[i+j]!=b[j]&&a[i+j]!='?'){pd=0;break;}
		if(pd)pre=i;
	}
	if(pre==60)printf("UNRESTORABLE");
	else 
	{
		for(int i=0;i<strlen(b);i++)
		    a[pre+i]=b[i];
		for(int i=0;i<strlen(a);i++)
		    if(a[i]=='?')a[i]='a';
		for(int i=0;i<strlen(a);i++)
		    printf("%c",a[i]);
	}
}


Measured memory_bytes: 128
import sys
import math

N = int(input())
S = input()
ans = 0

for i in range(10):
    a = S.find(str(i))
    if a == -1:
        continue
    for j in range(10):
        b = S.find(str(j), a+1)
        if b == -1:
            continue
        for k in range(10):
            if S.find(str(k), b+1) != -1:
                ans += 1


print(ans)

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

void solve()
{
    int n; cin >> n;
    if(n == 0)
    {
        cout << "1" << endl;
    }
    else
    {
        cout << "0" << endl;
    }
}
int main()
{
   solve();
    return 0;
}


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

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


Measured memory_bytes: 3056
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define E end()
#define B begin()
#define sz size()
#define EM empty()
#define fi first
#define se second
#define cl clear()
#define sqr(a) (a*a)
#define mk make_pair
#define pb push_back
string en="\n";
string sp=" ";
string t="hello";
string Y="YES\n";
string N="NO\n";
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define peR(i,n) for(i=n;i>0;i--)
#define mem(a,b) memset(a,b,sizeof(a))
#define all(cont) cont.begin(),cont.end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<long long>
#define vs  vector<string>
#define MX LLONG_MAX
#define MN LLONG_MIN
#define MOD 1000000007
#define vp(vi,x) cin>>x; vi.pb(x);
#define bsearch(a,x) binary_search(all(a),x)
#define LB(a,x) (lower_bound(all(a),x)-a.B)
#define UB(a,x) (upper_bound(all(a),x)-a.B)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
bool isprm(LL a){for(LL i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
bool palin(string a){for(int i=0;i<a.sz;i++){if(a.at(i)!=a.at(a.sz-i-1))return 0;} return 1;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
LL bpow(LL a,LL b){if(b==0)return 1;LL r=bpow(a,b/2);if(b%2)return r*r*a;else return r*r;}
LL binpow(LL a,LL b){LL r=1;while(b>0){if(b&1)r=r*a;a=a*a;b>>=1;}return r;}
LL binpow(LL a,LL b,LL m){a%=m;LL r=1;while(b>0){if(b&1) r=r*a%m;a=a*a%m; b>>=1;}return r;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,p,q,a,b,c=0;
    bool f=0,ff=0;
    string st;
    char ch;
    while(cin>>st)
    {
        f=0;
        map<char,int>mp;
        stringstream ss(st);
        while(ss>>ch)mp[ch]++;
        for(auto it=mp.B;it!=mp.E;it++)
        {
            x=it->se;
            if(x%2)
            {
                f=1;
                break;
            }
        }
        if(f)cout<<"No"<<en;
        else cout<<"Yes"<<en;
    }
}




Measured memory_bytes: 3620
x1, y1, x2, y2 = tuple(map(int, input().split()))

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x3 - (y3 - y2)
y4 = y3 + (x3 - x2)

print(x3, y3, x4, y4)

Measured memory_bytes: 9068
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<vector<int>> X(N, vector<int>(3));
    REP(i, N) {
        REP(j, 3) {
            cin >> X[i][j];
        }
    }
    int pt = 0, px = 0, py = 0;
    REP(i, N) {
        int dt = X[i][0] - pt;
        int d = abs(X[i][1] - px) + abs(X[i][2] - py);
        if (dt < d || dt % 2 != d % 2) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    int a,b,c,d;
    string ans ;
    cin >> a >> b;
    if (a>8 || b>8) {
        ans = ":(";
    }else{
        ans = "Yay!";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	unsigned long long a, b, x;
	cin >> a >> b >> x;
	if (a != 0)
		cout << (b / x) - ((a-1) / x) << endl;
	else
		cout << b / x - a / x + 1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
   int y,m,d;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int sum=0;
    cin>>y>>m>>d;
    for(;d<=19;d++)sum++;
    if(m%2==1||y%3==0){sum++;}
    for(;m<10;m++){
      sum+=19;
      if(y%3==0||m%2==0)sum++;
    }
    for(y++;y<1000;y++){
      sum+=195;
      if(y%3==0)sum+=5;
    }
    cout<<sum<<endl;
  }
}

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

int main()
{
  string S;cin>>S;
  for(int i=1;i<S.size();i++)
  {
    bool check=true;
    if((S.size()-i)%2==1)continue;
    for(int j=0;j<(S.size()-i)/2;j++)if(S[j]!=S[j+(S.size()-i)/2])check=false;
    if(check){printf("%d",S.size()-i);return 0;}
  }
}

Measured memory_bytes: 3720
#include <iostream>
#include <array>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

#include <atcoder/maxflow>

using namespace std;
using namespace atcoder;
#define rep(i,l,r) for(int i = l; i < r; ++i)

int main() {
    int n, m, s, t, x;
    cin >> n >> m;
    s = n * m;
    t = s + 1;

    mf_graph<int> mf(t + 1);
    vector<string> str(n);
    rep(i,0,n) cin >> str[i];

    rep(i, 0, n) {
        rep(j, 0, m) {
            x = i * m + j;
            if((i + j) % 2 == 0) {
                mf.add_edge(s, x, 1);
            } else {
                mf.add_edge(x, t, 1);
            }
        }
    }

    rep(i, 0, n) {
        rep(j, 0, m) {
            x = i * m + j;
            if ((i + j) % 2 == 1 || str[i][j] == '#') continue;

            if (i > 0 && str[i-1][j] == '.') mf.add_edge(x, x - m, 1);
            if (j > 0 && str[i][j-1] == '.') mf.add_edge(x, x - 1, 1);
            if (i < n - 1 && str[i+1][j] == '.') mf.add_edge(x, x + m, 1);
            if (j < m - 1 && str[i][j+1] == '.') mf.add_edge(x, x + 1, 1);
        }
    }

    cout << mf.flow(s, t) << endl;
    auto edge = mf.edges();
    for (auto e : edge) {
        if (e.from == s || e.to == t || e.flow == 0) continue;

        int from_i = e.from / m, from_j = e.from % m;
        int to_i = e.to / m, to_j = e.to % m;

        if (from_i == to_i) {
            if (from_j > to_j) swap(from_j, to_j);
            str[from_i][from_j] = '>';
            str[to_i][to_j] = '<';
        } else {
            if (from_i > to_i) swap(from_i, to_i);
            str[from_i][from_j] = 'v';
            str[to_i][to_j] = '^';
        }
    }

    for (auto e : str) cout << e << endl;
}


Measured memory_bytes: 5284
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		myMaxHeap heap=new myMaxHeap();
		
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			 char odr[]=in.next().toCharArray();
			 
			 if(odr[0]=='e' && odr[1]=='n')break;
			 else if(odr[0]=='i')heap.add(Integer.parseInt(in.next()));
			 else {
				 out.println(heap.remove());
			 }
		}
		in.close();
		out.flush();

	}

}

class myMaxHeap{
	private int size=0,array[]=new int[2000001];

	myMaxHeap() {

	}


	/*----Insert----*/
	public void add(int v) {
		size++;
		array[size]=v;
		
		formatWhenInsertion(size);
	}
	
	private void formatWhenInsertion(int i) {
		int nxt=i/2;
		
		if(nxt>=1 && array[i]>array[nxt]) {
			int tt=array[nxt];
			array[nxt]=array[i];
			array[i]=tt;
			
			formatWhenInsertion(nxt);
		}
	}
	
	
	/*----extract----*/
	public int remove() {
		int res=array[1];
		
		array[1]=array[size];
		size--;
		tailor(1);
		return res;
	}
	
	
	/*----sort----*/
	public void build() {
		for(int i=size/2;i>=1;i--) {
			tailor(i);
		}
	}

	private void tailor(int i) {
		int indexL=i*2,indexR=i*2+1,max=i;

		if(indexL<=size && array[indexL] > array[max])max=indexL;
		if(indexR<=size && array[indexR] > array[max])max=indexR;

		if(max!=i) {
			//System.out.println("swap "+array[max]+" "+array[i]);
			int tt=array[i];
			array[i]=array[max];
			array[max]=tt;

			tailor(max);
		}
	}

	
	/*----print----*/
	public void dump(PrintWriter out) {
		for(int i=1;i<=size;i++)out.print(" "+array[i]);
		out.println();
		out.flush();
	}


}


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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    string s, x = "keyence";
    cin >> s;

    for (int i = 1; i < x.length(); i++) {
        string a = x.substr(0, i), b = x.substr(i);
        bool f = 1;
        for (int j = 0; j < a.length(); j++)
            if (s[j] != a[j])
                f = 0;
        if (f) {
            for (int j = 0; j < b.length(); j++)
                if (b[j] != s[s.length() - b.length() + j])
                    f = 0;
            if (f) {
                cout << "YES\n";
                return 0;
            }
        } else {
            continue;
        }
    }
    cout << "NO\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define INF 2000000000
    typedef long long int ll;
    typedef pair<ll,ll> ii;
    typedef pair<ii,ll> iii;
    typedef vector<ll> vi;
    typedef vector<ii> vii;
    #define getbit(n,i) (((n)&(1<<(i)))!=0)
    #define setbit0(n,i) ((n)&(~(1<<(i))))
    #define setbit1(n,i) ((n)|(1<<(i)))
    #define togglebit(n,i) ((n)^(1<<(i)))
    #define lastone(n) ((n)&(-(n)))
    #define read freopen("debug\\in.txt","r",stdin)
    #define write freopen("debug\\out.txt","w",stdout)
    #define fi first
    #define se second
    #define getI(a) scanf("%d",&a)
    #define getII(a,b) scanf("%d%d",&a,&b)
    #define PI (acos(-1))
    #define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
    #define mod (1000000007)
    #define asz 500005
    #define pb push_back
    #define ppf pop_front
    #define ppb pop_back
    #define pf push_front
    vector<ll>primes;
    vector<ll>res;
    ll validity[3000000];
    ll nofprimes[3000000];
    bool status[2750139];
    ll b[3000000];
    void siv()
   {
	int N=2750133;
	int sq=sqrt(N);
	for(ll i=4;i<=N;i+=2) status[i]=1;
	for(ll i=3;i<=sq;i+=2){
		if(status[i]==0)
		{		
			for(int j=i*i;j<=N;j+=i) status[j]=1;
		}
	}
	status[1]=1;
	for(ll i=2;i<=N;i++){
		if(status[i]==0){
			primes.pb(i);
		}
	}
	ll sz=primes.size();
	for(ll i=0;i<sz;i++){
		nofprimes[primes[i]]=i+1;
	}
   }
    int main()
    {
        fastread;
        ll n,i,j,k,l;
        //int n;
        cin>>n;
        cout<<pow(n,3LL);
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define ppll pair <pll, pll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
int main(){
	fastio; string s; cin >> s;
	for (ll i = 0; i<s.length(); i++) cout << "x";
	return 0;	
}

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

int main() {
	int n;
	cin>>n;
	vector<int>a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	map<long long,long long>m;
	m[0]=1;
	long long sum=0;
	for(int i=0;i<n;i++){
		sum+=a[i];
		m[sum]++;
	}
	long long ret=0;
	for (auto& x:m) {
        ret+=x.second*(x.second-1)/2;
    }
	cout<<ret<<endl;
	return 0;
}

Measured memory_bytes: 13568
#include<iostream>
#include<cstring>
using namespace std;
int tot[3];
int two(int n){
	int res=0;
	while(n && n%2==0) res++,n/=2;
	if (res<=1) return res;
	return 2;
}
int main(){
	int n,a;
	cin>>n;
	if(n==0){puts("No");return 0;}
	for(int i=1;i<=n;++i){
		cin>>a;
		tot[two(a)]++;
	}
	if(tot[1]==0){
		if(tot[2]>=n/2)puts("Yes");
		else puts("No");
	}else{
		if(tot[2]>=(n-tot[1]+1)/2)puts("Yes");
		else puts("No");
	}
	return 0;
} 


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

int main(){
  ll h;
  cin >> h;
  ll res=0;
  int c = 0;
  while(h!=0){
    //cout << h << c << endl;
    res+=pow(2,c);
    c++;
    h /= 2;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      int ctr_rt = 0;
      int ctr_ac = 0;
      int ctr_ob = 0;
      boolean loop = true;
      while(loop && sc.hasNext()) {
         String[] input = sc.nextLine().split(" ");
         int[] temp = new int[3];
         
         temp[0] = Integer.parseInt(input[0]);
         temp[1] = Integer.parseInt(input[1]);
         temp[2] = Integer.parseInt(input[2]);
         
         Arrays.sort(temp);
         
         int a = temp[0];
         int b = temp[1];
         int c = temp[2];
         
         
         if (c >= a + b ) {
            int total = ctr_rt + ctr_ac + ctr_ob;
            System.out.println(total + " " +
                         ctr_rt + " " +
                         ctr_ac + " " +
                         ctr_ob);
            loop = false;
            break;
         } else if(c * c == a * a + b * b) {
            ctr_rt ++;
         } else if (c * c > a * a + b * b) {
            ctr_ob ++;
         } else {
            ctr_ac ++;
         }
      }
      
   }
}


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

vector<int> path, cycle;
map<int, bool> mp;

int main() {
    long long n, k; cin >> n >> k;
    int a[n + 1] = {}; 
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; 1; i = a[i]) {
        if (!mp[a[i]]) {
            path.push_back(a[i]);
            mp[a[i]] = true;
        } else {
        	bool flag = false;
        	for (int j : path) {
        		if (j == a[i]) flag = true;
        		if (flag) cycle.push_back(j);
        	}
        	break;
        }
    }
    if (k <= path.size()) cout << path[k - 1];
    else {
        k -= path.size();
        k %= cycle.size();
        cout << cycle[(k - 1 + cycle.size()) % cycle.size()];
    }
}


Measured memory_bytes: 14972
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
const int MAX_N=15;
const ll INF=1e18;	
using namespace std;
int N,K;
ll a[MAX_N];
int main(){
	cin>>N>>K;
	REP(i,N)cin>>a[i];
	ll ans=INF;
	REP(bit,1<<(N-1)){
		int cnt=1;
		ll h=a[0],sm=0;
		REP(j,N-1){
			if((bit>>j)&1){
				sm+=max(h+1-a[j+1],0ll);
				cnt++;
				h=max(a[j+1],h+1);
			}else{
				h=max(a[j+1],h);
			}
			
		}
		if(cnt>=K){
			ans=min(ans,sm);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int N, A[1 << 18], B[1 << 18], col[1 << 18];
bool used[1 << 18];
vector<pair<int, int>> X[1 << 18];

void dfs(int pos, int precol) {
	used[pos] = true;

	int ret = 0;
	for (int i = 0; i < X[pos].size(); i++) {
		if (used[X[pos][i].first] == true) continue;
		ret++;
		if (ret == precol) ret++;
		col[X[pos][i].second] = ret;
		dfs(X[pos][i].first, ret);
	}
}

int main() {
	cin >> N;
	for (int i = 1; i <= N - 1; i++) {
		cin >> A[i] >> B[i];
		X[A[i]].push_back(make_pair(B[i], i));
		X[B[i]].push_back(make_pair(A[i], i));
	}
	dfs(1, 0);

	int maxn = 0;
	for (int i = 1; i <= N - 1; i++) maxn = max(maxn, col[i]);
	cout << maxn << endl;
	for (int i = 1; i <= N - 1; i++) cout << col[i] << endl;
	return 0;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h> 
using namespace std; 
#define ll int long long
int pa(string s)
{
    ll n=s.size();
    if(n==1)
    return true;
    ll i=0;
    while(1)
    {
        if(s[i]==s[n-i-1])
        i++;
        else
        break;
        if((i==n-i-1&&n%2!=0)||(i==n-i&&n%2==0))
        {
            
            return true;
        }
    }
    return false;
}

int main()
{
    string s;
    cin>>s;
    ll n=s.size();
   
    string s1 = s.substr(0,(n-1)/2);
 
    
    string s2=s.substr((n+1)/2,(n-1)/2);
   
    if(pa(s)&&pa(s1)&&pa(s2))
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    
}













Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a,x;
        
        x = sc.nextInt();
        a = sc.nextInt();
        
        if(x < a){
            System.out.println(0);
        }else{
            System.out.println(10);
        }
        
    }
}


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

int main(void){
    int n,m;
    cin>>n>>m;
    vector<ll> x(n),y(n),z(n);
    rep(i,n) cin>>x[i]>>y[i]>>z[i];
    int s[2] = {-1,+1};
    ll res = -1e10;
    rep(sx,2)rep(sy,2)rep(sz,2){
        vector<ll> v;
        rep(i,n){
            v.push_back(x[i]*s[sx] + y[i]*s[sy] + z[i]*s[sz]);
        }
        sort(all(v),greater<ll>());
        res = max(res,accumulate(v.begin(),v.begin()+m,0LL));
    }
    cout<<res<<endl;
    return 0;
}


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

pub fn read_from<T: FromStr, R: Read>(s: &mut R) -> T {
    let s = s.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    if !s.is_empty() {
        if let Ok(s) = s.parse::<T>() {
            s
        } else {
            panic!("faild to parse {}", s);
        }
    } else {
        if cfg!(local) {
            // eprintln!("reached to EOF");
        }
        std::process::exit(0)
    }
}

fn main() {
    let stdin = stdin();
    let mut stdin = stdin.lock();

    loop {
        let h: usize = read_from(&mut stdin);
        let w: usize = read_from(&mut stdin);
        let g: Vec<Vec<i32>> = (0..h).map(|_| (0..w).map(|_| {
            read_from(&mut stdin)
        }).collect()).collect();

        let mut route = vec![];

        for i in 0..h {
            if i % 2 == 0 {
                for j in 0..w {
                    route.push((i, j))
                }
            } else {
                for j in (0..w).rev() {
                    route.push((i, j))
                }
            }
        }

        let mut ans = String::new();
        let mut cnt = 0;

        let mut prev = None;
        for (cur, &(i, j)) in route.iter().enumerate() {
            if g[i][j] % 2 == 1 {
                if let Some(p) = prev {
                    for pair in route[p..cur + 1].windows(2) {
                        let (fi, fj) = pair[0];
                        let (ti, tj) = pair[1];
                        ans += format!("{} {} {} {}\n", fi+1, fj+1, ti+1, tj+1).as_str();
                        cnt += 1;
                    }
                    prev = None;
                } else {
                    prev = Some(cur);
                }
            }
        }

        println!("{}", cnt);
        print!("{}", ans);
    }
}


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

int main()
{
	string a,b;
	
	getline(cin,a);
	getline(cin,b);
	
	for(int i=1;i<=3;i++)
	{
		if(a[i-1]!=b[4-i-1])
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	
	cout<<"YES"<<endl;
	
	system("pause");
	return 0;
}

Measured memory_bytes: 504
import java.util.*;

public class Main {
	public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int n = N/2;

		if(N%2==0){
		System.out.println((double)N/2/N);
		}else {
	 	System.out.println((double)(n+1)/N);      
        }
}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<ll>>;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int N;
	cin >> N;
	if(N%10==0) N--;
	int k = log10(N)+1; // N の桁数

	int S = N / pow(10, k-1);
	int E = N % 10;

	vector<vector<int>> dic(10, vector<int>(10, 0));

	for(int i=1; i<=N; i++) {
		int ki = log10(i)+1;
		int s = i / pow(10, ki-1);
		int e = i % 10;
		dic[s][e]++;
	}

	int ans = 0;
	rep(i, 10) {
		rep(j , 10) {
			ans += dic[i][j] * dic[j][i];
		}
	}

	cout << ans << endl;	

	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll ans = max(A*C, A*D);
    ans = max(ans, B*C);
    ans = max(ans, B*D);
    printf("%lld\n", ans);
}

Measured memory_bytes: 3760
S = str(input())
if S == 'SUN':
    ans = 7
elif S == 'SAT':
    ans =1
elif S == 'FRI':
    ans =2
elif S == 'THU':
    ans =3
elif S == 'WED':
    ans =4
elif S == 'TUE':
    ans =5
elif S == 'MON':
    ans =6
print(ans)

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

int main(){
	int a,b,c,d,i,s=0;
	cin>>a>>b>>c;
	for(i=1;i<=a;i++){
		cin>>d;
		if(d<b||d>=c)s++;
	}
	cout<<s<<endl;
	return 0;
}

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

typedef struct{
  int data;
}dice;

void roll(char move,dice *a,dice *b,dice *c,dice *d,dice *e,dice *f)
{
  dice temp;

  temp = *a;
  if(move == 'E'){//???
    *a = *d;    *d = *f;    *f = *c;    *c = temp;
  }
  else if(move == 'N'){//???
    *a = *b;    *b = *f;    *f = *e;    *e = temp;
  }
  else if(move == 'S'){//???
    *a = *e;    *e = *f;    *f = *b;    *b = temp;
  }
  else if(move == 'W'){//???
    *a = *c;    *c = *f;    *f = *d;    *d = temp;
  }
}

void spin(char move,dice *a,dice *b,dice *c,dice *d)
{
  dice temp;

  temp = *a; //??±?????????
  if(move == 'R'){ //???????????????????????????????¨??????????
    *a = *b;    *b = *d;    *d = *c;    *c = temp;    
  }
  else if(move == 'L'){  //??????????????????????????????????¨??????????
    *a = *c;    *c = *d;    *d = *b;    *b = temp;
  }
}

int main(void)
{
  int n;
  int i,j,k,l,p,q,r,s,t;

  scanf("%d",&n);

  dice ** a = new dice * [n];
  for(i=0; i<n; i++){
    a[i] =new dice[6];
  }

  for(i=0; i<n; i++){
    for(j=0; j<6; j++){
      scanf("%d",&a[i][j].data);
    }
  }

  for(i = 1; i <= (n-1); i++){ //(n-1)????????????????????????
    int ii = i - 1;
    for(j=1; j<=(n-i); j++){ //????????§????????????????????????????????°??°?????????
      for(k=0; k<=3; k++){
	roll('S',&a[ii][0],&a[ii][1],&a[ii][2],&a[ii][3],&a[ii][4],&a[ii][5]);
	for(l=0; l<=3; l++){
	  spin('L',&a[ii][1],&a[ii][2],&a[ii][3],&a[ii][4]);
	  for(p=0; p<=5; p++){
	    if(a[ii+j][p].data != a[ii][p].data){
	      break;
	    }
	    else if((a[ii+j][p].data == a[ii][p].data) && (p==5)){
	      puts("No");
	      return(0);
	    }
	  }
	}
      }
      for(q=1; q<=2; q++){
	for(r=0; r<q; r++){
	  roll('W',&a[ii][0],&a[ii][1],&a[ii][2],&a[ii][3],&a[ii][4],&a[ii][5]);
	}
	for(s=0; s<=3; s++){
	  spin('L',&a[ii][1],&a[ii][2],&a[ii][3],&a[ii][4]);
	  for(t=0; t<=5; t++){
	    if(a[ii+j][t].data != a[ii][t].data){
	      break;
	    }
	    else if((a[ii+j][t].data == a[ii][t].data) && (t==5)){
	      puts("No");
	      return(0);
	    }
	  }
	}
      }
    }
  }
  
  puts("Yes");

  for(i=0; i<n; i++){
    delete[] a[i];
  }
  delete[] a;

  return(0);
}

Measured memory_bytes: 1016
from collections import deque

N = int(input())
EhasV = [set() for x in range(N)]
EhasVnums = [0] * N
EE = [0] * (N-1)
for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    EE[i] = {a,b}
    EhasV[a].add(i)
    EhasV[b].add(i)
    EhasVnums[a] += 1
    EhasVnums[b] += 1

K = len(max(EhasV,key=len))
Vcolor = [set(range(1,EhasVnums[x]+1)) for x in range(N)]
Ecolor = [-1] * (N-1)

q = deque()
q.append(0)
while q:
    v1 = q.pop()
    for e in EhasV[v1]:
        if Ecolor[e] != -1:
            continue
        color = Vcolor[v1].pop()
        Ecolor[e] = color
        edgeside = EE[e]
        edgeside.discard(v1)
        v2 = edgeside.pop()
        Vcolor[v2].discard(color)
        q.append(v2)

print(*([K]+Ecolor),sep='\n')

Measured memory_bytes: 88964
# frozen_string_literal: true

m, d = gets.split(' ').map(&:to_i)

i = 0
m.times do |manth|
  d.times do |day|
    next if day + 1 < 20

    iti = ((day + 1) % 10)
    next if iti < 2
    zyuu = ((day + 1 % 100) - iti) / 10
    i += 1 if manth + 1 == zyuu * iti

  end
end

puts i


Measured memory_bytes: 1788
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <complex>
#include <cassert>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const int mod = 99999997;
const ll cons = 100000000000;
const double pi = 3.141592653589793;

int main()
{
	int a,b;
	scanf("%d%d", &a, &b);

	if (a > 0)puts("Positive");
	else if (a == 0)puts("Zero");
	else
	{
		if (b >= 0)puts("Zero");
		else
		{
			if ((b - a) % 2)
			{
				puts("Positive");
			}
			else
			{
				puts("Negative");
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
char s[4],t[4];
int sum=0;
gets(s);
gets(t);
if(s[0]==t[0])
sum++;
if(s[1]==t[1])
sum++;
if(s[2]==t[2])
sum++;
printf("%d\n",sum);

}


Measured memory_bytes: 1640
#include <iostream>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main()
{
  int D, G;
  cin >> D >> G;

  vector<int> p(D);
  vector<int> c(D);
  rep(i, D)
  {
    cin >> p[i];
    cin >> c[i];
  }

  vector<vector<int>> score(D + 1);
  rep(i, D + 1)
  {
    score[i].resize(1001, 0);
  }

  int problems = 0;
  rep(i, D)
  {
    for (int j = 0; j <= problems; j++)
    {
      int s = score[i][j];
      for (int k = 0; k <= p[i]; k++)
      {
        if (k == p[i])
          s += c[i];
        score[i + 1][j + k] = std::max(score[i + 1][j + k], s + 100 * (i + 1) * k);
      }
    }

    problems += p[i];
  }

  rep(i, 1001)
  {
    if (score[D][i] >= G)
    {
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author rahdirigs
 */

#include <bits/stdc++.h>

using namespace std;

const int mxN = 310;
double dp[mxN][mxN][mxN];
bool vis[mxN][mxN][mxN];
int N;

class TaskJ {
public:
	void solve(std::istream& in, std::ostream& out) {
		in >> N;
		int a[4] = {0};
		for (int i = 0; i < N; i++) {
			int x; in >> x;
			a[x]++;
		}
		memset(vis, false, sizeof(vis));
		double ans = rec(a[1], a[2], a[3]);
		out << fixed << setprecision(12) << ans;
	}

	double rec(int x, int y, int z) {
		double &ret = dp[x][y][z];
		if (x < 0 || y < 0 || z < 0) return 0;
		if (x == 0 && y == 0 && z == 0) return 0;
		if (vis[x][y][z]) return ret;
		vis[x][y][z] = true;
		int rem = x + y + z;
		double val = N + x * rec(x - 1, y, z) + y * rec(x + 1, y - 1, z) + z * rec(x, y + 1, z - 1);
		return ret = val / rem;
	}
};


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	TaskJ solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 143488
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
map<LL,int>m;
int main(){
    cin>>N;
    REP(i,N){
        LL a;
        cin>>a;
        m[a]++;
    }
    int ans=0;
    for(auto it=m.begin();it!=m.end();it++){
        if((it->second)%2==1){
           ans++;
        }
    }
    cout<<ans<<endl;
    return(0);
}

Measured memory_bytes: 6528
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}

//提出コード↓

double n, sum, c = 1;
int x[10], y[10];




int main() {
	cin >> n;
	rep(i, n) cin >> x[i] >> y[i];
	vector<int> v(n);
	rep(i, n) v[i] = i;
	do {
		rep(i, n - 1) sum += dis(x[v[i]],y[v[i]], x[v[i + 1]],y[v[i + 1]]);
	} while (next_permutation(v.begin(), v.end()));
	REP(i, 1, n + 1) c *= i;
	cout << setprecision(10) << sum / c << endl;



	return 0;
}



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

int main(){
    int a, b;
    
    cin >> a >> b;
    
    if (a > b){
        cout << "a > b" << endl;
    } else if (a < b){
        cout << "a < b" << endl;
    } else {
        cout << "a == b" << endl;
    }
    
    return 0;
}




Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;int ans=0;vector<int>x(n);
for(int i=0;i<n;++i)cin>>x[i];for(int i=0;i<n-1;++i)if(x[i]==i+1){swap(x[i],x[i+1]);++ans;}if(x[n-1]==n)++ans;
  cout<<ans;cout<<endl;
  return 0;}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<ll> height(N);
    for (int i = 0; i < N; i++) cin >> height[i];

    ll ma = 0, su  = 0;
    for (int i = 0; i < N; i++) {
        if (height[i] > ma) ma = height[i];
        su += ma - height[i];
    }
    cout << su << endl;
}


Measured memory_bytes: 4720
#include <bits/stdc++.h>
#define ld long double
#define int long long
using namespace std;
const int N = 1e5 + 50;
const int mod = 1e9 + 7;
const int inf = 1e17;
int Dx[] = {0, 1, -1, 0, -1, 1, 1, -1};
int Dy[] = {1, 0, 0, -1, -1, 1, -1, 1};
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	int arr[n];
	for(int i = 0; i < n; i++){
		cin >> arr[i];
	}
	int ans = 1;
	for(int i = 1; i < n; i++){
		bool ok = true;
		for(int j = 0; j < i; j++){
			if(arr[j] > arr[i]){
				ok = false;
				break;
			}
		}
		if(ok){
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <utility>
#include <functional>
#include <queue>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>      // std::setprecision
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/math/common_factor_ct.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/icl/interval_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/strong_components.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/graph/kruskal_min_spanning_tree.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/numeric/ublas/vector.hpp>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::math;
using namespace boost::numeric;
namespace bst = boost;
template<class T> void fill(T& v) { for (auto& i : v) cin >> i; }

int main() {
  int N;

  cin >> N;
  vector<pair<int,int>> A;
  REP(i,N) {
    int a;
    
    cin >> a;
    A.emplace_back(a, i+1);
  }
  
  bst::sort(A);

  for (auto i : A)
    cout << i.second << endl;

  return 0;
}


Measured memory_bytes: 1780
import java.util.Scanner;

fun main (args : Array<String>) {
  val input = Scanner(System.`in`)
  val dayOfWeek = arrayOf("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT")
  
  while (input.hasNext()) {
    val S = input.next()
    
    for (i in dayOfWeek.indices) {
      if (S.equals(dayOfWeek[i])) {
        println(7 - i)
      }
    }
  }
}

Measured memory_bytes: 36064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<set>

using namespace std;

class UnionFind{
private:
    vector<int> Parent;
public:
    UnionFind(int N){
        vector<int> Parent(N,-1);
    }

    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A]=root(Parent[A]);
    }

    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A,int B){
        A=root(A);
        B=root(B);
        if(A==B) return false;
        if(size(A)<size(B)) swap(A,B);
        Parent[A]-=Parent[B];
        Parent[B]=A;
    }
};

int f(int x){}

int main(){
    int Q;
    cin >> Q;
    int query;
    typedef pair<int,int> P;
    P kukan;
    multiset<int> left,right;
    int x=0;
    long long ans=0;
    multiset<int>::iterator itr;
    for(int i=0;i<Q;i++){
        cin >> query;
        if(query==1){
            int a,b;
            cin >> a >> b;
            left.insert(a);
            right.insert(a);
            itr =left.end();
            --itr;
            int lmax = *itr;
            int rmin = *right.begin();
            
            if(lmax>rmin){
                ans +=lmax-rmin;
                right.erase(right.begin());
                right.insert(lmax);
                left.erase(itr);
                left.insert(rmin);
                
            }
            
            ans+=b;
            itr = left.end();
            --itr;
            x = *itr;
        }
        if(query==2){
            cout << x << " ";
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 18944
#include <iostream>
#define ll long long
using namespace std;

int main() {
    ll n, m, h[100100], a[100100], b[100100];
    cin >> n >> m;

    for (ll i = 1; i <= n; ++i)
        cin >> h[i];

    for (ll i = 1; i <= m; ++i)
        cin >> a[i] >> b[i];

    ll better[100100] = {0};
    for (ll i = 1; i <= m; ++i) {
        if (h[a[i]] <= h[b[i]])
            better[a[i]] = b[i];

        if (h[b[i]] <= h[a[i]])
            better[b[i]] = a[i];
    }

    ll cnt = 0;
    for (ll i = 1; i <= n; ++i) {
        if (!better[i]) ++cnt;
        // cout << better[i] << endl;
    }

    cout << cnt << endl;
}


Measured memory_bytes: 6712
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	std::string s, t;
	std::cin >> s >> t;
	if(s.size()>t.size()) puts("GREATER");
	else if(s.size()<t.size()) puts("LESS");
	else{
		REP(i, 0, s.size()){
			if(s[i]>t[i]) puts("GREATER");
			else if(s[i]<t[i]) puts("LESS");
			else continue;
			return 0;
		}
		puts("EQUAL");
	}
	return 0;
}



Measured memory_bytes: 256
N, X = input().split()
m = [int(input()) for x in range(int(N))]
X = int(X)
base = X - sum(m)
m = sorted(m)
counter = 0
for mi in m:
   while base >= 0:
      base -= mi
      if base < 0:
         break
      counter += 1

print(counter + int(N))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

int main() {
    ll n, ans = 0;
    cin >> n;
    for(auto x : prime_factor(n)){
        ll now = x.second, i = 1;
        while(now - i >= 0){
            now -= i;
            ans++; i++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<cmath>
#include<tuple>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cerr << v[a][b] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define MMAX 7368792

int main()
{
	int m,n;
	while(cin >> m >> n,m|n)
	{
		vector<int> memo(MMAX,0);
		int i,Mcount = 0;
		for(i = m;i < MMAX;i++)
		{
			if(memo[i] == 0)
			{
				if(Mcount == n)break;

				for(int j = i;j < memo.size();j += i)
				{
					memo[j] = 1;
				}
				Mcount++;			
			}
		}
		
		cout << i << endl;
		
		
	}
	return 0;
}

Measured memory_bytes: 31784
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    sum = 0
    l = K - A
    if l <= 0:
        sum += K
    else:
        sum += A
    l -= B
    if l > 0:
        sum -= l
    print(sum)
        
        
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9204
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
int N; 
int a[200010];
int b[200010];
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    int next = 1;
    rep(i, N) cin >> a[i];
    rep(i, N) {
        if (a[i] == next) next++;
    }
    if (next == 1) {
        cout << -1 << endl; 
    } else {
        cout << N - next + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
     int n;
     long long a[100005];
     cin >> n;
     long long ans=0;
     for (int i=1;i<=n;i++){
     	cin >> a[i];
     	ans+=a[i];
     }
     if (ans%2==0) cout << "YES\n";
     else cout << "NO\n";
}

Measured memory_bytes: 1024
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    s, t = input(), input()

    s = list(sorted(s))
    t = list(sorted(t))[::-1]

    print("Yes" if s < t else "No")

if __name__ == '__main__':
    main()


Measured memory_bytes: 3948
import java.io.*;
import java.util.*;
 
public class Main {
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		int n=in.nextInt(), x=in.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; ++i)
			a[i]=in.nextInt();
		Arrays.sort(a);
		int ans=0;
		for(int i=0; i<n; ++i) {
			if(a[i]<=x){
				x-=a[i];
				++ans;
			}
		}
		out.println(x>0?Math.min(ans, n-1):ans);
		out.close();
	}
	
	static class Reader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while(st==null||!st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

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

int main() {
  string c;
  cin >> c;
  if(c=="ABC")cout << "ARC" << endl;
  else cout << "ABC" << endl;
  return 0;
}


Measured memory_bytes: 3592