akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(15000)
n = 0
A = [0]

def maxHeapify(A, i):
  l = i*2
  r = l+1
  if l <= n and A[l] > A[i]:
    largest = l
  else:
    largest = i
  if r <= n and A[r] > A[largest]:
    largest = r
  if largest != i:
    A[i],A[largest]=A[largest],A[i]
    maxHeapify(A,largest)

def insert(k):
  A.append(k)
  global n
  n += 1
  i = n
  while i > 1:
    #print(A)
    p = i>>1
    if A[p] > A[i]:
      break
    A[p],A[i] = A[i],A[p]
    i = p
  #buildMaxHeap(A)
  #maxHeapify(A, n)

def extract():
  ret = A[1]
  global n
  if 1 < n:
    A[1] = A.pop()
  else:
    A.pop()
  n -= 1
  maxHeapify(A,1)
  #buildMaxHeap(A)
  return ret

S = sys.stdin.readlines()
o = []
for s in S:
#while 1:
  if s[2]=="d":
    #print("\n".join(map(str,o)))
    print(*o,sep='\n')
    exit(0)
  elif s[0] == "i":
    insert(int(s[7:]))
  else:
    o.append(extract())
    #print(s,A)



Measured memory_bytes: 210588
import sys
sys.setrecursionlimit(300000)

N, M = map(int, input().split())
nl = [[] for _ in range(N + 1)]
for _ in range(M):
    L, R, D = map(int, input().split())
    nl[L].append((R, D))
    nl[R].append((L, -D))

seen = [None for _ in range(N + 1)]


def dfs(v, d):
    seen[v] = d
    for next_v, D in nl[v]:
        next_d = d + D
        if seen[next_v] is None:
            dfs(next_v, next_d)
        else:
            if seen[next_v] != next_d:
                print('No')
                exit(0)


for v in range(1, N + 1):  # すべての連結成分に対してDFS
    if seen[v] is None:
        dfs(v, 0)

print('Yes')


Measured memory_bytes: 129008
import java.util.Scanner;

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

    while (in.hasNext()) {
      String[] date = in.next().split("/");
      int year = Integer.valueOf(date[0]);
      int month = Integer.valueOf(date[1]);
      int day = Integer.valueOf(date[2]);

      if (year < 2019) {
          System.out.println("Heisei");
      } else if (year == 2019 && month <= 4) {
          System.out.println("Heisei");
      } else {
          System.out.println("TBD");
      }
    }
  }
}

Measured memory_bytes: 23252
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[200000];

LL ans = 0;

void solve(){
	//A[0]~A[i-1]の話をaccum[i]とおく
	vector<LL> accum(N+1,0);
	for(int i=0;i<N;i++) accum[i+1] = accum[i] + A[i];
	// for(int i=0;i<=N;i++){
	// 	cout << accum[i] << " ";
	// }
	// cout << endl;
	map<LL,LL> num;//数値iのでてきた回数をnum[i]とおく
	for(int i=0;i<=N;i++) num[accum[i]]++;
	for(auto iter=num.begin();iter!=num.end();iter++){
		ans += (iter->second-1)*(iter->second)/2;
	}
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];
 
    solve();

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

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
const int KMAX = 1e5;

int main() {
  int K, Count=0, Ones;
  long long Num;
  queue<long long> Lunlun;
  
  cin >> K;
  
  for(int i=1; i<=9; i++) Lunlun.push(i);

  while(K) {
    K--; Count++;
    Num = Lunlun.front();
    Lunlun.pop();
    if(Count+Lunlun.size()>=KMAX) continue;
    Ones = Num%10;
    if(Ones != 0) Lunlun.push(Num*10+Ones-1);
    Lunlun.push(Num*10+Ones);
    if(Ones != 9) Lunlun.push(Num*10+Ones+1);
  }
  
  cout << Num << endl;
  return 0;
}

Measured memory_bytes: 768
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long sum = 0;

        for(long i = 1 ; i <= n ; i++){
            if(i % 3 == 0 || i % 5 ==0){
                continue;
            }
            sum += i;
        }
        System.out.println(sum);
    }

}

Measured memory_bytes: 35852
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb push_back
#define mp make_pair
#define nt _ll128
#define ld double
long double PI =3.14159265;
using ll = long long;

const ll modo=998244353;
const ll ms=3e5+5;
const ll inf=-1e17;

ll pp[ms];
ll vv[ms];
ll tree[ms*4];
int lazy[ms*4]={0};
int modpow(ll a,ll b)
{
    ll r=1;
    while(b)
    {
        if(b&1)
        {
            r=(r*a)%modo;
        }
        a=(a*a)%modo;
        b>>=1;
    }
    return r;
}


void buildtree(int l,int r,int ind)
{
    if(l==r)
    {
        tree[ind]=vv[l+1];
        return ;
    }
    int mid=(l+r)>>1;

    buildtree(l,mid,2*ind);
    buildtree(mid+1,r,2*ind+1);

    tree[ind]=tree[2*ind]+tree[2*ind+1];
    tree[ind]%=modo;
}

