akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
char a;
int main(){
	ios::sync_with_stdio(0);
	cin>>a;
	if(a>='a')
	cout<<'a';
	else
	cout<<"A";
	re 0;
}

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

string get(int a, int keta){
  string ret = "";
  if(a > 9 || keta > 1) ret += get(a / 10, keta - 1);
  ret += (char)('0' + a % 10);
  return ret;
}
int toint(string s){
  return(atoi(s.c_str()));
}


int main(){
  int a, L;
  while(cin >> a >> L, a|L){
    map< string, int > used;
    int cnt = 0;
    while(used.count(get( a, L)) == 0){
      string xx = get( a, L), yy = xx;
      used.insert(make_pair(xx,cnt));
      sort( xx.begin(), xx.end());
      sort( yy.rbegin(), yy.rend());
      a = toint(yy) - toint(xx);
      cnt++;
    }
    cout << used[get(a,L)] << " " << toint(get( a, L)) << " " << cnt - used[get(a,L)] << endl;
  }
}

Measured memory_bytes: 1244
#import math
from fractions import gcd
'''
3.7 以降は、Math
以前は、
from fractions import gcd 
'''
a, b, k = map(int, input().split())
# 最大公約数のK倍。

'''
def lcm(x, y):
    # // for integer answer
    #ll = (x * y) // math.gcd(x, y)
    ll = (x * y) // gcd(x, y)
    return ll
'''

ans = [i for i in range(1, 200) if (a % i == 0 and b % i == 0)]
print(ans[-k])
# print(int(ans))


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

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

using namespace std;

int n, m;
int g[8][8];
int dp[1 << 8][8];

int main(){
  scanf("%d%d", &n, &m);
  rep(i, m){
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a][b] = g[b][a] = 1;
  }

  dp[(1 << n) - 2][0] = 1;
  for(int i = (1 << n) - 3; i >= 0; --i){
    rep(j, n){
      rep(k, n){
        if(g[j][k] && !(i >> j & 1)){
          dp[i][j] += dp[i | 1 << j][k];
        }
      }
    }
  }
  int a = 0;
  rep(i, n){
    a += dp[0][i];
  }
  printf("%d\n", a);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
    int x = Integer.parseInt(sc.next());
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
String ans="";
if(a-b>=0){ans="delicious";
}else if(b-a<=x){ans="safe";
}else{ans="dangerous";}
    out.println(ans);
}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>

using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll a, b, x;
	cin >> a >> b >> x;
	ll ans = 0;
	if (a % x == 0) {
		ans = static_cast<ll>(b / x) - a / x + 1;
	} else {
		ans = static_cast<ll>(b / x) - static_cast<ll>(a / x);
	}
	
	cout << ans << endl;
	
	
	
	
	
	return 0;
	
}

Measured memory_bytes: 256
import numpy as np
X = []
for i in range(5):
  tmp = int(input())
  X.append(tmp)

X_remain = np.zeros(5)
for i in range(5):
  if X[i] % 10 == 0:
    X_remain[i] = 0
  else:
    X_remain[i] = 10 -(X[i] % 10)
#print(X_remain)

ans = 0
count = 0
for i in range(10):
  for j in range(5):
    if X_remain[j] == i:
      if count < 4:
        ans += X[j] + X_remain[j]
        count += 1
      else:
        ans += X[j]
print(int(ans))
      
  

  

Measured memory_bytes: 27156
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<int>> tmp(n), g(n);
        for (int i = 0; i < n - 1; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                tmp[a].push_back(b);
                tmp[b].push_back(a);
        }
        string s;
        cin >> s;
        int root = -1;
        for (int i = 0; i < n; i ++) {
                if (s[i] == 'W') {
                        root = i;
                        break;
                }
        }
        if (root == -1) {
                printf("0\n");
                return 0;
        }
        int tozan = 0;
        for (int i = 0; i < n; i ++) {
                tozan += s[i] == 'W';
        }
        if (tozan == 1) {
                printf("1\n");
                return 0;
        }
        int nn = 1;
        vector<bool> all_black(n, false);
        function<void (int, int)> dfs = [&](int u, int prev) {
                all_black[u] = s[u] == 'B';
                for (auto v : tmp[u]) if (v != prev) {
                        dfs(v, u);
                        all_black[u] = all_black[u] && all_black[v];
                }
                for (auto v : tmp[u]) if (v != prev) {
                        if (!all_black[v]) {
                                nn ++;
                                g[u].push_back(v);
                                g[v].push_back(u);
                        }
                }
        };
        dfs(root, -1);
        vector<bool> good(n);
        int gc = 0;
        for (int i = 0; i < n; i ++) {
                if ((int) g[i].size() == 0) continue;
                int deg = (int) g[i].size();
                good[i] = (deg % 2 == 0 && s[i] == 'W') || (deg % 2 == 1 && s[i] == 'B');
                if (good[i]) gc ++;
        }
        function<pair<int, int> (int, int)> dfs2 = [&](int u, int prev) {
                auto ma = make_pair(-1, -1);
                bool il = true;
                for (auto v : g[u]) if (v != prev) {
                        ma = max(ma, dfs2(v, u));
                        il = false;
                }
                if (il) {
                        return make_pair((good[u] ? 1 : 0), u);
                }
                ma.first += good[u] ? 1 : 0;
                return ma;
        };
        int dist, node;
        tie(dist, node) = dfs2(root, -1);
        int cnt;
        tie(cnt, node) = dfs2(node, -1);
        printf("%d\n", 2 * (nn - 1) + gc - 2 * cnt);
        return 0;
}


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

