akhauriyash/Code-Regression huggingface dataset:
#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)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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

/*（๑•﹏•๑｀) */

int main() {
    ll N;
    vector<ll> A(5);
    cin >> N;
    int miniin = -1;
    ll mini = 1e15 + 2;

    REP(i,5){
        cin >> A[i];
        if (chmin(mini,A[i])){
            miniin = i;
        }
    }

    ll ans =  4 + ((N + (mini - 1)) / mini);
    cout << ans << "\n";

}

// a/b 切り上げ
// (a + (b - 1)) / b

Measured memory_bytes: 256
//  Copyright © 2020 Diego Garcia Rodriguez del Campo. All rights reserved.
#include<bits/stdc++.h>
#define MAX 200005
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
using namespace std;
typedef long long i64;

const i64 INF = 1e6;
i64 N, M, a[MAX], suf[MAX], sum;

i64 solve( i64 x ) {
    i64 par = 0;
    sum = 0;
    for( i64 i = 1; i <= N; i ++ ) {
        if( a[i] + a[N] < x )
            continue;
        i64 l = 1;
        i64 r = N;
        while( l < r ) {
            i64 m = ( l + r ) / 2;
            if( a[i] + a[m] >= x )
                r = m;
            else
                l = m + 1;
        }
        par += N - l + 1;
        sum += ( N - l + 1 ) * a[i];
        sum += suf[l];
        
    }
    return par;
}

int main()
{
    optimiza_io
    cin >> N >> M;
    for( i64 i = 1; i <= N; i ++ )
        cin >> a[i];
    
    sort( a + 1 , a + N + 1 );
    
    for( i64 i = N; i >= 1; i -- )
        suf[i] = suf[i + 1] + a[i];
    
    i64 l = 0, r = INF;
    while( l < r ) {
        i64 m = ( l + r + 1 ) / 2;
        if( solve( m ) >= M )
            l = m;
        else
            r = m - 1;
    }
    
    i64 K = solve( l );
    sum -= ( K - M ) * l;
    cout << sum << "\n";
    
    return 0;
}

// CHECAR LIMITES 

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

char given_string[3];
char days[7][4] = {"SAT","FRI","THU","WED","TUE","MON","SUN"};

