akhauriyash/Code-Regression huggingface dataset:
n=int(input())
shigoto=[]
for i in range(n):
  a,b=map(int,input().split())
  shigoto.append([b,a])

shigoto.sort()
t=0
for i in range(n):
  t+=shigoto[i][1]
  if t>shigoto[i][0]:
    print('No')
    exit()
print('Yes')

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

const int MAX_N = (int)2e5 + 5;
int a[MAX_N];
long long sum[MAX_N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", a + i);
        sum[i] = sum[i - 1] + a[i];
    }
    long long res = 1e18;
    for (int i = 1; i < n; i++)
        res = min(abs(sum[n] - sum[i] * 2), res);
    cout << res << '\n';
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int d,g;
  cin >> d >> g;
  int p[d],c[d];
  rep(i,d) cin >> p[i] >> c[i];
  
  int ans = 1001001001;
  
  rep(i,1<<d){
    //cout << i << ":";
    int temp = 0, point = 0, rest = -1; 
    rep(j,d){
      if(i>>j&1){
        temp += p[j];
        point += 100*(j+1)*p[j];
        point += c[j];
      }else{
        rest = j;
      }
    }
    //cout << temp << ";" << point << endl;
    
    if(point<g){
      int x = 100*(rest+1);
      int need = (g-point+x-1)/x;
      if(need>=p[rest]){continue;}
      temp += need;
    }
    
    ans = min(ans,temp);
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    string ans;
    int ab = a + b;
    int cd = c + d;
    if (ab > cd) ans = "Left";
    else if (ab < cd) ans = "Right";
    else ans = "Balanced";

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define int                 long long
#define FF(i,a,b)           for(int i=a;i<b;i++)
#define BF(i,a,b)           for(int i=a;i>=b;i--)
#define vi                  vector<int>
#define MAP                 map<int,int>
#define pb                  push_back
#define MP                  make_pair
#define F                   first
#define S                   second
#define pi                  pair<int,int>
#define all(v)              v.begin(),v.end()
#define PIE                 3.1415926535897932384626433832795
#define FastIO              ios::sync_with_stdio(0); cin.tie(0);cout.tie(0)
//#define ordered_set         tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
/*

    order_of_key (k) : Number of items strictly smaller than k .
    find_by_order(k) : K-th element in a set (counting from zero).

*/
/**************************************************************************************/
                       /*Global Variables*/
const int mod = 1e9+7;
const int N = 2e5+10;
const int inf = 3e18;

/**************************************************************************************/
template <typename A>istream& operator>>(istream& input,vector<A>& x) {for(auto& i:x)input>>i;return input;}
template<typename A>ostream& operator<<(ostream& output,vector<A>& x) {for(auto& i:x)output<<i<<' ';return output;}
int add(int a, int b){return (a%mod + b%mod + mod)%mod;}
int sub(int a, int b){return (a%mod - b%mod + mod)%mod;}
int mul(int a, int b){return ((a%mod)*(b%mod) + mod)%mod;}
signed main()
{
    FastIO;
    int T=1;
    //cin>>T;
    while(T--)
    {
        int n,k;
        cin>>n>>k;
        vi a(n);
        cin>>a;
        sort(all(a));
        int sum=0;
        for(int i=0;i<k;i++)
        {
            sum+=a[i];
        }
        cout<<sum<<"\n";
    }

}
/*
|| Do what you can with all you have,wherever you are. ||

|| Knowing is not enough, we must apply. Wishing is not enough, we must do. ||

|| A goal is a dream with deadline. ||

|| Whether you think you can or you think you can't, you're right. ||

|| A year from now you may wish you had started today ||
*/



Measured memory_bytes: 3640
#include<bits/stdc++.h> 
#define ll                 long long                            
#define ra                 return a;                                          
#define pb                 push_back                                                     
#define sti                stack<ll>
#define spi                stack<pair<ll,ll>>
#define S                  second
#define msi                map<string,ll >
#define msi                map<string,ll >
#define mii                map<ll ,ll >
#define dbg(x)             { cerr<<#x<<": "<<x<< endl; }
#define dbg2(x,y)          { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<endl; }
#define dbg3(x,y,z)        { cerr<<#x<<": "<<x<<" , "<<#y<<": "<<y<<" , "<<#z<<": "<<z<<endl; }
#define mis                map<ll , string>
#define rep(i,a,b)         for(ll  i=a;i<b;i++)
#define mpi                map<pair<ll ,ll >,ll >                                                
#define pii                pair<ll ,ll >
#define ppb                pop_back
#define F                  first 
#define vi                 vector<ll >
#define vii                vector<pair<ll , ll >>
#define si                 set <ll>
#define vs                 vector<string>
#define all(a)             (a).begin(),(a).end()
#define sz(x)              (ll )x.size()
#define hell               1000000007
#define bs                 binary_search
#define mp                 make_pair
#define qi                 queue<ll>
#define qs                 queue<string>
#define qpi                queue<pair<ll,ll>>
#define qps                queue<pair<ll,string>> 
#define endl               '\n' 
#define itr(a,it)          for(typeof(a.begin()) it=a.begin();it!=a.end();it++)// This will produce const_iterator for const object and normal iterator for non-const object
#define ss                 set<string>
using namespace std;
#define N  11
ll p[N];
bool check(ll a,vi b,ll c)
{
	ll cnt=0;
	for(auto i:b)
	{
		if(a&(1<<i))cnt++;
	}
	if(cnt%2==p[c])return true;
	else return false;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
//    cin>>t;
    while(t--)
{
    ll n,m;
    cin>>n>>m;
    ll k[m];
    vi v[m];
    rep(i,0,m)
    {
    	cin>>k[i];
    	rep(j,0,k[i])
    	{
    		ll a;
    		cin>>a;
    		v[i].pb(a-1);
    	}
    }
    rep(i,0,m)cin>>p[i];
    ll ans=0;
    rep(i,0,(ll)pow(2,n))
    {
    	ll cnt=0;
    	rep(j,0,m)
    	{
    		if(check(i,v[j],j)==true)cnt++;
    	}
    	if(cnt==m)ans++;
    }
    cout<<ans;
 }
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int search(int A[], int n, int key);
    
int main() {
    int i, n, A[10000+1], q, key, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++ ){
         scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for (i = 0; i < q; i++ ) {
    scanf("%d", &key);
    if ( search(A, n, key) ) sum++;
    }
    printf("%d\n", sum);
    return 0;
}
int search(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while (A[i] != key ) i++;
    return i != n;
}



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

const int N = 123;
int n , m , freq[150];
char a[N][N];
void yes(){ cout << "Yes"; exit(0); }
void no(){ cout << "No"; exit(0); }

int main()
{
	cin >> n >> m;
	for(int i=0;i<n;i++)
	{
		string z;
		cin >> z;
		for(int j=0;j<m;j++) freq[z[j]]++;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			a[i][j] = '@';
		}
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			int ct = 1;
			if(a[i][j] != '@') continue;
			sort(freq,freq+130);
			reverse(freq,freq+130);
			a[i][j] = 'a';
			if(a[i][m - 1 - j] == '@')
			{
				ct++;
				a[i][m - 1 - j] = 'a';
				if(a[n - 1 - i][m - 1 - j] == '@')
				{
					ct++;
					a[n - 1 - i][m - 1 - j] = 'a';
				}
			}
			if(a[n - 1 - i][j] == '@')
			{
				ct++;
				a[n - 1 - i][j] = 'a';
				if(a[n - 1 - i][m - 1 - j] == '@')
				{
					ct++;
					a[n - 1 - i][m - 1 - j] = 'a';
				}
			}
			int pos = -1;
			for(int j=40;j>=0;j--)
			{
				if(freq[j] >= ct)
				{
					pos = j;
					freq[j] -= ct;
					break;
				}
			}
			if(pos == -1) no();
		}
	}
	yes();
}

