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

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

using namespace std;

//inline int read(){int t = 0;int neg=1;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1;continue;}t=t*10+c-48;}return neg*t;}
//inline int readl(){long long t = 0;long long neg=1ll;char c;while((c=getchar_unlocked())!='\n'&&c!=' '&&c!=EOF){if(c=='-'){neg=-1ll;continue;}t=t*10+c-48;}return neg*t;}

#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';

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<pi> vpi;
typedef vector<plli> vplli;
const lli M=1000000007ll;

int main(){
	fast_io 
	string s;
	int a,b;
	cin>>a>>s>>b;
	if(s=="+") cout<<(a+b);
	else cout<<(a-b);
	
	return 0;
}

Measured memory_bytes: 256
lst = input().split(" ")
A =lst[0]
B =lst[1]
if A == "H" and B == "H":
	print("H")
elif A == "D" and B == "H":	
	print("D")
elif A == "D" and B == "D":		
	print("H")
elif A == "H" and B == "D":		
	print("D")	

Measured memory_bytes: 2940
n = int(input())
T = []
graph = [[] for i in range(n)]
for i in range(n):
    s = input()
    for j in range(n):
        if s[j] == '1':
            graph[j].append(i)
color = [-1]*n
color[0] = 0
stack = [0]
flag = True
while len(stack) != 0:
    t = stack.pop()
    for i in range(len(graph[t])):
        cur = graph[t][i]
        if color[cur] == -1:
            if color[t] == 1:
                color[cur] = 0
            else:
                color[cur] = 1
            stack.append(cur)
        else:
            if color[t] != color[cur]:
                None
            else:
                flag = False
                break
    if not flag:
        break
ans = 0
if not flag:
    print(-1)
else:
    dist = [[10**5]*n for i in range(n)]
    for i in range(n):
        dist[i][i] = 0
    for i in range(n):
        for j in range(len(graph[i])):
            dist[i][graph[i][j]] = 1
            dist[graph[i][j]][i] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
    for i in range(n):
        for j in range(n):
            ans = max(ans, dist[i][j]+1)
    print(ans)


Measured memory_bytes: 43356
N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))

from itertools import permutations
from math import factorial

X=[i+1 for i in range(N)]
X_list = list(permutations(X))

P=tuple(P)
Q=tuple(Q)

ans=[0,0]
for j in range(factorial(N)):
    if X_list[j]==P:
        ans[0] = j
        break
for k in range(factorial(N)):
    if X_list[k]==Q:
        ans[1] = k
        break
print(abs(ans[0]-ans[1]))


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

int n,W;
int weight[110],value[110];
int dp[110][10010];

