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:
import numpy as np
N = int(input())
a = np.array(list(map(int, input().split())))

tmp = sum(np.abs(a))
if np.count_nonzero(a < 0)%2 == 0 or 0 in a:
    print(tmp)
else:
    z = abs(a[0])
    z = min(z, abs(a[1]))
    z = min(z, abs(a[-1]))
    z = min(z, abs(a[-2]))
    print(tmp-z*2)

Submission status: Wrong Answer

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

tmp = sum(np.abs(a))
if np.count_nonzero(a < 0)%2 == 0 or 0 in a:
    print(tmp)
else:
    print(a//1000000000)
    z = abs(a[0])
    z = min(z, abs(a[1]))
    z = min(z, abs(a[-1]))
    z = min(z, abs(a[-2]))
    print(tmp-z*2)

Submission status: Wrong Answer

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:
        try:
            Ans = max(Tmp-A[:insert_index]*2, Tmp+A[insert_index-1]*2)
        except:
            Ans = Tmp + A[-1]
print(Ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
from collections import defaultdict
import math
import re

def main():
    #A, B, T = map(int, input().split())
    N = int(input())
    A_list = [int(a) for a in input().split()]

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

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = map(int, input().split())
A_list = list(map(int, input().split()))
A_sum = sum(A_list)
array1 = A_list[1:]
array2 = A_list[:-1]
array_add = max(list(map(lambda x,y: -(x+y), array1, array2)))*2
B_set =A_sum+ array_add
print(B_set)

Submission status: Wrong Answer

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:
	print(total)
else:
	print(total - 2 * minimum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

even = 0
for a in A:
    if a%2==0:
        even+=1
        
A = [abs(a) for a in A]        
A.sort()

if even%2==1:
    A[0] = -1*A[0]

print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
mina = 10*9
minus = 0
sumA = 0
for a in A:
    if a < 0:
        minus += 1
        a = -a
    sumA += a
    mina = min(a, mina)
if minus % 2 == 1:
    sumA -= 2*mina
print(sumA)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

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

if count % 2 == 0:
    print(ans)
else:
    print(ans - min(a) * 2)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Minus=0
Zero=0
L_absolute=[]

for i in LA:
    if i<0:
        L_absolute.append(i*(-1))
        Minus+=1
    elif i==0:
        Zero=1
    else:
        L_absolute.append(i)
        
L_absolute.sort()

if Zero==0:
    ans=sum(L_absolute)
elif Minus%2==1:
    ans=sum(L_absolute)-2*L_absolute[0]
else:
    ans=sum(L_absolute)
    
print(ans)

Submission status: Wrong Answer

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

Minus=0
Zero=0
L_absolute=[]

for i in LA:
    if i<0:
        L_absolute.append(i*(-1))
        Minus+=1
    elif i==0:
        Zero=1
    else:
        L_absolute.append(i)
        
L_absolute.sort()

if Zero==0:
    ans=sum(L_absolute)
if Minus%2==1:
    ans=sum(L_absolute)-2*L_absolute[0]
else:
    ans=sum(L_absolute)
    
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans = 0
min_chk = 10**10
minus_chk = 0
for i in input().split():
    i = int(i)
    if i < 0 :
        minus_chk += 1
    num = abs(i)
    min_chk = min(num,min_chk)
    ans += num
if min_chk != 0:
    if minus_chk%2 == 1:
        print(ans-2*num)
    else:
        print(ans)
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
ans = 0
min_chk = 10**10
minus_chk = 0
for i in input().split():
    i = int(i)
    if i < 0 :
        minus_chk += 1
    num = abs(i)
    min_chk = min(num,min_chk)
    ans += num
if minus_chk%2 == 1:
    print(ans-2*num)
else:
    print(ans)

Submission status: Wrong Answer

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==n:
	print(-sum(alist)+2*max(alist))

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

Submission status: Wrong Answer

Solution code:

def main():
    _ = input()
    A = list(map(int, input().split()))
    A_list = []
    count = 0
    for a in A:
        if a < 0:
            count += 1
            A_list.append(a * -1)
        else:
            A_list.append(a)
    if count % 2 == 0:
        print(sum(A_list))
    else:
        print(sum(A_list))
        print(min(A_list))
        print(sum(A_list)-min(A_list) * 2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
sum_A = []
for i in range(N-1):
  A[i] *= -1
  A[i+1] *= -1
  sum_A.append(sum(A))
print(max(sum_A))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
ans = 0
for i in range(n-1):
    if s[i]<0:
        s[i] = -s[i]
        s[i+1] = -s[i+1]
if s[n-1]>0:
    print(sum(s))
else:
    s[n-1] = -s[n-1]
    print(sum(s)-min(s))

Submission status: Wrong Answer

Solution code:
n = int(input())
s = [int(i) for i in input().split()]
ans = 0
for i in range(n-1):
    s[i] = -s[i]
    s[i+1] = -s[i+1]
    if ans<sum(s):
        ans = sum(s)
for i in range(n-1, -1):
    s[i-1] = -s[i-1]
    s[i] = s[i]
    if ans<sum(s):
        ans = sum(s)
            
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A = np.array(A)
idx_minabs = np.argmin(np.abs(A))
n_minus = np.sum(A < 0) - (A[idx_minabs] < 0)

ans = np.sum(np.abs(A)) - np.abs(A[idx_minabs]) + (2*(n_minus+1)%2-1)*A[idx_minabs]

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A = np.array(A)
idx_minabs = np.argmin(np.abs(A))
n_minus = np.sum(A < 0) - (A[idx_minabs] < 0)

ans = np.sum(np.abs(A)) - np.abs(A[idx_minabs]) + (2*n_minus%2-1)*A[idx_minabs]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
eo = False #False = even
suma = sum(A)
lta = 10**10
for j in range(n):
    i = A[j]
    if i <= 0: #0未満なら
        if j == n - 1 and eo: break
        eo ^= True
        lta = i
        suma += 2*(-i)
        #print(i,"を+にした")
    else: #0以上なら
        if lta == 10**10: break
        if eo: #奇数回変更歴なら
            if abs(i) > abs(lta):
                suma += lta*2
            else:
                suma += 2*(-i)
         #   print("oddかつ",abs(i),">",abs(lta),"だったので元に戻した")
        break
print(suma)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
eo = False #False = even
suma = sum(A)
lta = 10**10
for j in range(n):
    i = A[j]
    if j == n-1 and eo: break
    if i < 0: #0未満なら
        eo ^= True
        lta = i
        suma += 2*(-i)
        #print(i,"を+にした")
    else: #0以上なら
        if lta == 10**10: break
        if eo: #奇数回変更歴なら
            if abs(i) > abs(lta):
                suma += lta*2
            else:
                suma += 2*(-i)
         #   print("oddかつ",abs(i),">",abs(lta),"だったので元に戻した")
        break
print(suma)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
eo = False #False = even
suma = sum(A)
lta = 10**10
for i in A:
    if i <= 0: #0未満なら
        eo ^= True
        lta = i
        suma += 2*(-i)
        #print(i,"を+にした")
    else: #0以上なら
        lta = 0 if lta == 10**10 else lta
        if eo: #奇数回変更歴なら
            if abs(i) > abs(lta):
                suma += lta*2
            else:
                suma -= 2*i
         #   print("oddかつ",abs(i),">",abs(lta),"だったので元に戻した")
        break
print(suma)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
A.sort()
eo = False #False = even
suma = sum(A)
lta = 10**7
for i in A:
    if i <= 0:
        eo ^= True
        lta = i
        suma += 2*(-i)
        #print(i,"を+にした")
    else:
        if eo:
            if abs(i) > abs(lta):
                suma += lta*2
            else:
                suma -= 2*i
         #   print("oddかつ",abs(i),">",abs(lta),"だったので元に戻した")
        break
print(suma)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
mi = 0
for i in range(n):
  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: Wrong Answer

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)
A.remove(m)
n = min(A)

if m < 0 or -n > -m :
	A.remove(n)
	A.append(-n)
	A.append(-m)
else :
	A.append(m)
	
print(sum(A))

Submission status: Wrong Answer

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

for i,_ in enumerate(A_dash):
	if len(A) > i+1 :
		if A[i] < 0 and A[i+1] < 0 :
			A[i] = -A[i]
			A[i+1] = -A[i+1]

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

else :
	A.append(m)

print(sum(A))

Submission status: Wrong Answer

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

for i,_ in enumerate(A_dash):
	if len(A) > i+1 :
		if A[i] < 0 and A[i+1] < 0 :
			A[i] = -A[i]
			A[i+1] = -A[i+1]

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

print(sum(A))

Submission status: Wrong Answer

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

for i,_ in enumerate(A_dash):
	if len(A) > 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: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
sum=0
z=0
for i in range(n):
    if i+2==n:
        for i in a:
            sum+=i
        print(sum)
        break
    if a[i+1]*-1<a[i]*-1:
        a[i]*=-1
        a[i+1]*=-1

Submission status: Wrong Answer

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

a[0]*=-1
a[1]*=-1
for i in a:
    sum+=i
    
print(sum)

Submission status: Wrong Answer

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

abs_min=+a[0]
abs_sum=0
cnt=0
for val in a:
	if val<0:
		cnt+=1
	abs_sum+=abs(val)
	abs_min=min([abs_min,abs(val)])

if cnt%2==0:
	print(abs_sum)
else:
	print(abs_sum-2*abs_min)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split(' ')))
sum = 0
min = 1000000000
minus = 0
for n in range(N):
    n_abs = abs(A[n])
    sum += n_abs
    if min > n_abs:
        min = n_abs
    if A[n] < 0:
        minus += 1
if N%2 != 0 and minus%2 != 0:
    sum -= 2*min
print(sum)

Submission status: Wrong Answer

Solution code:
# 数列の個数
num_count = int(input())

# 数列を定義
nums_list = list(map(int, input().split()))

max_num = 0
zero_count = 0
minus_count = 0

for num in nums_list:
    max_num += abs(num)
    
    if num == 0:
        zero_count += 1
    if num < 0:
        minus_count += 1

if zero_count != 0 and minus_count % 2 != 0:
    max_num -= min(list(map(abs, nums_list))) * 2

print(max_num)

Submission status: Wrong Answer

Solution code:
# 数列の個数
num_count = int(input())

# 数列を定義
nums_list = list(map(int, input().split()))

# 変換結果を格納するリスト
convert_nums = [0] * num_count

max_num = 0

for num in nums_list:
    max_num += abs(num)

if num_count % 2 != 0:
    max_num -= min(list(map(abs, nums_list))) * 2

print(max_num)

Submission status: Wrong Answer

Solution code:
# 数列の個数
num_count = int(input())

# 数列を定義
nums_list = list(map(int, input().split()))

# 変換結果を格納するリスト
convert_nums = [0] * num_count

for i in range(num_count - 1):
    if i == num_count - 1:
        if abs(nums_list[i]) > abs(nums_list[i+1]):
            if nums_list[i] < 0:
                nums_list[i] *= -1
                nums_list[i + 1] *= -1
        else:
            if nums_list[i+1] < 0:
                nums_list[i] *= -1
                nums_list[i + 1] *= -1

        convert_nums[i] = nums_list[i]
    else:
        if nums_list[i] < 0:
            nums_list[i] *= -1
            nums_list[i+1] *= -1

        convert_nums[i] = nums_list[i]
        convert_nums[i+1] = nums_list[i+1]

print(sum(convert_nums))

Submission status: Wrong Answer

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

while True :
    if a[i] < 0 :
        a[i] *= -1
        a[i+1] *= -1
    i += 1
    if i > n-2 :
        break

print(sum(a))

Submission status: Wrong Answer

Solution code:
# 絶対値が最も小さい数に向けて、両端から始め、その数より遠い側の数がマイナスなら入れ替えると言う動作を行う
# すると絶対値が最小の数以外は全て正になる
# あとは、絶対値が最小の数が正か負かを判断するのみ
# 絶対値が最小の数の符号は、全体のうちマイナスが奇数個なら負で、偶数個なら正

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

minus = 0
a_min = a[0]
a_sum = 0

for x in a:
  if x < 0:
    minus += 1
    x = -x
  if x < a_min:
    a_min = x
  a_sum += x

if minus % 2 == 0:
  print(a_sum)
else:
  print(a_sum - 2 * a_min)

Submission status: Wrong Answer

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

b = [0 for i in range(n) ]
sum_b = 0
for i in range(n-1):
  a[i] = -1*a[i]
  a[i+1] = -1*a[i+1]
  
for i in range(n):
  sum_b += a[i]
  
print(sum_b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

    cum = 0
    for i in range(N - 1):
        a_i = As[i]
        a_ii = As[i + 1]
        if a_i + a_ii < 0:
            As[i] = -a_i
            As[i + 1] = -a_ii
        cum = cum + As[i]
    ans = sum(As)
    print("{}".format(ans))


sub()

Submission status: Wrong Answer

Solution code:
def sub():
    N, As = [input() for _ in range(2)]
    N = int(N)
    As = [int(e) for e in As.split(" ")]
     
    for i in range(N-1):
        a_i = As[i]
        a_ii = As[i+1]
        if a_i + a_ii < 0:
            As[i] = -a_i
            As[i+1] = -a_ii
    ans = sum(As)
    print("{}".format(ans))

sub()

Submission status: Wrong Answer

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

i = 0
j = 0
total = 0
while i < N-1:
    if A[i] >= 0:
        total += A[i]
    else:
        total += -A[i]
        A[i+1] *= -1
    i = i + 1
total += A[N-1]
print(total)

Submission status: Wrong Answer

Solution code:
from itertools import accumulate
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

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

Solution code:
#Conding: Utf-8

N= int(input())
a=list(map(int, input().split()))
count=0
for i in range(N-1):
    if a[i]<0 and a[i+1]<0:
        a[i]=a[i]*-1
        a[i+1]=a[i+1]*-1
    elif a[i]<0 and abs(a[i])>=abs(a[i+1]):
        a[i]=a[i]*-1
        a[i+1]=a[i+1]*-1
for j in range(N):
    count=a[j]+count

print(count)

Submission status: Wrong Answer

Solution code:
#Conding: Utf-8

N= int(input())
a=list(map(int, input().split()))
count=0
for i in range(N-1):
    if a[i]<0 and a[i+1]<0:
        a[i]=a[i]*-1
        a[i+1]=a[i+1]*-1
        print("a")
    elif a[i]<0 and abs(a[i])>=abs(a[i+1]):
        a[i]=a[i]*-1
        a[i+1]=a[i+1]*-1
        print("b")
print(a)
for j in range(N):
    count=a[j]+count

print(count)

Submission status: Wrong Answer

Solution code:
#Conding: Utf-8

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

a.sort()
for i in range(N-1):
    if a[i]<0:
        a[i]=a[i]*-1
    else:
        break

for j in range(N):
    count=a[j]+count

print(count)

Submission status: Wrong Answer

Solution code:
import sys
from functools import lru_cache
sys.setrecursionlimit(10**7)
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):
    print(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])
        elif 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: Wrong Answer

