akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
int main(){
    int n,k;
    scanf("%d%d",&n,&k);
    int i,j,ans=1;
    for(i=1;i<=n;i++){
    	if(i==1){
    		ans*=k;
		}else{
			ans*=k-1;
		}
	}
	printf("%d\n",ans);
    return 0;
}

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

int a[110];

void print(const int *a, int n){
	for(int j = 0; j < n - 1; j++)
		printf("%d ", a[j]);
	printf("%d\n", a[n-1]);
}

void insertionSort(int *a, int n){
	for(int i = 1; i < n; i++) {
		print(a, n);
		int v = a[i];
		int j = i - 1;
		while(j >= 0 && v < a[j]) {
			a[j+1] = a[j];
			j--;
		}
		a[j+1] = v;
	}
	print(a, n);
}

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	insertionSort(a, n);
}



Measured memory_bytes: 3220
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

int ans=0;
void dfs(const int now, vector<int>&comes,vector<int>&colors,const vector<int>&tos) {
	if (find(comes.begin(), comes.end(), now) != comes.end()) {
		auto it=find(comes.begin(),comes.end(),now);
		for (auto tt = it; tt != comes.end(); ++tt) {
			colors[*tt]=-1;
		}
		ans++;
		return;
	}
	if (colors[now] == -1) {
		return ;
	}
	else {
		comes.push_back(now);
		dfs(tos[now],comes,colors,tos);
	}
}

