Harryxun/stf_run huggingface dataset:
def dfs(s):
    if visited[s]:
        return
    visited[s] = 1
    for to in t[s]:
        if visited[to]:
            continue
        dfs(to)
    
N, M = map(int,input().split())
t = [[] for _ in range(N)]
visited = [0] * N
for _ in range(M):
    X, Y, Z = map(int,input().split())
    X -= 1
    Y -= 1
    t[X].append(Y)
    t[Y].append(X)
for i in range(1, N + 1):
    s = visited.index(0)
    dfs(s)
    if min(visited):
        ans = i
        break
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10 ** 7)

def dfs(s):
    if visited[s]:
        return
    visited[s] = 1
    for to in t[s]:
        if visited[to]:
            continue
        dfs(to)
    
N, M = map(int,input().split())
t = [[] for _ in range(N)]
visited = [0] * N
for _ in range(M):
    X, Y, Z = map(int,input().split())
    X -= 1
    Y -= 1
    t[X].append(Y)
    t[Y].append(X)
ans = 0
for i in range(0, N):
    if visited[i]:
        continue
    ans += 1
    dfs(i)
print(ans)
tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dict = {}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dict[tmp[d]] = str(i)+' '+str(d)
result ={}
cost ={}

def calcost(L,R,D):
    if int(R)<=D:
        cost[R] = 0
        return 0
    else:
        posi1 = dict[R].split()
        posi2 = dict[str(int(R)-D)].split()
        costs = abs(int(posi2[0])-int(posi1[0])) + abs(int(posi2[1])-int(posi1[1]))
        if str(int(R)-D) in cost:
            cost[R] = costs + cost[str(int(R)-D)]
            return cost[R]
        else:
            cost[R] = costs + calcost(L,str(int(R)-D),D)
            return cost[R]

for n in range(D+1,H*W+1):
    calcost(str(1),str(n),D)

Q = int(input())
for j in range(Q):
    tmpx = input()
    if tmpx in result:
        print(result[tmpx])
    else:
        tmp = tmpx.split()
        result[tmpx] = cost[tmp[1]]-cost[tmp[0]]
        print(result[tmpx])
print(cost)

### FIXED CODE ###

tmp =input().split()
H,W,D=int(tmp[0]),int(tmp[1]),int(tmp[2])

list = [[0 for x in range(W)] for y in range(H)]
dictx ={}
dicty ={}
for i in range(H):
    tmp = input().split()
    for d in range(W):
        dictx[tmp[d]] = i
        dicty[tmp[d]] = d
cost ={}
def calcost(R):
    if int(R)<=D:
        cost[R] = 0
        return 0
    else:
        costs = abs(dictx[R]-dictx[str(int(R)-D)]) + abs(dicty[R]-dicty[str(int(R)-D)])
        cost[R] = costs + cost[str(int(R)-D)]
        return cost[R]

for n in range(1,H*W+1):
    calcost(str(n))
Q = int(input())
for j in range(Q):
    tmp = input().split()
    print(str(cost[tmp[1]]-cost[tmp[0]]))
from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  N = int(input())
  B = [0]*N
  for i in range(N):
    a,b = input().split()
    a1,a2 = map(int,a.split(':'))
    b1,b2 = map(int,b.split(':'))
    a = a1*60+a2
    b = b1*60+b2
    B[i] = [a,b]
  A = [[0]*N for _ in range(N)]
  for i in range(N):
    for j in range(N):
      if B[i][0]>=B[j][1] and B[i][1]<=B[j][0]+1440:
        A[i][j] = 1
        A[j][i] = 1
  dp = [float('inf')]*(1<<N)
  dp[0] = 0
  for i in range(N):
    dp[1<<i] = 1
  for i in range(2,N+1):
    for com in combinations(range(N),i):
      S = 0
      for c in com:
        S += 1<<c
      last = com[-1]
      dp[S] = dp[S-(1<<last)]
      for c in com[:-1]:
        if A[last][c]==0:
          dp[S] = float('inf')
  for i in range(2,N+1):
    for com in combinations(range(N),i):
      S = sum([1<<c for c in com])
      T = (S-1)&S
      while T>0:
        dp[S] = min(dp[S],dp[T]+dp[S-T])
        T = (T-1)&S
  ans = dp[-1]
  return ans
