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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

void yaml();
void mapping(int& i, int level, string key);
int mapping_item(int& i, int& j, int level, string key);
string key_(int& i, int& j);
string string_(int& i, int& j);
int indent(int& i, int& j);

string prop;
vector<string> S;

void yaml() {
    int i = 0;
    int level = 0;
    string key = "";
    mapping(i, level, key);
}

void mapping(int& i, int level, string key) {
    for (; i < SZ(S); i++) {
        int j = 0;
        int lv = mapping_item(i, j, level, key);
        if (lv == -1) {
            i--;
            break;
        }
        level = lv;
    }
}

int mapping_item(int& i, int& j, int level, string key) {
    int lv = indent(i, j);
    if (level > lv) {
        return -1;
    }
    string k = key + '.' + key_(i, j);
    j++; // ':'
    if (S[i][j] == ' ') {
        j++;
        string v = string_(i, j);
        if (k == prop) {
            throw "string \"" + v + "\"";
        }
    } else if (S[i][j] == '\n') {
        if (k == prop) {
            throw string("object");
        }
        i++;
        mapping(i, lv, k);
    }
    return lv;
}

string key_(int& i, int& j) {
    string x;
    while (isalnum(S[i][j])) {
        x += S[i][j];
        j++;
    }
    return x;
}

string string_(int& i, int& j) {
    string x;
    while (isalnum(S[i][j]) || S[i][j] == ' ') {
        x += S[i][j];
        j++;
    }
    return x;
}

int indent(int& i, int& j) {
    int level = 0;
    while (S[i][j] == ' ') {
        level++;
        j++;
    }
    return level;
}

int main() {
    cin >> prop;
    cin.ignore(); // '\n'
    string s;
    while (getline(cin, s)) S.push_back(s + '\n');
    try {
        yaml();
        cout << "no such property" << endl;
    } catch (string res) {
        cout << res << endl;
    }
}

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

using namespace std;

