akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n;
  cin>>n;
  //vector<ll> x(n);
  //vector<ll> y(n);
  //vector<ll> h(n);

  vector<tuple<ll,ll,ll>> t(n);

  rep(i,n){
    ll x,y,h;
    cin>>x>>y>>h;
    t[i]=make_tuple(h,x,y);
  }

  sort(begin(t),end(t),greater< tuple<ll,ll,ll> >() );

  //for(auto x:t) cout << get<0>(x) << " " << get<1>(x) << " " << get<2>(x)<< endl;

  for(ll cx=0;cx<=100;cx++){
    for(ll cy=0;cy<=100;cy++){
      ll ans;
      ans=0;
      bool comp;
      comp=true;

      //cout << cx << " " << cy << endl;

      rep(i,n){
        
        ll tmp;
        tmp= get<0>(t[i]) + abs( cx-get<1>(t[i]) ) + abs( cy-get<2>(t[i]) ) ;
        //cout << tmp << endl;

        if( i==0 ) ans=tmp;
        else{
          if( get<0>(t[i])==0 && tmp<ans ){
            comp=false;
            break;
          }
          else if( get<0>(t[i])>0 && ans!=tmp  ){
            comp=false;
            break;
          }
          
        }

      }
      if(comp){
        
        cout << cx << " " << cy << " " << ans << endl;

        return 0;
      }
    }
  }

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 256
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

con = 10 ** 9 + 7
#入力受け取り
def getlist():
	return list(map(int, input().split()))

def Binary_Search(A, N, M, V, P):
	#初期化
	#B:累積和
	B = [0]
	for i in range(N):
		B.append(B[i] + A[i])
	ans = float("inf")
	left = 0
	right = N - 1
	#二分探索
	while left <= right:
		mid = (left + right) // 2
		if (A[mid] + M) * (N - P - mid) >= B[N - P + 1] - B[mid + 1] + (V - mid - P) * M and A[mid] + M >= A[N - P]:
			ans = min(ans, mid)
			right = mid - 1
		elif mid >= N - P:
			ans = min(ans, mid)
			right = mid - 1
		else:
			left = mid + 1

	return N - ans

#処理内容
def main():
	N, M, V, P = getlist()
	A = sorted(getlist())
	ans = Binary_Search(A, N, M, V, P)

	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 56944
#include <bits/stdc++.h>
using namespace std;
long long N,P;
vector<long long> A(60);
long long memo[60][3];

long long dp(long long n,long long p){
  if(n==N){
    if(p==P){return 1;}
    else{return 0;}
  }
  if(memo[n][p]!=-1){return memo[n][p];}
  else{
    return memo[n][p]=dp(n+1,p)+dp(n+1,(p+A[n])%2);
  }
}

int main(){
  cin >> N >> P;
  for(int i=0;i<N;i++)cin >> A[i];
  for(int i=0;i<=N;i++){
    for(int j=0;j<2;j++){memo[i][j]=-1;}
  }
  cout << dp(0,0) << endl;
}

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


int main(){
    int n, m,a[100],b[100];
    cin >> n >> m;
    for(int i = 1 ;i <= m;i++) cin >> a[i] >> b[i];
    
    int c[100] = {0},d[100]={0};

    for (int i = 1;i <= m;i++){
        c[a[i]]++;
        c[b[i]]++;
    }
    for (int i = 1;i <= n;i++)
    cout << c[i] << endl;



}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int E[5001], n[5001], C[5001], H[2501];
bool vis[2501];
void dfs(int v) {
	vis[v] = true;
	for (int p = H[v]; p; p = n[p]) {
		int to = E[p];
		if (!vis[to]) dfs(to);
	}
}

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


	int N, M, P;
	cin >> N >> M >> P;
	rep1(i, M) {
		int a;
		cin >> a >> E[i] >> C[i];
		n[i] = H[a];
		H[a] = i;
	}
	ll D[2501];
	rep1(i, N) D[i] = -2e9;
	D[1] = 0;
	int q[2501] = {};
	q[1] = 1;

	//こんな明らかに正しくない提出をして何をしたいというのかこの男は
	int cnt[2501] = {};
	int mushi = 0;

	rep1(k, N) {
		rep1(i, N) {
			if (q[i] == k) {
				for (int p = H[i]; p; p = n[p]) {
					int to = E[p];
					ll d = D[i] + C[p] - P;
					if (D[to] < d && to != mushi) {
						cnt[to]++;
						if (cnt[to] >= 200 && !mushi) mushi = to;
						D[to] = d;
						q[to] = k + 1;
					}
				}
			}
		}
	}

	rep1(i, N) {
		if ((q[i] == N + 1 || i == mushi) && !vis[i]) dfs(i);
	}

	if (vis[N]) co(-1);
	else co(max(0ll, D[N]));


	Would you please return 0;
}

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

using namespace std;
typedef pair<int,int> pii;

