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 -*-
n = int(input())
a_l = list(map(int, input().split()))

a_min = 10**9
for i in range(n-1):
    if a_l[i] < 0:
        a_l[i] = a_l[i]*-1
        a_l[i+1] = a_l[i+1]*-1
    if i == n-1:
        if abs(a_l[i+1])>a_l[i]:
            a_l[i] = a_l[i]*-1
            a_l[i+1] = a_l[i+1]*-1




print(sum(a_l))

Submission status: Wrong Answer

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

for i in range(n-1):
        if columns[i] < 0 and columns[i+1] < 0:
            columns[i+1] = -columns[i+1]
            columns[i] = -columns[i]
        
        elif columns[i+1] + columns[i] <= 0 and columns[i] < 0:
            columns[i+1] = -columns[i+1]
            columns[i] = -columns[i]

result = 0
for x in columns:
    result += x

print(result)

Submission status: Wrong Answer

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

from fractions import gcd
from functools import reduce
import functools

def gcd(a,b):
    if a==0:
        return b 
    else:
        return gcd(b%a,a)
  
max_gcd = 0
loop_range = min(200,len(A))

# 小さい方から確認
for i in range(loop_range):
  if i < N:
    values = A[i+1:] + A[:i] 
  else:
    values = A[:-1]
  
  g = lambda a,b:a if b==0 else g(b,a%b)
  gcd = functools.reduce(lambda x,y:g(x,y),values)
  max_gcd = max(max_gcd,gcd)

# 大きい方からも確認
A.sort(reverse=True)
for i in range(loop_range):
  if i < N:
    values = A[i+1:] + A[:i] 
  else:
    values = A[:-1]
  
  g = lambda a,b:a if b==0 else g(b,a%b)
  gcd = functools.reduce(lambda x,y:g(x,y),values)
  max_gcd = max(max_gcd,gcd)

print(max_gcd)

Submission status: Wrong Answer

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

minNum = 0

for x in range(0, len(aList)):
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]
	minNum += 1 if aList[x] < 0 else 0

aMin = min(aList)

even = minNum%2==0

if not even:
	print(sum(aList))
