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.



Sample input:
3
-10 5 -4


Sample output:
19

Submission status: Runtime Error

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

for i in range(len(a) - 1):
  if a[i] < 0 and a[i+1] < 0:
    a[i] *= -1
    a[i+1] *= -1
  elif a[i] < 0 and abs(a[i]) > abs(a[i+1]):
    a[i] *= -1
    a[i+1] *= -1
  elif a[i+1] < 0 and abs(a[i]) < abs(a[i+1]):
    if i < n-1 and abs(a[i]) > abs(a[i+2]):
      continue
    else:
      a[i] *= -1
      a[i+1] *= -1
      
print(sum(a))

Submission status: Runtime Error

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

a.sort()

b = []

for j in range(n):
    b.append(abs(a[j]))
    
i = 0

while a[i] < 0 and i <= n-1:
    i += 1

if i % 2 == 0:
    print(str(sum(b)))

else:
    print(str(sum(b) - 2 * min(b)))

Submission status: Runtime Error

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
memo = [{} for i in range(N)]

def ddp(cur_N, ai):
    if ai in memo[cur_N]:
        return memo[cur_N][ai]
    if cur_N >=N-1:
        return ai
    nx = Alist[cur_N+1]
    ret = max(ai + ddp(cur_N+1, nx), -ai + ddp(cur_N+1, -nx))
    memo[cur_N][ai] = ret
    return ret
print(ddp(0, Alist[0]))

Submission status: Runtime Error

Solution code:
# D

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

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

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1
    
tmp = [A]
for i in reversed(range(0, N-1)):
    A[i] *= -1
    A[i+1] *= -1
    tmp.append(sum(A))
    
print(max(tmp))

Submission status: Runtime Error

Solution code:
from functools import lru_cache
N = int(input())
A = list(map(int, input().split()))


@lru_cache(maxsize=None)
def rec(i, reverse):
    if i == N - 1:
        return A[i] * reverse

    num_normal = rec(i + 1, +1) + (A[i] * reverse)
    num_reverse = rec(i + 1, -1) + (-A[i] * reverse)

    return max(num_normal, num_reverse)


print(rec(0, 1))

Submission status: Runtime Error

Solution code:
import math
import sys


def parse(file):
    n = int(file.readline().strip())
    nums = map(int, file.readline().split())
    return n, nums


def main(n, nums):
    minimum_abs = math.inf
    negatives = 0
    ans = 0

    for num in nums:
        if num < 0:
            a = - num
            negatives += 1
        else:
            a = num

        if a < minimum_abs:
            minimum_abs = a
        ans += a

    if negatives % 2 == 1:
        ans -= (minimum_abs * 2)

    return ans


if __name__ == '__main__':
    print(main(*parse(sys.stdin)))

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
B = [abs(i) for i in A]
for i in range(N-1):
    if(A[i]<0):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
if(A[N]<0):
    flag = False
else:
    flag = True

if(flag):
    print(sum(A))
else:
    m = min(B)
    print(sum(B))

Submission status: Runtime Error

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

# A has 0
if abs_list[0] == 0:
	print(sum(abs_list))
elif len(neg) % 2 == 0:
	print(sum(abs_list))
elif abs(pos[0]) < abs(neg[-1]):
	print(sum(abs_list) - 2*pos[0])
else:
	print(sum(pos) + sum(neg[:-1]))

Submission status: Runtime Error

Solution code:
from sys import stdin

readline = stdin.readline

_, *a = map(int, open(0).read().split())
res = 0
mi = 1_000_000_000
rem = True
for v in a:
    if v < 0:
        rem = not rem
    b = abs(v)
    res += b
    mi = min(b, mi)
if rem:
    res -= mi*2
print(res)

Submission status: Runtime Error

Solution code:
N = int(input().rstrip())
A = map(int, input().rstrip().split())
for i in range(len(A)):
  if A[i] >= 0 and A[i+1] >= 0:
    pass
  else:
    s = A[i] + A[i+1]
    if s < -s:
      A[i] = -A[i]
      A[i+1] = -A[i+1]
print(sum(A))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

def dp(A):
    if len(A) == 2:
        return A[0] + A[1] if A[0] + A[1] > -A[0] + -A[1] else -A[0] + -A[1]

    A_last, rA_last = A[-1], -A[-1]
    rA = A[:-1]
    rA[-1] = -rA[-1]
    return max( dp(A[:-1])+A_last, dp(rA)+rA_last)

print '{}'.format(dp(A))

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
b=min(B)
c=min(C)
d=min(b,c)
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*c)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from collections import defaultdict
from sys import setrecursionlimit
setrecursionlimit(100000)
def inpl(): return list(map(int, input().split()))
N = int(input())
A = inpl()

