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

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()]
 
a_abs_list = [abs(a) for a in a_list]
sum_a_abs_list = sum(a_abs_list)
print(sum_a_abs_list)

Submission status: Wrong Answer

Solution code:
n = int(input())
w = input().split(" ")

a = []
m = 0
k = False
for i in range(n):
    a.append(int(w[i]))
    if a[i] < 0:
        a[i] *= -1
        k = not (k)
    if i == 1:
        m = a[i]
    if a[i] < m:
        m = a[i]

sum = sum(a)
if k:
    sum -= m
print(sum)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
r = []
res = 0

for i in l:
    res+= abs(i)
    r.append(abs(i))
else:
    if n%2==0:
        print(res)
    else:
        print(res-min(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[i+1]+A[i],m[i+3]-A[i]+A[i+1]-A[i+2],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],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())

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]

#print(plus,minus)
if len(A)==1:
    print(A[0])
elif len(minus) % 2 == 0:
    print(sum(plus)-sum(minus))

else:
    plus.sort()
    if plus == []:
        r = -1*minus[0]
    else:
        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()))
c=0
k=0
for i in range(0,n):
  if a[i]<0:
    c=c+1
  k=k+abs(a[i])
  a[i]=abs(a[i])
a.sort()
if c%2==1:
  k=k-a[0]
  print(k)
else:
  print(k)

Submission status: Wrong Answer

Solution code:

N = int(input())
a =list(map(int, input().split()))
def solve(a, ignore=-1):
    ret = 0
    for i in range(len(a)-1):
        if a[i] < 0:
            a[i] *= -1
            a[i+1] *= -1
        elif a[i] >= 0 and i == ignore:
            a[i] *= -1
            a[i+1] *= -1
        ret += a[i]
#         print(a[i], ret)
    ret += a[-1]
    return ret

abs_list = list(map(abs, a))
test = sorted(enumerate(abs_list), key=lambda x:x[1])
print(max(solve(a), solve(a[::-1]), solve(a[::-1], test[0][0])))

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]

#print(plus,minus)
if len(A)==1:
    print(A[0])
elif len(minus) % 2 == 0:
    print(sum(plus)-sum(minus))

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

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
r = []
res = 0

for i in l:
    res+= abs(i)
    r.append(abs(i))
else:
    if 0 in l:
        print(res)
    else:
        print(res-min(r))

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
c=0
for i in a:
    if i < 0:
        c+=1

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

if c%2 == 0:
    print(b)
    exit()

