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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(),(v).end()
typedef long long ll;

#define get_money iwfebvosbi

const int N = 50, M = 5e3;
vector<tuple<ll,ll,ll>> g[N+10];

ll n, m, s;
bool vis[N+10][M+10];
ll t_dist[N+10][M+10];
ll get_money[N], time_get_money[N];

void dij(){
	s = min<ll>(s,M);
	set<tuple<ll,ll,ll>> st;
	st.emplace(0,0,s);
	
	while(!st.empty()){
		ll curt, no, cur_money;
		tie(curt,no,cur_money) = *(st.begin());
		st.erase(st.begin());
		if(vis[no][cur_money]) continue;
		vis[no][cur_money] = 1;
		t_dist[no][cur_money] = curt;
		
		for(auto &tup : g[no]){
			ll it,cost,temp;
			tie(it,cost,temp) = tup;
			if(cur_money>=cost) st.emplace(curt+temp,it,cur_money-cost);
		}	
		if(cur_money+get_money[no]<=M){
			st.emplace(curt+time_get_money[no],no,cur_money+get_money[no]);
		}
	}
}

int main(){
	cin >> n >> m >> s;
	
	fr(i,m){
		ll u, v, cost, temp;
		scanf("%lld%lld%lld%lld", &u, &v, &cost, &temp);
		u--,v--;
		g[u].emplace_back(v,cost,temp);
		g[v].emplace_back(u,cost,temp);
	}
	fr(i,n){
		scanf("%lld%lld", get_money+i, time_get_money+i);
	}
	
	dij();
	
	for(int i = 1; i<n; i++){
		ll mint = LLONG_MAX;
		fr(din,M){
			if(vis[i][din]) mint = min(mint,t_dist[i][din]);
		}
		printf("%lld\n", mint);
	}
}

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

using lint = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	multiset<int> values;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		values.insert(v[i]);
	}
	for (int i = 0; i < n; ++i) {
		multiset<int>::iterator k = values.find(v[i]);
		values.erase(k);
		int x = *(values.rbegin());
		cout << x << '\n';
		values.insert(v[i]);
	}
}



Measured memory_bytes: 11776
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <string>
#include <random>
#include <queue>


using namespace std;

// ans = a ? b : c; // to simplify: if (a) ans = b; else ans = c;
// ans += val; // to simplify: ans = ans + val; and its variants
// index = (index + 1) % n; // index++; if (index >= n) index = 0;
// index = (index + n - 1) % n; // index--; if (index < 0) index = n - 1;
// int ans = (int)((double)d + 0.5); // for rounding to nearest integer
// ans = min(ans, new_computation); // min/max shortcut
// alternative form but not used in this book: ans <?= new_computation;
// some code use short circuit && (AND) and || (OR)

typedef long long ll; // comments that are mixed in with code
typedef pair<int, int> ii; // are aligned to the right like this
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
#define INF 1000000000
#define M_PI 3.14159265358979323846

