akhauriyash/Code-Regression huggingface dataset:
/*************************************************************************
    > File Name: C.cpp
    > Author: HandsomeHow
    > Mail: handsomehowyxh@gmail.com 
    > Created Time: 2017/4/29 20:11:31
 ************************************************************************/

#include <bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------

int main(){
#ifdef HandsomeHow
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);
#endif
	int n;gn(n);
	ll t;gn(t);
	ll su = 0;
	ll lst = 0;
	rep(i,1,n){
		ll now;gn(now);
		if(now <= lst){
			su += now+t-lst;
			lst = now + t;
		}else{
			su += t;
			lst=now+t;
		}
	}
	cout<<su<<endl;
	return 0;
}



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

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		Edge[] edges= new Edge[m];
		for (int i = 0; i < m; i++) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			edges[i] = new Edge(a, b, c);
		}
		System.out.println(kruskal(n, edges));
	}

	private int kruskal(int n, Edge[] edges) {
		int totalCost = 0;
		Arrays.sort(edges);
		UnionFind unionFind = new UnionFind(n);
		for (Edge edge:edges) {
			if (!unionFind.isSame(edge.sorce, edge.target)) {
				totalCost += edge.cost;
				unionFind.merge(edge.sorce, edge.target);
			}
		}
		return totalCost;
	}

	class Edge implements Comparable<Edge> {
		int sorce, target, cost;

		@Override
		public String toString() {
			return "Edge [sorce=" + sorce + ", target=" + target + ", cost="
					+ cost + "]";
		}

		public Edge(int sorce, int target, int cost) {
			super();
			this.sorce = sorce;
			this.target = target;
			this.cost = cost;
		}

		@Override
		public int compareTo(Edge o) {
			return this.cost - o.cost;
		}

	}

	class UnionFind {
		int[] rank, node;

		UnionFind(int size) {
			rank = new int[size];
			node = new int[size];
			for (int i = 0; i < size; i++) {
				node[i] = i;
			}
		}

		@Override
		public String toString() {
			return "UnionFind [rank=" + Arrays.toString(rank) + ", node="
					+ Arrays.toString(node) + "]";
		}

		int find(int x) {
			if (x == node[x])
				return x;
			return node[x] = find(node[x]);
		}

		boolean isSame(int x, int y) {
			return find(x) == find(y);
		}

		void merge(int x, int y) {
			x = find(x);
			y = find(y);
			if (x == y)
				return;
			if (rank[x] > rank[y])
				node[y] = x;
			else {
				node[x] = y;
				if (rank[x] == rank[y])
					rank[y]++;
			}
		}

	}
}

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

int main(){
  int N,M,t=0;
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int tmp;
    cin >> tmp;
    t += tmp;
  }
  if(N >= t){
    cout << (N-t) << endl;
  }else{
    cout << -1 << endl;
  }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define INF 1000000000000000000
#define fn(i,n) for(int i=0;i<n;i+=1)

int dp[3001][3001]={0};