int main() {
  scanf("%s", given_string);
  for (size_t i = 0; i < 7; i++) {
    if (strcmp(days[i], given_string) == 0) printf("%d", i + 1);
  }
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define FORR(i,a,b) for (int i = b - 1; i >= a; --i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,0,n)

int main() {
	int a;
	cin >> a;
	cout << a * a * a + a * a + a << endl;
	return 0;
}

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

#define ld long double

double prob[305][305][305]={}, ev[305][305][305] = {};
int main(){
	int n;
	cin>>n;
	
	int cnt[4] = {};
	for(int i = 0; i<n; i++){
		int x;
		cin>>x;
		cnt[x]++;
		}
	
	prob[cnt[1]][cnt[2]][cnt[3]] = 1;
	//cout<<"check "<<prob[0][0][0]<<endl;
	//fd ev[cnt[1]][cnt[2]][cnt[3]] = {};
	for(int c = cnt[3]; c>=0; c--){
		for(int b = cnt[2] + cnt[3]; b>=0; b--){
			for(int a = cnt[1] + cnt[2] + cnt[3]; a>=0; a--){
				if(a + b + c > n)
					continue;
				if(a==0 && b==0 && c== 0)
					continue;
				ld temp = (double)n/(a+b+c);
				//cout<<a <<" "<<b<<" " <<c<<" " <<temp<<endl;
				//ev[a][b][c] += temp * prob[a][b][c];
				//temp *= p[a][b][c];
				//ev[a][b][c] += temp;
				if(a!= 0){
						ld p_go = (double) a/(a+b+c);
						prob[a-1][b][c] += prob[a][b][c] * p_go;
						ev[a-1][b][c] += (temp * prob[a][b][c] + ev[a][b][c]) * p_go;
					}
				if(b!=0){
						ld p_go = (double) b/(a+b+c);
						prob[a+1][b-1][c] += prob[a][b][c] * p_go;
						ev[a+1][b-1][c] += (temp * prob[a][b][c] + ev[a][b][c])  * p_go ;
					}
				if(c!= 0){
						ld p_go = (double) c/(a+b+c);
						prob[a][b+1][c-1] += prob[a][b][c] * p_go;
						ev[a][b+1][c-1] += (temp* prob[a][b][c] + ev[a][b][c])  * p_go ;
					}
				}
			}
		
		}
	cout<<fixed << setprecision(10)<<ev[0][0][0]<<endl;
	
	
	
	return 0;
	}


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

int main() {
  char b;
  cin >> b;
  
  if(b == 'A') cout << 'T' << endl;
  else if(b == 'C') cout << 'G' << endl;
  else if(b == 'G') cout << 'C' << endl;
  else cout << 'A' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;



int main(){
    ll N;
    cin>>N;
    ll Key=26;
    ll Keta=1;
    while(Key<N){
        N-=Key;
        Key*=26;
        Keta++;
    }
	string S="abcdefghijklmnopqrstuvwxyz";
  	//cout<<N<<endl;
  	//cout<<Key/26<<endl;
    Key/=26;
  	if(N==0){
      	rep(i, Keta-1){
          	cout<<'z';
        }
      	return 0;
    }
  	N--;
    rep(i, Keta){
        ll J=N/Key;
        N%=Key;
       	cout<<S.at(J);
      	Key/=26;
    }
}
     

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define re register
#define int long long
inline int read(){
	re int t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int n,a,b,ans,ans1,c,d;
signed main(){
	n=read();
	a=read();
	b=read();
	if(a>b)swap(a,b);
	if((a&1)==(b&1)){
		printf("%lld",(b-a)/2);
	}
	else{
		c=a;
		d=b;
		d-=a;
		ans+=a;
		ans+=d/2;
		d=b;
		a+=(n-b+1);
		ans1+=n-b+1;
		ans1+=(n-a)/2;
		if(ans1<ans)printf("%lld",ans1);
		else printf("%lld",ans);}
}


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

ls = [0] + A + [0]

ls2 = [0] * (N+1)
for n in range(N+1):
  ls2[n] = abs(ls[n+1]-ls[n])

sum_ls2 = sum(ls2)
for n in range(N):
  print(sum_ls2 - ls2[n] - ls2[n+1] + abs(ls[n+2]-ls[n]))

Measured memory_bytes: 14048
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ITP1_3B
{
    class Program
    {
        static void Main(string[] args)
        { 
            int count = 0;

            while(true) {
                int inInt = int.Parse(Console.ReadLine());
                if (inInt == 0) break;
                count++;
                Console.WriteLine("Case " + count + ": " + inInt);
            }
        }
    }
}

Measured memory_bytes: 9428
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var a = IntStream.range(0, n).map(i -> sc.nextInt()).toArray();
		sc.close();

		var count = 0;
		for (var i = 0; i < n; i++) {
			if ((i + 1) % 2 == 1 && a[i] % 2 == 1) {
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 36296
// template version 1.12
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i, n) {
    cin>>a[i];
  }
  dump(a);

  vi l(n);
  vi r(n);

  l[0] = a[0];
  r[n-1] = a[n-1];
  rep(i, 1, n){
    l[i] = max(l[i-1], a[i]);
  }
  rrep(i, 0, n-1){
    r[i] = max(r[i+1], a[i]);
  }
  dump(l);
  dump(r);

  cout << r[1] << endl;
  rep(i, 1, n-1){
    cout << max(l[i-1], r[i+1]) << endl;
  }
  cout << l[n-2] << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, m, l;
long long a[100][100], b[100][100], c[100][100];
cin >> n >> m >> l;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++) cin >> a[i][j];
for(int i = 0; i < m; i++)
 for(int j = 0; j < l; j++) cin >> b[i][j];
for(int i = 0; i < n; i++){
 for(int j = 0; j < l; j++){
  c[i][j] = 0;
  for(int k = 0; k < m; k++){
   c[i][j] += a[i][k]*b[k][j];
  }
 }
}
for(int i = 0; i < n; i++){
 for(int j = 0; j < l; j++){
  if ( j ) cout << " ";
  cout << c[i][j];
  }
 cout << endl;
 }
return 0;
}

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

int main(){
	ll N;
	cin>>N;
	ll h,w;
	ll n;
	for(h=1;h<=3500;h++){
		for(w=1;w<=3500;w++){
			ll a=N*h*w;
			ll b=4*h*w-N*(w+h);
			if(b!=0&&a%b==0&&a/b>0&&a/b<=3500){
				cout<<h<<" "<<w<<" "<<a/b<<endl;
				return 0;
			}
		}
	}
}

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

typedef struct {
	size_t n, c;
	int *arr;
} list;

void add(list *l, int x) {
	if (l->n+1 > l->c) {
		l->c = l->c*2 + !l->c;
		l->arr = realloc(l->arr, l->c * sizeof *l->arr);
	}
	l->arr[l->n++] = x;
}

int seenx[100000], seeny[100000];
list lstx[100000], lsty[100000];
long long int cntx, cnty;

void dfs(int i, long long int* cnt, long long int* cntb, int* seen, int* seenb, list *lst, list *lstb) {
	seen[i] = 1;
	(*cnt)++;
	for (size_t j = 0; j < lst[i].n; j++) {
		int k = lst[i].arr[j];
		if (seenb[k]) continue;
		dfs(k, cntb, cnt, seenb, seen, lstb, lst);
	}
}

int main(void) {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		add(&lstx[x-1], y-1);
		add(&lsty[y-1], x-1);
	}

	long long int cnt = -n;
	for (int i = 0; i < 100000; i++) {
		if (seenx[i] || lstx[i].n == 0) continue;
		cntx = cnty = 0;
		dfs(i, &cntx, &cnty, seenx, seeny, lstx, lsty);
		cnt += cntx * cnty;
	}

	for (int i = 0; i < 100000; i++) {
		free(lstx[i].arr);
		free(lsty[i].arr);
	}

	printf("%lld\n", cnt);
}


Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<int64_t,int64_t> pll;
typedef vector<int64_t> vl;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
const long double PI = acos(-1);
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define ALL(a) begin(a),end(a)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

string N;ll K,n;

ll nCr(ll nn,ll r){
    if(r>n)return 0;
    if(r==1)return nn;
    if(r==2)return nn*(nn-1)/2;
    if(r==3)return nn*(nn-1)*(nn-2)/6;
    return 0;
}

ll dp(ll i,ll k,bool smaller){
    if(k==0)return 1;
    else if(i==n)return 0;

    if(smaller)return nCr(n-i,k)*pow(9,k);
    else {
        if (N[i] == '0') return dp(i+1, k, false);
        else {
            long long zero = dp(i+1, k, true);
            long long aida = dp(i+1, k-1, true) * (N[i] - '1');
            long long icchi = dp(i+1, k-1, false);
            return zero + aida + icchi;
        }
    }
}

void solve() 
{
    cin>>N>>K;
    n=N.size();
    cout<<dp(0,K,0)<<endl;
}

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


Measured memory_bytes: 512
# https://atcoder.jp/contests/abc112/tasks/abc112_b

N, T = map(int, input().split())

cts = [list(map(int, input().split())) for _ in range(N)]


cs = []
for ct in cts:
    if ct[1] <= T:
        cs.append(ct)

if len(cs) == 0:
    print("TLE")
    exit()

ans = 1000

for c in cs:
    ans = min(ans, c[0])

print(ans)



Measured memory_bytes: 3060
def main():
    mod, pow3, p = 2**31-1, [1]*200001, 1
    i3 = pow(3, mod-2, mod)
    for i in range(1, 200001):
        pow3[i] = p = p*3 % mod

    def rolling_hash(seq):
        h = sum([(i+1)*j for i, j in zip(seq, pow3[:-1])]) % mod
        H0s = [0]*n
        for i, j in enumerate(seq):
            H0s[i] = h
            h = (h-j-1+(j+1)*pn)*i3 % mod
        return H0s

    n = int(input())
    a, b = list(map(int, input().split())), list(map(int, input().split()))
    pn, memo = pow3[n], []

    a1 = [a[i-1] ^ a[i] for i in range(n)]
    b1 = [b[i-1] ^ b[i] for i in range(n)]
    b_hash = sum([(i+1)*j for i, j in zip(b1, pow3[:-1])]) % mod
    A1 = rolling_hash(a1)
    for i, j in enumerate(A1):
        if j == b_hash:
            memo.append(i)
    b0 = b[0]
    for i in memo:
        x = b0 ^ a[i]
        print(i, x)


main()


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

using namespace std;


void solve()
{
    vector<int>test(5);
    for(int i = 0; i < 5; ++i)
    {
        cin >> test[i];
        if(test[i] == 0)
        {
            cout << i+1 << endl;
            break;

        }
    }
}





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


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
signed main()
{
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 2 == 0) {
            continue;
        }
        int cnt = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) {
                cnt ++;
            }
        }
        if (cnt == 8) {
            ans ++;
        }
    }
    put(ans)
    return 0;
}

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

