akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main() {
  int n, m;
  int mmm=0;
  while(cin>>n>>m,n||m) {
    if (mmm++) cout << endl;
    map<string, int> mp;
    string lang[n];
    REP(i, n) {
      cin >> lang[i];
      mp[lang[i]] = i;
    }
    int mask[m];
    REP(i, m) {
      int c;
      cin >> c;
      mask[i] = 0;
      REP(j, c) {
        string s;
        cin >> s;
        mask[i] |= 1<<mp[s];
      }
    }
    vector<int> ans;
    for (int i=1; i<=min(n,5); ++i) {
      bool perm[n];
      REP(j,n) perm[j] = (j>=n-i);
      do {
        UnionFind uf(m);
        REP(j, n) {
          if (!perm[j]) continue;
          int hoge = -1;
          REP(k, m) {
            if (mask[k]>>j&1) {
              if (hoge == -1) hoge = k;
              else uf.unionSet(hoge, k);
            }
          }
        }
        if (uf.size(0) == m) {
          REP(j, n) {
            if (perm[j]) 
              ans.push_back(j);
          }
          break;
        }
      } while(next_permutation(perm, perm+n));
      if (ans.size()) break;
    }
    if (ans.size()) {
      cout << ans.size() << endl;
      FOR(it, ans) {
        cout << lang[*it] << endl;
      }
    } else {
      cout << "Impossible" << endl;
    }
  }
}

Measured memory_bytes: 932
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		ou.println(2 * b - a);
		ou.flush();
	}
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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 x,y;
    cin >> x >> y;

    set<int> a;
    a.insert(1);
    a.insert(3);
    a.insert(5);
    a.insert(7);
    a.insert(8);
    a.insert(10);
    a.insert(12);

    set<int> b;
    b.insert(4);
    b.insert(6);
    b.insert(9);
    b.insert(11);

    if( x == y || (a.find(x) != a.end() && a.find(y) != a.end()) || (b.find(x) != b.end() && b.find(y) != b.end()) )
    {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define Aint(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
const int MOD = 1e9+7;
const int INF = 1e9;
const int MAXN = 1050000;

ll N,T,a,b,c,d,e,f;
ll A[MAXN];

string S;
int main(){
  cin>>N;
  a += 1000*(N/500);
  N%=500;
  a += 5*(N/5);
  cout<<a;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
fast_io
int x,a,b; cin>>x>>a>>b;
x-=a;
x%=b;
cout<<x;
return 0;
}

Measured memory_bytes: 256
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int H, W;

vector<vector<bool>> map0;   //true->障害物
vector<vector<int>> map1;
vector<vector<int>> temp;

void solve() {
	cin >> H >> W;
	map0.resize(W);
	map1.resize(W);
	temp.resize(W);
	for (int x = 0; x < W; x++) {
		map0[x].resize(H);
		map1[x].resize(H,0);
		temp[x].resize(H);
	}
	for (int y = 0; y < H; y++) {
		string S;
		cin >> S;
		for (int x = 0; x < W; x++)map0[x][y] = (S[x]=='#'?true:false);
	}
	for (int y = 0; y < H; y++) {
		map1[W-1][y] = (map0[W-1][y]?-1:0);
		for (int x = W-2; x >= 0; x--) {
			if (map0[x][y])map1[x][y] = -1;
			else map1[x][y] = map1[x + 1][y] + 1;
		}
	}
	for (int y = 0; y < H; y++) {
		temp[0][y] = (map0[0][y] ? -1 : 0);
		for (int x = 1; x < W; x++) {
			if (map0[x][y])temp[x][y] = -1;
			else temp[x][y] = temp[x - 1][y] + 1;
			map1[x][y] += temp[x][y];
		}
	}
	for (int x = 0; x < W; x++) {
		temp[x][0] = (map0[x][0] ? -1 : 0);
		for (int y = 1; y < H; y++) {
			if (map0[x][y])temp[x][y] = -1;
			else temp[x][y] = temp[x][y - 1] + 1;
			map1[x][y] += temp[x][y];
		}
	}
	for (int x = 0; x < W; x++) {
		temp[x][H-1] = (map0[x][H-1] ? -1 : 0);
		for (int y = H - 2; y >= 0; y--) {
			if (map0[x][y])temp[x][y] = -1;
			else temp[x][y] = temp[x][y + 1] + 1;
			map1[x][y] += temp[x][y];
		}
	}
	int ans = 0;
	for (int x = 0; x < W; x++) {
		for (int y = 0; y < H; y++) {
			if (map0[x][y])continue;
			ans = max(ans,map1[x][y]+1);
		}
	}
	cout << ans << endl;
	return;
}

Measured memory_bytes: 32256
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp 
int main(){
    ll x,y,z,n,m=0,k,h,w,sum=0,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u,v;
    bool ok=true;
    cin >> n >> h;
    VL a(n);
    VL b(n);
    rep(i,n){
        cin >> a[i] >> b[i];
    }

    sort(ALL(a));
    sort(RALL(b));
    Max = a[n-1];
    rep(i,n){
        if(b[i] > Max){
            h -= b[i];
            ans++;
            if(h<=0){
                cout << ans << endl;
                return 0;
            }
        }
    }
    ans += (ll)ceil((double)h/(double)Max);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[200001]; 
int main()
{
	 int n;
	 cin>>n;
	 for(int i=1;i<=n;i++)
	 	cin>>a[i];
	int max=0;
	int min=0;
	int j;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=max)
		{
			max=a[i];
			j=i;
			}	
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=min and i!=j)
			min=a[i];
	}
	
	for(int i=1;i<=n;i++)
	{
		if(a[i]==max)
			cout<<min<<endl;
		else
			cout<<max<<endl;			
	}
}


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

