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


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:
        j = N-1
        while j > i+1:
            sumA = A[i] + A[j] - sum(A[i+1:j])
            if sumA < 0:
                A[i] = -1 * A[i]
                A[j] = -1 * A[j]
                j = 0
            j -= 1

print(sum(A))

Submission status: Wrong Answer

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

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

    if i==n-2 and b[i]+b[i+1]<-b[i]-b[i+1]:
        b[i]*=-1
        b[i+1]*=-1
    elif b[i]<0:
        b[i]*=-1
        b[i+1]*=-1


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

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 = [int(item) for item in input().split()]

# ans = sum(a)
# i = 0
# while i < n and a[i] >= 0:
#     i += 1

min_suf = [0] * n
min_suf[-1] = a[-1]
for i in range(n - 2, -1, -1):
    min_suf[i] = min(min_suf[i + 1], abs(a[i]))

flag = False
for i in range(n):
    if a[i] >= 0:
        flag = False
    elif a[i] < 0 and i < n - 1 and min_suf[i + 1] <= abs(a[i]):
        a[i] *= -1
        a[i + 1] *= -1
        flag = True
    elif a[i] < 0 and flag and min_suf[i] == abs(a[i]):
        flag = False
    # print(a)

print(sum(a))

# dp = [0] * (n + 1)
# for i in range(1, n + 1):
#     dp[i] = dp[i - 1] + max(a[i])

Submission status: Wrong Answer

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

minus_count = 0
plus_list = []
for x in n_list:
  if x < 0:
    minus_count += 1
  plus_list.append(abs(x))
    
if x % 2 == 0 or 0 in plus_list: #even
  print(sum(plus_list))
else:
  print(sum(plus_list) - 2 * min(plus_list))

Submission status: Wrong Answer

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
count = 0
for i in range(len(a)):
    if a[i] < 0:
        count += 1
        a[i] = -a[i]
ans = 0
if count % 2 == 0:
    ans = sum(a)
else:
    ans = sum(a) - min(a)
print(ans)

Submission status: Wrong Answer

Solution code:
A=int(input())
B=[_ for _ in map(int,input().split())]
"マイナスの数を求める"
minus=0
for i in B:
  if i<0:
    minus=+1
"マイナスの数が偶数の場合、絶対値Bを全部足す"
ans=0
if minus%2==0:
  for i in B:
    if i<0:
      ans=+(-1)*i
    else:
      ans+=i
  print(ans)

else:
  S=0
  for i in range(A):
    B[i]=abs(B[i])
  
  for i in B:
    S+=i
  if (S-2*min(B))<=0:
    print(0)
  else:
    print(S-min(B))

Submission status: Wrong Answer

Solution code:
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsl = lambda: map(str, sys.stdin.readline().split())

n = ni()
a = nl()
count = 0
for i in range(len(a)):
    if a[i] < 0:
        count += 1
        a[i] = -a[i]
ans = 0
if count % 2 == 0:
    ans = sum(a)
else:
    print(a, sum(a), min(a))
    ans = sum(a) - min(a)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = 0;index = 0
for i in range(n):
    if m < abs(a[i]):
        m = a[i]
        index = i
s = 0;check = False
if a[-1] < 0 or a[0] < 0:check = True
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:
n = int(input())
A = [int(a) for a in input().split()]
B = [1 if _ > 0 else 0 for _ in A]

i = B[:-2].count(0)

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

C = abs(sum(A[-2:]))

D = sum([abs(d) for d in A[:-2]])

print(D+C)

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):
  if t_int[i] < 0:
    count -= t_int[i]
    x += 1
  else:
    count += t_int[i]
if x % 2 == 0:
  count += 2 * t_int[N-1]
else:
  count -= 2 * t_int[N-1]
print(count)

Submission status: Wrong Answer

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

dp = [[-10**16 for __ in range(3)] for _ in range(N+10)]
A = A+[0,0,0,0,0,0,0]

