akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdlib.h>
#include <stack>

using namespace std;

int r[530000],rp[2][530000],sw[2][530000],rb[2],bf;

int main() {
	int a,i,j,k,g,m,n,s,t,f,f2,rl[16][16],rs[16][16],sn[16],lc[16],p=32768;
	stack<int> an,bn; 
	while(cin >> n >> m) {
		if (n==0) break;
		for (i=0;i<530000;i++) r[i]=-1;
		for (i=0;i<16;i++) sn[i]=lc[i]=0;
		for (i=0;i<m;i++) { cin >> s >> t; rl[s-1][lc[s-1]++]=t-1; rl[t-1][lc[t-1]++]=s-1; }
		rb[0]=1; f=0; bf=0; sw[0][0]=0;
		for (i=0;i<n;i++) { cin >> j; f+=(1 << i)*j; }
		r[f]=0; rp[0][0]=f;
		for (i=0;i<n;i++) {
			cin >> k; sn[i]=0;
			if (k>0) for (j=0;j<k;j++) {cin >> rs[i][sn[i]++]; rs[i][sn[i]-1]--;}
			for (j=sn[i]-1;j>0;j--) for (k=0;k<j;k++) 
			if (rs[i][k]>rs[i][k+1]) { a=rs[i][k]; rs[i][k]=rs[i][k+1]; rs[i][k+1]=a;}
			}
		f2=f=0;
		while(f==0) {
	    f=1; rb[1-bf]=0;
	      for (i=0;i<rb[bf];i++) {
			s=rp[bf][i]/p; t=(p-1) & rp[bf][i];
			if (s==n-1) f2=1;
			for (g=0;g<lc[s];g++) {
				  if ((t & (1 << rl[s][g]))>0 && r[rl[s][g]*p+t]==-1) {
					     f=0;
						 r[rl[s][g]*p+t]=s*p+t;
						 sw[1-bf][rb[1-bf]]=0; 
						 rp[1-bf][rb[1-bf]++]=rl[s][g]*p+t;
						 } 
					  }
			if (sn[s]==0) continue;		  					 
 			for (k=sw[bf][i];k<sn[s];k++) {
				 a=rp[bf][i] ^ (1 << rs[s][k]);
				 if (r[a]==-1 && (a & (1 << s))>0) { f=0; r[a]=rp[bf][i]; sw[1-bf][rb[1-bf]]=k+1; rp[1-bf][rb[1-bf]++]=a;}
			 } 
	 }			
	 bf=1-bf;
     }
     s=(n-1)*p+(1 << (n-1));
     if (f2==0) { cout << "Help me!"<< endl;  continue;}
     if (r[s]==-1) { cout << "You can not switch off all lights." << endl; continue;}
     while (r[s]!=0) {
		 if (s/p!=r[s]/p) { an.push(s/p); bn.push(0);} else {
			 for (k=0;k<15;k++) {
				 if ((s & (1 << k))>0 && (r[s] & (1 << k))==0) { an.push(k); bn.push(1);}
				 if ((s & (1 << k))==0 && (r[s] & (1 << k))>0) { an.push(k); bn.push(2);}
			 } 
		  }
	 s=r[s];
 } 
	 cout << "You can go home in " << an.size() << " steps." << endl;
	 while(!an.empty()) {
		 if (bn.top()==0) cout << "Move to room ";
		 if (bn.top()==1) cout << "Switch on room ";
		 if (bn.top()==2) cout << "Switch off room ";
		 cout << an.top()+1 << '.' << endl;
		 an.pop(); bn.pop();
	 } 
	}			 	
 return 0;
} 

Measured memory_bytes: 9556
import sys
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=1)
a=0
b=0
j=N-1
for i in range(N-1):
  if A[i]==A[i+1]:
    a=A[i]
    j=i
    break
for i in range(j+2,N-1):
  if A[i]==A[i+1]:
    b=A[i]
    break
 
print(a*b)

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <cassert>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<long> an(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> an[i];
    }

    auto get_sign = [](int x) {
        return x >= 0 ? 1 : -1;
    };

    long cnt_min = LONG_MAX;
    for (int j = -1; j < 1; ++j)
    {
        auto cp = an;
        int sign = get_sign(j);
        long accum = an[0];
        long cnt = 0;
        if (accum * sign <= 0)
        {
            // accum + x = sign
            auto x = sign - accum;
            accum += x;
            cnt += abs(x);
            cp[0] = sign;
        }

        for (int i = 1; i < n; ++i)
        {
            auto new_accum = accum + an[i];
            int new_sign = -sign;
            if (new_accum * get_sign(accum) >= 0)
            {
                // new_accum + x = new_sign
                auto x = new_sign - new_accum;
                new_accum += x;
                cnt += abs(x);
                cp[i] += x;
            }
            accum = new_accum;
            sign = new_sign;
        }

        cnt_min = min(cnt, cnt_min);
    }
    cout << cnt_min << endl;
    return 0;
}

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