#define ll long long
#define pb push_back
#define mp make_pair


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char ch;
    cin>>ch;
    if(ch>=97 && ch<=122)
    cout<<'a';
    else if(ch>=65 && ch<=90)
    cout<<'A';
		
	
}


Measured memory_bytes: 3604
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[][]A = new int[M][];
		var listA = new HashSet<int>[N];
		for(var i=0;i<N;i++){
			listA[i] = new HashSet<int>();
		}
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i] = new int[2]{int.Parse(str2[0]),int.Parse(str2[1])};
			listA[A[i][0]-1].Add(A[i][1]);
		}
		string[] str3 = Console.ReadLine().Split();
		int S = int.Parse(str3[0]);
		int T = int.Parse(str3[1]);
		var list = new HashSet<int>();
		list.Add(S);
		int[]C = new int[N];
		C[S-1] = 1;
		int ans = 0;
		while(list.Count>0){
			ans++;
			var list2 = new HashSet<int>(list);
          	var list3 = new HashSet<int>();
			list.Clear();
			bool flag = false;
			bool flag2 = false;
			foreach(var i in list2){
				foreach(var j in listA[i-1]){
					list3.Add(j);
				}
            }
          	var list4 = new HashSet<int>();
			foreach(var i in list3){
				foreach(var k in listA[i-1]){
					list4.Add(k);
				}
			}
        	var list5 = new HashSet<int>();
			foreach(var i in list4){
				foreach(var l in listA[i-1]){
					if(C[l-1]==0){
						list.Add(l);
						C[l-1]=1;
						flag = true;
						if(l==T){
							flag2 = true;
							break;
						}
					}
				}
              	if(flag2){
                  break;
                }
			}
			if(flag2){
				break;
			}
			if(!flag){
				ans = -1;
				break;
			}
		}
		Console.WriteLine(ans);
	}
}


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

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int sum = 0;
  int cnt = 0;
  x -= (z * 2);
  while (true) {
    sum += y;
    cnt++;
    if ((x - sum) >= y + z) {
      sum += z;
    } else {
      break;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;


int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<int> ans;
    vector<int> balls(n+1);
    for (int j = n; j >= 1; --j) {
        int cnt = v[j-1];
        for (int k = 2*j; k <= n; k += j) {
            cnt ^= balls[k];
        }
        balls[j] = cnt;
        if(cnt) ans.emplace_back(j);
    }
    reverse(ans.begin(),ans.end());
    cout << ans.size() << "\n";
    for (int i = 0; i < ans.size(); ++i) {
        if(i) cout << " ";
        cout << ans[i];
    }
    puts("");
    return 0;
}

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CompetitiveProg
{
    class Program
    {
        static int w, h;
        static int[,] room;
        static bool[,] roomVisited;
        static int count;
        static void Main(string[] args)
        {
            var ans = new List<int>();
            while(true)
            {
                count = 0;
                var wh = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                if (wh[0] == 0 && wh[1] == 0) break;
                w = wh[0]; h = wh[1];
                room = new int[w, h];
                roomVisited = new bool[w, h];
                int[] start = new int[2];
                for (int j = 0; j < h; j++)
                {
                    var row = Console.ReadLine();
                    var i = 0;
                    foreach (var r in row)
                    {
                        switch (r)
                        {
                            case '.':
                                room[i, j] = 1;
                                break;
                            case '#':
                                room[i, j] = 0;
                                break;
                            case '@':
                                room[i, j] = 1;
                                start = new[] { i, j };
                                break;
                        }
                        i++;
                    }


                }
                for (int i = 0; i < w; i++)
                {
                    for (int j = 0; j < h; j++)
                    {
                        roomVisited[i, j] = false;
                    }
                }
                dfs(start[0], start[1]);
                ans.Add(count);
            }
            foreach (var c in ans)
            {
                Console.WriteLine(c);
            }
            

        }
        static void dfs(int startx,int starty)
        {
            if (roomVisited[startx, starty]) return;
            roomVisited[startx, starty] = true;
            count++;
            if ((startx - 1 >= 0) && room[startx - 1, starty]==1)
            {
                dfs(startx - 1, starty);
            }
            if ((starty - 1 >= 0)&& room[startx , starty-1]==1)
            {
                dfs(startx, starty-1);
            }
            if ((startx + 1<w)&& room[startx + 1, starty]==1)
            {
                dfs(startx + 1, starty);
            }
            if ((starty + 1 < h) && room[startx , starty+1] == 1)
            {
                dfs(startx, starty+1);
            }
        }
       
    }
}

Measured memory_bytes: 6040
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

            int a, b, n;
            int[] ps;
            GetInput(out n, out a, out b, out ps);
            Console.WriteLine(Solve(a, b, ps));
        }

        static void GetInput(out int n,out int a,out int b,out int[] ps)
        {
            n = int.Parse(Console.ReadLine());
            var items = Console.ReadLine().Split(' ');
            a = int.Parse(items[0]);
            b = int.Parse(items[1]);
            ps = Console.ReadLine().Split(' ').Select(item => int.Parse(item)).ToArray() ;
        }

        static int Solve(int a,int b,int[] ps)
        {
            int count1 = 0, count2 = 0, count3 = 0;
            for (int i = 0; i < ps.Length; i++)
            {
                if (ps[i] <= a)
                {
                    count1++;
                }
                else if(ps[i]<=b)
                {
                    count2++;
                }
                else
                {
                    count3++;
                }
            }
            return Math.Min(count1, Math.Min(count2, count3));
        }


    }
}


