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: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=0
Min=float('inf')
while True:
    if len(A)==0:
        break
    if A[-1]<0:
        break
    else:
        Min=A[-1]
        ans+=A[-1]
        A.pop()
if len(A)%2==1:
    if abs(A[-1])>Min:
        ans-=A[-1]+2*Min
    A.pop()
ans+=-1*sum(A)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:

# coding: utf-8

# In[14]:

import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))


# In[15]:

import numpy as np
A.sort(key=lambda x:abs(x))
#print(N, A)


# In[19]:

A = np.array(A)
#print(sum(A<0))
if sum(A<0)%2 == 0:
    #print('a')
    print(sum(abs(A)))
else:
    print(sum(abs(A[1:])) + A[0])


# In[ ]:

Submission status: Wrong Answer

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

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

if N > 2:
	for i in range(2, N):
		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-1]*2-A[i], dp[i-1][1]+A[i-1]*2+A[i])

print(max(dp[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
nums = list(map(int,input().split()))
cnt = 0
for num in nums:
  if num < 0:
    cnt += 1
    
abnums = [abs(i) for i in nums]
if cnt % 2 == 0:
  ans = sum(abnums)
else:
  ans = sum(nums) - min(abnums)*2
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

negCount = 0

#sum of A
sum = 0

#min of A
min = 0
if A[0] < 0:
    min = A[0] * -1
else:
    min = A[0]

for i in A:
    
    if i < 0:
        negCount += 1
        i *= -1

    sum += i

    if i < min:
        min = i

print(min)

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

Submission status: Wrong Answer

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

negCount = 0

#sum of A
sum = 0

#min of A
min = A[0]

for i in A:
    
    if i < 0:
        negCount += 1
        i *= -1

    sum += i

    if i < min:
        min = i


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

Submission status: Wrong Answer

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

negCount = 0

#sum of A
sum = 0

#min of A
min = A[0]

for i in A:
    
    if i < 0:
        negCount += 1
        i *= -1

    sum += i

    if i < min:
        min = i


if negCount % 2 == 0:
    print(sum)
    
else:
    print(sum - min)

Submission status: Wrong Answer

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

negCount = 0

#sum of A
sum = 0

#min of A
min = A[0]

for i in A:
    
    if i < 0:
        negCount += 1
        i *= -1

    sum += i
    
    print(negCount)
    if i < min:
        min = i


if negCount % 2 == 0:
    print(sum)
    
else:
    print(sum - min)

Submission status: Wrong Answer

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(int, input().split()))
findmax2(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split(" ")))
dp = [[0 for i in range(2)] for i in range(n)]

dp[1][0] = a[0] + a[1]
dp[1][1] = -(a[0] + a[1])

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

for i in range(2):
    for j in range(n):
        print(dp[j][i], end=" ")
    print()

print(max(dp[n-1][0], dp[n-1][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
abs_a = [abs(x) for x in a]
parity_a = len([x for x in a if x < 0]) % 2

if parity_a == 0:
  print(sum(abs_a))
else:
  print(sum(abs_a) - min(abs_a))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
a_neg=sum([1 if i>=0 else 0 for i in a])
if a_neg%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
if n%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
if n%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
from itertools import combinations
import copy
n=5
a=[10, -4, -8, -11, 3]
b=[i for i in range(n-1)]
c=[v for i in range(1,n) for v in combinations(b, i)]
sum_temp=sum(a)
for v in c:
    a_temp=copy.copy(a)
    for i in v:
        a_temp[i]*=-1
        a_temp[i+1]*=-1
    if sum_temp<sum(a_temp):
        sum_temp=sum(a_temp)
print(sum_temp)

Submission status: Wrong Answer

Solution code:

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

total = 0
minim = 1000000000
num_negs = 0

for a in An:
    is_neg = int(a < 0)
    num_negs += is_neg
    a *= (is_neg * -2 + 1)
    total += a
    minim = ((minim < a) and minim) or a
    pass

if num_negs % 2:
    print(total - 2*minim)
else:
    print(total)
    pass

Submission status: Wrong Answer

Solution code:
from itertools import *
from collections import *

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

An_pos, An_neg = deque(), deque()
for a in An:
    if a >= 0:
        An_pos.append(a)
    else:
        An_neg.append(a)
        pass
    pass

ans = sum(chain(An_pos, An_neg))

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

print(ans)

Submission status: Wrong Answer

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

An_neg = [ -a for a in An if a < 0]

ans = sum(An)

if len(An_neg) % 2 == 1:
    ans -= 2 * min(An)
    pass

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
def multi(a,i):
    A[i] *= -1
    A[i+1] *= -1

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

Submission status: Wrong Answer

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

for i in A:
    if i < 0:
        ans += -1 * i
    else:
        ans += i
print(ans)

Submission status: Wrong Answer

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(map(abs,s)))
else:
  print(sum(map(abs,s))-2*abs(min(s)))

Submission status: Wrong Answer

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(map(abs,s)))
else:
  print(sum(map(abs,s))-abs(min(s)))

Submission status: Wrong Answer

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(map(abs,s)))
else:
  print(sum(map(abs,s[:len(s)-1]))-abs(s[len(s)-1]))

Submission status: Wrong Answer

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(map(abs,s)))
else:
  print(sum(map(abs,s[:len(s)-1]))-abs(s[len(s)-1]))

