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()))
A.sort()
t = 0
i = 0
while True:
    if A[i]<0:
        A[i] = -1*A[i]
        t+=1
        if i==N-1:
            if t%2==0:
                break
            elif t%2==1:
                A[i] = -1*A[i]
                break
    elif A[i]>=0:
        if t%2==0:
            break
        elif t%2==1:
            X = -1*A[i]+A[i-1]
            Y = -1*A[i-1]+A[i]
            if X>=Y:
                A[i] = -1*A[i]
            else:
                A[i-1] = -1*A[i-1]
            break
    i+=1

print(sum(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]=-10**9+1

for i in range(0,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()))
dp = [[0] * 2 for i in range(n)]
dp[0][0],dp[0][1] = a[0], -a[0]
dp[1][0], dp[1][1] = a[0] + a[1], -a[0] + -a[1]

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


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

Solution (Python):
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce

import heapq
sys.setrecursionlimit(100001)






def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList




n = int(input())
data = getInputListInt()

cnt = 0
for i in range(n):
    if data[i] < 0:
        data[i] *= -1
        cnt += 1
sum_num = sum(data)

data.sort()
if cnt % 2 == 1:
    sum_num -= 2*data[0]

print(sum_num)

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
abs_A=[abs(a) for a in A]
sum_abs_A=sum(abs_A)

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

print(sum_abs_A if neg%2==0 else sum_abs_A-2*min(abs_A))

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

ans,cnt,mini=[],0,float('inf')
for a in A:
  if abs(a)!=a: cnt+=1
  ans.append(abs(a))
  mini=min(mini,abs(a))
if cnt%2==0:
  print(sum(ans))
else:
  print(sum(ans)-(mini*2))

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

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

s = 0
mini = 10000000000000
count = 0
for i in t:
    if i < 0:
        count += 1
    s += abs(i)
    mini = min(mini, abs(i))
if count%2 == 0:
    print(s)
else:
    print(s-mini*2)

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

ans = 0
cnt = 0
for i in a:
    if i < 0:
        cnt += 1
    ans += abs(i)
if cnt % 2 == 0:
    print(ans)
else:
    ans -= abs(min(aa)) * 2
    print(ans)

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

ans = 0
m = 10**10
k = 0
for i in range(N):
    ans += abs(A[i])
    m = min(m,abs(A[i]))
    if A[i] < 0:
        k += 1

if k % 2 == 0:
    print(ans)
else:
    print(ans - 2*m)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
mic = 0
for i in range(n):
    if a[i]<0: 
        mic += 1
        a[i] *= -1
if mic%2:
    a.sort()
    print(sum(a[1:])-a[0])
else:
    print(sum(a))

Solution (Python):
import numpy as np
input()
A = np.array(input().split(), dtype=np.int64)
S = np.sign(A)
A = np.sort(np.abs(A))
a = A[0]
print(A.sum() if 0 in S or not ((S == -1).sum() & 1) else A.sum() - a * 2)

Solution (Python):
import numpy as np
input()
A = np.array(input().split(), dtype=np.int64)
S = np.sign(A)
A = np.abs(A)
if 0 in S or not ((S == -1).sum() & 1):
    print(A.sum())
else:
    A.sort()
    print(A.sum() - A[0] * 2)

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

total = 0
ct = 0
min_num = 10**9
for i in l:
    total += abs(i)
    ct += 1 if i < 0 else 0
    min_num = min(min_num,abs(i))

if ct%2:
    print(total - min_num*2)
else:
    print(total)

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

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

B = []
t = 0
for i in A:
    if i < 0:
        t += 1
        B.append(abs(i))
    else:
        B.append(i)
    
if t % 2 == 0:
    print(sum(B))
else:
    print(sum(B) - 2 * min(B))

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

neg_cnt = 0
zero_cnt = 0

max_neg_v = -float("inf")
min_pos_v = float("inf")

for i in range(len(a)):
    if a[i] < 0:
        neg_cnt += 1
        max_neg_v = max(max_neg_v, a[i])
    elif a[i] == 0:
        zero_cnt += 1
    else:
        min_pos_v = min(min_pos_v, a[i])

if neg_cnt % 2 == 0 or zero_cnt > 0:
    print(sum(list(map(abs, a))))
