akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
int N;
ll W[10][10];
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	W[1][0]=W[0][1]=1;
	for(N=3;N<=10;N++) {
		vector<int> V;
		FOR(i,N-1) V.push_back(i);
		ll ma=0;
		do {
			if(V[0]>V.back()) continue;
			ll ret=0;
			FOR(i,N-2) ret+=W[V[i]][V[i+1]];
			ma=max(ma,ret);
		} while(next_permutation(ALL(V)));
		
		ma++;
		int cand[]={1,2,4,7,12,20,29,38,52,73};
		FOR(x,N-1) {
			W[N-1][x]=W[x][N-1]=ma*cand[x];
		}
	}
	
	cin>>N;
	vector<int> V;
	FOR(i,N) V.push_back(i);
	set<ll> C;
	
	do {
		if(V[0]>V.back()) continue;
		ll ret=0;
		FOR(i,N-1) ret+=W[V[i]][V[i+1]];
		assert(C.count(ret)==0);
		
	} while(next_permutation(ALL(V)));
	
	
	FOR(y,N) {
		FOR(x,N) cout<<W[y][x]<<" ";
		cout<<endl;
	}
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int N_MAX = 100000;
typedef long long ll;
int main()
{
  int n,i;
  ll x,res=0;
  ll a[N_MAX];
  cin >> n >> x;
  cin >> a[0];
  if(a[0]>x){
    res+=a[0]-x;
    a[0]=x;
  }
  for(i=1;i<n;i++){
    cin >> a[i];
    if(a[i]+a[i-1]>x){
      res+=a[i]+a[i-1]-x;
      a[i]=x-a[i-1];
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4400
#include<bits/stdc++.h>
using namespace std;
long long f[87];
int main(){
	int i,n;
	f[0]=2;
	f[1]=1;
	cin>>n;
	for(i=2;i<=n;i++)
		f[i]=f[i-1]+f[i-2];
	cout<<f[n]<<endl;
	return 0;
}

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

fn main() {
    let xs = read_vec_i64();
    let (v,e) = (xs[0] as usize, xs[1] as usize);
    let mut adj = vec![vec![None; v]; v];
    for i in 0..v {
        adj[i][i] = Some(0);
    }
    for _ in 0..e {
        let ys = read_vec_i64();
        let (s,t,d) = (ys[0] as usize, ys[1] as usize, ys[2]);
        adj[s][t] = Some(d);
    }
    for k in 0..v {
        for i in 0..v {
            for j in 0..v {
                if let (Some(dik),Some(dkj)) = (adj[i][k],adj[k][j]) {
                    let nd = dik + dkj;
                    if adj[i][j].is_none() || nd < adj[i][j].unwrap() {
                        adj[i][j] = Some(nd);
                    }
                }
            }
        }
    }
    for i in 0..v {
        if let Some(x) = adj[i][i] {
            if x < 0 {
                println!("NEGATIVE CYCLE");
                return;
            }
        }
    }
    for i in 0..v {
        for k in 0..v {
            match adj[i][k] {
                Some(x) => print!("{}", x),
                None => print!("INF"),
            }
            if k != v-1 {
                print!(" ");
            }
            else {
                println!("");
            }
        }
    }
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}



Measured memory_bytes: 5048
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(cont) cont.begin(), cont.end()
#define foreach(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define fore(i,a,b) for(int i=a,almo5t=b;i<almo5t;++i)
#define SZ(x) ((int)x.size())
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define FIN std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

const int N = 0;

typedef long long int ll;

using namespace std;

int elems;
int mVal;
int q;
vector<int> queries[60];


int check(int A[]){
    int val = 0;
    fore(i,0,q){
        if(A[queries[i][1]] - A[queries[i][0]] == queries[i][2]){
            val += queries[i][3];
        }
    }
    return val;
}

int f(int pos,int val,int A[]){
    if(pos == elems){
        return check(A);
    }
    int out = 0;
    fore(i,val,mVal+1){
        A[pos] = i;
        out = max(f(pos+1,i,A),out);
    }
    return out;
}

int main(){
    FIN;

    //freopen("../input.txt", "r", stdin);freopen("../output.txt", "w", stdout);
    cin>>elems>>mVal>>q;
    fore(i,0,q){
        int a,b,c,d;cin>>a>>b>>c>>d;
        queries[i].pb(a-1);
        queries[i].pb(b-1);
        queries[i].pb(c);
        queries[i].pb(d);
    }
    int temp[12];
    int maxP = f(0,1,temp);
    cout<<maxP<<"\n";
	return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int W, H, N;
int x[110], y[110], a[110];
int D[110][110];

int main(void) {
	cin >> W >> H >> N;
	rep(i, N){
		cin >> x[i] >> y[i] >> a[i];
	}
	rep(k, N){
		if(a[k] == 1){
			rep(i, x[k])rep(j, H) D[j][i] = 1;
		}else if(a[k] == 2){
			reps(i, x[k], W)rep(j, H) D[j][i] = 1;
		}else if(a[k] == 3){
			rep(i, y[k])rep(j, W) D[i][j] = 1;
		}else if(a[k] == 4){
			reps(i, y[k], H)rep(j, W) D[i][j] = 1;
		}
	}
	int cnt = 0;
	rep(i, H)rep(j, W)if(D[i][j])cnt++;
	printf("%d\n", H * W - cnt);
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
nii=lambda: map(int, stdin.readline().split())

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m,k=map(int,input().split())

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

uf=UnionFind(n+1)

for i in range(m):
  a,b=nii()
  tree_f[a].append(b)
  tree_f[b].append(a)
  uf.union(a,b)

for i in range(k):
  a,b=nii()
  if uf.find(a)==uf.find(b):
    tree_g[a].append(b)
    tree_g[b].append(a)

ans=[]
for i in range(n):
  i+=1
#  sst=list(set(tree_f[i]+tree_g[i]) & set(uf.members(i)))
#  cnt=len(sst)
  cnt=len(tree_f[i])+len(tree_g[i])
  ans.append(uf.size(i)-cnt-1)

print(*ans)

Measured memory_bytes: 46792
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]
ans = []
for i in range(n):
  p = 10 ** 9
  q = 1
  a, b = ab[i]
  for j in range(m):
    c, d = cd[j]
    tmp = abs(a-c) + abs(b-d)
    if tmp < p:
      p = tmp
      q = j + 1
  ans.append(q)
for p in ans:
  print(p)

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

int main(int argc, char const *argv[]) {
  int n, i, count=0;
  cin >> n;
  int p[n];
  for (i=0; i < n; i++) {
    cin >> p[i];
  }
  for (i=1; i < n-1; i++) {
    if(p[i-1] < p[i] && p[i] < p[i+1]) {
      count++;
    } else if (p[i-1] > p[i] && p[i] > p[i+1]) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


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

const int INF = (int)1e9;

int main() {
  while(true) {
    int m, nmin, nmax;
    cin >> m >> nmin >> nmax;
    if(m == 0 && nmin == 0 && nmax == 0) break;
    vector<int> p(m);
    for(int i = 0; i < m; ++i) cin >> p[i];
    int ansgap = 0;
    int ansac = -1;
    for(int point = 0; point <= 10000; ++point) {
      int acmin = INF;
      int wamax = 0;
      int numac = 0;
      for(int i = 0; i < m; ++i) {
        if(p[i] >= point) {
          acmin = min(acmin, p[i]);
          numac++;
        }
        else {
          wamax = max(wamax, p[i]);
        }
      }
      if(nmin <= numac && numac <= nmax) {
        if(ansgap < acmin - wamax || (ansgap == acmin - wamax && ansac < numac)) {
          ansgap = acmin - wamax;
          ansac = numac;
        }
      }
    }
    cout << ansac << endl;
  }
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n, r; cin >> n >> r;
	if( n >= 10 ){
		cout << r << endl;
	} else {
		cout << r+100*(10-n) << endl;
	}
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(void){
	int N, n2, n3, a, b, c, d;
	do{
		scanf("%d", &N);
	}while(N < 1000 || N > 9999);

	a = N / 1000;	n2 = N % 1000;
	b = n2 /100;	n3 = n2 % 100;
	c = n3 / 10;
	d =n3 % 10;

	if((a == b && b == c) || (b == c && c == d))	printf("Yes\n");
	else	printf("No\n");

	return 0;
}

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;
using pint = pair<int, int>; 
using pll  = pair<ll, ll>;
using vint = vector<int>; 
using vll  = vector<ll>;
using vstr = vector<string>;

//　定数, 変数 *********************************************
const ll MOD=1e9+7;
const ll INF=1ll<<60;

string S, T;

// *********************************************************
int main(){

    cin >> S >> T ;
    int sum=0;
    rep(i, S.size()){
        if(S[i] != T[i]){
            ++sum;
        }
    }
    
    cout << sum<<endl;



    return 0;
}

Measured memory_bytes: 3784
A, B, K = map(int, input().split())
for i in range(0, K):
    if(i & 1):
        if(B & 1):
            B -= 1
        A += B//2
        B //= 2
    else:
        if(A & 1):
            A -= 1
        B += A//2
        A //= 2
print("{0} {1}".format(A, B))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    ll n; cin >> n;
    ll ans = 1000000001000;
    FOR(i,1, sqrt(n)){
        if(n % i == 0) ans = min(ans, (n / i - 1) + (i - 1));
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] a){

		String str;
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		try {
			while(null != (str = bf.readLine())){
				String[] arr = str.split(" ");
				int number = Integer.parseInt(arr[0]) + Integer.parseInt(arr[1]);
				int count = 0;
				while(number != 0){
					number /= 10;
					count++;
				}
				System.out.println(count);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				bf.close();
			} catch (IOException e) {
			}
		}
	}
}

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

using namespace std;

int main()
{
	for(int n,w,h;cin>>n>>w>>h,n;){
		vector<vector<int> > a(h,vector<int>(w));
		for(int i=0;i<n;i++){
			int x,y; cin>>x>>y;
			a[y-1][x-1]=1;
		}
		for(int i=0;i<h;i++)
			for(int j=1;j<w;j++)
				a[i][j]+=a[i][j-1];
		for(int i=1;i<h;i++)
			for(int j=0;j<w;j++)
				a[i][j]+=a[i-1][j];
		
		int s,t; cin>>s>>t;
		int res=0;
		for(int i=t-1;i<h;i++)
			for(int j=s-1;j<w;j++){
				int val=a[i][j];
				if(i-t>=0)
					val-=a[i-t][j];
				if(j-s>=0)
					val-=a[i][j-s];
				if(i-t>=0 && j-s>=0)
					val+=a[i-t][j-s];
				if(val>res)
					res=val;
			}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
listP=[]
listX=[]
N=int(input())
T=input().split()
M=int(input())
for a in range(M):
    P,X=input().split()
    listP.append(int(P))
    listX.append(int(X))

for b in range(M):
    listT = [int(b) for b in T]

    listT[listP[b]-1]=listX[b]

    print(sum(listT))


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

int n, m, cnt;
int data[22];
int memo[22][50001];

int solve(int i, int p){

  if(!p) return 0;
  if(p < 0 || i == m) return 1<<28;
  if(memo[i][p]) return memo[i][p];
  
  int ans = 0;
  
  //cout << i << " " << p << endl;
  return memo[i][p] = ans += min(solve(i+1, p), min(solve(i, p-data[i]), solve(i+1, p-data[i]))+1);

}

int main(){

  cin >> n >> m;

  for(int i=0;i<m;i++) cin >> data[i];

  cout << solve(0, n) << endl;

}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

const int d4x[] = {0, 1, 0, -1};
const int d4y[] = {1, 0, -1, 0};

int h, w, r, c;
void d4p(int y, int x, vector<vector<int>>& exc,
         deque<tuple<int,int>>& q){
  exc[y][x] = 1;
  REP(d, 4){
    int ny = y + d4y[d], nx = x + d4x[d];
    if(ny < 0 || nx < 0 || ny > h+1 || nx > w+1 ){
      continue;
    }
    if(exc[ny][nx] == 0){
      if(!(ny <= 0 || nx <= 0 || ny >= h+1 || nx >= w+1 )){
        q.push_back(make_tuple(ny,nx));
      }
    }
  }
}
void sss(const vector<vector<int>>& hv, const vector<vector<int>>& wv,
         const vector<vector<int>>& e,int ay ,int ax){
  for(int y = 1; y <= h; y++){
    for(int x = 1; x <= w; x++){
      
      if (y==ay && x==ax) cout << "x" ;
      else if(e[y][x]==0)cout << "." ;
      else cout << "*" ;
    }cout << endl;
  }
}
int main(){
  while(cin >> h >> w >> r >> c, h != 0){
    vector<vector<int>> hv(h, vector<int>(w+1));
    vector<vector<int>> wv(h+1, vector<int>(w));
    REP(i, w){
      cin >> wv[0][i];
    }
    REP(i,h){
      REP(j,w+1){
        cin >> hv[i][j];
      }
      REP(j,w){
        cin >> wv[i+1][j];
      }
    }
    vector<vector<int>> exc(h+2, vector<int>(w+2));
    deque<tuple<int,int>> q;
    REP(y, h+2){
      d4p(y,0, exc, q);
      d4p(y,w+1, exc, q);
    }
    REP(x, w+2){
      d4p(0,x, exc, q);
      d4p(h+1,x, exc, q);
    }
    while(!q.empty()){
      int y, x; tie(y, x) = q.front();
      q.pop_front();
      if(exc[y][x] == 1) continue;
      bool res = true;
      REP(wl,2){
        bool out = false;
        if(hv[y-1][x-1] == wl && exc[y][x-1] == 1){
          out = true;
        }
        if(hv[y-1][x] == wl && exc[y][x+1] == 1){
          out = true;
        }
        if(wv[y-1][x-1] == wl && exc[y-1][x] == 1){
          out = true;
        }
        if(wv[y][x-1] == wl && exc[y+1][x] == 1){
          out = true;
        }
        res = res && out;
      }
      if(res){
        d4p(y,x, exc, q);
      }
    }
    
    bool eee = false;
    if(hv[r-1][c-1] == 0 && exc[r][c-1] == 1){
      eee = true;
    }
    if(hv[r-1][c] == 0 && exc[r][c+1] == 1){
      eee = true;
    }
    if(wv[r-1][c-1] == 0 && exc[r-1][c] == 1){
      eee = true;
    }
    if(wv[r][c-1] == 0 && exc[r+1][c] == 1){
      eee = true;
    }
    if(eee){
      cout << "Yes" << endl;
    } else if(exc[r][c] == 1){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5712
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
	
 
 
int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        vector<ll> a(n);
        for(int i=0;i<n;i++){
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        ll ans = a[1]-a[0];
        for(int i=2;i<n;i++){
            if(ans>a[i]-a[i-1]){
                ans = a[i]-a[i-1];
            }
        }
        cout<<ans<<endl;
    }
}



Measured memory_bytes: 3108
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

#define _USE_MATH_DEFINES
#include <math.h>


int main(void) {

	double result[1001] = { 0 };
	int kurikaesi = 0;


	while (1) {
		int n = 0;

		scanf("%d%*[^\n]%*c", &n);

		if (n == 0) {
			break;
		}
		
		int s[1000] = { 0 };

		char c = 0; 
		int count = 0;
		double sum = 0;
		/*while (c = getchar() != EOF) {
			if (c == "\n") {
				break;
			}
			if (c == " ") {
				continue;
			}
			s[count++] = (int)c;
			sum += (int)c;
			if (count >= n) {
				break;
			}
		}*/

		while (count < n) {
			scanf("%d", &s[count++]);
			sum += s[count - 1];
		}


		// 標準偏差を計算する
		double m = sum / n;
		double sigma = 0;

		int i = 0;
		for (; i < n; i++) {
			sigma += pow(s[i] - m, 2);
		}


		double a = sqrt(sigma/n);
		result[kurikaesi++] = a;
	}
	
	int i = 0;

	for (; i < kurikaesi; i++) {
		printf("%lf\n", result[i]);
	}


	return 0;
}



Measured memory_bytes: 2072
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int D, N; cin >> D >> N;
    vector<int> T(D);
    for (int i = 0; i < D; ++i)
        cin >> T[i];
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i] >> B[i] >> C[i];

    vector<vector<int>> dp(D, vector<int>(N));
    for (int d = 1; d < D; ++d) {
        for (int c = 0; c < N; ++c) {
            if (T[d] < A[c] || T[d] > B[c]) continue;
            for (int b = 0; b < N; ++b) {
                if (T[d-1] < A[b] || T[d-1] > B[b]) continue;
                dp[d][c] = max(dp[d][c], dp[d-1][b] + abs(C[b] - C[c]));
            }
        }
    }
    int ans = 0;
    for (int c = 0; c < N; ++c)
        ans = max(ans, dp[D-1][c]);
    cout << ans << endl;
}

Measured memory_bytes: 1344
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
//#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

 
vi a, b;
int nxt;

map<int, vi> mp;

bool getIdx(int idx, int s){
	vi v = mp[s];
	auto it = upper_bound(all(v), idx);
	if(it==v.end()) return false;
	nxt = *it;
	return true;
}

int main(){
    int n, m, tmp;
    cin>>n>>m;
    rep(i, n) cin>>tmp, a.pb(tmp);
    rep(i, m) cin>>tmp, b.pb(tmp);

    for(int i = 0; i < n; i++){
    	mp[a[i]].pb(i);
    }
    int ans = 0;
    for(int i = 0; i < b.size(); i++){
    	int idx = -1; tmp = 0;
    	while(i+tmp<b.size() && idx < n &&getIdx(idx, b[i+tmp])){
    		tmp++;
    		idx = nxt;
    	}
    	ans = max(ans, tmp);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3256
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<string>
#include<unordered_map>
using namespace std;
 
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j,k
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  cout<<max({a*c,a*d,b*c,b*d});
return 0;}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}

#define MOD 1000000007
typedef long long ll;

int main(){
  int n;
  cin >> n;
  int a[1000],mini=10000,maxi=-10000;
  FOR(i,n){
    cin >> a[i];
    chmin(mini,a[i]);
    chmax(maxi,a[i]);
  }

  cout << maxi-mini << endl;
  
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int list[26];

int main()
{
    string s;
    cin >> s;

    for (int i=0; i<26; i++) {
        list[i] = 0;
    }

    for (int i=0; i<s.size(); i++) {
        list[s[i]-'a'] += 1;
    }

    for (int i=0; i<26; i++) {
        if (list[i] > 1) {
            cout << "no" << endl;
            exit(0);
        }
    }

    cout << "yes" << endl;

    return 0;
}


Measured memory_bytes: 256
while True:
    a, b = map(int, input().split())
    if a == 0:
        break
    N = int(input())
    memo = [[0 for i in range(a+1)] for j in range(b+1)]
    flag = [[False for i in range(a+1)] for j in range(b+1)]
    memo[1][1] = 1
    flag[1][1] = True
    x = [0] * N
    y = [0] * N
    for i in range(N):
        x[i], y[i] = map(int, input().split())
        flag[y[i]][x[i]] = True

    for i in range(1, b+1):
        for j in range(1, a+1):
            if not flag[i][j]:
                flag[i][j] = True
                memo[i][j] = memo[i-1][j] + memo[i][j-1]

    print(memo[b][a])



Measured memory_bytes: 5608
from collections import Counter

N = int(input())
A = [int(x) for x in input().split()]

A.sort()
C = Counter(A)
for a in A:
    if C[a] == 0: continue
    if C[a] > 1:
        C[a] = 0
    for ab in range(2 * a, A[-1] + 1, a):
        C[ab] = 0

print(sum(C.values()))

Measured memory_bytes: 96824
k=int(input())
l= input().split(' ')
a=int(l[0])
b=int(l[1])

flag = 0
for i in range(a,b+1):
    if(i%k == 0):
        print("OK")
        flag = 1
        break
if(flag == 0):
    print("NG")
    
    


Measured memory_bytes: 61688
from collections import deque


if __name__ == "__main__":
    num_query = int(input())
    int_que: deque = deque()
    for _ in range(num_query):
        op, *value = map(lambda x: int(x), input().split())
        if (0 == op):
            if (0 == value[0]):
                int_que.appendleft(value[1])
            else:
                int_que.append(value[1])
        elif (1 == op):
            print(f"{int_que[value[0]]}")
        elif (2 == op):
            if (0 == value[0]):
                int_que.popleft()
            else:
                int_que.pop()
        else:
            pass



Measured memory_bytes: 21964
#include <stdio.h>
int main(){
	int n,i,counter,l,r;
	char s[3];
	
	while(1){
		l=2;
		r=2;
		counter=0;
	scanf("%d",&n);
	if(n==0)break;
	for(i=0;i<n;i++){
		scanf("%s",s);
			if(s[1]=='u'){
				if(l==0||r==0){
					l=2;
					r=2;
				}
				if(s[0]=='l')l=1;
				else if(s[0]=='r')r=1;
				if(l==1&&r==1){
					counter++;
					l=2;
					r=2;
				}
			}else if(s[1]=='d'){
				if(l==1||r==1){
					l=2;
					r=2;
				}
				if(s[0]=='l')l=0;
				else if(s[0]=='r')r=0;
				if(l==0&&r==0){
					counter++;
					l=2;
					r=2;
				}
			}
		}
		printf("%d\n",counter);
	}
		return 0;
}

Measured memory_bytes: 1032
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  rep(i,n) {
    R a[i];
    a[i]--;
  }
  int d[n];
  memset(d,-1,sizeof(d));
  vector<ll> v;
  ll x=0;
  d[0]=0;
  v.pb(0);
  while(1) {
    m--;
    if(d[a[x]]!=-1) {
      ll z=d[x]-d[a[x]]+1;
      m%=z;
      pr(v[d[a[x]]+m]+1);
      return;
    } else {
      if(!m) {
        pr(a[x]+1);
        return;
      }
      v.pb(a[x]);
      d[a[x]]=d[x]+1;
      x=a[x];
    }
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 7592
package main

import (
	"fmt"
)

func main() {

	var A, B int
	fmt.Scanf("%d %d", &A, &B)

	var result int
	result = A - 2*B
	if result >= 0 {
		fmt.Println(A - 2*B)
	} else {
		fmt.Println("0")
	}

}


Measured memory_bytes: 1832
#include <bits/stdc++.h>
 using namespace std;
  int main(){
      int n;
      cin >> n;
      int ans=0;
      for(int i=n;i!=0;i--){
           int a=sqrt(i);
          if(a*a==i){
              ans=i;
              break;
          }
      }
      cout << ans << endl;
      
  }

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;

#define pi 3.141592653589
#define repeat(i,n) for(int i=0;i<n;i++)

int main(){
	int n, m, l;
	long **a, **b,**c;

	cin >> n >> m >> l;

	//2次元配列の確保
	a = new long*[n];
	repeat(i, n)
	{
		a[i] = new long[m];
	}

	b = new long*[m];
	repeat(i, m)
	{
		b[i] = new long[l];
	}

	c = new long*[n];
	repeat(i, n)
	{
		c[i] = new long[l];
	}

	//行列Cの要素を初期化
	repeat(i, n)
	{
		repeat(j, l)
		{
			c[i][j] = 0;
		}
	}

	//行列A,Bの要素に値を入力
	repeat(i, n)
	{
		repeat(j, m)
		{
			cin >> a[i][j];
		}
	}
	
	repeat(i, m)
	{
		repeat(j, l)
		{
			cin >> b[i][j];
		}
	}

	//行列Cの各要素の値を計算
	repeat(i, n)
	{
		repeat(j, l)
		{
			repeat(k, m)
			{
				c[i][j] += (a[i][k] * b[k][j]);
			}
		}
	}

	//Cを出力
	repeat(i, n)
	{
		repeat(j, l)
		{
			cout << c[i][j];
			if (j != l - 1) cout << " ";
			else if (j == l - 1) cout << endl;
		}
	}

	return 0;
}

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

int main() {
    int N, K, ans = 1e9 + 1;
    cin >> N >> K;
    vector<int> h(N);
    vector<int> dis(N - 1);
    for(int i = 0; i < N; ++i)
        cin >> h[i];
    sort(h.begin(), h.end());
    for(int i = 0; i <= N - K; ++i)
        ans = min(ans, h[i + K - 1] - h[i]);
    cout << ans << endl;
    return 0;
}


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

int main() {
  int X,B;
  
  cin >> X;
  
  B = X % 10;
    
  X = X / 10;
    
  B += X % 10;
  
  B = B + X /10;
    
  
  cout <<  B  << endl;
    
}

Measured memory_bytes: 256
/*
    ThunderClap and Flash.
    Raunaq Singh
*/
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define ThunderClap ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define debugg(something)   cout<<#something<<" - "<<something<<"\n";
#define vi vector
#define umap unordered_map
#define uset unordered_set
#define mset multiset
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define pb push_back
#define in insert
#define s second
#define f first
#define pQueue priority_queue
#define maxElement *max_element
#define minElement *min_element
#define MAX 100000
#define mod 1000000007
#define inf 1000000000000000000
#define mI2 500000004
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod))%mod;}
inline ll mul(ll a, ll b){ return ((a%mod)*(b%mod))%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

void Flash(){
    char c;
    cin>>c;
    int ans=(c-'a')+1;
    cout<<char(ans+'a')<<"\n";
}

int main(int argc, char const *argv[]){
    ThunderClap;
    ll t=1;
    //cin>>t;
    for(ll i=1;i<=t;i++){
        //cout<<"Case #"<<i<<": ";
        Flash();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
typedef long long  ll;
//typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set
// this for long double
#define press_F_to_pay_respect ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn for(int i=0;i<n;i++) 
#define form for(int j=0;j<n;j++) 
#define fore(i,a,b) for(int i = a; i < (b); i++)
#define pb push_back 
#define pob pop_back()
#define mp make_pair 
#define sc second 
#define f first 
#define ld long double
#define kek cout<<endl; 
#define rep(i,a,b) for(int i=a;i<b;i++)
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
#define halt {cout<<-1; return 0;}
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const int N = 1010;
const int INF = 1e8;
const ll MOD1=1073741824;
const long double pi=3.1415926535;
using namespace std;
using namespace __gnu_pbds;
typedef tree<ld,null_type,less<ld>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
string bin_rep(int n)
{
          string s="";
      for(int i=31;i>=0;i--)
   {
           if(n&(1<<i)) s+='1';
           else s+='0';
   }
   return s;
}
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
 press_F_to_pay_respect;
 // cout << fixed << setprecision(12) << ans;
 // string al = "abcdefghijklmnopqrstuvwxyz";
 int k;
 cin>>k;
 string s;
 cin>>s;
 int n=s.size();
 if(n<=k) cout<<s;
 else cout<<s.substr(0,k)<<"...";
 
 
 
 
 
    
 
 
 
  // cout <<"Runtime is:"<<clock() * 1.0 / CLOCKS_PER_SEC <<endl;
   return 0;
   
   
 
}

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

int main(){
    int n,m,l;
    cin >> n >> m >> l;

    vector<vector<unsigned long>> dk(n,vector<unsigned long>(n,ULONG_MAX));
    vector<vector<unsigned long>> sup(n,vector<unsigned long>(n,ULONG_MAX));

    for(int i=0; i<m; i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        dk[a][b] = c;
        dk[b][a] = c;
    }
    for(int i=0; i<n; i++){
        dk[i][i] = 0;
        sup[i][i] = 0;
    }
    for(int k=0; k<n ;k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(dk[i][k] == ULONG_MAX || dk[k][j] == ULONG_MAX){
                    continue;
                }
                dk[i][j] = min(dk[i][j], dk[i][k]+dk[k][j]);
                if(dk[i][j] <= l){
                    sup[i][j] = 1;
                }
            }
        }
    }
    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(sup[i][k] == ULONG_MAX || sup[k][j] == ULONG_MAX){
                    continue;
                }
                sup[i][j] = min(sup[i][j], sup[i][k]+sup[k][j]);
            }
        }
    }

    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int s,t;
        cin >> s >> t;
        if(sup[s-1][t-1] < ULONG_MAX){
            cout << sup[s-1][t-1]-1 << endl;
        }else{
            cout << -1 << endl;
        }
    }
}

Measured memory_bytes: 1920
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args) {
		try {
			String packageName = new Main().getClass().getPackage().getName();
			System.setIn(new FileInputStream("src/" + packageName + "/input.txt"));
			// System.setOut(new PrintStream(new FileOutputStream("src/" + packageName + "/result.txt")));
		} catch (FileNotFoundException e) {
		} catch (NullPointerException e) {
		}
		new Main().run();
	}

	void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	Scanner sc;
	void run() {
		sc = new Scanner(System.in);
		int t = sc.nextInt();
		while (t --> 0) solve();

	}
	void solve() {
		int n = sc.nextInt() + 1;
		int m = sc.nextInt();

		int sa = sc.nextInt();
		int sb = sc.nextInt();

		ArrayList<ArrayList<E>> g = new ArrayList<ArrayList<E>>();
		for (int i = 0; i < n; i++) g.add(new ArrayList<E>());

		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			int t = sc.next().charAt(0);
			g.get(a).add(new E(b, t));
			g.get(b).add(new E(a, t));
		}

		int ans = inf;

		int[] fromGoal = dijk(g, 0, true);
		int[] fromCat = dijk(g, sb, true);
		int[] fromMan = dijk(g, sa, false);

		if (fromCat[0] == 0) ans = 0;
		else
			for (int i = 0; i < n; i++) {
				ans = min(ans, fromGoal[i] + fromCat[i] + fromMan[i]);
			}

		System.out.println(ans);
	}

	int inf = Integer.MAX_VALUE / 5;

	int[] dijk(ArrayList<ArrayList<E>> g, int s, boolean strict) {
		int n = g.size();
		int[] res = new int[n];
		fill(res, inf - 1);
		res[s] = 0;
		PriorityQueue<Tupple> q = new PriorityQueue<Tupple>();
		q.add(new Tupple(0, s));
		while (!q.isEmpty()) {
			int cost = q.peek().a;
			int here  = q.peek().b;
			q.poll();

			if (cost != res[here]) continue;

			for (E e : g.get(here)) {
				int ncost = 0;
				if (strict)
				{
					if (cost == 0 && e.type == 'L') ncost = 0;
					else if (cost > 0 && e.type == 'L') ncost = inf;
					else ncost = 1;
				}
				else
				{
					if (e.type == 'L') ncost = inf;
					else ncost = 1;
				}
				ncost += cost;
				if (res[e.to] > ncost) {
					res[e.to] = ncost;
					q.add(new Tupple(ncost, e.to));
				}
			}
		}
		return res;
	}

	class Tupple implements Comparable<Tupple> {
		int a, b;

		public int compareTo(Tupple o) {
			if (a != o.a) return a < o.a ? -1 : 1;
			if (b != o.b) return b < o.b ? -1 : 1;
			return 0;
		}

		public Tupple(int a, int b) {
			this.a = a;
			this.b = b;
		}

	}

	class E {
		public E(int to, int type) {
			this.to = to;
			this.type = type;
		}
		int to;
		int type;
	}

}

