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

a.sort()
if n % 2 == 0:
    ans = sum(a)
else:
    ans = sum(a) - (a[0]*2)
print(ans)

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

num = 0
for i in range(n):
    if a[i] < 0:
        num = num + 1
if num % 2 == 0:
    ans = sum(b)
else:
    ans = sum(b) - (b[0]*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())
A = list(map(int, input().split()))
for i in range(n):
    if A[i]<0:
        A[i] = -A[i]
if n % 2 == 1:
    print(sum(A)-2*min(A))
else:
    print(sum(A))

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

n = int(input())
A = list(map(int, input().split()))
count = 0
for i in range(n):
    if A[i]<0:
        A[i] = -A[i]
        count += 1
if count % 2 == 1:
    print(sum(A)-2*min(A))
else:
    print(sum(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):
n = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(sum(map(abs, a)))
  exit()
minus = len([i for i in range(n) if a[i]<0 ])
if minus % 2 == 0:
  print(print(sum(map(abs, a))))
else:
  a = sorted(a, key=lambda x: abs(x))
  print(sum(map(abs, a[1:])))

n = int(input())
a = list(map(int, input().split()))
if 0 in a:
  print(sum(map(abs, a)))
  exit()
minus = len([i for i in range(n) if a[i]<0 ])
if minus % 2 == 0:
  print(sum(map(abs, a)))
else:
  a = sorted(a, key=lambda x: abs(x))
  print(sum(map(abs, a[1:]))-abs(a[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()))
#N=9
#A=[10,-4,-8,-11,3,90,78,3,999]
count=0
B=[]
for i in range(N):
    if A[i]<0:
        B.append((-1)*A[i])
        count+=1
    else:
        B.append(A[i])
print(B)
if count%2==0:
    print(sum(B))
else:
    print(sum(B)-2*min(B))

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

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

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
n = int(input())
l = np.array(list(map(int,input().split()))).astype("i")

if n % 2 == 0:
  print(np.sum(np.abs(l)))
else:
  print(np.sum(np.abs(l)) - 2 * np.min(np.abs(l)))

import numpy as np
n = int(input())
l = np.array(list(map(int,input().split()))).astype("i")

m = np.sum(l < 0)

if m % 2 == 0:
  print(np.sum(np.abs(l)))
else:
  print(np.sum(np.abs(l)) - 2 * np.min(np.abs(l)))

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

count=0
ans=0
for i in range(N):
    if a[i]<0:
        c+=1
        
a[i]=abs[i]
if c%2==0
    ans=sum(a)
else:
    a.sort()
    ans=sum(a)-a[0]

N=int(input())
a=[int(i) for i in input().split()]
 
count=0
ans=0
for i in range(N):
    if a[i]<0:
        c+=1        
    a[i]=abs(a[i])

if c%2==0
    ans=sum(a)
else:
    a.sort()
    ans=sum(a)-a[0]

N=int(input())
a=[int(i) for i in input().split()]
 
count=0
ans=0
for i in range(N):
    if a[i]<0:
        c+=1        
    a[i]=abs(a[i])

if c%2==0:
    ans=sum(a)
else:
    a.sort()
    ans=sum(a)-a[0]

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

count=0
ans=0
for i in range(N):
    if a[i]<0:
        c+=1
        
a[i]=abs(a[i])
if c%2==0
    ans=sum(a)
else:
    a.sort()
    ans=sum(a)-a[0]

N = int(input())

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

count=0
ans=0

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

if count%2==0:
    ans=sum(a)

else:
    a.sort()
    ans=sum(a)-a[0]*2

print(ans)


Verdicts: Runtime Error

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 = np.zeros((N+1, 2), dtype=int)
dp[0, 1] = -10**9

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

import numpy as np
N = int(input())
A = list(map(int, input().split()))

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

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

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):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,copy
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
a = [abs(x) for x in a]
a.sort()
a[0] = -a[0]
print(sum(a))

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,copy
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
cnt = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
a = [abs(x) for x in a]
a.sort()
if cnt%2:
    a[0] = -a[0]
print(sum(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()))
for i in range(n):
  if A[i]<0 and A[i+1]<0:
    A[i] = -A[i]
    A[i+1] = -A[i]
  elif A[i]<0:
    if A[i]-A[i+1]<0:
      A[i] = -A[i]
      A[i+1] = -A[i]
print(sum(A))
    

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

dp0 = [0]
dp1 = [-INF-1]

for i, x in enumerate(A):
  dp0.append( max(dp0[i] + x, dp1[i] - x) )
  dp1.append( max(dp0[i] - x, dp1[i] + x) )

print(dp0[-1])


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 range(n):
    a[i] = abs(a[i])
a.sort()
a[0] *= -1
print(sum(a))
    

n = int(input())
a = list(map(int, input().split()))
k = 1
for i in range(n):
    if a[i] < 0:
        a[i] *= -1
        k *= -1
a.sort()
if k == -1:
    a[0] *= -1
print(sum(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 = list(map(int, input().split()))

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

if count % 2 == 0:
    print(ans)
else:
    print(ans - min(a) * 2)


# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))

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

ans = sum(a)
if count % 2 == 0:
    print(ans)
else:
    print(ans - 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()))


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


if N == 2:
    print(max(A[0], A[1]))
    quit()
if N == 3:
    print(max(gcd(A[0], A[1]), gcd(A[0], A[2]), gcd(A[1], A[2])))
    quit()

ans0 = A[0]
ans1 = A[-1]
for i in range(N//2-1):
    ans0 = min(gcd(A[i], A[i+1]), ans0)
for i in range(N//2, N-1):
    ans1 = min(gcd(A[i], A[i+1]), ans1)
ans = max(ans0, ans1)
print(ans)

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


C = 0
for i, v in enumerate(A):
    if v < 0:
        C += 1
if C % 2 == 0:
    ans = 0
    for i, v in enumerate(A):
        ans += abs(v)
else:
    A = sorted([abs(a) for a in A])
    ans = sum(A) - 2*A[0]

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())
a = list(map(abs, map(int, input().split())))
print(sum(a) - 2 * min(a))

n = int(input())
sum_abs_a = 0
min_abs_a = 10 ** 9
minus_odd = False
for a in map(int, input().split()):
  if a < 0:
    minus_odd = not minus_odd
    a = -a
  sum_abs_a += a
  min_abs_a = min(min_abs_a, a)
if minus_odd:
  print(sum_abs_a - 2 * min_abs_a)
else:
  print(sum_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()))
min_b = 10**9
sum_b = 0
for i in range(n):
    sum_b += abs(a[i])
    if abs(a[i]) < min_b:
        min_b = abs(a[i])
print(sum_b - 2*min_b)

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

for i in range(n):
    if a[i] < 0:
        ne_num += 1
if ne_num % 2 == 0:
    print(sum(list(map(abs, a))))
    exit()

min_b = 10**9
for i in range(n):
    if abs(a[i]) < min_b:
        min_b = abs(a[i])
print(sum(list(map(abs, a))) - 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()))
b = 0
ans = sum(a)

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

print(ans)

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, *a = map(int, read().split())
cnt = 0
for i, aa in enumerate(a):
    if aa < 0:
        a[i] = -aa
        cnt += 1
if cnt % 2 == 0:
    print(sum(a))
else:
    print(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()))

