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()))
count = 0
ans, mina = a[0], a[0]
flag = False
for i in range(1, n):
    ans += abs(a[i])
    mina = min(mina, abs(a[i]))
    if a[i]<0: count += 1
if count%2 or a.count(0): print(ans-mina*2)
else: print(ans)

Submission status: Wrong Answer

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = np.array(lr())
if np.count_nonzero(A) != len(A):
    answer = np.abs(A).sum()
else:
    negative = np.count_nonzero(A < 0)
    if negative%2 == 0:
        answer = np.abs(A).sum()
    else:
        answer = np.abs(A).sum()
        answer -= 2 * min(np.abs(A[0]), np.abs(A[-1]))

print(answer)
# 37

Submission status: Wrong Answer

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
A = nl()

abstotal = sum([abs(i) for i in A])
absmin = min([abs(i) for i in A])
if n % 2 == 0:
    ans = abstotal
else:
    ans = abstotal - 2 * absmin
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline
#from collections import defaultdict
#d = defaultdict(int)
#import fractions
#import math
#import collections
#from collections import deque
#from bisect import bisect_left
#N = int(input())
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = list(map(int,input().split()))
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
A = list(map(int,input().split()))
if 0 in A:
    s = 0
    for i in A:
        s += abs(i)
    print(s)
c = 0
for i in range(N):
    if A[i] < 0:
        c += 1
        A[i] *= -1
Min = min(A)
s = 0
for i in A:
    s += i
if c % 2 == 1:
    s -= Min * 2
print(s)

Submission status: Wrong Answer

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

zero = False
minus = 0
min = -999999999999999
sum = 0
for i in a:
    if i == 0:
        zero = True
    if i < 0:
        minus += 1
        min = max(min, i)
    sum += abs(i)

if not zero and minus % 2 != 0:
    sum += min * 2

print(sum)

Submission status: Wrong Answer

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

mina = abs(aa[0])
nm = 0
for i in range(n):
    mina = min(mina, abs(aa[i]))
    if aa[i] < 0:
        nm += 1

if nm % 2 == 1 and mina == 0:
    print(sum(map(abs, aa)) - 2 * mina)
else:
    print(sum(map(abs, aa)))

Submission status: Wrong Answer

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

mina = aa[0]
nm = 0
for i in range(n):
    mina = min(mina, abs(aa[i]))
    if aa[i] < 0:
        nm += 1

if nm % 2 == 1 and mina > 0:
    print(sum(map(abs, aa)) - 2 * mina)
