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_arr = list(map(int, input().split()))
A_abs = [abs(A_arr[i]) for i in range(N)]

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

ans = 0
if 0 in A_arr:
    for i in range(N):
        ans += A_abs[i]

else:
    if count % 2 == 0:
        for i in range(N):
            ans += A_abs[i]
    else:
        for i in range(N):
            ans += A_abs[i]
        ans -= 2*min(A_abs)

print(ans)

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

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

counter = 0
min_list = []
for i in range(N):
    if a_list[i] < 0:
        counter += 1
        min_list.append(a_list[i])

if counter % 2 == 0:
    abc = sum(min_list)
    abc *= -1
    ans = sum(a_list)
    print(ans + 2*abc)

if counter % 2 == 1:
    for i in range(N):
        if a_list[i] < 0:
            a_list[i] *= -1
    min_mun = min(a_list)
    ans = sum(a_list) - 2*min_mun
    print(ans)

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

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

if 0 in A:
  ans = sum(A)
else:
  if count%2 == 0:
    ans = sum(A)
  else:
    ans = sum(A) - 2*min(A)

print(ans)

Solution (Python):
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    S = 0
    min_ = 10**9 + 1
    neg = 0
    for a in A:
        S += abs(a)
        min_ = min(min_, abs(a))

        if a < 0:
            neg += 1

    if neg % 2 == 0:
        return S
    else:
        return S - 2 * min_


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

Solution (Python):
def flipping(n,a):
    c = list(filter(lambda x:x<0,a))
    b = list(map(lambda x:abs(x),a))
    if len(c)%2==0:
        return sum(b)
    if len(c)%2!=0:
        return sum(b)-2*min(b)
    return b
n = int(input())
a=list(map(int, input().split()))
print(flipping(n,a))

Solution (Python):
n = int(input())
a = list(int(n) for n in input().split())
b = [0] * n
num_of_minus = 0

for i in range(n):
    if a[i] < 0:
        num_of_minus += 1
        b[i] = int(a[i] * (-1))
    else:
        b[i] = int(a[i])

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

print(ans)

Solution (Python):
import numpy as np
       
N = input()
A = np.array([int(x) for x in input().split(" ")])

if len(np.where(A<0)[0])%2 == 0:
  print(np.abs(A).sum())
else:
  print(np.abs(A).sum() - np.abs(A).min()*2)

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

count = np.sum(A_array < 0)

A_array_abs = np.abs(A_array)

A_array_abs = np.sort(A_array_abs)

if A_array_abs[0] == 0 or count % 2 == 0:
    print(np.sum(A_array_abs))
else:
    print(np.sum(A_array_abs[1:]) - A_array_abs[0])

Solution (Python):
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])
negative_count = np.sum(A<0)

abs_A = list(map(abs, A))
if(negative_count%2==0):
    print(int(np.sum(abs_A)))
else:
    print(int(np.sum(abs_A) - (min(abs_A)*2)))

Solution (Python):
N=int(input())
A=list(map(int,input().split(" ")))
A_p = [ a for a in A if a > 0 ]
A_n = [ -1*a for a in A if a < 0 ]
A_0 = [ a for a in A if a == 0 ]

l_p = len(A_p)
l_n = len(A_n)
l_0 = len(A_0)

if l_p == 0:
    if l_n%2 == 0:
        print(sum(A_n+[0]))
    elif l_0 > 0:
        print(sum(A_n+[0]))
    else:
        tmp_n=min(A_n)
        A_n.remove(tmp_n)
        print(sum(A_n+[0])-tmp_n)
elif l_n == 0:
    print(sum(A_p+[0]))

elif l_n%2 == 0:
    print(sum(A_p)+sum(A_n))
else:
    if l_0 > 0:
        print(sum(A_p)+sum(A_n))
    else:
        if min(A_n) > min(A_p):
            tmp_n=min(A_p)
            A_p.remove(tmp_n)
            print(sum(A_p)+sum(A_n)-tmp_n)    
        else:
            tmp_n=min(A_n)
            A_n.remove(tmp_n)
            print(sum(A_p)+sum(A_n)-tmp_n)

Solution (Python):
import numpy as np

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