// Inserted snippets: io, root
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
// End snippets

int D, c[27];
int s[366][27];

chrono::steady_clock::time_point program_begin;

double runtime() {
	chrono::steady_clock::time_point program_end = chrono::steady_clock::now();

	return chrono::duration_cast<chrono::microseconds>(program_end - program_begin).count() / 1000000.0;
}

int calc(vector<int> sc) {
	vector<int> last(27, 0);
	int val = 0;
	rep(d, 1, D + 1) {
		val += s[d][sc[d]];
		last[sc[d]] = d;
		rep(i, 1, 27)
			val -= c[i] * (d - last[i]);
	}
	return val;
}

int myrand(int a, int b) {
	return a + rand() % (b - a + 1);
}

void solve() {
	vector<int> ans(366), best_ans(366);
	int best_ans_val = -50000000;
	int cur_val = calc(ans);

	for (int i = 1; i <= 365; i++)
		ans[i] = i % 26 + 1;

	auto rng = default_random_engine {};
	while (runtime() <= 0.2) {
		for (int i = 1; i + 25 <= 365; i += 26) {
			shuffle(ans.begin() + i, ans.begin() + i + 26, rng);
		}

		int val = calc(ans);
		if (val > best_ans_val) {
			best_ans_val = val;
			best_ans = ans;
		}
	}

	ans = best_ans;
	cur_val = best_ans_val;

	while (runtime() <= 1.8) {
		int d = myrand(1, 365), n = myrand(1, 26);
		if (ans[d] == n)
			continue;
		vector<int> new_ans = ans;
		new_ans[d] = n;
		int new_val = calc(new_ans);
		double base_proc = exp(-15.0 * runtime() / 1.8);
		double rand_double = 1.0 * rand() / RAND_MAX;
		bool accept =
			rand_double < base_proc * (1.0 * new_val / best_ans_val);
		if (new_val > cur_val || accept) {
			ans = new_ans;
			cur_val = new_val;

			if (chmax(best_ans_val, cur_val)) {
				best_ans_val = cur_val;
				best_ans = ans;
			}
		}
	}

	rep(i, 1, D + 1)
		write(best_ans[i]);
}

void test() {}

int main(int argc, char *argv[]) {
	//cin.tie(0)->sync_with_stdio(0);
	//cin.exceptions(cin.failbit);

	srand(time(NULL));

	program_begin = chrono::steady_clock::now();

	read(D);
	rep(i, 1, 27) read(c[i]);
	rep(i, 1, D + 1) rep(j, 1, 27) read(s[i][j]);
	
	solve();
}


Measured memory_bytes: 4348
n,d=map(int,input().split())

x=[]
y=[]

for i in range(n):
    a,b=map(int,input().split())
    x.append(a)
    y.append(b)

c=0
for i in range(n):
    if d**2>=x[i]**2+y[i]**2:
        c+=1
print(c)

Measured memory_bytes: 24772
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
#include <utility>
using namespace std;
typedef long long longlong;
typedef long long LL;

