akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

//	for priority queue
//	priority_queue<ipair, vector<ipair>, greater<ipair>>
using ipair = pair<int, pair<int, int>>;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; };
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };

int main()
{
	int x[5];
	cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
	int r = 0;
	for(int i = 0; i < 5; i++)
		if (x[i] == 0)
		{
			r = i;
			break;
		}
	r++;
	printf("%d", r);
	return 0;
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    vector<string> X = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

    string S;
    cin >> S;

    for(int i=0; i<7; i++)
        if(S == X[i])
        {
            cout << 7 - i << "\n";
            return 0;
        }

    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	int n, m;
	scanf("%d %d", &n, &m);
	map<int, int> cnt;
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		cnt[x]++;
	}

	while(m--) {
		int b, c;
		scanf("%d %d", &b, &c);
		swap(b, c);
		int me = 0;
		while(!cnt.empty() and cnt.begin()->first < b and c > 0) {
			int tmp = min(c, cnt.begin()->second);
			me += tmp;
			c -= tmp;
			cnt.begin()->second -= tmp;
			if(!cnt.begin()->second) {
				cnt.erase(cnt.begin());
			}
		}
		if(me > 0) {
			cnt[b] += me;
		}
	}

	ll ans = 0;
	for(auto p : cnt) {
		ans += 1LL * p.first * p.second;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 4992
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

com_mx=200005
mod=998244353
fac=[0]*com_mx
finv=[0]*com_mx
inv=[0]*com_mx
fac[0]=1
fac[1]=1
finv[0]=1
finv[1]=1
inv[1]=1
for i in range(2,com_mx):
  fac[i]=fac[i-1]*i%mod
  inv[i]=-inv[mod%i]*(mod//i)%mod
  finv[i]=finv[i-1]*inv[i]%mod

def com(n,k):
  if n<k or n<0 or k<0:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod

def main():
  n,m,k=LI()
  res=0
  tmp=m*pow(m-1,n-k-1,mod)
   
  for r in range(n-k-1,n):
    res=(res+tmp*com(n-1,r)%mod)%mod
    tmp=tmp*(m-1)%mod
  return res

# main()
print(main())


Measured memory_bytes: 77912
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int Max=0;
  vector<int> Mochi(N);
  int count=0;

  for(int i=0;i<N;i++)
    cin>>Mochi.at(i);
  
  for(int j=0;j<N;j++){
    Max=0;
    for(int i=0;i<N;i++){
      if(Mochi.at(i)>Max)
        Max=Mochi.at(i);
    }
    for(int i=0;i<N;i++){
      if(Mochi.at(i)==Max){
        Mochi.at(i)=0;
      }
    }
    if(Max>0)
      count++;
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans=0;
    if(a>b){
        ans+=b;
    }
    else{
        ans+=a;
    }
    if(c>d) ans+=d;
    else ans+=c;

    cout << ans;

    return 0;
}

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

#define endl "\n"
#define ll long long int
#define f(i,st,ed) for(ll i=st;i<ed;i++)
#define fr(i,ed,st) for(ll i=ed;i>=st;i--)
#define vv vector<ll>
#define all(v) v.begin(),v.end() 
#define pb push_back
#define pp pair<ll,ll>
#define gv(v,s,e) f(i,s,e){ ll x; cin >> x; v.pb(x);}
#define pv(v,s,e) f(i,s,e){cout << v[i] << " ";}
#define MOD 1000000007
#define debug(x) cout << x << endl;


void yes(){
    cout << "YES" << endl;
}

void no(){
    cout << "NO" << endl;
}

ll powmod(ll x, ll y, ll mod)
{
    ll ans=1;

    while(y)
    {
        if(y%2==1)
        {
            ans = (ans*x)%mod;
        }

        x = (x*x)%mod;
        y/=2;
    }

    return ans;
}

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

        ll n,k;
        cin >> n >> k;

        vv v;
        gv(v,0,n);

        ll dp[n+5];
        dp[0]=0;

        f(i,1,n)
        {
            ll mn=INT_MAX;
            ll t = i-k;
            ll g=0;
            ll p = max(g,t);
            fr(j,i-1,p)
            {
                mn = min(mn, dp[j]+abs(v[i]-v[j]));
            }
            dp[i]=mn;
        }

        cout << dp[n-1] << endl;

    return 0;
}



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

int main() {
  int N, L;
  cin >> N >> L;
  string S[N];
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  sort(S, S + N);
  for (int i = 0; i < N; i++) {
    cout << S[i];
  }
  cout << endl;
}


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

using namespace std;

map<int,int> rep;

int main(void){
  int n, x;
  cin >> n;
  for(int i = 0; i < n; ++i){
      cin >> x;
      rep[x]++;
  }
  int ans = 0;
  for(auto s : rep){
      if(s.first > s.second)
        ans += s.second;
      else ans += (s.second - s.first);
  }
  cout << ans;
}

Measured memory_bytes: 4736
#include <stdio.h>

int main()
{
  int N;
  int R;
  int K;
  
  scanf("%d %d", &N, &R);
  
 
  if (N < 10) {
	K = 100 * (10 - N);
    printf("%d", R + K);
  }
  else {
    printf("%d", R);
  }
 
  return 0;
}

Measured memory_bytes: 1704
import collections
import math

n = int(input())
a = [int(i) for i in input().split()]

l = [0]
for x in a:
    l.append(l[-1]+x)

l = l[1:]

c = collections.Counter(l)

res = 0
for x in c.values():
    res += sum(range(x))

res += c[0]

print(res)


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

#define debug_input freopen("stdin.in", "r", stdin)
#define debug_output freopen("stdout.out", "w", stdout)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORALL(i, n) for(int i = 0; i < n; i++)
#define FORD(i, a, b) for(int i = a; i >= b; i--)
#define SORT(a) sort(a.begin(), a.end())
#define REV(a) reverse(a.begin(), a.end())
#define NP(a) next_permutation(a.begin(), a.end())
#define ALL(a) a.begin, a.end()
#define mp make_pair
#define pb push_back
#define endl "\n"
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	int n;
	int ans = 0;
	cin >> n;
	FOR(c, 1, n - 1) {
		int temp = n - c;
		
		int mult = 1;
		for(int i = 2; temp > 1 and i * i <= temp; i++) {
			int cnt = 0; 
			while(temp % i == 0) {
				temp /= i;
				cnt++;
			}

			if(cnt) {
				mult *= (cnt + 1);
			}
		}	
		if(temp != 1) mult *= 2;

		ans += mult;
	}

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

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

const int N_MAX=10;
bool f[N_MAX][N_MAX];
int h,w;
int cnt=0;

bool dfs(int x, int y, int t) {
  if (x==h-1&&y==w-1&&t==cnt) return true;
  if (f[x+1][y]) return dfs(x+1, y, t+1);
  if (f[x][y+1]) return dfs(x, y+1, t+1);
  return false;
}

int main() {
  cin>>h>>w;
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      char c; cin>>c;
      if (c=='#') f[i][j]=true;
      else f[i][j]=false;
      if (f[i][j]) cnt++;
    }
  }
  if (dfs(0, 0, 1)) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 384
