akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < (int)(n); i++)
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;

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

    vector<P> vec;
    int a, b;
    rep(i, N) {
        cin >> a >> b;
        vec.push_back(make_pair(b, a));
    }

    sort(vec.begin(), vec.end());

    ll time = 0;
    string ans = "Yes";
    rep(i, N) {
        time += vec[i].second;
        if (time > vec[i].first) ans = "No";
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2420
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <limits>
#include <numeric>

#define el '\n'
typedef long long ll;

using namespace std;



class DSU{
	public:
	 vector<int> siz, par;


	 DSU(int n){
	 	this -> siz.resize(n, 1);
	 	this -> par.resize(n);
	 	for (int i = 0; i < n; i++){
	 		this -> par[i] = i;
	 	}
	 }


	 void _union(int a, int b){
	 	int pa = this -> _get(a),
	 		pb = this -> _get(b);
 		if (pa == pb) return ;
 		if (siz[pa] > siz[pb]){
 			siz[pa] += siz[pb];
 			par[pb] = pa;
 		} else {
 			siz[pb] += siz[pa];
 			par[pa] = pb;
 		}

	 }

	 int _get(int ell){
	 
	 	return this -> par[ell] = (this -> par[ell] == ell ? ell : this -> _get(this -> par[ell])); 
	 }


	 bool _chech(int a, int b){
	 	return this -> _get(a) == this -> _get(b);
	 }
};


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,m;
	cin >>n>>m;
	bool a;
	int u,v;
	DSU *ds = new DSU(n);
	for(int i = 0; i < m; i++){
		cin >>a>>u>>v;
		if (!a){
			ds -> _union(u,v);
		} else {
			if (ds -> _chech(u,v)) {
				cout << 1 << el;
			} else {
				cout << 0 << el;
			}
		}
	}
}

Measured memory_bytes: 4484
#include<stdio.h>

int main(){
    int a,b,c;
    int i=0;
    int n=0;
    scanf("%d %d %d",&a,&b,&c);
    for(i=a;i<=b;i++){
        if(c%i==0){
            n++;
        }
    }
    printf("%d\n",n);
    return 0;
}

Measured memory_bytes: 1848
#include<iostream>
#include <bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
    int n;
    cin >> n;
    if (n == 1)
    {
        cout << 1;
        return 0;
    }

    vector<char> d(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> d[i];
    }
    int ans = 0;
    for (int i = 0; i < n-1; ++i)
    {
        if (d[i] == d[i+1])
        {
            /* code */
        } else {
            ans++;
        }
    }
    ans++;

    cout << ans << endl;

    return 0;

}

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

using ll = long long;
#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 REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(n, vector<int>());
    int s, t;
    REP(i, m) {
        cin >> s >> t;
        g[s].push_back(t);
    }

    vector<double> dp(n + 1);
    double ans = LINF;
    REP(b, n - 1) {
        dp[n] = 0.0;
        FORR(i, n - 1, 1) {
            double sum = 0.0;
            double mx = 0.0;
            int r = sz(g[i]);
            for (auto x : g[i]) {
                sum += dp[x];
                chmax(mx, dp[x]);
            }
            if (r > 1 && b == i) {
                sum -= mx;
                r--;
            }
            dp[i] = sum / r + 1;
        }
        chmin(ans, dp[1]);
    }
    cout << ans << EOL;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
long long f1(long long X1,long long C1,long long D1){
  long long G1=GCD(C1,D1);
  long long L1=C1*D1/G1;
  return X1-X1/C1-X1/D1+X1/L1;
}
int main(){
  long long A,B,C,D;cin>>A>>B>>C>>D;
  cout<<f1(B,C,D)-f1(A-1,C,D)<<endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void swap(int &x, int&y) {
    if (x > y) {
        int z;
        z = x;
        x = y;
        y = z;
    }
}
int main() {
    while(1){
        int x,y;
        cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        }
        else {
            swap(x,y);
            cout << x << ' ' << y << endl;
        }
    }
}


Measured memory_bytes: 3076
n = int(input())

l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[n-1])




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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int a, b;
  cin >> a >> b;
  cout << (a - 1) * (b - 1);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3600
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(void) {
    int N;
    cin >> N;
    set<char> se;
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        se.insert(c);
    }

    if ((int) se.size() == 3) {
        cout << "Three" << endl;
    } else if ((int) se.size() == 4) {
        cout << "Four" << endl;
    } else {
        printf("illegal size: %d\n", (int) se.size());
        return 1;
    }

    return 0;
}


Measured memory_bytes: 3616
import copy

