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):
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    cnt_minus = 0
    zero_flag = False
    for i, a in enumerate(A):
        if a < 0:
            cnt_minus += 1
        elif a == 0:
            zero_flag = True

    ans = 0
    if cnt_minus % 2 == 0 or zero_flag:
        ans = sum(abs(a) for a in A)
    else:
        ans = sum(abs(a) for a in A) - min(abs(a) for a in A) * 2
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
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])
B.sort()
if cnt%2==0:
    print(sum(B))
else:
    print(sum(B)-2*B[0])

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
j=n
for i in range(n):
    if a[i]>=0:
        j=i
        break
a=list(map(abs,a))
a.sort()
if j%2==0:
    print(sum(a))
else:
    print(sum(a)-2*a[0])

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

ans = 0
m = 10 ** 9 + 1
cnt = 0
for a in A:
    if a < 0:
        cnt ^= 1
        a *= -1
    m = min(m, a)
    ans += a

if cnt:
    ans -= 2 * m

print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
D=0
zcnt=0
fcnt=0
m=10**9
for i in range(N):
  D+=abs(A[i])
  m=min(m,abs(A[i]))
  if A[i]<0:
    fcnt+=1
  elif A[i]==0:
    zcnt+=1

if ((fcnt%2)==1) and (zcnt==0):
  print(D-2*m)  
else:
  print(D)

Solution (Python):
n = int(input())
check = []
l = []
li = list(map(int,input().split()))
for a in li:
    if a > 0:
        check.append(1)
        l.append(a)
    elif a < 0:
        check.append(-1)
        l.append(-a)
    else:
        check.append(0)
        l.append(a)
for i in range(n-1):
    if check[i] == -1:
        check[i] = 1
        check[i+1] *= -1

if check[-1] == -1:
    print(sum(l)-2*min(l))
else:
    print(sum(l))

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

mc = 0
absum = 0
absmin = 10**9+7

for a in A:
    if a < 0:
        mc += 1
    absum += abs(a)
    absmin = min(absmin,abs(a))

if mc%2 == 0:
    ans = absum
else:
    ans = absum-absmin*2

print(ans)

Solution (Python):
n = int(input())
List = list(map(int,input().split()))
counter = 0
min = abs(max(List))
sum = 0
for item in List:
  if item < 0:
    counter += 1
  if abs(item) <= min:
    min = abs(item)
  sum += abs(item)
if counter % 2 == 0:
  Answer = sum
else:
  Answer = sum - min*2
print(Answer)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
na = [abs(i) for i in a]
m = min(na)
s = sum(na)
cnt = 0

for i in a:
    if i < 0:
        cnt += 1
if cnt%2 == 0 or m == 0:
    ans = s
else:
    ans = s-2*m

print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
na = [abs(i) for i in a]
m = min(na)
s = sum(na)

if m == 0:
    ans = s
else:
    cnt = 0
    for i in a:
        if i < 0:
            cnt += 1
    if cnt%2 == 0:
        ans = s
    else:
        ans = s-2*m

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
num_negative = 0
zero_flag = False
for a in A:
    if zero_flag:
        zero_flag = True
    if a < 0:
        num_negative += 1
total = sum([abs(a) for a in A])
if num_negative % 2 == 0 or zero_flag:
    print(total)
else:
    print(total - 2 * min([abs(a) for a in A]))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
s=sum(map(abs,a))
m=min(list(map(abs,a)))
z=[]
for i in range(n):
    if a[i]<0:
        z.append(a[i])

if len(z)%2:
    print(s-2*m)
else:
    print(s)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
INF = float('inf')

dp = [[-INF for _ in range(2)] for _ in range(N+1)]
dp[0][0] = dp[0][1] = sum(A)

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

    dp[i+1][1] = max(dp[i+1][1], dp[i][0] - (A[i] + A[i+1]) + (-A[i]-A[i+1]))
    if i > 0:
        dp[i+1][1] = max(dp[i+1][1], dp[i][1] - (-A[i] + A[i+1]) + (A[i]-A[i+1]))

