There are $n$ slimes in a row. Each slime has an integer value (possibly negative or zero) associated with it.

Any slime can eat its adjacent slime (the closest slime to its left or to its right, assuming that this slime exists). 

When a slime with a value $x$ eats a slime with a value $y$, the eaten slime disappears, and the value of the remaining slime changes to $x - y$.

The slimes will eat each other until there is only one slime left. 

Find the maximum possible value of the last slime.


-----Input-----

The first line of the input contains an integer $n$ ($1 \le n \le 500\,000$) denoting the number of slimes.

The next line contains $n$ integers $a_i$ ($-10^9 \le a_i \le 10^9$), where $a_i$ is the value of $i$-th slime.


-----Output-----

Print an only integer — the maximum possible value of the last slime.


-----Examples-----
Input
4
2 1 2 1

Output
4
Input
5
0 -1 -1 -1 -1

Output
4


-----Note-----

In the first example, a possible way of getting the last slime with value $4$ is:

  Second slime eats the third slime, the row now contains slimes $2, -1, 1$

 Second slime eats the third slime, the row now contains slimes $2, -2$

 First slime eats the second slime, the row now contains $4$ 

In the second example, the first slime can keep eating slimes to its right to end up with a value of $4$.

Difficulty: MEDIUM_HARD
Tags: Dynamic programming

Implementation

Greedy algorithms
Skill types: Dynamic programming

Greedy algorithms
Expected Time Complexity: O(N)

Starter code:

Solutions:
import sys
import os

def solve(slimes):
	if len(slimes) == 1:
		return slimes[0]
	havePos = False
	haveNeg = False
	for s in slimes:
		if s > 0:
			havePos = True
		elif s < 0:
			haveNeg = True
	if havePos and haveNeg:
		return sum(map(abs, slimes))
	elif not havePos:
		m = max(slimes)
		return sum(list(map(abs, slimes))) + 2 * m
	elif not haveNeg:
		m = min(slimes)
		return sum(list(map(abs, slimes))) - 2 * m
	else:
		return 0

def main():
	n = int(input())
	slimes = list(map(int, input().split()))
	print(solve(slimes))

def __starting_point():
	main()
__starting_point()


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
else:
	(p, e) = (0, 0)
	for i in range(n):
		if a[i] >= 0:
			p = p + 1
		else:
			e = e + 1
	if p > 0 and e > 0:
		ans = 0
		for i in range(n):
			ans = ans + abs(a[i])
		print(ans)
	else:
		d = -2 * 10 ** 9
		ans = abs(a[0])
		for i in range(1, n):
			ans = ans + abs(a[i])
			if d < abs(a[i] - a[i - 1]) - (abs(a[i]) + abs(a[i - 1])):
				d = abs(a[i] - a[i - 1]) - (abs(a[i]) + abs(a[i - 1]))
		ans = ans + d
		print(ans)


def f(a):
	if len(a) == 1:
		return a[0]
	pos = 0
	neg = 0
	ans = 0
	a = sorted(a)
	for i in a[1:len(a) - 1]:
		ans += abs(i)
	ans -= a[0]
	ans += a[-1]
	return ans
s = input()
a = list(map(int, input().strip().split()))
print(f(a))


import sys

def input():
	return sys.stdin.readline().rstrip()

def slv():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		return
	elif all((a[i] <= 0 for i in range(n))):
		minabs = 1 << 128
		s = 0
		for v in a:
			minabs = min(minabs, abs(v))
			s += abs(v)
		print(s - 2 * minabs)
	elif all((a[i] >= 0 for i in range(n))):
		minabs = 1 << 128
		s = 0
		for v in a:
			minabs = min(minabs, abs(v))
			s += abs(v)
		print(s - 2 * minabs)
	else:
		ans = sum((abs(v) for v in a))
		print(ans)
	return

def main():
	t = 1
	for i in range(t):
		slv()
	return
main()


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	import numpy

	def dprint(*args, **kwargs):
		print(*args, **kwargs, file=sys.stderr)
	dprint('debug mode')
except ModuleNotFoundError:

	def dprint(*args, **kwargs):
		pass
inId = 0
outId = 0
if inId > 0:
	dprint('use input', inId)
	sys.stdin = open('input' + str(inId) + '.txt', 'r')
if outId > 0:
	dprint('use output', outId)
	sys.stdout = open('stdout' + str(outId) + '.txt', 'w')
	atexit.register(lambda : sys.stdout.close())
(N,) = getIntList()
za = getIntList()
if N == 1:
	print(za[0])
	return
t1 = max(za)
t2 = min(za)
if t2 >= 0:
	print(sum(za) - 2 * t2)
	return
if t1 <= 0:
	print(2 * t1 - sum(za))
	return
res = 0
for x in za:
	res += abs(x)
print(res)


import sys, math
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
if n == 1:
	print(sum(a))
else:
	minn = 10 ** 9
	neg = 0
	pos = 0
	ans = 0
	for i in range(n):
		minn = min(minn, abs(a[i]))
		if a[i] >= 0:
			pos += 1
		if a[i] <= 0:
			neg += 1
		ans += abs(a[i])
	if pos > 0 and neg > 0:
		print(ans)
	else:
		print(ans - 2 * minn)


tot = int(input())
arr = [int(x) for x in input().split()]
(n, p, z) = (0, 0, 0)
for i in arr:
	if i > 0:
		p += 1
	elif i < 0:
		n += 1
	else:
		z += 1
ans = 0
for i in arr:
	ans += abs(i)
if tot == 1:
	print(arr[0])
elif p == 0 or n == 0:
	mi = min(arr)
	if mi < 0:
		mi = max(arr)
	if mi > 0:
		print(ans - 2 * mi)
	else:
		print(ans + 2 * mi)
else:
	print(ans)


N = int(input())
A = [int(x) for x in input().split()]
B = [abs(x) for x in A]
if N == 1:
	print(A[0])
	exit(0)
s = sum(B)
if any((x >= 0 for x in A)) and any((x <= 0 for x in A)):
	print(s)
else:
	print(s - 2 * min(B))


import sys
n = int(input())
l = list(map(int, input().split()))
f = 0
f1 = 0
ans = 0
if n == 1:
	print(l[0])
	sys.exit()
for i in range(n):
	if l[i] <= 0:
		f = 1
		ans += abs(l[i])
	else:
		f1 = 1
if f == 1:
	ans = sum(l) + 2 * ans
	if f1 == 0:
		ans -= abs(max(l) * 2)
	print(ans)
else:
	ans = -999999999999999999999999999999999
	for i in range(1, n):
		ans = max(-2 * min(l[i], l[i - 1]), ans)
	ans = sum(l) + ans
	print(ans)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit(0)
(hasp, hasn) = (False, False)
for aa in a:
	hasp = hasp or aa > 0
	hasn = hasn or aa < 0
if hasn and hasp:
	print(sum(list(map(abs, a))))
elif hasn or hasp:
	print(sum(list(map(abs, a))) - 2 * min(list(map(abs, a))))
else:
	print(0)


n = int(input())
arr = list(map(int, input().split()))
sum = 0
for i in range(n):
	sum += abs(arr[i])
ans = 0
if n == 1:
	print(arr[0])
else:
	for i in range(n - 1):
		ans = max(ans, sum - abs(arr[i]) - abs(arr[i + 1]) + abs(arr[i] - arr[i + 1]))
	print(ans)


n = int(input())
a = [int(el) for el in input().split()]
a.sort()
kotr = 0
k0 = 0
for i in a:
	if i < 0:
		kotr += 1
	elif i == 0:
		k0 += 1
if n == 1:
	print(a[0])
	raise SystemExit
if n == 2:
	print(abs(a[0] - a[1]))
	raise SystemExit
if kotr == n:
	out = a[n - 1]
	for i in range(n - 1):
		out = out + abs(a[i])
else:
	out = -a[0]
	for i in range(1, n):
		out = out + abs(a[i])
print(out)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
a.sort()
if a[0] < 0 and a[n - 1] >= 0:
	suma = 0
	for i in range(n):
		suma += abs(a[i])
	print(suma)
	exit()
suma = 0
mina = 9999999999
for i in range(n):
	suma += abs(a[i])
	mina = min(mina, abs(a[i]))
print(suma - 2 * mina)


import sys, os
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
from itertools import permutations
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
MOD = 10 ** 9 + 7
dic = defaultdict(int)