ll getv(int l,int r)
{
    ll ans=pp[r+1]+modo-pp[l];
    ans=ans%=modo;
    return ans;
}


void query(int l,int r,int a,int b,int v,int ind)
{
    if(lazy[ind])
    {
        tree[ind]=getv(l,r)*lazy[ind];
        tree[ind]%=modo;
        if(l!=r)
        {
         lazy[2*ind]=lazy[ind];
         lazy[2*ind+1]=lazy[ind];
        }
        lazy[ind]=0;
    }

    if(l>b||a>r)return;

    if(l>=a&&b>=r)
    {
        tree[ind]=getv(l,r)*v;
        tree[ind]%=modo;
        if(l!=r)
        {
            lazy[2*ind]=v;
            lazy[2*ind+1]=v;
        }
        return;
    }
    int mid=(l+r)>>1;
    query(l,mid,a,b,v,2*ind);
    query(mid+1,r,a,b,v,2*ind+1);

    tree[ind]=tree[2*ind]+tree[2*ind+1];
    tree[ind]%=modo;
}



int main()
{
    idfc;

    int n;
    int q;
    cin>>n>>q;
    int i;
    ll t=1;

    pp[0]=0;
    for(i=1;i<=n;i++)
    {
        vv[i]=modpow(10,n-i);
        pp[i]=(pp[i-1]+vv[i])%modo;
    //    cout<<pp[i]<<" ";
    }
    buildtree(0,n-1,1);
    int x,y,v;
   // cout<<tree[1]<<"\n";
    while(q--)
    {
        cin>>x>>y>>v;
        x--; y--;
        query(0,n-1,x,y,v,1);
        cout<<tree[1]<<"\n";
    }

    return 0;
}

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

int main() {
  int N, A;
  bool flag;
  int num;
  cin >> N >> A;

  num = N % 500;
  if(A >= num){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  } 
}

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

string alpha = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
string s;
string ss;
int n;

char find(char a, int n){
    for (int i = 0; i < alpha.size(); i++){
        if (alpha[i] == tolower(a))  return toupper(alpha[i+n]);
    }
}

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

    for (int i = 0; i < s.size(); i++){
        cout << find(s[i], n);
    }


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1145141919810
int main(){
    ll n;
    cin>>n;
    ll four=0,two=0;
    for(int i=0;i<n;i++){
        ll hoge;
        cin>>hoge;
        if(hoge%4==0)four++;
        else if(hoge%2==0)two++;
    }
    if(n%2==0){
        ll hoge=four*2+two*1;
        if(hoge>=n){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    else{
        ll hoge=four*2+two*1;
        if(hoge>=n-1){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }



}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define int long long int
#define vi vector<int>
#define vvi vector<vector<int>>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define mp make_pair
using namespace std;
int N=1e6+3;
vi sieve(N,1);
vi vis(N,0);
void sievex(int n)
{
    int i,j;
    sieve[1]=1;
    for(i=2;i<=n;i++)
    {
        if(vis[i])
        continue;
        for(j=i;j<=n;j+=i)
        {
            sieve[j]=i;
            vis[j]=1;
        }
    }
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int32_t main() {
	// your code goes here

	  //cout<<"Case #"<<x++<<":\n";
	 int n,i,j,k,m;
	 string s,t;
	 cin>>s>>t;
	 n=s.length(),m=t.length();
	 int mini=m;
	 for(i=0;i<n;i++)
	 {
	     if(i+m>n)
	     break;
	     int count=0;
	     for(j=i;j<i+m;j++)
	     {
	         if(s[j]!=t[j-i])
	         count++;
	     }
	     //cout<<i<<" "<<count<<endl;
	     mini=min(mini,count);
	 }
	 if(s==t)
	 mini=0;
cout<<mini<<"\n";
	return 0;
}


Measured memory_bytes: 18632
#a = list(map(int,input().split()))
a = input()
b = input()
pointer = 0
smallest  = 0
def compare(s1,s2):
	count = 0
	for x in range(len(s1)):
		if s1[x] == s2[x]:
			count+=1
	return count
for x in range(len(a)- len(b)+1):
	value =  compare(b,(a[x:x+len(b)]))
	smallest = max(value,smallest)
print(len(b) - smallest)


Measured memory_bytes: 9136
import java.util.*;
import java.io.*;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		int h = in.nextInt();
		int w = in.nextInt();
		String[] a = new String[h];
		for (int i = 0; i < h; i++) {
			a[i] = in.next();
		}

		boolean[] row = new boolean[h];
		Arrays.fill(row, false);
		boolean[] col = new boolean[w];
		Arrays.fill(col, false);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i].charAt(j) == '#') {
					row[i] = true;
					col[j] = true;
				}
			}
		}

		for (int i = 0; i < h; i++) {
			if (row[i]) {
				for (int j = 0; j < w; j++) {
					if (col[j]) {
						System.out.print(a[i].charAt(j));
					}
				}
				System.out.println();
			}
		}
	}
}



