Harryxun/stf_run huggingface dataset:
import sys
input = sys.stdin.readline
from collections import defaultdict
import itertools

mask = (1 << 10) - 1

symmetry = dict()
decode = dict()
counter = defaultdict(int)

def encode(a,b,c,d):
    t = 1 << 40
    for x,y,z,w in [(a,b,c,d), (b,c,d,a), (c,d,a,b), (d,a,b,c)]:
        u = x + (y << 10) + (z << 20) + (w << 30)
        if t > u:
            t = u
    return t

N = int(input())
tiles = []
for _ in range(N):
    a,b,c,d = map(int,input().split())
    t = encode(a,b,c,d)
    tiles.append(t)
    counter[t] += 1
    if a == b == c == d:
        symmetry[t] = 4
    elif a == c and b == d:
        symmetry[t] = 2
    else:
        symmetry[t] = 1
    decode[t] = (a,b,c,d)

P = [(1,n,n*(n-1),n*(n-1)*(n-2),n*(n-1)*(n-2)*(n-3)) for n in range(N+1)]
P += [(0,0,0,0,0)] * (N+1) # 負数代入対策

power = [[n ** e for e in range(5)] for n in range(5)]

answer = 0
for bottom, top in itertools.combinations(tiles,2):
    counter[bottom] -= 1
    counter[top] -= 1
    a,b,c,d = decode[bottom]
    e,f,g,h = decode[top]
    for x,y,z,w in [(e,f,g,h), (f,g,h,e), (g,h,e,f), (h,e,f,g)]:
        # a,b,c,d
        # x,w,z,y 
        tiles = [encode(p,q,r,s) for p,q,r,s in [(b,a,x,w), (c,b,w,z), (d,c,z,y), (a,d,y,x)]]
        need = Counter(tiles)
        x = 1
        for tile, cnt in need.items():
            x *= P[counter[tile]][cnt] # 残っている個数、必要枚数
            x *= power[symmetry[tile]][cnt]
        answer += x
    counter[bottom] += 1
    counter[top] += 1

# 上下を固定した分
answer //= 3
print(answer)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from collections import Counter
import itertools

mask = (1 << 10) - 1

def encode(a,b,c,d):
    t = 1 << 40
    for x,y,z,w in [(a,b,c,d), (b,c,d,a), (c,d,a,b), (d,a,b,c)]:
        u = x + (y << 10) + (z << 20) + (w << 30)
        if t > u:
            t = u
    return t

def decode(x):
    for _ in range(4):
        yield x & mask
        x >>= 10

def P(n,k):
    x = 1
    for i in range(k):
        x *= (n-i)
    return x

def symmetry(tile):
    a,b,c,d = decode(tile)
    if a == b == c == d:
        return 4
    if a == c and b == d:
        return 2
    return 1

N = int(input())
tiles = []
for _ in range(N):
    a,b,c,d = map(int,input().split())
    tiles.append(encode(a,b,c,d))
counter = Counter(tiles)

counter

answer = 0
for bottom, top in itertools.combinations(tiles,2):
    counter[bottom] -= 1
    counter[top] -= 1
    a,b,c,d = decode(bottom)
    e,f,g,h = decode(top)
    for x,y,z,w in [(e,f,g,h), (f,g,h,e), (g,h,e,f), (h,e,f,g)]:
        # a,b,c,d
        # x,w,z,y 
        tiles = [encode(p,q,r,s) for p,q,r,s in [(b,a,x,w), (c,b,w,z), (d,c,z,y), (a,d,y,x)]]
        need = Counter(tiles)
        x = 1
        for tile, cnt in need.items():
            x *= P(counter[tile],cnt) # 残っている個数、必要枚数
            x *= pow(symmetry(tile), cnt)
        answer += x
    counter[bottom] += 1
    counter[top] += 1

# 上下を固定した分
answer //= 3
print(answer)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import cmp_to_key
import itertools