int main(){
    double a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    double ff= -1;
    double ss, tt;
    for(double i = 0; i <= 110; i++){
     for(double j = 0; j<=110; j++){
      for(double k = 0; k <= 110; k++){
       for(double l = 0; l <= 110; l++){
        double sugar = (k * c + l * d);
        if(i *a* e + j *b* e < sugar){
            continue;
        }
        if(i *a* 100 + j *b* 100 + k*c + l*d <= f){
            double perc = ((double) k*c + (double)l * d)*100. / ((double)((double)i *a* 100 + (double)j *b* 100
                                                                     + (double)k*c +(double) l*d));

            if(perc > ff){
                ff = perc;
                ss = 100.*(i*a + j*b);
                tt = (k*c + l*d);
            }
        }
       }
      }
     }
    }

    cout << (long long)(ss+tt )<< " " << (long long)(tt);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(void)
{
    int D;
    cin >> D;
    switch(D){
        case 25:
            cout << "Christmas" << endl;
            break;
        case 24:
            cout << "Christmas Eve" << endl;
            break;
        case 23:
            cout << "Christmas Eve Eve" << endl;
            break;
        case 22:
            cout << "Christmas Eve Eve Eve" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}

const int maxn=100005;
//i_am_noob
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	print1((str[2]==str[3]&&str[4]==str[5])?"Yes":"No");
	return 0;
}

Measured memory_bytes: 256
def solve(l:list)->int:
    ab_l = list(map(abs, l))
    del l[ab_l.index(min(ab_l))]
    return sum(l)


def main():
    n, k = map(int, input().split())
    l = [i + k for i in range(n)]
    print(solve(l))

if __name__ == "__main__":
    main()

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

int main() {
  long n,max = 0,nax = 0;
  cin >> n;
  vector<long>data(n);
  for(long i = 0;i < n;i++){
    cin >> data.at(i);
    if(data.at(i) >= max){
      nax = max;
      max = data.at(i);
    }
    else if(data.at(i) > nax){
      nax = data.at(i);
    }
  }
  for(long i = 0;i < n;i++){
    if(data.at(i) == max){
      cout << nax << endl;
    }
    else{
      cout << max << endl;
    }
  }
}


Measured memory_bytes: 3200
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
Sum = 0
for i in range(X):
  Sum += p[i]
for j in range(Y):
  Sum += q[j]
cntp, cntq = X-1, Y-1
flg = 0

for i in range(C):
  dp, dq = 0, 0
  if cntp >= 0:
    if r[i] > p[cntp]:
      dp = r[i] - p[cntp]
  if cntq >= 0:
    if r[i] > q[cntq]:
      dq = r[i] - q[cntq]
  if dp == 0 and dq == 0:
    break
  else:
    if dp >= dq:
      Sum += dp
      cntp -= 1
    else:
      Sum += dq
      cntq -= 1
print(Sum)

Measured memory_bytes: 23328
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        int H = 0;
        int W = 0;

        int[][] board;
        try (Scanner sc = new Scanner(System.in)) {
            H = sc.nextInt();
            W = sc.nextInt();
            board = new int[H][W];
            for (int i = 0; i < H; i++) {
                String s = sc.next();

                int w = 0;
                for (char c : s.toCharArray()) {
                    if (c == '#') {
                        board[i][w] = -1;
                    } else {
                        board[i][w] = 0;
                    }
                    w++;
                }
            }
        }
        //横
        int[][] boardW = new int[H][W];
        //縦
        int[][] boardH = new int[H][W];

        //横のライトのマスを各マス計算
        for (int h = 0; h < H; h++) {
            int temp1 = 0;
            int temp2 = 0;
            for (int w = 0; w < W; w++) {

                if (board[h][w] == 0) {
                    temp2 = w;
                }
                if (board[h][w] == 0 && w != W - 1) {
                    continue;
                }
                int max = (temp2 - temp1) + 1;
                //temp1～temp2までをmaxで更新する
                for (int n = temp1; n <= temp2; n++) {
                    if(board[h][n] == -1 ){
                        boardH[h][n] = 0;
                        continue;
                    }
                    boardW[h][n] = max;
                }
                temp1 = w + 1;
                temp2 = w + 1;

            }
        }

        //縦のライトのマスを各マス計算
        for (int w = 0; w < W; w++) {
            int temp1 = 0;
            int temp2 = 0;
            for (int h = 0; h < H; h++) {

                if (board[h][w] == 0) {
                    temp2 = h;
                }
                if (board[h][w] == 0 && h != H-1) {
                    continue;
                }
                int max = (temp2 - temp1) + 1;

                //temp1～temp2までをmaxで更新する
                for (int n = temp1; n <= temp2; n++) {
                    if(board[n][w] == -1 ){
                        boardH[n][w] = 0;
                        continue;
                    }
                    boardH[n][w] = max;
                }
                temp1 = h +1;
                temp2 = h +1;

            }
        }
        //
        int max = 0;
        for (int h = 0; h < H; h++) {
            for (int w = 0; w < W; w++) {
                /*
                System.out.println("h,w:"+h+","+w);
                System.out.println("boardH:"+boardH[h][w]);
                System.out.println("boardW:"+boardW[h][w]);
                */
                int temp = (boardH[h][w] + boardW[h][w])-1;
                if (max < temp) {
                    max = temp;
                }
            }
        }
        System.out.println(max);

    }

}