dp[0][0] = A[0]
dp[0][1] = -A[0]

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

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

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:
			break
		if a[i] >= 0 and f == 0:
			kk = a[i-1]
			f = 1
		if a[i] >= 0:
			if a[i] == 0:
				k = 0
				break
			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(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:
import math

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



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


print(max(x))

Submission status: Wrong Answer

Solution code:
N = int(input())
At = list(map(int, input().split()))
INF = 10**10
A = [INF, INF] + At + [INF, INF]
start = False
ans = 0
for i in range(1, N + 3):
  if A[i - 1] >= 0 and A[i] >= 0 and A[i + 1] < 0:
    start = True
    mi = INF
    count = 0
  if start:
    if A[i] < 0:
      tem = -A[i]
      count += 1
    else:
      tem = A[i]
    if tem != INF:
      ans += tem
    mi = min(tem, mi)
    if A[i - 1] < 0 and A[i] >= 0 and A[i + 1] >= 0:
      if count % 2 == 0:
        start = False
      else:
        ans -= 2*mi
        start = False
  else:
    if A[i] != INF:
      ans += A[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = int(input())

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

if np.sum(A==0) != 0:
# Aに0が含まれる場合
    # 最後に0が出てくる場所
    z = np.max(np.where(A==0))
    B = A[z:N]
    if np.sum(B < 0)%2 ==0:
        sign = 1
    else:
        sign = -1

# Aに0が含まれない場合
else:
    if np.sum(A < 0)%2 ==0:
        sign = 1
    else:
        sign = -1

print(np.abs(A[0:N-1]).sum() + sign*abs(A[-1]))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
if n == 2:
    i = 0
    if (A[i] >= 0 and A[i+1] <= 0) and abs(A[i]) < abs(A[i+1]):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
    elif (A[i] <= 0 and A[i+1] >= 0) and abs(A[i]) > abs(A[i+1]):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
    elif A[i] <= 0 and A[i+1] <= 0:
        A[i] = -A[i]
        A[i+1] = -A[i+1]
else:
    for i in range(n-2):
        if A[i] >= 0 and A[i+1] >= 0 and A[i+2] >= 0:
            continue
        elif A[i] >= 0 and A[i+1] >= 0 and A[i+2] <= 0:
            continue
        elif A[i] >= 0 and A[i+1] <= 0 and A[i+2] >= 0:
            if abs(A[i+2]) <= abs(A[i+1]) and A[i+2] <= A[i]:
                A[i+2] = -A[i+2]
                A[i+1] = -A[i+1]
            elif abs(A[i]) <= abs(A[i+1]) and A[i] <= A[i+2]:
                A[i] = -A[i]
                A[i+1] = -A[i+1]
        elif A[i] <= 0 and A[i+1] >= 0 and A[i+2] >= 0:
            if abs(A[i]) >= abs(A[i+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+1] = -A[i+1]
            A[i+2] = -A[i+2]
        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:
            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+1] = -A[i+1]
    i = n-2
    if (A[i] >= 0 and A[i+1] <= 0) and abs(A[i]) < abs(A[i+1]):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
    elif (A[i] <= 0 and A[i+1] >= 0) and abs(A[i]) > abs(A[i+1]):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
    elif A[i] <= 0 and A[i+1] <= 0:
        A[i] = -A[i]
        A[i+1] = -A[i+1]
    #print(A)
print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
a = l.copy()
ans = 0
for i in range(n-1):
    #print(a)
    #iがプラス
    if a[i] > 0:
        #i+1がマイナス
        if a[i+1] < 0:
            if abs(a[i]) <= abs(a[i+1]):
                a[i] = a[i] * -1
                a[i + 1] = a[i+1] * -1
                #print(a)
                #print(sum(a))
    #iが0
    elif a[i] == 0:
        if a[i+1] <= 0:
            a[i] = a[i] * -1
            a[i + 1] = a[i+1] * -1
            #print(a)
            #print(sum(a))
    # iがマイナス
    else:
        #i+1がプラス
        if a[i+1] > 0:
            if abs(a[i]) >= abs(a[i+1]):
                a[i] = a[i] * -1
                a[i + 1] = a[i+1] * -1
                #print(a)
                #print(sum(a))
        elif a[i + 1] == 0:
            a[i] = a[i] * -1
            a[i + 1] = a[i+1] * -1
            #print(a)
            #print(sum(a))                
        else:
            a[i] = a[i] * -1
            a[i + 1] = a[i+1] * -1
            #print(a)
            #print(sum(a))
print(sum(a))

Submission status: Wrong Answer

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

neg = [x for x in a if x < 0]

b = len(neg) % 2 == 0

if b:
    print(sum([abs(x) for x in a]))
else:
    a.remove(max(neg))
    flip = [abs(x) for x in a]
    if -max(neg) > min(flip):
        print(sum(flip) - min(flip) * 2- max(neg))
    else:
        print(sum(flip))

Submission status: Wrong Answer

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

####################
m=[0 for i in range(N)]
m[N-1] = abs(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]))