void printVector2d(vector<vector<int>> a){
    for(int i=0;i<a.size();i++){
        for(int j=0;j<a[i].size();j++){
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<"end"<<endl;
}

void printVector(vector<ll> a){
    for(int i=0;i<a.size();i++){
        cout<<"Total "<<i<<": "<<a[i]<<endl;
    }
}

void printVectorPair(vector<pair<int,int>> a){
    for(int i=0;i<a.size();i++){
        cout<<"Total "<<i<<": "<<a[i].first<<" "<<a[i].second<<endl;
    }
}

void printMap(map<char, int> mp){
    for(auto x:mp){
        cout<<x.first<<": "<<x.second<<endl;
    }
}

void printMapVec(map<int, vector<int>> mpV){
    for(auto x:mpV){
        cout<<x.first<<": ";
        for(auto y:x.second){
            cout<<y<<" ";
        }
        cout<<endl;
    }
}

void printQueue(queue<char> q){
    while(!q.empty()){
        cout<<q.front()<<" ";
        q.pop();
    }
    cout<<" ##### ";
}

void solve(){
    string n;
    cin>>n;
    int tot_ans = 0;
    for(int i=0;i<n.size();i++){
        char curr_num_char = n[i];
        int curr_num = curr_num_char - '0';
        tot_ans += curr_num;
    }

    if(tot_ans%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

int main() {
    //solve();
    int T;
//    cin >> T;
    T=1;
    for (int case_num = 1; case_num <= T; case_num++) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3276
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <cmath>
#include <cstring>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;

int main() {
	int X, A;
    cin >> X >> A;
    cout << (X < A ? 0 : 10) << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
def judge(k, N, A):
    t = 0
    for i in A:
        j = bisect.bisect_left(A, k - i)
        t += N - j
    return t
def main():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    t = A[-1] * 2
    b = 0
    X = None
    while t - b > 1:
        m = (t + b)//2
        i = judge(m, N, A)
        if i == M:
            X = m
            break
        if i > M:
            ip = judge(m + 1, N, A)
            if ip == M:
                X = m + 1
                break
            if ip < M:
                X = m
                break
            b = m + 1
        if i < M:
            im = judge(m - 1, N, A)
            if im >= M:
                X = m - 1
                break
            t = m - 1
    if X is None:
        X = b
    B = []
    tmp = 0
    for i in reversed(range(N)):
        tmp += A[i]
        B.append(tmp)
    B.reverse()
    r = 0
    tot = 0
    for i in reversed(range(N)):
        j = bisect.bisect_left(A, X - A[i])
        tot += N - j
        if j == N:
            break
        r += A[i] * (N - j) + B[j]
    return r - (tot - M) * X
print(main())


Measured memory_bytes: 14204
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 
#define fi first
#define se second

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

int main() {
    ll a, b; cin >> a >> b;
    co(a*b);

    return 0;
}


Measured memory_bytes: 3652
s = input()
S = list(s)
cnt = 0
l = int(len(s))
l = l // 2
for i in range(l + 1):
    if S[i] == S[-(1 + i)]:
        for j in range(l):
            if S[j] == S[-(l + 2 + j)]:
                cnt += 1


if cnt == l * (l + 1):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9124
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

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); }

bool compareP(pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

int main() {
    int n;
    cin >> n;
    if ((n / 100) * 5 < n % 100)
        cout << 0 << endl;
    else
        cout << 1 << endl;
}

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

#define lld long long

int main() {
    int N;
    lld sum = 0;
    string S;

    cin >> N;
    cin >> S;

    lld Rcnt[N + 1];
    lld Gcnt[N + 1];
    lld Bcnt[N + 1];

    Rcnt[N] = 0;
    Gcnt[N] = 0;
    Bcnt[N] = 0;

    for(int i = N - 1; i >= 0; i--) {
        if(S[i] == 'R') {
            Rcnt[i] = Rcnt[i + 1] + 1;
            Gcnt[i] = Gcnt[i + 1];
            Bcnt[i] = Bcnt[i + 1];
        } else if(S[i] == 'G') {
            Gcnt[i] = Gcnt[i + 1] + 1;
            Rcnt[i] = Rcnt[i + 1];
            Bcnt[i] = Bcnt[i + 1];
        } else if(S[i] == 'B') {
            Bcnt[i] = Bcnt[i + 1] + 1;
            Gcnt[i] = Gcnt[i + 1];
            Rcnt[i] = Rcnt[i + 1];
        }
    }

    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            if(S[i] == 'R' && S[j] == 'G') {
                sum += Bcnt[j + 1];
                if(j + j - i <= N && S[j + j - i] == 'B') {
                    sum -= 1;
                }
            } else if(S[i] == 'R' && S[j] == 'B') {
                sum += Gcnt[j + 1];
                if(j + j - i <= N && S[j + j - i] == 'G') {
                    sum -= 1;
                }
            } else if(S[i] == 'G' && S[j] == 'R') {
                sum += Bcnt[j + 1];
                if(j + j - i <= N && S[j + j - i] == 'B') {
                    sum -= 1;
                }
            } else if(S[i] == 'G' && S[j] == 'B') {
                sum += Rcnt[j + 1];
                if(j + j - i <= N && S[j + j - i] == 'R') {
                    sum -= 1;
                }
            } else if(S[i] == 'B' && S[j] == 'R') {
                sum += Gcnt[j + 1];
                if(j + j - i <= N && S[j + j - i] == 'G') {
                    sum -= 1;
                }
            } else if(S[i] == 'B' && S[j] == 'G') {
                sum += Rcnt[j + 1];
                if(j + j - i <= N && S[j + j - i] == 'R') {
                    sum -= 1;
                }
            }
        }
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int s,w;
  cin >> s >> w;
  if(s > w){
    cout << "safe" << endl;
  }else{
    cout << "unsafe" << endl;
  }

  return 0;
}


Measured memory_bytes: 3632
use std::io::prelude::*;
use std::io;
use std::cmp::*;

#[derive(PartialEq, Eq, Debug)]
enum Road {
    P(u64),
    Q(u64),
}

impl PartialOrd for Road {
    fn partial_cmp(&self, other: &Road) -> Option<Ordering> {
        let cs = match *self {
            P(c) | Q(c) => c,
        };
        let co = match *other {
            P(c) | Q(c) => c,
        };
        cs.partial_cmp(&co)
    }
}

impl Ord for Road {
    fn cmp(&self, other: &Road) -> Ordering {
        self.partial_cmp(other).unwrap()
    }
}

use Road::*;

fn read_to_string() -> String {
    let mut buf = String::new();
    let mut stdin = io::stdin();
    stdin.read_to_string(&mut buf);
    buf
}

fn solve(p: &[u64], q: &[u64]) -> u64 {
    let w = p.len();
    let h = q.len();
    let mut pq: Vec<_> = p.iter()
        .map(|c| P(*c))
        .chain(q.iter()
            .map(|c| Q(*c)))
        .collect();
    pq.sort();
    let mut a = w as u64 + 1;
    let mut b = h as u64 + 1;
    pq.iter()
        .map({
            |e| match *e {
                P(c) => {
                    a -= 1;
                    b * c
                }
                Q(c) => {
                    b -= 1;
                    a * c
                }
            }
        })
        .fold(0, std::ops::Add::add)
}

fn main() {
    let input = read_to_string();
    let mut words = input.split_whitespace();
    let w: usize = words.next().unwrap().parse().unwrap();
    let h: usize = words.next().unwrap().parse().unwrap();
    let p: Vec<u64> = words.by_ref().take(w).map(|i| i.parse().unwrap()).collect();
    let q: Vec<u64> = words.by_ref().take(h).map(|i| i.parse().unwrap()).collect();
    println!("{}", solve(&p, &q));
}


Measured memory_bytes: 14972
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#define rep(i, x) for(ll i = 0; i < x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

ll a[1234];
signed main() {
	ll n, p; cin >> n >> p;
	rep(i, n) {
		cin >> a[i];
	}
	ll gu1 = 0, ki1 = 0, gu2 = 0, ki2 = 0, gu3 = 0, ki3 = 0;
	ll flag = n / 3, kari1 = 0, kari2 = 0;
	for (int h = 0; h < (1 << flag); h++) {
		ll cnt = 0;
		for (ll i = 0; i <= flag - 1; i++) {
			if ((h & (1 << i)) > 0) {
				cnt += a[i]; cnt %= 2;
				kari1 = max(kari1, i);
			}
		}
		if (cnt % 2 == 0) { gu1++; }
		else { ki1++; }
	}
	kari1++;
	flag = (n + 1) / 3;
	for (int h = 0; h < (1 << flag); h++) {
		ll cnt = 0;
		for (int i = 0; i <= flag - 1; i++) {
			if ((h & (1 << i)) > 0) {
				cnt += a[kari1 + i]; cnt %= 2;
				kari2 = max(kari2, kari1 + i);
			}
		}
		if (cnt % 2 == 0) { gu2++; }
		else { ki2++; }
	}
	flag = (n + 2) / 3;
	for (int h = 0; h < (1 << flag); h++) {
		ll cnt = 0;
		for (int i = 0; i <= flag - 1; i++) {
			if ((h & (1 << i)) > 0) {
				cnt += a[kari2 + i]; cnt %= 2;
			}
		}
		if (cnt % 2 == 0) { gu3++; }
		else { ki3++; }
	}
	ll ans = 0;
	if (p == 0) {
		ans += (gu1 * gu2 * gu3);
		ans += (gu1 * ki2 * ki3);
		ans += (ki1 * gu2 * ki3);
		ans += (ki1 * ki2 * gu3);
		cout << ans << endl;
	}
	else {
		ans += (gu1 * gu2 * ki3);
		ans += (gu1 * ki2 * gu3);
		ans += (ki1 * gu2 * gu3);
		ans += (ki1 * ki2 * ki3);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m;

    cin >> n >> m;

    vector<ll> a(n),b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }

    vector<pair<ll,ll>> x;
    for(int i = 0; i < n; i++){
        x.push_back(make_pair(a[i],b[i]));
    }

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

    ll ans = 0;
    for(int i = 0; i < n; i++){
        if(x[i].second >= m){
            ans += x[i].first*m;
            break;
        }else{
            ans += x[i].first*x[i].second;
            m -= x[i].second;
        }
    }

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

Measured memory_bytes: 3956
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for(int i = 1; i < 10001; i++) {
            int x = sc.nextInt();
            if (x == 0) {
                return;
            }
            System.out.println("Case " + i + ": "  + x);
        }
    }
}


Measured memory_bytes: 40848
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()


void solve(){
  ll n,m,v,p;
  cin >> n >> m >> v >> p;
  vll a(n);
  rep(i,0,n) cin >> a[i];
  sort(all(a),gll);
  
  ll l=p-1,r=n-1;
  while(a[r]+m<a[p-1]) r--;
  r++;
  
  while(r-l>1){
   ll mid=l+(r-l)/2;
   ll num=m*p+(n-1-mid)*m;
   rep(i,p-1,mid) num+=a[mid]+m-a[i]; 
   if(num<m*v) r=mid;
   else l=mid; 
  }
 cout << l+1 << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  


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

using namespace std;

#define sz(x) ((int) ((x).size()))
typedef long long ll;
typedef long double ld;

int n, a[200000];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  bool wf;
  for (int i = 0; i < n; i++) {
    if (i == 0 || a[i] != a[i - 1])
      wf = (n - i - 1 + a[i]) % 2 == 0;
    if (wf && a[i] >= n - i - 1) {
      cout << "First\n";
      return 0;
    } else if (!wf && a[i] - 1 >= n - i - 1) {
      cout << "Second\n";
      return 0;
    }
  }
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
// ll mod = 998244353;
 ll mod = 1000000007;
  
ll mypow(ll number1,ll number2, ll mod){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = mypow(number1,number2 / 2, mod);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 

ll fact[fact_table + 5],rfact[fact_table + 5];
 
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}


ll n,m,num,sum,a,b,d,e,h,r,l,q;
ll w, ans;
ll k;
ll x[500005], y[500005], z[500005];
char s[500005], t[500005];

int main(){
    cin >> n >> a >> b;
    c3_init();
    ll ans = rui(2, n);
    ll tmp1 = 1, tmp2 = 1;
    for(ll i=0;i<a;i++){
        tmp1 *= (n - i);
        tmp1 %= mod;
        tmp1 *= rui((i+1), mod - 2);
        tmp1 %= mod;
    }
    for(ll i=0;i<b;i++){
        tmp2 *= (n - i);
        tmp2 %= mod;
        tmp2 *= rui((i+1), mod - 2);
        tmp2 %= mod;
    }
    ans += mod - tmp1 + mod - tmp2 + mod - 1;
    ans %= mod;
    p(ans);
    return 0;

}


















Measured memory_bytes: 13184
N,A,B,C = map(int,input().split())
L = [int(input()) for _ in range(N)]

def f(a,b,c,k):
    if k == N:
        if not a or not b or not c:
            return 10**9
        return abs(a-A)+abs(b-B)+abs(c-C)-30
    ans0 = f(a,b,c,k+1)
    ans1 = f(a+L[k],b,c,k+1)+10
    ans2 = f(a,b+L[k],c,k+1)+10
    ans3 = f(a,b,c+L[k],k+1)+10
    return min(ans0,ans1,ans2,ans3)

print(f(0,0,0,0))

Measured memory_bytes: 3188
#include <stdio.h>

int main(void) {
    // insert code here...
    int a[4], i, ans[2];
    
    for(i = 0; i<4; i++){
        scanf("%d", &a[i]);
    }
    
    if(a[0]<=a[1]){
        ans[0] = a[0];
    }
    if(a[0]>a[1]){
        ans[0] = a[1];
    }
    if(a[2]<=a[3]){
        ans[1] = a[2];
    }
    if(a[2]>a[3]){
        ans[1] = a[3];
    }
    
    printf("%d", ans[0]+ans[1]);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(int i=0;i<(n);i++)
#define cinv(v,n) FOR(i,n){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n);
#define pb push_back
#define mp make_pair

int main() {
  int n,k;
  cin>>n>>k;
  if(k==1){
    cout<<0;
    return 0;
  }
  cout<<n-k;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int sum[100010] = {};
  int n;
  cin >> n;
  
  REP(i,n){
    int a;
    cin >> a;
    sum[a+1]++;
    sum[a]++;
    sum[a+2]++;
  }
  
  int ans = 0;
  REP(i,100010){
    ans = max(ans,sum[i]);
  }
  
  cout << ans << endl;


 return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;

signed main(){
    string s;
    cin >> s;
    ll temp = s[s.size()-1] - '0';

    switch(temp){
        case 3:
            cout << "bon" << endl;
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon" << endl;
            break;
        default:
            cout << "hon" << endl;
            break;
    }
    return 0;
}

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

int N,W;
vector<int>v,w;

int dp[10001];

int main(){
    cin>>N>>W;
    v.resize(N);w.resize(N);

    for(int i=0;i<N;i++)cin>>v[i]>>w[i];

    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j-w[i]<0)continue;
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
        }
    }

    cout<<dp[W]<<endl;
    return 0;
}

Measured memory_bytes: 1236
#include <iostream>
#include <cstdio>
#include <cmath>

#define PI 3.14159265358979
#define rad(deg) ((deg) / 180 * PI) 

using namespace std;

int main() {
	int d, a;
	float x = 0., y = 0., deg = 0.;

	while (scanf("%d,%d", &d, &a)) {
		if (d == 0 && a == 0) { break; }

		x += d * sin(rad(deg));
		y += d * cos(rad(deg));

		deg += a;
	}

	cout << (int)x << endl << (int)y << endl;
	return 0;
}

Measured memory_bytes: 3452
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <numeric>
#include <algorithm>
using namespace std;
int N;
int A[100000];
int ans[100000];
int sum;
int main() {
	cin >> N;
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}

	//1回目だけ別処理
		ans[0] = 0;
		for (int i = 0;i < N;i++) {
			ans[0] += A[(i) % N] * pow(-1, i % 2);
		}
	//2回目以降
		for (int i = 1;i < N;i++) {
			ans[i] += 2*A[i-1] - ans[i-1];
		}

	


	for (int i = 0;i < N;i++) {
		cout << ans[i] << " ";
	}
	return 0;
}


Measured memory_bytes: 2048
#include<cstdio>
#include<cmath>

using namespace std;

int main(void){
	int n;
	while(scanf("%d", &n) && n != 0){
//		scanf("%d", &n);
		int array[100005]={0};
		int count = 1;
		int temp;
		
		for(int i = 1; i <= n; i++){
			scanf("%d", &temp);
			//ÈçO
			//ÈçPªüÍ³êéB
			
			//Èç³Ì
			//ÈçÌðzñÉ¢êéB
			
			if(i%2){
				if(count > 1 && array[count-1] < 0 && temp == 1)array[count-1]--;
				else if(count > 1 && array[count-1] > 0 && temp == 0)array[count-1]++;
				else if(temp == 0){
					array[count] ++;
					count++;
				}
				else {
					array[count] --;
					count++;
				}
			}else{
				if(temp == 0){
					if(count > 1 && array[count-1] > 0){
						array[count-1]++;
					}else if(count > 2 && array[count-1] < 0){
						array[count-2] += -1*(array[count-1])+1;
						array[count-1] = 0;
						count--;
					}else if(count - 1 > 0 && array[count-1] < 0){
						array[count-1] *= -1;
						array[count-1] ++;
					}
				}else{
					if(count > 1 && array[count-1] < 0){
						array[count-1]--;
					}else if(count > 2 && array[count-1] > 0){
						array[count-2] += -1*(array[count-1]+1);
						array[count-1] = 0;
						count--;
					}else if(count > 1 && array[count-1] > 0){
						array[count-1] *= -1;
						array[count-1] --;
					}
				}
			}
			/*
			printf("count -> %d\n",count);
			for(int i = 0; i <= count ; i++){
				printf("%d%s",array[i],i>=0?" ":"");
			}puts("");
			*//*
			for(int i = 1; i < count; i++){
				for(int j = 0; j < abs(array[i]); j++){
					printf("%s", array[i]>0?"":"");
				}
			}puts("");
			//*/
		}
		int ans = 0;
		for(int i = 0; i <= count; i++){
			if(array[i] > 0)ans+=array[i];
		}
		printf("%d\n",ans);
	}
	
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n+1];
    a[0]=0;
    a[1]=0;
    for(int i=2; i<n+1; i++){
        cin >> a[i];
    }
    int b[n+1];
    for(int i=0; i<n+1; i++){
        b[i]=0;
    }
    for(int i=1; i<n+1; i++){
        b[a[i]]++;
    }
    for(int i=1; i<n+1; i++){
        cout << b[i] << endl;
    }
    return 0;
}

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



int main() {
	int n, x;
	while (1) {
		int cnt = 0;
		cin >> n >> x;
		if (n == 0 && x == 0)break;
		for (int i = 1; i <= n - 2; i++) {
			for (int j = i + 1; j <= n - 1; j++) {
				for (int k = j + 1; k <= n; k++) {
					int sum = i;
					sum += k;
					sum += j;
					if (sum == x)cnt++;
				}
			}
		}
		cout << cnt << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <map>
#include <algorithm>
#include <vector>
#include <queue>

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

typedef pair<int,int> s;
typedef long long int ll;

int abs(int x){
  return x > 0 ? x : -x;
}

int length(char c[]){
  int cnt=0;
  for(cnt=0;c[cnt]!='\0';cnt++){
  }
  return cnt;
}

map<ll,int> m;
vector<ll> v;
int n;
ll a;
ll mn,mx;


int main(){
  scanf("%d",&n);
  REP(i,n){
    scanf("%lld",&a);
    v.push_back(a);
    if(m.find(a)==m.end()){
      m[a]=1;
    }else{
      m[a]++;
    }
  }
  sort(v.begin(),v.end());
  ll prev=0;
  for(ll x:v){
    if(prev==x)
      continue;
    if(m[x]>=4){
      mx=mn=x;
    }else if(m[x]>=2){
      mn=mx;
      mx=x;
    }
    prev=x;
  }
  printf("%lld\n",mn*mx);
  return 0;
}


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

int main () {
  int N; cin >> N;
  vector<int> a(N);
  int total=0;
  for (int i=0; i<N; i++){ cin >> a.at(i); total += a.at(i);}
  if (total%N) {
    int m = total/N, cost1=0, cost2=0;
    for (int i=0; i<N; i++) {
      cost1 += pow(a.at(i)-m, 2);
      cost2 += pow(a.at(i)-m-1, 2);
    }
    cout << min(cost1, cost2) << endl;
  } else {
    int m = total / N, cost=0;
    for (int i=0; i<N; i++) cost += pow(a.at(i)-m, 2);
    cout << cost << endl;
  }
}
  

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

int main(int argc, char *argv[])
{
	int a, b, c;
	vector<int> target;

	cin >> a >> b >> c;
	target.push_back(a);
	target.push_back(b);
	target.push_back(c);

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

	cout << target[2] * 10 + target[1] + target[0];
	
	
	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();
		String s = String.valueOf(n);
		String ans = "";

		for (int i = 1; i <= 3; i++) {
			String cash = s.substring(i - 1, i);
			if (cash.equals("1")) {

				ans += "9";

			} else {

				ans += "1";

			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
/*-****************************************-*/

#define USE_CPP11

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>

#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <bitset>
#ifdef USE_CPP11
# include <unordered_set>
# include <unordered_map>
# include <array>
# include <valarray>
#endif // USE_CPP11

#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>

using namespace std;

/*-****************************************-*/

typedef pair<int, int> pii;
typedef long long ll;

/*-****************************************-*/

#define mp make_pair

#define sz_array(a) (sizeof(a) / sizeof((a)[0]))

#define all(a) (a).begin(),(a).end()
#define r_all(a) (a).rbegin(), (a).rend()

#define exists(container, elem) ((container).find(elem) != (container).end())

/*-****************************************-*/

template<typename T> T MinAssign(T &a, T b) {
    if (a > b)
        a = b;
    return a;
}

template<typename T> T MaxAssign(T &a, T b) {
    if (a < b)
        a = b;
    return a;
}

template<typename T, size_t size> void Fill(void *ptr, T value) {
    fill((T *)ptr, (T *)ptr + size / sizeof(T), value);
}

/*-****************************************-*/

static const double EPS = 1e-10;
static const double PI = acos(-1.0);
static const int INF = 1 << 28;

/*-****************************************-*/

#ifdef DEBUG
#define ANSWER_PREFIX() cout << "[[ Answer ]] "
#else
#define ANSWER_PREFIX()
#endif // DEBUG

/*-****************************************-*/

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

constexpr int MOD = 1000000000 + 7;

bool IsPrime(int n) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }

    return true;
}

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

    ll ans = 1;
    for (int i = 2; i <= n; i++) {
        if (IsPrime(i)) {
            int num = 0;
            int val = i;
            while (val <= n) {
                num += n / val;
                val *= i;
            }

            ans = ans * (num + 1) % MOD;
        }
    }

    ANSWER_PREFIX();
    cout << ans << endl;
}


Measured memory_bytes: 384
n,a,b=map(int,input().split())
total=0
for i in range(1,n+1):
    x=(str(i))
    j=0
    total2=0
    for j in range(len(x)):
        total2+=int(x[j])
    if a<=total2<=b:
        total+=i
print(total)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(obj) (obj).begin(), (obj).end()


int main()
{
	int n;
	cin >> n;
	int h[n+1];
	REP(i, n){
		cin >> h[i];
	}
	h[n] = 0;
	int ans = 0, bef0 = 1;
	while(1){
		int sum = 0;
		REP(i, n+1){
			if(h[i]){
				bef0 = 0;
				h[i]--;
			}else if(bef0 == 0){
				ans++;
				bef0 = 1;
			}
			sum += h[i];
		}
		if(sum == 0){
			cout << ans << "\n";
			return 0;
		}else{
			sum = 0;
		}
	}
}


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

int n, m;
vector<int> v;
int main() {
  cin >> n >> m;
  v.resize(n, -1);
  for (int i = 0; i < m; ++i) {
    int d, k;
    cin >> d >> k;
    --d;
    if (v[d] != -1 && v[d] != k) {
      cout << -1 << endl;
      return 0;
    }
    v[d] = k;
  }
  for (int i = 0; i < n; ++i) {
    if (v[i] == -1) {
      v[i] = (n != 1 && i == 0) ? 1 : 0;
    }
  }
  
  if (n != 1 && v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int c : v) {
    cout << c;
  }
  cout << endl;
}


Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = Integer.parseInt(sc.next());
	int[] T = new int[N+1];
	int sum = 0;
	for(int i = 1; i<N+1; i++) {
	    T[i] = Integer.parseInt(sc.next());
	    sum += T[i];
	}
	int M = sc.nextInt();
	for(int i = 0; i<M; i++) {
	    int time = sum - T[Integer.parseInt(sc.next())] + Integer.parseInt(sc.next());
	    System.out.println(time);
	}
    }
}

Measured memory_bytes: 23124
n=int(input())
mod=10**9+7
from collections import Counter as co
var=co(map(int,input().split()))
if n%2:
    if 0 not in var:print(0);exit()
    if var[0]!=1:print(0);exit()
    for i in range(2,n,2):
        if i not in var:print(0);exit()
        if var[i]!=2:print(0);exit()
else:
    for i in range(1,n,2):
        if i not in var:print(0);exit()
        if var[i]!=2:print(0);exit()
print(2**(n//2)%mod)


Measured memory_bytes: 16616
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    while (cin >> N >> M) {
        cout << (M * 1900 + (N - M) * 100) * (1<<M) << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <stack>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a % 2 == 1 && b % 2 == 1) cout << "Yes" << endl;
    else cout << "No" << endl;
}
    



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ll n,m;
	cin>>n>>m;
	ll sum=0;
	if(m<n*2)
	{
		sum=m/2;
		cout<<sum<<endl;
		return 0;
	}
	if(m>n*2)
	{
		sum=sum+n;
		sum=sum+(m-n*2)/4;
		cout<<sum<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		HashMap<Long, Long> a = new HashMap<Long, Long>();
		int ans = 0;
		
		for (int i = 0; i < n; i++) {
			long x = sc.nextInt();
			
			if (a.get(x) == null) {
				a.put(x, Long.valueOf("1"));
				ans++;
			} else if (a.get(x) == 0) {
				a.put(x, Long.valueOf("1"));
				ans++;
			} else if (a.get(x) == 1) {
				a.put(x, Long.valueOf("0"));
				ans--;
			}
		}
		
		
		System.out.println(ans);

		sc.close();
	}
}

Measured memory_bytes: 64960
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 2000010
#define MO 1000000007
int fac[MAXN],inv[MAXN];
void Pre()
{
	fac[0]=inv[0]=inv[1]=1;
	for(int i=1;i<MAXN;i++)
		fac[i]=1LL*fac[i-1]*i%MO;
	for(int i=2;i<MAXN;i++)
		inv[i]=1LL*(MO-MO/i)*inv[MO%i]%MO;
	for(int i=2;i<MAXN;i++)
		inv[i]=1LL*inv[i]*inv[i-1]%MO;
}
int C(int x1,int y1,int x2,int y2)
{
	return 1LL*fac[x1-x2+y1-y2]*inv[x1-x2]%MO*inv[y1-y2]%MO;
}
int x3,y3,x4,y4,ans;
int Solve(int x1,int y1,int x2,int y2)
{
	int ret=0;
	for(int i=x3;i<=x4;i++) (ret+=1LL*C(i,y3-1,x1,y1)*C(x2,y2,i,y3)%MO*(-i-y3)%MO)%=MO;
	for(int i=y3;i<=y4;i++) (ret+=1LL*C(x3-1,i,x1,y1)*C(x2,y2,x3,i)%MO*(-i-x3)%MO)%=MO;
	for(int i=x3;i<=x4;i++) (ret+=1LL*C(i,y4,x1,y1)*C(x2,y2,i,y4+1)%MO*(y4+1+i)%MO)%=MO;
	for(int i=y3;i<=y4;i++) (ret+=1LL*C(x4,i,x1,y1)*C(x2,y2,x4+1,i)%MO*(x4+1+i)%MO)%=MO;
	return ret;
}
int x[8],y[8],c[8];
int main()
{
	Pre();
	scanf("%d%d%d%d%d%d",&x[0],&x[1],&x3,&x4,&x[4],&x[5]);
	scanf("%d%d%d%d%d%d",&y[0],&y[1],&y3,&y4,&y[4],&y[5]);
	c[0]=c[1]=c[4]=c[5]=1;
	c[2]=c[3]=c[6]=c[7]=-1;
	x[0]--,y[0]--,x[5]++,y[5]++;
	x[2]=x[0],x[3]=x[1],y[2]=y[1],y[3]=y[0];
	x[6]=x[4],x[7]=x[5],y[6]=y[5],y[7]=y[4];
	for(int i=0;i<4;i++)
		for(int j=4;j<8;j++)
			(ans+=1LL*Solve(x[i],y[i],x[j],y[j])*c[i]*c[j]%MO)%=MO;
	ans=(ans%MO+MO)%MO;
	printf("%d\n",ans);
}

Measured memory_bytes: 15744
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}

