akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
#include<bitset>
using namespace std;
using ll = long long;
#define MOD 1000000007
int main(){
  int n;
  cin>>n;
  int bit[60] = {};
  for(int i = 0; i < n; i++) {
    ll tmp;
    cin >> tmp;
    for(int j = 0; j < 60; j++){
      if((tmp>>j) & 1){
        bit[j]++;
      }
    }
  }
  ll ans = 0;
  for(int i = 0; i < 60; i++){
    //cout << bit[i] << endl;
    ans += (ll)pow(2, i) % MOD * (n - bit[i]) % MOD * bit[i];
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

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

int main() {
  vector<int> v = {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 << v[k-1] << endl;
}

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

int sum_check(int);

int main(int argc, char const *argv[]) {
  int n,a,b,tmp,sum=0;
  cin>>n>>a>>b;
  for(int i=1;i<=n;i++){
    tmp=sum_check(i);
    if(tmp>=a&&tmp<=b)  sum+=i;
  }
  cout<<sum<<endl;
  return 0;
}

int sum_check(int i){
  int num=0;
  while(i){
    int dig=i%10;
    num+=dig;
    i=i/10;
  }
  return num;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	const double eps=1e-11;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var a=sc.Ia;
		int p=a.Sum();
		Array.Sort(a,(u,v)=>v-u);
		Console.WriteLine("{0}",(1.0*p/(4*s[1]))>a[s[1]-1]?"No":"Yes");
	}
}
public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public double[] Da2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),double.Parse);}}
	public double[] Da3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),double.Parse);}
	public double[] Da3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),double.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1005;
vector<int> T[N];
int ai[2 * N], bi[2 * N];
int pr[N];


int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 0 ; i < m ; i ++ ){
    cin >> ai[i] >> bi[i];
    T[ai[i]].push_back(bi[i]);
  }
  int nd;
  vector<int> ret;
  for(int i = 1; i <= n; i ++ ){
    for(int j = 1; j <= n; j ++ )
      pr[j] = -1;
    queue<int> qq;
    qq.push(i);
    while(!qq.empty()){
      nd = qq.front();
      qq.pop();
      for(auto x : T[nd]){
        if(pr[x] == -1){
          pr[x] = nd;
          qq.push(x);
        }
      }
    }
    if(pr[i] != -1){
      vector<int> res;
      nd = pr[i];
      while(nd != i){
        res.push_back(nd);
        nd = pr[nd];
      }
      res.push_back(nd);
      reverse(res.begin(), res.end());
      if(ret.empty() || res.size() < ret.size())
        ret = res;
    }
  }
  if(ret.empty()){
    cout << -1;
    return 0;
  }
  cout << ret.size() << "\n";
  for(auto x : ret)
    cout << x << " ";
  return 0;
}

Measured memory_bytes: 384
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
p = list(map(int,input().split()))
pp = list(range(102))

for i in p:
    pp.remove(i)

ans = 0
sa = 100000

for i in pp:
    memo = abs(x - i)
    if memo < sa:
        sa = memo
        ans = i

print(ans)

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

int n;
string x, y;
bool mat[1000][1000];
int a[1000][1000];

int max(int i, int j) {
	int r = (!mat[i - 1][j] ? a[i - 1][j] : 0);
	r = ((!mat[i][j - 1] && a[i][j - 1] > r) ? a[i][j - 1] : r);
	return r > a[i - 1][j - 1] ? r : a[i - 1][j - 1];
}

int main(){
	cin >> n;
	for (int ia = 0; ia < n; ia++) {
		int ans = 0;
		cin >> x >> y;
		for (int i = 0; i < x.length(); i++) {
			for (int j = 0; j < y.length(); j++) {
				if (x[i] == y[j]) {
					mat[i][j] = true;
				}
				else {
					mat[i][j] = false;
				}
			}
		}
		for (int i = 0; i < x.length(); i++) {
			a[i][0] = mat[i][0] ? 1 : 0;
		}
		for (int i = 1; i < y.length(); i++) {
			a[0][i] = mat[0][i] ? 1 : 0;
		}
		for (int i = 1; i < x.length(); i++) {
			for (int j = 1; j < y.length(); j++) {
				a[i][j] = max(i, j) + (mat[i][j] ? 1 : 0);
			}
		}
		int p = 0;
		for (int i = 0; i < x.length(); i++) {
			p = a[i][y.length() - 1] > p ? a[i][y.length() - 1] : p;
		}
		for (int i = 0; i < y.length() - 1; i++) {
			p = a[x.length() - 1][i] > p ? a[x.length() - 1][i] : p;
		}
		cout << p << endl;
	}


	return 0;
}

