Problem:
 Score : 400 points    Problem Statement There are N integers, A_1, A_2, ..., A_N , arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  Operation : Choose an integer i satisfying 1 \leq i \leq N-1 . Multiply both A_i and A_{i+1} by -1 .  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N .      Constraints  All values in input are integers.  2 \leq N \leq 10^5  -10^9 \leq A_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print the maximum possible value of B_1 + B_2 + ... + B_N .        Sample Input 1 3
-10 5 -4      Sample Output 1 19  If we perform the operation as follows:   Choose 1 as i , which changes the sequence to 10, -5, -4 .  Choose 2 as i , which changes the sequence to 10, 5, 4 .   we have B_1 = 10, B_2 = 5, B_3 = 4 . The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19 , is the maximum possible result.       Sample Input 2 5
10 -4 -8 -11 3      Sample Output 2 30       Sample Input 3 11
-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000      Sample Output 3 10000000000  The output may not fit into a 32 -bit integer type.

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

zero = 0
minus = 0
for i in range(n):
    if a[i] == 0:
        zero = 1
    elif a[i] < 0:
        minus += 1
    a[i] = abs(a[i])

a.sort()
if zero or minus%2 == 0:
    print(sum(a))
else:
    print(sum(a[1:])-a[0])

Solution (Python):
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N=int(input())
    A=list(map(int,input().split()))
    minA=INF
    c_m=0
    sumA=0
    for i in A:
        if i<0:
            c_m+=1
        minA=min(minA,abs(i))
        sumA+=abs(i)
    if c_m%2==1:
        print(sumA-2*minA)
    else:
        print(sumA)
        
    

if __name__ == '__main__':
    main()

Solution (Python):
input()
a = list(map(int, input().split()))

ans = 0
min_abs = 10**9
count_n = 0
flag_z = False

for i in a:
    if flag_z:
        if i >= 0:
            ans += i
        else:
            ans -= i

    else:
        if i == 0:
            flag_z = True
        elif i > 0:
            min_abs = min(min_abs, i)
            ans += i
        else:
            count_n += 1
            min_abs = min(min_abs, abs(i))
            ans -= i

if not (flag_z or count_n % 2 == 0):
    ans -= min_abs*2

print(ans)

Solution (Python):
n = int(input())

al = list(map(int,input().split()))
absl = []
minus = 0
for a in al:
    absl.append(abs(a))
    if a < 0:
        minus += 1

if minus % 2 == 0:
    print(sum(absl))
else:
    print(sum(absl) - 2 * min(absl))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
A_=sorted([i if i>0 else -i for i in A])
print(sum(A_)-A_[0]*2*((N-len([i for i in A if i>0]))%2))

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

Sum = 0
minus_Sum = 0
min = 10**9

for i in range(N):
    Sum += abs(A[i])
    if min > abs(A[i]):
        min = abs(A[i])
    
    if A[i] < 0:
        minus_Sum += 1
        
if minus_Sum % 2 == 0:
    print(Sum)
else:
    print(Sum - 2*min)

Solution (Python):
import sys
sys.setrecursionlimit(10**5)

n = int(input())
a = list(map(int, input().split()))
dp = [[None]*(2) for _ in range(n+1)]

dp[n-1][0] = a[n-1]
dp[n-1][1] = -a[n-1]

for i in reversed(range(n-1)):
    for j in range(2):
        
        
        unexe_unexe = a[i] + dp[i+1][0]
        exe_unexe = -a[i] + dp[i+1][1]
        dp[i][0] = max(unexe_unexe, exe_unexe)

        
        unexe_exe = a[i] + dp[i+1][1]
        exe_exe = -a[i] + dp[i+1][0]
        dp[i][1] = max(unexe_exe, exe_exe)



print(dp[0][0])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

negcnt = 0
mina = 10 ** 10
suma = 0
for i in a:
  if i < 0:
    negcnt += 1
  if mina > abs(i):
    mina = abs(i)
  suma += abs(i)

