akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
vector<pii>pat[101010];
bool flag[101010];
ll dep[101010];
void dfs(int node, ll d)
{
	if (flag[node])return;
	flag[node] = true;
	dep[node] = d;
	for (int i = 0; i < pat[node].size(); i++)dfs(pat[node][i].first, d + pat[node][i].second);
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--, zb--;
		pat[za].push_back(make_pair(zb, zc));
		pat[zb].push_back(make_pair(za, zc));
	}
	int query, cent;
	scanf("%d%d", &query, &cent);
	cent--;
	dfs(cent, 0);
	for (int i = 0; i < query; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		printf("%lld\n", dep[za] + dep[zb]);
	}
}

Measured memory_bytes: 14464
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

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

int main() {
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        for(int j=i+1;j<s.size();j++){
            if(s[i]=='C' && s[j]=='F'){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;





    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define SORTR(v,n) sort(v, v+n, greater<int>());
#define SORTPairSecond(v, n) sort(v, v+n, pairCompareSecond);
#define int long long    // %d=>%lld, 1<<n  => 1LL<<n
#define pb push_back

using namespace std;
typedef long long ll;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> piii;
typedef pair<ll, pll> plll;
bool pairCompareSecond(const pii& firstEl, const pii& secondEl) {
    return firstEl.second > secondEl.second;
}

const ll MOD = 1000000007;
const int INF = 1000000007;
// const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
// const ll LLINF = 1LL << 50;
const double PI = acos(-1);
const double EPS = 0.000000001;



string s;



signed main(){
    ios::sync_with_stdio(0);

    cin >> s;

    if(s.length()<4){
        cout<< "No\n";
        return 0;
    }

    string ans="YAKI";

    if(s.substr(0,4) ==  ans){
        cout<< "Yes\n";
    }else{
        cout<< "No\n";
    }

    return 0;
}

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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int N, L;
    cin >> N >> L;
    vector<string> S(N);
    rep(i, N) cin >> S.at(i);

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

    rep(i, N) cout << S.at(i);
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;
const double PI = acos(-1);

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(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;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
  vector<int> p;
  vector<int> s;
  void init(int n) {
    p.resize(n, -1);
    s.resize(n, 1);
  }
  int find(int n) {
    if(p[n] == -1) return n;
    else return find(p[n]);
  }
  int size(int n) {
    return s[find(n)];
  }
  void unite(int n, int m) {
    int pn = find(n);
    int pm = find(m);
    if(pn == pm) return;
    if(s[pn] > s[pm]) {
      s[pn] = s[pn] + s[pm];
      p[pm]= pn;
    } else {
      s[pm] = s[pm] + s[pn];
      p[pn] = pm;
    }
  }
};

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  UnionFind uf;
  uf.init(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    x--;y--;
    uf.unite(x, y);
  }
  int ans = 0;
  rep(i, n) {
    if(uf.find(i) == uf.find(p[i])) ans++;
  }
  cout << ans << endl;
}


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

int main(void) {
  unsigned long n, m[5], mmin;
  cin >> n;
  for (int i = 0; i < 5; i++) {
    cin >> m[i];
    if (mmin > m[i] || i == 0) mmin = m[i];
  }
  if (n % mmin == 0) cout << n / mmin + 4 << endl;
  else cout << n / mmin + 5 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main(){
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    if ((x - r) < 0 || (y - r) < 0 || W < (x + r) || H < (y + r)){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}


Measured memory_bytes: 2692
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    };
    let mod_p = 1_000_000_007_i64;
    let mut c = vec![0_i64; n + 1];
    for (i, &a_i) in a.iter().enumerate().rev() {
        c[i] = c[i + 1] + a_i;
        c[i] %= mod_p;
    }
    let mut s = 0_i64;
    for (i, &a_i) in a.iter().enumerate() {
        if i + 1 > n {
            continue;
        }
        s += (a_i * c[i + 1]) % mod_p;
        s %= mod_p;
    }
    let ans = s;
    println!("{}", ans);
}


Measured memory_bytes: 7148
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
fn main() {
    input!(a: u64, b: f64);
    println!("{}", a * (b * 100.).round() as u64 / 100);
}


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

int main(){
    long long int n, k, n_min;
    cin >> n >> k;
    n=n%k;
    n_min=n;
    while(1){
        if(n_min<=abs(n-k)){
            break;
        }
        n=abs(n-k);
        n_min=n;
    }
    cout << n_min << endl;
    
}

Measured memory_bytes: 256
from collections import deque
n=int(input())
que=deque()

for i in range(n):
    command=input()
    if command=="deleteFirst":que.popleft()
    elif command=="deleteLast":que.pop()
    else:
        x,y=command.split()
        if x=="insert":que.appendleft(y)
        else:
            if y in que:que.remove(y)

print(*que)


Measured memory_bytes: 69736
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
template<class T> bool umin(T &x,T y) { if (x<y) return 0; x=y; return 1; }
template<class T> bool umax(T &x,T y) { if (x>y) return 0; x=y; return 1; }
using ll = long long;
using ld = long double;

int const INF=1e9;

struct dist_func {
	ll l1,r1,l2,r2,m1,m2;
	vector<ll> ts;
	
	dist_func(ll a,ll b,ll c,ll d,ll e,ll f): l1(a),r1(b),l2(c),r2(d),m1(e),m2(f) {
		ts.push_back(0);
		while (true) {
			ll nt=find_next(ts.back());
			if (nt==ts.back() || nt==INF) break;
			ts.push_back(nt);
		}
	}
	
	ll eval(ll t) const {
		return max({r1+t,r2-t,m2})-min({l1+t,l2-t,m1});
	}
	
	ll operator()(ll t) const {
		return eval(t);
	}
	
	ll find_next(ll t) {
		ll s=eval(t+1)-eval(t);
		ll l=t,r=INF;
		while (l<r) {
			ll m=l+(r-l)/2;
			ll s2=eval(m+1)-eval(m);
			if (s==s2) l=m+1; else r=m;
		}
		return l;
	}
};

ll check(const dist_func &dx, const dist_func &dy, ll t) {
//~ cerr<<ld(t)/4.0<<" "<<ld(dx(t)*dy(t))/16<<endl;
	return dx(t)*dy(t);
}

ll cross(const dist_func &d1, const dist_func &d2,ll l,ll r) {
	while (l<r) {
		ll m=l+(r-l)/2;
		if (d1(m)<d2(m)) l=m+1; else r=m;
	}
	return l;
}

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	ll r1,r2,l1,l2,x1,x2,d1,d2,u1,u2,y1,y2;
	r1=l1=x1=d1=u1=y1=INF;
	r2=l2=x2=d2=u2=y2=-INF;
	
	int N;
	cin>>N;
	rep(i,0,N) {
		ll x,y;
		string s;
		cin>>x>>y>>s;
		x*=4;
		y*=4;
		switch (s[0]) {
			case 'R':
				umin(r1,x),umax(r2,x),umin(y1,y),umax(y2,y);
				break;
			case 'L':
				umin(l1,x),umax(l2,x),umin(y1,y),umax(y2,y);
				break;
			case 'U':
				umin(u1,y),umax(u2,y),umin(x1,x),umax(x2,x);
				break;
			case 'D':
				umin(d1,y),umax(d2,y),umin(x1,x),umax(x2,x);
				break;
			default:
				throw;
		}
	}
	
	dist_func dx(r1,r2,l1,l2,x1,x2);
	dist_func dy(u1,u2,d1,d2,y1,y2);
	
//~ cerr<<dx.l1/4<<" "<<dx.r1/4<<" "<<dx.l2/4<<" "<<dx.r2/4<<" "<<dx.m1/4<<" "<<dx.m2/4<<endl;
//~ cerr<<dy.l1/4<<" "<<dy.r1/4<<" "<<dy.l2/4<<" "<<dy.r2/4<<" "<<dy.m1/4<<" "<<dy.m2/4<<endl;
//~ cerr<<endl;
	
	ll res=check(dx,dy,0);
	for (ll t:dx.ts) umin(res,check(dx,dy,t));
	for (ll t:dy.ts) umin(res,check(dx,dy,t));
	for (ll t1:dx.ts) for (ll t2:dy.ts) {
		umin(res,check(dx,dy,cross(dx,dy,t1,t2)));
		umin(res,check(dy,dx,cross(dy,dx,t2,t1)));
	}
	cout<<ld(res)/16<<"\n";	
}


Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll n, k;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    a.resize(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i]--;
    vector<int> v;
    int cur = 0;
    map<int, bool> m;
    map<int, int> mm;
    ll syuu = 0;
    int last=0;
    while (true)
    {
        v.push_back(cur);
        m[cur] = true;
        mm[cur] = v.size();
        cur = a[cur];
        if (m[cur])
        {
            syuu=v.size()-mm[cur]+1;
            last=mm[cur]-1;
            break;
        }
    }
    /*
    debug(v);
    cout<<syuu<<"\n";
    cout<<last<<"\n";
    */
    if(k<=last){
        //cout<<100<<"\n";
        cout<<v[k]+1<<"\n";
        return 0;
    }
    k-=last;
    k=k%syuu;
    cout<<v[last+k]+1<<"\n";
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n,a;cin>>n>>a;
  cout<<n*n-a<<endl;

  return 0;
}


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

