akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
inline bool check(li x) {
    li tmp = n;
    while (tmp >= x) {
        if (tmp % x == 0) {
            tmp = tmp / x;
        } else {
            tmp = tmp % x;
        }
    }
    return tmp == 1;
}

int main() {
    cin >> n;
    li c = sqrt(n);
    if (c * c == n) {
        c++;
    }

    li res = 2; // n, n-1
    if (n == 2) {
        cout << 1 << endl;
        return 0;
    }
    if (n <= 3) {
        cout << res << endl;
        return 0;
    }
    repp(i, 2, c + 1) {
        if (check(i)) {
            res++;
        }
        li opp = n / i;
        if (opp * i == n - 1 && opp > c && opp < n - 1) {
            res++; // opp
        }
    }
    cout << res << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 200005
using namespace std;

int main() {
  int k;
  cin >> k;
  int gu, ki;
  gu = k/2;
  if(k%2 == 0) {
    ki = gu;
  } else {
    ki = gu+1;
  }
  cout << ki*gu << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <climits>
#include <iostream>

int main() {
  int N; std::cin >> N;
  int T; std::cin >> T;
  double A; std::cin >> A;

  int best_i = -1;
  double best_v = 999999;
  for (int i = 0; i < N; ++i) {
    int H; std::cin >> H;
    double temp = T - 0.006 * H;
    double diff = std::abs(temp - A);
    if (diff < best_v) {
      best_i = i + 1;
      best_v = diff;
    }
  }
  std::cout << best_i << std::endl;
}


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

constexpr ll mod = 1e9 + 7;
unordered_map<string, ll> dp[105];

bool CanConcatenate(const string& s, char c) {
  if (s.size() < 2) return true;
  if (s.size() == 2) {
    if (s == "AG" && c == 'C') return false;
    if (s == "GA" && c == 'C') return false;
    if (s == "AC" && c == 'G') return false;
    return true; 
  } else if (s.size() == 3) {
    if (s[0] == 'A' && s[2] == 'G'&& c == 'C') return false;
    if (s[0] == 'A' && s[1] == 'G'&& c == 'C') return false;
    return CanConcatenate(s.substr(1), c);
  } else {
    return CanConcatenate(s.substr(1), c);
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  dp[0]["A"] = 1;
  dp[0]["C"] = 1;
  dp[0]["G"] = 1;
  dp[0]["T"] = 1;
  rep(i, n-1) {
    for(auto& e : dp[i]) {
      const char *next_ch = "AGCT";
      rep(j, 4) {
        if (CanConcatenate(e.first, next_ch[j])) {
          string s = e.first + next_ch[j];
          if (s.size() > 4) s = s.substr(1);
          dp[i+1][s] += e.second;
          dp[i+1][s] %= mod; 
        }
      }
    }
  }
  ll ans = 0;
  for (auto& e : dp[n-1]) {
    ans += e.second;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2688
#include <iostream>

using namespace std;

int main() {
    string _S, T;
    cin >> _S >> T;
    
    bool ff=false;
    for(int i=_S.size()-T.size()+1; i>=0; i--) {
        bool flag=true;
        for(int j=0; j<T.size(); j++) {
            if(_S[i+j]==T[j] || _S[i+j]=='?') {
                continue;
            } else {
                flag=false;
                break;
            }
        }
        if(flag) {
            for(int j=0; j<T.size(); j++) {
                _S[i+j] = T[j];
            }
            ff=true;
            break;
        }
    }
    
    if(ff) {
        for(int i=0; i<_S.size(); i++) {
            if(_S[i]=='?') _S[i]='a';
        }
        cout << _S << endl;
    } else {
        cout << "UNRESTORABLE" << endl;
    }


    return 0;
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  
  for(int i=0; i<N; i++){
    cin >>a.at(i);
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  int count =0;
  for(int i=0;i<N;i++){
    
    if(i%2==0){
      count += a.at(i);
    }else
      count -= a.at(i);
  }
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
check(char s){
  
}

int main(){
  int len = 0, i, j;
  char s[27];
  scanf("%s", s);
  
  while(s[len]){
    len++;
  }
  for (i = 0; i < len; i++){
    for (j = i + 1; j < len; j++){
      if(s[i] == s[j]){
        printf("no\n");
        return 0;
      }
    }
  }
  
  printf("yes\n");
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}

string out;
vs s1,s2;
int n;
int ans;

void f(string in, int cnt){
    if(in == out){
        ans = min(ans, cnt);
        return;
    }
    if(in.size() >= out.size())return;
    rep(i,n){
        string s = "";
        int len = s1[i].size();
        rep(j,in.size()){
            if(j + len <= in.size() && in.substr(j,len)==s1[i]){
                s += s2[i];
                j += len - 1;
            }else{
                s += in[j];
            }
        }
        if(s == in)continue;
        //cout << in << " " << i << " " << s << endl;
        f(s,cnt+1);
    }
}

int main(void) {
    int i,j;
    while(cin >> n,n){
        s1 = s2 = vs(n);
        rep(i,n) cin >> s1[i] >> s2[i];
        string in;
        cin >> in;
        cin >> out;
        ans = INF;
        f(in,0);
        if(ans < INF)cout << ans << endl;
        else cout << -1 << endl;
    }
}



Measured memory_bytes: 3136
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  int64 ret = 0;
  for (int i = 0; i < m; ++i) ret += a[i];
  printf("%lld\n", ret);
  return 0;
}


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

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var a = new int[n];
            var b = new int[n];
            for (int i = 0; i < n; i++)
            {
                var s = Console.ReadLine().Trim();
                a[i] = s.Length - s.Replace(".", "").Length;
                s = s.Replace(".", "");
                if (s == "+") b[i] = -1;
                else if (s == "*") b[i] = -2;
                else b[i] = int.Parse(s);
            }
            var ans =   getAns(a, b, n);
            Console.WriteLine(ans);
        }
    }
    static int getAns (int[] a, int[] b, int n)
    {
        var c = new List<int>[n];
        for (int i = 0; i < n; i++) c[i] = new List<int>();
        for (int i = n -1; i >= 0; i--)
        {
            if (b[i] >= 0) c[a[i]].Add(b[i]);
            else if (b[i] == -1)
            {
                var t = c[a[i] + 1].Sum();
                c[a[i]].Add(t);
                c[a[i] + 1].Clear();
            }
            else
            {
                var t = c[a[i] + 1].Aggregate((x, y) => x * y);
                c[a[i]].Add(t);
                c[a[i] + 1].Clear();
            }
        }
        return c[0][0];
    }
}



Measured memory_bytes: 16208
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if (a==b) cout<<c<<endl;
    else if(a==c) cout<<b<<endl;
    else cout<<a<<endl;
}



Measured memory_bytes: 256
#include<iostream>
using namespace  std;
int f(int x)
{
	return x * x;
}
int main()
{
	int d;
	while (cin >> d)
	{
		int sum = 0;
		for (int i = d; i <= 600 - d; i += d)
		{
			sum += (f(i) * d);
		}
		cout << sum << endl;
	}
	return 0;
}

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

int x[10], y[10];

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; ++i) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; ++i) v[i] = i;
    do{
        for(int i = 0; i < N-1; ++i) {
            double dx = x[v[i]] - x[v[i+1]];
            double dy = y[v[i]] - y[v[i+1]];
            double dist = sqrt(dx * dx + dy * dy);
            sum += dist;
        }
    }while(next_permutation(v.begin(), v.end()));
    
    int n = 1;
    for(int i = 2; i <= N; ++i) n *= i;
    
    printf("%.10f\n", sum / n);
}


