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):
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:
        if a < 0:
            neg += 1
            S += -a
            min_ = min(min_, -a)
        else:
            S += a
            min_ = min(min_, a)

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


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

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

P = []
N = []
for a in A:
  if a>=0:
    P += [a]
  else:
    N += [a]
P.sort()
N.sort()

if len(N)%2==0:
  print sum(P)+sum(-t for t in N)
elif len(P)>0:
  print sum(P[1:])+sum(-t for t in N[:-1])+abs(P[0]+N[-1])
else:
  print sum(-t for t in N[:-1])+N[-1]

Solution (Python):
N=int(input())
a_list = list(map(int, input().split()))
minus_a_list = list(filter(lambda x: x < 0, a_list))

if (len(minus_a_list) % 2 == 0):
    print(sum(map(abs, a_list)))
else:
    abs_a_list = list(map(abs, a_list))
    print(sum(abs_a_list) - 2 * min(abs_a_list))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in a:
  b.append(abs(i))
m=[]
for i in a:
  if i>=0:
    m.append(0)
  else:
    m.append(1)
if sum(m)%2==0:
  ans=sum(b)
else:
  k=1000000000
  t=0
  for i in range(n):
    if b[i]<k:
      k=b[i]
      t=i
  ans=sum(b)-2*b[t]
print(ans)

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

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

INF = float('inf')
dp = [[-INF] * N for i in range(2)]
dp[0][0] = A[0]
dp[1][0] = -A[0]

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

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

a.sort()

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

abs_a.sort()
plus_sum = sum(abs_a)

if minus_num % 2 == 0:
    print(plus_sum)
else:
    print(plus_sum - 2*abs_a[0])

Solution (Python):
import collections as c
ip = lambda : map(int, input().split())


N = int(input())
A = [int(i) for i in input().split()]
minn = 1e9
cminus = 0
czero = 0
s = 0
for i in A:
    minn = min(minn,abs(i))
    if i<0:
        cminus += 1
    elif i==0:
        czero += 1
    s += abs(i)
if cminus%2 == 1:
    s -= 2*minn
print(s)

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

absmin=abs(nums[0])
abssum=0
minus=0

for n in nums:
    if n < 0:
        minus += 1
    absmin = min(absmin, abs(n))
    abssum += abs(n)

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

Solution (Python):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq
"""
A,B,T=map(int, input().split())
print(int(math.floor((T+0.5)/(A))*B))
"""
"""
N=int(input())
V=list(map(int, input().split()))
C=list(map(int, input().split()))
print(sum([V[i] - C[i] for i in range(N) if V[i] - C[i] > 0]))
"""
"""
N=int(input())
A=list(enumerate(map(int, input().split())))
l=list(A)
l.sort()

x=(-1, -1)
y=(-1, -1)

while l[0][1] != 0:
        l=list(map(lambda it: (it[0], it[1]%l[0][1]), l[1:]))
        (i, xi) = x
"""
N=int(input())
A=list(map(int, input().split()))
nNeg = len([1 for a in A if a < 0])
minAbs = min(A, key=lambda ai: abs(ai))
if nNeg%2 == 0:
        print(sum([abs(ai) for ai in A]))
else:
        print(-2*abs(minAbs) + sum([abs(ai) for ai in A]))

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

cnt_minus = sum(x<0 for x in a)
cnt_zero = sum(x==0 for x in a)

if cnt_minus % 2 == 0 or cnt_zero > 0:
    print(sum(abs(x) for x in a))
else:
    y = min(abs(x) for x in a)
    while y == 0:
        a.remove(0)
        y = min(abs(x) for x in a)
    print(sum(abs(x) for x in a) - 2 * y)

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

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

for i in range(0, n-n%2-1, 2):
    if a[i] + a[i+1] < 0:
        a[i] = -a[i]
        a[i+1] = -a[i+1]
    else:
        break
print(sum(a))

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

B = []

count = 0
for x in A:
  if x < 0:
    count += 1
  B.append(abs(x))

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