{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a ,b;
	char s;
	cin >> a >> s >> b ;
	if(s=='+')
	{
		cout << a + b <<"\n";
	}
	else
	{
		cout << a - b <<"\n";
	}
	

}

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


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int K,A,B;
	cin>>K;
	cin>>A>>B;

	int flag = 0;

	for(int i = A;i<=B;i++)
	{
		if(i % K == 0)
		{
			flag = 1;
			break;
		}
	}

	if(flag)
		cout<<"OK"<<endl;
	else
		cout<<"NG"<<endl;

	return 0;
}

Measured memory_bytes: 3608
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <iomanip>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 100000
#define LARGENUM 1000000007
#define INF 9223372036854775807
#define ull unsigned long long 
int color[MAX], n;
ull d[MAX];
typedef pair <ull, int> P;
vector <P> adj[MAX];

void dijkstra(int s){
    priority_queue<P> PQ;
    rep(i, n) {
        d[i] = INF;
        color[i] = WHITE;
    }
    d[s] = 0;
    PQ.push(P(0, s));
    color[0] = GRAY;
    while (!PQ.empty()){
        P f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;
        if (d[u] < f.first * -1) continue;
        rep(j, adj[u].size()){
            int v = adj[u][j].second;
            if (color[v] == BLACK) continue;
            if (d[v] > d[u] + adj[u][j].first){
                d[v] = d[u] + adj[u][j].first;
                PQ.push(make_pair(d[v] * -1, v));
                color[v] = GRAY;
            }
        }
    }
}