s = input()
s_sub = copy.deepcopy(s)
# # 
# tar1 = "01"
# tar2 = "10"
# tar3 = ["1010","1001","0101","0110","1100","0011",""]
# 
# while((tar1 in s )or(tar2 in s)):
# 
# 
#     # for i in range(4):
#     #     if tar3[i] in s:
#     #         s = s.replace(tar3[i],"")
# 
# 
#     if tar1 in s:
#         s = s.replace(tar1,"",1)
#     if tar2 in s:
#         s = s.replace(tar2,"",1)
# 
# 
# 
# print(len(s_sub)-len(s))

#0と1の数数えて差分が残るのでは？
l1 = s.count("0")
l2 = s.count("1")
l3 = abs(l1-l2)

print(len(s_sub)-l3)



Measured memory_bytes: 3828
#pragma region header
#include <bits/stdc++.h>
using namespace std;

#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_CAT_I(x,y) x ## y
//#define CPP_STR(x) CPP_STR_I(x)
//#define CPP_STR_I(args...) #args
//#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
//using f80 = __float80;

constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
constexpr char EL[] = "\n";

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end());
#define REPIT(x) for(auto it=(x).begin(), end=(x).end(); it!=end; ++it)
#define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<typename T = i64>
T IN() { T x; cin >> x; return (x); }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }
template<typename T, size_t N>
i64 SIZE(const T(&)[N]) { return static_cast<i64>(N); }

template<typename T, typename U, typename Comp = less<>>
bool chmax(T& xmax, const U& x, Comp comp = {}) {
	if (comp(xmax, x)) {
		xmax = x;
		return true;
	}
	return false;
}
template<typename T, typename U, typename Comp = less<>>
bool chmin(T& xmin, const U& x, Comp comp = {}) {
	if (comp(x, xmin)) {
		xmin = x;
		return true;
	}
	return false;
}

void print() {
  cout << EL;
}
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
	cout << a;
	if (&a != &vec.back()) cout << " ";
  }
  cout << EL;
}
template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
	print(vec);
  }
}

struct ProconInit {
	static constexpr int IOS_PREC = 15;
	static constexpr bool AUTOFLUSH = false;

	ProconInit() {
		cin.tie(nullptr);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(IOS_PREC);
		if (AUTOFLUSH)
			cout << unitbuf;
	}
} PROCON_INIT;
#pragma endregion

signed solve()
{
	string s;
	cin >> s;
	string ans = "";
	REP(i, SIZE(s))
	{
		if (s[i] == 'B')
		{
			if (SIZE(ans) > 0)
			{
				ans = ans.substr(0, SIZE(ans) - 1);
			}
		}
		else
		{
			ans += s[i];
		}
	}
	print(ans);
	return 0;
}

#ifndef LOCALCODE
signed main()
{
	return solve();
}
#endif


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[]a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(a);
		int t1 = 0;
		int t2 = 0;
		int turn = 1;
		for(int i = N - 1; i >= 0; i--) {
			if(turn == 1) {
				t1 += a[i];
			}else {
				t2 += a[i];
			}
			turn *= -1;
		}
		int ans = t1 - t2;
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const int INF = 1e9+7;

int n, m;
struct lendata {
    int next; int dist;
};