Measured memory_bytes: 7996
import sys

def jeat(a, f, x, K):
    N = 0
    for i in range(len(a)):
        if a[i]*f[i] > x:
            N += a[i] - x // f[i]
    if N > K:
        return False
    if N <= K:
        return True

N,K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))
F = list(map(int, input().split(' ')))
if K >= sum(A):
    print(0)
    sys.exit()
A.sort()
F.sort(reverse = True)
a = 0
b = 10**18
while (True):
    z = (a+b)//2
    if jeat(A,F,z,K) == True:
        if jeat(A,F,z-1,K) == False:
            break
        b = z-1
    else:
        if jeat(A,F,z+1,K) == True:
            z += 1
            break
        a = z+1

print(z)

Measured memory_bytes: 115676
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<tuple>
#include<string.h>
#include<iomanip>
#include<stack>
#include<queue>
#include<map>
#include<deque>

using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define ALLOF(c) (c).begin(), (c).end()
#define Pa pair<ll,ll>
const ll mod=1000000007;
const ll INF=10e12;
const ll inf=-1;
ll ABS(ll a){return max(a,-a);}


int main(void){
    ll H,A;
    cin>>H>>A;
    ll ans=H/A;
    if(H%A) ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){

int r,c,a;  //ｒが行（横）ｃが列（縦）
    cin >> r >> c;
    int spreadsheet[r][c];
    int total1 = 0,total2 = 0,sumyoko = 0;
    
    
    
    for(int i = 0; i < r; i++){
        
        for(int j = 0; j < c;j++){
            cin >> a;
            spreadsheet[i][j] = a;
        }
    }
    
    for(int k = 0; k<r;k++){  //横の列の合計を出す   
        
        for(int l = 0; l < c;l++){
            cout << spreadsheet[k][l] << " ";
            total1 += spreadsheet[k][l];
            sumyoko += spreadsheet[k][l]; 
        }
        cout << total1 << endl;
        total1 = 0;
        
    }
    //cout << endl;
    
    
    
    int q = 0;
    while(q < c){   //縦の列の合計を出す。
        
        for(int p = 0; p < r;p++){
            total2 += spreadsheet[p][q];
            //cout << spreadsheet[p][q] << " ";
        }
        cout << total2 << " ";
        q += 1;
        total2 = 0;
    }
    
    cout << sumyoko << endl;

    
}


Measured memory_bytes: 3112
import itertools
N, M = map(int, input().split())
k, s = [], []
for _ in range(M):
    x = list(map(int, input().split()))
    k.append(x[0])
    s.append(x[1:])
p = list(map(int, input().split()))
ans = 0
for x in itertools.product([0, 1], repeat=N):
    c = 0
    for i in range(M):
        if sum(x[s[i][j]-1] for j in range(k[i])) % 2 == p[i]:
            c += 1
    if c == M:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

// Fenwick Tree
int n;
int bit[575]; 

void add( int a, int x ){
	for( int i = a; i <= n; i += ( i & -i ) ) bit[i] += x;
}

int sum( int a ){
	int res = 0;
	for( int i = a; i > 0; i -= ( i & -i ) ) res += bit[i];
	return res;
}

struct abschnitt{
	int link;
	int recht;
	bool art; // query wenn true, zug wenn false
	int nummer;
};
	