Measured memory_bytes: 13268
import sys
input = sys.stdin.readline
class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
    
    def make(self, list):
        self.tree[1:] = list.copy()
        for i in range(self.size+1):
            j = i + (i & (-i))
            if j < self.size+1:
                self.tree[j] += self.tree[i]
 
    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # 総和がx以上になる位置のindex をbinary search
    def bsearch(self,x):
        le = 0
        ri = 1<<(self.size.bit_length()-1)
        while ri > 0:
            if le+ri <= self.size and self.tree[le+ri]<x:
                x -= self.tree[le+ri]
                le += ri
            ri >>= 1
        return le+1

n,q = map(int,input().split())
a = list(map(int,input().split()))
bit = BIT(n)
bit.make(a)
for i in range(q):
    t,l,r = map(int,input().split())
    if t == 0:
        bit.add(l,r)
    else:
        print(bit.sum(r)-bit.sum(l))

Measured memory_bytes: 65052
#include <stdio.h>
#include <math.h>
 
typedef struct{ 
    double x,y;
}Point;
void koch(int, Point, Point);
 
int main() {
    Point a,b;
    int n;
     
    scanf("%d",&n);
     
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;
     
    printf("%.8f %.8f\n",a.x,a.y);
    koch(n,a,b);
    printf("%.8f %.8f\n",b.x, b.y);
     
    return 0;
}
 
