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

using namespace std;

namespace uf {
const int maxE = 10001;
int parent[maxE];
int parent_rank[maxE];


void init(int max_element) {
	for (int i = 0; i < max_element; i++) {
		parent[i] = i;
		parent_rank[i] = 0; 
	}
}

int find(int x) {
	if (x == parent[x]) return x;
	
	parent[x] = find(parent[x]);
	return parent[x];
}

bool is_same(int x, int y) {
	return find(x) == find(y);
}



void link(int x, int y) {
	if (parent_rank[x] > parent_rank[y]) {
		parent[y] = x;
		return;
	}
	parent[x] = y;
	if (parent_rank[x] == parent_rank[y]) {
		parent_rank[y]++;
	}
}

void unite(int x, int y) {
	link(find(x),find(y));
}
}

struct Edge {
	int src, dest, cost;
	Edge(int src = 0, int dest = 0, int cost = 0) :
	src(src),dest(dest),cost(cost) {};
	bool operator < ( const Edge &e) const {
		return cost < e.cost;
	}
};

vector<Edge> kruskal(int N, vector<Edge> edges) {
	//int totalCost = 0;
	vector<Edge> result;
	sort(edges.begin(), edges.end());
	uf::init(N);

	int src, dest;
	for (int i = 0; i < edges.size(); i++) {
		Edge e = edges[i];
		if (!uf::is_same(e.src, e.dest)) {
			result.push_back(e);
			//totalCost+= e.cost;
			uf::unite(e.src, e.dest);
		}
	}
	return result;
}


int main() {
	using namespace std;
	int V,E;
	cin >> V >> E;

	vector<Edge> edges;
	for (int i = 0; i < E; i++) {
		int s,t,w;

		cin >> s >> t >> w;

		edges.push_back(Edge(s,t,w));
	}
	vector<Edge> es = kruskal(V,edges);
	int cost = 0;
	for (const auto& e : es) {
		cost += e.cost;
	}

	cout << cost << endl; 
}

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

using namespace std;

#define TC ll t; cin >> t; while(t--)
typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long a,bb;
    double b;
    cin >> a >> b;
    bb=round(b*100);
    cout << (a*bb)/100 << endl;
    return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> ac(N);
    vector<int> wa(N);
    rep(i, M) {
        int p;
        string s;
        cin >> p >> s;
        --p;
        if(s == "AC") {
            ac[p] = 1;
        } else {
            if(ac[p] == 0) {
                wa[p]++;
            }
        }
    }
    int A = count(ac.begin(), ac.end(), 1);
    int W = 0;
    rep(i, N) {
        if(ac[i]) W += wa[i];
    }
    cout << A << " " << W << '\n';
    return 0;
}


Measured memory_bytes: 1152
n = gets.to_i
t = gets.split.map(&:to_i)
t_sum = t.inject(0) { |sum, v| sum += v }
m = gets.to_i
for i in 0...m do
  p, x = gets.split.map(&:to_i)
  puts t_sum - t[p - 1] + x
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int mod=1e9+7;
const int INF=1001001001;

int main() {
  int H,W,K;
  cin>>H>>W>>K;
  vector<string>s(H);
  for(int i=0;i<H;i++){
    cin>>s[i];
  }
  vector<vector<int>>num(H,vector<int>(W));
  int cnt=1;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(s[i][j]=='#'){
        num[i][j]=cnt;
        cnt++;
      }
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(num[i][j]==0&&j>0){
        num[i][j]=num[i][j-1];
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=W-1;j>=0;j--){
      if(num[i][j]==0&&j<W-1){
        num[i][j]=num[i][j+1];
      }
    }
  }

  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(num[i][j]==0&&i>0){
        num[i][j]=num[i-1][j];
      }
    }
  }
  for(int j=0;j<W;j++){
    for(int i=H-1;i>=0;i--){
      if(num[i][j]==0&&i<H-1){
        num[i][j]=num[i+1][j];
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout<<num[i][j]<<" ";
    }cout<<endl;
  }
  return 0;  
}

Measured memory_bytes: 4068
S = list(raw_input())

del S[-1]
if len(S)%2 != 0:
    del S[-1]

while len(S) >= 2:
    if S[0:len(S)/2] == S[len(S)/2:len(S)]:
        print len(S)
        break
    del S[-1]
    del S[-1]

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int mod = 1e9+7;