print(max(dp[N-1]))

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

c = 0
f = 0
for i in range(N):
    if A[i] < 0:
        c += 1
    elif A[i] == 0:
        f = 1
    A[i] = abs(A[i])
    
if f == 1 or c % 2 == 0:
    ans = sum(A)
else:
    ans = sum(A) - 2 * min(A)
    
print(ans)

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

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    count = 0
    ans = 0
    mi = float("inf")

    for a in A:
        ans += abs(a)
        mi = min(mi, abs(a))
        if a <= 0:
            count += 1

    if count & 1:
        print(ans - mi * 2)
    else:
        print(ans)

    
    

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mn = 10**9+1
minus = 0
zero = 0
ans = 0
for i in a:
    if abs(i) < mn:
        mn = abs(i)
    if i < 0:
        minus += 1
    if i == 0:
        zero += 1
    ans += abs(i)

tmp = mn if zero == 0 and minus % 2 else 0
print(ans - tmp * 2)

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    v = list(map(int, input().strip().split()))
    s = 0
    m = INF
    su = 0
    for i in range(n):
        if v[i] < 0:
            s += 1
        if abs(v[i]) < m:
            m = abs(v[i])
        su += abs(v[i])
    if s % 2 == 0:
        print(su)
    else:
        print(su - 2 * m)

if __name__ == '__main__':
    main()

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

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)
if cnt%2==0:
    print(sum(a))
else:
    print(sum(a)-min(a)*2)

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] *= -1

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
NS = sum(int(a < 0) for a in A)
S = sum(abs(a) for a in A)
m = min(abs(a) for a in A)
print(S - 2 * m if NS & 1 else S)

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

minus_count = 0
A_abs = sorted(list(map(abs, A)))

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

if minus_count % 2 == 0:
    print(sum(A_abs))
else:
    print(sum(A_abs) - A_abs[0] * 2)

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

nums = list(map(int, input().split(' ')))

abs_sum = 0
count = 0
min_value = abs(nums[0])
for i in range(N):
  abs_sum += abs(nums[i])
  if nums[i] < 0:
    count += 1
  if abs(nums[i]) < min_value:
    min_value = abs(nums[i])

if count % 2 == 1:
  print(abs_sum - 2*min_value)
else:
  print(abs_sum)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
cnt = 0
target = 10**10
sum_A = 0
for a in A:
	if a < 0:
		cnt+=1
		sum_A+=-a
	else:
		sum_A+=a
		
	if target > abs(a):
		target = abs(a)

if cnt%2==0:
	print(sum_A)
else:
	print(sum_A - 2*target)

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


_ = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

A = np.array(A, dtype=int)
cnt = np.count_nonzero(A < 0)
A = np.abs(A)
if cnt & 1:
    ans = A.sum() - A.min() * 2
else:
    ans = A.sum()
print(ans)

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.sort()
cnt %= 2
print(sum(a) - 2 * sum(a[:cnt]))

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

Solution (Python):
def solve():
    N, *A = map(int, open(0).read().split())
    
    dp = [[0 for _ in range(2)] for _ in range(N+1)]
    dp[0][1] = -10**15
    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])


if __name__ == '__main__':
    solve()

Solution (Python):
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines





import numpy as np

def main():
	n=int(input())
	A= np.array(read().split(), np.int64)
	nega=len(A[A<0])
	B=abs(A)
	ans=np.sum(B)
	
	if nega%2:
		ans-=2*np.min(B)
	
	print(ans)
	
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:
        A[i] *= -1
        count += 1

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    n=int(input())
    aa=LI()
    pp=[]
    mm=[]
    for a in aa:
        if a<0:mm.append(a)
        else:pp.append(a)
    if not mm:
        print(sum(pp))
        exit()
    if not pp:
        if len(mm)%2:
            print(-sum(mm)+max(mm)*2)
        else:
            print(-sum(mm))
        exit()
    if len(mm)%2:
        m=max(mm)
        p=min(pp)
        if p+m>=0:print(sum(pp)-sum(mm)+2*m)
        else:print(sum(pp)-2*p-sum(mm))
    else:
        print(sum(pp)-sum(mm))