from collections import defaultdict as dd

N = int(input())
po = dd(int)
for _ in range(N):
    po[input()] += 1
M = int(input())
for _ in range(M):
    po[input()] -= 1

ans = 0
for s in po.values():
    if ans < s:
        ans = s
print(ans)

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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n ;
	cin>>n ;
	int arr[2][n] ;
	for(int i = 0 ; i < 2 ; ++i)
	{
		for(int j = 0 ; j < n ; ++j)
			cin>>arr[i][j] ;
	}
	int ans = 0 ;
	int sum = 0 ;
	for(int i = 0 ; i < n ; ++i)
	{
		sum += arr[0][i] ;
		int sum2 = 0 ;
		for(int j = i ; j < n ; ++j)
			sum2 += arr[1][j] ;
		ans = max(ans , sum + sum2) ;
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi  = vector<int>;
using ii  = pair<int,int>;
using vii = vector<ii>;
using ll  = long long;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)

const int N = 2e5;
ll a[N+5];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int n; ll k;
	cin >> n >> k;
	REP(i, 0, n-1) {
		cin >> a[i];
	}
	ll l = 0, r = 1e9+1;
	while (r - l > 1) {
		ll m = (l+r)/2;
		ll res = 0;
		REP(i, 0, n-1) {
			res += (a[i] - 1)/m;
		}
		// cout << "HELLO " << l << ' ' << r << ' ' << m << ' ' << res << '\n';
		if (res > k) {
			l = m;
		} else {
			r = m;
		}
	}
	cout << r << '\n';
	return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
#include <cstring> 
using namespace std;
using ll=long long;

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define LLONG_MAXs 9223372036854775800