print(m[0])

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:
      ans += - A[i]
      A[i + 1] = - A[i + 1]
    else:
      ans += A[i]
  else:
    ans += A[i]
    
print(ans)

Submission status: Wrong Answer

Solution code:

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

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline
n = int(input())
a_list = list(map(int, input().split()))
for i in range(n-1):
    if i < n-2:
        if a_list[i] + a_list[i+1] <= 0:
            if a_list[i] < a_list[-1]:
                a_list[i] = a_list[i] * (-1)
                a_list[i+1] = a_list[i+1] * (-1)
    else:
        if a_list[i] + a_list[i+1] < 0:
            a_list[i] = a_list[i] * (-1)
            a_list[i+1] = a_list[i+1] * (-1)

print(sum(a_list))

Submission status: Wrong Answer

Solution code:
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read() for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


N = read_a_int()
A = read_ints()

# 最初にすべてのマイナスが外せないか試して、
# abs最小の数に-をつけて合計すればいいんだ！

# 問題はどうやってすべてのマイナスがはずせるか判別するか
# +-+,---っていうパターンがあったらアウト
flg = False
for a1, a2, a3 in zip(A, A[1:], A[2:]):
    if a1 > -1 and a2 < 0 and a3 > -1:
        flg = True
    if a1 < 0 and a2 < 0 and a3 < 0:
        flg = True

anstmp = sum([abs(a) for a in A])
if not flg:
    print(anstmp)
    exit()

# else
mi = 10 ** 9
for a in A:
    mi = min(mi, abs(a))

print(anstmp-2*mi)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
m = 0;index = 0
for i in range(n):
    if m < abs(a[i]):
        m = a[i]
        index = i
s = 0;check = False
for i in range(n-1):
    if a[i] < 0:
        a[i] *= -1
        a[i+1] *= -1
if a[-1] > 0:check = True
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:
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)

negcnt = 0
zcnt = 0
for k in a:
    if k < 0:
        negcnt += 1
    elif k == 0:
        zcnt += 1

ans = 0
if (negcnt + zcnt) % 2 == 0:
    for k in a:
        ans += abs(k)
    print(ans)
else:
    negmin = -1 * (10**9+1)
    for k in a:
        if k > negmin:
            negmin = k
    for k in a:
        ans += abs(k)
    print(ans - 2*negmin)

Submission status: Wrong Answer

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

dp = [[-10**16 for __ in range(3)] for _ in range(N+10)]
A = A+[0,0,0,0,0,0,0]

dp[0][0] = A[0]
dp[0][1] = -A[0]

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

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math

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



ans = 0

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

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):
  if t_int[i] < 0:
    count -= t_int[i]
    x += 1
  else:
    count += t_int[i]
if x % 2 == 0:
  count += 2 * t_int[N-1]
else:
  count -= 2 * t_int[N-1]
print(float(count))

Submission status: Wrong Answer

Solution code:
A=int(input())
B=[_ for _ in map(int,input().split())]
"マイナスの数を求める"
minus=0
for i in B:
  if i<0:
    minus=+1
"マイナスの数が偶数の場合、絶対値Bを全部足す"
ans=0
if minus%2==0:
  for i in B:
    if i<0:
      ans=+(-1)*i
    else:
      ans+=i
  print(ans)

else:
  S=0
  for i in range(A):
    B[i]=abs(B[i])
  
  for i in B:
    S+=i
  if (S-2*min(B))<=0:
    print(0)
  else:
    print(S-2*min(B))

