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:
n = int(input())
a = list(map(int, input().split()))
b = 0
ans = sum(a)

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
check=sum([a<0 for a in A]) #the number of positive number in A
if check%2==0:
    print(sum([abs(a) for a in A]))
else:
    dust=min([abs(a) for a in A if a<0])
    print(sum([abs(a) for a in A])-2*dust)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
#N=9
#A=[10,-4,-8,-11,3,90,78,3,999]
count=0
B=[]
for i in range(N):
    if A[i]<0:
        B.append((-1)*A[i])
        count+=1
    else:
        B.append(A[i])
print(B)
if count%2==0:
    print(sum(B))
else:
    print(sum(B)-2*min(B))

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def get_result(L, N):
    L_abs = [abs(x) for x in L]
    A = sum(L_abs)
    B = min(L_abs)
    neg_count = 0
    for elem in L:
        if elem < 0:
            neg_count += 1
    if neg_count % 2 == 0:
        return A
    else:
        return (A-B)


N = int(input())
L = [int(s) for s in input().split(" ")]
result = get_result(L, N)
print(result )

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def get_result(L, N):
    A = sum(L)
    B = min(L)
    neg_count = 0
    for elem in L:
        if elem < 0:
            neg_count += 1
    if neg_count % 2 == 0:
        return A
    else:
        return (A-B)


N = int(input())
L = [int(s) for s in input().split(" ")]
result = get_result(L, N)
print(result )

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
pa.sort()
ma.sort()
s = sum(l)
for i in [pa,ma]:
  if len(i)==0:i.append(0)
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
pa.sort()
ma.sort()
s = sum(l)
for i in [pa,ma]:
  if len(i)==0:i.append(0)
print(s if len(ma)%2==0 or t==1 else max(s+ma[-1]*2 if len(ma) != 0 else s,s-pa[0]*2) if len(pa) != 0 else s)

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()
print(a)
if c%2==1:
  k=k-2*a[0]
  print(k)
else:
  print(k)

Submission status: Wrong Answer

Solution code:
# D

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

minus_num = sum([x for x in A if x < 0])
abs_list = [abs(x) for x in A]
if minus_num % 2:
    print(sum(abs_list) - min(abs_list)*2)
else:
    print(sum(abs_list))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int, input().split()))
ans = 0
abs_A = [abs(a) for a in A]
count = sum([1 if a < 0 else 0 for a in A])
if (count % 2 == 0):
    print(sum(A))
else:
    print(sum(abs_A) - min(abs_A))

Submission status: Wrong Answer

Solution code:
def flipping_signs(N: int, A: list)->int:
    # 負の数が偶数この場合は全部正にできる。
    # 奇数個の場合は必ず一つ正にできないので絶対値の一番小さいもの
    # を残して他は全部正にする。
    min_abs = float('inf')
    s = 0
    neg_n = 0
    for a in A:
        s += abs(a)
        if a < 0:
            neg_n += 1
        min_abs = min(abs(a), min_abs)

    if neg_n & 1:
        return s - min_abs
    return s


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]

    ans = flipping_signs(N, A)
    print(ans)

Submission status: Wrong Answer

Solution code:
def flipping_signs(N: int, A: list)->int:
    # 負の数が偶数この場合は全部正にできる。
    # 奇数個の場合は必ず一つ正にできないので絶対値の一番小さいもの
    # を残して他は全部正にする。
    min_abs = float('inf')
    s = 0
    neg_n = 0
    for a in A:
        s += abs(a)
        if a < 0:
            neg_n += 1
            min_abs = min(abs(a), min_abs)

    if neg_n & 1:
        return s - min_abs
    return s


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]

    ans = flipping_signs(N, A)
    print(ans)

Submission status: Wrong Answer

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

def ary_abs(data):
    for i in range(len(data)):
        data[i] = abs(data[i])


for i in data:
    count = 0
    if i <= 0:
        count += 1

if count % 2 == 0:
    # 負が 偶数 個のとき
    # 全てを正にした和
    ary_abs(data)
    print(sum(data))
else:
    # 負が 奇数 個のとき
    # どれか一つを負(最小のもの)
    ary_abs(data)
    print(sum(data) - min(data) * 2)

Submission status: Wrong Answer

Solution code:
def flipping_signs(N: int, A: list)->int:
    # 前から全部正にしようとするか後ろからそうしようとするかの 2 通り。
    front = [a for a in A]
    for i in range(N-1):
        if front[i] < 0:
            front[i] *= -1
            front[i+1] *= -1

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

    return max(sum(front), sum(back))


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]

    ans = flipping_signs(N, A)
    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