print(solve())

### FIXED CODE ###

from itertools import groupby, accumulate, product, permutations, combinations
def solve():
  N = int(input())
  A = [list(map(int, input().split())) for _ in range(N)]
  dp = [0]*(1<<N)
  dp[0] = 0
  for i in range(2,N+1):
    for com in combinations(range(N),i):
      S = sum([1<<c for c in com])
      last = com[-1]
      dp[S] = dp[S-(1<<last)]
      for c in com:
        dp[S] += A[last][c]
  for i in range(2,N+1):
    for com in combinations(range(N),i):
      S = sum([1<<c for c in com])
      T = (S-1)&S
      while T>0:
        dp[S] = max(dp[S],dp[T]+dp[S-T])
        T = (T-1)&S
  ans = dp[-1]
  return ans
print(solve())
a = input()
b = input()

if (a % 2) == 0:
  print("Even")
elif(b % 2) == 0:
  print("Even")
else:
  print("Odd")

### FIXED CODE ###

a,b = (int(x) for x in input().split())

if (a % 2) == 0:
    print("Even")
elif (b % 2) == 0:
    print("Even")
else:
    print("Odd")
def main():
  n, k = map(int, input().split())

  plus = []
  minus = []

  for n in input().split():
    n = int(n)
    if n >= 0:
      plus.append(n)
    else:
      minus.append(n)

  mod = 10 ** 9 + 7

  if len(plus) == 0 and k % 2 == 1:
    minus.sort(reverse=True)
    ans = 1
    for i in range(k):
      ans *= minus[i]

    print(ans % mod)
    return


  plus.sort(reverse = True)
  minus.sort()

  pn = 0
  mn = 0

  while k > 0:
    if pn + 1 == len(plus):
      pn += 1
      mn += k - 1
      break

    if pn == len(plus):
      mn += k
      break

    if mn + 1 >= len(minus):
      pn += k
      break

    if plus[pn] * plus[pn + 1] >= minus[mn] * minus[mn + 1]:
      pn += 1
      k -= 1
    else:
      mn += 2
      k -= 2

  ans = 1
  for i in range(pn):
    ans = (ans * plus[i]) % mod

  for i in range(mn):
    ans = (ans * (-minus[i])) % mod

  print(ans % mod)


main()


### FIXED CODE ###


def main():
  n, k = map(int, input().split())

  mod = 10 ** 9 + 7

  if n == k:
    ans = 1
    for num in input().split():
      ans = (ans * int(num)) % mod

    print(ans % mod)
    return

  plus = []
  minus = []
  for num in input().split():
    num = int(num)
    if num >= 0:
      plus.append(num)
    else:
      minus.append(num)

  pn = len(plus)
  mn = len(minus)

  if pn == 0 and k % 2 == 1:
    minus.sort(reverse = True)
    ans = 1
    for i in range(k):
      ans = (-ans * minus[i]) % mod

    print((-ans) % mod)
    return


  plus.sort(reverse = True)
  minus.sort()

  pi = 0
  mi = 0

  while k > 0:
    if pi + 1 == pn:
      if k % 2 == 0:
        mi += k
      else:
        pi += 1
        mi += k - 1

      break

    if pi == pn:
      mi += k
      break

    if mi + 1 >= mn:
      pi += k
      break

    if k == 1 or plus[pi] * plus[pi + 1] >= minus[mi] * minus[mi + 1]:
      pi += 1
      k -= 1
    else:
      mi += 2
      k -= 2

  ans = 1
  for i in range(pi):
    ans = (ans * plus[i]) % mod

  for i in range(mi):
    ans = (-ans * minus[i]) % mod

  print(ans % mod)


main()
from collections import defaultdict

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

result=0

dic_a=defaultdict(int)
dic_b=defaultdict(int)