sum=0
min=10**9
for i in a:
  if i>=0:
    sum=sum+i
    if min>i:
      min=i
  else:
    sum=sum-i
    if min>-i:
      min=-i
print(sum if len(a)%2==0 else sum-min)

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

sum=0
min=10**9
minus=0
for i in a:
  if i>=0:
    sum=sum+i
    if min>i:
      min=i
  else:
    minus=minus+1
    sum=sum-i
    if min>-i:
      min=-i
print(sum if minus%2==0 else sum-min*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(" ")))
for i in range(1, n-1):
    print(a)
    if 0 <= a[i-1] and 0 <= a[i] and 0 <= a[i+1]:
        continue
    elif a[i-1] < 0 and 0 <= a[i] and a[i+1] < 0:
        a[i-1] = abs(a[i-1])
        a[i+1] = abs(a[i+1])
    elif a[i-1] < 0 and a[i] < 0:
        a[i-1] = abs(a[i-1])
        a[i] = abs(a[i])
    elif a[i] < a[i+1]:
        if abs(a[i]) >= abs(a[i+1]):
            a[i] = a[i]*-1
            a[i+1] = a[i+1]*-1
    elif a[i-1] < a[i]:
        if abs(a[i-1]) >= abs(a[i]):
            a[i-1] = a[i-1]*-1
            a[i] = a[i]*-1
    else:
        continue
