TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
import numpy as np

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

ary = []

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

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

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)

import numpy as np

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

ary = []

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

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

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)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
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)

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)

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)

input()
A=list(map(int,input().split()))
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)

Verdicts: Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
dp=[[0,0]for _ in range(n)]
dp[0]=[a[0],-a[0]]
for i in range(1,n):
  dp[i][0]=max(dp[i-1][0]+a[i],dp[i-1][1]-a[i])
  dp[i][1]=max(dp[i-1][0]-a[i],dp[i-1][1]+a[i])
for i in dp:print(i)
print(dp[n-1][0])

n=int(input())
a=list(map(int,input().split()))
dp=[[0,0]for _ in range(n)]
dp[0]=[a[0],-a[0]]
for i in range(1,n):
  dp[i][0]=max(dp[i-1][0]+a[i],dp[i-1][1]-a[i])
  dp[i][1]=max(dp[i-1][0]-a[i],dp[i-1][1]+a[i])
print(dp[n-1][0])

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
i = 10**9
s = 0
z = 0
c = 0
for b in a:
  if b < 0:
    s += 1
  elif b == 0:
    z += 1
  if abs(b) < i:
    i = abs(b)
  c += abs(b)
print(s,z,c)
if z > 0 or s%2 == 0:
  print(c)
else:
  print(c-2*i)

n = int(input())
a = list(map(int,input().split()))
i = 10**9
s = 0
z = 0
c = 0
for b in a:
  if b < 0:
    s += 1
  elif b == 0:
    z += 1
  if abs(b) < i:
    i = abs(b)
  c += abs(b)
if z > 0 or s%2 == 0:
  print(c)
else:
  print(c-2*i)

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
absmin = 0
minnum = 0
for i in range(n):
  if abs(a[i]) < abs(a[absmin]):
    i = absmin
  if a[i] <= 0:
    minnum += 1
  a[i] = abs(a[i])
if minnum % 2 == 1:
  a[absmin] = -1 * abs(a[absmin])
ans = 0
for i in range(n):
  ans += a[i]
print(ans)

n = int(input())
a = list(map(int, input().split()))
absmin = 0
minnum = 0
for i in range(n):
  if abs(a[i]) < abs(a[absmin]):
    absmin = i
  if a[i] <= 0:
    minnum += 1
  a[i] = abs(a[i])
if minnum % 2 == 1:
  a[absmin] = -1 * abs(a[absmin])
ans = 0
for i in range(n):
  ans += a[i]
print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
L = list(map(int,input().split()))

def sel2(a,b,c):
    if a <= 0 and b <= 0 and c >= 0:
        return (-a,-b,c)
    elif a >= 0 and b <= 0 and c <= 0:
        return (a,-b,-c)
    elif a <= 0 and b >= 0 and c <= 0:
        return (-a,b,-c)
def sel1(a,b,c):
    if a <= 0 and b >= 0 and c >= 0:
        if abs(a) >= abs(b):
            return (-a,-b,c)
        else:
            return (a,b,c)
    elif a >= 0 and b <= 0 and c >= 0:
        if abs(b) == min(abs(a),abs(b),abs(c)):
            return (a,b,c)
        elif abs(a) > abs(c):
            return (a,-b,-c)
        elif abs(a) < abs(b):
            return (-a,-b,c)
    elif a >= 0 and b >= 0 and c <= 0:
        if abs(b) >= abs(c):
            return (a,-b,-c)
        else:
            return (a,b,c)
def selend(a,b):
    if a < 0 and b < 0:
        return (-a,-b)
    elif a < 0 and b > 0:
        if abs(a) > abs(b):
            return (-a,-b)
        elif abs(a) < abs(b):
            return (a,b)
    elif a > 0 and b < 0:
        if abs(a) > abs(b):
            return (a,b)
        elif abs(a) < abs(b):
            return (-a,-b)