Solution (Python):
import numpy as np
N = int(input())
A_list = list(map(int,input().split()))
neg_num = len([x for x in A_list if x<0])
zero_num = len([x for x in A_list if x==0])
abs_list = [abs(x) for x in A_list]

ans = np.sum(abs_list)
if neg_num%2==0 or zero_num>0:
    ans = ans
elif neg_num%2!=0:
    ans = ans - 2*min([x for x in abs_list if x!=0])
print(ans)

Solution (Python):
def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    A = sorted(A, key = lambda x: abs(x), reverse=True)
    minus = 0
    for a in A:
        if a < 0:
            minus += 1
    if minus % 2 == 1:
        minus -= 1
    res = 0
    for i in range(N):
        a = A[i]
        if a < 0 and minus > 0:
            A[i] = -a
            minus -= 1
    for i in range(N):
        a = A[i]
        if a < 0:
            A[i] = -a
            A[-1] = -A[-1]
    
    print(sum(A))
main()

Solution (Python):

import copy
import random
import bisect 
import fractions 
import math

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

A.sort()
cnt_mi = 0
if A[0] >= 0:
    ans = sum(A)
    print(ans)
    exit()

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

if cnt_mi%2 == 0:
    ans = sum(A)
    print(ans)
    exit()

A.sort()

ans = sum(A)-2*A[0]
print(ans)

Solution (Python):
N = int(input())
A = sorted(list(map(int,input().split())))
t = 0
for e in A:
    if e < 0:
        t += 1
B = sorted([abs(e) for e in A])

if t%2 == 1:
    print(sum(B)-B[0]*2)
else:
    print(sum(B))

Solution (Python):
def main():
    n = int(input())
    arr = list(map(int, input().split()))
    mi = 1000000000
    s = 0
    cnt = 0
    for i in range(n):
        if arr[i] < 0:
            cnt += 1
            s -= arr[i]
            mi = min(mi, -arr[i])
        else:
            s += arr[i]
            mi = min(mi, arr[i])
    if cnt & 1:
        print(s - 2 * mi)
    else:
        print(s)
    return 0

main()

Solution (Python):
n=int(input())
a=[int(x) for x in input().split()]
num_minus=0
a_modified=[]
for ai in a:
    if ai<0:
        num_minus+=1
        a_modified.append(-ai)
    else:
        a_modified.append(ai)
if num_minus%2==0:
    print(sum(a_modified))
else:
    print(sum(a_modified)-2*sorted(a_modified)[0])

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

Solution (Python):

import sys
import math
import numpy as np
import itertools



n = int(input())

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

fugou = 0
saishou = 999999999999
goukei = 0

for i in range(n):
    if a[i] < 0:
        fugou += 1
    goukei += abs(a[i])
    saishou = min(saishou,abs(a[i]))
if fugou % 2 == 0:
    print(goukei)
else:
    print(goukei - 2*saishou)

Solution (Python):




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

mcnt = 0
absmin = 10**10
abssum = 0


for i in range(n):
    abssum += abs(d[i])
    if d[i] < 0:
        mcnt += 1
    if absmin > abs(d[i]):
        absmin = abs(d[i])
if mcnt % 2 == 0:
    ans = abssum
else:
    ans = abssum - (absmin * 2)


print(ans)

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A, dtype = 'int64')
k = np.where(A < 0)
l = len(k[0])
A = np.abs(A)
if l % 2 == 0:
    print(np.sum(A))
else:
    print(np.sum(A) - 2 * np.min(A))

Solution (Python):
N = int(input())
A = sorted([int(x) for x in input().split()])
ans, p = 0, 0
for i in range(N):
    p = i
    if A[i] >= 0:
        break
for i in range(N):
    if i < p:
        ans -= A[i]
    else:
        ans += A[i]
if p % 2 != 0:
    ans += max(2*A[p-1],-2*A[p])
print(ans)

Solution (Python):

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


