akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

const MOD: usize = 1_000_000_007;
const MAX: usize = 510_000;
fn com_init(fac: &mut [usize], finv: &mut [usize], inv: &mut [usize]) {
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    finv[1] = 1;
    inv[1] = 1;
    for i in 2..MAX {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

fn bin_coef(n: usize, k: usize, fac: &mut [usize], finv: &mut [usize], inv: &mut [usize]) -> usize {
    if k > n/2 {
        bin_coef(n-k, k, fac, finv, inv)
    } else {
        fac[n] * (finv[k] * finv[n - k] % MOD) % MOD
    }
}


use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        A: usize,
        P: usize,
    }
    let p = A * 3 + P;
    println!("{}", p/2);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
//ダイクストラを空で書きたいあなたに
//離散的速度を例にとって...
const int MAX_C = 32;
const double INF = 1e9;

//頂点
struct node{

    int cur;
    int pre;
    int v;
    double t;

    node(int c, int p, int v, double t) : cur(c), pre(p), v(v), t(t){}
};

//比較演算子
bool operator < (const node &a, const node &b) { return a.t > b.t; }
bool operator > (const node &a, const node &b) { return a.t < b.t; }

struct edge{
    int to;
    double d;
    int c;
    edge(int t, double d, int c) : to(t), d(d), c(c){}
};

int main(){

    while(true){
        int n, m; cin >> n >> m;
        if(!n) break;
        int s, g; cin >> s >> g;
        vector<vector<edge> > adj(n + 1);
        
        for(int i = 0; i < m; i++){
            int x, y, c;
            double d;
            cin >> x >> y >> d >> c;
            adj[x].push_back(edge(y, d, c));
            adj[y].push_back(edge(x, d, c));
        }

        //cur, pre, v
        vector<vector<vector<double> > > result(n + 1, vector<vector<double> > (n + 1, vector<double> (MAX_C, INF)));
        priority_queue<node> pq;

        //スタート地点を追加
        //架空のスタート地点(s, 0, 0)
        result[s][0][0] = 0.0;
        pq.push(node(s, 0, 0, 0.0));

        while(!pq.empty()){

            node now = pq.top();
            pq.pop();
            
            if(result[now.cur][now.pre][now.v] > now.t) continue;

            //今いる頂点と隣接しているすべての頂点をなめる
            for(auto e : adj[now.cur]){
                for(int p = -1; p <= 1; p++){

                    if(now.v + p <= 0) continue;
                    if(e.to == now.pre) continue;
                    node next(e.to, now.cur, now.v + p, now.t + e.d / (double)(now.v + p));
                    if(next.v < 1 || e.c < next.v) continue;
                    
                    //現時点よりも安く到達できそうなら
                    if(result[next.cur][next.pre][next.v] > next.t){
                        result[next.cur][next.pre][next.v] = next.t;
                        pq.push(next);
                    }
                }
            }
        }

        double ans = INF;
        for(int i = 1; i <= n; i++) ans = min(ans, result[g][i][1]);
        if(abs(ans - INF) < 1e-9) printf("unreachable\n"); 
        else printf("%.10lf\n", ans);
    }

    return 0;
}


Measured memory_bytes: 3916
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,k = m()

po = [0 for i in range(n)]

for i in range(k):
    d = onem()
    a = l()
    for j in a:
        po[j-1] += 1

co = 0

for i in range(n):
    if po[i] == 0:
        co += 1
print(co) 

Measured memory_bytes: 68192
import sys

def main():
  input = sys.stdin.readline
  N, M = map(int, input().split())
  ans = 0
  if N < M:
    g = [int(a) for a in input().split()]
    g = sorted(g)
    L = g[:-1]
    R = g[1:]
    sub = [b - a for a, b in zip(L, R)]
    sub = sorted(sub)
    ans = sum(sub[:(M-N)])
  print(ans)


if __name__ == '__main__':
  main()

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

bool check[110];

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

	int x,n,p;
	int res = 1e9;
	int diff = 1e9;

	cin >> x >> n;

	memset(check,true,sizeof(check));
	for(int i=0;i<n;i++)
	{
		cin >> p;
		check[p] = false;
	}

	for(int i=0;i<110;i++)
	{
		if(check[i])
		{
			int d = abs(x - i);
			if(d < diff)
			{
				res = i;
				diff = d;
			}
		}
	}

	cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3620
package main

import "fmt"

func main() {
	var r, d, x2000 int
	fmt.Scan(&r, &d, &x2000)

	s := make([]int, 11)
	for i := range s {
		if i == 0 {
			s[i] = x2000
			continue
		}
		s[i] = r*s[i-1] - d
		fmt.Println(s[i])
	}
}


Measured memory_bytes: 512
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

const ll mod = 1e9+7;

ll modpow(ll x, ll n){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = (res * x) % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

vl f;

ll nckm(ll n, ll k){
    return (f[n] * modpow(f[n-k], mod-2) % mod) * modpow(f[k], mod-2) % mod;
}

int main(){
    ll N; cin >> N; ll NN = 3*N;
    vl A(NN); REP(i, NN) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());
    
    ll ans = 0;
    REP(i, N){
        ans += A[2*i+1];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
//#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  1000000007
#define MAXN 15000001
 //priority_queue<int, vector<int>, greater<int> > Q; 
//ll int a[1001][1001];
int main()
{//memset(,0,sizeof(m));
ios_base::sync_with_stdio(false);
 cin.tie(0);
 cout.tie(0);
 
    ll int n;
    cin>>n;
    vector<ll int > h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
     
    //cout<<endl;
    vector<ll int> v(n,0);
     
    for(int i=1;i<n;i++)
    {
       v[i]=INT_MAX;
       if(i-1>=0)
       {
           v[i]=min(v[i],v[i-1]+abs(h[i]-h[i-1]));
       }
       if(i-2>=0)
       {
             v[i]=min(v[i],v[i-2]+abs(h[i]-h[i-2]));
            
       }
    }
    
   cout<<v[n-1];
}


Measured memory_bytes: 1792
/* ex4_2
   kohei_suzuki */

#include <stdio.h>
#include <stdlib.h>
#define _USE_MATH_DEFINES
#include <math.h>

int main(void){
    double short_hand, long_hand, hour, min;
    double angle, ans;

    scanf("%lf %lf %lf %lf",&short_hand, &long_hand, &hour, &min);
    angle = fabs(hour*30.0 + min/2.0 - min*6.0) / 180.0 * M_PI;

    ans = sqrt(pow(short_hand ,2.0)+ pow(long_hand, 2.0) - 2 * short_hand * long_hand * cos(angle));

    printf("%.9f\n",ans);
    return 0;
}

Measured memory_bytes: 2588
fun main(args: Array<String>) {
    readLine()
    val lines = readLine()!!.split(" ").map { it.toInt() }.sorted().reversed()

    var answer = 0
    for (long_i in 0..(lines.size - 3)){
        for (middle_i in (long_i + 1)..(lines.size - 2)){
            var top = lines.size - 1
            var bottom = middle_i
            var middle = 0
            while (top > bottom + 1) {
                middle = (top + bottom) / 2
                if (lines[long_i] < lines[middle_i] + lines[middle]){
                    bottom = middle
                } else {
                    top = middle
                }
            }
            answer += (bottom - middle_i)
            if (lines[long_i] < lines[middle_i] + lines.last()){
                answer += 1
            }
        }
    }
    println(answer)
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  REP(i,3){
    string s;
    cin>>s;
    cout<<s[0];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        int K;
        String str;
        String[] A = new String[2];
        String ans = "NG";
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        K = Integer.parseInt(r.readLine());
        str = r.readLine();
        A = (str.split(" "));
        for(int i=1;i*K <= Integer.parseInt(A[1]);i++){
            if(Integer.parseInt(A[0]) <= i*K && i*K <= Integer.parseInt(A[1])){
                ans="OK";
                continue;
            }
        }
        System.out.println(ans);
    }
}

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

using namespace std;

int main() {
	int N, M, C,ans = 0;
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int i = 0; i < M; i++) {
		cin >> B.at(i);
	}
	vector<vector<int>> A(N,vector<int>(M));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			cin >> A.at(i).at(j);
		}
	}
	for (int i = 0; i < N; i++) {
		int tmp = 0;
		for (int j = 0; j < M; j++) {
			tmp += B.at(j) * A.at(i).at(j);
			if (j + 1 == M) {
				if ((tmp + C) > 0) {
					ans++;
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 2048
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
typedef long double ld;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


typedef vector<ll> vcL;
typedef vector<vcL> vvL;
const ll mod = 1e9 + 7;
ll X[maxn], Y[maxn];
//ll dp[maxn][maxn];
ll n, m;


void solve()
{
    //vvL dp( n+1, vcL( m+1, 1 ) );
    vector<vector<ll> > dp(n+1, vector<ll> (m+1, 1));
    for(ll i = 1; i <= n; i++){
        for(ll j = 1; j <= m; j++){
            dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
            if(X[i] == Y[j]) dp[i][j] += dp[i - 1][j - 1];
            dp[i][j] = (dp[i][j] + 10 * mod) % mod;

        }
    }
    cout << dp[n][m]<< "\n";
}


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    cin >> n >> m;
    for(ll i = 1; i <= n; i++) cin >> X[i];

    for(ll i = 1; i <= m; i++) cin >> Y[i];
    //memset(dp, 0, sizeof dp);
   // dp[0][0] = 1;
    solve();
    //double end_time = clock();
    //prllf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);

    return 0;
}


Measured memory_bytes: 31616
n = int(input())
a = list(map(int,input().split()))
ans = []
if n % 2 == 0:
    for i in range(n-1,0,-2):
        ans.append(a[i])
    for i in range(0,n,2):
        ans.append(a[i])
else:
    for i in range(n-1,-1,-2):
        ans.append(a[i])
    for i in range(1,n,2):
        ans.append(a[i])
print(' '.join([str(i) for i in ans]))


Measured memory_bytes: 121556
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int main(){
  ll k;
  cin >> k;
  string s;
  cin >> s;
  string a;
  
  for(int i=0; i<k; i++){
    a+=s[i];
  }
  ll x = s.size();
  if(x>k)a+="...";
  if(x<=k) cout << s;
  else cout << a << endl;
  
  
  
}
  
  
  
  


Measured memory_bytes: 3624
#include <stdio.h>

int main(void)
{
	int num;
	int a[20], v[20] = {0};
	int n, f;
	int max_num, max;
	
	scanf("%d", &num);
	while (scanf("%d %d", &n, &f) != EOF){
		v[n - 1] += f;
	}
	max = -1;
	for (n = 0; n < num; n++){
		if (max < v[n]){
			max_num = n + 1;
			max = v[n];
		}
	}
	printf("%d %d\n", max_num, max);
	
	return 0;
}

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

int main() {
	string A,B;
	cin>>A>>B;
	string ans="EQUAL";
	if(!(A==B)){
		if(A.size()==B.size()){
			if(A>B)ans="GREATER";
			else ans="LESS";
		}
		else{
			if(A.size()>B.size())ans="GREATER";
			else ans="LESS";
		}
	}
	cout<<ans<<endl;
}

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

using namespace std;
using ll = long long int;

int main(void) {
    cout << fixed << setprecision(16);

    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> v(n);
    for(auto &e: v) cin >> e;
    sort(v.begin(), v.end(), greater<>());
    ll ca = 0, cb = 0;
    ll x = v[a-1];
    for(ll i=0; i<a; i++)
        if(v[i] == x) ca++;
    for(ll i=a; i<n; i++)
        if(v[i] == x) cb++;

    double s = 1.0 * accumulate(v.begin(), v.begin()+a, 0ll) / a;
    cout << s << endl;

    if(v[0] == v[a-1]) {
        ll r = 0;
        for(ll k=a; k<=b; k++) {
            ll t = 1;
            // ca+cb C k
            for(ll i=0; i<k; i++)
                t *= ca+cb-i, t /= i+1;
            r += t;
        }
        cout << r << endl;
    } else {
        ll t = 1;
        // ca+cb C ca
        for(ll i=0; i<ca; i++)
            t *= ca+cb-i, t /= i+1;
        cout << t << endl;
    }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void dfs(vector<vector<int>>& a,int curr,vector<int> &vis,stack<int> &s)
{
    vis[curr]=1;
    for(int i=0;i<a[curr].size();i++)
    {
        if(vis[a[curr][i]]==0)
        {
            dfs(a,a[curr][i],vis,s);
        }
    }
    s.push(curr);
}
int main() 
{

    int n,m,maxi=0;
    cin>>n>>m;
    vector<int> indeg(n+1,0);
    vector<int> outdeg(n+1,0);
    vector<vector<int>> a(n+1);
    int z,x;
    for(int i=0;i<m;i++)
    {
        cin>>z>>x;
        a[z].push_back(x);
 
    }
    vector<int> vis(n+1,0);
    stack<int> stk;
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0) dfs(a,i,vis,stk);
    }
    vector<int> ans(n+1,0);
    while(!stk.empty())
    {
        int x=stk.top();
        stk.pop();
        for(int i=0;i<a[x].size();i++)
        {
            ans[a[x][i]]=max(ans[a[x][i]],ans[x]+1);
            maxi=max(maxi,ans[a[x][i]]);
        }
    }
    cout<< maxi;
}

Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int selectionSort(int A[], int n) {
    int cnt = 0;

    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (A[j] < A[minj])
                minj = j;
        }
        if (i != minj)
            swap(A[i], A[minj]), cnt++;
    }
    return cnt;
}
int main() {
    int n, A[110];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &A[i]);

    int cnt = selectionSort(A, n);
    for (int i = 0; i < n; i++)
        printf("%d%c", A[i], i == n - 1 ? '\n' : ' ');
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
ll MOD = 1e9+7;
ll add(ll &a, ll b)
{
    a = (a+b) % MOD;
}
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> s(n);
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    if(a > b) swap(a, b);
    for(int i = 0; i < n-2; i++)
    {
        if(s[i] + a > s[i+2])
        {
            cout << 0 << endl;
            return 0;
        }
    }
    vector<int> rx(n); // 連続して同居できる一番右の位置
    vector<int> ry(n); 
    rx[n-1] = n-1;
    ry[n-1] = n-1;
    for(int i = n-2; i >= 0; i--)
    {
        if(s[i+1] - s[i] >= a) rx[i] = rx[i+1];
        else rx[i] = i;
        if(s[i+1] - s[i] >= b) ry[i] = ry[i+1];
        else ry[i] = i;
    }
    vector<ll> x(n);
    vector<ll> y(n);
    x[0] = 1;
    y[0] = 1;
    for(ll i = 0; i < n-1; i++)
    {
        if(s[i+1] - s[i] >= a)
        {
            add(x[i+1], x[i]);
        }
        // xでs[i]と同居できない一番右の位置
        ll pos = lower_bound(s.begin(), s.end(), s[i]+a) - s.begin() - 1;
        pos = max(pos, i+1);
        // i+1 ~ posまでyに含まれることが可能か
        if(ry[i+1] >= pos) add(y[pos], x[i]);
      
        if(s[i+1] - s[i] >= b)
        {
            add(y[i+1], y[i]);
        }
        pos = lower_bound(s.begin(), s.end(), s[i]+b) - s.begin() - 1;
        pos = max(pos, i+1);
        if(rx[i+1] >= pos) add(x[pos], y[i]);
    }
    ll ans = 0;
    add(ans, x[n-1]);
    add(ans, y[n-1]);
    add(ans, MOD);
    cout << ans << endl;
}