int main(void) {
	LL a, b, c;
	cin >> a >> b >> c;
	if (c >= a&&c <= b) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc =new Scanner(System.in);
		int N=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		if(A*N<B)System.out.println(A*N);
		else System.out.println(B);
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

int main(void){
    // Your code here!
    long double N;
    cin >> N;
    long double sum = 0;
    for( int i =0; i < N; i++){
        long double tmp;
        cin >> tmp;
        sum += (1/tmp);
    }
    cout << std::setprecision(15) << 1/sum << endl;
}

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

/*  bitwise  */
#define LSH <<
#define RSH >>
#define AND ^
#define OR ||

/*    */

int N;
int arr[101];
int result = 0;

int main()
{
    cin>>N;

    for(int i = 1; i <= N; i++)
        cin>>arr[i];

    for(int i = 1; i < N; i++)
        for(int j = i + 1; j <= N; j++)
        {
            if(arr[i] == 0 OR arr[j] == 0)
                continue;
            result += arr[i]*arr[j];
        }

    cout<<result<<"\n";
    return 0;
}




Measured memory_bytes: 256
h,w = map(int,input().split())
a = [list(input()) for _ in range(h)]

x = [0,1,1,1,0,-1,-1,-1]
y = [1,1,0,-1,-1,-1,0,1]

for i in range(h):
    for j in range(w):
        if a[i][j] == '.':
            a[i][j] = 0
            for k in range(8):
                if (0 <= i+x[k] <= h-1) and (0 <= j+y[k] <= w-1):
                    if a[i+x[k]][j+y[k]] == '#':
                        a[i][j] += 1
            a[i][j] = str(a[i][j])

for aa in a:
    print(''.join(aa))

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

int  main()
{ 
	ll a; string b; cin >> a >> b;
	b.erase(1, 1);
	int ib = stoi(b);
	printf("%lld", (ll)a*ib/100);
	return (0);
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define PREP(i, m, n) for(int i = m; i < n; i++)
#define MREP(i, m, n) for(int i = m - 1; i >= n; i--)

#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define X first
#define Y second
#define MP make_pair
#define PB push_back

using namespace std;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
bool mark[12][6] = {false};
int c;
const int h = 12, w = 6;

void clear(){
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			mark[i][j] = false;
		}
	}
}

void del(vector<string> &map){
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(mark[i][j]){
				for(int k = 0; k < 4; k++){
					if((j+dx[k]<0||j+dx[k]>=w)||(i+dy[k]<0||i+dy[k]>=h))continue;
					if(map[i+dy[k]][j+dx[k]] == 'O') map[i+dy[k]][j+dx[k]] = '.';
				}
				map[i][j] = '.';
				mark[i][j] = false;
			}
		}
	}
}

void dfs(char target, int y, int x, vector<string> &map){
	mark[y][x] = true;
	for(int i = 0; i < 4; i++){
		if((x+dx[i]<0||x+dx[i]>=w)||(y+dy[i]<0||y+dy[i]>=h))continue;
		if(map[y+dy[i]][x+dx[i]] == target && !mark[y+dy[i]][x+dx[i]]){
			c++;
			dfs(target, y+dy[i], x+dx[i], map);
		}
	}
}

int main(){
	int n = 0;
	cin >> n;
	while(n--){
		vector<string> map(h, string(w, ' '));
		for(int i = 0; i < h; i++){
			cin >> map[i];
		}
		int chain = 0;
		while(1){
			bool chainf = false;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					if(map[i][j]=='.' || map[i][j]=='O')continue;
					c = 1;
					dfs(map[i][j], i, j, map);
					if(c >= 4){
						del(map);
						chainf = true;
					}
					else clear();
				}
			}
			if(chainf) chain++;
			else break;
			for(int i = h-2; i >= 0; i--){
				for(int j = 0; j < w; j++){
					int tmp = i;
					while(tmp+1<h&&map[tmp+1][j]=='.'){
						map[tmp+1][j] = map[tmp][j];
						map[tmp][j] = '.';
						tmp++;
					}
				}
			}
		}
		cout << chain << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long N,K;
  cin >> N >> K;

  long A[N+1];
  for(long i=1; i<N+1; i++){
    cin >> A[i];
  }

  long pos = 1;
  long tag[N+1]={0};
  while(K>0){
    K--;
    pos = A[pos];
    //cout << pos << ' ' << tag[pos] << ' ' << K <<endl;
    if(tag[pos]==0){
      tag[pos]=K;
    }else{
      K = K % (tag[pos]-K);
    }
  }
  
  cout << pos << endl;
  return 0;
}


Measured memory_bytes: 6756
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

from operator import itemgetter as get

def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)], key=get(1)
    )
    cur = 0
    for task, deadline in A:  # check all tasks greedily
        cur += task
        if cur > deadline:  # fail to finish a task within its deadline
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 33488
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define inf 0x3f3f3f3f
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout);
using namespace std;

const int N=200005,M=100005,mod=1e9+7;
template<class T> inline void gmin(T &x,const T &y){if(x>y) x=y;}
template<class T> inline void gmax(T &x,const T &y){if(x<y) x=y;}
inline void ch(int &x,int y){x=(x+y)%mod;}
inline void read(int &x){
	x=0;char ch=getchar(),rev=0;
	while(ch>'9'||ch<'0') rev=(ch=='-'),ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	x=rev?-x:x;
}
inline int exp(int x,int y){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int n,m,cnt,xx[N],yy[N],x[N],y[N];
priority_queue<int> q;
vi g[N];

int main(){
#ifdef rqgao2014
	freopen("input.txt","r",stdin);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&x[i],&y[i]),xx[i]=x[i];
		g[x[i]].pb(y[i]);
	}
	sort(xx+1,xx+n+1);
	int lb=0;
	for(int i=1;i<=n;i++)
		if(xx[i]>lb) lb++;
	for(int i=lb+1;i<=m;i++)
		if(g[i].size()) for(int j:g[i]) q.push(j);
	for(int i=lb;i;i--){
		if(g[i].size())
			for(int j:g[i]) q.push(j);
		q.pop();
	}
	if(g[0].size())
		for(int j:g[0]) q.push(j);
	while(!q.empty()) yy[++cnt]=m+1-q.top(),q.pop();
	int rb=0;
	sort(yy+1,yy+cnt+1);
	for(int i=1;i<=cnt;i++)
		if(yy[i]>rb) rb++;
	printf("%d\n",n-min(m,lb+rb));
	return 0;
}

