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

using namespace std;

int main(){
	int n;
	cin >> n;
	int a[100];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	
	int ans = 4000000;
	for(int i=-100;i<=100;i++){
		int cost = 0;
		for(int j=0;j<n;j++){
			cost += pow(i-a[j],2);
		}
		ans = min(ans,cost);
	}
	cout << ans << endl;
	
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  multiset<int> st;
  rep(i, n) st.insert(-a[i]);

  rep(i, m) {
    auto itr = st.begin();
    int x = (-*itr) / 2;
    st.erase(itr);
    st.insert(-x);
  }

  ll ans = 0;
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    ans -= *itr;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8228
#include <bits/stdc++.h>
using namespace std;
#define ff        first
#define ss        second
#define ll        long long
#define int       long long
#define inf       ((ll)1e18)
#define mod       1000000007
#define double    long double
#define ull       unsigned long long
#define vi        vector<ll>
#define ppi       pair<int,int>
#define pii       pair<pair<int,int>,int>
#define pb        push_back
#define pi        2*acos(0.0)
#define rev       greater<int>()
#define pr(a,x,y) for(int i=x;i<y;i++){cout<<a[i]<<" ";}
#define ps(s)     for(auto i:s){cout<<i<<" ";}
#define sp(x,y)   fixed<<setprecision(y)<<x
#define w(x)      ll x; cin>>x; while(x--)
#define all(v)    v.begin(), v.end()
#define rall(v)   v.rbegin(), v.rend()
#define test      cout<<"This is test"<<endl;
#define str       string
#define endl      '\n'
#define e         cout<<'\n';
void kehsihba(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif*/
}
void solve(){
	ll n;cin>>n;
	ll x;
	set<int>s;
	for(int i=0;i<n;i++){
		cin>>x;s.insert(x);
	}
	cout<<(((int)s.size()==n)?"YES":"NO");
}
int32_t main(){
	kehsihba();
	//init();
	ll t=1;
	//cin>>t;
	for(int k=1;k<=t;k++){
		//cout<<"Case "<<k<<": ";
		solve();
		//e;
	}
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
vector<ll> A,B;
map<ll, ll> Amp, Bmp;
vector<vector<ll>> bv;

ll i, j, k, l;


bool is2Cycl(ll a,ll d,vector<bool>& mk){
    //printf("%lld %lld\n", a, d);
    if(mk[a]){
        if(a==0&&d==N*2){
            return false;
        }
        return true;
    }
    mk[a] = true;
    ll i;
    fornum(i,0,bv[a].size()){
        if(is2Cycl(bv[a][i],d+1,mk)){
            return true;
        }
    }
    mk[a] = false;
    return false;
}

int main(){
    scanf("%lld", &N);
    A.resize(N);
    B.resize(N);
    bv.resize(N * 2);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    fornum(i,0,N){
        scanf("%lld", &B[i]);
    }
    fornum(i,0,N){
        if(Amp.find(A[i])==Amp.end()){
            ll aa = Amp.size();
            Amp[A[i]] = aa;
        }
        if(Bmp.find(B[i])==Bmp.end()){
            ll aa = Bmp.size();
            Bmp[B[i]] = aa + N;
        }
        bv[Amp[A[i]]].push_back(Bmp[B[i]]);
    }
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    j = 0;
    bool flg = false;
    fornum(i,0,N){ 
        while(j<N&&A[j]<=B[i]) {
            j++;
        }
        //printf("%lld,%lld\n", A[j], B[i]);
        if(j-1<i){
            printf("No");
            return 0;
        }else if(j-1>i){
            flg = true;
        }

        bv[Bmp[B[i]]].push_back(Amp[A[i]]);
    }
    vector<bool> mk(2 * N,false);
    if(flg||is2Cycl(0,0,mk)){
        printf("Yes");
    }else{
        printf("No");
    }
    
    
    return 0;
}

Measured memory_bytes: 37632
from collections import Counter
h, w, m = map(int, input().split())
blist = [list(map(int, input().split())) for _ in range(m)]

blist_set = set(map(tuple, blist))

rowdict = Counter([blist[i][0] for i in range(m)])
coldict = Counter([blist[i][1] for i in range(m)])

maxr = rowdict.most_common()[0][1]
maxr_keys = []
for i in rowdict.most_common():
    if i[1] == maxr:
        maxr_keys.append(i[0])
    else:
        break
maxc = coldict.most_common()[0][1]
maxc_keys = []
for i in coldict.most_common():
    if i[1] == maxc:
        maxc_keys.append(i[0])
    else:
        break

for i in maxr_keys:
    for j in maxc_keys:
        if (i, j) not in blist_set:
            print(maxr + maxc)
            break
    else:
        continue
    break
else:
    print(maxr + maxc - 1)


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

int n, l[2000], ans = 0, dp[2000][2000], hen1;
std::vector<int> vec;

int main(void) {

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> l[i];
		vec.push_back(l[i]);
	}
	std::sort(vec.begin(), vec.end());

	while (vec.size() >= 3) {
		hen1 = vec.back();
		vec.pop_back();
		for (int i = vec.size() - 1; i >= 0; i--) {
			for (int j = i - 1; j >= 0; j--) {
				if ((hen1 + vec[i] > vec[j]) && (hen1 + vec[j] > vec[i]) && (vec[i] + vec[j] > hen1)) {
					ans++;
				}
				else {
					goto CONTINUE_LABEL;
				}
			}
			CONTINUE_LABEL: {} 
		}
	}
	cout << ans << endl;
}

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

public class Main {
	
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int w = Integer.parseInt(s[0]);
		int h = Integer.parseInt(s[1]);
		int x = Integer.parseInt(s[2]);
		int y = Integer.parseInt(s[3]);

		double q = (double)w * (double)h / 2.0d;
		int f = 0;
		if ( x*2 == w && y*2 == h ) {
			f = 1;
		}
		System.out.printf("%f %d\n",q,f);
	}
}


