Harryxun/stf_run huggingface dataset:
n,m=map(int,input().split())
# Union-Find
a=list(range(n))
def find(x):
  if a[x]==x:
    return x
  a[x] = find(a[x])
  return a[x]

for _ in range(m):
  x,y=map(lambda x:find(int(x)-1),input().split())
  if x != y: a[x] = y

count=[0]*n
for i in range(n):
  count[find(i)] += 1
print(max(count))


### FIXED CODE ###

n,m=map(int,input().split())
# Union-Find
a=list(range(n))
def find(x):
  g = x
  while g != a[g]: g = a[g]
  a[x] = g
  return g

for _ in range(m):
  x,y=map(int,input().split())
  x,y=find(x-1),find(y-1)
  if x == y: continue
  a[y]=x

count=[0]*n
for i in range(n):
  count[find(i)] += 1
print(max(count))
s=input()
if s.count("o")<:7
    print("NO")
else:
    print("YES")


### FIXED CODE ###

s=input()
if s.count("o")<8-(15-len(s)):
    print("NO")
else:
    print("YES")
import numpy as np
import sys

def fib(n):
    if (n == 0):
        return 1
    elif (n == 1):
        return 1
    else :
        return fib(n - 1) + fib(n - 2)

if __name__ == "__main__":
    n = input("input number: ")
    n = int(n)
    #print(type(n))
    print(fib(n))



### FIXED CODE ###


f = [-1 for i in range(45)]
f[0] = f[1] = 1

def fib(n):
    global f
    for i in range(2,n+1):
        f[i] = f[i - 1] + f[i - 2]
        #print(i,f[i])
    return f[n]

if __name__ == "__main__":
    n = input()
    n = int(n)
    #print(type(n))
    print(fib(n))
def resolve():
    def f(x):
        res = (A*x)//B - A*(x//B)
        return res

    A, B, N = map(int, input().split())
    x = min(B-1, N)
    print(f(x))

if __name__ == "__main__":
    resolve():

### FIXED CODE ###


def resolve():
    def f(x):
        res = (A*x)//B - A*(x//B)
        return res

    A, B, N = map(int, input().split())
    x = min(B-1, N)
    print(f(x))

if __name__ == "__main__":
    resolve()
n, m = map(int, input().split())
if n == 1:
    _, c = map(int, input().split())
    print(c)
else:
    digits = [None for _ in range(n)]
    failflag = False
    for _ in range(m):
        s, c = map(int, input().split())
        s = s - 1
        if digits[s] is None or digits[s] == c:
            digits[s] = c
        else:
            failflag = True
            break
    if digits[0] == 0:
        failflag = True
    elif digits[0] is None:
        digits[0] = 1
    if failflag:
        print(-1)
    else:
        print(''.join(str(0) if digit is None else str(digit) for digit in digits))

### FIXED CODE ###

n, m = map(int, input().split())
if n == 1:
    digits = [None for _ in range(n)]
    failflag = False
    for _ in range(m):
        s, c = map(int, input().split())
        s = s - 1
        if digits[s] is None or digits[s] == c:
            digits[s] = c
        else:
            failflag = True
            break
    if failflag:
        print(-1)
    else:
        print(''.join(str(0) if digit is None else str(digit) for digit in digits))
else:
    digits = [None for _ in range(n)]
    failflag = False
    for _ in range(m):
        s, c = map(int, input().split())
        s = s - 1
        if digits[s] is None or digits[s] == c:
            digits[s] = c
        else:
            failflag = True
            break
    if digits[0] == 0:
        failflag = True
    elif digits[0] is None:
        digits[0] = 1
    if failflag:
        print(-1)
    else:
        print(''.join(str(0) if digit is None else str(digit) for digit in digits))
n = int(input())
b = list(map(int, input().split()))
b = b[::-1]
a = []
cont0 = False
a.append(b[0])
if len(b) == 1:
	print(2*b[0])
	quit() 
if b[0] > b[1]:
	a.append(b[1])
	a.append(b[1])
elif b[0] == b[1]:
	a.append(b[0])
	a.append(b[0])
elif b[0] < b[1]:
	a.append(b[0])
	a.append(b[1])
if len(b) == 2:
	print(sum(a))
	quit()
