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

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

if 0 in A:
    out = 0
    for i in A:
        out += abs(i)
    print(out)
else:
    count = 0
    for i in A:
        if i < 0:
            count += 1
    
    if count%2 == 0:
        out = 0
        for i in A:
            out += abs(i)
        print(out)
    else:
        count = 10 ** 9
        for i in A:
            if abs(i) < count:
                count = abs(i)
        
        out = 0
        for i in A:
            out += abs(i)
        out = out - count*2
        
        print(out)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import numpy as np
n=int(input())
a=np.array(list(map(int,input().split())),dtype='int64')
if np.sum(a<0)%2==0:
    a=abs(a)
else:
    a=abs(a)
    a[a.argmin()]=-a[a.argmin()]
# print(a)
print(int(sum(a)))

Submission status: Accepted

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

neg_count = 0
max_neg = -10**9-1
max_neg_i = -1
min_pos = 10**9+1
min_pos_i = -1
total2 = 0
for i in range(N):
    if As[i] >= 0 and As[i] < min_pos:
        min_pos = As[i]
        min_pos_i = i
    if As[i] < 0 and As[i] > max_neg:
        max_neg = As[i]
        max_neg_i = i
    total2 += abs(As[i])
    if As[i] < 0:
        neg_count += 1

if neg_count % 2 == 0:
    print(total2)
else:
    cands = []
    if min_pos_i >= 0:
        cands.append(total2 - min_pos*2)
    if max_neg_i >= 0:
        cands.append(total2 + max_neg*2)
    print(max(cands))

Submission status: Accepted

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

absA = [abs(A[i]) for i in range(N)]
minA = min(absA)
sumA = sum(absA)
minus = 0
for i, a in enumerate(A):
    if a < 0:
        minus += 1

if minus % 2 == 0:
    ans = sumA
else:
    ans = sumA - 2 * minA

print(ans)

Submission status: Accepted

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


if x%2 == 0:
    print(sum(a))
else:
    m = min(a)
    print(sum(a)-2*m)

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
num=0
for i in l:
    if i<0:
        num+=1
res=0
for i in l:
    if i>0:
        res+=i
    else:
        res+=-1*i
p=10**10
for i in l:
    p=min(abs(i),p)
if num%2==0:
    A=True
else:
    A=False

if A:
    print(res)
else:
    print(res-2*p)

Submission status: Accepted

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

N = int(input())
X = list(map(int, input().rstrip().split(' ')))

count_minus = 0
for x in X:
    if x < 0:
        count_minus += 1
        
if count_minus % 2 == 0:
    print(sum(map(abs, X)))
else:
    print(sum(map(abs, X)) - 2 * min(map(abs, X)))

Submission status: Accepted

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

if sum(a < 0 for a in A) & 1:
	print(sum(map(abs, A)) - 2 * min(abs(a) for a in A))
