akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(S == T) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inp_ll;

const int MAXN = 44;
const int INF = 1000000000;

int n;
char s[MAXN], t[MAXN];
unordered_map<string, unordered_map<string, int> > F;

int main()
{
	
	scanf("%d%s", &n, s);
	for (int i = n; i < 2*n; ++ i)
		t[i-n] = s[i];
	reverse(t, t+n);
	for (int mask = 0; mask < 1<<n; ++ mask)
	{
		string t1, t2;
		for (int i = 0; i < n; ++ i)
		{
			if (mask>>i&1)
				t1 += t[i];
			else
				t2 += t[i];
		}
		F[t1][t2] ++;
	}
	ll ans = 0;
	for (int mask = 0; mask < 1<<n; ++ mask)
	{
		string s1, s2;
		for (int i = 0; i < n; ++ i)
		{
			if (mask>>i&1)
				s1 += s[i];
			else
				s2 += s[i];
		}
		ans += F[s1][s2];
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 134132
#include<stdio.h>
#include<string.h>

int main()
{
  int n,i,c=1;
  scanf("%d",&n);
  char str[n];
  
  scanf("%s",str);
  for(i=0;i<n-1;i++)
  {
    if(str[i]!=str[i+1])
       c++;
   }  
  printf("%d\n",c);
  return 0;
}     
    
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
cin >> n>>k;
vector<int> ans(n);

for(int i = 0;i < n;i++){
	ans[i] = 0;
}

vector<int> d(k);


for(int i = 0;i < k;i++){
cin >>d[i];
int a;
for(int j = 0;j < d[i];j++){
	cin >>a;
	ans[a-1] = 1;
}

}

int cnt = 0;
for(int i = 0;i < n;i++){
if(ans[i] == 0){
	cnt++;
}
}
cout << cnt <<endl;
}

Measured memory_bytes: 3624
import java.util. *;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int[] a = new int[3];
	for(int i = 0;i < a.length;i++){
	    a[i] = sc.nextInt();
	}
	Arrays.sort(a);
	System.out.println(a[2] - a[0]);
    }
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int h, n;
    cin >> h >> n;
    vector< int > a;
    for( int i = 0; i < n; ++i ) {
        int b;
        cin >> b;
        a.pb(b);

    }

    for( int i = 0; i < n; ++i ) {
        h -= a[i];

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



Measured memory_bytes: 892
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

using ll = long long;
using Graph = vector<vector<int>>;

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=1;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n);
  VIN(A)
  REP(i,n-1){
    if(A[i]==A[i+1]) {z++;}
    else {y+=(z/2);z=1;}
  }
  y+=(z/2);
  OUT(y);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<bool> VB;
typedef vector<vector<int> > VVI;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v, seen); // 再帰的に探索
    }
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    int w, h;

    cin >> w >> h;

    while (w || h){
        VVI c(h, VI(w));
        VVI G(h*w);
        REP(i,h) REP(j,w) cin >> c[i][j];
        VI seen(h*w,false);
        REP(i,h) REP(j,w){
            if (c[i][j]){
                if (i != 0) if (c[i-1][j]) G[i*w+j].push_back((i-1)*w+j);
                if (i != h-1) if (c[i+1][j]) G[i*w+j].push_back((i+1)*w+j);
                if (j != 0) if (c[i][j-1]) G[i*w+j].push_back(i*w+j-1);
                if (j != w-1) if (c[i][j+1]) G[i*w+j].push_back(i*w+j+1);
                if (i != 0 && j != 0) if (c[i-1][j-1]) G[i*w+j].push_back((i-1)*w+j-1);
                if (i != 0 && j != w-1) if (c[i-1][j+1]) G[i*w+j].push_back((i-1)*w+j+1);
                if (i != h-1 && j != 0) if (c[i+1][j-1]) G[i*w+j].push_back((i+1)*w+j-1);
                if (i != h-1 && j != w-1) if (c[i+1][j+1]) G[i*w+j].push_back((i+1)*w+j+1);
            }
            else {
                seen[i*w+j] = true;
            }
        }

        int ans = 0;
        REP(i,h*w){
            if (seen[i] == false){
                dfs(G,i,seen);
                ans++;
            }
        }

        cout << ans << endl;

        cin >> w >> h;
    }
}


