akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string> 
#include <array>
using std::cin; using std::cout;
using std::max; using std::min;
using std::vector; using std::string;
using ll=long long;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
template<class T, class U> bool ckmin(T &a, U b){return (a>b? a=b, true : false);}
template<class T, class U> bool ckmax(T &a, U b){return (a<b? a=b, true: false);}
int main(){
    ll a, b;
    cin>>a>>b;
    if(a<=5){
        cout<<"0\n";
    }
    else if(a>=6 and a<=12){
        cout<<b/2<<"\n";
    }
    else{
        cout<<b<<"\n";
    }
}




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

map<int,int>m;
vector<int>v;

int main()
{
	int n,i,x,ans=0;
	cin >>n;
	
	for (i=1;i<=n;i++)
	{
		cin>>x;
		if(m[x]==0) v.push_back(x);
		m[x]++;
	}
	
	for (i=0;i<v.size();i++)
		if (v[i]>m[v[i]])
			ans+=m[v[i]];
		else if (v[i]<m[v[i]])
			ans+=m[v[i]]-v[i];
			
	cout<<ans;
}

Measured memory_bytes: 5112
#include <stdio.h>

int main(void){
 int a,b,n,max,min, ret = 3;
  ret = scanf("%d %d %d",&n,&a,&b);
  while(ret == 3){
    max=(a>b?b:a);
    if(a+b > n){
        min=a+b-n;
    }else{
        min=0;
    }
    printf("%d %d\n",max,min);
    fprintf(stderr, "%d %d %d\n",n,a,b);
	ret = scanf("%d %d %d",&n,&a,&b);
  }
  return 0;
}


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