for i in range(n//2):
    dic_a[v[i*2]]+=1
    dic_b[v[i*2+1]]+=1


#それぞれの最大値を取得
max_a=max(dic_a.items(),key=lambda x:[1])
max_b=max(dic_b.items(),key=lambda x:[1])

if max_a[0] != max_b[0]:
    result=n-max_a[1]-max_b[1]

elif len(dic_a)==1 and len(dic_b)==1:
    result=n//2

elif len(dic_a)==1:
    dic_b.pop(max_b[0])
    max_b=max(dic_b.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

elif len(dic_b)==1:
    dic_a.pop(max_a[0])
    max_a=max(dic_a.items(),key=lambda x:[1])
    result=n-max_a[1]-max_b[1]

else:
    dic_a.pop(max_a[0])
    max_a2=max(dic_a.items(),key=lambda x:[1])

    dic_b.pop(max_b[0])
    max_b2=max(dic_b.items(),key=lambda x:[1])

    if max_a2>max_b2:
        result=n-max_a2-max_b
    else:
        result=n-max_a-max_b2

print(result)

### FIXED CODE ###

from collections import defaultdict

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

result=0

dic_a=defaultdict(int)
dic_b=defaultdict(int)

for i in range(n//2):
    dic_a[v[i*2]]+=1
    dic_b[v[i*2+1]]+=1


#それぞれの最大値を取得
max_a=max(dic_a.items(),key=lambda x:x[1])
max_b=max(dic_b.items(),key=lambda x:x[1])

if max_a[0] != max_b[0]:
    result=n-max_a[1]-max_b[1]

elif len(dic_a)==1 and len(dic_b)==1:
    result=n//2

else:
    dic_a.pop(max_a[0])
    max_a2=max(dic_a.items(),key=lambda x:x[1])

    dic_b.pop(max_b[0])
    max_b2=max(dic_b.items(),key=lambda x:x[1])

    result=min(n-max_a2[1]-max_b[1],n-max_a[1]-max_b2[1])

print(int(result))
import math

N = int(input())
A = list(map(int, input().split()))

if N == 2:
  print(max(A))
  exit()

G = math.gcd(A[0], A[1])
H = math.gcd(A[1], A[2])
I = math.gcd(A[2], A[0])

print(max(G, H, I))

### FIXED CODE ###


def gcd(a, b):
	while b > 0:
		a, b = b, a % b
	return a


N = int(input())
A = list(map(int, input().split()))

if N == 2:
  print(max(A))
else:

  L = [0 for j in range(N+1)]
  R = [0 for j in range(N+1)]
  
  for j in range(N):
    L[j+1] = gcd(L[j], A[j])
  for j in reversed(range(N)):
    R[j] = gcd(R[j+1], A[j])

    m = -1
  for j in range(N):
    m = max(m, gcd(L[j], R[j+1]))
  print(m)
S = input()
s=0
for i in len(S):
  c = S[i]
  s = i if c =="A" && s <> 0
  if c =="Z":
    print(S[s:i+1])
    break

### FIXED CODE ###

S = input()
L = len(S)
for i in range(L):
  c = S[i]
  if c == "A":
    s = i
    break
for i in range(L):
  c = S[-(i+1)]
  if c == "Z":
    e = L - (i+1)
    break
print(e-s+1)
n = int(input())
h = [int(i) for i in input().split()]

h2 = [0] + h[:]
can = True
for i in range(1, n-1):
    if h2[i] <= h2[i+1]:
        continue
    elif h2[i]-1 > 0 and h2[i]-1 <= h2[i+i] and h2[i-1] <= h2[i]:
        h2[i] -= 1
    else:
        can = False
        break

print('Yes') if can else print('No')


### FIXED CODE ###

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

h2 = h[:]
can = True
for i in range(n-2, -1, -1):
    if h2[i] <= h2[i+1]:
        continue
    elif h2[i] > 1:
        h2[i] -= 1
    if not h2[i] <= h2[i+1]:
        can = False
        break

print('Yes') if can else print('No')
S = input()

if S==hi or S==hihi or S==hihihi or S==hihihihi or S==hihihihihi:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

S = input()

if S=='hi' or S=='hihi' or S=='hihihi' or S=='hihihihi' or S=='hihihihihi':
    print('Yes')
else:
    print('No')
N, M = map(int, input().split())
Grap = {j+1:[] for j in range(N)}
memo = {j+1: 0 for j in range(N)} # 各頂点からの最長経路をメモ. -1で初期化.
done = {j+1: False for j in range(N)}
ans = 0

for _ in range(M):
  x, y = map(int, input().split())
  Grap[x].append(y)


def dp(v):# 頂点nから始まる最長経路を返す.
  if done[v]: 
    return memo[v]
  elif done[v] == True:
    answ = 0
    for to in Grap[v]:
      answ = max(answ, dp(to)+1)
    memo[v] = answ
    done[v] = True
    return answ

for n in range(1,N+1):
  ans = max(ans, dp(n))
print(ans)




### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
MEMO = [-1 for _ in range(N+1)]

for _ in range(M):
  x, y = map(int, input().split())
  G[x].append(y)


def dp_LP(v):# 頂点nから始まる最長経路を返す.
  if MEMO[v] != -1:
    return MEMO[v]
  else:
    ans = 0
    for i in G[v]:
      ans = max(ans, dp_LP(i)+1)
    MEMO[v] = ans

    return ans



answer = 0
for n in range(1,N+1):
  answer = max(answer, dp_LP(n))
print(answer)
input()
vs=list(map(int, input().split(" ")))
k = 0
for i in range(0, len(vs)-1):
	if vs[i] - vs[i+1] >= 2:
		k = 100
		break
	if vs[i] - vs[i+1] == 1:
		k += 1
		if k >= 2:
			break
	elif vs[i+1] - vs[i] >= 1:
		k = 0
if k > 1:
	print("No")
else:
	print("Yes")


### FIXED CODE ###

a, b, c = map(int, input().split(" "))
print(max(0, c - (a - b)))
d, g = map(int, input().split())
p = []
c = []
for i in range(d):
    a,b = map(int, input().split())
    p.append(a)
    c.append(b)

def recursive_min(score, pi):
    # 点数と（残っている）問題の数に対してminの問題数を返す
    min = float('inf')
    for i in range(d):
        if pi[i] > 1:
            next_pi = pi[:]
            next_pi[i] += -1
            next_score = score-(i+1)*100
        elif pi[i] == 1:
            next_pi = pi[:]
            next_pi[i] += -1
            next_score = score-c[i]-(i+1)*100
        else:
            continue

        if next_score<=0:
            return 1
        cand_min = 1+recursive_min(next_score, next_pi)
        if cand_min<min:
            min = cand_min
    return min

print(recursive_min(g, p))


### FIXED CODE ###

import numpy as np
d, g = map(int ,input().split())
points = [list(map(int,input().split())) for _ in range(d)]

def min_q(comp_flg, target_score): # comp_flag[i]=True以外の問題iについて、compポイントを無視してtarget_scoreを超えるには最低いくつの問題数が必要かを返す
    score = 0
    q_num = 0
    for i in range(d-1,-1,-1):
        if comp_flg[i]:
            continue
        if target_score>score+points[i][0]*(i+1)*100:
            score += points[i][0]*(i+1)*100
            q_num += points[i][0] 
        else:
            q_num += np.ceil((target_score-score)/(100*(i+1)))
            break
    return q_num


mn = float('inf')
for i in range(1<<d):
    complete_flg = [False]*d
    tmp_q_num = 0
    tmp_point = 0
    for j in range(d):
        if i&(2**j) != 0:
            tmp_point += points[j][0] * 100*(j+1) + points[j][1]
            complete_flg[j] = True
            tmp_q_num += points[j][0]
    if tmp_point < g:
        tmp_q_num += min_q(complete_flg, g-tmp_point)
    if mn>tmp_q_num:
        mn = tmp_q_num

print(int(mn))
N,M=map(int,input().split())
A=[0]*(N*1)

for _ in range(M):
  a,b=map(int,input())
  A[a]+=1
  A[b]+=1

for i in range(1,N+1):
  print(A[i])

### FIXED CODE ###

N,M=map(int,input().split())
A=[0]*(N+1)
 
for _ in range(M):
  a,b=map(int,input().split())
  A[a]+=1
  A[b]+=1
 
for i in range(1,N+1):
  print(A[i])
n,b,r=list(int,input().split())

m=n%(b+r)
l=n//(b+r)

if m<b:
    s=b
else:
    s=m

if m!=0:
    n_b=l*b+s
else:
    n_b=l*b

print(n_b)

### FIXED CODE ###

n,b,r=list(map(int,input().split()))

m=n%(b+r)
l=n//(b+r)
x=n-l*(b+r)

if x<b:
    s=m
else:
    s=b

if m==0:
    n_b=l*b
else:
    n_b=l*b+s
print(n_b)
n, y = map(int, input().split())

ans = "-1 -1 -1"

for n10000 in range(n+1):
    for n5000 in range(n - n10000 + 1):
        n1000 = n - n5000 - n10000
        money_total = n10000 * 10000 + n5000 * 5000 + n1000 * 1000
        if money_total == y:
            ans = f"{n10000} {n5000} {n1000}"

print(ans)


### FIXED CODE ###

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

for n10000 in range(n+1):
    for n5000 in range(n - n10000 + 1):
        n1000 = n - n5000 - n10000
        money_total = n10000 * 10000 + n5000 * 5000 + n1000 * 1000
        if money_total == y:
            print(n10000, n5000, n1000)
            exit()

print(-1, -1, -1)
N = int(input())
card = map(int,input().split(" "))

all = 0
for i in card:
    all += i

a = all
ab = all
for i in range(len(card),-1):
    b -= card[i]
    if abs(a - b) > ab:
        break
    a,ab = b,abs(a - b)
print(ab)

### FIXED CODE ###

N = int(input())
card = [int(i) for i in input().split(" ")]
 
all = 0
for i in card:
    all += i
 
a = card[0]
mab = abs(a - (all - a))
for i in range(1,len(card) - 1):
    a += card[i]
    if mab > abs(a - (all - a)):
    	mab = abs(a - (all - a))
print(mab)
#
# abc086 a
#
a, b = map(input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")

### FIXED CODE ###

#
# abc086 a
#
a, b = map(int, input().split())
if a*b % 2 == 0:
    print("Even")
else:
    print("Odd")
N,M=map(int,input().split())
s=[]
c=[]
ans=0
for i in range(M):
    x,y=map(int,input().split())
    s.append(x)
    c.append(y)
    
for i in range(M-1):
    for j in range(i+1,M):
        if s[i]==s[j] and c[i]!=c[j]:
            print(-1)
            exit()

for i in range(M):
    if N<s[i]:
        print(-1)
        exit()

for i in range(M):
    if s[i]==1 and c[i]==0 and N>1:
        print(-1)
        exit()

for i in range(M-1):
    for j in range(i+1,M):
        if s[i]==s[j] and c[i]==c[j]:
            s[j]=0
            c[j]=0
if N==1:
    print(c[0])
    exit()
if N==2:
    ans=10
    for i in range(M):
        if s[i]==1:
            ans=0
    for i in range(M):
        if s[i]==1:
            ans+=10*c[i]
        if s[i]==2:
            ans+=c[i]
    print(ans)
    exit()
if N==3:
    ans=100
    for i in range(M):
        if s[i]==1:
            ans=0
    for i in range(M):
        if s[i]==1:
            ans+=100*c[i]
        if s[i]==2:
            ans+=10*c[i]
        if s[i]==3:
            ans+=c[i]
    print(ans)

### FIXED CODE ###

#なんもわからんくなった
N,M=map(int,input().split())
s=[]
c=[]
ans=0
#入力
for i in range(M):
    x,y=map(int,input().split())
    s.append(x)
    c.append(y)

if M==0:
    if N==1:
        print(0)
        exit()
    elif N==2:
        print(10)
        exit()
    else:
        print(100)
        exit()
#同じ桁だけど数が違う場合
for i in range(M-1):
    for j in range(i+1,M):
        if s[i]==s[j] and c[i]!=c[j]:
            print(-1)
            exit()

#1桁目が0なのにNが2桁以上の時
for i in range(M):
    if s[i]==1 and c[i]==0 and N>1:
        print(-1)
        exit()

#処理の重複を消してる
for i in range(M-1):
    for j in range(i+1,M):
        if s[i]==s[j] and c[i]==c[j]:
            s[j]=0
            c[j]=0

#各桁ごとの最小値
if N==1:
    print(c[0])
    exit()
if N==2:
    ans=10
    for i in range(M):
        if s[i]==1:
            ans=0
    for i in range(M):
        if s[i]==1:
            ans+=10*c[i]
        if s[i]==2:
            ans+=c[i]
    print(ans)
    exit()
if N==3:
    ans=100
    for i in range(M):
        if s[i]==1:
            ans=0
    for i in range(M):
        if s[i]==1:
            ans+=100*c[i]
        if s[i]==2:
            ans+=10*c[i]
        if s[i]==3:
            ans+=c[i]
    print(ans)
n, w = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
minw = min(wv)[0]
l = [0] * (n + 1)
for i in range(n + 1):
    l[i] = [0] * (w - minw + 1)
for i in range(1, n + 1):
    for j in range(w - minw + 1):
        if wv[i - 1][0] <= j + minw:
            if j - wv[i - 1][0] >= 0:
                l[i][j] = max(l[i - 1][j], l[i - 1][j - wv[i - 1][0]] + wv[i - 1][1])
            else:
                l[i][j] = max(l[i - 1][j], wv[i - 1][1])
        else:
            l[i][j] = l[i - 1][j]
print(l[n][w - minw])

### FIXED CODE ###

n, w = map(int, input().split())
l1 = [list(map(int, input().split())) for i in range(n)]
v = 0
for i in range(n):
  v += l1[i][1]
d = [10 ** 9 + 1] * (v + 1)
d[0] = 0
for i in range(n):
    for j in range(v, -1, -1):
        d[j] = min(d[j], d[j - l1[i][1]] + l1[i][0])
answer = 0
for j in range(v + 1):
    if  w >= d[j]:
        answer = max(answer, j)
print(answer)
R, G, B, N = map(int, input().split())
cnt = 0
 
for i in range(N // R + 1):
    for j in range(N // G + 1):
        q, mod = divmod((N - R * i - G * j), B)
        if q >= 0 and mod == 0:
            cnt += 1
print(cnt)

### FIXED CODE ###

n, k = map(int, input().split())
print(n-k+1)
n,k = map(int,input().split())

ab= []
ans = 0
for i in range(n):
    ab = list(map(int,input().split()))
    ab.append(count)
ab.sort()

while ans < k:
    ans +=ab[i][1]
    i +=1
print(ab[i-1][0])

### FIXED CODE ###

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

count= []
ans = 0
for i in range(n):
    ab = list(map(int,input().split()))
    count.append(ab)
count.sort()
i = 0
while ans < k:
    ans +=count[i][1]
    i +=1
print(count[i-1][0])
from math import gcd

# = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
mA = max(A)
counter = [0 for _ in range(mA+1)]

primenum = [2]
sgn = [-1 for _ in range(int(mA**0.5)+1)]
k = 3
while k**2 <= mA:
  if sgn[k] == -1:
    primenum.append(k)
    add = k*k
    ok = k
    while ok**2 <= mA:
      sgn[ok] = 1
      ok += add
  k += 2
#prime_num が用意されているとき
def factorization(n):
  M = n
  for p in primenum:
    if p**2 > M:
      break
    else:
      if M%p == 0:
        if counter[p] == 0:
          counter[p] = 1
        else:
          return False
        while M%p == 0:
          M //= p

  if M > 1:
    if counter[M] == 0:
      counter[M] = 1
    else:
      return False
  return True



g = A[0]
flag = True
for k in range(N):
  a = A[k]
  g = gcd(g, a)
  if flag:
    flag = factorization(a)


if flag:
  print('pairwise coprime')
  exit()
if g == 1:
  print('setwise coprime')
else:
  print('not coprime')


### FIXED CODE ###

import sys
sys.setrecursionlimit(2*10**9)

N, M = map(int, input().split())
friends = [[] for _ in range(N)]
for k in range(M):
  A, B = map(int, input().split())
  A -= 1
  B -= 1
  friends[A].append(B)
  friends[B].append(A)
group = []
sgn = [0 for _ in range(N)] #0なら未所属
def make_group(person, groupnum):
  sgn[person] = 1
  for f in friends[person]:
    if sgn[f] == 0:
      group[groupnum].append(f)
      make_group(f, groupnum)
  return None

c = 0
for k in range(N):
  if sgn[k] == 0:
    group.append([k])
    make_group(k, c)
    c += 1
ans = 0
for g in group:
  ans = max(len(g), ans)
print(ans)
input int=a, int=b
int puls = a + b
int m = a - b
int x = a * b
print(max(plus,m,x))

### FIXED CODE ###

a, b= map (int, input().split())
plus = a + b
m = a - b
x = a * b
print(max(plus,m,x))
W, H, r, x, y = list(map(int,  input().split()))
print('Yes' if 0 <= x - r <= x + r = W and 0 <= y - r <= y + r = H else 'No')

### FIXED CODE ###

W, H, x, y, r = list(map(int, input().split()))
print('Yes' if 0 <= x - r <= x + r <= W and 0 <= y - r <= y + r <= H else 'No')
import math


def main():
    n = int(input())
    a = []
    for i in range(1, (int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            a.append((n // i) - 1)
    a.sort()
    ans = 0
    if len(a) == 0:
        ans = 0
    else:
        for i in a:
            if i != 1 and (n // i == n % i):
                ans += i
    print(ans)


main()


### FIXED CODE ###

import math


def main():
    n = int(input())
    a = []
    for i in range(1, (int)(math.sqrt(n)) + 1):
        if n % i == 0:
            if i != 1:
                a.append(i - 1)
            if n // i - 1 != 0:
                a.append((n // i) - 1)
    ans = 0
    for i in range(len(a)):
        if a[i] != 1 and (n // a[i] == n % a[i]):
            ans += a[i]
    print(ans)


main()
N = int(input())
A = list(map(int, input().split()))
max_gcd = 1

import math

for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            if math.gcd(A[i], A[j]) > max_gcd:
                max_gcd = math.gcd(A[i], A[j])

print(max_gcd)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
 
L = [0]*(N+2)
R = [0]*(N+2)
 
import fractions
 
for i in range(1,N+1):
    L[i] = fractions.gcd(L[i-1],A[i-1])
for i in range(0,N)[::-1]:
    R[i] = fractions.gcd(R[i+1],A[i])
 
M = [fractions.gcd(L[i-1],R[i]) for i in range(1,N+1)]
print(max(M))
r = input()
print(r*2*3.14)

### FIXED CODE ###

r = input()
print(int(r) * 2 * 3.14)
a,b,c,d=int(input()).split()
print(max(abs(a),abs(b))*max(abs(c),abs(d)))

### FIXED CODE ###

a,b,c,d=map(int,input().split())
print(max(a*c,a*d,b*c,b*d))
s=input()
q=int(input())
cnt1=0
s_mae=[]
s_ushiro=[]
for i in range(q):
    query=list(input().split())
    if int(query[0])==1:
        cnt1+=1
    else:
        if (int(query[1])+cnt1)%2==0:
            s_ushiro.append(query[2]])
        else:
            s_mae=[query[2]]+s_mae
ans="".join(s_mae)+s+"".join(s_ushiro)
if cnt1%2==0:
    print(ans)
else:
    ans2=""
    for i in range(len(ans)):
        ans2=ans2+ans[-1-i]
        print(ans2)

### FIXED CODE ###

s=input()
q=int(input())
cnt1=0
s_mae=[]
s_ushiro=[]
for i in range(q):
    query=list(input().split())
    if int(query[0])==1:
        cnt1+=1
    else:
        if (int(query[1])+cnt1)%2==0:
            s_ushiro.append(query[2])
        else:
            s_mae.append(query[2])
s1=""
for i in range(len(s_mae)):
    s1=s1+s_mae[-1-i]
s2="".join(s_ushiro)
ans=s1+s+s2
if cnt1%2==0:
    print(ans)
else:
    ans2=""
    for i in range(len(ans)):
        ans2=ans2+ans[-1-i]
    print(ans2)