signed main() {
    string s,t;cin>>s>>t;
    int m=s.size();int n=t.size();
    fn(i,m+1)
    {
        fn(j,n+1)
        {
            if(i==0||j==0)dp[i][j]=0;
            else if(s[i-1]==t[j-1])
            dp[i][j]=dp[i-1][j-1]+1;
            else
            dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    string ans="";
    int i=m,j=n;
    while(i>0 && j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans+=s[i-1];i-=1;j-=1;
        }
        else if (dp[i-1][j]>dp[i][j-1])
        i-=1;
        else
        j-=1;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 70656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

const int MOD = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const { return pow(MOD-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination MOD prime
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
    mint p(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[n-k];
    }
}; //comb(10000007);
// comb(5, 2) → 10, comb.p(5, 2) → 20
// comb.fact[4] → 24, 2のN乗 → mint(2).pow(N)

mint imos[200005];

int main() {
    int N, K;
    cin >> N >> K;
    vector<P> LR(K);
    rep(i, K) cin >> LR[i].first >> LR[i].second;
    imos[0] = 1;
    for (int i = 0; i < N; i++) {
        if (i > 1) imos[i] += imos[i-1];
        for (auto p : LR) {
            int left = i + p.first;
            if (left >= N) continue;
            int right = min(N, i + p.second);
            imos[left] += imos[i];
            imos[right+1] -= imos[i];
        }
    }
    cout << imos[N-1] << '\n';
    return 0;
}

Measured memory_bytes: 5188
N, K= map(int,input().split())
a = list(map(int,input().split()))
p=0
while p<K:
  B=[0]*(N+1)
  for i in range(N):
    t = a[i]
    B[max(i-t,0)] +=1
    B[min(i+t+1,N)] -=1
  for i in range(N):
    B[i+1] += B[i]
  a=B[:N]        
  if min(a)==N:
    break
  p+=1
print(*a)

Measured memory_bytes: 169164
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

// input scanner
var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func gcd(a int64, b int64) int64 {
	for b > 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a int64, b int64) int64 {
	return (a / gcd(a, b)) * b
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := int64(nextInt())
	var b []int64
	lcmAll := int64(1)
	for i := 0; i < n; i++ {
		a := int64(nextInt())
		bi := a / 2
		b = append(b, bi)
		lcmAll = lcm(lcmAll, bi)
		if lcmAll > m {
			fmt.Println(0)
			return
		}
	}
	for i := 0; i < n; i++ {
		if (lcmAll/b[i])%2 == 0 {
			fmt.Println(0)
			return
		}
	}
	ans := (m/lcmAll + 1) / 2
	fmt.Println(ans)
}


Measured memory_bytes: 6912
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

int dx[]={1, 0, -1, 0};
int dy[]={0, -1, 0, 1};

int maxDepth;
int w, h;

void dfs(int cy, int cx, int depth, vector<vector<int>> &ice){
    ice[cy][cx] = 0;

    chmax(maxDepth, depth);

    if(0 <= cx - 1 && ice[cy][cx-1]){
        dfs(cy, cx-1, depth+1, ice);
    }
    if(cx + 1 < w && ice[cy][cx+1]){
        dfs(cy, cx+1, depth+1, ice);
    }
    if(0 <= cy - 1 && ice[cy-1][cx]){
        dfs(cy-1, cx, depth+1, ice);
    }
    if(cy + 1 < h && ice[cy+1][cx]){
        dfs(cy+1, cx, depth+1, ice);
    }

    ice[cy][cx] = 1;
}

int main(){
    while(1){
        cin>>w>>h;
        if(w == 0) return 0;

        vector<vector<int>> ice(h, vector<int>(w));
        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                cin>>ice[i][j];
            }
        }

        for(int i=0; i<h; i++){
            for(int j=0; j<w; j++){
                if(ice[i][j]){
                    dfs(i, j, 1, ice);
                }
            }
        }

        cout << maxDepth << endl;

        maxDepth = 0;
    }
}


Measured memory_bytes: 3176
import numpy as np
import math
N, X = map(int,input().split())
x = list(map(int,input().split()))
_x = N*[0]

for i in range(N):
  _x[i] = np.abs(X - x[i])

if N == 1:
  print(_x[0])
  exit()
ans = math.gcd(_x[0],_x[1])
for i in range(2,N):
  ans = math.gcd(_x[i],ans)
  
print(ans)
  

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

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

    int A[N + 1];
    A[0] = -1;

    for (int i = 1; i < N + 1; i++)
    {
        cin >> A[i];
    }

    int hat[3][N + 1];
    int x = 0, y = 0, z = 0;

    hat[0][0] = 0;
    hat[1][0] = 0;
    hat[2][0] = 0;

    for (int i = 1; i < N + 1; i++)
    {
        if (x == A[i])
        {
            x++;
            hat[0][i] = x;
            hat[1][i] = y;
            hat[2][i] = z;
            continue;
        }

        else if (y == A[i])
        {
            y++;
            hat[0][i] = x;
            hat[1][i] = y;
            hat[2][i] = z;
            continue;
        }

        else if (z == A[i])
        {
            z++;
            hat[0][i] = x;
            hat[1][i] = y;
            hat[2][i] = z;
            continue;
        }
    }

    long long ans = 1, div = 1e9 + 7;

    for (int i = 0; i < N; i++)
    {
        int cnt = 0;

        if (A[i + 1] == hat[0][i])
        {
            cnt++;
        }

        if (A[i + 1] == hat[1][i])
        {
            cnt++;
        }

        if (A[i + 1] == hat[2][i])
        {
            cnt++;
        }

        ans = ans % div * cnt;
    }

    cout << ans % div << endl;
}


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

const long long mod = 998244353;

long long mpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
  long long N,M,K;
  cin >> N >> M >> K;
  
  vector<long long> comb(N,1),power(N,1);
  for(long long i=1;i<N;i++){ // n-1 C i
    comb[i] = comb[i-1] * (N-i);
    comb[i] %= mod;
    comb[i] *= mpow(i,mod-2);
    comb[i] %= mod;
  }
  for(long long i=1;i<N;i++){ // (m-1)^i
    power[i] = power[i-1] * (M-1);
    power[i] %= mod;
  }
  
  long long ans=0;
  for(int i=0;i<=K;i++){
    long long x = M * power[N-i-1];
    x %= mod;
    x *= comb[i];
    x %= mod;
    ans += x;
    ans %= mod;
  }
  
  cout << ans << endl;
  return 0;
}


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

typedef long long LL;

const int N=200000,C=40;

int n,m;
struct thing{
  int x,y;
}a[N+9];

