Problem:
 Score : 400 points    Problem Statement There are N integers, A_1, A_2, ..., A_N , arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  Operation : Choose an integer i satisfying 1 \leq i \leq N-1 . Multiply both A_i and A_{i+1} by -1 .  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N .      Constraints  All values in input are integers.  2 \leq N \leq 10^5  -10^9 \leq A_i \leq 10^9         Input Input is given from Standard Input in the following format:  N  A_1  A_2  ...  A_N       Output Print the maximum possible value of B_1 + B_2 + ... + B_N .        Sample Input 1 3
-10 5 -4      Sample Output 1 19  If we perform the operation as follows:   Choose 1 as i , which changes the sequence to 10, -5, -4 .  Choose 2 as i , which changes the sequence to 10, 5, 4 .   we have B_1 = 10, B_2 = 5, B_3 = 4 . The sum here, B_1 + B_2 + B_3 = 10 + 5 + 4 = 19 , is the maximum possible result.       Sample Input 2 5
10 -4 -8 -11 3      Sample Output 2 30       Sample Input 3 11
-1000000000 1000000000 -1000000000 1000000000 -1000000000 0 1000000000 -1000000000 1000000000 -1000000000 1000000000      Sample Output 3 10000000000  The output may not fit into a 32 -bit integer type.

Solution (Python):

def main():
    
    
    
    N = int(input())
    A = tuple(map(int, input().split()))
    mi = abs(min(A, key=abs))
    abs_sum = sum(abs(i) for i in A)
    neg = sum(i < 0 for i in A)
    if 0 in A or neg % 2 == 0:
        print(abs_sum)
    else:
        print(abs_sum - mi * 2)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    
    
    
    N = int(input())
    A = tuple(map(int, input().split()))
    mi = min(abs(i) for i in A)
    abs_sum = sum(abs(i) for i in A)
    neg = sum(i < 0 for i in A)
    if 0 in A or neg % 2 == 0:
        print(abs_sum)
    else:
        print(abs_sum - mi * 2)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    N = int(input())
    A = tuple(map(int, input().split()))
    mi = min(abs(i) for i in A)
    abs_sum = sum(abs(i) for i in A)
    neg = sum(i < 0 for i in A)
    if 0 in A or neg % 2 == 0:
        print(abs_sum)
    else:
        print(abs_sum - mi * 2)


if __name__ == "__main__":
    main()

Solution (Python):
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

n=getint()
a=getints()
inf = 1 << 60

cache=[[-inf] * 2 for _ in range(n)]

def solve(pos, minus):
    if pos == n - 1:
        return -a[pos] if minus else a[pos]
    res = cache[pos][minus]
    if res > -inf:
        return res
    now = a[pos] if minus == 0 else -a[pos]
    res1 =  now + solve(pos + 1, 0)
    res2 = -now + solve(pos + 1, 1)
    res  = max(res1, res2)
    cache[pos][minus] = res
    return res

for i in range(n-1,-1,-1):
    solve(i, 0)
    solve(i, 1)

res = solve(0, 0)
print(res)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
ans = sum(map(abs,A))
flag = False
sign = 0
mi = 10 ** 9
for a in A:
    if a == 0:
        flag = True
        break
    if a < 0:
        sign += 1
    if abs(a) < mi: mi = abs(a)
if flag:
    print(ans)
else:
    if sign % 2 == 0:
        print(ans)
    else:
        print(ans-2*mi)

Solution (Python):
import fractions

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

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

if(count == 0 and flag==0):
    flag = 1

abss = [abs(a[i]) for i in range(n)]

if(flag==1):
    print(sum(abss))
else:
    print(sum(abss) - 2*min(abss))

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

count_0 = 0
count_minus = 0

abs_a = a

for i in range(n):
    if a[i] < 0:
        count_minus += 1
        abs_a[i] = -1*a[i]
    elif a[i] == 0:
        count_0 += 1

abs_a.sort()
a_sum = sum(abs_a)

if count_minus % 2 == 1 and count_0 == 0:
    print(a_sum - abs_a[0]*2)
else:
    print(a_sum)

Solution (Python):
from array import array

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

