akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int f=1,n,sum=0,i;
    cin>>n;
    int d[n];
    for(i=0;i<n;++i){
        cin>>d[i];;
    }
    for(i=0;i<n;++i){
        sum=max(sum-10,d[i]);
        if(sum<10)f=0;
    }
    sum=0;
    for(i=n-1;i>=0;--i){
        sum=max(sum-10,d[i]);
        if(sum<10)f=0;
    }
    if(f)cout<<"yes\n";
    else cout<<"no\n";
}



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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	int n;cin>>n;
	int l=n%10;
	if(l==2||l==4||l==5||l==7||l==9) cout << "hon";
	else if(l==0||l==1||l==6||l==8) cout << "pon";
	else if(l==3) cout << "bon";
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 3628
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {

    //グローバル変数を定義
    List<char[]> list = new ArrayList<>();

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        char[] array = sc.next().toCharArray();
        int[] intArray = new int[array.length];
        for(int i=0; i<array.length; i++){
            intArray[i] = Character.getNumericValue(array[i]);
        }

        // nは個数で、Math.pow(2,n)は、32個の
        // 組み合わせができることを指している。
        for(int bit=0; bit<Math.pow(2, array.length-1); bit++){
//            StringBuilder str = new StringBuilder();
            String str = "";
            for(int i=0; i<array.length; i++){
                //bitにi番目のフラグが立っているかどうか
                if((1&bit>>i) == 1){
                    str += intArray[i] + "+";
//                    str.append(intArray[i] + "+");
                } else if(i==array.length-1){
                    str += intArray[i] + "=7";
                } else {
                    str += intArray[i] + "-";
                }
            }
            int sum = 0;
            char op = '*';
            sum += Character.getNumericValue(str.charAt(0));
            for(int j=1; j<str.length()-1; j++){
                char cBefore = str.charAt(j-1);
                char cNow = str.charAt(j);
                if(cBefore == '+'){
                    sum+=Character.getNumericValue(cNow);
                } else if(cBefore == '-'){
                    sum-= Character.getNumericValue(cNow);
                } else if(cBefore == '='){
                    break;
                }
            }

            if(sum == 7){
                System.out.println(str);
                break;
            }
        }
    }
}


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

using namespace std;

int main(){
	
	int x, b,p,result;
	
	b=2;
	p=2;
	result=1;
	cin >> x ;
	
	
	
	while(pow(b,2) <= x){
		
		while(pow(b,p) <= x){
			
			if(result <= pow(b,p)) {
				result = pow(b,p);
			}
			p++;
		}
		p=2;
		b++;
	}
	cout << result <<endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main{       
   public static void main(String[] args){

     Scanner sc = new Scanner(System.in);  
      
     int chair[] = new int[100002];
     
     int N = sc.nextInt();
     
     for(int i = 0; i < N;i++){
         int l = sc.nextInt();
         int r = sc.nextInt();         
         chair[l]++;
         chair[r+1]--;         
     }
      
     for(int i = 1;i <= 100000;i++){
         chair[i+1] += chair[i]; 
     }
     
     int count = 0;
     for(int i = 1;i<= 100000;i++){
         if(chair[i] > 0){
             count++;
         }
     }
     
     System.out.println(count);
      
   }
}

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

int main() {
    int A, B, K;
    cin >> A >> B >> K;

    int n = min(A, B);
    vector<int> ans;
    for (int i = 1; i <= n; ++i) {
        if (A % i == 0 && B % i == 0) {
            ans.push_back(i);
        }
    }

    sort(ans.begin(), ans.end(), greater<int>());
    cout << ans[K - 1] << endl;
    return 0;
}

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

int main() {
  int N,L;
  cin >> N >> L ;
  vector<string> S(N);
  rep(i,N){
    cin >> S[i];
  }
  sort(S.begin(), S.end());
  rep(i,N){
    cout << S[i];
  }
  cout << endl;
  return 0;
}

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

using namespace std;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

void sub()
{
    const auto N(cin2var<size_t>());
    int64_t ans = N / 2;
    if (N % 2 != 0) {
        ++ans;
    }
    cout << ans / static_cast<double>(N) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    sub();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  char s[55][55];
  bool ok = true;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin >> s[i][j];
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(s[i][j]=='.')continue;
      if(s[i][j]=='#'&&s[i-1][j]!='#'&&s[i][j+1]!='#'&&s[i][j-1]!='#'&&s[i+1][j]!='#')
      ok=false;
    }
  }
  if(ok)cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N,M = map(int,input().split())