else:
	print(sum(map(abs, A)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr2=[]
cnt=0
for i in range(n):
  if arr[i]<0:
    cnt+=1
  arr2.append(abs(arr[i]))
if cnt%2==0:
  print(sum(arr2))
else:
  print(sum(arr2)-min(arr2)*2)

Submission status: Accepted

Solution code:
n = int(input())
num_list = list(map(int,input().split()))
i = 0
neg_count = 0
while(i < n):
    if num_list[i] < 0:
        neg_count += 1
        num_list[i] *= -1
    i += 1
num_list = sorted(num_list)
if neg_count %2 == 0:
    print(sum(num_list))
else:
    num_list[0] *= -1
    print(sum(num_list))

Submission status: Accepted

Solution code:
n = int(input())
inputlist = list(map(int, input().split()))
count = 0
isZero = 0
minabs = float("inf")
abslist = []

for i in range(n):
  ith = inputlist[i]
  if ith == 0:
    isZero = 1
  if ith < 0:
    count += 1
  if abs(ith) < minabs:
    minabs = abs(ith)
  abslist.append(abs(ith))
  
ans = 0
if count % 2 == 0 or isZero == 1:
  for j in range(n):
    ans += abslist[j]
  print(ans)
else:
  for k in range(n):
    ans += abslist[k]
  ans -= 2 * minabs
  print(ans)

Submission status: Accepted

Solution code:
N = int(input())
al = [int(a) for a in input().split()]

ans = 0

c_minus = 0
abs_min = 1e10

for i in range(N):
    a = al[i]
    if a < 0:
        c_minus += 1
    if abs(a) < abs_min:
        abs_min = abs(a)
    ans += abs(a)
    
if c_minus % 2 == 0:
    print(ans)
else:
    print(ans - 2 * abs_min)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
minuscount=0
zerocount=0
for i in range(len(l)):
  if l[i]<0:
    minuscount+=1
  elif l[i]==0:
    zerocount+=1
absl=[abs(l[i]) for i in range(len(l))]
if minuscount%2==0:
  print(sum(absl))
else:
  if zerocount>0:
    print(sum(absl))
  else:
    absl.sort(reverse=True)
    print(int(sum(absl)-2*absl[-1]))

Submission status: Accepted

Solution code:
N=int(input())

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

minusCnt = 0
absMin = 10**10
# absMinIndex = -1

for i in range(len(A)):
	if abs(A[i]) < absMin:
		absMin = min( abs(A[i]), absMin )
		absMinIndex = i
	if A[i] < 0:
		minusCnt+=1

if minusCnt % 2 == 0:
	# even
	for i in range(len(A)):
		if A[i] < 0:
			A[i] *= -1
else:
	# odd
	for i in range(len(A)):
		if absMinIndex == i:
			if 0 < A[i]:
				A[i] *= -1
		if A[i] < 0 and i != absMinIndex:
			# print(i,A[i],absMinIndex)
			A[i] *= -1

ans = sum(A)

print(ans)

Submission status: Accepted

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

S=0
for a in A:
    S+=abs(a)




cnt=0
for a in A:
    if a<0:
        cnt+=1
if cnt%2==0:
    print(S)
else:
    m=abs(A[0])
    for i in range(n):
        if m>abs(A[i]):
            m=abs(A[i])
    print(S-2*m)

Submission status: Accepted

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
    s += z
    if m > z:
        m = z
if cn%2 == 0:
    print(s)
else:
    print(s - m*2)

Submission status: Accepted

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

m = 0
for i in a:
    if i < 0:
        m += 1

for i in range(n):
    a[i] = abs(a[i])

ans = 0
for i in range(n):
    ans += a[i]
if m%2 == 0:
    print(ans)
else:
    print(ans-2*min(a))

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
b=[abs(a[i]) for i in range(N)]
d=[0]*N
M=sum(b)

tmp=0
for i in range(N):
    if a[i]<0: tmp+=1
    d[i]=tmp

if d[N-1]%2==0 or 0 in a:
    print(M)

else: print(M-min(b)*2)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
c = 0
min_abs = float('inf')
for i in range(N):
  if A[i] < 0:
    c += 1
  if abs(A[i]) < min_abs:
    min_abs = abs(A[i])

s = 0
#print(min_abs)
if c % 2 == 0:
  for i in range(N):
    s += abs(A[i])
else:
  for i in range(N):
      s += abs(A[i])
  s -= abs(min_abs) * 2

print(s)

Submission status: Accepted

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

if 0 in a:
    print(sum(a))
elif cnt%2 == 0:
    print(sum(a))
else:
    print(sum(a)-min(a)*2)

Submission status: Accepted

Solution code:
num = int(input())
values = list(map(int, input().split()))
count = 0
for index, value in enumerate(values):
    if value < 0:
        count += 1
    values[index] = abs(value)

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
cnt=sum([1 if a < 0 else 0 for a in A])
lAl=list(map(abs, A))
if cnt % 2 == 1:
	print(sum(lAl) - 2 * min(lAl))
else:
	print(sum(lAl))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
mn = len(list(filter(lambda x: x < 0, A)))
ans = [-A[i] if A[i] < 0 else A[i] for i in range(N)]
if mn % 2 == 0:
    print(sum(ans))
else:
    print(sum(ans)-min(ans)*2)

Submission status: Accepted

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

neg = [ai for ai in an if ai < 0]

sum = 0
mini = 10 ** 9
for ai in an:
  sum += abs(ai)
  mini = min(mini, abs(ai))
  
if len(neg) % 2 != 0:
  sum -= 2 * mini

print(sum)

Submission status: Accepted

Solution code:
n=int(input())
a = [int(i) for i in input().split()] 
#print(n,a)

cnt=0
ans=0
mina=float('inf')

for i in range(n):
  if a[i] >= 0:
    ans+=a[i]
    mina=min(mina,a[i])
  else:
    ans-=a[i]
    cnt+=1
    mina=min(mina,-a[i])
    
if a.count(0)>0:
  print(ans)
elif cnt%2==0:
  print(ans)
else:
  print(ans-2*mina)

Submission status: Accepted

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

num_of_minus = sum([a < 0 for a in A])
abs_A = [abs(a) for a in A]
ans = sum(abs_A)

if num_of_minus % 2 == 0:
    print(ans)
else:
    print(ans - 2 * min(abs_A))

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())),key=lambda x:abs(x))

