akhauriyash/Code-Regression huggingface dataset:
#pragma once
#include <stdio.h>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

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

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

// res[i][c] := i 文字目以降で最初に文字 c が登場する index (存在しないときは n)
vector<vector<int> > calcNext(const string& S) {
	int n = (int)S.size();
	vector<vector<int> > res(n + 1, vector<int>(26, n));
	for (int i = n - 1; i >= 0; --i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i + 1][j];
		res[i][S[i] - 'a'] = i;
	}
	return res;
}

void solv() {
	ll n, k;
	cin >> n >> k;
	ll r = n - k;
	for (ll i = 1; i <= k; i++)
	{
		ll di = COM(r + 1, i);
		ll b = COM(k - 1, i - 1);
		ll v = (di * b) % INF;
		cout << v << endl;
	}
}

int main() {
	COMinit();
	solv();

	return 0;
}
 

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main(){
    long k,s;
    cin>>k>>s;
    long count=0;
    for(int x = 0; x<=k; x++){
        for(int y = 0; y<= k; y++){
            if(s-x-y<=k&&s-x-y>=0)
                    count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
#include <ios>
#include <iomanip>
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>

using namespace std;
typedef long long int ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    vector<ll> lst;
    rep(i, N){
        ll c;
        cin >> c;
        lst.push_back(c);
    }
    vector<ll> ans;
    while(lst.size() > 0) {
        bool flag = false;
        for(ll i = lst.size()-1; i >= 0; i--) {
            if (lst[i] == i+1) {
                ans.push_back(i+1);
                lst.erase(lst.begin() + i);
                flag = true;
                break;
            }
        }
        if (!flag) {
            print(-1);
            return 0;
        }
    }
    if (ans.size() == N) {
        rep(i, N) {
            print(ans[N-1-i]);
        }
    } else print(-1);
    return 0;
}


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

struct ModInt {
    using M = ModInt;

    static vector<M> fact, finv;
    static long long MOD;
    long long v;

    // normalize: [-MOD, MOD**2] -> [0, MOD)
    ModInt(const long long _v = 0) : v((_v < 0) ? _v % MOD + MOD : _v % MOD) {}

    M operator+(const M& x) const { return M(v + x.v); }
    M operator-(const M& x) const { return M(v - x.v); }
    M operator*(const M& x) const { return M(v * x.v); }
    M operator/(const M& x) const { return M(v * x.inv().v); }
    M& operator+=(const M& x) { return *this = *this + x; }
    M& operator-=(const M& x) { return *this = *this - x; }
    M& operator*=(const M& x) { return *this = *this * x; }
    M& operator/=(const M& x) { return *this = *this / x; }
    bool operator==(const M& x) const { return v == x.v; }
    bool operator!=(const M& x) const { return v != x.v; }
    friend istream& operator>>(istream& input, M& x) {
        return input >> x.v, x = M(x), input;
    }
    friend ostream& operator<<(ostream& output, const M& x) {
        return output << x.v;
    }
    inline M pow(long long n) const {
        M x(v), res(1);
        while (n) {
            if (n & 1) res *= x;
            x *= x;
            n >>= 1;
        }
        return res;
    }
    inline M inv() const { return this->pow(MOD - 2); }
    static void build(int n) {
        fact.assign(n + 1, 1);
        for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
        finv.assign(n + 1, fact[n].inv());
        for (int i = n; i > 0; i--) finv[i - 1] = finv[i] * M(i);
    }
    static M comb(int n, int k) {
        if (n < k || k < 0) return M(0);
        return fact[n] * finv[n - k] * finv[k];
    }
    static M perm(int n, int k) { return fact[n] * finv[n - k]; }
    static M extgcd(int a, int b, int& x, int& y) {
        M d(a);
        if (b) {
            d = extgcd(b, a % b, y, x);
            y -= (a / b) * x;
        } else {
            x = 1;
            y = 0;
        }
        return d;
    }
};
vector<ModInt> ModInt::fact = vector<ModInt>();
vector<ModInt> ModInt::finv = vector<ModInt>();
long long ModInt::MOD = 1e9 + 7;

int main() {
    int n, m;
    cin >> n >> m;
    ModInt::build(m);
    ModInt ans = 0;
    for (int i = 0; i <= n; i++) {
        ModInt p = ModInt::perm(m - i, n - i) * ModInt::comb(n, i);
        if (i & 1) p *= -1;
        ans += p;
    }
    ans *= ModInt::perm(m, n);
    cout << ans << endl;
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e15;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;


int main() {

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    int ans = min(a, b) + min(c, d);

    cout << ans << endl;

}

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

 int main()
 {
 	int n, h, w, a[1000], b[1000], ans = 0;
 	cin >> n >> h >> w;
 	for(int i = 0; i < n; i++){
 		cin >> a[i] >> b[i];
 		if(a[i]>=h and b[i]>=w) ans++;
 	}
 	cout << ans << endl;
 	return 0;
 }

Measured memory_bytes: 256
/*
    
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1000000,ha=998244353;
inline int add(int x,int y){ x+=y; return x>=ha?x-ha:x;}
inline void ADD(int &x,int y){ x+=y; if(x>=ha) x-=ha;}

inline int ksm(int x,int y){
	int an=1;
	for(;y;y>>=1,x=x*(ll)x%ha) if(y&1) an=an*(ll)x%ha;
	return an;
}

int jc[maxn+5],ni[maxn+5],n,m,ans;

inline int C(int x,int y){ return x<y?0:jc[x]*(ll)ni[y]%ha*(ll)ni[x-y]%ha;}

inline void init(){
	jc[0]=1;
	for(int i=1;i<=maxn;i++) jc[i]=jc[i-1]*(ll)i%ha;
	ni[maxn]=ksm(jc[maxn],ha-2);
	for(int i=maxn;i;i--) ni[i-1]=ni[i]*(ll)i%ha;
}

inline void solve(){
	for(int i=1;i<=m;i++)
	    ADD(ans,C(i<<1,i)*(ll)C(n+m-i*2,n-i)%ha);
	
}

int main(){
	init();
	
	scanf("%d%d",&n,&m);
	if(n<m) swap(n,m);
	
	solve();
	
	ans=ans*(ll)ni[2]%ha*(ll)ksm(C(n+m,n),ha-2)%ha;

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


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        string S;
        cin >> S;
        ll mn = inf;
        rep(i, 0, len(S)-2) {
                string ss = S.substr(i, 3);
                ll num = stoll(ss);
                chmin(mn, abs(num-753));
        }
        cout << mn << endl;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int N; cin >> N;
  vector<int> x(N), y(N);
  rep(i, N) cin >> x[i] >> y[i];
  map<pair<int, int>, int> mp;
  rep(i, N) {
    mp.emplace(make_pair(x[i], y[i]), i);
  }
  set<pair<int, int>> pqs;
  rep(i, N) REP(j, i + 1, N) {
    auto p = x[i] - x[j], q = y[i] - y[j];
    pqs.emplace(p, q);
    pqs.emplace(-p, -q);
  }
  int ans = inf;
  for (auto pq: pqs) {
    auto p = pq.first, q = pq.second;
    int cnt = 0;
    rep(i, N) {
      cnt += !mp.count(make_pair(x[i] - p, y[i] - q));
    }
    ans = min(ans, cnt);
  }
  if (ans == inf) {
    cout << "1\n";
  } else {
    cout << ans << "\n";
  }
}


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


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

int main()
{
  int a,b;
  cin >> a >> b;
  
  string s;
  cin >> s;
  
  if(s[a] != '-'){
    cout << "No" << endl;
    return 0;
  }
  
  for(int i = 0; i < a+b+1; i++){
    if(i == a){
      continue;
    }
    if( !((s[i] - '0') >= 0 && (s[i] - '0') <= 9) ){
      cout << "No" << endl;
      return 0;
    }
  }//for
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 3620
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] p = new int[M];
        String[] S = new String[M];
        boolean[] isCleared = new boolean[N];
        int AC = 0;
        int[] WA = new int[N];

        for (int i = 0; i < M; i++) {
            p[i] = sc.nextInt();
            S[i] = sc.next();
        }
        for (int i=0;i <N;i++) {
            isCleared[i] = false;
        }

        for(int i= 0; i< M;i++){
            if(S[i].equals("AC") && !isCleared[p[i]-1]){
                AC++;
                isCleared[p[i]-1] = true;
            } else if(S[i].equals("WA") && !isCleared[p[i]-1]){
                WA[p[i] -1]++;
            }
        }
        int WAinAC = 0;
        for(int i=0;i <N;i++){
            if(isCleared[i]){
                WAinAC+= WA[i];
            }
        }

        System.out.println(AC + " "+ WAinAC);
    }
}


Measured memory_bytes: 72712
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int d, e, y;
  cin >> d >> e;
  
  for( int a = 0; a < 10; a++){
    for ( int b = 0; b < 10; b++){
      for ( int c = 0; c< 10; c++){
        int x = 10001*a + 1010*b + 100*c;
        if ( x >= d && x <= e){
          y++;
        }
      }
    }
  }
  cout << y << endl;
}


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

int main(){
	int i,q;
	cin >> q;
	for(i=0;i<q;i++){
		long long a,b,c,d,ans1,ans2;
		cin >> a >> b;
		if(a>b){
			long long x;
			x = a;
			a = b;
			b = x;
		}
		if(b-a==1 || a==b){
			cout << 2*(a-1) << endl;
		}else{
			long long l = -1,r = 1000000000,mid;
			while(r-l>1){
				mid = (l+r)/2;
				if(mid*mid>a*b){
					r = mid;
				}else{
					l = mid;
				}
			}
			c = l;
			l = -1; r = 1000000000;
			while(r-l>1){
				mid = (l+r)/2;
				if(mid*(mid+1)>a*b){
					r = mid;
				}else{
					l = mid;
				}
			}
			d = l;
			if(c*c==a*b){
				ans1 = 2*c-3;
			}else{
				ans1 = 2*c-2;
			}
			
			if(d*(d+1)==a*b){
				ans2 = 2*d-3;
			}else{
				ans2 = 2*d-1;
			}
			cout << max(ans1,ans2) << endl;
		}
	}
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <climits>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <tuple>
#define ll long long
#define rep(i,s,n) for(ll i = (ll)(s); i < (ll)(n); i++)
#define all(a) (a).begin(),a.end()
#define mod 1000000007
using namespace std;
using graph =vector<vector<ll>>;
/*階乗*/
ll factorial(ll n){
    if(n==0){
        return 1;
    }
    else{
        return (n%mod)*(factorial(n-1)%mod);
    }
}

/* ユークリッドの互除法 最大公約数*/
ll gcd(ll a, ll b) {
	return b ? gcd(b,a%b) : a;
}



/*最小公倍数*/

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}


/*二点間の距離*/
double dist(pair<double,double> a,pair<double,double> b){
	return sqrt(pow((a.first - b.first) ,2) + pow((a.second - b.second),2));
}

//繰り返し自乗法
double ism(double aa,ll p){
    double ap=aa;
    double ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans*=ap;
        }
        p/=2;
        ap=ap*ap;
    }
    return ans;

}
//繰り返し自乗法(アマリトリバージョン)
ll ismm(ll aa,ll p,ll m){
    ll ap=aa;
    ll ans=1;
    while(p>0){
        //cout<<"p="<<p<<",ap="<<ap<<endl;
        if(p&1){//奇数が真
            ans=(ans*ap)%m;    
        }
        p/=2;              
        ap=(ap*ap)%m;
    }
    return ans;

}
/*
ll solve(ll i,ll m,vector<ll>t,ll n){
    if(m==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    
    
    cout<<i+1<<" "<<m<<endl;
    cout<<i+1<<" "<<m-t[i]<<endl;
    ll res=solve(i+1,m,t,n)||solve(i+1,m-t[i],t,n);
    return res;
}
*/