Measured memory_bytes: 3328
from sys import stdin

def main():
  def find(parent, i):
    t = parent[i]
    if t == -1:
      return i
    t = find(parent, t)
    parent[i] = t
    return t

  def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
      return
    parent[i] = j

  from builtins import int, map, range
  readline = stdin.readline

  n, k, l = map(int, readline().split())

  roads = [-1] * n
  rails = [-1] * n

  for i in range(k):
    p, q = map(int, readline().split())
    unite(roads, p - 1, q - 1)

  for i in range(l):
    p, q = map(int, readline().split())
    unite(rails, p - 1, q - 1)

  d = {}
  for i in range(n):
    t = (find(roads, i), find(rails, i))
    if t in d:
      d[t] += 1
    else:
      d[t] = 1

  print(*[d[(find(roads, i), find(rails, i))] for i in range(n)])

main()


Measured memory_bytes: 41188
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;

int main(){
	int a, b;
	cin >> a >> b;
	if(a+b==15) cout << "+" <<endl;
	else if(a*b==15) cout << "*" << endl;
	else cout << "x" << endl;


	return 0;
}


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

using namespace std;

int solve(int N, vector<int> &cnt)
{
    if (cnt[0] == N) return 1;

    int res = 0, p = (cnt[1] > cnt[2] ? 1 : 2);
    cnt[p]--;
        
    while (1) {
        res++;
        if (p == 0) {
            break;
        } else if (p == 1) {
            if (cnt[1] > 0) {
                cnt[1]--;
                p = 2;
            } else if (cnt[0] > 0) {
                cnt[0]--;
                p = 1;
            } else {
                p = 0;
                if (cnt[2] == 0) {
                    break;
                }
            }                
        } else {
            if (cnt[2] > 0) {
                cnt[2]--;
                p = 1;
            } else if (cnt[0] > 0) {
                cnt[0]--;
                p = 2;
            } else {
                p = 0;
                if (cnt[1] == 0) {
                    break;
                }
            }
        }
    }
    return res;
}