Measured memory_bytes: 256
from itertools import permutations

n=int(input())
P=tuple(map(int,input().split()))
Q=tuple(map(int,input().split()))

L=[_+1 for _ in range(n)]

a=1
for i in list(permutations(L)):
    if i==P:
        break
    a+=1

b=1
for i in list(permutations(L)):
    if i==Q:
        break
    b+=1

print(abs(a-b))

Measured memory_bytes: 8052
from collections import defaultdict, Counter, namedtuple, deque
import itertools
import functools
import bisect
import heapq
import math
# MOD = 10**9+7
# MOD = 998244353

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

dega = h*30 + m*0.5
degb = m*6

dif = dega - degb if dega >= degb else degb - dega
dif = min(dif, 360 - dif)
# print(dif)

c2 = a**2 + b**2 - 2*a*b*math.cos(dif*math.pi/180)

print(math.sqrt(c2))

Measured memory_bytes: 68620
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<int,int>

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n,k;
    cin>>n>>k;
    ll ar[n],rem[n],sum=0;
    map<ll,vector<ll> > m;
    for(ll i=0;i<n;++i)
    {
        cin>>ar[i];
        sum+=ar[i];
        rem[i]=sum%k;
        if(m.find(rem[i])==m.end())
        {
            vector<ll> cr;
            cr.pb(i);
            m.insert(mp(rem[i],cr));
        }
        else
        {
            m[rem[i]].pb(i);
        }
    }
    ll ans=0;
    for(ll i=0;i<n;++i)
    {
        vector<ll> ::iterator it;
        it=lower_bound(m[rem[i]].begin(),m[rem[i]].end(),i);
        ll tt1=it-m[rem[i]].begin();
        //cout<<tt1<<endl;
        ans+=tt1;
        if(rem[i]==0){++ans;}
    }
    cout<<ans;


