akhauriyash/Code-Regression huggingface dataset:
local read = io.read
local insert = table.insert

local h, w, m = read("n", "n", "n")
local grid_t = {}
for i = 1, h do
	grid_t[i] = {}
end

local sum_h_i_t, sum_w_i_t = {}, {}
for i = 1, m do
	local h_i = read("n")
	local w_i = read("n")
	grid_t[h_i][w_i] = true
	sum_h_i_t[h_i] = sum_h_i_t[h_i] and sum_h_i_t[h_i] + 1 or 1
	sum_w_i_t[w_i] = sum_w_i_t[w_i] and sum_w_i_t[w_i] + 1 or 1
end

local max_h, max_w = 0, 0
local max_h_index_t, max_w_index_t = {}, {}
for i = 1, h do
	if sum_h_i_t[i] and sum_h_i_t[i] > max_h then
		max_h = sum_h_i_t[i]
		max_h_index_t = {i}
	elseif sum_h_i_t[i] and sum_h_i_t[i] == max_h then
		insert(max_h_index_t, i)
	end
end
for i = 1, w do
	if sum_w_i_t[i] and sum_w_i_t[i] > max_w then
		max_w = sum_w_i_t[i]
		max_w_index_t = {i}
	elseif sum_w_i_t[i] and sum_w_i_t[i] == max_w then
		insert(max_w_index_t, i)
	end
end

local is_dup = true
for i = 1, #max_h_index_t do
	for j = 1, #max_w_index_t do
		if grid_t[max_h_index_t[i]][max_w_index_t[j]] == nil then
			is_dup = false
			break
		end
	end
	if not is_dup then
		break
	end
end

print(is_dup and max_h + max_w - 1 or max_h + max_w)


Measured memory_bytes: 51248
//#define _GLIBCXX_DEBUG//実行時、何も出なかったらこれを使う
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>
#include<climits>
#include<limits>//
#include <stdio.h>//
#include<cmath>
#include<iomanip>

using namespace std;

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

typedef long long ll;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

int dy[] = {1,0,-1,0}; //次に行くところ
int dx[] = {0,1,0,-1}; //s上に同じ

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,m,c = 0;
  cin >> n >> m;
  vector<int> a(m);
  
  for (int i = 0; i < m; i++){
    cin >> a[i];
    c+=a[i];
  }
  
  if (c <= n){
    cout << n-c << '\n';
  }else
  {
    cout << "-1\n";
  }
  
  
  
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

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

    double a[n], b[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }

    sort(a, a + n);
    sort(b, b + n);

    double mida, midb;
    if(n % 2 == 0) {
        mida = (a[n/2-1] + a[n/2]) / 2;
        midb = (b[n/2-1] + b[n/2]) / 2;
    } else {
        mida = a[(n-1)/2];
        midb = b[(n-1)/2];
    }

    int ans;
    if(n % 2 != 0) {
        ans = (int)midb - (int)mida + 1;
    } else {
        ans = (int)(midb*2) - (int)(mida*2) + 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6856
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin >> n >> k;
	int a[n],b[k+1]={0},i,j;
	for(i=0;i<n;i++)
	cin >> a[i];
	for(i=1;i<=k;i++)
	{
		for(j=0;j<n;j++)
		{
			if(i>=a[j]&&b[i-a[j]]==0)
			b[i]=1;
		}
	}
	if(b[k])
	cout << "First";
	else
	cout << "Second";
	return 0;
}

Measured memory_bytes: 640
//============================================================================
// Name        : hoba.cpp :)
// Author      : (O_O Diab) (Why_not) (el 3AQ)
// Version     :
// Copyright   : please, Don't touch me :(
// Description : problem G in C++
/* IDEA        : interesting problem the main idea
 * to gain the longest K we need to find seq which start and end with the same
 * number so for each number let us store the start and end pos we can do it easily
 * using set
 * depend on OVERLAP
 */