print(sum(a))

n = int(input())
a = list(map(int, input().split(" ")))
if len(list(filter(lambda x: x < 0, a))) % 2 == 0:
    print(sum(list(map(abs, a))))
else:
    a = list(map(abs, a))
    print(sum(a) - min(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):
import math

def main():
    n = int(input())
    a = [int(t) for t in input().split()]

    m = 0
    if 0 in a:
        m = sum([abs(x) for x in a])
    else:
        a_ = [abs(x) for x in a]
        m = sum(a_)-2*min(a_)

    print(m)

if __name__ == "__main__":
    main()

import math

def main():
    n = int(input())
    a = [int(t) for t in input().split()]

    m = 0
    if 0 in a or len([x for x in a if x<0])%2==0:
        m = sum([abs(x) for x in a])
    else:
        a_ = [abs(x) for x in a]
        m = sum(a_)-2*min(a_)

    print(m)

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

sum1=0
index=0
while index < len(listA):
    sum1+=listA[index]
    index+=1

if len(listA)%2==0:
    leng = len(listA)-1
else:
    leng = len(listA)-2
while leng > 1:
    index=0
    max1 = 0
    startI=0
    endI=0
    while index < len(listA)-leng+1:
        if sum(listA[index:index+leng+1]) <= 0 and max1 < sum(listA[index:index+leng+1])*-2:
            max1 = -2*(sum(listA[index:index+leng+1]))
            startI = index
            endI = index+leng
        index+=1
    if max1!=0:
        sum1+=max1
        index2=startI
        while index2 < endI+1:
            listA[index2]*=-1
            index2+=1
    leng-=1

print(sum1)

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

index=0
count=0
plSum=0
miSum=0
miniO=10000000
while index < len(listA):
    if listA[index] < 0:
        count+=1
        miSum-=listA[index]
    else:
        plSum+=listA[index]
    if abs(listA[index]) < miniO:
        miniO = abs(listA[index])
    index+=1
if count%2==0:
    print(plSum+miSum)
else:
    print(plSum+miSum-2*miniO)

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=[abs(A[i]) for i in range(N)]
c=sum([A[i]<0 for i in range(N)])
print([A[i]<0 for i in range(N)])
if c%2==0:
    print(sum(Aabs))
else:
    print(sum(Aabs)-2*min(Aabs))

N=int(input())
A=list(map(int,input().split()))
Aabs=[abs(A[i]) for i in range(N)]
c=sum([A[i]<0 for i in range(N)])
if c%2==0:
    print(sum(Aabs))
else:
    print(sum(Aabs)-2*min(Aabs))

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())
aList = [int(x) for x in input().split(" ")]

for x in range(0, len(aList)):
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]

aMin = min(aList)

print(sum(aList) - ((aMin if len(aList)%2 == 1 else 0)*2))




n = int(input())
aList = [int(x) for x in input().split(" ")]

minNum = 0

