akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int N = s.length();

    int cntr = 0;
    int cntb = 0;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if(s[i] == '0')
        {
            cntr++;
        }
        else
        {
            cntb++;
        }
        if(cntr >= 1 && cntb >= 1)
        {
            cntr--;
            cntb--;
            ans += 2;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000004
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
#define fin ios_base::sync_with_stdio(false); cin.tie(NULL);
int p[3001][3001];
void print(string s,int i,int j)
{
  if(i==0 || j==0)
    return;
  else if(p[i][j]==1)
  {
    print(s,i-1,j-1);
    cout<<s[i-1];
  }
  else if(p[i][j]==-1)
    print(s,i-1,j);
  else
    print(s,i,j-1);
}
int main()
{fin;
  string s,t,ans;
  ans="";
  cin>>s>>t;
  int i,j;
  int dp[s.length()+1][t.length()+1];
  memset(p,0,sizeof(p));
  for(i=0;i<=s.length();i++)
  {
    for(j=0;j<=t.length();j++)
    {
      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;
        p[i][j]=1;}
      else
      {
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        if(dp[i-1][j]>=dp[i][j-1])
          p[i][j]=-1;
      }
    }
  }
  print(s,s.length(),t.length());
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<string> svec;

#define IN_LL(in) ll in; cin >> in
#define IN_STR(in) string in; cin >> in
#define IN_VEC(in, size) vec in; for(int i = 0; i < (size); ++i){int ____cur; cin >> ____cur; in.push_back(____cur); } 0
#define IN_SVEC(in, size) svec in; for(int i = 0; i < (size); ++i){string ____cur; cin >> ____cur; in.push_back(____cur); } 0

#define OUT(out) cout << (out)
#define OUT_VEC(out) for(ll i = 0; i < (out).size(); ++i) cout << (out)[i]

ll func(svec& s){
	sort(s.begin(), s.end());
	s.erase(unique(s.begin(), s.end()), s.end());
	return s.size();
}

int main(void){
	IN_LL(n);
	IN_SVEC(s, n);
	
	ll res = func(s);
	
	OUT(res);
	return 0;
}


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

#define M 1046527
#define NIL (-1)
#define L 14
#define Ture 1
#define False 0
char H[M][L];

int getChar(char ch) {
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]) {
    int len = strlen(str);
    long long sum = 0, p = 1, i;
    for(i=0; i<len; ++i) {
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key) {return key%M;}
int h2(int key) {return 1+(key%(M-1));}

int find(char str[]) {
    long long key, i, h;
    key = getKey(str);
    for(i=0; ; ++i) {
        h = (h1(key)+i*h2(key))%M;
        if(strcmp(H[h], str) == 0) return 1;
        else if(strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
  long long int key,h,i;
    /* your task */
  key = getKey(str);

  for(i=0;;i++){
  h = (h1(key) + i*h2(key))%M;
  if(H[h][0]=='\0'){
    strcpy(H[h],str);
    break;
  }
}return 0;
}

int main()
{
    int i, n, h,j,k=0;
    char str[L], com[9];
    for(i=0; i<M; ++i) H[i][0] = '\0';
    scanf("%d", &n);

    /*for(i=0; i<n; ++i) {
        scanf("%s %s", com, str);
        if(com[0] == 'i') insert(str);
        else {
            if(find(str)) printf("yes\n");
            else printf("no\n");
        }
    }*/
 int a[n];
    for(i=0; i<n; ++i) {
        scanf("%s %s", com, str);
        if(com[0] == 'i') insert(str);
        else {
            if(find(str)==1){
              a[k]=1;
              k++;
            }
            else if(find(str)==0){
              a[k]=0;
              k++;
            };
        }
    }for(j=0;j<k;j++){
      if(a[j]==1){
        printf("yes\n");
      }else if(a[j]==0){
        printf("no\n");
      }
    }
    /*for(j=0;j<k;j++){
      printf("%d",a[j]);
    }*/

    return 0;
}



Measured memory_bytes: 17704
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define srt(i) sort(i.begin(), i.end())
#define rvt(i) sort(i.begin(), i.end(), greater<int>())

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

    int ans = 0;
    rep(i,n){
      int a;
      cin >> a;

      if((i+1)%2!=0 && a%2!=0) ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3592
N, D = map(int, input().split())
X = [0]*N
Y = [0]*N
for i in range(N):
    X[i], Y[i] = map(int, input().split())

count = 0
D2 = D**2

for i in range(N):
    temp = X[i]**2 + Y[i]**2
    if temp<=D2:
        count += 1

print(count)

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

template<typename T>
T gcd(T a, T b) {
	if (a%b == 0) {
		return b;
	} else {
		return gcd(b, a % b);
	}
}

int main() {
	int T;
	cin >> T;
	vector<ll> A(T);
	vector<ll> B(T);
	vector<ll> C(T);
	vector<ll> D(T);
	for (int i = 0; i < T; ++i) {
		cin >> A[i] >> B[i] >> C[i] >> D[i];
	}

	for (int i = 0; i < T; ++i) {
		if ((A[i] < B[i]) || (B[i] > D[i])) {
			cout << "No" << endl;
			continue;
		}
		if (B[i] <= C[i]) {
			cout << "Yes" << endl;
			continue;
		}

		ll g = gcd(B[i], D[i]);
		ll x = B[i] - g + (A[i] % g);
		if (x > C[i]) { cout << "No" << endl; }
		else { cout << "Yes" << endl; }
	}

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
template<typename T> void SSS(T& t) { cin >> t; }
#define SS(T, ...)      T __VA_ARGS__; SSS(__VA_ARGS__);
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

// (x, y) を始点とした BFS をして、(x, y) から最も遠いマスへの距離を答える
int bfs(const vector<string> &v, ll x, ll y) {
    ll H = v.size(), W = v[0].size();
    vvl dist(H, vl(W, -1));//-1で埋める
    queue<pair<ll,ll>> que;

    ll res = 0;
    que.push(make_pair(x,y));
    dist[x][y] = 0;
    while (!que.empty()) {
        ll x = que.front().first, y = que.front().second;
        res = max(res, dist[x][y]);
        que.pop();
        rep(dir,4){
            ll nx = x+ dx[dir], ny = y + dy[dir];
            if (nx < 0 || nx >= H || ny < 0 || ny >= W) continue;
            if (v[nx][ny] == '.'&&dist[nx][ny]==-1){ //未探索の道なら
                dist[nx][ny] = dist[x][y] + 1; //前のマス+1
                que.push({nx, ny}); //4方位をqueueに追加
            }
        }
    }
    return res;
}

int main() {
    ll h,w;cin >> h >> w;
    vector<string> v(h);
    for (int i = 0; i < h; ++i) cin >> v[i];

    int res = 0;
    rep(x,h){
     rep(y,w){
         if (v[x][y] == '#') continue;
         res = max(res, bfs(v, x, y));
         debug(bfs(v,x,y))
     }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<vpll> vvpll;
typedef unordered_map<ll, ll> um;
typedef unordered_set<ll> us;

#define fastio ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ts ll t; in(t) while (t--) solve();
#define ks ll t; in(t) FOR(i, 1, t+1) out("Case #" << i << ": " << solve());
#define endl '\n'
#define ln cout << endl;
#define in(x) cin >> x;
#define out(x) cout << x << endl;
#define flush cout << flush;
#define reset(a, b) memset(a, b, sizeof(a));
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define FOR(i, a, b) for (ll i = a; i < b; ++i)
#define FORI(i, a, b, c) for (ll i = a; i < b; i += c)
#define FORD(i, a, b) for (ll i = a; i > b; --i)
#define FOREACH(it, v, r) for (auto it = v.begin() + r; it != v.end(); it++)
#define FORALL(it, v) for (auto it : v)
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define vin(v, x) vll v(x); FOR(i, 0, x) in(v[i])
#define all(v) v.begin(), v.end()
#define allr(v, r) v.begin(), v.begin() + r
#define showv(v) FORALL(it, v) cout << it << ' '; ln
#define printv(v) FORALL(it, v) out(it)
#define show2d(v) FORALL(it, v) { FORALL(j, it) cout << j << ' '; ln}
#define showm(v) FORALL(it, v) cout << it.F << ": " << it.S << ' '; ln
#define sortv(v) sort(all(v));
#define revv(v) reverse(all(v));
#define maxv(v) *max_element(all(v))
#define minv(v) *min_element(all(v))
#define gcd __gcd
#define checkbit(n, i) (n >> i) & 1               // check ith bit
#define bitcount __builtin_popcount               // count set bits
#define firstbitindex __builtin_ctz               // count trailing zeros
#define lastbitindex __builtin_clz                // count leading zeros
#define bitparity __builtin_parity                // check set bits are even or odd
#define findv(v, x) (find(all(v), x) != v.end())  // find in a vector
#define findsm(u, x) (u.find(x) != u.end())       // find in a set / map
#define findstr(s, x) (s.find(x) != string::npos) // find in a string
#define sz(a) a.size()
#define precise(x) cout << fixed << setprecision(x);

const ll MAXN = 1e5, MOD = 998244353, SIZE = 2e7;//, INF = 0x7f7f7f7f7f7f7f7f;
const double EPS = 1e-9, PI = acos(-1);
const int INFi = 0x7f7f7f7f;

//<<------Declare Variables Here----->>//
ll n;
char c[26] = {'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'};
string s;

//<<-----Implement Functions Here---->>//
void solve()
{
    in(n)
    while (n)
        --n, s = c[n % 26] + s, n /= 26;
    out(s)
}

//<<----------Start of Main---------->>//
int main()
{
    fastio
    //ts
    solve();
    return 0;
}

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

#define DEBUG 0

#define PLUS 0
#define MINUS 1

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

lli goal = 0;

int main(){
	lli n;
	vector<lli> a[3];
	cin>>n;
	REP(i,3){
		REP(j,n){
			lli tmp;
			cin>>tmp;
			a[i].push_back(tmp);
		}
		sort(a[i].begin(),a[i].end());
		if(DEBUG){
			REP(j,a[i].size()){
				cout<<a[i].at(j)<<" ";
			}
			cout<<endl;
		}
	}

	lli bigPos = 0;
	lli smallPos = 0;
	lli ans = 0;
	REP(i,n){
		lli center = a[1].at(i);
		if(DEBUG)cout<<"center = "<<center<<" ";
		/*center > smallPosになるまで検索する*/
		while(1){
			if(smallPos>=n)break;
			if(center > a[0].at(smallPos)){
				smallPos++;
			}
			else break;
		}
		if(DEBUG)cout<<"small = "<<a[0].at(smallPos-1)<<" ";
		/*center > Bigになるまで検索する*/
		while(1){
			if(bigPos>=n)break;
			if(center >= a[2].at(bigPos)){
				bigPos++;
			}
			else{
				break;
			}
		}if(DEBUG)cout<<"Big= "<<a[2].at(bigPos)<<" ";
		lli nowAns = smallPos * (n-bigPos);
		if(DEBUG)cout<<"nowAns ="<<nowAns;
		ans += nowAns;
		if(DEBUG)cout<<endl;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//uniform_int_distribution<int>(1000,10000)(rng)

ll binpow(ll a, ll b)
{
    if (b == 0)
        return 1;
    ll res = binpow(a, b / 2);
    res*=res;
    if (b % 2)
        return res * a;
    return res;
}

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

string to_upper(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='a' && a[i]<='z') a[i]-='a'-'A';
    return a;
}
 
string to_lower(string a)
{
    for (int i=0;i<(int)a.size();++i) if (a[i]>='A' && a[i]<='Z') a[i]+='a'-'A';
    return a;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n,mod=0;
    cin>>n;
    for (int i=1;i<3000000;++i)
    {
        mod*=10;
        mod+=7;
        mod%=n;
        if (mod==0)
        {
            cout<<i;
            return 0;
        }
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 3644
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
//#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
//using namespace std::chrono;
typedef long long int llint;
typedef double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase

/*
cout<<fixed<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=110000007;//減らしてる
const llint big=2.19e17+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
vector<int>Zalgo(string S){
	vector<int>A(S.size());
	A[0] = S.size();
	int i = 1, j = 0;
	while (i < S.size()) {
		while (i+j < S.size() && S[j] == S[i+j]){ ++j;}
		A[i] = j;
		if (j == 0) { ++i; continue;}
		int k = 1;
		while (i+k < S.size() && k+A[k] < j){ A[i+k] = A[k];++k;}
		i += k; j -= k;
	}
	return A;
}

int main(void){
	cout<<fixed<<setprecision(20);
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,t;cin>>s>>t;
	string st=t+"#"+s;
	REV(s);REV(t);
	string rst=t+"#"+s;
	auto A=Zalgo(st);
	auto B=Zalgo(rst);
	int ans=0,i,n=s.size(),m=t.size();
	for(i=0;i<=n-m;i++){
		if(m-1==A[m+1+i]+B[m+1+n-m-i]){ans++;}
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 8420
mask = [[i for i in range(6)], (1, 5, 2, 3, 0, 4), (2, 1, 5, 0, 4,3),(3, 1, 0, 5, 4, 2), (4, 0, 2, 3, 5, 1)]
mask += [[mask[1][i] for i in mask[1]]]
 
def set_top(dice, top):
    return [dice[i] for i in mask[top]]
 
def twist(dice):
    return [dice[i] for i in (0, 3, 1, 4, 2, 5)]
 
def equal(dice1, dice2):
    for i in range(6):
        tmp_dice = set_top(dice2, i)
        for _ in range(4):
            if dice1 == tmp_dice:
                return True
            tmp_dice = twist(tmp_dice)
    return False
         
dice1 = input().split()
dice2 = input().split()
 
print('Yes' if equal(dice1, dice2) else 'No')


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

int main(){

    int count = 0;
    int max = 0;
    int flag = 0;
    
    string s;
    cin >> s;
    for(int i =0; i<s.length();i++){
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
            count++;
            if(max <= count){
                max = count;
            }
        }
        else{
            
            count = 0;

        }
    }

    cout << max << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int dp[2][3] = {};
	for(int i=1; i<=n; i++)
		for(int j=0; j<3; j++)
		{
			int x;
			scanf("%d",&x);
			dp[i%2][j] = max(dp[(i+1)%2][(j+1)%3], dp[(i+1)%2][(j+2)%3]) + x;
		}
	printf("%d\n",max(dp[n%2][0],max(dp[n%2][1],dp[n%2][2])));
	return 0;
}

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

#define CIN_ONLY if(1)
struct cww{cww(){
    CIN_ONLY{
        ios::sync_with_stdio(false);cin.tie(0);
    }
}}star;
#define fin "\n"
#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define DEBUG if(0)
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l,T r)
{bool a=l>r;if(a)l=r;return a;}
template <typename T>inline bool chmax(T &l,T r)
{bool a=l<r;if(a)l=r;return a;}
template <typename T>
istream& operator>>(istream &is,vector<T> &v){
    for(auto &it:v)is>>it;
    return is;
}
template <typename T> class svector:private std::vector<T>{
    using V=std::vector<T>;
    using SV=svector;
private:
    int sz;
public:
    using V::begin;
    using V::end;
    svector(int n,T ini):V(n*2+1,ini),sz(n){}
    svector(int n):SV(n,T()){}
    svector():V(),sz(0){}
    int size(){return sz;}
    T& operator[](int id){
        //assert(abs(id)<=sz);
        return V::operator[](id+sz);
    }
    SV& copy(const SV &other){
        V::operator=(other);
        sz=other.sz;
        return (*this);
    }
    SV& operator=(const SV& other){
        return copy(other);
    }
};

typedef vector<int> V;
int main(){
    int N,M;
    cin>>N>>M;
    V A(N);
    V B(N+1,0);
    svector<int> C(N,0);
    cin>>A;
    for(auto &it:A)B[it]++;
    FOR(i,1,N+1){
        int id=i;
        int num=B[i];
        while(num){
            C[id]++;
            num--;
            id--;
        }
    }
    int res=0;
    FOR(i,1,N+1)res+=(C[i]==0);
    REP(_,M){
        int x,nxt,id;
        cin>>x>>nxt;x--;
        int prv=A[x];
        B[prv]--;
        id=prv-B[prv];
        C[id]--;
        if(id>=1&&C[id]==0)res++;
        id=nxt-B[nxt];
        if(id>=1&&C[id]==0)res--;
        C[id]++;
        B[nxt]++;
        A[x]=nxt;
        cout<<res<<endl;
    }
    return 0;
}


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

int main() {
  string s;
  cin >> s;

  vector<ll> a(s.size()+1, 0);

  rep(i,s.size()) if (s[i] == '<') a[i+1] = max(a[i+1], a[i]+1);
  for (int i = s.size()-1; i >= 0; i--) {
    if (s[i] == '>') a[i] = max(a[i],a[i+1]+1);
  }

  cout << accumulate(a.begin(),a.end(),ll(0)) << endl;

  return 0;
}


Measured memory_bytes: 7652
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    vector<ll> sum(n,0);
    for(ll i=0; i<n; i++){
        if(i==0) sum[i]=a[i];
        else sum[i] = a[i]+sum[i-1];
    }
    ll cnt1=0,cnt2=0;
    ll add1=0,add2=0;

    for(ll i=0; i<n; i++){
        ll tmp1 = sum[i]+add1;
        ll tmp2 = sum[i]+add2;
        if( i%2==0 ){
            if(tmp1<=0){
                ll b = 1-tmp1;
                cnt1+=b;
                add1+=b;
            }
            if(tmp2>=0){
                ll b = tmp2+1;
                cnt2+=b;
                add2-=b;
            }
        }else{
            if(tmp1>=0){
                ll b = tmp1+1;
                cnt1+=b;
                add1-=b;
            }
            if(tmp2<=0){
                ll b = 1-tmp2;
                cnt2+=b;
                add2+=b;
            }
        }
    }
    cout << min(cnt1,cnt2) << endl;
    return 0;
}


Measured memory_bytes: 1792
N=int(raw_input())
a=map(int,raw_input().split())
odd=even=four=0
for i in a:
    if i%2==1:
        odd+=1
    elif i%4==0:
        four+=1
    else:
        even+=1
flag=True
if even==0:
    if odd>four+1:
        flag=False
else:
    if odd>four:
        flag=False
print "Yes" if flag else "No"

Measured memory_bytes: 11320
#include<stdio.h>
#include<limits.h>
#include<math.h>

int main(){
  int i,j,l,k,n,p[101],m[101][101];
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i-1],&p[i]);
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=(n-l+1);i++){
      j=i+l-1;
      m[i][j]= INT_MAX;
      for(k=i;k<=j-1;k++){
        if(m[i][j]>m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]){
          m[i][j]=(m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
        }
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


int main(){
    int N;
    cin >> N;
    
    map<string,int>j;

    rep(i,N){
        string s;
        cin >> s;
        j[s] +=1;
    }

    cout << "AC" << " x " << j["AC"] << endl;
    cout << "WA" << " x " << j["WA"] << endl;
    cout << "TLE" << " x " << j["TLE"] << endl;
    cout << "RE" << " x " << j["RE"] << endl;

}

Measured memory_bytes: 3632
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI(N);
  vector<int> C(N - 1), S(N - 1), F(N - 1);
  FOR(i, N - 1) { cin >> C[i] >> S[i] >> F[i]; }
  FOR(i, N) {
    int now = 0;
    for (int j = i; j < N - 1; ++j) {
      if (now <= S[j]) {
        now = S[j];
      } else {
        now = (now + F[j] - 1) / F[j] * F[j];
      }
      now += C[j];
    }
    print(now);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  string s;
  cin >> s;
  int n = 0b1000;
  int m = 4;
  //DUMP(n);
  REP(i, 0, n) {
    VEC<int> a(m);
    REP(j, 0, m) a[j] = s[j] - '0';
    int sum = a[0];
    //DUMP(i,a);
    REP(j, 0, m-1) {
      //DUMP(i >> j & 1);
      sum = (i >> j & 1 ? sum + a[j+1] : sum - a[j+1]);
    }
    //DUMP(sum);
    if (sum == 7) {
      REP(j, 0,m-1) { cout << a[j] << (i >> j & 1 ? '+' : '-'); }
      cout << a[3] <<"=7"<< endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#pragma region
#include <assert.h>
#include <math.h>

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define pb push_back
#define f(i, a, b) for (int i = a; i < b; i++)
#define revf(i, b, a) for (int i = b; i >= a; i--)
#define all(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define revsrt(v) sort(v.rbegin(), v.rend())
#define sp << ' ' <<
#define en << '\n'
#define precision(x) cout << fixed << setprecision(x);

using namespace std;

template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &v) {
  os << "{" << v.first << ", " << v.second << "}" en;
  return os;
}

template <typename T> ostream &operator<<(ostream &os, set<T> &v) {
  for (T t : v)
    os << t << " ";
  os en;
  return os;
}

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (T t : v)
    os << t << " ";
  os en;
  return os;
}

template <typename T> istream &operator>>(istream &is, vector<T> &v) {
  int n = v.size();
  for (int i = 0; i < n; i++)
    is >> v[i];
  return is;
}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
#pragma endregion

int mod = 1e9 + 7; // 998244353;
const int MAX = 1e5 + 5;

void preprocessing() {}

void solvetestcase() {
  int n;
  cin >> n;
  vi a, b;
  f(i, 0, n) {
    int x, y;
    cin >> x >> y;
    a.push_back(x - y);
    b.push_back(x + y);
  }
  srt(a);
  srt(b);
  int ans = max(a[n - 1] - a[0], b[n - 1] - b[0]);
  cout << ans en;
}

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

  preprocessing();

  int t = 1;
  // UNCOMMENT FOR TESTCASES	\
	cin >> t;

  f(T, 1, t + 1) {
    // UNCOMMENT FOR CODEJAM,HACKERCUP	\
		cout << "Case #" << T << ": ";
    solvetestcase();
    cout.flush();
  }

  return 0;
};

/*
    AUTHOR:     KUNAL TAWATIA
    EDUCATION:  INDIAN INSTITUTE OF TECHNOLOGY, JODHPUR
*/


Measured memory_bytes: 5136
import java.io.*;
import java.util.*;

class Main {
    static Scanner scanner = new Scanner();

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] h = new int[n + 1];
        int[] can = new int[n + 1];
        for (int i = 1; i <= n; i++) {
            h[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            can[i] = h[i] >= h[i + 1] ? 1 : 0;
        }
        for (int i = 1; i <= n; i++) {
            if (can[i] != 0) {
                can[i] += can[i - 1];
            }
        }
        Arrays.stream(can).max().ifPresent(System.out::println);
    }

    static class Scanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 40168
#include<stdio.h>
#include<string.h>
int main(){
  int i,c0,c1,c2,c3,N;
  char S[3];
  c0=c1=c2=c3=0;
  scanf("%d",&N);
  for(i=0;i<N;++i){

      scanf("%s",S);
    
      if(strcmp(S,"AC")==0){
        c0+=1;
      }
      else if(strcmp(S,"WA")==0){
        c1+=1;
      }
      else if(strcmp(S,"TLE")==0){
        c2+=1;
      }
      else {

        c3+=1;
      }
  }
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",c0,c1,c2,c3);
}


Measured memory_bytes: 1736
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

# n = int(input())
# a, b
# s = input()


l = list(map(int, input().split()))
l.sort()
if l == [1,4,7,9]:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 38384
from itertools import product

n, a, b, c = map(int, input().split())
l = [int(input()) for _ in range(n)]

ans = 10 ** 10
for bit in product([0, 1, 2, 3], repeat=n):
    tmp = [0] * 4
    mp = 0
    for i, j in enumerate(bit):
        if j != 3 and tmp[j] != 0:
            mp += 10
        tmp[j] += l[i]
    if any([i == 0 for i in tmp[:3]]):
        continue
    mp += abs(a - tmp[0]) + abs(b - tmp[1]) + abs(c - tmp[2])
    ans = min(ans, mp)
print(ans)


Measured memory_bytes: 3064
n=int(input())
a=[list(map(int, input().split())) for _ in range(2)]
s=a[0][0]+sum(a[1])
ans=s
for i in range(1, n):
  s=s+a[0][i]-a[1][i-1]
  if s>ans:
    ans=s
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=3e3+10;
const int mod=1e9+7;
int dp[maxn<<1][maxn][2];
inline int read(){
	int x=0,flag=1;
	char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')flag=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return x*flag;
}
int n,sum=0;
int add(int &x,int y){
	while(y>=mod)y-=mod;
	x+=y;
	while(x>=mod)x-=mod;
}
int main(){
	int i,j,k,m,p;
	n=read();m=read();
	int pos=1;
	for(i=1;i<=n;i++)dp[0][i][0]=1;
	dp[0][0][1]=1;
	for(i=0;i<m;i++)
		for(j=0;j<=n;j++)
			for(k=0;k<=1;k++){
				if(j>0){
					add(dp[i+1][j-1][k|(j==1)],dp[i][j][k]);
					add(dp[i+1][j][k|(j==1)],dp[i][j][k]);
				}
				if(n-j>0){
					add(dp[i+1][j][k],dp[i][j][k]);
					add(dp[i+1][j+1][k],dp[i][j][k]);
				}
			}
	int ans=0;
	for(i=0;i<=n;i++)ans=(ans+dp[m][i][1])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 71936
require 'prime'
n=10**5
a=[false]*(n+1)
Prime.each(n){|i| a[i]=true}

b=[0]*(n+1)
for i in 1..n
    b[i]=b[i-1]+(a[i]&&a[(i+1)/2] ? 1 : 0)
end

gets.to_i.times{
    l, r=gets.split.map &:to_i
    puts b[r]-b[l-1]
}


Measured memory_bytes: 4504
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

int main() {
    ll N;
    cin >> N;
    ll t = 0;
    ll a = 0;
    rep(phase,0,N) {
        ll T, A;
        cin >> T >> A;
        ll good = 1;
        while (!((t <= T * good) && (a <= A * good))) {
            good *= 2;
        }
        if (good == 1) {
            t = T;
            a = A;
            continue;
        }
        ll bad = 1;
        while (good - bad >= 2) {
            ll mid = (bad + good) / 2;
            if ((t <= T * mid) && (a <= A * mid)) {
                good = mid;
            } else {
                bad = mid;
            }
        }
        t = T * good;
        a = A * good;
    }
    cout << (t + a) << endl;
}



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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;
int const inf = 1<<29;

int calc(int t, int f, int o) {
  return 10 * t + 5 * f + o;
}

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

  rep(i, N + 1) rep(j, N + 1) {
    if (i + j > N) { continue; }
    int k = N - i - j;
    if (10000 * i + 5000 * j + 1000 * k == Y) {
      cout << i << " " << j << " " << k << "\n";
      exit(0);
    }
  }

  cout << "-1 -1 -1\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    string O, E; cin >> O >> E;

    for (int i = 0; i < O.size(); i++) {
        cout << O[i];
        if (i < E.size()) {
            cout << E[i];
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
a,b = map(int,raw_input().split())
if a<0 and b>0 or a==0 or b==0:
	print "Zero"
elif a>0 and b>0:
	print "Positive"
elif a<0 and b<0 and a%2==0 and b%2==0:
	print "Negative"
elif a%2!=0 and b%2!=0:
	print "Negative"
elif a%2!=0 or a%2==0 and b%2!=0 or b%2==0:
	print"Positive"

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 2 * INF;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		ans = min(ans, a + b);
	}
	cout << ans << endl;

}


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

using namespace std;

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

	string result = "No";

	for(int i = 0; i <= K; i++) {
		if(B <= A) {
			B *= 2;
		} else if(C <= A) {
			C *= 2;
		} else if(C <= B) {
			C *= 2;
		
		} else {
			result = "Yes";
			break;
		}
	}

	cout << result << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std; 
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ld long double
#define fi first 
#define se second 
#define mp make_pair
#define pb push_back
#define ull unsigned long long int
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define mo 1000000007
ll gcd(ll a ,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll poww(ll a,ll n){if(n==0)return 1;ll p=poww(a,n/2);p=(p*p)%mo;if(n%2)p=(a*p)%mo;return p;}
////////////////////////////////////////////////////

ll tn ; 
void solve()
{
  ll n ; cin>>n ;
  ll sum = 0 ; 
  for(ll i = 1; i<=n; i++)
  { 
  	if((i%3)&&(i%5))
  	sum+=i;
  }
  cout<<sum; 
}
int main()
{ ios; 

ll t ;t = 1; 
  for(tn = 1; tn<=t; tn++)
	solve(); 
	return 0 ; 
}


Measured memory_bytes: 3660
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int a[]=new int[100],n=stdIn.nextInt(),i,j,m,t,s=0;
		for(i=0;i<n;i++)a[i]=stdIn.nextInt();
		for(i=0;i<n;i++){
			m=i;
			for(j=i;j<n;j++)if(a[m]>a[j])m=j;
			if(a[i]!=a[m])s++;
			t=a[i];
			a[i]=a[m];
			a[m]=t;
		}
		for(i=0;i<n-1;i++)System.out.print(a[i]+" ");
		System.out.println(a[n-1]+"\n"+s);
	}
}


Measured memory_bytes: 26208
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

#include <iostream>
#include <vector>
using namespace std;

//重複順列
vector<ll> buf;
void permutation(ll i, const ll size, const ll range_start, const ll range_end)
{
    if (i == size) {
      // ここで所望の作業を行う
      for(ll itr:buf){
        cout << itr;
      }
    }
    else{
        for(ll j = range_start; j <= range_end; ++j){
            buf[i] = j;
            permutation(i + 1, size, range_start, range_end);
        }
    }
}

int main(void)
{
  map<ll, ll> H, W;
  vector<ll> MH, MW;
  map<pair<ll, ll>, ll> check;
  ll h, w, m, ans=-1, ansh=-1, answ=-1, a, b, mh=-1, mw=-1;
  cin >> h >> w >> m;
  RAP(i, m){
     cin >> a >> b;
     H[a]++;
     W[b]++;
     check[make_pair(a, b)]++;
  }
  for(auto x : H){
    if(x.second>ansh){
      ansh = x.second;
      MH.clear();
      MH.push_back(x.first);
    }else if(x.second == ansh){
      MH.push_back(x.first);
    }
  }
  for(auto y : W){
    if(y.second>answ){
      answ = y.second;
      MW.clear();
      MW.push_back(y.first);
    }else if(y.second == answ){
      MW.push_back(y.first);
    }
  }
  bool flag = false;
  for(auto x : MH){
    for(auto y : MW){
      if(check[make_pair(x, y)]==0){
        flag = true;
        break;
      }
    }
    if(flag){
      break;
    }
  }
  if(flag){
    ans = ansh + answ;
  }else{
    ans = ansh + answ -1;
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 67812
// created_by  Rishi_Mohan

#include<bits/stdc++.h>

#define    ll           long long
#define    db1(x)       cout<<#x<<"="<<x<<'\n'
#define    db2(x,y)     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define    db3(x,y,z)   cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;

void solve()
{
   ll a , b, c , k;
   cin >> a >> b >> c >> k;
   ll ans = 0;

   /*if(a<=k) {ans+=a; k-=a;}
   if(b<=k) {k-=b;}
   if(c<=k) {ans-=k;}*/
   if(k>0)
   {
       if(k>=a)
       {
            k -= a;
            ans += a;
       }
        else
        {
            ans += k;
            k=0;
            //ans += k;
        }
   }
    if(k>0)
   {
        if(k>=b)
        {
            k-=b;
        }
        else k=0;

   }
   if(k>0)
   {
        //cout << "dfd" << endl;
      ans-=k;
       /*if(k>=c)
        {
            ans -= k;
            k=0;
        }
        else ans-=k;*/
   }
   cout << ans << endl;

}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = ReadLong();
            var N = 50;
            var a = new long[50];
            var times = K / N;
            var rem = K % N;
            if (K <= 50)
            {
                for (int i = 0; i < K; i++) a[i] = 50 - i;
            }
            else
            {
                for (int i = 0; i < 50; i++) a[i] = 50 - i + times - 1;
                for (int i = 0; i < rem; i++) a[i]++;
            }

            Console.WriteLine(N);
            foreach (var i in a) Console.Write(i + " ");

            Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13140
N=int(input())
A=list(map(int,input().split()))
count=0
max=0

for i in range(N-1):
    if A[i]>=A[i+1]:
        count+=1
    else:
        if max<=count:
            max=count
        count=0
if max<=count:
    max=count
print(max)

Measured memory_bytes: 14224
s = input()
if s == "SUN":
    print(7)
if s == "MON":
    print(6)
if s == "TUE":
    print(5)
if s == "WED":
    print(4)
if s == "THU":
    print(3)
if s == "FRI":
    print(2)
if s == "SAT":
    print(1)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{
	int r, D, x;
	cin >> r >> D >> x;

	int i;
	for (i = 0; i < 10; i++)
	{
		x = r * x - D;
		cout << x << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int n, k;
int h;
int i;
int ans;

int main()
{
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; i++) {
    scanf("%d", &h);
      if (h>=k){
        ans += 1;
      }
  }
printf("%d\n", ans);
}

Measured memory_bytes: 128
N=gets.to_i
S=gets.chomp

s=S.split("").select {|x|x=="#"}.length
d=N-s

l=[0,0]
r=[s,d]

ret = N
(0..N).each do |i|
    rr = l[0] + r[1]
    ret = rr if rr < ret
    if S[i] == "#"
        r[0]-=1
        l[0]+=1
    else
        r[1]-=1
        l[1]+=1
    end
end
puts ret


Measured memory_bytes: 31992
#include<stdio.h>

int main(void)
{
	int S,h,m,s;
	
	scanf("%d",&S);
	
	h=S/3600;
	m=(S-h*3600)/60;
	s=S-h*3600-m*60;
	printf("%d:%d:%d\n",h,m,s);

	return 0;
}



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
   string s;
   int k;
   cin>>k>>s;
   int a=s.length();
   string b=s.substr(0,k);
   if(a<=k)cout<<s<<endl;
   else cout<<b<<"..."<<endl;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		while (true) {
			StringBuilder s = new StringBuilder(sc.next());
			int L = sc.nextInt();
			if (L == 0) {
				break;
			}
			TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();

			int cnt = 0;
			while (true) {
				if (map.get(Integer.parseInt(s.toString())) != null) {
					System.out.print(map.get(Integer.parseInt(s.toString())));
					System.out.print(" " + Integer.parseInt(s.toString()));
					System.out.println(" " + (cnt - map.get(Integer.parseInt(s.toString()))));
					break;
				}
				map.put(Integer.parseInt(s.toString()), cnt++);
				while (s.length() < L) {
					s = s.reverse().append("0").reverse();
				}
				char[] a = s.toString().toCharArray();
				Arrays.sort(a);

				int ka = 0, kb = 0;
				for (int i = 0; i < L; i++) {
					ka *= 10;
					ka += a[i] - '0';
				}
				for (int i = L - 1; 0 <= i; i--) {
					kb *= 10;
					kb += a[i] - '0';
				}
				int next = kb - ka;
				s = new StringBuilder("" + next);
			}
		}
	}

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

Measured memory_bytes: 21028
#include <algorithm> 
#include <iostream> 
using namespace std; 
 
int main(){
int N,a,l[50],yan,b;
cin>>N>>a;
for(int i=0;i<N;i++){
cin>>l[i];
}
for(int j=0;j<N;j++){
for(int k=j+1;k<N;k++){
if(l[j]<l[k]){
yan=l[j];
l[j]=l[k];
l[k]=yan;
}
}
}
for(int m=0;m<a;m++){
b+=l[m];
}
cout<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const int INF=1e9;
const int MOD=1e9+7;
int main(){
  int n;
  cin>>n;
  bool light[100100];
  REP(i,n)cin>>light[i];
  vector<int>V;
  int cnt=1,ans=0;
  REP(i,n-1){
    if(light[i]!=light[i+1]){
      cnt++;
    }else{
      V.PB(cnt);
      cnt=1;
    }
  }
  V.PB(cnt);
  REP(i,V.size()){
    int res=V[i];
    if(i!=0)res+=V[i-1];
    if(i!=V.size()-1)res+=V[i+1];
    ans=max(ans,res);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vi A, B;
string S, T;

void input() {
  int x, y, z;
  ;
  cin >> x >> y >> z;
  int a = x * 100 + y * 10 + z;
  cout << (a % 4 ? "NO" : "YES");
}
void solve() {
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int n, k;
Int dp[110][110000];
Int dp_sum[110][110000];
Int a[110];

int main(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++)cin >> a[i];
    dp[0][0] = 1;
    for(int j = 0;j <= k;j++)dp_sum[0][j] = 1;
    
    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= k;j++){
            dp[i][j] = dp_sum[i-1][j];
            if(j-a[i]-1 >= 0)dp[i][j] -= dp_sum[i-1][j-a[i]-1];
            if(j-1 >= 0)dp_sum[i][j] = dp_sum[i][j-1] + dp[i][j];
            else dp_sum[i][j] = dp[i][j];
            dp[i][j] %= MOD;
            dp_sum[i][j] %= MOD;
        }
    }
    if(dp[n][k] < 0)dp[n][k] += MOD;
    cout << dp[n][k] << endl;
    return 0;
}

Measured memory_bytes: 176256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int INF = 1 << 29;
const ll LINF = 1l << 61;
const ld PI = abs(acos(-1));
#define pq priotity_queue
#define mp make_pair
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define rrep(i, a, b) for (ll i = a; i >= b; i--)
#define cbuf(buf, init) memset(buf, init, sizeof(buf))
#define modp(x, y) (((y) + (x) % (y)) % (y))
#define divd(x, y) (static_cast<double>(x) / static_cast<double>(y))

ll N;
ll F[200][10][5];
ll P[200][20];

int main()
{
    //
    cin >> N;
    rep(i, 0, N)
    {
        rep(j, 0, 5)
        {
            cin >> F[i][j][0];
            cin >> F[i][j][1];
        }
    }
    rep(i, 0, N)
    {
        rep(j, 0, 11) { cin >> P[i][j]; }
    }

    ll pmax = -LINF;
    rep(d, 1, (1 << 10))
    {
        ll p = 0;
        rep(i, 0, N)
        {
            ll c = 0;
            rep(j, 0, 5)
            {
                rep(k, 0, 2)
                {
                    if (F[i][j][k] == 1 && (d & (1 << (j * 2 + k))) != 0) c++;
                }
            }
            p += P[i][c];
        }
        pmax = max(pmax, p);
    }
    cout << pmax << endl;
}


Measured memory_bytes: 256