int main(){
    int a,b,c;
    cin >> a >> b >>c;
    int x,y;
    cin >> x >> y;
    ll ans = 0;
    if(a+b >= c*2){
        ans += min(x,y)*2*c;
        if(x >= y && a >= 2*c) ans += (x-y)*2*c;
        else if(x >= y) ans += (x-y)*a;
        else if(x < y && b >= 2*c) ans += (y-x)*2*c;
        else if(x < y) ans += (y-x)*b;
    }
    else ans += a*x+b*y;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
int w[105], v[105];
ll dp[105][100005];

int main() {
    int n, W;
    cin >> n >> W;
    ll maxV = n * 1000;
    for (int i = 0; i < n; ++i) cin >> w[i] >> v[i];
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= maxV; ++j) dp[i][j] = 1145141919;
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= maxV; ++j) {
            dp[i + 1][j] = dp[i][j];
            if (j >= v[i]) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
        }
    }
    for (int i = maxV; i >= 0; --i) {
        if (dp[n][i] <= W) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 80256
#include<stdio.h>
int main(void)
{
	int n,m,i,a[101],sum[101],b[101],j;
	scanf("%d",&n);
	scanf("%d",&m);
	for(i=1;i<=m;i++){
		scanf("%d ",&a[i]);
	}
	for(i=1;i<=n;i++){
		sum[i]=0;
	}
	for(i=1;i<=m;i++){
		for(j=1;j<=n;j++){
			scanf("%d",&b[j]);
			if(a[i]==b[j]){
				sum[j]++;
			}
			else{
				sum[a[i]]++;
			}
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",sum[i]);
	}
	return 0;	
}

Measured memory_bytes: 1796
n, t = map(int, input().split())

c_list = []
t_list = []

for i in range(n):
    c, t1 = map(int, input().split())
    c_list.append(c)
    t_list.append(t1)

n_min = 1001

for i, j in zip(c_list, t_list):
    if j <= t and i < n_min:
        n_min = i

if n_min == 1001:
    print("TLE")
else:
    print(n_min)


Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
//#include<cstdio>
//#include<algorithm>
//#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int N, M;
int K[100001];
int to[200001], ne[200001], he[100001], num[200001];
vector<int> S1[100001], S2[100001];
int dame[100001];
bool memo[100001];

int dfs(int v, int prev) {
	if (memo[v]) {
		ll ret = 1;
		if (prev) {
			int k = K[v] - num[prev];
			ret = (ll)S1[v][k - 1] * S2[v][k + 1] % M;
		}
		else ret = S1[v][K[v]];
		if (dame[v] && dame[v] != prev) {
			ll tmp = dfs(to[dame[v]], dame[v] ^ 1);
			int k = K[v] - num[dame[v]];
			for (int i = k; i <= K[v]; i++) {
				S1[v][i] = S1[v][i] * tmp % M;
			}
			for (int i = k; i > 0; i--) {
				S2[v][i] = S2[v][i] * tmp % M;
			}
			ret *= tmp;
			dame[v] = 0;
		}
		return (ret + 1) % M;
	}
	memo[v] = true;
	dame[v] = prev;
	ll ret = 1;
	int k = 1;
	for (int i = he[v]; i; i = ne[i]) {
		int tmp = 1;
		if (i != prev) {
			tmp = dfs(to[i], i ^ 1);
			ret = ret * tmp % M;
		}
		S1[v][k] = ret;
		S2[v][k++] = tmp;
	}
	for (int i = k - 1; i > 0; i--) {
		S2[v][i] = ((ll)S2[v][i] * S2[v][i + 1]) % M;
	}
	return ret + 1;
}

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


	cin >> N >> M;

	int k = 2;
	rep1(i, N - 1) {
		int x, y;
		cin >> x >> y;

		num[k] = K[x];
		to[k] = y;
		ne[k] = he[x];
		he[x] = k++;
		num[k] = K[y];
		to[k] = x;
		ne[k] = he[y];
		he[y] = k++;
		K[x]++;
		K[y]++;
	}
	rep1(i, N) {
		S1[i].resize(K[i] + 2);
		S2[i].resize(K[i] + 2);
		S1[i][0] = 1;
		S2[i][K[i] + 1] = 1;
	}

	rep1(j, N) {
		ll kotae = (dfs(j, 0) - 1 + M) % M;
		co(kotae);
	}


	Would you please return 0;
}

Measured memory_bytes: 21376
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999999999;
const ll MOD = 998244353;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, ans = 0, w, l;
vector<PP> A, B;
vl X, Y;
void input() {
	cin >> n;
	inputv(X, n);
	inputv(Y, n);
	rep(i, n) {
		A.push_back({ Y[i],X[i] });
	}
}
void solve() {
	vl par(100010);
	sort(all(A));
	rep(i, n) {
		B.push_back({ A[i].second,i });
	}

	sort(all(B));

	rep(i, n) {
		if (B[i].first > A[i].first) {
			cout << "No" << endl;
			return;
		}
	}

	rep(i, n) {
		par[i] = B[i].second;
	}

	rep(i, n - 1) {
		if (A[i] > B[i + 1]) {
			cout << "Yes" << endl;
			return;
		}
	}

	x = 0;
	k = 0;
	x = par[x];
	k++;
	while (x != 0) {
		x = par[x];
		k++;
	}

	if (k != n) {
		cout << "Yes" << endl;
		return;
	}

	cout << "No" << endl;
}

int main() {
	input();
	solve();
}

Measured memory_bytes: 7152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
ll dp[1001][5001];
ll memo[1000];
ll X[1000];
vector<int> child[1000];
ll solve(int v) {
    memo[v]=INF;
    for(int c:child[v]) {
        if (solve(c) == INF) return INF;
    }
    for(int i=0;i<=child[v].size();i++) {
        for(int j=0;j<=X[v];j++) {
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<child[v].size();i++) {
        int c=child[v][i];
        for(int j=0;j<=X[v];j++) {
            if(j+X[c]<=X[v]) dp[i+1][j+X[c]]=min(dp[i+1][j+X[c]],dp[i][j]+memo[c]);
            if(j+memo[c]<=X[v]) dp[i+1][j+memo[c]]=min(dp[i+1][j+memo[c]],dp[i][j]+X[c]);
        }
    }
    for(int i=0;i<=X[v];i++) {
        memo[v]=min(memo[v],dp[child[v].size()][i]);
    }
    return memo[v];
}
int main() {
    int N;
    cin>>N;
    for(int i=1;i<N;i++) {
        int p;
        cin>>p;
        p--;
        child[p].push_back(i);
    }
    for(int i=0;i<N;i++) cin>>X[i];
    if(solve(0)<INF) cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 37376
n = int(input())
a = list(map(int,input().split()))
s = 0
def calc_mod(x):
    return x%2
def calc_div(x):
    return x/2
while list(map(calc_mod, a)).count(0) == n:
    s += 1
    a = list(map(calc_div, a))
print(s)

Measured memory_bytes: 3060
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
def dijkstra():
    d[0] = 0
    q = [[0,0]]
    while q:
        dx, x = heappop(q)
        for y in v[x]:
            if d[y] > dx+1:
                d[y] = dx+1
                heappush(q,[d[y],y])
n,m = LI()
v = [[] for i in range(n)]
for i in range(m):
    a,b = LI()
    a -= 1
    b -= 1
    v[a].append(b)
    v[b].append(a)
d = [float("inf") for i in range(n)]
dijkstra()
if d[n-1] <= 2:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 115532
N,M,K=list(map(int,input().split()))

MAXN = 2*(10**5)+10
p = 998244353
MOD = p
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res

out = 0
for i in range(K+1):
    out += M*nCr(N-1,i,p)*power_func(M-1,N-1-i,p)
    out = out % p
print(out)

Measured memory_bytes: 89116
import sys
import math
import copy
import queue
input = sys.stdin.readline
def LI(): return [int(x) for x in input().split()]
INF = 10**15
EPS = 10**(-10)
DD = ((1,0),(0,1),(-1,0),(0,-1))

a , b  = LI()
a0 = math.ceil(a / 0.08)
a1  = int((a+1)/0.08 - EPS)
b0 = math.ceil(b / 0.1)
b1 = int((b+1)/0.1 - EPS)
x = max(a0,b0)
y = min(a1,b1)
if x > y : print (-1)
else : print (x)

Measured memory_bytes: 40556
#include <map>
#include <iostream>
using namespace std;
int main(){
int N,C;
  C=0;
cin>>N;
int A[N];
map<int,int> AN;
for(int i=0;i<N;i++){
cin>>A[i];
if(AN[A[i]]){
C=1;
}else{
AN[A[i]]=1;
}
}
  
 if(C==1){cout<<"NO";}else{cout<<"YES";} 
}

Measured memory_bytes: 10368
def main():
	n = int(input())
	k = int(input())
	x = int(input())
	y = int(input())
	if n<=k:
		print(n*x)
	else:
		ans = 0
		ans = ans+k*x
		n = n-k
		ans = ans+n*y
		print(ans)
if __name__=="__main__":
	main()

Measured memory_bytes: 62012
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		int sum=0;
		while(!a.equals("0")){
			int digit = a.length();
			for(int i=0;i<digit;i++){
				sum+=a.charAt(i)-'0';
			}
			System.out.println(sum);
			sum=0;
			a=scan.next();
		}
	}

}

Measured memory_bytes: 17184
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;

int main(){

  int H, W; cin >> H >> W;

  int C[10][10];
  for (int i = 0; i < 10; i++){
    for (int j = 0; j < 10; j++){
      cin >> C[i][j];
    }
  }
  
  vector <int> SCORE(10);
  for (int i = 0; i < 10; i++){
    SCORE[i] = nmax;
  }
  
  vector <int> V(10);
  for (int i = 0; i < 10; i++){
    V[i] = i;
  }
  
  do{
    int cnt = 0;
    int start = V[0];
    if (start != 1){
      for (int i = 0; i < 10; i++){
        cnt += C[V[i]][V[i + 1]];
        if (V[i + 1] == 1) break;
      }
    }
    
    if (SCORE[start] > cnt){
      SCORE[start] = cnt;
    }
  } while (next_permutation(V.begin(), V.end()));

  int A[H][W];
  int ans = 0;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
      if (A[i][j] != -1){
        ans += SCORE[A[i][j]];
      }
    }
  }
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;}
ll lcm(ll x, ll y) {return x/gcd(x,y)*y;}