int main(){
	vector<abschnitt> v;
	map<int, int> karte;
	int m, q; cin >> n >> m >> q;
	
	for( int i = 0; i < m; ++i ){
		int l, r; cin >> l >> r;
		v.push_back( (abschnitt){ l, r, false, 0 } );
	}
	for( int i = 0; i < q; ++i ){
		int l, r; cin >> l >> r;
		v.push_back( (abschnitt){ l, r, true, i } );
	}
	
	sort(
		v.begin(), v.end(),
		[]( const abschnitt& x, const abschnitt& y ){
			return ( x.recht == y.recht ) ? ( x.art < y.art ) : ( x.recht < y.recht );
		}
	);
	
	for( int i = 0; i < m+q; ++i ){
		// cout << v[i].link << " " << v[i].recht << " " << v[i].art <<  " " << v[i].nummer << endl;
		if( v[i].art ) karte.emplace( v[i].nummer, sum( v[i].recht ) - sum( v[i].link - 1 ) );
		else add( v[i].link, 1 );
	}
	
	for ( int i = 0; i < q; ++i ) cout << karte.at(i) << endl;
	return 0;
}

Measured memory_bytes: 12136
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ちゃんとユニークな配列にする。連続した値を除去して切り出す。
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  int lengthOfStr = 0;
  lengthOfStr = A + B + 1;
  bool isPostalCode = true;

  if (S.length() != lengthOfStr) isPostalCode = false;
  if (isPostalCode) {
    rep(i, lengthOfStr) {
      if(i == A) {
        if(S[i] != '-') isPostalCode = false;
      } else {
        if(!isdigit(S[i])) isPostalCode = false;
      }
    }
  }

  if(isPostalCode) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_C() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A,B,C; cin >> A>>B>>C;
    int X, Y; cin >> X >> Y;

    int sum = A * X + B * Y;
    int z = 2;
    while (true) {
        int ns = A * max(0, (X - z / 2)) + B * max(0, (Y - z / 2)) + C * z;
        if (ns < sum) sum = ns;
        else break;
        z += 2;
    }

    int ans = sum;
    cout << ans << endl;

    return 0;
}

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

int main(int argc, char const *argv[]) {
  int dif;
  long long k;
  string str;
  std::cin >> str >> k ;
  static const int mdif = 'z'-'a';
  int len=str.size();
  for (long long i = 0; i < len; i++) {
    if (str[i]!='a') {
      dif='z'-str[i];
      if (k > dif) {
        str[i] = 'a';
        k -= (dif + 1);
      }
    }
  }

  k = k % (mdif + 1);
  str[len - 1]=(char) (str[len - 1] + k);

  std::cout << str << std::endl;

  return 0;
}


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

const int maxn=1001;
const double EPS =1e-6;
const double PI =3.141592653589793;
using namespace std;
const int MOD=1e9;
typedef long long ll;
typedef long double ld;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    int col=n/k;
    if (k==1){
        cout<<1ll*n*n*n;
        return 0;
    }
    if (k&1){
        cout<<1ll*col*col*col;
        return 0;
    }
    int hlf=k/2;
    int mx=col*k;
    int z=col;
    if (mx+hlf<=n){
        ++z;
    }
    cout<<1ll*col*col*col+1ll*z*z*z;
}


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

#define vi vector<int>
#define vl vector<long>
#define vvi vector<vector<int>>
#define vvl vector<vector<long>>
#define pint pair<int, int>
#define plong pair<long, long>

long MOD = 998244353;
long long MODPOW(long long inv,long long pow, long long mod){
    if(pow == 1) return inv % mod;
    else{
        if(pow % 2) return inv * MODPOW(inv, pow -1, mod) % mod;
        long long res = MODPOW(inv, pow/2, mod);
        return res * res % mod; 
    }
}

long long COMMOD(int a, int b){
    long long res=1; long long resinv = 1;
    for(int i = a; i>a-b; i--){
        res = res * i % MOD;
        resinv = resinv*(a-i+1) % MOD;
    }
    return res*MODPOW(resinv, MOD-2, MOD) % MOD;
}

int main() {
    long N, M, K;
    cin>>N>>M>>K;
    vl Com(N), Color(N);
    Color[N-1]= M; 
    for(int i = N-2; i >= 0; i--){
        Color[i] = Color[i+1]*(M-1) % MOD;
        //cout << Color[i] << endl;
    }
    Com[0] = 1;
    long res = N-1; long resinv = 1;
    REP(i, 1, N){
        Com[i] = Com[i - 1] * res % MOD;
        Com[i] *= MODPOW(resinv, MOD-2, MOD);
        Com[i] %= MOD;
        res--; resinv++;
        //cout << Com[i] << endl;
    }
    long ans = 0;
    REP(i, 0, K+1){
        ans += Color[i] * Com[i] % MOD;
        if(ans > MOD) ans %= MOD;
    }
    cout << ans << endl;

}

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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