Measured memory_bytes: 106128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i< int(n); i++)
int main(){
int N, M;
cin >> N >> M;
vector<int> seq(N,0);
seq.at(0)=1;
vector<int> position(M+10);
vector<int> change(M+10);
rep(i,M){
    cin >> position.at(i) >> change.at(i);
}
//入力完了

int non=0;
rep(i,M){
    rep(j,M){
        if (position.at(i)==position.at(j) && change.at(i)!= change.at(j)){
            non++;
        }
    }
}

if (position.at(0)==1 && change.at(0)==0) {
    if (N>1) non++;
}

rep(i,M){
    seq.at(position.at(i)-1)=change.at(i);
}


if (non>0) cout << -1 << endl;
else if (N==1 && M==0) cout << 0 << endl;
else{
    rep(i,N){
    cout << seq.at(i);
    }
    cout << endl;
}

}

Measured memory_bytes: 256
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
sum_v = sum(wv[i][1] for i in range(n))
sum_w = sum(wv[i][0] for i in range(n))

dp = [[sum_w + 1] * (sum_v + 1) for i in range(n + 1)]
dp[0][0] = 0

for i in range(n):
    for j in range(sum_v + 1):
        if j - wv[i][1] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - wv[i][1]] + wv[i][0])
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])

ans = 0
for j in range(sum_v + 1):
    if dp[n][j] <= w:
        ans = max(ans, j)
