akhauriyash/Code-Regression huggingface dataset:
/*
ID: alec3
LANG: C++14
PROG:
*/


#include <bits/stdc++.h>

#define check(x) cout<<(#x)<<": "<<x<<" ";
#define io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ss second
#define ff first
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define ld long double
#define all(c) (c).begin(), (c).end()
#define FOR(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int pct(int x) { return __builtin_popcount(x); }


int main()
{
    io;
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& it : a) cin >> it;

    sort(a.rbegin(), a.rend());
    ll ans = a[0];
    int val = a[1];
    int pos = 1;
    FOR(i, 2, n){
        if (i + 1 == n)
            ans += val;
        else
            ans += 2 * val;
        i ++;
        pos ++;
        val = a[pos];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3956
// Problem : E - Dist Max
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define all(x) (x).begin() , (x).end()
#define inf 10000000000000000
#define mod 1000000007

void dbg(){
	cerr << endl;
}
template<typename Head , typename... Tail>
void dbg(Head h , Tail... t){
	cerr << h << " ";
	dbg(t...);
}

#ifdef EMBI_DEBUG
#define debug(...) cerr << "(" << #__VA_ARGS__  << "): ", dbg(__VA_ARGS__)
#else 
#define debug(...)
#endif

const ll max_n = 1e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
void solve(){
	ll n;
	cin >> n;
	
	ll x[n] , y[n];
	
	for(ll i = 0 ; i < n ; i++){
		cin >> x[i] >> y[i];
	}
	ll sum[n] , diff[n];
	
	for(ll i = 0 ; i < n ; i++){
		sum[i] = x[i] + y[i];
		diff[i] = x[i] - y[i];
	}
	
	
	ll max1 = -inf;
	
	ll min_sum = inf , min_diff = inf , max_sum = -inf , max_diff = -inf;
	for(ll i = 0 ; i < n ; i++){
		max1 = max(max1 , sum[i] - min_sum);
		max1 = max(max1 , diff[i] - min_diff);
		
		max1 = max(max1 , max_sum - sum[i]);
		max1 = max(max1 , max_diff - diff[i]);
		
		min_sum = min(min_sum , sum[i]);
		min_diff = min(min_diff , diff[i]);
		max_sum = max(max_sum , sum[i]);
		max_diff = max(max_diff , diff[i]);
	}
	
	cout << max1 << "\n";
}
signed main(){
	ll t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

ll dp[100005][2];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  string s; cin>>s;
  // s[i]==1 => (0,1)*2, s[i]==0 => (0,0)*1
  ll n=s.size();
  dp[0][0]=1;
  
  // (0,1)*2, (0,0)
  
  rep(i,n){
    // (dp[i+1][1]+=dp[i][1]*4%MOD)%=MOD;
    dp[i+1][1]=dp[i][1]*3%MOD;
    
    if(s[i]=='1'){
      (dp[i+1][1]+=dp[i][0])%=MOD;
      (dp[i+1][0]+=dp[i][0]*2%MOD)%=MOD; // 1,0
    }else{
      (dp[i+1][0]+=dp[i][0])%=MOD;
    }
  }
  ll ans=(dp[n][0]+dp[n][1])%MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 5312
import math

a,b=map(int,input().split())

emin=math.ceil(a/0.08)
emax=math.ceil((a+1)/0.08)-1
tmin=math.ceil(b/0.1)
tmax=math.ceil((b+1)/0.1)-1

if tmin<=emin<=tmax:
    print(emin)
elif emin<=tmin<=emax:
    print(tmin)
else:
    print(-1)

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

bool cmp(P &i, P &j) { return i.second < j.second; }

int main() {

  int N, M;
  cin >> N >> M;

  int c[M];
  vector<P> ab(M);
  rep(i, M) {
    int a, b;
    cin >> a >> b;
    ab[i] = make_pair(a, b);
  }
  sort(ab.begin(), ab.end(), cmp);

  vector<int> ret(1, ab[0].second - 1);
  rep(i, M) {
    int a = ab[i].first;
    int b = ab[i].second;
    if (ret.back() < a) {
      ret.push_back(b - 1);
    }
  }

  cout << ret.size() << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(int qtd, char* nome[])
{
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	int h, n;
	cin >> h >> n;
	ll sum = 0;
	for(int i=0, a; i<n; i++)
		cin >> a, sum += a;
	cout << (sum >= h? "Yes\n": "No\n");
	
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>

#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
int main()
{
	int n, m, a[40],i,j,k,ans=0 ;
	static int ta[40];
	//cin >> n >> m;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++)
	{
		
		//cin >> k;
		scanf("%d", &k);
		//printf("%d::", k);
		for (j = 1; j <= k; j++)
		{
			//cin >> a[j];
			scanf("%d", a + j);
			ta[a[j]]++;
		}
		
	}
	for (i = 1; i <= m; i++)
	{
		//printf("%d,%d\n", i, ta[i]);
		if (ta[i] == n) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define REL

#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <string>
#include <set>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <complex>
#include <stack> 
#include <random>

using namespace std;

typedef int64_t i64;
typedef long long LL;
typedef long long ll;
typedef long double LD;
typedef complex <LD> cld;
typedef unsigned int uint;
typedef complex <double> cd;
typedef unsigned long long ULL;

#define endl "\n"
#define dendl "\n\n"
#define mp make_pair
#define mt make_tuple
#define size(v) (int)v.size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

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

template <typename T>
T sqr(T a) {
	return a * a;
}

template <typename T>
int sign(T a) {
	if (a == 0)
		return 0;
	return (a > 0 ? 1 : -1);
}

template <typename T>
bool uax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
bool uin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T1, typename T2>
istream& operator >> (istream& in, pair<T1, T2>& p) {
	in >> p.first >> p.second;
	return in;
}

template <typename T1, typename T2>
ostream& operator << (ostream& out, pair<T1, T2>& p) {
	out << p.first << ' ' << p.second;
	return out;
}

mt19937_64 rnd(0);

const int LOG = 64;
const int N = (int)2e3 + 7;
const int MAXN = (int)1e7 + 7;
const int MOD = (int)1e9 + 7;
const int INF = (int)2e9 + 7;
const int CONST = 450;
const LL LINF = (i64)1e18;
const LD PI = 3.1415926535897932384626433832795;
const LD EPS = 1;

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

void solve() {
	int x, y;
	cin >> x >> y;
	for (int a = 0; a <= x; a++) {
		int b = x - a;
		if (2 * a + 4 * b == y) {
			cout << "Yes";
			return;
		}
	}
	cout << "No";
}

int main() {
	double start = clock();
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	cout << fixed << setprecision(20);
	cerr << fixed << setprecision(20);
#else
	cout << fixed << setprecision(20);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	rnd.seed(time(0));
#endif

	int t = 1;
	for (int i = 0; i < t; i++) {
		solve();
	}
	
#ifdef _DEBUG
	cout << endl << "Time is " << (clock() - start) / 1000.0;
#endif
}

Measured memory_bytes: 3648
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]

N = ri()
a = [int(_) - 1 for _ in rs().split()]
ans = 0
for i in range(N):
    if a[a[i]] == i:
        ans += 1
print(ans // 2)


Measured memory_bytes: 52336
import sys

sys.setrecursionlimit(10 ** 9)

def main():
  input = sys.stdin.buffer.readline
  read = sys.stdin.buffer.read
  # Nがノードの数, Qが操作回数
  N, Q = map(int, input().split())
  ABPX = list(map(int, read().split()))
  AB = iter(ABPX[:N+N-2])
  PX = iter(ABPX[N+N-2:])

  parents = [None] * N
  childrens = [set() for _ in range(N)]
  relations = [[] for _ in range(N)]
  shown = set()

  for a, b in zip(AB, AB):
    a -= 1
    b -= 1
    relations[a].append(b)
    relations[b].append(a)

  points = [0] * N
  result = [0] * N

  for p, x in zip(PX, PX):
    p -= 1
    points[p] += x

  def solve(parent, relations, points, result):
    result[parent] += points[parent]
    shown.add(parent)
    for child in relations[parent]:
      if child not in shown:
        result[child] += result[parent]
        solve(child, relations, points, result)
      
  solve(0, relations, points, result)
  print(*result)

if __name__ == "__main__":
  main()


Measured memory_bytes: 381436
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};

// // Nの約数の個数を求める
// int divide_num(int N){
//   int ans = 1;
//   vector<int> x(N + 1);
//   int num = N;
//   for (int i = 2; i <= N; i++) {
// 		while (num%i == 0) {
// 			x.at(i)++;
// 			num /= i;
// 		}
// 	}
//
// 	for (int i = 2; i <= N; i++)
// 	{
// 		ans *= x.at(i) + 1;
// 	}
//
//   return ans;
// }

// int divide(int N){
//   int ans = 0;
//   for (int i = 1; i <= N; i++){
//     if (N % i == 0) ans ++;
//   }
//   return ans;
// }

int main(void){
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i < N; i++){
    ans += (N - 1) / i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
n = int(input())
a = list(map(int, input().split()))

if n <= 2:
    print(1)
    exit()

dec, inc = False, False
cnt = 1

for i in range(n-1):
    if a[i+1] - a[i] < 0:
        dec = True
    elif a[i+1] - a[i] > 0:
        inc = True

    if dec and inc:
        cnt += 1
        dec, inc = False, False

print(cnt)

Measured memory_bytes: 14228
let n, m = stdin.ReadLine().Split() |> Array.map int |> fun [|x1; x2|] -> x1, x2
let pStrs =
    [| for _ in 1..m -> stdin.ReadLine().Split() |> fun [|x1; x2|] -> int x1, x2 |]

let acSet, waMap =
    pStrs
    |> Seq.fold 
        (fun (acSet,waMap) (p, str) ->
            match str with
            |"AC" ->
                ((acSet |> Set.add p)
                , waMap)
            |"WA" -> 
                (acSet
                , 
                    if acSet.Contains p then waMap
                    else waMap |> Map.add p (waMap |> Map.tryFind p |> function Some(v) -> v+1 | None  -> 1)))
        (Set.empty, Map.empty)

((acSet |> Set.count)
, waMap |> Seq.sumBy (fun kp -> if acSet.Contains kp.Key then kp.Value else 0))
|> fun x -> (fst x |> string) + " " + (snd x |> string)
|>stdout.WriteLine

Measured memory_bytes: 38796
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[11];
int used[11];
int sv=0;
int solve(int v){
	if(v==9){
	//	for(int i=1;i<11;i++)if(!used[i])return 0;
		return 1;
	}
	int ret=0;
	if(a[v]){
		bool ok=true;
		int i=a[v];
		if(v==2)sv=(a[0]+a[1]+a[2])%a[9];
		if(v%3==2){
			if((a[v-2]+a[v-1]+i)%a[9]!=sv)ok=false;
		}
		if(v>=6){
			if((a[v-6]+a[v-3]+i)%a[9]!=sv)ok=false;
		}
		if(v==6){
			if((a[2]+a[4]+i)%a[9]!=sv)ok=false;
		}
		if(v==8){
			if((a[0]+a[4]+i)%a[9]!=sv)ok=false;
		}
		if(ok){
			return solve(v+1);
		}else return 0;
	}
	for(int i=1;i<=10;i++){
		if(used[i])continue;
		bool ok=true;
		if(v==2)sv=(a[0]+a[1]+i)%a[9];
		if(v%3==2){
			if((a[v-2]+a[v-1]+i)%a[9]!=sv)ok=false;
		}
		if(v>=6){
			if((a[v-6]+a[v-3]+i)%a[9]!=sv)ok=false;
		}
		if(v==6){
			if((a[2]+a[4]+i)%a[9]!=sv)ok=false;
		}
		if(v==8){
			if((a[0]+a[4]+i)%a[9]!=sv)ok=false;
		}
		if(!ok)continue;
		used[i]=1;
		a[v]=i;
		ret+=solve(v+1);
		used[i]=0;
		a[v]=0;
	}
	//printf("%d: %d\n",v,ret);
	return ret;
}
int main(){
	while(1){
		for(int i=0;i<10;i++)scanf("%d",a+i);
		if(a[0]==-1)break;
		for(int i=0;i<11;i++)used[i]=0;
		for(int i=0;i<10;i++)if(a[i])used[a[i]]=1;
		if(a[9]){
			printf("%d\n",solve(0));
		}else{
			int ret=0;
			for(int i=1;i<=10;i++){
				if(used[i])continue;
				used[i]=1;
				a[9]=i;
				ret+=solve(0);
				used[i]=0;
			}
			printf("%d\n",ret);
		}
	}
}

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


def f(S, N, A, B, C, D):
    if B > C:
        if g(S, A, C) or g(S, C, D):
            return 'No'
        else:
            return 'Yes'
            
    elif C < D:
        if g(S, A, D):
            return 'No'
        else:
            return 'Yes'
        
    else:
        if g(S, A, B):
            return 'No'

        if g2(S, B-1, D):
            return 'Yes'
        
        return 'No'


def g(S, X, Y):
    for i in range(X-1, Y-1):
        if S[i] == '#' and S[i+1] == '#':
            return True

    return False



def g2(S, X, Y):
    for i in range(X-1, Y-1):
        if S[i] == '.' and S[i+1] == '.' and S[i+2] == '.':
            return True

    return False



def main():
    N, A, B, C, D = map(int, input().split())
    S = input()

    print(f(S, N, A, B, C, D))
 


if __name__ == '__main__':
    main()


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

int main() {
  string s; cin >> s;
  int n = s.size();
  long long ans = 0;

  for(int i = 0; i < (1<<(n-1)); i++) {
    long long t = s[0] - '0';
    for(int j = 0; j < n-1; j++) {
      if(i>>j & 1) {
        ans += t;
        t = s[j+1] - '0';
      } else {
        t *= 10;
        t += s[j+1] - '0';
      }
    }
    ans += t;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> d(n);
	for(int i=0;i<n;i++)
		cin >> d[i];
	
	long long cnt=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++)
		{
			cnt+=(d[i]*d[j]);
		}
	
	cout <<cnt << endl;





}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double x = sc.nextDouble();
    double s = x/a;

    if(s <= (a*b)/2){
      double a1 = 2*s/b;
      double result1 = Math.atan(b/a1);
      System.out.println(Math.toDegrees(result1));
    }else{
      double result2 = Math.atan(2*(a*b-s)/(a*a));
      System.out.println(Math.toDegrees(result2));
    }
  }
}


Measured memory_bytes: 23124
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val y = sc.nextInt() / 1000
  var a = -1
  var b = -1
  var c = -1

  for {
    i <- 0 to n
    j <- 0 to n-i
    if a == -1
  } {
    val k = n - i - j
    if (10 * i + 5 * j + k == y) {
      a = i
      b = j
      c = k
    }
  }

  println(s"$a $b $c")
}

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

const int N = 2e5 + 10;

char s[N], str[N];
int cnt[N];

int main(){
	int n, tot;
	long long ans;
	scanf("%s", s + 1);
	n = strlen(s + 1);
	tot = 1; str[1] = s[1];
	for (int i = 2; i <= n; i++){
		if (str[tot] == 'B' && s[i] == 'C') str[tot] = 'D';
		else str[++tot] = s[i];
	}
	if (str[tot] == 'D') cnt[tot] = 1;
	else cnt[tot] = 0;
	for (int i = tot - 1; i >= 1; i--){
		if (str[i] == 'B' || str[i] == 'C') cnt[i] = 0;
		else{
			cnt[i] = cnt[i + 1];
			if (str[i] == 'D') cnt[i]++;
		}
	}
	ans = 0;
	for (int i = 1; i <= tot; i++){
		if (str[i] == 'A') ans += cnt[i];
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define rep(i, n) for(int i=0; i < (n); ++i)
#define ll long long

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; }}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; }}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    int n; cin >> n;
    v<int> a(n); rep(i,n) cin >> a[i];

    int digit = 1;
    int ans = 0;
    rep(i,n) {
        if (a[i] == digit) {
            ++digit;
        } else {
            ans++;
        }
    }
    if (digit == 1) {
        ans = -1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
n, c = [int(item) for item in input().split()]
ds = [[int(item) for item in input().split()] for _ in range(c)]
cs = [[int(item) for item in input().split()] for _ in range(n)]

counter = [[0] * (c+1) for _ in range(3)]
for i in range(n):
  for j in range(n):
    counter[(i+j) % 3][cs[i][j]] += 1
    
costs = [[0] * (c+1) for _ in range(3)]
for i in range(1, c+1):
  for j in range(3):
    for k, count in enumerate(counter[j]):
      if k == 0:
        continue
      costs[j][i] += ds[k-1][i-1] * count

ans = 500*500*1000
for i in range(c):
  for j in range(c):
    for k in range(c):
      if i == j or j == k or k == i:
        continue
      sol = costs[0][i+1] + costs[1][j+1] + costs[2][k+1]
      ans = min(ans, sol)
    
print(ans)


Measured memory_bytes: 5492
s1 = input()
s2 = input()

x, y, z = [int(i) for i in s1.split()]
l = [int(i) for i in s2.split()]

if x == 1:
  print(abs(z - l[x-1]))
else:
  if abs(z - l[x-1]) > abs(l[x-1] - l[x-2]):
    print(abs(z - l[x-1]))
  else:
    print(abs(l[x-1] - l[x-2]))

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

char s1[55], s2[55];
int n;
const int P = 1000000007;

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> s1[i];
	for (int i = 1; i <= n; i++) cin >> s2[i];
	long long ans = 0;
	if (s1[1] == s2[1]) ans = 3;
	else ans = 6;
	for (int i = 2; i <= n; i++) {
		if (s1[i] == s1[i - 1]) continue;
		if (s1[i - 1] == s2[i - 1]) ans = 1ll * ans * 2 % P;
		else {
			if (s1[i] != s2[i]) ans = 1ll * ans * 3 % P;
		}
	}
	cout << ans << endl;
}

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

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

int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;

    for (int i = l; i <= r; i++) {
        if (i % d == 0) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    int i,j[3] = {0},len[3],turn = 0;
    char abc[3][101];

    for (i = 0; i < 3; i++)
    {
        scanf("%s",abc[i]);
        len[i] = strlen(abc[i]);
    }

    do
    {
        j[turn]++;
        turn = abc[turn][j[turn] - 1] - 'a';
        if(j[turn] == len[turn])
        {
            break;
        }
    }while(1);
    printf("%c",'A' + turn);
}

Measured memory_bytes: 128
fn chmin<T: PartialOrd>(x: &mut T, a: T) {
    if *x > a {
        *x = a;
    }
}

fn main() {
    proconio::input! {
        n: usize,
        w: u32,
        item: [(u32, usize); n],
    }
    let mut dp = vec![w + 1; 1000 * n + 1];
    dp[0] = 0;
    for (w, v) in item {
        let mut next = dp.clone();
        for (x, y) in next.iter_mut().skip(v).zip(dp.iter()) {
            chmin(x, *y + w);
        }
        dp = next;
    }
    let ans = dp.into_iter().rposition(|p| p <= w).unwrap();
    println!("{}", ans);
}

Measured memory_bytes: 2812
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n,m;
    cin >> n>>m;
    vector<int> l(m);
    vector<int> r(m);
 
    for (int i=0;i<m;i++){
        cin >> l.at(i);
        cin >> r.at(i);
    }
    int lmax,rmin;
    lmax = *std::max_element(l.begin(),l.end());
    rmin = *std::min_element(r.begin(),r.end());
    if (lmax > rmin) {
        cout << 0 <<endl;
    }
    else{
        cout << rmin-lmax+1<<endl;
    }
 
}

