akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>

int main(void){
  int n;
  std::cin >> n;

  std::vector<int> a(n), b(n);
  std::map<int, int> a_cnt, b_cnt;
  std::set<std::pair<int, int> > t_ureshii;
  for(int i=0; i<n; i++){
    std::cin >> a[i] >> b[i];
    if(a_cnt.find(a[i]) == a_cnt.end()) a_cnt[a[i]] = 0;
    if(b_cnt.find(b[i]) == b_cnt.end()) b_cnt[b[i]] = 0;
    a_cnt[a[i]]++;
    b_cnt[b[i]]++;
    t_ureshii.insert(std::make_pair(a[i] + b[i], i));
  }


  long result = 0;
  for(int i=0; i<n; i++){
    if(i%2==0){
      result += a[(*t_ureshii.rbegin()).second];
      t_ureshii.erase(*t_ureshii.rbegin());
    }else{
      result -= b[(*t_ureshii.rbegin()).second];
      t_ureshii.erase(*t_ureshii.rbegin());
    }
  }
  std::cout << result << std::endl;

  return 0;
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int mod = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


vector<bool> prime(300100);

void eratos ( int n){
	prime[2] = true; prime[0] = prime[1] = false;
	for(int i = 3; i <= n; i += 2) prime[i] = true, prime[i+1] = false;
	int limit = (int)sqrt((double)n) + 1;
	for(int i = 3; i <= limit; i += 2){
		if(!prime[i]) continue;
		for(int j = i * i, k = i * 2; j <= n; j += k) prime[j] = false;
	}
}
int main()
{
	
	//cin.tie(0); ios_base::sync_with_stdio(false);
	eratos(300000);
	VI prm;
	const int MX = 100;
	rep(i,300000){
		if(prime[i] && i%5==1) prm.push_back(i);
		if(sz(prm) > MX+4) break;
	}
	int n;
	cin >> n;
	
	//dbg(sz(prm));
	string sq=string(MX, '0');
	rep(i,n) sq[i] ='1';
	sort(all(sq));
	do {
		int sm =0;
		rep(i, MX) if(sq[i]=='1') sm += prm[i];
		if(!prime[sm] ){
			//dbg("sm=",sm);
			rep(i, MX) if(sq[i]=='1'){ cout << prm[i] <<" ";}
			return 0;
		}
	} while ( next_permutation(all(sq)) );

	
	return 0;
}


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

#define MAX(a,b) ((a>b)?a:b)
#define MIN(a,b) ((a>b)?b:a)

int main(void)
{
	int n_tri;
	int i;
	int a,b,c; //raw input
	int x,y,z; //x>=y>=z

	scanf("%d",&n_tri);
	for(i=0;i<n_tri;i++){
		scanf("%d %d %d",&a,&b,&c);
		x=MAX(MAX(a,b),c);
		z=MIN(MIN(a,b),c);
		y=(a+b+c)-(x+z);
		if(x*x==y*y+z*z){
			printf("YES\n");
		}else{
			printf("NO\n");
		}
	}
	return 0;
}

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

int main(){

int num;


cin >> num;

for (int i=0;i<num;i++)
{
     int a,b,c;
     cin >> a >>b >>c;
     if ( (a*a+b*b == c*c ) ||
          (a*a+c*c ==b*b) ||
          (c*c+b*b == a*a))
     {
          cout<<"YES"<<endl;
      }else 
          cout<<"NO"<<endl;
          
}

return 0;
} 

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


int T;
int N,D;

int X[128][128];

int main(){
  for(int i=0;i<128;i++)
    for(int j=0;j<128;j++)
      X[i][j] = i^j;
  cin >> T;
  for(int i=0;i<T;i++){
    cin >> N >> D;
    if( N == 1 )
      cout << D << endl;
    else {
      for(int j=0;j<N-2;j++)
        D = X[D][127];
      int p=0;
      for(int j=0;j<128;j++)
        p = max( p, X[D][j]+j );
      cout << 127*(N-2) + p << endl;
    }
  }
}


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

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  int gcd = 1;
  for ( int i = 2; i <= m; i++){
    //int a = m / i, b = m % i;
    if ( m / i < n ) break;
    if ( m % i != 0 ) continue;
    if ( i == gcd ) continue;
    int tmp;
    if ( ( m / i ) % n == 0 ) tmp = m / n;
    else tmp = i;
    if ( gcd < tmp ){
      gcd = tmp;
      i = gcd;
    }
  }
  
  cout << gcd << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int P[N], Q[N];
  for (int i = 0; i < N; i++) cin >> P[i];
  for (int i = 0; i < N; i++) cin >> Q[i];
  int a, b;
  int cnt = 0;
  for (int s = 0; s < (1 << (3 * N)); s++) {
    bool check[8];
    fill(check, check + 8, false);
    int ss = s;
    bool isp = true, isq = true;
    for (int i = 0; i < N; i++) {
      int r = ss % 8;
      check[r] = true;
      isp &= (r + 1 == P[N - 1 - i]);
      isq &= (r + 1 == Q[N - 1 - i]);
      ss >>= 3;
    }
    bool isok = true;
    for (int i = 0; i < N; i++) {
      isok &= check[i];
    }
    if (!isok) continue;
    cnt++;
    if (isp) a = cnt;
    if (isq) b = cnt;
  }
  cout << abs(a - b) << endl;
  return 0;
}


