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()))
b=[]
for _ in range(n):
  if a[_]<0:
    b.append(a.pop(_)*(-1))
if 0 in a or len(b)%2==0:
  print(sum(a)+sum(b))
else:
  b.sort()
  print(sum(a)+sum(b[1:])-b[0])

Submission status: Runtime Error

Solution code:
def dp(i, j):
    if i == 0:
        if j:
            return -float('inf')
        else:
            return 0
    if j:
        return max(dp(i-1, False) - a[i-1], dp(i-1, True) + a[i-1])
    else:
        return max(dp(i-1, False) + a[i-1], dp(i-1, True) - a[i-1])


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

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
insert_index = bisect.bisect_left(A,0)
if insert_index == 0:
    print(sum(A) - A[0]*2)
if insert_index == len(A):
    print(Ans = -1*sum(A) + A[-1]*2)
if len(A[:insert_index]) % 2 == 0:
    print(-1*sum(A[:insert_index])+sum(A[insert_index:]))
else:
    tmp = -1*sum(A[:insert_index])+sum(A[insert_index:])
    print(max(tmp-A[insert_index]*2, tmp+A[insert_index-1]*2))

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
insert_index = bisect.bisect_left(A,0)
if len(A[:insert_index]) % 2 == 0:
    Ans = -1*sum(A[:insert_index])+sum(A[insert_index:])
else:
    Tmp = -1*sum(A[:insert_index])+sum(A[insert_index:])
    if insert_index == 0:   #全て正のとき
        Ans = Tmp - A[0]*2
    else:
        if insert_index < len(A):
            Ans = max(Tmp-A[:insert_index]*2, Tmp+A[insert_index-1]*2)
        else:
            Ans = Tmp + A[-1]
print(Ans)

Submission status: Runtime Error

Solution code:
import bisect
N = int(input())
A = list(map(int, input().split()))
A.sort()
insert_index = bisect.bisect_left(A,0)
if len(A[:insert_index]) % 2 == 0:
    Ans = -1*sum(A[:insert_index])+sum(A[insert_index:])
else:
    Tmp = -1*sum(A[:insert_index])+sum(A[insert_index:])
    if insert_index == 0:   #全て正のとき
        Ans = Tmp - A[0]*2
    else:
        Ans = max(Tmp-A[insert_index]*2, Tmp+A[insert_index-1]*2)
print(Ans)

Submission status: Runtime Error

Solution code:
input_num = int(input())

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

max_value = []

for i in range(input_num -1):
    controlled_list = map(lamda x: x * (-1), value_list[i:i+2])
    max_value.append(sum(controlled_list))

print(max(max_value))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
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(Am)%2==0:
    Ams=-sum(Am)
    Aps=sum(Ap)
    ans=Ams+Aps
else:
    Ams=-sum(Am[1:])
    Aps=sum(Ap[1:])
    tmp=Ap[0]+Am[0]
    if tmp<0:
        tmp=-tmp
    ans=Ams+Aps+tmp
        
print(ans)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N=ri()
A=list(rl())
cnt = [0]*3
ans = 0
sei = []
for a in A:
    ans += abs(a)
    if a > 0:
        sei.append(a)
        cnt[0] += 1
    elif a == 0:
        cnt[1] += 1
    elif a < 0:
        cnt[2] += 1

if cnt[1] > 0 or cnt[2]%2 == 0:
    None
else:
    ans -= 2 * min(sei)

print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, input().split())
plus_count = 0
total = 0
minimum = 999999999999999999

for a in A:
	total += abs(a)
	if abs(a) < minimum:
		minimum = abs(a)
	if a >= 0:
		plus_count += 1
			
if plus_count % 2 == 0 or plus_count == N:
	print(total)
else:
	print(total + 2 * mininum)

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int, input().split()))
mina = 10*10
minus = False
sumA = 0
for a in A:
    if a < 0:
        if minus:
            minus = False
        else:
            minus = True
    	a = -a
    sumA += a
    mina = min(a, mina)