i_of_minimum_abs = 0
minimum_abs = 10**9
Aarray = array('l', A)

for i in range(N):
    a = Aarray[i]
    if abs(a) < minimum_abs:
        minimum_abs = min(minimum_abs, abs(a))
        i_of_minimum_abs = i

for i in range(i_of_minimum_abs):
    if Aarray[i] < 0:
        Aarray[i] = -Aarray[i]
        Aarray[i+1] = -Aarray[i+1]
        
for i in reversed(list(range(i_of_minimum_abs+1,N))):
    if Aarray[i] < 0:
        Aarray[i] = -Aarray[i]
        Aarray[i-1] = -Aarray[i-1]

print(sum(Aarray))

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

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

b.sort()
ans = sum(b)
if m % 2 == 1:
    ans -= b[0] * 2

print(ans)

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

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

minum = 0
minabs = float("inf")
allsum = 0

for i in A:

    if i < 0:
        minum += 1

    allsum += abs(i)
    minabs = min(minabs,abs(i))

if minum % 2 == 0:
    print (allsum)

else:
    print (allsum - 2 * minabs)

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

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

Solution (Python):

import sys
import math
from collections import defaultdict


sys.setrecursionlimit(10**7)
def input():
  return sys.stdin.readline()[:-1]


mod = 10**9 + 7


def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))



N = I()

A = III()

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

if num%2==0:
  print(sum(map(abs, A)))
else:
  print(sum(map(abs, A))-2*min(map(abs, A)))

Solution (Python):
import math
import copy

n = int(input())



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






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

print(dp[n][0])

Solution (Python):
N = int(input())
As = list(map(int, input().split()))
count = len(list(filter(lambda A: A < 0, As)))
As2 = list(map(abs, As))
As2.sort()

if count%2 == 0:
  r = sum(As2)
else:
  r = sum(As2)-2*As2[0]
print(r)

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

    pos = [0] * n
    neg = [0] * n

    pos[0] = aa[0]
    neg[0] = -aa[0]

    for i, a in enumerate(aa[1:-1], start=1):
        pos[i] = max(pos[i - 1] + a, neg[i - 1] - a)
        neg[i] = max(pos[i - 1] - a, neg[i - 1] + a)

    pos[n - 1] = pos[n - 2] + aa[n - 1]
    neg[n - 1] = neg[n - 2] - aa[n - 1]

    score = max(pos[n - 1], neg[n - 1])

    print(score)


main()

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

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

abs_ls = [abs(a) for a in a_ls]
if any([a < 0 for a in a_ls]):
    print(sum(abs_ls) - min(abs_ls) * 2)
else:
    print(sum(abs_ls))

Solution (Python):
import bisect
N = int(input())
A = [int(i) for i in input().split()]
A.sort()
idx = bisect.bisect_left(A,0)
ans = 0
if idx%2 == 0:
  ans += abs(sum(A[0:idx]))
  if N > idx:
    ans += sum(A[idx:])
else:
  ans += abs(sum(A[0:idx-1]))
  if idx < N:
    ans += abs(A[idx-1]+A[idx])
  elif idx == N:
    ans += A[idx-1]
  if idx + 1 < N:
    ans += sum(A[idx+1:])
print(ans)

Solution (Python):


n = int(input())
arr = list(map(int, input().split()))
minus_n = 0
positive_arr = list(sorted(list(map(lambda x: abs(x), arr))))
for a in arr:
    if a < 0:
        minus_n += 1

if minus_n % 2 == 0:
    print(sum(positive_arr))
else:
    print(sum(positive_arr) - positive_arr[0] * 2)

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

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

print(ans)

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

minus = sum(i <= 0 for i in a) 


abs = [abs(i) for i in a] 
  
if minus%2 == 0 or 0 in a:
  print(sum(abs))
else:
  abs[abs.index(min(abs))] *= -1
  print(sum(abs))

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

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

has_zero = False
min_abs = 10**5
sum_abs = 0
for i in range(N):
    if A[i] == 0:
        has_zero = True
    sum_abs += abs(A[i])
    if abs(A[i]) < min_abs:
        min_abs = abs(A[i])