void koch(int n, Point a, Point b){
    Point s,t,u;
    double th;
    if(n==0) return;
    th = M_PI * 60.0/180.0;
     
    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
     
    koch(n-1,a,s);
    printf("%.8f %.8f\n", s.x, s.y);
    koch(n-1,s,u);
    printf("%.8f %.8f\n", u.x, u.y);
    koch(n-1,u,t);
    printf("%.8f %.8f\n", t.x, t.y);
    koch(n-1,t,b);
}

Measured memory_bytes: 640
import math
a,b=map(int,input().split())
gcd=math.gcd(a,b)

def prime_factorization(n):
  i=2
  prime=[]
  while i*i<=n:
    if n%i:
      i+=1
    else:
      n//=i
      prime.append(i)
      while n%i==0:
        n//=i
  if n>1:
    prime.append(n)
  return prime

print(len(prime_factorization(gcd))+1)
#print(prime_factorization(gcd))

Measured memory_bytes: 9168
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    double reciprocal = 0;
    rep(i,n){
        reciprocal += (double)(1.0/a[i]);
    }
    double ans = 1.0/reciprocal;

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

Measured memory_bytes: 256
// Vicfred
// https://atcoder.jp/contests/abc153/tasks/abc153_c
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main() {
    long n, k;
    readf("%s %s", &n, &k);
    readln;

    long[] h = readln.split.map!(to!long).array;
    h.sort!("a > b");

    if(k >= n)
        0.writeln;
    else
        sum(h[k..$]).writeln;
}



Measured memory_bytes: 10992
S = input()
List = []
for i in range(len(S)):
  tmp = S[i]
  List.append(tmp)
List = list(set(List))
num2alpha = lambda c: chr(c+96)
for k in range(1,27):
  if(num2alpha(k) in List):
    pass
  else:
    print(num2alpha(k))
    exit()
print("None")

