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):
input()
A=list(map(int,input().split()))
s=0
for a in A:
  if a < 0:
    s += 1
S=0
if s % 2 == 0:
  S = sum([abs(a) for a in A])
else:
  B = [abs(a) for a in A]
  m = min(B)
  S = sum(B) - 2*m
print(S)

Solution (Python):

N = int(input())
data = list(map(int, input().split()))
count = 0

def ary_abs(data):
    for i in range(len(data)):
        data[i] = abs(data[i])


for i in data:
    if i <= 0:
        count += 1

if count % 2 == 0:
    
    
    ary_abs(data)
    print(sum(data))
else:
    
    
    ary_abs(data)
    print(sum(data) - min(data) * 2)

Solution (Python):
def d_flipping_signs_dp(N, A):
    dp = [[0] * 2 for _ in range(N + 1)]
    dp[0][0] = 0
    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])
    return dp[N][0]

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs_dp(N, A))

Solution (Python):
def d_flipping_signs(N, A):
    minus_count_parity = len([1 for a in A if a < 0]) % 2
    a = list(map(abs, A))
    return sum(a) + (-2 * min(a) if minus_count_parity == 1 else 0)

N = int(input())
A = [int(i) for i in input().split()]
print(d_flipping_signs(N, A))

Solution (Python):


import math
                                                                                                       
def main(n,a):                                                                                         
    n = int(n)                                                                                         
    a = a.split()
    cnt = 0
    minus = 0                                                                                          
    b = []                                                                                             
    for i in a:                                                                                        
        a[cnt] = int(i)                                                                                
        b.append(abs(int(i)))                                                                          
        if a[cnt] < 0:
            minus += 1                                                                                 
        cnt += 1 
    if minus % 2 != 0: 
        mini = min(b)                                                                                  
    else:       
        mini = 0 
    total = 0   
    for i in b: 
        total += abs(i)
    total -= 2 * abs(mini)                                                                             
    print total     
    return total
                                                                                                       
if __name__ == "__main__":                                                                             
    n = raw_input()
    a = raw_input()                                                                                    
    main(n,a)

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a_min = 0
minus_count = 0
for i in a:
    if i < 0:
        minus_count += 1
a = [abs(e) for e in a]
if minus_count % 2 != 0:
    a_min = a.pop(a.index(min(a)))
ans = sum(a) - a_min
print(ans)

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

minus_count = 0

for a in A:
    if a < 0:
        minus_count += 1

total = 0
min_num = 10 ** 9

for a in A:
    total += abs(a)
    min_num = min(min_num, abs(a))

if minus_count % 2 == 1:
    total -= 2 * min_num

print(total)

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

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

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

    if N == 2:
        print(max(A[0]+A[1], (-A[0])+(-A[1])))
        return

    a_sum, a1, a2 = 0, A[0], A[1]
    b_sum, b1, b2 = 0, -A[0], -A[1]
    for i in range(2, N):
        
        
        
        

        if (a_sum + a1 + a2 + A[i]) > (b_sum + b1 + b2 + A[i]):
            new_a_sum = a_sum + a1
            new_a1 = a2
            new_a2 = A[i]
        else:
            new_a_sum = b_sum + b1
            new_a1 = b2
            new_a2 = A[i]

        if (a_sum + a1 - a2 - A[i]) > (b_sum + b1 - b2 - A[i]):
            new_b_sum = a_sum + a1
            new_b1 = -a2
            new_b2 = -A[i]
        else:
            new_b_sum = b_sum + b1
            new_b1 = -b2
            new_b2 = -A[i]

        a_sum, a1, a2 = new_a_sum, new_a1, new_a2
        b_sum, b1, b2 = new_b_sum, new_b1, new_b2
        
    print(max(a_sum+a1+a2, b_sum+b1+b2))

main()

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

dp = {(0, 0): 0, (0, 1): -10 ** 10}
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):
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
import math
from functools import reduce


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


def INT(): return int(input())


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


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

def SUM(x):return sum([abs(x) for x in a ])



sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

a = LIST()

ct = 0

p=[]

for i, x in enumerate(a):
    if x < 0:
        ct +=1
        p.append([i, x])
    elif x == 0:
        ct = 0
        p.clear()


saidai = SUM(a)
a_abs = [abs(x) for x in a]

if ct % 2 == 0:
    print(saidai)
else:
    a_min = min(a_abs)
    print(saidai-2*a_min)

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