// 素因数分解 O(√n)
// たとえば 60 = 2^2 x 3 x 5 だったら {(2, 2), (3, 1), (5, 1)} を返す
// 素因数の個数はlogn
vector<pair<ll,ll>> prime_factorize(ll n){
    vector<pair<ll,ll>> res;
    for(ll p=2;p*p<=n;p++){
        if(n%p!=0) continue;
        int num=0; // 指数
        while(n%p==0){
            num++;
            n/=p;
        }
        res.push_back({p,num});
    }
    if(n!=1) res.push_back({n,1});
    return res;
}

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

    auto pf=prime_factorize(gcd(a,b));
    cout<<pf.size()+1<<endl;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
    ll i,j,k;
    ll n,m;
    cin>>n>>m;

    VVVI dp(m+1,VVI(n+2,VI(n+2,0))); //孤立j 1の成分k

    dp[0][n-1][1]=1;

    for(i=1;i<=m;i++){
        for(j=0;j<=n;j++){
            for(k=0;k<=n;k++){
                dp[i][j][k]=(j+1)*dp[i-1][j+1][k]+(n-j-k)*dp[i-1][j][k];
                if(j+k==n) {
                    for(ll l=0;l<=k;l++) dp[i][j][k]+=l*dp[i-1][j][l];
                }
                dp[i][j][k]%=Mod;
            }
        }
    }

    cout<<dp[m][0][n]<<endl;
    
    
}