if negcnt % 2 == 1:
  ans = suma - 2*mina
else:
  ans = suma

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
dp=[[0]*2 for _ in range(N+1)]
dp[0][1]=-float("inf")
for i in range(N):
  dp[i+1][0]=max(dp[i][0]+A[i],dp[i][1]-A[i]) 
  dp[i+1][1]=max(dp[i][0]-A[i],dp[i][1]+A[i])
print(dp[-1][0])

Solution (Python):
N = int(input())
A =sorted( list(map(int, input().split())))
A_abs = list(map(abs, A))
flag = 0
for i in range(N):
    if A[i]<0:
        flag += 1
    else:
        break
if flag%2==0:
    print(sum(A_abs))
else:
    A_abs_s = sorted(A_abs)
    A_abs_s[0] = -1*A_abs_s[0]
    print(sum(A_abs_s))

Solution (Python):
n=int(input())
d=list(map(int,input().split()))
k=[]
t=0
ans=0
for i in range(n):
  ans+=abs(d[i])
  if d[i]<=0:
    t+=1
for i in range(len(d)):
  k.append(abs(d[i]))
k.sort()
if t%2:
  ans-=2*k[0]
print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
absa = [abs(i) for i in a]
c = 0
for i in a:
  if i < 0:
    c += 1
if c%2 == 0:
  print(sum(absa))
else:
  print(sum(absa)-min(absa)*2)

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    switch_count = N if N%2 == 0 else N-1
    A.sort()
    sumA = sum(A)
    answer = sumA
    prev = sumA
    for i in range(2,switch_count+1,2):
        a = prev - A[i-1]*2 - A[i-2]*2
        answer = max(a,answer)
        prev = a
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
mn = 0
for i in range(n):
    if a[i] < 0:
        mn += 1
        a[i] *= -1
if mn % 2 == 1:
    print(sum(a) - 2 * min(a))
else:
    print(sum(a))

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]

cnt = 0
m = 1e10
ans = 0
for a in A:
    if a < 0:
        cnt += 1
    ans += abs(a)
    m = min(abs(a), m)
if cnt % 2 == 0:
    print(ans)
else:
    print(ans - m*2)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
A = LI()
plus_a = [abs(a) for a in A]
z_cnt = 0
minus_cnt = 0
for i in A:
    if i == 0:
        z_cnt += 1
    elif i < 0:
        minus_cnt += 1


if z_cnt or minus_cnt % 2 == 0:
    print(sum(plus_a))
else:
    print(sum(plus_a) - min(plus_a) * 2)

Solution (Python):


n = int(input())
a = list(map(int, input().split()))
if a.count(0) == 0:
    hu_count = 0
    min = 10 ** 9
    for i in range(0,n):
        if a[i] < 0:
            hu_count += 1
            a[i] = -1 * a[i]
        if min > a[i]:
            min = a[i]
    if hu_count % 2 == 0:
        print(sum(a))
    else:
        print(sum(a) - min - min)
else:
    for i in range(0,n):
        if a[i] < 0:
            a[i] = -1 * a[i]
    print(sum(a))

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))

    cnt = 0
    for e in a:
        if e < 0:
            cnt += 1

    a = list(map(abs, a))
    a.sort()
    if cnt % 2:
        ans = sum(a[1:]) - a[0]
    else:
        ans = sum(a)

    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=sum(map(abs,a))
c=min(list(map(abs,a)))
z=[]
for i in a:
    if i<0:
        z.append(i)
x=len(z)%2
if x:
    print(s-2*c)
else:
    print(s)

Solution (Python):
input()
a = list(map(int, input().split()))
s = sum(map(abs, a))
n = sum(x < 0 for x in a)
if n % 2:
    s -= 2 * min(map(abs, a))
print(s)