Measured memory_bytes: 26268
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const lint INF=1e18;

int n;
pi range[5005];
lint dp[5005][5005];
int main(){
  cin>>n;
  REP(i,n) cin>>range[i].fr>>range[i].sc;
  sort(range,range+n,[&](pi a,pi b ){
    return a.fr+a.sc>b.fr+b.sc;
  });

  REP(i,5005) REP(j,5005) dp[i][j]=INF;

  int m=(n+1)/2;
  dp[0][0]=0;

  REP(i,m+1) REP(j,m+1) if(dp[i][j]<INF){
    pi r=range[i+j];
    lint sum=r.fr+r.sc;
    if(n&1 && i+1==m) chmin(dp[i+1][j],dp[i][j]+sum*i);
    else chmin(dp[i+1][j],dp[i][j]+sum*i+r.sc);
    if(n&1 && j+1==m) chmin(dp[i][j+1],dp[i][j]+sum*j);
    else chmin(dp[i][j+1],dp[i][j]+sum*j+r.fr);
  }
  lint res=INF;
  REP(i,m+1) REP(j,m+1) if(i+j==n) chmin(res,dp[i][j]);
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 195968
#include <bits/stdc++.h>
using namespace std;
int main(){
	int m; cin >> m;
	string s; cin >> s;
	const int mod = 1'000'000'007;
	int len = s.size(), n = 5001;
	vector<int> f(2 * n, 0), nf;
	f[len] = 1;
	for(int i = 0; i < m; i++){
		nf.assign(2 * n, 0);
		for(int j = 0; j < 2 * n; j++){
			if(f[j]){
				nf[j + 1] += f[j];
				if(nf[j + 1] >= mod) nf[j + 1] -= mod;
				nf[j + 1] += f[j];
				if(nf[j + 1] >= mod) nf[j + 1] -= mod;
				int nm = max(0, j - 1);
				nf[nm] += f[j];
				if(nf[nm] >= mod) nf[nm] -= mod;
			}
		}
		f = nf;
	}
	cout << f[0] << endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a)
    {
        cout << k << endl;
    }
    else if (k <= (a + b))
    {
        cout << a << endl;
    }
    else
    {
        cout << (a - (k - (a + b))) << endl;
    }
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int main() {
    ll D, G;
    cin>>D>>G;
    ll p[D], c[D];
    for(ll i=0;i<D;++i){
        cin>>p[i]>>c[i];
    }
    ll ans = big;
    ll tmpans;
    ll tmpscore;
    for(ll bit=0;bit<(1<<D);++bit){
        tmpans = 0;
        tmpscore = 0;
        for(ll i=0;i<D;++i){
            if((bit&(1<<i))!=0){
                tmpans += p[i];
                tmpscore += p[i] * 100 * (i+1);
                tmpscore += c[i];
            }
        }
        if(tmpscore<G){
            for(ll j=D-1;j>=0;--j){
                if((bit&(1<<j))==0){
                    if(tmpscore + p[j] * 100 * (j+1) >= G){
                        if((G-tmpscore)%(100*(j+1))==0){
                            tmpans += (G-tmpscore)/(100*(j+1));
                            tmpscore = G;
                        }
                        else{
                            tmpans += (G-tmpscore)/(100*(j+1)) + 1;
                            tmpscore = G;
                        }
                    }
                    break;
                }
            }
        }
        //cout<<bit<<endl;
        //cout<<tmpans<<" "<<tmpscore<<endl;
        if((tmpans<ans)&(tmpscore>=G))ans = tmpans;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
import java.util.Scanner;

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

		//?¶???????????????????????????°?????????
		int n = sc.nextInt();

		//2?¬???????????????£?¨?
		boolean [][] cards = new boolean[4][13];
		//?????????????????????????????°?????????
		for(int i = 0; i < n; i++){
			String mark =sc.next();

			//???????????????
			if(mark.equals("S")){
				cards[0][sc.nextInt()-1] = true;
			}else if(mark.equals("H")){
				cards[1][sc.nextInt()-1] = true;
			}else if(mark.equals("C")){
				cards[2][sc.nextInt()-1] = true;
			}else if(mark.equals("D")){
				cards[3][sc.nextInt()-1] = true;
			}
		}
		//
		for(int i = 0; i<cards.length;i++){
			for(int j = 0; j<cards[0].length;j++){
				//true????????¨???
				if(!cards[i][j]){
					if(i == 0){
						System.out.println("S " + (j+1));
					}else if(i == 1){
						System.out.println("H " + (j+1));
					}else if(i == 2){
						System.out.println("C " + (j+1));
					}else if(i == 3){
						System.out.println("D " + (j+1));
					}
				}
			}
		}
	}
}

Measured memory_bytes: 26112
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayDeque;

public class Main{
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(br.readLine());
    ArrayDeque<Integer> list = new ArrayDeque<Integer>();
    for(int i = 0; i < n; i++){
      String[] tmp = br.readLine().split(" ");
      if(tmp[0].equals("insert")){
        list.addFirst(Integer.parseInt(tmp[1]));
      }else if(tmp[0].equals("deleteFirst")){
        list.removeFirst();
      }else if(tmp[0].equals("deleteLast")){
        list.removeLast();
      }else{
        list.remove(Integer.parseInt(tmp[1]));
      }
    }
    StringBuilder sb = new StringBuilder();
    sb.append(list.poll());
    while(list.peekFirst() != null){
      sb.append(" ").append(list.poll());
    }
    System.out.println(sb);
  }
}

