Harryxun/stf_run huggingface dataset:
import sys
import copy
from collections import deque
import collections
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m, k = na()

a = na()
b = na()

num_books = 0
sum_time = 0
for i in a:
    if sum_time+i > k:
        break
    num_books += 1
    sum_time += i
# print(num_books)


res = num_books
ia = num_books - 1
ib = 0
if num_books==0 and b[ib] > k:
    print(0)
    exit(0)
while ib < len(b):
    if sum_time < k:
        sum_time += b[ib]
        ib += 1
        num_books += 1
    else:
        sum_time -= a[ia]
        ia -= 1
        num_books -= 1
    if sum_time <= k:
        res = max(res, num_books)

print(res)


### FIXED CODE ###

import sys
import copy
from collections import deque
import collections
stdin = sys.stdin

mod = 10**9+7

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n, m, k = na()

a = na()
b = na()

num_books = 0
sum_time = 0
for i in a:
    if sum_time+i > k:
        break
    num_books += 1
    sum_time += i
# print(num_books)


res = num_books
ia = num_books - 1
ib = 0
if num_books==0 and b[ib] > k:
    print(0)
    exit(0)
while ib < len(b):
    if sum_time < k:
        sum_time += b[ib]
        ib += 1
        num_books += 1
    else:
        if ia == -1:
            break
        sum_time -= a[ia]
        ia -= 1
        num_books -= 1
    if sum_time <= k:
        res = max(res, num_books)

print(res)
N, M = map(int, input().split())

like = list(map(int, input().split()))
all_like = set()
for l in like:
	all_like.add(l)
for i in range(N):
  like = list(map(int, input().split()))
  for l in like:
    if l not in all_like:
      all_like.remove(l);
print(len(all_like))

### FIXED CODE ###

import copy

N, M = map(int, input().split())

like = list(map(int, input().split()))
like.pop(0)
all_like = set()
for l in like:
	all_like.add(l)
    
for i in range(N-1):
  like = list(map(int, input().split()))
  like.pop(0)
  tmp = copy.deepcopy(all_like)
  for l in all_like:
    if l not in like:
      tmp.remove(l);
  all_like = tmp
print(len(all_like))
n = input()

if '7' in n:
  print('Yes')
else:
  ptint('No')

### FIXED CODE ###

a, b, c = input()

if a == '7' or b == '7' or c == '7':
  print('Yes')
else:
  print('No')
package main

import (
	"fmt"
)

func main(){
	var A, B int
	fmt.Scan(&A)
	fmt.Scan(&B)
	if A+B > 16 {
		panic("Exceeded pieces!")
	}
	if A > 8 || B > 8 {
		fmt.Println(":(")
	} else {
		fmt.Println("Yay!")
	}
}

### FIXED CODE ###

num = input()
a = int(num.split(' ')[0])
b = int(num.split(' ')[1])
x = int(num.split(' ')[2])


if a+b>=x:
    if a>x:
        print("NO")
    else:
        print("YES")
else:
    print("NO")
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    for i in range(N):
        tmp = As[:i] + As[i + 1 :]
        gI = gcd(tmp[0], tmp[1])
        tmp = tmp[2:]
        for t in tmp:
            gI = gcd(t, gI)
            if gI < memG:
                break
        if gI > memG:
            memG = gI
    print("{}".format(memG))


sub()


### FIXED CODE ###

from functools import lru_cache, reduce