return(0);
}

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


int main() {
  vector<int> a(100);
  vector<int> b(100);
  for(int i = 0 ; i<100;i++){
    cin >> a.at(i);
    cin >> b.at(i);
    if( a.at(i)==0){
      break;
    }
    for(int j = 0 ; j< a.at(i) ; j++){
      if(j==0||j==a.at(i)-1){
       for(int k = 0 ; k< b.at(i) ; k++){
        cout << "#" ;
       }
      cout << endl;
      }
      else{
        for(int l = 0 ; l< b.at(i) ; l++){
         if(l==0 || l==b.at(i)-1){
           cout << "#" ;
         }
         else{
           cout << "." ;
         }
        }
        cout << endl;
      }
    }
    cout << endl;
  }
}
    


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long fac(long long n){
	long long ret = 1;
	for(long long i = 1; i<=n; i++){
		ret*=i;
		ret%=mod;
	}
	return ret;
}
long long ferma(long long n,long long r){
	if(r==0) return (long long)1;
	if(r==1) return n;
	long long ret = ferma(n,r/2);
	ret*=ret;
	ret%=mod;
	if(r%2) ret*=n;
	return ret%mod;
}
int main(){
	long long x,y;
	cin>>x>>y;
	if(x<y) swap(x,y);
	if(x>2*y) cout<<0;
	else if(x==2*y) cout<<1;
	else{
		long long one = x-y;
		x-=2*one;
		y-=one;
		if(x%3) cout<<0;
		else{
			one+=x/3;
			long long two = x/3;
			long long a = fac(one)*fac(two);
			a = ferma(a%mod,mod-2);
			cout<<(fac(one+two)*a)%mod;
		}
	}
}

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

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

    int sum;
    if (n % 2 == 0) {
        sum = (n / 2) * (n + 1);
    } else {
        sum = ((n + 1) / 2) * n;
    }

    cout << sum << endl;

    return 0;
}

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

#define CIN2(a,b) long long a,b;cin >> a >> b;
#define CIN3(a,b,c) long long a,b,c;cin >> a >> b >> c;
#define rep(i,n) for(int i=0,i##_len=(n); i<i##_len; ++i)

int main(){
    CIN2(a,b)
    if(b%a){
        cout << b-a << endl;
    }else{
        cout << b+a << endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
#include <random>
using namespace std;

//make_tuple emplace_back next_permutation
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(...) string s999=#__VA_ARGS__;replace(ALL(s999),',',' ');stringstream ds999; ds999<<s999; debug(ds999,__VA_ARGS__);
inline void debug(stringstream& ds){cerr<<endl;return;}
template<typename F, typename... R>void debug(stringstream& ds,const F& f, const R&... r){string n; ds>>n; cerr<< n <<' '<<f<<' '; debug(ds,r...);}
#define ALL(v) (v).begin(),(v).end()
#define SI(v) (int)(v).size()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
typedef pair<int,int>PI; typedef vector<int> VI;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y,ans=2e9+10;
    cin >> x >> y;
    /*if(x>=0 and y>x) ans=y-x;
    else if (x>=0 and 0<=y and y<x) ans=x-y+2;
    else if(x>=0 and y<0)ans=min(x-y);
*/
    if(abs(x)<=abs(y))ans=min(ans,abs(y)-abs(x)+(abs(x)==x?0:1)+(abs(y)==y?0:1));
    if(1)ans=min(ans,abs(x)+abs(y)+(abs(x)==x?0:1)+(-abs(y)==y?1:0));
    if(-abs(x)<=-abs(y))ans=min(ans,abs(x)-abs(y)+(-abs(x)==x?0:1)+(-abs(y)==y?0:1));
    cout << ans<<endl;

    return 0;
}


Measured memory_bytes: 256
class Queue():
    def __init__(self):
        self.queue = [None] * 100000
        self.head = 0
        self.tail = 0
        self.max_queue = len(self.queue)

    def is_empty(self):
        return self.head == self.tail

    def is_full(self):
        return self.head == (self.tail + 1) % self.max_queue

    def enqueue(self, x):
        if self.is_full():
            raise ValueError("Error: Full!")

        self.queue[self.tail] = x

        if self.tail + 1 == self.max_queue:
            self.tail = 0
        else:
            self.tail += 1

    def dequeue(self):
        if self.is_empty():
            raise ValueError("Error: Empty!")

        x = self.queue[self.head]

        if self.head + 1 == self.max_queue:
            self.head = 0
        else:
            self.head += 1
        return x


process_name = Queue()
process_cost = Queue()

n, q = map(int, input().split())

for i in range(n):
    name, time = input().split()
    time = int(time)

    process_name.enqueue(name)
    process_cost.enqueue(time)

at_time = 0
while not process_name.is_empty():
    name = process_name.dequeue()
    cost = process_cost.dequeue()
    if cost > q:
        process_name.enqueue(name)
        process_cost.enqueue(cost - q)
        at_time += q
    else:
        at_time += cost
        print(f"{name} {at_time}")
        pass

    pass







Measured memory_bytes: 12948
#include<bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	if (a > b)swap(a, b);
	if ((b - a) % 2 == 0) {
		cout << (b - a) / 2 << endl;
	}
	else {
		cout << min((a + b - 1) / 2, (2*n - a - b + 1) / 2);
	}
}