int main(void){
  int h,n,i,a,asum=0;
  
  cin >> h >> n;
  for (i=0;i<n;i++){
    cin >> a;
    asum+=a;
  }
  
  if (asum>=h) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

const int MAXN = 1e5+2;

char s[MAXN], t[MAXN];
int len = 0;
vector<int> pos[26];

int main() {
	scanf("%s%s", s, t);
	for (len=0; s[len]!='\0'; ++len) {
		pos[s[len]-'a'].push_back(len);
	}

	int now = 0;
	long long ans = 0;
	for (int i=0; t[i]!='\0'; ++i) {
		auto &p = pos[t[i]-'a'];
		if (p.size() == 0) {
			printf("-1\n");
			return 0;
		}
		int j = lower_bound(p.begin(), p.end(), now) - p.begin();
		if (j == p.size()) {
			ans += len;
			j = 0;
		}
		now = p[j]+1;
	}

	printf("%lld\n", ans + now);

	return 0;
}



Measured memory_bytes: 1024
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


int main(){
      ll n;
      cin>>n;
      vector<ll> a(60);
      rep1(i,n) cin>>a[i];
      ll max_a=0;
      ll index_max_a=0;
      ll min_a=0;
      ll index_min_a=0;
      rep1(i,n){
            if(a[i]>max_a){
                  max_a=a[i];
                  index_max_a=i;
            }
            if(a[i]<min_a){
                  min_a=a[i];
                  index_min_a=i;
            }
      }
      vector<P> sousa;
      if(max_a>-min_a){
            for(int i=1;i<n;i++){
                  while(a[i]>a[i+1]){
                        a[i+1]+=max_a;
                        P p=make_pair(index_max_a,i+1);
                        sousa.push_back(p);
                        if(a[i+1]>max_a){
                              index_max_a=i+1;
                              max_a=a[i+1];
                        }
                  }
            }
      }
      else{
            for(int i=n;i>1;i--){
                  int cnt=0;
                  while(a[i-1]>a[i]){
                        a[i-1]+=min_a;
                        P p=make_pair(index_min_a,i-1);
                        sousa.push_back(p);
                        if(a[i-1]<min_a){
                              index_min_a=i-1;
                              min_a=a[i-1];
                        }
                        //cout<<i<<endl;
                        //cnt++;
                        //if(cnt>10){
                              //cout<<a[i-1]<<endl;
                              //break;
                        //} 
                  }
            }
      }
      //rep1(i,n) cout<<a[i]<<" ";
      //cout<<endl;
      cout<<sousa.size()<<endl;
      for(auto p:sousa){
            cout<<p.first<<" "<<p.second<<endl;
      }

      return 0;
}


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

int main()
{
    int na, nb, m, mina = (1 << 30), minb = (1 << 30), x, y, c;
    cin >> na >> nb >> m;
    vector<int> a(na), b(nb);
    for (int i = 0; i < na; ++i)
    {
        cin >> a[i];
        mina = (min)(mina, a[i]);
    }
    for (int i = 0; i < nb; ++i)
    {
        cin >> b[i];
        minb = (min)(minb, b[i]);
    }
    int ans = mina + minb;
    for (int i = 0; i < m; ++i)
    {
        cin >> x >> y >> c;
        --x, --y;
        int value = a[x] + b[y] - c;
        ans = (min)(ans, value);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    long long n, m;
    cin >> n >> m;

    vector<vector<long long> > s(m);
  
    for(long long i = 0; i < m; i++){
        long long k;
        cin >> k;
        
        for(long long j = 0; j < k; j++){
            long long a;
            cin >> a;
            s[i].push_back(a-1);
        }
    }

    vector<long long> p(m);

    for(long long i = 0; i < m; i++){
        cin >> p[i];
    }

    long long count = 0;
    for(long long bit = 0; bit < (1 << n); bit++){

        bool light = true;
        for(long long i = 0; i < m; i++){
            long long count_on = 0;

            for(long long j = 0; j < n; j++){
                if(find(s[i].begin(), s[i].end(), j) == s[i].end()){
                    continue;
                }

                if(bit & (1 << j)){
                    
                    count_on++;
                }
            }
            //printf("i %lld count_on %lld\n", i, count_on);
            //printf("bit %lld count_on %lld p[%lld] %lld\n", bit, count_on, i, p[i]);
            if(count_on % 2 != p[i]){
                light = false;
                //break;
            }
        }

        if(light == true){
            count++;
        }

    }

    cout << count << endl;

    return 0;

}

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

const int N=200005;

int n,k,a[N],s[N],mn[N],mx[N],pre[N];

int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int h=1,t=0;
	for (int i=1;i<=n;i++)
	{
		while (h<=t&&a[s[t]]>a[i]) t--;
		if (h<=t&&i-s[h]>=k) h++;
		s[++t]=i;
		mn[i]=s[h];
	}
	h=1,t=0;
	for (int i=1;i<=n;i++)
	{
		while (h<=t&&a[s[t]]<a[i]) t--;
		if (h<=t&&i-s[h]>=k) h++;
		s[++t]=i;
		mx[i]=s[h];
	}
	for (int i=1;i<n;i++) pre[i]=pre[i-1]+(a[i]<a[i+1]);
	int ans=n-k+1;
	bool flag=0;
	for (int i=1;i+k-1<=n;i++)
	{
		if (pre[i+k-2]-pre[i-1]==k-1) ans+=flag^1,flag=1;
		if (pre[i+k-2]-pre[i-1]==k-1||i>1&&mn[i+k-2]==i-1&&mx[i+k-1]==i+k-1) ans--;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <deque>

std::map<long long, int > mp;
long long N;

int digit(long long value){
  int ans = 0;
  while(value!=0){
    value = value / 10;
    ans++;
  }
  return ans;
}

int dfs(std::map<long long, int>::iterator itr, long long value){
  //std::cout << itr << std::endl;
  if (itr==mp.end()){
    //if ((itr==mp.end())){
    //printf("value=%lld, ret=%d\n", value, std::max(digit(value), digit(N/value)));
    return std::max(digit(value), digit(N/value));
  } else {
    int ans = 1e8;
    auto itr2 = itr;
    itr2++;
    //std::cout << itr->first << "," << itr->second << std::endl;
    for (int i=0; i<=itr->second; i++){
      ans = std::min(ans, dfs(itr2, value*pow(itr->first, i)));
      //printf("ans%d=%d\n",i,ans);
    }
    return ans;
  }
}

int main(){
  scanf("%lld", &N);
  long long N2 = N;
  for (long long i=2; i*i<=N2; i++){
    while (N2%i==0){
      mp[i]++;
      N2 = N2/i;
    }
  }
  if (N2!=1){
    mp[N2]++;
  }
  /*auto itr_begin = mp.begin();
  auto itr_end = mp.end();
  //std::cout << "begin="<<&itr_begin << ", end=" << &itr_end << std::endl;
  itr_begin++;
  //std::cout << "begin="<<&itr_begin << ", end=" << &itr_end << std::endl;
  for (auto &entry:mp){
    std::cout << &entry << std::endl;
    }*/
  int ans = dfs(mp.begin(), 1);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
using namespace std;

int main(){
    int N, T, A;
    cin >> N >> T >> A;
    int height[N];
    int temp[N];
    int ans;
    A *= 1000;
    for(int i = 0; i < N; i++){
        cin >> height[i];
        temp[i] = 1000*T - 6 * height[i];
    }
    int dif = 100000000;
    for(int i = 0; i < N; i++){
        if(dif > abs(temp[i] - A)){
            ans = i+1;
            dif = abs(temp[i] - A);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s_input = sorted([int(input()) for i in range(n)])

if all(s%10==0 for s in s_input):
    print(0)

elif sum(s_input)%10==0:
    while sum(s_input)%10==0:
        for i in range(len(s_input)):
            if s_input[i]%10!=0:
                del s_input[i]
                break
    print(sum(s_input))
else:
    print(sum(s_input))






Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	s := make([]pair, n)

	for i := 0; i < n; i++ {
		s[i].f = nextStr()
		s[i].s = nextInt()
		s[i].i = i + 1
	}
	sortPairs(s)
	for _, v := range s {
		fmt.Println(v.i)
	}
}

type pair struct { // f=first, s=second
	f string
	s int
	i int
}

// []pair をf->sの順でソートする
func sortPairs(s []pair) {
	sort.Slice(s, func(i, j int) bool {
		if s[i].f == s[j].f {
			return s[i].s > s[j].s // 点数大きい順
		}
		return s[i].f < s[j].f
	})
	return
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;

const int MAXN = 100 + 5;

string s[MAXN];

bool condition_1(string s[], int n) {
    for (int i = 0; i < n; i++)
        if (i > 0 && s[i][0] != s[i - 1][s[i - 1].size() - 1])
            return false;
    return true;
}

bool condition_2(string s[], int n) {
    sort(s, s + n);
    for (int i = 0; i < n; i++)
        if (i > 0 && s[i] == s[i - 1])
            return false;
    return true;
}

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> s[i];
    if (condition_1(s, n) && condition_2(s, n))
        cout << "Yes";
    else
        cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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

int n,a[100005] = {},b[100005] = {};


int main(){
    
    cin >> n ;

    rep(i,1,n+1)cin >> a[i];

    ll ans = 0;
    rep(i,1,n+2){
        ans += abs(a[i-1] - a[i]);

        b[i] = abs(a[i-1] - a[i+1]) - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]));
    }

    rep(i,1,n+1)P(ans + b[i]);
	return  0;
}


Measured memory_bytes: 2048
import math

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

n,d = map(int,input().split())

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

ans = 0
for i in range(n-1):
  for j in range(i+1,n):
    res = 0
    for k in range(d):
      res += (x[i][k]-x[j][k])**2
    if is_integer_num(math.sqrt(res)):
      ans += 1

print(ans)


Measured memory_bytes: 3064
import java.util.Scanner;

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

	int a = scan.nextInt();
	int b = scan.nextInt();

	if(a % 3 == 0){
	    System.out.println("Possible");
	}else if(b % 3 == 0){
	    System.out.println("Possible");
	}else if((a+b) % 3 == 0){
	    System.out.println("Possible");
	}else{
	    System.out.println("Impossible");
	}
    }
}
		


Measured memory_bytes: 23124
#include<stdio.h>


main()
{
	float a,b,c,d,e,f;
	float x,y;
	x=0;
	y=0;
	
	while(scanf("%f %f %f %f %f %f",&a,&b,&c,&d,&e,&f)!=EOF){
	
	x=(float)(c*e-b*f)/(a*e-b*d);
	y=(float)(c*d-a*f)/(b*d-a*e);
	
	if(-0.0005<x && x<=0)
      x=0;
    if(-0.0005<y && y<=0)
      y=0;
	
	printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 648
n,m=map(int,input().split())
pos=[]
for _ in range(n):
    x,y=map(int,input().split())
    pos.append((x,y))
dist=[10**9]*n
ans=[0]*n
for goal in range(m):
    p,q=map(int,input().split())
    for i in range(n):
        x,y=pos[i]
        d=abs(x-p)+abs(y-q)
        if d<dist[i]:
            dist[i]=d
            ans[i]=goal+1

for i in ans:
    print(i)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=1000;
static const int NMAX=50;
static const int MMAX=50;
int N;

bool f[MAX+1];//篩　iが素数ならf[i]はfalse i
void prime(){
    for(int i=2;i<=MAX;i++){
        if(f[i])continue;
        for(int j=i*2;j<=MAX;j+=i) f[j]=true;
    }
}


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

    ll ans=1;
    for(int i=2;i<=N;i++){
        int cunt=0;
        if(f[i])continue;
        
        int x=i;
        while(x<=N){
            cunt+=N/x;
            x*=i;
        }
        ans=ans*(cunt+1)%(int)(1e9+7);
        
    }
    cout<<ans%(int)(1e9+7)<<"\n";
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (a, b) = Slice2<long>();
            WriteLine((a + b + 1) / 2);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

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

int main(){
  int n,d;
  cin >> n >> d;
  vector<vector<int>> map(n, vector<int>(d));
  for(int i=0; i<n; i++){
    for(int j=0; j<d; j++){
      cin >> map.at(i).at(j);
    }
  }
  int count =0;
  
  for(int i=0; i<n-1; i++){
    for(int j=i+1; j<n; j++){
      int sum=0;
      for(int k=0; k<d; k++){
        sum += pow( map.at(i).at(k) - map.at(j).at(k) , 2);
      }
      float a= sqrt(sum);
      int b = a;
      if(a==b) count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt(), B = sc.nextInt();
		System.out.println(Math.max(A+B, Math.max(A-B, A*B)));
		sc.close();			
	}

	public static void main(String args[]) {
		solve();
	}

}

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

const long long MOD = 1000000007;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(n), t(m);
    for (int i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    for (int i = 0; i < m; i++) {
        cin >> t.at(i);
    }

    vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, 1));   

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s.at(i) == t.at(j)) {
                dp.at(i + 1).at(j + 1) = dp.at(i).at(j + 1) + dp.at(i + 1).at(j);
                dp.at(i + 1).at(j + 1) %= MOD;
            }
            else {
                dp.at(i + 1).at(j + 1) = (dp.at(i).at(j + 1) + dp.at(i + 1).at(j)) % MOD - dp.at(i).at(j);
                dp.at(i + 1).at(j + 1) %= MOD;
                
                if (dp.at(i + 1).at(j + 1) < 0) dp.at(i + 1).at(j + 1) += MOD;
            }
        }
    }   

    cout << dp.at(n).at(m) << endl;
}    

