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

using namespace std;

#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair

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

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {
    _for(i,0,v.size()) os << v[i] << " ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){
    for(typename set<T>::iterator it = v.begin();it != v.end();it++)
    os << *it <<" ";
    return os;
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){
    os << v.first <<" "<<v.second<<endl;
    return os;
}

int N;
const int maxn = 1e5+5;

int A[maxn];

vector<LL> ans;

LL ret;

int main()
{
    cin >> N;
    _for(i,0,N){
        cin >> A[i];
    }
    sort(A,A+N,greater<int>());

    if(A[0] >= 0 && A[N-1] <= 0){
        LL temp = A[0];
        
        _for(i,1,N-1){
            if(A[i] <= 0){
                ans.pb(temp);ans.pb(A[i]);
                temp = temp - A[i];
            }
        }
        LL temp2 = A[N-1];
        for(int i = N-2;i > 0;i--){
            if(A[i] > 0){
                ans.pb(temp2);ans.pb(A[i]);
                temp2 = temp2 - A[i];
            }
        }
        ans.pb(temp);ans.pb(temp2);

        ret = temp - temp2;
    }
    else if(A[0] > 0 && A[N-1] >= 0){
        LL temp = A[N-1];
        for(int i = N-2; i > 0;i--){
            ans.pb(temp);ans.pb(A[i]);
            temp -= A[i];
        }
        ans.pb(A[0]);ans.pb(temp);

        ret = A[0] - temp;
    }
    else if(A[0] <= 0 && A[N-1] < 0){
        LL temp = A[0];
        _for(i,1,N){
            ans.pb(temp);
            ans.pb(A[i]);
            temp -= A[i];
        }
        ret = temp;
    }
    printf("%lld\n",ret);
    for(int i = 0; i < ans.size();i+=2){
        printf("%lld %lld\n",ans[i],ans[i+1]);
    }
    return 0;
}


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

int main() {
    int a,b,c,d;
    cin >> a>>b>>c>>d;
    if (a+b>c+d){
        cout <<"Left"<<endl;
    }else if (a+b<c+d){
        cout << "Right"<<endl;
    }else{
        cout << "Balanced"<<endl;
    }
    
    return 0;
}


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

int main() {
  int A,B,C;
  cin >> A >> B;
  C = 0;
  for (int i; i<B+1 ;i++){
    if (i != 0){
      if((i/1000 + i%100)%11 ==0 && i/10000==i%10){
        C++;
      }
    }else{
      i = A-1;
    }
  }
    cout << C << endl;
}


Measured memory_bytes: 3628
n = int(input())
k = int(input())
b = [[]]
for i in range(n):
    tmp = len(b)
    for j in range(tmp):
        b.append([])
        for l in range(len(b[j])):
            b[j+tmp].append(b[j][l])
    for j in range(tmp):
        b[j].append(0)
        b[j+tmp].append(1)
#0: x2, 1: +k
#print(b)
m = 2 ** 11
for i in range(len(b)):
    num = 1
    #print(b[i])
    for j in range(n):
        if b[i][j] == 0:
            num *= 2
        else:
            num += k
        #print(i, j, num, n, k)
    m = min(m, num)
    #print(i, num)
print(m)

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

int ctoi(char num) {
	return num - '0';
}

int main() {
	char s;
	int a[4];
	for (int i = 0; i < 4; i++) {
		cin >> s;
		a[i] = ctoi(s);
	}
	int ans = 0;
	int op[3];
	bool breakflag = false;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				if (i == 0) {
					ans += a[0] + a[1];
				}
				else if (i == 1) {
					ans += a[0] - a[1];
				}
				if (j == 0) {
					ans += a[2];
				}
				else if (j == 1) {
					ans -= a[2];
				}
				if (k == 0) {
					ans += a[3];
				}
				else if (k == 1) {
					ans -= a[3];
				}
				if (ans == 7) {
					op[0] = i;
					op[1] = j;
					op[2] = k;
					ans = 0;
					breakflag = true;
					break;
				}
				ans = 0;
			}
			if (breakflag) {
				break;
			}
		}
		if (breakflag) {
			break;
		}
	}
	for (int i = 0; i < 4; i++) {
		cout << a[i];
		if (i != 3) {
			if (op[i] == 0) {
				cout << '+';
			}
			else {
				cout << '-';
			}
		}
	}
	cout << "=7" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int P=998244353,MAXN=3010;
int n,s,x,dp[MAXN],inv2;
int main () {
	inv2=(P+1)/2;
	scanf("%d%d",&n,&s);
	dp[0]=1;
	for (int i=1;i<=n;i++) {dp[0]=(1ll*dp[0]*2)%P;}
	for (int i=1;i<=n;i++) {
		scanf("%d",&x);
		for (int i=s-x;i>=0;i--) {
			dp[i+x]=(dp[i+x]+(1ll*dp[i]*inv2)%P)%P;
		}
	}
	printf("%d\n",dp[s]);
	return 0;
}

Measured memory_bytes: 3820
#include <stdio.h>

using namespace std;

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

	for(int i = 1; i<= n; i++)
	{
		if(i%3 == 0){
			printf(" %d",i);
		}else{
			x = i;
			do{
				if(x%10 == 3){
					printf(" %d",i);
					break;
				}
				x /=10;
			}while(x);
		}
	}
	printf("\n");
}