Measured memory_bytes: 3384
from collections import deque
import sys

flg1 = 1
s = input()
ll = deque()
lr = deque()
for _ in range(int(input())):
    q = sys.stdin.readline().rstrip()
    if q == "1":
        flg1 *= -1
    else:
        q = list(q.split())
        flg2 = 1 if q[1] == "1" else -1
        if flg1 * flg2 == 1:
            ll.appendleft(q[2])
        else:
            lr.append(q[2])

ans = "".join(ll) + s + "".join(lr)
print((ans[::-1], ans)[flg1 == 1])

Measured memory_bytes: 12488
n = int(input())
height = list(map(int, input().split()))

for i in range(n-2, -1, -1):
    if height[i] > height[i+1]:
        height[i] -= 1

for i in range(n-1):
    if height[i] > height[i+1]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 14396
#include<iostream>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<vector>
using namespace std;
int N,K;
int x[200],y[200];
double calc(double X,double Y)
{
	vector<double>A(N);
	for(int i=0;i<N;i++)A[i]=hypot(x[i]-X,y[i]-Y);
	sort(A.begin(),A.end());
	double ret=0;
	for(int i=0;i<K;i++)ret+=A[N-i-1];
	return ret;
}
double get(double X)
{
	double L=-1e3,R=1e3;
	for(int i=0;i<100;i++)
	{
		double M1=(L*2+R)/3,M2=(L+R*2)/3;
		if(calc(X,M1)<calc(X,M2))R=M2;
		else L=M1;
	}
	return calc(X,L);
}
main()
{
	cin>>N>>K;
	for(int i=0;i<N;i++)
	{
		cin>>x[i]>>y[i];
	}
	double L=-1e3,R=1e3;
	for(int i=0;i<100;i++)
	{
		double M1=(L*2+R)/3,M2=(L+R*2)/3;
		if(get(M1)<get(M2))R=M2;
		else L=M1;
	}
	cout<<fixed<<setprecision(16)<<get(L)<<endl;
}



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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define debug(x) cerr<<#x<<"="<<x<<'\n'

pii f[100010];
vector <int> edge[100010];

pii getf(int node,int lst) {
	if (f[node].fi!=-1) return f[node];
	if (edge[node].size()==0||(node!=1&&edge[node].size()==1)) {
		f[node].fi=1;
		f[node].se=1;
		return f[node];
	}
	ll x=1,y=1;
	for (int i=0;i<edge[node].size();i++) {
		int v=edge[node][i];
		if (v==lst) continue;
		x*=(ll)getf(v,node).se;
		y*=(ll)((getf(v,node).se+getf(v,node).fi)%mod);
		x%=mod,y%=mod;
	}
	f[node].fi=x,f[node].se=y;
	return f[node];
}

int main(){
	int n;
	scanf("%d",&n);
	for (int i=1;i<n;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		edge[x].pb(y);
		edge[y].pb(x);
		f[i].fi=-1;
	}
	f[n].fi=-1;
	printf("%d",(getf(1,-1).fi+getf(1,-1).se)%mod);
	return 0;
}


Measured memory_bytes: 14848
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>  // https://boostjp.github.io/tips/math.html
#include <boost/dynamic_bitset.hpp>  // https://boostjp.github.io/tips/dynamic_bitset.html

constexpr int64_t DIV1097 = 1000000007LL;

using namespace std;

