akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int h, w;
char maze[51][51];
int d[51][51];

void bfs(int x, int y)
{
	queue<pair<int, int>> que;
	que.push({x, y});

	d[0][0] = 1;

	while (que.size()){
		pair<int, int> p = que.front();
		que.pop();

		if (p.first == h-1 and p.second == w-1) return;

		for (int i = 0; i < 4; i++){
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 <= nx and nx < h and 0 <= ny and ny < w and maze[nx][ny] == '.' and d[nx][ny] == -1){
				que.push({nx, ny});
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
}

int main()
{
	cin >> h >> w;
	int white = 0;
	REP(i, h) {
		REP(j, w){
			cin >> maze[i][j];
			if (maze[i][j] == '.') white++;
		}
	}

	memset(d, -1, sizeof(d));
	bfs(0, 0);

	cout << (d[h-1][w-1] == -1 ? -1 : white-d[h-1][w-1]) << endl;
}


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

#define INF 1e9
using namespace std;

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()


template<class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

template<class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

typedef long long ll;


int main() {
    int N = 0;
    cin >> N;
    int L[N];
    REP(i, N) {
        cin >> L[i];
    }
    sort(L, L + N);
    // 選択した二本は組み合わせなので重複しない。　よって、「選択した二本は(どっちがどっちか知らんけど)三角形の棒の中で最も長い二本」
    // とすれば三本の混合は起きなくなる。
    // 例えば 2,3,4は三角形の組み合わせだが、 2,3がForで決まってからの4と 3,2がForで決まってからの4は組み合わせにより重複しないが、
    // 3,4が決まってからの2と重複してしまう。
    // これを回避するために「選択した二本は(どっちがどっちか知らんけど)三角形の棒の中で最も長い二本」という制約を設けている。
    // この思考が出来るようにしたい前もハマったような・・・
    // REPで回しているインデックスの指す値,forで回しているインデックスの指す値をa,b (a>=b)とする。
    // とすると、 三角形の条件より、 max(b-a,a-b) < c < a+b が成立。
    // ここから条件を満たす棒の数を二分探索で求められる。
    // さらに c < b <= a が成立するため、  c < a+bは考えなくてよい。
    //
    int score = 0;
    REP(i, N) {
        for (int j = i + 1; j < N; ++j) {
            int a, b;
            a = L[i];
            b = L[j];
            if (a < b) swap(a, b);

            if ((a - b) >= b) continue;
            // bの立ち位置の確認
            int *pos = lower_bound(L, L + N, b);
            int last_index = (int) (pos - L);
            pos = upper_bound(L, L + N, max(b - a, a - b));
            int first_index = (int) (pos - L) - 1;
            int w = i - first_index - 1;
            score += w;
        }
    }

    cout << score << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int X;

bool primeJ(int a){
	if(a==1)return false;
	else if(a==2)return true;
	else if(a%2==0)return false;
	int dim=(int)(sqrt(a));
	for (int i=2;i<=dim;i++){
		if(a%i==0)return false;
	}
	return true;
}

signed main(){
	int X;
	cin>>X;
	for(int i=X;;i++){
		if(primeJ(i)){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>

using namespace std;

long long int A, a, n, m, y, s;
string str_1, str_2, str_3;
long long int x[2][30000];


long long int gcd(int m, int n){
	while (true) {
		if (m%n == 0)return n;
		m %= n;
		if (n%m == 0)return m;
		n %= m;
	}
}


int main() {
	cin >> n >> m;
	cin >> str_1 >> str_2;

	for (int i = 0; i < gcd(n, m); i++) {
		if (str_1[i*n / gcd(n, m)] != str_2[i*m / gcd(n, m)]) {
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << n * m / gcd(n, m) << '\n';
	return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
ll mod = 1000000007;
int INF = 0x3f3f3f3f;

int main() {
    ll x;
    cin >> x;
    vector<int> log;
    for(int i = 1; i <= int(floor(sqrt(x))); ++i) {
        if(x % i == 0) {
            log.push_back(i);
        }
    }

    for(auto v : log) {
        for(int a = -int(floor(sqrt(x))); a <= int(floor(sqrt(x))); ++a) {
            if(pow((v + a), 5) - pow(a, 5) == (double)x) {
                cout << v + a << " " << a << endl;
                break;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 4236
import collections

N, K = map(int, input().split())
As = list(map(int, input().split()))

myset = set(As)
if len(myset) <= K:
    print(0)
else:
    cnt = collections.Counter()
    for d in As:
        cnt[d] += 1
    cnt_val = sorted(cnt.values())
    print(sum(cnt_val[:(len(myset)-K)]))


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

int main(){
  int a,b; cin>>a>>b;
  if(abs(a)==abs(b)){
    if(a!=b)cout<<1<<endl;
    else cout<<0<<endl;
  }
  else if(abs(a)<abs(b)){
    int ans=0;
    if(a<0)ans++;
    if(b<0)ans++;
    cout<<ans+abs(b)-abs(a)<<endl;
  }
  else{
    int ans=0;
    if(a>0)ans++;
    if(b>0)ans++;
    cout<<ans+abs(a)-abs(b)<<endl;
  }
}


Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while(true) {
            String line = br.readLine();
            String[] line2 = line.split(" ");
            if(Integer.parseInt(line2[0]) == 0)
                if(Integer.parseInt(line2[1]) == 0)
                    break;
            print(Integer.parseInt(line2[0]),Integer.parseInt(line2[1]));
        }
    }
    static void print(int h,int w) {
        for(int i=0;i < h;i++) {
            for(int j = 0; j < w ; j++) {
                if(i % 2 == 0) {
                    if(j % 2==0) {
                        System.out.print("#");
                    }else {
                        System.out.print(".");
                    }
                }
                else {
                    if(j % 2==0) {
                        System.out.print(".");
                    }else {
                        System.out.print("#");
                    }
                }
            }
            System.out.println();
        }
        System.out.println();

    }
}

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main()
{
    ll n,sum=0;
    cin >> n;
    rep(i,n+1)sum += i;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
ans=[0 for i in range(10**5)]
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            tmp=x*x+y*y+z*z+x*y+y*z+z*x
            ans[tmp]+=1
for i in range(1,n+1):
    print(ans[i])

Measured memory_bytes: 9780
#include<iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    char S[3];
    bool flag=false;
    cin>>S;
    for(int i=0;i<3;i++){
        if(S[i]=='a'){
        for(int j=0;j<3;j++){
            if(S[j]=='b'){
            for(int k=0;k<3;k++){
                if(S[k]=='c'){
                    flag=true;
                }
            }
            }
        }
        }
    }
 if(flag){cout<<"Yes"<<endl;}
 else{cout<<"No"<<endl;}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	s=s+s.substr(0,s.size()-1);
	if (s.find(t)!=string::npos)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 3e3 + 10;

int S[N][N],Sum[N],fac[N],inv[N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

inline int fpm(int a,int b,int mod) {
	int res = 1;
	while(b) {
		if(b & 1) res = 1ll * res * a % mod;
		a = 1ll * a * a % mod,b /= 2;
	}
	return res;
}

inline void init(int n,int mod) {
	fac[0] = 1;
	For(i,1,n) fac[i] = 1ll * fac[i - 1] * i % mod;
	inv[n] = fpm(fac[n],mod - 2,mod);
	Fordown(i,n,1) inv[i - 1] = 1ll * inv[i] * i % mod;
}

inline int C(int n,int m,int mod) {
	return 1ll * fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int main() {

	int n = read(),mod = read();
	init(n + 5,mod);
	S[0][0] = 1;
	For(i,1,n + 5) For(j,1,i + 5)
		S[i][j] = (S[i - 1][j - 1] + 1ll * S[i - 1][j] * j) % mod;
	int ans = 0;
	For(i,0,n) {
		int tot = 0,Prod = 1,val = fpm(2,n - i,mod);
		int Others = fpm(2,fpm(2,n - i,mod - 1),mod);
		For(j,0,i) {
			tot = (tot + 1ll * Prod * S[i + 1][j + 1]) % mod;
			Prod = 1ll * Prod * val % mod;
		}
		tot = 1ll * C(n,i,mod) * tot % mod * Others % mod;
		ans = (ans + (i & 1 ? -tot : tot)) % mod;
	}

	printf("%d\n",(ans + mod) % mod);

	return 0;
}

Measured memory_bytes: 34304
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		for(int i=0;i<n;i++) {
			String key = sc.next(); int val = sc.nextInt();
			if(map.containsKey(key)) map.put(key, map.get(key)+val);
			else map.put(key, val);
		}
		V[] vs = new V[map.size()]; int i=0;
		for(Map.Entry<String, Integer> entry: map.entrySet()) {
			vs[i++] = new V(entry.getKey(), entry.getValue());
		}
		sort(vs);
		for(int j=0;j<vs.length;j++) {
			System.out.println(vs[j].s + " " + vs[j].t);
		}
	}
	
	class V implements Comparable<V> {
		String s;
		int t;
		
		V(String s, int t) {
			this.s = s;
			this.t = t;
		}
		
		@Override
		public int compareTo(V o) {
			// TODO Auto-generated method stub
			if(s.length() == o.s.length()) return s.compareTo(o.s);
			return s.length() - o.s.length();
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 38864
#include <iostream>

using namespace std;

int main()
{
  int a,b;
  cin >> a >> b;
  if(a == b){
    cout << "a == b" << endl;
  }
  else if(a > b) {
    cout << "a > b" << endl;
  }
  else 
    cout << "a < b" << endl;

  return 0;
}


Measured memory_bytes: 3108
// In the Name of God

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

#define	ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define ub upper_bound
#define lb lower_bound

const int N = 2e5 + 5;
const ll mod = 1e9 + 7;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const int pw = 257;

int h, w, a, b;
ll f[N], ans;

inline ll binpow(ll x, ll n) {
	ll res = 1;
	while (n) {
//		cerr << n << "\n";
		if (n % 2 == 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n /= 2;
	}
	return res;
}

inline ll c(int n, int k) {
	return (((f[n] * binpow(f[k], mod - 2)) % mod) * binpow(f[n - k], mod - 2)) % mod;
}

int main() {
	#ifdef Madi
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	#endif
	                                            	
	ios_base :: sync_with_stdio(false); cin.tie(NULL);

	f[0] = 1;
	rep(i, 1, 200000)
		f[i] = (f[i - 1] * i) % mod;

    cin >> h >> w >> a >> b;
    rep(i, b, w - 1)
    	ans = (((c(h - a - 1 + i, h - a - 1) * c(a - 1 + w - i - 1, a - 1)) % mod) + ans) % mod;

    cout << ans;

	#ifdef Madi
    cerr << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
	return 0;
}

Measured memory_bytes: 1792
# include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
template<typename T>vector<T> make_v(size_t a){ return vector<T>(a); }
template<typename T,typename... Ts>auto make_v(size_t a, Ts... ts){ return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type fill_v(T &t, const V &v){ t = v; }
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)
# define INIT                 std::ios::sync_with_stdio(false);std::cin.tie(0)

int h, w;
char a[1010][1010];
int d[1010][1010];
int main(){
    cin >> h >> w;
    REP(i, h)REP(j, w){
        cin >> a[i][j];
    }
    queue<pair<int, int>> q;
    REP(i, h)REP(j, w)d[i][j] = HINF<int>();
    REP(i, h)REP(j, w){
        if(a[i][j] == '#'){
            q.push(make_pair(i, j));
            d[i][j] = 0;
        }
    }
    while(!q.empty()){
        auto p = q.front();
        q.pop();
        REP(k, 4){
            int ny = dy[k] + p.first, nx = dx[k] + p.second;
            if(0 <= ny && ny < h && 0 <= nx && nx < w && d[ny][nx] == HINF<int>()){
                q.push(make_pair(ny, nx));
                d[ny][nx] = d[p.first][p.second] + 1;
            }
        }
    }
    int ans = 0;
    REP(i, h)REP(j, w){
        ans = max(ans, d[i][j]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 13456
#include <iostream>
#include <vector>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    string s, t; cin >> s >> t;
    int n = s.length(), m = t.length();
    int dp[n + 1][m + 1];
    for (int i = 0; i <= n; i++) dp[i][0] = 0;
    for (int i = 0; i <= m; i++) dp[0][i] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            if (s[i] == t[j]) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
        }
    }
    int j = m;
    vector<char> ans;
    for (int i = n; i > 0; i--) {
        while (!(j > 0 && s[i - 1] == t[j - 1] ? dp[i][j] == dp[i - 1][j - 1] + 1 : dp[i][j] == dp[i - 1][j])) j--;
        if (j > 0 && s[i - 1] == t[j - 1]) {
            ans.push_back(s[i - 1]);
            j--;
        }
    }
    for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i];
    return 0;
}


Measured memory_bytes: 35456
def main():
    N = int(input())
    A = []
    for _ in range(N):
        A.append(input())

    d = {}
    for ai in A:
        if d.get(ai):
            d[ai] += 1
        else:
            d[ai] = 1

    cnt = 0
    for v in d.values():
        if v % 2 != 0:
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    main()

Measured memory_bytes: 19476
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <utility>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <limits>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;++a) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define print_double(val,a) cout << fixed << setprecision(a) << val << endl;
ll mod = 1e9 + 7;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
  cin>>n;
  vector<int>a(n);
  rep(i,n){cin>>a[i];}
  Sort(a);
  int sum=0;
  rep(i,n){sum+=a[i];}
  sum-=a[n-1]/2;
  cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
string s;
  cin>>s;
  int fl=0;
  int flag=0;
  int n=s.length();
  int x=(n-1)/2;
  for(int i=0;i<n;i++){
  	if(s[i]==s[n-1-i])
  	flag=0;
  	else{
  	flag=1;
  	break;}
  }
  for(int i=0;i<x;i++){
    if(s[i]==s[x-1-i])
       fl=0;
       else{
         fl=1;
       break;}
}
       	int fla=0;
       	int y=(n+3)/2;
       	int z=0;
             for(int j=y-1;j<n;j++){
            if(s[j]==s[n-1-z]){
            z++;
               fla=0;}
               else{
               fla=1;
               break;}
               }
               if(fla==0&&fl==0&&flag==0)
               cout<<"Yes"<<endl;
               else
               cout<<"No"<<endl;
               
           }
            
        

Measured memory_bytes: 256
#include <stdio.h>
int solve(int,int,int,int*);

int main(){
int n,q,A[2000],m[2000];
int i,j;

scanf("%d",&n);
for(i=0;i<n;i++)    scanf("%d",&A[i]);
scanf("%d",&q);
for(i=0;i<q;i++)    scanf("%d",&m[i]);

for(j=0;j<q;j++){
    i=0;
if(solve(i,m[j],n,A)==1) printf("yes\n");
else printf("no\n");
}

return 0;
}

int solve(int i,int m,int n,int*A){
int res=0;
  if (m == 0)   return 1;
  if (i >= n)     return 0;
  res = solve(i + 1, m,n,A) || solve(i + 1, m - A[i],n,A);
   return res;
   }



Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
using namespace std;
static const int N=100,WHITE=0,GRAY=1,BLACK=2;

int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u) {
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for (v=0; v<n; v++) {
    if (M[u][v]==0) {
      continue;
    }
    if(color[v]==WHITE) {
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;
}
void dfs() {
  int u;
  for (u=0; u<n; u++) {
    color[u]=WHITE;
  }
  tt=0;
  for (u=0; u<n; u++) {
    if (color[u]==WHITE) {
      dfs_visit(u);
    }
  }
  for (u=0; u<n; u++) {
    cout<<u+1<<" "<<d[u]<<" "<<f[u]<<endl;
  }
}
int main() {
  int u,v,k,i,j;
  cin>>n;
  for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
      M[i][j]=0;
    }
  }
  for (i=0; i<n; i++) {
    cin>>u>>k;
    u--;
    for (j=0; j<k; j++) {
      cin>>v;
      v--;
      M[u][v]=1;
    }
  }
  dfs();
  return 0;
}


Measured memory_bytes: 3140
count = int(input())
numlist = list(map(int, sorted(input().split())))
result = 0

  
for i in range(1,count):
  numlist = sorted(numlist)
  sum = (numlist[1] + numlist[0]) / 2
  del numlist[0:2] #0,1番目の要素を削除
  numlist.append(sum)

  
print(sum)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

    vector <  pair <pair<string, int>, int> > SP(N);

    for (int i = 0; i < N; i++){
        int P;
        cin >> SP[i].first.first >> P;
        SP[i].first.second = 100 - P;
        SP[i].second = i + 1;
    }

    sort(SP.begin(), SP.end());

    for (int i = 0; i < N; i++){
        cout << SP[i].second << endl;
    }
    



    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    bool cur[200005] = {}, targ[200005] = {};
    std::vector<int> ans;
    for (int i = 1; i <= n; i++) std::cin >> targ[i];
    for (int i = n; i >= 1; i--) {
        if (cur[i] ^ targ[i]) {
            ans.push_back(i);
            for (int j = 1; j*j <= i; j++) {
                if (i%j != 0) continue;
                cur[j] ^= true;
                if (j*j != i) cur[i / j] ^= true;
            }
        }
    }
    bool flag = true;
    for (int i = 1; i <= n; i++) flag &= targ[i] == cur[i];
    if (!flag) {
        std::cout << -1 << std::endl;
        return 0;
    }
    std::cout << ans.size() << std::endl;
    for (int i = 0; i < (int)ans.size(); i++) {
        std::cout << ans[i] << " \n"[i == (int)ans.size() - 1];
    }
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,m;cin >> n >> m;
    vector<string> a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    bool ok;
    for(int x=0;x<n-m+1;++x){
        for(int y=0;y<n-m+1;++y){
            ok = true;
            for(int i=0;i<m;++i){
                for(int j=0;j<m;++j){
                    if(a[x+i][y+j]!=b[i][j]){
                        ok = false;
                        break;
                    }
                }
                if(!ok) break;
            }
            if(ok) break;
        }
        if(ok) break;
    }
    cout << (ok? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
#define sz size()
#define bgn begin()
#define en end()
#define pb push_back
#define pp() pop_back()
#define V vector
#define P pair
#define yuko(a) setprecision(a)
#define uni(a) a.erase(unique(a.begin(),a.end()),a.end())
#define Q queue
#define pri priority_queue
#define Pri priority_queue<int,vector<int>,greater<int>>
#define PriP priority_queue<P<int,int>,vector<P<int,int>>,greater<P<int,int>>>
#define ff first.first
#define fs first.second
#define sf second.first
#define ss second.second
#define all(a)  (a).begin(),(a).end()

void dfs(int n,V<int> &lunlun){
  if(n>3234566667)
    return;
  lunlun.pb(n);
  if(n%10<9) 
    dfs(n*10+(n%10)+1,lunlun);
  dfs(n*10+(n%10),lunlun);
  if(n%10>0) 
    dfs(n*10+(n%10)-1,lunlun);
}
signed main(){
  int k;
  cin>>k;
  V<int> lunlun;
  for(int i=1; i<=9; i++){
    dfs(i,lunlun);
  }
  Sort(lunlun);
  cout<<lunlun[k-1]<<endl;
}

Measured memory_bytes: 1400
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int M = sc.nextInt();
        Point[] students = readPoints(sc, N);
        Point[] checkpoints = readPoints(sc, M);

        System.out.println(solve(students, checkpoints));

        sc.close();
    }

    static Point[] readPoints(Scanner sc, int size) {
        Point[] result = new Point[size];
        for (int i = 0; i < result.length; ++i) {
            int x = sc.nextInt();
            int y = sc.nextInt();

            result[i] = new Point(x, y);
        }

        return result;
    }

    static String solve(Point[] students, Point[] checkpoints) {
        return Arrays.stream(students).map(student -> String.valueOf(find(checkpoints, student)))
                .collect(Collectors.joining("\n"));
    }

    static int find(Point[] checkpoints, Point student) {
        int minDistance = Integer.MAX_VALUE;
        int result = -1;
        for (int i = 0; i < checkpoints.length; ++i) {
            int distance = Math.abs(student.x - checkpoints[i].x) + Math.abs(student.y - checkpoints[i].y);
            if (distance < minDistance) {
                minDistance = distance;
                result = i + 1;
            }
        }

        return result;
    }
}

class Point {
    int x;
    int y;

    Point(int x, int y) {
        this.x = x;
        this.y = y;
    }
}

Measured memory_bytes: 29012
import java.util.*
fun main(args:Array<String>?): Unit {
    val (n, m) = readLine()!!.trim().split(' ').map(String::toInt)
    val nodes = Array(n){Stack<Edge>()}
    repeat(n - 1){
        val (a, b, c) = readLine()!!.trim().split(' ').map(String::toInt)
        nodes[a - 1].add(Edge(b - 1, c))
        nodes[b - 1].add(Edge(a - 1, c))
    }
    val servers = readLine()!!.trim().split(' ').map(String::toLong).toLongArray()
    println(solve(servers, nodes).let{
        list -> list.take(Math.min(list.size, m)).fold(0L){a, b -> a + b}
    })
}
data class Edge(val to: Int, val distance: Int)
fun solve(servers: LongArray, nodes: Array<out Collection<Edge>>): LongArray {
    val parents = IntArray(nodes.size){-1}
    val cache = Array(nodes.size){ listOf<Int>()}
    fun sub(current: Int, prev: Int): List<Int> {
        return if (parents[current] == prev) cache[current]
        else {
            parents[current] = prev
            cache[current] = nodes[current].filterNot{it.to == prev}.flatMap{(to, distance) ->
                val res = sub(to, current)
                if (res.isEmpty()) listOf(distance)
                else listOf(res.drop(1), listOf(res.first() + distance)).flatten()
            }.sortedDescending()
            cache[current]
        }
    }
    val results = MutableList(servers.size){listOf<Long>()}
    fun dfs(current: Int, prev: Int = -1): Unit {
        results[current] = sub(current, nodes.size).map{it * servers[current]}
        nodes[current].forEach{
            if (it.to != prev) dfs(it.to, current)
        }
    }
    dfs(0)
    return results.flatten().sortedDescending().toLongArray()
}


Measured memory_bytes: 486548
#include<stdio.h>
int main(void){
	char ball[2]="A",where[4];
	while(scanf("%s",where)!=EOF){
		if(ball[0]==where[0])ball[0]=where[2];
		else if(ball[0]==where[2])ball[0]=where[0];
	}
	printf("%s\n",ball);
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 100'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  cin >> n >> m;
  map<int, int> mp;
  set<int> was;
  int64 ans = 0, c = 0;
  for (int i = 0; i < m; ++i) {
    string s; int x;
    cin >> x >> s;
    if (s == "AC") {
      if (was.insert(x).second) {
        ans += mp[x];
        ++c;
      }
    } else {
      ++mp[x];
    }
  }
  cout << c << ' ' << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


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

#define ll long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define F first
#define S second

void solve() {

}

int main() {
#ifndef ONLINE_JUDGE
	freopen("manish.txt", "r", stdin);
	//freopen("ps.txt", "w", stdout);
#endif
	int t;
	t = 1;
	while (t--) {
		ll n, x, t;
		cin >> n;
		int arr[n];

		for (int i = 0; i < n; i++)
			cin >> arr[i];

		ll ans = 0;

		for (int i = 1; i < n; i++) {
			if (arr[i] < arr[i - 1]) {
				ans += (arr[i - 1] - arr[i]);

				arr[i] += (arr[i - 1] - arr[i]);
			}
		}

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

Measured memory_bytes: 4368
#include <iostream>
#include <stdlib.h>
using namespace std;
long n,i,h[100001],b[100001];
long tmp;
int main()
{
    //freopen("frog2.inp","r",stdin);
    cin >> n ;
    for (i=1;i<=n;i++)
    {
        cin >> h[i];
    }
    b[0]=99999999;
    b[1]=h[1];
    for (i=2;i<=n;i++)
    {
        b[i]=min(b[i-1]+abs(h[i]-h[i-1]),b[i-2]+abs(h[i]-h[i-2]));
    }
    cout << b[n]-b[1];
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;



int main(){

    
    int n, m;
    cin >> n >> m;
    vector<pair<ll,ll>> pairs(n);
    rep(i,n) cin >> pairs[i].first >> pairs[i].second;

    vsort(pairs);

    ll ans = 0;
    int index = 0;
    while(m > 0){
        if (pairs[index].second <= m){
            m -= pairs[index].second;
            ans += pairs[index].first * pairs[index].second;
            index++;
        }
        else{
            m -= 1;
            ans += pairs[index].first;
        }
    }


    cout << ans << endl;




}






//              g++ -std=c++1z

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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}


int main()
{
    ll n;

    cin >> n;

    ll ans=(n+1)/2;

    cout << ans <<endl;
 
    return 0;

}

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

using namespace std;

template <class T>inline T updmax(T& a, T b) {return a = max(a, b);}
template <class T>inline T updmin(T& a, T b) {return a = min(a, b);}

class Solution {
public:
	void solve() {
		int n, m;
		cin >> n >> m;
		if(n < 10 && m < 10){
			cout << n*m << "\n";
		}else{
			cout << -1 << "\n";
		}
		return;
	};
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	Solution solution;
	solution.solve();
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int a1,b1,c1;
cin>>a1>>b1>>c1;
if(a1==b1 && a1!=c1)
{
cout<<"Yes";
}
else if(b1==c1 && c1!=a1)
{
 cout<<"Yes";
}
else if(a1==c1 && a1!=b1)
{
 cout<<"Yes";
}
else
{
 cout<<"No";
}
return 0;
}


Measured memory_bytes: 256
using System;

namespace ITP1_6_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            var n = int.Parse(input[0]);
            var m = int.Parse(input[1]);

            var a = new int[n][];
            for(int i = 0; i < n; i++)
            {
                a[i] = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            }

            var b = new int[m];
            for(int i = 0; i < m; i++)
            {
                b[i] = int.Parse(Console.ReadLine());
            }

            for(int i = 0; i < n; i++)
            {
                var c = 0;
                for(int j = 0; j < m; j++)
                {
                    c += a[i][j] * b[j];
                }
                Console.WriteLine(c);
            }
        }
    }
}

Measured memory_bytes: 9416
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = - 10**18

for i in range(1, 2**10):
    x = 0
    for n in range(N):
        c = 0
        for j in range(10):
            if (i >> j) & F[n][j]:
                c += 1
        x += P[n][c]
    ans = max(ans, x)

print(ans)

Measured memory_bytes: 3064
N = int(input())
ans = float('inf')
for i in range(N//2):
    a = i+1
    b = N-a
    sa,sb = 0,0
    for j in range(max(len(str(a)),len(str(b)))):
        sa += a%10
        a //= 10
        sb += b%10
        b //= 10
    ans = min(sa+sb,ans)
print(ans)


Measured memory_bytes: 41708
#include<bits/stdc++.h>
#define ll long long 
#define ld long long double
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;  
int main() 
{
	FAST
	ll n,val;
	cin>>n;
	vector<pair<ll,ll>> v;
 	for(ll i=1;i<=n;i++)
	{
		cin>>val;
		v.push_back(make_pair(val,i));
	}
	sort(v.begin(),v.end());
	for(ll i=0;i<n;i++)
		cout<<v[i].second<<" ";
	return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=1,a,b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> a>>b;
       while(1){
          if(a*2<=b){
              ans++;
              a*=2;
          }
          else{
              break;
          }
       }
       Cout(ans);
       
return 0;
}


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

#define llu             unsigned long long int
#define ll              long long int
#define s(n)            scanf("%lld",&n)
#define p(n)            printf("%lld\n",n)
#define f0(i, n)        for( i = 0 ; i <  n ; i++ )
#define f1(i, n)        for( i = 1 ; i <= n ; i++ )
#define ff(i, m, n)     for( i = m ; i <= n ; i++ )
#define sp(i)           fixed << setprecision( i )
#define pb              push_back
#define pf              push_front
#define nl              cout<<"\n";

///ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75ELIN75
///                    ELIN(K-5)
///ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47ELIN47

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

    ll x,y,a,b,c,i,s=0,d,e;
    cin>>x>>y>>a>>b>>c;
    d=x;
    e=y;
    vector< ll > v1,v2,v3,v4;
    f1(i,a)
    {
        ll p;
        cin>>p;
        v1.pb(p);
        v4.pb(p);
    }
    f1(i,b)
    {
        ll q;
        cin>>q;
        v2.pb(q);
        v4.pb(q);
    }
    f1(i,c)
    {
        ll r;
        cin>>r;
        v3.pb(r);
        v4.pb(r);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    sort(v3.begin(),v3.end());
    sort(v4.begin(),v4.end());
    ll n=0;
    while(1)
    {
        ll m=0;
        auto j=v4.end();
        j--;
        if(!v1.empty() && d!=0 && m==0)
        {
            auto k=v1.end();
            k--;
            if(*k==*j)
            {
                s=s+*j;
                m=1;
                n++;
                v1.erase(k);
                d--;
            }

        }
        if(!v2.empty() && e!=0 && m==0)
        {
            auto k=v2.end();
            k--;
            if(*k==*j)
            {
                s=s+*j;
                m=1;
                n++;
                v2.erase(k);
                e--;
            }

        }
        if(!v3.empty() && m==0)
        {
            auto k=v3.end();
            k--;
            if(*k==*j)
            {
                s=s+*j;
                m=1;
                n++;
                v3.erase(k);
            }
        }

        v4.erase(j);
        if(n==(x+y))
        {
            break;
        }

    }

    cout<<s<<endl;



    return 0;
}


Measured memory_bytes: 8936
n,m=map(int,input().split())
v=[0]*n
w=[0]*n
for i in range(n):
    v[i],w[i]=map(int,input().split())
dp=[0]*(m+1)
old=[0]*(m+1)
for i in range(n):
    for j in range(1,m+1):
        if j>=w[i]:
            dp[j]=max(old[j],old[j-w[i]]+v[i])
    old=dp.copy()
print(dp[m])


Measured memory_bytes: 6512
#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 a,b;
    cin >> a >> b;
    if(a==1) a+=13;
    if(b==1) b+=13;
    if(a>b) cout << "Alice";
    else if(a<b) cout << "Bob";
    else cout << "Draw";
    
}

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

int main() {
	int d;
	cin >> d;
	const int n = 26;
	vector<int> c(n);
	vector<vector<int>> s(d, vector<int>(n));
	rep(i, n) cin >> c[i];
	rep(i, d) rep(j, n) cin >> s[i][j];
	vector<int> t(d), last(n);
	
	
	vector<vector<int>> nex(d);
	// 貪欲
	ll ans = 0;
	rep(i, d) {
		ll mx = -1001001001;
		int now = 0;
		
		rep(j, n) {
			ll tmp = ans;
			tmp += s[i][j];
			rep(k, n) {
				if(j == k) continue;
				tmp -= c[k] * (i+1-last[k]);
			}
			if(mx < tmp) {
				nex[i].push_back(now+1);
				mx = tmp;
				now = j;
			}
		}
		ans = mx;
		last[now] = i+1;
		t[i] = now+1;
	}
	int cnt = 0;
	while(1) {
		// 局所探索法
		cnt++;
		if(cnt > 200000) break;
		vector<int> old = t;
		const int CH = rand()%5 + 1; // CH箇所変える
		rep(i, CH) {
			// int nd = rand()%d;
			// int nq = rand()%n + 1;
			// t[nd] = nq;
			int nd = rand()%d;
			t[nd] = nex[nd][rand()%nex[nd].size()];
		}
		
		// 点数の再計算
		vector<int> nlast(n);
		ll now = 0;
		rep(i, d) {
			now += s[i][t[i]];
			nlast[t[i]-1] = i+1;
			rep(j, n) {
				now -= c[j] * (i+1-nlast[j-1]);
			}
		}
		
		// 良くなれば更新
		if(now > ans) {
			ans = now;
		} else {
			t = old;
		}
	}
	
	rep(i, d) printf("%d\n", t[i]);
	return 0;
}

Measured memory_bytes: 3788
open Batteries
let string_count string target =
  let rec count lst =
    match lst with
    | [] -> 0
    | first :: rest -> if first = target then 1 + count rest else count rest
  in let explode s = List.init (String.length s) (String.get s)
  in count @@ explode string

let _ = Printf.printf "%d\n" (700 + 100 * (string_count (read_line ()) 'o'))

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int a,b,c;
    cin>>a>>b>>c;
    a-=b;
    int t=min(a,c);
    c-=t;
    cout<<c;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define de(x) cout<<#x<<"="<<x<<endl
#define dd(x) cout<<#x<<"="<<x<<" "
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define repd(i,a,b) for(int i=a;i>=(b);--i)
#define repp(i,a,b,t) for(int i=a;i<(b);i+=t)
#define mt(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp(u,v) make_pair(u,v)
#define sz(a) (int)a.size()
#define pb push_back
#define PI acos(-1.0)
#define qc std::ios::sync_with_stdio(false)
#define all(a) a.begin(),a.end()
using namespace std;
typedef vector<int> vi;
typedef long long ll;
typedef double db;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;

const ll mod = 1000000007;
const int N = 1e5+6;
const int M = 2e6+6;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;

bool eq(const db &a, const db &b) { return fabs(a - b) < eps; }
bool ls(const db &a, const db &b) { return a + eps < b; }
bool le(const db &a, const db &b) { return eq(a, b) || ls(a, b); }
ll gcd(ll a,ll b) { return a==0?b:gcd(b%a,a); };
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll kpow(ll a,ll b) {ll res=1;a%=mod; if(b<0) return 1; for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll read(){
    ll x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
//inv[1]=1;
//for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
int n;
ll dp[N], a[N], e[N];
int main() {
    cin>>n;
    rep(i, 1, n + 1) cin>>a[i];
    if(a[1]) return printf("0\n"),0;
    dp[1] = 3; e[0] = 1;
    rep(i, 2, n + 1) {
        if(a[i]==0) dp[i] = (3 - e[0]);
        else {
            dp[i] = e[a[i]-1] - e[a[i]];
        }
        if(dp[i] <= 0) return printf("0\n"),0;
        e[a[i]]++;
    }
    ll ret = 1;
    rep(i, 1, n + 1) ret *= dp[i], ret %= mod;
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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;}
/*----------------------------------------------------------------*/
const int MOD = 998244353;
// const int MOD = 1000000007;

/*----------------------------------------------------------------*/
signed main(){

	int n,d,x;
	cin >> n >> d >> x;
	vll a(n);
	rep(i,n)cin >> a[i];

	int cnt = 0;
	rep(i,n){
		int day = 1;
		while(day <= d){
			day += a[i];
			cnt++;
		}
	}
	cout << cnt + x << endl;

	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://abc092.contest.atcoder.jp/tasks/abc092_b

Measured memory_bytes: 3612
#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 s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3592