if minus:
    sumA -= 2*mina
print(sumA)

Submission status: Runtime Error

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
A.sort()

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

Submission status: Runtime Error

Solution code:
#https://atcoder.jp/contests/abc125/tasks/abc125_d

from functools import reduce

def positivesum(lists):
	for i in range(len(lists)):
		if lists[i]<0:
			lists[i]=lists[i]*(-1)
	return(sum(lists))
	

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

#負数の数をカウント
count=0
for i in range(n):
	if alist[i]<0:
		count+=1

if count%2==0:
	print(positivesum(alist))
else:
	alist.sort()
	x=max(alist[count-1],-alist[count])
	print(positivesum(alist)+x*2)

Submission status: Runtime Error

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
 
count=0
ans=0
for i in range(N):
    if a[i]<0:
        c+=1        
    a[i]=abs(a[i])

if c%2==0:
    ans=sum(a)
else:
    a.sort()
    ans=sum(a)-a[0]

Submission status: Runtime Error

Solution code:
N=int(input())
a=[int(i) for i in input().split()]
 
count=0
ans=0
for i in range(N):
    if a[i]<0:
        c+=1        
    a[i]=abs(a[i])

if c%2==0
    ans=sum(a)
else:
    a.sort()
    ans=sum(a)-a[0]

Submission status: Runtime Error

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

count=0
ans=0
for i in range(N):
    if a[i]<0:
        c+=1
        
a[i]=abs(a[i])
if c%2==0
    ans=sum(a)
else:
    a.sort()
    ans=sum(a)-a[0]

Submission status: Runtime Error

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

count=0
ans=0
for i in range(N):
    if a[i]<0:
        c+=1
        
a[i]=abs[i]
if c%2==0
    ans=sum(a)
else:
    a.sort()
    ans=sum(a)-a[0]

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import numpy as np


n = int(raw_input())
 
A_list = map(int,raw_input().split())

minus_id = [i for i, x in enumerate(A_list) if x < 0]

for i in minus_id:
	A_list[i] = abs(A_list[i])

min_id = min(A_list)

if(len(minus_id)%2 == 0):
	print sum(A_list)
else:
	print sum(A_list)-A_list[min_id]-A_list[min_id]

Submission status: Runtime Error

Solution code:
# -*- coding:utf-8 -*-
import numpy as np


n = int(raw_input())
 
A_list = map(int,raw_input().split())

minus_id = [i for i, x in enumerate(A_list) if x < 0]

for i in minus_id:
	A_list[i] = abs(A_list[i])

min_id = min(A_list)

if(minus_sum%2 == 0):
	print sum(A_list)
else:
	print sum(A_list)-A_list[min_id]-A_list[min_id]

Submission status: Runtime Error

Solution code:
N=int((input().split('\n'))[0])
A=input().split()
for i in range(0,len(A)):
  A[i]=int(A[i])
count=[]
plus=[]
for i in range(0,len(A)):
  if A[i]<0:
    count.append(A[i])
  else:
    plus.append(A[i])
if (len(count)%2==0) or (0 in plus):
  answer=sum(plus)-sum(count)
else:
  x=min(min(plus),-1*max(count))
  answer=sum(plus)-sum(count)-2*x
print(answer)

Submission status: Runtime Error

Solution code:
N=float((input().split('\n'))[0])
A=input().split()
for i in range(0,len(A)):
  A[i]=float(A[i])
count=[]
plus=[]
for i in range(0,len(A)):
  if A[i]<0:
    count.append(A[i])
  else:
    plus.append(A[i])
if len(count)%2==0 or 0 in plus:
  answer=sum(plus)-sum(count)
else:
  x=min(min(plus),-1*max(count))
  answer=sum(plus)-sum(count)-2*x
print(answer)

Submission status: Runtime Error