Measured memory_bytes: 31616
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

func stringifyArray(arr []int) string {
	return strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]")
}

func swap(a []int, i, j int) {
	tmp := a[i]
	a[i] = a[j]
	a[j] = tmp
}

func roll(dice []int, cmd string) {
	if cmd == "N" {
		swap(dice, 0, 1)
		swap(dice, 1, 5)
		swap(dice, 5, 4)
	} else if cmd == "W" {
		swap(dice, 0, 2)
		swap(dice, 2, 5)
		swap(dice, 5, 3)
	} else if cmd == "S" {
		swap(dice, 0, 4)
		swap(dice, 4, 5)
		swap(dice, 5, 1)
	} else if cmd == "E" {
		swap(dice, 0, 3)
		swap(dice, 3, 5)
		swap(dice, 5, 2)
	}
}

func fixUpper(dice []int, upper int) {
	for _, cmd := range strings.Split("NWWWN", "") {
		if dice[0] == upper {
			break
		}
		roll(dice, cmd)
	}
}

func fixFront(dice []int, front int) {
	for i := 0; i < 4; i++ {
		if dice[1] == front {
			break
		}
		swap(dice, 1, 2)
		swap(dice, 2, 4)
		swap(dice, 4, 3)
	}
}

func main() {
	scanner.Split(bufio.ScanWords)
	dice1 := make([]int, 6)
	dice2 := make([]int, 6)
	for i := 0; i < 6; i++ {
		dice1[i], _ = nextInt()
	}
	for i := 0; i < 6; i++ {
		dice2[i], _ = nextInt()
	}

	eq := false
	for _, cmd := range strings.Split("NWWWN", "") {
		roll(dice1, cmd)

		upper := dice1[0]
		front := dice1[1]

		fixUpper(dice2, upper)
		fixFront(dice2, front)

		eq = reflect.DeepEqual(dice1, dice2)
		if eq {
			break
		}
		// fmt.Println(dice1, dice2, eq)
	}
	msg := ""
	if eq {
		msg = "Yes"
	} else {
		msg = "No"
	}
	fmt.Println(msg)
}