def calc(i):
    if i == N-2:
        return (A[i], A[i+1]), (-A[i], -A[i+1])
    else:
        X, Y = calc(i+1)
        return ([A[i], max(X[0] + X[1], Y[0] + Y[1])],
                [-A[i], max(-X[0] + X[1], -Y[0] + Y[1])])

print(max(map(sum, calc(0))))

Submission status: Runtime Error

Solution code:
from sys import stdin

readline = stdin.readline

_, *a = map(int, open(0).read().split())
res = 0
mi = 1_000_000_000
rem = True
for v in a:
    if v < 0:
        rem != rem
    b = abs(v)
    res += b
    mi = min(b, mi)
if rem:
    res -= mi*2
print(res)

Submission status: Runtime Error

Solution code:
n=int(input())
aa=(map(int,input().split()))
aa.append(0)
aaa=tuple(a)
a=list(aaa)
for i in range(n-1):
    if a[i]<0:
        a[i]=-1*a[i]
        a[i+1]=-1*a[i+1]
b=list(aaa)
for i in range(n,0,-1):
    if b[i]<0:
        b[i]=-1*b[i]
        b[i-1]=-1*b[i-1]

print(max(sum(a),sum(b))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split(" ")))
abs_list = list(map(abs, A))
abs_list.sort()
pos = list(filter(lambda x: x > 0, A))
neg = list(filter(lambda x: x < 0, A))
pos.sort()
neg.sort()
# A has 0
if abs_list[0] == 0:
	print(sum(abs_list))
elif len(neg) % 2 == 0:
	print(sum(abs_list))
elif abs(pos[0]) < abs(neg[-1]):
	print(sum(abs_list) - 2*pos[0] - 2*neg[-1])
else:
	print(sum(pos) - sum(neg[:-1]))

Submission status: Runtime Error

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

for i in range(len(a)-1):
	 
	if a[i] < 0 and a[i+1] < 0:         
	    a[i] *= -1 
        a[i+1] *= -1  
    elif a[i] < 0 and abs(a[i]) > abs(a[i+1]): 
        a[i] *= -1 
        a[i+1] *= -1 
    elif a[i+1] < 0 and abs(a[i]) < abs(a[i+1]):
	    if i < n-1 and abs(a[i]) > abs(a[i+2]):
	        continue
	    else: 
            a[i] *= -1
            a[i+1] *= -1 
          
print(sum(a))

Submission status: Runtime Error

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

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

goukei=0
if mynas % 2 ==0:
    for j in range(n):
        goukei+=abs(a[j])
else:
    a=np.array(a)
    np.abs(a)
    a=np.sort(a)
    for k in range(n):
        goukei+=a[i]
    goukei-=a[0]*2

print(goukei)

Submission status: Runtime Error

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

def dp(A):
    if len(A) == 2:
        return A[0] + A[1] if A[0] + A[1] > -A[0] + -A[1] else -A[0] + -A[1]
    A_last, rA_last = A[-1], -A[-1]
    A, rA = A[:-1], A[:-1]
    rA[-1] = -rA[-1]
    return max( dp(A)+A_last, dp(rA)+rA_last)


print '{}'.format(dp(A))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
a = np.array(a, dtype='int64')
a.sort()
for i in range(n):
    if a[i] > 0:
        k = i
        break
a = np.absolute(a)
a.sort()

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
b=min(B)
c=min(C)
d=min(b,c)
if B==[]:
    print(sum(C))
elif len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*c)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

a.sort()

i = 0

cnt = 0

while a[i] < 0 and i <= n-1:
    i += 1

b = []

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

if i % 2 == 0:
    print(str(sum(b)))

else:
    print(str(sum(b) - 2 * min(b)))

Submission status: Runtime Error

Solution code:
A=int(input())
B=[_ for _ in map(int,input().split())]
"マイナスの数を求める"
minus=0
for i in B:
  if i<=0:
    minus=+1

if minus%2==0:
  for i in B:
    if i<=0:
      ans=+(-1)*i
    else:
      ans+=i
    print(ans)

else:
  S=0
  for i in range(A):
    B[i]=abs(B[i])
  for i in B:
    S+=i
  print(S-2*min(B))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
a = np.array(a, dtype='int64')
a.sort()
print(a)
for i in range(n):
    if a[i] > 0:
        k = i
        print(i)
        break
a = np.absolute(a)
a.sort()

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

Submission status: Runtime Error

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

# A has 0
if abs_list[0] == 0:
	print(sum(abs_list))
else if len(neg) % 2 == 0:
	print(sum(abs_list))
