akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(){
    int x,y;
    cin >>x>>y;
    vector<int> list(4);
    for(int i=0;i<4;i++){
        list[i] =i;
    }
    list[x]=0;
    list[y]=0;
    for(int h=0;h<4;h++){
        if(list[h]){
            cout <<h<<endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

const ll Mod = 1e9 + 7;
// const ll Mod = 998244353;
const ll MAXN = 1e6;

void solve(){
    ll n,k;cin>>n>>k;
    vll v(n+1,0);
    for(ll i=0;i<k;i++){
        ll x;cin>>x;
        while(x--){
            ll nd;cin>>nd;
            v[nd]++;
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        if(v[i]==0) ans++;
    }
    cout<<ans<<"\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);

    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3684
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
void read (long long &x) { 
	long long f = 1; x = 0; char s = getchar (); while (s < '0' || s > '9') {if (s == '-') f = -1; s = getchar ();}
	while (s >= '0' && s <= '9') {x = x * 10 + s - '0'; s = getchar ();} 
	x *= f;
}
struct st {
	long long l, r, id;
}k[1000005];
long long a[1000005], bit[1000005], n ,m;
bool cmp (st x, st y) {
	return x.r < y.r;
}
long long lowbit (long long x) {
	return x & (-x);
}
void add (long long x, long long y) {
	for (long long i = x; i <= n; i += lowbit (i)) bit[i] += y;
}
long long sum (long long x) {
	long long cnt = 0;
	for (long long i = x; i >= 1; i -= lowbit (i)) cnt += bit[i];
	return cnt;
}
long long vis[1000005], ans[1000005];
int main () {
	read (n);read (m);
	for (long long i = 1; i <= n; i++) read (a[i]);
	for (long long i = 1; i <= m; i++) read (k[i].l), read (k[i].r), k[i].id = i;
	sort (k + 1, k + 1 + m, cmp);
	long long last = 1;
	for (long long i = 1; i <= m; i++) {
		for (long long j = last; j <= k[i].r; j++) {
			if (vis[a[j]]) add (vis[a[j]], -1);
			add (j, 1);
			vis[a[j]] = j;
		}
		last = k[i].r + 1;
		ans[k[i].id] = sum (k[i].r) - sum (k[i].l - 1);
	}
	for (long long i = 1; i <= m; i++) printf ("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 30976
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){
	int a1,a2;
	int b1,b2;
	int c, d;
	int n, m;
	int s, t;
	int x, y, z;

		scanf("%d %d %d %d %d %d", &a1,&a2,&b1,&b2,&c,&d);
	x = 100*a1;
	y = 0;
	s = 0;
	t = 0;
	for (int i = 0;a2*i*100<=d;i++){
		s = a2*i*100 + s;
		for (int j = 0; (a1*j * 100) + s <= d; j++){
			s = a1*j * 100 + s;
			for (int k = 0; (k*b2) + s <= d && (k*b2)*100 <= c*s; k++){
				t = k*b2 + t;
				for (int l = 0; (l*b1) + s + t <= d && ((l*b1) + t)*100 <= c*s; l++){
					t = l*b1 + t;
					if (y*s < x*t){
						x = s;
						y = t;
					}
					t = t - (l*b1);
				}
				t = t - (k*b2);
			}
			s = s - (j*a1*100);
		}
		s = s - (i*a2 * 100);
	}

	printf("%d %d\n", x+y,y);

	return 0;
}


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

typedef long long int lli;

int main(void)
{
	lli n;
	scanf("%lld", &n);
	vector<lli> A(3*n);
	for(lli i = 0;i < 3*n;i++) scanf("%lld", &A[i]);
	sort(A.rbegin(), A.rend());
	
	lli res = 0;
	for(lli i = 1, j = 0;j < n;i += 2, j++)
	{
		res += A[i];
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define NMAX (int)2e+5
#define INF 1e+6
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg
#define newl cout<<"\n"
using namespace std;
typedef long long ll;
string s,t;
vector<int> v,w;
bool C(){
  if(v.size()!=w.size()) return false;
  rep(i,v.size()){
    if(v[i]!=w[i]) return false;
  }
  return true;
}
int main(){
  scan(s);scan(t);
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  int i=0;
  while(i!=s.size()){
    int cnt=1;
    while(s[i]==s[i+1]){
      cnt++;
      i++;
    }
    v.push_back(cnt);
    i++;
  }
  i=0;
  while(i!=t.size()){
    int cnt=1;
    while(t[i]==t[i+1]){
      cnt++;
      i++;
    }
    w.push_back(cnt);
    i++;
  }
  sort(v.begin(),v.end());
  sort(w.begin(),w.end());
  /*  rep(i,v.size()){
    prin(v[i]);prin(" ");
  }
  newl;
  rep(i,w.size()){
    prin(w[i]);prin(" ");
  }
  newl;*/
  if(C())prin("Yes\n");
  else prin("No\n");
  
  return 0;
}


Measured memory_bytes: 776
n=int(input())
h=list(map(int, input().split())) 
dp=[float('inf')]*n
dp[0]=0
for i in range(n-1):
  dp[i+1]=min(dp[i+1],dp[i]+abs(h[i+1]-h[i]))
  if i < n - 2:
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
print(dp[n-1])

Measured memory_bytes: 52552
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

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

void Main() {
  Cin(ll, n);
  Cins(ll, n + 1, a);
  Cins(ll, n, b);

  ll ans = 0;
  rep(i, n) {
    if (a[i] >= b[i]) {
      ans += b[i];
    } else {
      ans += a[i];
      b[i] -= a[i];
      if (a[i + 1] >= b[i]) {
        a[i + 1] -= b[i];
        ans += b[i];
      } else {
        ans += a[i + 1];
        a[i + 1] = 0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define pi 3.14159265358979323846
#define INF 100000000000000000

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

int main(){
	ll n,k;cin>>n>>k;
	vector<ll> h(n),ans(n,INF);

	for(ll i=0;i<n;i++){
		cin>>h[i];
	}

	ans[0]=0;

	for(ll i=0;i<n;i++){
		for(ll j=1;j<=k;j++){
			if(i+j<n) chmin(ans[i+j],ans[i]+abs(h[i+j]-h[i]));
		}
	}

	cout<<ans[n-1]<<endl;

	return 0;
}

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

int main() {

	string s, t; cin >> s >> t;	
	vector<string> ans;
	for (int i = 0; i < s.size() - t.size() + 1; i++) {
		bool can = true;
		for (int j = 0; j < t.size(); j++) {
			if (s[i + j] == '?') continue;
			if (!(s[i + j] == t[j])) {
				can = false;
			}
		}
		if (can) {
			string tmp_s = s;
			for (int j = 0; j < t.size(); j++) {
				tmp_s[i + j] = t[j];
			}
			for (int j = 0; j < tmp_s.size(); j++) {
				if (tmp_s[j] == '?') {
					tmp_s[j] = 'a';
				}
			}
			ans.push_back(tmp_s);
		}
	}
	if (ans.size() != 0) {
		sort(ans.begin(), ans.end());
		cout << ans[0] << endl;
	}
	else {
		cout << "UNRESTORABLE" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;

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

int main() {
  int H,W;   cin >> H >> W;
  char mp[1001][1001];
  int cost[1001][1001];
  queue<P> que;

  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      cost[i][j] = -1;
    }
  }

  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      cin >> mp[i][j];
      if ( mp[i][j] == '#' ) {
	que.push(P(i,j));
	cost[i][j] = 0;
      }
    }
  }


  while(!que.empty()) {
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    for ( int i = 0; i < 4; i++ ) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if ( 0 <= nx && nx < H && 0 <= ny && ny < W &&
	   mp[nx][ny] == '.' && cost[nx][ny] == -1 ) {
	que.push(P(nx,ny));
	cost[nx][ny] = cost[x][y] + 1;
      }
    }
  }

  int ans = 0;
  for ( int i = 0; i < H; i++ ) {
    for ( int j = 0; j < W; j++ ) {
      ans = max(ans,cost[i][j]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 13328
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int a[52];
    a[0]=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    a[n+1]=24;
    sort(a,a+n+1);
    for(int i=1;i<=n;i++)
    {
        if(i&1)
            a[i]=24-a[i];
    }
    sort(a,a+n+1);
    int ans=24;
    for(int i=0;i<=n;i++)
    {
        ans=min(ans,a[i+1]-a[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>
#include <cstdio>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint a[3];

void solve(){
  cin >> a[0] >> a[1] >>a[2];
  sort(a,a+3);
  for(int i=0;i<3;i++){
    if(i==2)cout << a[i] << endl;
    else cout << a[i] << " ";
  }
}

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



Measured memory_bytes: 3148
#include <iostream>

using namespace std;
int Memo[33001];
int pow2[201];
void solve()
{
	for(int i = 0; i < 200; ++i)
	{
		pow2[i] = i * i;
	}
	for(int i = 1; i < 200; ++i)
	{
		int n1 = pow2[i];
		if(n1 > 33000)
		{
			break;
		}
		Memo[n1]++;
		for(int j = i; j < 200; ++j)
		{
			int n2 = n1 + pow2[j];
			if(n2 > 33000)
			{
				break;
			}
			Memo[n2]++;
			for(int k = j; k < 200; ++k)
			{
				int n3 = n2 + pow2[k];
				if(n3 > 33000)
				{
					break;
				}
				Memo[n3]++;
				for(int l = k; l < 200; ++l)
				{
					int n4 = n3 + pow2[l];
					if(n4 > 33000)
					{
						break;
					}
					Memo[n4]++;
				}
			}
		}
	}
	int num;
	while(cin >> num, num)
	{
		cout << Memo[num] << endl;
	}
}

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

Measured memory_bytes: 880
#include<iostream>
using namespace std;
int main() {
	int h, w;
	while (1) {
		cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int i = 0; i < h;i ++) {
			for (int j = 0; j < w; j++) {
				if (i == 0 || j == 0 || i == h - 1 || j == w - 1) {
					cout << "#";
				}
				else {
					cout << ".";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;

void insertionSort(int A[], unsigned short int N);//ソート関数
void trace(int A[], unsigned short int N);//配列の要素を順番に出力

int main()
{
	unsigned short int N;
	int A[100] = {};

	cin >> N;

	for (int i = 0;i<N;i++)
	{
		scanf("%d", &A[i]);
	}
	trace(A, N);
	insertionSort(A, N);

	return 0;
}

void insertionSort(int A[], unsigned short int N)
{
	int v, j;
	for (int i = 1;i < N;i++)
	{
		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v)
		{
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
		trace(A, N);
	}
}

void trace(int A[], unsigned short int N)
{
	cout << A[0];
	for (int i = 1;i < N;i++)
	{
		cout << " " << A[i];
	}
	cout << endl;
}


Measured memory_bytes: 3144
nu = gets.to_i
red = Array.new(nu).map{Array.new(2, 0)}
blue = Array.new(nu).map{Array.new(2, 0)}
inst = 0
for i in 0..nu - 1
  red[i] = gets.chomp.split(" ").map(&:to_i)
  inst = red[i][0] - red[i][1]
  red[i][0] -= inst
  red[i][1] += inst
end
for i in 0..nu - 1
  blue[i] = gets.chomp.split(" ").map(&:to_i)
end
bl = blue.sort
re = red.sort.reverse
count = 0
ans = 0
length = re.length
for i in 0..nu - 1
  for j in 0..length - 1
    if bl[i][0] > re[j][1] && bl[i][1] > re[j][0]
      ans += 1
      re.delete_at(j)
      break
    end
  end
  length = re.length
end

print ans


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

struct node{
	ll point;
	ll weight;
};

vector <vector<node>> graph;
vector <ll> ans;

void dfs(ll p, ll v, ll color){
	ans[v] = color;
	for (int z=0;z<graph[v].size();z++){
		if (p == graph[v][z].point) continue;
		if (graph[v][z].weight % 2 == 0){
			dfs(v,graph[v][z].point,color);
		}
		else {
			dfs(v,graph[v][z].point,color^1);
		}
	}
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;
    cin >> n;
    graph.resize(n+1);
    ans.resize(n+1);
    for (int z=0;z<n-1;z++){
    	node temp;
    	ll a,b,c;
    	cin >> a >> b >> c;
    	temp.weight = c;
    	temp.point = b;
    	graph[a].push_back(temp);
    	temp.point = a;
    	graph[b].push_back(temp);
    }
    dfs(0,1,0);
    for (int z=1;z<=n;z++){
    	cout << ans[z] << endl;
    }
    cin >> n;
}

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

int main() {

    char c; cin >> c;
    char m[] = { 'a', 'e', 'i', 'o', 'u' };

    rep(i, 5) {
        if (c == m[i]) {
            cout << "vowel" << endl;
            return 0;
        }
    }

    cout << "consonant" << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 110
#define MAX_V 100010

ll N, W;
ll item_v[MAX_N];
ll item_w[MAX_N];
ll dp[MAX_N][MAX_V];

signed main()
{
    cin >> N >> W;
    REP(i, N) { cin >> item_w[i] >> item_v[i]; }

    REP(i, N) { REP(j, MAX_V) { dp[i][j] = (j == 0) ? 0 : LLINF; } }

    // 配る DP
    // dp[j][val] : [0,j] まで使って val を作った時の最小の重さ
    ll ans = 0;
    for(ll i = 0; i < N; ++i) {
        for(ll val = 0; val < MAX_V; ++val) {
            if(val == item_v[i]) { dp[i][val] = min(dp[i][val], item_w[i]); }
            for(ll j = 0; j < i; ++j) {
                if (dp[j][val] + item_w[i] <= W) {
                    dp[i][val + item_v[i]] = min(dp[i][val + item_v[i]], dp[j][val] + item_w[i]);
                }
            }
            if(dp[i][val] <= W) { ans = max(ans, val); }
        }
    }

    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 80128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			
			int[][] map = new int[2*n+1][2*n+1];
			for(int i = 0; i < map.length; i++) {
				for(int j = 0; j <  map[0].length; j++) {
					map[i][j] = -1;
				}
			}
			
			map[n][n] = 0;/* 中央を0 */
			for(int i = 1; i < n; i++) {
				int ni = sc.nextInt();
				int di = sc.nextInt();
				
				boolean _break = false;
				for(int j = 0; j < map.length; j++) {
					for(int k = 0; k < map[0].length; k++) {
						if(map[j][k] == ni) {
							
							if(di == 0) {
								map[j][k-1] = i;
							}else if(di == 1) {
								map[j+1][k] = i;
							}else if(di == 2) {
								map[j][k+1] = i;
							}else {
								map[j-1][k] = i;
							}
							_break = true;
						}
					}
					if(_break) break;
				}
			}
			
			int h1=map.length, h2=0, w1=map.length, w2=0;
			for(int i = 0; i < map.length; i++) {
				for(int j = 0; j < map[0].length; j++) {
					if(map[i][j] != -1) {
						if(w1 > j) w1 = j;
						if(w2 < j) w2 = j;
						if(h1 > i) h1 = i;
						if(h2 < i) h2 = i;
					}
				}
			}
			System.out.println((w2-w1+1) + " " + (h2-h1+1));
		}
	}
	
}



Measured memory_bytes: 55788
N = int(input())

import math

def f(A,B):
    return max(len(str(A)),len(str(B)))

ans = 100
for A in range(1,int(math.sqrt(N+1))+1):
    if N % A == 0:
        B = N // A
        ans = min(ans,f(A,B))
print(ans)

Measured memory_bytes: 39024
use std::io::*;
use std::str::FromStr;
//00.標準入力(n) n:usize
//let n = read_n();
fn read_n() -> usize {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let token = stdin
        .by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .fold(0, |a, x| (x as u8 - b'0') as usize + a * 10);
    token
}
//01.標準入力(n) n:i64
//let n = read_i();
fn read_i() -> i64 {
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let token = stdin
        .by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .fold(0, |a, x| (x as u8 - b'0') as i64 + a * 10);
    token
}
//02.標準入力(s) s:Vec<char>
//let s = read_s();
fn read_s() -> Vec<char> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token = stdin
        .bytes().map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !(*c=='\r'||*c=='\n')).collect();
    token
}
//03.標準入力(n) n:FromStr
//let n:u32=read();
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !(*c=='\r'||*c=='\n'))
        .collect();
    token.parse().ok().expect("failed to parse token")
}
//04.標準入力[a(1)...a(n)]
//let a:Vec<i64>=read_a();
fn read_a<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
//05.標準入力(a,b)*n
//let mut a=Vec::new();
//let mut b=Vec::new();
//for _ in 0..n{
//    let tl:Vec<i64>=read_a();
//    a.push(tl[0]);
//    b.push(tl[1]);
//}

fn main() {
//ABC109
//ABC109_A
/*
    let ab=read_a();
    let a:i64=ab[0];
    let b:i64=ab[1];
    let mut j=false;
    for c in 1..4{
        if a*b*(c as i64)%2==1{j=true;}
    }
    if j{println!("Yes")} else {println!("No")};
*/
//ABC109_B
//use std::collections::BTreeSet;
/*
    let n=read_n();
    let mut w:Vec<Vec<char>>=vec!();
    for _ in 0..n{w.push(read_s())};
    //println!("{},{:?}", n,w);
    let mut j=true;
    if w.iter().collect::<BTreeSet<_>>().len() !=n{j=false};
    for i in 0..n-1{
        if w[i][w[i].len()-1]!=w[i+1][0]{j=false};
    }
    if j{println!("Yes");} else {println!("No");}
*/
    let nx:Vec<i64>=read_a();
    let n=nx[0] as usize;
    let x=nx[1];
    let mut a:Vec<i64>=read_a();
    let mut b:Vec<i64>=vec!();
    for i in 0..n{
        b.push(a[i as usize]-x);
    }
    fn gcd(a: i64, b: i64) -> i64 {
        if b == 0 {a} else {gcd(b, a % b)}
    }
    let mut ans=b[0];
    for i in 0..n{ans=gcd(ans,b[i]);}
    fn abs(a:i64)->i64{if a>0{a} else {-a}}
    ans=abs(ans);
    println!("{}",ans);
}

Measured memory_bytes: 8444
S = input()
ans = [0 for _ in range(len(S) + 1)]
t = 0
for i in range(len(S)):
    if S[i] == "<":
        t += 1
    else:
        t = 0
    ans[i + 1] = t
# print(ans)

t = 0
for i in reversed(range(1, len(S) + 1)):
    if S[i - 1] == ">":
        t += 1
    else:
        t = 0
    ans[i - 1] = max(ans[i - 1], t)
print(sum(ans))


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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int K; cin >> K;

    for(int i = 0; i < S.length(); i++) {
        if(S[i] != S[K-1]) S[i] = '*';
    }

    cout << S << endl;
}

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

long long gcd(long long aaa,long long bbb) {
    if(bbb==0) {
        return aaa;
    }
    return gcd(bbb,aaa%bbb);
}

int main (){

    int N;
    cin >> N;
    long long int a[N],sum=0,summ[N],ans=0,tmp=0;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
        summ[i] = sum;
    }

    for(int i = 0; i < N-1; i++) {
        tmp = abs(summ[i]-(sum-summ[i]));
        if(i == 0) {
            ans = tmp;
        }else {
            ans = min(ans,tmp);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

vector<int> g[100010];

int dfs(int now,int par){
    int res=0;
    int zero=0;
    for(auto nex:g[now]){
        if(nex==par) continue;
        int tmp=dfs(nex,now);
        res+=tmp;
        if(tmp==0) zero++;
    }
    res+=max(0,zero-1);
    return res;
}

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

  int N;
  cin>>N;
  rep(i,N-1){
      int a,b;
      cin>>a>>b;
      g[a].push_back(b);
      g[b].push_back(a);
  }

  int root=-1;
  rep(i,N) if(g[i].size()>=3) root=i;
  if(root==-1){
      cout<<1<<endl;
      return 0;
  }

  int ans=dfs(root,-1);
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 9216
import java.util.*;

public class Main {
	private static Scanner sc=new Scanner(System.in);;

	public static void main(String args[]) {
		//System.out.println((int)'1');
		while(sc.hasNextLine()){
			char a[]=sc.nextLine().toCharArray();
			if(a[0]==48)break;
			int ans=0;
			for(int i=0;i<a.length;i++){

				ans+=a[i]-48;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 17648
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    long long int h,n,a;
    long long int total=0;

    cin>>h>>n;
    FOR(i,1,n){
        cin>>a;
        total+=a;
    }
    if(total>=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  queue<ll> q; 
  int cnt = 0;
  fi(1, 10)
    q.push(i);
  while(q.size()) {
    ll num = q.front();
    q.pop();
    cnt++;
    if(cnt == n) {
      cout << num << endl;
      return 0;
    }

    int last_digit = num % 10;
    if(last_digit != 0)
      q.push(num * 10 + last_digit - 1);
    q.push(num * 10 + last_digit);
    if(last_digit != 9)
      q.push(num * 10 + last_digit + 1);
  }
  
  return 0;
}



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

#define _GLIBCXX_DEBUG

//vector<int> A(M), B(M);
//vector<vector<char>> answer(N, vector<char>(N, '-'));

int main() {
  int n, c, k = 0;
  double ans;
  
  cin >> n;
  
  c = n;
  while(c != 0){
    if(c%2 != 0) k++;
    c--;
  }
  
  ans = (double)k / (double)n;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3756
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [n, m] <- getIntList
    as <- getIntList
    print $ solve as m

solve as m | all (== d) as' = (m `div` l + 1) `div` 2
           | otherwise = 0
    where as' = map div2 as
          d = head as'
          l = foldl lcm 1 $ map (`div` 2) as

div2 a | a `mod` 2 == 0 = 1 + div2 (a `div` 2)
       | otherwise = 0


Measured memory_bytes: 14716
# https://atcoder.jp/contests/abc066/tasks/arc077_a

from collections import deque
n = int(input())
nums = [int(i) for i in input().split()]

ans = deque()
rev = False
for i in range(n):
    if rev:
        ans.appendleft(nums[i])
        rev = False
    else:
        ans.append(nums[i])
        rev = True
if rev:
    ans = reversed(ans)
print(*ans)

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

using namespace std;

int main() {
	int H, W;
	while (cin >> H >> W && (H || W)) {
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				cout << '#';
			}
			cout << '\n';
		}
		cout << '\n';
	}
}


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

int main()
{
  cin.tie(0);
  cin.sync_with_stdio(0);

  vector < string > days = {
  "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  string s;
  cin >> s;
  cout << (7 - (find(days.begin(), days.end(), s) - days.begin()));
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#define ROP(i,n) for(int i=0;i<n;i++)
#define ROOP(i,n) for(int i=1;i<=n;i++)
using namespace std;
int main(){
  int N;
  scanf("%d",&N);
  if(N%1000%111==0) printf("Yes\n");
  else if(N%1110<=9) printf("Yes\n");
  else printf("No\n");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <math.h>
#include <stdbool.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <chrono>
using namespace std;

int main(){
    int w, h, x, y;
    cin >> w >> h >> x >> y;

    double area = double(w) * double(h) / 2.0;
    
    if ( w == x * 2 && h == y * 2 ) {
        cout << area << " " << 1 << endl;
    } else {
        cout << area << " " << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    // cout << a.length() << endl;
    if(a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) puts("YES");
    else puts("NO");

}

Measured memory_bytes: 256
#include<stdio.h>
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int c[26],s[365][26]={{0}},type[365];
void solve(int d)
{
  int since[26]={0};
  for(int i=0;i<d;i++)
  {
    int max=1<<31,now=-1,keep;
    for(int j=0;j<26;j++){keep=s[i][j]+c[j]*(i-since[j]);if(max<keep){max=keep;now=j;}}
    type[i]=now;since[now]=i;
  }
}
int main()
{
  int D=IN(),i=0,j=0;
  while(i<26){c[i++]=IN();}i=0;
  while(i<D){while(j<26){s[i][j++]=IN();}i++,j=0;}i=0;
  solve(D);
  while(i<D){printf("%d\n",type[i++]+1);}
}

Measured memory_bytes: 1620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0016
{
    class Program
    {
        static void Main(string[] args)
        {
            string str;
            double angle = 90;
            double x = 0;
            double y = 0;
            while ((str = Console.ReadLine()) != "0,0")
            {
                double[] array = str.Split(',').Select(double.Parse).ToArray();
                double d = array[0];
                x = x + d * Math.Cos(angle * (Math.PI / 180));
                y = y + d * Math.Sin(angle * (Math.PI / 180));
                angle -= array[1];
            }
            Console.WriteLine((int)x+"\n"+(int)y);
        }
    }
}



Measured memory_bytes: 16388
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC107_2 solver = new ABC107_2();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC107_2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int H = in.nextInt();
            int W = in.nextInt();
            String[][] charr = new String[W][H];
            boolean[] existW = new boolean[W + 1];
            boolean[] existH = new boolean[H + 1];

            String[] burarr = in.nextLine().split("");
            for (int y = 0; y < H; y++) {
                burarr = in.nextLine().split("");
                for (int x = 0; x < W; x++) {
                    charr[x][y] = burarr[x];
                    if (charr[x][y].compareTo("#") == 0) {
                        existH[y] = true;
                        existW[x] = true;
                    }
                }
            }
            for (int y = 0; y < H; y++) {
                if (existH[y]) {
                    for (int x = 0; x < W; x++) {
                        if (existW[x]) {
                            out.print(charr[x][y]);
                        }
                    }
                    out.println();
                }
            }

        /*
        for (int y = 0; y < H; y++) {
            String line = "";
            for (int x = 0; x < W; x++) {
                if ()
                charr[x][y] = (char)in.nextByte();
            }
        }


        for (int i = 0; i <H ; i++) {
            String buf  =in.next();
            if (buf.contains("#")) {
                out.println();
            } else {
                String[] arrbuf = buf.split("");
            }
        }
        */


        }

    }
}



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

//FenwickTree↓
int dat[N];
void init(){
    rep(i,N)dat[i]=0;
}
void add(int i,int x){
    for(;i<N;i+=i&-i)dat[i]+=x;
}
int sum(int i){
    int res=0;
    for(;i>0;i-=i&-i)res+=dat[i];
    return res;
}
int rangesum(int l,int r){//[l,r]
    return sum(r)-sum(l-1);
}
//FenwickTree↑

int a[N];
vector<int> ql[N],qid[N];
int ans[N];

int n,q,c[N];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>c[i];
    rep(i,q){
        int l,r;
        cin>>l>>r;
        ql[r].push_back(l);
        qid[r].push_back(i);
    }
    init();
    for(int i=1;i<=n;i++)a[i]=0;
    for(int i=1;i<=n;i++){
        if(a[c[i]]>0)add(a[c[i]],-1);
        add(i,+1);
        a[c[i]]=i;
        rep(j,ql[i].size()){
            ans[qid[i][j]]=rangesum(ql[i][j],i);
        }
    }
    rep(i,q)cout<<ans[i]<<"\n";
}


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

#define int long long

signed main() {
    int n;
    cin >> n;
    stack<int> s;
    while(n > 0){
        s.push(n%10);
        n /= 10;
    }
    int ans = s.size()*9;
    ans-= 9;
    int sum = 0;
    while(!s.empty()){
        int temp = s.top()%10;s.pop();
        sum += temp;
        int nen = s.size()*9;
        ans = max(nen+temp-1,ans);
    }
    ans = max(ans,sum);
    cout << ans;
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  ll a[n],b[n];
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];
  ll add=0;
  for(int i=n-1;i>=0;i--){
    a[i]+=add;
    if(a[i]%b[i]!=0) add+=b[i]-a[i]%b[i];
  }
  cout<<add<<endl;
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int main(){
	while(1){
		int n;
		int c[100010];
		
		scanf("%d",&n); if(n == 0)break;
		rep1(i,n){
			scanf("%d",&c[i]);
		}
		
		int a[100010],k[100010];
		int t = 0;
		
		rep1(i,n){
			if(i&1){
	  			if(t > 0 && a[t-1] == c[i]){
					k[t-1] ++;
				}
				else {
					a[t] = c[i];
					k[t] = 1;
					t ++;
				}
			}
			else {
				if(t > 1 && a[t-1] != c[i]){
					k[t-2] += k[t-1] + 1;
					t --;
				}
				else {
					a[t-1] = c[i];
					k[t-1] ++;
				}
			}
		}
		
		int ret = 0;
		rep(i,t){
			if(!a[i])ret += k[i];
		}
		
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1588
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>



int main(void){
    int n,a[200006];
    int max;
    long long int sum=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    max=a[0];

    for(int i=0;i<n;i++){
        if(max>=a[i]){sum=sum+abs(max-a[i]);}
        else{max=a[i];}
        //printf("%d\n",sum);
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 2476
#include<stdio.h>

int main(void){
 
	int a,b,x;
	char  op;

	while(1){
 
 		scanf("%d %c %d",&a,&op,&b);
		if(op=='?'){
			break;
		}

		if(op=='+'){
			x=a+b;
			printf("%d\n",x);
		}
		 else if(op=='-'){
			x=a-b;
			printf("%d\n",x);
	        }
	        else if(op=='*'){
			x=a*b;
			printf("%d\n",x);
	        }
	        else if(op=='/'){
			x=a/b;
			printf("%d\n",x);
	        }
 	}
	return 0;
}


Measured memory_bytes: 2104
from collections import Counter as CC
N = int(input())
a = list(map(int, input().split()))
b = CC(a)
X1, X2, X3 = 0, b[min(b)], b[min(b)+1]
count = X1 + X2 + X3
ans = count
for i in range(min(b) + 2, max(b) + 1):
  count -= X1
  X1, X2, X3 = X2, X3, b[i]
  count += X3
  ans = max(ans, count)
else:
  print(ans)

Measured memory_bytes: 14564
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    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 main():
    N, M, *AB = map(int, read().split())

    AB = list(reversed(AB[2:]))
    count = N * (N - 1) // 2
    ans = [count]
    uf = UnionFind(N)

    for a, b in zip(AB[::2], AB[1::2]):
        a -= 1
        b -= 1
        if not uf.same(a, b):
            count -= uf.size(a) * uf.size(b)
            uf.union(a, b)
        ans.append(count)

    print('\n'.join(map(str, reversed(ans))), sep='\n')
    return


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < n; ++i)
#define FOR(i, t, n)  for(ll i = t; i <= (ll)n; ++i)
struct edge {
    int from, to;
    ll cost;
};


class Eratosthenes {
public:
    vector<bool> prime;

    Eratosthenes(int size) {
        prime.resize(size + 1, 1);
        prime[0] = 0;
        prime[1] = 0;
        FOR(i, 2, size) {
            if (prime[i]) {
                for (int j = 2 * i; j <= size; j += i) {
                    prime[j] = 0;
                }
            }
        }
    }

};


class Combination {
    vector<ll> fac; //n!(mod M)
    vector<ll> ifac; //k!^{M-2} (mod M)
public:
    Combination(ll size) {
        fac.resize(size);
        ifac.resize(size);
        fac[0] = 1;
        ifac[0] = 1;
        for (ll i = 0; i < size; i++) {
            fac[i + 1] = fac[i] * (i + 1) % MOD;
            ifac[i + 1] = ifac[i] * mpow(i + 1, MOD - 2) % MOD;
        }
    }

    ll mpow(ll x, ll n) {
        ll ans = 1;
        while (n != 0) {
            if (n & 1) ans = ans * x % MOD;
            x = x * x % MOD;
            n = n >> 1;
        }
        return ans;
    }

    ll comb(ll a, ll b) {
        if (a == 0 && b == 0)return 1;
        if (a < b || a < 0)return 0;
        ll tmp = ifac[a - b] * ifac[b] % MOD;
        return tmp * fac[a] % MOD;
    }
};

ll A, B;

ll GCD(ll a, ll b) {
    if (b == 0)return a;
    return GCD(b, a % b);
}

ll N, K;
int c[1010], s[1010], f[1010];

int main() {
    cin >> N;
    REP(i, N - 1) {
        cin >> c[i] >> s[i] >> f[i];
    }
    REP(i, N) {
        int t = 0;
        FOR(j, i, N - 2) {
            if (t < s[j])t = s[j];
            t += t % f[j] != 0 ? f[j] - t % f[j] : 0;
            t += c[j];
        }
        cout << t << endl;
    }
    return 0;
}



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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

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

    cout << ((a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? "Possible" : "Impossible") << "\n ";

    return 0;
}


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

#define int ll

#define pb push_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second

typedef long long ll;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifdef LOCAL
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

double get_time() {
	return 1.0 * clock() / CLOCKS_PER_SEC;
}

const int INF = 1E9 + 5, W = 5E4 + 100, N = 1E3 + 10;
int dp[N][W];

void maxi(int &x, int y) {
	x = max(x, y);
}

int32_t main() {
	fast();
	int n;
	cin >> n;
	vi w(n), s(n), val(n);
	for(int i = 0; i < n; i++)
		cin >> w[i] >> s[i] >> val[i];
	vi v(n);
	iota(all(v), 0);
	sort(all(v), [&](int i, int j) {
		return s[i] + w[i] < s[j] + w[j];
	});
	vi tmp1(n), tmp2(n), tmp3(n);
	for(int i = 0; i < n; i++) {
		tmp1[i] = w[v[i]];
		tmp2[i] = s[v[i]];
		tmp3[i] = val[v[i]];
	}
	swap(tmp1, w);
	swap(tmp2, s);
	swap(tmp3, val);
	//vvi dp(n + 1, vi(W, -INF));
	// dp[i][j] = If our tower made with first i blocks is weight j, then what is the maximum value we can get?
	// (i, j) -> (i + 1, j + w[i + 1]) if s[i + 1] >= j
	// (i, j) -> (i + 1, j)
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < W; j++) {
			maxi(dp[i + 1][j], dp[i][j]);
			if(s[i] < j || j + w[i] >= W)
				continue;
			maxi(dp[i + 1][j + w[i]], dp[i][j] + val[i]);
		}
	}
	// debug(dp[2][4], dp[3][4]);
	int res = 0;
	for(int i = 0; i < W; i++)
		maxi(res, dp[n][i]);
	cout << res << '\n';
}

/*
3
2 1 30
2 2 20
3 1 40
*/

Measured memory_bytes: 393088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
const double PI = acos(-1.0);

ll lcm(ll a, ll b)
{
    ll x = __gcd(a, b);
    return ((a/x)*b);
}

int main()
{
    double r;
    cin >> r;
    cout << setprecision(20) << fixed;
    cout << r*PI*2 << endl;
}


Measured memory_bytes: 3792
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int x, y;cin>>x>>y;
  if(y%2==0 && x<=y/2 && y/2<=2*x)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3504
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <bitset>

using namespace std;
using ll = long long;

const int MAX = 81;
const int MAX2 = 160 * 80 / 2 + 1;

int dp[MAX][MAX][MAX2];

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<int>> grid(h, vector<int>(w));
    for (auto &row : grid) {
        for (int &v: row) {
            cin >> v;
        }
    }
    for (auto &row : grid) {
        for (int &v: row) {
            int vv;
            cin >> vv;
            v = abs(v - vv);
        }
    }
    dp[0][0][grid[0][0]] = 1;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int d = grid[i][j];
            for (int k = 0; k < d; ++k) {
                if (i > 0) dp[i][j][k] |= dp[i - 1][j][d - k];
                if (j > 0) dp[i][j][k] |= dp[i][j - 1][d - k];
            }
            for (int k = d; k < MAX2; ++k) {
                if (i > 0) dp[i][j][k] |= dp[i - 1][j][k - d];
                if (j > 0) dp[i][j][k] |= dp[i][j - 1][k - d];
            }
            for (int k = 0; k < MAX2 - d; ++k) {
                if (i > 0) dp[i][j][k] |= dp[i - 1][j][k + d];
                if (j > 0) dp[i][j][k] |= dp[i][j - 1][k + d];
            }
        }
    }
    int res = 0;
    for (; res < MAX2; ++res) {
        if (dp[h - 1][w - 1][res]) {
            break;
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 164096
import Data.List

solve :: String -> String
solve line = if prob>=0.5 then "YES" else "NO"
    where c = map (\s->read s::Int) $ words $ line
          lc4 = delete (c!!0) $ delete (c!!1) $ delete (c!!2) [1..10]
          nunder20 = realToFrac $ length $ filter (\c4->((c!!0)+(c!!1)+c4)<=20) lc4
          prob = nunder20 * (1.0/7.0)
main = do
    str <- getContents 
    mapM_ putStrLn $ map solve $ lines $ str

Measured memory_bytes: 4012