int main()
{
    int N;
    cin >> N;
    int a;
    vector<int> cnt(3, 0);
    for (int i = 0; i < N; i++) {
        cin >> a;
        cnt[a%3]++;
    }

    cout << solve(N, cnt) << endl;
    return 0;
}

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

blues = []
reds = []

count = []
for i in range(n):
    count.append(0)
max_count = 0

for i in range(n):
    p = input()
    blues.append(p)

v = input()
m = int(v)

for i in range(m):
    q = input()
    reds.append(q)

for i in range(len(blues)):
    for j in range(len(blues)):
        if blues[i] == blues[j]:
            count[i] += 1

for i in range(len(blues)):
    for j in range(len(reds)):
        if blues[i] == reds[j]:
            count[i] -= 1

for i in range(len(count)):
    max_count = max(max_count, count[i])

print(max_count)
        


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

int main(){
	long long int h,w,a,b;
	long long int ans,M,m,X,Y,Z;
	cin>>h>>w;
	if(h*w%3==0){
		cout<<0<<endl;
		return 0;
	}
	ans=min(h,w);
	for(int k=0;k<2;++k){
		for(int i=0;i<=1;++i){
			for(int j=0;j<=1;++j){
				a=w/3+i;b=h/2+j;
				X=a*h;
				Y=b*(w-a);
				Z=(w-a)*(h-b);
				M=max(X,Y);
				M=max(M,Z);
				m=min(X,Y);
				m=min(m,Z);
				ans=min(ans,M-m);
				
			}
		}
		swap(h,w);
	}
	cout<<ans<<endl;
}

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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  rep(i, N){
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  //rep(i, N)    cout << p[i];

  int sum =0;
  rep(i, K){
    sum += p[i];
  }
  cout << sum;
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int k; cin >> k;
   int x = 0, y = 7;
   rep(i,k){
      y %= k;
      x += y;
      x %= k;
      if(x==0){
         cout << i+1 << endl;
         return 0;
      }
      y *= 10;
   }
   cout << -1 << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	int p, q, r;
	cin >> p >> q >> r;
    int ans = min(p+q, min(q+r, r+p));
	cout << ans << endl;
	return 0;
}


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