Solution code:
N=int((input().split('\n'))[0])
A=input().split()
for i in range(0,len(A)):
  A[i]=int(A[i])
count=[]
plus=[]
for i in range(0,len(A)):
  if A[i]<0:
    count.append(A[i])
  else:
    plus.append(A[i])
if len(count)%2==0 or 0 in plus:
  answer=sum(plus)-sum(count)
else:
  x=min(min(plus),-1*max(count))
  answer=sum(plus)-sum(count)-2*x
print(answer)

Submission status: Runtime Error

Solution code:
N=int((input().split('\n'))[0])
A=input().split()
for i in range(0,len(A)):
  A[i]=int(A[i])
count=[]
plus=[]
answer=0
for i in range(0,len(A)):
  if A[i]<0:
    count.append(A[i])
  else:
    plus.append(A[i])
if len(count)%2==0:
  answer=sum(plus)-sum(count)
else:
  x=min(min(plus),-1*max(count))
  answer=sum(plus)-sum(count)-2*x
print(answer)

Submission status: Runtime Error

Solution code:
N = int(input())
# N < 10 ** 5
A = sorted([int(x) for x in input().split()])
# - 10 ** 9 < A < 10 ** 9

B = [-a for a in A if a < 0]
D = [a for a in A if a >= 0]

if len(B) % 2 == 1:
    B[-1] = -B[-1]
    if -B[-1] > D[0]:
        B[-1] = -B[-1]
        D[0] = -D[0]

print(sum(B)+sum(D))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
A_dash = sorted(A)

for i in range(n):
	if n >= i+1 :
		if A[i] < 0 and A[i+1] < 0 :
			A[i] = -A[i]
			A[i+1] = -A[i+1]

m = min(A)
if m < 0 :
	A.remove(m)
	n = min(A)
	A.remove(n)
	A.append(-n)
	A.append(-m)

print(sum(A))

Submission status: Runtime Error

Solution code:
import math


def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]

    dp = {(-1, 0): 0, (-1, 1): -math.inf}
    for i in range(0, N):
        dp[(i, 0)] = max(dp[(i - 1, 0)] + As[i], dp[(i - 1, 1)] - As[i])
        dp[(i, 1)] = max(dp[(i - 1, 0)] - As[i], dp[(i - 1, 1)] + As[i])
    print("{}".format(dp[(N - 1, 0)]))


sub()

Submission status: Runtime Error

Solution code:
import math
def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
    
    dp = {(-1,0): 0, (-1,1): -math.inf}
    for i in range(0, N):
        dp[(i,0)] = max(dp[(i-1, 0)] + As[i], dp[(i-1,1)] - As[i])
        dp[(i,1)] = max(dp[(i-1, 0)] - As[i], dp[(i-1,1)] + As[i])
    print("{}".format(dp[(N-1,0)]))

sub()

Submission status: Runtime Error

Solution code:
N=input()
As=str(input())
ListA=As.split()
for i in range(0,len(ListA),1):
  a=ListA.pop(0)
  ListA.append(int(a))
  
cou=0
for i in range(0,ListA,1):
  if ListA[i]<0:
    cou+=1
    ListA[i]=abs(ListA[i])

ListA.sort()
if cou%2==0:
  S=sum(ListA)
  print(S)
elif cou%2==1:
  S=sum(ListA)-2*ListA[0]
  print(S)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))
pbox=[]
nbox=[]
if 0 in A:
  count=0
  for i in A:
    count += abs(i)
  print(count)
else:
  for i in a:
    if i > 0:
      pbox.append(i)
    else:
      nbox.append(i)
  if len(nbox)%2==0:
    count=0
    for i in a:
      count += abs(i)
    print(count)
  else:
    box=[]
    for i in a:
      box.append(abs(i))
    mi=min(box)
    count=0
    for i in a:
      count += abs(i)
    print(count-2*mi)

Submission status: Runtime Error

Solution code:
# Coding: Utf-8