n = np.sum(A < 0)
b = np.abs(A)
s = np.sum(b)

if n % 2:
    print(s - 2 * np.min(b))
else:
    print(s)

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

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

sign = 1
abs_sum = 0
min_abs = int(1e9)

for a in a_list:
    tmp = abs(a)
    abs_sum += tmp
    min_abs = min(min_abs, tmp)
    sign *= (a >= 0) * 2 - 1

if sign > 0:
    print(abs_sum)
else:
    print(abs_sum - 2 * min_abs)

Solution (Python):
import sys

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
new_list = []
cnt = 0
for a in a_list:
    if a < 0:
        cnt += 1
        a = -a
    new_list.append(a)
if cnt%2 == 0:
    print(sum(new_list))
else:
    print(sum(new_list)-min(new_list)*2)

Solution (Python):
N = int(input())
A = [int(s) for s in input().split()]
abss = [abs(a) for a in A]
signs = sum(1 if a < 0 else 0 for a in A)
if signs % 2 == 0:
    print(sum(abss))
else:
    minabs = min(abss)
    print(sum(abss) - 2 * minabs)

Solution (Python):
import numpy as np
import sys
 
n = int(input())
l = np.array([int(x) for x in input().split()])
ans = 0
if 0 in l:
  for i in range(n):
    ans += abs(l[i])
  print(ans)
  sys.exit()
m = abs(l[0])
p = 0
for i in range(n):
  if l[i] < 0:
    p += 1
  if m > abs(l[i]):
    m = abs(l[i])
for i in range(n):
  ans += abs(l[i])
if p % 2 == 0:
  print(ans)
else:
  print(ans - m*2)

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

index=0
count=0
plSum=0
miSum=0
miniO=10000000
while index < len(listA):
    if listA[index] < 0:
        count+=1
        miSum-=listA[index]
    else:
        plSum+=listA[index]
    if abs(listA[index]) < miniO:
        miniO = abs(listA[index])
    index+=1
if count%2==0:
    print(plSum+miSum)
else:
    print(plSum+miSum-2*miniO)

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

if 0 in a:
  b = list(map(abs, a))
  print(sum(b))
  
else:
  if (a[a<0].size % 2) == 0:
    b = list(map(abs, a))
    print(sum(b))
  else:
    b = list(map(abs, a))
    b = sorted(b)
    b.reverse()
    c = b.pop()
    print(sum(b)-c)

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

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

if minus%2 == 0:
    for i in range(n):
        a[i] = abs(a[i])
    total = sum(a)
else:
    for i in range(n):
        a[i] = abs(a[i])
    total = sum(a) - min(a)*2

print(total)

Solution (Python):



N =int(input())
B = list(map(int,input().split()))
count=0
for i in range(N):
    if B[i]< 0:
        B[i] =-B[i]
        count+=1

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

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

Solution (Python):
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
c=0
for i in a:
    if i < 0:
        c+=1

b = [abs(i) for i in a]

if c%2 == 0:
    print(sum(b))
    exit()

b.sort()
print(sum(b)-2*b[0])

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().rstrip().split(' ')))
    total = 0
    n_count = 0
    n_max = -10000000000
    p_min = 10000000000
    for i in range(n):
        if a[i] < 0:
            n_count += 1
            if n_max < a[i]:
                n_max = a[i]
        else:
            if p_min > a[i]:
                p_min = a[i]
    if n_count % 2 == 0:
        total = sum(map(abs, a))
    else:
        total = sum(map(abs, a)) - 2 * min(p_min, abs(n_max))
    print(total)

if __name__ == '__main__':
    main()

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

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

amin = 10 ** 9 + 1
cntm = 0
asum = 0
for a in A:
    if a < 0:
        cntm += 1
        amin = min(amin, -a)
        asum -= a
    else:
        amin = min(amin, a)
        asum += a


if(cntm % 2):
    print(asum - 2 * amin)
else:
    print(asum)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
sei=[0]*n
mai=0
zero=0
pr=0
for i in range(n):
  sei[i]=max(a[i],-a[i])
  pr+=sei[i]
  if a[i]<0:
    mai +=1
  elif a[i]==0:
    zero+=1
  else:
    pass