minus = (tuple(filter(lambda x: x < 0, A)))
cnt_minus = len(minus)
if cnt_minus % 2 == 0 or has_zero == True:
    print(sum_abs)
else:
    print(sum_abs - 2*min_abs)

Solution (Python):


def count_negative(n,a):
    count = 0
    for i in range(n):
        if a[i] == 0:
            return 0
        elif a[i] < 0:
            count += 1
    return count

def num_of_min(n,a):
    minimum = sum(map(abs,a))
    
    count = 0    
    tmp = 0
    for i in range(n):
        tmp = abs(a[i])
        if tmp < minimum:
            minimum = tmp
            count = i
        else:
            pass
    return count

def flipping(n,a):
    nc = count_negative(n,a)
    total = 0
    count = 0
    if nc % 2 == 0:
        total = sum(map(abs,a))
    else:
        count = num_of_min(n,a)
        target = a.pop(count)
        
        total = sum(map(abs,a))
        if target > 0:
            total += target*(-1)
        else:
            total += target

    return total

if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())
    gt = flipping(n,a)
    print("%d" %gt)

Solution (Python):
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
import math

N = int(input())
A = list(map(int, input().split()))
zeros = 0
minus = 0
B = []
for i in range(len(A)):
	if A[i] < 0:
		minus += 1
	elif A[i] == 0:
		zeros += 1
	B.append(abs(A[i]))


if zeros > 0:
	print(sum(B))
elif minus % 2 == 0:
	print(sum(B))
else:
	print(sum(B) - 2*min(B))

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

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

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

count = 0
minabs = max(max(a),-min(a))
sumabs = 0
for i in range(n):
    if a[i] < 0:
        count += 1
        sumabs += -a[i]
    else:
        sumabs += a[i]
    minabs = min(minabs,abs(a[i]))
if count%2 == 0:
    print(sumabs)
else:
    print(sumabs-2*minabs)

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
neg_A = len(list(filter( lambda x: x < 0, A)))
A = sorted(map(abs, A))

if neg_A%2 == 0:
  print(sum(A))