@lru_cache(maxsize=None)
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    # As = sorted(As, reverse=True)

    memG = 0
    # if N == 2:
    # memG = gcd(As[0], As[1])
    if N < 10:
        for i in range(N):
            tmp = As[:i] + As[i + 1 :]
            g = reduce(gcd, tmp)
            if g > memG:
                memG = g
    else:
        gLeft = {0: As[0], 1: gcd(As[0], As[1])}
        for i in range(2, N):
            gI = gcd(gLeft[i - 1], As[i])
            gLeft[i] = gI
        gRight = {N - 1: As[N - 1], N - 2: gcd(As[N - 1], As[N - 2])}
        for i in range(2, N):
            gI = gcd(gRight[N - i], As[N - 1 - i])
            gRight[N - 1 - i] = gI

        buf = []
        for i in range(N):
            leftG = None
            if (i - 1) in gLeft:
                leftG = gLeft[i - 1]
            rightG = None
            if (i + 1) in gRight:
                rightG = gRight[i + 1]
            # tmpG = None
            if leftG is None:
                leftG = rightG
            elif rightG is None:
                rightG = leftG
            buf.append(gcd(leftG, rightG))
            # tmpG = gcd(leftG, rightG)
            # if tmpG > memG:
            #     memG = tmpG
        memG = max(buf)

    print("{}".format(memG))


sub()
#!/usr/bin/env python

import sys

def fill(i,now):
    global iro, d1, k
    nuttayo = []
    for v in d1[i]:
        if iro[v]==0:
            now-=1
            iro[v]= now
            nuttayo.append(v)
    #
    for v in nuttayo: fill(v,k-1)

n,k = [ int(x) for x in sys.stdin.readline().split() ]
d1 = [ [] for _ in range(n) ]
for _ in range(n-1):
    ai,bi = [ int(x)-1 for x in sys.stdin.readline().split() ]
    d1[ai].append( bi )
    d1[bi].append( ai )
#
iro = [ 0 ] * n
iro[0] = k
fill(0,k)
i= 1
for j in iro: i= ( i * j ) % 1000000007
print( i )    


### FIXED CODE ###

#!/usr/bin/env python

import sys

n,k = [ int(x) for x in sys.stdin.readline().split() ]
d1 = [ [] for _ in range(n) ]
for _ in range(n-1):
    ai,bi = [ int(x)-1 for x in sys.stdin.readline().split() ]
    d1[ai].append( bi )
    d1[bi].append( ai )
#
flag = [ True ] * n
flag[0] = False
total = k
now = k
nxt = [ d1[0] ]
while nxt:
    tmp= []
    for points in nxt:
        if now!=k: now= k-1
        for v in points:
            if not flag[v]: continue
            flag[v]= False
            tmp.append(v)
            now -= 1
            total= ( total * now ) % 1000000007
    #
    nxt= []
    for v in tmp:
        a= [ vv for vv in d1[v] if flag[vv] ]
        if a: nxt.append( a )
#
print( total )
n,k=map(int,input().split())
h=list(map(int,input().split()))

h.sort(reverse=True)
for i in range(k):
  h[i]=0
print(sum(h))

### FIXED CODE ###

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

h.sort(reverse=True)

if k>n:
  k=n

for i in range(k):
  h[i]=0

sum_=0
for hh in h:
  sum_+=hh
print(sum_)
a, b = [int(x)-1 for x in input().split()]
won = 0
if a in range(3):
  won  += [300000,200000,200000][a]
if b in range(3):
  won  += [300000,200000,200000][a]
won += 400000 * (a == 0 and b == 0)
print(won)

### FIXED CODE ###

a, b = [int(x) for x in input().split()]
won = 0
if a in range(1, 4):
  won  += [0,300000,200000,100000][a]
if b in range(1, 4):
  won  += [0,300000,200000,100000][b]
if a == 1 and b == 1:won += 400000  
 
print(won)
def f(e):
 a=list([*map(int,input().split())]for _ in range(int(e)))
 s,t=a[0]
 b={(*map(int,input().split()))for _ in range(int(input()))}
 for x,y in b:
  for u,v in a[1:]:
   if(x+u-s,y+v-t)not in b:break
  else:return print(x-s,y-t)
for e in iter(input,'0'):f(e)


### FIXED CODE ###

for e in iter(input,'0'):
 a=[[*map(int,input().split())]for _ in[0]*int(e)]
 s,t=min(a)
 b={tuple(map(int,input().split()))for _ in[0]*int(input())}
 m=max(b)[0]-max(a)[0]+s
 for x,y in b:
  if x<=m:
   for u,v in a:
    if(x+u-s,y+v-t)not in b:break
   else:print(x-s,y-t);break
