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:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque

INF = 1 << 50



def run():
    N, *A = map(int, read().split())
    flip = 0
    tmp = 0
    l = 0
    SUM = sum([abs(a) for a in A])
    if A.count(0):
        print(SUM)
        return

    do = [0]
    for a in A:
        if not do[-1]:
            if a > 0:
                do.append(0)
                continue
            else:
                do.append(1)
        else:
            if a > 0:
                do.append(1)
            else:
                do.append(0)

    if A[-1] > 0:
        if do:
            ans = SUM - A[-1] * 2
        else:
            print(SUM)
            return
    else:
        if do:
            print(SUM)
            return
        else:
            ans = SUM - A[-1] * 2

    for i in range(N-1):
        ans = max(ans, ans - abs(A[i]) - abs(A[i+1]) + abs(A[-1]))
    print(ans)





if __name__ == "__main__":
    run()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
zr = 0
for i in range(n-1):
  # a[i] <0かつa[i+1]>0 でabs(a[i])>=abs(a[i+1])
  if (a[i] <= 0 and a[i+1]>=0 and abs(a[i]) >= abs(a[i+1])) or (a[i]<=0 and a[i+1]<=0):
    a[i] *=-1
    a[i+1] *=-1
  #print(*a)
print(sum(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
zr = 0
for i in range(n-1):
  if (a[i] <= 0 and a[i+1]>=0 and abs(a[i]) >= abs(a[i+1])) or (a[i]<0 and a[i+1]<0):
    a[i] *=-1
    a[i+1] *=-1
print(sum(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
zr = 0
for i in range(n-1):
  if a[i+1]==0:
    zr = 1
    a[i] = abs(a[i])
    continue
  if zr:
    if i < n-2:
      a[i+1]=abs(a[i+1]) if a[i+2]>0 else -abs(a[i+1])
    else:
      a[i+1]=abs(a[i+1])
  # a[i] <0 で[a[i]] > [a[i+1]] or その逆なら交換
  if (a[i] < 0 and abs(a[i]) > abs(a[i+1])) or (a[i] > 0 and abs(a[i]) < abs(a[i+1])):
    a[i] *=-1
    a[i+1] *=-1
print(sum(a))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

dp[1][False] = N_List[0] + N_List[1]
dp[1][True] = (N_List[0] + N_List[1])*-1

for i in range(2,N):
    dp[i][False] = max(dp[i-1][True] + N_List[i],dp[i-1][False] + N_List[i])
    dp[i][True] = max(dp[i-1][True] + N_List[i-1]*2 + N_List[i]*-1 ,dp[i-1][False] + N_List[i]*-2 + N_List[i]*-1)

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys

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


ans = 0
for a in A:
    ans += abs(a)

c = 0
m = A[0]
for a in A:
    if a < 0:
        c += 1
    elif a == 0:
        print(ans)
        sys.exit()

    if abs(a) < m:
        m = abs(a)

if c % 2 == 0:
    print(ans)
else:
    # print(ans - 2 * m)
    print('h')

Submission status: Wrong Answer

Solution code:
import sys

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


ans = 0
for a in A:
    ans += abs(a)

c = 0
m = A[0]
for a in A:
    if a < 0:
        c += 1
    elif a == 0:
        print(ans)
        sys.exit()

    if abs(a) < m:
        m = abs(a)

if c % 2 == 0:
    print(ans)
else:
    print(ans - 2 * m)

Submission status: Wrong Answer

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

A_tmp = sorted(A, key=abs, reverse=True,)
total = 0
for i,v in enumerate(A_tmp):
    if (v <= 0) and (i < len(A_tmp)-1):
        A_tmp[i+1] = (-1) * A_tmp[i+1]
    total += abs(v)
print(total)

Submission status: Wrong Answer

Solution code:
n = int(input())
la = [int(w) for w in input().split()]

ans = sum([abs(w)for w in la])
if len([w for w in la if w < 0]) % 2 == 0:
    print(ans)
    exit()

minus = [0]*n
minus[0] = 1 if la[0] < 0 else 0


def multi_index(li, val):
    return [i for i, _x in enumerate(li) if _x == val]


for i in range(1, n):
    minus[i] = minus[i-1]+1 if la[i] < 0 else minus[i-1]

sla = sorted([abs(w)for w in la])

for s in sla:
    indexs = multi_index(la, s)+multi_index(la, -s)
    for i in indexs:
        if minus[i] % 2 == 1:
            ans -= s*2
            print(ans)
            exit()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[*map(int,input().split())]
c=0
for e,i in enumerate(l):
  if i<0:
    c+=1
    l[e]=-i
print(sum(l)-[0,min(l)*2][i%2 and l.count(0)<1])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[*map(int,input().split())]
c=0
for e,i in enumerate(l):
  if i<0:
    c+=1
    l[e]=-i
print(sum(l)-[0,min(l)*2][i%2*l.count(0)])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[*map(int,input().split())]
c=0
for e,i in enumerate(l):
  if i<0:
    c+=1
    l[e]=-i
print(sum(l)-[0,min(l)*2][i%2 and l.count(0)>0])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[*map(int,input().split())]
c=0
for e,i in enumerate(l):
  if i<0:
    c+=1
    l[e]=-i
print(sum(l)-[0,min(l)*2][i%2 or l.count(0)>0])

Submission status: Wrong Answer

Solution code:
n=int(input())
l=[*map(int,input().split())]
c=0
for e,i in enumerate(l):
  if i<0:
    c+=1
    l[e]=-i
print(sum(l)-[0,min(l)*2][i%2])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

if (sum([i < 0 for i in a]) + sum([i == 0 for i in a]))% 2 == 0:
    print(sum(b))
else:
    b = [abs(i) for i in a]
    a0 = a.pop(0)
    af = a.pop()
    print(sum(b) - min(abs(a0), abs(af)) * 2)

Submission status: Wrong Answer

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

count = 0
min = abs(A[0])
sum = 0
for i in A:
    # 0と負の数をカウント
    if i<=0:
        count += 1
    # 最小更新
    if min > abs(i):
        min = abs(i)
    # 合計
    sum += abs(i)
#print('count:'+str(count))
#print('min:'+str(min))
#print('sum:'+str(sum))
if count%2 == 0:
    print(sum)
else:
    print(sum-min)

Submission status: Wrong Answer

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    ans = sum(map(lambda x: abs(x), a))
    m = min(a, key=lambda x: abs(x))
    cnt = sum([1 for x in a if x < 0])
    if cnt%2 == 0 or 0 in a:
        print(ans)
    else:
        print(ans-2*m)
        
    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    ans = sum(map(abs, a))
    m = min(a, key= lambda x: abs(x))
    if 0 in a:
        print(ans)
        return
    cnt = sum([1 for x in a if x < 0])
    if cnt%2 == 0:
        print(ans)    
    else:
        print(ans-2*m)
        
    
    
if __name__ == '__main__':
    main()

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

Submission status: Wrong Answer

Solution code:
def resolve():
    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
    if abs(A[-2]) < abs(A[-1]):
        A[-2] *= -1
        A[-1] *= -1
    print(sum(A))

resolve()

Submission status: Wrong Answer

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

# 絶対値の和
plus_sum = 0
# 負の数の個数
minus_num = 0
# 絶対値が最も小さい数
min_abs = 10**10

for a in A:
    plus_sum += abs(a)
    if a < 0:
        minus_num += 1
    if abs(a) < abs(min_abs):
        min_abs = a

# 0が入っていたら全部正にできる
if 0 in A:
    print(plus_sum)

# 0が含まれない場合、負の個数の偶奇で場合分け

elif minus_num % 2 == 0:
    print(plus_sum)

# min_absだけマイナス、他はプラス
elif minus_num % 2 == 1:
    ans = plus_sum - 2 * min_abs
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int, input().split()))
mcnt = 0
for i in range(n):
  if lst[i] < 0:
    mcnt += 1
if 0 in lst or mcnt % 2 == 0:
  print(sum(list(map(abs, lst))))
  exit()
m = min(lst, key=abs)
print(sum(list(map(abs, lst))) - 2 * m)

Submission status: Wrong Answer

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

pos = []
neg = []
ans = 0

for e in A:
    if e > 0:
        pos.append(e)
    else:
        neg.append(e)
if len(neg) % 2 == 0:
    ans = sum(pos) - sum(neg)
else:
    pos.sort(reverse=True)
    neg.sort(reverse=True)
    if len(neg) == N:
        ans = -sum(neg[:-1]) + neg[-1]
    else:
        #ans = max(-sum(neg[:-1]) + neg[-1], -sum(neg[:-3]) + sum(neg[-3:]))
        #ans = max(sum(pos[:-1])-pos[-1]-sum(neg), sum(pos) + neg[0] -sum(neg[1:]))
        ans = sum(pos) - sum(neg)
        ans -= 2 * min(min(pos), -max(neg))
print(ans)

Submission status: Wrong Answer

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

pos = []
neg = []
ans = 0

for e in A:
    if e > 0:
        pos.append(e)
    else:
        neg.append(e)
if len(neg) % 2 == 0:
    ans = sum(pos) - sum(neg)
else:
    pos.sort(reverse=True)
    neg.sort(reverse=True)
    if len(neg) == N:
        ans = -sum(neg[:-1]) + neg[-1]
    else:
        #ans = max(-sum(neg[:-1]) + neg[-1], -sum(neg[:-3]) + sum(neg[-3:]))
        #ans = max(sum(pos[:-1])-pos[-1]-sum(neg), sum(pos) + neg[0] -sum(neg[1:]))
        ans = sum(pos) - sum(neg)
        tmp_p = min(pos)
        tmp_n = -max(set(neg) - set({0}))
        if tmp_p > tmp_n:
            ans -= 2 * tmp_n
        else:
            ans -= 2 * tmp_p
        
print(ans)

Submission status: Wrong Answer

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

pos = []
neg = []
ans = 0

for e in A:
    if e > 0:
        pos.append(e)
    else:
        neg.append(e)
if len(neg) % 2 == 0:
    ans = sum(pos) - sum(neg)
else:
    pos.sort(reverse=True)
    neg.sort(reverse=True)
    if len(neg) == N:
        ans = -sum(neg[:-1]) + neg[-1]
    else:
        #ans = max(-sum(neg[:-1]) + neg[-1], -sum(neg[:-3]) + sum(neg[-3:]))
        ans = max(sum(pos[:-1])-pos[-1]-sum(neg), sum(pos) + neg[0] -sum(neg[1:]))
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

sum = 0
for i in a:
    if i < 0:
        sum += -i
    else:
        sum += i

if cnt % 2 != 0:
    if 0 < a[-2] and 0 < a[-1]:
        if a[-2] < a[-1]:
            sum -= (a[-2] * 2)
        else:
            sum -= (a[-1] * 2)
    elif a[-2] < 0 and 0 < a[-1]:
        if -a[-2] < a[-1]:
            sum += (a[-2] * 2)
        else:
            sum -= (a[-1] * 2)
    elif 0 < a[-2] and a[-1] < 0:
        if a[-2] < -a[-1]:
            sum -= (a[-2] * 2)
        else:
            sum += (a[-1] * 2)
    else:
        if -a[-2] < -a[-1]:
            sum += (a[-2] * 2)
        else:
            sum += (a[-1] * 2)

print(sum)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

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

sum = 0
for i in a:
    if i < 0:
        sum += -i
    else:
        sum += i

if cnt % 2 != 0:
    if 0 < a[-2] and 0 < a[-1]:
        if a[-2] < a[-1]:
            sum -= (a[-2] * 2)
        else:
            sum -= (a[-1] * 2)
    elif a[-2] < 0 and 0 < a[-1]:
        if -a[-2] < a[-1]:
            sum += (a[-2] * 2)
        else:
            sum -= (a[-1] * 2)

print(sum)

Submission status: Wrong Answer

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

for i in range(n-1):
  f= 1 if a[i]*f>=0 else -1
print (sm if f*a[n-1]>0  or 0 in a else sm-2*min(abs(a[n-1]),abs(a[n-2])) )

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sm=sum(map(abs,a))
f=1
for i in range(n-1):
  f= 1 if a[i]*f>=0 else -1
print (sm if f*a[n-1]>0 else sm-2*min(abs(a[n-1]),abs(a[n-2])) )

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

cnt = 0
for i, x in enumerate(A):
	if x < 0:
		cnt += 1
		A[i] *= -1

if cnt%2:
	print(sum(A) - min(A))
else:
	print(sum(A))

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
ans = 0
for i in range(n-2):
    if a[i] < 0:
        ans += -1 * a[i]
        a[i+1] = -1 * a[i+1]
    else:
        ans += a[i]
if a[-2] * a[-1] < 0:  # 最後２つが異符号のとき
    ans += max(abs(a[-2]), abs(a[-1])) - min(abs(a[-2]), abs(a[-1]))
else:
    ans += abs(a[-2]) + abs(a[-1])
print(ans)

Submission status: Wrong Answer

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

def main(n,a):
    sump=0
    summ=0
    minm=-10**9
    minp=10**9
    countm=0
    for i in range(n):
        if a[i]>=0:
            sump+=a[i]
            minp=min(minp,a[i])
        else:
            countm+=1
            summ+=a[i]
            minm=max(minm,a[i])
    #print(sump,summ,countm,minm,minp)
    if countm%2==0:
        return sump-summ
    else:
        return sump-summ-minp*2

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

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:
        if a[i + 1] <= 0 or -a[i] - a[i + 1] >= 0:
            a[i] *= -1
            a[i + 1] *= -1
            

print(sum(a))

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] + a[i + 1] < -a[i] - a[i + 1]:
        a[i] *= -1
        a[i + 1] *= -1

print(sum(a))

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:
        a[i] *= -1
        a[i + 1] *= -1

print(sum(a))

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] + a[i + 1] <= -a[i] - a[i + 1]:
        a[i] *= -1
        a[i + 1] *= -1

