akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(long long i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define rrep(i,n) for(long long i=int(n);i>0;i--)
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+5  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
using PPI=pair<P,int>;
//ll const mod=998244353;
ll const mod=1e9+7;
const ll MAX=1000005;
using vi=vector<int>;
using vl=vector<ll>;
using vc=vector<char>;
using vd=vector<double>;
using vs=vector<string>;
using vp=vector<P>;
using vb=vector<bool>;
using vvi =vector<vector<int>>;
using vvl =vector<vector<ll>>;
using vvd=vector<vector<double>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;
using vvb=vector<vector<bool>>;
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}


int main(){
    int n,m;
    cin>>n>>m;
    vp b(n);
    b[0].sc=1;
    rep(i,n)b[i].fs=1;
    rep(i,m){
        int x,y;
        cin>>x>>y;
        x--,y--;
        b[x].fs--;
        b[y].fs++;
        if(b[x].sc==1){
            b[y].sc=1;
        }
        if(b[x].fs==0){
            b[x].sc=0;
        }
    }
    int ans=0;
    rep(i,n){
        ans+=b[i].sc;
    }
    cout<<ans<<endl;
    return 0;
}

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

void print(vector<int> &v){
    vector<int>::iterator ite = v.begin();
    while(ite != v.end()){
        cout << *ite << endl;
        ite++;
    }
}

int insSort(vector<int> &v, int g){
    int i, j, x, n = v.size(), cnt = 0;
    for(i = g; i < n; i++){
        x = v[i];
        j = i - g;
        while(j >= 0 && v[j] > x){
            v[j+g] = v[j];
            cnt++;
            j -= g;
        }
        v[j+g] = x;
    }
    return cnt;
}

void makeG(vector<int> &v,int n){
    for(int i = 1; ;){
        if(i > n) break;
        v.push_back(i);
        i = 3*i + 1;
    }
}

void shellSort(vector<int> &v){
    int i, cnt = 0;
    vector<int> g;
    makeG(g, v.size());
    int gs = g.size();
    cout << gs << endl;
    for(i = gs - 1; i >= 0; i--){
        if(i != gs - 1)
            cout << " ";
        cout << g[i];
        cnt += insSort(v, g[i]);
    }
    cout << endl <<  cnt << endl;
}

int main(){
    int n, x, i;
    vector<int> v;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> x;
        v.push_back(x);
    }
    shellSort(v);
    print(v);
    return 0;
}

Measured memory_bytes: 7256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int pre[3][4010],a[4010];
ll n,ans,i,j,k;

int main(){
    string s;
    cin>>n>>s;
    s=" "+s;
    
    for(i=1;i<=n;i++){
        if(s[i]=='R') a[i]=0;
        if(s[i]=='G') a[i]=1;
        if(s[i]=='B') a[i]=2;
    }
    
    for(i=n;i>=1;i--){
        pre[a[i]][i]=pre[a[i]][i+1]+1;
        pre[(a[i]+1)%3][i]=pre[(a[i]+1)%3][i+1];
        pre[(a[i]+2)%3][i]=pre[(a[i]+2)%3][i+1];
    }
    
    for(i=1;i<=n-2;i++)
    for(j=i+1;j<=n-1;j++){
        if(a[i]==a[j]) continue;
		
		int pos;  
        for(k=0;k<=2;k++)
        if(k!=a[i]&&k!=a[j]){
            pos=k;
            break;
        }
        
        ans+=pre[pos][j+1];
    }
    
    for(i=1;i<=n-2;i++)
    for(j=i+1;j<=n-1;j++){
        int pos=2*j-i;
        if(pos>n||pos<=0) break;
        if(a[i]!=a[j] && a[i]!=a[pos] && a[j]!=a[pos]) ans--;
    }
    
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
 
using namespace std;
 
long long n, t[5000], x, y, m, ans, f[5000], q[5000];
 
int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0;i < n-1;i++){
		cin >> t[i];
	}
	ans+=t[0];
	for(int i = 1;i < n;i++){
		ans+=min(t[i], t[i-1]);
		//cout << ans << endl;
	}
	ans+=t[n-2];
	cout << ans << endl;
}

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

int main() {
  int n, m;cin >> n >> m;
  int out = (n*(n-1) + m*(m-1))/2;
  if(n==0) out = m*(m-1)/2;
  if(m==0) out = n*(n-1)/2;
  cout << out;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n, q;
    cin >> n >> q;
    
    v_int a(n), b(n);

    irep(i, n-1) {
        cin >> a[i] >> b[i];
    }
    a[n-1] = 0; b[n-1] = 1;
    
    map<int, int> cost;
    irep(i, q) {
        int c, d;
        cin >> c >> d;
        cost[c] += d;
    }
    
    v2_int g(n+1);
    irep(i, n) {
        g[a[i]].push_back(b[i]);
        g[b[i]].push_back(a[i]);
    }
    
    queue<int> que;
    v_int dist(n+1, INF);
    que.push(0);
    dist[0] = 0;
    
    while(que.size()) {
        int node = que.front(); que.pop();
        
        irep(i, g[node].size()) {
            int next = g[node][i];
            if(dist[next] != INF) { continue; }
            que.push(next);
            dist[next] = dist[node] + cost[next];
        }
    }
    
    irep2(i, 1, n) {
        cout << dist[i] << endl;
    }
    return 0;
}


