akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;
string table = "yuiophjklnm";

int main() {
	while (cin >> s&&s != "#") {
		ll ans = 0;
		bool f = (table.find(s[0]) != -1);
		rep(i, s.size() - 1) {
			if (f != (table.find(s[i + 1]) != -1)) {
				f = (table.find(s[i + 1]) != -1);
				ans++;
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3156
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function hpush(h::Array{Tuple{Int,Int},1},x::Tuple{Int,Int})
	push!(h,x)
	if length(h) > 1
		l = length(h)
		k = div(l,2)
		while h[k][2]>x[2]&&k>=1
			tmp = h[k]
			h[k] = x
			h[l] = tmp
			k = max(div(k,2),1)
			l = div(l,2)
		end
	end
end

function hpop(h::Array{Tuple{Int,Int},1})
	x = h[1]
	z = pop!(h)
	if !isempty(h)
		h[1] = z
		k = 1
		l = length(h)
		while k <= l
			if 2*k>=l
				break
			elseif 2*k+1>=l
				if h[2*k][2]>=z[2]
					break
				else
					tmp = h[2*k]
					h[2*k] = z
					h[k] = tmp
					k = 2*k
				end
			else
				if h[2*k][2]>=z[2]&&h[2*k+1][2]>=z[2]
					break
				else
					t = h[2*k][2]<h[2*k+1][2]?2*k:2*k+1
					tmp = h[t]
					h[t] = z
					h[k] = tmp
					k = t
				end
			end
		end
	end
	x
end

function dijkstra(e::Array{Array{Int,1},1},k,t)
	dis = -ones(Int, length(e))
	h = Array{Tuple{Int,Int},1}()
	push!(h,(k,0))
	while !isempty(h)
		v,w = hpop(h)
		dis[v] = dis[v]<0?w:min(dis[v],w)
		if v == t
			break
		end
		for i in 1:length(e[v])
			if dis[e[v][i]]<0　|| dis[e[v][i]]>w+1
				dis[e[v][i]]=w+1
				hpush(h,(e[v][i],w+1))
			end
		end
	end
	dis
end

function main()
	n,m = readline() |> split |> parseMap
	e = [Int[] for i in 1:3*n]
	for i in 1:m
		u,v = readline() |> split |> parseMap
		push!(e[u],n+v)
		push!(e[n+u],2*n+v)
		push!(e[2*n+u],v)
	end
	s,t = readline() |> split |> parseMap
	dis = dijkstra(e,s,t)
	println(dis[t]>=0?div(dis[t],3):-1)

end

main()

Measured memory_bytes: 166532
import java.util.*;

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

        int wsize = t.length();
        int mcount = 0;
        for(int i = 0 ; i < s.length() - wsize + 1; i++){
            int temp = 0;
            String k = s.substring(i, wsize + i);
            for(int j = 0 ; j < wsize ; j++){
                if(t.charAt(j) == k.charAt(j)) temp++;
            }
            mcount = Math.max(temp,mcount);
        }

        System.out.println(wsize - mcount);

    }
}

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

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  double sum = 0;
  rep(i, n) sum += 1.0 / a[i];
  double result = 1.0 / sum;

  cout.precision(10);
  cout << result << endl;

  return 0;
}


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

int main() {
  int N, K, X=0, Y=0;
  
  cin >> N >> K;
  
  while(N > 0){
    X += N % K;
    N = N / K;
    Y++;
  }
  
  cout << Y << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	if((ll)s.size()==1) {
		cout<<"YES"<<endl;
		return 0;
	}
	vector<ll> c(3,0);
	REP(i,(ll)s.size()) {
		if(s[i]=='a') c[0]++;
		if(s[i]=='b') c[1]++;
		if(s[i]=='c') c[2]++;
	}
	bool d=false;
	REP(i,3) {
		REP(j,3) {
			if(i==j) continue;
			vector<ll> buf(3,0);
			buf[0]=c[0];
			buf[1]=c[1];
			buf[2]=c[2];
			ll a=i,b=j;
			if(buf[i]==0||buf[j]==0) continue;
			buf[i]--;
			buf[j]--;
			bool f=true;
			FOR(k,2,(ll)s.size()) {
				if(buf[3-a-b]!=0) {
					buf[3-a-b]--;
					ll bufbuf=b;
					b=3-a-b;
					a=bufbuf;
				} else {
					f=false;
					break;
				}
			}
			if(f) d=true;
		}
	}
	if(d) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}



Measured memory_bytes: 512
#include <bits/stdint-intn.h>
#include<cstdint>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<iterator>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>
#include<utility>
#include<initializer_list>


#define repi(i,start,end)for(int64_t (i)=(start);(i)<(end);++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x, v) for(auto& (x) : (v))
#define iterate(itr, v) for(auto (itr)=(v).begin();(itr)!=(v).end();++(itr))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vin(v) rep(i,(v).size()) cin >> (v)[i];
#define vpin(v) rep(i,(v).size()) cin >> (v)[i].first >> (v)[i].second

using namespace std;
using Int = int64_t;
using pint = pair<Int, Int>;
using vint = vector<Int>;
using vvint = vector<vint>;
using vpint = vector<pint>;
using vstr = vector<string>;

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<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<"\n";}
template<class T>void println(T a){cout << a << "\n";}
template<class T>void put_line(T &v){iterate(itr,v){cout<<*itr<<((itr==--v.end())?"\n":" ");}}
// auto [x, y] = make_tuple(3, 4); => let (x, y) = (3, 4);