print(sum(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())

array = [int(i) for i in input().split()]
calc_array = []

cnt = 0

for n in array:
    if n < 0:
        cnt += 1
    calc_array.append(abs(n))
        
if cnt % 2 == 1:
    output = sum(calc_array) - min(calc_array)
else :
    output = sum(calc_array)
    
print(output)

Submission status: Wrong Answer

Solution code:
import copy

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

A_copy = copy.deepcopy(A)
for i in range(N-1):
    if A[i] < 0:
        A[i], A[i+1] = -A[i], -A[i+1]
ans = sum(A)

for i in range(N-1):
    if A_copy[-(i+1)] < 0:
        A_copy[-(i+1)], A_copy[-(i+2)] = -A_copy[-(i+1)], -A_copy[-(i+2)]
ans = max(ans, sum(A_copy))

print(sum(A))

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:
        if A[i+1] < 0:
            A[i], A[i+1] = -A[i], -A[i+1]
        elif abs(A[i]) >= abs(A[i+1]):
            A[i], A[i+1] = -A[i], -A[i+1]
    #print("i=",i,"A",A)

#print(A)

print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

A.sort()

ans = 0
cnt_minus = 0
cnt_plus = False

for i in range(n):
    if A[i] < 0:
        cnt_minus += 1
        ans -= A[i]
    elif not cnt_plus:
        if cnt_minus%2 == 0:
            ans += A[i]
        elif A[i] > -A[i-1]:
            ans += A[i] + A[i-1]
        else:
            ans -= A[i]
        cnt_plus = True
    else:
        ans += A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)

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