else:
    print(max(sum(list(map(abs, a)))-2*min_pos_v, sum(list(map(abs, a)))+2*max_neg_v))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]
ninf = -float("inf")





n=ii()
arr=limii()

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

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

print(dp[n][0])

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

a, b, c = 0, 0, 0
for i in A:
    if i<0:
        a+=1
    elif i>0:
        c+=1
    else:
        b+=1

if b:
    ans = sum(map(abs, A))
elif c:
    for i,j in enumerate(A):
        if j>=0:break

    if a%2==0:
        ans = sum(map(abs, A))
    else:
        for i,j in enumerate(A):
            if j>=0:break
        ans = sum(map(abs, A)) + 2 * max(-abs(A[i-1]), -abs(A[i]))
else:
    if a%2 == 0:
        ans = sum(map(abs, A))
    else:
        ans = sum(map(abs, A[:-1]))+A[-1]

print(ans)

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

m = 0
ab = []
for i in a:
    if i < 0:
        m+=1
        i = i*-1
    ab.append(i)

if m%2 == 0:
    print(sum(ab))
else:
    ab.sort()
    print(sum(ab[1:])-ab[0] )

Solution (Python):
import sys
from fractions import gcd

N=input()
A=map(int, sys.stdin.readline().split())

minus_count=0
A_sum=0
A_min=float("inf")
for a in A:
    if a<0:
        minus_count+=1
    a=abs(a)
    A_min=min(A_min,a)
    A_sum+=a

if minus_count%2==0:
    print A_sum
else:
    print A_sum-A_min*2

Solution (Python):
n = int(input())
L = list(map(int,input().split()))
L1 = len([x for x in L if x < 0])
L.sort()
for i in range(n):
  if L[i] < 0:
    L[i] = -L[i]

if L1%2 == 0:
  print(sum(L))
else:
  print(sum(L)-2*min(L))

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

minus = 0
sm = 0
mn = abs(ls[0])

for i in range(n):
    if ls[i] < 0:
        minus += 1
    
    z = abs(ls[i])
    if z < mn:
        mn = z
    
    sm += z

if minus % 2 == 0:
    print(sm)
elif minus % 2 == 1:
    print(sm - 2 * mn)

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


zero_included = (0 in set(a))
negative_count = sum([item < 0 for item in a])
a_abs = sorted([abs(item) for item in a])

if zero_included or negative_count % 2 == 0:
    print(sum(a_abs))
else:
    print(sum(a_abs[1:]) - a_abs[0])

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

if A.count(0) >= 1:
    ans = 0
    for i in range(n):
        ans += abs(A[i])
else:
    ans = 0
    parity = 0
    absmin = 10**10
    for i in range(n):
        if A[i] < 0:
            parity += 1
        absmin = min(absmin, abs(A[i]))
        ans += abs(A[i])
    if parity % 2 == 0:
        pass
    else:
        ans = ans - absmin * 2
print(ans)

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

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

cnt = 0
min_abs = 10 ** 15
for a in A:
    if a < 0:
        cnt += 1
    min_abs = min(min_abs, abs(a))
        
if cnt % 2 == 0:
    print(sum(map(abs, A)))
else:
    print(sum(map(abs, A)) - min_abs * 2)

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

cnt_m,cnt_z=0,0
for i in range(n):
  if num[i]<0:
    cnt_m+=1
  elif num[i]==0:
    cnt_z+=1

num1=[abs(i) for i in num]  

if cnt_m%2==0:
  ans=sum(num1)
else:
  if cnt_z>0:
    ans=sum(num1)
  else:
    ans=sum(num1)-2*min(num1)
    
print(ans)

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

min_abs = abs(a[0])  
sum = 0   
p_neg = 0  
zero_exists = False  

for i in range(n):
    min_abs = min( min_abs, abs(a[i]))
    if a[i] < 0:
        p_neg = 1 - p_neg
        sum += -a[i]
    elif a[i] == 0:
        zero_exists = True
    else:
        sum += a[i]

if zero_exists or p_neg == 0:
    pass
else:
    sum -= 2 * min_abs

print(sum)

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

min_abs = abs(a[0])  
sum = 0   
p_neg = 0  
zero_exists = False  