for i in range(2,n-1):
	if not cont0
		if b[i-2] > b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = b[i]
				a.append(b[i])
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
		elif b[i-2] == b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = b[i]
				a.append(b[i])
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
		elif b[i-2] < b[i-1]:
			if b[i-1] > b[i]:
				a[-1] = 0
				a.append(0)
				cont0 = True
			elif b[i-1] == b[i]:
				a.append(b[i])
			else:
				a.append(b[i])
	else:
		if b[i-1] < b[i]:
			a.append(b[i])
		else:
			a.append(0)
		cont0 = False

print(sum(a))



### FIXED CODE ###

n = int(input())
b = list(map(int, input().split()))
c = []
c.append(b[0])
for i in range(1,n-1):
	c.append(min(b[i-1], b[i]))
c.append(b[-1])
print(sum(c))
n,m=map(int,input().split())
a=[]
b=[0]*(n+1)
b[0]=1
MOD=(10**9)+7

a.append(int(input()) for i in range(m))
  
if 1 not in a:
  b[1]=1
else:
  b[1]=0
  
for j in range(2,n+1):
  if j in a:
    continue
  else:
    b[j]=(b[j-1]+b[j-2])%MOD
    
print(b[n]%MOD)    
    
  
  
  



### FIXED CODE ###

p,q,r=map(int,input().split())
a=p+q
b=p+r
c=q+r
print(min(a,b,c))
def main():
    n = int(input())

    nums = []
    for i in range(n):
        nums.append(int(input()))

    r = max(nums[1:]) - nums[0]

    for i in range(1, n-1):
        ri = nums[i]

        if ri == rj:
            rj = max(nums[i+1:])

        r = max(r, rj-ri)

    print(r)

if __name__ == '__main__':
    main()

### FIXED CODE ###

def main():
    n = int(input())

    r  = 0
    ri = 0

    for i in range(n):
        m = int(input())

        if 0 == i:
            ri = m
            continue

        if 1 == i:
            r = m - ri

        r  = max(r, m - ri)
        ri = min(ri, m)

    print(r)

if __name__ == '__main__':
    main()
from itertools import accumulate
N,Q = list(map(int,input().split()))
S = list(input())
cnt = [0]*(N-1)
for i in range(N):
    if S[i] == 'A' and S[i+1] == 'C':
        cnt[i] = 1
R = [0]+list(accumulate(cnt))
print(R)
for k in range(Q):
    x,y = list(map(int,input().split()))
    print(R[y-1]-R[x-1])

### FIXED CODE ###

from itertools import accumulate
N,Q = list(map(int,input().split()))
S = list(input())
cnt = [0]*(N)
for i in range(N-1):
    if S[i] == 'A' and S[i+1] == 'C':
        cnt[i] = 1
R = [0]+list(accumulate(cnt))
for k in range(Q):
    x,y = list(map(int,input().split()))
    print(R[y-1]-R[x-1])
import math

n = int(input())
a = [int(x) for x in input().split()]

l = 0
r = sum(a)

d = math.inf

for i in range(n - 1):
    l += a[i]
    r -= a[i]
    d = min(d, abs(l - r))

print(d)


### FIXED CODE ###

n = int(input())
a = [int(x) for x in input().split()]

left = 0
right = sum(a)

diff = []

for i in range(n - 1):
    left += a[i]
    right -= a[i]
    diff.append(abs(left - right))

print(min(diff))
import math
a = input()
print('{} {}'.format(math.pi*a*2, math.pi*a*a))


### FIXED CODE ###

import math
a = float(input())
pi = 3.1415926535897
print('{} {}'.format(pi*a*a, pi*a*2))
h1, m1, h2, m2, k = int(input().split(' '))

awake_time = (h2 - h1) * 60 + (m2 - m1)
y = awake_time - k

print(y)

### FIXED CODE ###

h1, m1, h2, m2, k = list(map(int, input().split(' ')))

awake_time = (h2 - h1) * 60 + (m2 - m1)
y = awake_time - k

print(y)
S = list(input())

L = []

for i, ch in enumerate(S):
    if ch != 'B':
        L.append(ch)
    elif len(L) > 0:
        del L[i - 1]

R = ''.join(L)
print(R)


### FIXED CODE ###

S = list(input())

L = []

for i, ch in enumerate(S):
    if ch != 'B':
        L.append(ch)
    elif len(L) > 0:
        L = L[:-1]