else:
	print(sum(aList) - (aMin*2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

####################
if N>2:

    m=[0 for i in range(N)]
    m[N-1] = A[N-1]
    m[N-2] = (abs(A[N-1]+A[N-2]))

    m1 = A[N-1]+A[N-2]+A[N-3]
    m2 = A[N-1]-A[N-2]-A[N-3]
    m3 = -A[N-1]-A[N-2]+A[N-3]
    m4 = -A[N-1]+A[N-2]-A[N-3]

    m[N-3] = max(m1,m2,m3,m4)

    for i in range(N-4,-1,-1):
        m[i]=max(m[i+3]+A[i]+abs(A[i+1]+A[i+2]),m[i+2]+abs(A[i]+A[i+1]),m[i+1]+A[i],m[i+3]-A[i]+A[i+1]-A[i+2])

    ####################
    M = [0 for i in range(N)]
    M[0] = A[0]
    M[1] = (abs(A[0]+A[1]))

    m1 = A[0]+A[1]+A[2]
    m2 = A[0]-A[1]-A[2]
    m3 = -A[0]-A[1]+A[2]
    m4 = -A[0]+A[1]-A[2]

    M[2] = max(m1,m2,m3,m4)

    for i in range(3,N):
        M[i]=max(M[i-3]+A[i]+abs(A[i-1]+A[i-2]),M[i-2]+abs(A[i]+A[i-1]),M[i-1]+A[i],M[i-3]-A[i]+A[i-1]-A[i-2])

    ans = max(M[0],m[0])


    print(ans)
else:
    ans = abs(A[0]+A[1])
    print(ans)

Submission status: Wrong Answer

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

for i in range(n - 1):
    if i == n - 2:
        if (num_list[i] < 0 and num_list[i + 1] < 0) or (num_list[i] < 0 and abs(num_list[i]) > abs(num_list[i + 1])) or (num_list[i + 1] < 0 and abs(num_list[i]) < abs(num_list[i + 1])):
            num_list[i], num_list[i + 1] = num_list[i] * -1, num_list[i + 1] * -1
    else:
        if (num_list[i] < 0 and num_list[i + 1] < 0) or (num_list[i] < 0 and abs(num_list[i]) > abs(num_list[i + 1])):
            num_list[i], num_list[i + 1] = num_list[i] * -1, num_list[i + 1] * -1
print(sum(num_list))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = 0
    for i in range(len(A) - 2):
        if 0 == A[i] and 0 > A[i + 1] and 0 > A[i + 2]:
            A[i + 1] *= -1
            A[i + 2] *= -1
            continue
        if 0 > A[i]:
            A[i] *= -1
            A[i + 1] *= -1
        B += A[i]
    if 0 >= A[-2]:
        A[-2] *= -1
        A[-1] *= -1
    print(B + A[-1] + A[-2])


main()

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
n = sum(1 for x in A if x<0)
print(n)
B = np.abs(A)
if n % 2 == 1:
  print(sum(B) - 2*min(B))
else:
  print(sum(B))

Submission status: Wrong Answer

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

count = 0
minus = 0
total = 0
for i in range(n):
    if a[i] == 0:
        count = i
if count == 0:
    while count < n:
        if a[count] < 0:
            minus += 1
        count += 1
else:
    minus = 0

if minus%2 == 0:
    for i in range(n):
        a[i] = abs(a[i])
    total = sum(a)
else:
    for i in range(n-1):
        a[i] = abs(a[i])
    a[n-1] = -abs(a[n-1])
    total = sum(a)

print(total)

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:
import numpy

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

sorted_index = sorted(range(len(A)), key=lambda k: abs(A[k]))
sorted_index = sorted_index[::-1]

for i in range(N):
    if sorted_index[i] == N - 1:
        continue

    if A[sorted_index[i]] < 0:
        if 0 < A[sorted_index[i]+1] and abs(A[sorted_index[i]]) < A[sorted_index[i]+1]:
            continue
        A[sorted_index[i]] = A[sorted_index[i]] * -1
        A[sorted_index[i]+1] = A[sorted_index[i]+1] * -1

ans = numpy.sum(A)
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
import math
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()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

a = LIST()

ct = 0

for i, x in enumerate(a):
    if x <= 0:
        ct += 1
        if x < 0:
            p = [i, x]
        else:
            ct = 0

"print(p)"

lis = [abs(x) for x in a]
"""print(ct, sum(lis))"""

if ct % 2 == 0:
    print(sum(lis))
else:
    if p[0] == n-1:
        print(sum(lis) - 2 * min(abs(p[1]), abs(a[p[0] - 1])))
    else:
        print(sum(lis) - 2 * min(abs(p[1]), abs(a[p[0] + 1])))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int, input().split()))
b = []
sum = 0
for i in range(n):
  sum += a[i]
max = sum
c = a
min = c[0] + c[1]
key1 = 0
key2 = 1
while(1):
  for i in range(1, n-1):
    if min > c[i] + c[i+1]:
      min = c[i] + c[i+1]
      key1 = i
      key2 = i+1
    c[key1] = c[key1]*(-1)
    c[key2] = c[key2]*(-1)
  sum = 0
  for i in range(n):
    sum += c[i]
  if max < sum:
    max = sum
  else:
    break
print(max)

Submission status: Wrong Answer

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

s = 0
mc = 0
for i in A:
  if i < 0:
    mc += 1
  s += abs(i)

if (mc % 2 == 1):
  mv = min(A[0],A[-1])
  #print('mv',mv)
  s -= mv*2
print(s)

Submission status: Wrong Answer

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

for i in range(N):
  if A[i] < 0:
    if i != N-1:
      if A[i]+A[i+1] <= (A[i]*-1 + A[i+1]*-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 = [int(a) for a in input().split()] 
ans = 0
for i in range(N):
  if A[i] < 0:
    if i < N - 1:
      A[i] = - A[i]
      A[i + 1] = - A[i + 1]
      ans += A[i]
    else:
      ans += A[i]
  else:
    ans += A[i]
    
if A[N - 2] + A[N - 1] < - A[N - 2] - A[N - 1]:
  ans += 2 * (- A[N - 2] - A[N - 1])
  
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(s) for s in input().split()]
for j in range(len(a)):
	if a[j]<0:
	    a[j]=abs(a[j])