//小数点12桁
struct all_init
{
    all_init()
    {
        cout << fixed << setprecision(12);
    }
} All_init;


int main()
{
    double l;
    cin>>l;
    cout<<pow(l/(3.0),3)<<endl;
    
}


Measured memory_bytes: 256
# 解説を見た。
def main():
    days = int(input())
    happiness = [[int(x) for x in input().split()] for _ in range(days)]

    dp = [[0] * 3 for _ in range(days)]
    # dp[i][j]=(i日目に行動jをして、i日目までに得られる幸福度の和の最大値)
    dp[0] = happiness[0]
    selection = set((0, 1, 2))
    for i in range(1, days):
        for sel in selection:
            dp[i][sel] = max(
                dp[i - 1][not_sel] for not_sel in selection - set((sel,))
            ) + happiness[i][sel]
    print(max(dp[days - 1][sel] for sel in selection))


if __name__ == '__main__':
    main()


Measured memory_bytes: 105080
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    ll d = c-a-b;
    if (d > 0 && d*d > 4*a*b) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}

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

using namespace std;
using ll = long long;

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << #x << ": " << x << endl;

const ll MOD = (ll) 1e9 + 7;
const int SIZE = 200010;

ll f[SIZE], rf[SIZE];
ll p2[SIZE];