Measured memory_bytes: 35000
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INT = 1e9;
const ll LINF = 1e18;

string s;
vector<string> button(10);
void init(){
    button[1] = ".,!? ";
    button[2] = "abc";
    button[3] = "def";
    button[4] = "ghi";
    button[5] = "jkl";
    button[6] = "mno";
    button[7] = "pqrs";
    button[8] = "tuv";
    button[9] = "wxyz";
}
string solve(){
    string res;
    replace(s.begin(),s.end(),'0',' ');
    s += "#";
    stringstream ss; ss << s;
    while(true){
        string X; ss >> X;
        if(X == "#") break;
        int i = X[0] - '0';
        int j = (X.length()-1)%(int)button[i].length();
        res += button[i][j];
    }
    return res;
}
int main(void){
    cin.tie(0); ios_base::sync_with_stdio(false);
    init();
    int T; cin >> T;
    while(T--){
        cin >> s;
        cout << solve() << endl;
    }
    return 0;
}



Measured memory_bytes: 3176
#include<iostream>
using namespace std;
int n;
int a[100000];

int s1(int i){
    if(a[i]==1&&a[i-1]==0) return 1;
    return 0;
}
int s2(int i){
    if(a[i]==0&&a[i-1]==1) return 1;
    return 0;
}
int happy(int i){
    if(a[i]==a[i-1]) return 1;
    return 0;
}