print(sum(a))

Submission status: Wrong Answer

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

for i in range(n - 1):
    if i == n - 1:
        if (num_list[i] < 0 and num_list[i + 1] < 0) or (num_list[i] < 0 and abs(num_list[i]) > abs(num_list[i + 1])) or (num_list[i + 1] < 0 and abs(num_list[i]) < abs(num_list[i + 1])):
            num_list[i], num_list[i + 1] = num_list[i] * -1, num_list[i + 1] * -1
    else:
        if (num_list[i] < 0 and num_list[i + 1] < 0) or (num_list[i] < 0 and abs(num_list[i]) > abs(num_list[i + 1])):
            num_list[i], num_list[i + 1] = num_list[i] * -1, num_list[i + 1] * -1
print(sum(num_list))

Submission status: Wrong Answer

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

import numpy as np
A = np.array(A)
B = A
for i in range(len(A)-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 :
        if A[i] + A[i+1] <= 0:
            A[i] = A[i] * -1
            A[i+1] = A[i+1] * -1

print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys,collections as cl
import fractions
from functools import reduce
import copy
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


n = int(input())
su = 0

a = l()

co = 0
k = 0
a.sort()
f = 0
for i in range(n):
	if a[i] <= 0:
		co += 1
if co % 2 == 0:
	for i in range(n):
		su += abs(a[i])
	print(su)
else:
	for i in range(n):
		if f == 2 or a[i] == 0:
			break
		if a[i] >= 0 and f == 0:
			kk = a[i-1]
			f = 1
		if a[i] >= 0:
			if abs(a[0]) >= a[i]:
				k = a[i]*(-2)
			else:
				k = kk*2
			f = 2
		elif i == n-1:
			k = a[i]*2
	for i in range(n):
		su += abs(a[i])
	su += k
	print(su)

Submission status: Wrong Answer

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

minus_count_even_flug = 1
zero_exist_flug = -1

for a in a_list:
    if a < 0:
        minus_count_even_flug *= -1
    if a == 0:
        zero_exist_flug = 1

a_abs_list = [abs(a) for a in a_list]
sum_a_abs_list = sum(a_abs_list)
if minus_count_even_flug == 1 or zero_exist_flug == 1:
    print(sum_a_abs_list)
else:
    print(max(sum_a_abs_list - (2 * a_abs_list[0]), sum_a_abs_list - (2 * a_abs_list[-1])))

Submission status: Wrong Answer

Solution code:
n = int(input())
*v, = map(int,input().split())
#print(v)
c = v
mn = 0
cn = 0
flag = True
while flag:  
  for i in range(n-1):
    if i == n-2:
      if abs(c[n-2]) > abs(c[n-1]) and c[n-2] < 0:
        c[i] = c[i]*(-1)
        c[i+1] = c[i+1]*(-1)
      else:
        continue
    elif c[i] < 0:
      c[i] = c[i]*(-1)
      c[i+1] = c[i+1]*(-1)
  cn = sum(c)
  if mn == cn:
    flag = False
  elif cn > mn:
    mn = cn
  
print(mn)

Submission status: Wrong Answer

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

zero = [0]*N
div1 = 0
div2 = 0
for i in range(N):
    if A[i] < 0:
        zero[i] += 1
        if i % 2 == 0:
            div2 += 1
        else:
            div1 += 1
#print(div1,div2)
A = [abs(i) for i in A]
A_1 = A[1::2]
A_2 = A[0::2]
#print(A_1,A_2)

if div2 - div1 == 1:
    print(sum(A) - min(A_1)*2)

elif div1 - div2 == 1:
    print(sum(A) - min(A_2)*2)

else:
    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):
  if A[i] < 0:
    if i != N-1:
      if A[i]+A[i+1] <= 0:
        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()))