int main() {
    cin >> n >> m;
    vector<int> lvec(m, 0);
    vector<int> rvec(m, 0);
    vector<int> dvec(m, 0);
    vector< vector<lendata> > graph(n, vector<lendata>());
    vector<int> xvec(n, INF);
    for(int i = 0; i < m; ++i) {
        int l, r, d; cin >> l >> r >> d;
        l--; r--;
        lvec.at(i) = l; rvec.at(i) = r; dvec.at(i) = d;
        lendata nd; nd.next = r; nd.dist = d;
        graph.at(l).emplace_back(nd);
        nd.next = l; nd.dist = -d;
        graph.at(r).emplace_back(nd);
    }

    for(int i = 0; i < n; ++i) {
        if(xvec.at(i) == INF) {
            queue<lendata> que;
            lendata first; first.next = i; first.dist = 0;
            xvec.at(i) = 0;
            que.push(first);
            while(!que.empty()) {
                lendata now = que.front();
                que.pop();
                int glen = graph.at(now.next).size();
                for(int j = 0; j < glen; ++j) {
                    int nx = graph.at(now.next).at(j).next;
                    if(xvec.at(nx) == INF) {
                        xvec.at(nx) = now.dist + graph.at(now.next).at(j).dist;
                        lendata nxxx;
                        nxxx.next = nx; nxxx.dist = xvec.at(nx);
                        que.push(nxxx);
                    }
                }
            }
        }
    }

    for(int i = 0; i < m; ++i) {
        if(xvec.at(rvec.at(i)) - xvec.at(lvec.at(i)) != dvec.at(i)) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

#define SZ(x) (int)((x).size())
#define xx first
#define yy second
#define pii pair<int, int>



void solve() {
    string s;
    cin >> s;
    int sm = 0;
    for (int i = 0; i < SZ(s); i++)
        sm = (sm + (s[i] - '0')) % 9;
    cout << (sm ? "No" : "Yes") << '\n';
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    // int _; cin >> _; while (_--)
    solve();
    return 0;
}


Measured memory_bytes: 3752
n = int(input())
res = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0}

for i in range(n):
    s = input()
    res[s] = res[s] + 1

print("AC", "x", res["AC"])
print("WA", "x", res["WA"])
print("TLE", "x", res["TLE"])
print("RE", "x", res["RE"])


Measured memory_bytes: 69868
#include<stdio.h>
int mountain[10];

void input(){
    int i1;
    for(i1=0;i1<10;i1++){
        mountain[i1]=0;
        scanf("%d",&mountain[i1]);
    }
}

void hikaku(){
    int h1,h2,temp=0;
    for(h1=0;h1<10;h1++){
        for(h2=h1+1;h2<10;h2++){
            if(mountain[h1]<mountain[h2]){
                temp=mountain[h1];
                mountain[h1]=mountain[h2];
                mountain[h2]=temp;
            }
        }
    }
}
void output(){
    int o1;
    for(o1=0;o1<3;o1++){
        printf("%d\n",mountain[o1]);
    }
}
                            
int main(){
    input();
    hikaku();
    output();
return 0;
}    

Measured memory_bytes: 600
fun main(args: Array<String>) {
    var (N, K) = listOfLong()
    val MAX = 100000
    val C = LongArray(MAX + 1)
    for (n in 0 until N) {
        val (a, b) = pairIntLong()
        C[a] += b
    }
    for (a in C.indices) {
        if (K <= C[a]) return println(a)
        K -= C[a]
    }
}

fun pairIntLong() = listOfLong().let { Pair(it[0].toInt(), it[1]) }
fun tripleIntIntLong() = listOfLong().let { Triple(it[0].toInt(), it[1].toInt(), it[2]) }
fun tripleIntLongLong() = listOfLong().let { Triple(it[0].toInt(), it[1], it[2]) }
fun pairIntLong(offset: Pair<Int, Long> = Pair(0, 0L)) = listOfLong().let { Pair(it[0].toInt() + offset.first, it[1] + offset.second) }
fun tripleIntIntLong(offset: Triple<Int, Int, Long> = Triple(0, 0, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1].toInt() + offset.second, it[2] + offset.third) }
fun tripleIntLongLong(offset: Triple<Int, Long, Long> = Triple(0, 0L, 0L)) = listOfLong().let { Triple(it[0].toInt() + offset.first, it[1] + offset.second, it[2] + offset.third) }

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map(String::toInt)
fun listOfInt(vararg deltas: Int) = listOfString().map { Integer.parseInt(it) }.mapIndexed { index, int -> int + deltas[index % deltas.size] }
fun listOfLong() = listOfString().map(String::toLong)
fun listOfLong(offset: Long = 0L) = listOfString().map { it.toLong() + offset}


Measured memory_bytes: 56728
#include <iostream>

#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include <cstdlib>
#include <typeinfo>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;

void printAns(long long a) { cout << a << endl; }

void yesno(bool a) { if (a)cout << "Yes" << endl; else cout << "No" << endl; }

void YESNO(bool a) { if (a)cout << "YES" << endl; else cout << "NO" << endl; }

typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

//ll INF = 10000000;
//ll mod = 1000000007;//10^9+7

//using Graph = vector<vector<pair<int, int>>>;
//Graph G(100100);


//番号ズレ注意！！
int main() {
    string S;
    cin >> S;
    int ansBit;
    for (int bit = 0; bit < (1 << 3); bit++) {
        int sum = S[0] - '0';
        REP(i, 3) {
            if ((bit >> 2 - i) & 1) {
                sum += S[i + 1]-'0';
            } else {
                sum -= S[i + 1]-'0';
            }
        }
        if (sum == 7) {
            ansBit = bit;
            break;
        }
    }
    cout << S[0];
    REP(i, 3) {
        if ((ansBit >> 2 - i) & 1) {
            cout << "+" << S[i + 1];
        } else {
            cout << "-" << S[i + 1];
        }
    }
    cout << "=7" << endl;

}


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

bool doUseLeft(char ch) {
    return (('a' <= ch && ch <= 'g') || ('q' <= ch && ch <= 't') || ('v' <= ch && ch <= 'x') || ch == 'z');
}

