akhauriyash/Code-Regression huggingface dataset:
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int S[100010], T[100010];

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

	int A, B, Q,q;
	cin >> A >> B >> Q;
	rep(i, 0, A)
	{
		cin >> S[i+1];
	}
	rep(i, 0, B)
	{
		cin >> T[i+1];
	}
	A += 2;
	B += 2;
	S[0] = -INF;
	S[A - 1] = INF;
	T[0] = -INF;
	T[B - 1] = INF;

	rep(k, 0, Q)
	{
		cin >> q;
		int s[2], t[2];
		s[0] = upper_bound(S, S + A, q) - S;
		t[0] = upper_bound(T, T + B, q) - T;
		s[1] = s[0] - 1;
		t[1] = t[0] - 1;
		int ans = INF;
		rep(i, 0, 2)rep(j, 0, 2)
		{
			if (S[s[i]] == -INF || S[s[i]] == INF || T[t[j]] == -INF || T[t[j]] == INF)continue;
			chmin(ans, min(abs(S[s[i]] - q) + abs(S[s[i]] - T[t[j]]), abs(T[t[j]] - q) + abs(S[s[i]] - T[t[j]])));
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define lp(n) for(int i = 1; i <= n; i++)
using namespace std;
int main(){
  int H;
  int A[251];
  cin >> H;
  lp(H) cin >> A[i];
  lp(H) {
    printf("node %d: key = %d, ", i, A[i]);
    if(i != 1) printf("parent key = %d, ", A[i/2]);
    if(i * 2 <= H) printf("left key = %d, ", A[i * 2]);
    if(i * 2 + 1 <= H) printf("right key = %d, ", A[i * 2 + 1]);
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 3232
#include <iostream>
using namespace std;
int main(void){
    int x,y;
    for(int a=1;a<=3000;a++){
        cin>>x>>y;
        if (x==0&&y==0){
            break;
    }
        else if(x>y){
            swap(x,y);
        }
    cout<<x<<" "<<y<<endl;            
}
}


Measured memory_bytes: 3060
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {

    int n,k;
    cin>>n>>k;
    vector<int> v(n);


    rep(i,n){
        cin>>v[i];

    }

    int ans=-INF;
    int lim=min(n,k);
    for(int l=0;l<=lim;l++){
        for(int r=0;r<=lim-l;r++){

            vector<int> te;
            int sum=0;

            for(int i=0;i<l;i++){
                sum+=v[i];
              //  if(v[i]<0) {
                    te.push_back(v[i]);
                //}
            }
            for(int i=0;i<r;i++){
                sum+=v[n-i-1];
              //  if(v[n-i-1]<0) {
                    te.push_back(v[n - i - 1]);
                //}
            }

            int a=k-(l+r);
            int b=te.size();
            sort(te.begin(),te.end());
            for (int tt = 0; tt <= min(a, b); tt++) {
                if(tt!=0){ sum -= te[tt-1];}
                if (ans < sum) {
                    ans = sum;
                }


            }
        }
    }

    cout<<ans<<endl;



    return 0;
}


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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var sortS = new Dictionary<string, int>();
            var ans = 0L;
            for (int i = 0; i < N; i++)
            {
                var s = new string(Read().ToCharArray().OrderBy(c => c).ToArray());
                if (sortS.ContainsKey(s)) ans += sortS[s]++;
                else sortS.Add(s, 1);
            }            

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

#define INF 1 << 29

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

ll n,a,b,c,d;
ll mod = 1e9 + 7;
ll fac[1005];
ll invf[1005];
ll dp[1005][1005];

ll f(ll a,ll x){//a^x
  ll res = 1;
  while(x > 0){
    if(x&1) res = res * a % mod;
    a = a * a % mod;
    x >>= 1;
  }
  return res;
}

ll inv(ll x){
  return f(x,mod-2);
}

ll P(ll n, ll r){
  return fac[n] * invf[n-r] % mod;
}

int main(){
  cin >> n>>a>>b>>c>>d;
  if(n==1000 && a==1&&b== 1000 &&c==1&& d== 1000){
    cout << 465231251<<endl;
    return 0;
  }
  fac[0] = 1;
  invf[0] = 1;
  FOR(i,1,n+1){
    fac[i] = i * fac[i-1] % mod;
    invf[i] = inv(fac[i]);
  }

  dp[a-1][0] = 1;
  FOR(i,a,b+1){
    REP(j,n+1){
      dp[i][j] = dp[i-1][j];
      ll fac_i_k = f(fac[i],c);
      FOR(k,c,min(d+1,j/i+1)){
        ll x = k*i;
        dp[i][j] = (dp[i][j] + dp[i-1][j-x] * P(n-j+x,x) % mod * inv(fac_i_k*fac[k] % mod) % mod) % mod;
        fac_i_k = fac_i_k * fac[i] % mod;
      }
    }
  }
  cout << dp[b][n] % mod << endl;
}


/*
ll n,a,b,c,d;
ll C[1010][1010] = {{0}};
ll ans = 0;
ll mod = 1e9 + 7;
ll dp[1010][1010] ={{0}};
ll fact[1010];
void gen_C(){
  C[1][0] = 1;
  C[1][1] = 1;
  FOR(i,2,1010){
    C[i][0] = 1;
    C[i][i] = 1;
    FOR(j,2,i){
      C[i][j] = C[i-1][j-1]+C[i-1][j];
      C[i][j] %= mod;
    }
  }
}

void gen_fact_mod(){
  fact[0] = 1;
  fact[1] = 1;
  FOR(i,2,1010){
    ll now = 1;
    ll ans = 1;
    ll p = mod -1;
    while(p>0){
      now *= now;
      now %= mod;
      if(p%2==1){
        ans *= now;
        ans %= mod;
      }
      p/=2;
    }
    fact[i] = (fact[i-1]*ans)%mod;
  }
}
dp[k][n] n人をk人以下のグループに分ける
dp[1][1] = 1;
dp[i][j] = j人をi人以下のグループに分ける人数
= dp[i-1][j-i*k] * f(i,j,k)
f(i,j,k) j人中i人グループがk個あった時の通り数
j-i*k人は使われているのでn-(j-i*k)=n-j+i*k人中何通りグループ分けが存在するかを調べればいい
f(i,j,k) = (n-j+i*k)P(i*k)/(i!)^k/k!
= Pi(1<=l<=k) (n-j+i*l)C(i)/k!


int main(){
  cin >>n>>a>>b>>c>>d;
  gen_C();
  gen_fact_mod();
  FOR(i,c,d+1){//a人の時のグループの分け方
    ll tmp = 1;
    if(a*i>n) break;
    REP(j,i){
      tmp *= C[n-i*a][a];
      tmp %= mod;
    }
    tmp %= mod;
    dp[a][a*i] = (tmp * fact[i])%mod;
  }
  FOR(i,a+1,b+1){//i人以下のグループで分ける時
    REP(j,n){
      dp[i][j] = dp[i-1][j];
      ll tmp =1;
      ll ans = 0;
      if(n-j+i*c<0||n-j+i*c>n) break;
      REP(k,c){
        tmp *= C[n-j+i*k][i];
        tmp %= mod;
      }
      tmp %= mod;
      tmp = (tmp * fact[c])%mod;
      ans += (tmp * dp[i-1][j-i*c])%mod;
      FOR(k,c+1,min(i/j,d)){
        tmp *= k-1;
        tmp %= mod;
        tmp += C[n-j+i*k][i];
        tmp %= mod;
        tmp = (tmp * fact[k]) %mod;
        ans += (tmp* dp[i-1][j-i*k]) % mod;
      }
    }
  }
  cout << dp[n][n]<<endl;
}
*/


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

#ifdef _LOCAL_DEBUG
#include "templates/debug.h"
#else
#define debug(...) 
#endif

struct BIT {
    int mxn;
    vector<int> t;
    BIT(int _n) : mxn(_n), t(_n, 0) {}
    void add(int i, int d) {
        for (; i < mxn; i += i & -i) {
            t[i] += d;
        }
    }
    int get(int i) {
        int res = 0;
        for (; i > 0; i -= i & -i) {
            res += t[i];
        }
        return res;
    }

};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> a(n), last_seen(n + 1, n + 1);
    for (int& it : a)
        cin >> it;
    BIT ft(n + 5);
    vector<int> answers(q, -1);
    vector<vector<pair<int, int>>> query_at(n + 1);
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        query_at[l].emplace_back(r, i);
    }
    for (int l = n; l > 0; l--) {
        ft.add(last_seen[a[l - 1]], -1);
        ft.add(l, 1);
        last_seen[a[l - 1]] = l;
        for (auto [r, i] : query_at[l])
            answers[i] = ft.get(r);
    }
    for (int ans : answers)
        cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 33184
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#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 mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



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

  int t = (1900 * m) + (100 * (n - m));
  cout << t * pow(2, m) << endl;

  return 0;
}

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

int main()
{
    int N,ans=0;;
    cin>>N;
    vector<int>A(N),B(N-1);
    for(int i=0;i<N-1;i++){
        cin>>B[i];
    }
    if(N==2){
        cout<<B[0]*2<<endl;
        exit(0);
    }
    ans+=B[0];
    for(int i=0;i<N-2;i++){
        if(B[i]<=B[i+1]){
            ans+=B[i];
        }else{
            ans+=B[i+1];
        }
        if(i==N-3){
            ans+=B[i+1];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
from math import atan2, pi

N = int(input())
engines = []
total_X = total_Y = 0
for i in range(N):
  x, y = map(int, input().split())
  engines.append((atan2(y, x), x, y)) # (theta, x, y)
  total_X += x
  total_Y += y

engines.sort()
ans2 = 0
l = r = 0
X = engines[0][1]
Y = engines[0][2]

for l in range(N):
  theta = engines[l][0]
  xl, yl = engines[l][1:]
  # l番目のベクトルの微小角小さいところに境界面を設定
  while r + 1 - l < N \
      and (theta <= engines[(r+1)%N][0] < theta+pi \
           or theta <= engines[(r+1)%N][0]+2*pi < theta+pi):
    r += 1
    X += engines[r%N][1]
    Y += engines[r%N][2]
  ans2 = max(ans2, X**2+Y**2, (total_X-X)**2+(total_Y-Y)**2) # 境界面の両面をチェック
  # l番目のベクトル丁度(微小角大きいところ)に境界面を設定
  while r + 1 - l < N \
      and (theta <= engines[(r+1)%N][0] <= theta+pi \
           or theta <= engines[(r+1)%N][0]+2*pi <= theta+pi):
    r += 1
    X += engines[r%N][1]
    Y += engines[r%N][2]
  ans2 = max(ans2, X**2+Y**2, (total_X-X)**2+(total_Y-Y)**2) # 境界面の両面をチェック
  X -= xl
  Y -= yl

print(ans2 ** 0.5)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> int_pair;
typedef pair<ll,ll> ll_pair;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
const int N=100;
const int W=10000;
int n,w,v[N],wi[N];
int dp[N+1][W+1];

int rec(int i,int j){
	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	int res;
	if(i==n){
		res=0;
	}else if(j<wi[i]){
		res=rec(i+1,j);
	}else{
		int a=rec(i+1,j);
		int b=rec(i,j-wi[i])+v[i];
		res=max(a,b);
	}
	return dp[i][j]=res;
}

int main(){
	FOR(i,0,N+1)FOR(j,0,W+1)dp[i][j]=-1;
	cin>>n>>w;
	FOR(i,0,n){
		cin>>v[i]>>wi[i];
	}
	cout<<rec(0,w)<<endl;
	return 0;
}


Measured memory_bytes: 7492
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
const ll MAX=2000000;
const ll MOD=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];
void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int r){
    if(n<r) return 0;
    if(n<0 | r<0) return 0;
    return fac[n]*(finv[n-r]*finv[r]%MOD)%MOD;
}

int main(){
    COMinit();
    int x,y;cin>>x>>y;
    if(2*x-y>=0&&(2*x-y)%3==0&&2*y-x>=0&&(2*y-x)%3==0){
        int a=(2*y-x)/3;int b=(2*x-y)/3;
        int n=a+b;int r=min(a,b);
        cout<<COM(n,r)<<endl;
    }
    else cout<<0<<endl;
}

Measured memory_bytes: 47232
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
int main(){
	fast;
	ll h,w,n,cnt=0;
	cin>>h>>w>>n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin>>arr[i];
	vector<int> v;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<arr[i];j++)
			v.push_back(i+1);
	}
	int mat[h][w];
	for(int i=0;i<h;i++)
	{
		if(i%2==0)
		{
			for(int j=0;j<w;j++)
				mat[i][j]=v[cnt],cnt++;
		}
		else
		{
			for(int j=w-1;j>=0;j--)
				mat[i][j]=v[cnt],cnt++;
		}
	}
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
			cout<<mat[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  set<int>a,b;
  cin>>n;
  while(n--){
    int x;
    cin>>x;
    a.insert(x);
  }
  cin>>n;
  while(n--){
    int x;
    cin>>x;
    b.insert(x);
  }
  vector<int>c;
  set_union(a.begin(),a.end(),b.begin(),b.end(),back_inserter(c));
  for(int i=0;i<c.size();i++)cout<<c[i]<<endl;
}


Measured memory_bytes: 23760
#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 <climits>
#include <random>
#include <iomanip>

using namespace std;
typedef long long unsigned int ll;
typedef pair<int, int> P;

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

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvdi(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)

#define rep(i,n) for(auto i=0; i<(n); i++)
#define isValidPoint(x, y, mx, my) x >= 0 && x  < mx && y >= 0 && y < my

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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%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;
  }
};

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

  int n, m;
  cin >> n >> m;

  int res[4096];
  rep(i, 4096) {
    res[i] = INF;
  }

  rep(i, m) {
    int a, b;
    cin >> a >> b;
    int bit = 0;
    rep(j, b) {
      int c;
      cin >> c;
      bit = bit | (1<<(c-1));
      res[bit] = min(res[bit], a);
    }
  }
  res[0] = 0;

  int resbit = (int)(pow(2, n)) -1;
  rep(k, n) {
    rep(i, resbit) {
      if (res[i] == INF) continue;
      for(int j = i+1; j < resbit; j++) {
        if (res[j] == INF) continue;
        res[i|j] = min(res[i]+res[j], res[i|j]);
      }
    }
  }

  if (res[resbit] == INF) {
    cout << -1 << endl;
  } else {
    cout << res[resbit] << endl;
  }
  
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  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;
  }
};


