akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

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

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

    cout << 10 * c + b + a << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
using namespace std;

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

  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  cout << ((v.size() == 3)? "Three" : "Four") << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
typedef pair<int,int> P;
struct edge{int to, id;};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod 1000000007

using graph = vector<vector<ll>>;

int main(){
    string s;
    cin >> s;
    if(s == "RRR"){
        cout << 3 << endl;
    }
    else if(s == "RRS"){
        cout << 2 << endl;
    }
    else if(s == "SRR"){
        cout << 2 << endl;
    } 
    else if(s == "RSS"){
        cout << 1 << endl;
    }
    else if(s == "RSR"){
        cout << 1 << endl;
    }
    else if(s == "SSR"){
        cout << 1 << endl;
    }
    else if(s == "SSS"){
        cout << 0 << endl;
    }
    else if(s == "SRS"){
        cout << 1 << endl;
    }
}

Measured memory_bytes: 3616
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    readint;
    auto xs = readints;

    int min = xs.reduce!((a, b) => min(a, b));
    int max = xs.reduce!((a, b) => max(a, b));
    writeln(max - min);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<int>;
using A = array<int, 2>;
using P = pair<int, int>;
constexpr int MOD{1000000000 + 7};
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr array<int, 4> dx{1, 0, -1, 0}, dy{0, 1, 0, -1};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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;
}
constexpr int div_roundup(int a, int b)
{
    return (a + b - 1) / b;
}

// vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));

// *****************************************************************************

void solve()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    // 各単調増加部分列の最後の値たち
    multiset<int> c;
    c.insert(a[0]);
    for (int i = 1; i < n; i++)
    {
        // cからa[i]より小さくない最初の値を探す
        auto it = c.lower_bound(a[i]);
        // その値がcの最も小さい値なら，cのすべての値はa[i]より大きい
        // いまある部分列にa[i]を追加できない．部分列を新しく追加する
        if (it == c.begin())
        {
            c.insert(a[i]);
        }
        // その一つ前の部分列の最後にa[i]を追加する
        else
        {
            c.erase(--it);
            c.insert(a[i]);
        }
    }
    // lb(3) 2, 5
    //

    cout << c.size() << endl;
}

// *****************************************************************************

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(0);

    solve();
}


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

#define ll long long
#define ld long double
#define ft first
#define sd second
#define pb push_back
using namespace std;
const ll mod = 1e9+7;

ll power(ll a, ll b, ll m = mod) {
    ll x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}

const int N = 1e6+9;
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);    

    int n, m; cin >> n >> m;
    vector<vector<pair<int, ll>>> starting(n+1);
    for(int i = 1; i <= m; i++) {
        int l, r; ll c; cin >> l >> r >> c;
        starting[l].pb({r, c});
    }
    multiset<ll> ss;
    vector<vector<ll>> rem(n+1);
    vector<ll> d(n+1, 1e18);
    d[1] = 0;
    for(int i = 1; i <= n; i++) {
        if(i > 1 && !ss.empty()) {
            d[i] = *ss.begin();
        }
        for(ll j: rem[i]) {
            ss.erase(ss.find(j));
        }
        for(auto it: starting[i]) {
            int c = it.sd;
            rem[it.ft].pb(d[i]+c);
            ss.insert(d[i]+c);
        }
    }
    cout << (d[n] > 1e17 ? -1 : d[n]) << "\n";    
    
    


    return 0;
    
}


Measured memory_bytes: 11904
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::multiprecision;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define rep(I,N) for(auto I=0;I<(N);++I)
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef unsigned long long ull;
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<endl;}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<endl;}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<endl;}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<endl;}
inline                                              void out(double p){printf("%.10f\n",p);}
template<class T>inline                             void outs(T p){for_each(all(p),out<decltype(p[0])>);}
template<class T>inline T calc_gcd(T a,T b){if(b==0)return a;return calc_gcd(b,a%b);}
template<class T>inline T calc_lcm(T a,T b){return a*b/calc_gcd(a,b);}

inline void solve(void){
  long A,B;in(A,B);
  out(calc_lcm(A,B));
}
int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int n,m,in,out,result,i;

  scanf("%d %d",&n,&m);
  result=m;

  for(i = 0; i < n; i++){

    scanf("%d %d",&in,&out);

    m=m+in-out;

    if(result < m) result=m;
    if(m < 0){

      printf("0\n");
      return 0;
    }

  }

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

    return 0;

}

Measured memory_bytes: 596
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <stack>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

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

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

