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: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
for i,j in enumerate(a):
  if j >= 0:
    if i % 2 == 0:
      ans = abs(sum(a[:i]))+sum(a[i:])
      break
    else:
      ans = abs(sum(a[:i-1]))+abs(a[i]+a[i-1])+sum(a[i+1:])
      break
print(ans)

Submission status: Runtime Error

Solution code:
x = int(input())
y = list(map(int, input().split(" ")))

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

if y[-1] < 0 and abs(min(y[0:-2])) < abs(y[-1]) :
  y[-1] *= -1
  y[y.index(min(y[0:-2]))] *= -1

print(sum(y))

Submission status: Runtime Error

Solution code:
x = int(input())
y = list(map(int, input().split(" ")))

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

if y[-1] < 0:
  y[-1] *= -1
  y[y.index(min(y[0:-2]))] *= -1
  
print(sum(y))

Submission status: Runtime Error

Solution code:
#include "bits/stdc++.h"

using namespace std;

int i;

int main(){
  int N, neg_cnt = 0;
  cin >> N;
  vector<int> A(N), B(N);
  for (i = 0; i < N; i++){
    cin >> A[i];
    if (A[i] < 0){
      neg_cnt++;
    }
  }
  for (i = 0; i < N; i++){
    B[i] = abs(A[i]);
  }
  int acm = 0;
  int min = *min_element(B.begin(), B.end());
  acm = accumulate(B.begin(), B.end(), 0);
  if (neg_cnt%2 == 0){
    cout << acm << endl;
  }else{
    cout << acm - 2*min << endl;
  }
}

Submission status: Runtime Error

Solution code:
import numpy as np
from math import inf

N = int(input())
a = map(int, input().split())

dp = np.zeros((N + 1, 2))
dp[0][1] = -inf
# dp[i][0]:=1-indexedで、a_iとa_i+1を反転させない場合の最大値
# dp[i][1]:=1-indexedで、a_iとa_i+1を反転させる場合の最大値

for i, aa in enumerate(a, 0):
    dp[i + 1][0] = max(dp[i][0] + aa, dp[i][1] - aa)
    dp[i + 1][1] = max(dp[i][0] - aa, dp[i][1] + aa)
print(dp[N][0])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

abs_A = [abs(A[i]) for i in A]
ans = 0
if N % 2 == 0:
    ans = sum(abs_A)
else:
    ans = sum(abs_A) - 2*min(abs_A)

print(ans)

Submission status: Runtime Error

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

dp = np.zeros((N+1, 2), dtype=int)
dp[0, 1] = -10**9

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

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(100000)

class Solution():
    def dp(self, pos, sign):
        if pos == self.n-1:
            if sign == 0:
                return +self.lst[pos]
            else:
                return -self.lst[pos]
        elif (pos, sign) in self.vis:
            return self.rcd[pos][sign]
        elif sign == 0:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) + self.lst[pos], self.dp(pos+1, 1) - self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]
        else:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) - self.lst[pos], self.dp(pos+1, 1) + self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]

    def run(self):
        self.n = int(input())
        self.lst = list(map(int, raw_input().split()))
        self.rcd = [[0, 0] for _ in range(self.n)]
        self.vis = set()
        print(self.dp(0, 0))

solution = Solution()
solution.run()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10000)

class Solution():
    def dp(self, pos, sign):
        if pos == self.n-1:
            if sign == 0:
                return +self.lst[pos]
            else:
                return -self.lst[pos]
        elif (pos, sign) in self.vis:
            return self.rcd[pos][sign]
        elif sign == 0:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) + self.lst[pos], self.dp(pos+1, 1) - self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]
        else:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) - self.lst[pos], self.dp(pos+1, 1) + self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]

    def run(self):
        self.n = int(input())
        self.lst = list(map(int, raw_input().split()))
        self.rcd = [[0, 0] for _ in range(self.n)]
        self.vis = set()
        print(self.dp(0, 0))

