akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 1e6 + 7;


unordered_map<ll, ll> cnt;
bool prime[maxn];
ll kek[maxn];

ll gcd(ll a, ll b) {
	return (a == 0 ? b : gcd(b % a, a));
}

ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return mul(a, mul(b, inv(g)));
}


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	memset(prime, 1, sizeof(prime));
	prime[0] = 0;
	prime[1] = 0;
	prime[2] = 1;
	for (ll i = 2; i < maxn; i++) {
		if (prime[i]) {
			kek[i] = i;
			for (ll j = i + i; j < maxn; j += i) {
				kek[j] = i;
				prime[j] = 0;
			}
		}
	}

	ll n; cin >> n;
	vector<ll>a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	//ll lc = a[0];
	//for (ll i = 1; i < n; i++) {
	//	lc = lcm(lc, a[i]);
	//}

	//ll ans = 0;
	//for (ll i = 0; i < n; i++) {
	//	ans += mul(lc, inv(a[i]));
	//	ans %= mod;
	//	if (ans < 0) ans += mod;
	//}
	//cout << ans << endl;


	// 2
	for (ll x : a) {
		unordered_map<ll, ll> cnt1;
		if (prime[x]) {
			cnt1[x] = 1;
		}
		else {
			while (x > 1) {
				cnt1[kek[x]]++;
				x /= kek[x];
			}
		}
		for (auto p : cnt1) {
			cnt[p.X] = max(cnt[p.X], p.Y);
		}
	}

	ll rofl = 1;

	for (auto p : cnt) {
		rofl = mul(rofl, poww(p.X, p.Y));
	}

	ll ans = 0;
	for (ll x : a) {
		ans += mul(rofl, inv(x));
		ans %= mod;
	}
	if (ans < 0) ans += mod;
	cout << ans << endl;

	return 0;	
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 9600
#include <stdio.h>


int main(void)
{
	//変数の宣言
	int n,m;
	int s=0;
	
	//データの読み込み
	scanf("%d",&n);
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	
	
	//実際の処理
	
	m=n;
	
	while(n!=0){
		s=s+n%10;
		n=n/10;
	}
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	if(m%s==0){
		printf("Yes");
	}else{
		printf("No");
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <numeric>
#include <utility>
#include <iomanip>

using namespace std;
using int64 = long long;

struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a.rbegin(), a.rend());
    int alice = 0;
    int bob = 0;
    for (int i=0; i<n; i++) {
        if (i%2) bob += a[i];
        else alice += a[i];
    }
    cout << alice - bob << endl;
}


Measured memory_bytes: 3120
#pragma GCC optimize("Ofast")
#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()
#define ln '\n'
const double PI = acos(-1.0);
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
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; }
///////////////////////////////////////////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,K; cin >> N >> K;

    vector<int> cnt;
    int cur;
    for (int i = 1; i*i <= N; ++i) {
        if (i < N/i) cnt.emplace_back(N/i - N/(i+1));
        cur = i;
    }
    rep(i,cur) cnt.emplace_back(1);
    reverse(all(cnt));
    int M = cnt.size();
    vector<vector<mint>> dp(K, vector<mint>(M));
    rep(i,M) {
        dp[0][i] = cnt[i];
        if (i) dp[0][i] += dp[0][i-1];
    }
    rep(i,K-1) {
        rep(j,M) {
            dp[i+1][j] = dp[i][M-1-j]*cnt[j];
            if (j) dp[i+1][j] += dp[i+1][j-1];
        }
    }

    cout << dp[K-1][M-1].a << ln;
}

Measured memory_bytes: 50684
class Heap
  attr_reader :size

  def initialize
    @heap = []
    @size = 0
  end

  def add(n)
    i = @size
    while i > 0 do
      parent_index = (i - 1) / 2
      break if n < @heap[parent_index]

      @heap[i] = @heap[parent_index]
      i = parent_index
    end

    @heap[i] = n
    @size += 1
  end

  def pop
    return if @size <= 0
    min_n = @heap[0]
    @size -= 1
    n = @heap[@size]
    i = 0
    while i * 2 + 1 < @size do
      child_index1 = i * 2 + 1
      child_index2 = i * 2 + 2
      if child_index2 < @size && @heap[child_index2] >= @heap[child_index1]
        child_index1 = child_index2
      end
      break if @heap[child_index1] < n

      @heap[i] = @heap[child_index1]
      i = child_index1
    end
    @heap[i] = n
    min_n
  end

  def min; @heap[0] end
  def values; @heap.first(@size) end
  def inspect; "Heap: #{values}" end
end

heap = Heap.new

N, M = gets.split.map!(&:to_i)
gets.split.each do |a|
  heap.add(a.to_i)
