akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"


int func(int arr[], int n){
  int t[n + 1];
  // init
  t[1] = 0;
  t[2] = abs(arr[1] - arr[0]);
  // logic
  for(int i = 3; i<= n; i++){
    int a1 = abs(arr[i - 1] - arr[i - 2]);
    int a2 = abs(arr[i - 1] - arr[i - 3]);
    t[i] =  min(a1 + t[i - 1], a2 + t[i - 2]);
  }
  return t[n];
}

void solve() {
  int n; cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++) cin >> arr[i];
  int ans = func(arr, n);
  cout << ans << endl;
}
int main(){
// #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 4416
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll N;
    cin >> N;
    ll A[200010], B[200010];
    rep(i,0,N) cin >> A[i] >> B[i];
    ll ans = 0;
    vector<ll> va,vb;
    rep(i,0,N){
        va.push_back(A[i]);
        vb.push_back(B[i]);
    }
    sort(va.begin(), va.end());
    sort(vb.begin(), vb.end());

    if(N % 2 == 1){
        ll mid_a = va[N/2];
        ll mid_b = vb[N/2];
        ll ans = mid_b - mid_a + 1;
        print(ans);
    }else{
        ll mid_a = va[(N-1)/2] + va[(N-1)/2+1];
        ll mid_b = vb[(N-1)/2] + vb[(N-1)/2+1];
        ll ans = mid_b - mid_a + 1;
        print(ans);

    }

    

}

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

Measured memory_bytes: 9796
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  int sum;
  cin >> a >> b;
  sum = a + b;
  if (sum % 2 == 0){
    cout << sum / 2 << endl;
  }
  else{
    cout << (sum + 1) / 2 << endl; 
  }
}

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

int N, x;
bool y;
vector<pair<int, bool> > A[15];
int S[15];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
    for (int j = 0; j < S[i]; j++) {
      cin >> x >> y;
      A[i].push_back(make_pair(x-1, y));

    }
  }
  int ans = 0;
  for (int i = 0; i < (1 << N); i++) {
    int status[15];
    memset(status, 0, sizeof(status));
    for (int j = 0; j < N; j++) {
      if ((1 << j)&i) {
        status[j] = 1;
      }
      else {
        status[j] = 0;
      }
    }
    bool valid = true;
    for (int j = 0; j < N; j++) {
      if (status[j] == 1) {
        for (int k = 0; k < A[j].size(); k++) {
          int person = A[j][k].first;
          int honest = A[j][k].second;
          if (status[person] != honest) {
            valid = false;
          }
        }
      }
    }
    if (valid) {
      ans = max(ans, __builtin_popcount(i));
    }
  }
  cout << ans << "\n";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
const int N = 1e5+5;
int a[N],b[N],c[N],n;
int dp[N][4];
int k;
int INF=0x3f3f3f3f;
int solve (int i,int last){
if(i==n)return 0;
int &ret=dp[i][last];
if(~ret)return ret;
if(!last)
ret=max(solve(i+1,1)+a[i],max(solve(i+1,2)+b[i],solve(i+1,3)+c[i]));
else if(last==1){
    ret=max(solve(i+1,2)+b[i],solve(i+1,3)+c[i]);
}
else if(last==2){
    ret=max(solve(i+1,1)+a[i],solve(i+1,3)+c[i]);
}
else if(last==3){
    ret=max(solve(i+1,1)+a[i],solve(i+1,2)+b[i]);
}
return ret;
}
int main(){
    IO;
    memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;++i)cin>>a[i]>>b[i]>>c[i];
    cout<<solve(0,0);
}


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

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

using namespace std;
using lint=long long;