int main(){
    int m, a, b, c, Q, K, x, y;
    cin >> n;
    m = n - 1;
    rep(i, m){
        cin >> a >> b >> c;
        adj[a-1].push_back(P(c, b-1));
        adj[b-1].push_back(P(c, a-1));
    }
    cin >> Q >> K;
    dijkstra(K-1);
    rep(i, Q){
        cin >> x >> y;
        cout << d[x-1] + d[y-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 11504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

bool ifprime(int x){
    if(x==1)return false;
    if(x==2)return true;
    if(x%2==0)return false;
    for(int i=2;i*i<=x;i++){if(x%i==0)return false;}
    return true;
}
ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up

//Start from Here
int main(){
    ll N, K;
    cin>>N>>K;
    cout<<min(mod(N, K), K-mod(N, K))<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;
#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++)

// AOJ How Many Islands? 1160
int h, w;
vector<vector<bool> > square(50, vector<bool>(50));

// 幅優先探索
void dfs(int x, int y){

    // 一度通過した部分は塀とする
    square.at(x).at(y) = 0;

    rep2(dx, -1, 2){
        rep2(dy, -1, 2){
            int nx = x + dx;
            int ny = y + dy;
            if(0 <= nx && nx < w && 0 <= ny && ny < h && square.at(nx).at(ny) == 1) {
                dfs(nx, ny);
            }
        }
    }

    return;
}

int main(){
    h = 1;
    w = 1;
    while(true){
        cin >> w >> h;
        if(h == 0 && w == 0) break;
        int answer = 0;
    
        rep(i, h){
            rep(j, w) {
                int a;
                cin >> a;
                square.at(j).at(i) = a;
            }
        }
        rep(i, h){
            rep(j, w){
                if(square.at(j).at(i) == 1) {
                    dfs(j, i);
                    //cout << "x:" << j << " y:" << i << endl;
                    answer++;
                    //rep(i, h) {rep(j, w) {cout << square.at(j).at(i);} cout << "\n";} cout << "------\n";
                }
            }
        }
        cout << answer << endl;
    }
    
    


}


Measured memory_bytes: 3336
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct UnionFind {
    vector<int> par;
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return 0;
        if (par[x] > par[y]) swap(x, y); 
        par[x] += par[y];par[y] = x;
        return 1;
    }
    int size(int x) {
        return -par[root(x)];
    }
};
int main() {
    long long N, M; cin >> N >> M;
    vector<int> A(M), B(M);
    for (int i = 0; i < M; ++i) {
        cin >> A[i] >> B[i], --A[i], --B[i];
    }UnionFind uf(N);
    long long cur = N * (N-1) / 2;
    vector<long long> res;
    for (int i = 0; i < M; ++i) {
        res.push_back(cur);
        int a = A[M-1-i], b = B[M-1-i];
        if (uf.issame(a, b)) continue;
        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); ++i) cout << res[i] <<endl;
}

Measured memory_bytes: 5500
#include <stdio.h>

int main(void)
{
  int N, K;
  scanf("%d %d", &N, &K);
  int ans = 0;
  for(int i = 0; i < N; i++){
    int h;
    scanf("%d", &h);
    if(K <= h)
    	ans++;
  }
  printf("%d", ans);
}


Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	int n,m;cin>>n;
	vint a(n);
	vector<vector<P>> s(n);
	rep(i, n){
		cin>>a[i];
		rep(j, a[i]){
			int x,y;cin>>x>>y;
			s[i].push_back(P(x, y));
		}
	}

	int ans = 0;
	rep(bit, 1<<n){
		bool flag = true;
		int cou = 0;
		rep(i, n){
			if((1<<i)&bit){
				cou++;
				rep(j, a[i]){
					if((s[i][j].second == 1&& (1<<(s[i][j].first-1)&bit) == 0)||(s[i][j].second == 0&& (1<<(s[i][j].first-1)&bit) > 0) ){
						flag = false;
					}
				}
			}
		}
		debug("%d\n", cou);
		if(flag)chmax(ans, cou);
	}

	cout << ans << endl;

	return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

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

/*
bool isOK(ll x){
  	int temp = x%10;
	while(x>9){
      	x = x/10;
      	if(abs(temp-x%10) > 1) return false;
      	temp = x%10;
    }
  	return true;
}

ll nextOK(ll x){
	if(x<10) return x+1;
	ll y = x;
	while(1){
		ll temp = x%10;
		ll y = (y-temp)/10;
		if(temp!=(y%10)+1) return x+1;
      	else 
    }
}
*/

void Main(){
 	// const ll MAX = 3234566667;
	int k;
	cin >> k;
  	set<ll> ans = {1};
  	  
  	while(ans.size()<k){
		ll temp = *(--ans.end());
      	if(temp<10) ans.insert(temp+1);
        else{
          	int x = temp%10;
        	int y = (temp/10)%10;
        	if(x == y-1) ans.insert(temp+1);
      		else if(x==y && x!=9) ans.insert(temp+1);
      		else if((x==y && x==9) || x==y+1) {
          		auto it = ans.lower_bound(temp/10);
       		   	it++;
       	   		ll next = *it;
				int z = next%10;
         	 	if(z==0) next = next*10;
          		else next = next*10 + z - 1;
          		ans.insert(next);
        	}
        }
    }
  	auto it = ans.end();
  	--it;
  	cout << *it << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
int main()
{
    long long int n,a,i,S[2]={},C[2]={};
    scanf("%lld",&n);
    for(i=0;i<n;i++){
        scanf("%lld",&a);
        S[0]+=a;
        S[1]+=a;
        if(i%2==0){
            if(S[0]>=0){
                C[0] += S[0] + 1;
                S[0] = -1;
            }
            if(S[1]<=0){
                C[1] += -1*S[1] + 1;
                S[1] = 1;
            }
        }
        else{
            if(S[0]<=0){
                C[0] += -1*S[0] + 1;
                S[0] = 1;
            }
            if(S[1]>=0){
                C[1] += S[1] + 1;
                S[1] = -1;
            }
        }
    }
    printf("%lld\n",C[0]<C[1]?C[0]:C[1]);
    return 0;
}

Measured memory_bytes: 128
n=int(input())
l=[]
cnt=0
B,A,BA=0,0,0
for i in range(n):
    s=input()
    cnt+=s.count("AB")
    if s[0]=="B"and s[-1]=="A":BA+=1
    elif s[0]=="B":B+=1
    elif s[-1]=="A":A+=1
if BA==0:print(cnt+min(A,B))
else:print(cnt+BA-1+(B>0)+(A>0)+max(0,min(A-1,B-1)))

Measured memory_bytes: 3064
n = int(input())
M = 10**9 + 7
a = list(map(int, input().split()))
a.sort(reverse=True)
# print(np.sum((np.array(range(2, 2 + n)) * 2**((n - 1) * 2))[::-1] * a) % M)

def mod(a):
    if a >= M:
        a %= M
    return a

def powmod(a, n):
    if n == 0:
        return 1
    if n % 2:
        return mod(a * powmod(a, n - 1))
    else:
        return mod(powmod(a, n // 2)**2)

result = 0
for i, v in enumerate([mod(i * powmod(2, (n - 1) * 2)) for i in range(2, 2 + n)]):
    result = mod(result + mod(v * a[i]))
print(result)



Measured memory_bytes: 109396
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm> 
using namespace std;
 
# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

const int limit=30;

int a[limit],b[limit];

int graph[limit][limit];
bool isVisited[limit];

bool isAllVisited(int n){
    bool ans=true;
    for(int i=0;i<n;i++){
        if(!isVisited[i]) ans = false;
    }
    return ans;
}

int dfs(int v,int depth,int n){
    if(depth==n) {
        if(isAllVisited(n)) return 1;
        else return 0;
    } 
    int ret=0;
    for(int v2=0;v2<n;v2++){
        if(isVisited[v2]) continue;
        if(!graph[v][v2]) continue;
        isVisited[v2]=true;
        ret += dfs(v2,depth+1,n);
        isVisited[v2]=false;
    } 
    return ret;
}

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

    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i];
        a[i]--;b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    isVisited[0]=true;
    p(dfs(0,1,n))
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxN = 15;
int cnt[maxN];
int bonus[maxN];
int n, g;
bool used[150];
int main() {
    ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    cin >> n >> g;
    for (int i = 1; i <= n; i++) {
        cin >> cnt[i] >> bonus[i];
    }
    int ans = (int)1e9;
    for (int mask = 0; mask < (1 << n); mask++) {
        int ball = 0;
        int probl = 0;
        memset(used, 0, sizeof used);
        for (int j = 0; j < n; j++) {
            if (mask & (1 << j)) {
                used[j + 1] = true;
                probl += cnt[j + 1];
                ball += cnt[j + 1] * (100 * (j + 1)) + bonus[j + 1];
            }
        }
        if (ball >= g) ans = min(ans, probl);
        for (int j = n; j >= 1; j--) {
            if (used[j]) continue;
            for (int t = 1; t <= cnt[j] - 1; t++) {
                ball += 100 * j;
                probl++;
                if (ball >= g) {
                    ans = min(ans, probl);
                    break;
                }
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <cstdlib>
    #include <cmath>
    #include <climits>
    #include <cfloat>
    #include <map>
    #include <utility>
    #include <set>
    #include <iostream>
    #include <memory>
    #include <string>
    #include <vector>
    #include <algorithm>
    #include <functional>
    #include <sstream>
    #include <deque>
    #include <complex>
    #include <stack>
    #include <queue>
    #include <cstdio>
    #include <cctype>
    #include <cstring>
    #include <ctime>
    #include <iterator>
    #include <bitset>
    #include <numeric>
    #include <list>
    #include <iomanip>
    #include <cassert>
    #include <array>
    #include <tuple>
    #include <initializer_list>
    #include <unordered_set>
    #include <unordered_map>
    #include <forward_list>
    using namespace std;
    using ll = long long;
    #define rep(j,k) for (int j = 0; j < (int)(k); j++)
     
    int n;
    ll x[100010];
    ll L;
    int Q;
    int a[100010], b[100010];
     
    const int LOG = 20;
    ll go[100010][LOG];
     
    int f(int a, int x) {
        for (int i = 0; x; ++i, x /= 2) {
            if (x & 1) a = go[a][i];
        }
        return a;
    }
     
    int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
     
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> x[i];
        }
        x[n] = 2e9;
        cin >> L >> Q;
        for (int i = 0; i < n; i++) {
            int k = upper_bound(x + i, x + n, x[i] + L) - x;
            go[i][0] = k - 1;
        }
        for (int i = 0; i < LOG - 1; i++) {
            for (int j = 0; j < n; j++) {
                go[j][i + 1] = go[go[j][i]][i];
            }
        }
        for (int i = 0; i < Q; i++) {
            int a, b;
            cin >> a >> b;
            --a; --b;
            if (a > b) swap(a, b);
            int lb = 0, ub = n;
            while (lb + 1 < ub) {
                int mid = (lb + ub) / 2;
                if (f(a, mid) >= b) ub = mid;
                else lb = mid;
            }
            cout << ub << endl;
        }
    }

Measured memory_bytes: 17280
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    if ((B - A) % 2 == 0) {
        cout << (B - A) / 2 << endl;
    } else {
        ll ans = min(B - 1, N - A);
        ll c = A + (B - A - 1) / 2;
        if (c < ans) ans = c;
        c = N + 1 - B + (B - A - 1) / 2;
        if (c < ans) ans = c;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))
A.sort()
F.sort(reverse=True)

def solve(X):
    s = 0
    for i in range(N):
        if A[i]*F[i]>X:
            s += math.ceil((A[i]*F[i]-X)/F[i])
    # print(X, s)
    return s <= K

if sum(A) <= K:
    print(0)
else:
    l, r = 0, 10**12+10
    while l+1<r:
        mid = (l+r)//2
        if solve(mid):
            r = mid
        else:
            l = mid
    print(r)

Measured memory_bytes: 119500
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];

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

    int dp[n];
    dp[0] = 0;
    dp[1] = abs(a[1]-a[0]);

    for(int i=2;i<n;i++)
        dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),
                    dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1]<<'\n';
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int A,B;
  cin>>A>>B;
  int ans = 0;
  while(A>0){
    A -= 2*B+1;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}

int main(){
	ll a, b;
	char op;
	cin >> a >> op >> b;
	ll ans = (op == '+')? a + b: a - b;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>
#include <complex>

const long INF = (1l << 30);
const long LINF = (1l << 60);

long h, w, a, b;

long mat[1005][1005];

int main(){
    scanf("%ld%ld%ld%ld", &h, &w, &a, &b);
    for(int i = 0; i < b; i++){
        for(int j = 0; j < a;j++){
            mat[i][j] = 1;
        }
    }
    for(int i = b; i < h; i++){
        for(int j = a; j < w; j++){
            mat[i][j] = 1;
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            printf("%ld", mat[i][j]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 9088
N = int(input())
b = list(map(int, input().split()))

remove_list = []
while b != []:
    #print(b)
    can_remove = False
    remove_index = 0
    for i, e in reversed(list(enumerate(b))):
        #print(i, e)
        if i + 1 == e:
            remove_list.append(e)
            can_remove = True
            remove_index = i
            break
        
    if not can_remove:
        break
    else:
        del b[remove_index]

if b != []:
    print(-1)
else:
    for e in reversed(remove_list):
        print(e)
    

Measured memory_bytes: 3060
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	s.resize(s.size() - 8);
	cout << s << endl;
	return 0;
}


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

bool read(int** ppArray, int &num)
{
    cin >> num;
    *ppArray = new int[num];
    
    if (NULL == ppArray) {
        return false;
    }
    for (int i = 0; i < num; i++) {
        cin >> *(*ppArray + i);
    }

    return true;
}

int selectionSort(int* pArray, const int num)
{
    int sw = 0;
    for (int i = 0; i < num - 1; i++) {
        int min = i;
        for (int j = i; j < num; j++) {
            if (*(pArray + j) < *(pArray + min)) {
                min = j;
            }
        }
        swap(*(pArray + i), *(pArray + min));
        if (i != min)
            sw++;
    }

    return sw;
}

void puts(const int* pArray, const int sw, const int num)
{
    for (int i = 0; i < num; i++) {
        i > 0 ? cout << " " << *(pArray + i) : cout << *(pArray + i);
    }
    cout << endl;
    cout << sw << endl;
}

int main()
{
    int n = 0;
    int *pArray = NULL;

    if (!read(&pArray, n)) {
        return 1;
    }

    int sw = selectionSort(pArray, n);

    puts(pArray, sw, n);

    delete[] pArray;
}

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



int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h.at(i);
  }

  vector<int> move_c(1, 0);

  int start = 0;
  while (start < n-1) {
    int count = 0;
    int place = start;
    while (h.at(place) >= h.at(place + 1)) {
      count++;
      place++;
      if (place >= n-1) break;
    }
    move_c.push_back(count);
    start += count + 1;
  }

  int ans;
  sort(move_c.begin(), move_c.end());
  reverse(move_c.begin(), move_c.end());
  ans = move_c.at(0);

  cout << ans << endl;
}

Measured memory_bytes: 1276
N, K = gets.chop.split.map(&:to_i)

def dev(a, b)
  return a / b, a % b
end

def main(n, k, count)
  ans, sur = dev(n, k)

  if ans == 0
    return puts count + 1
  else
    main(ans, k, count + 1)
  end
end

main(N, K, 0)


Measured memory_bytes: 1788
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){

			int N = scan.nextInt();

			int[]a = new int[N-1];
			int[]b = new int[N-1];

			int []c = new int[N+1];
			GM[]map = new GM[N];


			for(int i = 0;i<N;i++) {
				map[i] = new GM(i+1);
			}

			for(int i = 0;i<N-1;i++) {
				a[i] = scan.nextInt();
				b[i] = scan.nextInt();
				c[a[i]]++;
				c[b[i]]++;
				map[a[i]-1].hen.put(b[i], 0);
				map[b[i]-1].hen.put(a[i], 0);
			}





			int max = 0;
			int maxi = 0;
			for(int i = 1;i<=N;i++) {
				if(max<c[i]) {
					max = c[i];
					maxi = i;
					//System.out.println(max);
				}
			}


			dfs(maxi,max,map,1);



			//System.out.println(maxi);




			/*
			Deque<GM>queue = new ArrayDeque<GM>();
			queue.addFirst(map[maxi]);
			map[maxi].ch = true;

			//System.out.println(maxi);
			//System.out.println();


			int i = 0;
			while(!queue.isEmpty()) {
				GM p  =queue.removeLast();
				for(Integer key:p.hen.keySet()) {
					if(map[key-1].ch==false) {
						//System.out.println(p.num+" "+key);
						//System.out.println(p.pre);
						map[key-1].ch=true;
						queue.addFirst(map[key-1]);
						if(p.pre==i) {
							i++;
							if(i>max)i = 1;
							p.hen.put(key, i);
							map[key-1].hen.put(p.num, i);
							map[key-1].pre=i;
						}else {
							i++;
							if(i>max)i=1;
							if(p.pre==1)i++;
							p.hen.put(key, i);
							map[key-1].hen.put(p.num, i);
							map[key-1].pre=i;

						}

					}
				}
			}

			*/

			System.out.println(max);


			for(int k = 0;k<N-1;k++) {
				int p = map[a[k]-1].hen.get(b[k]);
				System.out.println(p);

			}






		}


	}

	private static void dfs(int num,int max,GM[] map,int count) {

		int a = count++;
		if(a>max)a%=max;

		map[num-1].ch = true;

		for(Integer key:map[num-1].hen.keySet()) {
			//System.out.println(num+" "+key);
			if(map[key-1].ch==false) {
				map[num-1].hen.put(key, a);
				map[key-1].hen.put(num, a);
				a++;
				if(a>max)a%=max;
				//map[key-1].ch = true;
				dfs(key,max,map,a);

			}
		}



	}

	private static  class GM{
		int num = 0;
		boolean ch = false;
		int pre = 0;
		Map<Integer,Integer>hen = new TreeMap<Integer,Integer>();


		GM(int n){
			num = n;
		}
	}



}


Measured memory_bytes: 92664
#include<stdio.h>

int n,A[50];

int solve(int i,int m){
	if(m==0)return 1;
	if(i>=n)return 0;
	int res=solve(i+1,m) || solve(i+1,m-A[i]);
	return res;
}

int main(void){
	int q,M,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&A[i]);
		scanf("%d",&q);
	for(i=0;i<q;i++){
		scanf("%d",&M);
		if(solve(0,M))printf("yes\n");
		else printf("no\n");
}
	return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#include <queue>
#include <map>
#define FLAG -1
using namespace std;
typedef pair<int,int> P;
int main(){
      int h,w,dh[] = {1,1,1,0,-1,-1,-1,0}, dw[] = {1,0,-1,-1,-1,0,1,1},ctn,i,j,solve = -1 ;
      cin >> h >> w;
      queue<P> que,tmp;
      char d[h][w];
      for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                  cin >> d[i][j];
                  if('1'<=d[i][j]&&'9'>=d[i][j])
                        que.push(make_pair(i,j));
            }
      }
      que.push(make_pair(FLAG,FLAG));
      for(;;){
            solve++;
            map<P,bool> m;
            for(;;){
                  P p = que.front();
                  que.pop();
                  if(p.first==FLAG)break;
                  if(d[p.first][p.second]=='.')continue;
                  ctn = 0;
                  for(i = 0;i < 8;i++)if(d[p.first+dh[i]][p.second+dw[i]]=='.')ctn++;
                  if(ctn >= d[p.first][p.second]-'0'){
                        tmp.push(p);
                        for(j=0;j<8;j++)
                              if(m.count(make_pair(p.first+dh[j],p.second+dw[j]))==0){
                                    que.push(make_pair(p.first+dh[j],p.second+dw[j]));
                                    m[make_pair(p.first+dh[j],p.second+dw[j])]=true;
                              }
                  }
            }
            if(tmp.empty())break;
            while(!tmp.empty()){
                  d[tmp.front().first][tmp.front().second]='.';
                  tmp.pop();
            }
            que.push(make_pair(FLAG,FLAG));
      }
      cout << solve << endl;
}