void reverse(int i,int j){
    int b[j];
    for(int k=i;k<=j;k++){
        b[k]=a[j--];
    }
    for(int k=i;k<=j;k++){
        if(b[k]==1) a[k]=0;
        if(b[k]==0) a[k]=1;
    }
}

int main(){
    cin>>n;
    int k;
    cin>>k;
    char s[n];
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='L') a[i]=0;
        if(s[i]=='R') a[i]=1;
    }
    int hp=0;
    for(int i=1;i<n;i++){
        if(happy(i)==1) hp++;
    }
    for(int z=0;z<k;z++){
        if(hp==n-1||hp==n-2){
            cout<<n-1;
            return 0;
        }
        int as1,as2;
        int i=1;
        while(s1(i)==0)
            i++;
        as1=i;
        int j=1;
        while(s2(j)==0)
            j++;
        as2=j;
        if(as1<as2){
            reverse(as1,as2);
            hp+=2;
        }
        else{
            reverse(as2,as1);
            hp+=2;
        }
    }
    cout<<hp;
    return 0;
}


Measured memory_bytes: 768
N = list(input())
Y = [0]
for i in N:
    Y.append(int(i))
dp = [0 for i in range(len(N)+1)]
dp2 = [10 for i in range(len(N)+1)]
for i in range(1,len(N)+1):
    dp[i] = min(dp[i-1] + Y[i],dp2[i-1] + Y[i])
    dp2[i] = min(dp[i-1] + 1 + 10 - Y[i],dp2[i-1] - 1 + 10 - Y[i])
