Harryxun/stf_run huggingface dataset:
import math
a,b = input().split(" ")
ab = int(a+b)
if math.sqrt(ab) = int(np.sqrt(ab)):
  print("Yes")
else:
  print("No")


### FIXED CODE ###

a,b = input().split(" ")
ab = int(a+b)
for i in range(1,400):
  if i**2 == ab:
    print("Yes")
    exit()
print("No")
n = int(input())
# min, max, sum は関数名なので
# 別名を使うとよい
min0 = 100000
max0 = -100000
sum0 = 0
for i in range(n):
  x = int(input())
  min0 = min(min0, x)
  max0 = max(max0, x)
 sum0 += x
 
print(min0, max0, sum0)


### FIXED CODE ###

n = int(input())
ns = list(map(int, input().split()))

print(min(ns), max(ns), sum(ns))
N = int(input())

frames = []
for i range(N):
  frames.append(int(input()))

mean = sum(frames) / N

sa = 100
for i in range(N):
  if sa > abs(frames[i] - mean):
    sa = abs(frames[i] - mean)
    ind = i
    
print(ind)

### FIXED CODE ###

N = int(input())

frames = list(map(int, input().split(" ")))

mean = sum(frames) / N

sa = 100
ind = 0
for i in range(N):
  if sa > abs(frames[i] - mean):
    sa = abs(frames[i] - mean)
    ind = i
    