print(ans)

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<int>());
    ll ans = 0;
    if (N % 2 == 0) {
        for (int i = 0; i < N/2 - 1; i++) ans += 2 * A[i];
        ans += A[N/2-1];
        ans -= A[N/2];
        for (int i = N/2 + 1; i < N; i++) ans -= 2 * A[i];        
    } else {
        ll t1 = 0, t2 = 0;
        int m = (N-1)/2;
        
        for (int i = 0; i < m-1; i++) t1 += 2 * A[i];
        t1 += A[m-1] + A[m];
        for (int i = m+1; i < N; i++) t1 -= 2 * A[i];
        
        for (int i = 0; i < m; i++) t2 += 2 * A[i];
        t2 -= A[m] + A[m+1];
        for (int i = m+2; i < N; i++) t2 -= 2 * A[i];

        ans = max(t1, t2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
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; }
void rcmb(ll *x,ll s,ll r,function<void(ll *)>f){if(r==0){f(x);}else{if(s<0)return;rcmb(x,s-1,r,f);x[r-1]=s;rcmb(x,s-1,r-1,f);}}
void cmb(ll n,ll k,function<void(ll *)>f){ll x[k];rcmb(x,n-1,k,f);}
void prm(ll n,function<void(ll *)>f){ll x[n];for(ll i=0;i<n;i++)x[i]=i;do{f(x);}while(next_permutation(x,x+n));}
void prm(ll n,ll k,function<void(ll *)>f){cmb(n,k,[&](ll *c){prm(k,[&](ll *p){ll x[k];for(ll i=0;i<k;i++){x[i]=c[p[i]];}f(x);});});}
// prm(4, 2, [](ll *x){ cout << x[0] << "," << x[1] << "\n"; });


int main(){
	vector<ll> V(5);
	REP(i,5) cin >> V[i];
	ll min = 1e18;
	do{
		ll sum = 0;
		REP(i, 5) {
			sum += V[i];
			if (i<4 && sum%10!=0) sum += 10-sum%10;
		}
		chmin(min, sum);
	}while(next_permutation(ALL(V)));
	cout << min << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<map>
using namespace std;
typedef long long LL;

LL a[100005];

int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n ; i++){
		scanf("%lld", &a[i]);
	}
	LL ans = 0;
	for(int i = 1; i <= n; i++){
		ans += a[i] / 2;
		if(a[i] % 2 == 0) continue;
		else {
			if(a[i + 1] != 0) {ans++; a[i + 1]--; continue;}
			else continue;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX
typedef pair<int, int> P;
int main(){
   int n;
   cin>>n;
   vector<int> v;
   int d;
   rep(i,n){
       cin>>d;
       v.push_back(d);
   }
   sort(v.begin(),v.end());
   int ce=v.size()/2;
   int ans=v[ce]-v[ce-1];
   cout<<ans<<endl;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define N 2000010
#define INF 0x3f3f3f3f

using namespace std;

int n_road,n_rail;
int city;
int road_cont[2][N];
int road[2][N];
bool visit[N];
int cont[N];

set <int> way_con[2][N],temp_cont;
set<int>::iterator it;

int path[N];

int Find(bool way,int x)
{
    //while (x!=road_cont[way][x])x=road_cont[way][x]
    if(x==road_cont[way][x])return x;
    else return road_cont[way][x]=Find(way,road_cont[way][x]);
}

void join(bool way,int a,int b)
{
    if(road[way][a]<road[way][b]) road_cont[way][a]=b;
    else
    {
        road_cont[way][b]=a;
        if(road[way][a]==road[way][b]) ++road[way][a];
    }
}

/*bool ok_road(int a,int b)
{
    if(Find1(a)==Find1(b))return true;
    else return false;
}
bool ok_rail(int a,int b)
{
    if(Find2(a)==Find2(b))return true;
    else return false;
}*/

void Create()
{
    int i;
    int x,y;
    for(i=1; i<=city; ++i)
    {
        road_cont[0][i]=road_cont[1][i]=i;
    }
    for(i=1; i<=n_road; ++i)
    {
        scanf("%d%d",&x,&y);

        int f1=Find(0,x);
        int f2=Find(0,y);
        if(f1!=f2) join(0,f1,f2);
    }
    for(i=1; i<=n_rail; ++i)
    {
        scanf("%d%d",&x,&y);

        int f1=Find(1,x);
        int f2=Find(1,y);
        if(f1!=f2) join(1,f1,f2);
    }
}

int main()
{
    scanf("%d%d%d",&city,&n_road,&n_rail);
    Create();
    for(int i=0; i<=1; ++i)
    {
        for(int j=1; j<=city; ++j)
        {
            way_con[i][Find(i,j)].insert(j);
        }
    }
    int e;
    for(int i=1; i<=city; ++i)
    if(!visit[i])
    {
        e=0;
        int way[2];
        bool ok=0;
        way[0]=Find(0,i);
        way[1]=Find(1,i);
        if(way_con[0][way[0]].size() > way_con[1][way[1]].size())
        {
            ok=1;
        }
        temp_cont=way_con[ok][way[ok]];

        for(it=temp_cont.begin(); it!=temp_cont.end(); ++it)
        {
            int p=*it;
            if(way_con[!ok][way[!ok]].find(p)!=way_con[!ok][way[!ok]].end())
            {
                way_con[ok][way[ok]].erase(p);
                way_con[!ok][way[!ok]].erase(p);
                path[++e]=(p);
                visit[p]=1;
            }
        }
        for(int j=1; j<=e; ++j)
        {
            cont[path[j]]=e;
        }
    }
    for(int i=1; i<=city; ++i)
    {
        if(i!=1)printf(" ");
        printf("%d",cont[i]);
    }
    return 0;
}


Measured memory_bytes: 227712
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad.ST            (ST)
import           Data.Bits                   (shiftR)
import qualified Data.ByteString.Char8       as BC
import           Data.Vector.Unboxed         (Vector, (!))
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

main :: IO ()
main = do
  n <- readLn
  as <- V.unfoldr (BC.readInt . BC.dropWhile (== ' ')) <$> BC.getLine
  print $ solve n as

solve :: Int -> Vector Int -> Int
solve n as = V.sum $ V.map (\b -> abs (b - m)) bs where
  bs = V.zipWith (-) as $ V.fromList [1 .. ]
  m = median n bs

median :: Int -> Vector Int -> Int
median n xs = xs' ! (n `div` 2) where
  xs' = sort xs

sort :: Vector Int -> Vector Int
sort = V.modify (\v -> quicksort v 0 (VM.length v))

-- https://github.com/as-capabl/haskell-qsort-pfm/blob/master/src/UV.hs
quicksort :: VM.STVector s Int -> Int -> Int -> ST s ()
quicksort work iStart iEnd
    | iEnd - iStart <= 1 = return ()
    | otherwise = do
        pivot <- VM.unsafeRead work (((iEnd - iStart) `shiftR` 1) + iStart)
        med <- divide pivot iStart (iEnd - 1)
        quicksort work iStart med
        quicksort work med iEnd
  where
    divide pivot iS' iE'
        | iS' > iE' = return iS'
        | otherwise = do
            lower <- shrinkLower pivot iS' iE'
            higher <- shrinkHigher pivot lower iE'
            if lower >= higher
              then do
                return lower
              else do
                swapWork lower higher
                divide pivot (lower + 1) (higher - 1)

    shrinkLower pivot iS' iE'
        | iS' > iE' = return iS'
        | otherwise = do
            x <- VM.unsafeRead work iS'
            if x >= pivot
              then
                return iS'
              else
                shrinkLower pivot (iS' + 1) iE'

    shrinkHigher pivot iS' iE'
        | iS' > iE' = return iE'
        | otherwise = do
            x <- VM.unsafeRead work iE'
            if x <= pivot
              then
                return iE'
              else
                shrinkHigher pivot iS' (iE' - 1)

    swapWork i j = VM.unsafeSwap work i j


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    double n,m,d;cin >> n >> m >> d;
    double ans = 0;
    if(d!=0)
    {
        ans += (double)(m-1)*((double)2 * (double)(n - d) / (double)(n * n));
    }else
    {
        ans += (m-1)/n;
    }
    cout << setprecision(11) <<  ans << endl;
}

Measured memory_bytes: 3768
#include<iostream>
#include <algorithm>
#include<functional>//greaterの使用
using namespace std;
#define MAX_LIST 999983+100
#define MP 999983

int main(){
	bool prime[MAX_LIST];
	for(int i=0;i<MAX_LIST;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<MAX_LIST;i++){
		if(prime[i]==1){
			for(int j=i*2;j<MAX_LIST;j=j+i){
				prime[j]=0;
			}
		}
	}
	for(int i=MP+1;i<MAX_LIST;i++){
		prime[i]=0;
	}
	int prime_num[MAX_LIST];
	prime_num[0]=1;
	for(int i=1;i<MAX_LIST;i++){
		prime_num[i]=prime_num[i-1]+prime[i];
	}
	
	
	int pair_num;
	while(cin>>pair_num,pair_num){
		int ans=0;
		for(int i=0;i<pair_num;i++){
			int p,m;
			cin>>p;
			cin>>m;
			int x=0;
			int a,b;
			if(p+m>MP){
				a=MP;
			}else{
				a=p+m;
			}
			if(p-m<0){
				b=0;
			}else{
				b=p-m;
			}
			x=prime_num[a]-prime_num[b]+prime[b];
			
			if(x==0){
				ans--;
			}else{
				x--;
				ans=ans+x;
			}
			
		}
		cout<<ans<<endl;
	}
	return 0;
}

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


int main()
{
        int n;
        cin>>n;
        double a[n];
        for(int i=0;i<n;i++)
        {
                cin>>a[i];
        }
        double sum=0;
        for(int i=0;i<n;i++)
        {
                sum+=1/a[i];
        }
        sum=1/sum;
        cout<<sum<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) { 
		Scanner scn = new Scanner(System.in);
		int n =scn.nextInt();
		int k =scn.nextInt();
		ArrayList<Integer> arr=new ArrayList<Integer>();
		for(int j=0;j<n;j++) {
			int h=scn.nextInt();
			arr.add(h);
		}int ans=0;
		for(int j=0;j<n;j++) {
			if(arr.get(j)>=k) {
				ans++;
			}
		}System.out.println(ans);
    }
}

Measured memory_bytes: 50264
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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

	cout << t / a * b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun May 31 16:53:00 JST 2020
 **/

void print(std::vector<Int>& a) {
    REP(i, a.size()) std::cout << a[i] << (i == a.size() - 1 ? "" : " ");
    std::cout << std::endl;
}
signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    auto x = a, y = a;
    if (std::prev_permutation(x.begin(), x.end())) print(x);
    print(a);
    if (std::next_permutation(y.begin(), y.end())) print(y);
}



Measured memory_bytes: 3212
#!/usr/bin/env python3
import sys


def solve(H: int, A: int):
    print(H // A + 1 if H % A else H // A)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    solve(H, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
from sys import *
x = int(stdin.readline())
if x >= 400 and x <= 599:
    print(8)
elif x >= 600 and x <= 799:
    print(7)
elif x >= 800 and x <= 999:
    print(6)
elif x >= 1000 and x <= 1199:
    print(5)
elif x >= 1200 and x <= 1399:
    print(4)
elif x >= 1400 and x <= 1599:
    print(3)
elif x >= 1600 and x <= 1799:
    print(2)
elif x >= 1800 and x <= 1999:
    print(1)

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, x); }
template<class T, class U> void init(vector<T> &v, U x, size_t n, size_t m...) { v=vector<T>(n); for(auto& a : v) init(a, x, m);}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n;
    cin >> n;
    string s;
    cin >> s;
    // k:  RRRR x k WWWW x (n-k)

    vector<int> cntw(n), cntr(n);
    FOR(i, n){
        cntw[i] += s[i] == 'W';
        cntr[i] += s[i] == 'R';
        if (i){
            cntw[i] += cntw[i-1];
            cntr[i] += cntr[i-1];
        }
    }

    int sol = 0;
    int i = 0, j = n-1;
    while(i < j){
        while(i < j && s[i] == 'R') i++;
        while(i < j && s[j] == 'W') j--;
        if (i == j) break;
        swap(s[i], s[j]);
        sol++;
    }
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}



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