main()

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

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

a1 = a[:]

for i in range(N-1):
    if a1[i] < 0:
        a1[i] *= -1
        a1[i+1] *= -1
    a[i] = abs(a[i])

a[N-1] = abs(a[N-1])

print(max(sum(a1), sum(a)-2*min(a)))

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

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

B = [abs(a) for a in A]
negatives = sum([1 for a in A if a<0])



if negatives % 2:
	min_B = min(B)
	ans = sum(B) - (2*min_B)
else:
	ans = sum(B)

print(ans)

Solution (Python):
import copy
n=int(input())
a=list(map(int,input().split()))
absa=[]

for i in a:
  absa.append(abs(i))

mi=0
pl=0
for i in a:
  if i<0:
    mi+=1
  else:
    pl+=1


def jud(x):
  temp=copy.copy(x)
  for i in range(len(temp)-1):
    if temp[i]>=0:
      continue
    else:
      temp[i]*=-1
      temp[i+1]*=-1
  if temp[-1]>=0:
    return 1
  else:
    return 0

if jud(a)==1:
  print(sum(absa))
else:
  print(sum(absa)-min(absa)*2)

Solution (Python):

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

minus_odd = len(list(filter(lambda x: x < 0, A))) % 2 != 0

a = list(map(lambda x: abs(x), A))
if minus_odd:
  mini = min(a)
  print(sum(a) - mini * 2)
else:
  print(sum(a))

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

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

Solution (Python):
n = int(input())
a =  list(map(int,input().split()))
dp = [[0]*2 for i in range(n+1)]
dp[0][0] = 0
INF = -10**9
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):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = 0
    for i in range(N):
        if A[i] < 0:
            cnt += 1
        A[i] = abs(A[i])

    A.sort()
    if cnt % 2 == 1:
        print(sum(A) - 2 * A[0])
    else:
        print(sum(A))

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
ls=[int(s) for s in input().split()]
_abs=[0 for _ in range(N)]
zero=0
minus=0
for i in range(N):
  if ls[i]<0:
    minus+=1
    _abs[i]=-ls[i]
  elif ls[i]==0:
    zero+=1
  else:
    _abs[i]=ls[i]
if zero>0:
  print(sum(_abs))
elif minus%2==0:
  print(sum(_abs))
else:
  print(sum(_abs)-2*min(_abs))

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

n_minus = 0

for a in list_a:
  if a < 0:
    n_minus += 1

if n_minus % 2 == 0:
  print(sum(list(map(abs, list_a))))
else:
  list_a_min = min(list(map(abs,list_a)))
  print(sum(list(map(abs, list_a))) - 2 * list_a_min)

Solution (Python):


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

cnt = 0
a2 = []
for i in range(n):
    if a[i]<0:
        cnt += 1
        a2.append(a[i]*(-1))
    else:
        a2.append(a[i])

if cnt%2 == 0:
    print(sum(a2))
else:
    memo = 10**9
    for i in range(n):
        memo = min(abs(a[i]),memo)
    print(sum(a2)-2*memo)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
mn=10**18
ng=0
sm=0
for i in a:
  sm+=abs(i)
  mn=min(mn,abs(i))
  if i<0:
    ng+=1
if ng%2==0:
  print(sm)
else:
  print(sm-mn*2)

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

b = []
count = 0
for i in a:
    if i < 0:
        count += 1
    b.append(abs(i))

if count % 2:
    print(sum(b) - 2 * min(b))
else:
    print(sum(b))

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

dp = [[0] * 2 for i 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[n][0])

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

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
c=0
s=0
Az=[]
for i in A:
    if i<0:
        c+=1

    s+=abs(i)
    Az.append(abs(i))
if c%2==0:
    print(s)
else:
    print(s-2*min(Az))

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

res = 0
min_abs = float('inf')
cnt_neg = 0
for a in A:
    if a < 0:
        cnt_neg += 1
    abs_a = abs(a)
    res += abs_a
    if min_abs > abs_a:
        min_abs = abs_a

