akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
 
struct Node {
  int key;
  Node *right,*left,*parent;
};
 
Node *root, *NIL;
 
void insert(int k) {
  Node *y=NIL;
  Node *x=root;
  Node *z;
  z=(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;
  while (x!=NIL) {
    y=x;
    if (z->key<x->key) {
      x=x->left;
    } else {
      x=x->right;
    }
  }
  z->parent=y;
  if (y==NIL) {
    root=z;
  } else {
    if (z->key<y->key) {
      y->left=z;
    } else {
      y->right=z;
    }
  }
}
void inorder(Node *u) {
  if (u==NIL) {
    return;
  }
  inorder(u->left);
  cout<<" "<<u->key<<flush;
  inorder(u->right);
}
void preorder(Node *u) {
  if (u==NIL) {
    return;
  }
  cout<<" "<<u->key<<flush;
  preorder(u->left);
  preorder(u->right);
}
int main() {
  int n;
  scanf("%d",&n);
  string com;
  int x;
  for (int i=0; i<n; i++) {
    cin>>com;
    if (com=="insert") {
      scanf("%d",&x);
      insert(x);
    } else if (com=="print") {
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  }
  return 0;
}


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

int main(){
  long long int N;
  long long int min = 999999999999999999; 

  cin >>N;

  for(int i = 0;i<5;i++){
      long long int x;
      cin >>x;
      if(min > x)min = x;
  }
  cout <<4 +(N%min != 0)+((N) / min)<<endl;
  return 0;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define si(x) scanf("%d", &x)
#define sl(x) scanf("%lld", &x)
#define ss(s) scanf("%s", s)
#define pi(x) printf("%d\n", x)
#define pl(x) printf("%lld\n", x)
#define ps(s) printf("%s\n", s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<vc> vcc;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim)
{
    uniform_int_distribution<int> uid(0, lim - 1);
    return uid(rang);
}

int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1'000'000'007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];

void solve()
{
    ll i, j, n, m;
    cin >> n >> m;
    vector<string> a(n, "");
    fo(i, n)
    {
        cin >> a[i];
    }
    sort(all(a));
    fo(i, n)
    {
        cout << a[i];
    }
}
int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());

    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }

    return 0;
}

