akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    int N; cin>>N;
    int buy; cin>>buy;
    int ans = -1e9;
    for(int i=1;i<N;i++){
        int R; cin>>R;
        ans = max(ans,R-buy);
        buy = min(buy,R);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include<iterator>
#include<vector>
#include<algorithm>


#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pci pair<char,int>
#define un unsigned

#define mod 1000000007
#define MAXN 100000
using namespace std; 


int main() 
{ 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,p;
    cin>>a>>p;
    a *= 3;
    a += p;
    cout<<a/2<<endl;
    return 0;
} 



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

#define ll long long 
int main() {
  ll N, M;
  cin >> N >> M;
  
  ll A[N], B[N];
  pair<ll, ll> P[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    P[i] = make_pair(A[i], B[i]);
  }
  
  sort(P, P+N);
  
  ll drink = 0;
  ll ans = 0;
  ll i = 0;
  while (drink < M) {
    if (drink + P[i].second > M) {
      ans += P[i].first * (M - drink);
      drink = M;
    } else {
      drink += P[i].second;
      ans += P[i].first * P[i].second;
    }
    i++;
  }
  
  cout << ans << endl;  
}

Measured memory_bytes: 3328
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

func ScanText() string {
	if scanner.Scan() {
		return scanner.Text()
	}
	fmt.Fprintf(os.Stderr, "Text not found")
	return ""
}

func ScanInt() (ret int) {
	var err error
	if scanner.Scan() {
		txt := scanner.Text()
		if ret, err = strconv.Atoi(txt); err != nil {
			_, _ = fmt.Fprintf(os.Stderr, err.Error())
		}
	}
	return
}

func Abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func Min(ns ...int) int {
	if len(ns) == 0 {
		_, _ = fmt.Fprintf(os.Stderr, "Arguments are necessary")
		return 0
	}
	if len(ns) == 1 {
		return ns[0]
	}
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

var n, a, b, c int
var ls []int

func dfs(i, aa, bb, cc int) int {
	if i == n {
		if aa > 0 && bb > 0 && cc > 0 {
			return Abs(a-aa) + Abs(b-bb) + Abs(c-cc) - 30
		}
		return math.MaxInt32
	}
	return Min(
		dfs(i+1, aa, bb, cc),
		dfs(i+1, aa+ls[i], bb, cc)+10,
		dfs(i+1, aa, bb+ls[i], cc)+10,
		dfs(i+1, aa, bb, cc+ls[i])+10,
	)
}

func main() {
	n, a, b, c = ScanInt(), ScanInt(), ScanInt(), ScanInt()
	ls = make([]int, n)
	for i := 0; i < n; i++ {
		ls[i] = ScanInt()
	}
	fmt.Println(dfs(0, 0, 0, 0))
}


Measured memory_bytes: 1780
#include <cstdio>


/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int a;
char s[11];




int main () {

	// 文字列数の読込み
	scanf("%d %s", &a, &s);

	if(a >= 3200) printf("%s\n", s);
	else printf("red\n");	

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define res register short
#define N 105
using namespace std;
short line[N][N],List[N][N],ans[N][N][N][N],n,m,op,sx,sy;
char s[N][N];

signed main() {
	cin>>n>>m;
	for (res i=1; i<=n; i++) scanf("%s",s[i]+1);
	for (res i=1; i<=n; i++)
		for (res j=1; j<=m; j++) {
			line[i][j]=line[i][j-1]+(s[i][j]=='o');
			List[i][j]=List[i-1][j]+(s[i][j]=='o');
			if (s[i][j]=='E') sx=i,sy=j;
		}
	for (res i=sx; i; i--)
		for (res j=sy; j; j--)
			for (res k=sx; k<=n; k++)
				for (res p=sy; p<=m; p++) {
					if (1<i && k+1<sx+i) op=max(op,ans[i-1][j][k][p]=max((int)ans[i-1][j][k][p],ans[i][j][k][p]+line[i-1][min((int)p,m-sy+j)]-line[i-1][max(j-1,p-sy)]));
					if (k<n && sx+k<n+i) op=max(op,ans[i][j][k+1][p]=max((int)ans[i][j][k+1][p],ans[i][j][k][p]+line[k+1][min((int)p,m-sy+j)]-line[k+1][max(j-1,p-sy)]));
					if (1<j && p+1<sy+j) op=max(op,ans[i][j-1][k][p]=max((int)ans[i][j-1][k][p],ans[i][j][k][p]+List[min((int)k,n-sx+i)][j-1]-List[max(i-1,k-sx)][j-1]));
					if (p<m && sy+p<m+j) op=max(op,ans[i][j][k][p+1]=max((int)ans[i][j][k][p+1],ans[i][j][k][p]+List[min((int)k,n-sx+i)][p+1]-List[max(i-1,k-sx)][p+1]));
				}
	cout<<op<<endl;
	return 0;
}

Measured memory_bytes: 227584
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)
#define Yes cout<<"Yes"<<endl;
#define No cout<<"No"<<endl;
#define all(v) v.begin(), v.end()
#define mp make_pair
#define INF 1e9

void init()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
}

int main()
{
    init();
    int n;
    cin>>n;
    int d1, d2;
    int c=0,tmp=0;
    rep(i,n){
        cin>>d1>>d2;
        if(d1==d2)c++;
        if(d1!=d2)c=0;
        if(c>=3)tmp=1;
    }
    if(tmp==1){
        Yes;
    }else{
        No;
    }
}


Measured memory_bytes: 3648
x = int(input())

if 400 <= x <= 599:
    print(8)
elif 600 <= x <= 799:
    print(7)
elif 800 <= x <= 999:
    print(6)
elif 1000 <= x <= 1199:
    print(5)
elif 1200 <= x <= 1399:
    print(4)
elif 1400 <= x <= 1599:
    print(3)
elif 1600 <= x <= 1799:
    print(2)
elif 1800 <= x <= 1999:
    print(1)


Measured memory_bytes: 9184
#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");}
#define MAX_N 200005

ll ans[MAX_N];
ll cnt[MAX_N];
ll c[MAX_N];
ll n;
ll son[MAX_N];
vector<int> pre_G[MAX_N];
vector<int> G[MAX_N];
int par_[MAX_N];
int flag_netsukigi[MAX_N];
void make_netsukigi(int r){
    rep(i,MAX_N){
        G[i].clear();
        par_[i] = 0;
        flag_netsukigi[i] = 0;
    }
    queue<int> que;
    que.push(r);
    flag_netsukigi[r] = 1;
    par_[r] = -1;

    while(que.size() > 0){
        int x = que.front();
        que.pop();
        flag_netsukigi[x] = 1;
        rep(i,pre_G[x].size()){
            if(flag_netsukigi[pre_G[x][i]] == 0){
                par_[pre_G[x][i]] = x;
                G[x].push_back(pre_G[x][i]);
                que.push(pre_G[x][i]);
            }
        }
    }
}

void dfs(int x, int par){
    if(x == -1){
        rep(i,n){
            cnt[i] = n;
        }
        dfs(0,-1);
    }
    else{
        ll keep = cnt[c[x]];

        rep(i,G[x].size()){
            int y = G[x][i];
            cnt[c[x]] = son[y];
            dfs(y,x);
        }

        cnt[c[x]] = keep - son[x];
        // 計算
        if(par == -1){
            rep(i,n){
                ans[i] -= cnt[i] * (cnt[i]+1) / 2;
            }
        }else{
            ans[c[par]] -= cnt[c[par]] * (cnt[c[par]] + 1) / 2;
        }
    }
}

int main() {
    cin >> n;
    
    rep(i,n){
        cin >> c[i];
        c[i]--;
    }

    rep(i,n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        a--; b--; // 0-indexにするため.
        pre_G[a].push_back(b);
        pre_G[b].push_back(a);
    }

    make_netsukigi(0);
    queue<int> que;
    int son_cnt[n] = {};
    rep(i,n){
        son_cnt[i] = G[i].size();
        if(G[i].size() == 0){
            que.push(i);
        }
    }
    while(que.size() > 0){
        int x = que.front();
        que.pop();
        son[x]++;
        if(par_[x] == -1)break;
        son[par_[x]] += son[x];
        son_cnt[par_[x]]--;
        if(son_cnt[par_[x]] == 0)que.push(par_[x]);
    }

    rep(i,n)ans[i] = n * (n+1) / 2;

    dfs(-1, -1);

    rep(i,n)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 52828
#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <stdio.h>
#include <bits/stdc++.h>

#define uint unsigned int
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;
using namespace std;
const int N = 2 * 1e5 + 10;
int tot , a[N] , n , ans; 
int t[4 * N];
void upd(int v , int tl ,int tr , int pos ,int x){
	if(tl == tr){
		t[v] = x;
		return;
	}
	int mid = ( tl + tr) >> 1;
	if(pos <= mid)
		upd(v + v , tl , mid , pos , x);
	else
		upd(v + v + 1 , mid + 1 , tr , pos , x);
	t[v] = min(t[v + v] , t[v + v + 1]);
}
int get(int v , int tl , int tr , int l , int r){
	if(l > r)
		return 1e18;
	if(tl == l && tr == r)
		return t[v];
	int mid = (tl + tr) >> 1;
	return min(get(v + v , tl , mid , l , min(mid , r)) 
			   , get(v + v + 1 , mid + 1 , tr , max(mid + 1 , l) , r));
}
main(){
	//ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	scanf("%lld" , &n);
	for(int i = 1 ; i <= n ; i++){
		scanf("%lld" , &a[i]);
		upd(1 , 1 , n , i , a[i]);
	}
	for(int i = 1 ; i <= n ; i++){
		int l = 1 , r = i , res1 = i , res2 = i;
		while(l <= r){
			int mid = (l + r) >> 1;
			if(get(1 , 1 , n , mid, i) == a[i]){
				r = mid  - 1;
				res1 = mid;
			}
			else
				l = mid + 1;
		}
		l = i , r = n;
		while(l <= r){
			int mid = (l + r) >> 1;
			if(get(1 , 1 , n , i , mid) == a[i]){
				res2 = mid;
				l = mid + 1;
			}
			else
				r = mid - 1;
		}
		
		ans += (i - res1 + 1)* (res2 - i + 1) * a[i];
	}
	cout << ans;
	
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ll 				long long
#define int             long long int
#define setbits(x)      __builtin_popcountll(x)
#define mod             1000000007
#define modp            998244353
#define inf             (ll)1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define FIO           	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl 			'\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
int power(int x, int y, int p)  
{  
    int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
} 

void solve()
{
	int n; cin >> n;
	if(n == 1)
		cout << 0 << endl;
	else if(n == 2)
		cout << 2 << endl;
	else
	{
		int ans = power(9, n, mod)%mod;
		ans = ans*2;
		ans = ans%mod;
		ans = ans-power(8, n, mod);
		ans = (ans+mod)%mod;
		ans = (power(10, n, mod)%mod-ans+mod)%mod;
		// ans = ans%mod;
		cout << ans << endl;
	}
}
 
int32_t main()
{
	FIO
    // w(t)
    {
    	solve();
    }
    return 0;
}
	

	

Measured memory_bytes: 3684
#include <stdio.h>


int main(){

  int i,j,N,k;

  scanf("%d",&N);

  int A[100];
  
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  } 

  for(i=0;i<N;i++){
    if(i!=0){
    printf(" ");
    }
    printf("%d",A[i]);
  }
  printf("\n");

  
  int v;
//挿入ソート
  // insertionSort(A,N);

  for(i=1;i<=N-1;i++){
  v=A[i];
  j=i-1;
  while(j >= 0 && A[j] > v){
    A[j+1]=A[j];
    j--;
    A[j+1]=v;
  }
  

  for(k=0;k<N;k++){
    if(k!=0){
    printf(" ");
    }
    printf("%d",A[k]);
  }
  printf("\n");
  
  }
  

 return 0;
}



Measured memory_bytes: 2084
#include <bits/stdc++.h>
#define WHOLE(v) v.begin(), v.end()
using namespace std;
const double RATE = 3.8e5;
int main() {
    int N;
    cin >> N;
    double Y = 0;
    for(int i = 0; i < N; i++) {
        double x;
        string u;
        cin >> x >> u;
        if(u == "JPY") Y += x;
        else Y += RATE * x;
    }
    cout << std::fixed << std::setprecision(8) << Y << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
    char b, c[128];

    c['A'] = 'T';
    c['T'] = 'A';
    c['G'] = 'C';
    c['C'] = 'G';
    cin >> b;

    cout << c[(int)b] << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
bool p(int n) {
	for (int i = 2; i <= sqrt(n); i++)if (n%i == 0)return false; return true;
}
int main(){
	int n;
	while (cin >> n){
		if (n == 0)return 0;
		for (int i = n;; i--){
			if (p(i) && p(i - 2)) {
				cout << i - 2 << ' ' << i << endl;
				goto end;
			}
		}
	end:;
	}
}

Measured memory_bytes: 2968
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t N;
	cin >> N;

	vector<int32_t> H(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> H[i];
	}

	vector<int32_t> d(N);
	d[N - 1] = 0;
	int32_t res = 0;
	for (int32_t i = N - 2; i >= 0; i--) {
		d[i] = (H[i] < H[i + 1]) ? 0 : (d[i + 1] + 1);
		res = max(res, d[i]);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  int a, b, m;
  cin >> a >> b >> m;
  vector<int> av(a), bv(b), x(m), y(m), c(m);
  for (int i = 0; i < a; i++) {
    cin >> av[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> bv[i];
  }

  for (int i = 0; i < m; i++) {
    cin >> x[i] >> y[i] >> c[i];
    x[i]--;
    y[i]--;
  }

  ll ans =
      *min_element(av.begin(), av.end()) + *min_element(bv.begin(), bv.end());

  for (int i = 0; i < m; i++) {
    ll tmp = av[x[i]] + bv[y[i]] - c[i];

    if (ans > tmp) {
      ans = tmp;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2176
N, M = [int(x) for x in input().split()]
G = [[] for x in range(N)]
V = (1 << N) - 1
count = 0

for i in range(M):
    a, b = [int(x) for x in input().split()]
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)


def dfs(s, v):
    global count
    if v == V:
        count += 1
    for t in G[s]:
        if (v >> t & 1) == 0:
            dfs(t, v | 1 << t)


dfs(0, 1)

print(count)

Measured memory_bytes: 3064
#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++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N; cin >> N;
    vector<int> H(N); cin >> H;

    int ans = 0;
    int c = 0;
    rep1(i, N) {
        if (H[i - 1] >= H[i]) {
            c++;
        } else {
            chmax(ans, c);
            c = 0;
        }
    }
    chmax(ans, c);
    
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    ll K,A,B; cin >> K >> A >> B;
    // 極限まで叩く or A 枚まで持っていって操作しまくる
    cout << max(K+1,max(0ll,((K-A+1)/2)*(B-A)+A+((K-A-1)%2))) << endl;
}

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

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

uint_fast64_t pow2(uint_fast64_t x) {
	if (x == 0) return 1;

	uint_fast64_t half = pow2(x / 2);
	uint_fast64_t result = half * half;

	if (x % 2 != 0) result *= 2;

	return result;
}

uint_fast64_t combination(int n, int r) {
	uint_fast64_t result = 1;

	if (r + r > n) r = n - r;

	for (int i = r - 1; i >= 0; i--) {
		result *= n - i;
	}

	for (int i = 2; i <= r; i++) {
		result /= i;
	}

	return result;
}

int main()
{
	int n, p;
	std::cin >> n >> p;

	int even_count = 0;
	int odd_count = 0;

	for (int i = 0; i < n; i++) {
		int a;
		std::cin >> a;

		if (a % 2 == 0) even_count++;
		else odd_count++;
	}


	// いずれかの偶数を選択
	uint_fast64_t even_select = pow2(even_count);

	uint_fast64_t odd_select = 0;

	if (p == 0) {
		// 奇数を偶数個選択
		for (int i = 0; i <= odd_count; i += 2) {
			odd_select += combination(odd_count, i);
		}
	}
	else {
		// 奇数を奇数個選択
		for (int i = 1; i <= odd_count; i += 2) {
			odd_select += combination(odd_count, i);
		}
	}

	std::cout << even_select * odd_select << std::endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    unordered_map<int,int> mp;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        mp[a[i]]++;
        mp[a[i]-1]++;
        mp[a[i]+1]++;
    }    
    pair<int,int> ans = {-1,-1};
    for(auto p:mp){
        if(p.second> ans.second){
            ans = {p.first,p.second};
        }
    }
    cout << ans.second << endl;;
}

Measured memory_bytes: 4644
function main(input){
    var lines = input;
    var flg = true;
    var p=0;
    var ans = 0;
    var min=999;
    while(flg){
        var suu = Number(""+lines[p]+lines[p+1]+lines[p+2]);
        var mi = 753-suu;
        if(mi==0){
            min=0;
            break;
        }else if(mi<0){
            mi*=-1;
        }
        if(min>mi){
            min=mi;
        }
        p++;
        var t=p+2;
        if(t>lines.length){
            break;
        }
    }

    console.log(min);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));

Measured memory_bytes: 21064
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

X = gets_i

cases = (-1000..1000).to_a.repeated_combination(2).to_a
cases.each do |a, b|
  if X == a**5 - b**5
    puts [a, b].join(" ")
    exit
  elsif X == b**5 - a**5
    puts [b, a].join(" ")
    exit
  end
end



Measured memory_bytes: 125580
#include "bits/stdc++.h"
using namespace std;
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a)  (a).begin(),(a).end()

template<class T>
class UF{
private:
    vector<T> par,rank;
    //    vector<int> size;
    int _size;
    int groups;
public:
    
    UF(int __size):_size(__size) , par(__size) , rank(__size,0) ,groups(1){
        for(int i=0;i<__size;i++)par[i]=i;
    }
    
    int size(){
        return _size;
    }
    
    T find(int x){
        if(par[x]==x) {
            return x;
        }else{
            return par[x]=find(par[x]);
        }
    }
    
    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        
        if(rank[x]<rank[y]){
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y])rank[x]++;
        }
    }
};


