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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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 dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};
ll n;
string x;

map<ll,ll> m;

ll f(ll a){
    if(a == 0) return 0;
    if(m.count(a)) return m[a];

    ll ppcnt = 0;
    ll tmp = a;
    while(tmp>0){
        if(tmp & 1){
            ppcnt++;
        }
        tmp = (tmp>>1);
    }

    ll rtn = f(a%ppcnt) + 1;
    m[a] = rtn;
    return rtn;

}

int main() {
    cout<<fixed<<setprecision(10);

    cin>>n;
    cin>>x;

    ll tmp_pl = 0;
    ll tmp_mi = 0;
    ll fac_pl = 1;
    ll fac_mi = 1;
    ll ppcnt = 0;
    for(auto b:x){
        if(b=='1') ppcnt++;
    }

    rep(i,n){
        tmp_pl = (tmp_pl + (ll)(x[n-1-i] == '1')*fac_pl)%(ppcnt+1);
        fac_pl = (fac_pl*2)%(ppcnt+1);

        if(ppcnt <= 1) continue;
        tmp_mi = (tmp_mi + (ll)(x[n-1-i] == '1')*fac_mi)%(ppcnt-1);
        fac_mi = (fac_mi*2)%(ppcnt-1);
    }

    vint ans(n,0);
    fac_pl = 1;
    fac_mi = 1;

    // cout<<ppcnt<<endl;

    rep(i,n){
        ll a;
        if(ppcnt <= 1){
            if(x[n-1-i] == '1'){
                ans[n-1-i] = 0;
                fac_pl = (fac_pl*2)%(ppcnt+1);
                continue;
            }else{
                a = (tmp_pl + fac_pl)%(ppcnt+1);
            }
            // cout<<a<<endl;
            ans[n-1-i] = f(a) + 1;
            fac_pl = (fac_pl*2)%(ppcnt+1);
        }else{
            if(x[n-1-i] == '1'){
                a = (tmp_mi - fac_mi + ppcnt - 1)%(ppcnt-1);
            }else{
                a = (tmp_pl + fac_pl)%(ppcnt+1);
            }
            // cout<<a<<endl;
            ans[n-1-i] = f(a) + 1;
            fac_pl = (fac_pl*2)%(ppcnt+1);
            fac_mi = (fac_mi*2)%(ppcnt-1);
        }
    }

    for(auto e:ans) cout<<e<<endl;





    return 0;

}

Measured memory_bytes: 6236
def hms(num):
    h = int(num / (60 ** 2))
    m = int((num - h * 3600) / 60)
    s = int((num - (h * 3600) - m * 60))
    print(str(h) + ":" + str(m) + ":" + str(s))


if __name__ == '__main__':
    n = int(input())
    hms(n)

Measured memory_bytes: 7716
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAXC 12
int N,dis[MAXC][MAXC];
int main()
{
	int m;
	while(~scanf("%d",&N)&&N)
	{
		for(int i=0;i<=9;i++)
			for(int j=0;j<=9;j++)
				if(i==j)
					dis[i][j]=0;
				else
					dis[i][j]=0x3FFFFFFF;
		m=0;
		for(int i=1,a,b,c;i<=N;i++)
		{
			scanf("%d%d%d",&a,&b,&c);
			m=max(m,max(a,b));
			dis[a][b]=dis[b][a]=c;
		}
		for(int k=0;k<=m;k++)
			for(int i=0;i<=m;i++)
				for(int j=0;j<=m;j++)
					dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
		int mn=0x3FFFFFFF,id,sum;
		for(int i=0;i<=m;i++)
		{
			sum=0;
			for(int j=0;j<=m;j++)
				sum+=dis[i][j];
			if(mn>sum)
			{mn=sum;id=i;}
		}
		printf("%d %d\n",id,mn);
	}
	return 0;
}

Measured memory_bytes: 2704
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int fa1[N],fa2[N];
map<pair<int,int>,int> mp;
int get1(int x)
{
    if(x==fa1[x])
        return x;
    else
        return fa1[x]=get1(fa1[x]);
}
int get2(int x)
{
    if(x==fa2[x])
        return x;
    return fa2[x]=get2(fa2[x]);
}
void merge1(int x,int y)
{
    int fx=get1(x),fy=get1(y);
    if(fx!=fy)
        fa1[fx]=fy;
}
void merge2(int x,int y)
{
    int fx=get2(x),fy=get2(y);
    if(fx!=fy)
        fa2[fx]=fy;
}
int main()
{
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
        fa1[i]=fa2[i]=i;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        merge1(x,y);
    }
    for(int i=1;i<=k;i++)
    {
        int x,y;
        scanf("%d %d",&x,&y);
        merge2(x,y);
    }
    for(int i=1;i<=n;i++)
        mp[make_pair(get1(i),get2(i))]++;
    for(int i=1;i<=n;i++)
        printf("%d%c",mp[make_pair(get1(i),get2(i))],i!=n?' ':'\n');
    return 0;
}

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

int main(){
    int N, M, count, ans;
    count = 0;
    ans = 0;
    cin >> N >> M;
    int tmp1=0, tmp2=0;

    for (int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        if (a < N){
            tmp1 += (N-a);
            tmp2 = max(tmp2, (N-a));
        }
    }

    cout << tmp1 - tmp2 << endl;
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  cout << N/3 << endl;
  return 0;
}


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

#define D_iN	200

