akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
 int r,c;
 cin>>r>>c;
 
 int num [101][101] = {};
 for(int i=0;i<r;i++)
  for(int j=0;j<c;j++) cin>>num[i][j];

for(int i=0;i<r;i++)
 for(int j=0;j<c;j++) num[r][c] += num[i][j];

for(int i=0;i<r;i++){
 int sum = 0;
 for(int j=0;j<c;j++) sum += num[i][j];
 num[i][c] = sum;
}

for(int j=0;j<c;j++){
 int sum =0;
 for (int i=0;i<r;i++) sum += num[i][j];
 num[r][j] = sum;
}

for(int i=0;i<=r;i++){
 for(int j=0;j<=c;j++){
   if(j) cout<<" "; 
   cout<<num[i][j];
}
cout<<endl;
}
}


Measured memory_bytes: 3120
nu1,nu2 = gets.chomp.split(" ").map(&:to_i)
nu = [nu1, nu2]
wo1 = gets.chomp.split("")
wo2 = gets.chomp.split("")
if wo1[0] != wo2[0]
  puts "-1"
  exit
end
pr = []
require 'prime'
Prime.each(10**5) do |prime|
  pr.push(prime)
end
nu1_p = Array.new(pr.length, 0)
nu2_p = Array.new(pr.length, 0)
for i in 1..pr.length
  if nu1 % pr[i - 1] == 0
    while nu1 % pr[i - 1] == 0
      nu1 /= pr[i - 1]
      nu1_p[i - 1] += 1
    end
  end
end
for i in 1..pr.length
  if nu2 % pr[i - 1] == 0
    while nu2 % pr[i - 1] == 0
      nu2 /= pr[i - 1]
      nu2_p[i - 1] += 1
    end
  end
end
min = 1
for i in 1..pr.length
  if (nu1_p[i - 1] >= nu2_p[i - 1])
    if pr[i - 1]*nu1_p[i - 1] != 0
      min *= pr[i - 1]**nu1_p[i - 1]
    end
  elsif (nu1_p[i - 1] < nu2_p[i - 1])
    if pr[i - 1]*nu2_p[i - 1] != 0
      min *= pr[i - 1]**nu2_p[i - 1]
    end
  end
end
nu3 = min / nu[0]
nu4 = min / nu[1]
count = 1 + (min / nu[0])*nu4
count1 = (min / nu[1]) + 1
count2 = (min / nu[0]) + 1
while count <= min
  if wo1[count1 - 1] != wo2[count2 - 1]
    puts "-1"
    exit
  end
  count += (min / nu[0])*nu4
  count1 += (min / nu[1])
  count2 += (min / nu[0])
end
puts min


Measured memory_bytes: 11580
#include <iostream>

int main() {

  long N, M;
  long result;
  std::cin >> N >> M;
  if(N >= M / 2){
    result = M / 2;
  }else{
    result = N + (M - N * 2) / 4;
  }
  std::cout << result;
  return 0;
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define MAXN 200005
#define eps 1e-10
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
	res = 0;T f = 1;char c = getchar();
	while(c < '0' || c > '9') {
		if(c == '-') f = -1;
		c = getchar();
	}
	while(c >= '0' && c <= '9') {
		res = res * 10 + c - '0';
		c = getchar();
	}
	res *= f;
}
template<class T>
void out(T x) {
	if(x < 0) {x = -x;putchar('-');}
	if(x >= 10) {
		out(x / 10);
	}
	putchar('0' + x % 10);
}
const int MOD = 1000000007;
int inc(int a,int b) {
	return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
	return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
	int res = 1,t = x;
	while(c) {
		if(c & 1) res = mul(res,t);
		t = mul(t,t);
		c >>= 1;
	}
	return res;
}
int N,Q,Inv2;
int dp[3005][3005],f[3005][3005];
int A[3005];
void Solve() {
	Inv2 = (MOD + 1) / 2;
	read(N);read(Q);
	for(int i = 1 ; i <= N ; ++i) read(A[i]);
	for(int i = 1 ; i <= N ; ++i) {
		for(int j = 1 ; j <= N ; ++j) {
			if(A[i] > A[j]) dp[i][j] = 1;
		}
	}
	int x,y;
	for(int i = 1 ; i <= Q ; ++i) {
		read(x);read(y);
		for(int j = 1 ; j <= N ; ++j) {
			f[x][j] = dp[x][j];
			f[j][x] = dp[j][x];
			f[j][y] = dp[j][y];
			f[y][j] = dp[y][j];
		}
		for(int j = 1 ; j <= N ; ++j) {
			if(j != x && j != y)
			dp[x][j] = mul(Inv2,inc(f[x][j],f[y][j]));
			dp[j][x] = mul(Inv2,inc(f[j][x],f[j][y]));
			dp[y][j] = mul(Inv2,inc(f[y][j],f[x][j]));
			dp[j][y] = mul(Inv2,inc(f[j][y],f[j][x]));
		}
		dp[x][y] = mul(Inv2,inc(f[x][y],f[y][x]));
		dp[y][x] = mul(Inv2,inc(f[y][x],f[x][y]));
	}
	int ans = 0;
	for(int i = 1 ; i <= N ; ++i) {
		for(int j = i + 1 ; j <= N ; ++j) {
			ans = inc(ans,dp[i][j]);
		}
	}
	ans = mul(ans,fpow(2,Q));
	out(ans);enter;
}
int main() {
#ifdef ivorysi
	freopen("f1.in","r",stdin);
#endif
	Solve();
}


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