a = 0
for i in A:
  if i < 0:
    a += 1
  elif i == 0:
    a = -1
    break

ans = 0
if a == -1 or a % 2 == 0:
  ans = sum([abs(x) for x in A])
else:
  ans = abs(A[0]) * -1
  for a in A[1:]:
    ans += abs(a)
print(ans)

Submission status: Accepted

Solution code:
# Flipping Signs

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

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

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

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

    # 負の数が偶数個の時
    if cnt_neg % 2 == 0:
        return sum(abs_l)

    # 負の数が奇数個の時
    return sum(abs_l) - 2 * min(abs_l)


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.sort()
posA = 0
negcnt = 0
absmin = 10**9
for itm in A:
    if itm < 0:
        negcnt += 1
    absmin = min(absmin, abs(itm))
    posA += abs(itm)
ifNodd = N % 2
ifnegodd = negcnt % 2
#-1 N
#odd odd = N-1
#even even = N
#odd even = N-1
#even odd = N
if ifnegodd == 1:
    ans = posA - 2*absmin
else:
    ans = posA
print(ans)

Submission status: Accepted

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

cnt=0
for i in A:
    if i < 0:
        cnt += 1

X=[]
for i in A:
    X.append(abs(i))

if cnt % 2 == 0:
    print(sum(X))
else:
    print(sum(X) - (min(X)*2))

Submission status: Accepted

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

minus = len(A[np.where(A < 0)])
abs_list = [abs(0-i) for i in A]
res = sum(abs_list)
if minus % 2 != 0:
    m = min(abs_list)
    res -= m * 2
print(res)

Submission status: Accepted

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

A_k = [i for i in A if i < 0]

A_abs = list(map(abs, A))

if len(A_k) % 2 == 0:
    print(int(sum(A_abs)))
    exit()
else:
    print(int(sum(A_abs) - 2 * min(A_abs)))

Submission status: Accepted

Solution code:
min_val = 10 ** 9
N = int(input())
A = list(map(int, input().split()))
minus_conut = 0
sum_val = 0
for num in A:
    if num < 0:
        minus_conut += 1
    abs_val = abs(num)
    min_val = min(min_val, abs_val)
    sum_val += abs_val

if minus_conut % 2 == 0:
    print(sum_val)
else:
    print(sum_val - 2 * min_val)

Submission status: Accepted

Solution code:
#   最初に合計値を計算　つぎにマイナスになるペアを見つけてはその絶対値の二乗を逐一足していく。

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

abs_min = 10**9
count_minus = 0
abs_A_lst = []

for i in range(N):
    A_lst[i] = int(A_lst[i])
    abs_A_lst.append(abs(A_lst[i]))
    if abs_A_lst[-1] < abs_min:
        abs_min = abs_A_lst[-1]
    if A_lst[i] < 0:
        count_minus += 1

output = sum(abs_A_lst)
if count_minus % 2 == 1:
    output -= abs_min*2

print(output)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
A = [int(s) for s in a]
B = len([i for i in A if i < 0])
ABS = list(map(abs, A))
small = min(ABS)
if small == 0 or B % 2 ==0:
    print(sum(ABS))
else:
    print(sum(ABS) - 2 * small)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
count = 0
sumabs = 0
minabs = 10 ** 10
for i in range(N):
    if A[i] < 0:
        count += 1
    sumabs += abs(A[i])
    minabs = min(minabs, abs(A[i]))

if count % 2 == 0:
    print(sumabs)
else:
    print(sumabs-2*minabs)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted([int(_) for _ in input().split()])