Measured memory_bytes: 24916
#include <iostream>

using namespace std;

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

    int k, x;
    cin >> k >> x;
    cout << (500 * k >= x ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 256
from itertools import permutations
n=int(input())
l=[]
for i in range(n):
    l.append(list(map(int,input().split())))
c=0
g=0
for i in permutations(range(n),n):
    t=0
    c+=1
    for j in range(n-1):
        t+=((l[i[j]][0]-l[i[j+1]][0])**2+(l[i[j]][1]-l[i[j+1]][1])**2)**0.5
    g+=t
print(g/(1.0*c))

Measured memory_bytes: 42732
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(System.in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		int ans = Math.max(a+b, Math.max(a-b,a*b));
		out.println(ans);
	}
}


Measured memory_bytes: 21716
#include <stdio.h>
int main(void){
    int n,i,a[100];
    scanf("%d",&n);

    for(i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }

    for(i=n;i>=1;i--){
        printf("%d",a[i]);
        if(i==1) break;
        printf(" ");
    }
    
    printf("\n");
    return 0;
}


Measured memory_bytes: 2124
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const INF = 1000000000

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n, l := nextInt(), nextInt()
	dWhole := 0
	for i := 1; i <= n; i++ {
		dWhole += l + i - 1
	}
	switch {
	case 0 <= -l && -l <= n-1:
		fmt.Println(dWhole)
	case -l < 0:
		fmt.Println(dWhole - l)
	default:
		fmt.Println(dWhole - (l + (n - 1)))
	}
}