ll inv(ll x) {
    ll res = 1;
    ll k = MOD - 2;
    ll y = x;
    while (k) {
        if (k & 1) res = (res * y) % MOD;
        y = (y * y) % MOD;
        k /= 2;
    }
    return res;
}

void init() {
    f[0] = 1;
    for (int i = 1; i < SIZE; i++) f[i] = (f[i - 1] * i) % MOD;
    for (int i = 0; i < SIZE; i++) rf[i] = inv(f[i]);
    p2[0] = 1LL;
    for (int i = 1; i < SIZE; i++)p2[i] = p2[i - 1] * inv(2) % MOD;
}

//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
    if (n < k)return 0LL;
    ll a = f[n]; // = n!
    ll b = rf[n - k]; // = (n-k)!
    ll c = rf[k]; // = k!

    ll bc = (b * c) % MOD;

    return (a * bc) % MOD;
}


int main() {
    init();
    int b, w;
    cin >> b >> w;
    ll pb = 0, pw = 0;
    for (int i = 1; i <= b + w; i++) {
        cout << (pb + (1LL - pb - pw + (2LL * MOD)) % MOD * inv(2) % MOD) % MOD << endl;
        pb += p2[i] * C(i - 1, w - 1) % MOD;
        pw += p2[i] * C(i - 1, b - 1) % MOD;
        if (pb >= MOD)pb -= MOD;
        if (pw >= MOD)pw -= MOD;
    }

    return 0;
}

