akhauriyash/Code-Regression huggingface dataset:
def SelectionSort(A, N):
    count = 0
    for i in range(N):
        flag = 0
        minj = i
        j = i - 1
        for j in range(i,N):
            if A[j] < A[minj]:
                flag = 1
                minj = j
            
        if flag == 1:
            a = A[minj]
            A[minj] = A[i]
            A[i] = a
            count += 1
 
    return(A, count)

N = int(input())
A = list(map(int,input().split()))

A, count = SelectionSort(A,N)
print(' '.join(map(str, A)))
print(count)


Measured memory_bytes: 5600
#include<stdio.h>
#define white 0
#define gray 1
#define black 2

typedef struct{
  int data[100];
  int head;
  int tail;
}queue;

queue Q;

int n,d[100] = {10000000};
int g[100][100] = {0};
int color[100] = {white};

void bfs(int);
void enqueue(int);
int dequeue(void);

int main(){
  int i,j,u,k,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      g[u-1][v-1] = 1;
    }
  }
  for(i=0;i<n;i++)
    d[i] = 10000000;

  bfs(0);

  for(i=0;i<n;i++){
    if(d[i] == 10000000)printf("%d %d\n",i+1,-1);
    else printf("%d %d\n",i+1,d[i]);
  }
  return 0;
}

void bfs(s){
  int v,u;

  d[s] = 0;
  color[s] = gray;
  Q.head = Q.tail = 0;
  enqueue(s);

  while(Q.tail < n){
    u = dequeue();
    if(u == 10000000)break;
    for(v=0;v<n;v++){
      if(g[u][v] == 0)continue;
      if(color[v] == white){
	d[v] = d[u] + 1;
	color[v] = gray;
	enqueue(v);
      }
    }
    color[u] = black;
  }
}

void enqueue(int s){

  if(Q.tail >= n)return;
  
  Q.data[Q.tail] = s;
  Q.tail++;
}

int dequeue(){
  int s;

  if(Q.head == Q.tail)return 10000000;

  s = Q.data[Q.head];
  Q.head++;

  return s;
}



Measured memory_bytes: 2084
#include <iostream>
#include <vector>
#include <cmath> // ??????

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

using namespace std;

struct FourArithmeticOperationParser {
    
    int pos;
    string Formula;
    
    long long operator () (string F) {
        pos = 0;
        Formula = F;
        return expr();
    }
    
    long long number() {
        long long ret = 0;
        while (pos != Formula.size()) {
            if (Formula[pos] < '0' || Formula[pos] > '9') {
                break;
            } else {
                ret *= 10;
                ret += (Formula[pos++] - '0');
            }
        }
        return ret;
    }
    
    long long expr() {
        long long x = term();
        while (pos < Formula.size()) {
            switch (Formula[pos]) {
                case '+':
                    pos++;
                    x += term();
                    continue;
                case '-':
                    pos++;
                    x -= term();
                    continue;
            }
            break;
        }
        return x;
    }
    
    long long term() {
        long long x = factor();
        while (pos < Formula.size()) {
            switch (Formula[pos]) {
                case '*':
                    pos++;
                    x *= factor();
                    continue;
                case '/':
                    pos++;
                    x /= factor();
                    continue;
            }
            break;
        }
        return x;
    }
    
    long long factor() {
        if (pos < Formula.size()) {
            if (Formula[pos] == '(') {
                pos++;
                long long ret = expr();
                if (Formula[pos] == ')') {
                    pos++;
                }
                return ret;
            }
        }
        return number();
    }
    
};


int main() {
   
    int N; cin >> N;
    REP(i,N) {
        string s; cin >> s;
        cout << FourArithmeticOperationParser()(s.substr(0,s.size() - 1)) << endl;
    }
   
    return 0;
}

Measured memory_bytes: 3156
H=float(input())
layer=[1]
i=0
count=0
HP=int(H/2)
if HP<=0:
    count+=layer[0]
    print(count)
else:
    count+=layer[0]
    while HP>0:
        i+=1
        layer.append(layer[i-1]*2)
        count+=layer[i]
        HP=int(HP/2)
    print(count)

Measured memory_bytes: 3064
import bisect
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

SA = [0]*(N+1)
SB = [0]*(M+1)
T = 0


ans = 0

for i in range(N):
    SA[i+1] = SA[i] + A[i]

for i in range(M):
    SB[i+1] = SB[i] + B[i]

for i in range(N+1):
    if SA[i] > K:
        break
    id = bisect.bisect_right(SB, K - SA[i]) - 1
    ans = max(ans, i + id)


print(ans)


Measured memory_bytes: 47548
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int n,ma,mb;
int a[100],b[100],c[100];
int dp[101][1000][1000]={0};