Measured memory_bytes: 188612
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, m) = listOfInt()
    val pref = IntArray(m){0}

    repeat(n) {
        val aa = listOfInt().drop(1)
        aa.forEach {
            pref[it-1]++
        }
    }

    println(pref.count { it == n })
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37868
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



int main(void) {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	char c;
	rep(i, 0, 4) {
		std::cin >> c;
		std::cout << c;
	}
	std::cout << " ";
	rep(i, 0, 8) {
		std::cin >> c;
		std::cout << c;
	}
	std::cout << "\n";
	return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll a, b;
  cin >> a >> b;

  if (a >= 13) {
    cout << b << "\n";
  } else if (a <= 12 && a >= 6) {
    cout << b / 2 << "\n";
  } else {
    cout << 0 << "\n";
  }
}

Measured memory_bytes: 256
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
import sys
n,T = ma()
ans=10**15
for i in range(n):
    c,t=ma()
    if t<=T:
        ans=min(ans,c)
if ans==10**15:
    print("TLE")
else:print(ans)


Measured memory_bytes: 9464
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n, m;
vi G[100010];
bool used[100010];

deque<int> deq;

int main(){

  n = in();
  m = in();
  REP( i , m ){
    int a = in() - 1;
    int b = in() - 1;
    G[a].pb( b );
    G[b].pb( a );
  }

  int x = 0;
  int y = G[0][0];
  used[x] = true;
  used[y] = true;
  deq.push_back( 0 );
  deq.push_back( y );

  while( 1 ){
    int nex = -1;
    YYS( w , G[y] ){
      if( not used[w] ){
        nex = w;
        break;
      }
    }
    if( nex == -1 ){
      break;
    }
    used[nex] = true;
    deq.push_back( nex );
    y = nex;
  }

  while( 1 ){
    int nex = -1;
    YYS( w , G[x] ){
      if( not used[w] ){
        nex = w;
        break;
      }
    }
    if( nex == -1 ){
      break;
    }
    used[nex] = true;
    deq.push_front( nex );
    x = nex;
  }

  vi ans(0);
  YYS( w , deq ){
    ans.pb( w );
  }
  
  printf( "%lld\n" , SZ(ans) );
  REP( i , SZ(ans) ){
    if( i != 0 ){
      printf( " " );
    }
    printf( "%d" , ans[i]+1 );
  }
  printf( "\n" );

  return 0;
}


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

int n,k,a[1000];
int dp[100005];
bool rec(int K=k)
{
    if(K==0)
        return 0;
    if(dp[K]+1)
        return dp[K];
    for(int i=0;i<n;i++)
    {
        if(K>=a[i]&&!rec(K-a[i]))
            return dp[K] = 1;
    }
    return dp[K] = 0;
}

int main()
{
    memset(dp,-1,sizeof dp);
    cin >> n >> k;
    for(int i=0;i<n;i++)
        cin >> a[i];
    if(rec())
        cout << "First";
    else
        cout << "Second";
    return 0;
}


Measured memory_bytes: 3712
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Deque;
 
 
class Main {
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int q = scan.nextInt();

    Deque<deque> d = new ArrayDeque<deque>();

    for(int i = 0; i < n; ++i) {
        String name = scan.next();
        int time = scan.nextInt();
        d.add(new deque(name, time));
    }
     
    int elapsed = 0;
    while(!d.isEmpty()){
         deque p = d.removeFirst();
         if(p.time > q) {
            elapsed += q;
            d.add(new deque(p.name, p.time - q));
         }else{
            elapsed += p.time;
            System.out.println(p.name + " "  + elapsed);
         }
    }
  }
}
 
class deque {
    public String name;
    public int time;
    public deque(String n, int t) {
        name = n;
        time = t;
    }
 }

Measured memory_bytes: 76304
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextLine.toInt
    val restaurants = List.fill(n)(sc.nextLine.split(" "))
    restaurants.zipWithIndex.sortBy(item => (item._1(0), -item._1(1).toInt)).map(_._2).map(_ + 1).foreach(println)
  }
}


Measured memory_bytes: 25804
#![allow(non_snake_case)]

use std::io;

/// u:上, f:前,l:左, b:奥, r:右, d:下
#[derive(Debug)]
struct Dice {
    u: u32, f: u32, r: u32, l: u32, b: u32, d: u32, 
}

#[allow(dead_code)]
impl Dice {
    fn new(u: u32, f: u32, r: u32, l: u32, b: u32, d: u32) -> Dice {
        Dice {u, f, r, l, b, d}
    }