b.sort()
print(sum(b)-2*b[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a


n = int(input())  # 数値
a = list(map(int, input().split()))  # 複数数値をリストに格納

li = []
for i in range(n - 1):
    li.append(gcd(a[i], a[i + 1]))

    if (n - 2) != i and n != 2:
        li.append(gcd(a[i], a[i + 2]))

if(n == 2):
    print(max(a[0], a[1]))
elif (n == 3):
    li.sort()
    print(li[2])
elif n == 4:
    mae1 = li[0]
    mae2 = li[1]
    mae3 = li[2]
    mae4 = li[3]
    usiro1 = li[-1]
    usiro2 = li[-2]
    usiro3 = li[-3]
    usiro4 = li[-4]
    li.sort()

    if (li[0] == mae1 and li[1] == mae2) or (li[0] == usiro1 and li[1] == usiro2):
        print(li[2])
    else:
        print(li[3])
else:
    mae1 = li[0]
    mae2 = li[1]
    mae3 = li[2]
    mae4 = li[3]
    usiro1 = li[-1]
    usiro2 = li[-2]
    usiro3 = li[-3]
    usiro4 = li[-4]

    li.sort()

    if (li[0] == mae1 and li[1] == mae3 and li[2] == mae4) or (li[0] == usiro1 and li[1] == usiro3 and li[2] == usiro4):
        print(li[3])
    elif (li[0] == mae2 and li[0] == mae1) or (li[0] == usiro2 and li[0] == usiro1):
        print(li[2])
    else:
        print(li[4])

Submission status: Wrong Answer

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


a = As[0]
b = sum(As[1:-1])
c = As[-1]


num1 = (abs(a) + abs(b) -c)
num2 = (abs(b) + abs(c) -a)

print(max([num1, num2]))

Submission status: Wrong Answer

Solution code:

N = int(input())
a =list(map(int, input().split()))
def solve(a, ignore=-1):
    ret = 0
    for i in range(len(a)-1):
        if a[i] < 0 and i != ignore:
            a[i] *= -1
            a[i+1] *= -1
        ret += a[i]
#         print(a[i], ret)
    ret += a[-1]
    return ret

abs_list = list(map(abs, a))
test = sorted(enumerate(abs_list), key=lambda x:x[1])
print(max(solve(a), solve(a[::-1]), solve(a[::-1], test[0][0])))

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[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],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())
l = list(map(int,input().split()))
res= 0
for i in l:
  res+= abs(i)
else:
  print(res) if l[-1]>0 else print(res+2*l[-1])

Submission status: Wrong Answer

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

ans = 0
count = 0
for i in range(n-1):
    if aa[i] < 0:
        count += 1
        aa[i+1] *= -1
    ans += abs(aa[i])
ans += aa[n-1]
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=0
for i in range(N-1):
    if (A[i+1]>=0 and A[i]>=0):
        continue
    elif(A[i+1]<=0 and A[i]>=0):
        continue
    else:
        A[i]=-A[i]
        A[i+1]=-A[i+1]
    ans=max(ans,sum(A))
print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while b > 0:
        a, b = b, a % b
    return a


n = int(input())  # 数値
a = list(map(int, input().split()))  # 複数数値をリストに格納

li = []
for i in range(n - 1):
    li.append(gcd(a[i], a[i + 1]))

    if (n - 2) != i and n != 2:
        li.append(gcd(a[i], a[i + 2]))

if(n == 2):
    print(max(a[0], a[1]))
elif (n == 3):
    li.sort()
    print(li[2])

elif n == 4:
    mae1 = li[0]
    mae2 = li[1]
    mae3 = li[2]
    mae4 = li[3]
    usiro1 = li[-1]
    usiro2 = li[-2]
    usiro3 = li[-3]
    usiro4 = li[-4]
    li.sort()

    if (li[0] == mae1 and li[1] == mae2) or (li[0] == usiro1 and li[1] == usiro2):
        print(li[2])
    else:
        print(li[3])


else:
    mae1 = li[0]
    mae2 = li[1]
    mae3 = li[2]
    mae4 = li[3]
    usiro1 = li[-1]
    usiro2 = li[-2]
    usiro3 = li[-3]
    usiro4 = li[-4]

    li.sort()

    if (li[0] == mae1 and li[1] == mae3 and li[2] == mae4) or (li[0] == usiro1 and li[1] == usiro3 and li[2] == usiro4):
        print(li[3])
    elif (li[0] == mae2 and li[0] == mae1) or (li[0] == usiro2 and li[0] == usiro1):
        print(li[2])
    else:
        print(li[4])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans =0
for i in range(n):
  ans += abs(a[i])
  
print(ans)

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)
#
i = 0
while i < n:
    while i < n and a[i] >= 0:
        i += 1
    j = i
    idx = -1
    mn = float('inf')
    while j < n and a[j] <= 0:
        if abs(a[j]) < mn:
            mn = abs(a[j])
            idx = j
        j += 1
    if (i - j + 1) % 2 == 0:
        for k in range(i, j):
            a[k] = abs(a[k])
    else:
        for k in range(i, j):
            if k != idx:
                a[k] = abs(a[k])
    i = j
    # print(i)


print(sum(a))

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]

    # B = [0 -?]のときだけ例外
    if B.shape[0] == 2 and B[-1] < 0:
        sign = 1
    elif 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:
A=int(input())
B=[_ for _ in map(int,input().split())]

minus=0
for i in B:
  if i<0:
    minus=+1

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 -*-

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

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

print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(int(n) for n in input().split())
b = [0] * n
num_of_minus = 0
sum2 = 0

for i in range(n):
    if a[i] < 0:
        num_of_minus += 1
        b[i] = int(a[i] * (-1))
    else:
        b[i] = int(a[i])

if num_of_minus % 2 == 0:
    ans = sum(b)
else:
    ans = sum(b) - min(b)

print(ans)

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
a=b[::-1]
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:
import numpy as np
N = int(input())
A = [int(i) for i in input().split()]

abs_A = list(map(abs, A))
if(N%2!=0):
    print(int(np.sum(abs_A)))
else:
    print(int(np.sum(abs_A) - (min(abs_A)*2)))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
for i in range(N-2):
  a,b,c = A[i],A[i+1],A[i+2]
  if a<0 and b>0 and c<0:
    A[i]=-A[i]
    A[i+1]=A[i+1]
    A[i+2]=-A[i+2]
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):
  a,b = A[i],A[i+1]
  if a+b<=-a-b:
    A[i]=-A[i]
    A[i+1]=-A[i+1]
print(sum(A))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
f = True
num = 0
rex = 0
x = 0
mi = 0
ans = 0
left = 0
right = 0
for i in range(n):
    if int(a[i]) >=0:
        ans = ans + int(a[i])
        if f == False:
            if num%2 == 0:
                ans = ans - x
            else:
                ans = max(ans -x + mi,ans-x-int(rex),ans-x-int(a[i])*2)
            f = True
            num = 0
            x = 0
            mi = 0
    else:
        rex = a[i-1]
        x = x + int(a[i])
        f = False
        if mi > x:
            mi = x
        num  = num + 1

if num%2 == 0:
    ans = ans - x
else:
    ans = ans -x + mi
f = True
num = 0
x = 0
mi = 0
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
for i in range(N-1):
    if A[i] + A[i+1] < -1 * (A[i] + A[i+1]):
        A[i] = A[i] * -1
        A[i+1] = A[i+1]
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[i+3]-A[i]+A[i+1]-A[i+2],m[i+3]+A[i]-A[i+1]+A[i+2],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],M[i-3]+A[i]-A[i-1]+A[i-2],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())
a=list(map(int,input().split()))
f=0
m=0
for i in range(2):
  if len(a[i::2])%2==1:
    s=sorted([abs(c)for c in a[i::2]])[::-1]
    f+=sum(s[:-1])
    m+=s[-1]
  else:
    f+=sum([abs(c)for c in a[i::2]])
if len(a[::2])%2 and len(a[1::2]):
  c=[]
  for i in range(2):
    l=sorted([abs(c)for c in a[i::2]])[::-1]
    t=l[-1]if l[-1]in a[i::2]else -l[-1]
    c.append([t,a.index(t)])
  if abs(c[0][1]-c[1][1])==1:
    m-=max(abs(c[0][0]),abs(c[1][0]))*2
print(f-m)

Submission status: Wrong Answer

Solution code:
n = int(input())
l = list(map(int,input().split()))
res= 0
for i in l:
  res+= abs(i)
else:
  print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
for i in range(n-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().rstrip())
A = list(map(int, input().rstrip().split()))
_A = A
for i in range(len(A)):
  if i == len(A) - 2:
    break
  if A[i] >= 0 and A[i+1] >= 0:
    pass
  else:
    s = _A[i] + _A[i+1]
    if s < -s:
      _A[i] = -1 * A[i]
      _A[i+1] = -1 * A[i+1]
print(sum(_A))

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ary = []