Measured memory_bytes: 256
fn main() {
    use std::collections::HashMap;
    let mut data: HashMap<u64, (usize, bool)> = HashMap::new();
    for i in 0..3 {
        for j in 0..3 {
            let (pos, b) = (i * 10 + j, false);
            data.insert(read(), (pos, b));
        }
    }

    let mut m: HashMap<usize, bool> = HashMap::new();
    let n: usize = read();
    for _ in 0..n {
        let num: u64 = read();
        if let Some(&(pos, _)) = data.get(&num) {
            m.insert(pos, true);
        }
    }

    // よこ
    if let (Some(&true), Some(&true), Some(&true)) = (m.get(&0), m.get(&1), m.get(&2)) {
        println!("Yes");
        return;
    }
    if let (Some(&true), Some(&true), Some(&true)) = (m.get(&10), m.get(&11), m.get(&12)) {
        println!("Yes");
        return;
    }
    if let (Some(&true), Some(&true), Some(&true)) = (m.get(&20), m.get(&21), m.get(&22)) {
        println!("Yes");
        return;
    }
    // たて
    if let (Some(&true), Some(&true), Some(&true)) = (m.get(&0), m.get(&10), m.get(&20)) {
        println!("Yes");
        return;
    }
    if let (Some(&true), Some(&true), Some(&true)) = (m.get(&1), m.get(&11), m.get(&21)) {
        println!("Yes");
        return;
    }
    if let (Some(&true), Some(&true), Some(&true)) = (m.get(&2), m.get(&12), m.get(&22)) {
        println!("Yes");
        return;
    }
    // ななめ
    if let (Some(&true), Some(&true), Some(&true)) = (m.get(&0), m.get(&11), m.get(&22)) {
        println!("Yes");
        return;
    }
    if let (Some(&true), Some(&true), Some(&true)) = (m.get(&2), m.get(&11), m.get(&20)) {
        println!("Yes");
        return;
    }
    println!("No");
}