// repetition
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) for (long long i = 0; i < (n); ++i)

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;

  REP(i,n){
    cout << s[i] << t[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
class Kruskal_UnionFind():
    def __init__(self, N):
        self.edges = []
        self.rank = [0] * N
        self.par = [i for i in range(N)]
        self.counter = [1] * N

    def add(self, u, v, d):
        """
        :param u: 始点
        :param v: 終点
        :param d: コスト
        """
        self.edges.append([u, v, d])

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            z = self.counter[x] + self.counter[y]
            self.counter[x], self.counter[y] = z, z
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        x = self.find(x)
        return self.counter[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def Kruskal(self):
        """
        :return: 最小全域木のコストの和
        """
        edges = sorted(self.edges, key=lambda x: x[2])  # costでself.edgesをソートする
        res = 0
        for e in edges:
            if not self.same(e[0], e[1]):
                self.unite(e[0], e[1])
                res += e[2]
        return res


N = int(input())
XY = [[i] + list(map(int, input().split())) for i in range(N)]

graph = Kruskal_UnionFind(N)
XY = sorted(XY, key=lambda x: x[1])
X_costs = [[XY[i-1][0], XY[i][0], abs(XY[i-1][1] - XY[i][1])] for i in range(1, N)]
XY = sorted(XY, key=lambda x: x[2])
Y_costs = [[XY[i-1][0], XY[i][0], abs(XY[i-1][2] - XY[i][2])] for i in range(1, N)]

for i in range(N-1):
    x0, x1, d = X_costs[i]
    graph.add(x0, x1, d)
    y0, y1, d = Y_costs[i]
    graph.add(y0, y1, d)

print(graph.Kruskal())

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

char s[1005];

int solve() {
  scanf("%s", s);
  if (s[2] == s[3] && s[4] == s[5]) printf("Yes\n");
  else printf("No\n");
  return 0;
}

int main() {
  int t = 1;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}


Measured memory_bytes: 256
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll inf = 5e15;

VV<ll> dists, edges;
ll N, M, L;

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

    dists = make_v<ll>(inf, N, N);
    edges = make_v<ll>(inf, N, N);
    for(ll i = 0; i < N; i++) dists[i][i] = edges[i][i] = 0;
    for(ll i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        if(L < c) continue;
        dists[a][b] = dists[b][a] = edges[a][b] = edges[b][a] = c;
    }

    for(ll k = 0; k < N; k++) for(ll i = 0; i < N; i++) for(ll j = 0; j < N; j++) chmin(dists[i][j], dists[i][k] + dists[k][j]);
    for(ll i = 0; i < N; i++) for(ll j = 0; j < N; j++) dists[i][j] = (dists[i][j] <= L ? !!dists[i][j] : inf);
    for(ll k = 0; k < N; k++) for(ll i = 0; i < N; i++) for(ll j = 0; j < N; j++) chmin(dists[i][j], dists[i][k] + dists[k][j]);

    ll Q;
    cin >> Q;
    while(Q--) {
        ll s, t;
        cin >> s >> t;
        s--; t--;
        ll ans = dists[s][t];
        if(ans == inf) ans = 0;
        cout << ans - 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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; }


int main() {
	int n,m;
	cin >> n >> m;
	vector<pair<ll,ll>>p(n);
	rep(i,n) {
		cin >> p[i].first >> p[i].second;
	}
	
	sort(p.begin(),p.end());
	ll ans = 0;
	rep(i,n) {
		if(p[i].second<=m) {
			ans += p[i].first*p[i].second;
			m -= p[i].second;
		}
		else {
			ans += p[i].first*m;
			break;
		}
	}
	cout << ans << endl;
	
}


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

using namespace std;

const int INF = 2e9 + 3;
const int N = 1e5 + 3;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

const double PI = acos(-1);


void solve() {
    int n;
    cin >> n;
    int a[n];
    for (int &x : a)
        cin >> x;
    int mx = 0;
    auto ans = 0ll;
    for (int i = 0; i < n; i++) {
        if (a[i] < mx)
            ans += mx - a[i];
        mx = max(mx, a[i]);
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int t;
    t = 1;
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 4396
// ------------------------------------
// Date:2018/ 3/12
// Problem:ABC 073 Septmeber9 a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;

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

  string N;
  cin >> N;
  bool ok = false;
  REP(i, N.size()) {
    if (N[i] == '9') ok = true;
  }

  cout << (ok ? "Yes" : "No") << endl;
  
  return 0;
}



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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int x = n%10;
    if(x ==2 ||x == 4 || x == 5 || x == 7 || x == 9)
        cout<<"hon"<<endl;
    if(x ==0 ||x ==1 || x == 6 || x == 8)
        cout<<"pon"<<endl;
    if(x == 3)
        cout<<"bon"<<endl;
}

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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

// vecからnumを見つける
bool find(vector<int> vec, int num) {
    auto itr = find(ALL(vec), num);
    size_t index = distance(vec.begin(), itr);
    return index != vec.size();
}

void Main() {
    int x,n;
    cin >> x >> n;

    vector<int> p(n);
    REP(i,n) cin >> p.at(i);

    int min = 999999;
    int ans = x;
    FOR(i,-10,110) {
        int dif = abs(i - x);
        if (min > dif && !find(p, i)) {
            min = dif;
            ans = i;
        }
    }
    cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	Main();
	return 0;
}


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

signed main() {
    string S;
    cin >> S;
    const int base = 13;
    vector<int> dp(base, 0);
    dp[0] = 1;
    int mul = 1;
    reverse(S.begin(), S.end());
    for (char c : S) {
        vector<int> next(base, 0);
        if (c == '?') {
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < base; j++) {
                    next[(i * mul + j) % base] += dp[j];
                    next[(i * mul + j) % base] %= mod;
                }
            }
        } else {
            int i = c - '0';
            for (int j = 0; j < base; j++) {
                next[(i * mul + j) % base] += dp[j];
                next[(i * mul + j) % base] %= mod;
            }
        }
        mul *= 10;
        mul %= base;
        copy(next.begin(), next.end(), dp.begin());
    }
    cout << dp[5] << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    int N,M,C; cin >> N >> M >> C;
    int B[M], A[N][M];
    for (int i=0; i<M; i++) cin >> B[i];
    for (int i=0; i<N; i++) for (int j=0; j<M; j++) cin >> A[i][j];

    int result = 0, val;
    for (int i=0; i<N; i++) {
        int val = C;
        for (int j=0; j<M; j++) val += B[j] * A[i][j];
        if (val>0) result++;
    }

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> v(8, 0);
    int a, b, c;
    cin >> a >> b >> c;
    v[a]++;
    v[b]++;
    v[c]++;
    if(v[5] == 2 && v[7] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
using System;

    class ABC116C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] input = Console.ReadLine().Split(' ');
            int[] h = new int[n+1];
            for(int i = 1; i <= n; i++)
            {
                h[i] = int.Parse(input[i-1]);
            }
            int l, r;
            int cnt = 0;

            // 端から攻めてく

            for(int i = 1; i <= n; i++)
            {
                 while(h[i] != 0)
                {
                    l = i;
                    r = i;
                    for(int j = i+1; j <= n; j++)
                    {
                        if(h[j] != 0)
                        {
                            r = j; // ここ念のため
                        }
                        if(h[j] == 0)
                        {
                            r = j - 1;
                            break;
                        }
                    }

                    for(int x = l; x <= r; x++)
                    {
                        h[x]--;
                    }
                    cnt++;
                }
            }

            Console.WriteLine(cnt);
        }
    }


