akhauriyash/Code-Regression huggingface dataset:
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {
    ll h, w;
    cin >> h >> w;
    int a[h][w], b[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    ll max_diff = 2 * 80 * 160;
    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = false;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = true;
    dp[0][0][-b[0][0] + a[0][0] + mid] = true;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if (!dp[i][j][l]) continue;
                if (i + 1 <= h - 1) {
                    dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] = true;
                    dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] = true;
                }
                if (j + 1 <= w - 1) {
                    dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] = true;
                    dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] = true;
                }
            }
        }
    }
    ll ans = 1e18;
    rep(i, max_diff) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}

Measured memory_bytes: 160256
#include<iostream>
using namespace std;
int main(){
 int i,j,n,m,a[51]={0},x,y;
 cin>>n>>m;
 for(i=0;i<m;i++)
    cin>>x>>y,a[x]++,a[y]++;
 for(i=1;i<=n;i++)
    cout<<a[i]<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
int main(){
  
  int N;
  cin >> N;
  ll B[N];
  for(int i=0;i<N;i++){
    ll n;
    cin >> n;
    B[i] = n - i -1;
  }

  sort(B, B+N);
  ll bmin = -B[N/2];

  ll ans = 0;
  for(int i=0;i<N;i++){
    ans += abs(B[i]+bmin);
  }
  cout << ans <<endl;
  


  return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#define ll long long
using namespace std;
const ll MOD=998244353,base=233;
map<ll,ll>f;
int n;
char s[105];
ll calc(char*s,int n)
{
	if(n==0)return 1;
	if(n==1)
	{
		if(s[1]=='1')return 2;
		else return 1;
	}
	ll v=0;
	for(int i=1;i<=n;i++)
	  v=v*base+s[i];
	if(f[v])return f[v];
	ll ans=calc(s+1,n-1);
	if(s[1]=='1')ans*=2;
	char tmp[105];
	for(int l=1;l<=n/2;l++)
	{
		for(int i=1;i<=l;i++)tmp[i]=s[i];
		for(int k=2;k*l<=n;k++)
		{
			for(int i=1;i<=l;i++)
			  tmp[i]=min(tmp[i],s[i+(k-1)*l]);
			ans+=calc(tmp,l)*calc(s+k*l,n-k*l)%MOD;
		}
	}
	return f[v]=ans%MOD;
}
int main()
{
	scanf("%s",s+1);
	n=(int)strlen(s+1);
	printf("%lld\n",calc(s,n));
	return 0;
}

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

const int N = 2e5;

vector<int> adj[N];
int n, mod, subt[N], pos[N];

int DFS(int i, int pre) {
    subt[i] = 1;
    for(int j : adj[i]) if(j != pre)
        subt[i] = (subt[i] * (1+DFS(j, i))) % mod;
    return subt[i];
}

void dfs(int i, int pre, int anc) {
    pos[i] = (++anc * subt[i]) % mod;
    int t = adj[i].size(), val[t];
    for(int j = 0; j < t; j++) {
        if(adj[i][j] == pre)
            val[j] = anc;
        else
            val[j] = subt[adj[i][j]]+1;
    }
    
    int mul[t][2];
    mul[0][0] = mul[t-1][1] = 1;
    for(int j = 1; j < t; j++)
        mul[j][0] = (mul[j-1][0]*val[j-1]) % mod;
    for(int j = t-2; j > -1; j--)
        mul[j][1] = (mul[j+1][1]*val[j+1]) % mod;
    
    for(int j = 0; j < t; j++)
        if(adj[i][j] != pre)
            dfs(adj[i][j], i, (mul[j][0]*mul[j][1]) % mod);
}

signed main() {
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> mod;
    
    for(int i = 1; i < n; i++) {
        int a, b; cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    
    DFS(0, -1);
    dfs(0, -1, 0);
    
    for(int i = 0; i < n; i++)
        cout << pos[i] << '\n';
}

Measured memory_bytes: 24064
#include<stdio.h>
#include<stdlib.h>

int main(){
  int i,j,minj,N,n,A[100],sum = 0,flag = 0;

  scanf("%d",&N);
  if(N < 1 || N > 100) exit(1);

  for(i = 0;i < N;i++){
    scanf("%d",&A[i]);
    if(A[i] < 0 || A[i] > 100) exit(2);
  }

  for(i = 0;i < N;i++){
    minj = i;
    flag = 0;
    for(j = i;j < N;j++){
      if(A[j] < A[minj]){
	minj = j;
	flag = 1;
      }
    }
    n = A[i];
    A[i] = A[minj];
    A[minj] = n;
    sum += flag;
  }

  for(i = 0;i < N;i++){
    if(i == 0) printf("%d",A[i]);
    else printf(" %d",A[i]);
  }

  printf("\n%d\n",sum);

  return 0;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define w(x) int x; cin>>x; while(x--)
#define mo 998244353
#define d arr0.size()
#define ba back()
using namespace std;
ll p=748683265;
int main(){
    int freq[200001]={0};
    ll n,a;
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a;
        freq[a]++;
    }
    f1(i,1,n){
        cout<<freq[i]<<endl;
    }
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    for (int i = 0; i < n; i++) {
        cout << s.at(i) << t.at(i);
    }
}

Measured memory_bytes: 3612
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

#define MAX_V 1000

struct edge{
	long long int to, cap, rev; // 行き先、容量、逆辺
};

vector<edge> G[MAX_V] = {};
bool used[MAX_V];

// from から to へ向かう容量 cap の辺を張る
void add_edge(long long int from, long long int to, long long int cap){
	G[from].push_back((edge){to, cap, G[to].size()});
	G[to].push_back((edge){from, 0, G[from].size() - 1}); // 有向辺
	// G[to].push_back((edge){from, cap, G[from].size() - 1}); // 無向辺
}

// 増加パスを dfs で探す
long long int dfs(int v, int t, long long int f){
	if(v == t){
		return f;
	}
	used[v] = true;
	for(int i = 0; i < G[v].size(); i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap > 0){
			long long int d = dfs(e.to, t, min(f, e.cap));
			if(d > 0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

// s から t への最大流を求める
long long int max_flow(int s, int t){
	long long int flow = 0;
	while(true){
		fill(used, used + MAX_V, 0);
		long long int f = dfs(s, t, INF);
		if(f == 0){
			return flow;
		}
		flow += f;
	}
}

int main(){
	
	int V, E;
	cin >> V >> E;
	
	for(int i = 0; i < E; i++){
		int num1, num2, c;
		cin >> num1 >> num2 >> c;
		add_edge(num1, num2, c);
	}
	
	cout << max_flow(0, V - 1) << endl;
	
	return 0;
}


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

int main(){
  long long  a,b,k;
  cin >> a >> b >> k;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
std::vector<int> A['   '];
int n, m, S['   '], a, l, r, i, d;
void U(int x, int u) {
  while (x <= n)
    S[x] += u, x += x & -x;
}
int Q(int x) {
  r = 0;
  while (x)
    r += S[x], x -= x & -x;
}
int main() {
  scanf("%d%d", &m, &n);
  for (i = 1; i <= m; i++)
    scanf("%d%d", &l, &r), A[r - l + 1].push_back(l);
  for (d = 1; d <= n; d++) {
    a = m;
    for (i = d; i <= n; i += d)
      Q(i), a += r;
    for (int u : A[d])
      U(u, 1), U(u + d, -1), m--;
    printf("%d\n", a);
  }
  return 0;
}

Measured memory_bytes: 53760
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int  H = sc.nextInt();
        int N = sc.nextInt();

        for (int i = 0; i < N; i++) {
            H -= sc.nextInt();
        }
        if(H<=0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }



}


Measured memory_bytes: 50808
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(x) x.begin(), x.end()

int main() {
  ll n, sum = 0;
  cin >> n;
  vector<ll> d(n);
  for (ll i = 0; i < n; i++) {
    cin >> d.at(i);
  }
  for (ll i = 0; i < n - 1; i++) {
    for (ll j = i + 1; j < n; j++) {
      sum += d.at(i) * d.at(j);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <set>

using namespace std;

int main(void){
    map<string,set<int> > data;
    int n;
    string str;
    
    while(cin>>str>>n){
        data[str].insert(n);
    }
    
    map<string,set<int> >::iterator m_it=data.begin();
    while(m_it!=data.end()){
        cout<<(*m_it).first<<endl;
        set<int>::iterator s_it=(*m_it).second.begin();
        while(s_it!=(*m_it).second.end()){
            cout<<*s_it;
            s_it++;
            (s_it==(*m_it).second.end())?cout<<endl:cout<<" ";
        }
        m_it++;
    }
    return 0;
}

Measured memory_bytes: 1228
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    string S1,S2;
    cin>>S1>>S2;
    for(int i=0;i<S1.size();i++){
        cout<<S1[i];
        if(i==S1.size()-1&&S2.size()<S1.size()){
            break;
        }
        cout<<S2[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>

/*
	入力例：
	3
	1 1 3
*/
int main(){
	int iDataNum,st,sx,sy,i;
	int ct,cx,cy;
	int strInput[5];
	for(int i=0;i<5;i++){
	 scanf("%d", &strInput[i]);
	}
	for(int i=0;i<5;i++){
		if (strInput[i] == 0) {
			printf("%d",i+1);
			return 0;
		}
	}


  return 0;
}

Measured memory_bytes: 1708
#include<stdio.h>
int main(void)
{
  int h,w;
  char s[100][100];
  int result[100][100];

  scanf("%d %d\n",&h,&w);
  for(int i=0;i<h;i++){
    scanf("%s",s[i]);
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      result[i][j]=0;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        result[i][j-1]++;
        result[i][j+1]++;
        result[i-1][j-1]++;
        result[i-1][j]++;
        result[i-1][j+1]++;
        result[i+1][j-1]++;
        result[i+1][j]++;
        result[i+1][j+1]++;
      }
    }
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j]=='#'){
        printf("#");
      }else{
        printf("%d",result[i][j]);
      }
    }
    puts(" ");
  }
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = map(int, readline().split())

    D = [0] * N
    for i in range(K):
        d = int(readline())
        A = [int(i) for i in readline().split()]
        for a in A:
            D[a-1] += 1
    
    ans = 0
    for i in D:
        if i == 0:
            ans += 1
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9220
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int>a;
    for(int i = 0;i<n;i++)
    {
        int x;
        cin>>x;
        a.push_back(x);
    }
    int t,k,r;
    cin>>t;
    for(int i = 0;i<t;i++)
    {
       cin>>k;
      r =  lower_bound(a.begin(),a.end(),k)-a.begin();
      cout<<r<<endl;
    }
    return 0;
}



Measured memory_bytes: 3468
n = int(input())
import heapq
A = list(map(int, input().split()))
a = max(A)
b = a//2
C = []
for i in range(n):
  heapq.heappush(C, abs(A[i]-b))
c = heapq.heappop(C)
print(a)
if c+b != a and A.count(c+b) == 1:
  print(c+b)
else:
  print(b-c)

Measured memory_bytes: 14196
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
int main(){
	double x,s=0;
	while(cin>>x){
		for(int i=1;i<=3;i++){
			s+=pow(x,i);
		}
		cout<<s<<endl;
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 500010;
const int MOD = 998244353;
const ll INF = 1000000LL * 1000000LL * 1000000LL % MOD;

vector <int> g[N];
ll pwr[N], sum[3][N];
int n, m, grundy[N], lim;

int main() {
  pwr[0] = 1;
  for (int i = 1; i < N; ++i) pwr[i] = INF * pwr[i - 1] % MOD;
  cin >> n;
  for (int it = 0; it < 3; ++it) {
    cin >> m;
    while (m--) {
      int u, v;
      scanf("%d %d", &u, &v);
      g[u].emplace_back(v);
      g[v].emplace_back(u);
    }
    for (int i = n; i >= 1; --i) {
      set <int> nei;
      for (int j : g[i]) if (j > i) nei.emplace(grundy[j]);
      grundy[i] = 0;
      for (int x : nei) {
        if (x == grundy[i]) ++grundy[i]; 
        else break;
      }
      lim = max(lim, grundy[i]);
      sum[it][grundy[i]] += pwr[i], sum[it][grundy[i]] %= MOD;
    }
    for (int i = 1; i <= n; ++i) g[i].clear();
  }
  ll ans = 0;
  for (int i = 0; i <= lim; ++i) {
    for (int j = 0; j <= lim; ++j) {
      ll cur = (sum[0][i] * sum[1][j] % MOD) * sum[2][i ^ j] % MOD;
      ans += cur, ans %= MOD;
    }
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 25216
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#include<algorithm>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------

//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = -1;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x]<0) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのま
        if(par[rx]>par[ry]) swap(rx,ry);
        par[rx]+=par[ry];
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){
        return -par[root(x)];
    }
};

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

    ll n,m;
    cin>>n>>m;
    UnionFind uf(n);
    
    ll ans = n*(n-1)/2;
    vec<pint> v;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        v.emplace_back(a,b);
    }

    vll res(m);

    rep(i,m){
        res[m-1-i]=ans;
        int a=v[m-1-i].fi;
        int b=v[m-1-i].se;
        if(uf.same(a,b)) {
            continue;
        }

        ans-=uf.size(a)*uf.size(b);
        uf.unite(a,b);
    }

    rep(i,m){
        cout<<res[i]<<endl;
    }
}

Measured memory_bytes: 5460
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, m, a[60], b[60];
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < m; j++) {
            if (i+1 == a[j]) {
                cnt++;
            }
            if (i+1 == b[j]) {
                cnt++;
            }
        }
        cout << cnt << endl;
    }
	return 0;
}

Measured memory_bytes: 256
kai = int(input())

AC = 0
WA = 0
TLE = 0
RE = 0


for _ in range(kai):
    a = input()
    if a == "AC":
        AC = AC+1
    elif a == "WA":
        WA = WA+1
    elif a == "TLE":
        TLE = TLE+1
    elif a == "RE":
        RE = RE+1

print(f"AC x {AC}")
print(f"WA x {WA}")
print(f"TLE x {TLE}")
print(f"RE x {RE}")


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

int main() 
{
	int n,count;
	cin >> n;
	count = 1;
	char* slimes = new char[n];
	cin >> slimes;
	for( int i=0 ; i<n-1 ; i++ )
	{
		if( slimes[i] != slimes[i+1] )
			count++;
	}
	delete[] slimes;
	cout << count << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define endl '\n'

int check(int m, vector<int> &a) {
     int ans = 0;
     for (int i = 0; i < a.size(); ++i) {
          ans += abs(a[i] - m - i);
     }
     return ans;
}

signed main() {
     ios::sync_with_stdio(false);
     cin.tie();
     cout.tie();
     int n;
     cin >> n;
     vector<int> a(n);
     for (auto &el : a) {
          cin >> el;
     }
     int l = -1e9 - 1, r = 1e9 + 1;
     while (r - l > 2) {
          int m2 = (2*r + l) / 3;
          int m1 = (r + 2*l) / 3;
          int mm1 = check(m1, a);
          int mm2 = check(m2, a);
          if (mm1 < mm2) {
               r = m2;
          } else {
               l = m1;
          }
     }
     cout << min(check(l, a), min(check(l + 1, a), check(l + 2, a)));
     return 0;
}


Measured memory_bytes: 1792
while True:
	m,f,r= map(int,input().split())
	if m==-1 and f==-1 and r==-1:
		break
	elif m==-1 or f==-1:
		print("F")
	elif m+f>=80:
		print("A")
	elif m+f>=65:
		print("B")
	elif m+f>=50:
		print("C")
	elif m+f>=30 and r >=50:
		print("C")
	elif m+f>=30:
		print("D")
	else:
		print("F")



Measured memory_bytes: 5596
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.append(0)
ans = 0
for i in range(n):
    beaten = min(a[i], b[i])
    b[i] -= beaten
    beaten2 = min(a[i + 1], b[i])
    a[i + 1] -= beaten2
    ans += beaten + beaten2
print(ans)


Measured memory_bytes: 18624
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func add(cnt map[int]int, v int) {
	if _, ok := cnt[v]; !ok {
		cnt[v] = 1
		return
	}
	cnt[v]++
}

func main() {
	sc := NewScanner(os.Stdin)
	A := sc.NextInt()
	B := sc.NextInt()
	a := []int{A, B, A - 1, B - 1}
	sort.Ints(a)
	fmt.Println(a[2] + a[3])
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func gcd(x, y int) int {
	if y > 0 {
		return gcd(y, x%y)
	}
	return x
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String str = reader.readLine();
            Dice dice = new Dice(str);
            str = reader.readLine();
            int q = Integer.parseInt(str);
 
            for (int i = 0; i < q; i++) {
                str = reader.readLine();
                String[] face = str.split(" ");
 
                int j = 0;
                int k = 0;
                for (j = 0; j < 6; j++) {
                    if (face[0].equals(dice.getFace(j))) {
                        break;
                    }
                }
                switch (j) {
                case 0:
                    break;
                case 1:
                    dice.moveN();
                    break;
                case 2:
                    dice.moveW();
                    break;
                case 3:
                    dice.moveE();
                    break;
                case 4:
                    dice.moveS();
                    break;
                case 5:
                    dice.moveN();
                    dice.moveN();
                    break;
                }
                for (k = 1; k < 5; k++) {
                    if (face[1].equals(dice.getFace(k))) {
                        break;
                    }
                }
                int right = 0;
                switch (k) {
                case 1:
                    right = 2;
                    break;
                case 2:
                    right = 4;
                    break;
                case 3:
                    right = 1;
                    break;
                case 4:
                    right = 3;
                    break;
                }
                System.out.println(dice.getFace(right));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
class Dice {
    private String face[];
    private String tmp;
     
    Dice (String str) {
        this.face = new String[6];
        this.face = str.split(" ");
    }
 
    public String getFace(int n) {
        return this.face[n];
    }
     
    public void moveN() {
        tmp = this.face[0];
        this.face[0] = this.face[1];
        this.face[1] = this.face[5];
        this.face[5] = this.face[4];
        this.face[4] = tmp;
    }
     
    public void moveE() {
        tmp = this.face[0];
        this.face[0] = this.face[3];
        this.face[3] = this.face[5];
        this.face[5] = this.face[2];
        this.face[2] = tmp;
    }
     
    public void moveW() {
        tmp = this.face[0];
        this.face[0] = this.face[2];
        this.face[2] = this.face[5];
        this.face[5] = this.face[3];
        this.face[3] = tmp;
    }
     
    public void moveS() {
        tmp = this.face[0];
        this.face[0] = this.face[4];
        this.face[4] = this.face[5];
        this.face[5] = this.face[1];
        this.face[1] = tmp;
    }
}

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

using namespace std;
int main() {
    ios::sync_with_stdio(false);
    int N,K;

    cin >> N >> K;
    int x[N];
    int sum=0;
    for(int i=0; i<N; i++) {
        cin >> x[i];
        int n = min(x[i], abs(x[i]-K));
        sum += n*2;
    }
    cout << sum << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <climits>

using namespace std;

typedef long long ll;

ll inf = LLONG_MAX;

int main() {
    ll n;   cin >> n;
    ll m = sqrt(n);

    ll ans = inf;

    for (int i = 1; i <= m; i++) {
        if (!(n % i)) {
            ans = min(ans, i + n/i - 2);
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
let n, k, q = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let rs = Array.make n 0
let s = for i = 1 to q do Scanf.scanf " %d" @@ fun a -> rs.(a - 1) <- rs.(a - 1) + 1 done; Array.fold_left (+) 0 rs
let _ = Array.iter (fun r -> print_endline @@ if k - (s - r) > 0 then "Yes" else "No") rs

Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
main(){
  unsigned long num[11]={63,6,91,79,102,109,125,39,127,111,0};
  int n,a,b=10;
  while(cin>>n,n!=-1){
    bitset<7> now((unsigned long)0);
    b=10;
    for(int i=0;i<n;i++){
      cin>>a;
      now=num[b]^num[a];
      for(int i=6;i>=0;i--){
	cout<<now[i];
      }
      cout<<endl;
      b=a;
    }
  }
}

Measured memory_bytes: 1160
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

bool G[8][8];

bool check(const vector<int> v) {
  int i = 0;
  for (int j : v) {
    if (!G[i][j]) {
      return false;
    }
    i = j;
  }
  return true;
}

int main() {
  int N, M; cin >> N >> M;
  vector<int> ids(N-1);
  for (int i = 0; i < M; ++i) {
    int a, b; cin >> a >> b; --a, --b;
    G[a][b] = true;
    G[b][a] = true;
  }
  for (int i = 0; i < N-1; ++i) {
    ids[i] = i + 1;
  }

  int cnt = 0;
  do {
    if (check(ids)) ++cnt;
  } while (next_permutation(ids.begin(), ids.end()));
  cout << cnt << endl;
}


Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextFloatVec() []float64 {
  L := strings.Split(NextLine(), " ")
  N := make([]float64, len(L))
  for i := range N {
    N[i], _ = strconv.ParseFloat(L[i], 64)
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func Dist(A, B *[]float64) float64 {
  return math.Sqrt(math.Pow((*B)[0] - (*A)[0], 2.0) + math.Pow((*B)[1] - (*A)[1], 2.0))
}

func MaxFloat64(A *[]float64) float64 {
  ret := (*A)[0]
  for _, a := range (*A) {
    if ret < a { ret = a }
  }
  return ret
}
func MinFloat64(A *[]float64) float64 {
  ret := (*A)[0]
  for _, a := range (*A) {
    if a < ret { ret = a }
  }
  return ret
}
func TriangleArea(A, B, C *[]float64) float64 {
  _B := []float64{(*B)[0] - (*A)[0], (*B)[1] - (*A)[1]}
  _C := []float64{(*C)[0] - (*A)[0], (*C)[1] - (*A)[1]}
  return math.Abs(_B[0] * _C[1] - _B[1] * _C[0])
}
func IncircleRadius(A, B, C *[]float64) float64 {
  AB := Dist(A, B)
  BC := Dist(B, C)
  CA := Dist(C, A)
  S := TriangleArea(A, B, C)
  return S / (AB + BC + CA)
}

func main() {
  A := NextFloatVec()
  B := NextFloatVec()
  C := NextFloatVec()
  AB := Dist(&A, &B)
  BC := Dist(&B, &C)
  CA := Dist(&C, &A)
  L := MaxFloat64(&[]float64{AB, BC, CA})
  r := IncircleRadius(&A, &B, &C)
  Write(L * r / (2 * r + L))
  Output()
}

Measured memory_bytes: 640
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0
for x in range(A+1):
  for y in range(B+1):
    for z in range(C+1):
      if 500*x+100*y+50*z==X:
        count+=1
      else:
        continue
        
print(count)

Measured memory_bytes: 3188
#include <iostream>

using namespace std;

int main() {
	int N, Q;
	while ( cin >> N >> Q, N || Q ) {
		int conv[101] = {0};
		for (int j = 0; j < N; ++j) {
			int M; cin >> M;
			for (int i = 0; i < M; ++i) {
				int date; cin >> date;
				++conv[date];
			}
		}
		int M = 0;
		int ans = 0;
		for (int i = 0; i < 101; ++i) {
			if (conv[i] >= Q && conv[i] > M) {
				ans = i;
				M = conv[i];
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int main(){
  int a,b,c;cin>>a>>b>>c;
  int t = 0;
  while(t <= c){
    if(t>=b && t<=c){
      cout << "OK" << endl;
      return 0;
    }
    t+=a;
  }
  cout << "NG" << endl;
}


Measured memory_bytes: 3632
// バブルソート

#include <iostream>
using namespace std;

void bubbleSort(int *A, int N);

int main()
{
    int N, A[100];
    cin >> N;
    for (int i=0; i<N; i++)
        cin >> A[i];
    bubbleSort(A, N);
    return 0;
}

void bubbleSort(int *A, int N)
{
    int flag = 1;  // 逆の隣接要素が存在する
    int tmp, count = 0;
    while (flag) {
        flag = 0;
        for (int j=N-1; j>0; j--) {
            if (A[j] < A[j-1]) {
                count++;
                tmp = A[j];
                A[j] = A[j-1];
                A[j-1] = tmp;
                flag = 1;
            }
        }
    }
    for (int i=0; i<N-1; i++)
        cout << A[i] << ' ';
    cout << A[N-1] << '\n';
    cout << count << '\n';
}


Measured memory_bytes: 3088
#ifdef OJ_MISC_OFFLINE

#include "prolog.h"

#else
#define LOG
#define PRINT
#define LCERR
#include <iostream>
auto optimize_cpp_stdio = []() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::setvbuf(stdout, nullptr, _IOFBF, BUFSIZ);
    return 0;
}();
#endif

#include <algorithm>
#include <array>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

namespace {

using namespace std;

class Solution {
public:
    vector<int> exception_handling(vector<int>& nums) {
        int max1 = numeric_limits<int>::min();
        int max2 = numeric_limits<int>::min();
        for (size_t i = 0; i < nums.size(); ++i) {
            if (nums[i] >= max1) {
                max2 = max1;
                max1 = nums[i];
            } else if (nums[i] > max2) {
                max2 = nums[i];
            }
        }
        vector<int> result;
        for (size_t i = 0; i < nums.size(); ++i) {
            if (nums[i] == max1) {
                result.emplace_back(max2);
            } else {
                result.emplace_back(max1);
            }
        }
        return result;
    }
};

int solve() {
    Solution solution;
    // handle IO here
    int N;
    cin >> N;
    vector<int> nums(N);
    for (int i = 0; i < N; ++i) {
        cin >> nums[i];
    }
    auto result = solution.exception_handling(nums);
    for (auto n : result) {
        cout << n << endl;
    }
    return 0;
}

} // anonymous namespace

#ifdef OJ_MISC_OFFLINE

#include "epilog.h"

#else

int main() {
    return solve();
}

#endif


Measured memory_bytes: 3316
package main

import "fmt"

func main() {
	var S string
	fmt.Scanf("%s", &S)
	N := len(S)
	flags := make([]bool, N)
	for i := range flags {
		if S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T' {
			flags[i] = true
		}
	}

	maxLen := 0
	ll := 0
	for _, v := range flags {
		if v {
			if ll != 0 {
				ll++
			} else {
				ll = 1
			}
			if ll > maxLen {
				maxLen = ll
			}
		} else {
			ll = 0
		}
	}
	fmt.Println(maxLen)
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int c[3], N, ans = 0, c0, c1, c2, tmp, tmp1, tmp2;
  cin >> c[0] >> c[1] >> c[2] >> N;
  sort(c, c + 3);
  c2 = N / c[2];
  for(int i = 0; i <= c2; ++i) {
    tmp = N;
    tmp -= i * c[2];
    if(tmp == 0) {++ans; continue;}
    c1 = tmp / c[1];
    for(int j = 0; j <= c1; ++j) {
      tmp1 = tmp;
      tmp1 -= j * c[1];
      if(tmp1 == 0) {++ans; continue;}
      else if(tmp1 % c[0] == 0) ++ans;
    }
  }
  cout << ans << endl; 
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	_ = scanInt(sc)
	str := scanString(sc)
	max := 0
	for i := 0; i < len(str); i++ {
		lsets := map[byte]struct{}{}
		rsets := map[byte]struct{}{}
		num := 0
		for j := 0; j < len(str); j++ {
			if j < i {
				lsets[str[j]] = struct{}{}
			} else {
				if _, ok := lsets[str[j]]; ok {
					if _, ok := rsets[str[j]]; !ok {
						rsets[str[j]] = struct{}{}
						num++
					}
				}
			}
			if max < num {
				max = num
			}
		}
	}
	return max
}

func resolve(n int) int {
	return n
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1812
using System;
using System.Linq;
  
namespace Linear_Search
{
    class Program
    {
        static void Main()
        {
            Console.ReadLine();
            var a = Console.ReadLine().Split();
            Console.ReadLine();
            var b = Console.ReadLine().Split();
            Console.WriteLine("{0}", a.Intersect(b).Count());
        }
    }
}

Measured memory_bytes: 22628
n = gets.to_i
h = Hash.new(0)
n.times{
    name, number = gets.chomp.split
    h[name] += number.to_i
}
h2 = h.to_a.map{|name, number| [name, name.length, number]}.sort_by{|name, length, number| [length, name]}
h2.each{|name, length, number| puts "#{name} #{number}"}


Measured memory_bytes: 6872
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n,m;cin>>n>>m;
  cout<<(n+2*m)/(2*m+1)<<endl;
  return 0;
}


Measured memory_bytes: 3600
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	typedef pair<int, int> Node;
	priority_queue<Node, vector<Node>, greater<Node>> pq;
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		pq.emplace(x, 1);
	}
	while (m--)
	{
		int b, c;
		cin >> b >> c;
		int tot = 0;
		while (!pq.empty() && b > 0 && pq.top().first < c)
		{
			int val, cnt;
			tie(val, cnt) = pq.top();
			pq.pop();
			int o = min(b, cnt);
			b -= o;
			cnt -= o;
			tot += o;
			if (cnt > 0)
				pq.emplace(val, cnt);
		}
		if (tot)
			pq.emplace(c, tot);
	}
	LL ans = 0;
	while (!pq.empty())
	{
		auto& p = pq.top();
		ans += 1LL * p.first * p.second;
		pq.pop();
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N,M,t;
  cin >> N >> M >> t;
  map<int, int>  a;
  for(int i=0;i<t;++i){
    int x;
    cin >> x;
    a[x] = 1;
  }
  for(int i=0;i<N-1;++i){
    int x;
    cin >> x;
    for(int j=0;j<x;++j){
      int y;
      cin >> y;
      if(a.count(y)){
        ++a[y];
      }
    }
  }
  int cnt = 0;
  for(auto p : a){
    auto v = p.second;
    if(v==N){
      ++cnt;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read # 全読み込み
readline = sys.stdin.buffer.readline # 一行読み込み
readlines = sys.stdin.buffer.readlines # 一行ずつ全読み込み
sys.setrecursionlimit(10**7) # 再帰限界変更（デフォルトは1000）

"""
# 文字列（数値変換も含む）
n = readline().rstrip() # １行に１文字列のみ
lis = readline().rstrip().split() # # １行に複数の文字列

# 数値（文字変換も含む）
n = int(readline().rstrip()) # １行に数値１個のみ
a, b, c = map(int,readline().rstrip().split()) # １行に複数の数値
A = list(map(int,readline().rstrip().split()))  # １行に複数の数値（リスト受け取り）
lis = [readline().rstrip().split() for _ in range(n)] # 

"""

n=int(readline().rstrip())
d=list(map(int,readline().rstrip().split()))

d_inv=sorted(d)

print(d_inv[int(len(d)/2)]-d_inv[int(len(d)/2-1)])


Measured memory_bytes: 53104
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 40000;
const long long INF = 1LL << 60;

/* typedef */

typedef long long ll;

/* global variables */

int n, m;
ll h0, a0, d0, s0;
ll hs[MAX_N], as[MAX_N], ds[MAX_N], ss[MAX_N];
ll tns[MAX_N], dms[MAX_N];
int ids[MAX_N];

/* subroutines */

bool idcmp(const int& a, const int& b) {
  return tns[a] * dms[b] < tns[b] * dms[a];
}

/* main */

int main() {
  cin >> n;
  cin >> h0 >> a0 >> d0 >> s0;

  m = 0;

  for (int i = 0; i < n; i++) {
    cin >> hs[i] >> as[i] >> ds[i] >> ss[i];
    int ai = a0 - ds[i], di = as[i] - d0;
    tns[i] = (ai > 0) ? (hs[i] + ai - 1) / ai : INF;
    dms[i] = (di > 0) ? di : 0;
    if (ai <= 0 && di > 0) {
      cout << -1 << endl;
      return 0;
    }

    if (di > 0) ids[m++] = i;
  }

  sort(ids, ids + m, idcmp);

  ll dsum = 0, tnsum = 0;
  
  for (int i = 0; i < m; i++) {
    int id = ids[i];
    //printf("id=%d, tns[id]=%lld, dms[id]=%lld\n", id, tns[id], dms[id]);

    tnsum += tns[id];
    dsum += (s0 > ss[id] ? tnsum - 1 : tnsum) * dms[id];

    if (dsum >= h0) {
      dsum = -1;
      break;
    }
  }

  cout << dsum << endl;
  
  return 0;
}

Measured memory_bytes: 3144
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

struct UnionFind {
    par: Vec<usize>,
    rank: Vec<usize>,
}

impl UnionFind {
    fn new(n: usize) -> UnionFind {
        let mut vec = vec![0;n];
        for i in 0..n {
            vec[i] = i;
        }
        UnionFind {
            par : vec,
            rank : vec![0;n],
        }
    }

    fn find(&mut self, x: usize) -> usize {
        if x == self.par[x] {
            x
        }else{
            let par = self.par[x];
            let res = self.find(par);
            self.par[x] = res;
            res
        }
    }

    fn same(&mut self, a: usize, b: usize) -> bool {
        self.find(a) == self.find(b)
    }

    fn unite(&mut self, a: usize, b: usize){
        let apar = self.find(a);
        let bpar = self.find(b);
        if self.rank[apar] > self.rank[bpar] {
            self.par[bpar] = apar;
        }else{
            self.par[apar] = bpar;
            if self.rank[apar] == self.rank[bpar] {
                self.rank[bpar] += 1;
            }
        }
    }
}

use std::collections::HashMap;

fn main() {
    let (n, k, l) = get!(usize, usize, usize);
    let mut kq = UnionFind::new(n);
    let mut lq = UnionFind::new(n);
    for _ in 0..k {
        let (p, q) = get!(usize, usize);
        kq.unite(p-1, q-1);
    }
    for _ in 0..l {
        let (r, s) = get!(usize, usize);
        lq.unite(r-1, s-1);
    }
    let mut map = HashMap::new();
    for i in 0..n {
        let key = (kq.find(i), lq.find(i));
        let x = match map.get(&key) {
            Some(x) => x+1,
            None => 1
        };
        map.insert(key, x);
    }
    let mut ans = Vec::new();
    for i in 0..n {
        let key = (kq.find(i), lq.find(i));
        if let Some(x) = map.get(&key) {
            ans.push(x.to_string());
        }
        
    }
    println!("{}", ans.join(" "));
}

Measured memory_bytes: 28320
#include<stdio.h>
	int main(){
		int a,b;
		char op;
		while(1){
			scanf("%d %c %d",&a,&op,&b);
			if(op=='+'){
				printf("%d\n",a+b);
				}else if(op=='-'){
					printf("%d\n",a-b);
				}else if(op=='*'){
					printf("%d\n",a*b);
				}else if(op=='/'){
					printf("%d\n",a/b);
				}if(op=='?')break;
		}
		return 0;
	}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define MAX (int)1e9 + 99
#define vi vector<int>
#define vb vector<bool>
#define ll long long
#define ull unsigned long long
#define vll vector<ll>
#define pa pair<int, int>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define MOD 998244353
#define bitcnt(x) __builtin_popcount(x)
#define gcd(a,b) __gcd(a,b)
#define all(x) (x).begin(),(x).end()
#define ts(x) to_string(x)
#define set0(x) memset(x, 0, sizeof(x))
ll fastPowMod(ll a, ll p,ll mod){ if(p==0) return 1; ll z = fastPowMod(a,p/2,mod); z = (z*z)%mod; if(p%2) z = (z*a)%mod; return z; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is;}
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) {if (!v.empty()) {os << v.front();for (int i = 1; i < v.size(); ++i) os << ' ' << v[i];} return os;}

vi graph[100001];
vi dp(100001,0);
vb visited(100001,false);

int dfs(int i)
{
    if(visited[i]) return dp[i];

    visited[i] = true;

    for(int j: graph[i])
    {
        dp[i] = max(dp[i], 1+dfs(j));
    }



    return dp[i];

}


void solve()
{
    int n,m;
    cin>>n>>m;
    rep(i,m)
    {
        int x,y;
        cin>>x>>y;
        graph[x].pb(y);

    }

    int ans=0;
    srep(i,1,n) ans=max(ans,dfs(i));
    cout<<ans;
}

int main()
{
    fastio;

    solve();
    cout<<"\n";
    
    return 0;
}

Measured memory_bytes: 11104
#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

typedef long long ll;
typedef unsigned long long ull;

string solve(string s) {
    int n = s.size();
    if (s.at(n - 1) == 's') {
        return s + "es";
    }
    return s + 's';
}

int main() {
    string s;
    cin >> s;
    cout << solve(s) << endl;
}

Measured memory_bytes: 3632
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;
    vector<P> vp(n);
    rep(i, n){
        int a, b;
        cin >> a >> b;
        vp[i] = {b, a};
    }
    sort(ALL(vp));

    int now = 0;
    rep(i, n){
        now += vp[i].second;
        if(now > vp[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<string.h>

using namespace std;

int main()
{

    char ch[2048];

    cin.getline(ch,2048,'\n');


    int len=strlen(ch);

    for(int i=0;i<len;i++)
    {
        if(ch[i]>='a'&&ch[i]<='z')
        {
            ch[i]+='A'-'a';
        }else if(ch[i]<='Z'&&ch[i]>='A')
        {
            ch[i]+='a'-'A';
        }
    }

    cout<<ch<<endl;

    return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define MAX 100005
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
using namespace std;

typedef long long ll;

int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int a, b, c;

    cin>>a>>b>>c;
    cout<<max(0, (c - (a - b)))<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n;
vvi a;
map<vi,int> m;

void f(vi a,int t){
	for(int i=0;i<4;i++){
		m[a]+=t;
		for(int j=0;j<3;j++) swap(a[j],a[j+1]);
	}
}

int main(){
	cin>>n;
	a=vvi(n,vi(4));
	for(int i=0;i<n;i++){
		for(int j=0;j<4;j++) cin>>a[i][j];
		f(a[i],1);
	}
	ll res=0;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(i!=j){
		f(a[i],-1);f(a[j],-1);
		for(int k=0;k<4;k++){
			int A[2][4];
			for(int l=0;l<4;l++) A[0][l]=a[i][l];
			for(int l=0;l<4;l++) A[1][l]=a[j][(4-l+k)%4];
			map<vi,int> M;
			for(int l=0;l<4;l++){
				vi b(4);
				b[0]=A[0][(l+1)%4];b[1]=A[0][l];
				b[3]=A[1][(l+1)%4];b[2]=A[1][l];
				vi b_=b;
				for(int I=0;I<3;I++){
					for(int J=0;J<3;J++) swap(b_[J],b_[J+1]);
					b=min(b,b_);
				}
				M[b]++;
			}
			ll tmp=1;
			for(auto it=M.begin();it!=M.end();it++){
				vi b=it->first;
				ll t=it->second,B=m[b],type=1;
				if(b[0]==b[1]&&b[0]==b[2]&&b[0]==b[3]) type=4;
				else if(b[0]==b[2]&&b[1]==b[3]) type=2;
				for(int l=0;l<t;l++) tmp*=B-type*l;
			}
			res+=tmp;
		}
		f(a[i],1);f(a[j],1);
	}
	cout<<res/6<<endl;
}

Measured memory_bytes: 140032