ans = sum(A)
for i in range(1, N // 2 + 1):
    a1 = ans - 2 * (A[2 * i - 2] + A[2 * i - 1])
    if a1 < ans:
        break
    ans = a1
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
cntm = cntz = 0
for i in range(n):
    if a[i] < 0:
        cntm += 1
    elif a[i] == 0:
        cntz += 1
ans = 0
for i in range(n):
    ans += abs(a[i])
if cntm%2 == 0 or cntz > 0:
    print(ans)
else:
    abmin = 10**15
    for i in range(n):
        if abs(a[i]) < abmin:
            abmin = abs(a[i])
    print(ans - 2*abmin)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
check = list(map(lambda x:1 if x>-1 else 0, A)).count(0)%2
A = list(map(abs,A))
if check:
    print(sum(A)-min(A)*2)
else:
    print(sum(A))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def solve(xs):
    num_neg = sum(x < 0 for x in xs)
    ys = sorted(abs(x) for x in xs)
    if num_neg % 2 == 0:
        res = sum(ys)
    else:
        res = -ys[0] + sum(ys[1:])
    return res


def main():
    _ = int(input())
    xs = [int(z) for z in input().split()]
    print(solve(xs))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

zero_count = 0
minus_count = 0
s = 0
min_num = abs(a[0])

for i in range(n):
    if a[i] < 0:
        minus_count += 1
    elif a[i] == 0:
        zero_count += 1
    s += abs(a[i])
    min_num = min(min_num, abs(a[i]))

if minus_count % 2 == 0:
    print(s)
else:
    if zero_count == 0:
        print(s - 2 * min_num)
    else:
        print(s)

Submission status: Accepted

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

abs_a = []
minuses = 0

for _a in a:
	if _a < 0:
		minuses += 1
	abs_a.append(abs(_a))

if minuses % 2 == 0:
	print(sum(abs_a))
else:
	print(sum(abs_a) - 2 * min(abs_a))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
t=len([i for i in a if i<0])
b=[abs(i)for i in a]
if t%2==0:
    print(sum(b))
else:
    print(sum(b)-2*min(b))

Submission status: Accepted

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
n_minus = 0
for a in A_list:
    if a < 0:
        n_minus += 1
if int(n_minus)%2 == 0:
    print(sum([abs(a) for a in A_list]))
else:
    tmp = sorted([abs(a) for a in A_list])
    print(int(sum(tmp[1:]) - tmp[0]))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

odd = False
for i in range(len(A)):
    if A[i] < 0:
        A[i] *= -1
        odd = not odd

if odd:
    print(sum(A) - min(A) * 2)
else:
    print(sum(A))

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
l2=[]
hugoc=0
for i in range(n):
  x=l[i]
  if x<0:
    hugoc+=1
  l2.append(abs(x))
l2.sort()
if hugoc%2==0:
  print(sum(l2))
else:
  print(sum(l2[1:])-l2[0])

Submission status: Accepted

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):
        C[i]=max(-1*C[i],C[i])
    print(sum(C)-2*min(C))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
gu=False
min_i = [0,10**5]
count = 0
for i in range(N):
    if(A[i] < 0):
        count = count + 1

if(count%2 == 0):
    gu=True

if(gu or 0 in A):
    print(sum(list(map(abs,A))))
else:

    for i in range(N):
        if(abs(A[i])<min_i[1]):
            min_i[0] = i
            min_i[1] = abs(A[i])
    a =sum(list(map(abs,A)))
    print(a-min_i[1]*2)

Submission status: Accepted

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

minabs = 10 ** 9
numneg = 0

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

    minabs = min(minabs, A[i])

print(sum(A) if numneg % 2 == 0 else sum(A) - 2 * minabs)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A_min = 10000000000
negative_count = 0
ans = 0

for i in range(N):
    if abs(A[i]) < A_min:
        A_min = abs(A[i])
    if A[i] < 0:
        negative_count += 1
    ans += abs(A[i])

if negative_count % 2 == 0:
    print(ans)
else:
    ans -= A_min*2
    print(ans)

Submission status: Accepted

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

count = 0
p = 10**9
sum_l = 0
for i in l:
    sum_l += abs(i)
    p = min(p,abs(i))
    if i < 0:
        count += 1

if count%2 == 0:
    print(sum_l)
else:
    print(sum_l-2*p)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
ab = [abs(a) for a in A]
p = sum([a < 0 for a in A])
if p % 2:
    print(sum(ab) - 2*min(ab))
else:
    print(sum(ab))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
n_minus = 0
has_zero = False
for i, a in enumerate(A):
    if a < 0:
        n_minus += 1
    if a == 0:
        has_zero = True
    A[i] = abs(a)

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
minus = 0
for a in A:
    if a < 0:
        minus += 1
absA = list(map(abs,A))
if minus%2 ==1:
    print(sum(absA)-min(absA)*2)
else:
    print(sum(absA))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
ABS = sorted([abs(a) for a in A])
minus = sum([1 for a in A if a < 0])
if minus % 2:
  ABS[0] *= -1
print(sum(ABS))

Submission status: Accepted

Solution code:
import numpy as np

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