/*atcoder*/


Measured memory_bytes: 27432
#include<iostream>

using namespace std;

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


Measured memory_bytes: 3068
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

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

pii A[200000];

int main() {
    int n, m; cin >> n >> m;
    for(int i = 0; i < n; ++i)
        cin >> A[i].first, A[i].second = 1;

    for(int i = 0; i < m; ++i)
        cin >> A[i + n].second >> A[i + n].first;
    
    sort(A, A + n + m);
    
    ll mx = 0;
    int rx = 0;
    int j = n + m - 1;
    while(rx < n) {
        mx += (ll) min(n - rx, A[j].second) * A[j].first;
        rx += A[j].second;
        j -= 1;
    }
    
    cout << mx;
    
    return 0;
}

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

int n;
int y;
int main(){
  cin >> n >> y;

  bool ans=false;
  int a=-1, b=-1, c=-1;
  for(int i=0; i<=n; i++){
    for(int j=0; j<=n; j++){
      if(i+j>n) continue;
      if(10000*i+5000*j+1000*(n-i-j)==y){
        a=i; b=j; c=n-i-j;
        ans=true;
        break;
      }
      if(ans)break;
    }
    if(ans)break;
  }

  cout << a << " " << b <<  " " << c << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
  { int n,r;
   cin>> n >> r; 
   if(n>=10)
     cout<< r ;
   else 
    { r=r+100*(10-n); 
   cout<< r ;} 
 return 0;  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

struct Set {
  multiset<LL> st;
  LL off;

  void Add(LL v) {
    off += v;
  }

  LL L(void) {
    return off + *st.begin();
  }

  LL R(void) {
    return off + *st.rbegin();
  }

  void Insert(LL v) {
    st.insert(v-off);
  }

  void Erase(LL v) {
    v -= off;
    auto itr = st.find(v);
    assert(itr != st.end());
    st.erase(itr);
  }

  void Show() {
    for (LL v : st) {
      printf("%lld ", v+off);
    }
    puts("");
  }
};

int N;
LL L[114514];
LL R[114514];
LL W[114514];
Set sw[2];

int main() {
  scanf("%d", &N);
  rep(i, N) {
    scanf("%lld%lld", &L[i], &R[i]);
    W[i] = R[i] - L[i];
  }

  rep(i, 2) sw[i].Insert(L[0]);

  LL ans = 0;
  reps(i, 1, N) {
    sw[0].Add(-W[i]);
    sw[1].Add(W[i-1]);

    //printf("After Adjust\n");
    //rep(j, 2) { 
    //  sw[j].Show();
    //}

    LL x = sw[0].R();
    LL y = sw[1].L();
    if (L[i] < x) {
      ans += x-L[i];
    } else if (y < L[i]) {
      ans += L[i]-y;
    }

    sw[0].Insert(L[i]);
    sw[0].Insert(L[i]);
    while (sw[0].R() > sw[1].L() || sw[0].st.size() > sw[1].st.size()) {
      LL v = sw[0].R();
      sw[0].Erase(v);
      sw[1].Insert(v);
    }

    while (sw[0].st.size() < sw[1].st.size()) {
      LL v = sw[1].L();
      sw[1].Erase(v);
      sw[0].Insert(v);
    }

    //printf("After %d L=%lld R=%lld ans=%lld:\n", i, L[i], R[i], ans);
    //rep(j, 2) { 
    //  sw[j].Show();
    //}
    assert(sw[0].st.size() == sw[1].st.size());
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
typedef long long LL;
int read()
{
    char c=getchar();int f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
int r,c,n;
struct point{
	int id,x,y;
}p[maxn];
int tot,top;
int s[maxn];
bool onedge(point x){return !x.x||!x.y||x.x==r||x.y==c;}
int calc(point x)
{
	if(x.y==0) return x.x;
    if(x.x==r) return r+x.y;
    if(x.y==c) return 2*r+c-x.x;
	if(x.x==0) return 2*r+2*c-x.y;
}
bool cmp(point x,point y){return calc(x)<calc(y);}
int main()
{
	r=read();c=read();n=read();
	for(int i=1;i<=n;i++)
	{
		point x1,x2;
		x1.id=x2.id=i;
		x1.x=read();x1.y=read();
		x2.x=read();x2.y=read();
		if(onedge(x1) && onedge(x2)) p[++tot]=x1,p[++tot]=x2;
	}
	sort(p+1,p+1+tot,cmp);
	for(int i=1;i<=tot;i++)
	{
		if(top && s[top]==p[i].id) top--;
		else s[++top]=p[i].id;
	}
	puts(top?"NO":"YES");
	return 0;
}

Measured memory_bytes: 2944
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_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;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

int main() {
  ll N;
  string S;
  cin >> N >> S;

  ll MOD = 1000000007;

  unordered_map<char, ll> cnt;
  for (char c: S) {
    cnt[c] += 1;
  }

  ll ans = 1;
  for (auto p: cnt) {
    ans *= (p.second + 1);
    ans %= MOD;
  }

  ans = (ans + MOD - 1) % MOD;

  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

int gcd(int x,int y){
  return y? gcd(y,x%y):x;
}

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

  sort(ALL(a));

  if(k>a.back()){
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }

  int g=a[0];
  REP(i,n) g=gcd(g,a[i]);

  cout<<((k%g)? "IMPOSSIBLE":"POSSIBLE")<<endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
	double N,K;
	cin>>N>>K;
	double sub=0;
	for(int i=1;i<=N;i++){
		double a=i;
		double tmp=1.0/N;
		while(a<K){
			a*=2;
			tmp/=2;
		}
		sub+=tmp;
	}
	cout<<setprecision(12)<<sub<<endl;
}

Measured memory_bytes: 384
N, M = map(int, input().split())

lst = []
for i in range(M):
    a = list(map(int, input().split()))
    a += [i] #i: 市の番号
    lst += [a]
#print (lst)
lst.sort()
#print (lst)

ken = -1
x = 0
ans = []
for j in range(M):
    if ken != lst[j][0]: #1つ前と市の名前が違う
        x = 1 #
        ken = lst[j][0]
#        P = '{:0>6}'.format(ken)
        #print ('A')
    else: #1つ前と市の名前が同じ
        x += 1
        #print ('B')
#    X = '{:0>6}'.format(x)
    ans += [[lst[j][2], ken, x]]

ans.sort()
#print (ans)
for k in range(M):
    P = '{:0>6}'.format(ans[k][1])
    X = '{:0>6}'.format(ans[k][2])
    print (P+X)

Measured memory_bytes: 42528
#include <iostream>
#include <vector>
using namespace std;
int N;
vector <pair <int, int> > G[100005];
long long DP[2][100005], PMax[100005], Max2[100005], ans, Sz[100005];
long long C[100005], sum, cen;
long long Min = 1000000000000000000;
void Read()
{
    cin >> N;
    for(int i = 1; i < N; i++)
    {
        int x, y, c;
        cin >> x >> y >> c;
        G[x].push_back(make_pair(y, c));
        G[y].push_back(make_pair(x, c));
    }
}

void DFS(int node, int father)
{
    Sz[node] = 1;
    for(int i = 0; i < G[node].size(); i++)
    {
        long long neighb = G[node][i].first, cost = G[node][i].second;
        if(neighb == father)
            continue;
        C[neighb] = cost;
        DFS(neighb, node);
        Sz[node] += Sz[neighb];
    }
}

void findCentroid(int node, int father)
{
    bool centroid = 1;
    for(int i = 0; i < G[node].size(); i++)
    {
        int neighb = G[node][i].first, cost = G[node][i].second;
        if(neighb == father)
            continue;
        if(Sz[neighb] > N / 2)
        {
            centroid = 0;
            findCentroid(neighb, node);
            break;
        }
    }
    if(centroid == 1)
        cen = node;
}
int main()
{
    Read();
    DFS(1, 0);
    sum = 0;
    long long ans = 0;
    for(int i = 1; i <= N; i++)
    {
        ans += C[i] * min(Sz[i], N - Sz[i]) * 2;
    }
    for(int i = 1; i <= N; i++)
        if(Sz[i] == N / 2 && N % 2 == 0)
        {
            cout << ans - C[i] << "\n";
            return 0;
        }
    findCentroid(1, 0);
    for(int i = 0; i < G[cen].size(); i++)
    {
        Min = min(Min, 1LL * G[cen][i].second);

    }
cout << ans - Min << "\n";

    return 0;
}


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

int vis[100007];
int dp[100007];
vector<int> arr[100007];
int solve(int u)
{
    if(vis[u]==1)
    return dp[u];
    vis[u]=1;
    int best=0;
    for(auto i=arr[u].begin();i!=arr[u].end();i++)
    {
        best=max(best,solve(*i)+1);
    }
    dp[u]=best;
    return best;
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        int u,v;
        cin>>u>>v;
        arr[u].push_back(v);
        //arr[v].push_back(u);
    }
    int best=0;
    for(int i=1;i<=n;i++)
    {
        best=max(best,solve(i));
    }
    cout<<best<<"\n";
}

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

int main() {
	vector<long> v;
	long s;
	long i;
	cin >> s;
	v.push_back(s);
	for (i = 0; ; i++) {
		if (v[i]%2) {
			v.push_back(v[i]*3+1);
		} else {
			v.push_back(v[i]/2);
		}
		bool f = false;
		for (long j = 0; j < i; j++) {
			if (v[i+1] == v[j]) {
				f = true;
			}
		}
		if (f)
			break;
	}
	cout << i+2 << endl;
}


Measured memory_bytes: 256
/*
 * Stack.c
 *
 *  Created on: 2015/02/14
 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int stack[100];
int count = 0;

int  pop(){
	count--;
	return stack[count];
}

void push(int n){
	stack[count]=n;
	count++;
}

int main(void){
	int x,n,m;
	char s[100];

	while(scanf("%s",s)!= EOF){
		if(s[0]=='+'){
			n=pop();
			m=pop();
			push(n+m);
		}
		else if(s[0]=='-'){
			n=pop();
			m=pop();
			push(m-n);
		}
		else if(s[0]=='*'){
			n=pop();
			m=pop();
			push(n*m);
		}
		else{
			x = atoi(s);
			push(x);
		}
	}
	printf("%d\n",stack[count-1]);
	return 0;
}

Measured memory_bytes: 548
#include<cstdio>
#include<cmath>
#include<algorithm> 
using namespace std;
int n,k,a[100010],f[100010];
int main(){
  scanf("%d %d",&n,&k);
  for(int i=1;i<=n;i++) scanf("%d",&a[i]);
  for(int i=2;i<=n;i++){
    f[i]=2e9;
    for(int j=i-1;j>=1&&i-j<=k;j--){
    	f[i]=min(f[i],f[j]+abs(a[j]-a[i]));
	}
  }
  printf("%d",f[n]);
}

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

int sosu(int n){
	int ret=0;
	for(int i=n+1;i<2*n+1;i++){
		bool flg=1;
		for(int j=2;j<=sqrt(i);j++){
			if(i%j==0) flg=0;
		}
		if(flg) ret++;
	}
	return ret;
}

int main(){
	int n;
	while(cin>>n and n>0){
		cout<<sosu(n)<<endl;
	}
    return 0;
}



Measured memory_bytes: 3092
N = gets.to_i
X = gets.chomp

@m = {0 => 0, 1 => 1}
f = ->(n){@m[n] ||= f[n % n.to_s(2).count('1')] + 1}
c = X.count('1')
c0, c1 = c + 1, c - 1
cf = c1 > 0
xd = X.to_i(2)
x0, x1 = xd % c0, cf ? xd % c1 : nil
(N - 1).downto(0).each do |i|
  if xd[i] == 0
    puts f[(x0 + 2.pow(i, c0))%c0] + 1
  else
    puts cf ? f[(x1 - 2.pow(i, c1))%c1] + 1 : 0
  end
end

Measured memory_bytes: 15716
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mt make_tuple
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
const ll INF=1e16;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s,t;
	cin>>s>>t;
	int n=min(s.size(),t.size());
	rep(i,n)cout<<s[i]<<t[i];
	if(s.size()!=t.size())cout<<s[n]<<endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
    
  int n;
  cin>>n;
  ll arr[n][3];
  for(int i=0;i<n;i++){
      cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
  }
  
  ll dp[n][3];
  dp[0][0]=arr[0][0];
  dp[0][1]=arr[0][1];
  dp[0][2]=arr[0][2];
  for(int i=1;i<n;i++){
      dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
      dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
      dp[i][2]=arr[i][2]+max(dp[i-1][1],dp[i-1][0]);
  }
 ll res=max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
 //for(int i=0;i<n;i++){cout<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<endl;}
  cout<<res<<endl;
  
    
    }

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d) {
    cout << "Yes" << endl;
  } else if ((abs(a - b) <= d) && (abs(b - c) <= d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args : Array<String>) {
    val (n, m, q) = readLine()!!.split(" ").map { it.toInt() }
    val qq = mutableListOf<Item>()

    repeat(q) {
        val (a, b, c, d) = readLine()!!.split(" ").map { it.toInt() }
        qq.add(Item(a-1, b-1, c, d))
    }

    val dfs = Stack<IntArray>()
    for (i in 1..m) {
        val a = IntArray(n){0}
        a[0] = i
        dfs.push(a)
    }

    var max = 0

    while (dfs.isNotEmpty()) {
        val a = dfs.pop()
        if (a.last() != 0) {
            var score = 0
            qq.forEach {
                if (a[it.idx2] - a[it.idx1] == it.diff) score += it.score
            }
            max = Math.max(max, score)
            continue
        }

        val lastIdx = a.indexOfLast { it != 0 }
        for (i in a[lastIdx]..m) {
            val newA = a.copyOf()
            newA[lastIdx+1] = i
            dfs.push(newA)
        }
    }

    println(max)
}

data class Item(val idx1: Int, val idx2: Int, val diff: Int, val score: Int)

Measured memory_bytes: 55576
import java.text.DecimalFormat;
        import java.util.Scanner;

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

        DecimalFormat df = new DecimalFormat( "0.000000 ");

        System.out.println(df.format(s*s*s/27));

    }
}


Measured memory_bytes: 24020
import sys
input = sys.stdin.readline

if __name__ == '__main__':
  h,w,k=map(int,input().strip("\n").split())
  s=[]
  for i in range(h):
    s.append(list(input().strip("\n")))
  ans=0
  #print(s)
  # 2 -> 100 rangeだから11まで
  for iS in range(1<<h):
    # 3->1000=2^3=8
    for js in range(1<<w):
      #print(iS,js)
      cnt=0
      for i in range(h):
        for j in range(w):
          # 赤で塗る場合
          # ex)iS=01,i=0->i+1桁目が1か
          if iS>>i&1: continue
          if js>>j&1: continue
          if s[i][j]=='#': cnt+=1
      if cnt==k: ans+=1

  print(ans)

Measured memory_bytes: 9196
import sys

def shuffle( cards ):
	h = int( sys.stdin.readline() )
	n = len( cards )
	s = ""
	t = ""
	for i in range( h ):
		s += cards[i]
	for i in range( h, n ):
		t += cards[i]
	t += s
	return t

while True:
	cards = sys.stdin.readline().rstrip()
	if '-' == cards:
		break
	m = int( sys.stdin.readline() )
	for i in range( 0, m ):
		cards = shuffle( cards )
	print( cards )

Measured memory_bytes: 6724
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 1.0e9+7;
bool ispalin(string s,int l,int r)
{
    for(int i=l;i<=r;i++)
    {
        if(s[i]!=s[r-i])
            return false;
    }
    return true;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n,m,i,x,y,z;
    cin>>n;
    int arr[n+1];
    map<int,int> mp;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    int sum=0;
    for(auto it: mp)
    {
        sum+=((it.second*(it.second-1))/2);
    }
    for(i=0;i<n;i++)
    {
        int ans = sum - (mp[arr[i]]*(mp[arr[i]]-1))/2 + ((mp[arr[i]]-1)*(mp[arr[i]]-2))/2;
        cout<<ans<<endl; 
    }
    return 0;
}

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

int main(){
  int N,A,B,i,j,sum=0,ans=0;
  cin >> N >> A >> B;
  for(i=1;i<=N;i++){
    j = i;
    while(j>0){
      sum += j%10;
      j /= 10;
    }
    if((A <= sum)&&(sum <= B)){
      ans += i;
    }
    sum = 0;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    ll n;
    cin>>n;
    ll yen=0;
    while(n>yen)
    {
        yen=yen+1000;
            
    }
    cout<<yen-n;
    return 0;
}

Measured memory_bytes: 3620
/* In the name of God */
     
#include <bits/stdc++.h>
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pii pair <int, int>
using namespace std;
const ll mod = 1e9 + 7;
const int N = 2e5 + 5;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = k; i < n; i++) {
        cout << (a[i - k] < a[i] ? "Yes\n" : "No\n");
    }
}
 
int main()  {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int tt = 1;
    // cin >> tt;
    for (int tc = 1; tc <= tt; ++tc) {
        // cout << "Case #" << tc << ": ";
        solve();
    } 
}                        

Measured memory_bytes: 3984
x,y=gets.split.map(&:to_i)
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]

r=->ar{ar.index(x)&&ar.index(y)}

if r[a]||r[b]||r[c] then
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                                              NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("C:/Users/DELL/Desktop/input.txt", "r", stdin);
	#endif

	fast;
	ll n;
	cin>>n;
	string str;
	while(n)
	{
		str = (char)('a'+(n-1)%26) + str;
		n = (n-1)/26;
	}
	cout<<str;
	return 0;
}


