akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

void trace(vector<int> vi) {
    for (auto i : vi) {
        cout << i << " ";
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, loops;
    vector<int> va, vb, vc;

    // input
    cin >> loops;
    for (int i = 0; i < loops; i++) {
        cin >> n;
        va.push_back(n);
    }
    for (int i = 0; i < loops; i++) {
        cin >> n;
        vb.push_back(n);
    }
    for (int i = 0; i < loops - 1; i++) {
        cin >> n;
        vc.push_back(n);
    }

    // calc
    int satisfaction = 0;

    for(size_t i=0; i<va.size(); i++) {
        satisfaction += vb.at(va.at(i) - 1);
        if((va.at(i) != loops) && (i != va.size() - 1)) {
            if(va.at(i) + 1  == va.at(i + 1)) {
                satisfaction += vc.at(va.at(i) - 1);
            }
        }
    }
    cout << satisfaction << endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = int64_t;

__attribute__((constructor)) static void init()
{
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double bdeg = m * M_PI / 30.0;
    double adeg = h * M_PI / 6.0 + bdeg / 12;

    double C = abs(adeg - bdeg);
    double c = sqrt(a * a + b * b - 2 * a * b * cos(C));

    printf("%.9lf\n", c);
}


Measured memory_bytes: 4276
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)


int memo[1 << 20];
int w[10];
int f[3];

void make_f(int n){
	rep(i, 3){
		int num = 0;
		rep(j, n){
			num = num * 4 + i;
		}
		f[i] = num;
	}
}

int get_s(const string &s){
	int res = 0;
	rep(i, s.size()){
		res *= 4;
		if(s[i] == 'r') res++;
		if(s[i] == 'g') res += 2;
	}
	return res;
}

int get_color(int a, int b){
	int c = min(a, b);
	int d = max(a, b);
	if(c == 0 && d == 1) return 2;
	if(c == 0 && d == 2) return 1;
	else return 0;
}

int get_num(int *w, int n){
	int res = 0;
	for(int i = 0; i < n; i++){
		res = res * 4 + w[i];
	}
	return res;
}

void to_w(int num, int n){
	for(int i = 0; i < n; i++){
		w[i] = num % 4;
		num /= 4;
	}
	reverse(w, w + n);
}

int main(){
	int n, start;
	string s;
	while(cin >> s && s != "0"){
		memset(memo, -1, sizeof(memo));
		n = s.size();
		start = get_s(s);
		make_f(n);
		queue<int> que;
		que.push(start);
		memo[start] = 0;
		bool ok = false;
		while(!que.empty()){
			int num = que.front();
			int c = memo[num];
			que.pop();
			if(num == f[0] || num == f[1] || num == f[2]){
				cout << c << endl;
				ok = true;
				break;
			}
			to_w(num, n);
			rep(i, n-1){
				if(w[i] != w[i+1]){
					int a = w[i];
					int b = w[i+1];
					w[i] = get_color(a, b);
					w[i+1] = get_color(a, b);
					int num2 = get_num(w, n);
					if(memo[num2] == -1){
						memo[num2] = c + 1;
						que.push(num2);
					}
					w[i] = a;
					w[i+1] = b;
				}
			}
		}
		if(!ok) cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[20];
int main(){
	scanf("%s",s);
	s[3]=0;
	puts(s);
}

Measured memory_bytes: 1660
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using edge = pair<int, long long>;
using Graph = vector<vector<edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

Graph g;
vector<long long> dp;
void dfs(int u, int p) {
    for (auto &e: g[u]) if (e.first != p) {
        dfs(e.first, u);
        chmax(dp[u], dp[e.first] + e.second);
    }
}
vector<long long> res;
void dfs2(int u, int p, int d_par = 0) {
    vector<pair<long long, int>> d_child;
    for (auto &e: g[u]) {
        long long dv = (e.first == p ? d_par : dp[e.first]) + e.second;
        d_child.emplace_back(dv, e.first);
    }
    sort(d_child.rbegin(), d_child.rend());
    res[u] = d_child[0].first;
    for (auto &e: g[u]) if (e.first != p) {
        long long nd_par = d_child[d_child[0].second == e.first].first;
        dfs2(e.first, u, nd_par);
    }
}

int main() {
    int n; cin >> n;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int s, t, w; cin >> s >> t >> w;
        g[s].emplace_back(t, w);
        g[t].emplace_back(s, w);
    }
    if (n == 1) return !(cout << 0 << endl);
    if (n == 2) return !(cout << g[0][0].second << endl);
    int r = -1;
    for (int i = 0; i < n; i++) if (g[i].size() >= 2) r = i;
    dp.resize(n);
    dfs(r, -1);
    res.resize(n);
    dfs2(r, -1);
    cout << *max_element(res.begin(), res.end()) << endl;
    return 0;
}


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

int main() {
    long long int A,B,C,D, K, N;
    long long int new_A, new_B, new_C, new_K;
    long long int a, b, c, d, e, f, g, h, i, j, k, l, m, n, s, w;
    vector<long long int> a_v;
    cin >> N;
    for (int i = 0; i < N; i++) {
        long long int a;
        cin >> a;
        a_v.push_back(a);
    }

    int now = 1;
    bool flag = false;
    for (i = 0; i < N; i++) { 
        now = a_v[now-1];
        // cout << now << endl;
        if (now == 2) {
            flag = true;
            break;
        }
    }

    if (flag) {
        cout << i+1 << endl;
    }
    else {
        cout << "-1" << endl;
    }

    // cin >> A;
    // cin >> B;
    // cin >> C;
    // cin >> D;

    // while(1) {
    //     C = C-B;
    //     if (C <= 0) {break;} 
    //     A = A - D;    
    //     if (A <= 0) {break;} 
    // }
    // if (A <= 0) {
    //     cout << "No" << endl;
    // }
    // else {
    //     cout << "Yes" << endl;
    // }
    // long long int tmp, cnt = 0;
    // tmp = b;
    // for (;;) {
    //     tmp = tmp/10;
    //     cnt ++;
    //     if (tmp > 0) {
    //     }
    //     else {
    //         break;
    //     }
    // } 
    // long long int time = 1;
    // for (int i = 0; i < cnt; i++) {
    //     time *= 10;
    // }
    // b += a*time;
    // // cout << b<< endl;
    // bool flag = false;
    // for (long long int i = 0; i < sqrt(b)+1; i++) {
    //     if (i*i == b) {
    //         flag = true;
    //     }
    // }
    // if (flag) {
    //     cout << "Yes" << endl;
    // }
    // else {
    //     cout << "No" << endl;
    // }

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <map>
#include <cstring>
using namespace std;

typedef vector<int> VI;
typedef pair<int, int> PII;

int N, M;
int u, v, f;
const int MAX_N = 101;
const int MAX_F = 1000000;

int maxv = 0;
int table[MAX_N][MAX_N];
bool att[MAX_N];

void solve(int last) {
	int ret = 0;
	for(int i=0; i<last+1; i++) {
		if(!att[i]) continue;
		int minF = MAX_F;
		for(int j=0; j<N; j++) {
			if(i == j) continue;
			if(!att[j]) continue;
			minF = min(minF, table[i][j]);
		}
		if(minF == MAX_F) continue;
		ret += minF;
	}
	maxv = max(maxv, ret);

	for(int i=last+1; i<N; i++) {
		bool isF = true;
		for(int j=0; j<last+1; j++) {
			if(!att[j]) continue;
			if(table[i][j]==0) { isF = false; break; }
		}
		if(!isF) continue;
		att[i] = true;
		solve(i);
		att[i] = false;
	}
}

int main() {
	cin >> N >> M;
	memset(table, 0, sizeof(int) * MAX_N * MAX_N);
	for(int i=0; i<N; i++) att[i] = false;	
	for(int i=0; i<M; i++) {
		cin >> u >> v >> f;
		u--;
		v--;
		table[u][v] = f;
		table[v][u] = f;
	}
	maxv = 0;
	solve(-1);
	cout << maxv << endl;

	return 0;
}

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

typedef bool B;
typedef long double D;
typedef complex<D> P;
typedef vector<P> VP;
typedef struct {P s,t;} L;
typedef vector<L> VL;
typedef struct {P c;D r;} C;
typedef vector <C> VC;

const D eps=1.0e-10;
const D pi=acos(-1.0);
template<class T> bool operator==(T a, T b){return abs(a-b)< eps;}
template<class T> bool operator< (T a, T b){return a < b-eps;}
template<class T> bool operator<=(T a, T b){return a < b+eps;}
template<class T> int sig(T r) {return (r==0||r==-0) ? 0 : r > 0 ? 1 : -1;}
#define X real()
#define Y imag()

D ip(P a, P b) {return a.X * b.X + a.Y * b.Y;}
D ep(P a, P b) {return a.X * b.Y - a.Y * b.X;}
D sq(D a) {return sqrt(max(a, (D)0));}
P vec(L l){return l.t-l.s;}
inline void input(P &p){D x,y;cin >> x >> y;p={x,y};}
// ???????????¬????????¨???

// ccw
enum CCW{
	LEFT = 1,
	RIGHT = 2,
	BACK = 4,
	FRONT = 8,
	MID = 16,
	ON=FRONT|BACK|MID
};

inline int ccw(P base, P a, P b) {              //???a??¨???b???????????????????????????
	a -= base; b -= base;
	if (ep(a, b) > 0)
		return LEFT;    // counter clockwise
	if (ep(a, b) < 0)
		return RIGHT;   // clockwise
	if (ip(a, b) < 0)
		return BACK;    // b--base--a on line
	if (norm(a) < norm(b))
		return FRONT;   // base--a--b on line
	// otherwise
	return MID;      // base--b--a on line  a??¨b????????????????????????
}

B iver(L a, L b) {return ip(vec(a),vec(b) )== 0.0;}
B ipar(L a, L b) {return ep(vec(a),vec(b) )== 0.0;}


// ??????
P pLL(L a,L b){ return a.s+vec(a)*ep(vec(b),b.s-a.s)/ep(vec(b),vec(a));}


// ?????¨??´?????¨????????¢??£???????????????

B iLL(L a,L b){return !ipar(a,b);}
B eqL(L a,L b){return !iLL(a, b) && ep(vec(a), b.s - a.s)==0;}
B iLS(L a,L b){return sig(ep(vec(a),b.s-a.s))*sig(ep(vec(a),b.t-a.s)) <= 0;}
B iLSs(L a,L b){return sig(ep(vec(a),b.s-a.s))*sig(ep(vec(a),b.t-a.s)) < 0;}
B iSS(L a,L b){
	int cwa = ccw(a.s,a.t, b.s) | ccw(a.s,a.t, b.t);
	int cwb = ccw(b.s,b.t, a.s) | ccw(b.s,b.t, a.t);
	return ((cwa | cwb) & MID) || ((cwa & cwb) == (LEFT | RIGHT));
}
B iSSs(L a,L b) {
	int cwa = ccw(a.s,a.t, b.s) | ccw(a.s,a.t, b.t);
	int cwb = ccw(b.s,b.t, a.s) | ccw(b.s,b.t, a.t);
	return (cwa & cwb) == (LEFT | RIGHT);
}

// ?????¨??´?????¨????????¢??£????????¢

D dLP(L l,P p){return abs( ep(vec(l),p-l.s) )/abs(vec(l));}
D dSP(L s,P p){
	if (sig( ip( vec(s), p - s.s)) <= 0) return abs(p - s.s);
	if (sig( ip(-vec(s), p - s.t)) <= 0) return abs(p - s.t);
	return dLP(s,p);
}
D dLL(L a,L b){ return iLL(a,b)?0:dLP(a,b.s);}
D dLS(L a,L b){ return iLS(a,b)?0:min(dLP(a, b.s),dLP(a, b.t));}
D dSS(L a,L b){ return iSS(a,b)?0:
	min({ dSP(a,b.s),dSP(a,b.t),dSP(b,a.s),dSP(b,a.t)});}


int main(void){
	int q;
	cin >> q;
	cout.precision(10);
	rep(loop,q){
		L line[2];
		rep(i,2){
			input(line[i].s);
			input(line[i].t);
		}
		D ans=dSS(line[0],line[1]);
		cout << fixed << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1312
# 桁DP 最適化もうむり

MOD = 10 ** 9 + 7
s = gets.chomp.split("")
question = s.map { |c| c == "?" }
length = s.length
# dp[上から i 桁まで][13 で割ったあまり]の出現回数
# 桁の自由度(smaller)は本問では不要
dp = (length + 1).times.map { Array.new(13, 0) }
# 初期化
# dp[0 桁目まで][13 で割ったあまりが 0]の出現回数は 1
dp[0][0] = 1
# （右から見た）桁数 % 6
mod_memo = [4, 1, 10, 9, 12, 3]
all_nums = (0..9).to_a

# 桁数分ループする（i は遷移元の桁）
length.times do |i|
  # 13 で割ったあまりの増加分を求める
  addition = mod_memo[(length - i) % 6]
  # 桁の数字が "?" の場合は 10 回ループ、それ以外の場合はその数字のみ
  nums = question[i] ? all_nums : [s[i].to_i]
  original_counts = dp[i]
  tmp = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
  # 13 で割ったあまりごとに確認する
  13.times do |mod|
    original_count = original_counts[mod] % MOD
    nums.each do |d|
      # 次の桁に遷移する
      tmp[(mod + addition * d) % 13] += original_count
    end
  end
  dp[i + 1] = tmp
end

puts dp[length][5] %= MOD


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
}*/
int n, k;
vi g[100000];

int dfs(int v, int p, int x){
  int res = k-x;
  int cnt = 1 + (p != -1);
  for(int to : g[v]) if(to != p){
    (res *= dfs(to, v, cnt)) %= mod;
    cnt++;
  }
  return res%mod;
}

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

  rep(i, 0, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].pb(b);
    g[b].pb(a);
  }

  int ans = dfs(0, -1, 0);
  cout << ans << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll N, A;
    cin >> N >> A;
    cout << (N < A ? 0 : 10) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
typedef long long ll;
typedef int64_t in;

using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[0]==s[1] || s[1] == s[2] || s[2]==s[3]){
        cout << "Bad" << "\n";
    }else{
        cout << "Good" << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  ll ans = 0;
  int R, G, B, N; cin>>R>>G>>B>>N;
  for(int r = 0; ; r++) {
    int sum1 = r*R;
    if(sum1 > N) break;
    for(int g = 0; ; g++) {
      int sum2 = sum1;
      sum2 += g*G;
      if(sum2 > N) break;
      int rem = N-sum2;
      if(rem % B == 0) {
        ans++;
        //      cout << r << g << rem/B << ans << endl;                                    
      } 
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
# ABC 062
def getInt(): return int(input())
def getIntList(): return [int(x) for x in input().split()]
def zeros(n): return [0]*n
def db(x): 
    global debug
    if debug: print(x)
debug = False
N = getInt()
TA = zeros(N)
for i in range(N):
    TA[i] = getIntList()
db(TA)
real = TA[0]
for i in range(1,N):
#    if real[0]>real[1]:
    if real[0]/TA[i][0] > real[1]/TA[i][1]:
        lc = (real[0]+TA[i][0]-1)//TA[i][0]*TA[i][0]
        real[0] = lc 
        real[1] = lc * TA[i][1] // TA[i][0]  
    else:
        lc = (real[1]+TA[i][1]-1)//TA[i][1]*TA[i][1]
        real[1] = lc 
        real[0] = lc * TA[i][0] // TA[i][1]  
    db((lc,real))
print(sum(real))



Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#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,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline std::ostream& operator << (std::ostream& out, const std::vector<T>& v) {
    if (v.empty())return out;
    constexpr bool is_vector_v = is_vector<T>::value;
    if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
    else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
    return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<ll> a(n);
    REP(i,n){
        a[i] = s[i]-'0';
    }
    vector<P> dp(n);
    dp[0] = P(a[0],11-a[0]);
    REP(i,n-1){
        ll t = min(dp[i].first,dp[i].second);
        ll t2 = min(dp[i].first,dp[i].second-2);
        dp[i+1] = P(t+a[i+1],t2+11-a[i+1]);
    }
    ll res = min(dp[n-1].first,dp[n-1].second);
    put(res);
    return 0;
}


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VC> VVC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

LL Gcd(LL a, LL b) {
  if (a < b) {
    return Gcd(b,a);
  }
  if (b == 0) {
    return a;
  }
  else {
    return Gcd(b,a%b);
  }
}

LL Lcm(LL a, LL b) {
  LL abd = Gcd(a,b);
  LL x = a / abd, y = b / abd;
  
  return x*y*abd;
}


LL RepSqu(LL N, LL P, LL M) {
  if(P == 0) {
    return 1;
  }
  if(P%2 == 0) {
    LL t = RepSqu(N, P/2, M);
    return t*t % M;
  }
  return (N * RepSqu(N, P-1, M)) % M;
}

bool cont(string a,int b){
  if(toInt(a)%b == 0) {
    return true;
  }else{
    return false;
  }
}

int main() {
  
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  VI a(n),b,c;
  
  int t = n%2;
  
  REP(i,n){
    cin >> a.at(i);
  }
  
  REP(i,n){
    if(i%2 == t){
      c.PB(a.at(i));
    }else{
      b.PB((a.at(i)));
    }
  }
  
  for(int i = SZ(b)-1; i>=0; i--){
    cout << b.at(i);
    if(i != 0) cout << " ";
  }
  
  if(SZ(c)) cout << " ";
  
  REP(i,SZ(c)) {
    cout << c.at(i);
    if(i != SZ(c)-1) cout << " ";
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
using namespace std;
int main(void){
    int n, ans = 0, nxt = 1;
    cin >> n;
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        if(a == nxt) nxt++;
        else ans++;
    }
    if(nxt == 1)ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

map<char,int> s_id = {{'S',0},{'H',1},{'C',2},{'D',3}};
map<int,char> id_s = {{0,'S'},{1,'H'},{2,'C'},{3,'D'}};
bool check[4][13];

int main () {
  int n = in();
  rep(i,n) {
    char s;
    int x;
    cin >> s >> x;
    check[s_id[s]][x-1] = true;
  }
  rep(i,4)rep(j,13) {
    if (!check[i][j]) {
      printf("%c %d\n", id_s[i], j+1);
    }
  }
  return 0;
}


Measured memory_bytes: 3200
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int a,b,c;
		Scanner sc=new Scanner(System.in);
		a=sc.nextInt();
		b=sc.nextInt();
		c=sc.nextInt();
		if(a+b+c>21){
			System.out.println("bust");
		}else{
			System.out.println("win");
		}
	}
}


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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int k = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            string result = "";
            if (s.Length <= k)
            {
                result = s;
            }
            else
            {
                result = s.Substring(0, k) + "...";
            }


            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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


int main(int argc, const char * argv[]) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if (abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
use strict;
my $N = <STDIN>;
my $line = <STDIN>;
my @a=split ' ',$line;

my $mean=0;
for(my $i=0;$i<$N;$i++){ $mean += $a[$i]; }

$mean = int($mean/$N);

my @cost;
my $l=0;
my $plus=$mean;
my $minus=$mean;
my $tempM=$mean;
my $tempP=$mean;

while($l<3){
  my $k=0;
  my $up=0;
  my $down=0;
  while($k<$N){
    $up += ($a[$k]-$tempP)*($a[$k]-$tempP);
    $k++;
  }
  my $k=0;
  while($k<$N){
    $down += ($a[$k]-$tempM)*($a[$k]-$tempM);
    $k++;
  }
  push @cost,$up;
  push @cost,$down;
  $tempP++;
  $tempM--;
  $l++;
}

@cost = sort{$a<=>$b}@cost;

print"$cost[0]\n";


Measured memory_bytes: 512
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;

int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  const int N = 1e5 + 42;
  vector<int> a(N);
  int n; cin >> n;
  i64 s = 0;
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    a[x]++;
    s += x;
  }
  int q; cin >> q;
  while (q--) {
    int x, y; cin >> x >> y;
    s += (i64) (y - x) * a[x];
    a[y] += a[x];
    a[x] = 0;
    cout << s << '\n';
  }
}


Measured memory_bytes: 3660
h, w, k = map(int, input().split())
s = [list(map(int, list(input()))) for _ in range(h)]
result = []
if h*w<=k:
    result.append(0)
else:
    for i in range(2**(h-1)):
        checker, num, p = 0, i ,[0]
        for _ in range(h):
            p.append(p[-1]+num%2)
            checker += num%2
            num >>= 1
        x = 0
        c = [0 for _ in range(checker+1)]
        for j in range(w):
            num = i
            nex = [0 for _ in range(checker+1)]
            for m in range(h):
                nex[p[m]] += s[m][j]
            if max(nex) > k:
                x = float('inf')
                break            
            
            if all(nex[m]+c[m] <= k for m in range(checker+1)):
                c = [c[I]+nex[I] for I in range(checker+1)]
            else:
                x += 1
                c = nex
        result.append(checker+x)
print(min(result))

Measured memory_bytes: 49244
#include <bits/stdc++.h>
#define cin_fit() cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed;
#define rep(i, N) for(int i=0; i<(N); i++)
#define reps(i, N) for(int i=1; i<=(N); i++)
#define rrep(i, N) for(int i=(int)(N)-1; i>=0; i--)
#define rreps(i, N) for(int i=(int)(N); i>=1; i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
using namespace std;
using ll = long long;
using V = vector<ll>;
using P = pair<ll, ll>;
constexpr int inf = 1e9;
constexpr int mod = 1e9+7;
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;}

ll n, k;

int main() {
    cin_fit();
    cin >> n >> k;
    double ans = 0;
    reps(i, n) {
        double p = 1.0;
        ll x = i;
        while (x < k) {
            p *= 0.5;
            x *= 2;
        }
        ans += p;
    }
    cout << setprecision(11) << ans/n << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#define FOR(n) for(int i = 0;i < n;i++)
#define PRN(n) printf("%d\n",n)

 int main(void){
   char a[4],b[4];
   scanf("%s %s",a , b);
   if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0])
     printf("YES");
   else
     printf("NO");
   return 0;
}

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

using namespace std;

int main(){
	int n, k, sum = 0;
	cin >> n>>k;

	vector<int> c;
	c.resize(n);
	for(int i = 0;i<n;i++){
		cin >> c[i];
	}
	sort(c.begin(), c.end());

	for(int i=0;i<k;i++){
		sum+=c[i];
	}

	cout << sum;


	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

//Persistence
public class Main {

	static int[] w;
	static int n, m;
	
	static boolean f(int W){
		int need = 1;
		int s = 0;
		for(int i=0;i<n;i++){
			if(w[i]>W)return false;
			if(s+w[i]>W){
				need++;
				s = 0;
			}
			s+=w[i];
		}
		return need <= m;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			m = sc.nextInt();
			n = sc.nextInt();
			if((m|n)==0)break;
			w = new int[n];
			for(int i=0;i<n;i++)w[i]=sc.nextInt();
			int l = 1;
			int r = 1500000;
			while(r-l>1){
				int mid = (l+r)/2;
				if(f(mid))r = mid;
				else l = mid;
			}
			System.out.println(f(l)?l:r);
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

template<int mod> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % mod) {
        if (val < 0) val += mod;
    }
    constexpr int getmod() { return mod; }
    constexpr Fp operator - () const noexcept {
        return val ? mod - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= mod) val -= mod;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % mod;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % mod;
        if (val < 0) val += mod;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr istream& operator >> (istream &is, const Fp<mod>& x) noexcept {
        int val; is >> val;
        x = Fp<mod>(val);
        return is;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<mod>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<mod> modpow(const Fp<mod> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int mod = 1e9+7;
using mint = Fp<mod>;

int main(){
    int n; cin  >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    vector<mint> sum(n);
    sum[n-1] = (mint)a[n-1];
    rrep(i,n-1){
        sum[i] = sum[i+1] + (mint)a[i];
    }
    mint ans = 0;
    rep(i,n-1){
        ans += (mint)a[i] * sum[i+1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 6408
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

bool equal(string s) {
  for(int i = 0,j = s.size()/2;j < s.size();i++,j++) {
    if(s[i] != s[j]) return false;
  }
  return true;
}

int main() {
  int n;
  cin>>n;
  int a[n+1];
  fr(i,1,n+1) cin>>a[i];
  set<int> vis;
  int s = 1, ans = 0;
  while(true) {
    s = a[s];
    if(vis.find(s) != vis.end()) {
      cout<<-1;
      return 0;
    }
    vis.insert(s);
    if(s == 2) {cout<<ans+1; return 0;}
    ans++;
  }
  
}

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

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll K, a, b;
string ans = "NG";
int main(){
	cin >> K;
	cin >> a >> b;
	REP(i,a,b+1){
		if(i % K == 0) ans="OK";
	}
	p(ans);
	return 0;
}


Measured memory_bytes: 3636
#-*- coding:utf-8 -*-
N = int(input())
a1 = []
a2 = []
s,t = 0,0

a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))



for i in range(N):
	for j in range(i+1):
		t += a1[j]
	for k in range(N-i):
		t += a2[i+k]
	if t > s:
	    s = t
	t = 0
print(s)

Measured memory_bytes: 3060
X, Y, Z, K = map(int, input().split())
*A, = map(int, input().split())
*B, = map(int, input().split())
*C, = map(int, input().split())

S = []
for a in A:
    for b in B:
        S.append(a+b)
S.sort()
C.sort()
T = C

L = X*Y

left = 3; right = max(A)+max(B)+max(C)+1
while left+1 < right:
    mid = (left + right) >> 1
    cur = L
    cnt = 0
    for c in C:
        while cur > 0 and S[cur-1]+c > mid:
            cur -= 1
        cnt += L - cur
    if cnt < K:
        right = mid
    else:
        left = mid
ans = []
for c in C:
    cur = L
    while cur > 0 and S[cur-1]+c >= left:
        v = S[cur-1]+c
        if v == left and len(ans) >= K:
            break
        ans.append(v)
        cur -= 1
ans.sort(reverse=1)
print(*ans[:K], sep='\n')

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

int main(){
    long long h, n;
    cin >> h >> n;
    vector<long long> a(n);
    for(int i=0; i<n; i++) {
        cin >> a[i];
        h -= a[i];
    }
    if(h <= 0) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 4048
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

s = [_ for _ in input()]
t = [_ for _ in input()]

ans = 10**10

for i in range(len(s) - len(t)+1):
  a = 0
  for j in range(len(t)):
    if s[i+j] != t[j]:
      a+=1
  ans = min(a,ans)
print(ans)


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

const int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
int w, h;
int c[50][50];

void dfs(int y, int x) {
    c[y][x] = 0;
    for (int i = 0; i < 8; ++i) {
        int ny = y + dy[i];
        int nx = x + dx[i];
        if (ny >= 0 && ny < h && nx >= 0 && nx < w && c[ny][nx]) {
            dfs(ny, nx);
        }
    }    
}

int main() {
    while (cin >> w >> h, w) {
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> c[i][j];
            }
        }
        int ans = 0;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                if (c[i][j] == 1) {
                    ans++;
                    dfs(i, j);
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3176
#include<stdio.h>
#define MAX 2000000
#define INFTY 1073000000
void maxHeapify(int);
void insert(int);
void increaseKey(int,int);
int extractMax(void);
void swap(int,int);
int parent(int);
int left(int);
int right(int);
int A[MAX+1],H=0;

int main(){
  int key;
  char c[8];
  while(1){
    scanf("%s",c);
    if(c[0] =='e' && c[1] == 'n') break;
    if(c[0] == 'i'){
      scanf("%d",&key);
      insert(key);
    }
    else{
      printf("%d\n",extractMax());
    }
  }
  return 0;
}

void maxHeapify(int i){
  int r,l,largest;
  l = left(i);
  r = right(i);

  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    swap(i,largest);
    maxHeapify(largest);
  }
}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

void swap(int i, int largest){
  int tmp;
  tmp = A[i];
  A[i] = A[largest];
  A[largest] = tmp;
}


void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseKey(H,key);
}

 void increaseKey(int i,int key){
   if(key < A[i]) return;
   A[i] = key;
   while(i > 1 && A[parent(i)] < A[i]){
     swap(parent(i),i);
     i = parent(i);
   }
 }
 int extractMax(void){
   int max;
   if(H < 1) return -INFTY;
   max = A[1];
   A[1] = A[H];
   H--;
   maxHeapify(1);
   return max;
}

Measured memory_bytes: 4696
def main():
    n = int(input())
    s = input()
    # まず第1の条件を満たす組をカウント
    ans = s.count('R') * s.count('G') * s.count('B')
    # その後、第2の条件も同時に満たす組を除外する
    for i in range(n - 2):
        for d in range(1, (n - i - 1) // 2 + 1):
            j, k = i + d, i + d * 2
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans -= 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n),c(n);
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n)cin>>c[i];
    sort(a.begin(),a.end());
    sort(c.begin(),c.end());
    ll ans=0;
    rep(i,n){
        ans+=(lower_bound(a.begin(),a.end(),b[i])-a.begin())*
        (n-(lower_bound(c.begin(),c.end(),b[i]+1)-c.begin()));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#define MAX 100000000

void maxHeapify(int);

int A[MAX+1];
int H;

int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

void maxHeapify(int i){
  int l,r,largest,swap;
  l=2*i;
  r=2*i+1;
  if(l<=H&&A[l]>A[i]){
    largest=l;
  }
  else{
    largest=i;
  }
  if(r<=H&&A[r]>A[largest]){
    largest=r;
  }
  if(largest!=i){
    swap=A[largest];
    A[largest]=A[i];
    A[i]=swap;
    maxHeapify(largest);
  }
}



Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <algorithm>

using namespace std;

int hilbert(int x, int y, int d)
{
	if (d < 0)
	{
		return 0;
	}
	if (x < (1 << d))
	{
		if (y < (1 << d))
		{
			return hilbert(y, x, d - 1);
		}
		else
		{
			return hilbert(x, y - (1 << d), d - 1) + (1 << d) * (1 << d);
		}
	}
	else
	{
		if (y < (1 << d))
		{
			return hilbert((1 << d) - 1 - y, (1 << d) * 2 - 1 - x, d - 1) + (1 << d) * (1 << d) * 3;
		}
		else
		{
			return hilbert(x - (1 << d), y - (1 << d), d - 1) + (1 << d) * (1 << d) * 2;
		}
	}
}

#define M 5

#define INF (1 << 20)

class rec
{
public:
	int xt, xb, yt, yb;

	bool operator<(const rec& a) const
	{
		return true;
	}
};

rec kou(rec m, rec n)
{
	rec r;
	r.xt = min(m.xt, n.xt);
	r.xb = max(m.xb, n.xb);
	r.yt = min(m.yt, n.yt);
	r.yb = max(m.yb, n.yb);
	return r;
}

bool kt(rec b, rec n, int s)
{
	s = sqrt((double)s) + 1;
	return (b.xt - n.xt > -s && b.xt - n.xb < s) && (b.yt - n.yt > -s && b.yt - n.yb < s);
}

bool eq(rec a, rec b)
{
	return a.xt == b.xt && a.xb == b.xb && a.yt == b.yt && a.yb == b.yb;
}

int ky(rec a, rec b)
{
	return (a.xt - b.xt) * (a.xt - b.xt) + (a.yt - b.yt) * (a.yt - b.yt);
}

class rtree
{
public:
	class point
	{
	public:
		int n;
		int k[M];
		rec r[M];
	};

	point* mm;
	int ulas;

	rtree(int s)
	{
		mm = (point*)malloc(sizeof(point) * (s / M * 3 + 10));
		ulas = 0;
	}

	int get()
	{
		ulas++;
		return ulas;
	}

	int make(vector<pair<int, rec>> d)
	{
		int k = (d.size() - 1) / M + 1;
		vector<pair<int, rec>> r(k);
		for (int i = 0; i < k; i++)
		{
			int s = i * d.size() / k;
			int e = (i + 1) * d.size() / k;
			int n = get();
			mm[n].n = e - s;
			rec b;
			b.xt = INF;
			b.xb = -INF;
			b.yt = INF;
			b.yb = -INF;
			for (int j = 0; j < e - s; j++)
			{
				mm[n].k[j] = d[s + j].first;
				mm[n].r[j] = d[s + j].second;
				b = kou(b, d[s + j].second);
			}
			r[i] = make_pair(n, b);
		}
		if (k == 1)
		{
			return r[0].first;
		}
		return make(r);
	}

	int find(rec r, int b, int s)
	{
		if (mm[b].k[0] < 0)
		{
			for (int i = 0; i < mm[b].n; i++)
			{
				if (!eq(r, mm[b].r[i]))
				{
					s = min(s, ky(r, mm[b].r[i]));
				}
			}
		}
		else
		{
			for (int i = 0; i < mm[b].n; i++)
			{
				if (kt(r, mm[b].r[i], s))
				{
					s = find(r, mm[b].k[i], s);
				}
			}
		}
		return s;
	}
};

int main()
{
	int N;
	scanf("%d", &N);
	vector<rec> w(N);
	for (int i = 0; i < N; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x += 10000;
		y += 10000;
		w[i].xt = x;
		w[i].xb = x;
		w[i].yt = y;
		w[i].yb = y;
	}
	vector<pair<int, rec>> d(N);
	for (int i = 0; i < d.size(); i++)
	{
		d[i] = make_pair(hilbert(w[i].xt, w[i].yt, 20), w[i]);
	}
	sort(d.begin(), d.end());
	for (int i = 0; i < N; i++)
	{
		d[i].first = -1;
	}
	int m = INF;
	for (int i = 0; i < N - 1; i++)
	{
		m = min(m, ky(d[i].second, d[i + 1].second));
	}
	rtree t(N);
	int o = t.make(d);
	for (int i = 0; i < N; i++)
	{
		m = t.find(w[i], o, m);
	}
	printf("%d\n", m);
}

Measured memory_bytes: 47736
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> x(n),y(n);
  for(int i=0;i<n;i++)cin>>x.at(i)>>y.at(i);
  auto dist=[&](int i,int j){
  double dx=x.at(j)-x.at(i);
  double dy=y.at(j)-y.at(i);
  return sqrt(dx*dx+dy*dy);
  };
  double d=0;
  int cnt=0;
  vector<int> p(n);
  for(int i=0;i<n;i++)p.at(i)=i;
  do{
    for(int i=0;i<n-1;i++)d+=dist(p.at(i),p.at(i+1));
    cnt++;
  }while(next_permutation(p.begin(),p.end()));
  double ans=d/cnt;
  cout<<fixed<<setprecision(10)<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};


#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define REP_REV(i, n) for (ll i = n-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;

signed main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string s;
  ll K;
  cin >> s >> K;
  ll n = sz(s);
  vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(2, vector<ll>(K+1)));
  dp[0][0][0] = 1;
  REP(i, n) {
//    bound
    if(s[i] == '0') {
      REP(k, K+1) {
        dp[i + 1][0][k] += dp[i][0][k];
      }
    }
    else {
      // 0
      REP(k, K+1) {
        dp[i + 1][1][k] += dp[i][0][k];
      }
      // upper
      REP(k, K) {
        dp[i + 1][0][k+1] += dp[i][0][k];
      }
    }
    REP_FROM(j, 1, s[i] - '0') { // upperは無視
      REP(k, K) {
        dp[i+1][1][k+1] += dp[i][0][k];
      }
    }
//    unbound
    REP(k, K+1) {
      dp[i+1][1][k] += dp[i][1][k];
    }
    REP_FROM(j, 1, 10) {
      REP(k, K) {
        dp[i+1][1][k+1] += dp[i][1][k];
      }
    }
  }

  cout << dp[n][0][K] + dp[n][1][K] << endl;

  return 0;
}


Measured memory_bytes: 256