for i in range(0,n//3+1,3):
    (p,q,r) = sel2(L[i],L[i+1],L[i+2])
    L[i] = p
    L[i+1] = q
    L[i+2] = r
#print(L)
(s,t) = selend(L[-2],L[-1])
L[-2] = s
L[-1] = t
#print(L)
print(sum(L))

n = int(input())
L = list(map(int,input().split()))
L1 = len([x for x in L if x < 0])
L.sort()
for i in range(n):
  if L[i] < 0:
    L[i] = -L[i]
#print(L)
if L1%2 == 0:
  print(sum(L))
else:
  print(sum(L)-2*min(L))

Verdicts: Runtime Error

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

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
box = []

for num in range(n):
    box.append(abs(a[num]))

box.sort()

box[0] = -box[0]

print(sum(box))

n = int(input())
a = list(map(int, input().split()))
pbox = []
nbox = []
if 0 in a:
    count = 0
    for i in a:
        count += abs(i)
    print(count)
else:
    for i in a:
        if i > 0:
            pbox.append(i)
        else:
            nbox.append(i)
    if len(nbox) % 2 == 0:
        count = 0
        for i in a:
            count += abs(i)
        print(count)
    else:
        box = []
        for i in a:
            box.append(abs(i))
        mi = min(box)
        count = 0
        for i in a:
            count += abs(i)
        print(count - 2*mi)

Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split(" ")))
dp = [[0 for i in range(2)] for i in range(n)]

dp[1][0] = a[0] + a[1]
dp[1][1] = -(a[0] + a[1])

for i in range(2, n):
    dp[i][0] = max(dp[i-1][0]+a[i], dp[i-1][1]+a[i])
    dp[i][1] = max(dp[i-1][0]+(-2*a[i-1])+(-a[i]), dp[i-1][1]+2*a[i-1]+(-a[i]))

for i in range(2):
    for j in range(n):
        print(dp[j][i], end=" ")
    print()

print(max(dp[n-1][0], dp[n-1][1]))


n = int(input())
a = list(map(int, input().split(" ")))
dp = [[0 for i in range(2)] for i in range(n)]

dp[1][0] = a[0] + a[1]
dp[1][1] = -(a[0] + a[1])

for i in range(2, n):
    dp[i][0] = max(dp[i-1][0]+a[i], dp[i-1][1]+a[i])
    dp[i][1] = max(dp[i-1][0]+(-2*a[i-1])+(-a[i]), dp[i-1][1]+2*a[i-1]+(-a[i]))

print(max(dp[n-1][0], dp[n-1][1]))



Verdicts: Wrong Answer

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

Submission attempts (in order):
N, *A = map(int, open(0).read().split())
n = N//3 + (1 if N % 3 == 0 else 2)
cur_i = []

for i in range(n):
    a = A[i]
    b = A[i+1]
    c = A[i+2]

    if a < 0 and b < 0 and c < 0:
        if A[i-1] * -1 > A[i+3] * -1:
            cur_i.append(i-1)
        else:
            cur_i.append(i+3)

ans = 0
for i, a in enumerate(A):
    if i in cur_i:
        ans += a * -1
    else:
        ans += abs(a)

print(ans)


N, *A = map(int, open(0).read().split())
negative_num = sum(1 if a < 0 else 0 for a in A)
positive_num = list(abs(n) for n in A)

if negative_num % 2 == 0:
    print(sum(positive_num))
else:
    print(sum(positive_num) - 2*min(positive_num))


Verdicts: Runtime Error

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

Submission attempts (in order):
n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
if n%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min

n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
if n%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min

print(ans)

n=int(input())
a=[int(i) for i in input().split()]
from itertools import combinations
import copy
n=5
a=[10, -4, -8, -11, 3]
b=[i for i in range(n-1)]
c=[v for i in range(1,n) for v in combinations(b, i)]
sum_temp=sum(a)
for v in c:
    a_temp=copy.copy(a)
    for i in v:
        a_temp[i]*=-1
        a_temp[i+1]*=-1
    if sum_temp<sum(a_temp):
        sum_temp=sum(a_temp)