Measured memory_bytes: 3640
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: usize = sc.read();
    let a = sc.read_vec::<i64>(n);
    const MOD: i64 = 1e9 as i64 + 7;

    let mut cum = vec![0; n + 1];
    for i in 0..n {
        cum[i + 1] = cum[i] + a[i];
    }

    let mut ans = 0;
    for i in 0..n {
        ans += (a[i] % MOD) * ((cum[n] - cum[i + 1]) % MOD);
        ans %= MOD;
    }
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 4028
N,K = map( int, input().split() )
H = list( map( int, input().split() ) )
dp = [0]*N
for i,Hi in enumerate(H[1:],1):
    s = max(0,i-K)
    dp[i] = min( [ t + abs( Hi - hl ) for hl,t in zip(H[s:i], dp[s:i]) ] )
print(dp[N-1])

Measured memory_bytes: 13928
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
using namespace std;

const int MAX_K = 4;
const int MAX_X = 10500;
const int MAX_N = 41;
const int INF = 1e+8;
int n, p[MAX_N], t[MAX_N];
int ans, get;
int dp[MAX_N][MAX_K][MAX_X];

void solve(){
	for(int i=0 ; i < MAX_N ; i++ ){
		for(int j=0 ; j < MAX_K ; j++ ){
			for(int k=0 ; k < MAX_X ; k++ ){
				dp[i][j][k] = INF;
			}
		}
	}
	
	// dp[i][k][x] := sum distance
	dp[0][0][0] = 0;
	for(int i=0 ; i < n ; i++ ){
		for(int k=0 ; k <= 3 ; k++ ){
			for(int x=0 ; x < MAX_X ; x++ ){
				if( dp[i][k][x] != INF ){
					if( k != 0 ){ // go house
						int dist = x;
						double next_time = t[i-1] + (double)dist / (1.0 / (k+1));
						dist += p[i];
						next_time += (double)p[i];
						
						if( next_time <= t[i] ){
							dp[i+1][1][p[i]] = min(dp[i+1][1][p[i]], dp[i][k][x] + dist );
						}
					}
					if( k != 3 ){
						int dist = abs(x - p[i]);
						double prev_time = i? t[i-1] : 0;
						double next_time = prev_time + (double)dist / (1.0 / (k+1));
						
						if( next_time <= t[i] ){
							dp[i+1][k+1][p[i]] = min(dp[i+1][k+1][p[i]], dp[i][k][x] + dist );
						}
					}
				}
			}
		}
	}
	get = 0;
	ans = INF;
	for(int i=0 ; i <= n ; i++ ){
		for(int k=0 ; k <= 3 ; k++ ){
			for(int x=0 ; x < MAX_X ; x++ ){
				if( dp[i][k][x] != INF ){
					get = max(get, i);
					if( i == n ){
						ans = min(ans, dp[i][k][x] + p[i-1]);
					}
				}
			}
		}
	}
}