Measured memory_bytes: 3956
#include<bits/stdc++.h>
#define GLX glx ak!!
#define ZZH zzh ak!!
#define LYH lyh ak!!
#define XRY xry ak!!
#define ZJH zjh ak!!
#define HP hp ak!!
#define WXH wxh ak!!
#define JIRY jiry good teacher
#define ll long long
using namespace std;
int n,ans,x,f[110];
bool vis[110];
inline void dfs(int x){
    if(x>12){
        int ret=24;
        for(int i=0;i<=23;i++)
            for(int j=i+1;j<=23;j++)
                if(vis[i]&&vis[j]) ret=min(ret,min(j-i,24-j+i));
        ans=max(ans,ret);
        return ;
    }
    if(f[x]==2){
		vis[x]=vis[24-x]=1;
		dfs(x+1);
		return;
	}
	if(f[x]){
        vis[x]=1;
		dfs(x+1);
		vis[x]=0;
        if(x){
        	vis[24-x]=1;
			dfs(x+1);
			vis[24-x]=0;
    	}
		return ;
	}
    dfs(x+1);
	return;
}
int main(){
    scanf("%d",&n);
    f[0]=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		f[x]++;
	}
	if(f[12]>1||f[0]>1){puts("0");return 0;}
    for(int i=1;i<=12;i++) if(f[i]>2){puts("0");return 0;}
    dfs(0);
    printf("%d",ans);
    return 0;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	int n, k;
	cin >> n >> k;
	int arr[n];
	for(int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	sort(arr, arr + n);
	int sum = 0;
	for(int i = 0; i < k; i++) {
		sum += arr[i];
	}
	cout << sum << "\n";
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main()
{
	// a, b, c, d, e
	// f, g, h, i, j
	// k, l, m, n, o
	// p, q, r, s, t
	// u, v, w, x, y
	// z
	bool alp[26] = { 0, 0, 0, 0, 0,
					 0, 0, 1, 1, 1,
					 1, 1, 1, 1, 1,
					 1, 0, 0, 0, 0,
					 1, 0, 0, 0, 1,
					 0 };
	string str;
	while (cin >> str, str != "#") {
		bool prev = alp[str[0] - 'a'];
		int ans = 0;
		REP(i, 1, str.size()) {
			bool now = alp[str[i] - 'a'];
			if (prev != now) ans++;
			prev = now;
		}

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

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

#define ll long long

int main() {
    ll l,r;
    cin >> l >> r;
    r=min(r,l+2019);
  
    ll res = 2018;
    for (ll i = l; i <= r; ++i)
    {
        for (ll j = i + 1; j <= r; ++j)
        {
            res = min(res, (i * j) % 2019);
        }
    }
    cout<<res;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n;
  cin>>n;
  long long ar[n],ar1[n];
  for(int i=0;i<n;i++)
  {
  cin>>ar[i];
  ar1[i]=ar[i];
  }
  int f=0;
  for(int i=0;i<n-1;i++)
  {
  	if(ar[i]!=ar[i+1])
  	{f=1;break;}
  }
  sort(ar,ar+n);
  if(f==0)
  {
  	for(int i=0;i<n;i++)
  	cout<<ar[n-1]<<endl;;
  }
  else
  {
  	for(int i=0;i<n;i++)
  	{
  		if(ar1[i]!=ar[n-1])
  		cout<<ar[n-1]<<endl;
  		else
  		cout<<ar[n-2]<<endl;
  	}
  	//cout<<ar[n-1]<<endl<<q;
  }
  return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
//#define INF 1000000000000 //10^12:極めて大きい値,∞
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string n;

    cin >> n;
    
    if(n == "ABC")cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)

#define INF 1000000001
#define MOD 1000000007
#define INF64 1000000000000000001

#define F first
#define S second

#define Pii pair<SINT32,SINT32>
#define Pll pair<SINT64,SINT64>


using namespace std;

int main() {

	string s;
	cin >> s;
	SINT32 ans = s.length();
	
	rep(i,1,s.length()) {
		if (s[i] != s[i-1]) {
			ans = MIN(ans,MAX(i,s.length()-i));
		}
	}

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

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());	//ソート後に使用

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));	//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();	//key以上を探す
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/
/* 文字列合成
	string N,M;
	cin >> N >> M;
	SINT64 ans = 0;
	ans = stoi(N+M);
*/



/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}

	//全表示
    set<string>::iterator it; //  イテレータを用意
    for(it = DATA.begin(); it != DATA.end(); it++) {
        cout << *it << endl;
    }

	//N番目を一部表示
	set<string>::iterator it; //  イテレータを用意
	it = DATA.begin();
	rep (i,0,N) {
		it++;
	}
	cout << *it << endl;
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 512
#include<iostream>
int main(){while(1){int s[6],g[4]={0},n=-2,v=0,i;for(i=5;i;i--){std::cin>>s[i];if(!s[5])goto l;if(!g[s[i]]){n++;g[s[i]]=1;if(v-1==s[i]%3||!v)v=s[i];}}for(i=5;i;i--)std::cout<<(!n?(v==s[i]?1:2):3)<<"\n";}l:;return 0;}

Measured memory_bytes: 1160
import numpy as np

n = int(input())
a = np.array(list(map(int,input().split())), dtype=int)
b = np.zeros(n, dtype=int)

for i in range(n-1, -1, -1):
    m = sum(b[i::i+1]) % 2
    b[i] = (a[i] + m) % 2
bsum =sum(b) 
if bsum == 0:
    print(bsum)
else:
    ans = np.where(b>0)[0] + 1
    ans = ans.astype('str')
    print(bsum)
    print(' '.join(ans))

Measured memory_bytes: 54728
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int N;
	cin >> N;
	vector<ll> a(N);
	rep(i, N) cin >> a[i];
	int tmp = 0;
	rep(i, N-1) {
		tmp ^= a[i];
	}
	if (tmp == a[N-1]) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;
}



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