for i in range(n):
    min_abs = min( min_abs, abs(a[i]))
    if a[i] < 0:
        p_neg = 1 - p_neg
        sum += -a[i]
    elif a[i] == 0:
        zero_exists = True
    else:
        sum += a[i]

if zero_exists or p_neg == 0:
    pass
else:
    sum -= 2 * min_abs

print(sum)

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

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

Solution (Python):
N = int(input())
A=list(map(int,input().split()))
cnt = 0
B=[None]*N
C=10**9+1
for i in range(len(A)):
  B[i]=abs(A[i])
  C=min(C,B[i])
  if A[i]<0:
    cnt+=1
ret = sum(B)-C+C*(-1)**cnt
print(ret)

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

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

cnt_minus = 0
wa = 0
small = 10 ** 10
for i in range(N):
    if A[i] < 0:
        cnt_minus += 1
    wa += abs(A[i])
    small = min(abs(A[i]), small)
    

if cnt_minus % 2 == 0:
    print(wa)
else:
    print(wa - (2 * small))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
sumabs = 0
minuscnt = 0
zerocnt = 0
minabs = 10**9+1
for i in range(n):
  if a[i] < 0:
    minuscnt += 1
  elif a[i] == 0:
    zerocnt += 1
  sumabs += abs(a[i])
  minabs = min(minabs, abs(a[i]))
if zerocnt > 0 or minuscnt % 2 == 0:
  print(sumabs)
else:
  print(sumabs - minabs * 2)

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

Solution (Python):
import numpy as np

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

dp = [[0, 0] for i in range(n+1)]
dp[0][1] = -np.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()))

cnt_m, cnt_z = 0, 0

for a in A:
    if a < 0:
        cnt_m += 1
    elif a == 0:
        cnt_z += 1

B = list(map(abs, A))

if cnt_m % 2 == 0 or cnt_z > 0:
    print(sum(B))
else:
    print(sum(B) - min(B)*2)

Solution (Python):
import numpy as np
n = int(input())
a = np.array(tuple(map(int, input().split())))
b = len(np.where(a < 0)[0])
a = abs(a)
if b % 2 == 0:
    print(np.sum(a))
else:
    print(np.sum(a) - 2 * np.min(a))

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

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
m=list(map(abs,l))
print(sum(m)-sum(i<0 for i in l)%2*min(m)*2)

Solution (Python):
n = int(input())
l = list(map(int,input().split()))
m = sorted(list(map(abs,l)))
print(sum(m) - sum(i<0 for i in l)%2*m[0]*2)

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

minus=0
abssum=0
absmin=10**9
for i in range(0,N):
    if A[i]<0:
        minus=minus+1
    if abs(A[i])<absmin:
        absmin=abs(A[i])
    abssum=abssum+abs(A[i])

if minus%2==0:
    print(abssum)
else:
    print(abssum-2*absmin)

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

minus_cnt=0
zero_flag=False
mn = 10**10
sm = 0

for i in range(N):
    if a[i] == 0:
        zero_flag=True
    if a[i] < 0:
        minus_cnt+=1
    if mn > abs(a[i]):
        mn = abs(a[i])
    sm+=abs(a[i])

if zero_flag or minus_cnt%2==0:
    print(sm)
else:
    print(sm-2*mn)

Solution (Python):
import bisect
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    i = bisect.bisect_left(A, 0)
    j = bisect.bisect_right(A, 0)
    if i % 2 == 0:
        print(sum([abs(i) for i in A]))
    else:
        if i != j:
            print(sum([abs(i) for i in A]))
        elif i == N:
            print(sum([abs(i) for i in A]) - 2 * abs(A[-1]))
        else:
            if abs(A[i-1]) > A[i]:
                print(sum([abs(i) for i in A]) - 2 * abs(A[i]))
            else:
                print(sum([abs(i) for i in A]) - 2 * abs(A[i-1]))
main()

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

Solution (Python):
import numpy as np
N = int(input())
a = np.array(list(map(int,input().split())))
b = a[a<0]
if len(b)%2==0:
    print(int(sum(np.abs(a))))
else:
    print(int(sum(np.abs(a))-2*min(np.abs(a))))

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

cnt = 0
for num in nums:
    if num < 0:
        cnt += 1

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

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

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

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

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