int main() {
	while (true) {
		ans=0;
		int N;cin>>N;
		if(!N)break;
		vector<int>tos(N*N);
		for (int i = 0; i < N*N; ++i) {
			int x,y;cin>>x>>y;
			tos[i]=y*N+x;
		}
		vector<int>colors(N*N);
		for (int i = 0; i <N* N; ++i) {
			vector<int>comes;
			dfs(i,comes,colors,tos);
		}
		
		cout<<ans<<endl;
	}
	return 0;
} 

Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
int main() {
 ll n, m;
 cin >> n >> m;
 if(m - 2*n<=0){
     cout << min(n, m/2) << endl;
     return 0; 
 }else{
     ll k = (m - 2*n)/4;
     cout << min(n+k, (m-2*k)/2) << endl;
     return 0;
 }
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>

int main(int argc, char *argv[])
{
    int n;

    std::vector<std::string> s;
    std::vector<int> t;

    std::string x;

    std::cin >> n;

    s.resize(n);
    t.resize(n);

    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
        std::cin >> t[i];
    }

    std::cin >> x;

    int length = 0;
    for (int i = 0; i < n; i++) {
        length += t[i];
        if (s[i] == x) {
            length = 0;
        }
    }

    std::cout << length << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

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

ll GCD(ll x, ll y) {
	if (y == 0) return x;
	else return GCD(y, x % y);
}

int main()
{
	int j = 0;
	string S;
	cin >> S;

	rep(i, 4) {
		if (S[i] == '+') { ++j; }
		else { --j; }
	}

	cout << j << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int N, K;
vector<int> A, B;

ll solve(int x) {
	if (!(K & (1 << x))) return 0;
	int f = (1 << x) - 1;
	for (int i = x + 1; i <= 30; ++i)
		f |= (K & (1 << i));
	ll tmp = 0;
	for (int i = 0; i < N; ++i)
		if ((f | A[i]) == f)
			tmp += B[i];
	return tmp;
}

int main() {
	cin >> N >> K;
	A.resize(N); B.resize(N);
	for (int i = 0; i < N; ++i)
		cin >> A[i] >> B[i];
	ll res = 0;
	for (int i = 0; i < N; ++i) 
		if ((K | A[i]) == K)
			res += B[i];
	for (int x = 30; x > 0; --x)
		res = max(res, solve(x));
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(c==-1||d==-1)
	{
		if(a<b)cout<<"Alice"<<endl;
		else if(a>b)cout<<"Bob"<<endl;
		else cout<<"Draw"<<endl;
	}
	else
	{
		if(c>d)cout<<"Alice"<<endl;
		else if(c<d)cout<<"Bob"<<endl;
		else cout<<"Draw"<<endl;
	}
	return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

int main()
{
    int house[4][3][10] = { 0 };
    const string hr = "####################";

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int b, f, r, v;
        cin >> b >> f >> r >> v;

        house[b - 1][f - 1][r - 1] += v;
    }

    for (size_t i = 0; i < 4; i++) {
        if (i != 0) {
            cout << hr << endl;
        }

        for (size_t j = 0; j < 3; j++) {
            for (size_t k = 0; k < 10; k++) {
                cout << " " << house[i][j][k];
            }
            cout << endl;
        }
    }
}



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

int main(){
	int H,N,L,R;
	H = 0;
	cin >> N;
	
	for(int i = N; i>0;i--){
		cin >> L >> R;
		R = R - L + 1;
		H = H + R;
	}
	cout << H << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define INF 1LL<<60
#define pi 3.14159265358979323846
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

int main(){
    string x;cin>>x;
    int n=x.size();

    int s=0,t=0;
    for(int i=0;i<n;i++){
        if(x[i]=='S'){s++;}
        if(x[i]=='T'){if(t<s) t++;}
    }

    cout<<n-2*min(s,t)<<endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main() {
	//input
	string S;
	char c;
	int count=0;
	cin >> S;

	//compute
	for (int i = 0; i <= 50; i++) {
		c = S[2*i];
		if (c!=' ') {
			if (c == 'L')count++;
			c = ' ';
		}
	}
	for (int i = 0; i < 50; i++) {
		c = S[2 * i+1];
		if (c != ' ') {
			if (c == 'R')count++;
			c = ' ';
		}
	}
	//output
  if(count==0){
    cout << "Yes";
  }
  else{
	cout<<"No";
  }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll a,b,c;
  cin >>a>>b>>c;
  if(a<b){
    if(a<=c&&b>=c) cout <<"Yes"<<endl;
    else cout <<"No"<<endl;
  }
  else{
    if(b<=c&&a>=c) cout <<"Yes"<<endl;
    else cout <<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) throws Exception{
        Scanner input = new Scanner(System.in);
        int sx = input.nextInt();
        int sy = input.nextInt();
        int cx = input.nextInt();
        int cy = input.nextInt();
        int cn = input.nextInt();
        if(cx+cn > sx || cy+cn > sy || cx-cn < 0 || cy-cn < 0){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 26224
M = int(input())
d, c = zip(*[[int(x) for x in input().split()] for _ in range(M)])
n_digits = sum(c) # 桁数
sum_digits = sum(d[i] * c[i] for i in range(M))
ans = n_digits - 1 + (sum_digits - 1) // 9
print(ans)

Measured memory_bytes: 49800
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
    int n,x[1000],y[1000];
    cin >> n;
    for (int i = 0;i < n;i++) cin >> x[i];
    for (int i = 0;i < n;i++) cin >> y[i];
    double d[]={0.0,0.0,0.0,0.0};
    for (int p = 1;p <= 3;p++){
        for (int i = 0;i < n;i++){
            d[p]+=pow(fabs(x[i]-y[i]),p);
        }
        d[p]=pow(d[p],1.0/p);
    }
    for (int i = 0;i < n;i++){
        d[0]=max(d[0],fabs(x[i]-y[i]));
    }
    printf("%lf\n",d[1]);
    printf("%lf\n",d[2]);
    printf("%lf\n",d[3]);
    printf("%lf\n",d[0]);

    return 0;
}


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

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>

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

int main()
{
    int n, a[3000];
    int sum = 0;

    cin >> n;
    rep(i, 0, n)
    {
        cin >> a[i];
        sum += a[i] - 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define pb push_back
#define eb emplace_back
#define mp make_pair
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using vvli = vector<vlli>;
using vs = vector<string>;
using vvs = vector<vs>;
using vb = vector<bool>;
using vvb = vector<vb>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, e, h, k, n, w, ans = 0, count = 0;
  long double f, tmp;
  string s, t;
  vector<pair<string, pair<lli, lli>>> pr;
  cin >> e >> f;
  if (e == 0 || f == 0)
  {
    cout << 0 << endl;
    return 0;
  }
  ans = e * f;

  cout << ans << endl;
}


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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	auto cs = load<string>();
	auto good = cs[0] != cs[1] and cs[1] != cs[2] and cs[2] != cs[3];
	cout << (good ? "Good\n" : "Bad\n");
}


Measured memory_bytes: 256
/*
Hanit Banga
Problem: 
*/

#include <iostream>
#include <vector>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 5;

int main()
{
	int x, y;
	cin >> x >> y;

	if (x <= y)
	{
		if ((x <= 0 and y <= 0) or (x >= 0 and y >= 0))
			cout << y-x;

		else if (x < -y)
			cout << 1-x-y;

		else
			cout << 1+x+y;
	}

	else if (x == -y)
		cout << 1;

	else if ((x < 0 and y < 0) or (x > 0 and y > 0))
		cout << 2-y+x;

	else if (x > -y)
		cout << 1+x+y;

	else
		cout << 1-x-y;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

void add_uekara(vector<vector<int64>>& g, vector<int64>& ad, vector<int64>& ans,
                vector<int64>& visited, int64 idx) {
  ans[idx] += ad[idx];
  visited[idx] = 1;
  if (g[idx].size() == 0) return;
  for (auto v : g[idx]) {
    if (visited[v]) continue;
    ans[v] = ans[idx];
    debug(ans);
    add_uekara(g, ad, ans, visited, v);
  }
}

int main() {
  int64 N, Q;
  cin >> N >> Q;
  vector<vector<int64>> g(N);
  int64 a, b;
  for (int64 i = 0; i < N - 1; i++) {
    cin >> a >> b;
    g[a - 1].push_back(b - 1);
    g[b - 1].push_back(a - 1);
  }
  debug(g);
  vector<int64> ans(N);
  int64 p, x;
  vector<int64> ad(N);
  for (int64 i = 0; i < Q; i++) {
    cin >> p >> x;
    ad[p - 1] += x;
  }
  debug(ad);
  vector<int64> visited(N);
  add_uekara(g, ad, ans, visited, 0);
  for (int64 i = 0; i < N; i++) {
    cout << ans[i] << ' ';
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 34408
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int height[10] = {0};
  for(int i=0; i<10; i++){
    cin >>height[i];
  }
  sort(height,height+10);
  cout <<height[9]<<endl<<height[8]<<endl<<height[7]<<endl;
  return 0;
}

Measured memory_bytes: 1176
#include<iostream>

int n,d,x;
int a[100], count = 0, s;

int main()
{
	std::cin >> n;
	std:: cin >> d >> x;
	for(int i = 0; i < n; i++)
	{
		std::cin >> a[i];
		for(int j = 0; j < 100; j++)
		{
			if(a[i] * j + 1 <= d)
			{
				count++;
			}
		}
	}
	std::cout << count + x << std::endl;
	return 0;
}

Measured memory_bytes: 760
//abc145C
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void) {
  int n, i,k,tmp=0;
  float sum=0;
  scanf("%d", &n);

  int x[n], y[n];
  for(i=0; i < n; i++){
    scanf("%d %d", &x[i], &y[i]);
  }
  for(i=0;i<n;i++){
    tmp+=i;
    for(k=i+1;k<n;k++){
      sum+=sqrt(pow(x[i]-x[k],2)+pow(y[i]-y[k],2));
    }
  }
  printf("%f",sum*(n-1)/tmp);
}


Measured memory_bytes: 128
X,N=[int(x) for x in input().rstrip().split()]
p=[int(x) for x in input().rstrip().split()]
nai=[]
for i in range(0,102):
  if i not in p:
    nai.append(i)

nai.append(X)
nai.sort()
ind = nai.index(X)
if abs(nai[ind-1]-X)<=abs(nai[ind+1]-X):
  print(nai[ind-1])
else:
  print(nai[ind+1])

Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
const bool debug=false;
#define DEBUG if(debug==true)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
string s;
int main(void) {
    cin >> s;
    int n=s.size();
    int cnt[2]={};
    rep(i,n){
        if(s[i]=='0')cnt[0]++;
        else cnt[1]++;
    }
    cout << min(cnt[0],cnt[1])*2 << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;
#define PI 3.14159265
	
int main(void){
	double a,b,rad;
	double S,L,h;
	cin>>a>>b>>rad;
	rad=rad*PI/180;
	S = a*b*sin(rad)/2.0;
	L = a + b + sqrt(a*a+b*b-2*a*b*cos(rad));
	h = 2*S/a;
	cout.precision(8);
	cout<<fixed<<S<<" "<<L<<" "<<h<<endl;
	return 0;
}

Measured memory_bytes: 1288
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const int INF = 1e9;


int N, Q;
vector<int> G[200000];
bool used[200000];
int cnt[200001];
int ans[200000];

void dfs(int u, int c) {
    ans[u] = c;
    used[u] = true;
    for (int i = 0; i < G[u].size(); i++) {
        if (!used[G[u][i]]) dfs(G[u][i], c+cnt[G[u][i]]);
    }
}

int main() {
    
    cin >> N;
    cin >> Q;
    for (int i= 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    //cnt[0] = 0;
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        cnt[p-1] += x;
    }

    dfs(0,cnt[0]);
    for (int i = 0; i < N; i++) {
        cout << ans[i] << " ";
    } cout << endl;


    
}


Measured memory_bytes: 24192
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n;
    cin >> n;
    int b1 = 0,b2 = 0,b4 = 0;
    rep(i,n) {
        int a;
        cin >> a;
        if(a%4==0) {
            b4++;
        } else if(a%2 == 0) {
            b2++;
        } else b1++;
    }
    if(b2 == 0) {
        if(b1<=b4+1) cout << "Yes" << endl;
        else cout << "No" << endl;
        return 0;
    } else {
        if(b1<=b4) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll s; cin >> s;
    ll roots = ceil(pow(s, 0.5));
    ll zan = roots*roots - s;
    ll ax = -1; ll ay = -1; ll bx = -1; ll by = -1; ll cx= -1; ll cy = -1;
    ax = 0;
    by = 0;
    if (zan<roots){
        cx = cy = roots;
        ay = roots - 1;
        bx = roots - zan;
    } else if (zan%2 == 0){
        cx = cy = roots;
        ay = roots - 2;
        bx = roots - zan/2;
    } else {
        cx = roots + 1;
        cy = roots - 1;
        ll zan2 = cx*cy-s;
        ay = cy - 2;
        bx = cx - zan2/2;
    }
    cout << ax << " " << ay << " " << bx << " " << by << " " << cx << " " << cy << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  ll x;
  cin >> x;
  ll a = 100, count = 0; 
  
  while(a < x){
    a += a / 100;
    count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3636
import java.util.Scanner;

//Common Sub-String
public class Main{

	void run(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			char[] s = sc.next().toCharArray();
			char[] t = sc.next().toCharArray();
			int ns = s.length;
			int nt = t.length;
			int[][] dp = new int[ns][nt];
			for(int i=0;i<ns;i++)dp[i][0]=s[i]==t[0]?1:0;
			for(int j=0;j<nt;j++)dp[0][j]=s[0]==t[j]?1:0;
			int m = 0;
			for(int i=1;i<ns;i++){
				for(int j=1;j<nt;j++){
					dp[i][j] = s[i]==t[j]?dp[i-1][j-1]+1:0;
					m = Math.max(m, dp[i][j]);
				}
			}
			System.out.println(m);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

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

typedef long long ll;

using namespace std;

vector<int> v[2002];
int d[2002][2002], nr[2002];

void bfs(int x) {
	queue<int> q;
	q.push(x);
	while(!q.empty()) {
		int curr = q.front();
		q.pop();
		for(int i = 0; i < v[curr].size(); i++) {
			int nxt = v[curr][i];
			if (nxt == x || d[x][nxt] != 0) continue;
			d[x][nxt] = d[x][curr] + 1;
			q.push(nxt);
		}
	}
	
}

int main() {
	int n, x, y; cin >> n >> x >> y;
	for(int i = 1; i < n; i++) {
		v[i].push_back(i+1);
		v[i+1].push_back(i);
	}
	v[x].push_back(y);
	v[y].push_back(x);
	for(int i = 1; i <= n; i++) {
		bfs(i);
	}
	for(int i = 1; i <= n; i++) {
		for (int j = i+1; j <= n; j++) {
			nr[d[i][j]]++;
		}
	}
	for(int i = 1; i < n; i++) {
		cout << nr[i] << endl;
	}
}





Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second 

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

// End of template code!
int main() 
{
    buff();
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
    return 0;
}



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

int main()
{	
	int n, m;
	std::cin >> n;
	int* A = new int[n];
	for (int i=0; i<n; i++) std::cin >> A[i];
	std::cin >> m;
	int* B = new int[m];
	for (int i=0; i<m; i++) std::cin >> B[i];
	
	int* C = new int[n+m];
	for (int i=0; i<n+m; i++) C[i] = -1;
	std::set_symmetric_difference(A, A+n, B, B+m, C);
	
	for (int i=0; i<n+m; i++) {
		if (C[i] < 0) break;
		std::cout << C[i] << std::endl;
	}
	
	delete[] A;
	delete[] B;
	delete[] C;
	
	return 0;
}



Measured memory_bytes: 5940
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int r = sc.nextInt();
      int d = sc.nextInt();
      int x = sc.nextInt();
      int ans = x;

      for (int i = 0;i<10 ;i++ ) {
        ans = r*ans-d;
        System.out.println(ans);
      }


  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
      int n;
      cin>>n;
      int a[n+10];
      map<int,int>m;
      for(int i=0;i<n;i++)
      {
            cin>>a[i];
            m[a[i]-1]+=1;
            m[a[i]]+=1;
            m[a[i]+1]+=1;
      }
      int res=1;
      for(int i=0;i<n;i++)
      {
            res=max(res,max(m[a[i]],max(m[a[i]-1],m[a[i]+1])));
      }
      cout<<res;
      return 0;
}

Measured memory_bytes: 5120
import sys

def main():
  input = sys.stdin.readline
  N = int(input())
  
  ans = 'No'
  if N % 7 == 0:
    ans = 'Yes'
  else:
    for i in range(N//7+ 1):
      m = N - 7 * i
      if m % 4 == 0:
        ans = 'Yes'
        break
  
  print(ans)


if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
n=int(input())
a=[0]*n
x=[[0]*n for i in range(n)]
y=[[0]*n for i in range(n)]
for i in range(n):
  a[i]=int(input())
  for j in range(a[i]):
    x[i][j],y[i][j]=map(int,input().split())
ans=0
for bit in range(1<<n):
  res=True
  for i in range(n):
    if bit & (1<<i):
      for j in range(a[i]):
        if ((bit>>(x[i][j]-1))&1)^y[i][j]:
          res=False
  if res:
    wklen=len(str(format(bit,"b")).replace("0",""))
    ans = ans if ans>=wklen else wklen
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vec = vector<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
	int n, m;
	cin >> n >> m;
	int ans = (n*(n-1) + m*(m-1)) / 2;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    string t; cin >> t;
    int n = 0, w = 0, s = 0, e = 0;
    each(c, t) {
        if (c == 'N')++n;
        else if (c == 'W')++w;
        else if (c == 'S')++s;
        else ++e;
    }

    chmin(n, 1);
    chmin(w, 1);
    chmin(e, 1);
    chmin(s, 1);

    if ((n ^ s) == 1)cout << "No\n";
    else if ((w ^ e) == 1)cout << "No\n";
    else cout << "Yes\n";
}

Measured memory_bytes: 256
def maximize_the_formula(A: int, B: int, C: int) -> int:
    x, y, z = sorted([A, B, C], reverse=True)
    return 10 * x + y + z


if __name__ == "__main__":
    A, B, C = map(int, input().split())
    ans = maximize_the_formula(A, B, C)
    print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
    cin>>s>>t;
  int a=0,i;
  for(i=0;i<3;i++)
  {
    if(s[i]==t[i])a=a+1;
  }
  cout<<a;
  return 0;
}

Measured memory_bytes: 256
object Main extends App {

  val SENTINEL = 10000000001L

  def sliceAndTerminate(a: Array[Long], from: Int, until: Int) = {
    val n = until - from
    val ret = new Array[Long](n + 1)
    compat.Platform.arraycopy(a, from, ret, 0, n)
    ret(n) = SENTINEL
    ret
  }

  def merge(a: Array[Long], left: Int, mid: Int, right: Int) = {
    val l = sliceAndTerminate(a, left, mid)
    val r = sliceAndTerminate(a, mid, right)

    def loop(i: Int, j: Int, k: Int): Unit = {
      if (k < right) {
        if (l(i) <= r(j)) {
          a(k) = l(i)
          loop(i+1, j, k+1)
        } else {
          a(k) = r(j)
          loop(i, j+1, k+1)
        }
      }
    }

    loop(0, 0, left)
    right - left
  }

  def mergeSort(a: Array[Long], left: Int, right: Int): Int = {
    if (left + 1 < right) {
      val mid = (left + right) / 2
      mergeSort(a, left, mid) +
      mergeSort(a, mid, right) +
      merge(a, left, mid, right)
    } else 0
  }


  val sc = new java.util.Scanner(Console.in)

  def readInt() = sc.next().toInt
  def readLong() = sc.next().toLong

  val ary = Array.fill(readInt())(readLong())
  val n = mergeSort(ary, 0, ary.length)
  println(ary mkString " ")
  println(n)
}


Measured memory_bytes: 402872
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();

		if((h==2)||(w==2))System.out.println("No");
		else System.out.println("Yes");
	}

}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n,k;string s;
  cin>>n>>s>>k;k--;
  for(int i=0;i<n;i++){
    if(s[i]!=s[k])s[i]='*';
  }
  cout<<s;
}

Measured memory_bytes: 256
import sys
red=lambda a:"".join(map(str,[(int(a[i])+int(a[i+1]))%10 for i in range(len(a)-1)]))
tl=[]
l=[i.strip() for i in sys.stdin]

for i in l:
    while len(i) != 1:
        i=red(i)
    tl.extend([int(i)])
[print(i) for i in tl]



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;


int main(){
    int N;cin>>N;
    vector<string> W(N);
    bool ok=true;
    for(int i=0;i<N;i++){
        cin>>W[i];
        if(i>=1){
            if(W[i-1][W[i-1].size()-1]!=W[i][0]){
                ok=false;
            }
        }
    }
    sort(ALL(W));
    for(int i=1;i<N;i++){
        if(W[i-1]==W[i]){
            ok=false;break;
        }
    }
    cout<<(ok?"Yes":"No")<<endl;
}

Measured memory_bytes: 3652
N, K = map(int, input().split())
h = list(map(int, input().split()))

cost = [0 for _ in range(N)]
K = min(N, K)
for i in range(1,K):
    cost[i] = abs(h[0] - h[i])
    
for i in range(1,N):
    t = max(0, i - K)
    for j in range(t,i):
        if j == t:
            cost[i] = cost[j] + abs(h[i] - h[j])
        else:
            cost[i] = min(cost[i], cost[j] + abs(h[i] - h[j])) 
    
print(cost[-1])

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

using namespace std;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define SI(n) scanf("%d",&n)
#define PI(n) printf("%d\n",n)
#define SL(n) scanf("%lld",&n)
#define PL(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE

#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
typedef long long int 	LL;
typedef long double 	LD;
typedef pair<int,int>   II;
typedef vector<int>     VI;
const int MOD = 1e9 + 7;
const int N = 311;
int a[N][N], s[N];
bool b[N];

II compMax(int *s, int n, int m) {
    int cnt[N] = {0}, mx = 0;
    for(int i = 1; i <= n; ++i)
        cnt[s[i]]++;
    int ind = 0;
    for(int i = 1; i <= m; ++i) {
        if(mx < cnt[i]) mx = cnt[i], ind = i ;
    }
    return MP(ind, mx);
}

int main() {
    int n, m;
    SI(n), SI(m);
    for(int i = 1;i <= n; ++i) {
        for(int j = 1;j <= m; ++j) {
            SI(a[i][j]);
        }
    }

    int ans = 1e9;
    while(1) {
        memset(s, 0, sizeof(s));
        for(int i = 1;i <= n; ++i)
            for(int j = 1;j <= m; ++j) {
                if(!b[a[i][j]] and !s[i]) s[i] = a[i][j]; 
            }
        auto it = compMax(s, n, m);
        if(b[it.F] || !it.F) break;
        b[it.F] = 1;
        ans = min(ans, it.S);
    }
    PI(ans);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI atan(1)*4
typedef long long int ll;
using namespace std;
bool vis[105];
int main(){
	io;
	int n,k;
	memset(vis,0,sizeof(vis));
	cin >> n >> k;
	for(int i = 0;i < k;++i){
		int d;
		cin >> d;
		for(int j = 0;j < d;++j){
			int t;
			cin >> t;
			vis[t] = 1;
		} 
	}
	int coun = 0;
	for(int i = 1;i <= n;++i){
		if(vis[i] == 0){
			coun += 1;
		}
	}
	cout << coun;
	return 0;
} 

Measured memory_bytes: 3664
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	while(true){
		int N=in(),M=in();
		if(!N && !M) break;
		list<int> P(N);
		iota(ALL(P),1);
		int pos=N-1;
		REP(i,N-1){
			pos = (pos+M+N-i)%(N-i);
			auto itr = P.begin();
			advance(itr,pos);
			P.erase(itr);
			pos--;
		}
		out(P.front());
	}

	return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

#define loop(i, a, b) for(int i = a; i < b ; i++)
#define rep(i, a) loop(i, 0, a)
#define MAX 50022

int main()
{
  bool prime[MAX];
  rep(i, MAX) prime[i] = true;
  prime[0] = prime[1] = false;
  loop(i, 2, sqrt(MAX)){
    for(int j = i * 2; j < MAX; j += i){
      prime[j] = false;
    }
  }
  
  int n;
  while(cin >> n) {
    for(int j = n - 1; j > 1; j--) if(prime[j] == true) {cout << j << ' '; break;}
    loop(i, n + 1, MAX)            if(prime[i] == true) {cout << i << endl; break;}
  }
}

Measured memory_bytes: 1208
/*
  Vivek Rathi
  CSE 2nd Year
  MNNIT
*/
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define ll long long int
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define present(c,x) ((c).find(x) != (c).end())
#define null NULL
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 1e18
#define flush fflush(stdout);
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}
//-------------------------------Template--Above------------------------------------------------


int main()
{
	boost
	ll n,d;
	cin>>n>>d;
	ll a[n][d];
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<d;j++)
		{
			cin>>a[i][j];
		}
	}
	ll co=0;
	for(ll i=0;i<n;i++)
	{
		for(ll j=i+1;j<n;j++)
		{
			ll sum=0;
			for(ll k=0;k<d;k++)
			{
				sum+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
			}
			if(((ll)sqrt(sum))*((ll)sqrt(sum))==sum)
			{
				co++;
			}
		}
	}
	cout<<co<<endl;
	return 0;
}


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

using namespace std;

struct Dsu {
    int n;
    vector<int> p;
    
    Dsu(int _n) { n = _n; p.resize(n); init(); }
    inline void init() {
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
    }
    inline int find(int x) {
        return p[x] == x ? x: p[x] = find(p[x]);
    }
    inline bool join(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        p[y] = x; return true;
    }
    inline bool check(int x, int y) {
        return find(x) == find(y);
    }
};

struct Edge {
    int u, v, cost;
    Edge() {}
    Edge(int _u, int _v, int _cost) : u(_u), v(_v), cost(_cost) {}
    bool operator<(const Edge& _oth) const {
        return cost<_oth.cost;
    }
};

void solve() {
    int n; cin >> n;
    vector<pair<int, int>> a(n);
    for (auto& p: a) {
        cin >> p.first >> p.second;
    }
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    n = a.size();
    vector<Edge> es;
    for (int i = 1; i < n; i++) {
        es.emplace_back(i-1, i, a[i].first-a[i-1].first);
    }
    vector<int> id(n);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](auto& u, auto& v){
        return a[u].second < a[v].second;
    });
    for (int i = 1; i < n; i++) {
        int i0 = id[i-1], i1 = id[i];
        es.emplace_back(i0,i1, a[i1].second - a[i0].second);
    }

    sort(es.begin(), es.end());
    Dsu d(n);
    long long res = 0;
    for (auto& e: es) {
        if (!d.check(e.u, e.v)) {
            d.join(e.u, e.v);
            res += e.cost;
        }
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 6004
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n, k, s, t;
    std::cin >> n >> k >> s >> t;
    std::vector<std::vector<long long>> C(n + 1, std::vector<long long>(n + 1));
    for (int i = 0; i <= n; ++i) {
        C[i][0] = 1;
        for (int j = 1; j <= i; ++j)
            C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
    }
    for (int i = 0; i <= n; ++i)
        for (int j = 2; j <= n; ++j)
            C[i][j] += C[i][j - 1];
    std::vector<int> a;
    for (int i = 0; i < n; ++i) {
        int x;
        std::cin >> x;
        if ((x & s) == s && (x | t) == t)
            a.push_back(x);
    }
    n = a.size();
    long long ans = 0;
    int c[1 << 18] = {};
    for (int v = 0; v < (1 << 18); ++v) {
        if ((v & s) != s || (v | t) != t)
            continue;
        long long res = 0;
        for (int i = 0; i < n; ++i)
            ++c[a[i] & v];
        for (int i = 0; i < n; ++i) {
            if (c[a[i] & v]) {
                res += C[c[a[i] & v]][k];
                c[a[i] & v] = 0;
            }
        }
        ans += (__builtin_parity(v ^ s) ? -1 : 1) * res;
    }
    std::cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4700
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
const ll MOD = 1000000007;
void Main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    For(i,0,n) cin >> a[i];
    ll sm = accumulate(ALL(a), 0LL);
    sm %= MOD;
    sm *= sm;
    sm %= MOD;
    ans += sm;
    for(auto i:a){
        ans -= i * i % MOD;
        ans %= MOD;
        ans += MOD;
        ans %= MOD;
    }
    ans *= 500000004;
    ans %= MOD;
    cout << ans << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 4836
from collections import deque

def inside(x, l, r):
    return l <= x < r

if __name__ == '__main__':
    h, w = map(int, input().split())

    a = []
    for i in range(h):
        a.append(list(input()))

    qu = deque()
    
    nokori = h*w
    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                nokori -= 1
                qu.append((i, j))

    ans = 0
    dx = [0, 1, 0, -1]
    dy = [1, 0, -1, 0]
    while True:
        if nokori == 0:
            break
        ans += 1
        qu2 = deque()
        while len(qu) > 0:
            i0, j0 = qu.popleft()
            for k in range(4):
                ni = i0 + dx[k]
                nj = j0 + dy[k]
                if not (inside(ni, 0, h) and inside(nj, 0, w)):
                    continue
                if a[ni][nj] == '.':
                    a[ni][nj] = '#'
                    nokori -= 1
                    qu2.append((ni, nj))
        qu = qu2
    print(ans)


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

const int MAX = 100000;
const int maxnum = 1000000010;
struct Card {
	char suit;
	int value;
};

Card L[MAX / 2 + 2], R[MAX / 2 + 2];

// ??????????????¶
void merge(Card A[], int n,int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	for (int i = 0; i < n1; i++) {
		L[i].suit = A[left + i].suit;
		L[i].value = A[left + i].value;
	}
	for (int i = 0; i < n2; i++) {
		R[i].suit = A[mid + i].suit;
		R[i].value = A[mid + i].value;
	}

	// ???????±???¨??°?????????????????????????????§?????°
	L[n1].value = R[n2].value = maxnum;
	int i = 0, j = 0;
	// ?????¶
	for (int k = left; k < right; k++) {
		if (L[i].value <= R[j].value)
			A[k] = L[i++];
		else
			A[k] = R[j++];
	}
}
// ??????
void mergeSort(Card A[], int n, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, n ,left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}

// ??????
int partition(Card A[],int p, int r) {
	Card x = A[r];
	int i = p - 1;
	for (int j = p; j < r; j++) {
		if (A[j].value <= x.value) {
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}

// ????????????
void quickSort(Card A[], int p, int r) {
	int q;
	if (p < r) {
		q = partition(A, p, r);
		quickSort(A, p, q - 1);
		quickSort(A, q + 1, r);
	}
}

// ?????¶?????????????¨?????????????????????????????????±????????¶?????????????????\?????????????¨???????
bool isStable(struct Card C1[], struct Card C2[], int n) {
	for (int i = 0; i < n; i++) {
		if (C1[i].suit != C2[i].suit)
			return false;
	}
	return true;
}
Card C1[MAX], C2[MAX];
int main() {
	int n;
	scanf("%d", &n);
	getchar();
	for (int i = 0; i < n; i++) {
		scanf("%c %d", &C1[i].suit, &C1[i].value);
		getchar();
		C2[i] = C1[i];
	}
	// ??????C1??°???????????????????????????C2??°??????????????????????????¶?????????????????????????????±???
	// ???????????\???????????????????¨????
	mergeSort(C1, n, 0 ,n);
	quickSort(C2, 0, n -1);

	if (isStable(C1, C2, n))
		printf("Stable\n");
	else
		printf("Not stable\n");

	for (int i = 0; i < n; i++)
		printf("%c %d\n", C2[i].suit, C2[i].value);
	return 0;
}

Measured memory_bytes: 5456
N=int(input())
S1=input()
S2=input()
pr=10**9+7
t=0
a=1
c=0
while t<N:
    if S1[t]==S2[t]:
        a=a*(3-c)%pr
        t+=1
        c=1
    else:
        if c==0:
            a=6
        elif c==1:
            a=a*2%pr
        else:
            a=a*3%pr
        t+=2
        c=2
print(a)

Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    S = input().strip()

    ans = []
    for s in S:
        if s == '?':
            ans.append("D")
        else:
            ans.append(s)

    print("".join(ans))

    
    

if __name__ == '__main__':
    main()



Measured memory_bytes: 10900
n=int(input())
s=[input()for _ in range(n)]
def check(s,t):
  for i in range(n):
    for j in range(n):
      if s[(i+t)%n][j]!=s[(j+t)%n][i]:return False
  return True
ans=0
for i in range(n):
  if check(s,i):ans+=n
print(ans)

Measured memory_bytes: 42032
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	unsigned long a, b, n, tmp, ans, i, j, k;
	cin >> n >> a >> b;
	i = n / (a + b);
	ans = a * i;
	tmp = n - i * (a + b);
	ans += min(tmp, a);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define forr(i, b, e)     for(int i = b; i < e; i++)
#define forg(i, b, e, m)  for(int i = b; i < e; i+=m)
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
#define tam 2200
typedef pair<ii,int> iii;
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    string txt1,txt2;
    txt1="RUD";
    txt2="LUD";
    string txt;
    cin>>txt;
    bool nop=false;
    forr(i,0,txt.size())
    {
        if (i%2==0)
        {
            if (txt1.find(txt[i])==-1)
                nop=1;
        }
        else
        {
            if (txt2.find(txt[i])==-1)
                nop=1;
        }
    }
    if (nop)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}
// PLUS ULTRA!


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

int main(){

	long long a,b,c=1ll;
	scanf("%lld %lld",&a,&b);

	if(a>b)swap(a,b);
	long long d=b;
	for(long long i=2;i*i<=b;i+=(i==2?1:2)){
		if(d%i==0){
			while(d%i==0){d/=i;}
			if(a%i==0)c++;
		}
	}
	if(d!=1 && a%d==0)c++;

	printf("%lld\n",c);
}

/*
128+4+1 -> 10000101
10110110
0.25+0.0625 = 0.3125
11.001001 (0.125)
128+32+8+4 -> 10101100 
*/

Measured memory_bytes: 256