Measured memory_bytes: 1136
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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; }

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    bool operator==(const mint a){
        return (x == a.x);
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

//nが非常に大きく、aが小さい場合
mint choose(int n, int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int N, K; cin >> N >> K;

    combination c(N+1);
    mint ans = 0;
    auto f2 = [&](ll n, ll k){
        return c(n+k-1, k-1);
    };
    auto f = [&](ll n, ll k){
        if (n < k) return (mint)0;
        if (n == 0 && k == 0) return (mint)1;
        if (k < 1) return (mint)0;
        return f2(n-k, k);
    };
    for(int i = 1; i <= K; i++){
        mint blue = f(K, i);
        mint red = f(N-K, i-1);
        red += f(N-K,i);
        red += f(N-K,i);
        red += f(N-K,i+1);
        mint ans = blue*red;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3668
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int X, A, B;
    std::cin >> X >> A >> B;

    int ans = X - A;
    ans %= B;
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
n, x, y = map(int, input().split())
L=[0]*n

def dist(i, j):
  d1 = abs(i - j)
  d2 = abs(x - i) + 1 + abs(y - j)
  return min(d1, d2)

for i in range(1,n):
	for j in range(i,n+1):
		a= dist(i,j)
		L[a]+=1

for i in range(1,n):
	print(L[i])

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
ll MAX_V = 2e5 + 5;
vector<ll>t(MAX_V);
bool win=false;
ll dfs(ll k,vector<vector<ll>>&g){
  t[k]=1;
  vector<ll>num(2);
  ll ret=1;
  for(ll i=0;i<g[k].size();i++){
    if(t[g[k][i]]==0){
      ll x=dfs(g[k][i],g); 
      num[x%2]++;
      ret+=x;
    }
  }
  if(num[1]>=2)win=true;
  if(k==0&&num[1]==0)win=true;
  //cout<<k spa num[0] spa num[1]<<endl;
  return ret;
}
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<vector<ll>>g(n);
  rep(i,0,n-1){
    ll a,b;cin>>a>>b;a--;b--;
    g[a].PB(b);
    g[b].PB(a);
  }
  dfs(0,g);
  ans(win,"First","Second");
  return 0;
}

Measured memory_bytes: 7936
from collections import defaultdict
N = int(input())
dic = defaultdict(list)
A = []
for i in range(N):
    a = int(input())
    A.append(a)
    for j in range(a):
        x,y = map(int,input().split())
        dic[i].append((x-1,y))
# print(dic)

from itertools import product
P = product(range(2),repeat=N)
# print(list(p))

ans = 0
for p in P:
    flg = True
    for i in range(N):
        if p[i] == 1:
            for xi,yi in dic[i]:
                if p[xi] != yi:
                    flg = False
        if not flg:
            break
    if flg: ans = max(ans, sum(p))
print(ans)

Measured memory_bytes: 3316
n = int(input())
a = list(map(int,input().split()))
a = [0] + a + [0]*n
ans = [0] * (n * 2 + 1)
m = n

for k in range(400):
    if m % 2 == 0:
        m //= 2
        for i in range(m+1,2*m+1):
            al = 0
            for j in range(i,2*n+1,i):
                al += ans[j]
            ans[i] = (a[i] + al) % 2
            
    else:
        m //= 2
        for i in range(m+1,2*m+2):
            al = 0
            for j in range(i,2*n+1,i):
                al += ans[j]
            ans[i] = (a[i] + al) % 2
            
    if m <= 0:
        break
        
ans2 = ans[1:n+1]
q = []
aa = 0
for i in range(n):
    if ans2[i] == 1:
        q.append(i+1)
        aa += 1
        
print(aa)
print(*q)

Measured memory_bytes: 76808
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>

bool isprime(int a) {
	if (a == 1) return false;

	for (int i = 2; i <= sqrt(a) ; i++) {
		if (a % i == 0) return false;
	}

	return true;
}

int main() {
	int n;
	std::vector<int> d;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		int b;
		scanf("%d", &b);
		d.push_back(b);
	}

	printf("%d\n", 
		std::count_if(d.begin(), d.end(),isprime));

	return 0;
}

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

#define ll long long

using namespace std;


int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);
   
   ll N, K; cin >> N >> K;
   
   ll min = abs(N - K);
   N %= K;
   if(N < (K - N)) cout << N;
   else cout << (K - N);

   return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;