ans = 0
minnum = abs(A[0])
numminus = 0
for i in range(N):
    if A[i]<0:
        numminus+=1
    ans += abs(A[i])
    minnum = min(minnum,abs(A[i]))
    
if numminus%2 == 1:
    ans -= minnum*2
print(ans)

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

minuses = sum(i < 0 for i in ls)

if minuses % 2 == 0:
	print(sum(abs(i) for i in ls))
else:
	absls = [abs(i) for i in ls]
	minimum = min(absls)
	print(sum(absls) - minimum * 2)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
 
sys.setrecursionlimit(10**7)
inf = 10**20
MOD = 998244353

N = int(input())
a = list(map(int,input().split()))
sumOfAbsValues = 0
minimumValueAbs = 10**10
minusSignParity = 0
zeroExists = False
for value in a:
    if value == 0:
        zeroExists = True
    absValue = abs(value)
    sumOfAbsValues += absValue
    minimumValueAbs = min(minimumValueAbs,absValue)
    if value < 0:
        minusSignParity += 1
if zeroExists:
    ans = sumOfAbsValues
elif minusSignParity%2 == 0:
    ans = sumOfAbsValues
else:
    ans = sumOfAbsValues - 2*minimumValueAbs
print(ans)

Solution (Python):

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

out = 0
negative_cnt = 0
min_abs = 1000000000
for _a in a:
    tmp = abs(_a)
    if _a <= 0:
        negative_cnt += 1
    min_abs = min(min_abs, tmp)
    out += tmp

if negative_cnt % 2 != 0:
    out -= min_abs * 2

print(out)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = []
kosu = 0
mini = 10**9

for i in range(n):
    if a[i] < 0:
        b.append(-a[i])
        kosu += 1
    else:
        b.append(a[i])
    mini = min(mini, b[i])

ans = sum(b)

if kosu % 2 == 0:
    print(ans)
else:
    print(ans - 2 * mini)

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

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

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

Solution (Python):


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

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

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

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

ans = 0
abs_mina = 10 ** 10
import copy
copy_a = copy.copy(a)
sum_a = 0

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

for i in a:
    ans += abs(i)
    abs_mina = min(abs_mina, abs(i))

if copy_a[-1] < 0:
    ans -= abs_mina * 2


print(ans)

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

minuc = 0
for i in range(N):
    if A[i] < 0:
        minuc += 1
ans = 0
if minuc % 2 == 0:
    for i in range(N):
        ans += abs(A[i])

else:
    for i in range(N):
        A[i] = abs(A[i])
    mina = min(A)
    for i in range(N):
        if mina == A[i]:
            ans -= A[i]
        else:
            ans += A[i]
print(ans)

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

b = list(filter(lambda x: x<0, a))
n = len(b)

c = list(map(abs, a))
d = c
s = sum(c)
if n & 1 == 1:
    s -= min(d)*2

print(s)

Solution (Python):
N = int(input())
import numpy as np
li = np.array(list(map(int,input().split())))	
li_abs = abs(li)
M = np.argmin(li_abs)
if sum(li < 0)%2 == 0:
    print(sum(li_abs))
else:
    for i in range(N-1):
        tmp = N-1-i
        if tmp == M:
            if li[tmp] >= 0:
                li[tmp] = li[tmp] * (-1)
                li[tmp - 1] = li[tmp - 1] * (-1)
        else:
            if li[tmp] < 0:
                li[tmp] = li[tmp]*(-1)
                li[tmp-1] = li[tmp-1]*(-1)

    print(sum(li))

Solution (Python):
n = int(input())
lists = list(map(int,input().split()))
ans = 0
count =0
min_num = 999999
for i in lists:
    if i<0:
        count+=1
if(count%2==0):
    for i in lists:
        ans += abs(i)
else:
    for i in lists:
        if abs(i) < min_num:
                min_num = abs(i)
    for i in lists:
        ans += abs(i)
    ans -= min_num*2
print(ans)

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

if count%2==0:
    ans=sum(a_abs)
else:
    ans=sum(a_abs)-2*min_abs
    
