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 math

# Check


def main():
    N = int(input())
    A = list(map(int, input().split()))
    even = 0
    c = 0

    ans = 0
    for i in A:
        if i <= 0:
            c += 1
        else:
            if c % 2 != 0:
                even += 1
            c = 0
        ans += abs(i)

    if c != 0 and c % 2 != 0:
        even += 1

    if even % 2 == 0:
        print(ans)
    else:
        print(ans - min([abs(i) for i in A if abs(i) > 0]) * 2)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

# Check


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

    ans = 0
    for i in A:
        ans += abs(i)
    print(ans)


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

print(sum(A))

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
dp = [[None]*(2) for _ in range(n+1)]

dp[n-1][0] = a[n-1]
dp[n-1][1] = -a[n-1]

for i in reversed(range(n-1)):
    for j in range(2):
        print('\n# i: ' + str(i))
        # Unexe
        unexe_unexe = a[i] + dp[i+1][0]
        exe_unexe = -a[i] + dp[i+1][0]
        dp[i][0] = max(unexe_unexe, exe_unexe)

        # Exe
        unexe_exe = a[i] + dp[i+1][1]
        exe_exe = -a[i] + dp[i+1][1]
        dp[i][1] = max(unexe_exe, exe_exe)

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

Submission status: Wrong Answer

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

n = int(input())
a = list(map(int, input().split()))
dp = [None]*(n+1)

def solve(a):
    l = len(a)
    if dp[l] is not None:
        return dp[l]

    if l == 0:
        dp[l] = 0
        return dp[l]
    elif l == 1:
        dp[l] = a[0]
        return dp[l]
    elif l == 2:
        v1 = a[0] + a[1]
        v2 = -a[0] - a[1]
        dp[l] = max(v1, v2)
        return dp[l]

    v1 = a[0] + solve(a[1:])
    v2 = -a[0] + solve([-a[1]] + a[2:])
    dp[l] = max(v1, v2)
    return dp[l]

#def solve(idx):

print(solve(a))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

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

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

for i in range(1,n-1):
  if a[i]<=0:
    if a[i+1]<=0:
      a[i]*=(-1)
      a[i+1]*=(-1)
    elif a[i-1]<=0:
      a[i]*=(-1)
      a[i+1]*=(-1)
    elif abs(a[i])>=abs(a[i+1]) or abs(a[i])>=abs(a[i-1]):
      if a[i-1]>=a[i+1]:
        a[i]*=(-1)
        a[i+1]*=(-1)
      elif a[i-1]<=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 i == N-2:
    if A[N-2] >= 0 and A[N-1] >= 0:
      pass
    elif A[N-2] >= 0 and A[N-1] < 0:
      if A[N-1] * -1 > A[N-2]:
        A[i] *= -1
        A[i+1] *= -1
    elif A[N-2] < 0 and A[N-1] >= 0:
      if A[N-2] * -1 > A[N-1]:
        A[i] *= -1
        A[i+1] *= -1
    else:
      A[i] *= -1
      A[i+1] *= -1
  else:
    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:
    A[i] *= -1
    A[i+1] *= -1
print(sum(A))

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
cnt = 0
abs_sum = 0
for i in A:
    abs_sum += abs(i)
    if i < 0:
        cnt += 1
mi = min([abs(i) for i in A])
if cnt % 2 == 0:
    print(abs_sum)
else:
    print(abs_sum-mi)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
dp = [0] * N
if a[0] * -1 > 0:
    dp[0] = a[0] * -1
    a[1] = a[1] * -1
else:
    dp[0] = a[0]

for i in range(1, N - 2):
    if a[i] * -1 > 0:
        dp[i] = dp[i - 1] + (a[i] * -1)
        a[i + 1] = a[i + 1] * -1
    else:
        dp[i] = dp[i - 1] + a[i]

dp[N - 1] = max(dp[N - 3] + a[-2] + a[-1], dp[N - 3] - a[-2] - a[-1])
print(dp[-1])

Submission status: Wrong Answer

Solution code:
a=int(input())
lis=list(map(int,input().split()))
lis=sorted(lis)
i=0
while i<a-2 and lis[i]<0:
  if lis[i]<=0 and lis[i+1]>=0:
    if -1*lis[i]>lis[i+1]:
      lis[i],lis[i+1]=-lis[i],-lis[i+1]
  elif lis[i]<=0 and lis[i+1]<=0:
    lis[i],lis[i+1]=-lis[i],-lis[i+1]
  i+=2