def f(n):
	if n in dic:
		return dic[n]
	if n < 5:
		return n
	if n // 2 + n // 3 + n // 4 <= n:
		return n
	ans = f(n // 2) + f(n // 3) + f(n // 4)
	dic[n] = ans
	return ans

def main():
	n = int(input())
	arr = read()
	(x, y) = (0, 0)
	(s, r) = (0, 0)
	ans = 0
	for i in range(n):
		x += arr[i] < 0
		y += arr[i] >= 0
		s += abs(arr[i])
		r += arr[i]
		arr[i] = abs(arr[i])
	if x + y == 1:
		print(r)
	elif x == n or y == n:
		for i in range(n - 1):
			(a, b) = (arr[i], arr[i + 1])
			ans = max(ans, s - abs(a + b) + abs(a - b))
		print(ans)
	else:
		print(s)
main()


n = int(input())
arr = [int(x) for x in input().split()]
if n == 1:
	print(arr[0])
	exit()
sum = sum((abs(x) for x in arr))
if not any((x < 0 for x in arr)):
	sum = sum - 2 * min(arr)
if not any((x >= 0 for x in arr)):
	sum = sum - 2 * abs(max(arr))
print(sum)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(sum(a))
	return
mn = min(a)
mx = max(a)
s = 0
for i in a:
	s += abs(i)
print(s - abs(mn) - abs(mx) + mx - mn)


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n != 1:
	total = a[0]
	for i in range(1, n - 1):
		if total < 0 and a[i] < 0:
			total += a[i]
		else:
			total = min(total - a[i], a[i] - total)
	print(max(total - a[n - 1], a[n - 1] - total))
else:
	print(a[0])


n = int(input())
ans = 0
i = 0
l = list(map(int, input().split()))
t = 0
if n == 1:
	print(l[0])
else:
	while i < n:
		if l[i] >= 0:
			c = 0
			t += 1
			while l[i] >= 0:
				c += l[i]
				i += 1
				if i == n:
					break
			ans += c
		else:
			c = 0
			t += 1
			while l[i] < 0:
				c -= l[i]
				i += 1
				if i == n:
					break
			ans += c
	if t > 1:
		print(ans)
	elif l[0] >= 0:
		print(ans - 2 * min(l))
	else:
		print(ans + 2 * max(l))


def abs_sum(lis):
	ans = 0
	for item in lis:
		ans += abs(item)
	return ans
import sys
n = int(input())
lis = [int(x) for x in input().split()]
if n == 1:
	print(lis[0])
	sys.exit()
a = abs_sum(lis)
b = sum(lis)
if a != b and a != -b:
	print(a)
elif b >= 0:
	minn = min(lis)
	print(a - 2 * minn)
else:
	maxx = max(lis)
	print(a + 2 * maxx)


if input() == '1':
	print(input())
else:
	(x, *a, y) = sorted(map(int, input().split()))
	print(y - x + sum(map(abs, a)))


n = int(input())
H = list(map(int, input().split()))
d = 0
f = 0
m = 10 ** 9 + 7
if n > 1:
	for i in range(n):
		if H[i] < 0:
			f += 1
		d += abs(H[i])
		if abs(H[i]) < m:
			m = abs(H[i])
	if f == 0 or f == n:
		print(d - m * 2)
	else:
		print(d)
else:
	print(H[0])


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
(m, M) = (min(a), max(a))
if m >= 0:
	print(sum(a) - 2 * m)
elif M < 0:
	print(-sum(a) + 2 * M)
else:
	print(sum((abs(ai) for ai in a)))


n = int(input())
a = list(map(int, input().split()))
a.sort()
if n == 1:
	print(a[0])
else:
	i = 0
	while i < n and a[i] <= 0:
		i += 1
	if i == 0:
		print(sum(a) - 2 * a[0])
	elif i == n:
		print(2 * a[-1] - sum(a))
	else:
		print(sum(a[i:]) - sum(a[:i]))


from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def main():
	n = ii()
	a = li()
	if n == 1:
		print(a[0])
		exit(0)
	pos = 0
	ans = 0
	neg = 0
	minv = 1000000000.0 + 7
	for i in a:
		if i < 0:
			neg = 1
		else:
			pos = 1
		minv = min(minv, abs(i))
		ans += abs(i)
	if pos and neg:
		print(ans)
	else:
		print(ans - 2 * minv)
main()


from math import inf as inf
from math import *
from collections import *
import sys
input = sys.stdin.readline
t = 1
while t:
	t -= 1
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
		exit(0)
	(p, n1) = (0, 0)
	s = 0
	m = float('inf')
	for i in a:
		if i >= 0:
			p = 1
		if i < 0:
			n1 = 1
		s += abs(i)
		m = min(m, abs(i))
	if p and n1:
		print(s)
	else:
		print(s - 2 * m)


n = int(input())
x = [int(x) for x in input().split()]
result = 0
i = 1
j = n - 2
k = 0
l = 0
x.sort()

def check(x):
	a = 0
	for i in range(0, n):
		if x[i] >= 0:
			a = x[i]
			return a
if x[0] < 0 and x[n - 1] <= 0:
	result = x[n - 1]
	while j >= 0:
		result = result - x[j]
		j -= 1
elif x[0] < 0 and x[n - 1] >= 0:
	result = check(x)
	k = x.index(result)
	while k != 0:
		result = result - x[k - 1]
		k -= 1
	x.append(result)
	k = x.index(check(x))
	while k != n:
		l = l - x[k + 1]
		k += 1
	result = abs(l)
else:
	result = x[0]
	while i <= n - 1:
		result = result - x[i]
		i += 1
	result = abs(result)
print(result)


def solve(a):
	if len(a) == 1:
		return a[0]
	if max(a) < 0:
		return 2 * max(a) - sum(a)
	elif min(a) >= 0:
		return sum(a) - 2 * min(a)
	else:
		return sum((abs(x) for x in a))
n = int(input())
a = list(map(int, input().split()))
print(solve(a))


import sys
n = int(input())
A = list(map(int, input().split()))
if n == 1:
	print(A[0])
	sys.exit(0)
suma = 0
mine = 1000000001
d = False
for i in range(0, n):
	mine = min(mine, abs(A[i]))
	suma += abs(A[i])
	if i > 0 and (A[i] >= 0 and A[i - 1] < 0 or (A[i] < 0 and A[i - 1] >= 0)):
		d = True
if d:
	print(suma)
else:
	print(suma - 2 * mine)


N = int(input())
slimes = [int(s) for s in input().split()]
all_same = True
for i in range(N - 1):
	if (slimes[i] > 0) != (slimes[i + 1] > 0):
		all_same = False
if N == 1:
	print(slimes[0])
else:
	slimes = [abs(x) for x in slimes]
	print(sum(slimes) - (2 * min(slimes) if all_same else 0))


n = int(input())
lis = [int(x) for x in input().split()]
total = 0
l_negative = -1000000000000
s_positive = 1000000000000
for i in lis:
	if i <= 0:
		l_negative = max(l_negative, i)
	if i >= 0:
		s_positive = min(s_positive, i)
	total += abs(i)
if l_negative == -1000000000000:
	total -= 2 * s_positive
if s_positive == 1000000000000:
	total += 2 * l_negative
if n == 1:
	print(lis[0])
else:
	print(total)


import sys
import math as mt
input = sys.stdin.buffer.readline
t = 1
for ___ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	suma = 0
	(pos, neg) = (0, 0)
	for i in range(n):
		if l[i] >= 0:
			pos = 1
		else:
			neg = 1
		suma += abs(l[i])
	if pos & neg:
		print(suma)
	else:
		ans = 0
		for i in range(1, n):
			sub = abs(l[i]) + abs(l[i - 1])
			diff = abs(l[i]) - abs(l[i - 1])
			compare = suma + abs(diff) - sub
			if compare > ans:
				ans = compare
		if n == 1:
			if l[0] < 0:
				suma = l[0]
			print(suma)
		else:
			print(ans)


n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(arr[0])
else:
	brr = [abs(i) for i in arr]
	fl = False
	for i in range(n - 1):
		if arr[i] * arr[i + 1] < 0:
			fl = True
	if not fl:
		print(sum(brr) - 2 * min(brr))
	else:
		print(sum(brr))


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
import math as mt
MAXN = int(10000000.0 + 1)
spf = [0 for i in range(MAXN)]

def sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, mt.ceil(mt.sqrt(MAXN))):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def getFactorization(x):
	ret = 0
	while x != 1:
		k = spf[x]
		ret += 1
		while x % k == 0:
			x //= k
	return ret
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

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

def lcm(a, b):
	return a * b / gcd(a, b)