a.append(0)
a.append(0)
a.append(0)
for i in range(n):
    if a[i]<0 and a[i+1]<0 and a[i+2]>=0 and i<=n-1:
        a[i]=-a[i]
        a[i+1]=-a[i+1]
    elif a[i]<0 and a[i+1]>=0 and a[i+2]<0:
        a[i]=-a[i]
        a[i+2]=-a[i+2]
    elif a[i]<0 and a[i+1]<0 and a[i+2]<0:
        if a[i+3]<abs(a[i+2]):
            a[i]=-a[i]
            a[i+1]=-a[i+1]
            a[i+2]=-a[i+2]
            a[i+3]=-a[i+3]
        elif abs(a[i]+a[i+1])>abs(a[i+1]+a[i+2]):
            a[i]=-a[i]
            a[i+1]=-a[i+1]
        else:
            a[i+1]=-a[i+1]
            a[i+2]=-a[i+2]
    elif a[i]<0 and a[i+1]>=0 and a[i+2]>=0 and i<=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()))

####################
if N>2:

    m=[0 for i in range(N)]
    m[N-1] = A[N-1]
    m[N-2] = (abs(A[N-1]+A[N-2]))

    m1 = A[N-1]+A[N-2]+A[N-3]
    m2 = A[N-1]-A[N-2]-A[N-3]
    m3 = -A[N-1]-A[N-2]+A[N-3]
    m4 = -A[N-1]+A[N-2]-A[N-3]

    m[N-3] = max(m1,m2,m3,m4)

    for i in range(N-4,-1,-1):
        m[i]=max(m[i+3]+A[i]+abs(A[i+1]+A[i+2]),m[i+2]+abs(A[i]+A[i+1]),m[i+1]+A[i])

    ####################
    M = [0 for i in range(N)]
    M[0] = A[0]
    M[1] = (abs(A[0]+A[1]))

    m1 = A[0]+A[1]+A[2]
    m2 = A[0]-A[1]-A[2]
    m3 = -A[0]-A[1]+A[2]
    m4 = -A[0]+A[1]-A[2]

    M[2] = max(m1,m2,m3,m4)

    for i in range(3,N):
        M[i]=max(M[i-3]+A[i]+abs(A[i-1]+A[i-2]),M[i-2]+abs(A[i]+A[i-1]),M[i-1]+A[i])

    ans = max(M[0],m[0])


    print(ans)
else:
    ans = abs(A[0]+A[1])
    print(ans)

Submission status: Wrong Answer

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

A.sort()
for i in range(N-1):
    if 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())
n=0
A=list(map(int,input().split()))
for i in range(N-1):
 if A[i] < 0 and (abs(A[i]) >= abs(A[i+1]) or (A[i] < 0 and A[i+1] <=0)):
  A[i] = 0-A[i]
  A[i+1] =0-A[i+1]
 else:
  if A[i] < 0 and A[i+1] <= 0:
   A[i] = 0-A[i]
   A[i+1] = 0-A[i+1]
for i in range(0,N):
 n+=A[i]
print(n)

Submission status: Wrong Answer

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

def solve(a):
    ret = 0
    for i in range(len(a)-1):
        if a[i] < 0:
            a[i] *= -1
            a[i+1] *= -1
        ret += a[i]
#         print(a[i], ret)
    ret += a[-1]
    return ret

print(max(solve(a), solve(a[::-1])))

Submission status: Wrong Answer

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

count = 0
minus = 0
total = 0
for i in range(n):
    if a[i] == 0:
        count = i

while count < n:
    if a[count] < 0:
        minus += 1
    count += 1

if minus%2 == 0:
    for i in range(n):
        a[i] = abs(a[i])
    total = sum(a)
else:
    for i in range(n-1):
        a[i] = abs(a[i])
    a[n-1] = -abs(a[n-1])
    total = sum(a)

print(total)

Submission status: Wrong Answer

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

for i in range(n-1):
    d = a[i] + a[i+1]
    if -d > d:
        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-1):
	if((A[i]<0 and A[i+1]<0) or ((A[i]<0 or A[i+1]<0) and (A[i]*(-1)>A[i+1]*(-1)))):	
		A[i] = A[i]*(-1)
		A[i+1] = A[i+1]*(-1)
	else:
		continue
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 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 = list(map(int, input().split()))

zero_count = 0
minus_count = 0
total = 0
minimum = abs(A_list[0])
for i in range(len(A_list)):
    if A_list[i] == 0:
        zero_count += 1
    elif A_list[i] < 0:
        minus_count += 1

    total += abs(A_list[i])
    if A_list[i] != 0:
        minimum = min(minimum, abs(A_list[i]))
