akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let  s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: i32, a: i32
    }
    let b = a >= 500 || (n % 500) <= a;
    println!("{}", if b {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+100;
const int P = 1e9+7;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

inline int pow_mod(int x,int k){
   int res = 1,base = x;
   while(k){
      if(k&1)res = 1LL*res*base%P;
      k >>= 1; base = 1LL*base*base%P;
   }
   return res;
}

inline void add(int &x,int y){
   x += y; if(x >= P)x -= P;
}

struct bit{
   int val[N],cnt[N];
   void init(){
      memset(val,0,sizeof val); memset(cnt,0,sizeof cnt);
   }
   inline void modify(int x,int v){
      while(x < N){
         cnt[x]++; add(val[x],v); x += x&(-x);
      }
   }
   inline int query(int x){
      int res = 0;
      while(x){
         add(res,val[x]); x -= (x&(-x));
      }
      return res;
   }
   inline int q2(int x){
      int res = 0;
      while(x){
         res += cnt[x]; x -= (x&(-x));
      }
      return res;
   }
}s;

int a[N],n,cnt[N],d[N];
int b[N];
int pre[N],pos[N];
int ans;

int main(){
   scanf("%d",&n);
   fr(i,1,n)scanf("%d",a+i),a[i] = min(a[i],n),b[i] = a[i];

   sort(b+1,b+n+1);
   int j = 1,tot = 1;

   fr(i,1,n){
      while(j <= n && b[j] < i) ++j;
      cnt[i] = n-j+1-(n-i); d[i] = 1LL*(cnt[i]-1)*pow_mod(cnt[i],P-2)%P;
      tot = 1LL*tot*cnt[i]%P;
   }

   if(tot == 0){
      puts("0");
      return 0;
   }

   pre[0] = 1; pos[0] = 0;
   fr(i,1,n){
      if(d[i] == 0)pre[i] = 1,pos[i] = i;
      else pre[i] = 1LL*pre[i-1]*d[i]%P,pos[i] = pos[i-1];
   }

   s.init();
   ans = 0;
   fr(i,1,n){
      add(ans,1LL*(P+s.query(a[i])-s.query(pos[a[i]]))*pre[a[i]]%P*tot%P);
      s.modify(a[i],pow_mod(pre[a[i]],P-2));
   }
   ans = 1LL*ans*pow_mod(2,P-2)%P;

   s.init();
   nfr(i,n,1){
      if(d[a[i]] != 0){
         add(ans,(P-(1LL*(P+s.query(a[i]-1)-s.query(pos[a[i]]))*pre[a[i]]%P*tot%P
               *pow_mod(2,P-2)%P))%P);
      }
      add(ans,1LL*tot*s.q2(a[i]-1)%P);

      s.modify(a[i],pow_mod(pre[a[i]],P-2));
   }

   printf("%d\n",ans);
   return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
int main(){
    int a, b, c, k;
    cin >> a >> b >> c >>k;
    if(k<=a){
        cout << k << endl;
        return 0;
    }
    if(k<=a+b){
        cout << a << endl;
        return 0;
    }
    if(k<=a+b+c){
        int d = k-a-b;
        cout << a-d << endl;
        return 0;
    }
}

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

int main(){
	int a,b,k;
	cin>>a>>b>>k;
	for(int i=min(a,b);i>=1;i--){
		if(a%i==0 && b%i==0)k--;
		if(k==0){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pi 3.141592653589793116
#define mod 1e9+7
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

long long int dp[100001][2][2];
int a[100001];
int n;
long long  go(int i,int curr,int pre1)
{
   if(i==n-1)
     {
         if(curr==1)
           return -a[i];
         else
            return a[i];
     }
    if(dp[i][curr][pre1]!=-1)
       return dp[i][curr][pre1]; 
   else
      {   long long ans=0;
          if(curr==1)
             ans=max({ans,-a[i]+go(i+1,0,curr),a[i]+go(i+1,1,curr)});
          else
             ans=max({ans,a[i]+go(i+1,0,curr),-a[i]+go(i+1,1,curr)});
          dp[i][curr][pre1]=ans;
          return ans;       
      }
}


int main() {
  off;
  int t;
  //cin>>t;
  t=1;
  while(t--){  
     cin>>n;
     for(int i=0;i<n;i++)
        cin>>a[i];
      memset(dp,-1,sizeof(dp));
    long long x=0;
    x=max(a[0]+go(1,0,0),-a[0]+go(1,1,1));
      cout<<x<<'\n';  
  }
    return 0;
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int n, k; cin >> n >> k;
    vector<ll> a(n+1, 0), c(n+1, 0);
    repr(i, 1, n+1) cin >> a[i];
    repr(i, 1, n+1) c[i] = c[i-1] + a[i];
    repr(i, 1, n+1) c[i] = (c[i]-i)%k;

    map<int, ll> mp;
    ll ans = 0;
    rep(i, n+1){
        ans += mp[c[i]];
        ++mp[c[i]];
        if(i-k+1>=0) mp[c[i-k+1]]--;
    }
    cout << ans << endl;
    
    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const double EPS = 1e-10;

int main() {
    int N;
    cin >> N;
    bool all_even = true;
    rep(i, N) {
        int tmp;
        cin >> tmp;
        if (tmp % 2 != 0) all_even = false;
    }
    cout << (all_even ? "second" : "first") << endl;
    return 0;
}

Measured memory_bytes: 3684
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N; cin >> N; int a[N]; int mi = inf, ma = 0;
  rep(i, N){
    cin >> a[i]; mi = min(a[i], mi); ma = max(a[i], ma);
  }
  if(ma-mi>1){
    cout << "No" << endl; return 0;
  }
  if(ma==mi){
    if(ma==N-1){
      cout << "Yes" << endl; return 0;
    }
    if(N>=ma*2){
      cout << "Yes" << endl; return 0;
    }
    cout << "No" << endl; return 0;
  }
  int micnt=0, macnt=0;
  rep(i, N){
    if(a[i]==mi) micnt++; else macnt++;
  }
  if(micnt + macnt/2 >=ma && micnt + 1<=ma){
    cout << "Yes" << endl; return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int, int> P;
#define fi first
#define se second
int main(){
int n;
cin>>n;
vector<int>odd,even;
for(int i=0;i<n;i++){
	int a;
	if(i%2==0){
		cin>>a;
		even.push_back(a);
	}
	else{
		cin>>a;
		odd.push_back(a);
	}
}
sort(even.begin(),even.end());
sort(odd.begin(),odd.end());
priority_queue<P> odd_p,even_p;
int o=odd.at(0),e=even.at(0);
int count=1;
for(int i=1;i<even.size();i++){
     if(e==even.at(i))count++;
	 else{
		 even_p.push(P(count,e));
		 e=even.at(i);
		 count=1;
	 }
}
if(count!=1)even_p.push(P(count,e));
count=1;
for(int i=1;i<odd.size();i++){
     if(o==odd.at(i))count++;
	 else{
		 odd_p.push(P(count,o));
		 o=odd.at(i);
		 count=1;
	 }
}
if(count!=1)odd_p.push(P(count,o));
even_p.push(P(0,0));
odd_p.push(P(0,0));
P t=even_p.top(),v=odd_p.top();
even_p.pop();
odd_p.pop();
if(t==v){
   P t1=even_p.top(),v1=odd_p.top();
   int ans1=n-t1.fi-v.fi,ans2=n-t.fi-v1.fi;
   cout<<min(ans1,ans2)<<endl;
}
else{
	int res=n-t.fi-v.fi;
	cout<<res<<endl;
}

}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
                using namespace std;
                #define lli long long int
                #define fr(i,a,b) for(int i=a;i<b;i++)
                #define bfr(i,a,b) for(int i=a;i>=b;i--)
                #define fio ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
                #define tc int t;cin>>t;while(t--)
                #define mod 1000000007 
                #define all(vec) vec.begin(),vec.end()  
                #define ld long double


               
        int main()
                {
                       
                        
                    
                     fio
                     
                     map<lli,pair<lli,lli>> m;
                     lli a[3][3],x;
                     fr(i,0,3)
                     fr(j,0,3)
                     {
                        cin>>x;
                        m[x]={i,j};
                        a[i][j]=0;
                     }
                     lli n;
                     cin>>n;
                     fr(i,0,n)
                     {
                        cin>>x;
                        if(m.count(x)!=0)
                        a[m[x].first][m[x].second]=1;
                     }

                     lli sum1=0,sum2=0,sum3=0;
                     fr(i,0,3)
                     {
                        if(a[0][i]==1)sum1++;
                        if(a[1][i]==1)sum2++;
                        if(a[2][i]==1)sum3++;

                     }
                     if(sum1==3 || sum2==3 || sum3==3){cout<<"Yes";return 0;}

                     sum1=0,sum2=0,sum3=0;

                     fr(i,0,3)
                     {
                        if(a[i][0]==1)sum1++;
                        if(a[i][1]==1)sum2++;
                        if(a[i][2]==1)sum3++;

                     }

                      if(sum1==3 || sum2==3 || sum3==3){cout<<"Yes";return 0;}

                      if(a[0][0]+a[1][1]+a[2][2]==3){cout<<"Yes";return 0;}
                      if(a[0][2]+a[1][1]+a[2][0]==3){cout<<"Yes";return 0;}

                      cout<<"No";




                     







                     


                     

                     

                     


return 0;}

Measured memory_bytes: 256
import java.util.*;
 
class Main{
    public static void main(String[] arg){
    Scanner sc = new Scanner(System.in);
 
    while(sc.hasNext()){
 
        double[] x = new double[3];
        double[] y = new double[3];
        for(int i=0; i<3; i++){
        x[i] = sc.nextDouble();
        y[i] = sc.nextDouble();
        }
 
        double xp = sc.nextDouble();
        double yp = sc.nextDouble();
 
        for(int i=0; i<3; i++){
        x[i] = x[i] - xp;
        y[i] = y[i] - yp;
        }
 
        double[] gaiseki = new double[3];
        gaiseki[0] = x[0]*y[1] - y[0]*x[1];
        gaiseki[1] = x[1]*y[2] - y[1]*x[2];
        gaiseki[2] = x[2]*y[0] - y[2]*x[0];
 
        int plus = 0;
        int minus = 0;
        for(int i=0; i<3; i++){
        if(gaiseki[i]>0){plus++;}
        if(gaiseki[i]<0){minus++;}
        }
 
        String ans = "NO";
        if(plus==3 || minus==3){ans = "YES";}
 
        System.out.println(ans);
    }
    }
}

Measured memory_bytes: 31008
input=$(</dev/stdin)
A=$(echo $input | cut -d ' ' -f1-5)
K=$(echo $input | cut -d ' ' -f6)

for i in $(seq 1 5); do
    for k in $(seq $i 5); do
        X=$(echo $input | cut -d ' ' -f$i)
        Y=$(echo $input | cut -d ' ' -f$k)
        
        D=$(($Y-$X))
        
        if [ $D -gt $K ]; then
            echo ':('
            exit
        fi
    done
done

echo Yay!


Measured memory_bytes: 856
def main():
    n = int(input())
    a_list = list(map(int, input().split()))
    b_list = list(map(int, input().split()))
    c_list = list(map(int, input().split()))

    count = 0
    before = -1

    for i in range(n):
        count += b_list[a_list[i]-1]
        if before + 1 == a_list[i]:
            count += c_list[a_list[i]-2]
        before = a_list[i]

    print(count)

if __name__ == '__main__':
    main()

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

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

  if ( a * b % 2 == 0 ) {
    cout << "Even" << endl;
  }
  else if (!( a * b % 2 == 0 )) {
    cout << "Odd" << endl;
  }
  
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n;
    cin>>n;
    V<int> a(n);
    map<int,int> mp;
    for(int i=1;i<n;i++){
        cin>>a[i];
        mp[a[i]]++;
    }
    for(int i=1;i<=n;i++) cout<<mp[i]<<'\n';
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え(=でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
*/

Measured memory_bytes: 13552
package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Scan()
	n, _ := strconv.Atoi(s.Text())

	d := make(map[int]int, n)
	for i := 0; s.Scan(); i++ {
		a, _ := strconv.Atoi(s.Text())
		d[a] = 1
	}

	fmt.Println(len(d))
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
  int a,b,c=0;
  scanf("%d%d",&a,&b);
 //2a-1 2b-1 a+b
  if(a>=b)
  {
    if(2*a-1>=a+b)
    {
      c=2*a-1;
    }else
    {
      c=a+b;
    }
  }  
  else
  {
    c=2*b-1;
  }
  printf("%d",c);
  return 0;
}

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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  ll n, k;
  cin >> n >> k;

  ll cnt1 = 0, cnt2 = 0;
  for (int i = 1; i <= n; ++i) {
    if (k % 2 == 0 && i % k == k / 2) {
      cnt2++;
    }

    if (i % k == 0) {
      cnt1++;
    }
  }

  auto pow3 = [](ll x) { return x * x * x; };
  cout << pow3(cnt1) + pow3(cnt2) << '\n';
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
int mod = 1e9 + 7;

signed main() {
    vector<int> A(3);
    cin >> A;
    cout << ((accumulate(all(A), 0L) >= 22) ? "bust" : "win") << endl;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        
        boolean isOK = Math.abs( a - c ) <= d || ( Math.abs(a - b) <= d && Math.abs(b - c) <= d );

        System.out.println( (isOK) ? "Yes" : "No" );
    }
}


Measured memory_bytes: 35660
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
total = 0
for i in range(n):
    if a[i] > b[i]:
        total += b[i]
    else:
        if a[i+1] >= b[i] - a[i]:
            a[i+1] -= (b[i] - a[i])
            total += b[i]
        else:
            total += a[i] + a[i+1]
            a[i+1] = 0
print(total)

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 200005;
int N;
ll a[MAX_N];

void solve()
{
	ll tot = 0;
	for(int i=0;i<N;++i) tot ^= a[i];
	for(int i=0;i<N;++i){
		cout << (tot^a[i]) << ' ';
	}
	cout << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i) cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 5108
// #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}


long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}

int main() {
  int N;string S;
  cin >> N >> S;
  vector<int> r,g,b;
  rep(i,N) {
    if (S[i]=='R') r.push_back(i);
    else if (S[i]=='G') g.push_back(i);
    else b.push_back(i);
  }

  ll ans = 0;
  for (auto ir:r) {
    for (auto ig:g) {
      int si=min(ir,ig),li=max(ir,ig),w=li-si,cnt=0;
      
      if (si-w>=0 && S[si-w]=='B') cnt++;
      
      if (li+w<N && S[li+w]=='B') cnt++;
      
      if ((li+si)%2==0 && S[(li+si)/2]=='B') cnt++;
      // cout << cnt << endl;
      ans += b.size()-cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;

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

#define pb push_back
#define fr first
#define sc second

vector<int> ret;
int N;
void sol(int k,int n){
	ret.pb( (k+1)/2 );
	if(n == 1)return;
	sol( k , n-1 );
	if(n%2 == 0){
		if(ret.size() == N){
			ret[ret.size()-1] --;
			if(ret[ret.size()-1] == 0){
				ret.pop_back();
			}
		}
		else {
			ret[ret.size()-1] --;
			if(ret[ret.size()-1] == 0){
				ret.pop_back();
			}
			else {
				while(ret.size() < N)ret.pb(k);
			}
		}
	}
}

int main(){
	int k,n;
	cin >> k >> n;
	N = n;
	if(k%2 == 0){
		ret.pb(k/2);
		for(int i = 0 ; i < n-1 ; i ++){
			ret.pb(k);
		}
	}
	else {
		sol(k,n);
	}
	for(int i = 0 ; i < ret.size() ; i ++){
		printf("%d%c",ret[i],(i==ret.size()-1)?'\n':' ');
	}
}



Measured memory_bytes: 17648
#include<stdio.h>
//小さい順にソート
int c[200002];
void merge(int i,int j,int *s){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d]=s[b];
        b++;
      }
      else if(j<b){
        c[d]=s[a];
        a++;
      }
      else if(s[a]<s[b]){
        c[d]=s[a];
        a++;
      }
      else{
        c[d]=s[b];
        b++;
      }
    }
    for(d=i;d<=j;d++)
      s[d]=c[d];
  }
}

int main(){
  int n,i;
  scanf("%d",&n);
  int a[n+1];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  merge(0,n-1,a);
  int dp[a[n-1]+1];
  for(i=1;i<=a[n-1];i++)
    dp[i]=0;
  for(i=0;i<n;i++){
    int j=2;
    if(a[i]==a[i-1] && i!=0)
      j=1;
    while(j*a[i]<=a[n-1]){
      dp[j*a[i]]=1;
      j++;
    }
  }
  int count=0;
  for(i=0;i<n;i++)
    if(dp[a[i]]==0)
      count++;
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 7188
import java.util.Scanner;

    public class Main {
        public static void main(String... args) {
            try (Scanner sc = new Scanner(System.in)) {
                final int K = sc.nextInt();
                final int S = sc.nextInt();
                int count = 0;
                for (int X = 0; X <= K; X++) {
                    for (int Y = 0; Y <= K; Y++) {
                        if (X + Y > S) break;
                        if (S - X - Y <= K) count++;
                    }
                }
                System.out.println(count);
            }
        }
    }

Measured memory_bytes: 9680
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int time;
    
    scanf("%d", &time);

    int s = time%60;
    int m = (time/60)%60;
    int h = time/60/60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  ll N, M; cin >> N >> M;
  ll A[N]; rep(i,N) cin >> A[i]; sort(A, A+N);
  ll l = 0, r = 2*pow(10,5);
  while (l!=r) {
    ll mid = (l+r+1)/2;
    ll num = 0;
    rep(i,N) num += (A+N) - lower_bound(A,A+N,mid-A[i]);
    if (num>=M) l = mid;
    else r = mid-1;
    // cout << mid << " " << num << endl;
  }
  ll sum[N+1] = {}; rep(i,N) sum[i+1] = sum[i] + A[i];
  ll result = 0;
  ll sumpos = 0;
  rep(i,N) {
    ll pos = (A+N) - lower_bound(A,A+N,l-A[i]);
    result += sum[N] - sum[N-pos] + pos * A[i];
    sumpos += pos;
  }
  result -= (sumpos-M) * l;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1792
n = int(input())


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def counter(n):

    ccc = 1

    for i in range(2, 16):
        n -= i
        if n < 1:
            return ccc
        else:
            ccc += 1


results = prime_factorize(n)
numbers = {}

for nn in results:
    if nn in numbers.keys():
        numbers[nn] += 1
    else:
        numbers[nn] = 1

output = 0
for v in numbers.values():
    output += counter(v)

print(output)

Measured memory_bytes: 9180
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{

    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var S = Console.ReadLine();

        var leftBlackCount = 0;
        var rightWhiteCount = S.Count((s) => s == '.');
        var result = leftBlackCount + rightWhiteCount;

        for (int i = 0; i < S.Length; i++)
        {
            if (S[i] == '#')
            {
                leftBlackCount++;
            }
            else
            {
                rightWhiteCount--;
            }
            result = Math.Min(result, leftBlackCount + rightWhiteCount);
        }

        Console.WriteLine(result);
    }

}



Measured memory_bytes: 11744
#include <stdio.h>

int main(void) {
    long n, x, m;
    scanf("%ld%ld%ld", &n, &x, &m);
    int s[100001] = { 0 };
    long f = x;
    int first = 1;
    int last = 0;
    s[f] = 1;
    for(int i = 2;i <= n;i++) {
        f = (f * f) % m;
        if(s[f] != 0) {
            first = s[f];
            last = i;
            break;
        } else {
            s[f] = i;
            first = i;
        }
    }
    int t[100001] = { 0 };
    for(int i = 0;i < 100001;i++) {
        if(s[i] > 0) {
            t[s[i]-1] = i;
        }
    }
    if(first == n) {
        long result = 0;
        for(int i = 0;i < n;i++) {
            result += t[i];
        }
        printf("%ld\n", result);
    } else {
        first--, last--;
        long result = 0;
        for(int i = 0;i < first;i++) {
            result += t[i];
        }
        long x = 0;
        for(int i = first;i < last;i++) {
            x += t[i];
        }
        result += x * ((n - first) / (last - first));
        int d = (n - first) % (last - first);
        for(int i = 0;i < d;i++) {
            result += t[first + i];
        }
        printf("%ld\n", result);
    }
    return 0;
}


Measured memory_bytes: 2892
#!/usr/bin/env python3
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

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

score = sum(A[:K])
old_score = score
# print(score)
for i, j in enumerate(range(K, N)):
    score = score - A[i] + A[j]
    # print("new_score: {}".format(score))
    if score > old_score:
        print('Yes')
    else:
        print('No')
    old_score = score


Measured memory_bytes: 31612
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;

int n;
struct node
{
    ll v;
    int index;
};
node a[3000];

ll f[2100][2100];
bool flag[2100][2100];

bool cmp(node& a, node& b)
{
    return a.v>b.v;
}

ll dp(int l,int r)
{
    if (l>r) return 0;
    if (flag[l][r]) return f[l][r];
    flag[l][r] = 1;

    int now=n-(r-l+1)+1;

    ll put_left = a[now].v*(a[now].index-l) + dp(l+1,r);
    ll put_right = a[now].v*(r-a[now].index) + dp(l,r-1);
    f[l][r] = max(put_left, put_right);

    return f[l][r];
}

int main()
{
    cin>>n;
    for (int i=1; i<=n; ++i)
    {
        cin>>a[i].v;
        a[i].index=i;
    }
    sort(a+1, a+1+n, cmp);
    for (int i=1; i<=n; ++i)
    {
        //cout<<a[i].v<<' '<<a[i].index<<endl;
    }
    cout<<dp(1,n)<<endl;
    return 0;

}



Measured memory_bytes: 30892
#include<bits/stdc++.h>
#include<iostream>
#include<fstream>
#define ll long long
using namespace std;

int main(){
    int N;  cin >> N;
    vector<int> W(N+1,0);
    int S = 0;
    for(int i=1; i<=N; i++){
        cin >> W[i];
        S += W[i];
        W[i] += W[i-1];
    }

    int ans = 1e9;
    for(int i=1; i<N; i++){
        int del = abs(W[i] - (S-W[i]));
        ans = min(ans,del);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int b = 1;
        for (int i = 0; i < n; i++) {
            b = Math.min(b + k, 2 * b);
        }
        System.out.println(b);
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<pair<int,int>> a(n);
	for(int i=0;i<n;i++){
		cin >> a[i].first >> a[i].second;
		a[i].second++;
	}
	sort(a.begin(),a.end());
	multiset<int> l,r;
	for(int i=0;i<n;i++){
		l.insert(a[i].first);
		r.insert(a[i].second);
	}
	int ans=0;
	int e1=2e9,s2=0;
	// 1個区別する場合
	for(int i=0;i<n;i++){
		e1=min(e1,a[i].second);
		s2=max(s2,a[i].first);
		l.erase(l.find(a[i].first));
		r.erase(r.find(a[i].second));
		int cnt=max(0,*r.begin()-*l.rbegin());
		ans=max(ans,cnt+a[i].second-a[i].first);
		l.insert(a[i].first);
		r.insert(a[i].second);
	}
	for(int i=0;i<n-1;i++){
		r.erase(r.find(a[i].second));
		ans=max(ans,max(0,e1-a[i].first)+max(0,*r.begin()-s2));
	}
	cout << ans << endl;
}



Measured memory_bytes: 10368
import math
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    A, B, H, M = map(int, input().split())

    h = H * 30 + M * 0.5
    m = M * 6
    rad = math.radians(abs(h - m))
    x = A * A + B * B - 2 * A * B * math.cos(rad)
    print(x ** 0.5)


main()


Measured memory_bytes: 9564
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// get a integer
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		int tmp = y;
        y = x;
        x = tmp;
        tmp = z;
        z = x;
        x = tmp;
        
      
		System.out.println(x + " " + y + " " + z);
	}
}

Measured memory_bytes: 21712
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
	int a, b, c, d, p,x,y;
	std::cin >> a >> b >> c >> d >> p;
	x = p / 1 * a;
	if (p <= c) {
		y = b;
	}
	else {
		y = b + (p - c) / 1 * d;
	}
	if (x >= y) { std::cout << y << std::endl; }
	else { std::cout << x << std::endl; }
}


Measured memory_bytes: 3068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static Tuple<long, long> Convert(Tuple<long, long> tuple, long a)
        {
            if (a > tuple.Item2) { return null; }
            long min = (tuple.Item1 + a - 1) / a * a;
            long max = tuple.Item2 / a * a;
            if (min > max) { return null; }
            return new Tuple<long, long>(min, max + a - 1);
        }

        static Tuple<long, long> Solve(long[] A)
        {
            var tuple1 = new Tuple<long, long>(2, 2);
            foreach (long a in A.Reverse())
            {
                var tuple2 = Convert(tuple1, a);
                if (tuple2 != null)
                {
                    tuple1 = tuple2;
                }
                else
                {
                    return null;
                }
            }
            return tuple1;
        }

        static void Main(string[] args)
        {
            int K = ReadInt();
            long[] A = ReadLongs();
            var ans = Solve(A);
            if (ans != null)
            {
                Console.WriteLine("{0} {1}", ans.Item1, ans.Item2);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


Measured memory_bytes: 27612
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int a,b,c;
int main()
{
    scanf("%d%d%d",&a,&b,&c);
    if(a==b&&b==c) puts("Yes"); else puts("No");
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {

    int i=0;
    int x=0;
    
    while (1) {
        scanf("%d", &x);
        if (x==0) {
            break;
        }
        i++;
        printf("Case %d: %d\n", i, x);
    }
    return 0;
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    int Fbits[N];
    for(int i = 0; i < N; i++) {
        Fbits[i] = 0;
        for(int j = 0; j < 10; j++) {
            int F;
            cin >> F;
            Fbits[i] |= F << j;
        }
    }
    ll P[N][11];
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= 10; j++) {
            cin >> P[i][j];
        }
    }
    ll ans = -INF;
    for(int joi = 1; joi < (1 << 10); joi++) {
        ll a = 0;
        for(int i = 0; i < N; i++) {
            a += P[i][__builtin_popcount(Fbits[i] & joi)];
        }
        ans = max(ans, a);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
res = 0


for i in range(len(s)):
    cnt = 0
    for j in range(i, len(s)):
        if s[j] == "A" or s[j] == "C" or s[j] == "T" or s[j] == "G": cnt += 1
        else: break
    res = max(res, cnt)
print(res)


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

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

	int num;
	int ans;

	if (k % 2 == 0) {
		num = k / 2;
		ans = num * num;
	}
	else {
		num = k / 2 + 1;
		ans = num * (num - 1);
	}
	
	cout << ans << endl;
	
	return 0;
}

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


int main()
{
    int N;
    cin>>N;
    vector<int> buttons(N);
    for (int i=0;i<N;++i){
        cin>>buttons.at(i);
    }
    
    int on = 1;
    for (int i=0;i<=N;++i){
        if (on == 2){
            cout << i << endl;
            return 0;
        }
        on = buttons.at(on-1);
    }
    cout<<-1<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;

ll max(ll x,ll y){
	if(x>y){
	return x;
	}else{
		return y;
	}
}

int main(){
	ll dp[101][11];
	ll N,W;
//	ll w[101]={},v[101]={};
	vector<ll>v_1,v_2,v_3,v_4;
	ll W_1;
	cin >> N >> W;
	ll input;
	
	cin >> W_1 >> input;
	
	v_1.push_back(input);
	for(int i=2;i<=N;i++){
		cin >> input;
		switch (input-W_1){
			case 0:
				cin >> input;
				v_1.push_back(input);
				break;
			case 1:
				cin >> input;
				v_2.push_back(input);
				break;
			case 2:
				cin >> input;
				v_3.push_back(input);
				break;
			case 3:
				cin >> input;
				v_4.push_back(input);
				break;
			default:
				cout << "Unexpected error" << endl;
				return 0;
		}
	}
	
	sort(v_1.begin(),v_1.end(),greater<int>());
	sort(v_2.begin(),v_2.end(),greater<int>());
	sort(v_3.begin(),v_3.end(),greater<int>());
	sort(v_4.begin(),v_4.end(),greater<int>());
	
	ll weight=0,value=0,answer=0;
	
	for(int i=0;i<=v_1.size();i++){
		for(int j=0;j<=v_2.size();j++){
			for(int k=0;k<=v_3.size();k++){
				for(int l=0;l<=v_4.size();l++){
					weight=(W_1+0)*i+(W_1+1)*j+(W_1+2)*k+(W_1+3)*l;
					if(weight<=W){
						value=0;
						for(int m=0;m<i;m++){
							value+=v_1[m];
						}
						for(int m=0;m<j;m++){
							value+=v_2[m];
						}
						for(int m=0;m<k;m++){
							value+=v_3[m];
						}
						for(int m=0;m<l;m++){
							value+=v_4[m];
						}
						
						answer=max(answer,value);
					}
				}
			}
		}
	}
	
	cout << answer << endl;
	
	/*
	
	for(int i=1;i<=N;i++){
		cin >> w[i] >> v[i];
		if(i==1){ //w[i] 0<=...<=3
			w_1=w[1]-1;
			w[1]=1;
		}else{
			w[i]=w[i]-w_1;
		}
	}
	
	for(int i=0;i<101;i++){
		for(int j=0;j<11;j++){
			dp[i][j]=0;
		}
	}
	
	bool check[11]={};
	check[0]=true;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<11;j++){
			if(check[j]){
				dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
				
				if(j+w[i+1]<=W-(w_1+1)&&j+w[i+1]<11){
					dp[i+1][j+w[i+1]]=max(dp[i+1][j+w[i+1]],dp[i][j]+v[i+1]);
					check[j+w[i+1]]=true;
				}
			}
		}
	}
	
	ll answer=0;
	
	for(int i=0;i<11;i++){
		answer = max(answer,dp[N][i]);
	}
	
	cout << answer << endl;
	 */
	
	return 0;
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };
 
typedef long long ll;
using namespace std;
 
int main() {
  rep(i,1,10){
    rep(j,1,10){
      printf("%dx%d=%d\n",i,j,i*j);
    }
  }
  return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  int n, k;cin>>n>>k;
  vector<int>a(n);
  rep(i, n){
    cin>>a[i];
  }

  int dp[100001];
  memset(dp, 0, sizeof(dp));
  
  dp[0]=-1;
  for(int i=1; i<=k; i++){
    bool f = true;
    rep(j, n){
      if(i >= a[j]  && dp[i-a[j]]==-1){
        dp[i]=a[j];
        f=false;
        break;
      }
    }
    if(f)dp[i]=-1;
//rep(i, k+1)cout<<dp[i]<<' ';cout<<endl;
  }

  if(dp[k] != -1)cout<<"First"<<endl;
  else cout<<"Second"<<endl;

  return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

ll H,W;
ll c[10][10];
signed main() {
    cin>>H>>W;
    rep(i,0,10) rep(j,0,10) cin>>c[i][j];
    rep(k,0,10) rep(i,0,10) rep(j,0,10) c[i][j]=min(c[i][j], c[i][k]+c[k][j]);
    // rep(i,0,10){
    //     printf("%d -> 0: %d\n", i, c[i][1]);
    // }

    ll ans = 0;
    rep(i,0,H) rep(j,0,W){
        ll x;
        cin>>x;
        if (x!=-1){
            ans += c[x][1];
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);

// ===

fn main() {
    let n: usize = read();
    let a: Vec<i32> = readnc();

    let mut deq = VecDeque::new();
    for i in 0..n {
        if i % 2 == 0 {
            deq.push_front(a[i]);
        } else {
            deq.push_back(a[i]);
        }
    }

    let mut first = false;
    while deq.len() >= 1 {
        if first {
            print!(" ");
        }
        first = true;
        print!("{}", if n % 2 == 0 { deq.pop_back().unwrap() } else { deq.pop_front().unwrap() })
    }
    println!();
}

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

long long int gcd(long long int a, long long int b)
{
	if(b == 0) return a;
	return gcd(b, a%b);
}

int main()
{
	long long int A, B, C, D;
	cin >> A >> B >> C >> D;

	long long int ans = B - A + 1;

	long long int g = gcd(D, C);
	long long int x = C / g * D;


	long long int a1 = (A-1) / C;
	long long int a2 = (A-1) / D;
	long long int a3 = (A-1) / x;

	long long int b1 = B / C;
	long long int b2 = B / D;
	long long int b3 = B / x;

	ans -= (b1+b2-b3) - (a1+a2-a3);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ll long long
#define ull unsigned long long
// #define ordered_set tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> 
ll mod=1e9+7;
#define PI 3.1415926535897932385
#define inf 9e18
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
typedef pair<long long, long long> ii;
#define S second
#define F first
ll max(ll a,ll b){if(a>b){return a;}return b;}
ll min(ll a,ll b){if(a<b){return a;}return b;}
#define MAXN 200005
// Comment this out for interactice problem
// #define endl '\n'
// string to integer stoi() Remember: it takes string not character
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
 
// To compile--> g++ -std=c++0x -o output one.cpp
// To run--> ./output

int main() 
{ 
    fastio;
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ll x,y;
    cin>>x>>y;
    if(y%2==0){
        ll a = (2*x)-(y/2);
        ll b = (y/2)-x;
        if((a>=0) && (b>=0)){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No";
    }


    return 0;
}

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

using namespace std;

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

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

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}

int main(){
    string s;
    char pp_c, p_c;

    cin >> s;

    pp_c = s[0];
    p_c  = s[1];
    if(p_c == pp_c) {
        cout << 1 << " " << 2 << endl;
        return 0;
    }
    int st = -1, ed = -1;

    for(int i = 2; i < s.length(); i++) {
        if(p_c == s[i]) {
            st = i;
            ed = i + 1;
            break;
        } else if(pp_c == s[i]) {
            st = i - 1;
            ed = i + 1;
            break;
        }
        pp_c = p_c;
        p_c  = s[i];
    }

    cout << st << " " << ed << endl;

    return 0;
}


Measured memory_bytes: 512
n,k=map(int,input().split())
rabbit=[0]*n
anger=[0]*n
for i in range(k):
    m,*b=map(int,input().split())
    for j in b:
        rabbit[j-1]=i+1
k=int(input())
for i in range(k):
    a,b=map(int,input().split())
    if rabbit[a-1]==rabbit[b-1]:anger[a-1],anger[b-1]=1,1
print(sum(anger))


Measured memory_bytes: 5604
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

template <typename T>
set<T> factors(T a) {
    set<T> facs;
    for (T i = 1; i * i < a; ++i) {
        if (a % i == 0 && i + 1 < a / i) {
            //facs.insert(i);
            facs.insert(a / i);
        }
    }
    return facs;
}

int main() {
    ll N;
    cin >> N;
    auto f = factors<ll>(N);
    ll ret = 0;
    for (auto ff : f) {
        ret += ff - 1;
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 384