akhauriyash/Code-Regression huggingface dataset:
N, W = map(int, input().split())
wv = [[0, 0]]
for _ in range(N):
    w, v = map(int, input().split())
    wv.append([w, v])


# dp[i][j]=(i番目までの品物を、価値がj以上になるように選んだときの最小重さ)
# N<=100, v_i<=1000 なので、価値の総和<=100000
dp = [[10**12 for _ in range(100001)] for _ in range(N + 1)]
dp[0][0] = 0
# print(dp)
for i in range(1, N + 1):
    for j in range(0, 100001):
        # i番目のアイテムを入れることができる場合
        if j - wv[i][1] >= 0:
            # i番目のアイテムを入れない場合、入れる場合
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - wv[i][1]] + wv[i][0])
        # i番目のアイテムを入れることができない場合
        else:
            dp[i][j] = dp[i - 1][j]

# 1<= 価値の総和 <=100000
# 100000から降順に、本当にナップサックに入るのか確かめる
ans = 100000
while(dp[N][ans] > W):
    ans -= 1

# print(dp)
print(ans)


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

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

using namespace std;

int main() {
  int N,D;
  string X;
  cin >> N >> X >> D;
  string Y = X;
  int remain = D;
  rep(i,(int)Y.size()) {
    if( remain == 0 ) break;
    if( Y[i] == '0' ) Y[i] = '1', --remain;
  }
  rep(j,(int)Y.size()) {
    if( remain == 0 ) break;
    int i = (int)Y.size() - 1 - j;
    if( X[i] == Y[i] ) Y[i] = ((Y[i]=='0')?'1':'0'), --remain;
  }
  assert( remain == 0 );
  cout << Y << endl;
  return 0;
}

Measured memory_bytes: 3192
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int mod = 1000000007;
const int INF = 1 << 30;
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define vin(v,n) rep(i,n)cin>>v[i];
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define sz size()
#define fi first
#define se second
#define pb push_back
#define prquete priority_queue<ll,vector<ll>,greater<ll>>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
int main() {
	ll a, b, c, k,sum=0,mx;
	cin >> a >> b >> c >> k;
	sum += a + b + c;
	mx = max({ a,b,c });
	sum -= mx;
	rep(i, k)mx *= 2;
	sum += mx;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n");
    println(solve(input).trim());
  }

  def solve(input:String):String={
    if(input.split("\n")(1).split(" ").contains("Y")){
      "Four"
    }else{
      "Three"
    }
  }
}


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

long long N, K, C;
string S;
long long head[200005];
long long tail[200005];

int main(){
	cin >> N >> K >> C >> S;

	long long last = LONG_MIN;
	long long idx = 1;
	for(long long i = 0; i < N; i++) {
		if(S[i] == 'o' && i > last + C) {
			last = i;
			head[i] = idx;
			idx++;
		}
	}

	//if(idx > K + 1) {
	//	return 0;
	//}

	last = LONG_MAX;
	idx = K;
	for(long long i = N-1; i >= 0; i--) {
		if(S[i] == 'o' && last > i + C) {
			last = i;
			tail[i] = idx;
			idx--;
		}
	}


	//for(long long i = 0; i < N; i++) {
	//	cout << "head[" << i << "] = " << head[i] << endl;
	//}

	//for(long long i = 0; i < N; i++) {
	//	cout << "tail[" << i << "] = " << tail[i] << endl;
	//}

	for(long long i = 0; i < N; i++) {
		if(head[i] != 0 && head[i] == tail[i]) {
			cout << i + 1 << endl;
		}
	}



}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353
#define Graph vector<vector<int>>