Solution (Python):
def main():
    
    
    
    
    
    
    
    
    
    
    n=int(input())
    a = list(map(int,input().split()))
    cnt=0
    for i in range(n):
        if a[i]<0:
            a[i]*=-1
            cnt+=1
    a.sort()
    S=sum(a)

    print(S) if cnt%2==0 else print(S-2*a[0])
main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [0] * n
cnt = 0
for i in range(n):
    b[i] = abs(a[i])
    if a[i] < 0:
        cnt += 1
if cnt % 2 == 0:
    print(sum(b))
else:
    print(str(sum(b) - 2 * min(b)))

Solution (Python):
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n = INT()
a = MAP()

flag = False
cnt=0
for i in a:
    if i==0:
        flag = True
        break
    if i<0:
        cnt+=1
if cnt%2==0:
    flag = True

if flag:
    l = [abs(i) for i in a]
    print(sum(l))
else:
    l = [abs(i) for i in a]
    print(sum(l)-(2*min(l)))

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [abs(i) for i in a]
minus = 0
for i in range(n):
    if a[i] < 0:
        minus += 1
if minus%2:
    print(sum(b) - 2*min(b))
else:
    print(sum(b))

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
minus = 0
Min = float("inf")
ans = 0
for i in range(N):
  if A[i] < 0:
    minus += 1
  Min = min(Min,abs(A[i]))
  ans += abs(A[i])
if minus % 2 == 0:
  print(ans)
else:
  print(ans - (2 * Min))

Solution (Python):
n = int(input())
list1 = list(map(int,input().split()))
"""
for i in range(2):
	for i in range(n-1):
		if list1[i] < 0 and list1[i+1] < 0:
			list1[i] = abs(list1[i])
			list1[i+1] = abs(list1[i+1])
		elif (list1[i] < 0 and (abs(list1[i]) > abs(list1[i+1]))) or \
		(list1[i+1] < 0 and (abs(list1[i+1]) > abs(list1[i]))):
			list1[i] = list1[i]*-1
			list1[i+1] = list1[i+1]*-1


"""
count = 0
for i in range(n):
	if list1[i] < 0:
		count += 1
		list1[i] = abs(list1[i])
if count%2 == 0:
	print(sum(list1))
else:
	list1.sort()
	print(sum(list1)-list1[0]*2)

Solution (Python):


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

n_minus = len([x for x in A if x < 0])

if n_minus % 2 == 0:
    print(sum([abs(x) for x in A]))
else:
    print(sum([abs(x) for x in A]) - 2*abs(min(A, key=abs)))

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
A=tuple(map(int,input().split()))
B=[abs(i) for i in A]
o=0
for i in A:
    if i<0:
        o+=1
if o%2==0:
    print(sum(B))
else:
    print(sum(B)-min(B)*2)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)

N = I()
A = LI()
k = int(1)
for i in A:
    if i<0:
        k *=(-1)
    elif i==0:
        k = 0

for i in range(N):
    A[i] = abs(A[i])
sumA = sum(A)
if k<0:
    ans = sumA-min(A)*2
else:
    ans = sumA

print(ans)

Solution (Python):
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

N = int(input())
A = [0] + list(map(int, input().split()))

dp = makelist(N+1, 2)
dp[1][0] = A[1]
dp[1][1] = -int(1e9)
for i in range(2, N+1):
    dp[i][0] = A[i] + max(dp[i-1][0], dp[i-1][1])
    dp[i][1] = -A[i] + max(dp[i-1][0] + (-A[i-1])*2, dp[i-1][1] + A[i-1]*2)

ans = max(dp[N][0], dp[N][1])
print(ans)

Solution (Python):
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

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

A.sort()
for i in range(N-1):
    if i % 2 == 0:
        if A[i] + A[i+1] < 0:
            A[i] = -A[i]
            A[i+1] = -A[i+1]
            
print(sum(A))

Solution (Python):
import sys
import bisect
import collections
import fractions
import heapq