N=in(input())
a=list(map(int, input().split()))
count=0
zero=0
total=0

for i in range(N):
  if a[i]<0:
    count+=count
    total=toal+abs(a[1])
  if a[1]<0:
    zero+=zero
    
if count%2==0 or zero>0:
  print(total)
else:
  print(total-np.abs(a))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
dp = [[0]*2 for i in range(n+1)]
dp[0][1] = -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(max(dp[n][0],dp[n][1]))

Submission status: Runtime Error

Solution code:
import sys
from functools import lru_cache

INF = 10 ** 18
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())

N = II()
A_li = LI()
N = len(A_li)

@lru_cache(maxsize=None)
def dp(i,j):
    if i == 0:
        if j == 0: return 0
        elif j == 1: return -INF
    else:
        if j == 0: return max(dp(i-1,0) + A_li[i-1], dp(i-1,1) - A_li[i-1])
        if j == 1: return max(dp(i-1,0) - A_li[i-1], dp(i-1,1) + A_li[i-1])

print(dp(N,0))

Submission status: Runtime Error

Solution code:
import sys

INF = 10 ** 18
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())

N = II()
A_li = LI()
N = len(A_li)

def dp(i,j):
    if i == 0:
        if j == 0: return 0
        elif j == 1: return -INF
    else:
        if j == 0: return max(dp(i-1,0) + A_li[i-1], dp(i-1,1) - A_li[i-1])
        if j == 1: return max(dp(i-1,0) - A_li[i-1], dp(i-1,1) + A_li[i-1])

print(dp(N,0))

Submission status: Runtime Error

Solution code:
import sys

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())

N = II()
A_li = LI()

def dp(i,j):
    if i == 0:
        if j == 0: return A_li[0]
        elif j == 1: return -A_li[0]
    else:
        if j == 0: return max(dp(i-1, 0) + A_li[i], dp(i-1, 1) - A_li[i])
        if j == 1: return max(dp(i-1, 0) - A_li[i], dp(i-1, 1) + A_li[i])

print(dp(N-1,0))

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int, input().strip().split()))
dp = [[0,0] for i in range(N+1)]
if L[0] >= 0:
    dp[0][1] = -L[0]
else:
    dp[0][1] = L[0]
for i in range(N):
    dp[i+1][0] = max(dp[i][0] + L[i], dp[i][1] - L[i])
    dp[i+1][1] = max(dp[i][1] + L[i], dp[i][0] - L[i])

print(min(dp[N][0]))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(v) for v in input().split(' ')]

# 負の数が偶数 -> 全部+にできる
# 負の数が奇数 -> どれか一つが-になる
# 負の数の偶奇チェック
sign = 1
for a in A:
    sign *= a/abs(a)

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

if sign > 0:
    print(sum(abs_A))
else:
    print(sum(abs_A)-min(abs_A)*2)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(v) for v in input().split(' ')]

# 負の数が偶数 -> 全部+にできる
# 負の数が奇数 -> どれか一つが-になる
# 負の数の偶奇チェック
sign = 1
for a in A:
    sign *= a/abs(a)

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

if sign > 0:
    print(sum(abs_A))
else:
    print(sum(abs_A)-min(abs_A))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = [int(v) for v in input().split(' ')]

# 負の数が偶数 -> 全部+にできる
# 負の数が奇数 -> どれか一つが-になる
# 負の数の偶奇チェック
sign = 1
for a in A:
    sign *= a/abs(a)
    
if sign > 0:
    print(sum(A))
else:
    print(sum(A)-min(A))

Submission status: Runtime Error

Solution code:

#_N = 5
#A = [10, -4, -8, -11, 3]
_N = int(input())
A = map(int, input().split(" "))

n = len([*filter(lambda a:a<=-1, A)])
a = [*map(abs, A)]
res = sum(a)
if n % 2 == 1:
    res -= min(a) * 2
print(res)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
M = list(map(int, input().split()))
X = [math.abs(x) for x in M]
print(sum(X) - min(X)*2)