def totalPrimeFactors(n):
	count = 0
	if n % 2 == 0:
		count += 1
		while n % 2 == 0:
			n //= 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			count += 1
			while n % i == 0:
				n //= i
		i += 2
	if n > 2:
		count += 1
	return count

def countPairs(G, L):
	if L % G != 0:
		return 0
	div = int(L / G)
	return 1 << getFactorization(div)

def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	if n == 1:
		print(a[0])
		return
	if a[0] >= 0:
		print(sum(a) - 2 * a[0])
	elif a[-1] <= 0:
		print(-1 * sum(a) + 2 * a[-1])
	else:
		ans = 0
		for i in a:
			ans += abs(i)
		print(ans)
	return
main()


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
elif all((ele > 0 for ele in a)):
	s = sum(a) - 2 * min(a)
	print(s)
elif all((ele < 0 for ele in a)):
	s = abs(sum(a)) - 2 * abs(max(a))
	print(s)
else:
	ans = 0
	for ele in a:
		ans += abs(ele)
	print(ans)


n = int(input())
a = list(map(int, input().split()))
a.sort()
x = 0
y = 0
s = 0
if n == 1:
	print(a[0])
	exit(0)
for i in a:
	if i > 0:
		x += 1
	if i < 0:
		y += 1
	s = s + abs(i)
if x == n or y == n:
	if x == n:
		print(s - 2 * a[0])
	if y == n:
		print(s + 2 * a[n - 1])
else:
	print(s)


n = int(input())
l = list(map(int, input().split()))
fl = 0
f = 0
s = 0
for i in l:
	if i <= 0:
		fl = 1
	if i >= 0:
		f = 1
	s = s + abs(i)
x = min(l)
y = max(l)
if n == 1:
	print(l[0])
elif f == 1 and fl == 1:
	print(s)
elif fl == 1:
	print(s - 2 * abs(y))
else:
	print(s - 2 * x)


from collections import *
n = int(input())
l = [*map(int, input().split())]
flag = False
flag1 = False
if n == 1:
	print(l[0])
	exit()
for i in range(n):
	if l[i] <= 0:
		flag = True
	if l[i] >= 0:
		flag1 = True
if flag and flag1:
	total = 0
	for i in range(n):
		total += abs(l[i])
	print(total)
elif not flag and flag1:
	print(sum(l) - 2 * min(l))
else:
	print(-sum(l) + 2 * max(l))


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
if min(a) > 0:
	print(sum(a) - 2 * min(a))
elif max(a) < 0:
	print(-sum(a) + 2 * max(a))
else:
	x = 0
	for i in range(n):
		x += abs(a[i])
	print(x)


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
else:
	minval = 10000000000.0
	ans = 0
	checkpos = False
	checkneg = False
	for i in range(n):
		minval = min(abs(a[i]), minval)
		if a[i] >= 0:
			checkpos = True
		elif a[i] <= 0:
			checkneg = True
		ans += abs(a[i])
	if checkpos and checkneg:
		print(ans)
	else:
		print(ans - 2 * minval)


import sys
from sys import stdout
input = lambda : sys.stdin.readline().strip()
P = lambda : list(map(int, input().split()))
from math import factorial as f, gcd, ceil
from collections import deque, defaultdict as dd, Counter as C
from heapq import heapify, heappop, heappush, heappushpop, heapreplace, merge
from random import randint, choice, sample
from operator import itemgetter as ig, attrgetter as ag, methodcaller as mc
import time
mod = 10 ** 9 + 7
a = ord('a')

class FT:

	def __init__(self, N):
		self.ft = [0] * (N + 1)
		self.N = N

	def ls(self, x):
		return x & -x

	def fenwick_update(self, p, v):
		while p <= self.N:
			self.ft[p] += v
			p += self.ls(p)

	def fenwick_query(self, p):
		s = 0
		while p:
			s += self.ft[p]
			p -= self.ls(p)
		return s
start = time.time()

def fast_exp(x, exp):
	ans = 1
	base = x
	while exp:
		if exp & 1:
			ans *= base
		base *= base
		base %= mod
		ans %= mod
		exp >>= 1
	return ans

def countBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count

def submasks(n):
	org = n
	while n:
		yield n
		n = n - 1 & org

def solve():
	n = int(input())
	l = P()
	if n == 1:
		return l[0]
	elif any((i > 0 for i in l)) and any((i < 0 for i in l)):
		return sum(map(abs, l))
	else:
		return sum(map(abs, l)) - 2 * min(map(abs, l))
print(solve())


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
elif max(a) < 0:
	ans = -sum(a)
	ans += 2 * max(a)
	print(ans)
elif min(a) > 0:
	ans = sum(a)
	ans -= 2 * min(a)
	print(ans)
else:
	sum1 = 0
	for i in range(n):
		sum1 += abs(a[i])
	print(sum1)


n = int(input())
a = list(map(int, input().split()))
mina = abs(a[0])
summ = 0
okeye = False
mosbat = 0
for adad in a:
	if abs(adad) < mina:
		mina = abs(adad)
	summ += abs(adad)
	if adad == 0:
		okeye = True
	elif adad > 0:
		mosbat += 1
if n == 1:
	print(a[0])
elif okeye or 0 < mosbat < n:
	print(summ)
else:
	print(summ - 2 * mina)


n = int(input())
x = list(map(int, input().split()))
(ans, mi) = (0, 1234567654321)
for i in range(n):
	ans += abs(x[i])
	if i > 0:
		mi = min(mi, abs(x[i]) + abs(x[i - 1]) - abs(x[i] - x[i - 1]))
if n == 1:
	print(x[i])
else:
	print(ans - mi)


n = int(input())
if n == 1:
	a = input()
	print(a)
else:
	a = list(map(int, input().split()))
	b = [abs(i) for i in a]
	if min(a) * max(a) > 0:
		print(sum(b) - 2 * min(b))
	else:
		print(sum(b))


n = int(input())
if n == 1:
	print(input())
else:
	a = [int(x) for x in input().split()]
	b = [abs(x) for x in a]
	if min(a) >= 0:
		print(sum(b) - 2 * min(a))
	elif max(a) <= 0:
		print(sum(b) + 2 * max(a))
	else:
		print(sum(b))


def mi():
	return map(int, input().split())
n = int(input())
a = list(mi())
(cp, cn) = (0, 0)
for i in a:
	if i >= 0:
		cp += 1
	if i <= 0:
		cn += 1
s = 0
if n == 1:
	print(a[0])
	exit(0)
for i in a:
	s += abs(i)
if cn and cp:
	print(s)
else:
	m = -1e+100
	for i in a:
		m = max(m, s - 2 * abs(i))
	print(m)


n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
mx = max(a)
mn = min(a)
s = 0
if n == 1:
	print(a[0])
	exit()
for i in range(1, n - 1):
	s += abs(a[i])
print(s + mx - mn)


n = int(input())
arr = [int(x) for x in input().split()]
if n == 1:
	print(arr[0])
else:
	allpos = True
	allneg = True
	for i in arr:
		if i > 0:
			allneg = False
		elif i < 0:
			allpos = False
	if allpos:
		print(sum(arr) - min(arr) * 2)
	elif allneg:
		print(-sum(arr) - -(max(arr) * 2))
	else:
		ans = 0
		for i in arr:
			ans += abs(i)
		print(ans)


import sys, os, io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def si():
	return input()

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
t = 1
for _ in range(t):
	n = ii()
	a = li()
	if n == 1:
		print(a[0])
		continue
	mi = a.index(min(a))
	a1 = [abs(i) for i in a]
	if min(a) >= 0 and a == a1:
		print(sum(a) - a[mi] - a[mi])
	elif max(a) < 0:
		print(sum(a1) - 2 * min(a1))
	else:
		print(sum(a1))


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
ans = sum(map(abs, a))
pos = sum((x > 0 for x in a))
neg = n - pos
if pos == n:
	ans -= min(a) * 2
if neg == n:
	ans += max(a) * 2
print(ans)


n = int(input())
x = 0
cp = 0
cn = 0
a = [int(i) for i in input().split()]
sum1 = 0
for i in range(n):
	sum1 += abs(a[i])
	if i == 0:
		x = abs(a[i])
	else:
		x = min(x, abs(a[i]))
	if a[i] > 0:
		cp = 1
	elif a[i] < 0:
		cn = 1
	else:
		cp = 1
		cn = 1
if n == 1:
	print(a[0])
elif cp == 1 and cn == 1:
	print(sum1)