int main() {
  int n, k, l, s = 0;
  cin >> n >> k;
  vector<int> v;
  REP(i, n) {
    cin >> l;
    v.push_back(l);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  REP(i, k) s += v[i];
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const ll MOD=1e9+7;


int main() {
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<vector<pair<int,int>>> r(n);
    rep(i,n-1) {
        int u,v,w;
        cin >> u >> v >> w;
        r[u-1].push_back(make_pair(v-1,w));
        r[v-1].push_back(make_pair(u-1,w));
    }
    queue<int> q; 
    q.push(0);
    vector<ll> cost(n,-1);
    cost[0]=0;
    while (!q.empty()) {
        int now=q.front();
        q.pop();
        rep(i,r[now].size()) {
            int next=r[now][i].first;
            ll c=r[now][i].second;
            if (cost[next]==-1) {
                cost[next]=cost[now]+c;
                q.push(next);
            }
        }
    }
    rep(i,n) cout << cost[i]%2 << endl;

    return 0;
}

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

using namespace std;

int N, M;
vector<vector<int>> g;
vector<int> memo;

int solve(int u) {
    if (memo[u] != -1) return memo[u];
    int res = 0;
    for (int v : g[u]) {
        res = max(res, 1 + solve(v));
    }
    memo[u] = res;
    return res;
}

int main(int argc, char *argv[])
{
    cin >> N >> M;
    g.resize(N + 1);
    memo.resize(N + 1, -1);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
    }
    int res = 0;
    for (int i = 0; i < N; i++) {
        res = max(res, solve(i));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 8192
n, m = map(int, input().split())
S = []
C = []
for _ in range(m):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)

ans = -1
for i in range(0, 1001):
    now = str(i)
    if len(now) != n:
        continue
    check = True
    for j in range(m):
        if now[S[j]-1] != str(C[j]):
            check = False
    if check == True:
        ans = i
        break
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MOD = ((int)1e9)+7;
const int INF = (int)(1e9)+(int)(1e7);
const ll INFL = (ll)(1e18)+INF;
const double EPS = 1e-8;
using namespace std;
int main()
{
   int N,M;
   cin >> N >> M;
   vector<int>s(M);
   vector<char>c(M);
   rep(i,M)cin >> s[i] >> c[i];
   for(int i=0;i<=999;i++){
       string t= to_string(i);
       //cout << t[0] << endl;
       if(t.size()!=N)continue;
       bool ok=true;
       rep(j,M){
           ok&=(t[s[j]-1]==c[j]);
       }
       if(ok){
           cout << i << endl;
           return 0;
       }
   }
   cout << -1 << endl;
   return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

    def string():
        return sys.stdin.readline().rstrip()

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.int_list_list(2)
    ans = 0
    for i in range(N):
        cnt = sum(A[0][:i + 1]) + sum(A[1][i:])
        ans = max(ans, cnt)
    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 38768
N,C = map(int,input().split())
x,v = [],[]
for i in range(N):
	X,V = map(int,input().split())
	x.append(X)
	v.append(V)

V_tokei = []
V_hantokei = []
for i in range(N):
	if i == 0:
		V_tokei.append((v[i] - x[i], x[i]))
		V_hantokei.append(((v[N-i-1] - (C - x[N-i-1])), x[N-i-1]))
	else:
		V_tokei.append(((V_tokei[i-1][0] + v[i] - (x[i] - V_tokei[i-1][1])), x[i]))
		V_hantokei.append(((V_hantokei[i-1][0] + v[N-i-1] - (V_hantokei[i-1][1] - x[N-i-1]), x[N-i-1])))

# n <= i での V_hantokeiの最大値
V_hantokei_max = [V_hantokei[0][0]]
# n <= i での V_tokeiの最大値
V_tokei_max = [V_tokei[0][0]]
for i in range(1,N):
	V_hantokei_max.append(max(V_hantokei_max[i-1], V_hantokei[i][0]))
	V_tokei_max.append(max(V_tokei_max[i-1], V_tokei[i][0]))

v_mix_max = 0
for i in range(0, N-1):
	v_mix_max = max(v_mix_max, V_tokei[i][0] - V_tokei[i][1] + V_hantokei_max[N - i - 2])
	v_mix_max = max(v_mix_max, V_hantokei[i][0] - (C - V_hantokei[i][1]) + V_tokei_max[N - i - 2])
print(max(max([v[0] for v in V_hantokei] + [0]), max([v[0] for v in V_tokei] + [0]), v_mix_max))



Measured memory_bytes: 35900
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
int main()
{
	int n,m;lint out=0;
	cin>>n>>m;out=n*100+m*1800;
	rep(i,m) out*=2;
	cout<<out<<endl;
}


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

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var b = int.Parse(Console.ReadLine());
            var c = int.Parse(Console.ReadLine());
            var d = int.Parse(Console.ReadLine());
            var e = int.Parse(Console.ReadLine());

            var list = new[] { a, b, c, d, e };

            var m = 0;
            var output = 0;
            foreach (var x in list)
            {
                var n = 10 - x % 10;
                if (n == 10) n = 0;

                output += x + n;

                m = Math.Max(m, n);
            }

            output -= m;

            Console.Write(output);
        }
    }
}