Measured memory_bytes: 6912
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

n=int(input())
lst=sorted(map(int,input().split()))

p=make_divisors(lst[0])
q=make_divisors(lst[1])
pq=set(p+q)
pq=sorted(pq)
for i in range(len(pq)-1,-1,-1):
    out=0
    for j in lst:
        if j%pq[i]!=0:
            out+=1
    if out<=1:
        print(pq[i])
        exit()

Measured memory_bytes: 84864
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000005
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, v, p; ll m;
ll a[MN];

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

    cin >> n >> m >> v >> p;
    F0R(i, n){
        cin >> a[i];
    }
    sort(a, a+n);

    int l = -1, r = n-1;
    while(l+1<r){
        int mid = (l+r)/2;
        ll res = m+a[mid];
        ll ch = max(0LL, m*(v-p));
        ll cur = 0;
        //cout << mid << " " << res << " " << ch << " ";
        F0R(i, n-p+1){
            if(mid == i) continue;
            if(res < a[i]){
                cur = -1;
                break;
            }
            cur += min(res-a[i], m);
            //cout << cur << " ";
        }
        //cout << cur << "\n";
        if(cur >= ch){
            r = mid;
        } else{
            l = mid;
        }
    }
    cout << n-r << "\n";

    /*a[n] = INF;
    ll co1 = max(0LL, v-(p-1LL));
    ll co2 = max(0LL, a[n-p]-m);
    cout << co1 << " " << co2 << "\n";
    int v1 = lower_bound(a, a+n, max(a[co1], co2)) - a;
    cout << n-v1 << "\n";*/

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
  
constexpr double eps = 1e-12;
double deg2rad(double x) { return x / 360 * (2 * M_PI); }
double frem(double x, double y) { return fmod(fmod(x, y) + y + eps, y); }
enum face_t { ABC, ACD, ADB, BCD };
  
face_t get_face() {
    string xy; int d, l; cin >> xy >> d >> l;
    double face_theta =
        xy == "BC" ? 0 :
        xy == "CD" ? 60 :
        xy == "DB" ? 120 :
        NAN;
    double theta = deg2rad(face_theta + d);
    double x = l * cos(theta);
    double y = l * sin(theta);
    double z60 = x + y / sqrt(3);
    double z120 = - x + y / sqrt(3);
    z60 = frem(z60, 2);
    z120 = frem(z120, 2);
    double w = (z60 + z120) * (sqrt(3) / 2);
    return
        w < sqrt(3) / 2 ?
            ACD :
        w < sqrt(3) ?
            z60 > 1 ? ABC :
            z120 > 1 ? ADB :
            BCD :
        w < 3 * sqrt(3) / 2 ?
            z60 < 1 ? ABC :
            z120 < 1 ? ADB :
            BCD :
        ACD;
}
  