Measured memory_bytes: 2736
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  double l;
  cin >> l;
  double x,y,z;
  x = l/3.0;
  y = l/3.0;
  z = l/3.0;
  double ans = x*y*z;
  printf("%.10f\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
#include<map>
#include<string>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
 
using namespace std;

int main(){
    int H, W, M;    cin >> H >> W >> M;
    vector<int> r(W,0), c(H,0);
    int bomb[M][2];
    for(int i=0; i<M; i++){
        int h, w;   cin >> h >> w;
        c[h-1]++;
        r[w-1]++;
        bomb[i][0] = h-1;
        bomb[i][1] = w-1;
    }
    int mc=0, mr=0;
    for(int i=0; i<H; i++)  mc = max(mc,c[i]);
    for(int i=0; i<W; i++)  mr = max(mr,r[i]);

    vector<int> maxc(H,0), maxr(W,0);
    int cntc=0, cntr=0;
    for(int i=0; i<H; i++)  if(c[i] == mc){maxc[i] = 1; cntc++;}
    for(int i=0; i<W; i++)  if(r[i] == mr){maxr[i] = 1; cntr++;}
    int cnt = 0;
    for(int i=0; i<M; i++){
        int x = bomb[i][0];
        int y = bomb[i][1];
        if(maxc[x] == 1 && maxr[y] == 1)    cnt++;
    }
    int ans = mc + mr;
    if(cnt == cntc*cntr)    ans--;
    print(ans);
}

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

int g(int x, int y, int z)
{
    return x*x + y*y + z*z + x*y + y*z + z*x;
}

int main(void){
    // Your code here!
    int N, count[10000] = {}, temp;
    
    scanf("%d", &N);
    
    for(int i = 1; i <= 100; i++)
    {
        for(int j = 1; j <= 100; j++)
        {
            for(int k = 1; k <= 100; k++)
            {
                temp = g(i,j,k);
                if(temp <= N)
                    count[temp-1]++;
                else
                    break;
            }
        }
    }
        
    for(int i = 0; i < N; i++)
        printf("%d\n",count[i]);
}


Measured memory_bytes: 3792
#include <iostream>
using namespace std;
int main(){
  int i=0 ,n ,total=32 ,length;
  while( cin >> length ){
    if( length == 0 ){
      break;
    }
    int jiro[length];
    
    for( int j=0 ; j<length ; j++ ){ // 次郎の取る数
      cin >> jiro[j];
    }
    
    while( 1 ){
      n = total; // 一郎のターン
      total -= (n - 1 ) % 5;
      if( total <= 0 ){
	cout << "0" << endl;
	break;
      }
      cout << total << endl;
    
      total -= jiro[i]; // 次郎のターン
      i++;
      if( i == length ){
	i = 0;
      }
      if( total <= 0 ){
	cout << "0" << endl;
	break;
      }
      cout << total << endl;
    }
    total = 32;
    i = 0;
  }
  return 0;
}

Measured memory_bytes: 1160
import itertools
N, A, B, C = map(int, input().split())
target = [C, B, A]
L = []
for i in range(N):
    L.append(int(input()))

products = list(itertools.product([0, 1, 2, 3], repeat=N))

ans = float("inf")
for p in products:
    scores = [[0, 0], [0, 0], [0, 0], [0, 0]]
    for i in range(len(p)):
        scores[p[i]][0] += L[i]
        scores[p[i]][1] += 1
    temp = [elem[0] for elem in scores[:3]]
    cost = sum([10 * (elem[1] - 1) for elem in scores[:3] if elem[1] >= 1])
    if 0 in temp:
        continue
    sorted(temp)
    cost += sum([abs(target[i] - temp[i]) for i in range(3)])
    ans = min(ans, cost)
print(ans)


Measured memory_bytes: 10996
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    int a,b;
    cin >> a >> b;
    cout << 6-a-b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    string ans =  "No";
    for (int i=0; i*7<=N; ++i) if ((N-7*i)%4==0) ans = "Yes";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#define ll long long int
#define MIN(x,y) (x>y?y:x)

ll getmin(ll a[], ll x, int N, int i){
  ll min = a[0]+i*x;
  for(int j=1; j<N; j++){
    ll temp = a[j]+((i-j+N)%N)*x;
    if(min > temp) min = temp;
  }
  std::cout << min << std::endl;
     
  return min;
}
     
ll min_element(ll *st, ll *end){
  ll *now = st;
  ll min = *now;
  now++;
  while(now!=end){
    if(min > *now){
      min = *now;
    }
    now++;
  }
  return min;
}
     
int main(void){
  int N;
  std::cin >> N;
     
  ll x, a[N];
  std::cin >> x;
  for(int i=0; i<N; i++){
    std::cin >> a[i];
  }

  ll dp[N][N]; //i番目のスライムをj回の変色で作る最小コスト
  for(int i=0; i<N; i++){
    //j=0のとき、a[N]と等しくなる
    dp[i][0] = a[i];
  }
  for(int j=1; j<N; j++){
    for(int i=0; i<N; i++){
      dp[i][j] = MIN(dp[i][j-1], dp[(i-1+N)%N][j-1]);
    }
  }
     
  ll total_min = 1000000000000000L;
  for(int k=0; k<N; k++){
    ll total = 0;
    for(int i=0; i<N; i++){
      total += dp[i][k];
    }
    total += k*x;
     
    if(total_min > total) {
      total_min = total;
    }
  }
     
  std::cout << total_min << std::endl;
     
  return 0;
}

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

using namespace std;

int main(){
	int N;
	cin >> N;
	
	vector<int> p(N);
	for (int i = 0; i < N; ++i) {
		cin >> p.at(i);
	}
	
	int count_not_ordered = 0;
	
	for (int i = 0; i < N; ++i) {
		if (p.at(i) != i + 1) count_not_ordered++;
	}
	
	if (count_not_ordered == 0 || count_not_ordered == 2) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 
int main(){ 
  int h,n;cin>>h>>n;
  vector<int>a(n);
  int d=0;
  rep(i,n)
  {
    cin>>a.at(i);
    d+=a.at(i);
  }
  if(d>=h)
    cout<<"Yes";
  else
    cout<<"No";
}
    
    

Measured memory_bytes: 640
import math
N,H=map(int,input().split())
Katana=[[int(i) for i in input().split()] for i in range(N)]
a_max=max(list(zip(*Katana))[0])
B=list(list(zip(*Katana))[1])
B.sort(key=lambda x:(-1)*x)
n=N
for i in range(N):
  if B[i]<=a_max:
    n=i
    break
del B[n:N]
m=0
for b in B:
  if H>0:
    H-=b
    m+=1
if H>0:
  m+=math.ceil(H/a_max)
print(m)

Measured memory_bytes: 29852
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
typedef long long LL;
LL M5=5000000000000000;
int main(int argc, char* argv[])
{
	string S;
	cin>>S;
	LL K;
	cin>>K;
	if (S.length()==1 || K==1){
		cout<<S[0]<<endl;
		return 0;
	}
	for (int i=0;i<S.length();i++){
		if (S[i]=='1'){
			if (i==K-1){
				break;
			}
			continue;
		}
		cout<<S[i]<<endl;
		return 0;
	}
	cout<<1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=400000+1000;
char t[N];
int s[N],top;
int len;
int main()
{
	scanf(" %s",t+1);
	len=strlen(t+1);
	for(int i=1;i<=len;i++)
	{
		int flag=0;
		int temp=0;
		if(t[i]=='S') temp=1;
		else temp=2;
		if(s[top]==1 && temp==2 && top) --top,flag=1;
		if(!flag) s[++top]=temp;
	}
	printf("%d\n",top);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	vector<vector<char>> grid(100, vector<char>(100, '.'));
	for (int i = 0; i < 50; ++i) {
		for (int j = 0; j < 100; ++j) { grid[i][j] = '#'; }
	}

	for (int i = 0; i < 100; i += 2) {
		if (A < 2) { break; }
		for (int j = 0; j < 100; j += 2) {
			grid[i][j] = '.';
			--A;
			if (A < 2) { break; }
		}
	}
	for (int i = 51; i < 100; i += 2) {
		if (B < 2) { break; }
		for (int j = 1; j < 100; j += 2) {
			grid[i][j] = '#';
			--B;
			if (B < 2) { break; }
		}
	}

	cout << "100 100\n";
	for (int i = 0; i < 100; ++i) {
		for (int j = 0; j < 100; ++j) {
			cout << grid[i][j];
		}
		cout << "\n";
	}

	return 0;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size())
ll n,m,dep[100005],val[100005],vis[100005];
void dfs(ll i,vector<vector<p2>> &v){
	vis[i]=1;
	for(ll j=0;j<sz(v[i]);j++)
		if(!vis[v[i][j].first]){
			dep[v[i][j].first]=dep[i]+1;
			val[v[i][j].first]=v[i][j].second-val[i];
			dfs(v[i][j].first,v);
		}
}
void util(ll i,vector<vector<p2>> &v){
	vis[i]=1;
	for(ll j=0;j<sz(v[i]);j++)
		if(!vis[v[i][j].first]){
			val[v[i][j].first]=v[i][j].second-val[i];
			util(v[i][j].first,v);
		}
}
void assign(ll i,ll x,vector<vector<p2>> &v){
	val[i]=x;
	for(ll i=1;i<=n;i++)
		vis[i]=0;
	util(i,v);
	for(ll i=1;i<=n;i++){
		if(val[i]<=0){
			cout<<0;
			exit(0);
		}
		for(ll j=0;j<sz(v[i]);j++)
			if(val[i]+val[v[i][j].first]!=v[i][j].second){
				cout<<0;
				exit(0);
			}
	}
	cout<<1;
	exit(0);
}
void solve(){
	cin>>n>>m;
	vector<vector<p2>> v(n+1);
	for(ll i=0;i<m;i++){
		ll x,y,w;
		cin>>x>>y>>w;
		v[x].push_back({y,w});
		v[y].push_back({x,w});
	}
	dfs(1,v);
	ll l=1,r=pow(10,15);
	for(ll i=1;i<=n;i++){
		if(dep[i]%2==0)
			l=max(l,-val[i]+1);
		else
			r=min(r,val[i]-1);
		for(ll j=0;j<sz(v[i]);j++){
			ll x0=dep[i],y0=dep[v[i][j].first];
			if(y0>x0){
				if(x0%2==y0%2){
					ll x=v[i][j].second+val[i]-val[v[i][j].first];
					x/=2;
					assign(i,x,v);
				}
				else{
					ll x=v[i][j].second-val[i]-val[v[i][j].first];
					if(x){
						cout<<0;
						exit(0);
					}
				}
			}
		}
	}
	cout<<max(ll(0),r-l+1);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++){
        solve();
    }
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}

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

int main() {
  int n;
  long long d;
  long long x, y;

  scanf("%d %lld", &n, &d);
  int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld", &x, &y);
    if (x*x+y*y <= d*d) ans++;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3760
#include <bits/stdc++.h>
  using namespace std;
 
int main(){
  int N,K,Q;
  cin>>N>>K>>Q;
  vector<int> count(N);
  int ans;
  for(int i=0;i<Q;i++){
    cin>>ans;
    count.at(ans-1)+=1;
  }
  
  for(int i=0;i<N;i++){
   if(K-Q+count.at(i)<=0){
     cout<<"No"<<endl;
   }else{
     cout<<"Yes"<<endl;
   }
  }
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void)
{
	int a,b;
	char s[100];
	char t[100];
	char u[100];
	
	scanf("%s%s",s,t);
	scanf("%d%d",&a,&b);
	scanf("%s",u);
	
	if(strcmp(s,u)==0)
	{
		a--;
		printf("%d %d",a,b);
	}
	
	else if(strcmp(t,u)==0)
	{
		b--;
		printf("%d %d",a,b);
	}
	

	return 0;
}
	

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
int main(void) {
    int n, k;
    scanf("%d", &n);
    int ans = 0;
    int step=0;
    scanf("%d", &k);
    int cur = k;
    for(int i=1;i<n;i++){
        scanf("%d", &k);
        if(cur<k)
            step=0;
        else
            step++;
        cur=k;
        ans = max(ans, step);
    }
    printf("%d", ans);
}

Measured memory_bytes: 256
/*
        _            _                  _            _       _     _         _   _          _          _             _        
       / /\         / /\               / /\         / /\    / /\  /\ \      /\_\/\_\ _     /\ \       /\ \     _    /\ \      
      / /  \       / /  \             / /  \       / / /   / / /  \ \ \    / / / / //\_\   \ \ \     /  \ \   /\_\ /  \ \     
     / / /\ \__   / / /\ \           / / /\ \__   / /_/   / / /   /\ \_\  /\ \/ \ \/ / /   /\ \_\   / /\ \ \_/ / // /\ \_\    
    / / /\ \___\ / / /\ \ \         / / /\ \___\ / /\ \__/ / /   / /\/_/ /  \____\__/ /   / /\/_/  / / /\ \___/ // / /\/_/    
    \ \ \ \/___// / /  \ \ \        \ \ \ \/___// /\ \___\/ /   / / /   / /\/________/   / / /    / / /  \/____// / / ______  
     \ \ \     / / /___/ /\ \        \ \ \     / / /\/___/ /   / / /   / / /\/_// / /   / / /    / / /    / / // / / /\_____\ 
 _    \ \ \   / / /_____/ /\ \   _    \ \ \   / / /   / / /   / / /   / / /    / / /   / / /    / / /    / / // / /  \/____ / 
/_/\__/ / /  / /_________/\ \ \ /_/\__/ / /  / / /   / / /___/ / /__ / / /    / / /___/ / /__  / / /    / / // / /_____/ / /  
\ \/___/ /  / / /_       __\ \_\\ \/___/ /  / / /   / / //\__\/_/___\\/_/    / / //\__\/_/___\/ / /    / / // / /______\/ /   
 \_____\/   \_\___\     /____/_/ \_____\/   \/_/    \/_/ \/_________/        \/_/ \/_________/\/_/     \/_/ \/___________/    
                                                                                                                              
*/
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for(int i = 0;i < (n);++i)

#define endl '\n'
#define pb emplace_back
#define mkp make_pair
#define p_q priority_queue
#define INF 2000000000
#define PI 3.1415926
#define coutdb cout << fixed << setprecision(13)

const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
const int dx_8[]={1,1,0,-1,-1,-1,0,1}, dy_8[]={0,-1,-1,-1,0,1,1,1};
const long long MOD = 1e9+7;

// typedef long long ll;
#define int long long

template <typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T> inline T nHr(T a,T b){return nCr(a+b-1,b);}

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

  int N, H[100000]; cin >> N;
  bool no = 0;
  REP(i, N){
    cin >> H[i];
    if(i==0) H[i]--;
    else{
      if(H[i] < H[i-1]) no = 1;
      else if(H[i] > H[i-1]) H[i]--;
    }
  }
  if(no) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 1024
// Your code here!
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

use std::convert::TryInto;

fn main(){
    let nums:Vec<i32> = read_vec();
    let mut a:i32 = nums[0];
    let mut b:i32 = nums[1];
    let mut c:i32 = nums[2];
    let mut d:i32 = nums[3];
    
    loop {
        c-=b;
        if c<=0 {
            println!("Yes");
            break
        }
        
        a-=d;
        if a<=0 {
            println!("No");
            break
        }
    }
    
}




Measured memory_bytes: 2136
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	private static int n,A,B,C;
	private static int INF=1000000000;
	private static int[] L;
	private static int dfs(int i,int a,int b,int c) {
		if(i==n) {
			if(a==0 || b == 0 || c==0) return INF;
			return Math.abs(a-A)+Math.abs(b-B)+Math.abs(c-C)-30;
		}
		
		int res=dfs(i+1,a,b,c);
		res=Math.min(res, dfs(i+1,a+L[i],b,c)+10);
		res=Math.min(res, dfs(i+1,a,b+L[i],c)+10);
		res=Math.min(res, dfs(i+1,a,b,c+L[i])+10);
		
		return res;
	}

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		 n = sc.nextInt();
		 A = sc.nextInt();
		 B = sc.nextInt();
		 C = sc.nextInt();
		 L= new int[n];

		ArrayList<Integer> array = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			L[i]=sc.nextInt();
			
		}
		
		System.out.println(dfs(0,0,0,0));
	}
}


