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

int main() {
  int n,mc = 0,min = 1000000000+1;
  long long ans = 0;
  bool zf = false;
  cin >> n;
  for(int i = 0;i < n;i++){
    long long a;
    cin >> a;
    if(a == 0) zf = true;
    if(a < 0) mc++;
    if(abs(a) < min) min = abs(a);
    ans += abs(a);
  }
  if(zf || mc%2 == 0) cout << ans << endl;
  else cout << ans-2*min << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;


// 138_a
public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();

        double tmp = 0.0;
        for (int i = 0; i < n; i++) {
            tmp += 1.0 / scan.nextDouble();
        }

        System.out.println(1.0 / tmp);

    }

}


Measured memory_bytes: 22612
/*
Author: miitbh1
*/
#include <bits/stdc++.h>

#define rep(i, n) for(int i=0; i<n; i++)
#define repA(i, a, n) for(int i=a; i<n; i++)
#define repD(i, a, n) for(int i=a; i>=n; i--)
#define trav(it, ctr) for(auto it=ctr.begin(); it!=ctr.end(); it++)
#define p(x) cout<<x<<"\n"
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pp(x, y) cout<<x<<" "<<y<<"\n"
#define btc __builtin_popcount
#define all(x) x.begin(), x.end()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef priority_queue<int> pq;
typedef pair<int, int> ii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;
using ll=long long int;
const int N=100001;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cout<<fixed<<setprecision(10);
    ll a, b, c, y, k;
    cin>>a>>b>>c>>k;
    ll x=min(a, k);
    k-=x;
    if(k){
        y=min(b, k);
        k-=y;
        if(k){
            y=min(c, k);
            x-=y;
        }
    }
    p(x);
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define N_MAX 200002

using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

ll n, a, b;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

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


template <typename T>
T pow(T a, ll n){
    T ans = 1;
    T tmp = a;
    for(int i = 0; i <= 60; i++){
        ll m = (ll)1 << i;
        if(m&n){
            ans *= tmp;
            ans %= MOD;
        }
        tmp *= tmp;
        tmp %= MOD;
    }
    return ans;
}

ll comb(ll s, ll t){
    ll ans = 1;
    for(int i = 0; i < t; i++){
        ans *= (n-i);
        ans %= MOD;
    }
    for(int i = 0; i < t; i++){
        ans *= inv[i+1];
        ans %= MOD;
    }
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> n >> a >> b;
    init();
    ll ans = pow<ll>(2, n);
    ans -= comb(n, a);
    ans -= comb(n, b);
    ans--;
    ans %= MOD;
    ans += MOD;
    ans %= MOD;
    cout << ans << endl;
}

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

int main(int argc, char** argv)
{
  int n = 0;
  cin >> n;
  n %= 10;
  switch(n)
  {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
    default:
      break;
  }
  return 0;
}
      

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

int N, M;
bool used[100100];
deque<int> deq;
vector<int> G[100100];

void dfs(int v, bool f)
{
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        int to = G[v][i];
        if(!used[to]){
            if(f){
                deq.pb(to);
            }
            else {
                deq.pf(to);
            }
            dfs(to, f);
            break;
        }
    }
    return;
}