def slove():
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    t = 0
    for i in range(n):
        if a[i] < 0:
            cnt += 1
        a[i] = abs(a[i])
        t += a[i]
    a.sort()
    if cnt % 2 == 0:
        print(t)
    else:
        print(t - abs(a[0]) * 2)


if __name__ == '__main__':
    slove()

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

negA = []
posA = []
for a in A:
    if a >= 0:
        posA.append(a)
    else:
        negA.append(a)

ans = sum(posA) - sum(negA)

if len(negA) % 2 == 1:
    ans -= min([abs(a) for a in A]) * 2

print(ans)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0
abs_sum = 0
for i in A:
    abs_sum += abs(i)
    if i < 0:
        cnt += 1
mi = min([abs(i) for i in A])
if cnt % 2 == 0:
    print(abs_sum)
else:
    print(abs_sum-(mi*2))

Solution (Python):
import heapq
n = int(input())
a = list(map(int,input().split()))
count = 0
for i in a:
    if i < 0:
        count += 1
abs_a = list(map(abs,a))
if 0 in a or count % 2 == 0:
    print(sum(abs_a))
else:
    heapq.heapify(abs_a)
    min_a = heapq.heappop(abs_a)
    print(sum(abs_a)-min_a)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
cnt = 0
zcnt = a.count(0)
for i in range(N):
    if a[i] < 0:
        cnt += 1

total = 0
if cnt % 2 == 0 or (cnt % 2 != 0 and zcnt > 0):
    for i in range(N):
        total += abs(a[i])
else:
    tmp = 10 ** 9
    for i in range(N):
        total += abs(a[i])
        tmp = min(tmp, abs(a[i]))
    total -= 2 * tmp

print(total)

Solution (Python):
a=int(input())
lis=list(map(int,input().split()))
lis=sorted(lis)
i=0
while i<=a-2 and lis[i]<0:
  if lis[i]<=0 and lis[i+1]>=0:
    if -1*lis[i]>lis[i+1]:
      lis[i],lis[i+1]=-lis[i],-lis[i+1]
  elif lis[i]<=0 and lis[i+1]<=0:
    lis[i],lis[i+1]=-lis[i],-lis[i+1]
  i+=2
print(sum(lis))

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
cnt = sum(a < 0 for a in A)
sumabs = sum(abs(a) for a in A)
if cnt % 2 == 0:
    print(sumabs)
else:
    print(sumabs - 2 * min(abs(a) for a in A))

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

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

dp[0][0] = 0
dp[0][1] = -10000000

for i in range(N):
    dp[i+1][0] = max(dp[i][0] + A[i],dp[i][1] - A[i])
    dp[i+1][1] = max(dp[i][0] - A[i],dp[i][1] + A[i])
print(dp[N][0])

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

cnt = 0

for i in A:
    if i < 0:
        cnt += 1

A = [abs(i) for i in A]
if cnt % 2 == 0:
    print(sum(A))
else:
    print(sum(A) - 2 * min(A))

Solution (Python):
import numpy as np

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

A2 = np.abs(A)
x = A2.min()
s = A2.sum()
A3 = A < 0
if A3.sum() % 2 == 0:
    print(s)
else:
    print(s-2*x)

Solution (Python):
import numpy as np

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

A2 = np.abs(A)
x = A2.min()
s = A2.sum()
A3 = A < 0
if sum(A3) % 2 == 0:
    print(s)
else:
    print(s-2*x)

Solution (Python):
import numpy as np

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

A2 = abs(A)
x = min(A2)
A3 = A < 0
if sum(A3) % 2 == 0:
    print(sum(A2))
else:
    print(sum(A2)-2*x)

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

cnt=0
S=0
mi=10000000000
C0=False

for i in range(N):
    mi=min(mi,abs(A[i]))
    if A[i]>0:
        S+=A[i]
    elif A[i]==0:
        C0==True
    elif A[i]<0:
        cnt+=1
        S+=(-A[i])

if cnt%2==0 or C0==True:
    print(S)
else:
    print(S-mi*2)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