using namespace std;

int main () {
	int n;
	scanf("%d", &n);
	long long ans = 0;
	for (int i = 1; i <= n; i++)
		if (i % 3 != 0 && i % 5 != 0)	
			ans += i;
	printf("%lld", ans);
	return 0;
}


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

int main()
{
    string s;
    getline (cin, s);
    int ans = 0;
    for (int i = 0; i < s.size(); i++)
    {
        ans += ((s[i] == '+') ? 1 : -1);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define INF (1ll<<60)

using namespace std;
int main(){
	ll N;
  cin >> N;
  vector<vector<ll>> h;
  h.resize(N);
  for(ll i=0;i<N;i++){
  	h[i].resize(3);
  }
  for(ll i=0;i<N;i++){
    for(ll j=0;j<3;j++){
      cin >> h[i][j];
    }
  }
  
  auto dp=h;
  for(ll i=0;i<N;i++){
    for(ll j=0;j<3;j++){
    	dp[i][j]=-INF;
    }
  }
  dp[0][0]=h[0][0];
  dp[0][1]=h[0][1];
  dp[0][2]=h[0][2];
  for(ll i=1;i<N;i++){
  	for(ll a=0;a<3;a++){
      for(ll b=0;b<3;b++){
      	if(a==b)continue;
        dp[i][a]=max(dp[i-1][b]+h[i][a],dp[i][a]);
      }
    }
  }
  auto res=max(max(dp[N-1][0],dp[N-1][1]),dp[N-1][2]);
      cout <<res << endl;
}

Measured memory_bytes: 13996
#include<stdio.h>

int main()
{
	int r, c;
	scanf("%d %d", &r, &c);
	int i, j, graph[100][100];
	for (i = 0; i <= r-1; i++)
	{
		for (j = 0; j <= c-2; j++)
		{
			scanf("%d ", &graph[i][j]);
		}
		scanf("%d", &graph[i][c - 1]);
	}
	int rtotal[100] = { 0 };
	for (i = 0; i <= r - 1; i++)
	{
		for (j = 0; j <= c - 1; j++)
		{
			rtotal[i] += graph[i][j];
		}
	}
	int ctotal[100] = { 0 };
	for (i = 0; i <= c - 1; i++)
	{
		for (j = 0; j <= r - 1; j++)
		{
			ctotal[i] += graph[j][i];
		}
	}
	for (i = 0; i <= r-1; i++)
	{
		for (j = 0; j <= c-1; j++)
		{
			printf("%d ", graph[i][j]);
		}
		printf("%d\n", rtotal[i]);
	}
	for (i = 0; i <= c - 1; i++)
	{
		printf("%d ", ctotal[i]);
	}
	int all = 0;
	for (i = 0; i <= r - 1; i++)
	{
		all += rtotal[i];
	}
	printf("%d\n", all);

}

Measured memory_bytes: 1068
import statistics
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
	A[i] = A[i] - (i+1)
A.sort()

if N % 2 == 0:
	med1 = A[N // 2 - 1]
	med2 = A[N //2]
	ans = min(sum([abs(a - med1) for a in A]), sum([abs(a - med2) for a in A]))

else:
	med = A[N // 2]
	ans = sum([abs(a - med) for a in A])
	
print(ans)

Measured memory_bytes: 27244
/**
 *  author: mahfuzz
 *  created: 13.06.2020
**/
 
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(), (a).end()
#define trace(x) cout << #x << ':' << x << "\n"
typedef long long ll;


int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    string ans[] = {"pon", "pon", "hon", "bon", "hon", 
            "hon", "pon", "hon", "pon", "hon"};
    
    int n; cin >> n;
    cout << ans[n % 10] << "\n";
        
    return 0;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
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;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

// 正四面体数
vector<int> all, odd;

const int MAX = 1000000;
vector<int> dp, dp2;

bool solve() {
    int n;
    cin >> n;
    if(n == 0) {
        return 0;
    }
    print(dp[n], dp2[n]);
    return 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 1;; i++) {
        int s = i * (i + 1) * (i + 2) / 6;
        if(s >= 1000000) {
            break;
        }
        all.emplace_back(s);
        if(s & 1) {
            odd.emplace_back(s);
        }
    }
    int N = all.size();
    dp.assign(MAX + 1, INF);
    dp[0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = all[i]; j <= MAX; j++) {
            chmin(dp[j], dp[j - all[i]] + 1);
        }
    }
    N = odd.size();
    dp2.assign(MAX + 1, INF);
    dp2[0] = 0;
    for(int i = 0; i < N; i++) {
        for(int j = odd[i]; j <= MAX; j++) {
            chmin(dp2[j], dp2[j - odd[i]] + 1);
        }
    }
    while(1) {
        if(!solve()) {
            break;
        }
    }
}


Measured memory_bytes: 10636
/**
*    created: 14.06.2020 21:05:44
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int x, n;
    cin >> x >> n;
    set<int> p;
    rep(i,n) {
        int a;
        cin >> a;
        p.insert(a);
    }
    vector<pair<int,int>> ans;
    rep(i,102) {
        if (p.count(i) == 0) ans.push_back(make_pair(abs(i-x),i));
    }
    sort(ans.begin(),ans.end());
    cout << ans[0].second << endl;
    return 0;
}

Measured memory_bytes: 3656
#include<stdio.h>

int main(){
	int A,B,C,D,P,x,y;
	scanf("%d \n%d \n%d \n%d \n%d",&A,&B,&C,&D,&P);
	x = P*A;
	if(P <= C){
		y = B;
	}else{
		y = B + ((P-C)*D);
	}
	if(x <= y){
		printf("%d\n",x);
	}else{
		printf("%d\n",y);
	}
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int n,k;
int a[105];
int dp[100005];

int main(){
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=0;i<=k;i++){
		dp[i]=0;
		for(int j=1;j<=n;j++){
			if(i<a[j]) break;
			if(dp[i-a[j]]==0) dp[i]=1;
		}
	}
	if(dp[k]==1) printf("First\n");
	else printf("Second\n");
	
	return 0;
}

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

int main() {

	string a, b;
	cin >> a >> b;
	//cout << a << b;
	for (int i=0; i<a.size(); i++)
	{
     rotate(a.begin(), a.begin()+1, a.end());
     
     if(a == b)
     {
     	cout << "Yes";
     	return 0;
     }
     }
     cout << "No";
	return 0;
}

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

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

using namespace std;

struct rectangle{
  int h; int w; int diagsq;
  bool operator<(const rectangle& x){
    if(diagsq < x.diagsq) return true;
    if(diagsq > x.diagsq) return false;
    if(h < x.h) return true;
    return false;
  }
  bool operator==(const rectangle& x){
    if(h == x.h and w == x.w) return true;
    return false;
  }
};

int main(){
  vector<rectangle> recs;
  REP(i, 155) REP(j, i){
    if(i*j == 0) continue;
    recs.push_back({j, i, j*j+i*i});
  }
  sort(ALL(recs));
  int h, w;
  while(cin >> h >> w and h + w){
    rectangle target = {h, w, h*h+w*w};
    REP(i, recs.size())
      if(recs[i] == target) { cout << recs[i+1].h << " " << recs[i+1].w << endl; break;}
  }
  return 0;
}

Measured memory_bytes: 3184
# Union-Find木を使って書き直し

# Union-Find木（サイズ付き）
class UnionFind():
    def __init__(self, n):  # n要素で初期化　初めは全ての頂点が別々の木の根
        self.parent = [None] * n # 親
        self.rank = [None] * n   # 木の深さ
        self._size = [1] * n # 要素が属する集合の大きさ（根の要素のみ参照すること）
        for i in range(n):
            self.parent[i] = i
            self.rank[i] = 0

    # 木の根を求める
    def root_of(self, x):
        children = [x]
        while self.parent[x] != x:
            x = self.parent[x]
            children.append(x)

        for ch in children: # 根の子供として張りなおす
            self.parent[ch] = x

        return x

    # xとyの属する集合を併合
    def unite(self, x, y):
        rx = self.root_of(x)
        ry = self.root_of(y)
        if rx == ry:
            return
        if self.rank[rx] < self.rank[ry]: # ランクの小さい木から大きい木の根に辺を張る
            self.parent[rx] = ry  # rxをryの子とする
            self._size[ry] += self._size[rx]
        else:
            self.parent[ry] = rx
            self._size[rx] += self._size[ry]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    # 同じ集合に属するかどうか
    def is_same(self, x, y):
        return self.root_of(x) == self.root_of(y)

    # 頂点xが属する集合のサイズ
    def size(self, x):
        return self._size[self.root_of(x)]

# 入力
N, M = [int(x) for x in input().split()]
A = [None] * M
B = [None] * M
for i in range(M):
    A[i], B[i] = [int(x) - 1 for x in input().split()]


# 島同士が全く繋がっていない状態からスタート
# M-1番目, M-2番目, ..., , 2番目, 1番目の橋の順に橋をかけていく
inconv = [-1] * (M - 1) + [N * (N - 1) // 2]    # 不便さ

uf = UnionFind(N)

for i in range(M - 1, 0, -1):
    # i番目の橋をかける
    if not uf.is_same(A[i], B[i]):
        size_a = uf.size(A[i]) # A[i]が属する集合の大きさ
        size_b = uf.size(B[i]) # B[i]が属する集合の大きさ
        inconv[i - 1] = inconv[i] - size_a * size_b
        uf.unite(A[i], B[i])
    else:
        inconv[i - 1] = inconv[i]

for i in range(M):
    print(inconv[i])


Measured memory_bytes: 76120
n = gets.to_i
a = gets.split.map(&:to_i)
b = Array.new(n)
cnt = 1
n.times do |i|
    if i % 2 == 1
        b[-cnt] = a[n - i - 1]
        cnt += 1
    else
        b[cnt - 1] = a[n - i - 1]
    end
end

puts b.join(' ')

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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)


int main(void){

	int N; cin >> N;
	vector<int> x(N);
	vector<int> y(N);
	vector<int> idx(N);


	REP(i,N){
		cin >> x[i] >> y[i];
		idx[i] = i;
	}

	double ans = 0.0;
	int cnt = 0;

	do{
		double sum = 0.0;	
		FOR(i,1,N){
			int a = idx[i];
			int b = idx[i-1];
			
			sum += sqrt(pow(x[a]-x[b],2) + pow(y[a]-y[b],2));
		}

		ans += sum;
		cnt++;
	}while(next_permutation(idx.begin(), idx.end()));

	ans /= cnt;
	cout << setprecision(16) <<  ans << endl;



	return 0;

}


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

using namespace std;


int main() {
    int a, b, c, sum;
    cin >> a >> b >> c;
    sum = a + b + c;

    int MAX, MID, MIN;
    MAX = max(max(a, b), c);
    MIN = min(min(a, b), c);
    MID = sum - (MAX + MIN);

    cout << (MAX * 10 + MID) + MIN << endl;
}


Measured memory_bytes: 3640
N = list(input())
num = list(map(lambda x: int(x) , N))
for i in range(8):
    sum_val = num[0]
    for j in range(3):
        if i >> j & 1:
            sum_val += num[j + 1]
        else:
            sum_val -= num[j + 1]
    if sum_val == 7:
        print(num[0] , end = '')
        for j in range(3):
            if i >> j & 1:
                print("+" , end = '')
            else:
                print("-",end = '')
            print(num[j + 1] , end = '')
        print('=7')
        exit()


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    string s, t, a;
    cin >> s >> t;
    a = t.substr(0, t.length()-1);

    if(s == a){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,i,a,x=0,cnt=0;
    scanf("%d",&n);
    int sz[n],b[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&sz[i]);
        b[i]=sz[i];
    }
    a=0;
    sort(b,b+n);
    for(i=0;i<n;i++)
    {
       // printf("sz[i]=%db[n/2+1]%d ",sz[i],b[n/2+1]);
        if(sz[i]<b[n/2])
            printf("%d\n",b[n/2]);
        else
        {
             printf("%d\n",b[n/2-1]);
        }
    }
    return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>

int main(void)
{
	int r,c,i,j,xy[101][101];

	scanf("%d %d",&r,&c);
	for(i=0;i<r+1;i++)
	{
		for(j=0;j<c+1;j++)
		{
			xy[i][j] = 0;
		}
	}
	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			scanf("%d",&xy[i][j]);
		}
	}
	for(i=0;i<r;i++)
	{
		for(j=0;j<c;j++)
		{
			xy[i][c] += xy[i][j];
		}
	}
	for(i=0;i<r;i++)
	{
		for(j=0;j<c+1;j++)
		{
			xy[r][j] += xy[i][j];
		}
	}
	for(i=0;i<r+1;i++)
	{
		for(j=0;j<c+1;j++)
		{
			printf("%d",xy[i][j]);
			if(j!=c)
			{
				printf(" ");
			}
		}
			printf("\n");
	}
	return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int cnt = 0;
    while (b - a >= 0)
    {
        if (cnt == c)
            break;
        cnt++;
        b -= a;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n, w = map(int, input().split())
    ws = [0 for _ in range(n)]
    vs = [0 for _ in range(n)]
    dp = [[0 for _ in range(w + 1)] for _ in range(n + 1)]

    for i in range(n):
        wi, vi = map(int, input().split())
        ws[i] = wi
        vs[i] = vi

    for i in range(n):
        for sum_w in range(w + 1):
            if sum_w - ws[i] >= 0:
                dp[i + 1][sum_w] = max(dp[i + 1][sum_w],
                                       dp[i][sum_w - ws[i]] + vs[i])

            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

    print(dp[n][w])


if __name__ == '__main__':
    main()


Measured memory_bytes: 171528
using System;

namespace AtCoderBC113C_ID
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);

            int[][] city = new int[M][];

            for(int i=0;i<M;i++)
            {
                string[] c = Console.ReadLine().Split(' ');

                city[i] = new int[4];

                city[i][0] = int.Parse(c[0]);
                city[i][1] = int.Parse(c[1]);
                city[i][2] = i;
            }

            OrgComparer comp = new OrgComparer();
            Array.Sort(city, comp);

            int[] pref = new int[N];

            for(int i=0;i<M;i++)
            {
                city[i][3] = pref[city[i][0]-1];
                pref[city[i][0]-1]++;
            }

            IdComparer icomp = new IdComparer();
            Array.Sort(city, icomp);

            for(int i=0;i<M;i++)
            {
                String ans = city[i][0].ToString("000000") + (city[i][3] + 1).ToString("000000");
                Console.WriteLine(ans);
            }

            Console.ReadKey();
        }
    }

    public class PrefComparer : System.Collections.IComparer
    {
        public int Compare(object x, object y)
        {
            int[] X = (int[])x;
            int[] Y = (int[])y;

            if (X[0] < Y[0])
                return -1;
            if (X[0] > Y[0])
                return 1;

            return 0;
        }
    }


    public class OrgComparer : System.Collections.IComparer
    {
        public int Compare(object x,object y)
        {
            int[] X = (int[])x;
            int[] Y = (int[])y;

            if (X[1] < Y[1])
                return -1;
            if (X[1] > Y[1])
                return 1;

            return 0;
        }
    }
    public class IdComparer : System.Collections.IComparer
    {
        public int Compare(object x, object y)
        {
            int[] X = (int[])x;
            int[] Y = (int[])y;

            if (X[2] < Y[2])
                return -1;
            if (X[2] > Y[2])
                return 1;

            return 0;
        }
    }
}


Measured memory_bytes: 26328
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'

signed main() {
    fio();
    int n, s;
    cin >> n >> s;
    vl a(n);
    rep (i, n) cin >> a[i];

    vll dp(n + 1, vl(s + 1));
    dp[0][0] = 1;
    rep (i, n) {
        rep (j, s + 1) {
            if (j + a[i] <= s) {
                (dp[i + 1][j + a[i]] += dp[i][j]) %= MOD;
            }
            (dp[i + 1][j] += 2 * dp[i][j]) %= MOD;
        }
    }
    cout << dp[n][s] << endl;
}

Measured memory_bytes: 73692