use std::io::stdin;
use std::io::Read;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let token: String = cin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
from itertools import permutations

n = int(input())
p = tuple([int(item) for item in input().split()])
q = tuple([int(item) for item in input().split()])

array = [item for item in range(1, n+1)]

for i, perm in enumerate(permutations(array)):
    if perm == p:
        frm = i
    if perm == q:
        to = i
print(abs(frm - to))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
long long lim = 2e18 + 7;
int buf[65];

int main () {
    long long n;

    cin >> n;

    long long cur = 1;
    int step = 0;
    -- n;

    while (true) {
        if (cur  > lim / 26 ) goto CP;

        cur *= 26LL;

        if (n >= cur) {
            ++ step;
            n -= cur;
            continue;
        }

        CP:

        int top = 0;
        while (n > 0) {
            buf[top ++] = n % 26;
            n /= 26;
        }
        reverse(buf, buf + step + 1);
        for (int i = 0 ; i <= step ; ++ i) {
            printf("%c", buf[i] + 'a');
        }
        return 0;
    }

/**
546837504
*/


}


Measured memory_bytes: 3648
#include <iostream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

const int MAXN = 100000;

struct item
{
    int value, weight;
    char upper_case_letter;
    long long date;
    string name;

    // item(int value,int weight, char upper_case_letter, long long date, string name)
    // {
    //     this->value = value;
    //     this->weight = weight;
    //     this->upper_case_letter = upper_case_letter;
    //     this->date = date;
    //     this->name = name;
    // }

    bool operator< (const item & y)
    {
        if (value != y.value)
            return value < y.value;
        else if (weight != y. weight)
            return weight < y.weight;
        else if (upper_case_letter != y. upper_case_letter)
            return upper_case_letter < y.upper_case_letter;
        else if (date != y. date)
            return date < y.date;
        else
            return name < y.name;
    }

};



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

    vector<item> items(n);

    // int value, weight;
    // char upper_case_letter;
    // long long date;
    // string name;
    // while (n--)
    // {
    //     cin >> value >> weight >> upper_case_letter >> date >> name;
    //     items.push_back(item(value, weight, upper_case_letter, date, name));
    // }

    for (int i = 0; i < n; i++)
    {
        item & t = items[i];
        cin >> t.value 
            >> t.weight 
            >> t.upper_case_letter 
            >> t.date 
            >> t.name;
    }

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

    for (int i = 0; i < n; i++)
    {
        item & t = items[i];
        cout<< t.value << ' ' 
            << t.weight << ' ' 
            << t.upper_case_letter << ' ' 
            << t.date << ' '
            << t.name << endl;
    } 

}


Measured memory_bytes: 12184
n = gets.chomp.to_i
w = gets.chomp.split(' ').map(&:to_i)

s1 = 0
s2 = 0

n.times do
  if s1 <= s2
    s1 += w.shift
  else
    s2 += w.pop
  end
end

print((s1 - s2).abs)


Measured memory_bytes: 1788
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int main() {
    ll N, K; cin >> N >> K;
    vector<int> A(N);
    vector< vector<int> > rec(200010);
    for(int i=0; i<N; i++) {
        cin >> A[i]; A[i];
        rec[ A[i] ].emplace_back(i);
    }

    vector< pair<int, int> > nxt(N);
    for(int i=0; i<200010; i++) {
        for(size_t j=0; j<rec[i].size(); j++) {
            int u = rec[i][j], v = rec[i][(j+1)%rec[i].size()];
            int diff = v - u + N;
            if(diff > N) diff -= N;
            nxt[u] = make_pair(diff + 1, (v+1)%N);
        }
    }

    ll sum = 0;
    {
        int pos = 0;
        while(true) {
            int cnt, nidx; tie(cnt, nidx) = nxt[pos];
            sum += cnt;
            
            if(nidx == 0) break;
            pos = nidx;
        }
    }

    ll ope = N*K % sum;
    ll cur = 0;
    while(true) {
        int cnt, nidx; tie(cnt, nidx) = nxt[cur];
        if(ope - cnt >= 0) {
            ope -= cnt;
            cur = nidx;
        }
        else break;
    }

    vector<int> vec, cnt(200010);
    while(ope--) {
        if(cnt[ A[cur] ] == 0) {
            vec.emplace_back(A[cur]);
            cnt[ A[cur] ]++;
        }
        else {
            while(cnt[ A[cur] ] > 0) {
                int num = vec.back();
                cnt[num]--;
                vec.pop_back();
            }
        }
        (cur += 1) %= N;
    }

    for(size_t i=0; i<vec.size(); i++) {
        printf("%d%c", vec[i], i+1 == vec.size() ? '\n' : ' ');
    }
    return 0;
}


