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

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) (a) = max((a), (b))
#define relaxi(a, b) (a) = min((a), (b))

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;
typedef long double ld;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7)) 
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

// for rand
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// use uniform_int_distribution<int>(0, i)(rng)


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


	string s; cin >> s;
	int n = s.length();
	int cnt0 = 0, cnt1 = 0;
	f(i,n) cnt0 += (s[i]-'0')%2 == i%2;
	f(i,n) cnt1 += (s[i]-'0')%2 != i%2;
	cout << min(cnt0,cnt1) << endl;

	return 0;
}



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

int main(){
  int n, m;
  cin >> n >> m;
  
  int b = (m + n - 1) / n;
  int ans = 0;
  for(int i = 1; i * i <= m; ++i){
    if(m % i) continue;
    if(m/i <= b) ans = max(ans, m/i);
    else if(i <= b) ans = max(ans, i);
  }
  
  cout << ans << endl;
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define FORW(a, b, c) for(int a = b; a >= c; --a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 100;
const int oo = 1e18;
const int mod  = 1e9 + 7;

int a[200];

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    int n, m; cin >> n >> m;
    int sum = 0;
    FOR(i, 1, n) cin >> a[i], sum += a[i];
    int cnt = 0;
    FOR(i, 1, n) if(a[i] * 4 * m >= sum)
        cnt ++;
    if(cnt >= m) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define ull unsigned long long
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
int main(){
	fast;
	int n;
	cin>>n;
	vector<int> jump;
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		jump.pb(temp);
	}
	vector<int> dp(n+1,0);
	dp[0] = 0;
	dp[1] = abs(jump[1]-jump[0]);
	for(int i=2;i<n;i++){
		int val1 = dp[i-1]+abs(jump[i]-jump[i-1]);
		int val2 = dp[i-2]+abs(jump[i] - jump[i-2]);
		dp[i] = min(val1,val2);
	}
	cout<<dp[n-1];
	
	return 0;
}


Measured memory_bytes: 1144
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
import numpy as np
def resolve():
    N, M = lr()
    rev = 0
    if N < M:
        M, N = N, M
        rev = 1
    T = np.zeros(1, dtype=np.int8)
    for i in range(N):
        T = np.tile(T, (2, 2))
        T[1<<i:, 1<<i:] ^= 1
    T = np.diff(T, axis=0)
    T = np.diff(T, axis=1)
    T = T[:, :(1<<M)-1]%2
    if rev:
        T = np.transpose(T)
    for t in T:
        print(''.join(t.astype(str)))
resolve()

Measured memory_bytes: 15440
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;

bool visited[100005];
int value[2][100005];
vector <int> vec[100005];

void dfs(int v, int t) {
    visited[v] = true;
    for (int i = 0; i < vec[v].size() ; i++) {
        if (visited[vec[v][i]] == false) {
            value[t][vec[v][i]] = 1 + value[t][v];
            dfs(vec[v][i], t);
        }
    }
}

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

    fill(value[0], value[1]+100005, 0);
    for (int i = 0; i < n-1; i++) {
        cin >> a >> b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }

    fill(visited, visited+100005, false);
    dfs(1, 0);
    fill(visited, visited+100005, false);
    dfs(n, 1);

    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (value[0][i] <= value[1][i]) {
            count++;
        }
    }

    if (2 * count <= n) {
        cout << "Snuke" << endl;
    } else {
        cout << "Fennec" << endl;
    }

    return 0;
}

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

int main(){
    vector<ll> num(4);
    for (int i = 0; i < 4; i++){
        cin >> num.at(i);
    }
    ll ans = num[0]*num[2];
    for (int i = 0; i < 2; i++){
        for (int j = 2; j < 4; j++){
            ans = max(ans,num[i]*num[j]);
        }
    }

    cout << setprecision(18) << ans << endl;
}

Measured memory_bytes: 3620
import Data.List

calc :: Integer -> Integer -> Integer
calc l r | r <= l = 2019
         | r == l+1 = l*r `mod` 2019
         | l+672 <= r = 0
         | mod r 673 < mod l 673 = 0
         | mod l 673 == 0 = 0
         | otherwise = min (calc l (r-1)) (foldl min 2019 $ map (\x -> x*r `mod` 2019) [l..(r-1)])

main = do
  l:r:_ <- map read . words <$> getLine :: IO [Integer]
  putStrLn . show $ calc l r


Measured memory_bytes: 1020
n = int(input())
a = list(map(int, input().split()))