N, T = map(int, readline().split())
m = map(int, read().split())
AB0 = []
AB1 = []
for a,b in zip(m,m):
    if a == 0:
        AB0.append(b)
    else:
        AB1.append((a,b))

if not AB0:
    raise

def sort_func(ab0, ab1):
    a0, b0 = ab0
    a1, b1 = ab1
    return a1*b0 - a0*b1

AB0.sort()
AB1.sort(key=cmp_to_key(sort_func))
AB0, AB1

def compute_0():
    INF = T + 1
    dp = [INF] * 40
    dp[0] = 0
    for a,b in AB1:
        for n in range(39, -1, -1):
            if dp[n] > T:
                continue
            x = (dp[n] + 1) * (a + 1) + b
            if x < dp[n+1]:
                dp[n+1] = x
    return dp

def compute_1():
    return [0] + list(itertools.accumulate(x + 1 for x in AB0))

dp0 = compute_0()
dp1 = compute_1()

R = len(dp1) - 1
answer = 0
for i,x in enumerate(dp0):
    if x > T:
        break
    while x + dp1[R] > T:
        R -= 1
    value = i + R
    if answer < value:
        answer = value

print(answer)

### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from functools import cmp_to_key
import itertools

N, T = map(int, readline().split())
m = map(int, read().split())
AB0 = []
AB1 = []
for a,b in zip(m,m):
    if a == 0:
        AB0.append(b)
    else:
        AB1.append((a,b))

def sort_func(ab0, ab1):
    a0, b0 = ab0
    a1, b1 = ab1
    return a1*(1+b0) - a0*(1+b1)

AB0.sort()
AB1.sort(key=cmp_to_key(sort_func))
AB0, AB1

def compute_0():
    INF = T + 1
    dp = [INF] * 40
    dp[0] = 0
    for a,b in AB1:
        for n in range(39, -1, -1):
            if dp[n] > T:
                continue
            x = (dp[n] + 1) * (a + 1) + b
            if x < dp[n+1]:
                dp[n+1] = x
    return dp

def compute_1():
    return [0] + list(itertools.accumulate(x + 1 for x in AB0))

dp0 = compute_0()
dp1 = compute_1()

R = len(dp1) - 1
answer = 0
for i,x in enumerate(dp0):
    if x > T:
        break
    while x + dp1[R] > T:
        R -= 1
    value = i + R
    if answer < value:
        answer = value

print(answer)
N = int(input())
*a, = map(int, input().split())
two, four, no = [], [], []
for i in range(N):
    if a[i] % 4 == 0:
        four += 1
    elif a[i] % 2 == 0:
        two += 1
    else:
        no += 1

ok = (two >= max(0, (N-4)) and four >= 2) or four >= N//2
ok = ok and ((four-no) >= 2 or ((four+no) == N and (no-four) <= 1))
if ok:
    print("Yes")
else:
    print("No")


### FIXED CODE ###

N = int(input())
*a, = map(int, input().split())
two, four, no = 0, 0, 0
for i in range(N):
    if a[i] % 4 == 0:
        four += 1
    elif a[i] % 2 == 0:
        two += 1
    else:
        no += 1

ok = four == no or (four+two) == N
ok = ok or ((four+no) == N and abs(four-no) <= 1)
if ok:
    print("Yes")
else:
    print("No")
import numpy as np
a,b = map(int, input().split())
grid1 = np.full((50,100), '.')
grid2 = np.full((50,100), '#')

### FIXED CODE ###

import numpy as np
a,b = map(int, input().split())
grid1 = [['.' for j in range(100)] for i in range(50)]
grid2 = [['#' for j in range(100)] for i in range(50)]
a -= 1
b -= 1
x = y = 1

for i in range(a):
    grid2[x][y] = '.'
    y += 2
    if y != y % 100:
        x += 2
    y = y % 100
    if x >= 50 or y >= 100:break

x = y = 1
for i in range(b):
    grid1[x][y] = '#'
    y += 2
    if y != y % 100:
        x += 2
    y = y % 100
    if x >= 50 or y >= 100:break

