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

N = int(input())
a = input().split()
num=[]
tex=[]
count
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)


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)
             

N = int(input())
a = input().split()
num=[]
numabs=[]
tex=[]
count=0
count2=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(numabs)
else:
	res =sum(numabs)-2*min(numabs)
print(res)
             

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

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)

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=min(absA)
  
print(sum(absA)-minus*2)

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):
import math
N=int(input())
A=list(map(int, input().split()))
A=list(map(math.fabs, A))
A.sort()
print(sum(A[1:]-A[0]))

N=int(input())
A=list(map(int, input().split()))
A=list(map(lambda x:-x if x < 0 else x, A))
A.sort()
print(sum(A[1:]-A[0]))

N=int(input())
A=list(map(int, input().split()))
A=list(map(abs, A))
A.sort()
print(sum(A[1:]-A[0]))

N=int(input())
A=list(map(int, input().split()))
A=list(map(abs, A))
A.sort()
print(sum(A[1:])-A[0])

N=int(input())
A=list(map(int, input().split()))
cnt=0
for i in range(N):
  if A[i]<0:
    A[i]*=-1
    cnt+=1
A=list(map(abs, A))
A.sort()
if cnt&1==0:
  print(sum(A))
else:
  print(sum(A[1:])-A[0])

Verdicts: Runtime Error

Runtime Error

Runtime Error

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()))
if n&1:
    print(sum(list(map(abs,a)))-2*min(list(map(abs,a))))
else:
    print(sum(list(map(abs,a))))


n=int(input())
a=list(map(int,input().split()))
n=sum(list(map(lambda x: x<0,a)))
c0=sum(list(map(lambda x: x==0,a)))
if c0:
    print(sum(list(map(abs,a))))
    exit(0)
if n&1:
    print(sum(list(map(abs,a)))-2*min(list(map(abs,a))))