inline int ctoi(char c) { if(c < '0' || '9' < c) throw invalid_argument("ctoi error"); return c - '0'; }
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, k, n) for(int i = (int)(k); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
inline T gcd(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("gcd error: x <= 0 or y <= 0");
	
	if(x < y) swap(x, y);
	T r = x % y;

	while(r != 0){
		x = y;
		y = r;
		r = x % y;
	}

	return y;
}
template <typename T>
inline T lcm(T x, T y){
	if (x <= 0 || y <= 0) throw invalid_argument("lcm error: x <= 0 or y <= 0");

	return x * y / gcd(x, y);
}

int n, q;
vector<vector<int>> tree;
vector<long long int> ope;
vector<long long int> ans;
vector<bool> path;

void dfs(int node, long long int x){
	if(!path[node]){
		x += ope[node];
		ans[node] += x;
		path[node] = true;
	}

	if(tree[node].size() == 0) return;

	rep(i, tree[node].size()){
		if(!path[tree[node][i]]) dfs(tree[node][i], x);
	}
}

int main(){
	cin >> n >> q;
	tree.resize(n);
	ope.resize(n, 0);
	ans.resize(n, 0);
	path.resize(n, false);

	rep(i, n - 1){
		int a, b;
		cin >> a >> b;

		tree[a - 1].push_back(b - 1);
		tree[b - 1].push_back(a - 1);
	}

	rep(i, q){
		int p, x;
		cin >> p >> x;
		ope[p - 1] += x;
	}

	dfs(0, 0);

	rep(i, n){
		cout << ans[i] << " ";
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 25856
#![allow(unused_imports)]
#![allow(unused_variables)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};

fn main() {
    input! {
        n: usize,
        m: usize,
        x: u32,
        ca: [(u32, [u32; m]); n],
    }
    let mut ans = std::u32::MAX;
    for i in 0..(1 << n) {
        let mut c = 0;
        let mut a = vec![0; m];
        for j in 0..n{
            if (i >> j) & 1 == 0{
                continue;
            }
            c += ca[j].0;
            for (a, ca) in a.iter_mut().zip(ca[j].1.iter()){
                *a += *ca;
            }
        }
        if a.iter().all(|a| *a >= x){
            ans = min(ans, c);
        }
    }
    if ans != std::u32::MAX{
        println!("{}", ans);
    }else{
        println!("-1");
    }
}


Measured memory_bytes: 2136
#include <cstdio>
#include <algorithm>
#include <limits>

constexpr int INF_I = std::numeric_limits<int>::max();
constexpr int MAX_N = 100000;

int main(){
    int N;
    int L[MAX_N];
    scanf("%d", &N);
    std::fill(L, L + N + 1, INF_I);
    for(int i = 0; i < N; ++i){
        int A;
        scanf("%d", &A);
        *std::lower_bound(L, L + N + 1, A) = A;
    }
    printf("%d\n", std::lower_bound(L, L + N, INF_I) - L);
    return 0;
}

Measured memory_bytes: 3144
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = readInt >>= putStrLn . solve

solve r
	| r < 1200 = "ABC"
	| r < 2800 = "ARC"
	| otherwise = "AGC"

Measured memory_bytes: 508
#include<stdio.h>
#include<math.h>
int main()
{
  int A,B,C;
  scanf("%d%d%d",&A,&B,&C);
  if(C-A+B>0){
      printf("%d",C-A+B);
    }else{
        printf("0");
    }
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K; cin >> N >> K;
  vector<ll> A(N);
  REP(i, N){
    cin >> A[i];
  }
  for(int i = K; i < N; i++){
    if(A[i-K] < A[i]){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 4776
#include <algorithm>
#include <iostream>
#include <cstring>
#include <complex>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <vector>  
#include <string>
#include <cmath>
#include <ctime>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <ext/pb_ds/assoc_container.hpp>    // PBDS
#include <ext/pb_ds/tree_policy.hpp>      // PBDS

using namespace std;
using namespace __gnu_pbds;                 // PBDS

/* typedef starts */

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> PBDS_INT;               // PBDS for int
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> PBDS_LL;    // PBDS for long long

/* typedef ends */

/* macro starts */

#define PI acos(-1)
#define EPS 1e-9
#define INF 1e9
#define fastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define sinD(degree) sin((degree * PI) / 180.0)
#define cosD(degree) cos((degree * PI) / 180.0)
#define tanD(degree) tan((degree * PI) / 180.0)
#define cotD(degree) (1.0 / tanD(degree))
#define secD(degree) (1.0 / cosD(degree))
#define cosecD(degree) (1.0 / sinD(degree))
#define asinD(value) (asin(value) * 180.0) / PI
#define acosD(value) (acos(value) * 180.0) / PI
#define atanD(value) (atan(value) * 180.0) / PI
#define forn(i,n) for(int i=0;i<n;i++)
#define value_at_index(x) find_by_order(x)
#define index_of(x) order_of_key(x)
#define pb push_back
#define set0(add) memset(add,0,sizeof(add))
#define max(a,b) a>b ? a : b
#define forr(i,a,b) for(int i=a;i<b;i++)

/* macro ends */

/* function starts */

/// calculates n-th (0-based) Gray Code
template<typename dataType>
dataType nthGrayCode(dataType n)
{
    return (n ^ (n >> 1));
}

/// generates all possible subsets for the given set
//template<typename dataType>
// void generateAllSubset(vector<dataType> &data)
// {
//     int i, j, n;
//     n = data.size();

//     for (i = 0; i < (1 << n); i++) {
//         for (j = 0; j < n; j++) {
//             if (i & (1 << j)) {
//                 cout << data[j] << " ";
//             }
//         }
//         cout << "\n";
//     }
// }


void swap(ll a, ll b){
	ll temp;
	temp=a;
	a=b;
	b=temp;
}


ll fact(ll n){
	ll ans=1;
  for(ll i=1;i<=n;i++){
    ans=((ans%1000000007)*(i%1000000007))%1000000007;
  }
  return ans;
}


void solve(){
 ll a,b,c,d;
 cin >> a >> b >> c >> d;
 ll p1=a*c;
 p1=max(a*d,p1);
 p1=max(b*c,p1);
 p1=max(b*d,p1);
 cout << p1 << '\n';

}





int main()
{
  #ifndef ONLINE_JUDGE
       freopen("in.txt", "r", stdin);
       freopen("out.txt", "w", stdout);
  #endif
  fastIO;
    int t=1;
   // cin >> t;
    while(t--){
     solve();
    }
    return 0;
    }

Measured memory_bytes: 3644
//84104971101048411497 - Can you guess what does this mean?
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 505
#define oo 2000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int H, W, h, w, a[maxN][maxN];

int main () {
    scanf("%d%d%d%d", &H, &W, &h, &w);
    int sum = 0;
    fto(i, 1, H) {
        fto(j, 1, W) {
            if (i%h == 0 && j%w == 0) a[i][j] = -1000*h*w+999;
            else a[i][j] = 1000;
            sum += a[i][j];
        }
    }

    if (sum > 0) {
        puts("Yes");
        fto(i, 1, H) {
            fto(j, 1, W) printf("%d ", a[i][j]);
            puts("");
        }
    } else puts("No");

    return 0;
}


Measured memory_bytes: 2560
s = input()
a = ["R", "U", "D"]
b = ["L", "U", "D"]
for i, j in enumerate(s):
    if i % 2 == 0:
        if not j in a:
            print("No")
            exit()
    else:
        if not j in b:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 3060
n=int(input())
l=list(map(int,input().split()))
res=0
if n<=2:
	print(0)
else:
	for i in range(n):
		for j in range(i,n):
			for k in range(j,n):
				if (l[i]!=l[j]) and (l[j]!=l[k]) and (l[i]!=l[k]) and (l[i]+l[j]>l[k]) and (l[j]+l[k]>l[i]) and (l[k]+l[i]>l[j]):
					#print(l[i],l[j],l[k])
					res+=1
	print(res)


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    string a, b;cin >> a >> b;
    int n = a.size();
    int m = b.size();
    string ans = "EQUAL";
    if(n == m){
        inc(i, 0, n){
            if(a[i] < b[i]){
                ans = "LESS";
                break;
            }
            if(a[i] > b[i]){
                ans = "GREATER";
                break;
            }
        }
    }else if(n < m){
        ans = "LESS";
    }else{
        ans = "GREATER";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

int main() {
	int N,MOD=1e9+7; cin >> N;
	vector<int> x(N + 1, 1);
	for (int i = 2; i <= N; i++) {
		int z = i;
		for (int j = 2; j <= i; j++) {
			while (z%j == 0) {
				z /= j;
				x[j]++;
			}
			if (z == 1)break;
		}
	}
	long long ans = 1;
	for (int i = 1; i <= N; i++) {
		ans *= x[i];
		ans %= MOD;
	}
	cout << ans << endl;
}





Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  int d = 0;
  for (int i = 0; i < n; ++i) {
    int l;
    cin >> l;
    d += l;
    if (d > x) {
      cout << i + 1 << endl;
      return 0;
    }
  }
  cout << n + 1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n,a[100],i,j,k,tmp;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[n-1]);
  for(i=1;i<n;i++){
    k = a[i];
    j=i-1;
    while(j>=0 && k<a[j]){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = k;
    for(j=0;j<n-1;j++){
      printf("%d ",a[j]);
    }
    printf("%d\n",a[n-1]);
  }
  return 0;
}



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

string s;
char buf[500010];
int fail1[500010], fail2[500010]; 
int n;

void getfail(string &s, int *fail){
	fail[0] = -1;
	int j = -1;
	for (int i = 1; i <= n; i++){
		while (~j && s[j] != s[i - 1]) j = fail[j];
		fail[i] = ++j;
	}
}

int main(){
	scanf("%s", buf), s = buf;
	n = s.length();
	getfail(s, fail1);
	int len = n % (n - fail1[n]) == 0 && (n - fail1[n] <= n / 2) ? n - fail1[n] : -1;
	if (len == -1){
		printf("1\n1\n");
		return 0;
	}
	if (len == 1){
		printf("%d\n1\n", n);
		return 0;
	}
	printf("2\n");
	reverse(s.begin(), s.end());
	getfail(s, fail2);
	int ans = 0;
	for (int i = 2; i < n - 1; i++){
		if ((!fail1[i] || i % (i - fail1[i])) && (!fail2[n - i] || (n - i) % ((n - i) - fail2[n - i]))) ans++;
	}
	printf("%d\n", ans + 2);
	return 0;
}


Measured memory_bytes: 5120
N,K=map(int, input().split())
A=list(map(int, input().split()))
A.sort()
#---------------
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
#---------------
X = 10**5     #出力の制限
mod = 10**9+7 
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, X + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
ans = 0
if K == 1:
  print(0)
else:
  for i in range(N-K+2):
    ans += cmb(N-i-1,K-1,mod)*(A[N-1-i]-A[i]) % mod
    ans = ans % mod
  print(ans % mod)

Measured memory_bytes: 20568
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
    	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    	String line = br.readLine();
    	int x = Integer.parseInt(line);
    	int y = x*x*x;
    	System.out.println(y);
    }
}

Measured memory_bytes: 24272
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

ans = 0

r_ = p
s_ = r
p_ = s

for i in range(k):
    if t[i] == 'r':
        ans += r_
    if t[i] == 's':
        ans += s_
    if t[i] == 'p':
        ans += p_

for i in range(k,n):
    if t[i] == t[i-k]:
        t[i] = 'z'
    else:
        if t[i] == 'r':
            ans += r_
        if t[i] == 's':
            ans += s_
        if t[i] == 'p':
            ans += p_

print(ans)

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


int main(){
  int x;
  cin >> x;
  if(x>=30) cout << "Yes" << endl;
  else cout << "No" << endl;
}
  

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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	if (s=="KIHBR"||s=="AKIHBR"||s=="KIHABR"||s=="AKIHABR"||s=="KIHBAR"||s=="AKIHBAR"||s=="KIHABAR"||s=="AKIHABAR"||s=="KIHBRA"||s=="AKIHBRA"||s=="KIHABRA"||s=="AKIHABRA"||s=="KIHBARA"||s=="AKIHBARA"||s=="KIHABARA"||s=="AKIHABARA")
	{
		cout<<"YES\n";
	}
	else
	{
		cout<<"NO\n";
	}
	return 0;
}


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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        _i64 n, a; _i64 min = INT64_MAX; _i64 max = INT64_MIN; _i64 sum = 0; cin >> n;
        _rep(i, n) { cin >> a; if(a < min) { min = a; } if(a > max) { max = a; }  sum += a; }
        cout << min << " " << max << " " << sum << endl;
    }
    return 0;
}


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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

    int res = 0;
    FOR(i,1, n+1){
        FOR(j, i, n+1){
            FOR(k, j, n+1){
                if (i != j && j != k && k != i){ 
                    res += 6 * gcd(i, gcd(j, k));
                } else if (i == j && j == k){
                    res += i;
                } else {
                    res += 3 * (gcd(i, gcd(j, k)));
                }
            }
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3624
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/multiset_of.hpp>
#include <boost/multi_array.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/pending/disjoint_sets.hpp>
// #include <atcoder/all>

#define REPI(i, S, N) for(int i=int(S); i<int(N); i++)
#define REP(i, N) REPI(i, 0, N)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;
using namespace boost::integer;

using ll = long long;
namespace bst = boost;
// using mint = atcoder::modint1000000007;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> A;


  return !A;
}

template<typename T> void plot(const T& func) { cout << setprecision(9) << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }

int main() {
  plot(solve);

  return 0;
}


Measured memory_bytes: 3632
n=int(input())
a=list(map(int,input().split()))
c=0
d=0
a.sort()
e=len(a)-1
f=0
while(e>=0):
	if(f==0):
		c+=a[e]
		f=1
	elif(f==1):
		d+=a[e]
		f=0
	e-=1
print(c-d)			


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

const int MAXN = 100000 + 5;

int N, M;
vector<int> Adj[MAXN];
int fa[MAXN], col[MAXN], dep[MAXN];

bool hasCircle;
int circA, circB;

inline void addEdge(int u, int v)
{
	Adj[u].push_back(v);
	Adj[v].push_back(u);
}

void DFS(int cur)
{
	dep[cur] = dep[fa[cur]] + 1;
	col[cur] = (dep[cur] & 1 ? 1 : -1);

	for (int to : Adj[cur])
	{
		if (to == fa[cur])
			continue;
		if (dep[to])
		{
			if (!hasCircle)
				circA = cur, circB = to, hasCircle = true;
		}
		else
			fa[to] = cur, DFS(to), col[cur] += col[to];
	}
}

int solveAcyclic()
{
	if (col[1])
		return -1;

	int ret = 0;
	for (int i = 1; i <= N; i++)
		ret += abs(col[i]);
	return ret;
}

int solveOddCircle()
{
	if (col[1] & 1)
		return -1;

	int delta = -col[1] / 2, ret = abs(delta), cur;
	cur = circA;
	while (cur)
		col[cur] += delta, cur = fa[cur];
	cur = circB;
	while (cur)
		col[cur] += delta, cur = fa[cur];

	for (int i = 1; i <= N; i++)
		ret += abs(col[i]);
	return ret;
}

int solveEvenCircle()
{
	if (col[1])
		return -1;

	int circle[MAXN] =
	{ 0 }, top = 0;
	for (int cur = circA; cur != circB; cur = fa[cur])
		circle[++top] = col[cur], dep[cur] = 0;

	int mid = (top + 1) >> 1, delta, ret;
	nth_element(&circle[1], &circle[mid], &circle[top + 1]);
	delta = (circle[mid]), ret = abs(delta);

	for (int i = 1; i <= N; i++)
		if (dep[i])
			ret += abs(col[i]);
	for (int i = 1; i <= top; i++)
		ret += abs(circle[i] - delta);
	return ret;
}

int main()
{
	//printf("%d %d\n", 1 & 1, -1 & 1);
	fflush(stdout);

	scanf("%d%d", &N, &M);
	for (int i = 1; i <= M; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		addEdge(u, v);
	}

	DFS(1);

	if (!hasCircle)
		printf("%d\n", solveAcyclic());
	else
	{
		if ((dep[circA] - dep[circB] + 1) & 1)
			printf("%d\n", solveOddCircle());
		else
			printf("%d\n", solveEvenCircle());
	}

	return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    double v;
    while(cin >> v)
    {
        double t = v / 9.8;
        double y = 4.9 * t * t;
        int h = 1;
        while(1)
        {
            if(y < 5 * h - 5) break;
            h++;
        }
        cout << h << endl;
    }
    return 0;
}




Measured memory_bytes: 3152
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>

#define maxn 100005

using namespace std;

inline int getint()
{
	int num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n;
long long sum[maxn],ans;

int main()
{
    n=getint();
	for(int i=1;i<=n;i++)
	{
		sum[i]=getint();
		ans+=sum[i]*sum[i-1];
		sum[i]+=sum[i-1];
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

a.sort()

if n == 1:
    print(1)
    exit()

ans = [1] * (a[n-1]+1)

for i in range(n):
    if i >= 1 and a[i] == a[i-1]:
        ans[a[i]] = 0

    else:
        j = 2
        while j*a[i] <= a[n-1]:
            ans[j*a[i]] = 0
            j += 1


sum = 0

for i in range(n):
    sum += ans[a[i]]


print(sum)


Measured memory_bytes: 32168
#include <iostream>
#include<bitset>
using namespace std;
int main()
{
    long long int n; cin >> n;
    cout << bitset<32>(n) << endl;
    cout << bitset<32>(~n) << endl;
    cout << bitset<32>(n << 1) << endl;
    cout << bitset<32>(n >> 1) << endl;
}


Measured memory_bytes: 3156
#include<stdio.h>
int data[100], out[100];
int i = 0, k = 0;
int top(){
  return data[i - 1];
}
void pop(){
  i--;
}

int main(){
  int a;
  while(scanf("%d", &data[i]) != EOF){
  if(data[i] != 0){
      i++;
    }else{
      out[k] = top() ;
      k++;
      pop();
    }
  }
  for(a = 0; a < k; a++){
    printf("%d\n",out[a]);
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<int,int>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;

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

	ll r,d,x;
	cin >> r >> d >> x;
	FOR(i,1,11){
		x = r*x-d;
		cout << x << endl;
	}

	
}


Measured memory_bytes: 764
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}

int main() {
    string S;
    cin >> S;
    if (S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3580
#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(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
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;}

const int mod = 1000000007;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

int main() {
  int n; cin >> n;
  int x[n];
  FOR(i,0,n-1) cin >> x[i];

  mint porb = 0;
  mint ans = 0;

  FOR(i,0,n-2){
    porb += (mint)1 / (i+1);
    ans += porb * (x[i+1]-x[i]);
  }
  FOR(i,1,n-1){
    ans *= i;
  }

  cout << ans.x << endl;
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
#include <chrono>

#define _ << " " <<
#define all(v) v.begin(), v.end()
#define sp(n) fixed << setprecision(n)
#define ff first
#define ss second

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const ll mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a, b;
	cin >> a >> b;
	//ll k = (a + b) / 2;
	if (a > b) swap(a, b);
	for (ll i = max(a, (a + b) / 2 - 100000); i <= min(b, (a + b) / 2 + 100000); i++) {
		if (abs(a - i) == abs(b - i)) {
			cout << i;
			return 0;
		}
	}
	cout << "IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 105
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll N,x;
vector<ll> a;

int main()
{
	ll A;
	scanf("%lld%lld",&N,&x);
	for(int i=0;i<N;i++){
		scanf("%lld",&A);
		a.push_back(A);
	}
	int cnt=0;
	sort(a.begin(),a.end());
	for(int i=0;i<N;i++){
		//printf("%lld,",a[i]);
		x -= a[i];
		if(x>=0)cnt++;
		else break;
	}
	if(x>0)cnt--;
	if(cnt<0)cnt=0;
	printf("%d\n",cnt);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  if (s[0] != '7' and s[1] != '7' and s[2] != '7'){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}


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

  int a,b;
  vector<pair<int,int> > red;
  rep(i,n){
    cin >> a >> b;
    red.push_back(make_pair(a,b));
  }
  vector<pair<int,int> > blue;
  rep(i,n){
    cin >> a >> b;
    blue.push_back(make_pair(a,b));
  }
  sort(all(red));
  sort(all(blue));

  int ans = 0;
  int redIndex = 0, blueIndex = 0;
  vector<int> redY;
  while(blueIndex < n){
    if(redIndex < n && red[redIndex].first <= blue[blueIndex].first){
      redY.push_back(red[redIndex].second);
      redIndex ++;
    }else{
      sort(all(redY),greater<int>());
      rep(i,redY.size()){
        if(redY[i] < blue[blueIndex].second){
          ans++;
          redY[i] = 2000;
          break;
        }
      }
      blueIndex++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a, s, r;
int main()
{
	cin>>a;
	for(int d=0;d<a;d++)
	{
		int x, x2;
		cin>>x>>x2;
		if(x==x2)
		{
			s+=1;
		}
		else
		{
			if(s>=3)
			{
				r+=1;
			}
			s=0;
		}
	}
	if(s>=3||r>=1)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  if (a == b)
    cout << "Draw" << endl;
  else
  {
    if (a == 1)
      cout << "Alice" << endl;
    else if (b == 1)
      cout << "Bob" << endl;
    else if (b < a)
      cout << "Alice" << endl;
    else
      cout << "Bob" << endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
	int i,l,n,c=0;
	char s[131072];
	scanf("%s",s);
	l = strlen(s);
	for(i = 0;i<l;i++){
		if(!(i)){
			if(s[i] == 'B'){n = 0;}
			else{n = 1;}
		}
		else if(s[i] == 'B' && n == 1){c++;n=0;}
		else if(s[i] == 'W' && n == 0){c++;n=1;}
	}
	printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  int i,j,k,A[1000],N,v;

  scanf("%d", &N);
  for(k=0;k<N;k++)
    {
      scanf("%d", &A[k]);
    }
  for(k=0;k<N;k++)
    {
      if(k>0)printf(" ");
      printf("%d",A[k]);
    }
  printf("\n");
  
  for(i=1;i<=N-1;i++)
    {
      v=A[i];
      j=i-1;
      while(j>=0 && A[j]>v)
	{
	  A[j+1]=A[j];
	  j--;
	}
      A[j+1]=v;
      for(k=0;k<N;k++)
	{
	  if(k>0)printf(" ");
	  printf("%d",A[k]);
	}
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2048
#include<stdio.h>
#define NIL -1
#define WHITE 0
#define BLACK 1
#define MAX 500
#define INF 1000000

int main(){
  int n, i, j, u, v, c, k, minv, M[MAX][MAX], check[MAX], p[MAX], key[MAX], a;
  scanf("%d", &n);
  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j] = INF;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    for(j=0; j<k; j++){
      scanf("%d%d", &v, &c);
      M[u][v] = c;
    }
  }
  for(i=0; i<n; i++){
    key[i] = INF;
    p[i] = NIL;
    check[i] = WHITE;
  }
  key[0] = 0;

  while(1){
    u=NIL;
    minv=INF;
    for(i=0; i<n; i++){
      if(key[i] < minv && check[i] == WHITE){
	u=i;
	minv = key[i];
      }
    }
    if(u == NIL)break;
    check[u] = BLACK;
    for(v=0; v<n; v++){
      if(check[v] == WHITE && key[v] > key[u] + M[u][v]){
	key[v] = key[u] + M[u][v];
	p[v] = u;
      }
    }
  }
  for(j=0; j<3; j++){
  }
  
  for(j=0; j<1; j++){
    for(i=0; i<n; i++){
      if(key[i]==INF)a=0;
      else a=key[i];
      printf("%d %d\n", i, a);
    }
  }

  return 0;
}



Measured memory_bytes: 2084
#include <iostream>
using namespace std;
int main(){
	
  int l,a[4];
  int i=0;
  while(cin>>l){
    a[i]=l;
    i++;
  }
  int ret=0;
  for(int i=0;i<a[0];i++){
    if(i<a[1]){
    ret+=a[2];
    }else{
    ret+=a[3];
    }
  }
  cout<<ret;
  return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 9

using namespace std;

typedef unsigned long long ull;

const string Y = "YES", N = "NO";
int n,field[MAX][MAX],V;
vector<int> V_sum;
vector<int> coor;

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

inline bool isValid(int x,int y){ return 0 <= x && x < n && 0 <= y && y < n; }

/*
bool check(ull used,int cur,int x,int y){
  int sp_x = x, sp_y = y;

  REP(i,cur,V){
    ull tmp_used = used;
    if( i != cur ) sp_x = coor[i] % n, sp_y = coor[i] / n;
    deque<int> deq;
    deq.push_back(sp_x+sp_y*n);
    bool ok = false;
    int score = V_sum[i];
    if( score == 0 ) ok = true;
    while(!deq.empty()){
      int p = deq.front(); deq.pop_front();
      int cx = p % n, cy = p / n;
      if(ok)break;
      rep(j,4){
	int nx = cx + dx[j];
	int ny = cy + dy[j];
	if(!isValid(nx,ny))continue;
	if((tmp_used>>(nx+ny*n))&1)continue;
	tmp_used |= (1ULL<<(nx+ny*n));
	score += field[ny][nx];
	if( score >= 0 ){
	  ok = true;
	  break;
	}
	deq.push_back(nx+ny*n);
      }
    }
    if(!ok)return false;
  }
  return true;
}
*/
bool dfs(ull used,int cur,int pre,int x,int y,int sum){

  if( cur >= V ){
    return true;
  }

  //if(!check(used,cur,x,y))return false;

  rep(i,4){
    if( i == pre ) continue;
    int nx = x + dx[i];
    int ny = y + dy[i];
    if( !isValid(nx,ny) ) continue;
    if( (used>>(nx+ny*n)) & 1 ) continue;
    if( field[ny][nx] < 0 ) continue;
    if( sum + field[ny][nx] > V_sum[cur] ) continue;

    int ncur = cur;
    int npre = ( i + 2 ) % 4;
    int nsum = sum + field[ny][nx];
    ull nused = used | (1ULL<<(nx+ny*n));
    if( sum + field[ny][nx] == V_sum[cur] ){
      ncur++;
      npre = -1;
      nsum = 0;
      nx = coor[ncur] % n;
      ny = coor[ncur] / n;
    }
    if( dfs(nused,ncur,npre,nx,ny,nsum) ) return true;
  }

  return false;  
}

int main(){

  while( scanf("%d",&n), n ){
    ull initial_state = 0ULL;
    V = 0;
    coor.clear();
    V_sum.clear();
    int sum = 0;
    rep(i,n)rep(j,n){
      scanf("%d",&field[i][j]);
      sum += field[i][j];
      if( field[i][j] < 0 ){
	V++;
	ull tmp = (1ULL<<(j+i*n));
	coor.push_back(j+i*n);
	initial_state |= (1ULL<<(j+i*n));
	V_sum.push_back(-field[i][j]);
      }
    }

    if( sum != 0 ){
      cout << N << endl;
      continue;
    }

    bool res = dfs(initial_state,0,-1,coor[0]%n,coor[0]/n,0);
    cout << (res?Y:N) << endl;
  }

  return 0;
}

Measured memory_bytes: 1244
//#define _GLIBCXX_DEBUG
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef map<int, int> mii;
    typedef map<char,int> mci;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef vector<ll> vll;
    typedef vector<pair<int,int>> vii;
    typedef vector<char> vc;
    typedef vector<vc> vcc;
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define pb push_back
    #define F first
    #define S second
    #define in insert
    #define mina(a,b) (a)=min((a),(b));
    #define maxa(a,b) (a)=max((a),(b));
    const int INF = 1e9 + 7;
    void solve(){
        int n; cin>>n;
        vi a(n+1),b(n+1),c(n+1);
        for(int i = 1; i <= n; i++) cin>>a[i];
        for(int i = 1; i <= n; i++) cin>>b[i];
        for(int i = 1; i < n; i++) cin>>c[i];

        int ans=0;
        for(int i = 1; i <= n; i++){   // eat a[i]
            ans+=b[a[i]];
            if(i<n) if(a[i+1]==a[i]+1){
                ans+=c[a[i]];
            }
            //cout<<ans<<" ";
        }
        cout<<ans;

    }
    int main(){
        int T=1;
        //cin>>T;
        for(int i = 0; i < T; i++) solve(); 
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  string s; cin >> s;
  const int n = s.length();

  s += "XXX";

  ll ans = 0;
  for(int i=0, r=0; i<n; i++){
    if(s[i] == 'A'){
      r++;
    } else if(s.substr(i, 2) == "BC"){
      ans += r;
      i++;
    } else {
      r = 0;
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
    int n, k; cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; ++i) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i = 0; i < k; ++i) ans += p[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <complex>
#include <cassert>

#define enp     puts("**chkchkchkchkchk**")
#define A       first
#define B       second
#define MP      make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;

const int INF = 0x60000000;
const int MINF = -1000000000;
const int mod = 1000000007;
const ll cons = 100000;
const double pi = 3.141592653589793;

vector < vector <int> > adj;
int vl[100001];

int main()
{
	int n;
	scanf("%d", &n);
	adj.resize(n + 1);

	for (int i = 1; i <= n; i++)
	{
		vl[i] = INF;
	}

	for (int i = 0; i < n - 1; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	int k;
	scanf("%d", &k);

	priority_queue < pair <int, int>, vector < pair <int, int> >, greater < pair <int, int> > > pq;

	while (k--)
	{
		int v, p;
		scanf("%d%d", &v, &p);
		pq.push(MP(p, v));
		vl[v] = p;
	}

	bool flag = true;
	while (!pq.empty())
	{
		pair <int, int> cur = pq.top();
		pq.pop();

		int u = cur.B;

		for (int i = 0; i < adj[u].size(); i++)
		{
			int v = adj[u][i];

			if (vl[v] != INF && abs(vl[v] - vl[u]) != 1)
			{
				flag = false;
				break;
			}

			if (vl[v] != INF)continue;

			vl[v] = cur.A + 1;

			pq.push(MP(cur.A + 1, v));
		}

		if (!flag)break;
	}

	if (!flag)
	{
		puts("No");
	}
	else
	{
		puts("Yes");

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

	return 0;
}

Measured memory_bytes: 7924
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")
    var tmp = data.shift().split(" ").map(Number)
    var A = tmp[0]
    var B = tmp[1]
    var M = tmp[2]
    var a = data.shift().split(' ').map(Number)
    var b = data.shift().split(' ').map(Number)
    var min_a = Math.min.apply(null, a);
    var min_b = Math.min.apply(null, b);
    var ans = 0
    for (var i = 0; i < data.length; i++) {
        var row = data[i].split(' ').map(Number)
        var x = row[0]
        var y = row[1]
        var c = row[2]
        var _x = a[x - 1]
        var _y = b[y - 1]
        var d = _x + _y - c
        if (i === 0) {
            ans = d
        }
        // console.log(ans)
        ans = Math.min(ans, d)
    }
    console.log(Math.min(ans, min_a + min_b))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 53836
while True:
    n, x = map(int, input().split())
    
    if n == x == 0:
        break
    
    ans = 0
    for i in range(1, n+1):
        for j in range(1, i):
            for k in range(1, j):
                if i + j + k == x:
                    ans += 1
    
    print(ans)


Measured memory_bytes: 5596
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) {
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
  }
  map<string, int> mp;
  rep(i, N) mp[s[i]]++;
  ll ans = 0;
  for(auto e : mp)
    ans += (ll)e.second*(e.second-1)/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <string>
#include <algorithm>

int main() {
    std::string s,t;
    std::cin >> s >> t;

    if (s == t) {
        std::cout << "Yes" << std::endl;
        return 0;
    }
    for (int i = 0; i < s.size(); i++) {
        std::rotate(s.begin(), s.begin() + 1, s.end());
        if (s == t) {
            std::cout << "Yes" << std::endl;
            return 0;
        }
    }

    std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
q = int(input())
for i in range(q) :
    b, e, k = map(int, input().split())
    count = 0
    for j in range(b, e) :
        if a[j] == k :
            count += 1
    print(count)
            


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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()
S=LIST()
T=LIST()

# dp[i][j][k] := Sをi文字目、Tをj文字目まで考えた時、kが0ならi方向、1ならj方向に遷移させる
dp=list3d(N+2, M+2, 2, 0)
dp[0][0][0]=1
for i in range(N+1):
    for j in range(M+1):
        dp[i][j][0]%=MOD
        # 数え上げをi方向とj方向で重複がないように遷移させる
        dp[i+1][j][0]+=dp[i][j][0]
        dp[i][j][1]+=dp[i][j][0]
        dp[i][j+1][1]+=dp[i][j][1]
        # 今回増やす数値が一致するなら
        if i<N and j<M and S[i]==T[j]:
            # 斜めに遷移させる(1→0)
            dp[i+1][j+1][0]+=dp[i][j][1]
print((dp[N][M][1])%MOD)


Measured memory_bytes: 371452
#include<iostream>
#include<algorithm>

int main(){
    int w, a, b;
    std::cin >> w >> a >> b;
    int aedge = a + w;
    int bedge = b + w;
    int ans;
    if((aedge > b && a < b) || (bedge > a && b < a))ans = 0;
    else if(a == b)ans = 0;
    else if(b < a)ans = a - bedge;
    else ans = b - aedge;
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedInputStream(System.in));
        int H = scan.nextInt();
        int W = scan.nextInt();
        char[][] grid = new char[H][];
        for (int i=0;i<H;i++) grid[i] = scan.next().toCharArray();
        Task tsk = new Task();
        char[][] fnl = tsk.solve(grid);
        for (char[] row: fnl) System.out.println(new String(row));
    }

    static class Task{
        public char[][] solve(char[][] grid) {
            boolean change = true;
            while (change) {
                change = false;
                char[][] delr = delRow(grid);
                if (delr != null) change = true;
                grid = delr == null? grid: delr;
                char[][] delc = delCol(grid);
                if (delc != null) {
                    grid = delc;
                    change = true;
                }
            }
            return grid;
        }

        private char[][] delRow(char[][] grid) {
            if (grid.length == 0) return null;
            int m = grid.length, n = grid[0].length;
            HashSet<Integer> rows = new HashSet<>();
            for (int i=0;i<m;i++) {
                boolean white = true;
                for (int j=0;j<n&&white;j++) {
                    if (grid[i][j] == '#') white = false;
                }
                if (white) rows.add(i);
            }
            if (rows.isEmpty()) return null;
            char[][] res = new char[m-rows.size()][n];
            int idx = 0;
            for (int i=0;i<m;i++) {
                if (rows.contains(i)) continue;
                for (int j=0;j<n;j++) res[idx][j] = grid[i][j];
                idx++;
            }
            return res;
        }

        private char[][] delCol(char[][] grid) {
            if (grid.length == 0) return null;
            int m = grid.length, n = grid[0].length;
            HashSet<Integer> cols = new HashSet<>();
            for (int j=0;j<n;j++) {
                boolean white = true;
                for (int i=0;i<m&&white;i++) {
                    if (grid[i][j] == '#') white = false;
                }
                if (white) cols.add(j);
            }
            if (cols.isEmpty()) return null;
            char[][] res = new char[m][n-cols.size()];
            for (int i=0;i<m;i++) {
                int idx = 0;
                for (int j=0;j<n;j++) {
                    if (cols.contains(j)) continue;
                    res[i][idx++] = grid[i][j];
                }
            }
            return res;
        }
    }
}


Measured memory_bytes: 25172