old_idx = 0
summ = 0
for i in range(len(A)-1):
  if A[i] >= 0 and A[i+1] >= 0:
    A_tmp = np.array(A[old_idx:i+1])
    if len(np.where(A_tmp<0)[0])//2 == 0:
      summ += np.abs(A_tmp).sum()
    else:
      summ += np.abs(A_tmp).sum() - np.abs(A_tmp).min()*2
    old_idx = i+1

if old_idx < len(A):
    A_tmp = np.array(A[old_idx:])
    if len(np.where(A_tmp<0)[0])//2 == 0:
      summ += np.abs(A_tmp).sum()
    else:
      summ += np.abs(A_tmp).sum() - np.abs(A_tmp).min()*2
  
print(summ)

Submission status: Wrong Answer

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

As.sort()

for i in range(0, len(As)-2):
  if As[i] < As[i+1] + As[i+2]:
    As[i] = -As[i]
    As[i+1] = -As[i+1]

print(sum(As))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = np.absolute(A)
C = np.sign(A)
x = sum(B)
y = sum(C)
if y % 2 == 0:
  print(x)
z = x - min(B) * 2
print(z)

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 :
    print(A[i])
    A[i] *= -1
    A[i + 1] *= -1
  elif i == N - 2 and A[i] == 0:
    A[i + 1] *= -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[i+3]-A[i]+A[i+1]-A[i+2],m[i+3]+A[i]-A[i+1]+A[i+2],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],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())
a = list(map(int,input().split()))
l=[]
ans = sum(a)
for i in range(n):
    if a[i] <0:
        a[i] *=-1
b = sum(a)
for i in range(n):
    ans=max(ans,b-2*a[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

ary = []

old_idx = 0
summ = 0
for i in range(len(A)-1):
  if A[i] > 0 and A[i+1] > 0:
    A_tmp = np.array(A[old_idx:i+1])
    if len(np.where(A_tmp<0)[0])//2 == 0:
      summ += np.abs(A_tmp).sum()
    else:
      summ += np.abs(A_tmp).sum() - np.abs(A_tmp).min()*2
    old_idx = i+1

if old_idx < len(A):
    A_tmp = np.array(A[old_idx:])
    if len(np.where(A_tmp<0)[0])//2 == 0:
      summ += np.abs(A_tmp).sum()
    else:
      summ += np.abs(A_tmp).sum() - np.abs(A_tmp).min()*2
  
print(summ)

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

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

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

Submission status: Wrong Answer

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

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



if 0 in A:
    
   # print (A)
    print (sum(list(map(abs, A))))
    
    
    
else:
    
    for index in range(N-1):
       # print(A)
        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()))

prev = 0
while True:
	alldone = True
	exp = 9999999999999
	ai = 0
	for i in range(n-1) :
		e = (a[i] + a[i+1])
		if e < 0 :
			e *= -1
			if exp > e:
				ai = i
				exp = e
			alldone = False

	if alldone == False:
		a[ai] *= -1
		a[ai+1] *= -1
	else :
		break

print (sum(a))

Submission status: Wrong Answer

Solution code:
n = int(input())
lis = list(map(int,input().split()))
numm = 0
ans = 0
nu = 10 ** 9
for num in lis:
  nu = min(nu,num)
  ans += abs(num)
  if num < 0:
    numm += 1
if numm % 2 == 1:
  print(ans-nu*2)
else:
  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]

#print(plus,minus)
if len(A)==1:
    print(A[0])
elif len(minus) % 2 == 0:
    print(sum(plus)-sum(minus))

else:
    plus.sort()
    if plus == []:
        r = -1*minus[-1]
    else:
        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()))
a2 = [(i,a[i]) for i in range(n-1)]
a2.sort(key = lambda x:-abs(x[1]))
total = 0

for i in range(n-1):
  j = a2[i][0]
  if (- a[j] - a[j+1]) > (a[j] + a[j+1]) or (((- a[j] - a[j+1]) == (a[j] + a[j+1])) and a[j] < 0):
    a[j] = -a[j]
    a[j+1] = - a[j+1]
for i in range(n):
	total += a[i]
print(total)