if cnt_neg%2==0:
    print(res)
else:
    print(res-2*min_abs)

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

if c%2==0:
    print(sum(a))
else:
    print(sum(a)-2*min(a))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
count = 0
for a in A:
    if a < 0:
        count += 1
    elif a == 0:
        count = 0
        break
A = list(map(abs, A))
A.sort()
if count % 2 == 0:
    print(sum(A))
else:
    print(sum(A[1:]) - A[0])

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

has_zero = False
cnt = 0
for a in A:
    if a < 0:
        cnt += 1
    elif a == 0:
        has_zero = True

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

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

cnt = 0
for Ai in A:
    cnt += int(Ai < 0)

if cnt % 2 == 0:
    print(sum([abs(Ai) for Ai in A]))
else:
    ans_sum = 0
    ans_min = 10 ** 9 + 7
    for Ai in A:
        ans_sum += abs(Ai)
        ans_min = min(ans_min, abs(Ai))
    
    print(ans_sum - 2 * ans_min)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np

N = int(readline())
A = [int(x) for x in readline().rstrip().split()]

B = []
cnt = 0
for i in A:
    if i < 0:
        cnt += 1
    B.append(abs(i))

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

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())
L=list(map(int,input().split()))
c=0
s=0
mi=10**10
for i in range(N):
    if(L[i]<0):
        c+=1
    s+=abs(L[i])
    if(abs(L[i])<mi):
        mi=abs(L[i])
if(c%2==0):
    print(s)
    exit()
print(s-(2*mi))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
num_minus = 0
A_abs = []
for a in A:
    if a < 0:
        num_minus += 1
    A_abs.append(abs(a))
A_abs.sort()
if num_minus % 2 == 0:
    print(sum(A_abs))
else:
    print(sum(A_abs) - 2 * A_abs[0])

Solution (Python):
import numpy as np

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

count  = 0
for i in a:
    if i < 0:
        count += 1
    elif i == 0:
        print(sum(np.abs(a)))
        exit()

if count % 2 == 0:
    print(sum(np.abs(a)))
else:
    a = np.abs(a)
    a.sort()
    b = a[0]
    a = np.delete(a, 0, 0)
    print(sum(a) - b)

Solution (Python):
from sys import stdin

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

point = 0
mi = 10**10
total = 0

for i in li:
    if i < 0:
        point += 1
    mi = min(mi,abs(i))
    total += abs(i)
if point % 2 == 0:
    print(total)
else:
    print(total-mi*2)

Solution (Python):
N=int(input())
import numpy as np
A=np.array(list(map(int,input().split())))
m=np.sum(A<0)
flag=np.any(A==0)
A=np.abs(A)
ans=np.sum(A)
if (m%2==1)and(not flag):
  x=np.min(A)
  ans-=x*2

print(ans)

Solution (Python):
N=int(input())
import numpy as np
A=np.array(list(map(int,input().split())))
m=np.sum(A<0)
A=np.abs(A)
ans=np.sum(A)
if m%2==1:
  x=np.min(A)
  ans-=x*2

print(ans)

Solution (Python):

N = int(input())
A = [int(i)for i in input().split()]
p = 0
min = 10**9 + 1
ans = 0
for i in A:
    if i < 0:
        p += 1
    i = abs(i)
    ans += i
    if min > i:
        min = i
if p%2 ==1:
    ans -= min*2
print(ans)

Solution (Python):






import numpy as np





N = int(input())
A = np.array([int(x) for x in input().split()])





A = A.astype('int64')





if np.count_nonzero(A < 0) % 2 == 0:
    print(sum(abs(A)))
else:
    print(sum(abs(A)) - 2 * min(abs(A)))

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

    dp = [[-1] * 2 for _ in range(n + 1)]
    dp[0][False] = 0
    

    for j, x in enumerate(a):
        if dp[j][True] == -1:
            dp[j + 1][False] = dp[j][False] + x
            dp[j + 1][True] = dp[j][False] - x
        else:
            dp[j + 1][False] = max(dp[j][False] + x, dp[j][True] - x)
            dp[j + 1][True] = max(dp[j][False] - x, dp[j][True] + x)
    return dp[n][False]


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