bool cmp0(const thing &a,const thing &b){return (LL)b.y*(a.x-1)>(LL)a.y*(b.x-1);}
bool cmp1(const thing &a,const thing &b){return a.y<b.y;}

void into(){
  scanf("%d%d",&n,&m);
  for (int i=1;i<=n;++i){
	scanf("%d%d",&a[i].x,&a[i].y);
	a[i].y+=++a[i].x;
  }
}

LL dp[N+9][C+9];
int ans;

void Get_dp(){
  sort(a+1,a+n+1,cmp0);
  for (int i=0;i<C;++i) dp[0][i]=m+1;
  dp[0][0]=0;
  int i=1;
  for (;i<=n;++i){
    if (a[i].x==1) break;
	for (int j=0;j<C;++j) dp[i][j]=min(dp[i-1][j],j?a[i].x*dp[i-1][j-1]+a[i].y:(LL)m+1);
  }
  sort(a+i,a+n+1,cmp1);
  for (int j=0;j<C;++j){
	LL t=dp[i-1][j];
	if (t>m) continue;
	ans=max(ans,j);
	for (int k=i;k<=n;++k)
	  if ((t+=a[k].y)>m) {ans=max(ans,j+k-i);break;}
    if (t<=m) ans=max(ans,j+n-i+1);
  }
}