#   print("total:{} min:{} zero:{} minus:{}".format(total, minimum, zero_count, minus_count))

if (minus_count - zero_count) % 2 == 0:
    print(total)
else:
    print(total - minimum*2)

Submission status: Wrong Answer

Solution code:
#conding utf-8
N = int(input())
A = input().split()
ans = 0
t = 0
for i in range(N):
  A[i] = int(A[i])
for i in range(N):
  if A[i] == 0:
    for j in range(N):
      if A[j]<0:
        A[j] = -A[j]
    ans = sum(A)
for j in range(N):
  if A[j]<0:
    t +=1
if t%2 == 0:
  for j in range(N):
    if A[j]<0:
      A[j] = -A[j]
      ans = sum(A)
else:
  for j in range(N):
    if A[j]<0:
      A[j] = -A[j]
  A[A.index(min(A))] = -A[A.index(min(A))]
  ans = sum(A)
      
print(ans)

Submission status: Wrong Answer

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

for i in range(n - 1):
    if (num_list[i] < 0 and num_list[i + 1] < 0) or (num_list[i] < 0 and abs(num_list[i]) > abs(num_list[i + 1])):
        num_list[i], num_list[i + 1] = num_list[i] * -1, num_list[i + 1] * -1
print(sum(num_list))

Submission status: Wrong Answer

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

minus_count_even_flug = 1

for a in a_list:
    if a <= 0:
        minus_count_even_flug *= -1

a_abs_list = [abs(a) for a in a_list]
sum_a_abs_list = sum(a_abs_list)
if minus_count_even_flug == 1:
    print(sum_a_abs_list)
else:
    print(max(sum_a_abs_list - (2 * a_abs_list[0]), sum_a_abs_list - (2 * a_abs_list[-1])))

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

Submission status: Wrong Answer

Solution code:
import fractions
import functools
N = int(input())
A = [int(i) for i in input().split()] 
max_gcd = functools.reduce(fractions.gcd, A)
for i in range(N):
	tmp = A.copy()
	if A[i]%2==1:
		tmp.pop(i)
		gcd = functools.reduce(fractions.gcd, tmp)
	else:
		gcd = functools.reduce(fractions.gcd, tmp)
	if max_gcd < gcd:
		max_gcd = gcd
print(max_gcd)

Submission status: Wrong Answer

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

absA=[0 for i in range(N)]
for i in range(N):
    absA[i]=abs(A[i])

res = sum(absA)-min(absA)
print(res)

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]
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 += int(t_int[j])
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

fu = np.sum(A < 0)

if fu == 0:
    print(np.sum(A))
elif fu%2 == 0:
    print(np.sum(abs(A)))
else:
    b = min(abs(A))
    print(np.sum(abs(A)) - b)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = 0;count = 0;check = False
for i in range(n):
    if a[i] == 0:check = True
    if m < abs(a[i]):
        m = a[i]
    if a[i] < 0:count += 1
if count % 2 == 0:check = True
s = 0
for i in range(n):
    s += abs(a[i])
if check:print(s)
else:print(s-2*abs(m))

Submission status: Wrong Answer

Solution code:
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
import math
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()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

n = INT()

a = LIST()

ct = 0

for i, x in enumerate(a):
    if x <= 0:
        p = [i, x]
        ct += 1

"print(p)"

lis = [abs(x) for x in a]
"""print(ct, sum(lis))"""

if ct % 2 == 0:
    print(sum(lis))
else:
    if p[0] == n-1:
        print(sum(lis) - 2 * min(abs(p[1]), abs(a[p[0] - 1])))
    else:
        print(sum(lis) - 2 * min(abs(p[1]), abs(a[p[0] + 1])))

Submission status: Wrong Answer

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

ans = -1000000000
for i in range(N):
  if A[i] < 0:
    if i != N-1:
      if A[i]+A[i+1] <= 0:
        A[i] = A[i] * -1
        A[i+1] = A[i+1] * -1
        ans = max(ans, sum(A))

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

plus = [x for x in A if x >0]