Submission status: Wrong Answer

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

    if i==n-2 and b[i]+b[i+1]<-b[i]-b[i+1]:
        b[i]*=-1
        b[i+1]*=-1
    elif b[i]<0:
        b[i]*=-1
        b[i+1]*=-1

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

Submission status: Wrong Answer

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

sum = 0
for i in range(0,N-1):
  x = A[i]
  y = A[i+1]
  if x > 0:
    sum += A[i]
    continue
  
  if x > 0 and y > 0:
    sum += x
    continue
    
  if x < 0 and y < 0:
    sum += x * (-1)
    A[i+1] = y * (-1)
    continue
  
  if x < 0:
    x = x * (-1)
    if x > y:
      sum += x
      A[i+1] = y * (-1)
    else:
      sum += x * (-1)
sum += A[-1]
print(sum)

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
sei=[0]*n
mai=0
zero=0
pr=0
for i in range(n):
  sei[i]=max(a[i],-a[i])
  pr+=sei[i]
  if a[i]<0:
    mai +=1
  elif a[i]==0:
    zero+=1
  else:
    pass
#ゼロと負の数を数える
if mai%2==0 or zero >=1:
    print(pr)
else:
    print(pr-min(sei))

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):
  if t_int[i] < 0:
    count -= t_int[i]
    x += 1
  else:
    count += t_int[i]
if x % 2 == 0:
  count += 2 * t_int[N-1]
else:
  count -= 2 * t_int[N-1]
print(int(count))

Submission status: Wrong Answer

Solution code:

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

B = False
if all(A):
    print("not contain")
    M = 0
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
            M += 1
    print(M)
    if M%2 == 0:
        B = True
    else:
        B = False

else:
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
    B = True

if B:
    print(sum(A))
else:
    print("else")
    print(min(A))
    print(str(sum(A)-2*min(A)))

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
f = 0
for i in range(len(A)-1):
  if f ==0 :
    if A[i] < 0 and A[i+1] < 0:
        A[i] = A[i] * -1
        A[i+1] = A[i+1] * -1
        f = 1
    elif A[i] < 0 :
        if A[i] + A[i+1] < 0:
            A[i] = A[i] * -1
            A[i+1] = A[i+1] * -1
            f = 1
  else:
      f = 0

print(sum(A))

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 c[i] < 0:
      c[i] = v[i]*(-1)
      c[i+1] = v[i+1]*(-1)
  cn = sum(c)
  if mn == cn:
    flag = False
  elif cn > mn:
    mn = cn
  
print(mn)

Submission status: Wrong Answer

Solution code:
import sys
import numpy as np

N = int(input())

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

if np.sum(A==0) != 0:
# Aに0が含まれる場合
    # 最後に0が出てくる場所
    z = np.max(np.where(A==0))
    B = A[z:N]
    if np.sum(B < 0)%2 ==0:
        print(np.abs(A).sum())
    else:
        print(np.abs(A[0:N-1]).sum() - abs(A[-1]))