m = float("inf")
cnt = 0
ans = 0
for x in a:
    if x < 0:
        cnt += 1
    
    m = min(m, abs(x))
    ans += abs(x)

if cnt%2:
    ans -= m*2

print(ans)

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

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
mval = float('inf')
minus_cnt = 0
isZero = False
ans = 0

for a in A:
    if a < 0: minus_cnt += 1
    if a == 0: isZero
    mval = min(mval, abs(a))
    ans += abs(a)

if isZero or minus_cnt % 2 == 0: print(ans)
else: print(ans - mval*2)

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

minus_count = sum([1 for v in aa if v<0])
a = [abs(v) for v in aa]

if minus_count % 2 == 0:    
  print(sum(a))
else:
  print(sum(sorted(a)[1:]) - min(a))

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

b=list(filter(lambda x:x<0, a))
a = list(map(abs, a))


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

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

minus_cnt = 0
min_abs = 10 ** 15
for i in range(N):
  if A[i] < 0:
    minus_cnt += 1
    A[i] *= -1
  min_abs = min(min_abs, abs(A[i]))

print(sum(A) - 2 * min_abs * (minus_cnt % 2))

Solution (Python):
def solve(n, A):
    if A.count(0) > 0:
        return sum(map(abs, A))
    total = 0
    minval = 10 ** 9
    count = 0
    for a in A:
        total += abs(a)
        if a < 0:
            count += 1
        if abs(a) < minval:
            minval = abs(a)
    return total - (2 * minval if count % 2 == 1 else 0)

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    _ = int(input())
    A = list(map(int, input().split()))
    A_abs = [abs(a) for a in A]
    mc = sum([1 for a in A  if a < 0])

    ans = sum(A_abs)
    if mc % 2 != 0:
        ans -= min(A_abs) * 2
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = lambda: sys.stdin.readline().rstrip()

class Solution(object):
    def flipping_signs(self,N, A):

        oddeven = 1
        cnt = 0
        B = [0]*N
        for i in range(N):
            B[i] = abs(A[i])
            if A[i] == 0:
                oddeven = 0
            elif A[i] < 0:
                cnt += 1
        if cnt%2 == 0: oddeven = 0

        return sum(B)-2*min(B) if oddeven != 0 else sum(B) 

def main():

    N0 = int(read())
    A0 = tuple(map(int, read().split()))



    res = Solution().flipping_signs(N0, A0)

    print(res)
 
if __name__ == "__main__":
    main()

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

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

B = sorted(map(abs, A))
if negative % 2 == 1:
    B[0] = -B[0]

print(sum(B))

Solution (Python):
N, *A = map(int, open(0).read().split())
negative_num = sum(1 if a < 0 else 0 for a in A)
positive_num = list(abs(n) for n in A)

if negative_num % 2 == 0:
    print(sum(positive_num))
else:
    print(sum(positive_num) - 2*min(positive_num))

Solution (Python):
import sys
import numpy as np 

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main():
    tmp = np.absolute(a)
    if np.count_nonzero(a) != n:
        return tmp.sum()
    else:
        if np.count_nonzero(a < 0) & 1:
            return tmp.sum() - np.amin(tmp) * 2
        else:
            return tmp.sum()

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

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

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

Solution (Python):
import heapq
N = int(input())
A = list(map(int, input().split()))
heapq.heapify(A)
while True:
  m = heapq.heappop(A)
  n = heapq.heappop(A)
  if m + n >= 0:
    heapq.heappush(A, m)
    heapq.heappush(A, n)
    break
  else:
    heapq.heappush(A, -m)
    heapq.heappush(A, -n)
print(sum(A))

Solution (Python):
from numpy import*


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


if 0 in a:
  print(sum(b));exit()
  
  
minus_cnt=sum(a<0)


if minus_cnt%2==0:
  print(sum(b));exit()
  
  
print(sum(b)-min(b)*2)

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

if zero_in_a:
  tmp=[abs(i) for i in a]
  print(sum(tmp))
  exit()

minus_cnt=0
b=[]
for i in a:
  if i<0:
    minus_cnt+=1
    b.append(-i)
  else:
    b.append(i)

if minus_cnt%2==0:
  print(sum(b))
  exit()
  
c=min(b)
print(sum(b)-2*c)

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