//============================================================================
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define rw freopen("input.txt","r",stdin),freopen("output.txt","w",stdout);
#define pb push_back
#define F first
#define S second
#define pf push_front
#define lp(i,a,b) for (int i=a;i<=(int)b;++i)
#define lp2(i,a,b) for (int i=a;i>=b;--i)
#define f(x) return cout<<x<<"\n",0
#define pii pair<int,int>
#define pll pair<ll,ll>
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define p(x) cout<<#x<<" = { "<<x<<" } \n"
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define EPS 1e-6
// to convert string to number use int a = stoi(string);
// to convert number to string use string s = to_string(int);
#define FAST ios::sync_with_stdio(0),ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define clr(c,x) memset(c,x,sizeof(c));
using namespace __gnu_pbds;
using namespace std;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int dx[] = { 0, 1, 0, -1, 1, -1, 1, -1 };
const int dy[] = { 1, 0, -1, 0, 1, -1, -1, 1 };
const int N = 1e5 + 5, mod = (int) 1e9 + 7, INF = 0x3f3f3f3f;
inline ll compute(ll x) {
	ll fact = 1;
	for (ll i = 1; i <= x; ++i) {
		fact *= i;
		fact %= mod;
	}
	return fact;
}
int main() {
	FAST;
	ll a,
	b;
	cin >> a >> b;
	if (abs(a - b) > 1)
		f(0);
	ll fact1 = compute(a);
	ll fact2 = compute(b);
	ll ans = fact1 * fact2;
	ans %= mod;
	if (a == b)
		ans *= 2;
	ans %= mod;
	f(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN = 2000;
const ll INF = 1e16;
ll a[MAXN + 5], m[MAXN + 5];

int main()
{
    ll n, x;
    cin >> n >> x;
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
        m[i] = a[i];
        ans += a[i];
    }
    for (ll k = 1; k <= n - 1; k++)
    {
        ll sum = 0;
        for (ll i = 0; i < n; i++)
        {
            m[i] = min(m[i], a[(i - k + n) % n]);
            sum += m[i];
        }
        ans = min(ans, sum + x * k);
    }
    cout<<ans;
}

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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

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;
}

int main(){

    ll n;
    cin >> n;
    map<ll, ll> mp;
    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        if(mp[a]) mp[a] = 0;
        else mp[a]++;
    }
    ll ans = 0;
    for(auto iter : mp){
        if(iter.second == 1) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(n) for(int i=0;i<n;i++)
#define ll long long
#define ull unsigned long long
#define lli long long int
lli mob=1000000007;
using namespace std;
lli g=1000000000000000007;lli k;
lli ye(lli t)
{ if(g<t)
   return g;
  else
 { g=t;
 return ye(abs(t-k));
     
 }
    
    
}

int main()
{ lli n; lli r;
std::cin >> n>>k;
if(n%k==0)
{
    cout<<0;
    goto end;
}
else
{
    r=ye(n%k);
}
cout<<r;
end:;


return 0;
}


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

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

    if (n == 0) { break; }

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

    // 平均値m
    double sum = 0;
    for (int i = 0; i < n; i++) {
      sum += s.at(i);
    }
    double m = sum / n;

    // 分散a**2 = (Si - m)**2 の数列 / n
    double sum2 = 0;
    for (int i = 0; i < n; i++) {
      sum2 += (s.at(i) - m) * (s.at(i) - m);
    }
    double a_square = sum2 / n;

    // 標準偏差 = sqrt(分散)
    double standard_deviation = sqrt(a_square);

    printf("%.5f\n", standard_deviation);
  }
  return 0;
}



Measured memory_bytes: 3200
include Math

gets.to_i.times do
	x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f)

	a1 = 2 * (x2 - x1)
	b1 = 2 * (y2 - y1)
	c1 = x1*x1 - x2*x2 + y1*y1 - y2*y2
	a2 = 2 * (x3 - x1)
	b2 = 2 * (y3 - y1)
	c2 = x1*x1 - x3*x3 + y1*y1 - y3*y3

	a = sqrt((x2-x3)**2 + (y2-y3)**2)
	b = sqrt((x3-x1)**2 + (y3-y1)**2)
	c = sqrt((x1-x2)**2 + (y1-y2)**2)

	px = (b1*c2 - b2*c1)/(a1*b2 - a2*b1)
	py = (c1*a2 - c2*a1)/(a1*b2 - a2*b1)
	r = (a*b*c) / sqrt((a+b+c)*(-a+b+c)*(a-b+c)*(a+b-c))

	printf("%.3f %.3f %.3f\n", px, py, r);
end

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

#define ll long long

void oddSolve(ll smaller, ll bigger, ll n){
	ll a = n - smaller;
	ll b = bigger - 1; 
	ll diff = bigger - smaller; 
	ll s = (diff - 1) / 2;

	if(a <= b) cout << a - s << endl;
	else cout << b - s << endl; 
}


void solve(ll n, ll a, ll b){
	ll bigger = a, smaller = b;
	if(b > a){
		smaller = a;
		bigger = b; 
	}

	ll diff = bigger - smaller; 
	if(diff % 2 == 0){
		cout << diff / 2 << endl; 
	}
	else{
		oddSolve(smaller, bigger, n);
	}
}

int main(){
	ll n, a, b;
	cin >> n >> a >> b;

	solve(n , a , b);
}

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