int main() {
    while (true) {
        char word[33];
        cin >> word;
        if (word[0] == '#') {
            break;
        }
        int count = 0;
        bool isLeft = doUseLeft(word[0]);
        for (int i = 1; word[i] != '\0'; i++) {
            if ((isLeft && doUseLeft(word[i]) == false) || (isLeft == false && doUseLeft(word[i]))) {
                isLeft = !isLeft;
                count++;
            }
        }
        cout << count << endl;
    }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,d,x,y;
    cin>>a>>b>>c>>d;
    if(a>=b) x=b;
    else x=a;
    if(c>=d) y=d;
    else y=c;
    cout<<x+y<<endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import *
input()
s=list(accumulate(map(int,input().split())))
l,r,t=0,2,s[-1];a=t
for m in s[1:-2]:
    while abs(t-2*s[r]+m)>abs(t-2*s[r+1]+m):r+=1
    while abs(m-2*s[l])>abs(m-2*s[l+1]):l+=1
    x=sorted([s[l],m-s[l],s[r]-m,t-s[r]])
    a=min(a,x[3]-x[0])
print(a)

Measured memory_bytes: 25972
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

enum
{
    MALE = 'M',
    FEMALE = 'F',
    VACANT = 'V'
};


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

    int N;
    string input;
    cin >> N;

    int cmd = 0;
    char zero = VACANT;
    cout << cmd << "\n";
    cout.flush();
    cin >> input;
    zero = input[0];
    int left = 0, right = N;
    cmd = (left + right) / 2;
    while (input[0] != 'V')
    {
        cout << cmd << "\n";
        cout.flush();
        cin >> input;
        /* generate next query */
        if (input[0] == zero)
        {
            if (cmd & 1) // odd
            {
                right = cmd;
            }
            else // even
            {
                left = cmd + 1;
            }
        }
        else
        {
            if (cmd & 1) // odd
            {
                left = cmd + 1;
            }
            else // even
            {
                right = cmd;
            }
        }
        cmd = (left + right) / 2;
    }

    return 0;
}



Measured memory_bytes: 852
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i=0;i<n;i++)
		cin >> a[i];
	sort(a.begin(),a.end());
	int bef=-1;
	int cnt=0;
	vector<int> xx;
	for(int i=0;i<n;i++)
	{
		if(bef==a[i])cnt++;
		else
		{
			bef=a[i];
		}
	}

	cout << n-(cnt+1)/2*2 << endl;



}

Measured memory_bytes: 640
// inputに入力データ全体が入る
function Main(input) {
	var input = input.split("\n");
  	var length = input[0];
  	var mochi = input.slice(1);

  	var stack = []; // 重ねた餅
  
  	// 降順にソートする
  	function compareFunc(a, b){
      return b-a; // a<bだと間違うことがある。。。
    }
  	mochi.sort(compareFunc);
  
  	// 餅を重ねる
  	for(var i=0; i<length; i++){
      if(stack.length != 0){
      	if(stack.slice(-1)[0] != mochi[i]){
        	 stack.push(mochi[i]);
        }
      }else{
       	stack.push(mochi[i]); 
      }
    }

	//出力
  	console.log(stack.length);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			if(n == 0){
				break;
			}else if(n == 1){
				System.out.println(scan.nextInt() + " " + (scan.nextInt() + scan.nextInt()));
				continue;
			}
			int[][] p = new int[n][2];
			for(int i = 0;i < n;i++){
				p[i][0] = scan.nextInt();
				p[i][1] = scan.nextInt() + scan.nextInt();
			}
			int max = p[0][1];
			int tarI = 0;
			for(int i = 1;i < n;i++){
				if(max < p[i][1]){
					max = p[i][1];
					tarI = i;
				}
			}
			System.out.println(p[tarI][0] + " " + max);
		}
	}
}

Measured memory_bytes: 156288
n,k=map(int,input().split())
x=list(map(int,input().split()))

ans=float('inf')
for i in range(n-k+1):
    temp=x[i+k-1]-x[i]+min(abs(x[i]),abs(x[i+k-1]))
    if ans>temp:ans=temp
print(ans)

Measured memory_bytes: 14388
#include <iostream>
using namespace std;
int main(){
    int a,c;
    char b;
    while (cin >> a >> b >> c){
        switch (b){
            case '?' : goto last;
            case '+' : cout << a+c << endl; break;
            case '-' : cout << a-c << endl; break;
            case '*' : cout << a*c << endl; break;
            case '/' : cout << a/c << endl; break;
        }
    }
    last:
    return 0;
}

Measured memory_bytes: 1160
fn main() {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	let r: u16 = s.trim().parse().unwrap();
	println!("{}", match r {
		_ if r < 1200 => "ABC",
		_ if r < 2800 => "ARC",
		_ => "AGC",
	})
}