if mai%2==0 or zero >=1:
    print(pr)
else:
    print(pr-2*min(sei))

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

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

minus_count_even_flug = 1
zero_exist_flug = -1

for a in a_list:
    if a < 0:
        minus_count_even_flug *= -1
    if a == 0:
        zero_exist_flug = 1

a_abs_list = [abs(a) for a in a_list]
sum_a_abs_list = sum(a_abs_list)
if minus_count_even_flug == 1 or zero_exist_flug == 1:
    print(sum_a_abs_list)
else:
    print(sum_a_abs_list - 2 * min(a_abs_list))

Solution (Python):
n = int(input())
lis = list(map(int,input().split()))
numm = 0
ans = 0
nu = 10 ** 9
for num in lis:
  nu = min(nu,abs(num))
  ans += abs(num)
  if num < 0:
    numm += 1
if numm % 2 == 1:
  print(ans-nu*2)
else:
  print(ans)

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

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

print(sum(A))

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

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

minNum = 0

for x in range(0, len(aList)):
	minNum += 1 if aList[x] < 0 else 0
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]

aMin = min(aList)


even = minNum%2==0

if even:
	print(sum(aList))
else:
	print(sum(aList) - (aMin*2))

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

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

o=0

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

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

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

Solution (Python):
import numpy as np

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

A = np.array(A)

plus = A[A >= 0]
minus = A[A < 0]

if len(minus) % 2 == 0:
    ans = np.sum(plus) - np.sum(minus)
else:
    ans = np.sum(plus) - np.sum(minus) - np.min(np.abs(A)) * 2

print(ans)

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

sum = 0
minus = 0
minn = -1
for a in A:
    b = abs(a)
    sum += b
    if minn == -1 or b < minn:
        minn = b
    if a < 0:
        minus += 1

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

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

min_m = -10**9+1
min_p = 10**9+1 
ans = 0
cnt = 0

for i in range(n):
  ans += abs(a[i])
  if min_p > a[i] >= 0:
    min_p = a[i]
  elif a[i] < 0:
    if min_m < a[i]:
      min_m = a[i]
    cnt += 1
if cnt % 2:
  if abs(min_m) > abs(min_p):
    print(ans - abs(min_p)*2)
  else:
     print(ans - abs(min_m)*2)
else:
  print(ans)

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

dp = [[-10**16 for __ in range(4)] for _ in range(N+10)]
A = A+[0,0,0,0,0,0,0]

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

dp[1][0] = A[0]+A[1] 
dp[1][1] = -A[0]-A[1]





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

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

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

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

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

A = list(map(abs, A))

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

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int,input().split()))
n = sum(1 for x in A if x<0)
B = np.abs(A)
if n % 2 == 1:
  print(sum(B) - 2*min(B))
else:
  print(sum(B))

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

minus_count = 0
abs_min = 0
has_zero = False
total = 0
for a in a_list:
    if abs_min == 0 or abs(a) < abs_min:
        abs_min = abs(a)
    if a < 0:
        minus_count += 1
        total -= a
    elif a == 0:
        has_zero = True
    else:
        total += a
if not has_zero and minus_count % 2 == 1:
    total -= abs_min * 2
print(total)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
counter = 0
m = []
def abab(l):
    for i in range(len(l)):
        m.append(abs(l[i]))
    return m

for i in range(N):
    if A[i] < 0:
        counter += 1
      
if counter % 2 == 1:
    m = abab(A)
    idx = m.index(min(m))
    m[idx] *= -1
    print(sum(m))
else:
    print(sum(abab(A)))

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

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

print(sum(A))

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

zero = False
gu = 1
for a in A:
    if a == 0:
        zero = True
    elif a < 0:
        gu *= -1

anss = [abs(a) for a in A]
if zero | (gu == 1):
    print(sum(anss))

else:
    mina = min(anss)
    print(sum(anss) - 2 * mina)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
m = 11111111111111111111111111111111111111111111111110;count = 0;check = False
for i in range(n):
    if a[i] == 0:check = True
    if m > abs(a[i]):
        m = abs(a[i])
    if a[i] < 0:count += 1
if count % 2 == 0:check = True
s = 0
for i in range(n):
    s += abs(a[i])
