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()))
m = 0
for i in range(n):
	if a[i] < 0:
		m = m + 1
b = list(map(abs,a))
b.sort()
ans = 0
if m % 2 == 0:
	for j in range(n):
		ans = ans + b[j]
else:
	for j in range(n):
		if j == 0:
			ans = ans - b[0]
		else:
			ans = ans + b[j]
print(ans)

Solution (Python):


def abs_list_sum(numbers):
    result = 0
    for v in numbers:
        result += abs(v)
    return result


def abs_min(numbers):
    result = abs(numbers[0])
    for v in numbers:
        if result > abs(v):
            result = abs(v)
    return result

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    negative_count = 0
    for v in a:
        if v < 0:
            negative_count += 1
    if negative_count % 2 == 0:
        print(abs_list_sum(a))
    else:
        minimum = abs_min(a)
        print(abs_list_sum(a) - 2 * minimum)


if __name__ == '__main__':
    main()

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

minus_count = 0
plus_list = []
for x in n_list:
  if x < 0:
    minus_count += 1
  plus_list.append(abs(x))
    
if minus_count % 2 == 0 or 0 in plus_list: 
  print(sum(plus_list))
else:
  print(sum(plus_list) - 2 * min(plus_list))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
abss = [abs(x) for x in a]
ans = sum(abss)
minus = [-x for x in a if x <= 0]

if len(minus) % 2 == 0:
    print(ans)
    exit(0)

ans -= 2 * min(abss)

print(ans)

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

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

Solution (Python):
n = int(input())
a_lst = []
cnt = 0
for elem in input().split():
    if int(elem) < 0:
        cnt += 1
        a_lst.append((-1) * int(elem))
    else:
        a_lst.append(int(elem))

if cnt % 2 == 0:
    print(sum(a_lst))
else:
    print(sum(a_lst) - 2 * sorted(a_lst)[0])

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
cnt = 0
for i in range(len(a)):
	if a[i] < 0:
		cnt += 1
		a[i] *= -1

if cnt % 2 == 0:
	print(sum(a))
else:
	a[a.index(min(a))] *= -1
	print(sum(a))

Solution (Python):
import numpy as np

def rev(i):
    if i==0:
        return 1
    return 0

N=int(input())
A=np.array(list(map(int,input().split())))
s=[]
for i in range(N):
    if A[i]>=0:
        s.append(1)
    else:
        s.append(0)

s[::-1]
for i in range(N-1):
    if s[i]==0:
        s[i]=1
        s[i+1]=rev(s[i+1])
if np.sum(s)!=N:
    ans=np.sum(np.abs(A))-2*np.min(np.abs(A))
    print(ans)
else:
    print(np.sum(np.abs(A)))

Solution (Python):
N = int(input())
A = list(map(int , input().split()))
Pos_min =  10**9
Neg_max = -10**9
Sum = 0

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

if M % 2 == 1:
	for n in range(N):
		if A[n] < 0:
			Neg_max = max(Neg_max , A[n])
		else:
			Pos_min = min(Pos_min , A[n])


	
	if abs(Neg_max) < abs(Pos_min):
		A.remove(Neg_max)
		Sum += Neg_max
	else:
		A.remove(Pos_min)
		Sum -= Pos_min
	
	for n in range(N-1):
		Sum += abs(A[n])

else:
	for n in range(N):
		Sum += abs(A[n])

print(Sum)

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

a.sort(reverse=False)

for i in range(n-1):

    if a[i] < 0:

        if a[i+1] >= 0:

            if -a[i] > a[i+1]:
                a[i] = -a[i]
                a[i+1] = -a[i+1]
                b.append(a[i])

                for j in range(i+1,n-1):
                    b.append(a[j])
                break

            else:
                b.append(a[i])

                for j in range(i+1,n-1):
                    b.append(a[j])
                break

        a[i] = -a[i]
        a[i+1] = -a[i+1]
        b.append(a[i])

    else:
        b.append(a[i])

ans = sum(b) + a[n-1]

print(ans)

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

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

if cnt % 2 == 0:
    print(sum(map(abs, A_list)))