a, b = 0, -1e10
for ai in A:
    a, b = max(a + ai, b - ai), max(a - ai, b + ai)

print(a)

Solution (Python):

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

c = 0
S = 0
m = pow(10, 9)
for a in A:
    if a < 0:
        c += 1
        abs = -a
    else:
        abs = a
    S += abs
    if abs < m:
        m = abs

if c % 2 == 0:
    print(S)
else:
    print(S - 2 * m)

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

sgn = 0
for i in range(N):
    if A[i] < 0 :
        sgn += 1
    A[i] = abs(A[i])

A.sort()

if sgn % 2 == 0:
    print(sum(A))
else:
    print(sum(A) - A[0] * 2)

Solution (Python):
def main():
    N = int(input())

    neg_num = 0
    sum_abs = 0
    min_abs = 100000
    for i in input().split():
        number = int(i)
        if number < 0:
            neg_num +=1

        sum_abs += abs(number)
        min_abs = min(min_abs, abs(number))

    if neg_num % 2 == 0:
        print(sum_abs)
    else:
        print(sum_abs - min_abs*2)
    
if __name__ == "__main__":
    main()

Solution (Python):
import fractions
from functools import reduce

n = int(input())

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

dp = [[a[0]],[-10**10]]

for i in range(n-1):
    dp[0].append(max(dp[0][i] +a[i+1], dp[1][i] + a[i+1]))
    dp[1].append(max(dp[0][i] - a[i+1]- 2*a[i], dp[1][i]-a[i+1] + 2*a[i]))

print(max(dp[0][n-1],dp[1][n-1]))

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

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

print(dp[N][0])

Solution (Python):
import numpy as np
N = int(input())
A_list = list(map(int, input().split()))

dp = np.zeros((len(A_list)+1, 2))
dp[0][1] = - 10**5

for idx, a in enumerate(A_list):
    dp[idx+1][0] = max(dp[idx][0] + a, dp[idx][1] - a)
    dp[idx+1][1] = max(dp[idx][0] - a, dp[idx][1] + a)
print(int(dp[N][0]))

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

num_negative = sum([1 for x in A if x < 0])
absA = [abs(x) for x in A]
if num_negative % 2 == 0:
    print(sum(absA))
else:
    print(sum(absA)-min(absA)*2)

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

ans = 0
minus_cnt = 0
min_num = 10000000000000
for i in a:
  if i < 0:
    minus_cnt += 1
  if abs(i) < min_num:
    min_num = abs(i)

case = minus_cnt % 2

for i in a:
   ans += abs(i)

if case == 1:
  ans -= 2 * min_num

print (ans)

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

Solution (Python):
N = int(input())
A = list(int(i) for i in input().split())
count_m = 0
count_z = 0

for i in A:
  if i < 0:
    count_m += 1
  elif i == 0:
    count_z += 1

A_abs = [abs(i) for i in A]
if count_m%2 == 0 or (count_m+count_z)%2 == 0:
  print(sum(A_abs))
  
else:
  A_min = A_abs.index(min(A_abs))
  A_abs[A_min] = A_abs[A_min]*(-1)
  print(sum(A_abs))

Solution (Python):
from sys import stdin

def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()



N = ri()
A = ria()
inf = int(1e18)

dp = [0] * 2
dp[0] = [-inf] * (N + 1)
dp[1] = [-inf] * (N + 1)

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

ma = max(dp[0][N - 1] + A[N - 1], dp[1][N - 1] - A[N - 1])

print(ma)

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

k = 0
tmp = abs(a[n - 1])

for i in range(n - 1):
    if abs(a[i]) < tmp:
        tmp = abs(a[i])

    if a[i] < 0:
        a[i] *= -1
        a[i + 1] *= -1

    k += a[i]

if a[n - 1] < 0:
    if abs(a[n - 1]) == tmp:
        k += a[n - 1]
    else:
        k += abs(a[n - 1])
        k -= tmp * 2
else:
    k += a[n - 1]

print(k)

Solution (Python):
N=int(input())
A=list(int(x) for x in input().split())
minus_cnt=0
zero_cnt=0

B=[]
for x in A:
	if x<0:
		minus_cnt+=1
	if x==0:
		zero_cnt+=1
	B.append(max(x,-x))

if (minus_cnt%2==1 and zero_cnt==0):
	print(sum(B)-min(B)*2)
else:
	print(sum(B))