if check:print(s)
else:print(s-2*abs(m))

Solution (Python):
def calc_abs(n):
    return abs(n)

N = int(input())
A = [int(i) for i in input().split()]
count = len([i for i in A if i < 0])
count_zero = A.count(0)
answer = 0
if(count % 2 != 0 and count_zero == 0):
    abs_list = list(map(calc_abs,A))
    answer = sum(abs_list) - 2 * min(abs_list)
else:
    abs_list = list(map(calc_abs, A))
    answer = sum(abs_list)
print(answer)

Solution (Python):
n = int(input())
A = [int(a) for a in input().split()]
B = [1 if _ > 0 else 0 for _ in A]
D = [abs(d) for d in A]
i = B.count(0)

if i % 2 != 0:
    D[D.index(min(D))] *= -1

print(sum(D))

Solution (Python):

N = int(input())
A = input().split()
ans = 0
t = 0
for i in range(N):
  A[i] = int(A[i])
for i in range(N):
  if A[i] == 0:
    for j in range(N):
      if A[j]<0:
        A[j] = -A[j]
    ans = sum(A)
    break
for j in range(N):
  if A[j]<0:
    t +=1
if t%2 == 0:
  for j in range(N):
    if A[j]<0:
      A[j] = -A[j]
  ans = sum(A)
else:
  for j in range(N):
    if A[j]<0:
      A[j] = -A[j]
  A[A.index(min(A))] = -A[A.index(min(A))]
  ans = sum(A)
      
print(ans)

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

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

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

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

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

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

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

num_minus = sum([int(a < 0) for a in A])

abs_a = [abs(a) for a in A]
ans = sum(abs_a)
if num_minus % 2 != 0:
    ans -= min(abs_a) * 2
print(ans)

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

count = 0
s = 1000000000
add = 0
for num in arr:
  if num < 0:
    count += 1
  s = min(s, abs(num))
  add += abs(num)

print(add-(count%2)*abs(s)*2)

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

zero_count = 0
minus_count = 0
total = 0
minimum = abs(A_list[0])
for i in range(len(A_list)):
    if A_list[i] == 0:
        zero_count += 1
    elif A_list[i] < 0:
        minus_count += 1

    total += abs(A_list[i])
    if A_list[i] != 0:
        minimum = min(minimum, abs(A_list[i]))


if minus_count % 2 == 0 or zero_count > 0:
    print(total)
else:
    print(total - minimum*2)

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

Solution (Python):
import numpy as np

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

fu = np.sum(A < 0)

if fu == 0:
    print(np.sum(A))
elif fu%2 == 0:
    print(np.sum(abs(A)))
else:
    b = min(abs(A))
    print(np.sum(abs(A)) - 2*b)

Solution (Python):
import operator
n = int(input())
lisa = list(map(int,input().strip().split()))
lisb = []
suma = 0
for val in lisa:
	suma+=abs(val)

m = 0
for i,val in enumerate(lisa):
	if val < 0:
		m+=1
		lisa[i] = abs(val)
		lisb.append((val,i))


if m%2==0:
	print(suma)
else:
	minb = min(lisb,key = operator.itemgetter(0))
	mina = min(lisa)
	print(suma-2*min(-minb[0],mina))

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

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

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

    print(sum(A))
else:
    abs_min_ind = 0
    abs_min = 10**9
    for i in range(N):
        if A[i] < 0:
           A[i] = A[i] * -1
        if abs_min > abs(A[i]):
            abs_min = abs(A[i])
            abs_min_ind = A.index(A[i])

    A[abs_min_ind] = A[abs_min_ind] * -1

    print(sum(A))

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

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

ans = 0
cost = float('inf')
count = 0

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

if 0 not in a:
    
    if count % 2 != 0:
        ans -= 2*cost

print(ans)

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

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

if odd%2==1:
  print(ans-2*min(a))
else:
  print(ans)

Solution (Python):
import math


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

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

if __name__ == "__main__":
    main()

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

nums = A[:]
import math