Submission status: Runtime Error

Solution code:
n = input()
p = map(int, raw_input().split(" "))

i = 0
while i != n:
    if (p[i] < 0):
        p[i] = -p[i]
        p[i+1] = -p[i+1] 
        i += 1
    else:
        i += 2
    if(n <= i):break
print sum(p)

Submission status: Runtime Error

Solution code:
n = input()
p = raw_input().split(" ")

i = 0
while i != n:
    if not(p[i]):
        p[i] = -p[i]
        p[i+1] = -p[i+1] 
        i += 1
    else:
        i += 2
print max(p)

Submission status: Runtime Error

Solution code:
import numpy as np

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

"""
任意の2組みの数字の符号を変えることができる
したがって負の数が偶数個の場合全てを正にして総和をとれば良い
負の数が奇数個の場合絶対値の最小のもののみ負にして総和をとればよい
0が存在する場合はすべて正にできる
"""

A_abs = np.abs(A)

if 0 in A:
    print(np.sum(A_abs))

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

    if num % 2 == 0:
        print(np.sum(A_abs))
    else:
        print(np.sum(A_abs) - 2 * min(A_abs))

Submission status: Runtime Error

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

memo = dict()
def dp(pos, flag):
  if pos == n - 1:
    if flag == 0:
      return a[pos]
    else:
      return -a[pos]
  if (pos, flag) in memo:
    return memo[(pos, flag)]
  elif flag == 0:
    memo[(pos, flag)] = max(dp(pos + 1, 0) + a[pos], dp(pos + 1, 1) - a[pos])
    return memo[(pos, flag)]
  else:
    memo[(pos, flag)] = max(dp(pos + 1, 0) - a[pos], dp(pos + 1, 1) + a[pos])
    return memo[(pos, flag)]
print dp(0, 0)

Submission status: Runtime Error

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

memo = dict()
def dp(pos, flag):
  if pos == n - 1:
    if flag == 0:
      return a[pos]
    else:
      return -a[pos]
  if (pos, flag) in memo:
    return memo[(pos, flag)]
  elif flag == 0:
    memo[(pos, flag)] = max(dp(pos + 1, 0) + a[pos], dp(pos + 1, 1) - a[pos])
  else:
    memo[(pos, flag)] = max(dp(pos + 1, 0) - a[pos], dp(pos + 1, 1) + a[pos])
  return memo[(pos, flag)]

print dp(0, 0)

Submission status: Runtime Error

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
dp = [[0, float('inf')]] * N

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 - 1, 0]

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * (n + 1) for _ in [0, 1]]
dp[0][0] = 0
dp[1][0] = -1 * 10 ** 10
for i in range(n):
    for j in [0, 1]:
        dp[j][i + 1] = max(dp[0][i] + (-1)**j * a[i],
                           dp[1][i] + (-1)**(j + 1) * a[i])
print(dp[n][0])

Submission status: Runtime Error

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
min = (10**9,None)
for i in range(n-1):
    if a[i] < 0:
        a[i] *= (-1)
        a[i+1] *= (-1)
    if min[0] > abs(a[i]):
        min = (abs(a[i],i))
if a[-1] < 0:
    a[-1]**=(-1)
    a[min[1]]**=(-1)
print(sum(a))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
s = sum(l)
print(s  if t == 1 or N%2==0 else s - 2*min(l))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
s = sum(l)
print(s  if t == 1 or len(b)%2==0 else s - 2*min(l))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
pa.sort()
ma.sort()
s = sum(l)
for i in [pa,ma]:
  if len(i)==0:i.append(0)
print(s  if t == 1 or len(b)%2==0 else s - 2*min(l))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=input()
alist = list(map(int,input().split()))

ans = 0
for i in range(N):
  ans += abs(alist[i])
  
print(ans)

Submission status: Runtime Error

Solution code:
def getNumNeg(L):
  return sum([i<0 for i in L])
  