Measured memory_bytes: 16504
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

int main(){

    int n;
    cin >> n;
    vector<int> v(n);
    REP(i,n){cin >> v[i];}

    vector<int> w(v);
    std::sort(w.begin(),w.end());


    REP(i,n){
        if(v[i]==w[(n/2)-1]){
            cout<<w[n/2]<<endl;
        }else if(v[i]==w[n/2]){
            cout<<w[(n/2)-1]<<endl;
        }else if(v[i]>(w[(n/2)-1]+w[(n/2)])/2.0){
            cout<<w[(n/2)-1]<<endl;
        }else if(v[i]<(w[(n/2)-1]+w[(n/2)])/2.0){
            cout<<w[n/2]<<endl;
        }
    }



    return 0;
}

Measured memory_bytes: 3712
fn main() {
    let mut sc = Scanner::new();
    let a: Vec<usize> = sc.read_vec(7);

    let ans1 = if a[0] > 0 && a[3] > 0 && a[4] > 0 {
        a[1] + (a[0] - 1) / 2 * 2 + (a[3] - 1) / 2 * 2 + (a[4] - 1) / 2 * 2 + 3
    } else {
        0
    };
    let ans2 = a[1] + a[0] / 2 * 2 + a[3] / 2 * 2 + a[4] / 2 * 2;

    println!("{}", if ans1 > ans2 { ans1 } else { ans2 });
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        (0..n).map(|_| self.read()).collect()
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  string s;
  cin >> s;
  ll sum=0;  
rep(i,1 << s.size()-1){
  int next=0,count=1;
  for (int j=0; j < s.size()-1;j++){
      if ( i & 1 << j){
        sum+=stoll(s.substr(next,count));
        next=j+1;
        count=1;
      }else{
        count++;
      }
  }
  sum+=stoll(s.substr(next));
}
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int A,B,C,sum=0;
  scanf("%d %d %d",&A,&B,&C);
  for(int i=1;i<B;i++){
    if((A*i)%B==C){
      printf("YES");
      return 0;
    }
  }
  printf("NO");
}

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

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

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]#親
        self.rank = [1]*n # 木の高さ <- unite()で併合する際に木が深くなるのを避ける
        self.size = [1]*n # size[i] は i を根とするグループのサイズ


    def find(self, x): # x の根を返す
        if self.parent[x] == x: #xが根そのもの
            return x
        else:
            self.parent[x] = self.find(self.parent[x]) #あるxの親は必ず根になる <- 経路圧縮
            return self.parent[x]


    def unite(self, x, y): # x, y の属する集合を併合する
        x = self.find(x)#xにxの根を代入
        y = self.find(y)#yにyの根を代入
        if x!=y:
            if self.rank[x]<self.rank[y]:#根がxのほうがyのほうより浅い木
                self.parent[x] = y #xの親がyになる
                self.size[y]+=self.size[x] #yのサイズがxのサイズ分大きくなる
            else:
                self.parent[y] = x
                self.size[x]+=self.size[y]
                if self.rank[x]==self.rank[y]: #どちらも同じ深さの時
                    self.rank[x]+=1 #1だけ深くなる
    

    def is_same(self, x, y): # x, y が同じ集合に属するか判定する
        return self.find(x)==self.find(y)

    def group_size(self, x): # x が属する集合の大きさを返す
        return self.size[self.find(x)]

person_num, friend_relation_num, block_relation_num = [int(n) for n in input().rstrip().split()]
#friend
A, B = [0]*friend_relation_num, [0]*friend_relation_num
#block
C, D = [0]*block_relation_num, [0]*block_relation_num

direct = [[] for _ in range(person_num)]#直接の友達、ブロックされている人を管理
uf = UnionFind(person_num)#UnionFindでは根の番号は0から