print(ans)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]
b = [abs(aa) for aa in a]
b.sort()
plus_a = len([aa for aa in a if aa > 0])
zero_a = a.count(0)
minus_a = n - plus_a - zero_a
if minus_a % 2 == 0:
    ans = sum(b)
else:
    ans = sum(b[1:]) - b[0]
print(ans)

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

cnt = 0

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

nA = [abs(a) for a in A]

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

Solution (Python):



from collections import deque
import heapq
import math
import bisect


def main():
    N = int(input())
    A = list(map(int, input().split()))
    dp = [[-1]*2 for i in range(N+1)]

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

    print(max(dp[N-2][0]+A[N-1], dp[N-2][1]-A[N-1]))


if __name__ == '__main__':
    main()

Solution (Python):
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    minus = len([a for a in A if a < 0])
    zero = len([a for a in A if a == 0])
    absA = [abs(a) for a in A]
    low = sorted(absA)[0]
    if minus % 2 == 0:
        return sum(absA)
    elif zero >= 1:
        return sum(absA)
    return sum(absA) - low * 2

print(solve())

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]
plus = True
absmin = 10000000000
s = 0
for i in a:
    if i < 0:
        plus = not plus
    absi = abs(i)
    if absi < absmin:
        absmin = absi
    s += absi
if plus:
    print(s)
else:
    print(s - absmin * 2)

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

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

if fu % 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()))

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

if count_minus % 2 == 0:
    print(sum(b))
if count_minus % 2 == 1:
    print(sum(b) - 2 * min(b))

Solution (Python):
from numpy import*
n,*a=map(int,open(0).read().split())
a=array(a)
if len(a[a<0])%2==0:
    print(sum(abs(a)))
else:
    a=sorted(abs(a))
    print(sum(a[1:])-a[0])

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

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

a.sort()
sum=0

if cnt%2==0:
  for j in range(n):
    sum+=a[j]
else:
  for j in range(n-1):
    sum+=a[j+1]
  sum-=a[0]

print(sum)

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

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

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

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

if ct % 2:
    ans = sum(A) - 2*min(A)
else:
    ans = sum(A)

print(ans)

Solution (Python):
import numpy

n = int(input())
a = []
a = numpy.array([ int(e) for e in input().split(" ")])



if sum(a < 0)%2 == 0:
    print(numpy.abs(a).sum())
else:
    tmp = numpy.abs(a)
    print( tmp.sum() -2*min(tmp))

Solution (Python):

"""
Created on Sat Apr 27 20:57:36 2019

@author: Yamazaki Kenichi
"""

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

flg = 1
m = 10**9
ans = 0
for c in A:
    flg *= -1 if c < 0 else 1
    m = min(m, abs(c))
    ans += abs(c)

ans = ans - (2*m if flg < 0 else 0)

print(ans)

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

count = 0
num = 0
absl = []

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

for j in range(n):
  absl.append(abs(a[j]))

num = sum(absl)

if count % 2 == 0:
  ans = num
else:
  ans = num - min(absl) * 2

print(ans)

Solution (Python):
import numpy as np

n = int(input())
an = np.array([int(i) for i in input().split(" ")])
suma = 0
suma = np.sum(an <= 0)
minus = np.empty(0)
if suma % 2 == 0:
    print(np.sum(np.abs(an)))
else:
    print(int(np.sum(np.abs(an)) - 2 * np.min(np.abs(an))))

Solution (Python):
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
count = 0
b = []
for i in a:
  if i <0:
    count += 1
  b.append(abs(i))
b.sort()
b = np.array(b)
if count % 2 ==0:
  print(b.sum())
else:
  print(b.sum()-b[0]*2)

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

dpP = [0] * N
dpN = [0] * N
dpP[0] = As[0]
dpN[0] = -As[0]

for i, A in enumerate(As[1:-1], 1):
    dpP[i] = max(dpP[i-1]+A, dpN[i-1]-A)
    dpN[i] = max(dpP[i-1]-A, dpN[i-1]+A)

