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 numpy as np
N =int(raw_input())
A =map(int ,raw_input().split())
B =np.abs(A)
B = np.array(B,dtype=np.int64)
C = min(B)
D = (sum(B))
E = D - C
k = 0
print E

Submission status: Wrong Answer

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

zeroFlag = False
kosuu = 0
ans = 0
for i in range(n):
    if(a[i]<0):
        kosuu += 1
    elif(a[i]==0):
        zeroFlag = True
    ans += abs(a[i])

if(zeroFlag):
    print(ans)
else:
    if(kosuu%2==0):
        print(ans)
    else:
        ans -= 2*abs(a[n-1])
        print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = [int(i) for i in input().split()] 
Acnt = 0
for i in range(N):
	if A[i] < 0:
		Acnt += 1

if Acnt % 2 == 1:
	print(np.sum(np.abs(A)) - np.min(np.abs(A))*2)
else:
	print(np.sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A_1 = A.copy()

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

if (A[N - 1] < 0) & (A[N - 1] + A[N - 2] < 0):
    A[N - 1] *= -1
    A[N - 2] *= -1

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

if (A_1[N - 1] < 0) & (A_1[N - 1] + A_1[N - 2] < 0):
    A_1[N - 1] *= -1
    A_1[N - 2] *= -1

print(max(sum(A), sum(A_1)))

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = int(stdin.readline().rstrip())
an = list(map(int, input().split()))

m = []
p = []
z = 0

for i in range(n):
  if(an[i]<0):
    m.append(an[i])
  if(an[i]>0):
    p.append(an[i])
  if(an[i]==0):
    z=1

if ( z==1 ):
  ans = sum(p) - sum(m)
elif ( len(m) == 0):
    ans = sum(p)
else:
  if ( len(p) == 0):
    ans = -sum(m)
  else:
    if ( len(m)%2 == 0):
      ans = sum(p) - sum(m)
    else:
      minm = 0
      if ( min(p) < (-max(m)) ):
        minm = min(p)
      else:
        minm = -max(m)
      ans  = sum(p) - sum(m) - (minm*2)

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
f=0
for i in range(n-1):
  if a[i]<=0 and a[i+1]<=0 and f==0:
    a[i]=a[i]*(-1)
    a[i+1]=a[i+1]*(-1)
    f=1
  elif a[i]*a[i+1]<=0:
    a[i]=max(a[i]+a[i+1],-a[i+1]-a[i])
    a[i+1]=0
    f=0
  else:
    f=0
s=0
for i in range(n):
  s=s+a[i]
print(s)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    *A, = map(int, input().split())
    minuscount = 0
    A.sort(key=abs)
    for i in A:
        if i < 0:
            minuscount += 1
    maxi = 0
    for i in A:
        maxi += abs(i)
    if minuscount % 2 == 0:
        print(maxi)
    else:
        print(maxi - 2*A[0])
main()

Submission status: Wrong Answer

Solution code:
n=int(input())  #数値入力 「N」だけの入力のとき
c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき

v = 0

for i in range(0, n-1):
  idx = c.index(min(c))
  c[idx] = -1*c[idx]

print(sum(c))

Submission status: Wrong Answer

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

for i in range(N):
    if nums[i] < 0 and i + 1 < N:
        if nums[i + 1] < 0 or (nums[i + 1] >= 0 and (-nums[i] - nums[i + 1] > nums[i] + nums[i + 1] or (i + 2 < N and -nums[i] + nums[i + 1] - nums[i + 2] > nums[i] + nums[i + 1] + nums[i + 2]))):
            nums[i] = -nums[i]
            nums[i + 1] = -nums[i + 1]

print(sum(nums))

Submission status: Wrong Answer

Solution code:
import numpy as np
N =int(raw_input())
A =map(int ,raw_input().split())
B =np.abs(A)
B = np.array(B,dtype=np.int64)
C = min(B)
D = (sum(B))
E = D - C
k = 0
print D

Submission status: Wrong Answer

Solution code:
import numpy as np

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

b = np.sort(np.abs(a))
c = np.sum(b < 0)

if c % 2 == 0:
  total = np.sum(b)
else:
  total = np.sum(b[1:]) - b[0]

print(total)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    if pos == []:
      print(-sum(neg[:-1]))
      exit()
    else:
      b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

n_minus = 0
n_zero = 0
for x in a:
  if x == 0:
    n_zero += 1
  elif x < 0:
    n_minus += 1
r = 0
for x in a:
    r += abs(x)
if n_zero == 0 and n_minus % 2 == 1:
  r -= min(abs(a[0]), abs(a[-1])) * 2
print(r)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(n):
	if a[i] < 0:
		c += 1
	elif a[i] >0:
		pass
	else:
		for i in range(n):
			s += abs(a[i])
		print(s)
		quit()

if c%2 == 0:
	for i in range(n):
		s += abs(a[i])
else:
	a.sort(key = lambda x: abs(x))
	for i in range(1,n):
		s += abs(a[i])
	s -= a[0]
print(s)

Submission status: Wrong Answer

Solution code:
import math
from functools import reduce
def mkt(a, b):
    while b:
        a, b = b, a % b
    return a
def gcd_list(numbers):
    return reduce(mkt, numbers)
n=int(input())
a=list(map(int,input().split()))
max=1
for i in range(n):
    q=gcd_list(a[:i]+a[i+1:])
    if q>max:
        max=q
print(max)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

cnt = 0
for i in range(n):
    if a[i] < 0:
       cnt += 1

b = 0
for j in range(n):
    b += abs(a[j])

if cnt % 2 != 0:
        b -= abs(min(a))

print(b)

Submission status: Wrong Answer

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

for i in range(N-1):
    ai = lstA[i]
    ai1 = lstA[i+1]
    # print(ai, ai1)
    if ai < 0:
        lstA[i] = -ai
        lstA[i+1] = -ai1
    # print(lstA[i], lstA[i+1])
else:
    if (lstA[N-2] >= 0 and lstA[N-1] >= 0) or (lstA[N-2] < 0 and lstA[N-1] < 0):
        lstA[N-2] = abs(lstA[N-2])
        lstA[N-1] = abs(lstA[N-1])
    elif (lstA[N-2] >= 0 and lstA[N-1] < 0):
        if abs(lstA[N-2]) < abs(lstA[N-1]):
            lstA[N-2] = -lstA[N-2]
            lstA[N-1] = -lstA[N-1]
    elif (lstA[N-2] < 0 and lstA[N-1] >= 0):
        if abs(lstA[N-2]) > abs(lstA[N-1]):
            lstA[N-2] = -lstA[N-2]
            lstA[N-1] = -lstA[N-1]
# print(lstA)
ans = sum(lstA)
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N =int(raw_input())
A =map(int ,raw_input().split())
B =np.abs(A)
B = np.array(B,dtype=np.int64)
C = min(B)
D = (sum(B))
E = D - C
k = 0
for i in range(N):
    if A[i]<0:
        k = k+1
if k%2 == 0:
    print D
else:
    print E

Submission status: Wrong Answer

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

cnt = 0
for i in range(n):
    if a[i] < 0:
       cnt += 1

b = 0
for j in range(n):
    b += abs(a[j])
    if cnt % 2 != 0:
        b -= abs(min(a))

print(b)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = 10**9
cn = 0
s = 0
for x in input().split():
    y = int(x)
    z = abs(y)
    if y < 0:
        cn += 1
        print("cn+=1",y,cn)
    s += z
    print("sum:",s)
    if m > z:
        m = z
        print("m:updated",m)
if cn%2 == 0:
    print(s)
else:
    print(s - m*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N=int(input())
As=list(map(int, input().split()))
for i in range(N - 1):
    if As[i] > 0 and As[i+1]>0:
        pass
    elif As[i] <0 and As[i+1]<0:
        As[i]=-1*As[i]
        As[i+1] = -As[i+1]
    elif As[i]<0:
        As[i]=-1*As[i]
        As[i+1] = -As[i+1]
    
As_tot=np.sum(np.array(As))
print(As_tot)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    if pos == []:
      b=0
    else:
      b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A = [int(i) for i in input().split()] 
Acnt = 0
for i in range(N):
	if A[i] < 0:
		Acnt += 1
res = np.sum(np.abs(A)) - np.min(np.abs(A))*2
print(res)

Submission status: Wrong Answer

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

N = int(input())
A = input().split()

sum = 0

for i in range(0, N - 1):

    a = int(A[i])
    a_next = int(A[i + 1])

    if a < 0:
        # 操作
        A[i] = a * -1
        A[i + 1] = a_next * -1

for i in range(N):
    sum += int(A[i])

print(sum)

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([abs(i) for i in 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]
    A = A[:MP-1] + B
    print(sum(A))

Submission status: Wrong Answer

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

for i in range(N-1):
    if A[i] < 0:
        A[i] = A[i] * -1
        A[i+1] = A[i+1] * -1
    
a = max(A[-1] + A[-2], -1 * A[-1] + -1 * A[-2])
del A[-1]
del A[-1]
if A == []:
    print(a)
else:
    print(sum(A) + a)

Submission status: Wrong Answer

Solution code:
n = int(input())
v = list(map(int, input().split()))
if len(v) == 1:
    print(v[0])
else:
    for i in range(1, len(v)):
        if v[i-1] < 0:
            if (abs(v[i-1]) > abs(v[i])) or (v[i-1] < 0 and v[i]<0):
                v[i-1] *= -1
                v[i] *= -1
    print(sum(v))

Submission status: Wrong Answer

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

b_list = []

for i in range(N-1):
    a = a_list[i]
    if i == N -2:
        a1 = a_list[-1]
        if a >= 0 and a1 >= 0:
            b_list.append(a)
            b_list.append(a1)
        elif a <= 0 and a1 <= 0:
            b_list.append(-a)
            b_list.append(-a1)
        elif abs(a) > abs(a1):
            b_list.append(abs(a))
            b_list.append(-abs(a1))
        else:
            b_list.append(-abs(a))
            b_list.append(abs(a1))
    else:
        if a < 0:
            b_list.append(abs(a))
            a_list[i+1] = a_list[i+1] * (-1)
        else:
            b_list.append(a)
   
print(sum(b_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))  # �������l�����X�g�Ɋi�[
ans = 0

a.sort()
num = 0

for i in range(n):
    if a[i] < 0:
        num += 1
        ans -= a[i]
    else:
        if num % 2 == 0:
            ans += a[i]
        else:
            ans -= min(-a[num-1], a[num])
            num = 2

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if n%2==0: print(sum(abs(a)))
else: print(sum(abs(a))-2*abs(a[(np.argmin(abs(a)))]))

Submission status: Wrong Answer

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

def operate(A,i):
  if A[i] <= 0 and - (A[i] + A[i + 1]) >= 0:
    A[i] = - A[i]
    A[i + 1] = - A[i + 1]
  else:
    pass
  return

for i in range(len(A) - 1):
  operate(A,i)

print(sum(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(abs, A))
print(sum(B))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
pos = []
neg = []
cnt = 0
for i in a:
    if i > 0:
        pos.append(i)
    elif i < 0:
        neg.append(i)
    else:
        cnt += 1
if cnt != 0 or len(neg) % 2 == 0:
    print(sum(pos) - sum(neg))
else:
    pos = sorted(pos)
    neg = sorted(neg)
    pos.append(0)
    neg = [0]+neg
    b = min(pos)
    c = -max(neg)
    pos = pos[1:]
    neg = neg[:-1]
    r = sum(pos) - sum(neg)
    m = max(b - c, c - b)
    print(r + m)

Submission status: Wrong Answer

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

A_1 = A.copy()

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

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

print(max(sum(A), sum(A_1)))

Submission status: Wrong Answer

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

b_list = []

for i in range(N-1):
    a = a_list[i]
    if i == N -2:
        a1 = a_list[-1]
        if a >= 0 and a1 >= 0:
            b_list.append(a)
            b_list.append(a1)
        elif a <= 0 and a1 <= 0:
            b_list.append(-a)
            b_list.append(-a1)
        elif abs(a) > abs(a1):
            b_list.append(-a)
            b_list.append(a1)
        else:
            b_list.append(-a)
            b_list.append(a1)
    else:
        if a < 0:
            b_list.append(abs(a))
            a_list[i+1] = a_list[i+1] * (-1)
        else:
            b_list.append(a)
print(sum(b_list))

Submission status: Wrong Answer

Solution code:
# Flipping Signs

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

def answer(l):
    len_l = len(l)
    abs_l = []
    cnt_neg = 0

    for v in l:
        abs_l.append(abs(v))
        if v < 0:
            cnt_neg += 1  # 負数をカウント

    if test:
        print('len_l  :', len_l)
        print('abs_l  :', abs_l)
        print('cnt_neg:', cnt_neg)

    # Aの要素が偶数個で、負の数が偶数個の時
    if len_l % 2 == 0 & cnt_neg % 2 == 0:
        return sum(abs_l) - 2 * min(abs_l)

    # Aの要素が偶数個で、負の数が奇数個の時
    if len_l % 2 == 0 & cnt_neg % 2 == 1:
        return sum(abs_l)

    # Aの要素が奇数個で、負の数が奇数個の時
    if len_l % 2 == 1 & cnt_neg % 2 == 1:
        return sum(abs_l) - 2 * min(abs_l)

    # Aの要素が奇数個で、負の数が偶数個の時
    return sum(abs_l)


def main():
    print(answer(A))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(n):
	if a[i] < 0:
		c += 1
	else:
		pass

if c%2 == 0:
	for i in range(n):
		s += abs(a[i])
else:
	a.sort(key = lambda x: abs(x))
	for i in range(1,n):
		s += abs(a[i])
	s -= a[0]
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
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]
    A = A[:MP-1] + B
    print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy

N = int( input() )
A = list( map( int ,input().split()) )
cnt = sum( lop < 0 for lop in A)

nA = numpy.array(A)
nA = numpy.abs(nA)

lA = nA.tolist()
if min(lA) == 0 or cnt % 2 == 0:
    print(sum(lA))
else :
    print(sum(lA)-min(lA))

Submission status: Wrong Answer

Solution code:
import copy
N = int(input())
A = set(map(int, input().split()))
A = sorted(list(A))


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


lo, hi = 1, 10 ** 9 + 1
while abs(hi - lo) > 1:
    X = copy.deepcopy(A)
    m = (hi + lo) // 2

    skipped = False
    while len(X) > 1:
        a, b = X.pop(), X.pop()
        GCD = gcd(a, b)
        if GCD < m:
            if skipped is False:
                skipped = True
                X.append(b)
                continue
            else:
                    hi = m
                    break
        X.append(GCD)
    else:
        if X[0] >= m:
            lo = m
        else:
            hi = m

print(lo)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(N):
    if A[i]<=0:
        B.append(-A[i])
    else:
        C.append(A[i])
if len(B)%2==0:
       print(sum(B)+sum(C))
else:
       print(sum(B)+sum(C)-2*min(B))

Submission status: Wrong Answer

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

while True:
	updated = False
	for i in range(N-1):
		if (A[i] + A[i+1] < 0):
			updated = True
			A[i] *= -1
			A[i+1] *= -1
			updated = True
	if not updated:
		break

print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])

if n//2==0: print(sum(abs(a)))
else: print(sum(abs(a))-2*abs(a[(np.argmin(abs(a)))]))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
for i in range(N-1):
	if A[i]<0:
		A[i]=-A[i]
		A[i+1]=-A[i+1]
print(sum(A))

Submission status: Wrong Answer

Solution code:
import numpy as np
N =int(raw_input())
A =map(int ,raw_input().split())
B =np.abs(A)
C = min(B)
D = sum(B)
E = D - C
k = 0
for i in range(N):
    if A[i]<0:
        k = k+1
if k%2 == 0:
    print D
else:
    print E

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
z=0
m=0
s=0
t=10000000000000
for i in range(n):
    s+=abs(l[i])
    t=min(t,abs(l[i]))
    if l[i]==0:
        z+=1
    if l[i]<0:
        m+=1
        
if z>0 or m%2==0:
    print(s)
else:
    print(s-t)

Submission status: Wrong Answer

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

N = int(input())
A = input().split()

sum = 0

for i in range(1, N):

    a_before = int(A[i - 1])
    ai = int(A[i])

    if a_before < 0:
        # 操作
        A[i - 1] = a_before * -1
        A[i] = ai * -1


for i in range(N):
    sum += int(A[i])

print(sum)

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:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq
"""
A,B,T=map(int, input().split())
print(int(math.floor((T+0.5)/(A))*B))
"""
"""
N=int(input())
V=list(map(int, input().split()))
C=list(map(int, input().split()))
print(sum([V[i] - C[i] for i in range(N) if V[i] - C[i] > 0]))
"""
"""
N=int(input())
A=list(enumerate(map(int, input().split())))
l=list(A)
l.sort()

x=(-1, -1)
y=(-1, -1)

while l[0][1] != 0:
        l=list(map(lambda it: (it[0], it[1]%l[0][1]), l[1:]))
        (i, xi) = x
"""
N=int(input())
A=list(map(int, input().split()))
nNeg = len([1 for a in A if a < 0])
minAbs = min(A, key=lambda ai: abs(ai))
if nNeg%2 == 0:
        print(sum([abs(ai) for ai in A]))
else:
        print(-2*minAbs + sum([abs(ai) for ai in A]))

Submission status: Wrong Answer

Solution code:
N = int(input())
lst_A =list(map(int, input().split()))
neg_count = 0
zero_count = 0
total = 0

if lst_A[0] < 0:
    neg_count += 1
elif lst_A[0] == 0:
    zero_count +=1
total += abs(lst_A[0])
print (total)
memo = abs(lst_A[0])
i = 1
while i < N:
    if lst_A[i] < 0:
        neg_count += 1
    elif lst_A[i] == 0:
        zero_count +=1
    total += abs(lst_A[i])
    print (total)
    memo = min(memo, abs(lst_A[i]))
    i += 1
if zero_count > 0:
    total = total
elif neg_count % 2 == 1:
    total = total - memo *2
else:
    total = total
print (total)

Submission status: Wrong Answer

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

temp = sum(A)

while True:
	updated = False
	for i in range(N-1):
		if (A[i] + A[i+1] < 0):
			updated = True
			A[i] *= -1
			A[i+1] *= -1
			temp += 2*(A[i]+A[i+1]) 
			updated = True
	if not updated:
		break

print(temp)

Submission status: Wrong Answer

Solution code:
memo = {}

def gcd(a, b):
    if (a, b) in memo.keys():
        return memo[(a, b)]
    if b == 0:
        return a
    return gcd(b, a % b)

n = input()
a_list = map(int, raw_input().split())
max_g = 0
for exclude in xrange(n):
    g = a_list[0] if exclude > 0 else a_list[1]
    for i in xrange(1, n):
        if i == exclude:
            continue
        g_new = gcd(g, a_list[i])
        memo[(g, a_list[i])] = g_new
        g = g_new
        if g <= max_g:
            break
    if g > max_g:
        max_g = g
print(max_g)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#D問題
N=int(input())
A=list(map(int,input().split()))
B=A[::]
for i in range(N-1):
    if A[i] > 0:
        pass
    else:
        A[i]=(-1*A[i])
        A[i+1]=(-1*A[i+1])
if min(A) >= 0:
    print(sum(A))
else:
    C=B[::]
    for i in range(N-1):
        C[i]=max(-1*C[i],C[i])
    print(sum(C)-2*min(C))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
if n==2:
    print(max(a[0],a[1]))
    exit()
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
g = gcd(max(a[0],a[1]),min(a[0],a[1]))
ind = [0,1]
for i in range(1,n):
    tmp = gcd(max(g,a[i]),min(g,a[i]))
    if tmp<g:
        ind = [i-1,i]
    g = tmp
import copy
a1,a2 = copy.copy(a),copy.copy(a)
del a1[ind[0]]
del a2[ind[1]]
g1=a1[0]
g2=a2[0]
for i in range(n-1):
    g1 = gcd(max(g1,a1[i]),min(g1,a1[i]))
    g2 = gcd(max(g2,a2[i]),min(g2,a2[i]))
print(max(g1,g2))

Submission status: Wrong Answer

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

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

if count%2==0:
    print(sum(A))
else :
    print(sum(A)-2*min(A))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A_list = list(map(int,input().split()))
neg_num = len([x for x in A_list if x<0])
zero_num = len([x for x in A_list if x==0])
abs_list = [abs(x) for x in A_list]

ans = np.sum(abs_list)
if neg_num%2==0 or zero_num>0:
    ans = ans
elif neg_num%2!=0:
    ans = ans - min([x for x in abs_list if x!=0])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
count = 0
ab_sum = 0
min = A[0]

for i in range(N):
    ab = 0

    if A[i] >= 0:
        ab_sum += A[i]
        ab = A[i]
    else:
        count += 1
        ab_sum -= A[i]
        ab = -A[i]
    if ab < min:
        min = ab

if(count % 2 == 0):
    print(ab_sum)
else:
    print(ab_sum-2*min)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
count=0
a_abs=[0 for j in range(n)]
min_abs=abs(a[0])
for i in range(n):
    a_abs[i]=abs(a[i])
    if a[i]<0:
        count+=1
    if abs(a[i])<min_abs:
        min_abs=abs(a[i])
        

if count%2==0:
    ans=sum(a_abs)
else:
    ans=sum(a_abs)-2*min_abs
    
print(count)
print(min_abs)
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import re
import bisect
from datetime import datetime as dt

n = input()
a = map(int, raw_input().split())
for i in range(n - 1):
    if a[i] > 0:
        continue
    elif - a[i] - a[i + 1] > a[i] + a[i + 1]:
        a[i] = -a[i]
        a[i+1] = -a[i+1]
print sum(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=sum(a)
for i in range(n-1):
    if a[i]<0:
        if i==n-2:
            b=sum(a)
            a[i]=a[i]*(-1)
            a[i+1]=a[i+1]*(-1)
            b=max(sum(a),b)
            break            
        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(i) for i in input().split()]
A.sort(reverse = True)
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]
    A = A[:MP-1] + B
    print(sum(A))
    print(A,B)