int main() {
    int X, N; cin >> X >> N;
    set<int> p;
    for (int i = 0; i < N; i++) {
        int q; cin >> q;
        p.insert(q);
    }
    int m = inf, hoji = inf;
    int ans = 0;
    for (int i = -200; i <= 200; i++) {
        if (p.count(i)) {
        }
        else {
            m = min(m, abs(i - X));
            if (m == abs(i - X)) {
                if (hoji == inf) {
                    ans = i;
                    hoji = abs(i - X);
                }
                else if (abs(i - X) != hoji) {
                    ans = i;
                    hoji = abs(i - X);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
  int r,D,x;
  cin>>r>>D>>x;
  int cnt=0;
  while(cnt<10){
      x=r*x-D;
      cout<<x<<endl;
      cnt++;
  }
  
  
}

Measured memory_bytes: 3604
#include <stdio.h>
#include <math.h>

void merge(int [],int,int,int); //??¨??????????????±???
void mergeSort(int [],int,int); //2????????¨?????????????????????????????????

int cnt=0;
int L[250000+2],R[250000+2];

int main()
{
  int i,n,left,right;
  int A[500000];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  left=0;
  right=n;

  mergeSort(A,left,right);

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

  return 0;
}

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

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

  for(i=0;i<=n2-1;i++){
    R[i]=A[mid+i];
  }

  L[n1]=2000000000;
  R[n2]=2000000000;
  i=0;
  j=0;

  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }else{
      A[k]=R[j];
      j=j+1;
    }
    cnt++;
  }
}

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

int main(void)
{
    int N,A[210];
    int cnt = 0;
    cin >> N;
    for(int i =0; i < N; i++) cin >> A[i];

    bool isExistOdd = false; 

    while(true)
    {
        for(int i = 0; i < N; i++) 
        {
            if(A[i] % 2 != 0) isExistOdd = true;
        }

        if(isExistOdd) break;
        
        for(int i = 0; i < N; i++)
        {
            A[i] /= 2;
        }
        cnt++;
    } 
    cout << cnt << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#define REP(i, a, n) for(int i = a; i < n; i++)
using namespace std;


int N, a[200000], p[200001];
set<int> s;
long sum;

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> a[i];

  REP(i, 0, N) {
    p[a[i]] = i + 1;
  }

  sum = 0;
  s.insert(0);
  s.insert(N + 1);
  REP(i, 1, N + 1) {
    set<int>::iterator itr = s.lower_bound(p[i]);
    int r = *itr;
    int l = *(--itr);
    sum += (long) i * (r - p[i]) * (p[i] - l);
    s.insert(p[i]);
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 11136
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
string s;
bool t;
int main(){
	cin>>s;
	for(int i=0;i<s.size();++i){
		if(t && s[i]=='F'){
			puts("Yes");
			return 0;
		}
		if(s[i]=='C')t=true;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n)cin >> a[i];
    map<int,int>mp;
    for(int x: a)mp[x]++;
    if(mp.size() == 1){
        if(mp[0] == n){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else if(mp.size() > 3){
        cout << "No" << endl;
    }else if(mp.size() == 3){
        vector<pii>b;
        for(auto x: mp)b.emplace_back(x);
        if(b[0].second == b[1].second and b[1].second == b[2].second and b[2].second == b[0].second and (b[0].first^b[1].first^b[2].first) == 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        vector<pii>b;
        for(auto x: mp)b.emplace_back(x);
        if(b[0].second * 2 == b[1].second and b[0].first == 0){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4224
a = input()
ans = 0
for i in range(len(a)):
  for j in range(len(a)):
    hoge = a[i:len(a)-j]
    if hoge.count('A') + hoge.count('T') + hoge.count('C') + hoge.count('G') == len(hoge):
      ans = max(ans, len(hoge))
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin >> n;
  vector<ll> a(n);
  ll al = 0;
  rep(i,n){
    cin >> a[i];
    al ^= a[i];
  }
  rep(i,n){
    cout << (al ^ a[i]) << " ";
  }
}

Measured memory_bytes: 4748
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    sc.close();
    if(k % 2 == 0 || k % 5 == 0) {
      System.out.println(-1);
      return;
    }
    if(k % 7 == 0) {
      k /= 7;
    }
    k = 9 * k;

    int mod = 1;
    int n = 1;
    while(n <= k){
      mod = mod * 10;
      mod = mod % k;
      if(mod == 1){
        break;
      } else {
        n++;
      }
    }
    System.out.println(n);
  }
}


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

int main(){
  string str;
  cin >> str;
  int ans = 0;
  for(int i = 0 ; i< 4;i++){
    if(str[i]=='+')ans++;
    else ans--;
  }
  cout << ans << endl;
}

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

namespace Diverta
{
    class A
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = a[0], K = a[1];
            Console.WriteLine(N - K + 1);
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i = 0; i< N; i++){
    cin >> h.at(i);
  }
  int ans = 0;
  int count = 0;
  for(int i = 0; i< N-1; i++){
    if(h.at(i)<h.at(i+1)){
      ans = max(ans,count);
      count = 0;
    }
    else{
      count++;
    }
    
  }
  cout << max(ans,count) << endl;
}

Measured memory_bytes: 640
import sys
input = lambda: sys.stdin.readline().rstrip()
k, n = map(int, input().split())

a = list(map(int, input().split()))
sub = [abs(k - a[-1] + a[0])]

for i in range(len(a) - 1):
    tmp = abs(a[i + 1] - a[i])
    sub.append(tmp)
print(sum(sub) - max(sub))


Measured memory_bytes: 26444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
const int maxn = 3e5 + 5;
ll arr[maxn], bit[maxn][65];
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        int j = 0; ll tmp = arr[i];
        while (tmp) {
            bit[i][j] = (tmp & 1);
            tmp >>= 1;
            ++j;
        }
    }
    for (int i = n - 1; i >= 0; --i)
        for (int j = 0; j <= 61; ++j)
            bit[i][j] += bit[i + 1][j];
    ll ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        ll last = n - i - 1;
        for (int j = 0; j <= 61; ++j) {
            ll cnt = bit[i + 1][j];
            if (arr[i] & 1LL)
                ans = (ans + ((1LL << j) % mod * (ll)(last - cnt)) % mod) % mod;
            else
                ans = (ans + ((1LL << j) % mod * (ll)(cnt)) % mod) % mod;
            arr[i] >>= 1;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 155008
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
#define ct(a) cout<<a<<endl
static const double pi = 3.141592653589793;
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

map<char, int> mp;
string S,cpy;
int ans;

int main() {
	cin.tie(0);
	cout.tie(0);

	ios::sync_with_stdio(false);

	cin >> S;
	int N = S.length();

	int mae = 0;
	int usiro = N - 1;
	bool flag = false;

	while (usiro - mae > 0) {
		if (S[mae] == S[usiro]) {
			mae++; usiro--;
			continue;
		}
		if (S[mae] == 'x') {
			ans++;
			mae++;
			continue;
		}
		if (S[usiro] == 'x') {
			ans++;
			usiro--;
			continue;
		}
		flag = true;
		break;
	}



	if (flag)cout << -1 << endl;
	else cout << ans << endl;


	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int l = sc.nextInt();
		int product = w * l;
		int around = 2 * (w + l);
		System.out.println(product + " " + around);
		
	}
}

Measured memory_bytes: 25980
# -*- coding: utf-8 -*-

M, D = map(int, input().split())
count = 0

for i in range(1, M+1):
    di = len(str(i))
    for j in range(1, D+1):
        d_10 = j // 10
        d_1 = j % 10
        if d_10 >= 2 and d_1 >= 2 and d_10 * d_1 == i:
            count += 1

print(count)

Measured memory_bytes: 3060
//     . .. ... ..... be naame khodaa ..... .... ... .. .     \\

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;

inline int in(){int x, y; y = scanf("%d", &x); return x;}

const int N = 120021;

int d[N];
vector <int> g[N];
bool mark[N];

void dfs(int v) {
	mark[v] = true;
	for(int u : g[v])
		if(!mark[u])
			dfs(u);
}

int main() {
	int n = in(), m = in();
	while(m--) {
		int u = in() - 1, v = in() - 1;
		g[u].push_back(v);
		g[v].push_back(u);
		d[u]++;
		d[v]++;
	}
	bool bad = false;
	int cnt = 0;
	int a = -1, b = -1;
	for(int i = 0; i < n; i++) {
		bad |= d[i]%2;
		cnt += (d[i] - 2)/2;
		if(d[i] == 4)
			if(a == -1)
				a = i;
			else
				b = i;
	}
	if(!bad && (cnt >= 3 || (cnt == 2 && b == -1)))
		cout << "Yes\n";
	else if(bad || cnt < 2)
		cout << "No\n";
	else {
		mark[a] = true;
		dfs(b);
		cerr << 1 + a << ", " << b + 1 << (*min_element(mark, mark + n)) << endl;
		if(*min_element(mark, mark + n) == false)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
}



Measured memory_bytes: 7424
#include <stdio.h>
#define MAX 100000

int A[MAX],n;

int partition(int p,int r){
  int x,i,j,t;
  x = A[r];
  i = p - 1;
  for(j=p;j<r;j++){
    if(A[j] <= x){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }

  }
  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;
  return i+1;
}

int main(){
  int i,q;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  q = partition(0,n-1);

  for(i=0;i<n;i++){
    if(i) printf(" ");
    if(i == q) printf("[");
    printf("%d",A[i]);
    if(i == q) printf("]");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main() {
    int N;
    vector<int> V(3);
    string temp = "ABC";
    cin >> N >> V[0] >> V[1] >> V[2];
    map<string, vector<int>> idx;
    map<char, int> associations;
    associations['A'] = 0;
    associations['B'] = 1;
    associations['C'] = 2;
    map<int, string> asss2;
    asss2[0] = "A";
    asss2[1] = "B";
    asss2[2] = "C";
    vector<string> query(N);
    for (int i = 0; i < N; i++) {
        cin >> query[i];
        idx[query[i]].push_back(i);
    }

    vector<string> ans;
    bool bad = false;
    for (int i = 0; i < N; i++) {
        string q = query[i];
        int a = associations[q[0]];
        int b = associations[q[1]];
        if (V[a] == 0 && V[b] == 0) {
            bad = true;
        }

        if (V[a] > V[b]) {
            V[a]--;
            V[b]++;
            ans.push_back(asss2[b]);
        } else if (V[a] < V[b]) {
            V[b]--;
            V[a]++;
            ans.push_back(asss2[a]);
        } else {
            int diff1 = -1;
            int diff2 = -1;
            for (string aaa : {"AB", "AC", "BC"}) {
                if (aaa == q) {
                    continue;
                }
                auto itr = upper_bound(idx[aaa].begin(), idx[aaa].end(), i);
                if (itr == idx[aaa].end()) {
                    if (diff1 == -1) {
                        diff1 = 1e9;
                    } else {
                        diff2 = 1e9;
                    }
                } else {
                    if (diff1 == -1) {
                        diff1 = *itr;
                    } else {
                        diff2 = *itr;
                    }
                }
            }
            if (diff1 < diff2) {
                V[b]--;
                V[a]++;
                ans.push_back(asss2[a]);
            } else {
                V[a]--;
                V[b]++;
                ans.push_back(asss2[b]);
            }
        }
    }

    if (bad) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        for (string s : ans) {
            cout << s << endl;
        }
    }
}


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

#define mod (ll)(1e9+7)

int main()
{
    ll n,m;
    string row;
    cin>>n>>m;

    ll dp[n+1][m+1];
    memset(dp,0,sizeof dp);

    for(ll i=1;i<=n;i++)
    {
        cin>>row;
        for(ll j=0;j<m;j++)
            if(row[j] == '#')
                dp[i][j+1] = -1;
    }

    dp[1][1] = 1;

    for(ll i=1;i<=n;i++)
    {
        for(ll j=1;j<=m;j++)
        {
            if(dp[i][j] == -1)  continue;
            dp[i][j] = (dp[i][j] + max((ll)0,dp[i-1][j]) + max((ll)0,dp[i][j-1]))%mod;
        }
    }

    cout<<dp[n][m];
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int k, n;
  cin >> k >> n;
  vector <int> a(n);
  REP(i, n) {
	cin >> a[i];
  }
  int ans = k + a[0] - a[n - 1];
  REP(i, n - 1) {
	ans = max(ans, a[i + 1] - a[i]);
  }
  cout << k - ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

// 1 2 3 4
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Integer> ai = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            ai.add(sc.nextInt());
        }
        List<Integer> sorted = new ArrayList<>(ai);
        sorted.sort(Comparator.naturalOrder());

        int medLow = sorted.get(N / 2 - 1);
        int medHigh = sorted.get(N / 2);

        for (int a : ai) {
            System.out.println((a <= medLow) ? medHigh : medLow);
        }
    }
}


Measured memory_bytes: 97352
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 20;
ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

ll getv(ll H, ll W) {
	if (H % 2 == 0 || W % 2 == 0) return (H*W) / 2;
	return max((H / 2)*W, H*(W / 2));
}
ll getans(ll H, ll W) {
	ll ans = LL_INF;
	for (ll i = 1; i < H; i++) {
		ll s1 = i*W;
		ll s2 = getv(H - i, W), s3 = (H - i)*W - s2;

		ll v = abs(s1 - s2);
		v = max(v, abs(s1 - s3));
		v = max(v, abs(s2 - s3));
		ans = min(ans, v);
	}
	return ans;
}
int main() {
	ll H, W;
	scanf("%lld %lld", &H, &W);

	printf("%lld\n", min(getans(H, W), getans(W, H)));
	return 0;
}
//*/

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#define rr register
using namespace std;
const int M=4003,N=200011,mod=1000000007;
int dp[M][M],n,fac[M<<1],inv[M<<1],a[N],b[N],ans;
inline signed iut(){
    rr int ans=0; rr char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) ans=ans*10+c-48,c=getchar();
    return ans;
}
inline signed mo(int x,int y){return x+y>=mod?x+y-mod:x+y;}
inline signed c(int n,int m){return 1ll*fac[n]*inv[m]%mod*inv[n-m]%mod;}
signed main(){
    n=iut(),fac[0]=fac[1]=inv[0]=inv[1]=1;
    rr int t=M>>1,T=t<<2;
    for (rr int i=2;i<=T;++i) inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
    for (rr int i=2;i<=T;++i) fac[i]=1ll*fac[i-1]*i%mod,inv[i]=1ll*inv[i-1]*inv[i]%mod;
    for (rr int i=1;i<=n;++i){
        a[i]=iut(),b[i]=iut();
        ++dp[t-a[i]][t-b[i]];
    }
    for (rr int i=1;i<M;++i)
    for (rr int j=1;j<M;++j){
        rr int w=mo(dp[i-1][j],dp[i][j-1]);
        dp[i][j]=mo(dp[i][j],w);
    }
    for (rr int i=1;i<=n;++i){
        ans=mo(ans,dp[t+a[i]][t+b[i]]);
        ans=mo(ans,mod-c(a[i]*2+b[i]*2,a[i]*2));
    }
    return !printf("%d\n",1ll*ans*inv[2]%mod);
}

Measured memory_bytes: 65796
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{ 
    class Program
    {
        static int[] pre;
        static int[] ino;
        static int pos;
        static List<int> pro;  //Pro

        static void Solve(int l, int r)
        {
            if(l >= r)
            {
                return;
            }           

            int root = pre[pos++];         

            int m = Array.IndexOf(ino, root);            
            
            Solve(l, m);           
            Solve(m + 1, r);            
            pro.Add(root);

        }
                  
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            pre = new int[n];
            ino = new int[n];

            string[] input1 = Console.ReadLine().Split(' ');  //Pre
            string[] input2 = Console.ReadLine().Split(' ');  //In

            for(int i = 0; i < n; i++)
            {
                pre[i] = int.Parse(input1[i]);
                ino[i] = int.Parse(input2[i]);
            }

            pos = 0;
            pro = new List<int>();

            Solve(0, pre.Length);

            Console.WriteLine(String.Join(" ", pro));

        }
    }
}



Measured memory_bytes: 17928
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let c=read::<i32>();
    println!("{}",if a<=c&&c<=b{"Yes"}else{"No"})
}

Measured memory_bytes: 4352
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
S = [LS2() for _ in range(N)]
ans = 0
for a in range(N):
    X = [S[i] for i in range(a,N)] + [S[i] for i in range(a)]
    for i in range(N-1):
        for j in range(i+1,N):
            if X[i][j] != X[j][i]:
                break
        else:
            continue
        break
    else:
        ans += 1

print(ans*N)


Measured memory_bytes: 77356
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll A, B, C;
ll K;

int main()
{
  std::cin >> A >> B >> C >> K;

  while( A >= B ) {
      B *= 2;
      --K;

      if( K < 0 ) {
        std::cout << "No" << std::endl;

        return 0;
      }
  }

  while( B >= C ) {
    C *= 2;
    --K;

    if( K < 0 ) {
      std::cout << "No" << std::endl;

      return 0;
    }
  }

  std::cout << "Yes" << std::endl;

  return 0;
}

Measured memory_bytes: 3668
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		for(int i = 0; i < 3; i++){
			System.out.print(sc.nextLine().charAt(i));
		}
		System.out.println();
		
		
	}
}

