akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){

    double x1, y1, x2, y2, m;
    
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    
    m = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
    
    printf("%.8f\n", m);
    
    return 0;
    
}



Measured memory_bytes: 2056
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

int Q, N, logn, r, l, turn;

int main(){
	cin >> Q;
	for (int i = 0; i < Q; i++){
		cin >> N;
		if (N == 0) logn = 1;
		else logn = int(log10(N)) + 1; //N????????°?????????
		if (logn == 1) cout << 0 << endl;
		else{
			turn = 0;
			while (logn != 1){
				int max = 0;
				for (int j = 0; j < logn - 1; j++){
					r = N % int(pow(10, j + 1)+0.1);
					l = N / int(pow(10, j + 1) + 0.1);
					if (max < r*l){
						max = r*l;
					}
				}
				N = max;
				if (N == 0) logn = 1;
				else logn = int(log10(N)) + 1; //N????????°?????????
				turn++;
			}
			cout << turn << endl;
		}
	}
	return 0;
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  
  int plan1 = a * n;
  int plan2 = b;
  
  int rst = (plan1 < plan2)
    ? plan1
    : plan2;
  
  cout << rst << endl;
}

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

public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
           int q = Integer.parseInt(reader.readLine());
           int[] S = new int[q];
           int j = 0;
           for(int i = 0; i < q; i++){
               String l =reader.readLine();
               String[] str = l.split(" ");
               if(str[0].equals("0")){
                    S[j] = Integer.parseInt(str[1]);
                    j++;
               }else if(str[0].equals("1")){
                   int t = Integer.parseInt(str[1]);
                    System.out.println(S[t]);
               }else{
                   j--;
               }
           } 
        }catch(IOException e){

        }
    }
}


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

using namespace std;

vector<long long> buf;

void appl(vector<long long> perm, vector<long long> &v) {
    for (long long i = 0; i < perm.size(); ++i) {
        buf[i] = v[perm[i]];
    }
    v = buf;
}