lis = [0] * N
for i in range(M):

    a,b = map(int,input().split())

    lis[a-1] += 1
    lis[b-1] += 1

flag = True
for i in range(N):

    if lis[i] % 2 == 1:
        flag = False
        break

if flag:
    print ("YES")
else:
    print ("NO")


Measured memory_bytes: 44504
#include <bits/stdc++.h>
#define maxn 200005
#define INF 0x3f3f3f3f
#define mod 1000000007
#define rep(i, a, n) for (int i=(a); i<(n); i++)
#define per(i, a, n) for (int i=(a); i>(n); i--)
typedef long long ll;
using namespace std;

void slove()
{
	int w, a;
	cin >> w >> a;
	if (w <= a) cout << "unsafe";
	else cout << "safe";
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef DEBUG
	freopen("C:\\Users\\Fish_Brother\\Desktop\\in", "r", stdin);
	//freopen("C:\\Users\\Fish_Brother\\Desktop\\out", "w", stdout);
#endif
	slove();

	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<int>> dp(H + 1, vector<int> (W, 0)); 

    dp[0][0] = 1;
	rep(i, H) {
		rep(j, W) {
			for (int k = 0; k < 1 << (W - 1); k++) {
				// 2 つの横線がつながっていないか調べる
				bool ok = true;
				rep(l, W-2) {
					if (((k >> l) & 1) && ((k >> (l + 1)) & 1)) {
						ok = false;
					}
				}

				if (ok) {
					if (j >= 1 && ((k >> (j - 1)) & 1)) {
						// 左方向に横線をたどるケース
						dp[i+1][j-1] += dp[i][j];
						dp[i+1][j-1] %= mod;
					}
					else if (j <= W - 2 && ((k >> j) & 1)) {
						// 右方向に横線をたどるケース
						dp[i+1][j+1] += dp[i][j];
						dp[i+1][j+1] %= mod;
					}
					else {
						// 横線をたどらないケース
						dp[i+1][j] += dp[i][j];
						dp[i+1][j] %= mod;
					}
				}
			}
		}
	}

	cout << dp[H][K-1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                   // below comment for pbds
#include<ext/pb_ds/assoc_container.hpp>   // to use it make ordered_set
#include<ext/pb_ds/tree_policy.hpp>       // all set fnct + = 1. order_of_key(x); // number of 
#define ll long long                      //element strictly smaller than it;
#define ld long double                    // 2. find_by_order(x),pointer el at x pos after sort  use as s.f();
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;                     
using namespace __gnu_pbds;
// assert(a[i]<n ) // if we want to check for special cond , used for debug
// make less_equal in order to make a multiset pbds
const ll Mod = (int)1e9;
ll CaseN=1;
ll fast_power(ll a,ll b,ll mod){
	ll ans=1;
	while(b>0){
	if(b&1){
	ans=(a*ans)%mod;
	}
	b=b>>1;
	a=(a*a)%mod;
	}
	return ans;
	}


ll nCr(ll n ,ll r)
{
ll p= n;
r = min(r,n-r);
ll a =1;
ll b=1;	
while(r)
{
	a = a*p;
	b = b*r;
	
	ll g = __gcd(a,b);
	
	a = a/g;
	b = b/g;
	
	p--;
	r--;	
}	
return a;
	
}

void solve()
{
	
	ll w,h,n;
	cin>>w>>h>>n;
	ll x[n+4],y[n+4],a[n+4];
	ll ans =0;
	ll a1=0,a2=0,b1=w, b2 =h;
	for(ll i=0;i<n;i++)
	{
	cin>>x[i]>>y[i]>>a[i];
		if(a[i]==1)
		{
			a1=max(x[i],a1);
		}
		else if(a[i]==2)
		{
			b1 = min(x[i],b1);
		}
		else if(a[i]==3)
		{
			a2 = max(y[i],a2);
		}
		else
		{
			b2 = min(y[i],b2);
		}
	}
    if(b1>a1 && b2>a2)
    {
	ans = (b1-a1)*(b2-a2) ;
		
	}
    
	
   cout<<ans<<endl;
	 //if(ans)
  //{
  //cout<<"Yes"<<endl; 
  //}
  //else
   //{
  //cout<<"No"<<endl;
  //}
 
	
    //cout<<"Case #"<<CaseN<<": ";
   CaseN++;
	// print your ans below;
return ;
}


signed main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();	
	}
}


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