else:
	print(sum1 - 2 * x)


n = int(input())
q = d = 0
p = False
ar = list(map(int, input().split()))
min = 10000000000
r = max(ar)
for i in ar:
	if i >= 0:
		if i < min:
			min = i
		q += i
	else:
		p = True
		d += -i
if r >= 0:
	if p:
		max = q + d
	else:
		max = q - min - min
else:
	max = d + r + r
if len(ar) == 1:
	print(ar[0])
else:
	print(max)


import math
n = int(input())
arr = list(map(int, input().split()))
cp = 0
cn = 0
for i in range(len(arr)):
	if arr[i] >= 0:
		cp += 1
	else:
		cn += 1
b = []
for i in range(len(arr)):
	b.append(abs(arr[i]))
m = min(b)
if n == 1:
	print(arr[0])
elif cp > 0 and cn > 0:
	print(sum(b))
else:
	nrt = 2 * min(b)
	print(sum(b) - nrt)


from math import *
from collections import *
import sys
sys.setrecursionlimit(10 ** 9)
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
else:
	ans = 0
	for i in range(n):
		ans += abs(a[i])
	m = max(a)
	if m < 0:
		ans += 2 * m
	m = min(a)
	if m > 0:
		ans -= 2 * m
	print(ans)


from collections import Counter, defaultdict, deque
get = lambda : int(input())
read = lambda : list(map(int, input().split()))
mod = 10 ** 9 + 7
inf = float('inf')
n = get()
a = read()
if n == 1:
	print(a[0])
elif all((a[i] > 0 for i in range(n))):
	print(sum(a) - 2 * min(a))
elif all((a[i] < 0 for i in range(n))):
	print(-sum(a) + 2 * max(a))
else:
	res = 0
	for i in range(n):
		res += abs(a[i])
	print(res)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit(0)
min_idx = 0
min_res = a[0]
max_idx = 0
max_res = a[0]
for i in range(1, n):
	if a[i] < min_res:
		(min_idx, min_res) = (i, a[i])
	if a[i] > max_res:
		(max_idx, max_res) = (i, a[i])
res = 0
for i in range(n):
	if i != min_idx and i != max_idx:
		res += abs(a[i])
if min_res == max_res:
	res -= abs(min_res)
print(max_res + res - min_res)


import math
from decimal import *
getcontext().prec = 30
n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	quit()
ans = 0
neg = 0
pos = 0
i = 0
for val in a:
	ans += abs(val)
	if val < 0:
		neg += 1
		a[i] *= -1
	else:
		pos += 1
	i += 1
if neg == n or pos == n:
	ans -= abs(min(a)) * 2
print(ans)


import sys
input = sys.stdin.readline
n = int(input())
ar = list(map(int, input().split()))
if n == 1:
	print(ar[0])
elif n == 2:
	print(abs(ar[0] - ar[1]))
else:
	flag = False
	for i in range(1, n):
		if ar[i] * ar[i - 1] <= 0:
			flag = True
			break
	if flag:
		ans = 0
		for i in range(n):
			ans += abs(ar[i])
		print(ans)
	else:
		mi = float('inf')
		ans = 0
		for i in range(n):
			mi = min(mi, abs(ar[i]))
			ans += abs(ar[i])
		print(abs(ans - mi * 2))


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
dp = [[[0, 0], [0, 0]] for i in range(n + 1)]
dp[1][0][1] = -a[0]
dp[1][1][0] = a[0]
dp[1][1][1] = -10 ** 18
for i in range(2, n + 1):
	dp[i][0][1] = -a[i - 1] + dp[i - 1][0][1]
	dp[i][1][0] = a[i - 1] + dp[i - 1][1][0]
	dp[i][1][1] = max(a[i - 1] + dp[i - 1][0][1], -a[i - 1] + dp[i - 1][1][0], a[i - 1] + dp[i - 1][1][1], -a[i - 1] + dp[i - 1][1][1])
print(dp[-1][1][1])


n = int(input())
l = list(map(int, input().split()))
if n == 1:
	print(l[0])
	exit(0)
pos = 0
neg = 0
for i in l:
	if i >= 0:
		pos -= -1
	else:
		neg -= -1
if neg > 0 and pos > 0:
	sm = 0
	for i in l:
		sm += abs(i)
	print(sm)
elif neg == 0:
	print(sum(l) - 2 * min(l))
else:
	print(abs(sum(l)) - 2 * abs(max(l)))


n = int(input())
a = [int(i) for i in input().split()]
if n == 1:
	print(a[0])
	exit()
(mx, mxi) = (-10 ** 10, -1)
(mn, mni) = (10 ** 10, -1)
for i in range(n):
	if a[i] > mx:
		(mx, mxi) = (a[i], i)
	if a[i] < mn:
		(mn, mni) = (a[i], i)
if mn < 0:
	if mx < 0:
		print(-sum(a) + 2 * mx)
	else:
		print(sum([abs(i) for i in a]))
else:
	print(sum(a) - 2 * mn)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
else:
	prod_minus = False
	for i in range(n - 1):
		if a[i] * a[i + 1] <= 0:
			prod_minus = True
			break
	Min_abs = float('inf')
	Sum = 0
	for num in a:
		Sum += abs(num)
		if abs(num) < Min_abs:
			Min_abs = abs(num)
	if prod_minus:
		print(Sum)
	else:
		print(Sum - 2 * Min_abs)


n = int(input())
a = list(map(int, input().split()))
a.sort()
ans = 0
ck = 0
d1 = -10000000000
d2 = 10000000000
for i in a:
	ans += abs(i)
	d1 = max(d1, i)
	d2 = min(d2, i)
	if i == 0:
		ck = 1
if ck == 1:
	print(ans)
elif n == 1:
	print(a[0])
else:
	ans -= abs(d1) + abs(d2)
	ans += abs(d1 - d2)
	print(ans)


from sys import stdin
input = lambda : stdin.readline().strip()
lin = lambda : list(map(int, input().split()))
iin = lambda : int(input())
main = lambda : map(int, input().split())
from math import ceil, sqrt, factorial, log
from collections import deque
from bisect import bisect_left

def gcd(a, b):
	(a, b) = (max(a, b), min(a, b))
	while a % b != 0:
		(a, b) = (b, a % b)
	return b
mod = 998244353

def solve():
	n = iin()
	l = lin()
	a = []
	b = []
	for i in l:
		if i >= 0:
			a.append(i)
		else:
			b.append(i)
	if n == 1:
		print(l[0])
	else:
		if len(a) == 0:
			t = max(b)
			a.append(t)
			b.remove(t)
		elif len(b) == 0:
			t = min(a)
			b.append(t)
			a.remove(t)
		print(sum(a) - sum(b))
qwe = 1
for _ in range(qwe):
	solve()


n = int(input())
l = list(map(int, input().split()))
pos = 0
neg = 0
w = []
for i in range(n):
	if l[i] >= 0:
		pos += 1
	else:
		neg += 1
	w.append(abs(l[i]))
if n == 1:
	print(l[0])
elif neg != 0 and pos == 0:
	print(sum(w) - min(w) * 2)
elif pos != 0 and neg == 0:
	print(sum(w) - min(w) * 2)
else:
	print(sum(w))


n = int(input())
a = list(map(int, input().split()))
p = 0
if n <= 1:
	print(a[0])
else:
	for j in range(n):
		if a[j] < 0:
			p += 1
	if p == 0:
		print(sum(a) - 2 * min(a))
	elif p == n:
		print(abs(sum(a)) - 2 * abs(max(a)))
	else:
		s = 0
		for j in range(n):
			s += abs(a[j])
		print(s)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
arr1 = []
arr2 = []
val1 = 0
for i in range(n - 1):
	val1 += arr[i]
	arr1.append(val1)
val1 = 0
for i in range(n - 1, 0, -1):
	val1 += arr[i]
	arr2.append(val1)
fans = -10000000000000000000000
for i in range(n - 1):
	fans = max(fans, arr2[n - 2 - i] - arr1[i])
if n == 1:
	print(arr[0])
else:
	print(fans)


from math import inf
n = int(input())
a = [int(c) for c in input().split()]
c = 0
for i in range(n):
	if a[i] >= 0:
		c += 1
if n == 1:
	print(a[0])
elif c == n:
	s = sum(a)
	m = -inf
	for i in range(1, n):
		s -= a[i] + a[i - 1]
		s += abs(a[i] - a[i - 1])
		m = max(s, m)
		s -= abs(a[i] - a[i - 1])
		s += a[i] + a[i - 1]
	print(m)