print(100, 100)
grid = np.concatenate((grid1, grid2), axis=0)
for row in grid:
    print(''.join(row))
N, M, X, Y = map(int, input().split())

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

for z in range(-100, 101):
    if (X < z) and (max(x) < z) and (min(y) >= z) and (Y >= z):
        print("No War")
    else:
        print("War")

### FIXED CODE ###

a, b, c = (int(x) for x in input().split())
print(a + b + c + max(a, b, c)*9)
n=int(input())
lis=list(map(int,input().split()))
count=1
if 0 in lis:
  print(0)
  exit()
for i in lis:
    count*=i
	if count>10**18:
    	print(-1)
        exit()
print(count)


### FIXED CODE ###

n = int(input())
lis = list(map(int,input().split()))
ans = 1
if 0 in lis:
  print(0)
  exit()
for num in lis:
  ans *= num
  if ans > 10 ** 18:
    print(-1)
    exit()
print(ans)
N = int(raw_input())
a = map(int, raw_input().split())
ans = 0
i = 0
while i < N-1:
  if a[i] == a[i+1]:
    if i+1 < N and a[i] == a[i+2]:
      a[i+1] = 101+ans
      i += 3
    else:
      a[i] = 101+ans
      i += 2
    ans += 1
  else:
    i += 1
print ans



### FIXED CODE ###

N = int(raw_input())
a = map(int, raw_input().split())
ans = 0
i = 0
while i < N-1:
  if a[i] == a[i+1]:
    if i+2 < N and a[i] == a[i+2]:
      a[i+1] = 101+ans
    else:
      a[i] = 101+ans
    ans += 1
    i += 2
  else:
    i += 1
print ans
import math
n=int(input())
print(math.factorial(n)%(1e9+7))n=int(input())
ans=1
for i in range(1,n+1):
    ans=(ans*i)%(1e9+7)
print(ans)

### FIXED CODE ###

n=int(input())
ans=1
for i in range(1,n+1):
    ans=(ans*i)%(1e9+7)
print(int(ans))
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
cost=[0,2,5,5,4,5,6,3,7,6]
inf=-1*(10**9)
dp=[inf]*(n+1)
dp[0]=0
for i in range(1,n+1):
    ddp=[]
    for j in range(m):
        ddp.append(dp[i-cost[a[j]]]+1)
    dp[i]=max(ddp)
ans=[]
for i in range(dp[n]):
    for j in range(m):
        if dp[n-cost[a[j]]]==dp[n]-1:
            ans.append(a[j])
            n-=cost[a[j]]
            break
print("".join(list(map(str,ans))))


### FIXED CODE ###

n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
nums=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(n+1)
dp[0]=0
for i in range(1,n+1):
    for x in a:
        if i-nums[x]>=0:
            dp[i]=max(dp[i-nums[x]]+1,dp[i])
k=dp[n]
ans=[]
for i in range(k):
    for x in a:
        if n-nums[x]<0:
            continue
        if dp[n-nums[x]]==dp[n]-1:
            n-=nums[x]
            ans.append(x)
            break
print("".join(list(map(str,ans))))
x=list(map(int,input().split()))
for i in range(n):
    if x[i]==0:
        print(i+1)
        break

### FIXED CODE ###

x=list(map(int,input().split()))
for i in range(len(x)):
    if x[i]==0:
        print(i+1)
        break
a,b,c=map(int,input().split())
print('A' if abs(a,b)<abs(a,c) else 'B')

### FIXED CODE ###

a,b,c=map(int,input().split())
print('A' if abs(a-b)<abs(a-c) else 'B')
import sys
from io import StringIO
import unittest

sys.setrecursionlimit(10**5)
def search(n, step, rec, seq, k):
	if rec[n] != -1:
		c = step - rec[n]
		sim = (k - rec[n]) % c
		v = n
		for i in range(sim):
			v = seq[v-1]
		print(v)
		return
	rec[n] = step
	search(seq[n-1], step + 1, rec, seq, k)

