akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define int long long
int c,n;
string s[1111];
int calc(int i,int j){
  int tmp=0;
  tmp+=s[i][j]=='1';
  tmp+=s[n-1-i][j]=='1';
  tmp+=s[i][n-1-j]=='1';
  tmp+=s[n-1-i][n-1-j]=='1';
  return tmp;
}
signed main(){
  cin>>c>>n;
  for(int i=0;i<n;i++) cin>>s[i];
  int cnt=0;
  for(int i=0;i<n/2;i++){
    for(int j=0;j<n/2;j++){
      if(calc(i,j)==0||calc(i,j)==4) cnt++;
    }
  }
  c--;
  int ans=cnt==n*n/4;
  while(c--){
    int d;
    cin>>d;
    for(int k=0;k<d;k++){
      int i,j;
      cin>>i>>j;
      i--;j--;
      if(calc(i,j)==0||calc(i,j)==4) cnt--;
      if(s[i][j]=='1') s[i][j]='0';
      else s[i][j]='1';
      if(calc(i,j)==0||calc(i,j)==4) cnt++;
    }
    ans+=cnt==n*n/4;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 4160
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    long long N, h, n, w, wx, wy;

   
      
    scanf("%lld", &N );

   
    for( h = 1 ; h <= 3500 ; h = h + 1 ){
   
         for( n = 1 ; n <= 3500 ; n = n + 1 ){

              if( ( 4 * h * n - n * N - h * N ) != 0 ){

                   wx = 4 * h * n - n * N - h * N;

                   wy = N * h * n;

                   if( wy % wx == 0 && wy / wx > 0 ){

                       w = wy / wx;

                       printf("%lld %lld %lld\n", h, n, w );

                       return 0;

                       }

                   }      

              }        

         }


    return 0;
                                                          
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };


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

	int div = 1;
	int count = 1;

	if (N == 100000)printf("90909");
	else if (N >= 0 && N < 10)printf("%d", N);
	else if (N >= 10 && N < 100)printf("9");
	else if (N >= 100 && N < 1000)printf("%d", 9 + N - 100 +1);
	else if (N >= 1000 && N < 10000)printf("%d",9 + 900);
	else if(N >= 10000 && N < 100000)printf("%d", 9 + 900 +90000 + N-100000 +1);



}

/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

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

int main(){
    int n;
    cin >> n;
    int sum = 0;
    vector<int> res(n);
    rep(i, n) {
        cin >> res[i];
        sum += res[i];
    }
    sort(res.begin(), res.end());
    if ( sum % 10 != 0 ) {
        cout << sum << endl;
    }
    else {
        rep(i, n) {
            if ( res[i] % 10 != 0 ) {
                cout << sum - res[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val src: Iterator[Int] = io.Source.stdin.getLines.map(_.toInt)

  def isPrime(n: Int) = n >= 2 && (2 to math.sqrt(n).toInt).forall(n%_ != 0)
  def findPrimeOver(curr: Int): Int = if (isPrime(curr)) curr else findPrimeOver(curr + 1)
  def findPrimeUnder(curr: Int): Int = if (isPrime(curr)) curr else findPrimeUnder(curr - 1)

  for (num <- src) println(s"${findPrimeUnder(num-1)} ${findPrimeOver(num+1)}")
}

Measured memory_bytes: 44032
import java.util.*;

import javax.xml.crypto.Data;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if(n == 0) break;
			int[] listX = new int[n];
			int[] listY = new int[n];
			boolean[][] map = new boolean[5001][5001];
			for (int i = 0; i < n; i++) {
				listX[i] = sc.nextInt();
				listY[i] = sc.nextInt();
				map[listY[i]][listX[i]] = true;
			}
			int max = 0;
			for (int i = 0; i < n; i++) {
				for (int j = i + 1; j < n; j++) {
					int tx = listX[j] - listX[i];
					int ty = listY[j] - listY[i];

					int ax = listX[j] + ty;
					int ay = listY[j] - tx;

					int bx = listX[i] + ty;
					int by = listY[i] - tx;
					if (rCheck(ax, ay) && map[ay][ax] && rCheck(bx, by)
							&& map[by][bx]) {
						max = (int) Math.max(max, (int)Math.pow(
								(listX[i] - listX[j]), 2)
								+ Math.pow((listY[i] - listY[j]), 2));
					}
				}
			}
			System.out.println(max);
		}
	}
	
	static boolean rCheck(int x, int y) {
		if(x < 0 || y < 0 || x > 5000 || y > 5000) return false;
		return true;
	}
	
	static boolean sCheck(int x, int y, int x1, int y2) {
		if(x == x1 && y == y2) return false;
		return true;
	}
	
	static boolean check(int x, int y, int x1, int y1) {
		if(!rCheck(x,y)) return false;
		if(sCheck(x,y,x1,y1)) return false;
		return true;
	}


}

Measured memory_bytes: 128456
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; // [9,223,372,036,854,775,807 to -9.....808] 19 digits
typedef long double ld;
#define inc(i, a, b) for (long long int i = a; i <= b; i++)
#define dec(i, a, b) for (long long int i = a; i >= b; i--)
#define fast                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(NULL);                \
    cout.tie(NULL);
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define lv vector<ll>
#define cv vector<char>
#define dv vector<ld>
#define rall(c) (c).rbegin(), (c).rend()
#define lpr pair<ll, ll>
#define mp make_pair
#define cin(c) \
    ll c;      \
    cin >> c;
#define lmap unordered_map<ll, ll>
#define vinp(a, n) \
    inc(i, 1, n)   \
    {              \
        cin(k);    \
        a.pb(k);   \
    }
#define LIM 1000000007
#define F first
#define S second
#define fr(i, n) inc(i, 0, n - 1)
#define fri(n, a) \
    inc(i, 0, n - 1) { cin >> a[i]; }
//#define end cout<<"\n";
#define debug(p) cout << p;
#define umap unordered_map
#define uset unordered_set
#define fill(a, val, n) \
    inc(i, 0, n - 1) { a[i] = val; }
void i_love_Accepted()
{
    ll n;
    cin>>n;
    string ans="";
    while(n)
    {
        n--;
        ans.pb(char('a'+n%26));
        n/=26;
    }
    reverse(all(ans));
    cout<<ans;
}   
int main()
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        i_love_Accepted();
        //end;
    } 
}