Measured memory_bytes: 3520
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split(" ");

const A = parseInt(input[0], 10);
const B = parseInt(input[1], 10);
const C = parseInt(input[2], 10);

console.log(C <= A + B + 1 ? B + C : A + (B * 2) + 1);


Measured memory_bytes: 7372
N=int(input())
S=list(input())

dp_f=[0 for _ in range(N)]
dp_b=[0 for _ in range(N)]
for n in range(1,N):
    if S[n-1]=="W":
        tmp=1
    else:
        tmp=0
    dp_f[n]=dp_f[n-1]+tmp

for n in reversed(range(N-1)):
    if S[n+1]=="E":
        tmp=1
    else:
        tmp=0
    dp_b[n]=dp_b[n+1]+tmp

MIN=N
for n in range(N):
    if n==N-1:
        MIN=min(MIN,dp_f[N-1])
    elif n==0:
        MIN=min(MIN,dp_b[0])
    else:
        MIN=min(MIN,dp_f[n]+dp_b[n])
print(MIN)

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

int main()
{
	int n,m,l;
	int i,j;
	while(scanf("%d %d",&n,&m),(n&&m))
	{
		int data[3][n+1];
		int len[3];
		int lentmp[3];
		int tmp[3][n+1];
		int min = m;
		int direction;
		for(i = 0;i < 3;i++)
		{
			scanf("%d",&len[i]);
			lentmp[i] = len[i];
			data[i][0] = 0;
			tmp[i][0] = 0;
			for(j = 1;j <= len[i];j++)
			{
				scanf("%d",&data[i][j]);
				tmp[i][j] = data[i][j];
			}
		}
		direction = 0;
		for(i = 0;i < m;i++)
		{
			if(len[1] == 0 && (len[0] == 0 || len[2] == 0))
			{
				min = i;
				break;
			}
			if(data[direction][len[direction]] > data[direction+1][len[direction+1]])
			{
				data[direction+1][len[direction+1]+1] = data[direction][len[direction]];
				len[direction+1]++;
				len[direction]--;
			}
			else
			{
				data[direction][len[direction]+1] = data[direction+1][len[direction+1]];
				len[direction]++;
				len[direction+1]--;
			}
			if(len[1] == 0 && (len[0] == 0 || len[2] == 0))
			{
				min = i+1;
				break;
			}
			direction ^= 1;
		}
		direction = 1;
		for(i = 0;i < m;i++)
		{
			if(lentmp[1] == 0 && (lentmp[0] == 0 || lentmp[2] == 0))
			{
				if(min > i)
				{
					min = i;
				}
				break;
			}
			if(tmp[direction][lentmp[direction]] > tmp[direction+1][lentmp[direction+1]])
			{
				tmp[direction+1][lentmp[direction+1]+1] = tmp[direction][lentmp[direction]];
				lentmp[direction+1]++;
				lentmp[direction]--;
			}
			else
			{
				tmp[direction][lentmp[direction]+1] = tmp[direction+1][lentmp[direction+1]];
				lentmp[direction]++;
				lentmp[direction+1]--;
			}
			if(lentmp[1] == 0 && (lentmp[0] == 0 || lentmp[2] == 0))
			{
				if(min > (i+1))
				{
					min = i+1;
				}
				break;
			}
			direction ^= 1;
		}
		if(m == min)
		{
			printf("-1\n");
		}
		else
		{
			printf("%d\n",min);
		}
	}
	return 0;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_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); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b; cin >> n >> a >> b;
	a--, b--;

	int ans = INF;

	if ((b - a) % 2 == 0)
		chmin(ans, (b - a) / 2);
	else {
		int t = a + 1 + (b - 1 - a) / 2;
		int t2 = n - 1 - b + 1 + (b - 1 - a) / 2;
		chmin(ans, min(t, t2));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> prime;
vector<int> fprime;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)