for x in range(0, len(aList)):
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]
	minNum += 1 if aList[x] < 0 else 0

aMin = min(aList)

even = minNum%2==0

if not even:
	print(sum(aList))
else:
	print(sum(aList) - (aMin*2))

n = int(input())
aList = [int(x) for x in input().split(" ")]

minNum = 0

for x in range(0, len(aList)):
	minNum += 1 if aList[x] < 0 else 0
	aList[x] = -aList[x] if aList[x] < 0 else aList[x]

aMin = min(aList)


even = minNum%2==0

if even:
	print(sum(aList))
else:
	print(sum(aList) - (aMin*2))


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()))
for i in range(N-1):
    if A[i] + A[i+1] < -1 * (A[i] + A[i+1]):
        A[i] = A[i] * -1
        A[i+1] = A[i+1]
sum(A)

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

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

        print(sum(A) - dele)   

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())
li = list(map(int, input().split()))
temp = li.copy()
for i in range(n-1):
    if li[i] < 0:
        li[i] *= -1
        li[i+1] *= -1
ans = sum(li)
li = temp
for i in reversed(range(1,n)):
    if li[i] < 0:
        li[i] *= -1
        li[i-1] *= -1
ans = max(ans, sum(li))

n = int(input())
li = list(map(int, input().split()))
temp = li.copy()
for i in range(n-1):
    if li[i] < 0:
        li[i] *= -1
        li[i+1] *= -1
ans = sum(li)
li = temp
for i in reversed(range(1,n)):
    if li[i] < 0:
        li[i] *= -1
        li[i+1] *= -1
ans = max(ans, sum(li))

n = int(input())
li = list(map(int, input().split()))
mainus_li = [i for i in li if i<0]
li = [abs(i) for i in li]
ans = sum(li)
if len(mainus_li) %2 == 1:
    ans -= 2*min(li)
print(ans)


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

#print(s)

count = 0

#  if s[i] < 0:
#    s[i] -= 2 * s[i]
#    s[i+1] -= 2 * s[i+1]
#for j in range(N):
#  count += int(s[j])
#print(count)

min1 = abs(s[0])
#print(min1)
for i in range(N):
  min1 = min(min1, abs(s[i]))
  count += abs(s[i])
  
count = count - 2*min1
print(count)
  

N = int(input())
s = [input().split() for i in range(1)]
t = s[0]
t_int = [int(n) for n in t]
x = 0
count = 0
for i in range(N):
  if t_int[i] < 0:
    count -= t_int[i]
    x += 1
  else:
    count += t_int[i]
if x % 2 == 0:
  count += 2 * t_int[N-1]
else:
  count -= 2 * t_int[N-1]
print(float(count))

N = int(input())
s = [input().split() for i in range(1)]
t = s[0]
t_int = [int(n) for n in t]
x = 0
count = 0
for i in range(N):
  if t_int[i] < 0:
    count -= t_int[i]
    x += 1
  else:
    count += t_int[i]
if x % 2 == 0:
  count += 2 * t_int[N-1]
else:
  count -= 2 * t_int[N-1]
print(int(count))

N = int(input())
s = [input().split() for i in range(1)]
t = s[0]
t_int = [int(n) for n in t]
x = 0
count = 0
for i in range(N):
  if t_int[i] < 0:
    count -= t_int[i]
    x += 1
  else:
    count += t_int[i]
if x % 2 == 0:
  count += 2 * t_int[N-1]
else:
  count -= 2 * t_int[N-1]
print(count)

N = int(input())
s = [input().split() for i in range(1)]
t = s[0]
t_int = [int(n) for n in t]
#print(s)
#print(t_int)
x = 0
count = 0
for i in range(N-1):
  if t_int[i] < 0:
    t_int[i] -= 2 * t_int[i]
    t_int[i+1] -= 2 * t_int[i+1]
for j in range(N):
  count += float(t_int[j])
print(float(count))

