akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cctype>
#include <numeric>
#include <bitset>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

// struct node {
//   int v, d, c;
//   bool operator<(const node& other) const {
//     if (d != other.d) return d > other.d;
//     return c > other.c;
//   }
// };

struct node {
  int v, d, c;
  bool operator<(const node& other) const {
    if (d != other.d) return d > other.d;
    return c > other.c;
  }
};

enum { kN = 10002 };

int N, M;
vector<node> es[kN];
bool visit[kN];

int solve() {
  memset(visit, false, sizeof visit);

  priority_queue<node> pq;
  rep(i,es[0].size()) pq.push(es[0][i]);
  visit[0] = true;

  int ans = 0;
  while (!pq.empty()) {
    node n = pq.top(); pq.pop();
    if (visit[n.v]) continue;
    visit[n.v] = true;
    // printf("[%d]\n", n.v+1);
    ans += n.c;
    rep(i,es[n.v].size()) {
      node t = es[n.v][i];
      if (!visit[t.v])
        pq.push((node){t.v, t.d + n.d, t.c});
    }
  }
  
  return ans;
}

int main() {
  while (scanf("%d%d", &N, &M) != -1, N | M) {
    rep(i,kN) es[i].clear();
    int u, v, d, c;
    rep(i,M) {
      scanf("%d%d%d%d", &u, &v, &d, &c);
      --u; --v;
      es[u].push_back((node){v, d, c});
      es[v].push_back((node){u, d, c});
    }
    printf("%d\n", solve());
  }
  return 0;
}

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

namespace Rally
{
    class Program
    {
        static void Main(string[] args)
        {
            int inputCoordinate = int.Parse(Console.ReadLine());
            string[] inputStamina = Console.ReadLine().Split(' ');

            if (inputStamina.Count() != inputCoordinate)
            {
                Console.WriteLine("Wrong input");
            }

            List<int> minStamina = new List<int>();
            for(int i = 0; i < 100; i++)
            {
                int countedStamina = 0;
                foreach (string inp in inputStamina)
                {
                    countedStamina += (i - int.Parse(inp)) * (i - int.Parse(inp));
                }

                minStamina.Add(countedStamina);
            }        

            Console.WriteLine(minStamina.Min());
        }
    }
}

Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