def resolve():
	n, k = map(int, input().split())
	seq = list(map(int, input().split()))
	rec = [-1]*(n+1)
	search(1, 0, rec, seq, k)
resolve()

### FIXED CODE ###

def resolve():
	n, m, x = map(int, input().split())
	books = [list(map(int, input().split())) for _ in range(n)]

	pay = float('inf')
	for i in range(1 << n):
		selected = []
		for j in range(n):
			if i >> j & 1:
				selected.append(j)
		rem = [0] * m
		tmp_pay = 0
		for j in selected:
			tmp_pay += books[j][0]
			for k in range(1, m+1):
				rem[k-1] += books[j][k]
		done = True
		for j in range(m):
			if rem[j] < x:
				done = False
		if done:
			pay = min(pay, tmp_pay)
	if pay == float('inf'):
		print(-1)
	else:
		print(pay)
resolve()
def sunuke_sum(arg):
    sum_digit = 0
    for char in arg:
        sum_digit += int(char)
    return sum_digit


input_num = int(input())

sunuke_list = []
min_sunuke_div = 10 ** 20
for d in reversed(range(1, 16)):
    for n in reversed(range(10, 100)):
        i = n * (10 ** d) + (10 ** d - 1)
        sunuke_div = i / sunuke_sum(str(i))
        if min_sunuke_div >= sunuke_div:
            sunuke_list.append(i)
            min_sunuke_div = sunuke_div

for i in reversed(range(1, 101)):
    sunuke_div = i / sunuke_sum(str(i))
    if min_sunuke_div >= sunuke_div:
        sunuke_list.append(i)
        min_sunuke_div = sunuke_div

sunuke_list.reverse()

for i in range(0, input_num):
    print(sunuke_list[i])


### FIXED CODE ###

input_line = input().split()

num_array = int(input_line[0])
num_equal = int(input_line[1])

input_line = input()
array_str = input_line.split()

array = list(map(int, array_str))

for index, number in enumerate(array):
    if number == 1:
        index_min = index
        break

# from forward

equalized = 1
i = 1
while equalized < num_array:
    equalized += (num_equal - 1)
    # print(i, equalized)
    i += 1

print(i - 1)
n = int(input())
p = input().split(" ")
a = 0
for i in range(len(n)):
    pf = p[i]
    ps = p[i+1]
    pt = p[i+2]
    il = [int(pf),int(ps),int(pt)]
    max_p = max(il)
    il.remove(max_p)
    if int(ps) == max(il):
        a += 1
print(a)

### FIXED CODE ###

n = int(input())
p = input().split(" ")
a = 0
for i in range(len(p)):
    try:
        pf = p[i]
        ps = p[i+1]
        pt = p[i+2]
        il = [int(pf),int(ps),int(pt)]
        max_p = max(il)
        il.remove(max_p)
        if int(ps) == max(il):
            a += 1
    except:
        pass
print(a)
ans = 0
for i in range(len(S)-2):
    m = int(S[i:i+3])
    ans = abs(753 - m)
    if min > ans:
        min = ans
print(min)

### FIXED CODE ###

S = str(input())
min = 99999999999
ans = 0
for i in range(len(S)-2):
    m = int(S[i:i+3])
    ans = abs(753 - m)
    if min > ans:
        min = ans
print(min)
S = input()
K = int(input())

for i in range(len(S)):
    if (int(S[i]) == 1):
        continue
    if (int(S[i]) >= 2):
        ans = int(S[i])
    break

print(ans)


### FIXED CODE ###

S = input()
K = int(input())

for i in range(K):
    if (int(S[i]) == 1):
        ans = int(S[i])
        continue
    if (int(S[i]) >= 2):
        ans = int(S[i])
    break

print(ans)
x=int(input())
y=x//2
z=x-1
print(z/y)

### FIXED CODE ###

x=int(input())
y=x//2
z=x-y
print(z/x)
while 1:
	list = raw_input().split()
	x = int(list[0]) + int(list[1])
	print "%d" % len(str(x))