int main(){

  string  s;
  cin >> s;
  if(s=="SSS")cout<<0;
  else if(s=="SSR")cout<<1;
  else if(s=="SRS")cout<<1;
  else if(s=="SRR")cout<<2;
  else if(s=="RRS")cout<<2;
  else if(s=="RSR")cout<<1;
  else if(s=="RRR")cout<<3;
  else if(s=="RSS")cout<<1;
  
    return 0;
}

Measured memory_bytes: 3548
/* {{{ */
use std::io::*;
use std::str::FromStr;

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(r: R) -> Scanner<R> {
        Scanner { reader: r }
    }
    fn read<T: FromStr>(&mut self) -> T {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok().unwrap()
    }
}
/* }}} */

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let s = sc.read::<String>().chars().collect::<Vec<char>>();
    let q: usize = sc.read();
    let mut vl = Vec::new();
    let mut vr = Vec::new();
    let mut flg = true;
    for _ in 0..q {
        let t: usize = sc.read();
        if t == 1 {
            flg = !flg;
        } else {
            let f: usize = sc.read();
            let s: char = sc.read::<String>().chars().next().unwrap();
            if f == 1 {
                if flg { vl.push(s); }
                else   { vr.push(s); }
            } else {
                if flg { vr.push(s); }
                else   { vl.push(s); }
            }
        }
    }
    vl.reverse();
    let it = vl.iter().chain(s.iter()).chain(vr.iter());
    if flg {
        print!("{}", it.cloned().collect::<String>());
    } else {
        print!("{}", it.rev().cloned().collect::<String>());
    }
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 6652
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    ll a,b,c;
    cin>>a>>b>>c;
    if(a%2==0 || b%2==0 || c%2==0)
    cout<<0;
    else
    {
        cout<<min(a*b,min(b*c,a*c));
    }
    
  }  
  return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    int ans = 0;
    int num = 0;
    for (int i = 1; i <= N; i++) {
        int count = 0;
        int tmp = i;
        while (tmp % 2 == 0) {
            count++;
            tmp /= 2;
        }

        if (num <= count) {
            num = count;
            ans = i;
        }
    }

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

Measured memory_bytes: 256
//  RAKSHIT KADAM
//ALWAYS USE &IT FOR ITERATING USING AUTO ...
//USE COUNT(STARTING ADDRESS, ENDING ADRESS ,VALUE) FOR FINDING THE COUNT IN THE RESPECTIVE DATA STRUCTURE
//NOTE THAT MEMSET CANT ASSIGN A VALUE OF 10^18 IT WILL ASSIGN A LOWER VALUE THAN THAT!!!
 #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// #define ordered_set tree< int ,  null_type ,  less<int> ,  rb_tree_tag ,  tree_order_statistics_node_update>
#warning !!!check the size of arrayss!!!

// NUMERIC DEFINITIONS :
    #define INF 2000000000000000005
    #define MOD  1000000007
    #define newMOD  998244353
    #define MAX 300006
    #define pi 3.1415926535897932384626433832795
 #define ll long long
 #define int long long
 #define P(gg) for(auto rax:gg){cout<<rax<<" ";}cout<<endl;
 #define Need_for_speed(activated) ios_base :: sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
 #define satisfy ll t; cin>> t; while(t--)
 #define inp(n) int n;cin >> n
 #define mp make_pair
 #define pb push_back
 #define endl "\n"
 #define x first
 #define y second
 #define fore(i,a,b) for(ll i=a;i<b;i++)
 #define forci(i,n) for(ll i=0;i<n;i++)
 #define vi vector<ll>
 #define Endl endl
 #define lb lower_bound
 #define ub upper_bound
#define pii pair<ll,ll>
 #define input freopen("input.txt", "r", stdin),freopen("output.txt", "w", stdout)
 #define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
//ll gcd(ll a, ll b){if (b == 0)return a;return gcd(b, a % b);}n..
//int power(int x, unsigned int y, unsigned int m){ if (y == 0) return 1;int p = power(x, y/2, m) % m;  p = (p * p) % m;                                                  return (y%2 == 0)? p : (x * p) % m;}
//ll modInverse(int a, int m){int g = gcd(a, m); { return power(a, m-2, m);}}