Measured memory_bytes: 3568
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <set>
#include <queue>
#include <string>
#include <iostream>
#include <stack>
#include <bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,int> pii;
const ll mod = 1e9+7;
const int inf  = 0x3f3f3f3f;

struct cmp
{
	bool operator()(const pii & a, const pii & b)
	{
		return a.second > b.second;
	}
};

const int maxn = 1e5+5;
int a[maxn];
std::vector<int> vv[maxn];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for (int  i= 1; i <= n; i ++ )
		scanf("%d",&a[i]);
	for (int  i= 1; i <= m; i ++ )
	{
		int x,y;
		scanf("%d%d",&x,&y);
		vv[x].push_back(y);
		vv[y].push_back(x);
	}
	int ans =0 ;
	for(int i = 1; i <= n; i ++ )
	{
		int f = 1;
		for(int j = 0; j < vv[i].size();j ++ )
		{
			int  v=  vv[i][j];
			if(a[i] <= a[v])
			{
				f = 0;
				break;
			}
		}
		if(f)
			ans ++ ;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 8776
n,t = map(int,input().split())
now = [0 for _ in range(t+1)]
wv = []
for _ in range(n):
  wv.append(list(map(int,input().split())))
wv.sort(key=lambda x:x[0])
for i in range(n):
  w,v = wv[i]
  last = now
  now = []
  for f in range(t):
    if f - w >= 0:
      now.append(max(last[f],last[f-w]+v))
    else:
      now.append(last[f])
  now.append(max(last[-2]+v,last[-1]))
  #print(now)
print(now[-1])

Measured memory_bytes: 52568
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#define fi first
#define se second
#define pb(i) push_back(i)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mes(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 55+10;
const int INF = 0x3f3f3f3f;
const int inf = - INF;
const int mod = 1e9+7;
const double pi = acos(-1.0);

ll x[N];
ll dp[N][N][N*N];
int main(){
    int n,a;
    cin>>n>>a;
    mes(dp,0);
    rep(i,1,n)
        cin>>x[i];
    rep(i,0,n){
        rep(j,0,n){
            rep(k,0,n*a){
                if(i==0&&j==0&&k==0) dp[i][j][k]=1;
                else if(i>=1&&k<x[i]) dp[i][j][k]=dp[i-1][j][k];
                else if(i>=1&&j>=1&&k>=x[i]) dp[i][j][k]=dp[i-1][j][k]+dp[i-1][j-1][k-x[i]];
                else dp[i][j][k]=0;
            }
        }
    }
    ll ans=0;
    rep(i,1,n){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 139648
#include <stdio.h>

int main(){
	int obj;
	int i, j;
	int w[10];

	while( ~scanf("%d",&obj) ){
		for( i=512, j=0; i>=1; i=i/2 ){
			if( obj - i >= 0 ){
				w[j++] = i;
				obj -= i;
			}
		}
		for( i=j-1; i>=0; i-- ){
			printf("%d", w[i]);
			(i==0)? putchar('\n'):putchar(' ');
		}
	}
	
	return 0;
}
		

Measured memory_bytes: 596
#include <iostream>
#include <string>


using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    if (s == t.substr(0, s.length())) {
        if (s.length() + 1 == t.length()) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3632
import math
from functools import reduce
import time

def gcd(*numbers):
    return reduce(math.gcd, numbers)

K = int(input())
ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(i, j, k)
print(ans)


Measured memory_bytes: 69644
erast s = let erasti [] = []
              erasti (x:xs) = x : erasti (filter (\y -> y`mod`x /= 0) xs)
          in
          erasti [2..s]
putlis [] = putStrLn ""
putlis (x:xs) = do
                putStr $ show x ++ " "
                putlis xs
main = do
       n <- getLine
       putlis $ take (read n) $ filter (\x -> x `mod` 5 == 1) $ erast 55555

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()

int main(){
  ll N,M;
  cin >> N >> M;
  if(N*N==M){
    cout << N << endl;
  }else if(N*N<M){
    for(ll i=N;i*i<M;i++){
      if(M%i==0){
        cout << M/i << endl;
        return 0;
      }
    }
    for(ll i=N-1;i>0;i--){
      if(M%i==0){
        cout << i << endl;
        return 0;
      }
    }
  }else{
    for(ll i=M/N;i>0;i--){
      if(M%i==0){
        cout << i << endl;
        return 0;
      }
    }
  }
      
}

Measured memory_bytes: 3596
// https://atcoder.jp/contests/abc146/tasks/abc146_e

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)

const int N_MAX = 2*1e5;
const int K_MAX = 1e9;
const int A_I_MAX = 1e9;

int N, K;
int A[N_MAX];

map<int, vector<int>> mp;

void solve() {
  ll ans = 0;
  int f = 0;
  mp[f].push_back(0);
  REP(i, N) {
    f = (f + A[i] - 1) % K;
    vector<int> &vec = mp[f];
    ans += vec.end() - upper_bound(vec.begin(), vec.end(), i + 1 - K);
    vec.push_back(i + 1);
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N) scanf("%d", A + i);
}

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


Measured memory_bytes: 22912
while True:
    str = input()
    if str == "-":
        break
    count = int(input())
    result = str

    for i in range(count):
        sep = int(input())

        str_1 = result[:sep]
        str_2 = result[sep:]
        result = str_2 + str_1
    else:
        print(result)


Measured memory_bytes: 5588
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
const int N = 1e8+5;
int n;
int a[N];
bool flag = false;
int main(){
	int j  = 1;
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> a[i];
	sort(a+1,a+n+1);
	for(int i = 1; i < n; i++){
		if(a[i] == a[i+1]){
			puts("NO");
			return 0;
		}
	}
	puts("YES");
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> L(N);
  for (int i = 0; i < N; i++) cin >> L.at(i);

  sort(L.rbegin(), L.rend());

  int ans = 0;

  for (int i = 0; i < K; i++) {
    ans += L.at(i);
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int ,int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 1e5 + 10, LOG = 20;

int p[N], ans, n, k, st[N], en[N];
int par[LOG][N], h[N], seg[4 * N], tim;
vector<int> adj[N], que[N];

void p_dfs(int v){
	st[v] = tim++;
	par[0][v] = p[v];
	
	for(int j=1; j<LOG; j++)
		par[j][v] = par[j - 1][par[j - 1][v]];

	for(auto u : adj[v]){
		if(u == p[v])continue;
		h[u] = h[v] + 1;
		p_dfs(u);
	}
	en[v] = tim;
}

int i_par(int v, int c){
	if(h[v] < c)return -1;
	for(int j=LOG-1; j>=0; j--)
		if(c & (1 << j))v = par[j][v];
	return v;
}

void upd(int id, int vl, int L, int R,int s = 0, int e = n){
	if(L<=s && e<=R){
		seg[id] += vl;
		return ;
	}
	if(L>=e || s>=R)return ;
	int mid = (s + e)/2;
	upd(2*id, vl, L, R, s, mid);
	upd(2*id + 1, vl, L, R, mid, e);
}


int get(int id, int p, int s = 0, int e = n){
	if(e - s < 2)
		return seg[id];
	int mid = (s + e)/2;
	if(p < mid)
		return seg[id] + get(2*id, p, s, mid);
	else return seg[id] + get(2*id + 1, p, mid, e);
}

void dfs(int v){
	for(auto u : adj[v]){
		if(u == p[v])continue;
		dfs(u);
	}
	bool need = 0;
	for(auto u : que[v]){
		int cnt = get(1, st[u]) - get(1, st[p[v]]);
		if(cnt == 0)need = true;
	}
	if(need)
		upd(1, 1, st[v], en[v]), ans++;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n >> k;
	
	for(int i=1; i<=n; i++){
		cin >> p[i];
		if(i == 1 && p[i] != 1)ans++, p[i] = 1;
		else if(i != 1){
			adj[i].pb(p[i]);
			adj[p[i]].pb(i);
		}
	}

	p_dfs(1);
	for(int i=1; i<=n; i++){
		if(h[i] <= k)continue;
		int u = i_par(i, k - 1);
		que[u].pb(i);
	}
	
	dfs(1);
	cout << ans << endl;
}


Measured memory_bytes: 26880
{-# LANGUAGE OverloadedStrings #-} 
import qualified Data.Text as T
import qualified Data.Text.IO as I

isPalindrome :: T.Text -> Bool
isPalindrome t
  | T.length t <= 1 = True
  | T.head t == T.last t = isPalindrome $ T.init $ T.tail t
  | otherwise = False

main :: IO ()
main = do
    line <- I.getLine
    let len = T.length line
    let halfLen = (len - 1) `div` 2
    let ans = isPalindrome line && isPalindrome (T.take halfLen line) && isPalindrome (T.drop (halfLen+1) line)
    putStrLn $ if ans then "Yes" else "No"

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

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))


using namespace std;
int main(){
	int ans = 0, N;
	cin>>N;
	for(int i=0;i<N;++i){
		int l,r;
		cin>>l>>r;
		ans += r+1-l;
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 256
import sys
import numpy as np

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

S = list(rs())
cnt_B = 0
answer = 0
for s in S:
    if s == 'B':
        cnt_B += 1
    else:
        answer += cnt_B
print(answer)


Measured memory_bytes: 14540
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int N;

  cin>>N;

  if(N%2==0){
    cout<<N<<endl;
  }else{
    cout<<2*N<<endl;
  }

}




Measured memory_bytes: 256
from collections import defaultdict
n, W = map(int, input().split())
dd = defaultdict(list)
for i in range(n):
    weight, value = map(int, input().split())
    dd[weight].append(value)

a = min(dd.keys())
b, c, d = a+1, a+2, a+3
Vcum = defaultdict(lambda: [0])
for k in [a, b, c, d]:
    s = 0
    dd[k].sort(reverse=True)
    for val in dd[k]:
        s += val
        Vcum[k].append(s)

ans = 0
for w in range(len(dd[a])+1):
    for x in range(len(dd[b])+1):
        for y in range(len(dd[c])+1):
            if W < a*w+b*x+c*y:
                break
            z = min((W-a*w-b*x-c*y)//d, len(dd[d]))
            val = Vcum[a][w]+Vcum[b][x]+Vcum[c][y]+Vcum[d][z]
            ans = max(ans, val)
print(ans)


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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<ll> vll;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = a; i<b; ++i)
#define pb push_back
#define INF 1000000000


int main(){
	IO
	int s, w;
	cin >> s >> w;
	if(w >= s)
		cout << "unsafe\n";
	else
		cout << "safe\n";
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define INF 1073741824
#define ll long long
#define PI (2*acos(0.0))
#define Hare prllf("here\n")
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define x first
#define y second
#define on(val,pos) val|(1<<pos)
#define off(val,pos) val&(~(1<<pos))
#define check(val,pos) (val&(1<<pos))

//first four adjacent,second four corner
//ll row[8]={0,-1,0,1,1,-1,-1,1};
//ll col[8]={-1,0,1,0,-1,-1,1,1};
using namespace std;

int main(){
    ll i,j,k,n,m,val,t=0,cnt,test;
    //freopen("000input.txt","r",stdin);
    cin>>n>>k;
    ll arr[k+5];
    memset(arr,0,sizeof arr);
    for(i=0;i<n;i++){
        scanf("%lld %lld",&m,&val);
        for(j=k;j>=m;j--){
            arr[j]=max(arr[j],arr[j-m]+val);
        }
    }
    printf("%lld\n",arr[k]);
    //free();   //if poller array
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
ll const MOD=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin>>N;
    N=N*(N-1)/2;
    cout<<N<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int a,b,c,temp;
  scanf("%d%d%d",&a,&b,&c);
  if(a>b) {
    while(a>b) {
      temp = a;
      a = b;
      b = temp;
      while(b>c) {
        temp = b;
        b = c;
        c = temp;
      }
    }
  }
  else {
    while(b>c) {
      temp = b;
      b = c;
      c = temp;
      while(a>b) {
        temp = a;
        a = b;
        b = temp;
      }
    }
  }
  printf("%d %d %d\n",a,b,c);
return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n), f(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> f[i];
	ll ng = -1, ok = INF;
	while (ok - ng > 1) {
		ll mid = (ng + ok) / 2;
		vector<ll> b = a;
		sort(all(b));
		vector<ll> c(n);
		rep(i, n) c[i] = mid / f[i];
		sort(all(c));
		ll cnt = 0;
		rep(i, n) cnt += max(b[i] - c[i], 0ll);
		if (cnt <= k) ok = mid;
		else ng = mid;
	}
	cout << ok << '\n';
}

Measured memory_bytes: 8600
#include<stdio.h>

int main(void)
{
	int n, k,num;
	int i;
	scanf("%d %d", &n, &k);
	num = k;
	for (i = 0; i < n - 1; i++)
	{
		num = num*(k - 1);
	}
	printf("%d\n", num);
	return 0;
}

Measured memory_bytes: 128
// D.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;
typedef long long LL;

int main(int argc, char* argv[]) {
	LL x;
	cin >> x;
	for (LL a = -500; a <= 500; ++a) {
		for (LL b = -500; b <= 500; ++b) {
			if (a * a * a * a * a - b * b * b * b * b == x) {
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	return 0;
}


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

int main() {
    int K;
    cin >> K;
    int A , B;
    cin >> A >> B;
    bool a = false;
    for(int i = A; i <= B; i++){
        if(i % K == 0){
            a = true;
            break;
        }
    }
    if(a){
        cout << "OK" << endl;
    }
    else{
        cout << "NG" << endl;
    }
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std; 
ll gcdExtended(ll a, ll b, ll *x, ll *y); 
  
// Function to find modulo inverse of a 
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1) 
        cout << "Inverse doesn't exist"; 
    else
    { 
        // m is added to handle negative x 
        ll res = (x%m + m) % m; 
        return  res; 
    } 
} 
  
// C function for extended Euclidean Algorithm 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    // Base Case 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; // To store results of recursive call 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    // Update x and y using results of recursive 
    // call 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
} 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or 
                // equal to 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; 
} 
ll nCr(ll n,ll r,ll m)
{
    ll res = 1;
    for (ll i = 1; i <= r; ++i)
    {
        res = (res*(n-i+1)%MOD)*modInverse(i,MOD);
        res%=MOD;
    }
    return res;
}
int main()
{
    ll n,k;
    cin>>n>>k;
    if(n<=k)
    {   
        cout<<nCr(2*n-1,n,MOD);
    }
    else
    {
        ll a=1;
        ll ans=0;
        // cout<<a<<endl;
        for (int i = 0; i <= k; ++i)
        {
            ans+=a;
            ans%=MOD;
            a*= (n-i);
            a%=MOD;
            a*= (n-i-1);
            a%=MOD;
            a*=modInverse(i+1,MOD);
            a%=MOD;
            a*=modInverse(i+1,MOD);
            a%=MOD;
            // cout<<a<<endl;
        }
        cout<<ans<<endl;
    }
    //cout<<(power(2,n,MOD)-nCr(n,a,MOD)-nCr(n,b,MOD)-1+MOD+MOD+MOD)%MOD<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    int n, al=0, bo=0;
    cin>>n;
    int a[n];
    for (int i=0; i<n; i++) cin>>a[i];
    sort(a, a+n);
    reverse(a, a+n);
    for (int i=0; i<n; i++)
    {
        if (i%2==0) al+=a[i];
        else bo+=a[i];
    }
    cout<<al-bo<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int N;
  cin >> N;
  if(N%2==0) printf("%.6f\n", 0.5);
  else printf("%.6f\n", ((double)N+1.0)/(2.0*(double)N));
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<cmath>
#include<unordered_set>
using namespace std;

signed main() {
	int n; cin >> n;
	map<int, int>a;
	for (int i = 0; i < n; i++) {
		int b; cin >> b;
		a[b % 4]++;
	}
	a[1] += a[3];
	if ((a[1] - 1 <= a[0]&&a[1]+a[0]==n)||a[1]<=a[0]) {
		puts("Yes");
	}
	else {
		puts("No");
	}
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

string x, y;

int main() {
	cin >> x >> y;
	
	cout << (x == y ? "=" : (x < y ? "<" : ">")) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <map>

using namespace std;

int main()
{
    int q;
    cin >> q;

    map<string, int> S;
    int cmd, x;
    string key;
    while (q--)
    {
        cin >> cmd;
        if (cmd == 0)
        {
            cin >> key >> x;
            S[key] = x;
            // cout << S.size() << endl;
        }
        else if (cmd == 1)
        {
            cin >> key;
            // cout << (S.find(x) != S.end()) << endl;

            if (S.find(key) != S.end())
                cout << S[key] << endl;
            else
                cout << 0 << endl;

            //由于不存在键值时，会以默认值插入，所以会输出0
            //  cout << S[key] << endl;
        }
        else if (cmd == 2)
        {
            cin >> key;
            S.erase(key);
            // remove(S.begin(), S.end(), x);
        }
        else
        {
            string L, R;
            cin >> L >> R;

            map<string ,int>::iterator it1 = S.lower_bound(L), it2 = S.upper_bound(R);
            while (it1 != it2)
            {
                cout << it1->first << ' ' << it1->second << endl;
                it1++;
            }

            //法2
            // map<string, int>::iterator it = S.begin();
            // while (it != S.end())
            // {
            //     if (it->first >= L && it->first <= R)
            //     cout << it->first << ' ' << it->second << endl;
            //     it++;                
            // }

        }

    }
}


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

#define pb push_back
#define int long long
#define debug(n) cerr << #n << " = " << n << '\n';

using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN] , dp[MAXN];

int32_t main() {
    int n,k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = 1; i < n; i++) {
        dp[i] = 1e9;
        for(int j = 1; j <= min (i , k); j++)
            dp[i] = min(dp[i] , dp[i - j] + abs(a[i] - a[i - j]));
    }
    cout << dp[n - 1];
    return 0;   
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define mod 1000000007
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i;
    cin>>n;
    vi a(n),b(n),v(n);
    //int i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=0;i<n;i++)
    {
        cin>>b[i];
    }
    int x=0,y=0;
    for(i=0;i<n;i++)
    {
        v[i]=i+1;
    }
    if(v==a) x=1;
    if(v==b) y=1;
    i=2;
    while(next_permutation(v.begin(),v.end()) && (x==0 || y==0))
    {
        if(v==a) x=i;
        if(v==b) y=i;
        i++;
    }
    cout<<abs(x-y)<<endl;
}

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

int main() {
	string a, t;char s[210];
	cin >> a >> t;
	for (int i = 0; i < a.length(); i++) {
		s[i] = a[i]; s[i + a.length()] = a[i];
	}
	bool flag;
	for (int i = 0; i < a.length() * 2 - t.length(); i++) {
		flag = true;
		for (int j = i; j < i + t.length(); j++) {
			if (s[j] != t[j-i]) {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

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

  LL A, B, C;
  cin >> A >> B >> C;
  if((A<C&&C<B)||(A>C&&C>B)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

class card{
public:
    char m;
    int n;
};

int main(void){
    int n,min,flag=0;
    card a[36],b[36];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i].m>>a[i].n;
        b[i]=a[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=n-1;j>i;j--){
            if(a[j-1].n>a[j].n)
            swap(a[j-1],a[j]);
        }
    }
    for(int i=0;i<n;i++){
        min=i;
        for(int j=i;j<n;j++){
            if(b[j].n<b[min].n){
                min=j;
            }
        }
        swap(b[i],b[min]);
    }
    for(int i=0;i<n-1;i++)
    cout<<a[i].m<<a[i].n<<" ";
    cout<<a[n-1].m<<a[n-1].n<<endl;
    cout<<"Stable"<<endl;
    for(int i=0;i<n-1;i++){
        if(a[i].m!=b[i].m) flag=1;
        cout<<b[i].m<<b[i].n<<" ";
    }
    cout<<b[n-1].m<<b[n-1].n<<endl;
    if(flag)cout<<"Not stable"<<endl;
    else cout<<"Stable"<<endl;
    return 0;
    
}


Measured memory_bytes: 3104
#!/usr/bin/ruby

def result(cardLists)
  aScore, bScore = 0, 0
  cardLists.each do |aCards, bCards|
    if aCards < bCards
      bScore += aCards + bCards
    elsif aCards == bCards
      aScore += aCards
      bScore += aCards
    else
      aScore += aCards + bCards
    end
  end
  [aScore, bScore]
end

while true
  c = STDIN.gets
  if c.to_i == 0
    break
  end

  cardLists=[]
  (1..c.to_i).each do
    cardLists << STDIN.gets.split(/\s*/).map(&:to_i)
  end

  puts result(cardLists).join(" ")
end

Measured memory_bytes: 9176
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            double w = Double.parseDouble(in.next());
            double h = Double.parseDouble(in.next());
            double x = Double.parseDouble(in.next());
            double y = Double.parseDouble(in.next());
            double ans = w * h / 2.0;
            // 出力
            out.printf("%.10f", ans);
            out.print(" ");

            if (2 * x == w && 2 * y == h) out.print(1);
            else out.print(0);

        }

    }
}



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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int n;
    cin >> n;
    int g;
    cin >> g;
    for(int i = 1; i < n; ++i) {
        int a;
        cin >> a;
        g = __gcd(g, a);

    }
    cout << g << endl;
    return 0;
}



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

namespace NotFounds
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }

        public void Solve(ConsoleInput cin)
        {
            checked
            {
                if (string.Join("", cin.Read.ToCharArray().OrderBy(x => x)) == "abc")
                    WriteLine("Yes");
                else
                    WriteLine("No");
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
        public void ReadIntArrays(long N, out int[] A, out int[] B) { A = new int[N]; B = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; }}
        public void ReadIntArrays(long N, out int[] A, out int[] B, out int[] C) { A = new int[N]; B = new int[N]; C = new int[N]; for (long i = 0; i < N; ++i) { A[i] = ReadInt; B[i] = ReadInt; C[i] = ReadInt; }}
        public void ReadLongArrays(long N, out long[] A, out long[] B) { A = new long[N]; B = new long[N]; for (long i = 0; i < N; ++i) { A[i] = ReadLong; B[i] = ReadLong; }}
    }
}


Measured memory_bytes: 13396
N = gets.to_i
ts = gets.split.map(&:to_f)
vs = [0.0, *gets.split.map(&:to_f), 0.0]

ts2 = ts.reduce([0]) { |memo, t| memo + [memo.last + t] }
T = ts2.last
fs = [-1, *ts2, T + 1].each_cons(2).zip(vs)

ws = 0.step(T, 0.5).map do |t|
  fs.map do |(l, r), v|
    if t < l
      v + (l - t)
    elsif t <= r
      v
    else
      v + (t - r)
    end
  end.min
end

ans = ws.each_cons(2).map { |w1, w2| w1 + w2 }.reduce(&:+) * 0.25
puts format('%.15f', ans)


Measured memory_bytes: 5116
#include<iostream>

using namespace std;

int main() {

	int a, b;
	cin >> a >> b;

	if ((a + b) % 3 == 0 || a % 3 == 0 || b % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{  
    public void yatary() { 
    Scanner sc = new Scanner(System.in);
        double r,f,men,syu;
          r = sc.nextDouble();
          f = 3.141592653589;
          men = r *1.0 * r * 1.0 * f;
          syu = r * 1.0 * 2 * f;
          System.out.printf("%2.6f %2.6f",men,syu);
    }
    public static void main(String[] args){ 
    new Main().yatary();   
   }
} 

Measured memory_bytes: 18880
#include<bits/stdc++.h>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;
bool visited[100005];
const int max_N=1e5+10;
int A,B;
int main(void)
{
  string s;
  cin >> s;
  int lose=0;
  for (int i = 0; i < int(s.size()); ++i)
    {
      if(s[i]=='x') lose++;
    }
  if(lose>=8)
    {
      cout << "NO" << endl;
    }
  else
    {
      cout << "YES" << endl;
    }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define F first
#define S second
#define PB push_back
#define INF 1000000001
#define INFL 1000000000000000001
#define M 1000000007
struct T{
	int a,b,c;
	bool operator<(const T&q)const{
		if(a!=q.a)return a<q.a;
		if(b!=q.b)return b<q.b;
		return c<q.c;
	}
};
int n,par[100005],ans;
T m[100005];
vector<T>e;
int find(int v){
	if(par[v]==v)return v;
	return par[v]=find(par[v]);
}
bool same(int v,int u){
	return find(v)==find(u);
}
void unit(int u,int v){
	v=find(v);
	u=find(u);
	par[v]=u;
}
int main(void){
	cin>>n;
	for(int i=0;i<n;i++){
		scanf("%d%d",&m[i].a,&m[i].b);
		m[i].c=i;
	}
	sort(m,m+n);
	for(int i=0;i+1<n;i++)e.PB(T{m[i+1].a-m[i].a,m[i].c,m[i+1].c});
	for(int i=0;i<n;i++)swap(m[i].a,m[i].b);
	sort(m,m+n);
	for(int i=0;i+1<n;i++)e.PB(T{m[i+1].a-m[i].a,m[i].c,m[i+1].c});
	for(int i=0;i<n;i++)par[i]=i;
	sort(e.begin(),e.end());
	for(int i=0;i<e.size();i++){
		int a=e[i].c,b=e[i].b,c=e[i].a;
		if(!same(a,b)){
			ans+=c;
			unit(a,b);
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 6132
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define EPS 0.000001
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
int main()
{
  //flash;
  ll k;
  cin>>k;
  k--;
  ll si=1;
  ll vo=k;
  while(1){
    if(vo-pow(26,si)<0)break;
    vo-=pow(26,si);
    si++;
  }
  string ans;
  for (int i = 0; i < si; ++i)
  {
    ll last=0;
    char n='z';
    bool ka=false;
    for (int j = 1; j < 26; ++j)
    {
      last=last+pow(26,(si-i-1));
      if(last>vo){
        n=(j-1)+'a';
        last-=(pow(26,(si-i-1)));
        break;
      }
    }
    ans.pb(n);
    vo-=(last);
  }
  for(auto it:ans)cout<<it;
  return 0;
}
//code the AC sol !
// BS/queue/map

Measured memory_bytes: 4088
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define inf 1e9
#define F first
#define S second
#define dbg(x) cout<<#x<<" value : "<<x<<"\n";
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--)
#define mst(a,b) memset(a,b,sizeof(a))
#define sf(n) scanf("%d",&n)
#define stf(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d\n",n)
#define sllf(n) scanf("%lld",&n)
#define pllf(n) printf("%lld\n",n)
priority_queue<int,vector<int>,greater<int> > q;
const int N=2e3+10;
const int mod=1e9+7;
int n,a[N],sum=0;
int main()
{
	sf(n);
	rep(i,1,n)sf(a[i]);
	sort(a+1,a+n+1);
	rep(i,1,n){
		rep(j,i+1,n){
			for(int l=n;l>j;l--){
				if(a[i]+a[j]>a[l]){
					sum+=l-j;
					break;
				}
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1005
#define M 200005
using namespace std;

int n,m;
bool irp[N][N],lnk[N][N];
int rt,cnt,fir[N];
bool col[N];
vector<int>to[N];
struct edge{int u,v;}e[M];

inline int read()
{
	int ans=0,f=1;char c=getchar();
	while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') ans=(ans<<1)+(ans<<3)+(c^48),c=getchar();
	return ans*f;
}

inline void add(int a,int b){to[a].push_back(b);e[++cnt]=(edge){a,b};}

inline void dfs(int x)
{
	col[x]=lnk[rt][x]=1;
	for(auto it:to[x]) if(!col[it]) dfs(it);
}

inline void insert(int x)
{
	rt=x;
	memset(col+1,0,n*sizeof(col[0]));
	col[x]=1;
	for(auto it:to[x])
		if(col[it]) irp[x][it]=1;
		else dfs(it);
	reverse(to[x].begin(),to[x].end());
	memset(col+1,0,n*sizeof(col[0]));
	col[x]=1;
	for(auto it:to[x])
		if(col[it]) irp[x][it]=1;
		else dfs(it);
}

int main()
{
//	freopen("test.in","r",stdin);
	n=read(),m=read();
	for(int i=1;i<=m;++i)
	{
		int a=read(),b=read();
		add(a,b);
	}
	for(int i=1;i<=n;++i)insert(i);
	for(int i=1;i<=m;++i)
	{
		int x=e[i].u,y=e[i].v;
		puts(irp[x][y]^lnk[y][x]?"diff":"same");
	}
}

Measured memory_bytes: 6272
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def perm(n,mod=None):
    ans = 1
    for i in range(1,n+1):
        ans *= i
        if mod!=None:
            ans %= mod
    return ans
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,K=mint()
A=lint()
judge(K<=max(A) and K%lgcd(A)==0,['POSSIBLE','IMPOSSIBLE'])

Measured memory_bytes: 81572
a, b, c = map(int, input().split())
k = int(input())

while k > 0 and a >= b:
  k -= 1
  b *= 2

while k > 0 and b >= c:
  k -= 1
  c *= 2

if a < b < c:
  print("Yes")
else:
  print("No")

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

int main() {

    long long n;
    cin >> n;
    priority_queue<long long, vector<long long>, greater<long long> > under;
    priority_queue<long long, vector<long long>, greater<long long> > over;
    for (long long i=0; i<n; i++) {
        long long a;
        cin >> a;
        if (a < 0) {
            under.push(a);
        }
        else {
            over.push(a);
        }
    }
    while (under.size() > 1) {
        long long f = under.top();
        under.pop();
        long long s = under.top();
        under.pop();
        over.push(-f); over.push(-s);
    }
    long long sm = 0;
    if (under.size() == 1) {
        long long alt = over.top();
        over.pop();
        long long ye = under.top();
        under.pop();
        if (abs(ye) > abs(alt)) {
            sm += -ye - alt;
        }
        else {
            sm += alt + ye;
        }
    }
    while (!over.empty()) {
        sm += over.top(); over.pop();
    }
    cout << sm;
}

Measured memory_bytes: 2548