int main(){
    int n,q;
    cin>>n>>q;
    UF<int> uf(n);
    rep(i,q){
        int a,b,c;
        cin>>a>>b>>c;
        if(a==0)uf.unite(b,c);
        else    cout<<(uf.find(b)==uf.find(c))<<endl;
    }
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef pair<int,int> pi;

//#define cerr if(0) cout	

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	set<int> st;
	for (int i = 0; i < n; ++i) {
		int x; cin >> x;
		st.emplace(x);
	}
	cout << (n==st.size() ? "YES": "NO");
	return 0;
}


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

void f(vector<int> v0, vector<int> v1, int x){
    if (v0.size() == 0) {
        cout << x << " ";
        return;
    }
    int i = 0;
    while (v0[i] == v1[i])
        i++;
    vector<int> A, B, C;
    for (int j = 0; j < v0.size(); j++)
    {
        if (i == j) continue;
        A.push_back(v0[j]);
        B.push_back(v1[j]);
    }
    C = A;
    if (C.size() != 0)C[0] *= -1;
    f(A, C, x + (v0[i] < 0 ? 0 : v0[i]));
    f(C, B, x + (v1[i] < 0 ? 0 : v1[i]));
}
int main(){
    int N, A, B; cin >> N >> A >> B;
    vector<int> v_A, v_B;
    int j = 1, parity = 0;
    for (int i = 0; i < N; i++){
        v_A.push_back(((A >> i) & 1) ? j : -j);
        v_B.push_back(((B >> i) & 1) ? j : -j);
        j *= 2;
        parity += ((A >> i) & 1) + ((B >> i) & 1);
    }
    if (parity % 2 == 0)
        cout << "NO" << endl;
    else{
        cout << "YES" <<endl;
        f(v_A, v_B, 0);
    }
}