solution = Solution()
solution.run()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def dp(pos, sign):
    if pos == n-1:
        if sign == 0:
            return +lst[pos]
        else:
            return -lst[pos]
    elif (pos, sign) in vis:
        return rcd[pos][sign]
    elif sign == 0:
        rcd[pos][sign] = max(dp(pos+1, 0) + lst[pos], dp(pos+1, 1) - lst[pos])
        vis.add((pos, sign))
        return rcd[pos][sign]
    else:
        rcd[pos][sign] = max(dp(pos+1, 0) - lst[pos], dp(pos+1, 1) + lst[pos])
        vis.add((pos, sign))
        return rcd[pos][sign]

n = int(input())
lst = list(map(int, input().split()))
rcd = [[0, 0] for _ in range(n)]
vis = set()
print(dp(0, 0))

Submission status: Runtime Error

Solution code:
class Solution():
    def dp(self, pos, sign):
        if pos == self.n-1:
            if sign == 0:
                return +self.lst[pos]
            else:
                return -self.lst[pos]
        elif (pos, sign) in self.vis:
            return self.rcd[pos][sign]
        elif sign == 0:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) + self.lst[pos], self.dp(pos+1, 1) - self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]
        else:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) - self.lst[pos], self.dp(pos+1, 1) + self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]

    def run(self):
        self.n = int(input())
        self.lst = list(map(int, input().split()))
        if self.n != len(self.lst):
            while(True):
                pass
        self.rcd = [[0, 0] for _ in range(self.n)]
        self.vis = set()
        print(self.dp(0, 0))

solution = Solution()
solution.run()

Submission status: Runtime Error

Solution code:
class Solution():
    def dp(self, pos, sign):
        if pos == self.n-1:
            if sign == 0:
                return +self.lst[pos]
            else:
                return -self.lst[pos]
        elif (pos, sign) in self.vis:
            return self.rcd[pos][sign]
        elif sign == 0:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) + self.lst[pos], self.dp(pos+1, 1) - self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]
        else:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) - self.lst[pos], self.dp(pos+1, 1) + self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]

    def run(self):
        self.n = int(input())
        self.lst = list(map(int, input().split()))
        self.rcd = [[0, 0] for _ in range(self.n)]
        self.vis = set()
        print(self.dp(0, 0))

solution = Solution()
solution.run()

Submission status: Runtime Error

Solution code:
class Solution():
    def dp(self, pos, sign):
        if pos == self.n-1:
            if sign == 0:
                return +self.lst[pos]
            else:
                return -self.lst[pos]
        elif (pos, sign) in self.vis:
            return self.rcd[pos][sign]
        elif sign == 0:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) + self.lst[pos], self.dp(pos+1, 1) - self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]
        else:
            self.rcd[pos][sign] = max(self.dp(pos+1, 0) - self.lst[pos], self.dp(pos+1, 1) + self.lst[pos])
            self.vis.add((pos, sign))
            return self.rcd[pos][sign]

    def run(self):
        self.n = int(input())
        self.lst = list(map(int, input().split(' ')))
        self.rcd = [[0, 0] for _ in range(self.n)]
        self.vis = set()
        print(self.dp(0, 0))

solution = Solution()
solution.run()

Submission status: Runtime Error

Solution code:
# D - Flipping Signs
# https://atcoder.jp/contests/abc125/tasks/abc125_

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

rcd = [ [-1, -1] for _ in range(N) ]

def dp(pos, st):
    # terminal condition
    if pos == 0:
        if st == 0:
            return A[0]
        else:
            return -A[0]

    # if visit
    if rcd[pos][st] != -1:
        return rcd[pos][st]

    elif st == 0:
        # memorize
        rcd[pos][st] = max(dp(pos-1, 0) + A[pos], dp(pos-1, 1) + -A[pos])
        return rcd[pos][st]

    else: # st == 1
        # memorize
        rcd[pos][st] = max(dp(pos-1, 0) + -A[pos], dp(pos-1, 1) + A[pos])
        return rcd[pos][st]

print '{}'.format( max(dp(N-1, 0), dp(N-1, 1)) )

Submission status: Runtime Error

Solution code:
class Solution():
    def dp(self, pos, st):
        if pos == self.n-1:
            if st == 0:
                return self.lst[pos]
            else:
                return -self.lst[pos]
        elif self.rcd[pos][st] != -1:
            return self.rcd[pos][st]
        else:
            self.rcd[pos][st] = max(self.dp(pos+1, 0), self.dp(pos+1, 1))
            if st == 0:
                self.rcd[pos][st] += self.lst[pos]
            else:
                self.rcd[pos][st] -= self.lst[pos]
            return self.rcd[pos][st]

    def run(self):
        self.n = int(input())
        self.lst = list(map(int, input().split(' ')))
        self.rcd = [[-1, -1] for _ in range(self.n)]
        print(max(self.dp(0, 0), self.dp(0, 1)))