A_allplus = np.where(A>=0,A,-A)
#print(A_allplus)
plus = A[A>=0]
minus = A[A<0]
#print(minus)
d = 0
if len(minus)%2==1:
    a = np.inf
    b = np.inf
    if len(minus)>0:
        a = max(minus)
    if len(plus)>0:
        b = min(plus)
    
    
    d = min(abs(a),abs(b))*2

print(sum(A_allplus)-d)

Submission status: Accepted

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]
if A[N-1]>0:
	print(sum(A))
else:
	A[N-1]=-A[N-1]
	aa=min(A)
	print(sum(A)-aa-aa)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
minnumber = -1
answer = 0
number = 0

for x in range(len(A)):
    if A[x] < 0:
        A[x] = abs(A[x])
        number += 1
    answer += A[x]
    if minnumber == -1 or minnumber > A[x]:
        minnumber = A[x]

if number % 2 == 0:
    print(answer)
else:
    answer -= minnumber * 2
    print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

fugo = [a < 0 for a in A]
seiA = [abs(a) for a in A]

ans = sum(seiA)
if sum(fugo) % 2 == 0:
    print(ans)
else:
    print(ans - 2 * min(seiA))

Submission status: Accepted

Solution code:
n = int(input())
lis = list(map(int,input().split()))
count = 0
zero = 0
for i in range(n):
  if lis[i] == 0:
    zero += 1
  elif lis[i] < 0:
    lis[i] = lis[i] * -1
    count += 1
if zero >= 1:
  print(sum(lis))
elif count % 2 == 0:
  print(sum(lis))
else:
  print(sum(lis) - (min(lis)*2))

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    a = list(map(int, input().split()))
    b = [abs(x) for x in a]
    n = sum(map(lambda x: x < 0, a))

    # print(n)
    if n%2==0:
        print(sum(b))
    else:
        print(sum(b) - min(b)*2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split(" ")]
c = 0
z = False
for i in range(0, n):
    if a[i] == 0:
        z = True
    elif a[i] < 0:
        c += 1

if z or c % 2 == 0:
    print(sum([abs(i) for i in a]))
else:
    ab = [abs(i) for i in a]
    print(sum(ab) - 2 * min(ab))

Submission status: Accepted

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

ans = 0
plus = 0
minus = 0
zero = 0
min = 10**9

for i in range(N):
    if A[i] == 0:
        zero += 1
    elif A[i] > 0:
        plus += 1
    else:
        minus += 1
    ans += abs(A[i])
    if min > abs(A[i]):
        min = abs(A[i])

if zero > 0 or minus%2==0:
    print(ans)
else:
    print(ans - min*2)

Submission status: Accepted

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

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

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

if A[-1] < 0:
    A[-1] *= -1
    print(sum(A) - 2*min(A))
else:
    print(sum(A))

Submission status: Accepted

Solution code:
N=int(input())
A=map(int,input().split())
a_min=10**9
ans=0
neg=0
for a in A:
    aa=abs(a)
    ans+=aa
    if a<0:
        neg+=1
    if a_min>aa:
        a_min=aa
if neg%2==1:
    ans-=a_min*2
print(ans)

Submission status: Accepted

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

N = int(input())
A = list(map(int, input().split()))
A2 = [-a if a<0 else a for a in A]
N2 = len([a for a in A if a<0])

if N2 % 2 == 0:
    print(sum(A2))
else:
    print(sum(A2) - min(A2) * 2)

Submission status: Accepted

Solution code:
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
A = IL()

SUM = 0
cnt = 0
MIN = MAX_INT
for i in range(N):
  if A[i] < 0:
    tmp = -A[i]
    cnt += 1
  else:
    tmp = A[i]
  MIN = min(MIN,tmp)
  SUM += tmp

if cnt%2 == 0:
  print(SUM)
else:
  print(SUM-MIN*2)

Submission status: Accepted

Solution code:
N=int(input())
#S=input()
#A,B,T=map(int,input().split())
A=list(map(int,input().split()))
m=10**19
count=0
for i in A:
    if abs(i)<m:
        m=abs(i)
    if i<0:
        count+=1
if count%2==0:
    print(sum([abs(i) for i in A]))
else:
    print(sum([abs(i) for i in A])-2*m)

Submission status: Accepted

Solution code:
n = int(input())
a = [int(m) for m in input().split()]
S = 0
for i in range(n):
    S += abs(a[i])
fu = 0
minabs = float("INF")
for i in range(n):
    if a[i] < 0:
        fu += 1
    minabs = min(minabs, abs(a[i]))