N = int(input())
s = [input().split() for i in range(1)]
t = s[0]
t_int = [int(n) for n in t]
x = 0
count = 0
for i in range(N):
  if t_int[i] < 0:
    count -= t_int[i]
    x += 1
  else:
    count += t_int[i]
if x % 2 == 0:
  count += 2 * t_int[N-1]
else:
  count -= 2 * t_int[N-1]
print(count)

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

#print(s)

count = 0
odd = 0

min1 = abs(s[0])
#print(min1)
for i in range(N):
  min1 = min(min1, abs(s[i]))
  count += abs(s[i])
  if abs(s[i]) != s[i]:
    odd += 1

count2 = count - 2*min1

if odd%2 == 1:
  print(count2)
else:
  print(count)
  

Verdicts: Wrong Answer

Wrong Answer

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())
A = list(map(int,input().split()))
B = sum(a<0 for a in A)
C = sum(a==0 for a in A)
D = sum([abs(a) for a in A])

if 2<=C:
  print(D)
else:
  if B%2==0:
    print(C)
  else:
    print(C-2*min(A,key=abs))

N = int(input())
A = list(map(int,input().split()))
B = list(map(abs,A))
print(sum(B)-2*min(B)*(sum(a<0 for a in 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())
Alist = list(map(int, input().split()))
dp = [[0, 0] for i in range(N+1)]
dp[0][1] = -(3*10**9)
for i in range(1, N+1):
    dp[i][0] = max(dp[i-1][0]+Alist[i], dp[i-1][1]-Alist[i])
    dp[i][1] = max(dp[i-1][0]-Alist[i], dp[i-1][1]+Alist[i])
print(dp[N][0])


N = int(input())
Alist = list(map(int, input().split()))
dp = [[0, 0] for i in range(N+1)]
dp[0][1] = -(3*10**9)
for i in range(1, N+1):
    Ai = Alist[i-1]
    dp[i][0] = max(dp[i-1][0]+Ai, dp[i-1][1]-Ai)
    dp[i][1] = max(dp[i-1][0]-Ai, dp[i-1][1]+Ai)
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()))
import bisect
a.sort()

idx = bisect.bisect_left(a, 0)

if idx % 2 == 0:
    print(sum(abs(a)))
else:
    sm = [abs(x) for x in a]
    print(sum(sm) - 2*min(abs(a[idx]), abs(a[idx-1])))

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

idx = bisect.bisect_left(a, 0)
sm = [abs(x) for x in a]
if idx % 2 == 0:
    print(sum(sm))
else:
    print(sum(sm) - 2*min(sm))

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 = list(map(int,input().split()))
n = sum(1 for x in A if x<0)
print(n)
B = np.abs(A)
if n % 2 == 1:
  print(sum(B) - 2*min(B))
else:
  print(sum(B))

import numpy as np
N = int(input())
A = list(map(int,input().split()))
n = sum(1 for x in A if x<0)
B = np.abs(A)
if n % 2 == 1:
  print(sum(B) - 2*min(B))