solution = Solution()
solution.run()

Submission status: Runtime Error

Solution code:
class Solution():
  def dp(self, pos, st):
    if pos == n-2:
      if st == 0:
        return sum(self.lst[pos:])
      else:
        return -sum(self.lst[pos:])
    elif rcd[pos][st] != -1:
      return rcd[pos][st]
    elif st == 0:
      rcd[pos][st] = max(self.dp(pos+1, st) + self.lst[pos], self.dp(pos+1, 1-st) + (1-self.lst[pos]))
      return rcd[pos][st]
    else:  # st == 1
      rcd[pos][st] = max(self.dp(pos+1, st) + (1-self.lst[pos]), self.dp(pos+1, 1-st) + self.lst[pos])
      return rcd[pos][st]

	def run(self):
      self.n = int(input())
      self.lst = map(int, input().split(' '))

      self.rcd = [[-1, -1] for _ in range(self.n)]
      print(max(self.dp(0, 0), self.dp(0, 1)))
  
solution = Solution()
solution.run()class Solution():
  def dp(self, pos, st):
    if pos == n-2:
      if st == 0:
        return sum(self.lst[pos:])
      else:
        return -sum(self.lst[pos:])
    elif rcd[pos][st] != -1:
      return rcd[pos][st]
    elif st == 0:
      rcd[pos][st] = max(self.dp(pos+1, st) + self.lst[pos], self.dp(pos+1, 1-st) + (1-self.lst[pos]))
      return rcd[pos][st]
    else:  # st == 1
      rcd[pos][st] = max(self.dp(pos+1, st) + (1-self.lst[pos]), self.dp(pos+1, 1-st) + self.lst[pos])
      return rcd[pos][st]

	def run(self):
      self.n = int(input())
      self.lst = map(int, input().split(' '))

      self.rcd = [[-1, -1] for _ in range(self.n)]
      print(max(self.dp(0, 0), self.dp(0, 1)))
  
solution = Solution()
solution.run()

Submission status: Runtime Error

Solution code:
class Solution():
  def dp(pos, st):
    if pos == n-2:
      if st == 0:
        return sum(self.lst[pos:])
      else:
        return -sum(self.lst[pos:])
    elif rcd[pos][st] != -1:
      return rcd[pos][st]
    elif st == 0:
      rcd[pos][st] = max(dp(pos+1, st) + self.lst[pos], dp(pos+1, 1-st) + (1-self.lst[pos]))
      return rcd[pos][st]
    else:  # st == 1
	  rcd[pos][st] = max(dp(pos+1, st) + (1-self.lst[pos]), dp(pos+1, 1-st) + self.lst[pos])
      return rcd[pos][st]
 
  def run():
    self.n = int(input())
    self.lst = map(int, input().split(' '))
 
    self.rcd = [[-1, -1] for _ in range(self.n)]
    print(max(dp(0, 0), dp(0, 1)))
  
solution = Solution()
solution.run()

Submission status: Runtime Error

Solution code:
class Solution():
  def dp(pos, st):
    if pos == n-2:
      if st == 0:
        return sum(self.lst[pos:])
      else:
        return -sum(self.lst[pos:])
    elif rcd[pos][st] != -1:
      return rcd[pos][st]
    elif st == 0:
      return rcd[pos][st] = max(dp(pos+1, st) + self.lst[pos], dp(pos+1, 1-st) + (1-self.lst[pos]))
    else:  # st == 1
      return rcd[pos][st] = max(dp(pos+1, st) + (1-self.lst[pos]), dp(pos+1, 1-st) + self.lst[pos])

  def run():
    self.n = int(input())
    self.lst = map(int, input().split(' '))

    self.rcd = [[-1, -1] for _ in range(self.n)]
    print(max(dp(0, 0), dp(0, 1)))
  
solution = Solution()
solution.run()

Submission status: Runtime Error