Measured memory_bytes: 11092
/*************************************************************************
    > File Name: ALDS1_1_A.cpp
    > Author: Wqr_
    > Mail: xueduanwei@126.com 
    > Created Time: Tue Oct 23 08:44:17 2018
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin >> n;
    int in[n];
    for(int i = 0; i < n; i++){
        cin >> in[i];
    }
    for(int i = 0; i < n; i++){
        if(i) cout << " ";
        cout << in[i];
    }
    cout << endl;
    for(int i = 1; i < n; i++){
        int v = in[i];
        int j = i - 1;
        while(j >= 0 && in[j] > v){
            in[j+1] = in[j];
            j--;
        }
        in[j+1] = v;
        for(int i = 0; i < n; i++){
            if(i) cout << " ";
            cout << in[i];
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3108
import java.util.*;
public class Main {
    public static long mod(long x, long y){
    return x%y<0?x%y+(y<0?-y:y):x%y;
    }
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		long [] in = new long [a];
        long b = 1000000007;
        long sum = 0;
        long mul = 0;
        for(int i=0;i<a;i++){
                             in[i] = sc.nextLong();
                             sum+=in[i];
                             mul+=in[i]*in[i];
                             sum=mod(sum,b);
                             mul=mod(mul,b);
                            }       
        long ans = mod(sum*sum-mul,b);
        if(ans%2==1){ans+=b;}
        ans/=2;
		System.out.println(ans);
	}
}

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

int main() {
    int h, w;
    cin >> h >> w;

    char s[52][52] = {};
    for (int i = 0; i < h; i++) {
        cin >> &s[i + 1][1];
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            if (s[i][j] == '#') continue;
            int k = 0;
            for (int a = 0; a < 3; a++) {
                for (int b = 0; b < 3; b++) {
                    if (s[i + a - 1][j + b - 1] == '#') k++;
                }
            }
            s[i][j] = '0' + k;
        }
    }

    for (int i = 0; i < h; i++) {
        cout << &s[i + 1][1] << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)
#define setp(X,Y) cout<<fixed<<setprecision(Y)<<X;
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[10010];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	sort(A,A+N);
	double d=A[0];
	for(int i=1;i<N;i++){
		d+=A[i];
		d/=2;
	}
	setp(d,10)
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
S= input()
s_list=S.split("/")
s_list[0]=int(s_list[0])
s_list[1]=int(s_list[1])
s_list[2]=int(s_list[2])
if s_list[0]<2019:
    print('Heisei')
elif (s_list[0]==2019) and (s_list[1]<=4):
    print('Heisei')
else:
    print('TBD')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int r, g, b, n;
  cin >> r >> g >> b >> n;
  long long ans = 0;
  for (int i = 0; i <= 3000; i++) {
    for (int j = 0; j <= 3000; j++) {
      int t = n - r * i - g * j;
      if (t >= 0 && t % b == 0) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long n;
  cin >> n;
  long long even = 0LL, odd = 0LL, e_cnt = 0LL, o_cnt = 0LL;
  for(int i = 0; i < n; i++){
    long long a;
    cin >> a;
    even += a;
    odd += a;
    if(i%2 == 0){
      if(even <= 0){
        e_cnt += abs(even)+1LL;
        even = 1LL;
      }
      if(odd >= 0){
        o_cnt += abs(odd)+1LL;
        odd = -1LL;
      }
    }
    else{
      if(even >= 0){
        e_cnt += abs(even)+1LL;
        even = -1LL;
      }
      if(odd <= 0){
        o_cnt += abs(odd)+1LL;
        odd = 1LL;
      }
    }
  }
  cout << min(e_cnt, o_cnt) << endl;
  return 0;
}

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

int main(){

int a , h , m , s;

cin >> a;

h = a / 3600;

m = (a - 3600 * h) / 60;

s = a - ( ( 3600 * h ) + ( 60 * m ) );

cout << h << ":"<< m <<":"<< s << endl;
 
return 0;

}


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;

void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}

int f[100001];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n;
    cin >> n;
    int h[n + 1];
    FOR(i, 1, n) cin >> h[i];
    if(n == 1) cout << 0;
    else
    {
        int t = 0, res = 0;
        FORd(i, n - 1, 1)
        {

            if(h[i] >= h[i + 1])
            {
                t++;
            }
            else
            {
                res = max(res, t);
                t = 0;
            }
        }
        res = max(res, t);
        cout << res;

    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long N,A,B;
  cin >> N >> A >> B;
  long long ans=0;
  ans += (N/(A+B))*A;
  ans += min(N%(A+B),A);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

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

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 5005;
const int mo = 1e9+7;

int n;
struct node{
	int x,nxt;
}e[N*2];
int h[N],tot;
int s[N];
int key,v;
LL js[N],inv[N];
LL f[N];

void inse(int x,int y){e[++tot].x=y;e[tot].nxt=h[x];h[x]=tot;}

void dfs(int x){
	s[x]=1;
	int mx=0;
	for(int p=h[x];p;p=e[p].nxt)
	if (!s[e[p].x]){
		dfs(e[p].x);
		s[x]+=s[e[p].x];
		mx=max(mx,s[e[p].x]);
	}
	mx=max(mx,n-s[x]);
	if (!key||mx<v){
		v=mx;
		key=x;
	}
}

int a[N],k;
LL A[N],B[N];

LL calc(int n,int m){return js[n]*inv[m]%mo*inv[n-m]%mo;}

LL add(LL x,LL y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	n=get();
	fo(i,2,n){
		int x=get(),y=get();
		inse(x,y),inse(y,x);
	}
	dfs(1);
	if (v==n/2&&n%2==0){
		LL tmp=1;
		fo(i,2,v)tmp=tmp*i%mo;
		printf("%lld\n",tmp*tmp%mo);
		return 0;
	}
	js[0]=1;
	fo(i,1,n)js[i]=js[i-1]*i%mo;
	inv[0]=inv[1]=1;
	fo(i,2,n)inv[i]=1ll*(mo-mo/i)*inv[mo%i]%mo;
	fo(i,2,n)inv[i]=inv[i]*inv[i-1]%mo;
	k=0;
	if (s[key]<n)a[k=1]=n-s[key];
	for(int p=h[key];p;p=e[p].nxt)
	if (s[e[p].x]<s[key])a[++k]=s[e[p].x];
	s[++k]=1;
	f[0]=1;
	int pre=0;
	fo(i,1,k){
		fo(x,0,pre)A[x]=f[x];
		fo(x,0,a[i])B[x]=calc(a[i],x)*js[a[i]]%mo*inv[a[i]-x]%mo;
		fo(x,0,pre+a[i])f[x]=0;
		fo(x,0,pre)
			fo(y,0,a[i])f[x+y]=add(f[x+y],A[x]*B[y]%mo);
		pre+=a[i];
	}
	fo(i,0,n)f[i]=f[i]*js[n-i]%mo;
	LL ans=0;
	fo(i,0,n)
	if (i&1)ans=(ans+mo-f[i])%mo;else ans=add(ans,f[i]);
	printf("%lld\n",ans);
	return 0;
}

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

string k;
bool nice(int x) {
	for (int i = 0; i < k.size(); ++i, --x)
		if (k[i] == k[i + 1])
			++i;
	return x <= 0;
}

int main() {
	cin >> k; int x = 0, tag = 0;
	for (int i = 0; i < k.size(); ++i, ++x)
		if (!tag && k[i] == k[i + 1])
			++i, tag = 1;
		else if (tag) tag = 0;
	printf("%d\n", x);
	return 0;
}

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

using namespace std;

int x;
int vis[5];

int main(){
	cin>>x;
	vis[x]=1;
	cin>>x;
	vis[x]=1;
	for(int i=1;i<=3;i++) if(!vis[i]) cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 256
"use strict";
const Main = (input) =>{
   let xs = input.trim().split(' ').map(v=>parseInt(v,10));
   let ans = 0;
   for(let i=1; i<=10; i++){
     if(xs[0]<=1000*i){
        ans = 1000*i -xs[0];
        break;
     }
   }
   console.log(ans);
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

int Solve(string s) {
    int n = s.size();
    int start1 = 0, start2 = 1, cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] - '0' != start1)
            cnt1++;
        if (s[i] - '0' != start2)
            cnt2++;
        start1 = 1 - start1;
        start2 = 1 - start2;
    }
    return min(cnt1, cnt2);
}


int main() {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  cout<<Solve(S);
    return 0;
}



Measured memory_bytes: 512
N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

MOD = 10**9 + 7

safe = [True] * (N+1)
for i in range(len(A)):
    safe[A[i]] = False

dp = [0] * (N+1)
dp[0] = 1
if safe[1]:
    dp[1] = 1

for i in range(2, N+1):
    if(safe[i]):
        dp[i] = dp[i-1] + dp[(i-2)]
        dp[i] = dp[i] % MOD
    else:
        dp[i] = 0

print(dp[N])

Measured memory_bytes: 14456
#include<bits/stdc++.h>
using namespace std;
#define ll  long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;

int main(){

    int n;  cin >> n;
    for(int i=0;i<n;i++){
        cout << "ACL" ;
    }
    cout << endl;
    

}
       


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

using namespace std;

long long f(long long n) {
    if (n % 4 == 0 ) return 0^n;
    else if (n % 4 == 1) return 1;
    else if (n % 4 == 2) return  1^n;
    else return 0;

}
    

int main(){ 
    long long a, b;
    cin >> a >> b;

    long long res = f(b) ^ f(a-1);

    cout << res << endl;
}


Measured memory_bytes: 256
#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 A, B, C;

int main() {
	cin >> A >> B >> C;
	if (A % 2 + B % 2 + C % 2 >= 2) {
		cout << "Hom" << endl;
	}
	else {
		cout << "Tem" << endl;
	}
}


Measured memory_bytes: 3136
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x){
    S[++top] = x;
}

int pop(){
    top--;
    return S[top+1];
}

int main(){
    int a, b;
    top = 0;
    char s[100];
    while(scanf("%s", s) != EOF){
        if(s[0]=='+'){
            a = pop();
            b = pop();
            push(a + b);
        }else if(s[0]=='-'){
            b = pop();
            a = pop();
            push(a - b);
        }else if(s[0]=='*'){
            a = pop();
            b = pop();
            push(a * b);
        }else{
            push(atoi(s));
        }
    }
    printf("%d\n", pop());
    return 0;
}

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

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

  vector<int> v;

  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;

    v.push_back(a);
  }

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

  ll minVal = INT_MAX;
  for(int p = v.at(0); p <= v.at(N-1); p++) {
    ll distanse = 0;

    for(int i = 0; i < N; i++) {
       distanse += pow(v.at(i) - p, 2);
    }

    minVal = min(minVal, distanse);
  }

  cout << minVal << endl;
}


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

#if DEBUG && !ONLINE_JUDGE
  #include "header.h"
#else
  #define debug(args...)
#endif

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long lli;
typedef long double ld;

#define pb push_back
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x).size()
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b) for(auto i=(a);i<b;i++)

#define INF (int)1e9
#define EPS 1e-9
#define MOD 1000000007
void preprocess(void) {
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  preprocess();
  lli a, b; cin>>a>>b;
  cout<<max(a+b, max(a*b, a-b))<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000'000'007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
    int n,k,x,y;
    cin >> n >>k >> x >> y;
    cout << min(k,n)*x + max(0,n-k)*y << endl;
    return 0;
}

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

int main() {
  string s, ans;
  cin >> s;
  rep(i, 0, s.size()) {
    if (s[i] == '0') {
      ans += "0";
    } else if (s[i] == '1') {
      ans += "1";
    } else {
      if (!ans.empty()) {
        ans.pop_back();
      }
    }
  }
  cout << ans << endl;
  getchar();
}

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


int main() {

	int n, k;

	int a[1005];

	cin >> n >> k;

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

	sort(a, a + n);

	int ans = 0;
	for (int i = 0; i < k; i++) {
		ans += a[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = Math.max(40, sc.nextInt());
		int b = Math.max(40, sc.nextInt());
		int c = Math.max(40, sc.nextInt());
		int d = Math.max(40, sc.nextInt());
		int e = Math.max(40, sc.nextInt());
		System.out.println((a+b+c+d+e)/5);
	}
}

Measured memory_bytes: 26076
#include<bits/stdc++.h>
using namespace std;
int main(){int n,k,i;
cin>>n>>k;
int a[n+1];
for(i=1;i<=n;i++)cin>>a[i];
for(i=k+1;i<=n;i++){
    if(a[i]>a[i-k]){cout<<"Yes\n";}
    else{cout<<"No\n";}
}
    return 0;}

Measured memory_bytes: 4384
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int K, N;
  cin >> K >> N;

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  int ans = K-A[N-1]+A[0];
  REP(i, N-1){
    chmax(ans, A[i+1]-A[i]);
  }

  cout << K-ans << "\n";

  return 0;
}


Measured memory_bytes: 1792
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val (A, B, C) = sc.nextLine().split(" ")
    val a = A.toInt()
    val b = B.toInt()
    val c = C.toInt()

    println(if (a + b >= c) "Yes" else "No")
}

Measured memory_bytes: 34140
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

struct E {
	int a;
	int i;
};

bool search(vector<vector<E>>& edges, vector<int>& ce, int u, int v, int p)
{
	if (u == v) return true;

	for (auto& e : edges[u]) {
		if (e.a == p) continue;

		if (search(edges, ce, e.a, v, u)) {
			ce.push_back(e.i);
			return true;
		}
	}

	return false;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	vector<vector<E>> edge(n);
	FOR_LT(i, 0, n - 1) {
		int a, b; cin >> a >> b;
		a--;
		b--;
		edge[a].push_back({ b, i });
		edge[b].push_back({ a, i });
	}

	int m; cin >> m;
	vector<vector<int>> ces(m);
	FOR_LT(i, 0, m) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		search(edge, ces[i], u, v, -1);
	}

	vector<int64_t> css(m);
	FOR_LT(i, 0, m) {
		int64_t s = 0;
		for (int e : ces[i]) {
			s |= ((int64_t)1 << e);
		}
		css[i] = s;
	}

	int64_t ans = ((int64_t)1 << (n - 1));
	FOR_LT(i, 1, (1 << m)) {
		int64_t nm = 0;
		FOR_LT(j, 0, m) {
			if (i & ((int64_t)1 << j)) nm++;
		}
		int s = (nm & 1) ? -1 : 1;

		int64_t state = 0;
		FOR_LT(j, 0, m) {
			if (i & ((int64_t)1 << j)) state |= css[j];
		}

		int ns = 0;
		FOR_LT(j, 0, n) {
			if (state & ((int64_t)1 << j)) ns++;
		}

		ans += s * ((int64_t)1 << (n  - 1 - ns));
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def possible(m,d):
    d = str(d)
    if len(d) < 2:
        return False
    if int(d[0]) >= 2 and int(d[1]) >= 2 and int(d[0])*int(d[1]) == m:
        return True
    return False

def main():
    m,d = map(int,input().split())
    ans = 0
    for month in range(1,m+1):
        for day in range(1,d+1):
            if possible(month,day):
                ans += 1

    print(ans)


main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

string S;
void input(){
    fast_io();
    cin >> S;
}

ll calc(string s, int bit){
    int n = s.length();
    ll ret=0;
    int le = 0;
    for (int j = 0; j < n-1; j++)
    {
        if((bit>>j)&1){
            ret += stoll(s.substr(0,j+1-le));
            s = s.substr(j+1-le);
            le=j+1;
        }
    }
    if(s.length()!=0) ret += stoll(s);
    DBG(ret)
    return ret;
}

int solve(){
    int N = S.length();
    ll ans = 0;
    for (int bit = 0; bit < 1<<(N-1); bit++)
    {
        ans += calc(S,bit);
    }
    cout << ans << endl;
    
    return 0;
}   

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

Measured memory_bytes: 256
def b(M,x,y,n=1):
 M[x][y]=0;a=n
 if M[x-1][y]:a=max(a,b(M,x-1,y,n+1))
 if M[x][y-1]:a=max(a,b(M,x,y-1,n+1))
 if M[x+1][y]:a=max(a,b(M,x+1,y,n+1))
 if M[x][y+1]:a=max(a,b(M,x,y+1,n+1))
 M[x][y]=1
 return a
for e in iter(input,'0'):
 n,m=int(e),int(input())
 P=[[0]*(n+2)for _ in[0]*(m+2)]
 for i in range(m):P[i+1][1:-1]=map(int,input().split())
 print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if P[i][j]))


Measured memory_bytes: 5740
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<map>
using namespace std;

int main(){
//srandom((unsigned long)time(NULL));

int h,w;
cin>>h>>w;
char a[h+2][w+2];
for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
        a[i][j]='#';
    }
    
}

for(int i=1;i<h+1;i++){
    for(int j=1;j<w+1;j++){
        cin>>a[i][j];
    }
}

for(int i=0;i<h+2;i++){
    for(int j=0;j<w+2;j++){
        cout<<a[i][j];
    }
    cout<<endl;
}


return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<set>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const ll mod = 100000000000000003;
int ne[200001], he[100001];
char C[1200100];

ll num[524300];
int kazu[524300];
const int ma = (1 << 19) - 1;
int query(ll n) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) return kazu[n2];
		n2 = n2 * 61 % 524287;
	}
	return 0;
}
void add(ll n, int b) {
	int n2 = (n & ma) + 1;
	while (num[n2]) {
		if (num[n2] == n + 1) {
			kazu[n2] |= b;
			return;
		}
		n2 = n2 * 61 % 524287;
	}
	num[n2] = n + 1;
	kazu[n2] = b;
}

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


	fread(C, 1, 1200100, stdin);
	char* ci = C, c;
	int N = 0;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';
	set<pair<int, char*>> ST;
	char* s[200001];
	rep1(i, N) {
		s[i] = ci;
		while (*ci++ >= '0');
		int n = ci - s[i] - 1;	
		if (n <= 100000) {
			ne[i] = he[n];
			he[n] = i;
		}
		else {
			ST.insert(mp(n, s[i]));
		}
	}

	ll kotae = 0;

	for (int M = 1; M <= 100000; M++) {
		for (int p = he[M]; p; p = ne[p]) {
			auto S = s[p];
			int k[26] = {};
			ll are = 0;
			for (int i = M - 1; i >= 1; i--) {
				int tmp = query(are);
				if (tmp) {
					rep(j, 26) if ((tmp >> j & 1)) {
						k[j]++;
					}
				}
				kotae += k[S[i] - 'a'];
				k[S[i] - 'a'] = 0;
				are = (are * 30 + S[i] - 'a' + 1) % mod;
			}

			kotae += k[S[0] - 'a'];
			k[S[0] - 'a'] = 0;

			add(are, 1 << (S[0] - 'a'));
		}
	}
	for (auto p : ST) {
		auto S = p.second;
		int k[26] = {};
		ll are = 0;
		for (int i = p.first - 1; i >= 1; i--) {
			int tmp = query(are);
			if (tmp) {
				rep(j, 26) if ((tmp >> j & 1)) {
					k[j]++;
				}
			}
			kotae += k[S[i] - 'a'];
			k[S[i] - 'a'] = 0;
			are = (are * 30 + S[i] - 'a' + 1) % mod;
		}

		kotae += k[S[0] - 'a'];
		k[S[0] - 'a'] = 0;

		add(are, 1 << (S[0] - 'a'));
	}
	printf("%lld\n", kotae);


	Would you please return 0;
}

Measured memory_bytes: 12760
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(int i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


//////////////////////////////////////
int main(){
    int n;
    cin>>n;
    vi x(n);
    vi t(n);
    rep(i,n){
        cin>>x[i];
        t[i]=x[i];
    }
    sort(all(x));
    int xi=(n)/2;
    rep(i,n){
        if(t[i]<x[xi])cout<<x[xi]<<endl;
        else cout<<x[xi-1]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 4740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main() {
  ll n,k;
  cin>>n>>k;
  ll l=-1,r=1LL<<60;
  while(l+1!=r) {
    ll m=(l+r)/2;
    ll x=m;
    for(ll i=1;i<n;i++)x-=x/k+1;
    if(x<0)l=m;
    else r=m;
  }
  cout<<r<<endl;
  return 0;
}


Measured memory_bytes: 3104
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ll x, ll y, ll a, ll b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( int k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }

const ll mod = 1000000007;
ll fact[111111];
ll cnk(ll n, ll k) {
	return (fact[n] * ((modInverse(fact[k], mod) * modInverse(fact[n - k], mod)) % mod)) % mod;
}
int main(){
	FASTIO;
	fact[0] = 1;
	for ( ll k = 1; k < 111111; k++ )
		fact[k] = (k * fact[k - 1]) % mod;
	ll n, m; cin >> n >> m;
	ll a[n]; parseArray(a, n); sort(a, a + n);
	ll ans = 0;
	for ( ll k = m - 1; k < n; k++ ){
		ans += (a[k] * cnk(k, k - (m - 1))) % mod;
		ans %= mod;
	}
	for ( ll k = n - m; k >= 0; k--){
		ans = (ans - (a[k] * cnk(n - 1 - k, n - 1 - k - (m - 1))) % mod + mod) % mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1920
N,M = map(int, input().split())
H = list(map(int, input().split()))
L = []
for i in range(M):
  a, b = map(int, input().split())
  if H[a-1] > H[b-1]:
    L.append(b-1)
  elif H[a-1] < H[b-1]:
    L.append(a-1)
  else:
    L.append(a-1)
    L.append(b-1)
print(N - len(set(L)))


Measured memory_bytes: 20068
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 1000000;
ll mod = INF;


int main(){

    int n,x,t;
    cin >> n>>x>>t;
    int ans=0;
    ans+=t*(n/x);
    
    n=n%x;
    
    if(n>0)ans+=t;
    cout << ans<<endl;
    
    return 0;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second

//int dxy[5] = {0, 1, 0, -1, 0};
// assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination

void move(vi &data)
{
    int ptr = 0;
    rep(i, data.size()) {
        if (data[ptr] > data[i]) {
            ptr = i;
        }
    }

    data[ptr] += data.size();
    rep(i, data.size()) {
        if (i != ptr) {
            data[i]--;
        }
    }
}

signed main()
{
    Int(k);
    std::cout << 50 << std::endl;

    vi data(50, 49);
    rep(i, 50) {
        data[i] += k / 50;
    }

    for (int i = 0; i < k % 50; i++) {
        move(data);
    }

    rep(i, data.size()) {
        cout << data[i] << " ";
    }
    std::cout << std::endl;


    return 0;
}




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

int main() {
	long long N, A, B;
	cin >> N >> A >> B;
	long long ans = N / (A + B);
	ans *= A;
	N %= (A + B);
	if (N >= A)ans += A;
	else ans += N;
	cout << ans << endl;
	return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ull sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    cin >> n;
    vl a(n);
    NREP() {
        cin >> a[i];
        sum += a[i];
    }

    ans = LLONG_MAX;
    ll snuke = 0;
    ll arai = sum;
    REP(i, 0, n - 1) {
        snuke += a[i];
        arai -= a[i];
        ans = min(ans, abs(snuke - arai));
    }
    MSG(ans)
}


Measured memory_bytes: 1792
#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;
const int MOD = (int)1e9 + 7;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  rep(i,n) cin >> a[i];  
  int up = n;
  int down = n/2;
  while(up>0){
    for(int i = down; i<up;i++){
      int buf = 0;
      for(int j=2;j*(i+1)<=n;j++){
        buf = (buf + b[j*(i+1)-1]) % 2; 
      }
      b[i] = (buf+a[i]) % 2;
    }
    up = down;
    down = up/2;
  }
  vector<int> c;
  int m=0;
  rep(i,n) if(b[i] == 1){
    m++;
    c.push_back(i+1);
  }
  cout<<m<<endl;
  if(m==0) return 0;
  rep(i,m) cout<<c[i]<<" ";
  cout<<endl;
}



Measured memory_bytes: 3064
#include<stdio.h>
#define N 100
void insertionSort(int *,int);
int main()
{
   int n,i;
   int a[N];
   scanf("%d",&n);
   for(i=0;i<n;i++)
   scanf("%d",&a[i]);
   insertionSort(a,n);
   return 0;
}
void insertionSort(int *a,int n){
  int i,j,x=0,k;
  for(i=0;i<n;i++){
    x=a[i];
    j=i-1;
    while(j>=0&&a[j]>x){
	a[j+1]=a[j];
	j--;
	a[j+1]=x;
      }
    for(k=0;k<n;k++){
	if(k>0)printf(" ");
	printf("%d",a[k]);
      }
    printf("\n");
  }
}
      
   
	 
   
   



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    double sum = 0.0;
    
    for (int i = 0; i < n; ++i) {
        double amount;
        string currency;
        
        cin >> amount >> currency;
        if (currency == "BTC") {
            sum += amount * 380000;
        }
        else {
            sum += amount;
        }
    }
    
    cout << sum;
    
    return 0;
}

Measured memory_bytes: 256