print(''.join(L))
def bfs(n,e,fordfs):
    #点の数、スタートの点、有向グラフ
    W = [-1]*n
    #各点の状態量、最短距離とか,見たかどうかとか
    W[e] = 0
    que = deque()
    que.append(e)
    len = [float("inf")]*n
    len[e] = 0
    while que:
        now = que.popleft()
        nowv = W[now]
        nowlen = len[now]
        for ne in fordfs[now]:
            if nowv == W[ne]:
                #ループが嫌な時
                return -1
            elif W[ne] == -1:
                W[ne] = (nowv+1) % 2
                len[ne] = nowlen+1
                que.append(ne)
    return len


def examB():
    N = I()
    v = [[]for _ in range(N)]
    for i in range(N):
        a = I()
        v[i].append(a-1)
    v[1]=[]
    b = bfs(N,0,v)
    ans = b[1]
    if ans==float("inf"):
        ans = -1
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()


### FIXED CODE ###

def bfs(n,e,fordfs):
    #点の数、スタートの点、有向グラフ
    W = [-1]*n
    #各点の状態量、最短距離とか,見たかどうかとか
    W[e] = 0
    que = deque()
    que.append(e)
    len = [float("inf")]*n
    len[e] = 0
    while que:
        now = que.popleft()
        nowv = W[now]
        nowlen = len[now]
        for ne in fordfs[now]:
            if nowv == W[ne]:
                #ループが嫌な時
                return -1
            elif W[ne] == -1:
                W[ne] = (nowv+1) % 2
                len[ne] = nowlen+1
                que.append(ne)
    return len


def examB():
    N = I()
    v = [[]for _ in range(N)]
    for i in range(N):
        a = I()
        v[i].append(a-1)
    v[1]=[]
    b = bfs(N,0,v)
    if b==-1:
        ans = -1
    else:
        ans = b[1]
    if ans==float("inf"):
        ans = -1
    print(ans)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()
def main():
    import sys
    input=sys.stdin.readline
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        for e in G[i]:
            if visited[e]:
                visited[e]=False
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()

### FIXED CODE ###

def main():
    import sys
    input=sys.stdin.readline
    sys.setrecursionlimit(1000000000)
    n,m=map(int,input().split())
    G=[[] for _ in range(n)]
    for _ in range(m):
        x,y,z=map(int,input().split())
        x-=1
        y-=1
        G[x].append(y)
        G[y].append(x)
    
    visited=[True]*n
    def dfs(i):
        visited[i]=False
        for e in G[i]:
            if visited[e]:
                dfs(e)
    
    cnt=0
    for i in range(n):
        if visited[i]:
            cnt+=1
            dfs(i)
    
    print(cnt)  

if __name__=='__main__':
    main()
n = int(input())
restaurants_list = []
for _ in range(n):
  s, p = input().split()
  restaurants_list.append([s, p, _])
restaurants_list.sort()
for _ in range(n):
  print(restaurants_list[2])
  
  


### FIXED CODE ###

n = int(input())
restaurants_list = []
for _ in range(n):
  s, p = input().split()
  restaurants_list.append([s, -int(p), _+1])
restaurants_list.sort()
for _ in range(n):
  print(restaurants_list[_][2])
s=str(input())

lens=len(s)
ans=0
list=[]

for i in range(lens):
	if (s[i]=='A')|(s[i]=='T')|(s[i]=='C')|(s[i]=='G'):
		ans=ans+1
	else:
		list.append(ans)
		ans=0

#print(list)
print(max(list))

### FIXED CODE ###

s=str(input())

lens=len(s)
ans=0
list=[]

for i in range(lens):
	if (s[i]=='A')|(s[i]=='T')|(s[i]=='C')|(s[i]=='G'):
		ans=ans+1
	else:
		list.append(ans)
		ans=0
list.append(ans)
print(max(list))
import collections
import itertools
from operator import mul

n = int(input())
k = n
ans = n -1
prime = []

while k != 1:
    for i in range(2,int(k**0.5)+1):
        if k % i == 0:
            prime.append(i)
            k /= i
            break
    else:
        prime.append(int(k))
        k = 1

div = list(itertools.accumulate(prime,mul))