Measured memory_bytes: 1024
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int h;

int solve(int n){
   if(n <= 1)
      return n;

   return 2 * solve(n/2) + 1;
}

int32_t main(){_
   
   cin>>h;
      
   cout<<solve(h);
   

   return 0;
}

Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
# print(A)
# print(B)

sum_a = sum(A)
sum_b = sum(B)
need_n = sum_b - sum_a

need_an = 0
need_bn = 0
for i in range(N):
    if A[i] > B[i]:
        need_bn += A[i] - B[i]
    elif A[i] < B[i]:
        tmp = B[i] - A[i]
        need_an += tmp // 2

# print(need_n, need_an, need_bn)
if sum_a <= sum_b and need_an >= need_bn:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 10548
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
vector<string> vec;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W;
    cin >> H >> W;
    vec.resize(H);
    for (int i = 0; i < H; ++i) {
        cin >> vec[i];
    }

    for (int i = 0; i < H; ++i) {
        cout << vec[i] << endl;
        cout << vec[i] << endl;
    }
    return 0;
}

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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;

    int t = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == b[i]) {
            if (a[i] != c[i]) {
                t++;
            }
        } else if (a[i] == c[i]) {
            t++; 
        } else if (b[i] == c[i]) {
            t++;
        } else {
            t += 2;
        }
    }
    cout << t << endl;

}