for i in range(friend_relation_num):
    A[i], B[i] = [int(n)-1 for n in input().rstrip().split()]#UnionFindの根の番号に合わせる
    direct[A[i]].append(B[i])
    direct[B[i]].append(A[i])
    uf.unite(A[i], B[i])# 人A[i]と人B[i]を友達関係として繋ぐ

for i in range(block_relation_num):
    C[i], D[i] = [int(n)-1 for n in input().rstrip().split()]#UnionFindの根の番号に合わせる
    if uf.is_same(C[i], D[i]):
        direct[C[i]].append(D[i])
        direct[D[i]].append(C[i])
        # ブロックされていても他のグループなら処理してはいけない

answer = [0]*person_num
for i in range(person_num):
    answer[i] = uf.group_size(i) - len(direct[i]) -1 
    #i番目の人の友達候補は、その人が含まれる木のサイズから、
    # その人の直接の友達、ブロックされている人の数を引き、
    # 更に自分として-1する

print(*answer)


Measured memory_bytes: 41488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

const ll inf = LONG_LONG_MAX / 2 - 1;
ll n;
vector<ll> a;
vector<vector<ll>> dp;

ll dfs(ll l, ll r) {
    if (dp[l][r] != inf) return dp[l][r];
    ll turn = n - (r - l + 1);
    if (l == r) {
        if (turn % 2 == 0) dp[l][r] = a[l];
        else dp[l][r] = -a[l];
    }
    else {
        if (turn % 2 == 0) dp[l][r] = max(dfs(l + 1, r) + a[l], dfs(l, r - 1) + a[r]);
        else dp[l][r] = min(dfs(l + 1, r) - a[l], dfs(l, r - 1) - a[r]);
    }
    return dp[l][r];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    cin >> n;
    a.resize(n);
    rep(i, n) cin >> a[i];
    dp.resize(n, vector<ll>(n, inf));
    cout << dfs(0, n - 1) << endl;
    return 0;
}


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

int main(){
  int N ; 
  cin >> N ; 
  vector<int> a(N) ; 
  for(int i = 0 ; i < N ; i++) cin >> a.at(i) ; 
  sort(a.begin(),a.end()) ; 
  reverse(a.begin(),a.end());
  
  int alice = 0 , bob = 0 ; 
  
  for(int i = 0 ; i < N ; i++){
    if(i%2 == 0 ) alice += a.at(i) ; 
    else bob += a.at(i) ; 
  }
  
  cout << alice - bob << endl ;
  
}

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> prices(n);
	for (int i = 0; i < n; i++)
		cin >> prices[i];
	sort(prices.begin(), prices.end());
	cout << accumulate(prices.begin(), prices.begin() + k, 0) << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int x[20]; vector<int>R[20]; bool used[1 << 20];