Measured memory_bytes: 21972
from collections import Counter

N = int(input().strip())
Vs = list(map(int,input().strip().split()))


def get_word_num(Ss):
    hists = {}
    for v in Ss:
        if v in hists.keys():
            hists[v] += 1
        else:
            hists[v] = 1

    return sorted(hists.items(),reverse = True)


even_ar = Vs[0::2]
odd_ar = Vs[1::2]

even_hist = Counter(even_ar).most_common(2)
odd_hist = Counter(odd_ar).most_common(2)

if even_hist[0][0] != odd_hist[0][0]:
    print(N - even_hist[0][1] - odd_hist[0][1])
else:
    if len(even_hist) == 1 and len(odd_hist) == 1:
        print(len(even_ar))
    else:
        print(N - max(even_hist[0][1] + odd_hist[1][1], even_hist[1][1] + odd_hist[0][1]))


Measured memory_bytes: 15972
#B
N=int(input())
ans=1
flag=True
A=[]
for x in input().split():
    A.append(int(x))
    if int(x)==0:
        ans=0

for i in range(N):
    x=A[i]
    ans*=x
    if ans>pow(10,18):
        flag=False
        break

if flag:
    print(ans)
else:
    print("-1")

Measured memory_bytes: 84196
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 1000000007
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int gcd(int a, int b) {
	if (b > a) {
		swap(a, b);
	}

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

}
int main(void) {
	int k; cin >> k;
	int ans = 0;
	rep(a, k) {
		rep(b, k) {
			rep(c, k) {
				ans += gcd(gcd(a+1, b+1), c+1);
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3624
# A - Poor
def is_poor(x: int, y: int, z: int) -> bool:
    for _ in range(3):
        x, y, z = y, z, x
        if x == y != z:
            return True
    return False


def main():
    A, B, C = map(int, input().split())
    print("Yes" if is_poor(A, B, C) else "No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

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

int main() {
    int n,in,prev,dir = 0,len = 0;
    cin >> n;
    if (n <= 2) {
        cout << 1 << endl;
        return 0;
    }
    int cnt = 1;
    REP(i,0,n) {
        cin >> in;
        
/*            dump(i);
            dump(cnt);
            dump(dir);
            dump(len);
            dump(prev);*/
        
        if (len == 0) {
            prev = in;
            ++len;
        } else if (len == 1) {
            if (prev > in) {
                dir = -1;
                ++len;
            } else if (prev < in) {
                dir = 1;
                ++len;
            } else {
                dir = 0;
                ++len;
            }
            prev = in;
        } else {
            if (dir == 1) {
                if (prev <= in) {
                    prev = in;
                } else {
                    ++cnt;
                    len = 1;
                    prev = in;
                }
            } else if (dir == -1) {
                if (prev >= in) {
                    prev = in;
                } else {
                    ++cnt;
                    len = 1;
                    prev = in;
                } 
            } else {
                if (prev > in) {
                    dir = -1;
                    ++len;
                } else if (prev < in) {
                    dir = 1;
                    ++len;
                } else {
                    dir == 0;
                    ++len;
                }
                prev = in;
            }
        }
    }
    cout << cnt << endl;
    
    return 0;
}

Measured memory_bytes: 256
N=int(input())
Blist=list(map(int,input().split()))
Alist=[]

for i in range(N):
    if i==0:
        Alist.append(Blist[0])
    elif i==N-1:
        #print(i)
        Alist.append(Blist[i-1])
        #print(i)
    else:
        #print(i)
        Alist.append(min(Blist[i-1],Blist[i]))
        #print(i)
    
#print(Alist)
print(sum(Alist))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=1e5+5;
ll par[N],siz[N];
ll dsu_parent(ll node){
    if(node==par[node])return node;
    return par[node]=dsu_parent(par[node]);
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,m;cin>>n>>m;
    for(ll i=1;i<=n;i++)siz[i]=1,par[i]=i;

    vector< pair<ll,ll> >edges(m);
    for(ll i=0;i<m;i++)cin>>edges[i].first>>edges[i].second;
    ll ans[m];
    ans[m-1]=(n*(n-1))/2;
    for(ll i=m-2;i>=0;i--){
        ll a = dsu_parent(edges[i+1].first);
        ll b = dsu_parent(edges[i+1].second);
        if(a==b)ans[i]=ans[i+1];
        else{
            ans[i] = ans[i+1] - siz[a]*siz[b];
            if(siz[a]<siz[b])swap(a,b);
            par[b]=a;
            siz[a]+=siz[b];
        }
    }

    for(ll i=0;i<m;i++)cout<<ans[i]<<"\n";
}




Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
int main(){
    string S;
    int N,Q;
    vector <long long> l(1000000),r(1000000);
    vector <long long> s(1000000,0);    
    vector <long long> t(1000000,0);
    cin >> N >> Q >> S;
    for(int i=0;i<Q;i++){
        cin >>l.at(i)>>r.at(i);
    }
    for(int i=0;i<N-1;i++){
        if(S.at(i)=='A'&&S.at(i+1)=='C'){
            s.at(i)=1;
        }
    }
    for(int i=0;i<N-1;i++){
        t.at(i+1)=s.at(i)+t.at(i);
    }
    for(int i=0;i<Q;i++){
        cout << t.at(r.at(i)-1)-t.at(l.at(i)-1)<<endl;
    }
  return 0;
}


Measured memory_bytes: 34652
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    int n,m;
    cin>>n>>m;
    int ans=0;
    ans+=((n*(n-1))/2);
    ans+=((m*(m-1))/2);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
// #include <map>
// #include <cmath>
// #include <string>

using namespace std;
typedef long long ll;


int pow_mod(int x, int a) {
    if (a == 0) return 1;
    return ((ll)pow_mod(x, a-1) * x) % 1000000007;
}

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

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

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

    bool possible = true;
    if (A.size() % 2 == 0) {
        for (int i = 0; i < A.size(); i++) {
            if (A[i] != (i/2)*2 + 1) {
                possible = false;
                break;
            }
        }
    } else {
        for (int i = 0; i < A.size(); i++) {
            if (A[i] != ((i+1)/2)*2) {
                possible = false;
                break;
            }
        }
    }

    if (possible) {
        cout << pow_mod(2, A.size() / 2) << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

// <四則演算> ::= <乗除算> | <四則演算> + <乗除算> | <四則演算> - <乗除算>
// <乗除算>   ::= <括弧か数> | <乗除算> * <括弧か数> | <乗除算> / <括弧か数>
// <括弧か数> ::= ( <四則演算> ) | <数>
// <数>       ::= [数]

typedef string::const_iterator State;
class ParseError {};

int expr(State&);
int term(State&);
int factor(State&);
int number(State&);

// 四則演算の式
int expr(State &begin)
{
    int ret = term(begin);
    while (true) {
        if (*begin == '+') {
            begin++; // skip '+'
            ret += term(begin);
        } else if (*begin == '-') {
            begin++;
            ret -= term(begin);
        } else {
            break;
        }
    }
    return ret;
}


// 乗除算
int term(State &begin)
{
    int ret = factor(begin);
    while (true) {
        if (*begin == '*') {
            begin++;
            ret *= factor(begin);
        } else if (*begin == '/') {
            begin++;
            ret /= factor(begin);
        } else {
            break;
        }
    }
    return ret;
}


// 括弧か数
int factor(State &begin)
{
    if (*begin == '(') {
        begin++; // skip '('
        int ret = expr(begin);
        begin++; // skip ')'
        return ret;
    } else {
        return number(begin);
    }
}


// 数字
int number(State &begin)
{
    int ret = 0;
    while (isdigit(*begin)) {
        ret *= 10;
        ret += (*begin - '0');
        begin++;
    }
    return ret;
}


int main()
{
    int N; cin >> N;
    rep(i, N) {
        string S; cin >> S;
        State begin = S.begin();
        cout << expr(begin) << endl;
    }
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define MOD 998244353
#define INF 10000000000000001
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long> 
#define pb push_back
#define ll long long
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 1000005
using namespace std;
int main()
{
	string s,t;
	int cnt=0;
	cin>>s>>t;
	rep(i,0,3)
	if(s[i]==t[i])
	cnt++;
	cout<<cnt<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;
 
public class Main {
    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args){
        int n = stdIn.nextInt();
        String[] sortedS = new String[n];
        for(int i=0; i<n; i++){
            String s = stdIn.next();
            char[] cs = s.toCharArray();
            Arrays.sort(cs);
            sortedS[i] = new String(cs);
        }
        
        Arrays.sort(sortedS);

        long cnt = 0;
        for(int i=0; i<n-1; i++){
            if(!sortedS[i].equals(sortedS[i+1])){
                continue;
            }

            int j=i+1;
            while(true){
                if(!sortedS[i].equals(sortedS[j])){
                    while(!sortedS[i].equals(sortedS[j])){
                        j--;
                    }
                    break;
                }else{
                    j = j+100;
                    if(j>=n){
                        j = n-1;
                        while(!sortedS[i].equals(sortedS[j])){
                            j--;
                        }
                        break;
                    }
                }
            }
            cnt += nC2(j - i + 1);
            i = j;
        }

        System.out.println(cnt);
    }

    static long nC2(int n){
        return ((long)n * (long)(n-1)) / 2;
    }
}


Measured memory_bytes: 67564
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);

	private void doit() {
		while (true) {
			double n = sc.nextDouble();
			if(n < 0) break;
			int nint = (int)n;
			String s = Integer.toBinaryString(nint);
			if(s.length() >= 9){
				System.out.println("NA");
				continue;
			}
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < 8 - s.length(); i++){
				sb.append(0);
			}
			sb.append(s);
			sb.append(".");
			boolean flg = false;
			n = n - nint;
			for(int i = 0; i < 4; i++){
				if(n * 2 >= 1.0){
					sb.append(1);
					n = n * 2 - (int)(n * 2);
					
				}
				else{
					sb.append(0);
					n = n * 2;
				}
				if(n == 0.0){
					for(int j = i+1; j < 4; j++){
						sb.append("0");
					}
					flg = true;
					break;
				}
			}
			if(flg){
				System.out.println(sb.toString());
			}
			else{
				System.out.println("NA");
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 27936
#include<stdio.h>
#include <string.h>

int main()
{
   char s[100];
   gets(s);
   if(s[0]=='S'){

        printf("Cloudy\n");

   }else if(s[0]=='C'){

         printf("Rainy\n");

   }else{
        printf("Sunny\n");



   }

    return 0;


}


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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;
ll gcd(ll x,ll y){
    if(x%y==0)return y;
    return gcd(y,x%y);
}
ll LCM(int a, int b){
    return a*b/gcd(a,b);
}

int main(void){
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,0,n){
        cin>>a[i];
    }
    auto b=a;
    sort(a.begin(),a.end());

    ll l=n/2;
    ll med1=a[l-1],med2=a[l];
    rep(i,0,n){
        if(med2>b[i])cout<<med2<<endl;
        else cout<<med1<<endl;
    }
    return 0;
}

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

using namespace std;

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

int c[111][111];

void solve() {
    int n,m;
    cin >> n >> m;
    int k; cin >> k;
    vector<int> a(k);
    for (auto& x: a) {
        cin >> x;
    }
    memset(c, -1, sizeof c);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            c[i][j] = 0;
        }
    }
    int d = 0;
    function<pair<int, int> (int,int)> nxt = [&](int i, int j)->pair<int,int>{
        int x = i + dx[d];
        int y = j + dy[d];
        if (c[x][y]) {
            d = (d+1)%4;
            return nxt(i, j);
        }
        return {x,y};
    };
    int i=0, j=1;
    for (int t = 0; t < k; t++) {
        for (int _ = 0; _ < a[t]; _++) {
            tie(i,j) = nxt(i,j);
            c[i][j] = t+1;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            cout << c[i][j] << ' ';
        }cout << "\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 384
n,m=map(int,input().split())
a=list(map(int,input().split()))
tmp=0
ca=[tmp]
for ai in a:
  tmp+=ai
  tmp%=m
  ca.append(tmp)
from collections import Counter
cnt_ca=Counter(ca)
ans=0
for c in cnt_ca.values():
  ans+=(c*(c-1))//2
print(ans)

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

int main() {
	char a, b, z;
	cin >> a >> b;
	if (a == 'H') { if (b == 'H')cout << 'H' << endl;
	else cout << 'D' << endl;
	}
	else { if (b == 'H')cout << 'D' << endl;
	else cout << 'H' << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn rec(dp: &mut Vec<Vec<Vec<f64>>>, n: usize, i: usize, j: usize, k: usize) -> f64 {
    if dp[i][j][k] > 0f64 {
        return dp[i][j][k];
    }
    if i == 0 && j == 0 && k == 0 {
        return 0.0;
    }
    let mut ans = 0.0 as f64;
    if i > 0 { ans += rec(dp, n, i-1, j, k) * i as f64; }
    if j > 0 { ans += rec(dp, n, i+1, j-1, k) * j as f64; }
    if k > 0 { ans += rec(dp, n, i, j+1, k-1) * k as f64; }

    ans += n as _;
    ans *= 1.0 / (i + j + k) as f64;

    dp[i][j][k] = ans;
    ans
}

fn main() {
    input!{
      n: usize,
      aa: [usize; n],
    }

    let mut xx = 0;
    let mut yy = 0;
    let mut zz = 0;
    for i in 0..n {
        if aa[i] == 1 { xx += 1; }
        if aa[i] == 2 { yy += 1; }
        if aa[i] == 3 { zz += 1; }
    }
    let mut dp = vec![vec![vec![-1.0; n+1]; n+1]; n+1];
    dp[0][0][0] = 0.0;
    println!("{}", rec(&mut dp, n, xx, yy, zz));
}


Measured memory_bytes: 237820
#include <stdio.h>

    int main(void)
    {
        int s,m,h;
        scanf("%d",&s);
        m=s/60;
        s=s%60;
        h=m/60;
        m=m%60;
        printf("%d:%d:%d\n",h,m,s);
	return 0;
    }

Measured memory_bytes: 592
def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 0
    for i in range(1, n):
        if A[i - 1] > A[i]:
            a = A[i - 1] - A[i]
            ans += a
            A[i] += a

    print(ans)

resolve()

Measured memory_bytes: 32236
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int x,y,z;
    int e;
    
    while(1){
        cin >> e;
        if(e==0) break;
        int minval=1000000;
        for(int i=0;i<100000;i++){
            z = i*i*i;
            if(z>e) break;
            for(int j=0;j<1000000;j++){
                y = j*j;
                if(z + y>e) break;
                x = e - z - y;
                // cout << minval << " " << x << " " << y << " " << z << endl;
                minval = min(x+j+i,minval);
                
            }
        }
        cout << minval << endl;
        
    }
}



Measured memory_bytes: 3088
#include<bits/stdc++.h>//万能头文件 
using namespace std;
bool x=0,y=0;//boolqinsong
char a;
int main()
{
    while(a!='\n')
    {
        a=getchar();
        if(a=='C') x=1;//
        if(a=='F'&&x) y=1;//
    }
    if(x&&y) cout<<"Yes";
    else cout<<"No";
    return 0;//END!
}



Measured memory_bytes: 256