#define ll long long

int main(void){
    ll N,T;
    ll ans = pow(10,9);
    cin >> N>>T;
    for(ll i=0;i<N;i++){
        ll c,t;
        cin >>c>>t;
        if(t <= T and c < ans){
            ans = c;
        }
    }if(ans == pow(10,9)){
        cout << "TLE"<<endl;
    }else{
        cout << ans << endl;
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <unistd.h>
#include <bits/stdc++.h>

#define pii pair<int,int>
#define REP(i, n) for (long long i = 0; i < (n); i++) 
using namespace std;


typedef long long ll;
static const ll INF = 1000000000000000000LL;
static const ll MOD = 1000000007;


int main()
{
    int  H,A;
    cin >> H >> A;



    int res;

    res = (H-1)/ A + 1;
    cout << res << endl;

    return 0;
}

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

ans = 1

has_zero = False
for a in A:
    if a == 0:
        has_zero = True

# print("here?")

for a in A:
    # print("here?2")
    # print(a)
    ans *= a
    if ans > 1000000000000000000:
        ans = -1
        break

if has_zero is True:
    print('0')
else:
    print(ans)


Measured memory_bytes: 21636
#include <stdio.h>

int a,b;
int d,r;
double f;
main(){
		scanf("%d%d%d",&a,&b);
		d=a/b;
		r=a%b;
		f=(double)a/(double)b;
		
		printf("%d %d %f\n",d,r,f);
	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  
  ll A, B, C;
  cin >> A >> B >> C;

  if(A+B < C) print(B + (A+B+1));
  else if(A+B >= C) print(B + C);

 return 0;
}


Measured memory_bytes: 256
def type(a, b, c) # a, b, c is sorted
    if a + b <= c then
        return -1
    elsif a * a + b * b == c * c then
        return 0
    elsif a * a + b * b > c * c then
        return 1
    else
        return 2
    end
end

t0 = 0
t1 = 0
t2 = 0

while true do
    
    a, b, c = gets.split.map(&:to_i)
    
    if a > b then
        t = a
        a = b
        b = t
    end
    
    if a > c then
        t = a
        a = c
        c = t
    end
    
    if b > c then
        t = b
        b = c
        c = t
    end
    
    ttype = type(a, b, c)
    
    if ttype == -1 then
        break
    elsif ttype == 0 then
        t0 += 1
    elsif ttype== 1 then
        t1 += 1
    else
        t2 += 1
    end
end

puts "#{t0 + t1 + t2} #{t0} #{t1} #{t2}"

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

void frame1(const int width)
{
	for(int i = 0; i < width; i++){
		cout << "#";
	}
	cout << endl;
}

void frame2(const int width)
{
	for(int i = 0; i < width; i++){
		if(i == 0 || i == width - 1)
		{
			cout << "#";
		}
		else
		{
			cout << "."; 
		}
	}
	cout << endl;
}


int main()
{
	int h = 0, w = 0;
	while(true)
	{
		cin >> h >> w;
		if(h == 0 && w == 0){ break; }
		for(int y = 0; y < h; y++)
		{
			if(y == 0 || y == h - 1){ frame1(w); }
			else                    { frame2(w); } 
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3016
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    
 
  int main(){
     string s;
     cin>>s;
     rep(i,s.size()){
         if(s[i]=='?')s[i]='D';
     }
     cout<<s<<endl;
          }
     
  
      
      
    

  
          
  

Measured memory_bytes: 3752
#include <iostream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <limits>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <unordered_map>
#include <random>
#include <cmath>
#include <complex>
// #include "utiltime.hpp"

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef complex<double> cdouble;

const int INFL = (int)1e9;
const ll INFLL = (ll)1e18;
const double INFD = numeric_limits<double>::infinity();
const double PI = 3.14159265358979323846;
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loopll(i, n) for(ll i = 0; i < (ll)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopll1(i, n) for(ll i = 1; i <= (ll)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Looprll(i, n) for(ll i = (ll)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define Looprll1(i, n) for(ll i = (ll)n; i >= 1; i--)
#define Loopitr(itr, container) for(auto itr = container.begin(); itr != container.end(); itr++)
#define printv(vector) Loop(extra_i, vector.size()) { cout << vector[extra_i] << " "; } cout << endl;
#define printmx(matrix) Loop(extra_i, matrix.size()) { Loop(extra_j, matrix[extra_i].size()) { cout << matrix[extra_i][extra_j] << " "; } cout << endl; }
#define quickio() ios::sync_with_stdio(false); cin.tie(0);
#define readfile(filename) ifstream in(filename); cin.rdbuf(in.rdbuf());
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
bool nearlyeq(double x, double y) { return abs(x - y) < 1e-9; }
ll rndf(double x) { return (ll)(x + (x >= 0 ? 0.5 : -0.5)); }
ll floorsqrt(double x) { ll m = (ll)sqrt(x); return m + (m * m <= (ll)(x) ? 0 : -1); }
ll ceilsqrt(double x) { ll m = (ll)sqrt(x); return m + ((ll)x <= m * m ? 0 : 1); }
ll rnddiv(ll a, ll b) { return (a / b + (a % b * 2 >= b ? 1 : 0)); }
ll ceildiv(ll a, ll b) { return (a / b + (a % b == 0 ? 0 : 1)); }
ll gcd(ll m, ll n) { if (n == 0) return m; else return gcd(n, m % n); }

/*******************************************************/

int main() {
	int n; cin >> n;
	vll a(n); Loop(i, n) cin >> a[i];
	sort(a.begin(), a.end());
	if (n % 2) {
		int half = n / 2;
		ll sum0 = 0, sum1 = 0;
		Loop(i, half) {
			sum0 -= a[i] * 2;
		}
		Loop(i, half - 1) {
			sum0 += a[n - 1 - i] * 2;
		}
		sum0 += a[n - 1 - (half - 1)];
		sum0 += a[n - 1 - half];
		Loop(i, half - 1) {
			sum1 -= a[i] * 2;
		}
		Loop(i, half) {
			sum1 += a[n - 1 - i] * 2;
		}
		sum1 -= a[half - 1];
		sum1 -= a[half];
		cout << max(sum0, sum1) << endl;
	}
	else {
		int half = n / 2;
		ll sum = 0;
		Loop(i, half - 1) {
			sum -= a[i] * 2;
		}
		Loop(i, half - 1) {
			sum += a[n - 1 - i] * 2;
		}
		sum -= a[half - 1];
		sum += a[half];
		cout << sum << endl;
	}
}

Measured memory_bytes: 1024
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main()
	{
		long N = GetLong();
		long M = GetLong();
		Dictionary<long, long> num = new Dictionary<long, long>();
		for(int i = 0; i < N; i++)
		{
			long A = GetLong();
			long current = 0;
			num.TryGetValue(A, out current);
			num[A] = current + 1;
		}
		for(int i = 0; i < M; i++)
		{
			long B = GetLong();
			long C = GetLong();
			long current = 0;
			num.TryGetValue(C, out current);
			num[C] = current + B;
		}

		long ans = 0;
		long rest = N;
		List<long> keys = num.Keys.ToList();
		keys.Sort();
		keys.Reverse();
		for(int i = 0; i < keys.Count; i++)
		{
			long key = keys[i];
			ans += key * Math.Min(rest, num[key]);
			rest -= Math.Min(rest, num[key]);
			if(rest == 0)
				break;
		}

		Console.WriteLine(ans);
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}





Measured memory_bytes: 32712
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
using namespace std;
template <class T> inline void chmax(T & a, T const & b) { a = max(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

int main() {
    // input
    int n, k; scanf("%d%d", &n, &k);
    vector<int> x(n), y(n); vector<char> c(n);
    REP (i, n) scanf("%d%d %c", &x[i], &y[i], &c[i]);
    // solve
    auto acc = vectors(2 * k, 2 * k + 1, array<int, 2>({}));
    REP (i, n) {
        acc[y[i] % (2 * k)][x[i] % (2 * k) + 1][c[i] == 'B'] += 1;
    }
    REP (y, 2 * k) {
        REP (x, 2 * k) {
            REP (p, 2) {
                acc[y][x + 1][p] += acc[y][x][p];
            }
        }
    }
    int result = 0;
    REP (x, 2 * k) {
        vector<array<int, 2> > accx(2 * k + 1);
        REP (y, 2 * k) {
            int b, w;
            if (x < k) {
                b =                     acc[y][x + k][1] - acc[y][x][1];
                w = acc[y][2 * k][0] - (acc[y][x + k][0] - acc[y][x][0]);
            } else {
                b = acc[y][2 * k][1] - (acc[y][x][1] - acc[y][x - k][1]);
                w =                     acc[y][x][0] - acc[y][x - k][0];
            }
            int total = acc[y][2 * k][0] + acc[y][2 * k][1];
            accx[y + 1][1] = accx[y][1] + (b + w);
            accx[y + 1][0] = accx[y][0] + (total - (b + w));
        }
        REP (y, 2 * k) {
            int b, w;
            if (y < k) {
                b =                   accx[y + k][1] - accx[y][1];
                w = accx[2 * k][0] - (accx[y + k][0] - accx[y][0]);
            } else {
                b = accx[2 * k][1] - (accx[y][1] - accx[y - k][1]);
                w =                   accx[y][0] - accx[y - k][0];
            }
            chmax(result, b + w);
        }
    }
    // output
    printf("%d\n", result);
    return 0;
}


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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> tree(n + 1, vector<int>());
    int a, b;
    REP(i, n - 1) {
        cin >> a >> b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    vector<int> c(n);
    REP(i, n) {
        cin >> c[i];
    }

    sort(ALL(c), greater<int>());

    vector<int> ans(n + 1);
    deque<pair<int, int>> q;
    q.emplace_back(1, c[0]);
    ans[1] = c[0];
    int count = 1;
    int total = 0;
    vector<bool> used(n + 1, false);
    used[1] = true;
    while (!q.empty()) {
        auto p = q.front(); q.pop_front();
        auto v = tree[p.first];
        for (const int x : v) {
            if (used[x]) {
                continue;
            }
            ans[x] = c[count];
            total += min(c[count], p.second);
            q.emplace_back(x, c[count]);
            count++;
            used[x] = true;
        }
    }
    cout << total << endl;
    int z = 0;
    for (int i = 1; i <= n; i++) {
        z++;
        cout << ans[i];
        if (i == n) {
            cout << endl;
        } else {
            cout << " ";
        }
    }
}


Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;

    int ans = min(a * n, b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3576
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
rr = range


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols
    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])
    return ret


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_map_as_int(H):
    '''
    #→1,.→0として読み込む
    '''
    ret = []
    for _ in range(H):
        ret.append([1 if s == '#' else 0 for s in read()[:-1]])
        # 内包表記はpypyでは若干遅いことに注意
        # #numpy使うだろうからこれを残しておくけど
    return ret


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right
from fractions import gcd


def lcm(a, b):
    # 最小公倍数
    g = gcd(a, b)
    return a * b // g


X, Y, Z = read_ints()
print(Z, X, Y)


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
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;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    if(s[0]=='7'||s[1]=='7'||s[2]=='7')puts("Yes");
    else puts("No");
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef long long Int;
const int INF = 6000;


bool match(char a, char b) {
    return (a == '?' || b == '?' || a == b);
}


int main() {
    string a, b, c;
    cin >> a >> b >> c;

    int x, y, z;
    x = a.size();
    y = b.size();
    z = c.size();

    /*vector<vector<bool>> ab(x, vector<bool>(y, false)), bc(y, vector<bool>(z, false)), ac(x, vector<bool>(z, false));
    rep(i,x) {
        rep(j,y) {
            if (match(a[i], b[j])) ab[i][j] = true;
        }
    }
    rep(j,y) {
        rep(k,z) {
            if (match(b[j], c[k])) bc[j][k] = true;
        }
    }
    rep(i,x) {
        rep(k,z) {
            if (match(a[i], c[k])) ac[i][k] = true;
        }
    }*/

    vector<bool> ab(x+y-1, true), bc(y+z-1, true), ac(x+z-1, true);
    rep(i,x) {
        rep(j,y) {
            if (!match(a[i], b[j])) ab[j-i+x-1] = false;
        }
    }
    rep(j,y) {
        rep(k,z) {
            if (!match(b[j], c[k])) bc[k-j+y-1] = false;
        }
    }
    rep(i,x) {
        rep(k,z) {
            if (!match(a[i], c[k])) ac[k-i+x-1] = false;
        }
    }

    int ans = INF;

    rep(i,8000) {
        rep(j, 8000) {
            bool flag = true;
            if (i >= 4001 - y && i <= 3999 + x) {
                if (!ab[3999 + x - i]) flag = false;
            }
            if (j >= 4001 - z && j <= 3999 + x) {
                if (!ac[3999 + x - j]) flag = false;
            }
            if (j - i < y && i - j < z) {
                if (!bc[y - j + i - 1]) flag = false;
            }
            if (flag) {
                int left, right;
                left = min(4000, min(i,j));
                right = max(4000 + x, max(i + y, j + z));
                ans = min(ans, right - left);
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#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 all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S;
	cin>>S;
	int N = S.size() - 1;
	//bit全探索　bitは{0,1, ..., n-1}の2^n通りの部分集合全体の集合を動く
	//足すか足さないかを決めるフラグをbitで表現
	ll ans = 0;//部分集合全体の和
	if(N == 0){
		ans = S[0] - '0';
		cout<<ans<<endl;
		return 0;
	}
	for (int bit = 0; bit < (1<<N); ++bit){
		ll sum = 0;
		for (int i = 0; i < N; ++i){
			sum += S[i]-'0';
			if(bit & (1<<i)){//i番目の仕切りに+を入れるようになっていたら
				ans += sum;
				sum = 0;
			}
			else{
				sum *=10;
			}
			if(i == N-1){
				sum += S[N] - '0';
			}
		}
		ans += sum;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int a[110];
int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	printf("%lld",(ll)(k*pow(k-1,n-1)));
}

Measured memory_bytes: 128
sub max{$_[$_[1]>$_[0]]}
sub min{$_[$_[1]<$_[0]]}
$X=<>+0;
$K=<>;
@r=(0,0,glob<>);
$Q=<>;

$l=0;
$h=$X;

for(<>){
	($t,$a)=split;
	for(;$k<$#r&&$t>=$r[$k+1];++$k){
		$m+=$%=(-1)**$|*($r[$k+1]-$r[$k]);
		$l=min$X,max$l+$%,0;
		$h=min$X,max$h+$%,0;
		--$|
	}
	$%=(-1)**$|*($t-$r[$k])+min$h,max$l,$a+$m;
	print min($X,max$%,0),$/
}


Measured memory_bytes: 31660
#ifndef _WIN32
#include<iostream>
#endif // !_WIN32

#include<string>
#include<iomanip>
#include<vector>
#include<string>
using namespace std;

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()



int main() {
	int n;
	while (cin >> n, n) {
		int prv = 0;
		int l = 0;
		int r = 0;
		int res=0;
		REP(i, n) {
			string s;
			cin >> s;
			if (s == "lu")l = 1;
			if (s == "ru")r = 1;
			if (s == "ld")l = 0;
			if (s == "rd")r = 0;
			if (l == r&&r != prv) {
				prv = r;
				res++;
			}
		}
		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define int long long
using namespace std;

int dp[401][401];//debut et fin inclus
int sum[401], a[401], n;

int t(int s, int e)
{
    if (s==e) return 0;
    if (dp[s][e] == -1)
    {
        dp[s][e] = t(s, s) + t(s+1, e) + sum[e+1] - sum[s];
        for (int c=s;c<e;++c)
            chmin(dp[s][e], t(s, c) + t(c+1, e) + sum[e+1] - sum[s]);
      //  cout << s << " " << e << " " << dp[s][e] << endl;
    }
    return dp[s][e];
}

signed main()
{
   cin >> n;
   for (int i=0;i<n;++i)cin >> a[i];
   for (int i=0;i<=n;++i)
       for (int j=0;j<=n;++j)
           dp[i][j] = -1;
    for (int i=0;i<n;++i)dp[i][i] = a[i];
   for(int i=1;i<=n;++i)sum[i] = sum[i-1] + a[i-1];
   cout << t(0, n-1) << endl;
   return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

class Main{
	public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        int n = sc.nextInt();
        sc.close();
        if(n == 100){
            n++;
        }
        System.out.println((int)Math.pow(100,d)*n);
    }
}

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

int max(int a, int b, int c){
  return max(max(a, b), c);
}

int main(){
  int a, b, c;  cin >> a >> b >> c;
  cout << ((a + b + c == 2 * max(a, b, c))?"Yes":"No") << endl;
}

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

typedef long long ll;
const int INF = 1e9;
using namespace std;
#define int long long

signed main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 0; i < n; ++i) cin >> b[i];
    for (int i = 0; i < n; ++i) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vector<int> bc(n);

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        bc[i] = n - (upper_bound(c.begin(), c.end(), b[i]) - c.begin());
    }
    for (int j = n - 2; j >= 0; --j) {
        bc[j] += bc[j + 1];
    }

    for (int i = 0; i < n; ++i) {
        int x = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
        ans += bc[x];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
# -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
S=sys.stdin.readline().strip()
S=S[::-1]

dp=[ [ 0 for j in range(N+1) ] for i in range(N+1) ]

for i in range(1,N+1):  #iは1-indexed
    for j in range(1,i+1):
        if S[i-1]==S[j-1]:  #Sは0-indexedなので-1
            dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1)
        else:
            dp[i][j]=0

ans=0
for i in range(1,N+1):  #iは1-indexed
    for j in range(1,i):
        ans=max(ans,min(dp[i][j],i-j))  #2つの文字列は重ならないので最長でもi-j
print ans


Measured memory_bytes: 229532
x = list(map(int,input().split()))
a = [list(map(int,input().split())) for l in range(x[0])]

a.sort()
buy = 0
money = 0
for i in a:
  if (buy + i[1]) <= x[1]:
    money += i[0] * i[1]
    buy += i[1]
  else:
    money += i[0] * (x[1] - buy)
    break
    
print(money)

Measured memory_bytes: 27756
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll n, k, ans;
	ll sum = 0;
	
	cin >> n >> k;

	vector<pair<ll, ll>> v(n, make_pair((ll)0, (ll)0));
	set<ll> s;
	stack<ll> st;

	REP(i, n) {
		cin >> v[i].second >> v[i].first;
	}

	sort(v.begin(), v.end(), greater<pair<ll,ll>>());

	REP(i, k) {
		sum += v[i].first;
		if (s.count(v[i].second)) {
			st.push(v[i].first);
		}
		s.insert(v[i].second);
	}

	ans += sum + s.size() * s.size();

	FOR(i, k, n) {
		if (st.empty()) {
			break;
		}
		if (s.count(v[i].second)) {
			continue;
		}
		sum -= st.top();
		sum += v[i].first;
		s.insert(v[i].second);
		ans = max(ans, sum + (ll)s.size() * (ll)s.size());
		st.pop();
	}

	cout << ans << endl;
}


Measured memory_bytes: 4992
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n, r;
    cin >> n >> r;
    if (n >= 10) cout << r;
    else cout << r + 100 * (10 - n);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll N,M,l,tmp;
	cin >> N;
	cin >> M;
	priority_queue<ll> q;
	for (ll i = 0; i < N;i++){
		cin >> tmp;
		q.push(tmp);
	}
	ll i = M;
	while(i > 0){
		l = q.top();//最大値をコピー
		q.pop();//最大値を取り出す
		l /= 2;
		i --;//割引券を利用
		q.push(l);//割引券使用後の値をぶちこむ
	}
	ll ans = 0;
	for(i = 0;i < N;i++){
		ans += q.top();
		q.pop();
	}
	cout <<ans << endl;
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int a,b;
  cin>>a>>b;
  cout << (a + b) % 24 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
//typedef pair<int,int> P;
//priority_queue<int> pque;
//priority_queue<int, vector<int>, greater<int>> pque;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 998244353;



int main(void){
    int A,B,C;
    cin >> A >> B >> C;
    if(A < B){
        if(A < C && C < B){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }else{
        if(B < C && C < A){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
  public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
  public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};


int main(){
  ll n,m,v,p; cin >> n >> m >> v >> p;
  vl a(n);
  rep(i, n) cin >> a[i];
  sort(all(a));
  reverse(all(a));
  vl s(n+1); rep(i,n) s[i+1] = s[i] + a[i];

  rrep(i,n) {
    if(i <= p-1){
      cout << i+1 << endl;
      return 0;
    }
    if(a[i] + m < a[p-1]) continue;
    
    ll sum = (p-1+n-i)*m + (i-p+1)*(a[i]+m) - (s[i] - s[p-1]);
    if(sum >= m*v){
      cout << i+1 << endl;
      return 0;
    }
  }

}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

int n, a, b, c, d;
string s;
bool ans;

int main(){
	scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
	a--;b--;c--;d--;
	cin >> s;

	ans = true;
	// First, general check
	for(int i = a; i < c; ++i){
		if(s[i] == '#' && s[i+1] == '#')
			ans = false;
	}
	for(int i = b; i < d; ++i){
		if(s[i] == '#' && s[i+1] == '#')
			ans = false;
	}

	// Second
	if(c > d){
		bool possible = false;
		for(int i = b; i <= d; ++i){
			if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.')
				possible = true;
		}
		//printf("Special %d\n", possible);
		ans = ans&possible;
	}
	if(ans)
		printf("Yes\n");
	else
		printf("No\n");
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int main()
{
    int N,K;
    cin >> N >> K;
    vector<int> H(N);

    for(int i = 0; i < N; i++) cin >> H[i];
    if(N <= K)
    {
        cout << 0 << endl;
        return(0);
    }
    sort(H.begin(),H.end(),greater<int>());
    for(int i = 0; i < K; i++)
    {
        H[i] = 0;
    }
    ll ans = 0;
    for(int i = 0; i < N; i++)
    {
        ans += H[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
<?php
$W=strtolower(trim(fgets(STDIN)));
$C=0;
while(1){
  if('END_OF_TEXT'==$T=trim(fgets(STDIN))) break;
  foreach(explode(' ',strtolower($T)) as $t) if($t==$W) ++$C;
}
echo $C;
?>

Measured memory_bytes: 15228
n, k = map(int, input().split())
h = []
for i in range(n):
    h.append(int(input()))

h.sort()

ret = 10 ** 100

for i in range(n-k+1):
    tmp = h[i+k-1] - h[i]
    ret = min(ret, tmp)

print(ret)


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

string s;

int main() {
	cin>>s;
	int n=s.length();
	int sama=0;
	for (int i=0; i<(n-1)/2; i++) {
		if (s[i]==s[(n-3)/2-i]) sama++;
	}
	bool palin=0;
	if (sama==(n-1)/2) palin=1;
	string s1, s2;
	s1.insert(0, s, 0, (n-1)/2);
	s2.insert(0, s, (n+1)/2, (n-1)/2);
	if (s1==s2&&palin) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  long long n,d;
  long long xx,yy;
  cin >> n >> d;
  int ans = 0;
  for(int i=0;i < n;i ++){
    long long x,y;
    cin >> x >> y;
    //cout << sqrt(x*x + y*y) << endl;
    xx = x*x;
    yy = y*y;
    if(sqrt(xx+yy) <= d){
      ans++;
    }
  }
  cout << ans << endl;
}
      

Measured memory_bytes: 3644
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    string s;
    cin>>s;
    int n=s.size();
    bool ok=0;
    P ans=P(-1,-1);
    rep(i,n){
        if(i<n-1){
            if(s[i]==s[i+1]){
                ok=1;
                ans=P(i+1,i+2);
                break;
            }
        }
        if(i<n-2){
            if(s[i]==s[i+2]){
                ok=1;
                ans=P(i+1,i+3);
                break;
            }
        }
    }
    cout<<ans.ft<<' '<<ans.sc<<endl;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	vector<int> v(3);
	cin >> v[0] >> v[1] >> v[2];

	sort(BE(v));

	cout << v[2]*10+v[1]+v[0] << endl;



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x = 1;
  int n,k;
  cin >> n >> k;
  
  for(int i=0;i < n;i++){
    if(2*x < x+k){
      x *= 2;
    }else{
      x += k;
    }
  }
  cout << x << endl;
  
}

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

using namespace std;


int main()
{
    long long n ;   cin>>n ;
    long long ans=n;
    int sq=sqrt(n);
    for(int i=1 ; i<=sq ;i++)
    {
        if(n%i==0)
            ans = min(ans , i+n/i-2);
    }
    cout<<ans ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const long long INF = 1LL << 58;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
template <class string>
inline bool chmax(string &a, string b)
{
    if (a == "-")
    {
        a = b;
        return true;
    }
    if (a.size() < b.size())
    {
        a = b;
        return true;
    }
    else if (a.size() == b.size() and a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

int main()
{
    int N, M;
    cin >> N >> M;
    int T[10];
    T[1] = 2;
    T[2] = 5;
    T[3] = 5;
    T[4] = 4;
    T[5] = 5;
    T[6] = 6;
    T[7] = 3;
    T[8] = 7;
    T[9] = 6;
    string A[9];
    REP(i, M)
    cin >> A[i];

    string dp[10001];
    REP(i, 10001)
    {
        dp[i] = "-";
    }
    dp[0] = "";
    REP(i, N + 1)
    {
        REP(j, M)
        {
            if (i - T[stoi(A[j])] >= 0)
            {
                if (dp[i - T[stoi(A[j])]] != "-")
                    chmax(dp[i], dp[i - T[stoi(A[j])]] + A[j]);
            }
        }
    }
    cout << dp[N] << endl;

    // system("pause");
}

Measured memory_bytes: 41472