else if abs(pos[0]) < abs(neg[-1]):
	print(sum(abs_list) - 2*pos[0] - 2*neg[-1])
else:
	print(sum(pos) - sum(neg[:-1]))

Submission status: Runtime Error

Solution code:
def parse(file):
    n = int(file.readline())
    nums = list(map(int, file.readline().split()))
    return n, nums


def main(n, nums):
    minimum_abs = abs(nums[0])
    negatives = 0
    ans = 0

    for num in nums:
        if num < 0:
            a = - num
            negatives += 1
        else:
            a = num

        if a < minimum_abs:
            minimum_abs = a
        ans += a

    if negatives % 2 == 1:
        ans -= minimum_abs * 2

    return ans


if __name__ == '__main__':
    print(main(*parse(sys.stdin)))

Submission status: Runtime Error

Solution code:
N = int(input()) 
a = list(int(_) for _ in input().split()) 

print(sum(np.abs(a[:N-1]))-np.abs(a[-1]))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
neg = 0
r = 
for i in a:
  r = r + abs(i)
  if i < 0 :
     neg = neg + 1
if neg % 2 != 0:
  s = 10000000000
  for i in a:
    s = min(s,abs(i))
  r = r - 2*s
  
print(r)

Submission status: Runtime Error

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

ans = sum(A)
for i in range(N):
  if A[i] < 0:
    if i != N-1:
      A[i] = A[i] * -1
      A[i+1] = A[i+1] * -1
      print(A)
  ans = max(ans, sum(A))

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
A = [int(_) for _ in input().split()]
total = sum(A)
neg = 0
neno = []
pono = []
for a in A:
    if a < 0:
        neg += 1
        neno.append(a)
    else:
        pono.append(a)
neno.sort()
pono.sort()
noneg = -sum(neno) + sum(pono)
if n == 2:
    print(max(-total, total))
else:
    if neg % 2 == 0:
        print(noneg)
    else:
        print(noneg - 2*min(-neno[-1],pono[0]))

Submission status: Runtime Error

Solution code:
import math
import sys


def parse(file):
    n = int(file.readline())
    nums = map(int, file.readline().split())
    return n, nums


def main(n, nums):
    minimum_abs = math.inf
    negatives = 0
    ans = 0

    for num in nums:
        if num < 0:
            a = - num
            negatives += 1
        else:
            a = num

        if a < minimum_abs:
            minimum_abs = a
        ans += a

    if negatives % 2 == 1:
        ans -= minimum_abs * 2

    return ans


if __name__ == '__main__':
    print(main(*parse(sys.stdin)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

a.sort()

i = 0

cnt = 0

while a[i] < 0 and i <= n-1:
    i += 1

b = []

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

if i % 2 == 0:
    print(sum(b))

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(c) for c in input().split()]

A_plus, A_minus = [], []
for a in A:
    if a>0: A_plus.append(a)
    else: A_minus.append(a)

if len(A_minus)%2==0:
    print(sum(A_plus) - sum(A_minus))
else:
    if min(A_plus) > -max(A_minus):
        print(sum(A_plus) - sum(A_minus) + max(A_minus)*2)
    else:
        print(sum(A_plus) - sum(A_minus) - min(A_plus)*2)

Submission status: Runtime Error

Solution code:
# D
n = int(input())
a = list(map(int, input().split()))

l_minus = [i for i in a if i <= 0]
l_plus = [i for i in a if i > 0]
ans = 0
if len(l_minus) % 2 == 0:
    l_minus_edit = [-i for i in l_minus]
else:
    l_minus_edit = [-i for i in l_minus]
    plus = l_plus.extend(l_minus_edit)
    l_minus_edit.append(-min(plus) * 2)
    
ans = sum(l_plus) + sum(l_minus_edit)
print(ans)

Submission status: Runtime Error

Solution code:
import math
A = int(input())
B = int(input())
T = int(input())
e = 1/2
f = T + e
if A != 0:
    c = math.floor(f / A)
else:
    c = 0
d = B * c
print(d)

Submission status: Runtime Error

Solution code:
import math

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

a.sort()

if n == 2:
    print(a[1])
elif n == 3:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])
    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

else:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])

    for i in range(3,n):
        if math.gcd(gcd1, a[i]) < gcd1:
            gcd1 = math.gcd(gcd1, a[i])

    for i in range(3,n):
        if math.gcd(gcd2, a[i]) < gcd2:
            gcd2 = math.gcd(gcd2, a[i])

    for i in range(3,n):
        if math.gcd(gcd3, a[i]) < gcd3:
            gcd3 = math.gcd(gcd3, a[i])

    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

Submission status: Runtime Error

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