int main()
{
    long long n;
    long long m;
    unsigned long long k;
    cin >> n;
    vector<long long> x(n);
    for (long long i = 0; i < n; ++i)
        cin >> x[i];
    cin >> m >> k;
    vector<long long> pos(m);
    for (long long i = 0; i < m; ++i) {
        cin >> pos[i];
        --pos[i];
    }
    vector<long long> dff(n - 1);
    for (long long i = 0; i < n - 1; ++i) {
        dff[i] = x[i + 1] - x[i];
    }
    vector<long long> perm(n - 1);
    for (long long i = 0; i < n - 1; ++i)
        perm[i] = i;
    buf.resize(n - 1);
    for (long long i = 0; i < m; ++i) {
        swap(perm[pos[i] - 1], perm[pos[i]]);
    }
    for (unsigned long long i = 0; i < 64; ++i) {
        if (k & (1ull << i))
            appl(perm, dff);
        appl(perm, perm);
    }
    long long sum = 0;
    cout << x[0] << endl;
    sum = x[0];
    for (long long i = 0; i < n - 1; ++i) {
        sum += dff[i];
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 6000
// 5/28
// 過去問ガリガリ
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int main() {
    ll A, B;
    cin >> A >> B;

    ll ans = A * B;

    while (B) {
        A %= B;
        swap(A, B);
    }

    cout << ans / A << endl;
}


Measured memory_bytes: 256
// スタックサイズ: 100MB

#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1e18;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }



int main() {
	fastio;

	ll a, b;
	cin >> a >> b;
	cout << max((ll)0, a - b) << endl;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

const int mod = 1000000007;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x(x % mod) {}

    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 {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator*(const mint a) const {
        mint res(*this);
        return res *= 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 {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        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];
    }
} comb(100005);

mint f(int n, int k) {
    if (n < 0) return 0;
    // nPk = nCk * k!
    mint res = comb(n, k);
    res *= comb.fact[k];
    return res;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<ll> x(N), y(M);
    rep(i, N) cin >> x[i];
    rep(i, M) cin >> y[i];

    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    vector<mint> dpx(N); // i => i-1,i-2,...0地点までの距離の総和
    for (int i = 1; i < N; i++) dpx[i] = dpx[i - 1] + mint(x[i] - x[i - 1]) * i;
    vector<mint> dpy(M);
    for (int i = 1; i < M; i++) dpy[i] = dpy[i - 1] + mint(y[i] - y[i - 1]) * i;

    mint sumX = 0; // x方向の距離の総和
    rep(i, N) sumX += dpx[i];
    mint sumY = 0;
    rep(i, M) sumY += dpy[i];

    cout << (sumX * sumY).x << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
int main() {
  int N;
  cin >> N;
  vector<int> T(N), A(N);
  for (int i = 0; i < (int)N; ++i) cin >> T[i] >> A[i];
 
  ll t = T[0], a = A[0];
  for (int i = 1; i < N; ++i) {
    ll kt = (t + T[i] - 1) / T[i], ka = (a + A[i] - 1) / A[i];
    if (kt * A[i] < a) {
      t = T[i] * ka;
      a = A[i] * ka;
      continue;
    }
    if (ka * T[i] < t) {
      t = T[i] * kt;
      a = A[i] * kt;
      continue;
    }
    t = T[i] * min(ka, kt);
    a = A[i] * min(ka, kt);
  }
 
  cout << t + a << endl;
 
  return 0;
}

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

int main()
{
	char c;
	cin >> c;
	if(islower(c)){
		cout << 'a' << endl;
	} else {

		cout << 'A' << endl;
	}
}


Measured memory_bytes: 3524
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int N = sc.nextInt();
    int A[] = new int[N+1];
    for(int i = 0; i<N; i++){
      A[i]=sc.nextInt();
    }
    int ans = 0;
    A[N]=A[0]+K;
    for(int i = 0; i<N; i++){
      ans=Math.max(ans, A[i+1]-A[i]);
    }
    System.out.println(K-ans);
  }
}    

Measured memory_bytes: 60064
package main

import "fmt"

func main()  {
  var s string
  fmt.Scan(&s)
  list := map[string]int{
    "A" : 0,
    "C" : 1,
    "G" : 2,
    "T" : 3,
  }
  max := 0
  for i := range s {
    count :=0
    for  j := i; j<len(s) ;j++ {
      if _, ok :=list[string(s[j])] ; ok {
        count++
        }else{
          i=j+1
          break
        }
      }
      if max < count {
        max=count
      }
    }
    fmt.Println(max)
  }


Measured memory_bytes: 512
fn main() {
    let num: i32 = read();
    if num == 2 {
        println!("{}", num);
        return;
    }

    let mut prime = vec![2];

    let mut i = 1;
    'outer: loop {
        i += 2;
        for n in prime.iter() {
            if i % n == 0 {
                continue 'outer;
            }
        }

        prime.push(i);

        if num <= *prime.last().unwrap() {
            break;
        }
    }

    println!("{}", i)
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 4352
def main():
    N = int(input())
    C = list(input())

    l=0
    r=N-1
    ans = 0
    while l < r:
        while l < N and C[l] == 'R':
            l += 1
        while r >= 0 and C[r] == 'W':
            r -= 1
        
        if l < r:
            C[l] = 'R'
            C[r] = 'W'
            ans += 1
        # print(C, l, r)
        # return
    
    print(ans)

if __name__ == '__main__':
    main()

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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    cout << n - k + 1 << ln;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int SumOfDisit(int n){
  int sum;
  while(n>0){
    sum+=n%10;
    n/=10;
  } 
  return sum;
}
int main(){
int N;
cin>>N;
if(N%SumOfDisit(N)==0){
  cout<<"Yes";
} 
else {
cout<<"No";}
}


Measured memory_bytes: 256
import sys
n = int(sys.stdin.readline().rstrip("\n"))
l = [int(s) for s in sys.stdin.readline().rstrip("\n").split()]
l.sort()
ans = 0
for a in range(n):
    for b in range(a+1,n):
        for c in range(b+1,n):
            if l[a] != l[b] and l[b] != l[c] and l[c] != l[a]:
                if l[a]+l[b] > l[c]:
                    ans += 1
print(ans)

Measured memory_bytes: 9196
#include<cstdio>
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long
int cnt[100005];
int book[100005];
ll son[100005];
const ll mod=1000000007;
ll n,k;
vector <int> e[100005];
int main()
{
    scanf("%lld %lld",&n,&k);
    for(int i=1;i<=n-1;i++)
    {
        int u,v;
        scanf("%d %d",&u,&v);
        cnt[u]++;
        cnt[v]++;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    int p=n;
    while(p>1)
    {
        for(int i=1;i<=n;i++)
        {
            if(cnt[i]==1)
            {
                book[i]=1;
                cnt[i]--;
                p--;
                for(int j=0;j<e[i].size();j++)
                {
                    if(book[e[i][j]]==0)
                    {
                        son[e[i][j]]++;
                        cnt[e[i][j]]--;
                        break;
                    }
                }
            }
        }
    }
    int flag;
    for(int i=1;i<=n;i++)if(book[i]==0)
    {
        flag=i;
        break;
    }

    ll ans=k;
    while(son[flag]--)ans=(ans*(k-son[flag]-1))%mod;
    son[flag]=0;
    for(int i=1;i<=n;i++)
    {
        if(son[i]==0)continue;
        if(k<=son[i]+1)
        {
            printf("0");
            return 0;
        }
        while(son[i]--)ans=(ans*(k-son[i]-2))%mod;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 10268
n=int(input())
a=list(map(int,input().split()))
even=0
count=0

for i in range(n):
  if a[i]%2==0:
    even+=1
    if a[i]%3==0 or a[i]%5==0:
      count+=1

if even==count:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{

  int Max=0,X=0,Y=0,Z=0;
  
  scanf("%d",&X);
  
  Max=X/500;
  Max=Max*1000;
  
  Y=(X%500)/5;
  Y=Y*5;
  
  Max=Max+Y;
  
  printf("%d",Max);
  
  return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    MOD = 10 ** 9 + 7
    S = int(rl())
    
    dp = [[0] * (S + 1) for _ in range(S + 1)]
    dp[0][0] = 1
    
    for i in range(S):
        for j in range(2, S):
            dp[i + 1][j + 1] = (dp[i + 1][j] + dp[i][j - 2]) % MOD
    
    ans = 0
    for i in range(1, (S // 3) + 1):
        ans += dp[i][S]
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 99928
n,m = [int(x) for x in input().split()]


if n == m == 1:
    print(1)
elif n == 1 or m == 1:
    print(max(n,m) - 2)
elif n == 2 or m == 2:
    print(0)
else:
    print((n*m) - (n * 2 + m * 2 - 4))

Measured memory_bytes: 3060
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
typedef pair<ll,ll> P;
int main(void){
    string S;cin>>S;
    ll N=S.size();
    //ランレングス圧縮
    vector<P> v;
    for(ll i=0,n1=0,n2=0;i<N;n1=n2=0){
        while(S[i]=='R')n1++,i++;
        while(S[i]=='L')n2++,i++;
        v.push_back(make_pair(n1,n2));
    }
    /*//結果の確認
    for(auto r:v){
        cout<<'R'<<r.first<<'L'<<r.second;
    }cout<<"\n";*/

    ll ans[N];REP(i,N)ans[i]=0;
    ll n=0;
    for(auto r:v){
        ll len=r.first+r.second;
        ll idxR=n+r.first-1,idxL=idxR+1;
        if(len%2==0){//文字数が偶数
            ans[idxR]=ans[idxL]=len/2;
        }
        else if(len%2==1){//文字数が奇数
            if(r.first>r.second&&r.second%2==1){//lの長さ>rの長さ=1
                ans[idxR]=(len-1)/2,ans[idxL]=(len+1)/2;
            }else if(r.first%2==1&&r.first<r.second){//lの長さ=1<rの長さ
                ans[idxR]=(len+1)/2,ans[idxL]=(len-1)/2;
            }
            else if(r.first<r.second){//lの長さ<rの長さ
                ans[idxR]=(len-1)/2,ans[idxL]=(len+1)/2;
            }else if(r.first>r.second){//lの長さ>rの長さ
                ans[idxR]=(len+1)/2,ans[idxL]=(len-1)/2;
            }
        }
        n+=len;
    }
    REP(i,N){
        cout<<ans[i]<<" ";
    }cout<<"\n";
}


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

typedef long long ll;

ll I = 1;
const ll P = 31;
const int N = 1000005;
const int MOD = 1e9 + 7;
int n;
char sub[N];
ll pwr[N], inv[N], h[N], subH[N];
string s;
ll bigMod (ll a, int e){
  if (e == -1) 
    e = MOD - 2;
  ll r = 1;
  while (e) {
      if (e & 1) r = (r * a) % MOD;
      a = (a * a) % MOD, e >>= 1;
  }
  return r;
}

ll getHash (int l, int r) 
{
    ll ret = ((h[r] - h[l - 1]) * inv[l - 1]) % MOD;
    if (ret < 0) ret += MOD;
    return ret;
}
bool ok(int len)
{
    map<ll, int> st;
    //cout << len << ": ";
    for(int i=len;i<=n;i++){
        ll c = getHash(i-len+1,i);
       // cout << c << ", ";
        if(st.count(c)==0) st[c]=i;
        else if(st[c]<i-len+1) return 1;
    }
    //cout << "\n";
    return 0;
}
int main()
{
    pwr[0] = inv[0] = 1;
    I = bigMod(P, -1);
    for (int i = 1; i < N; ++i) 
    {
        pwr[i] = (pwr[i - 1] * P) % MOD;
        inv[i] = (inv[i - 1] * I) % MOD; 
    }
    cin>>n;
    cin>>s;
    //n = s.size();
    s = "$"+s;
    //cal hash of string
    for (int i = 1; i <= n; ++i)
        h[i] = (h[i - 1] + (s[i] - 'a' + 1) * pwr[i - 1]) % MOD;
    
    int lo = 1, hi = n, ans = 0;
    while(lo<=hi){
            int mid = (lo+hi)>>1;
        if(ok(mid)) ans=mid,lo=mid+1;
        else hi=mid-1;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 19584
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)N; i++)

const int VISITED = 1,
  CURRENTLY_VISITED = 2;

int V, E;
bool findCycle(int node);

vector<vector<int>> adjacentList;
vector<int> states;

bool hasCycle() {
  vector<int> states(V,0);
  for(int i = 0; i < V; i++) {
    if(states[i] != VISITED && findCycle(i)) {
      return true;
    }
  }
  return false;
}

bool findCycle(int node) {
  if(states[node] == CURRENTLY_VISITED) return true;
  states[node] = CURRENTLY_VISITED;
  for(int nn: adjacentList[node]) {
    if(states[nn] != VISITED && findCycle(nn))return true;
  }
  states[node] = VISITED;
  return false;
}

int main () {
  cin >> V >> E;
  adjacentList = vector<vector<int>>(V);
  states = vector<int>(V, 0);

  for(int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    adjacentList[s].push_back(t);
  }

  cout << (hasCycle() ? 1 : 0) << endl;
  return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    ll h;
    ll sum=0LL;
    ll count=1LL;
    cin>>h;

    while(h>0){
        h=h/2;
        sum+=count;
        count=count*2;
    }
    cout<<sum;
    return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A,B,C;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B>>C;
	cout<<max({A,B,C})-min({A,B,C})<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

signed main(){
  int V, E; cin >> V >> E;
  vector<vector<int> > dist(V, vector<int> (V, INF));
  for(int i = 0; i < E; i++){
    int s, t, d; cin >> s >> t >> d;
    dist[s][t] = d;
 }  
 vector<vector<int> > dp(V, vector<int> (1 << V, INF));
 dp[0][0] = 0;
 for(int i = 0; i < (1 << V); i++){
   for(int j = 0; j < V; j++){
     if(!(i & (1 << j))){
       for(int k = 0; k < V; k++){
         dp[j][i + (1 << j)] = min(dp[j][i + (1 << j)], dp[k][i] + dist[k][j]);
       }
     }
   }
 }
 int ans = dp[0][(1 << V) - 1];
 if(ans == INF) cout << -1 << endl;
 else cout << ans << endl;
}


Measured memory_bytes: 5000
#include <iostream>
#include <string>
using namespace std;
  
class Dice{
private:
    int d[6];
public:
    Dice(int n0, int n1, int n2, int n3, int n4, int n5){ //Constructor
        d[0]=n0; d[1]=n1; d[2]=n2; d[3]=n3; d[4]=n4; d[5]=n5;
    }
    int get_top(){
        return d[0];
    }
    int get_front(){
        return d[1];
    }
    int get_right(){
        return d[2];
    }
    int get_left(){
        return d[3];
    }
    int get_back(){
        return d[4];
    }
    int get_bottom(){
        return d[5];
    }
    void Roll(string op){
        for(unsigned int i=0;i<op.length();i++){
            switch(op[i]){
                case 'N': RollN(); break;
                case 'E': RollE(); break;
                case 'W': RollW(); break;
                case 'S': RollS(); break;
            }
        }
    }
    void RollN(){
        int tmp=d[0];
        d[0]=d[1];
        d[1]=d[5];
        d[5]=d[4];
        d[4]=tmp;
    }
    void RollE(){
        int tmp=d[0];
        d[0]=d[3];
        d[3]=d[5];
        d[5]=d[2];
        d[2]=tmp;
    }
    void RollW(){
        int tmp=d[0];
        d[0]=d[2];
        d[2]=d[5];
        d[5]=d[3];
        d[3]=tmp;
    }
    void RollS(){
        int tmp=d[0];
        d[0]=d[4];
        d[4]=d[5];
        d[5]=d[1];
        d[1]=tmp;
    }
    bool operator==(const Dice& t)const{
    	return(d[0]==t.d[0] && d[1]==t.d[1] && d[2]==t.d[2] && 
    	d[3]==t.d[3] && d[4]==t.d[4] && d[5]==t.d[5]);
    }
    bool operator!=(const Dice& t)const{
    	return !(*this==t);
    }
};
  
int main(){
    int a, b, c, d, e, f, n;
    cin >> n >> a >> b >> c >> d >> e >> f;
    Dice di(a, b, c, d, e, f);
    bool dif=true;
    for (int i=0;i<n-1;i++){
    cin >> a >> b >> c >> d >> e >> f;
        Dice di2(a, b, c, d, e, f);
        for(int j=0;j<4;j++){
            bool flg = false;
            di.RollE();
            for(int k=0;k<4;k++){
                di.RollN();
                for(int l=0;l<4;l++){
                    di.RollE();
                    if(di==di2) dif=false;
                    }
                }
                if(di==di2) dif=false;
            }
            if(di==di2) dif=false;
        }
    if(dif) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3092
/*
*/

//#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>т мом
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds
#define ends asdgahhfdsfshdshfd

#define eps 1e-8
#define M_PI 3.141592653589793
#define bsize 512

#define ldouble long double
using namespace std;

#define bs 1000000007

const int N = 400031;

struct pt{
	double x;
	double y;
};

int n;
pt p[N];


long double get_dist(long double x1,long double y1,long double x2,long double y2){
	return (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
}

int get_best(long double ang){
	long double X=1e12*cosl(ang);
	long double Y=1e12*sinl(ang);
	int id=1;
	for (int i=2;i<=n;i++){
		if (get_dist(X,Y,p[i].x,p[i].y)<get_dist(X,Y,p[id].x,p[id].y))
			id=i;
	}
	return id;
}

double ans[10235];

int MAG = 750000;

int main(){
//	freopen("apache.in","r",stdin);
//	freopen("apache.out","w",stdout);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
//	cin.tie(0);

	cin>>n;
	//n=100;
	for (int i=1;i<=n;i++){
		cin>>p[i].x>>p[i].y;
		//p[i].x+=1e6;
		//p[i].y+=1e6;
		//=p[i].y=i;
	}

	for (double t=0;t<2*M_PI;t+=2*M_PI/MAG){
		int id=get_best(t);
		ans[id]+=1.0/MAG;
	}
	for (int i=1;i<=n;i++){
		cout.precision(12);
		cout<<fixed<<ans[i]<<endl;
	}
/*	for (int i=1;i<=n;i++){
		double ang_here=atan2(p[i].y,p[i].x);
		double l,r;
		l=0;
		cout.precision(12);
		if (get_best(ang_here)!=i)
		{
			cout<<fixed<<0.0<<endl;
			continue;
		}
		l=0;
		r=M_PI/2;
		for (int iter=1;iter<=70;iter++){
			double mid=l+r;
			mid/=2;
			if (get_best(ang_here+mid)==i)
				l=mid;
			else
				r=mid;
		}
		cout<<fixed<<l/M_PI<<endl;
	}*/

//	cin.get(); cin.get();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

#define INF 1000000000

typedef pair<int, int> P;
typedef pair<P, int> Q;

int main() {
	int w, h;
	while (cin >> w >> h) {
		if (w == 0 && h == 0) {
			break;
		}
		vector< vector<int> > s(h, vector<int>(w));
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> s[i][j];
			}
		}
		int cc[4];
		for (int i = 0; i < 4; i++) {
			cin >> cc[i];
		}
		vector< vector< vector<long long int> > > dp(h, vector< vector<long long int> >(w, vector<long long int>(4, INF)));
		dp[0][0][0] = 0;
		int dx[] = { 1, 0, -1, 0 };
		int dy[] = { 0, 1, 0, -1 };
		bool hh = true;
		while (hh) {
			hh = false;
			vector< vector< vector<long long int> > > dp2;
			dp2 = dp;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					for (int k = 0; k < 4; k++) {
						for (int kk = 0; kk < 4; kk++) {
							//cout << i << ' ' << j << ' ' << k << ' ' << kk << endl;
							int mm = (k + kk) % 4;
							int cost = cc[kk];
							if (s[i][j] == kk) {
								cost = 0;
							}
							if (0 <= j+dx[mm] && j+dx[mm] < w && 0 <= i+dy[mm] && i+dy[mm] < h && dp2[i+dy[mm]][j+dx[mm]][mm] > dp[i][j][k]+cost) {
								hh = true;
								dp2[i + dy[mm]][j + dx[mm]][mm] = dp[i][j][k] + cost;
								//cout << i + dy[mm] << ' ' << j + dx[mm] << ' ' << dp2[i + dy[mm]][j + dx[mm]][mm] << endl;

							}
						}
					}
				}
			}
			dp = dp2;
		}
		cout << min(dp[h - 1][w - 1][0], min(dp[h - 1][w - 1][1], min(dp[h - 1][w - 1][2], dp[h - 1][w - 1][3]))) << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  vector<int> A(9, 0), B(9, 0);
  bool flg = false;
  for(int i = 0; i < 9; i++) cin >> A[i];
  int N; cin >> N;
  for(int i = 0; i < N; i++) {
    int b; cin >> b;
    for(int j = 0; j < 9; j++) {
      if(A[j] == b) B[j] = 1;
    }
  }
  for(int i = 0; i < 3; i++) {
    if(B[i * 3] == 1 && B[i * 3 + 1] == 1 && B[i * 3 + 2] == 1) flg = true;
    if(B[i] == 1 && B[i + 3] == 1 && B[i + 6] == 1) flg = true;
  }
  if(B[0] == 1 && B[4] == 1 && B[8] == 1 || B[2] == 1 && B[4] == 1 && B[6] == 1) flg = true;
  if(flg) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

#define pb push_back
#define mp make_pair


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

    ll t,m;
    string s,s1,s2;
    cin>>s;
    ll n=s.size();
    s1=s.substr(0,(n-1)/2);
    s2=s.substr((n+3)/2-1,n-1);
    //cout<<s1<<" "<<s2<<" ";
    string k=s,k1=s1,k2=s2;
    reverse(k.begin(),k.end());
    reverse(k1.begin(),k1.end());
    reverse(k2.begin(),k2.end());
    if(k==s && k1==s1 && k2==s2)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}




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

int n;
vector<vector<int>> g;
vector<int> color;
vector<int> parts;
vector<pair<int, int>> ps;

bool dfs(int u, int c) {
    color[u] = c;
    parts[c]++;
    for (int v: g[u]) {
        if (~color[v]) {
            if (color[v] == color[u]) return false;
        } else {
            if (!dfs(v, c ^ 1)) return false;
        }
    }
    return true;
}

bool is_bipartite() {
    color.assign(n, -1);
    parts.assign(2, 0);
    for (int u = 0; u < n; u++) if (color[u] == -1) {
        if (!dfs(u, 0)) return false;
        ps.emplace_back(parts[0], parts[1]);
        parts.assign(2, 0);
    }
    return true;
}

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int m; cin >> n >> m;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--; b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    if (!is_bipartite()) return !(cout << -1 << endl);
    map<int, int> diff;
    for (auto &p: ps) diff[abs(p.first - p.second)]++;
    bitset<(int)2e5 + 1> dp; dp.set(n);
    vector<int> ds;
    for (auto &p: diff) {
        int u = 1;
        while (p.second >= u) {
            ds.emplace_back(p.first * u);
            p.second -= u, u <<= 1;
        }
        if (p.second) ds.emplace_back(p.first * p.second);
    }
    for (auto d: ds) dp = dp << d | dp >> d;
    long long ma = 0;
    for (int d = 0; d <= n; d++) if (dp[d + n]) {
        int t = (n - d) / 2;
        ma = max(ma, 1LL * t * (t + d));
    }
    cout << ma - m << endl;
    return 0;
}



Measured memory_bytes: 9416
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n;i>=0;i--)
#define MAX 10001
#define ll long long
#define dmp make_pair
#define dpb push_back
#define P pair<int,int>
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);
const int inf = 1e9;
const ll INF = 1e18;
#define B 100

int a[MAX], dp[2][MAX][2];
int main(){
	int n, t1, t2;
	scanf("%d", &n);
	rep(i,2)rep(j,MAX)rep(k,2)dp[i][j][k] = inf;
	for(int i = 2;i <= n;i++)scanf("%d", &a[i]);
	dp[0][0][0] = dp[0][0][1] = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			dp[i%2][j][0] = min(dp[(i-1)%2][j-1][0], dp[(i-1)%2][j-1][1]+a[i]);
			dp[i%2][j][1] = min(dp[(i-1)%2][j][1], dp[(i-1)%2][j][0]+a[i]);
		}
		rep(j,n)rep(k,2)dp[(i-1)%2][j][k] = inf;
	}
	/*for(int i = 0;i <= n;i++){
		for(int j = 0;j <= n;j++)printf("%d ", dp[i][j][1]);
		printf("\n");
	}*/
	printf("%d\n", min(dp[n%2][n/2][0], dp[n%2][n/2][1]));
	return 0;
}

Measured memory_bytes: 3412
while orig = gets
  orig = orig.chomp.split("")

  while true
    orig.length.times do |i|
      unless orig[i] == " " || orig[i] == "."
        orig[i] = (orig[i].ord + 1).chr
        if orig[i].ord > 122 # z.ord == 122
          orig[i] = (orig[i].ord - 26).chr
        end
      end
    end
    break if orig.join =~ /the|this|that/
  end
  puts orig.join
end

Measured memory_bytes: 8708
////#include <bits/stdc++.h>
//#include <iostream>
//#include <algorithm>
//using namespace std;
//
//long long n,ans;
//int main() {
//    while(cin >> n) {
////          cout << __gcd(n,(long long)2) << endl;
//        if(__gcd((long long)2,n) == 1)
//            cout << (long long)2 * n << endl;
//        else {
//            cout << n << endl;
//
//        }
//    }
//    return 0;
//}
//#include <bits/stdc++.h>
//#include <iostream>
//#include <algorithm>
//using namespace std;
//
////long long n,ans;
//int n,x;
//int main() {
//    while(cin >> n) {
//            int Max = -99;
//            int Min = 2e9;
//            for(int i = 0;i < n;i++){
//                    cin >> x;
//                 Max = max(x,Max);
//                 Min = min(x,Min);
//            }
//            cout << Max - Min << endl;
//    }
//    return 0;
//}




#include <iostream>
#include <stdio.h>
#include <map>
#include <algorithm>
using namespace std;
const int Maxn = 2e5 + 100;
int n,x;
int a[Maxn];
map<int,int>m;
int main() {
    while(cin >> n) {
        m.clear();
        for(int i = 0; i < n; i++)
            cin >> a[i];
        long long  ans = 0;
        int b = 0;
        int q = 1;
        for(int i = 0; i < n; i++) {
            a[i] -= q++;
            m[a[i]]++;
        }
        sort(a,a + n);
        int cnt = 0;
        for(int i = 0; i < n; i++) {
            if(a[i] == 0) continue;
            if(m[a[i]] && m[-a[i]])
                cnt++,m[a[i]]--,m[-a[i]]--;
        }
        int Max = 0;
        int data;
        if(cnt == n) b = 0;
        else {
            b = a[n / 2];
//            for(map<int,int>::iterator it = m.begin(); it != m.end(); it++)  {
////                if(it -> first == 0) continue;
//                if(Max < it -> second) {
//                    Max = it -> second;
//                    data = it -> first;
//                }
            }
//            b = data;
//        }
//        cout << b <<endl;
        for(int i = 0; i < n; i++) {
            ans += abs(a[i] - b);
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main(void)
{
	long long n;
	cin >> n;
	long long orig_n = n;
	map<long long, int> z;
	for (long long i = 2; i*i <= n; i++) {
		while (n % i == 0) {
			z[i]++;
			n/=i;
		}
	}
	if (n != 1)
		z[n] = 1;
	/*
	for (const auto p : z) {
		cout << p.first << " " << p.second << endl;
	}
	*/
	
	int i = 1;
	int count = 0;
	bool found = false;
	while (true) {
		found = false;
		for (auto& p : z) {
			if (p.second >= i) {
				p.second-=i;
				count++;
				found = true;
			}
		}
		if (!found)
			break;
		i++;
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3140
import itertools
n=int(input())

keta=len(str(n))
hako=[]
for i in range(3,keta+1):
    for c in list(itertools.product(["7","5","3"],repeat=i)):
        if len(set(c))==3:
            a=int("".join(c))
            hako.append(a)
if n in hako:
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(len(b)+1) 
else:
    hako.append(n)
    hako.sort()
    k=hako.index(n)
    b=hako[:k]
    print(int(len(b)))

Measured memory_bytes: 7284
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}



signed main(){
  int n;
  char a;
  bool h=false;
  cin >> n;
  FOR(i,n){
    cin >> a;
    if(a=='Y') h=true;
  }
  if(h) cout <<"Four\n";
  else cout <<"Three\n";
  
  return 0;
}



struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;



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

int main(){
	string s;
	int a = 0;
	cin >> s;
	for(int i = 0;s.at(i) != 'A';i++){
		a++;
	}
	for(int i = s.size()-1;s.at(i) != 'Z';i--){
		a++;
	}
	cout << s.size() - a << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int n,i,j;
  int data[3];
  scanf("%d",&n); 
  for(i=0;i<n;i++){
    scanf("%d %d %d",&data[0],&data[1],&data[2]);
    for(j=0;j<2;j++){
      if(data[j]>data[j+1]){
	int temp;
	temp=data[j];
	data[j]=data[j+1];
	data[j+1]=temp;
      }
    }
    if(data[0]*data[0]+data[1]*data[1]==data[2]*data[2]){
      printf("YES\n");
    } else{
      printf("NO\n");
    }
  }
  return(0);
}

Measured memory_bytes: 1008
#include <iostream>

using namespace std;

int main()
{
    int A,B;
    cin>>A>>B;
    int m;
    int x=A+B; int y=A-B;int z=A*B;
    if (x>=y&&x>=z)
        cout<<x;
    else if(y>=x&&y>=z)
        cout<<y;

    else if (z>=y&&z>=x)
        cout<<z;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	string s,k;
	char t;
	int l,i,p;
	cin>>s>>k;
	l=s.length();
	if(s==k)
		{
				cout<<"Yes";
				return 0;			
		}
		
	for(i=0;i<l-1;i++)
		{
			t=s[0];		
			for(p=0;p<l;p++)			
				s[p]=s[p+1];
			s[l-1]=t;
			if(s==k)
			{
				cout<<"Yes";
				return 0;
			}	
	}
		
	cout<<"No";	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
const int MAX=2e5;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int N; cin >> N;
  vector<int> a(N);
  vector<int> b(N);
  vector<int> c(N);
  rep(i,N) cin >> a[i];
  rep(i,N) cin >> b[i];
  rep(i,N) cin >> c[i];
  sort(all(a));
  sort(all(b));
  sort(all(c));
  ll ans=0;
  rep(i,N){
    ll la=-1,ra=N;
    while(ra-la!=1){
      ll mida=(la+ra)/2;
      if(a[mida]<b[i]) la=mida;
      else ra=mida;
    }
    ll lc=-1,rc=N;
    while(rc-lc!=1){
      ll midc=(lc+rc)/2;
      if(c[midc]<=b[i]) lc=midc;
      else rc=midc;
    }
    ans+=ra*(N-rc);
  }
  cout << ans << endl;
}

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

using namespace std;

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n, -1) {}

  void init(int n) { par.assign(n, -1); }

  int root(int x) {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }

  bool issame(int x, int y) { return root(x) == root(y); }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x) { return -par[root(x)]; }
};

int main() {
  int N;
  cin >> N;
  vector<long long> x(N), y(N);
  for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

  using pint = pair<int, int>;
  using Edge = pair<long long, pint>;
  vector<Edge> edges;

  vector<int> ids(N);
  iota(ids.begin(), ids.end(), 0);
  sort(ids.begin(), ids.end(), [&](int i, int j) { return x[i] < x[j]; });

  for (int i = 0; i + 1 < ids.size(); i++) {
    int u = ids[i], v = ids[i + 1];
    edges.push_back(Edge(x[v] - x[u], pint(u, v)));
  }

  sort(ids.begin(), ids.end(), [&](int i, int j) { return y[i] < y[j]; });

  for (int i = 0; i + 1 < ids.size(); i++) {
    int u = ids[i], v = ids[i + 1];
    edges.push_back(Edge(y[v] - y[u], pint(u, v)));
  }

  sort(edges.begin(), edges.end());

  UnionFind uf(N);

  long long res = 0;
  for (auto e : edges) {
    int u = e.second.first, v = e.second.second;
    long long cost = e.first;
    if (uf.issame(u, v)) continue;
    uf.merge(u, v);
    res += cost;
  }

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 8432
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)

void sort2vectors(vector<ll> &av, vector<ll> &bv)
{
        int n = av.size();
        vector<ll> p(n), av2(n), bv2(n);
        iota(p.begin(), p.end(), 0);
        sort(p.begin(), p.end(), [&](ll a, ll b) { return av[a] < av[b]; });
        for (int i = 0; i < n; i++) {
                av2[i] = av[p[i]];
                bv2[i] = bv[p[i]];
        }
        av = av2;
        bv = bv2;
}

int main() {

  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  REP(i, N) cin >> A[i] >> B[i];

  sort2vectors(B, A);

  //REP(i, N) cout << A[i] << B[i] <<endl;
  ll cul = 0;
  ll time = 0;
  REP(i, N){
    cul += A[i];
    if (cul > B[i]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 8064
#include <iostream>
using namespace std;
int main(void){
 	int N = 0;
  	int K = 0;
  	cin >> N >> K;
  	
  	int i = 0;
  	for(;;++i) {
  	    N = N / K;
  	    if (N == 0) {
  	        break;
  	    }
  	}
  	
  	cout << i + 1 << endl;
  	
  	return 0;   
}


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

int main(){
  int time;
  scanf("%d",&time);
  int h,m,s;
  h = time/3600;
  m = (time - h*3600)/60;
  s = time - h*3600 - m*60;
  printf("%d:%d:%d\n",h,m,s);
  return 0;
}



Measured memory_bytes: 2056
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1159

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
  int n, p;
  while (scanf("%d%d", &n, &p) != EOF && n && p) {
    int a[50];
    fill(a, a+50, 0);
    int cur = 0;
    int res = p;
    while(true) {
      if (res > 0) {
	a[cur]++;
	res--;
      } else {
	if (a[cur] == p) break;
	res = a[cur];
	a[cur] = 0;
      }
      cur = (cur+1)%n;
    }
    printf("%d\n", cur);
  }
}

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

const int M = 998244353;

int main(){
    int n,s;
    cin>>n>>s;

    vector<int> arr(n);
    for(int i = 0; i < n; i++) cin>>arr[i];

    vector<int> dp(s+1);

    int res = 0;
    for(int i = 0; i < n; i++){
        for(int j = s - arr[i]; j>=0; j--){
            dp[j+arr[i]]+=dp[j];
            dp[j+arr[i]]%=M;
        }
        if(arr[i]<=s){
            dp[arr[i]]+=i+1;
        }
    
        res += dp[s]%M;
        res%=M;
    }
    cout<<res;
}


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

int main()
{
    int n, x, ck = 0, ans;
    cin >> n >> x;
    ll arr[n], sum_c;
    sum_c = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum_c += arr[i];
    }

    sort(arr, arr + n);
    ll total = 0;
    for(int i = 0; i < n; i++)
    {
        total += arr[i];
        if(total > x)
        {
            ck = 1;
            ans = i;
            break;
        }
    }

    if(sum_c < x)
        cout << n - 1 << endl;
    else if(ck)
        cout << ans << endl;
    else
        cout << n << endl;
return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll a, b, x;
  cin>>a>>b>>x;
  cout<<(b+x)/x-(a+x-1)/x<<endl;
	return 0;
}


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

int main()
{
	int n;
	string s;
	cin >> n >> s;
	vector<vector<ll>> cnt(4,vector<ll>(n));
	for(int i = 0;i<n;i++)
	{
		if(s[i]=='R')cnt[1][i]++,s[i]=1;
		if(s[i]=='G')cnt[2][i]++,s[i]=2;
		if(s[i]=='B')cnt[3][i]++,s[i]=3;
	}
	for(int i = 0;i<3;i++)
	{
		for(int j = n-1;j>0;j--)
		{
			cnt[i+1][j-1] += cnt[i+1][j];
		}
	}
	ll ans = 0;
	for(int i = 0;i<n-2;i++)
	{
		for(int j = i+1;j<n-1;j++)
		{
			if(s[i]!=s[j])ans += cnt[(s[i]^s[j])][j];
		}
	}
	for(int i = 1;i<n;i++)
	{
		for(int j = 0;j<n;j++)
		{
			if(j+i*2>=n)break;
			if((s[j]^s[j+i]^s[j+i*2])==0)ans --;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3692