akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll a, b;
    cin >> a >> b;
    ll c = gcd(a, b);
    set<ll> list;
    while (c > 0)
    {
        ll prev_c = c;
        for (ll i = 2; i * i <= c; i++)
        {
            if (c % i == 0)
            {
                list.emp(i); 
                c /= i;
                break;
            }
        }
        if (c == prev_c) break;
    }
    if (c > 0) list.emp(c);
    list.emp(1);
    cout << list.size() << '\n';
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int hyo[101][101]={0};
	int x,y;
	int r,c;
	int i,j,k;
	int sumx[101]={0},sumy[101]={0},sumh;
	scanf("%d %d",&y,&x);
	
	for(i=0;i<y;i++){
		for(j=0;j<x;j++){
			scanf("%d",&r);
			hyo[i][j]=r;
			sumx[i]+=r;
			sumy[j]+=r;
		}
		
	}
	for(i=0;i<y;i++){
		for(j=0;j<x;j++){
			printf("%d ",hyo[i][j]);

		}
		printf("%d\n",sumx[i]);
		sumh+=sumx[i];
	}
	i=0;
	for(k=0;k<x;k++){
		printf("%d ",sumy[k]);
		i++;
	}
	printf("%d",sumh);
	
	printf("\n");
	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <iomanip>

using namespace std;

// common
#define X real()
#define Y imag()

using Vector2 = complex<double>;
using Line = pair<Vector2, Vector2>;
using Segment = pair<Vector2, Vector2>;
const double EPS = 1e-10;
const double PI = 3.14159265359;

bool isSame(double a, double b){
    if(abs(a - b) < EPS){
        return true;
    }
    else{
        return false;
    }
}

// struct

struct Circle{
    Vector2 c;
    double r;
    Circle(Vector2 c, double r){
        this->c = c;
        this->r = r;
    }
};

// Vector2
double dot(Vector2 a, Vector2 b){
    return (a.X * b.X + a.Y * b.Y);
}

double cross(Vector2 a, Vector2 b){
    return (a.X * b.Y - a.Y * b.X);
}

Vector2 project(Line l, Vector2 p){
    Vector2 base = l.second - l.first;
    double r = dot(p - l.first, base) / norm(base);
    return l.first + base * r;
}

int main(){

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Line l(Vector2(x1, y1), Vector2(x2, y2));
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        Vector2 p(x, y);
        Vector2 ans = project(l, p);
        cout << fixed << setprecision(9) << ans.X << " " << ans.Y << endl;
    }

    return 0;
}


Measured memory_bytes: 3324
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,n) for(int i=1; i<=(n); i++)

int main() {
    long long n,ans=0,max=0,max2=0;
    cin>>n;
    vector<long long>a(n),b(n);
    rep(i,n)cin>>a[i];
    rep(j,n)b[j]=a[j];
    sort(b.begin(),b.end());
    max=b[n-1];
    max2=b[n-2];
    rep(i,n){
        if(a[i]!=max)cout<<max<<endl;
        else cout<<max2<<endl;
    }
	return 0;
}



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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

mt19937 Rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

template <typename T>
inline void chkmax(T &x, T y) { if (x < y) x = y; }

template <typename T>
inline void chkmin(T &x, T y) { if (x > y) x = y; }

inline int read() {
  #define nc getchar()
  int x = 0;
  char c = nc;
  while (c < 48) c = nc;
  while (c > 47) x = x * 10 + (c ^ 48), c = nc;
  return x;
  #undef nc
}

typedef long long ll;
int n, m, k;

struct node {
  int a, b, c, d;
} DDData[105];

int A[105];
int ans;

void dfs(int now){
  if(now>n){
    int sum=0;
    rep(i,1,k){
      if(A[DDData[i].b]-A[DDData[i].a]==DDData[i].c)sum+=DDData[i].d;
    }
    chkmax(ans,sum);
    return;
  }
  rep(i,A[now-1],m)A[now]=i,dfs(now+1);
}

void solve() {
  cin>>n>>m>>k;
  rep(i,1,k)DDData[i].a=read(),DDData[i].b=read(),DDData[i].c=read(),DDData[i].d=read();
  A[0]=1;
  dfs(1);
  cout<<ans<<endl;
}