A.sort()

ans = 0
cnt_minus = 0

for i in range(n):
    if A[i] < 0:
        cnt_minus += 1
        ans -= A[i]
    elif cnt_minus != -1:
        if cnt_minus%2 == 0:
            ans += A[i]
        elif A[i] > -A[i-1]:
            ans += A[i] - (-A[i-1])
        else:
            ans -= A[i]
        cnt_minus = -1
    else:
        ans += A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
if len(A)%2==0:
 ans=0
 for i in A:
  ans+=abs(i)
 print(ans)
else:
 ans=0
 mins=10**10
 for i in A:
  ans+=abs(i)
  mins=min(mins,abs(i))
 print(ans-2*mins)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
a=map(int,input().split())
    
z=0
p=0
result=0
min=1000000002

for i in a:
    if i<0:
        z+=1
    if i==0:
       p=1 
    result+=abs(i)
    if abs(i)<min:
        min=abs(i)

if p==0 & z%2==1:
    result-=min*2

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
a=map(int,input().split())
    
z=0
p=0
result=0
min=1000000002

for i in a:
    if i<0:
        z+=1
    if i==0:
       p=1 
    result+=abs(i)
    if abs(i)<min:
        min=abs(i)

if p==0 & z//2==1:
    result-=min*2

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
a=map(int,input().split())
    