Solution (Python):
import numpy as np
n = int(input())
a = list(map(int, input().split()))

if sum(1 for x in a if x < 0) % 2 == 0:
    print(sum(np.abs(a)))
else:
    print(sum(np.abs(a)) - min(np.abs(a)) * 2)

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

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
count_m = 0
b_abs = [abs(b[i]) for i in range(n)]
for i in range(n):
  if b[i] < 0:
    count_m += 1
if count_m % 2 == 0:
  print(sum(b_abs))
else:
  b_min = min(b_abs)
  min_i = b_abs.index(b_min)
  if min_i == 0:
    print(sum(b_abs[1:]) - b_abs[0])
  elif min_i == n-1:
    print(sum(b_abs[:n-1]) - b_abs[n-1])
  else:
    print(sum(b_abs[0:min_i]+b_abs[min_i+1:]) - b_abs[min_i])

Solution (Python):
from collections import deque

N = int(input())
A = list(map(int, input().split()))
minAbs = 10**10
countMinus = 0
S = 0
for a in A:
  countMinus += (1 if a < 0 else 0)
  S += abs(a)
  minAbs = min(minAbs, abs(a))
print(S-2*(0 if countMinus % 2 == 0 else minAbs))

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

dp[0][1] = -1e9
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 = [int(i) for i in input().split()]
n = [a for a in A if a < 0]
S = sum([abs(a) for a in A])
if len(n) % 2 == 0:
    print(S)
else:
    print(S - 2 * min([abs(i) for i in A]))

Solution (Python):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())),dtype="i8")
cm = np.sum(a < 0)
a = np.abs(a)
s = np.sum(a)
if cm % 2:
    s -= np.min(a) * 2
print(s)

Solution (Python):

from functools import reduce

n = int(input()) 
alist = list(map(int, input().split()))

def isMinus(x):
  if x<0:
    return 1
  else:
    return 0


s = sum([isMinus(i) for i in alist]) % 2


if s == 0:
  ans = sum(map(abs, alist))
else:
  ans = sum(map(abs, alist)) - min(list(map(abs, alist)))*2

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

Solution (Python):
if __name__ == "__main__":
    _, *aa = map(int, open(0).read().split())
    bb = tuple(map(abs, aa))
    m = tuple(a for a in aa if a < 0)
    print(sum(bb) - min(bb)*2*(len(m)%2))

Solution (Python):
_, *aa = map(int, open(0).read().split())
bb = tuple(map(abs, aa))
m = tuple(a for a in aa if a < 0)
print(sum(bb) - min(bb)*2*(len(m)%2))

Solution (Python):
def main():
    _, *aa = map(int, open(0).read().split())
 
    bb = tuple(map(abs, aa))
    m = tuple(a for a in aa if a < 0)
    print(sum(bb) - min(bb)*2*(len(m)%2))
 
 
if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a = input().split()
mi = abs(int(a[0]))
ans =  0 
count = 0
for i in range(n):
    ans = ans + abs(int(a[i]))
    if mi > abs(int(a[i])):
        mi = abs(int(a[i]))
    if int(a[i])<0:
        count = count + 1
if count%2 ==0:
    print(ans)
else:
    print(ans-2*mi)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
 
    B = list(map(abs, A))
    C = [a for a in A if a < 0]
    if len(C) % 2 == 0:
        print(sum(B))
    else:
        print(sum(B) - min(B)*2)
    
if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin

readline = stdin.readline