int main(){
  IO; int N; ll A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> T(N); FORE(i,T)cin>>i; T.PB("");
  vector<char> ans(N);
  int ok = 1;
  REP(i,N){
    if(T[i]=="AB"){
      if(!A&&!B){
        ok = 0;
        break;
      }
      if(A==1&&B==1){
        if(T[i+1]=="AC")A++,B--,ans[i]='A';
        else A--,B++,ans[i]='B';
      }else{
        if(A<B)A++,B--,ans[i]='A';
        else A--,B++,ans[i]='B';
      }
    }else if(T[i]=="BC"){
      if(!B&&!C){
        ok = 0;
        break;
      }
      if(B==1&&C==1){
        if(T[i+1]=="AB")B++,C--,ans[i]='B';
        else B--,C++,ans[i]='C';
      }else{
        if(B<C)B++,C--,ans[i]='B';
        else B--,C++,ans[i]='C';
      }
    }else{
      if(!A&&!C){
        ok = 0;
        break;
      }
      if(A==1&&C==1){
        if(T[i+1]=="AB")A++,C--,ans[i]='A';
        else A--,C++,ans[i]='C';
      }else{
        if(A<C)A++,C--,ans[i]='A';
        else A--,C++,ans[i]='C';
      }
    }
  }
  if(ok){
    cout<<"Yes"<<endl;
    FORE(i,ans)cout<<i<<endl;
  }else cout<<"No"<<endl;
}


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

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        vector<vector<int>> g(n);
        for(int i = 0; i < m; ++i) {
            int a, b; cin >> a >> b;
            g[a - 1].push_back(b - 1);
            g[b - 1].push_back(a - 1);
        }
        vector<int> col(n, -1), cnt(2);
        function<void(int, int)> coloring =
            [&] (int v, int c) {
                if(col[v] != -1 && col[v] != c) throw runtime_error("");
                if(col[v] != -1) return;
                col[v] = c;
                cnt[c] += 1;
                for(auto to : g[v]) {
                    coloring(to, !c);
                }
            };
        try {
            coloring(0, 0);
        } catch (...) {
            cout << 0 << endl;
            continue;
        }
        set<int> s;
        if(cnt[0] % 2 == 0) s.insert(cnt[0] / 2);
        if(cnt[1] % 2 == 0) s.insert(cnt[1] / 2);
        cout << s.size() << endl;
        for(auto x : s) {
            cout << x << endl;
        }
    }
}