Measured memory_bytes: 10232
#include <bits/stdc++.h>
#include <set>
#define rep(i,n) for (int i =0; i < (n); ++i)
using namespace std;
// 153b

int main() {
  char s[3];
  for(int i=0; i< 3 ;i++) cin >> s[i];
  
  if (s[0]==s[1]&&s[1]==s[2]){
    cout << "No" << endl;
    return 0;
}

cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
////////////////////////////////////////////////////////////
#define all(x) (x).begin(), (x).end() 
const int inf = 1e9;
const long long INF=1e15;
#define endl '\n'
#define rep(i, n) for(int i=0;i<(n);++i)
#define repp(i, a, b) for(int i=(a);i<=(b);++i)
#define pb push_back
#define eb emplace_back
#define fastio ios::sync_with_stdio(false);cin.tie(0); //cout.tie(0);

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

void solve() {
	ll n; cin>>n;
	vll l(2*n);rep(i,2*n)cin>>l[i];
	sort(all(l));
	ll sum = 0;
	rep(i,n) sum += l[i*2];
	cout << sum;
}

int main() {
	fastio;
	solve();
}



Measured memory_bytes: 256
main = do
    n <- getLine
    a <- map read . words <$> getLine
    putStrLn . show $ solve a

solve:: [Int]-> Int
solve a = evCount 0 a

evCount n s
    | hasOdd s = n
    | otherwise = evCount (n + 1) $ map (\x -> div x 2) s

hasOdd:: [Int] -> Bool
hasOdd [] = False
hasOdd (s:ss)
    | mod s 2 == 1 = True
    | otherwise = hasOdd ss


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

int main()
{
    string n;
    cin >> n;
    if ((n[0] == n[1] && n[1] == n[2]) || (n[1] == n[2] && n[2] == n[3]))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};

LL pas[55][55] = {};

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    pas[0][0] = 1;
    FOR(i,1,53) REP(j,i+1){
        if(j == 0 or j == i) pas[i][j] = 1;
        else pas[i][j] = pas[i-1][j] + pas[i-1][j-1];
    }

    LL N,P; cin >> N >> P;
    LL cnt[2] = {};
    REP(i,N){
        int a; cin >> a;
        if(a % 2 == 0) cnt[0]++;
        else cnt[1]++;
    }
    if(P == 0){
        LL ans = (1LL << cnt[0]);
        LL tmp = 0;
        for(LL i = 0; i <= cnt[1]; i+=2){
            tmp += pas[cnt[1]][i];
        }
        cout << ans * tmp << endl;

    }else{
        LL ans = (1LL << cnt[0]);
        LL tmp = 0;
        for(LL i = 1; i <= cnt[1]; i+=2){
            tmp += pas[cnt[1]][i];
        }
        cout << ans * tmp << endl;


    }


}

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

