akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

class Date{
public:
  int y, m, d;

  Date(){}
  Date(int _y, int _m, int _d){
    y = _y;
    m = _m;
    d = _d;
  }

  bool operator<=(const Date &date)const{
    if(y == date.y){
      if(m == date.m){
        return d <= date.d;
      }
      return m < date.m;
    }
    return y < date.y;
  }
};

int main(){
  Date date;
  Date from[] = {Date(1868, 9, 8), Date(1912, 7, 30), Date(1926, 12, 25), Date(1989, 1, 8)};
  string name[] = {"meiji", "taisho", "showa", "heisei"};

  while(cin >> date.y >> date.m >> date.d){
    int gengo = -1;

    for(int i = 3; i >= 0; i--){
      if(from[i] <= date){
        gengo = i;
        break;
      }
    }

    if(gengo == -1){
      cout << "pre-meiji" << endl;
    }
    else{
      cout << name[gengo] << " " << date.y - from[gengo].y + 1 << " " << date.m << " " << date.d << endl;
    }
  }
}

Measured memory_bytes: 1204
#include<bits/stdc++.h>
#include<algorithm>
#include<map>
#include<cmath>
#define int long long
#include<string>
#include <vector>


using namespace std;
signed main()
{
int p=1000000007;
	int n,c=0;
	cin>>n;
	int a[n],b[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	b[0]=a[n-1];
	for(int i=n-2;i>=1;i--)
	{
		b[n-i-1] =(b[n-i-2]+a[i])%p	;
	}
	for(int i=0;i<=(n-2);i++)
	{
		c = (c+ (a[i]*b[n-2-i])%p)%p;
	}
	cout<<c;
	
}


Measured memory_bytes: 6748
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int dp[20500];
const int INF = 1001001001;

int main(void){
  int h,n; cin >> h >> n;
  int a[n],b[n];
  FOR(i,0,n-1){
    cin >> a[i] >> b[i];
  }

  FOR(i,1,20499) dp[i] = INF;

  FOR(i,0,n-1){
    FOR(j,a[i],h+10000){
      chmin(dp[j],dp[j-a[i]]+b[i]);
    }
  }

  int ans = 1001001001;
  FOR(i,h,h+10000){
    chmin(ans,dp[i]);
  }

  cout << ans << endl;


}

Measured memory_bytes: 384
#include <stdio.h>
int n, m;
int main() {
	scanf("%d%d", &n, &m);
	if (n % 2) {
		for (int i = 1; i <= m; i++) {
			printf("%d %d\n", i, n + 1 - i);
		}
	}
	else {
		for (int i = 1; i <= m; i++) {
			if (i <= n / 4) {
				printf("%d %d\n", i, n + 1 - i);
			}
			else printf("%d %d\n", i, n - i);
		}
	}
}

Measured memory_bytes: 1736
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
#include<utility>
#include<vector>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long N; cin >> N;
	long L[10009];
	L[0] = 2; L[1] = 1;

	for (int i = 2; i <= N; i++) L[i] = L[i - 1] + L[i - 2];

	cout << L[N] << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
long long mod=(long long)1e09+7;
int inf=1<<29;
long long llinf=1ll<<60;

int in(void){
    int i;scanf("%d",&i);
    return i;
}
long long llin(void){
    long long i;scanf("%lld",&i);
    return i;
}
double din(void){
    double i;scanf("%lf",&i);
    return i;
}
void chin(char s[]){
    scanf("%s",s);
}
void print(int a){
    printf("%d\n",a);
}
void llprint(long long a){
    printf("%lld\n",a);
}
void dprint(double a){
    printf("%.10f\n",a);
}
void print2(int a,int b){
    printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
    return a>b?a:b;
}
long long min(long long a,long long b){
    return a<b?a:b;
}
int cmp(const void *a,const void *b){
    return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
    return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
    return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
    return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
    int t=*a;
    *a=*b;
    *b=t;
}
long long gcd(long long x,long long y){
    return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
    return x/gcd(x,y)*y;
}

// write codes below this
// when you use 'sort',
// make sure TYPE macro is correct
typedef struct{
    double eff;
    char l[21];
}data;

int main(void){
    int n,p,a,b,c,d,e,f,s,m,i,j,time,income;
    data w[50],tmp;
    while(1){
        n=in();
        if(!n)break;
        rep(i,n){
            chin(w[i].l);
            p=in();
            a=in();
            b=in();
            c=in();
            d=in();
            e=in();
            f=in();
            s=in();
            m=in();
            time=a+b+c+(d+e)*m;
            income=f*s*m-p;
            w[i].eff=(double)income/time;
        }
        rep(i,n-1){
            for(j=n-1;j>i;j--){
                if(w[j-1].eff<w[j].eff||fabs(w[j-1].eff-w[j].eff)<EPS&&strcmp(w[j-1].l,w[j].l)>0){
                    tmp=w[j-1];
                    w[j-1]=w[j];
                    w[j]=tmp;
                }
            }
        }
        rep(i,n)puts(w[i].l);
        puts("#");
    }
    return 0;
}


Measured memory_bytes: 2040
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_K = 100010;
ll X,K;
vector<int> r;
int main() {
  cin >> X;
  cin >> K;
  r.resize(K + 1);
  for (int i = 0; i < K; i++){
    cin >> r[i + 1];
  }
  vector<ll> el(K + 1),em(K + 1), en(K + 1);
  vector<ll> curdir(K + 1);
  el[0] = 0;
  em[0] = X;
  en[0] = 0;
  ll dir = -1;
  curdir[0]= -1;
  for (int i = 0; i < K; i++){
    ll pass = r[i + 1] - r[i];
    en[i + 1] = en[i] + dir * pass;
    em[i + 1] = max(0LL, min(X, em[i] + dir * pass));
    el[i + 1] = max(0LL, min(X, el[i] + dir * pass));
    dir *= -1;
    curdir[i + 1] = dir;
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    ll t,a;
    cin >> t >> a;
    int idx = upper_bound(r.begin(), r.end(), t) - r.begin() - 1;
    ll diff = t - r[idx];
    ll base = max(el[idx], min(em[idx], a + en[idx]));
    ll ans = max(0LL, min(X, base + curdir[idx] * diff));
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;
int main() {
	string s;
	cin >> s;
	int n = s.size();
	for (int i = 0; i < n; i+=2) {
		if (s[i] == 'L') {
			cout << "No" << endl;
			return 0;
		}
	}
	for (int j = 1; j < n; j += 2) {
		if (s[j] == 'R') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define OUT(a) cout << (a) << "\n"
#define ll long long

const int INF = 1e9 + 7;
const ll MOD = 10e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<vector<pair<int, int> > > list = vector<vector<pair<int, int> > >(n, vector<pair<int, int> >());
    int u,v,w;
    REP(i, n-1) {
        scanf("%d %d %d", &u, &v, &w);
        list[u-1].push_back(make_pair(v-1, w%2));
        list[v-1].push_back(make_pair(u-1, w%2));
    }
    stack<int> st;
    vector<int> paint = vector<int>(n, -1);
    int now = 0;
    paint[now] = 0;
    int size = list[now].size();
    REP(i, size) {
        st.push(list[now][i].first);
        paint[list[now][i].first] = list[now][i].second==0?paint[now]:paint[now]^1;
    }
    while(!st.empty()) {
        now = st.top();
        st.pop();
        int size = list[now].size();
        REP(i, size) {
            if (paint[list[now][i].first] != -1) continue;
            st.push(list[now][i].first);
            paint[list[now][i].first] = list[now][i].second==0?paint[now]:paint[now]^1;
        }
    }
    REP(i, n) printf("%d\n", paint[i]);
    return 0;
}

Measured memory_bytes: 6784
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    string s; cin >> s;
    int a[26] = {};
    for (char c : s) a[c-'a']++;
    long long ans = 1;
    int M = 1000000007;
    for (int i = 0; i < 26; i++) ans = ans * (a[i] + 1) % M;
    cout << ans - 1 << endl;
}


Measured memory_bytes: 512
//Volume0-0067
import java.util.ArrayDeque;
import java.util.Scanner;

class El {
    public int x;
    public int y;
    public int r = 0;
    El(int x,int y){
        this.x = x;
        this.y = y;
    }
}

public class Main {

    //declare
    private static ArrayDeque<El> q = new ArrayDeque<El>();
    private static       int            num,x,y;
    private static final int            L     = 12,
    		                            BLACK = 1;
    private static       int    [][]    ck = {{-1,0},{0,-1},{1,0},{0,1}},
                                        map;
    private static       char   []      ch;
    private static       boolean[][]    chk;

    public static void main(String[] args) {

    	String s;

        //input
        Scanner sc = new Scanner(System.in);
        out:while(sc.hasNext()){
            map = new int     [L][L];
            chk = new boolean [L][L];
            for(int i=0;i<L;i++){
            	if ((s = sc.nextLine()).equals("")){
            		continue out;
            	} else {
            		ch = s.toCharArray();
            		for(int j=0;j<L;j++){
            			map[i][j] = Character.digit(ch[j], 10);
            		}
            	}
            }

            //calculate
            num = 0;
            for(int i=0;i<L;i++){
                for(int j=0;j<L;j++){
                    if(map[i][j] == BLACK && !chk[i][j]){
                        num++;
                        DFS(i,j);
                    }
                }
            }

            //output
            System.out.println(num);
        }
    }

    public static void DFS(int i,int j){

        x = j;  y = i;

        do {
            if(map[y][x] == BLACK && !chk[y][x]){
                chk[y][x] = true;
                q.push(new El(x,y));
            }
        } while (update());
    }

    private static boolean update(){

        El e;
        boolean ret = false;
        while(!q.isEmpty()){
            e = q.peek();
            if(e.r == 4){
                q.pop();
                continue;
            }
            if(e.x + ck[e.r][0] >= 0 && e.x + ck[e.r][0] < L &&
               e.y + ck[e.r][1] >= 0 && e.y + ck[e.r][1] < L ) {
                x = e.x + ck[e.r][0];
                y = e.y + ck[e.r][1];
                e.r++;
                ret = true;
                break;
            } else {
                e.r++;
            }
        }
        return ret;
    }
}

Measured memory_bytes: 17404
N, A, B = map(int,input().split())

q, mod = divmod(N, A + B)

if  A == 0 :
    print(0)

elif q < 1 and N <= A:
    print(N)
    
elif q < 1 and N > A:
    print(A)
    
elif q >= 1:
    if mod == 0 :
        print(q*A)
    elif mod <= A :
        print(q*A+mod)
    elif mod > A :
        print(q*A+A)

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new ABC120().SolveC(new ConsoleInput(Console.In, ' '));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
  class ABC120
    {
        public void SolveC(ConsoleInput cin)
        {
            var S = cin.Read.ToCharArray();
            var n = S.Count();
            var A = new int[n];
            for (int i = 0; i < n; i++)
            {
                A[i] = (int)S[i] - 48;
            }
            var sums = new int[n];
            for (int i = 0; i < n; i++)
            {
                if (i == 0) sums[i] = A[i];
                else sums[i] = sums[i - 1] + A[i];
            }
            int count = Min(sums[n - 1], n - sums[n - 1]);
            WriteLine(count * 2);
            ReadLine();
        }
    }
}

Measured memory_bytes: 13400
n,k=map(int,input().split())
a=list(map(int,input().split()))
pl=1
visit=[-1]*n
visit[0]=0
loop=0
cnt=0

while 1:
    cnt+=1
    pl=a[pl-1]
    
    
    if visit[pl-1]!=-1:
        loop=visit[pl-1]
        
        break
    visit[pl-1]=cnt
    if cnt==k:
        print(pl)
        exit()

loop_len=cnt-loop

k=(k-loop)%loop_len+loop
print(visit.index(k)+1)


Measured memory_bytes: 32376
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
int main(){
	
	int n;
	cin>>n;
	int co2=0;
	for(int i=1;i<=n;i++){
	    int co=0;
	    if(i%2==0)continue;
	    for(int j=1;j<=i;j++){
	        if(i%j==0)co++;
	    }
	    if(co==8)co2++;
	}
	cout<<co2<<endl;
	return 0;
}





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

int a,b,c,d;
int main () {
 cin >> a>> b >> c >> d;
 
 if (c==a-1 && d==b-1)
  cout << 1;
  
 else if (a>c && b>d)
  cout << (a-c)*(b-d);
  
 else
  cout << 0;
 
 
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
 
int main(){
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < s.length(); i++){
		if(s.at(i) == '1') cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
//package atcoder;
 
import java.util.*;
//import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int ac = 0;
		int wa[] = new int [N];
		int wawa = 0;
		TreeMap<Integer,String> map = new TreeMap<Integer,String>();
		for(int i=0;i<M;i++) {
			int p = sc.nextInt();
			String s = sc.next();
			if(map.containsKey(p)) {
				if(map.get(p).equals("AC")) {
					continue;
				}else {
					map.put(p,s);
					if(s.contentEquals("AC")) {
						ac ++;
						continue;
					}else if(s.contentEquals("WA")) {
						wa[p-1] ++;
						continue;
					}
			}
		}
			map.put(p,s);
			if(s.equals("AC")) {
				ac ++;
			}else if(s.equals("WA")){
				wa[p-1]++;
			}
		}
		for(Integer key:map.keySet()) {
			if(map.get(key).equals("AC")) {
				wawa += wa[key-1];
			}
		}
		System.out.print(ac+" "+wawa);
}
}

Measured memory_bytes: 73472
#create date: 2020-07-02 22:54

import sys
stdin = sys.stdin
from collections import deque

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    n, m = na()
    g = [[] for i in range(n)]
    for i in range(m):
        a, b = na()
        g[a-1].append(b-1)
        g[b-1].append(a-1)
    q = deque([0])
    d = [-1] * n
    d[0] = 0
    while q:
        v = q.popleft()
        for w in g[v]:
            if d[w] != -1:
                continue
            d[w] = v
            q.append(w)
    if -1 in d:
        print("No")
    else:
        print("Yes")
        for di in d[1:]:
            print(di+1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 34760
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
namespace io{
    #define ll long long
    #define inf 0x3f3f3f3f
    #define il inline 
    #define in1(a) read(a)
    #define in2(a,b) in1(a),in1(b)
    #define in3(a,b,c) in2(a,b),in1(c)
    #define in4(a,b,c,d) in2(a,b),in2(c,d)
    il void readl(ll &x){
        x=0;ll f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
    il void read(int &x){
        x=0;int f=1;char c=getchar();
        while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
        while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
        x*=f;
    }
}using namespace io;
#define N 100005
int n,k;
int main(){
	in2(n,k);
	if(n%2==1){
		if(n/2+1>=k){
			puts("YES");
		}
		else puts("NO");
	}
	else{
		if(n/2>=k){
			puts("YES");
		}
		else puts("NO");
	}
	return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.math.BigDecimal;

public class Main {
  static InputReader in;
  static PrintWriter out;

  static class Solution {
    void solve() throws IOException {
      Scanner sc = new Scanner(System.in);
      while (sc.hasNext()) {
        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double c = sc.nextDouble();
        double d = sc.nextDouble();
        double e = sc.nextDouble();
        double f = sc.nextDouble();
        
        double y = (d * c - a * f) / (d * b - a * e);
        double x = (e * c - b * f) / (a * e - b * d);
        BigDecimal xx = new BigDecimal(x);
        BigDecimal yy = new BigDecimal(y);

        xx = xx.setScale(3, BigDecimal.ROUND_HALF_UP);
        yy = yy.setScale(3, BigDecimal.ROUND_HALF_UP);
        
        out.printf("%.3f %.3f\n", xx, yy);
      }
      
//      End solve()
    }
    
    int gcd(int x, int y) {
      if (x < y) {
        int tmp = x;
        x = y;
        y = tmp;
      }
      
      while (y > 0) {
        int r = x % y;
        x = y;
        y = r;
      }
      
      return x;
    }
//    End Solution
}


  public static void main(String[] args) throws IOException {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out);
    Solution solver = new Solution();
    solver.solve();
    out.close();
}


  static class InputReader {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream));
    }

    public int nextInt() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Integer.parseInt(st.nextToken());
    }

    public long nextLong() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Long.parseLong(st.nextToken());
    }

    public String next() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return st.nextToken();
    }

    public double nextDouble() throws IOException {
      while (st == null || !st.hasMoreTokens()) {
        st = new StringTokenizer(br.readLine());
      }
      return Double.parseDouble(st.nextToken());
    }

  }

}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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





