akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
 
int main(){
  static bool cmp[1000000]={true};
  static int npr[1000000];
  for(int i=2;i<1000000;i++){
    if(!cmp[i]){
      for(int j=2;j*i<1000000;j++){
    	cmp[i*j]=true;
      }
    }
    npr[i]=npr[i-1]+!cmp[i];
  }
  for(int n;cin>>n;n++){
    cout<<npr[n]<<endl;
  }
}

Measured memory_bytes: 7940
N=int(input())
L= list(map(int,input().split()))
L_sorted=sorted(L,reverse=False)#昇順
count=0
for i in range(N):
    for j in range(i+1,N):
        a=L_sorted[i]
        b=L_sorted[j]
        n=a+b
        fin=N
        sta=0
        while sta+1<fin:
            m=((fin-sta)//2)+sta
            if L_sorted[m]<n:
                sta=m       
            else:
                fin=m   
        count+=sta-j
print(count)

Measured memory_bytes: 74208
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {

	string s;
	cin >> s;
	reverse(all(s));

	vi sm(s.size() + 1);
	int k = 1;
	rep(i, s.size()) {
		sm[i + 1] = (sm[i] + (s[i] - '0') * k) % 2019;
		k *= 10;
		k %= 2019;
	}
	map<int, int> mp;
	rep(i, s.size() + 1)mp[sm[i]]++;
	ll ans = 0;
	for (auto x : mp)ans += x.second * (x.second - 1) / 2;
	cout << ans << endl;

}

Measured memory_bytes: 4368
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"

using namespace std;

int main()
{
  int n;
  cin >> n;
  int a[200010];
  int ainv[200010];
  for (int i = 1; i <= n; i++)
  {
    cin >> a[i];
    ainv[a[i]] = i;
  }
  int max = 0;
  int check = 0;
  for (int i = 1; i < n; i++)
  {
    if (ainv[i] < ainv[i + 1])
    {
      check++;
      if (max < check)
      {
        max = check;
      }
    }
    else
    {
      check = 0;
    }
  }
  cout << n - 1 - max << "\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <list>

static const int MAX = 100000;

std::vector<int> Graph[MAX];
//std::list<int> out;
std::stack<int> outs;
bool isVisited[MAX];
int N;

void dfs(int u) {
    isVisited[u] = true;
    for (int i = 0; i < Graph[u].size(); i++) {
        int v = Graph[u][i];
        //ha az adott vertex meg nem vizsgalt
        if (!isVisited[v]) {
            //std::cout << "run: " << v << std::endl;
            dfs(v);
        }
    }
    //out.push_front(u);
    outs.push(u);
}

int main()
{
    int start, target, M;
    std::cin >> N >> M;
    for (int i = 0; i < N; i++) isVisited[i] = false;
    for (int i = 0; i < M; i++) {
        std::cin >> start >> target;
        Graph[start].push_back(target);
    }

    for (int i = 0; i < N; i++) {
        if (!isVisited[i])
            dfs(i);
    }

    /*for (std::list<int>::iterator it = out.begin(); it != out.end(); it++) {
        std::cout << *it << std::endl;
    } */
    while (!outs.empty()) {
        std::cout << outs.top() << std::endl;
        outs.pop();
    }


    return 0;
}



Measured memory_bytes: 5952
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
const int maxn=2e3+5,mod=1e9+7;
int n,k;
int fac[maxn*maxn],ifac[maxn*maxn],f[maxn][maxn];
int C(int n,int m){
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
void upd(int &x,int y){
	x=(x+y)%mod;
}
int main(){
	read(n);read(k);
	fac[0]=1;rep(i,1,n*k)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n*k]=power(fac[n*k],mod-2,mod);per(i,n*k-1,0)ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	rep(i,0,n*k)ifac[i]=power(fac[i],mod-2,mod);
	if(k==1){
		printf("%d\n",1);
		return 0;
	}
	f[2][1]=1;
	rep(i,2,n+1)rep(j,1,i){
		if((i==n+1&&j==n+1)||(!f[i][j]))continue;
		upd(f[i+1][j],f[i][j]);
		int rest=n*k-((i-1)+(j-1)*(k-1));
		upd(f[i][j+1],1ll*f[i][j]*C(rest-1,k-2)%mod);
	}
	printf("%lld\n",1ll*f[n+1][n+1]*fac[n]%mod);
	return 0;
}

Measured memory_bytes: 46464
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do { (t*=10)+=ch-'0'; ch=getchar(); } while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const ll mod=(1e9)+7;
const int maxn=(2e5)+10;
int n,tot,nxt[maxn*2],head[maxn],to[maxn*2];
int sz[maxn];
ll ans[maxn],jc[maxn],iv[maxn];
void add(int x,int y) {
	tot++; nxt[tot]=head[x];
	head[x]=tot; to[tot]=y;
}
void DFS(int u,int p) {
	sz[u]=1;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (v==p) continue;
		DFS(v,u);
		sz[u]+=sz[v];
	}
}
void dfs(int u,int p) {
	int a,b;
	for (int i=head[u],v;i;i=nxt[i]) {
		v=to[i];
		if (v==p) continue;
		a=sz[u],b=sz[v];
		ans[v]=ans[u]*sz[u]%mod*sz[v]%mod;
		sz[u]-=sz[v],sz[v]=n;
		ans[v]=ans[v]*iv[sz[u]]%mod*iv[sz[v]]%mod;
		dfs(v,u);
		sz[u]=a,sz[v]=b;
	}
}

int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	jc[0]=iv[0]=jc[1]=iv[1]=1;
	for (int i=2;i<=n;i++) {
		jc[i]=jc[i-1]*i%mod;
		iv[i]=(mod-mod/i)*iv[mod%i]%mod;
	}
	int x,y;
	for (int i=1;i<n;i++) {
		read(x); read(y);
		add(x,y); add(y,x);
	}
	DFS(1,0);
	ans[1]=jc[n];
	for (int i=1;i<=n;i++) ans[1]=ans[1]*iv[sz[i]]%mod;
	dfs(1,0);
	for (int i=1;i<=n;i++) printf("%lld\n",ans[i]);
	return 0;
}
/*
  0. Enough array size? Enough array size? Enough array size? Interger overflow?
  
  1. Think TWICE, Code ONCE!
  Are there any counterexamples to your algo?
    
  2. Be careful about the BOUNDARIES!
  N=1? P=1? Something about 0?
    
  3. Do not make STUPID MISTAKES!
  Time complexity? Memory usage? Precision error?
*/