int main(){
	while( cin >> n , n ){
		for(int i=0 ; i < n ; i++ ){
			cin >> p[i] >> t[i];
		}
		ans = INF;
		solve();
		if( ans != INF ){
			cout << "OK " << ans << endl;
		}else{
			cout << "NG " << get+1 << endl;
		}
	}
}

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

n = int(input())
num = list(map(int, input().split()))
ans = 0
flg = 0
for i in range(n):
    if num[i] == 0:
        flg = 1;
        break
    
for i in range(n):
    if flg == 1:
        print(0)
        break
    elif i == 0:
        ans = num[0]
    else:
        ans*=num[i]
    
    if ans > 10 ** 18 and flg ==0:
        print(-1)
        break
    

if ans <= 10 ** 18 and flg == 0:
    print(ans)

Measured memory_bytes: 21780
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			long a = cin.Long();
			long b = cin.Long();
			long c = cin.Long();

			long d = c - a- b;
			if (d <= 0) {
				Console.WriteLine("No");
				return;
			}

			if (4 * a * b < d * d) {
				Console.WriteLine("Yes");
			} else {
				Console.WriteLine("No");
			}
		}
	}

	public static class Helper
	{
		public static void UpdateMin32<T>(T array, int index, int value) where T : IList<int>
			=> array[index] = Math.Min(array[index], value);
		public static void UpdateMax32<T>(T array, int index, int value) where T : IList<int>
			=> array[index] = Math.Max(array[index], value);
		public static void UpdateMin64<T>(T array, int index, long value) where T : IList<long>
			=> array[index] = Math.Min(array[index], value);
		public static void UpdateMax64<T>(T array, int index, long value) where T : IList<long>
			=> array[index] = Math.Max(array[index], value);

		public static T[] Array<T>(int n, Func<int, T> init)
			=> Enumerable.Range(0, n).Select(x => init(x)).ToArray();
		public static List<T> List<T>(int n, Func<int, T> init)
			=> Enumerable.Range(0, n).Select(x => init(x)).ToList();
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private readonly Func<string> reader_;
		private string[] buf_;
		private int index_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

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

dic = {}
for i in range(1, 10):
  for j in range(1, 10):
    dic[(str(i), str(j))] = 0

for i in range(1, n+1):
  if i % 10 == 0:
    continue
  front = str(i)[0]
  back = str(i)[-1]
  dic[(front, back)] += 1
ans = 0
for i in range(1, 10):
  for j in range(1, 10):
    ans += dic[(str(i), str(j))] * dic[(str(j), str(i))]
print(ans)


Measured memory_bytes: 73568
#include<cstdio>
#include<cstring>

const int MAXN = 100 + 10;
char s[MAXN];

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

void solve()
{
    int n;
    scanf("%d", &n);
    getchar();
    fgets(s, n + 1,stdin);
    if(n%2==1)
        printf("No");
    else 
    {
        for (int i = 0; i < n / 2;i++)
        {
            if(s[i]!=s[i+n/2])
            {
                printf("No");
                return;
            }
        }
        printf("Yes");
    }
}

Measured memory_bytes: 1772
n = int(input())
cnt = [[0] * 10 for i in range(10)]
for i in range(1,n+1):
  i = str(i)
  cnt[int(i[0])][int(i[-1])] += 1
ans = 0
for i in range(10):
  for j in range(10):
    ans += cnt[i][j] * cnt[j][i]
print(ans)

Measured memory_bytes: 3064
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 4005 , M = 4e5 + 10;
int n , m , cost[N][N] , a[M] , b[M] , c[M] , id[M];
int Q;
int fa[N];
vi contain[N];
int F(int x) {return fa[x] == x ? x : fa[x] = F(fa[x]);}

int main(){
  scanf("%d%d",&n,&m);
  rep(i,0,m) scanf("%d%d%d",a+i,b+i,c+i),id[i]=i;
  rep(i,1,n+1) fa[i]=i,contain[i].pb(i);
  sort(id,id+m,[&](int x,int y){return c[x]<c[y];});
  ll sum = 0;
  rep(i,0,m) {
    int u=F(a[id[i]]) , v=F(b[id[i]]);
    if(u != v) {
      sum += c[id[i]];
      if(sz(contain[u]) < sz(contain[v]))
        swap(u , v);
      for(auto e : contain[u])
        for(auto f : contain[v])
          cost[e][f] = cost[f][e] = c[id[i]];
      contain[u].insert(contain[u].end(),all(contain[v]));
      contain[v].clear();
      fa[v] = u;
    }
  }
  scanf("%d",&Q);
  rep(i,0,Q) {
    int s,t;
    scanf("%d%d",&s,&t);
    printf("%lld\n",sum-cost[s][t]);
  }
  return 0;
}


Measured memory_bytes: 70528
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define sll set<ll>
#define msll multiset<ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define vpl vector<pll>
#define gll greater<ll>
#define gpl greater<pll>
#define spl set<pll>
#define mspl multiset<pll>
#define lb lower_bound
#define bp __builtin_popcount
#define ub upper_bound
#define prq priority_queue
#define mp make_pair
#define pb push_back
#define mem(x,y) memset(x, y, sizeof x)
#define endl "\n"
#define sz(x) (ll)x.size()
#define sqr(x) x*x
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long int ll;
typedef long double ld;
ll mx=INT_MAX;
ll mn=INT_MIN;
ll MOD=1e9+7;
const ll maxs=1e5+10;
ll max2d=1e3+3;
ll INF = 1e18;
const ll lg=22;

void code_idhr_h(){
    ll N; cin>>N;
    ll A[N+1];
    ll cnt1[100001], cnt0[100001]; mem(cnt1 , 0); mem(cnt0 , 0);
    for(ll i=1; i<=N; i++){
        cin>>A[i];
        if(i%2) cnt1[A[i]]++;
        else cnt0[A[i]]++;
    }
    ll oc=0,ec=0,oe=0,ee=0;
    for(ll i=1; i<=100000; i++){
        if(oc<cnt1[i]){
            oe=i;
            oc=cnt1[i];
        }
        if(ec<cnt0[i]){
            ee=i;
            ec=cnt0[i];
        }
    }
    if(ee!=oe){
        cout<<N-(oc+ec);
        return;
    }
    if(oc>ec){
        ec=0;
        for(ll i=1; i<=100000; i++) if(i!=oe) ec=max(ec , cnt0[i]);
        cout<<N-(oc+ec);
        return;    
    }
    if(oc<ec){
        oc=0;
        for(ll i=1; i<=100000; i++) if(i!=ee) ec=max(ec , cnt1[i]);
        cout<<N-(oc+ec);
        return;
    }
    ll tmp=oc;
    ec=0;
    for(ll i=1; i<=100000; i++) if(i!=oe) ec=max(ec , cnt0[i]);
    oc=0;
    for(ll i=1; i<=100000; i++) if(i!=ee) ec=max(ec , cnt1[i]);
    ll ans = N-(tmp+oc);
    ans = min(ans , N - (tmp+ec));
    cout<<ans;
}

int main(){
    rapido;
    ll T=1; //cin>>T;
    while(T--){
        code_idhr_h();
    }
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		int max = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;

		for(int i = 0; i < n; i++) {
			int gt = sc.nextInt();
			if(max < gt) {
				max = gt;
			}
			if(min > gt) {
				min = gt;
			}
		}



		System.out.println(max - min);
	}

}