minus_count = 0
for i in a:
    if i < 0:
        minus_count += 1
a = [abs(e) for e in a]
if minus_count % 2 != 0:
    a.pop(a.index(min(a)))
ans = sum(a)
print(ans)

Submission status: Wrong Answer

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

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:
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
pa.sort()
ma.sort()
s = sum(l)
for i in [pa,ma]:
  if len(i)==0:i.append(0)
print(s if len(ma)%2==0 or t==1 else max(s+ma[-1]*2,s-pa[0]*2))

Submission status: Wrong Answer

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

k = 0
tmp = abs(a[n - 1])

for i in range(n - 1):
    if abs(a[i]) < tmp:
        tmp = abs(a[i])

    if a[i] < 0:
        a[i] *= -1
        a[i + 1] *= -1

    k += a[i]

if a[n - 1] < 0:
    if abs(a[n - 1]) == tmp:
        k += a[n - 1]
    else:
        k += abs(a[n - 1])
        k -= tmp
else:
    k += a[n - 1]

print(k)

Submission status: Wrong Answer

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

k = 0
tmp = abs(a[n - 1])

for i in range(n - 1):
    if abs(a[i]) < tmp:
        tmp = abs(a[i])

    if a[i] < 0:
        a[i] *= -1
        a[i + 1] *= -1

    k += a[i]

if a[n - 1] < 0:
    if a[n - 1] == tmp:
        k += a[n - 1]
    else:
        k += abs(a[n - 1])
        k -= tmp
else:
    k += a[n - 1]

print(k)

Submission status: Wrong Answer

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

#マイナスの数が奇数の場合、合計値から一番小さい値を二倍して引く# 
 
else:
  for i in range(N):
    A[i]=abs(A[i])
 
  print(ans-2*min(A))

Submission status: Wrong Answer

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

k = 0
tmp = abs(a[n - 1])

for i in range(n - 1):
    if abs(a[i]) < tmp:
        tmp = abs(a[i])

    if a[i] < 0:
        a[i] *= -1
        a[i + 1] *= -1

    k += a[i]

if a[n - 1] < 0:
    k += abs(a[n - 1])
    k -= tmp
else:
    k += a[n - 1]

print(k)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
n = [a for a in A if a < 0]
S = sum([abs(a) for a in A])
if len(n) == 0:
    print(S)
else:
    print(S - 2 * abs(min(n)))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[_ for _ in map(int,input().split())]
#マイナスの数を求める#
minus_count=0
for i in A:
  if i<0:
    minus_count=+1
#Aの列絶対値をつけて足す#
ans=0
for i in A:
  ans+=abs(i)

#マイナスの数が偶数の場合、絶対値Bを全部足す#
if minus_count %2==0:
  print(ans)

#マイナスの数が奇数の場合、合計値から一番小さい値を二倍して引く# 

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

  print(ans-2*min(A))

Submission status: Wrong Answer

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

ans = 0
for i in a:
   ans += abs(i)