const int64_t MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  ll k;
  ll count = 0;
  cin >> k;
  
  ll val = 7;
  for(int i=1;i<100000000;i++){
    if(val%k==0){
      cout << i << endl;
      return 0;
    }
    val *= 10;
    val += 7;
    val %= k;
  }
  cout << "-1" << endl;
  return 0;
}



Measured memory_bytes: 3684
@$_=$_ for@i=@p=0..10**5;$\-=<>;/ />${*a=-$'}||(${@{$B=$p[$a]}>@{$A=$p[$`]}or$A^=$B^=$A^=$B;A}-$B&&map$p[$$B[@$B]=$_]=$B,@$A),$a=$`for<>;@0=();$\+=@{$p[${-$_}]}for@i;print

Measured memory_bytes: 143104
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    
    vector<bool> red(N, false);
    vector<int> boll(N, 1);
    red[0] = true;
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        
        if (red[x]) red[y] = true;
        --boll[x];
        ++boll[y];
        if (boll[x] == 0) red[x] = false;
    }
    int cnt = 0;
    rep(i, N) if (red[i]) ++cnt;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x,a,b,c,ans=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++){
        for(int j=0;j<=b;j++){
            for(int z=0;z<=c;z++){
                int k=i*500+j*100+z*50;
                if(k==x)
                   ans++;
                if(k>x)
                   break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/* ***********************************************
Author        :dasinlsb
Created Time  :2018/5/31 12:46:21
File Name     :C:\dasin\mine.cpp
************************************************ */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
const int N=305;
int n,kk,mod,f[N][N],g[N][N],c[N][N];
inline void add(int&x,int y){x=x+y<mod?x+y:x+y-mod;}
int main(){
 // freopen("C:/dasin/aa.in","r",stdin);
  int i,j;
  scanf("%d%d%d",&n,&kk,&mod);
  for(c[0][0]=i=1;i<=n;++i){
    for(c[i][0]=j=1;j<=i;++j){
      c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
    }
  }
  for(i=0;i<=kk;++i)f[1][i]=1,g[1][i]=kk-i+1;
  for(i=2;i<=n+1;++i){
    for(j=0;j<=kk;++j){
      for(int _i=1;_i<i;++_i){
        add(f[i][j],(ll)g[_i][j+1]*f[i-_i][j]%mod*c[i-2][_i-1]%mod);
      }
      //printf("[%d,%d] : %d\n",i,j,f[i][j]);
    }
    for(j=kk;j;--j){
      g[i][j]=(g[i][j+1]+f[i][j])%mod;
    }
  }
  printf("%d\n",f[n+1][0]);
  return 0;
}


Measured memory_bytes: 1280