def findmax2(L):
  numNeg = getNumNeg(L)
  absL = list(map(abs, L))
  if numNeg % 2 == 0:
    print(sum(absL))
  else:
    print(sum(absL)-min(absL))
        
n = int(input())
a = list(map(abs, input().split()))
findmax2(a)

Submission status: Runtime Error

Solution code:
def getNumNeg(L):
    return sum([i<0 for i in L])
  
def findmax2(L):
    numNeg = getNumNeg(L)
    absL = list(map(abs, L))
    if numNeg % 2 == 0:
        print(sum(absL))
    else:
        print(sum(absL)-min(absL))
        
n = int(input())
a = list(map(abs, input().split()))
findmax2(a)

Submission status: Runtime Error

Solution code:
def getNumNeg(L):
    return sum([i<0 for i in L])

def findmax(L):
    numNeg = getNumNeg(L)
    if numNeg % 2 == 0: # end-point: all positive
         while getNumNeg(L) != 0:
            i = L.index(min(L[:-1]))
            j = i + 1
            L[i] = L[i] * (-1)
            L[j] = L[j] * (-1)
        print(sum(L))
    else: # end-point: smallest abs(number) is negative
        absL = list(map(abs, L))
        stop = min(absL)*(-1)
        while (getNumNeg(L) != 1) or (min(L) != stop):
            i = L.index(min(L[:-1]))
            j = i + 1
            L[i] = L[i] * (-1)
            L[j] = L[j] * (-1)
        print(sum(L))

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

Submission status: Runtime Error

Solution code:
def getNumNeg(L):
    return sum([i<0 for i in L])

def findmax(L):
    numNeg = getNumNeg(L)
    print(numNeg)
    if numNeg % 2 == 0: # end-point: all positive
         while getNumNeg(L) != 0:
            i = L.index(min(L[:-1]))
            j = i + 1
            L[i] = L[i] * (-1)
            L[j] = L[j] * (-1)
        print(sum(L))
    else: # end-point: smallest abs(number) is negative
        absL = list(map(abs, L))
        stop = min(absL)*(-1)
        while (getNumNeg(L) != 1) or (min(L) != stop):
            i = L.index(min(L[:-1]))
            j = i + 1
            L[i] = L[i] * (-1)
            L[j] = L[j] * (-1)
        print(sum(L))

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

Submission status: Runtime Error

Solution code:
def getAbs(L):
  return list(map(abs, L))

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

stop = min(getAbs(a))
while min(a) != stop*(-1):
  if a == getAbs(a):
    break
  i = a.index(min(a))
  j = i + 1
  a[i] = a[i] * (-1)
  a[j] = a[j] * (-1)
print(sum(a))

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split()
abs_a = list(map(abs, a)))
print(sum(abs_a) if len([i for i in a if i < 0]) % 2 == 0 else sum(abs_a) - 2 * min(a))

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())
print(sum(a) - 2 * min(a))

Submission status: Runtime Error

Solution code:

N = int(input())
An = list(map(int, input().split()[0:N]))

An_pos = [ a for a in An if a >= 0]
An_neg = [ a for a in An if a < 0]

ans = sum(An_pos) - sum(An_neg)

if len(An_neg) % 2 == 1:
    min_abs = min(min(An_pos), -max(An_neg))
    ans -= 2 * min_abs
    pass

print(ans)

Submission status: Runtime Error

Solution code:
import sys
from bisect import insort_left
from collections import *

N = int(input())
An = list(map(int, input().split()))[0:N]

An_pos = [ a for a in An if a >= 0]
An_neg = [ a for a in An if a < 0]

if len(An_neg) % 2 == 0:
    print(sum(An_pos) - sum(An_neg))
    sys.exit(0)
    pass

min_neg = min(min(An_pos), -max(An_neg))
print(sum(An_pos) - sum(An_neg) - 2*min_neg)