print(sum(lis))

Submission status: Wrong Answer

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

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

dp[0][0] = 0
dp[0][1] = -10000

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

Submission status: Wrong Answer

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

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

dp[0][0] = 0
dp[0][1] = -100000

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

Submission status: Wrong Answer

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

cnt=0
S=0
mi=10000000000
C0=False

for i in range(N):
    mi=min(mi,abs(A[i]))
    if A[i]>0:
        S+=A[i]
    elif A[i]==0:
        C0==True
    elif A[i]<0:
        cnt+=1
        S+=(-A[i])

if cnt%2==0 or C0==True:
    print(S)
else:
    print(S-mi)

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())

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

flg=1
for num in A:
    if num < 0:
        flg*(-1)
        
B=[abs(i) for i in A]

if flg==1:
    print(sum(B))
else:
    print(sum(B)-2*sorted(B)[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = 0
c = 0
m = 10 ** 10

for x in a:
    if x < 0:
        c += 1
    
    s += abs(x)
    m = min(m, abs(x))
    
if c % 2 != 0:
    s -= m
    
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
B=[abs(i) for i in A]
P=0
for i in A:
    if i<0:P +=1
    elif i==0:print(sum(B));exit()

print(B if P%2==0 else sum(B)-2*min(B))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
count,flag=0,0
min_n=10**9
for i in A:
    if i<0:count +=1
    elif i==0:flag=True
    elif min_n>abs(i):min_n=abs(i)
sum_n=sum([abs(i) for i in A])
if flag or (count%2==0):print(sum_n)
else:print(sum_n-(2*min_n))

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
count,flag=0,0
min_n=10**9
for i in A:
    if i<0:count +=1
    elif i==0:flag=True
    elif min_n>abs(i):min_n=abs(i)
sum_n=sum([abs(i) for i in A])
if flag or count%2==0:print(sum_n)
else:print(sum_n-(2*min_n))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
min_abs_a = float('inf')
sum_abs_A = 0
include_zero = False
for a in A:
  sum_abs_A += abs(a)
  if a == 0: include_zero = True
  if a < 0 : neg_num += 0
  min_abs_a = min(abs(a),min_abs_a)
print(sum_abs_A if neg_num%2==0 or include_zero is True else sum_abs_A - 2*min_abs_a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
min_abs_a = float('inf')
sum_abs_A = 0
include_zero = False
for a in A:
  sum_abs_A += abs(a)
  if a == 0: include_zero = True
  if a < 0 :
    neg_num += 0
    min_abs_a = min(abs(a),min_abs_a)
print(sum_abs_A if neg_num%2==0 or include_zero is True else sum_abs_A - 2*min_abs_a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
min_abs_a = -float('inf')
sum_abs_A = 0
include_zero = False
for a in A:
  sum_abs_A += abs(a)
  if a == 0: include_zero = True
  if a < 0 :
    neg_num += 0
    min_abs_a = min(abs(a),min_abs_a)
print(sum_abs_A if neg_num%2==0 or include_zero is True else sum_abs_A - 2*min_abs_a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
min_abs_a = -float('inf')
sum_abs_A = 0
include_zero = False
for a in A:
  sum_abs_A += abs(a)
  if a == 0: include_zero = True
  if a < 0 :
    neg_num += 0
    min_abs_a = min(abs(a),min_abs_a)
print(sum_abs_A if neg_num%2==0 or include_zero is True else sum_abs_A + 2*min_abs_a)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
max_neg = -float('inf')
sum_abs_A = 0
include_zero = False
for a in A:
  sum_abs_A += abs(a)
  if a == 0: include_zero = True
  if a < 0 :
    neg_num += 0
    max_neg = max(a,max_neg)
print(sum_abs_A if neg_num%2==0 or include_zero is True else sum_abs_A + 2*max_neg)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
neg_num = 0
max_neg = -float('inf')
sum_abs_A = 0
for a in A:
  sum_abs_A += abs(a)
  if a < 0 :
    neg_num += 0
    max_neg = max(a,max_neg)
print(sum_abs_A if neg_num%2==0 else sum_abs_A + 2*max_neg)

Submission status: Wrong Answer

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


if 0 in lists:
    ans=0
    for _ in lists:
        ans+=abs(_)
        print(ans)
    
    
else:
    abslists=[]
    for j in lists:
        abslists.append(abs(j))
        
    ans=0
    count=0
    
    for inner in lists:
        if inner<0:
            count+=1
        
        else:
            continue
            
    if count%2==0:
        for _ in lists:
            ans+=abs(_)
        print(ans)
        
    else:
        for _ in lists:
            ans+=abs(_)
            
        min1=min(abslists)
        
        print(ans-2*min1)

Submission status: Wrong Answer

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


if 0 in lists:
    ans=0
    for _ in lists:
        ans+=abs(_)
    
    
else:
    abslists=[]
    for j in lists:
        abslists.append(abs(j))
        
    ans=0
    count=0
    
    for inner in lists:
        if inner<0:
            count+=1
        
        else:
            continue
            
    if count%2==0:
        for _ in lists:
            ans+=abs(_)
        print(ans)
        
    else:
        for _ in lists:
            ans+=abs(_)
            
        min1=min(abslists)
        
        print(ans-2*min1)

Submission status: Wrong Answer

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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

# 負の数をカウントしつつ、絶対値が最小の数を求める & 0があるか
smallest = INF
minus = 0
is_zero = False
ans = 0
for a in A:
    if a > 0:
        smallest = min(smallest, abs(a))

    if a == 0:
        is_zero = True
    elif a < 0:
        minus += 1

    ans += abs(a)

if is_zero or minus % 2 == 0:
    print(ans)
else:
    ans -= smallest*2
    print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]+[0]
    for i in range(N-1):
        if A[i] > 0 :
            continue
        elif A[i] + A[i+1] > 0 :
            continue
        else :
            A[i] *= -1
            A[i+1] *= -1
    return  sum(A)
print(main())

Submission status: Wrong Answer

Solution code:
from heapq import heappush,heappop

N = int(input())
array = list(map(int,input().split()))
nega = []
posi = []

for num in array:
  if num >= 0:
    heappush(posi,num)
  else:
    heappush(nega,num*(-1))


if len(nega)%2==0:
  ans = sum(nega) + sum(posi)
else:
  if len(nega)==N:
    max_nega = heappop(nega)
    print(max_nega)
    ans = sum(nega) - max_nega
  else:
    min_posi = heappop(posi)
    max_nega = heappop(nega)
    if min_posi > max_nega:
      ans = sum(nega) + sum(posi) + min_posi - max_nega
    else:
      ans = sum(nega) + sum(posi) - min_posi + max_nega

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a_s = list(map(int, input().split(' ')))

    count = 0
    ans = 0
    _min = 10**9

    for a in a_s:
        if a <= 0:
            count += 1
        ans += abs(a)
        _min = min(_min, abs(a))
    if count % 2 == 1:
        ans -= _min
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
A_list = list(map(int, input().split()))
ans = 0
for i in range(n):
    if A_list[i] < 0:
        ans -= A_list[i]
    else:
        ans += A_list[i]
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a =  list(map(int,input().split()))
a.sort()
#print(a)
for i in range(n-2):
  if a[i]<0:
    a[i]=a[i]*-1
    a[i+1]=a[i+1]*-1
  else:
    pass
#print(a)
print(sum(a))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

else:
    print(suma-2*mini)

Submission status: Wrong Answer

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

else:
    print(suma-2*mini)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
m = 10**9
sum = 0
for i in a:
    i = abs(i)
    m = min(m,i)
    sum += i
    count += 1
    
if count % 2 == 1:
    sum -= m * 2
    
print(sum)

Submission status: Wrong Answer

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

lb = [0]*n
lb[0] = la[0]

for i in range(n-2):
	if lb[i] >= 0:
		lb[i+1] = la[i+1]
	else:
		a = la[i] + la[i+1]
		b = a * -1
		if b >= a:
			lb[i] = lb[i] * -1
			lb[i + 1] = la[i+1] * -1
		else:
			lb[i+1] = la[i+1]

a = lb[n-2] + la[n-1]
b = a * -1
if b >= a:
	lb[n-2] = lb[n-2] * -1
	lb[n-1] = la[n-1] * -1
else:
	lb[n-1] = la[n-1]

print(sum(lb))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
b=False
sum=0
count=0
absmin=100000000000000
for i in l:
  if i==0:
    b=True
  elif i<0:
    count+=1
  if absmin>abs(i):
    absmin=abs(i)
  sum+=abs(i)
if b:
  print(sum)
else:
  if count%2==1:
    print(sum-absmin)
  else:
    print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
b=False
sum=0
count=0
absmin=10000000
for i in l:
  if i==0:
    b=True
  elif i<0:
    count+=1
  if absmin>abs(i):
    absmin=abs(i)
  sum+=abs(i)
if b:
  print(sum)
else:
  if count%2==1:
    print(sum-absmin)
  else:
    print(sum)

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [int(x) for x in input().split()]
dp = [[0 for _ in range(2)] for _ in range(N+1)]
dp[0][0] = 0
dp[0][1] = -10**9
for i in range(N):
  dp[i+1][0] = max(dp[i][0]+x[i],dp[i][1]-x[i])
  dp[i+1][1] = max(dp[i][0]-x[i],dp[i][1]+x[i])
print(max(dp[N][0],dp[N][1]))

Submission status: Wrong Answer

Solution code:
N = int(input())
x = [int(x) for x in input().split()]
dp = [[0 for _ in range(2)] for _ in range(N+1)]
dp[0][0] = 0
dp[0][1] = -10**9
for i in range(N-1):
  dp[i+1][0] = max(dp[i][0]+x[i],dp[i][1]-x[i])
  dp[i+1][1] = max(dp[i][0]-x[i],dp[i][1]+x[i])
print(max(dp[N][0],dp[N][1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
dp = [[0,0]]*(n+1)
dp[0][0] = 0
dp[0][1] = -float('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(dp[n][0])

Submission status: Wrong Answer

Solution code:
import copy
import sys

sys.setrecursionlimit(10 ** 7)

N = int(input())
A = [int(i) for i in input().split(' ')]

# 1 から N-1 を小さい順に並べる
# 負の数が残り1つになるまで -1 を掛ける操作を繰り返す
# 最後の負の数になったときに、足してマイナスになるなら -1 を掛ける

sorted_A = sorted(A)
A_n_1 = sorted(copy.deepcopy(A[:-1]))
An = A[-1]

is_N_minus = True if An < 0 else False
An_abs = abs(An)

result = 0
for i in range(N - 1):
    if A_n_1[i] <= 0:
        if (i + 1 == N - 1) or A_n_1[i + 1] > 0:
            # 判断する
            _an = An_abs
            _an_pm = -1 if is_N_minus else 1
            _an = _an_pm * _an
            if A_n_1[i] + _an < 0:
                is_N_minus = not is_N_minus  # An に -1 を掛ける
                result += -A_n_1[i]  # ー1 をかけて足す
            else:
                result += A_n_1[i]
        else:
            is_N_minus = not is_N_minus  # An に -1 を掛ける
            result += -A_n_1[i]  # ー1 をかけて足す
    else:
        result += A_n_1[i]

# N番目を足す
_an = An_abs
_an_pm = -1 if is_N_minus else 1
_an = _an_pm * _an
result += _an

print(result)

Submission status: Wrong Answer

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

if 0 in A:
	print(sum(abs(a) for a in A))

cnt=sum([1 for a in A if a<0])
if cnt%2==0:
	print(sum(abs(a) for a in A))
else:
	A=[abs(a) for a in A]
	print(sum(A) -2*min(A))

Submission status: Wrong Answer

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

p = min(b)
ans = sum(b) - 2 * p
print(ans)

Submission status: Wrong Answer

Solution code:
# ABC125D - Flipping Signs
def main():
    # neg % 2 == 0 -> all negatives disappear
    # 0 in A -> move all neg there
    # else -> move all neg to smallest one (abs(i))
    N = int(input())
    A = tuple(map(int, input().split()))
    mi = min(A, key=abs)
    abs_sum = sum(abs(i) for i in A)
    neg = sum(i < 0 for i in A)
    if 0 in A or neg % 2 == 0:
        print(abs_sum)
    else:
        print(abs_sum - mi * 2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = sum(map(abs,A))
flag = False
sign = 0
mi = 10 ** 9
for a in A:
    if a == 0:
        flag = True
        break
    if a < 0:
        sign += 1
        if abs(a) < mi: mi = abs(a)
if flag:
    print(ans)
else:
    if sign % 2 == 0:
        print(ans)
    else:
        print(ans-2*mi)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
ans = sum(map(abs,A))
flag = False
sign = 0
mi = 10 ** 9
for a in A:
    if a == 0:
        flag = True
        break
    if a < 0:
        sign += 1
        if abs(a) < mi: mi = a
if flag:
    print(ans)
else:
    if sign % 2 == 0:
        print(ans)
    else:
        print(ans-2*abs(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
temp = li.copy()
for i in range(n-1):
    if li[i] < 0:
        li[i] *= -1
        li[i+1] *= -1
ans = sum(li)
li = temp
for i in reversed(range(1,n)):
    if li[i] < 0:
        li[i] *= -1
        li[i-1] *= -1
ans = max(ans, sum(li))
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int, input().split()))
temp = li.copy()
for i in range(n-1):
    if li[i] < 0:
        li[i] *= -1
        li[i+1] *= -1
ans = sum(li)
li = temp
for i in reversed(range(1,n)):
    if li[i] < 0:
        li[i] *= -1
        li[i-1] *= -1
ans = max(ans, sum(li))

Submission status: Wrong Answer

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

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

print(sum(li))

Submission status: Wrong Answer

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

def count_negative(n,a):
    count = 0
    for i in range(n):
        if a[i] == 0:
            return 0
        elif a[i] < 0:
            count += 1
    return count

def num_of_min(n,a):
    minimum = max(a)
    count = 0    
    tmp = 0
    for i in range(n):
        tmp = abs(a[i])
        if tmp < minimum:
            minimum = tmp
            count = i
        else:
            pass
    return count

def flipping(n,a):
    nc = count_negative(n,a)
    total = 0
    count = 0
    if nc % 2 == 0:
        for i in range(n):
            total += abs(a[i])
    else:
        count = num_of_min(n,a)
#            print("i %d, a[i] %d, count %d" %(i,a[i],count))
        target = a.pop(count)

        k = n - 1
        for i in range(k):
            total += abs(a[i])
#            print("i %d, tmp total %d" %(i,total))
        else:
            total += target*(-1)

    return total

if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())
    gt = flipping(n,a)
    print("%d" %gt)

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

Submission status: Wrong Answer

Solution code:
def main():
    n = int(input())
    a = list(map(int,input().split()))
    for i in range(n-2):
        if a[i]< 0:
            a[i] = -a[i]
            a[i+1] *= -1
    if a[-1]>=0 and a[-2]>=0:
        pass
    elif a[-1]<=0 and a[-2]<=0:
        a[-1] *= -1
        a[-2] *= -1
    else:
        if abs(a[-2])>=abs(a[-1]):
            a[-2] = abs(a[-2])
            a[-1] = -1*abs(a[-1])
        else:
            a[-2] = -1*abs(a[-2])
            a[-1] = abs(a[-1])
    print(sum(a))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
A = [int(a) for a in input().split()]
A.sort()
A_abs = [abs(ab) for ab in A]

sum_abs = sum(A_abs)

wh = bisect.bisect_left(A, 0)
dev2 = wh % 2
if dev2 == 0:
  print(sum_abs)
else:
  print(sum_abs - 2 * A_abs[0])

Submission status: Wrong Answer

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

#print(s)

count = 0
#for i in range(N-1):
#  if s[i] < 0:
#    s[i] -= 2 * s[i]
#    s[i+1] -= 2 * s[i+1]
#for j in range(N):
#  count += int(s[j])
#print(count)

min1 = abs(s[0])
#print(min1)
for i in range(N):
  min1 = min(min1, abs(s[i]))
  count += abs(s[i])
  
count = count - 2*min1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
s = [input().split() for i in range(1)]
t = s[0]
t_int = [int(n) for n in t]
#print(s)
#print(t_int)
x = 0
count = 0
for i in range(N-1):
  if t_int[i] < 0:
    t_int[i] -= 2 * t_int[i]
    t_int[i+1] -= 2 * t_int[i+1]
for j in range(N):
  count += float(t_int[j])
print(float(count))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
min_num = 10**9
cnt = 0
sum_num = 0
for idx in range(N):
  if A[idx] < 0:
    cnt += 1
  min_num = min(min_num, abs(A[idx]))
  sum_num += abs(A[idx])
if cnt%2 == 0:
  print(sum_num)
else:
  print(sum_num-min_num)

Submission status: Wrong Answer

Solution code:
def larger(x, y):
	if x > y:
		return x
	return y

N = int(input())
A = list(map(int, input().split()))
dpp = [A[0]]
dpn = [-A[0]]
for i in range(1, N-1):
	dpp.append(larger(dpp[-1]+A[i], dpn[-1]-A[i]))
	dpn.append(larger(dpp[-1]-A[i], dpn[-1]+A[i]))
dpp.append(dpp[-1]+A[-1])
dpn.append(dpn[-1]-A[-1])
print(larger(dpp[-1], dpn[-1]))

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:
    print(tmp)
else:
    ind = np.argmin(np.abs(a))
    print(tmp-a[ind]*2)