int main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    deq.pb(0);
    dfs(0, true);
    dfs(0, false);
    printf("%d\n", deq.size());
    while(deq.size()){
        printf("%d", deq.front() + 1);
        if(deq.size() > 1){
            printf(" ");
        }
        deq.pop_front();
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 11008
#include<bits/stdc++.h>
#include<cctype>
#define For(i,a,b) for(i=(a),i##end=(b);i<=i##end;++i)
#define Forward(i,a,b) for(i=(a),i##end=(b);i>=i##end;--i)
#define Rep(i,a,b) for(register int i=(a),i##end=(b);i<=i##end;++i)
#define Repe(i,a,b) for(register int i=(a),i##end=(b);i>=i##end;--i)
using namespace std;
template<typename T>inline void read(T &x){
	T s=0,f=1;char k=getchar();
	while(!isdigit(k)&&k^'-')k=getchar();
	if(!isdigit(k)){f=-1;k=getchar();}
	while(isdigit(k)){s=s*10+(k^48);k=getchar();}
	x=s*f;
}
const int MAXN=201001;
static int n,k,top;
static int cnt[MAXN];
typedef pair<int,int> Pr;
Pr sta[MAXN];
inline void init()
{
    read(n);read(k);
    static int x;
    Rep(i,1,n)read(x),++cnt[x];
    Rep(i,1,n)if(cnt[i])sta[++top].second=i,sta[top].first=cnt[i];
    sort(sta+1,sta+top+1);
}
inline void solve()
{
    if(top<=k)
    {
        printf("0\n");
        return;
    }
    else
    {
        static int sum=0;
        Repe(i,top,top-k+1)sum+=sta[i].first;
        printf("%d\n",n-sum);
    }
    
}
int main(void){
    init();
    solve();
	return 0;
}


Measured memory_bytes: 2688
#include<iostream>
using namespace std;
int main(){
  int n,r,l,cnt=0;
  bool end=false;
  cin >> n;
  int h[n],fh[100]={};
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  while(end==false){
    r=-1;
    l=-1;
    for(int i=0;i<n;i++){
      if(r==-1&&h[i]>fh[i]){
        r=i;
        continue;
      }
      if(r!=-1&&h[i]<=fh[i]){
        l=i-1;
        break;
      }
    }
    if(r==-1) break;
    if(l==-1) l = n-1;
    for(int i=r;i<=l;i++){
      fh[i]++;
    }
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,i,ans=0;cin>>N;ll A[N];
  REP(i,N)cin>>A[i];
  sort(A,A+N);i=0;
  while(i<N){
    ll j=i;
    while(j<N&&A[i]==A[j])j++;
    if(j-i>=A[i])ans+=j-i-A[i];
    else ans+=j-i;
    i=j;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    string s = "";
    for (int i = 0; i < b; ++i)
    {
        s += to_string(a);
    }
    string t = "";
    for (int i = 0; i < a; ++i)
    {
        t += to_string(b);
    }

    if( s < t ){
        cout << s << endl;
    }else{
        cout << t << endl;
    }

    return 0;
}

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

long cntDigits(long n);

int main() {
    long n, temp;
    cin >> n;
    for(long i = 1; i * i <= n; i++) {
        if(n % i == 0) temp = n / i;
    }
    cout << cntDigits(temp) << endl;
}

long cntDigits(long n) {
    long t = 0;
    while(n) {
        n /= 10;
        t++;
    }
    return t;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	long[] total = new long[N];
	long bsum = 0;
	for(int i = 0; i<N; i++) {
	    long a = sc.nextLong();
	    long b = sc.nextLong();
	    bsum += b;
	    total[i] =  a+b;
	}
	Arrays.sort(total);
	long ans = 0;
	for(int i = N-1; i>=0; i=i-2) {
	    ans += total[i];
	}
	ans = ans - bsum;
	System.out.println(ans);

    }
}

Measured memory_bytes: 88716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;

int main(){
    int n;
    cin >> n;
    ll ans=1;
    for(int i=1;i<=n;i++){
        ans*=i;
        ans%=mod;
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  string s;
  cin >> s;
  stack<char> sta;
  rep(i, 0, s.size()) {
    if(s[i] == 'T' && !sta.empty() && sta.top() == 'S') sta.pop();
    else sta.push(s[i]);
  }
  cout << sta.size() << endl;
}


Measured memory_bytes: 720
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner(System.in);
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		int n = cin.nextInt();
		int p = cin.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++)
			a[i] = cin.nextInt();

		long ans = solve(n, p, a);
		cout.println(ans);
	}

	private static long solve(int n, int p, int[] a) {
		boolean containsOdd = Arrays.stream(a).filter(val -> val % 2 == 1).count() != 0;
		if (containsOdd)
			return 1L << (n - 1);
		if (p == 0)
			return 1L << n;
		return 0;
	}

	static class FastScanner {
		private final InputStream in;
		private final byte[] buf = new byte[1 << 14];
		private int bufs = 0;
		private final long[] num = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
		private int ptr = 0;

		public FastScanner(InputStream in) {
			super();
			this.in = in;
		}

		boolean hasNext() {
			while (hasNextByte() && !isMeaningful(buf[ptr]))
				ptr++;
			return hasNextByte();
		}

		private boolean hasNextByte() {
			if (ptr < bufs)
				return true;
			ptr = 0;
			try {
				bufs = in.read(buf);
			} catch (IOException e) {
				throw new IllegalArgumentException(e);
			}
			if (bufs <= 0)
				return false;
			return true;
		}

		private static boolean isMeaningful(int b) {
			return 33 <= b && b <= 126;
			// return b != -1 && !Character.isWhitespace(b);
		}

		String next() {
			if (!hasNext())
				throw new IllegalArgumentException();
			StringBuilder sb = new StringBuilder();
			int b = read();
			while (isMeaningful(b)) {
				sb.appendCodePoint(b);
				b = read();
			}
			return sb.toString();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			long nl = nextLong();
			int ni = (int) nl;
			if (ni != nl)
				throw new IllegalArgumentException();
			return ni;
		}

		long nextLong() {
			if (!hasNext())
				throw new IllegalArgumentException();
			long n = 0;
			int plus = 1;
			int b = read();
			if (b == '-') {
				plus = -1;
				b = read();
			}
			if ('0' > b || b > '9')
				throw new java.lang.IllegalArgumentException();
			while (true) {
				if (!isMeaningful(b))
					return plus * n;
				n *= 10;
				n += num[b - '0'];
				b = read();
			}
		}

		private int read() {
			if (hasNextByte())
				return buf[ptr++];
			else
				return -1;
		}

	}
}


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

