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

#define EPS (1e-10)
double length(double x1, double y1, double x2, double y2){
	return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));
}

int main(){
	double x1, y1, x2, y2, x3, y3, xp, yp;
	double a, b, c, x, pa, pb, pc;
	double S, Sp, Sa, Sb, Sc;
	while(cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> xp >> yp){
		a = length(x2, y2, x3, y3);
		b = length(x3, y3, x1, y1);
		c = length(x1, y1, x2, y2);
		x = (a + b + c) / 2;
		S = sqrt(x*(x-a)*(x-b)*(x-c)); // Heron's formula

		pa = length(xp, yp, x1, y1);
		pb = length(xp, yp, x2, y2);
		pc = length(xp, yp, x3, y3);
		x = (a + pb + pc) / 2;
		Sa = sqrt(x*(x-a)*(x-pb)*(x-pc));
		x = (pa + b + pc) / 2;
		Sb = sqrt(x*(x-pa)*(x-b)*(x-pc));
		x = (pa + pb + c) / 2;
		Sc = sqrt(x*(x-pa)*(x-pb)*(x-c));
		Sp = Sa + Sb + Sc;
		if (fabs(Sp-S) < EPS) {
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const int INF = INT_MAX;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x, ll y){ if(x>y) swap(x, y);while(x!=0){ y%=x; swap(x, y); }return y; }
ll mpow(ll x, ll r){if(r==0) return 1;if(r%2==1){ return x*mpow(x, r-1)%mod; }else{ ll aa = mpow(x, r/2); return aa*aa%mod; }}

int main(){
	string s, t; cin >> s >> t;
	rep(i, s.size()){
		if(s[i] != t[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
# define pii pair<int,int>
# define fio ios_base::sync_with_stdio(false); cin.tie(NULL)
int main()
{   ll n,k;
    ll a[200009];
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(ll i=k+1;i<=n;i++)
    {
        if(a[i]>a[i-k]) cout<<"Yes\n";
        else cout<<"No\n";
    }
}


Measured memory_bytes: 4688
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

typedef long long int ll;

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), b(n);
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    ll ans = 0;
    for(int i = 0; i <= 30; i++){
        if(i != 0 && (k & (1LL << i)) == 0) continue;
        ll t;
        if(i == 0) t = k;
        else t = k & ~(1LL << i) | ((1LL << i) - 1);
        ll sum = 0;
        for(int j = 0; j < n; j++){
            if((t | a[j]) == t) sum += b[j]; 
        }
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    int n, m; cin >> n >> m;
    vector<pair<int, int>> key;
    rep(i, m){
        int a, b, s = 0; cin >> a >> b;
        rep(j, b){
            int c; cin >> c; c--;
            s |= (1<<c);
        }
        key.emplace_back(s, a);
    }

    // bitDP
    vector<int> dp(1<<n, 1<<30); dp[0] = 0;
    rep(s, 1<<n){
        rep(i, m){
            int t = s | key[i].first;
            int cost = dp[s] + key[i].second;
            chmin(dp[t], cost);
        }
    }
    int ans = dp.back();
    if(ans == 1<<30) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 3672
from itertools import combinations
h, w, k = map(int, input().split())
c = [input() for _ in range(h)]


def count_black():
    res = 0
    for i in range(h):
        if red_h[i] != 1:
            for j in range(w):
                if red_w[j] != 1:
                    if c[i][j] == "#":
                        res += 1
    if res == k:
        return 1
    else:
        return 0


ans = 0
for i in range(2**h):
    red_h = [0]*h
    for j in range(h):
        if i >> j & 1 == 1:
            red_h[j] = 1

    for x in range(2**w):
        red_w = [0]*w
        for y in range(w):
            if x >> y & 1 == 1:
                red_w[y] = 1
        ans += count_black()

print(ans)


Measured memory_bytes: 68928
package main
import(
  "fmt"
)
func main(){
  var n, i, x, y int
  x=0
  y=0
  fmt.Scan(&n)
  a:=make([]int, n)
  for i=0;i<n;i++{
    fmt.Scan(&a[i])
    if a[i]>x&&a[i]>y{
      y=x
      x=a[i]
    }else if a[i]>y{
      y=a[i]
    }
  }
  for i=0;i<n;i++{
    if a[i]==x{
      fmt.Println(y)
    }else{
      fmt.Println(x)
    }
  }
}


Measured memory_bytes: 7424
import sys
input = sys.stdin.readline
def print_ans(N, A, B):
    """Test Case
    >>> print_ans(4, 2, 9)
    8
    >>> print_ans(4, 2, 7)
    7
    >>> print_ans(4, 2, 8)
    8
    """
    print(min(N * A, B))

if __name__ == '__main__':
    N, A, B = map(int, input().rstrip().split())
    print_ans(N, A, B)


Measured memory_bytes: 2940
import java.util.*;
import java.io.*;

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
//......................................@uthor_Alx..............................................
static long mod=(long)1e9+7;
static long rec(long x, Map<Long,Long> map,long[][] op,long d){
    if(x<=0l){
        map.put(0l,0l); return 0l;
    }
    if(map.get(x)!=null) return map.get(x);
    long n=x;
    map.put(x,(long)4e18);
    if((map.get(x)+d-1)/d>n) map.put(x,d*n);
    for(int i=0;i<3;i++){
        if(x%op[i][0]==0){
            map.put(x,Math.min(map.get(x),rec(x/op[i][0],map,op,d)+op[i][1]));
        }
        else{
            map.put(x,Math.min(map.get(x),d*(x%op[i][0])+rec(x/op[i][0],map,op,d)+op[i][1]));
            map.put(x,Math.min(map.get(x),d*(op[i][0]-x%op[i][0])+rec(x/op[i][0]+1,map,op,d)+op[i][1]));
        }
    }
    
     return map.get(n);
}
public static void main(String[] args) throws  IOException{
                assign();
                int t=int_v(read());
               while(t--!=0){
                     long[] x=long_arr();
                     long n=x[0],a=x[1],b=x[2],c=x[3],d=x[4];
                     Map<Long,Long> map=new HashMap<>();
                     long[][] op=new long[][]{{2l,a},{3l,b},{5l,c}};
                     out.write(rec(n,map,op,d)+"\n");
               }

                out.flush();

    }
}


Measured memory_bytes: 61356
#include <vector>
#include <functional>
#include <algorithm>
#include <iostream>
#include <climits>
using namespace std;

// 抽象 SegmentTree (0-indexed・一点更新・区間取得)
template <typename MonoidType, typename UpdateType>
struct SegmentTree {
    using UpdateFunc  = function< MonoidType(MonoidType, UpdateType) >;
    using CombineFunc = function< MonoidType(MonoidType, MonoidType) >;

    // node, identity element
    int n;
    vector<MonoidType> node;
    MonoidType E0;

    // update / combine function
    UpdateFunc  upd_f;
    CombineFunc cmb_f;

    void build(int m, vector<MonoidType> v = vector<MonoidType>()) {
        if(v != vector<MonoidType>()) m = v.size();
        n = 1; while(n < m) n *= 2;

        node = vector<MonoidType>(2*n-1, E0);
        if(v != vector<MonoidType>()) {
            for(int i=0; i<m; i++) {
                node[n-1+i] = v[i];
            }
            for(int i=n-2; i>=0; i--) {
                node[i] = cmb_f(node[2*i+1], node[2*i+2]);
            }
        }
    }

    // initialize
    SegmentTree() {}
    SegmentTree(int n_, MonoidType E0_,
                UpdateFunc upd_f_, CombineFunc cmb_f_,
                vector<MonoidType> v = vector<MonoidType>()) :
        E0(E0_), upd_f(upd_f_), cmb_f(cmb_f_) {
        build(n_, v);
    }

    // update k-th element (applied value: x)
    void update(int k, UpdateType x) {
        k += n - 1;
        node[k] = upd_f(node[k], x);
        while(k > 0) {
            k = (k - 1) / 2;
            node[k] = cmb_f(node[2*k+1], node[2*k+2]);
        }
    }

    // range query for [a, b)
    MonoidType query(int a, int b) {
        MonoidType vl = E0, vr = E0;
        for(int l=a+n, r=b+n; l<r; l>>=1, r>>=1) {
            if(l & 1) vl = cmb_f(vl, node[(l++)-1]);
            if(r & 1) vr = cmb_f(node[(--r)-1], vr);
        }
        return cmb_f(vl, vr);
    }
};


// Range Minimum Query
// query 1: update
// query 2: range minimum
void DSL_2_A() {
    int N, Q; cin >> N >> Q;
    SegmentTree<int, int> seg(N, INT_MAX,
                              [](int a, int b) { return b; },
                              [](int a, int b) { return min(a, b); });

    int indexed = 0;
    for(int i=0; i<Q; i++) {
        int query_type; cin >> query_type;
        int x, y; cin >> x >> y;
        if(query_type == 0) {
            x -= indexed;
            seg.update(x, y);
        }
        if(query_type == 1) {
            x -= indexed, y -= indexed;
            y++;
            cout << seg.query(x, y) << endl;
        }
    }
}

int main() {
    DSL_2_A();
    return 0;
}



Measured memory_bytes: 3856
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
////////////////////////////////////////
vector<ll>calc_divisor(ll n) {
	vector<ll>res;
	for (ll i = 1LL; i*i <= n; ++i) {
		if (n%i == 0) {
			res.push_back(i);
			ll j = n / i;
			if (j != i)res.push_back(j);
		}
	}
	sort(res.begin(), res.end());
	return res;
}

ll solve(ll N) {
	auto div = calc_divisor(N);
	ll res = 0;
	for (auto r : div) {
		if (N > r*r + r)res += (N - r) / r;
		else {
			break;
		}
	}
	return res;
}
int main() {
	ll N; cin >> N;
	cout << solve(N) << endl;
	return 0;
}


Measured memory_bytes: 384
using System;
using System.Linq;
using System.Collections.Generic;
public class Test
{
    public static void Main()
    {
        Console.ReadLine();
        long foo = 0;
        Console.WriteLine(new long[]{0}.Concat(Console.ReadLine().Split().Select(s => long.Parse(s))).Select(i=> { foo += i;return foo; }).GroupBy(v=>v).Select(g=>g.LongCount()).Where(i=>i>1).Select(i=>i*(i-1)/2).Sum());
        Console.ReadKey();
    }
}

Measured memory_bytes: 50460
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define wzh(x) cerr<<#x<<'='<<x<<endl;
int t,m,n,a[N];

int main() {
  ios::sync_with_stdio(false);
  for(t=1;t;t--){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    int x=a[1];
    LL tot=0;
    for(int i=1;i<=n;i++){
      if(a[i]<x){
        tot-=a[i]-x;
      }else x=a[i];
    }
    cout<<tot<<'\n';
  }
  return 0;
}

Measured memory_bytes: 4356
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

#define fo(i,j,l) for(int i=j;i<=l;++i)
#define fd(i,j,l) for(int i=j;i>=l;--i)

using namespace std;
typedef long long ll;
const ll N=32e2,mo=1e9+7;

ll f[2][N][2];

int n,m;

int main()
{
	cin>>n>>m;
	fo(i,1,n)f[0][i][0]=1;
	f[0][0][1]=1;
	int u=0,v;
	fo(i,1,m){
		v=u^1;
		fo(i,0,n)f[v][i][0]=f[v][i][1]=0;
		fo(i,0,n)f[u][i][0]=f[u][i][0]%mo,f[u][i][1]=f[u][i][1]%mo;
		fo(i,1,n)f[v][i-1][(i==1)]=f[v][i-1][(i==1)]+f[u][i][0],f[v][i-1][1]=f[v][i-1][1]+f[u][i][1];
		fo(i,1,n)f[v][i][(i==1)]=f[v][i][(i==1)]+f[u][i][0],f[v][i][1]=f[v][i][1]+f[u][i][1];
		fo(i,0,n-1)f[v][i][0]=f[v][i][0]+f[u][i][0],f[v][i][1]=f[v][i][1]+f[u][i][1];
		fo(i,0,n-1)f[v][i+1][0]=f[v][i+1][0]+f[u][i][0],f[v][i+1][1]=f[v][i+1][1]+f[u][i][1];
		u=v;
	}
	ll ans=0;
	fo(i,0,n)ans=(ans+f[u][i][1])%mo;
	cout<<ans;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    int N;
    std::cin >> N;

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

    int n_swaps = 0;
    for (int i = 0; i < N; i ++) {
        int minj = i;
        for (int j = i; j < N; j ++) {
            if (A[j] < A[minj]) {
                minj = j;
            }
        }
        if (A[i] != A[minj]) {
            std::swap(A[i], A[minj]);
            n_swaps += 1;
        }
    }

    for (int i = 0; i < N; i ++) {
        if (i > 0) std::cout << " ";
        std::cout << A[i];
    }
    std::cout << std::endl;
    std::cout << n_swaps << std::endl;
}



Measured memory_bytes: 3088
#include <stdio.h>

int main() {
  int H, W;
  int i, j;
  while (1) {
    scanf("%d %d", &H, &W);
    if (H == 0 && W == 0) break;
    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++) {
        putchar((i+j)%2 == 0 ? '#' : '.');
      }
      putchar('\n');
    }
    putchar('\n');
  }
  return 0;
}



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

int main(){
  int X, Y, Z;
  cin >> X >> Y >> Z;
  cout << Z << " " << X << " " << Y << " " << endl;
  return 0;
}

Measured memory_bytes: 256
a = input()
l = map(int, raw_input().split())

s = 100000000
ma = max(l)
mi = min(l)

for i in range(mi, ma + 1):
	t = 0
	for j in l:
		t += (j - i) ** 2
	if t < s:
		s = t

print s

Measured memory_bytes: 2568
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=998244353;


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=300005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}

int main(){
	LL n,a,b,k,ans=0;
	cin>>n>>a>>b>>k;
	cmbset(n+1);
	FOR(i,0,n+1){
		LL x=i*1LL,y;
		y=(k-a*x)/b;
		if(a*x+b*y!=k)continue;
		if(x<0||x>n||y<0||y>n)continue;
		int mnz=0,mxz=min(x,y);
		if(x+y>n)mnz=x+y-n;
		int tz=mxz-mnz;
		FOR(z,mnz,mnz+1){
			ans=add(mul(cmb(n,x),cmb(n,y)),ans);
		}
		//cout<<i<<" "<<ans<<endl;
	}
	cout<<ans;
    return 0;
}


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

int n, m, i, w, v, out;
int dp [100001];

int main ()
	{
	scanf ("%d%d",&n,&m);
	fill (dp+1, dp+100001, 1000000001);
	while (n--)
		{
		scanf ("%d%d",&w,&v);
		for (i=100000; i-v>=0; i--)
			{
			dp[i]=min(dp[i], dp[i-v]+w);
			if (dp[i]<=m)
				out=max(out,i);
			}
		}
	printf ("%d\n",out);
	return 0;
	}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

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

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	string s;
	bool b=false;
	cin >> s;
	ll n=(ll)s.size();
	for(ll i=0;i<n;i++){
		for(ll j=i;j<n+1;j++){
			string t=s.substr(0,i)+s.substr(j);
			if(t=="keyence") b=true;
		}
	}
	YES(b);
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
//#define all(x) (x).begin(),(x).end()
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int a[1000];
signed main(){
    int n;
    cin >> n;
    int sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    int avg = sum / n;
    int ans = INF;
    for(int i = avg-1;i <= avg + 2;i++){
        int cnt = 0;
        rep(j,n){
            cnt += (a[j] - i) * (a[j] - i);
        }
        ans = min(ans,cnt);
    }
    cout << ans << '\n';
    return 0;   
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/10/04  Problem: Nagoya_univ_contest_17_f  / Link:   ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;
int cnt[26][200005];//1 index
LL ans = 0LL;

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


	string S;
	cin >> S;
	FOR(a, 0, SZ(S)) {
		FOR(i, 0, 26) {
			cnt[i][a + 1] += cnt[i][a];
			if (S[a] - 'a' == i)cnt[i][a + 1]++;
		}
	}
	FOR(i, 1, SZ(S)) {
		ans += (i - cnt[S[i] - 'a'][i]);
	}

	ans++;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 20884
input1s = input()
input2s = input()

input1 = [int(i) for i in input1s.split(' ')]
N = input1[0]
P = input1[1]
array = [int(i) for i in input2s.split(' ')]

count = 0

for i in range(len(array)):
  if(array[i]%2 == 1):
    count = 1

if(count == 0):
  if(P == 0): print (2**N)
  else: print(0)
else:
  print (2**(N-1))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B;
    cin>>A>>B;
    A=A-1;
    B=B-1;
    int c=B%A;
    if(c!=0){
        cout<<B/A+1<<endl;
    }else{
        cout<<B/A<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_A
#include <bits/stdc++.h>

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

#define N_STACK 100

class Stack {
 private:
  int stack[N_STACK];
  int idx = 0;

 public:
  void push(int n) {
    idx++;
    stack[idx] = n;
  }

  int pop() {
    int n = stack[idx];
    idx--;
    return n;
  }

  bool isEmpty() { return idx == 0; }

  bool isFull() { return idx == N_STACK - 1; }
};

bool isOperator(string s) {
  return s[0] == '+' || s[0] == '-' || s[0] == '*' || s[0] == '/';
}

int calc(char op, int n1, int n2) {
  int ans;
  switch (op) {
    case '+':
      ans = n1 + n2;
      break;
    case '-':
      ans = n1 - n2;
      break;
    case '*':
      ans = n1 * n2;
      break;
    case '/':
      ans = n1 / n2;
      break;

    default:
      break;
  }
  return ans;
}

vector<string> split_str(string s, char delimitor) {
  vector<string> lst_str;
  string tmp = "";

  rep(i, s.size()) {
    if (s[i] == delimitor) {
      lst_str.push_back(tmp);
      tmp = "";
    } else {
      tmp += s[i];
    }
  }
  lst_str.push_back(tmp);
  return lst_str;
}

int main() {
  Stack stack;
  string l;

  getline(cin, l);
  vector<string> lst_s = split_str(l, ' ');

  rep(i, lst_s.size()) {
    string s = lst_s[i];
    if (isOperator(s)) {
      int n1, n2;
      n2 = stack.pop();
      n1 = stack.pop();
      stack.push(calc(s[0], n1, n2));
    } else {
      stack.push(atoi(s.c_str()));
    }
  }
  int ans = stack.pop();
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3164
#include <iostream>

#define MAX(a, b) (a > b ? a : b)
#define MIN(a, b) (a < b ? a : b)

constexpr auto NMAX = (int)2e5 + 20;
constexpr auto INF = 2000000000;
using namespace std;

typedef unsigned long long ull;

int r;
double const pi = 3.14159;

int main()
{
	cin >> r;
	cout << 2 * pi * r << '\n';
	return 0;
}

Measured memory_bytes: 3776
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
int main()
{
	long long a,b;
	char op;
	cin >> a >> op >> b;
	if(op=='+')
		cout << a+b;
	else
		cout << a-b;
	return 0;
}

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

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl

using namespace std;
using lli = long long int;

lli mod197 = 1000000007LL;

lli p[10] = {};
lli c[10] = {};

lli dp[11][10000] = {};

int main(void) {

	lli D, G;
	cin >> D >> G;

	for (int i = 0; i < D; i++)
		cin >> p[i] >> c[i];

	for (lli i = 0; i < D; i++) {
		for (lli j = 0; j <= p[i]; j++) {
			for (lli k = 0; k <= 1000; k++) {
				if(j == p[i])
					CHMAX(dp[i + 1][j + k], dp[i][k] + j * (i + 1) + c[i] / 100);
				else
					CHMAX(dp[i + 1][j + k], dp[i][k] + j * (i + 1));
			}
		}
	}

	for (lli k = 0; k <= 1000; k++) {
		if (dp[D][k] >= G / 100) {
			cout << k << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

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

	int l=-1,r=-1;
	for(int i=0;i<s.size();i++)
	{
		if(i<s.size()-1 && s[i]==s[i+1])
		{
			l=i+1;
			r=i+2;
			break;
		}
		if(i<s.size()-2 && s[i]==s[i+2])
		{
			l=i+1;
			r=i+3;
			break;
		}
	}

	cout << l << " " << r << endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
    int n, t = 0;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        if(i <= 9 || (i >= 100 && i <=999) || (i >= 10000 && i <= 99999))
           t++;
    }
    cout << t;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(x) (((long long)x)%modulo)



int main(){
	string S;
	cin>>S;
	int mini = 10000;
	if(S.size()==1){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<S.size()-1;i++){
		if(S[i]!=S[i+1])break;
		if(i==S.size()-2){
			cout<<0<<endl;
			return 0;
		}
	}
	
	for(int i='a';i<='z';i++){
		string T = S;
		bool flag = false;
		int cnt = 0;
		while(!flag){
			flag=true;
			string TT = "";
			for(int j=0;j<T.size()-1;j++){
				if(T[j]==i||T[j+1]==i)TT+=i;
				else{
					TT+=T[j];
					flag=false;
				}
			}
			T=TT;
			cnt++;
		}
		mini=min(mini,cnt);
	}
	
	cout<<mini<<endl;
				
				
	
	
	
	return 0;
}


Measured memory_bytes: 256
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    ll ans[10000001];


    void init()
    {
        for (int i = 1; i <= 10000000; ++i)
            ans[i]=1;
        int ct=0,x;
        for (int i = 2; i <= 10000000; ++i)
        {
            if(ans[i]!=1)
                continue;
         for (int j = i; j <= 10000000; j += i)
         {
            ct=0;
            x=j;
            while(x%i==0)
            {
                ++ct;
                x=x/i;
            }
            ans[j]*=(ct+1);
         }
        }
        ans[0]=0;
        for(int i=1;i<=10000000;++i)
        {
            ans[i]=ans[i-1]+ans[i]*i;
        }
    }

    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        init();
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n;
            cin>>n;
            cout<<ans[n]<<endl;
        }
        return 0;
    }


Measured memory_bytes: 81768
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define PI 3.141592653589793

using namespace std;
using ll = long long;

ll X[13];

int main() {

	int r, D;

	cin >> r >> D >> X[0];

	for(int i=1;i<=10;i++){
	
		X[i] = r * X[i - 1] - D;
		cout << X[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
   int n,a,b,c;

   while(true){
       scanf("%d",&n);
       if(n == 0)break;

       for(int i = 0; i < n; i++){
           scanf("%d %d %d",&a,&b,&c);
           if(a == 100 || b == 100 || c == 100 || a + b >= 180 || a+b+c >= 240){
               printf("A\n");
           }else if((a + b + c >= 210) || (a+b+c>=150 && (a >= 80 || b >= 80))){
               printf("B\n");
           }else{
               printf("C\n");
           }
       }

   }
   return 0;
}


Measured memory_bytes: 2500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

int a[200010];
int b[200010];
int n;

int main()
{
	read(n);
	for(int i=1; i<=n; ++i){
		scanf("%d", a+i); b[i]=a[i];
	}
	sort(b+1, b+n+1);
	for(int i=1; i<=n; ++i) printf("%d\n", b[n/2+(a[i] <= b[n/2])]);
	return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int H, W, a[2000][2000], res;
string S[2000];

int main(){
	cin >> H >> W;
	for (int i = 0; i < H; ++i) {
		cin >> S[i];
	}
	for (int i = 1; i < H; ++i) {
		for (int j = 0; j < W - 1; ++j) {
			int t = 0;
			for (int k = 0; k < 4; ++k) {
				t += (S[i - k % 2][j + k / 2] == '#');
			}
			if (t & 1) {
				a[i][j] = 1;
			}
		}
	}
	for (int i = 0; i < W; ++i) {
		a[0][i] = 1;
	}
	for (int i = 1; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			if (!a[i][j]) {
				a[i][j] = a[i - 1][j] + 1;
			}
		}
	}
	/*
	for (int i = 0; i < H; ++i) {
		for (int j = 0; j < W; ++j) {
			cout << a[i][j] << sp;
		}
		cout << endl;
	}
	*/
	res = H;
	for (int i = 0; i < H; ++i) {
		vector<pair<int, int>>vec;
		vec.push_back(mkp(-1, 0));
		for (int j = 0; j < W; ++j) {
			while (vec.back().second > a[i][j]) {
				res = max(res, vec.back().second*(j - vec[vec.size() - 2].first));
				vec.pop_back();
			}
			vec.push_back(mkp(j, a[i][j]));
		}
		while (vec.size() >= 2) {
			res = max(res, vec.back().second*(W - 1 - vec[vec.size() - 2].first));
			vec.pop_back();
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 19968
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<vector>
#include<cctype>
using namespace std;

class Saikoro{//サイコロを表すクラス
	private:
	int rab[6];//ラベル
	public:
	void setrab(int rabs[6]);
	void getrab();
	int gettop();
	void N();
	void E();
	void S();
	void W();
};

void Saikoro::setrab(int rabs[6]){
	for(int i=0;i<6;i++)rab[i]=rabs[i];
}
void Saikoro::getrab(){
	for(int i=0;i<6;i++)cout<<rab[i]<<endl;
}
void Saikoro::N(){
	int a;
	a=rab[0];rab[0]=rab[1];rab[1]=rab[5];rab[5]=rab[4];rab[4]=a;

}
void Saikoro::E(){
	int a;
	a=rab[0];rab[0]=rab[3];rab[3]=rab[5];rab[5]=rab[2];rab[2]=a;

}
void Saikoro::S(){
	int a;
	a=rab[0];rab[0]=rab[4];rab[4]=rab[5];rab[5]=rab[1];rab[1]=a;

}
void Saikoro:: W(){
int a;
a=rab[0];rab[0]=rab[2];rab[2]=rab[5];rab[5]=rab[3];rab[3]=a;
}
int Saikoro::gettop(){
	return rab[0];
}


//ITP1_8
int main(){
	int a[6];
	for(int i=0;i<6;i++)cin>>a[i];
	string n;
	cin>>n;
	Saikoro saikoro1;
	saikoro1.setrab(a);
	for(int i=0;i<n.size();i++){
	if(n[i]=='N')saikoro1.N();
	else if(n[i]=='S')saikoro1.S();
	else if(n[i]=='E')saikoro1.E();
	else if(n[i]=='W')saikoro1.W();
	}
	cout<<saikoro1.gettop()<<endl;
return 0;
}

Measured memory_bytes: 1204
fun main(args: Array<String>) {
    val (N, M) = listOfInt()
    val X = LongArray(N); val Y = LongArray(N); val Z = LongArray(N)
    repeat(N) { n ->
        val (x, y, z) = listOfLong()
        X[n] = x; Y[n] = y; Z[n] = z
    }
    var ans = 0L
    for (b in 0 until 8) {
        val A = LongArray(N)
        for (n in 0 until N) {
            A[n] += (if ((b and 1) == 0) X[n] else -X[n])
            A[n] += (if ((b and 2) == 0) Y[n] else -Y[n])
            A[n] += (if ((b and 4) == 0) Z[n] else -Z[n])
        }
        A.sortDescending()
        var w = A.slice(0 until M).sum()
        if (ans < w) ans = w
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }


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

#define INF 200000000
#define FER 0.0000000001

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;

int dp[10001];
int v[1000];
int w[1000];
int m[1000];

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

	int N, W;
	cin >> N >> W;

	for (int i = 0; i < N; i++)
	{
		cin >> v[i] >> w[i];// >> m[i];
	}

	for (int i = 0; i < N; i++)for (int j = 0; j <= W; j++)
	{
		if (w[i] <= j)
		{
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
		}
	}

	cout << dp[W] << endl;
	
	return 0;
}


Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)

int CH[4001][4001], A, B, sc[2001][2001], md = 1e9 + 7;

inline void ad(int &x, int y) { if ((x += y) >= md)x -= md; }
inline int ch(int n, int a) { int t = CH[n][a] - (a ? CH[n][a - 1] : 0); return t < 0 ? t + md : t; }
inline int ch(int n, int l, int r) { int t = CH[n][r] - (l ? CH[n][l - 1] : 0); return t < 0 ? t + md : t; }

int main(){
	f(i, 0, 4001){
		CH[i][0] = 1;
		f(j, 1, i + 1)ad(CH[i][j], CH[i - 1][j] + CH[i - 1][j - 1]);
	}
	f(i, 1, 4001)f(j, 1, i + 1)ad(CH[i][j], CH[i][j - 1]);
	
	scanf("%d%d", &A, &B);
	
	f(i, 0, A + 1){
		int kl = B - 1;
		f(a, 0, min(i, kl) + 1)ad(sc[i - a][B - 1 - kl + a], ch(kl, a));  
	}
	
	for (int i = A - 1; i >= 0; --i)f(j, 1, B + 1)ad(sc[i][j], sc[i + 1][j]);
	
	int an = 0;
	f(i, 0, A + 1)f(j, 0, B + 1){
		int &v = sc[i][j];
		if (v == 0)continue;
		int a = i, b = j;
		if (b == 0) { ad(an, v); continue; }
		--b;
		int kl = b, l = 0, r = min(a, kl);
		ad(an, (ll)ch(kl, l, r) * v % md);
	}
	printf("%d\n", an);
}

Measured memory_bytes: 78464
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }



signed main()
{
	int N, K;
	int X[101];

	cin >> N;
	cin >> K;
	REP(i, N) cin >> X[i];

	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		ans += min(X[i], abs(K - X[i])) * 2;
	}
	cout << ans << endl;
}



Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i < n; ++i)
using namespace std;
const int INF = 2147483647;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> x(n);
    for (int i=0;i<n;i++){
        cin >> x.at(i);
    }
    vector<int> b = x;
    sort(b.begin(),b.end());
    int l,r;
    l = b.at(n/2-1);
    r = b.at(n/2);
    vector<int> ans(n);
    for (int i=0;i<n;i++){
        if(x.at(i)<=l) ans.at(i) = r;
        else ans.at(i) = l;
    }
    for (int i=0;i<n;i++){
        cout << ans.at(i) << '\n';
    }
    return 0;
}



Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <stack>
#include <cstring>
using namespace std;

#define MAX_LENGTH  3000

string s1;					//string 1
string s2;					//string 2
stack <char> soln;	//soln stack
int dp[MAX_LENGTH][MAX_LENGTH];

//Memoisation solution
//step 1 : Base Case
//step 2 : if soln not computed already then compute recursively
//step 3 : return the soln
int solve(int p1,int p2){
	if(p1<0||p2<0)
		return 0;
	if(dp[p1][p2]==-1){
		if(s1[p1]==s2[p2])
			dp[p1][p2] = 1+ solve(p1-1,p2-1);
		dp[p1][p2] = max( dp[p1][p2] , max( solve(p1-1,p2) , solve(p1,p2-1) ));
	}
	return dp[p1][p2];
}

void build(int p1,int p2){
	if(p1<0||p2<0)
		return;
	if(s1[p1]==s2[p2]){
		soln.push(s1[p1]);
		build(p1-1,p2-1);
		return;
	}
	if(p1>0 && p2>0){
		if(dp[p1-1][p2] > dp[p1][p2-1] )
			build(p1-1,p2);
		else
			build(p1,p2-1);
	}
	else if(p1>0)
		build(p1-1,p2);
	else if(p2>0)
		build(p1,p2-1);
	return;
}

int main(){
	
	memset(dp,-1,sizeof(dp));
	//memset(first_ptr,value,size_in_bytes)
	//sets the bytes equal to the given value
	//initial state of our dp table

	cin>>s1>>s2;
	int L = s1.length();
	int M = s2.length();

	solve(L-1,M-1);
	build(L-1,M-1);
	
	while(!soln.empty()){
		cout<<soln.top();
		soln.pop();
	}
}


Measured memory_bytes: 35840
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n = I()
xy = [LI() for _ in range(n)]

def d(x1,y1,x2,y2):
    return math.sqrt((x1-x2)**2 + (y1-y2)**2)

def f(x,y):
    res = 0
    for x1,y1 in xy:
        res = max(res,d(x,y,x1,y1))
    return res

def g(x):
    l,r = 0,1000
    for _ in range(80):
        a = (l*2+r)/3
        b = (l+r*2)/3
        if f(x,a) > f(x,b):
            l = a
        else:
            r = b
    return f(x,l)

l,r = 0,1000
for _ in range(80):
    a = (l*2+r)/3
    b = (l+r*2)/3
    if g(a) > g(b):
        l = a
    else:
        r = b
print(g(l))




Measured memory_bytes: 47596
#include<stdio.h>
#include<string.h>
int main(void){
    int m,i,h,len;
    int count=0;
    char str[404],inc[203];
    while(1){
        scanf("%s",str);
        if(str[0]=='-'){
            break;
        }
        scanf("%d",&m);
        for(i=0;i<m;i++){
            scanf("%d",&h);
            count+=h;
        }
        len=strlen(str);
        count%=len;
        strcpy(inc,str);
        strcat(str,inc);
        strncpy(inc,str+count,len);
        printf("%s\n",inc);
        count=0;
    }
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <math.h>
#include <algorithm> // sort

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

const int MOD = 1000000007;

//h,n,w
int main(){
    ll N;
    cin >> N;
    REP(i,N)
    {
        int a;
        cin >> a;
        if(a % 2 != 0)
        {
            cout << "first" << endl;
            return 0;
        }
    }

    cout << "second" << endl;
    return 0;    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<stdlib.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+5;
ll a[maxn];
int main()
{
	ll n;
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	ll d=0,k=0;
	for(ll i=1;i<=n;i++)
	{
		if(a[i]%4==0)
		d++;
		if(a[i]%2==0&&a[i]%4!=0)
		k++;
	}
	ll p;
	if(d!=0)
	p=n-d*2-1;
	else
	p=n;
	if(p<k||p==0||k==n)
	printf("Yes\n");
	else
	printf("No\n");
	return 0;
}

Measured memory_bytes: 896
KN = list(map(int, input().split()))
A = list(map(int, input().split()))

answer = []

for i,home in enumerate(A):
    if home < A[i - 1]:
        answer.append(home - A[i - 1] + KN[0])
    else:
        answer.append(home - A[i - 1])

print(KN[0] - max(answer))


Measured memory_bytes: 26444
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int Y = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        Integer[] p = new Integer[A];
        Integer[] q = new Integer[B];
        Integer[] r = new Integer[C];
        for (int i=0;i<A;i++) p[i] = sc.nextInt();
        for (int i=0;i<B;i++) q[i] = sc.nextInt();
        for (int i=0;i<C;i++) r[i] = sc.nextInt();

        Arrays.sort(p, (o1, o2)->Integer.compare(o2, o1));
        Arrays.sort(q, (o1, o2)->Integer.compare(o2, o1));
        Arrays.sort(r);

        PriorityQueue<Integer> r_ = new PriorityQueue<Integer>((o1, o2)->Integer.compare(o2, o1));
        for (int i=0;i<C;i++) {
            r_.add(r[i]);
        }

        long ans = 0L;
        PriorityQueue<int[]> p_q = new PriorityQueue<int[]>((o1, o2)->Integer.compare(o1[0], o2[0]));
        for (int i=0;i<X;i++) {
            int[] add = {p[i], 0};
            ans += p[i];
            p_q.add(add);
        }
        for (int i=0;i<Y;i++) {
            int[] add = {q[i], 1};
            ans += q[i];
            p_q.add(add);
        }

        // System.out.println(ans);
        // System.out.println(Arrays.toString(r));
        for (int i=C-1;i>=0;i--) {
            int[] rem = p_q.peek();
            // System.out.println(i);
            // System.out.println(Arrays.toString(rem));
            if (rem[0]>=r[i]) {
                break;
            } else {
                ans-=rem[0];
                ans+=r[i];
                p_q.poll();
            }
        }
        System.out.println(ans);
    }
}

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

int main()
{
    int n,m,sum=0;
    cin>>n>>m;
    int matrix[n][m];
    int vector[m][1];
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>matrix[i][j];
        }
    }
    
    for(int i=0;i<m;i++){
        for(int j=0;j<1;j++){
            cin>>vector[i][j];
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            sum=sum+(matrix[i][j]*vector[j][0]);
        }
        cout<<sum<<"\n";
        sum=0;
    }
 
    return 0;
}


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

const int INF = 1e+9;

int main() {
	string s;
	while(cin >> s){
		vector<int> now;
		vector<int> next;
		next.resize(10);
		for(int i = 0; i < s.size(); ++i)
			now.push_back(s[i] - '0');
		for(int i = 0; i < 9; ++i){
			for(int j = 0; j < 10 - i - 1; ++j){
				next[j] = (now[j] + now[j + 1]) % 10;
			}
			now = next;
		}
		cout << now[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<vector>
#include<cstdlib>
#include<cmath>
#define range(i,a,b) for(int i = (a); i <= (b); i++)
#define rrange(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,b) for(int i = 1; i <= (b); i++)
#define rrep(i,b) for(int i = (b); i >= 1; i--)
#define all(a) (a).begin(), (a).end()
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long ll;
const int N=2e5+11;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001LL;
template<typename T> void chmin(T& a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T& a, T b) { if (a < b) a = b; }
int n,m;
map<int,int> mp;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return f*x;
}
int main(){
//	freopen("ex.in","r",stdin);
	n=read();
	rep(i,n){
		int tmp=read();
		mp[tmp]++;
	}
	m=read();
	rep(i,m){
		int tmp=read();
		if(mp[tmp]==0){
			printf("NO");return 0;
		}
		mp[tmp]--;
	}
	printf("YES");
	return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main() {
    ll A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;
    if(A+B <= 2*C){
        cout << A*X + B*Y;
    }else{
      ll ans = 0;
      ans = min(X,Y) * 2 * C;
      ll tmp = min(X,Y);
      X = X - tmp;
      Y = Y - tmp;
      ans += X * min(A,2 * C) + Y * min(B,2 * C);
      cout << ans;

    }
}


Measured memory_bytes: 256