elif c == 0:
	s = abs(sum(a))
	m = -inf
	for i in range(1, n):
		s += a[i] + a[i - 1]
		s += abs(a[i] - a[i - 1])
		m = max(s, m)
		s -= abs(a[i] - a[i - 1])
		s -= a[i] + a[i - 1]
	print(m)
else:
	an = 0
	for i in range(n):
		an += abs(a[i])
	print(an)


import sys
import math
import collections
import heapq
import decimal
input = sys.stdin.readline
n = int(input())
l = [int(i) for i in input().split()]
if len(l) == 1:
	print(*l)
else:
	mi = min(l)
	ma = max(l)
	if mi >= 0:
		print(sum(l) - 2 * mi)
	elif ma <= 0:
		print(-sum(l) + 2 * ma)
	else:
		s = 0
		for i in l:
			s += abs(i)
		print(s)


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
if n == 1:
	print(a[0])
elif any((x >= 0 for x in a)) and any((x <= 0 for x in a)):
	print(sum((abs(x) for x in a)))
else:
	print(sum((abs(x) for x in a)) - 2 * min((abs(x) for x in a)))


n = int(input())
b = list(map(int, input().split()))
if n == 1:
	print(b[0])
	exit(0)
min1 = min(b)
max1 = max(b)
s = 0
for i in range(n):
	s = s + abs(b[i])
print(s + max1 - min1 - abs(max1) - abs(min1))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
a.sort()
if n == 1:
	print(a[0])
elif a[0] <= 0 and a[-1] >= 0:
	r = 0
	for i in a:
		r += abs(i)
	print(r)
elif a[0] >= 0:
	r = -a[0]
	for i in range(1, n):
		r += a[i]
	print(r)
else:
	r = a[-1]
	for i in range(n - 1):
		r -= a[i]
	print(r)


from math import ceil, sqrt

def mod_expo(n, p, m):
	result = 1
	while p != 0:
		if p % 2 == 1:
			result = result * n % m
		p //= 2
		n = n * n % m
	return result

def find_product(n, m, arr):
	product = 1
	if n <= m:
		for i in range(n):
			for j in range(i + 1, n):
				product = product * abs(arr[i] - arr[j]) % m
		return product
	return 0

def count_tables(l):
	count = 0
	l.sort()
	a = l[1] - l[0]
	b = l[2] - l[0]
	if a % 3 > 0 and a % 3 + (b - (a - a % 3)) >= 3:
		count += 1
	count += l[0] + 2 * a // 3
	return int(min(sum(l) / 3, l[0] + l[1]))

def no_vacancy(n, arr):
	hotel = {}
	for i in range(n):
		room = (i + arr[i]) % n
		if room in hotel:
			return False
		else:
			hotel[room] = 1
	return True