ans = min(dp[-1],dp2[-1])
#print(dp,dp2)
print(ans)

Measured memory_bytes: 100396
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // [b,c) イテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

int64_t N; cin >> N;
VI X(N); rep(i, 0, N) cin >> X[i];
VI Y = X;
sort(ALL(Y));
VI Xmed{Y[N/2 - 1], Y[N/2]};

rep(i, 0, N){
    if (X[i] <= Xmed[0]) cout << Xmed[1] << endl;
    else cout << Xmed[0] << endl;
}

}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 5376
## coding: UTF-8
from decimal import *
from itertools import permutations, combinations,combinations_with_replacement,product
import math
from math import gcd

#(i<j<k)j-i = k-jをやるときは k = 2*j-iを用いる
#これでif continueをすればよかった

N = int(input())
S = input()

r_list = []
g_list = []
b_list = []

for i in range(N):
    if(S[i] == 'R'):
        r_list.append(i)
    elif(S[i] == 'G'):
        g_list.append(i)
    else:
        b_list.append(i)

#print('r:{}, g:{}, b:{}'.format(r_list, g_list, b_list))

R_count = len(r_list)
G_count = len(g_list)
B_count = len(b_list)
#print(R_count * G_count * B_count)

#3重ループを防ぐ方法
#これでTLEを防げ！
b_num_list = [0 for i in range(N)]
for i in range(B_count):
    b_num_list[b_list[i]] += 1