Submission status: Runtime Error

Solution code:
import sys
from bisect import insort_left
from collections import *

N = int(input())
An = list(map(int, input().split()))[0:N]

An_sorted_pos = deque(sorted([ a for a in An if a > 0]))
An_sorted_neg = deque(sorted([ a for a in An if a < 0]))

if len(An_sorted_neg) % 2 == 0:
    print(sum(An_sorted_pos) - sum(An_sorted_neg))
    sys.exit(0)
    pass

min_neg = min(min(An_sorted_pos), -max(An_sorted_neg))

print(sum(An_sorted_pos) - sum(An_sorted_neg) - 2*min_neg)

Submission status: Runtime Error

Solution code:
import sys
from bisect import insort_left
from collections import *

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

An_sorted_pos = deque(sorted([ a for a in An if a > 0]))
An_sorted_neg = deque(sorted([ a for a in An if a < 0]))
zero_exists = not all([ a != 0 for a in An ])

if zero_exists:
    print(sum(An_sorted_pos) - sum(An_sorted_neg))
    sys.exit(0)
    pass

if len(An_sorted_neg) == 0:
    print(sum(An_sorted_pos))
    sys.exit(0)
    pass

if len(An_sorted_pos) == 0:
    if len(An_sorted_neg) % 2 == 0:
        print(-sum(An_sorted_neg))
    else:
        print(-sum(An_sorted_neg)+max(An_sorted_neg))
        pass
    sys.exit(0)
    pass

while An_sorted_pos[0] < -An_sorted_neg[0]:
    pos = An_sorted_pos.popleft()
    neg = An_sorted_neg.popleft()
    idx_pos = insort_left(An_sorted_pos, -neg)
    idx_neg = insort_left(An_sorted_neg, -pos)
    pass

print(sum(An_sorted_pos) + sum(An_sorted_neg))

Submission status: Runtime Error

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

#どうするか
#-1 -1  1
# 1 -1 -1
#-1  1 -1

#偶数個の数値を自由に反転できるとして見ていい

positive=[]
negative=[]
for a in A:
	if(a>=0):
		positive.append(a)
	else:
		negative.append(a)
if(len(negative)%2==0):#偶数個なら全部ひっくり返せばいい
	print(sum(positive)-sum(negative))
else:#奇数個なら, もっとも大きなもの以外をひっくり返す
	#あるいは, 最後にpositive最小とnegative最大をひっくり返すこともありうる	
	max_nega=max(negative)
	min_posi=min(positive)
	if(-1*max_nega>min_posi):
		print(sum(positive)-sum(negative)-2*min_posi)
	else:
		
		print(sum(positive)-sum(negative)+2*max_nega)

Submission status: Runtime Error

Solution code:
N = int(input())

A = list(map(int), input().split())
if N % 2 == 0:
    print(sum(map(abs, A)))
else:
    neg = [a for a in A if a < 0]
    c = max(neg) if len(neg) > 0 else 0
    print(sum(map(abs, A)) - 2 * c)

Submission status: Runtime Error

Solution code:
N = int(input())

A = list(map(int), input().split())
if N % 2 == 0:
    print(sum(map(abs, A)))
else:
    print(sum(map(abs, A)) - 2 * max([a for a in A if a <= 0]))

Submission status: Runtime Error

Solution code:
n=int(input())
s=list(map(int,input().split()))
o = 0
for i in s:
  if i < 0:
    o+=1
if o%2==0:
  print(sum(abs(s)))
else:
  print(sum(abs(s［:len(s)］))-s［len(s)-1］)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
p=[e for e in a if e>=0]
n=[f for f in a if f<0]
k=min(abs(max(n)),min(p))
if len(n)%2==0:
  print(sum(p)-sum(n))
else:
  print(sum(p)-sum(n)-2*k)

Submission status: Runtime Error

Solution code:
from numpy import *

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

if len(A[A<0])%2 == 0:
    print(sum(abs(A)))