N, K = list(map(int, input.split()))

if (K == 1):
    print("0")
else:
    print(N-K)

### FIXED CODE ###

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

if (K == 1):
    print("0")
else:
    print(N-K)
ant = [int(input()) for _ in range(5)]
k = int(input())

if ant[5] - ant[1] > k:
  print(':(')
else:
  print('Yay!')



### FIXED CODE ###

ant = [int(input()) for i in range(5)]
k = int(input())
d = []
for i in range(5):
    for j in range(5):
        d.append(ant[i] - ant[j])

if max(d) > k:
    ans = ':('
else:
    ans = 'Yay!'

print(ans)
from sys import stdin
readline = stdin.readline


def main():
    R, S, P = 1, 2, 3
    W, L, D = 1, 2, 3

    rps = {
        (R, S, P):{R:D, S:D, P:D},
        (R, S)   :{R:W, S:L},
        (S, P)   :{S:W, P:L},
        (R, P)   :{P:W, R:L}
    }

    while True:
        hand = int(readline())
        if hand == 0:
            break
        hands = [hand] + [int(readline()) for _ in range(4)]
        hand_set = tuple(sorted(set(hands)))
        for h in hands:
            print(rps[hand_set][h])
main()

### FIXED CODE ###

from sys import stdin
readline = stdin.readline


R, S, P = 1, 2, 3  # rock, scissors, paper
W, L, D = 1, 2, 3  # win, lose, draw

rps = {
    (R, S, P): {R: D, S: D, P: D},
    (R, S):    {R: W, S: L},
    (S, P):    {S: W, P: L},
    (R, P):    {P: W, R: L},
    (R,):       {R: D},
    (S,):       {S: D},
    (P,):       {P: D}
    }

while True:
    hands = []
    hands.append(int(readline()))
    if hands[0] == 0:
        break
    for _ in range(4):
        hands.append(int(readline()))

    hands_set = tuple(sorted(set(hands)))
    for h in hands:
        print(rps[hands_set][h])
inData = int(input())

seqData = list(range(1,inData+1,1))
outData = [0] * inData
for thisData in seqData:
    if thisData == inData:
        if thisData%3 == 0 or thisData%10==3:
            print(" "+str(thisData))
        else:
            for i in range(5):
                i=i+1
                over =  10 ** i
                tmp = thisData/over
                if int(tmp % 10) == 3:
                    print(" "+str(thisData))
                    break
                else:
                    pass:
    else:
        if thisData%3 == 0 or thisData%10==3:
            print(" "+str(thisData), end = "")
        else:
            for i in range(5):
                i=i+1
                over =  10 ** i
                tmp = thisData/over
                if int(tmp % 10) == 3:
                    print(" "+str(thisData), end = "")
                    break
                else:
                    pass


### FIXED CODE ###

inData = int(input())

seqData = list(range(1,inData+1,1))
outData = [0] * inData
for thisData in seqData:
    if thisData == inData:
        if thisData%3 == 0 or thisData%10==3:
            print(" "+str(thisData))
        else:
            for i in range(5):
                i=i+1
                over =  10 ** i
                tmp = thisData/over
                if int(tmp % 10) == 3:
                    print(" "+str(thisData))
                    break
                else:
                    pass
            print("")
    else:
        if thisData%3 == 0 or thisData%10==3:
            print(" "+str(thisData), end = "")
        else:
            for i in range(5):
                i=i+1
                over =  10 ** i
                tmp = thisData/over
                if int(tmp % 10) == 3:
                    print(" "+str(thisData), end = "")
                    break
                else:
                    pass
from math import *
from decimal import *
a,b,c=map(int,input().split())
if Decimal( a**2+ b**2+2*a+2*b+2*sqrt(a)*sqrt(b)))<Decimal(c**2):
    print("Yes")
else:
    print("No")

### FIXED CODE ###

from math import *
from decimal import *
a,b,c=map(int,input().split())
if 4*a*b<(c-a-b)**2 and c-a-b>0:
    print("Yes")
else:
    print("No")
