akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std  ;
typedef long  long ll ;
#define pb push_back
ll a[5] ;
int main() {
    ll i,n , t ;


    cin >> n >> t ;
    a[n]++ , a[t]++ ;

    for(i=1;i<4;i++){
        if (!a[i]){
            cout << i << endl ;
            return  0;
        }
    }




    return  0 ;
}






Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
  int n;
  string s;
  queue<char> ans;
  	cin >> n >> s;
  	ans.push(s[0]);
  	for(int i=0; i<n-1; i++){
      if(s[i] != s[i+1]){
        ans.push(s[i+1]);
      }
    }

  cout << ans.size() << endl;



}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp15
{
    class Class236
    {
        static int[] dy = new int[4] { 0, 1, 0, -1 };
        static int[] dx = new int[4] { 1, 0, -1, 0 };

        static void Main()
        {
            var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int H = HW[0], W = HW[1];
            var map = new bool[H, W];
            for(int i = 0; i < H; i++)
            {
                var r = Console.ReadLine();
                for(int j = 0; j < W; j++)
                {
                    if (r[j] == '#')
                        map[i, j] = true;
                }
            }

            var que = new Queue<Tuple<int, int, int>>();
            que.Enqueue(Tuple.Create(0, 0, 1));
            var frag = new bool[H, W];
            frag[0, 0] = true;

            while (que.Count > 0)
            {
                var p = que.Dequeue();
                for(int i = 0; i < 4; i++)
                {
                    int ny = p.Item1 + dy[i], nx = p.Item2 + dx[i];
                    int nc = p.Item3 + 1;

                    if (0 <= ny && ny < H && 0 <= nx && nx < W)
                    {
                        if (!frag[ny, nx] && !map[ny, nx])
                        {
                            frag[ny, nx] = true;
                            que.Enqueue(Tuple.Create(ny, nx, nc));
                            if (ny == H - 1 && nx == W - 1)
                                goto brk;
                        }
                    }
                }
            }
            brk:;
            if (frag[H - 1, W - 1])
            {
                var p = que.Last();
                int count1 = 0;
                int count2 = p.Item3;
                for (int i = 0; i < H; i++)
                    for (int j = 0; j < W; j++)
                        if (map[i, j]) count1++;

                Console.WriteLine(map.Length-count1-count2);
            }
            else Console.WriteLine("-1");

        }
    }
}


Measured memory_bytes: 13524
def add(bit, a, w, n):
    x = a
    while x <= n:
        bit[x] += w
        x += x & -x


def sum_from_zero(bit, a):
    ret = 0
    x = a
    while x > 0:
        ret += bit[x]
        x -= x & -x
    return ret


def main():
    [n, q] = [int(num) for num in input().split()]

    bit = [0 for _ in range(n + 1)]

    for i in range(q):
        [com, x, y] = [int(num) for num in input().split()]

        if com == 0:
            add(bit, x, y, n)
        else:
            print(sum_from_zero(bit, y) - sum_from_zero(bit, x-1))


if __name__ == '__main__':
    main()



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

#define DEBUG

#ifdef DEBUG
#define dump(x) cout << "[*] " #x ": " << x << endl
#define debug(x) x
#else
#define dump(x)
#define debug(x)
#endif

#define int long long
typedef long long ll;
//constexpr int INF = 1e9;
//constexpr int MOD = 1000000007;