using namespace std;

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

#define REP(i, a, n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define N 100010
#define M 200010
#define endl "\n"

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n, arr[N];
	
	cin >> n;
	REP(i, 0, n){
		cin >> arr[i];
	}
	
	int cnt = 0, ans = 0;
	int curr = arr[0];
	
	REP(i, 1, n){
		if(curr >= arr[i]){
			cnt++;
		}
		else{
			ans = max(ans, cnt);
			cnt = 0;
		}
		
		curr = arr[i];
	}
	
	ans  = max(ans, cnt);
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int k = sc.nextInt();

        int x = sc.nextInt();

        if (x <= 500 * k) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 23636
import itertools
n, m, x = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(n)]

mn = 10**18
l = [i for i in range(n)]
for cnt in range(1, n+1):
    for v in itertools.combinations(l, cnt):
        cost = 0
        tm = [0]*m
        for vv in v:
            cost += c[vv][0]
            for j in range(1, m+1):
                tm[j-1] += c[vv][j]
        flag = True
        for i in range(m):
            if tm[i] < x:
                flag = False
                break
        if flag:
            mn = min(cost, mn)

if mn == 10**18:
    print(-1)
else:
    print(mn)


Measured memory_bytes: 9176
#include <stdio.h>
int main(void) {
    int num,i,j,k,fund,year,kind,type,fee,interest,max,temp;
    double rate;
    scanf("%d",&num);
    for (i=0; i<num; i++) {
        scanf("%d %d %d",&fund,&year,&kind);
        max=0;
        for (j=0; j<kind; j++) {
            scanf("%d %lf %d",&type,&rate,&fee);
            temp=fund;
            if (type==0) {
                interest=0;
                for (k=0; k<year; k++) {
                    interest+=temp*rate;
                    temp-=fee;
                }
                if (temp+interest>max) max=temp+interest;
            } else {
                for (k=0; k<year; k++) temp=temp*(1.0+rate)-fee;
                if (temp>max) max=temp;
            }
        }
        printf("%d\n",max);
    }
    return 0;
}

Measured memory_bytes: 632
n=input()
#n=int(input())
#li=input().split()
#li=list(map(int,input().split()))
#d=["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"]
#import math
#import numpy as np
ans=0
tmp=0
dict={"A","C","G","T"}
for i in range(len(n)):
    if n[i] in dict:
        tmp+=1
    else:
        if ans<tmp:
            ans=tmp
        tmp=0
if ans<tmp:
    ans=tmp


print(ans)


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

const li mod = 1e9 + 7;