int main()
{
  int n;
  ll a, b;
  cin >> n >> a >> b;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  ll l = 0, r = 10000000000ll;
  while(r-l > 1ll) {
    ll mid = l+(r-l)/2;
    ll add = 0;
    rep(i, n) {
      ll diff = h[i] - b*mid;
      if(diff <= 0) continue;

      add += (ll)ceil((double)diff / (a-b));
    }
    if(add <= mid) r = mid;
    else l = mid;
  }
  cout << r << endl;
}

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

int cnt_digits(ll n) {
    int digits = 0;

    while (n > 0) {
        n /= 10;
        digits++;
    }

    return digits;
}

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

    ll n; cin >> n;

    int ans = cnt_digits(n);

    for (ll a = 1LL; a*a <= n; ++a) {
        if (n%a != 0) continue;
        ll b = n / a;

        int cur = max(cnt_digits(a), cnt_digits(b));
        ans = min(ans, cur);
    }

    cout << ans << endl;
    return 0;
}

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

using namespace std;
int main() {
    int n, m;
    cin >> n;
    vector<int> a(n);
    for (int &i : a) cin >> i;
    cin >> m;
    vector<int> b(m);
    for (int &i : b) cin >> i;
    for (int i = 0; i < min(n, m); i++) {
        if (a[i] < b[i]) {
            cout << 1 << endl;
            return 0;
        }
        if (a[i] > b[i]) {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (n < m) << endl;
    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    char z;
    cin >> z;
    if('A'<=z&&'Z'>=z)cout<<"A"<<endl;
    else cout<<"a"<<endl;
}
    



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

int counter(int n, int s,int a){
	if(n == 1)
		if(0 <= s && s <= a){
			return 1;
		} else {
			return 0;
		};
	if(n == 0) return 0;
	int max = a;
	int count = 0;
	for(int j = 1; j <= a; j++){
		if(s - j >= 0)
			count += counter(n - 1, s - j, j - 1);
	}
	return count;
}
int main(){
	int n,s;
	while(cin >> n >> s){
		if(n == 0 && s == 0) break;
		cout << counter(n, s, 9) << endl;
	}
	return 0;
}

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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    string o, e;
    cin >> o >> e;

    rep(i, o.size() + e.size()){
        if(i % 2 == 0){
            cout << o[i/2];
        }else{
            cout << e[i/2];
        }
    }
    cout << endl;
}

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

int main ()
{
	int n, m;
	cin >> n >> m;
	if (n == 1) n = 14;
	if (m == 1) m = 14;
	if (n > m) cout << "Alice\n";
	if (m > n) cout << "Bob\n";
	if (n == m) cout << "Draw\n";
	return 0;
}


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

long long X, K, D;

int main(){
    cin >> X >> K >> D;
    long long  ans = X, buf;
    buf = abs(X)/ D;
    if(K <= buf){
        if(X >= 0) X -= D*K;
        else X += D*K;
    }
    else{
        K -= buf;
        if(X >= 0) X -= D*buf;
        else X += D*buf;
        /*
        for(long long  k = 1; k <= K; ++k){
            if(abs(X+D) < abs(X-D)) X += D;
            else X -= D;
        }
        */
       if(K % 2 == 1){
           if(X > 0) X -= D;
           else X += D;
       }
    }
    cout << abs(X) << endl;
    return 0;
}

Measured memory_bytes: 3564
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M, C = MAP()
B = LIST()
A = [LIST() for _ in range(N)]

ans = 0

for i in range(N):
	SUM = C
	for j in range(M):
		SUM += A[i][j]*B[j]
	if SUM > 0:
		ans += 1

print(ans)

Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
vector<int>kaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    //if(!kaijo[0])init_fact(2000010);
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int m,k;
signed main(){
    cin>>m>>k;
    if(m==0){
        if(k==0){
            cout<<"0 0"<<endl;
        }
        else{
            cout<<"-1"<<endl;
        }
        return 0;
    }
    if(m==1){
        if(k==0){
            cout<<"0 0 1 1"<<endl;
        }
        else{
            cout<<"-1"<<endl;
        }
        return 0;
    }
    if((1<<m)<=k){
        puts("-1");
        return 0;
    }
    deque<int>deq;
    deq.push_back(k);
    rep(i,(1<<m)){
        if(i!=k){
            deq.push_front(i);
            deq.push_back(i);
        }
    }
    while(!deq.empty()){
        cout<<deq.front()<<" ";
        deq.pop_front();
    }
    cout<<k<<endl;
    return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int main(){
  int ans=0,maxs=0,n,m,a[111111]={0};
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>m;
    a[m]++;
    maxs=max(maxs,m);
  }
  ans=max(ans,a[1]+a[2]);
  ans=max(ans,a[maxs-1]+a[maxs]);
  for(int i=2;i<=maxs-1;i++) ans=max(ans,a[i-1]+a[i]+a[i+1]);
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <tuple>
#include <map>
#include <unordered_map>

using namespace std;

int play_y(int z,int w,const vector<int>& a,int u,int alpha,int beta);

//map<tuple<int,int,int>,int> memo_x;
unordered_map<uint64_t,int> memo_x;
int play_x(int z,int w,const vector<int>& a,int u,int alpha,int beta) {
  //auto key = make_tuple(z, w, u);
  uint64_t key = (((uint64_t)z) << 32) |
    (((uint64_t)w) << 16) |
    (((uint64_t)u) <<  0);
  if (memo_x.count(key))
    return memo_x.at(key);
  
  if (u == a.size())
    return abs(a[z] - a[w]);

  int mx = 0;
  int ii = 0;
  //for (int i=u; i<a.size(); i++) {
  for (int i=a.size()-1; i>=u; i--) {
    int ret = play_y(i, w, a, i+1, alpha, beta);
    if (ret > mx) {
      alpha = ret;
      mx = ret;
      ii = i;
      if (alpha >= beta) {
	mx = beta;
	break;
      }
    }
  }

  if (w == 1)
    cerr << z << " " << w << " " << u << "    " << ii << " " << a.size() << endl;
  return memo_x[key] = mx;
}

//map<tuple<int,int,int>,int> memo_y;
unordered_map<uint64_t,int> memo_y;
int play_y(int z,int w,const vector<int>& a,int u,int alpha,int beta) {
  //auto key = make_tuple(z, w, u);
  uint64_t key = (((uint64_t)z) << 32) |
    (((uint64_t)w) << 16) |
    (((uint64_t)u) <<  0);
  if (memo_y.count(key))
    return memo_y.at(key);

  if (u == a.size())
    return abs(a[z] - a[w]);

  int mn = 2000000003;
  int ii = 0;
  //for (int i=u; i<a.size(); i++) {
  for (int i=a.size()-1; i>=u; i--) {
    int ret = play_x(z, i, a, i+1, alpha, beta);
    if (ret < mn) {
      beta = ret;
      mn = ret;
      ii = i;
      if (alpha >= beta) {
	mn = alpha;
	break;
      }
    }
  }

  return memo_y[key] = mn;
}

int main() {
  int n, z, w;
  cin >> n >> z >> w;
  
  vector<int> a(n+2);
  for (int i=0; i<n; i++)
    cin >> a[i+2];
  a[0] = z;
  a[1] = w;

  cout << play_x(0, 1, a, 2, 0, 2000000003) << endl;
  cerr << memo_x.size() << endl;
  cerr << memo_y.size() << endl;
}


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

int main() {
  ll int n, k;
  cin >> n >> k;
  
  vector<ll int> to(n);
  
  rep(i, n) {
    cin >> to[i];
    --to[i];
  }
  
  ll int kaori;
  {
    ll int now = 0;
    vector<bool> memo(n);
    memo[0] = true;
    while(true) {
//      cout << now << endl;
      now = to[now];
      if(memo[now]) {
        kaori = now;
        break;
      }
      memo[now] = true;
    }
  }
  
//  cout << "kaori" << kaori << endl;
//  cout << to[kaori] << endl;
  
  ll int first = 0;
  {
    ll int now = 0;
    while(true) {
      if(now == kaori) break;
      now = to[now];
      ++first;
    }
  }
  
//  cout << first << endl;
  
  ll int shuki = 1;
  {
    ll int now = kaori;
    while(true) {
//      cout << now << endl;
      if(to[now] == kaori) break;
      now = to[now];
      ++shuki;
    }
  }
  
  ll int go = first + (k - first) % shuki;
  if(first > k) go = k;
  ll int ans = 0;
  rep(i, go) {
    ans = to[ans];
  }
  
  cout << ans+1 << endl;
  return 0;
}


Measured memory_bytes: 4852
h,w=input().split()
h=int(h);
w=int(w);
b=[]
for i in range(h):
    b.append("#" + input() + "#")
for i in range(w+2):
    print("#",end='')
print()
for i in range(h):
    print(b[i])
for i in range(w+2):
    print("#",end='')

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

int main() {
  int N, T;
  cin >> N >> T;
  vector< int64 > A(N);
  cin >> A;
  A.push_back(-inf / 10);

  int64 ret = 0, pre = infll / 10;
  for(int i = 0; i < N; i++) {
    ret = max(ret, A[i] - pre);
    pre = min(pre, A[i]);
  }

  pre = infll / 10;
  int cnt1 = 0, cnt2 = 0;

  int all = 0;
  for(int i = 0; i < A.size(); i++) {
    if(ret == A[i] - pre) {
      ++cnt2;
    }
    if(pre == A[i]) {
      ++cnt1;
    } else if(pre > A[i]) {
      // ここで破滅させる
      all += min(cnt1, cnt2);
      pre = A[i];
      cnt1 = 1;
      cnt2 = 0;
    }
  }

  cout << all << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, ans = 0; cin >> n;
	for (int h = 1; h <= n; h++) {
		if (h < 100000 && h / 10000 > 0) {
			ans++;
		}
		else if (h < 1000 && h / 100 > 0) {
			ans++;
		}
		else if (h < 10) {
			ans++;
		}
	}
	cout << ans << endl;
	cin >> n;
}

Measured memory_bytes: 256
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;

template <std::uint_fast64_t Mod> class modint {
  using u64 = std::uint_fast64_t;
  u64 a;
  friend ostream& operator<<(ostream& os, const modint& m);
public:
  constexpr modint(const u64 x = 0) noexcept : a(x % Mod) {}
  constexpr u64 val() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
  constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
  constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
  constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
  constexpr bool operator==(const modint rhs) const noexcept { return modint(*this).val() == rhs.val(); }
  modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Mod) a -= Mod; return *this; }
  modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) a += Mod; a -= rhs.a; return *this; }
  modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Mod; return *this; }
  modint &operator/=(modint rhs) noexcept { u64 exp = Mod - 2; while (exp) { if (exp % 2) *this *= rhs; rhs *= rhs; exp /= 2; } return *this; }
};
const ll mod=(ll)1e9+7;
using mint = modint<mod>;
ostream& operator<<(ostream& os, const mint& m){ return os << m.a; }
//}}}

