akhauriyash/Code-Regression huggingface dataset:
W,H = map(int, input().split())
P = [0] * W
Q = [0] * H
for i in range(W):
  P[i] = int(input())
for i in range(H):
  Q[i] = int(input())
  
P.sort()
Q.sort()
cumP = [0] * (W+1)
cumQ = [0] * (H+1)
for i in range(W):
  cumP[i+1] = cumP[i] + P[i]
for i in range(H):
  cumQ[i+1] = cumQ[i] + Q[i]
  
#print(cumP)
#print(cumQ)
y,x = 0,0
cost = 0
while y <= H and x <= W:
  #print(x,y)
  # 右か下にコストが安いほうにいけばよい。イコールなら任意でよい。
  if x == W and y == H:
    break
  elif x == W:
    cost += Q[y]
    y += 1
    cost += cumP[x]    
  elif y == H:
    cost += P[x]
    x += 1
    cost += cumQ[y]
  elif P[x] <= Q[y]:
    cost += P[x]
    x += 1
    cost += cumQ[y]
  else:
    cost += Q[y]
    y += 1
    cost += cumP[x]
    
print(cost)

Measured memory_bytes: 28292
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#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>
#include <climits>

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;
const char ENDL = '\n';

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int n;
    cin >> n;
    VI a(n);
    REP(i,n){
        cin >> a[i];
    }

    int ans = LLONG_MAX;

    FOR(i,-100,101){
        int c=0;
        REP(j,n){
            c += (a[j]-i)*(a[j]-i);
        }
        ans = min(ans,c);
    }

    cout << ans << ENDL;
    
    return 0;
}

Measured memory_bytes: 768
a, b, c = input()  # 1234を整数(int)型ではなく、文字列(str)型で変数に格納する
if(a=="7" or b=="7" or c=="7"): print("Yes")
elif( a=="7" and b=="7"): print("Yes")
elif( c=="7" and b=="7"): print("Yes")
elif( c=="7" and a=="7"): print("Yes")
elif(a=="7" and b=="7" and c=="7"): print("Yes")
else:print("No")

Measured memory_bytes: 9064
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int max(int a, int b) {
	if (a < b)return b;
	return a;
}
int min(int b, int a) {
	if (a > b)return b;
	return a;
}

int main() {
	llint n, t;
	cin >> n >> t;
	hei(int)a(n);
	rep(i, 0, n)cin >> a[i];
	llint ans = t;
	rep(i, 0, n-1) {
		ans += min(t, a[i + 1] - a[i]);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int i=0,j=0,k=0;
  int N=0,temp=0;
  int num[100];
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&num[i]);
  }
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",num[i]);
  }
  printf("\n");
  for(i=1;i<N;i++){
    temp=num[i];
    j=i-1;
    while(j>=0&&num[j]>temp){
      num[j+1]=num[j];
      j--;
    }
    num[j+1]=temp;
    for(k=0;k<N;k++){
      if(k>0)printf(" ");
      printf("%d",num[k]);
    }
    printf("\n");
  }
  return 0;
}



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

#define LL long long
#define hell 998244353
#define PI 3.1415926535897932385



int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << showpoint;
cout << setprecision(11);

int n;cin>>n;
LL v[n];for(int i=0;i<n;i++) cin>>v[i];

LL ar[30][n];

memset(ar, 0, sizeof(ar));

for(int i=0;i<30;i++)
{
  int ct = 0;
  vector<int>ev, od;
  for(int j=0;j<n;j++)
  {
     if((1ll)<<i & v[j])
     {
         ct+=1;
         ev.push_back(j);
     }
     else
     {
      od.push_back(j);
     }
  }
  if(ct%2==0)
  {
     for(int j=0;j<ev.size();j++)
     {
      ar[i][ev[j]]=1;
     }
  }
  else
  {
     for(int j=0;j<od.size();j++)
     {
      ar[i][od[j]]=1;
     }
  }
}
vector<int>ans;

for(int i=0;i<n;i++)
{
  LL sv = 0;
  for(int j=0;j<30;j++)
  {
    sv+=(1ll<<j)*(ar[j][i]);
  }
  ans.push_back(sv);
}
for(int i=0;i<n;i++)
{
  cout<<ans[i]<<" ";
}

return 0;
}

