Harryxun/stf_run huggingface dataset:
N,A = map(int,input().split())

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

ma = max(X)

dp = [[[0 for s in range(ma*N+1)] for k in range(N+1)] for i in range(N+1)]

dp[0][0][0] = 1

for i in range(1,N+1) :
    for k in range(i+1) :
        for s in range(ma*N+1) :
            if (k >= 1) and (s >= X[i-1]) :
                dp[i][k][s] = dp[i-1][k][s] + dp[i-1][k-1][s-X[i-1]]
            else :
                dp[i][k][s] = dp[i-1][k][s]

ans = 0

for k in range(1,N+1) :
    ans += dp[N][k][k*A]

print(ans)


### FIXED CODE ###

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

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

ma = max(X)

dp = [[[0 for s in range(ma*N+1)] for k in range(N+1)] for i in range(N+1)]

dp[0][0][0] = 1

for i in range(1,N+1) :
    for k in range(i+1) :
        for s in range(ma*N+1) :
            if (k >= 1) and (s >= X[i-1]) :
                dp[i][k][s] = dp[i-1][k][s] + dp[i-1][k-1][s-X[i-1]]
            else :
                dp[i][k][s] = dp[i-1][k][s]

ans = 0

for k in range(1,N+1) :
    if k*A > ma*N :
        break
    ans += dp[N][k][k*A]

print(ans)
N = input()
oh = N//100
ot = (N-oh*100)//10
oo = N-oh*100-ot*10
if oh==7 or ot==7 or oo==7:
    print('Yes')
else:
    print('No')


### FIXED CODE ###

N = int(input())
oh = N//100
ot = (N-oh*100)//10
oo = N-oh*100-ot*10
if oh==7 or ot==7 or oo==7:
    print('Yes')
else:
    print('No')
a = input()
import math
print("{:.7f} {:.7f}".format(a ** 2 * math.pi, 2 * a * math.pi))

### FIXED CODE ###

a = float(input())
import math
print("{:.5f} {:.5f}".format(a ** 2 * math.pi, 2 * a * math.pi))
# 2019/11/23
# DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選 - B

# Binary Search
def binSearch (tlis, tval):
    lf = 0
    rg = len(tlis)
    while(lf <= rg):
        ct = int((lf + rg) / 2)
        if tlis[ct] < tval:
            lf = ct + 1
        elif tlis[ct] > tval:
            rg = ct - 1
        else:
            return ct
    return ct

# Input
n = int(input())
a = list(map(int,input().split()))
acm_a = list()
acm_a.append(0)

# Sum
for i in range(len(a)):
    acm_a.append(a[i] + acm_a[i])

# Calc Center
center = acm_a[len(a)] / 2
ctidx = binSearch(acm_a, center)

if (center - acm_a[ctidx]) < (acm_a[ctidx] - center):
    ans = (acm_a[len(a)] - acm_a[ctidx + 1]) - acm_a[ctidx+1]
elif (center - acm_a[ctidx]) > (acm_a[ctidx] - center):
    ans = acm_a[ctidx+1] - (acm_a[len(a)] - acm_a[ctidx + 1])
else:
    ans = 0

# Output
print(ans)


### FIXED CODE ###

# 2019/11/23
# DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選 - B

# Binary Search
def binSearch (tlis, tval):
    lf = 0
    rg = len(tlis)
    while(lf <= rg):
        ct = int((lf + rg) / 2)
        if tlis[ct] < tval:
            lf = ct + 1
        elif tlis[ct] > tval:
            rg = ct - 1
        else:
            return ct
    return ct

# Input
n = int(input())
a = list(map(int,input().split()))
acm_a = list()
acm_a.append(0)

# Sum
for i in range(len(a)):
    acm_a.append(a[i] + acm_a[i])

acm_a.append(acm_a[len(a)])
# Calc Center
center = acm_a[len(a)] / 2
ctidx = binSearch(acm_a, center)

ans = min(abs((acm_a[len(a)] - acm_a[ctidx-1]) - acm_a[ctidx-1]), abs((acm_a[len(a)] - acm_a[ctidx]) - acm_a[ctidx]), abs((acm_a[len(a)] - acm_a[ctidx+1]) - acm_a[ctidx+1]))