else:
  print(sum(A)-2*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 += 1
        a[i] = abs(a[i])
a = sorted(a)
if count%2 != 0:
    a[0] = a[0]*-1
ans = 0
for i in range(n):
    ans += a[i]
print(ans)

Solution (Python):
n = int(input())
li = list(map(int,input().split()))
cnt = 0
for i in li:
    if i <= 0:cnt+=1
if cnt%2:
    d = sorted(li,key=lambda x:abs(x))[0]
    print(sum(list(map(lambda x:abs(x),li)))-abs(d)*2)
else:print(sum(list(map(lambda x:abs(x),li))))

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.sort()
import numpy as np
Ac = A.copy()
Ac.sort(key = lambda x:np.abs(x))

import bisect
zero_idx = bisect.bisect(A,0)
if zero_idx == 0:
    An = []
    Ap = A[:]
elif zero_idx == N:
    Ap = []
    An = A[:]
else:
    An = A[:zero_idx]
    Ap = A[zero_idx:]
    
pnum = len(Ap)
nnum = len(An)
ans = 0
total = 0
for a in A:
    total += int(np.abs(a))

if N%2 == 0:
    if nnum % 2 == 0:
        ans = total
    else:
        ans = total - 2 * np.abs(Ac[0])
           
    
else:
    if nnum % 2 == 1:        
        ans = total - 2 * np.abs(Ac[0])
    else:           
        ans = total
    
    
print(ans)

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

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

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

b=0
minus=0
low=abs(a[0])
for i in range(n):
    if a[i]>0:
        b += a[i]
    else:
        b -= a[i]
        minus += 1
    if abs(a[i])<low:
        low = abs(a[i])

print(b if minus%2==0 else b-2*low)

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

p = 0
m = float('inf')
ret = 0
for a in A :
    if a < 0 :
        p ^= 1
        m = min(m, -a)
        ret -= a
    else :
        m = min(m, a)
        ret += a
        
if p == 0 :
    print(ret)
else :
    print(ret - 2 * m)

Solution (Python):
import bisect
n = int(input())
A = [int(a) for a in input().split()]
A.sort()
A_abs = [abs(ab) for ab in A]
A_abs.sort()
sum_abs = sum(A_abs)

wh = bisect.bisect_left(A, 0)
dev2 = wh % 2
if dev2 == 0:
  print(sum_abs)
else:
  print(sum_abs - 2 * A_abs[0])

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



count = 0
odd = 0

min1 = abs(s[0])

for i in range(N):
  min1 = min(min1, abs(s[i]))
  count += abs(s[i])
  if abs(s[i]) != s[i]:
    odd += 1

count2 = count - 2*min1

if odd%2 == 1:
  print(count2)
else:
  print(count)

Solution (Python):
import numpy as np

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

minus = 0

minim = 100000000

for i,v in enumerate(A):
    if v < 0 :
        minus += 1
        A[i] = -v
    minim = min(minim,A[i])

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

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

sign = len([i for i in a if i < 0]) % 2
b = list(map(abs, a))
b.sort()

if sign == 0:
	print(sum(b))
else:
	print(sum(b) - b[0] * 2)

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

sum_abs_all = False
minus_count = 0

for i in A_list:
    if i == 0:
        sum_abs_all = True
        break
    if i < 0:
        minus_count += 1

if minus_count % 2 == 0:
    sum_abs_all = True

abs_A_list = [abs(i) for i in A_list]

ans = 0
for i in abs_A_list:
    ans += i

if not sum_abs_all:
    abs_A_list.sort()
    ans -= 2*abs_A_list[0]

print(ans)

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

Solution (Python):
N, *A = map(int, open(0).read().split())

dp = [[0] * 2 for _ in range(N + 1)]
dp[0][1] = -float('inf')

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

Solution (Python):
N, *A = map(int, open(0).read().split())

s = list(abs(x) for x in A)
cnt = sum(x < 0 for x in A)
if (cnt % 2 == 0) or (0 in A):
    print(sum(s))
else:
    print(sum(s) - 2 * min(s))

Solution (Python):
import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
MAX = 10**5+5
INF = 10**9

def resolve():
    n = int(input())
    a = [0]
    a.extend(list(map(int,input().split())))
    dp = [[0,0] for _ in range(n+1)]
    dp[0][1]=-INF
    for i in range(1,n+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]-a[i],dp[i-1][1]+a[i])
    print(dp[n][0])

if __name__ == "__main__":
    resolve()

Solution (Python):



n = int(input())
a = list(map(int,input().split()))
cnt = 0
mi = float('inf')
tmp = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
    if mi > abs(a[i]):
        mi = abs(a[i])
        tmp = i
s = list(map(lambda x:abs(x),a))
if cnt % 2:
    print(sum(s)-2*s[tmp])
else:
    print(sum(s))

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

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

Solution (Python):
import bisect
n = int(input())
a = [int(_) for _ in input().split()]
a.sort()
i = bisect.bisect_left(a,0)
if i % 2 == 1:
    i -= 1
for j in range(i):
    a[j] *= -1
if i == n-1 or i == n:
    print(sum(a))
else:
    if a[i] + a[i+1] >= 0:
        print(sum(a))
    else:
        a[i] *= -1
        a[i+1] *= -1
        print(sum(a))

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

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

Solution (Python):




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

n_minus = 0
mn = 10**9
abssum = 0
for a in a_list:
  absa = abs(a)
  abssum += absa
  if a < 0:
    n_minus += 1
  if absa < mn:
    mn = absa
    
if n_minus %2 == 0:
  print(abssum)
else:
  print(abssum - 2*mn)

Solution (Python):
import sys
from functools import reduce

def main():
    input = sys.stdin.readline
    N = int(input())
    As = list(map(int, input().split()))
    sign = reduce(lambda x, y: x * y, [int(a >= 0) * 2 - 1 for a in As])
    A_abs = [abs(a) for a in As]
    ans = sum(A_abs) if sign > 0 else sum(A_abs) - 2 * min(A_abs)
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
dp = {}
dp[0,0] = 0
dp[0,1] = -float('inf')
for i in range(1, n+1):
    dp[i, 0] = max(dp[i-1, 0] + a[i-1], dp[i-1, 1] - a[i-1])
    dp[i, 1] = max(dp[i-1, 0] - a[i-1], dp[i-1, 1] + a[i-1])