n = readline()
aa = map(int, readline().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    if b < mi:
        mi = b
print(r - mi * 2 * (m % 2))

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

Solution (Python):
_, *aa = map(int, open(0).read().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    if b < mi:
        mi = b
print(r - mi * 2 * (m % 2))

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

cnt = 0

for i in range(N):
    if A[i] < 0:
        cnt += 1
if cnt % 2 == 0:
    ans = 0
    for a in A:
        ans += max(a, -a)
    print(ans)
else:
    ans = 0
    smallest = float("inf")
    for a in A:
        ans += max(a, -a)
        smallest = min(smallest, abs(a))
    
    ans -= 2 * smallest
    print(ans)

Solution (Python):
def main():
    _ = input()
    A = tuple(map(int, input().split()))
 
    B = tuple(map(abs, A))
    C = tuple(a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()

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

s = 0
mc = 0
mh = 1e10
for i in A:
  if i <= 0:
    mc += 1
  if abs(i) <= mh:
    mh = abs(i)
  s += abs(i)

if (mc % 2 == 1):
  mv = min(A[0],A[-1])
  
  s -= mh*2
print(s)

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

n = sum(1 for a in A if a < 0)
s = sum(abs(a) for a in A)
m = min(abs(a) for a in A)

if n % 2 == 0:
    print(s)
else:
    print(s - 2 * m)

Solution (Python):
n = int(input())
aa = list(map(int, input().split()))
abs_aa = sorted([abs(a) for a in aa])
minus_count = sum([1 for a in aa if a < 0])
if minus_count % 2:
    abs_aa[0] *= -1
print(sum(abs_aa))

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

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

Solution (Python):
import numpy as np 
N = int(input())
A =list(map(int, input().strip().split()))
Ap = np.abs(A)
i = 0
m = 0
s = 0
M = np.sum(Ap)
while i <= N - 1:
    if A[i] < 0:
        m += 1
    i += 1
if m % 2 ==0:
    print(M)
else:
    Ma = 0
    while s <= N - 1:
        M1 = M - 2 * Ap[s]
        if M1 >= Ma:
            Ma = M1
        s += 1
    print(Ma)

Solution (Python):
from sys import stdin

readline = stdin.readline

_, *aa = map(int, open(0).read().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    if b < mi:
        mi = b
print(r - mi * 2 * (m % 2))

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
d=0
z=0
s=0
for i in range(n):
  if l[i]<0:
    d+=1
  elif l[i]==0:
    z+=1
if d%2==0 or (d+z)%2==0:
  for i in range(n):
    s+=abs(l[i])
  print(s)
else:
  for i in range(1,n):
    if a>=abs(l[i]):
      a=abs(l[i])
      m=i
  s=0
  for i in range(m):
    s+=abs(l[i])
  s+=-abs(l[m])
  for i in range(m+1,n):
    s+=abs(l[i])
  print(s)

Solution (Python):
def solve(n, a_list):
    total = [abs(item) for item in a_list]
    negative = [abs(item) for item in a_list if item < 0]
    
    if len(negative) % 2 == 0:
        return sum([abs(item) for item in a_list])
    else:
        minimum = sorted(total)[0]
        return sum([abs(item) for item in a_list]) - 2 * minimum


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
a_list = [int(i) for i in input().split()]
minus_count_even_flug = True
zero_exist_flug = False
  
for a in a_list:
    if a < 0:
        minus_count_even_flug = not minus_count_even_flug
    if a == 0:
        zero_exist_flug = True
     
a_abs_list = [abs(a) for a in a_list]
sum_a_abs_list = sum(a_abs_list)
if minus_count_even_flug or zero_exist_flug:
    print(sum_a_abs_list)
else:
    print(sum_a_abs_list - 2 * min(a_abs_list))

Solution (Python):


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








ng = [a for a in A if a < 0]    
ab = [abs(a) for a in A]    

if len(ng) % 2 == 0:
    print(sum(ab))
else:
    mn = min(ab)
    print(sum(ab)-2*mn)

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

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    zero = 0
    neg = 0
    m = float("inf")
    for i in range(N):
        if A[i] == 0:
            zero += 1
        if A[i] < 0:
            neg += 1
        A[i] = abs(A[i])
        m = min(m, A[i])

    neg = neg % 2 
    if neg == 0:
        result = sum(A)
    else:
        if zero:
            result = sum(A)
        else:
            result = sum(A) - 2*m
    print(result)
    return 

if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
nums = [int(i) for i in input().split(' ')]

count = 0
m = 0
target = -1
for i in range(N):
    if nums[i] < 0:
        count += 1
    if abs(nums[i]) < m or target == -1:
        target = i
        m = abs(nums[i])
pos = [abs(i) for i in nums]
if count % 2 != 0:
    pos[target] = -abs(pos[target])

print(sum(pos))

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

Solution (Python):
from sys import stdin
 
readline = stdin.readline
 
def main():
    _, *A = map(int, open(0).read().split())
 
    B = tuple(map(abs, A))
    C = tuple(a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
count = 0
for i in range(N):
    if A[i] < 0:
        count += 1
Negative = False
if count % 2 == 0:
    Negative = True

for i in range(N):
    A[i] = max(A[i],-A[i])

ans = 0
if Negative:
    ans = sum(A)
else:
    ans = sum(A) - 2* min(A)

print(ans)

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
minus = []
for i in range(N):
  if A[i] < 0:
    minus.append(A[i])
abs_A = [abs(i) for i in A]
if len(minus) % 2 == 0:
  print(sum(abs_A))
else:
  print(sum(abs_A)-min(abs_A)*2)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
N = int(input())
Alist = list(map(int, input().split()))
memo = [{} for i in range(N)]

def ddp(cur_N, ai):
    if ai in memo[cur_N]:
        return memo[cur_N][ai]
    if cur_N >=N-1:
        return ai
    aj = Alist[cur_N+1]
    ret = max(ai + ddp(cur_N+1, aj), -1*ai + ddp(cur_N+1, -1*aj))
    memo[cur_N][ai] = ret
    return ret
print(ddp(0, Alist[0]))

Solution (Python):
N=int(input())
A = [int(j) for j in input().split()]
ans=0
min_A=10**5

A_count= len([a for a in A if a <0])
if A_count%2==0:
    for a in A:
        if a <0:
            ans+= -1*a
        else:
            ans+=a


elif A_count%2!=0:
    for a in A:
        ans+=abs(a)
        min_A=min(min_A,abs(a))
    ans=ans-2*min_A
print(ans)

Solution (Python):
N = int(input())
A= list(map(int, input().split()))
minus = 0
A_abs = []
for i in range(N):
    A_abs.append(abs(int(A[i])))
    if(A[i] < 0):
        minus += 1

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

Solution (Python):
N = input()
A = map(int, raw_input().split())
B = []
flag = 2
flag2 = 0
k = 0
minabs = 0
for i in range(N):
	k = abs(A[i])
	B.append(k)
	if(k != 0 and (k < minabs or minabs == 0)):
		minabs = k
	if(i == N - 1):
		if(A[i] == 0 or flag2 == 1):
			flag2 = 1
		elif((flag == 1 and A[i] < 0) or (flag == 0 and A[i] > 0)):
			flag2 = 1
		else:
			flag2 = 0
	else:
		if(flag == 2):
			if(A[i] > 0):
				flag = 0
			elif(A[i] == 0):
				flag2 = 1
			else:
				flag = 1
		elif((A[i] > 0 and flag == 0) or (A[i] < 0 and flag == 1)):
			flag = 0
		elif((A[i] < 0 and flag == 0) or (A[i] > 0 and flag == 1)):
			flag = 1
		else:
			flag2 = 1
if(flag2 == 1):
	print(sum(B))
else:
	print(sum(B)- minabs * 2)

Solution (Python):

n = int(input())
a = (list(map(int, input().split())))
aa=[]
minus = 0
for i in range(n):
    if a[i] < 0:
        aa.append(-a[i])
        minus += 1
    else: aa.append(a[i])

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

Solution (Python):
import sys,collections as cl
import fractions
from functools import reduce
import copy
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a

n = int(input())
su = 0

a = l()

co = 0
k = 0
a.sort()
f = 0
for i in range(n):
	if a[i] <= 0:
		co += 1
if co % 2 == 0:
	for i in range(n):
		su += abs(a[i])
	print(su)
else:
	for i in range(n):
		if a[i] == 0:
			break
		if a[i] > 0:
			kk = a[i-1]
		if a[i] > 0:
			if abs(a[i-1]) >= a[i]:
				k = a[i]*(-2)
			else:
				k = kk*2
			break
		elif i == n-1:
			k = a[i]*2
	for i in range(n):
		su += abs(a[i])
	su += k
	print(su)

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

negs = [num for num in numbers if num <= 0]
abss = []

count = 0
for num in numbers:
  if num >= 0:
    count += num
    abss.append(num)
  else:
    count -= num
    abss.append(-num)
    
if len(negs) % 2 == 0:
  print(count)
else:
  print(count - 2*min(abss))

Solution (Python):
N = int(input())
a = input().split()
num=[]
numabs=[]
tex=[]
count=0
count2=0
for i in range(N):
	num.append(int(a[i]))
	numabs.append(abs(num[i]))
	if num[i] < 0 :
		count +=1
	elif num[i] == 0:
		count2 +=1
if count%2 ==0 or count2 > 0:
	res = sum(numabs)
else:
	res =sum(numabs)-2*min(numabs)
print(res)

Solution (Python):
from sys import stdin

readline = stdin.readline

_, *aa = map(int, open(0).read().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    mi = min(b, mi)
print(r - mi * 2 * (m % 2))

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
l=[]
cnt=0
for i in range(N):
    if A[i]<0:
        cnt+=1
        l.append(A[i])
wa=0
l_ab=[]
for i in range(N):
    wa+=abs(A[i])
    l_ab.append(abs(A[i]))
if cnt%2!=0:
    wa-=2*min(l_ab)

print(wa)

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

m = 0
su = 0
mi = 10 ** 10
for ai in A:
    if ai < 0:
        m += 1
    mi = min(mi, abs(ai))
    su += abs(ai)

if m % 2 == 1:
    print(su - 2 * mi)
else:
    print(su)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
ans=0
c=0
tmp=10**9
for a in A:
    if a<0:
        c+=1
    ans+=abs(a)
    tmp=min(tmp,abs(a))
if c%2==0:
    print(ans)
else:
    print(ans-tmp*2)

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

s = sum(map(abs, A))
if sum(1 for a in A if a < 0) % 2 == 0:
    print(s)
else:
    print(s - 2 * min(map(abs, A)))

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

zero = 0
minus = 0
ans = 0

for i in range(N) :
    if A[i] == 0 :
        zero = 1
    elif A[i] < 0 :
        minus += 1
        A[i] *= -1

if zero or (minus % 2 == 0) :
    ans = sum(A)
else :
    ans = sum(A) - min(A) * 2

print(ans)

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

Solution (Python):
n = int(input())
num = list(map(int,input().split()))
numabs = [abs(i) for i in num]
cnt = 0           
for i in num :
    if i < 0 :
        cnt += 1

if cnt % 2 == 0 :
    print(sum(numabs))

if cnt % 2 == 1 :
    print(sum(numabs) - 2*min(numabs))

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

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

is_even = True
exists_zero = False
min_a = 10 ** 9
for i, a in enumerate(a_list):
    if a == 0:
        exists_zero = True
    else:
        is_even = is_even ^ (a < 0)
    if min_a > abs(a):
        min_a = abs(a)
    a_list[i] = abs(a)

all_plus = is_even | exists_zero
if all_plus:
    print(sum(a_list))
else:
    print(sum(a_list) - min_a * 2)

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

Solution (Python):
n = int(input())
w = input().split(" ")

a = []
m = 0
k = False
for i in range(n):
    a.append(int(w[i]))
    if a[i] < 0:
        a[i] *= -1
        k = not (k)
    if i == 0:
        m = a[i]
    if a[i] < m:
        m = a[i]

sum = sum(a)
if k:
    sum -= m*2
print(sum)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
abs_a = []
minus = 0

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

for i in range(n):
  abs_a.append(abs(a[i]))
  
if minus % 2 == 0:
  print(sum(abs_a))
else:
  min_abs_a = min(abs_a)
  print(sum(abs_a)-min_abs_a*2)

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

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

Solution (Python):

N = int(input())
A = [int(i) for i in input().split()]
if A[1] > 0:
	total_p = A[0]
	total_n = -A[0]
	B = [A[1],-A[1]]
else:
	total_p = -A[0]
	total_n = A[0]
	B = [-A[1],A[1]]
for i in range(2,N):
	if A[i] > 0:
		(total_p,total_n) = (max(total_p+B[0],total_n+B[1]),max(total_p+B[1],total_n+B[0]))
		B = [A[i],-A[i]]
	else:
		(total_p,total_n) = (max(total_p+B[1],total_n+B[0]),max(total_p+B[0],total_n+B[1]))
		B = [-A[i],A[i]]
print(max(total_n+B[1],total_p+B[0]))

Solution (Python):
import sys

stdin = sys.stdin

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

n = ni()
li = na()
ct = 0
s1 = 0
li2 = []
m = -1000000000000000000
for i in range(n):
    s1 += abs(li[i])
    li2.append(abs(li[i]))
    if li[i] < 0:
        ct += 1
if ct % 2 == 0:
    print(s1)
else:
    print(s1-2*min(li2))

Solution (Python):

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

cnt = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
a2 = [ abs(i) for i in a]
if cnt%2 == 0:
    print(sum(a2))
else:
    print(sum(a2)-min(a2)*2)

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

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
cnt = 0
for a in A:
    if a < 0:
        cnt += 1
res = 0
A = [abs(a) for a in A]
A.sort()
for a in A:
        res += a
if cnt%2 == 1:
    res -= 2*A[0]
print(res)