#include <iostream>
#include <cmath>
using namespace std;
 

 
bool isPrimeNum( ll x ){ // 素数である場合 true を返す
  if( x <= 1 ){ // 1以下である場合は素数でないことがすぐにわかる
    return false;
  }
  // sqrt( double型 ) は引数の平方根を double型で返すので、int型でキャスト
  int n = (int)sqrt( (double)x );
  for( int i = 2; i <= n; i++ ){
    if( x % i == 0 ){ // 割り切る整数がある場合、即判定終了
      return false;
    }
  }
  return true; // 割り切る整数がない場合、素数である
}

constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}
constexpr ll min(ll a,ll b){
if(a>=b)return b;
if(a<b)return a;
}

constexpr ll max(ll a,ll b){
if(a>=b)return a;
if(a<b)return b;
}

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

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
  ll ans=0;
  ll N,K;
  cin>>N>>K;
  ll A[N];
  ll B[200001]={};
  FOR(i,0,N-1){
    cin>>A[i];
    B[A[i]]++;
  }
  sort(B,B+200001,greater<int>());

  FOR(i,K,200000){
    ans=ans+B[i];
    //cout<<B[i];
  }

cout<<ans<<endl;
return 0;

}
 


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define gc getchar
#define ll long long
#define db double
#define pii pair<int,int>
#define fi first
#define se second
#define Vi vector<int>
#define Vp vector<pii>

using namespace std;

inline void cmax(int &x,int y){y>x?x=y:0;}
inline void cmin(int &x,int y){y<x?x=y:0;}

int read(){
	char ch=gc(); int x=0,op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}

const int N=1e5+10;
int n; ll a[N],b[N],c[N];

int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep (i,1,n){
		cin>>a[i]>>b[i];
		ll tmp=(a[i]+b[i]-1)/b[i]*b[i];
		c[i]=tmp-a[i];
	}
	for (int i=n-1;i;i--)
		if (c[i+1]>c[i]) c[i]+=(c[i+1]-c[i]+b[i]-1)/b[i]*b[i];
	
	cout<<c[1]<<'\n';
	return 0;
}


Measured memory_bytes: 2560
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]

for i in range(n):
    l=[abs(c[j][0]-a[i][0])+abs(c[j][1]-a[i][1]) for j in range(m)]
    print(l.index(min(l))+1)

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<stdio.h>
#include<cmath>
#include<math.h>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<sstream>
#define forn(i,n) for(int (i)=0;i<(n);i++)
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
const int MAXN=100005;
const int INF=2147483647;
const ll LINF=9223372036854775807;
const int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
ll n,m;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>m;
	if(n==1||m==1)cout<<1;
	else cout<<(n*m+1)/2ll;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
// #define mp make_pair
#define nt _int128 
#define fir first
#define sec second
#define fast_as_levi ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define inf 0x3f3f3f3f
 
const ll mod = 1e9 + 7;
const ll mx = 2e6 + 5;
const ll mxi = 2e3 + 5;


int main()
{
    fast_as_levi;
    ll i,j,n,m;
    cin>>n>>m;
    ll ar[mx];
    for(i=1;i<=n;i++)
    {
        cin>>ar[i];
    }
    ll dp[mx] = {2};
    for(i=0;i<=m;i++)
    dp[i] = 2;
    // memset(dp,2,sizeof(dp));
    for(i=1;i<=m;i++)
    {
        for(j=1;j<=n;j++)
        {
            if((ar[j]<=i) && (dp[i-ar[j]] == 2))
            {
                dp[i] = 1;
            }
        }
    }
    // for(i=0;i<=m;i++)
    // cout<<dp[i]<<" ";
    // cout<<"\n";
    if(dp[m]==1)
    cout<<"First\n";
    else
    cout<<"Second\n";
}

Measured memory_bytes: 17920
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

#define int long long

const int MAX_V = 100005;
vector<int> G[MAX_V];

int color[MAX_V];

bool dfs(int cur, int c){
	color[cur] = c;
	for(auto to : G[cur]){
		if(color[to] == c) return false;
		if(color[to] == 0 && not dfs(to, -c)) return false;
	}
	return true;
}

bool solve(int n){
	rep(i,n){
		if(color[i] == 0){
			if(not dfs(i, 1)){
				return false;
			}
		}
	}
	return true;
}

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

	rep(i,m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}

	if(solve(n)){
		int w = 0, b = 0;
		rep(i,n){
			if(color[i] == 1) w++;
			else b++;
		}
		cout << w * b - m << endl;
	}else{
		cout << n * (n - 1) / 2 - m << endl;
	}
}


Measured memory_bytes: 7424
#include <iostream>
#include <algorithm>

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

using namespace std;

using ll = long long;

const int mod = 1e9 + 7;

int n;
int x[100000];

int mul(int a, int b){
  return ll(a) * b % mod;
}
int fact(int k){
  return k ? mul(fact(k - 1), k) : 1;
}