print (ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[_ for _ in map(int,input().split())]
#マイナスの数を求める#
minus_count=0
for i in A:
  if i<0:
    minus_count=+1
#Aの列絶対値をつけて足す#
ans=0
for i in A:
  ans+=abs(i)

#マイナスの数が偶数の場合、絶対値Bを全部足す#
if minus_count %2==0:
  print(ans)

#マイナスの数が奇数の場合、合計値から一番小さい値を二倍して引く# 

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

Submission status: Wrong Answer

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

val= -a[0] - a[1]
val_i = 0
for i in range(1, n-1):
  new_val = -a[i] -a[i+1]
  if new_val > val:
    val = new_val
    val_i = i

for i in range(0, n):
  if i==val_i or i==val_i+1:
    a[i] = -a[i]
ans = sum(a)
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin

readline = stdin.readline

_ = readline()
aa = map(int, open(0).read().split())
r = 0
mi = 1000000000
m = 0
for a in aa:
    if a < 0:
        m += 1
    b = abs(a)
    r += b
    if b < mi:
        mi = b
print(r - mi * 2 * (m % 2))

Submission status: Wrong Answer

Solution code:
A=int(input())
B=[_ for _ in map(int,input().split())]
"マイナスの数を求める"
minus=0
for i in B:
  if i<0:
    minus=+1
#マイナスの数が偶数の場合、絶対値Bを全部足す#
ans=0
if minus%2==0:
  for i in B:
    ans+=abs(i)
  print(ans)
#マイナスの数が奇数の場合、合計値から一番小さい値を二倍して引く# 
else:
  S=0
  for i in range(A):
    B[i]=abs(B[i])
  
  for i in B:
    S+=i
#合計値がマイナスになったら0 になるように場合分け#
  if (S-2*min(B))<=0:
    print(0)
  else:
    print(S-2*min(B))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = input().split()
mi = int(a[0])
ans =  0 
for i in range(n):
    ans = ans + abs(int(a[i]))
    if mi > int(a[i]):
        mi = int(a[i])
print(ans-2*mi)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
ma = []
pa = []
l =[]
t = 0
for i in a:
  if i < 0:
    ma.append(i)
    l.append(i*-1)
  elif i> 0:
    pa.append(i)
    l.append(i)
  else:
    t = 1
pa.sort()
ma.sort()
s = sum(l)
if len(ma) > 0 and len(pa):
  print(s if len(ma)%2==0 or t==1 else max(s+ma[-1]*2,s-pa[0]*2))
elif len(ma) > 0 and len(pa) == 0:
  print(s if len(ma)%2==0 or t==1 else max(s+ma[-1]*2,s))
elif len(pa) > 0 and len(ma) == 0:
  print(s if len(ma)%2==0 or t==1 else max(s,s-pa[0]*2))

Submission status: Wrong Answer

Solution code:
n = int(input())
aa = list(map(int, input().split()))
abs_aa = [abs(a) for a in aa]
minus_count = sum([1 for a in aa if a < 0])
if minus_count % 2:
    abs_aa[0] *= -1
print(sum(abs_aa))

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def solve(n, a_list):
    total = [abs(item) for item in a_list]
    negative = [abs(item) for item in a_list if item < 0]
    print(negative)
    if len(negative) % 2 == 0:
        return sum([abs(item) for item in a_list])
    else:
        minimum = sorted(total)[0]
        return sum([abs(item) for item in a_list]) - 2 * minimum


def input_from_console():
    n = int(input())
    a = list(map(int, input().split()))
    return n, a


def main():
    n, a_list = input_from_console()
    print(solve(n, a_list))


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

min_abs = 10*10
negative_count = 0
ans = 0
for a in aa:
    if a<0: negative_count += 1
    min_abs = min(min_abs, abs(a))
    ans += abs(a)
    # print(negative_count, ans, min_abs) 

if negative_count%2==1:
    ans -= min_abs*2
print(ans)

Submission status: Wrong Answer

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

min_abs = 10*10
negative_count = 0
ans = 0
for a in aa:
    if a<0: negative_count += 1
    min_abs = min(min_abs, abs(a))
    ans += abs(a)
    print(negative_count, ans, min_abs) 

if negative_count%2==1:
    ans -= min_abs*2
print(ans)

Submission status: Wrong Answer

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

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

# かっこいい解法版
# Ai, Ai+1を反転して-Ai,-Ai+1であるが、これを繰り返すことで、
# -Ai, Ai+1, Ai+2,....,Aj-1, -Aj というように、
# i < jとなるi,jのみを反転させ、間はそのままという操作が可能。
# ここから、負の数が偶数個であれば、全てを正にすることができる
# 負の数が奇数個であれば、絶対値が一番小さい負の数を残して残りを正にすればよい

ng = [a for a in A if a < 0]    # 負の数の抽出
ab = [abs(a) for a in A]    # 絶対値の和

if len(ng) % 2 == 0:
    print(sum(ab))
else:
    mn = max(ng)
    print(sum(ab)+2*mn)

Submission status: Wrong Answer

Solution code:
def main():
    _ = input()
    A = map(int, input().split())
 
    B = tuple(map(abs, A))
    C = tuple(a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

count = 0
m = 0
target = -1
for i in range(N):
    if nums[i] < 0:
        count += 1
        if nums[i] > m or target == -1:
            target = i
            m = nums[i]
pos = [abs(i) for i in nums]
if count % 2 != 0:
    pos[target] *= -1

print(sum(pos))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
for i in range(1,n):
  if a>=abs(l[i]):
    a=abs(l[i])
    m=i
s=0
for i in range(m):
  s+=abs(l[i])
s+=-abs(l[m])
for i in range(m+1,n):
  s+=abs(l[i])
print(s)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
minus = []
for i in range(N):
  if A[i] < 0:
    minus.append(A[i])
if len(minus) % 2 == 0:
  print(sum(abs(i) for i in A))
else:
  print(sum(abs(i) for i in A)-abs(min(A))*2)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
B=[x for x in A if x<0]
absA=[abs(x) for x in A]
if len(B)%2==0:
  minus=0
else:
  minus=max(B)
  
print(sum(absA)+minus*2)

Submission status: Wrong Answer

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

val = -a[0]-a[1]
val_i = 0
for i in range(0, n-1):
  new_val = -a[i] - a[i+1]
  if new_val > val:
    val = new_val
    val_i = i

ans = 0
for i in range(0, n):
  if i==val_i or i==val_i+1:
    ans -= a[i]
  else:
    ans += a[i]
print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
minus = []
for i in range(N):
  if A[i] < 0:
    minus.append(A[i])
if len(minus) % 2 == 0:
  print(sum(abs(i) for i in A))
else:
  print(sum(abs(i) for i in A)-min(minus)*2)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
B=[x for x in A if x<0]
absA=[abs(x) for x in A]
if len(B)%2==0:
  minus=0
else:
  minus=max(B)
  
print(sum(absA)+minus)

Submission status: Wrong Answer

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

if len(B)%2==0:
  minus=0
else:
  minus=max(B)
  
print(sum(A)+minus)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    _, *A = map(int, open(0).read().split())
 
    B = list(map(abs, A))
    C = [a for a in A if a < 0]
    print(sum(B) - min(B)*2*len(C)%2)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = input()
A = map(int, raw_input().split())
B = []
flag = 2
flag2 = 0
k = 0
minabs = 0
for i in range(N):
	k = abs(A[i])
	B.append(k)
	if(k != 0 and (k < minabs or minabs == 0)):
		minabs = k
	if(i == N - 1):
		if(A[i] == 0 or flag2 == 1):
			flag2 = 1
		elif((flag == 1 and A[i] < 0) or (flag == 0 and A[i] > 0)):
			flag2 = 1
		else:
			flag2 = 0
	else:
		if(flag == 2):
			if(A[i] > 0):
				flag = 0
			elif(A[i] == 0):
				flag2 = 1
			else:
				flag = 1
		elif((A[i] > 0 and flag == 0) or (A[i] < 0 and flag == 1)):
			flag = 0
		elif((A[i] < 0 and flag == 0) or (A[i] > 0 and flag == 1)):
			flag = 1
		else:
			flag2 = 1
	print(flag)
if(flag2 == 1):
	print(sum(B))
else:
	print(sum(B)- minabs * 2)

Submission status: Wrong Answer

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

val = - a[0] - a[1]
val_i = 0
for i in range(1, n-1):
  if - a[i] - a[i+1] > val:
    val = -a[i] -a[i+1]
    val_i = i

ans = 0
for i in range(0, n):
  if i==val_i:
    ans += -a[i] -a[i+1]
    i += 1
  else:
    ans += a[i]
print(ans)

Submission status: Wrong Answer

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

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
for i in range(A):
  B[i]=abs(B[i])
  ans=+B[i]  

"マイナスの数が偶数の場合、絶対値Bを全部足す"
if minus%2==0:
  print(ans)

else:
  print(ans-2*min(B))

Submission status: Wrong Answer

Solution code:
N = int(input())
A= list(map(int, input().split()))
minus = 0
A_abs = []
for i in range(N):
    A_abs.append(abs(int(A[i])))
    if(A_abs[i] < 0):
        minus += 0

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
ans=0
c=0
tmp=10**9
for a in A:
    if a<0:
        c+=1
    ans+=abs(a)
    tmp=min(tmp,abs(a))
print(tmp)
if c%2==0:
    print(ans)
else:
    print(ans-tmp*2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if cnt % 2 == 0 :
    print(sum(numabs))

if cnt % 2 == 1 :
    print(sum(numabs) - 2*max(numabs))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int,input().split()))
numabs = [abs(i) for i in num]
cnt = 0    
negative = []        
for i in num :
    if i < 0 :
        cnt += 1
        negative.append(i)

if cnt % 2 == 0 or num.count(0) >= 1 :
    print(sum(numabs))

if cnt % 2 == 1 and num.count(0) == 0 :
    print(sum(numabs)+2*max(negative))

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 == 0:
        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:
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 a[i] == 0:
			break
		if a[i] > 0:
			kk = a[i-1]
		if a[i] > 0:
			if abs(a[0]) >= a[i]:
				k = a[i]*(-2)
			else:
				k = kk*2
			break
		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())