else:
    print(sum(list(map(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):
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**18

for i in range(1, N):
    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(max(dp[N-1][0], dp[N-1][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**18

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

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) % 2 == 0:
    print(S)
else:
    print(S - 2 * min([abs(i) for i in 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=[0]*n
a=map(int,input().split())
    
z=0
result=0
min=1000000002

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

    i=abs(i)
    result+=i
    if i<min:
        min=i

if z//2==1:
    result-=min*2

print(result)

n=int(input())
a=[0]*n
a=map(int,input().split())
    
z=0
result=0
min=1000000002

for i in a:
    if i<0:
        z+=1
    result+=abs(i)
    if abs(i)<min:
        min=abs(i)

if z%2==1:
    result-=min*2

print(result)

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()))
sum = 0
minus_count = 0
zero_flag = 0
min_ind = 0

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

if zero_flag ==1:
	for i in range(n):
		sum += abs(a[i])
elif minus_count % 2 == 0:
	for i in range(n):
		sum += abs(a[i])
else:
	for i in range(n):
	min_ind = a[a.index(min(a))]
		sum += abs(a[i])
		sum -= abs(a[min_ind])

print(sum)

n = int(input())
a = list(map(int, input().split()))
new_a = []
sum = 0
minus_count = 0

for i in range(n):
	new_a.append(abs(a[i]))

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

if minus_count % 2 == 0:
	for i in range(n):
		sum += abs(a[i])
else:
	for i in range(n):
		sum += new_a[i]
	sum = sum - min(new_a) * 2

print(sum)

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.readline
N=int(input())
num = list(map(int,input().split()))
c=0
ans=0
for i in range(N):
  if num[i]<0:
    c+=1 
ans = list(map(lambda x: abs(x),num))
if c%2==0:
  print(ans)
else:
  print(sum(ans) - min(num,key=lambda x: abs(x))*2)

import sys
input=sys.stdin.readline
N=int(input())
num = list(map(int,input().split()))
c=0
ans=0
for i in range(N):
  if num[i]<0:
    c+=1 
ans = list(map(lambda x: abs(x),num))
if c%2==0:
  print(sum(ans))
else:
  print(sum(ans) - min(ans,key=lambda x: abs(x))*2)

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())
x = [int(x) for x in input().split()]
dp = [[0 for _ in range(2)] for _ in range(N+1)]
dp[0][0] = 0
dp[0][1] = -10**9
for i in range(N-1):
  dp[i+1][0] = max(dp[i][0]+x[i],dp[i][1]-x[i])
  dp[i+1][1] = max(dp[i][0]-x[i],dp[i][1]+x[i])
print(max(dp[N][0],dp[N][1]))

N = int(input())
x = [int(x) for x in input().split()]
dp = [[0 for _ in range(2)] for _ in range(N+1)]
dp[0][0] = 0
dp[0][1] = -10**9
for i in range(N):
  dp[i+1][0] = max(dp[i][0]+x[i],dp[i][1]-x[i])
  dp[i+1][1] = max(dp[i][0]-x[i],dp[i][1]+x[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 collections

N,X,Y=map(int,input().split())
if X > Y:
    exc=X
    X=Y
    Y=exc
L=[]
for i in range(N-1):
    for j in range(i+1,N):
        if i >= Y-1 or j <= X-1:
            L.append(j-i)
        elif j-i == 1:
            L.append(1)
        elif i <= X-1 and j >= Y-1:
            L.append(1+abs(X-1-i)+abs(Y-1-j))
        elif i >= X-1 and i-(X-1) > (Y-1)-i:
            L.append(j-i)            
        else:
            L1=j-i
            L2=min(j-i,1+abs(X-1-i)+abs(Y-1-j))
            L.append(min(L1,L2))

c=collections.Counter(L)

for i in range(1,N):
    print(c[i])




import numpy as np
import collections

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

a=np.array(A, dtype=np.float64)
asign=np.sign(A)
c = collections.Counter(asign)
ar = np.array(c[-1], dtype=np.float64)
ac = a * asign

if c[-1] % 2 == 0:
    print(int(sum(ac)))
else:
    print(int(sum(ac)-min(ac)*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):
import numpy as np
n = int(input())
*a, = map(int, input().split())
b = np.abs(a)
#print(b)
print(np.sum(b)-2*np.min(b) if (i<0 for i in a) else np.sum(b)) 

import numpy as np
n = int(input())
*a, = map(int, input().split())
b = np.abs(a)
#print(b)
print(np.sum(b)-2*np.min(b) if (np.sum(i<0 for i in a)%2) else np.sum(b)) 

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

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

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

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


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

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

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

B = [abs(i) for i in A]
minus = [int(i<0) for i in A]
if sum(minus)%2 == 0:
    print(sum(B))
else:
    print(sum(B)-2*min(B))

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

for i in range(n-1):
    if a[i] <= 0 and a[i+1] <= 0:
        a[i] = -a[i]
        a[i+1] = -a[i+1]
        
for i in range(n-2):
    if a[i] < 0 and a[i+1] >= 0 and a[i+2] <= 0:
        a[i] = -a[i]
        a[i+2] = -a[i+2]
        
for i in range(n-1):
    if a[i] < 0:
        if a[i]+a[i+1] < -(a[i]+a[i+1]):
            a[i] = -a[i]
            a[i+1] = -a[i+1]

if a[n-1]+a[n] < -(a[n-1]+a[n]):
    a[n-1] = -a[n-1]
    a[n] = -a[n]

print(sum(a))

n = int(input())
a = list(map(int,input().split()))
dp_table = [0, -10 ** 10]
temp = [0,0]
for i in range(n):
    temp[0] = dp_table[0]
    temp[1] = dp_table[1]
    dp_table[0] = max(temp[0]+a[i],temp[1]-a[i])
    dp_table[1] = max(temp[0]-a[i],temp[1]+a[i])
    
print(dp_table[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 = map(int,input())
if 0 in A:
  print(sum(A))
else:
  count=0
  min_A =100000000000000000
  for i in range(N):
    if A[i]<0:
      count=count+1
    if abs(A[i])<min_A:
      min_A = abs(A[i])
  print(sum(A)-min_A)

N = int(input())
A = map(int,input().split())
if 0 in A:
  print(sum(A))
else:
  count=0
  min_A =100000000000000000
  for i in range(N):
    if A[i]<0:
      count=count+1
    if abs(A[i])<min_A:
      min_A = abs(A[i])
  print(sum(A)-min_A)

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

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

Verdicts: Runtime Error

Runtime Error

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

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

print(sum(A)-2*min(A))

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

count = len([i for i in A if i < 0])

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

N = int(input())
A = list(map(int, input().split()))
 
count = len([i for i in A if i < 0])
A = [abs(i) for i in A]
 
if count % 2 == 1: 
  print(sum(A)-2*min(A))
else:
  print(sum(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())
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)
    


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)
    

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)
    


n=int(input())
l=list(map(int,input().split()))
b=False
sum=0
count=0
absmin=100000000000000
for i in l:
  if i==0:
    b=True
  elif i<0:
    count+=1
  if absmin>abs(i):
    absmin=abs(i)
  sum+=abs(i)
if b:
  print(sum)
else:
  if count%2==1:
    print(sum-2*absmin)
  else:
    print(sum)

Verdicts: Runtime Error

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):
n = int(input())
A = list(map(int,input().split()))
abs_A = [abs(i) for i in A]
zero = 0
minus = 0
for i in A:
    if i < 0:
        minus += 1
    elif i == 0:
        zero += 1  
print(minus)
if minus % 2 == 0 or (zero in A):
    print(sum(abs_A))
else:
    print(sum(abs_A) - min(abs_A)*2)

n = int(input())
A = list(map(int,input().split()))
abs_A = [abs(i) for i in A]
zero = 0
minus = 0
for i in A:
    if i < 0:
        minus += 1
    elif i == 0:
        zero += 1  
if minus % 2 == 0 or (zero in A):
    print(sum(abs_A))
else:
    print(sum(abs_A) - min(abs_A)*2)

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


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)



N = int(input())
data = list(map(int, input().split()))
count = 0

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


for i in data:
    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)


Verdicts: Runtime Error

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()))
b=[]
for _ in range(n):
  if a[_]<0:
    b.append(a.pop(_)*(-1))
if 0 in a or len(b)%2==0:
  print(sum(a)+sum(b))
else:
  b.sort()
  print(sum(a)+sum(b)-(b[0]*2))

n=int(input())
a=list(map(int,input().split()))
b=[]
for _ in range(n):
  if a[_]<0:
    b.append(a.pop(_)*(-1))
if 0 in a or len(b)%2==0:
  print(sum(a)+sum(b))
else:
  b.sort()
  print(sum(a)+sum(b[1:])-b[0])

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

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()))
cnt=0
for i in range(n):
  if a[i]<0:
    cnt+=1
if min(a)>=0 or cnt%2==0:
  print(sum(a))
  exit()
b=[abs(a[i]) for i in range(n)]
s=sum(b)
ans=-10**18
for i in range(n):
  ans=max(ans,s-2*b[i])
print(ans)


n=int(input())
a=list(map(int,input().split()))
if min(a)>=0:
  print(sum(a))
  exit()
b=[abs(a[i]) for i in range(n)]
s=sum(b)
ans=-10**18
for i in range(n):
  ans=max(ans,s-2*b[i])
print(ans)

n=int(input())
a=list(map(int,input().split()))
cnt=0
for i in range(n):
  if a[i]<0:
    cnt+=1
if min(a)>=0:
  print(sum(a))
  exit()
b=[abs(a[i]) for i in range(n)]
s=sum(b)
if cnt%2==0:
  print(s)
  exit()
ans=-10**18
for i in range(n):
  ans=max(ans,s-2*b[i])
print(ans)


Verdicts: 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 = list(map(int,input().split()))
dp = [[0] * 2 for _ in range(n-1)]
dp[0][0] = a_list[0] + a_list[1]
dp[0][1] = -1*(a_list[0] + a_list[1])

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

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

for i in range(1,n-1):
    dp[i][0] = max(dp[i-1][0] + a_list[i+1] , dp[i-1][1] + a_list[i+1])
    dp[i][1] = max(dp[i-1][0] - a_list[i+1] -2*a_list[i], dp[i-1][1] - a_list[i+1]+2*a_list[i])
    
print(max(dp[n-2][0] ,dp[n-2][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):
# -*- coding: utf-8 -*-
"""
Created on Tue May 14 10:45:22 2019

@author: avina
"""

N = int(input())
L = list(map(int, input().strip().split()))
dp = [[0,0] for i in range(N+1)]
if L[0] >= 0:
    dp[0][1] = -L[0]
else:
    dp[0][1] = L[0]
for i in range(N):
    dp[i+1][0] = max(dp[i][0] + L[i], dp[i][1] - L[i])
    dp[i+1][1] = max(dp[i][1] + L[i], dp[i][0] - L[i])

print(min(dp[N]))

N = int(input())
L = list(map(int, input().strip().split()))
dp = [[0,0] for i in range(N+1)]
if L[0] >= 0:
    dp[0][1] = -L[0]
else:
    dp[0][1] = L[0]
for i in range(N):
    dp[i+1][0] = max(dp[i][0] + L[i], dp[i][1] - L[i])
    dp[i+1][1] = max(dp[i][1] + L[i], dp[i][0] - L[i])

print(min(dp[N][0]))

# -*- coding: utf-8 -*-
"""
Created on Tue May 14 10:45:22 2019

@author: avina
"""

N = int(input())
L = list(map(int, input().strip().split()))
dp = [[0,0] for i in range(N+1)]
dp[0][1] = -1e7
for i in range(N):
    dp[i+1][0] = max(dp[i][0] + L[i], dp[i][1] - L[i])
    dp[i+1][1] = max(dp[i][1] + L[i], dp[i][0] - L[i])

print(dp[N][0])

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):
import numpy as np

inf = float('inf')

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

dp = np.zeros((N + 1, 2))
dp[0][1] = -inf



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


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



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


def main():
    inf = 10 ** 14 + 1

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

    stay = 0  
    done = -inf  

    for x in a:
        stay, done = max(stay + x, done - x), max(stay - x, done + x)

    print(stay)


if __name__ == '__main__':
    main()


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

l = int(input())
tmp = list(map(int, input().split()))
lst = list(map(lambda x: x if x > 0 else x*-1, tmp))

ans = 0
if l % 2 == 0:
    ans = sum(lst)
else:
    ans = sum(lst)-(min(lst)*2)

print(ans)


l = int(input())
tmp = list(map(int, input().split()))
lst = list(map(lambda x: x if x > 0 else x*-1, tmp))

minus = list(filter(lambda x: x < 0, tmp))

ans = 0
if len(minus) % 2 == 0:
    ans = sum(lst)
else:
    ans = sum(lst) - (abs(min(lst))*2)

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

An_neg = [ -a for a in An if a < 0]

ans = sum(An)

if len(An_neg) % 2 == 1:
    ans -= 2 * min(An)
    pass

print(ans)


from itertools import *
from collections import *

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

An_pos, An_neg = deque(), deque()
for a in An:
    if a >= 0:
        An_pos.append(a)
    else:
        An_neg.append(a)
        pass
    pass

ans = sum(chain(An_pos, An_neg))

if len(An_neg) % 2 == 1:
    ans -= 2 * min(chain(An_pos, An_neg))
    pass

print(ans)


import sys
from bisect import insort_left
from collections import *

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

An_sorted_pos = deque(sorted([ a for a in An if a > 0]))
An_sorted_neg = deque(sorted([ a for a in An if a < 0]))
zero_exists = not all([ a != 0 for a in An ])

if zero_exists:
    print(sum(An_sorted_pos) - sum(An_sorted_neg))
    sys.exit(0)
    pass

if len(An_sorted_neg) == 0:
    print(sum(An_sorted_pos))
    sys.exit(0)
    pass

if len(An_sorted_pos) == 0:
    if len(An_sorted_neg) % 2 == 0:
        print(-sum(An_sorted_neg))
    else:
        print(-sum(An_sorted_neg)+max(An_sorted_neg))
        pass
    sys.exit(0)
    pass

while An_sorted_pos[0] < -An_sorted_neg[0]:
    pos = An_sorted_pos.popleft()
    neg = An_sorted_neg.popleft()
    idx_pos = insort_left(An_sorted_pos, -neg)
    idx_neg = insort_left(An_sorted_neg, -pos)
    pass

print(sum(An_sorted_pos) + sum(An_sorted_neg))




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

total = 0
minim = 1000000000
num_negs = 0

for a in An:
    is_neg = int(a < 0)
    num_negs += is_neg
    a *= (is_neg * -2 + 1)
    total += a
    minim = minim if minim < a else a
    pass

if num_negs % 2:
    print(total - 2*minim)
else:
    print(total)
    pass


Verdicts: Wrong Answer

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):
from bisect import bisect_left,bisect,bisect_right
import sys

icase=1
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

print(asum)

from bisect import bisect_left,bisect,bisect_right
import sys

icase=0
if icase==0:
    n=int(input())
    a=list(map(int,input().split()))

a.sort()
ii=bisect(a,0)

if ii==n:
    if ii%2==0:
        asum=-sum(a)
    else:    
        asum=-sum(a[0:ii-1])+a[ii-1]
    print(asum)
    sys.exit()

if ii%2==0:
    asum=-sum(a[0:ii])+sum(a[ii:])
else:
    if -a[ii-1]<a[ii]:
        d=a[ii-1]+a[ii]
    else:
        d=-a[ii-1]-a[ii]
    asum=-sum(a[0:ii-1])+d+sum(a[ii+1:])

print(asum)


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 = map(int, input().split())
plus_count = 0
total = 0
minimum = 999999999999999999

for a in A:
	total += abs(a)
	if abs(a) < minimum:
		minimum = abs(a)
	if a >= 0:
		plus_count += 1
			
if plus_count % 2 == 0 or plus_count == N:
	print(total)
else:
	print(total + 2 * mininum)

N = int(input())
A = map(int, input().split())
plus_count = 0
total = 0
minus_max = -999999999999999999

for a in A:
	total += abs(a)
	if a > 0:
		plus_count += 1
	else: 
		if minus_max < a:
			minus_max = a
			
if plus_count % 2 == 0 or plus_count == N:
	print(total)
else:
	print(total + 2 * minus_max)

N = int(input())
A = map(int, input().split())
plus_count = 0
total = 0
minus_max = -999999999999999999

for a in A:
	total += abs(a)
	if a > 0:
		plus_count += 1
	elif a < 0: 
		if minus_max < a:
			minus_max = a
			
if plus_count % 2 == 0 or plus_count == N:
	print(total)
else:
	print(total + 2 * minus_max)

N = int(input())
A = map(int, input().split())
plus_count = 0
total = 0
minimum = 999999999999999999

for a in A:
	total += abs(a)
	if abs(a) < minimum:
		minimum = abs(a)
	if a > 0:
		plus_count += 1
			
if plus_count % 2 == 0:
	print(total)
else:
	print(total - 2 * minimum)

N = int(input())
A = map(int, input().split())
plus_count = 0
total = 0
minus_max = -999999999999999999

for a in A:
	total += abs(a)
	if a >= 0:
		plus_count += 1
	if a <= 0: 
		if minus_max < a:
			minus_max = a
			
if plus_count % 2 == 0 or plus_count == N:
	print(total)
else:
	print(total + 2 * minus_max)

N = int(input())
A = map(int, input().split())
minus_count = 0
total = 0
minimum = 999999999999999999

for a in A:
	total += abs(a)
	if abs(a) < minimum:
		minimum = abs(a)
	if a < 0:
		minus_count += 1
			
if minus_count % 2 == 0:
	print(total)
else:
	print(total - 2 * minimum)

Verdicts: Runtime Error

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):
x=int(input())
y=list(map(int, input().split()))
t=1
for i in range(x):
	if y[i]<0:
		t=t*-1
	y[i]=abs(y[i])

