akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll h, w, hh, ww;
    cin >> h >> w >> hh >> ww;

    cout << (h-hh)*(w-ww) << endl;

    return 0;
}


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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


signed main() {
    int L; cin >> L;
    double ans = L * L * L * 1.0 / 27;
    cout << fixed;
    cout << setprecision(18) << ans << endl;

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々

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

using namespace std ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	int n , d;
	cin>>n>>d ;
	int ans = 0 ;
	for(int i = 1 ; i <= n ; ++i)
	{
		for(int j = 1 ; j <= d ; ++j)
		{
			if(j < 10)
				continue ;
			int y = j ;
			int x = j%10; y /= 10 ;
			if(x >= 2 && y >= 2 && x*y == i)
				ans++ ;
		}
	}
	return cout<<ans<<"\n" , 0 ;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/

/**
 *    author:  nasimnoob
**/

#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

//----------------------------------------------------------//

typedef long long int                        ll;
typedef unsigned long long int              ull;
typedef long double                          ld;

//-----------------------------------------------------------//
#define      test                       int t; cin>>t;  while(t--)

#define      cube(x)                    (x*x*x)
#define      sqr(x)                     (x*x)

#define      sc1(x)                     scanf("%lld",&x);
#define      sc2(x,y)                   scanf("%lld %lld", &x, &y)
#define      scf1(x)                    scanf("%lf",&x)
#define      scf2(x,y)                  scanf("%lf %lf", &x, &y)

#define      srev                       reverse(s.begin(),s.end())
#define      sortstr                    sort(s.begin(), s.end());
#define      gtl(x)                     getline(cin, (x))

#define      PI                         acos(-1) // 3.1415926535897932
#define      MIN                        9999999

#define      Faster                     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//scanf("%[^\n]%*c", str);
//sort(s,s+n,greater<int>());

//-----------------------------------------------------------//

int main()
{
    Faster;
    //string ;

    int x, y ;
    cin >> x >> y ;
    if(y % 2 == 0 && 2*x <= y && (y <= 4*x))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}






Measured memory_bytes: 3620
#解説参照
n = int(input())
a = list(map(int, input().split( )))

dp = 1
for i in range(n):
    dp |= dp<<a[i]
ans = (sum(a)+1)//2
tmp = 1<<ans
for i in range(ans):
    if dp&tmp:
        print(ans)
        exit()
    ans+=1
    tmp <<=1
print(ans)


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

#define ll long long int
#define hell 1000000007
#define vi vector <ll>
#define pb push_back
#define pii pair<ll,ll>
#define vii vector <pii>
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define sep(i,a,b)  for(ll i=a-1;i>=b;i--)
#define inf (ll)(1e16)

using namespace std;

vi adj[300005];
vector <bool> visited(300005,false);
vi a(300005,0);

void dfs(ll s,ll pv)
{
    visited[s]=true;
    a[s]+=pv;
    for(auto ch:adj[s])
    {
        if(!visited[ch])
            dfs(ch,a[s]);
    }
}

void solve()
{
    ll n,u,v,q;
    cin>>n>>q;
    rep(i,1,n)
    {
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    rep(i,0,q)
    {
        cin>>u>>v;
        a[u]+=v;
    }
    dfs(1,0);
    rep(i,1,n+1)
        cout<<a[i]<<" ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
    //cin>>t;
    while(t--)
        solve();
    return 0;
}


Measured memory_bytes: 27392
use std::collections::BinaryHeap;
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let m = it.next().unwrap().parse::<usize>().unwrap();
    let mut qu = BinaryHeap::new();
    for _i in 0..n {
        qu.push(it.next().unwrap().parse::<i64>().unwrap());
    }
    for _i in 0..m {
        let v = qu.pop().unwrap();
        qu.push(v/2);
    }
    let mut res = 0;
    for _i in 0..n { res += qu.pop().unwrap(); }
    println!("{}", res);
}


Measured memory_bytes: 8444
def main():
    N, K = tuple(int(c) for c in input().split(' '))
    A = [1] + list(int(c) for c in input().split(' '))

    for i in range(K+1, N+1):
        if A[i] > A[i-K]:
            print('Yes')
        else:
            print('No')

if __name__ == "__main__":
    main()

Measured memory_bytes: 99752
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
char a[200000];
int main()
{
    int i,n,m,j,k,l;
    scanf("%s",a);
    n=strlen(a);
    n--;
    while(1)
    {
        int f=0;
        if(n%2==1)
        {
            n--;
            continue;
        }else
        {
            i=0;
            k=n/2;
            f=0;
            while(k<=n-1)
            {
                if(a[i]==a[k])
                {
                    i++;
                    k++;
                }else
                {
                    f=1;
                    n--;
                    break;
                }
            }
            if(f==0)
            {
                printf("%d",n);
                break;
            }

        }

    }
    return 0;
}


Measured memory_bytes: 256
<?php
	$output = array();
	$i = 0;
	while( true ) {
		fscanf( STDIN, "%d%d", $H, $W );
		if( 0 == $H && 0 == $W ) { break; }
		
		$buf = array();
		for( $i=0; $i<$H; $i++ ) {
			$row = "";
			for( $j=0; $j<$W; $j++ ) {
				$row .= '#';
			}
			array_push( $buf, $row );
		}
		array_push( $output, implode( "\n", $buf ) );
	}
	print implode( "\n\n", $output );
	if( 0 == $i) {
		print PHP_EOL;
		$i++;
	}

?>

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vst = vector<st>;
using vch = vector<char>;
using vbl = vector<bl>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
#define mkp(a, b) make_pair(a, b) 
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 ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main() {
  ll x, y;
  cin >> x >> y;
  ll a, b;
  a =-2 * x + y;
  b = 4 * x - y;
  if(a >= 0 && b >= 0 && a % 2 == 0 && b % 2 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define mk make_pair

using namespace std;

const int N=51;
int n,px[N],py[N],ans;
map<pair<int,int>,int>mp;

void calc(int qx,int qy){
	int now=n;
	for(int i=1;i<=n;++i){
		if(mp.count(mk(px[i]-qx,py[i]-qy)))now--;
	}
	ans=min(ans,now);
}

int main(){
	//freopen("b.in","r",stdin);
	//freopen("b.out","w",stdout);
	scanf("%d",&n);ans=n;
	for(int i=1;i<=n;++i){
		scanf("%d%d",&px[i],&py[i]);
		mp[mk(px[i],py[i])]=1;
	}
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j)
			if(i!=j)calc(px[i]-px[j],py[i]-py[j]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
# Python template 
from collections import defaultdict 
import sys
import math 

def get_array(): return list(map(int , sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

sys.setrecursionlimit(10**6) 

# Python3 program to find the number of pairs 
# such that gcd equals to 1 
N = 1000005

lpf = [0 for i in range(N)] 
mobius = [0 for i in range(N)] 

# Function to calculate least 
# prime factor of each number 
def least_prime_factor(): 

	for i in range(2, N): 

		# If it is a prime number 
		if (lpf[i] == 0): 

			for j in range(i, N, i): 

				# For all multiples which are not 
				# visited yet. 
				if (lpf[j] == 0): 
					lpf[j] = i 

# Function to find the value of Mobius function 
# for all the numbers from 1 to n 
def Mobius(): 

	for i in range(1, N): 

		# If number is one 
		if (i == 1): 
			mobius[i] = 1
		else: 

			# If number has a squared prime factor 
			if (lpf[ (i // lpf[i]) ] == lpf[i]): 
				mobius[i] = 0

			# Multiply -1 with the previous number 
			else: 
				mobius[i] = -1 * mobius[i // lpf[i]] 

# Function to find the number of pairs 
# such that gcd equals to 1 
def gcd_pairs(a, n): 

	# To store maximum number 
	maxi = 0

	# To store frequency of each number 
	fre = [0 for i in range(N)] 

	# Find frequency and maximum number 
	for i in range(n): 
		fre[a[i]] += 1
		maxi = max(a[i], maxi) 

	least_prime_factor() 
	Mobius() 

	# To store number of pairs with gcd equals to 1 
	ans = 0

	# Traverse through the all possible elements 
	for i in range(1, maxi + 1): 
		if (mobius[i] == 0): 
			continue

		temp = 0
		for j in range(i, maxi + 1, i): 
			temp += fre[j] 

		ans += temp * (temp - 1) // 2 * mobius[i] 

	# Return the number of pairs 
	return ans 

# Driver code 

n = int(input())

a = get_array() 
if gcd_pairs(a,n) == (n*(n-1))//2:
    print("pairwise coprime")
else:
    gs = a[0]
    for i in range(1,n):
        gs = math.gcd(gs,a[i])
    if gs == 1:
        print("setwise coprime")
    else:
        print("not coprime")



Measured memory_bytes: 253492
A = input()
ans = 1

for i,j in enumerate(A):
    if i == 2:
        second = j
    if i == 3:
        if j != second:
            ans *= 0
    if i == 4:
        forth = j
    if i == 5:
        if j != forth:
            ans *= 0

if ans == 1:
    print('Yes')
else:
    print('No')

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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> vec(N);
  for (int i = 0; i < N; i++) {
    int A;
    int B;
    cin >> A >> B;
    vec.at(i) = make_pair(B, A);
  }
  sort(vec.begin(), vec.end());
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += vec.at(i).second;
    if (sum > vec.at(i).first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  
  return 0;
}




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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

const char lf = '\n';

namespace ae86
{
	const int bufl = 1 << 15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0;int b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007 , __ = _ + _;

void failure(){cout<<"IMPOSSIBLE"<<lf;exit(0);}

int n;
vector<int> e[_];

struct oatww
{
	int rt,to[__],ne[__],he[_],ecnt;

	void adde(int a,int b){to[++ecnt]=b,ne[ecnt]=he[a],he[a]=ecnt;}

	void addde(int a,int b){adde(a,b),adde(b,a);}

	int du[_];

	int dfs(int x)
	{
		int a=0;
		du[x]=0;
		for(int i=he[x];i;i=ne[i])
		{
			int b=dfs(to[i]);du[x]++;
			if(!a)a=b;
			else e[a].emplace_back(b),e[b].emplace_back(a),a=0;
		}
		if(!a)a=x;
		return a;
	}

	void make()
	{
		for(int i=1,a;i<=n;i++)
		{
			a=ty();
			if(a==-1)rt=i;
			else adde(a,i);
		}
		int res=dfs(rt);
		e[res].emplace_back(res);
	}
	
	oatww()
	{
		memset(he,0,sizeof(he));
		ecnt=1;
	}
}t1,t2;

int col[_]={0};

void dfs(int x,int v)
{
	col[x]=v+v-1;
	for(auto b:e[x])if(!col[b])dfs(b,1-v);
}

int main()
{
	ios::sync_with_stdio(0),cout.tie(nullptr);

	n=ty(),t1.make(),t2.make();
	for(int i=1;i<=n;i++)if(t1.du[i]%2!=t2.du[i]%2)failure();

	for(int i=1;i<=n;i++)if(!col[i] && !e[i].empty())dfs(i,0);
	cout<<"POSSIBLE";
	for(int i=1;i<=n;i++)cout<<" \n"[i==1]<<col[i];
	cout<<lf;

	return 0;
}


Measured memory_bytes: 12672
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>

using namespace std;

typedef vector<int> vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

typedef pair<int, int> pi;
#define mp make_pair
#define f  first
#define s  second

typedef long long ll;
typedef long double ld;

/*
const int MOD = 1e9+7;
const int MX =  2e5+5;
const ll  INF = 1e18;
const ld  PI = acos((ld)-1);
*/

template <class array>
inline void array_input(array a[], size_t  n){
  for(size_t i = 0; i < n; i++)
    cin >> a[i];
}

template <class array>
inline void array_init(array a[], array value, size_t n){
  for(size_t i = 0; i < n; i++)
    a[i] = value;
}


int main(){/*
  int t;

  cin >> t;
 
  while(t--)*//*for(int m = 1; m <= t; m++)*/{
    /* input for each test case */
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    
    /* calcultion for each test case */
    int ans = 0;

    while(b <= a){
      b *= 2;
      ans++;
    }

    while(c <= b){
      c *= 2;
      ans++;
    }
    
    /* output of each test ca*/
    if(ans > k) cout << "No\n";
    else cout << "Yes\n";
    
    
  }

  return 0;
}



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

int main(){
    int num;
    int underNum,upperNum;
    cin >> num;
    cin >> underNum >> upperNum;
    int counter=1;
    int sum = num * counter;
    while(true) {
        if(sum > upperNum){
            cout << "NG" << endl;
            break;
        }
        if(sum >= underNum && sum <= upperNum) {
            cout << "OK" << endl;
            break;
        }
        counter++;
        sum = num * counter;
    }
    return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  int yon=0;int kisuu=0;int ni=0;
  //vector<int> a(N);
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    if(a%4==0)yon++;
    else if(a%2==0)ni++;
    if(a%2==1)kisuu++;
  }
  if(N%2==0){
    if(yon>=kisuu)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }else{
    if(yon+1>=kisuu)
      cout<<"Yes"<<endl;
    else
      cout<<"No"<<endl;
  }

  return 0;
}


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

int N;
vector<vector<pair<int, int>>> G;
vector<int> V;
vector<int> ans;

void dfs(int v, int dist) {
  V.at(v) = 1;
  ans.at(v) = dist % 2;
  // if (accumulate(V.begin(), V.end(), 0L) == N) return;
  for (auto g : G.at(v)) {
    if (V.at(g.first)) continue;
    dfs(g.first, dist + g.second);
  }
}

int main() {
  cin >> N;
  G.resize(N);
  V.resize(N);
  ans.resize(N);
  for (int a, b, c; cin >> a >> b >> c;) {
    G.at(--a).push_back({--b, c % 2});
    G.at(b).push_back({a, c % 2});
  }
  dfs(0, 0);
  for (auto a : ans) cout << a << "\n";
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<bool> hasRed(N, false);
  vector<int> countsTotal(N, 1);
  hasRed[0] = true;
  for (int i = 0; i < M; i++) {
    int from, to;
    cin >> from >> to;
    from--;
    to--;

    if (hasRed[from]) {
      hasRed[to] = true;
    }

    if (countsTotal[from] == 1) {
      hasRed[from] = false;
    }

    countsTotal[from]--;
    countsTotal[to]++;
  }

  int count = 0;
  for (int i = 0; i < N; i++) {
    if (hasRed[i]) count++;
  }

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

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//const int INF = INT_MAX;
//vector<vector<int>> adj;

int main() {

	ll n,k;
	cin>>n>>k;
	ll w[n+1], v[n+1];
	for(ll i=1; i<=n; i++) {
		cin>>w[i];
		cin>>v[i];
	}

	ll dp[n+1][k+1];
	memset(dp, 0 ,sizeof(dp));

	for(ll i=1; i<=n; i++) {
		for(ll j=1; j<=k; j++) {
			if(j<w[i])
				dp[i][j] = dp[i-1][j];
			else {
				ll prev = dp[i-1][j];
				ll pres = 0;
				pres = v[i] + dp[i-1][j-w[i]];
				dp[i][j] = max(prev,pres);
			}
		}
	}

	cout<<dp[n][k]<<"\n";

	return 0;
}

Measured memory_bytes: 79104
from math import factorial

def combinations_count(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))
a, b = list(map(int, input().split()))

if a <= 1 and b <= 1:
    print(0)
    exit()
if a < 2:
    result = combinations_count(b,2)
elif b < 2:
    result = combinations_count(a,2)
elif b > 1:
    result = combinations_count(a,2) + combinations_count(b,2)
else:
    result = combinations_count(a,2)
print(result)


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

int main() {
	int a,b,c;
	cin >> a >> b >> c;
	if( a > b )swap(a,b);
	if( b > c )swap(b,c);
	if( a > b )swap(a,b);
	cout << a << " " << b << " " << c << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N){
    cin >> d.at(i);
  }
  int res = 0;
  rep(i, N){
    rep(j, N-i-1){
      res += d.at(i) * d.at(i+j+1);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
ABs = [list(map(lambda x:int(x)-1, input().split())) for _ in range(M)]

uf = UnionFind(N)

for AB in ABs:
    uf.union(AB[0], AB[1])

roots = uf.roots()
answer = 0
for root in roots:
    size = uf.size(root)
    if size > answer:
        answer = size
print(answer)

Measured memory_bytes: 107120
def main():
  import sys
  import numpy as np
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import floyd_warshall
  t=np.fromstring(sys.stdin.buffer.read(),'i',sep=' ')
  n,m,l=t[:3]
  t=t[3:]
  m*=3
  print('\n'.join((floyd_warshall(floyd_warshall(csr_matrix((t[2:m:3],(t[:m:3],t[1:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n).astype(int)%n-1).astype(str).tolist()))
main()

Measured memory_bytes: 28844
#include <cstring>
#include <cstdio>
#define FOR(i,j,k) for(i=j;i<=k;++i)
const int rt = 1, N = 500005;
int last = 1, cnt = 1, len = 0;
int trans[N][26], fa[N], ma[N], v[N], b[N], l[N], bucket[N];
char str[N];
void add(char c) {
    int np = ++cnt, p = last, q, nq; last = np; ma[np] = ++len;
    while (p && !trans[p][c]) trans[p][c] = np, p = fa[p];
    if (!p) fa[np] = rt;
    else {
        q = trans[p][c];
        if (ma[q] == ma[p] + 1) fa[np] = q;
        else {
            nq = ++cnt; memcpy(trans[nq], trans[q], sizeof trans[q]);
            ma[nq] = ma[p] + 1; fa[nq] = fa[q]; fa[q] = fa[np] = nq;
            while (p && trans[p][c] == q) trans[p][c] = nq, p = fa[p];
        }
    }
}

void sort(int *x, int *y, int n, int m) {
    int i;
    FOR(i,1,n) ++bucket[x[i]];
    FOR(i,1,m) bucket[i] += bucket[i - 1];
    for(i=n;i;--i) y[bucket[x[i]]--] = i;
}

int main() {
    int i, j, n, q, o, k, p;
    scanf("%s", str + 1);
    n = strlen(str + 1);
    FOR(i,1,n) add(str[i] - 'a');
    sort(ma, b, cnt, n);
    FOR(i,1,cnt) v[i] = 1;
    for (i = cnt; i; --i) FOR(j,0,25)
        if (trans[b[i]][j]) v[b[i]] += v[trans[b[i]][j]];
    for (o=1; o--; putchar('\n')) {
        scanf("%d", &k); p = rt;
        while (k) FOR(i,0,25) if (trans[p][i]) {
            q = trans[p][i];
            if (k > v[q]) k -= v[q];
            else {
                putchar(i + 'a');
                p = trans[p][i];
                --k;
                break;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 10368
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int c = Integer.parseInt(sc.next());
        int count = 0;
        for (int i = a; i <= b; i++)
            if (c % i == 0)
                count++;
        System.out.println(count);
    }
}


Measured memory_bytes: 26248
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int N;
  scanf("%d",&N);
  //std::vector<std::pair<std::string, int> > moji;
  std::map<std::string, int > moji;
  std::string S;
  for (int i=0; i<N; i++){
    std::cin >> S;
    int count = moji[S];
    moji[S] = count + 1;
  }
  std::vector<std::pair<int, std::string > > moji2(moji.size());
  for (auto const& entry: moji) {
    moji2.push_back(std::make_pair(entry.second, entry.first));
  }
  std::sort(moji2.begin(), moji2.end(), std::greater<std::pair<int, std::string> >());
  int maxnum = moji2[0].first;
  int counter = 1;
  std::vector<std::string > ans;
  ans.push_back(moji2[0].second);
  while(moji2[counter].first == maxnum){
    ans.push_back(moji2[counter].second);
    counter++;
  }
  std::sort(ans.begin(), ans.end());
  for (int i=0; i<ans.size(); i++){
    std::cout << ans[i] << std::endl;
  }
  return 0;
}


Measured memory_bytes: 42132
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
   int k, x;
   cin>>k>>x;

   if(500*k>=x) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define repr(i,n) for(int i=0, i##_len=(n); i<i##_len; --i)
#define REP(i,m,n) for(int i=int(m), i##_len=(n); i<i##_len; ++i)
#define pb push_back
typedef long long ll;
typedef double D;
using namespace std;

int main(){
  int N, X=0, x=0;
  vector<char> S(N);
  cin >> N;
  rep(i,N) cin >> S[i];
  rep(i,N){
    if(S[i]=='I') x++;
    if(S[i]=='D') x--;
    X = max(X,x);
  }
  cout << X << endl;
}

Measured memory_bytes: 3660
from collections import defaultdict
import sys
sys.setrecursionlimit(10 ** 6)

n, q = list(map(int, input().split()))
G = [[]*n for i in range(n)]
for _ in range(n-1):
    a, b = list(map(int, input().split()))
    G[a-1].append(b-1)
    G[b-1].append(a-1)


done = [False]*n
points = [0]*n
d = defaultdict(lambda: 0)

for _ in range(q):
    a, b = list(map(int, input().split()))
    d[a-1] += b


def dfs(i, cnt):
    cnt += d[i]
    points[i] += cnt
    done[i] = True
    for j in G[i]:
        if not done[j]:
            dfs(j, cnt)


dfs(0, 0)
print(*points)


Measured memory_bytes: 249456
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int ans = 0;
        ans += sc.nextInt();
        ans += sc.nextInt();
        ans += sc.nextInt();
        if(ans >= 22){
            System.out.println("bust");
            return;
        }else{
            System.out.println("win");
            return;
        }
    }
}

Measured memory_bytes: 22612
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
using namespace std;

int N, Q;
vector<vector<int>> Edges;
vector<int> in;
vector<int> sum;
vector<bool> check;
queue<pair<int, int>> que;

void solve() {
	cin >> N >> Q;
	Edges.resize(N);
	for (int n = 1; n <= N - 1; n++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		Edges[a].push_back(b);
		Edges[b].push_back(a);
	}
	in.resize(N,0);
	for (int q = 0; q < Q; q++) {
		int p, x;
		cin >> p >> x;
		p--;
		in[p] += x;
	}
	sum.resize(N,0);
	check.resize(N, false);
	que.push(pair<int, int>(0, 0));
	while (!que.empty()) {
		int cur = que.front().first;
		int s = que.front().second;
		que.pop();
		sum[cur] += (s+in[cur]);
		check[cur] = true;
		for (auto itr = Edges[cur].begin(); itr != Edges[cur].end(); itr++) {
			if (check[*itr])continue;
			que.push(pair<int, int>(*itr, sum[cur]));
		}
	}
	for (int n = 0; n < N; n++)cout << sum[n] << " ";
	return;
}


Measured memory_bytes: 17140
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n,q = LI()
s = input()
lr = [LI() for _ in range(q)]
lst = [0]*n
for i in range(n-1):
    if s[i:i+2] == 'AC':
        lst[i] = 1

lst = [0] + list(accumulate(lst))
for l,r in lr:
    print(lst[r-1] - lst[l-1])


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << '\n';
    } else {
        cout << (H * W + 1) / 2 << '\n';
    }

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
function Main(S) {
    var A = parseInt(S[0].substring(0,2));
    var B=  parseInt(S[0].substring(2));

    if(A > 0 && A < 13) {
        if(B > 0 && B < 13) {
            console.log("AMBIGUOUS");
        } else {
            console.log("MMYY");
        }
    } else {
        if(B > 0 && B < 13) {
            console.log("YYMM");
        } else {
            console.log("NA");
        }
    }
}

// 1行入力の場合
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());

// 改行で分割
// Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n/));

// 改行・空白で分割
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

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

int main(){
    int d, m;
    cin >> d;
    vector<int> c(26);
    vector<vector<int>> s(d, vector<int>(26));
    vector<int> t(d);
    for(auto &&n : c) cin >> n;
    for(auto &&n1 : s) for(auto &&n2 : n1) cin >> n2;

    vector<int> l(26);
    vector<int> v(26);
    
    rep(i, d){
        rep(j, 26){
            v[j] = s[i][j];
            v[j] -= c[j] * (++l[j]);
        }
        m = 0;
        for(int j=1; j<26; ++j) if(v[j] > v[m]) m = j;
        cout(m+1);
        l[m] = 0;

    }
}


Measured memory_bytes: 3680
#include <cstdio>
#include <cstring>
 
int main(){
    char s[32768];
        gets(s);
        int len = strlen(s);
        for(int i=0; i<len; i++){
                if('A' <= s[i] && s[i] <= 'Z')
                        s[i] += 0x20;
                else if('a' <= s[i] && s[i] <= 'z')
                        s[i] -= 0x20;
        }
        printf("%s\n", s);
}

Measured memory_bytes: 924
var a,b,temp:longint;
begin
  readln(a,b);
  if a < b then
    begin
      temp:=a;
      a:=b;
      b:=temp;
    end;
  if (a - b) mod 2 <> 0 then write('IMPOSSIBLE')
  else write(a - ((a - b) div 2))
end.

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int x=0;
  if((a==b)&&(a!=c))
    x=1;
  else if((b==c)&&(b!=a))
    x=1;
  else if((c==a)&&(c!=b))
    x=1;
  if(x==1)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
N, M, X = map(int, input().split())
ABC = [list(map(int, input().split())) for i in range(N)]

cost = 10 ** 7

for i in range(2 ** N):
    score = [0] * M
    r = str(format(i, 'b')).zfill(N)
    c = 0
    for j in range(N):
        if r[j] == '1':
            c += ABC[j][0]
            for k in range(M):
                score[k] = score[k] + ABC[j][1 + k]
    j = 1
    for k in range(M):
        if score[k] < X:
            j = 0
    if j == 1 and c < cost:
        cost = c
if cost == 10 ** 7:
    print(-1)
else:
    print(cost)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const long double PI = (acos(-1));

int main()
{
    double a, b, x, S, ans;
    cin >> a >> b >> x;

    S = x / a;
    if (S >= a * b / 2.0) {
        double h = (a * b - S) * 2.0 / a;
        ans = atan2(h, a);
    }
    else {
        ans = atan2(b, 2 * S / b);
    }
    ans = ans / PI * 180.0;
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int a = line[0];
            int b = line[1];
            Console.WriteLine(a * b % 2 == 0 ? "Even" : "Odd");
        }
    }
}

Measured memory_bytes: 11092
#include <stdio.h>
int main() {
	int x, i;
	scanf("%d", &x);
	for (i = 1; i < 50000; i++) {
		if (i * (1 + i) / 2 >= x) {
			printf("%d", i);
			return 0;
		}
	}
	return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;

int W[5020][5020];
int B[5020][5020];

int WW(int x,int y) {
	if(x>=0 && y>=0) return W[y][x];
	return 0;
}
int BB(int x,int y) {
	if(x>=0 && y>=0) return B[y][x];
	return 0;
}

pair<int,int> hoge(int X,int Y) {
	int w=WW(Y+K,X+K)-WW(Y,X+K)-WW(Y+K,X)+WW(Y,X);
	int b=BB(Y+K,X+K)-BB(Y,X+K)-BB(Y+K,X)+BB(Y,X);
	return make_pair(w,b);
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,N) {
		cin>>x>>y>>s;
		x%=2*K;
		y%=2*K;
		if(s=="W") W[y][x]++;
		else B[y][x]++;
	}
	
	for(y=0;y<=5010;y++) for(x=0;x<=5010;x++) {
		B[y][x] = B[y][x]+(y?B[y-1][x]:0)+(x?B[y][x-1]:0)-((y&&x)?B[y-1][x-1]:0);
		W[y][x] = W[y][x]+(y?W[y-1][x]:0)+(x?W[y][x-1]:0)-((y&&x)?W[y-1][x-1]:0);
	}
	int ma=0;
	for(x=-2*K;x<=0;x++) {
		for(y=-K;y<=0;y++) {
			int ok=0;
			FOR(i,4) FOR(j,4) {
				auto p=hoge(x+i*K,y+j*K);
				if((i+j)%2) ok+=p.first;
				if((i+j)%2==0) ok+=p.second;
			}
			ma=max(ma,ok);
		}
	}
	cout<<ma<<endl;
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 196992
// Alert!!! This program may have some NARGLE.
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define endl '\n'

using namespace std;

const int Mod = 1e9 + 7, Inf = 1e9;
int n, ans = 1;

int32_t main ()
{
	//ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	scanf("%d", &n);
	for (int i = 2; i < n; i++)
	{
		int r = sqrt(i);
		for (int j = 1; j * j <= i; j++)
		{
			int tm = i / j;
			if ((j * tm) == i and (tm > r or i == j))
				ans += 2;
			else if ((j * tm) == i)
				ans++;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 3800
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n, m, q; cin >> n >> m >> q;
    vector<int> a(q), b(q), c(q), d(q);
    rep(i,q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--; b[i]--;
    }

    int ans = 0;
    vector<int> k(n+1);
    auto rec = [&](auto &&rec, int v, int pos) -> void {
        if (pos == n) {
            // rep(i,n) {
            //     cout << k[i] << " ";
            // }
            // cout << endl;
            int tmp = 0;
            rep(i,q) {
                if (k[b[i]] - k[a[i]] == c[i]) tmp += d[i];
            }
            chmax(ans, tmp);
            return;
        }

        repf(i,v,m+1) {
            k[pos] = i;
            rec(rec, i, pos+1);
        }
    };

    rec(rec, 1, 0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val list1 = sc.asSequence().take(n).map(String::toInt).toList()
    val list2 = sc.asSequence().take(n).map(String::toInt).toList()
    println((0 until n).map {
        list1.slice(0..it).sum() + list2.slice(it until n).sum()
    }.max())
}

Measured memory_bytes: 33644
#include <iostream>
using namespace std;
int main()
{
    int n; cin >> n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    if(n==1 && a[0]==1)
    {
        cout << 0 << endl;
        return 0;
    }
    int min=a[0],minnum=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]<min)
        {
            min=a[i];
            minnum=i;
        }
    }
    if(min!=1)
    {
        cout << -1 << endl;
        return 0;
    }

    int count=minnum,count2=0;
    int i=minnum;


    while(1)
    {
        int j=i+1;
        bool flag=0;
        while(j<n)
        {
            if(a[j]-a[i]==1)
            {
                count2++;
                flag=1;
                break;
            }
            count++;
            j++;
        }
        if(flag) i=j;
        else break;
        flag=0;
    }
    if(min==1 && count2==0) cout << n-1 << endl;
    else if(count2==0) cout << -1 << endl;
    else cout << n-count2-1 << endl;
    return 0;
}

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

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


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e9+7;

int main(){
   int a[3][3];
   int n;
   int b[n];
   bool get[3][3] = {false};

   for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
         cin >> a[i][j];
      }
   }
   cin >> n;
   for(int i = 0; i < n; i++) cin >> b[i];
   for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++){
         for(int k = 0; k < n; k++){
            if(a[i][j] == b[k]) get[i][j] = true;
         }
      }
   }
   
   string ans = "No";
   for(int i = 0; i < 3; i++){
      if(get[i][0] == true && get[i][1] == true && get[i][2] == true) ans = "Yes";
   }
   for(int i = 0; i < 3; i++){
      if(get[0][i] == true && get[1][i] == true && get[2][i] == true) ans = "Yes";
   }
   if(get[0][0] == true && get[1][1] == true && get[2][2] == true) ans = "Yes";
   if(get[0][2] == true && get[1][1] == true && get[2][0] == true) ans = "Yes";
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define MOD 1000000007
#define DOM 1000000009
#define BASE 1000000021

using P = pair<int,pair<long,long>>;
// depth, hash1, hash2

vector<int> tree[100005];
map<pair<int,pair<long,long>>,int> memo;

P dfs(int v, int from){
  long h1 = 1, h2=1;
  int d = 1;
  for(auto to : tree[v]) if(to!=from){
    P p = dfs(to,v);
    d = max(d, p.fi+1);
    h1 += p.se.fi*MOD;
    h1 %= BASE;
    h2 += p.se.se*DOM;
    h2 %= BASE;
  }
  P p = mp(d,mp(h1,h2));
  memo[p]++;
  return p;
}

int main(){
  int n;
  cin>>n;
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    tree[a].pb(b);
    tree[b].pb(a);
  }

  dfs(0,-1);

  long ans = 0;
  for(auto &p : memo){
    ans += (long)p.se * (p.se-1) / 2;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < (int)k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = {0, 0, 1, -1};
const int dx[] = {1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int dp[21][50001];

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

    int n, m, c[20];
    cin >> n >> m;
    rep(i, m) rep(j, n + 1) dp[i][j] = INF;
    dp[0][0] = 0;
    rep(i, m) cin >> c[i];
    rep(i, m) rep(j, n + 1) {
        if(c[i] > j) dp[i + 1][j] = dp[i][j];
        else dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - c[i]] + 1);
    }
    cout << dp[m][n] << endl;
    return 0;
}

Measured memory_bytes: 7236
import numpy as np
x, y, a, b, c = map(int, input().split())
p = np.array(list(map(int, input().split())))
q = np.array(list(map(int, input().split())))
r = np.array(list(map(int, input().split())))

p = np.sort(p)[::-1][:x]
q = np.sort(q)[::-1][:y]

mix = np.hstack((p, q, r))
mix = np.sort(mix)[::-1]

eat = x+y

print(sum(mix[:eat]))

Measured memory_bytes: 24832
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
typedef vector<vector<P>> vvP;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    rep(i, n) {
        ll t, x, y;
        cin >> t >> x >> y;
        if(t%2 != (x+y)%2) {
            out("No");
            re0;
        }
        else if(t < x+y) {
            out("No");
            re0;
        }
    }

    out("Yes");
    re0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector> 
using namespace std;
int main (){
    char s[5005];
    for(int i=0;i<5005;i++)s[i]='1';
    scanf("%s",s);
    int x;x=1;
    for(int i=0;i<5005;i++){
        if(s[i]=='1')x++;
    }
    int m;
    m=5005-x;
    int k;
    scanf("%d",&k);
    int p;
    p=27*27*27*27*27;
    int a[p];
    for(int i=0;i<p;i++)a[i]=0;
    for(int i=0;i<m;i++){
        a[(s[i]-'a'+1)*p/27]=1;
    }
    for(int i=0;i<m-1;i++){
        a[(s[i]-'a'+1)*p/27+(s[i+1]-'a'+1)*27*27*27]=1;
    }
    for(int i=0;i<m-2;i++){
        a[(s[i]-'a'+1)*p/27+(s[i+1]-'a'+1)*27*27*27+(s[i+2]-'a'+1)*27*27]=1;
    }
    for(int i=0;i<m-3;i++){
        a[(s[i]-'a'+1)*p/27+(s[i+1]-'a'+1)*27*27*27+(s[i+2]-'a'+1)*27*27+(s[i+3]-'a'+1)*27]=1;
    }
    for(int i=0;i<m-4;i++){
        a[(s[i]-'a'+1)*p/27+(s[i+1]-'a'+1)*27*27*27+(s[i+2]-'a'+1)*27*27+(s[i+3]-'a'+1)*27+(s[i+4]-'a'+1)]=1;
    }
    int w;w=1;
    int y;y=0;
    while(w<=k){
        if(a[y]==1)w++;
        y++;
    }
    y--;
    int z;
    int b[5];
    for(int i=0;i<4;i++){
        b[4-i]=y%27;
        z=(y-b[4-i])/27;
        y=z;
    }
    b[0]=y;
    for(int i=0;i<5;i++){
        if(b[i]>0){
            printf("%c",b[i]-1+'a');
        }
    }
printf("\n");
}

Measured memory_bytes: 56320
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int x;
    cin>>x;
    int a=0,w=0,t=0,r=0;
    while(x--)
    {
    	string st;
    	cin>>st;
    	if(st=="AC")
    	a++;
    	else if(st=="WA")
    	w++;
    	else if(st=="TLE")
    	t++;
    	else if(st=="RE")
    	r++;	
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<w<<endl;
	cout<<"TLE x "<<t<<endl;
	cout<<"RE x "<<r<<endl;
    
	return 0;
}

Measured memory_bytes: 3636
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    int m;
    cin >> m;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    vector<int> c;
    set_symmetric_difference(all(a), all(b), back_inserter(c));
    for (int x : c) cout << x << endl;
}



Measured memory_bytes: 6440
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
  long long int A,B,C;
  cin>>A>>B>>C;
  
  if(A+B<=C)
  {A=0;
   B=0;
  }
  else
  {  if(A>C)
      {  A-=C;
         
      }
     else
     {C=C-A;
      A=0;
      B=B-C;
     }
  }
  
  cout<<A<<" "<<B<<endl;
}

Measured memory_bytes: 256