int main(){
  cin >> n;
  rep(i, n){
    cin >> x[i];
  }
  int ans = 1;
  int p = 0;
  int k = 0;
  while(true){
    while(p < n && x[p] > 2 * k){
      ++p;
      ++k;
    }
    if(p == n){
      ans = mul(ans, fact(k));
      break;
    }
    ans = mul(ans, k + 1);
    ++p;
  }
  cout << ans << endl;
  return 0;
}

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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> adj[n + 1];
    vector<int> prev(n + 1, 0);
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u); } vector<int> dist(n + 1, 1e9); queue<int> q; q.push(1); dist[1] = 0; while (!q.empty()) {
        int u = q.front();
        q.pop();
        for (int v: adj[u]) {
            if (dist[v] == 1e9) {
                dist[v] = dist[u] + 1;
                prev[v] = u;
                q.push(v);
            }
        }
    }
    for (int i = 2; i <= n; i++) {
        if (dist[i] == 1e9) {
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';
    for (int i = 2; i <= n; i++) {
        cout << prev[i] << '\n';
    }
    return 0;
}



Measured memory_bytes: 10544
import java.io.*;
import java.util.*;

//solution classes here

public class Main {

    //main solution here

    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        long[] red = new long[a];
        long[] green = new long[b];
        long[] col = new long[c];
        for(int i=0;i<a;i++)
            red[i]=sc.nextLong();
        for(int i=0;i<b;i++)
            green[i]=sc.nextLong();
        for(int i=0;i<c;i++)
            col[i]=sc.nextLong();

        Arrays.sort(red);
        Arrays.sort(green);
        Arrays.sort(col);
        ArrayList<Long> list = new ArrayList<>();
        for(int i=a-1;i>=a-x;i--) {
            list.add(red[i]);
        }

        for(int i=b-1;i>=b-y;i--) {
            list.add(green[i]);
        }

        for(int i=0;i<c;i++) {
            list.add(col[i]);
        }

        Collections.sort(list);

        long sum=0;
        for(int i=list.size()-1;i>=list.size()-x-y;i--)
            sum+=list.get(i);
        out.println(sum);




        out.flush();
        out.close();
    }

    //solution functions here


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

/* *****************************************************************************************************************************
 * I'M NOT IN DANGER, I'M THE DANGER!!!
 * *****************************************************************************************************************************
 */

Measured memory_bytes: 60076
import java.util.Scanner;

public class Main {

    public static void main(String... args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();

        int num = 0;
        if ( N <= K ) {
            num = N * X;
        } else {
            num = ( N - K ) * Y +  K * X;
        }

        System.out.println(num);

    }

}

Measured memory_bytes: 9556
#include<bits/stdc++.h>
using namespace std;
struct point{
	double x,y;
	point(){}
	point(double _x,double _y){
		x=_x;y=_y;
	}
	point operator +(const point &b) const{
		return point(x+b.x,y+b.y);
	}
	point operator -(const point &b) const{
		return point(x-b.x,y-b.y);
	}
	double operator ^(const point &b) const{
		return (x*b.x)+(y*b.y);
	}
	double operator *(const point &b) const{
		return x*b.y-y*b.x;
	}
	point operator *(const double &b) const{
		return point(x*b,y*b);
	}
};
double len(point p){
	return (p.x*p.x+p.y*p.y);
}
int main(){
	point res,p1,p2,p;
	cin>>p1.x>>p1.y>>p2.x>>p2.y;
	int q;
	cin>>q;
	while(q--){
		cin>>p.x>>p.y;
		res=(p2-p1)*(((p-p1)^(p2-p1))/len(p2-p1));
		res=res+p1;
		if(fabs(res.x)==0) res.x=0;
		if(fabs(res.y)==0) res.y=0;
		printf("%.8lf %.8lf\n",res.x,res.y);
	}
	return 0;
}


Measured memory_bytes: 3288
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
using namespace std;


int main() {
	map<int, int> mp;
	long long int a, b = 0, num[200005], sum[200005] = {}, n, cou = 0, res = 0, memo;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> num[i];
		sum[i] = sum[i - 1] + num[i];
	}
	sort(sum , sum + n + 1);
	
	memo = sum[0];
	cou = 1;
	for (int i = 1; i <= n; i++) {
		if (sum[i] != memo) {
			
			res += cou * (cou - 1) / 2;
			cou = 1;
			memo = sum[i];
		}
		else { cou++; }
	}
	res += cou * (cou - 1) / 2;
	cout << res;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
    }
    sort(s.begin(),s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    cout << s.size() << endl;
}