Submission status: Wrong Answer

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

for num in range(n):
    box.append(abs(a[num]))

box.sort()

box[0] = -box[0]

print(sum(box))

Submission status: Wrong Answer

Solution code:

l = int(input())
tmp = list(map(int, input().split()))
lst = list(map(lambda x: x if x > 0 else x*-1, tmp))

ans = 0
if l % 2 == 0:
    ans = sum(lst)
else:
    ans = sum(lst)-(min(lst)*2)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
minabs = 10**9
i = 0
j = N-1
sum = 0
while i < j:
    while A[i] > 0 and i < j:
        A[i]
        if A[i] < minabs:
            minabs = A[i]
        sum += A[i]
        i += 1
        #print(sum)

    if i == j:
        break

    if -A[i]< minabs:
        minabs = -A[i]
    
    sum -= A[i]
    i += 1
    #print(sum)

    while A[j] > 0 and i < j:
        if A[j] < minabs:
            minabs = A[j]
        sum += A[j]
        j -= 1
        #print(sum)
    if i == j:
        break
    if -A[j] < minabs:
        minabs = -A[j]
    sum -= A[j]
    j -= 1
    #print(sum)
if i == j:
    if A[i] < 0:
        sum -= A[i]
        #print(sum)
        sum -= minabs*2
        #print(sum)
    else:
        sum += A[i]
        #print(sum)
print(sum)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = int(input())
A = list(map(int, input().split()))

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

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

print(max(dp[N - 2]))

Submission status: Wrong Answer