int main(void){
	int N,K,need=0;
	cin>>N>>K;
	int a[N];
	rep(i,N)cin>>a[i];
	sort(a,a+N,greater<int>());
	rep(i,N){
		int sum=0;
		rep(j,N)if(i<=j)if((sum+=a[j])>=K){
			need = max(need,j+1);
			sum -= a[j];
		}
	}
	cout<<N-need<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


ll dp[111][101010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);

    REP(i,N) cin >> w[i] >> v[i];
    
    for(int i=0;i<N;i++){
        for(int j=0;j<=W;j++){
            if(j - w[i] >= 0) chmax(dp[i+1][j], dp[i][j-w[i]] + v[i]);
            chmax(dp[i+1][j], dp[i][j]);
        }
    }

    cout << dp[N][W] << endl;
}

Measured memory_bytes: 79360
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        int n=sc.nextInt();
        int d[][] = new int[n][n];
        boolean x[][] = new boolean[n][n];
        long s=0;
        for (int i=0; i<n; i++) {
            for (int t=0; t<n; t++) {
                d[i][t] = sc.nextInt();
                s += d[i][t];
            }
        }
        s/=2;
        boolean f=true;

      lp:for (int i=0; i<n; i++) {
            for (int t=0; t<n; t++) {
                if(i==t)continue;
                for (int u=0; u<n; u++) {
                    if(i==u || u==t)continue;
                    if(d[i][t]+d[t][u] <  d[i][u] ){f = false; break lp;}
                    if(!x[i][u] && d[i][t]+d[t][u] ==  d[i][u] ){s-=d[i][u]; x[i][u]=x[u][i]=true;}
                }
            }
        }

        out.println(f ? s:-1);
        out.flush();
    }
    
    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 33000
#include <iostream>
#include <math.h>

using namespace std;

int main(){
    int n,ave,max = 0,min = 0,tmp = 0,sum = 0;
    int *array;

    cin >> n;

    array = new int[n];

    for(int i = 0;i < n;i++){
        cin >> array[i];
        if(i == 0){
            max = array[i];
            min = array[i];
        }else{
            if(max < array[i])
                max = array[i];
            else if(min > array[i])
                min = array[i];
        }
    }

    for(int i = min;i <= max;i++){
        tmp = 0;
        for(int j = 0;j < n;j++){
            tmp += pow((array[j]-i),2);
        }
        if(i == min){
            sum = tmp;
        }else{
            if(sum > tmp)
                sum = tmp;
        }
    }

    cout << sum << endl;

    delete [] array;

    return 0;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

ll calc(ll n, P p) { return n / p.first * p.second + n % p.first; }

ll f(ll n, vector<P> p) {
  ll m = p.size();
  if(m == 0)
    return n;
  else if(m == 1)
    return calc(n, p[0]);
  else if(m == 2) {
    ll res = n;
    rep(i, n + 1) {
      ll j = n - i;
      ll now = calc(i, p[0]) + calc(j, p[1]);
      res = max(res, now);
    }
    return res;
  } else {
    ll res = n;
    rep(i, n + 1) rep(j, n + 1) {
      ll k = n - i - j;
      if(k < 0) continue;
      ll now = calc(i, p[0]) + calc(j, p[1]) + calc(k, p[2]);
      res = max(res, now);
    }
    return res;
  }
}

int main() {
  ll n;
  vl a(3), b(3);
  cin >> n;
  rep(i, 3) cin >> a[i];
  rep(i, 3) cin >> b[i];
  vector<P> p1, p2;
  rep(i, 3) if(a[i] < b[i]) p1.push_back({a[i], b[i]});
  n = f(n, p1);
  rep(i, 3) if(a[i] > b[i]) p2.push_back({b[i], a[i]});
  ll ans = f(n, p2);
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <cmath>
#include <iostream>
#include <cmath>
using namespace std;
typedef long long LL;
#define lgx cerr<<"------------"<< endl;
#define debug(x) cerr<< #x << "=" << x << endl;

int main() {
	LL n, m;
	while(cin >> n >> m) {
		LL ans = 0;
		if(n >= 3 && m >= 3) ans = (n-2) * (m-2);
		else if(n == 1) ans = m-2;
		else if(m == 1) ans = n-2;
		else ans = 0;
		if(ans < 0) ans = 0;
		if(n == 1 && m==1) ans = 1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}




int N;
vector<ll> a;
ll d[100010];
bool b[100010];

int main () {
  cin >> N;

  rep(i, N) {
    ll tmp;
    cin >> tmp;
    a.push_back(tmp);
  }

  sort(All(a));

  Rep(i, N) {
    d[i+1] = a[i] + d[i];
  }

  rep(i, N-1) {
    if (a[i] <= d[i] * 2) {
      b[i] = true;
    }
  }

  int ans = 1;

  for (int k=N-1;k>=1;--k) {
    if (b[k]) {
      ans++;
    } else {
      break;
    }
  }

//  Rep(i, N) {
//    cout << a[i] << "\n";
//  }
//
//  rep(i, N) {
//    cout << d[i] << "\n";
//  }
//
//  rep(i, N-1) {
//    cout << b[i] << "\n";
//  }
  cout << ans << "\n";

}

Measured memory_bytes: 5060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNextInt()) {
			int n = sc.nextInt();
			int x = sc.nextInt();
			int c = 0;
			if (n == 0 && x == 0) {
				break;
			}
			for (int i = 1; i < n - 1; i++) {
				for (int j = i + 1; j <= n; j++) {
					if (i + j < x) {
						if (x - i - j <= n && x - i - j > j) {
							c++;
						}
					}
				}
			}
			System.out.println(c);
		}
    }
}