dp = [[0 for i in range(2)] for i in range(N+1)]
dp[0][1] = -10**9



for i in range(N):
    
    dp[i+1][0] = max(dp[i][0]+A[i],dp[i][1]-A[i])
    dp[i+1][1] = max(dp[i][0]-A[i],dp[i][1]+A[i])


print(dp[N][0])

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

K = len([a for a in A if a < 0])
B = sorted([abs(a) for a in A])

if K % 2 == 0:
    print(sum(B))
else:
    print(sum(B[1:]) - B[0])

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

cnt = 0
for i in range(N):
    if A[i] < 0:
        cnt += 1
        A[i] = -1 * A[i]
if cnt % 2 == 0:
    print(sum(A))
else:
    A.sort()
    print(sum(A) - A[0] * 2)

Solution (Python):
N = int(input())
A = [int(x) for x in input().split()]
B = [0]*N
numofminus = 0
minabs = 10**9  
for i in range(N):
    B[i] = abs(A[i])
    if A[i] < 0:
        numofminus += 1
    if abs(A[i]) < minabs:
        minabs = abs(A[i])

if numofminus % 2 == 1:
    ans = sum(B) - 2 * minabs
else:
    ans = sum(B)
print(ans)

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
count = 0
ans = 0
num = float("inf")

for i in range(n):
	a = A[i]
	if a < 0:
		count += 1
	ans += abs(a)
	num = min(num, abs(a))

if count % 2:
	print(ans - 2*(num))
else:
	print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
n=sum(list(map(lambda x: x<0,a)))
c0=sum(list(map(lambda x: x==0,a)))
if c0:
    print(sum(list(map(abs,a))))
    exit(0)
if n&1:
    print(sum(list(map(abs,a)))-2*min(list(map(abs,a))))
else:
    print(sum(list(map(abs,a))))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
cnt,po=0,0
for i in range(n):
    if A[i]<0:po +=1
    A[i]=abs(A[i])
    cnt +=A[i]
print(cnt-2*min(A) if po%2==1 else cnt)

Solution (Python):
n=int(input())

A=[int(i) for i in input().split()]

flg=1
for num in A:
    if num < 0:
        flg*=(-1)
        
B=[abs(i) for i in A]

if flg==1:
    print(sum(B))
else:
    print(sum(B)-2*sorted(B)[0])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
minus = sum([1 if x<0 else 0 for x in A])
if minus%2==1:
    absA = list(map(abs, A))
    mn = min(absA)
    print(sum(absA)-2*mn)
else:
    print(sum(map(abs, A)))

Solution (Python):

def main():
    
    
    
    N, *A = map(int, open(0).read().split())
    mi = abs(min(A, key=abs))
    abs_sum = sum(abs(i) for i in A)
    neg = sum(i < 0 for i in A)
    ans = abs_sum if neg % 2 == 0 else abs_sum - mi * 2
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
s = 0
c = 0
m = 10 ** 10

for x in a:
    if x < 0:
        c += 1
    
    s += abs(x)
    m = min(m, abs(x))
    
if c % 2 != 0:
    s -= 2 * m
    
print(s)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
m = sum(1 for i in a if i < 0)
z = any(i==0 for i in a)
if m%2 == 0 or z:
    print(sum(abs(i) for i in a))
else:
    
    print(sum(abs(i) for i in a)-2*abs(min(abs(i) for i in a)))

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
B=[abs(i) for i in A]
P=0
for i in A:
    if i<0:P +=1
    elif i==0:print(sum(B));exit()

print(sum(B) if P%2==0 else sum(B)-2*min(B))

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

flag=True 
for i in range(N):
    if A[i]<0:
        flag=not flag

S=sum([abs(Ai) for Ai in A])
m=min([abs(Ai) for Ai in A])

if flag:
    print(S)
else:
    print(S-2*m)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
absA=list(map(abs,A))

if 0 in A:
  print(sum(absA))
  exit()