print(sum_temp)

n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
a_neg=sum([1 if i>=0 else 0 for i in a])
if a_neg%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min
print(ans)

n=int(input())
a=[int(i) for i in input().split()]
ans=None
a_pos=[abs(i) for i in a]
a_min=min(a_pos)
a_neg=sum([1 if i<0 else 0 for i in a])
if a_neg%2==0:
    ans=sum(a_pos)
else: ans=sum(a_pos)-2*a_min
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
N = int(input())
lst_A =list(map(int, input().split()))
neg_count = 0
zero_count = 0
total = 0

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

count = 0
for i, x in enumerate(A):
	if x < 0:
		count += 1
		A[i] *= -1
print(count)
if count % 2 == 0:
	print(sum(A))
else:
	print(A)
	print(sum(A)-2*min(A))


import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

count = 0
for i, x in enumerate(A):
	if x < 0:
		count += 1
		A[i] *= -1
# print(count)
if count % 2 == 0:
	print(sum(A))
else:
	# print(A)
	print(sum(A)-2*min(A))


Verdicts: Wrong Answer

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

Submission attempts (in order):
N=int(input())
A = [int(i) for i in input().split()]
cnt=0
ans=0
B=[]
for i in range(N):
    if A[i]<0:
        cnt+=1
if cnt%2==0:
    ans=sum(abs(A))
    print(ans)
else:
    for i in range(N):
        if A[i]<0:
            B.append(A[i])
    max(B)
    ans=sum(abs(A))
    ans=ans+2*B
    print(ans)

N=int(input())
A = [int(i) for i in input().split()]
cnt=0
ans=0
B=[]
C=[]
for i in range(N):
    B.append(abs(A[i]))
for i in range(N):
    if A[i]<0:
        C.append(A[i])
if len(C)%2==0:
    ans=sum(B)
    print(ans)
else:
    sel=min(B)
    print(sum(B)-2*abs(sel))

Verdicts: Runtime Error

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

Submission attempts (in order):
import numpy as np

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



A_abs = np.abs(A)

if 0 in A:
    print(np.sum(A_abs))

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

    if num % 2 == 0:
        print(np.sum(A_abs))
    else:
        print(np.sum(A_abs) - 2 * min(A_abs))

import numpy as np

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



A_abs = np.abs(A)

if 0 in A:
    print(np.sum(A_abs))

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

    if num % 2 == 0:
        print(np.sum(A_abs))
    else:
        print(np.sum(A_abs) - 2 * min(A_abs))


Verdicts: Runtime Error

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

Submission attempts (in order):
# -*- 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)

# -*- coding: utf-8 -*-

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

cnt = 0
abs_A = []
for i in range(N):
    if A[i] < 0:
        cnt += 1
        abs_A.append(-A[i])
    else:
        abs_A.append(A[i])
ans = sum(abs_A)
if cnt % 2 != 0:
    ans -= 2*min(abs_A)

print(ans)

Verdicts: Runtime Error

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

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
aabs = [i if i>=0 else i*(-1) for i in a]
MIN = min(aabs)
ans = 0
mcount = 0

for i in range(n):
  if a[i] < 0:
    mcount += 1
    
if mcount%2 == 0:
  for i in a:
    ans += abs(i)
    print(ans)
else:
  for i in a:
    ans += abs(i)
  print(ans - 2*MIN)
  


n = int(input())
a = list(map(int,input().split()))
aabs = [i if i>=0 else i*(-1) for i in a]
MIN = min(aabs)
ans = 0
mcount = 0

for i in range(n):
  if a[i] < 0:
    mcount += 1
    
if mcount%2 == 0:
  for i in a:
    ans += abs(i)
  print(ans)
else:
  for i in a:
    ans += abs(i)
  print(ans - 2*MIN)

Verdicts: Wrong Answer

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

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))

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

res = sum(absA)-min(absA)
print(res)


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

c=0
absA=[0 for i in range(N)]
for i in range(N):
    if A[i] <=0:
        c+=1
    absA[i]=abs(A[i])