Measured memory_bytes: 1152
import itertools

x = int(input())

if x < 100:
    print("0")
else:
    n = x // 100
    # r = x % 105
    # print(n, r)

    nums = [100, 101, 102, 103, 104, 105]

    for balls in itertools.combinations_with_replacement(nums, n):
        # print(balls)
        if sum(balls) == x:
            print('1')
            break
    else:
        print('0')




Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int prime[1000000];
bool is_prime[1000001];

void sieve(int n){
	int p=0;
	for(int i=0;i<=n;i++) is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++]=i;
			for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
		}
	}
}

int d[1000001];

int main(){
	int n,p,m;
	sieve(1000000);
	rep(i,1,1000001){
		d[i]=d[i-1];
		if(is_prime[i]) d[i]++;
	}
	while(1){
		int ans=0;
		cin>>n;
		if(n==0) break;
		rep(i,0,n){
			cin>>p>>m;
			int c=0;
			c=d[min(p+m,1000000)]-d[max(1,p-m-1)];
			//o(c);
			if(c==0) ans--;
			else ans+=c-1;
		}
		o(ans);
	}
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define faster  ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pb push_back
const double PI = acos(-1.0);
using namespace std;

int main()
{
    faster

    int n;
    cin>>n;

    int a[n],b[n],c[n];

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

        if(i!=0)
        {
            a[i]=a[i]+max(b[i-1],c[i-1]);
            b[i]=b[i]+max(a[i-1],c[i-1]);
            c[i]=c[i]+max(a[i-1],b[i-1]);
        }
    }


    //cout<<a[n-1]<<" "<<b[n-1]<<" "<<c[n-1]<<endl;

    cout<<max(a[n-1],max(b[n-1],c[n-1]))<<endl;









    return 0;
}