else:
    A_list_abs = list(map(abs, A_list))
    minimum = min(A_list_abs)
    A_list_abs.remove(minimum)
    print(sum(A_list_abs) - minimum)

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

neg = [x for x in a if x < 0]

b = len(neg) % 2 == 0

if b:
    print(sum([abs(x) for x in a]))
else:
    a.remove(max(neg))
    flip = [abs(x) for x in a]
    if -max(neg) > min(flip):
        print(sum(flip) - min(flip) * 2- max(neg))
    else:
        print(sum(flip) + max(neg))

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=list(map(int,input().split()))
sign=[1 if i<0 else 0 for i in a]
a_abs=[abs(i) for i in a]
if sum(sign)%2==0:
    print(sum(a_abs))
else:
    print(sum(a_abs)-2*min(a_abs))

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

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

flag = False
for i in range(n):
    if a[i] < 0:
        if flag == False:
            flag = True
        else :
            flag = False
        a[i] = -1 * a[i]

list.sort(a, reverse=True)        
sum_a = 0

for i in range(n):
    if i == n - 1 and flag:
        sum_a -= a[i]
    else :
        sum_a += a[i]
print(sum_a)

Solution (Python):



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

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

for i in range(n-1):
    if lsta[i]<0:
        lsta[i]=lsta[i]*(-1)
        lsta[i+1]=lsta[i+1]*(-1)

if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))

Solution (Python):
n = int(input())
tmp = input().split()
a = []
minus_count = 0
abs_sum = 0
min_num = min_num = abs(int(tmp[0]))
for i in range(n):
    b = int(tmp[i])
    a.append(b)
    if (b < 0):
        minus_count += 1
    abs_sum += abs(b)
    if abs(b) < min_num:
        min_num = abs(b)

ans = 0
if minus_count % 2 == 0:
    ans = abs_sum
else:
    ans = abs_sum - (min_num * 2)

print(ans)

Solution (Python):
def main():
  n = int(input())
  vs = list(map(int, input().split()))
  avs = [abs(v) for v in vs]
  mvs = [v for v in vs if v < 0]
  
  mvs_len = len(mvs)
  avs_sum = sum(avs)
  avs_min = min(avs)
  if mvs_len % 2 == 0:
    return avs_sum
  else:
    return avs_sum - avs_min * 2
    
  
print(main())

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

count = 0
for a in alist:
    if a < 0:
        count += 1

ans = 0
if count & 1 == 0:
    for a in alist:
        ans += abs(a)
else:
    mina = abs(alist[0])
    for a in alist:
        mina = min(mina, abs(a))
    for a in alist:
        ans += abs(a)
    ans -= mina * 2


print(ans)

Solution (Python):
def main():
    input = sys.stdin.readline
    try:
        n = int(input())
        a = list(map(int, input().split()))
        if len([i for i in a if i < 0]) % 2 == 0:
            print(sum((abs(i) for i in a)))
        else:
            arr = [abs(i) for i in a]
            print(sum(arr) - min(arr) * 2)
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()

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

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

Solution (Python):
def solve():
    N = int(input())
    A = [int(i) for i in input().split()]
    absA = [abs(Ai) for Ai in A]
    rA = [-1 if Ai < 0 else 1 for Ai in A]
    
    for i in range(N - 1):
        if rA[i] < 0:
            rA[i] *= -1
            rA[i + 1] *= -1
    
    if rA[-1] == 1:
        result = sum(absA)
    else:
        
        result = sum(absA) - (min(absA) * 2)
    print(result)


if __name__ == '__main__':
    solve()

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

ans = 0

count = 0

is_zero = False

mint = abs(a[0])

for i in range(0, n):
	if(a[i] == 0):
		is_zero = True
	if(a[i] < 0):
		a[i] = a[i] * -1
		count += 1
	ans += a[i]
	mint = min(mint, a[i])

if(count % 2 != 0 and is_zero == False):
	ans -= 2 * mint
print(ans)

Solution (Python):
n=int(input())
a = list(map(int,input().split()))
minus_cnt = len([x for x in a if x<0])
abs_a = list(map(abs,a))



if 0 in abs_a:
    print(sum(abs_a))
