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

pair<char, int> P[1000005];
pair<char, int> S[1000005], L[500005], R[500005];
long long sum=0;

void merge(int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i=0; i<n1; i++) {
        L[i] = S[left + i];
    }
    for (int i=0; i<n2; i++) {
        R[i] = S[mid + i];
    }
    L[n1].second = INF;
    R[n2].second = INF;
    int i = 0, j = 0;
    for (int k=left; k<right; k++) {
        if (L[i].second <= R[j].second) {
            S[k] = L[i];
            i++;
        }
        else {
            S[k] = R[j];
            j++;
        }
        sum++;
    }
}

void mergeSort(int left, int right) {
    if (left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(left, mid);
        mergeSort(mid, right);
        merge(left, mid, right);
    }
    return;
}

int partition(int p, int r) {
    int x, i, j;
    pair<char, int> t;
    x = P[r].second;
    i = p - 1;
    for (j = p; j < r; j++) {
        if (P[j].second <= x) {
            i++;
            t = P[i]; P[i] = P[j]; P[j] = t;
        }
    }
    t = P[i + 1]; P[i + 1] = P[r]; P[r] = t;
    return i + 1;
}

void quickSort(int p, int r) {
    if (p < r) {
        int q = partition(p, r);
        quickSort(p, q - 1);
        quickSort(q + 1, r);
    }
}

