akhauriyash/Code-Regression huggingface dataset:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,A,B = MI()
C = A-B
h = [I() for i in range(N)]

def f(n):  # n回の爆発で討伐完了できるか
    a = 0
    for i in range(N):
        if h[i]-B*n > 0:
            a += (h[i]-B*n+C-1)//C
    if a <= n:
        return True
    else:
        return False

left = 0
right = 10**9
while left + 1 < right:
    mid = (left + right)//2
    if f(mid):
        right = mid
    else:
        left = mid

print(right)


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

#define pb push_back
#define ff first
#define ss second

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

int n, a, b;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n >> a >> b;
	if ((a & 1) == (b & 1))
		cout << "Alice" << endl;
	else
		cout << "Borys" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N=1e6+5;
const int Mod=1e9+7;
int n;
int ans; 
int F[MAX_N];
int inv[MAX_N];
int inv_F[MAX_N];
signed main()
{
	cin>>n;
	F[0]=inv_F[0]=1;
	for(int i=1;i<=n;i++)F[i]=F[i-1]*i%Mod;
	inv[1]=inv_F[1]=1;
    for(int i=2;i<=n;i++)inv[i]=(Mod-Mod/i)*inv[Mod%i]%Mod;
    for(int i=2;i<=n;i++)inv_F[i]=inv_F[i-1]*inv[i]%Mod;
	/*	dp[k]=(k-1)!/((n-k-1)!*(2k-n)!)*(n-k-1)!*(k)!
		=(k-1)!*k!/(2k-n)!*/
	for(int i=(n+1)/2;i<n;i++)ans=(ans+(F[i-1]*F[i]%Mod*inv_F[2*i-n]%Mod))%Mod;	
	cout<<(Mod+F[n]-ans%Mod)%Mod<<endl;
	return 0;
}

Measured memory_bytes: 23680
from math import atan2, degrees


def solve(string):
    a, b, x = map(int, string.split())
    if x >= a**2 * b / 2:
        c, d = 2 * (a**2 * b - x), a**3
    else:
        c, d = a * b**2, 2 * x
    return str(degrees(atan2(c, d)))


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include<iomanip>
#include<limits>
using namespace std;
int main(void){
    long long int A,B,K;
    cin>>A>>B>>K;
    if(A>=K){
        cout<<A-K<<" "<<B<<endl;
    }
    else if(K-A<=B){
        cout<<0<<" "<<B-(K-A)<<endl;
    }
    else {
        cout<<0<<" "<<0<<endl;
    }
}