Solution code:
import sys

def dp(i,j, a):
    if i==0 and j==0:
        return 0
    elif i==0 and j==1:
        return -1 * sys.maxsize
    else:
        if j==0:
            return max(dp(i-1,0,a)+a[i-1], dp(i-1,1,a)-a[i-1])
        else:
            return max(dp(i-1,0,a)-a[i-1], dp(i-1,1,a)+a[i-1])
    


n=int(input())
a=[int(i) for i in input().split()]

print(dp(n, 0, a))

Submission status: Runtime Error

Solution code:
def dp(i,j, a):
    if i==0 and j==0:
        return 0
    elif i==0 and j==1:
        return -10**9
    else:
        if j==0:
            return max(dp(i-1,0,a)+a[i-1], dp(i-1,1,a)-a[i-1])
        else:
            return max(dp(i-1,0,a)-a[i-1], dp(i-1,1,a)+a[i-1])
    


n=int(input())
a=[int(i) for i in input().split()]

print(dp(n, 0, a))

Submission status: Runtime Error

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

numbers_abs = [abs(n) for n in numbers if n != 0]
sum_abs = sum(numbers_abs)
min_abs = min(numbers_abs)

count_negative = 0
count_zero = 0
for n in numbers:
  if (n < 0):
    count_negative += 1
  elif (n == 0):
    count_zero += 1

answer = sum_abs
if (count_negative % 2 == 1 and count_zero < 1):
  answer = sum_abs - 2 * min_abs

print(answer)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input()
A=list(map(int,input()))
s=0
for a in A:
  if a < 0:
    s += 1
S=0
if s % 2 == 0:
  S = sum([abs(a) for a in A])
else:
  B = [abs(a) for a in A]
  m = min(B)
  S = sum(B) - 2*m
print(S)

Submission status: Runtime Error

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 data <= 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: Runtime Error

Solution code:
input()
A=list(map(int,input()))
s=0
for a in A:
  if a < 0:
    s += 1
if s % 2 == 0:
  S = sum([abs(a) for a in A])
else:
  B = [abs(a) for a in A]
  m = min(B)
  S = sum(B) - 2*m
print(S)

Submission status: Runtime Error

Solution code:
def d_flipping_signs_dp(N, A):
    dp = [[0] * 2 for _ in range(N + 1)]
    dp[0][0] = 0
    dp[0][1] = -float('inf')
    for i in range(N):
        dp[i + 1][0] = max(dp[i][0] + A[i], dp[i][1] - A[i])
        dp[i + 1][1] = max(dp[i][0] - A[i], dp[i][1] + A[i])
    return dp[N][0]

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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_min = a.pop(a.index(min(a)))
ans = sum(a) - a_min
print(ans)

Submission status: Runtime Error

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

B = map(abs, A)
if len([a for a in A if a < 0]) % 2 == 1:
    print(sum(B) - min(B))
else:
    print(sum(B))

Submission status: Runtime Error

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

    if N == 2:
        print(max(A[0]+A[1], (-A[0])+(-A[1])))
        return

    a_sum, a1, a2 = 0, A[0], A[1]
    b_sum, b1, b2 = 0, -A[0], -A[1]
    for i in range(2, N):
        #print(a_sum, a1, a2)
        #print(b_sum, b1, b2)
        #print(A[i])


        if (a_sum + a1 + a2 + A[i]) > (b_sum + b1 + b2 + A[i]):
            new_a_sum = a_sum + a1
            new_a1 = a2
            new_a2 = A[i]
        else:
            new_a_sum = b_sum + b1
            new_a1 = b2
            new_a2 = A[i]
        a_sum, a1, a2 = new_a_sum, new_a1, new_a2
        b_sum, b1, b2 = new_b_sum, new_b1, new_b2

    print(max(a_sum+a1+a2, b_sum+b1+b2))

main()

Submission status: Runtime Error

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

def dp(i, j):
	if i==0 and j==0:
		return 0
	elif i == 0 and j==1:
		return -10**9
	elif j==0:
		return max(dp(i-1,0)+ai[i-1], dp(i-1,1)-ai[i-1])
	else:
		return max(dp(i-1,0)-ai[i-1], dp(i-1,1)+ai[i-1])