void work(){
  Get_dp();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

int main() {
  string S;
  cin >> S;
  //cout << S.at(3) << endl;                                                                         

  if(S.size() != 4) {
    cout << "No" << endl;
    return 0;
  }
  int count = 0;
  char A, B, C, D;

  if(S.at(0) == S.at(1) && S.at(2) == S.at(3)) {
    count++;
    if(S.at(0) == S.at(2)) {
      count++;
    }
  }
  if(S.at(0) == S.at(2) && S.at(1) == S.at(3)) {
    count++;
    if(S.at(0) == S.at(1)) {
      count++;
    }
  }
  if(S.at(0) == S.at(3) && S.at(1) == S.at(2)) {
    count++;
    if(S.at(0) == S.at(1)) {
      count++;
    }
  }


  if(count == 1) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,m=map(int, input().split())
h=list(map(int, input().split()))
arr=[0]*n
for i in range(m):
    a,b=map(int, input().split())
    if h[a-1]>h[b-1]:
        if arr[a-1]!=-1:
            arr[a-1]=1
        arr[b-1]=-1
    elif h[a-1]<h[b-1]:
        if arr[b-1]!=-1:
            arr[b-1]=1
        arr[a-1]=-1
    else:
        arr[b-1]=-1
        arr[a-1]=-1
ans=0

for i in range(n):
    if arr[i]>=0:
        ans+=1
print(ans)

Measured memory_bytes: 20144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int N,X,T; cin >> N>>X>>T;
    int h = N/X;
    int k = N%X;
    if(k){AA(h*T+T);}
    else AA(h*T);
    return 0;
}

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

int N;
string S;

void solve() {
	S.push_back('.');
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		if (S[i] != S[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;
}

int main() {
	cin >> N >> S;
	solve();

	return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    vs a(h);
    rep(i, h) cin >> a[i];
    set<int> allwhite_i, allwhite_j;
    rep(i, h) {
        bool flag = true;
        rep(j, w) {
            if (a[i][j] == '#') flag = false;
        }
        if (flag) allwhite_i.insert(i);
    }
    rep(j, w) {
        bool flag = true;
        rep(i, h) {
            if (a[i][j] == '#') flag = false;
        }
        if (flag) allwhite_j.insert(j);
    }
    rep(i, h) {
        if (allwhite_i.count(i)) continue;
        rep(j, w) {
            if (!allwhite_j.count(j))cout << a[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep2(i,m,n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i,n) rep2(i,0,n)
#define all(x) (x).begin(), (x).end()
#define sz size()
#define pb push_back
#define bg begin()
#define ed end()
#define fi first()
#define se second()
using namespace std;
using ll = long long;
using vint = vector<int>;
using pint = pair<int,int>;
using vpint = vector<pint>;
template <typename T>
T sq(T x){
  return x * x;
}
ll mod = 1e9 + 7;

signed main (){
  string s;
  cin >> s;
  string ans;

  rep(i,s.sz){
if(i  % 2 == 0){
ans += s.at(i);
}
  }
cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3736
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N = 1e2 + 9;

int n, h, w, col[N][N], a;
typedef pair<int, int> pii;
pii now;

pii next (pii x) {
	static bool o = 0;
	if (x.second == (o ? 1 : w)) ++x.first, o ^= 1;
	else x.second += o ? -1 : 1;
	return x;
}

int main () {
	now = pii (1, 1);
	scanf ("%d%d%d", &h, &w, &n);
	for (int i = 1; i <= n; ++i) {
		scanf ("%d", &a);
		for (; a--; now = next(now)) col[now.first][now.second] = i;
	}
	for (int i = 1; i <= h; ++i) for (int j = 1; j <= w; ++j) printf ("%d%c", col[i][j], j == w ? '\n' : ' ');
	return 0;
}


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

#define ll long long
const char newl = '\n';

//***---***---***---Useless Code---***---***---***//

template<class T> void read(T &t) {
	cin >> t;
}
template<class A, class...B> void read(A& a, B&... b) {
	read(a);
	read(b...);
}
template<class T> void read(vector<T>& vt) {
	for(auto &a : vt)
		read(a);
}

string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return string(1, c); }
string to_string(string s) { return s; }
string to_string(const char* str) { return string(str); }
string to_string(vector<bool> vt) {
	string ret;
	bool ft = 1;
	for(bool x : vt) {
		if(!ft)
			ret += ' ';
		ft = 0;
		ret += char('0' + x);
	}
	return ret;
}
template<class T> string to_string(vector<T> vt) {
	string ret;
	bool ft = 1;
	for(auto a : vt) {
		if(!ft)
			ret += ' ';
		ft = 0;
		ret += to_string(a);
	}
	return ret;
}

template<class T> void write(T t) {
	cout << to_string(t);
}
template<class A, class... B > void write(A a, B... b) {
	write(a);
	if(sizeof...(b))
		write(' ');
	write(b...);
}
void print() {
	write(newl);
}
template<class A, class... B> void print(A a, B... b) {
	write(a);
	if(sizeof...(b))
		write(' ');
	print(b...);
}

//***---***---***---Useless Code---***---***---***//

int a,b,c,k;

void solve() {
	read(a,b,c,k);
	int ans = 0;
	bool bad = 0;
	while(a >= b) {
		b *= 2;
		++ans;
		if(ans > k)
			bad = 1;
	}
	while(b >= c) {
		c *= 2;
		++ans;
		if(ans > k)
			bad = 1;
	}
	print(bad ? "No" : "Yes");
}

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

	solve();
}


Measured memory_bytes: 3496
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define pri 1000000007
#define pr pair <ll,ll>

using namespace std;

void masterstroke(){
ll n,k;
cin>>n>>k;
ll v[n];
for(ll i=0;i<n;i++){
	cin>>v[i];
}
ll ans=0;
vector <ll> sa;
for(ll i=-1;i<n;i++){
	vector <ll> s=sa;
	if(i!=-1)s.PB(v[i]);
	if(i!=-1)sa.PB(v[i]);
	for(ll j=n;j>=i+1;j--){
        
        if(i+1+n-j>k)continue;
        if(j!=n)s.PB(v[j]);
        sort(all(s));
        ll xa=(k-(i+1+n-j));
        ll f=s.size();
        ll ne=0;
        for(ll i=f-1;i>=0;i--){
        	if(i<xa&&s[i]<0)break;
        	ne+=s[i];
        }
        ans=max(ans,ne);
	}
}
cout<<ans<<endl;
}

int main() {
    ll t=1;
    //cin>>t;
    for(ll i=0;i<t;i++)masterstroke();
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        int count = 0;
        int maxHeight = 0;

        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
            if (h[i] >= maxHeight) {
                maxHeight = h[i];
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<vector<ll>> dp(n,vector<ll>(4,0)); //A-dp[i][0] C-dp[i][1] G-dp[i][2] T-dp[i][3]
  for(int i=0; i<4; ++i) dp[0][i] = 1;
  for(int i=1; i<n; ++i){
    for(int j=0; j<4; ++j) for(int k=0; k<4; ++k){
      dp[i][j] += dp[i-1][k];
      dp[i][j] %= MOD;
    }
    if(i>=2){
      dp[i][1] -= dp[i-2][0] +dp[i-2][2];  //"AGC""GAC"
      if(dp[i][1] <0) dp[i][1] += MOD;
      if(dp[i][1] <0) dp[i][1] += MOD;
      dp[i][2] -= dp[i-2][0];  //"ACG"
      if(dp[i][2] <0) dp[i][2] += MOD;
    }
    if(i>=3){
      dp[i][1] -= dp[i-3][0] *3;  //"ATGC""AGGC"""AGTC"
      if(dp[i][1] <0) dp[i][1] += MOD;
      if(dp[i][1] <0) dp[i][1] += MOD;
      if(dp[i][1] <0) dp[i][1] += MOD;
      dp[i][2] += dp[i-3][2];  //"GACG"を2回引いてるので
      dp[i][2] %= MOD;
    }
  }
  ll ans = 0;
  for(int i=0; i<4; ++i) ans += dp[n-1][i];
  ans %= MOD;
  cout << ans << endl;
}

Measured memory_bytes: 3580
def main():
    import itertools
    import os
    import sys

    if os.getenv("LOCAL"):
        sys.stdin = open("_in.txt", "r")

    sys.setrecursionlimit(10 ** 9)
    INF = float("inf")
    IINF = 10 ** 18
    MOD = 10 ** 9 + 7


    # MOD = 998244353


    def cumsum(it):
        """
        累積和
        :param collections.Iterable it:
        """
        cs = 0
        ret = [0]
        for v in it:
            cs += v
            ret.append(cs)
        return ret


    def cumsum_mat(mat):
        h = len(mat)
        w = len(mat[0])

        tmp = []
        for row in mat:
            tmp.append(cumsum(row))
        del mat

        ret = [[0] * (w + 1) for _ in range(h + 1)]
        for c in range(w + 1):
            col = [row[c] for row in tmp]
            for r, a in enumerate(cumsum(col)):
                ret[r][c] = a
        return ret


    N, M, Q = list(map(int, sys.stdin.buffer.readline().split()))
    S = [list(map(int, sys.stdin.buffer.readline().decode().rstrip())) for _ in range(N)]
    XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]


    def count_v(x1, y1, x2, y2):
        return counts_cum[x2][y2] - counts_cum[x1 - 1][y2] - counts_cum[x2][y1 - 1] + counts_cum[x1 - 1][y1 - 1]


    def count_ev(x1, y1, x2, y2):
        return edges_v_cum[x2][y2] - edges_v_cum[x1][y2] - edges_v_cum[x2][y1 - 1] + edges_v_cum[x1][y1 - 1]


    def count_eh(x1, y1, x2, y2):
        return edges_h_cum[x2][y2] - edges_h_cum[x1 - 1][y2] - edges_h_cum[x2][y1] + edges_h_cum[x1 - 1][y1]


    vs = []
    e1 = []
    e2 = []

    counts_cum = cumsum_mat(S)
    for x1, y1, x2, y2 in XY:
        vs.append(count_v(x1, y1, x2, y2))
    del counts_cum

    edges_v = [[0] * M for _ in range(N)]
    for h, w in itertools.product(range(1, N), range(M)):
        edges_v[h][w] = S[h][w] & S[h - 1][w]
    edges_v_cum = cumsum_mat(edges_v)
    for x1, y1, x2, y2 in XY:
        e1.append(count_ev(x1, y1, x2, y2))
    del edges_v
    del edges_v_cum

    edges_h = [[0] * M for _ in range(N)]
    for h, w in itertools.product(range(N), range(1, M)):
        edges_h[h][w] = S[h][w] & S[h][w - 1]
    edges_h_cum = cumsum_mat(edges_h)
    for x1, y1, x2, y2 in XY:
        e2.append(count_eh(x1, y1, x2, y2))
    del edges_h
    del edges_h_cum

    ans = [v - e1 - e2 for v, e1, e2 in zip(vs, e1, e2)]
    print(*ans, sep='\n')


main()


Measured memory_bytes: 233556
X, Y = [int(x) for x in input().split()]
M = 10**9+7
if (X + Y) % 3:
  print(0)
else:
  x = X - (X+Y)//3
  y = Y - (X+Y)//3
  if x < 0 or y < 0:
    print(0)
  else:
    #print(x, y)
    #x+y c x
    #(x+y)!/x!/y!
    ans = 1
    for j in range(y):
      #print(j)
      #print(x+j+1, j+1)
      ans *= (x+j+1) * pow(j+1, -1, M)
      ans %= M
    print(ans)

Measured memory_bytes: 9136
import sys
n,m,x= map(int, sys.stdin.readline().rstrip("\n").split())
lines = [ [int(s) for s in line.split()] for line in sys.stdin ]

books = {}
num = 0
for a in range(2):
    for b in range(2):
        for c in range(2):
            for d in range(2):
                for e in range(2):
                    for f in range(2):
                        for g in range(2):
                            for h in range(2):
                                for i in range(2):
                                    for j in range(2):
                                        for k in range(2):
                                            for l in range(2):
                                                books[num] = [a,b,c,d,e,f,g,h,i,j,k,l]
                                                num += 1
price = -1
skill = {}
for i in range(2**12-1):
    price_ = 0
    for j in range (m):
        skill[j] = 0
    for j in range(n):
        if books[i+1][j] == 1:
            price_  += lines[j][0]
            for k in range(m):
                skill[k] = skill[k] + lines[j][k+1]
        for k in range(m):
            if skill[k] < x:
                break
        else:
            if price == -1:
                price = price_
            else:
                price = min(price, price_)
print(price)

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


int main(){
    long long n;
    cin >> n;
    vector<long long> a(3 * n);
    for (long long i = 0; i < 3 * n; i++) cin >> a.at(i);
    long long ans = 0;
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for (long long i = 0; i < 2 * n; i++){
        if (i % 2 != 0){
            //cout << a.at(i) << endl;
            ans = ans + a.at(i);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

long long n, a[200000], IT[1000000];

void Input()
{
    ios_base::sync_with_stdio(0);   cin.tie(0);

    cin >> n;
    for (int i=1; i<=n; i++)
        cin >> a[i];
    a[0] = a[n+1] = n + 1;
}

long long Max(int x, int y, int l, int r, int id)
{
    if (r < x || y < l) return -1;

    if (x <= l && r <= y) return IT[id];

    int mid = (l + r) / 2;

    return max(Max(x, y, l, mid, id*2), Max(x, y, mid+1, r, id*2+1));
}

long long pre(int l, int r, int val)
{
    while (r - l > 1)
    {
        int mid = (l + r) / 2,
            k = Max(mid, r-1, 1, n, 1);

        if (k > val) l = mid;
            else r = mid;
    }

    return l;
}

long long suf(int l, int r, int val)
{
    //cout << l << " " << r << endl;
    while (r - l > 1)
    {
        int mid = (l + r) / 2,
            k = Max(l+1, mid, 1, n, 1);

        //cout << l << " " << r << " " << k << " " << val << endl;

        if (k > val) r = mid;
            else l = mid;
    }

    return r;
}

void Update(int l, int r, int pos, int id)
{
    if (!(l <= pos && pos <= r)) return;

    if (l == r) IT[id] = a[pos];
        else
        {
            int mid = (l + r) / 2;

            Update(l, mid, pos, id*2);
            Update(mid+1, r, pos, id*2+1);

            IT[id] = max(IT[id*2], IT[id*2+1]);
        }
}

void Process()
{
    for (int i=1; i<=n; i++)
        Update(1, n, i, 1);

    long long res = 0;

    for (int i=1; i<=n; i++)
    {
        long long pre1 = pre(0, i, a[i]),
                  pre2 = pre(0, pre1, a[i]),
                  suf1 = suf(i, n+1, a[i]),
                  suf2 = suf(suf1, n+1, a[i]);

        //cout << pre2 << " " << pre1 << " " << suf1 << " " << suf2 << endl;

        res += a[i] * ((pre1 - pre2)*(suf1 - i) + (suf2 - suf1)*(i - pre1));
    }

    cout << res;
}

int main()
{
    Input();
    Process();
    return 0;
}


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

int main(){
	map<string, int> m;
	char c;
	string s;
	int n, nn = 0;
	while(cin >> n >> c >> s){m[s]++;}
	cout << m["A"] << endl;
	cout << m["B"] << endl;
	cout << m["AB"] << endl;
	cout << m["O"] << endl;
	return 0;
}

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

int main(){
    int n;
    long long k;
    cin>>n>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
    }
    map<int, int> arrive;
    vector<bool> checked(n,false);
    vector<int> route;
    int now=0;
    int count=0;
    while(count<k){
        if(checked[now]==true) break;
        checked[now]=true;
        arrive[now]=count;
        route.push_back(now);
        count++;
        now=a[now];
    }
    if(count==k) cout<<now+1<<endl;
    else{
        int cicle=count-arrive[now];
        cout<<route[arrive[now]+(k-count)%cicle]+1<<endl;
    }
}

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

int main() {
  int n, k;
  cin >> n >> k;

  vector<long long int> x(n);
  for(int i=0;i<n;i++) cin >> x[i];

  long long int ans = LLONG_MAX;

  for(int i=0;i<n-k+1;i++) {
    long long int closer = min(abs(x[i]), abs(x[i+k-1]));
    if(closer + x[i+k-1] - x[i] < ans) ans = closer + x[i+k-1] - x[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int r ,l, n,q,s[100000],t[50000],i,j,count=0,mid;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&s[i]);
  }

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }

  for(i=0;i<q;i++){
    l=0;
    r=n;
    while(l<r){
      mid = (l+r)/2;
      if(s[mid]==t[i]){
	count++;
	break;
      }
      else if(t[i]<s[mid]){
	r=mid;
      }
      else{
	l=mid+1;
      }
    }
  }

  printf("%d\n",count);

  return 0;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int val=s[s.size()-1]-'0';
	if(val==3) cout<<"bon\n";
	else if(val==0||val==1||val==6||val==8) cout<<"pon\n";
	else cout<<"hon\n";
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;

     signed main(){
      
      int n;
      cin>>n;
      int ans=0;
      for(int i=1;i<=n;i++){
           if(i%3!=0&&i%5!=0)ans+=i;
      }
      cout<<ans<<endl;

      }

        


Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

def main():
    s = input()
    t = input()

    s_len = len(s)
    t_len = len(t)
    dp = [[0]*(t_len + 1) for _ in range(s_len + 1)]

    # 最長共通部分列の長さを求めるDP配列を作る
    for i1 in range(1, s_len + 1):
        for i2 in range(1, t_len + 1):
            if s[i1 - 1] == t[i2 - 1]:
                dp[i1][i2] = dp[i1-1][i2-1] + 1
            else:
                dp[i1][i2] = max(dp[i1-1][i2], dp[i1][i2-1])
    #for k in range(s_len):
    #    print(dp[k])
    #print("--")
    # DP配列から最長共通部分列をもとめる。
    j1 = s_len
    j2 = t_len
    r = ""
    while j1 > 0 and j2 > 0:
        #print(j1, j2)
        if s[j1-1] == t[j2-1]:
            r += s[j1-1]
            j1 -= 1
            j2 -= 1
        elif dp[j1 - 1][j2] == dp[j1][j2]:
            j1 -= 1
        else:
            j2 -= 1
    print(r[::-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 111836
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		Set<Integer> T = new HashSet<Integer>();
		for(int i = 0; i < n; i++){
			T.add(sc.nextInt());
		}
		
		final int q = sc.nextInt();
		int count = 0;
		for(int i = 0; i < q; i++){
			final int t = sc.nextInt();
			
			if(T.contains(t)){
				count++;
			}
		}
		
		System.out.println(count);
	}
	
	public static class Scanner {
	    private BufferedReader br;
	    private StringTokenizer tok;

	    public Scanner(InputStream is) throws IOException {
	        br = new BufferedReader(new InputStreamReader(is));
	    }

	    private void getLine() throws IOException {
	        while (!hasNext()) { tok = new StringTokenizer(br.readLine()); }
	    }

	    private boolean hasNext() {
	        return tok != null && tok.hasMoreTokens();
	    }

	    public String next() throws IOException {
	        getLine(); return tok.nextToken();
	    }

	    public int nextInt() throws IOException {
	        return Integer.parseInt(next());
	    }
	    
	    public long nextLong() throws IOException {
	    	return Long.parseLong(next());
	    }
	    
	    public void close() throws IOException {
	        br.close();
	    }
	}

}

Measured memory_bytes: 23052
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;

int main(void)
{
    string w;
    cin >> w;
    map<char, int> mp;

    for(int i = 0; i < w.length(); i++)
    {
        mp[char(w[i])]++;
    }

    bool isBeautiful = false;
    for(auto m:mp)
    {
        if(m.second % 2 == 0)
            isBeautiful = true;
        else
        {
            isBeautiful = false;
            cout << "No" << endl;
            return 0;
        }
    }
    

    if(isBeautiful)
        cout << "Yes" << endl;    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};



signed main(){
  string w;cin>>w;

  map<char,int>c;
  for(int t=0;t<w.size();t++){
    c[w[t]]++;
  }

  for(char t='a';t<='z';t++){
    if(c[t]%2!=0){
      cout<<"No"<<endl;
      return 0;
    }
  }

  cout<<"Yes"<<endl;
  return 0;
}


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

const long long mod = 1000000007;

class BIT{
public:
    vector<long long> v;
    BIT(int _n) {
	int n = 1;
	while (n < _n) n *= 2;
	v.resize(n, 0);
    }
    void add(int p, long long val) {
	for (int t = p; t > 0; t -= (t & -t)) {
	    v[t] += val;
	}
    }
    long long query(int p) {
	long long ans = 0;
	for (int t = p; t < v.size(); t += (t & -t)) {
	    ans += v[t];
	}
	return ans;
    }
};

int main() {
    int n;
    while (cin >> n, n) {
	vector<int> nlist(n);
	int R;
	cin >> R;
	for (int i = 1; i <= n; i++) {
	    nlist[i - 1] = i;
	}
	while (R--) {
	    int a, b;
	    cin >> a >> b;
	    a--;
	    b--;
	    swap(nlist[a], nlist[b]);
	}
	BIT bit(n + 1);
	vector<long long> fact(n + 1, 1);
	for (int i = 1; i <= n; i++) {
	    fact[i] = (fact[i - 1] * i) % mod;
	}
	
	long long ans = 0;
	for (int i = 0; i < n; i++) {
	    int v = nlist[i] - (i - bit.query(nlist[i]));
	    if (v > 1) {
		ans = (ans + (v - 1) * fact[n - i - 1]) % mod;
	    }
	    bit.add(nlist[i], 1);
	}
	cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 5072
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */
int main()
{
	int		a,b,c,i=0,ans=0;

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



Measured memory_bytes: 2108
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	s := io.Next()
	if isPalindrome(s) && isPalindrome(s[:len(s)/2]) {
		io.Println("Yes")
	} else {
		io.Println("No")
	}
}

func isPalindrome(s string) bool {
	n := len(s)
	for i := 0; i < n/2; i++ {
		if s[i] != s[n-1-i] {
			return false
		}
	}
	return true
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1780
n, y = map(int, input().split())
discov_flg = False

for a in range(0, n + 1):
    for b in range(0, n + 1 - a):
        c = n - a - b
        total = 10000 * a + 5000 * b + 1000 * c
        if y == total:
            print(f"{a} {b} {c}")
            discov_flg = True
            break
    if discov_flg:
        break
        
if not(discov_flg):
    print("-1 -1 -1")

Measured memory_bytes: 9092
#include<cstdio>
#include<algorithm>
#include<utility>
#include<vector>

using namespace std;

int main(void){
    int N,K;
    scanf("%d %d",&N,&K);
    int H[N];
    for(int i = 0;i<N;i++){
        scanf("%d",&H[i]);
    }

    sort(H,H+N);

    long long int sum = 0;
    for(int i=0;i<N-K;i++){
        sum += H[i];
    }
    printf("%lld",sum);


    return 0;
}

Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main()
{
    int n,d,a,b,c=0,cnt = 0,i;
    cin>> n >> d ;
    for(i=1;i<=n;i++)
    {
        a = i - d ;
        b = i + d;
        c += b - a +1;
        cnt++;



        if(c >= n)
        {
            //cnt++;

         break;

        }
    }





    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
/*#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#pragma GCC target("avx2")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>

//#define int long long

#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define endl '\n'


using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

const double PI = acos((double)-1);
const double eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve() {
	int a, b, c, k; cin >> a >> b >> c >> k;
	if (a >= k) cout << k << endl;
	else if (a + b >= k) cout << a << endl;
	else cout << a - (k - (a + b)) << endl;
	return;
}

Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		
		int sum = k;
		int cnt = 1;
		for (int i = 0; ; i++) {
			if (sum >= n) {
				break;
			}
			sum += (k - 1);
			cnt++;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 49164
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define maxn 200001
#define f(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rf(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);i--)
#define pb(x) push_back((ll)(x))
#define pf(x) push_front((ll)(x))
#define nl cout << "\n";
 
//void ini(){
//	#ifndef ONLINE_JUDGE
//		freopen("input.txt","r",stdin);
//		freopen("output.txt","w",stdout);
//	#endif
//}

ll h[100001],dp[100001];

ll tab(ll n,ll k){
	dp[1]=0;
	f(i,2,n+1){
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		f(j,2,k+1){
			if(i-j<1){
				break;
			}

			dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
		}
	}

	return dp[n];
}

int main(){
	//ini();
	
	ll n,k;
	cin >> n >> k;
	f(i,1,n+1){
		cin >> h[i];
	}	

	cout <<tab(n,k);nl;

}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    int N;
    cin >> N;
    int ans = 0;
    REP0(i, N)
    {
        int a;
        cin >> a;
        while (a % 2 == 0)
        {
            a /= 2;
            ans++;
        }
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

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

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


ll eval(string s){
	ll ret = 0, sum = 0;
	//cout << s << endl;
	rep(i,s.length()){
		if( s[i] == '+' ){
			ret += sum;
			sum = 0;
		}else{
			sum *= 10;
			sum += s[i] - '0';
		}
	}
	ret += sum;
	return ret;
}

int main(){
	int N;
	ll ans=0;
	string S;

	cin >> S;
	N = S.length()-1;

	rep(k,1<<N){
		string t;
		rep(i,S.length()){
			t += S.substr(i,1) + (k&(1<<i)?"+":"");
		}
		ans += eval(t);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: i32,
    }

    let mut sunuke = vec![0; n];

    for i in 0..k {
        input!{
            num: i32,
            people: [usize; num]
        }
        for j in people {
            sunuke[j - 1] += 1;
        }
    }

    println!("{:?}", sunuke.into_iter().filter(|i| *i == 0).count());
}

Measured memory_bytes: 2160
using System;
using System.Linq;

public class Hello
{
    public static void Main()
    {
       
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int A = a[0];
        int B = a[1];
        int C = a[2];
        if(B >= A * C) Console.WriteLine(C);
        else Console.WriteLine(B / A);
        
    }
}

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

int n;
double a[3003];
double dp[3003][3003];
double rec(int i=0,int cnt=0)
{
    if(i==n && cnt>n/2)
        return 1;
    if(i==n)
        return 0;
    if(dp[i][cnt]==dp[i][cnt])
        return dp[i][cnt];
    double head=0,tail=0;
    head = a[i]*rec(i+1,cnt+1);
    tail = (1.0-a[i])*rec(i+1,cnt);
    return dp[i][cnt] = head+tail;
}

int main()
{
    memset(dp,-1,sizeof dp);
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> a[i];
    cout << setprecision(10) << fixed << rec();
    return 0;
}

Measured memory_bytes: 71040