Measured memory_bytes: 3240
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
	int a,b;
	cin>>a>>b;
	if(a>=13)cout<<b<<endl;
	else if(a>=6) cout<<b/2<<endl;
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
$trump
$ns
$ew
def play(cards, first)
    suit = cards[first].suit
    winner = cards[first]
    cards.each do |c|
        if c.suit == $trump && winner.suit == $trump
            winner = c if c.rank > winner.rank
        elsif c.suit == $trump && winner.suit != $trump
            winner = c
        elsif c.suit == suit && winner.suit == suit
            winner = c if c.rank > winner.rank
        end
    end
    id = cards.index(winner)
    if id == 0 || id == 2
        $ns += 1
    else
        $ew += 1
    end
    return id
end
class Cards
    attr_accessor :suit, :rank
    def initialize(s)
        @rank = s[0].gsub((/T|J|Q|K|A/), "T" => "10", "J" => "11", "Q" => "12", "K" => "13", "A" => "14").to_i
        @suit = s[1]
    end
    def to_s
        "#{@rank} of #{@suit}"
    end
end
loop do
    $trump = gets.chomp
    break if $trump == "\#"
    p = 4.times.map{gets.split.map{|e| Cards.new(e)}}
    $ns = $ew = 0
    first = 0
    13.times do |i|
        first = play([p[0][i],p[1][i],p[2][i],p[3][i]], first)
    end
    puts $ns > 6 ? "NS #{$ns - 6}" : "EW #{$ew - 6}"
end

Measured memory_bytes: 6120
N = int(input())

l = [[0 for j in range(10)] for i in range(10)]

for n in range(1, N+1):
  s = str(n)
  i = int(s[0])
  j = int(s[-1])
  l[i][j] += 1

ans = sum([l[i][j]*l[j][i] for i in range(10) for j in range(10)])

print(ans)

Measured memory_bytes: 3064
h, w = map(int, input().split())
canvas = []
for _ in range(h):
    row = input()
    canvas.append(row)

for i in range(h):
    for j in range(w):
        if canvas[i][j] == ".": continue
        candraw = False
        for delta in [-1,1]:
            if 0 <= i + delta < h:
                if canvas[i+delta][j]=="#":
                    candraw = True
                    break
            if 0 <= j + delta < w:
                if canvas[i][j+delta]=="#":
                    candraw = True
                    break
        if not candraw:
            print("No")
            exit(0)
print("Yes")

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

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