c_4 = 0
c_2 = 0
odd = 0
for i in range(n):
    if a[i]%4==0:
        c_4+=1
    elif a[i]%2==1:
        odd += 1
    else:
        c_2 += 1
if odd <= c_4:
    print("Yes")
elif odd <= c_4+1 and c_2==0:
    print("Yes")
else:
    print("No")

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    LL X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    priority_queue<LL, vector<LL>, greater<LL>> a, b, c;
    REP(i, A) {
        LL p;
        cin >> p;
        a.push(p);
    }
    REP(i, B) {
        LL p;
        cin >> p;
        b.push(p);
    }
    REP(i, C) {
        LL p;
        cin >> p;
        c.push(p);
    }
    REP(i, A - X) {
        a.pop();
    }
    REP(i, B - Y) {
        b.pop();
    }
    for(;!c.empty();) {
        LL af, bf, cf;
        af = a.top();
        bf = b.top();
        cf = c.top();

        if(min(af, bf) < cf) {
            if(af < bf) {
                a.pop();
                a.push(cf);
            }else{
                b.pop();
                b.push(cf);
            }
        }
        c.pop();
    }
    LL res = 0;
    for(;!a.empty();) {
        res += a.top();
        a.pop();
    }
    for(;!b.empty();) {
        res += b.top();
        b.pop();
    }
    cout << res << endl;
    return 0;
}


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

int main() {
  int x1,x2,x3,x4,x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if(x1 == 0){
      cout << 1 << endl;
    }
  else if(x2 == 0){
    cout << 2 << endl;
  }
  else if(x3 == 0){
    cout << 3 << endl;
  }
  else if(x4 == 0){
    cout << 4 << endl;
  }
  else if(x5 == 0){
    cout << 5 << endl;
  }
    
      
}


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