Measured memory_bytes: 11392
s=input()
ans=[0]*(len(s))

now="R"
r=[0]*2
l=[0]*2
for i in range(len(s)):
    if now=="R":
        if s[i]=="R":
            r[i%2]+=1
        else:       
            ans[i]+=r[i%2]
            ans[i-1]+=r[(i+1)%2]
            now="L"
            r=[0]*2
            pos=i
            l[i%2]+=1
    else:
        if s[i]=="L":
            l[i%2]+=1
        else:
            ans[pos]+=l[pos%2]
            ans[pos-1]+=l[(pos+1)%2]
            now="R"
            l=[0]*2
            r[i%2]+=1

ans[pos]+=l[pos%2]
ans[pos-1]+=l[(pos+1)%2]

L=[str(a) for a in ans]
ans=" ".join(L)
print(ans)


Measured memory_bytes: 17140
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;
int dp[1000010];
int sum[1000010];

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int n;
	cin >> n;
	dp[0] = 1; sum[0] = 1;
	dp[1] = n; sum[1] = n + 1;
	for (int i = 2; i <= n; i++) {
		dp[i] = (n - 1)*(n - 1);
		dp[i] += dp[i - 1];
		dp[i] %= mod;
		int l = i - n - 1, r = i - 3;
		if (r <= 0) {
			dp[i] += n - 1;
		}
		else if (l <= 0) {
			dp[i] -= l;
			dp[i] += sum[r];
		}
		else {
			dp[i] -= sum[l - 1];
			dp[i] += sum[r];
		}
		dp[i] = (dp[i] + mod) % mod;
		sum[i] = (sum[i - 1] + dp[i]) % mod;
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long ULL;
    const int maxn = 200000 + 5;
    const int mod = 10007;
    const double PI = acos(-1.0);
    const double eps = 1e-10;
    int a[maxn], n, l[maxn], r[maxn];
    stack<int> stk;
    ULL ans ;
    int main()
    {
        while (~scanf("%d", &n)) {
            for (int i=1; i<=n; i++) scanf("%d", &a[i]);
            sort(a+1, a+n+1);
            int q = a[n], flag = 0;
            if (a[1] != (q+1)/2) flag = 1;
            else {
                int cnt = 1, now = a[1], i;
                for (i=2; i<=n; i++) {
                    if (a[i] == now) cnt++;
                    else break;
                }
                if ((q%2==1 && cnt!=2) || (q%2==0 && cnt!=1)) flag = 1;
                else {
                    cnt = 0; now = a[i];
                    for (; i<=n; i++) {
                        //printf("%d: %d %d\n",i,now,cnt);
                        if (a[i] == now) cnt++;
                        else {
                            if (cnt < 2 || a[i]-now!=1) { //puts("===");
                                flag = 1;
                                break;
                            }
                            cnt = 1; now = a[i];
                        }
                    }
                }
            }
            if (flag) puts("Impossible");
            else puts("Possible");
        }
        return 0;
    }

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

#define ALL(v) v.begin(), v.end()
typedef long long ll;



using namespace std;
int main() {
	int n;
	cin >> n;

	vector<int> ary = {111, 222, 333, 444, 555, 666, 777, 888, 999};

	for (int x : ary) {
		if (n <= x) {
			cout << x;
			break;
		}
	}
	


}

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

class Program {
    static string ReadLine() { return Console.ReadLine(); }
    static int ReadInt() { return int.Parse(ReadLine()); }
    static int[] ReadInts() { return ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return ReadLine().Split(); }

    static int LevenshteinDistance(string s, string t) {
        Func<int, int, int, int> min = (a, b, c) => Math.Min(a, Math.Min(b, c));

        var d = new int[s.Length+1, t.Length+1];
        for (int i = 0; i < s.Length+1; i++)
            for (int j = 0; j < t.Length+1; j++)
                d[i, j] = int.MaxValue/10;

        for (int i = 0; i <= s.Length; i++) d[i, 0] = i;
        for (int i = 0; i <= t.Length; i++) d[0, i] = i;

        for (int i = 1; i <= s.Length; i++) {
            for (int j = 1; j <= t.Length; j++) {
                var cost = s[i-1] == t[j-1] ? 0 : 1;
                d[i, j] = min(d[i-1, j  ] + 1,     // ??????????????\
                              d[i,   j-1] + 1,     // ???????????????
                              d[i-1, j-1] + cost); // ???????????????
            }
        }
        return d[s.Length, t.Length];
    }

    static void Main() {
        var s = ReadLine();
        var t = ReadLine();
        Console.WriteLine(LevenshteinDistance(s, t));

    }
}

Measured memory_bytes: 13344
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n; cin >> n;
    set<string> st;
    rep(i, n){
        string s; cin >> s;
        st.insert(s);
    }

    cout << st.size() << endl;

    return 0;
}