N, M = map(int, input().split())
X = []
for i in range(N):
	X.append(list(map(int, input().split())))

#Sorted by first element
X.sort(key=lambda x:x[0])
i = 0
total = 0
ans = 0

while i <= N-1:
	total += X[i][1]
	ans += X[i][0] * X[i][1]
	if total > M:
		ans -= X[i][0] * (total-M)
		break
	i += 1
print(ans)

### FIXED CODE ###

H,W = map(int, input().split())
h,w = map(int, input().split())

total = H* W
ans = total - (H*w + W*h - h*w) 
print (ans)
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))

#S = input()
S = 'abcdefghijklmnopqrstuvwxyz'*200
K = ii()
N = len(S)
'''
N = len(S)
d = defaultdict(int)
for i in range(N+1):
    for j in range(N-i+1):
        d[S[j:j+i+1]] += 1
l = sorted(d.keys())
#print(l)
print(l[K])
'''

alphabets = list('abcdefghijklmnopqrstuvwxyz')

#print(len(alphabets))
l = []
for alpha in alphabets:
    for i, m in enumerate(S):
        if m == alpha:
            for j in range(1, N-i+1):
                l.append(S[i:i+j])

    l = sorted(set(l))
    if len(l) >= K:
        print(l[K-1])
        exit()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))

S = input()
K = ii()
N = len(S)


alphabets = list('abcdefghijklmnopqrstuvwxyz')
l = []

for alpha in alphabets:
    for i, m in enumerate(S):
        if m == alpha:
            flag = 1
            for j in range(1, min(K+1, N-i+1)):
                l.append(S[i:i+j])
    #print(set(l))
    l = sorted(set(l))
    if len(l) >= K:
        print(l[K-1])
        exit()
S = input()
ACGT = ['A', 'C', 'G', 'T']
count = 0
max_count = 0
for w in S:
    if w in ACGT:
        count += 1
    else:
        if count > max_count:
            max_count += count