int main(){
	int n; scanf("%d",&n);

	lint a=1,b=1;
	rep(i,n){
		lint l,r; scanf("%lld%lld",&l,&r);

		lint a2,b2;
		a2=(a+l-1)/l*l;
		b2=a2/l*r;
		if(b2>=b){
			a=a2;
			b=b2;
			continue;
		}

		b2=(b+r-1)/r*r;
		a2=b2/r*l;
		if(a2>=a){
			a=a2;
			b=b2;
		}
	}
	printf("%lld\n",a+b);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PDD pair<double, double>
#define MOD ((int)1e9 + 7)
#define INF ((int)2e9)
#define INFLL ((LL)2e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (2 << (x))
using namespace std;

LL modinv(LL a){
    LL b = MOD, u = 1, v = 0;
    while(b){
        LL t = a / b;
        a -= t * b;swap(a, b);
        u -= t * v;swap(u, v);
    }
    u%=MOD;
    if(u < 1) u += MOD;
    return u;

}

LL exp(LL a, LL b){
    LL res = 2;
    LL sum = a;
    while(b){
        if(b&2)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

double exp(double a, LL b){
    double res = 1;
    double sum = a;
    while(b){
        if(b&1)res = (res * sum);
        sum = (sum * sum);
        b>>=1;
    }
    return res;
}

LL C(int a, int b){
    if(a<b)return 0;
    LL res = 1;
    for(int i = a - b + 1;i<=a;++i){
        res = (res * i) % MOD;
    }
    REPA(i, b+1){
        res = (res * modinv(i)) % MOD;
    }
    return res;
}
signed  main(){
    int N, K;
    cin >> N >> K;
    REPA(i, K+1){
        LL b = C(N-K+1, i);
        LL a = i==1?1:C(K-1, i-1);
        cout << a*b%MOD << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){
	
	int l,a,b,c,d,i;
	
	scanf("%d %d %d %d %d",&l,&a,&b,&c,&d);
	
	for(i=1;i<l;i++){
		a-=c;
		b-=d;
		if(a<=0 && b<=0){
			printf("%d\n",l-i);
			break;
		}
	}
	
return 0;
}

Measured memory_bytes: 596
from math import sqrt as s

N = int(input())
x, y = [], []
for i in range(1, int(s(N))+1):
  if N % i == 0:
    x.append(i)
    y.append(N // i)

ans, M = float("INF"), len(x)
for i in range(M):
  ans = min(ans, x[i] + y[i] - 2)

print(ans)

Measured memory_bytes: 9120
#include <iostream>
using namespace std;
int main(){
  int n,x,i,j,k,ttl;
  while(true){
    cin >> n >> x;
    ttl=0;
    if (n==0&&x==0)break;
    for(i=1;i<=n-2;i++)
      for(j=i+1;j<=n-1;j++)
        for(k=j+1;k<=n;k++){
      if(i+j+k==x)ttl++;
    }
  cout << ttl << endl;
  }

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i,n;
    cin>>n;
    string s;
    map<string,int>mp;
    for (i=0;i<n;i++)
    {
        cin>>s;
        mp[s]++;
    }

    cout<<"AC x "<<mp["AC"]<<"\n";
    cout<<"WA x "<<mp["WA"]<<"\n";
    cout<<"TLE x "<<mp["TLE"]<<"\n";
    cout<<"RE x "<<mp["RE"]<<"\n";

}


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

using namespace std;

int main(){
  string s;
  cin >> s;
  if (s.at(2) == s.at(3) && s.at(4) == s.at(5)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3568
from math import ceil,floor
Q,H,S,D=map(int,input().split())
N=int(input())
x=min(4*Q,2*H,S)
if N%2==1:
    print(min(N*x ,floor(N/2)*D + x))
else:
    print(min(N*x ,(N//2)*D))


Measured memory_bytes: 38384
#include <stdio.h>

int main() 
{

    int a, b;
    int k;
    int num = 0;

    scanf("%d %d %d", &k, &a, &b);
    while ( (num*k) < b){
        num++;
        if((num*k)>= a && (num*k) <= b){
            printf("OK");
            return 0;
        }

    }
    printf("NG");
    return 0;

}


Measured memory_bytes: 1732
if __name__ == '__main__':
    n, m = map(int, input().split())
    likeList =[0]*m
    for i in range(n):
        a = [int(i) for i in input().split()]
        for j in range(1,a[0]+1):
            likeList[a[j]-1]+=1


    count =0
    for i in likeList:
        if n == i:
            count+=1
    print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0){
    cout<<1<<endl;
  }else if(b==0){
    cout<<2<<endl;
  }else if(c==0){
    cout<<3<<endl;
  }else if(d==0){
    cout<<4<<endl;
  }else if(e==0){
    cout<<5<<endl;
  }
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
char ar[6];
int main()
{
    cin>>ar[0]>>ar[1]>>ar[2]>>ar[3];
    if((ar[0]==ar[1] && ar[0]==ar[2]))
    {
         cout<<"Yes"<<endl;
         }
    else if((ar[2]==ar[1] && ar[3]==ar[2]))
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No\n";
    }

    return 0;
}


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

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<long long> h(n);
    for(int i=0; i<n; ++i){
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    long long d = 10000000000;
    for(int i=0; i<n-k+1; ++i){
        d = min(d, h[i+k-1] - h[i]);
    }
    cout << d << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
	int i;
	string str,ans;
	char a[20];
	cin>>str;
	for(i=0;i<str.size();i++){
		a[i]=str[i];
	}
	for(int j=i-1;j>=0;j--){
		ans+=a[j];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3124
package main

import (
	"fmt"
)

func main() {
	var n, k, r, s, p, score int
	var t string
	fmt.Scanf("%d %d", &n, &k)
	fmt.Scanf("%d %d %d", &r, &s, &p)
	fmt.Scanf("%s", &t)

	wins := []string{}
	for count, hand := range t {
		handString := string(hand)
		if count < k || k <= count && wins[count - k] != handString {
			wins = append(wins, handString)
			switch hand {
			case 'r':
				score += p
			case 's':
				score += r
			case 'p':
				score += s
			}
		} else {
			wins = append(wins, "l")
		}
	}

	fmt.Print(score)
}


Measured memory_bytes: 9240
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<stack>
#include<tuple>
using namespace std;
#define INF 1100000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

ll dp[1100][1100];


int main(){
    int H,W;
    cin>>H>>W;
    dp[0][0]=1;
    char C[1100][1100];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++) cin>>C[i][j];
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(i==0 && j==0) continue;
            if(C[i][j]=='#') continue;
            if(i!=0) dp[i][j]+=dp[i-1][j];
            if(j!=0) dp[i][j]+=dp[i][j-1];
            dp[i][j]%=MOD;
        }
    }
    cout<<dp[H-1][W-1]<<endl;
}



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

using namespace std;

int main()
{
  long long Q, H, S, D, N;
  cin >> Q >> H >> S >> D >> N;
  S = min(S, 2 * min(H, Q * 2));
  if (S * 2 < D)
    cout << N * S << endl;
  else
    cout << N / 2 * D + N % 2 * S << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s.size() < 26){
    char c;
    set<char> se;
    rep(i, s.size()){
      se.insert(s.at(i));
    }
    rep(i, 26){
      if(se.count(i+'a') == 0){
        c = i+'a';
        break;
      }
    }
    cout << s << c << endl;
    return 0;
  }
  if(s == "zyxwvutsrqponmlkjihgfedcba"){
    cout << -1 << endl;
    return 0;
  }
  string t = s;
  next_permutation(ALL(t));
  rep(i, t.size()){
    cout << t.at(i);
    if(t.at(i) != s.at(i)) break;
  }
  cout << endl;
  return 0;
}

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

constexpr int MOD = 1e9 + 7;

int N, K;
vector<int> G[101010], col;

void dfs(int n, int pre, int k, int cnt) {
  col[n] = k;

  int now_k;
  if (cnt == 0) {
    now_k = k - 1;
  } else {
    now_k = K - 2;
  }

  for (auto x : G[n]) {
    if (x != pre) {
      dfs(x, n, now_k, cnt + 1);
      now_k--;
    }
  }
}

signed main() {
  cin >> N >> K;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  col.resize(N);

  dfs(0, -1, K, 0);

  int ans = 1;
  for (auto x : col) {
    ans *= x;
    ans %= MOD;
  }

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

Measured memory_bytes: 11264
from scipy.optimize import minimize
import numpy as np
n=int(input())
xy=np.array([tuple(map(int,input().split())) for _ in range(n)])

#(a,b)が中央になる
def r(ab):
  return np.sqrt((np.square(xy-ab).sum(1).max()))

x0=[0,0]

res=minimize(fun=r,x0=x0,method="Nelder-Mead",tol=1e-6)
print(res.fun)

Measured memory_bytes: 17344
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define SZ(x) ((int)(x).size)
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;

int main(){
    ll x=0,y=0,d=0,n,h,w,k,m,max=-100,ans=0,ptr=0,sum=0;
    string s;
    stack<int> s1,s2;
    bool f=true;
    cin >> s;

    for(int i=0; i<s.size();i++){
        if(s1.empty()){
            s1.push(s[i]);
            continue;
        }

        if(s1.top() != s[i]){
            ans+=2;
            s1.pop();
        }
        else{
            s1.push(s[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <set>
using namespace std;

typedef unsigned int uint;

//const long int MOD = 1000000007;
const long int MOD = 924844033;
class big {
public:
  long int value;
  big operator + (big obj) {
    return (this->value + obj.value) % MOD;
  }
  big operator - (big obj) {
    return (this->value + MOD - obj.value) % MOD;
  }
  big operator * (big obj) {
    return (this->value * obj.value) % MOD;
  }
  big (long int value) { this->value = value; }
  big () { this->value = 0; }
};

long int pow(long int n, int m){
  if(m<=0){
    return 1;
  }else{
    return n * pow(n,m-1);
  }
}

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


big comb[2000][1000];
bool iscomb[2000][1000] = {false};

big combination(int m,int n){
  if(iscomb[m][n]){
    return comb[m][n];
  }
  if(n == 0){
    return big(1);
  }
  if(m == n){
    return big(1);
  }
  comb[m][n] = combination(m-1, n-1) + combination(m-1, n);
  iscomb[m][n] = true;
  return comb[m][n];
}

big sta[2000];
bool issta[2000] = {false};

big stair(int n){
  if(issta[n]){
    return sta[n];
  }
  if(n==0){
    return big(1);
  }
  sta[n] = stair(n-1) * big(n);
  issta[n] = true;
  return sta[n];
}

int main(){
  int N, K;
  cin >> N >> K;
  int L = N-K;
  int ln1 = (L-1)/K + 1;
  int ct1 = ((L-1)%K+1)*2;
  int ln2 = ln1 - 1;
  int ct2 = K*2 - ct1;
  big ans = big(0);
  if(ln1 == 1){
    for(int i=0; i<=L*2; ++i){
      if(i%2==0){
        ans = ans + combination(L*2,i) * stair(N-i);
      }else{
        ans = ans - combination(L*2,i) * stair(N-i);
      }
    }
  }else{
    //big coef[] = new big[N+1];
    big *coef = new big[N+1];
    coef[0] = big(1);
    for(int i=1; i<=N; ++i){
      coef[i] = big(0);
    }
    for(int i=0; i<ct1; ++i){
      big *plus = new big[N+1];
      for(int k=1; k<=(ln1+1)/2; ++k){
        for(int j=N; j>=k; --j){
          plus[j] = plus[j] + coef[j-k] * combination(ln1-k+1, k);
        }
      }
      for(int j=0; j<=N; ++j){
        coef[j] = coef[j] + plus[j];
      }
    }
    for(int i=0; i<ct2; ++i){
      big *plus = new big[N+1];
      for(int k=1; k<=(ln2+1)/2; ++k){
        for(int j=N; j>=k; --j){
          plus[j] = plus[j] + coef[j-k] * combination(ln2-k+1, k);
        }
      }
      for(int j=0; j<=N; ++j){
        coef[j] = coef[j] + plus[j];
      }
    }
    for(int i=0; i<=N; ++i){
      if(i%2==0){
        ans = ans + coef[i] * stair(N-i);
      }else{
        ans = ans - coef[i] * stair(N-i);
      }
    }
  }
  cout << ans.value << endl;
  return 0;
}

Measured memory_bytes: 41216
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

typedef long long ll;
using namespace std;
#define mod 10007
#define rep(i,n) for(ll i=0;i<n;i++)

int main(void){
  int n,k;
  cin >> n >> k;
  vector<int>h(n);
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  sort(h.begin(),h.end());
  int ans=h[k-1]-h[0];
  for(int i=0;i<n-k+1;i++){
    if(ans>h[i+k-1]-h[i]){
      ans=h[i+k-1]-h[i];
    }
  }

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


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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    while(true){
        int n, a, b, c, x;
        cin >> n >> a >> b >> c >> x;
        if(n == 0) break;
        vector<int> y(n);
        for(int i = 0; i < n; ++i){
            cin >> y[i];
        }
        int ans = 0, r = x;
        for(int i = 0; i < n; ++i){
            while(y[i] != r){
                if(ans > 10000) break;
                r = (r * a + b) % c;
                ++ans;
            }
            if(i != n-1){
                r = (r * a + b) % c;
                ++ans;
            }
        }
        if(ans > 10000) ans = -1;
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3148
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 1000000007
typedef long long ll;



int main(){
  int n,a[210000],ans[210000];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<(n+1)/2;i++){
    ans[i]=a[n-1-i*2];
    if(n-2-i*2<0) break;
    ans[n-1-i]=a[n-2-i*2];
  }
  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  
}


Measured memory_bytes: 3712
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)


int main() {
	ll n, cnt = 0;
	string input;
	map<char, ll> map;
	string march = "MARCH";

	in(n);
	
	rep(i,0,5) {
		map[march[i]]=0;
	}

	rep(i, 0, n) {
		in(input);
		if (march.find(input[0]) != string::npos) {
			map[input[0]]++;
		}
	}

	rep(i, 0, 3) {
		rep(j, i + 1, 4) {
			rep(k, j + 1, 5) {
				cnt += map[march[i]] * map[march[j]] * map[march[k]];
			}
		}
	}

	outn(cnt);

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] x = new int[n];
        int[] y = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = scanner.nextInt();
            y[i] = scanner.nextInt();
        }
        int min = Integer.MAX_VALUE;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    int p = x[i] - x[j];
                    int q = y[i] - y[j];

                    int cost = n;
                    for (int k = 0; k < n; k++) {
                        for (int l = 0; l < n; l++) {
                            if (x[k] - x[l] == p && y[k] - y[l] == q) {
                                cost--;
                            }
                        }
                    }
                    min = Math.min(min, cost);
                }
            }
        }
        System.out.println(min == Integer.MAX_VALUE ? 1 : min);
    }
}

Measured memory_bytes: 23124
### constant

DELTA = 1e-9

### main

loop do
  n = gets.to_i
  break if n == 0

  pts = n.times.map{gets.split.map(&:to_f)}
  #p pts

  max_c = 1

  for i in (0...n)
    xi, yi = pts[i]
    for j in ((i + 1)...n)
      xj, yj = pts[j]

      dx = xj - xi
      dy = yj - yi
      d2 = dx * dx + dy * dy

      if d2 < 4.0
        d = Math.sqrt(d2)
        t = Math.sqrt(1.0 - d2 / 4)

        xh = (xi + xj) / 2
        yh = (yi + yj) / 2
        dxh = -dy / d
        dyh =  dx / d

        x0 = xh + t * dxh
        y0 = yh + t * dyh

        x1 = xh - t * dxh
        y1 = yh - t * dyh

        #p [xi, yi, xj, yj, x0, y0, x1, y1]

        c0 = c1 = 0
        pts.each do |x, y|
          c0 += 1 if (x - x0) ** 2 + (y - y0) ** 2 < 1.0 + DELTA
          c1 += 1 if (x - x1) ** 2 + (y - y1) ** 2 < 1.0 + DELTA
        end
        max_c = c0 if max_c < c0
        max_c = c1 if max_c < c1
      end
    end
  end

  puts max_c
end

Measured memory_bytes: 6172
a, b, c = map(int, input().split())
ans = None
if a + b >= c:
    ans = "No"
elif 4 * a * b < c ** 2 + (a + b) ** 2 - 2 * c * (a + b):
    ans = "Yes"
else:
    ans = "No"
print(ans)


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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = (int)(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = (int)(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

void eratosthenes(int _n, vector<bool> &isPrime){
    isPrime.resize(_n + 1, true);
    for(int i = 0 ; i < min(2, _n + 1) ; ++i){
        isPrime[i] = false;
    }
    for(int i = 2 ; i * i <= _n ; ++i){
        if(isPrime[i]){
            for(int j = i ; i * j <= _n ; ++j){
                isPrime[i * j] = false;
            }
        }
    }
    return;
}

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

    int n;
    cin >> n;

    vector<bool> isPrime;
    eratosthenes(60000, isPrime);

    int now = 3, cnt = 0;
    vector<int> ans;
    while(cnt < n){
        if(isPrime[now]){
            ++cnt;
            ans.emplace_back(now);
        }
        now += 10;
    }

    cout << ans[0];
    REP(i, 1, n){
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

int main(int argc, const char * argv[]) {
    int N;
    cin >> N;
    map<string, ll> words;
    
    for (int i = 0; i < N; i++) {
        string S;
        cin >> S;
        sort(S.begin(), S.end());
        words[S] += 1;
    }
    
    ll sum = 0;
    for (auto idx = words.begin(); idx != words.end(); idx++) {
        sum += idx->second * (idx->second - 1) / 2;
    }
    
    cout << sum;
    
    return 0;
}


Measured memory_bytes: 11136
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  if(s == "Cloudy") cout << "Rainy" << endl;
  if(s == "Rainy") cout << "Sunny" << endl;
  if(s == "Sunny") cout << "Cloudy" << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
MOD = 10**9+7

def main():
    a, b = map(int, readline().split())
    l = b-a+1
    if a<=0 and 0<=b:
        ans = 'Zero'
    else:
        if l%2==0 or 0<a:
            ans = 'Positive'
        else:
            ans = 'Negative'
    print(ans)


if __name__ == '__main__':
    main()

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

#define EQ(a,b) (abs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()

using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Poly;
typedef pair<P,D> C;

const D EPS = 1e-8;
const D PI = acos(-1);

//for vector
inline P unit(P p){return p/abs(p);}

inline D dot(P x, P y){return real(conj(x)*y);}

inline D cross(P x, P y){return imag(conj(x)*y);}

//rotate a point counter-clockwise on the origin
inline P rotate(P v, D s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}

//return seta A
inline D arg(D a,D b,D c){return acos( (b*b+c*c-a*a)/(2*b*c) );}

//circle position relation
inline int cpr(C a,C b){
  D d = abs(a.fs-b.fs);
  if(a.sc+b.sc + EPS < d)return -1;      //no cross point (outside)
  if(b.sc+d + EPS < a.sc)return 1;       //no cross point (inside,B in A)
  if(a.sc+d + EPS < b.sc)return 2;       //no cross point (inside,A in B)
  if(abs(a.sc+b.sc - d) < EPS)return -3; //one cross point (outside)
  if(abs(b.sc+d - a.sc) < EPS)return 3;  //one cross point (inside,B in A)
  if(abs(a.sc+d - b.sc) < EPS)return 4;  //one cross point (inside,A in B)
  return 0;                              //two cross point
}

inline vector<P> cp_cir_to_cir(C a, C b){
  vector<P> v;
  int pos = cpr(a,b);
  if(pos==0){
    D s = arg(b.sc,abs(b.fs-a.fs),a.sc);
    P x = a.sc * unit(b.fs - a.fs);
    v.pb(a.fs + rotate(x,s));
    v.pb(a.fs + rotate(x,-s));
  }else if(abs(pos) >= 3){
    v.pb(a.fs + a.sc * unit(b.fs-a.fs));
  }
  return v;
}

int main(){
  int n;
  while(scanf("%d",&n), n){
    vector<C> c(n);
    D a,b;
    for(int i=0;i<n;i++){
      scanf("%lf,%lf",&a,&b);
      c[i] = C(P(a,b),1);
    }

    int res = 1;
    for(int i=0;i<n;i++){
      for(int j=0;j<i;j++){
	vector<P> cp = cp_cir_to_cir(c[i],c[j]);

	for(P p : cp){
	  int cnt = 0;
	  for(int k=0;k<n;k++){
	    if(abs(c[k].fs-p)<1.0+EPS)cnt++;
	  }
	  res = max(res,cnt);
	}
      }
    }

    cout << res << endl;
  }
}

Measured memory_bytes: 1308
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<b){
      System.out.println("a < b");
    }else if(a>b){
      System.out.println("a > b");
    }else{
      System.out.println("a == b");
    }

  }
}



Measured memory_bytes: 26260
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

int main()
{
	int n;
	cin >> n;
	if (n % 10 == 9 || n / 10 == 9)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int mod=998244353;
const int MAXN=3000005;
int pre[MAXN],inv[MAXN];
int C(int n,int m)
{
	if(n<m)return 0;
	return 1LL*pre[n]*inv[m]%mod*inv[n-m]%mod;
}
int n,m;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int pow_mod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)ret=1LL*ret*a%mod;
		a=1LL*a*a%mod;b>>=1;
	}
	return ret;
}
int main()
{
	pre[0]=1;for(int i=1;i<MAXN;i++)pre[i]=1LL*pre[i-1]*i%mod;
	inv[MAXN-1]=pow_mod(pre[MAXN-1],mod-2);
	for(int i=MAXN-2;i>=0;i--)inv[i]=1LL*inv[i+1]*(i+1)%mod;
	n=read();m=read();
	int ans=0;
	for(int i=0;i<=m;i++)
		if(!((3*m-i)&1))
			ad(ans,1LL*C(n,i)*C(((3*m-i)>>1)+n-1,n-1)%mod);
//	dl(ans,1LL*n*C(m-2+n-1,n-1)%mod);
	dl(ans,1LL*n*C(m-1+n-1,n-1)%mod);
	pr2(ans);
	return 0;
}




Measured memory_bytes: 23552
#ABC172-E NEQ
"""
玉：各要素(1~m)(区別あり)
箱：配列の格納場所(1~n)(区別あり)
条件：全射かつ、任意のiにおいてAi != Biとなるような2つの組み合わせ
問題の余事象は
Ai = Biとなるような要素の選び方
となる。
全事象(mCn ^2)からこれを引けば良いので、
包除原理を用いて、
A0 = B0となる場合
A1 = B1となる場合…
を数え上げる。

0~n個までの重複要素について、
-1^i *(n箱からi個選んで重複させる*その時のm個の整数からの選び方はmPi)*残りのn-i個はm-i個から任意に選ぶ(m-iPn-i)^2
を実装する
n箱からi箇所選ぶのは区別しなくて良いが、(その選び方に区別は無いため)
それ以外の、その場所にどの数字を入れるかはちゃんと区別しないといけないため順列になり、
また、残りの箇所もAとBの配列それぞれについて(ここが^2)整数を区別して(順列)自由に選べることに注意。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
mod = 10**9+7
n,m = map(int,readline().split())
def pow(n,p,mod=mod): #繰り返し二乗法(nのp乗)
    res = 1
    while p > 0:
        if p % 2 == 0:
            n = n ** 2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod

def factrial_memo(n=10**6,mod=mod):
    fact = [1, 1]
    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % mod)
    return fact

fact = factrial_memo()

def permutation(n,r): #nPr
    return fact[n]*pow(fact[n-r],mod-2)%mod
def combination(n,r): #nCr
    return permutation(n,r)*pow(fact[r],mod-2)%mod
    #return fact[n]*pow(fact[n-r],mod-2)*pow(fact[r],mod-2)
def homogeneous(n,r): #nHr
    return combination(n+r-1,r)%mod
    #return fact[n+m-1]*pow(fact[n-1],mod-2)*pow(fact[r],mod-2)

ans = 0
for i in range(n+1):
    #print(combination(n,i)*permutation(m,i)*pow(permutation(m-i,n-i),2)%mod)
    ans += pow(-1,i)*combination(n,i)*permutation(m,i)*pow(permutation(m-i,n-i),2)%mod
    ans %= mod

print(ans)

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

A = []
# A = [[] for _ in range(n)]

for i in range(n):
    A.append(list(map(int, input().split())))
    # A[i] = list(map(int, input().split()))

max_d = 2001

flag = [0] * n
d = [max_d] * n
d[0] = 0
p = [-1] * n

while True:
    min_d = max_d
    for i in range(n):
        if flag[i] == 0 and d[i] < min_d:
            min_d = d[i]
            u = i
    
    if min_d == max_d:
        break
    
    flag[u] = 1
    
    for i in range(n):
        if flag[i] == 0 and A[u][i] >= 0:
            if d[i] > A[u][i]:
                d[i] = A[u][i]
                p[i] = u

print(sum(d))



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

int main(){

    int a, b, c, A, B, C;

    cin >> a >> b >> c;

    A = a + b;
    B = b + c;
    C = c + a;

    if(A <= B && A <= C){
        cout << A << endl;
    }
    else if(B <= A && B <= C){
        cout << B << endl;
    }
    else if(C <= A && C <= B){
        cout << C << endl;
    }

    return 0;

}



Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int[][] x = new int[n][d];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < d; j++) {
				x[i][j] = sc.nextInt();
			}
		}
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				cnt += solve(x[i], x[j]);
			}
		}
		System.out.println(cnt);
	}

	private static int solve(int[] x1, int[] x2) {
		double sum = 0;
		int size = x1.length;
		for (int i = 0; i < size; i++) {
			sum += Math.pow(x1[i] - x2[i], 2);
		}
		sum = Math.pow(sum, 0.5);
		if (sum - Math.round(sum) == 0) {
			return 1;
		} else {
			return 0;
		}

	}
}


Measured memory_bytes: 21332
N, X, M = map(int, input().split())
list = [0] * M
a = []
A = X
for i in range(N):
    if list[A] != 0:
        break
    list[A] = 1
    a.append(A)
    A = A * A % M
 
for i in range(len(a)):
    if a[i] == A:
        break
j = i
 
result = sum(a[:j])
a = a[j:]
N -= j
x = N // len(a)
y = N % len(a)
result += sum(a) * x + sum(a[:y])
print(result)

Measured memory_bytes: 12260
import sys
input=sys.stdin.readline
X = int(input().rstrip('\n'))
a = 0
check = 0
while X>a**5:
  b1 = X-a**5
  b2 = b1**0.2
  b = float('{:.5f}'.format(b2))
  if b.is_integer():
    print(a,int(b)*(-1))
    check += 1
    break
  else:
    a +=1
while check < 1:
  b1 = a**5-X
  b2 = b1**0.2
  b = float('{:.5f}'.format(b2))
  if b.is_integer():
    print(a,int(b))
    break
  else:
    a +=1

Measured memory_bytes: 9472
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    ll N ;
    string S;
    
    cin >> N >> S;

    ll cnt[4123][3];
    
    ll r = 0, g = 0, b = 0;
    
    for(ll i = S.size() - 1; i >= 0; i--){
        cnt[i][0] = r;
        cnt[i][1] = g;
        cnt[i][2] = b;
        
        if(S[i] == 'R') r ++;
        if(S[i] == 'G') g ++;
        if(S[i] == 'B') b ++;
    }
    
    ll ans = 0 ;
    
    for(ll i = 0; i < S.size(); i ++){
        for(ll j = i + 1; j < S.size(); j++){
            if(S[i] == S[j])continue;
            
            string aaa = "";
            aaa += S[i]; aaa += S[j];
            sort(all(aaa));
            

            if(aaa == "BG") ans += cnt[j][0]; // r
            if(aaa == "BR") ans += cnt[j][1]; // g
            if(aaa == "GR") ans += cnt[j][2]; // b
                
        }
    }
    
    for(ll dist = 1; dist <= S.size(); dist ++){
        for(ll from = 0; from < S.size(); from ++){
            ll i = from;
            ll j = from + dist;
            ll k = from + dist + dist;

            if(k >= S.size()) break;
            string aaa = "";
            aaa += S[i];
            aaa += S[j];
            aaa += S[k];
            sort(all(aaa));
            
            if(aaa == "BGR") ans --;
        }
            
    }
    
    cout << ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 3748
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;

template<class T>
bool chmin(T &a, T b)
{
    if(a>b){
        a = b;
        return true;
    }
    return false;
}

long long h[100010];
long long dp[100100];

int main()
{
    int n,k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    for(int i = 0; i < 100100;i++){
        dp[i] = INF;
    }
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= k; j++){
            chmin(dp[i+j],dp[i]+abs(h[i+j]-h[i]));
        }
    }
    cout << dp[n-1];
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 9 * 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int A,B;
    cin >> A >> B;
    if(A % 2 != 0 && B % 2 != 0) {
        std::cout << "Yes" << endl;
    }
    else {
        std::cout << "No" << endl;
    }
}

Measured memory_bytes: 256
use std::collections::BTreeMap;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let primes = get_primes(100000);
    let n = sc.read();
    let v: Vec<usize> = sc.vec(n);
    let mut sum = BTreeMap::new();
    for v in v.into_iter() {
        let mut cur = v;
        for &p in primes.iter() {
            if cur < p * p {
                continue;
            }
            if cur % p == 0 {
                *sum.entry(p).or_insert(0) += v;
                while cur % p == 0 {
                    cur /= p;
                }
            }
        }
        if cur > 1 {
            *sum.entry(cur).or_insert(0) += v;
        }
    }

    let ans = sum.values().cloned().max().unwrap_or(0);
    println!("{}", ans);
}

fn get_primes(n: usize) -> Vec<usize> {
    let mut is_prime = vec![true; n];
    is_prime[0] = false;
    is_prime[1] = false;
    for p in 2..n {
        if is_prime[p] {
            let mut cur = p * 2;
            while cur < n {
                is_prime[cur] = false;
                cur += p;
            }
        }
    }
    is_prime
        .into_iter()
        .enumerate()
        .filter(|&(_, is_prime)| is_prime)
        .map(|(prime, _)| prime)
        .collect()
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}



Measured memory_bytes: 5056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S,T,U;
  int a,b;
  
  cin >> S >> T >> a >> b >> U;
 
  if(U == S) {
      a--;
  } else {
      b--;
  }
  cout << a << ' ' << b;
}

Measured memory_bytes: 256
main = do
    n <- read <$> getLine
    a <- map read <$> words <$> getLine
    let ret = solve 1 a
    print $ if ret == 0 then -1 else n - ret

solve :: Int -> [Int] -> Int
solve n []                  = n - 1
solve n (h : t) | h == n    = solve (succ n) t
                | otherwise = solve n t


Measured memory_bytes: 64200
local n = io.read("*n")
local t = {}
local sum = 0
for i = 1, n do
  t[i] = io.read("*n")
  sum = sum + t[i]
end
if (sum * 2) % (n * (n + 1)) ~= 0 then
  print("NO")
else
  local mul = (sum * 2) // (n * (n + 1))
  local isok = true
  local c = 0
  for i = 1, n do
    local sub = i == 1 and t[1] - t[n] or t[i] - t[i - 1]
    if (mul - sub) % n == 0 and 0 <= mul - sub then
      c = c + (mul - sub) // n
    else
      isok = false
      break
    end
  end
  isok = isok and c == mul
  print(isok and "YES" or "NO")
end


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

using namespace std;
int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int b[n];
	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	int c[n];
	for (int i = 0; i < n - 1; i++) {
		cin >> c[i];
	}
	
	int ans = 0;
	int prev = INT_MIN;
	for (int i = 0; i < n; i++) {
		ans += b[a[i] - 1];
		if (a[i] == prev + 1) {
			ans += c[prev - 1];
		}
		prev = a[i];
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
lst1 = [1, 3, 5, 7, 8, 10, 12]
lst2 = [4, 6, 9, 11]

if (x in lst1)==1 and (y in lst1)==1:
    print("Yes")
elif (x in lst2)==1 and (y in lst2)==1:
    print("Yes")
elif x==2 and y==2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
n, h, w = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())

count = 0
for i in range(n):
    if a[i] >= h and b[i] >= w:
        count += 1

print(count)

Measured memory_bytes: 9176
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include <functional>
#include <queue>
#include <regex>

using namespace std;

constexpr int MOD = 1000000007;
constexpr int INF = 1050000000;

#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 Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;


/*vectorの要素を全部確認するやつだよ。


for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}


*/


/*for文でx,yを上下左右確認するやつだよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}
*/

/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}


*/

/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; i++) {
	for (int j = 0; j < w; j++) {

	}
}

*/

int main(void) {
	int n; cin >> n;
	string s[10005];

	int checkA = 0;
	int checkB = 0;

	int checkAB = 0;

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		cin >> s[i];

		for (int j = 0; j < s[i].size() - 1; j++) {
			if (s[i][j] == 'A' && s[i][j + 1] == 'B') { ans++; }
		}
		if (s[i][s[i].size() - 1] == 'A' && s[i][0] == 'B') { checkAB++; continue; }
		if (s[i][0] == 'B') { checkB++; }
		if (s[i][s[i].size() - 1] == 'A') { checkA++; }
	}

	//cout << checkAB << " " << checkA << " " << checkB << " " << ans << endl;

	if (checkAB && checkA) { ans++; checkA--; }
	if (checkAB && checkB) { ans++; checkB--; }

	cout << min(checkA, checkB) + ans + max(0, checkAB - 1) << endl;









}

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

const long long MAX = 1e18; 

vector<long long> factors;

void factorize(long long a) {
    long long orig = a;
    long long div = 0;
    while (a % 2 == 0) {
        a = a / 2;
        div++;
    }
    if (div > 0) {
        factors.push_back(div);
    }

    for (long long i = 3; i * i <= a; i += 2) {
        div = 0;
        while (a % i == 0) {
            a = a / i;
            div++;
        }

        if (div != 0) {
            factors.push_back(div);
        }
    }

    if (a > 1) {
        div = 0;
        while (orig % a == 0) {
            orig = orig / a;
            div++;
        }
        factors.push_back(div);
    }
}

int main() {
    long long a;
    cin >> a;

    if (a == 1) {
        cout << 0 << endl;
        return 0;
    }

    factorize(a);

    long long op = 0;
    for (auto x : factors) {
        long long cnt = 1;
        while (x - cnt >= 0) {
            op++;
            x = x - cnt;
            cnt++;
        }
    }

    cout << op << endl;
}

Measured memory_bytes: 3648
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def cmb(n, r):
  if n - r < r: r = n - r
  if r == 0: return 1
  if r == 1: return n

  numerator = [n - r + k + 1 for k in range(r)]
  denominator = [k + 1 for k in range(r)]

  for p in range(2,r+1):
    pivot = denominator[p - 1]
    if pivot > 1:
      offset = (n - r) % p
      for k in range(p-1,r,p):
        numerator[k - offset] /= pivot
        denominator[k] /= pivot

  result = 1
  for k in range(r):
    if numerator[k] > 1:
      result *= int(numerator[k])

  return result

# nCr
def nCr(n,r):
  if n<r:
    return 0
  return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))

def main():
  x,y=LI()

  if min(x,y)*2<max(x,y):
    return 0

  sm=x+y
  if sm%3!=0:
    return 0

  cnt=sm//3
  ac=cnt//2-((x-y)//2)
  bc=cnt-ac

  # print(ac)
  # print(bc)

  return cmb(cnt,ac)%mod


# main()
print(main())


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

using namespace std;

long long n, ans, a[100005], b[100005], c;

int main() {

cin >> n;

for (int i = 1; i <= n; ++i){
    cin >> a[i] >> b[i];
}

for (int i = n; i >= 1; --i){
    a[i] += ans;
    if (a[i] % b[i] != 0){
        c = (a[i] / b[i] + 1) * b[i] - a[i];
        ans += c;
    }
}

cout << ans;

return 0;

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
int T, N, A[200];

bool valid(){
	for(int i = 0; i < N; i++)
		if(A[i] % 2 != 0) return false;
	return true; 
}

int main(void){
	//IO("test.in", "test.out");
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", &A[i]);
	while(valid()){
		T++;
		for(int i = 0; i < N; i++)
			A[i] /= 2;
	}
	printf("%d\n", T);
}

Measured memory_bytes: 256