Measured memory_bytes: 9600
package main

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

func solve() {
	s, t := getRunes(), getRunes()

	dp := make([][]int, len(s)+1)
	for i := range dp {
		dp[i] = make([]int, len(t)+1)
	}

	for i, ri := range s {
		for j, rj := range t {
			if ri == rj {
				dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1)
			} else {
				dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j])
				dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1])
			}
		}
	}

	ans := ""
	for i, j := len(s), len(t); i > 0 && j > 0; {
		switch dp[i][j] {
		case dp[i-1][j]:
			i--
		case dp[i][j-1]:
			j--
		default:
			ans = string(s[i-1]) + ans
			i--
			j--
		}
	}

	fmt.Fprintln(wr, ans)
}

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

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

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

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

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 80640
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
ll strtoint(string str);
int main(){
	fast;
	ll n,k,cnt=0; cin>>n>>k;
	vector<ll> arr(n);
	for(auto i=0;i<n;++i)cin>>arr[i];
	sort(arr.begin(), arr.end(),greater<>());
	for(auto i=0;k&&i<n;++i){
		arr[i]=0;
		--k;
	}
	for(auto i=0;i<n;++i)cnt+=arr[i];
	cout<<cnt<<'\n';
	return 0;
}
ll strtoint(string str){
	ll x=0;
	stringstream ss;
	ss<<str;
	ss>>x;
	return x;
}

Measured memory_bytes: 1792
main = do
    [a,b,c,d,e,k] <- map read . lines <$> getContents :: IO [Int]
    putStrLn $ if (or . map (>k))
        [x | x<-[1..122], y<-[a,b,c,d,e], z<-[a,b,c,d,e], x==abs(y-z)]
            then ":("
            else "Yay!"

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

using namespace std;

int main(){
  string b;
  cin >> b;
  for(auto& a : b){
    switch(a){
      case 'A':
        cout << 'T';
        break;
      case 'T':
        cout << 'A';
        break;
      case 'C':
        cout << 'G';
        break;
      case 'G':
        cout << 'C';
        break;
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
MAX = 200000


def main():
  R = []

  n  = input()

  for i in range(int(n)):
      R.append(int(input()))

  maxv = -20000000000;
  minv = R[0]

  for i in range(1,int(n)):
      maxv = max([maxv,R[i] - minv ])
      minv = min([minv,R[i]])

  print(maxv)


if __name__ == "__main__":
    main()


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

int main(){
	const int INF = 2000000000;
	int N, T;
	int x, y;
	cin >> N >> T;
	int cost = INF;
	for (int i = 0 ; i < N; i++){
		cin >> x >> y;
		if (y <= T){
			cost = min(cost, x);
		}
	}
	if (cost == INF){
		cout << "TLE";
		return 0;
	}
	cout << cost;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
    static int n,k;
    static String line;
    public static void main(String args[]){

        Scanner s=new Scanner(System.in);
        Integer a= s.nextInt();
        Integer b=s.nextInt();

            String ret1="";
            for (int i = 0; i <a ; i++) {
                ret1+=b.toString();
            }

            String ret2="";
            for (int i = 0; i <b ; i++) {
                ret2+=a.toString();
            }

            if(ret1.compareTo(ret2)<0){
                System.out.println(ret1);

            }else{
                System.out.println(ret2);
            }



    }
}

Measured memory_bytes: 21844
#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 indent() cout << '\n'
#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 / gcd(a, b) * 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};
string alphabet = "abcdefghijklmnopqrstuvwxyz";

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n){
        ans = INF;
        rep(i, 2, sqrt(n) + 1){
            if(n % i){
                continue;
            }
            ll j = n / i;
            debug(i), debug(j);
            mins(ans, ll(1 + max(log10(i), log10(j))));
        }
        if(ans == INF){
            print(ll(1 + log10(n)));
        }else{
            print(ans);
        }
    }
}


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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define debug(x) cout << #x << " : " << x << '\n'

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

  int ans = -1;
  int N;
  cin >> N;
  string S;
  cin >> S;

  FOR(i, 1, N) {
    int count = 0;
    string L = S.substr(0, i);
    string R = S.substr(i, N - i);

    for (char c = 'a'; c <= 'z'; c++) {
      if ((L.find(c) != -1) && (R.find(c) != -1)) {
        count++;
      }
    }

    ans = max(ans, count);
  }

  cout << ans << '\n';

  return 0;
}

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

#define pb	push_back
#define eb	emplace_back
#define mk	make_pair
#define fi	first
#define se	second
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const ll MAX = 1e18;