if y==1:
	print(sum(y))
else:
	print(sum(y)-(min(y)*2))

x=int(input())
y=list(map(int, input().split()))
t=1
for i in range(x):
	if y[i]<0:
		t=t*-1
	y[i]=abs(y[i])

if t==1:
	print(sum(y))
else:
	print(sum(y)-(min(y)*2))

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

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

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

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

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

if count%2==0:
    print(sum(A))
else :
    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 = list(map(int,input().split()))

count = 0
for i in range(N):
    if A[i] < 0:
        count += 1
        
Aabs = [abs(i) for i in A]
print(sum(Aabs))

if count % 2 == 0:
    print(sum(Aabs))
else:
    mini = min(Aabs)
    print(Asum - 2*mini)

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

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

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

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([int(i) for i in input().split()])

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

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

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

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

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

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

ret = 0
for i in range(len(a)-1):
    if a[i] < 0:
        a[i] *= -1
        a[i+1] *= -1
    ret += a[i]
    print(a[i], ret)
ret += a[-1]

abs_list = list(map(abs, a))
test = sorted(enumerate(abs_list), key=lambda x:x[1])
print(max(solve(a), solve(a[::-1]), solve(a[::-1], test[0][0]), solve(a[::-1], test[1][0])))

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

ret = 0
for i in range(len(a)-1):
    if a[i] < 0:
        a[i] *= -1
        a[i+1] *= -1
    ret += a[i]
    print(a[i], ret)