for i in div:
    ans = min(ans,i + n//i -2)

print(ans)

### FIXED CODE ###

import sys

n = int(input())

for i in range(int(n**0.5),0,-1):
    if n % i == 0:
        print(n//i + i - 2 )
        sys.exit()
N,M=map(int,input().split())
hen=[[] for i in range(0,N)]
for i in range(0,N):
    a,b=map(int,input().split())
    hen[a-1].append(b-1)
    hen[b-1].append(a-1)

def onestrokepath(start,visited=[]):
    flag=0
    count=0
    for next in hen[start]:
        if not next in visited:
            flag=1
            count+=onestrokepath(next,visited+[next])
    if flag==0:
        check=[i for i in range(0,N)]
        visited.sort()
        if check==visited:
            return 1
        else:
            return 0
    return count

print(onestrokepath(0,[0]))


### FIXED CODE ###

N,M=map(int,input().split())
hen=[[] for i in range(0,N)]
for i in range(0,M):
    a,b=map(int,input().split())
    hen[a-1].append(b-1)
    hen[b-1].append(a-1)

def onestrokepath(start,visited=[]):
    flag=0
    count=0
    for next in hen[start]:
        if not next in visited:
            flag=1
            count+=onestrokepath(next,visited+[next])
    if flag==0:
        check=[i for i in range(0,N)]
        visited.sort()
        if check==visited:
            return 1
        else:
            return 0
    return count

print(onestrokepath(0,[0]))
N, K=map(int, input().split())
A_list = list(map(int, input().split()))

flag = 0
for i in range(N):
    if A_list[i] >= 0:
        break
    if i == N-1:
        flag = 1

if flag == 1 and K % 2 ==1:
    A_list.sort(reverse = True)
    ans = 1
    for i in A_list[:K]:
        ans *= i
    print(ans % (10 ** 9 + 7))
else:
    A_list.sort(key=abs,reverse=True)
    ans = 1
    for i in A_list[:K]:
        ans *= i
    if ans >= 0:
        pass
    else:
        # (1)
        list_p = [x for x in A_list[K:] if x >= 0]
        list_n = [x for x in A_list[:K] if x < 0]

        ans1 = ans * list_p[0] / list_n[-1]
        # (2)
        list_p = [x for x in A_list[:K] if x >= 0]
        list_n = [x for x in A_list[K:] if x < 0]
        ans2 = ans * list_n[0] / list_p[-1]

        ans = max(ans1, ans2)
    print(ans % (10 ** 9 + 7))

### FIXED CODE ###

mod=10**9+7
n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr,reverse=True,key=lambda x:abs(x))
if k==n:
  ans=1
  for i in range(n):
    ans*=arr[i]
    ans%=mod
  print(ans)
else:
  if k%2==1 and max(arr)<0:
    ans=1
    for i in range(k):
      ans*=arr[n-1-i]
      ans%=mod
    print(ans)
  else:
    ans=1
    cnt=0
    for i in range(k):
      if arr[i]<0:
        cnt+=1
      ans*=arr[i]
      ans%=mod
    if cnt%2==0:
      print(ans)
    else:
      min_plus=-1
      min_minus=1
      for i in range(k):
        if arr[i]>=0:
          min_plus=arr[i]
        else:
          min_minus=arr[i]
      max_plus=-1
      max_minus=1
      for i in range(k,n):
        if arr[i]>=0 and max_plus==-1:
          max_plus=arr[i]
        if arr[i]<0 and max_minus==1:
          max_minus=arr[i]
      if min_plus==-1:        
        arr.remove(min_minus)
        ans=1
        for i in range(k-1):
          ans*=arr[i]
          ans%=mod
        ans*=max_plus
        ans%=mod
      elif min_minus==1:        
        arr.remove(min_plus)
        ans=1
        for i in range(k-1):
          ans*=arr[i]
          ans%=mod
        ans*=max_minus
        ans%=mod
      elif min_plus*max_plus>=min_minus*max_minus:
        arr.remove(min_minus)
        ans=1
        for i in range(k-1):
          ans*=arr[i]
          ans%=mod
        ans*=max_plus
        ans%=mod
      else:
        arr.remove(min_plus)
        ans=1
        for i in range(k-1):
          ans*=arr[i]
          ans%=mod
        ans*=max_minus
        ans%=mod
      print(ans)
n, m = map(int, input().split())
s = list(input())
out = [set() for _ in range(n)]
count = [[0, 0] for _ in range(n)]
def f(c):
    if c == 'A': return 0
    else: return 1
for _ in range(m):
    a, b = map(int, input().split())
    if a == b:
        count[a-1][f(s[a-1])] += 1
    elif b-1 not in out[a-1]:
        count[a-1][f(s[b-1])] += 1
        count[b-1][f(s[a-1])] += 1
    out[a-1].add(b-1)
    out[b-1].add(a-1)
elim = set()
def eliminate(x):
    elim.add(x)
    c = f(s[x])
    for node in out[x]:
        if node not in elim:
            count[node][c] -= 1
            if count[node][0] * count[node][1] == 0:
                eliminate(node)
for i in range(n):
    if i not in elim and count[i][0] * count[i][1] == 0:
        eliminate(i)
if len(elim) < n: print('Yes')
else: print('No')

### FIXED CODE ###

import sys
sys.setrecursionlimit(200000)
n, m = map(int, input().split())
s = input()
out = [set() for _ in range(n)]
count = [[0, 0] for _ in range(n)]
def f(c):
    if c == 'A': return 0
    else: return 1
for _ in range(m):
    a, b = map(int, input().split())
    if a == b:
        count[a-1][f(s[a-1])] += 1
    elif b-1 not in out[a-1]:
        count[a-1][f(s[b-1])] += 1
        count[b-1][f(s[a-1])] += 1
    out[a-1].add(b-1)
    out[b-1].add(a-1)
elim = set()
def eliminate(x):
    elim.add(x)
    c = f(s[x])
    for node in out[x]:
        if node not in elim:
            count[node][c] -= 1
            if count[node][0] * count[node][1] == 0:
                eliminate(node)
for i in range(n):
    if i not in elim and count[i][0] * count[i][1] == 0:
        eliminate(i)
if len(elim) < n: print('Yes')
else: print('No')
N = int(input())
a = [int(i) for i in input().split()]
a = a.sort(reverse=True)

ans = sum(a[2*i] for i in range(1,N+1))
print(ans)

### FIXED CODE ###

N = int(input())
a = [int(i) for i in input().split()]
a.sort(reverse=True)

ans = sum(a[2*i-1] for i in range(1,N+1))
print(ans)
x = int(input())
for i in range(-102,103):
    for j in range(-102,103):
        if (i**5)-(j**5)==x:
            print(i,j)
            exit()


### FIXED CODE ###

s=input()
print('ABC' if s=='ARC' else 'ARC')
import itertools
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
k = [(1+i)/2 for i in p]
a = list(itertools.accumulate(k))
max = a[2]
for i in range(3,N):
    if max < a[i] - a[i-3]:
        max = a[i] - a[i-3]
print(max)

### FIXED CODE ###

import itertools
N,K = list(map(int,input().split()))
p = list(map(int,input().split()))
k = [(1+i)/2 for i in p]
a = list(itertools.accumulate(k))
max = a[K-1]
for i in range(K,N):
    if max < a[i] - a[i-K]:
        max = a[i] - a[i-K]
print(max)
n = int(input())
xyh_list = [list(map(int, input().split())) for _ in range(n)]
list_1_100 = [i for i in range(0, 101)]
possible_list = []

x1 = xyh_list[0][0]
y1 = xyh_list[0][1]
h1 = xyh_list[0][2]
x2 = xyh_list[1][0]
y2 = xyh_list[1][1]
h2 = xyh_list[1][2]
for i in list_1_100:
    for j in list_1_100:
        if (h2 + abs(x2 - i) + abs(y2 - j)) == (h1 + abs(x1 - i) + abs(y1 - j)):
            possible_list.append([i, j])   # cx, cy 候補
pos_list = []
for i in range(2, n):
    if len(possible_list) == 1:
        break
    x = xyh_list[i][0]
    y = xyh_list[i][1]
    h = xyh_list[i][2]
    for j in range(len(possible_list)):  
        x_ = possible_list[j][0]
        y_ = possible_list[j][1]
        if (h + abs(x - x_) + abs(y - y_)) == (h2 + abs(x2 - x_) + abs(y2 - y_)):
            pos_list.append([x_, y_])
    possible_list = pos_list
    pos_list = []

print(possible_list[0][0], possible_list[0][1], h2 + abs(x2 - possible_list[0][0]) + abs(y2 - possible_list[0][1]))


### FIXED CODE ###

n = int(input())
xyh_list = [list(map(int, input().split())) for _ in range(n)]
list_0_100 = [i for i in range(0, 101)]
possible_list = []
for a in range(len(xyh_list)):
    if xyh_list[a][2] != 0:
        x1 = xyh_list[a][0]
        y1 = xyh_list[a][1]
        h1 = xyh_list[a][2]
        break

for cx in list_0_100:
    for cy in list_0_100:
        H = h1 + abs(x1 - cx) + abs(y1 - cy)
        count = 0
        for i in range(n):
            x = xyh_list[i][0]
            y = xyh_list[i][1]
            h = xyh_list[i][2]
            if h == max(H - abs(x - cx) - abs(y - cy), 0):
                count += 1
        if count == n:
            ansx = cx
            ansy = cy
            ansH = H
print(ansx, ansy, ansH)
n,m=map(int,input().split())
a=[]
b=[]

cnt=0
k=0
flag=0
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

for j in range(n-m+1):
    k=0
    for i in range(n-m+1):
        if b[k]==a[i][j:j+m]:
            k+=1
            if k==m:
                print("Yes")
                flag+=1

if flag==0:
    print("No")



### FIXED CODE ###

n,m=map(int,input().split())
a=[]
b=[]

cnt=0
k=0
flag=0
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

for j in range(n-m+1):
    k=0
    for i in range(n-m+1):
        if b[k]==a[i][j:j+m]:
            k+=1
            if k==m:
                print("Yes")
                flag+=1
                break
    else:
        continue
    break


if flag==0:
    print("No")
if __name__ = "__main__":
  S = input() # sを取得し、strに値を入れる
  if S == "ABC":
    print("ARC")
  elif S == "ARC":
    print("ABC")
  

### FIXED CODE ###

if __name__ == "__main__":
  S = input() # sを取得し、strに値を入れる
  if S == "ABC":
    print("ARC")
  elif S == "ARC":
    print("ABC")
s=input()
print(700+100*s.count(o))

### FIXED CODE ###

s=input()
print(700+100*s.count('o'))
x,y,z=map(int(input().split()))
ans=1
x-=(y+2*z)
print(ans+x//(y+z))

### FIXED CODE ###

x,y,z=map(int,(input().split()))
ans=1
x-=(y+2*z)
print(ans+x//(y+z))
n,*a=map(int,open(0).read().split())
a.sort()
p,z,m=[],[],[]
for i in a:
    if i<0:m+=[i]
    elif i>0:p+=[i]
    else:z+=[i]
if p and m:
    p=z+p
    for i in p[:-1]:
        # print(m[0],i)
        m[0]-=i
    for i in m:
        # print(p[-1],i)
        p[-1]-=i
    print(p[-1])    
elif p:
    p=z+p
    for i in p[:-2]:
        # print(p[0],i)
        p[0]-=i
    print(p[-2]-p[0])    
elif m:
    m=m+z
    for i in p[:-1]:
        # print(p[-1],i)
        p[-1]-=i
    print(p[-1])    
if p and m:
    p=z+p
    for i in p[:-1]:
        print(m[0],i)
        m[0]-=i
    for i in m:
        print(p[-1],i)
        p[-1]-=i
elif p:
    p=z+p
    for i in p[:-2]:
        print(p[0],i)
        p[0]-=i
    print(p[-2],p[0])    
elif m:
    m=m+z
    for i in p[:-1]:
        print(p[-1],i)
        p[-1]-=i

### FIXED CODE ###

n,*a=map(int,open(0).read().split())
a.sort()
print(sum(abs(i)for i in a)-2*min(abs(a[-1]),abs(a[0]))*(a[0]*a[-1]>0))
if a[0]>0:
    print(a[0],a[-1])
    a[0]-=a[-1]
    for i in a[1:-2]:
        print(a[0],i)
        a[0]-=i
    print(a[-2],a[0])
elif a[-1]<0:
    for i in a[:-1]:
        print(a[-1],i)
        a[-1]-=i
else:
    for i in a[1:-1]:
        if i<0:
            print(a[-1],i)
            a[-1]-=i
        else:
            print(a[0],i)
            a[0]-=i
    print(a[-1],a[0])
num=1000000
prime=[1]*1000000
i=2
ans=0
while i<1000000:
 if prime[i]==1:
  ans+=1
 if i<1000:
  j=i*i
  while j<1000000:
   prime[j]=0
   j+=i
 prime[i]=ans
 i+=1
while True:
 n=input()
 print prime[n]

### FIXED CODE ###

num=1000000
prime=[1]*1000000
prime[0]=0
prime[1]=0
i=2
ans=0
while i<1000000:
 if prime[i]==1:
  ans+=1
 if i<1000:
  j=i*i
  while j<1000000:
   prime[j]=0
   j+=i
 prime[i]=ans
 i+=1
while True:
 try:
  n=input()
  print prime[n]
 except:
  break