int mincost(int p,int q){
  rep(k,n+1){
    rep(i,p+1){
      rep(j,q+1){
        dp[k][i][j] = 100000000;
      }
    }
  }
  dp[0][0][0]=0;
  rep(k,n){
    rep(i,p+1){
      rep(j,q+1){
        if(i>=a[k]&&j>=b[k]){
          dp[k+1][i][j]=min(dp[k][i][j],dp[k][i-a[k]][j-b[k]]+c[k]);
        }else{
          dp[k+1][i][j]=dp[k][i][j];
        }
      }
    }
  }
  int ans=100000000;
  Rep(i,1,400/max(ma,mb)+1){
    ans=min(ans,dp[n][ma*i][mb*i]);
  }
  return ans;
}

int main(){
  cin >> n >> ma >> mb;
  rep(i,n){
    cin >> a[i] >> b[i] >> c[i];
  }
  int ans=mincost(401,401);
  if(ans==100000000){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
  
  return 0;
}
  
    
  
    

Measured memory_bytes: 151296
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
long long n, a[N], l[N], r[N];
int main(int argc, char const *argv[])
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	stack<long long> st;
	for (int i = 0; i < n; ++i)
	{
		while (!st.empty() && a[st.top()] > a[i])
		{
			r[st.top()] = i - 1;
			st.pop();
		}
		st.push(i);
	}
	while (!st.empty())
	{
		r[st.top()] = n - 1;
		st.pop();
	}
	for (int i = n - 1; i >= 0; --i)
	{
		while (!st.empty() && a[st.top()] > a[i])
		{
			l[st.top()] = i + 1;
			st.pop();
		}
		st.push(i);
	}
	while (!st.empty())
	{
		l[st.top()] = 0;
		st.pop();
	}
	long long ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ans += (i - l[i] + 1) * (r[i] - i + 1) * a[i]; 
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 9904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<ll, ll> mll;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, ans, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n >> m){
        vll from1, ton;
        rep(i, m){
            cin >> a >> b;
            if(a == 1 || b == 1){
                from1.pb(max(a, b));
            }else if(a == n || b == n){
                ton.pb(min(a, b));
            }
        }
        sort(all(ton));
        each(i, from1){
            if(binary_search(all(ton), i)){
                print("POSSIBLE");
                return 0;
            }
        }
        print("IMPOSSIBLE");
    }
}

Measured memory_bytes: 2004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

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

    int n;
    cin >> n;
    vector<int> a(n), p(n), q(n);
    rep(i, 0, n) cin >> p[i];
    rep(i, 0, n) cin >> q[i];

    int s, t;
    int c = 1;
    iota(a.begin(), a.end(), 1);
    do {
        if (a == p) s = c;
        if (a == q) t = c;
        c++;
    } while (next_permutation(a.begin(), a.end()));
    cout << abs(s - t) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
#define r(a) ((int)(a + .5))
vector<ll > d;
vector<bool> vis;
vector<vector<int> > g;
int in[100001];
void dfs(int a)
{
    vis[a] = 1;
    for(int i : g[a])
    {
        d[i] = max(d[i],d[a]  + 1);
        in[i]--;
        if(in[i] == 0)
        {
            dfs(i);
        }
    }
}
int main()
{
    int n,m;cin>>n>>m;
    g = vector<vector<int> >(n + 1);

    for(int i = 0 ;i < m ; i++)
    {
        int a,b;cin>>a>>b;
        g[a].push_back(b);
        in[b]++;
    }
    d = vector<ll>(n +1,0);
    vis = vector<bool> (n + 1,0);
    for(int i = 1 ; i <=  n  ; i++)
    {
        if(vis[i] == 0 && in[i] == 0)
            dfs(i);
    }
    cout<<*max_element(d.begin(),d.end())<<endl;
    // for(int i =0 ; i < n ; i ++)
    //     cout<<in[i + 1]<<' ';
    // cout<<endl;
}


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

using namespace std;

#define ff(i, a, b) for(int i = (a); (i <= (b)); ++i)
#define FF(i, a, b) for(int i = (a); (i >= (b)); --i)
#define ll long long

const int M = 1000000000 + 7;

struct re {
    int x, y;
//    const bool operator < (const re &a) const {
//        if (x != a.x) return x < a.x;
//        return y < a.y;
//    }
};

int n;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("", "r" , stdin);
    //freopen("", "w", stdout);
	cin >> n;
  	int cnt = 0;
  	ff(i, 1, n) cnt += (i % 2);
  	cout << setprecision(6) << fixed << ((double) cnt) / n;
}
//This code belongs to s34vv1nd


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

long long L[100];

int main() {
    int N = 0;
    cin >>N;
    L[0] = 2;
    L[1] = 1;
    for (int i =2; i<=N; i++) {
        L[i] = L[i-1] + L[i-2] ;
    }
    cout << L[N] << endl;
    return 0;
}

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

const int N = 1e5;

vector<int> xs;
vector<int> len;