m=list(filter(lambda x:x<0,A))

if len(m)%2==0:
  print(sum(absA))
else:
  print(sum(absA)-2*min(absA))

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = [0] * N
    cnt = 0
    for i in range(N):
        if A[i] < 0:
            cnt += 1
        B[i] = abs(A[i])

    if cnt % 2 == 0:
        print(sum(B))
    else:
        print(sum(B) - 2 * min(B))

main()

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

cnt = 0
for i in A:
    if i < 0: cnt += 1

A_abs = list(map(abs, A))
minmum = min(A_abs)

if cnt % 2 == 0:
    ans = sum(A_abs)
else:
    ans = sum(A_abs) - 2*minmum

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
minus = 0
for i in range(N):
  if A[i] < 0:
    minus += 1
    A[i] = abs(A[i])
if minus%2 == 0:
  print(sum(A))
else:
  print(sum(A)-(2*min(A)))

Solution (Python):
n = int(input())

counter = 0
a = 0
v = 10000000
for s in input().split():
    i = int(s)
    a += abs(i)
    if i < 0:
        counter += 1
    if abs(i) < v:
        v = abs(i)

if counter & 1:
    a -= v * 2
print(a)

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

INF = float("inf")
dp = [[0,0] for _ in range(N+1)]
dp[0][1] = -INF
for i in range(N):
    dp[i+1][0] = max(dp[i][0]+A[i],dp[i][1]-A[i])
    dp[i+1][1] = max(dp[i][0]-A[i],dp[i][1]+A[i])
print(dp[N][0])

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


S = sorted([[i,A[i]] for i in range(N)],key=lambda x: x[1])
judge = [False]*N
for j in range(0,N-1,2):
    if S[j][1]+S[j+1][1]<0:
        judge[S[j][0]] = True
        judge[S[j+1][0]] = True
for i in range(N-1):
    if judge[i]:
        A[i] *= -1
        A[i+1] *= -1
        judge[i+1] ^= True
print(sum(A))

Solution (Python):
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    negative = len([True for ai in a if ai <= 0])
    ans = sum([abs(ai) for ai in a])
    if negative % 2 == 0:
        print(ans)
    else:
        m = min([abs(ai) for ai in a])
        print(ans - m * 2)


if __name__ == "__main__":
    resolve()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
min_abs_a = float('inf')
sum_abs_A = 0
include_zero = False
for a in A:
  sum_abs_A += abs(a)
  min_abs_a = min(abs(a),min_abs_a)
  if a == 0: include_zero = True
  if a < 0 : neg_num += 1
print(sum_abs_A if neg_num%2==0 or include_zero is True else sum_abs_A - 2*min_abs_a)

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

negatives = len([a for a in A if a < 0])
if negatives % 2 == 0:
    m = 0
else:
    m = min(abs(a) for a in A)
print(sum(abs(a) for a in A) - 2 * m)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[abs(i) for i in a]
p=0
for i in a:
  if i<0:
    p+=1
if p%2==0:
  print(sum(b))
else:
  print(sum(b)-2*min(b))

Solution (Python):
import sys
import os
N = int(input())
A = list(map(int,input().split()))

negativeCnt = 0
for a in A:
    if a < 0:
        negativeCnt += 1
A = list(map(lambda a: -a if a < 0 else a, A))
miniA = min(A)
if negativeCnt%2 == 0:
    print(sum(A))
else:
    print(sum(A)-2*miniA)

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

plusmax = A[0]+A[1]
minusmax = -A[0]-A[1]

for i in range(2,N):
    m1 = max(plusmax,minusmax)+A[i]
    m2 = max(plusmax-2*A[i-1],minusmax+2*A[i-1])-A[i]
    plusmax, minusmax = m1,m2

print(max(plusmax,minusmax))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sign = 0
for i in range(n):
    if a[i] < 0:
        sign += 1
        a[i] *= -1
if sign%2 == 0:
    print(sum(a))
else:
    print(sum(a)-2*min(a))