print(ind)
a,b=map(int,input().split())
print((3*a+b)//2)


### FIXED CODE ###

a,b=map(int,input().split())
print((3*a+b)//2)
s=input();n=len(s);print(min(max(i,n-i*(s[i-1]!=s[i]))for i in range(1,n)))

### FIXED CODE ###

s=input();n=len(s);print(min([max(i,n-i)for i in range(1,n)if s[i-1]!=s[i]]or[n]))
l =[input() for i in range(n)]
r=[]
d={}
for i in l:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
m = max(d.values())
for key,value in d.items():
    if value==m:
        r.append(key)
sorted_r = sorted(r)
print(*sorted_r,sep='\n')

### FIXED CODE ###

n = int(input())
l =[input() for i in range(n)]
r=[]
d={}
for i in l:
    if i in d:
        d[i]+=1
    else:
        d[i]=1
m = max(d.values())
for key,value in d.items():
    if value==m:
        r.append(key)
sorted_r = sorted(r)
print(*sorted_r,sep='\n')
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if e-d>=k and e-c>=k and e-b>=k and e-b>=k and e-a>=k and d-c>=k and d-b>=k and d-a>=k and c-b>=k and c-a>=k and b-a>=k:
  print('Yay!')
else:
  prit(':(')


### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())
if e-d<=k and e-c<=k and e-b<=k and e-a<=k and d-c<=k and d-b<=k and d-a<=k and c-b<=k and c-a<=k and b-a<=k:
  print('Yay!')
else:
  print(':(')
x,y = int(input().split())
 
if x*4>y and y<x*2 and y%2 == 0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

x,y = input().split()
 
x=int(x)
y=int(y)
count = 0
for i in range(x+1):
  if 2*i+4*(x-i) == y:
    print("Yes")
    count = 1

if count == 0:
	print("No")
input()
N = int(input())
A = list(map(int, input().split())

S = A[0]
for i in range(1, N):
	S = S * A[i]
	if S > 10**18:
         print(-"1")
print(S)

### FIXED CODE ###

def main ():
	N = int(input())
	A = list(map(int,input(). split ()))
	if 0 in A:
		print(0)
		return
	prod = 1
	for a in A:
		prod *= a
		if prod > 1000000000000000000:
			print(-1)
			return
	print(prod)
main ()
n = int(input())
l = list(input().split())

l.sort(reverse = True)

if len(l) == n:
  lm = l[0]

  del l[0]

  if lm < sum(l):
    print('Yes')
  else:
    print('No')
else:
  print('No')


### FIXED CODE ###

n = int(input())
l = [int(i) for i in input().split()]

l.sort(reverse = True)

if len(l) == n:
  lm = l[0]

  del l[0]

  if int(lm) < sum(l):
    print('Yes')
  else:
    print('No')
else:
  print('No')
n, m = map(int,input().split())
num = list(map(int,input().split()))
num_dic = {1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}

dp = [0]*(n+1)

def creat_num(original,num):#original=431,num=1 return 4311
    if original == 0:
        return num
    new = list(map(int,list(str(original)))) + [num]
    new.sort()
    new.reverse()
    return int("".join(list(map(str,new))))

def match_dp(dp,num,num_dic,n):
    for i in num:
        if n - num_dic[i] >= 0:
            new_num = creat_num(dp[n],i)
            dp[n-num_dic[i]] = max(new_num, dp[n-num_dic[i]])
            match_dp(dp,num,num_dic,n-num_dic[i])

match_dp(dp,num,num_dic,n)

print(dp[0])

### FIXED CODE ###

#参照　https://atcoder.jp/contests/abc118/submissions/4292288
n,m = map(int, input().split())
b = [0,2,5,5,4,5,6,3,7,6]
a = [0]+list(map(int, input().split()))
f = [-1]*(n+1)
f[0]=0
for i in range(1,n+1):
    for j in range(1,m+1):
        x = a[j]
        if(i-b[x]<0):
            continue
        f[i] = max(f[i],f[i-b[x]]*10 + x)
        #print(i+1,"番目に,",str(f[i])+","+str(f[i-b[x]]*10 + x),"の最大値を入れると",f)
print(f[n])
A = int(input())
B = int(input())

A_s =str(A)
B_s = str(B)

if len(A_s) > len(B_s):
    print("GREATER")
elif len(A_s) < len(B_s):
    print("LESS")
else:
    for i in range(len(A_s)):
        if A[i] > B[i]:
            print("GREATER")
            break
        elif A[i] < B[i]:
            print("LESS")
            break
        elif (A[i] == B[i]) & (i == len(A_s)-1):
            print("EQUAL")
            break
            
    
            

### FIXED CODE ###

A = int(input())
B = int(input())

A_s =str(A)
B_s = str(B)

if len(A_s) > len(B_s):
    print("GREATER")
elif len(A_s) < len(B_s):
    print("LESS")
else:
    for i in range(len(A_s)):
        if A_s[i] > B_s[i]:
            print("GREATER")
            break
        elif A_s[i] < B_s[i]:
            print("LESS")
            break
        elif (A_s[i] == B_s[i]) & (i == len(A_s)-1):
            print("EQUAL")
            break
a, b = map(int, input().split())

if a < 1 or a > 9:
    return -1

if b < 1 or b > 9;
    return -1

return a * b

### FIXED CODE ###

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

if a < 1 or a > 9:
    print(-1)
elif b < 1 or b > 9:
    print(-1)
else:
    print(a * b)
from collections import defaultdict

def DFS(u,G,H,A,visited):
    visited[u]=True
    for v in G[u]:
        if not visited[v]:
            if H[u-1]>H[v-1]:
                A[u]+=1
            elif H[v-1]>H[u-1]:
                A[v]+=1
            DFS(v,G,H,A,visited)
def DFSUtil(G,H,N):
    visited=[False]*(N+1)
    A=[0]*(N+1)
    for u in G:
        if (not visited[u]):
            DFS(u,G,H,A,visited)
    return A
N,M=map(int,input().strip().split())
H=list(map(int,input().strip().split()))
G=defaultdict(list)

for i in range(M):
    u,v=map(int,input().strip().split())
    G[u].append(v)
    G[v].append(u)
A=DFSUtil(G,H,N)
cnt=0
for i in range(1,N+1):
    neighbours=len(list(set(G[i])))
    if neighbours==A[i]:
        cnt+=1
print(cnt)

### FIXED CODE ###

from collections import defaultdict
import sys
sys.setrecursionlimit(100000000)
def DFS(u,G,H,A,visited,P):
    visited[u]=True
    for v in G[u]:
        if not (min(u,v),max(u,v)) in P:
            if H[u-1]>H[v-1]:
                    A[u]+=1
            elif H[v-1]>H[u-1]:
                    A[v]+=1
            P.add((min(u,v),max(u,v)))
        if not visited[v]:
            DFS(v,G,H,A,visited,P)

def DFSUtil(G,H,N):
    visited=[False]*(N+1)
    A=[0]*(N+1)
    P=set()
    for u in G:
        if (not visited[u]):
            DFS(u,G,H,A,visited,P)
    return A
N,M=map(int,input().strip().split())
H=list(map(int,input().strip().split()))
G=defaultdict(list)

for i in range(M):
    u,v=map(int,input().strip().split())
    G[u].append(v)
    G[v].append(u)
A=DFSUtil(G,H,N)
cnt=0
for i in range(1,N+1):
    neighbours=len(list(set(G[i])))
    if neighbours==A[i]:
        cnt+=1
print(cnt)
N, K=map(int,input().split())
A=list(map(int,input().split()))
B=sorted([(a,abs(a)) for a in A],key=lambda x:x[1],reverse=True)
R=10**9+7
P=1
minus=0
last_neg=-1
last_pos=-1
for i in range(K):
    if i!=0:
        P=(P*B[i-1][1]) %R
    if B[i][0]>0:
        last_pos=i
    else:
        minus+=1
        last_neg=i
if minus%2==1:
    first_neg=-1
    first_pos=-1
    count=[0,0]
    for i in range(K,N):
        if count[0]==0 and B[i][0]>0:
            first_pos=i
            count[0]=1
            if last_neg<last_pos:
                count[1]=1
                break
        elif count[1]==0 and B[i][0]<0:
            first_neg=i
            count[1]=1
            if last_pos<last_neg:
                count[0]=1
                break
        elif count==[1,1]:
            break
    if last_pos==-1 and first_pos==-1:
        P=1
        for i in range(K):
            P=(P*B[N-i-1][0]) %R
        print(P)
        exit()
    list_product=[]
    if first_neg!=-1:
        list_product.append((P*B[first_neg][1]) %R)
    if first_pos!=-1:
        list_product.append((P*B[first_pos][1]) %R)
    print(max(list_product))
else:
    print(P*B[K-1][1] %R)


### FIXED CODE ###

import copy
N, K=map(int,input().split())
A=list(map(int,input().split()))
B=sorted([(a,abs(a)) for a in A],key=lambda x:x[1],reverse=True)
R=10**9+7
P=1
minus=0
last_neg=-1
last_pos=-1
for i in range(K):
    if B[i][0]>0:
        if last_pos != -1:
            P = (P * B[last_pos][1]) % R
        last_pos=i
    elif B[i][0]<0:
        if last_neg != -1:
            P = (P * B[last_neg][1]) % R
        minus+=1
        last_neg=i
    else:
        print(0)
        exit()
F=copy.copy(P)
if last_pos!=-1:
    F=(F*B[last_pos][1]) % R
if last_neg!=-1:
    F=(F*B[last_neg][1]) % R
if minus%2==1:
    if K == N:
        print(-F %R)
        exit()
    first_neg=-1
    first_pos=-1
    count=[0,0]
    for i in range(K,N):
        if count[0]==0 and B[i][0]>0:
            first_pos=i
            count[0]=1
        elif count[1]==0 and B[i][0]<0:
            first_neg=i
            count[1]=1
        elif count==[1,1]:
            break
    if first_pos==-1 and last_pos==-1:
        P = 1
        for i in range(K):
           P = (P * B[N - i - 1][0]) % R
        print(P)
        exit()
    if first_pos==-1 and first_neg==-1:
        print(0)
        exit()
    list_product=[]
    if first_neg!=-1 and last_pos!=-1:
        list_product.append(B[last_neg][1]*B[first_neg][1])
    if first_pos!=-1:
        P1=B[first_pos][1]
        if last_pos!=-1:
            P1=P1*B[last_pos][1]
        list_product.append(P1)
    print(max(list_product)*P %R)
else:
    print(F)
import sys

inputdata=sys.stdin.readlines()
whn=int(inputdata[0].split( ))
W=whn[0]
H=whn[1]
N=whn[2]
data1=[]
data2=[]
data3=[]
data4=[]
for i in inputdata:
	if i[-1]=="1":
		data1.append(int(i.split( )))
	elif i[-1]=="2":
		data2.append(int(i.split( )))
	elif i[-1]=="3":
		data3.append(int(i.split( )))	
	elif i[-1]=="4":
		data4.append(int(i.split( )))
		
a=0
for i in data1:
	if a<i:
		a=i
b=W
for i in data2:
	if b>i:
		b=i

c=0
for i in data3:
	if c<i:
		c=i					
d=H
for i in data4:
	if d>i:
		d=i
 		
if c>=d:
 	print("0")
elif b<=a:
 	print("0")
else:
 	print(str((d-c)*(b-a)))


### FIXED CODE ###

whn=input().split(" ")
W=int(whn[0])
H=int(whn[1])
N=int(whn[2])
a=[]
for i in range(N):
    a.append(input().split(" "))

left=0
right=W
top=H
bottom=0

for i in range(N):
    if a[i][2]=="1":
        if left<int(a[i][0]):
            left=int(a[i][0])
    elif a[i][2]=="2":
        if right>int(a[i][0]):
            right=int(a[i][0])
    elif a[i][2]=="3":
        if bottom<int(a[i][1]):
            bottom=int(a[i][1])
    elif a[i][2]=="4":
        if top>int(a[i][1]):
            top=int(a[i][1])


if left>=right:
    print(0)
elif top<=bottom:
    print(0)
else:
    print((top-bottom)*(right-left))
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = sorted(na())
x = [[0]*n for _ in range(30)]
 
if n%3:
    if max(a):
        print("No")
    else:
        print("Yes")
else:
    m = n//3
    if A[0] == A[m-1] and A[m] == A[2*m-1] and A[2*m] == A[3*m-1] and A[0]^A[m] == A[2*m]:
        print("Yes")
    else:
        print("No")

### FIXED CODE ###

import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = sorted(na())
x = [[0]*n for _ in range(30)]
 
if n%3:
    if max(a):
        print("No")
    else:
        print("Yes")
else:
    m = n//3
    if a[0] == a[m-1] and a[m] == a[2*m-1] and a[2*m] == a[3*m-1] and a[0]^a[m] == a[2*m]:
        print("Yes")
    else:
        print("No")
#include <bits/stdc++.h>
using namespace std;

int main() {
  int h, w; cin >> h >> w;
  vector<string> board(h);
  for (auto& e: board) cin >> e;

  vector<bool> rowIncludeSharp(h), colIncludeSharp(w);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (board[i][j] == '#') {
        rowIncludeSharp[i] = true;
        colIncludeSharp[j] = true;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    if (rowIncludeSharp[i]) {
      for (int j = 0; j < w; j++) {
        if (colIncludeSharp[j]) {
          cout << board[i][j];
        }
      }
      cout << endl;;
    }
  }
}

### FIXED CODE ###

h,w=map(int,input().split());print(*["".join(e)for e in zip(*["".join(e)for e in zip(*[e for e in[input()for _ in[0]*h]if"#"in e])if"#"in e])],sep="\n")
# 深さ優先探索で各直線を考える
def dfs(parent):
    for child in tree[parent]:
        # 累積和の計算
        ans[child] += ans[parent]
        dfs(child)


n, q = map(int, input().split())
# tree[i]: 頂点i+1の子どもたち
tree = [[] for i in range(n)]
ans = [0] * n

for _ in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)

for _ in range(q):
    p, x = map(int, input().split())
    ans[p - 1] += x

# 根ノードの頂点1から開始
dfs(0)
print(*ans)


### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
# 深さ優先探索で各直線を考える


def main():
    def dfs(v, p):
        for u in tree[v]:
            if u == p:
                continue
            # 累積和の計算
            ans[u] += ans[v]
            dfs(u, v)

    n, q = map(int, input().split())
    # tree[i]: 頂点i+1の子どもたち
    tree = [[] for i in range(n)]
    ans = [0] * n

    for _ in range(0, n - 1):
        a, b = map(int, input().split())
        tree[a - 1].append(b - 1)
        tree[b - 1].append(a - 1)

    for _ in range(q):
        p, x = map(int, input().split())
        ans[p - 1] += x

    # 根ノードの頂点 1 から開始
    dfs(0, -1)

    print(*ans)


if __name__ == '__main__':
    main()
n=int(input())
import sys
import math
list=[]


for i in range(0,int(math.sqrt(n))):
    if n%(i+1)==0:
        list.append(i-1+(n/(i+1)))

print(int(min(list)))

### FIXED CODE ###

x,y = map(int,input().split())
import sys

if x>9 or y>9:
    print(-1)
else:
    print(x*y)
def find(A):
    N = len(A)
    ans = [0]*N
    odd_sum = [0]*N
    even_sum = [0]*N
    for i in range(N):
        if i%2 == 0:
            if i-2>=0:
                even_sum[i] = even_sum[i-2] + A[i]
            else:
                even_sum[i] = A[i]
        else:
            if i-2>=0:
                odd_sum[i] = odd_sum[i-2] + A[i]
            else:
                odd_sum[i] = A[i]
    if N%2==0:
        return max(odd_sum[-1],even_sum[-2])
    
    def find_ans(M):
        if M==3:
            return max(A[0],A[1],A[2])
        elif M==2:
            return max(A[0],A[1])
        elif M==1:
            return 0
        
        if M%2==0:
            return max(even_sum[M-2],odd_sum[M-1])
        else:
            temp1 = A[M-1] + find_ans(M-2)
            temp2 = find_ans(M-1)
            return max(temp1,temp2)
    return find_ans(N)
input()
A = list(map(int,input().strip().split()))
print(find(A))

### FIXED CODE ###

def find(A):
    N = len(A)
    ans = [0]*N
    odd_sum = [0]*N
    even_sum = [0]*N
    for i in range(N):
        if i%2 == 0:
            if i-2>=0:
                even_sum[i] = even_sum[i-2] + A[i]
            else:
                even_sum[i] = A[i]
        else:
            if i-2>=0:
                odd_sum[i] = odd_sum[i-2] + A[i]
            else:
                odd_sum[i] = A[i]

#     print(odd_sum)
#     print(even_sum)
    for i in range(1,N):
        length = i+1
        if length%2==0:
            ans[i] = max(A[i] + ans[i-2],odd_sum[i-1]+even_sum[i-1] )
        else:
            ans[i] = max(A[i] + ans[i-2],ans[i-1])
            
    return ans[-1]
    
input()   
print(find(list(map(int,input().strip().split()))))
n = int(input())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0
 
diff = []
for i, index in enumerate(a,1):
    diff.append(abs(i - index))
 
diff.sort()
if n % 2 == 1:
    b = diff[len(diff) // 2]
    for i in diff:
        ans1 += abs(i - b)
 
    print(ans1)
else:
    b1 = diff[len(diff) // 2 - 1]
    b2 = diff[len(diff) // 2]
    for i in diff:
        ans1 += abs(i -b1)
        ans2 += abs(i -b2)
    print(min(ans1.ans2))

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
diff = []
for i, index in enumerate(a,1):
    diff.append(i-index)

diff.sort()
if n % 2 == 1:
    b = diff[n // 2]
    tmp = map(lambda x: x - b, diff)
    print(sum( map(abs,tmp )))
else:
    b1 = diff[n // 2 - 1]
    b2 = diff[n // 2]
    tmp1 = map(lambda x: x - b1, diff)
    tmp2 = map(lambda x: x - b2, diff)
    ans1 = sum( map(abs,tmp1 ))
    ans2 = sum( map(abs,tmp2 ))
    print(min(ans1,ans2))
n,m,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = list(map(int,input().split()))

from collections import deque
sa = deque([x for x in a])
sb = deque([x for x in b])
sa.append(10**9+1)
sb.append(10**9+1)
ans = 0
def cnt(a,b,time):
  global ans
  #print(ans, time,a,b)
  if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
    if a[0] < b[0]:
      time += a[0]
      a.popleft()
    else:
      time += b[0]
      b.popleft()
    if time <= k:
      ans += 1
      if (time <= k) & ( (len(a) > 1) | (len(b) > 1)):
        #cnt(a,b,time)

cnt(sa,sb,0)
print(ans)

### FIXED CODE ###

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
sa = [0] * (n + 1)
sb = [0] * (m + 1)
for i in range(n):
  sa[i + 1] = sa[i] + a[i]
for i in range(m):
  sb[i + 1] = sb[i] + b[i]
r = m
ans = 0
for i in range(n + 1):
  if sa[i] > k:
    break
  while sa[i] + sb[r] > k:
    r -= 1
  ans = max(ans, i + r)
print(ans)
class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parent=[i for i in range(n)]
        self.rank=[1]*n#木の高さ
        self.size=[1]*n#size[i]はiを根とするグループのサイズ

    def find(self,x):#ｘの根（親）を返す
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.find(self.parent[x])#経路圧縮
            return self.parent[x]

    def unite(self,x,y):#ｘ、ｙの集合の統合
        x=self.find(x)
        y=self.find(y)
        if x!=y:
            if self.rank[x]<self.rank[y]:#ランクの比較
                self.parent[x]=y
                self.size[y]+=self.size[x]
            else:
                self.parent[y]=x
                self.size[x]+=self.size[y]
                if self.rank[x]==self.rank[y]:
                    self.rank[x]+=1

    def is_same(self,x,y):#ｘ、ｙが同じ集合に属するかを判定する
        return self.find(x)==self.find(y)

    def group_size(self,x):#ｘが属する集合の大きさ
        return self.size[self.find(x)]

    def group_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.parent) if i==x]

    def group_count(self):#木の数を返す
        return len(self.roots())

    def all_group_members(self):#すべての木の要素を辞書で返す
        return {r: self.group_members(r) for r in self.roots()}

n,m=map(int,input().split())
un=UnionFind(n)
for i in range(m):
    a,b=map(int,input().split())
    un.unite(a,b)
ans=un.group_count()-1
print(ans)

### FIXED CODE ###

class UnionFind:
    def __init__(self,n):
        self.n=n
        self.parent=[i for i in range(n)]
        self.rank=[1]*n#木の高さ
        self.size=[1]*n#size[i]はiを根とするグループのサイズ

    def find(self,x):#ｘの根（親）を返す
        if self.parent[x]==x:
            return x
        else:
            self.parent[x]=self.find(self.parent[x])#経路圧縮
            return self.parent[x]

    def unite(self,x,y):#ｘ、ｙの集合の統合
        x=self.find(x)
        y=self.find(y)
        if x!=y:
            if self.rank[x]<self.rank[y]:#ランクの比較
                self.parent[x]=y
                self.size[y]+=self.size[x]
            else:
                self.parent[y]=x
                self.size[x]+=self.size[y]
                if self.rank[x]==self.rank[y]:
                    self.rank[x]+=1

    def is_same(self,x,y):#ｘ、ｙが同じ集合に属するかを判定する
        return self.find(x)==self.find(y)

    def group_size(self,x):#ｘが属する集合の大きさ
        return self.size[self.find(x)]

    def group_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.parent) if i==x]

    def group_count(self):#木の数を返す
        return len(self.roots())

    def all_group_members(self):#すべての木の要素を辞書で返す
        return {r: self.group_members(r) for r in self.roots()}

n,m=map(int,input().split())
un=UnionFind(n)
for i in range(m):
    a,b=map(int,input().split())
    un.unite(a-1,b-1)
ans=un.group_count()-1
print(ans)
from more_itertools import windowed

print("")

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

N, M = [int(_) for _ in input().split()]
A = [int(input()) for i in range(M)]
isBroken = [False] * (N + 1)
for i in A:
    isBroken[i] = True


def solve():

    # It's impossible
    if M >= 1:
        temp = A[0]
        for a in A[1:]:
            if a - 1 == temp:
                return 0
            temp = a

    # We can
    memo = [0] * (N + 2)

    def rec(i):
        if i == 0:
            return 1
        if i < 0:
            return 0
        if isBroken[i]:
            return 0

        if memo[i] == 0:
            count1 = rec(i - 1) % 1000000007
            count2 = rec(i - 2) % 1000000007
            memo[i] = (count1 + count2) % 1000000007
        return memo[i]
    return rec(N)


print(solve())
n,x0=map(int,input().split())
x=sorted(list(map(int,input().split())))
y=[]
for i in range(n-1):
    y.append(x[i+1]-x[i])
mindelta=min(y)
ans=1
for i in range(1,mindelta+1):
    flag=True
    if abs(x0-x[0])%i!=0:
        flag=False
    for j in range(n-1):
        if y[j]%i!=0:
            flag=False
    if flag:
        ans=i
print(ans)

### FIXED CODE ###

n,x0=map(int,input().split())
x=list(map(int,input().split()))

def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
if n==1:
    ans=abs(x[0]-x0)
else:
    ans=gcd(abs(x[0]-x0),abs(x[1]-x0))
    for i in range(n):
        ans=gcd(ans,abs(x[i]-x0))
print(ans)
x=int(input())
a=[]
for i in range(2,10):
  for j in range(1,32):
    if j**i<=x:a.append(j**i)
print(max(a))​

### FIXED CODE ###

x=int(input())
a=[]
for i in range(2,10):
  for j in range(1,32):
    if j**i<=x:a.append(j**i)
print(max(a))
S=int(input())
W=int(input())
if W>=(S):
    print('Unsafe')
else:
    print('Safe')

### FIXED CODE ###

s, w = map(int, input().split())
 
if w >= s:
    print("unsafe")
else:
    print("safe")
x, y = map(int, input().split())

print(int(x + y / 2))
x, y = map(int, input().split())

print(int(x + y / 2))


### FIXED CODE ###

x, y = map(int, input().split())

print(int(x + y / 2))
a,b,c=(int(i) for i in input().split())
if b+1>=c:
  print(b+c)
else:
  if a+1>c-b:
    print(2*b+c)
  else:
    print(2b+a+1)

### FIXED CODE ###

a,b,c=(int(i) for i in input().split())
if b+1>=c:
  print(b+c)
else:
  if a+1>=c-b:
    print(b+c)
  else:
    print(2*b+a+1)
alp=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','z']
if a<27:
 print(alp[a-1])
else:
 b=a//26
 c=a%26
 ans=[]
 for i in range(17):
  if b/(10^(i+1))>0:
    d=int(b/(10^(i+1)))
    ans.append(alp[d-1])
  else:
    break
 ans.append(alp[c-1])

 print(ans)


### FIXED CODE ###

alp=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
n=int(input())
ans=""
while n>0:
 n-=1
 a=n%26
 ans+=alp[a] 
 n=int(n//26)
 
print(ans[::-1])