int main() {
   int x1,x2,x3,x4,x5; cin >> x1 >> x2 >> x3 >> x4 >> x5;

   if(x1 == 0){
       cout << 1 << endl; 
   } else if(x2 == 0){
       cout << 2 << endl; 
   } else if(x3 == 0){
       cout << 3 << endl; 
   } else if(x4 == 0){
       cout << 4 << endl; 
   } else if(x5 == 0){
       cout << 5 << endl; 
   }

   return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
 
int main() {

    int n;
    cin>>n;

    if(n%10==7||(n/10)%10==7||n/100==7){cout<<"Yes"<<endl;}
    else{cout<<"No"<<endl;}


}

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

void change(int& a,int& b){
        if(a>b){
                int d;
                d = a;
                a = b;
                b = d;
        }
}

int main(){
        int a,b,c;
        cin>>a>>b>>c;
        change(a,b);
        change(b,c);
        change(a,b);
        printf("%d %d %d\n",a,b,c);
        return 0;
}

Measured memory_bytes: 1148
N = gets.to_i
ls, rs = [], []
N.times do |i|
    ls[i], rs[i] = gets.split.map(&:to_i)
end

lsort_1 = N.times.map{|i|[i, ls[i]]}.sort_by{|arr|-arr[1]}
lsort_2 = N.times.map{|i|[i, ls[i]]}.sort_by{|arr|-arr[1]}
rsort_1 = N.times.map{|i|[i, rs[i]]}.sort_by{|arr|arr[1]}
rsort_2 = N.times.map{|i|[i, rs[i]]}.sort_by{|arr|arr[1]}

pos = 0
result = 0
used = Array.new(N)
sur = false
N.times do |i|
    nex = nil
    if i % 2 == 0
        loop do
            arr = rsort_1.shift
            unless used[arr[0]]
                used[arr[0]] = true
                nex = arr[1]
                break
            end
        end
        if nex >= pos
            sur = true
        end
    else
        loop do
            arr = lsort_1.shift
            unless used[arr[0]]
                used[arr[0]] = true
                nex = arr[1]
                break
            end
        end
        if nex <= pos
            sur = true
        end
    end
    break if sur
    result += (pos-nex).abs
    pos = nex
end
result += pos.abs

result_1 = result

pos = 0
result = 0
used = Array.new(N)
sur = false
N.times do |i|
    nex = nil
    if i % 2 == 1    ### ここを変えた
        loop do
            arr = rsort_2.shift
            unless used[arr[0]]
                used[arr[0]] = true
                nex = arr[1]
                break
            end
        end
        if nex >= pos
            sur = true
        end
    else
        loop do
            arr = lsort_2.shift
            unless used[arr[0]]
                used[arr[0]] = true
                nex = arr[1]
                break
            end
        end
        if nex <= pos
            sur = true
        end
    end
    break if sur
    result += (pos-nex).abs
    pos = nex
end
result += pos.abs

result_2 = result

puts [result_1, result_2].max

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

int main(){
	
	int a, b, c, d = 0;
	cin >> a >> b >> c >> d;

	if (std::abs(a - c) <= d){
		std::cout << "Yes" << std::endl;
	}
	else if (!(std::abs(a - b) <= d)){
		std::cout << "No" << std::endl;
		return 0;
	}
	else if (!(std::abs(b - c) <= d)){
		std::cout << "No" << std::endl;
		return 0;
	}
	else{
		std::cout << "Yes" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
count=0
for a in range(0,A+1,1):
    for b in range(0,B+1,1):
        for c in range(0,C+1,1):
            if X - (500*a+100*b+50*c) ==0:
                count+=1
print(count)

Measured memory_bytes: 67696
#include <iostream>
#include <algorithm>
#define f first
#define s second
using namespace std;
int main(){
  pair <int,int> a[6];
  for(int i=0,c,b;i<6&&cin>>c>>b;a[i++]=make_pair(c,b)) if(c>b) swap(c,b);
  sort(a,a+6);
  int r=0;
  for(int i=0;i<3;i++) if(a[i*2]!=a[i*2+1]) r++;
  if(!r&&a[0].f==a[2].f&&a[2].s==a[4].s&&a[0].s==a[4].f) cout<<"yes"<<endl;
  else cout<<"no"<<endl;
  return 0;
}

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

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

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

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

int main(){
	std::cout << std::fixed;
	std::cout << std::setprecision(12);
	int n;
	cin>>n;
	LD p[3333]={};
	vector<vector<LD>> dp=vector<vector<LD>>(n+2,vector<LD>(n+2));
	FOR(i,0,n){
		cin>>p[i];
	}
	dp[0][0]=1.;
	LD ans=0;
	FOR(i,0,n){
		FOR(j,0,i+1){
			dp[i+1][j]+=dp[i][j]*(1-p[i]);
			dp[i+1][j+1]+=dp[i][j]*p[i];
		}
	}
	FOR(i,(n+1)/2,n+1){
		ans+=dp[n][i];
	}
	cout<<ans<<endl;
    return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_H = 100;
const int MAX_W = 100;
char m[MAX_H+1][MAX_W+1];
int h, w;
bool used[MAX_H+1][MAX_W+1];

int main()
{
  while((cin >> h >> w) && h && w){
    rep(i, h) rep(j, w) used[i][j] = false;
    rep(i, h) rep(j, w) cin >> m[i][j];

    int hx = 0;
    int hy = 0;
    while(true){
    used[hx][hy] = true;
    if(m[hx][hy] == '>') hy += 1;
    if(m[hx][hy] == '<') hy -= 1;
    if(m[hx][hy] == '^') hx -= 1;
    if(m[hx][hy] == 'v') hx += 1;
    if(m[hx][hy] == '.'){ cout << hy << " " << hx << endl; break;}
    if(used[hx][hy]){ cout << "LOOP" << endl;  break; }
    }
  }

  return 0;
}

Measured memory_bytes: 1184
#include<iostream>
#include<string.h>
    using namespace std;

int main(){
    int n,l,c=300,ans=0;
    cin >>n>>l;
    int s[n];
    for (int i = 1; i <= n;i++)
    {
      s[i] = l + i - 1;
      ans += s[i];
    }
    for (int i = 1; i <=n; i++)
    {
      if(abs(s[i])<c)
        c = abs(s[i]);
    }

    if(ans>=0)
    cout << ans-c << endl;
    else
      cout << ans + c << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;

  ll ans = 1;
  ll count = 0;
  rep(i, N + 1) {
    if (i == 0) continue;
    ll c = 0;
    ll num = i;
    while (num % 2 == 0) {
      c++;
      num /= 2;
    }

    if (c > count) {
      ans = i;
      count = c;
    }
  }
  ANS;
  return 0;
}

Measured memory_bytes: 3648
import math
n,m=[int(i) for i in input().split()]
r=math.factorial(n) // (math.factorial(n - 2) * math.factorial(2)) if n >= 2 else 0
r+=math.factorial(m) // (math.factorial(m - 2) * math.factorial(2)) if m >= 2 else 0
print(r)


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const int mod = (int)1e9 + 7;
const int mod2 = 998244353;

ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
	if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll mul(ll a, ll b, ll md){
	return a*b % md;
}

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
	fact.resize(n+5);
	inv_fact.resize(n+5);
	fact[0] = inv_fact[0] = 1;
	for(int i = 1; i <= n; i++){
		fact[i] = (fact[i-1] * i) % mod;
		inv_fact[i] = exp(fact[i], mod-2, mod);
	}
}

ll komb(ll a, ll b){
	if(a < b) return 0;
	return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}

const int N = 1e5+5;

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	vector<int> seen(1e6, 0);
	vector<int> vec(n);
	for(auto &x: vec) cin>>x;
	int cnt = 0;
	for(int i = 0; i < n; i++){
		seen[vec[i]]++;
	}
	for(int i = 0; i < n; i++){
		int x = vec[i];
		bool check = true;
		for(int b = 1; b*b <= x; b++){
			if(x % b == 0){
				if(seen[b] && x != 1) check = false;
				if(b != 1 && seen[x / b]) check = false;
				if(b == 1 && seen[x] > 1) check = false;
			}
		}
		cnt += check;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 7952
import sys
readline = sys.stdin.readline
N = int(readline())
*A, = map(int, readline().split())
C = A[:]
C.sort()

MOD = 4253024257
base = 3
B = [0]*N
v = 1
P = Q = 0
for i in range(N):
    B[i] = v
    P += v * A[i]
    Q += v * C[i]
    v = v * base % MOD
if P == Q:
    print(0)
    exit(0)

for i in range(int(readline())):
    x, y = map(int, readline().split()); x -= 1; y -= 1
    p = A[x]; q = A[y]; r = B[y] - B[x]
    P += r * p - r * q
    if P == Q:
        print(i+1)
        break
    A[x], A[y] = q, p
else:
    print(-1)


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

int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) scanf("%d", a + i);

  vector<int> b;
  // 末尾から1文字飛ばしで数字を配列bに格納していく
  for (int i = n - 1; i >= 0; i -= 2) {
    b.push_back(a[i]);
  }
  // 偶数だったら0から、奇数だったら1から1文字飛ばしで数字を配列bに格納していく
  int i = n & 1 ? 1 : 0;
  for (; i < n; i += 2) {
    b.push_back(a[i]);
  }

  // 解答
  for (int i = 0; i < b.size(); i++) {
    cout << b[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  int N;
  int A[100002];
  int B[100001];
  long long res=0;
  cin >> N;
  rep(i,N+1) cin >> A[i];
  rep(i,N) cin >> B[i];

  rep(i,N){
    res+=min(A[i],B[i]);
    int tmp1 = max(0,B[i]-A[i]);//left beating power                                     
    int tmp2 = min(A[i+1], tmp1) ; //how many monster in i+1 can be beaten               
    res+=tmp2;
    A[i+1]-= tmp2;
  }

  cout << res << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cassert>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

struct mint {
	ll x;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod)x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod)x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a)const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a)const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t)const {
		if (!t)return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1)a *= *this;
		return a;
	}

	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint>fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		assert(n < mod);
		fact[0] = 1;
		for (int i = 1; i <= n; i++)fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; i--)ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k<0 || k>n)return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
};