int main() {
    int n;
    cin >> n;
    int* a = new int[n];
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 0; i < n - 1; i++)
        cout << a[i] << ' ';
    cout << a[n - 1] << endl;
    void InsertionSort(int, int[]);
    InsertionSort(n, a);
    return 0;
}

void InsertionSort(int n, int a[]) {
    for(int i = 1, j; i < n; i++) {
        int temp = a[i];
        for(j = i - 1; j >= 0 && a[j] > temp; j--)
            a[j + 1] = a[j];
        a[j + 1] = temp;
        for(int m = 0; m < n - 1; m++)
            cout << a[m] << ' ';
        cout << a[n - 1] << endl;
    }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	int n;
	cin>>n;
	vector<int>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	int dp[n];
	dp[n-1]=0;
	dp[n-2]=abs(v[n-1]-v[n-2]);
	for(int i=n-3;i>=0;i--){
		int abs1=abs(v[i]-v[i+1]);
		int abs2=abs(v[i]-v[i+2]);
		dp[i]=min(abs1+dp[i+1],abs2+dp[i+2]);
	}
	// for(int i=0;i<n;i++){
	// 	cout<<dp[i]<<" ";
	// }
	// cout<<endl;
	cout<<dp[0]<<endl;
}

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

using namespace std;

int main() {
    int a = 0;
    int b = 0;
    int c = 0;
    cin >> a;
    cin >> b;
    cin >> c;
    int x = b - a;
    int y = c - b;
    if(x == y){
       cout << "YES" << endl;
    }
    else{
     cout << "NO" <<endl;

    }
    
                 
}

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

int main(){
    int N;
    cin >> N;
    string s;
    cout << 0 << endl;
    cin >> s;
    if (s == "Vacant") return 0;
    bool check = (s == "Male");
    cout << N-1 << endl;
    cin >> s;
    if (s == "Vacant") return 0;
    int l = 0;
    int r = N;
    while (r-l > 1) {
        int c = (l+r)/2;
        cout << c << endl;
        cin >> s;
        if ((s == "Male") ^ (!check) ^ (c%2==0)) r = c;
        else l = c;
    }
    cout << r << endl;
    cin >> s;
    return 0;
}


Measured memory_bytes: 852
S = input()

cnt_init_0 = 0
cnt_init_1 = 0

for i, s in enumerate(S):
    if s == "0":
        if i % 2 == 0:
            cnt_init_1 += 1
        else:
            cnt_init_0 += 1
    else:
        if i % 2 == 0:
            cnt_init_0 += 1
        else:
            cnt_init_1 += 1
print(min(cnt_init_0, cnt_init_1))


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  string str;
  cin >> str;
  if(str[0] == '9' || str[1] == '9'){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl '\n'
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;

signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll T;
    cin >> T;
    ll A;
    cin >> A;
    vector<ll> H(N,0);
    for(ll i=0;i<N;++i)cin>>H[i];
    vector<pair<ld,ll>> P(N);
    for(ll i=0;i<N;++i)P[i]=make_pair(T-0.006*H[i],i);
    pair<ld,ll> ans=make_pair((ld)10000000,INF);
    function<ll()> solve=[&]{
        for(ll i=0;i<N;++i){
            if(abs(ans.first-A)>abs(A-P[i].first)){
                ans=P[i];
            }
        }
        
        return  ans.second+1;
    };
    prt(solve())

    return 0;
}


Measured memory_bytes: 256
input = gets.chomp
testRegexp = /(\d{4})(\/)(\d{2})(\/)(\d{2})/
testRegexp =~ input

year =  $1.to_i
month = $3.to_i
day = $5.to_i

if year < 2019
	puts "Heisei"
else
	if month < 5
		puts "Heisei"
	else
		puts "TBD"
	end
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int p,q,r;
	cin >> p >> q >> r;
	int m = 10000;
	int a1 = p + q;
	int a2 = q + r;
	int a3 = r + p;
	int ans = min(a1, a2);
	ans = min(ans, a3);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
main(){float d,e,f,g,h,i,m,n,o,p,q;for(;~scanf("%f%f%f%f%f%f%f%f",&d,&e,&f,&g,&h,&i,&m,&n);puts(o*p>0&&p*q>0?"YES":"NO"))o=(f-d)*(n-e)-(m-d)*(g-e),p=(h-f)*(n-g)-(m-f)*(i-g),q=(d-h)*(n-i)-(m-h)*(e-i);return 0;}