Measured memory_bytes: 13140
n=int(input())
a=[0]*(n-1)
a=list(map(int,input().split()))
a=sorted(a)
ans=0
target=1
j=0
for i in range(n):
    if (j<n-1):
        while(a[j]==target):
            ans+=1
            j+=1
            #print(j,"here")
            if (j>n-2):
                break
    print(ans)
    ans=0
    target+=1

Measured memory_bytes: 93868
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,q,r=0;
string s;


void solve(){
    cin >> s;
    n=s.length();
    cin >> q;
    deque<string> que={};
    rep(i,n){
        que.push_back(s.substr(i,1));
        //cout << que.back() << endl;
    }
    int q_=0;
    rep(i,q){
        int t;cin >> t;
        if(t==1){
            r^=1;
        }
        else{
            q_+=1;
            int f;string c;cin >> f >> c;f--;
            if((r^f)==0){
                que.push_front(c);
            }
            else{
                que.push_back(c);
            }
        }
    }
    if(r==0){
        rep(i,n+q_){
            string m=que.front();que.pop_front();
            cout << m << "";
        }
        cout << "" << endl;
    }
    if(r==1){
        rep(i,n+q_){
            string m=que.back();que.pop_back();
            cout << m << "";
        }
        cout << "" << endl;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 17232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            int nT = 0, nX = 0, nY = 0;
            for (int i = 0; i < N; i++)
            {
                var input = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                var t = input[0];
                var x = input[1];
                var y = input[2];
                var time = t - nT;
                var len = Math.Abs(x - nX) + Math.Abs(y - nY);
                if (len - time > 0)
                {
                    Console.WriteLine("No");
                    return;
                }else
                {
                    len -= time;
                    if (len % 2 != 0)
                    {
                        Console.WriteLine("No");
                        return;
                    }
                }
                nT = t;
                nX = x;
                nY = y;
            }

            Console.WriteLine("Yes");
        }
    }
}