Measured memory_bytes: 11648
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n;
  while (cin >> n, n) {
    vector<ll> a(n); cin >> a;
    vector<vector<bool>> dp(n+1, vector<bool>(n+1, false));
    rep(i, n+1) dp[i][i] = true;
    rep(w, 2, n+1) rep(l, n) {
      ll r = l + w;
      if (r > n) continue;
      if (dp[l+1][r-1] && abs(a[l] - a[r-1]) <= 1) {
        dp[l][r] = true;
      }
      rep(m, l+1, r) {
        if (dp[l][m] && dp[m][r]) {
          dp[l][r] = true;
        }
      }
    }
    vector<ll> dp2(n+1, 0);
    rep(i, n) {
      chmax(dp2[i+1], dp2[i]);
      rep(j, i, n+1) {
        if (dp[i][j]) {
          chmax(dp2[j], dp2[i] + j-i);
        }
      }
    }
    ll ans = dp2[n];
    cout << ans << endl;
  }
}



Measured memory_bytes: 3228
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,k; cin >> n >> k;
    string s; cin >> s;
    ll ans = 0;
    rep(i,n-1){
        if(s[i] == s[i+1]) ans++;
    }
    ans = min(n-1, ans + 2*k);
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a[26],sz,M=1000000007;
vector<long long int>b;
long long int solve(int i){
	if(i==sz) return 1LL;
	return (b[i]*solve(i+1)%M+solve(i+1)%M)%M;
}

int main(){
	string s;
	int n;
	cin>>n>>s;
	for(int i=0;i<n;i++){
		a[s[i]-'a']++;
	}
	for(int i=0;i<26;i++)
		if(a[i]!=0) b.push_back(a[i]);
	sz=b.size();
	cout<<solve(0)-1;
	return 0;
}

	

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