Measured memory_bytes: 26352
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

int main()
{
  uint64_t N;
  cin >> N;

  uint64_t T = 0;
  vector<uint64_t> a(N);
  N_TIMES(n, N) {
    cin >> a[n];
    
    if (a[n] % 2 == 0) { ++T; }
  }

  cout << ((T < N) ? "first" : "second") << endl;

  return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int roomNum = scan.nextInt();
        ArrayList<Room> rooms = new ArrayList<>();
        for (int i = 0; i <= roomNum; i++) {
            rooms.add(new Room(i));
        }

        int routeNum=scan.nextInt();
        for (int i = 0; i <routeNum ; i++) {
            Room room1=rooms.get(scan.nextInt());
            Room room2=rooms.get(scan.nextInt());
            room1.connect(room2);
            room2.connect(room1);
        }


        HashSet<Room> roomNow = new HashSet<>();
        HashSet<Room> tempRoom = new HashSet<>();
        rooms.get(1).setMinStep(0);
        roomNow.add(rooms.get(1));
        while (!roomNow.isEmpty()) {
            for(Room oneRoom:roomNow){
                for (Room nextRoom:oneRoom.getNext()){
                    if (oneRoom.getMinStep()+1<nextRoom.getMinStep()){
                        nextRoom.setMinStep(oneRoom.getMinStep()+1);
                        nextRoom.setMinPath(oneRoom);
                        tempRoom.add(nextRoom);
                    }
                }
            }
            roomNow=tempRoom;
            tempRoom=new HashSet<>();
        }

        boolean ifOk=true;
        for (int i = 2; i <=roomNum ; i++) {
            if(rooms.get(i).getMinPath()==null){
                ifOk =false;
                break;
            }
        }
        if(ifOk){
            System.out.println("Yes");
            for (int i = 2; i <=roomNum ; i++) {
                System.out.println(rooms.get(i).getMinPath().getId());
            }
        }else{
            System.out.println("No");
        }

    }
}

class Room {
    public int getId() {
        return id;
    }

    int id;

    public ArrayList<Room> getNext() {
        return next;
    }

    ArrayList<Room> next = new ArrayList<>();

    public Room getMinPath() {
        return minPath;
    }

    public void setMinPath(Room minPath) {
        this.minPath = minPath;
    }

    Room minPath=null;

    public int getMinStep() {
        return minStep;
    }

    public void setMinStep(int minStep) {
        this.minStep = minStep;
    }

    int minStep = 1000000000;

    public Room(int id) {
        this.id = id;
    }

    void connect(Room room) {
        next.add(room);
    }
}


Measured memory_bytes: 74124
# 幅優先探索か深さ優先探索で、上下左右の隣接と異なる色ならば、連続する1つの領域とする
# 各領域ごとに、白マス数×黒マス数を計算し、その合計が答え

h, w = list(map(int, input().split()))
masu = [input() for _ in range(h)]
visited = [[False for _ in range(w)] for _ in range(h)]
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

# とりあえず周囲の番兵は使わずに書いてみよう……

# 再帰関数の呼び出し回数が多くなる時はこれが必要！！無いとruntime errorになる。
import sys
sys.setrecursionlimit(400*400 + 10)

def dfs(hi, wi, white, black):
    global colors
    global dx, dy
    global visited

    # print(hi, wi)

    visited[hi][wi] = True
    if masu[hi][wi] == '.':
        white += 1
    if masu[hi][wi] == '#':
        black += 1

    for neighbor in zip(dx, dy):
        h_new = hi + neighbor[0]
        w_new = wi + neighbor[1]
        # print("new: " , h_new, w_new)
        if 0 <= h_new <= h-1 and 0 <= w_new <= w-1:
            if not visited[h_new][w_new]:
                if masu[hi][wi] != masu[h_new][w_new]:
                    white, black = dfs(h_new, w_new, white, black)
    
    return white, black