Measured memory_bytes: 53440
#include<stdio.h>
int main(void)
{
	int N,D,i;
	int sum=0;
	scanf("%d%d",&N,&D);
	for(i=1;i<100;i++)
	{
		sum=(2*D+1)*i;
		if(sum>=N)
		break;
	}
	printf("%d",i);
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

ll dp[101][1<<17];//i人目まで、bitの立っている位置を被覆いているときの満足度の最大値
int main()
{
	int n;
	ll ans;
	int ch[100];
	ll l[100];
	int st[100][16];
	int en[100][16];
	while(1)
	{
		cin>>n;
		if(n==0)
			break;
		for(int i=0;i<n;i++)
		{
			cin>>ch[i]>>l[i];
			for(int j=0;j<ch[i];j++)
			{
				cin>>st[i][j]>>en[i][j];
				st[i][j]-=6;
				en[i][j]-=6;
			}
		}
		fill(dp[0],dp[101],0);
		//start dp
		for(int i=1;i<n+1;i++)
		{
			//i番目の人とのデートで使う時間
			int date=0;
			for(int j=0;j<ch[i-1];j++)
			{
				for(int k=st[i-1][j];k<en[i-1][j];k++)
					date|=(1<<k);
			}
			for(int j=0;j<(1<<17);j++)
			{
				if((j&date)==date)
					dp[i][j]=max(dp[i-1][j],dp[i-1][j^date]+l[i-1]);
				else
					dp[i][j]=dp[i-1][j];
			}
		}
		//end dp
		ans=0;
		for(int i=0;i<(1<<17);i++)
			ans=max(ans,dp[n][i]);
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 106448
x = int(input())
N = 1000000
def solve():
    primes = [False] * N
    for i in range(2, N):
        if primes[i]:
            continue
        for j in range(i*i, N, i):
            primes[j] = True

        if i >= x:
            print(i)
            return

solve()

Measured memory_bytes: 10740
#include <iostream>

using namespace std;
int main()
{
    int a;
    int b;
    int c;
    int k;
    cin >> a >> b >> c >> k;
    while (b <= a and k > 0) {
        b = b*2;
        k--;
    }
    while (c <= b and k > 0) {
        c = c*2;
        k--;
    }
    if (((c > b) and (b > a))) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 3048
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var line = ReadLine().Split(' ');
			var number = int.Parse(line[0] + line[1] + line[2]);
			WriteLine(number % 4 == 0 ? "YES" : "NO");
		}
	}
}


Measured memory_bytes: 11092
#include<stdio.h>
#include<math.h>

int main(void)
{
	int i,n,x[1000],y[1000];
	double D1,D2,D3,D8;
	
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&x[i]);
	}
	for(i = 0;i < n;i++){
		scanf("%d",&y[i]);
	}
	
        for(i = 0;i < n;i++){
		D1 += fabs(x[i] - y[i]);
	}
	printf("%f\n",D1);
        
	for(i = 0;i < n;i++){
		D2 += pow(fabs(x[i] - y[i]),2);
	}
        printf("%f\n",sqrt(D2));

	for(i = 0;i < n;i++){
		D3 += pow(fabs(x[i] - y[i]),3);
	}
	printf("%f\n",cbrt(D3));

	D8 = fabs(x[0] - y[0]);
	for(i = 1;i < n;i++){
		if(D8 < fabs(x[i] - y[i])){       
			D8 = fabs(x[i] - y[i]);
		}
	}
	printf("%f\n",D8);
	return 0;
}	

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