Measured memory_bytes: 640
/*betaでやろう*/
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <iterator>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(ll i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = 1e17;
const ll NEGA=-INF; 

int a[200];
int main() 
{ 
int n;
cin>>n;
int  x;
cin>>x;

for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
int ans=0;
for(int i=0;i<n;i++){
    if(x-a[i]>=0){
      x-=a[i];
    if(i==n-1&&x>0) break;
      ans++;
    } 
}

cout<<ans<<endl;

}



Measured memory_bytes: 256
a[100],v,j,k,n;main(i){scanf("%d",&n);for(;j<n;scanf("%d",&a[j++]));for(;k<n;printf("%d%s",a[k++],k-n+1?" ":"\n"));for(;i<n;i++){v=a[i];j=i-1;for(;j+1&&a[j]>v;a[j+1]=a[j--]);a[j+1]=v;for(k=0;k<n;printf("%d%s",a[k++],k-n+1?" ":"\n"));}exit(0);}

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

using namespace std;

int main(void) {
	string s;
	cin >> s;
	int i;
	for (i = 0; i < s.size(); i++) {
		if (s[i] == 'A') {
			break;
		}
	}
	for (int j = s.size() - 1; j >= 0; j--) {
		if (s[j] == 'Z') {
			cout << j - i + 1;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 640
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 
N = 10**4
g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

s = int(input())
mod=10**9+7
n = s//3
if n == 0:
  print(0)
  exit()
if n == 1:
  print(1)
  exit()
ans = 1
for i in range(2,n+1):
  a = s-i*3
  ans+=cmb(a+i-1,i-1,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 10216
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

bool used[11];

int main()
{
//	cut here before submit 
//	freopen ("testcase.CG0060", "r", stdin );
	int c1, c2, c3;
	while (scanf ("%d %d %d", &c1, &c2, &c3 ) != EOF ){
		memset (used, false, sizeof (used ) );
		used[c1] = true;
		used[c2] = true;
		used[c3] = true;
		int curr = c1+c2;
		int cnt = 0;
		for (int i = 1; i <= 10; i++ ){
			if (!used[i] && curr + i <= 20 ) cnt++;
		} // end for
		if (cnt >= 4 ){
			printf ("YES\n" );
		}else{
			printf ("NO\n" );
		} // end if
	} // end loop
		
	return 0;
}

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

int main()
{
        string s;
        cin >> s;

        string ans;
        for(int i = 0; i< s.length(); i++)
        {
               if(s[i] == '?')
               {
                   ans+= 'D';
               }
               else
               {
                   ans +=s[i];
               }
        }
                                                        
        cout << ans << endl;
}


Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define Return(expr) { Cout(expr); return 0; }
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
  	int a = n % 10;
  	if(a == 0 || a == 1 || a == 6 || a == 8) Return("pon");
  	if(a == 3) Return("bon");
  	Return("hon");
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
Created on Wed Mar  4 17:43:32 2020

@author: Kanaru Sato
"""

N,K = list(map(int, input().split()))
H = list(map(int, input().split()))

if N <= K:
    print(0)
else:
    H.sort()
    sum = 0
    for i in range(0, N-K):
        sum = sum + H[i]
    print(sum)

Measured memory_bytes: 26024
A, B, K = map(int, input().strip().split())

for k in range(K):
  if k % 2 == 0:
    _A = A // 2
    _B = B + A // 2
    A, B = _A, _B
  else:
    _B = B // 2
    _A = A + B // 2
    A, B = _A, _B
print(A, B)


Measured memory_bytes: 2940
from sys import stdin

N, M, C = [int(x) for x in stdin.readline().rstrip().split()]
Bi = [int(x) for x in stdin.readline().rstrip().split()]
Ai_list = [list(map(int, stdin.readline().rstrip().split())) for _ in range(N)]

count = 0

for Ai in Ai_list:
    sum = 0
    for i in range(M):
        sum += Ai[i] * Bi[i]
    sum += C
    if sum > 0:
        count += 1

print(count)


Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
const ll MOD=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<ll> A_height(N);
    vector<int> Righthand(N);
    vector<ll> Lefthand(N);

    for(int i=0;i<N;i++){
       cin>>A_height[i];
    }
    //身長分だけ横にずらす
    for(int i=0;i<N;i++){
       if(i-A_height[i]>=0){
          Lefthand[i-A_height[i]]++;
       }
       if(i+A_height[i]<N){
          Righthand[i+A_height[i]]++;
       }
    }
    ll count=0;
    for(int i=0;i<N;i++){
       count+=Lefthand[i]*Righthand[i];
    }
    cout<<count<<endl;
}

Measured memory_bytes: 7160
#include<stdio.h>

int main(){
int a,b,c;
int tmp;
scanf("%d %d %d", &a, &b, &c);

if(b < a){
  tmp = b;
  b=a;
  a=tmp;
}


if(c < a){
  tmp=c;
  c=a;
  a=tmp;
}

if(c < b){
  tmp=b;
  b=c;
  c=tmp;
}

printf("%d %d %d\n", a, b, c);


return 0;
}


Measured memory_bytes: 2004
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int H,W;

bool input() {
  cin >>H >>W;
  if (H == 0 && W == 0) return false;
  return true;
}

void solve() {
  rep(i, H){
    rep(j, W){
      cout <<((i+j) % 2 == 0 ? "#" : ".");
    }
    cout <<endl;
  }
  cout <<endl;
}

int main() {
  while (input()){
    solve();
  }
}



Measured memory_bytes: 3152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <functional>
using namespace std;

typedef long long ll;

vector<pair<ll, int>> edg[100003];
ll d[100003];

int main() {
	int n; cin >> n;
	for (int i = 0; i < n - 1; ++i) {
		int a, b; ll c; cin >> a >> b >> c;
		--a; --b;
		edg[a].push_back({ c, b });
		edg[b].push_back({ c, a });
	}
	int q, k; cin >> q >> k;
	--k;
	priority_queue<pair<ll, int> > que;
	for (int i = 0; i < n; ++i) d[i] = -1;
	que.push({ 0, k});
	while (!que.empty()) {
		ll dis = -que.top().first; int pos = que.top().second; que.pop();
		if (d[pos] >= 0) continue;
		d[pos] = dis;
		for (auto p : edg[pos]) {
			que.push({ -dis - p.first, p.second });
		}
	}
	for (int i = 0; i < q; ++i) {
		int x, y; cin >> x >> y;
		--x; --y;
		cout << d[x] + d[y] << endl;
	}
	return 0;
}


Measured memory_bytes: 11120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 競プロ_Csharp {
    class Program {
        static void Main(string[] args) {

            int s = NextInt();

            int h = s / 3600;
            s %= 3600;

            int m = s / 60;
            s %= 60;

            Println(h + ":" + m + ":" + s);

        }

        public static void Println (Object o) {
            Console.WriteLine(o);
        }

        public static String NextString() {
            return Console.ReadLine();
        }

        public static int NextInt () {
            return int.Parse(Console.ReadLine());
        }

        public static int[] NextInts () {
            return Console.ReadLine().Split().Select(int.Parse).ToArray();
        }
    }
}



Measured memory_bytes: 15968
def remove_path(islands,x,N):
    if x==0:
        islands[0].remove(1)
    elif x==N-1:
        islands[N-1].remove(N-2)
    else:
        islands[x].remove(x-1)
        islands[x-1].remove(x)

if __name__ == '__main__':
    N,M=list(map(int,input().split()))
    orders=[tuple(map(int,input().split())) for i in range(M)]
    islands={i:[i-1,i+1] for i in range(1,N-1)}
    islands[0]=[1]
    islands[N-1]=[N-2]

    orders.sort(key=lambda x:x[1])
    flag=False
    last=None
    count=0

    for order in orders:
        a,b=order[0],order[1]
        if flag and a<=last:
            continue
        else:
            remove_path(islands,b-1,N)
            last = b - 1
            count += 1
            flag = True

    print(count)

Measured memory_bytes: 77272
n, m = map(int, input().split())
lst = []
for _ in range(n):
    s = list(map(int, input().split()))
    lst.append(s)
lst = sorted(lst)

v = 0
s_b = 0
lst2 = []
for a, b in lst:
    v += a * b
    s_b += b
    if s_b == m:
        print(v)
        exit()
    if s_b > m:
        lst2.append([a, b])
        break
        
lst2.append([v, s_b])
t_v = lst2[1][0] - ((lst2[1][1] - m) * lst2[0][0])
print(t_v)

Measured memory_bytes: 28652
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

vector<ll> solve(int n,vector<ll>a){
    ll sum=0;
    vector<ll>ans(n);
    rep(i,n)sum+=a[i];
    ll count=0;
    for(int i=1;i<n;i+=2)
    {
        count+=2*a[i];
    }
    ans[0]=sum-count;
    rep(i,n-1)ans[i+1]=2*a[i]-ans[i];
    return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int n;
cin>>n;
vector<ll>a(n);
rep(i,n)cin>>a[i];
vector<ll>ans=solve(n,a);
rep(i,n){
     printf("%d%c", ans[i], i+1==ans.size()?'\n':' ');
}
return 0;
}

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

using namespace std;

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

    vector<long long> cr(n, 0), cg(n, 0), cb(n, 0);
    for (int i = n - 1; i >= 0; i--) {
        cr[i] = (s[i] == 'R' ? 1 : 0) + (i < n - 1 ? cr[i + 1] : 0);
        cg[i] = (s[i] == 'G' ? 1 : 0) + (i < n - 1 ? cg[i + 1] : 0);
        cb[i] = (s[i] == 'B' ? 1 : 0) + (i < n - 1 ? cb[i + 1] : 0);
    }

    long long res = 0;
    for (int i = 0; i < n - 2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            res += ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')
                    ? cb[j + 1] - (2 * j - i < n && s[2 * j - i] == 'B' ? 1 : 0) : 0);
            res += ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')
                    ? cg[j + 1] - (2 * j - i < n && s[2 * j - i] == 'G' ? 1 : 0) : 0);
            res += ((s[i] == 'G' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'G')
                    ? cr[j + 1] - (2 * j - i < n && s[2 * j - i] == 'R' ? 1 : 0) : 0);
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <string>
#include <unordered_map>

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

	std::unordered_map<std::string, std::string> baseTable;

	baseTable["A"] = "T";
	baseTable["T"] = "A";
	baseTable["C"] = "G";
	baseTable["G"] = "C";

	std::string b;
	std::cin >> b;

	std::cout << baseTable[b];
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main() {
    unsigned long long X, Y;
    cin >> X >> Y;

    int i = 0;

    while (X * (((unsigned long long)1) << i) <= Y) i++;

    cout << i << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template <class T> int size(const T &x) { return x.size(); }
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;
typedef unsigned long long ull;

template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

int main() {
    cin.sync_with_stdio(false);
    int n;
    cin >> n;
    bool min = false;
    bool plus = false;
    vi A(n);
    rep(i,0,n) {
        cin >> A[i];
        if(A[i] <= 0) min = true;
        else plus = true;
    }
    if(!min || !plus) {
        sort(A.begin(), A.end());
        int sm = A[n-1];
        vii F;
        rep(i,0,size(A)-1) {
            F.pb(ii(sm, A[i]));
            sm -= A[i];
        }
        vii OTH;
        int sm2 = A[0];
        rep(i,1,size(A)-1) {
            OTH.pb(ii(sm2,A[i]));
            sm2 -= A[i];
        }
        OTH.pb(ii(A[size(A)-1], sm2));
        sm2 = A[size(A)-1]-sm2;
        if(sm > sm2) {
            cout << sm << endl;
            iter(it,F) cout << it->first << " " << it->second << endl;
        } else {
            cout << sm2 << endl;
            iter(it,OTH) cout << it->first << " " << it->second << endl;
        }
        return 0;
    }


    if(min && plus) {
        vii ANS;
        int val = 0;
        rep(i,0,n) val += abs(A[i]);
        vi B;
        vi C;
        rep(i,0,n) {
            if(A[i] <= 0) B.pb(A[i]);
            else C.pb(A[i]);
        }
        while(size(C) != 1) {
            int val = C[size(C)-1];
            ANS.pb(ii(B[size(B)-1], val));
            B[size(B)-1] -= val;
            C.pop_back();
        }
        while(size(B) != 0) {
            int val = B[size(B)-1];
            ANS.pb(ii(C[0], val));
            C[0] -= B[size(B)-1];
            B.pop_back();
        }
        cout << val << endl;
        iter(it,ANS) {
            cout << it->first << " " << it->second << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3956
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n
    def find(self,x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]
    def unite(self,x,y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x<0]
    def group_count(self):
        return len(self.roots())
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
ans=[0]*m
ans[-1]=n*(n-1)//2
uf=UnionFind(n)
for i in range(m-1,0,-1):
  ai=ab[i][0]-1
  bi=ab[i][1]-1
  if uf.same(ai,bi):
    ans[i-1]=ans[i]
  else:
    ans[i-1]=ans[i]-uf.size(ai)*uf.size(bi)
    uf.unite(ai,bi)
print('\n'.join(map(str,ans)))

Measured memory_bytes: 41652
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define iter(i, n) for (int i = 1; i <= n; ++i)
#define NR 101000

const int mod = 1e9 + 7;

int n, a[NR], in[NR], in_x[NR], cnt[NR], f[NR], cc[NR], sz;
bool vis[NR], ring[NR];
vector<int> R[NR];

int main() {
	scanf("%d", &n);
	iter(i, n) {
		scanf("%d", &a[i]);
		++in[a[i]];
		in_x[a[i]] = i;
	}
	iter(i, n) if (in[i] > 2) { puts("0"); return 0; }
	int ans = 1;
	iter(i, n) if (!vis[i]) {
		int x = i; bool is_ring = true;
		for (; !vis[x]; x = a[x]) {
			vis[x] = true;
		}

		if (!ring[x]) {
			++sz;
			for (; !ring[x]; x = a[x]) {
				if (in[x] != 1) is_ring = false;
				ring[x] = true;
				R[sz].push_back(x);
			}
		}

		if (x != i) {
			bool is_chain = true;
			x = i;
			while (in[x] == 1) x = in_x[x];
			if (in[x] != 0) { puts("0"); return 0; }
			int len = 1;
			for (vis[x] = true, x = a[x]; !ring[x]; x = a[x]) {
				++len;
				vis[x] = true;
				if (in[x] != 1) { puts("0"); return 0; }
			}
			cc[x] = len;
		} else {
			if (is_ring) ++cnt[R[sz].size()];
		}
	}

	iter(i, sz) {
		reverse(R[i].begin(), R[i].end());
		int rem = 0;
		for (int x : R[i]) {
			if (cc[x] != 0) {
				if (rem > 1) { puts("0"); return 0; }
				else rem = cc[x];
			} else if (rem != 0) {
				--rem;
				if (rem == 0) ans = ans * 2 % mod;
			}	
		}

		if (rem != 0) {
			for (int x : R[i]) {
				if (cc[x] != 0) {
					if (rem > 1) { puts("0"); return 0; }
					else break;
				} else {
					--rem;
					if (rem == 0) {
						ans = ans * 2 % mod;
						break;
					}
				}
			}
		}
	}

	iter(k, n) {
		f[0] = 1;
		iter(i, cnt[k]) {
			f[i] = f[i - 1] * ((k % 2 && k != 1) ? 2 : 1) % mod;
			if (i > 1) f[i] = (f[i] + 1ll * (i - 1) * f[i - 2] % mod * k) % mod;
		}
		ans = 1ll * ans * f[cnt[k]] % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8320
from collections import deque


def resolve():
	n = int(input())
	a = list(map(int, input().split()))
	d = deque()
	is_even = True if n % 2 == 0 else False
	for i in range(n):
		if is_even:
			if (i+1) % 2 == 0:
				d.appendleft(a[i])
			else:
				d.append(a[i])
		else:
			if (i+1) % 2 == 0:
				d.append(a[i])
			else:
				d.appendleft(a[i])

	print(" ".join(list(map(str, d))))
resolve()

Measured memory_bytes: 119924
#include <stdio.h>
int main() {
	int x;
	scanf("%d", &x);
	if (400 <= x && x <= 599) {
		printf("8\n");
	} else if (600 <= x && x <= 799) {
		printf("7\n");
	} else if (800 <= x && x <= 999) {
		printf("6\n");
	} else if (1000 <= x && x <= 1199) {
		printf("5\n");
	} else if (1200 <= x && x <= 1399) {
		printf("4\n");
	} else if (1400 <= x && x <= 1599) {
		printf("3\n");
	} else if (1600 <= x && x <= 1799) {
		printf("2\n");
	} else {
		printf("1\n");
	}
	return 0;
}

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

#define ll long long
#define pb push_back
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define inf 0x3f3f3f3f
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/* 
* stuff you should look for
* int overflow, array bounds
* special cases (n=1?), set tle
*/

int main(){
    fcin;
	int k, x;
	cin >> k >> x;
	vector<int> v;
	v.pb(x);
	for(int i = 1; i < k; i++) v.pb(x+i);
	for(int i = 1; i < k; i++) v.pb(x-i);
	sort(v.begin(), v.end());
	for(auto i : v) cout << i << " ";
    return 0;
}



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

int memo[5][5001];

int solve(int p, int n){

  if(!p && !n) return 1;
  if(!p || n < 0 || n > p*1000) return 0;
  if(memo[p][n]) return memo[p][n];
  
  int res = 0;
  for(int i=0;i<1001;i++) res += solve(p-1, n-i);

  return memo[p][n] = res;
}

int main(){

  int n;
  for(int i=0;i<4001;i++) solve(4, i);
  while(cin >> n) cout << memo[4][n] << endl;

}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        

fast();
//ll t;cin>>t;while(t--)
{
    ll n,c=0,f=0;
    cin>>n;
    string s,t;
    cin>>s>>t;
    ll i=n-1,j=n-1;
   // cerr<<i<<" "<<j<<endl;
    //cerr<<s[i]<<" "<<t[j]<<endl;
    while(i>=0&&j>=0)
    {
      //cout<<i<<" "<<j<<endl;
      if(s[i]==t[j])
      {
        i--;
        j--;
        c++;
        f=1;
      }
      
      else
      {
        j--;
      }
    }
    //cout<<c<<endl;
    cout<<n*2-c<<endl;
}
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+10;
struct node{
	int x,id;
};
node s1[MAXN],s2[MAXN];
int a[MAXN],b[MAXN];
int n,sum,cnt;
map<int,int>fa;
map<int,int>mp;
int getfather(int x){
	if (fa[x]==x) return x;
	fa[x]=getfather(fa[x]);
	return fa[x];
}
bool cmp(node x,node y)
{
	return x.x<y.x;
}
void adit(int x,int y)
{
	x=getfather(x); y=getfather(y); 
	if (x!=y) {
		fa[x]=y; 
	}
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
        s1[i].x=a[i]; s1[n+1].x^=a[i]; 
	}
	a[n+1]=s1[n+1].x;
    for (int i=1;i<=n;i++) {
    	scanf("%d",&b[i]); 
    	s2[i].x=b[i]; s2[n+1].x^=b[i]; 
	}
	b[n+1]=s2[n+1].x;
	s1[n+1].id=n+1; s2[n+1].id=n+1;
	sort(s1+1,s1+n+2,cmp);
	sort(s2+1,s2+n+2,cmp);
	int w=0;
	for (int i=1;i<=n+1;i++) fa[i]=i;
	for (int i=1;i<=n+1;i++)
	 if (s1[i].x!=s2[i].x) {
	 	printf("%d\n",-1); return 0;
	 }
	sum=0;
	for (int i=1;i<=n+1;i++)
	 if (a[i]!=b[i]||i==n+1)  {
	 	if (!mp[a[i]]) mp[a[i]]=++cnt;
	 	if (!mp[b[i]]) mp[b[i]]=++cnt;
	 	if (i<=n) w++;
	 }
	 if (w==0) {
	 	printf("%d\n",0); return 0;
	 }
	for (int i=1;i<=n;i++) adit(mp[a[i]],mp[b[i]]);
	for (int i=1;i<=cnt;i++) if (fa[i]==i) sum++; 
     printf("%d\n",w+sum-1);
}

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


int main(){
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    if(k <= a){
        cout << k;
        return 0;
    }
    if(k-a <= b){
        cout << a;
        return 0;
    }
    cout << a-(k-a-b);
    return 0;
}

Measured memory_bytes: 3632
#include<cstdio>
#define maxn 100010
using namespace std;
int n,cnt,f[maxn<<1],sx[maxn<<1],sy[maxn<<1],mp1[maxn],mp2[maxn];
inline int find(int x){return x==f[x]?x:f[x]=find(f[x]);}
inline void link(int x,int y){
	x=find(x),y=find(y);
	if(x==y)return;
	f[x]=y,sx[y]+=sx[x],sy[y]+=sy[x]; 
}
int main(){
	scanf("%d",&n);
	cnt=0;
	for(int i=1;i<=n;++i){
		int x,y;
		scanf("%d%d",&x,&y);
		if(!mp1[x]){sx[mp1[x]=++cnt]=1;f[cnt]=cnt;}
		if(!mp2[y]){sy[mp2[y]=++cnt]=1;f[cnt]=cnt;}
		link(mp1[x],mp2[y]);
	}
	long long ans=-n;
	for(int i=1;i<=cnt;++i)if(f[i]==i)ans+=1ll*sx[i]*sy[i];
	printf("%lld\n",ans);
	return 0;
}

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

#define SZ(x) (((int)x.size()))
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

using namespace std;

const int mod = 1000000007;
ll n, k, ans;

int main()
{
	cin >> n >> k;
	for (ll i = k; i <= n + 1; i++)
	{
		ans += i * (n - i + 1) + 1;
		ans %= mod;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3576
#include <stdio.h>
#include <string.h>

int main(void) {
    char result[16];
    int i, sum = 0;
    scanf("%s", result);
    for ( i = 0; i <= ((int)strlen(result) - 1); i++ )
    {
        if ( result[i] == 'o' )
        {
            sum += 1;
        }
    }
    sum += 15 - strlen(result);
    if ( sum >= 8 )
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 128
loop do
  n = gets.to_i
  break if n == 0
  s = []
  longest = 0
  n.times do
    str = gets.chomp
    replaced = str[0]
    str.chars.each_cons(2) do |ch1, ch2|
      replaced += ch2 if ch1.match(/[aiueo]/)
    end
    s << replaced
    longest = replaced.size if replaced.size > longest
  end

  k = 0
  succeed = false
  ns = []
  while k <= longest
    k += 1
    ns = s.map { |str| str[0...k] }
    if ns.uniq.size == ns.size
      succeed = true
      puts k
      break
    end
  end

  puts -1 unless succeed
end

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


int main(){
    int n,m;cin >> n >> m;
    ll total = 0;
    vector<int> a(n);
    vector<P> p(m);
    rep(i,n){
        cin >> a[i];
        total += a[i];
    }
    //cout << "total "<<total <<endl;
    rep(i,m){
        int b,c;
        cin >> b >> c;
        p[i] = make_pair(c,b);
    }
    sort(a.begin(),a.end());
    //for(auto v:a) cout << v << endl;
    sort(p.rbegin(),p.rend());
    //for(auto v:p) cout << v.first << endl;
    vector<int> d;
    for(auto v:p){
        rep(i,v.second) d.push_back(v.first);
        if(d.size() > n) break;
    }

    //for(auto v:d) cout <<v<< endl;

    rep(i,n){
        //cout << a[i] << " " << d[i] << endl;
        if(a[i] > d[i]) break;
        total += (d[i] - a[i]);
        a[i] = d[i];
    
    }

    cout << total << endl;



}

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

int main() {
    int N;
    cin >> N;
    int max = 0;
    int count = 0;
    int h;

    for(int i=0; i<N; i++){
        cin >> h;
        if(max <= h){
            max = h;
            count++;
        }
    }
    
    cout << count << endl;
}

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

int main(){
  int K,k=0;
  std::string s,temp;
  std::vector<std::string> vec1,min;
  
  std::cin>>s;
  std::cin>>K;
  
  for(unsigned long i=0;i<s.length();i++)
      for(unsigned long j=0;j<K;j++){
        temp=s.substr(i,j+1);
        vec1.push_back(temp);
      }
      
  std::sort(vec1.begin(),vec1.end());
      
  while(min.size()<K){
    if(min.empty())
      min.push_back(vec1[k]);
    else if(min.size()<K&&vec1[k]!=min.back())
      min.push_back(vec1[k]);
    k++;
    }
      
  std::cout<<min[K-1]<<std::endl;
  return 0;

}

Measured memory_bytes: 1660
n = int(input())
aka = []
ao = []
aka = aka + [list(map(int,input().split())) for _ in range(n)]
ao = ao + [list(map(int,input().split())) for _ in range(n)]

aka = sorted(aka, key=lambda x:x[1],reverse=True)
ao = sorted(ao, key=lambda x:x[0])

ans = 0

for i in range(n):
	for j in range(n):
		if ao[i][0] > aka[j][0] and ao[i][1] > aka[j][1]:
			ans += 1
			aka[j][1] = 201
			break

print(ans)

Measured memory_bytes: 3064
#include<string>
#include<cctype>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
const int maxn = 36 + 8;
/*template<class T>
void swap(T &a,T &b)
{
    T c = a;
    a = b;
    b = c;
}
*/
struct node{
    char c;
    int n;
};

node x[maxn],y[maxn],z[maxn];

int n,minj;
void bubbleSort(node y[])
{
    for(int i = 0; i < n; i++){
        for(int j = n-1; j >= i+1; --j){
            if(y[j].n < y[j-1].n){
                swap(y[j],y[j-1]);
            }
        }
    }
    return;
}

void  selectSort(node z[])
{
    for(int i = 0; i < n-1; ++i){
        minj = i;
        for(int j = i; j < n; ++j){
            if(z[j].n < z[minj].n){
                minj = j;
            }
        }
        swap(z[minj],z[i]);
    }
    return;
}

void see(node m[])
{
    for(int i = 0; i < n; ++i){
        printf("%s%c%d",i == 0 ? "" : " ",m[i].c,m[i].n);
    }
    printf("\n");
}

bool judge(node a[],node b[])
{
    for(int i = 0; i < n ;++i){
        if(a[i].c != b[i].c || (a[i].c == b[i].c && a[i].n != b[i].n)){
            return false;
        }
    }
    return true;
}
int main()
{
    scanf("%d",&n);
    for(int i = 0; i < n; ++i){
        char ch = (char)getchar();
        scanf("%c%d",&x[i].c, &x[i].n);
        y[i].c = z[i].c = x[i].c;
        y[i].n = z[i].n = x[i].n;
    }
    bubbleSort(y);
    see(y);
    cout << "Stable" << endl;
    selectSort(z);
    see(z);
    printf("%s\n",judge(y,z) == 0 ? "Not stable" : "Stable");
    return 0;
}

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

int main() {
    int a1, a2, a3, temp;
    cin >> a1 >> a2 >> a3;

    if (a1 > a2) {
        temp = a1;
        a1 = a2;
        a2 = temp;
    }
    if (a2 > a3) {
        temp = a2;
        a2 = a3;
        a3 = temp;
    }
    if (a1 > a2) {
        temp = a1;
        a1 = a2;
        a2 = temp;
    }

    cout << a1 << " " << a2 << " " << a3 << endl;
}



Measured memory_bytes: 3092
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <queue>
# define MOD 1000000000+7
# define INF 1000000000
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0,e=0, ans = 0, x = 0, y = 0, z = 0, n = 0, m = 0, maxy = 0, mini = 9999, counter = 0, endp = 0, checker = 0;

std::vector <long long int> vec{}, vecsec{}, vecth{};
long long int iremono[100001], koware[100001];
long long int iremono2[100001], check[100001],xpo[10000001],ypo[10000001],hei[1000001];
std::vector<std::string>kinds{}, kaku{};
char maze[1000][1000];
int sx, sy;
int gx, gy;
pair<pair<std::string,long long int>, long long int>pairs[101];
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
bool okada = false, okada2 = false;
std::string output, output2, input, input2;
char re;
int starta, startb, enda, endb,ab;


unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}

int H, W;//はんい
bool qw = false, er = false, ty = false,ui=false;
int main() {
	cin >> a;
	rep(i, a) {
		cin >> input;
		cin >> x;
		pairs[i]=make_pair(make_pair(input,x*-1),i);
	}
	std::sort(pairs,pairs+a);
	rep(i, a) {
		cout << pairs[i].second+1<< endl;
	}
}


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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m;
int a[N];
int u[N];
int c[N];
pair < int, int > b[N];
ll ans;
vector < int > g[N], comp;


void dfs (int v) {
	u[v] = 1;
	comp.pb(v);
	for (auto to : g[v]) if (!u[to]) {
		dfs(to);
	}
}


int main () {
	SpeedForce;
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) cin >> a[i];

	for (int i = 1; i <= m; i ++) {
		int l, r;
		cin >> l >> r;
		l++, r++;
		g[l].pb(r);
		g[r].pb(l);
	}
	int cnt = 0;
	for (int i = 1; i <= n; i ++) if (!u[i]) {
		++cnt;
		comp.clear();
		dfs(i);

		int mn = i;
		for (auto x : comp) {
			if (a[mn] > a[x]) mn = x;
		}
		c[mn] = 1;
		ans += a[mn];
	//	cout << mn << '\n';
	}

	if (cnt == 1) {
		puts("0");
		exit(0);
	}

	cnt = 2 * (cnt - 1) - cnt;
	for (int i = 1; i <= n; i ++) b[i] = mp(a[i], i);
	sort(b + 1, b + n + 1);

  	for (int i = 1; i <= n && cnt > 0; i ++) if (!c[b[i].S]) {
  		cnt--;
  	//	cout << b[i].S << '\n';
  		ans += b[i].F;
  	}
  	if (cnt != 0) {
  		puts("Impossible");
  		exit(0);
  	}
  	cout << ans << '\n';

   	return Accepted;
}

// B...a

Measured memory_bytes: 26488
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
const long long MOD = 1e9+7, INF = 1e18;
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;}



signed main(){
	int N,M;
	cin>>N>>M;
	vector<pair<int,int>>v(N);
	REP(i,N)cin>>v[i].first>>v[i].second;
	REP(i,N)v[i].second *= -1;
	sort(ALL(v));
	priority_queue<int>que;
	int ans = 0,now = 0;
	REP(i,M+1){
		while(now<N&&v[now].first<=i){
			que.push(-v[now].second);
			now++;
		}
		if(!que.empty()){
			ans += que.top();
			que.pop();
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 2936
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000;
const double PI = acos(-1);
const int mod = 1000000007;


int main()
{
    int l, r, d;
    cin >> l >> r >> d;

    int ans = 0;
    for (int i = l; i <= r; i++) {
        if (i % d == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    ll t,n,i,j;
    string s;
    cin>>s;
    if(s[0]=='R' && s[1]=='R' && s[2]=='R')cout<<"3";
    else if((s[0]=='R'&& s[1]=='R')||(s[1]=='R'&&s[2]=='R'))cout<<"2";
    else if( s[0]=='R' || s[1]=='R'||s[2]=='R')cout<<1;
    else cout<<0;
}

Measured memory_bytes: 3588
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static long[] hi;
        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            if (M <= N)
            {
                WriteLine(0);
                return;
            }
            var X = Sarray();
            Array.Sort(X);
            var dsts = new Tuple<long, long, long>[M - 1];//dst,left,right
            for (var i = 0; i < M - 1; ++i)
                dsts[i] = new Tuple<long, long, long>(X[i + 1] - X[i], X[i], X[i + 1]);
            Array.Sort(dsts, (l, r) => (int)(r.Item1 - l.Item1));//逆順
            var start = new List<long>() { X[0] };
            var end = new List<long>() { X[M - 1] };
            //N個の領域に分ける
            for (var i = 0; i < N - 1; ++i)
            {
                end.Add(dsts[i].Item2);
                start.Add(dsts[i].Item3);
            }
            start.Sort();
            end.Sort();
            var ans = 0L;
            for (var i = 0; i < N; ++i)
            {
                ans += end[i] - start[i];
            }
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 34652