int main() {
  int n;
  cin >> n;
  
  if(n % 2 == 0)
    cout << n;
  
  else 
    cout << n*2;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int main(){

	int A,P;
	scanf("%d %d",&A,&P);

	printf("%d\n",(3*A+P)/2);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N, M; cin >> N >> M;
    vector<pair<int, int>> pairs;
    for(int i = 0; i < M; i++){
        int a, b; cin >> a >> b;
        pair<int, int> p = make_pair(b, a); //b a
        pairs.push_back(p);
    }
    sort(pairs.begin(), pairs.end());


    //for(int i = 0; i < M; i++) cout << pairs[i].first << endl;
    //cout << endl;
    //for(int i = 0; i < M; i++) cout << pairs[i].second << endl;
    //int idxa = 0; 
    //int idxb = 0;
    int cnt = 0;
    vector<int> bridge;

    for(int i = 0; i < pairs.size(); i++){
        int a = pairs[i].second;
        int b = pairs[i].first;
        //cout << a << " " << b << endl;
        if(i == 0){
            bridge.push_back(b);
            cnt++;
        }
        else{
            bool flag = true;
            for(int j = 0; j < bridge.size(); j++){
                int br = bridge[j];
                //cout << br << endl;
                if(a < br && br <= b) { flag = true; break;}
                else flag = false;
            }
            if(!flag){
                    //cout << "y" << endl;
                    bridge.push_back(b);
                    cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1400
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<cctype>
#include<set>
#include<vector>
#include<queue>
#include<map>
#define fi(s) freopen(s,"r",stdin);
#define fo(s) freopen(s,"w",stdout);
using namespace std;
typedef long long LL;

inline int read() {
    int x=0,f=1;char ch=getchar();for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
    for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';return x*f;
}

const int N = 1000005;

int a[N], n;

bool pd(int x) {
	int cnt = 0;
	for (int i=1; i<=n; ++i) {
		if (a[i] != x - 1 && a[i] != x) return false;
		if (a[i] == x - 1) cnt ++; // 独立的一种颜色 
	}
	int r = n - cnt;
	if (cnt <= x) {
		if (x - cnt && r >= (x - cnt) * 2) return true;
		if (x - cnt == 0 && r == 0) return true;
	}
	return false;
}

void solve() {
	n = read();
	int L = 0, R = 0;
	for (int i=1; i<=n; ++i) a[i] = read();
	L = a[1], R = a[1] + 1;
	for (int i=1; i<=n; ++i) 
		L = max(L, a[i]), R = min(R, a[i] + 1);	
	if (L > R) { puts("No"); return ; }
	if (pd(L)) { puts("Yes"); return ; }
	if (L < R) { if (pd(R)) { puts("Yes"); return ; } }
	puts("No");
}

int main() {
	
//	freopen("hat.in","r",stdin);
//	freopen("hat.out","w",stdout);
	solve();
//	for (int T = read(); T --; ) solve();
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

const int MAX = 2e5;
int n;
int a[MAX + 1];

int main() {
	cin >> n;
	rep1(i, n) cin >> a[i];


	if (n % 2 == 0) {
		for (int i = n;i >= 2;i -= 2) cout << a[i] << " ";
		for (int i = 1;i<n;i += 2) cout << a[i] << " ";
	}
	else {
		for (int i = n;i >= 1;i -= 2) cout << a[i] << " ";
		for (int i = 2;i<n;i += 2) cout << a[i] << " ";
	}
}

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

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

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    map<int, int> a2cnt;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        a2cnt[a]++;
    }
    auto l = a2cnt.begin();
    auto r = prev(a2cnt.end());
    while (l != r) {
        if (l->second == 1) {
            l++;
        } else if (r->second == 1) {
            r--;
        } else if (l->second >= r->second) {
            l->second -= r->second - 1;
            r->second = 1;
        } else {
            r->second -= l->second - 1;
            l->second = 1;
        }
    }
    int ans = (l->second % 2 == 0) ? a2cnt.size() - 1 : a2cnt.size();
    cout << ans << '\n';
}


Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10 
typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;
int main(){
  int sum = 0, a;
  rep(i, 4){
    scanf("%d", &a);
    sum += a;
  }
  printf("%d\n%d\n", sum/60, sum%60);
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n;
  cin >> n;
  vecll a(n);
  bool beforespace = false;
  forll(i, 0, n)
	cin >> a[i];


  if(n%2==0){
	for(int i=n-1; i>0; i-=2){
	  cout << a[i] << " ";
	}
	for(int i=0; i<n; i+=2){
	  cout << a[i] << " ";
	}
	cout << endl;
  }else{
	for(int i=n-1; i>=0; i-=2){
	  cout << a[i] << " ";
	}
	for(int i=1; i<n; i+=2){
	  cout << a[i] << " ";
	}
	cout << endl;
  }
}


Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int INF = 1 << 30;

class SegTree {
  int vertexc;
  int segstart;
  
  vector<pair<int, int>> tree;
  vector<int> lend;
  vector<int> rend;

  void update (int u) {
    if (u == 0) return;
    tree[u] = min(tree[2 * u], tree[2 * u + 1]);
    update(u / 2);
  }

public:
  SegTree (int _length = 0) {
    segstart = 1;
    while (segstart < _length) {
      segstart *= 2;
    }
    vertexc = segstart * 2;

    tree = vector<pair<int, int>> (vertexc, make_pair(INF, INF));
    lend = vector<int> (vertexc);
    rend = vector<int> (vertexc);
    for (int i = segstart; i < vertexc; i++) {
      lend[i] = i - segstart;
      rend[i] = i - segstart;
    }

    for (int i = segstart - 1; i >= 1; i--) {
      lend[i] = lend[2 * i];
      rend[i] = rend[2 * i + 1];
    }
  }

  pair<int, int> query (int ql, int qr, int u = 1) {
    ql = max(ql, lend[u]);
    qr = min(qr, rend[u]);

    if (ql > qr) return {INF, INF};
    if (ql == lend[u] && qr == rend[u]) return tree[u];
    return min(query(ql, qr, 2 * u), query(ql, qr, 2 * u + 1));
  }

  void set (int idx, pair<int, int> val) {
    tree[idx + segstart] = val;
    update((idx + segstart) / 2);
  }
};

const int MAX_N = 2e5 + 5;

int arr [MAX_N];
SegTree both;
SegTree even;
SegTree odd;

vector<int> adj [MAX_N];
pair<int, int> val [MAX_N];

int vc;
int solve (int l, int r) {
  int idx = vc;
  vc++;

  pair<int, int> lsp;
  if (l % 2 == 0) {
    lsp = even.query(l, r - 1); // <val, idx>
  } else {
    lsp = odd.query(l, r - 1);
  }
  pair<int, int> rsp;
  if (lsp.second % 2 == 0) {
    rsp = odd.query(lsp.second + 1, r);
  } else {
    rsp = even.query(lsp.second + 1, r);
  }

  val[idx] = make_pair(lsp.first, rsp.first);

  int m1 = lsp.second;
  int m2 = rsp.second;

  if (l <= m1 - 1) {
    adj[idx].push_back(solve(l, m1 - 1));
  }

  if (m1 + 1 <= m2 - 1) {
    adj[idx].push_back(solve(m1 + 1, m2 - 1));
  }

  if (m2 + 1 <= r) {
    adj[idx].push_back(solve(m2 + 1, r));
  }
  
  return idx;
}

priority_queue<pair<pair<int, int>, int>,
               vector<pair<pair<int, int>, int>>,
               greater<pair<pair<int, int>, int>>> PQ;

void expand () {
  pair<int, int> wal = PQ.top().first;
  int idx = PQ.top().second;

  cout << wal.first << " " << wal.second << " ";
  PQ.pop();

  for (int nxt : adj[idx]) {
    PQ.push(make_pair(val[nxt], nxt));
  }
}

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

  int n;
  cin >> n;

  both = SegTree (n + 5);
  even = SegTree (n + 5);
  odd = SegTree (n + 5);
  
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];

    both.set(i, make_pair(arr[i], i));
    if (i % 2 == 0) {
      even.set(i, make_pair(arr[i], i));      
    } else {
      odd.set(i, make_pair(arr[i], i));
    }
  }

  int root = solve(1, n);
  PQ.push(make_pair(val[root], root));

  while (!PQ.empty()) {
    expand();
  }
  cout << endl;
}


Measured memory_bytes: 96512
//
//  main.cpp
//  Study
//
//  Created by 佐々木勇星 on 2020/03/12.
//  Copyright © 2020 佐々木勇星. All rights reserved.
//

#include <iostream>
#include <vector>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;


int main(int argc, const char * argv[]) {
    
    long long h, w;
    long long ans = 0;
    
    cin >> h >> w;
    
    if (h % 2 == 1 && w % 2 == 1)
    {
        ans = (w / 2 + 1) * (h / 2 + 1) + (w / 2) * (h / 2);
    } else if (h % 2 == 1 && w % 2 == 0)
    {
        ans = (w / 2) * (h / 2 + 1) + (w / 2) * (h / 2);
    } else if (h % 2 == 0 && w % 2 == 1)
    {
        ans = (w / 2 + 1) * (h / 2) + (w / 2) * (h / 2);
    } else if (w % 2 == 0 && h % 2 == 0)
    {
        ans = (w / 2) * (h / 2) + (w / 2) * (h / 2);
    }
    
    if( h == 1 || w == 1) ans = 1;
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256