Measured memory_bytes: 4804
package main

import (
	"fmt"
	"strings"
)

func main(){
	var a,b,ans string
	fmt.Scan(&a)
	fmt.Scan(&b)
	if len(a) > len(b){
		b += " "
	}
	for i:=0 ;i < len(a); i++{
		ans += string(a[i])
		ans += string(b[i])
	}
	ans = strings.TrimSpace(ans)
	fmt.Println(ans)
}

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

using namespace std;

const int N=2e4+10;

const int INF=0x3f3f3f3f;

int dp[N];

int main()

{

    int h,n; scanf("%d%d",&h,&n);

    memset(dp,INF,sizeof dp);

    dp[0]=0;

    for(int i=0;i<n;i++){

        int x,y; scanf("%d%d",&x,&y);

        for(int j=0;j+x<N;j++)

            dp[j+x]=min(dp[j+x],dp[j]+y);

    }

    int res=dp[h];

    for(int i=h;i<N;i++)

        res=min(res,dp[i]);

    printf("%d\n",res);

    return 0;

}


Measured memory_bytes: 384
A, B = map(int, input().split())
ans = ''
if A == B:
    for a in range(A):
        ans += str(B)
elif A > B:
    for a in range(A):
        ans += str(B)
elif A < B:
    for b in range(B):
        ans += str(A)
        