c = 0

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

s = [abs(i) for i in A]

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

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

B = []
i = 0
while i < N:
  a = A[i]
  if a >= 0:
    B.append(a)
    i += 1
  else:
    if i+1 < N:
      if A[i+1] <= 0:
        B.extend([-a, -A[i+1]])
        i += 2
      else:
        B.append(-a)
        i += 1
        A[i] *= -1
    else:
      B.append(a)
      i += 1

if B[-1] >= 0:
  print(sum(B))
else:
  b = - B.pop()
  m = min(B)
  print(sum(B) + b - 2*min(m, b))

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

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

abssum=0
negative=0
mi=100000000000000
for i in range(N):
	if A[i]<0:
		negative+=1
	abssum+=abs(A[i])
	mi=min(mi,abs(A[i]))

if negative%2==1:
	abssum-=2*mi
print(abssum)

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

abs_sum=0
nega=0
mini=10**9+7

for i in range(N):
    a=abs(A[i])
    abs_sum+=a
    mini=min(mini,a)
    if A[i]<0:
        nega+=1

if nega%2==1:
    abs_sum-=2*mini
print(abs_sum)

Solution (Python):
N = int(input())
A = sorted(list(map(int, input().split())))
absA = [abs(a) for a in A]
if 0 in A:
    print(sum(absA))
else:
    num_minus = 0
    for a in A:
        if a < 0:
            num_minus += 1
        else:
            break

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

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

Solution (Python):
n = int(input())
a = sorted(map(int, input().split()))
print(sum(map(lambda a, b: abs(a + b), a[::2], a[1::2])) + (a[-1] if n % 2 == 1 else 0))

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

N = int(input())
A = list(map(int, input().split()))
cnt = 0
m = 10**18

for Ai in A:
    if Ai<0:
        cnt += 1
    
    m = min(m, abs(Ai))

if cnt%2==0:
    print(sum(abs(Ai) for Ai in A))
else:
    print(sum(abs(Ai) for Ai in A)-2*m)

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

negCnt = 0
absSum = 0
minAbs = float('inf')
for val in a:
    negCnt += val < 0
    absVal = abs(val)
    absSum += absVal
    minAbs = min(minAbs, absVal)
print(absSum - 2 * minAbs if negCnt & 1 else absSum)

Solution (Python):
N = input()
AA = input()
A = list(map(int, AA.replace('-', '').split()))
HC = AA.count('-')
if HC % 2 == 0:
    print(sum(A))
else:
    print(sum(A) - sorted(A)[0] * 2)

Solution (Python):
n = int(input())
l = list(map(int, input().split(' ')))
absl = [abs(i) for i in l]
mmm = len([True for i in l if i < 0])
if mmm % 2 == 0:
  print(sum(absl))
else:
  print(sum(absl) - min(absl)*2)

Solution (Python):
N = int(input())
As = [int(s) for s in input().split(' ')]
count_minus = len([a for a in As if a < 0])
As2 = [abs(a) for a in As]
As2.sort()
ret = sum(As2)

if count_minus % 2 == 1:
    ret -= As2[0] * 2

print(ret)

Solution (Python):
import os, sys, re, math

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

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

print(sum(A))

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

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

B_sum = 0
B = 10 ** 9
cnt = 0

for i in range(N):
  A = A_list[i]
  if A < 0:
    cnt += 1
    A = -A
  B_sum += A
  B = min(B, A)
  
if cnt % 2 == 0:
  print(B_sum)
else:
  print(B_sum - 2 * B)

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

*_a, = map(abs, a)
if sum(map(lambda x: x < 0, a))%2 == 0:
    print(sum(_a))
else:
    mi = min(_a)
    print(sum(_a)-2*mi)

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]=-a[i]
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()))
minus_num = 0
for i in range(n):
    if a[i] < 0:
        minus_num += 1
if minus_num % 2 == 0:
    ans = 0
    for i in range(n):
        ans += abs(a[i])
else:
    min_abs = abs(a[0])
    ans = 0
    for i in range(n):
        ans += abs(a[i])
        min_abs = min(min_abs, abs(a[i]))
    ans = ans - min_abs * 2
print(ans)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
count=len([i for i in A if i<0])
A=[i if i>=0 else -i for i in A]

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

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