elif minus_cnt %2 == 0:
    print(sum(abs_a))
else:
    print(sum(abs_a)-2*min(abs_a))

Solution (Python):
_,a=open(0);b,c=zip(*[(abs(i),i<0)for i in map(int,a.split())]);print(sum(b)-sum(c)%2*min(b)*2)

Solution (Python):
import numpy as np
n = int(input())
a = np.array([i for i in input().split()]).astype('int64')

for i in range(n-1):
    if a[i] < 0:
        a[i] = -a[i]
        a[i+1] = -a[i+1]
if a[n-1] < 0 :
    i = a[:n-1].argmin()
    if a[i] < -a[n-1]:
        a[i] = -a[i]
        a[n-1] = -a[n-1]
print(np.sum(a))

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

ans = 0

a = []
for i in A:
    ans += abs(i)
    a.append(abs(i))

gusu = False

count = 0
for i in A:
    if i == 0:
        gusu = True
        break
    if 0 > i:
        count += 1

if count % 2 == 0:
    gusu = True

if gusu == True:
    print(ans)
else:
    print(ans - min(a)*2)

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

s=0
a.sort()
for i in xrange(n-1):
	if a[i]<0:
		if a[i+1]<=0 or (a[i+1]>0 and -a[i]>a[i+1]):
			a[i+1]*=-1
			a[i]*=-1
print sum(a)

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

















cou = 0
min_abs = 10000000000
for i in range(N):
    if A[i] < 0:
        cou += 1
    min_abs = min(min_abs, abs(A[i]))
    A[i] = abs(A[i])

if cou % 2 == 0:
    print(sum(A))
else:
    print(sum(A)-2*min_abs)

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

Solution (Python):
import numpy as np

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

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(B))
else:
  print(sum(B[1 :]) - B[0])

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

minus = 0
abs_min = 10 ** 10
sum_A = sum(list(map(abs, A)))

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

if (minus % 2 == 0):
    print(sum_A)
else:
    print(sum_A - 2 * abs_min)

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

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

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

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

    aabs = [abs(aa) for aa in a]
    tmp = 0
    minabs = min(aabs)
    for aa in a:
        if aa < 0:
            tmp += 1
    if tmp%2==1:
        print(sum(aabs) - 2* minabs)
    else:
        print(sum(aabs))
    

if __name__ == '__main__':
    main()

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

minus = False
for a in A:
    if a < 0:
        minus = not minus

if minus:
    print(sum(map(abs,A)) - min(map(abs,A)) * 2)
else:
    print(sum(map(abs,A)))

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

sum_A = sum(A)
plus_A_sum = 0
minus_num = 0
Abs = []
for i in range(N):
  if(A[i] < 0): 
    minus_num += 1
    plus_A_sum += (-A[i])
  else:
    plus_A_sum += A[i]
  Abs.append(abs(A[i]))
  
if(minus_num%2 == 0):
  ans = plus_A_sum
else:
  Abs.sort()
  tmp = Abs[0]
  plus_A_sum = plus_A_sum-2*tmp
  ans = plus_A_sum
print(ans)

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

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

absA = list(map(abs, A))
if count % 2 == 0:
    print(sum(absA))
else:
    min_num = min(absA)
    print(sum(absA) - 2 * min_num)

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

B = False
if all(A):
    
    M = 0
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
            M += 1
    
    if M%2 == 0:
        B = True
    else:
        B = False

else:
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
    B = True

if B:
    print(sum(A))
else:
    print(str(sum(A)-2*min(A)))

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

a.sort()
i = 0
tmp = 0
while i + 1 < n and a[i+1] < 0:
      a[i] *= -1
      a[i+1] *= -1
      i += 2

a.sort()
if a[1] < -a[0]:
    a[1] *= -1
    a[0] *= -1


sum = 0
for i in range(n):
      sum += a[i]
print(sum)

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:
    a = min(A)
    print(sum(A)-2*a)

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
a.sort()
b=[x for x in a if x>0]
c=[x for x in a if x<=0]
if len(b)==0:
    if len(c)%2==0:
        print(sum(c)*-1)
    else:
        print(sum(c[:-1])*-1+c[-1])