Submission status: Wrong Answer

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

abs_a = [abs(i) for i in a]
a = len([i for i in a if i < 0 or i == 0])
init = [i for i in abs_a if i != 0]
if a%2 == 0:
    print(sum(abs_a))
else:
    abs_a_min = min(init)
    print(sum(abs_a)-abs_a_min*2)

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
li = na()
if n == 2:
    print(abs(sum(li)))
else:
    for i in range(n-2):
        if li[i] < 0:
            if li[i+1] < 0:
                if li[i+2] > 0:
                    li[i] *= (-1)
                    li[i + 1] *= (-1)
                else:
                     if li[i] < li[i+2]:
                         li[i] *= (-1)
                         li[i + 1] *= (-1)
                     else:
                         li[i + 1] *= (-1)
                         li[i + 2] *= (-1)
            else:
                if li[i+2] < 0:
                    li[i] *= (-1)
                    li[i + 2] *= (-1)
                else:
                    if abs(li[i]) > abs(li[i+1]):
                        li[i] *= (-1)
                        li[i + 1] *= (-1)
        else:
            if li[i+1] <0:
                if li[i+2] < 0:
                    li[i + 1] *= (-1)
                    li[i + 2] *= (-1)
                else:
                    li[i + 1] *= (-1)
            else:
                if li[i+2] < 0:
                    if abs(li[i+2]) > abs(li[i+1]):
                        li[i+1] *= (-1)
                        li[i + 2] *= (-1)
print(sum(li))

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 div1 - div2 == 1 or (div2 == 0 and N % 2 != 0):
    print(sum(A) - min(A_2)*2)

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

else:
    print(sum(A))

Submission status: Wrong Answer

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
li = na()
if n == 2:
    print(abs(sum(li)))
else:
    for i in range(n-2):
        if li[i] < 0:
            if li[i+1] < 0:
                if li[i+2] > 0:
                    li[i] *= (-1)
                    li[i + 1] *= (-1)
                else:
                     if li[i] < li[i+2]:
                         li[i] *= (-1)
                         li[i + 1] *= (-1)
                     else:
                         li[i + 1] *= (-1)
                         li[i + 2] *= (-1)
            else:
                if li[i+2] < 0:
                    li[i] *= (-1)
                    li[i + 2] *= (-1)
                else:
                    if abs(li[i]) > abs(li[i+1]):
                        li[i] *= (-1)
                        li[i + 1] *= (-1)
        else:
            if li[i+1] <0:
                if li[i+2] < 0:
                    li[i + 1] *= (-1)
                    li[i + 2] *= (-1)
                else:
                    li[i + 1] *= (-1)
            else:
                if li[i+2] < 0:
                    if abs(li[i+2]) > abs(li[i+1]):
                        li[i+1] *= (-1)
                        li[i + 2] *= (-1)

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())
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 :
        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()))
a2 = [(i,a[i]) for i in range(n-1)]
a2.sort(key = lambda x:-abs(x[1]))
total = 0
print(a2)

for i in range(n-1):
  j = a2[i][0]
  if (- a[j] - a[j+1]) > (a[j] + a[j+1]) or (((- a[j] - a[j+1]) == (a[j] + a[j+1])) and a[j] < 0):
    a[j] = -a[j]
    a[j+1] = - a[j+1]
for i in range(n):
	total += a[i]
print(total)

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[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],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())
a=list(map(int,input().split()))
count=0 
saidaiti=0
while True:
    saidaiti=saidaiti+abs(a[count])
    count=count+1
    if count==n:
        break
print(saidaiti)

Submission status: Wrong Answer

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

sum = 0
minus = 0
minn = 10 ** 10
for a in A:
    b = abs(a)
    sum += b
    if b < minn:
        minn = b
    if a < 0:
        minus += 1

print(sum)
print(minn)
print(minus)

if minus % 2 == 0:
    print(sum)
else:
    print(sum - 2*minn)