num = list(map(int,input().split()))
numabs = [abs(i) for i in num]
cnt = 0    
negative = []        
for i in num :
    if i < 0 :
        cnt += 1
        negative.append(i)

if cnt % 2 == 0 or num.count(0) >= 1 :
    print(sum(numabs))

if cnt % 2 == 1 and num.count(0) == 0 :
    print(sum(numabs)-2*max(negative))

Submission status: Wrong Answer

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

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

sum = sum(a)
if k and not(z):
    sum -= m*2
print(sum)

Submission status: Wrong Answer

Solution code:
n=int(input())
c=list(map(int,input().split()))
count=0
for i in range(max(c),0,-1):
  if i in c:
    for j in range(n):
      if c[j]%i!=0:
        count=count+1
      if count>=2:
        break
    if count==1 or count==0:
      print(i)
      break
    count=0

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
count = 0
mina = a[0]
ans = 0
zflag = False

for i in range(0,n):
    if a[i] == 0:
        zflag = True
        continue
    elif a[i] < 0:
        count += 1
        a[i] = -a[i]
    ans += a[i]
    mina = min(mina,a[i])

if zflag == False and count%2 == 1:
    ans -= 2*mina
print(ans)

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 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
			break
		elif i == n-1:
			k = a[i]*2
	for i in range(n):
		su += abs(a[i])
	su += k
	print(su)