else:
    A = abs(A).sort()
    print(sum(A[1:]) - A[0])

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(map(int, input().split()))
if len(A[A<0])%2 == 0:
    ans = sum(abs(A))
else:
    A = sorted(abs(A))
    ans = sum(A[1:])-A[0]
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = np.array(map(int, input().split()))
if len(A[A<0])%2 == 0:
    ans = sum(abs(A))
else:
    A = sorted(abs(A))
    ans = sum(A[1:] - A[0])
print(ans)

Submission status: Runtime Error

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

for i in range(N-1):
  if A[i] <= 0 and A[i+1] <= 0:
    A[i] *= -1
    A[i+1] *= -1
  if A[i] <= 0:
    if abs(A[i]) > abs(A[i+1]):
      A[i] *= -1
      A[i+1] *= -1
  if A[i+1] <= 0 and A[i+2]:
    if A[i+2] > 0:
      A[i] *= -1
      A[i+1] *= -1
      
print(sum(A))

Submission status: Runtime Error

Solution code:
N=int(input())
A= [int(a) for a in input().split()]
minusnum=sum(a<0 for a in A)
pluslist=[a for a in A if a>=0]
minuslist=[-a for a in A if a<0]
ans=sum(pluslist + minuslist)
if minusnum%2:
    plusmin=min(pluslist)
    minusmin=min(minuslist)
    if minusmin>plusmin:
        ans=ans-2*plusmin
    else:
        ans=ans-2*minusmin
print(ans)

Submission status: Runtime Error

Solution code:

N=int(input())
A= [int(a) for a in input().split()]
minusnum=sum(a<0 for a in A)
ans=sum(abs(a) for a in A)
if minusnum%2:
    plusmin=min(a for a in A if a>=0)
    minusmin=min(-a for a in A if a<0)
    if minusmin>plusmin:
        ans=ans-2*plusmin
    else:
        ans=ans-2*minusmin
print(ans)

Submission status: Runtime Error

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

minus = []
plus = []

for i in a:
    if i < 0:
        minus.append(i)
    else:
        plus.append(i)
plus.sort()
minus.sort(reverse=True)

if len(plus)*len(minus) == 0:
    plus[133],minus[133]
    print(sum(plus)-sum(minus))
    exit()

if len(minus) % 2==0:
    print(sum(plus) - sum(minus))
    exit()

if - minus[0] < plus[0]:
    print(sum(plus) - sum(minus) +2*minus[0])
else:
    print(sum(plus) - sum(minus) -2*plus[0])

Submission status: Runtime Error

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

minus = []
plus = []

for i in a:
    elif i < 0:
        minus.append(i)
    else:
        plus.append(i)
plus.sort()
minus.sort(reverse=True)

if len(plus)*len(minus) == 0:
    plus[133],minus[133]
    print(sum(plus)-sum(minus))
    exit()

if len(minus) % 2==0:
    print(sum(plus) - sum(minus))
    exit()

if - minus[0] < plus[0]:
    print(sum(plus) - sum(minus) +2*minus[0])
else:
    print(sum(plus) - sum(minus) -2*plus[0])

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
a = sorted(list(map(int, input().split())))
i = bisect.bisect_left(a,0)
if i % 2 == 0:
    ans = abs(sum(a[:i]))+sum(a[i:])
else:
    if i == n:
        ans = abs(sum(a[:i])+a[i])
    else:
        ans = abs(sum(a[:i-1]))+abs(a[i]+a[i-1])+sum(a[i+1:])
print(ans)

Submission status: Runtime Error

Solution code:
import bisect

n = int(input())
a = list(map(int, input().split()))
a.sort()
i = bisect.bisect_left(a,0)
if i % 2 == 0:
    ans = abs(sum(a[:i]))+sum(a[i:])
else:
    ans = abs(sum(a[:i-1]))+abs(a[i]+a[i-1])+sum(a[i+1:])
print(ans)