int main(){

    ll N, M, K;
    cin >> N >> M >> K;
    for(ll i = 0; i <= N; i++){
        for(ll j = 0; j <= M; j++){
            ll tmp = i * j + (N - i) * (M - j);
            if(tmp == K){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int h,w;
    scanf("%d%d",&h,&w);
    char s[h][w+1];
    for(int i=0;i<h;i++){
        scanf("%s",s[i]);
    }
    for(int i=0;i<=w+1;i++){
    printf("#");
    }
    printf("\n");
    for(int i=0;i<h;i++){
        printf("#%s#\n",s[i]);
    }
    for(int i=0;i<=w+1;i++){
    printf("#");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(void){
    int k,n;
    cin >> k >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    int x=0;
    for(int i=1;i<n;i++){
        x = max(abs(A[i-1]-A[i]),x);
    }
    x = max(abs(k+A[0]-A[n-1]),x);
    cout << k-x << endl;
	return 0;
}

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

N, K = map(int, input().split())
nums = [[] for i in range(N)]
for i in range(N):
    t, d = map(int, input().split())
    t -= 1
    nums[t].append(d)
maxs = []
rest = []
for i in range(N):
    if len(nums[i]) == 0: continue
    nums[i].sort(reverse=True)
    maxs.append(nums[i][0])
    for n in nums[i][1:]:
        rest.append(n)
maxs.sort(reverse=True)
rest.sort(reverse=True)
if len(maxs) > K:
    maxs = maxs[:K]
other = []
idx = 0
while len(maxs)+len(other) < K:
    other.append(rest[idx])
    idx += 1
rest = rest[idx:]

types = len(maxs)
for i,r in enumerate(rest):
    diff = types*types - pow(types-1, 2)
    if diff < r-maxs[len(maxs)-1-i]:
        maxs[len(maxs)-1-i] = r
        types -= 1
    else:
        break
ans = types*types
for num in maxs:
    ans += num
for num in other:
    ans += num
print(ans)


Measured memory_bytes: 19308
N = int(input())
li = [2**i for i in range(0,7,1)]
flag = False
for i in range(N):
  for j in range(7):
    if li[j] == N:
      print(li[j])
      flag = True
      break
  if flag == True:
    break
  else:
    N -= 1

Measured memory_bytes: 3060
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var c = lines.map(i => i.split(" ").map(i => Number(i)));
    
    // biを仮定する
    for (var a1 = 0; a1 <= 100; a1++) {
        var b1 = c[0][0] - a1
        var b2 = c[1][0] - a1
        var b3 = c[2][0] - a1

        // 仮定したbiが正しいか検証する
        for (var a2 = 0; a2 <= 100; a2++) {
            if (a2 + b1 !== c[0][1]) { continue }
            if (a2 + b2 !== c[1][1]) { continue }
            if (a2 + b3 !== c[2][1]) { continue }
            
            for (var a3 = 0; a3 <= 100; a3++) {
                if (a3 + b1 !== c[0][2]) { continue }
                if (a3 + b2 !== c[1][2]) { continue }
                if (a3 + b3 !== c[2][2]) { continue }
                
                // 正しければ Yes
                console.log("Yes");
                return (0)
            }
        }
    }
    // 間違っていれば No
    console.log("No")

});


Measured memory_bytes: 9548
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
    int h,w; cin>>h>>w;
    rep(i,w+2) cout<<"#";
    cout<<endl;
    rep(i,h){
        string s; cin>>s;
        cout<<"#";
        cout<<s;
        cout<<"#"<<endl;
    }
    rep(i,w+2) cout<<"#";
    cout<<endl;
}

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

int main() {
  int N[4];
  for (int i = 0; i < 4; i++) cin >> N[i];

  sort(N, N + 4);
  if (N[0] == 1 && N[1] == 4 && N[2] == 7 && N[3] == 9) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline auto vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    map<string,int>mp={
        {"SUN",0},
        {"MON",1},
        {"TUE",2},
        {"WED",3},
        {"THU",4},
        {"FRI",5},
        {"SAT",6}
    };
    cout<<7-mp[in<string>()]<<endl;
}


Measured memory_bytes: 256
import math
N, K = map(int, input().split())
x = 0
for i in range(1, N + 1, 1):
	a = math.ceil(math.log(float(K) / i, 2))
	if a < 0:
		a = 0
	x += float(1) / (2 ** a)
print(float(x) / N)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  ll n, m;
  cin >> n >> m;
  map<ll, ll> mp;
  rep(i, n){
    ll a;
    cin >> a;
    mp[a]++;
  }
  rep(i, m){
    ll b, c;
    cin >> b >> c;
    mp[c] += b;
  }
  ll ans = 0;
  rrepit(itr, mp){
    // cerr << itr->first << " " << itr->second << " " << ans << " " << n << endl;
    ans += itr->first*itr->second;
    n -= itr->second;
    if(n <= 0){
      ans += itr->first*n;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> ac(n);
    ac[0] = 0;
    for(int i=1; i < n; i++){
        if(s[i-1] == 'A' and s[i] == 'C'){
            ac[i] = ac[i-1] + 1;
        }else{
            ac[i] = ac[i-1];
        }
    }
    int l, r;
    for(int i=0; i < q; i++){
        cin >> l >> r;
        cout << ac[r-1] - ac[l-1] << endl;
    }
}


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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  while(cin>>N,N){
	stack<PII> st;
	FOR(i,1,N+1){
	  int c;
	  cin >> c;
	  if(i%2){
		if(!st.empty() && st.top().FF == c){
		  st.top().SS++;
		}
		else
		  st.push(MP(c,1));
	  }
	  else{
		int n = 1;
		while(!st.empty() && st.top().FF != c){
		  n += st.top().SS;
		  st.pop();
		}
		st.push(MP(c,n));
	  }
	}
	int ans = 0;
	while(!st.empty()){
	  if(st.top().FF == 0)
		ans += st.top().SS;
	  st.pop();
	}
	cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3080
fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val H = readLine()!!.split(" ").map { it.toInt() }


    var count = 1

    (1..N-1).forEach { i ->
        val h = H[i]
        if (
                (0..(i-1)).filter {
                    H[it] <= h
                }.size  == i
        ) {
            count++
        }
    }
    println(count)
}

Measured memory_bytes: 36116
n = int(input())

prime = [31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381, 1451]

print(' '.join(map(str, prime[:n])))

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

int main() {
  long long a;
  long long b;
  long long k;

  cin >> a;
  cin >> b;
  cin >> k;

  if (a >= k) {
    cout << a-k << " " << b <<endl;
  } else {
    if (k-a > b) {
      cout << 0 << " " << 0 <<endl;
    } else {
      cout << 0 << " " << b-(k-a) <<endl;
    }
  }
}


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

int main(){
	int k,t;
	cin >> k >> t;
	int a[1000000];
	for(int i=0;i<t;i++)cin >> a[i];
	sort(a,a+t);
	if(k==1)cout << a[0] - 1 << endl; 
	else {
		for(int i=t-2;i>=0;i--){
			a[t-1]-=a[i];
		}
		if(a[t-1]<=0)cout << 0 << endl;
		else cout << a[t-1] - 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

int main()
{
	int n;
	string s;
	ll ans=1;
	cin>>n;
	cin>>s;
	for(int i=1;i<n;i++)
	{
		if(s[i-1]!=s[i])
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;	
int n,dp[3][1000],a[3][1000];
int main()
{

	cin>>n;
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cin>>a[i][j];
			dp[i][j]=max(dp[i-1][j],dp[i][j-1])+a[i][j];
		}
	}
	cout<<dp[2][n];
}

Measured memory_bytes: 3676
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}
	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)

	fmt.Fprintln(writer, float64((n-(n>>1)))/float64(n))
	writer.Flush()
}


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

int main() {
	int n;
	cin >> n;
	int arr[n];
	for (int i=0; i<n; i++){
		cin>> arr[i];
	}
	for (int i=n-1; i>=0; i-=2){
		cout << arr[i]<<' ';
	}
	if (n%2==0){
		for (int i=0; i<n; i+=2){
			cout << arr[i]<<' ';
		}
	}
	else{
		for (int i=1; i<n; i+=2){
			cout << arr[i]<<' ';
		}		
	}	
	cout << endl;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
#define for0(i, n) for(int i = 0; i < (n); i++)
#define puts(x) cout << x << endl
using namespace std;
int input() {
	int r;
	scanf("%lld", &r);
	return r;
}
string f(int k) {
	string s = ""; for0(i, k)s += '.'; return s;
}
signed main() {
	int n = input();
	if (n == 2) { puts(-1); return 0; }
	if (n == 3) {
		printf("aab\nc.b\ncdd\n"); return 0;
	}
	for (int i7 = 0; i7 * 7 <= n; i7++) {
		for (int i6 = 0; i7 * 7 + i6 * 6 <= n; i6++) {
			for (int i5 = 0; i7 * 7 + i6 * 6 + i5 * 5 <= n; i5++) {
				if ((n - (i7 * 7 + i6 * 6 + i5 * 5)) % 4 == 0) {
					int i4 = (n - (i7 * 7 + i6 * 6 + i5 * 5)) / 4, sum = 0;
					string s1, s2;
					while (i7--) {
						s1 = f(sum), s2 = f(n - sum - 7);
						cout << s1 << "aabb..c" << s2 << "\n";
						cout << s1 << ".i..llc" << s2 << "\n";
						cout << s1 << ".imm..d" << s2 << "\n";
						cout << s1 << "h...n.d" << s2 << "\n";
						cout << s1 << "h...nk." << s2 << "\n";
						cout << s1 << "gjj..k." << s2 << "\n";
						cout << s1 << "g..ffee" << s2 << "\n";
						sum += 7;
					}
					while (i6--) {
						s1 = f(sum), s2 = f(n - sum - 6);
						cout << s1 << "aabb.c" << s2 << "\n";
						cout << s1 << ".i.llc" << s2 << "\n";
						cout << s1 << "hi...d" << s2 << "\n";
						cout << s1 << "h...kd" << s2 << "\n";
						cout << s1 << "gjj.k." << s2 << "\n";
						cout << s1 << "g.ffee" << s2 << "\n";
						sum += 6;
					}
					while (i5--) {
						s1 = f(sum), s2 = f(n - sum - 5);
						cout << s1 << "aabbc" << s2 << "\n";
						cout << s1 << "hii.c" << s2 << "\n";
						cout << s1 << "h..jd" << s2 << "\n";
						cout << s1 << "g..jd" << s2 << "\n";
						cout << s1 << "gffee" << s2 << "\n";
						sum += 5;
					}
					while (i4--) {
						s1 = f(sum), s2 = f(n - sum - 4);
						cout << s1 << "aacd" << s2 << "\n";
						cout << s1 << "bbcd" << s2 << "\n";
						cout << s1 << "efgg" << s2 << "\n";
						cout << s1 << "efhh" << s2 << "\n";
						sum += 4;
					}
					return 0;
				}
			}
		}
	}
}

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

int main() {

    int n;
    int a[100]; 
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cout << a[n-i-1];
        if (i != n - 1) {
            cout << " ";
        }

    }
    cout << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> L(2 * N);
  rep(i, 2 * N) cin >> L[i];
  sort(L.begin(), L.end());
  int ans = 0;
  rep(i, 2 * N) if (i % 2 == 0) ans += L[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n=int(input())
A=list(map(int,input().split()))

B0=[A[i] for i in range(0,n,2)]
B1=[A[i] for i in range(1,n,2)]

if n%2==0:
    C=B1[::-1]+B0

else:
    C=B0[::-1]+B1

for j in C:
    print(j,end=" ")


Measured memory_bytes: 26308
#include <cstdio>
#define MAX 100000
#define INF 999999
using namespace std;

typedef struct {
	char suit;
	int num;
} Card;

//int n;
//Card A[MAX], B[MAX];

void print(Card arr[], int n)
{
	for (int i = 0; i < n; i++) {
		printf("%c %d\n", arr[i].suit, arr[i].num);
	}
}

void swap(Card *a, Card *b)
{
	int ch;
	int num;
	
	ch = a->suit;
	a->suit = b->suit;
	b->suit = ch;
	
	num = a->num;
	a->num = b->num;
	b->num = num;
	
}

int Partition(Card arr[], int p, int r)
{
	int x = arr[r].num;
	int i = p-1;
	
	for (int j = p; j < r; j++) {
		if (arr[j].num <= x) {
			i++;
			swap(&arr[j], &arr[i]);
		}
		//test_def
		//print(arr, n);
		//test_end
	}
	swap(&arr[i+1], &arr[r]);
	
	return i+1;
}

void QuickSort(Card arr[], int p, int r)
{
	if (p < r) {
		int q = Partition(arr, p, r);
		QuickSort(arr, p, q-1);
		QuickSort(arr, q+1, r);
	}
}

void merge(Card arr[], int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	Card L[n1+1];
	Card R[n2+1];
	
	L[n1].num = R[n2].num = INF;
	for (int i = 0; i < n1; i++) {
		L[i].suit = arr[left+i].suit;
		L[i].num = arr[left+i].num;
	} 
	for (int i = 0; i < n2; i++) {
		R[i].suit = arr[mid+i].suit;
		R[i].num = arr[mid+i].num;
	}
	int i = 0;
	int j = 0;
	for (int k = left; k < right; k++) {
		if (L[i].num <= R[j].num) {
			arr[k].suit = L[i].suit;
			arr[k].num = L[i].num;
			i++;
		}
		else {
			arr[k].suit = R[j].suit;
			arr[k].num = R[j].num;
			j++;
		}
	}
}

void MergeSort(Card arr[], int left, int right)
{
	if (left+1 < right) {
		int mid = (left+right)/2;
		MergeSort(arr, left, mid);
		MergeSort(arr, mid, right);
		merge(arr, left, mid, right);
	}
}

bool isEqual(Card A[], Card B[], int n)
{
	for (int i = 0; i < n; i++) {
		if (A[i].suit != B[i].suit) {
			return false;
		}
	}
	
	return true;
}

int main(void)
{
	Card A[MAX], B[MAX];
	int n;
	
	scanf("%d", &n);
	while (getchar() != '\n');
	for (int i = 0; i < n; i++) {
		scanf("%c %d%*c", &A[i].suit, &A[i].num);
		B[i].suit = A[i].suit;
		B[i].num = A[i].num;
	}

	MergeSort(A, 0, n);
	QuickSort(B, 0, n-1);
	if (isEqual(A, B, n) == true) {
		printf("Stable\n");
	}
	else {
		printf("Not stable\n");
	}
	print(B, n);
	
	//test_def
	//putchar('\n');
	//print(A, n); 
	//putchar('\n');
	//print(B, n);
	//test_end
	
	return 0;
}

/*
S 3
C 3
H 4
D 4
S 4
C 5
S 2
C 2
H 3
D 3
C 5
C 3
H 4
D 4
S 4
C 4
H 5
D 5
S 5
C 5
*/


Measured memory_bytes: 5008
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>



using namespace std;

int main() {
    int a,b;
    cin>>a>>b;
    if(a>b){
        cout<<2*a-1<<endl;
    }else if(a==b){
        cout<<2*a<<endl;
    }else{
        cout<<2*b-1<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int H, W;
  cin >> H >> W;
  string board[H];
  for (int i = 0; i < H; i++)
  {
    cin >> board[i];
  }
  for (int i = 0; i < W + 2;i++){
    cout << '#';
  }
  cout << endl;
  for (int i = 0; i < H; i++)
  {
    cout <<'#'<< board[i]<<'#'<<endl;
  }
    for (int i = 0; i < W + 2;i++){
    cout << '#';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A.at(i);
  }
  vector<int> B(N);
  for(int i=0;i<N;i++){
    cin>>B.at(i);
  }
  vector<int> C(N-1);
  for(int i=0;i<N-1;i++){
    cin>>C.at(i);
  }

  int ans = 0;
  for(int i=0;i<N-1;i++){
    if(A.at(i)==A.at(i+1)-1){
      ans+=C.at(A.at(i)-1);
    }
  }

  for(int i=0;i<N;i++){
    ans+=B.at(A.at(i)-1);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[110];
int N,M;

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>N;
    int sum=0;
    for(int i=0;i<N;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    cin>>M;
    int p,x;
    for(int i=0;i<M;i++)
    {
        cin>>p>>x;
        cout <<sum+x-a[p-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>

using namespace std;

typedef long long ll;

int main(void) {
    ll K;
    vector<ll> A;
    cin >> K;
    for (ll i = 0; i < K; i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }

    if (A[K - 1] != 2) {
        cout << "-1" << endl;
        return 0;
    }

    ll low = 2;
    ll high = 3;
    ll n = 2;

    for (ll i = K - 2; i >= 0; i--) {
        ll nlow = (low + A[i] - 1) / A[i] * A[i];
        if (high < nlow) {
            cout << "-1" << endl;
            return 0;
        }
        low = nlow;
        n = A[i];
        high = high / n * n + n - 1;
    }

    cout << low << " " << high << endl;
    return 0;
}



Measured memory_bytes: 1400
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    h = sorted(h)
    mn = 1e9
    for i in range(N-K+1):
        if mn > h[i+K-1] - h[i]:
            mn = h[i+K-1] - h[i]
    print(mn)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8284
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n,ans=1,mod=1e9+7,cnt[1010]={};
  cin>>n;
  for(int i=1;i<=n;i++){
    int t=i;
    for(int j=2;t!=1;){
      while(t%j==0)t/=j,cnt[j]++;
      j++;
    }
  }
  for(int i=1;i<=n;i++)
    if(cnt[i])ans*=cnt[i]+1,ans%=mod;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (){
  int A[251],n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d",&A[i]);
    for(i=1;i<=n;i++){
      printf("node %d: key = %d, ",i,A[i]);
    
      if(i/2!=0)
	printf("parent key = %d, ",A[i/2]);
      if(n>=2*i)
	printf("left key = %d, ",A[i*2]);
      if(n>=2*i+1)
	printf("right key = %d, ",A[i*2+1]);
      printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2076
#include <stdio.h>
#include <stdlib.h>
#define rep(i,l,r)for(int i=(l);i<(r);i++)

int x,y;
char s[100010];
int main(){
	int n;
	scanf("%d %s",&n,s);
	rep(i,0,n){
		if('A'<=s[i]&&s[i]<='M')x++;
		if('N'<=s[i]&&s[i]<='Z')x--;
		if('a'<=s[i]&&s[i]<='m')y++;
		if('n'<=s[i]&&s[i]<='z')y--;
	}
	printf("%d\n",abs(x)+abs(y));
	rep(i,0,x)putchar('A');
	rep(i,0,-x)putchar('N');
	rep(i,0,y)putchar('a');
	rep(i,0,-y)putchar('n');
	puts("");
}


Measured memory_bytes: 2100
import sys
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
lrs = lambda: [_ for _ in rs().split()]
lri = lambda: [int(_) for _ in rs().split()]
lrf = lambda: [float(_) for _ in rs().split()]

K = ri()
A, B = lri()
ans = 'NG'
for i in range(1, 1000):
    if A <= i * K <= B:
        ans = 'OK'
print(ans)

Measured memory_bytes: 61828
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long k = Long.parseLong(sc.next());
        if (n % k == 0) {
            System.out.println(0);
            return;
        }
        long mod = Math.abs(n % k - k);
        System.out.println(Math.min(n, mod));
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 100000

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int H,W;
    cin >> H >> W;
    int d[10][10];
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            cin >> d[i][j];
        }
    }
    int a[H][W];
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> a[i][j];
        }
    }
    for(int k = 0; k < 10; k++){
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(a[i][j] == -1) continue;
            ans += d[a[i][j]][1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
N, A, B = map(int, input().split())
V = sorted([int(x) for x in input().split()],reverse=True)
from statistics import mean
from math import comb
maxmean = mean(V[:A])
if V[0] != V[A-1]:
    n = V.count(V[A-1])
    k = V[:A].count(V[A-1])
    way = comb(n, k)
else:
    n = V.count(V[A-1])
    way = sum(comb(n, k) for k in range(A, min(n,B)+1))
print(maxmean)
print(way)

Measured memory_bytes: 10960
#include<bits/stdc++.h>
#define ff(i, x, y) for(int i = x;i <= y;i++)
using namespace std;
typedef long long ll;
ll mes[200010], n;
int main() {
	scanf("%lld", &n);
	ff(i, 1, n) {
		scanf("%lld", &mes[i]);
		mes[i] -= i;
	}
	sort(mes + 1, mes + 1 + n);
	ll ans = 1e15, tmp = 0;
	ff(i, 2, n)
		tmp = tmp + (mes[i] - mes[1]);
	ans = tmp;
	//printf("%lld\n", ans);
	ff(i, 2, n) {
		ll cha = mes[i] - mes[i - 1];
		tmp = tmp + cha * (i - 1) - cha * (n - i + 1);
		ans = min(ans, tmp);
	}
	printf("%lld", ans);
	return 0;
}

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

int main()
{
    int n,k;
    cin >> n >> k;
    vector<int> h(n);
    
    for(int i = 0; i < n; i++){
        cin>> h[i];
    }
    
    const int INF = 1e9+5;
    vector<int> dp(n+1, INF);
    
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j <= i+k; j++){
            if(j < n){
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }
    cout << dp[n-1];
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {
	
	int n;
	cin >> n;
	n--;
	int a, b;
	cin >> a >> b;
	if (n)cout << a + b << endl;
	else cout << "Hello World" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int sum = 0;
	for ( int i = 1; i <= N; i++ ) {
	    sum +=i;
	}
	System.out.println(sum);
    }

}


Measured memory_bytes: 21204
import string
d = string.digits + string.ascii_letters


def con(x, base):
    if x < 0:
        sign = -1
    elif x == 0:
        return d[0]
    else:
        sign = 1
    x *= sign
    digits = []

    while x:
        digits.append(d[int(x % base)])
        x = int(x / base)

    if sign < 0:
        digits.append('-')
    digits.reverse()

    return ''.join(digits)
n,k = map(int,input().strip().split())
v = con(n,k)
print(len(v))


Measured memory_bytes: 3772
import java.util.*;
public class Main {
	public static void myout(Object text){//standard output
		System.out.println(text);
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		//String tmp = sc.next();
		//int tmp = sc.nextInt();
		//Long tmp = sc.nextLong();
      int N = sc.nextInt();
      int K = sc.nextInt();
      int output = K;
      for(int i = 0; i < N - 1; i++){
        output = output * (K - 1);
      }
      myout(output);
	}
}


Measured memory_bytes: 21332
/**
 * @author      : omgursocute
 * @created     : 2020-02-23 23:09 (UTC+7)	
 * @task        : D
 */

#include <bits/stdc++.h>

using namespace std;

#define int long long
const int mod = 1e9 + 7;

int add(int a, int b) {
	int ret = a + b;
	if(ret >= mod) return ret - mod;
	else return ret;
}

int sub(int a, int b) {
	int ret = a - b;
	if(ret >= 0) return ret;
	else return ret + mod;
}

int mul(int a, int b) {
	return (a * b) % mod;
}

int powmod(int a, int b) {
	int ret = 1;
	while(b) {
		if(b & 1) ret = mul(ret, a);
		b >>= 1;
		a = mul(a, a);
	}
	return ret;
}

int divide(int a, int b){
	return mul(a, powmod(b, mod - 2));
}


int comb(int n, int k) {
	int ret = 1;
	for(int i = 1; i <= k; i++) {
		// ret *= ((n + 1) - i) / i
		ret = mul(ret, divide(sub(add(n, 1), i), i));
	}
	return ret;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n, a, b;
	cin >> n >> a >> b;
	int ans = sub(powmod(2, n), 1);
	ans = sub(ans, comb(n, a));
	ans = sub(ans, comb(n, b));
	cout << ans;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[a[i]] == i) {
			a[i] = -1, a[a[i]] = -1;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <list>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <tuple>

//....................................................................................................................//

using std::cin;
using std::cout;
using std::vector;
using std::list;
using std::unordered_set;
using std::set;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::swap;
using std::stack;
using std::deque;
using std::queue;
using std::ios_base;
using std::ifstream;
using std::ofstream;
using std::string;
using std::tuple;
using std::make_tuple;
using std::get;
using std::upper_bound;
using std::lower_bound;
using std::max_element;
using std::min_element;
using std::multiset;

//....................................................................................................................//

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long ul;

[[maybe_unused]] const string endl = "\n";
[[maybe_unused]] const string sep = " ";
[[maybe_unused]] const string yes = "YES\n";
[[maybe_unused]] const string no = "NO\n";
[[maybe_unused]] const string ng = "NG\n";
[[maybe_unused]] const string ok = "OK\n";
[[maybe_unused]] const double pi = acos(-1);

//....................................................................................................................//



int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout.precision(10);
    ll x;
    cin >> x;
    for (ll i = -2510; i < 2511; ++i) {
        for (ll j = -2510; j < 2511; ++j) {
            if (i * i * i * i * i - j * j * j * j * j == x) {
                cout << i << sep << j;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define arrdump(n,a) for(int i=0;i<n;i++) {cout<<((i>0)? " ":"")<<a[i];}cout<<"\n";


typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc045/tasks/arc061_a

int main() {
    string S; cin >> S;
    int len = S.length();
    ll ans = 0;

    for (int msk = 0; msk < 1 << (len-1); msk++) {
        ll num = S[0] - '0';
        for (int i = 0; i < len-1; i++) {
            if (msk & (1 << i)) {
                ans += num;
                num = 0;
            }
            num = num * 10 + (S[i+1] - '0');
        }
        ans += num;
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main(){
  int a,b;
  cin >> a >> b;
  int ans;
  double x = (double)(a+b)/(double)2;
  ans = (double)x+0.5;
  cout << ans <<endl;
}


Measured memory_bytes: 256
{-# LANGUAGE RecordWildCards #-}
-- import Data.ByteString.Char8 as BC (getLine, words, readInt)
-- import Prelude hiding (getLine, words)
import Data.List hiding (words)
import Data.Function (on)
import qualified Data.Map.Strict as M
import Data.Maybe (fromJust)
import Control.Monad
import Control.Arrow

main = do
    n <- readLn
    xs <- map read . words <$> getLine
    mapM_ print . fill n . solve . groupMnts $ xs
    where
        fill n xs = let filler = M.fromAscList . zip [1..n] $ repeat 0
                        filled = (M.fromAscList xs) `M.union` filler
                        in M.elems filled

type Stones = Int
type Index = Int

sample = [1,2,1,3,2,4,2,5,8,1] :: [Stones]
sample2 = [1,2]

data Group = Group { _leftMost :: Index, _stones :: Stones, _mnts :: Int }
           deriving (Show)

groupMnts :: [Stones] -> [Group]
groupMnts = joinMountains . groupByStones . attachIndex
    where
        attachIndex = flip zip [1..]
        groupByStones
            = groupBy ((==) `on` fst) . sortBy (compare `on` first negate)
        joinMountains
            = map (\ xs@((s,i):_)  -> Group i s (length xs))

mergeGroups :: Group -> Group -> Group
mergeGroups (Group i s m) (Group i' s' m')
    = if s == s'
         then Group (min i i') s (m+m')
         else error "cannot merge and I was too lazy to use Maybe"

solve :: [Group] -> [(Int,Int)]
solve = join . consume
    -- fixme
    where
        join = foldl' f []
        f [] n = [n]
        f acc@((i,n):r) x@(i',n') = if i == i' then (i,n+n'):r else x:acc
        consume [] = []
        consume [Group{..}] = [ (_leftMost, _stones * _mnts) ]
        consume (g0:g1:rest) =
            (_leftMost g0, (_stones g0 - _stones g1)* _mnts g0)
                : consume (mergeGroups g0{_stones=_stones g1} g1:rest)


Measured memory_bytes: 84476
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		/*int count = 0;*/
		
		Scanner scan = new Scanner(System.in);
	

		while (true) {
			
			int count = 0;
			
			int n = scan.nextInt();
			int x = scan.nextInt();

			if ((n == 0) && (x == 0)) {
				break;
			} 
			else {
				for (int i = 1; i <= n - 2; i++) {

					for (int j = i + 1; j <= n - 1; j++) {

						for (int k = j + 1; k <= n; k++) {

							if (i + j + k == x) {
								count++;
							}
						}
					}
				}
			}
			System.out.println(count);
		}
	}
}

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

int main() {
    int H, W; cin >> H >> W;
    string S[H];
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            int ans = 0;
            if (i != 0) { // upper
                if (S[i - 1][j] == '#') {
                    ans++;
                }
            }
            if (i != 0 && j != W) { // upper right
                if (S[i - 1][j + 1] == '#') {
                    ans++;
                }
            }
            if (i != 0 && j != 0) { // upper left
                if (S[i - 1][j - 1] == '#') {
                    ans++;
                }
            }
            if (j != W) { // right
                if (S[i][j + 1] == '#') {
                    ans++;
                }
            }
            if (j != 0) { // left
                if (S[i][j - 1] == '#') {
                    ans++;
                }
            }
            if (i != H) { // lower
                if (S[i + 1][j] == '#') {
                    ans++;
                }
            }
            if (j != W && i != H) { // lower right
                if (S[i + 1][j + 1] == '#') {
                    ans++;
                }
            }
            if (i != H && j != 0) { // lower left
                if (S[i + 1][j - 1] == '#') {
                    ans++;
                }
            }
            if (S[i][j] != '#') {
                S[i][j] = ans + '0';
            }
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cout << S[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 3596
a = [int(input()) for _ in range(5)]
b = []
for i in range(len(a)):
    if a[i] % 10 == 0:
        b.append(0)
    else:
        b.append(10 - (a[i] % 10))
c = b.index(max(b))

ans = 0
for i in range(5):
    if i !=c:
        if a[i] % 10 == 0:
            ans += a[i]
        else:
            ans += ((a[i] // 10) + 1) * 10
print(ans+a[c])



Measured memory_bytes: 3064
n,m,k=map(int,input().split())
ab=[]
for i in range(m):
    a,b=map(int,input().split())
    ab.append((a-1,b-1))
cd=[]
for i in range(k):
    c,d=map(int,input().split())
    cd.append((c-1,d-1))

def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        #sizeの大きいほうがx
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]

#初期化
#根なら-size,子なら親の頂点
par = [-1]*n
for a,b in ab:
    unite(a,b)
dp1=[0]*n
for i in range(n):
    dp1[i]=size(i)-1
for a,b in ab:
    dp1[a]-=1
    dp1[b]-=1
for c,d in cd:
    if same(c,d):
        dp1[c]-=1
        dp1[d]-=1
print(' '.join(map(str,dp1)))

Measured memory_bytes: 105432
#include <iostream>
#include <numeric>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#define mod 1000000007
using namespace std; 

int main(){
	int n; cin >> n;
	map<int,int> aa;
	for (int i=1;i<n+1;i++){
		aa[i]=0;
	}
	for (int i=1;i<n;i++){
		int p; cin >> p;
		aa[p]++;
	}
	for (auto val : aa){
		cout << val.second << "\n";
	} 
}


Measured memory_bytes: 13004
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while(sc.hasNext()) {
			classCheck( sc.nextDouble() );
		}
	}

	private static void classCheck(double nextDouble) {
		double w = nextDouble;

			if (w <= 48.00) {
				System.out.println("light fly");
			} else if (w > 48.00 && w <= 51.00) {
				System.out.println("fly");
			} else if (w > 51.00 && w <= 54.00) {
				System.out.println("bantam");
			} else if (w > 54.00 && w <= 57.00) {
				System.out.println("feather");
			} else if (w > 57.00 && w <= 60.00) {
				System.out.println("light");
			} else if (w > 60.00 && w <= 64.00) {
				System.out.println("light welter");
			} else if (w > 64.00 && w <= 69.00) {
				System.out.println("welter");
			} else if (w > 69.00 && w <= 75.00) {
				System.out.println("light middle");
			} else if (w > 75.00 && w <= 81.00) {
				System.out.println("middle");
			} else if (w > 81.00 && w <= 91.00) {
				System.out.println("light heavy");
			} else if (w > 91.00) {
				System.out.println("heavy");
			}
	}

}



Measured memory_bytes: 28004
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
const int mod=1e9+7;
int tong[61][2],n;
ll x,tot;
inline int kuai(int p,int q,int mod) {int tot=1;for(;q;p=(ll)p*p%mod,q>>=1) if(q&1) tot=(ll)tot*p%mod;return tot;}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(res i=1;i<=n;++i) {
		cin>>x;
		for(res j=0;j<=60;++j) ++tong[j][(x>>j)&1];
	}
	for(res i=0;i<=60;++i) tot+=(ll)kuai(2,i,mod)*tong[i][0]%mod*tong[i][1]%mod,tot%=mod;
	cout<<tot<<'\n';
	cout<<flush;
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  double x, h;
  while (cin >> x >> h, x) {
    cout << prec(8) << x * x + x * hypot(h, x / 2) * 2 << endl;
  }
}

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

using namespace std;

int a, b, c;

int main(){
	cin >> a >> b >> c;
	int t;
	t = a;
	a = b;
	b = t;
	
	t = a;
	a = c;
	c = t;
	
	printf("%d %d %d ",a,b,c);
	return 0;
}

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


int main() {
    long long int number;

    std::cin >> number;

    std::vector<char> name;
    while (number > 26) {
        long long int val = (number - 1) % 26;
        name.emplace_back('a' + (uint8_t)val);
        number = (number - 1) / 26;
    }
    name.emplace_back('a' + (uint8_t)number - 1);

    for (int i = name.size() - 1; i >= 0; i--) {
        std::cout << name[i];
    }
    std::cout << std::endl;
}


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

int main() {
  int N;
  cin >> N ;
  vector<pair<int,int>> A(N);
  
  for(int i=0;i<N;i++){
    cin >> A.at(i).first;
    A.at(i).second=i+1;
  }
  sort(A.begin(),A.end());
  for(int i=0;i<N;i++){
    cout << A.at(i).second<<" " ;
  }
  cout <<endl;
}



Measured memory_bytes: 1664
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>
#include <map>

using namespace std;

bool check(int x, int y, int max_x, int max_y, vector<vector<char>> map){
  bool ans = false;
  if(x >= 1){
    ans |= map[y][x-1] == '#';
  }
  if(y >= 1){
    ans |= map[y-1][x] == '#';
  }
  if(x < max_x - 1){
    ans |= map[y][x+1] == '#';
  }
  if(y < max_y - 1){
    ans |= map[y+1][x] == '#';
  }
  return ans;
}

int main(int argc, const char * argv[]) {
  int max_x, max_y;
  cin >> max_x >> max_y;
  vector<vector<char>> map(max_y, vector<char>(max_x));
  for(int i = 0; i < max_y; i++){
    for(int j = 0; j < max_x; j++){
      cin >> map[i][j];
    }
  }
  bool ans = true;
  for(int i = 0; i < max_y; i++){
    for(int j = 0; j < max_x; j++){
      if(map[i][j] == '#'){
        ans &=  check(j, i, max_x, max_y, map);
      }
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256