Solution code:
n = int(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: Wrong Answer

Solution code:
from sys import stdin

N = int(stdin.readline().rstrip())
data = stdin.readline().rstrip().split()

abs_sum = 0
negative_elements = []
zero_exist = False

for number in data:
    num = int(number)
    abs_sum += abs(num)
    if num == 0:
        zero_exist = True
    elif num < 0:
        negative_elements.append(int(num))

if len(negative_elements) % 2 == 0 or zero_exist:
    print(abs_sum)
else:
    print(abs_sum - 2 * min(negative_elements))

Submission status: Wrong Answer

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

dp = [[0] * 2 for i in range(N+1)]

dp[0][1] = - 10 ** 18

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

print(dp[N][0])

Submission status: Wrong Answer

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

dp = [[0] * 2 for i in range(N+1)]

dp[0][1] = - 10 ** 9

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

print(dp[N][0])

Submission status: Wrong Answer

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

minv = -1
count = 0
s = 0
for i in range(n):
    if a[i] < 0:
        s += -a[i]
        if minv > -a[i] or minv == -1:
            minv = -a[i]
        count += 1
    else:
        s += a[i]
        if minv > a[i] or minv == -1:
            minv = a[i]

print(s)
if count % 2 == 1:
    s += 2*(-minv)

print(s)

Submission status: Wrong Answer

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

minv = 0
count = 0
s = 0
for i in range(n):
    if a[i] < 0:
        s += -a[i]
        if minv > -a[i] or minv == 0:
            minv = -a[i]
        count += 1
    else:
        s += a[i]
        if minv > a[i] or minv == 0:
            minv = a[i]

if count % 2 == 1:
    s += 2*(-minv)

print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 = sort(abs(A))
    print(A)
    print(sum(A[1:]) - A[0])

Submission status: Wrong Answer

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:
    if A[i] < abs(A[i+1]):
      A[i] *= -1
      A[i+1] *= -1
      
print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
x = list(map(int, input().split()))
mc = 0
m = 1000000001

for v in range(n):
    t = x[v]
    if t < 0:
        mc += 1
    
    m = min(m, abs(t))

if mc % 2 == 0:
    s = 0
    for v in range(n):
        s += abs(x[v])
    print(s)
else:
    s = 0
    for v in range(n):
        t = abs(x[v])
        if t == m:
            s += x[v] * -1
        else:
            s += t
            
    print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt = 0
allsei = False
for i in range(n):
    if a[i] == 0:
        allsei = True
        break
    if a[i] < 0:
        cnt += 1
if cnt%2 == 0:
    allsei = True

ans = 0
mini =12345678901
for i in range(n):
    ans += abs(a[i])
    mini = min(mini,abs(a[i]))
if not allsei:
    ans -= mini
print(ans)

Submission status: Wrong Answer

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)==0:
    if len(minus)%2:
        print(-sum(minus))
    else:
        print(-sum(minus)+2*minus[0])
    exit()

if len(minus)==0:
    print(sum(a))
    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: Wrong Answer

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

minus = []
plus = []
zero = 0

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

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

if len(minus) % 2==0 or zero>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: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
answer = 0
tmp = a[0]
check = 0

for b in a:
    if b == 0:
        check += 1
        tmp = 0
    else:
        if b < 0:
            check += 1
        b = abs(b)
        if b < tmp:
            tmp = b
            answer += tmp
        else:
            answer += b
if check % 2 != 0:
    answer -= 2*tmp
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = 0
answer = 0
tmp = 0
while i < n-1:
    if a[i] <= 0 and a[i+1] <= 0:
        answer -= a[i]
        answer -= a[i+1]
        i += 1
    elif a[i] * a[i+1] < 0:
        if i == n-2:
            answer += max(abs(a[i]), abs(a[i+1]))
            tmp = min(abs(a[i]), abs(a[i+1]))
            answer -= tmp
            i += 1
        elif a[i] > a[i+1]:
            answer += a[i]
        else:
            answer -= a[i]
            a[i+1] *= -1
    elif a[i] > 0:
        answer += a[i]
    i += 1
if i == n-1:
    answer += a[i]

for test in a:
    if tmp > abs(test):
        answer += 2*tmp
        answer -= 2*abs(test)
        tmp = abs(test)
    
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = 0
answer = 0
tmp = 0
while i < n-1:
    if a[i] < 0 and a[i+1] <= 0:
        answer -= a[i]
        answer -= a[i+1]
        i += 1
    elif a[i] * a[i+1] < 0:
        if i == n-2:
            answer += max(abs(a[i]), abs(a[i+1]))
            tmp = min(abs(a[i]), abs(a[i+1]))
            answer -= tmp
            i += 1
        elif a[i] > a[i+1]:
            answer += a[i]
        else:
            answer -= a[i]
            a[i+1] *= -1
    elif a[i] > 0:
        answer += a[i]
    i += 1
if i == n-1:
    answer += a[i]

for test in a:
    if tmp > abs(test):
        answer += 2*tmp
        answer -= 2*abs(test)
        tmp = abs(test)
    