int main()
{
    int n,Rt,min,max=-2000000000;
    cin>>n;
    cin>>Rt;
    min=Rt;
    for(int i=1;i<n; i++)
   {
        cin>>Rt;
        if(Rt-min>max)
            max=Rt-min;
        if(Rt<min)
            min=Rt;
    }
    cout<<max<<endl;
    return 0;
}



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

int main(){
    cin.tie(0);
   	ios::sync_with_stdio(false);
    int k,s,r = 0;
    cin >> k >> s;
    for (int x = 0; x <= k; x++){
        for (int y = 0; x + y <= s && y <= k; y++){
            if (s - x - y <= k){
                ++r;
            }
        }
    }
    cout << r << endl;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"

void Main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &x : a) {
    cin >> x;
  }

  vector<int> ans(n);

  // n ~ 1
  for (int i = n; i > 0; --i) {
      int sum = 0;
    for (int j = 1; i * j <= n; ++j) {
      if (j == 1) {
        sum += a[i - 1];
      } else {
        sum += ans[i * j - 1];
      }

      if (i * (j + 1) > n) {
        ans[i - 1] = sum % 2;
      }
    }
  }

  vector<int> pos;
  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    if (ans[i] == 1) {
      ++cnt;
      pos.push_back(i);
    }
  }

  cout << cnt << "\n";
  if (cnt != 0) {
    for (const auto &x : pos) {
      cout << x + 1 << "\n";
    }
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 3192
#include <cstdio>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <iostream>
#include <cstring>
#include <queue>
typedef long long ll;

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

using namespace std;
struct Edge {
    int src, dst;
    int weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
    Edge() {}
};

using Graph = vector<vector<Edge>>;

int V, E;
int num_stand; // num of stands
string src, dst;
int cap;
Graph g;

vector<string> c1, c2;
vector<int> d;
vector<string> s;

map<string, int> m;

const int inf = 1e9;

int dist[4010][2100]; // at town i with gas j
int canCharge[6010];

int dijkstra(int s, int t) {
    fill((int*)begin(dist), (int*)end(dist), inf);
    priority_queue<tuple<int,int, int>> q;// -dist, town, cap
    
    dist[s][cap] = 0;
    q.emplace(0, s, cap);

    while (q.size()) {
        int d, v, rem;
        tie(d, v,rem) = q.top();
        q.pop();
        d = -d;

        if (v == t) return d;

        if (dist[v][rem] < d) continue;
        for (auto &e : g[v]) {
            int nv = e.dst;
            int nrem = rem - e.weight;
            if (nrem < 0) continue;
            if (canCharge[nv]) {
                nrem = cap;
            }
            int nd = d + e.weight;
            if (dist[nv][nrem] > nd) {
                dist[nv][nrem] = nd;
                q.emplace(-nd, nv, nrem);
            }
        }
    }

    return 1e9;
}

int main() {
    while (cin >> E >> num_stand >> cap && E) {
        m.clear();
        V = 0;
        c1.resize(E);
        c2.resize(E);
        d.resize(E);
        cap *= 10;
        cin >> src >> dst;
        if (m.count(src) == 0) m[src] = V++;
        if (m.count(dst) == 0) m[dst] = V++;

        for (int i = 0; i < E; ++i) {
            cin >> c1[i] >> c2[i] >> d[i];
            if (m.count(c1[i]) == 0) m[c1[i]] = V++;
            if (m.count(c2[i]) == 0) m[c2[i]] = V++;
        }

        memset(canCharge, 0, sizeof(canCharge));
        s.resize(num_stand);
        for (int i = 0; i < num_stand; ++i) {
            cin >> s[i];
            canCharge[m[s[i]]] = true;
        }

        g.assign(V, {});
        for (int i = 0; i < E; ++i) {
            int a = m[c1[i]];
            int b = m[c2[i]];
            g[a].emplace_back(a, b, d[i]);
            g[b].emplace_back(b, a, d[i]);
        }

        int ans = dijkstra(m[src], m[dst]);
        if (ans == inf) ans = -1;
        cout << ans << endl;
    }
}

Measured memory_bytes: 61632
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int P = 998244353;
int base = 1e9;
int mul(int a,int b){
  return a * b % P;
}
int mul(int a,int b,int c){
  return a * b % P * c % P;
}
void add(int &a,int b){
  a += b;
  if(a >= P)
    a -= P;
}

int n,m;
vector<int> licz(){
  cin >> m;
  vector<vector<int>> d;
  d.resize(n);
  R(i,m){
    int a,b;
    cin >> a >> b;
    a--;b--;
    if(a > b)swap(a,b);
    d[a].PB(b);
  }
  vector<int> val(n);
  for(int i = n-1; i>=0;i--){
    vector<int> pom;
    for(int el:d[i]){
      pom.PB(val[el]);
    }
    sort(ALL(pom));
    val[i] = 0;
    R(j,SZ(pom)){
      if(pom[j] == val[i])val[i]++;
    }
  }
  int mn = base;
  vector<int> res(n);
  R(i,n){
    add(res[val[i]],mn);
    mn = mul(mn, base);
  }
  return res;
}
vector<int> splot(vector<int> a,vector<int> b){
  while(a.back() == 0)a.pop_back();
  while(b.back() == 0)b.pop_back();
  vector<int> res(SZ(a) + SZ(b));
  R(i,SZ(a))R(j,SZ(b)){
    add(res[i ^ j], mul(a[i], b[j]));
  }
  return res;
}

int32_t main() {
  base = mul(base,base);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  vector<int> res = splot(licz(), splot(licz(),licz()));
  res.resize(1,0);
  cout << res[0] << "\n";
}


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


int main(){
    int N; cin >> N;
    cout << fixed << setprecision(8);
    if(N % 2 == 0){
        cout << 1.0/2 << endl;
    }
    else{
        cout << static_cast<double>(N + 1)/2/N << endl;
    }
}

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

int main() {
	
	int a, b, c; cin >> a >> b >> c;
	map<int, int> mp;
	mp[a] = 1;
	mp[b] = 1;
	mp[c] = 1;
	int ans = 0;
	for (auto u : mp) {
		ans += u.second;
	}
	cout << ans << endl;
	return 0;
}

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

#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 rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

struct choice {
  int a;
  int b;
  int c;
  ll v;

  bool operator < (const choice& rhs) const {
    if(a != rhs.a) return a < rhs.a;
    else if(b != rhs.b) return b < rhs.b;
    else if(c != rhs.c) return c < rhs.c;
    else return false;
  }

  bool operator == (const choice& rhs) const {
    return a == rhs.a && b == rhs.b && c == rhs.c;
  }
};

struct vComparator {
  bool operator()(choice& left, choice& right) {
    return left.v < right.v;
  }
};

int X, Y, Z, K;
priority_queue<choice, vector<choice>, vComparator> choices;
set<choice> chosen;
ll as[1010], bs[1010], cs[1010];

void solve() {
  choices.push(choice {0, 0, 0, as[0]+bs[0]+cs[0]});
  int count = 0;
  while(!choices.empty() && count < K) {
    choice c = choices.top(); choices.pop();
    if(chosen.find(c) != chosen.end()) continue;
    chosen.insert(c);
    printf("%lld\n", c.v);
    count++;
    choice succ;
    if(c.a+1 < X) {
      succ = choice {c.a+1, c.b+0, c.c+0, as[c.a+1]+bs[c.b+0]+cs[c.c+0]};
      if(chosen.find(succ) == chosen.end()) choices.push(succ);
    }
    if(c.b+1 < Y) {
      succ = choice {c.a+0, c.b+1, c.c+0, as[c.a+0]+bs[c.b+1]+cs[c.c+0]};
      if(chosen.find(succ) == chosen.end()) choices.push(succ);
    }
    if(c.c+1 < Z) {
      succ = choice {c.a+0, c.b+0, c.c+1, as[c.a+0]+bs[c.b+0]+cs[c.c+1]};
      if(chosen.find(succ) == chosen.end()) choices.push(succ);
    }
  }
}

int main() {
  scanf("%d %d %d %d", &X, &Y, &Z, &K);
  rep(i, X) scanf("%lld", &as[i]);
  rep(i, Y) scanf("%lld", &bs[i]);
  rep(i, Z) scanf("%lld", &cs[i]);
  sort(as, as+X, greater<ll>());
  sort(bs, bs+Y, greater<ll>());
  sort(cs, cs+Z, greater<ll>());
  solve();
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

void dfs(char c,int n,string s){
  if(s.size()==n){
    cout<<s<<endl;
  }
  else {
    for(char h='a';h<=(c-'a')+1+'a';h=(h-'a')+1+'a'){
      if(h<(c-'a')+1+'a') dfs(c,n,s+h);
      else dfs(c+1,n,s+h);
    }
  }
}

int main() {
  int n;
  cin>>n;
  dfs('a',n,"a");
  return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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


int main(void) {
  int n,m;
  cin>>n>>m;
  int i;
  int path[10][10]={};
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    path[a][b]++;
    path[b][a]++;
  }

  vi v;
  rep(i,n)v.push_back(i);

  int ans=0;
  do{
    if(v[0]!=0)continue;
    bool c=true;
    rep(i,n-1)
      if(path[v[i]][v[i+1]]==0)c=false;
    if(c)ans++;
  }while(next_permutation(all(v)));

  cout<<ans<<endl;
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int check(int n)
{
    int ans = 0;
    for(int i = 1; i * i <= n; i++){
        if(n % i == 0){
            if(i != n / i)
                ans++;
            ans++;
        }
    }

    if(ans == 8)
        return 1;
    return 0;
}

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

    int ans = 0;
    for(int i = 1; i <= n; i += 2)
        ans += check(i);

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


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

typedef long long ll;
typedef vector < ll > vl;
typedef vector < int > vi;
typedef vector < bool > vb;
typedef vector < vl > vvl;
typedef vector < vi > vvi;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < pll > vpll;
typedef vector < pii > vpii;
typedef vector < vpll > vvpll;
typedef vector < vpii > vvpii;

#define pb push_back
#define eb emplace_back
#define pf push_front
#define all(c) (c).begin(), (c).end()
#define ff first
#define ss second
#define mp(x,y) make_pair((x), (y))
#define boost ios_base::sync_with_stdio(false); cin.tie(NULL)



void solve(){
    
    int n; cin >> n;
    vi a(n);
    int xr = 0;
    for(int& u : a){
        cin >> u;
        xr ^= u;
    }
    for(int& u : a){
        cout << (xr ^ u) << ' ';
    }
    
}


int main(){
	boost;
	int t = 1;
// 	cin >> t;
	
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	scanf("%d", &n);
	double s = 0;
	for(int i=0; i<n; i++){
		double ai; cin>>ai;
		s += (1.0/ai);
	}
	s = 1.0/s;
	printf("%.5lf\n", s);
}


Measured memory_bytes: 256
#

import sys
input=sys.stdin.readline

def main():
    N,K=map(int,input().split())
    A=list(map(lambda x: int(x)-1,input().split()))
    latest=[-1]*N
    latest[0]=0
    now=0
    while(K>0):
        K-=1
        to=A[now]
        if latest[A[now]]!=-1:
            K%=latest[now]-latest[A[now]]+1
        latest[A[now]]=latest[now]+1
        now=to
    print(now+1)
        
if __name__=="__main__":
    main()


Measured memory_bytes: 31344
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()
A = LIST()

ans = INF
A_sum = sum(A)
tmp = 0
for x in A:
	tmp += x
	ans = min(ans, abs(tmp-(A_sum-tmp)))

print(ans)


Measured memory_bytes: 27888
#include<iostream>
using namespace std;
 
int main(){
  long n, a,b;
  cin >> n >> a >> b;
  long p = n/(a+b);
  long ans = p*a;
  long x = n - p*(a+b);
  if(x <= a)
    ans += x;
  else
    ans+= a;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <string>
#include <queue>
#include <bitset>
using namespace std;

#define int long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = (a); i < _a; ++i)
#define REPD(i,n) for(int i = (n)-1; i >= 0; --i)

#define DEBUG(X) { cerr << #X << " = " << (X) << endl; }
#define PR(A, n) { cerr << #A << " = "; FOR(_, 1, n) cerr << A[_] << ' '; cerr << endl; }
#define PR0(A, n) { cerr << #A << " = "; REP(_, n) cerr << A[_] << ' '; cerr << endl; }

#define sqr(x) ((x) * (x))
#define ll long long
#define double long double
typedef pair<int, int> II;
#define PI (2 * acos((double)0))
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int)(x).size())
#define ALL(a) (a).begin(), (a).end()
#define MS(a,x) memset(a, x, sizeof(a))
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

#define TWO(X) (1LL<<(X))
#define CONTAIN(S,X) ((S) & TWO(X))

double safe_sqrt(double x) { return sqrt(max((double)0.0, x)); }
int GI(int& x) { return scanf("%lld", &x); }

const int MN = 100111;
int n, c, k, t[MN];

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << (fixed) << setprecision(9);
    while (cin >> n >> c >> k) {
        FOR(i,1,n) cin >> t[i];
        sort(t+1, t+n+1);

        int res = 0;
        int i = 1;
        while (i <= n) {
            ++res;
            int j = i;
            while (j < n && j - i + 1 < c
                    && t[j+1] <= t[i] + k) {
                ++j;
            }
            i = j + 1;
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep2(i,m,n) for (int i = (m); i < (n); ++i)
#define rep(i,n) rep2(i,0,n)
#define debug(x) cerr << x << endl
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> P;
template<typename T> struct V : vector<T> { using vector<T>::vector; };
V() -> V<int>;
V(size_t) -> V<int>;
template<typename T> V(size_t, T) -> V<T>;
template<typename T> vector<T> make_vec(size_t n, T a) { return vector<T>(n, a); }
template<typename... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec(ts...))>(n, make_vec(ts...)); }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << ' '; return os; }
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const ll MOD = 1000000007;

int main()
{
    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    rep(i,n)
    {
        int a;
        cin >> a;
        fw.add(i,a);
    }
    rep(i,q)
    {
        int t;
        cin >> t;
        if(t)
        {
            int l, r;
            cin >> l >> r;
            cout << fw.sum(l, r) << "\n";
        }
        else
        {
            int p, x;
            cin >> p >> x;
            fw.add(p, x);
        }
        
    }

    return 0;
}


Measured memory_bytes: 8260
#include<stdio.h>

int main(void)
{
  long int N;
  char eman[255],name[255];
  int m,l = 0;
  int i;

  scanf("%ld",&N);
  
  N--;
  while(N > -1)
  {
    m  = N % 26L;
    eman[l] = m + 'a';
    //printf("%c\n",eman[l]);
    l++;
    N /= 26;
    N--;
  }

  for(i = l -1;i >= 0;i--)printf("%c",eman[i]);
  //printf("%s",eman);
  return 0;
}

Measured memory_bytes: 1664
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int x[9];

int main() {
	int n;
	cin >> n;
	REP(i, n) {
		int a;
		cin >> a;
		x[min(a / 400, 8)]++;
	}
	int ret = 0;
	REP(i, 8)ret += (x[i]!=0);
	printf("%d %d\n", (ret==0)?1:ret, ret+x[8]);
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <list>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
string s1,s2;
int main()
{
    fast; 
    cin>>s1>>s2;
    if (s1==s2)
       cout<<'H'<<endl;
    else
       cout<<'D'<<endl;
	return 0;
}

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

int main() {
  char b;
  int a , c;
  cin >> a >> b >> c;
 
  
  if ( b =='+'){
    cout << a + c << endl;
  }
  if ( b =='-'){
    cout << a - c << endl;
  }
  
}


Measured memory_bytes: 3572
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//typedef
//------------------------------------------
template<class T> using v=vector<T>;
using VI = v<int>;
using VVI = v<v<int>>;
using VS = v<string>;
using PII = pair<int, int>;
using LL = long long;
using ULL = unsigned long long;
using VLL = v<LL>;
using VVLL = v<VLL>;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

//update
//------------------------------------------
template<class T>inline T updmax(T& target, T val) { return target = max(target, val); }
template<class T>inline T updmin(T& target, T val) { return target = min(target, val); }

int main() {
	int n;
	scanf("%d", &n);
	VLL a(n), b(n);
	REP(i, n)scanf("%lld%lld", &a[i], &b[i]);
	LL s = 0;
	REP(i, n) s += a[i];
	LL mi = s;
	REP(i, n) {
		if (a[i] > b[i])updmin(mi, b[i]);
	}
	printf("%lld\n", s - mi);
	return 0;
}

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

int a[12][12];

int main(void){
  int n,m,x; cin >> n >> m >> x;
  const int INF = 1001001001;
  vector<int> c(n);
  rep(i,n){
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }

  int min_cost = INF;
  rep(bit,1<<n){
    vector<int> ability(m,0);
    int money=0;
    rep(i,n){
      if(bit>>i&1){
	money+=c[i];
	rep(j,m) ability[j]+=a[i][j];
      }
    }    
    bool test=true;
    rep(j,m)
      if(ability[j]<x) test = false;
    if(test) min_cost = min(min_cost,money);
  }

  if(min_cost == INF) cout << -1 << endl;
  else cout << min_cost << endl;
  
  return 0;
}


Measured memory_bytes: 3596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	defaultBufferSize = 1024
	maxBufferSize     = 1e6
	Mod               = 1e9 + 7
)

var sc = bufio.NewScanner(os.Stdin)

// sc.Buffer(make([]byte, defaultBufferSize), maxBufferSize)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func primeFactorization(x int) map[int]int {
	result := make(map[int]int, 0)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			result[i]++
			x /= i
		}
	}
	if x != 1 {
		result[x]++
	}
	return result
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	for i := 2; i*i <= x; i++ {
		if i == x {
			continue
		}
		if x%i == 0 {
			return false
		}
	}
	return true
}