int main(void) {
    Int x; cin >> x;
    vpint pows;
    Int t = 0;
    while(1){
        Int r = pow(t, 5);
        if(r > 1e18) break;
        pows.push_back(pint(t, r));
        t++;
    }
    Int len = pows.size();

    rep(i, len - 1) {
        repi(j, i, len) {
            auto [a, a5] = pows[i];
            auto [b, b5] = pows[j];
            Int s = a5 + b5, d = abs(a5 - b5);
            if(d == x) {
                cout << b << " " << a << endl;
                return 0;
            }
            if(s == x) {
                cout << b << " " << -a << endl;
                return 0;
            }
        }
    }


    return 0;
}


Measured memory_bytes: 4360
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const B = arg[1].split(" ").map(n=>parseInt(n));
    
    let answer = [];
    
    answer[0] = B[0];
    answer[1] = B[0];
    
    for(let i=1; i<N-1; i++) {
        if(answer[i] > B[i]) {
            answer[i] = B[i];
        }
        
        answer[parseInt(i) + 1] = B[i];
    }
    
    console.log(answer.reduce((m,n)=>m+n));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif


    int k;
    cin >> k;
    if (k % 7 == 0) k /= 7;
    k *= 9;
    int pw = 1;
    for (int n = 1; n <= k + k; n++) {
        pw = (pw * 10) % k;
        if (pw % k == 1) {
            cout << n << "\n";
            return 0;
        }
    }
    cout << "-1\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3652
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {

    let v = read_t_in_line::<i32>();
    if v[0] == v[1] {
        println!("{}", v[2]);
    }
    else if v[0] == v[2] {
        println!("{}", v[1]);
    }
    else{
        println!("{}", v[0]);
    }

}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>
#include<functional>
#include<utility>

typedef long long ll;

#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define P pair<int, int>
#define PLI pair<ll, int>
#define PLL pair<ll, ll>

using namespace std;