if n % 2 == 0:
    if fu % 2 == 0:
        print(S)
    else:
        print(S - 2 * minabs)
else:
    if fu % 2 == 0:
        print(S)
    else:
        print(S - 2 * minabs)

Submission status: Accepted

Solution code:
import sys

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

    S = 0
    min_ = 10**9 + 1
    neg = 0
    for a in A:
        if a < 0:
            neg += 1
            S += -a
            min_ = min(min_, -a)
        else:
            S += a
            min_ = min(min_, a)

    if neg % 2 == 0:
        return S
    else:
        return S - 2 * min_


if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

P = []
N = []
for a in A:
  if a>=0:
    P += [a]
  else:
    N += [a]
P.sort()
N.sort()

if len(N)%2==0:
  print sum(P)+sum(-t for t in N)
elif len(P)>0:
  print sum(P[1:])+sum(-t for t in N[:-1])+abs(P[0]+N[-1])
else:
  print sum(-t for t in N[:-1])+N[-1]

Submission status: Accepted

Solution code:
N=int(input())
a_list = list(map(int, input().split()))
minus_a_list = list(filter(lambda x: x < 0, a_list))
# print(minus_a_list)
if (len(minus_a_list) % 2 == 0):
    print(sum(map(abs, a_list)))
else:
    abs_a_list = list(map(abs, a_list))
    print(sum(abs_a_list) - 2 * min(abs_a_list))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
for i in a:
  b.append(abs(i))
m=[]
for i in a:
  if i>=0:
    m.append(0)
  else:
    m.append(1)
if sum(m)%2==0:
  ans=sum(b)
else:
  k=1000000000
  t=0
  for i in range(n):
    if b[i]<k:
      k=b[i]
      t=i
  ans=sum(b)-2*b[t]
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

INF = float('inf')
dp = [[-INF] * N for i in range(2)]
dp[0][0] = A[0]
dp[1][0] = -A[0]

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

Submission status: Accepted

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

a.sort()

abs_a = []
minus_num = 0
for i in range(n):
    if a[i] < 0:
        minus_num += 1
    abs_a.append(abs(a[i]))

abs_a.sort()
plus_sum = sum(abs_a)

if minus_num % 2 == 0:
    print(plus_sum)
else:
    print(plus_sum - 2*abs_a[0])

Submission status: Accepted

Solution code:
import collections as c
ip = lambda : map(int, input().split())

#################
N = int(input())
A = [int(i) for i in input().split()]
minn = 1e9
cminus = 0
czero = 0
s = 0
for i in A:
    minn = min(minn,abs(i))
    if i<0:
        cminus += 1
    elif i==0:
        czero += 1
    s += abs(i)
if cminus%2 == 1:
    s -= 2*minn
print(s)

Submission status: Accepted

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

absmin=abs(nums[0])
abssum=0
minus=0

for n in nums:
    if n < 0:
        minus += 1
    absmin = min(absmin, abs(n))
    abssum += abs(n)

if minus % 2 == 0:
    print(abssum)
else:
    print(abssum - (absmin * 2))

Submission status: Accepted

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*abs(minAbs) + sum([abs(ai) for ai in A]))

Submission status: Accepted

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

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

if cnt_minus % 2 == 0 or cnt_zero > 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: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
pal =1
minabs = 10**9
for i in range(n):
    if a[i] <0:
        pal *=-1
        a[i] = -1*a[i]
    minabs = min(minabs,a[i])
if pal ==1:
    print(sum(a))
else:
    print(sum(a)-2*minabs)

Submission status: Accepted

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

for i in range(0, n-n%2-1, 2):
    if a[i] + a[i+1] < 0:
        a[i] = -a[i]
        a[i+1] = -a[i+1]
    else:
        break
print(sum(a))

Submission status: Accepted

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

B = []

count = 0
for x in A:
  if x < 0:
    count += 1
  B.append(abs(x))

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

Submission status: Accepted

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 - 2*min([x for x in abs_list if x!=0])
print(ans)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = [int(n) for n in input().split()]
    A = sorted(A, key = lambda x: abs(x), reverse=True)
    minus = 0
    for a in A:
        if a < 0:
            minus += 1
    if minus % 2 == 1:
        minus -= 1
    res = 0
    for i in range(N):
        a = A[i]
        if a < 0 and minus > 0:
            A[i] = -a
            minus -= 1
    for i in range(N):
        a = A[i]
        if a < 0:
            A[i] = -a
            A[-1] = -A[-1]
    
    print(sum(A))
main()