int main(){
    cin >> n >> W;
    for(int i=0;i<n;i++)    cin >> value[i] >> weight[i];
    for(int w=0;w<=W;w++)   dp[0][w]=0;
    for(int i=0;i<n;i++){
        for(int w=0;w<=W;w++){
            if(w>=weight[i]) dp[i+1][w] = max(dp[i][w-weight[i]]+value[i],dp[i][w]);
            else    dp[i+1][w] = dp[i][w];
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}


Measured memory_bytes: 6968
from collections import deque


n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
MOD = 998244353

info = [(10**10, 10 ** 10)] + sorted(info, reverse=True)
dp = [0] * (n + 1)
dp[0] = 1

q = deque([])
for i in range(n):
    if sum(info[i + 1]) <= info[i][0]:
        # 抜かさないとき
        dp[i + 1] = 2 * dp[i]
        dp[i + 1] %= MOD
        q.append((i, info[i]))
    else:
        # 抜かすとき
        if sum(info[i + 1]) <= q[-1][1][0]:
            dp[i + 1] = dp[i] + dp[q[-1][0]]
            dp[i + 1] %= MOD
        else:
            while q:
                q.pop()
                if sum(info[i + 1]) <= q[-1][1][0]:
                    dp[i + 1] = dp[i] + dp[q[-1][0]]
                    dp[i + 1] %= MOD
                    break
print(dp[-1] % MOD)

Measured memory_bytes: 90400
from collections import defaultdict
N = int(input())
A = list(map(int,input().split()))
sm = 0
d = defaultdict(int)
for a in A:
    d[a] += 1
    sm += a
Q = int(input())
for _ in range(Q):
    b,c = map(int,input().split())
    sm += d[b]*(c-b)
    d[c] += d[b]
    d[b] = 0
    print(sm)

Measured memory_bytes: 24088
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

const n,k=parseMap(split(readline()))
const a=sort(parseMap(split(readline())))
function f(x,y)
    res=0
    for i in a
        res+=ceil(Int,i/x)-1
    end
    return isless(y,res)
end
println(searchsortedfirst(1:a[end],k;lt=f))

Measured memory_bytes: 196856
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int k; cin>>k;
    int res =7;
    rep(i,k+100){
        res%=k;
        if(res==0){
            cout<<i+1<<endl;
            return 0;
        }
        res*=10; res+=7;
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 3572
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s, t;
	cin >> s >> t;
	int ans = 1e9;
	rep(i, s.size() - t.size() + 1){
		string cur = s.substr(i, (int)t.size());
		int nw = 0;
		rep(j, cur.size()) if(t[j] != cur[j]) nw++;
		ans = min(ans, nw);
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3636
def popcount(num):
    ans = 0
    while num:
        if num % 2 == 1:
            ans += 1
        num //= 2
    return ans


N = int(input())
X = input()

popcount_X = 0
for x in X:
    if x == "1":
        popcount_X += 1

tmp4p = int(X, 2) % (popcount_X+1)
if popcount_X != 1:
    tmp4m = int(X, 2) % (popcount_X-1)

for i in range(N):
    bit = X[i]

    f = 0
    if (popcount_X == 1 and bit == "1"):
        print(f)
        continue
    
    if bit == "1":
        nxt = ( tmp4m - pow(2, N-i-1, (popcount_X-1))  + (popcount_X-1) ) % (popcount_X-1)
    else:
        nxt = ( tmp4p + pow(2, N-i-1, (popcount_X+1))  ) % (popcount_X+1)

    f += 1
    while nxt:
        pc = popcount(nxt)
        nxt = nxt % pc
        f += 1
    
    print(f)


Measured memory_bytes: 9364
#include <utility>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <list>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    int ret = H * W;
    ret -= h * W;
    ret -= abs(H - h) * w;
    cout << ret << endl;
}

void cheatsheet()
{
    // loop
    // vector<int> vec(10);
    vector<int> vecloop;
    REP(i, 10)
    {
        vecloop.push_back(i);
    }

    // swap
    int a = 1;
    int b = 5;
    swap(a, b); // -> a = 5, b = 1

    // sort
    int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    sort(arr, arr + 9, greater<int>()); // 9 8 7 6 5 4 3 2 1

    // lower
    vector<int> vec(arr, end(arr));
    sort(vec.begin(), vec.end());
    cout << lower_bound(vec.begin(), vec.end(), 2)[0]; // 2

    // map
    map<Pll, ll> m;
    m[Pll(10, 100)] = 100;
}

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

using namespace std;

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

    vector<int> l(n);
    for (int i=0; i<n; i++){
        cin >> l.at(i);
    }
    int d = 0;
    int bound = 1;

    for (int i=0; i<n; i++){
        d += l.at(i);
        if (d <= x) {
            bound += 1;
        }
    }
    cout << bound << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int 
main(){
	int p[20];
	int a,b;
	int i;
	scanf("%d%d",&a,&b);
	
	if(a>b){
		for(i=0;i<a;i++)
		printf("%d",b);
	}
	else{
		for(i=0;i<b;i++)
		printf("%d",a);
	}
	

	printf("\n");
		
	
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    string t=s;
    int a=s.length();
    reverse(s.begin(),s.end());
    for(int i=0;i<=a;i++)
    {
    if(s[i]=='b') s[i]='d';
	else if(s[i]=='d') s[i]='b';
	else if(s[i]=='q') s[i]='p';
	else if(s[i]=='p') s[i]='q';
    }
    if(s==t) cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i )
typedef std::pair<int,int> pint;

using namespace std;
typedef long long ll;

int main(){
    int N; cin >> N;
    vector<int> list(N);
    rep(i,N) cin >> list[i];
    int max = list[0];
    ll count = 0;
    rep(i,N){
        if (list[i] < max){
            count += max - list[i];
        }
        else{
            max = list[i];
        }
    }
    cout << count << endl;
    return 0;
}

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

int main() {
  int h1,m1,h2,m2,k;
  int hm1,hm2;  
  int kisyo;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  
  hm1 = h1 * 60 + m1;
  hm2 = h2 * 60 + m2;
  kisyo = abs(hm1 - hm2);
  
  cout << max(0,kisyo - k);
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    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;
}


int main(void)
{
    unsigned long long h,w;
    cin >> h >> w;

    if(min(h,w) == 1){
        cout << 1 << endl;
    }
    else if(h % 2 == 0){
        cout << (h / 2) * w << endl;
    }
    else if(w % 2 == 0){
        
        cout << (w / 2) * h << endl;
    }
    else {
        unsigned long long mw = w / 2 + 1;
        unsigned long long lw = w/2;
        cout << (mw + lw) * (h / 2) + mw << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;

bool prime_number_check(long long N) {
    for (long long i = 2; i * i <= N; i++) {
        if (N % i == 0)
            return false;
    }
    return true;
}

int main() {
    ll M = 100000;

    vector<int> cnt(M+1, 0);    //cnt[i]は1からiまでの2017に似た数の個数

    for (int i = 3; i <= M; i += 2) {
        if (prime_number_check(i) && prime_number_check((i+1)/2))
            cnt[i] = cnt[i-2] + 1;
        else 
            cnt[i] = cnt[i-2];
    }

    int q;  cin >> q;

    for (int i = 0; i < q; i++) {
        int l, r;   cin >> l >> r;
        if (l == 1)
            cout << cnt[r] << endl;
        else 
            cout << cnt[r] - cnt[l-2] << endl;
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long a, b, c;
    int A = 0, B = 0, C = 0;
    long D = 50;
    cin >> a;
    cin >> b >> c;
    long i=0;
    vector <long> e(a);

    for (int i = 0; i < a; i++) {
    cin >> e.at(i);
    }
    
    for (i = 0; i < a; ++i){
        if (e[i]<=b){
            ++A;
        }
        else if (e[i]>b and e[i] <= c){
            ++B;
        }
        C = a - A - B;
    }
    

    if (D>A){
        D = A;
    }
    if (D>B){
        D = B;
    }
    if (D > C){
        D = C;
    }
    
    cout << D;
    
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def fn(n):
    if n % 2 == 0:
        return n // 2
    else:
        return 3*n + 1


def main():
    """Function."""
    s = int(input())

    check_dic = {}
    check = set()

    old = s
    counter = 1

    while old not in check:
        # print(old,counter)
        check.add(old)
        check_dic[old] = counter

        counter += 1
        old = fn(old)

    # print("!!!!!!!!!!!")
    print(counter)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define inputv(arr,n) for(ll i=0;i<n;i++){ll value;cin>>value;arr.pb(value);}
#define sz(a) ((ll)(a).size())
#define len(a) ((ll)(a).length())
#define precise cout<<fixed<<setprecision(0); 
#define F first
#define S second
#define vi vector <int> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define YES cout<<"Yes\n"
#define NO cout<<"No\n"
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll gcd(ll a ,ll b)
{if(b==0) return a;a%=b;return gcd(b,a);}
#define nl cout<<"\n"
using namespace std;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
// hashing for pairs
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
  }
};
//sort in reverse order
bool compare(ll x, ll y){
    return x>y;
}
void solve()
{
  ll n;
  cin>>n;
  vl arr;
  inputv(arr,n);
  ll ans=0;
  rep(i,n-1)
  {
    if(arr[i+1]<arr[i])
    {
      ans+=(arr[i]-arr[i+1]);
      arr[i+1]=arr[i];
      
    }
  }
  cout<<ans;nl;
  return;
}
int main()
{
    IOS;
    int T=1;
   // cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 5264
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto data = readln.split, N = data[0].to!long, M = data[1].to!long;
	auto A = readln.split.to!(long[]);
	
	long sum = 0;
	long[long] hash; hash[0] = 1;
	foreach (i; 0 .. N) {
		sum += A[i] % M;
		if (sum >= M) sum -= M; 
		if (sum !in hash) hash[sum] = 1;
		else hash[sum]++;
	}
	
	ulong ans;
	foreach (n; hash.byValue) {
		ans += n*(n-1)/2;
	}
	writeln(ans);
}

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

int match[] = {0,2,5,5,4,5,6,3,7,6};

void chmax(string &s, string t){
  if( s == "N"){ s = t;}
  else{
    if( t.size() > s.size()){ s = t;}
    else{
      s = max(s,t);}
  }
}
string dp[10100];
int main(){
int N,M; cin >> N >> M;
  vector<char> A(M); for(int i = 0; i < M; i++){ cin >> A[i];}
  
  for(int i = 0; i < 10100; i++){ dp[i] = "N";} // Nは不可能を表す
  dp[0] = "";
  for(int i = 0; i < 10010; i++){
    for(int j = 0; j < M; j++){
      if( dp[i] == "N"){ continue;}
      
      chmax( dp[i+match[A[j]-'0']], dp[i]+A[j]);}}
  
  cout << dp[N] << endl; return 0;}
  
  

Measured memory_bytes: 46336
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
s = gets.chomp.to_i


def f(n)
  if n.even?
    ret = n/2
  else
    ret = 3 * n + 1
  end
end

i = 1
pre = s
cache = {}
set = Set.new
set.add s
while true
  ret = f(pre)
  # p [i, pre, ret, set]
  if set.include? ret
    puts i + 1
    exit
  end
  set.add ret
  pre = ret
  i+=1
end

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2> void add( T1 &x, T2 y, ll m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2> void sub( T1 &x, T2 y, ll m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

vector<vector<int>> generate( int n, int mn, int mx )
{
    vector<vector<int>>ans;
    if( n == 0 )
    {
        return {{}};
    }
    for(int x=mn;x<=mx;x++)
    {
        vector<vector<int>>temp = generate(n-1,mn,x);
        for( auto v : temp )
        {
            vector<int>tt = v;
            tt.pb(x);
            ans.pb(tt);
        }
    }
    return ans;
}

int main() 
{
    fastio();

    int n,m,q;
    cin>>n>>m>>q;

    vector<array<int,4>>v(q);
    for(int i=0;i<q;i++)
    {
        for(int j=0;j<4;j++)
            cin>>v[i][j];
    }

    vector<vector<int>>all = generate(n,1,m);

    ll ans = 0;
    for( auto now : all )
    {
        ll tans = 0;
        for(int i=0;i<q;i++)
        {
            int a = v[i][0], b = v[i][1], gap = v[i][2], profit = v[i][3];
            if( now[b-1] - now[a-1] == gap )
                tans += profit;
        }
        ans = max( ans, tans );
    }
    cout<<ans,nl;


    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


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

int main() {
  int q; cin >> q;
  map<string, int> mp;
  for (int i = 0; i < q; i++) {
    int cmd; cin >> cmd;
    if (cmd == 0) {
      string key; int x; cin >> key >> x;
      mp[key] = x;
    }
    if (cmd == 1) {
      string key; cin >> key;
      auto itr = mp.find(key);
      if (itr != mp.end()) {
        cout << mp[key] << endl;
      } else {
        cout << 0 << endl;
      }
    }
    if (cmd == 2) {
      string key; cin >> key;
      mp.erase(key);
    }
    if (cmd == 3) {
      string l, r; cin >> l >> r;
      for (auto itr = mp.lower_bound(l), end = mp.upper_bound(r); itr != end; itr++) {
        cout << itr -> first << " " << itr -> second << endl;
      }
    }
  }
}



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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> v(n+1,-1);
	int l=0;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		if(v[l] < a){
			v[l+1]=a;
			l++;
		} else {
			*lower_bound(v.begin(),v.begin() + l,a) = a;
		}
	}
	cout << l << endl;
	
	return 0;
}

Measured memory_bytes: 3136
a, b, c, d = map(int, input().split())
num = int(input())
 
if num % 2 == 0:
    Min = min(num*a*4, num*b*2, num*c, num//2*d)
else:
    Min = min((num-1)*a*4, (num-1)*b*2, (num-1)*c, num//2*d) + min(4*a, 2*b, c)
print(Min)

Measured memory_bytes: 9192
fn main() {
    let scan = std::io::stdin();
    
    let mut line = String::new();
    
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    
    let x0: f64 = vec[0].parse().unwrap_or(0.0);
    let y0: f64 = vec[1].parse().unwrap_or(0.0);
    let x1: f64 = vec[2].parse().unwrap_or(0.0);
    let y1: f64 = vec[3].parse().unwrap_or(0.0);

    let d: f64 = ((x0 - x1).powi(2) + (y0 - y1).powi(2)).powf(0.5);
    println!("{}", d);
}



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

int main(){
    int X, N;
    std::cin >> X >> N;
    std::vector< int > A(N);
    for(int i=0; i<N; i++){
        std::cin >> A[i];
    }

    bool find = false;

    for(int i=0; i<N; i++){
        if(A[i] == X){
            find = true;
        }
    }
    if(!find){
        std::cout << X << std::endl;
        return 0;
    }

    int cnt = 1;
    while(1){
        find = false;
        for(int i=0; i<N; i++){
            if(A[i] == X - cnt){
                find = true;
            }
        }
        if(!find){
            std::cout << X - cnt << std::endl;
            return 0;
        }
        find = false;
        for(int i=0; i<N; i++){
            if(A[i] == X + cnt){
                find = true;
            }
        }
        if(!find){
            std::cout << X + cnt << std::endl;
            return 0;
        }
        cnt++;
    }
    
    return 0;
}



Measured memory_bytes: 3636
import Foundation
func isValid(s: String, start: Int, end: Int) -> Bool {
  if start > end {
    return false
  }
  var left = start
  var right = end
  let S = s.characters.map { String($0) }
  while left < right {
    if S[left] != S[right] {
    	return false
    }
    left += 1
    right -= 1
  }
  return true
}
let str = String(readLine()!)
let count = str.characters.count
let isStrong = isValid(str, start: 0, end: (count - 1) / 2 - 1) && 
			   isValid(str, start: 0, end: count - 1) &&
               isValid(str, start: (count + 3) / 2 - 1, end: str.characters.count - 1)

print(isStrong ? "Yes" : "No")

Measured memory_bytes: 6760
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
	long int i, j;
	long int h, a;
	long int count = 0;
	
	scanf("%ld%ld", &h, &a);
	
	while(h > 0) {
		count++;
		h -= a;
	}
	
	printf("%ld\n", count);
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define INT long long int
#define oo 987654321
#define MOD 1000000007
using namespace std;
INT n, m;
vector<INT> G[110];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    if( n%2 == 0 )
    {
        for(int i = 1 ; i <= n ; i++ )
        {
            for(int j = i+1 ; j <= n ; j++ )
            {
                if( i+j == 1+n ) continue;
                G[i].push_back(j), m++;
            }
        }
    }
    else
    {
        for(int i = 1 ; i < n ; i++ ) G[n].push_back(i), m++;
        for(int i = 1 ; i <= n-1 ; i++ )
        {
            for(int j = i+1 ; j <= n-1 ; j++ )
            {
                if( i+j == n ) continue;
                G[i].push_back(j), m++;
            }
        }
    }
    cout<<m<<endl;
    for(int i = 1 ; i <= n ; i++ )
        for(INT x : G[i] ) cout<<i<<" "<<x<<endl;
    return 0;
}


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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int n,l;
	cin >> n >> l;
	vector<string> s;
	for(int i = 0; i < n; i++){
		string a;
		cin >> a;
		pb(s,a);
	}
	sort(ben(s));
	for(int i = 0; i < n; i++){
		cout << s[i];
	}
	cout << endl;
	return 0; 
}

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

ll cnt[214514],a[214514];

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

	for(int i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=cnt[i]*(cnt[i]-1)/2;
	}
	for(int i=0;i<n;i++){
		cout<<ans-cnt[a[i]]*(cnt[a[i]]-1)/2+(cnt[a[i]]-1)*(cnt[a[i]]-2)/2<<endl;
	}
	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using Int = int64_t;
using UInt = uint64_t;
using C = std::complex<double>;
#define rep(i, n) for(Int i = 0; i < (Int)(n); ++i)
#define guard(x) if( not (x) ) continue;

struct DisjointSet {
   DisjointSet(Int n)
      : ps(n, -1), ns(n, 1) {}
   std::vector<Int> ps, ns;
   Int find(Int x) {
      while( ps[x] != -1 ) x = ps[x];
      return x;
   }
   void unite(Int x, Int y) {
      x = find(x), y = find(y);
      if( x != y ) {
         if( not ( ns[x] <= ns[y] ) ) std::swap(x, y);
         ps[x] = y;
         ns[y] += ns[x];
      }
   }
};

int main() {
   Int v, e;
   std::cin >> v >> e;
   std::vector<Int> ss(e), ts(e), ws(e);
   rep(i, e) std::cin >> ss[i] >> ts[i] >> ws[i];
   std::vector<std::pair<Int, Int>> xs;
   rep(i, e) xs.emplace_back(ws[i], i);
   std::sort(xs.begin(), xs.end());
   DisjointSet z(v);
   Int res = 0;
   rep(i, e) {
      Int k = xs[i].second;
      Int s = ss[k], t = ts[k];
      guard( z.find(s) != z.find(t) );
      z.unite(s, t);
      res += ws[k];
   }
   printf("%ld\n", res);
}

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



int main(){
	int n;
	int res = 0;
	cin >> n;
	int A[2*n];
	for (int k = 0; k< 2*n;k++){
		cin >> A[k];
	}

	sort(A,A+2*n);

	for (int k=0;k<2*n;k+=2){
		if (A[k]<A[k+1]){
			res += A[k];
		}
		else{
			res += A[k+1];
		}
	}
	cout << res << endl;

	return 0;
}

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

int main(){
	int n,x,c=0;
	while(cin >> n >> x,(n || x)){
		c=0;
		for(int i=1;i<=n-1;i++){
			for(int j=i+1;j<=n;j++){
				for(int k=j+1;k<=n;k++){
					if(i+j+k==x) c++;
				}
			}
		}
		cout << c << endl;
	}
		return 0;
}

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

int n, c[13], d[25];

int f(int x){
    if(x == 12){
        int r = 24;
        for(int i = 0; i < 24; i++){
            for(int j = i + 1; j < 24; j++){
                if(d[i] && d[j]) r = min(r, min(j - i, 24 + i - j));
            }
        }
        return r;
    }
    if(~c[x] & 1) return f(x + 1);
    d[x]++;
    int r = f(x + 1);
    d[x]--;
    d[24 - x]++;
    r = max(r, f(x + 1));
    d[24 - x]--;
    return r;
}

int main(){
    scanf("%d", &n);
    d[0] = 1;
    for(int i = 0, x; i < n; i++){
        scanf("%d", &x);
        c[x]++;
        if(x == 0 || c[x] > 2 || (x == 12 && c[x] > 1)){ puts("0"); return 0; }
        else if(c[x] == 2){ d[x]++; d[24 - x]++; }
    }
    if(c[12]) d[12]++;
    printf("%d\n", f(1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ll long long 
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    string s;
    ll ac = 0, re = 0, wa = 0, tle = 0;
    for(int T = 0; T < t ; T++){
        cin >> s;
        if(s == "AC")
        ac++;
        else if(s == "RE")  
        re++;
        else if(s == "TLE")
        tle++;
        else 
        wa++;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back
int main() 
{ 
	int n;
	cin>>n;
	map<string,int> mp;
	while(n--)
	{
		string s;
		cin>>s;
		mp[s]++;
	}
	cout<<"AC x "<<mp["AC"]<<"\n";
	cout<<"WA x "<<mp["WA"]<<"\n";
	cout<<"TLE x "<<mp["TLE"]<<"\n";
	cout<<"RE x "<<mp["RE"];
} 

Measured memory_bytes: 3628
#include<stdio.h>

int main()
{
  int N;
  int a[101];
  int i;
  int amin,amax,b;
  scanf("%d",&N);
  scanf("%d",&a[0]);
  amin=a[0];
  amax=a[0];
  for(i=1;i<N;i++){
    scanf("%d",&a[i]);
    if(a[i]<amin) amin=a[i];
    if(a[i]>amax) amax=a[i];
  }
  b=amax-amin;
  printf("%d",b);
  return 0;
}


Measured memory_bytes: 1716
#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 k, n;
    cin >> k >> n;
    int a[n];
    rep(i, n) cin >> a[i];

    // 各家間の距離を格納
    int maxl = 0;
    rep (i, n) {
        if (i == n-1) maxl = max(maxl, a[0]+k-a[n-1]);
        else maxl = max(maxl, a[i+1]-a[i]);
    }
    cout << k - maxl << endl;
 
}

Measured memory_bytes: 1024
#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() {
    char c;
    cin>>c;
    if(isupper(c))cout<<"A"<<endl;
    else cout<<"a"<<endl;
    return 0;
}

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

struct point{
	double x, y;
};

vector<point> t(3);

bool isIn(point s) {
	point a, b, c;
	a.x = t[1].x-t[0].x; a.y = t[1].y-t[0].y;
	b.x = t[2].x-t[0].x; b.y = t[2].y-t[0].y;
	c.x = s.x-t[0].x; c.y = s.y-t[0].y;
	double c1, c2;
	c1 = (b.y*c.x - b.x*c.y) / (a.x*b.y - a.y*b.x);
	c2 = (a.y*c.x - a.x*c.y) / (a.y*b.x - a.x*b.y);
	if ((c1>0.0)&&(c2>0.0)&&(c1+c2<1.0)) return true;
	return false;
}

int main()
{
	int n, i;
	point s, g;
	cin>>n;
	for (i = 0; i < n; i++) {
		cin>>t[0].x>>t[0].y>>t[1].x>>t[1].y>>t[2].x>>t[2].y;
		cin>>s.x>>s.y>>g.x>>g.y;
		if (isIn(s)^isIn(g)) cout<<"OK"<<endl;
		else cout<<"NG"<<endl;
	}
	return 0;
}

Measured memory_bytes: 948
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let n=t.n()
  let s=t.n(n)
  let c=0;
  for(let i=0;i<n;i++){
    if(s[i] != i+1) c++
  }
  t.o(c==2||c==0?'YES':'NO')
}
main()


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define int long long
#define inf 1e18
using namespace std;
const int N=5100;
int n,dp[N][N],ans,vi[N];
struct node
{
	int h,p;
}sh[N];
bool cmp(node a,node b)
{
	return (a.h+a.p<b.h+b.p || (a.h+a.p==b.h+b.p && a.p<b.p));
}
signed main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++) scanf("%lld%lld",&sh[i].h,&sh[i].p);
	sort(sh+1,sh+1+n,cmp);
	for (int i=0;i<=n;i++)
	{
		for (int j=0;j<=n;j++) dp[i][j]=inf;
	}
	dp[0][0]=0;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			dp[i][j]=min(dp[i][j],dp[i-1][j]);
			if (dp[i-1][j-1]<=sh[i].h) dp[i][j]=min(dp[i][j],dp[i-1][j-1]+sh[i].p);
		}
	}
	for (int i=n;i>=1;i--)
	{
		if (dp[n][i]!=inf)
		{
			printf("%d\n",i);
			return 0;
		}
	}
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;


Node treeMinimum(Node x){
  return 0;

}

Node treeMaximum(Node x){
  return 0;

}

Node treeSearch(Node u, int k){
  while(u != NIL){
    if(u->key == k){
      return u;
    }else if(u->key < k){
      u = u->right;
    }else{
      u = u->left;
    }
  }
  return NIL;
}

Node treeSuccessor(Node x){
  return 0;

}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  return ;


}

void inorder(Node u){
  if(u->key == NIL) return;

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

  if(u->right != NIL){
    inorder(u->right);
  }
}

void preorder(Node u){
  if(u->key == NIL) return;

  printf(" %d",u->key);

  if(u->left != NIL){
    preorder(u->left);
  }

  if(u->right != NIL){
    preorder(u->right);
  }
}

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

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

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

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

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20500
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9+ 7;
const int INF = 2e18;

signed main() {
    string s;
    cin >> s;
    int minus = 0;
    for (int i = 1; i < s.length(); i++) {
        if (s[i] != s[i - 1]) break;
        minus++;
    }
    for (int i = s.length() - 2; i >= 0; i++) {
        if (s[i] != s[i + 1]) break;
        minus++;
    }
    cout << ((s.length() - minus + (s[0] == s[s.length() - 1])) % 2 == 0 ? "Second" : "First") << endl;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int x,y,z,k,s;
	ll ans=0ll;
	cin >> k >> s;
	for(x=0; x<=k; ++x){
		for(y=0; y<=k; ++y){
			z = (s-x-y);
			if(0<=z && z<=k){
				++ans;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[200010];
int b[200010];
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	 {
	 	cin>>a[i];
	 	b[i]=a[i];
	 }
	 int x1=n/2-1;
	 sort(a,a+n);
	 int x2=n/2;
	 for(int i=0;i<n;i++)
	 {
	 	if(b[i]>=a[x2])
	 	cout<<a[x1]<<endl;
	 	else
	 	cout<<a[x2]<<endl;
	 }
	 return 0;
}


Measured memory_bytes: 3712
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>

using namespace std;

struct Node
{
    int key;
    Node *right,*left,*parent;
};

Node *root,*NIL;

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

    z=(Node*)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

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

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

Node* treeMinimum(Node* x)
{
    while (x->left!=NIL)
    {
        x=x->left;        
    }
    return x;
}

Node* treeSuccessor(Node* x)
{
    if (x->right!=NIL)return treeMinimum(x->right);
    Node* y=x->parent;
    while (y!=NIL && x==y->right)
    {
        x=y;
        y=y->parent;
    }
    return y;
}

void treeDelete(Node* z)
{
    Node* y;
    Node* x;
    if(z->left==NIL || z->right==NIL)y=z;
    else y=treeSuccessor(z);

    if (y->left!=NIL)
    {
        x=y->left;
    }
    else
    {
        x=y->right;
    }

    if (x!=NIL)
    {
        x->parent=y->parent;
    }
    if (y->parent==NIL)
    {
        root=x;
    }
    else
    {
        if (y==y->parent->left)
        {
            y->parent->left=x;
        }
        else
        {
            y->parent->right=x;
        }
    }
    
    if (y!=z)
    {
        z->key=y->key;
    }
    free(y);
}



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

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

int main()
{
    int n,i,x;
    string com;

    scanf("%d",&n);

    for (int i = 0; i < n; i++)
    {
        cin>>com;
        if(com=="insert")
        {
            scanf("%d",&x);
            insert(x);
        }
        else if(com=="print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if (com=="find")
        {
            scanf("%d",&x);
            Node *t=find(root,x);
            if(t!=NIL)printf("yes\n");
            else printf("no\n");
        }
        else if (com=="delete")
        {
            scanf("%d",&x);
            treeDelete(find(root,x));
        }
        
        
    }

    return 0;
}



Measured memory_bytes: 21996
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1e6+5;
const long long inf=0x3f3f3f3f;
long long n,a[maxn],b[maxn],sum1,sum2,sum,minu,ans; 
priority_queue<long long> q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(long long i=1;i<=n;i++)
	{
		cin>>a[i];
		sum1+=a[i];
	}
	for(long long i=1;i<=n;i++)
	{
		cin>>b[i];
		sum2+=b[i];
	}
	if(sum1<sum2)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	for(long long i=1;i<=n;i++)
	{
		if(a[i]>b[i])
		{
			sum+=a[i]-b[i];
			q.push(a[i]-b[i]);
		}
		if(a[i]<b[i])
		{
			minu+=b[i]-a[i];
			ans++;
		}
	}
	if(minu==0)
	{
		cout<<"0"<<endl;
		return 0;
	}
	while(!q.empty())
	{
		long long x=q.top();
		q.pop();
		minu-=x;
		ans++;
		if(minu<=0)
		{
			cout<<ans<<endl;
			return 0;
		}
	}
	return 0;
}




Measured memory_bytes: 5756
///
// File:  cgl_2_d.cpp
// Author: ymiyamoto
//
// Created on Mon Oct 23 00:28:22 2017
//
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>

using namespace std;
#define EPS 1e-10
#define equals(x, y) (fabs(x - y) < EPS)

struct vector_t {
  double x;
  double y;

  vector_t(double a, double b) : x(a), y(b)
  {
  }

  double norm2()
  {
    return x * x + y * y;
  }

  double norm()
  {
    return sqrt(norm2());
  }

  double dot(vector_t a)
  {
    return x * a.x + y * a.y;
  }

  double cross(vector_t a)
  {
    return x * a.y - y * a.x;
  }

  vector_t operator*(double a)
  {
    return vector_t(a * x, a * y);
  }
};

struct point_t {
  double x;
  double y;

  point_t operator+(const point_t a)
  {
    return point_t({x + a.x, y + a.y});
  }

  void print()
  {
    cout << fixed << setprecision(10) << x << " " << y << endl;
  }

  point_t operator+(const vector_t vec)
  {
    return point_t({x + vec.x, y + vec.y});
  }

  vector_t operator-(const point_t p)
  {
    return vector_t({x - p.x, y - p.y});
  }

  point_t project(point_t p1, point_t p2)
  {
    vector_t vec1(x - p1.x, y - p1.y);
    vector_t vec2(p2.x - x, p2.y - y);
    return point_t({x, y}) + vec1 * (vec1.dot(vec2) / vec1.norm2());
  }

  point_t reflect(point_t p1, point_t p2)
  {
    point_t proj = project(p1, p2);
    return p2 + (proj - p2) * 2.0;
  }
};

enum pos_t {
  CCLOCKWISE = -1,
  CLOCKWISE = 1,
  ONLINE_BACK = 2,
  ONLINE_FRONT = -2,
  ON_SEGMENT = 0,
};

pos_t ccw(point_t p0, point_t p1, point_t p2)
{
  if ((p1 - p0).cross(p2 - p0) > EPS) {
    return CCLOCKWISE;
  } else if ((p1 - p0).cross(p2 - p0) < -EPS) {
    return CLOCKWISE;
  } else if ((p1 - p0).dot(p2 - p0) < -EPS) {
    return ONLINE_BACK;
  } else {
    if ((p1 - p0).norm2() < (p2 - p0).norm2()) {
      return ONLINE_FRONT;
    } else {
      return ON_SEGMENT;
    }
  }
}

bool intersection(point_t p0, point_t p1, point_t p2, point_t p3)
{
  return (ccw(p0, p1, p2) * ccw(p0, p1, p3) <= 0) && (ccw(p2, p3, p0) * ccw(p2, p3, p1) <= 0);
}

struct segment_t {
  point_t a;
  point_t b;

  double distance(point_t p0)
  {
    if ((b - a).dot(p0 - a) < 0.0) {
      return (p0 - a).norm();
    } else if ((a - b).dot(p0 - b) < 0.0) {
      return (p0 - b).norm();
    } else {
      return fabs((b - a).cross(p0 - a) / (b - a).norm());
    }
  }
};

int32_t main()
{
  uint32_t q;
  cin >> q;

  for (uint32_t i = 0; i < q; i++) {
    double x, y;
    cin >> x >> y;
    point_t p0({x, y});
    cin >> x >> y;
    point_t p1({x, y});
    cin >> x >> y;
    point_t p2({x, y});
    cin >> x >> y;
    point_t p3({x, y});
    if (intersection(p0, p1, p2, p3)) {
      cout << fixed << setprecision(10) << 0.0 << endl;
    } else {
      segment_t seg1({p0, p1});
      segment_t seg2({p2, p3});
      double dist = min(seg2.distance(p0), min(seg2.distance(p1), min(seg1.distance(p2), seg1.distance(p3))));
      cout << fixed << setprecision(10) << dist << endl;
    }
  }

  return 0;
}

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

#define trace(...) __f( #__VA_ARGS__ , __VA_ARGS__ )
template <typename Arg1>
void __f( const char* name , Arg1&& arg1 ) {
        cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f( const char* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int n;
        cin >> n;
        int ans = 0;
        for( int i = 1; i <= n; i++ ) {
                int num = i;
                int dig = 0;
                while( num ) dig++ , num /= 10;
                if( dig&1 ) ans++;
        }
        cout << ans << endl;
        return 0;
}










Measured memory_bytes: 256
#include<iostream>
using namespace std;
int A[1000000],B[100000000];
int main(){
   int N,H,W;
   cin>>N>>H>>W;
   int ans = 0;
   for(int i=0;i<=N;++i){
       cin>>A[i]>>B[i];
       if(A[i]>=H && B[i]>=W){
           ans+=1;
       }
   }
   cout<<ans<<endl;
}

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

int main() {
    long long n, k;
    cin >> n >> k;
    int a[n], f[n];
    for (long long i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    for (long long i = 0; i < n; i++) {
        cin >> f[i];
    }
    sort(f, f + n, greater<int>());
    long long begin = 0, end = 0;
    for (long long i = 0; i < n; i++) {
        end = max(end, 1ll * a[i] * f[i]);
    }
    while (begin < end) {
        long long count = 0, mid = (begin + end) / 2;
        for (long long i = 0; i < n; i++) {
            count += max(a[i] - mid / f[i], 0ll);
        }
        if (count <= k) {
            end = mid;
        } else {
            begin = mid + 1;
        }
    }
    cout << begin;
    return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<memory.h>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

vector<pair<ll,ll>> primeFactorDecomp(ll n){
      vector<pair<ll,ll>> ret;
      ll m=n;
      for(ll i=2;i*i<=m;i++){
            if(n%i!=0) continue;
            int cnt=0;
            while(n%i==0){
                  cnt++;
                  n/=i;
            }
            ret.push_back({i,cnt});
      }
      if(n>1){
            ret.push_back({n,1});
      }
      return ret;
}

ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}

int main(){
  ll a,b;
  cin >> a >> b;
  if(gcd(a,b)==1){
    cout << 1 << endl;
    return 0;
  }
  cout << primeFactorDecomp(gcd(a,b)).size()+1 << endl;
return 0;}

Measured memory_bytes: 256
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#define waru 1000000000+7

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  vector<unsigned long long int> r(n);
  r[0] = 0;
  int now = 2;
  while (now != 0){
    r[now] = r[(now+n-2)%n] + (a[(now+n-1)%n] - a[(now+n-2)%n])*2;
    // shows(now) show(r[now])
    now = (now+2)%n;
  }
  // showa(r)
  int sum = 0;
  int sumsum = 0;
  unsigned long long int sa = 0;
  rep(i,n){
    sa += a[i] - r[i];
  }
  unsigned long long int bai = sa/n;
  rep(i,n){
    cout << bai + r[i] << " ";
  }

}

Measured memory_bytes: 2432
#include<stdio.h>
#include<math.h>
int main()
{
	int A,B;
	char op;
	scanf("%d %c %d",&A,&op,&B);
	switch (op)
	{
		case '+':
		    printf("%d\n",A+B);
		    break;
	    case '-':
	    	printf("%d\n",A-B);
	    	break;
	}
	return 0;
}

Measured memory_bytes: 128
// finish date: 2018/07/22
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


ll solve(ll a, ll b) {
    if (b == 0) return 0;
    if (a == b) return a;
    return 2 * ((a - 1) / b) * b + solve(b, a - ((a - 1) / b)*b);
}

int main() {
    ll N, X;
    cin >> N >> X;
    ll ans = N;
    ans += solve(max(X, N - X), min(X, N - X));
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256