minus = [x for x in A if x <=0]

minus.sort()
if len(minus) % 2 == 0:
    print(sum(plus)-sum(minus))

else:
    plus.sort()
    if len(plus) == 0:
        plus = [0]
    r = min(plus[0],-1*minus[-1])
    print(sum(plus)-sum(minus)-2*r)

Submission status: Wrong Answer

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

####################
if N>2:

    m=[0 for i in range(N)]
    m[N-1] = A[N-1]
    m[N-2] = (abs(A[N-1]+A[N-2]))

    m1 = A[N-1]+A[N-2]+A[N-3]
    m2 = A[N-1]-A[N-2]-A[N-3]
    m3 = -A[N-1]-A[N-2]+A[N-3]
    m4 = -A[N-1]+A[N-2]-A[N-3]

    m[N-3] = max(m1,m2,m3,m4)

    for i in range(N-4,-1,-1):
        m[i]=max(m[i+3]+A[i]+abs(A[i+1]+A[i+2]),m[i+2]+abs(A[i]+A[i+1]))

    ####################
    M = [0 for i in range(N)]
    M[0] = A[0]
    M[1] = (abs(A[0]+A[1]))

    m1 = A[0]+A[1]+A[2]
    m2 = A[0]-A[1]-A[2]
    m3 = -A[0]-A[1]+A[2]
    m4 = -A[0]+A[1]-A[2]

    M[2] = max(m1,m2,m3,m4)

    for i in range(3,N):
        M[i]=max(M[i-3]+A[i]+abs(A[i-1]+A[i-2]),M[i-2]+abs(A[i]+A[i-1]))

    ans = max(M[0],m[0])


    print(ans)
else:
    ans = abs(A[0]+A[1])
    print(ans)

Submission status: Wrong Answer

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

for i in range(n - 1):
    if num_list[i] < 0 and abs(num_list[i]) > abs(num_list[i + 1]):
        num_list[i], num_list[i + 1] = num_list[i] * -1, num_list[i + 1] * -1
print(sum(num_list))

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]
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 += t_int[j]
print(count)

Submission status: Wrong Answer

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

N = int(input())
A = [int(a) for a in input().split()]
# B = [a for a in A]

# 正の数p, 負の数nに対して、p+n=N
# 全探索は2^Nで爆発

# sm2 = [A[i] + A[i+1] for i in range(0, N-1)]
# sm3 = [A[i] + 2*A[i+1] + A[i+2] for i in range(0, N-2)]

# 最終状態から考える
# A[i]の符号は以下の時に正、
# 1. A[i-1]+A[i] > 0
# 2. A[i+1]+A[i] > 0
# 3. -A[i+1]+A[i]-A[i-1] > 0

# for i in range(1, N-1):
#     p1, p2, p3 = A[i-1], A[i], A[i+1]
#     if p1+p2 > 0 or p2+p3 > 0 or -p1+p2-p3 > 0:
#         B[i] = abs(p2)
#     else:
#         B[i] = -abs(p2)

# B[0] = A[0]+A[1] if A[0]+A[1] > 0 else -A[0]-A[1]
# B[-1] = A[-1]+A[-2] if A[-1]+A[-2] > 0 else -A[-1]-A[-2]

# print(sum(B))

# O(Nk)になってTLE
while True:
    ch = False
    for i in range(0, N-1):
        if i < N-2 and A[i]+A[i+2] < 0:
            # A[i]+A[i+1]+A[i+2] < -A[i]+A[i+1]-A[i+2]:
            A[i] *= -1
            A[i+2] *= -1
            ch = True
        if A[i] + A[i+1] < 0:
            A[i] *= -1
            A[i+1] *= -1
            ch = True
    if ch is False:
        break

print(sum(A))

Submission status: Wrong Answer

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

for x in range(0, len(aList)):
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]

aMin = min(aList)

print(sum(aList) - ((aMin if len(aList)%2 == 1 else 0)*2))

Submission status: Wrong Answer

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

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

print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)

if A[0]<0:
    print(-sum(A))
    exit()
MP = 0 #minus point
while A[MP] >= 0:
    MP += 1
    if MP == N:
        print(sum(A))
        exit()