    fn from_vec(vec: &Vec<u32>) -> Dice {
        assert_eq!(vec.len(), 6);
        Dice {
            u: vec[0], f: vec[1], r: vec[2], l: vec[3], b: vec[4], d: vec[5],
        }
    }

    fn from_dice(dice: &Dice) -> Dice {
        Dice {u: dice.u, f: dice.f, r: dice.r, l: dice.l, b: dice.b, d: dice.d, }
    }

    fn move_s(&mut self){
        let tmp = self.u;
        self.u = self.b;
        self.b = self.d;
        self.d = self.f;
        self.f = tmp;
    }

    fn move_n(&mut self) {
        let tmp = self.u;
        self.u = self.f;
        self.f = self.d;
        self.d = self.b;
        self.b = tmp;
    }

    fn move_e(&mut self) {
        let tmp = self.u;
        self.u = self.l;
        self.l = self.d;
        self.d = self.r;
        self.r = tmp;
    }

    fn move_w(&mut self) {
        let tmp = self.u;
        self.u = self.r;
        self.r = self.d;
        self.d = self.l;
        self.l = tmp;
    }

    fn rotate_r(&mut self){
        let tmp = self.f;
        self.f = self.l;
        self.l = self.b;
        self.b = self.r;
        self.r = tmp;
    }

    fn rotate_l(&mut self){
        let tmp = self.f;
        self.f = self.r;
        self.r = self.b;
        self.b = self.l;
        self.l = tmp;
    }

    fn operate(&mut self, op: char){
        match op {
            'S' => self.move_s(),
            'N' => self.move_n(),
            'W' => self.move_w(),
            'E' => self.move_e(),
            'R' => self.rotate_r(),
            'L' => self.rotate_l(),
            _ => (),
        };
    }

    fn operate_string(&mut self, ops: &String) {
        for c in ops.chars() {
            self.operate(c);
        }
    }

    fn top(&self) -> u32 {
        self.u
    }
}

fn main() {
    let sin = io::stdin();
    let mut buf = String::new();
    sin.read_line(&mut buf).ok();
    let v = buf.split_whitespace()
        .map(|v| v.parse::<u32>().unwrap() )
        .collect::<Vec<u32>>();

    let mut dice = Dice::from_vec(&v);

    let mut ops = String::new();
    sin.read_line(&mut ops).ok();
    
    dice.operate_string(&ops);
    println!("{}", dice.top());
}



Measured memory_bytes: 5028
s = list(map(int, input()))
n = len(s)
p = 2019
ans = 0

s.reverse()
cum = [0] * (n+1)
for i in range(n):
    cum[i+1] = (cum[i] + s[i] * pow(10, i, p)) % p
t = [0] * p
for x in cum: t[x] += 1

for x in t:
    ans += x * (x-1) // 2
print(ans)


Measured memory_bytes: 17996
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
const int INF = 1010101010;

struct UnionFind {
  vector<int> par;  // par[i]:iの親の番号　

  UnionFind(int N) : par(N) {  //最初は全てが根であるとして初期化
    for (int i = 0; i < N; i++) par[i] = i;
  }

  int root(int x) {  // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y) {  // xとyの木を併合
    int rx = root(x);         // xの根をrx
    int ry = root(y);         // yの根をry
    if (rx == ry) return;  // xとyの根が同じ(=同じ木にある)時はそのまま
    par[rx] =
        ry;  // xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
  }