end

M.times do
  a = heap.pop
  heap.add(a / 2)
end

puts heap.values.inject(:+)


Measured memory_bytes: 10836
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, m, a[N], new_m;
ll suff[N];

inline bool check (int val) {
   int r = n;
   ll ans = 0;
   for (int l = 1; l <= n; l ++) {
      while (l > r) r ++;
      while (r > l && a[l] + a[r - 1] >= val) r --;
      if (a[l] + a[r] >= val) ans += (n - r + 1) * 2 - (l == r);
   }
   return (ans >= m);
}

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n >> m;
   for (int i = 1; i <= n; i ++) cin >> a[i];
   sort (a + 1, a + n + 1);
   for (int i = n; i >= 1; i --) suff[i] = suff[i + 1] + a[i];
   int l = 0, r = 200001;
   while (r - l > 1) {
      int mid = l + r >> 1;
      if (check (mid)) l = mid;
      else r = mid;
   }
   ll ans = 0;
   int j = n;
   for (int i = 1; i <= n; i ++) {
      while (j < i) j ++;
      while (j > i && a[i] + a[j - 1] > l) j --;
      if (a[i] + a[j] > l) {
         ans += ((n - j + 1) * a[i] + suff[j]) * 2 - (i == j) * (a[i] + a[i]); 
         m -= (n - j + 1) * 2 - (i == j);
      }     
   }
   cout << ans + 1ll * m * l;
}               
 
signed main () {                                       
  //#ifdef QWERTY
  //    freopen("input", "r", stdin);
  // #endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}   

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

typedef ostringstream OSS; typedef istringstream ISS;
typedef long long LL;
typedef pair<int, int> PII;  typedef pair<LL, LL> PLL;
typedef vector<int>    VI;   typedef vector<VI>   VVI;   typedef vector<VVI>   VVVI;
typedef vector<LL>     VLL;  typedef vector<VLL>  VVLL;  typedef vector<VVLL>  VVVLL;
typedef vector<double> VD;   typedef vector<VD>   VVD;   typedef vector<VVD>   VVVD;
typedef vector<string> VS;   typedef vector<VS>   VVS;   typedef vector<VVS>   VVVS;
typedef vector<bool>   VB;   typedef vector<VB>   VVB;   typedef vector<VVB>   VVVB;
typedef vector<PII>    VPII; typedef vector<VPII> VVPII; typedef vector<VVPII> VVVPII;
typedef vector<PLL>    VPLL; typedef vector<VPLL> VVPLL; typedef vector<VVPLL> VVVPLL;

typedef unsigned int  UI;
typedef vector<UI>    VUI;
typedef vector<VUI>   VVUI;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define MAXUD(orig, target) orig = max(orig, target)
#define MINUD(orig, target) orig = min(orig, target)
#define DUMP(x) cerr << #x << " = " << (x) << endl

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a)   { OSS oss; oss << a; return oss.str(); };

template<typename T=int> inline void dump(vector<T> vs, bool ent=false) { rep(i, vs.size()) cout << vs[i] << (i+1==vs.size() ? '\n' : ' '); if (ent) cout << endl; }
template<typename T = int> inline void dump(vector<vector<T>> vs, bool ent=false) { rep(i, vs.size()) dump<T>(vs[i]); if (ent) cout << endl; }

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int    DX[] = {1,  0, -1, 0};
const int    DY[] = {0, -1,  0, 1};
const double EPS  = 1e-12;
// const double PI   = acos(-1.0);

template<typename T = int> inline T in() { T x; cin >> x; return x; }
template<typename T = int> inline vector<T> in(int n) { vector<T> xs(n); rep(i, n) cin >> xs[i]; return xs; }
template<typename T = int> inline vector<vector<T>> in(int n, int m) { vector<vector<T>> xs(n, vector<T>(m)); rep(i, n) rep(j, m) cin >> xs[i][j]; return xs; }

int main(void) {
	int n = in();
	int m = 1 << n;
	VI as = in(m);

	rep(i, n) {
		int l = 1 << (n - i - 1);
		VI ns(l);
		rep(j, l) {
			int p = as[j * 2];
			int q = as[j * 2 + 1];
			if (p == q) ns[j] = p;
			else ns[j] = abs(p - q);
		}
		as = ns;
	}

	cout << as[0] << endl;

    return 0;
}



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