Measured memory_bytes: 4352
import sys
import math
import heapq
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
n=int(input())
s=list(input())
s=list(map(int,s))

ans=0
for i in range(10):
    for j in range(10):
        for k in range(10):
            if i in s:
                ci=s.index(i)
                if j in s[ci+1:]:
                    cj=s[ci+1:].index(j)
                    if k in s[ci+1:][cj+1:]:
                        ans+=1
print(ans)
                

Measured memory_bytes: 4408
#include <stdio.h>

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

    char s[10];
    scanf("%s", s);

    if (a < 3200) {
        printf("%s\n", "red");
        return 0;
    }

    printf("%s\n", s);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

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

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

  int ans = 0;
  int gcd_of_iandj;
  REP(i,1,K+1){
    REP(j,1,K+1){
      gcd_of_iandj = gcd(i, j);
      REP(k,1,K+1){
        ans += gcd(gcd_of_iandj, k);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n)cin>>v[i];
    
    static double dp[21][130011];
    rep(i,21)rep(j,130011)dp[i][j] = INF;
    dp[0][1] = 0;
    
    for(int i=1;i<=n;i++){
        for(int j=1;j<=130010;j++){
            for(int k=1;k<=sqrt(j);k++){
                if(j%k==0){
                    dp[i][j] = min( dp[i][j], max( dp[i-1][k], (double)abs(v[i-1]-j)/v[i-1] ) );
                    dp[i][j] = min( dp[i][j], max( dp[i-1][j/k], (double)abs(v[i-1]-j)/v[i-1] ) );
                }
            }
        }
    }
    double ans = INF;
    rep(i,130011){
        ans = min(ans,dp[n][i]);
    }
    printf("%.20lf\n",ans);
}

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

using namespace std;

int n, m;
vector<int> G[100005];
bool used[100005];
int dp[100005];
vector<int> topo;

void tpsort(int v)
{
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		if(!used[G[v][i]]) tpsort(G[v][i]);
	}
	topo.push_back(v);
}