print(answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
i = 0
answer = 0
while i < n-1:
    if a[i] < 0 and a[i+1] <= 0:
        answer -= a[i]
        answer -= a[i+1]
        i += 1
    elif a[i] * a[i+1] < 0:
        if i == n-2:
            answer += max(abs(a[i]), abs(a[i+1]))
            answer -= min(abs(a[i]), abs(a[i+1]))
            i += 10
        elif a[i] > a[i+1]:
            answer += a[i]
        else:
            answer -= a[i]
            a[i+1] *= -1
    elif a[i] > 0:
        answer += a[i]
    i += 1
if i == n-1:
    answer += a[i]
print(answer)

Submission status: Wrong Answer

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


minuscount = 0
abss = []
for i in a:
	abss.append(abs(i))
	if (i < 0):
		minuscount += i

if minuscount % 2 == 0:
	print (sum(abss))
else :
	print (sum(abss) - 2 * min(abss))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc125
# -*- coding: utf-8 -*-

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

total = 0
minus = 0
minimum = abs(a[0])

for v in a:
        total += abs(v)
        if v < 0 :
                minus += 1
        if abs(v) < minimum:
                minimum = abs(v)

if minus%2 is 1:
        total -= minimum

print(total)

Submission status: Wrong Answer

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-1])+a[i-1])
    else:
        ans = abs(sum(a[:i-1]))+abs(a[i]+a[i-1])+sum(a[i+1:])
print(ans)

Submission status: Wrong Answer

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))
    else:
        ans = abs(sum(a[:i-1]))+abs(a[i]+a[i-1])+sum(a[i+1:])
print(ans)

Submission status: Wrong Answer

Solution code:
x = int(input())
y = list(map(int, input().split(" ")))

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

if abs(y[x - 2]) < abs(y[x - 1]) and y[x - 1] < 0:
  y[-2] *= -1
  y[-1] *= -1
  
print(sum(y))

Submission status: Wrong Answer

Solution code:
x = int(input())
y = list(map(int, input().split(" ")))

for i in range(x - 2):
  if y[i] < 0:
    y[i] *=-1
    y[i + 1] *=-1

if y[x - 2] < y[x - 1]:
  y[x - 2] *= -1
  y[x - 1] *= -1
  
print(sum(y))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = len([i for i in A if i < 0])

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

Submission status: Wrong Answer

Solution code:
x = int(input())
y = list(map(int, input().split(" ")))

for i in range(x - 1):
  if y[i] < 0:
    y[i] = y[i] * -1
    y[i + 1] = y[i + 1] * -1
    
print(sum(y))

Submission status: Wrong Answer

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

print(sum(A)-2*min(A))

Submission status: Wrong Answer

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

result = 0
for i in range(N-1):
  #print(A[i], i, A, result)
  if A[i] <= 0:
    if A[i+1] <= 0:
      A[i+1] *= -1
      result += A[i] * -1
      continue
    if abs(A[i]) >= abs(A[i+1]):
      A[i+1] *= -1
      result += A[i] * -1
      continue
  result += A[i]
result += A[-1]

print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

inf = float('inf')

N = int(input())
a = map(int, input().split())

dp = np.zeros((N + 1, 2))
dp[0][1] = -inf
# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値
# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値

for i, aa in enumerate(a, 0):
    dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
    dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)
print(dp[N][0])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[i for i in a if i<1]
ans=0;k=0
if len(b)%2==0:
    for i in a:ans+=abs(i)
else:
  c=sorted([abs(i) for i in a]);l=c[0]
  for i in a:
    if i==l and k==0:
      ans=ans+l if l<0 else ans-l
      k+=1
    else:
      ans+=abs(i)
print(ans)

Submission status: Wrong Answer

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

A_m = list()
A_p = list()
for a in A:
    if a >= 0: A_p.append(a)
    else: A_m.append(a)
M = 0
M += sum(A_p)
M -= sum(A_m)
if len(A_m)%2:
    M -= 2*max(A_m)
print(M)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
c=0
ans=0
for i in range(N):
  if num[i]<0:
    c+=1 
ans = list(map(lambda x: abs(x),num))
if c%2==0:
  print(sum(ans))
