akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
 
 
using namespace std;
 
typedef long long ll;
 
const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
typedef pair<int, int> pii;
 
 
int main() {
	int n;
	cin >> n;
	vector<int> t(n+1);
	vector<int> sum_t(n + 1);
	for (int i = 0; i < n;i++) {
		cin >> t[i];
		sum_t[i+1] +=sum_t[i] + t[i];
	}
	t[n] = 1;
	vector<int> v(n+1);
	for (int i = 0; i < n;i++) {
		cin >> v[i];
	}
	v[n] = 0;
 
	double vel = 0;
	double ans = 0;
	int i_n = 0;
	//cout << sum_t[n] << endl;
	for (double ti = 1; ti <=2*sum_t[n]; ti++) {
		//cout << ans << endl;
		bool isDecreace = false;
		if (2*(sum_t[i_n] + t[i_n] )< ti) {
			
			i_n++;
			
		}
		for (int i = i_n+1;i <=n;i++) {
			
			
			
			if ((2 * sum_t[i] - ti) <=( vel-1-2 * v[i])) {
				//cout << sum_t[i] << " " << v[i] << endl;
				ans += (2 * vel - 1) / 2.0;
				//cout << ti << " " << (2 * vel - 1) / 2.0 << endl;
				vel--;
				isDecreace = true;
				break;
			}
		}
 
		if (!isDecreace) {
			if (vel == 2 * v[i_n]) {
				ans += vel;
			}
			else {
				ans += (2 * vel + 1) / 2.0;
				//cout << ti << " " << (2 * vel + 1) / 2.0 << endl;
				vel++;
			}
		}
		//cout << ti << " " << vel << endl;
 
	}
	cout << setprecision(10) <<ans/4 << endl;
 
}

Measured memory_bytes: 384
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int p = 0;//????????????????????????
		char weather[][] = new char[h][];//??\?????¨
		int ans[][] = new int[h][w];//????????¨
		for(int i = 0; i < h; i++){//????????????????????\???
			weather[i] = sc.next().toCharArray();
		}
		
		for(int i = 0; i < h; i++){//????????°?????????
			int cloud = -1;//???????????????????´?
			for(int k = 0; k < w; k++){
				if(weather[i][k] == 'c'){//????????£??????
					cloud = k;
					ans[i][k] = 0;
				}else if(cloud == -1 && weather[i][k] == '.'){//"."??§???????????´??????????????????
					ans[i][k] = -1;
				}else{//"."??§?????????????????????
					int d = k - cloud;//?????¨????????¢
					ans[i][k] = d;
				}
			}
		}
		for(int i = 0; i < h; i++){
			p = 0;
			for(int k = 0; k < w; k++){
				if(p == w-1){
					System.out.println(ans[i][k]);
				}else{
					System.out.print(ans[i][k]);
					System.out.print(" ");
					p++;
				}
			}
		}
		
	}

}