print(dp[n, 0])

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
c = 0
z = False
for aa in a:
    if aa < 0:
        c += 1
    elif aa == 0:
        z = True
if z or c % 2 ==0:
    print(sum(map(abs, a)))
else:
    ab = [abs(x) for x in a]
    ans = sum(ab) - min(ab)*2
    print(ans)

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

dp_0 = an[0]
dp_1 = -an[0]

for i in range(1,n):
  dp_0, dp_1 = [max(dp_0 + an[i], dp_1 - an[i]), max(dp_0 - an[i], dp_1 + an[i])]

print(dp_0)

Solution (Python):
from numpy import zeros

inf = float('inf')

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

dp = zeros((n + 1, 2))
dp[0][1] = -inf


for i, aa in enumerate(a):
    if aa >= 0:
        dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
        dp[i + 1][1] = max(dp[i][1] + aa, dp[i][0] - aa)
    else:
        dp[i + 1][0] = max(dp[i][1] - aa, dp[i][0] + aa)
        dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)


print(int(dp[n][0]))

Solution (Python):
import numpy as np

inf = float('inf')

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

dp = np.zeros((n + 1, 2))
dp[0][1] = -inf


for i, aa in enumerate(a):
    if aa >= 0:
        dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
        dp[i + 1][1] = max(dp[i][1] + aa, dp[i][0] - aa)
    else:
        dp[i + 1][0] = max(dp[i][1] - aa, dp[i][0] + aa)
        dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)


print(int(dp[n][0]))

Solution (Python):
inf = float('inf')

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

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


for i, aa in enumerate(a):
    if aa >= 0:
        dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
        dp[i + 1][1] = max(dp[i][1] + aa, dp[i][0] - aa)
    else:
        dp[i + 1][0] = max(dp[i][1] - aa, dp[i][0] + aa)
        dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)


print(dp[n][0])

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

minus_count = len(tuple(filter(lambda x: x < 0, a)))
b = tuple(sorted(map(abs, a)))
s = sum(b)
if minus_count % 2 == 1:
    s -= b[0] * 2
print(s)

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

cnt = 0
s = 0
minabs = 10**11
for a in A:
    if a <= -1:
        cnt += 1
    s += abs(a)
    minabs = min(minabs, abs(a))

if cnt % 2 == 0:
    print(s)
else:
    print(s-minabs*2)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
X=[[0,0]]
Y=[[0,0]]
for i in A:
    if i<0:
        k=1-X[-1][1]
    else:
        k=X[-1][1]
    X.append([X[-1][0]+abs(i),k])
for i in A[::-1]:
    if i<0:
        k=1-Y[-1][1]
    else:
        k=Y[-1][1]
    Y.append([Y[-1][0]+abs(i),k])
Y.reverse()

ans=-10**20
for i in range(N):
    t=(-1)**(X[i][1]+Y[i+1][1])
    a=X[i][0]+Y[i+1][0]+t*A[i]
    ans=max(a,ans)
print(ans)

Solution (Python):
input()
A=list(map(int,input().strip().split(" ")))
pos=[]
neg=[]
for x in A:
    if x>=0:
        pos+=[x]
    else:
        neg+=[x]

pos=sorted(pos)
neg=sorted(neg)

if len(neg)%2==0:
    print(sum(pos)-sum(neg))
else:
    ans1=sum(pos)-sum(neg)+2*neg[-1]
    ans2=sum(pos)-sum(neg)+2*neg[-1]
    if len(pos)>0:
        ans2=sum(pos)-sum(neg)-2*pos[0]
    print(max(ans1,ans2))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
b = [abs(ai) for ai in a]
b.sort()
negative_count = len([ai for ai in a if ai < 0])
if negative_count % 2 == 1:
    b[0] *= (-1)

print(sum(b))

Solution (Python):
def larger(x, y):
	if x > y:
		return x
	return y