m = []
p = []
z = 0

for i in range(n):
  if(an[i]<0):
    m.append(an[i])
  if(an[i]>0):
    p.append(an[i])
  if(an[i]==0):
    z=1

if ( z==1 ):
  ans = sum(p) - sum(m)
else:
  if ( len(m) == 0):
    ans = sum(p)
  else:
    if ( len(m)%2 == 0):
      ans = sum(p) - sum(m)
    else:
      minm = 0
      if ( min(p) < (-max(m)) ):
        minm = min(p)
      else:
        minm = -max(m)
      ans  = sum(p) - sum(m) - (minm*2)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split(" ")))
abs_list = list(map(abc, A))
sort(A)
sort(abs_list)

if (N % 2 == 0):
	print(sum(abs_list))
else:
	print(sum(abs_list[1:]))

Submission status: Runtime Error

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

m = []
p = []
z = 0

for i in range(n):
  if(an[i]<0):
    m.append(an[i])
  if(an[i]>0):
    p.append(an[i])
  if(an[i]==0):
    z=1

if ( z==1 ):
  ans = sum(p) - sum(m)
else:
  if ( len(m)%2 == 0):
    ans = sum(p) - sum(m)
  else:
    minm = 0
    if ( min(p) < (-max(m)) ):
      minm = min(p)
    else:
      minm = -max(m)
    ans  = sum(p) - sum(m) - (minm*2)

print(ans)

Submission status: Runtime Error

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

a.sort()

i = 0

cnt = 0

while a[i] < 0 and i <= n-1:
    i += 1

b = []

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

if i % 2 == 0:
    print(sum(b))

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

A_allplus = np.where(A>=0,A,-A)
#print(A_allplus)
plus = A[A>=0]
minus = A[A<0]
#print(minus)
d = 0
if len(minus)%2==1:
    a = max(minus)
    b = min(plus)
    
    d = min(abs(a),abs(b))*2

print(sum(A_allplus)-d)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
neg = 0
for i in a:
  r = r + abs(i)
  if i < 0 :
     neg = neg + 1
if neg % 2 != 0:
  s = 10000000000
  for i in a:
    s = min(s,abs(i))
  r = r - 2*s
  
print(r)

Submission status: Runtime Error

Solution code:
# D
n = int(input())
a = list(map(int, input().split()))

l_minus = [i for i in a if i < 0]
l_plus = [i for i in a if i >= 0]
ans = 0
if len(l_minus) % 2 == 0:
    l_minus_edit = [-i for i in l_minus]
else:
    l_minus_edit = [-i for i in l_minus]
    plus = min(l_plus)
    minus = min(l_minus_edit)
    l_minus_edit.append(-min(plus, minus) * 2)
    
ans = sum(l_plus) + sum(l_minus_edit)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)

Submission status: Runtime Error

Solution code:
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 n%2!=0:
    ans = ans - min(abs_list)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
MP = 0 #minus point
while A[MP] >= 0 and MP<N:
    MP += 1
if MP == N :
    print(sum(A))
    exit()

if (N-MP)%2 == 0:
    A = [abs(i) for i in A]
    print(sum(A))
else:
    B = [abs(i) for i in A[MP-1:]]
    B.sort()
    B[0] = -B[0]
    A = A[:MP-1] + B
    print(sum(A))
    print(A,B)

Submission status: Runtime Error

Solution code:
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)

# print(ma, pa)

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

print(result)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
def CountMinusAndZeroAndMin(lis):#マイナスの個数とabs挿話とabs最小の値を返す
    curmin=1000000000000000
    plussum=0
    minus=0
    for i in lis:
        j=abs(i)
        plussum+=j
        curmin=min(j,curmin)
        if i<0:
           minus+=1
        elif i==0:
            zeros+=1
    return(minus,plussum,curmin)
minus,plussum,minabs=CountMinusAndZeroAndMin(A)
if minabs==0 or minus%2==0:
    print(plussum)
else:
    print(plussum-2*minabs)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int, input().split()))
pos=[]
nega=[]
for i in range(n):
    if a[i]>=0:
        pos.append(a[i])
    else:
        nega.append(a[i])
if len(nega)%2==0:
    print(sum(pos)-sum(nega))
else:
    if min(pos)>-max(nega):
        print(sum(pos)-sum(nega)+max(nega)*2)
    else:
        print(sum(pos)-sum(nega)-min(pos)*2)

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int,input().split())
max = -1
for i in range(1,n):
  z = a[0:]
  for b in range(i+1):
    z[i] *= -1
    z[i+1] *= -1
  nz = sum(z)
  if max < nz:
    max = nz
print(max)