Measured memory_bytes: 256
foo :: [Int] -> Bool
foo [] = True
foo nums = fst $ foldl bar (True, head nums) $ tail nums

bar :: (Bool, Int) -> Int -> (Bool, Int)
bar (False, _) _ = (False, 0)
bar (True,  x) y
  | x > y = (False, 0)
  | x == y = (True, y)
  | otherwise = (True, y-1)

showFoo :: Bool -> String
showFoo True = "Yes"
showFoo _    = "No"

main = do
  _ <- getLine
  ints <- map read . words <$> getLine :: IO [Int]
  putStrLn $ showFoo $ foo ints



Measured memory_bytes: 38268
#include<iostream>
using namespace std;
int main(){
    int a,b,k;  cin>>a>>b>>k;
    if(b-a<2*k)for(int i=a;i<=b;i++)cout<<i<<endl;
    else{
        for(int i=0;i<k;i++)cout<<a+i<<endl;
        for(int i=0;i<k;i++)cout<<b-k+i+1<<endl;
    }
    return 0;
}

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

// Order statistics tree (if supported by judge!):
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;

// template<class TK, class TM> using order_tree = tree<TK, TM, less<TK>, rb_tree_tag, tree_order_statistics_node_update>;
// iterator	find_by_order(int r) (zero based)
// int		order_of_key(TK v)
// template<class TV> using order_set = order_tree<TV, null_type>;

#define x first
#define y second
#define rs resize
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define rep(i,a,b) for(auto i=(a);i!=(b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<ii> vii;
template<class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;

template<class T1, class T2>
ostream& operator<<(ostream &out, const pair<T1,T2> &a) { return out << '(' << a.x << ", " << a.y << ')'; }
template<class T1, class T2>
istream& operator>>(istream &in, pair<T1,T2> &a) { return in >> a.x >> a.y; }

template<class T> int sz(const vector<T> &v) { return (int) v.size(); }

template<class T> ostream& operator<<(ostream &os, vector<T> v) {
	os << "\n[";
	for(T &x : v) os << x << ',';
	return os << "]\n";
}

const int INF = 2147483647;
const ll LLINF = 9223372036854775807LL;

// lambda-expression: [] (args) -> retType { body }

void run() {
	int n;
	cin >> n;
	vi P(n);
	REP(i, n) cin >> P[i];

	int minJ = INT_MAX, ans = 0;
	for (int i=0; i <n ; i++) {
		if (P[i] <= minJ)
			ans++;
		minJ = min(minJ, P[i]);
	}
	cout << ans << endl;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr << boolalpha;
	(cout << fixed).precision(10);

	run();

	return 0;
}


Measured memory_bytes: 1024
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
        Scanner sc = new Scanner(System.in);
        String strDate = sc.next();
        SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy/MM/dd");
        Date date = new Date();
        Date targetDate = new Date();;
        try {
        	date = sdFormat.parse(strDate);
        	targetDate = sdFormat.parse("2019/04/30");
        }catch(Exception e){

        }

        String msg = "Heisei";
        if(date.after(targetDate)) {
        	msg = "TBD";
        }
        System.out.println(msg);
	}

}


Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<utility>
#include<cstdio>
#include<cstring>
#include<new>
#include<float.h>
#include<ctype.h>
#include<cfloat>
#include<cmath>
#include<cctype>
#include<errno.h>
#include<cerrno>
#include<memory>
#include<memory.h>
#include<assert.h>
#include<cassert>
#include<deque>
#include<sstream>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qui queue<int>
#define vit vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define prq priority_queue
#define pii pair<int,int>
#define mp make_pair
#define sz size()
#define em empty()
#define ct continue
#define ms multiset
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define ppf pop_front()
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	if(a<=0&&b>=0)cout<<"Zero";
	else if(a<0&&b<0){
		if((b-a)%2)cout<<"Positive";
		else cout<<"Negative";
	}
	else cout<<"Positive";
	return 0;
}


Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
ar=((h+m/60)%12)/12 * math.pi * 2
ax=a*math.sin(ar)
ay=a*math.cos(ar)
br=((h*60+m)%60)/60 * math.pi * 2
bx=b*math.sin(br)
by=b*math.cos(br)
print( ( (ax-bx)**2+(ay-by)**2 )**0.5 )