print(max_count

### FIXED CODE ###

S = input()
ACGT = ['A', 'C', 'G', 'T']
count = 0
max_count = 0
for w in S:
    if w in ACGT:
        count += 1
    if count > max_count:
        max_count = count
    if w not in ACGT:
        count = 0
print(max_count)
H, W = map(int, input().split())
picture = [input() for i in range(H)]
print('#'*(W+2))
for i in range(H):
    print('#' + picture[i] + '#')
print('#'*(W+2))
#コピペです。


### FIXED CODE ###

x,y=map(int,input().split())
A=[1,3,5,7,8,10,12]
B=[4,6,9,11]
C=[2]
if x in A:
    if y in A:
        print("Yes")
    else:
        print("No")
elif x in B:
    if y in B:
        print("Yes")
    else:
        print("No")
else:
    print("No")
h,w=map(int,input().split())
num=0
s=[str(input()) for i in range(h):]
for i in range(h):
  num+=s[i].count("#")
if num>h+w-1:
  print("Impossible")
  exit()
print("Possible")

### FIXED CODE ###

h,w = map(int,input().split())
x = 0
y = 0
time = 0
cou = 0
lis = ""
for i in range(h):lis += str(input())
for i in range(h * w):
    if lis[i] == "#":
        cou += 1
for i in range(h):
    while lis[i * w + x] == "#" and y == 0:
        x += 1
        time += 1
        if x == w:
            x -= 1
            y = 1
    if i == h-1 and time == (h + w)-1 and time == cou:
        print("Possible")
        exit()
    time += 1
print("Impossible")
K = int(input())
S = input()
X = len(S)
mod = 10**9+7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

ans = 0
for i in range(X,K+X+1):
    temp = 1
    A = i-X
    B = K+X-i
    temp *= cmb(A+X-1,X-1,mod)*power(25,A,mod)
    temp %= mod
    temp *= power(26,B,mod)
    ans += temp
    ans %= mod
print(ans)

### FIXED CODE ###

K = int(input())
S = input()
X = len(S)
mod = 10**9+7

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod


A = 0
B = K
temp = cmb(A+X-1,X-1,mod)*power(25,A,mod)
temp %= mod
temp *= power(26,B,mod)
temp %= mod

ans = temp

for i in range(X+1,K+X+1):

    temp *= 25
    temp %= mod
    
    temp *= pow(26, mod-2, mod)
    temp %= mod
    
    temp *= i-1
    temp %= mod
    
    temp *= pow(i-X, mod-2, mod)
    temp %= mod    

    ans += temp
    ans %= mod

print(ans)
import numpy as np

ipt = list(map(int,input().split()))
cr = list(map(int,input().split()))
array = np.ones((ipt[0],ipt[1]),int)
for i in range(cr[0]):
  array[i] = array[i] * 0
for j in range(cr[1]):
  array[:,i] = array[:,i] * 0
print(array[array==1].sum())

### FIXED CODE ###

import numpy as np

ipt = list(map(int,input().split()))
cr = list(map(int,input().split()))
print((ipt[0]-cr[0])*(ipt[1]-cr[1]))
while True:
	a,b,c=map(str, input().split())
	if b=='?':
		break
	a=int(a)
	c=int(c)
	if b=='+':
		print(a+c)
	elif b=='*':
		print(a*c)
	elif b=='/':
		print(int(a/c))
	elif b=='-':
		print(a-c)

### FIXED CODE ###

while True:
	a,b,c=map(str, input().split())
	if b=='?':
		break
	a=int(a)
	c=int(c)
	if b=='+':
		print(a+c)
	elif b=='*':
		print(a*c)
	elif b=='/':
		print(int(a/c))
	elif b=='-':
		print(a-c)
N,M,K = map(int,input().split())

par = [i for i in range(N+1)]

# 木の根を求める
def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

# xとyが同じ集合に属するか否か
def bool_same(x,y):
    return root(x) == root(y)

# xとyの属する集合を併合
def unite(x,y):
    x = root(x)
    y = root(y)
    if x != y:
        par[x] = y

AB = [list(map(int,input().split())) for i in range(M)]
CD = [list(map(int,input().split())) for i in range(K)]

for i in range(M):
    a,b = AB[i]
    unite(a,b)

for i in range(N+1):
    root(i)

member = [0 for i in range(N+1)]

for i in range(1,N+1):
    member[par[i]] += 1

ans = [member[par[i]]-1 for i in range(N+1)]

for i in range(M):
    a,b = AB[i]
    if bool_same(a,b):
        ans[a] -= 1
        ans[b] -= 1

for i in range(K):
    c,d = CD[i]
    if bool_same(c,d):
        ans[c] -= 1
        ans[d] -= 1

print(' '.join(list(map(str,ans[1:]))))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**6)

N,M,K = map(int,input().split())

par = [i for i in range(N+1)]

# 木の根を求める
def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

# xとyが同じ集合に属するか否か
def bool_same(x,y):
    return root(x) == root(y)

# xとyの属する集合を併合
def unite(x,y):
    x = root(x)
    y = root(y)
    if x != y:
        par[x] = y

AB = [list(map(int,input().split())) for i in range(M)]
CD = [list(map(int,input().split())) for i in range(K)]

for i in range(M):
    a,b = AB[i]
    unite(a,b)

member = [0 for i in range(N+1)]

for i in range(1,N+1):
    member[root(i)] += 1

ans = [member[par[i]]-1 for i in range(N+1)]

for i in range(M):
    a,b = AB[i]
    if bool_same(a,b):
        ans[a] -= 1
        ans[b] -= 1

for i in range(K):
    c,d = CD[i]
    if bool_same(c,d):
        ans[c] -= 1
        ans[d] -= 1

print(*ans[1:])
x, y, z, k = map(int, input().split())
m = []
for _ in range(3):
    m.append(sorted(list(map(int, input().split())), reverse=True))

def sorted_sum(list_a, list_b, limit):
    s = []
    for x in list_a:
        for y in list_b:
            s.append(x + y)
    return sorted(s[0:limit], reverse=True)