constexpr ll LNF = 1e15;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,m,v,p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    sort(rall(a));
    auto is_ok = [&](const int index){
        ll base = a[index]+m;
        int c = 0;
        rep(i,0,n){
            if(a[i]>base) c++;
            else break;
        }
        if(c>=p){
            return false;
        }
        ll x = 0;
        int count = 0;
        rep(i,0,n){
            if(i==index) continue;
            if(count<p-1){
                count++;
                x += m;
                continue;
            }
            if(a[i]<=base){
                x += min(base-a[i],m);
            }
        }
        debug(x,m*(v-1));
        if(x>=m*(v-1)) return true;
        return false;
    };
    int ok = -1;
    int ng = a.size();
    while(abs(ng-ok)>1){
        int mid = (ok+ng)/2;
        debug(mid);
        if(is_ok(mid)) ok = mid;
        else ng = mid;
    }
    cout << ng << endl;
}

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

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

  string w,s;
  cin >> w;
  int count = 0;
  while (1) {
    cin >> s;
    if (s == "END_OF_TEXT") {
      break;
    }
    for (int i = 0; i < s.size(); i++) {
      s[i] = tolower(s[i]);
    }
    if (w == s) {
      count++;
    }
  }
  cout << count << '\n';
}


Measured memory_bytes: 3188
N,Q = map(int,input().split())
S = input()
qs = [input().split() for i in range(Q)]