Measured memory_bytes: 219008
#include<iostream>
#include<cstdio>

using namespace std;

const int maxn=1e2+5;

int s[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	for(int i=0;i<n;i++){
		if(i!=0){
			printf(" ");
		}
		printf("%d",s[i]);
	}
	printf("\n");
	for(int i=1;i<n;i++){
		int key=s[i];
		int j=i-1;
		while(j>=0&&s[j]>key){
			s[j+1]=s[j];
			j--;
		}
		s[j+1]=key;
		for(int k=0;k<n;k++){
			if(k!=0){
				printf(" ");
			}
			printf("%d",s[k]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization_level 3
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
	ll k;
	cin>>k;
	vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	cout<<v.at(k-1)<<endl;
	
}


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

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

  ll s;
  cin >> s;

  set<ll> appear;
  int ans = 1;

  while (1) {
    if (appear.count(s)) break;
    appear.emplace(s);

    if (s & 1) s = 3 * s + 1;
    else s /= 2;

    ++ans;
  }

  cout << ans << '\n';

  return (0);
}


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

using namespace std;

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

const int N = 1e5 + 5;

int h,w,h2,w2;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> h >> w >> h2 >> w2;
  cout << h * w - h2 * w - h * w2 + h2 * w2 << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] res = new long[m];

        int[] a = new int[m];
        int[] b = new int[m];
        for(int i=0; i<m; i++) {
            a[i] = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
        }

        long u = (long)n * (n-1) / 2;
        UnionFind uf = new UnionFind(n);

        res[m-1] = u;
        for (int i=m-1; i>0; i--) {
            int ra = uf.root(a[i]);
            int rb = uf.root(b[i]);

            if(ra != rb) {
                int numa = uf.num[ra];
                int numb = uf.num[rb];
                u -= numa * numb;
                int num = numa + numb;
                uf.num[ra] = uf.num[rb] = num;
                uf.connect(ra, rb);
            }
            res[i-1] = u;

        }

        for(int i=0; i<m; i++) {
            System.out.println(res[i]);
        }

    }
    static class UnionFind {
        int[] uf;
        int[] num;
        int n;
        public UnionFind(int n) {
            this.n = n;
            uf = new int[n];
            num = new int[n];
            for(int i=0; i<n; i++) {
                uf[i] = i;
                num[i] = 1;
            }
        }
        public int root(int a) {
            if(uf[a] == a) {
                return a;
            }
            uf[a] = root(uf[a]);
            return uf[a];
        }
        public boolean isGroup(int a, int b) {
            return root(a) == root(b);
        }
        public void connect(int a, int b) {
            uf[root(a)] = root(b);
        }
        public void print() {
            System.out.println(Arrays.toString(uf));
        }
        public void compact() {
            for(int i=0; i<n; i++) {
                root(i);
            }
        }
        public boolean isRoot(int a) {
            return a == uf[a];
        }
    }

}

Measured memory_bytes: 98320
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define xrep(i,a,b) for(int i=int(a);i<int(b);++i)
typedef long long ll;

int gcd(int a, int b, int c) {
    int gcdNum;
    int minV = min(a, b);
    minV = min(minV, c);
    for(int i=minV; i>0; i--) {
        if(a%i==0&&b%i==0&&c%i==0) {
            gcdNum = i;
            break;
        }
    }
    return gcdNum;
}


ll K;

int main() {
    cin >> K;
    int ans = 0;
    xrep(a, 1, K+1) {
        xrep(b, 1, K+1) {
            xrep(c, 1, K+1) {
                ans += gcd(a, b, c);
            }
        }
    }

    cout << ans << endl;



    return 0;
}

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


    class Program
    {


        static void Main(string[] args)
        {
            Solve();
        }

        static void Solve()
        {
        Scan sc = new Scan();
        write wr = new write();


        int[] a = sc.intarr;
        int n = a[0];
        int t = 0, x = 0, y = 0;
        bool ans = true;

        for(int i = 0; i < n; ++i)
        {
            int[] b = sc.intarr;
            int nt = b[0], nx = b[1], ny = b[2];

            if (Math.Abs(x - nx) + Math.Abs(y - ny) <= nt - t && (Math.Abs(x - nx) + Math.Abs(y - ny) )% 2 == (nt - t)%2)
            {
                x = nx;
                y = ny;
                t = nt;
                continue;
            }
            else
            {
                ans = false;
            }
        }
        if (ans) wr.wri("Yes");
        else wr.wri("No");
    }
}


    class Scan
    {
    public string str => Console.ReadLine();

    public string[] strarr => str.Split(' ');

    public long[] longarr => strarr.Select(long.Parse).ToArray();
    public int [] intarr => strarr.Select(int.Parse).ToArray();



}