int Abs(int g) { if (g < 0) { return -g; }return g; }
int main() {
	for (int i = 0; i < 20; i++) {
		for (int j = i + 1; j < 20; j++) {
			int p1 = i / 4, p2 = i % 4;
			int q1 = j / 4, q2 = j % 4;
			if (Abs(p1 - q1) <= 1 && Abs(p2 - q2) <= 1)R[i].push_back(j);
		}
	}
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < (1 << 20); j++)used[j] = false;
		for (int j = 0; j < 20; j++)cin >> x[j];
		queue<int>Q; Q.push((1 << 20) - 1); int res = 20;
		while (!Q.empty()) {
			int bit[20], d[20]; int r = Q.front(), t = 0; Q.pop();
			for (int j = 0; j < 20; j++) { bit[j] = (r / (1 << j)) % 2; t += bit[j]; }
			res = min(res, t); int cnt = 0;
			for (int j = 0; j < 20; j++) {
				if (bit[j] == 1) { d[cnt] = j; cnt++; }
			}
			for (int j = 0; j < cnt; j++) {
				for (int k = 0; k < R[j].size(); k++) {
					if (R[j][k] >= cnt)continue;
					if (x[d[j]] == x[d[R[j][k]]]) {
						int NUM = r - (1 << d[j]) - (1 << d[R[j][k]]);
						if (used[NUM] == true)continue;
						Q.push(NUM); used[NUM] = true;
					}
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}

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

using namespace std;

#define ll long long int



int main()
{
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
              ll n;
              cin>>n;
              if(n>=400 && n<=599)
                cout<<8;
              else
              if(n>=600 && n<=799)
                cout<<7;
              else
              if(n>=800 && n<=999)
                cout<<6;
              else
              if(n>=1000 && n<=1199)
                cout<<5;
              else
              if(n>=1200 && n<=1399)
                cout<<4;
              else
              if(n>=1400 && n<=1599)
                cout<<3;
              else
              if(n>=1600 && n<=1799)
                cout<<2;
              else
              if(n>=1800 && n<=1999)
                cout<<1;
              return(0);
}


Measured memory_bytes: 3640
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 3010;
int dp[mxn][mxn];

int32_t main(){
	NINJA;

	string a,b; cin >> a >> b;
	int n= sz(a);
	int m= sz(b);
	for1(i,n){
		for1(j,m){
			if(a[i-1]==b[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
			else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
		}
	}
	int ans = dp[n][m];
	string s;

	int i = n, j=m;
	while(i>=1 and j>=1){
		if(a[i-1]==b[j-1]){
			s += a[i-1];
			i--;
			j--;
		}else if(dp[i-1][j] > dp[i][j-1]){
			i--;
		}else{
			j--;
		}
		debug(s);
	}
	reverse(s.begin(), s.end());
	cout << s << endl;
	
	return 0;
}

Measured memory_bytes: 74188
#include <stdio.h>
int main() {
  int N, i;
  scanf("%d", &N);
  double A[N];
  double ans1, ans2;
  ans1 = ans2 = 0;
  for(i = 0; i < N; ++i) {
    scanf("%lf", &A[i]);
  }
  for(i = 0; i < N; ++i) {
    ans1 += 1.0 / A[i];
  }
  ans2 = 1.0 / ans1;
  printf("%f\n", ans2);
  return 0;
}

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

int main() {
	int a,b,c,d;
  	cin>>a>>b;
    
  if(a==1)
	a = 14;
  if(b ==1)
    b = 14;
  
  if(a>b)
    cout<<"Alice"<<endl;
  else if(a==b)
    cout<<"Draw"<<endl;
  else
    cout<<"Bob"<<endl;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  if(S.find("a") != -1 && S.find("b") != -1 && S.find("c") != -1){
    cout << YES << "\n";
  }else{
    cout << NO << "\n";
  }

}

// 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)
int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    int Hundred;
    int Ten;
    int One;
    if (n / 100 == 1){
        Hundred = 900;
    }else{
        Hundred = 100;
    }
    if ((n - 10) / 10 == 10 || (n - 10) / 10 == 90){
        Ten = 90;
    }else{
        Ten = 10;
    }
    if ((n - 1) % 10 == 0){
        One = 9;
    }else {
        One = 1;
    }
    cout << Hundred + Ten + One << endl;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        var flo = new int[n];

        var c = 0;

        while (true) {
            var exe = false;
            for (int i=0; i<n; i++) {
                if (flo[i] < ary[i]) {
                    exe = true;
                    c++;
                    while ( i < n && flo[i] < ary[i]) {
                        flo[i]++;
                        i++;
                    }
                }
            }
            if (!exe) break;
        }

        return c;
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl =strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}

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

namespace CSharpSample01
{
    
    class Program
    {

        static int RockButtle(int h1, int h2)
        {
            if(h1 == h2)
            {
                return h1;
            }
            else
            {
                return Math.Abs(h1 - h2);
            }

        }

        static int RockTournament(List<int> rock_hard, int N)
        {
            

            for(int i = 0; i < N; i++)
            {
                List<int> next_rock_hard = new List<int>();
                int rocknum = (int)Math.Pow(2, N - i);
                int h1 = 0;
                int h2 = 0;
                
                for (int j = 0; j < rocknum; j++)
                {
                    
                    if(j % 2 == 0)
                    {
                        h1 = rock_hard[j];
                    }
                    else
                    {
                        h2 = rock_hard[j];
                    }

                    if(j % 2 == 1)
                    {
                        next_rock_hard.Add(RockButtle(h1, h2));
                    }

                }

               
                rock_hard = new List<int>(next_rock_hard);

            }


            return rock_hard.First();

        }

        
        
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int num_rock = (int)Math.Pow(2, N);

            List<int> rock_hard = new List<int>();

            int old_hardness = 0;
            int now_hardness = 0;

            for(int i = 0; i < num_rock; i++)
            {
                int h = int.Parse(Console.ReadLine());

                if(i % 2 == 0)
                {
                    old_hardness = h;
                }
                else
                {
                    now_hardness = h;
                }
                    
                if(i % 2 == 1)
                {
                    rock_hard.Add(RockButtle(now_hardness, old_hardness));
                }
                
            }


            Console.WriteLine(RockTournament(rock_hard, N - 1));



        }
    }
}


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

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

	int n,x;
	cin>>n;
	if(n&1){
		cout<<((n-1)/2)*(n-1)<<"\n";
		for(int i=1;i<n;i++){
			cout<<i<<" "<<n<<"\n";
		}
		n-=1;
	}
	else{
		cout<<(n/2)*(n-2)<<"\n";
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(i+j==n+1) continue;
			cout<<i<<" "<<j<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.stream.IntStream;

public class Main {

	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int T = sc.nextInt();
		int[] a = new int[T];
		sc.fill(a);

		int max = IntStream.of(a).max().getAsInt();
		int sum = IntStream.of(a).sum() - max;

		System.out.println(Math.max(max - sum - 1, 0));
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}


Measured memory_bytes: 14404
import java.util.Scanner;

class Main {


    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        while (true){
        int n = scanner.nextInt();
        char op = scanner.next().charAt(0);
        int j = scanner.nextInt();

        if ( op == '?'){
            break;
        }

        switch (op){
            case '+': System.out.println(n+j); break;
            case '-': System.out.println(n-j); break;
            case '*': System.out.println(n*j); break;
            case '/': System.out.println(n/j); break;
            }
        }
    }
}


Measured memory_bytes: 26312
N, M = map(int, input().split())
L,R = map(int, input().split())

for i in range(M-1):
    a,b= map(int, input().split())
    if a<L and R<b:
        N=N
    elif L<=a<=R:
        L=a
    elif L<=b<=R:
        R=b
    else:
        print(0)
        exit(0)
print(R-L+1)




Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n; cin >> n;
   map<map<char, ll>,ll> m;
   while(n--){
      string s; cin >> s;
      map<char,ll> mp;
      for (auto &&j : s){
         mp[j]++;
      }
      m[mp]++;
   }
   ll ans = 0;
   for (auto &&i : m){
      ans += (i.second*(i.second-1))/2;
   }
   cout << ans << endl;
   
}

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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N, D;

bool check(vector<ll> &A, vector<ll> &B){
    ll sum = 0;
    FOR(i, 0, D){
        ll diff = A[i] - B[i];
        sum += diff*diff;
    }

    FOR(k, 1, 200){
        if(sum == k*k) return true;
    }
    return false;
}

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

    // input
    cin >> N >> D;

    vector<vector<ll> > A(N);
    FOR(i, 0, N){
        FOR(j, 0, D){
            ll a; cin >> a;
            A[i].push_back(a);
        }
    }

    ll count = 0;
    FOR(i, 0, N){
        FOR(j, i+1, N){
            if(check(A[i], A[j])) count++;
        }
    }
    p(count);
    
    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;

int main(){
    int n;
    cin >> n;
    vector<pair<int,int>> w(n);
    // firstは締切、secondはかかる時間
    rep(i,n) cin >> w[i].second >> w[i].first;
    sort(w.begin(),w.end());
    bool can = true;
    int t = 0;
    rep(i,n){
        t += w[i].second;
        if(t > w[i].first){
            can = false;
            break;
        }
    }
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define mp make_pair

using namespace std;

typedef long long int64;
typedef vector<int> vi;
typedef pair<int, int> ii;

class tasla {
 public:
  void solveOne(istream &in, ostream &out) {

  }

  void solve(std::istream &in, std::ostream &out) {
    int64 n;
    int64 a;
    int64 b;
    in >> n >> a >> b;
    if (a % 2 == b % 2) {
      out << abs(a - b) / 2 << endl;
    } else {
      out << min((a-1+b-1+1),(n-a+1+n-b))/2 << endl;
    }
  }
};


int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  tasla solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
	Scanner in = new Scanner(System.in);

	BigDecimal A = in.nextBigDecimal();
	BigDecimal B = in.nextBigDecimal();

	if(A.compareTo(B) > 0) System.out.println("GREATER");
	if(A.compareTo(B) == 0) System.out.println("EQUAL");
	if(A.compareTo(B) < 0) System.out.println("LESS");

	in.close();

	}
}