print(ans)

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

using namespace std;

#define PB push_back
#define MP make_pair
#define X first
#define Y second

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define err(x) cerr << #x << " = " << x << endl;
#define read(a) freopen(a,"r",stdin)
#define write(a) freopen(a,"w",stdout)

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

clock_t start;
void Time(bool timeIt) {
	if (!timeIt) return;
	clock_t end = clock();
	double elapsed_time = ((db)end - (db)start) / (db)CLOCKS_PER_SEC;
	fprintf(stderr, "Time elapsed = %0.4lf\n", elapsed_time);
}

#define LINF (long long)1e18
#define EPS 1e-9
#define INF 1000000007ll
#define SIZE 100010
#define MAX_A 1000010

ll cnt[SIZE], st[SIZE], f[SIZE], inv[SIZE], psum[SIZE], inv_f[SIZE];
ll a[SIZE];
const ll mod = INF;

ll exp(ll b, ll e) {
    ll ret = 1;
    while (e > 0) {
        if (e & 1) ret = (ret * b) % mod;
        b = (b * b) % mod;
        e >>= 1;
    }
    return ret;
}

ll add(ll p, ll q) {
    ll ret = p + q;
    return (ret >= mod ? ret - mod : ret);
}

int main() {
    start = clock();

    f[0] = 1;
    for (int i = 1 ; i < SIZE ; ++i) {
        f[i] = (1ll * f[i - 1] * i) % mod;
        inv[i] = exp(i, mod - 2);
        inv_f[i] = exp(f[i], mod - 2);
    }
    
    int n;
    scanf("%d", &n);
    for (int i = 1 ; i <= n ; ++i) scanf("%lld", &a[i]);

    st[1] = 1;
    for (int i = 2 ; i <= n + 5 ; ++i) st[i] = add((1ll * st[i - 1] * i) % mod, f[i - 1]);
    psum[1] = 0;
    for (int i = 2 ; i <= n ; ++i) psum[i] = add(psum[i - 1], inv[i]);
    cnt[1] = cnt[n] = st[n];
    for (int i = 2 ; i <= n - 1 ; ++i) {
        cnt[i] = add((1ll * (f[n] * inv_f[i] % mod) * st[i]) % mod, (f[n] * psum[n - i + 1]) % mod);
    }

    ll ans = 0;
    for (int i = 1 ; i <= n ; ++i) {
        ans = add(ans, (cnt[i] * a[i]) % mod);
    }
    printf("%lld\n", ans);

    Time(true);
    return 0;
}

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

int main(){
    long long a, b, k;
    cin >> a >> b >> k;
    
    if( k <= a ) {
        a -= k;
     }
    else if(k <= a+b) {
        b -= (k-a);
        a = 0;
    }
    else {
        a = 0;
        b = 0;
    }
    
    cout << a << " " << b << endl;
}

Measured memory_bytes: 3608
#include<stdio.h>