typedef long long ll;

int main(){
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  ll mx = 0;
  
  for ( ll i = 0; i < n; i++ ){
    cin >> a[i];
    mx = mx > a[i] ? mx : a[i];
  }
  
  ll ind = 0;
  vector<ll> b;
  
  int flg = 0;
  
  for ( ll i = 0; i < n; i++){
    if (a[i] == mx && flg == 0){

      flg = 1;
      ind = i;
      continue;
    }
    b.push_back(a[i]);
  }
  
  sort(b.begin(), b.end());
  
  for ( ll i = 0 ; i < n; i++ ){
    if ( i == ind )
      cout << b[n-2] << endl;
      
    else
      cout << mx << endl;
  }
  
}

Measured memory_bytes: 4848
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
import math
from functools import reduce

n = int(readline())
a = list(map(int,readline().split()))

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

x = reduce(lcm, a)

ans = 0
for i in range(n):
    ans += x // a[i]

print(ans%1000000007)

Measured memory_bytes: 75820
def ceil_log2(n):
    i = 0
    while (1 << i) < n:
        i += 1
    return i


class SegmentTree:
    def __init__(self, values, e, op):
        if type(values) == int:
            values = [e] * values

        self._n = len(values)
        self._ceil_log2_n = ceil_log2(self._n)
        self._size = 1 << self._ceil_log2_n

        self._e = e

        self._op = op

        self._nodes = [e] * (2 * self._size)
        for i, value in enumerate(values):
            self._nodes[self._size + i] = value

        for i in range(self._size - 1, 0, -1):
            self._update(i)

    def set(self, index, value):
        self._nodes[self._size + index] = value
        for i in range(1, self._ceil_log2_n + 1):
            self._update((self._size + index) >> i)

    def get(self, index):
        return self._nodes[self._size + index]

    def all_prod(self):
        return self._nodes[1]

    def prod(self, left, right):
        if left == right:
            return self._e

        if left == 0 and right == self._n:
            return self.all_prod()

        left_prod = self._e
        right_prod = self._e

        left += self._size
        right += self._size

        while left < right:
            if left & 1:
                left_prod = self._op(left_prod, self._nodes[left])
                left += 1

            if right & 1:
                right -= 1
                right_prod = self._op(self._nodes[right], right_prod)

            left >>= 1
            right >>= 1

        return self._op(left_prod, right_prod)

    def _update(self, index):
        self._nodes[index] = self._op(self._nodes[2 * index], self._nodes[2 * index + 1])