gcd_queue = [
    (0, nums[0]),
]
for n in nums[1:]:
    tmp_queue = []
    for q in gcd_queue:
        tmp_queue.append((q[0] + q[1], n))
        tmp_queue.append((q[0] + q[1]*-1, n*-1))
    gcd_queue = set(tmp_queue[:])
    
    tmp = {}
    for q in gcd_queue:
        if str(q[1]) in tmp:
            tmp[str(q[1])] = max(q[0], tmp[str(q[1])])
        else:
            tmp[str(q[1])] = q[0]
    
    gcd_queue = []
    for k, v in tmp.items():
        
        gcd_queue.append((v, int(k)))
    

gcd_queue = list(gcd_queue)
ans = gcd_queue[0][0] + gcd_queue[0][1]
for q in gcd_queue:
    ans = max(ans, q[0]+q[1])
print(ans)

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


count = len([i for i in A if i < 0])
B = []
for i in range(N):
    B.append(abs(A[i]))

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

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

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

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

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

n = sum(1 for a in A if a <  0)
z = sum(1 for a in A if a == 0)

s = sum(abs(a) for a in A)

if n % 2 == 0 or z >= 1:
    print(s)
else:
    x = min(abs(a) for a in A)
    print(s - 2 * x)

Solution (Python):
def abs(i):
    if i <0:
        i = -i
    return i
N = int(input())
As = [int(Ai) for Ai in input().split()]
count = 0
for i in As:
    if i <= 0:
        count += 1
As_prime = [abs(Ai) for Ai in As]
if count % 2 == 0:
    print(sum(As_prime))
else:
    print(sum(As_prime)-2*min(As_prime))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
ans=0
b=[]
for i in range(n):
  if a[i]<0:
    cnt+=1
    b.append(-a[i])
  else:
    b.append(a[i])
b.sort()
b.reverse()

if cnt%2==1:
  for i in range(n-1):
    ans+=b[i]
  ans-=b[n-1]
else:
  for i in range(n):
    ans+=b[i]
print(ans)

Solution (Python):
N = int(input())
Alist = list(map(int, input().split()))
c = 0
n0 = 0
Amin = 1000000000

for i in range(N):
    if abs(Alist[i]) < Amin :
        Amin = abs(Alist[i])
    if Alist[i] < 0 :
        c += 1
    elif Alist[i] == 0 :
        c = 0
        Amin = 0
        n0 = i
    Alist[i] = abs(Alist[i])

if n0 == 0 :
    if c % 2 == 0:
        print(sum(Alist))
    else:
        print(sum(Alist) - 2 * Amin)
else:
    if c % 2 == 0:
        print(sum(Alist))
    else:
        print(sum(Alist) - 2 * Amin)

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    A_list = list(map(int, input().split()))

    minus_cnt = 0

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

    answer = 0

    if minus_cnt % 2 == 0:
        for A in A_list:
            answer += abs(A)
    else:
        min_abs_A = pow(10, 9)
        for A in A_list:
            answer += abs(A)
            if min_abs_A > abs(A):
                min_abs_A = abs(A)
        answer -= min_abs_A * 2

    print(answer)

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

Solution (Python):


import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline() for _ in range(n)]
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main(N, An):
    n0 = An[0]
    n1 = -An[0]
    for i in range(1, N-1):
        n0t = max(n0 + An[i], n1 - An[i])
        n1t = max(n0 - An[i], n1 + An[i])
        n0 = n0t
        n1 = n1t
    n0 += An[N-1]
    n1 -= An[N-1]
    print(max(n0, n1))

N = i2n()
An = i2nn()
main(N, An)

Solution (Python):



def main():
    n = int(input())
    a = list(map(int, input().split()))
    minus_count = 0
    abs_min = float('inf')
    ans = 0

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

        abs_min = min(abs_min, abs(ai))
        ans += abs(ai)

    if minus_count % 2 == 1:
        ans -= abs_min * 2

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):

N=int(input())
A=list(map(int,input().split()))
n_plus=sum(x>0 for x in A)
min_abs=1000000000
if n_plus%2==N%2:
    ans=sum(abs(x) for x in A)
else:
    for x in A:
        x_abs=abs(x)
        if x_abs<min_abs:
            min_abs = x_abs
    ans=sum(abs(x) for x in A)-min_abs*2
print(ans)

Solution (Python):

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
A = read_ints()







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