elif len(c)%2==0:
    s=sum(b)
    s-=sum(c)
    print(s)
else:
    c.append(b.pop(0))
    s=sum(b)
    s-=sum(c[:-2])
    if c[-1] > c[-2]*-1:
        s+=c[-1]
        s+=c[-2]
        print(s)
    else:
        s-=c[-1]
        s-=c[-2]
        print(s)

Solution (Python):
N = int(input())
ans = 0
plus = []
minus = []
A =[]
zero =0
for i in  [int(n) for n in input().split()]:
    A.append(abs(i))
    if i > 0:
        plus.append(i)
    elif i<0:
        minus.append(i)
    else:
        zero += 1
if len(minus)%2 == 0:
    print(sum(plus)-sum(minus))
else:
    if zero > 0:
        print(sum(plus)-sum(minus))
    else:
        odd = min(A)
        print(sum(A)-2*odd)

Solution (Python):
def d_flipping_signs(N, A):
    minus_count = 0
    _a = []
    for a in A:
        if a >= 0:
            _a.append(a)
        else:
            minus_count += 1
            _a.append(abs(a))
    ans = sum(_a)
    if minus_count % 2 == 1:
        ans -= 2 * min(_a)
    return ans

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

Solution (Python):
def main():

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

    B = [abs(a) for a in A]
    if 0 in A:
        print(sum(B))
    else:

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

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


main()

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:
    a.sort()
    print(sum(a[1:]) - a[0])

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

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

if count % 2 == 0:
    ans = 0
    for i in range(n):
        ans = ans + abs(a[i])
    print(ans)
else:
    ans = 0
    for i in range(n):
        ans = ans + abs(a[i])
    l = []
    for i in range(n):
        l.append(ans - 2*abs(a[i]))
    print(max(l))

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

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

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

if count % 2 == 0:
    print(sum(Aabs))
else:
    mini = min(Aabs)
    print(sum(Aabs) - 2*mini)

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


C = 0
for i, v in enumerate(A):
    if v < 0:
        C += 1
if C % 2 == 0:
    ans = 0
    for i, v in enumerate(A):
        ans += abs(v)
else:
    A = sorted([abs(a) for a in A])
    ans = sum(A) - 2*A[0]

print(ans)

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

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


import numpy as np
a = np.array(a)

cnt = sum(a < 0)
b = np.abs(a)

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

Solution (Python):
n = int(input())
a_list = list(map(int, input().split()))
minus_count = 0
for i in range(n):
    if a_list[i] < 0:
        minus_count += 1
        a_list[i] *= -1
else:
    if minus_count % 2 == 0:
        print(sum(a_list))
    else:
        print(sum(a_list) - min(a_list)*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] = abs(A[i])
    minus %= 2

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

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

if a[-1] < 0:
    a[-1] *= -1
    print(sum(a) - min(a) * 2)
else:
    print(sum(a))

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

if ct%2==0:
    print(SUM)
if ct%2==1:
    a=abs(A[0])
    for i in range(N):
        if a>=abs(A[i]):
            a=abs(A[i])
    print(SUM-2*a)

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

abs_A = [abs(i) for i in A]
sa = sum(abs_A)

nm = len([i for i in A if i<0])
if nm % 2 == 1:
    ma = min(abs_A)
    sa = sa - 2*ma

print(sa)

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

abs_list = sorted([abs(x) for x in A])[::-1]

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

if abs(min(A)) != min(abs_list):
    A[A.index(min(A))] *= -1
    A[A.index(min(abs_list))] *= -1
    
print(sum(A))

Solution (Python):

import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
input = sys.stdin.readline