### FIXED CODE ###

one=0
two=0
three=0
while 1:
	try:
		i=int(raw_input())
		if one<i:
			three=two
			two=one
			one=i
		elif two<i:
			three=two
			two=i
		elif three<i:
			three=i
    	except:
	    	print"%d"%(one)
	    	print"%d"%(two)
	    	print"%d"%(three)
	    	break
r = input()
if r < 1200:
    print('ABC')
elif 1200 <= r < 2800:
    print('ARC')
else:
    print('AGC')


### FIXED CODE ###

r = int(input())
if r < 1200:
    print('ABC')
elif 1200 <= r < 2800:
    print('ARC')
else:
    print('AGC')
n=int(input())
a=list(map(int,input().split()))
def f():
  if 0 in a:
    print(0)
  else:
    b=1
    for i in range(0,n):
      b*=a[i]

      if b>10**8:
        print(-1)
        exit()
   
    print(b)

f()

### FIXED CODE ###

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

print(M[0]*M[1])
if __name__ == '__main__':
    N = int(input())
    l = []
    S = []; X = []; Y = []; P = []
    ans = 0
    for _ in range(N):
        x,y,p = map(int,input().split())
        s = p * min(abs(x),abs(y))
        ans += s
        S.append(s)
        X.append(x); Y.append(y); P.append(p)
    print(ans)
    l_S = []
    for i in range(N*2):
        if i < N:
            x = X[i]
            S_temp = []
            temp = 0
            for j in range(N):
                m = min(S[j],P[j] * (abs(X[j]-x)))
                S_temp.append(m)
                temp += m
            if ans > temp:
                 ans = temp
        else:
            y = Y[i-N]
            S_temp = []
            temp = 0
            for j in range(N):
                m = min(S[j],P[j] * (abs(Y[j]-y)))
                S_temp.append(m)
                temp += m
            if ans > temp:
                 ans = temp
        l_S.append(S_temp)
    print(ans)
    memo = [n for n in range(2 * N)]
    l_S0 = l_S
    for _ in range(N-1):
        if ans == 0:
          print(0)
          continue
        l_S1 = []
        newMemo = []
        for j in range(len(l_S0)):
            for k in range(memo[j]+1, N * 2):
                l = l_S[k]
                l0 = l_S0[j]
                S_temp = []
                temp = 0
                for h in range(N):
                    m = min(l[h],l0[h])
                    S_temp.append(m)
                    temp += m
                if ans > temp:
                     ans = temp
                l_S1.append(S_temp)
                newMemo.append(k)
        memo = newMemo
        l_S0 = l_S1
        print(ans)

### FIXED CODE ###