Solution (Python):
from bisect import bisect_left

n = int(input())
a = tuple(sorted(map(int, input().split())))
b = tuple(sorted(map(abs, a)))

j = bisect_left(a, 0)
m = a[:j]

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

Solution (Python):
INF = 1e10

n = int(input())
a = list(map(int, input().split()))
flag = True
a_min = INF
ans = abs(a[-1])
for i in range(n-1):
    ans += abs(a[i])
    if a[i]<0:
        a[i] = -1*a[i]
        a[i+1] = -1*a[i+1]
    a_min = min(a_min, abs(a[i]))
a_min = min(a_min, abs(a[-1]))
if a[-1]<0:
    ans = ans - 2*a_min
print(ans)

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

dp = [[0,-10**9] for _ in range(n+1)]

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

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

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input().strip())
A = list(map(int, input().strip().split(" ")))
minus_count = 0
minimum = float("inf")
S = 0
for a in A:
    if a < 0:
        minus_count += 1
        a *= -1
    minimum = min(a, minimum)
    S += a
if minus_count % 2 == 1:
    S -= 2*minimum

print(S)

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

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

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

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

Solution (Python):
def main():
    _ = int(input())
    A = [int(i) for i in input().split()]
    cnt_minus = 0
    zero_flag = False
    for i, a in enumerate(A):
        if a < 0:
            cnt_minus += 1
        elif a == 0:
            zero_flag = True

    ans = 0
    if cnt_minus % 2 == 0 or zero_flag:
        ans = sum(abs(a) for a in A)
    else:
        ans = sum(abs(a) for a in A) - min(abs(a) for a in A) * 2
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    cnt_minus = 0
    zero_idx = []
    for i, a in enumerate(A):
        if a < 0:
            cnt_minus += 1
        elif a == 0:
            zero_idx.append(i)
    flag = False
    for z in zero_idx:
        if (0 < z and A[z-1] < 0) or (z < N - 1 and A[z+1] < 0):
            flag = True

    ans = 0
    if cnt_minus % 2 == 0:
        ans = sum(abs(a) for a in A)
    elif flag:
        ans = sum(abs(a) for a in A)
    else:
        ans = sum(abs(a) for a in A) - min(abs(a) for a in A) * 2
    print(ans)


if __name__ == '__main__':
    main()

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

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

p=0
for i in range(n):
    if l[i]<0:
        l[i]=-l[i]
        p+=1
if p/2==p//2:
    print(sum(l))
else:
    print(sum(l)-2*min(l))

Solution (Python):



n = int(input())
a = list(map(int, input().split()))
n=len(a)
mns = [ai for ai in a if ai<0]
pls = [ai for ai in a if ai>=0]

mns.sort()
pls.sort()


lm = len(mns)
m_rem = 0
if lm%2:
    if pls:
        if pls[0]<-1*mns[-1]:
            tmp = -1*mns[-1]
            mns[-1] = -1*pls[0]
            pls[0] = tmp
    m_rem = mns.pop()

print(sum(pls)-sum(mns) + m_rem)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
minabs=10**9+1
minus=0
allsum=0
for i in a:
  if i<0:
    minus+=1
  minabs=min(minabs,abs(i))
  allsum+=abs(i)

if minus%2==1:
  allsum-=minabs*2
print(allsum)

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.sort()
if cnt % 2 == 0:
  print(sum(a))
else:
  print(sum(a)-2*a[0])

Solution (Python):
N = input()
A = list(map(int, input().split()))
plus = []
minus = []
for a in A:
    if a >= 0:
        plus.append(a)
    else:
        minus.append(-a)
if len(minus) % 2 == 0:
    sum_value = sum(plus + minus)
    print(sum_value)
else:
    min_value = min(plus + minus)
    sum_value = sum(plus + minus) - min_value*2
    print(sum_value)