if c%2==0:
    res = sum(absA)
else:
    res = sum(absA)-min(absA)*2
print(res)


Verdicts: Wrong Answer

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

Submission attempts (in order):
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)

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


Verdicts: Wrong Answer

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

Submission attempts (in order):
n = int(input())
a = list(map(abs, map(int, input().split())))
print(sum(a)-min(a))

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

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

a = list(map(abs, a))
total = sum(a)

if cnt % 2 ==  0:
    print(total)
else:
    print(total - 2 * min(a))


Verdicts: Wrong Answer

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

Submission attempts (in order):
import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = list(map(int, input().split()))
INF = 10**9

dp = [[0]*2 for _ in range(n+1)]　

dp[0][0] = 0 
dp[0][1] = -INF

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

print(dp[n][0]) 

import sys
sys.setrecursionlimit(10**6)

n = int(input())
A = list(map(int, input().split()))
INF = 10**9

dp = [[0]*2 for _ in range(n+1)] 

dp[0][0] = 0 
dp[0][1] = -INF

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

print(dp[n][0]) 

Verdicts: Runtime Error

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

Submission attempts (in order):
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)

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

Verdicts: Runtime Error

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

Submission attempts (in order):
import numpy as np

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

if 0 in A:
  print(np.sum(A))
else:
  print(np.sum(A) - np.min(A))

import numpy as np

n = int(input())
A = np.array(list(map(int,input().split())))
minus = np.count_nonzero(A < 0)
A = np.abs(A)

if minus % 2 == 0:
  print(np.sum(A))
else:
  print(np.sum(A) - 2 * np.min(A))

Verdicts: Wrong Answer

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

Submission attempts (in order):
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    ans = 0
    for i in range(N-1):
        if A[i] < 0:
            A[i] *= -1
            A[i+1] *= -1
    print(A)

    return sum(A)


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    for i in range(N-1):
        if A[i] < 0:
            A[i] *= -1
            A[i+1] *= -1
    a_sum =sum(A)

    aa = list(map(abs, A))
    return max(a_sum, sum(aa) - 2*min(aa))


def main():
    N = read_int()
    A = read_int_n()
    print(slv(N, A))


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

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

Submission attempts (in order):
N=int(input())
A=list(map(int,input().split()))
pbox=[]
nbox=[]
if 0 in A:
  count=0
  for i in A:
    count += abs(i)
  print(count)
else:
  for i in a:
    if i > 0:
      pbox.append(i)
    else:
      nbox.append(i)
  if len(nbox)%2==0:
    count=0
    for i in a:
      count += abs(i)
    print(count)
  else:
    box=[]
    for i in a:
      box.append(abs(i))
    mi=min(box)
    count=0
    for i in a:
      count += abs(i)
    print(count-2*mi)

N=int(input())
A=list(map(int,input().split()))
pbox=[]
nbox=[]
if 0 in A:
  count=0
  for i in A:
    count += abs(i)
  print(count)
else:
  for i in A:
    if i > 0:
      pbox.append(i)
    else:
      nbox.append(i)
  if len(nbox)%2==0:
    count=0
    for i in A:
      count += abs(i)
    print(count)
  else:
    box=[]
    for i in A:
      box.append(abs(i))
    mi=min(box)
    count=0
    for i in A:
      count += abs(i)
    print(count-2*mi)

Verdicts: Runtime Error

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

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
for i in a:
    i=abs(i)
print(sum(a))

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

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

Verdicts: Wrong Answer

Runtime Error

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

Submission attempts (in order):
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()


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]

        if (a_sum + a1 - a2 - A[i]) > (b_sum + b1 - b2 - A[i]):
            new_b_sum = a_sum + a1
            new_b1 = -a2
            new_b2 = -A[i]
        else:
            new_b_sum = b_sum + b1
            new_b1 = -b2
            new_b2 = -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()


Verdicts: Runtime Error

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