for i in range(n):
    if a[i] < 0:
        ne_num += 1
if ne_num % 2 == 0:
    print(sum(list(map(abs, a))))
    exit()

min_b = 10**9
for i in range(n):
    if abs(a[i]) < min_b:
        min_b = abs(a[i])
print(sum(list(map(abs, a))) - 2*min_b)

Solution (Python):
N = int(input())
A=sorted(list(map(int,input().split())))
dp = [[0 for i in range(N)] 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])
dp[0][-1] = max(dp[0][-2]+A[-1],dp[1][-2]-A[-1])
print(max(dp[0][-1],dp[1][-1]))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MIN_A = min(map(abs, A))
MINUS = 0

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

if min(A) > 0:
  print(sum(A))
  exit(0)
  
ans = 0
if MINUS % 2 == 0:
  for a in A:
    ans += abs(a)
else:
  for a in A:
    ans += abs(a)
  ans -= MIN_A * 2

print(ans)

Solution (Python):
import numpy as np

n = int(input())
a = np.array(list(map(int, input().split())), dtype=np.int64)

if np.sum([a < 0]) % 2 == 0 or np.sum([a == 0]) > 0:
    print(np.sum(np.abs(a)))
else:
    print(np.sum(np.abs(a)) - np.min(np.abs(a)) * 2)

Solution (Python):
import math
import numpy as np
from fractions import gcd
import fractions
import statistics
import collections
from functools import reduce
import itertools
from collections import defaultdict

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

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

if (cnt%2 == 0 or cnt0>=1):
    print(sum(np.abs(np.array(A))))
else:
    print(sum(np.abs(np.array(A)))-min(np.abs(np.array(A)))*2)

Solution (Python):
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor


"""
need to consider the case that ticket is not enough to lower everything
"""

N = gi()
nps = []
ns = []

for i in range(N):
    a = gi()
    if a < 0:
        ns.append(-a)
    else:
        nps.append(a)

ns.sort()
nps.sort()

base = sum(ns) + sum(nps)

if len(ns) % 2:
    ans = base - 2 * ns[0]
    if len(nps):
        ans = max(ans, base - 2 * nps[0])
else:
    ans = base

print(ans)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split(" ")))
    negative = 0
    result = 0
    abs_minimum = 10**9
    for a in A:
        abs_minimum = min(abs_minimum, abs(a))
        if a < 0:
            negative += 1
    if negative % 2 == 0:
        for a in A:
            result += abs(a)
    else:
        for a in A:
            if abs(a) == abs_minimum:
                result += min(a, -a)
            else:
                result += abs(a)
    print(result)


if __name__ == '__main__':
    main()

Solution (Python):
import math
def calculate(arr1,arr2,zeroExist):
    if (len(arr1) % 2 == 0) or (zeroExist == True):
        return sum(arr2) + sum(arr1)
    else:
        return sum(arr2) + sum(arr1) - 2 * (calculateAbsSmallest(arr1,arr2))


def calculateAbsSmallest(arr1,arr2):
    arr1.sort()
    arr2.sort()
    if len(arr2) == 0:
        return arr1[0]
    return min(arr1[0],arr2[0])

N = int(input())

arr1 = []
arr2 = []
zeroExist = False
for s in input().split(" "):
    if int(s) == 0:
        zeroExist = True
    if int(s) < 0:
        arr1.append(abs(int(s)))
    else:
        arr2.append(int(s))

arr1 = list(arr1)
arr2 = list(arr2)

res = calculate(arr1,arr2,zeroExist)
print(res)

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

minus_cnt = 0
zero_cnt = 0
for ai in A:
    if ai == 0:
        zero_cnt += 1
    elif ai < 0:
        minus_cnt += 1

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

sm_a = sum(A)
min_a = min(A)

if zero_cnt > 0:
    print(sm_a)
else:
    if minus_cnt % 2 == 0:
        print(sm_a)
    else:
        r = sm_a - 2 * min_a
        print(r)

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

abs_a = list(map(abs, a))
sm_abs_a = sum(abs_a)
min_a = min(abs(a[i]) for i in range(len(a)))

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

if cnt%2 == 0:
    print(sm_abs_a)
else:
    print(sm_abs_a - min_a*2)