N = int(input())
A = list(map(int, input().split()))
dpp = [A[0]]
dpn = [-A[0]]
for i in range(1, N-1):
	nextdpp = larger(dpp[-1]+A[i], dpn[-1]-A[i])
	nextdpn = larger(dpp[-1]-A[i], dpn[-1]+A[i])
	dpp.append(nextdpp)
	dpn.append(nextdpn)
print(larger(dpp[-1]+A[N-1], dpn[-1]-A[N-1]))

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

Solution (Python):
import sys
from collections import deque  
from collections import defaultdict  
from heapq import heapify, heappush, heappop, heappushpop  
from bisect import bisect_left, bisect_right  



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

def main():
    N = i2n()
    A = i2nn()
    A.sort()
    n = 0
    for i in range(1, N, 2):
        t = A[i-1] + A[i]
        if t < 0:
            t = -t
        n += t
    if N % 2 == 1:
        n += A[-1]
    print(n)

main()

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

tmp = sum(np.abs(a))
if np.count_nonzero(a < 0)%2 == 0:
    print(tmp)
else:
    ind = np.argmin(np.abs(a))
    print(tmp-abs(a[ind])*2)

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

    n_neg = 0
    near_zero = 10 ** 10
    for a in A:
        if a < 0:
            n_neg += 1
        near_zero = min(near_zero, abs(a))

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


main()

Solution (Python):
import math

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

  count = 0
  sum = 0
  min_number = 10000000000
  for i in a:
    count += 1 if i<0 else 0
    sum += abs(i)
    min_number = min(min_number, abs(i))
    
  if count % 2 == 0:
    print(sum)
  else:
    print(sum - min_number*2)
  
main()

Solution (Python):
n = int(input())
num_list = [ int(v) for v in input().split() ]

sign = len([ v for v in num_list if v < 0 ])
mini = min([ abs(v) for v in num_list ])
total = sum([ abs(v) for v in num_list ])

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

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

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

A.sort()
k = 0
while k<=n-1 and A[k]<0:
    k += 1
if k%2==0:
    print(-sum(A[:k])+sum(A[k:]))
elif k%2==1 and k==n:
    print(-sum(A[:k-1]) + sum(A[k-1:]))
else:
    print(max(-sum(A[:k-1])+sum(A[k-1:]) , -sum(A[:k+1])+sum(A[k+1:])))

Solution (Python):
import bisect
total = 0
N = int(input())
A = list(map(int, input().split()))
hu = [i for i in A if i < 0]
sei = [i for i in A if i >= 0]
hu.sort()
sei.sort()
if len(hu) % 2 == 0:
    print(sum(sei)+sum(hu)*-1)
else:
    if sei:
        print(sum(sei)+sum(hu)*-1 - min(-1*hu[-1], sei[0])*2)
    else:
        print(sum(sei)+sum(hu)*-1 + 1*hu[-1]*2)

Solution (Python):
N = int(input())
line = [int(a) for a in input().split()]
if 0 in line:
  line = [abs(a) for a in line]
  print(sum(line))
else:
  b = [i for i in line if i<0]
  if len(b)%2==0:
    line = [abs(a) for a in line]
    ans = sum(line)
    print(ans)
  else:
    line = [abs(a) for a in line]
    line.sort()
    ans = sum(line)-2*line[0]
    print(ans)

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

negative_number_count = list(map(lambda x: x < 0, A)).count(True)
B_tmp = sorted(map(abs, A))

if negative_number_count % 2 == 0:
    print(sum(B_tmp))
else:
    print(sum(B_tmp[1:]) - B_tmp[0])

Solution (Python):
from datetime import datetime as dt
N = int(input())
Ns = list(map(int,input().split(" ")))

l1 = len(Ns)
c = 0
for i in Ns:
    if i <= 0:
        c += 1

Ns = list(map(abs,Ns))
if c % 2 == 0:
    diff = 0
else:
    diff = min(Ns)
ans = sum(Ns) -2*diff
print(ans)

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

Ap=[]
Am=[]
for a in A:
    if a >= 0:
        Ap.append(a)
    else:
        Am.append(a)

Ap=sorted(Ap)
Am=sorted(Am,reverse=True)