int main() {
	int n, k; cin >> n >> k;
	vector<int>a(n);
	for (auto&& x : a)cin >> x;
	sort(a.begin(), a.end());
	combination c(n + 5);

	mint ans = 0;
	for (int ri = 0; ri < 2; ri++) {
		for (int i = 0; i < n; i++) {
			mint now = c(i, k - 1);
			if (ri == 1)now = -now;
			ans += now * a[i];
		}
		reverse(a.begin(), a.end());
	}
	cout << ans.x << endl;
	return 0;
}

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

using namespace std;

int SData[12], CData[12];
int CountOfData[101];

int solve(int n) {
	int count;
	bool flag;
	
	count = 0;
	while (1) {
		flag = false;
		for (int i = 0; i < n; i++) {
			CData[i] = CountOfData[SData[i]];
		}

		for (int i = 0; i < n; i++) {
			if (CData[i] != SData[i]) {
				flag = true;
				break;
			}
		}
		if (flag) {
			count++;
		}
		else
		{
			return count;
		}

		memset(CountOfData, 0, sizeof(CountOfData));
		for (int i = 0; i < n; i++) {
			SData[i] = CData[i];
			CountOfData[CData[i]]++;
		}
	}
	
}

int main() {
	int n, sum;

	while (cin >> n, n) {
		memset(CountOfData, 0, sizeof(CountOfData));
		for (int i = 0; i < n; i++) {
			cin >> SData[i];
			CountOfData[SData[i]]++;
		}

		sum = solve(n);
		cout << sum << endl;
		for (int i = 0; i < n; i++) {
			cout << SData[i];
			if (i != n - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}


	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
double sa(double q, double r) {
  if(q > r) {
    return q - r;
  }
  else {
    return r - q;
  }
}
int main() {
  int A, B, H, M;
  cin >> A >> B >> H >> M;
  double Z = 0, T = 0, R = 0;
  Z = 30.0 * H + 0.5 * M;
  T = 6 * M;
  if(sa(Z, T) >= 180) {
    R = 360 - sa(Z, T);
  }
  else {
    R = sa(Z, T);
  }
  double ans = 0;
  double cos1 = 0;
  double pi, unit;
  if(R != 0) {
    pi     = 2.0 * asin(1.0);
	unit   = pi / 180.0;
    double R_R;
    R_R = R * unit;
  cos1 = cos(R_R);
  ans = A * A + B * B - 2 * A * B * cos1;
  cout << fixed << setprecision(10);
  cout << sqrt(ans) << endl;
  }
  else {
    cout << sa(A, B) << endl;
  }
}

Measured memory_bytes: 4228
N = int(input())
S = [input() for _ in range(N)]
cli = [0] * 4
cli[0] = S.count('AC')
cli[1] = S.count('WA')
cli[2] = S.count('TLE')
cli[3] = S.count('RE')
print(f'AC x {cli[0]}')
print(f'WA x {cli[1]}')
print(f'TLE x {cli[2]}')
print(f'RE x {cli[3]}')

Measured memory_bytes: 16136
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int test[200001];
int main() {
	long long n, l, ans = 0; cin >> n >> l;
	if (l <= 0 && l + n - 1 >= 0) {
		for (int h = l; h <= l + n - 1; h++) {
			ans += h;
		}
		cout << ans << endl; cin >> n; return 0;
	}
	if (l > 0) {
		for (int h = l; h <= l + n - 1; h++) {
			ans += h;
		}
		cout << ans - l << endl;
	}
	else {
		for (int h = l; h <= l + n - 1; h++) {
			ans += h;
		}
		cout << ans - (l + n - 1) << endl;
	}
	cin >> n;
}

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

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

int main()
{
  string S; cin >> S;
  cout << min(count(ALL(S), '0'), count(ALL(S), '1')) * 2 << endl;
}

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

using namespace std;

int main()
{
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (i < K) ans += X;
        else ans += Y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    ll N; cin >> N;
    string S;
    while (N > 0) {
        N--;
        int i = N % 26;
        N /= 26;
        S += (char)('a' + i);
    }
    reverse(S.begin(), S.end());
    cout << S << endl;
}


Measured memory_bytes: 3628
#!/usr/bin/env python3
# O(NlogN) 
# PyPy3ならAC, Python3ではTLE

n = int(input())

div = [0 for _ in range(n+1)]
for i in range(1, n+1):
    ti = i 
    while ti <= n:
        div[ti] += 1 
        ti += i
ans = 0 
for i in range(1, n+1):
    ans += i*div[i]
print(ans)


Measured memory_bytes: 224692
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int[] vx = {-1,0,1,0};
		int[] vy = {0,1,0,-1};



		int h = stdIn.nextInt();
		int w = stdIn.nextInt();

		char[][] maze = new char[h][w];

		for(int i = 0; i < h; i++) {
			maze[i] = stdIn.next().toCharArray();
		}


		int max = 0;


		//s地点を設定
		for(int i = 0; i < h; i++) {
			for(int j = 0; j < w; j++) {
				if(maze[i][j]=='#') {
					continue;
				}
				
				int[][] board = new int[h][w];
				
				for(int a = 0; a < h; a++) {
					for(int b = 0; b < w; b++) {
						board[a][b] = -1;
					}
				}
				
				board[i][j] = 0;
				
				int sx = j;
				int sy = i;

				Queue<Integer> queueX = new LinkedList<>();
				Queue<Integer> queueY = new LinkedList<>();


				queueX.add(sx);
				queueY.add(sy);

				while(!queueX.isEmpty()) {
					int x = queueX.poll();
					int y = queueY.poll();

					for(int k = 0; k < 4; k++) {
						int nextX = x + vx[k];
						int nextY = y + vy[k];

						if(0 <= nextX && nextX < w && 0 <= nextY && nextY < h && maze[nextY][nextX] == '.' 
								&& board[nextY][nextX] == -1) {
							board[nextY][nextX] = board[y][x] + 1;
							queueX.add(nextX);
							queueY.add(nextY);
						}

					}

				}

				for(int l = 0; l < h; l++) {
					for(int m = 0; m < w; m++) {
						max = Math.max(max, board[l][m]);
					}
				}

			}
		}

		System.out.println(max);


	}

}


Measured memory_bytes: 30708
from collections import deque
N = int(input())
A = deque([int(i) for i in input().split()])
dec = False
inc = False
cnt = 1
antenum = A.popleft()

for _ in range(N - 1):
    if not inc and not dec:
        if A[0] < antenum:
            dec = True
        elif A[0] > antenum:
            inc = True
    elif inc:
        if A[0] < antenum:
            cnt += 1
            inc = False
    elif dec:
        if A[0] > antenum:
            cnt += 1
            dec = False
    antenum = A.popleft()

print(cnt)

Measured memory_bytes: 14636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<int> cnt(15,0);
    cnt[0]++;
    for(auto it:a)cnt[it]++;
    for(auto it:cnt){
        if(it>=3){
            cout<<0<<endl;
            return 0;
        }
    }
    int res=0;
    for(int bit=0;bit<(1<<12);bit++){
        vector<int> now(24,0);
        for(int i=0;i<=12;i++){
            if(i==0||i==12){
                if(cnt[i]>1){
                    cout<<0<<endl;
                    return 0;
                }else if(cnt[i]==1){
                    now[i]=1;
                }
            }else{
                if(cnt[i]==2){
                    now[i]=1;
                    now[24-i]=1;
                }else if(cnt[i]){
                    if(bit&(1<<i))now[i]=1;
                    else now[24-i]=1;
                }
            }
        }
        vector<int> v;
        for(int i=0;i<24;i++){
            if(now[i])v.push_back(i);
        }
        if(v[0]==0)v.push_back(24);
        int temp=100000000;
        for(auto p:v){
            for(auto q:v){
                if(p==q)continue;
                temp=min(temp,abs(p-q));
            }
        }
        res=max(temp,res);
    }
    cout<<res<<endl;
}

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  int nt=0;
  for(int i=0;i<10000;i++){
    if(nt%60<=c&&c<=nt%60+a){
      cout<<nt+c-(nt%60)<<endl;
      return 0;
    }
    nt+=a;
    nt+=b;
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3100
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

#define M_PI       3.14159265358979323846

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

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
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> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

struct Edge
{
    int target;
    int id;
};

ll solve()
{
    int N;

    cin >> N;

    vector<int> edgeColors(N - 1, 0);
    unordered_map<int, vector<Edge>> tree;

    for (int i = 0; i < N - 1; ++i)
    {
        int a, b;
        cin >> a >> b;

        tree[a].push_back({b, i});
    }

    int maxColor = 0;
    queue<pair<int, int>> q;
    q.push({1, 0});

    while (!q.empty())
    {
        int node = q.front().first;
        int usedColor = q.front().second;
        q.pop();

        int color = 1;

        for (auto& edge : tree[node])
        {
            if (color == usedColor)
                ++color;
            
            edgeColors[edge.id] = color;

            q.push({edge.target, color});

            ++color;
        }

        maxColor = std::max(maxColor, color-1);
    }

    cout << maxColor << endl;

    for (int i = 0; i < N - 1; ++i)
        cout << edgeColors[i] << endl;

    return 0;
}

int main()
{
    solve();

    return 0;
}

Measured memory_bytes: 8356
import itertools
import math

n = int(input())
l = []
for _ in range(n):
    x, y = map(int, input().split())
    l.append([x, y])

dist = 0
for v in itertools.permutations(l):
    # print(v)
    ll = list(v)
    # print(ll)
    
    prev = None
    for lll in ll:
        # print(lll)
        
        if prev is not None:
            # print(prev)
            x1 = prev[0]
            y1 = prev[1]
            x2 = lll[0]
            y2 = lll[1]
            # print()
            a = math.sqrt(((x1 - x2) ** 2) + ((y1 - y2) ** 2))
            # print(a)
            dist += a
            # print(dist)
        
        prev = lll

print(dist / math.factorial(n))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main()
{
	char a,b;
	cin >> a >> b;
	if(a == 'H' && b == 'H')cout << "H" << endl;
	else if(a == 'D' && b == 'H')cout << "D" << endl;
	else if(a == 'H' && b == 'D')cout << "D" << endl; 
	else if(a == 'D' && b == 'D')cout << "H" << endl;
	return 0;
} 

Measured memory_bytes: 764
#include <bits/stdc++.h> //ライブラリ全読み込み
using namespace std; //std:を省略できる

int main(){
    while (true){
        int x,y;
        cin >> x >> y;
        if(x==0 && y==0) break;

        if(x>y){
            int buf=x;
            x = y;
            y = buf;
        }
        cout <<x<<" "<<y<<endl;
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define en '\n'
#define pb push_back
#define mp make_pair
#define P pair<int, int>

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;

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

int main() {
	int a[3], b[3];
	map<int, int> mp;
	for (int i = 0; i < 3; i++) {
		cin >> a[i] >> b[i];
		mp[a[i]]++;
		mp[b[i]]++;
	}
	int sum = 0;
	for (int i = 0; i < mp.size(); i++) {
		if (mp[i] == 2) {
			sum++;
		}
	}
	if (sum == 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
S=list(input())
SV=S[::-1]
N=len(S)

for i in range(N):
    F=1
    if S[i]!=SV[i]:
        F=0
        break

s=S[:N//2]
sv=s[::-1]
n=len(s)
#print(s)
for i in range(n):
    FF=1
#    print(s[i],s[-(i+1)])
    if s[i]!=sv[i]:
        FF=0
        break

if F and FF:
    print('Yes')
else:
    print('No')

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

int main()
{
  ll n, x, y;
  x = y = 0;
  cin >> n;
  vector<ll> a(n);
  for (ll i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  bool flag = true;

  for (ll i = n - 1; i > 1; i--)
  {
    if (a.at(i - 1) == a.at(i - 2) && !flag)
    {
      y = a.at(i - 1);
      break;
    }

    if (a.at(i) == a.at(i - 1) && flag)
    {
      x = max(x, a.at(i - 1));
      flag = false;
    }
  }
  cout << x * y << endl;
}


Measured memory_bytes: 3976
#include <iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    if(N == 3){
        cout << 2 << ' ' << 5 << ' ' << 63 << endl;
        return 0;
    }
    if(N == 4){
        cout << 2 << ' ' << 5 << ' ' << 20 << ' ' << 63 << endl;
        return 0;
    }
    int a[8] = {2, 3, 4, 6, 8, 9, 10, 12};
    int n = N/8;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 8; j++){
            cout << a[j] + 12*i;
            if(N%8 != 0 || i != n-1 || j != 7) cout << ' ';
        }
    }
    if(N%8 == 0){
        cout << endl;
    }else if(N%8 == 1){
        cout << 6+12*n << endl;
    }else if(N%8 == 2){
        cout << 2+12*n << ' ' << 4+12*n << endl;
    }else if(N%8 == 3){
        cout << 2+12*n << ' ' << 4+12*n << ' ' << 6+12*n << endl;
    }else if(N%8 == 4){
        cout << 2+12*n << ' ' << 4+12*n << ' ' << 6+12*n << ' ' << 12+12*n << endl;
    }else if(N%8 == 5){
        cout << 3+12*n << ' ' << 8+12*n << ' ' << 9+12*n << ' ' << 10+12*n << ' ' << 12+12*n << endl;
    }else if(N%8 == 6){
        cout << 3+12*n << ' ' << 8+12*n << ' ' << 9+12*n << ' ' << 10+12*n << ' ' << 12+12*n << ' ' << 6+12*n << endl;
    }else if(N%8 == 7){
        cout << 3+12*n << ' ' << 8+12*n << ' ' << 9+12*n << ' ' << 10+12*n << ' ' << 12+12*n << ' ' << 2+12*n << ' ' << 4+12*n << endl;
    }
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N;
  ll C;
  cin >> N >> C;
  vector<ll> X(N+2, 0), V(N+2, 0);
  for(int i=1; i<N+1; i++)
    cin >> X[i] >> V[i];

  // 累積和
  vector<ll> suml(N+2, 0), sumr(N+2, 0);
  suml[0] = 0;
  for(int i=1; i<N+1; i++)
    suml[i] = suml[i-1] + V[i];
  sumr[N+1] = 0;
  for(int i=N; i>0; i--)
    sumr[i] = sumr[i+1] + V[i];

  // f(a) := v0 + v1 + ... + va - xa
  vector<ll> Fl(N+2, 0), Fr(N+2, 0);
  Fl[0] = 0;
  for(int i=1; i<N+1; i++)
    Fl[i] = suml[i] - X[i];
  Fr[N+1] = 0;
  for(int i=N; i>0; i--)
    Fr[i] = sumr[i] - (C - X[i]);

  // g(a) := max(f(0), f(1), ... , f(a))
  vector<ll> Gl(N+2, 0), Gr(N+2, 0);
  vector<ll> Glpos(N+2, 0), Grpos(N+2, 0);
  Gl[0] = 0;
  Glpos[0] = 0;
  for(int i=1; i<N+1; i++)
    if(Gl[i-1] < Fl[i]){
      Gl[i] = Fl[i];
      Glpos[i] = X[i];
    } else {
      Gl[i] = Gl[i-1];
      Glpos[i] = Glpos[i-1];
    }
  Gr[N+1] = 0;
  Grpos[N+1] = 0;
  for(int i=N; i>0; i--)
    if(Gr[i+1] < Fr[i]){
      Gr[i] = Fr[i];
      Grpos[i] = X[i];
    } else {
      Gr[i] = Gr[i+1];
      Grpos[i] = Grpos[i+1];
    }

  ll ans = 0LL;
  ans = max(ans, Gr[1]); // xa = 0
  ans = max(ans, Gl[N]); // xb = 0
  for(int i=1; i<N+1; i++) {
    ll tmpl = (suml[i]-X[i]) + Gr[i+1] - min(X[i], Grpos[i+1]);
    ll tmpr = (sumr[i]-(C-X[i])) + Gl[i-1] - min(C-X[i], Glpos[i-1]);
    ans = max(ans, tmpl);
    ans = max(ans, tmpr);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 8064
//Forbidden List

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int x,n;cin>>x>>n;
    vecrep(n,p,int);
    sort(range(p),greater<int>());
    int mi = inf,ans;
    for(int i = 101;i>=0;i--){
        bool flag = false;
        rep(j,0,n){
            if(p[j]==i)flag=true;
        }
        if(flag)continue;
        if(mi>=abs(x-i)){
            mi=abs(x-i);
            ans=i;
        }
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX_N 200000
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int X[MAX_N];
  int Y[MAX_N];
  rep(i, N) {
    cin >> X[i];
    Y[i] = X[i];
  }
  sort(Y, Y + N);
  int Mid0 = Y[((N - 1) / 2) + 1];
  int Mid1 = Y[((N - 1) / 2) + 0];

  rep(i, N) {
    if (X[i] <= Mid1)
      cout << Mid0 << endl;
    else
      cout << Mid1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

const int MAX_N = 110;
const int MAX_V = 100100;

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


int h, w;
vector<string> a;

int dp[1100][1100] = { 0 };

void add(int &a, int b) {
	a += b;
	if (a >= MOD)a -= MOD;
}

int main() {

	cin >> h >> w;
	a.resize(h);

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

	//必ず左上からスタート
	dp[0][0] = 1;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			//はみ出ないかつ通路なら移動する
			if (i + 1 < h && a[i + 1][j] == '.')add(dp[i + 1][j], dp[i][j]);
			if (j+ 1 < w && a[i][j+1] == '.')add(dp[i][j+1], dp[i][j]);
		}
	}

	cout << dp[h-1][w-1] << endl;

	return 0;
}

Measured memory_bytes: 5632
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        S: chars,
    }

    let mut color = if S[0] == 'W' { false } else { true };
    let mut ans = 0;

    for s in S {
        let c = if s == 'W' { false } else { true };
        if c ^ color {
            color = !color;
            ans += 1;
        }
    }
    println!("{}", ans);
}

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

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

	bool ans = false;
	for (int i=9; i>0; i--){
		if (N%i==0 && N/i <=9) {
			ans = true;
			break;
		}
	}

	if (ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int H = sc.nextInt();
    int M = sc.nextInt();
    sc.close();

    double a = (double) A;
    double b = (double) B;
    double h = (H * 60 + M) * 360d / 720d;
    double m = M * 360d / 60d;
    double ans = Math.sqrt(a * a + b * b
        - 2.0d * a * b * Math.cos(Math.toRadians(Math.abs(h - m))));
    System.out.println(ans);
  }
}


Measured memory_bytes: 35968
n=int(input())
def cal(x):
    y=str(x)
    cnt=0
    for i in range(len(y)):
        cnt+=int(y[i])
    return cnt
min=999999999
for a in range(1,n//2+1):
    b=n-a
    if cal(a)+cal(b)<min:
        min=cal(a)+cal(b)
print(min)


Measured memory_bytes: 3316