Submission attempts (in order):
import fractions
import functools
N = int(input())
A = [int(i) for i in input().split()] 
max_gcd = functools.reduce(fractions.gcd, A)
for i in range(N):
	tmp = A.copy()
	if A[i]%2==1:
		tmp.pop(i)
		gcd = functools.reduce(fractions.gcd, tmp)
	else:
		gcd = functools.reduce(fractions.gcd, tmp)
	if max_gcd < gcd:
		max_gcd = gcd
print(max_gcd)


import numpy as np

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

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


import numpy as np

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


import numpy as np

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

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


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
dp = [[0,0]]*(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])

print(dp[n][0])
  



n = int(input())
a = list(map(int,input().split()))
dp = [[0]*2 for _ in range(n+1)]
dp[0][0] = 0
dp[0][1] = -10**10

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



Verdicts: Wrong Answer

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

Submission attempts (in order):
import numpy as np

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

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(A))
else:
  print(sum(A[1 :] - A[0]))

import numpy as np

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

ab = len([n for n in A if n <0]) % 2

B = np.sort(np.abs(A))
if ab == 0:
  print(sum(B))
else:
  print(sum(B[1 :]) - B[0])


Verdicts: Runtime Error

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

Submission attempts (in order):
n=int(input())
aa=(map(int,input().split()))
aa.append(0)
aaa=tuple(a)
a=list(aaa)
for i in range(n-1):
    if a[i]<0:
        a[i]=-1*a[i]
        a[i+1]=-1*a[i+1]
b=list(aaa)
for i in range(n,0,-1):
    if b[i]<0:
        b[i]=-1*b[i]
        b[i-1]=-1*b[i-1]

print(max(sum(a),sum(b))


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


n=int(input())
a=list(map(int,input().split()))
a.append(0)
sum_a=sum(a)
x=[-100000000000]*(n+1)
x[0]=sum_a
for i in range(n-1):
    a[i]=-1*a[i]
    a[i+1]=-1*a[i+1]
    xx=x[i]+2*a[i]+2*a[i+1]
    if xx>=x[i]:
        x[i+1]=xx
    else:
        a[i]=-1*a[i]
        a[i+1]=-1*a[i+1]
        x[i+1]=0

print(x)
print(max(x))

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


n=int(input())
a=list(map(int,input().split()))
print(sum(a)-2*a[-1])


n=int(input())
a=list(map(int,input().split()))
c=0
for i in range(n):
    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))


Verdicts: Runtime Error

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if a[i] == 0:
        cnt -= 1000000000000
        break
    elif a[i] < 0:
        cnt += 1
a = [abs(a[i]) for i in range(n)]
if cnt < 0 or num % 2 == 0:
    print(sum(a))
else:
    print(sum(a) - 2*min(a))

n = int(input())
a = list(map(int,input().split()))
cnt = 0
for i in range(n):
    if a[i] == 0:
        cnt -= 1000000000000
        break
    elif a[i] < 0:
        cnt += 1
a = [abs(a[i]) for i in range(n)]
if cnt < 0 or cnt % 2 == 0:
    print(sum(a))
else:
    print(sum(a) - 2*min(a))

Verdicts: Runtime Error

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

Submission attempts (in order):
n = int(input())
a = list(map(int,input().split()))
neg = 0
r = 
for i in a:
  r = r + abs(i)
  if i < 0 :
     neg = neg + 1
if neg % 2 != 0:
  s = 10000000000
  for i in a:
    s = min(s,abs(i))
  r = r - 2*s
  
print(r)

  


n = int(input())
a = list(map(int,input().split()))
neg = 0
for i in a:
  r = r + abs(i)
  if i < 0 :
     neg = neg + 1
if neg % 2 != 0:
  s = 10000000000
  for i in a:
    s = min(s,abs(i))
  r = r - 2*s
  
print(r)

  

n = int(input())
a = list(map(int,input().split()))
neg = 0
r=0
for i in a:
  r = r + abs(i)
  if i < 0 :
     neg = neg + 1