def main():
    n, k = map(int, input().split())
    arr = [int(input()) for _ in range(n)]

    overall_max_len = 0
    seg = SegmentTree(3 * 10 ** 5 + 1, 0, max)

    for value in arr:
        max_len = seg.prod(max(0, value - k), min(3 * 10 ** 5 + 1, value + k + 1)) + 1
        seg.set(value, max_len)
        overall_max_len = max(overall_max_len, max_len)

    print(overall_max_len)


main()


Measured memory_bytes: 102716
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 5010;
const int MOD = 1000000007;
const int INF = 1000000000;

int n;
vector<int> v[MAXN];
int size[MAXN];

ll F[MAXN][MAXN][2];
ll tmp[MAXN][2];

ll g[MAXN];

void dfs(int x, int p)
{
	size[x] = 1;
	F[x][1][0] = 1;
	for (auto y : v[x])
	{
		if (y == p) continue;
		dfs(y, x);
		size[x] += size[y];
		for (int i = 1; i <= size[x]; ++ i)
			tmp[i][0] = tmp[i][1] = 0;
		for (int i = 1; i <= size[x]-size[y]; ++ i) for (int s = 0; s < 2; ++ s)
			for (int j = 1; j <= size[y]; ++ j) for (int t = 0; t < 2; ++ t)
			{
				(tmp[i+j][s^t] += F[x][i][s]*F[y][j][t]) %= MOD;
				(tmp[i][s^t^1] += F[x][i][s]*F[y][j][t]%MOD*g[j]) %= MOD;
			}
		for (int i = 1; i <= size[x]; ++ i)
		{
			F[x][i][0] = tmp[i][0];
			F[x][i][1] = tmp[i][1];
		}
	}
}