Solution (Python):
def p_d():
    n = int(input())
    *a, = map(int, input().split())
    *b, = filter(lambda x: x <= 0, a)
    *c, = map(abs, a)
    if len(b) & 1 == 0:
        print(sum(c))
    else:
        print(sum(c) - 2 * sorted(c)[0])


if __name__ == '__main__':
    p_d()

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
abs_min = float("inf")
ans = 0
cnt = 0
for i in range(N):
	if A[i] < 0:
		cnt += 1
	tmp = abs(A[i])
	abs_min = min(abs_min, tmp)
	ans += tmp

if cnt % 2 == 0:
	print(ans)
else:
	print(ans - 2*abs_min)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
absa = [abs(a) for a in A]
m = 0
for a in A:
    if a < 0:
        m += 1
if m % 2 == 0:
    print(sum(absa))
else:
    print(sum(absa) - min(absa)*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())
a = [int(_) for _ in input().split()]
m = float('inf')
i = 0
total = 0
minus = 0
while i < n:
    if a[i] < 0:
        m = min(m, -a[i])
        total -= a[i]
        minus += 1
    else:
        m = min(m, a[i])
        total += a[i]
    i += 1
if minus % 2 == 1:
    ans = total - 2 * m
else:
    ans = total
print(ans)

Solution (Python):
import heapq


n = int(input())
a = [int(_) for _ in input().split()]
q = []
heapq.heapify(q)
i = 0
total = 0
minus = 0
while i < n:
    if a[i] < 0:
        heapq.heappush(q, -a[i])
        total -= a[i]
        minus += 1
    else:
        heapq.heappush(q, a[i])
        total += a[i]
    i += 1
if minus % 2 == 1:
    ans = total - 2 * heapq.heappop(q)
else:
    ans = total
print(ans)

Solution (Python):
N=int(input())
A=[int(x) for x in input().split()]
count_f=0
count_0=0
B=[]
for i in range(N):
  B += [abs(A[i])]
  if A[i]==0:
    count_0 +=1
  elif A[i]<0:
    count_f +=1
if count_f%2==0 or count_0>0:
  print(sum(B))
else:
  print(sum(B)-2*min(B))

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
abA = [abs(i) for i in A]
mc = [i < 0 for i in A].count(True)
mv = min(abA)
sm = sum(abA)

if mc % 2 == 0:
    print(sm)
else:
    print(sm - 2 * mv)

Solution (Python):

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

if len([a for a in A if a == 0]) > 0:
    n = sum(map(abs, A))
    print(n)

elif len([a for a in A if a < 0]) % 2 == 0:
    n = sum(map(abs, A))
    print(n)

else:
    A.sort(key=lambda x: abs(x))
    n = sum(map(abs, A[1:]))
    n -= abs(A[0])
    print(n)

Solution (Python):
import math

INF = float("inf")



def good(N, A):
    even = 0
    zero = 0
    c = 0

    ans = 0
    for i in A:
        if i < 0:
            c += 1
        elif i == 0:
            even = 0
            c = 0
        else:
            if c % 2 != 0:
                even += 1
            c = 0
        ans += abs(i)

    if c != 0 and c % 2 != 0:
        even += 1

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


def main():
    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] = -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])
    


if __name__ == '__main__':
    main()

Solution (Python):
import math




def main():
    N = int(input())
    A = list(map(int, input().split()))
    even = 0
    zero = 0
    c = 0

    ans = 0
    for i in A:
        if i < 0:
            c += 1
        elif i == 0:
            even = 0
            c = 0
        else:
            if c % 2 != 0:
                even += 1
            c = 0
        ans += abs(i)

    if c != 0 and c % 2 != 0:
        even += 1

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


if __name__ == '__main__':
    main()

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

sum_list = [ ]
nagative_count = 0
for i in range(N):
    if An[i] < 0 :
        sum_list.append(An[i]*(-1))
        nagative_count += 1
    else: 
        sum_list.append(An[i])

if nagative_count%2 == 0:
    print(sum(sum_list))
else:
    sum_list.sort()
    sum_list[0] = sum_list[0]*(-1)
    print(sum(sum_list))