Measured memory_bytes: 19216
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

int dp[305][305][305] = {};

signed main(void) {
    int n,m;
    cin >> n >> m;
    vector<vp> in(n+1);
    rep(i,m){
        int l,r,x;
        cin >> l >> r >> x;
        in[r].push_back(pii(l,x));
    }
    dp[0][0][0] = 1;
    int ans = 0;
    rep(i,n+1)rep(j,n+1)rep(k,n+1){
        vi v(3);
        v[0] = i, v[1] = j, v[2] = k;
        sort(all(v));
        int ma = v.back();
        //cout << i << " " << j << " " << k << " " << in[ma].size() << endl;
        rep(p,in[ma].size()){
            int l = in[ma][p].first;
            int x = in[ma][p].second;
            if(x == 1){
                if(v[1] < l);
                else dp[i][j][k] = 0;
            }else if(x == 2){
                if(v[0] < l && l <= v[1]);
                else dp[i][j][k] = 0;
            }else if(x == 3){
                if(l <= v[0]);
                else dp[i][j][k] = 0;
            }
            if(!dp[i][j][k])break;
        }
        //cout << i << " " << j << " " << k << " " << dp[i][j][k] << endl;
        if(ma == n){
            ans = (ans + dp[i][j][k])%MOD;
            continue;
        }
        (dp[ma+1][j][k] += dp[i][j][k]) %= MOD;
        (dp[i][ma+1][k] += dp[i][j][k]) %= MOD;
        (dp[i][j][ma+1] += dp[i][j][k]) %= MOD;
    }
    cout << ans << endl;
}


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