int z_algorithm(vector<int> &Z, string &S, int index) {
    Z[index] = S.size() - index;
    int i = 1, j = 0;
    int N2 = Z[index] / 2;
    int ans = 0;

    while (index + i < S.size()) {
        while (index + i + j < S.size() && S[index + j] == S[index + i + j]) {
            ++j;
        }

        Z[index + i] = j;

        if (j == 0) {
            ++i;
            continue;
        }

        if (j <= i && ans < j) {
            ans = j;
        }

        int k = 1;

        while (index + i + k < S.size() && k + Z[index + k] < j) {
            Z[index + i + k] = Z[index + k];

            if (Z[index + k] <= i + k && ans < Z[index + k]) {
                ans = Z[index + k];
            }

            ++k;
        }

        i += k;
        j -= k;
    }

    return ans;
}

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

    auto Z = vector<int>(S.size());
    int ans = 0;

    for (int i = 0; i < N; ++i) {
        int ansi = z_algorithm(Z, S, i);

        if (ans < ansi) {
            ans = ansi;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main() {
  typedef long long ll;
  ll N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<ll> l(Q);
  vector<ll> r(Q);
  REP(i, Q) {
    cin >> l.at(i) >> r.at(i);
  }
  
  vector<ll> count(N);
  REP(i, N - 1) {
    count.at(i + 1) = count.at(i);
    if (S.at(i) == 'A' && S.at(i + 1) == 'C') {
      count.at(i + 1)++;
    }
  }
  
  REP(i, Q) {
    cout << count.at(r.at(i) - 1) - count.at(l.at(i) - 1) << endl;
  }
}


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

namespace ABC085_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            List<int> mochi = new List<int>();
            for(var i=0;i<n;i++)
            {
                mochi.Add(int.Parse(Console.ReadLine()));
            }
            Console.WriteLine(mochi.Distinct().Count());
        }
    }
}


Measured memory_bytes: 13152
{-# LANGUAGE BangPatterns, MultiWayIf #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Int
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> Int -> VU.Vector Int -> Bool
solve !n !k !an =
  VU.constructrN
      (k + 1)
      (\(!vec) -> not $ VU.and $ VU.map
        (\(!a) -> if a <= VU.length vec then vec VU.! (a - 1) else True)
        an
      )
    VU.! 0

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (n, k) <-
    (\(!vec) -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  an <- VU.unfoldrN n readInt <$> B.getLine
  putStrLn $ if solve n k an then "First" else "Second"


Measured memory_bytes: 1020
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define LB(c, x) lower_bound(c.begin(), c.end(), x)
#define UB(c, x) upper_bound(c.begin(), c.end(), x)
#define LI(c, x) distance(c.begin(), LB(c, x))
#define UI(c, x) distance(c.begin(), UB(c, x))

// functions
template <class T> T ceil(T a, T b) {
    return (a + b - 1) / b;
}
template <class T> T round(T a, T b) {
    return (a + b / 2) / b;
}
template <class T> T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T> T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T> bool amax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    int cnt = 0;
    REP(i, N) {
        if (S[i] == '.') {
            cnt++;
        }
    }
    int res = min(cnt, N - cnt);
    int w = 0, b = 0;
    REP(i, N) {
        if (S[i] == '.') {
            w++;
        } else {
            b++;
        }
        amin(res, b + cnt - w);
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
  string s;
  cin >> s;
  string output="";
  for(int i=0;i<s.length();i++){
    if(s[i]=='0')
      output+="0";
    if(s[i]=='1')
      output+="1";
    if(s[i]=='B' && output.length()>0)
      output.pop_back();
  }
  cout<<output<<endl;
}


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

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


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

typedef vector<int> vi;

//#define DEBUG 1
int main()
{
#ifdef DEBUG
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
#endif

   int n = 0;
   cin >> n;
   vi a(n);
   for (int i = 0; i < n; ++i) cin >> a[i];

   int cnt = 0;
   for (auto i : a) if (i % 2 != 0) ++cnt;

   if (cnt % 2 == 0) cout << "YES" << endl;
   else cout << "NO" << endl;

   return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  if(a[0]==5&&a[1]==5&&a[2]==7)
  {
    cout<<"YES"<<endl;
  }
  else
    cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 200100;
int par[MAX_N]; // 親
int rank_[MAX_N]; // 木の深さ
int cnt_[MAX_N]; // 属する頂点の個数(親のみ正しい)

// n要素で初期化
void UFinit(){
    for(int i=0;i<MAX_N;i++){
        par[i] = i;
        rank_[i] = 0;
        cnt_[i] = 1;
    }
}

// 木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank_[x] < rank_[y]){
        par[x] = y;
        cnt_[y] += cnt_[x];
    }else{
        par[y] = x;
        cnt_[x] += cnt_[y];
        if(rank_[x] == rank_[y]) rank_[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
    return find(x) == find(y);
}


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

    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        unite(a,b);
    }

    int ans = 0;
    rep(i,n){
        ans = max(ans, cnt_[i]);
    }

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



Measured memory_bytes: 5984
# include <bits/stdc++.h>
# define  long          long long
# define  all(vc)       vc.begin(),vc.end()
# define  allr(vc)      vc.rbegin(),vc.rend()
# define  pb            push_back
# define  fi            first 
# define  se            second
# define  pi            pair <long, long>    
# define  lcm(a, b)     (a * b) / __gcd(a, b)
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        using namespace std;
void read(){freopen("odometer.in" , "r" , stdin );freopen("odometer.out", "w" , stdout );}

const int N = 1e6 + 7;

int dp[N], c[N];

void solve(){
    long n, x, a;
    cin >> n >> x >> a;
    if( a * x >= n ) cout << "Yes";
    else cout << "No";
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); 
        long T = 1;
        //cin >> T;
        while( T-- ){
            solve();
            cout<<'\n';
        }
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";    
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define all(c) begin(c),end(c)
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
//最大公約数
ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}
//最小公倍数
ll lcm(ll x, ll y) {
  return x/gcd(x, y)*y;
}
//素因数分解
vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}
 
 
 ll mod=998244353;
 