int main(){
  int n=2;
  while(fprime.size()<=56){
  	bool f = true;
    rep(i,prime.size()) if(n % prime[i] ==0){f=false; break;}
    if(f) prime.push_back(n);
    if(f&&n%5==1) fprime.push_back(n);
    n++;
  }
  int x;
  cin >> x;
  rep(i,x) cout << fprime[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Ps {
  string name;
  int time;
};
vector<Ps> qu(1000000);
int head=0, tail = 0;

void enqu(Ps p) {
  qu.at(tail) = p;
  tail++;
}

Ps dequ() {
  Ps out =  qu.at(head);
  head++;
  return out;
}

bool isEmpty() {
  return head == tail;
}

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

  for (int i=0; i<n; i++) {
    Ps ps; cin >> ps.name >> ps.time;
    enqu(ps);
  }
  int count = 0;
  while (!isEmpty()) {
    Ps ps = dequ();
    if (ps.time > q) {
      ps.time = ps.time-q;
      enqu(ps);
      count += q;
    } else {
      count += ps.time;
      cout << ps.name << " " << count << endl;
    }
  }
}



Measured memory_bytes: 20812
import math,sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda:int(input())
li = lambda:list(map(int,input().split()))

def solve():
    k=I()
    a=input().strip()
    if(len(a)<=k):
        print(a)
    else:
        print(a[:k]+"...")
for _ in range(1):
    solve()

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

int main () {
  int N;
  cin >> N;
  vector<int> data(N);
  
  for (int i = 0; i < N; i++) {
    cin >> data[i];
  }
  vector<int> data2 = data;
  sort(data.begin(), data.end());
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (data[i] != data2[i]) {
      count ++;
    }
  }
  if (count == 0 || count == 2) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long                                    // long long省略
#define pb push_back                                    // push_back省略
#define mp make_pair                                    // make_pair省略
#define fi first                                        // first省略
#define se second                                       // second省略
#define itn int                                         // int誤字保険
#define count cout                                      // cout誤字保険
#define vecotr vector                                   // vector誤字保険
#define ednl endl                                       // endl誤字保険
#define opt() cin.tie(0); ios::sync_with_stdio(false)   // 入出力速度改善

#define rep(i,l,r) for(ll i=(l);i<(r);i++)               // 範囲[l, r)で刻み1のfor文(順方向)
#define repp(i,l,r,k) for(ll i=(l);i<(r);i+=(k))         // 範囲[l, r)で刻みkのfor文(順方向)
#define rrep(i,l,r) for(ll i=(r-1);i>=(l);i--)           // 範囲[l, r)で刻み1のfor文(逆方向)
#define rrepp(i,l,r,k) for(ll i=(r-1);i>=(l);i-=(k))     // 範囲[l, r)で刻みkのfor文(逆方向)
#define all(x) (x).begin(), (x).end()                   // vectorのポインタ位置指定用
#define max(p,q)((p)>(q)?(p):(q))                       // max拡張
#define min(p,q)((p)<(q)?(p):(q))                       // min拡張
#define bit(n,m)(((n)>>(m))&1)                          // 変数nのm番目のbitを取り出す

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

int dy[]={0, 1, 0, -1};                                 // 4方向近傍
int dx[]={1, 0, -1, 0};                                 // 4方向近傍


int main(){
	ll n,m;cin>>n>>m;
    vector<ll> v(m,0);
	rep(i,0,n){
        ll k;
		cin>>k;
		rep(j,0,k){
			ll a;cin>>a;a--;v[a]++;
		}
	}
    ll ans=0;
    rep(i,0,m)if(v[i]==n)ans++;
    cout << ans << ednl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5))
  {
    cout<<"YES";
  }
  else
  {
    cout<<"NO";
  }
  return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 1000005
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,a1,a2;
LL pre[2][M],pw[2][M], MOD[2]={1000000007, 1000000009};
char in[M];
pair<LL,LL> get_hash(int l,int r)
{
	LL re[2] = { pre[0][r], pre[1][r] };
	if(l>1)
	{
		REP(i,0,1)
		{
			re[i] -= pre[i][l-1] * pw[i][r-l+1];
			re[i] %= MOD[i];
			re[i] = (re[i]+MOD[i]) % MOD[i];
		}
	}
	return MP(re[0], re[1]);
}
int main()
{
	scanf("%s", in+1);
	n = strlen(in+1);

	//
	
	REP(j,0,1)
	{
		pre[j][1] = in[1];
		REP(i,2,n) pre[j][i] = (pre[j][i-1]*131 + in[i]) % MOD[j];

		pw[j][0] = 1;
		REP(i,1,n) pw[j][i] = (pw[j][i-1]*131) % MOD[j];
	}

	a1 = a2 = 0;
	//
	REP(i,1,n/3)
	{
		int j = n-3*i;
		if(j%2) continue;
		j = j/2;
		if(i*3 + j*2 != n) continue;
		if(j==0) continue;

		pair<LL,LL> h1,h2,h3,h4,h5;
		h1 = get_hash(1,i);
		h2 = get_hash(i+1,i+j);
		h3 = get_hash(i+j+1, i+i+j);
		h4 = get_hash(i+i+j+1, 2*(i+j));
		h5 = get_hash(2*(i+j)+1, n);

		if(h1==h3 && h3==h5 && h2==h4)
		{
			if(a1==0)
			{
				a1=i;
				a2=j;
			}
			else if((a1+a2) > i+j)
			{
				a1 = i;
				a2 = j;
			}
		}
	}

	if(a1==0) puts("mitomerarenaiWA");
	else
	{
		printf("Love ");
		REP(i,1,a1+a2) putchar(in[i]);
		puts("!");
	}

	return 0;
}

Measured memory_bytes: 33348
N = int(input())
arr = list(map(int,input().split()))
N+=1
arr.append(0)
now = 0
min = 100
count = 0

while True:
  min = 100
  if arr[now] == 0:
    now += 1
    if now == N:
      break
  else:
    for i in range(now,N):
      if min > arr[i]:
        if arr[i] == 0:
          last = i
          for j in range(now,i):
            arr[j] = arr[j] - min
          count+=min
          break
        else:
          min = arr[i]
print(count)
          

Measured memory_bytes: 3064
import java.util.*;