int main(void)
{
	cin >> n >> m;
	int u, v;
	for(int i = 0; i < m; i++){
		cin >> u >> v;
		G[u].push_back(v);
	}
	
	for(int i = 1; i <= n; i++) if(!used[i]) tpsort(i);
	reverse(topo.begin(), topo.end());
	
	for(int i = 0; i < topo.size(); i++){
		int v = topo[i];
		for(int j = 0; j < G[v].size(); j++){
			dp[G[v][j]] = max(dp[G[v][j]], dp[v]+1);
		}
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 8056
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = 1e9 + 7;

int main() {
	ll ans[30] = {};
	ll p = 0;
	ll n; cin >> n;

	ll t = n;
	while (t) {
		if (t & 1) {
			t = (t - 1) / -2;
			ans[p++] = 1;
		}
		else {
			t = t / -2;
			ans[p++] = 0;
		}
	}
	if (p == 0)cout << 0 << endl;
	else {
		for (int i = p - 1; i >= 0; i--) {
			cout << ans[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

int main(void){
	int N;
	cin >> N;
	vector<int> p(N);
	for(int i = 0; i < N; i++) cin >> p[i];

	int num = 0;
	for(int i = 0; i < N; i++){
		if(i+1 != p[i]) num++;
	}

	cout << (num<=2 ? "YES" : "NO") << '\n';

	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int> >;
using vii = vector<pair<int, int> >;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

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

	int m = max({ a, b,c });
	
	int tmp = 3 * m - (a + b + c);
	if (tmp % 2 == 0) cout << tmp / 2 << endl;
	else {
		tmp = 3 * (m + 1) - (a + b + c);
		cout << tmp / 2 << endl;
	}
}

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

using namespace std;

const int ms = 1e5 + 17;
const int mod = 1e9 + 7;

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

    int n;
    cin >> n;

    //vector<int> v(n, 0);

    int maxim = -1e9 - 3, minim = 1e9 + 3;
    for(int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;

        maxim = max(maxim, x);
        minim = min(minim, x);
    }


    cout << maxim - minim << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define EB emplace_back
#define GREATER(T) T, VT<T> greater<T>
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int N, K;

const int MAX = 1e5 + 10;
long double per_2[MAX];

int main(void) {
    cin >> N >> K;
    long double ans = 0;

    per_2[0] = (1.0 / N);
    per_2[1] = (1.0 / N) * (1.0 / 2);
    FOR(i, 2, MAX) {
        per_2[i] = per_2[i - 1] / 2;
    }

    FOR(i, 1, N + 1) {
        int cnt = 0;
        int tmp_i = i;
        while (tmp_i < K) {
            tmp_i *= 2;
            cnt++;
        }
        ans += per_2[cnt];
    }

    cout << fixed << setprecision(20) << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, x, l[102];

void solve()
{
    cin >> n >> x;
    for (int i=0; i<n; i++) cin >> l[i];
    int ans[n+1]; ans[0] = 0;
    for (int i=1; i<=n; i++) {
        ans[i] = ans[i-1] + l[i-1];
    }
    int k=0;
    for (int i=0; i<=n; i++) {
        if (ans[i]<=x) k++;
    }nout(k);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> p(N);
  int S = 0, M = 0;
  for(int i = 0; i < N; i++){
    cin >> p[i];
    S += p[i];
  }
  
  sort(p.begin(),p.end());
  
  M = p[p.size()-1];  
  int ans = S - M/2;
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf INT_MAX
#define llinf LONG_LONG_MAX

string X,Y;
vector <char> c;
void lcs(long long int m,long long int n ) 
{ 
   long long int i, j,index; 
   long long int L[m+1][n+1];
    for (i=0; i<=m; i++) 
    { 
        for (j=0; j<=n; j++) 
        { 
            if (i == 0 || j == 0) 
               L[i][j] = 0; 
       
            else if (X[i-1] == Y[j-1])
            {
               L[i][j] = L[i-1][j-1] + 1;
            }
            else
            {
               L[i][j] = max(L[i-1][j], L[i][j-1]);
            }
        } 
    } 
    i = m, j = n; 
    while (i > 0 && j > 0) 
    { 
        if (X[i-1] == Y[j-1]) 
        { 
            c.push_back(X[i-1]); 
            i--; j--;       
        }
        else if (L[i-1][j] > L[i][j-1]) 
           i--; 
        else
           j--; 
    } 
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    long long int i,p,q;
    cin>>X;
    cin>>Y;
    p=X.length();
    q=Y.length();
    lcs(p,q);
    for(i=c.size()-1;i>=0;i--)
        cout<<c[i];
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll              long long
#define pb              push_back
#define ppb             pop_back
#define endl            '\n'
#define mii             map<ll,ll>
#define pii             pair<ll,ll>
#define vi              vector<ll>
#define vs              vector<string>
#define all(a)          (a).begin(),(a).end()
#define F               first
#define S               second
#define sz(x)           ((ll)x.size())
#define hell            (1000000007)
#define inf             ((ll)5e18 + 5)
#define PI              ((double)3.14159265358979323844)
#define DECIMAL(n)      cout << fixed << setprecision(n);
#define rep(i,a,b)      for (ll i=a;i<b;i++)
#define repr(i,a,b)     for (ll i=a-1;i>=b;i--)
#define bitcount(a)     (ll)__builtin_popcount(a)
#define lbnd            lower_bound
#define ubnd            upper_bound
#define mp              make_pair
#define ios             ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set     tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define trace(...)      __f(#__VA_ARGS__, __VA_ARGS__)

template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}

using namespace std;
using namespace __gnu_pbds;

/*----------------------Graph Moves----------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

//primes for hashing 937,991,1013,1409,1741

void solve() {
    string s;
    cin>>s;
    if (s[0]=='R' && s[1]=='R' && s[2]=='R'){
        cout<<3<<endl;
        return;
    }
    if ((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R')) {
        cout<<2<<endl;
        return;
    }
    if (!(s[0]!='R' && s[1]!='R' && s[2]!='R')) {
        cout<<1<<endl;
        return;
    }
    cout<<0<<endl;
}

signed main() {
    ios
    ll test=1;
    //cin>>test;
    while (test--) solve();
    return 0;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(){
  int n;
  cin >> n;
  int INF = 1e5 + 1;
  vector<int> dp(n+10, INF);
  dp[0] = 0;
  rep(i, n){
    int power = 1;
    while(i + power <= n){
      chmin(dp[i + power], dp[i] + 1);
      power *= 6;
    }
    power = 9;
    while(i + power <= n){
      chmin(dp[i + power], dp[i] + 1);
      power *= 9;
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e17)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll x[2005][3];
vector<int> connected[2005];
ll ans;
ll n, k, s;

ll g(int a, int b) {
    ll ret = 0;
    ll dx[3];
    for(int i = 0; i <= 2; i++) {
        dx[i] = - max(x[a][i], x[b][i]) + min(x[a][i], x[b][i]) + s;
    }
    for(int i = 0; i <= 2; i++) {
        for(int j = i + 1; j <= 2; j++) {
            ret += dx[i] * dx[j] * 2;
        }
    }
    return ret;
}

void f(int now, int par, int rest, int root, ll val) {
    val += 6 * s * s;
    if(rest == 1) {
        if(k != 2) {
            if(count(connected[now].begin(), connected[now].end(), root)) {
                val -= g(now, root);
            }
        }
        ans = min(ans, val);
        return;
    }
    for(int i = 0; i < connected[now].size(); i++) {
        int to = connected[now][i];
        if(to == par) continue;
        if(to == root) continue;
        f(to, now, rest - 1, root, val - g(now, to));
    }
    return;
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        ans = INF;
        cin >> n >> k >> s;
        if(n == 0) break;
        for(int i = 1; i <= n; i++) {
            cin >> x[i][0] >> x[i][1] >> x[i][2];
            connected[i].clear();
        }
        for(int i = 1; i <= n; i++) {
            for(int j = i + 1; j <= n; j++) {
                bool isconnected = true;
                for(int k = 0; k <= 2; k++) {
                    if(min(x[i][k], x[j][k]) + s < max(x[i][k], x[j][k])) isconnected = false;
                }
                if(isconnected) {
                    connected[i].push_back(j);
                    connected[j].push_back(i);
                }
            }
        }
        for(int i = 1; i <= n; i++) {
            f(i, -1, k, i, 0);
        }
        if(ans == INF) ans = -1;
        cout << ans << endl;
        /*
        for(int i = 1; i <= n; i++) {
            cerr << i << " is connected with ";
            for(int j = 0; j < connected[i].size(); j++) cerr << connected[i][j] << " ";
            cerr << endl;
        }
        */
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int MOD = 1000000009;
const long long INF = 1LL << 60;

int main() {
    int N, M;
    cin >> N >> M;
    Graph G(N, vector<int>());
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> dist(N, -1);
    vector<int> prev(N, -1);
    queue<int> que;
    que.push(0);
    dist[0] = 0;
    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for (auto nv : G[v]) {
            if (dist[nv] == -1) {
                dist[nv] = dist[v];
                prev[nv] = v;
                que.push(nv);
            }
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < N; ++i) cout << prev[i] + 1 << endl;
    return 0;
}

Measured memory_bytes: 10632
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int X, Y, A, B, C;
  cin>>X>>Y>>A>>B>>C;
  ll tmp;
  pqueue<pair<ll, int> > que;
  for(int i=0;i<A;++i) {
    cin>>tmp;
    que.push(mp(tmp, 0));
  }
  for(int i=0;i<B;++i) {
    cin>>tmp;
    que.push(mp(tmp, 1));
  }
  for(int i=0;i<C;++i) {
    cin>>tmp;
    que.push(mp(tmp, 2));
  }
  int anum=0, bnum=0;
  ll ans = 0;
  pair<ll, int> state;
  for(int i=0;i<X+Y;++i) {
    state = que.top();que.pop();
    if(state.se==0) {
      if(anum==X) {
        i--;
        continue;
      }
      ans += state.fi;
      anum++;
    }
    if(state.se==1) {
      if(bnum==Y) {
        i--;
        continue;
      }
      ans += state.fi;
      bnum++;
    }
    if(state.se==2) {
      ans += state.fi;
    }
  }
  cout<<ans<<endl;
}



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

int N;
int a[210];
 
int main() {
  cin>>N;
  for(int i=0;i<N;i++)
    cin>>a[i];
  int ans=0;
  
  while(true){
    bool exist_odd =false;
    for(int i=0;i<N;i++){
      if(a[i]%2 != 0)
        exist_odd = true;
    }
    
    if(exist_odd)break;
    
    for(int i=0;i<N;i++){
      a[i]/=2;
    }
    ans++;
  }
  cout<<ans<<endl;

  

}


Measured memory_bytes: 256
import copy
def BubbleSort(N, A):
    A = copy.deepcopy(A)
    for i in range(N-1):
        for j in range(N-1,i,-1):
            if int(A[j-1][1]) > int(A[j][1]):
                A[j-1], A[j] = A[j], A[j-1]
    return A

def SelectSort(N, A):
    A = copy.deepcopy(A)
    for i in range(N-1):
        minidx = i
        for j in range(i+1,N):
            if int(A[j][1]) < int(A[minidx][1]):
                minidx = j
        if minidx != i:
            A[i], A[minidx] = A[minidx], A[i]
    return A

def main():
    n = int(input());  L = input().split()
    B = BubbleSort(n, L)
    S = SelectSort(n, L)
    print(*B); print('Stable')
    print(*S); print('Not stable') if B != S else print('Stable')
main()


Measured memory_bytes: 6344
#include<bits/stdc++.h>
using namespace std;
#define T top()
#define E end()
#define PS push
#define Q queue
#define PP pop()
#define L0 (LL)0
#define V vector
#define ST stack
#define FI first
#define MAX 4e18
#define MIN -MAX
#define DQ deque
#define RE rend()
#define SZ size()
#define C clear()
#define B begin()
#define F front()
#define SE second
#define DL double
#define G getline
#define IN insert
#define endl "\n"
#define EM empty()
#define RB rbegin()
#define PSB push_back
#define PI acos(-1.00)
#define PPB pop_back()
#define PSF push_front
#define ub upper_bound
#define lb lower_bound
#define MD 1000000007
#define PPF pop_front()
#define LL long long int
#define PQ priority_queue
#define N cout<<"NO"<<endl
#define Y cout<<"YES"<<endl
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define UOSMOY v.C;w.C;ww.C;u.C;uu.C;uo.C;vo.C;vu.C;ab.C;bc.C;cc.C;uuu.C;a.C;b.C;c.C
V<LL>v;
V<LL>w,ab,bc;
set<LL>uo;
map<LL,LL>u,uc;
map<LL,LL>ww,cc;
LL ar[120005];
LL br[500005];
LL cr[500][500];
V<pair<LL,LL> >uu;
map<LL,V<LL> >uuu;
map<pair<LL,LL>,LL> vo;
map<pair<LL,LL>,LL> vu;
LL vv[20000001];
void veve(LL n)
{
    LL i,j;
    for(i=1; i<=n; i++)
    {
        if(i%2==1)
        {
            vv[i]=i;
        }
        else
        {
            vv[i]=2;
        }
    }
    for(i=3; i<=sqrt(n); i+=2)
    {
        if(vv[i]==i)
        {
            for(j=i*i; j<=n; j+=2*i)
            {
                if(vv[j]==j)
                {
                    vv[j]=i;
                }
            }
        }
    }
}
int main()
{
//  BRR;
//  file;
    FAST;
    char ch;
    string a,b,c,str;
    DL x,y,d,e,f,g,h;
    LL n,m,i,j,k,p,q,o,l,s,tt=1,t,z,aa,r=0;
//    cin>>tt;
    veve(10000000);
    while(tt--)
    {
        UOSMOY;
        cin>>n;
        k=0;
        for(i=1; i<=n; i++)
        {
            if(i==1)
            {
                k+=1;
                continue;
            }
            j=i;
            l=1;
            while(j!=1)
            {
                u[vv[j]]++;
                j/=vv[j];
            }
            for(auto it=u.B;it!=u.E;it++)
            {
                l*=(it->SE+1);
            }
            k+=(l*i);
            u.C;
//            cout<<k<<endl;
        }
        cout<<k<<endl;

    }
    return 0;

}


Measured memory_bytes: 81804
# -*- coding: utf-8 -*-
from sys import stdin
import math

n = int(stdin.readline().rstrip())
ans = -(math.pow(10, 9))
tmp_min_val = int(stdin.readline().rstrip())
for i in range(n - 1):
  val = int(stdin.readline().rstrip())
  diff = val - tmp_min_val
  if ans < diff:
    ans = diff
  if val < tmp_min_val:
    tmp_min_val = val
print(ans)



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

int main() {
  
  int p, q, r;
  cin >> p >> q >> r;
  
  if (p >= q && p >= r) {
    cout << q + r << endl;
  } else if (q >= p && q >= r) {
    cout << p + r << endl;
  } else {
    cout << p + q << endl;
  }
  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>

using namespace std;

int main(int argc, char* argv[]) {
  int n;
  cin >> n;

  vector<vector<int> > V(n);
  for (int i = 0; i < n; ++i) {
    int u, k;
    cin >> u >> k;
    V[u - 1].resize(k);
    for (int j = 0; j < k; ++j)
      cin >> V[u - 1][j];
  }

  int d[n];
  memset(d, -1, sizeof(int) * n);
  d[0] = 0;

  queue<int> q;
  q.push(0);

  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < V[cur].size(); ++i) {
      if (d[V[cur][i] - 1] == -1) {
        q.push(V[cur][i] - 1);
        d[V[cur][i] - 1] = d[cur] + 1;
      }
    }
  }

  for (int i = 0; i < n; ++i)
    cout << i + 1 << " " << d[i] << endl;

  return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
#define PP 1000000007
using namespace std;

int main(){
ll N, Ans = 0;cin >> N;
vector<ll> A(N);
vector<ll> B(N);

rep(i, 0, N){

  cin >> A[i];

  B[i] = A[i] - i - 1;

}

sort(ALL(B));

rep(i, 0, N/2){

  Ans += B[N - 1 - i] - B[i];

}

cout << Ans;

}

Measured memory_bytes: 6380