akhauriyash/Code-Regression huggingface dataset:
use std::cmp::min;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let s = sc.chars();
    let t = sc.chars();
    let n = s.len();
    let mut ans = n;
    for i in 0..n {
        if i + t.len() > n {
            break;
        }
        let mut sum = 0;
        for j in 0..t.len() {
            if s[i + j] != t[j] {
                sum += 1;
            }
        }
        ans = min(sum, ans);
    }

    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> Self {
        Self(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write_all(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reps(i,s,n) for(int (i)=(s);(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n)-1;(i)>=0;(i)--)
#define forin(i,array) for(auto& x:array)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mod 1000000007
#define inf 10000000000000


typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef vector<pint> vpint;

int n;
vint h(100);


int main(){
    cin>>n;
    rep(i,n)cin>>h[i];

    int counter=0;
    rep(i,100){
        bool now=false;
        rep(j,n){
            if(h[j]){
                h[j]--;
                if(now==false){
                    now=true;
                    counter++;
                }
            }
            else{
                if(now==true){
                    now=false;
                }
            }
        }
    }
    cout<<counter<<endl;
}

Measured memory_bytes: 256
#include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <vector>
    #include <string>
    #include <string.h>
     
    typedef long long ll;
    using namespace std;
    const ll INF = 1000000000000000000ll;
    const ll MOD = 1000000007ll;
     
    const double EPS = 1e-8;
     
    int main()
    {
		string w;

		ll size,a[26]={};

		bool H=true;
		
		cin >> w;

		size=w.size();

		for(int i=0;i<26;i++){
			for(int j=0;j<size;j++){
				if(w[j]=='a'+i){
					a[i]++;
				}
			}
		}

		for(int i=0;i<26;i++){
			if(a[i]%2!=0){
				H=false;
				break;
			}
		}

		cout << (H ? "Yes" : "No") << endl;

		return 0;
    }

Measured memory_bytes: 256
/** Which of the favors of your Lord will you deny ? **/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl
#define READ        freopen("alu.txt", "r", stdin)
#define WRITE       freopen("vorta.txt", "w", stdout)

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

template<class TIn>using indexed_set = tree<TIn, null_type, less<TIn>,rb_tree_tag, tree_order_statistics_node_update>;

/**

PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

template <class T>
string to_str(T x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

template <class T>
T po_iter(T b, T p) /// Faster than recursive one
{
    T res = 1, x = b;
    while ( p ) {
        if ( p & 1 ) res = ( res * x );
        x = ( x * x );
        p >>= 1;
    }
    return res;
}


int main()
{
    optimizeIO();

    LL n;
    cin>>n;

    string s = "";

    while(n>0)
    {
        n--;
        s += char('a'+n%26);
        n = n/26;
    }

    reverse(ALL(s));

    cout<<s<<endl;

    return 0;
}

/**

**/

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}




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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int cur = 0, left = 0;
    for (char i : s) {
        if (i == '(') cur++;
        else {
            if (cur == 0) left++;
            else cur--;
        }
    }
    for (int i = 0; i < left; ++i) cout << "(";
    cout << s;
    for (int i = 0; i < cur; ++i) cout << ')';
    cout << endl;
}


Measured memory_bytes: 256
n, m = list(map(int, input().split()))
d = 10**9+7
if abs(n-m) > 1:
  ans = 0
else:
  cnt = 1
  for i in range(1,n+1):
    cnt = (cnt*i)%d
  for i in range(1,m+1):
    cnt = (cnt*i)%d
  if n==m:
    ans = cnt*2%d
  else:
    ans = cnt
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int a[200010],n,i;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	sort(a+1,a+n+1);
	for(i=1;i<n;i++)
	if(a[i]==a[i+1])
	{
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
}


Measured memory_bytes: 1024
using System;

namespace A_Transfar
{
    class Program
    {
        static void Main(string[] args)
        {
            int a;
            int b;
            int c;

            //A,B,Cの読み込みと格納
            string num = Console.ReadLine();

            char separator = ' ';
            string[] separated = num.Split(separator);

            a = Convert.ToInt32(separated[0]);
            b = Convert.ToInt32(separated[1]);
            c = Convert.ToInt32(separated[2]);

            //計算
            int d = a - b;
            int remainder = c - d;

            //容器Bに残る余りが0より小さいということは物理的にないので、その場合は0にする
            if(remainder < 0)
            {
                remainder = 0;
            }

            //出力
            Console.WriteLine(remainder);


        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <stdio.h>
using namespace std;
int ans = 0x3f3f3f3f;
int a, b;
void DFS(int x, int y, int z)
{
    if (x <= z)
    {
        ans = min(ans, y);
        return;
    }
    if (z > 0)
        DFS(x - a, y + 1, z - 1), DFS(x - 1, y, z - 1);
    if (z == 0)
        DFS(x + 1, y + 1, a);
}
int main()
{
    cin >> a >> b;
    DFS(b, 0, 1);
    cout << ans << endl;
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ret = 0;
  rep(i,N){
    int j=i;
    while(j+1<N && S[j+1]==S[i]) j++;
    ret++;
    i = j;
  }

  cout << ret << endl;
  
  return 0;
}



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

int maxVal = 1e5;
const int inf = 2*1e9;

int Knapsack_2(vector<int> &weight, vector<int> &profit, int maxCap)
{
	int n = weight.size();
	
	// It's very important to make DP as long long
	vector<vector<long long>> dp(n + 1, vector<long long>(maxVal + 1, 0));

	/* dp[n][val] represents the minimum capacity of knapsack needed to gain exactly 'val' profit
	 * from the first 'n' elements
	 */

	// No element. There is no way to make any profit
	for(int val = 1; val <= maxVal; val++)
		dp[0][val] = inf;
	
	// An empty knapsack is needed to create zero profit
	for(int i = 1; i <= n; i++)
		dp[i][0] = 0;
	
	// No element and No Profit ==> Empty knapsack would work
	dp[0][0] = 0;

	for(int i = 1; i <= n; i++)
	{
		for(int val = 0; val <= maxVal; val++)
		{
			long long take_it = inf, leave_it = inf;

			leave_it = dp[i-1][val];

			if(val >= profit[i-1])
				take_it = weight[i-1] + dp[i-1][val - profit[i-1]];
			
			dp[i][val] = min(take_it, leave_it);
		}
	}

	for(int ans = maxVal; ans >= 0; ans--)
		if(dp[n][ans] <= maxCap)
			return ans;

}
int main()
{
	int n, maxCap;
	cin >> n >> maxCap;

	vector<int> weight(n), val(n);

	for(int i = 0; i < n; i++)
		cin >> weight[i] >> val[i];

	cout <<	Knapsack_2(weight, val, maxCap);
	return 0;
}





Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef double db;
#define fi first
#define se second
#define pb push_back
#define vi vector<int>
#define SZ(x) (int)(x.size())
#define sci(x) scanf("%d",&(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define syn ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
ll modpow(ll x,ll n,ll mod){ll res=1;for(;n;n>>=1,x=x*x%mod)if(n&1)res=res*x%mod;return res;}
const db eps=1e-8,PI=acos(-1.0);
const int N=4e3+10,M=1e6+10,INF=0x3f3f3f3f,mod=1e9+7;//998244353
int n;
ll ans;
int main(){
	sci(n);
	rep(i,1,n){
		if(i%3==0 || i%5==0)continue;
		ans+=i;
	}
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 3828
N = int(input())

def dfs(s):
    #print('s:{}'.format(s))

    if int(s) > N:
        return 0
    
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)

    #print('ret:{}'.format(ret))
    return ret

print(dfs('0'))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define lli long long int
#define pb push_back
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int i;
	bool bad = false;
	for(i=0;i<3;i++)
	{
		if(s[i]==s[i+1])
		{
			bad = true;
			break;
		}
	}
	if(bad)
		cout<<"Bad"<<endl;
	else
		cout<<"Good"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int sum[200010];
int l[200010],r[200010];
int main()
{
    int n,q;
    while(cin>>n>>q)
    {
        string s;
        cin>>s;
        sum[0]=0;
        for(int i=1;i<s.size();i++)
        {
            if(s[i]!='A'||s[i]!='C')
            {
                sum[i]=sum[i-1];
            }
            if(s[i]=='C' && s[i-1]=='A') sum[i]=sum[i-1]+1;
        }
//        for(int i=0;i<s.size();i++)
//            cout<<sum[i]<<" ";
        for(int i=0;i<q;i++)
        {
            cin>>l[i]>>r[i];
        }
        for(int i=0;i<q;i++)
            cout<<sum[r[i]-1]-sum[l[i]-1]<<endl;
    }
}


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

int main() {
  long long a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  // c*2でx++ y++となる。
  long long c_2 = 2 * c;
  long long ans = 1e10;
  for (int i = 0; i <= max(x, y); i++) {
    long long sum = 0;
    sum += c_2 * i;
    if (x - i > 0) {
      sum += a * (x - i);
    }
    if (y - i > 0) {
      sum += b * (y - i);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,m;
int a[102]={0},b[102]={0};
int main()
{
	cin>>n>>m>>a[1]>>b[1];
	for(int i=2;i<=n+1;i++)
	{
		cin>>a[i];
	}
	for(int i=2;i<=m+1;i++)
	{
		cin>>b[i];
	}
	sort(a+1,a+n+2);
	sort(b+1,b+m+2);
	if(a[n+1]<b[1])
	{
		cout<<"No War";
		return 0;
	}
	if(a[n+1]>=b[1])
	{
		cout<<"War";
		return 0;
	}
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#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())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	LL n,x;
	cin >> n >> x;
	VL a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		a.push_back(a[i]);
	}
	VL mina = a;
	LL ans = INT64_MAX;
	for (LL magic = 0; magic < n; magic++) {
		LL tmp = 0;
		for (int i = n; i < 2*n; i++) {
			mina[i] = min(mina[i], a[i-magic]);
			tmp += mina[i];
		}
		ans = min(ans,tmp + x*magic);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    int ans = n % 1000;
    if (ans == 0) cout << 0 << endl;
    else cout << 1000 - ans << endl;
}

Measured memory_bytes: 3596
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

#　これだとダメ
# for a in range(A+1):
#     x = X - a*500
#     for b in range(B+1):
#         x -= b*100
#         for c in range(C+1):
#             x -= c*50
#             print(a,b,c,x)
#             if x == 0:
#                 ans += 1


for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a+100*b+50*c == X:
                ans += 1

print(ans)

Measured memory_bytes: 9128
/**
 * Selection Sort
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B&lang=ja
 */

#include<bits/stdc++.h>
using namespace std;

void trace(vector <int>A) {
  // 現在の並び替え状態を出力する
  int size = A.size();
  for (int i = 0; i < size; i++) {
    cout << A.at(i);
    if (i < size - 1) {
      cout << ' ';
    } else {
      cout << endl;
    }
  }
}

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

  vector <int>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  // trace(A);
  
  /**
   * selectionSort(A, N) // N個の要素を含む0-オリジンの配列A
   *   for i が 0 から N-1 まで
   *   minj = i
   *   for j が i から N-1 まで
   *     if A[j] < A[minj]
   *       minj = j
   *       A[i] と A[minj] を交換
   */
   int count = 0;
   for (int i = 0; i < N; i++) {
     int minj = i;
     // 最小要素の位置を探索する
     for (int j = i; j < N; j++) {
       if (A.at(j) < A.at(minj)) {
         minj = j;
       }
     }

     // 最小要素を未ソート配列の先頭に移動する
     if (i != minj) {
       swap(A.at(i), A.at(minj));
       count++;
     }
   }

  trace(A);
  cout << count << endl;
}



Measured memory_bytes: 3168
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
#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 fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    ll N;
    cin>>N;
    for(ll h=1;h<=3500;h++){
        for(ll n=1;n<=3500;n++){
            if((4*h*n-N*n-N*h)<=0)continue;
            if(N*h*n%(4*h*n-N*n-N*h)==0){
                cout<<h<<" "<<n<<" "<<N*h*n/(4*h*n-N*n-N*h)<<endl;
                return 0;
            }
        }
    }
//////////////////////////////////////////////////////
return 0;}


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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 2e5 + 10;
const int MOD = 1e9 + 7;

int32_t main(){
	boost;

  	//code
	int n , m , x , y;
	cin >> n >> m;
	int a[n];
	vector<pair<int,int>> b;
	multiset<int> st;


	for(int i = 0 ; i < n ; ++i){
		cin >> a[i];
		st.insert(a[i]);
	}


	for(int i = 0 ; i < m ; ++i){
		cin >> x >> y;
		b.push_back({y,x});
	}

	sort(b.begin(),b.end());
	reverse(b.begin() , b.end());

	for(int i = 0 ; i < m ; ++i){

		auto idx = st.lower_bound(b[i].first);
		// cout << *idx  << " ";
		if(idx != st.begin()){
			while(*st.begin() < b[i].first and (b[i].second)-- ){
				// cout << "aya ";
				st.erase(st.begin());
				st.insert(b[i].first);
			}
		}
		else{
			break;
		}
	}
	int s = 0;
	for(auto i : st){
		// cout << i << " ";
		s += i;
	}
	cout << s;
	return 0;
}

Measured memory_bytes: 7928
N, K = map(int, input().split())
A = list(map(int, input().split()))
dic = {}
B = []
for a in A:
  if a in dic:
    dic[a] += 1
  else:
    dic[a] = 1
for v in dic.values():
  B.append(v)
B.sort()
if len(B) <= K:
  print(0)
else:
  print(sum(B[:-K]))


Measured memory_bytes: 33312
#include <stdio.h>

int main() {

	char S[100001];
	int count = 0;
	char before;
	char tmp;

	scanf("%s", S);
	before = S[0];
	for (int i = 1; S[i] != '\0'; i++) {
		if (S[i] == before) {
			if (S[i + 1] == '\0') count++;
			else if (S[i + 1] == S[i]) {
				count++;
				if (S[i] == '1')	S[i] = '0';
				else if (S[i] == '0')	S[i] = '1';
			}
			else if (S[i + 1] != S[i] /*&& S[i + 1] != '\0'*/) {
				tmp = S[i];
				S[i] = S[i + 1];
				S[i + 1] = tmp;
				count += 2;
			}
		}
			before = S[i];
	}
	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define INFTY 1 << 30;



int Merge(int A[],int left,int mid,int right){

  int k;
  int n1 = mid-left;
  int n2 = right-mid;

  int L[n1+1];
  int R[n2+1];

  for(int i=0;i<n1;i++){
    L[i] = A[left+i];
  }

  for(int i=0;i<n2;i++){
    R[i] = A[mid+i];
  }

  L[n1] = INFTY;
  R[n2] = INFTY;

  int i=0;
  int j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k] = L[i];
      i++;
    }else{
      A[k] = R[j];
      j++;
    }
  }
  return k - left;
}

int MergeSort(int A[],int left,int right){
  int count = 0;
  if(left+1 < right){
    int mid = (left+right)/2;
    count += MergeSort(A,left,mid);
    count += MergeSort(A,mid,right);
    count += Merge(A,left,mid,right);
  }
  return count;
}

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

  int S[500000];
  for(int i=0;i<n;i++){
    scanf("%d",&S[i]);
  }

  m = MergeSort(S,0,n);

  for(int i=0;i<n-1;i++){
    printf("%d ",S[i]);
  }
  printf("%d\n%d\n",S[n-1],m);

  return 0;
}



Measured memory_bytes: 5584
N = int(input())
* A, = map(int, input().split())
for i in range(N):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j + 1] = A[j]
        j = j - 1
    A[j + 1] = v
    print(*A)


Measured memory_bytes: 5980
N, M = map(int, input().split())

dp = [float('inf')] * (2 ** N)


dp[0] = 0

for _ in range(M):
    a, b = map(int, input().split())
    c = sum(1 << (i - 1) for i in map(int, input().split()))
    for x in range(2 ** N):
        dp[c | x] = min(dp[c | x], dp[x] + a)

if dp[-1]==float('inf'):
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 49884
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
*/public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
static class TaskC   {
public void solve(int testNumber, Scanner in, PrintWriter out) {
        int N = in.nextInt();
        int K = in.nextInt();
        int h[] = new int[N];
        for (int i=0; i<N; i++) {
            h[i] = in.nextInt();
        }
        Arrays.sort(h);

        int idx1 = 0;
        int idx2 = K-1;
        int ans = 1<<30;
        while (idx2 != N){
            ans = Math.min(ans, h[idx2]-h[idx1]);
            idx1++;
            idx2++;
        }
        out.println(ans);
    }

}
}



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