# Output
print(ans)
# 高橋君の夏休みはN日間です。夏休みの宿題がM個出されており,i番目の宿題をやるにはAi日間かかります。
# 複数の宿題を同じ日にやることはできず、また、宿題をやる日には遊ぶことができません。
# 夏休み中に全ての宿題を終わらせるとき、最大何日間遊ぶことができますか？
# ただし、夏休み中に全ての宿題を終わらせることができないときは、かわりに -1 を出力してください。


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

# リストにM個の数字を、入力したい
# study_days_list = []
# study_days_list.append(study_days)
# print(study_days_list)

total_study_days = sum(study_days)

answer = (N - total_study_days)

if answer < 0:
    print(-1)
else:
    print(answer)

### FIXED CODE ###

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

SK = S[0 : (K)]

if len(S) <= K:
    print(S)
else:
    print(SK + '...')
a = int(input())
s = int(input())

if a >= 3200:
  print(s)
else:
  print("red")

### FIXED CODE ###

a = int(input())
s = input()

if a >= 3200:
  print(s)
else:
  print("red")
from collections import Counter
N = int(input())
A = list(map(int,input().split()))
C = sorted(Counter(A).most_common(),reverse=True)
D = []
F = []
for i in range(len(C)):
    x,y = C[i][0],C[i][1]
    if y >= 2:
        D.append(x)
    if y >= 4:
        F.append(x)
E = sorted(D,reverse=True)
G = sorted(F,reverse=True)
if len(E)>=2:
    if G[0]==E[0]:
        print(G[0]*G[0])
    else:
        print(E[0]*E[1])
else:
    print(0)

### FIXED CODE ###

from collections import Counter
N = int(input())
A = Counter(list(map(int,input().split()))).most_common()
fA = filter(lambda x: x[1] >= 2, A)
sA = sorted(fA,reverse=True)
if len(sA) < 2:
    print(0)
else:
    print(sA[0][0]**2 if sA[0][1]>=4 else sA[0][0]*sA[1][0])
a,b=map(int, input())

if a>=13:
    print(b)
elif a<=5:
    print(0)