dpP[N-1] = dpP[N-2]+As[N-1]
dpN[N-1] = dpN[N-2]-As[N-1]

print(max(dpP[N-1], dpN[N-1]))

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

pos = [a for a in As if a > 0]
neg = [a for a in As if a < 0]

if len(neg) % 2 == 0:
    print(sum(pos + [0]) - sum(neg + [0]))
else:
    print(sum(pos) - sum(neg) - 2 * min(map(abs, As)))

Solution (Python):
n=int(input())
a=list(map(int, input().split()))
temp=0
nummin=0
minabs=10**9
ans=0

for i in range(n):
    if a[i]==0:
        ans+=temp
        temp=0
        nummin=0
        minabs=0
    else:
        if a[i]<0:
            temp+=-a[i]
            nummin+=1
        else:
            temp+=a[i]
        if abs(a[i])<abs(minabs):
            minabs=a[i]
if nummin%2==1:
    temp-=abs(minabs)*2
ans+=temp
print(ans)

Solution (Python):


def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  N = readInts()[0]
  A = readInts()
  minus = 0
  m = abs(A[0])
  s = 0
  for a in A:
    if a < 0:
      minus += 1
    if abs(a) < m:
      m = abs(a)
    s += abs(a)

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

if __name__ == "__main__":
  main()

Solution (Python):
N=int(input())
LA=[int(x) for x in input().split()]
for i in range(len(LA)-1):
    if LA[i]>=0:
        pass
    else:
        LA[i]*=-1
        LA[i+1]*=-1

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

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

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

Solution (Python):
def input_ints():
    return list(map(int, input().split()))

def main():
    n = int(input())
    a = input_ints()
    c = 0
    for i in range(n):
        if a[i] < 0:
            c += 1
            a[i] *= -1
    ans = sum(a)
    if c % 2:
        ans -= 2 * min(a)
    print(ans)

if __name__ == '__main__':
    main()

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

minus = [i<0 for i in a]
a_abs = list(map(abs,a))

ans = sum(a_abs)
if sum(minus) %2 == 1:
    ans -= min(a_abs)*2
print(ans)

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime,random
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())
AA = inpl()

cnt = 0
plus_min = INF
mins_max = -INF
ans = 0

for a in AA:
    if a < 0:
        cnt += 1
        mins_max = max(mins_max,a)
        ans -= a
    else:
        plus_min = min(plus_min,a)
        ans += a

if cnt%2 == 0 :
    print(ans)
else:
    ans = max( ans + mins_max*2 , ans - plus_min*2 )
    print(ans)

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

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in sys.stdin.readline().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v

def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N = int(input())
    A = li_input()
    B = [abs(a) for a in A]

    n_negative = len([a for a in A if a < 0])

    if n_negative % 2 == 1:
        print(sum(B) - 2 * min(B))
    else:
        print(sum(B))


main()

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

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

for i in a:
    if i < 0:
        cnt += 1
    ans.append(abs(i))

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

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

Solution (Python):

import sys
import bisect


def solve(N: int, A: "List[int]"):
    A.sort()
    count_minus = bisect.bisect_left(A, 0)
    A = [abs(x) for x in A]
    A.sort()
    ret = sum(A)
    if count_minus % 2 != 0:
        ret -= A[0] * 2
    print(ret)
    return



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()))

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

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

if k%2 == 0:
    print(sum)
else:
    c = 10000000000
    for i in range(n):
        c = min(c,abs(a[i]))
    print(sum-2*c)

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

m = 1000000000
s = 0
f = 0

for i in range(N):
    if A[i] < 0:
        f += 1
    if m > abs(A[i]):
        m = abs(A[i])
    s += abs(A[i])
if f % 2 == 0:
    print(s)
else:
    print(s - m * 2)

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

memo = [[0, 0] for _ in range(n)]

memo[0][0] = A[0]
memo[0][1] = -A[0]

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