int main() {
	
	int N;
	long long int menor, soma, esq=0, dir=0;
	cin >> N;
	int Cards[N];
	
	
	for(int i=0; i<N; i++) {
		cin >> Cards[i];
		dir += Cards[i];
	}
	esq += Cards[0];
	dir -= Cards[0];
	
	
	if(esq - dir < 0)
		menor = dir - esq;
	else
		menor = esq - dir;
	
	
	for(int i=1; i<N-1; i++) {
		esq += Cards[i];
		dir -= Cards[i];
		soma = esq - dir;
		
		if(soma < 0)
			soma *= -1;
		
		
		if(soma < menor)
			menor = soma;
	}
	
	cout << menor << endl;
	return 0;
}

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


int main()
{
	char s[4];
	int n=0;
	cin >> s;
	for (int i = 0; i < 4; i++) {
		if (s[i] == '+'){
			n++;
		}
		else {
			n--;
		}
	}
	cout << n;
}


Measured memory_bytes: 256
import math
temp = list(map(int,input().split()))
a=temp[0]
b=temp[1]
h=temp[2]
m=temp[3]
htemp=float(h)+float(float(m)/float(60))
hdeg=math.pi*htemp/float(6)
mdeg=math.pi*float(m)/float(30)
deg=hdeg-mdeg
ans=math.sqrt((a*a)+(b*b)-2*a*b*float(math.cos(deg)))
print(ans)

Measured memory_bytes: 9456
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;

#define endl "\n"

const int MOD = 1000000007;


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

    int a, b;
    cin >> a >> b;

    int ara[a],sum = 0;
    for(int i = 0 ; i < a; i++) cin >> ara[i];
    sort(ara,ara+a);
    for(int i = 0 ; i < b ; i++){
        sum += ara[i] ;
    }
    cout << sum << endl;

	return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> m(n);
	int ans=0;
	bool v;
	for(int i=0;i<n;i++){
		cin >> m[i];
		int j=i-1;
		v=1;
		while(j>=0){
			if(m[j]>m[i]){
				v=0;
				break;
			}
			j--;
		}
		ans+=v;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#bはKより真に大きい、N以下
#aはK以上

N, K = map(int, input().split())

count = 0
for b in range(K+1, N+1):
    x = N // b
    y = N % b
    count += x * (b-K)
    count += max(0, (y-max(1,K)+1))

print(count)


Measured memory_bytes: 9116
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
  string S,T;
  cin>>S>>T;
  bool flag=true;
  for(int i=0;i<(int)S.size();i++,flag=true){
    for(int j=0;j<(int)S.size();j++){
      if(S[(i+j)%(int)S.size()]!=T[j]){
        flag=false; break;
      }
    }
    if(flag){
      cout<<"Yes"<<endl;
      return 0;
    }
  }
  cout<<"No"<<endl;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())

cnt = 0
while A >= B:
    cnt += 1
    B *= 2

# print(f'{cnt=}')

while B >= C:
    cnt += 1
    C *= 2

# print(f'{A=}, {B=}, {C=}, {cnt=}')
ans = 'Yes' if cnt <= K else 'No'
print(ans)


Measured memory_bytes: 9160
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> C(N);
  for(int i=0;i<N;++i) cin>>C[i];
  sort(C.begin(), C.end());
  ll two[N+10];
  two[0] = 1;
  for(int i=1;i<N+10;++i) {
    two[i] = two[i-1]*2%mod;
  }
  ll ans = 0;
  for(int i=0;i<N;++i) {
    ans += 2*two[i]%mod*two[i]%mod*two[N-i-1]%mod*C[i]%mod*((two[N-i-1]+(N-i-1)*two[max(0, N-i-2)]%mod)%mod)%mod;
    ans %= mod;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 6432
N, A, B = list(map(int, input().split()))
inputs = list(map(int, input().split()))

xi = []
xi.append(inputs[0])
hirou = 0

for i in range(1, N):
    xi.append(inputs[i])
    diff = xi[i] - xi[i-1]
    if diff * A > B:
        hirou += B
    else:
        hirou += A * diff

print(hirou)


Measured memory_bytes: 14252
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}

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

	int n, x, t;
	cin >> n >> x >> t;

	cout << (n + x - 1) / x*t << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;
int main() {
  int R0, W0, C, R;
  while (cin >> R0 >> W0 >> C >> R) {
    if (R0 == 0 && W0 == 0 && C == 0 && R == 0)
      break;
    for (int i = 0;; i++) {
      if (C * W0 <= (R0 + R * i)) {
        cout << i << endl;
        break;
      }
    }
  }
  return 0;
}

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