int main() {
	int N, M;
	int x[105], mp[2030] = {};

	cin >> N;
	rep(i, N) {
		cin >> x[i];
		mp[x[i]]++;
	}
	cin >> M;
	rep(i, M) {
		int a;
		cin >> a; a--;
		if (mp[x[a] + 1] == 0 && x[a] < 2019) {
			mp[x[a] + 1]++;
			mp[x[a]]--;
			x[a]++;
		}
	}

	rep(i, N) {
		cout << x[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
map<ll,ll> mp;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
ll dp[100005];
int main(){
int n,m;
cin>>n>>m;
priority_queue<ll> pq;
for(int i=0;i<n;i++){
    ll p;cin>>p;
   pq.push(p);
}
while(1){
   ll tmp=pq.top();
   pq.pop();
   if(pq.empty()){
       while(m!=0){
           if(tmp==0)break;
           tmp/=2;
       }
       pq.push(tmp);
       break;
   }
   ll tmp2=pq.top();
   while(m!=0&&tmp2<=tmp){
       tmp/=2;
       m--;
   }
   pq.push(tmp);
   if(m==0)break;
}
ll ans=0;
while(!pq.empty()){
    ans+=pq.top();
   pq.pop();
}
cout<<ans<<endl;
}


Measured memory_bytes: 1400
n = gets.to_i
a = gets.split.map(&:to_i)
cum = [0]
tmp = 0

a.each do |i|
  tmp += i
  cum << tmp
end

min = (cum[1] - (cum[-1] - cum[1])).abs

2.upto(n - 1) do |i|
  tmp = (cum[i] - (cum[-1] - cum[i])).abs
  min = tmp if min > tmp
end

puts min

Measured memory_bytes: 16956
from operator import itemgetter

A, B, C, D, E, F = map(int, input().split())


def f(x, y):
    max_i = F // x
    max_j = F // y
    arr = []
    for i in range(max_i + 1):
        for j in range(max_j + 1):
            a = x * i + y * j
            if a <= F:
                arr.append(a)
    return list(set(arr))


water = f(100 * A, 100 * B)
sugar = f(C, D)

ans = []
for w in water:
    if w == 0:
        continue
    for s in sugar:
        if w + s <= F and s / w <= E / 100:
            ans.append((w + s, s, s / (w + s)))
ans = sorted(ans, key=itemgetter(2), reverse=True)
print(ans[0][0], ans[0][1])


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

int n, x;
long long ans, cnt = 1;

int main() {
	cin >> n;

	cin >> x;
	ans += (x - 1);

	for (int i = 1; i < n; i++) {
		cin >> x;
                if (x > (cnt + 1))
                        ans += ((x - 1) / (cnt + 1));
		else if (x == (cnt + 1))
			++cnt;
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

int main()
{
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a; i <= b; i++) {
        if((i % 10 == i / 10000) && ((i/10) % 10 == (i/1000)%10)){
            ans++;
        }
    }

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


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

#define rep(i,a,b) for(int i=int(a);i<=int(b);++i)
#define nrep(i,a,b) for(int i=int(a);i>=int(a);--i)
#define trv(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define watch(x) cout<<"\n"<<#x<<" is "<<x<<"\n"
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
#define ZERO(box) memset(box, 0, sizeof(box));
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define chkbit(s, b) (s & (1<<b))
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
const int mod=1e9+7;

int n;

int main(){
	cin>>n;
	vi h(n);
	trv(i,0,n) cin>>h[i];
	vi dp(n+1);
	dp[0]=0;
	dp[1] = abs(h[1]-h[0]);
	trv(i,2,n){
		dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]));
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
    public static void main(String[] args)
    {
        
        Scanner sc = new Scanner(System.in);
        while(true)
        {
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W == 0)
            {
                break;
            }
            for(int j=0;j<H;j++)
            {
                for(int i = 0; i < W ;i++)
                {
                    if(i == 0 || i == W-1 || j == 0 || j == H-1)
                    {
                        System.out.print("#");
                        continue;
                    }
                    
                    System.out.print(".");

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


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

using namespace std;

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

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

    int p = 0, q = 0;
    while (prev_permutation(a + 0, a + n)) p++; 
    while (prev_permutation(b + 0, b + n)) q++;

    cout << (p > q ? p - q : q - p);
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

/*SXAQWCG
Aのアスキーコードは65
aのアスキーコードは97
*/


int main(int argc, char const *argv[])
{
	
/*
	char ch = 'A';
	printf("%c = %d\n", ch, ch);

	int num = 122;
	printf("%c = %d\n", num, num);

*/

	char ch;

	while(1) {
		scanf("%c", &ch);
		
		if ('a' <= ch && ch <= 'z') {
			ch -= 32;
		}

		else if ('A' <= ch && ch <= 'Z') {
			ch += 32;
		}



		printf("%c", ch);

		if (ch == '\n') break;


	}





	return 0;

}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int>v(n);
    for(int i=0;i<n;++i){
        cin>>v[i];
    }
    vector<int>vv=v;
    sort(v.begin(),v.end());
    int ans1=v[n/2],ans2=v[n/2-1];
    for(int i=0;i<n;++i){
        if(vv[i]<=ans2)cout<<ans1<<endl;
        else cout<<ans2<<endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
#define rep(i,e) for(int i= 0; i< (int)(e); i++)
#define reps(i,s,e) for(int i = s; i < (int)(e); i++)
#define repr(i,s,e) for(int i = s; i > (int)(e); i--)
#define pb push_back
typedef long long ll;
const ll INF = 1LL << 60;
ll bigp = 1000000007;

ll binary_search(ll key,vector<ll> &a) {
    ll ng = -1;
    ll ok = (ll)a.size(); 
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        if (a[mid] > key) ok = mid;
        else ng = mid;
    }
    return ok;
}


int main()
{
    ll n;
    cin >> n;
    vector<ll> l(n);
    rep(i,n){
        cin >> l[i];
    }
    sort(l.begin(),l.end());
    ll ans = 0;
    rep(i,n-1){
        reps(j,i+1,n){
            ll tmp_ans = 0;
            ll a = l[i];
            ll b = l[j];
            tmp_ans = binary_search(a+b-1,l) - binary_search(b-a,l);
            if(2*a > b){
                tmp_ans -= 2;
            }else{
                tmp_ans -= 1;
            }
            ans += tmp_ans;
        }
    }
    cout << ans/3;
}

Measured memory_bytes: 256
import Control.Monad
import Data.List
main=do
 n<-readLn
 s<-replicateM n readLn
 print(f (sum s) [x|x<-s,(mod x 10)/=0])
  where f s d = if (mod s 10)==0 then (if d==[] then 0 else s-(head(sort d))) else s

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

ll cnt;
int l;
int A[10000000];
int n;
vector<int> G; //シェルソートの際の差の配列

void insertionSort(int A[],int n,int g){
  for(int i = g;i<n;i++){
    int v = A[i];
    int j = i - g;
    while(j>=0 && A[j]>v){
      A[j+g] = A[j];
      j -= g;
      cnt++;
    }
    A[j+g] = v;
    }
  }

void shellSort(int A[],int n){//g[0]が１になるようにする
  for( int h = 1; ; ){
    if(h>n) break;
    G.push_back(h);
    h = 3*h + 1;
  }

  for( int i = G.size()-1; i>=0;i--){ //逆順にG[i]=gを指定
    insertionSort(A,n,G[i]);
  }
}

int main(){
  cin >> n; 
  rep(i,n) cin >> A[i];
  cnt=0;

  shellSort(A,n);
  
  cout << G.size() << endl;
  for(int i= G.size()-1;i>=0;i--){
    cout << G[i];
    if(i) cout << " ";
  }
  cout << endl;
  cout << cnt << endl;

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

  return 0;
}



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

int main() {
	int a;
	cin>>a;
	int b=(a-a%100)/100;
	int d=a%100;
	int c=(d-d%10)/10;
	int e=d%10;
	if(e==b){
		cout<<"Yes"<<endl;
	}
	else {
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 256
#include <stdio.h>
int INFTY = 1000000000;

int A[500001],cnt=0,n;

void merge(int left,int mid,int right)
{
  int n1,n2,i,j,k;
  n1 = mid - left;
  n2 = right - mid;
  int L[n1+1],R[n2+1];
  for(i=0;i<n1;i++) L[i] = A[left + i];
  for(i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k=left;k<right;k++)
  {
    cnt++;
    if( L[i] <= R[j] )
    {
      A[k] = L[i];
      i = i+1;
    }
    else
    {
      A[k] = R[j];
      j = j+1;
    }
  }
}


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

int main()
{
  
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  mergeSort(0,n);
  for(i=0;i<n;i++)
  {
    printf("%d",A[i]);
    if(i==n-1) printf("\n");
    else printf(" ");
  }
  printf("%d\n",cnt);
  return 0;
}



Measured memory_bytes: 5612
#include<bits//stdc++.h>
using namespace std;
int main(){
  string s;cin >>s;
  int num = 0;
  for(int i = 0;i <s.size();i++){
    num += s[i] - '0';
    num%=9;
  }if(num%9==0) cout << "Yes" <<endl;
  else cout << "No"<<endl;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define all(a)  (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<pii> a(n);
  rep(i, n){
    int tmp; cin >> tmp;
    a[i] = make_pair(tmp, i+1);
  }
  sort(all(a));
  rep(i, n) std::cout << a[i].second << '\n';
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long int ll;
int a[100100][3];
int dp[100100][3]; //dp[i][j] = i日目にjを選ぶ場合の幸福度の最大値
int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    rep(i, n)
    {
        rep(j, 3)
        {
            rep(k, 3)
            {
                if (k == j)
                    continue;
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + a[i][k]);
            }
        }
    }
    cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

Measured memory_bytes: 2560
N, Y = map(int,input().split())


for x in range(Y//10000 + 1):
    for y in range((Y - x*10000)//5000+1):
        z = N-(x+y)
        zz = (Y-x*10000-y*5000)//1000
        if z==zz:
            print(x, y, z)
            exit()

else:
    print('-1 -1 -1')


Measured memory_bytes: 3060
#include<stdio.h>
int main (void){
  int A;int B;
  scanf("%d %d",&A,&B);
  int ans;
  if(A == B){
    ans = A + B;
  }else if(A < B){
    ans = B + B - 1;
  }else {
    ans = A + A - 1;
  }
  printf("%d\n",ans);
}

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

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



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

int main() {
  vector<int> p;
  int N, K, i, j, sum = 0;
  
  cin >> N >> K;
  for(i = 0; i < N; i++){
    cin >> j;
    p.push_back(j);
  }
  sort(p.begin(), p.end());
  for(i = 0; i < K; i++)sum += p[i];
  cout << sum << endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef string str;
static const long long INF = 1LL<<59;
static const long long MOD = (ll)1e9+7;

#define endl "\n"
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define REP(i, n) for(ll i=0;i<n;i++)
#define SZ(v) (ll)((v).size())
#define WHOLE(v) (v).begin(), (v).end()
#define ASC(v) sort((v).begin(), (v).end())
#define DESC(v) sort((v).rbegin(), (v).rend())
#define INV(v) reverse((v).begin(), (v).end())
#define FOLDL(src, dst, lambda) partial_sum((src).begin(), (src).end(), (dst).begin(), lambda)
#define FOLDR(src, dst, lambda) INV(src);partial_sum((src).begin(), (src).end(), (dst).begin(), lambda);INV(dst)
#define CUMSUML(src, dst) FOLDL(src, dst, [](auto a, auto b) {return a+b;})
#define CUMSUMR(src, dst) FOLDR(src, dst, [](auto a, auto b) {return a+b;})
#define ACCUM(v, d0, lambda) accumulate((v).begin(), (v).end(), d0, lambda)
#define SUM(v, d0) ACCUM(v, d0, [](auto a, auto b) {return a+b;})
#define ERASE(v, i) v.erase(v.begin() + i)
#define UNIQ(v) ASC(v);v.erase(unique(v.begin(), v.end()), v.end())

template <typename T>void debug(T t) {cerr << t << endl;}
template <typename T, typename ...Args>void debug(T t, Args ...args) {cerr << t << " ";debug(args...);}
template <typename T>void out(T t) {cout << t << endl;}
template <typename T, typename ...Args>void out(T t, Args ...args) {cout << t << " ";out(args...);}

void solve() {
    ll r, D, x;
    cin >> r >> D >> x;
    REP(i, 10) {
        x = r * x - D;
        out(x);
    }
}

int main() {
    fast_io;
    solve();
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

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

	vector<tuple<ll, ll, ll>> event;
	for(int i=0; i<n; i++){
		ll s, t, x;
		cin >> s >> t >> x;
		event.push_back(make_tuple(s-x, 0, x));
		event.push_back(make_tuple(t-x, -1, x));
	}
	for(int i=0; i<q; i++){
		ll d;
		cin >> d;
		event.push_back(make_tuple(d, 1, i));
	}
	sort(event.begin(), event.end());

	ll ans[q];
	multiset<ll> s;
	for(int i=0; i<event.size(); i++){
		ll x=get<0>(event[i]), y=get<1>(event[i]), z=get<2>(event[i]);
		if(y==0) s.insert(z);
		else if(y==-1) s.erase(z);
		else{
			if(s.empty()) ans[z]=-1;
			else ans[z]=*s.begin();
		}
	}
	for(int i=0; i<q; i++) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 28004
// https://atcoder.jp/contests/abc145/tasks/abc145_c

#include "algorithm"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

double dist(PL a, PL b) {
  return sqrt((b.first - a.first) * (b.first - a.first) +
              (b.second - a.second) * (b.second - a.second));
}

void solve() {
  ll N;
  cin >> N;
  VPL ps(N);

  rep(i, N) {
    ll x, y;
    cin >> x >> y;
    ps[i] = {x, y};
  }

  double distSum = 0;

  rep(j, N) rep(i, j) { distSum += dist(ps[i], ps[j]) * 2; }

  double res = distSum / N;

  cout << fixed << setprecision(10) << res << endl;
}

void solve2() {
  ll N;
  cin >> N;
  VPL ps(N);

  rep(i, N) {
    ll x, y;
    cin >> x >> y;
    ps[i] = {x, y};
  }

  sort(all(ps));

  long double distSum = 0;

  auto fact = [](ll a) {
    ll res = 1;
    rep(i, a) res *= i + 1;
    return res;
  };

  do {
    rep(i, N - 1) distSum += dist(ps[i], ps[i + 1]);
  } while (next_permutation(ps.begin(), ps.end()));

  long double res = distSum / fact(N);

  cout << fixed << setprecision(10) << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve2();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>

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

    ll n,m,q;
    cin>>n>>m>>q;
    ll l[m],r[m];
    vector<ll> ar[n+1];
    for(ll i=0;i<m;++i)
    {
        cin>>l[i]>>r[i];
        ar[l[i]].pb(r[i]);
    }
    for(int i=1;i<=n;++i)
    {
        sort(ar[i].begin(),ar[i].end());
    }
    while(q--)
    {
        ll ans=0;
        ll p,q;
        cin>>p>>q;
        for(ll i=p;i<=q;++i)
        {
            vector<ll> ::iterator it=upper_bound(ar[i].begin(),ar[i].end(),q);
            ans+=it-ar[i].begin();
        }
        cout<<ans<<endl;
    }

return(0);
}

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

// Bit Matrix
const int MAX_ROW = 110; // to be set appropriately
const int MAX_COL = 110000; // to be set appropriately
struct BitMatrix {
	int H, W;
	bitset<MAX_COL> val[MAX_ROW];
	BitMatrix(int m = 1, int n = 1) : H(m), W(n) {}
	inline bitset<MAX_COL>& operator [] (int i) { return val[i]; }
};

// 掃き出し法
void GaussJordan(BitMatrix &A, bool is_extended = false) {
	vector<bool> used(A.H, 0);
	for (int col = 0; col < A.W; ++col) {
		if (is_extended && col == A.W - 1) break;
		int pivot = -1;
		for (int row = 0; row < A.H; ++row) {
			if (used[row]) continue;
			if (A[row][col]) {
				pivot = row;
				break;
			}
		}
		if (pivot == -1) continue;
		for (int row = 0; row < A.H; ++row) {
			if (row != pivot && A[row][col]) A[row] ^= A[pivot];
		}
		used[pivot] = true;
	}
}

const int MD = 60;
int main() {
	int N; cin >> N;
	vector<long long> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];

	// 方程式を立てる
	long long res = 0;
	BitMatrix B(MD + 1, N + 1);
	vector<bool> cannot(MD + 1, false);
	for (long long d = MD; d >= 0; --d) {
		// d 桁目が 1 が何個か
		int num = 0;
		for (int i = 0; i < N; ++i) {
			if (A[i] & (1LL << d)) ++num;
		}
		if (num == 0) {
			cannot[d] = true;
			continue;
		}
		else if (1 == (num % 2)) {
			cannot[d] = true;
			res += (1LL << d);
			continue;
		}

		for (int i = 0; i < N; ++i) {
			if (A[i] & (1LL << d)) B[MD - d][i] = 1;
		}
		B[MD - d][N] = 1;
	}
	GaussJordan(B, true);

	// 集計
	for (int d = MD; d >= 0; --d) {
		if (cannot[d]) continue;

		// d 行目が (0 0 0 ... 0 | 1) だったらダメ
		bool ok = false;
		for (int i = 0; i < N; ++i) if (B[MD - d][i]) ok = true;
		if (!B[MD - d][N]) ok = true;

		// 結果に 2 × 2^d が寄与
		if (ok) res += (2LL << d);
	}
	cout << res << endl;
}

Measured memory_bytes: 5604
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            //var a = long.Parse(ReadLine());
            var s = ReadLine();
            var t = ReadLine();

            var count = 0;
            for(var i = 0; i < s.Length; i++)
            {
                if(s[i] != t[i])
                {
                    count++;
                }
            }
            
            WriteLine(count);
        }
    }
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

struct mintcomb{
    vector<mint> fact;
    vector<mint> ifact;
    mintcomb(ll n) : fact(n + 1, 1), ifact(n + 1, 1) {
        for(ll i = 2; i <= n; ++i){
            fact.at(i) = fact.at(i - 1) * i;
            ifact.at(i) = fact.at(i).inv();
        }
    }

    mint factorial(ll k) const { return fact.at(k); }
    mint combination(ll k, ll l) const {
        return fact.at(k) * ifact.at(l) * ifact.at(k - l);
    }
};

int main(){
    ll h, w, a, b;
    cin >> h >> w >> a >> b;

    mintcomb mc(h + w);

    mint ans = 0;
    REP(i, w - b){
        ans += mc.combination(b + i + h - a - 1, h - a - 1) *
            mc.combination(a - 1 + w - b - i - 1, a - 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define Sort(v, n) sort(v, v+n);
#define VSort(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define cY cout<<"Yes";
#define cN cout<<"No";
#define cA(a) cout<<a;
const ll MOD = 1000000007;


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

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(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 > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;

const ll maxn_bellmanford=2505;
vector<vll> G(maxn_bellmanford);
bool reachableFrom1[maxn_bellmanford];
void dfs(ll v){
  if(reachableFrom1[v]) return;
  reachableFrom1[v]=true;
  for(auto nv: G[v]){
    dfs(nv);
  }
}

vector<vll> rG(maxn_bellmanford);
bool reachableToN[maxn_bellmanford];
void rdfs(ll v){
  if(reachableToN[v]) return;
  reachableToN[v]=true;
  for(auto nv: rG[v]){
    rdfs(nv);
  }
}

ll n,m;
vector<tuple<ll,ll,ll>> es;
ll dist[maxn_bellmanford];
bool ok[maxn_bellmanford];

bool bellmanford(ll s){
  fill(dist,dist+n,INF);
  dist[s]=0;
  bool update=true;
  ll cnt=0;
  while(update){
    update=false;
    for(auto e: es){
      ll a,b,c;
      tie(a,b,c)=e;
      if(!ok[a]||!ok[b]) continue;
      if(chmin(dist[b],dist[a]+c)) update=true;
    }
    if(cnt>=n){
      return true;
    }
    cnt++;
  }
  return false;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>m;
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    a--,b--; c=-c;
    es.emplace_back(a,b,c);
    G[a].push_back(b);
    rG[b].push_back(a);
  }
  dfs(0);
  rdfs(n-1);
  rep(i,n) ok[i]=reachableFrom1[i] && reachableToN[i];
  if(bellmanford(0)){
    cout<<"inf"<<endl;
  }else{
    cout<<-dist[n-1]<<endl;
  }
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;
//set<int>::iterator it;



int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int n,k,i,f,l,ans=1000000000;
	cin>>n>>k;
	int x[n];
	for(i=0;i<n;i++)cin>>x[i];
	for(f=0;f<n-k+1;f++){
		l=f+k-1;
		int len=min(abs(x[f]),abs(x[l]))+abs(x[f]-x[l]);
		if(ans>len)ans=len;
//		cout<<x[f]<<" "<<x[l]<<" "<<abs(x[f]-x[l])<<" "<<len<<endl;
	}
	cout<<ans<<endl;
	
	
	
	
	
	
	return 0;
}


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

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

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

  ll ans = 0;
  vector<bool> used(n);
  vector<int> keep;
  for(int k=1; ; k++) {
    //debug(k);
    int a = n-1-k;
    int b = k;
    if (b >= a || b >= n) break;
    ll now = 0;
    //debug(a); debugln(b);
    now += vec[a];
    now += vec[b];
    used[a] = true;
    used[b] = true;
    keep.push_back(a);
    keep.push_back(b);
    chmax(ans, now);
    while(true) {
      a -= k;
      b += k;
      if (a==b || a <= k || b >= n || used[a] || used[b]) {
        break;
      }
      //debug(a); debugln(b);
      used[a] = true;
      used[b] = true;
      keep.push_back(a);
      keep.push_back(b);
      now += vec[a] + vec[b];
      chmax(ans, now);
    }
    for(auto e: keep) {
      //debugln(e);
      used[e] = false;
    }
    keep.clear();
  }
  cout << ans << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll f[100001],t[100001];
int main(){
    int n,d;
    cin>>n>>d;
    rep(i,n) cin>>t[i]>>f[i],--f[i];
    ll cnt=0,cur=0,ti=0;
    ll ans=0;
    rep(i,n){
        if(t[i]-ti<abs(f[i]-cur)||cnt==d&&t[i]-ti<cur+f[i]){
            cout<<-1<<endl;
            return 0;
        }
        else if(t[i]-ti>=cur+f[i]){
            ans+=cnt*cur;cur=f[i];ti=t[i];cnt=1;
        }
        else{
            ans+=cnt*(t[i]-ti);cur=f[i];ti=t[i];++cnt;
        }
    }
    ans+=cnt*f[n-1];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4644
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	long long a, b;
	cin >> a >> b;
	if (a > b)
		swap(a, b);
	if (a > 0 && b > 0)
		cout << "Positive\n";
	else if (a == 0 || b == 0)
		cout << "Zero\n";
	else if (a < 0 && b > 0)
		cout << "Zero\n";
	else if ((b - a + 1) % 2 == 0)
		cout << "Positive\n";
	else
		cout << "Negative\n";
endapp:
	//system("pause > nul");
	return 0;
}

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int diff_cnt = 0;
    REP(i, n) {
        int p;
        cin >> p;
        if (p != i + 1) diff_cnt++;
    }

    if (diff_cnt <= 2)
        cout << "YES" << ln;
    else
        cout << "NO" << ln;

    return 0;
}


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

string f(long long n){
	if(n == 0) return "";
	n--;
	return f(n/26) + string(1, 'a'+n%26);
}
int main(){
	long long n;
	cin >> n;
	cout << f(n) << endl;
	return 0;
}

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

int main(void){
  int n;
  cin >> n;
  string word[n];
  bool flag = true;

  for(int i = 0;i < n;i++){
    cin >> word[i];
    if(i != 0){
      char& before = word[i-1].at(word[i-1].length()- 1);
      char& latter = word[i].at(0);
      if(before != latter){
        //cout << "No" << endl;
        //return(1);
        flag = false;
      }
      for(int j = 0;j < i;j++){
        if(word[j] == word[i]){
          //cout << "No" << endl;
          //return(1);
          flag = false;
        }
      }
    }
  }
  if(flag == true) cout << "Yes" << endl;
  else cout << "No"<< endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <algorithm>
using namespace std;
typedef complex<double> Point;

namespace std {
	bool operator<(Point &a, Point &b) {
		return a.real() != b.real() ? a.real() < b.real() : a.imag() < b.imag();
	}
}

double cross(Point a, Point b) {
	return a.real() * b.imag() - a.imag() * b.real();
}

Point toV(Point a, Point b) {
	return b - a;
}

vector<Point> convex(vector<Point> &ps) {
	static Point stkLow[100000]; int spL = 0;
	static Point stkUp[100000]; int spU = 0;
	
	sort(ps.begin(), ps.end());
	for (int i = 0; i < ps.size(); i++) {
		while (spL >= 2) {
			Point a = toV(stkLow[spL - 2], stkLow[spL - 1]);
			Point b = toV(stkLow[spL - 1], ps[i]);
			if (cross(a, b) < 0) spL--;
			else break;
		}
		stkLow[spL++] = ps[i];
	}
	
	for (int i = (int)ps.size() - 1; i >= 0; i--) {
		while (spU >= 2) {
			Point a = toV(stkUp[spU - 2], stkUp[spU - 1]);
			Point b = toV(stkUp[spU - 1], ps[i]);
			if (cross(a, b) < 0) spU--;
			else break;
		}
		stkUp[spU++] = ps[i];
	}
	
	vector<Point> ret;
	for (int i = 0; i < spL; i++) ret.push_back(stkLow[i]);
	for (int i = 1; i < spU - 1; i++) ret.push_back(stkUp[i]);
	return ret;
}

int n;
vector<Point> ps;

int main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) {
		double x, y;
		cin >> x >> y;
		ps.push_back(Point(x, y));
	}
	
	ps = convex(ps);
	
	int m = ps.size();
	int start = 0;
	
	for (i = 0; i < m; i++) {
		if (ps[i].imag() < ps[start].imag() || (ps[i].imag() == ps[start].imag() && ps[i].real() < ps[start].real())) {
			start = i;
		}
	}
	
	cout << m << endl;
	for (i = 0; i < m; i++) {
		Point p = ps[(i + start) % m];
		cout << p.real() << " " << p.imag() << endl;
	}
	return 0;
}


Measured memory_bytes: 10148
/*
All the players, welcome to PC Koshien. The main election of PC Koshien will be held at Aizu University, and one team will be assigned to one desk in the hall. As PC Koshien has one team and two people, it requires a team number × 2 chairs. In the university, there are other opportunities to set up desks and chairs at various event venues, but the number of desks and chairs needed also varies. So, given the number of desks to prepare for an event and the number of chairs needed per desk, create a program to calculate the total number of chairs needed.
*/

macro_rules! input_vec {
    () => {
        input!()
            .split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };
    ($delimiter:expr) => {
        input!()
            .split($delimiter)
            .map(|x| x.parse().unwrap())
            .collect()
    };
}

macro_rules! input {
    () => {{
        let mut return_ = String::new();
        std::io::stdin().read_line(&mut return_).ok();
        return_.pop();
        return_
    }};
}

fn main() {
    let v: Vec<i32> = input_vec!();
    println!("{}", v[0] * v[1]);
}



Measured memory_bytes: 5036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>

void view(const std::vector<T> &v)
{
#ifndef ONLINE_JUDGE
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
#endif
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

const int INF = 1e9;
int main()
{
    int n, m;
    cin >> n >> m;
    vp a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    priority_queue<int> q;

    int ans = 0;
    rep(i, m)
    {
        auto idx = lower_bound(a.begin(), a.end(), P(i + 1, 0));
        while (idx != a.end() && (*(idx)).first <= i + 1)
        {
            q.push((*idx).second);
            idx++;
        }
        if (!q.empty())
        {
            int x = q.top();
            q.pop();
            ans += x;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()

int main(){
    cout << setprecision(20);

    string N;
    cin >> N;

    if(N.find_first_of("7")!=string::npos) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3628