akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace boost::multiprecision;
//cpp_int 多倍長

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)

int A[100001];
cpp_int mxa[100001];
int N;
//3
//0 1 1 3
int sol(){

    //test();
    cin>>N;
    int mn=1;
    cpp_int mx=1;
    for(int i=0;i<N+1;i++){
        cin>>A[i];
        //cout<<",,,,"<<mx<<endl;
        mx-=A[i];
        mxa[i]=mx;
        if(mx<=0&&i!=N||mx<0&&i==N){
            //cout<<"-1"<<endl;
            return -1;
        }
        mx*=2;
    }


    int bef=A[N];
    int ans=A[N];
    for(int i=N-1;i>=0;i--){
        //cout<<ans<<","<<bef<<","<<mxa[i]<<endl;
        if(mxa[i]>bef) mxa[i]=bef;
        ans+=min(bef,(long long)mxa[i])+A[i];
        bef=min(bef,(long long)mxa[i])+A[i];
    }
    return ans;
}

int dfs(int deep,int leaf,int edge){
    if(deep>N+1) return -1;
    int sa=leaf-A[deep];
    if(sa==0&&deep==N) return edge;
    if(sa<0) return -1;
    //cout<<edge<<","<<leaf<<","<<sa<<endl;
    int ret=-1;
    for(int i=0;i<=sa;i++){
        ret=max(ret,dfs(deep+1,i+(sa-i)*2,edge+i+(sa-i)*2));
    }
    return ret;
}

void test(){
    N=3;
    for(int l=0;l<=9;l++){
    for(int i=0;i<=5;i++){
        for(int j=0;j<=3;j++){
            for(int k=0;k<=2;k++){
                A[0]=k;
                A[1]=j;
                A[2]=i;
                A[3]=l;
                int a=dfs(0,1,1);
                if(a!=sol()){
                    cout<<a<<","<<sol()<<","<<l<<","<<i<<","<<j<<","<<k<<endl;
                    cout<<"NO"<<endl;
                }
            }
        }
    }
    }
}

signed main(){
  //test();
  cout<<sol()<<endl;
}
/*
0,0,0,1,1
0,0,1,0,2
0,0,2,0,3
0,1,0,0,3
0,1,1,0,4
1,0,0,0,4
0,2,0,0,5
0,2,1,0,5
1,0,1,0,5
0,3,0,0,6
1,1,0,0,6
1,1,1,0,6
0,4,0,0,7
1,2,0,0,7
2,0,0,0,7
2,0,1,0,7
2,1,1,0,7
2,1,0,0,8
1,3,0,0,8
3,0,1,0,8
2,2,0,0,9
2,3,0,0,9
3,0,0,0,9
4,0,1,0,9
3,1,0,0,10
3,2,0,0,10
4,0,0,0,11
4,1,0,0,11
4,2,0,0,11
5,0,0,0,12
5,1,0,0,12
6,0,0,0,13
6,1,0,0,13
7,0,0,0,14
8,0,0,0,15
*/


Measured memory_bytes: 618876
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int[] x = new int[m];
        for (int i = 0; i < m; i++) {
            x[i] = in.nextInt();
        }
        ArrayList<Integer> diffs = new ArrayList<>();
        Arrays.sort(x);
        for (int i = 1; i < m; i++) {
            diffs.add(Math.abs(x[i] - x[i - 1]));
        }
        Collections.sort(diffs);
        int sum = 0;
        for (int i = 0; i < diffs.size() - (n - 1); i++) {
            sum += diffs.get(i);
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 49244
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
int main(){
    long long a,b,c,ans=0;
    cin >> a >> b >> c;
    if(a%c==0){
        cout << (b/c - a/c) +1 << endl;
    }
    else    
        cout << (b/c - a/c) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

    final int a = scanner.nextInt();
    final int b = scanner.nextInt();
    final int c = scanner.nextInt();
    int k = scanner.nextInt();

    int sum = 0;
    if (k >= a) {
      k -= a;
      sum += a;
    } else {
      sum += k;
      k = 0;
    }

    if (k >= b) {
      k -= b;
    } else {
      k = 0;
    }

    sum -= k;

    System.out.println(sum);
  }
}

Measured memory_bytes: 35772
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}

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

  string s; cin >> s;
  int k = s.size();

  int win = 0;

  for (int i = 0; i < k; ++i) {
    win += s[i] == 'o';
  }

  int res = 15 - k;

  if (res + win >= 8) {
    print("YES");
  } else {
    print("NO");
  }

  return 0;
}

Measured memory_bytes: 256
N = int(input())
pointR = []
pointB = []
for i in range(N):
    pointR.append(list(map(int, input().split())))