int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  if (a[0] == 5 and a[1] == 5 and a[2] == 7) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long


void solve(){

	int a , b;
	cin>>a>>b;
	string p = "";
	for(int i = 0 ; i < b ; ++i)
		p.pb(a+'0');
	string q;
	for(int i = 0 ; i < a ; ++i)
		q.pb(b+'0');

	if(p < q){

		cout<<p<<endl;
		return ;
	}
	cout<<q<<endl;
}


signed main(){
    
    int t;
    t = 1;
    //cin>>t;
    while(t--)
        solve();
}



Measured memory_bytes: 256
<?php

const MOD = 1000000007;

fscanf(STDIN, "%d%d", $n, $k);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));

sort($a);

$factorials = [1, 1];
$inv_factorials = [1, 1];
$inv_numbers = [null, 1];
for ($i = 2; $i <= $n; ++$i) {
    $factorials[$i] = $factorials[$i - 1] * $i % MOD;
    $inv_numbers[$i] = MOD - $inv_numbers[MOD % $i] * intdiv(MOD, $i) % MOD;
    $inv_factorials[$i] = $inv_factorials[$i - 1] * $inv_numbers[$i] % MOD;
}

$answer = 0;
for ($i = 1; $i <= $n; ++$i) {
    if ($i >= $k) {
        $combination = $factorials[$i - 1] * ($inv_factorials[$k - 1] * $inv_factorials[$i - $k] % MOD) % MOD;
        $answer = ($answer + ($a[$i - 1] * $combination % MOD)) % MOD;
    }
    if ($n - $i >= $k - 1) {
        $combination = $factorials[$n - $i] * ($inv_factorials[$k - 1] * $inv_factorials[$n - $i - $k + 1] % MOD) % MOD;
        $answer = ($answer + MOD - ($a[$i - 1] * $combination % MOD)) % MOD;
    }
}