public class Main {

	public static void main(String[] args) {
      Scanner sn = new Scanner(System.in);
    	int e = sn.nextInt();
      int t = sn.nextInt();	
      int v = sn.nextInt();
      double tt = (double)e * 1.0 / v;
      	
      	System.out.println( (tt <= (double)t) ? "Yes":"No");
    }
}

Measured memory_bytes: 35624
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
//Shift+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

int N;
int A[100];
bool ok = true;
string ans = "APPROVED";

void _main() {
	cin >> N;
	rep(i, 0, N) {
		cin >> A[i];
		if (A[i] % 2 == 0) {
			if (A[i] % 3 != 0 && A[i] % 5 != 0) {
				ok = false;
			}
		}
	}
	if (!ok) {
		ans = "DENIED";
	}

	cout << ans << endl;
}

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

S = []
for i in range(N):
    S.append(str(input()))

S.sort()

before = S[0]
num = 0
tmp = 0
R = []
for i in range(1, N):
    if S[i] == before:
        tmp += 1
    else:
        if tmp == num:
            R.append(before)
        elif tmp > num:
            R.clear()
            R.append(before)
            num = tmp
        before = S[i]
        tmp = 0

if tmp == num:
    R.append(S[N-1])
elif tmp > num:
    R.clear()
    R.append(S[N-1])
    num = tmp

for i in range(len(R)):
    print(R[i])

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

int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a.at(i);
  }
  int b=0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=0;i<N;i++){
    if(i%2==0){
      b += a.at(i) ;
    }
    else{
      b -= a.at(i);
    }
  }
  cout<< b <<endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N,M;
    cin >> N >> M;
    int high[N];
    int ma[N];
    for(int i = 1; i<=N; i++) {
        cin >> high[i];
        ma[i] = 0;
    }

    for(int i = 0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        ma[a] = max(ma[a], high[b]);
        ma[b] = max(ma[b], high[a]);
    }
    int res = 0;
    for(int i = 1; i<=N; i++) {
        if(high[i] > ma[i]) res++;
    }
  
    cout << res << endl;
    return 0; 
}

Measured memory_bytes: 4424
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

template <class T>
using MaxHeap = std::priority_queue<T>;

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    lint ans = 0;
    std::vector<std::vector<std::vector<int>>> xss(2, std::vector<std::vector<int>>(n));
    std::vector<int> sz(2, 0);

    for (int i = 0; i < n; ++i) {
        int k, l, r;
        std::cin >> k >> l >> r;

        if (l == r) {
            ans += l;
        } else if (l > r) {
            ans += r;
            xss[0][--k].push_back(l - r);
            ++sz[0];
        } else {
            ans += l;
            if (n - k - 1 < 0) continue;
            xss[1][n - k - 1].push_back(r - l);
            ++sz[1];
        }
    }

    for (int t = 0; t < 2; ++t) {
        MaxHeap<int> heap;
        int i = n - 1;

        // std::cerr << sz[t] << "\n";
        while (i >= sz[t]) {
            for (auto x : xss[t][i]) heap.push(x);
            --i;
        }

        while (i >= 0) {
            for (auto x : xss[t][i]) heap.push(x);
            if (!heap.empty()) {
                // std::cerr << (t == 0 ? i + 1 : n - i) << " = " << heap.top() << "\n";
                ans += heap.top();
                heap.pop();
            } else {
                // std::cerr << (t == 0 ? i + 1 : n - i) << " = " << -1 << "\n";
            }
            --i;
        }
    }

    std::cout << ans << "\n";
    // std::cerr << "==========\n";
}

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

    int q;
    std::cin >> q;
    while (q--) solve();

    return 0;
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

bool cp(int n)
{
    if(n<2)
        return false;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","w",stdout);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;

    string s;
    cin>>s;

    for(auto ch:s)
    {
        ch=((ch-65)+n)%26+65;
        cout<<ch;
    }


    return 0;
}