# Aに0が含まれない場合
else:
    if np.sum(A < 0)%2 ==0:
        print(np.abs(A).sum())
    else:
        print(np.abs(A[0:N-1]).sum() - abs(A[-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 and a[i+1] <= 0:
        a[i] = -a[i]
        a[i+1] = -a[i+1]
        
for i in range(n-2):
    if a[i] < 0 and a[i+1] >= 0 and a[i+2] <= 0:
        a[i] = -a[i]
        a[i+2] = -a[i+2]
        
for i in range(n-1):
    if a[i] < 0:
        if a[i]+a[i+1] < -(a[i]+a[i+1]):
            a[i] = -a[i]
            a[i+1] = -a[i+1]

if a[n-2]+a[n-1] < -(a[n-2]+a[n-1]):
    a[n-2] = -a[n-2]
    a[n-1] = -a[n-1]

print(sum(a))

Submission status: Wrong Answer

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

negcnt = 0
zcnt = 0
for k in a:
    if k < 0:
        negcnt += 1
    elif k == 0:
        zcnt += 1

ans = 0
if (negcnt + zcnt) % 2 == 0:
    for k in a:
        ans += abs(k)
    print(ans)
else:
    negmin = -1 * (10**9+1)
    for k in a:
        if k > negmin:
            negmin = k
    for k in a:
        ans += abs(k)
    print(ans - 2*k)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int, input().split()))
a = l.copy()
ans = 0
for i in range(n-1):
    #print(a)
    #iがプラス
    if a[i] > 0:
        #i+1がマイナス
        if a[i] < 0:
            if abs(a[i]) <= abs(a[i+1]):
                a[i] = a[i] * -1
                a[i + 1] = a[i+1] * -1
                #print(a)
                #print(sum(a))
    #iが0
    elif a[i] == 0:
        if a[i+1] <= 0:
            a[i] = a[i] * -1
            a[i + 1] = a[i+1] * -1
            #print(a)
            #print(sum(a))
    # iがマイナス
    else:
        #i+1がプラス
        if a[i+1] > 0:
            if abs(a[i]) >= abs(a[i+1]):
                a[i] = a[i] * -1
                a[i + 1] = a[i+1] * -1
                #print(a)
                #print(sum(a))
        elif a[i + 1] == 0:
            a[i] = a[i] * -1
            a[i + 1] = a[i+1] * -1
            #print(a)
            #print(sum(a))                
        else:
            a[i] = a[i] * -1
            a[i + 1] = a[i+1] * -1
            #print(a)
            #print(sum(a))
print(sum(a))

Submission status: Wrong Answer

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

count = 0

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

if count%2 == 1:
  ans = sum(A)
else:
  ans = sum(A) - 2*min(A)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split(" ")))
for i in range(n-1):
    if a[i] < 0 and a[i+1] < 0:
        a[i] = a[i]*-1
        a[i+1] = a[i+1]*-1
    elif a[i] >= a[i+1]:
        continue
    elif abs(a[i]) >= abs(a[i+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 = [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:
from fractions import gcd

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

if n == 2:
    print(max(*as_))
else:
    set_ = set()
    gcd_all = as_.pop()
    for a in as_:
        set_ = set(gcd(s, a) for s in set_)
        set_.add(gcd_all)
        gcd_all = gcd(gcd_all, a)

    print(max(set_))

Submission status: Wrong Answer

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

minus_count = 0
plus_list = []
for x in n_list:
  if x < 0:
    minus_count += 1
  plus_list.append(abs(x))
    
if x % 2 == 0: #even
  print(sum(plus_list))
else:
  print(sum(plus_list) - 2 * min(plus_list))

Submission status: Wrong Answer

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

print(max(sum(a),sum(b)))

Submission status: Wrong Answer

Solution code:
A=int(input())
B=[_ for _ in map(int,input().split())]
"マイナスの数を求める"
minus=0
for i in B:
  if i<0:
    minus=+1
"マイナスの数が偶数の場合、絶対値Bを全部足す"
ans=0
if minus%2==0:
  for i in B:
    ans=+abs(i)
  print(ans)

else:
  S=0
  for i in range(A):
    B[i]=abs(B[i])
  
  for i in B:
    S+=i
  if (S-2*min(B))<0:
    print(0)
  else:
    print(S-2*min(B))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import math
#最大公約数gcd
N = int(input())
A = list(map(int, input().split()))



ans = 0

for index in range(N*N):
    
    for index in range(N-1):
        
        if A[index] <=0 and A[index+1]<=0:
            A[index]*=-1
            A[index+1]*=-1
            
        if A[index]<=0 and A[index+1]>=0:
            A[index]*=-1
            A[index+1]*=-1
        

print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(B))
else:
  print(sum(B[1 :] - B[0]))

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) - 1):
        if 0 == A[i] and 0 > A[i + 1]:
            A[i + 1] *= -1
            continue
        if 0 > A[i]:
            A[i] *= -1
            A[i + 1] *= -1
        B += A[i]
    print(B + A[-1])


main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

if n == 2:
    print(max(as_))
else:
    set_ = set()
    gcd_all = as_.pop()
    for a in as_:
        set_ = set(gcd(s, a) for s in set_)
        set_.add(gcd_all)
        gcd_all = gcd(gcd_all, a)

    print(max(set_))