Measured memory_bytes: 21716
n,m,q=map(int,input().split())
Q=[list(map(int,input().split())) for i in range(q)]
ans=0
#めっちゃfor分あるならdfs
R=[range(i,m) for i in range(m)]
def dfs(d,s):
    global n,m,Q,ans
    if d==n:
        ans_=0
        for k in Q:
            a,b,c,e=k
            if int(s[b-1])-int(s[a-1])==c:
                ans_+=e
        ans=max(ans,ans_)
    else:
        l=int(s[-1])
        for i in R[l]:
            dfs(d+1,s+str(i))
for i in R[0]:
    dfs(1,str(i))

print(ans)

Measured memory_bytes: 80584
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int pp, n, m, f[5], a[200003], bj = 1;
string s, t, q;

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

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi();
	for (int i = 1; i <= n; i+=1)
	{
		a[i] = gi();
	}
	for (int i = 1; i <= n; i+=1)
	{
		if (a[i] == bj) 
		{
			++bj;
			++pp;
		}
	}
	if (pp == 0) puts("-1");
	else printf("%d\n", n - pp);
	return 0;
}



Measured memory_bytes: 1024
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    using namespace std;
    using Graph = vector<vector<int>>;

    #define INF 10000000
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    const int dx[4] = {1,0,-1,0};
    const int dy[4] = {0,1,0,-1};
    
    auto seen = vec(bool,500);
    
    void dfs(Graph &G,int v){
      seen[v] = true;

      for(auto nv : G[v]){
        if(seen[nv] == true)continue;
        dfs(G,nv);
      }

    }

    
    int main(){
      int n,m;
      cin >>n>>m;
      if(500*n>=m)cout <<"Yes";
      else cout <<"No";
      }
    
    

    