def main():
	N = int(input())
	A = input().split()
	A = [int(s) for s in A]

	ans = 0
	dels = 0
	naiCounts = 0
	lasts = -1
	for i, val in enumerate(A):
		if val < 0:
			lasts = i
			naiCounts += 1
		if val == 0:
			lasts = -1
			naiCounts = 0
			break

	if naiCounts % 2 == 0 or naiCounts == 0:
		for i, val in enumerate(A):
			if val < 0:
				ans = ans + (val * -1)
			else:
				ans += val
		print(ans)
		sys.exit()

	tmp = -1
	for i, val in enumerate(A):
		if tmp == -1 or tmp > abs(val):
			tmp = abs(val)
			dels = i
	
	
	for i, val in enumerate(A):
		if i == dels:
			
			if val < 0:
				ans += val
			else:
				ans -= val
		else:
			if val < 0:
				ans = ans + (val * -1)
			else:
				ans += val


	print(ans)



def gcd(a, b):
	if a > b:
		a, b = b, a
		
	while a > 0:
		a, b = b % a, a
	return b
	
if __name__ == "__main__":
	main()

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

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

dp = [[0 for i in range(2)] for i in range(n)]

dp[0][0] = a_list[0]
dp[0][1] = -1*a_list[0] 

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

print(ans)

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

r = 0
r_min = 1000000000
m_c = 0

for i in A:
    ia = abs(i)
    if i<0:
        m_c+=1
    if r_min > ia:
        r_min = ia
    r+=ia

if m_c%2==0 :
    print(r)
else:
    print(r-r_min*2)

Solution (Python):
import numpy as np
n = int(input())
l = np.array(list(map(int,input().split()))).astype("i")

m = np.sum(l < 0)

if m % 2 == 0:
  print(np.sum(np.abs(l)))
else:
  print(np.sum(np.abs(l)) - 2 * np.min(np.abs(l)))

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

Solution (Python):
import numpy as np
n = int(input())
lsta = list(map(int,input().split()))
npa = np.array(lsta)
guki = len(npa[npa<0])%2
npaabs = np.abs(npa)
print(sum(npaabs)-min(npaabs)*2*guki)

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

absA = []
for i in range(N):
    absA.append(abs(A[i]))

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

flag = 0
for i in range(N):
    if A[i] != 0:
        flag = 1
    if flag == 1 and A[i] == 0:
        cnt += 1
    
if cnt % 2 == 0:
    ans = sum(absA)
else:
    ans = sum(absA) - min(absA) * 2

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(N):
    if A[i] <= 0:
        count += 1
ans = 0
if count%2 == 0 or 0 in A:
    for i in range(N):
        ans += max(A[i],-A[i])
else:
    tmp = -1000000000
    c = 0
    for i in range(N):
        if tmp < min(A[i],-A[i]) < 0:
            tmp = min(A[i],-A[i])
            c = i
    if tmp == -1000000000 and c == 0:
        if tmp != A[0]:
            tmp = 0
            c = A.index(0)
    
    for i in range(N):
        if i != c:
            ans += max(A[i],-A[i])
        else:
            ans += tmp
print(ans)

Solution (Python):
import re
import sys
from fractions import gcd
from functools import reduce
from itertools import product

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    A = np.asarray(il())
    B = A[A < 0]
    if len(B) % 2 == 0:
        return sum(np.abs(A))
    sorted_A = sorted(np.abs(A))
    return sum(sorted_A[1:]) - sorted_A[0]


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

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

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


minn = 10**10
cnt = 0
ans = 0
for i in range(n):
    temp = abs(a[i])
    minn = min(temp, minn)

    ans += temp

    if a[i]<0:
        cnt += 1



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

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

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

Solution (Python):


import fractions as f
import copy

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

a_abs = list(map(abs, a))

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

if fu%2 == 0:
    max = sum(a_abs)
else:
    min_abs = a_abs.index(min(a_abs))
    max = sum(a_abs) - 2 * a_abs[min_abs]

print(max)

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

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

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

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

if minus_count%2 == 0 or 0 in a:
    for i in range(len(a)):
        ans += abs(a[i])
else:
    for i in range(len(a)):
        ans += abs(a[i])
    a = [e for e in a if e != 0]
    a.sort(key=abs)
    ans -= abs(a[0])*2
print(ans)

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

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

ans = 0
m = 10 ** 9 + 1
for i in range(N - 1):
    if A[i] < 0:
        A[i] = -A[i]
        A[i + 1] = -A[i + 1]
    ans += A[i]
    if A[i] < m:
        m = A[i]