if (N-MP)%2 == 0:
    A = [abs(i) for i in A]
    print(sum(A))
else:
    B = [abs(i) for i in A[MP-1:]]
    B.sort()
    B[0] = -B[0]
    C = A[:MP-1] + B
    print(sum(C))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.append(0)
sum_a=sum(a)
x=[-100000000000]*(n+1)
x[0]=sum_a
for i in range(n-1):
    a[i]=-1*a[i]
    a[i+1]=-1*a[i+1]
    xx=x[i]+2*a[i]+2*a[i+1]
    if xx>=x[i]:
        x[i+1]=xx
    else:
        a[i]=-1*a[i]
        a[i+1]=-1*a[i+1]
        x[i+1]=0

print(max(x))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(ret)

Submission status: Wrong Answer

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

def absdiff(a,b):
  return abs(abs(a) - abs(b))

for i in range(n-1):
  if absdiff(a[i], a[i+1]) > absdiff(a[m], a[m+1]):
    m = i
  if a[i] < 0:
    a[i] = -1*a[i]
    a[i+1] = -1*a[i+1]
if a[-1] < 0:
  if absdiff(a[-2], a[-1]) < absdiff(a[m], a[m+1]):
    for i in range(m, n-1):
      a[i] = -1*a[i]
      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()))
a.append(0)
sum_a=sum(a)
x=[-100000000000]*(n+1)
x[0]=sum_a
for i in range(n-1):
    a[i]=-1*a[i]
    a[i+1]=-1*a[i+1]
    xx=x[i]+2*a[i]+2*a[i+1]
    if xx>=x[i]:
        x[i+1]=xx
    else:
        a[i]=-1*a[i]
        a[i+1]=-1*a[i+1]
        x[i+1]=0

print(x)
print(max(x))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

ans = 0
cost = float('inf')
count = 0

for i in a:
    ans += abs(i)
    cost = min(cost,abs(i))
    if i < 0:
        count += 1

if 0 not in a:
    # count = max(count,n-count)
    if count % 2 != 0:
        ans -= cost

print(ans)

Submission status: Wrong Answer

Solution code:
#conding utf-8
N = int(input())
A = input().split()
ans = 0
t = 0
for i in range(N):
  A[i] = int(A[i])
for i in range(N):
  if A[i] == 0:
    for j in range(N):
      if A[j]<0:
        A[j] = -A[j]
    ans = sum(A)
for j in range(N):
  if A[j]<0:
    t +=1
if t%2 == 0:
  for j in range(N):
    if A[j]<0:
      A[j] = -A[j]
      ans = sum(A)
else:
  for j in range(N):
    if A[j]<0:
      A[j] = -A[j]
      A[A.index(min(A))] = -A[A.index(min(A))]
      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 abs(A[i])> abs(A[i+1]) and A[i]<0:
        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 = [int(a) for a in input().split()] 
ans = 0
_ans = 0
for i in range(N):
  if A[i] < 0:
    if i < N - 1:
      ans += - A[i]
      A[i + 1] = - A[i + 1]
    else:
      ans += A[i]
  else:
    ans += A[i]
    
if ans < ans - 2 * A[N - 2] - 2 * A[N - 1]:
  ans = ans - 2 * A[N - 2] - 2 * A[N - 1]
print(ans)

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int,input().split()))
c = 0
for i in range(n-1) :
    i = i + c
    c = 0
    if i <= n-2 :
        if num[i] < 0 and num[i+1] < 0 :
            num[i] *= -1
            num[i+1] *= -1
            c = 1
        elif num[i] > 0 and num[i+1] > 0 :
            num[i] *= 1
            num[i+1] *= 1
            c = 1
        elif num[i] < 0 and num[i+1] > 0 :
            if -num[i] >= num[i+1] :
                num[i] *= -1
                num[i+1] *= -1
                c = 0
        elif num[i] == 0 and num[i+1] < 0 :
            num[i] *= -1
            num[i+1] *= -1
            c = 0
        elif num[i] < 0 and num[i+1] == 0 :
            num[i] *= -1
            num[i+1] *= -1
            c = 0
        elif num[i] > 0 and num[i+1] < 0 :
            c == 0
print(sum(num))