int main() {
  int a,b;
  cin>>a>>b;
  if((a==1&&b==2)||(a==2&&b==1))cout<<3;
  if((a==1&&b==3)||(a==3&&b==1))cout<<2;
  if((a==2&&b==3)||(a==3&&b==2))cout<<1;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<llint,vector<llint>,greater<llint>> que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int n;
llint p[15];

void solve(){
	cin >> n;
	llint mx=0;
	llint sm=0;
	for(int i=0;i<n;i++){
		cin >> p[i];
		if(mx<p[i])mx=p[i];
		sm+=p[i];
	}
	sm-=mx;
	sm+=mx/2;
	cout << sm << endl;

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>

using namespace std;

#define N 100005
int dp[N][2];
vector<int> adj[N];

int dfs(int node,int p) {
  int ret = 0;
  int sz = adj[node].size(),ch;
  int sum = 0;// matched
  //one unmatch  + match
  int maxi = -2;
  for(int i=0;i<sz;++i) {
    ch = adj[node][i];
    if(ch!=p) {
      dfs(ch,node);
      sum += dp[ch][1];
      maxi = max(maxi,-dp[ch][1] +dp[ch][0]);
    }
  }
  dp[node][0] = sum;
  dp[node][1] = sum + maxi + 1;
  return max(dp[node][0],dp[node][1]);
}
void solve() {
  int n;
  scanf("%d",&n);

  if(n%2==1) {
    printf("First\n");
    return;
  }
  for(int i=0;i<n-1;++i) {
    int a,b;scanf("%d %d",&a,&b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  int R = dfs(1,0);
  if(R*2 == n) {
    printf("Second\n");
  } else {
    printf("First\n");
  }
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


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

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

    string answer = "No";
    for (int i = 1; i <= 9; i++)
    {
        if ((n % i == 0) & (n / i <= 9))
        {
            answer = "Yes";
            break;
        }
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
let read_lines () =
  let rec iter xs =
    try read_line() :: xs |> iter
    with End_of_file -> xs
  in iter [] |> List.rev

let split_nums str =
  Str.split (Str.regexp " ") str
  |> List.map float_of_string

let solve_se = function
    | [a; b; c; d; e; f] ->
       let x = (e*.c -. b*.f) /. (e*.a -. b*.d) in
       let y = (c -. a*.x) /. b in
       (x, y)
    | _ -> raise (Invalid_argument "line should be 6 nums.")

let print_answer (x, y) =
  let fmt x =
    let s = Printf.sprintf "%.3f" x in
    if s = "-0.000" then "0.000"
    else s
  in
  Printf.printf "%s %s\n" (fmt x) (fmt y)

let () =
  read_lines ()
  |> List.map split_nums
  |> List.map solve_se
  |> List.iter print_answer

Measured memory_bytes: 2300
import sys


def like2017(N):

    D = [True] * (N + 1)
    L = [0] * (N + 1)

    D[0] = False
    D[1] = False

    for n in range(2, N + 1):
        if not D[n]:
            continue

        for k in range(2, N // n + 1):
            D[k * n] = False

    cnt = 0
    for n in range(1, N + 1):
        if D[n] and D[(n + 1) // 2] and n % 2 == 1:
            cnt += 1
        L[n] = cnt

    return L


def main():
    Q = int(sys.stdin.readline().rstrip())  # クエリ数

    L = like2017(10**5)

    for _ in range(Q):
        l, r = map(int, sys.stdin.readline().rstrip().split())
        print(L[r] - L[l - 1])


main()



Measured memory_bytes: 10336
def gcd(a, b):
    if (b == 0):
        return a
    else:
        return gcd(b, a % b)


def divisor(n):
    l = []
    i = 1
    while True:
        if n % i == 0:
            l.append(i)
            if i * i != n:
                l.append(n / i)
        i += 1
        if i * i >= n:
            break
    return sorted(l)


n = int(input())
a = list(map(int, input().split()))

gcd_of_all = gcd(a[0], a[1])
for i in range(2, n):
    gcd_of_all = gcd(gcd_of_all, a[i])

if gcd_of_all != 1:
    print("not coprime")
    exit()

s = set()

for i in range(n):
    l = divisor(a[i])
    for j in range(len(l)):
        if l[j] == 1:
            continue
        if l[j] in s:
            print("setwise coprime")
            exit()
        else:
            s.add(l[j])

print("pairwise coprime")


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

/*
 * ax+by=c, dx+ey=f ツづーツ嘉ーツつュツ。
 * ツ姪淞づィツ値ツつェ0ツづ按づァツ青ャツ古キツ、1ツづ個湘ェツ債づ溝e-bdツつェEPSツ暗按可コツづ可づ按づづつ「ツづ古ォツ債キツ妥・ツつォツつ「ツ。
 */
int solve_linear_equations( double a, double b, double c, 
  double d, double e, double f, double& x, double& y )
{
  double EPS = 1e-9;
  double delta = a*e-b*d;
  x = 0.0;
  y = 0.0;
  if( (delta < 0 && -delta < EPS) || (delta >=0 && delta < EPS) ) return 1;
  x = ((c*e-b*f) / delta) + 0.0;
  y = ((a*f-c*d) / delta) + 0.0;
  return 0;
}

int main( void )
{
  int n;
  double x1,y1,x2,y2,x3,y3;
  cin >> n;
  for( int i=0; i<n; i++ ){
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double a,b,c,d,e,f,x,y,r;
    a = 2*(x1-x2);
    b = 2*(y1-y2);
    c = x1*x1+y1*y1-x2*x2-y2*y2;
    d = 2*(x1-x3);
    e = 2*(y1-y3);
    f = x1*x1+y1*y1-x3*x3-y3*y3;
    solve_linear_equations( a,b,c,d,e,f,x,y );
    r = sqrt(x1*x1-2*x1*x+x*x+y1*y1-2*y1*y+y*y);
    printf( "%.3lf %.3lf %.3lf\n",x,y,r );
  }
  return 0;
}

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

int main(){
    int n,m,k;
    cin >> n >> m >> k;
    vector<vector<int>> fld(n+1), blk(n+1);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        fld.at(a).push_back(b);
        fld.at(b).push_back(a);
    }
    rep(i,k){
        int a,b;
        cin >> a >> b;
        blk.at(a).push_back(b);
        blk.at(b).push_back(a);
    }
    
    if(debug){
        rep(i,n){
            cout << i+1 << ":" << endl;
            cout << " friends:";
            rep(j,fld.at(i+1).size()){
                cout << fld.at(i+1).at(j) << " ";
            }
            cout << endl;

            cout << " blocks:";
            rep(j,blk.at(i+1).size()){
                cout << blk.at(i+1).at(j) << " ";
            }
            cout << endl;
        }
        cout << "end input" << endl;
    }

    vector<int> grp(n+1);
    int grpno = 1;
    for(int i=1;i<=n;i++) {
        if(grp.at(i) > 0){
            continue;
        }
        queue<int> q;
        q.push(i);
        while(!q.empty()){
            int x = q.front();
            q.pop();
            if(grp.at(x) > 0) continue;
            grp.at(x) = grpno;
            // cout << "i:" << i << " x:" << x << endl;
            rep(j,fld.at(x).size()){
                int y = fld.at(x).at(j);
                if(grp.at(y) == 0){
                    // cout << "add:" << y << endl;
                    q.push(y);
                }
            }
        }
        grpno++;
    }

    if(debug){
        rep(i,n) cout << grp.at(i+1) << " ";
        cout << endl;
    }

    // グループごとの連結数を保存
    vector<int> grpcnt(grpno+1);
    rep(i,n){
        grpcnt.at(grp.at(i+1))++;
    }

    for(int i=1;i<=n;i++){
        if(i > 1) cout << " ";
        int a = grpcnt.at(grp.at(i));
        int b = fld.at(i).size();
        int c = 0;
        for(int bl : blk.at(i)){
            if(grp.at(i) == grp.at(bl)) c++;
        }
        int res = a - b - c - 1;
        cout << res;
    }
    cout << endl;
    // rep(i,n){
    //     cout << grp.at(i+1) << " ";
    // }
    // cout << endl;

    return 0;
}

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

int main(){
    int k, x;
    cin >> k >>x;
    if(500*k>=x){
        cout << "Yes" << endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3600
main(i){int s[9000],n,m,t,f;while(scanf("%d%d",&n,&m),i=0,t=f=1,n)while(i++<n+m)if(scanf("%d",&s[i]),i>n)if(t+=s[t+=s[i]],f==t>=n)printf("%d\n",i-n,f=0);}

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

int main() {
  int N, T;
  cin >> N >> T;
  int t[N];
  int ans = T;
  rep(i, N) cin >> t[i];
  rep(i, N - 1) { t[i + 1] - t[i] <= T ? ans += t[i + 1] - t[i] : ans += T; }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
n = gets.to_i
cities = Array.new
n.times do
  cities << gets.split.map(&:to_i)
end
sum = Array.new
cities.permutation(n).each do |p|
  current_pos = p.shift
  tmp = 0
  p.each do |next_pos|
    tmp += Math.sqrt((current_pos[0] - next_pos[0]) ** 2 + (current_pos[1] - next_pos[1]) ** 2)
    current_pos = next_pos
  end
  sum << tmp
end
puts sum.inject(:+) / sum.length


Measured memory_bytes: 2684
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	ll x, k, d;
	cin >> x >> k >> d;
	
	x = abs(x);
	ll m = x / d;
	
	if( m < k ) {
		x -= m * d;
		k -= m;
		
		if( k % 2 == 0 ) {
			cout << x << endl;
		} else {
			cout << d - x << endl;
		}
	} else {
		cout << x - k * d << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include<vector>
#include<string>
#include <numeric>
#include <utility>
#include<math.h>
#include<functional>
#include<queue>
#include<sstream>
#include<stack>
#include<algorithm>

int solve(int N){
    int ct=0;
    for(int i=N;i>0;i--)ct+=i;
    std::cout<<ct;
    return 0;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int N;
    std::cin>>N;
    return solve(N);
}


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

int main(){
    long long n, k;
    cin >> n >> k;
    long long sum = 0;
    for(long long i = k; i <= n+1; i++){
        long long min = i * (i-1) / 2;
        long long max = n * i - min;
        sum += max - min + 1;
    }
    sum %= 1000000007;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
path = Array.new(3).map{Array.new(2, 0)}
path[0] = gets.split.map(&:to_i)
path[1] = gets.split.map(&:to_i)
path[2] = gets.split.map(&:to_i)
ans = Array.new(4, 0)
for i in 0..2
  for j in 0..1
    if path[i][j] == 1
      ans[0] += 1
    elsif path[i][j] == 2
      ans[1] += 1
    elsif path[i][j] == 3
      ans[2] += 1
    else
      ans[3] +- 1
    end
  end
end
ans.sort!
if ans[1] == 1 && ans[2] == 2
  puts "YES"
else
  puts "NO"
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

bool can_survive(int i, vec &A){
    int size = A[i];
    REP(j, A.size()){
        if(j == i) continue;
        if(2 * size < A[j]) return false;
        size += A[j];
    }
    return true;
}

signed main(){

    int N; cin >> N;
    vec A(N); readvec(A);

    SORT(A);
    int i1 = -1, i2 = N - 1;
    while(i2 - i1 > 1){
        int i = (i1 + i2) / 2 + (i1 + i2) % 2;
        if(can_survive(i, A)){
            i2 = i;
        }else{
            i1 = i;
        }
    }

    cout << N - i2;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void debugF(ostream &os) {os << endl;}
template <typename Head, typename... Tail>
void debugF(ostream &os, Head H, Tail... T) { os << " " << H; debugF(os, T...); }
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debugF(cout, __VA_ARGS__)
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); os << (i>0 ? " ":"") << v[i++]); return os;}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t, i;
    cin >> n >> t;
    //x + y = n
    //2x + 4y = t
    for(i=0;i<=n;i++){
        int j = n-i;
        if((i + j == n) && (2*i + 4*j == t)) break;
    }

    if(i <= n){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3656
#include <stdio.h>

int main(void)
{
  char a[256] = {['a'] = 1, ['i'] = 1, ['u'] = 1, ['e'] = 1, ['o'] = 1};
  char c;
  scanf("%c", &c);
  puts(a[c] ? "vowel" : "consonant");
}


Measured memory_bytes: 128
S = input()
T = input()

ans = 'UNRESTORABLE'

for i in range(len(S)-len(T)+1):
    flag = True
    # if S[i] == T[0]:
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            flag = False

    if flag:
        ans = []
        for j in range(len(S)): ans.append(S[j])
        for j in range(len(T)): ans[i+j] = T[j]
        for j in range(len(S)):
            if ans[j] == '?': ans[j] = 'a'
            
for i in range(len(ans)):
    print(ans[i], end='')
print()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string S; int w; cin >> S >> w;
  for (int i = 0; i < S.size(); i+=w) {
    cout << S[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<int> VEC;
typedef vector<VEC> VVEC;


const LL INF=1<<30;
const LL MOD=1000000007;

LL gcd(LL a,LL b){
    if(b==0)return a;

    return gcd(b,a%b);
}

LL kaijo(LL n){
    LL ans=1;
    for(LL i=1;i<=n;++i){
        (ans*=i)%=MOD;
    }
    return ans;
}


int main(){
    int h,w;
    cin>>h>>w;
    int n;
    cin>>n;
    VEC a(n);
    VVEC ans(h,VEC(w));
    for(int i=1;i<=n;++i){
        cin>>a[i];
    }
    
    //sort(a.begin(),a.end(),greater<LL>());
    int k=1;
    for(int i=0;i<h;i++){
        if(i%2==0){
            for(int j=0;j<w;++j){
                ans[i][j]=k;
                a[k]--;
                if(a[k]==0)k++;
            }

        }else{
                for(int j=w-1;j>=0;--j){
                ans[i][j]=k;
                a[k]--;
                if(a[k]==0)k++;
            }

        }
    }
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            cout<<ans[i][j]<<" ";
        }
        cout<<"\n";
    }
    cout<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
using namespace std;
int main(void){
    
    int X, Y;
    cin >> X >> Y;
    
    for(int turu = 0; turu <= X; turu++){
        int kame = X - turu;
        int asi = (2 * turu) + (4 * kame);
        if(asi == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    
    cout << "No" << endl;
}


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

int main() {
    int n;
    int d[100000];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> d[i];

    sort(d, d + n);
    cout << d[n / 2] - d[n / 2 - 1] << endl;
}


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

using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0};
const int INF = 1e9+101;
const long long LINF = 1e18;
const double EPS = 1e-8;
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
template<class T>
ostream& operator<<(ostream &out, const vector<T> &v){
	out << "{";
	rep(i,v.size()){
		out << v[i] <<", ";
	}
	return out << "}" << endl;
}
Pll rc[128];
ll memo[128][128];
// [left, right)
ll solve(int left, int right) {
    if(memo[left][right] != -1) return memo[left][right];
    if (right - left <= 1) {
        return memo[left][right] = 0;
    }
    ll mn = LINF;
    reps(i, left+1, right) {
        ll cost = rc[left].first*rc[i-1].second*rc[right-1].second;
        mn = min(mn, solve(left, i) + solve(i, right) + cost);
    }
    return memo[left][right] = mn;
}
int main() {
    memset(memo,-1,sizeof(memo));
    int N;
    cin >> N;
    rep(i,N){
        int r,c;
        cin >> r >> c;
        rc[i] = mk(r,c);
    }
    cout << solve(0, N) << endl;
    return 0;  
}


Measured memory_bytes: 3224
/**
 *
 * AtCoder Beginner Contest 108 - Problema B: Ruined Square (https://beta.atcoder.jp/contests/abc108/tasks/abc108_b)
 *
 * Find the number of pairs (a, b) such as 1 <= a, b <= K, a is even, b is odd.
 *
 * Math solution: there is K/2 even numbers and (K + 1)/2 odd numbers in [1, K]. The answer is
 * (K/2)*[(K + 1)/2].
 */
#include <iostream>

#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define REP(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)

#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : (vec)) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }
#define LOGA2(arr, N, M, sep) { cerr << #arr << " =\n"; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) cerr << (arr)[i][j] << " "; cerr << endl; } cerr << (sep); }

ostream& operator<<(ostream& os, const ii& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

const int MAX { 2000010 };
const ll oo { 1LL << 62 };
const int MOD { 1000000007 };

ii rotate90(const ii& v)
{
    return ii(-v.second, v.first);
}

void solve(int x1, int y1, int x2, int y2)
{
    auto v = ii(x2 - x1, y2 - y1);

    auto u = rotate90(v);
    auto P3 = ii(x2 + u.first, y2 + u.second);

    u = rotate90(u);

    auto P4 = ii(P3.first + u.first, P3.second + u.second);

    cout << P3.first << " " << P3.second << " " << P4.first << " " << P4.second << endl;
}

int main()
{
    ios::sync_with_stdio(false);

    int x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    solve(x1, y1, x2, y2);

    return 0;
}

Measured memory_bytes: 256