if len(Ap)==0:
    if len(Am)%2==0:
        ans=-sum(Am)
    else:
        ans=-sum(Am)+2*Am[0]
        
elif len(Am)%2==0:
    Ams=-sum(Am)
    Aps=sum(Ap)
    ans=Ams+Aps
else:
    Ams=-sum(Am)+Am[0]
    Aps=sum(Ap)-Ap[0]
    tmp=Ap[0]+Am[0]
    if tmp<0:
        tmp=-tmp
    ans=Ams+Aps+tmp
        
print(ans)

Solution (Python):

from collections import defaultdict
import math
import re

def main():
    
    N = int(input())
    A_list = [int(a) for a in input().split()]

    min_val = 10 ** 10
    neg_num = 0
    total = 0
    for a in A_list:
        abs_a = a if a > 0 else -a
        if abs_a < min_val:
            min_val = abs_a
        if a < 0:
            neg_num += 1
        total += abs_a

    if neg_num % 2 != 0:
        total -= 2 * min_val
    print(total)

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
lst_a = list(map(int,input().split()))
num_minus = sum(i<0 for i in lst_a)
lst_abs = [abs(i) for i in lst_a]
if num_minus%2 == 0:print(sum(lst_abs))
else:print(sum(lst_abs)-2*min(lst_abs))

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

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
abs_A = [abs(i) for i in A]
ans = 0
if (0 in A) or (np.count_nonzero(A<0) % 2 == 0):
    ans = sum(abs_A)
else:
    ans = sum(abs_A) - 2*min(abs_A)
print(ans)

Solution (Python):
import numpy
N = map(int, input().split())
A_list = list(map(int, input().split()))
set = numpy.abs(numpy.array(A_list))
A_abs_min = min(set)
A_abs_sum = sum(set)
n = sum(x<0 for x in A_list)%2  
if n == 1:
    ans = A_abs_sum-2*A_abs_min
else:
    ans =  A_abs_sum
print(ans)

Solution (Python):
import numpy as np
def solve(n, a):
    b = np.abs(a)
    num = 0
    for i in range(n):
        if a[i] < 0:
            num += 1
    if num % 2 == 0:
        return np.sum(b)
    else:
        return np.sum(b) - 2*np.min(b)

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

Solution (Python):
n = int(input())
s = [int(i) for i in input().split()]
count = 0
for i in range(len(s)):
    if s[i] <0:
        count += 1

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

Solution (Python):
import numpy as np
N = int(input())
Alist = np.array(list(map(int, input().split())))
Blist = list(map(abs, Alist))
nom = sum(Alist<0)
if nom%2 == 0 :
    ans = sum(Blist)
else :
    ans = sum(Blist) - 2*min(Blist)
print(ans)

Solution (Python):





from functools import reduce

n = int(input())
minn = 10**9
arr = list(map(int, input().split()))
minus = 0
ans = reduce(lambda x, y: abs(x) + abs(y), arr)
for i in range(n):
    if arr[i] < 0:
        minus += 1
    if minn > abs(arr[i]):
        minn = abs(arr[i])
if minus % 2 == 0:
    print(ans)
else:
    print(ans-minn*2)

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

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

minus_cnt_is_even = True
has_zero = False
min_a = 1000000000
sum_a = 0
for item in a:
    if item < 0:
        item = -item
        minus_cnt_is_even = not minus_cnt_is_even
    elif item == 0:
        has_zero = True
    min_a = min(min_a, item)
    sum_a += item
if has_zero or minus_cnt_is_even:
    print(sum_a)
else:
    print(sum_a - min_a*2)

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

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
ans = sum([abs(item) for item in A])
def flip(a):
    res = [a[0]]
    for i in range(len(a) - 2):
        if a[i] < 0:
            a[i+1] = - a[i+1]
        res.append(a[i+1])
    return(res)
r = flip(A[:])
l = flip(A[::-1])[::-1]
costs = []
for ri, li in  zip(r, l):
    if ri * li >= 0:
        costs = [0]
        break
    else:
        costs.append(min(abs(ri), abs(li)))
print(ans - 2 * min(costs))