int main() {
    li l;
    cin >> l;
    vector<li> xs(l);
    for (int i = 0; i < l; ++i) {
        cin >> xs[i];
    }

    vector<li> degs(l + 1);
    for (int i = 0; i < l; ++i) {
        degs[i] += xs[i];
        degs[i + 1] += xs[i];
    }

    vector<vector<li>> dp(l + 1, vector<li>(5, 1LL << 55));
    for (int i = 0; i < 5; ++i) {
        dp[0][i] = 0;
    }

    for (int i = 1; i <= l ; ++i) {
        li dupcost = xs[i - 1] ? xs[i - 1] % 2 : 2;
        
        dp[i][0] = min(dp[i][0], dp[i - 1][0] + xs[i - 1]);

        dp[i][1] = min(dp[i][1], dp[i - 1][0] + xs[i - 1]);
        dp[i][1] = min(dp[i][1], dp[i - 1][1] + dupcost);

        dp[i][2] = min(dp[i][2], dp[i - 1][0] + xs[i - 1]);
        dp[i][2] = min(dp[i][2], dp[i - 1][1] + dupcost);
        dp[i][2] = min(dp[i][2], dp[i - 1][2] + (xs[i - 1] + 1) % 2);

        dp[i][3] = min(dp[i][3], dp[i - 1][2] + (xs[i - 1] + 1) % 2);
        dp[i][3] = min(dp[i][3], dp[i - 1][3] + dupcost);

        dp[i][4] = min(dp[i][4], dp[i - 1][1] + dupcost);
        dp[i][4] = min(dp[i][4], dp[i - 1][2] + (xs[i - 1] + 1) % 2);
        dp[i][4] = min(dp[i][4], dp[i - 1][3] + dupcost);
        dp[i][4] = min(dp[i][4], dp[i - 1][4] + xs[i - 1]);
    }

    li ans = dp[l][0];
    for (int i = 0; i < 5; ++i) {
        ans = min(ans, dp[l][i]);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
    using namespace std;
     
    /* REPmacro */
    #define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
    #define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
    #define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
     
    /*alias*/
    #define ALL(x) (x).begin(),(x).end()
    #define SZ(x) ((int)(x).size())
    #define F first
    #define S second
    #define PB push_back
    #define EB emplace_back
    #define MP make_pair 
     
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define next asdnext
    #define prev asdprev
    #define itn int
     
    /*using*/
    using ll = long long;
    using ull = unsigned long long;
    using unsi = unsigned;
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;
    using pii = pair<int, int>;
    using db = double;
    using plex = complex<double>;
    using vs = vector<string>;
     
    /*template*/
    template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
     
    /*struct*/
    struct aaa{
        aaa(){
            cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
        };
    }aaaaaaa;
     
    /* const */
    const int INF = 1001001001;
    const ll LINF = 1001001001001001001ll;
    const int MOD = 1e9 + 7; //10^9
    const db EPS = 1e-9;
    const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };  //Counterclockwise from the 9o'clock direction
    //Take the x-axis downward and the y-axis right
     
    //#define int ll
    //#define int long long
     
    //water,sugar,disslove,capacity
    int a,b,c,d,e,f;
     
    signed main()
    {
	cin >>a>>b>>c>>d>>e>>f;


	double con = 0.0;
	int water = 0,sugar = 0;
	for(int w = 0; w <=30; w++){
	for(int x = 0; x <= 30; x++){
	for(int y = 0; y <= ceil((double)f/c); y++){
	for(int z = 0; z <= ceil((double)f/d); z++){
      
		int water_weight = a*w+b*x, sugar_weight = c*y+d*z;
		int total = 100*water_weight + sugar_weight;
      
		if(total <= f && sugar_weight <= water_weight*e){
		  if(con < (double)sugar_weight/total){
            
			con = (double)sugar_weight/total;
			water = 100*water_weight;
			sugar = sugar_weight;
		  }
		}
	 }
	 }
	 }
	 }
      
 	  if(con == 0) water = 100*a;

	  cout << water+sugar << " " << sugar << endl;
      return 0;
    }
/*
frac{Cy+Dz}{100(Aw+Bx)+Cy+Dz}の利用
*/

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  string s1 = "Sunny";
  string s2 = "Cloudy";
  string s3 = "Rainy";

  string s;
  cin >> s;
  string t;
  if (s == s1) t = s2;
  else if (s == s2) t = s3;
  else t = s1;
  cout << t << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<ll,ll> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
#define INF 100000000000000000
ll pw(ll x,ll y){
	ll res=1;
	while(y){
		if(y&1)res=res*x%M;
		x=x*x%M;
		y>>=1;
	}
	return res;
}
ll n,m,d[2005],in[2005];
ll cm(ll x,ll y){
	return d[x]*in[x-y]%M*in[y]%M;
}
int main(void){
	cin>>n>>m;
	d[0]=1,in[0]=1;
	for(ll i=1;i<=2004;i++)d[i]=d[i-1]*i%M,in[i]=pw(d[i],M-2);
	for(ll i=1;i<=m;i++){
		if(n-m+1<i)cout<<0<<endl;
		else cout<<cm(m-1,i-1)*cm(n-m+1,i)%M<<endl;
	}
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
string s;
int N;
bool used[26];
int C[200100];
int nx[200100][26];
int nxt[26];
int cnt = 0;
int cur = 0;
int Next(int pos,int c){
	if(pos==-1)return nxt[c];
	else return nx[pos][c];
}
int main(){
	cin >> s;
	N = (int)s.size();
	for(int i=N-1;i>=0;i--){
		if(!used[s[i]-'a']){
			used[s[i]-'a']=true;
			cnt++;
		}
		if(cnt==26){
			cur++;
			cnt = 0;
			for(int i=0;i<26;i++)used[i]=false;
		}
		C[i]=cur;
	}
	//for(int i=0;i<N;i++)printf("%d",C[i]);
	memset(nxt,-1,sizeof(nxt));
	for(int i=N-1;i>=0;i--){
		for(int j=0;j<26;j++){
			nx[i][j]=nxt[j];
		}
		nxt[s[i]-'a']=i;
	}
	int ans_len = cur+1;
	int pos = -1;
	for(int i=0;i<ans_len;i++){
		for(int j=0;j<26;j++){
			int p = Next(pos,j);
			if(p!=-1&&C[p+1]>=ans_len-i-1)continue;
			printf("%c",'a'+j);
			pos = p;
			break;
		}
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 21636
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
V<int> v;
int n,m,ans,q;
int a[55],b[55],c[55],d[55];
void dfs(int p,int x){
	if(!p){
		int sum=0;
		FOR(i,1,q){
			if(v[b[i]]-v[a[i]]==c[i])sum+=d[i];
		}
		gmax(ans,sum);
		RE;
	}
	FOR(i,x,m){
		v.PB(i);
		dfs(p-1,i);
		v.pop_back();
	}
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m>>q;
	FOR(i,1,q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
		a[i]--;b[i]--;
	}
	dfs(n,1);
	cout<<ans;
	RE 0;
}




Measured memory_bytes: 3660
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int n = sc.nextInt();

		int max_x = w;
		int min_x = 0;
		int max_y = h;
		int min_y = 0;

		for (int i = 0; i < n; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();

			switch(a){
			case 1:
				if(x > min_x){
					min_x = x;
				}
				continue;
			case 2:
				if(x < max_x){
					max_x = x;
				}
				continue;
			case 3:
				if(y > min_y){
					min_y = y;
				}
				continue;
			case 4:
				if(y < max_y){
					max_y = y;
				}
				continue;
			}
		}
		w = max_x-min_x;
		h = max_y-min_y;
		if (w < 0) {
			w = 0;
		}
		if (h < 0) {
			h = 0;
		}
		int white = w * h;
		if(white < 0){
			white = 0;
		}
		System.out.println(white);
		sc.close();
	}
}


Measured memory_bytes: 22228
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;
}


Measured memory_bytes: 764
H, W = map(int, input().split())
 
if H == 1 or W == 1:
  print(1) 
# 両方奇数の場合
elif H%2 == 1 and W%2 == 1:
  print((H*W)//2+1)
else:
  print((H*W)//2)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int l = 0;
    int r = 0;
    int ans = 0;

    for (int i = 0; i < n; i++) {
      l = sc.nextInt();
      r = sc.nextInt();
      ans += (r - l + 1);
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 27236
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<iostream>
#include<queue>
using namespace std;
#define ll long long
#define re register
#define int ll
inline int gi(){
	int sum=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return sum*f;
}
inline ll gl(){
	ll sum=0,f=1;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return sum*f;
}
const int N=200010;
char s[N];int n;
signed main(){
	scanf("%s",s+1);n=strlen(s+1);int tot=0,ans=0;
	for(int i=1;i<=n;i++){
		if(s[i]=='A')tot++;
		else if(s[i]=='B' && s[i+1]=='C')ans+=tot,i++;
		else tot=0;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<ll,ll,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()

//重み付きUnionFind
vector<ll> par(1e6);
vector<ll> ran(1e6);
vector<ll> diff_weight(1e6);
void init(ll n){
  rep(i,n){
    par.at(i)=i;
    ran.at(i)=0;
    diff_weight.at(i)=0;
  }
}
ll find(ll x){
  if(par.at(x)==x){
    return x;
  }else{
    ll f=find(par.at(x));
    diff_weight.at(x)+=diff_weight.at(par.at(x)); // 累積和をとる
    return par.at(x)=f;
  }
}
ll weight(ll x) {
  find(x); // 経路圧縮
  return diff_weight.at(x);
}
void unite(ll x,ll y,ll w){
  w+=weight(x);
  w-=weight(y);
  x=find(x);
  y=find(y);
  if(x==y) return;
  if(ran.at(x)<ran.at(y)){
    par.at(x)=y;
    diff_weight.at(x)=-w;
  }else{
    par.at(y)=x;
    diff_weight.at(y)=w;
    if(ran.at(x)==ran.at(y)) ran.at(x)++;
  }
}

int main(){
  ll N,M;
  cin >> N >> M;
  init(N);
  rep(i,M){
    ll L,R,D;
    cin >> L >> R >> D;
    L--;
    R--;
    if(find(L)==find(R)){
      if(weight(R)-weight(L)!=D){
        cout << "No" << endl;
        return 0;
      }
    }else{
      unite(L,R,D);
    }
  }
  cout << "Yes" << endl;
}
          

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N,x;
    cin >> N >> x;
    vector<int> A;
    rep(i,N) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    ll ans = 0;
    rep(i,N-1) {
        if (A[i]+A[i+1]>x) {
            if (A[i]>x) {
                ans += A[i+1];
                A[i+1] = 0;
                ans += A[i]-x;
                A[i] = x;
            }
            else {
                ans += A[i+1] - (x-A[i]);
                A[i+1] = x-A[i];
            }
        }
        else continue;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define Oans cout << Ans << endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll
#define Endl endl

int N,K,Ans=INF;
int x[114514];

int kukan(int l,int r){
    return x[r]-x[l];
}

int f(int i){
    return kukan(i,i+K-1)+abs(min(abs(x[i]),abs(x[i+K-1])));
}

signed main(){
    cin >> N >> K;
    REP(i,N){cin >> x[i];}
    
    REP(i,N-K+1){
        Ans=min(Ans,f(i));
    }
    Oans
    
    return 0;
}   


Measured memory_bytes: 1024
a = int(input())
b = list(map(int, input().split()))
c = {}
d = 1
e = 0
for i in range(1, len(b)):
    if b[i] == b[i-1]:
        d += 1
    else:
        e += d // 2
        d = 1
print(e + d // 2)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

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

	}
	else if(c == a && c != b){
		cout << "Yes" << endl;

	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

typedef pair<int, int> pi;

int N, K, L;
vector<int> par;
vector<int> t_rank;
vector<int> A, B;
map<pi, int> M;

void init_union_find(int n) {
	for (int i = 0; i < n; ++i) {
		par[i] = i;
		t_rank[i] = 0;
	}
}

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

void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)
		return;
	if (t_rank[x] < t_rank[y])
		par[x] = y;
	else {
		par[y] = x;
		if (t_rank[x] == t_rank[y])
			++t_rank[x];
	}
}

void make_a(void) {
	par.clear();
	par.resize(N);
	t_rank.clear();
	t_rank.resize(N);
	A.clear();
	A.resize(N);
	init_union_find(N);
	for (int i = 0; i < K; ++i) {
		int p, q;
		cin >> p >> q;
		unite(p - 1, q - 1);
	}
	for (int i = 0; i < N; ++i)
		A[i] = find(i);
}

void make_b(void) {
	par.clear();
	par.resize(N);
	t_rank.clear();
	t_rank.resize(N);
	B.clear();
	B.resize(N);
	init_union_find(N);
	for (int i = 0; i < L; ++i) {
		int r, s;
		cin >> r >> s;
		unite(r - 1, s - 1);
	}
	for (int i = 0; i < N; ++i)
		B[i] = find(i);
}

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

	cin >> N >> K >> L;

	make_a();
	make_b();
	M.clear();
	for (int i = 0; i < N; ++i)
		++M[make_pair(A[i], B[i])];

	for (int i = 0; i < N; ++i) {
		cout << M[make_pair(A[i], B[i])];
		if (i == N - 1)
			cout << '\n';
		else
			cout << ' ';
	}
	return 0;
}


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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl);
#define cpp(a) for(auto x:(a)){cout << x << endl;}


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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 (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        // comment this out when you use scanf or printf
        // cin.tie(0); ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(15);
    };
}fastio;


ll dp[2010][2010];

int main(){

    int n,m;
    cin >> n >> m;
    vector<ll> s(n);
    rep(i, n) scanf("%lld", &s[i]);
    vector<ll> t(m);
    rep(i, m) scanf("%lld", &t[i]);
    for(int i = 0; i <= n; ++i) dp[i][0] = 1;
    for(int i = 0; i <= m; ++i) dp[0][i] = 1;
    rep(i, n){
        rep(j, m){
            if(s[i] == t[j]) (dp[i+1][j+1] += dp[i][j]) %= MOD;
            (dp[i+1][j+1] += dp[i][j+1]+dp[i+1][j]-dp[i][j]+MOD) %= MOD;
        }
    }
    ppp(dp[n][m]);


    return 0;
}


Measured memory_bytes: 31744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int ct = 0;
int n,k,s;
void solve(int k_num,int min_n,int sum_set){
	for(int i = min_n + 1;i <= n;i++){
		if(k_num == k-1 && sum_set + i == s){
			ct++;
			return;
		}
		if(k_num + 1 < k)
			solve(k_num + 1,i,sum_set + i);
	}
	return;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	while(cin >> n >> k >> s,n){
		ct = 0;
		solve(0,0,0);
		cout << ct << endl;
		}
  return 0;
}

Measured memory_bytes: 3192
n=int(input())
p=[int(pi) for pi in input().split(' ')]

num=0
for i in range(1,len(p)-1):
  if p[i-1]<p[i]<p[i+1]:
    num+=1
  elif p[i-1]>p[i]>p[i+1]:
    num+=1
  else:
    pass
  
print(num)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int N, X, T;
  cin >> N >> X >> T;
  
  int y;
  y = N % X;
  
  int a;
  if(y != 0){
    a = N / X;
    a++;
    T *= a;
  }
  else{
    a = N / X;
    T *= a;
  }  
  
cout << T << endl;
return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector< vector<int> > VVI;
typedef vector< vector<ll> > VVL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

int main(){
  int N;
  cin>>N;
  VI A(N-1),B(N-1);
  rep(i,N-1) cin>>A[i]>>B[i];
  VVI X(N,VI(N));
  rep(i,N) rep(j,N) X[i][j]=200;
  rep(i,N) X[i][i]=0;
  rep(i,N-1){
    X[A[i]-1][B[i]-1]=1;
    X[B[i]-1][A[i]-1]=1;
  }
  VI D(N);
  rep(i,N) rep(j,N) if(X[i][j]!=200) D[i]+=X[i][j];
  rep(k,N) rep(i,N) rep(j,N) X[i][j]=min(X[i][j],X[i][k]+X[k][j]);
  int tmp=0;
  int S,G;
  rep(i,N) rep(j,N){
    if(X[i][j]>tmp){
      tmp=X[i][j];
      S=i;
      G=j;
    }
  }
  int C=-1,C2=-1;
  ll ans=100100100100100100;
  if(tmp%2==0){
    rep(i,N) if(X[S][i]==tmp/2 and X[i][G]==tmp/2) C=i;
    rep(i,N){
      if(X[C][i]==1){
        C2=i;
        VI Z(N);
        rep(i,N) Z[min(X[C][i],X[C2][i])]=max(Z[min(X[C][i],X[C2][i])],D[i]);
        ll ans2=2;
        rep(j,N) if(Z[j]-1>0) ans2*=(Z[j]-1);
        ans=min(ans,ans2);
      }
    }
    VI Z(N);
    rep(i,N) Z[X[C][i]]=max(Z[X[C][i]],D[i]);
    ll ans2=Z[0];
    rep(i,N) if(i) if(Z[i]-1>0) ans2*=(Z[i]-1);
    ans=min(ans,ans2);
  }else{
    rep(i,N){
      if(X[S][i]==tmp/2+1 and X[i][G]==tmp/2) C=i;
      if(X[S][i]==tmp/2 and X[i][G]==tmp/2+1) C2=i;
    }
    VI Z(N);
    rep(i,N) Z[min(X[C][i],X[C2][i])]=max(Z[min(X[C][i],X[C2][i])],D[i]);
    ll ans2=2;
    rep(i,N) if(Z[i]-1>0) ans2*=(Z[i]-1);
    ans=min(ans,ans2);
  }
  cout<<tmp/2+1<<" "<<ans<<endl;
}


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

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 1e9+7;

string s;
int n;

int main(){
  // freopen("input.txt", "r", stdin); 
  // freopen("output.txt", "w", stdout);
  cin.sync_with_stdio(0); cin.tie();
  cin.exceptions(cin.failbit);

  cin >> s;
  n=s.length();
  if(s[n-1]=='s') cout << s << "es";
  else cout << s << "s";
}

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

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

    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }

    int a;
    int min;
    int max;
    int count_max;
    for (int k = 0; k < K; k++)
    {
        vector<int> B(N);
        count_max = 0;
        for (int i = 0; i < N; i++)
        {
            a = A.at(i);
            if (a == N)
            {
                count_max += 1;
            }
            min = i - a;
            max = i + a;
            if (min < 0)
            {
                min = 0;
            }
            if (N - 1 < max)
            {
                max = N - 1;
            }

            B.at(min) += 1;
            if (max + 1 < N)
            {
                B.at(max + 1) -= 1;
            }
        }

        for (int i = 1; i < N; i++)
        {
            B.at(i) += B.at(i - 1);
        }
        A = B;
        if (count_max == N)
        {
            break;
        }
    }

    for (int i = 0; i < N; i++)
    {
        cout << A.at(i) << " ";
    }
    cout << "" << endl;
    return 0;
}


Measured memory_bytes: 4844
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=1000000000;
const int MOD=1000000007;

int main()
{
 int a, b;
 string s;
 cin >> a >> b;
 char ca = '0' + a;
 char cb = '0' + b;
 if (a>b){
   for(int i=0;i<a;i++) s.push_back(cb);
   cout << s;
 }else if(a<b){
   for(int i=0;i<b;i++) s.push_back(ca);
   cout << s;
 }else{
   for(int i=0;i<b;i++) s.push_back(ca);
   cout << s;
 }
  return 0;
}

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

int main(){
  long x; cin>>x;

  for(int a=-200;a<200;a++){
    for(int b=-200;b<200;b++){
      if(long(pow(a,5))-long(pow(b,5))==x){cout<<a<<" "<<b;return 0;}
    }
  }
}

Measured memory_bytes: 4024
#include<iostream>

using namespace std;

int main()
{
int n,k;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++)
    a[i]=0;
for(int i=0;i<k;i++)
{
    int num;
    cin>>num;
    for(int j=0;j<num;j++)
    {
        int df;
        cin>>df;
        df--;
        a[df]++;
    }
}
int ct=0;
for(int i=0;i<n;i++)
{
    if(a[i]==0)
        ct++;
}
cout<<ct;

 return 0; 
}

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