for i in range(N):
    pointB.append(list(map(int, input().split())))
pointR.sort(key = lambda t: t[0], reverse = True)
pointB.sort(key = lambda t: t[1])
ans = 0

Rok = [True] * N

for i in range(N):
    for j in range(N):
        if Rok[j]:
            if pointR[j][0] < pointB[i][0] and pointR[j][1] < pointB[i][1]:
                ans += 1
                Rok[j] = False
                break
print(ans)

Measured memory_bytes: 3064
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

H1, M1, H2, M2, K = map(int, input().split())

MS1 = H1 * 60 + M1
MS2 = H2 * 60 + M2

print(MS2 - MS1 - K)

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

#define ll long long
#define MOD 1000000007

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

	int n,k;
	cin>>n>>k;
	int snukes[n+1]={0};
	for(int i=0;i<n;i++) {
		int d;
		cin>>d;
		for(int i=0;i<d;i++) {
			int x;
			cin>>x;
			snukes[x]++;
		}
	}
	int ans=0;
	for(int i=1;i<n+1;i++) {
		if(!snukes[i]) ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3648
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = do
	n <- ( read :: String -> Int ) . concat . words <$> getLine
	let
		res = or [ i * i == n | i <- [ 1 .. 10000 ] ]
	putStrLn $ which "Yes" "No" $ res


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
int n,m;
string a[1000];
int main(){
  std::cin >> n >> m;
  for(int i = 1; i<=n; i++){
    std::cin >> a[i];
    a[i] = '.' + a[i];
  }
  for(int i = 0; i<n; i++){
    for(int j = 0; j<m; j++){
      if(a[i][j]=='#' && !(a[i-1][j]=='#' || a[i+1][j]=='#' || a[i][j-1]=='#' || a[i][j+1]=='#'))
        return 0*printf("No\n");
    }
  }
  printf("Yes\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#define mid ( ( l + r ) >> 1 )

const int N = 2e5 + 5 ;

int n , v[N] ;

inline bool check ( int x ) { // true 偏大左移 , false 偏小右移 
	for (int i = 0 ; i < n - 1 ; ++ i) {
		if ( ( v[n+i] > x && v[n+i+1] > x ) || ( v[n-i] > x && v[n-i-1] > x ) ) return false ;
		if ( ( v[n+i] <= x && v[n+i+1] <= x ) || ( v[n-i] <= x && v[n-i-1] <= x ) ) return true ;
	}
	return ( v[1] <= x && v[1] <= x ) ;
}

int main () {
	scanf ("%d" , & n ) ;
	for (int i = 1 ; i < ( n << 1 ) ; ++ i) scanf ("%d" , & v[i] ) ;
	int l = 1 , r = ( n << 1 ) - 1 ;
	while ( l < r ) {
		if ( check ( mid ) ) r = mid ;
		else l = mid + 1 ;
	}
	printf ("%d\n" , r ) ;
	return 0 ;
}

Measured memory_bytes: 1152
l=[int(x) for x in raw_input().split(" ")]

def gcd(a,b):
    if a > b:
        mod = a % b
        if mod==0: return b
        return gcd(b, mod)
    else:
        mod = b % a
        if mod==0: return a
        return gcd(a, mod)

print gcd(l[0], l[1])

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

int main(){
  int i,j,cnt;
  int n;
  string s;
  cin>>n;
  cin>>s;
  char p[s.size()];
  for(i=0;i<s.size();i++){
    p[i]=(s[i]-'A'+n)%26+'A';
  }
  for(i=0;i<s.size();i++){
    cout<<p[i];
  }
}


Measured memory_bytes: 256
n = int(input())
arr = [int(x) for x in input().split()]
arr = sorted(arr)
arr.reverse()
d = []
d.append(1)
current = 0
s = 0
for i in range(1,len(arr)):
    d[current] -= 1
    s += arr[current]
    if d[current] == 0:
        current += 1
    d.append(2)
print(s)


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

struct data {
    int num, id;
};

bool comp(const data& d1, const data& d2) {
    return d1.num > d2.num;
}

int main() {
    int n, m;
    while(cin >> n >> m && n!=0 && m!=0) {
        vector<data> v(m);
        for(int i=0; i<m; ++i) {
            v[i].num = 0;
            v[i].id = i+1;
        }
        for(int i=0; i<n; ++i) {
            for(int j=0; j<m; ++j) {
                int tmp;
                cin >> tmp;
                v[j].num += tmp;
            }
        }
        sort(v.begin(), v.end(), comp);
        vector<int> ret;
        int tmp = v[0].num;
        int no = 0;
        vector<int> tv;
        tv.push_back(v[0].id);
        while(true) {
            while(++no < v.size() && v[no].num == tmp) {
                tv.push_back(v[no].id);
            }
            sort(tv.begin(), tv.end());
            for(int j=0; j<tv.size(); ++j) {
                ret.push_back(tv[j]);
            }
            if(no == v.size()) break;
            tmp = v[no].num;
            tv.clear();
            tv.push_back(v[no].id);
        }
        for(int i=0; i<ret.size()-1; ++i) cout << ret[i] << " ";
        cout << ret[ret.size()-1] << endl;
    }
}

Measured memory_bytes: 1220
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


const int dx[2] = {0, -1};
const int dy[2] = {-1, 0};

const int MOD = 1e9+7;

int H, W;
vector<string> a;
vector<vector<long long>> dp;
vector<vector<bool>> flag;


long long rec(int x, int y) {
    if (a[x][y] == '#') return 0;
    if (flag[x][y]) return dp[x][y];
    flag[x][y] = true;

    for (int i = 0; i < 2; i++) {
        int nx = x + dx[i], ny = y + dy[i];
        if (0 <= nx && nx < H && 0 <= ny && ny < W) {
            if (a[nx][ny] == '.') {
                dp[x][y] += rec(nx, ny);
                dp[x][y] %= MOD;
            }
            
        }
    }

    return dp[x][y];
}


void solve() {
    cin >> H >> W;
    a.resize(H);
    for (int i = 0; i < H; i++) cin >> a[i];

    dp.resize(H, vector<long long>(W));
    flag.resize(H, vector<bool>(W));
    dp[0][0] = 1;

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            rec(i, j);
        }
    }

    cout << dp[H-1][W-1] << endl;
}


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

Measured memory_bytes: 13496
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    char c;
    REP(i, 3) {
        REP(j, 3) {
            cin >> c;
            if (i == j) cout << c;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict


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


def main():
    N = int(input())
    W = list(map(int, input().split()))
    g = sum(W)
    ans = 10**6
    for i in range(1,N):
        t = abs(g-2*sum(W[:i]))
        ans = min(ans,t)

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9240
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int H, W;
    cin >> H >> W;
    array<array<int, 10>, 10> C;
    for (auto &c: C)
        copy_n(istream_iterator<int>(cin), 10, c.begin());
    array<int, 10> cnt = {};
    for (int h = 0; h < H; h++){
        for (int w = 0; w < W; w++){
            int a;
            cin >> a;
            if (a == -1)
                continue;
            cnt[a]++;
        }
    }
    
    for (int k = 0; k < 10; k++){
        for (int i = 0; i < 10; i++){
            for (int j = 0; j < 10; j++){
                C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i <= 9; i++)
        ans += C[i][1] * cnt[i];
    cout << ans << endl;
}


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, Q;
    cin >> N >> M >> Q;
    vector<vector<ll>> trainLR(N + 1, vector<ll>(N + 1, 0));
    for (int i = 0; i < M; i++)
    {
        ll left, right;
        cin >> left >> right;
        trainLR.at(left).at(right)++;
    }
    vector<vector<ll>> ruisekiTrainLR(N + 1, vector<ll>(N + 1, 0)); //Lを固定した場合のRの累積
    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= N; j++)
        {
            ruisekiTrainLR.at(i).at(j) = ruisekiTrainLR.at(i).at(j - 1) + trainLR.at(i).at(j);
        }
    }
    for(int i = 0; i < Q; i++)
    {
        ll qLeft, qRight;
        cin >> qLeft >> qRight;
        ll answer = 0;
        for(int j = qLeft; j <= qRight; j++)
        {
            answer += ruisekiTrainLR.at(j).at(qRight) - ruisekiTrainLR.at(j).at(j - 1);
        }
        cout << answer << "\n";
    }
    cout.flush();
    return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

int N;
char c[100];

int main() {
	while (cin >> N, N) {
		REP(i, N) scanf(" %c", c + i), c[i] -= 'A';
		
		int scr[26] = {}, tmp[26] = {};
		int ans = -1, p = -1;
		REP(i, N) {
			scr[c[i]]++;
			REP(j, 26) tmp[j] = scr[j];
			sort(tmp, tmp + 26, greater<int>());
			int dif = N - i - 1;
			if (tmp[0] > tmp[1] + dif) {
				ans = i + 1;
				p = max_element(scr, scr + 26) - scr;
				break;
			}
		}
		
		if (debug) printf("@ ");
		if (ans == -1) puts("TIE");
		else printf("%c %d\n", p + 'A', ans);
	}
	return 0;
}


Measured memory_bytes: 3144
use proconio::fastout;
use proconio::input;

#[fastout]
fn main() {
    input! {
        n: usize,
        a_s: [usize; n-1],
    }
    let a_s: Vec<_> = a_s.iter().map(|i| i - 1).collect();
    let mut cnt = vec![0; n];

    for a in &a_s {
        cnt[*a] += 1
    }

    for c in &cnt {
        println!("{}", c);
    }
}


Measured memory_bytes: 7084
# A - Fifty-Fifty

def main():
	S = input()
	isFF = checkFF(S)
	if isFF:
		print('Yes')
	else:
		print('No')

def checkFF(s):
	if len(s) != 4:
		return False
	if (s[0] == s[1]) and (s[2] == s[3]) and (s[0] != s[2]): 
		return True
	elif (s[0] == s[2]) and (s[1] == s[3]) and (s[0] != s[1]):
		return True
	elif (s[0] == s[3]) and (s[1] == s[2]) and (s[0] != s[1]):
		return True
	else:
		return False

main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#define LIM 1000007
#define ll long long
using namespace std;
int main() {
  map<ll, ll> mp;
  vector<ll> v;
  ll n, m, a, b;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    mp[i + 1] = a;
  }
  cin >> m;
  for (ll i = 0; i < m; i++) {
    cin >> a >> b;
    ll cnt = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++) {
      if (itr->first == a) {
        cnt += b;
      } else {
        cnt += itr->second;
      }
    }
    v.push_back(cnt);
  }
  for (auto vv : v) {
    cout << vv << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e9) + 1;
const int mod = 479001599;
const int maxn = 3e6 + 111;
        
using namespace std;          

int n, m, x;

void solve(){
	cin >> n >> m;

   	for (int i = 1; i <= m; i++){
   		cin >> x;
   		n -= x;
   	}

   	if (n < 0)
   		cout << -1;
   	else
   		cout << n;
}                              
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 3652
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = 6;//dice face
        int[] a = new int[n];
        
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        
        Dice dice = new Dice(a);
        
        String order = sc.next();
        
        for(int i = 0; i < order.length(); i++){
            char c = order.charAt(i);
            switch(c){
                case 'S':
                    dice.turnS();
                    break;
                case 'N':
                    dice.turnN();
                    break;
                case 'W':
                    dice.turnW();
                    break;
                case 'E':
                    dice.turnE();
                    break;
            }
        }
        
        System.out.println(dice.top);
    }
}