int mpow(int base, int exp)
{
    base %= mod;
    int result = 1;
    while (exp > 0)
    {
        if (exp & 1)
            result = ((ll)result * base) % mod;
        base = ((ll)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

void ipgraph(int n, int m)
{
    int i, u, v;
    while (m--)
    {
        cin >> u >> v;
        u--, v--;
        g[u].pb(v);
        g[v].pb(u);
    }
}

void dfs(int u, int par)
{
    for (int v : g[u])
    {
        if (v == par)
            continue;
        dfs(v, u);
    }
}


Measured memory_bytes: 10612
#include <bits/stdc++.h>
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
string s;
signed main(){
	cin>>s;
	string t;
	rep(i,s.size()){
		if(i%2==0)t+=s[i];
	}
	cout<<t<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;

int main(void){
    int height,width;
    vector<int> vec_height,vec_width;
    cin >> height >> width;
    vec_height.push_back(height);
    vec_width.push_back(width);

    for(int i = 0;height + width;i++){
        cin >> height >> width;
        vec_height.push_back(height);
        vec_width.push_back(width);
    }
    for(int i = 0;vec_height[i] + vec_width[i];i++){
        for (int j=0;j < vec_height[i];j++){
           for(int k=0;k < vec_width[i];k++){
               if(j == 0 || j == vec_height[i] -1 || k==0 || k == vec_width[i]-1)
                   printf("#");
               else
                  printf(".");
           }
        printf("\n");
        }
        printf("\n");
    }
}


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

int main(){
  int N,M,X;
  int ans = 10000000;
  cin >> N >> M >> X;
  vector<int> pri(N);
  vector<vector<int>> arg(N,vector<int> (M));
  
  for(int i=0;i<N;++i){
    cin >> pri.at(i);
    for(int j=0;j<M;++j){
      cin >> arg.at(i).at(j);
    }
  }

  for(int tmp =0;tmp < (1 << 12);tmp++){
    bitset<12> s(tmp);
    int sum =0;
    vector<int> ski(M);
    for(int i=0;i<N;++i){
      if(s.test(i)){
        sum += pri.at(i);
        for(int j=0;j<M;++j){
          ski.at(j) += arg.at(i).at(j);
        }
      }
    }
    bool flag = true;
    for(int i=0;i<M;++i){
      if(ski.at(i) < X) flag = false;
    }
    if(flag && sum < ans) ans = sum;
  }
  if(ans == 10000000){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


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

int main(){
	// sengen
	int n,m;

	// nyuryoku
	cin >> n >> m;
	int a[n];
	for(int i=0;i<n;i++){
		 cin >> a[i];
	}
	// keisan
	sort(a,a+n,greater<int>());
	int sum=0;
	for(int i=0;i<n;i++){
		sum += a[i];
	}
	int waru = 4*m;
	double suki=(double)sum/waru;
	if(a[m-1] >= suki){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;

#define Endl endl

/*--------------------template--------------------*/

int main(void)
{
	int N, M;
	cin >> N >> M;

	const int nmmax = 50;
	char A[nmmax][nmmax], B[nmmax][nmmax];

	for (int y = 0; y < N; ++y) {
		for (int x = 0; x < N; ++x) {
			cin >> A[y][x];
		}
	}

	for (int y = 0; y < M; ++y) {
		for (int x = 0; x < M; ++x) {
			cin >> B[y][x];
		}
	}

	bool exist = false;

	for (int ly = 0; ly < N; ++ly) {
		for (int lx = 0; lx < N; ++lx) {
			if (ly + M - 1 >= N || lx + M - 1 >= N) continue;
			bool match = true;
			for (int y = 0; y < M; ++y) {
				for (int x = 0; x < M; ++x) {
					if (A[ly + y][lx + x] != B[y][x]) match = false;
				}
			}
			if (match) exist = true;
		}
	}

	if (exist)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> an(n);
  for(int i=0; i<n; ++i) cin >> an[i];
  vector<bool> dp(200005, false);
  for(int i=0; i<=k; ++i){
    if(!dp[i]){
      for(int j=0; j<n; ++j){
        dp[i+an[j]] = true;
      }
    }
  }
  if(dp[k]) cout << "First" << endl;
  else cout << "Second" << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

using namespace std;

using lint = long long;
using ldouble = long double;

const int INF = 1 << 30;

vector<int> bfs(const vector<vector<int>>& graph, int s, int t) {
    vector<int> dist(graph.size(), INF);
    dist[s] = 0;

    queue<int> que;
    que.push(s);
    while (!que.empty()) {
        int v = que.front();
        que.pop();

        for (int sv : graph[v]) {
            if (dist[sv] <= dist[v] + 1) continue;
            dist[sv] = dist[v] + 1;
            que.push(sv);
        }
    }
    return dist;
}

int main() {
    int N, M, s, t;
    cin >> N >> M >> s >> t;
    --s, --t;

    vector<vector<int>> graph(N);
    for (int i = 0; i < M; ++i) {
        int u, v;
        cin >> u >> v;
        --u, --v;

        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    auto dist = bfs(graph, s, t);
    int D = dist[t];

    vector<lint> num(N, 0);
    for (int v = 0; v < N; ++v) {
        if (dist[v] < INF) ++num[dist[v]];
    }

    dist = bfs(graph, t, s);
    vector<lint> rnum(N, 0);
    for (int v = 0; v < N; ++v) {
        if (dist[v] < INF) ++rnum[dist[v]];
    }

    lint ans = 0;
    for (int d = 0; d <= D - 2; ++d) {
        ans += num[d] * rnum[D - d - 2];
    }

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



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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.141592653589793238462643383279;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    int N,K; cin >> N >> K;
    VL a(N); REP(i,N) cin >> a[i];
    VL S(N+1,0); REP(i,N) S[i+1] = S[i] + a[i];
    VL S2(N+1,0); REP(i,N) if(a[i] > 0) S2[i+1] = S2[i] + a[i]; else S2[i+1] = S2[i];

    ll ans = 0;
    REP(i,N-K+1){
        chmax(ans, S[i+K]-S[i] + S2[i] + S2[N]-S2[i+K]);
        chmax(ans, S2[i] + S2[N]-S2[i+K]);
    }

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

Measured memory_bytes: 2560
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String[] info=sc.nextLine().split(" ");
		Integer n=Integer.valueOf(info[0]);
		Integer k=Integer.valueOf(info[1]);
		List<Character> line=Arrays.asList(sc.nextLine().split(""))
				.stream().map(s->s.charAt(0)).collect(Collectors.toList());
		int happy=0;
		for(int i=0;i<n-1;i++) {
			if(line.get(i)==line.get(i+1)) {
				happy++;
			}
		}
		System.out.println(Integer.min(happy+2*k, n-1));
	}
}

Measured memory_bytes: 36988
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;

    map<int, string> seats;
    string s;
    cout << 0 << endl;
    cin >> s;
    if (s == "Vacant") return 0;
    seats[0] = s;

    cout << N-1 << endl;
    cin >> s;
    if (s == "Vacant") return 0;
    seats[N-1] = s;

    ll left = 0, right = N-1;

    while (true) {
        int center = (left + right) / 2;
        cout << center << endl;
        cin >> s;
        if (s == "Vacant") return 0;
        else seats[center] = s;

        if ((center - left) % 2 == 0 && seats[center] != seats[left] || (center - left) % 2 == 1 && seats[center] == seats[left]) {
            right = center;
        } else {
            left = center;
        }
    }
}

Measured memory_bytes: 852
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int[] arr = new int[5];

    for (int i = 0; i < 5; i++) {
      arr[i] = sc.nextInt();
    }

    int k = sc.nextInt();
    
    String result = "Yay!";

    loop: for (int i = 0; i < 5; i++) {
      for (int j = i + 1; j < 5; j++) {
        if (k < (arr[j] - arr[i])) {
          result = ":(";
          break loop;
        }
      }
    }

    System.out.println(result);

  }
}

Measured memory_bytes: 21844
H,W,N = map(int,input().split())
X = [list(map(int,input().split())) for _ in range(N)]
C = {}
for i in range(N):
    a,b = X[i]
    if a-2>=1 and b-2>=1:
        if (a-2,b-2) not in C:
            C[(a-2,b-2)] = 0
        C[(a-2,b-2)] += 1
    if a-2>=1 and b-1>=1 and b+1<=W:
        if (a-2,b-1) not in C:
            C[(a-2,b-1)] = 0
        C[(a-2,b-1)] += 1
    if a-2>=1 and b+2<=W:
        if (a-2,b) not in C:
            C[(a-2,b)] = 0
        C[(a-2,b)] += 1
    if a-1>=1 and b-2>=1 and a+1<=H:
        if (a-1,b-2) not in C:
            C[(a-1,b-2)] = 0
        C[(a-1,b-2)] += 1
    if a-1>=1 and b-1>=1 and a+1<=H and b+1<=W:
        if (a-1,b-1) not in C:
            C[(a-1,b-1)] = 0
        C[(a-1,b-1)] += 1
    if a-1>=1 and a+1<=H and b+2<=W:
        if (a-1,b) not in C:
            C[(a-1,b)] = 0
        C[(a-1,b)] += 1
    if b-2>=1 and a+2<=H:
        if (a,b-2) not in C:
             C[(a,b-2)] = 0
        C[(a,b-2)] += 1
    if b-1>=1 and a+2<=H and b+1<=W:
        if (a,b-1) not in C:
            C[(a,b-1)] = 0
        C[(a,b-1)] += 1
    if a+2<=H and b+2<=W:
        if (a,b) not in C:
            C[(a,b)] = 0
        C[(a,b)] += 1
D = {i:0 for i in range(10)}
for c in C:
    D[C[c]] += 1
cnt = 0
for i in range(1,10):
    cnt += D[i]
D[0] = (H-2)*(W-2)-cnt
for i in range(10):
    print(D[i])

Measured memory_bytes: 248680
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
long long n,N,i,x,Q,p,l,r,last,j;
long long a[150008],b[150008];
long long q[150008][30][2];
long long ans[150008];
int main()
{
	//freopen("1.in","r",stdin);
	//freopen("zty.out","w",stdout);
	scanf("%lld %lld",&N,&Q);
	a[n=1]=N;
	for(i=1;i<=Q;i++)
	{
		scanf("%lld",&x);
		while(a[n]>=x)n--;
		a[++n]=x;
	}
	q[1][0][1]=a[1];
	b[n]=1; 
	for(i=n;i>=2;i--)
	{
		p=a[i];last=i-1;
		while(p>=a[1])
		{
			l=1;r=last;
			while(l!=r)
			{
				if(a[(l+r+1)/2]<=p)l=(l+r+1)/2;
				else r=(l+r+1)/2-1;
			}
			b[l]+=p/a[l]*b[i];
			p=p%a[l];last=l;
		}
		ans[p]+=b[i];
	}
	ans[a[1]]+=b[1];
	for(i=N;i>=1;i--)
	  ans[i]+=ans[i+1];
	for(i=1;i<=N;i++)
	  printf("%lld\n",ans[i]); 
	return 0;
} 
/*
5 5 
1 2 0 4 5 

8
9
19
22
27
*/

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,p[11],max=0,sum=0;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>p[i];
    sum+=p[i];
    if(max<p[i]){
      max=p[i];
    }
  }
  sum-=max/2;
  cout<<sum<<"\n";
  return 0;
}


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

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

using namespace std;
using lint=long long;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_undirected_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
	G[v].emplace_back(u,wt);
}

class union_find{
	int n;
	vector<int> p;
public:
	union_find(int n):n(n),p(n,-1){}
	int find(int u){ return p[u]<0?u:p[u]=find(p[u]); }
	void unite(int u,int v){
		u=find(u); v=find(v);
		if(u!=v){
			if(p[v]<p[u]) swap(u,v);
			p[u]+=p[v]; p[v]=u; n--;
		}
	}
	bool is_same(int u,int v){ return find(u)==find(v); }
	int size()const{ return n; }
	int size(int u){ return -p[find(u)]; }
};

weighted_graph<lint> G;
vector<bool> vis;

int dfs(int u,lint c){
	vis[u]=true;
	int res=0;
	for(auto e:G[u]) if(e.wt<=c) {
		res++;
		if(!vis[e.to]) res+=dfs(e.to,c);
	}
	return res;
}

int main(){
	int n,m; scanf("%d%d",&n,&m);
	vector<lint> val(n);
	rep(u,n) scanf("%lld",&val[u]);
	G.resize(n);
	vector<tuple<lint,int,int>> E(m);
	rep(i,m){
		int u,v;
		lint c; scanf("%d%d%lld",&u,&v,&c); u--; v--;
		add_undirected_edge(G,u,v,c);
		E[i]={c,u,v};
	}

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

	vector<bool> good(m);
	{
		union_find U(n);
		vector<lint> vsum=val;
		rep(i,m){
			auto [c,u,v]=E[i];
			if(U.is_same(u,v)){
				if(c<=vsum[U.find(u)]) good[i]=true;
			}
			else{
				u=U.find(u);
				v=U.find(v);
				U.unite(u,v);
				int r=U.find(u);
				vsum[r]=vsum[u]+vsum[v];
				if(c<=vsum[r]) good[i]=true;
			}
		}
	}

	int res=0;
	vis.assign(n,false);
	for(int i=m-1;i>=0;i--) if(good[i]) {
		auto [c,u,v]=E[i];
		if(!vis[u]) res+=dfs(u,c);
	}
	printf("%d\n",m-res/2);

	return 0;
}


Measured memory_bytes: 17648
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  string S;
  cin >> S;
  vector<int> alpha(26, 0);
  for(int i=0; i<S.size(); i++){
    alpha[(int)S[i] - (int)'a']++;
  }
  string ans = "None";
  for(int i=0; i<26; i++){
    if(alpha[i] == 0){
      ans = (char)((int)'a' + i);
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,k;
	ll ans=INF;
	cin>>h>>k;
	ll ch[10000];
	for(ll i=0;i<10000;i++){
		ch[i]=INF;
	}
	ll d[1000],m[1000];
	for(ll i=0;i<k;i++){
		ll x,y;
		cin>>x>>y;
		d[i]=x;
		m[i]=y;
	}
	ch[0]=0;
	for(ll i=0;i<h;i++){
		for(ll j=0;j<k;j++){
			ll nex=d[j]+i;
			if(nex>=h){
				ans=min(ans,ch[i]+m[j]);
			}
			else{
			ch[nex]=min(ch[nex],ch[i]+m[j]);
			}
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
from collections import defaultdict
N, = map(int, input().split())

dd = defaultdict(int)
cc = dict()
norm = dict()
ss = []
for _ in range(N):
    xs = list(map(int, input().split()))
    cnd = [tuple(xs[j:] + xs[:j]) for j in range(1, 5)]
    x = min(cnd)
    for item in cnd:
        norm[item] = x
    dd[x] += 1
    cc[x] = (4 if x[0] == x[1] else 2)if x[0] == x[2] and x[1] == x[3] else 1
    ss.append(x)

def f(ff, gg):
    a,b,c,d=ff
    e,h,g,f=gg
    tl = [(a,e,f,b), (b,f,g,c), (c,g,h,d), (d,h,e,a)]
    for i in range(4):
        if tl[i] not in norm:
            return 0
        tl[i] = norm[tl[i]]
    r = 1
    for cp in tl:
        r *= dd[cp]*cc[cp]
        dd[cp] -= 1
    for cp in tl:
        dd[cp] += 1
    return r

r = 0
for i in range(N):
    ff = ss[i]
    dd[ff]-=1
    for j in range(i+1, N):
        sl = ss[j]
        x, y, z, w = sl
        dd[sl]-=1
        sls = [(x,y,z,w), (y,z,w,x), (z,w,x,y), (w,x,y,z)]
        for s in sls:
            r += f(ff, s)
        dd[sl]+=1
print(r)

Measured memory_bytes: 49240
#include <iostream>
int main() {
  int h, n;
  std::cin >> h >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    std::cin >> a;
    sum += a;
  }
  
  std::cout << (h <= sum ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

bool IsPrime(int num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false; // 偶数はあらかじめ除く

  double sqrtNum = sqrt(num);
  for (int i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
    {
      // 素数ではない
      return false;
    }
  }

  // 素数である
  return true;
}

int main()
{
  ll x;
  cin >> x;
  ll ans;
  ll i = x;
  while (1)
  {
    if (IsPrime(i))
    {
      ans = i;
      break;
    }
    i++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 888
N, C = gets.split.map(&:to_i)
Ds = C.times.map{gets.split.map(&:to_i)}
Cs = N.times.map{gets.split.map(&:to_i)}

cs = Array.new(3){Array.new(C, 0)}
[*1 .. N].repeated_permutation(2){|i, j| cs[(i + j)%3][Cs[i - 1][j - 1] - 1] += 1}
puts [*0 ... C].permutation(3).map{|p| [*0 ... 3].product([*0 ... C]).inject(0){|s, (m, c)| s + cs[m][c]*Ds[c][p[m]]}}.min

Measured memory_bytes: 4728
class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納　par[x] == x の時そのノードは根
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0)
        self.rank = [0] * (n+1)
        # 各々の集合の要素数（根が代表して値を持っておく）
        self.count = [1] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        root = x
        queue = [x]
        data = []
        while queue:
            now = queue.pop()
            if self.par[now] == now:
                root = now
            else:
                # 根でないなら親の要素で再検索
                data.append(now)
                queue.append(self.par[now])
        # 検索する過程で親を更新
        for y in data:
            self.par[y] = root
        return root

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return True
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.count[y] += self.count[x]
            self.count[x] = 0
        else:
            self.par[y] = x
            self.count[x] += self.count[y]
            self.count[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
        return False

    # 同じ集合に属しているか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    # 属している集合の要素数
    def size(self, x):
        q = UnionFind.find(self, x)
        return self.count[q]


n, m = map(int, input().split())
data = [tuple(map(lambda z: int(z) - 1, input().split())) for _ in range(m)][::-1]
u = UnionFind(n)
ans = [n*(n-1)//2]
for i in range(m):
    if u.same_check(data[i][0], data[i][1]):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - u.size(data[i][0])*u.size(data[i][1]))
        u.union(data[i][0], data[i][1])

for x in ans[::-1][1:]:
    print(x)


Measured memory_bytes: 93016
#include<iostream>

using namespace std;

int main()
{
  int a;

  cin>>a;


  if(a==25)
  {
    cout<<"Christmas";
  }
  else if(a==24)
  {
    cout<<"Christmas Eve";
  }
  else if(a==23)
  {
    cout<<"Christmas Eve Eve";
  }
  else
  {
    cout<<"Christmas Eve Eve Eve";
  }
  cout<<endl;
  
  return 0;

}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		ArrayList<Integer>[] list = new ArrayList[n+1];
		for(int i = 1; i <= n; i++){
		    list[i] = new ArrayList<Integer>();
		}
		for(int i = 0; i < m; i++){
		    int from  = sc.nextInt();
		    int to = sc.nextInt();
		    list[from].add(to);
		}
		
		// 計算
		double result = Double.MAX_VALUE;
		for(int k = 0; k <= n-1; k++){
		    double[] dp = new double[n+1];
		    for(int i = n-1; i >= 1; i--){
		        if(i == k && list[i].size() <= 1){
		            dp[i] = 0;
		            continue;
		        }
		        int cnt = list[i].size();
		        if(i == k) cnt--;
		        double q = (double)1/cnt;
		        double max = 0;
		        for(int to : list[i]){
		            if(dp[to] == 0 && to != n){
		                dp[i] = 0;
		                break;
		            }else{
		                dp[i] += (1 + dp[to]) * q;
		                max = max(max, dp[to]);
		            }
		        }
		        if(i == k) dp[i] -= (1 + max) * q;
		        //System.out.println("k:" + k + " " + Arrays.toString(dp));
		    }
		    //System.out.println("k:" + k + " " + Arrays.toString(dp));
		    if(dp[1] != 0) result = min(result, dp[1]);
		}
		// 出力
		System.out.println(result);
		
	}
}

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

int main(){
 
  int N;
  int L[110];
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> L[i];
  }
    
  int count = 0;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      for(int k = j+1; k < N; k++){
        if (L[i] == L[j] || L[j] == L[k] || L[k] == L[i]) continue;
        if (L[i]+L[j]<=L[k]) continue;
        if (L[j]+L[k]<=L[i]) continue;
        if (L[k]+L[i]<=L[j]) continue;
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3612
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	int[int] cnt;

	foreach (line; stdin.byLine) {
		cnt[line.to!int]++;
	}
	auto m = cnt.reduce!(max);

	foreach (key; cnt.keys.sort) {
		if (cnt[key] == m) writeln(key);
	}
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

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

    cout << endl;
    return 0;
}

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

int main(){
    int a;
    cin >> a;
    int b;
    cin >> b;
    a *= 500;
    if(a >= b)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using mint = map<int, int>;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int ans[100][100];
int main(){

    int h, w;
    cin >> h >> w;

    fill_n(*ans, h*w, 0);

    int n;
    cin >> n;

    vector<int> a(n);
    rep(i, n) cin >> a[i];

    int ci = 0;
    rep(i, h){
        rep(j, w){
            int pos;
            int c = a[ci];
            --a[ci];
            if(i%2) pos = w-1-j;
            else pos = j;
            ans[i][pos] = ci+1;
            if(a[ci]==0) ++ci;

        }
    }

    rep(i, h){
        rep(j, w){
            cout << ans[i][j] << sp;
        }
        cout << endl;
    }



    return 0;
}


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

#define rep(i, n) for(int i = 0, i_length = (n); i < i_length; i++)
#define MOD 1000000007
#define ll long long

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

	if (n >= b) cout << (a * (b - 1)) / b << endl;
	else cout << (a * n) / b << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define repr(i, a, n) for (ll i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;

void Main() {
  vector<char> c(6);
  rep(i, 0, 6) { cin >> c[i]; }
  if (c[0] == c[5] && c[1] == c[4] && c[2] == c[3])
    puts("YES");
  else
    puts("NO");
}

int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // CとC++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;





// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

int main(){
    string s;
    cin >> s;
    vector<int> ans;
    rep(i,s.size()){
        if (s[i] == '1'){
            ans.pb(1);
        }
        if (s[i] == '0'){
            ans.pb(0);
        }
        if (s[i] == 'B'){
            if (ans.size()){
                ans.pop_back();
            }
        }
    }
    rep(i,ans.size()){
        cout << ans[i];
    }
    
}


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

int main(void){
    int n, x, i, j, k, cnt;
    while(cin >> n >> x){
        cnt = 0;
        if(n == 0 && x == 0)    return 0;
        for(i = 1; i <= n; i++){
            for(j = i + 1; j <= n; j++){
                for(k = j + 1; k <= n; k++){
                    if(i + j + k == x)   cnt++;
                }
            }
        }
        cout << cnt << endl;
    }
}



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

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

string ABCD;

char getdigit(char n) {
	return n > 0 ? '+' : '-';
}

int main() {
	cin >> ABCD;
	const int A = ABCD[0] - '0';
	const int B = ABCD[1] - '0';
	const int C = ABCD[2] - '0';
	const int D = ABCD[3] - '0';

	char d1, d2, d3;
	bool flag = false;

	for (d1 = 1; d1 > -2; d1-=2) {
		for (d2 = 1; d2 > -2; d2-=2) {
			for (d3 = 1; d3 > -2; d3-=2) {
				
				int result = A;
				result += B * d1;
				result += C * d2;
				result += D * d3;

				if (result == 7) {
					flag = true;
					break;
				}
			}

			if (flag) break;
		}

		if (flag) break;
	}

	cout << A << getdigit(d1) << B << getdigit(d2) << C << getdigit(d3) << D << "=7" << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		if (k == 0) {
			System.out.println(n * n);
			return;
		}

		long ans = 0;
		for (int i = k + 1; i <= n; i++) {
			int d = i - k;
			long a = n / i;
			long b = n % i;
			long c = Math.max(b - k + 1, 0);
			ans += d * a + c;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
vector<int> v[200001];
vector<bool> visited (200001,false);
int dfs(int a){
    int cnt=0;
    if(visited[a] == true){
        return 0;
    }
    visited[a] = true;
    for(auto i : v[a]){
        if(!visited[i]){
            cnt++;
            
            cnt += dfs(i);
        }
    }
    
    return cnt;
}

int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,a,b;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        if(v[a].empty()){
            v[a].push_back(b);
            v[b].push_back(a);
            continue;
        }
        vector<int> :: iterator it = find(v[a].begin(),v[a].end(),b);
        if(it == v[a].end()){
            v[a].push_back(b);
            v[b].push_back(a);
        }
    }
    int ans =0;
   
   for(int i=1;i<=n;i++){
        int cnt = dfs(i);
        ans = max(ans,cnt);
        
    }
    cout<<(ans+1);
    return 0;
}

Measured memory_bytes: 23944
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)1e9+7;
const ll INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

int main(){
	int n;
	cin >> n;
	vector<vector<ll>> citys(n, vector<ll>(2));
	foreach(i, citys){ 
		foreach(j, i)cin>>j;
	}


	vector<vector<pll>> roads(n);

	rep(i, 2){
		vector<pll> line;
		rep(j, n){
			line.emplace_back(citys[j][i], j);
		}
		sort(all(line));
		rep(j, n-1){
			pll a = line[j];
			pll b = line[j+1];
			roads[a.second].emplace_back(abs(a.first-b.first), b.second);
			roads[b.second].emplace_back(abs(a.first-b.first), a.second);
		}
	}

	vector<bool> used(n, false);
	priority_queue<pll, vector<pll>, greater<pll>> pq;
	ll ans = 0;
	pq.emplace(0, 0);
	while(pq.size()){
		pll d = pq.top();
		pq.pop();
		if(used[d.second])continue;
		used[d.second] = true;
		ans += d.first;
		foreach(i, roads[d.second]){
			if(used[i.second])continue;
			pq.push(i);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 21716
class UnionFind():
    """
        unionfindtree のクラス
            グループを管理するデータ構造.
            全てのメソッドの計算量が O(log(n)) よりも小さい
        init: 管理対象の個数 n を用いて初期化
        find: ある要素 x の親がどの要素か返す
        union: ある要素 x と y が属しているグループを結合して1つのグループとする
        msize: ある要素 x が属するグループの大きさを返す
    """
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
        self.rank = [0]*n
        self.size = [1]*n

    def find(self, x):
        """
            ある要素 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, y の属するグループを結合するメソッド
            x と y のランク(子の数)の小さい方が結合先の親となる
        """
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.size[y] += self.size[x]
            self.parents[x] = y
        else:
            self.size[x] += self.size[y]
            self.parents[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def msize(self, x):
        """
            ある要素 x の属するグループの大きさを返すメソッド
        """
        return self.size[self.find(x)]
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
    def group_count(self):
        return len(self.roots())


def main():
    N, Q = map(int, input().split())
    uf = UnionFind(N)
    for _ in range(Q):
        u, v = map(int, input().split())
        uf.union(u-1, v-1)
    print(uf.group_count()-1)   
if __name__ == "__main__":
    main()


Measured memory_bytes: 14332
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a < b){
		System.out.println("a < b");
		}
		else if(a > b){
		System.out.println("a > b");
		}
		else
		System.out.println("a == b");
	}
}



Measured memory_bytes: 26096
N, K = map(int, input().split())
 
data_list = []
for i in range(N):
    data = int(input())
    data_list.append(data)
data_list.sort()
 
result = 9999999999999999
for i in range(N-K+1):
    temp = data_list[i+K-1] - data_list[i]
    result = min(result, temp)
print(result)

Measured memory_bytes: 7384
//8-B
import java.util.Scanner;

class Main {
    public static void main(String [] args){
    	
    	Scanner sc = new Scanner(System.in);
    	
    	while(true){
    		
            String num = sc.nextLine();
            
            int sum = 0;
            
            //0番目の文字が0だったらwhile抜ける
            if(num.charAt(0) == '0'){
            	break;
            }
            
            //入力されカ長さだけ呼び出して合計する
            for(int i = 0; i < num.length(); i++){
            	
            	//digit使い方　digit(char,整数)
            	//引数の整数部分に数字がいくつまで使えるかしていする
            	//例）9だったら　1?8まで　9だったら-が返される
            	//例）10だったら　1?9まで　10だったら-が返される
            	sum = sum + Character.digit(num.charAt(i),10);
                
            }
            
            System.out.println(sum);
        }

    }
}

Measured memory_bytes: 26612
#include <stdio.h>
#include <vector>
using namespace std;

int N, M; char S[200200];

const long long mod = 1000000007;
long long D[200200], V[200200];

int main()
{
	scanf ("%d %d %s", &N, &M, S);
	if (S[0] == 'B'){
		for (int i = 0; i < M; i++){
			if (S[i] == 'R') S[i] = 'B';
			else S[i] = 'R';
		}
	}

	vector<int> len;
	for (int i = 1, l = -1; i < M; i++){
		if (S[i-1] == 'R' && S[i] == 'B'){
			int u = i - l - 1;
			len.push_back(u);
		}
		if (S[i] == 'B') l = i;
	}

	if (len.empty()){
		if (N == 2){
			printf ("3\n");
			return 0;
		}
		D[0] = 1;
		D[1] = 2;
		for (int i = 2; i <= N; i++) D[i] = (D[i - 1] + D[i - 2]) % mod;
		printf ("%lld\n", (D[N - 1] + D[N - 3]) % mod);
		return 0;
	}
	if (N == 2){
		printf ("2\n");
		return 0;
	}
	if (N % 2){
		printf ("0\n");
		return 0;
	}

	int lim = len[0];
	if (lim % 2 == 0) lim++;
	for (int i = 1; i < len.size(); i++){
		if (len[i] % 2){
			if (lim > len[i])
				lim = len[i];
		}
	}

	D[0] = V[0] = 1;
	for (int i = 1; i <= N; i++){
		if (i <= lim + 1) D[i] = i - 1;
		if (i >= 2) D[i] = (D[i] + V[i - 2]) % mod;
		if (i >= lim + 3) D[i] = (D[i] + mod - V[i - (lim + 3)]) % mod;
		V[i] = D[i];
		if (i >= 2) V[i] = (V[i] + V[i - 2]) % mod;
	}
	printf ("%lld\n", D[N]);

	return 0;
}


Measured memory_bytes: 3836
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N, K; cin >> N >> K;
    vi A(N); F0R(i, N) cin >> A[i];
    sort(all(A));

    ll ans = 0;
    F0R(i, K) ans += A[i];

    cout << ans << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    ll n;
    cin>>n;
    int cnt=0;
    n--;
    deque<char> q;
    while(n>=0){
        q.push_front((char)'a'+(n%26));
        n/=26;
        n--;
    }
    while(!q.empty()){
        cout<<q.front();
        q.pop_front();
    }
    cout<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
#define ll long long int
#define pii pair <ll , ll >
#define pb push_back
ll x8[] = {1, 1, 1, 0, 0, -1, -1, -1};
ll y8[] = {1, 0, -1, 1, -1, -1, 0, -1};
ll x4[] = {1, -1, 0, 0};
ll y4[] = {0, 0, 1, -1};
ll mod = 1e9 + 7;
ll inf = 1e18;


void getac()
{
    string s;
    cin>>s;
    if(s=="SUN"){
        cout<<7;
    }
    else if(s=="MON")
        cout<<6;
    else if(s=="TUE"){
        cout<<5;
    }
    else if(s=="WED"){
        cout<<4;
    }
    else if(s=="THU"){
        cout<<3;
    }
    else if(s=="FRI"){
        cout<<2;
    }
    else{
        cout<<1;
    }
}
int  main()
{
    fastio;
    ll t;

    t = 1;

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

    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}

Measured memory_bytes: 256
N, D = map(int, input().split())
list_x = [list(map(int, input().split()))]
count = 0
for i in range(1, N):
    list_x.append(list(map(int, input().split())))
    for j in range(i):
        sum_square = 0
        for k in range(D):
            sum_square += (list_x[i][k] - list_x[j][k]) ** 2
        sum = sum_square ** (1/2)
        if(sum == int(sum)):
            count += 1
print(count)


Measured memory_bytes: 3188
#include<stdio.h>

int main(void){
  int a,b,c,x,y,i,j,k,count;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&x);
count =0;

for(i=0;i<=a;i++){
  for(j=0;j<=b;j++){
    for(k = 0;k<=c;k++){
      y = i*500 + j*100 + k*50;
      if(y == x)count++;
    }
  }
}
  printf("%d",count);
  return 0;

}



Measured memory_bytes: 128
#include<iostream>
#include<numeric>
#include<map>
#include<array>
const long mod=1e9+7;
long pow(long a,long b){return b?pow(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
main()
{
	int N;
	std::cin>>N;
	std::map<std::pair<long,long>,std::array<int,2>>mp;
	long O=mod-1;
	for(int i=0;i<N;i++)
	{
		long a,b;std::cin>>a>>b;
		if(!a&&!b)O++;
		else
		{
			long g=std::gcd(a,b);
			a/=g;b/=g;
			if(a<0||!a&&b>0)
			{
				a=-a;
				b=-b;
			}
			int f=0;
			if(b<0)
			{
				long t=a;
				a=-b;
				b=t;
				f=1;
			}
			mp[std::make_pair(a,b)][f]++;
		}
	}
	long ans=1;
	for(auto[_,c]:mp)ans=ans*(pow(2,c[0])+pow(2,c[1])-1)%mod;
	std::cout<<(ans+O)%mod<<std::endl;
}

Measured memory_bytes: 15916