echo $answer;


Measured memory_bytes: 27116
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

int main(void) {
	int i;
	string a, b, c;
	char aa, bb, cc;
	cin >> a >> b >> c;
	aa = a[0] - 32; bb = b[0] - 32; cc = c[0] - 32;
	cout << aa << bb << cc << endl;
	return 0;
}

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

typedef long long LL;

const int MAXN = 200000;
const int LOG = 50;

int N;
LL A[MAXN + 5];

#define lowbit(x) (x & -x)

int Tree[2 * LOG + 5][2 * LOG + 5];

void Update(int x, int y, int d) {
	Tree[x][y] += d;
}

int GetSum(int x, int y) {
	int ret = 0;
	for (int i = x; i > 0; i--)
		for (int j = y; j > 0; j--)
			ret += Tree[i][j];
	return ret;
}

int main() {
	scanf("%d", &N); getchar();
	for (int i = 1; i <= N; i++) {
		char c = getchar();
		while (c >= '0' && c <= '9')
			A[i] = A[i] * 10 + (c ^ 48), c = getchar();
		int cnt = 0;
		if (c == '.') {
			c = getchar();
			while (c >= '0' && c <= '9')
				A[i] = A[i] * 10 + (c ^ 48), cnt++, c = getchar();
		}
		A[i] = A[i] * (LL)pow(10, 9 - cnt);
	}
	LL Ans = 0;
	for (int i = 1; i <= N; i++) {
		LL tmp = A[i];
		int cnt2 = -9, cnt5 = -9;
		while (tmp % 2 == 0)
			tmp /= 2, cnt2++;
		while (tmp % 5 == 0)
			tmp /= 5, cnt5++;
		Ans += GetSum(cnt2 + LOG, cnt5 + LOG);
		Update(-cnt2 + LOG, -cnt5 + LOG, 1);
	}
	printf("%lld", Ans);
}