memo[n - 1][0] = memo[n - 2][0] + A[n - 1]
memo[n - 1][1] = memo[n - 2][1] - A[n - 1]

print(max(memo[-1]))

Solution (Python):
import numpy as np
N = int(input())
Alist = list(map(int, input().split())) 
Blist = list(map(abs, Alist))
Blist.sort()
parity = 1
for a in Alist:
    parity = parity*np.sign(a)
if parity>0:
    print(sum(Blist))
else:
    print(sum(Blist[1:])-Blist[0])

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
ans = []
num = 0
for i,x in enumerate(A):
    if x < 0:
        ans.append(-x)
        num += 1
    else:
        ans.append(x)
if num%2 == 0:
    print(sum(ans))
else:
    print(sum(ans)-2*min(ans))

Solution (Python):
import math

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

minus_count = 0
min_A = abs(A[0])
min_i = 0
for i in range(N):
    if A[i] < -1:
        minus_count += 1
    abs_a = abs(A[i])
    if min_A > abs_a:
        min_i = i
        min_A = abs_a

A2 = [abs(a) for a in A]
    
if minus_count % 2 == 0:
    out = sum(A2)
else:
    A2[min_i] *= -1
    out = sum(A2)

print(out)

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

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


dp[0][0]=A[0]
dp[0][1]=A[0]

for i in range(1,len(A)):
    if i!=1:
        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])  
    else:
        dp[i][0]=A[i-1]+A[i]
        dp[i][1]=-A[i-1]-A[i]              
print(max(dp[-1][0],dp[-1][1]))

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

cnt = 0
for x in a:
    if x > 0:
        break
    cnt += 1

if cnt % 2 == 0:
    print(sum(abs(x) for x in a))
else:
    y = [abs(x) for x in a]
    y.sort()
    print(sum(y[1:]) - y[0])

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

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

nega_count = [1 for x in A if x < 0]
nega_count = sum(nega_count)

B = [abs(x) for x in A]
if nega_count % 2 == 0:
  print(sum(B))
else:
  b = B.pop(B.index(min(B)))
  print(sum(B) - b)

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

Solution (Python):
from sys import stdin
from collections import deque, defaultdict as ddic
from itertools import combinations, permutations, product
import bisect
import heapq


rs = lambda: stdin.readline().strip()
ri = lambda: int(rs())
rsl = lambda: stdin.readline().split()
rim = lambda: map(int, rsl())
ril = lambda: list(rim())

N = ri()
A = list(rim())
B = [abs(elem) for elem in A]

low = min(B)
minus = 0
for i in range(len(A)):
    if A[i] < 0:
        minus += 1

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

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

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


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

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

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

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

Solution (Python):
N=int(input())
a_list = [int(i) for i in input().split()]
b_list = [abs(i) for i in a_list]
b_list.sort()
minus_number = 0
for i in a_list:
	if i<0:
		minus_number+=1
if minus_number%2==0:
	print(sum(b_list))
else:
	print(sum(b_list)-2*b_list[0])

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
plus = 0
minus = 0
cur = float('inf')
S = 0
for i in range(N):
  if A[i] > 0:
    plus += 1
    S += A[i]
    if A[i] < cur:
      cur = A[i]
  elif A[i] < 0:
    minus += 1
    S += -A[i]
    if -A[i] <= cur:
      cur = -A[i]
  else:
    cur = A[i]
if minus%2 == 0:
  print(S)
else:
  if cur != float('inf'):
    print(S-2*cur)
  else:
    print(S)

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

ma = sorted(x for x in A if x < 0)
pa = sorted(x for x in A if x >= 0)



if len(ma) % 2 == 0:
    result = -sum(ma) + sum(pa)
else:
    x = -ma[-1]
    if len(pa):
        x = min(x, pa[0])
    result = -sum(ma) + sum(pa) - x * 2

print(result)

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

absA = abs(A)
if sum(A <= 0) % 2 == 0:
    ans = sum(absA)
else:
    ans = sum(absA) - 2 * (min(absA))

print(ans)