Submission status: Wrong Answer

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

for i in range(n):
    if a[i] < n-1 and a[i] < 0 :
        a[i] = a[i]*-1
    if a[i] > n-1 and a[i] < 0:
        a.remove(a[i])

print(sum(a))

Submission status: Wrong Answer

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

for i in range(N):
    if nums[i] < 0 and i + 1 < N:
        if nums[i + 1] < 0 or (nums[i + 1] >= 0 and (-nums[i] - nums[i + 1] > nums[i] + nums[i + 1] or (i + 2 < N and -nums[i] - nums[i + 1] <= nums[i] + nums[i + 1] and nums[i + 2] < 0))):
            nums[i] = -nums[i]
            nums[i + 1] = -nums[i + 1]

print(sum(nums))

Submission status: Wrong Answer

Solution code:
#全体-絶対値一番小さいやつ*2
N = int(input())
A = list(map(int,input().split()))
# N=3
# A = [-10,5,-4]
ans = 0
minnum = abs(A[0])
for i in range(N):
    ans += abs(A[i])
    minnum = min(minnum,abs(A[i]))
    #print(minnum,ans)
if N%2 == 1:
    ans -= minnum*2
print(ans)

Submission status: Wrong Answer

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

for i in range(n):
    if a[i] < n-1:
        a[i] = a[i]*-1
    if a[i] > n-1 and a[i] < 0:
        a.remove(a[i])

print(sum(a))

Submission status: Wrong Answer

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

cnt_minus = sum(x<=0 for x in a)

if cnt_minus % 2 == 0:
    print(sum(abs(x) for x in a))
else:
    y = min(abs(x) for x in a)
    while y == 0:
        a.remove(0)
        y = min(abs(x) for x in a)
    print(sum(abs(x) for x in a) - 2 * y)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = [abs(i) for i in A]
k = 0
for i in range(N):
    if A[i] < 0:
        k += 1
if k % 2 == 0:
    ans = sum(B)
else:
    ans = sum(B) - min(B)
print(ans)

Submission status: Wrong Answer

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