func main() {
	sc.Split(bufio.ScanWords)
	x := readInt()
	if x == 0 {
		fmt.Println("1")
	} else {
		fmt.Println("0")
	}
}


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

int main(){
  string S;cin>>S;
  ll ans=0;
  for(int bit=0;bit<(1<<(S.size()-1));++bit){
    if(S.size()==1){ans=stoi(S);break;}
    ll tmp=0;
    vector<ll> n;
    rep(i,S.size()){
      if(bit & (1<<i)){
        string s = S.substr(tmp,i+1-tmp);
        n.push_back(stoll(s));
        tmp = i+1;
      }
    }
    string s = S.substr(tmp,S.size()+1-tmp);
    n.push_back(stoll(s));
    ans += accumulate(all(n),0ll);
  }
  cout << ans << endl;
}

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

int main()
{
    int a,b,c;
    int n;

    cin >> a >> b >> c >> n;

    int cnt = 0;
    for(int i = 0;i <= a;i++){
        for(int j = 0;j <= b;j++){
            int num = (n-500*i-100*j)/50;
            if(num >= 0 && num <= c){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int gcd(int ,int);

int main() 
{
int a,b,ans;

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

ans = gcd(a,b);

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

int gcd(int a,int b)
{
    int t;
    t=a%b;
    while(t != 0)
    {
       a=b;
       b=t;
       t=a%b;
    }
    return b; 
}


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

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

void code() {
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ll ans=0;
    vector<ll> A(a);
    vector<ll> B(b);
    vector<ll> C(c);
    for(ll i=0; i<a; i++) {
        cin>>A[i];
    }
    for(ll i=0; i<b; i++) {
        cin>>B[i];
    }
    for(ll i=0; i<c; i++) {
        cin>>C[i];
    }
    sort(A.rbegin(), A.rend());
    sort(B.rbegin(), B.rend());
    sort(C.rbegin(), C.rend());
    vector<ll> tot;
    for(ll i=0; i<x; i++)
        tot.push_back(A[i]);
    for(ll i=0; i<y; i++)
        tot.push_back(B[i]);
    for(ll i=0; i<c; i++)
        tot.push_back(C[i]);
    sort(tot.rbegin(), tot.rend());
    for(ll i=0; i<(x+y); i++)
        ans+=tot[i];
    cout << ans << "\n";
}

signed main() {
    std::ios_base::sync_with_stdio(false);
    ll t=1;
    // cin>>t;
    for(ll i=0; i<t; i++) {
        code();
    }
}


Measured memory_bytes: 9832
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)
n,m=map(int,input().split())
lis = []
for i in range(m):
    tmp = list(map(int,input().split()))
    tmp.extend(list(map(int,input().split())))
    lis.append(tmp)

dp = [[1000000000 for i in range(2**n)]for i in range(m+1)]
dp[0][0]=0
for i in range(m):
    clis = 0
    for j in lis[i][2:]:
        clis += 2**(j-1)

    for sin in range(2**n):
        #print(dp[i][sin]+lis[i][0],clis|sin)
        dp[i+1][clis|sin] = min(dp[i][sin]+lis[i][0],dp[i+1][clis|sin])
    for sin in range(2**n):
        dp[i+1][sin] = min(dp[i+1][sin],dp[i][sin])

#print(lis)
#print(*dp,sep="\n")
if dp[m][-1]==1000000000:
    print(-1)
else:
    print(dp[m][-1])


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

#define ll long long

int const N = 3e3 + 1;

int n;
int arr[N];

ll dp[N][N][2];
int vis[N][N][2];

ll pound(int left, int right, bool turn)
{
    if (left > right)
        return 0;
    
    if (vis[left][right][turn])
        return dp[left][right][turn];
    
    vis[left][right][turn] = 1;
    
    if (!turn)
        return dp[left][right][turn] = max(pound(left + 1, right, !turn) + arr[left], pound(left, right - 1, !turn) + arr[right]);
    return dp[left][right][turn] = min(pound(left + 1, right, !turn) - arr[left], pound(left, right - 1, !turn) - arr[right]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> arr[i];
    
    cout << pound(0, n - 1, 0);
    
    return 0;
}

Measured memory_bytes: 211328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define pf push_front
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	ll n;
	cin >> n;
	ll mn = 1e12+10;
	for(int i = 1; i <= sqrt(n); i++) {
		if(n % i == 0)
			mn = min(mn, i+(n/i)-2);
	}
	cout << mn << endl;
	return 0;
}



Measured memory_bytes: 3584
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const ll INF = 1 << 30;//10^9
ll MOD = 1000000007;
//ll MOD = 998244353;

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

void pres(double A, ll x = 10){cout << fixed << setprecision(x) << A << endl;}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

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



void solve(){
  int r;
  cin >> r;
  cout << r * r << endl;
}

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


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


void solve(string S){
  long long erased = 0;

  for(long long i = S.size() - 2; i >= 0; i--) {
    while(((S.size()) - i) >= 2 && S[i] != S[i+1]) {
      S.erase(i, 2);
      erased++;
    }
  }

  cout << erased*2 << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define N 400005
using namespace std;
int n,p[N],fa[N];
int head[N],ver[N],nxt[N],vis[N],tot;
void add(int a,int b)
{
    tot++;nxt[tot]=head[a];head[a]=tot;ver[tot]=b;return ;
}
int find(int x)
{
    if(vis[x])return x;
    vis[x]=1;
    return find(p[x]);
}
vector<int>v;
int tim;
int f[N],c[N];
void dfs(int x)
{
    for(int i=head[x];i;i=nxt[i])if(!vis[ver[i]])dfs(ver[i]);
    tim++;
    for(int i=head[x];i;i=nxt[i])if(!vis[ver[i]])c[f[ver[i]]]=tim;
    for(int i=0;;i++)
    {
        f[x]=i;
        if(c[i]!=tim)break;
    }
    return ;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&p[i]);add(p[i],i);fa[p[i]]=i;
    }
    int x=find(1);
    memset(vis,0,sizeof(vis));
    do{
        v.push_back(x);
        vis[x]=1;
        x=p[x];
    }while(x!=v[0]);
    if (!(v.size()&1))  {puts("POSSIBLE");  return 0;}
    for(int i=0;i<v.size();i++)dfs(v[i]);
    v.push_back(x);
    for(int i=0;i<v.size()-1;i++)
        if(f[v[i]]!=f[v[i+1]]){puts("POSSIBLE");return 0;}
    puts("IMPOSSIBLE");
    return 0;
}


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

long long D[51];

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

    for (int i = 1; i <= N; ++i)
    {
        cin >> D[i];
    }

    long long ans = 0;

    for (int i = 1; i <= N; ++i)
    {
        for (int j = i + 1; j <= N; ++j)
        {
            if (i == j) continue;

            ans += D[i] * D[j];
        }
    }

    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8

# https://atcoder.jp/contests/abc107


def main():
    H, W = map(int, input().split())
    a = [None] * H
    for i in range(H):
        a[i] = input()

    b = []
    for i in range(H):
        if any([x == "#" for x in a[i]]):
            b.append(a[i])
    
    idx = []
    for j in range(W):
        if any([b[i][j] == "#" for i in range(len(b))]):
            idx.append(j)

    for i in range(len(b)):
        for j in range(W):
            if j in idx:
                print(b[i][j], end="")
        print()


main()
# print(main())


Measured memory_bytes: 4468