ans = 0
for hi in range(h):
    for wi in range(w):
        if not visited[hi][wi]:
            white, black = dfs(hi, wi, 0, 0)
            ans += white * black

print(ans)


Measured memory_bytes: 205352
N = int(input())
A = list(map(int, input().split()))
p = 10**9+7
sumA = 0
sumsq = 0
for i in range(len(A)):
  a = A[i]
  sumA += a
  sumA = sumA%p
  sumsq += pow(a, 2, p)
  sumsq = sumsq%p
sqsum = pow(sumA, 2, p)
if sqsum < sumsq:
  sqsum += p
if (sqsum - sumsq)%2 != 0:
  sqsum += p
ans = (sqsum - sumsq)//2
print(ans)

Measured memory_bytes: 31616
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
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++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }


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

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
        int a,b,n;
        while(cin >> a >> b >> n){ 
                int s = 0;
                while(n--){
                        int _a = a*10%b;
                        s += (a*10/b)%10;
                        a = _a; 
                }   
                cout << s << endl;
        }   
}

Measured memory_bytes: 0
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			//			solveA();
			solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		int numN = nextInt();

		while (numN != 0) {
			int wk = numN % 10;
			if (wk == 9) {
				out.println("Yes");
				return;
			}
			numN /= 10;
		}

		out.println("No");
	}

	private void solveB() {
		int numN = nextInt();

		int[][] wk = IntStream.range(0, numN).collect(() -> new int[numN][2], (t, i) -> {
			t[i][0] = nextInt();
			t[i][1] = nextInt();
		}, (t, u) -> {
			Stream.concat(Arrays.stream(t), Arrays.stream(u)).toArray(int[][]::new);
		});

		int res = Arrays.stream(wk).mapToInt(i -> (i[1] - i[0]) + 1).sum();

		out.println(res);
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

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

#define mod 998244353
ll ebob(ll a, ll b){
	if(a == 0) return b;
	return ebob(b%a, a);
}
ll ekok(ll a, ll b){
	return (a*b)/ebob(a,b);
}
int main(){
	ll a,b,c,d; cin>>a>>b>>c>>d;
	ll res = 0;
	ll altsinir = a, ustsinir = b;
		altsinir = (a/c + (a%c > 0)) * c;
		ustsinir = b - b%c;
		res += (ustsinir-altsinir)/c + 1;
	altsinir = a, ustsinir = b;
		altsinir = (a/d + (a%d > 0)) * d;
		ustsinir = b - b%d;
		res += (ustsinir - altsinir)/d + 1;
	ll m = ekok(c,d);
		altsinir = (a/m + (a%m > 0)) * m;
		ustsinir = b - b%m;
		res -= (ustsinir-altsinir)/m + 1;
	cout<<b-a+1-res;
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from collections import defaultdict
dic = defaultdict(int)

for _ in range(N):
    s = list(input())
    s.sort()
    dic[''.join(s)] += 1

ans = 0
for n in dic.keys():
    ans += dic[n]*(dic[n]-1)//2

print(ans)

Measured memory_bytes: 93984
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,g,ko;
    ll x,y;
    cin>>str>>g>>ko;
    cout<<"A"<<g[0]<<"C"<<endl;
    return 0;
}


Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;
int64_t INF = 10000000000;
int main(){
  int64_t n,ma,mb;
  cin >> n >> ma >> mb;
  vector<int64_t> a(n),b(n),c(n);
  rep(i,n){
    cin >> a[i] >> b[i] >> c[i];
  }
  vector<vector<vector<int64_t>>> dp(n+1,vector<vector<int64_t>>(105,vector<int64_t>(105,INF)));
  dp[0][0][0] = 0;
  rep(i,n){
    rep(aw,100+1){
      rep(bw,100+1){
        dp[i+1][aw][bw] = dp[i][aw][bw];
        if(aw-a[i] >= 0 && bw-b[i] >= 0){
          dp[i+1][aw][bw] = min(dp[i+1][aw][bw],dp[i][aw-a[i]][bw-b[i]]+c[i]);
        }
      }
    }
  }
  int64_t minprice = INF;
  rep(i,100){
    if(i != 0 && ma*i <= 100 && mb*i <= 100 && dp[n][ma*i][mb*i] < INF){
      minprice = min(minprice,dp[n][ma*i][mb*i]);
    }
  }
  cout << (minprice < INF?minprice:-1) << endl;
      
    
}
                                

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using node = tuple<ll,int,int>;
const double inf = numeric_limits<double>::max()/3;

double acc[510];
double dp[510][510];

int main(void){
  int n,m;
  cin >> n >> m;
  acc[0] = 0.0;
  for(int i = 0;i < n;++i){
    double tmp;
    cin >> tmp;
    acc[i+1] = acc[i] + tmp;
  }
  fill(dp[0],dp[0] + 510*510, -inf);
  dp[0][0] = 0.0;
  for(int i = 1;i <= n;++i){
    for(int j = 1;j <= i;++j){
      for(int k = 0;k < i;++k){
        dp[i][j] = max(dp[i][j],
                       dp[k][j-1] + (acc[i]-acc[k])/(i-k));
      }
    }
  }
  double res = 0;
  for(int i = 1;i <= m;++i){
    res = max(res,dp[n][i]);   
  }
  cout << setprecision(15) << res << endl;
  return 0;
}



Measured memory_bytes: 5320
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

using vi = vector<int>;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define show(x) cout << #x << " = " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define sz(x) (int)(x).size()
#define YesNo {cout<<"Yes";}else{cout<<"No";}
#define v(T) vector<T>

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
template<class T> bool lcmp(const pair<T, T>& l, const pair<T, T>& r) {
  return l.first < r.first;
}
template<class T> istream& operator>>(istream& i, v(T)& v) {
  F0R(j, sz(v)) i >> v[j];
  return i;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  i64 X;
  cin >> N >> X;

  vector<i64> as(51), bs(51);
  as[0] = bs[0] = 1;

  F0R(i, 50) {
    as[i + 1] = as[i] * 2 + 1;
    bs[i + 1] = bs[i] * 2 + 3;
  }

  i64 r = 0;
  auto eat = [&](auto eat, int level)->void {
    if (!level) {
      if (X) {
        r++;
        X--;
      }
      return;
    }

    X--;
    if (X <= 0) return;
    if (X < bs[level - 1]) {
      eat(eat, level - 1);
      return;
    }
    X -= bs[level - 1];
    r += as[level - 1];
    if (X <= 0) return;
    X--; r++;
    if (X <= 0) return;
    if (X < bs[level - 1]) {
      eat(eat, level - 1);
      return;
    }
    X -= bs[level - 1];
    r += as[level - 1];
    X--;
  };
  eat(eat, N);
  cout << r;
}
#endif


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

int main()
{
	int A, B;
	cin >> A >> B;
	A = (A + 11) % 13;
	B = (B + 11) % 13;
	cout << (A > B ? "Alice" : A == B ? "Draw" : "Bob") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
const int MOD=1e9+7;
ll a[26]={0};
int main()
{
	CloseIo;
	ll sum=1;
 int n;
 string s;
 cin>>n>>s;
  for(int i=0;i<n;i++)
  a[s[i]-'a']++;
  for(int i=0;i<26;i++)
   sum=sum*(a[i]+1)%MOD;
   printf("%lld\n",sum-1);
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
     
    using namespace std;
     
    // https://atcoder.jp/contests/arc103/tasks/arc103_b
     
    struct Point {
      int x;
      int y;
      int u;
      int v;
    };
     
    void resolve(const vector<Point> &points, int mod2, size_t n) {
      vector<int> ads;
      for(int i = 30; i >= 0; i--) ads.push_back(1 << i);
      if(points[0].u % 2 == 0) ads.push_back(1);
      int M = ads.size();
      cout << M << endl;
      for(size_t i = 0; i < M; i++) cout << ads[i] << " \n"[i == M - 1];
     
      for(size_t i = 0; i < n; i++) {
          int xpy = points[i].u, xmy = points[i].v;
          for(auto&& ad : ads) {
              if(xpy >= 0){
                  if(xmy >= 0){
                      cout << "R";
                      xpy -= ad;
                      xmy -= ad;
                  }else{
                      cout << "U";
                      xpy -= ad;
                      xmy += ad;
                  }
              } else {
                  if(xmy >= 0) {
                      cout << "D";
                      xpy += ad;
                      xmy -= ad;
                  } else {
                      cout << "L";
                      xpy += ad;
                      xmy += ad;
                  }
              }
          }
          cout << endl;
      }
    }
     
    int main() {
      size_t n;
      cin >> n;
     
     
      vector<Point> points(n);
      int mod2 = 0;
      int m = 0;
      for (size_t i = 0; i < n; i++) {
        Point &tPoint = points[i];
        cin >> tPoint.x >> tPoint.y;
        tPoint.u = (tPoint.x + tPoint.y);
        tPoint.v = (tPoint.x - tPoint.y);
     
        int tMod2 = abs((tPoint.u) % 2);
        if (i == 0) {
          mod2 = tMod2;
        } else if (mod2 != tMod2) {
          m = -1;
          break;
        }
      }
     
      if (m == -1) {
        cout << -1 << "\n";
      } else {
        resolve(points, mod2, n);
      }
     
      return 0;
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;


typedef tree<int,null_type,less<int>,rb_tree_tag,
		tree_order_statistics_node_update> indexed_set;
#define P pair<int,int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define st std::string 
#define pb push_back 
#define ll long long 
#define pq(x) std::priority_queue<x> 
#define ultapq(x) priority_queue<x,vector<x>,greater<x>> 
#define show_pq(x,n) for(int i = 0; i < n; i++){cout<<x.top(); x.pop();} 
#define itrt(yo) for(auto x:yo){std::cout<<x<<" ";} 
#define vec(x) std::vector<x> 
#define nl '\n' 
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define ALL(x) x.begin(),x.end() 
#define just int i= 0; i<n ; i++

const int MOD = 1e9+7;


int solve(){
    st str; getline(cin,str);
    istringstream ss(str);
    st token;

    vec(st) yup;
    while (getline(ss,token,','))
    {
        yup.push_back(token);
    }

    for (int i = 0; i < yup.size(); i++)
    {
        
        cout<<yup[i]<<" ";
    }
    return 0;
    

}

int main()
{
    IOS;
    int t=1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    
}

    

    
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define all(v) v.begin() , v.end()
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999;
const ll MOD=1000000007;
const ll MAX_N=100010;
ll a,b,c,d,e,f,x,y,z,k,m,n,l,h,w,t,ans=0;
vl v;
float ff;
string s;
ll solve(){
    ans=v[n/2]-v[n/2-1];
    return ans;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n;
    rep(i,n){
    	cin>>a;
    	v.push_back(a);
    }
    sort(all(v));
    
    cout<<solve()<<endl;
}

Measured memory_bytes: 1400
from collections import Counter
N= int(input())
A = list(map(int, input().split()))

cnt = Counter(A)
cnt_key = list(cnt.values())

ans = 0

for i in cnt.values():
    ans += i*(i-1)//2

for j in A:
    m = cnt[j]
    print(ans - m*(m-1)//2 + (m-1)*(m-2)//2)

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

long long n;

long long solve();

int main() {
  cin >> n;

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0;
  for(int i = 1; i <= n; ++i) {
    if(i % 10 == 0) continue;
    long long now = i, pre = i % 10, suf = i % 10;
    while(now > 0) {
      suf = now % 10;
      now /= 10;
    }
    if(pre == suf) ++res;
    for(long long ten = 10; pre * ten + suf <= n;
        ten *= 10) {
      now = n - pre * ten - suf;
      if(ten == 10) {
        ++res;
        continue;
      }
      res += min((long long)ten / 10, now / 10 + 1);
    }
  }
  return res;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
using namespace std;

int main()
{
    int X, A;
    cin >> X >> A;
    if (X < A)
        cout << 0 << endl;
    else if (X >= A)
        cout << 10 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ran 101111
int n;
int ace[ran],a[ran],c[ran];
int ancestor(int x){return x-ace[x]?ace[x]=ancestor(ace[x]):x;}
vector<int> A[ran],B[ran];
int main(){
	int m;
	scanf("%d%d",&n,&m);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		ace[i] = i;
	}
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);
		x = ancestor(x);
		y = ancestor(y);
		if(x!=y)ace[x] = y;
	}
	for(int i=1; i<=n; i++){
		A[ancestor(i)].push_back(i);
		B[ancestor(i)].push_back(a[i]);
	}
	int ret = 0;
	for(int i=1; i<=n; i++)if(!A[i].empty()){
		for(auto x : A[i])c[x] = i;
		for(auto y : B[i])if(c[y] == i)ret++;
	}
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 12416
#include <iostream> 
#include <algorithm>
using namespace std;
int main(){
  
  int x;
  cin>>x;
  if(x==1||x==2||x==3) cout<<1;
  if(x==4) cout<<2;
  if(x==5) cout<<1;
  if(x==6) cout<<2;
  if(x==7) cout<<1;
  if(x==8) cout<<5;
  if(x==10||x==11) cout<<2;
  if(x==12) cout<<5;
  if(x==13) cout<<1;
  if(x==14) cout<<2;
  if(x==15) cout<<1;
  //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
  if(x==16) cout<<14;
  if(x==17) cout<<1;
  if(x==18) cout<<5;
  if(x==19) cout<<1;
  //, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  if(x==20) cout<<5;
  if(x==21||x==22) cout<<2;
  if(x==23) cout<<1;
  if(x==24) cout<<15;
  if(x==25||x==26) cout<<2;
  if(x==27) cout<<5;
  if(x==28) cout<<4;
  if(x==29) cout<<1;
  if(x==30) cout<<4;
  if(x==31) cout<<1;
  if(x==32) cout<<51;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  long double A, B, ans;
  long long ANS;
  cin >> A >> B;
 
  B = round(B * 100);
  ans = A * B;
  ans /= 100;
  ANS = (long long)ans;
  cout << ANS << endl;
}

Measured memory_bytes: 3772
using System;

namespace abc052A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int C = int.Parse(str[2]);
            int D = int.Parse(str[3]);
            if (A * B >= C * D)
                Console.WriteLine(A * B);
            else
                Console.WriteLine(C * D);
        }
    }
}



Measured memory_bytes: 13140
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k;
  cin>>n>>k;
  vll ans(1,0);
  vector<pll> a(n);
  vector<pll> b(n);
  rep(i,n){
    ll t,d;
    cin>>t>>d;
    b[i]=mp(t,d);
    a[i]=mp(d,t);
  }
  sort(rall(b));  
  PQR que;
  vector<pll> c(n);
  c[0]=mp(b[0].S,1);
  for(int i=1;i<n;i++){
    if(b[i].F==b[i-1].F){
      c[i]=mp(b[i].S,0);
    }
    else{
      c[i]=mp(b[i].S,1);
    }
  }
  sort(rall(c));
  vector<ll> e(0);
  for(int i=k;i<n;i++){
    if(c[i].S){
      e.pb(c[i].F);
    }
  }
  
  ll res=0;
  rep(i,k){
    if(c[i].S)res++;
    else que.pu(c[i].F);
    ans[0]+=c[i].F;
  }
  ans[0]+=res*res;
  sort(rall(e));
  rep(i,sz(e)){
    if(sz(que)==0) break;
    ll rr=ans[i];
    rr-=que.top();
    que.pop();
    rr-=res*res;
    res++;
    rr+=res*res;
    rr+=e[i];
    ans.pb(rr);
  }
  sort(rall(ans));
  COUT(ans[0]);
}


Measured memory_bytes: 8592
#include<iostream>
using namespace std;
int main(){

    string s;
    cin>>s;
    int x=0;

    for(int i=0;i<(s.size()+1)/2;i++){
        if(s[i]=='i'){
            if(s[s.size()-i-1]!='i')s[s.size()-i-1]='i',x++;
        }
        else if(s[i]=='w'){
            if(s[s.size()-i-1]!='w')s[s.size()-i-1]='w',x++;
        }
        else if(s[i]=='('){
            if(s[s.size()-i-1]!=')')s[s.size()-i-1]=')',x++;
        }
            else if(s[i]==')'){
            if(s[s.size()-i-1]!='(')s[s.size()-i-1]='(',x++;
        }
    }
    cout<<x<<endl;


    return 0;

}

Measured memory_bytes: 1180
#include<iostream>
//#include <cmath>
#include <bits/stdc++.h>

typedef long long ll;
typedef long double ld;
#define FOR(i,a,n) for(ll i=(a);i<(n);++i)
#define ROF(i,a,n) for(int i=(a);i>(n);--i)

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
 //   freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
    int n;cin>>n; cout<<ceil(float(n)/1000)*1000-n;
    return 0;
}