Measured memory_bytes: 34524
#include <stdio.h>
#define N 100001
int main(){
  int n,m,l[N]={},r[N]={},i,max,min,ans;
  scanf("%d%d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d%d",l+i,r+i);
  }
  max=l[0];
  min=r[0];
  for(i=1;i<m;i++){
    if(l[i]>max){
      max=l[i];
    }
    if(r[i]<min){
      min=r[i];
    }
  }
  ans=min-max+1;
  if(ans>n){
    ans=n;
  }
  if(ans<0){
    ans=0;
  }
  printf("%d\n",ans);
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
    int a, p;
    cin >> a >> p;
    int tmp = (3 * a + p) / 2;
    cout << tmp << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(unsigned long long x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

// 配列がソートされたときに移動するインデックスの配列を返す
// 配列自体はソートされない
// {1, 6, 2, 3, 6} -> {0, 3, 1, 2, 4}
template<typename T>
vi sortIndex(const vector<T>& vec){
    vi idx(SZ(vec));
    iota(ALL(idx), 0);
    stable_sort(ALL(idx), [&vec](int l, int r){
        return vec[l] < vec[r];
    });
    return idx;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    vi ans = sortIndex(a);
    rep(i, n){
        cout << ans[i]+1 << " \n"[i==n-1];
    }
    return 0;
}

Measured memory_bytes: 1984
h,n = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
dp = [1e100]*(h+1)
dp[0] = 0

for i in range(n):
    for j in range(h+1):
        if dp[j] != 1e100:
            nj = j + a[i]
            if nj >= h:
                nj = h
            dp[nj] = min(dp[nj],dp[j] + b[i])
print(dp[h])


Measured memory_bytes: 50780
#include <string>
#include <map>
#include <vector>
#include <iostream>
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
cin>>a>>b>>c;
if(a==b&&a==c){
    cout<<"Yes";
}else{
    cout<<"No";
}

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <map>
#include <string>
using namespace std;

int main() {
	string S;
	cin >> S;
	int ans = 0;
	for (int i = 1; i < S.size(); i++) {
		if (S.at(i - 1) == S.at(i)) {
			if (S.at(i) == '0') S.at(i) = '1';
			else S.at(i) = '0';
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 512
def cookie_T(a,b):
    if a%2!=0:
        a-=1
    b+=(a//2)
    a=a//2
    return a,b
def cookie_A(a,b):
    if b%2!=0:
        b-=1
    a+=(b//2)
    b=b//2
    return a,b
A,B,K=map(int,input().split())
for i in range(K):
    if i%2==0:
        A,B=cookie_T(A,B)
    else:
        A,B=cookie_A(A,B)
print("{} {}".format(A,B))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
static const int N = 100;

int main()
{
    int M[N][N];
    int n, u, k, v;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = 0;
        }
    }

    for (int i = 0; i < n; i++)
    {
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            cin >> v;
            M[u - 1][v - 1] = 1;
        }
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (j)
            {
                cout << " ";
            }
            cout << M[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;

int main() {
    string S;
    cin >> S;
    rep(i, S.size() - 1) {
        if (S.substr(i, 2) == "AC") {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
using namespace std;
int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if (s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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


int main() {
    int n,k,temp;
    cin>>n>>k;
    int ans=0;
    rep(i,n){
        cin>>temp;
        if(temp>=k)ans++;
    }
    cout << ans <<endl;
}


Measured memory_bytes: 256
def resolve():
  H, W = map(int, input().split(" "))
  s = []
  dp = [[0] * W for i in range(H)]
  for _ in range(H):
    s.append([x == "." for x in list(input())])

  for h in range(H):
    for w in range(W):
      if h == 0 and w == 0:
        if not s[0][0]:
          dp[0][0] = 1

      elif h == 0:
        dp[0][w] = dp[0][w-1]
        if s[0][w-1] and not s[0][w]:
          dp[0][w] += 1

      elif w == 0:
        dp[h][0] = dp[h-1][0]
        if s[h-1][0] and not s[h][0]:
          dp[h][0] += 1

      else:
        # 左側と上側を見て、操作回数が最小になるようにする。
        # 上だけをみる
        temp_up = dp[h-1][w]
        if s[h-1][w] and not s[h][w]:
          temp_up += 1

        # 左だけを見る
        temp_left = dp[h][w-1]
        if s[h][w-1] and not s[h][w]:
          temp_left += 1

        dp[h][w] = min(temp_up, temp_left)

  print(dp[H-1][W-1])

if __name__ == "__main__":
  resolve()

Measured memory_bytes: 74452
#!/usr/bin/env python3
# from typing import *

import collections


# def solve(N: str, c: List[str]) -> int:
def solve(c):
    counts = collections.Counter(c)
    if counts['R'] == 0 or counts['W'] == 0:
        return 0

    inversions = 0
    for i in range(counts['R']):
        if c[i] != 'R':
            inversions += 1

    return inversions

# generated by online-judge-template-generator v4.4.0 (https://github.com/kmyk/online-judge-template-generator)
def main():
    _ = int(input().rstrip())
    c = input().rstrip()
    a = solve(c)
    print(a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 74296
sx, sy, tx, ty = map(int, input().split())

dx, dy = tx - sx, ty - sy

first = 'U' * dy + 'R' * dx
second = 'D' * dy + 'L' * dx
third = 'L' + 'U' * (dy + 1) + 'R' * (dx + 1) + 'D'
forth = 'R' + 'D' * (dy + 1) + 'L' * (dx + 1) + 'U'

print(first + second + third + forth)

Measured memory_bytes: 9156
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long;
using pll = pair<ll,ll>;

#define reps(i,s,n) for(int (i) = (s) ;(i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int main(){
    string str;
    cin >> str;
    string ans = "YAKI";
    if(str.substr(0,4) == ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	ll A, V, B, W, T;
	cin >> A >> V >> B >> W >> T;
	bool ans = false;
	if(A < B){
		if(A + V * T >= B + W * T){
			ans = true;
		}
	}
	else{
		if(A - V * T <= B - W * T){
			ans = true;
		}
	}

	if(ans){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
typedef pair<double, double> P;
typedef pair<P, int> PP;

template <typename T>
struct BIT
{
    int n;
    vector<T> bit;
    
    BIT(){}
    
    BIT(int n) : n(n){
        bit.resize(n + 1);
    }
    
    T sum(int i){
        i++;
        T res = 0;
        while(i){
            res += bit[i];
            i -= (i & -i);
        }
        return res;
    }
    
    void add(int i, T x){
        i++;
        while(i <= n){
            bit[i] += x;
            i += (i & -i);
        }
    }
};

int main()
{
    int n;
    cin >> n;
    double a[40005], b[40005], c[40005];
    for(int i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i];
    for(int u = 0; u < 2; u++){
        bool f = false;
        P p[40005];
        double r;
        for(int i = 0; i < n; i++){
            if(b[i] == 0){
                f = true;
                r = c[i];
            }
            else{
                if(f) p[i - 1] = P(-a[i] / b[i], c[i] / b[i]);
                else p[i] = P(-a[i] / b[i], c[i] / b[i]);
            }
        }
        if(f) n--;
        sort(p, p + n);
        PP pp[40005];
        for(int i = 0; i < n; i++) pp[i] = PP(p[i], i);
        if(f) n++;
        double left = -1e18, right = 1e18;
        for(int t = 0; t < 200; t++){
            if(f) n--;
            double mid = (right + left) / 2;
            P q[40005];
            for(int i = 0; i < n; i++){
                q[i] = P(pp[i].first.first * mid + pp[i].first.second, pp[i].second);
            }
            sort(q, q + n);
            BIT<int> bit(n);
            int s = 0;
            for(int i = 0; i < n; i++){
                s += bit.sum(q[i].second);
                bit.add(q[i].second, 1);
            }
            if(f && r <= mid) s += n;
            if(f) n++;
            if(s * 2 < n * (n - 1) / 2) left = mid;
            else right = mid;
        }
        cout << fixed << setprecision(15) << right;
        if(u == 0) cout << " ";
        else cout << endl;
        for(int i = 0; i < n; i++) swap(a[i], b[i]);
    }
}


Measured memory_bytes: 3584
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define do long double
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; }
signed main(){
  int a,b;
  cin>>a>>b;
  int c[a];
  rep(i,a)
    cin>>c[i];
  int dp[110000];
  rep(i,110000)
    dp[i]=1e10;
  dp[0]=0;
  for(int i=0;i<a;i++){
    for(int j=1;j<=b;j++)
      chmin(dp[i+j],dp[i]+abs(c[i]-c[i+j]));
  }
  cout<<dp[a-1]<<endl;
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            var s = Console.ReadLine().ToCharArray();
            var amaris = new int[6, 10]
            {
                { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 },
                { 0, 10, 7, 4, 1, 11, 8, 5, 2, 12 },
                { 0, 9, 5, 1, 10, 6, 2, 11, 7, 3 },
                { 0, 12, 11, 10, 9, 8, 7, 6, 5, 4 },
                { 0, 3, 6, 9, 12, 2, 5, 8, 11, 1 },
                { 0, 4, 8, 12, 3, 7, 11, 2, 6, 10 }
            };

            var amaripatternnum = new long[13];
            amaripatternnum[0] = 1;
            for (int i = s.Length - 1; i >= 0; i--)
            {
                int keta = s.Length - i - 1;
                if (s[i] == '?')
                {
                    var tempamaripatternnum = new long[13];
                    for (int n = 0; n < 10; n++)
                    {
                        int tempamari = amaris[keta % 6, n];
                        for (int j = 0; j < 13; j++)
                        {
                            tempamaripatternnum[(j + tempamari) % 13] += amaripatternnum[j];
                        }
                    }
                    for (int j = 0; j < 13; j++)
                    {
                        amaripatternnum[j] = tempamaripatternnum[j] % 1000000007;
                    }

                }
                else
                {
                    int n = int.Parse(s[i].ToString());
                    int tempamari = amaris[keta % 6, n];
                    var tempamaripatternnum = new long[13];
                    for (int j = 0; j < 13; j++)
                    {
                        tempamaripatternnum[(j + tempamari) % 13] = amaripatternnum[j];
                    }
                    amaripatternnum = tempamaripatternnum;
                }
            }
            Console.WriteLine(amaripatternnum[5]);


#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


Measured memory_bytes: 15584
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static int nums[] , copys[] ;
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner (System.in) ;
		
		int N = in.nextInt() ;
		
		nums = new int [N] ;
		
		copys = new int [N] ;
		
		for(int i=0;i<N;i++) {
			
			nums[i] = in.nextInt() ;
			
			copys[i] = nums[i] ;
		
		}
		
		Arrays.sort(copys);
		
		int cnt = 0 ;
		
		for(int i=0;i<N;i++) {
			if(copys[i]!=nums[i])
				cnt++ ;
		}
		
		if(cnt>2) {
			System.out.println("NO");
		}else {
			System.out.println("YES");
		}
		
		in.close() ;
	}

}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left!=NIL)
     x=x->left;
     return x;
}

Node treeMaximum(Node x){
  while(x->right!=NIL)
    x=x->right;
  return x;
}


Node treeSearch(Node u, int k){
  while(u!=NIL && k!=u->key)
    {
      if(k<u->key)
        u=u->left;
      else u=u->right;
    }
  return u;
}
  
Node treeSuccessor(Node x){
   if(x->right!=NIL)
     return treeMinimum(x->right); 
 Node y=x->parent;
  while(y!=NIL && x==y->right)
    {
      x=y;
      y=y->parent;
    }
      return y;
    }

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL || z->right==NIL)
      y=z;
    else
          y=treeSuccessor(z);
    if(y->left!=NIL)
       x=y->left;
    else
    x=y->right;
  if(x!=NIL)
     x->parent=y->parent;
  if(y->parent==NIL)
      root=x;
   else if(y==(y->parent)->left)
       (y->parent)->left=x;    
  else
     (y->parent)->right=x;
    if(y!=z)
      z->key=y->key;
  }

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL)
    {
      y=x;
      if(z->key < x->key)
         x=x->left;
  else
  x=x->right;   
    }
  z->parent=y;
  if(y==NIL)
     root=z;
   else if(z->key < y->key)
      y->left=z;
   else
      y->right=z;
   
}

void inorder(Node u){
  int i=0;
  if(u!=NIL)
    {
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
    }
}
void preorder(Node u){
  int i=0;
  if(u!=NIL)
    {
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
   
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if( com[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if(t!=NIL)
        printf("yes\n");
      else printf("no\n");
    }else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20448
#include <bits/stdc++.h>
    using namespace std;
    
    typedef double dd;
    typedef long long ll;

    #define all(v) v.begin(),v.end()
    #define rall(v) v.rbegin(),v.rend()
    #define trav(i,a) for(auto i: a)
    #define ff first
    #define ss second
    #define eb emplace_back
    #define tc(t) ll t; cin>>t; while(t--)
    #define prec(n) fixed<<setprecission(n)
    #define mst(arr,value) memset(arr,value,sizeof(arr))
    #define mod %MOD
    #define sz(a) a.size()
    
    const long long inf = (long long)1e18;
    const long long MOD = (long long)1e9+7;
    
    #define f(i,n)     for(ll i=0;   i<n;  i++)
    #define fab(i,a,b) for(ll i=a;   i<b;  i++)
    #define fr(i,n)    for(ll i=n-1; i>=0; i--)
    #define fba(i,b,a) for(ll i=b-1; i>=a; i--)

    ll bpw(ll a, ll b) {
        if(b == 0) return 1;
        if(b % 2 == 1) {
            return bpw(a, b - 1) * a mod;
        } else {
            ll b2 = bpw(a, b / 2) mod;
            return b2 * b2 mod;
        }
    }
    ll ncr(ll n, ll r) { 
        ll p = 1, k = 1, m; 
        if (n - r < r) 
            r = n - r; 
        if (r != 0) { 
            while (r) { 
                p *= n; 
                k *= r; 
                m = __gcd(p, k); 
                p /= m; 
                k /= m; 
                n--; 
                r--; 
            } 
        } 
        else
            p = 1;  
        return p; 
    } 

    int main() {
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);
        cout.tie(NULL);
        ll n, k, ans;
        cin >> n >> k;
        if(n >= k) {
            n %= k;
            ans = min(n, abs(n - k));
        }
        else {
            ans = min(n, abs(n - k));
        }
        cout << ans;
        return 0;
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};



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

	string s,t;
	cin >> s >> t;
	string sub = t.substr(0,t.size()-1);
	if(s==sub){Yes}
	No

	return 0;
}


Measured memory_bytes: 3644
#include <stdio.h>

int main(void) 
{
	unsigned int a, b, c;
	int i;
	int num = 0;

	scanf("%d %d %d", &a, &b, &c);
	for(i = a; i <= b; i++)
	{
		if(c % i == 0)
		{
			num ++;
		}
	}
	
	printf("%d\n", num);
	
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char x;
	bool a=0,b=0;
	int c=0,d=0,i=0;
	while(cin>>x&&x!='\n')
	{
		++i;
		if(x=='C'&&!c)c=i;
		if(x=='F')d=i;
	}
	if(c<d&&c)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
#define max 100
 
int main(){
  int i,j,n,min,minj,ans=0;
 
  int data[max][max];
  int flag[max],d[max];
 
  scanf("%d",&n);
 
  for(i = 0 ; i < n ; i++){
    flag[i] = 0;
    d[i] = 2001;
  }
  d[0] = 0;
 
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      scanf("%d",&data[i][j]);
    }
  }
 
  for(i = 0 ; i <= n ; i++){
    min = 2001;
     
    for(j = 0 ; j < n ; j++){
      if((d[j] < min) && (flag[j] == 0 )){
    min = d[j];
    minj = j;
      }
    }
    flag[minj] = 1;
    for(j = 0 ; j < n ; j++){
      if(data[minj][j] != -1 && data[minj][j] < d[j] && flag[j] ==0){
 
    d[j] = data[minj][j];
      }
    }
  }
  for(i = 0 ; i < n ; i++){
    ans += d[i];
  }
  printf("%d\n",ans);
 
  return 0;
 
}

Measured memory_bytes: 636
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_str(char *str, int size)
{
    char format[100];
    if (size == 0)
        return 0;
    snprintf(format, sizeof(format), "%%%ds", size);
    scanf(format, str);
    return 0;
}

static char stack[200];
static int sidx = 0;
#define STR_MAX 100

void push(char ch) {
    stack[sidx++] = ch;
}

int pop(void) {
    return stack[--sidx];
}

int is_empty(void) { return !sidx; }

int main(void) {
    int num = get_int();
    char str[STR_MAX];
    int pre_cnt = 0;
    get_str(str, num);
    int i;
    for(i = 0; i < num; i++) {
        switch(str[i]) {
            case '(':
                push(str[i]);
                break;
            case ')':
                if(is_empty()) {
                    pre_cnt++;
                } else {
                    pop();
                }
                break;
            default:
                break;
        }
    }
    for(i = 0; i < pre_cnt; i++) {
        putchar('(');
    }
    for(i = 0; i < num; i++) {
        putchar(str[i]);
    }
    for(i = 0; i < sidx; i++) {
        putchar(')');
    }
    putchar('\n');
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
 
int main(){
  while(1){
    int h,h1,w,w1,a,b,min=100000000;
    cin>>h>>w;
    if(h+w==0)break;
    a=h*h+w*w;
 
    for(int i=1;i<=150;i++)
      for(int j=i+1;j<=150;j++){
    b=i*i+j*j;
    if(b>a || (b==a && h<i))
      if(min>b){
        min=b;
        h1=i;
        w1=j;
      }
      }
    cout<<h1<<' '<<w1<<endl;
  }
 
  return 0;
}

Measured memory_bytes: 3076
import java.util.*;

public class Main {


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

        int n = sc.nextInt();

        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;

        for (int i = 0; i < n; i++) {
            String str = sc.next();
            if (str.equals("AC")) {
                ac++;
            }
            if (str.equals("WA")) {
                wa++;
            }
            if (str.equals("TLE")) {
                tle++;
            }
            if (str.equals("RE")) {
                re++;
            }
        }

        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);


        sc.close();

    }

}

Measured memory_bytes: 58516
#define INF 2000000001
#define ll long long int
 
#include<bits/stdc++.h>
using namespace std;
 
void input(ll a[], ll n)
{
    for(ll i = 1; i <= n; i++)
        cin >> a[i];
}
 
void print(ll a[], ll n)
{
    for(ll i = 1; i <= n; i++)
        cout << a[i] << ' ';
    cout << '\n';
}


bool pal(string s, int i, int j)
{
    string s1 = "";
    string s2 = "";
    for(int k = i; k <= j; k++)
        s1 += s[k];
    for(int k = j; k >= i; k--)
        s2 += s[k];
    return s1 == s2;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
  	cin >> s;
    if(s[2] == s[3] && s[4] == s[5])
      	cout << "Yes";
 	else
        cout << "No\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <cmath>
#include <cstdlib>
#include <memory.h>
#include <ctime>
#include <bitset>

using namespace std;

#define ABS(a) ((a>0)?a:-(a))
#define MIN(a,b) ((a<b)?(a):(b))
#define MAX(a,b) ((a<b)?(b):(a))
#define FOR(i,a,n) for (int i=(a);i<(n);++i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define pnt pair <int, int>
#define mp make_pair
#define PI 3.1415926535897
#define MEMS(a,b) memset(a,b,sizeof(a))
#define LL long long
#define U unsigned

int a[100100];
int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

int solve(int n) {
	bool notOne = false;
	int cnt0 = 0;
	int cnt1 = 0;
	FOR(i,0,n) {
		if ((a[i]&1) == 0) {
			cnt0++;
		} else {
			cnt1++;
		}
		if (a[i] > 1) {
			notOne = true;
		}
	}
	if (!notOne) {
		return 0;
	}
	if (cnt0 & 1) {
		return 1;
	}
	if (cnt1 >= 2) {
		return 0;
	}
	FOR(i,0,n) {
		if (a[i] & 1) {
			if (a[i] == 1) {
				return 0;
			}
			a[i]--;
			int g = a[0];
			FOR(j,0,n) {
				g = gcd(g, a[j]);
			}
			FOR(j,0,n) {
				a[j] /= g;
			}
			int val = solve(n);
			return (val ^ 1);
		}
	}
	return -1;
}

int main()
{
#ifdef Fcdkbear
	freopen("in.txt", "r", stdin);
	double beg = clock();
	//freopen("out.txt", "w", stdout);
#endif

	int n;
	scanf("%d",&n);
	LL sum = 0;
	FOR(i,0,n) {
		scanf("%d",&a[i]);
		sum += a[i];
	}
	if (n == 1) {
		if (a[0] > 1) {
			printf("First\n");
		} else {
			printf("Second\n");
		}
		return 0;
	}
	int res = solve(n);
	if (res) {
		printf("First\n");
	} else {
		printf("Second\n");
	}

#ifdef Fcdkbear
	double end = clock();
	fprintf(stderr, "*** Total time = %.3lf ***\n", (end - beg) / CLOCKS_PER_SEC);
#endif
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
const int N = 2e5 + 1;

void findAns()
{
   float r;
   cin>>r;

   float ans = 2 *3.141*r;
   cout<<ans;
}
int main()
{
// #ifndef ONLINE_JUDGE
//     freopen("in.txt", "r", stdin);
//     freopen("o1.txt", "w", stdout);
// #endif

    fastio;

    // ll int t;
    // cin >> t;

    // while (t--)
    findAns();
}

Measured memory_bytes: 3816
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef unsigned int uint;
typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

const int MX = 100005;

int N, M;
int P[MX];

struct UF{
	int t[MX];
	int find(int x){
		return t[x] ? t[x] = find(t[x]) : x;
	}
	int merge(int a, int b){
		a = find(a), b = find(b);
		if(a == b) return false;
		t[a] = b;
		return true;
	}
}uf;

vector<int> Vl[MX];

int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) scanf("%d", P+i);
	for(int i = 1; i <= M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		uf.merge(a, b);
	}
	for(int i = 1; i <= N; i++) Vl[uf.find(i)].push_back(i);
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(uf.find(i) != i) continue;
		set<int> X;
		for(int c : Vl[i]) X.insert(P[c]);
		for(int c : Vl[i]) if(X.find(c) != X.end()) ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 8440
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
 
#define MOD 1000000007

#define MAX_V 300000
#define INF 1000000000

struct edge{int to, cost;};
typedef pair<int,int> P;

vector<edge> G[MAX_V];
int mn[MAX_V];

void ae(int from, int to, int cost){
  edge e = {to,cost};
  G[from].push_back(e);
}

void dijk(int start, int V){
  priority_queue<P, vector<P>, greater<P> > que;
  rep(i,0,V)mn[i] = 1000000000;
  mn[start] = 0;
  que.push(P(0,start));
  while(!que.empty()){
    P p = que.top(); que.pop();
    int v = p.second;
    if(mn[v]<p.first)continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(mn[e.to] > mn[v]+e.cost){
        mn[e.to] = mn[v]+e.cost;
        que.push(P(mn[e.to],e.to));
      }
    }
  }
}

int main(){
  int n,x;
  cin>>n>>x;
  vector<int> d;
  vector<int> c;
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    d.pb(a);
    c.pb(b);
  }
  rep(i,0,200005){
    rep(j,0,d.sz){
      if(i-d[j]>=0){
        ae(i,i-d[j],c[j]);
      }
      if(i+d[j]<200005){
        ae(i,i+d[j],c[j]);
      }
    }
  }
  dijk(0,200005);
  if(mn[x]==INF){
    cout << "-1" << endl;
    return 0;
  }
  cout << mn[x] << endl;
  return 0;
}


Measured memory_bytes: 64060
#include <stdio.h>
#include <string.h>

int gcd(int a, int b)
{
  if(b < a){
    int c = a;
    a = b;
    b = c;
  }
  int r;
  while((r = b%a) > 0){
    b = a;
    a = r;
  }
  return a;
}

int main(void)
{
  int N, X;
  scanf("%d%d", &N, &X);
  int x[N];
  for(int i = 0; i < N; i++){
    int y;
    scanf("%d", &y);
    x[i] = y-X;
    if(x[i] < 0) x[i] = -x[i];
  }
  int g = x[0];
  for(int i = 1; i < N; i++){
    g = gcd(g, x[i]);
  }
  printf("%d\n", g);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <cstring>

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<ll, pair<ll,ll>>;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define MOD 1000000007
//           123456789

ll a, b, c, d;
ll ans;

int main() {
    cin >> a >> b >> c >> d;
    ans = max(a*c, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

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

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
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(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    debug("debug test\n");
    int n,m;cin>>n;
    vint a(n+1), b(n);
    rep(i, n+1){
        cin>>a[i];
    }
    rep(i, n){
        cin>>b[i];
    }
    ll ans = 0;
    rep(i, n){
        if(a[i]>=b[i]){
            ans += b[i];
        }else if(a[i]+a[i+1]>=b[i]){
            ans += b[i];
            a[i+1] -= (b[i]-a[i]);
        }else{
            ans += a[i]+a[i+1];
            a[i+1] = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

// C - Grid Repainting 2
public class Main {
    public static void main(String[] args) {
        Main main = new Main();main.solve(args);
    }

    List<String> list = new ArrayList<>();
    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        for (int i = 0; i < H; i++) {
            list.add(scanner.next());
        }

        boolean ans = true;
        for (int i = 0; i < H; i++) {
            for (int l = 0; l < W; l++) {
                if (list.get(i).charAt(l) == '#') {
                    boolean ok = false;
                    if (i != 0 && list.get(i-1).charAt(l) == '#') {
                        ok = true;
                    }
                    if (l + 1 < W && list.get(i).charAt(l+1) == '#') {
                        ok = true;
                    }
                    if (i + 1 < H  && list.get(i+1).charAt(l) == '#') {
                        ok = true;
                    }
                    if (l != 0 && list.get(i).charAt(l-1) == '#') {
                        ok = true;
                    }
                    if (!ok) {
                        ans = false;
                    }
                }
            }
        }
        if (ans) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    private class MyScanner {
        String[] s;int i;BufferedReader br;String reg = " ";
        MyScanner () { s = new String[0];i = 0;br = new BufferedReader(new InputStreamReader(System.in)); }
        public String next() {
            try {
                if (i < s.length) return s[i++]; String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0); i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21460
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int ans = 0;
		for(int i = 0; i < n; i++) {
			int a = scanner.nextInt();
			while(a % 2 == 0) {
				a /= 2;
				ans++;
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 34220
#include <iostream>

using namespace std;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    for(int i=b;b<=c+1;b++)
    {
        if(b%a==0)
        {
            break;
        }
    }
    if(b<=c)
        cout<<"OK";
    else
        cout<<"NG";
}


Measured memory_bytes: 3624
//解説AC
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
  ll n, m, v, p, x = 1LL, v2, cnt;
  ll l, r, mid;
  cin >> n >> m >> v >> p;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  l = 0LL;
  r = 1000000000LL;
  while (l <= r) {
    mid = (l + r) / 2LL;
    cnt = 0LL;
    for (int i = 0; i < n; i++) {
      if (n - i < p) {
        cnt += m;
      } else {
        cnt += max(0LL, min(m, mid + m - a[i]));
      }
    }
    if (cnt >= m * v) {
      r = mid - 1LL;
    } else {
      l = mid + 1LL;
    }
  }
  cnt = 0LL;
  for (int i = 0; i < n; i++) {
    if (a[i] >= l && a[i] + m >= a[n - p]) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr  5 15:24:21 JST 2020
 **/

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

signed main() {
    Int n, K, C;
    std::cin >> n >> K >> C;
    std::string s;
    std::cin >> s;
    auto dp = make_vec<Int>(2, n, -1);
    REP(t, 2) {
        Int cur = 0;
        REP(i, n) {
            if (s[i] == 'x') continue;
            dp[t][i] = ++cur;
            i += C;
        }
        assert(cur >= K);
        std::reverse(s.begin(), s.end());
    }
    REP(i, n) {
        if (dp[0][i] + dp[1][n - 1 - i] == K + 1) {
            std::cout << i + 1 << "\n";
        }
    }
}


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

class Main {

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String str = br.readLine();
			String strArray[] = str.split(" ", 0);
			int num1 = Integer.parseInt(strArray[0]);
			int num2 = Integer.parseInt(strArray[1]);

			if(num1 == 0 && num2 ==0){
				break;
			}
			else{
				if(num1 <= num2){
					System.out.println(num1 + " " + num2);
				}
				else if(num2 < num1){
					System.out.println(num2 + " " + num1);
				}
			}
		}
	}

}

Measured memory_bytes: 22636
import sys
sys.setrecursionlimit(10 ** 5)

n, u, v = map(int, input().split())
u -= 1
v -= 1
es = [[] for i in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    es[a-1].append(b-1)
    es[b-1].append(a-1)

def dfs(v, dist, p=-1, d=0):
    dist[v] = d
    for nv in es[v]:
        if nv == p:
            continue
        dfs(nv, dist, v, d+1)

def calc_dist(x):
    dist = [-1] * n
    dfs(x, dist)
    return dist

dist_t = calc_dist(u)
dist_a = calc_dist(v)

mx = 0
for i in range(n):
    if dist_t[i] < dist_a[i]:
        mx = max(mx, dist_a[i])

ans = mx - 1
print(ans)

Measured memory_bytes: 117040
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int GetClearedStage(int state) {
  std::bitset<16> bit(state);
  return bit.count();
}

bool isCleared(int state, int stage) {
  std::bitset<16> bit(state);
  return bit[stage - 1];
}

int pow(int base, int ex) {
  if (ex == 0) return 1;
  int result = base;
  for (int i = 1; i < ex; i++) {
    result *= base;
  }
  return result;
}

int Solve(int n) {
  int time[20][20];
  for (int stage = 1; stage <= n; stage++) {
    for (int item = 0; item <= n; item++) {
      cin >> time[stage][item];
    }
  }

  const int MAX_DP = 70000;

  int dp[MAX_DP];
  for (int i = 0; i < MAX_DP; i++) {
    dp[i] = INT32_MAX / 2;
    // cerr << "\033[93m" << dp[i] << "\033[m" << endl;
  }
  for (int i = 1; i <= n; i++) {
    int bitpos = 1 << (i - 1);
    dp[bitpos] = time[i][0];
    // cerr << "\033[93m" << bitpos << " " << dp[bitpos] << "\033[m" << endl;
  }

  for (int stage = 2; stage <= n; stage++) {
    for (int state = 0; state < (1 << (n)); state++) {
      if (GetClearedStage(state) != stage) continue;

      for (int e = 1; e <= n; e++) {
        int mask = 1 << (e - 1);
        if (state & mask) {
          int prev_state = state - pow(2, e - 1);
          // cerr << "\033[93m" << std::bitset<16>(prev_state) << "\033[m" <<
          // endl;
          dp[state] = std::min(dp[state], dp[prev_state] + time[e][0]);
          for (int item = 1; item <= n; item++) {
            if (isCleared(prev_state, item)) {
              dp[state] = std::min(dp[state], dp[prev_state] + time[e][item]);
            }
          }
        }
      }
      // cerr << "\033[93m" << stage << " " << std::bitset<16>(state) << " "
      //      << dp[state] << "\033[m" << endl;
    }
  }

  return dp[(1 << (n)) - 1];
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);

  while (1) {
    int n;
    cin >> n;
    if (n == 0) {
      break;
    }
    cout << Solve(n) << endl;
  }

  return 0;
}



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

int main(){
    int n,x,num=0;
    while (cin >> n >> x, n!=0||x!=0){
        for(int i=1;n>=i;i++){
            for(int j=i+1;n>=j;j++){
                for(int k=j+1;n>=k;k++){
                    if(i+j+k==x) num++;
                }
            }
        }
        cout << num << endl;
        num=0;
    }
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int GCD(long long a, long long b){
    if(a==0) return b;
    return GCD(b%a, a);
}


int main(){
    int N; cin >> N;
    long long ans;
    for(int i=0;i<N;i++){
        long long n; cin >> n;
        if(i == 0) ans=n;
        else{
            ans = GCD(ans, n);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256