Measured memory_bytes: 0
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    ll sum = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j += i) {
            sum += j;
        }
    }
    cout << sum << endl;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

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

int m, a, b, tp[50000];
vi p;

int getPrime(int sp){
  int k[3] = {100, 10, 1};
  int w = 0;
  rep(i, 3){
    for(int j = w; j < (int)p.size(); j+=k[i]){
      //      printf("%d\n", j);
      if(sp < p[j]) break;
      if(p[j]*sp <= m) w = j;
      else break;
    }
  }
  return p[w];
}

int main(){
  tp[0] = tp[1] = 1;
  REP(i, 2, 50000){
    if(tp[i]) continue;
    for(int j = i+i; j < 50000; j += i) tp[j] = 1;
  }

  rep(i, 50000){
    if(tp[i]) continue;
    p.PB(i);
  }

  //  printf("%d\n", (int)p.size());

  while(scanf("%d%d%d", &m, &a, &b) && m){
    int resq = 0, resp = 0;
    for(int i = 0; i < p.size() && p[i] * 2 <= m; i++){
      //    for(int i = getPrime(sqrt(m)); i * 2 <= m; i++){
      //      if(tp[i]) continue;
      int tq = p[i];
      int tp = getPrime(tq);
      //      printf("%d %d\n", tq, tp);
      if((double)a/(double)b > (double)tp/(double)tq) continue;
      if(resq * resp > tp * tq) continue;
      resq = tq;
      resp = tp;
    }

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

Measured memory_bytes: 1460
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int main(){
    while(1){
        int N,M;
        long long int moto[201];
        long long int ato[1001];
        cin>>N;
        if(N==0)break;
        for(int i=0;i<N;i++){
            long long int a,b;
            scanf("%lld %lld",&a,&b);
            moto[i]=a*1000001+b;
        }
        cin>>M;
        for(int i=0;i<M;i++){
            long long int a,b;
            scanf("%lld %lld",&a,&b);
            ato[i]=a*1000001+b;
        }
        ato[M]=1000000000000000000;
        sort(ato,ato+M+1);
        for(int i=0;i<M;i++){
            int fg=1;
            for(int j=1;j<N;j++){
                int l=0,r=M+1;
                for(int k=0;k<12;k++){
                    int mid=(l+r)/2;
                    if(moto[j]-moto[0]<=ato[mid]-ato[i])r=mid;
                    else l=mid;
                }
                if(moto[j]-moto[0]!=ato[r]-ato[i]||(moto[j]/1000001-moto[0]/1000001)!=(ato[r]/1000001-ato[i]/1000001))fg=0;
            }
            if(fg==1){
                cout<<(ato[i]/1000001-moto[0]/1000001)<<" "<<(ato[i]%1000001-moto[0]%1000001)<<endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int N,K;
    int t,d;
    vector<pair<int,int>> DT;
    cin >> N >> K;
    REP(i,N){
        cin >> t >> d;
        DT.push_back({d,t});
    }
    sort(DT.begin(),DT.end(),greater<>());
    vector<int> F,G;
    bool f[114514]={};
    REP(i,N){
        if(!f[DT[i].second]){
            F.push_back(DT[i].first);
            f[DT[i].second]=true;
        }else{
            G.push_back(DT[i].first);
        }
    }
    
    //REP(i,F.size()){cout << F[i] << " ";}cout << endl;
    //REP(i,G.size()){cout << G[i] << " ";}cout << endl;
    REP(i,(int)(F.size())-1){
        F[i+1]+=F[i];
    }
    REP(i,(int)(G.size())-1){
        G[i+1]+=G[i];
    }
    
    //REP(i,F.size()){cout << F[i] << " ";}cout << endl;
    //REP(i,G.size()){cout << G[i] << " ";}cout << endl;
    
    int Ans=0;
    REP(i,K+1){
        if(F.size()<i || G.size()<K-i)continue;
        int num=(i)*(i);
        if(i!=0){
            num+=F[i-1];
        }
        if(K-i!=0 && K-i-1<G.size()){
            num+=G[K-i-1];
        }
        //cout << i MM num << endl;
        Ans=max(Ans,num);
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 3696
package main

import "fmt"

const mod int = 1e9 + 7

func main() {
	var L string
	fmt.Scan(&L)
	n := len(L)

	dp := make([][2]int, n+1)
	dp[0][0] = 1

	for i := 0; i < n; i++ {
		if L[i] == '1' {
			dp[i+1][1] = dp[i][1]*3 + dp[i][0]
			dp[i+1][0] = dp[i][0] * 2
		} else {
			dp[i+1][0] = dp[i][0]
			dp[i+1][1] = dp[i][1] * 3
		}

		dp[i+1][0] %= mod
		dp[i+1][1] %= mod
	}

	ans := (dp[n][0] + dp[n][1]) % mod
	fmt.Println(ans)
}


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

typedef long long ll;

using namespace std;

ll MAX = 1e9+1;

void dfs(int i, vector<int>& dp, map<int, vector<int> >& g, set<int>& seen) {
    if (seen.find(i) != seen.end()) 
        return;
    for (int j : g[i]) {
        dfs(j, dp, g, seen);
        dp[i] = max(dp[i], 1 + dp[j]);
    }
    seen.insert(i);
}

void solve() {
    int n, m;
    map<int, vector<int> > g;
    set<int> seen;

    cin >> n >> m;

    vector<int> dp(n+1); // dp[i] denotes the longest path starting at vertex i
    // dp[i] = 1 + max of dp[j] where i-j is an edge

    for (int i = 0; i < m; i++) {
        int from, to;
        cin >> from >> to;
        g[from].push_back(to);
    }
    for (int i = 1; i <= n; i++) {
        if (seen.find(i) == seen.end()) {
            dfs(i, dp, g, seen);
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) 
        ans = max(ans, dp[i]);

    cout << ans << endl;
}


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





Measured memory_bytes: 20992
#include<iostream>
using namespace std;
#include<string.h>
#define rep(i, a, b) for(long long int i=(a); i<(b); i++)
int main(){
  string S;
  cin >> S;
  long long int cand=0;
  long long int res=0;
   if(S.length()<3){
     cout<<0<<endl;
     return 0;
  }
  
  rep(i,0,S.length()-2){
 
    if(S[i]=='A'&&S[i+1]=='B'&&S[i+2]=='C'){
      S[i+2]='A';
      res+=cand+1;
      //cand++;
      i++;
      //cout<<S<<" "<<res<<endl;
      continue;
    }else if(S[i]=='A'){
      cand++;
      continue;
    }
    cand = 0;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

    public double nextDouble() {
      return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    long[] a = sc.nextLongArray(n);
    Arrays.sort(a);
    PriorityQueue<long[]> pq = new PriorityQueue<>((long[] x, long[] y) -> {
      long minX = Math.min(x[0], x[1]);
      long maxX = Math.max(x[0], x[1]);
      long minY = Math.min(y[0], y[1]);
      long maxY = Math.min(y[0], y[1]);
      if (minY != minX) return minY > minX ? 1 : -1;
      return maxY > maxX ? 1 : -1;
    });
    pq.add(new long[] {a[n - 1], a[n - 2]});
    pq.add(new long[] {a[n - 1], a[n - 2]});
    long sum = a[n - 1];
    for (int i = n - 3; i >= 0; i--) {
      long[] span = pq.poll();
      sum += Math.min(span[0], span[1]);
      pq.add(new long[] {span[0], a[i]});
      pq.add(new long[] {span[1], a[i]});
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 66592
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define pb push_back
#define N 200001
#define ll long long
#define int ll 
#define pi pair<int , int>
#define pip pair<pair ,int>
#define mp make_pair 
#define f first
#define s second
#define mod 998244353
ll Mod(ll x, ll y, int p) 
{ll res = 1; x = x % p;
while (y > 0) 
{if(y & 1) res = (res*x) % p; 
y = y>>1;x = (x*x) % p; 
}return res; 
}
int* getlps(string pattern){
 int len = pattern.length();
 int * lps = new int[len];
 lps[0] = 0;
 int i = 1 , j = 0;
 while(i < len){
  if(pattern[i] == pattern[j]){
	  lps[i] = j+1;
   i++;
   j++;
  }
  else{
		if(j != 0){
		 j = lps[j-1];
		}
		else{
		 lps[i] = 0;
		 i++;
		}
  }
 }
 return lps;
}
class Triplet{
 public:
 int x ;
 int y ;
 int gcd;
};
Triplet extendedEuclid(int a , int b){
 if(b == 0){Triplet ans; ans.gcd = a;ans.x = 1;ans.y = 0;return ans;}
 Triplet smallAns = extendedEuclid(b , a%b);
 Triplet ans;
 ans.gcd = smallAns.gcd;
 ans.x = smallAns.y;
 ans.y = smallAns.x - (a/b)*smallAns.y;
 return ans;
}
int mmInverse(int a , int m){
 Triplet ans = extendedEuclid(a , m);
 return ans.x;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a , b;
cin>>a>>b;
string str1;
for(int i = 0 ; i < b ; i++){
 str1 += a + '0';
}
string str2;
for(int i = 0 ; i < a; i++){
 str2 += b + '0';
}
if(str1 <= str2){
 cout<<str1<<endl;
}
else{
 cout<<str2<<endl;
}
}


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

int main (){
 ll n; cin >> n;
 ll sum=0;ll cnt,num;

  vector<char> ans;
  while(n>0){
    if(n%26!=0){
    ll a=n%26;  char c=a+'`';
    ans.push_back(c);
    }
    else{
      ans.push_back('z');
      n--;
    }
    n/=26;
  }
  for(ll i=ans.size()-1;i>=0;i--)cout << ans[i];
}


Measured memory_bytes: 3632
A = list(input())
B = list(input())
C = list(input())

d = A.pop(0)
while True:
    if d == "a":
        if len(A) == 0:
            print("A")
            break
        else:
            d = A.pop(0)
    elif d == "b":
        if len(B) == 0:
            print("B")
            break
        else:
            d = B.pop(0)
    elif d == "c":
        if len(C) == 0:
            print("C")
            break
        else:
            d = C.pop(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007

void solve()
{
	ll a,b,x;
	cin>>a>>b>>x;
    if(a%x==0)
        cout<<b/x-a/x+1;
    else 
    	cout<<b/x-a/x<<endl;
	return;
}

int main()
{
	fast;
	ll q=1;
	// cin>>q;
	while(q--)
		solve();
	return 0;
}



Measured memory_bytes: 3652
#include<stdio.h>
#define MAX 100001
#define NIL -1
struct Node {
    int p,l,r;
};
struct Node T[MAX];
int n;
void preParse(int u){
    if(u == NIL) return;
    printf(" %d",u);
    preParse(T[u].l);
    preParse(T[u].r);
}
void inParse(int u){
    if(u == NIL) return;
    inParse(T[u].l);
    printf(" %d",u);
    inParse(T[u].r);
}
void postParse(int u){
    if(u == NIL)return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d",u);
}
int main(){
    int i,v,l,r,root;
    scanf("%d",&n);
    for(i = 0;i < n;i++){
        T[i].p = NIL;
    }
for(i = 0;i < n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL){
        T[l].p = v;
    }
    if(r != NIL){
        T[r].p = v;
    }
}
for(i = 0;i < n;i++){
    if(T[i].p == NIL){
        root = i;
    }
}
printf("Preorder\n");
preParse(root);
printf("\n");
printf("Inorder\n");
inParse(root);
printf("\n");
printf("Postorder\n");
postParse(root);
printf("\n");
return 0;
}


Measured memory_bytes: 2120
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
  string a,b;
  cin>>a>>b;
  int len1=a.size();
  int len2=b.size();
  if(len1>len2)cout<<"GREATER";
  else if(len2>len1)cout<<"LESS";
  else
  {
      int carry=0,g=0;
      for(int i=0;i<len1;i++)
      {
          if(a[i]!=b[i])
          {
              g=1;
              break;
          }
      }
      if(g==0)
      {
          cout<<"EQUAL";
          return 0;
      }
      for(int i=len1-1;i>=0;i--)
      {
          int p=a[i]-'0';
          int q=b[i]-'0';
          q+=carry;
          if(p-q<0)
          {
              carry=1;;
          }
          else
          {
              carry=0;
          }
      }
      if(carry)printf("LESS");
      else cout<<"GREATER";
  }
}



Measured memory_bytes: 3692
#include<stdio.h>
#include<string>
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

int prime(int a, int b) {
	if (a % 2 != 0)return b;
	else {
		b++;
		prime(a / 2, b);
	}
}


int main(void) {
	int N, num = 0, x = 0;
	int *a;
	cin >> N;
	a = (int*)malloc(sizeof(int)*N);
	for (int i = 0;i < N;i++)cin >> a[i];
	x = prime(a[0], num);
	for (int i = 1;i < N;i++) {
		if (prime(a[i], num) <= x) {
			x = prime(a[i], num);
			num = 0;
		}
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
ll a[N],dp[N],sum[N];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i]=(i>2?sum[i-2]:0)+a[i];
	}
	for(int i=2;i<=n;i++)
	{
		if(i&1) dp[i]=max(dp[i-1],dp[i-2]+a[i]);
		else dp[i]=max(sum[i-1],dp[i-2]+a[i]);
	}
	printf("%lld\n",dp[n]);
	return 0;
}

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

int main(){
  int n,m;
  vector<int> v;
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    int a,b;
    cin >> a >> b;
    v.push_back(a);
  }
  int res = 0;
  sort(v.begin(),v.end(),greater<int>());
  for(int i = 0;i < m - 1;i++){
    if(n > v[i]) res += n - v[i];
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n;
  cin >> n;
  vector<int> v{111, 222, 333, 444, 555, 666, 777, 888, 999};
  cout << *lower_bound(all(v), n) << endl;
  return 0;
}

Measured memory_bytes: 256
#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 ss, h, m, s;
    cin >> ss;
    h = ss / 3600;
    m = (ss % 3600) / 60;
    s = (ss % 3600) % 60 ;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3088
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
const llint mod=1000000007;
const llint big=1.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int LBI(vector<lldo>&ar,lldo in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
int UBI(vector<lldo>&ar,lldo in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,i;cin>>n;
	vector<int>aa(n);
	for(i=0;i<n;i++){cin>>aa[i];}
	auto bb=aa;
	SO(bb);
	for(i=0;i<n;i++){
		if(aa[i]<=bb[n/2-1]){cout<<bb[n/2]<<endl;}
		else{cout<<bb[n/2-1]<<endl;}
	}
	return 0;
}

Measured memory_bytes: 3712
const main = (inputs) => {
  var N = inputs[0].split(" ")[0]-0;
  var X = inputs[0].split(" ")[1]-0;
  var l = inputs[1].split(" ").map(v=>v-0);
  var ans = 0;
  var pos = 0;
  for(var i=0;i<l.length;i++){
    if(pos<=X){
      ans ++;
    }
    pos += l[i];
  }
  if(pos<=X){
    ans ++;
  }
  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 21064
n = int(raw_input().rstrip("\n"))
ring = raw_input().rstrip("\n")
ring = ring + ring[0]

answers = []
answers.append([True,True])
answers.append([True,False])
answers.append([False,True])
answers.append([False,False])

sw = {True:"S",False:"W"}
result = None
for answer in answers:
  for i in xrange(n):
    if (answer[i+1] == True and ring[i+1] == "o") or (answer[i+1] == False and ring[i+1] == "x"):
       answer.append(answer[i])
    else:
       answer.append(not answer[i])   
  #print answer, answer[0:2],answer[-2:]
  if answer[0:2] == answer[-2:]:
    result= "".join([sw[is_sheep] for is_sheep in answer[:n]])
    break
    #print result

if result:
  print result
else:
  print -1


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

int main() {
	int x;
	cin>>x;
	if(x>=400 && x<600)
	cout<<"8\n";
		if(x>=600 && x<800)
	cout<<"7\n";
		if(x>=800 && x<1000)
	cout<<"6\n";
		if(x>=1000 && x<1200)
	cout<<"5\n";
		if(x>=1200 && x<1400)
	cout<<"4\n";
		if(x>=1400 && x<1600)
	cout<<"3\n";
		if(x>=1600 && x<1800)
	cout<<"2\n";
		if(x>=1800 && x<2000)
	cout<<"1\n";
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  double sum = 0;
  for(int i = 0;i < n;i++) {
    double x;
    string s;
    cin >> x;
    cin >> s;
    if(s == "JPY") {
      sum += x;
    }else {
      sum += x * 380000.0;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

ll N,M,V,P; 
vector<ll> A;
bool f(ll k) {
    if (k < 0) return false;
    if (k >= N) return true;
    vector<ll> B = A;
    vector<ll> C(N);
    ll p = A[k] + M;
    ll sump = M*V;
    ll v = 0;
    while (v < N && B[v] < p && sump > 0) {
        ll val = min({p - B[v],sump,M});
        B[v] += val;
        sump -= val;
        C[v] = val;
        v++;
    }
    v = N-1;
    while (v >= 0 && sump > 0) {
        ll val = min({sump,M,M-C[v]});
        B[v] += val;
        sump -= val;
        v--;
    }

    sort(all(B));
    ll x = upper_bound(all(B),p) - B.begin();
    if (N - x >= P) return false;
    else return true;
}
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    cin >> N >> M >> V >> P;
    A.resize(N);
    rep(i,N) cin >> A[i];

    sort(all(A));
    ll left = -1;
    ll right = N;
    while (left + 1 < right) {
        ll mid = left + (right - left) / 2LL;
        if (f(mid)) right = mid;
        else left = mid;
    }

    cout << N - right << endl;
}

Measured memory_bytes: 2672
use std::io;
use std::str::FromStr;

fn main(){
    let stdin = io::stdin();
    let mut buf = String::new();
    let mut man = [[[0; 10]; 3]; 4];

    let _ = stdin.read_line(&mut buf);
    let n = i64::from_str(buf.trim()).unwrap();
    buf.clear();

    for _ in 0..n {
        let _ = stdin.read_line(&mut buf);
        let vec : Vec<i64> = buf.split_whitespace().map(|x| i64::from_str(x).unwrap()).collect();
        buf.clear();
        let (b,f,r,v) = (vec[0] as usize, vec[1] as usize, vec[2] as usize, vec[3]);

        man[b-1][f-1][r-1] += v;
    }

    let mut out: Vec<String> = vec![];
    for x in man.iter() {
        for y in x.iter() {
            let z : Vec<String> = y.iter().map(|a| a.to_string()).collect();
            buf = format!("{} {}\n", buf, z.join(" "));
        }
        out.push(buf.to_string());
        buf.clear();
    }
    print!("{}", out.join(&("#".repeat(20)+"\n")));
}



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

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input;
		long a, b;
		while ((input = br.readLine()) != null) {
			String[] arr  = input.split(" ");
			a = Integer.parseInt(arr[0]);
			b = Integer.parseInt(arr[1]);
			System.out.println(gcd(a, b) + " " + lcm(a, b));
		}
	}
	private static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}
	private static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;

const ll mod = 1e9 + 7;
int n, k;
int A[2005];
void input() {
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> A[i];
}

void calc() {
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (A[i] <= A[j]) continue;
            if (i < j) ans += k * (k + 1ll) / 2;
            else ans += k * (k - 1ll) / 2;
            ans %= mod;
        }
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    input();
    calc();
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





const ll dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const ll dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const ll dy4[4] = {-1, 0, 1, 0};
const ll dx4[4] = {0, 1, 0, -1};

int main() {
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    vector<string> c(h);
    vector<vector<bool>> bomb(h, vector<bool>(w));
    ll sy, sx, gy, gx;
    REP(i, h){
        cin >> c[i];
        REP(j, w){
            if(c[i][j] == '*'){
                bomb[i][j] = true;
                REP(k, 8){
                    ll yy = i + dy8[k], xx = j + dx8[k];
                    if(yy < 0 || yy >= h || xx < 0 || xx >= w) continue;
                    bomb[yy][xx] = true;
                }
            }
            if(c[i][j] == 's'){
                sy = i;
                sx = j;
            }
            if(c[i][j] == 'g'){
                gy = i;
                gx = j;
            }
        }
    }
    
    vector<vector<vector<pair<ll, pair<ll, ll>>>>> g(h, vector<vector<pair<ll, pair<ll, ll>>>>(w));
    REP(i, h){
        REP(j, w){
            REP(k, 4){
                ll yy = i + dy4[k], xx = j + dx4[k];
                if(yy < 0 || yy >= h || xx < 0 || xx >= w || c[yy][xx] == '#') continue;
                g[i][j].push_back({a, {yy, xx}});
            }
            if(!bomb[i][j]){
                REP(k, 8){
                    ll yy = i + dy8[k], xx = j + dx8[k];
                    if(yy < 0 || yy >= h || xx < 0 || xx >= w) continue;
                    g[i][j].push_back({a * (1 + (k % 2)) + b, {yy, xx}});
                }
            }
        }
    }
    vector<vector<ll>> dist(h, vector<ll>(w, INF));
    using T = pair<ll, pair<ll, ll>>;
    priority_queue<T, vector<T>, greater<T>> que;
    que.push({0, {sy, sx}});
    while(!que.empty()){
        auto tmp = que.top(); que.pop();
        ll cost = tmp.first, y = tmp.second.first, x = tmp.second.second;
        if(dist[y][x] <= cost) continue;
        dist[y][x] = cost;
        for(auto &e : g[y][x]){
            que.push({cost + e.first, {e.second.first, e.second.second}});
        }
    }
    if(dist[gy][gx] != INF) cout << dist[gy][gx] << endl;
    else cout << "INF" << endl;
}


Measured memory_bytes: 239084
#include "bits/stdc++.h"
#define all(v) (v).begin(), (v).end()
using namespace std;
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define int long long
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
	int ans = 1;
	for (; b; b >>= 1, a = a * a % mod)
		if (b & 1)
			ans = ans * a % mod;
	return ans;
}
const int N = 1e6;
int fac[N], inv[N];

int cal(int n, int m)
{
	if (n <= 0 || m < 0 || m > n)
		return 0;
	return fac[n] * inv[m] % mod * inv[n - m] % mod;
}
signed main()
{
	fac[0] = 1;
	inv[0] = 1;

	rep(i, 1, N - 1) fac[i] = fac[i - 1] * i % mod;
	rep(i, 1, N - 1) inv[i] = ksm(fac[i], mod - 2);
	//	cout<<cal(5,2);
	int ans = 1;
	int n, k;
	cin >> n >> k;
	k = min(k, n - 1);
	rep(i, 1, k)
	{
		int f = 1;
		ans += cal(n, i) * cal(n - 1,i) * f;
		ans %= mod;
		//
			//cout<<i<<" "<<ans<<endl;
	}
	cout << (ans + mod) % mod << endl;

	getchar();
	getchar();
}


Measured memory_bytes: 15872