#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int n;
    cin >> n;
    vector<P> p(n);
    rep(i,n){
        cin >> p[i].second >> p[i].first;
    }
    sort(p.begin(), p.end());
    ll t = 0;
    rep(i,n){
        t += p[i].second;
        if(t > p[i].first){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 1792
n = input()

digit = len(n) 
ans = 0

for i in range(1, digit//2 + 1):
  ans += 10**(2*i-1) - 10**(2*i-2)

if len(n) % 2 == 1:
  nn = int(n)
  ans += nn - 10**(len(n)-1) + 1

print(ans)

Measured memory_bytes: 9156
import itertools
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
  score = []
  for i in range(Q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    if A[b-1]-A[a-1] == c:
      score.append(d)
  ans = max(ans,sum(score))
print(ans)


Measured memory_bytes: 9104
# -*- coding: utf-8 -*-

from copy import deepcopy

"""
stable sort
"""
N = int(input())
cN = list(map(str, input().split()))
cN2 = deepcopy(cN)

# bubble sort
for i in range(N):
    for j in range(N-1, i, -1):
        if int(cN[j][1]) < int(cN[j-1][1]):
            tmp = cN[j]
            cN[j] = cN[j-1]
            cN[j-1] = tmp
print(' '.join(cN))
print('Stable')

# selection sort
for i in range(N):
    minj = i
    for j in range(i, N):
        if int(cN2[j][1]) < int(cN2[minj][1]):
            minj = j
    tmp = cN2[i]
    cN2[i] = cN2[minj]
    cN2[minj] = tmp
print(' '.join(cN2))

for i in range(N):
    if cN[i] != cN2[i]:
        print('Not stable')
        exit()
print('Stable')



Measured memory_bytes: 6352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i=0;i<n;i++){
			d[i] = sc.nextInt();
		}
		sc.close();
		int wa = 0;
		for(int i=0;i<n-1;i++){
			for(int j=i+1;j<n;j++){
				wa += d[i] * d[j];
			}
		}
		System.out.println(wa);
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
 
#define mod 1000000007
typedef long long int LL;
const int MAX = 105;
const int INF = 1e5;


int main() {
	int n;
	cin >> n;
	vector<pair<int, int> > ans(n);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		ans[i] = make_pair(x, i);
	}
	sort (ans.begin(), ans.end());
	for (int i = 0; i < n; i++) {
		printf ("%d ", ans[i].second + 1);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1536
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
      // 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
      

      	int temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
      
      
      	System.out.println(c/b);

      
      	
	}
}

Measured memory_bytes: 21716
n=int(input())
H=list(map(int,input().split()))
dp=[0 for i in range(n)]
dp[n-2]=abs(H[n-1]-H[n-2])
for i in range(n-3,-1,-1):
    dp[i]=min(dp[i+1]+abs(H[i]-H[i+1]),dp[i+2]+abs(H[i]-H[i+2]))
print(dp[0])

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define pb push_back
typedef long long ll;
#define int long long
#define ld long double
#define f(i,n) for(ll i=0;i<n;i++)
#define fo(i,a,b) for(ll i=a;i<=b;i++)
#define forr(i,a,b) for(ll i=a;i>=b;i--)
#define ee endl
#define mem(a,b) memset(a,b,sizeof(a))
#define bp __builtin_popcount
#define all(x) (x).begin(),(x).end()
#define s(x) sort(all(x))
#define r(x) reverse(all(x))
#define sz size()
#define ln length()
#define mod 1000000007
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second 
#define mxe(v) *max_element(all(v))
#define vl vector<ll>
#define pll pair<ll,ll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 
#define KHILADI ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL))

ll max(ll a , ll b){ if(a>b) return a; else return b;}
ll min(ll a , ll b){ if(a<b) return a; else return b;}

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

/*const ll N=2005;
ll dep[N]={0};
bool v[N]={0};
vl adj[N+1];

void dfs(int x)
{
    v[x]=1;
    for(auto i:adj[x])
    {
        if(v[i]==0)
        {
            dep[i]=dep[x]+1;
            dfs(i);
        }
    }
    return;
}*/

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

signed main()
{
    KHILADI;
    ll t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    
    return 0;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> L(N);
	for(int i = 0; i < N; ++i) cin >> L[i];
	int max_l =  *max_element(L.begin(), L.end());

	if(max_l < accumulate(L.begin(), L.end(), 0) - max_l) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<char> A;
    char prev = '?';
    rep(i, s.size()) {
        if (prev == 'B' && s[i] == 'C')
            A.back() = 'D';
        else
            A.push_back(s[i]);
        prev = s[i];
    }

    ll ans = 0, cnt = 0;
    bool judge = 0;
    for (int i = 0; i < A.size(); i++) {
        if (!judge && A[i] == 'A') {
            judge = 1, cnt++;
        } else if (judge && A[i] == 'A') {
            cnt++;
        } else if (A[i] == 'D') {
            ans += cnt;
        } else
            cnt = 0, judge = 0;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3892
s = gets.split("")
count = 1
ans = 0

s.each do |i|
  if count % 2 == 1
    if i == "L"
      ans += 1 
    end
  else
    if i == "R"
      ans += 1
    end
  end
  count += 1
end

puts ans == 0 ? "Yes" : "No"

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

using namespace std;

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

    int N,K; cin>>N>>K;
    long double ans = 0;
    if (N >= K)
        ans += (N-K+1);

    long double p = 1;
    for (int i = 1; i < min(N+1,K); i++) {
        int cnt = 1;
        auto x = i;
        while (x < K) {
            x *= 2;
            cnt *= 2;
        }
        cerr << cnt << endl;
        ans += p / cnt;
    }
    ans /= N;
    cout << fixed << setprecision(10) << ans << endl;

    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<complex>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
using namespace std;

int main() {
  string s;
  int tmp[26] = {0};
  int i;
  bool flag = true;
  cin >> s;
  for (i = 0; i < s.size(); i++) {
    tmp[(int)s[i] - 97]++;
  }
  for (i = 0; i < 26; i++) {
    if (tmp[i] % 2 != 0) {
      flag = false;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
#include<list>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//int型0~9を文字0~9に変換
char int_to_char(int c) {
	if (c == 0) return '0';
	if (c == 1) return '1';
	if (c == 2) return '2';
	if (c == 3) return '3';
	if (c == 4) return '4';
	if (c == 5) return '5';
	if (c == 6) return '6';
	if (c == 7) return '7';
	if (c == 8) return '8';
	if (c == 9) return '9';
	else return'x';
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}
//xとyのビットごとの排他的論理和
template<class T> T XOR(T x, T y)
{
	T n = 0;
	while (max(x, y) > pow(2, n)) n++;
	T ans=0;
	for (int i = 0; i <= n; i++)
	{
		T x1 = (x % (T)pow(2, i + 1)) / (T)pow(2, i);
		T y1 = (y % (T)pow(2, i + 1)) / (T)pow(2, i);
		if (x1 != y1) ans += (T)pow(2, i);
	}
	return ans;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	long long H;
	cin >> H;
	long long ans = 0, hit = 1;

	while (H > 0)
	{
		ans += hit;
		hit *= 2;
		H /= 2;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
int main()
{
    int a;
    cin >> a;
    string s;
    cin >> s;

    if(a<3200) cout << "red" << endl;
    else cout << s << endl;

   

   return 0;
}

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

using namespace std;

#define endl '\n'

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const double eps = 1e-9;
const int maxn = 100000 + 10; 

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

    int n; cin >> n;

    vector<int> A(n), B(n);

    for (int i = 0; i < n; ++i){
        cin >> A[i];
        B[i] = A[i];
    }

    sort(B.begin(), B.end());

    int answer = 0;

    for (int i = 0; i < n; ++i){
        int p = lower_bound(B.begin(), B.end(), A[i]) - B.begin();
        answer += (p & 1) != (i & 1);
    }

    cout << answer / 2 << endl;

    return 0;
}

Measured memory_bytes: 1024
import sys
import bisect
import math
from operator import itemgetter
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N, D, A = IL()
X = []
xx = []
H = []
for i in range(N):
  x, h = IL()
  xx.append(x)
  X.append([x, i])
  H.append(h)
else:
  xx.append(MAX_INT)
xx.sort()
X.sort(key=itemgetter(0))
data = [0]*(N+1)

D = D*2
damage = 0
ans = 0
for i in range(N):
  x,j = X[i]
  hp = H[j]
  damage += data[i]
  num = max(0,math.ceil((hp - damage)/A))
  damage += num*A
  ans += num
  rng = x + D
  nxt = bisect.bisect_right(xx, rng)
  data[nxt] -= num*A
#print(data)
#print(xx)
print(ans)

"""
9 2 1
1 5
2 4
3 3
4 2
5 1
6 2
7 3
8 4
9 5
"""

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

const int maxn = 3e5+2;

int a[maxn];
int t;

int main()
{
	int n; cin>>n;
	int ans = 0;
	ans+= (n/500 )*1000;
	n%=500;
	ans+=(n/5)*5;
	n%=5;
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
def main():
    N = int(input())
    hList = list(map(int, input().split()))
    cnt = 0
    hMax = max(hList)
    isRange = False
    for h in range(1, hMax+1):
        for j in range(N):
            if not isRange and hList[j] >= h:
                isRange = True
            if isRange and hList[j] < h:
                isRange = False
                cnt += 1
        if isRange:
            cnt += 1
        isRange = False
    print(cnt)
            

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import math

A,B,C,D = map(int,input().split())
divAC,modAC = divmod(A,C)
divBC,modBC = divmod(B,C)
ans = 0
if modAC == 0:
    ans += divBC - divAC + 1
else:
    ans += divBC - divAC

divAD,modAD = divmod(A,D)
divBD,modBD = divmod(B,D)
if modAD == 0:
    ans += divBD - divAD + 1
else:
    ans += divBD - divAD
divACD,modACD = divmod(A,int(C * D / math.gcd(C, D)))
divBCD,modBCD = divmod(B,int(C * D / math.gcd(C, D)))
if modACD == 0:
    ans -= divBCD - divACD + 1
else:
    ans -= divBCD - divACD

print(B-A+1-ans)



Measured memory_bytes: 9176