decltype(1) main() {
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    sort(h.begin(), h.end());
    int ans = 0;
    for (int i = 0; i < n - k; ++i) {
        ans += h[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
struct edge {
    int to, cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;

typedef pair<int, int> P;

const int INF = 10000000;

vector<int> dist; 
vector<int> prever;

void dijkstra(int n, int s){
    dist = vector<int>(n,INF);
    prever = vector<int>(n,-1);
    dist[s] = 0;

    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top();
        que.pop();
        int v = p.second;
        if(dist[v] < p.first){
            continue;
        }
        for(int i=0;i<graph[v].size();i++){
            edge e = graph[v][i];
            if(dist[e.to] > dist[v] + e.cost){
                dist[e.to] = dist[v] + e.cost;
                prever[e.to] = v;
                que.push(P(dist[e.to],e.to));
            }
        }
    }
}

vector<int> get_path(int t){ //頂点tへの最短路
    vector<int> path;
    ll k = 0;
    for (; t != -1; t = prever[t]) {
        if (k == 2) break;
        path.push_back(t);
        k++;
    }

    return path;
}
int main(){
int n,m;
cin >> n >> m;
graph = AdjList(n);
for (ll i=0;i<m;i++){
    int from,to;
    cin >> from >> to;
    from--;
    to--;
    graph[from].push_back((edge){to, 1});
    graph[to].push_back((edge){from, 1});
}
dijkstra(n, 0);
cout << "Yes" << endl;
for (int i = 0; i < n - 1; i++){
vector<int> ans = get_path(i + 1);
cout << ans[1] +1<< endl;
}
}

Measured memory_bytes: 13600
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, Q, S, LR):
    p = []
    for i in range(N-1):
        if S[i] == 'A' and S[i+1] == 'C':
            p.append(i)
    
    for l, r in LR:
        l -= 1
        r -= 1
        i = bisect.bisect_left(p, l)
        j = bisect.bisect_left(p, r)
        print(j-i)


def main():
    N, Q = read_int_n()
    S = read_str()
    LR = [read_int_n() for _ in range(Q)]
    (slv(N, Q, S, LR))


if __name__ == '__main__':
    main()


Measured memory_bytes: 32624
// https://atcoder.jp/contests/abc130/tasks/abc130_b
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
// clang-format on
int main() {
  int N, X;
  cin >> N >> X;
  vector<int> L(N);
  for (auto &x : L) {
    cin >> x;
  }
  int tmp{}, cnt{};
  REP(i, N) {
    tmp += L[i];
    if (tmp <= X) {
      cnt++;
    }
  }
  cout << cnt + 1 << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;

#define endl "\n"

const ll INF = 1e15;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

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

    ll n;
    cin >> n;

    string ans;
    while (n) {
        ans += char(((n - 1) % 26) + 'a');
        n = (n - 1) / 26;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>


#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()

using namespace std;

const int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;

int N;
ll a[55];
signed main() {
	cin >> N;
	REP(i, N) {
		cin >> a[i];
	}
	int cnt = 0;
	REP(i, 10000000) {
		bool found = false;
		REP(j, N) {
			if (a[j] >= N) {
				found = true;
				cnt += a[j] / N;
				int c = a[j] / N;
				a[j] -= N * (a[j] / N);
				REP(k, N) {
					if (j == k)continue;
					a[k] += c;
				}
			}
		}
		if (!found)break;
	}
	print(cnt);
}


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

int main(void)
{
	int i, j, n, m, k, r = 0, max;
	long int a[200010], b[200010];

	scanf("%d%d%d", &n, &m, &k);

	a[0] = 0;
	b[0] = 0;

	for (i = 1; i < n + 1; i++)
	{
		scanf("%ld", &a[i]);
		a[i] += a[i - 1];
	}

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

Measured memory_bytes: 5272
import java.util.Scanner;
class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] cards = new int[4][13];
        
        for(int i = 1 ; i <= n ; i++){
            String mark = sc.next();
            int num = sc.nextInt();
            switch(mark){
                case "S":
                    cards[0][num-1] = 1;
                    break;
                case "H":
                    cards[1][num-1] = 1;
                    break;
                case "C":
                    cards[2][num-1] = 1;
                    break;
                case "D":
                    cards[3][num-1] = 1;
                    break;
            }
        }
        
        for(int i = 1 ; i <= 4 ; i++){
            for(int j = 1 ; j <= 13 ; j++){
                if(cards[i-1][j-1] != 1){
                    if(i == 1){
                        System.out.println("S" + " " + j);
                    } else if (i == 2){
                        System.out.println("H" + " " + j);
                    } else if (i == 3){
                        System.out.println("C" + " " + j);
                    } else {
                        System.out.println("D" + " " + j);
                    }
                }
            }
        }
        
    }
}


Measured memory_bytes: 26188
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

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

    int ans = 0;
    for(int i=0; i<=a; ++i){
        for(int j=0; j<=b; ++j){
            for(int k=0; k<=c; ++k){
                int y = 500 * i + 100 * j + 50 * k;
                if(x == y)
                    ++ ans;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        while(true)
        {
            string input = Console.ReadLine();
            var values = input.Split(' ');
            int[] numbers = new int[values.Length];
            for (int j = 0; j < values.Length; j++ )
            {
                numbers[j] = int.Parse(values[j]);
            }
            Array.Sort(numbers);

            if (numbers[0] == 0 && numbers[1] == 0) break;

            Console.WriteLine("{0} {1}", numbers[0], numbers[1]);
        }
    }
}

Measured memory_bytes: 5904
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

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 (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;


int main()
{
	int r; cin >> r;
	cout << 3 * r * r << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,k,ans=0; cin>>n>>k;
    for(int b=k+1;b<=n;b++){
        ans+=(n/b)*(b-k);
        int r=n%b;
        if(r>=k) ans+=r-max(k,1LL)+1;
    }
    cout<<ans<<endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

int H, W, K, ans[301][301], cnt[301], ind;
char s[301][301];

void cut(int h1, int h2)
{
    // いちごのある列
    vector<int> vec;
    FOR (h, h1, h2 + 1)
    {
        REP1 (w, W)
        {
            if (s[h][w] == '#')
                vec.push_back(w);
        }
    }
    sort(vec.begin(), vec.end());
    int V = vec.size();

    REP0 (i, V)
    {
        int w1 = 1, w2 = W;
        if (i >= 1)
            w1 = vec[i - 1] + 1;
        if (i < V - 1)
            w2 = vec[i];
        ind++;
        FOR (h, h1, h2 + 1)
        {
            FOR (w, w1, w2 + 1)
            {
                ans[h][w] = ind;
            }
        }
    }
}

void solve()
{
    cin >> H >> W >> K;
    REP1 (h, H)
    {
        REP1 (w, W)
        {
            cin >> s[h][w];
            if (s[h][w] == '#')
                cnt[h]++;
        }
    }

    // いちごのある行
    vector<int> vec;
    REP1 (h, H)
    {
        if (cnt[h] >= 1)
            vec.push_back(h);
    }

    int V = vec.size();

    REP0 (i, V)
    {
        // いちごが一行に集中するような形で
        // 行 h1 から h2 までここで横に切って、
        // そのあとに縦方向に切る(cut(h1,h2))
        int h1 = 1, h2 = H;
        if (i >= 1)
            h1 = vec[i - 1] + 1;
        if (i < V - 1)  // 最後の切り方は最終行であるようにするための条件
            h2 = vec[i];

        cut(h1, h2);
    }

    REP1 (h, H)
    {
        REP1 (w, W)
        {
            cout << ans[h][w];
            if (w < W)
                cout << ' ';
        }
        cout << endl;
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


Measured memory_bytes: 1280
n = int(input())
a = [input() for i in range(n)]
a.sort()
b =[]
k = 1
tmp = 1
d = 0
for i in range(n):
    if(i == 0):
        d = a[i]
        continue;
    if(a[i] != d):
        if(tmp == k):
            b.append(d)
        elif(tmp > k):
            k = tmp
            b = []
            b.append(d)
        tmp = 0
    tmp += 1
    d = a[i]

    if(i == n-1):
        if(tmp == k):
            b.append(a[i])
        elif(tmp > k):
            k = tmp
            b = []
            b.append(a[i])

for i in range(len(b)):
    print(b[i])




Measured memory_bytes: 20680
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const maxBuf = 200100

var debug = true

var buf []byte = make([]byte, maxBuf)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	if debug {
		testFile, err := os.Open("./test/sample-1.in")
		if err == nil {
			sc = bufio.NewScanner(testFile)
		}

	}
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

/* #### main #### */
func main() {
	H := readInt()
	W := readInt()

	odd := W/2 + W%2
	even := W / 2

	if H == 1 || W == 1 {
		fmt.Println(1)
		return
	}

	if H%2 == 0 {
		fmt.Println((even + odd) * (H / 2))
	} else {
		fmt.Println((even+odd)*(H/2) + odd)
	}
}


Measured memory_bytes: 1784
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N;
char S[100111];

int main() {
    scanf("%s", S);
    N = strlen(S);
    if (S[0] == S[N-1]) {
	puts(N & 1? "Second" : "First");
    } else {
	puts(N & 1? "First" : "Second");
    }

    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
typedef long long int lint;
using namespace std;

int main() {
    lint mod = 1e9 + 7;
    int n;
    string s;
    cin >> n >> s;
    if (s[0] != 'B' || s[2 * n - 1] != 'B') {
        cout << 0 << endl;
        return 0;
    }
    vector<int> t(2 * n);
    for (int i = 0; i < 2 * n; i++) {
        t[i] = s[i] == 'W' ? 0 : 1;
    }
    string lr(2 * n, ' ');
    int num = 0;
    for (int i = 0; i < 2 * n; i++) {
        if (num % 2 != t[i]) {
            lr[i] = 'L';
            num++;
        } else {
            lr[i] = 'R';
            num--;
            if (num < 0) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    if (num != 0) {
        cout << 0 << endl;
        return 0;
    }
    lint numl = 0;
    lint ans = 1;
    for (int i = 0; i < n; i++) {
        ans = (ans * (i + 1)) % mod;
    }
    for (int i = 0; i < 2 * n; i++) {
        if (lr[i] == 'L') {
            numl++;
        } else {
            ans = (ans * numl) % mod;
            numl--;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1540
import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt() + 1;
    int[] heap = new int[size];
    for (int i = 1; i < size; i++) {
      heap[i] = sc.nextInt();
    }

    for (int i = size / 2; i > 0; i--) {
      maxHeapify(heap, i, size);
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 1; i < size; i++) {
      sb.append(" ").append(heap[i]);
    }
    System.out.println(sb);
  }

  public static void maxHeapify(int[] heap, int i, int size) {
    int l = i * 2;
    int r = i * 2 + 1;
    int largest;

    if (l < size && heap[l] > heap[i]) {
      largest = l;

    } else {
      largest = i;
    }

    if (r < size && heap[r] > heap[largest]) {
      largest = r;
    }

    if (largest != i) {
      int tmp = heap[i];
      heap[i] = heap[largest];
      heap[largest] = tmp;
      maxHeapify(heap, largest, size);
    }
  }
}



Measured memory_bytes: 167200
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#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 pb push_back
#define pii pair<int,int>
#define mp make_pair
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
	//q=50000????????§????????????????????¨????????????
	//C++??????binary_search??¨?????????????????¢??°?????????
	//b2.cpp??§??????????????°??????????????????????£?
	int n,q;
	ll int cnt = 0;
	cin >> n;
	ll int data[100000];
	REP(i,n) cin >> data[i];
	sort(data,data+n);
	cin >> q;
	REP(i,q){
		ll int tmp;
		cin >> tmp;
		if(binary_search(data,data+n,tmp)) cnt++;
	}
	cout << cnt << endl;
	
}

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

int main(){
	long n = 0;
	long m = 0;
	cin >> n >> m;
	vector< vector<long> > a(n);
	vector<long> b(m, 0);
	vector<long> c(n, 0);
	for (long i = 0; i < n; i++){
		a[i].resize(m);
	}
	for (long i = 0; i < n; i++){
		for (long j = 0; j < m; j++){
			a[i][j] = 0;
			cin >> a[i][j];
		}
	}
	for (long i = 0; i < m; i++){
		cin >> b[i];
	}
	for (long i = 0; i < n; i++){
		for (long j = 0; j < m; j++){
			c[i] += a[i][j] * b[j];
		}
	}
	for (long i = 0; i < n; i++){
		cout << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int L, R;
  cin >> L >> R;

  if (L / 2019 == R / 2019)
  {
    L %= 2019;
    R %= 2019;

    int ans = 2020;
    for (int i = L; i < R; i++)
	{
      for (int j = i + 1; j <= R; j++)
	  {
        ans = min(ans, (i * j) % 2019);
      }
    }
    cout << ans << endl;

  } else {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
using System;
class Program
{
  static void Main(string[] args)
  {
    string s = Console.ReadLine();
    
    s = s.Replace(s[0].ToString(), string.Empty);
    if (s.Length != 2)
    {
      Console.WriteLine("No");
      return;
    }
    
    s = s.Replace(s[0].ToString(), string.Empty);
    Console.WriteLine(s.Length == 0 ? "Yes" : "No");
  }
}


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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<ll> A;
    ll before = 0;
    A.push_back(INF);
    REP(i,N){
        ll a; cin >> a;
        if(a != before) A.push_back(a);
        before = a;
    }
    A.push_back(0);
    ll ans = 1000;
    ll stock = 0;
    FOR(i,1,A.size()-1){
        if(A[i-1]>A[i] && A[i]<A[i+1]){
            stock = ans/A[i];
            ans = ans - stock*A[i];
        }
        if(A[i-1]<A[i] && A[i]>A[i+1]){
            ans = ans + stock*A[i];
            stock = 0;
        }
    }
    cout << ans << endl;
    


    return 0;
}

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

int main(void){
    long long int a,b;
    scanf("%lld%lld", &a,&b);

    if(a+b==3){
        printf("3\n");
    }
    else if(a+b==4){
        printf("2\n");
    }
    else if(a+b==5){
        printf("1\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <climits>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> P1;
typedef pair<P,P> P2;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

#define INF 1000000000
#define mod 1000000007
#define MAX5 100001

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

// cout << setfill('0') << setw(5) << number < endl;
// while(getline(cin, s)) { .. } | `s` is a string

int gcd(int a, int b){
	int old_a, old_b;
	while(a % b != 0){
		old_a = a;
		old_b = b;

		a = old_b;
		b = old_a % old_b;
	}

	return b;
}

int main(){
	IOS;
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif
	
	// auto l = [] () -> bool {
	// 	cout << "Hello, lamda function!" << endl;
	// 	return 2 > 1;
	// };
	// cout << l() << endl;

	int n, k, d, temp;
	cin >> n >> k;
	vector<bool> x(n, false);
	while(k--) {
		cin >> d;
		while(d--) {
			cin >> temp;
			x[temp-1] = true;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if(!x[i])
			ans++;
	}
	cout << ans << endl;
	return 0;
}

/*
11 
4 4 
-2 -2 
-3 -4 
-1 3 
2 3 
-4 0 
1 1 
-1 -1 
3 -1 
-4 2 
-2 4
*/

















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

using namespace std;

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

    int n, k = 2;
    cin >> n;

    vector<long long> h(n);
    vector<long long> jump(n);
    for(int i = 0; i < n; ++i)
        cin >> h[i];

    jump[n - 1] = 0;
    for(int i = n - 2; i >= 0; i--) {
        jump[i] = jump[i + 1] + abs(h[i] - h[i + 1]);
        for (int j = i + 2; j < min(n, i + k + 1); ++j)
            jump[i] = min(jump[i], jump[j] + abs(h[i] - h[j]));
    }


    cout << jump[0] << "\n";

    return 0;
}//RUL0

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;

bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int abs(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int n,m;
  cin>> n>>m;
  vector<int> x(m);

  for(int i=0;i<m;i++){
    cin>>x[i];
  }
  
  sort(x.begin(),x.end());
  ll ans =0;
  if(n>=m){
    cout<<0<<endl;
  }
  else{
    vector<int> l(m);
    for(int i=0;i<m-1;i++){
      l[i] = x[i+1]-x[i];

    }
    sort(l.begin(),l.end());
    reverse(l.begin(),l.end());
    for(int i=0;i<m-n;i++){
      ans += l[i+n-1]; 
    }
    cout<<ans <<endl;
  }
  
}

Measured memory_bytes: 1024
n,A,B,C = map(int,input().split())
list1 = [int(input()) for i in range(n)]

def search(t,a,b,c):
    if t == n:
        return abs(A-a)+abs(B-b)+abs(C-c) -30 if min(a,b,c) > 0 else 10**9
        #-30について。少なくともa,b,c各一本の竹はコストを払わずに使用することができ、また必ず使用するため、
        #予め30引くことでそのままprintできる。(printの方で-30したほうが分かりやすいとは思うが)
    ret0 = search(t+1,a,b,c)
    ret1 = search(t+1,a+list1[t],b,c) +10
    ret2 = search(t+1,a,b+list1[t],c) +10
    ret3 = search(t+1,a,b,c+list1[t]) +10
    return min(ret0,ret1,ret2,ret3)

print(search(0,0,0,0))

Measured memory_bytes: 43996
#2019/09/30
(N, M, C), B, *A = [list(map(int, i.split())) for i in open(0)]
#print(N, M, C)
#print(B)
#print(A)
src = list([[i*j for i,j in zip(a, B)] for a in A])
#( )で囲むとジェネレータになる
#参照：https://rennnosukesann.hatenablog.com/entry/2017/03/17/163959
#src = list(([i*j for i,j in zip(a, B)) for a in A])
#print(src)
cnt = 0
for i in src:
    if (sum(i) + C) > 0:
#        print(sum(i), i)
        cnt += 1
print(cnt)

#別解
'''
cnt = 0
for a in A:
    ans = 0
    for i,j in zip(a, B):
        ans += i*j
    if (ans + C) > 0:
        cnt += 1
print(cnt)
'''

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
//#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
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;
}
signed main() {
    int N;
    cin >> N;
    map<string, int> M;
    rep(i, N) {
        string s;
        cin >> s;
        M[s]++;
    }
    int ans = 0;
    for(auto x : M) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 19236
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  int a[n][m], b[m], c[n] = {0};
  rep(i, n) {
    rep(j, m) cin >> a[i][j];
  }
  rep(i, m) cin >> b[i];
  rep(i, n) {
    rep(j, m) c[i] += a[i][j] * b[j];
  }

  rep(i, n) cout << c[i] << endl;

  return 0;
}


Measured memory_bytes: 3096
using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using System.Numerics;

namespace competitive
{
    class Program
    {
        static void Main(string[] args)
        {
            var scanner = new Scanner();
            var n = scanner.NextInt();
            var an = scanner.NextLineToIntList();
            var ans = int.MaxValue;
            for (int i = -100; i <= 100; i++)
            {
                var sum = 0;
                foreach (var item in an)
                {
                    sum += (item - i) * (item - i);
                }
                if (ans > sum)
                {
                    ans = sum;
                }
            }
            Console.WriteLine(ans);
        }
    }


    #region
    public static class Extensions
    {
        public static int ToInt(this string str) => int.Parse(str);
        public static double ToDouble(this string str) => double.Parse(str);
        public static long ToLong(this string str) => long.Parse(str);
        public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    }

    public class Scanner
    {
        private TextReader reader;
        public Scanner()
        {
            reader = Console.In;
        }
        public Scanner(TextReader reader)
        {
            this.reader = reader;
        }
        private string NextWord()
        {
            var sb = new StringBuilder();
            while (true)
            {
                var c = reader.Read();
                if ((c == 13 || c == 10 || c == 32) && sb.Length > 0 || c == -1)
                {
                    break;
                }
                sb.Append((char)c);
            }
            return sb.ToString();
        }
        public int NextInt() => NextWord().ToInt();
        public string Next() => NextWord();
        public double NextDouble() => NextWord().ToDouble();
        public long NextLong() => NextWord().ToLong();
        public BigInteger NextBigInteger() => NextWord().ToBigInteger();
        public string NextLine()
        {
            var str = reader.ReadLine();
            if (string.IsNullOrWhiteSpace(str))
            {
                return reader.ReadLine();
            }
            else
            {
                return str;
            }
        }
        private List<string> NextLineToList() => NextLine().Split(new char[] { ' ' },
                                                                  StringSplitOptions.RemoveEmptyEntries)
                                                           .ToList();
        public List<int> NextLineToIntList() => NextLineToList().Select(x => int.Parse(x))
                                                                .ToList();
    }
    #endregion
}


Measured memory_bytes: 13396
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int[] h = new int[n];
		for(i=0; i<n; i++) {
			h[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		sc = null;
		Arrays.sort(h);
		int min = 1000000000;
		int dif;
		for(i=0; i<n-k+1; i++) {
			dif = h[i + k-1] - h[i];
			if(min > dif) min = dif;
		}
		System.out.println(min);
	}
}

Measured memory_bytes: 47988
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

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

    if(x <= 599) cout << 8 << endl;
    else if(x <= 799) cout << 7 << endl;
    else if(x <= 999) cout << 6 << endl;
    else if(x <= 1199) cout << 5 << endl;
    else if(x <= 1399) cout << 4 << endl;
    else if(x <= 1599) cout << 3 << endl;
    else if(x <= 1799) cout << 2 << endl;
    else if(x <= 1999) cout << 1 << endl;

    return 0;
}

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

int main(){
    int x,ans=0,a=1;
    cin>>x;
    for(int i=1;i<35;i++){
        int b=1;
        for(int k=0;k<30;k++){
            b*=i;
        if(k>0&&b<=x){
            ans=max(b,ans);
        }
    }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import defaultdict


def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A


def divisor(n):
    i = 1
    d = []
    while i * i <= n:
        if n % i == 0:
            d.append(i)
            if i * i != n:
                d.append(n // i)
        i += 1
    return d


def solve(N, A):
    ans = []
    for i in range(N, 0, -1):
        if A[i-1] == 1:
            ans += [i]
            for d in divisor(i):
                A[d-1] ^= 1
    print(len(ans))
    print(*ans)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main(){
    int n, x, i;
    cin >> n >> x;
    int m[n];
    for(i=0; i<n; i++){
        cin >> m[i];
        x -= m[i];
    }
    sort(m, m+n);
    cout << n + x/m[0];
    return 0;
}

Measured memory_bytes: 256
import itertools
import math
import sys
input = sys.stdin.readline


def TotalDis(L):
    D = 0
    for i in range(len(L) - 1):
        Xi, Yi = L[i]
        Xj, Yj = L[i+1]
        D += math.sqrt((Xj-Xi)**2 + (Yj-Yi)**2)
    return D


N = int(input())
P = []
for i in range(N):
    x, y = map(int, input().split())
    P.append((x, y))

SumDis = 0
for l in itertools.permutations(P):
    SumDis += TotalDis(l)
ans = SumDis/math.factorial(N)

print(ans)


Measured memory_bytes: 9016
X = int(input())

if X >=400 and X<=599:
    ans=8
elif X >=600 and X<=799:
    ans=7
elif X >=800 and X<=999:
    ans=6
elif X >=1000 and X<=1199:
    ans=5
elif X >=1200 and X<=1399:
    ans=4
elif X >=1400 and X<=1599:
    ans=3
elif X >=1600 and X<=1799:
    ans=2
elif X >=1800:
    ans=1
        
print(ans)

Measured memory_bytes: 9196
from itertools import permutations

Order = [int(input()) for _ in range(5)]

ans = []
for orders in permutations(Order):
    # print(orders)
    tmp = 0
    cnt = 1
    for order in orders:
        tmp += order
        if cnt == 5:
            ans.append(tmp)
        for _ in range(11):
            if tmp % 10 == 0:
                break
            tmp += 1
        cnt += 1

print(min(ans))

Measured memory_bytes: 9160
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
typedef long long ll;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=510000;
//~ const int mod=1e9+7;
const ll oo=1e18+5;

int dp[N];
int n,mod;

void add_self(int& a,int b){
	a+=b;
	if(a>=mod) a-=mod;
}

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	cin>>n>>mod;
	dp[0]=1;
	for(int i=2;i<=n;++i){
		int cur=min(i-1,n+2-i);
		//~ cout<<cur<<" ";
		for(int j=cur;j<=n;++j){
			add_self(dp[j],dp[j-cur]);
		}
	}
	//~ cout<<endl;
	//~ for(int i=0;i<=n;++i) cout<<dp[i]<<" ";cout<<endl;
	int ans=0;
	for(int i=0;i<=n;++i){
		add_self(ans,1ll*dp[i]*(n-i)%mod);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;
import java.io.*;
public class Main {
 
	public static void main(String[] args) throws Exception{
		int num = 998244353;
 
		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
//	 	
 		int n = Integer.parseInt(bf.readLine());
 		StringTokenizer st = new StringTokenizer(bf.readLine());
 		ArrayList<BigInteger> array = new ArrayList<BigInteger>();
 		boolean found = false;
 		for(int i = 0;i<n;i++){
 			array.add(new BigInteger(st.nextToken()));
 			if (array.get(i).equals(new BigInteger("0"))){
 				out.println(0);
 				out.close();
 				found = true;
 			}
 		}
 		if (found == false){
	 		BigInteger prod = new BigInteger("1");
	 		
	 		boolean found1 = true;
	 		for(int i = 0;i<n;i++){
	 			prod = prod.multiply(array.get(i));
	 			if (prod.compareTo(new BigInteger("1000000000000000000")) > 0){
	 				out.println(-1);
	 				found1 = false;
	 				break;
	 			}
	 		}
	 		if (found1 == true){
	 			out.println(prod);
	 		}
 		}
 		out.close();
 		
 		
 		
 	}
}


Measured memory_bytes: 56296
N, Y = map(int, input().split())
f = False
for x in range(2001):
    for y in range(2001):
        z = N - x - y
        if z < 0:
            continue
        if x * 10000 + y * 5000 + z * 1000 == Y:
            print(x, y, z)
            exit()
print('-1 -1 -1')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define SANKOU(n, a, b) cout << ((n) ? (#a) : (#b)) << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define P pair<int, int>
#define V vector<int>
#define M map<int, int>
#define S set<int>

int R, G, B, N;
void solve()
{
    int ans = 0;
    for (int r = 0; r <= N; r += R) {
        for (int g = 0; r + g <= N; g += G) {
            if ((N - r - g) % B == 0)
                ans++;
        }
    }
    cout << ans << endl;
}


signed main()
{
    cin >> R >> G >> B >> N;
    solve();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main {
  public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
    int num = 0;
    int sum = 0;
    for (int i = 0; i < N; i++) {
      int p = sc.nextInt();
      num = Math.max(num,p);
      sum += p;
    }
    System.out.println(sum-num/2);
  }
}  

Measured memory_bytes: 35912
import std.stdio;
import std.conv;
import std.array;
import std.math;
import std.algorithm;
import std.string;

public int gcd(int m, int n)
{
	if ((m == 0) || (n == 0)) return 0;
	
	while (m != n)
	{
		if (m > n) m = m - n;
		else n = n - m;
	}
	return m;
}

public int lcm(int m, int n)
{
	if ((m == 0) || (n == 0)) return 0;
	return ((m / gcd(m, n) * n));
}

int main()
{
	string s;
	while((s = readln()).length != 0)
	{
		string[] _s = split(s);
		int a = to!int(_s[0]);
		int b = to!int(_s[1]);
		int x = gcd(a,b);
		int y = lcm(a,b);

		printf("%d %d\n",x,y); 
	}
	return 0;
}

Measured memory_bytes: 1056
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (int i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (int i=(n);i>=(a);--i)
#define FI(i,n) for (int i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }

// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// I am questioning life and universe and 
// everything else after looking at this

vector<char> ch;
void solve(){   
    string s; cin>>s;
    s = s + ';';
    for(ll i=0;i<s.length();i++){
        if(s[i] == 'B' && s[i+1] == 'C'){
            ch.push_back('D');
            i++;
        }else {
            ch.push_back(s[i]);
        }
    }

    ll ans = 0;
    string temp = "";
    for(ll i=0;i<ch.size();i++){
        if(ch[i] == 'A' || ch[i] == 'D'){
            temp += ch[i];
        }else {
            ll d = 0;
            for(ll j=0;j<temp.length();j++){
                if(temp[j] == 'D') d++;
            }

            for(ll j=0;j<temp.length();j++){
                if(temp[j] == 'D') d--;
                else ans += d;
            }
            temp = "";
        }
    }

    cout<<ans<<endl;
}   

signed main(){

   FastRead;    


    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}




Measured memory_bytes: 1104
#include <stdio.h>

int main()
{
  int g,w,h=0,i,j,f,y,d;
  int A[100000],B[50000];

  scanf("%d",&g);
  for(i=0; i<g; i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&w);
  for(i=0; i<w; i++){
    scanf("%d",&B[i]);
    f = 0;
    d = g;
    while(f<d){
      y = (f+d)/2;
      if(A[y]<B[i])
        f = y+1;
      if(A[y]==B[i]){
        h++;
        break;
      }
      if(A[y]>B[i])
        d = y;
    }
  }    
  printf("%d\n",h);

  return 0;
}



Measured memory_bytes: 2280
h,w = gets.split.map(&:to_i)
n = gets.to_i
a = gets.split.map(&:to_i)

x = Array.new(h*w)
c = 0
a.each_with_index do |e,i|
    x.fill(i+1,c,e)
    c += e
end

h.times do |i|
    y = x[i*w,w]
    y.reverse! if i.odd?
    puts y.join(" ")
end

Measured memory_bytes: 2428
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,g;
    ll x,y;
    cin>>a>>b>>c;
    if(a==b&&b==c) cout<<1<<endl;
    else if(a==b||b==c||a==c) cout<<2<<endl;
    else cout<<3<<endl;
    return 0;
}


Measured memory_bytes: 3552
#include<stdio.h>

int main(void){
   int player = 0;
   int judger = 0;
   int ave_li[100]  ;
   int flag = 1;
   int num = 0;
   while (flag == 1) {
      scanf("%d", &judger);
      if (judger > 0) {
          int max = -1;
          int min = 1001;
          int sum = 0;
          for (int i = 0; i < judger; i++) {
              scanf("%d", &num);
              if(max < num) max = num;
              if(min > num) min = num;
              sum += num;
          }
          ave_li[player] = (sum - max - min) / (judger - 2);
          player++;
      }  else  {
         flag = 0;
      }
   }
   for (int i = 0; i < player; i++) {
       printf("%d\n", ave_li[i]);
   }
   return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N, K;
  cin >> N >> K;
  int ans = 0;
  FORS(i, K + 1, N) {
    ans += (N / i) * (i - K) + max(0ll, N % i - K + 1);
    if (K == 0)
      ans--;
  }
  print(ans);
}

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

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

    for(int i=1; i<=n; i++){
        auto result = find(a.begin(), a.end(), i);

        ans.push_back(distance(a.begin(), result)+1);
    }

    rep(i,n) cout << ans[i] << ' ';
    cout << endl;
    return 0;
}

Measured memory_bytes: 4132