else:
  print(sum(ans) - min(num,key=lambda x: abs(x))*2)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
c=0
ans=0
for i in range(N):
  if num[i]<0:
    c+=1 
ans = list(map(lambda x: abs(x),num))
if c%2==0:
  print(ans)
else:
  print(sum(ans) - min(num,key=lambda x: abs(x))*2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

# -*- coding: utf-8 -*-
"""
Created on Sat Apr 13 09:53:12 2019

@author: Owner
"""

import numpy as np
import sys
""""
import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy
import bisect
"""

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default


"""
N, X = map(int, input().split())

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

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

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

def main():
    B = A.copy()
    for n in range(1,N-1):
        c0 = B[n-1]+B[n]+B[n+1]
        cl = -B[n-1]-B[n]+B[n+1]
        cr = B[n-1]-B[n]-B[n+1]
        clr = -B[n-1]+B[n]-B[n+1]
        if c0 >= max(cl, cr, clr):
            pass
        elif cl > max(c0, cr, clr): 
            B[n-1], B[n] = -B[n-1], -B[n]
        elif cr > max(c0, cl, clr):
            B[n], B[n+1] = -B[n], -B[n+1]
        elif clr > max(c0, cl, cr):
            B[n-1], B[n+1] = -B[n-1], -B[n+1]
        #print(n, B, c0, cl, cr, clr)
    print(sum(B))
                

    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
np.abs(A)
X=sum(A)
ans = X - 2*min(A)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
A[0]=A[0]*(-1)
A[1]=A[1]*(-1)

print(sum(A))

Submission status: Wrong Answer

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

A[0]=A[0]*(-1)
A[1]=A[1]*(-1)
sum=0

for a in A:
    if a>0:
        sum+=a

print(sum)

Submission status: Wrong Answer

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

A[0]=A[0]-1
A[1]=A[1]-1
max=A[0]

for a in A:
    if a>max:
        max=a
print(max)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))

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

a=np.array(a)
np.abs(a)
np.sort(a)
goukei=0

if mynas % 2 ==0:
    for j in range(n):
        goukei += a[j]
else:
    for k in range(n):
        goukei+=a[k]
    goukei-=a[0]*2

print(goukei)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))

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

a=np.array(a)
a2 = a
np.abs(a)
goukei=0

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

print(goukei)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = list(map(int, input().split()))

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

a=np.array(a)
a2 = a
np.abs(a)
goukei=0

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

print(goukei)

Submission status: Wrong Answer

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

cnt = 0
min_val = a[0]
for it in a:
    if abs(it) < min_val:
        min_val = abs(it)
    
    if it < 0:
        cnt+=1
        
abs_list = list(map(abs, a))
if cnt%2 == 0:
    print(sum(abs_list))
else:
    print(sum(abs_list) - 2*min_val)

Submission status: Wrong Answer

Solution code:
N = int(input())
aa = list(map(int, input().split()))
abs_sum = sum(map(abs, aa))
if 0 in aa:
    print(abs_sum)
    exit()
pos_f = [False] * N
pos_b = [False] * N
pos_f[0] = aa[0] < 0
pos_b[-2] = aa[-1] < 0
for i in range(1, N-1):
    pos_f[i] = aa[i] < 0 != pos_f[i-1]
    pos_b[-2-i] = aa[-1-i] < 0 != pos_b[-1-i]
if (aa[0] < 0 == pos_b[0]) or (aa[-1] < 0 == pos_f[-2]):
    print(abs_sum)
    exit()
for i in range(1, N-1):
    if (pos_f[i-1] ^ pos_b[i]) == aa[i] < 0:
        print(abs_sum)
        exit()
print(abs_sum - 2*min(map(abs, aa)))

Submission status: Wrong Answer

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

for i in range(n):
    if a[i] < 0:
        b += 1
        a[i] = abs(a[i])
        
if (0 in a) or ((b % 2) == 0):
    pass
else:
    ans -= min(a)

ans += sum(a)
print(ans)