int main (void) {
	int ii=0, iRetValue=0, iN=0, iA[D_iN], iCount=0;
	int	a=0, b=0, c=0;

	iRetValue = scanf ("%d", &iN);
	for (ii=0; ii < iN; ii++) {
		iRetValue = scanf ("%d", &iA[ii]);
	}

	while (1) {
		for (ii=0; ii < iN; ii++) {
			//c=a-(a/b)*b;
//			a = iA[ii] >> 1;	// /2
//			b = a << 1;			// x2
//			c = iA[ii] - b;		// 1 - 

			a = iA[ii] >> 1;	// /2
			c = iA[ii] - (a << 1);
			if (c == 0) {
//				iA[ii] = a;
				iA[ii] = iA[ii] >> 1;
			} else {
				goto l_Exit;
			}
		}
		iCount++;
	}

l_Exit:
	printf ("%d\n", iCount);

	return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/

signed main(){
  int a, b;
  cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;
  return 0;
}


Measured memory_bytes: 256
use std::io;


fn main() {
    let (h, w) = {
        let i = read::<usize>();
        (i[0], i[1])
    };
    let mut aw = Vec::new();
    for _ in 0..h {
        let i = read_one::<String>().chars().collect::<Vec<char>>();
        aw.push(i);
    }

    let mut bw = aw.clone();
    for i in (0..h).rev() {
        let mut flg = true;
        for j in (0..w).rev() {
            if aw[i][j] != '.' { flg = false; }
        }
        if flg { bw.remove(i); }
    }

    let mut cw = bw.clone();
    for i in (0..bw[0].len()).rev() {
        let mut flg = true;
        for j in (0..bw.len()).rev() {
            if bw[j][i] != '.' { flg = false; }
        }
        if flg {
            for k in 0..bw.len() {
                cw[k].remove(i);
            }
        }
    }
    for row in cw {
        for c in row {
            print!("{}", c);
        }
        println!();
    }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<iostream>
using namespace std; // 575

int main() {
	int N, K;
	string S;
	cin >> N >> K >> S;
	S = '1' + S + '1';
	int ans = 1;
	for (int l = 1, r = 1, cng = 0;r <= N;ans = max(ans, ++r - l)) {
		if (r <= N && S[r - 1] == '1' && S[r] == '0') { // 0の区間を追加すると逆立ち回数は1増える
			if (++ cng > K) {
				-- cng;
				++ l;
				while (S[l - 1] == '1' || S[l] == '0') ++ l; // 逆側の0の区間を1個外す必要がある
			}
		}
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

答えとなる区間はある連続した区間であることに着目する
しゃくとり法を利用する
区間[l, r)が全員逆立ちした区間になるには何回の操作が必要か？を考える
これは、1から0に代わる瞬間に操作回数+1なことを利用すればいい
*/

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h1,h2,k1,k2;
  int a,b,c,d;
  cin >> h1 >> h2 >> k1 >> k2;
  cin>> a >> b >> c >> d;
  int h=0;
  int k=0;
  h+=h1*a;
  h+=h2*b;
  k+=k1*a;
  k+=k2*b;
  h+=(h1/10)*c;
  k+=(k1/10)*c;
  h+=(h2/20)*d;
  k+=(k2/20)*d;

  // cout << h << endl << k << endl;
  if(h>k)cout << "hiroshi" << endl;
  else if(h<k)cout << "kenjiro" << endl;
  else cout << "even" << endl;
  return 0;
}

Measured memory_bytes: 3100
import Control.Monad


main = do
  n <- getLine
  q <- readLn
  a <- map words <$> replicateM q getLine

  putStrLn $ f2 $ foldl f (True, n, "") a

f :: (Bool, String, String) -> [String] -> (Bool, String, String)
f (flag, l, r) [[c1]]
  | c1 == '1' = (not flag, r, l)
f (flag, l, r) [[c1], [c2], [c]]
  | flag && c2 == '1' = (flag, c : l, r)
  | flag && c2 == '2' = (flag, l, c : r)
  | not flag && c2 == '2' = (flag, l, c : r)
  | otherwise = (flag, c : l, r)

f2 :: (Bool, String, String) -> String
f2 (f, l, r) = l ++ reverse r




Measured memory_bytes: 78204
#include<stdio.h>

int main()
{
    int t,p=0,w=0,g=0,y=0,i;
    scanf("%d",&t);
    char A[t];
    for(i=0;i<t;i++){
        scanf("%s",&A[i]);
        if(A[i]=='P') p++;
        if(A[i]=='W') w++;
        if(A[i]=='G') g++;
        if(A[i]=='Y') y++;
    }
    if(p&&w&&g&&y)
        printf("Four\n");
    else
        printf("Three\n");
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int MOD=1000000007;
signed main(){
    int n;cin>>n;
    vector<int> a(n);rep(i,n)cin>>a[i];
    int res=0;
    vector<int> inc(a);
    sort(inc.begin(),inc.end());
    vector<int> odd;vector<int> even;
    rep(i,n){
        if(i%2==1)odd.push_back(a[i]);
        else even.push_back(a[i]);
    }
    sort(odd.begin(),odd.end());
    sort(even.begin(),even.end());
    int odd_sum=0;int even_sum=0;
    rep(i,n){
        if(i%2==1){
            if(!binary_search(odd.begin(),odd.end(),inc[i])){
                odd_sum++;
            }
        }
        else{
            if(!binary_search(even.begin(),even.end(),inc[i])){
                even_sum++;
            }
        }
    }
    res=min(odd_sum,even_sum);
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2812
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod=998244353,M=(1<<18)+10;
ll ksm(ll x,ll k){ll re=1;for(;k;k>>=1,x=x*x%mod)if(k&1)re=re*x%mod;return re;}
int pls(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int mns(int x,int y){return x-y<0?x-y+mod:x-y;}


int n,p[M],bin[20];ll s,x,y;ll inv2=ksm(2,mod-2);
void fwt(int *a){
	for(int i=1;i<bin[n];i<<=1)
		for(int j=0;j<bin[n];j+=2*i)
			for(int k=0;k<i;k++) {
				x=a[j+k];y=a[j+k+i];a[j+k]=pls(x,y);a[j+k+i]=mns(x,y);
			}
}
void ifwt(int *a){
	for(int i=1;i<bin[n];i<<=1)
		for(int j=0;j<bin[n];j+=2*i)
			for(int k=0;k<i;k++) {
				x=a[j+k];y=a[j+k+i];a[j+k]=pls(x,y)*inv2%mod;a[j+k+i]=mns(x,y)*inv2%mod;
			}
}
int A[M];
int main(){
	//freopen("a.in","r",stdin);
	scanf("%d",&n);
	bin[0]=1;for(int i=1;i<=n;i++)bin[i]=bin[i-1]<<1;
	for(int i=0;i<bin[n];i++)scanf("%d",&p[i]),s=pls(s,p[i]);s=ksm(s,mod-2);
	for(int i=0;i<bin[n];i++)p[i]=p[i]*s%mod;
	A[0]=bin[n]-1;for(int i=1;i<bin[n];i++)A[i]=mod-1;
	fwt(A);p[0]=mns(p[0],1);
	fwt(p);
	for(int i=0;i<bin[n];i++)A[i]=A[i]*ksm(p[i],mod-2)%mod;
	ifwt(A);
	for(int i=0;i<bin[n];i++)printf("%d\n",(A[i]-A[0]+mod)%mod);
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PL;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

ll V, E;
vector< vector< pair<ll,ll> > > G;
ll rec[15][1<<15];
const ll INF = 1e9;

void rec_init() {
    rep(i, 0, 15) rep(j, 0, 1<<15) rec[i][j] = -1;
}

ll dfs(int bit, ll last, ll srt) {

    // check memo
    if(rec[last][bit] != -1) return rec[last][bit];

    // end point
    if(bit == (1<<last)){
        for(PL g : G[last]) {
            if(g.first == srt) return rec[last][bit] = g.second;
        }
        return rec[last][bit] = INF;
    }

    // move to previous node
    ll res = INF;
    int prev = bit & ~(1<<last);
    for(PL g : G[last]){
        if(!(prev & (1<<g.first))) continue;
        res = min(res, dfs(prev, g.first, srt) + g.second); 
    }

    // return
    return rec[last][bit] = res;
}

int main(){

    // input
    cin >> V >> E;
    G.resize(V);
    rep(i, 0, E){
        ll s, t, d;
        cin >> s >> t >> d;
        G[t].push_back({s, d});
    }

    // memorizing dfs
    ll ans = INF;
    rep(srt, 0, V){
        rec_init();
        ans = min(ans, dfs((1<<V)-1, srt, srt));
    }

    // output
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6932
#include<stdio.h>

struct Dice{
  int above;
  int under;
  int north;
  int south;
  int east;
  int west;
};

//サイコロの操作をする関数
void Operate(struct Dice *dice, char *order);

int main(){
  int n,i;
  char order[8];
  int point;

  scanf("%d", &n);
  while(n != 0){
    point = 1;
    //ダイスの初期化
    struct Dice dice={1,6,5,2,3,4};

    for(i=0;i<n;i++){
      scanf("%s", order);  //操作の命令入力
      Operate(&dice,order);//ダイスの操作
      point += dice.above; //ポイント加算
    }
    printf("%d\n",point);//output
    scanf("%d", &n);
  }
  return 0;
}

void Operate(struct Dice *dice, char *order){
  int above,under,north,south,east,west;
  above = dice->above;
  under = dice->under;
  north = dice->north;
  south = dice->south;
  east = dice->east;
  west = dice->west;

  if(!strcmp(order, "North")){
    dice->above = south;
    dice->under = north;
    dice->north = above;
    dice->south = under;
  }
  else if(!strcmp(order, "East")){
    dice->above = west;
    dice->under = east;
    dice->east = above;
    dice->west = under;
  }
  else if(!strcmp(order, "West")){
    dice->above = east;
    dice->under = west;
    dice->east = under;
    dice->west = above;
  }
  else if(!strcmp(order, "South")){
    dice->above = north;
    dice->under = south;
    dice->north = under;
    dice->south = above;
  }
  else if(!strcmp(order, "Right")){
    dice->north = west;
    dice->south = east;
    dice->east = north;
    dice->west = south;
  }
  else if(!strcmp(order, "Left")){
    dice->north = east;
    dice->south = west;
    dice->east = south;
    dice->west = north;
  }
  else{
    printf("operate error.\n");
  }
}

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

int main() {
	// your code goes here
	int n,m;
	cin>>n>>m;
	vector<int>rooms(n+1,-1);
	unordered_map<int,vector<int>>conn;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		conn[x].push_back(y);
		conn[y].push_back(x);
	}
	queue<int>q;
	unordered_set<int>s;
	q.push(1);
	s.insert(1);
	int count=n-1;
	while(!q.empty()){
		int sizes=q.size();
		for(int i=0;i<sizes;i++){
			int val=q.front();
			q.pop();
			for(int j=0;j<(int)conn[val].size();j++){
				int curr=conn[val][j];
				if(s.find(curr)==s.end()){
					count--;
					q.push(curr);
					rooms[curr]=val;
					s.insert(curr);
				}
			}
		}
	}
	if(count!=0){
		cout<<"No";
		return 0;
	}
	cout<<"Yes"<<endl;
	for(int i=2;i<=n;i++){
		cout<<rooms[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 17708
N= int(input())
S=input()
r=[]
g=[]
b=[]
A=0
B=0
C=0
for i in range(N):
    if S[i]=="R":
        r.append(i)
        A+=1
    elif S[i]=="G":
        g.append(i)
        B+=1
    else:
        b.append(i)
        C+=1
k=0
for i in range(N-2):
    for j in range(i+1,N-1):
        t=2*j-i
        if t<N:
            if S[i]!=S[j] and S[i]!=S[t] and S[t]!=S[j] :
                k+=1

print(A*B*C-k)

Measured memory_bytes: 9236
p = [1, 0, 0, 0]
m = 1e9 + 7
def mod(x):
    return int(x % m)

for s in input():
    if s == 'A' :
        p[1] = mod(p[0] + p[1])
    if s == 'B' :
        p[2] = mod(p[1] + p[2])
    if s == 'C' :
        p[3] = mod(p[2] + p[3])
    if s == '?':
        p[3] = mod(p[2] + p[3] * 3)
        p[2] = mod(p[1] + p[2] * 3)
        p[1] = mod(p[0] + p[1] * 3)
        p[0] = mod(p[0] * 3)
        
print(int(p[3] % m))

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

int main(){
  string s;
  cin >> s;
  int K;
  cin >> K;
  int N=s.size();
  priority_queue<string,vector<string>,greater<string> > pq;
  string temp;
  for(int i=0;i<N;i++){
    pq.push(s.substr(i,1));
  }
  for(int i=1;i<K;i++){
    temp=pq.top();
    if(pq.top()==s.substr(N-temp.size(), temp.size())){
      pq.pop();
    }
    if(temp==pq.top()){
      while(temp==pq.top()){
        pq.pop();
        if(pq.empty()){
          break;
        }
      }
      for(int j=0;j<N-temp.size();j++){
        if(temp==s.substr(j,temp.size())){
          pq.push(s.substr(j,temp.size()+1));
        }
      }
    }
  }
  cout << pq.top() << endl;
  return 0;
}


Measured memory_bytes: 3744
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>

using namespace std;

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

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

const int Maxn = 50;
const int Maxm = 500;
const int INF = (int) 1e7;

int dp[Maxn][Maxm][Maxm];
int a[Maxn], b[Maxn], c[Maxn];

int n, A, B;

int main() {
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
     */
    cin >> n >> A >> B;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i] >> c[i];
    }
    for (int i = 0; i < n + 1; ++i) {
        for (int j = 0; j < Maxm; ++j) {
            fill(dp[i][j], dp[i][j] + Maxm, INF);
        }
    }
    dp[0][0][0] = 0;

    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < Maxm; ++j) {
            for (int k = 0; k < Maxm; ++k) {
                dp[i + 1][j][k] = dp[i][j][k];
                if (j - a[i] >= 0 && k - b[i] >= 0) {
                    dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
                }
            }
        }
    }

    int ans = INF;
    for (int i = 1; i < Maxm; ++i) {
        if (i % A) continue;
        if (i / A * B < Maxm) {
            ans = min(ans, dp[n][i][i / A * B]);
        }
    }
    if (ans == INF) cout << -1 << endl;
    else cout << ans << endl;
}

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

int main() {
    int64_t A, B, C, K;
    cin >> A >> B >> C >> K;
    if (A >= K) {
        cout << K << endl;
    } else if (A + B >= K) {
        cout << A << endl;
    } else {
        cout << A - (K - A - B) << endl;
    }
}

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

int main() {
    long long n, k;
    cin >> n >> k;
    if (k % 2 == 0) {
        long long a = n / (k);
        long long b = (n + (k/2)) / (k);
        cout << a*a*a + b*b*b << endl;
    }
    else {
        long long a = n / k;
        cout << a*a*a << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
int main(){
  string S, T;
  cin >> S >> T;
  cout << T << S;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

const int mod = 998244353;
using mint = ModInt<mod>;

int main() {
    int n, s;
    cin >> n >> s;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    mint ans = 0;
    vector<mint> dp(s + 1);
    dp[0] = 1;
    rep(i, n) {
        vector<mint> nx(s + 1);
        rep(j, s + 1) {
            int nj = j + a[i];
            if (nj > s) continue;

            mint add = dp[j];
            if (j == 0) add *= i + 1;
            nx[nj] += add;
        }
        ans += nx[s] * (n - i);

        rep(j, s + 1) nx[j] += dp[j];
        swap(dp, nx);
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define IO std::ios::sync_with_stdio(false);std::cin.tie(0)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mset(s,_) memset(s,_,sizeof s)
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define mk make_pair
using namespace std;
const int maxn=1000010;
ll vp[maxn+10],p[maxn+10];
void prime(){
	  vp[0]=vp[1] = 1;    //0和1为合数
	for(ll i = 2; i < maxn; i++){
		if(!vp[i]) p[++p[0]] = i;        //p[]里面的是素数
		for(ll j = 1; j <=p[0] && i * p[j]<maxn; j++){
			vp[i * p[j]] = 1;
			if(i % p[j] == 0) break;
		}
	}
}
vector<ll>v;
void init(){
	for(ll i=1;i<=p[0];i++){
		for(ll j=p[i];j<=1000000000000;j*=p[i]){
			v.push_back(j);
		}
	}
}
int main(){
 prime();
 init();
 ll n;
 sort(v.begin(),v.end());
 while(cin>>n){
 int ans=0,w1=0;
 for(int i=0;i<v.size();i++){
 	if(n%v[i]==0) n/=v[i],ans++,vp[v[i]]=1;
	if(n<v[i]) break;
  }
		if(n>1000000) cout<<ans+1<<'\n';
		else cout<<ans<<'\n';
 }
}




Measured memory_bytes: 13636
N = int(input())

if N % 2 != 0:
    print(0)

else:
    result_2 = 0
    n = N
    while n > 0:
        n //= 2
        result_2 += n

    result_5 = 0
    n = N // 2
    while n > 0:
        n //= 5
        result_5 += n
        
    print(min(result_2, result_5))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {}

class C {
 public:
  string s;
  C() { cin >> s; }
  ~C() {
    int len = s.size();
    char first = s[0];
    char last = s[len - 1];
    cout << first << len - 2 << last << endl;
  }
} x;



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

template<typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
/*
全部で1つのサーキットになってないとダメなのはそう
その上で4つ以上のそれが3つあったらYes?
*/
typedef pair<int,int> P;
set<P> s;
bool in(int u,int v){
  if(u>v)swap(u,v);
  return (s.count(P(u,v)));
}
void to(int u,int v){
  if(u>v)swap(u,v);
  s.insert(P(u,v));
}

signed main(){
  int N,M;cin>>N>>M;
  vector<int> edge[N];
  for(int i=0;i<M;i++){
    int u,v;cin>>u>>v;u--;v--;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  int six,four;six=four=0;
  for(int i=0;i<N;i++){
    if(edge[i].size()&1)fin("No");
    six+=(edge[i].size()>=6);
    four+=(edge[i].size()==4);
  }
  if(six||four>2)fin("Yes");
  if(four<2)fin("No");
  int u=-1,v;
  for(int i=0;i<N;i++){
    if(edge[i].size()==4){
      if(~u)v=i;
      else u=i;
    }
  }
  for(int i=0;i<4;i++){
    int now=edge[u][i];
    to(u,now);
    while(now!=v){
      if(now==u)fin("Yes");
      int a=edge[now][0];
      if(!in(now,a)){
        to(now,a);
        now=a;
      }
      else{
        a=edge[now][1];
        to(now,a);
        now=a;
      }
    }
  }
  fin("No");
}


Measured memory_bytes: 10368
#include<stdio.h>
#include<stdlib.h>
long int GCD(long long int x,long long int y){
	long long int big,sml,i;
	if(x>y){
		big=x;sml=y;
	}else{
		big=y;sml=x;
	}
	while(big%sml!=0){
		i=sml;
		sml=(big%i);
		big=i;
	}
	return sml;
}

int main(){
	long long int a,b,gcd,lcm;
	while(scanf("%lld %lld",&a,&b)!=EOF){
		gcd=GCD(a,b);
		lcm=a*b/gcd;
		printf("%lld %lld\n",gcd,lcm);
	}
    return 0;
}

Measured memory_bytes: 596
import numpy as np
Q = int(input())
lr = [list(map(int, input().split())) for _ in range(Q)]

is_prime = np.zeros(10**5 + 1, dtype='bool')
for i in range(2, 10**5 + 1):
    if not is_prime[i]:
        for j in range(2, int(np.sqrt(i) + 1)):
            if i % j == 0:
                break
        else:
            is_prime[i] = True
            # is_prime[::i] = True
# print(is_prime[:10])

like_2017 = np.zeros(10**5 + 1, dtype='bool')
for i in range(1, 10**5 + 1):
    if is_prime[i] and is_prime[(i + 1) // 2]:
        like_2017[i] = True
# print(like_2017)
# print(like_2017.cumsum())
cumsum = like_2017.cumsum()

for l, r in lr:
    print(cumsum[r] - cumsum[l - 1])


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

#include "atcoder/dsu"
using namespace std;
typedef long long int ll;

int main(int, char **) {
    int n, q;
    cin >> n >> q;
    atcoder::dsu uf(n);
    for (int i = 0; i < q; i++) {
        int t, u, v;
        cin >> t >> u >> v;
        if (t == 0) {
            uf.merge(u, v);
        } else {
            cout << (int)uf.same(u, v) << "\n";
        }
    }

    fflush(stdout);
}


Measured memory_bytes: 3976
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

ll solve(ll n, ll x, vector<ll> p, vector<ll> sz){
    assert(x <= sz[n]);
    if(x == 0)return 0;
    if(sz[n]-1 <= x)return p[n];
    if(n == 0)return p[n];
    if(x <= 1 + sz[n-1])return solve(n-1, x-1, p, sz);
    if(x == sz[n-1] + 2)return p[n-1] + 1;
    else return p[n-1] + 1 + solve(n-1, x-(sz[n-1]+2), p, sz);
}

int main(){
    ll n,x; cin >> n >> x;
    vector<ll> p(n+1), sz(n+1);
    p[0] = 1;sz[0] = 1;
    rep(i,n+1){
        if(!i)continue;
        p[i] = p[i-1] * 2 + 1;
        sz[i] = sz[i-1] * 2 + 3;
    }

    cout << solve(n,x,p,sz) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		long sum[] = new long[num + 2];
		sum[0] = 0;
		for(int i = 1; i <= num; i ++) {
			sum[i] = sum[i - 1] + sc.nextLong();
		}
		sum[num + 1] = Long.MAX_VALUE;
		Arrays.sort(sum);
		long ans = 0;
		long tmp = 1;
		for(int i = 0; i <= num; i ++) {
			if(sum[i] == sum[i + 1]) {
				tmp ++;
			}else {
				ans += tmp * (tmp - 1) / 2;
				tmp = 1;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 88612
#include <stdio.h>
#include <set>
#include <algorithm>

using namespace std;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)

int n,m;
pii ranges[353531];   // sort by first, [left, right]
pii ranges2[353531];  // sort by second, [right, id]

int ans[125252];

const int B = 500;
const int C = 252;

// pointer struct
struct data{
  // id, position, in-iterator, out-iterator
  int id,pos,in,out;
};
data pts[C];
int cnt[353531];

int main(){
  // input
  scanf("%d%d",&n,&m);
  REP(i,n){
    int l,r;
    scanf("%d%d",&l,&r);
    ranges[i] = pii(l,r);
  }
  
  // d small
  FOR(d,1,min(B,m+1)){
    int tmp = 0;
    REP(i,n){
      int x = (ranges[i].first+d-1)/d;
      if(x*d<=ranges[i].second)tmp++;
    }
    ans[d]=tmp;
  }

  // d large
  // sort
  sort(ranges,ranges+n);
  REP(i,n)ranges2[i]=pii(ranges[i].second, i);
  sort(ranges2,ranges2+n);

  // pointer init
  data yo;
  yo.id=0; yo.pos=0; yo.in=0; yo.out=0;
  set<int> S;
  int tmp = 0;
  FOR(i,1,m+1){
    yo.pos++;
    while(yo.in<n && ranges[yo.in].first==yo.pos){
      S.insert(yo.in);
      yo.in++;
    }
    while(yo.out<n && ranges2[yo.out].first<yo.pos){
      S.erase(S.find(ranges2[yo.out].second));
      yo.out++;
    }
    if(i%B==0){
      // pts
      pts[yo.id] = yo;
      yo.id++;
      for(int x : S){
        if(cnt[x]==0)tmp++;
        cnt[x]++;
      }
    }
  }

  int pts_len = yo.id;
  FOR(d,min(B,m+1),m+1){
    ans[d] = tmp;
    if(d==m)break;
    REP(i,pts_len){
      if(pts[i].pos > m)break;
      // step pts[i]
      pts[i].pos += i+1;
      while(pts[i].in<n && ranges[pts[i].in].first<=pts[i].pos){
        if(cnt[pts[i].in]==0)tmp++;
        cnt[pts[i].in]++;
        pts[i].in++;
      }
      while(pts[i].out<n && ranges2[pts[i].out].first<pts[i].pos){
        int id = ranges2[pts[i].out].second;
        cnt[id]--;
        if(cnt[id]==0)tmp--;
        pts[i].out++;
      }
    }
  }
  FOR(d,1,m+1)printf("%d\n",ans[d]);
  return 0;
}


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

int top, C[1000];

void push(int num){
   C[++top]=num;
}
int pop(){
  top--;
  return C[top+1];
}
int main(){
  top=0;
  int a,b,status;
  char s[100];
  while(scanf("%s",s)!=EOF){
       if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if(s[0]=='-'){
      b=pop();
      a=pop();
 push(a-b);
    }else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }else {
      push(atoi(s));
    }
  }
  printf("%d\n",pop());

  return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>

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

int main(){
  int hw,days,sum=0;
  cin >> days >> hw;
  int times[hw];
  for(int i=0;i<hw;i++){
    cin >> times[i];
    sum+=times[i];
  }
  int vacation=days-sum;
  if (vacation>=0)
    cout << vacation << endl;
  else
    cout << "-1" << endl;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    cin >>N;
    if(N>=1000){
        N-=999;
        cout<<"ABD"<<endl;;
       
    }else{
        cout<<"ABC"<<endl;;
       
    
    }



    return 0;
    

}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
   cin >> vec.at(i);
    }
  
  int A = 0;
  for (int i = 0; i < N; i++) {
   if (vec.at(i) == 1) {
     break;
   }
   else if(i == N - 1) {
     if (vec.at(i) != 1) {
     A = -1;
     cout << A << endl;
     exit(0);
     }
   }
  }
  int i = 0;
  int j = 1;
  while (i < N) {
   if(vec.at(i) == j) {
    i++;
    j++;
    if (i == N) {
     break;
    }
   }
   else {
   i++;
   A++;
   }
  }
  cout << A << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
ll isPrime[1000010]={0};
vector<ll> Prime;

void sieve(){
	ll i,j;
	isPrime[0] = isPrime[1] = 1;
	for( i=2; i<1000010; i++)if(isPrime[i]==0)for(j=2*i; j<1000010; j+=i)isPrime[j]=1;
	for( i=1; i<1000010; i++)if(isPrime[i]==0)Prime.push_back(i);
}
ll modMul(ll a,ll b,ll mod){
	ll res=0;
	if(mod<=MOD){
        return ((a%mod)*(b%mod))%mod;
	}
	while(b){
		if(b&1)res = (res+a)%mod;
		a = (2*a)%mod;
		b = b/2;
	}
	return res;
}
ll modPow(ll x,ll n,ll mod){
	ll r = 1;
	while(n){
		if(n&1)r = modMul(r,x,mod);
		x = modMul(x,x,mod);
		n = (n>>1);
	}
	return r;
}
vector<int>v;
void printDivisors(int n) 
{ 
    // Vector to store half of the divisors 3343434 
    for (int i=1; i<=sqrt(n); i++) 
    { 
        if (n%i==0) 
        { 
            if (n/i == i) // check if divisors are equal 
                if (i%2!=0){
                	v.push_back(i);
				} 
            else
            { 
                if (i%2!=0){
                	v.push_back(i);
				}  
  
                // push the second divisor in the vector 
                if ((n/i)%2!=0){
                	v.push_back(n/i);
				} 
            } 
        } 
    } 
  
    // The vector will be printed in reverse 
} 
long long int dp[101][100001];
long long int knapsack(int a[],int w[],int n,int W){
	if (n==0||W==0){
		return 0;
	}
	if (dp[n][W]!=-1){
		return dp[n][W];
	}
	if (W<w[n-1]){
		return dp[n][W]=knapsack(a,w,n-1,W);
	}
	else{
		return dp[n][W]=max(knapsack(a,w,n-1,W),a[n-1]+knapsack(a,w,n-1,W-w[n-1]));
	}
	
}
void solve (){
	int n,W;
	cin>>n>>W;
	int a[n],w[n];
	for(int i=0;i<n;i++){
		cin>>w[i];
		cin>>a[i];
	}
	cout<<knapsack(a,w,n,W)<<endl;
}
	
	

int main(){
	int t;
	//cin>>t;
	t=1;
	memset(dp,-1,sizeof(dp));
	while(t--){
		solve();
		}
		
	}


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

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		long ans = a[n-1];
		int cnt = n - 2;
		for (int i = n-2; i >= 0; i--) {
			if (cnt > 0) {
				ans += a[i];
				cnt--;
			}
			if (cnt > 0) {
				ans += a[i];
				cnt--;
			}
		}
		System.out.println(ans);
	}

}



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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, result = 0, outlet = 1;
    cin >> a >> b;
    while(outlet < b){
        outlet--;
        outlet += a;
        result++;
    }
    cout << result << "\n";
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  int x,y,a,b,c;cin >> x >> y >> a >> b >> c;
  vector<pair<int,int>> tt;
  for(int i=0;i<a;i++){
    int f;cin >> f;
    tt.push_back({f,1});
  }
  for(int i=0;i<b;i++){
    int f;cin >> f;
    tt.push_back({f,2});
  }
  for(int i=0;i<c;i++){
    int f;cin >> f;
    tt.push_back({f,3});
  }
  sort(ALL(tt));
  int cnt = 0;
  a = 0;
  b = 0;
  LL ans = 0;
  while(tt.size()){
    auto it = tt.back();
    tt.pop_back();
    if(it.second==1 && a<x){
      ans += it.first;
      ++a;
      cnt++;
    }else if(it.second==2 && b<y){
      ans += it.first;
      ++b;
      ++cnt;
    }else if(it.second==3){
      ans += it.first;
      ++cnt;
    }
    if(cnt==x+y) break;
  }
  cout << ans << endl;
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 5744
#include<stdio.h>
#define MAX 100

void init();

int G[MAX][MAX];
int n;


void init(){

  int i,j;

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      G[i][j] = 0;
    }
  }

}


int main(){

  int i,j,k = 0,vertex,num,edge;

  scanf("%d\n",&n);
  init();

  for(i = 0; i < n; i++){
    edge = 0;
    scanf("%d %d",&vertex,&edge);
    for(j = 0; j < edge; j++){
      scanf("%d",&num);
      G[i][num-1] = 1;
    }
    scanf("\n");
  }
  
  
  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      if(j == n-1){      
	printf("%d\n", G[i][j]);
      } else {
	printf("%d ", G[i][j]);
      }
    }
  }

  return 0;


}

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

int main() {
  int n, k; cin >> n >> k;
  
  int ans;
  
  if ((n - k) % (k - 1)) {
    ans = (n - k) / (k - 1) + 2;
  } else {
    ans = (n - k) / (k - 1) + 1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <math.h>
#include <numeric>
#include <iomanip>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define ppll pair<pll,ll>
#define vi vector <ll>
#define out(x) return cout<<x,0;
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define f(i,x,n) for(ll i=x;i<n;i++)
#define lc(n) 2*n+1
#define rc(n) 2*n+2
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;} 
const ll N = 2e5 + 5, M = 1e9 + 7;

int main(){
    FAST;
    ll n, x = 0, m, k, i, t, ans = 0, j, y = 0, z = 0, c = 0;
    string s;
    cin >> n;
    x = n / 500;
    n -= x*500;
    ans = 1000*x;
    x = n / 5;
    cout << ans + 5*x;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int list[n];
  for (int i = 0; i < n; i++) {
    list[a[i]-1] = i+1;
  }
  for (int i = 0; i < n-1; i++) {
    printf("%d ", list[i]);
  }
  printf("%d\n", list[n-1]);

  return 0;
}

Measured memory_bytes: 1536
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

type priorityQueue []int

func (p priorityQueue) Len() int            { return len(p) }
func (p priorityQueue) Less(i, j int) bool  { return p[i] > p[j] } // 大きい順に取り出すので不等号の向きに注意
func (p priorityQueue) Swap(i, j int)       { p[i], p[j] = p[j], p[i] }
func (p *priorityQueue) Push(x interface{}) { *p = append(*p, x.(int)) }
func (p *priorityQueue) Pop() interface{} {
	old := *p
	n := len(old)
	x := old[n-1]
	*p = old[0 : n-1]
	return x
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	jobs := make(map[int][]int)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		var a, b int
		a = nextInt(sc)
		b = nextInt(sc)
		jobs[a] = append(jobs[a], b)
	}
	// fmt.Println("n", n, "m", m, "jobs", jobs)
	pq := make(priorityQueue, 0, n)
	heap.Init(&pq)
	ans := 0
	for i := 1; i <= m; i++ { // 〆切日より1日前から始める
		for _, v := range jobs[i] { // i日後に給料日がある日をpqに追加する
			//fmt.Printf(" q[d:%d,p:%d]\n", i, v)
			heap.Push(&pq, v)
		}
		if len(pq) > 0 { // 1日に一個の仕事しかできないので、dequeueはiにつき一回だけ
			t := heap.Pop(&pq).(int)
			//fmt.Printf("dq[d:%d,p:%d]\n", i, t)
			ans += t
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 11648
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
inline ll f(ll a){return a?f(a/10)+1:0;}
inline ll f(ll a,ll b){return max(f(a),f(b));}
int main(){ll n,m,s=11; scanf("%lld",&n);m=sqrt(n);for(register ll i=1;i<=m;++i)if(n%i==0)s=min(s,f(i,n/i));printf("%lld",s);return 0;}

Measured memory_bytes: 128
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    int n;
    cin>>n;
    vector<int> s(n);
    rep(i,n){
        cin>>s[i];
    }

  vector<int> k(n+1,0);

  for(int i=n-1;i>=0;i--){
      int m = s[i];

      if(m+1<=n){
          k[m]=k[m+1]+1;
      }else{
          k[m]=1;
      }
  }


  sort(k.rbegin(),k.rend());
  cout<<n-k[0]<<endl;


    return 0;
}


Measured memory_bytes: 1792
N = int(input())
A = list(map(int, input().split()))

right = -1
ans = 0
tmp = 0
f_0 = 0
for left in range(len(A)):
    tmp -= f_0
    while(True):
        right += 1
        if(right == N):
            break
        if(bin(tmp + A[right]) == bin(tmp ^ A[right])):
            tmp += A[right]
        else:
            break
    ans += right - left
    f_0 = A[left]
    right -= 1
    # print(left, right)

print(ans)

Measured memory_bytes: 24840
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}

// }}}

struct Program {
    int s, t, c;

    Program(int ss, int tt, int cc): s(ss), t(tt), c(cc) {}

    bool operator<(const Program &rhs) const {
        if(s < rhs.s) return true;
        else if(s == rhs.s){
            return t < rhs.t;
        }else{
            return false;
        }
    }

};

ostream& operator<<(ostream &os, Program &prog) {
    os << prog.s << " " << prog.t << " " << prog.c;
    return os;
}

int N, C;
vector<Program> p;

void solve()
{
    sort(ALL(p));
    vector<P> v;
    int ans = 0;
    REP(i, N){
        bool ok = false;
        for(auto &r: v){
            if(p[i].c == r.fi){
                if(r.se <= p[i].s){
                    ok = true;
                    r.se = p[i].t;
                }
            }else{
                if(r.se < p[i].s){
                    ok = true;
                    r.se = p[i].t;
                    r.fi = p[i].c;
                }
            }
            if(ok) break;
        }
        if(!ok) v.pb(mp(p[i].c, p[i].t));
    }
    cout << v.size() << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> C;
    REP(i, N){
        int s, t, c;
        cin >> s >> t >> c;
        p.pb(Program(s, t, c));
    }
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 1912
MOD = 10 ** 9 + 7
X, Y = map(int, input().split())

if (X + Y) % 3 or Y > 2 * X or Y < X // 2:
    print(0)
    exit()

n = (X + Y) // 3
r = X - (X + Y) // 3
num, den = 1, 1
if n - r < r:
    r = n - r
for i in range(1, r + 1):
    num *= n - i + 1
    num %= MOD
    den *= i
    den %= MOD

print((num * pow(den, MOD - 2, MOD)) % MOD)

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

int main()
{
    int n, count = 0;
    char s[200010][11];

    scanf("%d", &n);

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

    qsort(s, n, 11, strcmp);

    for (int i = 0; i < n; i++)
    {
        if (strcmp(s[i], s[i + 1]) != 0)
            count++;
    }

    printf("%d", count);

    return 0;
}


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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

ll mod=1000000007;

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;}

int main() {
  ll a,b,v,w,t;
  cin>>a>>v>>b>>w>>t;
  if(v<=w){cout<<"NO";return 0;}
  ll dist=abs(a-b);
  ll d=t*abs(v-w);
  if(d<dist)cout<<"NO";
  else cout<<"YES";
}

Measured memory_bytes: 3624