class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 15440
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111
	
	struct FenwickTree {
    vector<int> bit;  // binary indexed tree
    int n;

    FenwickTree(int n) {
        this->n = n;
        bit.assign(n, 0);
    }

    FenwickTree(vector<int> a) : FenwickTree(a.size()) {
        for (size_t i = 0; i < a.size(); i++)
            add(i, a[i]);
    }

    int sum(int r) {
        int ret = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret += bit[r];
        return ret;
    }

    int sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }

    void add(int idx, int delta) {
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
    }
	
};
	

	void solve(){


		// ini(n1);
		// FenwickTree bit(n1);
		// FOR(i,0,n1){
		// 	ini(x);
		// 	bit.add(i,x);
		// }
		// ini(tmp1);
		// FOR(i,0,n1){
		// 		out(bit.sum(i,i));
		// 	}
		// FOR(i,0,tmp1){
		// 	ini(x,x1);
		// 	x--;
		// 	bit.add(x,-1*(bit.sum(x,x)));
		// 	bit.add(x,x1);
		// 	FOR(i,0,n1){
		// 		out(bit.sum(i,i));
		// 	}
		// 	out(bit.sum(n1-1));
		// }

		ini(n);
		map<int,int>map1;
		FOR(i,0,n){
			ini(x);
			map1[x]++;
		}
		int tmp = 0;
		FORR(x,map1){
			tmp+=x.first*x.second;
		}
		ini(n1);
		FOR(i,0,n1){
			ini(x,x1);
			tmp-=map1[x]*x;
			tmp+=x1*map1[x];
			map1[x1]+=map1[x];
			map1[x] = 0;
			out(tmp);
		}
		


			
			
			


				
		


		
		
		
		

		


		
		
	}



	



















int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 9496
n,x,y=map(int,input().split())
ans=[0 for _ in range(n+1)]
for i in range(1,n+1):
    for j in range(i+1,n+1):
        ans[min(abs(j-i),abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(j-x))]+=1

for i in range(1,n):
    print(ans[i])

Measured memory_bytes: 3444
#include<cstdio>
#include<algorithm>
int a[51];
bool cmp(const int a, const int b) {return a > b;}
int main()
{
	int n, k, sum = 0;
	scanf("%d%d",&n, &k);
	for(int i = 0;i < n;++i) scanf("%d",&a[i]);
	std::sort(a, a + n, cmp);
	for(int i = 0;i < k;++i) sum += a[i];
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] d = new int[k];
		int[] a = new int[n];
		for( int i=0 ; i < k ; i++ ) {
			d[i] = sc.nextInt();
			for( int j=0 ; j < d[i] ; j++ ) {
				int p = sc.nextInt(); 
				a[p-1]++;
			}
		}
		
		int c=0;
		for(int i=0; i<n ; i++ ) {
			if( a[i] == 0 )c++;
		}
		
		System.out.println(c);

	}

}