z=0
p=0
result=0
min=1000000002

for i in a:
    if i<0:
        z+=1
    if i==0:
       p=1 

    i=abs(i)
    result+=i
    if i<min:
        min=i

if p==0 & z//2==1:
    result-=min*2

print(result)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[0]*n
a=map(int,input().split())
    
z=0
result=0
min=1000000002

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

    i=abs(i)
    result+=i
    if i<min:
        min=i

if z//2==1:
    result-=min*2

print(result)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

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

print(np.sum(np.abs(A)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

from functools import reduce

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    A = LII()

    if 0 in A:
        print(reduce(lambda a, b: abs(a)+abs(b), A))
        return

  
    p = A[0]
    ans = abs(p) 
    cnt = 1
    n = 0
    mn = 10**9
    for a in A[1:]:
        if p * a < 0:
            if p < 0:
                n += 1 if cnt % 2 == 1 else 0 
            cnt = 0
        ans += abs(a)
        mn = min(mn, abs(a))
        cnt += 1
        p = a
        
    if p < 0:
        n += 1 if cnt % 2 == 1 else 0 
  
    if n % 2 == 0:
        print(ans)
    else:
        print(ans - 2 * mn)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    A = LII()

  
    p = A[0]
    ans = abs(p) 
    cnt = 1
    n = 0
    mn = 10**9
    for a in A[1:]:
        if p * a <= 0:
            if p < 0:
                n += 1 if cnt % 2 == 1 else 0 
            cnt = 0
        ans += abs(a)
        mn = min(mn, abs(a))
        cnt += 1
        p = a
        
    if p < 0:
        n += 1 if cnt % 2 == 1 else 0 
  
    if n % 2 == 0:
        print(ans)
    else:
        print(ans - 2 * mn)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

for i in range(n):
    a[i]=abs(a[i])

if zero_count==1 or minus_count%2==0:
    ans=sum(a)
else:
    heapq.heapify(a)
    mn=heapq.heappop(a)
    print(a)
    print(mn)
    ans=sum(a)-mn

print(ans)

Submission status: Wrong Answer

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

min_idx = 0
min_val = float('inf')

for i, a in enumerate(A):
    if abs(a) < min_val:
        min_idx = i
        min_val = abs(a)


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


for i in range(N - 2, min_idx, -1):
    if A[i + 1] < 0:
        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())
A = list(map(int, input().split()))
m = 0
zero = 0
ans = 0
odd = 10**9
for i in A:
    if i < 0:
        m += 1
    if i == 0:
        zero = 1
    ans += abs(i)
    if odd > abs(i):
        odd = abs(i)
if m %2 == 0 or zero:
    print(ans)
else:
    print(ans-odd)

Submission status: Wrong Answer

Solution code:
import sys

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

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

res = sumA + max(-1 * A[-2] + -1 * A[-1], A[-2] + A[-1])
print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
mi = float('INF')
t=0
for i in range(n):
    if abs(a[i])<mi:
        t=i
a1=a.copy()
sum1=0
for i in range(n-2):
    if a1[i]<0:
        sum1+=a1[i]*(-1)
        a1[i+1]*=-1
    else:
        sum1+=a1[i]
if a1[n-2]+a1[n-1]>(a1[n-2]+a1[n-1])*(-1):
    sum1+=a1[n-2]+a1[n-1]
else:
    sum1+=(a1[n-2]+a1[n-1])*(-1)

sum2=0
for i in range(n-2):
    if i==t and a[i]<0:
        sum2+=a[i]
        continue
    elif i==t and a[i]>0:
        sum2-=a[i]
        a[i+1]*=-1
        continue
    if a[i]<0:
        sum2+=a[i]*(-1)
        a[i+1]*=-1
    else:
        sum2+=a[i]
if a[n-2]+a[n-1]>(a[n-2]+a[n-1])*(-1):
    sum2+=a[n-2]+a[n-1]
else:
    sum2+=(a[n-2]+a[n-1])*(-1)
print(max(sum1,sum2))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
mi = float('INF')
t=0
for i in range(n):
    if abs(a[i])<mi:
        t=i
a1=a.copy()
sum1=0
for i in range(n-2):
    if a1[i]<0:
        sum1+=a1[i]*(-1)
        a1[i+1]*=-1
    else:
        sum1+=a1[i]
if a1[n-2]+a1[n-1]>(a1[n-2]+a1[n-1])*(-1):
    sum1+=a1[n-2]+a1[n-1]
else:
    sum1+=(a1[n-2]+a1[n-1])*(-1)

sum2=0
for i in range(n-2):
    if i==t:
        sum2+=a[i]
        continue
    if a[i]<0:
        sum2+=a[i]*(-1)
        a[i+1]*=-1
    else:
        sum2+=a[i]
if a[n-2]+a[n-1]>(a[n-2]+a[n-1])*(-1):
    sum2+=a[n-2]+a[n-1]
else:
    sum2+=(a[n-2]+a[n-1])*(-1)
print(max(sum1,sum2))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
if np.prod(a) >= 0:
    print(int(np.abs(a).sum()))
else:
    m = np.abs(a).min()
    print(int(np.abs(a).sum() - 2 * m))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
aabs = [i if i>=0 else i*(-1) for i in a]
MIN = min(aabs)
ans = 0
mcount = 0

for i in range(n):
  if a[i] < 0:
    mcount += 1
    
if mcount%2 == 0:
  for i in a:
    ans += abs(i)
    print(ans)
else:
  for i in a:
    ans += abs(i)
  print(ans - 2*MIN)

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

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    hifu_count = 0
    zero_count = num_list.count(0)

    for num in num_list:
        if num < 0:
            hifu_count += 1

    count = 0
    for num in num_list:
        count += abs(num)

    if zero_count >= 1 or hifu_count % 2 == 0:
        pass
    else:
        min_num = min(num_list)
        count -= min_num
        
    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial#, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    n = i_input()
    num_list = i_list()

    count = 0

    for i, num in enumerate(num_list):
        if num > 0:
            count += num
        elif num == 0:
            continue
        else:
            if i + 1 == n:
                count += num
                break
            count += num * -1
            num_list[i+1] *= -1
            
    print(count)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
d=l.copy()
ans=-float("INF")
for i in range(1,n-1):
    if 0>=d[i]+d[i+1]:
        if d[i]<0:
            d[i]*=-1
            d[i+1]*=-1
        

ans=max(ans,sum(d))
l[0]*=-1
l[1]*=-1
for i in range(1,n-1):
    if 0>=l[i]+l[i+1]:
        if l[i]<0:
            l[i]*=-1
            l[i+1]*=-1
print(max(ans,sum(l)))

Submission status: Wrong Answer

Solution code:

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

A[::-1]

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

print(sum+A[i+1])

Submission status: Wrong Answer

Solution code:

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

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

print(sum+A[i+1])

Submission status: Wrong Answer

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