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

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

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

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

Ans = sum(A)
if cnt % 2 == 1:
  Ans -= mi * 2

print(Ans)

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

Solution (Python):

import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    for i in range(N-1):
        if A[i] < 0:
            A[i] *= -1
            A[i+1] *= -1
    a_sum =sum(A)

    aa = list(map(abs, A))
    return max(a_sum, sum(aa) - 2*min(aa))


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int,input().split()))
A = np.array(A).astype(np.int64)
odd_even = np.sum(A<0) %2
absA = np.abs(A)
abssum = np.sum(absA)
if odd_even==1:

    ans = abssum - 2 * np.sort(absA)[0]
else:
    ans  = abssum
print(ans)

Solution (Python):


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

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


main()

Solution (Python):

if __name__ == "__main__":
    n = int(input())
    a = list(map(int, input().split()))
    bsum = 0
    ma = a[0]
    if ma < 0:
        ma = -ma
    count = 0
    for aa in a:
        if aa < 0:
            count += 1
            aa = -aa
        bsum += aa
        if aa < ma:
            ma = aa
    if count % 2 == 0:
        print(bsum)
    else:
        print(bsum-2*ma)

Solution (Python):

from __future__ import division, print_function

import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def main():
    n = int(readline())
    a = readlist()
    neg_cnt = sum(ai < 0 for ai in a)
    if neg_cnt % 2 == 0:
        print(sum(map(abs, a)))
    else:
        print(sum(map(abs, a)) - 2 * min(abs(ai) for ai in a))




BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


class ostream:
    def __lshift__(self, a):
        if a is endl:
            sys.stdout.write(b"\n")
            sys.stdout.flush()
        else:
            sys.stdout.write(str(a))
        return self


def print(*args, **kwargs):
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
cout, endl = ostream(), object()

readline = sys.stdin.readline
readlist = lambda var=int: [var(n) for n in readline().split()]
input = lambda: readline().rstrip(b"\r\n")



if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int,input().split()))
a.sort()
cnt = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
    if a[i] == 0:
        cnt = -1
res = 0
if cnt == -1:
    for i in range(n):
        res += abs(a[i])
elif cnt % 2 == 0:
    for i in range(n):
        res += abs(a[i])
else:
    if cnt == n:
        for i in range(n-1):
            res += abs(a[i])
        res += a[-1]
    else:
        for i in range(cnt-1):
            res += abs(a[i])
        res +=  max(abs(a[cnt-1])-a[cnt],a[cnt-1]+a[cnt])
        for i in range(cnt+1,n):
            res += abs(a[i])
print(res)

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

sign = 0
for i in range(N):
    if A[i] < 0:
        sign += 1
        A[i] *= -1
sign %= 2
A.sort()
if sign == 0:
    print(sum(A))
else:
    print(sum(A[1:])-A[0])

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

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

MINUS=0

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

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

if MINUS%2==0:
    print(sum(ABS))

else:
    print(sum(ABS)-min(ABS)*2)

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

check = 0
m = int(1e10)
ans = 0

for i in A:
    ans += abs(i)
    m = min(m, abs(i))
    if i < 0:
        check += 1

if check % 2 == 1:
    ans -= m * 2

print(ans)

Solution (Python):
n = int(input())
arr = list(map(int, input().split()))
zetArr = list(map(abs, arr))
minusNum = 0
minZ = min(zetArr)
for e in arr:
    if e < 0:
        minusNum += 1

if minusNum % 2 == 0:
    print(sum(zetArr))
else:
    print(sum(zetArr) - 2 * minZ)

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

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

cnt1 = 0
flag = False
for i in range(N):
    num = A[i]
    if num == 0:
        flag = True
    if num < 0:
        cnt1 += 1
        A[i] = -num

if flag or cnt1 % 2 == 0:
    print sum(A)
else:
    print sum(A) - min(A) * 2

Solution (Python):
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from collections import Counter
from itertools import product

def main():
    N = II()
    A = LI()
    n_neg = 0
    for a in A:
        if a < 0:
            n_neg += 1
        elif a == 0:
            n_neg = 0
            break
    if n_neg % 2 == 0:
        ans = sum(abs(a) for a in A)
    else:
        A = [abs(a) for a in A]
        A.sort()
        ans = sum(A[1:]) - A[0]

    return ans

print(main())

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
plus=0
zero=0
minus=0
for i in A:
    if i>0:
        plus+=1
    elif i==0:
        zero+=1
    else:
        minus+=1

if zero>0:
    print(sum([abs(i) for i in A]))
else:
    if minus%2==0:
        print(sum([abs(i) for i in A]))
    else:
        B=[abs(i) for i in A]
        print(sum(B)-2*min(B))

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

cnt_fu = 0

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

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

if cnt_fu & 1:
    print (sum(b)-min(b)*2)
else:
    print (sum(b) )

Solution (Python):
import numpy as np

N = int(input())
A = np.array([int(x) for x in input().split()], dtype = np.int64)

abs_A = np.abs(A)
abs_sum = abs_A.sum()
abs_min = abs_A.min()
negatives = (A < 0).sum()

ans = abs_sum if negatives%2 == 0 else abs_sum - 2*abs_min
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = sorted(LI())
    for i in range(n//2):
        if a[i*2+1] <= 0:
            a[i*2] *= -1
            a[i*2+1] *= -1
        else:
            if a[i*2] * -1 > a[i*2+1]:
                a[i*2] *= -1
                a[i*2+1] *= -1
            break

    return sum(a)


print(main())

Solution (Python):


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

nns = len([x for x in a if x < 0])

ans = sum(abs(x) for x in a)
if nns % 2 != 0:
    m = min(abs(x) for x in a)
    ans -= m * 2

print(ans)