  bool same(int x, int y) {  // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main() {
  // 頂点数と辺数
  int N, M;
  cin >> N >> M;

  // グラフ入力受取 (ここでは無向グラフを想定)
  Graph G(N);

  UnionFind tree(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree.unite(a, b);
    G[a].push_back(b);
    G[b].push_back(a);
  }

  // BFS のためのデータ構造
  vector<int> dist(N, -1);  // 全頂点を「未訪問」に初期化
  queue<int> que;

  // 初期条件 (頂点 0 を初期ノードとする)
  dist[0] = 0;
  que.push(0);  // 0 を橙色頂点にする

  // BFS 開始 (キューが空になるまで探索を行う)
  while (!que.empty()) {
    int v = que.front();  // キューから先頭頂点を取り出す
    que.pop();

    // v から辿れる頂点をすべて調べる
    for (int nv : G[v]) {
      if (dist[nv] != -1) continue;  // すでに発見済みの頂点は探索しない

      // 新たな白色頂点 nv について距離情報を更新してキューに追加する
      dist[nv] = dist[v] + 1;
      que.push(nv);
    }
  }

  bool ok = true;
  for (int i = 1; i < N; i++) {
    if (!tree.same(0, i)) ok = false;
  }

  if (ok) {
    cout << "Yes" << endl;
    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    vector<int> k(N);
    k[0] = 0;
    for (int i = 1; i < N; i++) {
      k[dist[i]] = i;
    }
    for (int v = 1; v < N; ++v) {
      cout << k[dist[v] - 1] + 1 << endl;
    }
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 11172
#include <stdio.h>

int main(){
    char s[27];
    int i,j;
    
    scanf("%s",s);

    for(i = 0;s[i] != '\0';i++){
        for(j = 0;s[j] != '\0';j++){
            if(i == j){

            }
            else if(s[i]==s[j]){
                printf("no\n");
                return 0;
            }
        }
    }
    printf("yes\n");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define int long long
#define ff first
#define ss second
#define loop(i,k,n) for(int i=k;i<n;++i)
#define rloop(i,n,k) for(int i=n;i>=k;i--)
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define all(v) v.begin(),v.end()
#define mset(a,i) memset(a,i,sizeof(a))
#define mii map<int,int>  
#define pii pair<int,int>
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define mp make_pair
#define pb push_back
#define mod 1000000007  
#define endl "\n"
#define inf 1e18

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> pbds1;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { if(0) return; cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args){   
    if(0) return; 
    const char* comma = strchr (names + 1, ',');
    cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}
void get_it_done(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}
int gcd(int a,int b){
    if(b==0) return a;
    if(a<b) return gcd(b,a);
    return gcd(b,a%b);
}
const int N = 3e5+5;
int n,m;
vi adjList[N];
bool visited[N];
int dp[N];

int dfs(int node){
    visited[node] = 1;
    if(dp[node]!=-1){
        return dp[node];
    }
    int ans = 0;
    for(auto x:adjList[node]){
        ans = max(ans,1+dp[x]);
        if(!visited[x]){
            ans = max(ans,1+dfs(x));
        }
    }
    return dp[node] = max(ans,dp[node]);
}

void solve(){
    cin>>n>>m;
    loop(i,0,m){
        int u,v;
        cin>>u>>v;
        adjList[u].pb(v);
    }
    mset(dp,-1);
    mset(visited,0);
    int ans = 0;
    loop(i,1,n+1){
        if(!visited[i]){
            ans = max(ans,dfs(i));
        }
    }
    cout<<ans<<endl;
}

int32_t main(){
    get_it_done(); 
    int tc=1;
    // cin >> tc;
    while (tc--){
        solve();        
    }
}


Measured memory_bytes: 15104
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
char S[MAX_N];
int solve(char a, char b) {
	int n = strlen(S);
	int res = 0;
	for (int i = 0; i < n; i += 2) if (S[i] != a) res++;
	for (int i = 1; i < n; i += 2) if (S[i] != b) res++;
	return res;
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	scanf("%s", S);
	printf("%d\n", min(solve('0', '1'), solve('1', '0')));
	return 0;
}

Measured memory_bytes: 384
num = input().split()
str = [input()]
strc = ''
flg = 0
res = ''
for i in range(int(num[0])-1):
#	print(1)
	strc = input()
	for j in range(len(str)):
		if str[j] < strc:
#			print(2)
			flg = 0
		else:
#			print(3)
			flg = j
			break
		j += 1
	flg = -1
	if flg == 0:
		str.append(strc)
	else:
		str.insert(j,strc)
#	print(str)
for x in str:
	res += x
print(res)

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

using namespace std;
bool isodd(int i){
    int a = 0;
    
    while(i!=0){
        a++;
        i= i/10;
    }
    return a%2!=0;
}
int main(){
    int n;
    cin>>n;
    int count = 0;
    for(int i=1;i<=n;i++){
        if(isodd(i)){
            //cout<<i<<endl;
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
s = gets.chomp
h = Hash.new(0)
s.size.times do |i|
  h[s[i]] += 1
end
if h.size == 3 && h.values.max - h.values.min <= 1
  puts "YES"
elsif h.size == 2 && s.size == 2
  puts "YES"
elsif s.size == 1
  puts "YES"
else
  puts "NO"
end

Measured memory_bytes: 1916
#C
def f(x):
    return int(x) - 1

n, q = map(int, input().split())
s = input()
t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i + 2] == "AC" else 0)
# print(t)
for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])

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

int main() {
  int N, T, c, t;
  cin >> N >> T;
  
  int ans = 1e9;
  
  for (int i = 0; i < N; i++) {
    cin >> c >> t;
    if(ans > c && t <= T) ans = c;
  }
  
  if(ans == 1e9) cout << "TLE" << endl;
  else cout << ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b;
  a = 0;
  string s;
  in(s);
  rep(i, s.size()){
    if(i % 2 == 0){
      if(s[i] == '0')
        a++;
    }
    else{
      if(s[i] == '1')
        a++;
    }
  }
  a = min(a, (ll)s.size() - a);
  out(a);
  memi;
}

Measured memory_bytes: 512
A, B, N = list(map(int, input().split()))

if B==1:
  print(0)
else:
  tb = B - 1
  tp_pre = 0
  while(True):
    tp = (A*tb)//B - A*(tb//B)
    if tp > tp_pre:
      tp_pre = tp
    tb += B
    if tb > N:
      break
  if (B > N):
    print((A*N)//B - A*(N//B))
  else:
    print(int(tp_pre))

Measured memory_bytes: 9200
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;

vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
int main() {
    
    int n;
    cin >> n;
    int sum = 0;
    vector<int> s(n);
    rep(i,0,n){
        cin >> s[i];
        sum+=s[i];
    }
    sort(s.begin(), s.end());
    rep(i, 0, n){
        if(sum%10){
           cout << sum << endl;
           return 0;
        }
        if(s[i]%10){
            sum-=s[i];
        }
    }
    cout << sum%10 << endl;
    return 0;
}


Measured memory_bytes: 5912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int sumA = 0;
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			sumA += a;
		}
		
		int ans = sumA <= n ? n - sumA : -1;
		System.out.println(ans);
	}
}


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

int main(){
    int n;
    cin>>n;
    vector<int> h(n);
    vector<bool> dp(n,false);
    for(int i=0;i<n;i++) cin>>h[i];
    dp[0]=true;
    for(int i=1;i<n;i++){
        for(int j=1;j>=0;j--){
            if(h[i]-j>=h[i-1]){
                if(dp[i-1]){
                    dp[i]=true;
                    h[i]-=j;
                    break;
                }
            }
            dp[i]=false;
        }
    }
    if(dp[n-1]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3768
#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 = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int d = 0;
    int ans = 1;
    for (int i = 0; i < n && d + l[i] <= x; i++) {
        d += l[i];
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import combinations

inputs = []
n,x = map(int,input().split())
while n != 0 or x != 0:
     inputs.append((n,x))
     n,x = map(int,input().split())

for n,x in inputs:
    print(len([0 for c in combinations(range(1,n+1),3) if sum(c) == x]))


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

#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;

typedef long long ll;

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);}
int lcm(int a,int b){
	return a/gcd(a,b)*b;}
#define Len 100005
typedef struct pp{
	char name[20];
	int t;
}P; 

P Q[Len];
int head,tail,n;

void enqueue(P x){/*在tail所指位置添加x，由于元素数增加一，
			所以tail也随之加一，此时如果超过数组容量上限则
			重置为0*/ 
	Q[tail]=x;
	tail=(tail+1)%Len;
}
P dequeue(){/*将头指针所指对头元素暂存入变量x,随后
			头指针加一，然后返回x值 */ 
	P x=Q[head];
	head = (head+1)%Len;
	return x; 
}
int min(int a,int b) {
	return a<b?a:b;
}
int main(){
	int elaps=0,c;
	int i,q;
	P u;
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1;
	tail=n+1;
	
	while(head!=tail){
		u=dequeue();
		c=min(q,u.t);
		u.t-=c;
		elaps+=c;
		if(u.t>0)enqueue(u);
		else {
			printf("%s %d\n",u.name,elaps);
		}
	}
	return 0;
}

/*
5 100
p1 150
p2 80
p3 200
p4 350
p5 20
*/
/*p2 180
p5 400
p1 450
p3 550
p4 800
*/


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

typedef long long ll;

const int maxn = 1e5 + 1e2;
int val[maxn];

int main(){
	std::ios::sync_with_stdio(false);

	int n, k;
	std::cin >> n >> k;

	for(int i = 0; i < n; i++){
		std::cin >> val[i];
	}

	int stop = n;
	for(int i = 0; i < n; i++){
		if(val[i] >= 0){
			stop = i;
			break;
		}
	}

	int res = 1e9;

	for(int i = 0; i <= stop; i++){
		int takena = stop - i;
		int need = k - takena;

		if(i == stop and stop + need - 1 < n){
			res = std::min(res, val[stop + need - 1]);
		} else if(need <= 0 and val[i] < 0){
			res = std::min(res, -val[i]);
		} else if(val[i] < 0 and stop + need - 1 < n){
			res = std::min(res, -val[i] + val[stop + need - 1] + std::min(-val[i], val[stop + need - 1]));
		}
	}

	std::cout << res << '\n';
}

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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

long long N, M, V, P;
vector<long long> A, acum;

bool check(int x) {
    if (x < P) return true;
    if (A[x] + M < A[P-1]) return false;
    
    long long room = M * (P+N-x-1) + (x-P+1) * (A[x]+M) - (acum[x] - acum[P-1]);
    return room >= M * V;
}

int main() {
    cin >> N >> M >> V >> P;
    A.resize(N);
    for (int i=0; i<N; ++i) cin >> A[i];
    sort(A.rbegin(), A.rend());

    acum.resize(N+1);
    acum[0] = 0;
    for (int i=0; i<N; ++i) {
        acum[i+1] = acum[i] + A[i];
    }
    
    int l = 0, r = N;
    while (r-l > 1) {
        int mid = (l+r) / 2;
        if (check(mid)) l = mid;
        else r = mid;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef pair<double, int> Pii;

struct edge{int to; double cost;};

class Graph
{
public:
    int V;
    vector<vector<edge>> G;
    vector<double> d;
    

    Graph(int V): V(V){
        G = vector<vector<edge>>(V, vector<edge>(0));
        d = vector<double>(V);
    }

    void add_edge(int from, int to, double cost){
        G[from].push_back(edge({to, cost}));
    }

    void add_edge2(int v1, int v2, double cost){
        add_edge(v1, v2, cost);
        add_edge(v2, v1, cost);
    }

    void dijkstra(int s, int t){
        priority_queue<Pii, vector<Pii>, greater<Pii>> que;
        fill(d.begin(), d.end(), INF);
        d[s] = 0;
        que.push(Pii(0, s));

        while(!que.empty()){
            Pii p = que.top(); que.pop();
            int v = p.second;
            if(v == t) return;
            if(d[v] < p.first) continue;
            REP(i, G[v].size()){
                edge e = G[v][i];
                if(d[e.to] > d[v] + e.cost){
                    d[e.to] = d[v] + e.cost;
                    que.push(Pii(d[e.to], e.to));
                }
            }
        }
    }

    void bellman_ford(int s){
        fill(d.begin(), d.end(), INF);
        d[s] = 0;
        while(true){
            bool update = false;
            REP(v, V){
                REP(i, G[v].size()){
                    edge e = G[v][i];
                    if(d[v] != INF && d[e.to] > d[v] + e.cost){
                        d[e.to] = d[v] + e.cost;
                        update = true;
                    }
                }
            }
            if(!update) break;
        }
    }

};

double dist(double x1, double y1, double x2, double y2){
    return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}

signed main(){

    double xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    int N; cin >> N;
    Graph G(N + 2);
    G.add_edge(N, N + 1, dist(xs, ys, xt, yt));

    vector<double> x(N), y(N), r(N);
    REP(i, N){
        cin >> x[i] >> y[i] >> r[i];
        G.add_edge(N, i, max(0.0, dist(x[i], y[i], xs, ys) - r[i]));
        G.add_edge(i, N + 1, max(0.0, dist(x[i], y[i], xt, yt) - r[i]));
    }

    REP(i, N) REP(j, i) G.add_edge2(i, j, max(0.0, dist(x[i], y[i], x[j], y[j]) - r[i] - r[j]));
    
    G.dijkstra(N, N + 1);
    //G.bellman_ford(N);

    cout << setprecision(12) << G.d[N + 1] << endl;

    return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

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

  vector<double> p(n);
  rep(i, 0, n) cin >> p[i];

  vector<vector<double>> dp(n+1, vector<double>(n+1));
  dp[0][0] = 1.0;
  rep(i, 0, n) rep(j, 0, n){
    dp[i+1][j] += dp[i][j]*(1-p[i]);
    dp[i+1][j+1] += dp[i][j]*p[i];
  }

  double ans = 0;
  rep(i, 0, n+1){
    if(i > n-1-i) ans += dp[n][i];
  }
  printf("%.12f\n", ans);

  return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  int product=0;
  if(a<=9 && b<=9) {
    product=a*b;
    cout << product << endl;}
  else {
    product=-1;
    cout << product << endl;}
  return 0;
  }

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		long a = sc.nextInt();
		long b = sc.nextInt();
		long c = sc.nextInt();
		long ans = 0;
		if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {

		} else {
			if (a >= b && a >= c) {
				ans = (a / 2 + 1) * b * c - b * c * (a / 2);
			} else if (b >= a && b >= c) {
				ans = (b / 2 + 1) * a * c - a * c * (b / 2);
			} else if (c >= a && c >= b) {
				ans = (c / 2 + 1) * a * b - a * b * (c / 2);
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21204
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/g.inp"
exit $?
'''
import sys
from collections import deque


def _s(): return sys.stdin.readline().strip()


def _sa(): return sys.stdin.readline().strip().split()


def _i(): return int(sys.stdin.readline().strip())


def main():
    s = deque([c for c in _s()])
    q = _i()
    flip = 0
    for _ in range(q):
        tmp = _sa()
        op = int(tmp[0])
        if op == 1:
            flip ^= 1
        else:
            loc = int(tmp[1]) - 1
            c = tmp[2]
            if flip ^ loc:
                s.append(c)
            else:
                s.appendleft(c)

    n = len(s)
    for _ in range(n):
        if flip == 0:
            print(s.popleft(), end="")
        else:
            print(s.pop(), end="")


if __name__ == "__main__":
    main()


Measured memory_bytes: 92080
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BPopularVote solver = new BPopularVote();
        solver.solve(1, in, out);
        out.close();
    }

    static class BPopularVote {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
        int x = Integer.parseInt(in.next());
        int y = Integer.parseInt(in.next());
        int z = Integer.parseInt(in.next());
        out.println("" + z + " " + x + " " + y);
        }
    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;

int X,Y,Z;
multiset<string> m;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> X >> Y >> Z;
	F0R(i,X) m.insert("a");
	F0R(i,Y) m.insert("b");
	F0R(i,Z) m.insert("c");
	while (m.size() > 1) {
	    string x = *m.begin(); m.erase(m.begin());
	    string y = *m.rbegin(); m.erase(prev(m.end()));
	    m.insert(x+y);
	}
	cout << *m.begin();
}

// read!
// ll vs. int!

Measured memory_bytes: 256