Measured memory_bytes: 9520
//インクルード
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>

//型宣言
typedef long long ll;
typedef unsigned long long ull;
typedef std::string string;
typedef ll answerType;

//変数宣言
ll N;
answerType answer;

//関数のプロトタイプ宣言
//入力の取得
void getInput();
//答えを求める
answerType calcAnswer();

//メイン関数
int main() {
	//入力の取得
	getInput();

	//答え
	answerType answer = calcAnswer();

	//答えの出力
	std::cout << answer << std::endl;

	//正常終了
	return EXIT_SUCCESS;
}

//入力の取得
void getInput() {
	std::cin >> N;
}

//答えを求める
answerType calcAnswer() {
	ll temp = N * 800;
	ll temp2 = N / 15;
	ll temp3 = temp2 * 200;
	return temp - temp3;
}


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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

const double EPS = 1e-8;

using R = long double;
using P = complex<R>;
using L = pair<P,P>;

inline int sgn(const R& r) { return (r>EPS) - (r<-EPS); }
namespace std {
	bool operator < (const P& a, const P& b) {
		return sgn(real(a-b)) ? real(a-b) < 0 : sgn(imag(a-b)) < 0;
	}
	bool operator == (const P& a, const P& b) {
		return sgn(real(a-b)) == 0 && sgn(imag(a-b)) == 0;
	}
}
inline R dot(const P& a, const P& b) {
  return real(a)*real(b) + imag(a)*imag(b);
}
inline R det(const P& a, const P& b) {
  return real(a)*imag(b) - imag(a)*real(b);
}
// a/b
inline P div(const P &a, const P &b) {
  return {dot(b,a)/norm(b), det(b,a)/norm(b)};
}

// PとLについて入力
inline istream& operator>>(istream& is, P& p) {
  R x, y;
  is >> x >> y;
  p = P(x, y);
  return is;
}
inline istream& operator>>(istream& is, L& l) {
  P a, b;
  is >> a >> b;
  l = L(a, b);
  return is;
}

// 線分abから見たcの位置
enum CCW{LEFT=1, RIGHT=2, BACK=4, FRONT=8, ON=16};
int ccw(P a, P b, P c) {
	P p = div(c-a, b-a);
	if(sgn(imag(p)) > 0) return LEFT;
	if(sgn(imag(p)) < 0) return RIGHT;
	if(sgn(real(p)) < 0) return BACK;
	if(sgn(real(p)-1) > 0) return FRONT;
	return ON;
}

P projection(const L &l, const P &p) {
	R t = dot(p-l.first, l.first-l.second) / norm(l.first-l.second);
	return l.first + t*(l.first-l.second);
}
// 反射
P reflection(const L &l, const P &p) {
	return p + (R)2 * (projection(l, p) - p);
}

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

  L l;
  cin >> l;
  int q;
  cin >> q;
  REP(i, q) {
    P p;
    cin >> p;
    P ret = projection(l, p);
    cout << fixed << setprecision(9) << real(ret) << " " << imag(ret) << endl;
  }

  return 0;
}



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

int main() {
    int N;
    cin >> N;
    vector<int>x(N);
    vector<int>y(N);
    for (int i = 0; i < N; ++i) {
      cin >> x[i] >> y[i];
    }

    // x, yをソート
    vector<pair<int, int>> xy(N);
    vector<pair<int, int>> yx(N);
    for (int i = 0; i < N; ++i) {
        xy[i] = make_pair(x[i], y[i]);
        yx[i] = make_pair(y[i], x[i]);
    }
    sort(xy.begin(), xy.end());
    sort(yx.begin(), yx.end());
    for (int i = 0; i < N; ++i) {
        x[i] = xy[i].first;
        y[i] = yx[i].first;
    }

    // mapで探索済みか管理
    map<pair<int, int>, int> mp;
    for (int i = 0; i < N; ++i) {
        mp[xy[i]] = 0;
    }

    ll ans = 0; // 操作後の点の数
    stack<pair<int, int>> st;
    stack<int> coY; // stの点とx座標が同じ点のy座標
    for (int i = 0; i < N; ++i) {
        if(mp[xy[i]] == 0){
            set<int> setX;
            set<int> setY;
            st.push(xy[i]);
            while (! st.empty()){
                while (! st.empty()){
                    auto top = st.top();
                    st.pop();
                    if(setX.count(top.first) == 0){
                        setX.insert(top.first);
                        auto iter1 = lower_bound(x.begin(), x.end(), top.first);
                        auto iter2 = upper_bound(x.begin(), x.end(), top.first);
                        for (int j = iter1 - x.begin(); j < iter2 - x.begin(); ++j) {
                            if(mp[xy[j]] == 0){
                                mp[xy[j]] = 1;
                                coY.push(xy[j].second);
                            }
                        }
                    }
                }
                while (! coY.empty()){
                    int top = coY.top();
                    coY.pop();
                    if(setY.count(top) == 0){
                        setY.insert(top);
                        auto iter1 = lower_bound(y.begin(), y.end(), top);
                        auto iter2 = upper_bound(y.begin(), y.end(), top);
                        for (int j = iter1 - y.begin(); j < iter2 - y.begin(); ++j) {
                            pair<int, int> rev = make_pair(yx[j].second, yx[j].first);
                            if(mp[rev] == 0){
                                mp[rev] = 1;
                                st.push(rev);
                            }
                        }
                    }
                }
            }

            ll temp = setX.size();
            temp *= setY.size();
            ans += temp;
        }
    }

    ans -= N;
    cout << ans;
    return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vector<vi> e(n, vi(n));
	
	for(int d = 1, lv = 1; d < n; d *= 2){
		
		rep(k, d){
			for(int i = k; i < n; i += d)
			for(int j = i + d; j < n; j += d) if((j - i) / d % 2)
			e[i][j] = e[j][i] = lv;
		}
		lv++;
	}
	
	rep(i, n) for(int j = i + 1; j < n; j++) cout << e[i][j] << (j==n-1?"\n":" ");
	
	return 0;
}