Measured memory_bytes: 46316
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, int> P;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define SP cout << fixed << setprecision(10)
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int main(void) {
    // code

    int n, k;
    cin >> n >> k;
    vector<int> x(n), y(n);
    vector<int> xarr, yarr;
    rep(i, n) {
        cin >> x[i] >> y[i];
        xarr.push_back(x[i]);
        yarr.push_back(y[i]);
    }

    sort(ALL(xarr));
    sort(ALL(yarr));

    ll ans = (ll)(xarr[n - 1] - xarr[0]) * (ll)(yarr[n - 1] - yarr[0]);

    rep(xi, n) {
        FOR(xj, xi, n) {
            rep(yi, n) {
                FOR(yj, yi, n) {
                    ll lx = xarr[xi], rx = xarr[xj];
                    ll by = yarr[yi], uy = yarr[yj];

                    int num = 0;
                    rep(i, n) {
                        if (lx <= x[i] && x[i] <= rx && by <= y[i] &&
                            y[i] <= uy) {
                            num++;
                        }
                    }

                    if (num >= k) {
                        ans = min(ans, (rx - lx) * (uy - by));
                    }
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(a) (a).begin(),(a).end()
 
using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
 
const ll MOD  = 998244353;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;

//組み合わせの計算
const ll MAX = 1e6+9;
ll fac[MAX], finv[MAX], inv[MAX];
//初期化
void COMinit() {
    fac[0]  = fac[1]  = 1;
    finv[0] = finv[1] = 1;
    inv[1]  = 1;

    for(int i = 2; i < MAX; ++i){
        fac[i]  = fac[i - 1] * i % MOD;
        inv[i]  = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
//nCk
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;

    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//べき乗でMODが計算できる
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    ll n, m, k;
    cin >> n >> m >> k;
    
    ll ans = 0;
    COMinit();

    rep(i, k+1){
        ll add = (m * modpow(m-1, n-1-i, MOD)) % MOD;
        ans += add * COM(n-1, i);
        ans %= MOD;
    }   
    
   cout << ans << endl;
}

Measured memory_bytes: 27076
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#include <cassert>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
    // ABC169-C, 
    /*ll a; double b; ll c; cin >> a >> b;
    c = round(b * ll(100));
    cout << a * c / ll(100) << endl;
    */
    
    // ABC169-B
    ll n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(ALL(a));
    if (a[0] == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    ll limit = 1e18;
    rep(i, n) {
        if (limit / a[i] < ans || limit < ans * a[i]) {
            cout << -1 << endl;
            return 0;
        }
        ans = ans * a[i];
    }
    cout << ans << endl;
    return 0;
}

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

template <typename T>
class FenwickTreeAdd{
  using value_type = T;
  
  int size;
  std::vector<value_type> data;
  
public:
  FenwickTreeAdd(){}
  FenwickTreeAdd(int size): size(size), data(size + 1, 0){}
  
  void update(int i, value_type val){
    i += 1; // 1-index
    
    while(i <= size){
      data[i] = data[i] + val;
      i += i & (-i);
    }
  }
  
  value_type get(int i) const { // [0, i)
    value_type ret = 0;
    i += 1; // 1-index

    while(i > 0){
      ret = ret + data[i];
      i -= i & (-i);
    }

    return ret;
  }

  value_type get(int l, int r) const { // [l, r)
    return get(r-1) - get(l-1);
  }
};


template <typename T>
struct RangeCountQuery{
  std::vector<int> a;
  std::vector<std::pair<int, int>> qs;
  std::map<std::pair<int, int>, std::vector<int>> index;
  int N;

  RangeCountQuery(std::vector<T> a_): N(a_.size()){
    auto temp = a_;
    std::sort(temp.begin(), temp.end());
    temp.erase(std::unique(temp.begin(), temp.end()), temp.end());

    for(auto x : a_){
      int i = std::lower_bound(temp.begin(), temp.end(), x) - temp.begin(); 
      a.push_back(i);
    }
  }

  void add(int l, int r){ // [l, r)
    index[{l, r}].push_back(qs.size());
    qs.emplace_back(r, l);
  }

  auto solve(){
    std::sort(qs.begin(), qs.end());

    FenwickTreeAdd<int> b(N);

    const int Q = qs.size();
    std::vector<int> last_index(N, -1);
    std::vector<int> ret(Q);
  
    int cur = 0;
    for(auto [r, l] : qs){
      while(cur < r){
        if(last_index[a[cur]] != -1){
          b.update(last_index[a[cur]], -1);
        }

        last_index[a[cur]] = cur;
        b.update(last_index[a[cur]], 1);

        ++cur;
      }

      auto t = index[{l, r}];
      for(int i : t){
        ret[i] = b.get(l, r);
      }
    }
    
    return ret;
  }
};


int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  
  int N, Q; std::cin >> N >> Q;
  std::vector<int> c(N);
  for(int i = 0; i < N; ++i) std::cin >> c[i];

  RangeCountQuery<int> rcq(c);

  for(int i = 0; i < Q; ++i){
    int l, r; std::cin >> l >> r;
    rcq.add(l - 1, r);
  }

  auto ans = rcq.solve();

  for(auto x : ans) std::cout << x << "\n";

  return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  
  int c = 0;
  for(int i = 0; i < K; i++){
    c += A.at(i);
  }
  cout << c << endl;
}

Measured memory_bytes: 3628
class UnionFind:
    def __init__(self, num):
        self.parent = [-1] * num

    def find(self, node):
        if self.parent[node] < 0:
            return node
        self.parent[node] = self.find(self.parent[node])
        return self.parent[node]

    def union(self, node1, node2):
        node1 = self.find(node1)
        node2 = self.find(node2)
        if node1 == node2:
            return
        if self.parent[node1] > self.parent[node2]:
            node1, node2 = node2, node1
        self.parent[node1] += self.parent[node2]
        self.parent[node2] = node1
        return

    def same(self, node1, node2):
        return self.find(node1) == self.find(node2)

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

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

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


n, m = map(int, input().split())

uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a, b)

print(uf.group_count() - 1)



Measured memory_bytes: 74852
// G++ MACRO.CPP -STD=C++17
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
 
#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
 
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
 
#define FOREACH(x,a) for(auto& (x) : (a) )
 
#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])
 
#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl
 
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}
 
#define ALL(obj) (obj).begin(),(obj).end()
 
#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
 
template <class T = ll>
T IN(){T x;cin>>x;return (x);}
 
template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}
 
template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}
 
#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc
 
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int
 
#define P pair<ll,ll>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>
 
#define pb(a) push_back(a)
#define mp make_pair

int main(){
  LCIN(x);
  ll ng = 0; ll ok = LINF;

  auto f = [&](ll p){
    ll num = (p / 2) * 11;
    if(p % 2 == 1) num += 6;
    return num >= x;
  };

  while(abs(ok-ng)>1){
    ll num = (ok+ng)/2;
    (f(num)?ok:ng)=num;
  }
  COUT(ok);

  return 0;
}

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

int main(void){
    int n;
    scanf("%d", &n);
    if(n/100 == 9) n = n - 800;
    else if(n/100 == 1) n = n + 800;
    if(n%100/10 == 9) n = n - 80;
    else if(n%100/10 == 1) n = n + 80;
    if(n%10 == 9) n = n - 8;
    else if(n%10 == 1) n = n + 8;
    printf("%d", n);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
const int INF = 1001001001;

int main() {
    int n, m;
    int sum = 0;
    cin >> n;
    vector<int> t(n);
    rep(i, n){
        cin >> t[i];
        sum += t[i];
    }
    cin >> m;
    rep(i, m){
        int p, x;
        cin >> p >> x;
        p--;
        cout << sum - t[p] + x << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>  
using namespace std;  
  
typedef long long LL;  
const int maxn = 1e5;  
int n, a, b, m[maxn+3];  
  
bool judge(LL x)  
{  
    LL sum = 0;  
    for(int i=0; i<n; ++i)  
    {  
        LL t = (LL)m[i]-x*b;  
        if(t>0)  
        {  
            sum += (int)ceil(t*1.0/(a-b));  
            if(sum > x || sum < 0)  
                return false;  
        }  
    }  
    return true;  
}  
int main()  
{  
    while(~scanf("%d%d%d",&n,&a,&b))  
    {  
        int imax = 0;  
        for(int i=0; i<n; ++i) scanf("%d",&m[i]), imax = max(imax, m[i]);  
        LL l=0, r=imax;  
        while(l<r)  
        {  
            LL mid = l+r>>1;  
            if(judge(mid)) r=mid;  
            else l=mid+1;  
        }  
        printf("%lld\n",r);  
    }  
    return 0;  
}  

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

using namespace std;
#define BUF (1000)
#define ll long long 

ll a,b;
ll ans = 0;
int main(void){
	cin >> a >> b;

	ll diff = b-a+1;

	if(a%2==0 && b%2==1){
		ans^=(diff/2)%2;
	}else if(a%2==1 && b%2==1){
		ans ^= a;
		ans ^= ((diff-1)/2)%2;
	}else if(a%2==0 && b%2==0){
		ans ^= b;
		ans ^= ((diff-1)/2)%2;
	}else if(a%2==1 && b%2==0){
		ans ^= a;
		ans ^= b;
		ans ^= ((diff-2)/2)%2;
	}

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


Measured memory_bytes: 256
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let (a, b, x): (usize, usize, usize) = parse_line().unwrap();

    if a <= x && x <= a + b {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
typedef long long int lli;
lli temp;
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

typedef pair<lli,lli> pii;
typedef vector<int> vi;
typedef vector<bool> vb;



void solve(){
  int n,m;
  cin>>n>>m;
  vi adj[n+1];
  for(int i = 0;i<m;i++){
    int u,v;
    cin>>u>>v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  vb visit(n+1);
  vi par(n+1);
  queue<int> q;
  visit[1] = true;
  q.push(1);
  while(!q.empty()){
    int s = q.front(); q.pop();

    for(auto c:adj[s]){
      if(visit[c]) continue;
      visit[c] = true;
      par[c] = s;
      q.push(c);
    }
  }

  bool flag = true;
  for(int i = 2;i<=n;i++){
    if(visit[i]==false)
      flag = false;
  }
  if(!flag){
    cout<<"No";
    return;
  }

  cout<<"Yes"<<endl;
  for(int i = 2;i<=n;i++){
    cout<<par[i]<<endl;
  }
}


int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 10164
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int i, j;

    int a[3];

    int b[3];

    int c[3][3];
   
      
    for( i = 0 ; i < 3 ; i = i + 1){

        for( j = 0 ; j < 3 ; j = j + 1 ){

             scanf("%d", &c[i][j]);

             }

        }


    a[0] = 0;

    for( i = 0 ; i < 3 ; i = i + 1 ){

         b[i] = c[0][i];

         }

    for( i = 1 ; i < 3 ; i = i + 1 ){

         a[i] = c[i][0] - c[0][0];

         }


    for( i = 0 ; i < 3 ; i = i + 1 ){

        for( j = 0 ; j < 3 ; j = j + 1 ){

             if( c[i][j] != a[i] + b[j] ){

                 printf("No\n");

                 return 0;

                 }

             }

        }


    printf("Yes\n");


    return 0;
                                                          
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
const int N=400050;
char s[N];
const int mod=1e9+7;
int main()
{
	int n;
	scanf("%i %s",&n,s+1);
	n*=2;
	int bl=0;
	int ans=1;
	for(int i=1;i*2<=n;i++) ans=(ll)ans*i%mod;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='B')
		{
			if(bl%2==0)
			{
				bl++;
			}
			else
			{
				ans=(ll)ans*bl%mod;
				bl--;
				if(bl<0) return 0*printf("0\n");
			}
		}
		else
		{
			if(bl%2==1)
			{
				bl++;
			}
			else
			{
				ans=(ll)ans*bl%mod;
				bl--;
				if(bl<0) return 0*printf("0\n");
			}
		}
	}
	if(bl!=0) return 0*printf("0\n");
	printf("%i\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define ull unsigned long long
#define FI(i,a,n) for(int i=a; i<=n; i++)
#define RFI(i,n,a) for(int i=n; i>=a; i--)
#define FLL(i,a,n) for(ll i=a; i<=n; i++)
#define RFLL(i,n,a) for(ll i=n; i>=a; i--)
#define vi vector<int>
#define vll vector<ll>
#define all(v) v.begin(),v.end()
#define pll pair<ll,ll>
#define pi pair<int, int>
#define GCD(a,b) __gcd(a,b)
#define MP make_pair
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define debug(x) cout << x << endl
/* #define MOD 1000000007 */
#define MOD 998244353
#define INF LLONG_MAX
#define PI 3.14159265359
#define MAX 100000
using namespace std;

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


int main()
{
  fastio
  /* int t; cin >> t; */
  /* while(t--) */
  /* { */
  /* } */
  int w, s;
  cin >> s >> w;
  if(w>=s) cout << "unsafe";
  else cout << "safe";
  return 0;
}




Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
using namespace std;
 
int main(){
    unsigned long long int H, W;
    // int N, M;
    cin >> H >> W;
    unsigned long long int res = H*W;
  
    if (H == 1 || W == 1){
        cout << 1;
    }
    else{
        if(H%2 == 1 && W%2 ==1){
            cout << res/2 + 1;
        }
        else{
            cout << res/2;
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1010;
ll ans = 0;int n,k;
ll a[maxn],b[maxn],c[maxn],d[maxn];
void init(int s)
{
	for(int i=1;i<=n;i++)
	{
		if(s&1)a[i] = -a[i];
		if(s&2)b[i] = -b[i];
		if(s&4)c[i] = -c[i];
	}
	return ;
}
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i]>>b[i]>>c[i];
	for(int i=0;i<8;i++)
	{
		init(i);
		ll cur = 0;
		for(int j=1;j<=n;j++)
			d[j] = -(a[j]+b[j]+c[j]);
		sort(d+1,d+1+n);
		for(int j=1;j<=k;j++)
			cur += -d[j];
		if(cur>ans)ans = cur;
		init(i);
	}
	cout << ans <<endl;
	return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
if a==b==c:
  print(-(a%2<1))
else:
  s=0
  while a%2<1and b%2<1and c%2<1:
    a,b,c=(b+c)//2,(c+a)//2,(a+b)//2
    s+=1
  print(s)

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
    public static void main(String[] args) throws IOException{


        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String word = br.readLine();
        String key = br.readLine();
        word = word + word;

        if(bmStringSearch(word,key)){
        	System.out.println("Yes");
        }else{
        	System.out.println("No");
        }

    }

    private static boolean bmStringSearch(String word, String key){
    	 int[] table = new int[Character.MAX_VALUE];

         for(int i=0;i<table.length;i++){
         	table[i] = key.length();
         }
         for(int i=0;i<key.length();i++){
         	table[key.charAt(i)] = key.length() - i - 1;
         }

         int wordIndex = key.length() - 1;
         int checkWordLength = word.length() / 2 + key.length();
         while(wordIndex < checkWordLength){
         	int keyIndex = key.length() -1;

         	while(word.charAt(wordIndex) == key.charAt(keyIndex)){
         		if(keyIndex == 0){
         			return true;
         		}
         		wordIndex--;
         		keyIndex--;
         	}

         	if(table[word.charAt(wordIndex)] > key.length()-keyIndex){
         		wordIndex += table[word.charAt(wordIndex)];
         	}else{
         		wordIndex += key.length() - keyIndex;
         	}
         }

         return false;
    }


}

Measured memory_bytes: 24812
import copy
def main():
    N = int(input())
    if N == 3:
        return 61
    mod = 10**9 + 7
    d = {'A':0, 'C':1, 'G':2, 'T':3}
    AGC = [[[1] * 4 for _ in range(4)] for _ in range(4)]
    AGC[d['A']][d['G']][d['C']] = 0
    AGC[d['A']][d['C']][d['G']] = 0
    AGC[d['G']][d['A']][d['C']] = 0
    NAGC = [[[1] * 4 for _ in range(4)] for _ in range(4)]
    for i in range(3, N):
        for i1 in range(4):
            for i2 in range(4):
                for i3 in range(4):
                    t = 0
                    if (i2 == d['G'] or i1 == d['G']) and i3 == d['C']:
                        for i4 in range(1, 4):
                            t += AGC[i4][i1][i2]
                    else:
                        for i4 in range(4):
                            t += AGC[i4][i1][i2]
                    if i1 == d['A'] and i2 == d['G'] and i3 == d['C']:
                        t = 0
                    if i1 == d['A'] and i2 == d['C'] and i3 == d['G']:
                        t = 0
                    if i1 == d['G'] and i2 == d['A'] and i3 == d['C']:
                        t = 0
                    t %= mod
                    NAGC[i1][i2][i3] = t
        AGC = copy.deepcopy(NAGC)
    return sum(sum(sum(j) for j in i) for i in AGC) % mod
print(main())


Measured memory_bytes: 3540
# D - People on a Line
import sys
sys.setrecursionlimit(10 ** 9)

n,m = map(int,input().split())
e = [[] for _ in range(n)]
for i in range(m):
  l,r,d = map(int,input().split())
  l -= 1
  r -= 1
  e[l].append((r,d))
  e[r].append((l,-d))

INF = float('inf')
c = [INF for _ in range(n)]

def dfs(u,x):
  c[u] = x
  for v,d in e[u]:
    if c[v] != INF:
      if c[v] == c[u]+d:
        continue
      else:
        print('No')
        exit()
    else:
      dfs(v,c[u]+d)

for i in range(n):
  if c[i] == INF:
    dfs(i,0)
print('Yes')


Measured memory_bytes: 134020
# -*- coding: utf-8 -*-

# 最大公約数
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return y


a, b, c, d = map(int, input().split())

cb = b//c
ca = (a-1)//c
cc = cb-ca

# print(cb, ca, cc)

db = b//d
da = (a-1)//d
dd = db-da

# print(db, da, dd)

cd = c*d // gcd(c, d)
cdb = b//cd
cda = (a-1)//cd
cdcd = cdb-cda

# print(cdb, cda, cdcd)

print(b-a+1-(cc+dd-cdcd))

Measured memory_bytes: 3064