Solution (Python):


N = int(input().split()[0])
a_list = list(map(int, input().split()))

odd_n = len([a for a in a_list if a < 0])


if odd_n % 2 == 0:
    s = 0
    for a in a_list:
        s += abs(a)
else:
    
    
    s = 0
    if 0 in a_list:
        for a in a_list:
            s += abs(a)
    else:
        min_abs = float('inf')
        for a in a_list:
            s += abs(a)
            min_abs = min(min_abs, abs(a))
        s -= min_abs * 2

ans = s
print(ans)

Solution (Python):
import sys


		
def main():
	n = int(input())
	al = list(map(int, input().split()))
	
	k=[abs(x) for x in al]
	bb=min(k)
	ss=sum(k)
	cc=len([x for x in al if x < 0])%2
	ans = ss - bb * cc*2
	
	
	print(ans)
	
	

isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		
			
	ret = main()
	if ret is not None:
		print(ret)

Solution (Python):
n=int(input())
lists=list(map(int,input().split()))


if 0 in lists:
    ans=0
    for _ in lists:
        ans+=abs(_)
    print(ans)
        
    
    
else:
    abslists=[]
    for j in lists:
        abslists.append(abs(j))
        
    ans=0
    count=0
    
    for inner in lists:
        if inner<0:
            count+=1
        
        else:
            continue
            
    if count%2==0:
        for _ in lists:
            ans+=abs(_)
        print(ans)
        
    else:
        for _ in lists: 
            ans+=abs(_)  
        min1=min(abslists)
        print(ans-2*min1)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7



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


smallest = INF
minus = 0
is_zero = False
ans = 0
for a in A:
    smallest = min(smallest, abs(a))

    if a == 0:
        is_zero = True
    elif a < 0:
        minus += 1

    ans += abs(a)

if is_zero or minus % 2 == 0:
    print(ans)
else:
    ans -= smallest*2
    print(ans)

Solution (Python):
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3
-10 5 -4"""
        output = """19"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """5
10 -4 -8 -11 3"""
        output = """30"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """11