else:
    print(b//2)


### FIXED CODE ###

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

if a>=13:
    print(b)
elif a<=5:
    print(0)
else:
    print(b//2)
print x*x*x:

### FIXED CODE ###

x = raw_input()
x = int(x)
print x*x*x
num =input()


for i in range(num):
    x = map(float, raw_input().split(' '))
    if x[1]-x[3] == 0 or x[1]-x[3] == 0:
        if x[1]-x[3] == 0 and x[1]-x[3] == 0:
            print 'YES'
        elif:
            print 'NO'
        
    elif (x[0]-x[2])/(x[1]-x[3]) == (x[4]-x[6])/(x[5]-x[7]):
        print 'YES'
    else:
        print 'NO'

### FIXED CODE ###

num =input()


for i in range(num):
    x = map(float, raw_input().split(' '))

    if x[1]-x[3] == 0 or x[5]-x[7] == 0:
        if x[1]-x[3] == 0 and x[5]-x[7] == 0:
            print 'YES'
        else:
            print 'NO'
        
    elif (x[0]-x[2])/(x[1]-x[3]) == (x[4]-x[6])/(x[5]-x[7]):
        print 'YES'
    else:
        print 'NO'
s=input()
a=s[:len(s)//2]
b=s[(len(s)//2)+1:]
if a==b:
  if a==reversed(a) and b==reversed(b):
  print('Yes')
else:
  print('No')


### FIXED CODE ###

s=input()
ans='No'
if s==s[::-1]:
  t=s[:len(s)//2]
  if t==t[::-1]:
    u=s[len(s)//2+1:]
    if u==u[::-1]:
      ans='Yes'
print(ans)
W, H, x, y, r = map(int, input().split())
  if r <= x <= W - r and r <= y <= H - r
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

W, H, x, y, r = map(int, input().split())
if r <= x <= W - r and r <= y <= H - r:
  print("Yes")
else:
  print("No")
a = int(input())
b = int(input())

c = a + b
d = a - b
e = a * b
ary = [c, d, e]
f = max(ary)
print ("Max:", f)

### FIXED CODE ###

a,b = map(int,input().split())
print(max(a+b, a-b, a*b))
N = int(input())
num = (N-2)**(0.5)
if N == 3:
  print("Yes");print(3)
  A = [2, 1, 2]; print(*A)
  A = [2, 2, 3]; print(*A)
  A = [2, 3, 1]; print(*A); exit()
if num%1 != 0:
  print("No");exit()
num = int(num)
ans = []
for i in range(num):
  temp = [1] + [2+j+num*i for j in range(num)]
  ans.append(temp)
for i in range(num):
  temp = [2+i+num*j for j in range(num)] + [N]
  ans.append(temp)
print("Yes")
print(num*2)
for x in ans:
  ret = [num+1] + x
  print(*ret)

### FIXED CODE ###

N = int(input())
MAX = 450
A = [[1],[1]] #size = 2
#A = [[1,2],[2,3],[3.1]]
size = 0
for i in range(1,MAX):
  if i*(i+1)//2 == N:
    size = i+1
    break
if size == 0:
  print("No")
  exit()
now = 2
while now < size:
  start = now*(now-1)//2+1
  last = [start+i for i in range(now)]
  for j in range(len(A)):
    A[j].append(last[j])
  A.append(last)
  now += 1
print("Yes")
print(len(A))
#ini = [len(A)-1]
for x in A:
  x.insert(0,len(A)-1)
  print(*x)
import math
N=int(input())
q=int(math.sqrt(N*2))
if N*2!=q*q+q:print("No");exit()
S=[list(range(1,q+1))]
S+=[[j]for j in S[0]]
last=q
for i in range(1,q):
	r=list(range(last+1,last+1+q-i))
	S[i]+=r
	for j in range(q-i):S[i+j+1]+=[r[j]]
	last=r[-1]
print("Yes")
print(len(S))
for s in S:print(len(s)," ".join(map(str,s)))

### FIXED CODE ###

S=input()
print(S[::-1]if len(S)==3 else S)
N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
# 小さい順にソートする
#def sort(h):
#    if len(h) <= 1:
#        return h
#    base = h[-1]
#    low_temp = [];
#    high_temp = [];
#    base_count = 1
#    for i in range(len(h)-1):
#        if h[i] < base:
#            low_temp.append(h[i])
#        elif h[i] > base:
#            high_temp.append(h[i])
#        else:
#            base_count += 1
#    low = sort(low_temp)
#    high = sort(high_temp)
#    return low + [base]*base_count + high
h.sort()
hantei = 10**10
for i in range(N-K+1):
    temp = h[i:i+K]
    temp_dif = temp_dif[-1] - temp_dif[0]
    if temp_dif < hantei:
        hantei = temp_dif
print(hantei)


### FIXED CODE ###

N, K = map(int, input().split())
h = [int(input()) for i in range(N)]
h.sort()
print(min(h[i+K-1] - h[i] for i in range(N-K+1)))
# -*- coding: utf-8 -*-
from bisect import bisect_left


def main():
    N, K = map(int, input().split())
    *a, = map(int,input().split())
    sum_a = [0] * N
    sum_a[0] = a[0]
    for i in range(N - 1):
        sum_a[i + 1] = sum_a[i] + a[i + 1]

    ans = N - bisect_left(sum_a, K)

    for l in range(1, N):
        ans += N - bisect_left(sum_a, K + sum_a[l - 1])

    print(ans)




if __name__ == '__main__':
    main()

### FIXED CODE ###

# -*- coding: utf-8 -*-


def main():
    x, a = map(int, input().split())
    if x < a:
        print('0')
    else:
        print('10')



if __name__ == '__main__':
    main()
a,b = int(input().split())
print(max(a+b,a-b,a*b))


### FIXED CODE ###

a,b = map(int,input().split())
list = [a+b,a-b,a*b]
print(max(list))
n = int(input())
#n, k = map(int,input().split())
#plst = [int(i) for i in input().split()]

lst = [int(input()) for _ in range(n)]

def a(p, q):
    if p % q == 0:
        return q
    else:
        return a(q, p % q)

f = lst[0] * (lst[1] // a(lst[0], lst[1]))
for i in range(2, n):
    f = f * (lst[i] // a(f, lst[i]))
print(f)

### FIXED CODE ###

n = int(input())
#n, k = map(int,input().split())
#plst = [int(i) for i in input().split()]
if n == 1:
    print(int(input()))
else:
    lst = [int(input()) for _ in range(n)]

    def a(p, q):
        if p % q == 0:
            return q
        else:
            return a(q, p % q)

    f = lst[0] * (lst[1] // a(lst[0], lst[1]))
    for i in range(2, n):
        f = f * (lst[i] // a(f, lst[i]))
    print(f)
c = input()
if c in 'aeiou':
  print(vowel)
else:
  print(consonant)

### FIXED CODE ###

c = input()
if c in 'aeiou':
  print('vowel')
else:
  print('consonant')
N=int(input())
A=list(map(int,input().split()))
if A is 0:
  print(0)
  return
p=1
for i in A:
  p=p*i
  if p>1000000000000000000:
    print(-1)
    return
print(p)  
  
  

### FIXED CODE ###

def main():
    N=int(input())
    A=list(map(int,input().split()))
    if 0 in A:
      print('0')
      return
    p=1
    for i in A:
      p=p*i
      if p>1000000000000000000:
        print(-1)
        return
    print(p)    
main()
101 9901 999999000001

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
s=1
if 0 in A:
    print(0)
    exit()
for i in range(N):
    s*=A[i]
    if s>10**18:
        print(-1)
        exit()
print(s)
n,m = map(int, input().split())
div = 1000000007
ok [True] * (n + 1)
for _ in range(m):
  a = int(input())
  ok[a] = False
dp = [0] * (n + 1)
dp[0] = 1
if ok[1]:
  dp[1] = 1
else:
  dp[1] = 0

for i in range(2, n+1):
  if ok[i]:
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= div

print(dp[n])
  

### FIXED CODE ###

n,m = map(int, input().split())
div = 1000000007
ok = [True] * (n + 1)
for _ in range(m):
  a = int(input())
  ok[a] = False
dp = [0] * (n + 1)
dp[0] = 1
if ok[1]:
  dp[1] = 1
else:
  dp[1] = 0

for i in range(2, n+1):
  if ok[i]:
    dp[i] = dp[i-1] + dp[i-2]
    dp[i] %= div

print(dp[n])
import math
while True:
    try:
        a,b = map(int,input().split())
        gcd = math.gcd(a,b)
        lcm = a*b /gcd
        print(gcd,int(lcm))
    except (EOFError,ValueError):
        break

### FIXED CODE ###

while True:
    try:
        As,Bs = map(int,input().split())
        a,b = As, Bs
        while True:
            if a % b == 0:
                gcd = b
                break
            a,b = b, a % b
        print(gcd,int(As * Bs / gcd))
    except EOFError:
        break
pow(x, 3)

### FIXED CODE ###

x = int(input())
print(x ** 3)
l = [0]*11
r = list(map(int,input().split()))
for i in r:
  l[r] += 1
print("YES" if (l[5]==2)and(l[7]==1) else "NO")

### FIXED CODE ###

l = [0]*11
r = list(map(int,input().split()))
for i in r:
  l[i] += 1
print("YES" if (l[5]==2)and(l[7]==1) else "NO")
a, b, c = input
b2 = a
c2 = b
a2 = c
print(a2, b2, c2)


### FIXED CODE ###

in_ = input()
a, b, c = map(int, in_.split())
b2 = a
c2 = b
a2 = c
print(a2, b2, c2)
N=input(">>")
print N*N*N

### FIXED CODE ###

def main():
  i=int(input())
  print(i*i*i)
  
main()
#!/usr/bin/env python
# coding: utf-8

# In[1]:


import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
bcs = [list(map(int, input().split())) for i in range(M)]
"""
10 3
1 8 5 7 100 4 52 33 13 5
3 10
4 30
1 4
"""


# In[14]:


def binary_search(nbs, tar):
    #print(nbs, tar)
    ln = 0
    rn = len(nbs)-1
    t = int(len(nbs)/2)
    
    while ln < rn:
        comp = nbs[t]
        if tar >= comp and tar<nbs[t+1]:
            break
        elif tar >= comp: # 今の値がtar以下であれば、
            ln = t + 1 # 左端をt+1に更新
        elif tar < comp: # 今の値が
            rn = t - 1 # 右端をt-1に更新
        t = int((ln+rn)/2)
    return t


# In[16]:


sbcs = sorted(bcs, key=lambda x:x[1], reverse=True)
nb = 0
sA = sorted(A)
for i in range(M):
    if nb >= N: # nbがN以上になれば、終了
        break
    
    B, C = sbcs[i]
    if sA[nb] >= C: # もしnb個目がC以上であれば、終了
        break
    elif sA[nb+B-1] <= C: #もしB個目が、C以下なら、B個目までをCにする
        sA[nb:nb+B] = [C]*B
        nb += B
    else: #nb個目がC未満で、nb+B-1個目がCより大きければ
        t = binary_search(sA[nb:nb+B], C) if nb+t < N else N-1
        sA[nb:nb+t+1] = [C]*(t+1)
        nb += t+1
    
print(sum(sA))


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[1]:


import sys
input = sys.stdin.readline
N, M = map(int, input().split())
A = list(map(int, input().split()))
bcs = [list(map(int, input().split())) for i in range(M)]


# In[14]:


"""
def binary_search(nbs, tar):
    #print(nbs, tar)
    ln = 0
    rn = len(nbs)-1
    t = int(len(nbs)/2)
    
    while ln < rn:
        comp = nbs[t]
        if tar >= comp and tar<nbs[t+1]:
            break
        elif tar >= comp: # 今の値がtar以下であれば、
            ln = t + 1 # 左端をt+1に更新
        elif tar < comp: # 今の値がtarより大きければ、
            rn = t - 1 # 右端をt-1に更新
        t = int((ln+rn)/2)
    return t
"""


# In[16]:


sbcs = sorted(bcs, key=lambda x:x[1], reverse=True)
sA = sorted(A)

nb = 0
ans = 0
is_finish = False

for i in range(M):
    B, C = sbcs[i]
    
    for j in range(B):
        if nb < N and sA[nb] < C:
            ans += C
            nb += 1
        else:
            is_finish = True
            break
    
    if is_finish:
        break

if nb < N:
    ans += sum(sA[nb:])

print(ans)
        
"""
    if nb >= N: # nbがN以上になれば、終了
        break
    
    B, C = sbcs[i]
    las = nb+B-1
    las = las if las <N else N-1
    if sA[nb] >= C: # もしnb個目がC以上であれば、終了
        break
    elif sA[nb+B-1] <= C: #もしB個目が、C以下なら、B個目までをCにする
        sA[nb:nb+B] = [C]*B
        nb += B
    else: #nb個目がC未満で、nb+B-1個目がCより大きければ
        t = binary_search(sA[nb:nb+B], C) 
        t = t if nb+t < N else N-nb-1
        sA[nb:nb+t+1] = [C]*(t+1)
        nb += t+1
    
print(sum(sA))
"""


# In[ ]:
import math

a, b = map(int, input().split())  # 複数数値入力

A = list()
B = list()

for i in range(1, int(math.log2(b))+2):
    tmp = b // (2 ** i) * 2 ** (i - 1)

    if b % (2 ** i) < (2 ** (i-1)):
        plus = 0
    else:
        plus = b % (2 ** i) - 2 ** (i-1) + 1

    B.append(tmp+plus)
if a == 0:
    A = [0]
elif a == 1:
    A = [0]
else:
    for i in range(1, int(math.log2(a-1))+2):
        tmp = (a-1) // (2 ** i) * 2 ** (i - 1)

        if (a-1) % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = (a-1) % (2 ** i) - 2 ** (i-1) + 1

        A.append(tmp + plus)

ans = 0
for i in range(0, int(math.log2(b)) + 1):
    if i >= len(A):
        ans += (B[i]) % 2 * 10 ** i
    else:
        ans += (B[i] - A[i]) % 2 * 10 ** i

print(int(str(ans), 2))


### FIXED CODE ###

import math

a, b = map(int, input().split())  # 複数数値入力

A = list()
B = list()

if b == 0:
    B = [0]
elif b == 1:
    B = [1]
else:
    for i in range(1, int(math.log2(b))+2):
        tmp = b // (2 ** i) * 2 ** (i - 1)

        if b % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = b % (2 ** i) - 2 ** (i-1) + 1

        B.append(tmp + plus)

if a == 0:
    A = [0]
elif a == 1:
    A = [0]
else:
    for i in range(1, int(math.log2(a-1))+2):
        tmp = (a-1) // (2 ** i) * 2 ** (i - 1)

        if (a-1) % (2 ** i) < (2 ** (i-1)):
            plus = 0
        else:
            plus = (a-1) % (2 ** i) - 2 ** (i-1) + 1

        A.append(tmp + plus)

if b == 0:
    print(0)
else:
    ans = 0
    for i in range(0, int(math.log2(b)) + 1):
        if i >= len(A):
            ans += (B[i]) % 2 * 10 ** i
        else:
            ans += (B[i] - A[i]) % 2 * 10 ** i

    print(int(str(ans), 2))
k = int(input())
list = list(map(int, input().split()))
if list[1] > list[0]+k:
  print("OK")
elif list[0] % k == 0 or list[1] % k == 0:
else:
  print("NG")

### FIXED CODE ###

k = int(input())
list = list(map(int, input().split()))
a = list[0]
b = list[1]
for i in range(a,b+1):
  if i % k ==0:
    print("OK")
    break
  if i==b:
    print("NG")
x = int(input())

if x == 0:
    prine(1)
else:
    print(0)


### FIXED CODE ###

x = int(input())

if x == 0:
    print(1)
else:
    print(0)
import numpy as np

N = int(input())
H = [ int(s) for s in str(input()).split()]
dp = np.full(10**5 + 10, np.inf)
dp[0] = 0

def rec(i):
    if dp[i] < np.inf:
        return dp[i]
    
    if i==0:
        return 0
    
    res = np.inf
    res = min(res, rec(i-1) + abs(H[i] -H[i-1]))
    if i > 1:
        res = min(res, rec(i-2) + abs(H[i] - H[i-2]))
    
    dp[i] = res
    return res

def main3():
    print(int(rec(N-1)))
    
if __name__ == '__main__':
    main3()

### FIXED CODE ###

import numpy as np

N = int(input())
H = [ int(s) for s in str(input()).split()]
dp = np.full(10**5 + 10, np.inf)

def rec(i):
    if dp[i] < np.inf:
        return dp[i]
    
    if i==0:
        return 0
    
    res = np.inf
    res = min(res, rec(i-1) + abs(H[i] -H[i-1]))
    if i > 1:
        res = min(res, rec(i-2) + abs(H[i] - H[i-2]))
    
    dp[i] = res
    return res

def main3():
    print(int(rec(N-1)))

def main2():
    dp = np.full(10**5 + 10, np.inf)
    dp[0] = 0
    
    for i in range(0, N):
        if i+1 < N:
            dp[i+1] = min(dp[i+1], dp[i] + abs(H[i] - H[i+1]))
        if i+2 < N:
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i] - H[i+2]))
    
    print(int(dp[N-1]))
    
if __name__ == '__main__':
    main2()
n=int(input())
N=[0]*(n+1)
result=0
for i in range(1,n+1):
  N[i]=i
for i in range(2,len(N)):
  result+=N[i-1]%N[i]
print(result)

### FIXED CODE ###

n=int(input());print(n*(n-1)//2)
N = int(input())
A = list(map(int,input().split()))

S = sum(map(abs,A))

if all([a>0 for a in A]):
    print(S-2*min(A))
    A = sorted(A)
    B = [A[0]]
    for i in range(1,N):
        B.append(B[-1]-A[i])
    for i in range(N-2):
        print(B[i],A[i+1])
    print(A[N-1],B[N-2])

elif all([a<0 for a in A]):
    print(S+2*max(A))
    A = sorted(A)
    B = [A[-1]]
    for i in range(N-1):
        B.append(B[-1]-A[i])
    for i in range(N-1):
        print(B[i],A[i])

else:
    print(S)
    A = sorted(A)
    B = [A[0]]
    for i in range(N):
        if A[-2-i]<0:
            print(A[-1-i],B[-1])
            B.append(A[-1-i]-B[-1])
            break
        print(B[-1],A[-1-i])
        B.append(B[-1]-A[-1-i])
    C = [B[-1]]
    for i in range(1,N):
        if A[i]>=0:
            break
        print(C[-1],A[i])
        C.append(C[-1]-A[i])

### FIXED CODE ###

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

S = sum(map(abs,A))

if all([a>0 for a in A]):
    print(S-2*min(A))
    A = sorted(A)
    B = [A[0]]
    for i in range(1,N):
        B.append(B[-1]-A[i])
    for i in range(N-2):
        print(B[i],A[i+1])
    print(A[N-1],B[N-2])

elif all([a<0 for a in A]):
    print(S+2*max(A))
    A = sorted(A)
    B = [A[-1]]
    for i in range(N-1):
        B.append(B[-1]-A[i])
    for i in range(N-1):
        print(B[i],A[i])

else:
    print(S)
    A = sorted(A)
    B = [A[0]]
    for i in range(N):
        if N-1-2-i<0 or A[-2-i]<0:
            print(A[-1-i],B[-1])
            B.append(A[-1-i]-B[-1])
            break
        print(B[-1],A[-1-i])
        B.append(B[-1]-A[-1-i])
    C = [B[-1]]
    for i in range(1,N):
        if A[i]>=0:
            break
        print(C[-1],A[i])
        C.append(C[-1]-A[i])
import sys

n = int(input())
s = input()
if n == 1:
  print("No")
  sys.exit()
n = n / 2
if s[:n]  == s[n:]:
    print("Yes")
else:
    print ("No")

### FIXED CODE ###

import sys

n = int(input())
s = input()
if n == 1:
  print("No")
  sys.exit()
n = n // 2
if s[:n]  == s[n:]:
    print("Yes")
else:
    print ("No")
#入力
N = int(input())
lst = input().split()

#整数値化
for i in range(len(lst)):
   lst[i] = int(lst[i])

#ソート
lst.sort()

#コスト計算関数
def get_cost(x, y):
   return (x - y) ** 2

costs = []

#コスト計算
for i in range(lst[0], lst[-1]): #入力値の最小値から最大値まで
   cost = 0
   for j in lst:
      cost = cost + get_cost(j, i)
   costs.append(cost)

#ソート
costs.sort()

#最小コストを出力
print(costs[0])

### FIXED CODE ###

#入力
N = int(input())
lst = input().split()

#整数値化
for i in range(len(lst)):
   lst[i] = int(lst[i])

#ソート
lst.sort()

#コスト計算関数
def get_cost(x, y):
   return (x - y) ** 2

costs = []

#コスト計算
for i in range(lst[0], lst[-1]): #入力値の最小値から最大値まで
   cost = 0
   for j in lst:
      cost = cost + get_cost(j, i)
   costs.append(cost)

#ソート
costs.sort()

#最小コストを出力
#入力値が全て同じとき最小も最大も同じなのでfor文の中のやつは1回も実行されない
#つまりcostsリストが空なのでcosts[0]が存在しない
if costs != []:
   print(costs[0])
else:
   print(0)
array = list(map(int, input().strip().split()))
n = array[0]
max = 0
t = len(array)
t = t-1
backup = 0

for i in range(n):
    backup = array[i+1]
    array[i+1] = 0

    for j in range(t):
        if(array[j+1] > max):
            max = array[j+1]      

    print(array)
    print(max)
    max = 0
    array[i+1] = backup


### FIXED CODE ###

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

a_sort = sorted(set(a))

max_val_1 = a_sort[-1]
max_total_1 = a.count(max_val_1)

if len(a_sort) >= 2:
    max_val_2 = a_sort[-2]

#print("max val:{}".format(max_val_1))
#print("max total:{}".format(max_total_1))

for i in range(n):
    if max_total_1 >=2:
        print(max_val_1)
    
    elif a[i] < max_val_1:
        print(max_val_1)

    elif a[i] == max_val_1 and max_total_1 == 1:
        print(max_val_2)
    else:
        print("err")
N,X=map(int,input().split())
for x in range(N+1):
    for y in range(N+1-y):
        z=N-x-y
        if 10000*x+5000*y+1000*z==X:
            print(x,y,z)
            exit()
print(-1,-1,-1)
        

### FIXED CODE ###

N,X=map(int,input().split())
for x in range(N+1):
    for y in range(N+1-x):
        z=N-x-y
        if ((10000*x+5000*y+1000*z==X)and(0<=z)):
            print(x,y,z)
            exit()
print(-1,-1,-1)