print(dp(n,0))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
count_m = 0
count_z = 0

for i in A:
  if i < 0:
    count_m += 1
  elif i == 0:
    count_z += 1

A_abs = [abs(i) for i in A]
if count_m%2 == 0 or (count_m+count_z)%2 == 0:
  print(sum(A_abs))
  
else:
  A_min = A.index(min(A_abs))
  A_abs[A_min] = A_min[A_min]*(-1)
  print(sum(A_abs))

Submission status: Runtime Error

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

dp = [[]]

def dp(i, j):
	if i==0 and j==0:
		return 0
	elif i == 0 and j==1:
		return -10**11
	elif j ==0:
		return max(dp(i-1,0)+ai[i-1], dp(i-1,1)-ai[i-1])
	else:
		return max(dp(i-1,0)-ai[i-1], dp(i-1,1)+ai[i-1])

print(dp(n,0))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
B = list(map(abs,a))
C = [a for a in A if a < 0]

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
n = int(input())
A = list(map(int,input().split()))
b = list(map(abs,a))
c = [a for a in A if a < 0]

if len(c) % 2 == 0:
    print(sum(b))
else:
    print(sum(b)-min(b)*2)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
b = list(map(abs,a))
c = list(a for a in A if a < 0)

if len(c) % 2 == 0:
    print(sum(b))
else:
    print(sum(b)-min(b)*2)

Submission status: Runtime Error

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

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

print (ans)

Submission status: Runtime Error

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)
print(s if len(ma)%2==0 or t==1 else max(s+ma[-1]*2,s-pa[0]*2))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
d=0
z=0
s=0
for i in range(n):
  if l[i]<0:
    d+=1
  elif l[i]=0:
    z+=1
if d%2==0 or (d+z)%2==0:
  for i in range(n):
    s+=abs(l[i])
  print(s)
else:
  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: Runtime Error

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
    
ans = long(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: Runtime Error

Solution code:
n=int(input())
l=list(map(int,input().split()))
a=abs(l[0])
m=0
d=0
z=0
for i in range(n):
  if l[i]<0:
    d+=1
  elif l[i]=0:
    z+=1
if d%2==0 or (d+z)%2==0:
  for i in range(n):
    s+=abs(l[i])
  print(s)
else:
  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: Runtime Error

Solution code:
def main():
    _ = input()
    A = map(int, input())
 
    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: Runtime Error

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])
abs_A = (abs(i) for i in A)
if len(minus) % 2 == 0:
  print(sum(abs_A))
else:
  print(sum(abs_A)-min(abs_A)*2)

Submission status: Runtime Error

Solution code:
from sys import stdin
 
readline = stdin.readline
 
def main():
    _, *A = map(int, open(0).read().split())
 
    B = tuple(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: Runtime Error

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
count_m = 0
count_z = 0

for i in A:
  if i < 0:
    count_m += 1
  elif i == 0:
    count_z += 1

A_abs = [abs(i) for i in A]
if count_m%2 == 0 or (count_m+count_z)%2 == 0:
  print(sum(A_abs))
  
else:
  A_min = A.index(min(A_abs))
  A_abs[A_min] = A[A_min]*(-1)
  print(sum(A_abs))

Submission status: Runtime Error

Solution code:
from sys import stdin

readline = stdin.readline

def main():
    _, *A = map(int, open(0).read().split())
 
    B = 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: Runtime Error

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
count_m = 0
count_z = 0

for i in A:
  if i < 0:
    count_m += 1
  elif i == 0:
    count_z += 1

A_abs = [abs(i) for i in A]
if count_m%2 == 0 || (count_m+count_z)%2 == 0:
  print(sum(A_abs))
  
else:
  A_min = A.index(min(A_abs))
  A_abs[A_min] = A[A_min]*(-1)
  print(sum(A_abs))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
count_m = 0
count_z = 0

for i in A:
  if i < 0:
    count_m += 1
  elif i == 0:
    count_z += 1

A_abs = [abs(i) for i in A]
if count_m%2 == 0 || count_m+count_z%2 == 0:
  print(sum(A_abs))
  
else:
  A_min = A.index(min(A_abs))
  A_abs[A_min] = A[A_min]*(-1)
  print(sum(A_abs))

Submission status: Runtime Error

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)+B)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(int(i) for i in input().split())
count = 0

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