int main(){

    bool flag=false;
    ll ans=INF,sum=0;

    string s,t;
    cin>>s>>t;

    int ls=s.length();
    int lt=t.length();

    rep(i, ls - lt + 1){
        int cnt = 0;

        rep(j,lt){
            if(s[i+j] != t[j])cnt++;
        }

        chmin(ans,cnt);
    }

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b;
  cin>>a>>b;
  int c,d;
  cin>>c>>d;

 int ans=b-d;
  if(ans>0)
    cout<<1<<endl;
  else
    cout<<0<<endl;









    return 0;
}



Measured memory_bytes: 3672
#![allow(unused_imports)]
#![allow(dead_code)]
#![macro_use]
use std::io::prelude::*;
use std::cmp::{max, min};
use std::collections::BinaryHeap;

const MOD: i64 = 1e9 as i64 + 7;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: chars,
        k: usize,
    }
    let k = min(k, s.len());
    let mut ans = 1;
    for &i in s.iter().take(k){
        if i != '1'{
            ans = i.to_digit(10).unwrap();
            break;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
int main(){
 	int i;
  int n;
  char tmp[64];
  	int ans[4] = {0};
  
  scanf("%d",&n);
	for(i=0;i<n;i++){
     scanf("%s",tmp);
      if(tmp[0]=='A'){
        ans[0]++;
      }
      if(tmp[0]=='W'){
        ans[1]++;
      }
      if(tmp[0]=='T'){
        ans[2]++;
      }
      if(tmp[0]=='R'){
        ans[3]++;
      }
      
    }
  
  printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d",ans[0],ans[1],ans[2],ans[3]);
  
  return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int h, w, f, s, k, ans = 0;
  cin >> h >> w;
  char a[h+10][w+10];
  int b[h][w];
  fill((int*) b, (int*) b[h], 0);
  rep(i,h)
    scanf("%s",a[i]);
  rep(i,h)
  {
    f = -1;
    s = 0;
    rep(j,w)
    {
      if (a[i][j] == '.') {
        if (b[i][j] == 0) {
          k = i;
          while (a[k][j] == '.' && k < h) {
            k++;
          }
          for (int l = i; l < k; l++) {
            b[l][j] = k - i;
          }
        }
        if (f < j) {
          k = j;
          while (a[i][k] == '.' && k < w) {
            k++;
          }
          f = k;
          s = k - j;
        }
        ans = max(ans, b[i][j] + s);
      }
    }
  }
  cout << ans - 1;
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, n)
    {
        cin >> x.at(i);
    }
    sort(x.begin(), x.end());
    int minn;
    for (int j = x.at(0); j <= x.at(n - 1); j++)
    {
        int sum = 0;
        rep(i, n)
        {
            int sa = (x.at(i) - j) * (x.at(i) - j);
            sum += sa;
        }
        if (j == x.at(0))
        {
            minn = sum;
        }
        else if (sum < minn)
        {
            minn = sum;
        }
    }
    cout << minn << endl;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] freq = new int[6];
		for(int i=0;i<n;i++) {
			double d = sc.nextDouble();
			if( d < 165.0 ) freq[0]++;
			else if( d < 170.0 ) freq[1]++;
			else if( d < 175.0 ) freq[2]++;
			else if( d < 180.0 ) freq[3]++;
			else if( d < 185.0 ) freq[4]++;
			else freq[5]++;
		}
		for(int i=0;i<6;i++) {
			System.out.print((i+1) + ":");
			for(int j=0;j<freq[i];j++) System.out.print("*");
			System.out.println();
		}
	}

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

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long int ll;