int main(){

    int n,k;
    scanf("%d %d",&n,&k);
    char s[n];
    scanf("%s",s);

    if(s[k-1]=='A'){
        s[k-1]='a';
    }else if(s[k-1]=='B'){
        s[k-1]='b';
    }else{
        s[k-1]='c';
    }
    printf("%s\n",s);

    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void){
  char a[100],b[100],c[100],moji;
  int i=1,j=0,k=0;
  scanf("%s",a);
  scanf("%s",b);
  scanf("%s",c);
  moji=a[0];
  while(1){
    while('a'==moji){
      if(a[i]=='\0'){
        printf("A\n");
        return 0;
      }
      moji=a[i];
      i++;
    }
    while('b'==moji){
      if(b[j]=='\0'){
        printf("B\n");
        return 0;
      }
      moji=b[j];
      j++;
    }
    while('c'==moji){
      if(c[k]=='\0'){
        printf("C\n");
        return 0;
      }
      moji=c[k];
      k++;
    }
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789

 
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int A, B, C;

int main(){
	
	cin>>A>>B>>C;

	if( A*B*C == 175 && A+B+C == 17 ) puts("YES");
	else{	puts("NO");}
	
	return 0;

}

Measured memory_bytes: 256
import math
def main():
  n,m = list(map(int,input().split()))
  alist=[[]]
  for i in range(0,n):
    alist.append(list(map(int,input().split())))
  ans=set(alist[1][1:])
  for i in range(2,n+1):
    ans=ans & set(alist[i][1:])
  print(len(ans))
main()

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

int main() {
  int c[3][3]={{0}};
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c[i][j];
    }
  }

  int a[3]={0}, b[3]={0};
  a[0] = 0;
  b[0] = c[0][0];
  b[1] = c[0][1];
  b[2] = c[0][2];
  a[1] = c[1][0] - b[0];
  a[2] = c[2][0] - b[0];

  bool ans = 1;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (a[i] + b[j] != c[i][j]) {
        ans = 0;
        break;
      }
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e3 + 5;
ll f[N][N];
pair<int, int> p[N];
ll cal(int cnt, int l, int r) {
    if(l > r) return 0;
    if(~f[l][r]) return f[l][r];
    ll ans = 1LL * p[cnt].first * abs(p[cnt].second - l) + cal(cnt + 1, l + 1, r);
    ans = max(ans, 1LL * p[cnt].first * abs(p[cnt].second - r) + cal(cnt + 1, l, r - 1));
    return f[l][r] = ans;
}
int main() {
    int n;
    scanf("%d", &n);
    for(int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        p[i] = {x, i};
    }
    sort(p + 1, p + n + 1,[](pair<int, int> a, pair<int, int> b) {
        return a.first > b.first;
    });
    memset(f, -1, sizeof f);
    printf("%lld\n", cal(1, 1, n));
    return 0;
}


Measured memory_bytes: 35372
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    class Shi: IComparable<Shi>
    {
        public int P;
        public int Y;
        public int ID;

        public Shi(int P, int Y, int ID)
        {
            this.P = P;
            this.Y = Y;
            this.ID = ID;
        }

        int IComparable<Shi>.CompareTo(Shi other)
        {
            if (P != other.P) return P.CompareTo(other.P);
            else return Y.CompareTo(other.Y);
        }
    }


    Scanner cin;
    
    void calc()
    {
        cin = new Scanner();

        int N = cin.nextInt();
        int M = cin.nextInt();
        int[] P = new int[M];
        int[] Y = new int[M];

        Shi[] shi = new Shi[M];
        for (int i = 0; i < M; i++)
        {
            P[i] = cin.nextInt();
            Y[i] = cin.nextInt();
            shi[i] = new Shi(P[i], Y[i], i);
        }

        Array.Sort(shi);

        string[] ans = new string[M];

        int preP = -1;
        int nowID = 1;

        for (int i = 0; i < M; i++)
        {
            if (preP != shi[i].P) nowID = 1;
            else nowID++;
            ans[shi[i].ID] = string.Format("{0:000000}{1:000000}", shi[i].P, nowID);

            preP = shi[i].P;
        }
        for (int i = 0; i < M; i++)
        {
            Console.WriteLine(ans[i]);
        }
    }    
}




class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

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

    public long nextLong()
    {
        return long.Parse(next());
    }

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

    public double nextDouble()
    {
        return double.Parse(next());
    }


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



Measured memory_bytes: 30776
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<char, int> mp;
    int n; cin >> n;
    string can = "MARCH";
    rep(i, n) {
        string s; cin >> s;
        rep(j, can.size()) {
            if (s[0] == can[j]) {
                mp[s[0]]++;
            }
        }
    }
    if (mp.size() <= 2) {cout << 0 << endl; return 0;}
    else if (mp.size() == 3) {
        ll ans = 1;
        for (auto e: mp) {
            ans *= (ll)e.second;
        }
        cout << ans << endl;
        return 0;
    } else if (mp.size() >= 4) {
        ll ans = 0;
        ans += (ll)mp['M'] * mp['A'] * mp['R'];
        ans += (ll)mp['M'] * mp['A'] * mp['C'];
        ans += (ll)mp['M'] * mp['A'] * mp['H'];
        ans += (ll)mp['M'] * mp['R'] * mp['C'];
        ans += (ll)mp['M'] * mp['R'] * mp['H'];
        ans += (ll)mp['M'] * mp['C'] * mp['H'];
        ans += (ll)mp['A'] * mp['R'] * mp['C'];
        ans += (ll)mp['A'] * mp['R'] * mp['H'];
        ans += (ll)mp['A'] * mp['C'] * mp['H'];
        ans += (ll)mp['R'] * mp['C'] * mp['H'];
        cout << ans << endl;
    }
}




Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
const int N_MAX = 50;
int main (void) {
    int n;

    cin >> n;
    int cnt[n][26];
    memset(cnt, 0, sizeof(cnt));
    for (int i = 0; i < n; i++) {
        string S;
        cin >> S;
        for (int j = 0, len = S.length(); j < len; j++) {
            cnt[i][S[j] - 'a']++;
        }
    }

    for (int i = 0; i < 26; i++) {
        int mi = N_MAX;
        for (int j = 0; j < n; j++) {
            mi = min(mi, cnt[j][i]);
        }
        for (int j = 0; j < mi; j++) {
            char c = i + 'a';
            cout << c;
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace atcoderBeginnerContest134
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = Convert.ToInt32(Console.ReadLine());
            int[] A = new int[N];
            List<int> ls = new List<int>()
            {
                -1
            };
            for (int i = 0; i < N; ++i)
            {
                A[i] = Convert.ToInt32(Console.ReadLine());

                if (ls[ls.Count - 1] >= A[i])
                    ls.Add(A[i]);
                else if (ls[0] < A[i])
                    ls[0] = A[i];
                else
                {
                    int idx = BinarySearch(ls, A[i]);
                    ls[idx] = A[i];
                }
            }
            Console.WriteLine(ls.Count);
        }

        private static int BinarySearch(List<int> ls, int elem)
        {
            int ini = 0;
            int fin = ls.Count;

            while(ini < fin)
            {
                int md = (ini + fin) >> 1;
                if (ls[md] >= elem)
                    ini = md + 1;
                else
                    fin = md; 
            }

            return ini;
        }
    }
}


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