Measured memory_bytes: 256
void main() {
	(N => readAs!(ulong[]).sort!"a > b"().array[0..2*N+1].enumerate.map!(i => i.index % 2 == 1 ? i.value : 0).sum.writeln)(ri);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 17816
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

vector<lli> divisorList(lli num){
	vector<lli> v;

	for(lli i=1;i*i<=num;i++){
		if(num%i==0){
			v.push_back(i);
			v.push_back(num/i);
		}
	}
	sort(v.begin(),v.end());
	return v;
}

signed main(){

	lli n,m;
	cin>>n>>m;

	lli ans=0;
	vector<lli> v = divisorList(m);
	for(lli i=0;i<v.size();i++){
		if(m/v[i] < n)break;
		if(m%v[i]==0){
			ans = max(ans,v[i]);
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int len,tot;
char s[101];
int main()
{
	ios::sync_with_stdio(false);
	cin>>(s+1),len=strlen(s+1);
	for(res i=1;i<=len>>1;++i) if(s[i]!=s[len-i+1]) ++tot;
	cout<<tot<<'\n';
	cout<<flush;
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int ans=0;
  string S;
  cin >> S;
  for(int i=0;i<S.size();i++){
     if(S.at(i)=='o'){
     ans+=100;
     }
  }
  cout << ans+700 << endl;
}
  

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

int main() {
  ll N;
  cin >> N;
  ll ans;
  if (N % 2 == 0) {
    ans = N/2 * (N-1);
  }
  if (N % 2 == 1) {
    ans = (N-1)/2 * N;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n,k;
  cin >> n >> k >> s;
  string b="ABC";
  string l="abc";
  for (int i=0;i<3;i++){
    if (s.at(k-1)==b.at(i)) {
      s.at(k-1) = l.at(i);
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3608
<?php
fscanf(STDIN, "%d", $m);
$ans = 0;
$next = [0,2,4,6,8,1,3,5,7,9];
$last = array_fill(0,10,0);
for($i = 0; $i<$m; $i++){
    fscanf(STDIN, "%d%d", $num, $pow);

    if($pow == 1){
        $last[$num]++;
    }else{
        while($pow > 1){
            if($pow % 2 ==1){
                $last[$num]++;
                $pow--;
            }
            $pow = $pow/2;
            if($num >= 5){
                $ans += $pow * 2;
            }else{
                $ans += $pow;
            }
            $num = $next[$num];
        }
        $last[$num]++;
    }
}
$goal = [];
foreach($last as $num => $pow){
    if($pow == 0){
        continue;
    }
    while($pow > 1){
        if($pow % 2 ==1){
            $goal[] = $num;
            $pow--;
        }
        $pow = $pow/2;
        if($num >= 5){
            $ans += $pow * 2;
        }else{
            $ans += $pow;
        }
        $num = $next[$num];
    }
    $goal[] = $num;
}

for($i=1;$i<count($goal);$i++){
    $goal[$i] = $goal[$i] + $goal[$i-1];
    $ans++;
    if($goal[$i] >= 10){
        $goal[$i] = substr($goal[$i],0,1) +  substr($goal[$i],1,1) ;
        $ans++;
    }

}

echo $ans;

Measured memory_bytes: 4856
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);
const bool DEBUG = 0;

int students, checks;
std::vector<pair<int, int> > student, check;

int main()
{
	int i, j;

	cin >> students >> checks;

	for(int i = 0; i < students; i++)
	{
		int x, y;
		cin >> x >> y;
		student.PB(MP(x, y));
	}

	for(int i = 0; i < checks; i++)
	{
		int x, y;
		cin >> x >> y;
		check.PB(MP(x, y));
	}

	for(int i = 0; i < students; i++)
	{
		int thisDist = MOD * 2, thisAns = -1;;
		for(int j = 0; j < checks; j++)
		{
			int dd = abs(student[i].first - check[j].first) + abs(student[i].second - check[j].second);
			// cout << dd << "\n";
			if(dd < thisDist)
			{
				thisDist = dd;
				thisAns = j;
			}
		}
		cout << thisAns + 1 << "\n";
	}


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
#define rep(i,j,n) for(int i=(j);i<=((int)n);++i)
#define rev(i,n,j) for(int i=(n);i>=((int)j);--i)
typedef long long int ll;
#define int long long int
const ll INFL=0x3f3f3f3f3f3f3f3fLL;
const int INF=0x3f3f3f3f;
const int mod=1000000007;
#define endl "\n"
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define pb push_back
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define readmat(a, n, m) int a[n + 5][m + 5] = {}; rep(i, 1, n) {rep(j, 1, m) cin >> a[i][j];}
#define printmat(a, n, m) rep (i, 1, n) {rep (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define printarr(a, n) rep(i, 1, n) cout << a[i] << " "; cout << endl;
typedef std::map< int,int> mii;
typedef std::vector< int > vi;
typedef std::vector< vi > vvi;
typedef std::pair< int,int > ii;
using namespace std;
#define cerr cout
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);}
const int N = 1e6+5, M = N;
vector <int>g[N];

ll power(ll a, ll b)	//a is base, b is exponent
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	if(b%2 == 1)
		return (power(a,b-1)*a)%mod;
	ll q = power(a,b/2);
	return (q*q)%mod;
}

int fac[N];
int inv[N];

void pre()
{
	fac[0]=1;
	fac[1]=1;
	for(int i = 2; i <=5e5+2; ++i) 
	{
		fac[i]=(i*fac[i-1])%mod;
	}
	for(int i = 0; i <=5e5+2; ++i) 
	{
		inv[i]=power(fac[i],mod-2);
	}
}

int ncr(int a,int b)
{
	if (b>a)
		return 0;

	return (((fac[a]*inv[b])%mod)*inv[a-b])%mod;
}

void solve()
{
	pre();
	int n,m;
	cin>>n>>m;
	int ans=(ncr(m,n)*fac[n])%mod;
	int x=1;
	int ps=0;
	for(int i = 0; i <=n; ++i) 
	{
		int q=(ncr(n,i)*fac[n-i])%mod;
		q=(q*(ncr(m-i,n-i)))%mod;
		q*=x;
		ps=(ps+q)%mod;
		x*=-1;
	}

	cout<<(((ps*ans)%mod)+mod)%mod<<endl;



  

}



signed main()
{
  FAST;
#ifdef LOCAL
    freopen("C:\\Users\\hp\\Documents\\input.txt", "r", stdin);
    freopen("C:\\Users\\hp\\Documents\\output.txt", "w", stdout);
    std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
    start = std::chrono::high_resolution_clock::now();
#endif

solve();

#ifdef LOCAL
    end = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
    cout<<endl;
    cout << "\nElapsed Time: " << elapsed_time << "ms\n";
#endif

return 0;

}

// vector string set map first second continue break return upper_bound lower_bound length void sort
// stack queue pop size erase empty insert
// #Hala BBCF



Measured memory_bytes: 34824
#include <bits/stdc++.h>
#define INF 1LL<<60
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll sum[205][205];
ll a[205][205];


// return [ly,ry)*[lx,rx)
ll getsum(int ly,int ry,int lx,int rx){
	//printf("%d %d %d %d %lld\n",ly,ry,lx,rx,sum[ry][rx]-sum[ry][lx]-sum[ly][rx]+sum[ly][lx]);
	return sum[ry][rx]-sum[ry][lx]-sum[ly][rx]+sum[ly][lx];
}

ll calc_two(int ly,int ry,int lx,int rx){
	ll res=0;
	for(int i=ly;i<ry;i++){
		ll v1=getsum(i,ry,lx,rx);
		ll v2=getsum(ly,i,lx,rx);
		if(v1>v2){
			swap(v1,v2);
		}
		res=max(v1,res);
	}
	for(int i=lx;i<rx;i++){
		ll v1=getsum(ly,ry,lx,i);
		ll v2=getsum(ly,ry,i,rx);
		if(v1>v2){
			swap(v1,v2);
		}
		res=max(v1,res);
	}
	return res;
}

ll solve(int ly,int ry,int lx,int rx,int n){
	if(n==2)return calc_two(ly,ry,lx,rx);
	ll res=0;
	for(int i=ly;i<ry;i++){
		ll v1=solve(i,ry,lx,rx,n-1);
		ll v2=getsum(ly,i,lx,rx);
		if(v1>v2){
			swap(v1,v2);
		}
		res=max(v1,res);
		v1=getsum(i,ry,lx,rx);
		v2=solve(ly,i,lx,rx,n-1);
		if(v1>v2){
			swap(v1,v2);
		}
		res=max(v1,res);
	}
	for(int i=lx;i<rx;i++){
		ll v1=solve(ly,ry,lx,i,n-1);
		ll v2=getsum(ly,ry,i,rx);
		if(v1>v2){
			swap(v1,v2);
		}
		res=max(v1,res);
		v1=getsum(ly,ry,lx,i);
		v2=solve(ly,ry,i,rx,n-1);
		if(v1>v2){
			swap(v1,v2);
		}
		res=max(v1,res);
	}
	if(n==3)return res;
	for(int i=0;i<ry-1;i++){
		for(int j=0;j<rx-1;j++){
			ll v1=getsum(0,i,0,j);
			if(v1<=res)continue;
			for(int k=1;k<j;k++){
				ll v2=getsum(i,ry,0,k);
				int lv=i,rv=ry;
				while(lv+1<rv){
					int mid=(lv+rv)/2;
					if(getsum(0,mid,j,rx)>getsum(mid,ry,k,rx))rv=mid;
					else lv=mid;
				}
				res=max(res,min(v1,min(v2,min(getsum(0,lv,j,rx),getsum(lv,ry,k,rx)))));
				res=max(res,min(v1,min(v2,min(getsum(0,lv+1,j,rx),getsum(lv+1,ry,k,rx)))));
			}
			for(int k=j;k<rx-1;k++){
				ll v2=getsum(i,ry,0,k);
				int lv=0,rv=i;
				while(lv+1<rv){
					int mid=(lv+rv)/2;
					if(getsum(0,mid,j,rx)>getsum(mid,ry,k,rx))rv=mid;
					else lv=mid;
				}
				res=max(res,min(v1,min(v2,min(getsum(0,lv,j,rx),getsum(lv,ry,k,rx)))));
				res=max(res,min(v1,min(v2,min(getsum(0,lv+1,j,rx),getsum(lv+1,ry,k,rx)))));
			}
		}
	}
	return res;
}


int main(void){
	int h,w,n;
	scanf("%d%d%d",&h,&w,&n);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%lld",&a[i][j]);
			sum[i+1][j+1]+=a[i][j];
		}
	}
	for(int i=0;i<=h;i++){
		for(int j=0;j<w;j++){
			sum[i][j+1]+=sum[i][j];
		}
	}
	for(int i=0;i<=w;i++){
		for(int j=0;j<h;j++){
			sum[j+1][i]+=sum[j][i];
		}
	}
	printf("%lld\n",solve(0,h,0,w,n));
	return 0;
} 


Measured memory_bytes: 3884
x = [int(i) for i in input().split()]

ans = 0

rmax = x[3]/x[0]
for i in range(int(rmax)+1):
    gmax = (x[3] -x[0]*i)/x[1]
    for j in range(int(gmax)+1):
        if (x[3]-x[0]*i - x[1]*j)%x[2] == 0:
                ans = ans + 1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ll w,h,x,y;
	long double W,H;
	cin>>w>>h>>x>>y;
	W=w,H=h;
	ll f=0;
	if(w==2*x&&h==2*y)f=1;
	cout<<fixed<<setprecision(10)<<W*H/2<<' '<<f;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func min(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	fmt.Println(min(a, b) + min(c, d))
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <stack>

using namespace std;

int a,b,c,x,y;
int ans;

int main() {
    cin>>a>>b>>c>>x>>y;
    if (x<y) {swap(x,y);swap(a,b);}
    int delta=x-y;
    ans+=min(y*(a+b),y*c*2);
    ans+=min(delta*a,delta*c*2);
    cout << ans;
}

Measured memory_bytes: 256
N, K = [int(c) for c in input().split()]

if N < K:
    print(0)
elif K == 0:
    print(N**2)
else:
    cnt = 0
    b_min = K+1 if K > 0 else 1
    for b in range(b_min, N+1):
        #print((N//b) * max(0, b-K) + max(0, (N%b)-K+1))
        cnt += (N//b) * (b-K) + max(0, N%b-K+1)

    print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1}; // 移動方向

ll H,W;

void input(){
    cin >> H >> W;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    ll ans = INF;
    for(int h=1;h<H;++h){
        ll a = h*W;
        ll b = (H-h)*(int(W/2));
        ll c = (H-h)*(W-int(W/2));
        ll mx = a;
        ll mn = a;
        chmax(mx, b);
        chmax(mx, c);
        chmin(mn, b);
        chmin(mn, c);
        chmin(ans, mx - mn);
    }
    for(int w=1;w<W;++w){
        ll a = w*H;
        ll b = (W-w)*(int(H/2));
        ll c = (W-w)*(H-int(H/2));
        ll mx = a;
        ll mn = a;
        chmax(mx, b);
        chmax(mx, c);
        chmin(mn, b);
        chmin(mn, c);
        chmin(ans, mx - mn);
    }
    for(int h=1;h<H;++h){
        ll a = h*W;
        ll b = int((H-h)/2)*W;
        ll c = (H-h-int((H-h)/2))*W;
        ll mx = a;
        ll mn = a;
        chmax(mx, b);
        chmax(mx, c);
        chmin(mn, b);
        chmin(mn, c);
        chmin(ans, mx - mn);
    }
    for(int w=1;w<W;++w){
        ll a = w*H;
        ll b = int((W-w)/2)*H;
        ll c = (W-w-int((W-w)/2))*H;
        ll mx = a;
        ll mn = a;
        chmax(mx, b);
        chmax(mx, c);
        chmin(mn, b);
        chmin(mn, c);
        chmin(ans, mx - mn);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  long long tmp = 0;
  vector<long long> b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    tmp += a[i];
    b[i] = tmp;
  }
  long long ans = 0;
  int mod = 1000000007;
  for (int i = 0; i < n-1; i++) {
    long long sum = (b[n-1] - b[i])%mod;
    ans += (a[i]*sum)%mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5592
a, v = gets.split.map(&:to_i)
b, w = gets.split.map(&:to_i)
t = gets.to_i

if v <= w
  puts "NO"
else
  aa = v * t
  bb = w * t
  puts (aa - bb) >= (b - a).abs ? "YES" : "NO"
end

Measured memory_bytes: 14308
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  int n;
  string s;
  cin >> n >> s;
  if(s.size()<=n)
    cout << s << endl;
  else
    cout << s.substr(0,n)+"..." << endl;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); \
					  cerr << "\n\n" << "Time elapsed: " << \
					  (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n"; \
					  return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define pii pair<int , int>
#define pdd pair<db , db>
#define pll pair<ll , ll>
#define vpl vector<pll >
#define vll vector<ll >
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed<<setprecision(20)
#define endl '\n'

int main()
{
	// start_routine();
	fastio;
	// #ifndef ONLINE_JUDGE
 //        freopen("input.txt", "rt", stdin);
 //        freopen("output.txt", "wt", stdout);
 //    #endif

    string s;
    string t="keyence";

    cin>>s;
    ll n=s.length();
    
    if(n<7)
    	return cout<<"NO",0;

    ll i=0,j=n-1;
    for(i=0;i<7;i++)
    	if(s[i]!=t[i])
    		break;

    if(i==7)
    	return cout<<"YES",0;

    reverse(t.begin(), t.end());
    for(j=0;j<7;j++)
    	if(s[n-j-1]!=t[j])
    		break;

    if(j==7)
    	return cout<<"YES",0;

    if(i+j>=7)
    	return cout<<"YES",0;
    else
    	return cout<<"NO",0;

	// end_routine();
}

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

main(){
  int n;
  int a, b;
  int maxv = -1;
  int id = 21;

  set<int> I;
  cin >> n;

  for ( int i = 0; i < n; i++ ){
    cin >> a >> b;
    I.insert(a);
    if ( maxv == b ){
      if ( id > a ){
	maxv = b;
	id = a;
      }
    } else if ( maxv < b ){
      maxv = b;
      id = a;
    }
  }

  cout << id << " " << maxv << endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 5;
ll N, A[MAX];

bool check(int x){
    unordered_map<ll, ll> mp;
    ll piv = 0, sum = 1, ret = 0;
    mp[0] = 1;
    for(int i = 0; i < N; i++){
        if(A[i] >= x){
            piv++;
            sum += mp[piv];
        }
        else{
            sum -= mp[piv];
            piv--;
        }
        ret += sum;
        mp[piv]++;  sum++;
    }
    return (2LL * ret < N * (N + 1) / 2);
}

int main(){
    scanf("%lld", &N);
    vector<ll> vt;
    for(int i = 0; i < N; i++){
        scanf("%lld", A + i);
        vt.push_back(A[i]);
    }
    sort(vt.begin(), vt.end());
    vt.erase(unique(vt.begin(), vt.end()), vt.end());
    ll l = 0, r = vt.size() - 1;
    while(l < r){
        int mid = (l + r + 1) / 2;
        if(check(vt[mid])){
            r = mid - 1;
        }
        else{
            l = mid;
        }
    }
    cout << vt[l] << endl;
    return 0;
}


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

int main() {
	 int x,n;
	 cin>>x>>n;
	 map<int,int>m;
	 for(int i=0;i<n;i++)
	 {
	     int temp;
	     cin>>temp;
	     m[temp]=1;
	 }
	 int min1=1000000,ans;
	 for(int i=-200;i<=200;i++)
	 {
	     if(i<0)
	     {
	         if(min1>abs(x-i))
	         min1=abs(x-i),ans=i;
	     }
	     else
	     {
	         if(m[i]==0 && min1>abs(x-i))
	         min1=abs(x-i),ans=i;
	         
	     }
	 }
	 cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
 
using namespace std;

int lcm( int x, int y )
{
    return (x*y)/__gcd(x,y);
}
 
signed main()
{
    fast;
    int n,m;
    cin>>n>>m;

    vector<int> a(n);
    int l = 1;
    for ( int i = 0 ; i < a.size() ; i++ )
    {
        cin>>a[i];
        l = lcm(l,a[i]);
    }

    int found = 0;

    for ( int i = 0 ; i < a.size() ; i++ )
    {
        if ( (l/a[i])%2 == 0 )
        {
            found = 1;
            break;
        }
    }
    l /= 2;
    if ( found == 1 )
    {
        cout<<0<<endl;
    }
    else
    {
        if ( (m/l) % 2 == 0 )
        {
            cout<<(m/l)/2<<endl;
        }
        else
        {
            cout<<((m/l)/2)+1<<endl;
        }
        
    }
    return 0;
}

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

typedef long long ll;

const int maxn = 2020, mod = 1e9 + 7;
int a, b, ans, dp[maxn][maxn], choose[maxn][maxn], sum[maxn][maxn];

ll add(int a, int b){
    return (ll(a) + b) % mod;
}

ll mult(int a, int b){
    return (ll(a) * b) % mod;
}

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

    for(int i = 0; i < maxn; i++){
        dp[0][i] = 1;
        dp[i][0] = 1;
        choose[i][0] = 1;
        sum[i][0] = 1;
    }

    for(int i = 1; i < maxn; i++){
        for(int j = 1; j < maxn; j++){
            choose[i][j] = add(choose[i - 1][j], choose[i - 1][j - 1]);
            sum[i][j] = add(sum[i][j - 1], choose[i][j]);
        }
    }

    for(int i = 1; i < maxn; i++){
        for(int j = 1; j < maxn; j++){
            dp[i][j] = add(dp[i - 1][j], sum[j - 1][min(i, j - 1)]);
        }
    }

    for(int i = 0; i <= a; i++){
        for(int j = 0; j <= min(a - i, b - 1); j++){
            ans = add(ans, mult(dp[a - i - j][j],  choose[b - 1][j]));
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
	string S, T;

	cin >> S >> T;

	int s = S.size(), t = T.size();

	for (int i = s - t; i >= 0; i--) {
		int k = 0;
		for (int a = 0; a < t; a++) {
			if (S[i + a] != T[a] && S[i + a] != '?')k = 1;
		}
		if (k)continue;
		for (int a = 0; a < t; a++) {
			S[i + a] = T[a];
		}
		for (int a = 0; a < s; a++) {
			if (S[a] == '?')S[a] = 'a';
		}
		cout << S << endl;
		return 0;
	}

	cout << "UNRESTORABLE" << endl;

	return 0;
}

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

#define ntest 0

using namespace std;
int x;
void solve() {
    cin >> x;
    cout << 1 - x;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
static const int64_t mod=1000000007;
int64_t f(int64_t x,int64_t y){
if(y==0)
  return 1;
  else if(y%2==0)
    return (f(x,y/2)*f(x,y/2))%mod;
  else
    return (x*((f(x,y/2)*f(x,y/2))%mod))%mod;

}
int main(){
int N;
  cin>>N;
  vector<int>A(N+1);
  for(int i=0;i<=N;i++)
    cin>>A.at(i);
  set<int>S;
  int b,a;
  for(int i=0;i<=N;i++)
    if(!S.count(A.at(i)))
       S.insert(A.at(i));
       else{
         b=i; break;}
       for(int i=0;i<N;i++)
       if(A.at(i)==A.at(b)){
       a=i; break;
       }int n=N-b+a;
       int64_t A1=N+1; int64_t B=1;
       for(int64_t i=2;i<=N+2;i++){
              cout<<(A1-B+mod)%mod<<endl;
         A1=(A1*(N+2-i))%mod;
         A1=(A1*f(i,mod-2))%mod;
         B=(B*(n+2-i))%mod;
         B=(B*f(i-1,mod-2))%mod;
       }
    
   return 0;
}

Measured memory_bytes: 8168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MAX_N = 10101010;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

int sieve(int n) {
    int p = 0;
    for (int i = 0; i <= n; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= n; i++) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (int j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return p;
}

int main() {
    int p = sieve(MAX_N);
    vector<int> vec;
    for (int i = 3; i < p; i++) {
        if (prime[i - 3] + 2 == prime[i - 2] && prime[i - 3] + 6 == prime[i - 1] && prime[i - 3] + 8 == prime[i]) {
            vec.push_back(prime[i]);
        }
    }
    int n;
    while (cin >> n && n) {
        int idx = upper_bound(vec.begin(), vec.end(), n) - vec.begin();
        idx--;
        cout << vec[idx] << endl;
    }
}


Measured memory_bytes: 15600
#include<stdio.h>
int main()
{
	int a,b,t;
	while(~scanf("%d %d %d",&a,&b,&t))
	{
		int c=0;
		if(a<=t)
		{
				for(int i=a;i<=t;i=i+a)
		{
			c=c+b;
		}
	printf("%d\n",c);
		}
	if(a>t)
	printf("0");
	}
	return 0;
 } 

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

const ll MOD = (ll)(1e9)+7;

ll inv[100000 + 10];
int a[100000 + 10];

map<pair<ll,ll> ,ll> memo;
ll choose(ll n, ll r) {
  if (r == 0) return 1;
  if (r < 0) return 0;
  if (n < r) return 0;
  if (memo.count( make_pair(n,r) ) == 0) {
    ll res = 1;
    for (int k = 1; k < 100000 + 10; k++) {
      res *= (n - k + 1);
      res %= MOD;
      res *= inv[k];
      res %= MOD;
      memo[ make_pair(n,k) ] = res;
    }
  }
  return memo[make_pair(n,r)];
}

int main2() {
  memo.clear();
  int N = nextInt();
  REP(i, N+1) a[i] = nextInt();
  int X, Y, Z;

  ll dup = -((ll)N) * (N+1) / 2;
  REP(i, N+1) dup += a[i];

  int ap = 0;
  REP(i, N+1) {
    if (a[i] == dup) {
      if (ap == 0) {
        X = i;
        ap++;
      } else {
        Y = i - X - 1;
        Z = N - i;
      }
    }
  }
  // cout << X << " " << Y << " " << Z << endl;

  for (int k = 1; k <= N+1; k++) {
    if (k == 1) {
      cout << N << endl;
    } else if (k == 2) {
      ll ans = choose(N-1, 2) + (X+Y) + (Y+Z) + 1;
      ans %= MOD;
      cout << ans << endl;
    } else {
      ll ans = 0;
      ans += choose(X+Y+Z, k);
      ans += 2 * choose(X+Y+Z, k-1);
      ans += (MOD - choose(X + Z, k-1));
      ans += choose(X+Y+Z, k-2);
      ans %= MOD;
      cout << ans << endl;
    }
  }

  return 0;
}

  
int main() {
  inv[1] = 1;
  for (int i = 2; i < 100000 + 10; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 14592
#include<stdio.h>
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
int main()
{
    int n;
    scanf("%d",&n);
    
    int A[n];
    for(int i=0;i<n;i++)scanf("%d",&A[i]);
    int minv=A[0];
    int maxv=-2000000000;
    for(int i=1;i<n;i++)
    {
        maxv=max(maxv,A[i]-minv);
        minv=min(minv,A[i]);
    }
    
    printf("%d\n",maxv);
    return 0;
    
    
}


Measured memory_bytes: 2580
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <iostream>
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> arr(n);
    for(int i=0; i<n; i++)cin >> arr[i];
    vector<int> dp(n);
    dp[0] = 0;
    dp[1] = abs(arr[1]-arr[0]);
    for(int i=2; i<n; i++)
    {
        int first = dp[i-2]+abs(arr[i]-arr[i-2]);
        int second = dp[i-1]+abs(arr[i]-arr[i-1]);
        dp[i] = min(first,second);
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define inf 1e18

 
using namespace std;
 
int max(int a, int b)
{
    if(a>b) return a;
    else return b;
}
 
int min(int a,int b)
{
    if(a<b) return a;
    else return b;
}
#define MAXN 10000001
// stores smallest prime factor for every number 
int spf[10000001]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
vector<int> getFactorization(int x) 
{ 
    vector<int> ret; 
    while (x != 1) 
    { 
        ret.push_back(spf[x]); 
        x = x / spf[x]; 
    } 
    return ret; 
} 

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif
    
    IOS;
    int n,i;
    cin>>n;
    sieve();
    int ans=1;
    for(i=2;i<=n;i++)
    {
        map<int,int> m;
        int x=i;
        int prd=1;
        while (x != 1) 
        { 
            m[spf[x]]++; 
            x = x / spf[x]; 
        }
        for(auto it=m.begin();it!=m.end();it++) prd*=it->S+1;
        ans+=prd*i;
    }
    cout<<ans;
}


Measured memory_bytes: 81668
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int[] digits(int n) {
    if (n == 0) return [0];

    int[] d;
    while (n > 0) {
        d ~= n % 10;
        n /= 10;
    }
    d.reverse();
    return d;
}

void main() {
    int n = readint;
    writeln(n % digits(n).sum == 0 ? "Yes" : "No");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, k, count=0;;
    int l[20000];
    cin >> n>>k;
    for (int i=0; i<n; i++){
        cin >> l[i];
    }
    sort(l, l+n, greater<int>());
    for(int i=0; i<k; i++){
        count += l[i];
    }
    cout << count << endl;
    return 0;
}

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

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define watch(x) cout<<(#x)<<" is "<<(x)<<"\n"
#define show(a,b) cout<<(#a)<<" is "<<(a)<<" "<<(#b)<<" is "<<(b)<<"\n"
#define ll long long int
#define pb push_back
#define mp make_pair
#define f(n) for(auto i=0;i<n;i++) 
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<pi,pi> ppi;

void solve()
{
    int n,k;
    cin>>n>>k;
    vi h(n);
    f(n)
    cin>>h[i];
    vi dp(n,INT_MAX);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        int count=1;
        while(count<=k && i-count>=0)
        {
            
            dp[i]=min(dp[i],dp[i-count]+abs(h[i]-h[i-count]));
            count++;
        }
        
    }
    cout<<dp[n-1]<<"\n";
}

int main()
{
    fast;
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n<2){
       cout<<1<<endl;
    }
    else if(n<4){
        cout<<2<<endl;
    }
    else if(n<8){
        cout<<4<<endl;
    }
    else if(n<16){
        cout<<8<<endl;
    }
    else if(n<32){
        cout<<16<<endl;
    }
    else if(n<64){
        cout<<32<<endl;
    }
    else{
        cout<<64<<endl;
    }
    return 0;
}


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

const int MOD = 1000000007;

char a[1010][1010];
long dp[1010][1010];

int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	for(int i=0; i < h; i++)
		for(int j=0; j < w; j++)
			scanf(" %c", &a[i][j]);
	dp[0][0] = 1;
	for(int i=0; i < h; i++) {
		for(int j=0; j < w; j++) {
			if(a[i][j] == '#') continue;
			if(i-1 >= 0) dp[i][j] = (dp[i][j] + dp[i-1][j]) % MOD;
			if(j-1 >= 0) dp[i][j] = (dp[i][j] + dp[i][j-1]) % MOD;
		}
	}
	printf("%ld\n", dp[h-1][w-1]);
}


Measured memory_bytes: 9216
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,h,w,cnt=0;
  cin >> n >> h >> w;
  ll a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    if(a[i]>=h&&b[i]>=w){
      cnt++;
    }
  }
  cout << cnt<<endl;
}


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

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

typedef long long LL;
typedef unsigned long UL;

using namespace std;

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

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

	sort(l.rbegin(), l.rend());

	int temp = 0;

	REP(i, n)
	{
		if (i > 0)
		{
			temp += l[i];
			if (l[0] < temp)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
const ll MOD=(ll)1e9+7;

int main(){
  ll n,ans=0;
  cin>>n;
  ll m=floor(sqrt(n));
  for(int i=1;i<=m;i++){
    ans+=i*(i+n/i)*(n/i+1-i);
  }
  ans-=m*(m+1)*(2*m+1)/6;
  cout<<ans<<endl;
}


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

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

const int N = 2e5+10 , mod = 1e9+7;

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n;
   ll k;
   cin >> n >> k;
   k *= k;
   int ans = 0;
   for(int i = 0 ; i < n ; i++){
      ll x , y;
      cin >> x >> y;
      x *= x;
      y *= y;
      ans += ((x + y) <= k);
   }
   cout << ans;
   return 0;
}


Measured memory_bytes: 3592
#!/usr/bin/env ruby

def figure(s, p)
    if s.include?(p) then
        return true
	end

    i = 0
	loop do
        idx = p[i..-1].index(s[-1]+s[0])
        if idx.nil? then
            break
		end
		idx += i
		if s[-(idx+1)..-1]+s[0, p.size-(idx+1)] == p then
            return true
		end
        i = idx+1
	end
    return false
end

if __FILE__ == $0 then
	s, p = gets.chomp, gets.chomp
	puts figure(s, p) ? 'Yes' : 'No'
end


Measured memory_bytes: 8864
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	string s;
	cin>>s;
	if(s[0]==s[1] && s[2]==s[3] && s[0]!=s[2]) cout<<"Yes"<<endl;
	else if(s[0]==s[2] && s[1]==s[3] && s[0]!=s[1]) cout<<"Yes"<<endl;
	else if(s[0]==s[3] && s[1]==s[2] && s[0]!=s[1]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;


	return 0;
}

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

typedef vector<int>  vi;
typedef set<char> setchar;
typedef set<int> sett;
typedef deque <int> dq;
typedef long long ll;
#define vec(a)  a.begin(),a.end()
#define pb     push_back
#define pf     push_front
#define F first
#define S second
#define mem(a,b) memset(a,b,sizeof(a));
#define inI(a)  scanf("%d",&a);
#define inT(a,b)  scanf("%d %d",&a,&b);
#define inL(a)  scanf("%lld",&a);
#define SWAP(a,b) a= a^b, b=a^b, a=a^b

//int fx[]={+0,-1,-1,-1,+0,+1,+1,+1};
//int fy[]={-1,-1,+0,+1,+1,+1,+0,-1};
int fx[]= {0,-1,0,+1};
int fy[]= {-1,0,+1,0};



int main()
{

    //freopen("input.txt","r",stdin);
    ll a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(a>=k)
    {
        ans+=(k*1);
        k=0;
    }
    else
    {
        ans+=(a*1);
        k=k-a;
    }
    if(k>0)
    {
        if(b>=k)
        {
            ans+=(b*0);
            k=0;
        }
        else
        {
            ans+=(k*0);
            k=k-b;
        }

    }
    if(k>0)
    {
        if(c>=k)
        {
            ans+=(k*-1);
            k=0;
        }
        else
        {
            ans+=(c*-1);
        }

    }
    cout<<ans<<"\n";




    return 0;

}







Measured memory_bytes: 3620
# coding: utf-8
# Your code here!
import numpy as np
n = int(input())

a = np.array([list(map(int,input().split())) for _ in range(n)])
t = np.argsort(a[:,0]+a[:,1])[::-1]
ans = 0

for i,j in zip(t,range(n)):
    if j%2 == 0:
        ans+=a[i][0]
    else:
        ans-=a[i][1]

print(ans)

Measured memory_bytes: 37840
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
#define rep(i, n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll int n, m;
  while(cin >> n >> m) {
    ll int gcd = __gcd(n, m);
    ll int lcm = n * m / gcd;
    cout << gcd << ' ' << lcm << endl;
  }
  return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  string a;
  cin >> a;
  int b=0,r=0;
  for (int z=0;z<n;z++){
    if (a[z] == 'B')b++;
    if (a[z] == 'R')r++;
  }
  if (r>b) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            while (true)
            {
                var inputs = Console.ReadLine().Split(' ');
                var nums = Array.ConvertAll(inputs, int.Parse);
                if ((nums[0] | nums[1]) == 0) return;
                var H = nums[0];
                var W = nums[1];
                const char outsideBlock = '#';
                const char insideBlock = '.';
                var frame = new char[H,W];

                for (int h = 0; h < H; h++)
                {
                    for (int w = 0; w < W; w++)
                    {
                        if (h == 0 || h == H - 1 || w == 0 || w == W - 1)
                        {
                            frame[h,w] = outsideBlock;
                        }
                        else
                        {
                            frame[h,w] = insideBlock;
                        }
                    }
                }

                for (int h = 0; h < H; h++)
                {
                    for (int w = 0; w < W; w++)
                    {
                        Console.Write(frame[h,w]);
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 5400
#include <bits/stdc++.h>
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define fi first
#define se second
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define MOD 1000000007
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 200009
#define M 1e6 + 9
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll, ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
#define int long long
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}
 
 struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }

  vector<pair<int,int> > factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return vector<pair<int,int> >();
    vector<pair<int,int> > res(1, make_pair(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.push_back(make_pair(p, 1));
      }
    }
    return res;
  }
};
 
 
 
void test_case()
{
    
    
    int x;
    cin>>x;


    int temp = 1939399;
    Sieve s(temp);
    
    
    while(!s.isPrime(x)) {
        x++;
    }

    cout<<x<<endl;


      



 
    
}
 
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    cin >> n;
    array<int,50> a,b;
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) cin >> b[i];
    int ans = 1000000;
    for (int s = 0;s < (1<<n);++s) {
        int cnt = 0;
        for (int i = 0;i < n;++i) if ((s>>i)&1) cnt++;
        if (cnt&1) continue;
        vector<int> c(n),d(n);
        for (int i = 0;i < n;++i) {
            if ((s>>i)&1) c[i] = b[i],d[i] = b[i];
            else c[i] = a[i],d[i] = a[i];
        }
        sort(c.begin(),c.end());
        int sum = 0;
        bool ok = true;
        vector<int> e(n);
        vector<bool> used(n,false);
        for (int i = 0;i < n;++i) {
            bool f = false;
            for (int j = 0;j < n;++j) {
                // if (s == 3) if (i == 0 && j == 1) cout << c[i] << " " << d[j] << " " << used[j] << " " << ((s>>j)&1) << " " << (i-j)%2 << endl;
                if (c[i] == d[j] && !used[j]) if ((((s>>j)&1) && abs(i-j)%2 == 1) || (((s>>j)&1) == 0 && (i-j)%2 == 0)) {
                    f = true;
                    e[j] = i;
                    used[j] = true;
                    break;
                }
            }
            if (f == false) {ok = false;break;}
        }
        // cout << s << endl;
        // p_ary(c,0,n);
        // p_ary(d,0,n);
        // p_ary(e,0,n);
        // cout << endl;
        if (ok == false) continue;
        for (int i = 0;i < n;++i) for (int j = 0;j < i;++j) if (e[i] < e[j]) sum++;
        ans = min(ans,sum);
    }
    if (ans < 1000000) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 256
def p_(l):
    if l==0:
        return 1;
    return 1+2*p_(l-1)
def len_(l):
    if l==0:
        return 1;
    return 3+2*len_(l-1)
def solve(l,s):
    if s==0:
        return 0
    if s==le[l]:
        return p[l]
    elif s>=2+le[l-1]:
        return 1+p[l-1]+solve(l-1,s-2-le[l-1])
    elif s>=1+le[l-1]:
        return p[l-1]+solve(l-1,s-2-le[l-1])
    elif s>=2:
        return solve(l-1,s-1)
    return 0

n,x=map(int,input().split())
p=[0]*(n+1)
le=[0]*(n+1)
for i in range(n+1):
    p[i]=p_(i)
    le[i]=len_(i)
print(solve(n,x))
    


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,a) REP(i,0,a)
#define REV(i,a,b) for(i=a-1;i>=b;i--)
#define rev(s) reverse(s.begin(),s.end())
#define pb push_back
#define mp make_pair
#define ord(v) sort(v.begin(),v.end());
const ll MAXN=2*1e5+10;
#define MAX 2*1e9
#define fi first
#define se second
#define pi 3.141592653589793238
#define rem 1000000007
#define eps 1e-9

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll n,i;
    cin>>n;
    char a[n];
    rep(i,n)
    cin>>a[i];
    ll p=0,q=n-1;
    ll count=0;
    while(p<q)
    {
        if(a[p]=='W')
        {
            if(a[q]=='R')
            {//cout<<a[p]<<" "<<a[q]<<endl;
                swap(a[p],a[q]);
                p++;
                q--;
                count++;
            }
            else q--;
        }
        else p++;

    }
    cout<<count<<endl;



    return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll N;
    cin >> N;
    vector<vector<pair<ll,ll>>> v(N);
    ll a,b,w;
    rep(i,N-1){
        cin >> a >> b >> w;
        v[--a].push_back(make_pair(--b,w));
        v[b].push_back(make_pair(a,w));
    }
    queue<pair<ll,ll>> que;
    que.push(make_pair(0,0));
    vector<int> memo(N,0);
    while(!que.empty()){
        ll x = que.front().first;
        ll y = que.front().second;
        que.pop();
        if(memo[x] != 0)continue;
        if(y % 2 == 0){
            memo[x] = 1;
        }else{
            memo[x] = 2;
        }
        rep(i,v[x].size()){
            que.push(make_pair(v[x][i].first, v[x][i].second + y));
        }
    }
    rep(i,N){
        cout << memo[i]-1 <<endl;
    }

}

Measured memory_bytes: 8320