int n,q;
ll add[200100];
vector<int> G[200100];
void dfs(int s,int b){
	if(b==-1){
		for(auto p:G[0]){
			dfs(p,0);
		}
	}
	else{
		add[s]+=add[b];
		for(auto p:G[s]){
			if(p!=b)dfs(p,s);
		}
	}
}
int main(){
	cin >> n >> q;
	for(int i=0;i<n-1;i++){
		int a,b; cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	vector<int>p(q),x(q);
	for(int i=0;i<q;i++){
		cin >> p[i] >> x[i];
		add[p[i]-1]+=x[i];
	}
	dfs(0,-1);
	for(int i=0;i<n;i++){
		cout << add[i] << " ";
	}
	cout << endl;
}

Measured memory_bytes: 25856
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
#define pii pair <int, int>
int k;
int dis[100005];
int dij() {
	priority_queue <pii, vector <pii>, greater <pii> > pq;
	memset(dis, inf, sizeof(dis));
	for (int i = 1; i <= 9; ++ i) pq.push(make_pair(dis[i] = i, i));
	while (!pq.empty()) {
		pii p = pq.top(); pq.pop();
		int v = p.second, d = p.first;
		for (int i = 0; i <= 9; ++ i) {
			int nw = (v * 10 + i) % k;
			if (dis[nw] > d + i) {
				dis[nw] = d + i;
				pq.push(make_pair(dis[nw], nw));
			}
		}
	}
	return dis[0];
}
int main() {
	scanf("%d", &k);
	printf("%d\n", dij());
	return 0;
}

Measured memory_bytes: 2804
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

s = input()
t = input()

if not set(s) >= set(t):
	print(-1)
	exit()

dic = defaultdict(list)
for i, char in enumerate(s, 1):
	dic[char].append(i)

loop = 0
index = -1
for i in range(len(t)):
	idx = bisect(dic[t[i]], index)
	if idx < len(dic[t[i]]):
		index = dic[t[i]][idx]
	else:
		idx = dic[t[i]][0]
		index = idx
		loop += 1

print(len(s)*loop+index)


Measured memory_bytes: 14876
import sys
#import time
#from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
#import heapq
#import math
import itertools
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))