A_abs = [abs(i) for i in A]
if count%2 == 0:
  print(sum(A_abs))
  
else:
  A_min = A.index(min(A_abs))
  A_abs[A_min] = A[A_min]*(-1)
  print(sum(A_abs))

Submission status: Runtime Error

Solution code:
N = int(input())
Alist = list(map(float, input().split()))
memo = [{} for i in range(N)]

def ddp(cur_N, ai):
    if ai in memo[cur_N]:
        return memo[cur_N][ai]
    if cur_N >=N-1:
        return ai
    aj = Alist[cur_N+1]
    ret = max([ai + ddp(cur_N+1, aj), -1*ai + ddp(cur_N+1, -1*aj)])
    memo[cur_N][ai] = ret
    return ret
print(int(ddp(0, Alist[0])))

Submission status: Runtime Error

Solution code:
N = int(input())
a = input().split()
num=[]
numabs=[]
tex=[]
count=0
for i in range(N):
	num.append(int(a[i]))
	numabs.append(abs(num[i]))
	if num[i] < 0 :
		count +=1
	elif num[i] == 0:
		count2 +=1
if count%2 ==0 or count2 > 0:
	res = sum(num)
else:
	res =sum(num)-2*min(numabs)
print(res)

Submission status: Runtime Error

Solution code:
N = int(input())
Alist = list(map(int, input().split()))
memo = [{} for i in range(N)]

def ddp(cur_N, ai):
    if ai in memo[cur_N]:
        return memo[cur_N][ai]
    if cur_N >=N-1:
        return ai
    aj = Alist[cur_N+1]
    ret = max([ai + ddp(cur_N+1, aj), -1*ai + ddp(cur_N+1, -1*aj)])
    memo[cur_N][ai] = ret
    return ret
print(ddp(0, Alist[0]))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split(" ")))
for i in range(1, n-1):
    print(a)
    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: Runtime Error

Solution code:
n=int(input())
v=[int(x) for x in input().split()]
c=v[0]+v[1]
for i in range(n-1):
    d=v[i]+v[1+1]
    if c>d:
        c=d
e=sum(v)-2*c
print(int(e))

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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

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

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

Submission status: Runtime Error

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
        negtive.append()

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys,collections as cl
import fractions
from functools import reduce
import copy
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[i]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
　　

n = int(input())
su = 0

a = l()

co = 0
k = 0
a.sort()
f = 0
for i in range(n):
	if a[i] < 0:
		co += 1
if co % 2 == 0:
	for i in range(n):
		su += abs(a[i])
	print(su)
else:
	for i in range(n):
		if f == 2 or a[i] == 0:
			break
		if a[i] >= 0 and f == 0:
			kk = a[i-1]
			f = 1
		if a[i] >= 0:
			if abs(a[0]) >= a[i]:
				k = a[i]*(-2)
			else:
				k = kk*2
			f = 2
		elif i == n-1:
			k = a[i]*2
	for i in range(n):
		su += abs(a[i])
	su += k
	print(su)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
 
n = int(input())
l = np.array([int(x) for x in input().split()])
ans = 0
if 0 in l:
  for i in range(n):
    ans += abs(l[i])
  print(ans)
  sys.exit()
m = abs(l[0])
for i in range(n):
  if l[i] < 0:
    p += 1
  if m < abs(l[i]):
    m = abs(l[i])
for i in range(n):
  ans += abs(l[i])
if p % 2 == 0:
  print(ans)
else:
  print(ans - m*2)

Submission status: Runtime Error

Solution code:
N = int(input())
a = input().split()
num=[]
tex=[]
count=0
for i in range(N):
	num.append(int(a[i]))
	if num[i] < 0 :
		count +=1
	elif num[i] == 0:
		count2 +=1
if count%2 ==0 or count2 > 0:
	res = sum(num)
else:
	tex=[i for i, x in enumerate(num) if x <0]
	res =sum(num)-min(tex[0],tex[-1])
print(res)

Submission status: Runtime Error

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

sum = 0
B = []
for i in range(A):
  B.append(abs(A[i]))
  
B.remove(min(B))
for i in range(B):
  sum += B[i]
  
print(sum)