Measured memory_bytes: 256
'use strict';

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = (input.trim()).split('\n');
lines.shift();
var hash = {};

lines.forEach(function(line) {
  var cmd = line.split(' ')[0];
  var key = line.split(' ')[1];
  if (cmd === 'insert') {
    hash[key] = true;
    return;
  }
  if (hash[key]) {
    console.log('yes');
  } else {
    console.log('no');
  }
});

Measured memory_bytes: 156300
n = int(input())
xs = [int(i) for i in input().split()]
for i in range(n):
    ind = i + 1
    ret = "node " + str(ind) + ": key = " + str(xs[ind - 1])
    if ind != 1:
        parent = ind // 2 - 1
        ret += ", parent key = " + str(xs[parent])
    if n > 2 * i + 1:
        ret += ", left key = " + str(xs[2 * i + 1])
    if n > 2 * i + 2:
        ret += ", right key = " + str(xs[2*i + 2])
    ret += ", "
    print(ret)

Measured memory_bytes: 7748
#include <iostream>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#define MAX_U   10
#define MIN_U   0
#define rep(i,n) for(int i=0;i<n;i++)
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a,b,c;
    cin >>a>>b>>c;
    printa("A",b[0],"C");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); i++)
using ll = long long;
using P = pair<int, int>;
int main()
{
    int a,b;
    cin >> a >> b;
    cout << a/b << " " << a%b << " ";
    cout << fixed << setprecision(6) << a / (double)b << endl;
    return 0;
}