int main(){
    int n,m,q;
    cin >> n >> m >> q;
    list<int> li;

    for(int i=0;i<n;i++){
        li.push_back(i);
    }

    list<int>::iterator btn(li.begin());
    for(int i=0;i<m;i++){   //バトン回す
        int a;  cin >> a;

        if(a%2==0){
            for(int j=0;j<a;j++){
                btn++;
                if(btn==li.end())
                    btn = li.begin();
            }
        }else{
            for(int j=0;j<a;j++){
                if(btn==li.begin())
                    btn = li.end();
                btn--;
            }
        }

        list<int>::iterator it(btn);
        btn++;
        if(btn==li.end())
            btn = li.begin();
        
        li.erase(it);
    }

    for(int i=0;i<q;i++){   //判定する
        int a;  cin >> a;

        list<int>::iterator it;

        for(it=li.begin();it!=li.end();it++){
            if(*it==a)  break;
        }

        if(it!=li.end())
            cout << 1 << endl;
        else{
            cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 9336
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
//using ll = long long;
//using P = pair<int,int>;

int main(){
 string s;
  int counts;
  cin >> s;
  rep(i,3) {
  if(s.at(i) == 'o')
    counts++;
  }
  cout << 700 + counts*100 << endl;
}

Measured memory_bytes: 3460
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<tuple>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

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

	int n;
	cin >> n;

	int tmp,a,b;
	bool flag;
	for(int i=n;i<=999;i++){
		tmp = i;
		a=tmp%10;
		tmp/=10;
		flag = false;
		for(int j=0;j<2;j++){
			b=tmp%10;
			if(a!=b){
				flag=true;
				break;
			}
			tmp/=10;
		}
		if(!flag){
			cout << i << "\n";
			return 0;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
const int maxn=50;
int n;
int a[maxn];
int fib(int n)
{
    a[0]=1;
    a[1]=1;
    for(int i=2;i<=n;i++) a[i]=a[i-2]+a[i-1];
    return a[n];
}
int main()
{
//    freopen("in.txt","r",stdin);
    scanf("%d",&n);
    printf("%d\n",fib(n));

    return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

using C = complex<double>;
double pi = acos(-1.0);

void FFT(vector<C>& A, bool inv) {
 int N=A.size();
 for(int i=0,j=0; j<N; j++){
  if(i<j) swap(A[i],A[j]);
  for(int k=N>>1; k>(i^=k); k>>=1);
 }
 for(int i=1; i<N; i<<=1){
  C q = C(cos(pi/i),sin(pi/i)*(inv?1.0:-1.0));
  C qj = C(1.0,0.0);
  rep(j,i){
   for(int k=j; k<N; k+=i*2){
    C l=A[k], r=A[k+i]*qj;
    A[k]=l+r;
    A[k+i]=l-r;
   }
   qj*=q;
  }
 }
 if(inv) rep(i,N) A[i]/=N;
}

vector<C> CONV(const vector<C>& A,const vector<C>& B) {
 int Z=1; while(Z<A.size()+B.size()) Z<<=1;
 vector<C> ans(Z),Ax(Z),Bx(Z);
 rep(i,Z) Ax[i]=Bx[i]=0;
 rep(i,A.size()) Ax[i]=A[i];
 rep(i,B.size()) Bx[i]=B[i];
 FFT(Ax,false);
 FFT(Bx,false);
 rep(i,Z) ans[i]=Ax[i]*Bx[i];
 FFT(ans,true);
 return move(ans);
}

const ULL M=200003;
int N;
ULL I[M];
vector<C> A;
vector<C> V;

int main() {
 scanf("%d", &N);
 for (int i=0,j=1; i<M-1; i++,j=j*2%M) I[j]=i;
 A.resize(M-1);

 ULL sq=0;
 rep(i, N) {
  int a; scanf("%d",&a);
  if(a) A[I[a]] += C(1.0,0.0);
  sq += (ULL)a*a%M;
 }
 V = CONV(A,A);

 ULL ans=0;
 for (int i=0,j=1; i<V.size(); i++,j=j*2%M)
  ans += (ULL)(V[i].real()+0.5)*j;
 ans = (ans-sq)/2;

 cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 32544
import math

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

n=int(input())

l=prime_factorize(n)
c=0
ls=set(l)

ln=[]
for i in iter(ls):
    s=0
    for j in l:
        if i==j:
            s+=1
    ln.append(s)



for i in range(len(ln)):
    c+=int((math.sqrt(1+8*ln[i])-1)/2)

print(c)

Measured memory_bytes: 9232
#include <bits/stdc++.h> 
using namespace std; 
  
int MinimumNumIncreasingSubsequences(int arr[], int n) 
{ 
    multiset<int> last; 
  
    // last element in each  increasing subsequence  
    // found so far 
    for (int i = 0; i < n; i++) { 
  
        // here our current element is arr[i] 
        multiset<int>::iterator it = last.lower_bound(arr[i]); 
  
        // iterator to the first element larger  
        // than or equal to arr[i] 
        if (it == last.begin()) 
  
            // if all the elements in last larger 
            // than or to arr[i] then insert it into last 
            last.insert(arr[i]); 
  
        else { 
            it--; 
  
            // the largest element smaller than arr[i] is the number 
            // before *it which is it-- 
            last.erase(it); // erase the largest element smaller than arr[i] 
            last.insert(arr[i]); // and replace it with arr[i] 
        } 
    } 
    return last.size(); // our answer is the size of last 
} 
  
// Driver program 
int main() 
{ 
    int n;
    cin >> n;
    int arr[n];
  for(int i=0;i<n;i++)
    cin >> arr[i];
    cout << MinimumNumIncreasingSubsequences(arr, n); 
    return 0; 
} 

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

int main(){
  string s;
  cin>>s;
  for(int i=s.size()-1;0<i;i--){
    s.erase(i);
    int sz=s.size();
    if(sz%2==0){
      int mid=sz/2;
      string x=s.substr(0,mid);
      string y=s.substr(mid);
      if(x==y) { cout<<sz; return 0; }
    }
    else continue;
  }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define LINE_BUF_SIZE  1024
#define NUM_DATA 10
#define SHOW_NUM 3

void BubSort(int x[ ], int n)
{
    int i, j, temp;

    for (i = 0; i < n - 1; i++) {
        for (j = n - 1; j > i; j--) {
            if (x[j - 1] < x[j]) {
                temp = x[j];
                x[j] = x[j - 1];
                x[j - 1]= temp;
            }
        }
    }
}
void ShowData(int x[ ], int n)
{
    int i;

    for (i = 0; i < n ; i++)
        printf("%d\n", x[i]);
}

int main(void)
{
    int x[LINE_BUF_SIZE];
    int i = 0;

    for (i ; i < NUM_DATA; i++) {
        int n;
        scanf("%d", &n);
        x[i] = n;
    }

    BubSort(x, NUM_DATA);
    ShowData(x, SHOW_NUM);

    return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int sX, sY;
bool yx;
void put(int x, int y, bool end = false) {
  if(yx) std::swap(x, y);
  x*=sX; y*=sY;
  std::cout << x << " " << y << "\n";
  if(end) exit(0);
}

int main() {
  int K, X, Y; std::cin >> K >> X >> Y;
  sX = sY = 1; yx = false;
  if(X < 0) { sX = -1; X = -X; }
  if(Y < 0) { sY = -1; Y = -Y; }
  if(X < Y) { std::swap(X, Y); yx = true; }
  int m = X+Y;
  if(m%2 == 1 && K%2 == 0) fin(-1);
  if(m == K) {
    std::cout << 1 << "\n";
    put(X, Y, true);
  }
  int n = 2;
  if(m < K) {
    if(m%2 == 1) { // K should be also odd
      int fx = (K+X-Y)/2;  // X < fx < K
      std::cout << 3 << "\n";
      put(0, -K); put(fx, -fx); put(X, Y, true);
    }
  } else {
    n = (m+K-1)/K;        // ceil(m/K)
    if((m+n*K)%2==1) ++n;
  }
  std::cout << n << "\n";
  int fy = (K*n-m)/2, x, y; // 0 <= fy < K
  put(x = K-fy, y = -fy);
  while(x+K <= X) put(x += K, y);
  fy = K - (X - x);
  put(X, y += fy);
  while(y < Y) put(X, y+=K);
  return 0;
}


Measured memory_bytes: 2304
#include <iostream>
#include <vector>
using namespace std;
int main(){
    long N;
    cin >> N;
    vector<int>A(N);
    vector<int>ans(N,0);
    for(int i=1;i<N;i++){
        cin >> A[i];
    }
    for(int i=1;i<N;i++){
        ans[A[i]-1]++;
    }
    for(int i=0;i<N;i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 4368
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }
    
    return b ? gcd(b, a % b) : a;
}
  int main(){
   int K;
   cin >> K;
   long long sum = 0;
   for(int i = 1; i <= K; i++) {
      for(int j = 1; j <= K; j++) {
         for(int l = 1; l <= K; l++) {
            sum += gcd(gcd(i,j),l);
         }
      }
   }

   cout << sum;
 return 0;

}

Measured memory_bytes: 3632
class UnionFind:
    def __init__(self, n):
        self.par = range(n)
        self.rank = [0 for i in xrange(n)]

    def find(self, x):
        if self.par[x] == x:
            return x
        self.par[x] = self.find(self.par[x])
        return self.par[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1


class Edge:
    def __init__(self, u, v, cost):
        self.u = u
        self.v = v
        self.cost = cost

def kruskal(es, V):
    es.sort(key=lambda x: x.cost)
    unionfind = UnionFind(V)
    res = 0
    for e in es:
        if unionfind.same(e.u, e.v):
            continue
        unionfind.union(e.u, e.v)
        res += e.cost
    return res

if __name__ == '__main__':
    n = int(raw_input())
    es = []
    for i in xrange(n):
        vs = map(int, raw_input().split())
        for j in xrange(i):
            if vs[j] != -1:
                es.append(Edge(i, j, vs[j]))

    print kruskal(es, n)

Measured memory_bytes: 5584
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
int main() {
  cin >> n;
  lli a=0, b=0, c=0;
  for (lli i=0; i<n; ++i) {
    lli x; cin >> x;
    if (!(x%4)) ++a;
    else if (!(x%2)) ++b;
    else ++c;
  }
  bool ok = b>0 ? a >= c : a+1 >= c;
  auto ans = ok ? "Yes" : "No";
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] X = new int[N];
		int[] Y = new int[N];
		TreeSet<Integer> xset = new TreeSet<Integer>();
		TreeSet<Integer> yset = new TreeSet<Integer>();
		for (int i = 0; i < N; ++i) {
			X[i] = Integer.parseInt(sc.next());
			Y[i] = Integer.parseInt(sc.next());
			xset.add(X[i]);
			yset.add(Y[i]);
		}
		xset.add(Integer.MIN_VALUE);
		xset.add(Integer.MAX_VALUE);
		yset.add(Integer.MIN_VALUE);
		yset.add(Integer.MAX_VALUE);
		HashMap<Integer, Integer> xs = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> ys = new HashMap<Integer, Integer>();
		int[] xpos = new int[xset.size()];
		for (int xv : xset) {
			xpos[xs.size()] = xv;
			xs.put(xv, xs.size());
		}
		int[] ypos = new int[yset.size()];
		for (int yv : yset) {
			ypos[ys.size()] = yv;
			ys.put(yv, ys.size());
		}
		int xl = xs.size();
		int yl = ys.size();
		int[][] dp = new int[xl][yl];
		for (int i = 0; i < N; ++i) {
			dp[xs.get(X[i])][ys.get(Y[i])]++;
		}
		for (int i = 1; i < xl; ++i) {
			for (int j = 1; j < yl; ++j) {
				dp[i][j] += dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
			}
		}
		for (int i = 0; i < M; ++i) {
			int x1 = pos(xpos, Integer.parseInt(sc.next()), true);
			int y1 = pos(ypos, Integer.parseInt(sc.next()), true);
			int x2 = pos(xpos, Integer.parseInt(sc.next()), false);
			int y2 = pos(ypos, Integer.parseInt(sc.next()), false);
			System.out.println(x1 > x2 || y1 > y2 ? 0 : dp[x2][y2] - dp[x2][y1 - 1] - dp[x1 - 1][y2] + dp[x1 - 1][y1 - 1]);
		}
	}

	static int pos(int[] coord, int p, boolean up) {
		int ret = Arrays.binarySearch(coord, p);
		if (ret < 0) ret = -ret - (up ? 1 : 2);
		if (ret >= coord.length) ret = coord.length - 1;
		return ret;
	}

}

Measured memory_bytes: 361320
let input = require('fs').readFileSync( '/dev/stdin', 'utf8' );
let arr = input.split(" ").map(Number);
let a = arr[0];
let b = arr[1];
let c = arr[2];
let count = 0;
for (let i = a; i <= b; i ++) {
    if (c % i === 0) count ++;
}
console.log(count);


Measured memory_bytes: 15308
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    int n,l; cin>>n>>l;
    int a[n];
    int ans=1001001,s=0;
    rep(i,0,n){
        a[i]=l+i;
        ans=min(ans,abs(a[i]));
    } 
    rep(i,0,n){
        if(abs(a[i])==ans) continue;
        else s+=a[i];
    }
    cout<<s<<endl;
    // cout<<ans<<endl;
}

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

int main()
{

    //  #ifndef oj
    //freopen("in", "r", stdin);
    //freopen("out.txt","w",stdout);
    //#endif
    // system("cls");
    //getchar();

    int a,b;
    cin>>a>>b;
    if((a==1 && b==2) || (a==2 && b==1))
        cout<<3<<endl;
    else if((a==2 && b==3) || (a==3 && b==2))
        cout<<1<<endl;
    else cout<<2<<endl;
}


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

ll combo(ll a, ll b){
  if(b==0) return 1;
  else{
  ll ue=1;
  ll shita=1;
  for(ll i=a; i>=a-b+1; i--) ue*=i;
  for(ll i=1; i<=b; i++) shita*=i;
  return ue/shita;
  }
}

int main(){
  ll N, P; cin>>N>>P;
  vector<ll> B(N);
  ll odd=0;
  ll even=0;
  for(ll i=0; i<N; i++){
    ll A; cin>>A;
    if(A%2==0) even++;
    if(A%2==1) odd++;
  }
  ll ans;
  if(odd==0 && P==0) ans=pow(2, N);
  else if(odd==0 && P==1) ans=0;
  else ans=pow(2, N-1);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
local n,k=io.read("n","n")
local x={}
for i=1,n do
    x[i]=io.read("n")
end

local min=math.maxinteger
for i=1,n-k+1 do
    local l=i
    local r=k+i-1
    local ltor=math.abs(x[l])+math.abs(x[r]-x[l])
    local rtol=math.abs(x[r])+math.abs(x[r]-x[l])
    min=math.min(min,ltor,rtol)
end
print(min)

Measured memory_bytes: 2552
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b)
{
	ll res = 1;
	a %= mod;
	assert(b >= 0);
	for (; b; b >>= 1)
	{
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
	}
	return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

static uint MD = mod;
struct ModInt
{
	using M = ModInt;
	uint v;
	ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
	M &set_v(uint _v)
	{
		v = (_v < MD) ? _v : _v - MD;
		return *this;
	}
	explicit operator bool() const { return v != 0; }
	M operator-() const { return M() - *this; }
	M operator+(const M &r) const { return M().set_v(v + r.v); }
	M operator-(const M &r) const { return M().set_v(v + MD - r.v); }
	M operator*(const M &r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
	M operator/(const M &r) const { return *this * r.inv(); }
	M &operator+=(const M &r) { return *this = *this + r; }
	M &operator-=(const M &r) { return *this = *this - r; }
	M &operator*=(const M &r) { return *this = *this * r; }
	M &operator/=(const M &r) { return *this = *this / r; }
	bool operator==(const M &r) const { return v == r.v; }
	M pow(ll n) const
	{
		M x = *this, r = 1;
		while (n)
		{
			if (n & 1)
				r *= x;
			x *= x;
			n >>= 1;
		}
		return r;
	}
	M inv() const { return pow(MD - 2); }
	friend ostream &operator<<(ostream &os, const M &r) { return os << r.v; }
};
using Mint = ModInt;
//head
// cin >> t;
// for (int cas = 1; cas <= t; ++cas)
// {
// 	cout << "Case #" << cas << ": ";
// }
int main()
{
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll x;
	cin>>x;
	ll a = 100;
	int cnt=0;
	while(true) {
		cnt++;
		ll b = a/100;
		a += b;
		if(a >= x) break;
	}
	cout<<cnt<<endl;
	return 0;
}


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

long long a[200010];

int main(void){
	int n;
	long long ans=0, x=0, s=0;
	cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		s += a[i];
	}
	for(int i=0; i<n-1; i++){
		x += a[i];
		if(i==0 || ans>abs(2*x-s)) ans = abs(2*x-s);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main{
    public static void main(String arg[]){
        Scanner sc=new Scanner(System.in);
        while(true){
            int n=sc.nextInt();
            if(n==0)break;
            int[] s=new int[n];
            double m=0,ans=0;
            for(int i=0;i<n;i++){
                s[i]=sc.nextInt();
                m+=s[i];
            }
            m/=n;
            for(int i=0;i<n;i++)ans+=Math.pow(s[i]-m,2);
            ans/=n;
            System.out.println(Math.sqrt(ans));
        }
        sc.close();
    }
}


Measured memory_bytes: 31460
a,b,m = map(int,input().split())
aprice = list(map(int,input().split()))
bprice = list(map(int,input().split()))
waribiki = [list(map(int, input().split())) for i in range(m)]
minprice = min(aprice)+min(bprice)
for i in range(len(waribiki)):
         tmp = aprice[waribiki[i][0]-1]+bprice[waribiki[i][1]-1]-waribiki[i][2]
         if minprice > tmp:
                  minprice = tmp
print(minprice)



Measured memory_bytes: 38564
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll n;cin>>n;
    set<string>ma;
    rep(i,n){
        string s;cin>>s;
        ma.insert(s);
    }
    cout<<ma.size()<<endl;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll MOD = (ll)1e9 + 7;

ll f(ll n) {
	ld a = (sqrtl(24*n+1)-1)/6;
	return ll(a);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cout.precision(20);
    cout << fixed;
	ll ans=0;
	ll n,k;
	cin>>n>>k;
	vll A(n);
	while(k--){
		ll x;
		cin>>x;
		for(int i=0;i<x;i++)
		{
			ll y;
			cin>>y;y--;
			A[y]++;
		}
	}
	for(auto i:A)
		ans+=(i==0);
	cout<<ans;

}


Measured memory_bytes: 3580
//
// Created by nhatminh2947 on 7/3/19.
//

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1000000007;

long long dp[2001][2001];
int n, k;

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

    int blue = k;
    int red = n - k;
    for (int i = 0; i <= 2000; ++i) {
        dp[i][0] = 1;
    }

    for (int i = 1; i <= 2000; ++i) {
        for (int j = 1; j <= 2000; ++j) {
            dp[i][j] = (dp[i - 1][j - 1] % MOD + dp[i - 1][j] % MOD) % MOD;
        }
    }

    for (int i = 1; i <= k; ++i) {
        cout << (dp[blue - 1][i - 1] % MOD * dp[red + 1][i] % MOD) % MOD << endl;
    }


    return 0;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
 
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<(int)1e9 + 7>;

int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int d, l, r;
    cin >> l >> r >> d;

    cout << r / d - (l - 1) / d << '\n';
    return 0; 
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
const int  N = 2e5 + 314;
void foo(){
    int a, b, c;
    cin>>a>>b>>c;
    if(a+b+c>=22)cout<<"bust";
    else cout<<"win";
}
int main(){
    speed;
    int t=1;
    //cin>>t;
    while(t--)foo();
}

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

typedef long long                   ll;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
typedef pair<string , string>       pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define F                           first
#define S                           second
#define sep                         ' '
#define file_io                     freopen("input.txt" , "r+" , stdin) ; freopen("output.txt" , "w+" , stdout);
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define error(x)                    cerr << "$$$ " << x << '\n';
#define error2(x,y)                 cerr << "#F : " << x << "      #S : " << y << '\n';
#define pb                          push_back

const ll MX5 = 2*1e5+3;
const ll MX6 = 2*1e6+3;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
const ll MOD2= 998244353;

ll power(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));
}
ll bmm(ll a,ll b){
    return (a%b==0 ? b : bmm(b,a%b));
}

ll A[MX5];
ll dp[MX5];
int main(){
    fast_io
    //file_io
    ll n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    dp[0]=0;
    for(int i=1;i<n;i++){
        if(i==1){
            dp[i]=abs(A[i-1]-A[i]);
        }
        else{
            dp[i]=min(abs(A[i-1]-A[i])+dp[i-1],abs(A[i-2]-A[i])+dp[i-2]);
        }
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
N = int(input())
L = list(map(int, input().split()))
M = max(L)

cntL = [0] * (M + 1)
for l in L:
    cntL[l] += 1

accCntL = [0] * (M + 2)
for i in range(1, M + 2):
    accCntL[i] = accCntL[i - 1] + cntL[i - 1]

ans = 0
for i, A in enumerate(L):
    for j, B in enumerate(L):
        if i == j:
            continue

        right = min(A + B, M + 1)
        left = abs(A - B) + 1
        ans += accCntL[right] - accCntL[left]

        if left <= A < right:
            ans -= 1
        if left <= B < right:
            ans -= 1

print(ans // 6)


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    string s;
    cin >> s;
    rep(i, s.size()) {
        s[i] = 'x';
    }
    out(s);
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        int a = ReadInt();
        int b = ReadInt();
        String str = String.format("%.6f", (double)a / b);
        System.out.println(a / b + " " + a % b + " " + str);
    }
    static int ReadInt() throws IOException {
        return Integer.parseInt(sc.next());
    }
}

Measured memory_bytes: 26352
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()

using namespace std;

vector<int> arr;
int top, bottom;

void north()
{
    swap(arr[2], top);
    swap(top, arr[0]);
    swap(arr[0], bottom);
}

void east()
{
    swap(arr[1], top);
    swap(top, arr[3]);
    swap(arr[3], bottom);
}

void right()
{
    swap(arr[0], arr[1]);
    swap(arr[1], arr[2]);
    swap(arr[2], arr[3]);
}

int main(int argc, char const* argv[])
{
    while (1) {
        arr = { 2, 3, 5, 4 };
        top = 1, bottom = 6;
        int T; cin >> T;
        if (!T) break;
        int ans = 1;
        while (T--) {
            string cmd; cin >> cmd;
            if (cmd == "North") north();
            if (cmd == "South") loop (3, i) north();
            if (cmd == "East") east();
            if (cmd == "West") loop (3, i) east();
            if (cmd == "Right") right();
            if (cmd == "Left") loop (3, i) right();
            ans += top;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int k;
vector<ll> v;
void dfs(ll cur,int cnt){
    v.pb(cur);
    if(cnt==9) return;
    if(cur%10>0) dfs(cur*10+cur%10-1,cnt+1);
    dfs(cur*10+cur%10,cnt+1);
    if(cur%10<9) dfs(cur*10+cur%10+1,cnt+1);
}
int main(){
    cin>>k;
    FOR(i,1,10){
        dfs(i,0);
    }
    sort(v.begin(),v.end());
    cout<<v[k-1]<<endl;
    return 0;
}

Measured memory_bytes: 5348
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

using LL = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using vll = vector<LL>;
using LD = long double;

#define ALL(v) v.begin(), v.end()
#define endl '\n'
#define SYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);
#define REP(i , n) for(int i =0 ; i < n ;i++)
#define REPN(i , n) for(int i = 1; i <= n ; i++)
#define cot(x) cerr << #x << " " << x << " ";
#define cotd(x) cerr << #x << " " << x << endl;
#define her 	cerr << " here \n"; 
#define pp push_back
#define fi first 
#define se second
#define un(x) x.erase(unique(ALL(x)), x.end())

template<typename T > void check(T & a, const T & b) { if (a >= b) { a %= b; } }
template<typename T>T gcd(T u, T v) { if (u == v)return u; if (u == 0)return v; if (v == 0)return u; if (~u & 1) { if (v & 1) return gcd(u >> 1, v); else return gcd(u >> 1, v >> 1) << 1; }if (~v & 1)return gcd(u, v >> 1); if (u > v)return gcd((u - v) >> 1, v); return gcd((v - u) >> 1, u); }
LL mulmod(LL a, LL b, const LL & m) { LL q = (LL)(((LD)a*(LD)b) / (LD)m); LL r = a*b - q*m; if (r>m)r %= m; if (r<0)r += m; return r; }
template <typename T, typename S>T expo(T e, S n) { T x = 1, p = e; while (n) { if (n & 1)x = x*p; p = p*p; n >>= 1; }return x; }
template <typename T>T powerL(T e, T n, const T & m) { T x = 1, p = e; while (n) { if (n & 1)x = mulmod(x, p, m); p = mulmod(p, p, m); n >>= 1; }return x; }

int main(){
	SYNC; 
	LL n; 
	cin >> n;
	int x = 100;
	vector<int> v(100, 0); int l = 0, r = 99; 

	while(n){
		if(n & 1) v[r--] = x, n /= 2; 
		else v[l++] = x, n--; 
		x--; 
	}
	vi ans, _ans; 
	for(int & i : v) if(i) ans.pp(i), _ans.pp(i);
	sort(ALL(_ans));  
	for(int & i : ans) i = lower_bound(ALL(_ans), i) - _ans.begin() + 1;
	for(int i = 0; i < ans.size(); i++) _ans[i] = i + 1;  
	cout << (int)ans.size() * 2 << endl; 
	for(int & i : ans) cout << i << " "; 
	for(int & i : _ans) cout << i << " ";  
	return 0; 
}

Measured memory_bytes: 256
N,M=map(int,input().split())
A=[]
C=[]
for i in range(N):
    A.append([int(i) for i in input().split()])
for j in range(M):
    C.append([int(i) for i in input().split()])

for i in range(N):
    l=[]
    for k in range(M):
        l.append(abs(A[i][0]-C[k][0])+abs(A[i][1]-C[k][1]))
    print(l.index(min(l))+1)


Measured memory_bytes: 3064
import sys,math,collections,itertools
input = sys.stdin.readline

N = int(input())
a = list(map(int,input().split()))
a.insert(0,0)
b = []
c = [0 for _ in range(N+1)]
for i in range(N,0,-1):
    cnt = 0
    for j in range(2*i,N+1,i):
        if c[j] == 1:
            cnt +=1
    if (cnt%2==1 and a[i] == 0) or (cnt%2==0 and a[i] == 1):
        b.append(i)
        c[i] = 1
print(len(b))
print(*b)


Measured memory_bytes: 18592
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(vector<T> & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(vector<T>& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(vector<T>& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>T Sum(vector<T> a, T init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define In(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);
#define Vin(T,name,n) int n; cin>>n; vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn(T,name,n) vector<T> name(n); rep(i,n)cin>>name[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template<class T>void out(T n) { cout << n << endl; }
template<class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	In(string, s);
	cout << s[0] << sz(s) - 2 << s.back() << endl;
}

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

int main()
{
    int n;
    cin >> n;
    int House[4][3][10] = {0};
    // vector<int> House[4][3][10];
    int b, f, r,v;
    for (b = 0; b<4; b++ ){
        for (f = 0; f<3;f++){
            for (r = 0; r<10; r++){
                House[b][f][r]=0;
            }
        }
    }
    for (int l=0; l<n; l++){
        cin >> b >> f >> r >> v;
        House[b-1][f-1][r-1]+=v;
    }

    for (b = 0; b<4; b++ ){
        for (f = 0; f<3;f++){
            for (r = 0; r<10; r++){
                cout << " "<<House[b][f][r];
            }
            cout<< endl;
        }
        if (b !=3){
            cout << "####################" << endl;
        }

    }

}


Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int n,min,max; //1e9
        long sum; // 1e18
        int m = sc.nextInt();
        sum = m;
        min = m;
        max = m;
        
        for(int i=1;i<N;i++){
        	n = sc.nextInt();
        	sum += n;
        	if(max<n){max = n;}
        	if(min>n){min = n;}
        }
        System.out.println(min+" "+max+" "+sum);

    }
}

Measured memory_bytes: 41940
#include<stdio.h>
#include<assert.h>
#include<math.h>
#include<string.h>
int stack[110];
int top = 0;

void push(int v){ stack[top++] = v; }
int  pop(){ return stack[--top]; }
int getInt(char *s)
{
  int i,ret=0;
  int size = strlen(s);
  for(i=0;i<size;i++)
    {
      ret += (s[i]-'0')*pow(10,size-i-1);
    }
  return ret;
}

int main()
{
  char s[1000];
  while(scanf("%s",s)!=EOF)
    {
      if('0' <= s[0] && s[0] <= '9')
	{
	  int v = getInt(s);
	  push(v);
	  continue;
	}
	  int a,b;
	  b = pop();
	  a = pop();
	  if(s[0] == '+')
	      push(a+b);
	  else if(s[0] == '-')
	    push(a-b);
	  else if(s[0] == '*')
	    push(a*b);
	  else 
	    assert(0);
    }
  printf("%d\n",pop());
  return 0;
}



Measured memory_bytes: 2048
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		
		if(x == 0) {
			System.out.println(1);
		}else {
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define lP pair<ll,ll>
#define iP pair<int,int>

typedef long long ll;
using namespace std;
const int mod = 1e9 + 7;


int N, A[100000], B[100000], MAX;
map<int, int>mp;

int main(){
	cin >> N;
	for (int i = 0; i != N; ++i) {
		cin >> A[i] >> B[i];
		++mp[A[i]];
		--mp[B[i] + 1];
	}
	auto it = mp.begin(), it2 = mp.begin();
	++it;
	MAX = mp.begin()->second;
	for (it; it != mp.end(); ++it) {
		it->second += it2->second;
		++it2;
		MAX = max(MAX, it->second);
	}
	cout << MAX << endl;
	return 0;
}


Measured memory_bytes: 13268
inf=10**10
n,m=map(int,input().split())
x=[inf]*n
con=[[] for _ in range(n)]
for i in range(m):
	l,r,d=map(int,input().split())
	con[l-1].append((r-1,d))
	con[r-1].append((l-1,-d))
from collections import deque
for i in range(n):
	if x[i]==inf:
		x[i]=0
		q=deque([i])
		while q:
			e=q.pop()
			for j,k in con[e]:
				if x[j]==inf:
					q.append(j)
					x[j]=x[e]+k
for i in range(n):
	for j,k in con[i]:
		if x[i]+k!=x[j]:
			print("No")
			exit()
print("Yes")

Measured memory_bytes: 66824
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        a: i64, b: i64,
        p: [i64; n],
    }
    let mut p1 = 0;
    let mut p2 = 0;
    for p in p {
        if p <= a {
            p1 += 1;
        } else if p <= b {
            p2 += 1;
        }
    }
    use std::cmp::min;
    println!("{}", min(p1, min(p2, n - p1 - p2)));
}


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

int main(){
int n;cin>>n;
  vector <int> v;
  while(n--){
  int a;cin>>a; v.push_back(a);
  }
  sort(v.begin(),v.end());
  int count=0;
  for (int i=v.size()-1;i>0;i--){
  int l=0,r=i-1;
    while(l<r){
    if(v[l]+v[r]>v[i]){count +=r-l;r--;}
      else l++;
      
    
    }
  
  }
cout<<count;
}


Measured memory_bytes: 384