int main() {
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    ll ans = 1;
    while(n--) {
        ll x; cin >> x;
        if(!x) { ans = 0; break; }
        if(MAX/ans < x) ans = -1;
        if(ans != -1) ans *= x;
    }
    cout << (ans>MAX?-1:ans) << endl;
    return 0;
}



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

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

    int array[n];
    int data;
    for(int i = 0;i < n;i++) {
        cin >> array[i];
    }
    int first = 0;
    int second = 0;
    for(int i = 0;i < n;i++){
        if(array[i] >= first) {
            second = first;
            first = array[i];
            data = i;//to tell the truth,data = i + 1
        }else if(array[i] >= second){
            second = array[i];
        }
    }
    for(int i = 0;i < n;i++){
        if(first == second){
            cout << first << endl;
        }else{
            if(i == data){
                cout << second << endl;
            }else{
                cout << first << endl;
            }
        }
    }
    return 0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

void solve()
{
  int ans=0;

  llong n;
  cin >> n;
  if (n%2==0)
  {
    ans=n;
  }
  else
  {
    ans=2*n;
  }


  cout << ans << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {

	int a, b, c, d;

	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;

	if (abs(a - c) <= d) {
		cout << "Yes" << endl;
	}
	else if (abs(a - b) <= d && abs(b - c) <= d) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[2002][2002];
long long a[2002];
const long long inf = 1e18;

int main() {
  int n, x;
  cin >> n >> x;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for(int i = 0; i < n; i++) dp[0][i] = a[i];
  for(int i = 1; i < n; i++) {
  	for(int j = 0; j < n; j++) {
      dp[i][j] = min(dp[i - 1][(j + n - 1) % n], a[j]);
    }
  }
  long long ans = inf;
  for(int i = 0; i < n; i++) {
  	long long res = 1LL * x * i;
    for(int j = 0; j < n; j++) {
      res += dp[i][j];
    }
    ans = min(ans, res);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll>
#define pl pair<ll,ll>
#define mp make_pair
#define rep(i,b) for(ll i=0;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define all(v) (v).begin(),(v).end()
using namespace std;


bool compare_by_b(pair<string,ll> a, pair<string,ll> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return b.second < a.second;
    }
}

ll n,T,t,previ,twice;
int main(){
  cin>>n>>T;
  cin>>previ;
  rep(i,n-1){
      cin>>t;
      if(previ+T-t>0)twice+=previ+T-t;
      previ=t;
  }
  cout<<n*T-twice<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 500001
using namespace std;
ll mi(ll n,ll m){ll pw=n;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define mkp make_pair
//#define d double
void solve(){
int n,l;
cin>>n>>l;
vs vec(n);
rep(i,0,n) cin>>vec[i];
Sort(vec);
rep(i,0,n) cout<<vec[i];
}
int32_t main(){
FIO;
int t=1;
//cin>>t;
while(t--){
	solve();
}
}



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

int main(){
int A,B,C,D,min,max,ans;

cin>>A;
cin>>B;
cin>>C;
cin>>D;

if(A>=C){
min = A;

}else{
  min = C;
}

if(B>=D){
  max = D;
}else{
  max = B;
}

ans = max-min;
if(ans<0){
  ans = 0;
}

cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;
  int ans = 1;
  for(int b = 2; b < n; b++){
    int tmp = 0;
    for(int p = 2; tmp < n; p++){
      tmp = pow(b,p);
      if(tmp <= n){
        //cout << tmp << endl;
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>

using namespace std;

int main()
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if(b>=c)
	{
		cout <<"Yes"<<endl;
	}
	else
	{
		if(c%b==0)
		{
			int x=c/b;
			x--;
			if(x*d>=a)
			{
				cout <<"No"<<endl;
			}
			else
			{
				cout << "Yes" <<endl;
			}
		}
		else
		{
			int x=c/b;
			if(x*d>=a)
			{
				cout <<"No"<<endl;
			}
			else
			{
				cout << "Yes" <<endl;
			}
		}
	}
	return 0;
 } 

Measured memory_bytes: 3624
import math

from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


K = int(input())

result = 0
for i in range(1, K + 1):
    for p in range(1, K + 1):
        for q in range(1, K + 1):
            result += gcd(i, p, q)
            
print(result)

Measured memory_bytes: 69628
h, n = map(int, input().split())
AB = [tuple(map(int, input().split())) for i in range(n)]
A = [a for a, b in AB]
B = [b for a, b in AB]
inf = 10**10
# DP[i][j]=i個以内で体力j以上削るための消費魔力の最小値
DP = [[inf for j in range(h+1)] for i in range(n+1)]
DP[0][0] = 0
for i in range(n):
    for j in range(h+1):
        DP[i+1][j] = min(DP[i][j], DP[i+1][max(0, j-A[i])]+B[i])
print(DP[n][h])


Measured memory_bytes: 125404
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]

a, b = map(int, input().split())

if a == 1:
    a = 14
if b == 1:
    b = 14

if a > b:
    print("Alice")
elif a == b:
    print("Draw")
else:
    print("Bob")



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

ege = 0
for _ in range(N-1):
  a, b = map(int, input().split())
  if a > b:
    a,b = b,a
  ege += a*(N-b+1)

vtx = 0
for k in range(1,N+1):
  vtx += (N-k+1)*k

print(vtx-ege)
  


Measured memory_bytes: 9004
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int test[345678], kari[345678], cost[345678];
signed main() {
	int n, a, b, c = 0, cnt = 0, ans = 0; cin >> n;
	int z = 0;
	for (int h = 0; h < n; h++) {
		cin >> a; cnt += a; test[h] = a;
	}
	for (int h = 0; h < n; h++) {
		cin >> b; cnt -= b; kari[h] = b;
	}
	if (cnt < 0) { cout << -1 << endl; return 0; }
	for (int h = 0; h < n; h++) {
		if (test[h] < kari[h]) { ans += kari[h] - test[h]; z++; }
		if (test[h] > kari[h]) { cost[c] = test[h] - kari[h]; c++; }
	}
	sort(cost, cost + c);
	if (ans == 0) { cout << 0 << endl; return 0; }
	for (int h = c - 1; h >= 0; h--) {
		ans -= cost[h]; z++;
		if (ans < 1) { cout << z << endl; return 0; }
	}
	return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<queue<int>> A(N, queue<int>());
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N - 1; j++) {
      int a;
      cin >> a;
      a--;
      A[i].push(a);
    }
  }

  int finish_count = 0;
  vector<int> days(N, 0);
  while (true) {
    bool updated = false;
    for (int i = 0; i < N; i++) {
    next:
      if (A[i].empty()) continue;
      int t = A[i].front();
      if (A[t].empty()) {
	cout << -1 << endl;
	return 0;
      }
      if (A[t].front() == i) {
	int d = max(days[i], days[t]) + 1;
	A[i].pop();
	A[t].pop();
	if (A[i].empty()) finish_count++;
	if (A[t].empty()) finish_count++;
	days[i] = d;
	days[t] = d;
	updated = true;
	goto next;
      }
    }

    if (finish_count == N) {
      break;
    }
    if (!updated) {
      cout << -1 << endl;
      return 0;
    }
  }

  int res = 0;
  for (int i = 0; i < N; i++) {
    res = max(res, days[i]);
  }
  cout << res << endl;

  return 0;
}


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

int main(){
  int a,b,c,x,y,z,N,Y;
  x = -1;
  y = -1;
  z = -1;
  cin >> N >> Y;
  for(a=0;a<=N;a++){
    for(b=0;b<=N;b++){
      c = N - a - b;
      if(c>=0){
        if(10000*a+5000*b+1000*c == Y && a + b + c == N){
          x = a;
          y = b;
          z = c;
          break;
          }
      }
    }
  }
  cout << x << " " << y << " " << z << " " << endl; 
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin>>N>>Q;
    vector<ll> a(N),x(N);
    REP(i,N) cin>>a[i];
    REP(i,Q) cin>>x[i];
    REP(i,Q){

        ll sum = 0;
        ll ans = 0;
        int right=0;
        for(int left=0;left<N;++left){
            while(right<N && sum+a[right]<=x[i]){
                sum+=a[right];
                ++right;
            }
            ans+=right-left;
            sum-=a[left];
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 4272
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    int n;
    cin >> n;
    vi input(n);
    rep(i, n) {
        cin >> input[i];
    }
    vi ans(n, 0);

    Rep(i, n+1) {
        int can = i*2;
        for (int j = i * 2, dist = 0; j < n; j++, dist++) {
            if (input[j-1] > (i * 2) + (dist * 2)) {
                can++;
            } else {
                break;
            }
        }
        ans[i-1] = min(can, n);
    }
//    rep(i, n) { cout << ans[i] << endl;}

    int ret = 1;
    rep(i, n) {
        ret *= (ans[i] - i);
        ret %= MOD;
    }
    cout << ret << endl;



    return 0;
}



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

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 18;
int const modulo = 1000000007;
int p[1 + (1 << nmax)];

void dfs(int node, int offset, int acc, std::vector<std::pair<int,int>> &sons) {
  acc = 1LL * acc * node % modulo;
  if(offset < node) {
    sons.push_back({node - offset, acc});
  } else {
    dfs(node * 2, offset, acc, sons);
    dfs(node * 2 + 1, offset, acc, sons);
  } 
}
int sum[2][1 + (1 << nmax)];

void gcd(int a, int b, int &x, int &y) {
  if(b == 0) {
    x = 1;
    y = 0;
  } else {
    gcd(b, a % b, x, y);
    int aux = x;
    x = y;
    y = aux - a / b * y;
  }
}

int inv(int number) {
  int x, y;
  gcd(number, modulo, x, y);
  x %= modulo;
  if(x < 0)
    x += modulo;
  return x;
}

void clearnode(int node, int offset, int &result) {
  if(sum[0][node] == 0 && sum[1][node] == 0)
    return ;
  if(1 < node)
    clearnode(node / 2, offset, result);

  if(node <= offset) {
    result += 1LL * node * ((1LL * sum[0][node * 2] * sum[1][node * 2 + 1] + 1LL * sum[1][node * 2] * sum[0][node * 2 + 1]) % modulo) % modulo;
    if(modulo <= result)
      result -= modulo;
  }

  sum[0][node] = sum[1][node] = 0;
}

void update(int node, int acc, int p) {
  acc = 1LL * acc * node % modulo;
  sum[p][node] += acc;
  if(modulo <= sum[p][node])
    sum[p][node] -= modulo;
  if(1 < node)
    update(node / 2, acc, p);
}

int main() {
  int n;
  std::cin >> n;
  int lim = (1 << n);
  int offset = (1 << (n - 1)) - 1;
  for(int i = 1;i <= (1 << (n - 1)); i++)
    std::cin >> p[i];
  int result = 0;
  for(int i = 1; i <= offset; i++) {
    std::vector<std::pair<int,int>> sons;
    dfs(i, offset, 1, sons);
    int half = sons.size() / 2;
    
    for(int i = 0; i < half; i++)
      update(offset + p[sons[i].first], sons[i].second, 0);
    
    for(int i = half; i < sons.size(); i++)
      update(offset + p[sons[i].first], sons[i].second, 1);
    int result2 = 0; 
    for(int i = 0; i < sons.size(); i++)
      clearnode(offset + p[sons[i].first], offset, result2);

    result += 1LL * inv(i) * result2 % modulo;
    if(modulo <= result)
      result -= modulo;
  }
  std::cout << result;
  return 0;
}


Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
int main() {
    int n,w;
    cin>>n>>w;
    i64 wt[n+1],v[n+1],dp[n+1][w+1];
    for(int i = 1; i <= n; i++)
        cin>>wt[i]>>v[i];
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= w; j++) {
            if(i == 0 || j == 0) {
                dp[i][j] = 0;
                //continue;
            }
            else if(wt[i] <= j)
                dp[i][j] = max(v[i] + dp[i-1][j-wt[i]],dp[i-1][j]);
            else 
                dp[i][j] = dp[i-1][j];
            //cout<<dp[i][j]<<" ";
            //if(dp[i][j] < 10)
                //cout<<" ";
        }
        //if(i > 0)
            //cout<<endl;
    }
    cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(string, a, b);

  int sq, rt;
  sq = stoi(a + b);
  rt = (int)sqrt(sq);

  puts(sq == rt * rt ? "Yes" : "No");

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll d[55];
deque<ll> D;
priority_queue<ll> Q;

int main()
{
	int N,K;
	cin >> N >> K;
	rep(i,N)
	{
		cin >> d[i];
	}

	ll ans = 0;
	for (int i = 1; i <= K; ++i)
	{
		for (int j = 0; j <= i; ++j)
		{
			if (j > N) continue;
			for (int k = 0; k <= j; ++k)
			{
				ll temp = 0;
				D.clear();
				rep(l,N)
				{
					D.push_back(d[l]);
				}
				rep(l,k)
				{
					temp += D[0];
					Q.push(-1 * D[0]);
					D.pop_front();
				}
				rep(l,j-k)
				{
					temp += D[D.size()-1];
					Q.push(-1 * D[D.size()-1]);
					D.pop_back();
				}
				//cout << i << " " << j << " " << k << " " << temp << endl;
				ans = max(ans,temp);
				for (int l = 0; l < i-j && !Q.empty(); ++l)
				{
					temp += Q.top();
					Q.pop();
					ans = max(ans,temp);
				}
				while(!Q.empty()) Q.pop();
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256