Measured memory_bytes: 1536
import java.io.*;
class Main {
 public static void main(String[] args) throws IOException{
	try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ){
		final int target = Integer.parseInt( br.readLine() );
        int result = (target%2 == 0) ? target*target/4 : (target/2+1)*(target/2);
		System.out.println(result);
	}
 }
}

Measured memory_bytes: 21076
#include <iostream>
using namespace std;
int main (){

  int a[3];

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

  if(a[0] == 1 && a[1] == 1 && a[2] == 0){
    cout <<"Open"<<endl;
  }else if(a[0] == 0 && a[1] == 0 && a[2] == 1){
    cout <<"Open"<<endl;
  }else{
    cout <<"Close"<<endl;
  }


  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>

int main()
{
  int n, x, i, j, k, count;
  while (true) {
    count = 0;
    scanf("%d %d", &n, &x);
    if (n == 0 && x == 0) break;
    if (n >= 3 && n <= 100) {
      if (x >= 0 && x <= 300) {
        for (i = 1; i <= n; i++) {
          for (j = i + 1; j <= n; j++) {
            for (k = j + 1; k <= n; k++) {
              if (i + j + k == x) count++;
            }
          }
        }
      }
      printf("%d\n", count);
    }
  }
}



Measured memory_bytes: 2740
#include "bits/stdc++.h"
#define hhh cerr<<"hhh"<<endl
#define see(x) cerr<<(#x)<<'='<<(x)<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pr;
inline int read() {int x=0,f=1;char c=getchar();while(c!='-'&&c<48)c=getchar();if(c=='-')f=-1,c=getchar();while(c>47)x=x*10+(c^48),c=getchar();return f*x;}

const int maxn = 3e5+7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;



int main() {
    string s, t;
    cin>>s>>t;
    int n=s.size(), m=t.size();
    s='0'+s;
    int ans=inf;
    for(int i=1; i<=n-m+1; ++i) {
        int tmp=0;
        for(int j=0; j<m; ++j) {
            tmp+=s[i+j]!=t[j];
        }
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<stack>

using namespace std;

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

int main() {
  int n;
  stack<int> st;
  while (cin >> n) {
    if (n == 0) {
      cout << st.top() << endl;
      st.pop();
    } else {
      st.push(n);
    }
  }
  return 0;
}

Measured memory_bytes: 1200
N, = map(int, input().split())
X = list(map(int, input().split()))
X.append(0)
S = 1000
st = 0
for i in range(N):
    if X[i+1] > X[i]:
        d, S = divmod(S, X[i])
        st += d
    else:
        S += st * X[i]
        st = 0
print(S)


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

int n;
double d[3010];
double dp[3010][3010];

double rek(int x, int y) {
	if (x == n) {
		if (y > (int)(n/2)) return 1;
		return 0;
	}
	
	double &ret = dp[x][y];
	if (ret != -1.0) {
		return ret;
	}
	
	ret = rek(x+1, y+1) * d[x] + rek(x+1, y) * (1 - d[x]);
	
	return ret;
}

int main () {
	
	scanf("%d", &n);
	for (int i = 0; i < n; i ++) {
		scanf("%lf", &d[i]);
		for (int j = 0; j <= n; j ++) {
			dp[i][j] = -1.0;
		}
	}
	
	printf("%.10lf", rek(0, 0));
	
	
	return 0;
}

Measured memory_bytes: 71040
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio (false) ;cin.tie(NULL);
#define tc  int t;cin>>t;for(int i=0;i<t;i++)
#define ll long long int
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define um(a,b) unordered_map<a,b>
#define vv(a) vector<a>
#define pp(a,b) pair<a,b>
ll power(ll a,ll b,ll mod){  ll ans=1;  while(b>0){
  if(b&1){ ans=(ans*a)%mod;} a=(a*a)%mod;  b=b/2; } return ans;}

int main(){
FIO
ll n;
cin>>n;
ll s=400;
 for(ll i=8;i>=1;i--){
    s=s+200;
    if(n<s){
     cout<<i<<endl;
     break;
    }
 }
}


Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    ll n, x, m;
    cin >> n >> x >> m;
    vector<ll> a(1000000, 0);
    map<ll, ll> p;
    a[0] = x;

    for (int i = 0; i < m; i++)
    {
        p[i] = INF;
    }

    ll end, start;

    for (int i = 0; i < 1000000; i++)
    {
        a[i + 1] = a[i] * a[i] % m;

        if (p[a[i]] != INF)
        {
            end = i;
            start = p[a[i]];
            break;
        }

        p[a[i]] = i;
    }

    ll ans = 0;

    for (int i = 0; i < start; i++)
    {
        ans += a[i];
    }

    ll tmp = 0;

    n -= start;

    for (int i = start, cnt = 0; i < end; i++, cnt++)
    {
        if (cnt < n % (end - start))
        {
            ans += a[i];
        }

        tmp += a[i];
    }

    ans += tmp * (n / (end - start));

    cout << ans << endl;
}


Measured memory_bytes: 17232
@F=map[glob<>],1..<>;
@P=map[glob],<>;
printf sort{$b-$a}map{
	$x=!//;
	for$f(@F){
		$x+=$P[$i++%@P][grep$'>>$_&1&&@$f[$_],0..9]
	}
	$x
}1..1023


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

#define foreach(i, v) for(__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define BETWEEN(a, x, b) (a<=x&&x<b)

using namespace std;
typedef long long ll;

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

  int a,b,c,d;cin>>a>>b>>c>>d;
  cout<<min(a,b)+min(c,d)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
int gcd(int a, int b) { if (a % b == 0) { return(b); } else { return(gcd(b, a % b)); } }


long long int value(long long int x, long long int A, long long int B) {
	return floor(A * x / B) - A * floor(x / B);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);

	long long int A, B, C, K;
	cin >> A >> B >> C >> K;
	long long int sum = 0;

	if (A < K) {
		sum += A;
		K = K - A;
	}
	else {
		sum += K;
		cout << sum;
		return 0;
	}
	if (B < K) {
		K = K - B;
	}
	else {
		cout << sum;
		return 0;
	}
	if (C < K) {
		sum -= C;
		K = K - C;
	}
	else {
		sum -= K;
		cout << sum;
		return 0;
	}

	return 0;
}


Measured memory_bytes: 3612
N=int(input())
S=input()
ans=0
c=0
for s in S:
    
    if s=="A":
        c=1
    elif s=="B" and c==1:
        c=2
    elif s=="C" and c==2:
        ans+=1
        c=0
    else:
        c=0

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>


int main(void){
	int height, width, h, w;
	
	scanf("%d %d", &height, &width);
	
	while(!(height == 0 && width == 0)){
		for(h = 0; h < height; h++){
			for(w = 0; w < width; w++){
				putchar('#');
			}
			putchar('\n');
		}
		putchar('\n');
		scanf("%d %d", &height, &width);
	}
	return 0;
}

Measured memory_bytes: 572
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define double long double
#define pi 3.141592653589
using namespace std;
signed main() {
	ll q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	h = min(h, q * 2);
	s = min(h * 2, s);
	d = min(s * 2, d);
	cout << n / 2 * d + n % 2 * s << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 256
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
    stack<int> s;
    char str[20];
    int op1, op2, val;
    while (cin >> str)
    {
        if (str[0] == '+' || str[0] == '-' || str[0] == '*')
        {
            op2 = s.top();
            s.pop();
            op1 = s.top();
            s.pop();
            switch (str[0])
            {
            case '+':
                val = op1 + op2;
                break;
            case '-':
                val = op1 - op2;
                break;
            case '*':
                val = op1 * op2;
                break;
            }
            s.push(val);
        }
        else
        {
            s.push(atoi(str));
        }
    }

    val = s.top();
    cout << val << endl;
}



Measured memory_bytes: 3092
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-03-25 10:09:00
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#include<map>
namespace run
{
	const int N=1000010,inf=12345678;
	int n,begin[N],next[N],to[N],e,w[N],ans,id[N],Id[N],m,d[N],q[N],l,r,cur[N],S,T;
	int a[N],b[N];
#define pii std::pair<int,int>
	std::map<pii,int> E;
	void add(int u,int v,int W)
	{
		if(E.count(pii(u,v))){ w[E[pii(u,v)]]+=W; return ; }
		E[pii(u,v)]=++e; next[e]=begin[u]; begin[u]=e; to[e]=v; w[e]=W;
	}
#define fo(i,a) for(int &i=cur[a];i;i=next[i])
	int bfs()
	{
		fr(i,1,m) cur[i]=begin[i];
		fr(i,1,m) d[i]=inf;
		d[T]=0; q[l=r=1]=T;
		while(l<=r)
		{
			int u=q[l++];
			fo(i,u) if(w[i^1]&&d[u]+1<d[to[i]])
			{
				d[to[i]]=d[u]+1; q[++r]=to[i];
			}
		}
		fr(i,1,m) cur[i]=begin[i];
		return d[S]!=inf;
	}
	int dfs(int u,int F)
	{
		if(!F||u==T) return F;
		int ans=0;
		fo(i,u) if(w[i]&&d[u]-1==d[to[i]])
		{
			int f=dfs(to[i],std::min(w[i],F));
			w[i]-=f; w[i^1]+=f; F-=f; ans+=f;
		}
		return ans;
	}
	int main()
	{
		n=read(); S=++m; T=++m; e=1;
		fr(i,1,n) a[i]=read()+1;
		fr(i,1,n) b[i]=read()+1;
		fr(i,1,n) if(!id[i])
		{
			int I=i; m++;
			do{ id[I]=m; I=a[I]; } while(I!=i);
		}
		fr(i,1,n) if(!Id[i])
		{
			int I=i; m++;
			do{ Id[I]=m; I=b[I]; } while(I!=i);
		}
		ans=n;
		fr(i,1,n)
		{
			if(a[i]==b[i]){ if(a[i]!=i){ add(id[i],Id[i],1); add(Id[i],id[i],1); } else ans--; }
			else if(a[i]==i){ add(Id[i],T,1); add(T,Id[i],0); }
			else if(b[i]==i){ add(S,id[i],1); add(id[i],S,0); }
			else{ add(id[i],Id[i],0); add(Id[i],id[i],1); }
		}
		while(bfs()) ans-=dfs(S,inf);
		printf("%d\n",ans);
		return 0;
	}
}
int main()
{
	return run::main();
}

Measured memory_bytes: 33536
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    auto dq = new Deque!int(a.length);
    dq.pushBack(a[0]);
    foreach (e; a.drop(1)) {
        int lo = 0;
        int hi = dq.size() - 1;
        int best = hi + 1;
        while (lo <= hi) {
            int m = (lo + hi) / 2;
            if (dq[m] >= e) {
                best = min(best, m);
                hi = m - 1;
            } else lo = m + 1;
        }

        if (best == 0) dq.pushFront(e);
        else dq[best-1] = e;
    }
    return dq.size();
}

void main() {
    int n = readint;
    int[] a;
    foreach (_; 0..n) a ~= readint;
    writeln(calc(a));
}

class Deque(T) {
    private T[] _buffer;
    private size_t _size;
    private int _front;
    private int _back;

    this(size_t size) {
        _buffer = new T[size * 3];
        _size = 0;
        _front = _back = cast(int)size * 3 / 2;
    }

    @property bool empty() {
        return _size == 0;
    }

    int size() {
        return cast(int)_size;
    }

    void pushFront(T elt) {
        _buffer[empty ? _front : --_front] = elt;
        _size++;
    }

    void pushBack(T elt) {
        _buffer[empty ? _back : ++_back] = elt;
        _size++;
    }

    T opIndex(size_t index) {
        return _buffer[_front + index];
    }

    T opIndexAssign(T value, size_t index) {
        return _buffer[_front + index] = value;
    }
}


Measured memory_bytes: 4860
#include<iostream>

using namespace std;

int main()
{
	int sx,sy,tx,ty;
	cin >> sx >> sy >> tx >> ty;
	
	for(int i=0;i<ty-sy;i++)
		cout<<"U";
	for(int i=0;i<tx-sx;i++)
		cout<<"R";	
	for(int i=0;i<ty-sy;i++)
		cout<<"D";
	for(int i=0;i<tx-sx;i++)
		cout<<"L";
	
	cout<<"L";
	for(int i=0;i<ty-sy+1;i++)
		cout<<"U";
	for(int i=0;i<tx-sx+1;i++)
		cout<<"R";
	cout<<"D";
	cout<<"R";
	for(int i=0;i<ty-sy+1;i++)
		cout<<"D";
	for(int i=0;i<tx-sx+1;i++)
		cout<<"L";
	cout<<"U"<<endl;

}



Measured memory_bytes: 256