Measured memory_bytes: 256
N = int(input())
A = [int(A) for A in input().split()]
cnt = 0
for i in range(1, N):
    for j in range(N-1, i-1, -1):
        if A[j] < A[j-1]:
            t = A[j]
            A[j] = A[j-1]
            A[j-1] = t
            cnt += 1
for i in range(N):
    if i == N - 1:
        print(A[i])
    else:
        print("{}".format(A[i]), end=' ')

print(cnt)

Measured memory_bytes: 7724
#! /usr/bin/python
# -*- coding: utf-8 -*-
# ALDS1_3_A: Stack

if __name__ == "__main__":
    # 数字と文字入力　行数＋数字(1行1文字)
    A=list(input().split()) # 空白を区切文字として配列に格納
    ANS_QUEUE = []
    j = 0
    for i in range(len(A)):
        if A[i] != '+' and A[i] != "-" and A[i] != "*":
            # print(A[i])
            ANS_QUEUE.append(int(A[i]))
            # print("A = {}".format(A))
        
        if A[i] == "+":
            # print("Sum")
            tmp = ANS_QUEUE.pop(-2) + ANS_QUEUE.pop(-1)
            ANS_QUEUE.append(int(tmp))
        
        if A[i] == "-":
            # print("Subtract")
            tmp = ANS_QUEUE.pop(-2) - ANS_QUEUE.pop(-1)
            ANS_QUEUE.append(int(tmp))
        
        if A[i] == "*":
            # print("Multiply")
            tmp = ANS_QUEUE.pop(-2) * ANS_QUEUE.pop(-1)
            ANS_QUEUE.append(int(tmp))
        # print("QUEUE = {}".format(ANS_QUEUE))
    
    print(ANS_QUEUE[0])
    # print("QUEUE = {}".format(ANS_QUEUE))