class Dice{
    int top, front, right, left, back, bottom;

    Dice(int[] a){
        this.top = a[0];
        this.front = a[1];
        this.right = a[2];
        this.left = a[3];
        this.back = a[4];
        this.bottom = a[5];
    }
    
     void turnS(){
        int tmp = this.top;
        this.top = this.back;
        this.back = this.bottom;
        this.bottom = this.front;
        this.front = tmp;
    }

    void turnN(){
        int tmp = this.top;
        this.top = this.front;
        this.front = this.bottom;
        this.bottom = this.back;
        this.back = tmp;
    }

    void turnW(){
        int tmp = this.top;
        this.top = this.right;
        this.right = this.bottom;
        this.bottom = this.left;
        this.left = tmp;
    }

    void turnE(){
        int tmp = this.top;
        this.top = this.left;
        this.left = this.bottom;
        this.bottom = this.right;
        this.right = tmp;
    }
}


Measured memory_bytes: 26424
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

// サイズ付きUnionFind
struct UnionFind {
	vector<int> data;
	/* constructor */
	UnionFind(int sz) { data.assign(sz, -1); }
	/* merge the set to which x belongs and the set to which y belongs */
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	/* find the root of k */
	int find(int k) {
		if (data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
	/* calculate the size of the set to which k belongs */
	int size(int k) { return -data[find(k)]; }
};

int main() {
	int N, M; cin >> N >> M;
	if (M == N - 1) {
		cout << 0 << endl;
		return 0;
	}
	if (N < 2 * (N - 1 - M)) {
		cout << "Impossible" << endl;
		return 0;
	}
	vector<int> a(N);
	for (int i = 0; i < N; ++i)
		cin >> a[i];
	// 現在の連結成分をUnionFindで管理
	UnionFind uf(N);
	for (int i = 0; i < M; ++i) {
		int x, y; cin >> x >> y;
		uf.unite(x, y);
	}
	// 連結成分の個数を求める
	set<int> id;
	for (int i = 0; i < N; ++i)
		id.insert(uf.find(i));
	int sz = id.size();
	// 連結成分ごとに、aiをまとめる
	map<int, vector<int>> id_a;
	for (int i = 0; i < N; ++i)
		id_a[uf.find(i)].push_back(a[i]);
	for (auto& e : id_a)
		sort(e.second.begin(), e.second.end());
	// 各連結成分のaが最小の頂点をselect
	ll res = 0;
	for (auto& e : id_a)
		res += e.second[0];
	// 残りの頂点から2 * (sz - 1) - sz個の頂点を決定する
	vector<int> left;
	for (auto& e : id_a)
		for (int i = 1; i < e.second.size(); ++i)
			left.push_back(e.second[i]);
	sort(left.begin(), left.end());
	for (int i = 0; i < 2 * (sz - 1) - sz; ++i)
		res += left[i];
	cout << res << endl;
}

Measured memory_bytes: 9344
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

array<string, 4> keywords = {"maerd", "remaerd", "esare", "resare"};

bool Solve(const string& S)
{
    string s = S;
    while (!s.empty())
    {
        bool match = false;
        for (const auto& keyword : keywords)
        {
            if (s.find(keyword) == 0)
            {
                s = s.substr(keyword.length());
                match = true;
                break;
            }
        }

        if (!match)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    cout << (Solve(S) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iterator>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define FI first
#define SE second
#define SI size()
#define VE vector<int>
#define MA(i,j) make_pair(i,j)
#define PA pair<int,int>
#define PB push_back
#define LL long long
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
string S;
int al[26];
int main(){
  cin>>S;
  char C='a';
  FOR(i,0,(int)S.SI){
    al[S[i]-C]++;
  }
  int ans=INF;
  FOR(i,0,26){
    if(al[i]==0){
      continue;
    }
    int M=0;
    int cnt=0;
    FOR(j,0,(int)S.SI){
      if(S[j]==C+i){
        M=max(M,cnt);
        cnt=0;
      }else if(j==(int)S.SI-1){
        M=max(M,cnt+1);
        cnt=0;
      }else{
        cnt++;
      }
    }
    ans=min(ans,M);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int H,W;
  int i,j;

  while(1){
    scanf("%d %d",&H,&W);
    if( H==0 && W==0 ) break;
    for(i=0;i<H;i++){
      for(j=0;j<W;j++){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
long long a[20001],n,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n-2;i++)
		for(int j=i+1;j<=n-1;j++)
		{
			int k=j+1;
			while(a[k]<a[i]+a[j]&&k<=n)
			{
				k++;
				ans++;
			}
		}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1e9;
int MOD = 1e9+7;
main(){
    int N,l,r,cnt = 0;
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> l >> r;
        cnt += r-l+1;
    }
    cout << cnt << endl;
}

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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

bool check(string &s, string &t) {
    unsigned int pos = 0;
    REP (i, 0, s.size()) {
        if (s[i] == t[pos]) pos++;
        if (pos == t.size()) return true;
    }
    return false;
}

int main () {
    string S, T;
    cin >> S >> T;
    string subS[2] = {"", ""};
    REP (i, 0, S.size()) {
        subS[i % 2] += S[i];
    }
    cout << (check(T, subS[0]) || check(T, subS[1]) ? "Yes" : "No") << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  int sum;
  int t = n;
  while(t > 0){
    sum += t % 10;
    t /= 10;
  }
  if(n % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
N, K = map(int, input().split())
S = input()
assert len(S) == N
first = S[0]
target = "R" if first == "L" else "L"


def count_unhappy():
    tcnt = 0
    consecutive = False
    for c in S:
        if c == target:
            consecutive = True
        elif consecutive:
            tcnt += 1
            consecutive = False
    if consecutive:
        tcnt += 1
    unhappy = 2 * tcnt + (0 if S[-1] == target else 1)
    return max(unhappy - 2 * K, 1)


print(N - count_unhappy())


Measured memory_bytes: 3316
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  int n;cin>>n;
  string s,t;cin>>s>>t;
  for(int i = 0; n > i; i++){
    cout << s[i] << t[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n, m;
    cin >> n >> m;

    vvl v(m+1);  // v[i] : xの中でmで割った余りがiのものの集合
    rep(i, n) {
        ll x;
        cin >> x;
        v[x%m].pb(x);
    }

    exrep(i, 0, m/2) {
        if(v[i].size() < v[m-i].size()) {
            swap(v[i], v[m-i]);
        }
    }

    ll ans = v[0].size()/2;
    exrep(i, 1, m/2) {
        if(m%2 == 0 && i == m/2) {
            ans += v[m/2].size()/2;
            break;
        }
        ll S = v[i].size();
        ll T = v[m-i].size();
        ll U = S - T;
        ans += T;
        map<ll, ll> mp;
        for(auto p : v[i]) {
            mp[p]++;
        }
        ll cnt = 0;
        for(auto p : mp) {
            ll nokori = U - 2*cnt;
            if(p.second <= nokori) {
                cnt += p.second/2;
            }
            else {
                cnt += nokori/2;
            }
        }
        ans += cnt;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 5760
N = int(input())
A = list(map(int, input().split()))

s = sum(A)

oe = s % 2
h = s // 2

p = 0
p0 = None
p1 = None
for i in A:
    p += i
    if p == h:
        if oe == 0:
            print(0)
            exit()
        print(1)
        exit()
    if p > h:
        p1 = p
        break
    p0 = p

if oe == 1:
    h += 1

p = p0 if p1 == s or abs(p0 - h) < abs(p1 - h) else p1

print(abs(p*2 - s))

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

int main(){
  ll a,b,v,w,t;
  cin>>a>>v>>b>>w>>t;
  if(v<=w){cout<<"NO"<<endl;return 0;}
  cout<<(abs(b-a)<=(v-w)*t ? "YES" : "NO")<<endl;
}


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

int N, K;
int h[100005];
int dp[100005];

void solve() {
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	for (int i = 2; i < N; ++i) {
		dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
		for (int j = 2; i - j >= 0 && j <= K; ++j) {
			dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
		}
	}
}

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; ++i)
		cin >> h[i];
	solve();
	cout << dp[N - 1];
	return 0;
}

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

typedef long long i64;

int D, n;
i64 p10[20], w[20];

//1000000000

i64 dfs(int i, i64 D) {
	//printf("%d %lld %lld\n", i, D, w[i]);
	if (abs(D) > 10 * w[i]) return 0;
	if (i * 2 > n) {
	//	printf("%lld %lld\n", w[i], D);
		
		if (D != 0) return 0;
		else if (i * 2 == n + 1) return 10;
		else return 1;
	}
	i64 ans = 0;
	for (int d = -9; d <= 9; ++d) {
		int l = i == 1 ? 1 : 0, r = 9;
		l = max(l, -d), r = min(r, 9 - d);
		if (l > r) continue;
		//if (n == 2 && i == 1 && d == 7) printf("%d %d\n", l, r);
		ans += (r - l + 1) * dfs(i + 1, D - d * w[i]);
	}
	return ans;
}

int main() {
	scanf("%d", &D);
	i64 ans = 0;
	p10[0] = 1;
	for (int i = 1; i <= 18; ++i)
		p10[i] = p10[i - 1] * 10;
	for (int i = 2; i <= 18; ++i) {
		n = i;
		for (int k = 1; k <= n / 2; ++k) w[k] = p10[n - k] - p10[k - 1];//, printf("%lld ", w[k]);
		//puts("");
		ans += dfs(1, D);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main()
{
    int N;
    cin >> N;
    int ac = 0, wa = 0, tle = 0, re = 0;
    for (int i = 0; i < N; ++i)
    {
        string str;
        cin >> str;
        if (str == "AC") ++ac;
        else if (str == "WA") ++wa;
        else if (str == "TLE") ++tle;
        else ++re;
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i = 0; i < N; i++) {
    cin >> L[i];
  }
  
  int ans = 0;
  sort(L.begin(), L.end());
  for(int i = 0; i < N; i++) {
    for(int j = i+1; j < N; j++) {
      for(int k = j+1; k < N; k++) {
        if(L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
          if(L[i] < L[j] + L[k] 
            && L[j] < L[i] + L[k]
            && L[k] < L[j] + L[i]) {
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

map<int, int> fr;

void win(bool w) { printf("%s\n", w ? "Yes" : "No"); exit(0); }

int main(){
	int n;
	scanf("%d", &n);
	int z = 0;
	f(i, 0, n){
		int t;
		scanf("%d", &t);
		++fr[t];
		z ^= t;
	}
	if (z)win(false);
	if (fr.find(0) != fr.end() && fr[0] == n)win(true);
	if (n % 3 != 0)win(false);
	vector<int> v;
	for (auto it = fr.begin(); it != fr.end(); ++it)v.push_back(it->second);
	if (v.size() > 3 || v.size() == 1)win(false);
	sort(v.begin(), v.end());
	if (v.size() == 3 && v[0] == v[2])win(true);
	if (v.size() == 2 && v[0] * 2 == v[1])win(true);
	win(false);
}

Measured memory_bytes: 3840
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
//#include <stdio.h>
//#include <stack>
//#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <fstream>
//#include <list>
//#include <iomanip>
#include <stdlib.h>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(),z.end())
#define rsort(z) sort(z.rbegin(),z.rend())
#define eerase(z) z.erase(unique(z.begin(),z.end()),z.end())
#define ccnt(z,w) count(z.begin(),z.end(),w)


void printVec(std::vector<int> & vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec2(std::vector<Int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a / gcd(a, b) *b;
	//a*bは64bit integer overflow
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str = "";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}
Int fact(int num) {
	if (num == 0) return 1;
	else return num * fact(num - 1);
}



int main() {
	//int a, b, c,d; cin >> a>>b>>c>>d ;
	string s,t; cin >> s;
	if (s == "a" || s == "i" || s == "u" || s == "e" || s == "o")cout << "vowel";
	else cout << "consonant";

	cout << endl;
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(3e5) + 5;
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir = "RDLU";
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v), end())
#define SORTR(v) sort((v).rbegin(), (v), rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    string s, t, ans = "Yes";
    set<char> st[2][26];
    cin >> s >> t;
    REP(i,s.size()){
        st[0][s[i]-'a'].insert(t[i]);
    }
    REP(i,s.size()){
        st[1][t[i]-'a'].insert(s[i]);
    }
    REP(i,26)if(st[0][i].size()>1 || st[1][i].size()>1)ans = "No";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 776
fun main(args : Array<String>) {
    val (n, k, s) = readLine()!!.split(" ").map { it.toInt() }
    val ans = mutableListOf<Int>()

    if (k == 0) {
        repeat(n) {
            if (s + 1 > 1000000000) {
                ans.add(s-1)
            } else {
                ans.add(s+1)
            }
        }
        println(ans.joinToString(separator = " "))
        return
    }

    repeat(k) {
        ans.add(s)
    }
    repeat(n-k) {
        if (s + 1 > 1000000000) {
            ans.add(s-1)
        } else {
            ans.add(s+1)
        }
    }
    println(ans.joinToString(separator = " "))
}

Measured memory_bytes: 44724
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	while(1){
	  int h,w; cin >> h >>w;
	  if(h==0 && w==0)break;
	  for(int i=0;i<h;i++){
		  for(int j=0;j<w;j++){
			  cout << "#";
		  }
		  cout << endl;
	  }
	  cout << endl;
	}
}



Measured memory_bytes: 3072
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int k,t;
  cin>>k>>t;
  vi a(t);
  rep(i,t)cin>>a[i];
  sort(all(a));
  int x=a[t-1];
  int y=k-x;
  cout<<max(0,x-y-1)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
#define MAXH 101
#define MAXW 101
#define INF 1000
#define MAXN 200002

int X, Y, N;
int A[MAXN];

int main(){
    cin >> N >> X >> Y;
    X--;Y--;

    vector<int> ds(N + 1);

    for(int i = 0;i < N;i++){
        for(int j = i + 1;j < N;j++){
            ds[min(j - i, abs(i - X) + abs(j - Y) + 1)]++;
        }
    }

    for(int k = 1;k < N;k++){
        printf("%d\n", ds[k]);
    }


    return 0;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define pli pair<ll, ll> 
#define pdd pair<ld, ld> 
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;

int main(){
	FASTIO
	ll n;
	cin >> n;
	vector<ll> v(n+1, 0);
	for(ll x = 1; x * x <= n; x++){
		for(ll y = 1; y * y <= n; y++) {
			for(ll z = 1; z * z <= n; z++){
				ll t = x*x + y*y + z*z + x*y + y*z + z*x;
				if(t <= n)
					v[t]++;
			}
		}
	}
		rep(i, 1, n + 1)
			cout << v[i] << "\n";
	
    return 0;
}

Measured memory_bytes: 3648
import java.io.BufferedReader; 
import java.io.*;
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
import java.util.*;
import java.math.*;
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader()
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next()
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine();
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
   public static void main(String args[])
    {
        FastReader sc=new FastReader();
        PrintWriter pw=new PrintWriter(System.out);
        int t=1;//sc.nextInt();
        while(t-->0)
        {
           int n=sc.nextInt(),f=0,a[]=new int[n];
           for(int i=0;i<n;i++)
           {
             a[i]=sc.nextInt();
           }int ans[]=new int[n],p=0,q=n-1;
           for(int i=n-1;i>=0;i-=2)
           {
             ans[p++]=a[i];
             if(i-1>=0)
             ans[q--]=a[i-1];
           }
           for(int w:ans)
           pw.print(w+" ");
           pw.println();
        }
           pw.close();
    }
}
  

Measured memory_bytes: 59548
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
using namespace std;
int N, M;
map<string, int> mp;
vector<string> vs;
int main(){
	cin >> N;
	for (int i = 0; i < N; ++i) {
		string str; cin >> str;
		auto itr = mp.find(str);
		if (itr != mp.end()) {
			mp[str]++;
		}
		else {
			mp[str] = 1;
			vs.push_back(str);
		}
	}
	cin >> M;
	for (int i = 0; i < M; ++i) {
		string str; cin >> str;
		auto itr = mp.find(str);
		if (itr != mp.end()) {
			mp[str]--;
		}
		else {
			mp[str] = -1;
			vs.push_back(str);
		}
	}
	int maxV = -100000;
	for (int i = 0; i < vs.size(); ++i) {
		maxV = max(maxV, mp[vs[i]]);
	}
	if (maxV < 0) maxV = 0;
	cout << maxV << endl;
	return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  s.erase(unique(s.begin(), s.end()), s.end());
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,e)for(int i=0;i<e;i++)
#define PI acos(-1)
using namespace std;

int main(){
    int i, j;
    int n;
    while(1){
        cin >> n;
        if(n==0)break;
        int s[n];
        rep(i,n) cin >> s[i];
        double m=0;
        rep(i,n) m += s[i];
        m = m / n;
        double sig=0;
        rep(i,n) sig += pow(s[i]-m,2);
        sig = sig / n;
        printf("%.8f\n", sqrt(sig));
    }
    return 0;
}


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

class UnionFind {
  vector<int> info;
  // 親、もしくは根の場合はそのsize*-1
  int num_group;

public:
  UnionFind(int n) {
    info.assign(n, -1);
    num_group = n;
  }

  int find_root(int x) {
    return info[x] < 0 ? x : info[x] = find_root(info[x]);
  }

  inline void unite(int x, int y) {
    // union-by-size
    int rx = find_root(x);
    int ry = find_root(y);
    if (rx == ry)
      return;
    if (info[rx] > info[ry])
      swap(rx, ry);
    info[rx] += info[ry];
    info[ry] = rx;
    num_group--;
  }

  bool is_same_group(int x, int y) { return find_root(x) == find_root(y); }

  int get_group_size(int x) { return -info[find_root(x)]; }

  int get_num_of_groups() { return num_group; }
};

int main() {
  int n, m;
  cin >> n >> m;
  auto uf = UnionFind(n);
  int x, y, z;
  for (int i = 0; i < m; i++) {
    cin >> x >> y >> z;
    x--;
    y--;
    uf.unite(x, y);
  }
  cout << uf.get_num_of_groups() << endl;
}


Measured memory_bytes: 640
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

bool isCommonDivisor(const uint64_t candidate, const uint64_t N, uint64_t P) {
	for (uint64_t count = 0; count < N; count++) {
		if (P < candidate || P % candidate != 0) {
			return false;
		}

		P /= candidate;
	}

	return true;
}

int main(void) {
	uint64_t N, P;

	scanf("%"PRIu64" %"PRIu64, &N, &P);

	uint64_t commonDivisor = 1;
	if (1 < N) {
		const uint64_t maxCandidate = (uint64_t)sqrt((double)P);

		for (uint64_t candidate = 2; candidate <= maxCandidate; candidate++) {
			if (isCommonDivisor(candidate, N, P)) {
				commonDivisor = candidate;
			}
		}
	}
	else {
		commonDivisor = P;
	}

	printf("%"PRIu64, commonDivisor);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pull = pair<ull, ll>;
using pis = pair<int, string>;
#define all(x) (x).begin(), (x).end()
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 998244353ll

struct BIT {
  ll n;
  vector<ll> bit;
  BIT(ll n, ll init=0): n(n), bit(n+1, init) {}

  //functions
  //OPERATION: ADD
  
  //i番目（0-indexed) にaを加算する
  void add(ll i, ll a) {
    i++;
    for (int j = i; j <= n; j += (j & -j)) bit[j] += a;
    return;
  }

  //区間和: [a, b)の区間和
  ll sum(ll a, ll b) {
    if (a == 0) {
      ll ans = 0;
      for (int i = b; i > 0; i -= (i & -i)) ans += bit[i];
      return ans;
    }
    else {
      return sum(0, b) - sum(0, a);
    }   
  }
};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(15)
  ll n, k;
  cin >> n >> k;
  BIT bit(n+1);
  bit.add(0, 1);
  vector<pll> range(k);
  for (int i = 0; i < k; i++) cin >> range[i].first >> range[i].second;
  for (ll i = 1; i <= n; i++) {
    ll temp = 0;
    for (int j = 0; j < k; j++) {
      ll left = max(0LL, i - range[j].second), right = max(0LL, i - range[j].first + 1);
      temp += bit.sum(left, right);
      temp %= MOD;
    }
    bit.add(i, temp);
  }
  cout << bit.sum(n-1, n) << endl;

  //for (int i = 0; i <= n; i++) cout << bit.sum(i, i+1) << " ";
  //cout << endl;
}



Measured memory_bytes: 4704