Measured memory_bytes: 5580
N, L = map(int,input().split())

A_list = []
aji = 0

for i in range(N):
    A_list.append(L + i)
    aji += (L + i)

#print(A_list)

#絶対値が0に一番近いものを取り出す
x = min(A_list,key= lambda A_list:abs(A_list))
#print(x)

aji -= x
print(aji)



Measured memory_bytes: 2940
from itertools import product
s = input()
k = int(input())
anss = []
for bit in product(list(range(len(s)+1)), repeat=2):
    if k >= bit[1] - bit[0] > 0:
        if bit[0] < bit[1] and s[bit[0]:bit[1]] not in anss:
            anss.append(s[bit[0]:bit[1]])

anss.sort()
print(anss[k-1])


Measured memory_bytes: 42332
#include<iostream>
using namespace std;
int N;
long A[300][300];
long ans;
main()
{
	cin>>N;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)cin>>A[i][j];
	for(int i=0;i<N;i++)for(int j=i+1;j<N;j++)
	{
		int flag=0;
		for(int k=0;k<N;k++)
		{
			if(k==i||k==j)continue;
			if(A[i][k]+A[k][j]==A[i][j])flag|=1;
			if(A[i][k]+A[k][j]<A[i][j])flag|=2;
		}
		if(flag&2)
		{
			cout<<-1<<endl;
			return 0;
		}
		if(~flag&1)ans+=A[i][j];
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1000000007;
main(){
    int H,W,N;
    pair<int,int> p[10000];
    cin >> H >> W >> N;
    for(int i = 0;i < N;i++){
        int a;
        cin >> a;
        p[i] = make_pair(a,i+1);
    }
    sort(p,p+N);
    int next = p[0].second;
    int r = p[0].first;
    int muki = 0;//→↓←↑
    int x = 0,y = 0;
    int num = 0;
    int map[100][101];
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            map[i][j] = -1;
        }
    }
    for(int i = 0;i < H*W;i++){
        if(x < 0 || x >= W || y < 0 || y >= H ||
            map[y][x] != -1){
            if(muki == 0){x--;y++;}
            if(muki == 1){y--;x--;}
            if(muki == 2){x++;y--;}
            if(muki == 3){y++;x++;}
            muki = (muki + 1) % 4;
        }
        if(!r){
            r = p[++num].first;
            next = p[num].second;
        }
        map[y][x] = next;
        r--;
        if(muki == 0)x++;
        if(muki == 1)y++;
        if(muki == 2)x--;
        if(muki == 3)y--;
    }
    for(int i = 0;i < H;i++){
        for(int j = 0;j < W;j++){
            printf("%d%c",map[i][j],j==W-1?'\n':' ');
        }
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, m;
	cin >> n >> m;
	ll d[n][n];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j) d[i][j]=0;
			else d[i][j]=LLONG_MIN;
		}
	}
	for(int i=0; i<m; i++){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b]=c;
	}
	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				if(d[i][k]==LLONG_MIN || d[k][j]==LLONG_MIN) continue;
				d[i][j]=max(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	for(int i=0; i<n; i++){
		if(d[0][i]!=LLONG_MIN && d[i][i]>0 && d[i][n-1]!=LLONG_MIN){
			cout << "inf" << endl;
			return 0;
		}
	}
	cout << d[0][n-1] << endl;
	return 0;
}

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