X = int(input())
print(8 - ((X-400)//200))
import sys
input = sys.stdin.readline
from itertools import accumulate

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Acc = list(accumulate(A))
Bcc = list(accumulate(B))
a = N-1
b = M-1
ans = 0
for n,i in enumerate(Acc):
    if i > K:
        a = n-1
        break
for n,i in enumerate(Bcc):
    if i > K:
        b = n-1
        break
if a > b:
    K -= Acc[a]
    b = 0
    for i in B:
        if i <= K:
            K -= i
            b += 1
        elif i < A[a]:
            K += A[a]-i
            a -= 1
            b += 1
        else:
            break
else:
    K -= Bcc[b]
    a = 0
    for i in A:
        if i <= K:
            K -= i
            b += 1
        elif i < B[b]:
            K += B[b] - i
            b -= 1
            a += 1
        else:
            break
a = a+1 if a else a
b = b+1 if b else b
print(a+b)

### FIXED CODE ###

import sys
input = sys.stdin.readline
from itertools import accumulate

N,M,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
a = [0]+list(accumulate(A))
b = [0]+list(accumulate(B))
ans,j = 0,M
for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)
a, b, c = map(int, input().split())
if a+b+c == 17 and a=5, b=7, c=5;
	print("YES")
else;
	print("NO")

### FIXED CODE ###

a, b, c = map(int, input().split())
if a+b+c == 17:
	print("YES")
else:
  print("NO")
n = int(input())

if n == 7 , 5 ,3:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

n = int(input())

if n in [7 , 5 ,3]:
  print("YES")
else:
  print("NO")
x = input()
print(x * x* x)


### FIXED CODE ###

a = input()
a = int(a)

print( a**3)
a = int(input())
b = list(map(int,input().split()))
b.sort()
ans = 0
n = b[0]
while n % 2 ==0:
	ans +=1
	n = n/2
print(ans)

### FIXED CODE ###

a = list(map(int,input()))
b= sum(a)
print(b)
A = list(map(int, input().split()))

total = sum(A)

if total > 22:
  print("bust")
else:
  print("win)

### FIXED CODE ###

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

total = sum(A)

if total > 21:
  print("bust")
else:
  print("win")
import sys
import collections

stdin = sys.stdin

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

n = ni()
a = na()
a.sort()
cnt = collections.Counter(a)


elem = [True]*(a[-1]+1)
for i in a:
  for j in range(i*2,len(elem)+1,i):
    elem[j] = False
ans = 0
for v in a:
  if elem[v] == True and cnt[v] == 1:
    ans += 1
    
print(ans)

### FIXED CODE ###

import sys
from collections import Counter

stdin = sys.stdin

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

n = ni()
a = na()
a.sort()
cnt = Counter(a)
elem = [True]*(a[-1]+1)

for i in a:
  for j in range(i*2,a[-1]+1,i):
    elem[j] = False
ans = 0
for v in a:
  if elem[v] == True and cnt[v] == 1:
    ans += 1
    
print(ans)
def main():
    S = list(input())
    k = int(input())
    ans = []
    for s in S:
        if k == 0:
            break
        if s != 'a' and ord(s) >= 123 - k:
            ans.append('a')
            k -= 123 - ord(s)
        else:
            ans.append(s)
    if k > 0:
        ans[-1] = chr(ord(ans[-1]) + k)
    print(''.join(ans))



if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    s = input()
    print(s[:4] + ' ' + s[4:])

if __name__ == '__main__':
    main()
a=int(input())
b=int(input())
print(len(str(a+b)))

### FIXED CODE ###

while True:
    try:
        a,b=map(int,input().split(' '))
        print(len(str(a+b)))
    except:
        break
import numpy as np
N = int(input())
data = np.zeros((N,3))
for i in range(N):
    data[i] = np.array(input().split())

# data = np.array([[2,3,5],[2,1,5],[1,2,0],[3,2,5]])

for n in range(10201):
    C_x = n // 101
    C_y = n % 101
    flg = True
    unsetflg = True
    for i,(x,y,h) in enumerate(data):
        if unsetflg and h>=1:
            H = abs(x-C_x)+abs(y-C_y)+h
            unsetflg = False
        else
            if h>=1 and H != abs(x-C_x)+abs(y-C_y)+h:
                flg = False
                break 
    if flg:
        print(C_x,C_y,int(H))
        break
    
            
            


### FIXED CODE ###

import numpy as np
N = int(input())
data = np.zeros((N,3))
for i in range(N):
    data[i] = np.array(input().split())

# data = np.array([[2,3,0],[2,1,0],[1,2,0],[3,2,5]])

if len(np.where(data[:,2]!=0)[0]) == 1:
    C_x, C_y, H = map(int,data[np.where(data[:,2]!=0)[0][0]])
    print(C_x, C_y, H)
else:
    for n in range(10201):
        C_x = n // 101
        C_y = n % 101
        correctflg = True
        unsetflg = True
        for x,y,h in data:
            if unsetflg:
                if h >= 1:
                    H = abs(x-C_x)+abs(y-C_y)+h
                    unsetflg = False
            else:
                if h >= 1 and H != abs(x-C_x)+abs(y-C_y)+h:
                    correctflg = False
                    break 
        if correctflg:
            print(C_x,C_y,int(H))
            break
n = int(input())
a = [int(i) for i in input().split()]
a_2 = [abs(a[i]) for i in range(n)]
a.sort()

if a[0] >= 0:
    print([sum(a_2) -2, sum(a_2)][a[0] == 0])
    aa = a[0]
    for i in range(n-1):
        if i == 0:
            print(aa, a[i + 1])
            aa = aa - a[i + 1]
        elif i == n - 2:
            print(a[i + 1], aa)
        else:
            print(aa, a[i+1])
            aa = aa - a[i + 1]

elif a[-1] <= 0:
    print(aaaaaa)

    print([sum(a_2) -2, sum(a_2)][a[-1] == 0])
    if a[-1] == 0:
        a = [a[0]] + [a[-1]] + a[1:]
    aa = a[0]
    for i in range(n-1):
        if i == 0:
            print(a[i+1], aa)
            aa = a[i + 1] - aa
        elif i == n - 2:
            print(aa, a[i + 1])
        else:
            print(aa, a[i+1])
            aa = aa - a[i + 1]

else:
    print(sum(a_2))
    minus = []
    plus = []
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        else:
            plus.append(a[i])
    minus2 = minus.pop()
    plus2 = plus.pop()
    for i in range(len(minus)):
        print(plus2 ,minus[i])
        plus2 -= minus[i]
    for i in range(len(plus)):
        print(minus2, plus[i])
        minus2 -= plus[i]
    print(plus2, minus2)



### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
a_2 = [abs(a[i]) for i in range(n)]
a.sort()

if a[0] >= 0:
    print([sum(a_2) -2, sum(a_2)][a[0] == 0])
    aa = a[0]
    for i in range(n-1):
        if i == 0:
            print(aa, a[i + 1])
            aa = aa - a[i + 1]
        elif i == n - 2:
            print(a[i + 1], aa)
        else:
            print(aa, a[i+1])
            aa = aa - a[i + 1]

elif a[-1] <= 0:

    print([sum(a_2) -2, sum(a_2)][a[-1] == 0])
    a.reverse()
    if a[-1] == 0:
        a = [a[-1]] + a[0:]
    aa = a[0]
    for i in range(n-1):
        if i == 0:
            print(aa, a[i + 1])
            aa = aa - a[i + 1]
        elif i == n - 2:
            print(aa, a[i + 1])
        else:
            print(aa, a[i+1])
            aa = aa - a[i + 1]

else:
    print(sum(a_2))
    minus = []
    plus = []
    for i in range(n):
        if a[i] < 0:
            minus.append(a[i])
        else:
            plus.append(a[i])
    minus2 = minus.pop()
    plus2 = plus.pop()
    for i in range(len(minus)):
        print(plus2 ,minus[i])
        plus2 -= minus[i]
    for i in range(len(plus)):
        print(minus2, plus[i])
        minus2 -= plus[i]
    print(plus2, minus2)
a,b=list(int(input().split()))
print(max(a+b,a-b,a*b))

### FIXED CODE ###

a,b=list(map(int,input().split()))
print(max(a+b,a-b,a*b))
from sys import stdin
import math
from collections import deque
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

def main():
    mod = 10**9+7
    n = I()
    a = LI()
    a.sort(reverse=True)
    ans = 0
    dig = int(math.log2(a[0])) + 1
    for i in range(dig):
        c0 = 0
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
            else:
                c0 += 1
        ans += c0*c1*2**i
    ans %= mod
    print(ans)
    return

if __name__=='__main__':
    main()

### FIXED CODE ###

from sys import stdin
def I(): return int(stdin.readline().rstrip())
def LI(): return list(map(int,stdin.readline().rstrip().split()))

if __name__=='__main__':
    mod = 10**9 + 7
    n = I()
    a = LI()
    ans = 0
    for i in range(60):
        c1 = 0
        for rep in a:
            if (rep>>i)&1:
                c1 += 1
        ans += ((n-c1)*c1*(2**i)%mod)%mod
    print(ans%mod)