int main()
{
	int l;
	cin >> l;
	double a, b;
	a = l / 3.0;
	b = l - a*2;
	printf("%.12lf\n", a*a*b);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
map<int,int>s;
int a[200005],b[200005];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    if(n==2)
    {
        printf("%d\n",b[1]);
        printf("%d\n",b[0]);
    }
    else
    {
        sort(a,a+n);
        int m=a[n/2-1];
        int k=a[n/2];
        for(int i=0;i<n/2;i++)
        {
            s[a[i]]=k;
        }
        for(int i=n/2;i<n;i++)
            s[a[i]]=m;
        for(int i=0;i<n;i++)
        {
            printf("%d\n",s[b[i]]);
        }
    }
    return 0;
}


Measured memory_bytes: 12928
n = gets.chomp.to_i
h = []
n.times do
    h << gets.chomp.split(" ").map(&:to_i)
end

# 前日までの累積の最大値, 
dp = []  # [累積, 前日の活動]

dp[0] = [h[0][0], h[0][1], h[0][2]]

(1..n-1).each do |i|
    pre = dp[i-1]
    dp[i] = [h[i][0], h[i][1], h[i][2]]
    dp[i][0] += (pre[1] > pre[2] ?  pre[1] : pre[2])
    dp[i][1] += (pre[0] > pre[2] ?  pre[0] : pre[2])
    dp[i][2] += (pre[1] > pre[0] ?  pre[1] : pre[0])
end

puts dp[n-1].max

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

// 約数列挙
vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; 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 pow(ll x, ll y, ll mod) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        return pow(x * x % mod, y / 2, mod) % mod;
    } else {
        return x * pow(x, y - 1, mod) % mod;
    }
}

bool search(ll left, ll right, ll diff, ll target){
    if ((right - left) == 1){return false;}
    ll mid = (left + right) / 2; // equal to b
    ll b = mid - diff;
    ll cand = pow(mid, 5, INF) - pow(b, 5, INF);
    // cout << diff << " " << cand << " " << left << " " << mid << " " << right << endl;
    if (cand == target){
        cout << mid << " " << b;
        return true;
    } else if (cand > target){
        return search(left, mid, diff, target);
    } else {
        return search(mid, right, diff, target);
    }
}