else:
  print(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, *A = map(int, open(0).read().split())
print(sum(map(abs, A)) - 2*min(map(abs, A)))

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






n=input()
a=list(map(int,input().split()))
b=[abs(x)for x in a]


print(sum(b)-2*min(b)if sum(x<0 for x in a)%2 else sum(b))

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=in(input())
a=list(map(int, input().split()))
count=0
zero=0
total=0

for i in range(N):
  if a[i]<0:
    count+=count
    total=toal+abs(a[1])
  if a[1]<0:
    zero+=zero
    
if count%2==0 or zero>0:
  print(total)
else:
  print(total-np.abs(a))
  


#Conding: Utf-8

N= int(input())
a=list(map(int, input().split()))
count=0
for i in range(N-1):
    if a[i]<0 and a[i+1]<0:
        a[i]=a[i]*-1
        a[i+1]=a[i+1]*-1
        print("a")
    elif a[i]<0 and abs(a[i])>=abs(a[i+1]):
        a[i]=a[i]*-1
        a[i+1]=a[i+1]*-1
        print("b")
print(a)
for j in range(N):
    count=a[j]+count

print(count)


#Conding: Utf-8

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

count=num=total=0
b=[]

for i in a:
    if i<0:
        count+=1
    elif i==0:
        num+=1

if count%2==0 or num>0:
    for j in a:
        total=total+abs(j)
    print(total)
else:
    for k in a:
        total=total+abs(k)
    for l in a:
        b.append(abs(l))

    print(total-2*min(b))

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(int(i) for i in input().split())
count_m = 0
count_z = 0

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

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

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

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

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

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

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

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

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()))
b=[abs(i) for i in a]
m=len([i for i in a if i<0])
M=len([i for i in a if i>0])
ans=0
if m%2!=M%2:
    ans=sum(b)-2*min(b)
else:
    ans=sum(b)
print(ans)

n=int(input())
a=list(map(int,input().split()))
b=[abs(i) for i in a]
m=len([i for i in a if i<0])
M=len([i for i in a if i>0])
ans=0
if (m%2==1 and M%2==0) or (m%2==M%2==1):
    ans=sum(b)-2*min(b)
else:
    ans=sum(b)
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())
a = list(map(int,input().split()))

minus = []
plus = []

for i in a:
    elif i < 0:
        minus.append(i)
    else:
        plus.append(i)
plus.sort()
minus.sort(reverse=True)

if len(plus)*len(minus) == 0:
    plus[133],minus[133]
    print(sum(plus)-sum(minus))
    exit()

if len(minus) % 2==0:
    print(sum(plus) - sum(minus))
    exit()

if - minus[0] < plus[0]:
    print(sum(plus) - sum(minus) +2*minus[0])
else:
    print(sum(plus) - sum(minus) -2*plus[0])

from bisect import bisect_left
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [abs(i) for i in a]
b.sort()

i = bisect_left(a, 0)
if i % 2==0:
    print(sum(b))
else:
    print(sum(b) - 2*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):
import numpy as np
n = int(input())
a = list(map(int, input().split()))

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

a=np.array(a)
a2 = a
np.abs(a)
goukei=0

if mynas % 2 ==0:
    for j in range(n):
        goukei += a[j]
else:
    a2=np.sort(a)
    for k in range(n):
        goukei+=a[i]
    goukei-=a[0]*2

print(goukei)


import numpy as np
n = int(input())
a = list(map(int, input().split()))

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

a=np.array(a)
a2 = a
np.abs(a)
goukei=0

if mynas % 2 ==0:
    for j in range(n):
        goukei += a[j]
else:
    a2=np.sort(a)
    for k in range(n):
        goukei+=a[k]
    goukei-=a2[0]*2

print(goukei)


import numpy as np
n = int(input())
a = list(map(int, input().split()))

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

a=np.array(a)
a2 = a
np.abs(a)
goukei=0

if mynas % 2 ==0:
    for j in range(n):
        goukei += a[j]
else:
    a2=np.sort(a)
    for k in range(n):
        goukei+=a[k]
    goukei-=a[0]*2

print(goukei)


import numpy as np
n = int(input())
a = list(map(int, input().split()))

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

a=np.array(a)
np.abs(a)
np.sort(a)
goukei=0

if mynas % 2 ==0:
    for j in range(n):
        goukei += a[j]
else:
    for k in range(n):
        goukei+=a[k]
    goukei-=a[0]*2

print(goukei)


import numpy as np
n = int(input())
a = list(map(int, input().split()))

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

a=np.array(a)
a=np.abs(a)
a=np.sort(a)
goukei=0

if mynas % 2 ==0:
    for j in range(n):
        goukei += a[j]
else:
    for k in range(n):
        goukei+=a[k]
    goukei-=a[0]*2