Measured memory_bytes: 23124
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;


int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    int dp[100010];
    dp[0] = 0;
    int INF = 2e9;
    
    for (int i = 1; i <= n; ++i)
    {
        dp[i] = INF;
        int power = 1;
        while(power <= i)
        {
            dp[i] = min(dp[i], 1 + dp[i - power]);
            power *= 6;
        }
        power = 1;
        while(power <= i)
        {
            dp[i] = min(dp[i], 1 + dp[i - power]);
            power *= 9;
        }
    }
    
    cout << dp[n] << endl;
    
    return 0;
}

Measured memory_bytes: 640
# coding: utf-8
import re
import math
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import sys
readline = sys.stdin.readline
#import numpy as np
mod=int(10**9+7)
inf=int(10**20)
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)

def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r):return math.factorial(n)//math.factorial(n-r)//math.factorial(r)
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
 

 
#main
A,B=map(int,input().split())
l=(A//2)%2
l^=(0 if A%2==0 else A-1)
r=((B+1)//2)%2
r^=(0 if (B+1)%2==0 else B)


print(l^r)


Measured memory_bytes: 6880
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main(){
  int n; cin >> n;
  lint a = 1, b = 1e18; bool c = 0;
  v1li v(n);
  rep(i, n){
    cin >> v[i];
    if(v[i] == 0) c = 1;
  }
  rep(i, n){
    if((b + 0.0) / a < v[i]){
      a = -1;
      break;
    }
    else a *= v[i];
    if(a > b){
      a = -1;
      break;
    }
  }
  if(c) a = 0;
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 4048
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef array <ll, 2> pii;
typedef vector <int> vi;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int M = 1e6 + 123;
int n, a[M], cnt[M];
vi f[M];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for (int i = 1; i < M; i++) {
		for (int j = i; j < M; j += i) {
			f[j].pb(i);
		}
	}
	int ans= 0 ;
	for (int i = 0; i < n; i++) {
		cnt[a[i]]--;
		int ok = 1;
		for (int t : f[a[i]]) {
			if (cnt[t]) {
				ok = 0;
				break;
			}
		}
		ans += ok;
		cnt[a[i]]++;
	}
	cout << ans;
}


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

int main() {
    int64_t N, x;
    cin >> N >> x;
    vector<int64_t> a(N);
    for (int i = 0; i < N; i++) cin >> a.at(i);
    sort(a.begin(), a.end());

    int64_t ans = 0; 
    for (int i = 0; i < N; i++) {
        if (x >= a.at(i)) ans++, x -= a.at(i);
        else break;
    }

    if (ans == N && x > 0) ans--;
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 1e18

int main()
{
    fastio;
    int n;
    cin >> n;
    vector<pair<pair<int,int>,int> >v(n);
    for(int i=0;i<n;i++)
        cin >> v[i].first.first >> v[i].first.second >> v[i].second;
    vector<pair<int,int> >sv(n);
    for(int i=0;i<n;i++)
    {
        sv[i].first=v[i].first.first+v[i].first.second;
        sv[i].second=i;
    }
    sort(sv.begin(),sv.end());
    int l=2e4;
    vector<vector<lli > >dp(n+1,vector<lli>(2e4+1,0));
    //lli dp[n+1][l+1];
    for(int i=0;i<=l;i++)
    {
        for(int j=0;j<=n;j++)
        {
            if(i==0 or j==0)
            {
                dp[j][i]=0;
                continue;
            }
            int ind=sv[j-1].second;
            int w=v[ind].first.first,st=v[ind].first.second;
            dp[j][i]=max(dp[j-1][i],dp[j][i-1]);
            lli a=0;
            if(w<=i and i-w<=st)
                a=v[ind].second*1LL+dp[j-1][i-w];
            dp[j][i]=max(dp[j][i],a);
        }
    }
    // for(int i=0;i<=l;i++)
    // {
    //     for(int j=0;j<=n;j++)
    //         cout << dp[j][i] << " ";
    //     cout << endl;
    // }
    lli ans=0;
    for(int i=1;i<=n;i++)
        ans=max(ans,dp[i][l]);
    cout << ans << endl;
}

Measured memory_bytes: 162528
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll cnt[int(1e5 + 5)];

int main(){
  int N; scanf("%d", &N);
  ll ans = 0;
  for (int i = 0; i < N; i++){
    int A; scanf("%d", &A);
    cnt[A]++; ans += A;
  }


  int Q; scanf("%d", &Q);
  for (int i = 0; i < Q; i++){
    ll B, C; scanf("%lld%lld", &B, &C);
    ans -= B * cnt[B];
    ans += C * cnt[B];
    cnt[C] += cnt[B];
    cnt[B] = 0;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 4300
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int i = 1;
		while (i < 1000) {
			String line = sc.nextLine();
			String[] string = line.split(" ");
			int m = Integer.parseInt(string[0]);
			int f = Integer.parseInt(string[1]);
			int r = Integer.parseInt(string[2]);

			if (m == -1 && f == -1 && r == -1) {
				break;

			} else if (m == -1 || f == -1 || m + f < 30) {
				System.out.println("F");

			} else if (m + f >= 80) {
				System.out.println("A");

			} else if (m + f >= 65 && m + f < 80) {
				System.out.println("B");

			} else if (m + f >= 50 && m + f < 65) {
				System.out.println("C");

			} else if (m + f >= 30 && m + f < 50 && r >= 50) {
				System.out.println("C");

			} else if (m + f >= 30 && m + f < 50) {
				System.out.println("D");

			}
			i++;
		}

	}
}

Measured memory_bytes: 26208
import 'dart:io';

main(List<String> args){
  List nm = stdin.readLineSync().split(" ").map((n) => int.parse(n)).toList();
  int sum=0;
  List numbers = stdin.readLineSync().split(" ").map((n) => int.parse(n)).toList();
  for(int i in numbers){
    sum+=i;
  }
  int select=0;
  for(int i in numbers){
    if(i>=sum.toDouble()/(4*nm[1])){
      select++;
    }
  }
  if(select>=nm[1]){
    print("Yes");
  }else{
    print("No");
  }

}

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

using namespace std;

int main() {
	int a, b; cin >> a >> b;
	int b1 = b*10, b2 = (b+1)*10-1;
	int a1 = a*100/8, a2 = (a+1)*100/8;
	if(a1*8/100 < a) ++a1;
	if(a2*8/100 > a) --a2;
	if(a1 > b2 || a2 < b1) cout << "-1\n";
	else cout << max(a1, b1) << endl;
	return 0;
}

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

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; }

using ll = long long;
using P = pair<int,int>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    ll X,K,D;
    cin>>X>>K>>D;
    ll P = X%D;
    ll Q;
    if(P<0) Q = P+D;
    else Q = P-D;
    if(K>abs(X-P)/D){
      if((abs(X-P)/D)%2==K%2) cout<<abs(P)<<endl;
      else cout<<abs(Q)<<endl;
    }
    else{
      cout<<abs(abs(X)-D*K)<<endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+9;
struct edge{int to,nxt;}e[N*2]; int hd[N],tot; 
void add(int u,int v){e[++tot]=(edge){v,hd[u]};hd[u]=tot;}
int d[N],ans[N]; bool in[N];
void bfs(){
	memset(d,0x3f,sizeof(d));
	queue<int>q; q.push(1); d[1]=0;
	while(!q.empty()){
		int u=q.front(); q.pop();
		for(int i=hd[u],v;i;i=e[i].nxt){
			if(d[v=e[i].to]>d[u]+1){
				d[v]=d[u]+1;
				ans[v]=u;
				q.push(v);
			}
		}
	} 
}
int main(){
	int n,m; cin>>n>>m;
	for(int i=1,u,v;i<=m;i++)
		scanf("%d%d",&u,&v),add(u,v),add(v,u);
	bfs();
	bool anss=1;
	for(int i=1;i<=n;i++) if(d[i]>1e9) anss=0;
	if(anss==0){puts("No");return 0;}
	puts("Yes");
	for(int i=2;i<=n;i++) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 11712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    ll n;
    cin >> n;
    if(n == 1){
        cout << 0 << endl;
        return 0;
    }

    ll cp = n;
    ll ans = 0;
    for(ll i = 2; i * i <= cp; i++){
            ll cnt = 0;
            while(n % i == 0){
                n /= i;
                cnt++;
            }
            ll k = 1;
            while(k * (k+1) / 2 <= cnt){
                k++;
            }
            ans += k - 1;
    }
    ans += (n != 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
import fractions

a, b, c, d = map(int, input().split())

kobai = (c * d) // fractions.gcd(c, d)


def cnt(b, c, d, kobai):
    bc = b // c
    bd = b // d
    b_kobai = b // kobai

    return b - bc - bd + b_kobai


b_num = cnt(b, c, d, kobai)
a_num = cnt(a - 1, c, d, kobai)

ans = b_num - a_num

print(int(ans))


Measured memory_bytes: 5076
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

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

int main()
{
	int counter=1;
	for(int n;cin>>n,n;){
		vvi a(2*n-1,vi(n));
		int k=0;
		rep(i,n){
			rep(j,i+1)
				a[i][j]=++k;
			if(i&1)
				reverse(a[i].begin(),a[i].begin()+i+1);
		}
		repi(i,n,a.size()){
			repi(j,i-n+1,n)
				a[i][j]=++k;
			if(i&1)
				reverse(a[i].begin()+i-n+1,a[i].end());
		}
		rep(i,n){
			rep(j,a[i].size()){
				a[i][j]=a[i+j][j];
			}
		}
		
		printf("Case %d:\n",counter++);
		rep(i,n){
			rep(j,a[i].size())
				printf("%3d",a[i][j]);
			puts("");
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
n = input()
iter_ = iter(list(map(int, input().rstrip("\n").split())))
ans = 0

last = next(iter_)
try:
    while True:
        ans += 1
        now = next(iter_)
        while now == last:
            now = next(iter_)
        laststate = (last < now)
        state = laststate
        while state == laststate:
            last = now
            now = next(iter_)
            while now == last:
                now = next(iter_)
            state = (last < now)
        last = now
except StopIteration:
    print(ans)


Measured memory_bytes: 62704
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N, d[100000];
int main(int argc, char **argv) {
    cin >> N;
    for(int i = 0; i < N; ++i)
        cin >> d[i];

    int N2 = N/2;
    sort(d, d + N);

    int res = 0;
    for(int i = 0; i <= 100000; ++i) {
        int dist = distance(d, lower_bound(d, d + N, i));

        if(dist == N2)
            ++res;
    }

    cout << res << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

int main(void)
{
    long long L, R;
    cin >> L >> R;

    const long long mod = 2019;

    long long ans = mod;
    if (R - L >= mod) {
        L %= mod;
        R %= mod;
        
        R += mod;
    }

    for (long long i = L; i < R; i++) {
        for (long long j = i + 1; j <= R; j++)
            ans = min(ans, (i*j) % mod);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [list(map(int,input().split())) for i in range(n)]
from itertools import permutations
perm = list(permutations(s,n))
def distance(s):
    res = 0
    for i in range(n-1):
        res += ((s[i][0]-s[i+1][0])**2 + (s[i][1]-s[i+1][1])**2)**0.5
    return res
k = 0
for key in perm:
    k += distance(key)
fin_res = format(k/len(perm),'.10f')
print(fin_res)

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

    /*
    ||||||||||||||||||||||||||||||||||||||||||||||||
       |      |||         |      ||||    ||||  |   |
      | |     |   |      | |     |   |  |      |   |
     |   |    |    |    |   |    |   |  |      |   |
    |||||||   |    |   |||||||   |||     |||   |||||
    |     |   |   |    |     |   | |        |  |   |
    |     |   |||      |     |   |  ||  ||||   |   |
    ||||||||||||||||||||||||||||||||||||||||||||||||

    */
    using namespace std;
    //#include "testlib.h"
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define int long long
    #define ll long long
    #define M 1000000007

    #define mii  map<ll ,ll >
    #define msi  map<string,ll >
    #define mis  map<ll int, string>
    #define rep(a,b)    for(ll i=a;i<b;i++)
    #define rep0(n)    for(ll i=0;i<n;i++)
    #define repi(i,a,b) for(ll i=a;i<b;i++)
    #define pb push_back
    #define vi vector<ll>
    #define mp make_pair
    #define vs vector<string>
    #define ppb pop_back
    #define endl '\n'
    #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define r0 return 0;
    #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
    #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
    #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #define input freopen("input.txt", "r", stdin);
    #define Set(a, s) 4(a, s, sizeof (a))
    #define FOR repi
    #define pii pair<int,int>
    //#define float long double
    ll max(ll a, ll b) { return (a > b)? a : b;}
    int min(int a, int b) { return (a < b)? a : b;}


     int solve()
     {

         string s;
         cin>>s;
         int n=s.size();
         int c=0;
         int t=0;
         //cout<<s.size()<<" ";
         rep(0,n-1){
         	if(i!=0&&s[i]=='B'&&s[i+1]=='C'){
         		c+=t;
         		if(t)
         		{s[i]='C';s[i+1]='A';
         		if(t>1) s[i]='A';
         		t=max(0,t-2);
         	}
         		//t=0;
         	}
         	if(s[i]=='A') t++;
         	else t=0;
         	//cout<<t<<" ";
         }	
         cout<<c;
     }
    signed main()
    {   
        asdf
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9+7;


int main(){
  int n;
  cin >> n;
  vector<ll> t(n),a(n);
  rep(i,n) cin >> t[i];
  rep(i,n) cin >> a[i];

  vector<ll> l(n,0),r(n,0);
  if (t[n-1] != a[0]) {
    puts("0");
    return 0;
  }
  l[0] = 1;
  for (int i = 1; i < n ; i++) {
    if (t[i] > t[i-1]) {
      l[i] = 1;
      r[i] = t[i];
    } else {
      l[i] = t[i];
      r[i] = -1;
    }
  }
  l[n-1] = 1;
  bool ok = true;
  for (int i = n-2; i >= 0; i--) {
    if (r[i] != -1 && a[i] < r[i]) {
      ok = false;
      break;
    }
    if(a[i] > a[i+1]) l[i] = 1;
    else l[i] = min(l[i],a[i]);
  }
  ll res = 1;
  if(!ok) puts("0");
  else {
    rep(i,n) {
      res = (res * l[i]) % mod;
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 3328
/*
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒██▒██▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒██▒██▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████████▒▒▒▒▒██▒▒████▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████████▒▒▒▒███▒▒████▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▒▒████▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██▒▒▒▒▒███▒▒▒▒▒████▒▒████▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒███▒▒▒▒▒████▒▒▒███▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒███▒▒▒▒▒████▒▒▒▒▒█████▒▒███▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒████▒▒▒▒▒████▒▒▒▒▒▒████▒▒███▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒▒████▒▒▒▒▒▒████▒▒███▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒████████▒▒▒▒▒▒███▒▒▒▒▒▒████▒▒███▒▒▒▒▒▒
			▒▒▒▒▒▒▒█████████▒▒▒▒▒▒███▒▒▒▒▒▒▒███▒▒███▒▒▒▒▒▒
			▒▒▒▒▒▒█████▒████▒▒▒▒▒▒████▒▒▒▒▒▒███▒▒███▒▒▒▒▒▒
			▒▒▒▒▒████▒▒▒████▒▒▒▒▒▒████▒▒▒▒▒▒███▒▒███▒▒▒▒▒▒
			▒▒▒▒▒████▒▒▒████▒▒▒▒▒▒████▒▒▒▒▒▒███▒▒███▒▒▒▒▒▒
			▒▒▒▒████████████▒▒▒▒▒▒████▒▒▒▒▒▒███▒▒███▒▒▒▒▒▒
			▒▒▒▒███████████████▒████████▒▒█████▒▒███▒▒▒▒▒▒
			▒▒▒▒██████████████████████████████▒▒▒███▒▒▒▒▒▒
			▒▒▒▒▒███████▒████████████████████▒▒▒▒███▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒██████████▒█████████▒▒▒▒██▒▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒██████▒▒▒▒██████▒▒▒▒▒▒██▒▒▒▒▒▒▒
			▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒*/
/*بسم الله الرحمن الرحيم*/
/*“Dengan menyebut nama Allah yang Maha Pengasih lagi Maha Penyayang”*/
/*“In the name of Allah, Most Gracious, Most Merciful”*/
/********************************************************************************************************\__
                                                                                                          |
        author  :   Althafa Dhia Syauqi   ||    email   :    daltafa@gmail.com                              ||
        SMAN 10 Samarinda, Kalimantan Timur.                                                    ||
                                                                                                          ||
/********************************************************************************************************/
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define rep_k(i,n) for(int x=i;x<n;x++
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_n(i,n) for(int i=1;i<=(n);i++)
#define rep_all(k) for(auto x:k)
#define endl '\n'
#define mod 1e9+7
#define pb push_back
#define READ(f)         freopen(f, "r", stdin)
#define WRITE(f)        freopen(f, "w", stdout)
#define maxSort         sort(all(v),greater<int>())
#define rSort           sort(v.rbegin(),v.rend())
#define FOREACH(i,c) for (typeof((c).end()) i = (c).begin(); i != (c).end(); ++i)
#define RESET(c,v) memset(c, v, sizeof(c))
#define sqr(x)          ((x)*(x))
#define qube(x)         ((x)*(x)*(x))
using namespace std;
void optimization()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
int main()
{
	optimization();
	ll t;
	cin >> t;
	if(t==7||t==5||t==3)
        cout << "YES"<<endl;
    else
        cout << "NO"<<endl;
    return 0;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"

using ld = long double;
using ll = long long;

inline ll addm(ll __a, ll __b, ll __m);
inline ll subm(ll __a, ll __b, ll __m);
inline ll mulm(ll __a, ll __b, ll __m);
ll powm(ll __a, ll __b, ll __m);
ll inv(ll __x, ll __m);
// }}}

const ll INFL = numeric_limits<ll>::max() / 2;
const ll INF = numeric_limits<int>::max() / 2;
const ll MOD = 1e9+7;

const int N = 3050;
int dp[N][N];
pair<int,int> prv[N][N];
void solve()
{
    string s, t; cin >> s >> t;
    for (int i = 1; i <= sz(s); i++) {
        for (int j = 1; j <= sz(t); j++) {
            if (dp[i-1][j] >= dp[i][j-1]) prv[i][j] = {i-1, j};
            else prv[i][j] = {i, j-1};
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if (s[i-1] == t[j-1] && dp[i-1][j-1] + 1 > dp[i][j]) {
                dp[i][j] = dp[i-1][j-1] + 1;
                prv[i][j] = {i-1, j-1};
            }
        }
    }
    pair<int,int> start = {0,0}, cur = prv[sz(s)][sz(t)];
    string ans;
    while (cur != start) {
        int i, j; tie(i, j) = cur;
        if (s[i] == t[j]) ans.push_back(s[i]);
        cur = prv[i][j];
    }
    if (s[0] == t[0]) ans.push_back(s[0]);
    reverse(all(ans));
    cout << ans << endl;
}

// main {{{
int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}

inline ll addm(ll __a, ll __b, ll __m = MOD) {
    return ((__a+__b)%__m);
}
inline ll subm(ll __a, ll __b, ll __m = MOD) {
    return (((__a-__b)%__m+__m)%__m);
}
inline ll mulm(ll __a, ll __b, ll __m = MOD) {
    return ((__a*__b)%__m);
}
ll powm(ll __a, ll __b, ll __m = MOD) {
    ll ret = (!__b) ? 1 : powm(__a, __b/2, __m);
    return (!__b) ? 1 : mulm(mulm(ret, ret, __m), (__b%2) ? __a : 1, __m);
}
ll inv(ll __x, ll __m = MOD) {
    return powm(__x, __m-2, __m);
}
// }}}


Measured memory_bytes: 108800
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

void pop(){
    
}

void push(){
    
}

int main(int argc, const char * argv[]) {
    
    int x[100];
    char s[100];
    int top = 0;
    
    while(scanf("%s",s) != EOF){
        if (s[0] == '+') {
            top--;
            x[top-1] = x[top-1] + x[top];
        }else if(s[0] == '-'){
            top--;
            x[top-1] = x[top-1] - x[top];
        }else if(s[0] == '*'){
            top--;
            x[top-1] = x[top-1] * x[top];
        }else{
            
            x[top] = atoi(s);
            top++;
            }
        
    }
    
    printf("%d\n",x[0]);

    return 0;
}



Measured memory_bytes: 2120
#include<stdio.h>
#define N 1000000
int binarySearch(int key,int [1000000]);
int n;
int s[N],t[N];
int main(){
  int q,i,x;
  int num=0;
  scanf("%d", &n);
  for(i = 0; i <n; i++){
    scanf("%d" , &s[i]);
  }
 scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d" , &t[i]);
  }

  for(i = 0; i < q; i++){
    
    x = binarySearch(t[i],s);
  
    if(x != -1) num++;
  }
  printf("%d\n", num);
  return 0;
}

int binarySearch(int key, int A[n]){
  int left=0;
  int right = n;
  int mid;
  while(left < right){
    mid = (left + right) / 2;
    if(A[mid] == key)return mid;
    else if(key < A[mid])right = mid;
    else left = mid + 1;
  }
  return -1;
}
    

Measured memory_bytes: 4892
(defun coins (a b c x)
  (let ((res 0)
        (total 0))
    (dotimes (i (+ a 1))
      (dotimes (j (+ b 1))
        (dotimes (k (+ c 1))
          (setf total (+ (* 500 i) (* 100 j) (* 50 k)))
          (if (= total x) (incf res)))))
    res))

(format t "~A~%" (coins (read) (read) (read) (read)))

Measured memory_bytes: 4964