n = ri()
a = rl()
a=a+a
a.sort()

a.pop()
ans=0
for i in range(n-1):
    ans+=a[-i-1]
print(ans)

Measured memory_bytes: 49496
n = gets.chomp.to_i
array = []
n.times do
  array << gets.chomp.to_i
end
array_sorted = array.sort
max = array_sorted[-1]
second = array_sorted[-2]

array.each do |num|
  if (num == max)
    puts second
  else
    puts max
  end
end

Measured memory_bytes: 7784
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main (){
    int N;
    cin >> N;

    vector< long long > A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    long long ans = 0x7fffffffffffffff;
    long long a,b,c;
    long long gcd=A[0];
    a = A[0];
    for(int i=0;i<N-1;i++){
        b = A[i+1];
        do{
            c = a % b;
            a = b;
            b = c;
        }while(b>0);
        gcd = a;
    }


    cout << gcd;
    return 0;
}

Measured memory_bytes: 1024
from collections import deque


mod = 10 ** 9 + 7
SIZE = 2 * 10 ** 5 + 1
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
fact[0], fact[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1
for i in range(2, SIZE):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod


n = int(input())
edges = [[] for _ in range(n)]

for _ in range(n-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

root_to_leaf = []
parents = [0] * n

todo = deque([])
for to in edges[0]:
    todo.append([to, 0])

while todo:
    node, parent = todo.popleft()
    root_to_leaf.append(node)
    parents[node] = parent

    for to in edges[node]:
        if to == parent:
            continue
        todo.append([to, node])

size_of_subtree = [0] * n
pattern_in_subtree = [1] * n

for node in root_to_leaf[::-1]:
    parent = parents[node]
    size_of_subtree[node] += 1
    size_of_subtree[parent] += size_of_subtree[node]
    pattern_in_subtree[parent] *= nCr(size_of_subtree[parent], size_of_subtree[node]) * pattern_in_subtree[node] % mod
    pattern_in_subtree[parent] %= mod

answers = [0] * n
answers[0] = pattern_in_subtree[0]

for node in root_to_leaf:
    parent = parents[node]
    ans = answers[parent] * size_of_subtree[node] * inv[n - size_of_subtree[node]] % mod
    answers[node] = ans

for ans in answers:
    print(ans)
    

Measured memory_bytes: 87128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;

struct info{
	vector<vector<int> > v;
	vector<pair<int,int> > b;
};

typedef pair<int,info > P;
typedef pair<int,int> PP;

int n;
vector<vector<int> > v, end;
map<vector<vector<int> >, int> m;
vector<PP> b;

void solve(){
	v.clear(); end.clear(); m.clear(); b.clear();
	v.resize(4);
	rep(i,4) v[i].resize(8);
	end.resize(4);
	rep(i,4) end[i].resize(8);
	rep(i,4) rep(j,8){
		v[i][j] = 0;
		end[i][j] = 0;
	}
	rep(i,4) rep(j,7){
		end[i][j] = (i+1)*10+j+1;
	}
	v[0][0] = 11; v[1][0] = 21; v[2][0] = 31; v[3][0] = 41;
	rep(i,4){
		rep(j,7){
			cin >> v[i][j+1];
			if(v[i][j+1]%10 == 1){
				v[i][j+1] = 0;
				b.push_back(PP(i,j+1));
			}
		}
	}
	queue<P> que;
	info tmp; tmp.v = v; tmp.b = b;
	que.push(P(0,tmp));
	m[v] = 1;
	while(!que.empty()){
		P p = que.front();
		info q = p.second;
		que.pop();
		if(q.v == end){
			cout << p.first << endl;
			return;
		}
		rep(u,q.b.size()){
			int i = q.b[u].first, j = q.b[u].second;
			if(q.v[i][j-1]%10 != 7){
				rep(k,4){
					bool br = false;
					rep(l,8){
						if(q.v[k][l] == q.v[i][j-1]+1){
							q.v[i][j] = q.v[k][l];
							q.v[k][l] = 0;
							if(m[q.v]){
								q.v[k][l] = q.v[i][j];
								q.v[i][j] = 0;
								br = true;
								break;
							}
							m[q.v] = 1;
							q.b[u] = PP(k,l);
							que.push(P(p.first+1,q));
							q.b[u] = PP(i,j);
							q.v[k][l] = q.v[i][j];
							q.v[i][j] = 0;
							br = true;
							break;
						}
					}
					if(br) break;
				}
			}
		}
	}
	cout << "-1" << endl;
}

int main(){
	cin >> n;
	rep(i,n) solve();
}

Measured memory_bytes: 25864
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def make_divisors(n: int):
    lower_divs = []
    upper_divs = []
    i = 1
    while i**2 <= n:
        if n % i == 0:
            lower_divs.append(i)
            if i != n // i:
                upper_divs.append(n // i)
        i += 1
    return lower_divs + upper_divs[::-1]


def main():
    n = input_int()
    divs = make_divisors(n)
    ans = float("inf")
    for div in divs:
        a = div
        b = n // div
        if a * a <= n:
            ans = min(ans, max(len(str(a)), len(str(b))))
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 9204
#include<iostream>
//#include <bits/stdc++.h>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include <iomanip>
#include <set>
#include<cmath>
#define F first
#define S second
#define pii pair<int,int>
#define pb push_back
#define int long long
#define mp make_pair
#define error(x) cout<<#x<<"="<<(x)<<endl;
void sp(double y,int x){cout<<fixed<<setprecision(x)<<y;}
int inf=1e9+10;
int const M=2e5+10;
int const M2=1e6+10;
int const M3=1e3+10;
int mod=1e9+7;
int sa(int x,int y){if(x%y==0)return x/y;return x/y+1;}
int binp(int x,int y){int ans=1;int t=x;while(y!=0){if(y%2==1){ans*=t;ans;}y/=2;t*=t;t;}return ans;}
main(){
	ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
	int n;
	cin>>n;
	if(n%10==9 || n/10==9)
        return cout<<"Yes",0;
    cout<<"No";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<map>
typedef long long ll;
using namespace std;
#define INF 0x3f3f3f3f
/**
*超时有可能是输入的问题
*注意边界
*仔细读题
*没思路试试逆向思维
**加油，奥利给！！！ 
**/
int a[200000];
int main()
{
	ll m,n,i,j,k,t;
	ll s=0;
	cin>>n>>m;
	t=n;
	n=n%m;
	
	if(n==0) cout<<0;
	else{
		for(i=1;i<=100000;i++)
		{
			t=min(t,abs(n-m));
		}
		cout<<t;
	}
 } 

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

int main() {
  int64_t N;
  cin >> N;
  
  int64_t ans= 0;
  if( N%2==0 ){ // (2N)!!= 2^N * (N!) 
    N/= 2;
    while( N>0 ){
      N/= 5;
      ans+= N;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str();}

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

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

const double EPS = 1e-10;


int main() {
	int n, m, s, g1, g2;

	while((cin >> n >> m >> s >> g1 >> g2) && n!=0) {
		vvi cost(n,vi(n,INT_MAX/10));
		REP(i,n){
			cost[i][i]=0;
		}

		REP(i, m) {
			int b1, b2, c;
			cin >> b1 >> b2 >> c;

			cost[b1-1][b2-1] = c;
		}

		REP(k, n) {
			REP(i, n) {
				REP(j, n) {
					cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
				}
			}
		}

		int minCost=INT_MAX;
		FOR(i, 0, n) {
			minCost = min(minCost, cost[s-1][i] + cost[i][g1-1] + cost[i][g2-1]);
		}

		cout << minCost << endl;

	}

	return 0;
}

Measured memory_bytes: 944
package main

import "fmt"

func main() {
	var N, w, p, c int
	fmt.Scan(&N)
	m := map[string]int{}
	for i := 0; i < N; i++ {
		fmt.Scan(&w)
		switch {
		case w < 400:
			m["gray"]++
		case w < 800:
			m["brown"]++
		case w < 1200:
			m["green"]++
		case w < 1600:
			m["water"]++
		case w < 2000:
			m["blue"]++
		case w < 2400:
			m["yellow"]++
		case w < 2800:
			m["orange"]++
		case w < 3200:
			m["red"]++
		default:
			p++
		}
	}
	for range m {
		c++
	}
	if c == 0 {
		c = 1
		p -= 1
	}
	fmt.Printf("%d %d\n", c, c+p)
}

Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> N;
	vector<int>v(N);
	for (auto &i : v) {
		cin >> i;
	}
	auto w = v;
	sort(w.begin(), w.end());
	reverse(w.begin(), w.end());
	for (auto i : v) {
		if (i == w[0])cout << w[1] << endl;
		else cout << w[0] << endl;
	}
}

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

int main(){
	string s; cin >> s;
	int n = s.size();
	int pre = n, cnt = 0;
	long long ans = 0;
	for(int i=n-1; i>=0; i--){
		if(s[i] == 'A'){
			int c = 0;
			for(int j=i+1; j<pre-1; j=j+2){
				if(s[j] == 'B' && s[j+1] == 'C'){
					c++;
				}else{
					break;
				}
			}
			if(2 * c == pre - i - 1){
				cnt += c;
				ans += cnt;
			}else{
				cnt = c;
				ans += cnt;
			}
			pre = i;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#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;
constexpr ll INF = (1LL << 60);

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  ll res = 0;
  for (int i = 0; i < n - 1; i++) {
    ll d = x[i + 1] - x[i];
    d *= a;
    if (d > b) res += b;
    else res += d;
  }
  cout << res << endl;
  return 0; 
} 

Measured memory_bytes: 768
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
using namespace std;

int main() {
	string N;
	cin >> N;
	if (N[0] == '7' || N[1] == '7' || N[2] =='7') cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3624
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint num[200100];
int a[200100];
int main()
{
	memset(num,0,sizeof(num));
	lint sum=0;int n;
	cin>>n;
	rep(i,n){
		cin>>a[i];num[a[i]]++;
	}
	rep(i,n+10) sum+=num[i]*(num[i]-1)/2;
	rep(i,n){
		cout<<sum-(num[a[i]]-1)<<endl;
	}
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define vv(T) vector<vector<T>>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;


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

    int ans = 0;
    for(int i = 0; i < 10000; i++){
        // cout << i << endl;
        int tp = 1000 * i;
        if(tp >= n){
            ans = tp - n;
            break;
        }
    }

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


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    long double A, B;
    cin >> A >> B;
    cout << (ll)(A * (ll)(B * 100 + 0.001)) / 100 << endl;
}

Measured memory_bytes: 3728
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};
fn main() {
    input! {//
    mut a:i64,
    mut b:i64,
    mut c:i64,
    }
    let mut ans = 0;

    // c -> b
    if c > 0 {
        if b < c {
            ans += b * 2 + 1;
            c -= b + 1;
            b = 0;
            if a > 1 {
                a -= 1;
                ans += min(a + 1, c);
            }
            println!("{}", ans);
            return;
        } else {
            println!("{}", b + c);
            return;
        }
    } else {
        println!("{}", b + c);
        return;
    }
}


Measured memory_bytes: 2080
#include <bits/stdc++.h>
using namespace std;
typedef long long llong;
int N, A, B, C;
vector<int> L;

int rec(int i, int a, int b, int c) {
	if (i == N) {
		if (!a || !b || !c) return 100000;
		return abs(a - A) + abs(b - B) + abs(c - C);
	}

	int res = rec(i + 1, a, b, c);

	res = min(res, rec(i + 1, a + L[i], b, c) + (a ? 10 : 0));
	res = min(res, rec(i + 1, a, b + L[i], c) + (b ? 10 : 0));
	res = min(res, rec(i + 1, a, b, c + L[i]) + (c ? 10 : 0));

	return res;
}

int main(void) {
	cin >> N >> A >> B >> C;
	L.resize(N);
	for (int i = 0; i < N; i++) cin >> L[i];

	cout << rec(0, 0, 0, 0) << endl;

	return 0;
}

Measured memory_bytes: 256