int main(void){
	int n;
	cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];

	vector<ll> po;
	vector<ll> ne;

	vector<pair<ll, ll>> ans;

	for (int i = 0; i < n; i++){
		if (a[i] < 0){
			ne.push_back(a[i]);
		}
		else {
			po.push_back(a[i]);
		}
	}

	sort(po.begin(), po.end());
	reverse(po.begin(), po.end());
	sort(ne.begin(), ne.end());

	if (ne.empty()){
		ne.push_back(po[po.size() - 1]);
		po.pop_back();
	}
	else if(po.empty()) {
		po.push_back(ne[ne.size() - 1]);
		ne.pop_back();
	}

	ll now = ne[0];

	for (int i = 0; i < po.size() - 1; i++){
		ans.push_back(make_pair(now, po[i]));
		now -= po[i];
	}

	ans.push_back(make_pair(po[po.size() - 1], now));
	now = po[po.size() - 1] - now;

	for (int i = 1; i < ne.size(); i++){
		ans.push_back(make_pair(now, ne[i]));
		now -= ne[i];
	}

	cout << now << endl;
	for (int i = 0; i < ans.size(); i++){
		cout << ans[i].first << " " << ans[i].second << endl;
	}
}



Measured memory_bytes: 5872
n = int(input())
A = [0] + sorted(list(map(int, input().split())), reverse=True)
res = A[1] + sum(A[2:(n//2)+1]) * 2
if n % 2 == 0:
    print(res)
else:
    res += A[n//2 + 1]
    print(res)

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

int main(void)
{
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int distanceX = tx-sx;
    int distanceY = ty-sy;
    cout << string(distanceY, 'U') << string(distanceX, 'R');
    cout << string(distanceY, 'D') << string(distanceX, 'L');
    cout << 'L' << string(distanceY+1, 'U') << string(distanceX+1, 'R') << 'D';
    cout << 'R' << string(distanceY+1, 'D') << string(distanceX+1, 'L') << 'U';

    cout << endl;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i=0; i<n; i++)
        cin >> d.at(i);

    sort(d.begin(), d.end());
    int pre = d.at(0);
    int cnt = 1;
    for(int i=1; i<n; i++){
        if(pre != d.at(i)){
            cnt++;
        }
        pre = d.at(i);
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	long long a[N + 1];
	int n;
	int x, y, z;
	long long p, q, r, s;
	long long mi, ma, ans;
	scanf("%d", &n);
	a[0] = 0;
	for (int i = 0; i < n; i++){
		scanf("%d", &p);
		a[i + 1] = a[i] + p;
	}

	x = 1;
	z = 3;
	ans = 10000000000000000;
	for (y = 2; y < n - 1; y++){
		for (; x < y - 1; x++){
			if (a[y] + a[0] < (2 * a[x]))break;
		}
		for (; z < n - 1; z++){
			if (a[y] + a[n] < (2 * a[z]))break;
		}

		if (1<x && (y + 1)<z){
			p = a[x - 1] - a[0];
			q = a[y] - a[x - 1];
			r = a[z - 1] - a[y];
			s = a[n] - a[z - 1];
			mi = min(min(p, q), min(r, s));
			ma = max(max(p, q), max(r, s));
			ans = min(ans, ma - mi);
		}
		if ((y + 1)<z){
			p = a[x] - a[0];
			q = a[y] - a[x];
			r = a[z - 1] - a[y];
			s = a[n] - a[z - 1];
			mi = min(min(p, q), min(r, s));
			ma = max(max(p, q), max(r, s));
			ans = min(ans, ma - mi);
		}
		if (1<x){
			p = a[x - 1] - a[0];
			q = a[y] - a[x - 1];
			r = a[z] - a[y];
			s = a[n] - a[z];
			mi = min(min(p, q), min(r, s));
			ma = max(max(p, q), max(r, s));
			ans = min(ans, ma - mi);
		}

		p = a[x] - a[0];
		q = a[y] - a[x];
		r = a[z] - a[y];
		s = a[n] - a[z];
		mi = min(min(p, q), min(r, s));
		ma = max(max(p, q), max(r, s));
		ans = min(ans, ma - mi);

	}

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

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x;i<=y;i++)
const int P=200003;
int pw[P],id[P];
const int N=524288;
const double pi=acos(-1.);
struct complex{
	double x,y;
	complex(double _x=0.,double _y=0.){x=_x,y=_y;}
	complex operator+(const complex&rhs){return complex(x+rhs.x,y+rhs.y);}
	complex operator-(const complex&rhs){return complex(x-rhs.x,y-rhs.y);}
	complex operator*(const complex&rhs){return complex(x*rhs.x-y*rhs.y,x*rhs.y+y*rhs.x);}
}A[N];
using ll=int64_t;
int rev[N];
ll result[N];
void dft(complex*f,int tp){
	for(int i=0;i<N;i++)if(i<rev[i])std::swap(f[i],f[rev[i]]);
	for(int len=1;len<N;len<<=1){
		complex wn(cos(pi/len),sin(pi/len)*tp);
		for(int i=0;i<N;i+=len<<1){
			complex w(1,0);rep(j,0,len-1){complex x=f[i+j],y=f[i+j+len]*w;f[i+j]=x+y;f[i+j+len]=x-y;w=w*wn;}
		}
	}
	if(tp==-1)for(int i=0;i<N;i++)result[i]=(ll)(f[i].x/N+.5);
}
int a[N];
int main(){
	pw[0]=1;
	rep(i,0,N-1)rev[i]=rev[i>>1]>>1|(i&1)<<18;
	rep(i,1,P-1)pw[i]=pw[i-1]*2%P;
	rep(i,0,P-1)id[pw[i]]=i;
	int n;
	scanf("%d",&n);
	rep(i,1,n){
		int x;
		scanf("%d",&x);
		if(x)A[id[x]].x++;
		a[i]=x;
	}
	dft(A,1);
	rep(i,0,N-1)A[i]=A[i]*A[i];
	dft(A,-1);
	rep(i,1,n)if(a[i])result[id[a[i]]*2]--;
	ll answer=0;
	rep(i,0,N-1)answer+=result[i]/2*pw[i%(P-1)];
	printf("%lld\n",answer);
	return 0;
}


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

sys.setrecursionlimit(10000)


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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(S):
    i = -1
    j = -1
    for k in range(len(S)-1):
        if S[k] == S[k+1]:
            i = k+1
            j = k+2
            break
        if k+2 < len(S) and S[k] == S[k+2]:
            i = k+1
            j = k+3
    return '%d %d' % (i, j)


def main():
    S = read_str().strip()

    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 5712
#include<bits/stdc++.h>
using std::vector;
using std::pair;
using lint = long long;

using pii = pair<lint, lint>;
long double PI = acos(-1);
struct indexed_tree {
	vector<lint> tree;
	int k = 1;
	indexed_tree(int n) {
		while (k < n)k *= 2;
		tree.resize(k * 2 + 10, 0);
	}
	void update(int idx, lint a) {
		idx += k;
		while (idx) {
			tree[idx] = std::max(tree[idx], a);
			idx /= 2;
		}
	}
	lint getRange(int left, int right) {
		left += k;
		right += k;
		lint ret = 0;
		while (left <= right) {
			if (left % 2 == 1)ret = std::max(ret, tree[left]);
			if (right % 2 == 0)ret = std::max(ret, tree[right]);
			left = (left + 1) / 2;
			right = (right - 1) / 2;
		}
		return ret;
	}
};
lint abss(int a) {
	if (a < 0)return -a;
	return a;
}
int main() {
	std::vector<lint> X, Y;
	lint x1, y1, x2, y2;
	scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
	X.push_back(x1);
	X.push_back(x2);
	Y.push_back(y1);
	Y.push_back(y2);
	int n;
	scanf("%d", &n);
	vector<pii> F;
	if (x1 > x2) {
		std::swap(x1, x2);
		std::swap(y1, y2);
	}
	F.push_back({ x1,y1 });
	for (int i = 0; i < n; i++) {
		lint x, y;
		scanf("%lld%lld", &x, &y);
		if (std::min(x1, x2) <= x && x <= std::max(x1, x2) &&
			std::min(y1, y2) <= y && y <= std::max(y1, y2)) {
			F.push_back({ x,y });
			Y.push_back(y);
		}
	}
	std::sort(F.begin() + 1, F.end());
	F.push_back({ x2,y2 });
	std::sort(Y.begin(), Y.end());
	Y.erase(std::unique(Y.begin(), Y.end()), Y.end());
	if (x1 == x2 || y1 == y2) {
		long double ans = (abss(x1 - x2) + abss(y1 - y2))*100.0;
		ans -= (20.0 - (10.0*PI))*(F.size() - 2);
		printf("%.15Lf", ans);
	}
	else {
		indexed_tree tree(Y.size());
		for (int i = 0; i < F.size(); i++) {
			int y = std::lower_bound(Y.begin(), Y.end(), F[i].second) - Y.begin();
			if (y1 < y2) {
				lint p = tree.getRange(0, y);
				tree.update(y, p + 1);
			}
			else {
				lint p = tree.getRange(y, Y.size()-1);
				tree.update(y, p + 1);
			}
		}
		
		lint p = 0;
		if (y1 < y2) {
			p = tree.getRange(Y.size() - 1, Y.size() - 1) - 2;
		}
		else {
			p = tree.getRange(0, 0) - 2;
		}
		
		long double ans = (abss(x1 - x2) + abss(y1 - y2))*100.0;
		int len = std::min(abss(x1 - x2), abss(y1 - y2))+1;
		if (len == p) {
			p--;
			ans -= (20.0 - (10.0*PI));
		}
		ans -= (20.0 - (5.0*PI) )*p;
		printf("%.15Lf", ans);
	}

}

Measured memory_bytes: 10080
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<limits.h>

int two(int a) {
    int x = a;
    int count = 0;
    int flag = 1;
    while(flag) {
        if(x % 2 == 0) {
            count++;
            x = x / 2;
        }
        else{
            flag = 0;
        }
    }
    return count;
}

int main(void){
    int max = 1;
    int count = 0;
    int N;
    scanf("%d", &N);
    int i;
    for(i=1; i<=N; i++) {
        if(count < two(i)) {
            count = two(i);
            max = i;
        }
        
    }
    printf("%d\n", max);
    return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    string S;
    in >> S;
    ll Q;
    in >> Q;
    string front{};
    string back{};
    bool reversed = false;
    REP(i, Q) {
        ll x;
        in >> x;
        if (x == 1) {
            reversed = !reversed;
        } else {
            ll F;
            char C;
            in >> F >> C;
            if ((F == 1 && !reversed) || (F == 2 && reversed)) {
                front.append(1, C);
            } else {
                back.append(1, C);
            }
        }
    }
    reverse(front.begin(), front.end());
    S.insert(S.begin(), front.begin(), front.end());
    S.append(back.begin(), back.end());
    if (reversed) {
        reverse(S.begin(), S.end());
    }
    ll ans = 0;

    // solution here

    out << S << endl;
    return 0;
}

int run2(istream& in, ostream& out) {
    ll N, M, R;
    in >> N >> M >> R;
    vector<ll> r{};
    REP(i, R) {
        ll x;
        in >> x;
        r.emplace_back(x);
    }
    vector<tuple<ll,ll,ll>> v{};
    REP(i, M) {
        ll a,b,c;
        in >> a >> b >> c;
        v.emplace_back(make_tuple(a,b,c));
    }

    ll ans = 0;

    // solution here

    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 1348
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a;
    cin >> a;
    ll mini = __LONG_LONG_MAX__;
    for (ll i = 1; i <= sqrt(a); i++)
    {
        if (a % i == 0)
        {
            ll x = i;
            ll y = a / i;
            mini = min(mini, abs(x - 1ll) + abs(y - 1ll));
        }
    }
    cout << mini << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
int main() {
    string s;
    cin >> s;
    int res = 0;
    int sa = 1000;
    rep(i, 0, s.size() - 2) {
        int tmp = 100 * (s[i] - '0') + 10 * (s[i + 1] - '0') + (s[i + 2] - '0');
        if(abs(tmp - 753) < sa) {
            res = tmp;
            sa = abs(tmp - 753);
        }
    }
    cout << sa << endl;

}

Measured memory_bytes: 256
// I look at my watch
// it say nine twenty-five
// And I think oh God
// I'm still alive
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) int((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(int i = int(a); i < int(b); ++i)
#define roF(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
 
typedef long long ll;
typedef pair<int,int> ii;
typedef long double ld;




int main(){	
	int R,G,a,b,c;cin>>R>>G>>a>>b>>c;
	vector<ii>app;
	For(i,0,a){
		int val;cin>>val;
		app.pb({val,0});
	}
	For(i,0,b){
		int val;cin>>val;
		app.pb({val,1});
	}
	For(i,0,c){
		int val;cin>>val;
		app.pb({val,2});
	}
	sort(app.rbegin(),app.rend());
	int r=0,g=0,w=0;
	ll ans=0;
	For(i,0,sz(app)){
		if(r==R&&app[i].ss==0)continue;
		if(g==G&&app[i].ss==1)continue;
		if(app[i].ss==0)r++;
		if(app[i].ss==1)g++;
		if(app[i].ss==2)w++;
		ans+=app[i].ff;
		if(r+g+w==R+G)break;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = n; i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int a,b,c,x,y;
	cin >>a>>b>>c>>x>>y;
	int upper = 2 * max(x, y);
	int ans = INF;
	for (int i = 0; i <= upper; i += 2) 
	{
		int now = i*c + max(x-i/2, 0)*a + max(y-i/2, 0)*b;
		
		ans = min(ans, now);
	}
	cout << ans << endl;
	return 0;
}

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

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

    vector<int> x(n);
    rep(i, n) cin >> x[i];

    long long minv = 1e+10;
    int point = 0;
    rep2(i, 1, 100) {

        int sum = 0;
        rep(j, n) {
            int tmp = x[j] - i;
            sum += pow(tmp, 2);
        }
        //cout << "sum = " << sum << endl;
        if (minv > sum) {
            minv = sum;
            point = i;
        }
    }
    cout << minv << endl;
    return 0;
}

Measured memory_bytes: 3596
n = int(input())
s = input()

back = 0
front = 0
for k in s:
    if k == '(':
        back += 1
    else:
        back -= 1
        while back < 0:
            front += 1
            back += 1
f = ""
for i in range(front):
    f = f + '('
b = ""
for i in range(back):
    b = b + ")"
s = f + s + b
#print(len(s))
print(s)


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


int main()
{    
    string a, b, c;
    cin >> a;
    cin >> b;
    cin >> c;
    // a = "abcb";
    // b = "aacb";
    // c = "bccc";
    
    string turn = "a";
    string winner;
    for(int i=0; i<310; ++i){
        if(turn == "a"){
            if(a.length() == 0){
                winner = "A";
                break;
            }
            turn = a.substr(0, 1);          
            a.erase(0, 1);
        }
        else if(turn == "b"){
            if(b.length() == 0){
                winner = "B";
                break;
            }
            turn = b.substr(0, 1);
            b.erase(0, 1);
        }
        else if(turn == "c"){
            if(c.length() == 0){
                winner = "C";
                break;
            }
            turn = c.substr(0, 1);
            c.erase(0, 1);
        }
    }
    cout << winner << endl;        
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, k;
	cin >> n >> k;
	vl v(n);
	REP(i, n)cin >> v[i];
	ll x = 0;
	RREP(i, 50) {
		int cnt0 = 0, cnt1 = 0;
		REP(j, n) {
			if ((1ll << i)&v[j])cnt1++;
			else cnt0++;
		}
		if (cnt0 > cnt1) {
			if ((x | (1ll << i)) <= k)x |= (1ll << i);
		}
	}
	ll ans = 0;
	REP(i, n) {
		ans += x ^ v[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
package main
 
import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
 
var sc = bufio.NewScanner(os.Stdin)
 
func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024*1024), bufio.MaxScanTokenSize)
}
 
func nextString() string {
	sc.Scan()
	return sc.Text()
}
 
func nextFloat() float64 {
	sc.Scan()
	f, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}
 
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
 
func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}
 
func min(a, b int) int {
	if a < b {
		return a
	} else {
		return b
	}
}
 
func main() {
	var N, K, D int64
	fmt.Scan(&N)
	fmt.Scan(&K)
	fmt.Scan(&D)
	N = abs(N)
	if K <= N/D {
		fmt.Println(N - K*D)
	} else if D > N {
		if K%2 == 0 {
			fmt.Println(N)
		} else {
			fmt.Println(D - N)
		}
	} else {
		num := N / D
		if (K-num)%2 == 0 {
			fmt.Println(N % D)
		} else {
			fmt.Println(D - (N % D))
		}
	}
}
 
func abs(n int64) int64 {
	if n < 0 {
		n = -n
	}
	return n
}

Measured memory_bytes: 1872
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
int a[2],b,c,d;
cin>>a[0]>>a[1]>>a[2];
if(a[0]>a[1]){
b=a[0];
a[0]=a[1];
a[1]=b;
}
if(a[1]>a[2]){
c=a[1];
a[1]=a[2];
a[2]=c;
}
if(a[0]>a[1]){
d=a[0];
a[0]=a[1];
a[1]=d;
}
if(a[0]<a[1]<a[2]){
cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
}
     return 0;
}

Measured memory_bytes: 1164
# AOJ 0034 Railway Lines
# Python3 2018.6.22 bal4u

while 1:
	try: a = list(map(int, input().split(',')))
	except: break
	pos = [0]*12
	v1, v2 = a[10], a[11]
	for i in range(10): pos[i+2] = pos[i+1] + a[i]
	L = pos[11]
	pq = (L*v1) // (v1 + v2);
	pr = (L*v1) % (v1 + v2);
	i = 10
	while pq < pos[i]: i -= 1
	if pq == pos[i] and pr == 0: i -= 1
	print(i)



Measured memory_bytes: 5596
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#ifdef PERVEEVM_LOCAL
    #define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
    #define debug(x) 238;
#endif

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define NAME "File"

using ll = long long;
using ld = long double;

#ifdef PERVEEVM_LOCAL
    std::mt19937 rnd(238);
#else
    std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 3100;

int dp[N][N];
char a[N], b[N];

void run() {
    scanf("%s\n%s", a, b);

    int n = strlen(a);
    int m = strlen(b);

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            dp[i][j] = std::max(dp[i - 1][j], dp[i][j - 1]);

            if (a[i - 1] == b[j - 1]) {
                dp[i][j] = std::max(dp[i][j], dp[i - 1][j - 1] + 1);
            }
        }
    }

    int i = n, j = m;
    std::string ans;
    while (i != 0 && j != 0) {
        if (a[i - 1] == b[j - 1] && dp[i][j] == dp[i - 1][j - 1] + 1) {
            ans.push_back(a[i - 1]);
            --i;
            --j;
        } else if (dp[i][j] == dp[i - 1][j]) {
            --i;
        } else {
            --j;
        }
    }

    std::reverse(ans.begin(), ans.end());
    printf("%s\n", ans.c_str());
}

int main(void) {
    // freopen(NAME".in", "r", stdin);
    // freopen(NAME".out", "w", stdout);

    auto start = std::chrono::high_resolution_clock::now();
    run();
    auto end = std::chrono::high_resolution_clock::now();

    #ifdef PERVEEVM_LOCAL
        std::cerr << "Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
                  << " ms" << std::endl;
    #endif

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  bool flag = false;
  for (int i = 0; 4 * i <= n; i++) {
    if ((n - 4 * i) % 7 == 0) {
      flag = true;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <unordered_map>
using namespace std;
using var = long long;
#define rep(i,n) for(var i=0, i##_len=(n); i<i##_len; ++i)
#define repin(a,n) vector<var> a(n);rep(i,n){cin>>a[i];}
#define in(a) var a;cin>>a;
#define out(a) cout<<a;

int main()
{
	in(n);
	unordered_map<string, var> ss(n);
	rep(i, n) {
		string a;
		string b = "00000000000000000000000000";
		cin >> a;
		rep(j, 10) {
			b[a[j] - 'a'] += 1;
		}
		ss[b] += 1;
	}

	var c = 0;
	for (auto s : ss) {
		var a = 0;
		for (var i = s.second - 1; i > 0; i--) {
			a += i;
		}
		c += a;
	}

	out(c);
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define Int ll
#define BORDER -1

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

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

  int sum=0;
  for(auto c:a)sum+=c;

  set<int>candidates;
  for(int i=1; i*i<=sum; i++){
    if(sum%i)continue;
    candidates.insert(i);
    candidates.insert(sum/i);
  }

  Int ans = 0;
  for(auto c:candidates){
    vector<Int>ca(n);
    rep(i, n)ca[i]=a[i]%c;

    sort(ca.begin(), ca.end());
    Int psum = 0, msum=0;
    rep(i, n)msum += ca[i];
    if(msum==psum)ans = max<Int>(ans, c);
//cout<<ans<<' '<<msum<<' '<<c<<endl;
if(c== BORDER)cout<<"---"<<endl;
    rrep(i, n){
      msum -= ca[i];
      psum += c-ca[i];
//cout<<psum<<' '<<msum<<endl;
      //if(psum!=msum)continue;
      Int opc = max<Int>(psum, msum);
if(c== BORDER && opc<=k)cout<<opc<<' '<<endl;
if(c== BORDER)cout<<psum<<' '<<msum<<endl;;
      if(opc<=k)ans = max<Int>(ans, c);

    }
if(c== BORDER)cout<<"---"<<endl;

  }

  cout << ans << endl;

  return 0;

  cout<<sum<<endl;
  cout<<candidates.size()<<endl;

  return 0;
}

Measured memory_bytes: 3636
n = gets.chomp.to_i
dd = gets.chomp.split(" ").map(&:to_i).sort
m = gets.chomp.to_i
tt = gets.chomp.split(" ").map(&:to_i).sort
i = 0
while true
  if tt.empty?
    puts "YES"
    exit
  end
  x = tt.shift
  while true
    if dd.empty?
      puts "NO"
      exit
    end
    y = dd.shift
    break if x == y
  end
end


Measured memory_bytes: 37200
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using System.Numerics;

class p
{

    static void Main(string[] args)
    {
        //解説みて実装した
        //変数の間違いに気づけず出力違いでだいぶ悩んだ。。。。
        //BItempはBigIntegerのなごり⇒上のバグがBigIntegerの原因かと思ってLongに書き換えた。
        long Xsum = 0;
        long Ysum = 0;
        long BItemp;

        string[] input = Console.ReadLine().Split();
        long N = long.Parse(input[0]);
        long M = long.Parse(input[1]);

        long Q = 1000000007;

        string[] inputX = Console.ReadLine().Split();

        for(long i = 0; i < N; i++)
        {
            BItemp = long.Parse(inputX[i]);
            Xsum += i * BItemp - (N - (i + 1)) * BItemp;
            Xsum %= Q;
        }

        string[] inputY = Console.ReadLine().Split();

        for (long i = 0; i < M; i++)
        {
            BItemp = long.Parse(inputY[i]);
            Ysum += i * BItemp - (M - (i + 1)) * BItemp;
            Ysum %= Q;
        }

        long ans = (Xsum * Ysum) % Q;
        Console.WriteLine(ans);
    }   
}

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

int main() {
  int n, k;
  cin>>n>>k;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  int mod[n];
  for (int i=0; i<n; i++) mod[i] = (a[i] - 1) % k;
  long acc[n+1];
  acc[0] = 0;
  for (int i=0; i<n; i++) {
    acc[i+1] = acc[i] + mod[i];
    acc[i+1] %= k;
  }
  map<long, vector<int>> m;
  for (int i=0; i<n+1; i++) {
    m[acc[i]].push_back(i);
  }
  long long ans = 0;
  for (auto e: m) {
    vector<int> v = e.second;
    for (int i=0; i<v.size(); i++) {
      auto it = upper_bound(v.begin(), v.end(), v[i] + k - 1);
      --it;
      ans += it - v.begin() - i;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 25216
require "prime"

class Problem
  M5 = 42
  M2 = 20
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n = gets.to_s.to_i
    @a = Array.new(n){ 
      x, y = gets.chomp.split(".")
      y ||= ""
      y = y.ljust(9,"0")
      (x + y).to_i
    }
  end

  def rec
    # dp[2の指数][5の指数] := 個数
    @dp = Array.new(M5){ Array.new(M2, 0) }
    a.each do |x|
      m2 = count_mod(x, 2)
      m5 = count_mod(x, 5)
      @dp[m2][m5] += 1
    end
  end

  def count_mod(x,n)
    ans = 0
    while x % n == 0
      x /= n
      ans += 1
    end
    ans
  end

  def solve
    rec
    ans = 0
    M5.times do |i|
      M2.times do |j|
        M5.times do |k|
          M2.times do |l|
            next if i + k < 18
            next if j + l < 18
            next if i * 20 + j < k * 20 + l

            if i == k && j == l
              ans += @dp[i][j] * (@dp[k][l] - 1) / 2
            else
              ans += @dp[i][j] * @dp[k][l]
            end
          end
        end
      end
    end
    ans
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 15848
from sys import setrecursionlimit
setrecursionlimit(10 ** 8)

n, k = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for j in range(n - 1)]
p = 10 ** 9 + 7

E = [[] for i in range(n + 1)]

for a, b in A:
    E[a].append(b)
    E[b].append(a)

visited = [False] * (n + 1)

def dfs(i, f, s):
    if visited[i]:
        return 1
    b = f + s
    visited[i] = True
    
    res = k - b
    s = f
    f = 1
    for v in E[i]:
        if visited[v]:
            continue
        res *= dfs(v, f, s)
        res %= p
        s += 1

    return res if res > 0 else 0

print(dfs(1, 0, 0) % p)

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

int main(){
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];

    int i=0;
    int b=1;
    for(i=0;i<n;i++){
        if(a[i]==b) b++;
    }

    if(b==1) cout<<-1<<endl;
    else cout<<(n-b+1)<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define mp 	    make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod        1000000007
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
ll power(ll a , ll b,ll modi)
{
    a%=modi;
    ll res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % modi ;
        }
        b/=2 ;
        a = (a*a) % modi ;
    }
    return res ;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t=1;
	//cin>>t;
	while(t--)
	{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
    {
        cout<<k;
        return 0;
    }
    else if(k<=b){
        cout<<a;
        return 0;
    }
    ll r=(k-a-b);
    cout<<a-r;
	}
return 0;
}


Measured memory_bytes: 3664
n = int(input())
s = list(input())

num_E = s.count("E")
num_W = 0
ans = float("inf")

for i in range(n):
    if s[i] == "W":
        ans=min(ans , num_E + num_W)
        num_W += 1
    else:
        num_E -= 1
        ans=min(ans , num_E + num_W)
    
print(ans)

Measured memory_bytes: 5924
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
int res = 0;

template <typename T>
void merge(vector<T> &a, int l, int m, int r){
  int n1 = m - l;
  int n2 = r - m;
  vector<T> L, R;
  for(int i = 0; i < n1; i++)L.push_back(a[l+i]);
  for(int i = 0; i < n2; i++)R.push_back(a[m+i]);
  L.push_back(numeric_limits<T>::max());
  R.push_back(numeric_limits<T>::max());
  int i = 0, j = 0;
  for(int k = l; k < r; k++){
    res++;
    if(L[i] <= R[j]){
      a[k] = L[i];
      i++;
    }else{
      a[k] = R[j];
      j++;
    }
  }
}

template <typename T>
void merge_sort(vector<T> &a, int l, int r){
  if(l + 1 < r){
    int m = (l + r) / 2;
    merge_sort<T>(a, l, m);
    merge_sort<T>(a, m, r);
    merge<T>(a, l, m, r);
  }
}

template <typename T>
void merge_sort(vector<T> &a){
  merge_sort<T>(a, 0, a.size());
}

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<ll> b(n);
  rep(i, n)cin >> b[i];
  merge_sort(b);
  for(int i = 0; i < n; i++){
    cout << b[i] << "\n "[i + 1 != n];
  }
  cout << res << endl;
	return 0;
}



Measured memory_bytes: 11532
#include<iostream>
#include<sstream>
int main()
{
	auto calc = [](int arg1, char op, int arg2)
	{
		switch (op)
		{
		case '+':
			return arg1 + arg2;
			break;
		case '-':
			return arg1 - arg2;
			break;
		case '*':
		default:
			return arg1 * arg2;
		}
	};
	while (true)
	{
		std::stringstream ans("0");
		int arg[4];
		std::cin >> arg[0] >> arg[1] >> arg[2] >> arg[3];
		if (arg[0] == 0 && arg[1] == 0 && arg[2] == 0 && arg[3] == 0)
		{
			break;
		}
		for (int i = 0; i < 4; i++)
		{
			for (int j = 0; j < 4; j++)
			{
				if (j == i)continue;
				for (int k = 0; k < 4; k++)
				{
					if (k == i || k == j)continue;
					for (int l = 0; l < 4; l++)
					{
						if (l == i || l == j || l == k)continue;
						for (auto op1 : "+-*")
						{
							for (auto op2 : "+-*")
							{
								for (auto op3 : "+-*")
								{
									if (calc(calc(calc(arg[i], op1, arg[j]), op2, arg[k]), op3, arg[l]) == 10)
									{
										ans.str("");
										ans << '(' << '(' << arg[i] << op1 << arg[j] << ')' << op2 << arg[k] << ')' << op3 << arg[l];
										goto breakpoint;
									}
									else if (calc(calc(arg[i], op1, arg[j]), op2, calc(arg[k], op3, arg[l])) == 10)
									{
										ans.str("");
										ans << '(' << arg[i] << op1 << arg[j] << ')' << op2 << '(' << arg[k] << op3 << arg[l] << ')';
										goto breakpoint;
									}
									else if (calc(calc(arg[i], op1, calc(arg[j], op2, arg[k])), op3, arg[l]) == 10)
									{
										ans.str("");
										ans << '(' << arg[i] << op1 << '(' << arg[j] << op2 << arg[k] << ')' << ')' << op3 << arg[l];
										goto breakpoint;
									}
									else if (calc(arg[i], op1, calc(calc(arg[j], op2, arg[k]), op3, arg[l])) == 10)
									{
										ans.str("");
										ans << arg[i] << op1 << '(' << '(' << arg[j] << op2 << arg[k] << ')' << op3 << arg[l] << ')';
										goto breakpoint;
									}
									else if (calc(arg[i], op1, calc(arg[j], op2, calc(arg[k], op3, arg[l]))) == 10)
									{
										ans.str("");
										ans << arg[i] << op1 << '(' << arg[j] << op2 << '(' << arg[k] << op3 << arg[l] << ')' << ')';
										goto breakpoint;
									}
								}
							}
						}
					}
				}
			}
		}
	breakpoint:
		std::cout << ans.str() << std::endl;
	}
	return 0;
}


Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using pll = pair<ll, ll>;
const ll INF = 0x1fffffffffffffff;
template<class T, class U> bool chmin(T& a, const U& b){ if(a > b){ a = b; return 1; } return 0; }


int main(){
    ll n;
    cin >> n;
    vector<pair<string, ll>> a(n);
    for(auto& [s, c] : a) cin >> s >> c;
    auto rev = a;
    for(auto& [s, c] : rev) reverse(s.begin(), s.end());
    vector<vector<pll>> g(2001);
    ll cnt = 0;
    unordered_map<string, ll> l, r;
    l[""] = r[""] = cnt++;
    for(auto& [s, c] : a){
        for(ll i = 0; i < s.size(); i++) r[s.substr(i)] = cnt++;
    }
    for(auto& [s, c] : rev){
        for(ll i = 0; i < s.size(); i++) l[s.substr(i)] = cnt++;
    }
    for(auto [key, id] : l){
        for(auto& [s, c] : a){
            if(key.size() <= s.size()){
                if(s.substr(0, key.size()) == key) g[id].emplace_back(r[s.substr(key.size())], c);
            }
            else{
                if(key.substr(0, s.size()) == s) g[id].emplace_back(l[key.substr(s.size())], c);
            }
        }
    }
    for(auto [key, id] : r){
        for(auto& [s, c] : rev){
            if(key.size() <= s.size()){
                if(s.substr(0, key.size()) == key) g[id].emplace_back(l[s.substr(key.size())], c);
            }
            else{
                if(key.substr(0, s.size()) == s) g[id].emplace_back(r[key.substr(s.size())], c);
            }
        }
    }
    vector cost(2001, INF);
    priority_queue q(greater<pll>(), vector<pll>{});
    for(auto& [s, c] : a){
        for(ll i = 0; i <= s.size(); i++){
            const string a(s.rend() - i, s.rend()), b(s.begin() + i, s.end());
            if(a.size() <= b.size()){
                if(b.substr(0, a.size()) == a){
                    const ll id = r[b.substr(a.size())];
                    if(chmin(cost[id], c)) q.emplace(cost[id], id);
                }
            }
            else{
                if(a.substr(0, b.size()) == b){
                    const ll id = l[a.substr(b.size())];
                    if(chmin(cost[id], c)) q.emplace(cost[id], id);
                }
            }
        }
        for(ll i = 0; i < s.size(); i++){
            const string a(s.rend() - i, s.rend()), b(s.begin() + i + 1, s.end());
            if(a.size() <= b.size()){
                if(b.substr(0, a.size()) == a){
                    const ll id = r[b.substr(a.size())];
                    if(chmin(cost[id], c)) q.emplace(cost[id], id);
                }
            }
            else{
                if(a.substr(0, b.size()) == b){
                    const ll id = l[a.substr(b.size())];
                    if(chmin(cost[id], c)) q.emplace(cost[id], id);
                }
            }
        }
    }
    while(q.size()){
        auto [c, at] = q.top();
        q.pop();
        if(c != cost[at]) continue;
        if(at == 0){
            cout << c << endl;
            return 0;
        }
        for(auto [i, c] : g[at]) if(chmin(cost[i], cost[at] + c)) q.emplace(cost[i], i);
    }
    cout << -1 << endl;
}


Measured memory_bytes: 3908
#include <iostream>
#include <string>

using namespace std;

int main(){
  string s;
  int p = 0, g = 0, score = 0;
  cin >> s;

  for(int i = 0;i < s.size();i++){
    if(p < g){
      if(s[i] == 'g'){
        score++;
        p++;
      } else {
        p++;
      }
    } else {
      if(s[i] == 'p'){
        score--;
        g++;
      } else {
        g++;
      }
    }
  }

  cout << score << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>

void show_staff(int N);

int main(void) {
    int N;
    
    std::cin >> N;
    show_staff(N);
    
    return 0;
}

void show_staff(int N) {
    int n, boss_id;
    std::vector<int> staff(N, 0);
    
    for(n=1; n<N; n++) {
        std::cin >> boss_id;
        staff[boss_id-1] += 1;
    }
    
    for(n=0; n<N; n++) {
        std::cout << staff[n] << std::endl;
    }
}


Measured memory_bytes: 4052