Measured memory_bytes: 3268
from copy import copy
N = int(input())
S = input()

alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"

ans = copy(S)



for i in range(len(S)):
    ans = ans[:i] + alpha[alpha.index(S[i]) + N] + ans[i+1:]

print(ans)

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

#define F first
#define S second 
#define mp make_pair
#define pb push_back
#define pf push_front
#define speed_up ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define debug cerr << "OK\n";
#define ub upper_bound
#define lb lower_bound 
 
namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) {int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) {  for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0;}
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void gp (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::gp;
 
void scan() {
	return;
}
 
template<class T, typename... Args>
void scan(T &a, Args&&... args) {
	gi(a);
	scan(args...);
	return;
}

template<typename T>
void scann(T a, T b) {
	for (auto it = a; it != b; ++it)
		scan(*it);
}
 
template<typename T>
void scerr(T a, T b) {
	for (auto it = a; it != b; ++it)
		cerr << *it << " ";
	cerr << '\n';
}

void print() {
	pc('\n');
	return;
}
 
template<class T, typename... Args>
void print(T a, Args... args) {
	gp(a);
	pc(' ');
	print(args...);
	return;
}
 
void cer() {
	return;
}
 
template<class T, typename... Args>
void cer(T a, Args... args) {
	cerr << " " << a;
	cer(args...);
	return;
} 

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef set <int> si;
typedef set <ll> sll;
typedef multiset <int> msi;
typedef multiset <ll> msll;
typedef map <int, int> mi;
typedef map <ll, int> mll;
 
const int N = 2e5 + 2;
const int M = 1e6 + 2;
const int mod = 998244353;
const int inf = 2e9 + 3;
const ll INF = 1e16;

void data() {
	#ifdef PC
		freopen("b.in", "r", stdin);
		freopen("b.out", "w", stdout);
	#endif
}

int n, k;
string s;

int main() {
	data();
	cin >> k >> s;
	if (sz(s) <= k) {
		cout << s;
	}
	else {
		cout << s.substr(0, k) << "...";
	}
}	


Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(){

int H,W;
cin>>H>>W;

while(H!=0&&W!=0){
for(int i=0;i<W;i++){
	cout<<"#";
}
cout<<endl;
for(int n=1;n<H-1;n++){
	cout<<"#";
	for(int m=1;m<W-1;m++){
		cout<<".";
	}
	cout<<"#"<<endl;
}
for(int i=0;i<W;i++){
	cout<<"#";
}
    cout<<endl;
    cout<<endl;
	cin>>H>>W;
	
}

return 0;
}


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

#define MAX_V 100
const int INF = 1e7;
int V, M;
int d[MAX_V][MAX_V], f[MAX_V][MAX_V];

void init() {
  for (int i=0; i<MAX_V; i++)
    for (int j=0; j<MAX_V; j++)
      d[i][j] = INF;
}

void warshall_floyd() {
  for (int k=0; k<V; k++) {
    for (int i=0; i<V; i++) {
      for (int j=0; j<V; j++) {
        d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
      }
    }
  }
}

int main() {
  cin >> V >> M;
  int A, B, C, ans = 0;
  init();
  for (int i=0; i<M; i++) {
    cin >> A >> B >> C;
    A--;
    B--;
    d[A][B] = d[B][A] = f[A][B] = f[B][A] = C;
  }
  warshall_floyd();
  for (int i=0; i<V; i++)
    for (int j=i+1; j<V; j++)
      if (f[i][j] > d[i][j])
        ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
vector<ll> v(51), u(51);

ll solve(ll n, ll x){
    if(x <= n) return 0;
    if(n == 0 && x == 1) return 1;
    if(n == 0) return 0;
    ll ans = 0;
    if(v[n-1]+1 <= x) {
        ans += u[n-1];
        if(v[n-1]+2 <= x) ans++;
        if(2*v[n-1]+2 <= x) ans += u[n-1];
        else ans += solve(n-1, x-v[n-1]-2);
    }
    else ans += solve(n-1, x-1);

    return ans;
}

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

int main() {
    u[0] = 1;
    v[0] = 1;
    for (int i = 1; i <= 50; ++i) {
        v[i] = v[i-1]*2+3;
        u[i] = u[i-1]*2+1;
    }
    ll n, x;
    cin >> n >> x;
    cout << solve(n, x) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int n;
    string s;
    cin >> n >> s;
    int w = 0;
    rep(i, n) if (s[i] == '.') w++;
    int ans = w, b = 0;
    rep(i, n)
    {
        if (s[i] == '#')
            b++;
        else
            w--;
        ans = min(ans, b + w);
    }
    cout << ans << endl;
}


Measured memory_bytes: 720
N = input()
number_list = [int(i) for i in input().split()]
sorted_list = sorted(number_list)
count = 0
for i,j in zip(number_list, sorted_list):
    if i != j:
        count += 1

if count == 2 or count == 0:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


int main()
{
    int n; string s;
    cin >> n;
    cin >> s;
    cin >> s;
    vector<int> b;
    int len = 1;
    rep(i, s.size()-1){
        if (s[i] == s[i+1]){
            len++;
        } else {
            b.push_back(len);
            len=1;
        }
    }
    b.push_back(len);

    int before = b[0];
    ll ans = (b[0] == 1) ? 3 : 6;
    rep1(i, b.size()-1){
        if (b[i] == 2){
            if (before==1) ans*=2;
            else ans*=3;
        } else {
            if (before==1) ans*=2;
            else ans*=1;
        }
        before = b[i];
        ans %= MOD;
    }

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define mp make_pair
#define mpp(AA, BB, CC) mp( mp(BB, CC) , AA )
#define F first
#define S second

using namespace std;

int main()
{
    int n, a;
    vector < pair < pair < string, int > , int > > v;
    string s;
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
        cin >> s >> a;
        v.push_back( mp( mp(s, -a), i ) );
    }
    sort(v.begin(), v.end());
    for(int i = 0 ; i < v.size() ; i++){
        cout << v[i].S << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, d;
    cin >> n >> d;

    cout << (n + d * 2) / (d * 2 + 1) << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int n,ans=0;
    cin >> n;
    rep(i,4){
        if(n%10 == 2) ans++;
        n /= 10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

class UnionFind
{
public:
    vs32 p;

    UnionFind() {}
    UnionFind(int size)
    : p(vs32(size, -1))
    {}

    bool same(int x, int y)
    {
        return findSet(x) == findSet(y);
    }

    void unite(int x, int y)
    {
        x = findSet(x); y = findSet(y);
        if (x == y) return;

        if (p[x] > p[y]) swap(x, y);
        p[x] += p[y];
        p[y] = x;
    }

    int findSet(int x)
    {
        if (p[x] < 0) return x;
        else return p[x] = findSet(p[x]);
    }
};

s64 kruskal(vector< pair<s64, P> >& edge)
{
    int n = edge.size();
    UnionFind uf(n);
    sort(edge.begin(), edge.end());
    s64 ret = 0;
    rep (i, n)
    {
        int u, v;
        s64 c = edge[i].first;
        u = edge[i].second.first;
        v = edge[i].second.second;
        if (!uf.same(u, v))
        {
            ret += c;
            uf.unite(u, v);
        }
    }
    return ret;
}

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

    int n;
    cin >> n;

    vector< P > xi(n), yi(n);
    rep (i, n)
    {
        s64 x, y;
        cin >> x >> y;
        xi[i].first = x;
        xi[i].second = i;
        yi[i].first = y;
        yi[i].second = i;
    }

    sort(xi.begin(), xi.end());
    sort(yi.begin(), yi.end());

    vector< pair<s64, P> > edge;
    rep (i, n - 1)
    {
        edge.emplace_back(xi[i + 1].first - xi[i].first, P{xi[i].second, xi[i + 1].second});
        edge.emplace_back(yi[i + 1].first - yi[i].first, P{yi[i].second, yi[i + 1].second});
    }

    cout << kruskal(edge) << "\n";
    return 0;
}



Measured memory_bytes: 7792
#include <iostream>
#include <cstdio>
#include <vector>
#define N 10
using namespace std;

int main() {
    vector<int> A;
    for (int i=0; i<N; i++) {
        int x;
        cin >> x;
        A.push_back(x);
    }
    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            if (A[i]>A[j]) {
                int t=A[i];
                A[i]=A[j];
                A[j]=t;
            }
        }
    }
    for (int i=0; i<3; i++) {
        printf("%d\n",A[i]);
    }
    return 0;
}

Measured memory_bytes: 3288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 1001001001
#define V_MAX 1e3+10;
#define W_MAX 1e9+10
#define N_MAX 1e2+10
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int N;
  long long W;
  vector<int> w(N_MAX);
  vector<int> v(N_MAX);
  vector<vector<ll>> dp(N_MAX, vector<ll>(100010));

  ll res = 0;

  cin >> N >> W;
  rep(i,N){
    cin >> w.at(i) >> v.at(i);
  } 
  
  rep(i,N_MAX){
    rep(j,100010){
      dp.at(i).at(j) = INF;
    }
  } 
  dp.at(0).at(0) = 0;
  
  rep(i,N){
    rep(j,100010){
      if(v.at(i) <= j){
        dp.at(i+1).at(j) = min(dp.at(i).at(j-v.at(i)) + w.at(i), dp.at(i).at(j));
      }
      else{
        dp.at(i+1).at(j) = dp.at(i).at(j);
      }
    }
  }

  rep(i,100010){
    //cout << dp.at(N).at(i) << endl;
    if(dp.at(N).at(i) <= W){
      res = i;
    }
    //res = min(res, dp.at(N).at(i));
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 87296
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

ll nxt()
{
    ll x;
    cin >> x;
    return x;
}

const ll L = 1e5+5;

void solve()
{
    ll k;
    cin >> k;

    vector <ll> ans;

    for(ll i=1; i<10; i++)
    {
        ans.pb(i);
    }

    for(ll i=0; sz(ans) <= k; i++)
    {
        ll rem = ans[i]%10;
        ll p = 10*ans[i];

        if(rem != 0)
        {
            ans.pb(p + rem - 1);
        }
        
        ans.pb(p + rem);

        if(rem != 9)
        {
            ans.pb(p + rem + 1);
        }

    }

    cout << ans[k-1] << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 1400
use std::io::{self, BufWriter, Write};

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty), +) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn main() {
    let out = io::stdout();
    let mut out = BufWriter::new(out.lock());
    loop {
        from_line!(h: usize, w: usize);
        if h == 0 && w == 0 {
            break;
        }
        let is_odd = w % 2 != 0;
        let patterns = vec!["#.", ".#"];
        let ends = vec!["#", "."];
        for x in 0..h {
            let mut line = patterns[x % 2].repeat(w / 2);
            if is_odd {
                line += ends[x % 2];
            }
            line += "\n";
            out.write_all(&line.as_bytes()).unwrap();
        }
        out.write_all(b"\n").unwrap();
    }
}


Measured memory_bytes: 5036
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int n, m; scan(n, m);
    auto a = new int[n + 2];
    for (int i = 0; i < m; i++) {
        int l, r; scan(l, r);
        a[l]++;
        a[r + 1]--;
    }

    for (int i = 1; i < a.length; i++) {
        a[i] += a[i - 1];
    }

    auto ans = a.count!(e => e == m);
    writeln(ans);
}


Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(v) (v).begin(), (v).end()
const int M=1e6+7;


int main() {
    
 string s;
 cin>>s;
 int f=0;
 for(int i=0;i+1<s.size();i++)
 {
     if(s[i]==s[i+1])
        {
            f=1;
            break;
        }
 }
 cout<<(f?"Bad":"Good");
}



Measured memory_bytes: 256
N = int(input())

num = N % 10

if ((num==2)or(num==4)or(num==5)or(num==7)or(num==9)):
	print('hon')
elif ((num==0)or(num==1)or(num==6)or(num==8)):
	print('pon')
else:
    print('bon')

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define full(c) c.begin(), c.end()
typedef signed long long int ll;
typedef unsigned long long int ull;
using namespace std;

int main(){
  ll i,j,n,m,a[50],b[50],c[50],d[50];
  cin>>n>>m;
  for(i=0; i<n; i++) cin>>a[i],cin>>b[i];
  for(i=0; i<m; i++) cin>>c[i],cin>>d[i];
  for(i=0; i<n; i++){
    ll mi,mx=1000000001;
    for(j=0; j<m; j++){
      ll md=abs(a[i]-c[j])+abs(b[i]-d[j]);
      if(md<mx) mi=j+1,mx=md;
    }
    cout<<mi<<endl;
  }
  return 0;
}

Measured memory_bytes: 256