Solution code:
N = int(input())                                                                                                                                             
A = list(map(int,input().split()))                                                                                                                           
                                                                                                                                                             
zc = 0                                                                                                                                                       
mc = 0                                                                                                                                                       
abs_min = float('inf')                                                                                                                                       
                                                                                                                                                             
sum_abs = 0                                                                                                                                                  
for a in A:                                                                                                                                                  
    if a == 0:                                                                                                                                               
        zc += 1                                                                                                                                              
    elif a <  0:                                                                                                                                             
        mc += 1                                                                                                                                              
                                                                                                                                                             
    if abs(a) < abs_min:                                                                                                                                     
        abs_min = abs(a)                                                                                                                                     
                                                                                                                                                             
    sum_abs += abs(a)                                                                                                                                        
                                                                                                                                                             
                                                                                                                                                             
if zc > 0 or mc % 2 == 0:                                                                                                                                    
    print(sum_abs)                                                                                                                                           
else:                                                                                                                                                        
    print(sum_abs-abs_min)

Submission status: Wrong Answer

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

for i in range(1,len(a)):
    if (a[i-1] < 0):
        a[i-1] = a[i-1]*-1
        a[i] = a[i] * -1
    

if abs(a[len(a)-2]) < abs(a[len(a)-1]) and a[len(a)-1] < 0:
    
    a[len(a)-2] = a[len(a)-2]* -1
    a[len(a)-1] = a[len(a)-1]* -1