if neg % 2 != 0:
  s = 10000000000
  for i in a:
    s = min(s,abs(i))
  r = r - 2*s
  
print(r)

  


Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
count=0
countk=0
saidaiti=0
while True:
    saidaiti=saidaiti+abs(a[count])
    count=count+1
    if a[count]%2==1:
        countk=countk+1
    if count==n:
        break
if countk%2==1:
    saidaiti=saidaiti-2*a[-1]
print(saidaiti)

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

Verdicts: Runtime Error

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

Submission attempts (in order):
def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(lambda x: abs(x), A))
    print(sum(B) - 2 * min(B))


if __name__ == '__main__':
    main()


def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = [None] * n
    cnt = 0
    for i in range(n):
        if A[i] <= 0:
            cnt += 1
        B[i] = abs(A[i])
    print(sum(B) - 2 * min(B) if cnt % 2 == 1 else sum(B))


if __name__ == '__main__':
    main()


Verdicts: Wrong Answer

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

Submission attempts (in order):
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
ans=np.sum(np.abs(A))-2*np.min(np.abs(A))
print(ans)

import numpy as np

def rev(i):
    if i==0:
        return 1
    return 0

N=int(input())
A=np.array(list(map(int,input().split())))
s=[]
for i in range(N):
    if A[i]>=0:
        s.append(1)
    else:
        s.append(0)

s[::-1]
for i in range(N-1):
    if s[i]==0:
        s[i]=1
        s[i+1]=rev(s[i+1])
if np.sum(s)!=N:
    ans=np.sum(np.abs(A))-2*np.min(np.abs(A))
    print(ans)
else:
    print(np.sum(np.abs(A)))

Verdicts: Wrong Answer

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

Submission attempts (in order):
# -*- coding: utf-8 -*-
N = int(input())
A = [int(v) for v in input().split(' ')]




sign = 1
for a in A:
    sign *= a/abs(a)
    
if sign > 0:
    print(sum(A))
else:
    print(sum(A)-min(A))

# -*- coding: utf-8 -*-
N = int(input())
A = [int(v) for v in input().split(' ')]




sign = 1
for a in A:
    if a != 0:
        sign *= a/abs(a)

abs_A = [abs(a) for a in A]

if sign > 0:
    print(sum(abs_A))
else:
    print(sum(abs_A)-min(abs_A)*2)

Verdicts: Runtime Error

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

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
count=0
flag=1
num=10*9+1
for i in range(n):
  if a[i]<0:
    count+=1
    a[i]*=-1
  elif a[i]==0:
    flag=0
  if num>a[i]:
    num=a[i]
if count%2==0 or flag=0:
  print(sum(a))
else:
  print(sum(a)-2*num)

n=int(input())
a=list(map(int,input().split()))
count=0
flag=1
num=10*9+1
for i in range(n):
  if a[i]<0:
    count+=1
    a[i]*=-1
  elif a[i]==0:
    flag=0
if count%2==0 or flag==0:
  print(sum(a))
else:
  print(sum(a)-2*min(a))

Verdicts: Runtime Error

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

Submission attempts (in order):
import sys
input = sys.stdin.read


n=int(input())
lsta=list(map(int, input().split()))

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

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

if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))

import sys
input = sys.stdin.read

n=int(input())
lsta=list(map(int,input().split()))

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

for i in range(n-1):
    if lsta[i]<0:
        lsta[i]=lsta[i]*(-1)
        lsta[i+1]=lsta[i+1]*(-1)
        print(lsta)


if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))

#import sys
#input = sys.stdin.read

n=int(input())
lsta=list(map(int, input().split()))

abslsta=[abs(v) for v in lsta]
min_index=abslsta.index(min(abslsta))

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

if lsta[n-1]<0:
    if min_index==n-1:
        print(sum(lsta))

    else:
        print(sum(lsta)-lsta[n-1]*2-lsta[min_index]*2)

else:
    print(sum(lsta))

Verdicts: Runtime Error

Runtime Error

Accepted