if A[N - 1] < 0:
    m = min(m, abs(A[N - 1]))
    ans += abs(A[N - 1])
    ans -= 2 * m
else:
    ans += A[N - 1]
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split(" ")))
abs_list = list(map(abs, A))
abs_list.sort()
pos = list(filter(lambda x: x > 0, A))
neg = list(filter(lambda x: x < 0, A))
pos.sort()
neg.sort()


if abs_list[0] == 0:
	print(sum(abs_list))
elif len(neg) % 2 == 0:
	print(sum(abs_list))
elif len(pos) > 0 and abs(pos[0]) < abs(neg[-1]):
	print(sum(abs_list) - 2*pos[0])
else:
	print(sum(abs_list[1:])-abs_list[0])

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

count = 0
for i in range(N):
    if B[i] < 0:
        count += 1
        B[i] *= -1
  
res = 0
if count%2 == 1:
    B.sort()
    for i in range(1, N):
        res += abs(B[i])

    res -= B[0]
else:
    for i in range(N):
        res += abs(B[i])
        
print(res)

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

minus = 0


A = [int(element) for element in a]

A_abs = [abs(element) for  element in A]

for a_num in A:
    if a_num < 0:
        minus = minus + 1


if minus % 2 == 0:
    result = sum(A_abs)

else:
    result = sum(A_abs) - 2*min(A_abs)

print(result)

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

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

sum = 0
for i in range(n):
    sum += a[i]

a.sort()

if time % 2 == 0:
    print(sum)
else:
    print(sum - a[0] * 2)

Solution (Python):




def main():
  input()
  s = 0
  m = 1e9
  c = 0

  for v in map(int, input().split()):
    s += abs(v)
    m = min(abs(v), m)

    if v < 0:
      c = 1 - c

  print(s - m * c * 2, flush=True)


if __name__ == '__main__':
  main()

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

dp = [[0]*2 for i in range(n)]

dp[1][0] = sum(arr[:2])
dp[1][1] = -sum(arr[:2])

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

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

Solution (Python):
def main():
    result = sub()
    print(result)


def sub():
    N = int(input())
    As = [int(i) for i in input().split()]

    abssum = 0
    negative_count = 0
    is_zero_contained = False
    absmin = 10**9

    for i in range(N):
        val = As[i]
        if val > 0:
            abssum += val
            absmin = min(absmin, val)
        elif val < 0:
            abssum -= val
            negative_count += 1
            absmin = min(absmin, -val)
        else:  
            is_zero_contained = True
            absmin = 0

    if is_zero_contained:
        return abssum
    elif negative_count % 2 == 0:
        return abssum
    else:
        return abssum - 2 * absmin

    return abssum


if __name__ == '__main__':
    main()

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

Solution (Python):


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

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

    
    
    minus_num = 0
    for a in A:
        if a < 0:
            minus_num += 1
    
    ans = 0
    lowest = 10**9+1
    for a in A:
        ans += abs(a)
        if lowest >= abs(a):
            lowest = abs(a)
    
    if minus_num%2 == 0:
        print(ans)
    else:
        ans -= lowest*2
        print(ans)


if __name__ == "__main__":
    solve()

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

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

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

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = 0
hoge = 10000000000000000000


n = sum(x < 0 for x in A)
if n % 2 == 0:
    for i in range(N):
        ans += abs(A[i])
    print(ans)
    exit()
else:
    for i in range(N):
        ans += abs(A[i])
        if hoge > abs(A[i]):
            hoge = abs(A[i])
    print(ans - hoge*2)
    exit()

Solution (Python):
N = int(input())
A = input().split(' ')
for i in range(N):
  A[i] = int(A[i])
cnt = 0
for i in range(N):
  if A[i]<0:
    cnt += 1
if cnt%2==0:
  rlt = 0
  for i in range(N):
    rlt += abs(A[i])
else:
  sml = 0
  for i in range(N-1):
    if abs(A[sml])>abs(A[i+1]):
      sml = i+1
  rlt = 0
  for i in range(N):
      if i != sml:
        rlt += abs(A[i])
      else:
        rlt += -(abs(A[i]))
print(rlt)