print(sum(a))

Submission status: Wrong Answer

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

for i in range(1,len(a)):
  if (a[i-1] < 0):
    a[i-1] = a[i-1]*-1
    a[i] = a[i] * -1

print(sum(a))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 10:45:22 2019

@author: avina
"""

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 10:45:22 2019

@author: avina
"""

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(dp[N][0])

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 10:16:31 2019

@author: avina
"""

N = int(input())
L = list(map(int, input().strip().split()))
sums = 0
if L[0] >0:
    sums += L[0]
else:
    sums-= L[0]
    L[1] = -L[1]

for i in range(1,N-1):
    if L[i] >=0:
        sums+=L[i]
    else:
        sums-= L[i]
        L[i+1] = -L[i+1]
sums+=L[N-1]
print(sums)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

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

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

print(sum(A))

Submission status: Wrong Answer

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

minus = 0
plus_min = 1000000000
total = 0

for j in range(N):
    if A[j] >= 0:
        plus_min = min(A[j],plus_min)
    else:
        minus += 1

    total += abs(A[j])

if minus % 2 == 0:
    print(total)
else:
    print(total-2*plus_min)

Submission status: Wrong Answer

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

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

total = sum(a)

if cnt % 2 ==  0:
    print(total)
    exit()
else:
    print(total - 2 * min(a))
    exit()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

minusList = [i for i in A if i < 0]
absList = list(map(abs,A))
ans = sum(absList)
if len(minusList) % 2 != 0:
	minimum = min(absList)
	ans = ans - minimum

print(ans)

Submission status: Wrong Answer

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

sum = 0
cnt = 0
d = 1000000000
for i in a:
    if (i < 0 and -i < d):
        d = -i
        cnt += 1;
    elif (i >= 0 and i < d):
        d = i
    sum = sum + i if i >= 0 else sum - i

if (cnt % 2 == 1):
    sum -= 2 * d

print(sum)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
a = int(input())
b = [int(i) for i in input().split()]
c = 0
d = []

for i in b:
    if i < 0:
        c += 1
    d.append(abs(i))

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
*a, = map(int, input().split())
b = np.abs(a)
#print(b)
print(np.sum(b)-2*np.min(b) if (i<0 for i in a) else np.sum(b))