ret += a[-1]

print(ret)

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

cnt = 0
min_val = abs(a[0])
for it in a:
    if abs(it) < min_val:
        min_val = abs(it)
    
    if it < 0:
        cnt+=1
        
abs_list = list(map(abs, a))
if cnt%2 == 0:
    print(sum(abs_list))
else:
    print(sum(abs_list) - 2*min_val)

Verdicts: Runtime Error

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 collections

N =int(input())

As = [int(item) for item in input().split()]

cnt = 0

Bs = collections.deque()

min1 = 1000000000000

for i in As:

	if As < 0:		cnt +=1

	Bs.append(abs(i))

	mim1=min(min1, abd(i))

	

if cnt % 2 =0:

	print(sum(list(Bs)))

else:

	print(sum(list(Bs))-min1*2)
    

import collections

N =int(input())

As = [int(item) for item in input().split()]

cnt = 0

Bs = collections.deque()

min1 = 1000000000000

for i in As:

	if As < 0:
      cnt +=1

	Bs.append(abs(i))

	mim1=min(min1, abs(i))

	

if cnt % 2 =0:

	print(sum(list(Bs)))

else:

	print(sum(list(Bs))-min1*2)

import collections
N =int(input())
As = [int(item) for item in input().split()]

cnt = 0
Bs = collections.deque()
min1 = 1000000000000