def find_height(n):
	return int((-1 + sqrt(1 + 8 * n)) // 2)

def find_cost(n, arr):
	return min(arr) * (n - 1)

def find_moves(n, s):
	a = 0
	b = 0
	for i in range(n):
		if s[i] == 'b':
			b += 1
		else:
			a += 1
	return min(a, b)

def ratio_function(l, b):
	P = 2 * (l + b)
	S = l * b
	return P * P / S

def find_max_val(n, slime):
	mn = pow(10, 9) + 1
	s = 0
	has_positive = False
	has_negative = False
	if n == 1:
		return slime[0]
	for i in range(n):
		if slime[i] > 0:
			has_positive = True
		elif slime[i] < 0:
			has_negative = True
		s += abs(slime[i])
		mn = min(mn, abs(slime[i]))
	if has_positive and has_negative:
		return s
	return s - 2 * mn
t = 1
while t:
	t = t - 1
	n = int(input())
	l = list(map(int, input().strip().split()))[:n]
	print(find_max_val(n, l))


n = int(input())
lis = list(map(int, input().split()))
pos = []
neg = []
for i in lis:
	if i >= 0:
		pos.append(i)
	else:
		neg.append(i)
pos.sort(reverse=True)
neg.sort(reverse=True)
if n == 1:
	print(lis[0])
	exit()
if len(pos) > 0:
	if len(neg) > 0:
		print(sum(pos) - sum(neg))
	else:
		print(sum(pos) - 2 * min(pos))
else:
	print(2 * max(neg) - sum(neg))


import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = [int(i) for i in input().split()]
mi = min(a)
ma = max(a)
b = [abs(i) for i in a]
m = min(b)
if n == 1:
	print(a[0])
elif mi <= 0 and ma >= 0:
	print(sum(b))
else:
	print(sum(b) - 2 * m)


import sys
import bisect
from collections import Counter
read_int = lambda : int(sys.stdin.readline())
read_ints = lambda : map(int, sys.stdin.readline().split())
read_int_list = lambda : list(read_ints())
read = lambda : sys.stdin.readline().strip()
read_list = lambda : sys.stdin.readline().split()

def main():
	n = read_int()
	a = read_int_list()
	if n == 1:
		print(a[0])
		return
	(ma, mi, ze) = (max(0, max(a)), min(0, min(a)), 0 in a)
	all_neg = ma == 0 and (not ze)
	all_pos = mi == 0 and (not ze)
	if all_neg:
		print(-sum(a) + 2 * max(a))
	elif all_pos:
		print(sum(a) - 2 * min(a))
	else:
		print(sum(map(abs, a)))
main()


(n, minus) = (int(input()), 100000000000000000000)
x = [int(x) for x in input().split()]
if n == 1:
	print(x[0])
	exit(0)
if min(x) > 0:
	for i in range(1, n):
		if x[i] - x[i - 1] <= 0 or x[i - 1] - x[i] <= 0:
			minus = min(minus, abs(x[i]) + abs(x[i - 1]) - abs(x[i] - x[i - 1]))
if max(x) < 0:
	for i in range(1, n):
		if x[i] - x[i - 1] >= 0 or x[i - 1] - x[i] >= 0:
			minus = min(minus, abs(x[i]) + abs(x[i - 1]) - abs(x[i] - x[i - 1]))
if min(x) <= 0 and max(x) >= 0:
	minus = 0
print(sum(map(abs, x)) - minus)


def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(mi())
n = ii()
a = li()
b = [abs(x) for x in a]
if n == 1:
	ans = a[0]
elif all((x > 0 for x in a)) or all((x < 0 for x in a)):
	b.sort()
	ans = sum(b) - 2 * b[0]
else:
	ans = sum(b)
print(ans)


N = int(input())
A = list(map(int, input().split()))
p = 0
n = 0
for i in A:
	if i >= 0:
		p += 1
	elif i < 0:
		n += 1
if N == 0:
	print(0)
elif N == 1:
	print(A[0])
elif p > 0 and n > 0:
	for i in range(N):
		if A[i] < 0:
			A[i] = -1 * A[i]
	print(sum(A))
elif p == len(A):
	x = A.index(min(A))
	if x == 0:
		print(sum(A) - 2 * A[0])
	elif x == N - 1:
		print(sum(A) - 2 * A[-1])
	else:
		print(sum(A) - 2 * min(A))
elif n == len(A):
	for i in range(N):
		A[i] = -1 * A[i]
	x = A.index(min(A))
	if x == 0:
		print(sum(A) - 2 * A[0])
	elif x == N - 1:
		print(sum(A) - 2 * A[-1])
	else:
		print(sum(A) - 2 * min(A))


n = int(input())
A = list(map(int, input().split()))
if n == 1:
	print(A[0])
elif n == 2:
	print(abs(A[0] - A[1]))
else:
	SUM = 0
	for i in range(n):
		SUM += abs(A[i])
	ANS = 0
	for i in range(n - 1):
		if ANS < SUM - abs(A[i]) - abs(A[i + 1]) + abs(A[i] - A[i + 1]):
			ANS = SUM - abs(A[i]) - abs(A[i + 1]) + abs(A[i] - A[i + 1])
	print(ANS)


n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
if n == 1:
	print(a[0])
else:
	sm = 0
	havePositive = False
	haveNegative = False
	for c in a:
		if c == 0:
			haveNegative = True
			havePositive = True
		elif c > 0:
			havePositive = True
			sm += c
		else:
			haveNegative = True
			sm -= c
	if haveNegative and havePositive:
		print(sm)
	else:
		for i in range(n):
			a[i] = abs(a[i])
		ans = sum(a)
		low = a[0]
		for c in a:
			low = min(low, c)
		print(ans - 2 * low)


n = input()
ls = [int(x) for x in input().split()]
if n == '1':
	print(ls[0])
else:
	ls = sorted(ls)
	start = ls[0]
	end = ls[-1]
	mid = ls[1:-1]
	res = end - start + sum([abs(x) for x in mid])
	print(res)


import sys
import string

def ria():
	return [int(i) for i in input().split()]
n = ria()[0]
ar = ria()
if n == 1:
	print(ar[0])
	exit(0)
onlyNegs = True
onlyPos = True
if max(ar) >= 0:
	onlyNegs = False
if min(ar) <= 0:
	onlyPos = False
if onlyNegs:
	print(abs(sum(ar)) + max(ar) * 2)
	exit(0)
if onlyPos:
	print(abs(sum(ar)) - min(ar) * 2)
	exit(0)
print(sum([abs(i) for i in ar]))


n = int(input())
l1 = list(map(int, input().split()))
x = l1[0]
flag1 = 0
flag2 = 0
ans = 0
for item in l1:
	ans += abs(item)
	if item < 0:
		flag1 = 1
	else:
		flag2 = 1
for i in range(0, n):
	l1[i] = abs(l1[i])
if flag1 == 1 and flag2 == 1:
	print(ans)
elif n != 1:
	print(sum(l1) - 2 * min(l1))
else:
	print(x)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	exit(print(*a))
(pos, neg) = (False, False)
mn = 10 ** 9 + 5
ans = 0
for i in a:
	pos |= i >= 0
	neg |= i <= 0
	ans += abs(i)
	mn = min(abs(i), mn)
if pos and neg:
	print(ans)
else:
	print(ans - 2 * mn)


n = int(input())
a = [int(x) for x in input().split(' ')]
if len(a) == 1:
	print(a[0])
	exit()
a.sort()
if all((x > 0 for x in a)):
	print(sum(a) - a[0] * 2)
	exit()
if all((x < 0 for x in a)):
	print(-sum(a) + a[-1] * 2)
	exit()
print(sum((abs(x) for x in a)))


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
else:
	s = 0
	a.sort()
	pos = 0
	neg = 0
	k = 1
	for i in range(n):
		if a[i] > 0:
			pos += 1
		if a[i] < 0:
			neg += 1
		s += abs(a[i])
	if pos == n:
		print(s - 2 * a[0])
	elif neg == n:
		print(s + 2 * a[n - 1])
	else:
		print(s)


n = int(input())
a = list(map(int, input().split()))
minval = abs(a[0])
havepos = 0
haveneg = 0
ans = 0
if n == 1:
	print(a[0])
else:
	for i in range(n):
		minval = min(abs(a[i]), minval)
		havepos = havepos or a[i] >= 0
		haveneg = haveneg or a[i] <= 0
		ans += abs(a[i])
	if haveneg and havepos:
		print(ans)
	else:
		print(ans - 2 * minval)


n = int(input())
s = list(map(int, input().split()))
if n == 1:
	exit(print(s[0]))
f = []
if any((i <= 0 for i in s)) and any((i >= 0 for i in s)):
	exit(print(sum(map(abs, s))))
s.sort(key=abs)
cs = s[0]
for i in s[1:]:
	cs -= i
print(abs(cs))


n = int(input())
s = list(map(int, input().split()))
ans = 0
smax = -10 ** 9
smin = 10 ** 9
for i in s:
	if i > smax:
		smax = i
	if i < smin:
		smin = i
f1 = False
f2 = False
for i in s:
	if not f1 and i == smax:
		ans += smax
		f1 = True
		continue
	if not f2 and i == smin:
		ans -= smin
		f2 = True
		continue
	if i > 0:
		ans += i
	else:
		ans -= i
print(ans)


n = int(input())
s = list(map(int, input().split()))
s.sort()
ans = 0
if n == 1:
	ans = s[0]
elif s[0] >= 0:
	ans = sum(s[1:]) - s[0]
elif s[-1] < 0:
	ans = -sum(s[0:n - 1]) + s[-1]
else:
	for i in range(n):
		s[i] = abs(s[i])
	ans = sum(s)
print(ans)


n = int(input())
val = sorted(map(int, input().split()))
sval = sum(map(abs, val))
if n == 1:
	print(val[0])
elif val[0] > 0:
	print(sval - val[0] * 2)
elif val[-1] < 0:
	print(val[-1] * 2 + sval)
else:
	print(sval)


import sys
input = sys.stdin.readline
n = int(input())
v = list(sorted(map(int, input().split())))
if n == 1:
	print(v[0])
else:
	print(v[n - 1] - v[0] + sum(map(abs, v)) - (abs(v[0]) + abs(v[n - 1])))


from sys import stdin
n = int(input())
a = [int(x) for x in stdin.readline().split()]
if n == 1:
	print(a[0])
else:
	cnt = 0
	b = [0] * n
	li1 = [0] * n
	li2 = [0] * n
	for i in range(n):
		b[i] = abs(a[i])
	for i in range(n):
		if b[i] == a[i]:
			cnt += 1
		else:
			cnt = cnt
	ans = float('-inf')
	if cnt == n or cnt == 0:
		for i in range(n):
			if i == 0:
				li1[i] = b[i]
			else:
				li1[i] = li1[i - 1] + b[i]
		for i in range(n - 1, -1, -1):
			if i == n - 1:
				li2[i] = b[i]
			else:
				li2[i] = li2[i + 1] + b[i]
		for i in range(n - 1):
			su = 0
			s = a[i] - a[i + 1]
			su += abs(s)
			if i != 0:
				su += li1[i - 1]
			if i != n - 2:
				su += li2[i + 2]
			if su > ans:
				ans = su
				pos = i
		print(ans)
	else:
		ans = sum(b)
		print(ans)


n = int(input())
arr = list(map(int, input().split()))
absArr = list(map(abs, arr))
(positiveCount, negativeCount) = (0, 0)
for num in arr:
	if num > 0:
		positiveCount += 1
	elif num < 0:
		negativeCount += 1
if n == 1:
	print(arr[0])
elif positiveCount == n or negativeCount == n:
	print(sum(absArr) - 2 * min(absArr))
else:
	print(sum(absArr))


n = int(input())
l = list(map(int, input().split()))
if n == 1:
	print(l[0])
	exit()
l = sorted(l)
s = abs(l[0] - l[-1])
for i in range(1, n - 1):
	s += abs(l[i])
print(s)


n = int(input())
l = list(map(int, input().split()))
mx = max(l)
mn = min(l)
lx = l.index(mx)
lm = l.index(mn)
if lx == lm and n != 1:
	lm = l.index(mn, lx + 1)
s = sum([abs(x) for (i, x) in enumerate(l) if i != lx and i != lm])
if n == 1:
	print(mn)
	exit()
if n == 2:
	print(mx - mn)
	exit()
print(s + mx - mn)


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
a.sort()
c = a[n - 1]
f = a[0]
if n > 1:
	for i in range(1, n - 1):
		if a[i] >= 0:
			f -= a[i]
		elif a[i] < 0:
			f += a[i]
	print(c - f)
else:
	print(a[0])


n = int(input())
if n == 1:
	print(int(input()))
	exit(0)
(a, b) = ([], [])
for i in map(int, input().split()):
	if i > 0:
		a.append(i)
	elif i < 0:
		b.append(i)
if len(a) != 0 and len(b) != 0:
	print(sum(a) - sum(b))
elif len(a) + len(b) != n:
	print(sum(a) - sum(b))
elif len(a) == 0:
	print(max(b) * 2 - sum(b))
else:
	print(sum(a) - min(a) * 2)


import sys
n = int(input())
l = list(map(int, sys.stdin.readline().split()))
if len(l) == 1:
	exit(print(l[0]))
if all((i > 0 for i in l)):
	print(sum(l) - 2 * min(l))
elif all((i < 0 for i in l)):
	print(abs(sum(l)) + 2 * max(l))
else:
	s = 0
	for i in l:
		s = s + abs(i)
	print(s)


ans = []
a = int(input())
ans = []
import math
z = list(map(int, input().split()))
count = 1
for i in range(1, len(z)):
	if z[i] >= 0 and z[i - 1] >= 0 or (z[i] <= 0 and z[i - 1] <= 0):
		count += 1
	else:
		ans.append(count)
		count = 1
ans.append(count)
if len(ans) > 1:
	tt = 0
	for i in range(len(z)):
		tt += abs(z[i])
	print(tt)
elif len(z) == 1:
	print(z[0])
	exit()
else:
	tt = 0
	mini = math.inf
	for i in range(len(z)):
		z[i] = abs(z[i])
		mini = min(z[i], mini)
		tt += z[i]
	print(tt - 2 * mini)


n = int(input())
a = list(map(int, input().split()))
s = 0
if max(a) <= 0:
	print(abs(sum(a)) + 2 * max(a))
elif min(a) >= 0:
	print(abs(abs(sum(a)) - 2 * min(a)))
else:
	for i in a:
		s += abs(i)
	print(s)


def f(arr, N):
	if N == 1:
		return arr[0]
	a = 0
	a_min = 10 ** 9 + 1
	b = 0
	c = False
	d = False
	b_min = -1 * a_min
	for i in arr:
		if i >= 0:
			c = True
			a += i
			a_min = min(a_min, i)
		else:
			d = True
			b += i
			b_min = max(i, b_min)
	if c:
		if d:
			return a - b
		return a - 2 * a_min
	return 2 * b_min - b
N = int(input())
arr = list(map(int, input().strip().split()))
print(f(arr, N))


n = int(input())
a = [int(s) for s in input().split()]
if n == 1:
	print(a[0])
	exit()
(mi, po, sum, mix) = (0, 0, 0, 1000000000.0 + 1)
for i in a:
	if i < 0:
		mi += 1
	if i >= 0:
		po += 1
	sum += abs(i)
	mix = min(mix, abs(i))
if mi and po:
	print(sum)
else:
	print(sum - mix * 2)


n = int(input())
a = list(map(int, input().split()))
all_positive = True
all_negative = True
min_positive_index = None
max_negative_index = None
min_abs_value = abs(a[0])
total = 0
if n == 1:
	print(a[0])
else:
	for i in range(n):
		value = a[i]
		all_positive &= value > 0
		all_negative &= value < 0
		min_abs_value = min(min_abs_value, abs(value))
		total += abs(value)
	if all_positive or all_negative:
		print(total - 2 * min_abs_value)
	else:
		print(total)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
	exit()
if max(a) > 1 and min(a) < 1:
	print(sum((abs(x) for x in a)))
else:
	print(sum((abs(x) for x in a)) - 2 * min((abs(x) for x in a)))


n = int(input().strip())
arr = [int(__) for __ in input().strip().split()]
if n == 1:
	print(arr[0])
else:
	ne = 0
	for i in arr:
		if i < 0:
			ne += 1
	if ne == len(arr):
		arr = [abs(i) for i in arr]
		print(sum(arr) - 2 * min(arr))
	else:
		mi = min(arr)
		arr = [abs(i) for i in arr]
		if mi < 0:
			print(sum(arr))
		else:
			print(sum(arr) - 2 * mi)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
sys.setrecursionlimit(10 ** 5)
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
n = int(input())
l = list(map(int, input().split()))
if max(l) <= 0:
	print(abs(sum(l)) + 2 * max(l))
elif min(l) >= 0:
	print(abs(abs(sum(l)) - 2 * min(l)))
else:
	ans = 0
	for i in l:
		ans += abs(i)
	print(ans)


n = int(input())
lis = list(map(int, input().split()))
if len(lis) == 1:
	print(lis[0])
else:
	lis.sort()
	a = -lis[0] + lis[-1]
	lis = list(map(abs, lis))
	print(a + sum(lis[1:-1]))


import sys
n = int(input())
line = list(map(int, input().split()))
if n == 1:
	print(line[0])
	sys.exit(0)
sum = 0
minNum = 10 ** 9
maxNum = -10 ** 9
for i in line:
	if minNum > i:
		minNum = i
	if maxNum < i:
		maxNum = i
	sum += abs(i)
if minNum * maxNum < 0:
	print(sum)
elif minNum < 0:
	print(sum - 2 * abs(maxNum))
else:
	print(sum - 2 * abs(minNum))


def solve():
	n = int(input())
	worms = list(map(int, input().split()))
	if n == 1:
		return worms[0]
	if len(list(filter(lambda x: x >= 0, worms))) == 0:
		worms = list(map(abs, worms))
		minimum = min(worms)
		return sum(worms) - 2 * minimum
	minimum = min(worms)
	worms_sum = abs(sum(list(map(abs, worms)))) - abs(minimum)
	return abs(worms_sum - minimum)
print(solve())


def abs(a):
	if a < 0:
		return -a
	return a

def min(a, b):
	if a < b:
		return a
	return b

def max(a, b):
	if b > a:
		return b
	return a
n = int(input())
a = input()
a = list(map(int, a.split(' ')))
if n == 1:
	print(a[0])
	exit()
pos = int(0)
neg = int(0)
mn = int(10000000010)
mx = int(-1000000010)
s = int(0)
for i in range(n):
	if a[i] >= 0:
		pos += 1
	elif a[i] <= 0:
		neg += 1
	mn = min(mn, abs(a[i]))
	mx = max(mx, abs(a[i]))
	s += abs(a[i])
if pos == n or n == neg:
	print(s - 2 * mn)
else:
	print(s)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
Max = max(a)
Min = min(a)
ans = 0
if n == 1:
	print(a[0])
	exit()
for i in range(n):
	if a[i] > 0:
		ans += a[i]
	else:
		ans -= a[i]
if Min > 0:
	ans -= Min * 2
	print(ans)
	exit()
elif Max < 0:
	ans += Max * 2
	print(ans)
else:
	print(ans)


I = lambda : map(int, input().split())
n = int(input())
a = list(I())
s = 0
if n == 1:
	exit(print(a[0]))
if all((i > 0 for i in a)):
	print(sum(a) - 2 * min(a))
elif all((i < 0 for i in a)):
	print(-(sum(a) - 2 * max(a)))
else:
	for i in a:
		s += abs(i)
	print(s)


n = int(input())
a = [int(w) for w in input().split()]
s = sum((abs(x) for x in a))
if len(a) == 1:
	print(a[0])
elif all((x > 0 for x in a)) or all((x < 0 for x in a)):
	print(max((abs(s - 2 * abs(x)) for x in a)))
else:
	print(s)


import math
import sys

def main(arr):
	neg = 0
	pos = 0
	if len(arr) == 1:
		return arr[0]
	if len(arr) == 2:
		return abs(arr[0] - arr[1])
	for e in arr:
		if e > 0:
			pos += e
		else:
			neg += -1 * e
	if pos == 0:
		return pos + neg + 2 * max(arr)
	if neg == 0:
		return pos + neg - 2 * min(arr)
	else:
		return pos + neg
n = int(input())
arr = list(map(int, input().split()))
print(main(arr))


import sys
import math
lines = sys.stdin.read().splitlines()
n = [int(x) for x in lines[0].split()][0]
slizni = [int(x) for x in lines[1].split()]
small_slizen = min(slizni)
big_slizen = max(slizni)
if n == 1:
	print(small_slizen)
elif small_slizen <= 0 and big_slizen >= 0:
	print(sum([abs(x) for x in slizni]))
elif small_slizen >= 0:
	print(sum([abs(x) for x in slizni]) - 2 * small_slizen)
else:
	print(sum([abs(x) for x in slizni]) + 2 * big_slizen)


from sys import stdin, stdout
tot = int(stdin.readline())
arr = [int(x) for x in stdin.readline().split()]
(n, p, z) = (0, 0, 0)
for i in arr:
	if i > 0:
		p += 1
	elif i < 0:
		n += 1
	else:
		z += 1
ans = 0
for i in arr:
	ans += abs(i)
if tot == 1:
	stdout.write(str(arr[0]))
elif p == 0 or n == 0:
	mi = min(arr)
	if mi < 0:
		mi = max(arr)
	if mi > 0:
		print(ans - 2 * mi)
	else:
		print(ans + 2 * mi)
else:
	stdout.write(str(ans))


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(a[0])
elif n == 2:
	print(max(a[0] - a[1], a[1] - a[0]))
else:
	x = min(a)
	y = max(a)
	a = list(map(abs, a))
	print(sum(a) - (2 * min(a) if x * y > 0 else 0))


for _ in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	s = 0
	for i in range(n):
		s += abs(arr[i])
	if min(arr) < 0 and max(arr) >= 0:
		print(s)
		continue
	if n == 1:
		print(arr[0])
		continue
	d = 999999999999999
	for i in range(1, n):
		d = min(d, abs(arr[i]) + abs(arr[i - 1]) - abs(arr[i] - arr[i - 1]))
	print(s - d)


n = int(input())
xs = [int(x) for x in input().split()]
prefix = [-1 for i in range(n)]
suffix = [-1 for i in range(n)]
prefix[0] = 0
pre_has_neg = [False for i in range(n)]
suffix[-1] = 0
suf_has_neg = [False for i in range(n)]
for i in range(n):
	if i == 0:
		prefix[i] = xs[i]
	else:
		prefix[i] = prefix[i - 1] + xs[i]
for i in reversed(range(n)):
	if i == n - 1:
		suffix[i] = xs[i]
	else:
		suffix[i] = suffix[i + 1] + xs[i]
for i in range(n):
	if i == 0:
		pre_has_neg[i] = xs[i] <= 0
	else:
		pre_has_neg[i] = pre_has_neg[i - 1] or xs[i] <= 0
for i in reversed(range(n)):
	if i == n - 1:
		suf_has_neg[i] = xs[i] <= 0
	else:
		suf_has_neg[i] = suf_has_neg[i + 1] or xs[i] <= 0
prebignum = [None for i in range(n)]
sufbignum = [None for i in range(n)]
for i in range(n):
	if i == 0:
		prebignum[i] = xs[i]
	else:
		prebignum[i] = min(prebignum[i - 1], xs[i])
for i in reversed(range(n)):
	if i == n - 1:
		sufbignum[i] = xs[i]
	else:
		sufbignum[i] = min(sufbignum[i + 1], xs[i])
neg_pre = [100000 for i in range(n)]
neg_suf = [100000 for i in range(n)]
for i in range(n):
	if i == 0:
		neg_pre[i] = min(xs[i], -xs[i])
	else:
		neg_pre[i] = neg_pre[i - 1] + min(xs[i], -xs[i])
for i in reversed(range(n)):
	if i == n - 1:
		neg_suf[i] = min(xs[i], -xs[i])
	else:
		neg_suf[i] = neg_suf[i + 1] + min(xs[i], -xs[i])
ans = -100000000000000000
for i in range(n):
	tans = xs[i]
	if i == 0:
		pass
	elif pre_has_neg[i - 1]:
		tans -= neg_pre[i - 1]
	else:
		tans += prefix[i - 1]
		tans -= prebignum[i - 1] * 2
	if i == n - 1:
		pass
	elif suf_has_neg[i + 1]:
		tans -= neg_suf[i + 1]
	else:
		tans += suffix[i + 1]
		tans -= sufbignum[i + 1] * 2
	ans = max(ans, tans)
print(ans)


n = int(input())
p = 0
m = []
for s in input().split():
	x = int(s)
	p += abs(x)
	m.append(x)
	m.sort()
	if len(m) > 2:
		m.pop(1)
if n == 1:
	print(m[0])
elif m[0] > 0:
	print(p - 2 * m[0])
elif m[1] < 0:
	print(p + 2 * m[1])
else:
	print(p)


n = int(input())
lis = list(map(int, input().split()))
if len(lis) == 1:
	print(*lis)
	exit()
mi = min(lis)
ma = max(lis)
if mi >= 0:
	print(sum(lis) - 2 * mi)
elif ma <= 0:
	print(-sum(lis) + 2 * ma)
else:
	s = 0
	for i in lis:
		s += abs(i)
	print(s)


import math
n = int(input())
if n == 1:
	print(input())
	exit(0)
s = 0
l = math.inf
r = -math.inf
a = list(map(int, input().split()))
for i in range(n):
	s += abs(a[i])
	if a[i] > r:
		r = a[i]
	if a[i] < l:
		l = a[i]
if r < 0:
	s += r * 2
elif l > 0:
	s -= l * 2
print(s)


import sys
from collections import defaultdict
import math
mod = 998244353
n = int(sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
ans = 0
nin = abs(arr[0])
allneg = True
allpos = True
for i in range(n):
	if arr[i] <= 0:
		allpos = False
	if arr[i] >= 0:
		allneg = False
for i in range(n):
	ans += abs(arr[i])
	nin = min(nin, abs(arr[i]))
if n == 1:
	print(arr[0])
	sys.exit()
if allneg or allpos:
	print(ans - 2 * nin)
else:
	print(ans)


from sys import stdin
input = stdin.buffer.readline
n = int(input())
(*a,) = map(int, input().split())
x = max(a)
ans = x
a.remove(x)
if n > 1:
	x = min(a)
	ans -= x
	a.remove(x)
for i in a:
	ans += abs(i)
print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(a[0])
	else:
		(p, nn) = (0, 0)
		for i in range(n):
			p += a[i] >= 0
			nn += a[i] < 0
			a[i] = abs(a[i])
		if p == 0 or nn == 0:
			print(sum(a) - 2 * min(a))
		else:
			print(sum(a))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 1119 + 7
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = array()
a.sort()
pos = [abs(i) for i in a]
ans = sum(pos)
if a[0] > 0:
	ans -= 2 * a[0]
if a[-1] < 0:
	ans += 2 * a[-1]
if n == 1:
	ans = a[0]
print(ans)


from sys import stdin, stdout, setrecursionlimit
n = int(input())
a = sorted([int(i) for i in input().split()])
minus = plus = 0
for x in a:
	if x <= 0:
		minus += 1
	else:
		plus += 1
if n == 1:
	print(a[0])
elif plus > 0 and minus > 0:
	a = [abs(x) for x in a]
	print(sum(a))
elif plus == 0:
	print(-sum(a) + max(a) * 2)
elif minus == 0:
	print(sum(a) - min(a) * 2)


l = int(input())
a = [*map(int, input().split())]
p = n = 0
for i in a:
	if i > 0:
		p += 1
	else:
		n += 1
ans = 0
if p and n:
	a.sort()
	for i in a:
		if i < 0:
			ans -= i
		else:
			ans += i
elif p:
	a.sort()
	ans -= a[0]
	for i in a[1:]:
		ans += i
else:
	a.sort(reverse=True)
	ans += a[0]
	for i in a[1:]:
		ans -= i
print(ans if l > 1 else a[0])


import sys
from array import array
import typing as Tp

def input():
	return sys.stdin.buffer.readline().decode('utf-8')

def output(*args):
	sys.stdout.buffer.write(('\n'.join(map(str, args)) + '\n').encode('utf-8'))

def main():
	from itertools import accumulate
	n = int(input())
	a = list(map(int, input().split()))
	acc = tuple(accumulate(map(abs, a)))
	left_min = tuple(accumulate(a, min))
	right_min = tuple(accumulate(a[::-1], min))[::-1]
	ans = -10 ** 9 * 2
	for i in range(n):
		val = a[i]
		if i > 0:
			if left_min[i - 1] < 0:
				val += acc[i - 1]
			else:
				val += acc[i - 1] - left_min[i - 1] * 2
		if i < n - 1:
			if right_min[i + 1] < 0:
				val += acc[-1] - acc[i]
			else:
				val += acc[-1] - acc[i] - right_min[i + 1] * 2
		ans = max(ans, val)
	print(ans)
main()


import sys
input = sys.stdin.readline
import bisect
n = int(input())
l = input().split()
li = [int(i) for i in l]
poss = 1
if n == 1:
	print(li[0])
	quit()
for i in li:
	if i <= 0:
		poss = 0
		break
if poss:
	print(sum(li) - 2 * min(li))
	quit()
poss = 1
for i in li:
	if i >= 0:
		poss = 0
		break
if poss:
	print(-sum(li) + 2 * max(li))
	quit()
ans = 0
for i in li:
	ans += abs(i)
print(ans)


n = int(input())
arr = list(map(int, input().split()))
arr.sort()
s = 0
if n == 1:
	s = arr[0]
elif arr[-1] < 0:
	s = abs(sum(arr)) - abs(arr[-1]) * 2
elif arr[0] < 0:
	for i in range(len(arr)):
		s += abs(arr[i])
else:
	s = sum(arr) - 2 * arr[0]
print(s)


from sys import stdin
input = stdin.readline
n = int(input())
lst = sorted(map(int, input().split()))
if n == 1:
	print(lst[0])
	exit()
elif lst[-1] <= 0:
	s = abs(sum(lst)) + 2 * lst[-1]
elif lst[0] >= 0:
	s = sum(lst) - 2 * lst[0]
else:
	s = 0
	for i in lst:
		s += abs(i)
print(s)


n = int(input())
arr = list(map(int, input().strip().split()))
k = min(arr)
h = max(arr)
s = 0
for i in arr:
	if i >= 0:
		s += i
	else:
		s -= i
if n == 1:
	print(arr[0])
elif k < 0 and h >= 0:
	print(s)
elif k >= 0:
	print(s - 2 * k)
else:
	print(s + 2 * h)