#print('b_num_list:{}'.format(b_num_list))
    

counter = R_count * G_count * B_count
NG_list = []
for i in range(R_count):
    for j in range(G_count):
        r = r_list[i]
        g = g_list[j]
        hit_count = 0
        #if( (g+g-r) in b_list):
        #print('g+g+r:{}'.format(g+g-r))
        if(g+g-r >= 0 and g+g-r <= N-1): #and b_num_list[g+g-r] == 1)
            #print('b_num_list[g+g-r]:{}'.format(b_num_list[g+g-r]))
            if(b_num_list[g+g-r] == 1):
                hit_count += 1
        #if( (g+r)%2 == 0 and ((g+r)/2) in b_list ):
        if( (g+r)%2 == 0 and b_num_list[int((g+r)/2)] == 1):
            hit_count+=1
        #if( (r-g+r) in b_list):
        if(r+r-g >= 0 and r+r-g <= N-1 ):#and b_num_list[r+r-g] == 1):
            if(b_num_list[r+r-g] == 1):
                hit_count+=1
        counter -= hit_count
print(counter)
   


Measured memory_bytes: 75600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define sz(x) ((int)x.size())
typedef long long ll;

const int M = 1e9+7;
const int maxn = 1e6+10;

int a[maxn];

int main()
{
	int t;
//	cin>>t;
	t = 1; 
	while(t--)
	{
		int n;
		cin>>n;
		n %= 1000;
		cout<<(1000-n)%1000<<endl;
	} 
}



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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