print(goukei)


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

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

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

dp = [[0]*2 for _ in range(N)]
dp[1][0] = A[0]+A[1]
dp[1][1] = -A[0]-A[1]

if N > 2:
	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]-A[i-1]*2-A[i], dp[i-1][1]+A[i-1]*2+A[i])

print(max(dp[-1]))

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

dp = [[0]*2 for _ in range(N)]
dp[1][0] = A[0]+A[1]
dp[1][1] = -A[0]-A[1]

if N > 2:
	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]-A[i-1]*2-A[i], dp[i-1][1]+A[i-1]*2-A[i])

print(max(dp[-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):
import sys
import numpy as np

N = int(input())

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

if np.sum(A==0) != 0:

    
    z = np.max(np.where(A==0))
    B = A[z:N]

    
    if B.shape[0] == 2 and B[-1] < 0:
        sign = 1
        break

    elif np.sum(B < 0)%2 ==0:
        sign = 1
    else:
        sign = -1


else:
    if np.sum(A < 0)%2 ==0:
        sign = 1
    else:
        sign = -1

print(np.abs(A[0:N-1]).sum() + sign*abs(A[-1]))

import sys

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


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

c = 0
m = abs(A[0])
for a in A:
    if a < 0:
        c += 1
    elif a == 0:
        print(ans)
        sys.exit()

    if abs(a) < m:
        m = abs(a)

if c % 2 == 0:
    print(ans)
else:
    print(ans - 2 * m)


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 = [int(i) for i in input().split()]
a = np.array(a, dtype='int64')
a.sort()
print(a)
for i in range(n):
    if a[i] > 0:
        k = i
        print(i)
        break
a = np.absolute(a)
a.sort()

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

import numpy as np
n = int(input())
a = [int(i) for i in input().split()]
a = np.array(a, dtype='int64')
k = np.sum(a < 0)
a = np.absolute(a)
a.dtype ='uint64'
a.sort()

if k % 2 == 0:
    print(int(np.sum(a)))
else :
    print(int(np.sum(a)- a[0]*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 math

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

a.sort()

if n == 2:
    print(a[1])
elif n == 3:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])
    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

else:
    gcd1 = math.gcd(a[0],a[1])
    gcd2 = math.gcd(a[1],a[2])
    gcd3 = math.gcd(a[0],a[2])

    for i in range(3,n):
        if math.gcd(gcd1, a[i]) < gcd1:
            gcd1 = math.gcd(gcd1, a[i])

    for i in range(3,n):
        if math.gcd(gcd2, a[i]) < gcd2:
            gcd2 = math.gcd(gcd2, a[i])

    for i in range(3,n):
        if math.gcd(gcd3, a[i]) < gcd3:
            gcd3 = math.gcd(gcd3, a[i])

    ans = [gcd1, gcd2, gcd3]
    ans.sort()

    print(ans[-1])

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

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

sum = 0
for i in range(n):
    sum += a[i]

a.sort()

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

N = int(input())
An = list(map(int, input().split()))
print(sum(An) - min(An))

N = int(input())
An = list(map(int, input().split()))
M = sum([0 if a >=0 else 1 for a in An])
An = [abs(a) for a in An]
if M % 2 == 0:
  print(sum(An))
else:
  print(sum(An) - 2*min(An))


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):
import numpy as np
import sys
n = int(input())
a = np.array([int(x) for x in input().split()])
dp = np.zeros((n + 1, 2))
dp[0][1] = -2000000001
for i in range(n):
	dp[i + 1][0] = dp[i][0] + a[i]
	dp[i + 1][1] = dp[i][0] - a[i]
print(int(dp[n][0]))

import numpy as np
import sys
n = int(input())
a = np.array([int(x) for x in input().split()])
dp = np.zeros((n + 1, 2))
dp[0][1] = -2000000001
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(int(dp[n][0]))

Verdicts: Wrong Answer

Accepted