def consume_diff(s, a_val, list_b, b_index):
    diff = a_val - list_b[b_index]
    for i in range(b_index + 1, len(list_b)):
        if list_b[b_index] - list_b[i] > diff:
            break
        s.append(a_val + list_b[i])



ans = sorted_sum(sorted_sum2(m[0], m[1], k), m[2], k)
for i in range(min([k, len(ans)])):
    print(ans[i])

### FIXED CODE ###

x, y, z, k = map(int, input().split())
m = []
for _ in range(3):
    m.append(sorted(list(map(int, input().split())), reverse=True))

def sorted_sum(list_a, list_b, limit):
    s = []
    for x in list_a:
        for y in list_b:
            s.append(x + y)
    return sorted(s, reverse=True)[0:limit]


def consume_diff(s, a_val, list_b, b_index):
    diff = a_val - list_b[b_index]
    for i in range(b_index + 1, len(list_b)):
        if list_b[b_index] - list_b[i] > diff:
            break
        s.append(a_val + list_b[i])



ans = sorted_sum(sorted_sum(m[0], m[1], k), m[2], k)
for i in range(min([k, len(ans)])):
    print(ans[i])
N = int(input())
A = list(map(int, input().split()))

A = sorted(A)

count_m = 0
count_z = 0
count_p = 0
sum_abs = 0

for i in range(N):
    if A[i] < 0:
        count_m += 1
        sum_abs -= A[i]
    elif A[i] == 0:
        count_z += 1
    else:
        count_p += 1
        sum_abs += A[i]

if count_m + count_z == 0:
    print(sum_abs-2*min(A))
    tmp = A[0]
    for i in range(N-2):
        print(tmp, A[i+1])
        tmp -= A[i+1]
    print(A[-1], tmp)

elif count_p + count_z == 0:
    print(sum_abs+2*max(A))
    tmp = A[-1]
    for i in range(N-1):
        print(tmp, A[i])
        tmp -= A[i]

elif count_p + count_m == 0:
    print(0)
    for i in range(N-1):
        print(0, 0)

elif count_z > 0:
    print(sum_abs)
    cmz = count_m + count_z
    tmp = A[-1]
    for i in range(cmz - 1):
        print(tmp, A[i])
        tmp -= A[i]
    tmp_2 = A[cmz-1]
    for i in range(count_p-1):
        print(tmp_2, A[i+cmz])
        tmp_2 -= A[i+cmz]
    print(tmp, tmp_2)

elif count_z == 0:
    print(A[2*N])
    print(sum_abs)
    cmz = count_m + count_z
    tmp = A[-1]
    for i in range(cmz - 1):
        print(tmp, A[i])
        tmp -= A[i]
    tmp_2 = A[cmz-1]
    for i in range(count_p-1):
        print(tmp_2, A[i+cmz])
        tmp_2 -= A[i+cmz]
    print(tmp, tmp_2)

### FIXED CODE ###

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

A = sorted(A)

count_m = 0
count_z = 0
count_p = 0
sum_abs = 0

for i in range(N):
    if A[i] < 0:
        count_m += 1
        sum_abs -= A[i]
    elif A[i] == 0:
        count_z += 1
    else:
        count_p += 1
        sum_abs += A[i]

if count_m + count_z == 0:
    print(sum_abs-2*min(A))
    tmp = A[0]
    for i in range(N-2):
        print(tmp, A[i+1])
        tmp -= A[i+1]
    print(A[-1], tmp)

elif count_p + count_z == 0:
    print(sum_abs+2*max(A))
    tmp = A[-1]
    for i in range(N-1):
        print(tmp, A[i])
        tmp -= A[i]

elif count_p + count_m == 0:
    print(0)
    for i in range(N-1):
        print(0, 0)

else:
    print(sum_abs)
    cmz = count_m + count_z
    tmp = A[-1]
    for i in range(cmz - 1):
        print(tmp, A[i])
        tmp -= A[i]
    tmp_2 = A[cmz-1]
    if count_p != 0:
        for i in range(count_p-1):
            print(tmp_2, A[i+cmz])
            tmp_2 -= A[i+cmz]
        print(tmp, tmp_2)