int main(){
  int n;cin>>n;
  vector<int> b(n);
  rep(i,n-1){
    int a;cin>>a;
    b[a-1]++;
  }
  rep(i,n)cout<<b[i]<<endl;
}


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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPL(i,a,n) for(ll i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SORTVG(v) sort(v.begin(),v.end(),greater<>())
#define SORTV(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define INF LLONG_MAX/2
#define int long long

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T> void AorB(T& a, string A,string B) {if(a){cout << A << ENT;}else{cout << B << ENT;}}

int atcoder(){
    int n,count=0,ans=0;
    cin>>n;
    Vi a(n);
    REP(i,0,n){
        cin>>a[i];
        if(a[i]<0){
            count++;
            a[i] *= -1;
        }
        ans+=a[i];
    }
    if(count&1) ans-=(*min_element(ALL(a)))*2;
    cout<<ans<<ENT;
    return 0;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    atcoder();
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;


int main() {
	cin >> N;
	vector<pair<string, int>> sp(N);
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> sp[i].first >> tmp;
		sp[i].second = 100 - tmp;
	}
	map<pair<string, int>,int> mp;
	for (int i = 0; i < N; i++)mp[sp[i]] = i+1;
	sort(sp.begin(), sp.end());
	for (int i = 0; i < N; i++) {
		cout << mp[sp[i]] << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cinttypes>
#include<vector>
#include<algorithm>

using si32 = std::int32_t;
using ui32 = std::uint32_t;

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

	ui32 n, m;
	std::cin >> n >> m;

	std::vector<std::vector<si32>> vertices(n);

	for (ui32 i{}; i < m; ++i) {
		ui32 x, y;
		std::cin >> x >> y;
		vertices[x - 1].emplace_back(y - 1);
	}

	auto p = [&] {
		std::cout << "print vertices--start\n\n";
		for (const auto&e : vertices) {
			for (const auto&ee : e)
				std::cout << ee << " ";
			std::cout << "\n";
		}
		std::cout << "print vertices--end\n";
	};
	//p();


	std::vector<ui32> tab(n, -1);

	auto count = 0;
	auto dfs = 
		[&](auto f, auto i)->ui32 {

		//std::cout << i << "\n";
//		++count;
//		std::cout << "c:" << count << "\n";
		if (i == -1)
			return 0;

		if (tab[i] != -1)
			return tab[i];

		ui32 acc{};
		for (auto e : vertices[i])
			acc = std::max(acc, 1 + f(f, e));

//		std::cout << i << ", " << acc << "\n";
		return tab[i] = acc;
	};

//	std::cout << dfs(dfs, 0) << "\n";

	for (ui32 i{}; i < n; ++i)
		auto v = dfs(dfs, i);
	
	/*/
	for (const auto&e : tab)
		std::cout << e << " ";
	std::cout << "\n";
	*/

	std::sort(std::begin(tab), std::end(tab), std::greater<>{});
	std::cout << tab[0] << "\n";
	return 0;
}

Measured memory_bytes: 10240
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(int argc, char const *argv[]){
    int x;
    scanf("%d", &x);
    if(x < 1200){
        printf("ABC\n");
        return 0;
    }
    printf("ARC\n");
    return 0;
}

Measured memory_bytes: 256
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,MOD=1e9+7;

void solve()
{
 int n,m;

 cin>>n>>m;

 vector<int> v(n);

 for(int i=0;i<n;++i)
 cin>>v[i];

 sort(all(v));

 vector<pair<int,int>> a(m);

 for(int i=0;i<m;++i)
 cin>>a[i].S>>a[i].F;

 sort(all(a));
 reverse(all(a));

 for(int i=0,j=0;i<n;++i)
 {
  if(j<m && a[j].F>v[i])
  {
   v[i]=a[j].F;
   a[j].S--;
   if(!a[j].S)
   ++j;
  }
 }

 //for(auto x:v)
 //cout<<x<<" ";
 //cout<<"\n";

 cout<<accumulate(all(v),0ll);
}

int32_t main()
{
 fast();

 int t=1;
 //cin>>t;
 while(t--)
 {
  solve();
 }

 return 0;
}



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

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

    vector<int> v;
    for(int i = 0; i < n; ++i){
      int tmp_v;
      cin >> tmp_v;
      v.push_back(tmp_v);
    }

    vector<int> c;
    for(int i = 0; i < n; ++i){
      int tmp_c;
      cin >> tmp_c;
      c.push_back(tmp_c);
    }

    int answer = 0;

    for(int i = 0; i < n; ++i){
      int value = v[i] - c[i];
      if(value > 0){
        answer += value;
      }
    }

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 256