void Main() {
    // n^{5}-(n-1)^{5}が初めて10^9を超えるときを考えると -118 <= A <= 119
    ll X; cin >> X;
    ll low = -1;
    ll high = 10000;
    vector<ll> div = divisor(X);
    bool flag = false;
    rep2(i, -120, 120){
        rep2(j, -120, 120){
            ll cand = pow(i, 5, INF) - pow(j, 5, INF);
            if (cand == X){cout << i << " " << j << endl; flag = true; break;}
        }
        if(flag){break;}
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

vector<ll> r,a,d;
vector<vector<int>> e;

void rec(int i=0,int p=-1){
    d[i]=a[i];
    for(auto&j:e[i]) if(j!=p){
            rec(j,i);
            d[i]+=d[j];
        }
}

ll mn=LLONG_MAX,S{};
void rec2(int i=0,int p=-1,ll s=0){
    S+=s;
    mn=min(mn,s);
    for(auto&j:e[i]) if(j!=p){
            rec2(j,i,s-d[j]);
        }
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,u,v;
    in>>n;
    e.resize(n);
    fr(i,n-1){
        in>>u>>v;
        --u;--v;
        e[u].emplace_back(v);
        e[v].emplace_back(u);
    }
    a.resize(n);
    for(auto&i:a) in>>i;
    fr(i,n){
        in>>u;
        a[i]=u-a[i];
    }
    d.resize(n);
    rec();
    rec2();
    S+=n*(-mn);
    cout<<S<<endl;
}


Measured memory_bytes: 14020
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(void)
{
    //string a,b;
    int a,b,c,d;
    //char a,b,c;
    int i=0;
    //char a,b='.';
    cin>>a>>b>>c;
    if(a>c||a+b<c) cout<<"NO";
    else cout<<"YES";
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  char s[3];
  int y=700;
  cin >> s;
  for (int i=0;i<3;i++) {
    if (s[i] == 'o') {
      y += 100;
    }
  }
  cout << y << endl;
  return(0);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n;cin>>n;
  int i,j,k;
  vector<int> v;
  for(i=0;i<n;i++){
    cin >> k;
    v.push_back(k);
  }
  for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  for(i=1;i<n;i++){
    for(j=0;j<i;j++){
      if(v[j]>v[i]){
	k=v[i];
	v.erase(v.begin()+i);
	v.insert(v.begin()+j,k);
	break;
      }
    }
    for(j=0;j<n;j++) cout << v[j] << (j==n-1?'\n':' ');
  }
  return 0;
}



Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
char a[52],b[52];
int n,m,sum,ans;
int main() {
	cin>>a;
	cin>>b;
	n=strlen(a),m=strlen(b);
	sum=min(n,m),ans=max(n,m);
	for(int i=0; i<=sum-1; i++)
		cout<<a[i]<<b[i];
	if(n>m)
		for(int i=sum; i<=ans-1; i++)
			cout<<a[i];
	else for(int i=sum; i<=ans-1; i++)
			cout<<b[i];
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		boolean[] array = new boolean[n];
		for (int i = 0; i < k; i++) {
			int d = sc.nextInt();
			for (int j = 0; j < d; j++) {
				array[sc.nextInt() - 1] = true;
			}
		}
		int count = 0;
		for (int i = 0; i < n; i++) {
			if (!array[i]) {
				++count;
			}
		}
		System.out.println(count);
	}
}


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

struct BIT{
  vector<int> bit;
  int n;
  //1-indexed
  BIT(){init(-1);}
  BIT(int n_){init(n_);}
  void init(int n_){
    n=n_;
    bit.clear();
    bit.resize(n+1,0);
  }
  int sum(int i){
    int s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }
  void add(int i,int x){
    if(i==0) return;
    while(i<=n){
      bit[i]+=x;
      i+=i&-i;
    }
  }
  int sum0(int i){
    return sum(i+1);
  }
  void add0(int i,int x){
    add(i+1,x);
  }
};

signed main(){
  int n,m;
  cin>>n>>m;
  int l[n],r[n];
  for(int i=0;i<n;i++) cin>>l[i]>>r[i];
  BIT bit(m+1);
  
  typedef pair<int,int> P;
  priority_queue<P,vector<P>,greater<P> > q;
  for(int i=0;i<n;i++) q.push(P(r[i]-l[i]+1,i));
  for(int i=1;i<=m;i++){
    while(!q.empty()&&q.top().first<=i){
      P p=q.top();q.pop();
      int k=p.second;
      //cout<<"k:"<<k<<endl;
      bit.add0(l[k],1);
      bit.add0(r[k]+1,-1);
    }
    int ans=q.size();
    for(int j=0;j<=m;j+=i)
      ans+=bit.sum0(j); 
    cout<<ans<<endl;
  }
  
  return 0;
}


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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

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

int main() {
    int d, t, s;
    cin >> d >> t >> s;
    cout << (t * s >= d ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>
#define N 100

int main(){

  int i,count,num=0,s,j,tmp,k;
  int A[N];

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


  for(k=0;k<num-1;k++){
    for(j=num-1;j>k;j--){
      if(A[j-1]>A[j]){
	tmp=A[j-1];
	A[j-1]=A[j];
	A[j]=tmp;
	count++;
      }
    }
  }
  for(s=0;s<num-1;s++){
    printf("%d ",A[s]);
  }
  printf("%d\n",A[num-1]);
  printf("%d\n",count);

  return 0;
}



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

int main()
{
    int n, k;
    cin >> n >> k;
    int arr[n];
    int dp[n];
    for (int i = 0; i != n; ++i)
    {
        dp[i] = 1000000000;
        scanf("%d", &arr[i]);
    }
    
    dp[0] = 0;
    for (int i = 1; i != n; ++i)
        for (int j = max(0, i - k); j != i; ++j)
            dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]));
    
    cout << dp[n - 1];
    
    return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7, MAX = 1e9, larg = 1e5, INF = -1e9;
long long A,B,C,D,E,F,G,H,I,J,K,L,N,M,O,P,Q,R,S,T,U,V,W,X,Y,Z;
long long max_value = 0, max_index = 0;
long long min_value = MAX, min_index = 0;
long long sum = 0;

typedef pair<int, int> Pa;
typedef long long ll;

int main() {
    cin >> N >> C;
    int diff[30][30] = {};
    int grid[3][30] = {}, num;
    rep(i, C){
        rep(j, C) cin >> diff[i][j];
    }
    rep(i, N){
        rep(j, N){
            cin >> num;
            grid[(i+j)%3][num-1]++;
        }
    }

    rep(i1, C){
        rep(i2, C){
            rep(i3, C){
                if(i1 == i2 || i2 == i3 || i3 == i1) continue;
                sum = 0;
                rep(j, C){
                    sum += diff[j][i1]*grid[0][j];
                }
                rep(j, C){
                    sum += diff[j][i2]*grid[1][j];
                }
                rep(j, C){
                    sum += diff[j][i3]*grid[2][j];
                }
                min_value = min(min_value, sum);
            }
        }
    }
    cout << min_value;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>

using namespace std;

int main(){
    
    string str;
    int cnt = 0;

    cin >> str;

    if(str[0] != 'A'){
        cout << "WA" << endl;
        return 0;
    }

    for(size_t i = 1; i < str.size(); i++){
        if(i >= 2 && i < str.size() - 1){
            if(str[i] == 'C'){
                cnt++;
            }
        }
        if((str[i] < 'a' || str[i] > 'z') && str[i] != 'C'){
            cout << "WA" << endl;
            return 0;
        }
    }

    if(cnt != 1){
        cout << "WA" << endl;
        return 0;
    }

    cout << "AC" << endl;

    return 0;
}


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


def solve(s):
    n = len(s)
    base = list("+".join(s))
    ans = 0
    for t in range(1 << (n - 1)):
        xs = base[:]
        for i in range(n - 1):
            if t & (1 << i) > 0:
                xs[2 * i + 1] = ""
        eq = "".join(xs)
        ans += eval(eq)
    return ans


def main():
    print(solve(input()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  ll N,K;
  cin>>N>>K;

  int ans=0;
  ll val=N;
  while(val>0){
    val/=K;
    ans++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#import<cstdio>
main(){int K,i=scanf("%d",&K)-2,n=K+3>>2<<1,j,k;for(printf("%d",n);++i<n;)for(j=puts("")-2;++j<n;printf("%d ",((k=i%2*n+(i+j)%n)>=K?k-n:k)%K+1));}

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

int main(){

  int n,a[10000],ans,c;

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

    ans = a[0];

    for(int i=0;i<n;i++){
      c = 0;
      for(int j=i;j<n;j++){
	c += a[j];
	ans = max(ans,c);
      }
    }

    cout << ans << endl;

  }
}

Measured memory_bytes: 1176
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

int N;
string str;

char conv(char c) {
	if (c == 'S') return 'W';
	else return 'S';
}

string solve() {
	string res = str;
	for (int bit = 0; bit < 4; ++bit) {
		if (bit & (1 << 0)) res[0] = 'S';
		else res[0] = 'W';
		if (bit & (1 << 1)) res[N - 1] = 'S';
		else res[N - 1] = 'W';
		string tmp = res;

		bool ok = true;
		for (int i = 0; i < N; ++i) {
			if ((tmp[i] == 'S' && str[i] == 'o') || (tmp[i] == 'W' && str[i] == 'x')) tmp[(i + 1) % N] = tmp[(i - 1 + N) % N];
			else tmp[(i + 1) % N] = conv(tmp[(i - 1 + N) % N]);
		}
		if (tmp[0] != res[0] || tmp[N - 1] != res[N - 1]) {
			ok = false;
		}
		if (ok) {
			res = tmp;
			return res;
		}
	}
	return "-1";
}

int main() {
	while (cin >> N >> str) {
		cout << solve() << endl;
	}
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int ans=0,cnt=0;
	for(int i=1;i<=n;i++){
		if(i%2==1){
			cnt=0;
			for(int j=1;j<=i;j++){
				if(i%j==0){
					cnt++;
				}
			}
			if(cnt==8){
				ans++;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int dist(pair<int, int> p, pair<int, int> q){
	return abs(p.first - q.first) + abs(p.second - q.second); 
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0); 
	int N; cin >> N; 
	int A[114514] = {}; 
	for(int i = 1; i <= N; i++) cin >> A[i]; 
	sort(A+1, A+N+1, greater<int>());
	vector<pair<int, int>> V; 
	V.emplace_back(0, A[1]); 
	bool ans = true; 
	for(int i = 1; i <= N; i++){
		if(A[i] == A[i+1]) continue; 
		V.emplace_back(i, A[i]); 
		V.emplace_back(i, A[i+1]); 
	}
	int idx = -1; bool equal = false; 
	for(int i = 0; i < V.size(); i++){
		int a = V[i].first; int b = V[i].second; 
		if(b == a){
			idx = i; equal = true; break; 
		}else if(b < a){
			idx = i; break; 
		}
	}
	if(equal && (idx & 1)){
		ans = false; 
	}else if(equal){
		int d1 = dist(V[idx + 1], V[idx]); 
		int d2 = dist(V[idx], V[idx - 1]); 
		if(!(d1 & 1) && !(d2 & 1)) ans = false;  
	}else if(idx & 1){
		if(!((V[idx].first + V[idx].second) & 1)) ans = false; 
	}else{
		if(!((V[idx-1].first + V[idx-1].second) & 1)) ans = false; 
	}
	cout << (ans ? "First" : "Second") << "\n";
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	cin >> n;
	unordered_map< string, ll > ana_list;

	string s;
	for(int i = 0; i < n; ++i)
	{
		cin >> s;
		sort(s.begin(), s.end());
		ana_list[s]++;
	}

	ll ans = 0;
	for(const auto& ana : ana_list)
	{
		ans += ana.second * (ana.second - 1LL) / 2LL;
	}
	cout << ans;

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 10232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int X; cin >> X;
  rep(i,100000){
    if(100*i <= X && X <= 105*i){
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
int main(){
    int N,M;
    std::cin>>N>>M;
    int a,b;
    if(M%2==0){
        a=M/2;
        b=M/2;
    }else{
        a=M/2;
        b=M-a;
    }
    for(int i=1;i<=a;++i){
        std::cout<<i<<" "<<2*a+2-i<<std::endl;
    }
    for(int i=1;i<=b;++i){
        std::cout<<i+2*a+1<<" "<<M*2+2-i<<std::endl;
    }
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 500 + 1;
int d[maxn][maxn];
int rm[maxn][maxn];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int N;
    cin >> N;
    for(int i = 1; i <= N; i += 1)
        for(int j = 1; j <= N; j += 1){
            d[i][j] = min({i - 1, N - i, j - 1, N - j});
            rm[i][j] = 1;
        }
    int ans = 0;
    for(int i = 1, P; i <= N * N; i += 1){
        cin >> P;
        int x = (P - 1) / N + 1;
        int y = (P - 1) % N + 1;
        ans += d[x][y];
        rm[x][y] = 0;
        queue<pair<int, int>> q;
        q.push({x, y});
        while(not q.empty()){
            auto p = q.front();
            q.pop();
            int x = p.first, y = p.second;
            if(x > 1 and d[x - 1][y] > rm[x][y] + d[x][y]){
                d[x - 1][y] = rm[x][y] + d[x][y];
                q.push({x - 1, y});
            }
            if(x < N and d[x + 1][y] > rm[x][y] + d[x][y]){
                d[x + 1][y] = rm[x][y] + d[x][y];
                q.push({x + 1, y});
            }
            if(y > 1 and d[x][y - 1] > rm[x][y] + d[x][y]){
                d[x][y - 1] = rm[x][y] + d[x][y];
                q.push({x, y - 1});
            }
            if(y < N and d[x][y + 1] > rm[x][y] + d[x][y]){
                d[x][y + 1] = rm[x][y] + d[x][y];
                q.push({x, y + 1});
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 5608
N = input()
a = [int(ai) for ai in input().split()]
m = sum(a) / len(a)
index = 0
min_diff = float('inf')
for i, ai in enumerate(a):
    diff = abs(m - ai)
    if diff < min_diff:
        index = i
        min_diff = diff
print(index)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int MAX=1e5+5;
const ll INF=1e12;

int A,B,Q;
ll s[MAX];
ll t[MAX];

ll ans(ll d){
	ll sl, sr, tl, tr;
	if(binary_search(s,s+A+2,d)){sl=d;sr=d;}
	else{
		int ind = lower_bound(s,s+A+2,d)-s;
		sl=s[ind-1],sr=s[ind];
	}
	if(binary_search(t,t+B+2,d)){tl=d;tr=d;}
	else{
		int ind = lower_bound(t,t+B+2,d)-t;
		tl=t[ind-1],tr=t[ind];
	}
	sl=d-sl;
	sr=sr-d;
	tl=d-tl;
	tr=tr-d;
	
	ll m=INF;
	m=min(m,max(sl,tl));
	m=min(m,max(sr,tr));
	m=min(m,sl*2+tr);
	m=min(m,tl*2+sr);
	m=min(m,sr*2+tl);
	m=min(m,tr*2+sl);
	return m;
}

int main(){
	cin>>A>>B>>Q;
	rep1(i,A)cin>>s[i];
	rep1(i,B)cin>>t[i];
	s[0]=-INF;
	t[0]=-INF;
	s[A+1]=INF;
	t[B+1]=INF;
	
	rep(i,Q){
		ll x;
		cin>>x;
		cout<<ans(x)<<endl;
	}
	
}

Measured memory_bytes: 2816
#include <stdio.h>

int main() {
	int A, B, C, X, ans=0;
	scanf("%d%d%d%d",&A,&B,&C,&X);
	for (int h = 0; h <= A; h++) {
		for (int i = 0; i <= B; i++) {
			for (int j = 0; j <= C; j++) {
				if (500 * h + 100 * i + 50 * j == X) ans++;
			}
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

ll fact(int a){
    ll r = 1;
    REP(i,a){
        r = (r * (i+1)) % MOD;
    }
    dump(r);
    return r;
}

ll inv(int a){
    int p = 32;
    ll mem[p];
    mem[0] = a;
    REP(i,p-1){
        mem[i+1] = (mem[i] * mem[i])%MOD;
    }
    ll r = 1;
    ll m = MOD-2;
    for (int i=p-1;i>=0;i--){
        if (m >= pow(2,i)){
            r *= mem[i];
            //dump(pow(2,i));
            m -= pow(2,i);
            r %= MOD;

        }
    }
    //dump(m);
    //dump(r);
    return r;
}

int comb(int a,int b){
    ll r;
    dump(a);
    dump(b);
    r = fact(a)*inv(fact(a-b)) % MOD;
    r = r * inv(fact(b)) % MOD;
    return int(r);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int x,y;
  cin >> x >>y;
  if ((x+y)%3 != 0){
      cout << 0 << endl;
      return 0;
  }
  if (x<y)swap(x,y);
  if (x > 2*y){
      cout << 0 << endl;
      return 0;
  }  
  int a = (x+y)/3;

  int b = x - a;
  if (a<b)swap(a,b);
  
  cout << comb(a,b) << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long a=sc.nextLong();
		long b=sc.nextLong();
		long c=sc.nextLong();
		long d=sc.nextLong();
		ArrayList<Long> al=new ArrayList<>();
		al.add(a*c);
		al.add(a*d);
		al.add(b*c);
		al.add(b*d);
		Collections.sort(al);
		System.out.println(al.get(al.size()-1));
	}

}


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

using namespace std;

typedef long long ll;

const int Mod=1e9+7;

int main()
{
    int n;
    scanf("%d",&n);
    if(n==1) return puts("0"),0;

    ll ans=1,tot=1,cnt=1;
    for(int i=1;i<=n;i++)
    {
        ans=ans*10%Mod;
        tot=tot*8%Mod;
        cnt=cnt*9%Mod;
    }

    printf("%lld",((ans-cnt*2+tot)%Mod+Mod)%Mod);

    return 0;
}

Measured memory_bytes: 3824
using System;

namespace AIZUJudge {
    class ququ {
        static void Main(string[] args) {
            int ququ_upper = 9;

            for (int i = 1; i <= ququ_upper; i++) {
                for (int j = 1; j <= ququ_upper; j++) {
                    Console.WriteLine(i+"x"+j+"="+i*j);
                }
            }
       }
    }
}

Measured memory_bytes: 9128
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define INF 2000000000LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int fie[501][501];


int main(void){
	scanf("%d",&n);
	int g=0;
	string str;
	bool flag=false;
	for(int i=0;i<n;i++){
		cin >> str;
		for(int j=0;j<n;j++){
			if(str[j]=='#'){
				fie[i][j]=1;
				flag=true;
			}
		}
	}
	int res=114514;
	int cnt2=0;
	for(int i=0;i<n;i++){
		bool flag=true;
		for(int j=0;j<n;j++){
			if(fie[j][i]==0)flag=false;
		}
		if(!flag)cnt2++;
	}
	for(int i=0;i<n;i++){
		int cnt=0;
		for(int j=0;j<n;j++){
			if(fie[i][j]==0)cnt++;
		}
		bool flag=false;
		for(int k=0;k<n;k++){
			if(fie[k][i]==1)flag=true;
		}
		if(!flag)cnt++;
		res=min(res,cnt+cnt2);
	}
	printf("%d\n",flag?res:-1);
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
using namespace std;

vector<pair<int,int>> edges;

void clear(int k) {
    vector<pair<int,int>> v;
    for (int i=0; i<(int)edges.size(); ++i) {
        if (edges[i].first != k && edges[i].second != k) {
            v.push_back(edges[i]);
        }
    }
    edges = v;
}

int main() {
    int m, n, x, y;
    cin >> m >> n;

    edges.clear();
    for (int i=0; i<n; ++i) {
        cin >> x >> y;
        edges.push_back(make_pair(x, y));
    }

    bool used[21] = {};
    for (int i=0; i<m; ++i) {
        for (int sus=1; sus<=m; ++sus) {
            if (used[sus]) continue;
            bool ok = true;
            for (int k=0; k<(int)edges.size(); ++k) {
                if (edges[k].second == sus) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << sus << endl;
                clear(sus);
                used[sus] = true;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int A, B;
  cin>>A>>B;

  if(A >= 13) cout<<B<<endl;
  else if(A >= 6) cout<<B/2<<endl;
  else cout<<0<<endl;
  

  return 0;
}


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

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

    int red=0, blue=0;
    for (int i=0; i<s.length(); i++) {
        if (s[i] == 'R') red++;
        else blue++;
    }
    if (red > blue)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;

int main(){
    int64_t i;//preparation for
    int64_t n;
    int64_t s;

    cin>>n;
    s=0;

    for(i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0){
            s+=i;
        }
    }

    cout<<s;
    return 0;
}

Measured memory_bytes: 3648