def left_out(i):
    if i < 0: return True
    if i >= N: return False
    for t,d in qs:
        if t != S[i]: continue
        if d == 'L':
            i -= 1
            if i < 0: return True
        else:
            i += 1
            if i >= N: return False
    return False

def right_out(i):
    if i >= N: return True
    if i < 0: return False
    for t,d in qs:
        if t != S[i]: continue
        if d == 'R':
            i += 1
            if i >= N: return True
        else:
            i -= 1
            if i < 0: return False
    return False

l_ok = -1
l_ng = N
while l_ng - l_ok > 1:
    m = (l_ok + l_ng) // 2
    if left_out(m):
        l_ok = m
    else:
        l_ng = m

r_ok = N
r_ng = -1
while r_ok - r_ng > 1:
    m = (r_ok + r_ng) // 2
    if right_out(m):
        r_ok = m
    else:
        r_ng = m

ans = N
if l_ok >= 0:
    ans -= l_ok+1
if r_ok < N:
    ans -= N-r_ok
print(ans)

Measured memory_bytes: 41392
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    s, t = input().split()
    a, b = map(int, input().split())
    u = input()
    if s == u:
        a = max(0, a-1)
    else:
        b = max(0, b-1)

    print(a, b)


if __name__ == '__main__':
    main()


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