anstmp = sum([abs(a) for a in A])
if minuscount % 2 == 0:
    print(anstmp)
    exit()


mi = 10 ** 9
for a in A:
    mi = min(mi, abs(a))

print(anstmp-2*mi)

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

Solution (Python):
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
count = 0
for i in range(len(a)):
    if a[i] < 0:
        count += 1
        a[i] = -a[i]
ans = 0
if count % 2 == 0:
    ans = sum(a)
else:
    ans = sum(a) - 2 * min(a)
print(ans)

Solution (Python):
N = int(input())
As = list(map(int,input().split()))
n = sum(x<0 for x in As)
ans = 0
if n%2 == 0:
    for i in range(N):
        ans += abs(As[i])
else:
    abs_list = []
    for i in range(N):
        abs_list.append(abs(As[i]))
        ans += abs(As[i])
    ans = ans-2*min(abs_list)
print(ans)

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

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


curmin = 1 + 10**9
negatives = 0
cursum = 0

for item in A:
    
    

    curmin = min(curmin, abs(item))

    if item < 0:
        negatives += 1

    cursum += abs(item)

if negatives % 2 == 1:
    cursum -= 2 * curmin

print(cursum)

Solution (Python):
inp = input()
inn = [int(e) for e in input().split()]
c = []
for d in inn:
    if d > 0:
        c.append(1)

    else:
        c.append(0)
k = [abs(d) for d in inn]


if c.count(0) % 2 == 1:
     k.sort()
     a = k.pop(0)
     aa = sum(k) - a
     print(aa)
else:
    k.sort()
    aa = sum(k)
    print(aa)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
minus = 0
for j in range(n):
    if a[j] < 0:
        minus += 1
for i in range(n-1):
    if a[i] < 0:
        a[i] = a[i] * -1
        a[i+1] = a[i+1] * -1
if a[n-1] < 0:
    a[n-1] = a[n-1] * -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()))
c = 0
s = 0
for i in range(n):
	s += abs(a[i])

for i in range(n):
	if a[i] == 0:
		print(s)
		quit()
	elif a[i] < 0:
		c += 1
	else:
		pass

if c%2 == 0:
	pass
else:
	a.sort(key = lambda x: abs(x))
	s = s - 2*abs(a[0])
print(s)

Solution (Python):
from numpy import sign
n=int(input())
a=list(map(int,input().split()))
a_abs=list(map(abs,a))
a_abs.sort()

plmi=1
for i in a:
    plmi*=sign(i)

if plmi==-1:
    ans=sum(a_abs[1:])-a_abs[0]
elif plmi==1 or plmi==0:
    ans=sum(a_abs)
print(ans)

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

aA = [abs(a) for a in A]
asum = sum(aA)
c = sum([(a < 0) for a in A])

if c % 2:
	print(asum - min(aA) * 2)
else:
	print(asum)

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    dp = [[0] * 4 for i in range(N)]

    dp[0][0] = A[0]
    dp[0][1] = -float('inf')
    dp[0][2] = -float('inf')
    dp[0][3] = -A[0]

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



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

if __name__ == '__main__':
    main()

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
t=0
hunokazu=0
while t<N:
    if A[t]<0:
        hunokazu=hunokazu+1
    t=t+1
q=[]
qq=0
while qq<N:
    if A[qq]>=0:
        q.append(A[qq])
    else:
        q.append(A[qq]*(-1))
    qq=qq+1
if hunokazu%2==0:
    k=0
    ans=0
    while k<N:
        ans=ans+q[k]
        k=k+1
else:
    k=0
    ans=0
    while k<N:
        ans=ans+q[k]
        k=k+1
    ans=ans-min(q)*2
print(ans)

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

negcnt = 0
zcnt = 0
for k in a:
    if k < 0:
        negcnt += 1
    elif k == 0:
        zcnt += 1

ans = 0
if (negcnt + zcnt) % 2 == 0:
    for k in a:
        ans += abs(k)
    print(ans)
else:
    negmin = (10**9+1)
    for k in a:
        if abs(k) < negmin:
            negmin = abs(k)
    for k in a:
        ans += abs(k)
    
    print(ans - 2*negmin)