int main()
{
	
	n = inp();
	g[0] = 1;
	for (int i = 2; i <= n; i += 2)
		g[i] = g[i-2]*(i-1)%MOD;
	for (int i = 1; i < n; ++ i)
	{
		int x = inp();
		int y = inp();
		v[x].push_back(y);
		v[y].push_back(x);
	}
	dfs(1, 0);
	ll ans = g[n];
	for (int i = 1; i < n; ++ i)
	{
		(ans += (F[1][i][0]-F[1][i][1])*g[i]) %= MOD;
	}
	cout << (ans+MOD)%MOD << endl;
	
	return 0;
}


Measured memory_bytes: 393344
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int w,h,n;cin>>w>>h>>n;
  vector<int>lrdu(4);
  lrdu[0]=0;
  lrdu[1]=w;
  lrdu[2]=0;
  lrdu[3]=h;
  rep(i,n){
    int x,y,a;
    cin>>x>>y>>a;
    a--;
    if(a==0){
      chmax(lrdu[0],x);
    }
    else if(a==1){
      chmin(lrdu[1],x);
    }
    else if(a==2){
      chmax(lrdu[2],y);
    }
    else if(a==3){
      chmin(lrdu[3],y);
    }
  }
  int res=max(lrdu[1]-lrdu[0],0)*max(lrdu[3]-lrdu[2],0);
  cout<<res<<endl;

  return 0;

}


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

