akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprev(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

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

    rep(i, n)
    {
        cin >> j;
        if (j % 2 == 0)
        {
            if ((j % 3 == 0 || j % 5 == 0))
            {
            }
            else
            {
                cout << "DENIED" << endl;
                return (0);
            }
        }
    }
    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int N; cin >> N; int sum= 0;
  rep(i, N){
    int a; cin >> a; sum += a;
  }
  cout << sum-N << endl;
 }
     

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

int main() {
   int N;
  int a,b,c;
  cin >> N;
  a = N/1000;
  N = N%1000;
  b = N/100;
  N = N%100;
  c = N/10;
  N = N%10;
  if(a == b){
     if(b == c){
    	cout << "Yes" << endl;
     }
 	 else{
    	cout << "No" << endl;
     }
   }
   else if(b == c){
     if(c == N){
     	cout << "Yes" << endl;
     }
     else{
        cout << "No" << endl;
     }
  }
  else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/**
 *      ABC 92 C
 *      author  : kyomukyomupurin
 *      created : 2018-08-30 18:20:12
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    vector<int> v;
    for (int i = 0; i < N; ++i) {
        int x; cin >> x;
        v.push_back(x);
    }

    int sum = 0;

    for (int i = 1; i < N; ++i) {
        sum += abs(v[i - 1] - v[i]);
    }
    sum = sum + abs(0 - v[0]) + abs(v[N - 1] - 0);//全部回ったときのコスト

    vector<int> diff;//iをスキップしたときに浮くコスト
    diff.push_back(abs(0 - v[0]) + abs(v[0] - v[1]) - abs(0 - v[1]));
    for (int i = 1; i < N - 1; ++i){
        diff.push_back(abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1]) - abs(v[i - 1] - v[i + 1]));
    }
    
    diff.push_back(abs(v[N - 2] - v[N - 1]) + abs(v[N - 1] - 0) - abs(v[N - 2] - 0));
    
    for (int i = 0; i < N; ++i) {
        cout << sum - diff[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

using ll = long long;
using namespace std;
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
ll M = 1000000007;
typedef pair<int, int> P;

typedef pair<ll, int> pli;

void solve()
{
   int n,k;
   cin>>n>>k;
    vector<double>a(n),b(n);
    vector<double>acc(n+1);
    double sum=0;
    rep(i,n){
        cin>>a[i];
        b[i]=(a[i]+1.0)/2.0;
        sum+=b[i];
        acc[i+1]=sum;
    }
    double ans=0;
    rep(i,n-k+1){
        ans=max(ans,acc[i+k]-acc[i]);
    }
    cout<<setprecision(11)<<ans<<endl;
}
// DPテーブル
int main()
{
    solve();
}

Measured memory_bytes: 4992
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  int t = 0,x = 0,y = 0;
  REP(i,n){
    int ti,xi,yi;
    cin >> ti >> xi >> yi;
    if(abs(ti - t) < (abs(xi - x)+abs(yi - y))){
	 cout << "No" << endl;
      return 0;
    }
    else{
      if((abs(ti - t)-abs(xi - x)-abs(yi - y)) % 2 == 0){
        t = ti;
        x = xi;
        y = yi;
        continue;
      }
      else{
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))


const int MOD = 1e+9+7;
const double PI  = acos(-1.0);

int main(){
    int n,num,tot=0;
    cin>>n;
    vi s;
    REP(i,n){
        cin>>num;
        s.push_back(num);
        tot+=num;
    }
    if(tot%10==0){
        sort(s.begin(), s.end());
        int i=0;
        while(i<n){
            if(s[i]%10!=0) break;
            i++;
        }
        if(i==n) tot=0;
        else tot-=s[i];
    }
    cout<<tot<<"\n";
}


Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)

l = []
o = []

n.times do 
    a,b = gets.split.map(&:to_i)
    l << a
    o << b
end

p = []
q = []
m.times do
    c,d = gets.split.map(&:to_i)
    p << c
    q << d
end

(0..n - 1).each do |i|
    k = 100000000000000
    point = 0
    (0..m - 1).each do |j|
        dist = (p[j] - l[i]).abs + (q[j] - o[i]).abs
        if dist < k
            point = j + 1
            k = dist
        end
    end
    puts point
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
 
#define MAXX 200010
 
#define PI   3.14159265358979323846264338327950
 
#define PB push_back 
#define F first
#define S second
 
#define fixx(n) fixed << setprecision(n)
 
#define ll 	  long long 
 
#define mod  1000000007
 
 
 
int main()
{
	FAST;
	ll n;
	cin >> n;
	ll a[n+5];
	ll ans = 0;
	for(ll i = 0; i < n; i ++){
		cin >> a[i];
	}
	for(ll i = 1; i < n; i ++){
		
		if(a[i] < a[i-1]){
			ans += a[i-1]-a[i];
			a[i] = a[i-1];
		}
		
	}
	cout << ans;
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int ansA = 0;
  int ansB = 0;
  int ans = 0;
  int mo = 1;
  
  for (int i=0; i<N; i++) {
    if (mo == 1) {
      if (S[i] == '0') {
        ansA++;
      }
    }
    else {
      if (S[i] == '1') {
        ansA++;
      }
    }
    mo = mo * -1;
  }
  
  mo = 1;
  for (int i=0; i<N; i++) {
    if (mo == 1) {
      if (S[i] == '1') {
        ansB++;
      }
    }
    else {
      if (S[i] == '0') {
        ansB++;
      }
    }
    mo = mo * -1;
  }
  
  ans = min(ansA,ansB);
  cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int R = sc.nextInt();
    int S = sc.nextInt();
    int P = sc.nextInt();   
    char[] t = sc.next().toCharArray();
    int point = 0;
    for(int i = 0;i < k;i++){
      if(t[i] == 'r')  point += P;
      if(t[i] == 's')  point += R;
      if(t[i] == 'p')  point += S;
    }
    for(int j = k;j < n;j++){
      if(t[j] != t[j-k]){
        if(t[j] == 'r')  point += P;
        if(t[j] == 's')  point += R;
        if(t[j] == 'p')  point += S;
      }else if(j + k < n){
        if(t[j] == 'r' && t[j+k] == 'r') t[j] = 's';
        if(t[j] == 's' && t[j+k] == 's') t[j] = 'p';
        if(t[j] == 'p' && t[j+k] == 'p') t[j] = 'r';  
      } 
    }  
    System.out.println(point);
  }
}

Measured memory_bytes: 28584
#include <bits/stdc++.h>
using namespace std;
#define __ <<' '<<
#define ___ <<' '
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {IoSetup() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout <<fixed<<setprecision(12);
    cerr <<fixed<<setprecision(12);
}}IoSetup;

using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int SMOD = 1000000007;
constexpr int NMOD = 998244353;
constexpr int dx[]={1,0,-1,0,1,1,-1,-1};
constexpr int dy[]={0,1,0,-1,-1,1,-1,1};

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



signed main() {

    string s;
    cin >> s;

    cout << s[0] + s[1] + s[2] - '0' * 3 << endl;


  
    return 0;
}



Measured memory_bytes: 256
# DP
def main():
    N, W = map(int, input().split())
 
    dp = [-1] * (W + 1)
    dp[0] = 0
    for _ in range(N):
        w, v = map(int, input().split())
        for i in range(W - w, -1, -1):
            if dp[i] == -1:
                continue
            if dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v
    print(max(dp))
 
 
main()

Measured memory_bytes: 9640
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9+7;
long long int s[200005];
int main(){
    int n;
    cin >> n;
    long long int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        s[i+1]=(s[i]+a[i])%mod;
    }
    long long int ans=0;
    long long int tmp;
    for(int i=0;i<n-1;i++){
        tmp = (a[i]*(s[n]-s[i+1]+mod))%mod;
        ans += tmp%mod;
        ans %= mod;
    }
    cout << ans;
}

Measured memory_bytes: 6712
#include <iostream>

using namespace std;

int gole, X, Y;
int map[15][15];

bool check(int x, int y, int flag) { // flag: ツ陳シツ進ツつオツづつォツつスツつゥ
	if (x < 0 || x >= X) return false;
	if (y >= Y) { gole += flag; return false; }
	if (map[y][x] == 1) return false;
	if (!flag && map[y][x] == 2) return false;
	return true;
}

int main() {
	while (cin >> X >> Y, X || Y) {
		int pattern[15][15] = {0};
		gole = 0;
		for (int y = 0; y < Y; ++y)
			for (int x = 0; x < X; ++x)
				cin >> map[y][x];

		for (int x = 0; x < X; ++x)
			if (map[0][x] == 0)
				pattern[0][x] = 1;

		for (int y = 1; y < Y; ++y)
			for (int x = 0; x < X; ++x) {
				if (map[y-1][x] == 0) {
					if (check(x-1, y, false)) pattern[y][x-1] += pattern[y-1][x];
					if (check(x,   y, true))  pattern[y][x]   += pattern[y-1][x];
					if (check(x+1, y, false)) pattern[y][x+1] += pattern[y-1][x];
				}
				else if (map[y-1][x] == 1) continue;
				else if (check(x, y+1, pattern[y-1][x])) pattern[y+1][x] += pattern[y-1][x];
			};

		for (int x = 0; x < X; ++x) gole += pattern[Y-1][x];

		cout << gole << endl;
	}
	return 0;
}

Measured memory_bytes: 0
<?php
fscanf(STDIN, "%d %d", $N, $x);
$a = array_map('intval', explode(" ", trim(fgets(STDIN))));
$ans = PHP_INT_MAX;
for ($k = 0; $k < $N; $k++) {
    for ($i = 0; $i < $N; $i++) {
        if ($k === 0) {
            $b[0][$i] = $a[$i];
        } else {
            $b[$k][$i] = min($b[$k - 1][$i], $a[($i - $k + $N) % $N]);
        }
    }
    $ans = min($ans, array_sum($b[$k]) + $k * $x);
}
echo $ans;


Measured memory_bytes: 141816
s = input().rstrip()

concurrent_BC_cnt = 0
old1 = ""
cnt = 0
for tmp in (reversed(s)):
	if tmp == "A":
		if old1 == "B":
			cnt += concurrent_BC_cnt
		else:
			concurrent_BC_cnt = 0
			old1 = "A"
		# if "A" not update old1
	else:
		if tmp == "B" and old1 == "C":
			concurrent_BC_cnt += 1
		elif tmp == "C" and old1 == "B":
			pass
		else:
			concurrent_BC_cnt = 0
			
		old1=tmp
	
print(cnt)

Measured memory_bytes: 40800
//https://atcoder.jp/contests/agc008/tasks/agc008_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-3.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#endif
    ll x,y; cin>>x>>y;
    ll ans=INT64_MAX;
    if(x==y){
        ans=0;
    }else{
        //すすんで、-おす
        ll tmp=-y-x;
        if(tmp>=0) ans=min(tmp+1,ans);
        //-おす、すすんで、-おす
        tmp=x-y;
        if(tmp>=0) ans=min(tmp+2,ans);
        //-おして、すすむ
        tmp=y-(-x);
        if(tmp>=0) ans=min(tmp+1,ans);

        //すすむだけ
        tmp=y-x;
        if(tmp>=0) ans=min(tmp,ans);
        //-おす、すすんで、-おす
        //tmp=x-y;
        //if(tmp>=0) ans=min(tmp+2,ans);
        //-おして、すすむ
        //tmp=y-(-x);
        //if(tmp>=0) ans=min(tmp+1,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int AB, BC, CA; cin >> AB >> BC >> CA;
    cout << AB * BC / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " ="; for(auto it : x) {cerr << " [" <<  it << "]";} cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18 + 100;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vector<ld> p(n + 1);
	vector<vector<ld>> dp(n + 1, vector<ld>(n + 1));
	dp[0][0] = 1;
	for(int i = 1;i <= n;++i){
		cin >> p[i];
		for(int qan = 0;qan <= i;++qan){
			if(qan > 0){
				dp[qan][i - qan] += dp[qan - 1][i - qan] * p[i];
			}
			if(i != qan){
				dp[qan][i - qan] += dp[qan][i - qan - 1] * (1 - p[i]);
			}
		}
	}
	ld answer = 0;
	for(int qan = 0;qan <= n;++qan){
		if(qan > n - qan){
			answer += dp[qan][n - qan];
		}
	}
	cout << answer << '\n';
	return 0;
}


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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

const long long mod = 1000000007;

i64 sum(i64 n){
    return (n + 1) * n / 2;
}

void solve(long long N, long long K){
    i64 ans = 0;
    rep(i, K, N + 2){
        ans = (ans + sum(N) - sum(N - i) - sum(i - 1) + 1) % mod;
    }
    cout << ans << endl;
}

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

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    solve(N, K);
    return 0;
}


Measured memory_bytes: 3764
#include<iostream>
#include<math.h>
#include<iomanip>

using namespace std;

int main()
{
    int n;
    int score[1001];

    while(cin>>n&&n)
    {
        double average=0;
        for(int i=0;i<n;i++)
        {
            cin>>score[i];
            average+=score[i];
        }
        average/=n;
        double ans=0;

        for(int i=0;i<n;i++)
        {
            ans+=(score[i]-average)*(score[i]-average);
        }
        ans=sqrt(ans/n);
        cout<<fixed<<setprecision(5)<<ans<<endl;
    }
}



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

using namespace std;

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

void solve(int A, int B) {
  cout << ((A < 10 && B < 10) ? A * B : -1) << endl;
}

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

  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N, C; cin >> N >> C;
    int D[C+1][C+1];
    for(int i=1; i<=C; i++){
        for(int j=1; j<=C; j++) cin >> D[i][j];
    }

    map<int, int> zero, one, two;

    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            int c; cin >> c;
            if((i+j)%3 == 0) zero[c]++;
            if((i+j)%3 == 1) one[c]++;
            if((i+j)%3 == 2) two[c]++;
        }
    }

    ll ans = 25000000000;
    for(int i=1; i<=C; i++){
        for(int j=1; j<=C; j++){
            if(i == j) continue;
            for(int k=1; k<=C; k++){
                if(i == k || j == k) continue;

                //zeroの色をiに、oneの色をjに、twoの色をkにする
                ll tmp = 0;
                for(int color=1; color<=C; color++){
                    tmp += zero[color]*D[color][i];
                    tmp += one[color]*D[color][j];
                    tmp += two[color]*D[color][k];
                }

                ans = min(ans, tmp);
            }
            
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=list(map(int,input().split()))
def gcd(a,b):
    if b==0:
        return a
    return gcd(b, a%b)
if N==1:
    print("POSSIBLE" if K==A[0] else "IMPOSSIBLE")
    exit()
element=gcd(A[0], A[1])
if N!=2:
    for _ in range(2, N):
        element=gcd(element, A[_])

print("POSSIBLE" if K%element==0 and max(A)>=K else "IMPOSSIBLE")

Measured memory_bytes: 14104
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

void combinit(){
	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 comb(int n, int k){
	if(n<k) return 0;
	if(n<0 || k<0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
	int n;
	scanf("%d", &n);
	int a[n+1], c[n+1] = {}, w;
	REP(i, 0, n+1){
		scanf("%d", &a[i]);
		c[a[i]]++;
		if(c[a[i]]>1) w = a[i];
	}

	int cnt[3] = {}, pos = 0, tmp = 0;;
	REP(i, 0, n+1){
		if(a[i]==w){
			cnt[pos] = tmp;
			pos++;
			tmp = 0;
		} else tmp++;
	}
	cnt[pos] = tmp;

	combinit();
	REP(i, 1, n+2){
		ll ans = comb(n+1, i) - comb(cnt[0]+cnt[2], i-1);
		printf("%ld\n", (ans+MOD)%MOD);
		//printf("%ld %ld %ld\n", comb(n+1, i), comb(cnt[0]+cnt[2], i-1),  ans);
	}
	return 0;
}



Measured memory_bytes: 16460
#include<iostream>
#include<vector>
#include<string>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>
using namespace std;
int main(void){
    string a,b;
    cin>>a>>b;
    b.erase(b.size()-1);
    if(a==b){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

void solve(){
  int n, m; cin >> n >> m;
  vector<int> v(n + 1, 0);
  for(int i = 0; i < m; i++){
    int a, b; cin >> a >> b;
    v[a]++;
    v[b]++;
  }
  for(int i = 1; i <= n; i++){
    cout << v[i] << endl;
  }
  return;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
int main(){
  int n;
  //ostream_iterator<int> out_it(cout, " ");
  while(cin >> n){
    int b = 1;
    vector<int> ans;
    while(n > 0){
      if((n & 1) == 1){
	ans.push_back(b);
      }
      b <<= 1;
      n >>= 1;
    }
    //copy(ans.begin(), ans.end(), out_it);
    for(int i = 0; i < ans.size() - 1; ++i){
      cout << ans[i] << " ";
    }
    cout << ans.back() << endl;
  }
  return 0;
}

Measured memory_bytes: 1212
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define EPS 1e-9
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

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;}


signed main(void) {
    string s;
    int n;
    cin >> n;
    double a = 0, b = 0;
    loop(i,1,n+1){
        if(i%2)a+=1;
        else b+=1;
    }
    cout << shosu(10) << a/(a+b) << endl;
}


Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#ifndef ONLINE_JUDGE
#include "debug.cpp"
#endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int x; cin >> x;
  if(x>=30) cout << "Yes\n";
  else cout << "No\n";
  

  return 0;
}

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

int main() {
	char b;
	cin >> b;
	if (b=='A'){
		cout << 'T';
	}else if (b=='T'){
		cout << 'A';
	}else if (b=='C'){
		cout << 'G';
	}else if (b=='G'){
		cout << 'C';
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

ll a[200010];
ll s[200010];
//s[i]でiと描かれたボールの数

void solve(){


    ll n;
    cin >> n;
    rep(i,n+2){
        s[i]=0;
    }
    rep(i,n){
        cin >> a[i];
        s[a[i]]++; 
    }

    ll sum=0;
    rep(i,n+2){
        sum += (s[i]*(s[i]-1)/2);
    }

    rep(i,n){
        //cout << s[i] << " ";
    }
    //cout << endl;
    //cout << sum << endl;

    rep(i,n){
        ll p = s[a[i]];
        cout << sum - p*(p-1)/2 + (p-1)*(p-2)/2 << endl;
    }


}

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


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

void fnInput(vector<int>& rvnStage, int& rnJmpStage)
{
  int nStageSiz;
  cin >> nStageSiz >> rnJmpStage;
  rvnStage.resize(nStageSiz);

  for(int& rnStage : rvnStage)
    cin >> rnStage;
}
  
int fnDPCost(const vector<int>& cnrvnStage, int nJmpStage)
{
  vector<int> vnDPCost(cnrvnStage.size(), INT_MAX);
  vnDPCost[0] = 0;

  for (int i = 0; i < cnrvnStage.size() - 1; i++)
    for (int j = 1; j <= nJmpStage; j++)
      if (i + j < cnrvnStage.size())
        vnDPCost[i + j] = 
          min(vnDPCost[i + j], vnDPCost[i] + abs(cnrvnStage[i + j] - cnrvnStage[i]));
      else
        break;

  return vnDPCost[cnrvnStage.size() - 1];
}
  
int main()
{
  vector<int> vnStage;
  int nJmpStage;
  fnInput(vnStage, nJmpStage);
  cout << fnDPCost(vnStage, nJmpStage) << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include <bitset>

using namespace std;

int main(void){

  int h,w,k;
  cin >> h;
  cin >> w;
  cin >> k;
  const int mod=1000000007;

  vector< vector<uint64_t> > num(w,vector<uint64_t>(102,0));
  num[0][0]=1;

  for(int i=0;i<=h;i++){

    for(int j=0;j<w;j++){
      //num[j][i+1] = num[j][i];
      for(int k=0;k<(1 << (w-1));k++){

        bool check=true;
        for(int l=0;l<w-2;l++){
          if( (k >> l)&1 && (k >> l+1)&1 ) check=false;
        }

        if(!check) continue;

        if(j>=1 && (k >> (j-1))&1 ){
          num[j-1][i+1] += num[j][i];
          num[j-1][i+1] %= mod;
        }
        else if(j<= w-2 && ( k >> j )&1 ){
          num[j+1][i+1] += num[j][i];
          num[j+1][i+1] %= mod;
        }
        else{
          num[j][i+1] += num[j][i];
          num[j][i+1] %= mod;
        }

      }
      //cout << endl;
      //cout << num[j][i] << " ";
      //cout << log10(num[j][i]) << " ";
      //cout << endl;
      //num[j][i]%=(uint64_t)1000000007;

    }
    //cout << num[0][i] << endl;
    //cout << endl;
  }

  //cout << (uint64_t)(num[k-1][h]%(uint64_t)1000000007) << endl;
  cout << num[k-1][h] << endl;
  //uint64_t ans=num[k-1][h]%mod;
  //cout << ans << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> p_i;

#define rep(i, n) for (ll i = 0LL; i < n; i++)
#define repext(i, a, b) for (ll i = a; i < b; i++)
#define reprev(i, n) for (ll i = n - 1; i >= 0; i--)
#define repextrev(i, a, b) for (ll i = b - 1; i >= a; i--)

#define repv(v, values) for (auto v : values)

#define vec_all(vec) vec.begin(), vec.end()
#define sum(vec) accumulate(vec_all(vec), 0LL)
#define srt(vec) sort(vec_all(vec))
#define rev(vec) reverse(vec_all(vec))
#define revsrt(vec) \
    srt(vec);       \
    rev(vec)

// vectorデバッグ
template <typename T>
void dump_vec(vector<T> vec)
{
    rep(i, vec.size())
    {
        cout << i << ": " << vec[i] << endl;
    }
}

template <typename T, typename S>
void dump_dic(map<T, S> dic)
{
    for (auto v : dic)
    {
        cout << v.first << ": " << v.second << endl;
    }
}

// --- notice ---
// intの和はllにしろ

int main()
{
    int n, k;
    cin >> n >> k;
    vector<p_i> sort_dic;
    map<int, int> dic;
    int a;
    rep(i, n) {
        cin >> a;
        dic[a]++;
    }

    repv(v, dic) {
        sort_dic.push_back(p_i(v.first, v.second));
    }

    sort(vec_all(sort_dic), [](p_i p1, p_i p2){
        return p1.second < p2.second;
    });

    int needed = sort_dic.size() - k;

    if (needed < 0) {
        needed = 0;
    }

    int cnt = 0;
    rep(i, needed) {
        cnt += sort_dic[i].second;
    }

    cout << cnt << endl;

    return 0;
}

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

int main(void){
    int n,i,flag;
    flag = 0;
    cin >> n;

    vector<int> a(n);

    for(i=0; i<n; i++){
        cin >> a.at(i);
    }

    for(i=0; i<n; i++){
        if(a.at(i) % 2 == 0){
            if(a.at(i) % 3 == 0 || a.at(i) % 5 == 0){
                flag = 0;
            }else{
                flag = 1;
                break;
            }
        }
    }

    if(flag == 0){
        cout << "APPROVED" << endl;
    }else{
        cout << "DENIED" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    string s;
    cin >> s;
    cout << s.rfind('Z') - s.find('A') + 1 << endl;
}


Measured memory_bytes: 720
#include<iostream>
#include<sstream>
#include<queue>
#include<map>
using namespace std;

long swap(long x,int i,int j){
  long y = x;
  y = (y&~((15<<(i*4))|(15<<(j*4))))|((x>>(i*4))&15)<<(j*4)|((x>>(j*4))&15)<<(i*4);
  return y;
}

void pr(long x){
  for(int i=0; i<8; i++) cout << ((x>>(4*i))&15) << " ";
  cout << endl;
}

int main(){
  long finish = 0;
  for(int i=0; i<8; i++) finish += i<<(i*4);
  map<long, long long> count;
  queue<long> que;
  count[finish] = 0;
  que.push(finish);
  int n = 0;

  while(!que.empty()){
    n++;
    queue<long> next;
    while(!que.empty()){
      long y = que.front();
      que.pop();
      if((y&15)==0){
        next.push(swap(y,0,1));
        next.push(swap(y,0,4));
      }else if(((y>>4)&15)==0){
        next.push(swap(y,1,0));
        next.push(swap(y,1,2));
        next.push(swap(y,1,5));
      }else if(((y>>4*2)&15)==0){
        next.push(swap(y,2,1));
        next.push(swap(y,2,3));
        next.push(swap(y,2,6));
      } else if(((y>>4*3)&15)==0){
        next.push(swap(y,3,2));
        next.push(swap(y,3,7));
      } else if(((y>>4*4)&15)==0){
        next.push(swap(y,4,0));
        next.push(swap(y,4,5));
      } else if(((y>>4*5)&15)==0){
        next.push(swap(y,5,4));
        next.push(swap(y,5,6));
        next.push(swap(y,5,1));
      } else if(((y>>4*6)&15)==0){
        next.push(swap(y,6,5));
        next.push(swap(y,6,7));
        next.push(swap(y,6,2));
      } else if(((y>>4*7)&15)==0){
        next.push(swap(y,7,6));
        next.push(swap(y,7,3));
      } else{
        cout << "Error" << endl;
      }
    }
    while(!next.empty()){
      long y = next.front();
      next.pop();
      if(count.find(y) == count.end()){
        que.push(y);
        count[y] = n;
      }
    }
  }

  string line;
  while(getline(cin,line)){
    int a[8];
    istringstream s(line);
    long x = 0;
    for(int i=0; i<8; i++) s >> a[i];
    for(int i=0; i<8; i++) x += a[i]<<(4*i);
    cout << count[x] << endl;
  }
  return 0;
}

Measured memory_bytes: 4288
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>

using namespace std;



int main() {
    int r,d,x;
    cin>>r>>d>>x;
    
    for(int i =1;i<=10;i++){
        x=r*x-d;
        cout<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,a[200005],x;
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  x=a[1]^a[2];
  for(int i=3;i<=n;i++) x^=a[i];
  for(int i=1;i<=n;i++) cout<<(x^a[i])<<" ";
  return 0;
}

Measured memory_bytes: 5080
import numpy as np
n = int(input())
s = np.array([True if i=='E' else False for i in input()])
t = np.array([False if i else True for i in s])
t = np.cumsum(t)
t = np.hstack(([0], t[1:]))
s = np.cumsum(s[::-1])[::-1]
s = np.hstack((s[1:], [0]))
print(np.min(s+t))


Measured memory_bytes: 19780
class Dice:
    def __init__(self,list):
        self.list = []
        for i in range(6):
            self.list.append(list[i])

    def rotate(self,dir):
        if dir == "N":
            self.list[0], self.list[1], self.list[5], self.list[4] = self.list[1], self.list[5], self.list[4], self.list[0]
        elif dir == "S":
            self.list[0], self.list[4], self.list[5], self.list[1] = self.list[4], self.list[5], self.list[1], self.list[0]
        elif dir == "W":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[2], self.list[0], self.list[3], self.list[5]
        elif dir == "E":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        elif dir == "H":
            self.list[1], self.list[2], self.list[4], self.list[3] = self.list[2], self.list[4], self.list[3], self.list[1]
        elif dir =="V":
            self.list[0], self.list[3], self.list[5], self.list[2] = self.list[3], self.list[5], self.list[2], self.list[0]
        else:
            pass

    def show(self):
        print("D:{}".format(repr(self.list)))

    def isface(self,f):
        if f in self.list:
            return True
        else:
            return False

    def isSameface(self,b):
        for i in range(len(self.list)):
            if self.list[i] != b.list[i]:
                return False
        return True

    def isSame(self,b):
        for c in "zHHHWHHHEHHHEHHHWHHHWHHH":
            b.rotate(c)
            if self.isSameface(b):
                return True
        return False


def main():
    num = int(input())
    dice =[]
    for i in range(num):
        l = [int(x) for x in input().split()]
        dice.append(Dice(l))

    for i in range(num):
        for j in range(i+1,num):
            if dice[i].isSame(dice[j]):
                print("No")
                exit(0)

    print("Yes")


if __name__  == '__main__':
    main()



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

using namespace std;

using ll = long long;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int& x : a) {
    cin >> x;
  }

  int ans = 0;
  for(int x : a) {
      ans += x - 1;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
    int n;
    std::cin >> n;

    std::vector<int> A(n);
    for (int i = 0; i < n; i++) {
        A[i] = i + 1;
    }

    do {
        for (auto it = A.begin(); it < A.end(); it++) {
            if (it != A.begin()) std::cout << " ";
            std::cout << *it;
        }
        std::cout << std::endl;
    } while (std::next_permutation(A.begin(), A.end()));
}



Measured memory_bytes: 3128
#include<stdio.h>
int p[100010]={0};
int d[100010]={0};
int S[100010];//サイズ用配列 未実験
int Find(int a,int b){
  int r,n;
  for(r=++a;p[r];r=p[r]);
  for(;n=p[a];a=n)p[a]=r;
  for(r=++b;p[r];r=p[r]);
  for(;n=p[b];b=n)p[b]=r;
  return a-b?1:0;
}
long long Union(int a,int b){
  long long r=0;
  if(Find(a,b)){
    for(++a;p[a];a=p[a]);
    for(++b;p[b];b=p[b]);
    d[a]<d[b]?(p[a]=b):(p[b]=a);
    if(d[a]==d[b])d[a]++;
    r=1LL*S[a]*S[b];
    S[a]=S[b]=S[a]+S[b];
  }
  return r;
}
int main(){
  long long n,m,i,a[100010],b[100010],c[100010];
  scanf("%lld %lld",&n,&m);
  c[m-1]=n*(n-1)/2;
  for(i=0;i<100010;i++)S[i]=1;
  for(i=0;i<m;i++)scanf("%lld %lld",&a[i],&b[i]);
  for(i=m;i--;)c[i-1]=c[i]-Union(a[i],b[i]);
  for(i=0;i<m;i++)printf("%lld\n",c[i]);
  return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int>v(n),c(n);
    for(int i=0;i<n;i++)cin>>v[i];
    for(int i=0;i<n;i++)cin>>c[i];
    int ans=0;
    for(int i=0;i<n;i++){
        if(v[i]>c[i])ans+=v[i]-c[i];
    }
    cout<<ans;
}

Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

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

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//円周率
const double PI = 3.14159265358979323846;

int main() {
	char a, b; cin >> a >> b;

	if (a == 'H') cout << b << endl;
	else {
		if (b == 'H')cout << 'D' << endl;
		else cout << 'H' << endl;
	}
}

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

using ll = long long;

const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    char ch;
    cin >> ch;
    putchar(ch + 1);
    putchar('\n');
}

Measured memory_bytes: 256
primes=[False for i in range(1000000)]
ps=[]
for i in range(2,1000000):
    if not primes[i]:
        ps.append(i)
        for j in range(i,1000000,i):
            primes[j]=True

while True:
    n=int(input())
    if(n==0):break
    sum=0
    for j in range(n):
        sum+=ps[j]
    print(sum)

Measured memory_bytes: 18312
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
    int H, W;
    int i, j;
    char buf[51][51];
    fgets(buf[0], sizeof(buf), stdin);
    sscanf(buf[0], "%d%d", &H, &W);
    for (i = 0; i <= H; i++)
        fgets(buf[i], sizeof(buf), stdin);

    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            if (buf[i][j] == '#')
                if (buf[i + 1][j] != '#' && buf[i][j + 1] != '#' && buf[i - 1][j] != '#' && buf[i][j - 1] != '#' ) {
                    printf("No");
                    return 0;
                }
        }
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 1776
import sys
input = sys.stdin.readline

class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.parent[x] = y

    def same(self, x, y):
        return self.root(x) == self.root(y)

N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    x, y = x-1, y-1
    X.append((x, y, i))
    Y.append((y, x, i))
X.sort()
Y.sort()
G = []
for i in range(1, N):
    d = abs(X[i][0]-X[i-1][0])
    a, b = X[i][2], X[i-1][2]
    G.append((d, a, b))
    d = abs(Y[i][0]-Y[i-1][0])
    a, b = Y[i][2], Y[i-1][2]
    G.append((d, a, b))
G.sort()
un = UnionFind(N)
ans = 0
for d, a, b in G:
    if not un.same(a, b):
        un.unite(a, b)
        ans += d
print(ans)


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

// nCr % 2
int comb(int n, int r){
    int t = 0;
    int a=n, b=r, c=n-r;
    while(a){ a/=2; t += a; }
    while(b){ b/=2; t -= b; }
    while(c){ c/=2; t -= c; }
    return t?0:1;
}

char str[1000010];

int main()
{
    int n, ans = 0;
    scanf("%d%s", &n, str);
    // only 3
    for(int i=0; i<n; ++i){
        if(str[i]!='3') continue;
        ans ^= comb(n-1, i);
    }
    ans *= 2;
    // only 2
    for(int i=0; i<n; ++i){
        if(str[i]!='2') continue;
        if(ans==2) ans = 0;
        ans ^= comb(n-1, i);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace  std;
int main(){
        
    int n;
    cin>>n;
    // int arr[n];
    unordered_map<string ,int> m;
    m.clear();
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        m[s]+=1;
    }
    cout<<m.size();



    
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> h(N), dp(N);
    for(int i = 0;i < N;i++){
        cin >> h[i];
    }
    for(int i = 1;i < N;i++){
        dp[i] = INT_MAX;
        for(int j = 1;j <= K;j++)
            if(i-j >= 0)
                dp[i] = min( dp[i], abs(h[i] - h[i-j]) + dp[i-j] );
    }
    cout << dp[N-1] << '\n';
}

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

int n,k;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> k;
	if (k <= (n+1)/2){
		cout << "YES\n";
	}else{
		cout << "NO\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 100005
using namespace std;
string s;
vector<int> son[maxn];
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> s;
	int n = (int)s.size();
	if(s[0]!='1' || s[n-2] !='1' || s[n-1]!='0')
		cout << -1 << endl;
	else {
		for(int i=1;i<n-2;i++)
			if(s[i]!=s[n-2-i]) {
				cout << -1 << endl;
				return 0;
			}
		int idx = 3;
		int now = 2;
		son[2].emplace_back(1);
		for(int i=1;i<n-1;i++) {
			if(s[i]=='1') {
				son[idx].emplace_back(now);
				now = idx++;
			}
			else {
				son[now].emplace_back(idx);
				idx++;
			}
		}
		for(int u=1;u<=n;u++)
			for(int v:son[u])
				cout << u << " " << v << endl;
	}
	return 0;
}


Measured memory_bytes: 6992
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define dev(v, m, n) for(int i=0;i<n;++i){for(int j=0;j<m;++j){cout<<"|"<<v[j][i];}cout<<"|"<<endl;}

using vi = vector<int>;

#define P (1'000'000'007)

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;}

signed main() {
    int n, k, c;
    cin >> n >> k >> c;

    string s;
    cin >> s;

    int p = -1;
    int l = n;

    list<int> lp, ll;

    while (s[++p] == 'x') ;
    while (s[--l] == 'x') ;
    lp.push_back(p);
    ll.push_front(l);

    rep(i, k - 1) {
        p += c;
        l -= c;
        while (s[++p] == 'x') ;
        while (s[--l] == 'x') ;
        lp.push_back(p);
        ll.push_front(l);
    }

    auto lit = ll.begin();
    auto pit = lp.begin();

    while (lit != ll.end() && pit != lp.end()) {
        if (*lit == *pit) {
            cout << *lit + 1 << endl;
        }
        ++lit;
        ++pit;
    }

    return 0;
}

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

int main() {
  int n;
  long long int y;
  bool found=false;
  cin >> n >> y;
  for (int ten=0; ten<=2000; ten++) {
    for (int five=0; five<=2000-ten; five++) {
      for (int one=0; one<=2000-ten-five; one++) {
        if (10000*ten+5000*five+1000*one==y && ten+five+one==n) {
          cout << ten << ' ' << five << ' ' << one;
          found=true;
          break;
        }
        if (found) break;
      }
      if (found) break;
    }
    if (found) break;
  }
  if (!found) cout << "-1 -1 -1";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    int n;
    cin >> n;
    vector<string> s({"a"});
    FOR(x,1,n-1){
        vector<string> next;
        for (string t : s){
            char d = 'a';
            for (char c : t) chmax(d, c);
            for (char c = 'a'; c <= d + 1; c++){
                next.push_back(t + c);
            }
        }
        s = next;
    }
    for (string t : s) cout << t << endl;
    return 0;
}


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

dp = [0]*N

for i in range(N-1):
    if i >= K:
        x = dp[i]+abs(h[i+1]-h[i])
        for j in range(1,K):
            x = min(x,dp[i-j]+abs(h[i+1]-h[i-j]))
            
    else:
        x = dp[i]+abs(h[i+1]-h[i])
        for j in range(1,i+1):
            x = min(x,dp[i-j]+abs(h[i+1]-h[i-j]))
    
    dp[i+1] = x            



print(dp[-1])


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


int main(){
    ll n;cin>>n;
    ll a[100010],b[100010];
    map<ll,ll> bcn;
    rep(i,0,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    rep(i,0,n){
        bcn[b[i]]=i;
    }
    ll an=0;
    rep(i,0,n){
        ll tmp=bcn[a[i]];
        if((i+tmp)%2==1)an++;
    }
    cout<<an/2<<endl;
}

    









Measured memory_bytes: 11444