int main() {
    int n;
    cin >> n;
    for (int i=0; i<n; i++) {
        cin >> P[i].first >> P[i].second;
        S[i].first = P[i].first;
        S[i].second = P[i].second;
    }
    quickSort(0, n-1);
    mergeSort(0, n);
    for (int i=0; i<n; i++) {
        if (P[i].first != S[i].first) {
            cout << "Not stable\n";
            break;
        }
        if (i == n - 1) cout << "Stable\n";
    }
    for (int i=0; i<n; i++) {
        cout << P[i].first << " " << P[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 26552
# ARC094E

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n = int(input())
a = [None] * n
b = [None] * n
ans = 0
same = 0
m = 0
diff = []
for i in range(n):
    a[i],b[i] = map(int, input().split())
    if a[i]<b[i]:
        ans += (b[i] - a[i])
    elif a[i]==b[i]:
        same += a[i]
    else:
        diff.append(b[i])
        m += b[i]
diff.sort()
c = 0
plus = 0
if ans==0:
    print(0)
else:
    plus = sum(diff[1:])
    print(sum(a) - (m - plus))

Measured memory_bytes: 43484
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <size_t N>
using Bits = std::bitset<N>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    Int n;
    std::cin >> n;
    Vector<Int> b(n - 1);
    for (auto& x : b) std::cin >> x;
    b.insert(b.begin(), INF);
    b.push_back(INF);

    Int ans = 0;
    for (Int i = 0; i < n; ++i) {
        ans += std::min(b[i], b[i + 1]);
    }
    std::cout << ans << std::endl;
    return 0;
}


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

int main(int argc, char const *argv[]) {

  int n1;
  char *m;
  char num1[9];
  m = (fgets(num1, sizeof(num1), stdin));
  sscanf(num1, "%d\n", &n1);

  int ans;

  if (n1 % 2 == 0) {                        //偶数のとき
    ans = n1 / 2 - 1;
  }else{                                    //奇数のとき
    ans = (n1 - 1) / 2;
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <ctime>


#ifndef _USEFUL_MACROS_
#define _USEFUL_MACROS_
#define INF INT_MAX/3
#define N_PRIME 1000000007
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define OUTPUT_DEBUG
#ifdef OUTPUT_DEBUG
#define debug(x) cout<<#x<<": "<<x<<endl
#else
#define debug(x) do{}while(false)
#endif
#endif 

using namespace std;

class UnionFind{
public:
    UnionFind(int max_n){
        _max_n = max_n+1;
        parent = (int*)malloc(_max_n * sizeof(int));
        rank = (int*)malloc(_max_n * sizeof(int));
        
        init();
    }
    
    ~UnionFind(){
        free(parent);
        free(rank);
    }
    
    void init(){
        REP(i,_max_n){
            parent[i] = i;
            rank[i] = 0;
        }
    }
    
    // ??´??°n???????????¢???
    int getParent(int n){
        if( parent[n] == n ){
            return n;
        }else{
            parent[n] = getParent(parent[n]);
            return parent[n];
        }
    }
    
    // ??´??°n,m???????????????????±????????????????true
    bool same(int n,int m){
        return getParent(n) == getParent(m);
    }
    
    // ??´??°n,m????±?????????????????????£?????????
    void unite(int n,int m){
        n = getParent(n);
        m = getParent(m);
        
        if( n == m )return; // ???????????£???
        
        if( rank[n] < rank[m] ){
            parent[n] = m;  // ??????????????±???????????????????????????
        }else{
            parent[m] = n;  // ??????????????±???????????????????????????
            
            // ????????±???????????±????????±??????????????§
            if( rank[n] == rank[m] )
                rank[n]++;
        }
    }
    
private:
    int _max_n;
    int *parent;    // parent[i]:   ??´??°i???????????´??°
    int *rank;      // rank[i]  :   ??´??°i?????±???
};

int main(void){
    int n,q;
    UnionFind uf(10000);
    
    cin >> n >> q;
    REP(i,q){
        int a,b,c;
        cin >> a >> b >> c;
        
        if( a == 0 ){
            uf.unite(b,c);
        }else{
            cout << (uf.same(b,c)?1:0) << endl;
        }
    }
    
    
    
    return 0;
}

Measured memory_bytes: 3176
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int count=0;
        String word=sc.nextLine();
        word=word.toLowerCase();
        String sent="";
        while(sc.hasNext()){
            sent=sc.next();
            if(sent.equals("END_OF_TEXT")) break;
            sent=sent.toLowerCase();
            if(sent.equals(word))
                    count++;
            
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 26224
from copy import deepcopy


def dfs(v):
    visited[v] = 1
    ret = 1
    for w in r[v]:
        if visited[w] == 1:
            continue
        ret += dfs(w)
        visited[w] = 1
    return ret


n,m = map(int,input().split())
x = [[] for _ in range(n)]
x_list = []
cnt = 0
for _ in range(m):
    a,b = map(int,input().split())
    x_list.append([a-1,b-1])
    x[a-1].append(b-1)
    x[b-1].append(a-1)
for i in range(m):
    r = deepcopy(x)
    r[x_list[i][0]].remove(x_list[i][1])
    r[x_list[i][1]].remove(x_list[i][0])
    visited = [0]*n
    if dfs(0) == n:
        cnt += 1
print(m-cnt)

Measured memory_bytes: 3572
#include <iostream>
#include <cmath>
#include <string>
#include<set>
#include<vector>
using namespace std;

int main(void) {
    string s;
    int ans=0;
    cin >> s;
    for(int i=0; i<4; i++) {
        if(s[i]=='+')
            ans++;
        else
            ans--;
    }
    cout << ans << endl;
}


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

using namespace std;

int main(){
    
    while(1){
        int a, L;
        cin>> a>> L;
        if(!(a||L)) break;
        
        int k=1e6;
        int S[k];
        for(int i=0; i<k; i++) S[i]=-1;
        S[a]=0;
        int cnt=0;
        while(1){
            string A=to_string(a);
            while(A.size()!=L) A+='0';
            sort(A.begin(), A.end());
            int mi=stoi(A);
            reverse(A.begin(), A.end());
            int ma=stoi(A);
            a=ma-mi;
            cnt++;
            if(S[a]!=-1){
                cout<< S[a]<< " ";
                cout<< a<< " ";
                cout<< cnt-S[a]<< endl;
                break;
            }
            S[a]=cnt;
        }
    }

    return 0;
}

Measured memory_bytes: 7124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    bool ok = 1;
    vector<int> T(N);
    vector<pair<int,int>> C(N);
    REP(i,N){
        T[i] = in();
        C[i].F = in();
        C[i].S = in();
    }
    pair<int,int> A;
    A.F = 0;
    A.S = 0;
    int time = 0;
    REP(i,N){
        int dist = 0;
        dist = abs(C[i].F - A.F) + abs(C[i].S - A.S);
        if(T[i] - time < dist){
            ok = 0;
        }else if((T[i] - time)%2 == dist%2){
            ok = 1;
        }else{
            ok = 0;
        }
        if(ok == 0)break;
        A.F = C[i].F;
        A.S = C[i].S;
        time = T[i];
    }
    cout << (ok ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 1408
package main

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

func f(s []int) (s2 []int, t bool) {
	t = true
	for _, v := range s {
		if v%2 != 0 {
			t = false
			break
		}
		s2 = append(s2, int(v/2))

	}
	return
}

func main() {
	var (
		//		n int
		s []int
		t bool
		c int = 0
	)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	//	n, _ = strconv.Atoi(sc.Text())
	for sc.Scan() {
		a, _ := strconv.Atoi(sc.Text())
		s = append(s, a)
	}

	for {
		s, t = f(s)
		if t == true {
			c = c + 1
		}
		if t == false {
			break
		}
	}
	fmt.Println(c)
}


Measured memory_bytes: 768
n=3
num_list = []
for i in range(n):
    num_list.append(list(map(int,input().split())))

N=int(input())

list1=[int(input()) for _ in range(N)]

list2=[]
i=0
while i<=2:
    j=0
    while j<=2:
        list2.append(num_list[i][j])
        j=j+1
    i=i+1

s=0
for k in list2:
    if list1.count(k)==1:
        list2[s]=101
        s=s+1
    else:
        s=s+1
        continue

if list2[0]+list2[1]+list2[2]==303:
    print('Yes')
elif list2[3]+list2[4]+list2[5]==303:
    print('Yes')
elif list2[6]+list2[7]+list2[8]==303:
    print('Yes')
elif list2[0]+list2[3]+list2[6]==303:
    print('Yes')
elif list2[1]+list2[4]+list2[7]==303:
    print('Yes')
elif list2[2]+list2[5]+list2[8]==303:
    print('Yes')
elif list2[0]+list2[4]+list2[8]==303:
    print('Yes')
elif list2[2]+list2[4]+list2[6]==303:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9236
#include <math.h>
#include <bits/stdc++.h>
#include <deque>
#define ll long long
#define l long double
#define pi 3.14159265358979323846
#define mod 1000000007
#define val 1000000000000000000
using namespace std;
int main()
{
    ll n,s=1,cnt=0;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    {
        if(a[i]!=s)
        cnt++;
        else
        s=s+1;
        if(cnt==n-1)
        {
            if(s==1)
            cnt=-1;
            break;
        }
    }
    cout<<cnt<<endl;
}

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

int main(){
  
  long long N,A,B,C,D,E;
  cin>>N>>A>>B>>C>>D>>E;
  
  long long totalmin = min(A,min(B,min(C,min(D,E))));
  
  long long ans;
  if (N % totalmin > 0) ans = N/totalmin + 5;
  else ans = N/totalmin + 4;
  
  cout << ans << endl;
  
}

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

using namespace std;

typedef long long ll;

const ll ts = 100005;

#define IOS  ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"
ll dp[1 << 20][19];
ll ans[20][20];
ll a[20];
ll b[20];
signed main() {

    IOS;
    int n ; cin >> n ; 
    for(int i = 0; i < n; i++) {
    	cin >> a[i]   ;
	}
	for(int i = 0; i < n ; i++) {
		cin >> b[i];
	}
	int Final = 1 << n ; 
	for(int i = 0 ;  i< n ; i++) { 
	    for(int j =0; j < n ;j++) {
	    	ans[i][j]  = (i % 2 == j % 2) ? a[j] : b[j];
		}
	}
	for(int i =  0; i <= Final ; i++ ) {
		for(int j = 0;  j <= n ; j++) {
			dp[i][j] = INT_MAX;
		}
	}
	dp[1][0] = 0 ;  
	dp[0][0] = 0 ; 
	for(int i = 0 ; i < n ; i++) dp[1 << i][i] = i; 
//	cout << dp[2][1]  << endl;
	for(int m = 1  ; m < Final ; m++) {
		int i = __builtin_popcount(m);
		int d = 0  ;
		for(int j = 0 ;j < n ; j++) {
			if( m & (1 << j) ) continue; 
			for(int s =0; s < n ; s++) {
				
				if( m & (1 << s) ) {
					if(ans[i - 1][s] <= ans[i][j]) {
						
						
				     //	cout <<  m << " " <<(m ^ (1 << j)) <<" " << i << " " <<  s << " " << j << " ";
				     	
						dp[m ^ (1 <<j )][j] = min(dp[m][s] + d , dp[m^(1 << j)][j]);
						//cout << dp[m ^ (1 << j)][j]  << " "<< dp[m][s] << endl;
					}
					
					
				}
			}
			d++;
		}
	}
	ll res = INT_MAX;
	for(int i = 0; i <n ;i++) res = min(res , dp[Final - 1][i]);
	if(res == INT_MAX) cout << "-1";
	else cout << res << endl;
 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 


Measured memory_bytes: 41344
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
void Say(bool say, string a = "Yes", string b = "No"){cout << (say ? a : b) << endl;};

ll A[101010];

int main(){

    ll N;
    cin >> N;
    for(ll i = 1; i <= N; i++)cin >> A[i];
    ll ans = 0;
    for(ll i = 1, cnt = 0; i <= N + 1; i++){
        if(A[i] == 0){
            ans += cnt / 2;
            cnt = 0;
        }
        else cnt += A[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

const int D = 11;
const int U = (1 << D) - 1;

using pi = pair<int, int>;

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

    vector<int> v(n + 1), w(n + 1);
    rep(i, n) scanf(" %d %d", &v[i + 1], &w[i + 1]);

    vector<int> p(n + 1);
    p[1] = -1;
    for (int i = 2; i <= n; ++i) p[i] = i / 2;

    vector<int> dep(n + 1);
    dep[1] = 0;
    for (int i = 2; i <= n; ++i) dep[i] = dep[p[i]] + 1;

    vector<vector<pi>> up(U + 1);
    for (int i = 1; i <= min(U, n); ++i) {
        int x = i;
        vector<int> a;
        while (x > 0) {
            a.pb(x);
            x = p[x];
        }
        const int A = a.size();

        vector<pi> ss;
        rep(mask, 1 << A) {
            int tw = 0, tv = 0;
            rep(j, A) if (mask >> j & 1) {
                tw += w[a[j]];
                tv += v[a[j]];
            }
            ss.pb({tw, -tv});
        }
        sort(all(ss));

        up[i].pb({0, 0});
        for (const auto& pp : ss) {
            int vv = -pp.se;
            if (up[i].back().se < vv) up[i].pb({pp.fi, vv});
        }
    }

    int Q;
    scanf(" %d", &Q);
    rep(qqq, Q) {
        int x, L;
        scanf(" %d %d", &x, &L);

        int ans = 0;
        if (dep[x] <= D - 1) {
            auto itr = lower_bound(all(up[x]), pi(L + 1, 0));
            --itr;
            ans = itr->se;
        } else {
            vector<int> a;
            while (dep[x] > D - 1) {
                a.pb(x);
                x = p[x];
            }
            int A = a.size();

            rep(mask, 1 << A) {
                int tw = 0, tv = 0;
                rep(i, A) {
                    if (mask >> i & 1) {
                        tw += w[a[i]];
                        tv += v[a[i]];
                    }
                }
                if (tw > L) continue;

                auto itr = lower_bound(all(up[x]), pi(L - tw + 1, 0));
                --itr;
                ans = max(ans, tv + itr->se);
            }
        }

        printf("%d\n", ans);
    }

    return 0;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  
  vector<int> A(N);  
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  int totalvote = 0;
  for (int i = 0; i < N; i++) {
    totalvote += A.at(i);
  }    
  
  int count = 0;  
  for (int i = 0; i < N; i++) {
    if ((4 * M * A.at(i)) >= totalvote) {
      count++;
    }        
  }
  if (count >= M) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}        
        

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>

using namespace std;

int main(){
	int n;
	cin >> n;
	long long int now_a=1,now_b=1;
	int s,t; 
	
	for(int i=0; i<n; i++){
		cin >> s >> t;
		if(s>now_a && t>now_b){
			now_a=s, now_b=t;
		}
		else{
			now_a = s*max((now_a+s-1)/s, (t+now_b-1)/t);
			now_b = t*max((s+now_a-1)/s, (t+now_b-1)/t);
		}
	}


	cout << now_a+now_b << endl;

	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  
  case class Card(mark: String, number: Int){
    override def toString: String = f"$mark $number%n"
  }
  val n = StdIn.readLine().trim.toInt
  val ar1 = new Array[Card](n)
  val ar2 = new Array[Card](n)
  (0 until n).foreach{ i =>
    val Array(m, num) = StdIn.readLine().trim.split(' ')
    ar1(i) = Card(m, num.toInt)
    ar2(i) = Card(m, num.toInt)
  } 


  def quickSort(target: Array[Card], partIndex: Int, size: Int): Unit = {

    val last = target(size)

    @inline def swap(from: Int, to: Int): Unit = {
      //println(s"from: $from  to: $to")
      val temp = target(from)
      target(from) = target(to)
      target(to)   = temp
    }

    def partition(arr: Array[Card], p: Int, r: Int): Int = {
      var i = p - 1
      (p until r).foreach{ j =>
        if(arr(j).number <= last.number){
          i += 1
          swap(i, j)
          //println(a.toList.mkString(" "))
        }
      }
      swap(i+1, r)
      //println("last:" + a.toList.mkString(" "))
      i + 1
    }

    if(partIndex < size){
      val newIndex = partition(target, partIndex, size)
      quickSort(target, partIndex, newIndex - 1)
      quickSort(target, newIndex + 1, size)
    }
    
    
  }
  //println(s"num: $partitionIndex")

  final val infity = Int.MaxValue
  def mergeSort(): Unit = {
    var compareCount = 0

    @inline def copyToArray(start: Int, end: Int): Array[Card] = {
      val alsize = end - start + 1
      val ar = new Array[Card](alsize)
      Array.copy(ar2, start, ar, 0, alsize - 1)
      ar(alsize-1) = Card("", infity)
      ar
    }

    def merge(left: Int, mid: Int, right: Int): Unit ={
      //var al = a.slice(left, mid) ++ Array(infity)
      val al = copyToArray(left, mid)

      //var ar = a.slice(mid, right) ++ Array(infity)
      val ar = copyToArray(mid, right)
      var i = 0
      var j = 0
      //println("left:" + al.toList)
      //println("right:" + ar.toList)
      (left until right).foreach{ k =>
        compareCount += 1
        if(al(i).number <= ar(j).number){
          ar2(k) = al(i)
          i += 1
        } else {
          ar2(k) = ar(j)
          j += 1
        }
      }
      //println("all:" + ar2.toList.mkString(" "))
    }

    def innerMergeSort(left: Int, right: Int): Unit ={
      if(left+1 < right){
        val mid = (left + right) / 2
        innerMergeSort(left, mid)
        innerMergeSort(mid, right)
        merge(left, mid, right)
      }
    }

    innerMergeSort(0, ar2.length)

  }



  quickSort(ar1, 0, n - 1)
  mergeSort()
  
  var k = 0
  var same = true
  val sb = new StringBuilder
  while(k < n) {
    if(ar1(k) != ar2(k)) same = false 
    sb ++= ar1(k).toString
    k += 1
  }
  
  println(if(same) "Stable" else "Not stable")
  print(sb.toString())
  //print(ar1.mkString(""))

}


Measured memory_bytes: 321100
#include <iostream>

using namespace std;

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

    if (n == 1) {
        cout << "1" << endl;
    } else {
        long long int L0 = 2LL, L1 = 1LL, ans = 0LL;
        for (int i = 2; i <= n; i++) {
            ans = L0 + L1;
            L0 = L1;
            L1 = ans;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; } //charを整数に

int main()
{
    ll N,A,B;
    cin >> N >> A >> B;
    if(A>B){
        cout << 0 << endl;
    }
    else if(N==1){
        if(A==B){
            cout << 1 << endl;
        }    
        else{
            cout << 0 << endl;
        }
    }
    else{
        if(A>B){
            cout << 0 << endl;
        }
        if(A==B){
            cout << 1 << endl; 
        }
        else{
            cout << (B-A)*(N-2)+1 << endl;
        }
    }
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 100

int main() {
	static char s[N + 1];
	int n, i, x, max;

	scanf("%d%s", &n, s);
	max = x = 0;
	for (i = 0; i < n; i++)
		if (max < (x = s[i] == 'I' ? x + 1 : x - 1))
			max = x;
	printf("%d\n", max);
	return 0;
}


Measured memory_bytes: 128
n = list(map(int, input().split()))
hoge = [1, 4, 7, 9]
foo = [1, 4, 7, 9]

res = True

for i in hoge:
    if i in n:
        foo.remove(i)
    else:
        res = False
        
if foo:
    res = False
    
if res:
    print("YES")
else:
    print("NO")

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

int N;
vector<int> d_list;

#if 0
bool cmp(const int& a, const int& b) {
  if (a < b) {
    return false;
  } else {
    return true;
  }
}
#endif

int main() {
  cin >> N;
  d_list.resize(N);
  for(int i=0;i<N;i++) cin >> d_list[i];

  sort(d_list.begin(), d_list.end(), greater<int>());

#define DEBUG_MSG_off
#ifdef DEBUG_MSG
  cerr << "debug d_list:\n";
  for(auto s: d_list) {
    cerr << s << "\n"; 
  }
#endif

  int pre = 101;
  int ans = 0;
  for(auto s: d_list) {
    if (pre > s) {
      ans++;
#ifdef DEBUG_MSG
      cerr << "condition pre > s :"
           << "pre=" << pre
           << ",s=" << s << "\n";
#endif
    } else {
#ifdef DEBUG_MSG
      cerr << "not condition pre > s :"
           << "pre=" << pre
           << ",s=" << s << "\n";
#endif
    }
    pre = s;
  }
  cout << ans << "\n";
#ifdef DEBUG_MSG
  // cout << N << "\n";
  for(auto s: d_list) cout << s << " "; 
#endif
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL) ; cout.tie(NULL);
#define MOD 1000000007

ll dp[1003][1003];

int main() 
{
    int h,w,i,j;
    char a[1003][1003];
    cin>>h>>w;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        	cin>>a[i][j];
    }

    dp[0][0]=1;
    
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        	{
        		if(a[i][j]=='.')
        		{
        			if(i+1<h&&a[i+1][j]=='.'){
        				dp[i+1][j]+=dp[i][j];
        				dp[i+1][j]%=MOD;
        			}

        			if(j+1<w&&a[i][j+1]=='.'){
        				dp[i][j+1]+=dp[i][j];
        				dp[i][j+1]%=MOD;
        			}
        		}
        	}
    }
    cout<<dp[h-1][w-1]%MOD<<"\n";
 	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#define rep(i,n) for(int i=0;i<(n);i++)
#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define maxn 5005
#define mod 998244353
using namespace std;



int main(){
int n, x=0,y=0;
cin>>n;
vi A(n);
vi B(n);

rep(i,n)cin>>A.at(i)>>B.at(i);
sort(A.begin(),A.end());
sort(B.begin(),B.end());

if(n%2==0){
    x=(A.at((n-1)/2)+A.at(((n-1)/2)+1));
    y=(B.at((n-1)/2)+B.at(((n-1)/2)+1));
    cout<<(y-x)+1<<endl;
}else{
    x=A.at(((n-1)+1)/2);
    y=B.at(((n-1)+1)/2);
    cout<<(y-x)+1<<endl;
   
}

}

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

stack<int> s;

int st(string str) {
    int b = s.top(); s.pop();
    int a = s.top(); s.pop();
    if(str == "+") return a + b;
    else if(str == "-") return a - b;
    else if(str == "*") return a * b;
}
int main() {
    string t;
    while(cin >> t) {
        if(t == "+" || t == "-" || t == "*") s.push(st(t));
        else s.push(atoi(t.c_str()));
        if(getchar() == '\n') {
            cout << s.top() << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3156
import java.util.Scanner;

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

        int a = scanner.nextInt();
        String s = scanner.next();

        if (a < 3200) {
            s = "red";
        }

        System.out.println(s);
    }
}


Measured memory_bytes: 35556
#include<iostream>
using namespace std;
typedef long long int ll;
int main(){
ll A, V;
cin >> A >> V;
ll B,W;
cin >> B >> W;
ll T;
cin >> T;
ll D=abs(A-B);
 ll D2=(V-W)*T;
 puts(D<=D2?"YES":"NO");
 }

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int powint(int a, int x){
	int res = 1;
	REP(i,x){
		res = res *a; 
	}
	return res;
}

using namespace std;

int main(){
	int N,Y;
	cin>>N>>Y;
	int x = -1;
	int y = -1;
	int z = -1;
	REP(i,N+1){
		REP(j,N+1-i){
			int k = N-i-j;
			if( Y == i*10000 + j*5000 + k*1000){
				x=i;
				y=j;
				z=k;
			}
		}
	}
	cout<<x<<" "<<y<<" "<<z<<endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, M;
        public string S, T;
        public long MOD = 1000000007;

        public void Run()
        {
            var line = Input.ReadIntArray();
            N = line[0];
            M = line[1];
            S = Console.ReadLine();
            T = Console.ReadLine();

            int gcd = GCD(N, M);

            for (int g = 0; g < gcd; g++)
            {
                if (S[N / gcd * g] != T[M / gcd * g])
                {
                    Console.WriteLine(-1);
                    return;
                }
           }
           
           // 2パターンがおかしい
           Console.WriteLine(LCM(N, M));

        }

        public static int GCD(int a, int b)
        {
            return b == 0 ? a : GCD(b, a % b);
        }

        public static long LCM(int a, int b)
        {
            return (long)a / (long)GCD(a, b) * (long)b;
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, m;
  cin >> n >> m;
  int a = 1900; int b = 100;
  int ans = (n-m) * b;
  ans += m * a;
  ans *= pow(2,m);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
long long a[200005],qzh[200005],ans;
int main()
{
	scanf("%d",&n);for(int i=1;i<=n;++i) {scanf("%lld",&a[i]);qzh[i]=qzh[i-1]+a[i];}
	sort(qzh,qzh+1+n);
	long long cnt=1;
	for(int i=1;i<=n;++i) {
		if(qzh[i]!=qzh[i-1]) {
			ans+=cnt*(cnt-1)/2;
			cnt=1;
		}
		else ++cnt;
	}
	ans+=cnt*(cnt-1)/2;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int main() {
	string O, E;
	cin >> O >> E;
	for (int i = 0; i < O.size(); i++) {
		cout << O[i];
		if (i < E.size()) cout << E[i];
	}
	if (O.size() < E.size()) cout << E.back();
	cout << endl;
}

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

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long


	
void solve(){
	int n;
	cin >> n;
	int a[n];
	int mp[1000005] = {};
	for(int i = 0 ; i < n ; i++){
		cin >> a[i];
		mp[a[i]]++;		
	}
	int ans = 0;	
	for(int i = 0 ; i < n ; i++){
		mp[a[i]]--;
		bool flag = true;
		for(int j = 1 ; j * j <= a[i] ; j++){
			if(a[i] % j == 0){
				if(mp[j] || mp[a[i]/ j]){
					flag = false;
					break;
				}
			}
		}
		ans += flag;
		mp[a[i]]++;	
	}
	cout << ans ;
}

signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n;i++)
const int INF = 1 << 30;
bool t[100][100];
string name[100];
int score[100];

int main(){
  int n, m, d;
  while(cin >> n &&n){
    rep(i,100) {
      score[i] = 0;
      rep(j,100) t[i][j] = false;
    }
    rep(i,n){
      cin >> name[i];
      cin >> m;
      rep(j,m){
	cin >> d;
	t[i][d] = true;
      }
    }
    rep(i,n){
      rep(j, 30){
	if(t[i][j]){
	  int s = n;
	  rep(k, n){
	    if(k ==i) continue;
	    if(t[k][j]) s--;
	  }
	  score[i]+=s;
	}
      }
    }
    string res;
    int s = INF;
    rep(i,n){
      
      if(score[i] < s || score[i] == s && res > name[i]){
	res = name[i];
	s = score[i];
      }
    }
    cout << s << " " << res << endl;
  }
  return 0;
}

Measured memory_bytes: 0
H, W = map(int, input().split())

x = int(H/2)  #3
y = H%2  #1

z = int(W*x)  # 3

num = z + int((W+1)/2)*y   #

"""""""""
print('x: ' + str(x))
print('y: ' + str(y))
print('z: ' + str(z))
print('num: ' + str(num))

print()

#print(H)
#print(W)
"""""
if H == 1 or W == 1:
    print(1)
else:
    print(int(num))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> A(M);
    cin >> A;
    ll ans = N - accumulate(A.begin(), A.end(), 0LL);
    cout << (ans < 0 ? -1 : ans) << endl;
}

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

int N;
vector<int> A(210);


int main() {
  cin >> N;
  for (int i = 0; i < N; ++i ){

  cin >> A.at(i);
  }
  int res = 0;
  
  while (true){
    bool existodd = false;
    for (int i = 0; i < N; ++i ){
    if (A.at(i) %2 != 0) existodd = true;
    }
    
    if (existodd) break;
    
    for (int i = 0; i < N; ++i ){
     A.at(i) /= 2;
    }
    
    ++ res;
  }
  
  cout << res << endl;
}

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

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

const int N = 3e5 + 10;

map <pii , int> m;
vector <int> adj[N];
ll maxi = 0;

void dfs(int v, int p = -1, int c = -1) {
	int cnt = 0;
	for (auto u : adj[v]) {
		if(u == p)	continue;
		if(cnt == c)
			cnt++;
		m[{v, u}] = cnt;
		m[{u, v}] = cnt;
		dfs(u, v, cnt);
		cnt++;
		maxi = max(maxi, cnt * 1LL);
	}
}

int main() {
	int n;
	cin >> n;
	vector <pii> edge;
	for (int i = 0; i < n - 1; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;
		adj[v].push_back(u), adj[u].push_back(v);	
		edge.push_back({u, v});
	}
	dfs(0);
	cout << maxi << "\n";
	for (auto e : edge) {
		cout << m[{e.first, e.second}] + 1 << "\n";
	}
}

Measured memory_bytes: 25208
import java.util.Scanner;

class Main {

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

		int cnt = 0;
		for (int i = 0; i < n; i++) {
			int h = sc.nextInt();
			if (h >= k)
				cnt++;
		}

		System.out.println(cnt);
		sc.close();
	}


}


Measured memory_bytes: 45280
#include<iostream>
#include<cstring>
#include<cstdio>
#define MN 2000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,eq=1,has=0,ans=1e9,L[MN+5],R[MN+5],LL[MN+5],RR[MN+5];
char A[MN+5],B[MN+5];
int main()
{
    scanf("%s%s",A+1,B+1);n=strlen(A+1);
    for(int i=1;i<=n;++i) eq&=(A[i]==B[i]),has|=(B[i]=='1');
    if(eq) return 0*puts("0");if(!has) return 0*puts("-1");
    for(int i=1;i<=n;++i)
    {
        for(int j=i;B[j]!='1';j=j%n+1) ++R[i];
        for(int j=i;B[j]!='1';j=(j+n-2)%n+1) ++L[i];
    }
    for(int i=0;i<=n;++i)
    {
        memset(LL,0,sizeof(LL));memset(RR,0,sizeof(RR));
        int res=0;
        for(int j=1;j<=n;++j)
        {
            int k=(j+i-1)%n+1;
            if(A[j]!=B[k])
            {
                ++res;
                if(R[j]>i) LL[R[j]-1]=max(LL[R[j]-1],L[j]);
                if(L[j]>n-i) RR[L[j]-1]=max(RR[L[j]-1],R[j]);
            }
        }
        for(int j=n;j>=i;--j)
            LL[j]=max(LL[j],LL[j+1]),ans=min(ans,res+j+(j-i)+LL[j]*2);
        for(int j=n;j>=n-i;--j)
            RR[j]=max(RR[j],RR[j+1]),ans=min(ans,res+j+(j-(n-i))+RR[j]*2);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long LL;
LL i,j,k,n,m;
LL mod=1000000007;

int main() {
  string s,t;
  cin >> s>>t;
  map<string, int> mps,mpt;
  for(i=0;i< s.size();++i) {
    string subs = s.substr(i,1);
    string subt = t.substr(i,1);
    if(mps.find(subs)!= mps.end()){
      mps[subs] += 1;
    } else {
      mps[subs] = 1;
    }
    if(mpt.find(subt)!= mpt.end()){
      mpt[subt] += 1;
    } else {
      mpt[subt] = 1;
    }
  }
  vector<pair<string, int>> vs;
  for (auto const& ele: mps) vs.push_back(make_pair(ele.first,ele.second));
  sort(vs.begin(), vs.end(), [](const pair<string, int>& a,const pair<string, int>& b){return a.second < b.second;});

  vector<pair<string, int>> vt;
  for (auto const& ele: mpt) vt.push_back(make_pair(ele.first,ele.second));
  sort(vt.begin(), vt.end(), [](const pair<string, int>& a,const pair<string, int>& b){return a.second < b.second;});

  string out = "Yes";
  if (vs.size()!=vt.size()) {
    out = "No";
  } else {
    for (j=0;j<vs.size();++j) {
      if(vs[j].second!=vt[j].second) out = "No";
    }
  }
  cout << out << endl;

  return 0;
}


Measured memory_bytes: 776
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  std::string s; std::cin >> s;
  std::deque<char> c;
  for(int i=0; i<sz(s); i++) {
    if ( s[i] == '0' ) c.push_back('0');
    if ( s[i] == '1' ) c.push_back('1');
    if ( s[i] == 'B' && !c.empty() ) c.pop_back();
  }

  for(auto&& a : c) std::cout << a ;
  std::cout << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

double dp[3000][3000];
int n;
vector<double> v;

double f(int i,int head){
    if(i==n)return head==0;
    if(head<0)return 0;
    double &ans=dp[i][head];
    if(ans>-1)return ans;
    ans=0;
    ans+=v[i]*f(i+1,head-1);
    ans+=(1-v[i])*f(i+1,head);
    return ans;
}

signed main(){
    FASTER;
    for(int i=0;i<3000;i++)for(int j=0;j<3000;j++)dp[i][j]=-1000.0;
    cin>>n;
    v=vector<double>(n);cin>>v;
    double ans=0;
    for(int i=((n+1)/2);i<=n;i++)ans+=f(0,i);
    cout<<fixed<<setprecision(10)<<ans;
}


Measured memory_bytes: 141184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main() {
	string s,a;
	int m, h;
	while (cin >> s,s!="-") {
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> h;
			a = s.substr(h);
			s.erase(h);
			s = a + s;
		}
		cout << s << endl;
	}
	return 0;
}



Measured memory_bytes: 3208
package main

import (
  "fmt"
)

func maxInt(a ...int) int {m := a[0]; for _, x := range a {if x > m {m = x}}; return m}
func minInt(a ...int) int {m := a[0]; for _, x := range a {if x < m {m = x}}; return m}

func main() {
  var s string 
  fmt.Scan(&s)
  var res []rune
  for _, c := range s {
    if c == 'B' {
      res = res[:maxInt(0, len(res) - 1)]
    } else {
      res = append(res, c)
    }
  }
  fmt.Println(string(res))
}

Measured memory_bytes: 512
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n;
vector<ll> a;
ll dp[401][401];
ll dfs(int l,int r){
    if(dp[l][r]!=-1) return dp[l][r];
    ll res=100000000000000;
    for(int i=l+1;i<r;i++){
        res=min(res,dfs(l,i)+dfs(i,r)+a[r]-a[l]);
    }
    dp[l][r]=res;
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    memset(dp,-1,sizeof dp);
    ll sum=0;
    a.push_back(0);
    for (int i = 0; i < n; i++)
    {
        ll temp;
        cin >>temp;
        sum+=temp;
        a.push_back(sum);
        dp[i][i+1]=0;
    }
    cout << dfs(0,n)<< "\n";
    /*
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<"\n";
    }
    */
}



Measured memory_bytes: 2044
import math

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
#pairwise coprime どの2つをとっても共通素因数がない
#setwise coprime すべてに共通する素因数が存在しない
#左から見ていって、素因数の個数をカウントしていく…？
#setwise はエラトステネスの篩を再帰的に行う
#pairwise はそもそも、maxまでの素数の個数までしか存在し得ない
N = int(input())
A_old = [int(hoge) for hoge in input().split()]
A = [a for a in A_old if a != 1]
Pairwise = False
Setwise = False
SOSUU = [0 for _ in range(10**6+10)]
A.sort()
Fail = False
G = A_old[0]
for a in A_old:
    G = math.gcd(G,a)
if G != 1:
    print("not coprime")
    exit()

if len(A) <= 80000:
    for a in A:
        Fact = factorization(a)
        for f in Fact:
            if f[0]==1:continue
            if SOSUU[f[0]] > 0:
                Fail = True
                break
            else:
                SOSUU[f[0]] += 1
        if Fail:
            break
    if not Fail:
        Pairwise = True

if Pairwise:
    print("pairwise coprime")
else:
    print("setwise coprime")


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

int main() {
  int a, b, n, c;
  int ans = 0;
  cin >> a >> b;
  
  n = b - a + 1;

  rep(i,n){
    int c1,c2,c3,c4,c5 = 0;
    c = a;
    c1 = c / 10000;
    c2 = (c - c1*10000) / 1000;
    c3 = (c - c1*10000 - c2*1000) / 100;
    c4 = (c - c1*10000 - c2*1000 - c3*100) / 10;
    c5 = (c - c1*10000 - c2*1000 - c3*100 - c4*10);
    if(c1 == c5 && c2 == c4){
      ans++;
    }
	a++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3552
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <climits>
#include <iomanip>
using namespace std;
#define MAXSIZE 100005
#define MAXL 100
typedef long long int lli;

int main(){
    int a, p;
    cin >> a >> p;

    int p_sum = 3 * a + p;
    int ans = p_sum / 2;

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

Measured memory_bytes: 256