else:
    print(sum(map(abs, aa)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
cnt = 1
ans = 0
for i in range(N):
  if(A[i] < 0):
    cnt = cnt * (-1)
  elif(A[i] == 0):
    cnt = cnt * 0
if(cnt >= 0):
  for i in range(N):
    ans += abs(A[i])
else:
  for i in range(N):
    A[i] = abs(A[i])
  A.sort()
  for i in range(N):
    ans = A[i]
  ans -= A[0] * 2
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:
        continue
    elif a[i] == 0:
        if a[i] >= 0:
            continue
        else:
            a[i] *= -1
            a[i+1] *= -1
    else:
        a[i] *= -1
        a[i+1] *= -1

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

ans = sum(a)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

N = int(input())

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

neg_cnt = 0
minimum = 10**10
for num in A:
    minimum = min(minimum, abs(num))
    if num < 0:
        neg_cnt += 1
        

print(minimum)
ans = 0
for num in A:
    if num < 0:
        ans += -num
    else:
        ans += num 

print(ans)
print(neg_cnt)
if neg_cnt % 2 == 0:
    print(ans)               
else:
    print(ans - minimum * 2)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
n = int(input())
a = np.array([int(x) for x in input().split()])
dp = np.zeros((n + 1, 2))
dp[0][1] = -2000000001
for i in range(n):
	dp[i + 1][0] = dp[i][0] + a[i]
	dp[i + 1][1] = dp[i][0] - a[i]
print(int(dp[n][0]))

Submission status: Wrong Answer

Solution code:
import math

n = int(input())
a_list = [int(i) for i in input().split()]
sum = 0
ans = 0
mini = 10000000000
count = 0
for i in range(n):
    if a_list[i]<0:
        count += 1
    mini = min(mini,abs(a_list[i]))
    sum += abs(a_list[i])

if count%2==1:
    print(sum - mini)
else:
    print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[i]<0:
    cnt+=1
if min(a)>=0 or cnt%2==0:
  print(sum(a))
  exit()
b=[abs(a[i]) for i in range(n)]
s=sum(b)
ans=-10**18
for i in range(n):
  ans=max(ans,s-2*b[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
if min(a)>=0:
  print(sum(a))
  exit()
b=[abs(a[i]) for i in range(n)]
s=sum(b)
ans=-10**18
for i in range(n):
  ans=max(ans,s-2*b[i])
print(ans)

Submission status: Wrong Answer

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

for i in range(1,N):
  B.append(B[-1]+A[i])
  
maxi= -1*float("inf")
print(maxi)
for j in range(N-1):
  tmp= B[-1] -2*(A[j]+A[j+1])
  maxi=max(maxi,tmp)
  
print(maxi)

Submission status: Wrong Answer

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

min_v = 10**9+1
cnt_min = 0
res = 0
for i, a in enumerate(A_list):
    print(i, a)
    if a < 0:
        cnt_min += 1
        a = -1 * a
    min_v = min(min_v, a)
    res += a

if cnt_min%2 == 1:
    res -= 2*min_v
print(res)

Submission status: Wrong Answer

Solution code:
n, *A = map(int, open(0).read().split())
print(sum(map(abs, A)) - 2*min(map(abs, A)))

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
count=0
sum=0
A=float("inf")
for i in L:
	sum+=abs(i)
	A=min(A,abs(i))
	if i<0:
		count+=1
if count%2==0:
	print(sum)
else:
	B=float("inf")
	for i in L:
		if i==A:
			if i==0:
				print(sum)
				exit()
			elif i>0:
				print(sum-2*i)
				exit()
			elif i<0:
				print(sum-2*A)
				exit()

Submission status: Wrong Answer

Solution code:
N=int(input())
L=list(map(int,input().split()))
count=0
sum=0
A=float("inf")
for i in L:
	sum+=abs(i)
	A=min(A,abs(i))
	if i<0:
		count+=1
if count%2==0:
	print(sum)
else:
	B=float("inf")
	for i in L:
		if i==A:
			if i==0:
				print(sum)
			elif i>0:
				print(sum-2*i)
			elif i<0:
				print(sum-2*A)

Submission status: Wrong Answer

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

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][1] = -10**9
for i in range(n):
    for j in range(2):
        dp[i+1][1-j] = max(dp[i+1][1-j],dp[i][j]+(-1)**(j+1)*a[i])
        dp[i+1][j] = max(dp[i+1][j],dp[i][j]+(-1)**j*a[i])
print(dp[n][0])

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
idx = []
idx2 = []
i = 0
while i < n:
    if i < n - 1 and a[i] < 0 and a[i + 1] < 0:
        idx.extend([i, i + 1])
        i += 2
    elif a[i] < 0:
        idx2.append(i)
        i += 1
    else:
        i += 1
for i in idx:
    a[i] = -a[i]
flag = True
for ii in range(len(idx2)):
    i = idx2[ii]
    if ii < len(idx2) - 1 and idx2[ii + 1] - i == 2 and flag:
        a[i] = -a[i]
        a[i + 1] = -a[i + 1]
        flag = False
        continue
    flag = True
    arr = [-inf for _ in range(3)]
    if 0 < i < n - 1:
        arr[0] = a[i - 1] + a[i] + a[i + 1]
        arr[1] = a[i - 1] - (a[i] + a[i + 1])
        arr[2] = -(a[i - 1] + a[i]) + a[i + 1]
        j = arr.index(max(arr))
        if j == 0:
            continue
        elif j == 1:
            a[i] = -a[i]
            a[i + 1] = -a[i + 1]
        else:
            a[i] = -a[i]
            a[i - 1] = -a[i - 1]
    elif i == 0:
        arr[0] = a[i] + a[i + 1]
        arr[1] = -(a[i] + a[i + 1])
        j = arr.index(max(arr))
        if j == 0:
            continue
        elif j == 1:
            a[i] = -a[i]
            a[i + 1] = -a[i + 1]
    elif i == n - 1:
        arr[0] = a[i] + a[i - 1]
        arr[1] = -(a[i] + a[i - 1])
        j = arr.index(max(arr))
        if j == 0:
            continue
        elif j == 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()))
dp = [[0]*2 for _ in range(n+1)]
for i in range(n):
    for j in range(2):
        dp[i+1][1-j] = max(dp[i+1][1-j],dp[i][j]+(-1)**(j+1)*a[i])
        dp[i+1][j] = max(dp[i+1][j],dp[i][j]+(-1)**j*a[i])
print(max(dp[n][0],dp[n][1]))

Submission status: Wrong Answer

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

import copy
A_ = copy.copy(A)

if n == 2:
    print(max(sum(A), -sum(A)))
    exit()

for i in range(n-2):
    if A[i] < 0:
        A[i] *= (-1)
        A[i+1] *= (-1)
s = sum(A[0:(n-2)])
ans1 = max(s+A[n-2]+A[n-1], s-A[n-2]-A[n-1])

A_.reverse()
for i in range(n-2):
    if A_[i] < 0:
        A_[i] *= (-1)
        A_[i+1] *= (-1)
s = sum(A_[0:(n-2)])
ans2 = max(s+A_[n-2]+A_[n-1], s-A_[n-2]-A_[n-1])
print(max(ans1, ans2))

Submission status: Wrong Answer

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

abs_sum = 0
minus = 0
abs_list = []
for i in range(n):
    if A[i] < 0:
        minus += 1
    abs_list.append(abs(A[i]))
    abs_sum += abs_list[i]

if minus % 2 != 0:
    abs_sum -= min(abs_list)
print(abs_sum)

Submission status: Wrong Answer

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

if n == 2:
    print(max(sum(A), -sum(A)))
    exit()

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

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    DP = [[-10 ** 20] * 2 for _ in range(N)]
    DP[0][0] = A[0]
    DP[0][1] = -1 * A[0]
    for i in range(1, N):
        a = A[i]
        DP[i][0] = max(max(DP[i-1][0] + a, DP[i-1][1] - a), DP[i][0])
        DP[i][1] = max(max(DP[i-1][0] - a, DP[i-1][1] + a), DP[i][1])
    print(DP[N-1])

    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
x=int(input())
y=list(map(int, input().split()))
t=1
for i in range(x):
	if y[i]<0:
		t=t*-1
	y[i]=abs(y[i])

if y==1:
	print(sum(y))
else:
	print(sum(y)-(min(y)*2))

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(N-1):
  if a[i]>0:
    ans+=a[i]
  else:
    if a[i+1]<0:
      ans+=(-a[i])
      a[i+1]*=-1
    else:
      if -a[i]>=a[i+1]:
        ans+=-a[i]
        a[i+1]*=-1
      else:
        ans+=a[i]
print(ans+a[-1])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
zero=0
ans=0
mn=1000000001
for x in a:
  mn=min(mn,abs(x))
  if x<0:
    cnt+=1
    ans-=x
  else:
    ans+=x
  print(ans)
cnt%=2
if cnt==0:
  print(ans)
else:
  print(ans-mn*2)
  
  
  
  
  
#print(ans,cnt,mn)

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

apos = []
aneg = []

for a in A:
    if a >=0: apos.append(a)
    else: aneg.append(a)

apos.sort()
aneg.sort()

if len(aneg) % 2 == 0:
    ans = sum(apos) - sum(aneg)
else:
    if len(apos) == 0:
        ans = - sum(aneg) + 2*aneg[-1]
    else:
        if abs(apos[0]) > abs(apos[-1]):
            ans = sum(apos) - sum(aneg) -  2*abs(aneg[-1])
        else:
            ans = sum(apos) - sum(aneg) - 2*abs(apos[0])


print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    f,b=[0]*(n+2),[0]*(n+2)
    f[1],b[n]=a[0],a[-1]
    for i in range(2,n+1):
        f[i],b[n-i+1]=gcd(a[i-1],f[i-1]),gcd(a[n-i],b[n-i+2])
    ans=0
    for i in range(1,n+1):
      ans=max(ans,gcd(f[i-1],b[i+1]))
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import fractions as fr
input = sys.stdin.readline

def main():
    n=int(input())
    a=list(map(int,input().split()))
    f,b=[0]*n,[0]*n
    for i in range(n):
      if i==0:
        f[i],b[n-i-1]=a[i],a[n-i-1]
      else:
        f[i],b[n-i-1]=fr.gcd(a[i],a[i-1]),fr.gcd(a[n-i-1],a[n-i])
    ans=max(b[1],f[-2])
    for i in range(1,n-1):
      ans=max(ans,fr.gcd(f[i-1],b[i+1]))
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

def main():
    n = int(input())
    a = [int(t) for t in input().split()]

    m = 0
    if 0 in a:
        m = sum([abs(x) for x in a])
    else:
        a_ = [abs(x) for x in a]
        m = sum(a_)-2*min(a_)

    print(m)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
t = 0
i = 0
while True:
    if A[i]<0:
        A[i] = -1*A[i]
        if i==N-1:
            if t%2==0:
                break
            elif t%2==1:
                A[i] = -1*A[i]
                break
        t+=1
    elif A[i]>=0:
        if t%2==0:
            break
        elif t%2==1:
            X = -1*A[i]+A[i-1]
            Y = -1*A[i-1]+A[i]
            if X>=Y:
                A[i] = -1*A[i]
            else:
                A[i-1] = -1*A[i-1]
            break
    i+=1

print(sum(A))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
# import statistics
import heapq
sys.setrecursionlimit(100001)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
data = getInputListInt()

for i in range(n):
    if data[i] < 0:
        data[i] *= -1

print(sum(data))

Submission status: Wrong Answer

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

ans,cnt,mini=[],0,float('inf')
for a in A:
  if abs(a)!=a: cnt+=1
  ans.append(abs(a))
  mini=min(mini,abs(a))
if cnt%2==0:
  print(sum(ans))
else:
  print(sum(ans)-mini)

Submission status: Wrong Answer

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

min_abs = abs(a[0])  # a[0], ..., a[n-1]中の絶対値の最小値
sum = 0   # b[0] +  ... + b[n-1]
p_neg = 0  # a[0], ..., a[n-1]中の負の数の数が偶数なら0、奇数なら1
zero_exists = False  # a[0], ..., a[n-1]の中に0があるかどうか

for i in range(n):
    min_abs = min( min_abs, abs(a[i]))
    if a[i] < 0:
        p_neg = 1 - p_neg
        sum += -a[i]
    elif a[i] == 0:
        zero_exists = True
        break
    else:
        sum += a[i]

if zero_exists or p_neg == 0:
    pass
else:
    sum -= 2 * min_abs

print(sum)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
    a[i] = abs(a[i])
a.sort()
a[0] *= -1
print(sum(a))

Submission status: Wrong Answer

Solution code:
import bisect
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    i = bisect.bisect_left(A, 0)
    j = bisect.bisect_right(A, 0)
    if i % 2 == 0:
        print(sum([abs(i) for i in A]))
    else:
        if i != j:
            print(sum([abs(i) for i in A]))
        elif i == N:
            print(sum([abs(i) for i in A]) - 2 * A[-1])
        else:
            if abs(A[i-1]) > A[i]:
                print(sum([abs(i) for i in A]) - 2 * A[i])
            else:
                print(sum([abs(i) for i in A]) - 2 * abs(A[i-1]))
main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# わからない

Submission status: Wrong Answer

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

ans = 0
for i in range(n-1):
    if a[i]<0 and -a[i] >= a[i+1]:
        a[i]=-a[i]
        a[i+1]=-a[i+1]
    ans += a[i]
ans += a[n-1]
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 and abs(a[i]) > abs(a[i+1]):
    #    a[i] *= -1
    #    a[i+1] *= -1
    if a[i] < 0:
        a[i] *= -1
        a[i+1] *= -1

#if abs(a[-1]) > abs(a[-2]):
#    a[-1] *= -1
#    a[-2] *= -1

print(sum(a))

Submission status: Wrong Answer

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

f=(0 in a)

import numpy as np

a=np.array(a)

b=abs(a)

c=min(b)

d=sum(a==b)

if d%2==1 or f:
  print(sum(b))
else:
  print(sum(b)-2*c)

Submission status: Wrong Answer

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

a=np.array(a)

b=abs(a)

c=min(b)

d=sum(a==b)

if d%2==1 or f:
  print(sum(b))
else:
  print(sum(b)-2*c)

Submission status: Wrong Answer

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

import numpy as np

a=np.array(a)

b=abs(a)

c=min(b)

d=sum(a==b)

if d%2==1:
  print(sum(b))
else:
  print(sum(b)-2*c)

Submission status: Wrong Answer

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

ans = []
minus_num = 0

for num in a:
    if num < 0:
        ans.append( num * -1 )
        minus_num += 1
    else:
        ans.append( num )

print(ans)

if minus_num % 2 == 0:
    print(sum(ans))
else:
    ans.sort()
    print(sum(ans[1:]) + ans[0] * -1)

Submission status: Wrong Answer

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

ans = 0
for num in a:
    if num < 0:
        ans += num * -1
    else:
        ans += num

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
mai=0
for i in range(n):
    if a[i]<0:
        mai+=1
for i in range(n):
    if i==0 or i==n-1:
        continue
    if a[i]<0:
        a[i]=-a[i]
    ans+=a[i]
dif=min(a[0],a[n-1])
dim=max(a[0],a[n-1])
if mai%2==0:
    print(max(ans-dif-dim,ans+dif+dim))
else:
    print(max(ans+dif-dim,ans-dif+dim))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
    if i==0 or i==n-1:
        continue
    if a[i]<0:
        a[i]=-a[i]
    ans+=a[i]
dif=min(a[0],a[n-1])
dim=max(a[0],a[n-1])
print(max([ans+dim-dif,ans-dim+dif,ans-dim-dif]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(map(int, input().split())) + [0]
print(sum(map(lambda a, b: abs(a + b), a[::2], a[1::2])))

Submission status: Wrong Answer

Solution code:
N = input()
A = list(map(int, input().replace('-', '').split()))
print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
min_b = 10**9
sum_b = 0
for i in range(n):
    sum_b += abs(a[i])
    if abs(a[i]) < min_b:
        min_b = abs(a[i])
print(sum_b - 2*min_b)

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] = -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
B = []

for i in A:
  if i < 0:
    MINUS += 1
  else:
    B.append(i)
  
if min(A) > 0:
  print(sum(A))
  exit(0)
  
ans = 0
if MINUS % 2 == 0:
  for a in A:
    ans += abs(a)
else:
  minB = max(A)
  for a in A:
    ai = abs(a)
    if ai < minB:
      minB = ai
    ans += ai
  ans -= minB * 2

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
MINUS = 0
B = []

for i in A:
  if i < 0:
    MINUS += 1
  else:
    B.append(i)
  
if min(A) > 0:
  print(sum(A))
  exit(0)
  
ans = 0
if MINUS % 2 == 0:
  for a in A:
    ans += abs(a)
else:
  minB = max(A)
  for a in A:
    ai = abs(a)
    if ai < minB:
      minB = ai
    ans += ai
  ans -= minB

print(ans)

Submission status: Wrong Answer

Solution code:
import math
def calculate(arr1,arr2,zeroExist):
    if (len(arr1) % 2 == 0) or (zeroExist == True):
        return sum(arr2) - sum(arr1)
    else:
        return sum(arr2) - sum(arr1) - 2 * (calculateAbsSmallest(arr1,arr2))



def concatList(arr1,arr2):
    arr3 = list([])
    arr3.extend(arr1)
    arr3.extend(arr2)
    return arr3

def calculateAbsSmallest(arr1,arr2):
    if len(arr2) == 0:
        arr1.sort()
        return -arr1[0]
    
    arr1.sort()
    arr2.sort()
    return min(-arr1[0],arr2[0])


N = int(input())

arr1 = []
arr2 = []
zeroExist = False
for s in input().split(" "):
    if int(s) == 0:
        zeroExist = True
    if int(s) < 0:
        arr1.append(int(s))
    else:
        arr2.append(int(s))

arr1 = list(arr1)
arr2 = list(arr2)

res = calculate(arr1,arr2,zeroExist)
print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=[0]*n
for i in range(n):
    B[i]=abs(A[i])
B.sort()
print(sum(B)-2*B[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=[0]*n
for i in range(n):
    B.append(abs(A[i]))
B.sort()
B[0]=-B[0]
print(sum(B))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
D=0
for i in range(N-1):
  a=A[i]
  b=A[i+1]
  if a>=0:
    D+=a
  else:
    A[i]=a*(-1)
    A[i+1]=b*(-1)
    D+=a*(-1)
D+=A[N-1]
x=A[N-2]+A[N-1]
E=D-2*x
print(max(D,E))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
D=0
for i in range(N-1):
  a=A[i]
  b=A[i+1]
  if a>=0:
    D+=a
  else:
    A[i]=a*(-1)
    A[i+1]=b*(-1)
    D+=a*(-1)
D+=A[N-1]
print(D)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
D=0
for i in range(N-1):
  a=A[i]
  b=A[i+1]
  if a>0:
    D+=a
  else:
    A[i]=a*(-1)
    A[i+1]=b*(-1)
    D+=a*(-1)
D+=A[N-1]
print(D)

Submission status: Wrong Answer

Solution code:
n = int(input())
List = list(map(int,input().split()))
counter = 0
min = max(List)
sum = 0
for item in List:
  if item < 0:
    counter += 1
  if abs(item) <= min:
    min = abs(item)
  sum += abs(item)

if counter %2 == 0:
  Answer = sum
else:
  Answer = sum -min*2

print(Answer)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
na = [abs(i) for i in a]
m = min(na)
s = sum(na)

if m == 0:
    ans = s
else:
    cnt = 0
    for i in a:
        if i < 0:
            cnt += 1
    if cnt%2 == 0:
        ans = s
    else:
        ans = s-m

print(ans)

Submission status: Wrong Answer

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
#from scipy.misc import comb

MOD = 10**9+7

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

positive = []
negative = []
zeros = []

for a in A:
    if a > 0:
        positive.append(a)
    elif a < 0:
        negative.append(-a)
    else:
        zeros.append(a)

ans = sum(positive)+sum(negative)


print(ans)

Submission status: Wrong Answer

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

count = 0

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

print(A)     

if count % 2 == 0:
    print(sum(A))
else:
    A.sort()
    print(sum(A) - 2 * A[0])

Submission status: Wrong Answer

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


for i in range(n):
    if a[i] < 0:
        if i == 0:
            if ((a[i + 1] * -1) + a[i] * -1) >= a[i] + a[i+1]:
                a[i] *= - 1
                a[i + 1] *= - 1
        elif i == n - 1:
            if ((a[i - 1] * -1) + a[i] * -1) >= a[i] + a[i-1]:
                a[i] *= - 1
                a[i - 1] *= - 1
        elif max((a[i - 1] * -1) + a[i] * -1, (a[i + 1] * -1) + a[i] * -1) > (a[i + 1] * -1) + a[i] * -1:
            a[i - 1] *= - 1
            a[i] *= - 1
        else:
            a[i] *= - 1
            a[i + 1] *= - 1

ans = 0
for i in range(n):
    ans += a[i]

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [0] + list(map(int,input().split()))
dp = [0]*(n+1)

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



print(sum(dp))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
mn=10**18
ng=0
for i in a:
  mn=min(mn,abs(i))
  if i<0:
    ng+=1
if ng%2==0:
  print(sum(a))
else:
  print(sum(a)-mn*2)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

count  = 0
for i in range(n-2):
    if a[i] > 0 and a[i+1] < 0 and a[i+2] > 0:
        count += 1
    elif a[i] < 0 and a[i+1] < 0 and a[i+2] < 0:
        count += 1

a = np.abs(a)
a.sort()
b = a[count:]
c = a[:count]


print(sum(b) - sum(c))

Submission status: Wrong Answer

Solution code:
n=input()
a=list(map(int,input().split()))
n=sum(x<0 for x in a)
a=list(map(lambda x: abs(x),a))
m=min(a)
s=sum(a) if n%2==0 else sum(a)-m 
print(s)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
cnt=0
for i in range(n):
    if a[i]<0:
        cnt+=1
cnt1=a[0]
for j in range(n):
    if a[j]!=0: ans+=abs(a[j])
    if cnt1>abs(a[j]):
        cnt1=abs(a[j])
    #print(ans)
if cnt%2==0:
    print(ans)
else:
    print(ans-abs(cnt1)*2)
#print(cnt)
#print(a//x,b//x)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=0
cnt=0
for i in range(n):
    if a[i]<=0:
        cnt+=1
cnt1=a[0]
for j in range(n):
    ans+=abs(a[j])
    if cnt1>abs(a[j]):
        cnt1=abs(a[j])
    #print(ans)
if cnt%2==0:
    print(ans)
else:
    print(ans-abs(cnt1)*2)

Submission status: Wrong Answer

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


if __name__ == '__main__':
    p_d()