for i in As:
	if i < 0:
		cnt +=1
	Bs.append(abs(i))
	min1=min(min1, abs(i))
	
if cnt % 2 ==0:
	print(sum(list(Bs)))
else:
	print(sum(list(Bs))-min1*2)
	

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=input()
a=list(map(int,input().split()))
n=sum(x<0 for x in a)
a=[map(abs,a)]
s=sum(a) if n%2==0 else sum(a)-min(a)*2
print(s)


n=int(input())
a=list(map(int,input().split()))
a=list(map(lambda x: abs(x),a))
neg_sum=sum(x<0 for x in a)
m = min(a)
s=sum(a)
s-=m if neg_sum%2
print(s)

n=input()
a=list(map(int,input().split()))
n=sum(x<0 for x in a)
a=list(map(abs,a))
s=sum(a) if n%2==0 else sum(a)-min(a)*2
print(s)


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):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    s = [abs(i) for i in a]
    print(sum(s) - 2*min(s))

if __name__ == "__main__":
    main()

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

if __name__ == "__main__":
    main()

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

if __name__ == "__main__":
    main()

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

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

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

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    DP = [[-10 ** 20] * 2 for _ in range(N)]
    DP[0][0] = A[0]
    DP[0][1] = -1 * A[0]
    for i in range(1, N):
        a = A[i]
        DP[i][0] = max(max(DP[i-1][0] + a, DP[i-1][1] - a), DP[i][0])
        DP[i][1] = max(max(DP[i-1][0] - a, DP[i-1][1] + a), DP[i][1])
    print(DP[N-1])

    return 0

if __name__ == "__main__":
    solve()

import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    DP = [[-10 ** 20, -10 ** 20] for _ in range(N)] 
    DP[0] = [A[0], -1 * 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])
    #print(DP)


    return 0

if __name__ == "__main__":
    solve()

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()]
min = (10**9,None)
for i in range(n-1):
    if a[i] < 0:
        a[i] *= (-1)
        a[i+1] *= (-1)
    if min[0] > abs(a[i]):
        min = (abs(a[i],i))
if a[-1] < 0:
    a[-1]**=(-1)
    a[min[1]]**=(-1)
print(sum(a))


n = int(input())
a = [int(i) for i in input().split()]
m,ans = 10**9,0
for i in range(n-1):
    m = min(m,abs(a[i]))
    if a[i] < 0:
        a[i]*=(-1)
        a[i+1]*=(-1)
if a[-1] >= 0:
    print(sum(a))
else:
    a[-1] *= (-1)
    m = min(m,abs(a[i+1]))
    print(sum(a)-m*2)


Verdicts: Runtime Error

Accepted