Measured memory_bytes: 3776
#include <iostream>
#include <string>
#include <vector>
#include <limits>
using namespace std;

int arr[202];

int main()
{
    int N,L;
    cin >> N >> L;
    int originalSum = 0;
    for (int i=1;i<=N;i++)
    {
        arr[i] = L+i-1;
        originalSum += arr[i];
    }
    int minDiff = numeric_limits<int>::max();
    int minSum = 0;
    for (int i=1;i<=N;i++)
    {
        int calcSum = 0;
        for (int j=1;j<=N;j++)
        {
            if (i == j)
                continue;
            calcSum += arr[j];
            if (abs(calcSum - originalSum) < minDiff)
            {
                minDiff = abs(calcSum - originalSum);
                minSum = calcSum;
            }
        }
    }
    cout << minSum << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String ans = "First";
    int n = s.length();
    if(s.charAt(0) == s.charAt(n - 1)) {
      if((n % 2) == 1) ans = "Second";
    } else {
      if((n % 2) == 0) ans = "Second";
    }
    System.out.println(ans);
  }
}

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


int main()
{
    long long n;
    cin >> n;
    vector<char> v;
    int cnt = 0;
    int j = 1;
    long long tmp = n;
    while(tmp>0)
    {
        tmp = tmp - pow(26,j);
        cnt++;
        j++;
    }
    while(cnt--)
    {
        char ch;
        int x = n%26;
        if(x == 0)
            x = 26;
        n = (n - x)/26 ;
        ch = x + 96 ;
        v.push_back(ch);

    }
    for(int i = v.size() - 1; i >= 0; i--)
        cout << v[i];
    return 0;

}




Measured memory_bytes: 3984