Submission status: Wrong Answer

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

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]
zero = [i for i in abs_a if i == 0]

if len(zero)%2 == 0:
    print(sum(abs_a))
elif 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())
w = input().split(" ")

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

sum = sum(a)
if k and not(z):
    sum -= m
print(sum)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
num = list(map(int,input().split()))
numabs = [abs(i) for i in num]
cnt = 0    
negative = []        
for i in num :
    if i < 0 :
        cnt += 1
        negative.append(i)

if cnt % 2 == 0 :
    print(sum(numabs))

if cnt % 2 == 1 :
    print(sum(numabs)-2*max(negative))

Submission status: Wrong Answer

Solution code:
def flipping(n,a):
    c = list(filter(lambda x:x<0,a))
    b = list(map(lambda x:abs(x),a))
    if len(c)%2==0:
        return sum(b)
    if len(c)%2!=0:
        return sum(b)-min(b)
    return b
n = int(input())
a=list(map(int, input().split()))
print(flipping(n,a))

Submission status: Wrong Answer

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

min_abs = 10*10
negative_count = 0
ans = 0
for a in aa:
    if a<0: negative_count += 1
    min_abs = min(min_abs, abs(a))
    ans += abs(a)
# print(negative_count, ans)

if negative_count%2==1:
    ans -= min_abs*2
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
     
N = input()
A = np.array([int(x) for x in input().split(" ")])
     
if len(np.where(A>0)[0])%2 == 0:
  print(np.abs(A).sum())
else:
  print(np.abs(A).sum() - np.abs(A).min()*2)

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split(" ")))
A_p = [ a for a in A if a > 0 ]
A_n = [ -1*a for a in A if a < 0 ]
A_0 = [ a for a in A if a == 0 ]

l_p = len(A_p)
l_n = len(A_n)
l_0 = len(A_0)

if l_p == 0:
    if l_n%2 == 0:
        print(sum(A_n+[0]))
    if l_0 > 0:
        print(sum(A_n+[0]))
    else:
        tmp_n=min(A_n)
        A_n.remove(tmp_n)
        print(sum(A_n+[0])-tmp_n)
elif l_n == 0:
    print(sum(A_p+[0]))

elif l_n%2 == 0:
    print(sum(A_p)+sum(A_n))
else:
    if l_0 > 0:
        print(sum(A_p)+sum(A_n))
    else:
        if min(A_n) > min(A_p):
            tmp_n=min(A_p)
            A_p.remove(tmp_n)
            print(sum(A_p)+sum(A_n)-tmp_n)    
        else:
            tmp_n=min(A_n)
            A_n.remove(tmp_n)
            print(sum(A_p)+sum(A_n)-tmp_n)

Submission status: Wrong Answer

Solution code:
N = input()
A = map(int, raw_input().split())
B = []
flag = 2
flag2 = 0
k = 0
minabs = 0
for i in range(N):
	k = abs(A[i])
	B.append(k)
	if(k != 0 and (k < minabs or minabs == 0)):
		minabs = k
	if(i == N - 1):
		if(A[i] == 0 or flag2 == 1):
			flag2 = 1
		elif((flag == 1 and A[i] < 0) or (flag == 0 and A[i] > 0)):
			flag2 = 1
		else:
			flag2 = 0
	else:
		if(flag == 2):
			if(A[i] > 0):
				flag = 0
			elif(A[i] == 0):
				flag2 = 1
			else:
				flag = 1
		if((A[i] > 0 and flag == 0) or (A[i] < 0 and flag == 1)):
			flag = 0
		elif((A[i] < 0 and flag == 0) or (A[i] > 0 and flag == 1)):
			flag = 1
		else:
			flag2 = 1
if(flag2 == 1):
	print(sum(B))
else:
	print(sum(B)- minabs * 2)