Measured memory_bytes: 5608
package main

import (
	"fmt"
	"math"
)

func main(){
	var x int
	var flag bool
	fmt.Scan(&x)
	for a:= 0 ; a <= 200 ; a++ {
		for b:=-200 ; b<=200 ; b++ {
			if int(math.Pow(float64(a),5)) - int(math.Pow(float64(b),5)) == x {
				fmt.Println(a,b)
				flag = true
				break
			}
		}
		if flag {
			break
		}
	}
}


Measured memory_bytes: 1824
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        int a[n+5];
        for(int i=1;i<=n;i++)
            cin>>a[i];
        int cnt=0;
        for(int i=1;i<n;i++)
        {
            if(a[i]==a[i+1])
            {
                cnt++;
                i++;
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


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

using namespace std;

int solve(int64_t X) {
  int count = 0;
  while (X != 0) {
    X %= __builtin_popcountll(X);
    count++;
  }
  return count;
}

int main() {
  int N;
  string S;
  cin >> N >> S;

  int popcount = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == '1') popcount++;
  }

  vector<int64_t> remainder_plus(N, 0);
  vector<int64_t> remainder_minus(N, 0);
  {
    int64_t num = 1;
    for (int i = 0; i < N; i++) {
      remainder_plus[N - 1 - i] = num;
      num = (num << 1) % (popcount + 1);
    }
  }
  if (popcount > 1) {
    int64_t num = 1;
    for (int i = 0; i < N; i++) {
      remainder_minus[N - 1 - i] = num;
      num = (num << 1) % (popcount - 1);
    }
  }

  int64_t total_plus = 0;
  int64_t total_minus = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == '1') {
      total_plus += remainder_plus[i];
      total_minus += remainder_minus[i];
    }
  }

  for (int i = 0; i < N; i++) {
    if (S[i] == '1') {
      if (popcount > 1) {
	int64_t X = (total_minus - remainder_minus[i] + popcount - 1) % (popcount - 1);
	cout << solve(X) + 1 << endl;
      } else {
	cout << 0 << endl;
      }
    } else {
      int64_t X = (total_plus + remainder_plus[i] + popcount + 1) % (popcount + 1);
      cout << solve(X) + 1 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 6824