int main() {
  ll n,d;
  cin>>n>>d;
  d=d*d;
  ll x[n],y[n];
  int ans=0;
  rep(i,n){
    cin>>x[i]>>y[i];
  }
  rep(i,n){
    ll dis=x[i]*x[i]+y[i]*y[i];
    if(dis<=d){
      ans++;
    }
  }
  cout<<ans;

}

Measured memory_bytes: 6748
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const long long INF = 1e15;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
typedef pair<int,int> pii;
int main(){
    int n;
    cin >> n;
    long long distance[n+1][n+1];
    long long ans = 0;
    rep(i,n+1){
        rep(j,n+1){
            if(i==j) distance[i][j]=0;
            else distance[i][j] = INF;
        }
    }
    long long a[n+1][n+1];
    rep(i,n){
        rep(j,n){
            cin >> a[i+1][j+1];
            distance[i+1][j+1] = a[i+1][j+1];
            ans+=a[i+1][j+1];
        }
    }
    for(int i = 1;i<=n;i++){
        for(int j = 1;j<=n;j++){
            for(int k = 1;k<=n;k++){
                distance[j][k] = min(distance[j][k],distance[j][i]+distance[i][k]);
            }
        }
    }
    rep(i,n){
        rep(j,n){
            if(distance[i+1][j+1]<a[i+1][j+1]){
                cout << -1 << endl;
                return 0;
            }
        }
    }
    ans/=2;
    for(int i = 1;i<=n;i++){
        for(int j = i+1;j<=n;j++){
            for(int k = 1;k<=n;k++){
                if(k!=i && k!=j){
                    if((distance[i][k]+distance[k][j])==a[i][j]){
                        ans-=a[i][j];
                        break;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
using namespace std;

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

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
const int maxn=2005;
struct edge {int u,v;} edges[maxn<<1];
int n,k,head[maxn],nxt[maxn<<1],idx=0;
inline void add(int u,int v) {edges[++idx]=(edge){u,v};nxt[idx]=head[u];head[u]=idx;}
int dfs(int x,int fa,int dep) {
	int ret=0;
	if(dep>k/2) ++ret;
	for(int i=head[x];i;i=nxt[i]) {
		int v=edges[i].v;if(v==fa) continue;
		ret+=dfs(v,x,dep+1);
	}
	return ret;
}
int main() {
	scanf("%d%d",&n,&k);
	int m=n-1,u,v;idx=0;
	while(m--) {
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	int ans=0x7fffffff;
	if(k&1) for(int i=1;i<=idx;i+=2) {
		u=edges[i].u;v=edges[i].v;
		ans=std::min(ans,dfs(u,v,0)+dfs(v,u,0));
	}
	else for(int i=1;i<=n;++i) ans=std::min(ans,dfs(i,0,0));
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll a,b;
	cin>>a>>b;
	vector<ll>pos1;
	vector<ll>pos2;
	for(ll i=2; i*i<=a; i++)
	{
		if(a%i==0)
		{
			pos1.push_back(i);
			while(a%i==0)
			{
				a=a/i;
			}
		}
	}
	if(a>1)
	 pos1.push_back(a);
	for(ll i=2; i*i<=b; i++)
	{
		if(b%i==0)
		{
			pos2.push_back(i);
			while(b%i==0)
			{
				b=b/i;
			}
		}
	}
	if(b>1)
	{
		pos2.push_back(b);
	}
	int cnt=1;
	sort(pos1.begin(),pos1.end());
	sort(pos2.begin(),pos2.end());
	for(int i=0; i<pos1.size(); i++)
	{
		if(binary_search(pos2.begin(),pos2.end(),pos1[i]))
		{
			cnt++;
		}
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 3612
MOD = 10**9+7
K = int(input())
S = input()
N = len(S)

n = N+K
fac = [1]*(n+1)
rev = [1]*(n+1)
 
for i in range(1,n+1):
  fac[i] = i*fac[i-1]%MOD
  rev[i] = pow(fac[i], MOD-2, MOD)
 
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD

ans = 0
for i in range(K+1):
    ans += pow(26, K-i, MOD) * pow(25, i, MOD) * comb(N+i-1, i)
    ans %= MOD
print(ans)

Measured memory_bytes: 106708
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, v;
  cin >> n;
  int* ohash = (int*) calloc(100000, sizeof(int));
  int* ehash = (int*) calloc(100000, sizeof(int));
  for (int i = 0; i < n/2; i++) {
    cin >> v;
    ohash[v - 1]++;
    cin >> v;
    ehash[v - 1]++;
  }
  int omax = 0, emax = 0;
  for (int i = 0; i < 100000; i++) {
    if (ohash[i] > ohash[omax]) omax = i;
    if (ehash[i] > ehash[emax]) emax = i;
  }
  if (omax != emax) {
    cout << n - ohash[omax] - ehash[emax];
  }
  else {
    int omax2 = 0, emax2 = 0;
    for (int i = 0; i < 100000; i++) {
      if (ohash[i] > ohash[omax2] && i != omax) omax2 = i;
      if (ehash[i] > ehash[emax2] && i != emax) emax2 = i;
    }
    if (ohash[omax] == n/2 && ehash[emax] == n/2) {
      cout << n/2;
    }
    else if (ohash[omax] == n/2) {
      cout << n/2 - ehash[emax2];
    }
    else if (ehash[emax] == n/2) {
      cout << n/2 - ohash[omax2];
    }
    else {
      cout << min(n - ohash[omax] - ehash[emax2], n - ohash[omax2] - ehash[emax]);
    }
  }
  free(ohash);
  free(ehash);
  return 0;
}

Measured memory_bytes: 4028
use std::io::*;
use std::str::FromStr;
use std::cmp::{min, max};

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin_lock = stdin.lock();
    let s = stdin_lock
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let n: i32 = read();
    let mut a: Vec<i32>= (0..n).map(|_| read()).collect();
    a.insert(0, 0);
    a.push(0);

    let cost: i32 = {
        let mut sum = 0;
        for x in a.windows(2) {
            sum += (x[0] - x[1]).abs();
        }
        sum
    };

    for x in a.windows(3) {
        println!("{}", cost + (x[2] - x[0]).abs() - (x[1] - x[0]).abs() - (x[2] - x[1]).abs());
    }
}

Measured memory_bytes: 5244
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    ll n;cin>>n;
    /*
    n div x=iあまりiつまり
    i*x+i=nとなるiの総和を求める
    上式変形でi*(x+1)=n
    なのでiの候補としてはnの約数しかない．
    あとx>iである必要がある(割る数よりあまりが大きくなるのはおかしい)
     */
    ll ans=0;
    for(ll i=1;i*i<n;i++){
        if(n%i!=0) continue;

        ll x=n/i-1;
        if(x>i){
            ans+=x;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// kill it - Abhinav IIITA
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define f(i,x,n) for(int i=x;i<n;++i)


// -----------------------------------------------------------------------


void solve(){	
	int n,m; cin>>n>>m;
	int h[n];
	f(i,0,n) cin>>h[i];
    map<int,vector<int>> mp;
    f(i,0,m){
		int a,b; cin>>a>>b;
		--a; --b;
		mp[a].push_back(b);
		mp[b].push_back(a);
	}
	int good=0;
	f(i,0,n){
		bool pp=1;
		for(auto it : mp[i]){
			if(h[it]>=h[i]) pp=0;
		}
		good+=pp;
	}
	cout<<good<<"\n";
}

// -----------------------------------------------------------------------


int32_t main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}


Measured memory_bytes: 15692
//package com.zhangyong.algorithm;

import java.io.*;
import java.util.StringTokenizer;

public class Main{

    FastScanner in;
    PrintWriter out;

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        private FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        private FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

    }

    static final int count = 100000;

    private void solve() {
        int n = in.nextInt();
        long m = in.nextLong();
        long arr[] = new long[count + 1];
        int l;
        long r;
        for (int i = 0; i < n; i++) {
            l = in.nextInt();
            r = in.nextLong();
            arr[l] += r;
        }
        for (int i = 0; i <= count; i++) {
            if ((m -= arr[i]) <= 0) {
                out.print(i);
                break;
            }
        }
    }

    private void run() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 45308
#include <bits/stdc++.h>
#define maxn 301
using namespace std;

int n;
int cnt[3];
double dp[maxn][maxn][maxn];

int main() {
	scanf("%d",&n);
	for( int i = 0 , x ; i < n ; i++ ) {
		scanf("%d",&x);
		cnt[x-1]++;
	}
	for( int c3 = 0 ; c3 <= n ; c3++ )
		for( int c2 = 0 ; c2 <= n-c3 ; c2++ )
			for( int c1 = 0 ; c1 <= n-c3-c2 ; c1++ )
				if( c1+c2+c3 ) {
					if(c3)
						dp[c3][c2][c1] += dp[c3-1][c2+1][c1] * c3 / n;
					if(c2)
						dp[c3][c2][c1] += dp[c3][c2-1][c1+1] * c2 / n;
					if(c1)
						dp[c3][c2][c1] += dp[c3][c2][c1-1] * c1 / n;
					dp[c3][c2][c1] += 1.0;
					dp[c3][c2][c1] *= (double) n / (c1+c2+c3);
				}
	printf("%.15lf\n",dp[cnt[2]][cnt[1]][cnt[0]]);
	return 0;
}


Measured memory_bytes: 213248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc081_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N;
  cin >> N;

  vector<ll> c(N);
  rep(i, N) { cin >> c[i]; }
  bool ok = true;
  int cnt = 0;
  while (ok) {
    rep(i, N) {
      ok = c[i] % 2 == 0;
      if (ok) {
        c[i] /= 2;
      } else {
        break;
      }
    }
    if (ok) cnt++;
  }

  cout << cnt << endl;
}

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

using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int A[1000010],n;
long long ans=0;
int main()
{
	n=read();	
	for(register int i=1;i<=n;++i) A[i]=read()-i;
	if(n==1) 
	{cout<<0<<"\n"; return 0;}
	sort(A+1,A+n+1);
	for(register int i=1;i<=n;++i) ans+=abs(A[i]-A[n/2+1]) ;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
def main() -> None:
    board = [[int(x) for x in input().split()] for _ in range(3)]
    N = int(input())
    B = [int(input()) for _ in range(N)]
    bingo = [[False] * 3 for _ in range(3)]
    for b in B:
        for i in range(3):
            for j in range(3):
                if b == board[i][j]:
                    bingo[i][j] = True
    flag = False
    for i in range(3):
        if all(bingo[i][j] for j in range(3)):
            flag = True
        if all(bingo[j][i] for j in range(3)):
            flag = True
    if all(bingo[i][i] for i in range(3)):
        flag = True
    if all(bingo[i][2-i] for i in range(3)):
        flag = True
    print("Yes" if flag else "No")



if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  int a,b;cin >> a >> b;
  cout << (int)max( 0, a - 2*b) << "\n";
  return 0;
}


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

#define MAX 500000
int cnt;

void merge(int A[],int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1+1];
    int R[n2+1];
    for(int i = 0; i < n1; i++){
        L[i] = A[left+i];
    }
    for(int i = 0; i < n2; i++){
        R[i] = A[mid+i];
    }
    L[n1] = INFINITY;
    R[n2] = INFINITY;

    int i=0;
    int j = 0;

    for (int k = left; k < right;k++){
        cnt++;
        if(L[i] <= R[j]){
            A[k] = L[i++];
        }
        else{
            A[k] = R[j++];
        }
    }
}

void mergesort(int A[], int n,int left, int right){
    if(left+1 < right){
        int mid = (left + right)/2;
        mergesort(A,n,left,mid);
        mergesort(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}
int main(){
    int n;
    cin >> n;
    int A[MAX];
    cnt = 0;
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    mergesort(A,n,0,n);
    for(int i = 0; i < n; i++){
        if(i) cout << " ";
        cout << A[i];
    } 
    cout << endl;

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 7004
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007ll
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define db(x) cout << #x << " = " << x << '\n'
#define sep cout << "********************************************\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL)
ll a[12][12], c[12], n, m, xx;
int main(int argc, char const *argv[])
{
	fast;
	cin >> n >> m >> xx;
	for (int i = 0; i < n; ++i)
	{
		cin >> c[i];
		for (int j = 0; j < m; ++j)
		{
			cin >> a[i][j];
		}
	}
	ll ans = LLONG_MAX;
	for (int i = 0; i < (1 << n); ++i)
	{
		vll cur(m, 0);
		ll cs = 0;
		for (int j = 0; j < n; ++j)
		{
			if ((1 << j) & i)
			{
				cs += c[j];
				for (int k = 0; k < m; ++k)
				{
					cur[k] += a[j][k];
				}
			}
		}
		ll f = 1;
		for (int j = 0; j < m; ++j)
		{
			f = f && (cur[j] >= xx);
		}
		if (f)
			ans = min(ans, cs);
	}
	if (ans == LLONG_MAX)
		ans = -1;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3644
n = gets.to_i
x = gets.split.map(&:to_i)
p1 = x.inject(:+) / n
p2 = p1 + 1
puts [x.inject(0){ |acc, cur| acc + (p1 - cur) ** 2 }, x.inject(0){ |acc, cur| acc + (p2 - cur) ** 2 }].min

Measured memory_bytes: 1788
#include <stdio.h>
#include <string.h>
#include <math.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int n, d, i, j, k, cnt=0;
	scanf("%d %d", &n, &d);
	
	float x[10][10], sav;
	
	lop(i, n)lop(j, d){
		scanf("%f", &x[i][j]);
	}
	
	lop(i, n-1){
		for(j=i+1; j<n; j++){
			sav=0;
			for(k=0; k<d; k++){
				sav+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
			}
			if((int)sqrt(sav)*(int)sqrt(sav) == sav) cnt++;
		}
	}
	
	printf("%d", cnt);
	
return 0;
}

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

int main() {
    int d; cin >> d;
    if (d == 25) cout << "Christmas" << endl;
    else if (d == 24) cout << "Christmas Eve" << endl;
    else if (d == 23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; 
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define ll long long
long long min(long long x,long long y){return (x<y ? x:y);}
long long max(long long x,long long y){return (x>y ? x:y);}
#define ld long double
int stoi(string s) {return atoi(s.c_str());}
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
#define LINEY "YES\n"
#define Liney "Yes\n"
#define LINEN "NO\n"
#define Linen "No\n"

int N;
ll func(ll a[],bool grt){
  int pl = 0;
  int pr = N-1;
  ll r=0;
  if(grt){sort(a,a+N,greater<ll>());}
  else{sort(a,a+N);}
  bool turn_l = true;
  while(pl<=pr){
    if(turn_l){
      //printf("%Ld ",a[pl]);
      r += a[pl]*2*pow(-1,grt+1);
      pl++;
    }else{
      //printf("%Ld ",a[pr]);
      r -= a[pr]*2*pow(-1,grt+1);
      pr--;
    }
    turn_l = !turn_l;
  }
  //printf("\n%Ld\n",r);
  if(N%2==1){
    if(grt){
      r -= (a[pl-1]+a[pl-2]);
    }else{
	  r += (a[pl-1]+a[pl-2]);
    }
  }else{
    if(grt){
      r -= a[pl-1];
      r += a[pr+1];
    }else{
	  r += a[pl-1];
      r -= a[pr+1];
    } 
  }
  return r;
}

int main(){
  cin >>N;
  ll a[N]; REP(i,N){cin>>a[i];}
  ll r = max(func(a,true),func(a,false));
  cout << r << "\n";
}

Measured memory_bytes: 1024
def odd_solve(x)
    (x + 1) / 2 % 2
end

def solve(x)
    if x & 1 == 1
        odd_solve(x)
    else
        odd_solve(x+1) ^ (x+1)
    end
end

a, b = gets.chomp.split(" ").map(&:to_i)
puts solve(b) ^ solve(a-1)

Measured memory_bytes: 1788
/*"Everything in the universe is balanced. Every disappointment
   you face in life will be balanced by something good for you!
                Keep going, never give up."            */

#include "bits/stdc++.h"
using namespace std;


#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ordered_set<int>  os;
#define up_bound(i) os.order_of_key(i) << endl; // the number of elements in the os less than i
#define access_idx(i) *os.find_by_order(i) // print the i-th smallest number in os(0-based)

typedef double f80;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){uniform_int_distribution<int> uid(l, r); return uid(rng); }

#define ll long long int
#define ld double 
#define rep(i,a,b) for(int i=a; i<=b; ++i)
#define repd(i,a,b) for(int i=a; i>=b; --i)
#define deb cerr << "Line no." << __LINE__
#define nl '\n'
#define pb push_back
#define all(a) a.begin(),a.end()
#define P pair<ll,ll> 
#define F first
#define S second
const ll p_mod=9999999999999983;
const long double pi = 3.14159265358979323;
const ll N=1e6+9;
const ll mod=1e9+7;
ll powerk(ll x, ll y);
ll mul(ll x, ll y);
ll add(ll x, ll y);
ll sub(ll x, ll y);

ll a[N],n,dp[3003][3003];

ll go(ll x, ll y){
	if(x<1 || y>n || x>y)return 0;
	//cout<<x<<" <<"<<y<<nl;
	ll &ans = dp[x][y];
	if(ans!=-1)return ans;
	
	ll xx = go(x+1,y);
	ll yy = go(x,y-1);
	return ans = a[y]-a[x-1]-max(xx+a[x]-a[x-1],yy+a[y]-a[y-1]);
}

void solve()
{    
  ll m=0;
  cin>>n;
  memset(dp,-1,sizeof dp);
  rep(i,1,n)cin>>a[i],a[i]+=a[i-1];
  ll x = go(1,n);
  cout<<a[n]-x-x;
}


int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll t=1;
    //pre();
    //cin>>t;
    while(t--)
    {
      solve();
    }  
}
ll mul(ll x, ll y){return (x*y)%mod;}
ll add(ll x, ll y){return (x+y)%mod;}
ll sub(ll x, ll y){return (x-y+mod)%mod;}
ll powerk(ll x, ll y)
{
  if(y==0)return 1;
  if(y==1)return x%mod;
  if(y&1)
    return ((powerk((x*x)%mod, y/2)%mod)*x)%mod;
  else return powerk((x*x)%mod,y/2)%mod;
}

// Xorawar

Measured memory_bytes: 72064
#include <iostream>
#include <algorithm>

using namespace std;

typedef pair<int,string> P;

int main(){
  int n,q;
  P p[50];

  cin >> n >> q;
  for(int i = 0 ; i < n ; i++){
    cin >> p[i].first >> p[i].second;
  }
  sort(p,p+n);

  
  string ans = "kogakubu10gokan";
  int t = 0;
  for(int i = 0 ; i < n ; i++){
    if(q < p[i].first){
      t++;
      cout << ans << endl;
      break;
    }
    ans = p[i].second;
  }
  if(!t) cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1216
import java.util.*;
import java.io.*;

public class Main {
	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);
		
		int x;
		
		try{
			do{
				x = System.in.read();
				if(Character.isLowerCase((char)x))
				{
					System.out.print(Character.toUpperCase((char)x));
				}
				else
				{
					System.out.print(Character.toLowerCase((char)x));
				}
			}while((char)x!='\n');
			
		}catch(IOException e){
			e.printStackTrace();
		}
	}
}

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

using namespace std;

const int MAX_N = 100000, INDEX = 1;

struct Operation {
    int a, b;

    Operation() {
        this->a = 0;
        this->b = 0;
    }

    Operation(int a, int b) {
        this->a = a;
        this->b = b;
    }

    friend bool operator < (const Operation& a, const Operation& b) {
        if (a.a == b.a) {
            return a.b < b.b;
        }

        return a.a < b.a;
    }
};

int n, a[MAX_N + INDEX], b[MAX_N + INDEX];
long long k;

Operation operations[MAX_N + INDEX];

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

    cin >> n >> k;

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

    for (int i = 1; i <= n; i++) {
        operations[i] = Operation(a[i], b[i]);
    }

    sort(operations + INDEX, operations + INDEX + n, less<Operation>());

    long long s = 0;
    for (int i = 1; i <= n; i++) {
        s += operations[i].b;

        if (s >= k) {
            cout << operations[i].a << endl;

            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    ll a,b,x;
    cin>>a>>b>>x;
    ll s,e;
    if (!(a%x))
        s=a;
    else
        s=(a/x+1)*x;
    e=b/x*x;
    if (s<=e)
        cout<<(e-s)/x+1<<endl;
    else
        cout<<"0\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a, b, c; cin >> a >> b >> c;
  if(c-a-b < 0) {
    cout << "No" << "\n";
  } else {
    cout << (4*a*b < (c-a-b)*(c-a-b) ? "Yes" : "No") << "\n";
  }
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define rep(i, n) for(int i=0; i<n; ++i)
typedef long long ll;
//必要な宣言
#define MAX 100000

//問題をよく読もう！
//論理的に考えよう！
//サンプルを確認しよう!
//絶対に諦めるな！
//工夫をしろ！
int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int N[3];
  N[0] = A;
  N[1] = B;
  N[2] = C;

  sort(N, N+3);

  cout << N[2]*10+N[1]+N[0] << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pair<int, int>, int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MAX = 300000;
const int MOD = 1000000007;
struct Graph{int to,coin; ll cost;};
struct Edge{int from,to,coin; ll cost;};
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n;cin>>n;
    ll pre = 0;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        ll a;cin>>a;
        ans += max(0LL,pre-a);
        pre = a + max(0LL,pre-a);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3528
#include<stdio.h>
#include<algorithm>
#include<utility>
using namespace std;
  
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  printf("%s",(min(a,b)<c && c<max(b,a)) ? "Yes" : "No" );
  return 0; 
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); 
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    long long N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    for (int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i], --A[i], --B[i];
    }
    UnionFind uf(N);
    long long cur = N * (N-1) / 2;
    vector<long long> res;
    for (int i = 0; i < M; ++i) {
        res.push_back(cur);
        int a = A[M-1-i], b = B[M-1-i];
        if (uf.issame(a, b)) continue;
        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); ++i) cout << res[i] <<endl;
}

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

void chmin(int& a, int b){
    a = min(a, b);
}

int main(){
    int N, A[200000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];

    static int dp[200001][5];
    for(int i=0; i<=N; i++) for(int j=0; j<=4; j++) dp[i][j] = 1e9;
    dp[0][0] = 0;

    for(int i=0; i<N; i++){
        chmin(dp[i+1][0], dp[i][0] + A[i]);
        for(int j=1; j<=3; j++){
            int prv = 1e9;
            for(int j2=0; j2<=j; j2++) chmin(prv, dp[i][j2]);
            int add;
            if(A[i] == 0 && j%2 == 1){
                add = 2;
            }else{
                add = (A[i]%2 == j%2);
            }
            chmin(dp[i+1][j], prv + add);
        }
        int prv = 1e9;
        for(int j2=0; j2<=4; j2++) chmin(prv, dp[i][j2]);
        chmin(dp[i+1][4], prv + A[i]);
    }
    int ans = 1e9;
    for(int j=0; j<=4; j++) chmin(ans, dp[N][j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


def factor(n, m=None):
    # mを与えると、高々その素因数まで見て、残りは分解せずにそのまま出力する
    arr = {}
    temp = n
    M = min(m+1, int(-(-n**0.5//1))+1)
    for i in range(2, M):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr[i] = cnt

    if temp!=1:
        arr[temp] = 1

    if not arr:
        arr[n] = 1

    return arr

n = int(input())
f = factor(n, n)
ans = 0
if n==1:
    print(0)
else:
    for k,v in f.items():
        i = 1
        while v>=i:
            v -= i
            i += 1
            ans += 1
    print(ans)

Measured memory_bytes: 63368
def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table
  

N=int(input())
#################################
ans = 0
#for i in range(1,N):
#  ans += num_divisors_table(i)

#print(ans)


a = num_divisors_table(N)
#print(a)
print(sum(a[1:-1]))
  


  
  

Measured memory_bytes: 83364
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;

int main() {
  int n, m;
  ll sum=0;
  cin >> n >> m;
  rep(i, m) {
    int a;
    cin >> a;
    sum += a;
  }
  if(n < sum) cout << -1 << endl;
  if(n >= sum) cout << n-sum << endl;
  return 0;
}

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

int main(){
    int n,a;
    cin>>n>>a;
    vector<priority_queue<int> > q(n);
    while(a--){
        int y;
        cin>>y;
        if(y==0){
            int t,x;
            cin>>t>>x;
            q[t].push(x);
        }
        else if(y==1){
            int t;
            cin>>t;
            if(!q[t].empty()){
                cout<<q[t].top()<<endl;
            }
        }
        else{
            int t;
            cin>>t;
            if(!q[t].empty()){
                q[t].pop();
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4052
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        int x = Integer.parseInt(br.readLine());
        double[] vectorA = new double[x];
        double[] vectorB = new double[x];

        String[] input = br.readLine().split(" ");
        for(int i = 0; i < x; i++)  vectorA[i] = Double.parseDouble(input[i]);
        input = br.readLine().split(" ");
        for(int i = 0; i < x; i++)  vectorB[i] = Double.parseDouble(input[i]);

        double d1 = 0;
        double d2 = 0;
        double d3 = 0;
        double dinf = 0;

        for(int i = 0; i < x; i++){ 
            double abs = Math.abs(vectorA[i]-vectorB[i]);
            d1 += abs;
            d2 += Math.pow(abs , 2);
            d3 += Math.pow(abs , 3);
            dinf = Math.max(dinf , abs);
        }

        d2 = Math.sqrt(d2);
        d3 = Math.cbrt(d3);

        System.out.println(d1);
        System.out.println(d2);
        System.out.println(d3);
        System.out.println(dinf);
    }
}

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

using namespace std;

int main()
{
  string x[3]; cin >> x[0] >> x[1] >> x[2];

  char cur = x[0][0];
  while (true) {
    if (x[cur-'a'].size() == 0) {
      cout << char(cur - 32);
      return 0;
    }
    char tmp = cur;
    cur = x[cur-'a'][0];
    x[tmp-'a'].erase(x[tmp-'a'].begin()+0);
  }
}

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

using namespace std;

int main()
{
    int n;
    vector<int> a;
    int i;
    int max1=0;
    int max2=0;

    cin >> n;
    for(i=0;i<n;i++){
        int n1;
        cin >> n1;
        a.emplace_back(n1);
        if(max1<n1){
            max1=n1;
        }else if(max2<n1){
            max2=n1;
        }
    }

    for(i=0;i<n;i++){
        if(max1==a[i]){
            cout << max2 <<endl;
        }else{
            cout << max1 << endl;
        }
    }

}

Measured memory_bytes: 2548
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))

def main():
    def qFromA(a):
        print("?", *list(range(a, a + n)))

    n = int(input())
    ans = [-1] * (2 * n + 1)

    # 二分探索で、切り替わりポイントを探す
    qFromA(1)
    if input() == "Red":
        r, b = 1, 1 + n
    else:
        r, b = n + 1, 1
    while abs(r - b) > 1:
        m = (r + b) // 2
        qFromA(m)
        if input() == "Red":
            r = m
        else:
            b = m
    # print(r, b)
    # red=1,blue=0
    if r < b:
        ans[r], ans[r + n] = 1, 0
    else:
        ans[b], ans[b + n] = 0, 1
    # print(ans)
    min_rb = min(r, b)
    even0 = list(range(min_rb + 1, min_rb + n))
    even1 = list(range(1, min_rb)) + list(range(min_rb + n + 1, 2 * n + 1))
    # print(even0)
    # print(even1)

    # 赤と青が同じ区間evenを使って残りの判定
    for x in even0:
        print("?", x, *even1)
        ans[x] = input() == "Red"
    for x in range(1, 2 * n + 1):
        if ans[x] != -1: continue
        print("?", x, *even0)
        ans[x] = input() == "Red"
    # 出力
    print("! ", end="")
    for c in ans[1:]:
        if c:
            print("R", end="")
        else:
            print("B", end="")
    print()

main()


Measured memory_bytes: 3532
#include<iostream>
#include<vector>
#include<unordered_set>
#include<algorithm>
#include<iterator>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    const int ma = 1000001;
    for(int i=0; i<N; i++){
        int t;
        cin >> t;
        A.at(i) = B.at(i) = t;
    }
    sort(B.begin(), B.end());
    vector<int> l(ma);
    vector<int> v(ma);
    for(int i=0; i<N; i++){
        int t = B.at(i);
        if(v.at(t) > 0 || l.at(t) == 1){
            v.at(t) += 1;
            continue;
        }else{
            v.at(t) = 1;
        }
        int x = 2*t;
        while(x < ma){
            l.at(x) = 1;
            x += t;
        }
    }
    int r = 0;
    for(int i=0; i<N; i++){
        int t = A.at(i);
        if (l.at(t) == 0 && v.at(t) == 1){
            r += 1;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 12764