int main()
{
	int h,w;
  	cin>>h>>w;
  	vector<string> grids;
  	string str;
  	for(int i=0 ; i<h ; ++i)
    {
    	cin>>str;
      	if(str.find("#")!=string::npos)
        grids.push_back(str);
    }
  	map<int,bool> white_cols;
  	for(int i=0 ; i<grids[0].length() ; ++i)
    {
      	bool white_col=true;
    	for(int j=0 ; j<grids.size() ; ++j)
        {
        	if(grids[j][i]=='#')
            {
            	white_col=false;
              	break;
            }
        }
		white_cols[i]=white_col;
    }
  	for(int i=0 ; i<grids.size() ; ++i)
    {
    	for(int j=0 ; j<grids[i].length() ; ++j)
        {
        	if(white_cols[j])
        	continue;
          	cout<<grids[i][j];
        }
      	cout<<endl;
    }
	return 0;
}

Measured memory_bytes: 256
// Problem : A - Addition and Subtraction Easy
// Contest : AtCoder Beginner Contest 050
// URL : https://atcoder.jp/contests/abc050/tasks/abc050_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

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

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T, size_t N> ostream& operator << (ostream &os, const array<T, N> &a) {os << "("; for (int i=0; i<(int)N; i++) {if (i) os << ", "; os << a[i];} return os << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int a, b;
    char op;
    cin >> a >> op >> b;
    
    cout << (op == '+' ? a + b : a - b) << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rep_start(a,i,n) for(ll i=a;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define sz(a) int((a).size())
#define all(c) c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i+=c.begin; i!=c.end(); i++)
#define present(c,x) (c.find(x)!=c.end())
#define cpresent(c,x) (find(all(c),x)!=c.end())
#define pb push_back
#define F first
#define S second
#define INF LONG_MAX
#define mod 1000000007
#define print1(a) cout<<a<<"\n";
#define print2(a,b) cout<<a<<" "<<b<<"\n";
#define print3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define mt make_tuple
#define eb emplace_back

typedef long long int ll;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef tuple<int,int,int> State;

void solve(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if( (c-1)/b<=(a-1)/d ) cout<<"Yes";
    else cout<<"No";
}

signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
    return 0;
}

Measured memory_bytes: 3600
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def size(self,x):
        return -self.root[self.Find_Root(x)]

    def members(self,x):
        root=self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i)==root]

    def roots(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:self.members(i) for i in self.roots()}

    def group_count(self):
        return len(self.roots())


def kruskal():
    D,M=[],[]

    A,B=sorted(XY),sorted(XY, key=lambda x: x[1])
    for i in range(n-1):
        M.append([min(abs(A[i][0]-A[i+1][0]),abs(A[i][1]-A[i+1][1])),A[i][2],A[i+1][2]])
        M.append([min(abs(B[i][0]-B[i+1][0]),abs(B[i][1]-B[i+1][1])),B[i][2],B[i+1][2]])

    M.sort()
    for w,s,t in M:
        if UnionFind.isSameGroup(s,t) is False:
            UnionFind.Unite(s,t)
            D.append(w)

    return D


import sys
input=sys.stdin.readline

n=int(input())
XY=[list(map(int,input().split()))+[i+1] for i in range(n)]
UnionFind=UnionFind(n+1)
print(sum(kruskal()))

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