int main()
{
    int64_t N;
    std::cin >> N;

    std::map<int64_t, int64_t> M;
    for (decltype(N) i = 0; i < N; ++i) {
        int64_t a;
        std::cin >> a;
        M[a-1]++;
        M[a]++;
        M[a+1]++;
    }

    int64_t ans = 0;
    for (auto& m: M) {
        ans = std::max(ans, m.second);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 6144
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
#define double long double
using namespace std;
const double pi=acos(-1);
struct poLL {LL  x,y,num;}p[110],a[110];
double ans[110];
LL multi(poLL  p1,poLL  p2,poLL  p0)
{
	LL x1=p1.x-p0.x,y1=p1.y-p0.y;
	LL x2=p2.x-p0.x,y2=p2.y-p0.y;
	return x1*y2-x2*y1;
}
LL  n,top=0,sta[110];
//LL  dis(poLL  a,poLL  b) {return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);}
double dis(double x,double y,double x1,double y1) {return sqrt((x-x1)*(x-x1)+(y-y1)*(y-y1));}
/*bool cmp(poLL  a,poLL  b)
{
	LL t1=multi(b,a,p[1]);
	return t1==0?dis(p[1],a)<dis(p[1],b):t1>0;
}
void solve()
{
	for(LL  i=2;i<=n;i++)
		if((p[1].x==p[i].x)?(p[i].y<p[1].y):(p[i].x<p[1].x)) swap(p[1],p[i]);
	sort(p+2,p+n+1,cmp);
	sta[++top]=1;
	for(LL  i=2;i<=n;i++)
	{
		while(top>1&&multi(p[sta[top]],p[sta[top-1]],p[i])<=0) top--;
		sta[++top]=i;
	}
}*/
bool cmp(poLL A,poLL b)
{
    double tmp=multi(A,b,p[1]);
    return tmp==0?dis(A.x,A.y,p[1].x,p[1].y)<dis(b.x,b.y,p[1].x,p[1].y):tmp>0;
}
void solve()
{
	for(int i=2;i<=n;i++)
        if(p[i].y<p[1].y||p[i].y==p[1].y&&p[i].x<p[1].x) swap(p[1],p[i]);
    sort(p+2,p+n+1,cmp);
    sta[1]=1;sta[2]=2;top=2;
    for(int i=3;i<=n;i++)
    {
        while(top>1&&multi(p[sta[top]],p[i],p[sta[top-1]])<0) top--;
        sta[++top]=i;
    }
}
double get(poLL  p1,poLL  p2,poLL  p0)
{
	LL x1=p1.x-p0.x,y1=p1.y-p0.y;
	LL x2=p2.x-p0.x,y2=p2.y-p0.y;
	return (double)(x1*x2+y1*y2)/(sqrt(x1*x1+y1*y1)*sqrt(x2*x2+y2*y2));
}
void calc()
{
	if(top==0) for(LL  i=1;i<=top;i++) ans[p[sta[i]].num]=0.5;
	else
	{
		sta[0]=sta[top];sta[top+1]=sta[1];
		for(LL  i=1;i<=top;i++)
		{
			double tmp=get(p[sta[i-1]],p[sta[i+1]],p[sta[i]]);
			double s=pi-acos(tmp);
			ans[p[sta[i]].num]=s/(pi*2);
		}
	}
}
int  main()
{
	scanf("%lld",&n);
	for(LL  i=1;i<=n;i++) scanf("%lld %lld",&p[i].x,&p[i].y),p[i].num=i;
	if(n==1) return puts("1.000000000000"),0;
	solve();calc();
	for(LL i=1;i<=n;i++) printf("%.9Lf\n",ans[i]);
}

Measured memory_bytes: 764
#include<stdio.h>

int main(void){
    int W,H,x,y;
    int k;
    double S;
    scanf("%d %d %d %d",&W,&H,&x,&y);
    S = (double) H * W / 2;
    k = (W == 2*x) * (H == 2*y);
    printf("%lf %d",S,k);
    return 0;
}

Measured memory_bytes: 128
inpl = lambda: list(map(int,input().split()))
N,M = inpl()
A = []
for i in range(N):
  A.append(inpl()) 
A.sort(key=lambda x: x[0])
ans = 0
for i in range(N):
  if A[i][1] >= M:
    ans += A[i][0]*M
    break
  else:
    M -= A[i][1]
    ans += A[i][0]*A[i][1]
print(ans)

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

const int inf = 1000000007;

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1]){
        cout << "Bad" << endl;
    }
    else if(s[1] == s[2]){
        cout << "Bad" << endl;
    }
    else if(s[2] == s[3]){
        cout << "Bad" << endl;
    }
    else{
        cout << "Good" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    As = [list(map(int, input().split())) for _ in range(3)]
    n = int(input())
    Bs = [int(input()) for _ in range(n)]
    
    for i in range(n):
        for j in range(3):
            for k in range(3):
                if Bs[i] == As[j][k]:
                    As[j][k] = 0
                    if (k in [0,2] and j in [0,2]) or (j == 1 and k == 1):
                        if (As[0][0] == 0 and As[1][1]  == 0 and As[2][2] == 0) or (As[0][2] == 0 and As[1][1]  == 0 and As[2][0] == 0):
                            print('Yes')
                            return
                    if (As[j][0] == 0 and As[j][1] == 0 and As[j][2] == 0) or (As[0][k] == 0 and As[1][k] == 0 and As[2][k] == 0):
                        print('Yes')
                        return
    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ff first
#define ss second
ll fact(ll n)
{
    if(n==0)
        return 1;
    return fact(n-1)*n;
}
double dist(pair<ll,ll> a , pair<ll,ll> b)
{
    return sqrt((a.ff-b.ff)*(a.ff-b.ff) + (a.ss-b.ss)*(a.ss-b.ss));
}
int main()
{
    ll n;
    cin >> n;
    double sum = 0;
    pair<ll,ll> a[n];
    for(ll i=0;i<n;i++)
    {
        cin >> a[i].first;
        cin >> a[i].second;
       
    }
    sort(a,a+n);
    int cnt = 0;
    do
    {
        cnt++;
        for(ll i=0;i<n-1;i++)
        {
            sum += dist(a[i],a[i+1]);
        }
        
    } while (next_permutation(a,a+n));
    
    // cout << sum << " " << fact(n)<<endl;
    double ans = sum/fact(n);
    printf("%0.12lf",ans);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }
int cnt[2020];
int main() {
    SS(int,n,x,y)
    for(int i=1; i<=n-1; i++){
        for(int j=i+1; j<=n; j++){
        cnt[min(j-i,abs(x-i)+1+abs(y-j))]++;
        }
    }
    rep(i,n-1)p(cnt[i+1]);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    vi broken(n+1);
    rep(_, m){
        int x; cin >> x;
        broken[x] = true;
    }

    vll dp(n+2);
    dp[0] = 1LL;

    rep(i, n){
        ll cur = dp[i];
        if(cur == 0LL) continue;

        rep(k, 1, 3){
            int ni = i + k;
            if(broken[ni]) continue;
            dp[ni] = ADD(dp[ni], cur);
        }
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iomanip>
#include<sstream>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1;i <=n;i++)
#define rrep(i,n) for(int i = n -1;i >= 0;i--)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
typedef long double ld;
const ll MOD =  1000000007;
const ll INF =  1LL << 60;
int n, m, x, y;ll z = 0, w, h, sum = 0, ans = 0;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
    std::fill((T*)array, (T*)(array + N), val);
}
int main(void) {
	cin >> n; vector<ll> k(5, 0); string s;
	rep(i, n) {
		cin >> s;
		if (s[0] == 'M') k[0]++;
		else if (s[0] == 'A')k[1]++;
		else if (s[0] == 'R')k[2]++;
		else if (s[0] == 'C') k[3]++;
		else if (s[0] == 'H') k[4]++;
	}
	rep(i, 1 << 5) {
		int cnt = 0; sum = 1;
		rep(j, 5) {
			if (i & (1 << j)) cnt++;
		}
		if (cnt != 3) continue;
		rep(j, 5) {
			if (i & (1 << j))sum *= k[j];
		}
		ans += sum;
	}cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
 
int main() {
	//cout.precision(10);
	cin.tie(0);
	ios::sync_with_stdio(false);

    int N; cin >> N;

    int sum = 0;
    rep(i,N){
        int l, r; cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    a,b,c,d = IR(4)
    print(min(a,b)+min(c,d))

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 39024
n = int(input())
num_list =  list(map(int,input().split()))
num_list2 = [0]*n
num_list3 = [0]*n
for i in num_list:
    num_list2[i-1] += 1
for i in range(n):
    ans = num_list2[i]*(num_list2[i]-1)//2
    num_list3[i] = ans
sum_V = sum(num_list3)
for i in num_list:
    ans = (num_list2[i-1]-1)*(num_list2[i-1]-2)//2
    print(ans-num_list3[i-1]+sum_V)

Measured memory_bytes: 25716
#include <iostream>
#include <string>

using namespace std;

#define nullptr  NULL

struct node
{
	int val;
	node* right;
	node* left;
	node(const int& v = 0) : val(v), right(nullptr), left(nullptr)
	{}
};

struct Tree
{
	node* root;
};

node* insert(node* root, int v)
{
	if (!root)
	{
		root = new node(v);
		return root;
	}
	node* temp = root;
	while (1)
	{
		if (root->val > v)
		{
			if (!root->left)
			{
				root->left = new node(v);
				break;
			}
			root = root->left;
		}
		else
		{
			if (!root->right)
			{
				root->right = new node(v);
				break;
			}
			root = root->right;
		}
	}
	return temp;
}

node* remove(node* root, int v)
{
	if (!root)
		return nullptr;
	if (root->val > v)
		root->left = remove(root->left, v);
	else if (root->val < v)
		root->right = remove(root->right, v);
	else
	{
		if (!root->left || !root->right)
		{
			root = (root->left) ? root->left : root->right;
		}
		else
		{
			node* temp = root->right;
			while (temp->left)
				temp = temp->left;
			root->val = temp->val;
			root->right = remove(root->right, temp->val);
		}
	}
	return root;
}

node* find(node* root, int v)
{
	if (!root)
		return nullptr;
	while (root != nullptr && v != root->val)
	{
		if (v < root->val)
			root = root->left;
		else
			root = root->right;
	}
	return root;
}

void preorder(node* root)
{
	if (!root)
		return;
	cout << " " << root->val;
	preorder(root->left);
	preorder(root->right);
}

void inorder(node* root)
{
	if (!root)
		return;
	inorder(root->left);
	cout << " " << root->val;
	inorder(root->right);
}

int main()
{
	int m;
	node* root = nullptr;
	cin >> m;
	for (int i = 0; i < m; i++)
	{
		int k;
		string s;
		cin >> s;
		if (s == "insert")
		{
			cin >> k;
			root = insert(root, k);
		}
		else if (s == "delete")
		{
			cin >> k;
			root = remove(root, k);
		}
		else if (s == "find")
		{
			cin >> k;
			if (find(root, k) != nullptr)
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
		else if (s == "print")
		{
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
	}

	return 0;
}



Measured memory_bytes: 15628
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<string>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;	

char ch[2];

int main() {

	scanf("%s", ch);
	if (ch[0] >= 'A' && ch[0] <= 'Z') puts("A");
	else puts("a");

	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N;
  cin >> N;
  vector<int> tree[N];
  for (int i = 0; i < N - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    tree[x].push_back(y);
    tree[y].push_back(x);
  }
  int grundy[N];
  function<int(int, int)> dfs = [&](int v, int p) {
    grundy[v] = 0;
    for (int u : tree[v])
      if (u != p) {
        grundy[v] ^= dfs(u, v) + 1;
      }
    return grundy[v];
  };
  cout << (dfs(0, -1) == 0 ? "Bob" : "Alice") << '\n';
  return 0;
}


Measured memory_bytes: 18856
#coding utf-8
S=list(input().strip())
S=[0]+S
l=len(S)
mod=10**9+7

dp=[[0 for i in range(13)] for j in range(l+1)]

dp[0][0]=1    
for i in range(l):
  if S[i]=="?":
    for j in range(13):
      for k in range(10):
        dp[i+1][(j*10+k)%13]+=dp[i][j]%mod
  else:
    for j in range(13):
      dp[i+1][(j*10+int(S[i]))%13]+=dp[i][j]%mod

print(dp[-1][5]%mod)  


Measured memory_bytes: 73448
n, k = map(int, input().split())
s = list(map(str, input().split()))[0]

ans = 0
w = 0
for i in range(n-1):
    if s[i+1] == s[i]:
        ans += 1
    else:
        w += 1

p = (w // 2) * [2] + (w % 2) * [1]

print(ans + sum(p[:k]))

Measured memory_bytes: 40560
#define _DEBUG 1
#define _GLIBCXX_DEBUG

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

void solve(string S) {
  int N = S.size();
  map<int, int> mp;
  mp[0] = 1;

  int p = 0;
  int ten = 1;
  repr(i, N - 1) {
    p = (p + (S.at(i) - '0') * ten) % 2019;
    ten *= 10;
    ten %= 2019;
    mp[p]++;
  }
  int cnt = 0;
  for (auto v : mp) {
    cnt += v.second * (v.second - 1) / 2;
  }
  cout << cnt << endl;
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 3940
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
using namespace std;
int main()
{
  string s;
  cin>>s;
  ll x1,x2;
  x1=(s[0]-'0')*10+(s[1]-'0');
  x2=(s[2]-'0')*10+(s[3]-'0');
  if((x1>=1&&x1<=12)&&(x2>=1&&x2<=12))
   cout<<"AMBIGUOUS";
  else if(x1>=1&&x1<=12)
  cout<<"MMYY";
  else if(x2>=1&&x2<=12)	
  cout<<"YYMM";
  
   else
   cout<<"NA";	
	
	
	
	
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//CODE
void solve(void)
{
  string str;
  cin>>str;
  bool ok = 1;
  for (int i = 0; i < str.size()-1; i++)
  {
    if(str[i] == str[i+1]) ok = 0;
  }
  
  cout<<(ok?"Good":"Bad")<<endl;
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a==5&&b==5&&c==7){
        puts("YES");
        return 0;
    }
    if(a==5&&b==7&&c==5){
        puts("YES");
        return 0;
    }
    if(a==7&&b==5&&c==5){
        puts("YES");
        return 0;
    }
    puts("NO");
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;


/*

*/

ll n,a[200010],odd=0;

int main(void){
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n){
		if(a[i]%2==1)odd++;
	}
	cout<<(odd>0?"first":"second")<<endl;
	return 0;
}

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

class Main{
    public static void main(String[] x){
		byte[] k = new byte[200];
		try{
			Scanner sc = new Scanner(System.in);
			for(byte i=-127;i<73;i++){
				String s = sc.nextLine();
				if(s==null||s.equals("")){
					k[i+127]=0;
					break;
				}
				k[i+127] = dig(Integer.parseInt((s.split(" ",0))[0])+Integer.parseInt((s.split(" ",0))[1]));
			}
		}catch(Exception e){}
		for(byte i=-127;i<73;i++){
			if(k[i+127]>0){System.out.println(k[i+127]);}
			else{break;}
		}
    }
	public static byte dig(int a){
		byte d = 0;
		while(true){
			if(a>=10){
				d++;
				a/=10;
			}
			else{return (byte)((int)d+1);}
		}
	}
}

Measured memory_bytes: 26372
#include<bits/stdc++.h>
int const INF = 1e6;
using namespace std;
int main(){
  string s; cin>>s;
  int min_dist = INF;
  for(int i=0; i<=s.size()-3; ++i){
    if( min_dist > abs(stoi(s.substr(i,3)) - 753 )){
      min_dist = abs(stoi(s.substr(i,3)) - 753 );
    }
  }
  cout << min_dist <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"NO"<<endl
#define YES() cout<<"YES"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

ll powe(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
vll dp(100001,-1);

ll sol(vll &v,ll i,ll &n,ll &k)
{
    if(i==n-1)
        return 0ll;
    if(dp[i]!=-1) return dp[i];;
    ll j,cnt,ans=-1;
    for(j=1;j<=k;j++)
    {
        if(i+j>=n)
        {
            break;
        }
        cnt=abs(v[i]-v[i+j])+sol(v,i+j,n,k);
        if(ans==-1) ans=cnt;
        else ans=min(ans,cnt);
    }
    dp[i]=ans;
    return dp[i];
}

void solve()
{
    ll i,j,k=0,n,l;
    cin>>n>>k;
    vll v(n);
    take(v,n);
    cout<<sol(v,0,n,k);


}

int main() {
    fast;
    ll i,j,l,k,t,n;
    t=1;
    while(t--)
    solve();
}


Measured memory_bytes: 12692
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;

struct priority_queue{
    int A[2000005];
    int fact;
    priority_queue(){
        for(int i=0;i<2000005;i++){
            A[i]=-1;
        }
        fact = 0;
    }
    int extract(){
        int ret = A[0];
        A[0]=A[--fact];
        A[fact]=-1;
        int start = 0;
        while(start*2+1<fact){
            int c1=start*2+1,c2=start*2+2;
            int next=c2;
            if(A[c1]>A[c2]){
                next = c1;
            }
            if(A[next]>A[start]){
                int temp=A[next];
                A[next]=A[start];
                A[start]=temp;
                start = next;
            }else{
                break;
            }
        }
        return ret;
        
        return ret;
    }
    void insert(int x){
        int start = fact;
        fact++;
        A[start]=x;
        while(start>0){
            int p = (start-1)/2;
            if(A[start]>A[p]){
                int temp =A[start];
                A[start]=A[p];
                A[p]=temp;
            }
            start = p;
        }
        return;
    }
};

int main(){
    priority_queue pq;
    char s[100];
    while(1){
        scanf("%s",s);
        if(!strcmp(s,"extract")){
            printf("%d\n",pq.extract());
        }else if(!strcmp(s,"end")){
            break;
        }else{
            int x;
            scanf("%d",&x);
            pq.insert(x);
        }
    }
    return 0;
                 
}

Measured memory_bytes: 9004
#include <stdio.h>
#include <iostream>
#include <fstream>

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

template<class T> inline T pow(T base, T exponent, T mod) {
    if (exponent == 0) return 1;

    if (exponent % 2 == 1) {
        return base * pow(base, exponent - 1, mod) % mod;
    } else {
        T tmp = pow(base, exponent / 2, mod);
        return (tmp * tmp) % mod;
    }
}

void solve() {
    long n, a, b; cin >> n >> a >> b;
    long mod = 1e9 + 7;

    long ans = pow(2l, n, mod) - 1;

    long X = 1;
    for (int i = n; i >= n - (a - 1); --i) {
        X *= i;
        X %= mod;
    }

    long Y = 1;
    for (int i = 1; i <= a; ++i) {
        Y *= i;
        Y %= mod;
    }

    ans += mod;
    ans -= X * pow(Y, mod - 2, mod) % mod;

    X = 1;
    for (int i = n; i >= n - (b - 1); --i) {
        X *= i;
        X %= mod;
    }

    Y = 1;
    for (int i = 1; i <= b; ++i) {
        Y *= i;
        Y %= mod;
    }

    ans += mod;
    ans -= X * pow(Y, mod - 2, mod) % mod;

    cout << ans % mod << endl;
}

int main() {

#ifdef DEV
    std::ifstream in("input");
    cin.rdbuf(in.rdbuf());

    int t; cin >> t;
    for (int x = 1; x <= t; ++x) {
        solve();
    }
#else
    solve();
#endif

    return 0;
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <numeric>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll MOD = 1000000007;
const ll INF = 1LL << 60;
#define PI (acos(-1))

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
vector<ll> divisor(ll n)
{
    vector<ll> ret;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0)
        {
            ret.push_back(i);
            if (i * i != n)
                ret.push_back(n / i);
        }
    }
    sort(begin(ret), end(ret));
    return (ret);
}

const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
ll COM(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll a[101];
ll solve()
{
    ll n, m;
    cin >> n >> m;
    auto d = divisor(m);
    ll ans = 0;
    for (auto v:d){
        if(m - n*v < 0){
            break;
        }
        if((m - (n*v)) % v == 0){
            ans = max(ans, v);
        }
    }
    cout << ans << endl;

    return 0;
}

int main()
{
    //cout.precision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
const array<int, 4> dr = { 1, -1, 0, 0 };
const array<int, 4> dc = { 0, 0, 1, -1 };

int H, W;
vector<string> S;
vector<vector<bool>> visited;

ll BFS(int sr, int sc)
{
    queue<tuple<int, int, int>> Q;
    Q.push(make_tuple(sr, sc, 0));

    visited[sr][sc] = true;

    ll blackNum = 0, whiteNum = 0;

    while (!Q.empty())
    {
        int r, c, d;
        tie(r, c, d) = Q.front();
        Q.pop();

        if (S[r][c] == '#')
        {
            ++blackNum;
        }
        else
        {
            ++whiteNum;
        }

        rep(i, 0, 4)
        {
            const int nr = r + dr[i];
            const int nc = c + dc[i];
            if (nr >= 0 && nr < H && nc >= 0 && nc <= W && !visited[nr][nc] && S[nr][nc] == (d % 2 == 0 ? '.' : '#'))
            {
                Q.push(make_tuple(nr, nc, d + 1));
                visited[nr][nc] = true;
            }
        }
    }

    return blackNum * whiteNum;
}

void _main()
{
    cin >> H >> W;
    S.resize(H);
    rep(i, 0, H) cin >> S[i];

    visited.assign(H, vector<bool>(W, false));

    ll ans = 0;
    rep(r, 0, H) rep(c, 0, W)
    {
        if ((S[r][c] == '#') && !visited[r][c])
        {
            ans += BFS(r, c);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	int n, k, q; cin >> n >> k >> q;
	int pt[n] = {}; rep(i,n) pt[i] = -q;
	while(q--) {
		int a; cin >> a;
		a--;
		pt[a]++;
	}
	rep(i,n) {
		// cout << pt[i] <<endl;
		if(pt[i] > -k) {
			cout << "Yes" <<endl;
		} else {
			cout << "No" <<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)//最大公約数
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}
vector<int> divisor(int n) {//約数発見
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
}
long nc2(long n){
    return n*(n-1)/2;
}
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
	static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string ret;
	static numeric_limits<TypeInt> t;
	TypeInt n = v;
	if (t.is_signed) {
		if (v < 0) n *= -1;
	}

	while (n >= base) {
		ret += table[n%base];
		n /= base;
	}
	ret += table[n];
	if (t.is_signed) {
		if (v < 0 && base == 10) ret += '-';
	}
	// 文字列の順番を逆にする
	std::reverse(ret.begin(), ret.end());

	return ret;
}

int main(){
    //std::stack<int> stack;
    int n;
    
    cin >> n;
    vector<long> a(n+1,1);
    for(int i = 2; i <= n; i++){
        for(int j = i; j <= n; j +=i){
            a[j] ++;
        }
    }
    long ans = 0;
    for(int i = 1; i <= n; i++){
        ans += i*a[i];
    }
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 81392
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n!=0){
		int[] rob = {10, 10};
		int i;
		int[][] jem = new int[2][n];
		boolean[] jemG = new boolean[n];
		for(i=0; i<n; i++){
		    jem[0][i] = kbd.nextInt();
		    jem[1][i] = kbd.nextInt();
		    jemG[i] = false;
		}
		int m = kbd.nextInt();
		while(m>0){
		    String d = kbd.next();
		    int l = kbd.nextInt();
		    while(l>0){
			move1(d, rob);
			for(i=0; i<n; i++){
			    if(rob[0]==jem[0][i] && rob[1]==jem[1][i]){
				jemG[i] = true;
				break;
			    }
			}
			l--;
		    }
		    m--;
		}
		if(get(jemG)) System.out.println("Yes");
		else System.out.println("No");
	    }
	}
    }

    static void move1(String d, int[] rob){
	     if(d.equals("N")) rob[1]++;
	else if(d.equals("E")) rob[0]++;
	else if(d.equals("S")) rob[1]--;
	else if(d.equals("W")) rob[0]--;
    }

    static boolean get(boolean[] jemG){
	int i;
	boolean ans = true;
	for(i=0; i<jemG.length; i++){
	    ans = ans && jemG[i];
	}
	/*
	for(i=0; i<jemG.length; i++){
	    System.out.println(jemG[i]);
	}
	*/
	return ans;
    }
}

Measured memory_bytes: 32312