int main() {
  int N;
  cin >> N;
  vector<int> V = vector<int>(N);
  for (int i = 0; i < N; i++) {
    int val;
    cin >> val;
    V[i] = val;
  }
  
  sort(V.begin(), V.end());
  double ans = (double)V[0];
  for (vector<int>::iterator it = ++V.begin(); it != V.end(); ++it) {
    int a = *it;
    ans = (ans + a) / 2.0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
s = input()

x = [list(map(int,bin(x)[2:].zfill(len(s)-1))) for x in range(2**(len(s)-1))]
ans = 0
sp1 = 0
sp2 = 0
for i in range(len(x)):
    for j in range(len(s)-1):
        if x[i][j]==1:
            sp1 = j+1
            ans += int(s[sp2:sp1])
            sp2 = sp1
    sp2=0
    ans += int(s[sp1:])
print(ans)

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

int main() {

int n ;
cin >> n;
vector<int> value(n);
vector<int> cost(n);

for(int i=0;i < n ; i ++){
cin >> value[i];
}
for ( int i = 0 ; i < n ; i++ ) {
cin >> cost[i] ;
}

int x  , y ;
x=0;
y=0;
for ( int i = 0; i < n ; i++ ){
if ( value[i] > cost[i]){
x += value[i];
y += cost[i];
}
}
cout << x - y <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if(n%2 == 0)
    cout << 0.5 << endl;
  else
    cout << ((double)(n/2+1)/(double)n) << endl; 
  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

int main()
{
    int N;
    int D;
    int range = 0;
    int ans = 0;

    cin >> N >> D;
    while (range < N)
    {
        range += D * 2 + 1;
        ans++;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define N 500000
typedef long long ll;
using namespace std;
int n,ans,sum;
int a[N],b[N],c[N];
int f=0;
int main()
{
    a[0]=b[0]=c[0]=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        ans=a[i]-a[i-1];
        sum=abs(b[i]-b[i-1])+abs(c[i]-c[i-1]);
        if(ans<sum||(ans-sum)%2!=0)
            f=1;
    }
    if(f)
        printf("No\n");
    else
        printf("Yes\n");
}



Measured memory_bytes: 2944
n = int(input())
l = list(map(int, input().split()))
l = sorted(l, reverse = 1)


if n % 2 == 0:
    print(l[0] + sum(l[1:1+(n-2)//2])*2)
else:
    print(l[0] + sum(l[1:1+(n-2)//2])*2 + l[1+(n-2)//2])
    






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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
	int N; cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    int sum = 0;
    rep(i, N) sum += a[i];
    int mi = INT_MAX, i0;
    rep(i, N) {
        int d = abs(N * a[i] - sum);
        if (d < mi) {
            mi = d;
            i0 = i;
        }
    }
    cout << i0 << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    while(cin>>n,n){
        
        vector<pair<pii, pii>>v;
        rep(_,n){
        int i,p,q,r; cin>>i>>p>>q>>r;
        v.push_back(pair<pii, pii>(pii(i,p),pii(q,r)));
        }
        vi ans;
        int rize,syaro,tiya,kokoa; cin>>rize>>syaro>>tiya>>kokoa;
        rep(i,n){
            if(v[i].first.second<=rize && v[i].second.first<=syaro&&v[i].second.second<=tiya &&
               v[i].first.second*4+v[i].second.first*9+v[i].second.second*4<=kokoa)
                ans.push_back(v[i].first.first);
        }
        if(ans.size()==0){cout<<"NA"<<endl; continue;}
        else rep(i,ans.size())cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
*/

int main(){
cout<<fixed<<setprecision(10);

ll N;cin>>N;
  vector<int> vec(N);
  vector<int> vecS(N);
  for(int i=0;i<N;i++){
    cin>>vec[i];
    vecS[i]=vec[i];
  }

  vsort(vecS);
  int A=N/2;
  int X=vecS[A-1];
  int Y=vecS[A];
  for(int i=0;i<N;i++){
    if(vec[i]<=X){
      cout<<Y<<endl;
    }else{
      cout<<X<<endl;
    }
      

  }
  
}




Measured memory_bytes: 3712
#include <iostream>
#include <vector>
using namespace std;
template <class T>
istream& operator>>(istream& input, vector<T>& v) {
    for (T& i : v) input >> i;
    return input;
}
template <class T>
ostream& operator<<(ostream& output, const vector<T>& v) {
    for (auto itr = v.begin(); itr != v.end() - 1; ++itr)
        output << *itr << " ";
    output << v.back();
    return output;
}
int main() {
    int N, cnt = 0;
    cin >> N;
    vector<int> a(N), b(N, 0), ans;
    cin >> a;
    for (int i = N - 1; i >= 0; i--) {
        int tmp = 0;
        for (int j = 2 * i + 1; j < N; j += i + 1) tmp += b[j];
        b[i] = (tmp & 1) != a[i];
        if (b[i]) {
            cnt++;
            ans.push_back(i + 1);
        }
    }
    cout << cnt << endl;
    if (cnt) cout << ans << endl;
}

Measured memory_bytes: 3064
n,m=gets.split(" ").map(&:to_i)
pairs = []
while line=gets
  break if line.chomp.empty?
  pairs<<line.split(" ").map(&:to_i)
end

def qsort(arr)
  return arr if arr.length <= 1
  pivot = arr.pop
  left, right = arr.partition{|elm| elm[1] < pivot[1] }
  qsort(left) + [pivot] + qsort(right)
end

ok = []
tmp = 0
pairs.sort{|a,b| a[1] <=> b[1] }.each do |a, b|
  # 最西の島が最東の島よりも西にあること
  if a >= tmp
    tmp = b
    ok << [a,b]
  end
end

p ok.length

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

int main(){
    stack<char> st;
    string s;
    cin >> s;
    for(auto ss : s){
        if(ss == 'B' && !st.empty()) st.pop();
        else if(ss != 'B') st.push(ss);
    }
    string ans;
    while(!st.empty()){
        ans.push_back(st.top());
        st.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		for(char c = 'a'; c <= 'z'; c++) {
			if(s.indexOf(c) == -1) {
				System.out.println(c);
				return;
			}
		}
		System.out.println("None");
	}

}


Measured memory_bytes: 24220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int fly[]={4,1,4,1,2,1,2,1},peo[8],remainder,point=0;
    while(cin>>peo[0]){
        for(int i=1;i<8;i++)cin>>peo[i];
        for(int i=0;i<8;i++){
            int num=0;
            for(int j=0;j<8;j++)if(fly[(i+j)%8]<peo[j])num+=peo[j]-fly[(i+j)%8];
            if(remainder>num||i==0){
                remainder=num;
                point=i;
            }
            else if(remainder==num){
                for(int j=0;j<8&&fly[(i+j)%8]<=fly[(point+j)%8];j++){
                    if(fly[(i+j)%8]<fly[(point+j)%8]){
                        point=i;
                        break;
                        }
                    }
                }
        }
        for(int i=0;i<7;i++)cout<<fly[(point+i)%8]<<" ";
            cout<<fly[(point+7)%8]<<endl;
    }
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <climits>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <=d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
stores = sorted([[int(i) for i in input().split()] for j in range(n)], key=lambda x: x[0])
sum = 0
for store in stores:
    price, cans = store
    sum += min(cans, m) * price
    m -= min(cans, m)
    if m == 0:
        break
print(sum)

Measured memory_bytes: 23524
#include <stdio.h>

int main(void) {
    int H;
    int W;
    int i;
    int n;
    while(1){
        scanf("%d%d",&H,&W);
        if(H==0 || W==0) break;
        for(i=1;i<=H;i++){
            for(n=1;n<=W;n++){
                if((i==1 || i ==H) || (n==1 || n==W)){
                    printf("#");
                }else{
                    printf(".");
                }
            }
                printf("\n");
        }
        printf("\n");
    }
   
	return 0;
}




Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

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

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    m1 += h1 * 60;
    m2 += h2 * 60;

    cout << max(0, (m2 - m1 - k));

    return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll sum = 0;
    rep(i, N) {
        if(i % 2 == 0) {
            sum += 2 * A[i];
        } else {
            sum -= 2 * A[i];
        }
    }
    vector<ll> res(N);
    res[0] = sum / 2;
    for(int i = 1; i < N; i++) {
        res[i] = 2 * (A[i - 1] - res[i - 1] / 2);
    }
    rep(i, N) { cout << res[i] << (i == N - 1 ? "\n" : " "); }
    return 0;
}

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

using namespace std;

#define FOR(i, n) for(int i = 0; i < (int) n; i++)
#define all(x) x.begin(), x.end()
#define PB push_back
#define F first
#define S second

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

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

	int v[3][3];
	FOR(i, 3) FOR(j, 3) cin >> v[i][j];
	int n; cin >> n;
	set<int> m;
	FOR(i, n){
		int x; cin >> x;
		FOR(j, 3) FOR(k, 3) 
			if(x == v[j][k])
				v[j][k] = -1;
	}

	//linha
	FOR(i, 3){
		int cnt = 0;
		FOR(j, 3) if(v[i][j] == -1) cnt++;
		if(cnt == 3){
			cout << "Yes\n";
			return 0;
		}
	}

	//coluna
	FOR(i, 3){
		int cnt = 0;
		FOR(j, 3) if(v[j][i] == -1) cnt++;
		if(cnt == 3){
			cout << "Yes\n";
			return 0;
		}
	}

	int cnt = 0;
	FOR(i, 3){
		if(v[i][i] == -1) cnt++;
	}
	if(cnt == 3){
		cout << "Yes\n";
		return 0;
	}

	cnt=0;
	FOR(i, 3){
		if(v[i][2-i] == -1)cnt++;
	}

	if(cnt == 3){
		cout << "Yes\n";
		return 0;
	}

	cout << "No\n";

	return 0;
}

Measured memory_bytes: 256