void solve()
{
    
    ll a,b,c,k;cin>>a>>b>>c>>k;
    ll ans=0;
    if(a<k)
    {
        ans+=a;k-=a;
        if(k<b)
        {
            cout<<ans<<endl;
           
        }
        else
                   {
                       cout<<ans-k+b<<endl;
                   }
    }
    else
    {
        cout<<k<<endl;
    }
}
signed main()
{
 
    Need_for_speed(activated);
//satisfy
//    {
//   solve();
//    }

 solve();
    return 0;
}



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

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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
int a[20][20],n,d;
bool check(int x,int y){
    ll res = 0;
    for(int i = 0;i < d; ++i){
        res += (a[x][i]-a[y][i])*(a[x][i]-a[y][i]);
    }
    ll tep = sqrt(res*1.0);
    return tep*tep == res;
}
int main(){
    cin >> n >> d;
    for(int i = 0;i < n; ++i)
        for(int j = 0;j < d; ++j) 
            cin >> a[i][j];
    int num = 0;
    for(int i = 0;i < n; ++i){
        for(int j = i+1;j < n; ++j){
            if(check(i,j)) num++;
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    double xp = ((x1 * x1 + y1 * y1) * (y2 - y3) + (x2 * x2 + y2 * y2) * (y3 - y1)
      + (x3 * x3 + y3 * y3) * (y1 - y2)) / (2 * (x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)));
    double yp = ((x1 * x1 + y1 * y1) * (x2 - x3) + (x2 * x2 + y2 * y2) * (x3 - x1)
      + (x3 * x3 + y3 * y3) * (x1 - x2)) / (2 * (y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2)));
    double a = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
    double b = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
    double c = sqrt((x3 - x2) * (x3 - x2) + (y3 - y2) * (y3 - y2));
    double r = a * b * c / (sqrt((a + b + c) * (-a + b + c) * (a - b + c) * (a + b - c)));
    cout << fixed << setprecision(3) << xp << " " << yp << " " << r << endl;
  }
}

Measured memory_bytes: 1292
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9; 
const int N = 6e5+5;                                         
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}

int main () {
	SpeedForce;
	
	int n;
	cin >> n;
	cout << !n;
	
	return Accepted;
}

// B...a


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

const int INF = (1 << 30) - 1;

template < typename T > inline void chmin ( T &a, T b ) { a = min(a, b); }

int N;
int C[1006], W[1006];
int sumW[1006] = {};
int rangeLeft[1006], rangeRight[1006];
int memo[1005][1005][2];

int isHave ( int pos, int range, int dir )
{

	if ( memo[pos][range][dir] == -1 ) { 

		if ( range == 1 ) {
			return ( true );
		}

		if ( dir == 0 && pos + range - 1 > N ||
			 dir == 1 && pos - range + 1 < 1 )
		{
			return ( false );
		}

		int val;
		if ( dir == 0 ) {
			val = sumW[pos + range - 1] - sumW[pos];
		} else {
			val = sumW[pos - 1] - sumW[pos - range];
		}
		if ( val > C[pos] ) {
			return ( false );
		}
		
		if ( dir == 0 ) {
			memo[pos][range][dir] = (isHave(pos + 1, range - 1, 0) || isHave(pos + range - 1, range - 1, 1));
		} else {
			memo[pos][range][dir] = (isHave(pos - range + 1, range - 1, 0) || isHave(pos - 1, range - 1, 1));
		}

	}

	return ( memo[pos][range][dir] );
}

int main()
{
	memset(memo, -1, sizeof(memo));
	cin >> N;
	for ( int i = 1; i <= N; i++ ) {
		cin >> C[i] >> W[i];
		sumW[i] += W[i] + sumW[i - 1];
	}

	for ( int i = 1; i <= N; i++ ) {
		for ( int p = 0; p < 2; p++ ) {
			int ok = 1, ng = N + 1;
			while ( abs(ok - ng) > 1 ) {
				int range = (ok + ng) / 2;
				if ( isHave(i, range, p) ) { 
					ok = range;
				} else {
					ng = range;
				}
			}
			if ( p == 0 ) rangeRight[i] = ok;
			else          rangeLeft [i] = ok;
		}
	}

	int dp[1006][2]; 

	fill_n(*dp, 1006 * 2, INF);

	dp[1][0] = 0;

	for ( int i = 1; i <= N; i++ ) {

		int val = INF;
		for ( int j = i; j <= N + 1; j++ ) {
			chmin(val, dp[j][1]);
		}

		chmin(dp[i + rangeRight[i]][1], dp[i][0] + 1);
		chmin(dp[i + rangeRight[i]][1], val + 1);
		for ( int j = i; j <= N; j++ ) {
			if ( j - rangeLeft[j] + 1 <= i ) {
				chmin(dp[j + 1][0], dp[i][0] + 1);
				chmin(dp[j + 1][0], val + 1);
			}
		}
	}

	cout << min(dp[N + 1][0], dp[N + 1][1]) << endl;
	return ( 0 );
}



Measured memory_bytes: 11016