int index(int numToFind, std::vector<int> vectorToFindIn) {int len = vectorToFindIn.size();for (int i = 0; i < len; i++){if (vectorToFindIn[i] == numToFind){return i;}}return -1;}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n;
	cin>>n;
	int a[n+1];
	int b[n];
	ll ans;
	for (int i=0;i<n+1;++i)
	{
		cin>>a[i];
	}
	for (int i=0;i<n;++i)
	{
		cin>>b[i];
	}
	ans=0;
	for (int i=0;i<n;++i)
	{
		ans+=min(a[i],b[i]);
		b[i]=max(0,b[i]-a[i]);
		//cout<<"i: "<<i<<" - "<<ans<<"\n";
		ans+=min(a[i+1],b[i]);
		a[i+1]=max(a[i+1]-b[i],0);
		//cout<<"i: "<<i<<" - "<<ans<<"\n";
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1024
def create_fact_mod(num_max)
    $fmod = Array.new(num_max + 1)
    $fmod[0] = 1
    $fmod[1] = 1
    (2..num_max).each do |i|
        $fmod[i] = ($fmod[i - 1] * i) % MOD
    end
end

def create_seq_inv_mod(num_max)
    $simod = Array.new(num_max + 1)
    $simod[0] = 1
    $simod[1] = 1
    (2..num_max).each do |i|
        $simod[i] = (MOD - MOD / i) * $simod[MOD % i] % MOD
    end
end

def create_fact_inv_mod(num_max)
    $fimod = Array.new(num_max + 1)
    $fimod[0] = 1
    $fimod[1] = 1
    (2..num_max).each do |i|
        $fimod[i] = ($fimod[i - 1] * $simod[i]) % MOD
    end
end

def create_mod_tables(n)
    create_fact_mod(n)
    create_seq_inv_mod(n)
    create_fact_inv_mod(n)
end

def power_mod(num, power)
    prod = 1
    num %= MOD
    while power > 0 do
        if power & 1 == 1
            prod = (prod * num) % MOD
        end
        num = (num * num) % MOD
        power >>= 1
    end
    return prod
end


N, A, B, C, D = gets.split.map(&:to_i)
MOD = 10**9+7

create_mod_tables(N)

dp = Array.new(N+1, 0)
pmod = Array.new(D+1)

dp[0] = 1

(A..B).each do |i|
    pmod[C] = power_mod($fimod[i], C)
    ub = D < N/i ? D : N/i
    ((C+1)..ub).each do |k|
        pmod[k] = pmod[k-1] * $fimod[i] % MOD
    end

    N.downto(0) do |j|
        ub = D < j/i ? D : j/i
        (C..ub).each do |k|
            #dp[j] += dp[j-i*k] * perm_mod(N-j+i*k, i*k) * power_mod($fimod[i], k) * $fimod[k] % MOD
            #dp[j] += dp[j-i*k] * $fmod[N-j+i*k] * $fimod[N-j] * pmod[k] * $fimod[k] % MOD
            #dp[j] %= MOD
            dp[j] = (dp[j] + 
                dp[j-i*k] * $fmod[N-j+i*k] % MOD *
                $fimod[N-j] % MOD *
                pmod[k] % MOD *
                $fimod[k] % MOD
            ) % MOD
        end
    end
end

puts dp[N]

Measured memory_bytes: 1916
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std;

int main(void){
	double ax, ay, ar, bx, by ,br;
	double dist;
	double large, small;
	int n;
	int i;

	cin >> n;
	for(i=0;i<n;i++){
		cin >> ax >> ay >> ar >> bx >> by >> br;

		//calc distance between points
		dist = sqrt((bx - ax) * (bx - ax) + (by - ay) * (by - ay));
		if(dist > ar + br){
			cout << 0 << endl;
		}else if(dist <= ar + br && dist >= fabs(ar - br) ){ //ツ静堋点ツづーツ篠敖づづつ「ツづゥ
			cout << 1 << endl;
		}else{
			if(max(ar, br) == ar){
				cout << 2 << endl;
			}else{
				cout << -2 << endl;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int h, w;
int dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
bool vis[10][20];
char dat[10][20];
vector<string> str;

void calc(int y, int x, int d){
  fill(vis[0], vis[10], false);
  string path;
  int ny = y;
  int nx = x;
  while(!vis[ny][nx]){
    vis[ny][nx] = true;
    path.push_back(dat[ny][nx]);
    ny = (ny + dy[d] + h) % h;
    nx = (nx + dx[d] + w) % w;
  }
  if(path.size() > 1) str.push_back(path);
}

int comp(string& a, string& b){
  int size = min(a.size(), b.size());
  for(int i=0;i<size;i++) if(a[i] != b[i]) return i;
  return size;
}

main(){
  while(cin >> h >> w && (h|w)){
    str.clear();
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) cin >> dat[i][j];
    for(int i=0;i<h;i++) for(int j=0;j<w;j++) for(int k=0;k<8;k++) calc(i, j, k);
    sort(str.begin(), str.end());
    int ans = 0, id;
    for(int i=1;i<str.size();i++){
      int tmp = comp(str[i-1], str[i]);
      if(ans < tmp){
        ans = tmp;
        id = i;
      }
    }
    if(ans > 1) cout << str[id].substr(0, ans) << endl;
    else cout << 0 << endl;
  }
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
 
int main(){
  int N;
  long long int A[201];
  long long int max=0;
  long long int min=1000000000;
  cin >> N;
  for(int i=0; i<N ;++i){
    cin >> A[i];
    if(A[i]>max) max=A[i];
    if(A[i]<min) min=A[i];
  }
  cout << max-min <<endl;
}

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

int n;
int a[40000],b[40000];

int main(){
  while(scanf("%d",&n),n){
    for(int i=0;i<n;i++)scanf("%d",&a[i]);
    for(int i=0;i<n;i++)scanf("%d",&b[i]);

    sort(a,a+n,greater<int>());
    sort(b,b+n,greater<int>());

    n >>=1;
    int i;
    for(i=0;i<n;i++){
      if(a[i<<1]>b[i]){
	cout << (i<<1)+1 << endl;
	break;
      }
    }
    if(i==n)cout << "NA\n";
  }
}

Measured memory_bytes: 1540
#include <bits/stdc++.h>
using namespace std;
int N; string s, a, b, A, B;
void change(int i){
  int j=(N+i-1)%N, k=(i+1)%N;
  A[i]=(A[i]=='S')?'W':'S'; a[i]=(a[i]=='o')?'x':'o';
  a[j]=(a[j]=='o')?'x':'o'; a[k]=(a[k]=='o')?'x':'o';
  B[i]=(B[i]=='S')?'W':'S'; b[i]=(b[i]=='o')?'x':'o';
  b[j]=(b[j]=='o')?'x':'o'; b[k]=(b[k]=='o')?'x':'o';
}
void flip(int c){ for(int i=c+3-N%3; i<c+N; i+=3){change(i%N);} }
int main(){
cin >> N >> s;
a=string(N,'o'); b=string(N,'x');
A=string(N,'S'); B=string(N,'W');
for(int i=0; i<N-2; i++){ if(a[i]!=s[i]){change(i+1);} }  
if(a[N-2]==s[N-2]&&a[N-1]==s[N-1]){ cout << A << "\n"; }
else if(N%3){
  if(a[N-2]==s[N-2]){ flip(N-1); cout << B << "\n"; }
  else if(a[N-1]==s[N-1]){ flip(N-2); cout << B << "\n"; }
  else{ flip(N-2); flip(N-1); cout << A << "\n"; }
}
else{ cout << -1 << "\n"; }
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VVI;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
  int N,T0;
  cin>>N>>T0;
  VI C(N),T(N);
  rep(i,N) cin>>C[i]>>T[i];
  int ans=2000;
  rep(i,N) if(T[i]<=T0) ans=min(ans,C[i]);
  if(ans==2000) cout<<"TLE"<<endl;
  else cout<<ans<<endl;
}



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

int main() {
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;

    int i;
    if (a == 0) {
        i = 1;
    } else if(b == 0) {
        i = 2;
    } else if (c == 0) {
        i = 3;
    } else if (d == 0) {
        i = 4;
    } else if ( e == 0) {
        i = 5;
    }

    cout << i << endl;
}

Measured memory_bytes: 3632