int main() {
//  int T = read();
//  while (T--) solve();
  solve();
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

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

bool primes[50000];

void make_prime(){
  primes[0]=primes[1]=true;
  for(int i=2; i*i<=50000; i++)if( !primes[i] ){
      for(int j=i*2; j<50000; j+=i)primes[j]=true;
    }
}

int main(){
  int n;
  make_prime();
  while(scanf("%d",&n),n){
    if( n<4 ){
      puts("0"); continue;
    }
    int cnt = 0;
    for(int i=2; i<=n/2; i++){
      if( !primes[i] && !primes[n-i] ){
	cnt++;
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 920
// Problem : A - Rating Goal
// Contest : AtCoder - AtCoder Beginner Contest 076
// URL : https://atcoder.jp/contests/abc076/tasks/abc076_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int old,new1;cin>>old>>new1;
	cout<<(2*new1)-old;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


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

const int N = 8;
const int FREE  = -1;
const int NOT_FREE = 1;

int row[N],col[N],DIAGONAL_L[2*N-1],DIAGONAL_R[2*N-1];
bool BOARD[N][N]= {false};

void printBoard(){
    for (int i = 0; i < N ; ++i) {
        for (int j = 0; j < N ; ++j) {
            if(BOARD[i][j])
                if(row[i] != j) return;
        }
    }

    for (int i = 0; i < N ; ++i) {
        for (int j = 0; j < N ; ++j) {
            cout << (row[i] == j ? 'Q' : '.');
        }
        cout << endl;
    }
}

void solve(int i){
    if(i == N){
        printBoard();
        return ;
    }

    for (int j = 0; j < N ; ++j) {
        if(col[j] == NOT_FREE or
           DIAGONAL_L[i+j] == NOT_FREE or
           DIAGONAL_R[i-j+N-1] == NOT_FREE)
            continue;

        row[i] = j;
        col[j] = DIAGONAL_L[i+j] = DIAGONAL_R[i-j+N-1] = NOT_FREE;

        solve(i+1);

        row[i] = col[j] = DIAGONAL_L[i+j] = DIAGONAL_R[i-j+N-1] = FREE;
    }
}

int main(){
    for (int i = 0; i < N ; ++i) {
        col[i] = row[i] = FREE;
        DIAGONAL_L[i] = DIAGONAL_R[i] = FREE;
        DIAGONAL_L[2*i] = DIAGONAL_R[2*i] =FREE;
    }

    int k; cin >> k;
    while(k --){
        int r,c; cin >> r >> c;
        BOARD[r][c] = true;
    }

    solve(0);
}

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30
#define UNDER 10000

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int t[UNDER + 10][5], n;

int count() {
	int res = 0;
	rep(i, UNDER)
		rep(j, 5)
			if (t[i][j] == 1)
				res++;
	return res;
}

void deleteblock() {
	for (int y = UNDER - 1; y >= 0; y--) {
		int f = 0;
		rep(i, 5)
			if (t[y][i] == 0) {
				f = 1;
				break;
			}
		if (f)
			continue;
		rep(i, 5)
		{
			for (int c = y; c > 0; c--) {
				t[c][i] = t[c - 1][i];
			}
		}
		t[0][0] = t[0][1] = t[0][2] = t[0][3] = t[0][4] = 0;
		y++;
	}
	return;
}

int main() {
	while (scanf("%d", &n) && n) {
		int d, p, q;
		memset(t, 0, sizeof(t));
		rep(i, 5)
			t[UNDER][i] = 1;

		rep(i, n)
		{
			scanf("%d%d%d", &d, &p, &q);
			q--;
			if (d == 1) {
				REP(y, 1, UNDER+1)
				{
					int f = 0;
					REP(x, q, q+p)
						if (t[y][x] == 1)
							f = 1;
					if (!f)
						continue;
					REP(x, q, q+p)
						t[y - 1][x] = 1;
					break;
				}
			} else {
				rep(y, UNDER+1)
				{
					if (!t[y][q])
						continue;
					for (int c = y - 1; c > y - p - 1; c--)
						t[c][q] = 1;
					break;
				}
			}
			deleteblock();
			/*      REP(i, 990, UNDER+1){
			 rep(j, 5) printf("%d ", t[i][j]); puts("");
			 }*/
		}

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

Measured memory_bytes: 3380
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <set>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
ll n,ans,a[200005];
map<ll,ll> o;
int main(void){
    cin>>n;
    o[0]++;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        a[i]+=a[i-1];
        o[a[i]]++;
    }
    for(int i=0;i<=n;i++){
        o[a[i]]--;
        ans+=o[a[i]];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; 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 < b) {
    cout << 2*b-1 << endl;
  } else if (a == b) {
    cout << a+b << endl;
  } else {
    cout << 2*a - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3632
def count_island(ban):
    def remove(x, y):
        if 0 <= y < 12 and 0 <= x < 12 and ban[y][x] == 1:
            ban[y][x] = 0
            for dx, dy in [(-1,0), (1,0), (0,-1), (0,1)]:
                remove(x + dx, y + dy)

    count = 0
    for y in range(12):
        for x in range(12):
            if ban[y][x] == 1:
                count += 1
                remove(x, y)

    print(count)

ban = []
while True:
    try:
       s = input()
    except EOFError:
        break

    if s:
        ban.append(list(map(int, s)))
    else:
        count_island(ban)
        ban = []

if ban: count_island(ban)

Measured memory_bytes: 6728
fun main(args: Array<String>) {
    val (A, B, K) = readLine()!!.split(" ").map { it.toLong() }
    if (A >= K) {
        println("${A - K} $B")
        return
    }
    val L = K - A
    if (B >= L) {
        println("0 ${B - L}")
        return
    }
    println("0 0")
}

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

vector<int> a;

int main() {
    int n, k;
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ok = *max_element(a.begin(), a.end());
    int no = 0;
    while (abs(ok - no) > 1) {
        int mid = (ok + no) / 2;
        int num = 0;
        for (int i = 0; i < n; i++) {
            num += (a[i] + mid - 1) / mid - 1;
        }
        if (num <= k) {
            ok = mid;
        } else {
            no = mid;
        }
    }
    cout << (int)ceil(ok) << endl;
}

Measured memory_bytes: 3944
#include <iostream>
#include <string>
#include <algorithm>

#define MAX (int)2e5
	
//にぶたんver  未完成

using namespace std;
typedef pair<char,int> P;

int n, q;
string s;
P spels[MAX+1];

int journey(int k) {
	for (int i=0; i<q; i++) {
		if (s[(size_t)k] != spels[i].first) continue;
		k += spels[i].second;
		if (k == n) return 1;
		else if (k == -1) return -1;
	}
	return 0;
}

int main() {
	cin >> n >> q >> s;
	for (int i=0; i<q; i++) {
		char t, d;
		cin >> t >> d;
		spels[i] = P(t, d == 'R' ? 1 : -1);
	}

	int a1 = 0, a2 = 0, b1 = n-1, b2 = n-1, j1, j2;
	while (true) {
		j1 = journey((a1 + b1)/2);
		j2 = journey((a2 + b2 + 1)/2);
		if (b1 - a1 <= 1 && b2 - a2 <= 1) break;
		if (j1 == -1) a1 = (a1 + b1)/2;
		else b1 = (a1 + b1)/2;
		if (j2 == 1) b2 = (a2 + b2 + 1)/2;
		else a2 = (a2 + b2 + 1)/2;
	}
	cout << b2 - a1 + (int)(j1==0) + (int)(j2==0) - 1 << '\n';
	return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
inline void IN(ut &x){cin >> x;}
inline void INA(ut n,ut x[]){REP(i,n) cin >> x[i];}
inline void INE(ut m,VI edges[]){
	ut a,b;
	REP(i,m){
		cin >> a >> b;
		edges[a].PB(b);
		edges[b].PB(a);
	}
}
inline void INEC(ut m,Vpr edges[]){
	ut a,b,c;
	REP(i,m){
		cin >> a >> b >> c;
		edges[a].PB(pr(c,b));
		edges[b].PB(pr(c,a));
	}
}
const int SIZE=5+5*1e5;
const int INF=10+1e9;
const LL p=7+1e9;
ut N,A[SIZE];

int main(){
	IN(N);
	INA(N,A);
	A[0]=1;
	FOR(i,1,N){
		A[i]=min(A[i-1]+2,A[i]);
	}
	LL ans=1;
	LL need=0;
	FOR(i,1,N){
		need=max(0LL,i*2-A[i-1])/2;
		ans*=i+1-need;
		ans%=p;
	}
	cout << ans << endl;
}

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

#define RP(x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP(i, x) for (int i = 0, i##_len = (int)(x); i < i##_len; i++)
#define REP1(i, x) for (int i = 1, i##_len = (int)(x); i <= i##_len; i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9 + 9;
using ll = long long;
using i_i = pair<int, int>;
using l_l = pair<ll, ll>;
using d_d = pair<double, double>;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    ll l = 0, r = 0;
    ll d = 0;
    REP(i, S.size()) {
        if (S[i] == '(') {
            if (d < 0) {
                r += abs(d);
                d = 0;
            } else
                d++;
        }
        if (S[i] == ')') {
            if (d > 0) {
                d--;
            } else {
                l++;
            }
        }
    }
    r += max(d, 0ll);
    RP(l) cout << "(";
    cout << S;
    RP(r) cout << ")";
}

Measured memory_bytes: 256
@a=map[glob<>],1..<>;
@b=map[glob],<>;
for$a(@a){
	$d=1e9;
	$i=@b;
	for$b(reverse@b){
		$t=abs(@$a[0]-@$b[0])+abs(@$a[1]-@$b[1]);
		$t>$d||($d=$t,$x=$i);
		--$i
	}
	print$x,$/
}


Measured memory_bytes: 768
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

shff = list(range(1, N + 1))
idx1 = -1
idx2 = -1
for i, perm in enumerate(permutations(shff)):
    if perm == P:
        idx1 = i
    if perm == Q:
        idx2 = i
print(abs(idx1 - idx2))




Measured memory_bytes: 5932
fun main(args: Array<String>) {
    val n = readLine()!!.toInt() % 10
    val hon = setOf(2, 4, 5, 7, 9)
    val pon = setOf(0, 1, 6, 8)

    when {
        hon.contains(n) -> print("hon")
        pon.contains(n) -> print("pon")
        else -> print("bon")
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef vector<vl> mt;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<string> vs;
typedef vector<vs> table;
typedef vector<vl> v2;
typedef vector<v2> v3;
typedef vector<v3> v4;


const ll e5 = 1 << 20;
const ll mods[] = {998244353, 1000000007, 1000000009};
const ll bases[] = {997, 1009, 1013};
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 50;


ll n;
string s;
ll ans;

bool judge(ll x){
  unordered_map<string,ll> m;
  for(ll i = 0;i+x <= n;i++){
    string sb = s.substr(i,x);
    if(m.find(sb) != m.end()){
      if(i-m[sb] >= x) return true;
    }else{
      m[sb] = i;
    }
  }
  return false;
}

int main(){
  cin >> n;
  cin >> s;
  ll top = n;
  ll bottom = 0;
  while(top-bottom > 1){
    ll middle = (top+bottom)/2;
    if(judge(middle)) bottom = middle;
    else top = middle;
  }
  cout << bottom << endl;
}


Measured memory_bytes: 6668
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

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

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

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

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
ll n;
cin>>n;
ll a[n+1];
rep(i,n){
	cin>>a[i];
}
sort(a+1,a+n+1);
ll sum=0;
ll sum2=0;

deque<ll> dq{};
deque<ll> dq2{};
dq.push_back(a[1]);
dq2.push_back(a[n]);
ll p=2;
ll q=n;

while(1){
	int fin=0;
for(int i=1;i<=4;i++){
if(p==q){fin=1;
}
if(i==1){dq.push_front(a[q]); q--;}
if(i==2){dq.push_back(a[q]); q--;}
if(i==3){dq.push_front(a[p]); p++;}
if(i==4){dq.push_back(a[p]); p++;}
if(fin) break;
}

if(fin) break;
}




for(ll i=0;i<dq.size()-1;i++){
sum+=abs(dq[i]-dq[i+1]);
}




p=1;
q=n-1;


while(1){
	int fin=0;
for(int i=1;i<=4;i++){
if(p==q){fin=1;}

if(i==1){dq2.push_front(a[p]); p++;}
if(i==2){dq2.push_back(a[p]); p++;}
if(i==3){dq2.push_front(a[q]); q--;}
if(i==4){dq2.push_back(a[q]); q--;}
if(fin) break;
}

if(fin) break;
}



for(ll i=0;i<dq2.size()-1;i++){
sum2+=abs(dq2[i]-dq2[i+1]);
}




cout<<max(sum,sum2)<<endl;
}






Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>

int main(){
	int a, p;
	std::cin>>a>>p;

	std::cout<< (int)(a*3+p)/2 << std::endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        sc.close();
        int tk = (c + b - 1) / b;
        int ao = (d + a - 1) / d;
        if(tk <= ao){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35584
(N, M), As = readlines.map{|l| l.split.map(&:to_i)}

h0 = [*1 .. 9].zip([2, 5, 5, 4, 5, 6, 3, 7, 6]).to_h
fs = As.sort.reverse
ns = fs.map{|f| h0[f]}
h = fs.zip(ns).to_h
dp = Array.new(N + 1, -Float::INFINITY)
dp[0] = 0
(1 .. N).each do |i|
  ns.each{|n| dp[i] = [dp[i], dp[i - n] + 1].max if i - n >= 0}
end
n = N
res = dp[N].times.inject([]) do |r, _|
  f, m = h.find{|f, m| dp[n - m] == dp[n] - 1 && n >= m}
  n -= m
  r << f
end
puts res.join

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

int main(){
    int n, m;
    while(cin >> n >> m, n+m){
        vector<vector<int>> dp(256, vector<int>(n+1, 1<<30));
        dp[128][0] = 0;
        vector<int> c(m);
        for(int i = 0; i < m; i++)  cin >> c[i];
        for(int i = 0; i < n; i++){
            int x;  cin >> x;
            for(int j = 0; j < 256; j++){
                for(int k = 0; k < m; k++){
                    int next = j + c[k];
                    if(next < 0)    next = 0;
                    if(next > 255)  next = 255;
                    dp[next][i+1] = min(dp[next][i+1], dp[j][i]+(next-x)*(next-x));
                }
            }
        }
        int ans = 1<<30;
        for(int j = 0; j < 256; j++)    ans = min(ans, dp[j][n]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 22876
import sys

'''
def countingSort(A, B, k):
    C = [0] * (k + 1)

    for j in range(len(A)):
        C[A[j]] += 1

    for i in range(1, k + 1):
        C[i] += C[i - 1]

    B = [0] * (max(C) + 1)
    for j in range(len(A) - 1, -1, -1):
        B[C[A[j]]] = A[j]
        C[A[j]] -= 1

    del B[0]
    print " ".join([str(b) for b in B])
    '''

def countingSort(A, B, k):
    C = [0] * (k + 1)
    for i in range(len(A)):
        C[A[i]] += 1
    for i in range(len(C)):
        for j in range(C[i]):
            B.append(i)
    print " ".join([str(b) for b in B])

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    A = map(int, lines[1].split())
    B = []
    countingSort(A, B, 10000)

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

int main()
{
    int N;
    cin >> N;
    vector<int> v1(N);
    vector<int> v2(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> v1.at(i) >> v2.at(i);
    }
    int cnt = 0;
    for (int i = 0; i < N; ++i)
    {
        cnt = v1.at(i) == v2.at(i) ? cnt + 1 : 0;
        if(cnt == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define MAXIM 1000003

ll mod = 1e9 + 7;
vll dp;



void solve(){
    ll n;
    cin >> n;
    dp.resize(n + 1);
    dp[0] = 1;
    dp[1] = 0;
    dp[2] = 0;
    rep(i,3,n + 1){
        rep(j,0,i - 2){
            (dp[i] += dp[j]) %= mod;
        }
    }
    cout << dp[n];
}
	

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}	

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <valarray>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)(x).size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N;
int r[1010],w[1010];
int dp[1010][1010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	while(cin>>N && N){
		rep(i,N)cin>>r[i]>>w[i];
		int sumr=accumulate(r,r+N,0);
		int sumw=accumulate(w,w+N,0);
		int maxr=*max_element(r,r+N);
		if(maxr <= sumr-maxr){
			cout<<sumr+sumw<<endl;
		}else{
			int gap=maxr-(sumr-maxr);
			int ng;
			rep(i,N)if(r[i]==maxr)ng=i;
			memset(dp,0,sizeof(dp));
			dp[0][0]=1;
			rep(i,N){
				rep(j,gap+1)if(dp[i][j]){
					dp[i+1][j]=1;
					if(i!=ng && j+w[i]<=gap)dp[i+1][j+w[i]]=1;
				}
			}
			for(int i=gap;i>=0;i--)if(dp[N][i]){
				cout<<2*maxr+sumw-i<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 5196
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int sum = 0;
		int i;
		for(i = 0; i < N; i++) {
			sum += sc.nextInt();
			if(sum > X)break;
		}
		sc.close();
		System.out.println(i+1);
	}
}

Measured memory_bytes: 22996
#include<iostream>

using namespace std;

string in;

int isA(){
  if(in.length() < 5) return 0;
  if(in[0] != '>') return 0;
  if(in[1] != '\'') return 0;
  if(!(in[in.length()-1] == '~' && in[in.length()-2] == '=')) return 0;
  int data[2] = {0,0};
  int status = 0;
  for(int i = 2; i < in.length()-1; i++){
    if(in[i] == '#') status = 1;
    if(in[i] == '=') data[status]++;
    if(in[i] != '#' && in[i] != '=') return 0;
  }
  if(data[0] && data[0] == data[1]) return 1;
  return 0;
}

int isB(){
  if(in.length() < 5) return 0;
  if(in[0] != '>') return 0;
  if(in[1] != '^') return 0;
  if(!(in[in.length()-1] == '~' && in[in.length()-2] == '~')) return 0;
  for(int i = 2; i < in.length()-2; i+=2){
    if(!(in[i] == 'Q' && in[i+1] == '=')) return 0;
  }
  return 1;
}


int main(){
  int num;
  cin >> num;
  for(int i = 0; i < num; i++){
    cin >> in;
    if(isA()) cout << "A" << endl;
    else if(isB()) cout << "B" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    s[5] = ' ';
    s[13] = ' ';
    cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int h[100005],vis[100005];
int main()
{
	int n,m,num=0;scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i)
	scanf("%d",&h[i]);
	for(int i=1;i<=m;++i)
	{
		int x,y;scanf("%d%d",&x,&y);
		if(h[x]==h[y]) 
		{
			vis[x]=vis[y]=1;
		}else if(h[x]>h[y])
		vis[y]=1;
		else vis[x]=1;
	}
	for(int i=1;i<=n;++i)
	if(vis[i]==0) num++;
	printf("%d",num);
 }

Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
	int X, N;
	cin >> X >> N;
	vector<int> p(N);
	for(int i=0; i<N; ++i) cin >> p[i];
	vector<int> ref(100, 0);
	for(int i=0; i<N; ++i){
		++ref[p[i]-1];
	}
	for(int i=0; i<100; ++i){
		if(ref[X-i-1]==0){
			cout << X-i << endl;
			return 0;
		}else if(ref[X+i-1]==0){
			cout << X+i << endl;
			return 0;
		}
	}
}

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

using namespace std;

using ll = long long;
using ld = long double;

bool Check(string s) {
    for (int i = 0; i < 3; ++i)
        if (s[i] == s[i + 1]) return false;
    return true;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    string s;
    cin >> s;
    if (Check(s)) cout << "Good\n";
    else cout << "Bad\n";

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a(1<<n);
    vector<int> f;
    bool ans = 0;
    for(int i=0; i<(1<<n); i++){
         scanf("%d", &a[i]);
    }
    for(int i=0; i<(1<<n); i++){
         bool g = 0;
         for(int j=0;j<n;j++)
         {
             if(!((i>>j)&1))continue;
             int t=i&~(1<<j);
             if(a[t]==1)
              {
                  g=1;
                  if(a[i] == 0){
                      cout << -1 << endl;
                      return 0;
                  }
             }
         }
         if(!g&&a[i] == 1){
             f.push_back(i);
         }
    }
    cout << f.size() << endl;

}



Measured memory_bytes: 8004
#include<stdio.h>
int main(void){
    int a,b,c,d;
    scanf("%d%d%d",&a,&b,&c);
    if(a>b){
        d=a;
        a=b;
        b=d;
    };
    if(b>c){
        d=b;
        b=c;
        c=d;
    };
    if(a>b){
        d=a;
        a=b;
        b=d;
    };
    printf("%d %d %d\n",a,b,c);
return 0;
}

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

struct Node{
    int k;
    struct Node *right;
    struct Node *left;
    struct Node *parent;
};

struct Node *root,*NIL;

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);
struct Node * find(struct Node *,int);

int main(){
    int i,n,value,findnum;
    
    char A[10];
    
    scanf("%d",&n);
    
    for(i = 0;i < n;i++){
        scanf("%s",A);
        if(strcmp(A,"insert") == 0){
            scanf("%d",&value);
            insert(value);
        }
        else if(strcmp(A,"print") == 0){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(strcmp(A,"find") == 0){
            scanf("%d",&findnum);
            struct Node *F = find(root,findnum);
            if(F != NIL) printf("yes\n");
            else printf("no\n");
        }
    }
    
    return 0;
}

void insert(int n){
    struct Node *p = root;
    struct Node *q = NIL;
    struct Node *r;
    
    r = (struct Node *)malloc(sizeof(struct Node));
    r -> k = n;
    r -> left = NIL;
    r -> right = NIL;
    
    while(p != NIL){
        q = p;
        if(r -> k < p -> k){
            p = p -> left;
        }
        else{
            p = p -> right;
        }
    }
    
    r -> parent = q;
    
    if(q == NIL){
        root = r;
    }
    else{
        if(r -> k < q -> k){
            q -> left = r;
        }
        else{
            q -> right = r;
        }
    }
}

void inorder(struct Node *x){
    if(x == NIL) return;
    inorder(x -> left);
    printf(" %d",x -> k);
    inorder(x -> right);
}

void preorder(struct Node *x){
    if(x == NIL) return;
    printf(" %d",x -> k);
    preorder(x -> left);
    preorder(x -> right);
}

struct Node * find(struct Node *x,int n){
    while(x != NIL && n != x -> k){
        if(n < x -> k){
            x = x -> left;
        }
        else{
            x = x -> right;
        }
    }
    return x;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> b(n), ans;
  rep(i, n) cin >> b[i];
  rep(i, n) {
    for (int j = b.size() - 1; j >= 0; j--) {
      if (j + 1 == b[j]) {
        ans.push_back(b[j]);
        b.erase(b.begin() + j);
        break;
      }
    }

    if (i + 1 != ans.size()) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

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

    long long M = 1000000007LL;
    vector<vector<long long>> T(N, vector<long long>(N));
    for (int i=0; i<N; i++)
        T[0][i] = 1;
    for (int i=1; i<N; i++)
        if (s[i-1]=='<')
        {
            T[i][0] = T[i-1][0];
            for (int j=1; j<N-i; j++)
                T[i][j] = T[i][j-1] + T[i-1][j],
                T[i][j] %= M;
        }
        else
        {
            for (int j=N-i-1; j>=0; j--)
                T[i][j] = T[i][j+1] + T[i-1][j+1],
                T[i][j] %= M;
        }
    cout<<T[N-1][0]<<endl;
}


Measured memory_bytes: 70656
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
using namespace std;
#define N 100
int th,t;
int place[15];
void dfs(int ws,int ths,int len)
{
    if(len==ws)
    {
        th++;

        if(th==t){
        for(int i=1;i<=ws;i++)
            cout<<place[i];
                cout<<endl;

            exit(0);}
        return ;

    }
    for(int i=ths-1;i<=ths+1;i++)
    {
        if(i<0||i>9)
            continue;
        place[len+1]=i;
        dfs(ws,i,len+1);
    }
}
int main()
{

    cin>>t;
    for(int i=1;i<=12;i++)
        for(int j=1;j<=9;j++)
        {
            place[1]=j;
            dfs(i,j,1);
        }



}


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

const int MAXN = 1e5+5;
const int MAXNN = 1e5+7;
const int INF = 1e9+7;
#define ll long long
#define pb push_back
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

ll MOD(ll a){
    return ((a%INF)+INF)%INF;
}

ll inv(ll a){
    return poww(a,INF-2,INF);
}

bool dp[MAXN];
int a[MAXN];

int main()
{
    fast_io;
    //cout << fixed << setprecision(15);

    int n,k;cin >> n >> k;
    for(int i=1;i<=n;++i) cin >> a[i];

    dp[0] = 0;
    for(int i=1;i<=k;++i){
        for(int f=1;f<=n;++f){
            if(i >= a[f]) dp[i] |= !dp[i-a[f]];
        }
    }
    if(dp[k]) cout << "First";
    else cout << "Second";
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define INF 987654321
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

#define MAX_N 60
double v[MAX_N];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(16); // show 16 digits

    int N;
    cin >> N;
    for(int i=0; i<N;i++){
        cin >> v[i];
    }
    sort(v, v+N);
    double res = (v[0] + v[1])/2.0;
    for(int i=2; i<N;i++){
        res = (res + (v[i])) / 2.0;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
 
    int n,m;
    int ans1 = 0, ans2 = 0;
    
    cin >> n >> m;
    
    if(n >= 2) {
        ans1 = 1;
        for(int i=n;i>n-2;i--)ans1 *= i;
        ans1= ans1/2;
    }
    
    if(m >= 2){
        ans2 = 1;
      for(int i=m;i>m-2;i--) ans2 *= i; 
      ans2 = ans2/2;  
    }
    
    
    cout << ans1 + ans2 << endl;
    
    return 0;    
}

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

int main() {
	bool ok = true;
	int n;
	cin >> n;
	forn(i, n) {
		int x;
		cin >> x;
		if(x % 2 == 0)
			if(x%3!=0 && x%5!=0)
				ok = false;
	}
	if(ok) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
	return 0;
}



Measured memory_bytes: 3548
#include <stdio.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(void){
    int n, x;
    int a[100+5];
    scanf("%d %d", &n, &x);
    for(int i=0; i<n; i++)scanf("%d", &a[i]);
    qsort(a, n, sizeof(int), compare_int);
    
    int ans=0;
    for(int i=0; i<n; i++){
        if(a[i]<=x){
            x-=a[i];
            ans++;
            if(i==n-1 && x!=0)ans--;
        }
    }
    
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1732
n = int(input())
a = list(map(int , input().split()))

from collections import defaultdict
l = defaultdict(int)
r = defaultdict(int)

for i in range(n):
    l[i - a[i]] += 1
    r[i + a[i]] += 1
ans = 0
for li in l:
    ans += l[li] * r[li]

print(ans)


Measured memory_bytes: 74108
#ABC139_C
N=int(input())
H=list(map(int,input().split()))
H.append(int(1e11))
cnt=0
ans=0
for i in range(N):
    if H[i]>=H[i+1]:
        cnt+=1
    else:
        if cnt>ans:
            ans=cnt
        cnt=0
print(ans)

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>
#define min(p,q)((p)<(q)?(p):(q))
#define bit2(n,m)(((n)>>(2*(m)))&3)

int x[10];
int a[4];
int main(){
	int n;
	scanf("%d%d%d%d",&n,a,a+1,a+2);
	for(int i=0;i<n;i++)scanf("%d",x+i);
	int ans=1e9;
	for(int i=0;i<1<<(2*n);i++){
		int t[4]={};
		int tc[4]={};
		for(int k=0;k<n;k++){
			t[bit2(i,k)]+=x[k];
			tc[bit2(i,k)]++;
		}
		if(tc[0]&&tc[1]&&tc[2]){
			int temp=0;
			for(int k=0;k<3;k++)temp+=(tc[k]-1)*10+abs(t[k]-a[k]);
			ans=min(ans,temp);
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e7;
int main() {
  ll H, W;
  cin >> H >> W;
  ll Ch, Cw, Dh, Dw;
  cin >> Ch >> Cw >> Dh >> Dw, Ch--, Cw--, Dh--, Dw--;
  vector<string> S(H + 1);
  REP(i, H) { cin >> S[i]; }
  vector<vector<ll>> Dis(H + 1, vector<ll>(W + 1, INF));
  queue<pair<P, ll>> que1{};
  Dis[Ch][Cw] = 0;
  que1.push(pair<P, ll>(P(Ch, Cw), 0));
  queue<pair<P, ll>> que2{};  //ワープもと候補
  bool start = true;
  ll ans = -1;
  while (!que2.empty() || start) {
    start = false;
    while (!que2.empty()) {
      auto p = que2.front();
      que2.pop();
      ll y = p.first.first, x = p.first.second, score = p.second;
      for (ll i = -2; i < 3; i++) {
        for (ll j = -2; j < 3; j++) {
          ll ny = y + i, nx = x + j;
          if (0 <= ny && ny < H && 0 <= nx && nx < W) {
            if (S[ny][nx] == '#') continue;
            if (score + 1 < Dis[ny][nx] && S[ny][nx] == '.') {
              Dis[ny][nx] = score + 1;
              que1.push(pair<P, ll>(P(ny, nx), score + 1));
            }
          }
        }
      }
    }
    ll a = 10;
    while (!que1.empty()) {
      auto p = que1.front();
      que1.pop();
      ll y = p.first.first, x = p.first.second, score = p.second;
      if (y == Dh && x == Dw) {
        if (ans == -1) {
          ans = score;
        } else {
          ans = min<ll>(score, ans);
        }
      }
      int canotMove = 0;
      if (0 < y) {
        ll ny = y - 1, nx = x;
        if (S[ny][nx] == '.') {
          if (score < Dis[ny][nx]) {
            Dis[ny][nx] = score;
            que1.push(pair<P, ll>(P(ny, nx), score));
            canotMove++;
          }
        }
      }
      if (y < H - 1) {
        ll ny = y + 1, nx = x;
        if (S[ny][nx] == '.') {
          if (score < Dis[ny][nx]) {
            Dis[ny][nx] = score;
            que1.push(pair<P, ll>(P(ny, nx), score));
            canotMove++;
          }
        }
      }
      if (0 < x) {
        ll ny = y, nx = x - 1;
        if (S[ny][nx] == '.') {
          if (score < Dis[ny][nx]) {
            Dis[ny][nx] = score;
            que1.push(pair<P, ll>(P(ny, nx), score));
            canotMove++;
          }
        }
      }
      if (x < W - 1) {
        ll ny = y, nx = x + 1;
        if (S[ny][nx] == '.') {
          if (score < Dis[ny][nx]) {
            Dis[ny][nx] = score;
            que1.push(pair<P, ll>(P(ny, nx), score));
            canotMove++;
          }
        }
      }
      if (true /*canotMove < 3*/) {
        que2.push(pair<P, ll>(P(y, x), score));
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 13348
#include "stdio.h"

int main(int argc, char const *argv[])
{
	char value0,value1;
	scanf("%c %c",&value0,&value1 );
	
	if((int)value0>(int)value1){
		printf(">\n");
	}
	else if((int)value0<(int)value1){
		printf("<\n");
	}
	else if((int)value0==(int)value1){
		printf("=\n");
	}

	return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

bool in(string s1, string s2) {
  int64 idx = 0;
  REP(i, s2.size()) {
    if (idx < s1.size() && s1[idx] == s2[i]) idx++;
  }
  return idx == s1.size();
}

::std::vector<::std::int64_t> divisors(::std::int64_t x) {
	::std::vector<::std::int64_t> res;
	for (::std::int64_t i = 1; i*i <= x; ++i) {
		if (x % i == 0) {
			res.push_back(i);
			if (i * i != x) res.push_back(x / i);
		}
	}
	::std::sort(res.begin(), res.end());
	return res;
}

int main(void) {
  int64 N, M;
  cin >> N >> M;
  vector<int64> A(N);
  REP(i, N) cin >> A[i];
  priority_queue<PLL> pq;
  REP(i, M) {
    int64 b, c;
    cin >> b >> c;
    pq.emplace(c, b);
  }
  sort(all(A));
  int64 res = 0;
  REP(i, N) {
    while (pq.size() && pq.top().sc == 0) pq.pop();
    if (pq.size()) {
      if (pq.top().fs > A[i]) {
        res += pq.top().fs;
        PLL a = pq.top(); pq.pop();
        a.sc--;
        pq.push(a);
      } else {
        res += A[i];
      }
    } else {
      res += A[i];
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int INF=1001001001;
const int NMAX=8;
const int MOD=1000000007;
const int dbase=80*160;


int main(){
	string s;
	cin>>s;
	string ans="No";
	rep(i,s.size()){
		if (s[i]=='7') ans="Yes";
	}
	cout<<ans;

}


Measured memory_bytes: 3596
#include <stdio.h>

int selectionSort(int *,int);

int main()
{
   int A[100],N,i,sw;

  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);
  
  sw = selectionSort(A,N);
  
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",sw);

  return 0;

}

int selectionSort(int A[],int N)
{
  int i,j,minj,s,sw;

  sw = 0;

  for(i=0;i<=N-1;i++){
    minj = i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj])minj = j;
    }
    s = A[i];
    A[i] = A[minj];
    A[minj] = s;

    if(i!=minj)sw++;
    }
    return sw;
  }
	
    



Measured memory_bytes: 2104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc_047_B
{
    class Program
    {
        public static long max(long a, long b)
        {
            return Math.Max(a, b);
        }
        public static long min(long a, long b)
        {
            return Math.Min(a, b);
        }
        static void Main(string[] args)
        {
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray(); ;
            long minx = 0;
            long maxx = a[0];
            long miny = 0;
            long maxy = a[1];
            for (long i = 0; i < a[2]; i++)
            {
                long[] S = Console.ReadLine().Split().Select(long.Parse).ToArray();
                if (S[2] == 1)
                {
                    minx = max(minx, S[0]);
                }
                else if (S[2] == 2)
                {
                    maxx = min(maxx, S[0]);
                }
                else if (S[2] == 3)
                {
                    miny = max(miny, S[1]);
                }
                else maxy = min(maxy, S[1]);
            }
            if (maxy - miny < 0 || maxx - minx < 0) { Console.WriteLine(0); return; }
            Console.WriteLine((maxx - minx) * (maxy - miny));
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13268