Measured memory_bytes: 25172
#幅優先探索
#参考↓
#https://abc007.contest.atcoder.jp/submissions/2107192

R,C = [int(i) for i in input().split()]
#sy,sx =  [int(i) for i in input().split()] #スタートの座標が入力で与えられる場合
#gy,gx =  [int(i) for i in input().split()] #ゴールの座標が入力で与えられる場合

#左上が(1,1)かつ周囲をシャープで囲むので、スタート地点は(2,2)となる
sy,sx = 2,2 
gy,gx = R+1, C+1

count=0 # .の数を数える

c_org = [ [ -1 if c_org == "#" else 9999 for c_org in input()] for r in range(R)]

#周囲をシャープ(というか-1)で囲む------------------------------
#c_org の左右を囲む
for i in range(R):
    c_org[i].append( -1)
    c_org[i].insert(0,-1)
    count=count+c_org[i].count(9999)
c_plus=[-1 for i in range(C+2)]

#上下も囲んだ配列をcとする
c=[]
c.append(c_plus)
for i in range(R):
    c.append(c_org[i])
c.append(c_plus)
#-------------------------------------------------------------------

#既にシャープで囲れている場合はこちら
#c=c_org[:]

c[sy - 1][sx - 1] = 0

neighbors = [(1, 0), (-1, 0), (0, 1), (0, -1)]
check_list = [(sy - 1, sx - 1)]
index = 0