int main() {
    face_t a = get_face();
    face_t b = get_face();
    cout << (a == b ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3452
#include <stdio.h>
int main(){
	char st[123];
	int posidif = 0, sz = 0;
	long long d;
	scanf("%s", st);
	while(st[sz++] != '\0');
	for(int i = 0; i < sz-1; ++i){
		if(st[i] != '1'){
			posidif = i;
			break;
		}
	}
	scanf("%lld", &d);
	d--;
	if(d < posidif){
		printf("%c\n", st[d]);
	}else{
		printf("%c\n", st[posidif]);
	}
	//printf("%d pos\n", posidif);
	return 0;
}


Measured memory_bytes: 128
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

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

  for (int x = 1; x <= 50000; x++){
    int t = x * 1.08;
    if(N==t){
      std::cout << x << std::endl;
      return 0;
    }
  }
  std::cout << ":(" << std::endl;
  return 0;
}

Measured memory_bytes: 256
// at_abc147b.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
using namespace std;
int main()
{
    string str;cin >> str;
    int Count = 0;
    for (int i = 0;i < str.length()/2;i++) {
        if (str[i] != str[str.length() - i - 1]) { 
    
            Count++; }
    }
    cout << Count << "\n";
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


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;

int main() {
    string S;
    cin >> S;
    rep(i, 3) {
        if (S[i] == S[i + 1]) {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int (i)=(a);(i)<(int)(b);++(i))
#define RREP(i,a,b) for(int (i)=(a);(i)>=(int)(b);--(i))
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int Maxn = 100010;

bool fix[Maxn];
int h[Maxn];

int main(){
    int n;
    cin >> n;
    vector<int> t(n), a(n);

    fix[0] = fix[n - 1] = true;
    REP(i,0,n){
        cin >> t[i];
        if (i == 0) h[0] = t[0];
        else if (t[i] > t[i - 1]){
            fix[i] = true;
            h[i] = t[i];
        }
    }
    REP(i,0,n){
        cin >> a[i];
    }

    if (a[0] != t[n - 1]){
        cout << 0 << endl;
        return 0;
    }
    RREP(i,n - 1,0){
        if (i == n - 1) h[n - 1] = a[n - 1];
        else if (a[i] > a[i + 1]){
            if (fix[i] == true && h[i] != a[i]){
                cout << 0 << endl;
                return 0;
            }

            fix[i] = true;
            h[i] = a[i];
        }
    }

    int tmp = h[0];
    REP(i,1,n){
        if (fix[i]) tmp = h[i];
        else h[i] = tmp;
    }
    tmp = h[n - 1];
    RREP(i,n - 2,0){
        if (fix[i]) tmp = h[i];
        else h[i] = min(h[i], tmp);
    }

    ll ans = 1LL;
    REP(i,0,n){
        if (!fix[i]) (ans *= h[i]) %= MOD;
    }

    REP(i,0,n){
        if (t[i] < h[i] || a[i] < h[i]){
            cout << 0 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;

ll ds(ll digit) {
	ll res = 0;
	while (digit != 0) {
		res += digit % 10;
		digit /= 10;
	}
	return res;
}
ll MOD = 1000000007;
int main() {
	ll N, T;
	cin >> N >> T;
	vector<ll>t(2000000);
	for (ll i = 0; i<N; ++i) { cin >> t[i]; }
	ll j = 1;
	ll sum = 0;
	for (ll i = 0; i < N - 1; ++i) {
		if (t[i + 1] - t[i] >= T) {
			++j;
		}
    }
		for (ll i = 0; i<N - 1; ++i) {
			if (t[i + 1] - t[i] <T)
				sum+=(t[i+1]-t[i]);
		}
 	sum+=T*j;
		cout << sum << endl;
}




Measured memory_bytes: 15872
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def ti(): return tuple(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    r = a % b
    if r == 0:
        return b
    return gcd(b, r)

def lcm(a):
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

def table(n:int, p=10**9+7):
    global fact, factinv, inv
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1] * i) % p)
        inv.append((-inv[p % i] * (p // i)) % p)
        factinv.append((factinv[-1] * inv[-1]) % p)

def main():
    N = ii()
    A = ti()
    P = 10**9 + 7
    lcm_a = lcm(A) % P

    N = 10**6+1
    inv_t = [0]+[1]
    for i in range(2,N):
        inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

    #print(inv_t[:10])
    ans = 0
    for num in A:
        ans = (ans + inv_t[num] * lcm_a) % P
        #ans +=  (ans + lcm_a // num) % P
        #ans %= inf
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 43740
#include<cstdio>
int K,L;
int f(int i,int j){
	if(i<L)return i*2+j;
	else return i+L;
}
int main(){
	scanf("%d",&K);
	if(K==1){
		puts("1\n1");return 0;
	}
	int N=K+1>>1;
	if(N%2==1)N++;
	printf("%d\n",N);
	L=K-N;
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)printf("%d%c",f((i+j)%N,i%2)+1," \n"[j==N-1]);
}

Measured memory_bytes: 1152
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	string S; cin >> S;
	if (S[2] == S[3] && S[4] == S[5]) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 100000

int A[MAX], n;

int partition(int A[], int p, int r) {
	int x = A[r];
	int t;
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j] <= x) {
			i += 1;
			t = A[j];
			A[j] = A[i];
			A[i] = t;
		}
	}
	t = A[r];
	A[r] = A[i+1];
	A[i+1] = t;
	return i + 1;
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
	}
	int p;
	p = partition(A, 0, n-1);
	for (int i = 0; i < n; i++) {
		if (i) printf(" ");
		if (i == p) printf("[");
		printf("%d", A[i]);
		if (i==p) printf("]");
	}
	printf("\n");
	return 0;
}









Measured memory_bytes: 3072
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;

stack<int> g;

int main(){
	int a,b,n,i;
	char t;
	string ans="! ";
	cin>>a>>b;
	
	n=a+b;
	
	if(a==0){
		for(i=1;i<=n;i++)
			ans=ans+'0';
		
		cout<<ans<<endl;
		fflush(stdout);
		return 0;
	}
	
	if(a<=b){
		cout<<"Impossible"<<endl;
		fflush(stdout);
		return 0;
	}
	
	for(i=0;i<n;i++){
		if(g.size()>0){
			cout<<"? "<<g.top()<<' '<<i<<endl;
			fflush(stdout);
			
			cin>>t;
			if(t=='N')g.pop();
			if(t=='Y')g.push(i);
		}
		else g.push(i);
	}
	
	for(i=0;i<n;i++){
		if(i==g.top()){
			ans=ans+'1';
			continue;
		}
		else{
			cout<<"? "<<g.top()<<' '<<i<<endl;
			fflush(stdout);
			
			cin>>t;
			if(t=='N')ans=ans+'0';
			if(t=='Y')ans=ans+'1';
		}
	}
	cout<<ans<<endl;
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 724
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <functional>


using namespace std;

int main() {
  double a,b,h,m;
  double pi = 3.141592653589793;
  cin>>a>>b>>h>>m;
  
  double kakua,kakub;
  kakua = 30*h + m/2;
  kakub = m*6;

  double kaku = abs(kakua-kakub);
  if(kaku >180)kaku = 360-kaku;
  kaku = kaku * pi /180;
  double cc = a*a + b*b -2*a*b*cos(kaku);
  cout<<setprecision(20)<<sqrt(cc)<<endl;

  return 0;
}

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

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

int K, X;

int main()
{
    int i, j;

    scanf("%d%d", &K, &X);
    for(i=max(-1000000, X-K+1); i<=min(1000000, X+K-1); i++) printf("%d ", i);
}


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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

int main() {
    lint a = 100;
    lint X;
    cin >> X;

    int ans = 0;
    while (a < X) {
        a = (double)a * 1.01;
        ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#define min(a, b) a<b ? a : b
#define abs(a) a>=0 ? a : -a

int main(){
  long long int x, k;
  scanf("%lld%lld", &x, &k);
  x = x%k;
  long long int ttt = x-k;
  if(ttt<0) ttt*=(-1);
  long long int ans = min(x, ttt);
  //  printf("%lld %lld\n", x, ttt);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(lambda x: (int(x[1]), x), input().split()))

    # Bubble Sort
    B = A.copy()
    at_least_once = True
    while at_least_once:
        at_least_once = False
        for i in range(N - 1):
            if B[i][0] > B[i + 1][0]:
                B[i], B[i + 1] = B[i + 1], B[i]
                at_least_once = True
    print(" ".join(map(lambda x: x[1], B)))
    print("Stable")

    # Selection Sort
    B = A.copy()
    stability = "Stable"
    for i in range(N - 1):
        min_j = i
        for j in range(i, N):
            if B[j][0] < B[min_j][0]:
                min_j = j
        if min_j != i:
            if B[i][0] in list(map(lambda x: x[0], B[i + 1: min_j])):
                stability = "Not stable"
            B[i], B[min_j] = B[min_j], B[i]
    print(" ".join(map(lambda x: x[1], B)))
    print(stability)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5616
#include <stdio.h>

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int n,int left, int mid, int right) {
  int i, j, k;
  int n1 = mid -left;
  int n2 = right - mid;
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  i=0, j=0;
  for(k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int n,int left,int right) {
  int mid;
  if(left+1 < right) {
    mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  mergeSort(A, n, 0, n);
  for(i=0;i<n;i++) {
    if(i) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",cnt);

  return 0;
}


Measured memory_bytes: 5708
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(void) {
        int a, b;
        cin >> a;       
        
        b = pow(a, 3);
        
        //cout << setprecision(N) << b  << endl;
        
        printf("%d\n", b);
        return 0;
}

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

bool accepted[100010];
int wa[100010];

int main() {
	int N, M;
	cin >> N >> M;
	int ac=0, pe=0;
	for(int i=0; i<M; ++i){
		int p;
		string S;
		cin >> p >> S;
		if(!accepted[p]){
			if(S=="AC"){
				++ac;
				accepted[p]=1;
			}else{
				++wa[p];
			}
		}
	}
	for(int i=1; i<=N; ++i){
		if(accepted[i]) pe += wa[i];
	}
	cout << ac << ' ' << pe << endl;
	return 0;
}

Measured memory_bytes: 768
#include<cstdio>
int A,B,h=100,w=100;
char map[111][111];
int main(){
	scanf("%d%d",&A,&B);
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)map[i][j]=i<h/2?'.':'#';
	int x=0,y=0;
	for(int i=0;i<B-1;i++){
		map[x][y]='#';
		y+=2;
		if(y>=w)x+=2,y=0;
	}
	x=h-1;y=0;
	for(int i=0;i<A-1;i++){
		map[x][y]='.';
		y+=2;
		if(y>=w)x-=2,y=0;
	}
	printf("%d %d\n",h,w);
	for(int i=0;i<h;i++)printf("%s\n",map[i]);
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
using namespace std;
long long int nC2(long long int n) {
	return n * (n - 1) / 2;
}

int main() {
	long long int N = 0;
	cin >> N;
	vector<long long int>A(N);
	vector<long long int>B(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[A[i] - 1]++;
	}
	long long int sum = 0;
	for (int i = 0; i < N; i++) {
		if (B[i] >= 2) {
			sum += nC2(B[i]);
		}
	}
	for (int i = 0; i < N; i++) {
		cout << sum - nC2(B[A[i] - 1]) + nC2(B[A[i] - 1] - 1) << endl;
	}
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main(void) {
    
    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    ll ans=0;
    int maxa=0;
    for(int i=0;i<n;i++){
        int num=(v[i]-1)/(maxa+1);
        ans+=num;
        // cout<<i<<" num:"<<num<<" "<<maxa<<endl;
        if(num>0)v[i]=1;
        maxa=max(maxa,v[i]);
    }
    fin(ans);
    

}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<pair<int,int>,string> item;
main(){
	int n,i,w,s,S;
	string f;
	for(;cin>>n,n;){
		vector<item> items,result;
		for(i=0;i<n;i++)cin>>f>>w>>s,items.push_back(make_pair(make_pair(w,s),f));
		sort(items.begin(),items.end());
		S=99999;
		do{
			for(s=w=0,i=n-1;i>=0;i--){
				if(items[i].first.second<w)break;
				w+=items[i].first.first;
				s+=(i+1)*items[i].first.first;
			}
			if(i<0&&s<S)S=s,result=items;
		}while(next_permutation(items.begin(),items.end()));
		for(i=0;i<n;i++)cout<<result[i].second<<endl;
	}
}

Measured memory_bytes: 1216
#include <stdio.h>
int main(void){
int a,b;
char op;
while(1){
scanf("%d %c %d",&a,&op,&b);
if ( op == '+' ){
printf("%d\n",a+b);
} else if ( op == '-' ){
printf("%d\n",a-b);
} else if ( op == '*'){
printf("%d\n",a*b);
} else if ( op == '/' ){
printf("%d\n",a/ b);
} else {
break;
}
}
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
 
using namespace std;
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
 

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    ll test=0;
    int i=n-1;
    int prev=n+3;
    //cout<<n<<endl;
    while(i>=0)
    {
        if((s[i]-48>4&&i-1>=0&&s[i-1]-48>4)||s[i]-48>5)
        {int x=i;
            while(i>=0&&s[i]-48>4)
            {
                test+=(9-(s[i]-48));
                i--;
            }
            if(prev==x+2&&prev<n&&s[x+1]-48==4)
                test+=1;
            else
                test+=2;
        prev=i+1;
        }
        else
        {
            if(s[i]-48==5&&i+2==prev&&i+2<n&&s[i+1]-48==4)
                prev=i;
            test+=(s[i]-48);
            i--;
        }
    }
    cout<<test<<endl;

    return 0;   
}
 
 

Measured memory_bytes: 1948
s = input()

answer = 0
a = 0
z = 0

words = list(s)

for num in range(len(words)):
    if words[num] == 'A':
        a = num
        break

for num in range(len(words)):
    if words[num] == 'Z':
        z = num

answer = z - a + 1

print(answer)




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


int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;

    cin >> k;

    cout << a[k-1];
    

    return 0;
}

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

using namespace std;
#define ll long long


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    string str;
    cin>>str;
    for(int i=0;i<3;i++)
        cout<<str[i];
    cout<<endl;
    return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
typedef vector<ll> vll;
typedef vector<int> vi;
const ll N = 1e7 + 10;
const int M = 1e9 + 7;
const double eps = 1e-9;
ll nod[N];

int main() {
    ll m, n, sum;
    cin >> m >> n >> sum;
    vll a(m), b(n);
    for (int i = 0; i < m; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    vll pa(m), pb(n);
    for (int i = 0; i < m; ++i) {
        pa[i] = (i == 0 ? a[i] : a[i] + pa[i - 1]);
    }
    for (int i = 0; i < n; ++i) {
        pb[i] = (i == 0 ? b[i] : b[i] + pb[i - 1]);
    }
    int ans = 0;
    for (int i = 0; i < m && pa[i] <= sum; ++i) {
        ll rem = sum - pa[i];
        int j = upper_bound(all(pb), rem) - pb.begin();
        ans = max(ans, i + 1 + j);
    }
    for (int i = 0; i < n && pb[i] <= sum; ++i) {
        ll rem = sum - pb[i];
        int j = upper_bound(all(pa), rem) - pa.begin();
        ans = max(ans, i + 1 + j);
    }
    cout << ans << endl;
}



Measured memory_bytes: 9540
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int N=110000;
int father[N];
long long sum[N],w[N];
int n,m,A[N],B[N],pos[N],in[N];
int findfather(int k1){
	if (father[k1]==k1) return k1; return father[k1]=findfather(father[k1]);
}
vector<int> go[N];
int compare(int k1,int k2){
	return max(0,A[k1]-B[k1])<max(0,A[k2]-B[k2]);
}
int pd[N],sign;
vector<int> C;
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d%d",&A[i],&B[i]);
	for (int i=1;i<=m;i++){
		int k1,k2; scanf("%d%d",&k1,&k2);
		go[k1].push_back(k2);
		go[k2].push_back(k1);
	}
	for (int i=1;i<=n;i++) pos[i]=i,father[i]=i;
	sort(pos+1,pos+n+1,compare);
	for (int i=1;i<=n;i++){
		int k1=pos[i]; sign++; C.clear();
		for (int j=0;j<go[k1].size();j++){
			int k2=go[k1][j];
			if (in[k2]){
				int root=findfather(k2);
				if (pd[root]!=sign){
					pd[root]=sign; C.push_back(root);
				}
			}
		}
		for (int j=0;j<C.size();j++){
			father[C[j]]=k1;
			sum[k1]+=sum[C[j]];
		} in[k1]=1;
		if (C.size()==0){
			w[k1]=max(A[k1],B[k1]); sum[k1]=B[k1]; continue;
		}
		w[k1]=sum[k1]+max(A[k1],B[k1]);
		for (int j=0;j<C.size();j++)
			w[k1]=min(w[k1],sum[k1]-sum[C[j]]+max(1ll*A[k1],w[C[j]]+B[k1]));
		sum[k1]+=B[k1];
		//cout<<k1<<" "<<w[k1]<<" "<<B[k1]<<endl;
	}
	printf("%lld\n",w[findfather(1)]);
}

Measured memory_bytes: 10620
#include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <algorithm>
    #include <cmath>
    #include <vector>
    #include <set>
    #include <map>
    #include <unordered_set>
    #include <unordered_map>
    #include <queue>
    #include <ctime>
    #include <cassert>
    #include <complex>
    #include <string>
    #include <cstring>
    #include <chrono>
    #include <random>
    #include <queue>
    #include <bitset>
    #include <stack>
    #include <functional>

    #ifdef LOCAL
        #define eprintf(...) fprintf(stderr, __VA_ARGS__)
    #else
        #define eprintf(...) 42
    #endif

    #define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
    #define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
    #define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
    #define all(x) (x).begin(), (x).end()
    template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
    template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
    template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair <ll,ll> P;
    typedef long double ld;

    int main(void)
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
        string s, t;
        cin >> s >> t;
        cout << t << s << "\n";
        return 0;
    }

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

int main(){
  int64_t N;
  cin>>N;
  vector<int64_t> A(N);
  int64_t j=0;
  for(int64_t &i:A){
    cin>>i;
    j+=i;
  }
  int64_t k=0,l=2020202020;
  for(int64_t &i:A){
    k+=i;
    l=min(l,abs(j-k*2));
  }
  cout<<l<<endl;
}

Measured memory_bytes: 1792
#include<math.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#define rg register
#define il inline
using namespace std;
long long a,b,lcm,c,d,cc,dd,e;
il long long A(long long q){return b/q-(a-1)/q;}
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	if(c<d){e=c;c=d;d=e;}
	cc=c,dd=d;c%=d;e=c;c=d;d=e;
	while(d){e=d;d=c%d;c=e;}
	lcm=1ll*cc*dd/c;
	printf("%lld",A(1)-A(cc)-A(dd)+A(lcm));
	return 0;
}


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

using namespace std;

int M = pow(10, 9) + 7;

map<int, int> prime_factor(int n) {
  map<int, int> factors;
  for (int i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      factors[i]++;
      n /= i;
    }
  }
  if (n != 1) factors[n] = 1;
  return factors;
}

int main() {
  int N;
  cin >> N;
  
  map<int, int> factors;
  
  for (int n = 1; n <= N; n++) {
    for (pair<int, int> x: prime_factor(n)) {      
      factors[x.first] += x.second % M;
    }
  }
  
  long long answer = 1;
  
  for (pair<int, int> x: factors) {
    answer *= (x.second + 1);
    answer %= M;
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
class BIT:
    def __init__(self,len_A):
        self.N = len_A + 10
        self.bit = [0]*(len_A+10)
        
    def query(self,i):
        res = 0
        idx = i+1
        while idx:
            res += self.bit[idx]
            idx -= idx&(-idx)
        return res

    def update(self,i,x):
        idx = i+1
        while idx < self.N:
            self.bit[idx] += x
            idx += idx&(-idx)
    
    def lower_left(self,w):
        if (w < 0):
            return -1
        x = 0
        k = 1<<(self.N.bit_length()-1)
        while k > 0:
            if x+k < self.N and self.bit[x+k] < w:
                w -= self.bit[x+k]
                x += k
            k //= 2
        return x
    
n, q = map(int, input().split())
a = list(map(int, input().split()))
bit = BIT(n)
for i in range(n):
    bit.update(i, a[i])

for i in range(q):
    x, y, z = map(int, input().split())
    if x == 0:
        bit.update(y, z)
    else:
        print(bit.query(z-1) - bit.query(y-1))

Measured memory_bytes: 132572