int main()
{
int n,m;
cin >>n>>m;
int maxx=0;
for(int i=1;i<=sqrt(m);i++)
{
if(m%i==0)
{
if(m/i>=n)
{
maxx=max(maxx,i);
}
if(i>=n)
{
maxx=max(maxx,m/i);
}
}
}
printf("%i\n",maxx);
}


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

int x,y,s;
int paper[10][10] = {0};

int sml[5][2] = { {0,0},{0,-1},{0,1},{-1,0},{1,0} };
int mid[9][2] = { {0,0},{-1,-1},{-1,0},{-1,1},{0,1},{1,1},{1,0},{1,-1},{0,-1} };
int big[13][2] = { {-2,0},{-1,-1},{-1,0},{-1,1},{0,-2},{0,-1},{0,0},{0,1},{0,2},{1,-1},{1,0},{1,1},{2,0} };

bool ok(int t){
	return t >= 0 && t < 10;
}

int main(){
	int deep = 0;
	int white = 100;
	while(scanf("%d,%d,%d",&x,&y,&s) == 3){
		if(s == 1){
			for(int i = 0; i < 5; i++){
				int tx = x + sml[i][0];
				int ty = y + sml[i][1];
				if(ok(tx) && ok(ty)){
					if(paper[tx][ty] == 0){
						white--;
					}
					paper[tx][ty]++;
					deep = max(deep,paper[tx][ty]);
				}
			}
		}
		else if(s == 2){
			for(int i = 0; i < 9; i++){
				int tx = x + mid[i][0];
				int ty = y + mid[i][1];
				if(ok(tx) && ok(ty)){
					if(paper[tx][ty] == 0){
						white--;
					}
					paper[tx][ty]++;
					deep = max(deep,paper[tx][ty]);
				}
			}
		}
		else if(s == 3){
			for(int i = 0; i < 13; i++){
				int tx = x + big[i][0];
				int ty = y + big[i][1];
				if(ok(tx) && ok(ty)){
					if(paper[tx][ty] == 0){
						white--;
					}
					paper[tx][ty]++;
					deep = max(deep,paper[tx][ty]);
				}
			}
		}
	}
	printf("%d\n%d\n",white,deep);

	return 0;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N), B(M);
    cin >> A >> B;
    ll a_idx = 0, b_idx = 0;
    A.push_back(INF);
    B.push_back(INF);
    for (int i = 1; i < B.size(); i++) {
        B[i] += B[i - 1];
    }
    ll sum = 0, ans = 0;
    auto calc = [&]() {
        auto itr = upper_bound(B.begin(), B.end(), K - sum);
        if (itr == B.begin()) return 0LL;
        itr--;
        return (ll) distance(B.begin(), itr) + 1;
    };
    ans = max(ans, calc());
    for (int i = 0; i < N; i++) {
        sum += A[i];
        if (sum > K) break;
        ans = max(ans, calc() + i + 1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 7956
function Main(input) {
  input = input.split("\n");
  var i = 0;
  var result = NaN;
  while(1){
    var tmp = input[i++];
    tmp = tmp.split(' ');
    switch(tmp[1]){
      case '+':
        result = parseInt(tmp[0]) + parseInt(tmp[2]);
        break;
      case '-':
        result = tmp[0] - tmp[2];
        break;
      case '*':
        result = tmp[0] * tmp[2];
        break;
      case '/':
        result = Math.floor(tmp[0] / tmp[2]);
        break;
      case '?':
        result = NaN;
        break;
    }
    if(isNaN(result)){
      break;
    }else{
      console.log(result);
    }
  }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 15440
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int n,ans=0;
	cin>>n;
	vector<string>s(1000000);
	for(int i=0;i<n;i++){
		cin>>s[i];
	}
	sort(s.begin(),s.end(),greater<>());
	for(int i=0;i<n-1;i++){
		if(s[i]!=s[i+1]){
			ans++;
		}
	}
	ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 34412
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }

    return true;
}
int n;
int main(void) {
    cin >> n;
    int sn = 0;
    int nn = n;
    while (n) {
        sn += n % 10;
        n /= 10;
    }
    if (nn % sn == 0)cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

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

    int n, k;
    cin >> n >> k;

    int ans = 0;
    for (; n; n /= k) {
        ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------


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

    int i = s.size()-1;
    LLI ans = 0,c = 0;
    while (i >= 0) {
        if (s[i] == 'A') ans += c,i--;
        else if ((i >= 1) && (s[i-1] == 'B') && (s[i] == 'C')) i -= 2,c++;
        else i--,c = 0;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static Map<Double, Integer> map = new TreeMap<Double,Integer>();
	static Map <Double, Integer>map2 = new TreeMap<Double, Integer>();
	static Map <Double, Integer>map3 = new TreeMap<Double, Integer>();
	static Map <Double, Integer>mapG = new TreeMap<Double, Integer>();
	static LinkedList<Double> list = new LinkedList<Double>();
	static LinkedList<Double> listG = new LinkedList<Double>();

	public static void main(String[] args) {
			read();
	}
	static void read(){
		int number = 0;
		double time = 0.0;
		for(int x = 0; x < 3; x++){
			for(int i = 0; i < 8; i++){
				number = sc.nextInt(); time = sc.nextDouble();
				map.put(time, number);
				list.add(time);
			}
			Collections.sort(list);
			time = list.getFirst();
			number = map.get(time);
			System.out.println(number + " " + time);
			list.remove(0);
			map.remove(time);
			number = map.get(list.getFirst());
			time = list.getFirst();
			System.out.println(number + " " + time);
			list.remove(0);
			map.remove(time);
			for(int i = 0; i < list.size(); i++){
				listG.add(list.get(i));
			}
			for(int i = 0; i < map.size(); i++){
				mapG.putAll(map);
			}
			list.remove();
			map.clear();
		}
		Collections.sort(listG);
		time = listG.getFirst();
		number = mapG.get(time);
		System.out.println(number + " " + time);
		listG.remove(0);
		mapG.remove(time);
		time = listG.getFirst();
		number = mapG.get(time);
		System.out.println(number + " " + time);
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007LL
#define mod2 1000000009LL
#define base1 19
#define base2 31
#define base3 137
#define MAX 1e12
#define MIN -10000000000
#define pi acos(-1)
#define esp 1e-6
#define memz(x) memset(x, 0, sizeof x)
#define memn(x) memset(x, -1, sizeof x)
#define pb push_back
#define nai string::npos
#define in1(a) scanf("%lld", &a)
#define in2(a,b) scanf("%lld%lld", &a, &b)
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(i) printf("Case #%lld: ", ++i)
#define FILE    freopen("input.txt", "r", stdin); freopen("out.txt", "w", stdout);
using namespace std;
const ll N = 300010;
ll n, a[N], b[N], res;
int main()
{
    in1(n);
    for(int i=0;i<n+1;i++)
        in1(a[i]);
    for(int i=0;i<n;i++)
    {
        in1(b[i]);
        ll g =min(b[i],a[i]);
        a[i]-=g;
        b[i]-=g;
        res+=g;
        g = min(b[i],a[i+1]);
        a[i+1]-=g;
        res+=g;
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 3072
num = list(map(int, input().split()))
if num[1] != 0:
    arr = list(map(int, input().split()))
    arr.sort()
    l_num = arr[0]
    l_diff = 10000
    for i in range(arr[0]-1, arr[-1]+2):
        if abs(num[0]-i) < l_diff and i not in arr:
            #print(i, num[0], l_num, abs(i-num[0]))
            l_num = i
            l_diff = abs(num[0]-i)
    print(l_num)
else:
    print(num[0])


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

template <int mod>
struct ModInt {
  int x;
  ModInt(): x(0) {}
  ModInt(long long a) { x = a % mod; if (x < 0) x += mod; }
  ModInt &operator+=(ModInt that) { x = (x + that.x) % mod; return *this; }
  ModInt &operator-=(ModInt that) { x = (x + mod - that.x) % mod; return *this; }
  ModInt &operator*=(ModInt that) { x = (long long) x * that.x % mod; return *this; }
  ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
  ModInt inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return ModInt(u);
  }
  #define op(o, p) ModInt operator o(ModInt that) { return ModInt(*this) p that; }
    op(+, +=) op(-, -=) op(*, *=) op(/, /=)
  #undef op
  friend ostream& operator<<(ostream &os, ModInt m) { return os << m.x; }
};

using mint = ModInt<1000000007>;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<mint> memo(k + 1);
  reps(i, k) {
    memo[i].x = -1;
  }
  auto f = [&](auto f, int x) -> mint {
    if (memo[x].x != -1) {
      return memo[x];
    }
    mint ret = exp((mint) x, n);
    repic(i, 2, x) {
      ret -= f(f, x / i);
    }
    return memo[x] = ret;
  };
  mint ans = 0;
  reps(i, k) {
    ans += (mint) i * f(f, k / i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int n;
  cin >> n;
  ll a[n], res = 0;

  REP(i, n) {
    cin >> a[i];
    res ^= a[i];
  }

  REP(i, n) {
    cout << (res ^ a[i]);
    if(i != n - 1) cout << " ";
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 5104
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
int n,m;

int main()
{
    int ans=1;
    cin>>n;
    for (int i=2; i<=n; ++i)
        for (int now=i*i; now<=n; now*=i)
            if (now>ans) ans=now;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;

vector<int> V[100005];
bool vis[100005] = {};//记录是否被标记
int flag[100005] = {};//记录最近的祖先

void add(int ind){
    if(vis[ind])
        return ;
    vis[ind] = 1;
    queue<int>Q;
    Q.push(ind);
    while(!Q.empty()){
        int t = Q.front();Q.pop();
        flag[t] = ind;
        for(int i=V[t].size()-1;i>=0;i--){
            if(vis[V[t][i]])
                continue ;
            Q.push(V[t][i]);
        }
    }
    return ;
}
int main(){
    int N, Q, x;
    char str[15];
    
    while(scanf("%d%d",&N,&Q),N|Q){
        long long ans = 0;
        memset(vis,0,sizeof(vis));
        memset(flag,0,sizeof(flag));
        for(int i=1;i<100005;i++){
            V[i].clear();
        }
        for(int i=2;i<=N;i++){
            scanf("%d",&x);
            V[x].push_back(i);
        }
        add(1);
        for(int i=0;i<Q;i++){
            scanf("%s%d",str,&x);
            if(str[0] == 'Q'){
                ans += flag[x];
            }else {
                add(x);
            }
        }
        printf("%lld\n",ans);
    }

    return 0;
}



Measured memory_bytes: 9108