while index < len(check_list):
    check_rc = check_list[index]
    for neighbor in [ (check_rc[0] + n[0], check_rc[1] + n[1]) for n in neighbors]:
        if c[neighbor[0]][neighbor[1]] >= 0 and  c[neighbor[0]][neighbor[1]] > c[check_rc[0]][check_rc[1]] + 1:
            c[neighbor[0]][neighbor[1]] = c[check_rc[0]][check_rc[1]] + 1
            check_list.append(neighbor)
    index += 1


#---------------------------------------------------
#print(c[gy - 1][gx - 1]) #最短移動数
#print(count)
if c[gy - 1][gx - 1]!=9999:
    print(count-c[gy - 1][gx - 1]-1)
else:
    print(-1)



Measured memory_bytes: 3188
N, M = map(int, input().split())
P = list(map(int, input().split()))

root = list(range(1, N+1))


def find(x):
    if root[x-1] == x:
        return x
    else:
        root[x-1] = find(root[x-1])
        return root[x-1]


for _ in range(M):
    x, y = map(int, input().split())
    x = find(x)
    y = find(y)
    root[max(x, y) - 1] = min(x, y)

ans = 0
for i in range(1, N+1):
    if find(i) == find(P[i-1]):
        ans += 1
print(ans)


Measured memory_bytes: 13880
import heapq

N,M = map(int,input().split())

T = list(map(int,input().split()))

memo = []
for t in T:
    memo.append(-t)
memo.sort()

for m in range(M):
    tmp = heapq.heappop(memo)
    tmp = int(tmp/2)
    heapq.heappush(memo,tmp)
print(-1*sum(memo))


Measured memory_bytes: 92384
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<ll>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

ll popHeap(vector<ll>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  ll i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  int i,j,k,cnt=0;
  int n;
  cin>>n;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  cnt=1;
  for(i=0;i<n;i++){
    if(a[i]==cnt)cnt++;
  }
  if(cnt==1){
    cout<<-1<<endl;
    return 0;
  }
  cout<<n-cnt+1<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

main(void)
{

    int i,roop=0;
    int x[10000];
    for(i=0;i<10000;i++){
        roop++;
        scanf("%d",&x[i]);
        if(x[i]==0) break;
    }
    for(i=0;i<roop;i++){
        printf("Case %d: %d\n",i+1,x[i]);
    }
}


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

bool cmp(pair<int, int> x, pair<int, int> y) { 
    return x.second < y.second;
}

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

    vector<pair<int, int>> vp(m);
    rep(i, m) cin >> vp[i].first >> vp[i].second;

    sort(vp.begin(), vp.end(), cmp);

    int ans = 0, cur = 0;
    rep(i, m) {
        if (vp[i].first >= cur) {
            cur = vp[i].second;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main(){
    int a[5];
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    for(int i=0;i<5;i++){
        if(a[i]==0){
            i++;
            cout<<i<<endl;
            return 0;
        }
    }
    
    
}

Measured memory_bytes: 3632
n, k = map(int, input().split())
s = input()
l = 1
w = 0
a = []
for c in s :
    if l^int(c) :
        l = int(c)
        a.append(w)
        w = 1
    else :
        w += 1
else :
    a.append(w)

m = 2*k+1
ans = [sum(a[0:m])]
i = 2
while i+m <= len(a) :
    ans.append(-sum(a[i-2:i])+ans[-1]+sum(a[i+m-2:i+m]))
    i += 2
else :
    ans.append(-sum(a[i-2:i])+ans[-1]+sum(a[i+m-2:]))

print(max(ans))

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

int main(void) {
  vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5,  2, 2, 1, 5, 1, 2, 1, 14,
                   1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout << a[K - 1] << endl;
  return 0;
}

Measured memory_bytes: 256