Measured memory_bytes: 3672
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string s, t;
	cin >> s >> t;
	if (s == t) {
		cout << "EQUAL" << endl;
	}
	else if (s.length() > t.length()) {
		cout << "GREATER" << endl;
	}
	else if (t.length() > s.length()) {
		cout << "LESS" << endl;
	}
	else {
		for (int i = 0; i < s.length(); i++) {
			if (s[i] > t[i]) {
				cout << "GREATER" << endl;
				break;
			}
			else if (s[i] < t[i]) {
				cout << "LESS" << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
//in the name of allah
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int a[N] , il[N] , dl[N] , dp[N];

int main(){               
        int n;
        scanf("%d" , &n);
        for(int i=0 ; i<n ; i++){
                scanf("%d" , &a[i]);     
                il[i] = dl[i] = 1;
                if(i){
                        if(a[i] >= a[i-1])
                                dl[i] += dl[i-1];
                        if(a[i] <= a[i-1])
                                il[i] += il[i-1];
                }
                dp[i] = 1e9;
                int id = i-il[i];
                if(id >= 0)
                        dp[i] = dp[id]+1;
                else
                        dp[i] = 1;
                id = i - dl[i];
                if(id >= 0)
                        dp[i] = min(dp[i] , dp[id]+1);
                else
                        dp[i] = 1;
        }
        printf("%d\n" , dp[n-1]);
        return 0;
}

Measured memory_bytes: 1792
/*
AizuOnline A0196
Title Baseball Championship
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section
int n;

struct BTEAM
{
  char nam[4];
  int  order;  //input order
  int  win;
  int  draw;
  int  lose;
} team_info[10];
//
int team_compare (struct BTEAM * a,struct BTEAM * b)
{
  if(a->win < b->win)return(1);
  if(a->win > b->win)return(-1);
  if(a->lose > b->lose)return(1);
  if(a->lose < b->lose)return(-1);
  if(a->order > b->order)return(1);
  if(a->order < b->order)return(-1);
  return(0);
}
main()
{
  int i,j,ss;

  while(1)
    {
      EOF!=scanf("%d",&n);
      if(n==0)break;
      for(i=0;i<n;i++)
	{
	  scanf("%s",team_info[i].nam);
	  team_info[i].win = team_info[i].draw = team_info[i].lose=0;
	  team_info[i].order=i;
	  for(j=0;j<n-1;j++)
	    {
	      scanf("%d ",&ss);
	      if(ss==0)
		team_info[i].win++;
	      else if(ss==1)
		team_info[i].lose++;
	      else if(ss==2)
		team_info[i].draw++;
	    }
	}
      qsort(team_info,n,sizeof(struct BTEAM ),team_compare);
      for(i=0;i<n;i++)
          puts(team_info[i].nam);
    }
      return(0);
}

Measured memory_bytes: 592
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	dances := strings.Split(s, "")
	easy := true
	for i, dance := range dances {
		if i%2 != 0 {
			if dance == "R" {
				easy = false
				break
			}
		} else {
			if dance == "L" {
				easy = false
				break
			}
		}
	}
	if easy {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<map>
#include<vector>
using namespace std;

int main(){
	long n,q;
	map<long , bool > s;
	
	cin >> n;

	for(long i = 0 ; i < n ; i++ ){
		long inp;
		cin >> inp;
		s[inp] = 1;
	}
	
	cin >> q;
	long ans = 0;
	for(long i = 0 ; i < q ; i++ ){
		long inp;
		cin >> inp;
		ans += s[inp];
	}

	cout << ans << endl;
		
}

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

int main(){
    string s;
    cin >> s;
    s.push_back('a'-1);
    while(!s.empty()){
        if(s.back() == 'z'){
            s.pop_back();
            continue;
        }
        s.back()++;
        vector<bool> same(26, false);
        bool flag = true;
        for(int i=0; i<s.length(); i++){
            if(same.at(s[i]-'a')){
                flag = false;
                break;
            }else{
                same.at(s[i]-'a') = true;
            }
        }
        if(flag){
            cout << s << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

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

int main() {

int N, a, b, c;
cin >> N;
b = 0;
c = 0;
for (int i = 0; i < N; i++) {
  cin >> a;
  if (a > b) {
    b = a;
  }
  c += a;
}
  if (c - b > b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" <<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
long long a,b,c,h;
int main()
{
	cin>>a>>b>>c;
  h=(a+b)*(c/2);
    if(c%2!=0)h+=(a+b)/2;
    cout<<h;
	
	return 0;
}

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

int main() {
	
	int N, A;
	int P[50];
	int Cnt = 0;

	scanf("%d", &N);
	
	for (int i = 0; i < N; i++) {
		scanf("%d", &P[i]);
	}

	for (int i = 0; i < N; i++) {
		for (int j = N - 1; j > i; j--) {
			if (P[i] > P[j]) {
				A = P[i];
				P[i] = P[j];
				P[j] = A;
				Cnt += 1;
				i = 0;
				if (Cnt > 1) {
					break;
				}
			}
		}
		if (Cnt > 1) {
			break;
		}
	}

	if (Cnt > 1) {
		printf("NO");
	}
	else {
		printf("YES");
	}

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  std::string s;
  Solver() {
    S002 r;
    r >= s;
  }
  void solve() {
    long xs[32] = {};
    for(char c : s) xs[c-'a'] += 1;
    long t = 0;
    for(int i = 0; i < 26; ++i) {
      t += xs[i] % 2;
    }
    puts(t == 0 ? "Yes" : "No");    
  }
};
 
int main() {
  for(;;) std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//define
#define inp(X) cin>>X;
#define inp_long(X) long long X; cin>>X;
#define inp_arr(A,N) long long A[N]; for(long long int i=0;i<N;i++) {cin>>A[i];}
#define sz(A) A.size()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define vect(A) vector<long long> A;
#define inp_vect(A,N); vect(A);for(long long i=0;i<N;i++){long long q; cin>>q; A.push_back(q);}
#define forin(i,a,b) for(long long i=a;i<=b;i++)
#define forde(i,a,b) for(long long i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 

int main()
{
	fio;
	ll n;
	cin>>n;
	vect(a);
	forin(i,0,n-1)
	{
		ll q;
		cin>>q;
		a.pb(q);
	}
	ll ans=0;
	sort(a.begin(),a.end());
	forin(i,0,n-3)
	{
		ll k=i+2;
		forin(j,i+1,n-1)
		{
			while(k<(n) && a[i]+a[j]>a[k])
			{
				k++;
			}
			if(k>j)
			{
				ans+=k-j-1;
			}
		}
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MOD 1000000007
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N, A, B, C;
int Comb[10050][5050];

int main()
{
	for (int i = 0; i <= 5000; ++i) Comb[0][i] = 0;
	Comb[0][0] = 1;
	for (int i = 1; i <= 10010; ++i) {
		Comb[i][0] = 1;
		for (int j = 1; j <= 5010; ++j) Comb[i][j] = (Comb[i - 1][j - 1] + Comb[i - 1][j]) % MOD;
	}
	scanf("%d%d%d%d", &N, &A, &B, &C);
	if (B % 2 == 1) {
		puts("0");
		return 0;
	}
	i64 ret = 0;
	for (int p = 0; p <= C; ++p) {
		if (B == 0 && p > 0) continue;
		for (int q = 0; 3 * q <= C - p; q++) {
			int r = C - p - 3 * q;
			int iso = A - r;
			if (iso < 0) continue;
			i64 tmp = (i64)Comb[B / 2 + q + r + iso][iso] * Comb[B / 2 + q + r][B / 2] % MOD * Comb[q + r][q] % MOD;
			if (B > 0) {
				tmp = tmp * Comb[B / 2 - 1 + p][p];
			}
			ADD(ret, tmp);
		}
	}
	printf("%lld\n", ret);
	return 0;
}


Measured memory_bytes: 197760
#include <stdio.h>
#include <stdlib.h>

#define NIL NULL

struct node {
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node *Node;

Node root;

void insert(int);
void inorder(Node);
void preorder(Node);


int main() {
  int n, i, x;
  char com[20];
  
  scanf( "%d" , &n );

  for ( i=0; i<n; i++ ) {
    scanf( "%s" , com );
    if ( com[0] == 'i' ) {
      scanf( "%d" , &x );
      insert(x);
    }
    else if ( com[0] == 'p' ) {
      inorder(root);
      printf( "\n" );
      preorder(root);
      printf( "\n" );
    }
  }

  return 0;
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while ( x != NIL ) {
    y = x;
    if ( z->key < x->key ) x = x->left;
    else x = x->right;
    z->parent = y;
  }
  if ( y == NIL ) root = z; // Tree is empty
  else if ( z->key < y->key ) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if ( u != NIL ) {
    inorder(u->left);
    printf( " %d" , u->key );
    inorder(u->right);
  }
}

void preorder(Node u){
  if ( u != NIL ) {
    printf( " %d" , u->key );
    preorder(u->left);
    preorder(u->right);
  }
}



Measured memory_bytes: 25128
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}
ll modinv(ll a){ ll b=mod,u=1,v=0,t; while(b){ t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); } return (u+mod)%mod; }
ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}
ll modncr(ll n,ll r){ ll i,plus=1; rep(i,r){ plus=(plus*(n-i))%mod; plus=moddevide(plus,i+1); } return plus; }
ll euclidean_gcd(ll a, ll b) { if(a<b) return euclidean_gcd(b, a); ll r; while ((r=a%b)){a=b;b=r;} return b; }
ll countdigits(ll n){ ll ans=0; while(n){n/=10;ans++;} return ans; }
ll sumdigits(ll n){ ll ans=0; while(n){ans+=n%10;n/=10;} return ans; }
void printmap(vector<ll>& a,ll H,ll W){ ll i,j; For(i,0,H+2){ For(j,0,W+2){cout<<a[i*(W+2)+j];} cout<<endl; } } void inputmap(vector<ll>& a,ll H,ll W){ ll i,j; string ss; For(i,1,H+1){ cin>>ss; For(j,1,W+1){ if(ss[j-1]=='#'){ a[i*(W+2)+j]=1; }else{ a[i*(W+2)+j]=0; } } } }
int main(){
  ll i,j,N,K,ans=1,cnt;
  string ss;
  cin>>N;
  vec a(1000,1),plis,v(1001,0);
  a[0]=a[1]=0;
  For(i,2,1000){
    if(a[i]){
      plis.push_back(i);
      for(j=2;i*j<1000;j++){
        a[i*j]=0;
      }
    }
  }
  rep(i,(ll)plis.size()){
    K=N;cnt=0;
    while(K){
      K/=plis[i];
      cnt+=K;
    }
    ans=(ans*(cnt+1))%mod;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const ll INF = +10010010000;

typedef pair<ll,ll> P;
const ll MO = 1000000007;

int main(){
    int n;
    cin >> n;
    vector<ll> c(n),s(n),f(n),ans(n);
    rep(i,n-1){
        cin >> c[i] >>s[i]>> f[i];
    }
    rep(i,n){
        int t = 0;
        for(int j = i; j<n-1;++j){
            if(t<s[j])t=s[j];
            else if (t%f[j]==0);
            else t +=f[j] - t%f[j];
            t+=c[j];
        }
        printf("%d\n",t);
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
            int[] input = Input.ScanIntArray();
          int N = input[0];
          int L = input[1];
          int[] Apples = Enumerable.Range(L,N).ToArray();
          int Sum = Apples.Sum();
          if(L>0)
            Sum -= Apples.Select(x => Math.Abs(x)).Min();
          else
            Sum += Apples.Select(x => Math.Abs(x)).Min();
          Console.WriteLine($"{Sum}");
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }
}


Measured memory_bytes: 11348
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int a=Integer.parseInt(br.readLine());
		for(int i=3;i<=a;i++){int b=0;
		if(i%3==0)System.out.print(" "+i);
		else if(i/1000==3)System.out.print(" "+i);
		else if((b=i%1000)/100==3)System.out.print(" "+i);
		else if((b=b%100)/10==3)System.out.print(" "+i);
		else if(b%10==3)System.out.print(" "+i);
					
		}System.out.println();
}}

Measured memory_bytes: 21888
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  int m=0;
  vector<int> a(n+1);
  rep1(i,n)cin>>a[i];
  vector<int> res(n+1,0);
  vector<int> ans;
  for(int i=n;i>0;--i){
    int sum=0;
    int buf=i;
    while(buf<=n){
      if(res[buf]==1){
        sum++;
      }
      buf+=i;
    }
    if(sum%2==a[i]){
      res[i]=0;
    }
    else{
      res[i]=1;
      m++;
      ans.push_back(i);
    }
  }
  cout<<m<<"\n";
  sort(ans.begin(),ans.end());
  rep(i,m){
    cout<<ans[i]<<"\n";
  }
  return 0;
}


Measured memory_bytes: 4980
#include <bits/stdc++.h>
using namespace std;
#define LL long int

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

    int count = 0;

    string ans[2] = {"NO","YES"};

    for(int i = 1; i <= n; ++i){
        int p;
        cin >> p;
        if(i != p) count++;
    }

    cout << ans[count == 2 || count == 0] << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())
AB=[list(map(int,input().split())) for i in range(N-1)]
C=list(map(int,input().split()))
C.sort(reverse=True)
data=[[] for i in range(N+1)]
num=[-1 for i in range(N+1)]
num[1]=C[0]
for a,b in AB:
    data[a].append(b)
    data[b].append(a)
sumc=sum(C[1:])

stack=[1]
visited=set()
visited.add(1)
idx=1
while stack:
    a=stack.pop()
    for p in data[a]:
        if not p in visited:
            visited.add(p)
            num[p]=C[idx]
            idx+=1
            stack.append(p)
print(sumc)
print(" ".join([str(num[i]) for i in range(1,N+1)]))


Measured memory_bytes: 50904
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,x; cin >>n >>x;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  int ans=0, i=0;
  while(x>0 && i<n){
    x-=a[i];
    ans++;
    i++;
    //cout <<i<<" "<<x<<" "<<ans<<endl;
  }
  if(x!=0)ans--;
  cout <<ans<<endl;
}

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

using namespace std;

inline void read() {}
template <class S>
inline void read(S &arg) {
  cin >> arg;
}
template <class S>
inline void readA(S Lptr, S Rptr) {
  while (Lptr != Rptr) {
    read(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void read(S &arg, T &... rest) {
  read(arg);
  read(rest...);
}

inline void write() {}
template <class S>
inline void write(S arg) {
  cout << arg;
}
template <class S>
inline void writeA(S Lptr, S Rptr) {
  if (Lptr != Rptr) {
    write(*Lptr);
    Lptr++;
  }
  while (Lptr != Rptr) {
    write(' ');
    write(*Lptr);
    Lptr++;
  }
}
template <class S, class... T>
inline void write(S arg, T... rest) {
  write(arg);
  write(' ');
  write(rest...);
}
#define int long long
#define rep(i, j, k) for (int i = j; i < (int)k; i++)
#define pb push_back
#define mt make_tuple
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

template <class T, class S>
inline bool smin(T &a, S b) {
  return (T)b < a ? a = b, 1 : 0;
}
template <class T, class S>
inline bool smax(T &a, S b) {
  return a < (T)b ? a = b, 1 : 0;
}

constexpr int MOD = 924844033;
constexpr int N = 1e6 + 10;

template <typename T>
inline T mod(T &v) {
  return v = (v % MOD + MOD) % MOD;
}
template <typename S, typename T>
inline S add(S &l, T r) {
  return mod(l += r);
}

ll po(ll v, ll u) {
  return u ? po(v * v % MOD, u >> 1) * (u & 1 ? v : 1) % MOD : 1;
}

int n, a[N];
int z[N], L[N], R[N];

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  read(n);
  rep(i, 1, n + 1) {
    cin >> a[i];
    z[i] = z[i - 1] + ((~a[i]) & 1);
  }

  int sum = 0;
  rep(i, 1, n + 1) {
    sum += a[i];
    if (!a[i])
      L[i] = min(L[i - 1] + 2, sum);
    else
      L[i] = min((a[i] & 1) + L[i - 1], sum);
  }

  sum = 0;
  for (int i = n; i; i--) {
    sum += a[i];
    if (!a[i])
      R[i] = min(R[i + 1] + 2, sum);
    else
      R[i] = min((a[i] & 1) + R[i + 1], sum);
  }

  int best = z[n];

  int local = 0;
  rep(i, 1, n + 1) {
    smin(local, L[i] - z[i]);
    smin(best, R[i + 1] + z[i] + local);
  }

  write(best);

  return 0;
}

// z[r] - z[l - 1] + R[r + 1] + L[l - 1];


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

#define A33 ios::sync_with_stdio(0);cin.tie(0)
#define endl '\n'
#define pi 3.14159265358979323846
#define ff first
#define ss second

typedef long long ll;


int dfs(int u, vector<bool> &vis, vector<vector<int>> &adj){
	int cnt = 1;
	vis[u] = true;
	for(int v : adj[u]){
		if(!vis[v])
			cnt += dfs(v, vis, adj);
	}
	return cnt;
}


int main(){
	A33;
	int n, m;
	cin >> n >> m;
	vector<vector<int>> adj(n + 1);
	vector<bool> vis(n + 1);
	for(int i = 0, s, d; i < m; ++i){
		cin >> s >> d;
		adj[s].push_back(d);
		adj[d].push_back(s);
	}	

	int answer = 0;

	for(int i = 1; i <= n; ++i)
		if(!vis[i])
			answer = max(answer, dfs(i, vis, adj));
	
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 26676
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <cmath>
#include <cassert>
#include <iostream>
#include <string>
#include <map>
#include <set>
#define mkp make_pair
#define pb push_back
#define IOS ios_base::sync_with_stdio(0),cin.tie(0)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=2e5+5;
const int mod=1e9+7;
const int INF=2147483647;
char G[205][205];
vector<int> E[205];
int id[205];
bool check(int u,int x){
	id[u]=x;
	for(int v:E[u]){
		if(id[v]==0){
			if(!check(v,3-x)) return 0;
		}
		if(id[v]==x) return 0;
	}
	return 1;
}

int main(){
	IOS;
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>G[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(G[i][j]=='1') E[i].push_back(j);
		}
	}
	if(check(0,1)){
		int ma=0;
		for(int i=0;i<n;i++){
			int d[205]={0};
			d[i]=1;
			queue<int> Q;
			Q.push(i);
			while(!Q.empty()){
				int x=Q.front(); Q.pop();
				for(int y:E[x]) if(!d[y])
					d[y]=d[x]+1,Q.push(y);
			}
			for(int j=0;j<n;j++) ma=max(ma,d[j]);
		}
		cout<<ma<<'\n';
	}
	else cout<<"-1\n";
	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>

using namespace std;

int
main() {
  int a, b;
  cin>>a>>b;

  if ((b-1)%(a-1) == 0)
    cout<<(b-1)/(a-1)<<endl;
  else
    cout<<(b-1)/(a-1)+1<<endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring> 
#include<queue>
#include<stack> 
#include<string.h>
#include<set>
#define ll long long
using namespace std;
int ct[100]={0};
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		ct[u]++;
		ct[v]++;
	}
	for(int i=1;i<=n;i++)
	printf("%d\n",ct[i]);
	return 0;
}

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

using namespace std;

// (weighted) UnionFind
class UnionFind {
    public:
        UnionFind(int n) : mPar(n), mRnk(n,0), mWeight(n,0) {
            for(int i = 0; i < n; ++i) mPar[i] = i;
        }

        int find(int x){
            if(mPar[x]==x) return x;
            mWeight[x] += mWeight[mPar[x]]; // 一つ上の親からの累積和
            return mPar[x] = find(mPar[x]);
        }

        bool same(int x,int y){
            return find(x) == find(y);
        }
        
        int diff(int x, int y){
            x = find(x);
            y = find(y);
            return mWeight[y] - mWeight[x];
        }

        void unite(int x,int y, int w = 0){
            x = find(x);
            y = find(y);
            if(x==y) return;
            w += mWeight[x]; w -= mWeight[y];
            if(mRnk[x] < mRnk[y]) swap(x,y), w = -w;
            mPar[y] = x;
            mWeight[y] = w;
            if(mRnk[x] == mRnk[y]) ++mRnk[x];
        }

    private:
        vector<int> mPar, mRnk, mWeight;
};

int main(){
    int n,q,c,x,y;
    cin >> n >> q;
    UnionFind uf(n);
    for(int i = 0; i < q; ++i){
        cin >> c >> x >> y;
        if(c==0){
            uf.unite(x,y);
        } else {
            cout << uf.same(x,y) << '\n';
        }
    }
    return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}

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

  ll a, b , h; cin >> a >> b >> h;
  cout << (a+b)*h/2 << endl;
  
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int count;

int kiten(int n);

int main(void)
{
	int n;
	
	while (scanf("%d", &n) != EOF){
		count = 0;
		kaiten(n);
	}
	
	return (0);
}

int kaiten(int n)
{
	int i, j, k, l;
	int sum;
	
	for (i = 0; i < 10; i++){
		for (j = 0; j < 10; j++){
			for (k = 0; k < 10; k++){
				for (l = 0; l < 10;l++){
					sum = i + j + k + l;
					if (sum == n){
						count++;
					}
				}
			}
		}
	}
	printf("%d\n", count);
	return (0);
	
}

Measured memory_bytes: 596