Measured memory_bytes: 17448
#include<stdio.h>
#define N 100
int main()
{
    int a,i,j,tmp;
    int flag = 0;
    int A[N];

    scanf("%d",&a);
    for(i = 0 ; i < a ; i++){
        scanf("%d",&A[i]);
    }
    for(i = 0 ; i < a ; i++){
        for(j = a - 1 ; j > i ; j--){
            if(A[j] < A[j-1]){
                tmp = A[j];
                A[j] = A[j - 1];
                A[j - 1] = tmp;
                flag++;
        }
    }
}
    for(i = 0 ; i < a ; i++){
        printf("%d",A[i]);
        if(i < a - 1)printf(" ");
    }
    printf("\n%d\n",flag);
    return 0;
}


Measured memory_bytes: 2108
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,a[60],ans=0;

int main()
{
	cin>>n;
	rep(i,n) cin>>a[i];
	rep(i,n) for(int j=i+1;j<n;j++) ans+=a[i]*a[j];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000
int H,A[MAX+1]; 
int parent(int i){
	return i/2;
}
int left(int i){
	return i*2;
}
int right(int i){
	return i*2+1;
}
int main(){
	cin>>H;
	for(int i=1;i<=H;i++){
		cin>>A[i];
	}
	for(int i=1;i<=H;i++){
		cout<<"node "<<i<<": ";
		cout<<"key = "<<A[i]<<", ";
		if(parent(i)>=1)
			cout<<"parent key = "<<A[parent(i)]<<", ";
		if(left(i)<=H)
			cout<<"left key = "<<A[left(i)]<<", ";
		if(right(i)<=H)
			cout<<"right key = "<<A[right(i)]<<", ";
		cout<<endl;
	}
	return 0;
}


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

int main(void) 
{
	int a , b, c;
	int l , m , n ; 
	int x;
	int kingaku;	
	int count=0;

	scanf("%d" , &a);	
	scanf("%d" , &b);
	scanf("%d" , &c);
	scanf("%d" , &x);
	
	for (l = 0 ; l <= a ; l++)
	{
		for (m = 0 ; m <= b ; m++)
		{
			for (n = 0 ; n <= c ; n++)
			{
				kingaku = 500 * l + 100 * m + 50 * n;
				if (kingaku == x)
					count ++ ;
			} 	
		}
 
	}
	printf ("%d", count);
	return 0;
}

Measured memory_bytes: 128
while(True):
    a, op, b = input().split()
    if(op == '+'):
        print(int(a) + int(b))
    elif(op == '-'):
        print(int(a) - int(b))
    elif(op == '*'):
        print(int(a) * int(b))
    elif(op == '/'):
        print(int(a) // int(b))
    elif(op == '?'):
        break


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

main(){
  int *a;
  int i,j,n,tmp,minj;
  int kokan=0;

  scanf("%d", &n);
  a=(int*)malloc(n*sizeof(int));

  for(i=0; i<n; i++) scanf("%d",a+i);

  //selection sort
  for(i=0; i<=n-1; i++){
    minj = i;
    for(j=i; j<=n-1; j++){
      if(a[j] < a[minj]) minj = j;
    }
    if(minj!=i){
      kokan++;
      //swap
      tmp = a[i];
      a[i]=a[minj];
      a[minj]=tmp;
    }
  }
  //print
  for(i=0; i<n-1; i++)printf("%d ", a[i]);
  printf("%d\n%d\n", a[i], kokan);

  return 0;
}

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

int main(){
  int N; cin >> N;
  map<string,int> m{{"AC",0}, {"WA",0},{"TLE",0},{"RE", 0}};
  for(int i = 0; i < N; i++){
    string tmp; cin >> tmp;
    m[tmp]++;
  }
    cout << "AC x " << m["AC"] <<endl;
    cout << "WA x " << m["WA"] <<endl;
    cout << "TLE x "<< m["TLE"] <<endl;
    cout << "RE x " << m["RE"] <<endl;
  return 0;
}


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

int main()
{
  int i;
  int n, k, p;
   cin >> n;
   for (i = 0; i < n; i++){
     cin >> k >> p;
     k %= p;
     if (k == 0){
       cout << p << "\n";
     }
     else {
       cout << k << "\n";
     }
   }
   return (0);
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;
const int  MOD  = 1e9+7;
typedef long long ll;
const int maxn=1e6;

ll pow(ll x, ll p, ll mod){
    ll ret = 1;
    while(p>0){
        if(p%2==1) ret = ret * x % mod;
        x = x * x % mod;
        p>>=1;
    }
    return ret ;
}


int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto &it: a) cin>>it;
    vector<int> f(maxn + 1,0);
    for(int i = 0 ;i< a.size(); i++){
        int x = a[i];
        for(int j = 2; j*j<=x; j++) if(x%j==0){
            int cnt = 1;
            while((x/=j)%j==0) cnt++;
            f[j] = max(f[j], cnt);
        }
        if(x>1) f[x] = max(f[x], 1);
    }
    ll lcm = 1;
    for(int i = 2; i<=maxn; i++) while(f[i]--)    lcm = lcm * i % MOD;
    ll ans = 0;
    for(int i = 0; i< a.size(); i++){
        ans = (ans + lcm * pow(a[i], MOD - 2, MOD)) % MOD;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4224
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    int x = (c+b-1)/b;
    if(d*(x-1) >= a) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

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

int main() {
	char c; cin >> c;
	char b[] = {'a', 'e', 'i', 'o', 'u'};
	
	bool flag = false;
	REP(i, 5) if (c == b[i]) flag = true;
	
	if (flag) puts("vowel");
	else puts("consonant");
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
string S;


signed main(){
    cin >> S;
    if(S == "SUN") cout << 7 << endl;
    else if(S == "MON") cout << 6 << endl;
    else if(S == "TUE") cout << 5 << endl;
    else if(S == "WED") cout << 4 << endl;
    else if(S == "THU") cout << 3 << endl;
    else if(S == "FRI") cout << 2 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

/* デカい配列はここで宣言 */

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> h(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    if (n == 1)
    {
        cout << "Yes" << endl;
        exit(0);
    }
    for (ll i = n - 1; i > 0; i--)
    {
        if (h[i - 1] - h[i] > 1)
        {
            cout << "No" << endl;
            exit(0);
        }

        if (h[i - 1] > h[i])
        {
            h[i - 1]--;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

Int N, M, V, P;
vector<Int> A;

bool isOK(Int i) {//A[i]が含まれ得るか

	Int temp = 0;
	temp += M * (P - 1);

	if (A[i]+M<A[N-P]) {
		return false;
	}
	temp += M * (i + 1);
	for (Int j = i+1; j <= N-P; j++) {
		temp += A[i] + M - A[j];
	}

	if (temp>=V*M) {
		return true;
	}
	else {
		return false;
	}
}

// 汎用的な二分探索のテンプレ
Int binary_search() {
	Int ng = -1; // 0が条件を満たすこともあるので、初期値は -1
	Int ok = N-P; // 考えられる答えの上限

	/* ok と ng のどちらが大きいかわからないことを考慮 */
	while (abs(ok - ng) > 1) {
		Int mid = (ok + ng) / 2;

		if (isOK(mid)) ok = mid;
		else ng = mid;
	}
	return ok;
}

int main() {

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

	
	cin >> N >> M >> V >> P;
	A.resize(N);
	
	for (Int i = 0; i < N; i++) {
		cin >> A[i];
	}

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

	Int res = binary_search();
	cout << N-res << "\n";
}


Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

# 入力を整数に変換して受け取る
def input_int():
    return int(input())

def map_int_input():
    return map(int, input())

MII = map_int_input

def MII_split():
    return map(int, input().split())

def MII_to_index():
    return map(to_index, input())

def MII_split_to_index():
    return map(to_index, input().split())

# 入力全てを整数に変換したものの配列を受け取る
def list_int_inputs():
    return list(map(int, input()))

LII = list_int_inputs

def LII_split():
    return list(map(int, input().split()))

# 2次元リスト化
def LII_2D(rows_number):
    return [LII() for _ in range(rows_number)]

def LII_split_2D(rows_number):
    return [LII_split() for _ in range(rows_number)]

N, K = MII_split()
sunukes = [0 for _ in range(N)]  # お菓子の個数
for k in range(K):
    _ = input()
    As = MII_split()
    for A in As:
        sunukes[A - 1] += 1

print(sunukes.count(0))

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    string s;
    cin >> s;
    int n = s.size();
    VI cnts;
    int cnt = 0;
    char c = 'g';
    for(int i = 1; i < n; i++){
        if (s[i] != c){
            cnts.push_back(cnt);
            c = c == 'g' ? 'p' : 'g';
            cnt = 0;
        }
        cnt++;
    }
    cnts.push_back(cnt);

    int score = 0, p_cnt = 1;
    if (s[0] == 'p') score = -1;
    rep(i, cnts.size()){
        if (i % 2 == 0){
            if (cnts[i] <= p_cnt){
                score += cnts[i];
                p_cnt -= cnts[i];
            }else{
                score += p_cnt;
                cnts[i] -= p_cnt;
                score += cnts[i] / 2;
                p_cnt = cnts[i] % 2;
            }
        }else{
            if (cnts[i] <= p_cnt){
                p_cnt -= cnts[i];
            }else{
                cnts[i] -= p_cnt;
                score -= (cnts[i]+1) / 2;
                p_cnt = cnts[i] % 2;
            }
        }
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 4028
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(10)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

typedef pair<string, int> PAIR;

bool compare(PAIR &a, PAIR &b){
  if(a.first == b.first) return a.second > b.second;
  else return a.first < b.first;
}

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

  vector<PAIR> vec;
  int N, P[100]; string S[100];
  cin >> N;
  REP(i, N){
    cin >> S[i] >> P[i];
    vec.pb(PAIR(S[i], P[i]));
  }
  sort(ALL(vec), compare);
  int idx = 1;
  REP(j, vec.size()){
    REP(i, N){
      if(S[i] == vec[j].first and P[i] == vec[j].second){
        cout << i+1 << endl;
      }
    }
  }
}

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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    int a, b;
    cin >> s ;
    int n = s.size();
    string x = string(n, 'x');

    cout << x << endl;

}

Measured memory_bytes: 256
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
N,M = [ int(it) for it in input().split() ]
S = input()
T = input()
P = gcd(N,M)
NP = N//P
MP = M//P
NPMP = NP*MP
flag = True
for i in range( P ):
  if ( S[NP*i] != T[MP*i] ):
    flag = False

print (NPMP*P) if flag else print (-1)
    
  
  
  


Measured memory_bytes: 39792