int solve(int x) {
	if (xs.empty() || x < xs[0]) return 0;
	int i = lower_bound(xs.begin(), xs.end(), x+1) - xs.begin() - 1;
	assert(xs[i] <= x);
	return len[i];
}

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

	int n;
	cin >> n;
	vector<pair<int, int>> zz;
	for (int i = 0; i < n; i++) {
		int x, k;
		cin >> x >> k;
		zz.emplace_back(x+k, x-k);
	}
	sort(zz.begin(), zz.end());

	int ans = 0;
	for (auto& it : zz) {
		int b = it.first;
		int a = it.second;

		int best = max(solve(a) + 1, solve(b));
		if (!xs.empty() && xs.back() == b) {
			len.back() = max(len.back(), best);
		} else {
			xs.push_back(b);
			len.push_back(best);
		}
		ans = max(ans, len.back());
	}

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



Measured memory_bytes: 2416
from fractions import gcd

A, B, C, D = [int(x) for x in input().split(" ")]

c = (B // C) - (A // C) + int(A % C == 0)
d = (B // D) - (A // D) + int(A % D == 0)
lcm_cd = (C * D) // gcd(C, D)
cd = (B // (lcm_cd)) - (A // (lcm_cd)) + int(A % (lcm_cd) == 0)

c_or_d = c + d - cd

print((B - A + 1) - c_or_d)


Measured memory_bytes: 5048
s=int(input())
l=[]
l.append(s)
ans=[]
c=1
for i in range(10000000000):
    if l[c-1]%2==0:
        l.append(int(l[c-1]/2))
    else:
        l.append(int(l[c-1]*3+1))
    for v in range(len(l)):
        ans.append(l.count(l[v]))
    if 2 in ans:
        break
    c+=1
print(c+1)


Measured memory_bytes: 3064
s = gets.to_i
results = [s]

i = 1
while true
  i += 1
  n = results[-1]

  tmp = if n.even?
    n / 2
  else
    3 * n + 1
  end

  break if results.include?(tmp) || i > 1000000
  results.push(tmp)
end

puts i

Measured memory_bytes: 1788
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
    int n,m;
    cin >>n >>m;

    int np = (n > 0) ? n * (n-1)/2 : 0;
    int mp = (m > 0) ? m * (m-1)/2 : 0;
    printf("%d\n", np+mp);

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split(' '))
minR = N
maxL = 0
for i in range(M):
  L, R = map(int, input().split(' '))
  maxL = max(maxL, L)
  minR = min(minR, R)
result = 0 if minR < maxL else minR-maxL+1
print(result)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int N, C, K;
int A[1000000 + 100];
int main()
{
	scanf("%d%d%d", &N, &C, &K);
	for (int i = 1; i <= N; ++i)
		scanf("%d", &A[i]);
	sort(A + 1, A + N + 1);
	int Start = A[1], Ans = 0, Sum = 1;
	for (int i = 2; i <= N; ++i)
	{
		if (A[i] - Start > K || Sum == C)
		{
			++Ans;
			Sum = 1, Start = A[i];
		}
		else ++Sum;
	}
	++Ans;
	printf("%d\n", Ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;
  
#define MP make_pair
#define PB push_back
#define MAX_N 1010000
#define SIZE 3000
#define X first
#define Y second
  
const int STX = 1500, STY = 1500;

typedef pair<int, int> Pii;
typedef pair<int, Pii> P;
  
int id[SIZE][SIZE];
bool is_prime[MAX_N+1];
vector<Pii> coord;

void Sieve() {
  fill(is_prime, is_prime+MAX_N+1, true);
  is_prime[0] = is_prime[1] = false;
  for(int i=2; i*i<=MAX_N; i++)
    if(is_prime[i])
      for(int j=i*i; j<=MAX_N; j+=i)
	is_prime[j] = false;
}

void MakeMap() {
  int x = STX, y = STY;
  int cnt = 0;
  
  coord.PB(MP(0, 0)); // no use
  cnt ++;
  coord.PB(MP(x, y)); // cnt = 1
  
  fill(id[0], id[0]+SIZE*SIZE+1, -1);
  
  const int dx[] = {0,-1,0,1};
  const int dy[] = {-1,0,1,0};
  
  int a = 0; x = STX+1; y = STY+1;
  while(cnt <= MAX_N) {
    a += 2;
    for(int turn=0; turn<4; turn++) {
      for(int i=0; i<a; i++) {
	x += dx[turn], y += dy[turn];
	coord.PB(MP(x, y));
	id[y][x] = ++ cnt;
      }
    }
    x++, y++;
  }
}

int dp[MAX_N+1];

int main() {
  
  Sieve();
  MakeMap();
  
  int m, n;

  while(cin >> m >> n && (m|n)) {
    
    fill(dp, dp+MAX_N+1, -1);
    dp[n] = is_prime[n];
    Pii ans(dp[n], n);
    
    queue<P> que;
    que.push(P(dp[n], coord[n]));
    while(!que.empty()) {
      P now = que.front(); que.pop();
      int tmpid = id[now.second.Y][now.second.X];
      if(now.first < dp[tmpid]) continue;
      
      int noid = id[now.second.Y][now.second.X];
      
      for(int i=-1; i<=1; i++) {
	Pii nex = MP(now.second.X+i, now.second.Y+1);
	if(nex.X < 0 || SIZE <= nex.X || nex.Y < 0 || SIZE <= nex.Y) continue;
	int neid = id[nex.Y][nex.X];
	if(neid <= m) {
	  if(dp[neid] < dp[noid] + is_prime[neid]) {
	    dp[neid] = dp[noid] + is_prime[neid];
	    if(is_prime[neid]) ans = max(ans, MP(dp[neid], neid));
	    que.push(P(dp[neid], nex));
	  }
	}
      }

    }
    
    if(ans.first == 0) cout << "0 0" << endl;
    else cout << ans.first << ' ' << ans.second << endl;
  }
  return 0;
}

Measured memory_bytes: 49264
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  double N; cin >> N;
  double pi = 3.14159265;
  double ans = pi * N * 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  double ans;
  ans=0;
  cin>>N;
  for(int i=0;i<N;i++){
    if((i+1)%2==1){
      ans++;
    }
  }
  cout<<ans/N<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
using namespace std;
int main(void){
    int N;
    int res = 0;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= N; i++) {
        int j = a[i-1];
        if ((a[j-1] == i) && (i < j)) {
            res++;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 768
#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    debug(__VA_ARGS__);                \
    cerr << endl;                      \
  } while (0)
#endif

const int matches[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  for (auto& x : A) cin >> x;
  sort(A.begin(), A.end());

  vector<vector<int>> dp(N / 2 + 1, vector<int>(N + 1, -1));
  REP(k, M) {
    int m = matches[A[k]];
    if (m <= N) {
      dp[0][m] = max(dp[0][m], A[k]);
    }
  }
  REP(i, N / 2) {
    bool placed = false;
    REP(j, N + 1) {
      if (dp[i][j] < 0) continue;
      REP(k, M) {
        int m = matches[A[k]];
        if (j + m > N) continue;
        dp[i + 1][j + m] = max(dp[i + 1][j + m], A[k]);
        placed = true;
      }
    }
    if (!placed) {
      break;
    }
  }
  int mi = -1;
  for (int i = N / 2; i >= 0; --i) {
    if (dp[i][N] >= 0) {
      mi = i;
      break;
    }
  }
  assert(mi >= 0);
  int s = N;
  for (int i = mi; i >= 0; --i) {
    int d = dp[i][s];
    cout << d;
    s -= matches[d];
  }
  cout << '\n';
}


Measured memory_bytes: 195840
import numpy as np
N, K = list(map(int,input().split()))
a = list(map(int,input().split()))

a = np.array(a)

s = 0
e = 0

arr = []
aa = np.append(0,np.cumsum(a))
for s in range(len(aa)):
    for e in range(s+1, len(aa)):
        arr.append(aa[e] - aa[s])

max_len = len(bin(np.sum(a))[2:])

su = 0
b = [bin(aa)[2:] for aa in arr]
b = ['0' * (max_len - len(bb)) + bb for bb in b]
while True:
    c = [bb for bb in b if bb[0] == '1']
    if len(c) >= K:
        su += 2 ** (len(c[0]) - 1)
        b = [cc[1:] for cc in c]
    else:
        b = [bb[1:] for bb in b]
    if len(b[0]) == 0:
        break
print(su)

Measured memory_bytes: 118116
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

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


Measured memory_bytes: 51024
n = int(input())
a_list = list(map(int, input().split()))
a_list.reverse()

d = [0] * (n + 1)

for j in range(n):
    i = n - j
    if n // i == 1:
        d[i] = a_list[j]
    else:
        c = 0
        for k in range(n // i, 1, -1):
            c += d[k * i]
        d[i] = (c + a_list[j]) % 2

counter = 0
res = []

for k in range(n):
    if d[k + 1] == 1:
        counter += 1
        res.append(k + 1)

print(counter)
if len(res) > 0:
    print(*res)

Measured memory_bytes: 69980
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = scanner.nextInt();
        Set<Integer> first = new HashSet<>();
        first.add(scanner.nextInt());
        String answer = "YES";
        for (int i = 1; i < size; i ++) {
            int new1 = scanner.nextInt();
            if (first.contains(new1)) {
                answer = "NO";
                break;
            }
            first.add(new1);
        }
        System.out.println(answer);
    }
}

Measured memory_bytes: 102176
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cctype>
#include<cmath>
#include<cstring>
#define maxn 2007
#define SDOI2020 RP++ 
using namespace std;
int a,b,c; 
inline int read()
{
	int x=0;
	int flag=0;
	char ch;
	ch=getchar();
	while(!isdigit(ch)) 
	{
		if(ch=='-') flag=1;
	ch=getchar();	
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+ch-48;
		ch=getchar();
		}
		if(flag==1) x=-x;	
		return x;
}


int main()
{
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl; 
	
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
const int maxn = 3e5 + 10;
int k, n;
ll f[maxn];
void dfs(int now, ll K)
{
	if(now == n + 1 || K == 0) return;
	ll x = K, y = f[now + 1] + 1;
	ll cur = (x + y - 1) / y;
	printf(" %lld", cur);
	dfs(now + 1, K - 1 - (cur - 1) * y);
}
int main()
{
	scanf("%d%d", &k, &n); 
	if(k % 2 == 0)
	{
		printf("%d", k / 2);
		for(int i = 2; i <= n; ++i)
			printf(" %d", k);
		puts("");
		return 0;
	}
	for(int i = n; i; --i)
	{
		if(inf / k < f[i + 1] + 1) f[i] = inf;
		else f[i] = k * (f[i + 1] + 1); 
	}
	printf("%d", (k + 1) / 2);
	for(int i = 2; i <= n; ++i)
		if(f[i] == inf)
			printf(" %d", (k + 1) / 2);
		else
		{
			dfs(i, (f[i] - (i - 2)) / 2);
			break;
		}
	puts("");
	return 0;
}

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

using namespace std;

int main(){
string a;
cin >> a;
int len = a.length();
for(int i = 1; i <=len;++i){
if(i&1 && a[i-1]=='L'){
cout<<"No";
return 0;
}
if(!(i&1) && a[i-1]=='R'){
cout<<"No";
return 0;
}
}
cout << "Yes";
return 0;
}


Measured memory_bytes: 3620
#include <stdio.h>

int main(void)
{
	double height,max=0.0,min=10000.0;//エベレスト8844.43

	while(scanf("%lf",&height)!=EOF){
		if(height>=max)
			max=height;
		if(height<=min)
			min=height;
	}
	printf("%.1f",max-min);

	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <stack>
#include <stdio.h>
#include <cmath>
#include <utility>
using namespace std;
int main()
{
    int n;
	cin>>n;
	while(n--){
		int ans=0;
		double ax,ay,ar,bx,by,br,d;
		cin>>ax>>ay>>ar>>bx>>by>>br;
		d=sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
		if(d<abs(ar-br)){//a)b||a(b
			ans=2;
			if(ar<br)ans*=-1;
		}else if(d<=ar+br){
			ans=1;
		}
		cout<<ans<<endl;
	}
    return 0;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i,n) for(ll i=0;i<n;i++)

int main(){
	int n;cin>>n;
	int x[n],y[n];
	rep(i,n) {
		cin>>x[i];
		y[i]=x[i];
	}
	sort(y,y+n);
	int mn=y[n/2-1],mx=y[n/2];
	rep(i,n){
		if(x[i]<=mn) cout<<mx<<"\n";
		else cout<<mn<<"\n";
	}
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll D, T, S;
    cin >> D >> T >> S;

    if (D <= T*S) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

int memo[12][2010];
int N, K, sum[12][2010];
vector<int> B[11];

int rec(int g, int k){
	if(memo[g][k] != -1)
		return memo[g][k];
	if(g > 10)
		return 0;
	
	int res = 0;
	int s = B[g].size();
	for(int i = 0; i <= s && i + k <= K; ++i){
		res = max(res, rec(g + 1, k + i) + sum[g][i]);
	}
	
	return memo[g][k] = res;
}

int main() {
	int c, g;
	memset(memo, -1, sizeof(memo));
	cin >> N >> K;
	for(int i = 0; i < N; ++i){
		scanf("%d%d", &c, &g);
		B[g].emplace_back(c);
	}
	for(int i = 1; i <= 10; ++i){
		sort(B[i].begin(), B[i].end(), greater<int>());
		for(int j = 1; j <= B[i].size(); ++j){
			sum[i][j] = sum[i][j - 1] + B[i][j - 1] + (j - 1) * 2;
		}
	}
	
	cout << rec(1, 0) << endl;
	return 0;
}

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

using ll = long long;
using P = pair<int, int>;

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

    int cnt = 0;
    rep(i, N)
    {
        if (S.substr(i, 3) == "ABC")
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3608
use std::io::*;

mod disjoint_set {
    pub struct DisjointSet {
        parent: Vec<usize>,
        size: Vec<usize>,
    }
    impl DisjointSet {
        pub fn new(n: usize) -> DisjointSet {
            DisjointSet {
                parent: (0..n).collect(),
                size: vec![1; n],
            }
        }
        pub fn root(&mut self, x: usize) -> usize {
            if x == self.parent[x] {
                x
            } else {
                let tmp = self.parent[x];
                self.parent[x] = self.root(tmp);
                self.parent[x]
            }
        }
        pub fn merge(&mut self, x: usize, y: usize) {
            let x = self.root(x);
            let y = self.root(y);
            if x == y {
                return;
            }
            if self.size[x] > self.size[y] {
                self.size[x] += self.size[y];
                self.parent[y] = x;
            } else {
                self.size[y] += self.size[x];
                self.parent[x] = y;
            }
        }
    }
}

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let m: usize = itr.next().unwrap().parse().unwrap();
    let mut uf = disjoint_set::DisjointSet::new(n);
    for _ in 0..m {
        let x: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let y: usize = itr.next().unwrap().parse::<usize>().unwrap() - 1;
        let _: usize = itr.next().unwrap().parse().unwrap();
        uf.merge(x, y);
    }

    let mut used = vec![false; n];
    let mut ans = 0;
    for i in 0..n {
        if !used[uf.root(i)] {
            ans += 1;
            used[uf.root(i)] = true;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int check(char block[],int idx,int size);
int main(void){
	int n;
	while(scanf("%d",&n),n){
		int mi = 10001;
		char block[10001];
		for(int i = 0;i < n;i++){scanf("%s",&block[i]);block[i] -= '0';}
		for(int i = 0;i < n;i++){
			for(int j = 0;j < 3;j++){
				char _block[10001];
				strcpy(_block,block);
				_block[i] = (char)(j+1);
				mi = min(mi,check(_block,i,n));
			}
		}
		printf("%d\n",mi);
	}
	return 0;
}

int check(char block[],int idx,int size){
	while(size > 3){
		int upper = idx;
		int low = idx;
		int low_cnt = 0,upper_cnt = 0;
		for(int i = idx-1;i >= 0; i--){
			if(block[i] == block[idx]){low_cnt++;}
			else break;
		}
		for(int i = idx+1;i < size;i++){
			if(block[i] == block[idx]) upper_cnt++;
			else break;
		}
		int cnt = low_cnt + upper_cnt+1;
		if(cnt < 4){
			return size;
		}
		
		for(int i = 0;i < size - (idx+upper_cnt);i++){
			block[idx-low_cnt+i] = block[idx+upper_cnt+i+1];
		}
		
		size -= cnt;
		idx -= low_cnt;
	}
	return size;
}

Measured memory_bytes: 1060
#include<stdio.h>

int main(){
  char s[101][101];
  int H, W, i;
  
  scanf("%d %d", &H, &W);
  for(i = 0; i < H; i++){
    scanf("%s", s[i]);
  }
  for (i = 0; i < 2*H; i++){
    printf("%s\n", s[i/2]);
  }
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

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 n, a,b;
i64 mod_pow(i64 x, i64 y, i64 mod){
	i64 res = 1;
	while(y > 0){
		if(y & 1) res = res * x % mod;
		x = x*x %mod;
		y >>= 1;
	}
	return res;
}
i64 extgcd(i64 a, i64 b, i64 &p, i64 &q){
	if(b == 0){
		p = 1;
		q = 0;
		return a;
	}
	i64 c = extgcd(b, a%b, q, p);
	q -= a/b * p;
	return c;
}
inline i64 mod(i64 a, i64 m) {
    return (a % m + m) % m;
}
i64 modinv(i64 a, i64 m) {
    i64 x, y;
    extgcd(a, m, x, y);
    return mod(x, m);
}
i64 fract(i64 x, i64 y, i64 mod){
	return x*modinv(y, mod) % mod;
}
i64 kai(i64 x, i64 y, i64 MOD){
	i64 res = x;
	while(--x > y){
		res = mod(res*x,MOD);
	}
	return res;
}

void solve(){
	cin >> n >> a >> b;
	
	i64 ans = mod_pow(2, n, INF) - 1;
	ans = mod(ans - fract(kai(n,n-a,INF),mod(kai(a,1,INF),INF),INF),INF);
	ans = mod(ans - fract(kai(n,n-b,INF),mod(kai(b,1,INF),INF),INF),INF);
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int N, num = 0, ans1 = 0; cin >> N;
	vector<int> A(N);
	rep(i, N) {
		cin >> A[i];
		if (A[i] == 0)num = 0;
		else ++num;
		ans1 = max(ans1, num);
	}
	cout << ans1 + 1 << endl;
	cin >> N;
}


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

#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    string S;
    cin >> S;
    ll N = S.size();
    ll P = 2019;

    ll ans = 0;
    vector<ll> mods(P, 0);

    ll cur = 0, coef = 1;
    mods[cur]++;
    REP(i, 0, N) {
        cur = (cur + coef * (S[N - i - 1] - '0') % P) % P;
        coef = coef * 10 % P;
        mods[cur]++;
    }

    REP(i, 0, P) {
        ans += mods[i] * (mods[i] - 1) / 2;
    }

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


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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(){
    int n, m;
    cin >> n >> m;
    V<V<int>> g(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    deque<int> ans;
    ans.push_back(0);
    int v_b = 0;
    int v_f = 0;
    V<bool> seen(n);
    seen[0] = true;
    while(1) {
        bool ok = true;
        { // うしろ
            for(int nv : g[v_b]) {
                if(seen[nv] == false) {
                    ok = false;
                    seen[nv] = true;
                    v_b = nv;
                    ans.push_back(nv);
                    break;
                } 
            }
        }
        { // まえ
            for(int nv : g[v_f]) {
                if(seen[nv] == false) {
                    ok = false;
                    seen[nv] = true;
                    v_f = nv;
                    ans.push_front(nv);
                    break;
                } 
            }
        }
        if(ok) break;
    }

    cout << sz(ans) << endl;
    rep(i,sz(ans)) cout << ans[i]+1 << " ";
}

Measured memory_bytes: 8896
#include <bits/stdc++.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define mod 1000000007
#define INF LLONG_MAX/5
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
signed main(){
	string s;
	cin>>s;
	f(i,s.size()){
		if((i%2&&s[i]=='R')||(i%2==0&&s[i]=='L')){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#define m 1000000007
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef long long int ll;
 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;

int main()
{
	ll a,b;
	cin>>a>>b;
	//cout<<(b-a)/(a-1);
	ll ans=ceil(floor((b-a))/(a-1));
	cout<<ans+1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ar array
#define db double
#define pi 3.14159265358979323846
#define pow pw
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#define N 100

int SelectionSort(int,int *);

int main(){
  int a,*num,i;
  scanf("%d",&a); 
  num = (int*)malloc(a*sizeof(int));
  for(i = 0;i < a;i++){
    scanf("%d",&num[i]);
  }
  SelectionSort(a,num);
  free(num);
  return 0;
  }

int SelectionSort(int len,int *a){
  int i,j,min,tmp,cnt=0;

  for(i = 0;i < len - 1;i++){
    min = i;
    for(j = i + 1;j < len;j++){
      if(a[j] < a[min]){
	       min = j;
      }

    }

    if(min != i){
      tmp = a[i];
      a[i] = a[min];
      a[min] = tmp;
      cnt++;
    }
    printf("%d ",a[i]);
  }
  printf("%d",a[len-1]);
  printf("\n");
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 604
from collections import deque

N, D, A=map(int, input().split())
XH=[list(map(int, input().split())) for _ in range(N)]
XH.sort(key=lambda x:x[0])
total=0
q=deque()
ans=0

for i in range(N):
  X, H=XH[i]
  while len(q) and q[0][0]<X:
    total-=q.popleft()[1]
  H-=total
  if H>0:
    attack_cnt=(H-1)//A+1
    ans+=attack_cnt
    damage=attack_cnt*A
    total+=damage
    q.append([X+2*D, damage])
print(ans)

Measured memory_bytes: 96728
# coding:utf-8
from collections import deque

S = deque(input())
Q = int(input())
queries = [input().rstrip('\n') for _ in range(Q)]
reverse = False

for query in queries:
    q = query.split(' ')
    if q[0] == '1':
        reverse = not reverse
    else:
        if q[1] == '1':
            S.appendleft(q[2]) if not reverse else S.append(q[2])
        else:
            S.append(q[2]) if not reverse else S.appendleft(q[2])

if reverse:
    S.reverse()
print("".join(S))

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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const LL LL_INF = LL(999999999999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;
const int RUN_SOLVE = 1;

#ifndef LOCAL_H
const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    for(int do_solve_time = 0;do_solve_time < RUN_SOLVE;do_solve_time++){
        void solve();
        if(DO_BENCHMARK){
            clock_t clock_start = clock();
            solve();
            clock_t clock_end = clock();
            const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
            cout << "\n------------------------------------\n" << time << "[ms]\n";
        }
        else solve();
    }
}

/************************************************************************************************************************************************/
void solve(){
    LL N;
    cin >> N;
    LL num = 1;
    N--;
    while(N >= pow(26,num)){
        N-=pow(26,num);
        num++;
    }
    vector<LL> name (num);
    for(LL i = 0;i < num;i++){
        name[i] = N%26;
        N /= 26;
    }
    REV(name);
    for(LL i = 0;i < num;i++){
        cout << char('a'+name[i]);
    }
    cout << endl;
}



Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  





void E(){
	int x , y , a, b , c ;
	cin >> x >> y >> a >> b >> c ;
	vi p(a),q(b),r(c);
	re(p);re(q);re(r);
	sort(rall(q));sort(rall(p));sort(rall(r));
	int mx = 0 ; 
	vi use ;
	rep(i,0,x) use.pb(p[i]);
	rep(i,0,y) use.pb(q[i]);
	use.insert(end(use),all(r));
	sort(rall(use));
	trace(use);
	for(int i = 0 ; i < x+y ; ++i) mx+=use[i];
	cout << mx << endl; 
};


signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) E();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
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 MOD = 1000000007;
ll INF =1<<30;
ll dp[110][100100];


int main(){
    int h,w,k;
    cin >>h>>w>>k;
    vector<string>fi(h);
    vector<vector<bool>> d(w,vector<bool>(h,true));
    rep(i,h){
        cin >> fi[i];
    }
    int ans = 0;
    for (int bit1 = 0; bit1 < (1 << h); ++bit1){
        for (int bit2 = 0; bit2 < (1 << w); ++bit2){
            int cnt = 0;
            rep(i,h){
                rep(j,w){
                    if(!(bit1&(1<<i))&&!(bit2&(1<<j))){
                        if(fi[i][j]=='#')cnt++;
                    }  
                }
            }
            if(cnt == k) ans ++;
        }

    }
    cout << ans <<endl;

}

Measured memory_bytes: 3496
#include<bits/stdc++.h>
    using namespace std;
    #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define int         long long
    #define pb          push_back
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
    #define INF         1e18
    const int N = 300 + 5, K = 501;

    void solve(){
        int h,w,k;
        cin>>h>>w>>k;
        string grid[h+1];
        int b = 0;
        for(int i=0; i<h; i++){
            cin>>grid[i];
            for(int j=0; j<w; j++){
                if(grid[i][j] == '#') b++;
            }
        }
        int ans = 0;
        int m1 = 0, m2 = 0;
        for(m1 = 0; m1<(1<<h); m1++){
            for(m2 = 0; m2<(1<<w); m2++){
                // cout<<m1<<endl;
                int t = 0;
                for(int i=0; i<h; i++){
                    if(m1 & (1<<i)) continue;
                    for(int j=0; j<w; j++){
                        if(m2 & (1<<j)) continue;
                        if(grid[i][j]=='#') t++;
                    }
                }
                if(t == k) ans++;
            }
        }
        cout<<ans<<endl;
    }

    int32_t main()
    {
        IOS;
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {       
            solve();
        }
        return 0;
    }

Measured memory_bytes: 3640
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;



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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,j) for(int i=0;i<j;i++)
#define REP(i,j,z) for(int i=j;i<z;i++)
int main()
{
	ll N;
	ll cnt=0;
	cin>>N;
	pair<ll,ll> P[200000];
	ll A,B;
	rep(i,N){
		cin>>A>>B;
		P[i]=make_pair(B,A);
	}
	sort(P,P+N);
	rep(i,N){
		cnt+=P[i].second;
		if(P[i].first<cnt){cout<<"No"<<endl; return 0;} 
	}
	cout<<"Yes"<<endl;
}


Measured memory_bytes: 3456
package main

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

// 数列の反転
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	s := ""
	for i := 0; i < n; i++ {
		sc.Scan()
		s = sc.Text() + " " + s
	}
	fmt.Println(strings.TrimSpace(s))
}



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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long a{N}, b{0}, c{0};
    for(unsigned long i{0}, X; i < N; ++i){
        cin >> X;
        b += 2 * X;
        c += X * X;
    }
    unsigned long ans{numeric_limits<unsigned long>::max()};
    for(unsigned long i{0}; i < 101; ++i)ans = min(ans, (a * i - b) * i + c);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; i++)
#define DEC(i, a, b) for(int i = (int)a; i >= (int)b; i--)
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define INF (int) 1e9 + 100
#define LLINF (ll) 1e18
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int n, q, a, b, depth[300005];
ll dp[550][100005], v[300005], w[300005];
vpi query[300005];

void dfs(int x, int dep) {
	int p = x/2;
	FOR(i, 0, 100000) dp[x][i] = dp[p][i];
	DEC(i, 100000, w[x]) dp[x][i] = max({dp[p][i-1], dp[p][i], dp[p][i-w[x]] + v[x]});
	if (dep < 9) {
		if (2*x <= n) dfs(2*x, dep+1);
		if (2*x < n) dfs(2*x+1, dep+1);
	}
}

int main() {
	fastio; cin >> n;
	depth[1] = 1;
	FOR(i, 2, n) depth[i] = depth[i/2]+1;
	FOR(i, 1, n) cin >> v[i] >> w[i];
	dfs(1, 1);
	cin >> q;
	while (q--) {
		cin >> a >> b;
		if (depth[a] <= 9) cout << dp[a][b] << "\n";
		else {
			vi vect;
			while (depth[a] > 9) {
				vect.pb(a);
				a /= 2;
			}
			ll res = 0, sz = vect.size();
			FOR(j, 0, (1<<sz)-1) {
				ll val = 0, wei = 0;
				FOR(k, 0, sz-1) if (j & (1<<k)) {
					val += v[vect[k]], wei += w[vect[k]];
				}
				if (wei <= b) res = max(res, val + dp[a][b-wei]);
			}
			cout << res << "\n";
		}
	}
}


Measured memory_bytes: 415028