int main(){
  string s;
  cin >>  s;
  
  for(int k=0; k<s.size(); k++){
    if(k%2==0){
      if(s[k]!='L'){
      }else{
        cout << "No" << endl;
        return 0;
      }
    }else{
      if(s[k]!='R'){
      }else{
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  }

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
typedef pair<int,int> P;

int main(){
     int N,M,A;
     while(cin>>N>>M>>A,N||M||A){
	  multimap<int,P> sen;
	  for(int i=0;i<M;i++){
	       int h,p,q;
	       cin>>h>>p>>q;
	       sen.insert(pair<int,P>(h,P(p-1,q-1)));
	  }
	  int tate[N];
	  for(int i=0;i<N;i++){
	       tate[i]=i;
	  }
	  multimap<int,P>::reverse_iterator itr=sen.rbegin();
	  while(sen.rend()!=itr){
	       swap(tate[itr->second.first],tate[itr->second.second]);
	       //cout<<"swapped!"<<tate[itr->second.first]<<":"<<tate[itr->second.second]<<endl;
	       ++itr;
	  }
	  int ans=-1;
	  for(int i=0;i<N;i++){
	       //cout<<tate[i]<<endl;
	       if(tate[i]==A-1){
		    ans=i+1;
		    break;
	       }
	  }
	  cout<<ans<<endl;
     }
     return 0;
}

Measured memory_bytes: 936
#include<string>
#include<iostream>
#include<cmath>

using namespace std;

int main()
{
	unsigned int s, x = 0, n;
	double xd = 0.1;
	do
	{
		cin >> s;
		xd = 0.1;
		if( s == 0 )
			break;
		n = (unsigned int)sqrt(2*s);
		while( xd != (double)((int)xd) )
		{
			if( 2*s != n*n )
				xd = (double)(((double)(2*s - n*n)/n + 1) / 2);
			n--;
		}
		n++;
		x = xd;
		cout << x << " " << n << endl;
	}while(1);
	return 0;
}



Measured memory_bytes: 3080
N,*E=map(int,open(0).read().split())
E=sorted((e,2*(i<N)-1)for i,e in enumerate(E))
a,c=1,0
for _,d in E:
	if c*d<0:
		a=(a*abs(c))%(10**9+7)
	c+=d
print(a)

Measured memory_bytes: 25948
package main

import (
	"fmt"
)

func main() {
	var N, X int
	fmt.Scanf("%d %d", &N, &X)
	var D, i int = 0, 0
	for i = 0; i < N; i++ {
		var Li, Di int
		fmt.Scanf("%d", &Li)
		Di = D + Li
		if Di > X {
			break
		} else {
			D = Di
		}
	}
	fmt.Printf("%d\n", i+1)
}


Measured memory_bytes: 512
#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)
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;

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

  vector<int> b(N);

  REP(i,N){
    int a;
    cin >> a;
    b[--a] = i;
  }

  REP(i,N-1){
    cout << b[i]+1 << " ";
  }
  cout << b[N-1]+1 << endl;

}



Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
using namespace std;
typedef long long int ll;

int main(){

  ll n, m;
  cin >> n >> m;
  if(n==1 && m==1){
    cout << 1 << endl;
    return 0;
  }
  if(n==1 || m==1){
    cout << n*m-2 << endl;
    return 0;
  } else if(n==2 || m==2){
    cout << 0 << endl;
    return 0;
  } else {
    cout << n*m-2*(n+m)+4 << endl;
  }
  
  return 0;
}


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

#define int long long
#define S second
#define F first

typedef long long ll;
typedef long double ld;

using namespace std;

const int INF = 1e9;
const int maxn = 1010;
const int mod = 1e9+7;

int n, m;
int dis[maxn][maxn];
bool mark[maxn][maxn];
queue<pair<int,int>> q;

int bfs()
{
    int mx = 0;
    while(q.size())
    {
        int x = q.front().F;
        int y = q.front().S;
        q.pop();
        mx = max(mx, dis[x][y]);

        if(!mark[x+1][y] && x+1 <= n)
        {
            mark[x+1][y] = 1;
            dis[x+1][y] = dis[x][y] + 1;
            q.push({x+1,y});
        }
        if(!mark[x-1][y] && x-1 >= 1){
            mark[x-1][y] = 1;
            dis[x-1][y] = dis[x][y] + 1;
            q.push({x-1,y});
        }
        if(!mark[x][y+1] && y+1 <= m)
        {
            mark[x][y+1] = 1;
            dis[x][y+1] = dis[x][y] + 1;
            q.push({x,y+1});
        }
        if(!mark[x][y-1] && y-1 >= 1)
        {
            mark[x][y-1] = 1;
            dis[x][y-1] = dis[x][y] + 1;
            q.push({x,y-1});
        }
    }

    return mx;
}

signed main()
{
    cin>> n >> m;
    for(int i = 1; i <= n; i++){
        string s; cin>> s;
        for(int j = 1; j <= m; j++)
            if(s[j-1] == '#'){
                mark[i][j] = 1;
                dis[i][j] = 0;
                q.push({i,j});
            }
    }

    cout<< bfs();
}




Measured memory_bytes: 25524
import java.util.Scanner;

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

        long sum;
        String input;
        while (true){
            sum = 0;
            input = scanner.nextLine();

            if(input.equals("0")){
                break;
            }

            String[] mash = input.split("");

            for(String txt : mash){
                sum += Integer.parseInt(txt);
            }
            System.out.println(sum);
        }
        scanner.close();
    }
}



Measured memory_bytes: 27240