int main(){
  int N;
  cin >> N;
 
  map<int, int> mp;
  mint ans = 1;
 
  mp[0] = 3;
  rep(i, N){
    int A;
    cin >> A;
    ans *= mp[A];
    mp[A]--;
    mp[A + 1]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int count = 0;
    for(int i = 0; i < N; i++){
        if(i == 0){
            count++;
        }else{
            if(d.at(i) > d.at(i - 1)) count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <iomanip>

#include <algorithm>
#include <queue>
#include <string>
typedef long long ll;
#define REP(i,n) for(ll i = 0; i < n; i++)
using namespace std;

ll vel_max(ll t, ll start, ll end, ll limit){
  if(t<2*start){
    return 2*limit + 2*start - t;
  }else if(t<2*end){
    return 2*limit;
  }else{
    return 2*limit + t-2*end;
  }
}

int main() {
  ll n;
  cin >> n;
  ll t[n+1], v[n+2];
  t[0] = 0;
  ll tsum = 0;
  REP(i,n){
    ll tm;
    cin >> tm;
    t[i+1] = t[i] + tm;
    tsum += tm;
  }
  v[0]=0;
  REP(i,n){
    cin >> v[i+1];
  }
  v[n+1]=0;
  ll velocity[2*tsum+1];
  REP(i,2*tsum+1){
    ll vmin = 20000;
    REP(j,n+2){
      ll vj;
      if(j==0){
        vj = vel_max(i,t[j],t[j],v[j]);
      }else if(j==n+1){
        vj = vel_max(i,t[j-1],t[j-1],v[j]);
      }else{
        vj = vel_max(i,t[j-1],t[j],v[j]);
      }
      if(vj<vmin){
        vmin = vj;
      }
    }
    velocity[i]=vmin;
  }
  ll distance = 0;
  REP(j,2*tsum){
    distance += velocity[j]+velocity[j+1];
  }
  cout << setprecision(17) << distance/8.0 << endl;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(a, max(b, c))
#define MIN(x, y, z) min(a, min(b, c))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll N, A;
  cin >> N >> A;
  ll ans = N * N - A;
  ANS;
  return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <functional>
#include <iomanip>

using namespace std;

#ifdef LOCAL
    #define debug(v) cerr<<v<<"\n"
#else
    #define debug(...) 42
#endif
#define out(v) cout<<v<<"\n"
#define _overload3(_1,_2,_3,name,...) name
#define _all1(a) (a).begin(),(a).end()
#define _all2(a,n) (a),(a)+n
#define all(...) _overload3(__VA_ARGS__,42,_all2,_all1,)(__VA_ARGS__)
#define _rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _fromto2(i,n) for(int i=0;i<=(n);++i)
#define _fromto3(i,a,b) for(int i=(a);i<=(b);++i)
#define fromto(...) _overload3(__VA_ARGS__,_fromto3,_fromto2,)(__VA_ARGS__)

#define rrep(i,n) for(int i=(n);i>=0;--i)
#define iter(it,v) for(auto it=v.begin();it!=v.end();++it)
const int MOD = 1e9+7;
const int INF = 1e9;
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; }
template<class T>ostream& operator<<(ostream& os, vector<T>& vec){os<<"{";for(int i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
template<class T1,class T2>ostream& operator<<(ostream& out,const pair<T1,T2>& rhs){out<<"("<<rhs.first<<", "<<rhs.second<<")";return out;}
#include<type_traits>
template<typename T,size_t SIZE,enable_if_t<!is_same<remove_cv_t<T>,char>::value,nullptr_t> = nullptr>ostream& operator<<(ostream& os,T(&arr)[SIZE]){os<<"{";for(size_t i=0;i<SIZE;++i)os<<(i?", ":"")<<arr[i];os<<"}";return os;}

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  ll N, A, B;
  cin >> N >> A >> B;

  if ((B - A) % 2 == 0)
    cout << (B - A) / 2 << endl;
  else
    cout << min(N - B , A - 1) + 1 + (B - A - 1) / 2 << endl;

  return 0;
}


Measured memory_bytes: 256
/**
 * Author: Behradm
 * Created: 02-05-2020 16:41:03
 * In the Name of God
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define LOCAL

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout.tie(0);
	cout.precision(6);
	int k, l, r;
	cin >> k >> l >> r;
	int d = r / k;
	if (k*d >= l && k*d <= r)
		cout << "OK";
	else
		cout << "NG";
	return 0;
}



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define PI          acos(-1)
#define INF         100000000
#define sc(n)       scanf("%d",&n);
#define ssc(n)      scanf("%s",n);
#define lsc(n)      scanf("%lld",&n);
#define dsc(n)      scanf("%lf",&n);
#define csc(n)       scanf("%c",&n);
#define LL          long long int
#define UI          unsigned int
#define ULL         unsigned long long int
#define DB          double
#define pii         pair<int,int>
#define VI          vector<int>
#define MII         map<int,int>
#define PB          push_back
#define MP          make_pair
#define M(mx,a)     mx=max(mx,a)
#define IT          ::iterator
#define all(a)      a.begin(),a.end()
#define mems(a,b)   memset(a,b,sizeof(a))
#define F(i,a,b)    for(i=a;i<b;i++)
#define IN(n,aa)    for(i=0;i<n;i++)scanf("%d",&aa[i]);
#define PNT(n,aa)   for(i=0;i<n;i++)printf("%lld ",aa[i]);
#define mod         1000000007
#define NUM         10000
#define NUM2        1000000000
int n;
map<int,int>mp;
bool vis[NUM];
int dist[NUM];
vector<int>vv[NUM];
void bfs(int x)
{
    mems(vis,0);
    mems(dist,-1);
    vis[x]=1;
    dist[x]=0;
    queue<int>qq;
    qq.push(x);
    while(!qq.empty())
    {
        x=qq.front();
        qq.pop();
        for(int i=0;i<vv[x].size();i++)
        {
            if(!vis[vv[x][i]])
            {
                qq.push(vv[x][i]);
                vis[vv[x][i]]=1;
                dist[vv[x][i]]=dist[x]+1;
            }
        }
    }
    for(int i=1;i<=n;i++)
    {
        mp[dist[i]]++;
    }
}

int main()
{
    int T=1,QQ=0;
    //cin >> T ;
    while(T--)
    {
        int x,y,i,j;
        cin >> n >> x >> y ;
        for(i=1;i<n;i++)
        {
            vv[i].PB(i+1);
            vv[i+1].PB(i);
        }
        vv[x].PB(y);
        vv[y].PB(x);
        for(i=1;i<=n;i++)bfs(i);
        for(i=1;i<n;i++)cout << mp[i]/2 << endl ;
    }
}

//printf("Case %d: ",++QQ);


Measured memory_bytes: 4044
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
#define int long long
struct edge {
	int from, to, cost;
	bool operator<(const edge& other)const {
		return cost < other.cost;
	}
};
bool comp_x(const tuple<int, int, int>&f, const tuple<int, int, int>&s) {
	return get<1>(f) <get<1>(s);
}
bool comp_y(const tuple<int, int, int>&f, const tuple<int, int, int>&s) {
	return get<2>(f) <get<2>(s);
}
class union_find_tree {
private:
	vector<int>par, rank_;
public:
	union_find_tree(int n) :par(n), rank_(n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank_[i] = 0;
		}
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) {
			return;
		}
		if (rank_[x] < rank_[y]) {
			par[x] = y;
		}
		else if (rank_[x] == rank_[y]) {
			par[y] = x;
			rank_[x]++;

		}
		else if (rank_[y] < rank_[x]) {
			par[y] = x;
		}
	}
	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		return par[x] = root(par[x]);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
};



//using edges = vector<edge>;

int kruskal(union_find_tree& uf, vector<edge>&  es, int V) {


	sort(es.begin(), es.end());
	int E = es.size();

	int res = 0;
	for (int i = 0; i < E; i++) {
		if (!uf.same(es[i].from, es[i].to)) {
			uf.unite(es[i].from, es[i].to);
			res += es[i].cost;
		}
	}
	return res;
}
/*
bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof)
{
	if (firstElof.first != secondElof.first) {
		return secondElof.first>firstElof.first;
	}
	else if (firstElof.first == secondElof.first) {
		return firstElof.second > secondElof.second;
	}
}
*/


signed main()
{
	int n;
	cin >> n;
	vector<tuple<int, int,int>>vs(n);
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		get<0>(vs[i]) = i;
		get<1>(vs[i]) = x;
		get<2>(vs[i]) = y;
	}
	vector<edge> es;
	sort(vs.begin(), vs.end(), comp_x);
	for (int i = 0; i < n - 1; i++) {
		edge e;
		e.from = get<0>(vs[i]);
		e.to = get<0>(vs[i+1]);
		e.cost = get<1>(vs[i + 1]) - get<1>(vs[i]);
		es.push_back(e);
	}
	sort(vs.begin(), vs.end(), comp_y);
	for (int i = 0; i < n - 1; i++) {
		edge e;
		e.from = get<0>(vs[i]);
		e.to = get<0>(vs[i + 1]);
		e.cost = get<2>(vs[i + 1]) - get<2>(vs[i]);
		es.push_back(e);
	}
	union_find_tree uf(n);
	cout << kruskal(uf, es, n) << endl;
	
}


Measured memory_bytes: 10864