-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000"""
        output = """10000000000"""
        self.assertIO(input, output)
def resolve():
    N=int(input())
    A=[int(i) for i in input().split()]
    d2=sum([1 if i<0 else 0 for i in A])%2
    B=[abs(i) for i in A]
    bs=sum(B)
    if d2==0:
        print(bs)
    else:
        print(bs-2*min(B))

if __name__ == "__main__":
    resolve()

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    dp = [[0,0] for i in range(N)]
    dp[0][0] = A[0]
    dp[0][1] = - A[0]
    for i in range(N-2):
        dp[i+1][0] = max(dp[i][0]+A[i+1],dp[i][1] - A[i+1])
        dp[i+1][1] = max(dp[i][0] - A[i+1],dp[i][1] + A[i+1])
    dp[N-1][0] = dp[N-2][0] + A[N-1]
    dp[N-1][1] = dp[N-2][1] - A[N-1]
    return max(dp[N-1])

if __name__ == '__main__':
    print(main())

Solution (Python):

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

cnt = 0
is_zero = False
for i in range(N):
    if A[i] < 0:
        cnt += 1
    if A[i] == 0:
        is_zero = True

A = [abs(a) for a in A]

if cnt%2 == 0 or is_zero == True:
    print(sum(A))
else:
    print(sum(A)-2*min(A))

Solution (Python):

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

Solution (Python):
from heapq import heappush,heappop

N = int(input())
array = list(map(int,input().split()))
nega = []
posi = []

for num in array:
  if num >= 0:
    heappush(posi,num)
  else:
    heappush(nega,num*(-1))


if len(nega)%2==0:
  ans = sum(nega) + sum(posi)
else:
  if len(nega)==N:
    max_nega = heappop(nega)
    ans = sum(nega) - max_nega
  else:
    min_posi = heappop(posi)
    max_nega = heappop(nega)
    if min_posi > max_nega:
      ans = sum(nega) + sum(posi) + min_posi - max_nega
    else:
      ans = sum(nega) + sum(posi) - min_posi + max_nega

print(ans)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
abs_A = [abs(a) for a in A]
minus_count = 0
for e in A:
    if e <= 0:
        minus_count += 1
if minus_count % 2 == 0:
    print(sum(abs_A))
else:
    print(sum(abs_A)-2*(min(abs_A)))

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    if(len([i for i in A if i <= 0])%2):
        print(sum(map(abs,A))-2*min(map(abs,A)))
    else:
        print(sum(map(abs,A)))

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [ int(next(tokens)) for _ in range(N) ]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):

plus,minus=[],[]
n=int(input())
m=10**9
for i in input().split():
    a = int(i)
    m=min(m,abs(a))
    if a>0:
        plus.append(a)
    else:
        minus.append(a)
if len(minus)%2==0:
    print(sum(plus)-sum(minus))
else:
    print(sum(plus)-sum(minus)-2*m)

Solution (Python):


import numpy as np

N=int(input())

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

count=0
mi=10**9
all=0

for i in range(N)[::-1]:
    mi=min(mi,abs(l[i]))
    if l[i]<0:
        count+=1
    elif l[i]==0:
        break

if count%2==1:
    print(sum(np.absolute(l))-2*mi)
else:
    print(sum(np.absolute(l)))

Solution (Python):
n =int(input())
a = list(map(int,input().split()))

a.sort()

for i in range(0,n//2):
    if a[2*i] <= 0 and a[2*i+1] <=0:
        a[2*i] *= -1
        a[2*i+1] *= -1
    elif a[2*i] <= 0 and a[2*i+1] >=0:
        if abs(a[2*i]) > abs(a[2*i+1]):
            a[2*i] *= -1
            a[2*i+1] *= -1
    else:
        break
print(sum(a))

Solution (Python):
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))

    count = 0
    ans = 0
    _min = 10**9

    for a in a_s:
        if a <= 0:
            count += 1
        ans += abs(a)
        _min = min(_min, abs(a))
    if count % 2 == 1:
        ans -= 2*_min
    print(ans)



if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
A_list = list(map(int, input().split()))
ans = 0
dp = [[0, 0] for _ in range(n+1)]
dp[0][0] = 0
dp[0][1] = -float("inf")
for i in range(n-1):
    dp[i+1][0] = max(dp[i][0] + A_list[i], dp[i][1] - A_list[i])
    dp[i+1][1] = max(dp[i][0] - A_list[i], dp[i][1] + A_list[i])
dp[n][0] = max(dp[n-1][0] + A_list[n-1], dp[n-1][1] - A_list[n-1])
print(dp[n][0])

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]

check=False
minus=0
mini=float('inf')
total=0
for i in a:
    if i==0:
        check=True
    if i<0:
        minus+=1
    total+=abs(i)
    mini=min(mini,abs(i))


if minus%2==0:
    check=True

    
print(total if check else total-mini*2)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mcnt = 0
s = 10**9
for i in range(n):
  if a[i] < 0:
    mcnt += 1
    a[i] = -1 * a[i]
  s = min(s, abs(a[i]))
if mcnt % 2 == 0:
  print(sum(a))
else:
  print(sum(a) - (s*2))

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
b = []
minus = 0
for i in range(n):
  if a[i] < 0:
    minus += 1
  b.append(abs(a[i]))
b.sort()
if minus % 2 == 0:
  print(sum(b))
else:
  print(sum(b) - 2 * b[0])

Solution (Python):


n=int(input())
a=list(map(int,input().split()))
cnt=0
minus=0
suma=0
mina=float('inf')
for i in range(n):
    if a[i]<0:
        minus+=1
    suma+=abs(a[i])
    mina=min(mina,abs(a[i]))

ans=suma
if minus%2 and 0 not in a:
    ans-=mina*2
print(ans)