TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There are N integers, A_1, A_2, ..., A_N, written on the blackboard.  You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.  Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Submission attempts (in order):
# coding:UTF-8


def calc_gcd(num1, num2):
    
    if num1 < num2:
        num1, num2 = num2, num1

    while num2 > 0:
        remainder = num1 % num2

        num1 = num2
        num2 = remainder

    return num1



num_count = int(input())


target_num = list(map(int, input().split()))


left_gcd = [0] * (num_count + 1)  
right_gcd = [0] * (num_count + 1)  

for i in range(num_count):
    left_gcd[i+1] = calc_gcd(left_gcd[i], target_num[i])
    right_gcd[num_count-1-i] = calc_gcd(right_gcd[num_count-i], target_num[num_count-1-i])

print(left_gcd)
print(right_gcd)

gcd = 0

for i in range(num_count):
    result = calc_gcd(left_gcd[i], right_gcd[i+1])
    if gcd < result:
        gcd = result

print(gcd)


# coding:UTF-8


def calc_gcd(num1, num2):
    
    if num1 < num2:
        num1, num2 = num2, num1

    while num2 > 0:
        remainder = num1 % num2

        num1 = num2
        num2 = remainder

    return num1



num_count = int(input())


target_num = list(map(int, input().split()))


left_gcd = [0] * num_count  
right_gcd = [0] * num_count  

for i in range(num_count-1):
    left_gcd[i+1] = calc_gcd(left_gcd[i], target_num[i])
    right_gcd[num_count-2-i] = calc_gcd(right_gcd[num_count-1-i], target_num[num_count-1-i])

print(left_gcd)
print(right_gcd)

gcd = 0

for i in range(num_count):
    result = calc_gcd(left_gcd[i], right_gcd[i])
    if gcd < result:
        gcd = result

print(gcd)


# coding:UTF-8


def calc_gcd(num1, num2):
    
    if num1 < num2:
        num1, num2 = num2, num1

    while num2 > 0:
        remainder = num1 % num2

        num1 = num2
        num2 = remainder

    return num1



num_count = int(input())


target_num = list(map(int, input().split()))


left_gcd = [0] * num_count  
right_gcd = [0] * num_count  

for i in range(num_count-1):
    left_gcd[i+1] = calc_gcd(left_gcd[i], target_num[i])
    right_gcd[num_count-2-i] = calc_gcd(right_gcd[num_count-1-i], target_num[num_count-1-i])

# print(left_gcd)
# print(right_gcd)

gcd = 0

for i in range(num_count):
    result = calc_gcd(left_gcd[i], right_gcd[i])
    if gcd < result:
        gcd = result

print(gcd)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, written on the blackboard.  You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.  Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Submission attempts (in order):
print(1)

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

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

divisors = make_divisors(A[-1])
answer = 1
for d in divisors:
  NG = 0
  for a in A:
    if a % d != 0:
      NG += 1
    if NG > 1:
      break
  if NG <= 1:
    answer = d
    break
    
divisors = make_divisors(A[-2])
for d in divisors:
  NG = 0
  for a in A:
    if a % d != 0:
      NG += 1
    if NG > 1:
      break
  if NG <= 1:
    if d > answer:
      print(d)
    else:
      print(answer)
    break 


Verdicts: Wrong Answer

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, written on the blackboard.  You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.  Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Submission attempts (in order):
import fractions
import functools

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

gcdlist = []

def gcdpy(numbers):
	return functools.reduce(fractions.gcd, numbers)

for i in range(0,N):
	I = A[i]
	A[i] = A[i-1]
	gcdlist.append(gcdpy(A))
	A[i] = I
	
print(max(gcdlist))


def gcd(x,y):
	if x < y:
		x,y = y,x
	if y == 0:
		return x
	
	return gcd(y,x % y)
	
N = int(input())
A = list(map(int,input().split()))

L = [0]
R = [0]
gcdlist = []



for i in range(N):
	L.append(gcd(L[i],A[i]))
	R.append(gcd(R[i],A[N-i-1]))



for i in range(N):
	gcdlist.append(gcd(L[i],R[N-i-1]))

print(max(gcdlist))

Verdicts: Time Limit Exceeded

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, written on the blackboard.  You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.  Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Submission attempts (in order):
import fractions
from functools import reduce
import copy


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


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

ans = 1
for i in range(N):
    a = copy.deepcopy(A)
    print(a)
    a.pop(i)
    g = gcd_list(a)
    if g > ans:
        ans = g
print(ans)


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

divs = {}
for A_i in A:
    
    for i in range(1, 1000):
        if A_i % i == 0:
            if i in divs:
                divs[i] += 1
            else:
                divs[i] = 1
            if i != A_i // i:
                if A_i // i in divs:
                    divs[A_i // i] += 1
                else:
                    divs[A_i // i] = 1
divs = sorted(divs.items(), key=lambda x: x[0], reverse=True)

for divs_i in divs:
    if divs_i[1] == N or divs_i[1] == N - 1:
        print(divs_i[0])
        break


import fractions
from functools import reduce
import copy


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


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

ans = 1
for i in range(N):
    a = copy.copy(A)
    a.pop(i)
    g = gcd_list(a)
    if g > ans:
        ans = g
print(ans)


def make_divisors(n):
    divisors = []

    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)

    return divisors


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

divisors = sorted(set(make_divisors(A[0]) + make_divisors(A[1])), reverse=True)
ans = 1

for divisor in divisors:
    indivisible_count = 0
    for i in range(N):
        if A[i] % divisor != 0:
            indivisible_count += 1

    if indivisible_count <= 1:
        ans = divisor
        break

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Time Limit Exceeded

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, written on the blackboard.  You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.  Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Submission attempts (in order):

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

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
L = [0 for i in range(n+1)]
R = [0 for i in range(n+1)]
for i in range(1,n+1):
    L[i] = gcd(L[i-1], a[i-1])

for i in range(n)[::-1]:
    R[i] = gcd(R[i+1], a[i])

m = []

for i in range(n):
    m.append(gcd(L[i], R[i+1]))

print(max(m))


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

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


n = int(input())

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

if n==2:
    print(max(a))
    exit()
'''
L = [gcd(a[0], a[1])]
R = [gcd(a[n-2], a[n-1])]
'''
L = [0 for i in range(n+1)]
R = [0 for i in range(n+1)]
for i in range(1,n+1):
    L[i] = gcd(L[i-1], a[i-1])

for i in range(n)[::-1]:
    R[i] = gcd(R[i+1], a[i])

m = [0 for i in range(n)]

for i in range(n):
    m[i] = gcd(L[i], R[i+1])

print(max(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):

#_N = 5
#A = [10, -4, -8, -11, 3]
_N = int(input())
A = map(int, input().split(" "))

n = len([*filter(lambda a:a<=-1, A)])
a = [*map(abs, A)]
res = sum(a)
if n % 2 == 1:
    res -= min(a) * 2
print(res)



#_N = 5
#A = [10, -4, -8, -11, 3]
_N = int(input())
A = list(map(int, input().split(" ")))

n = len(list(filter(lambda a:a<=-1, A)))
a = list(map(abs, A))
res = sum(a)
if n % 2 == 1:
    res -= min(a) * 2
print(res)


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()))
ans = 0
abs_A = [abs(a) for a in A]
count = sum([1 if a < 0 else 0 for a in A])
if (count % 2 == 0):
    print(sum(A))
else:
    print(sum(abs_A) - min(abs_A))


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


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

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

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(x) for x in input().split()]
b = [x for x in map(abs, a)]

p = min(b)
ans = sum(b) - 2 * p
print(ans)

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

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

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


Verdicts: Wrong Answer

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N.

Submission attempts (in order):
n=int(input())
A=list(map(int,input().split()))
c=0
for i in A:
  if i<0:
    c+=1
print(sum(A) if c%2==0 else sum(A)-2*min(A))

n=int(input())
A=list(map(int,input().split()))
c=0
for i in range(len(A)):
  if A[i]<0:
    c+=1
    A[i]=-A[i]
print(sum(A) if c%2==0 else 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):
import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
ind=bisect.bisect_left(a,0)
print(ind)

if ind==0:
  print(sum(a))

elif ind%2==0 or a[ind]==0:

  print(-sum(a[:ind])+sum(a[ind:]))
else:
  print(-sum(a[:ind])+sum(a[ind:])-2*min(abs(a[ind]),abs(a[ind-1])))

import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
ind=bisect.bisect_left(a,0)


if ind==0 :
  print(sum(a))
  
elif ind==n:
  if ind%2==1:
    print(-sum(a)+2*a[-1])
  else:
    print(abs(sum(a))

elif ind%2==0:

  print(-sum(a[:ind])+sum(a[ind:]))
else:
  print(-sum(a[:ind])+sum(a[ind:])-2*min(abs(a[ind]),abs(a[ind-1])))

import bisect
n=int(input())
a=sorted(list(map(int,input().split())))
ind=bisect.bisect_left(a,0)


if ind==0 :
  print(sum(a))
  
elif ind==n:
  if ind%2==1:
    print(-sum(a)+2*a[-1])
  else:
    print(abs(sum(a)))

elif ind%2==0:

  print(-sum(a[:ind])+sum(a[ind:]))
else:
  print(-sum(a[:ind])+sum(a[ind:])-2*min(abs(a[ind]),abs(a[ind-1])))

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):
from sys import stdin

readline = stdin.readline

_, *a = map(int, open(0).read().split())
res = 0
mi = 1_000_000_000
rem = True
for v in a:
    if v < 0:
        rem != rem
    b = abs(v)
    res += b
    mi = min(b, mi)
if rem:
    res -= mi*2
print(res)


from sys import stdin

readline = stdin.readline

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


from sys import stdin

readline = stdin.readline

_, *a = map(int, open(0).read().split())
res = 0
mi = 1000000000
rem = True
for v in a:
    if v < 0:
        rem = not rem
    b = abs(v)
    res += b
    mi = min(b, mi)
if rem:
    res -= mi*2
print(res)


from sys import stdin
 
readline = stdin.readline
 
def main():
    _, *A = map(int, open(0).read().split())
 
    B = tuple(map(abs, A))
    C = (a for a in A if a < 0)
    print(sum(B) - min(B)*2*(len(C)%2))
 
 
if __name__ == "__main__":
    main()


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


from sys import stdin

readline = stdin.readline

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

from sys import stdin

readline = stdin.readline

_, *a = map(int, open(0).read().split())
res = 0
mi = 1_000_000_000
rem = True
for v in a:
    if v < 0:
        rem = not rem
    b = abs(v)
    res += b
    mi = min(b, mi)
if rem:
    res -= mi*2
print(res)


if __name__ == "__main__":
    _, *aa = map(int, open(0).read().split())
    bb = tuple(map(abs, aa))
    m = tuple(a for a in aa if a < 0)
    print(sum(bb) - min(bb)*2*(len(m)%2))

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

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()))
ans=0
c=0
tmp=10**9
for a in A:
    if a<0:
        c+=1
    ans+=abs(a)
    tmp=min(tmp,abs(a))
print(tmp)
if c%2==0:
    print(ans)
else:
    print(ans-tmp*2)

N=int(input())
A=list(map(int,input().split()))
ans=0
c=0
tmp=10**9
for a in A:
    if a<0:
        c+=1
    ans+=abs(a)
    tmp=min(tmp,abs(a))
if c%2==0:
    print(ans)
else:
    print(ans-tmp*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(n) for n in input().split()]

sum = 0
minus = 0
minn = 10 ** 10
for a in A:
    b = abs(a)
    sum += b
    if b < minn:
        minn = b
    if a < 0:
        minus += 1

print(sum)
print(minn)
print(minus)

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


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

sum = 0
minus = 0
minn = -1
for a in A:
    b = abs(a)
    sum += b
    if minn == -1 or b < minn:
        minn = b
    if a < 0:
        minus += 1

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


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

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

# abs_list = sorted([abs(x) for x in A])[::-1]

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1
    
tmp = [A]
for i in reversed(range(0, N-1)):
    A[i] *= -1
    A[i+1] *= -1
    tmp.append(sum(A))
    
print(max(tmp))

# D

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

# abs_list = sorted([abs(x) for x in A])[::-1]

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1
    
tmp = []
for i in reversed(range(0, N-1)):
    A[i] *= -1
    A[i+1] *= -1
    tmp.append(sum(A))
    
print(max(tmp))

# D

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

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

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()))
total=0
minloss=100000000000
zeroflag=0
for i in range(N):
  total+=abs(a[i])
  if a[i]==0:
    zeroflag=1
  if abs(a[i])<minloss:
    minloss=abs(a[i])
if N%2==0 or zeroflag==1:
  print(total)
else:
  print(total-2*minloss)

N=int(input())
a=list(map(int,input().split()))
total=0
minloss=100000000000
zeroflag=0
minus=0
for i in range(N):
  total+=abs(a[i])
  if a[i]==0:
    zeroflag=1
  if a[i]<0:
    minus+=1
  if abs(a[i])<minloss:
    minloss=abs(a[i])
if minus%2==0 or zeroflag==1:
  print(total)
else:
  print(total-2*minloss)

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 = False
if all(A):
    print("not contain")
    M = 0
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
            M += 1
    print(M)
    if M%2 == 0:
        B = True
    else:
        B = False

else:
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
    B = True

if B:
    print(sum(A))
else:
    print("else")
    print(min(A))
    print(str(sum(A)-2*min(A)))

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

B = False
if all(A):
    # print("not contain")
    M = 0
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
            M += 1
    # print(M)
    if M%2 == 0:
        B = True
    else:
        B = False

else:
    for i in range(N):
        if A[i] < 0:
            A[i] *= -1
    B = True

if B:
    print(sum(A))
else:
    print(str(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):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
A = nl()

abstotal = sum([abs(i) for i in A])
absmin = min([abs(i) for i in A])
if n % 2 == 0:
    ans = abstotal
else:
    ans = abstotal - 2 * absmin
print(ans)

import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n = ni()
A = nl()

abstotal = sum([abs(i) for i in A])
absmin = min([abs(i) for i in A])
if len([i for i in A if i < 0]) % 2 == 0:
    ans = abstotal
else:
    ans = abstotal - 2 * absmin
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 = [abs(int(i)) for i in input().split()]
s = sum(a)
if n % 2 == 0 or 0 in a:
    print(s)
else:
    print(s - 2 * min(a))

n = int(input())
a = [int(i) for i in input().split()]
m = len(list(filter(lambda x: x < 0, a)))
s = [abs(i) for i in a]
if m % 2 == 0 or 0 in a:
    print(sum(s))
else:
    print(sum(s) - 2 * min(s))


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 math
n = int(input())
M = list(map(int, input().split()))
X = [math.abs(x) for x in M]
print(sum(X) - min(X)*2)

import math
n = int(input())
M = list(map(int, input().split()))
p = [q < 0 for q in M].count(True)
X = [abs(x) for x in M]
if p % 2 == 0:
    print(sum(X))
else:
    print(sum(X) - min(X)*2)

Verdicts: Runtime Error

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split(" ")))
abs_list = list(map(abc, A))
sort(abs_list)
pos = list(filter(lambda x: x > 0, A))
neg = list(filter(lambda x: x < 0, A))

# A has 0
if abs_list[0] == 0:
	print(sum(abs_list))
else if len(neg) % 2 == 0:
	print(sum(abs_list))
else if abs(pos[0]) < abs(neg[-1]):
	print(sum(abs_list) - 2*pos[0] - 2*neg[-1])
else:
	print(sum(pos) - sum(neg[:-1]))



N = int(input())
A = list(map(int, input().split(" ")))
abs_list = list(map(abc, A))
sort(abs_list)
pos = list(filter(lambda x: x > 0, A))
neg = list(filter(lambda x: x < 0, A))

# A has 0
if abs_list[0] == 0:
	print(sum(abs_list))
elif len(neg) % 2 == 0:
	print(sum(abs_list))
elif abs(pos[0]) < abs(neg[-1]):
	print(sum(abs_list) - 2*pos[0] - 2*neg[-1])
else:
	print(sum(pos) - sum(neg[:-1]))



N = int(input())
A = list(map(int, input().split(" ")))
abs_list = list(map(abc, A))
sort(A)
sort(abs_list)

if (N % 2 == 0):
	print(sum(abs_list))
else:
	print(sum(abs_list[1:]))


N = int(input())
A = list(map(int, input().split(" ")))
abs_list = list(map(abs, A))
abs_list.sort()
pos = list(filter(lambda x: x > 0, A))
neg = list(filter(lambda x: x < 0, A))
pos.sort()
neg.sort()

# A has 0
if abs_list[0] == 0:
	print(sum(abs_list))
elif len(neg) % 2 == 0:
	print(sum(abs_list))
elif len(pos) > 0 and abs(pos[0]) < abs(neg[-1]):
	print(sum(abs_list) - 2*pos[0])
else:
	print(sum(abs_list[1:])-abs_list[0])



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(i) for i in input().split()]
B = [abs(i) for i in A]
for i in range(N-1):
    if(A[i]<0):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
if(A[N]<0):
    flag = False
else:
    flag = True

if(flag):
    print(sum(A))
else:
    m = min(B)
    print(sum(B))

N = int(input())
A = [int(i) for i in input().split()]
B = [abs(i) for i in A]
for i in range(N-1):
    if(A[i]<0):
        A[i] = -A[i]
        A[i+1] = -A[i+1]
if(A[N-1]<0):
    flag = False
else:
    flag = True

if(flag):
    print(sum(A))
else:
    m = min(B)
    print(sum(B)-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):
N=int(input())
A=list(map(int,input().split()))

mini=float("inf")
summ=0
for i in range(N):
  mini = min(mini,abs(A[i]))
  summ += abs(A[i])
  
print(summ-2*mini)

N=int(input())
A=list(map(int,input().split()))
B=[A[0]]

for i in range(1,N):
  B.append(B[-1]+A[i])
  
maxi= -1*float("inf")
print(maxi)
for j in range(N-1):
  tmp= B[-1] -2*(A[j]+A[j+1])
  maxi=max(maxi,tmp)
  
print(maxi)

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


dp=[[0,0] for _ in range(N)] 
dp[0][0]=A[0]+A[1]
dp[0][1]=-1*(A[0]+A[1])
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]-2*A[i]-A[i+1], dp[i-1][1]+2*A[i]-A[i+1])
  
#print(dp)
print(max(dp[-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):
import numpy as np

N = int(input())
A = np.array(map(int, input().split()))
if len(A[A<0])%2 == 0:
    ans = sum(abs(A))
else:
    A = sorted(abs(A))
    ans = sum(A[1:] - A[0])
print(ans)

import numpy as np

N = int(input())
A = np.array(map(int, input().split()))
if len(A[A<0])%2 == 0:
    ans = sum(abs(A))
else:
    A = sorted(abs(A))
    ans = sum(A[1:])-A[0]
print(ans)



n = int(input())
*a, = map(int, input().split())
*a_abs, = map(abs, a)
if len([i for i in a if i<0])%2==0:
    print(sum(a_abs))
else:
    print(sum(a_abs)-2*min(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()))
minus = 0
ans = 0
abs_min = float('inf')
for a in A:
  if a < 0:
    minus += 1
  ans += abs(a)
  abs_min = min(abs_min, abs(a))
if mins%2:
  ans -= abs_min*2

print(ans)

n = int(input())
A = list(map(int,input().split()))
minus = 0
ans = 0
abs_min = float('inf')
for a in A:
  if a < 0:
    minus += 1
  ans += abs(a)
  abs_min = min(abs_min, abs(a))
if minus%2:
  ans -= abs_min*2

print(ans)



Verdicts: Runtime Error

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N.

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

import numpy as np
N = int(input())
A = list(map(int, input().split()))
B = A.copy()
B.sort()
C=[]
for i in range(N):
  if B[i]<0:
    C.append(B[i])
  else:
    continue
count = len(C)
if count % 2 == 0:
  B = np.abs(B)
  ans = sum(B)
else:
  B = np.abs(B)
  X = sum(B)
  ans = X - 2*min(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()))
f=(0 in a)
print(f)
import numpy as np

a=np.array(a)

b=abs(a)

c=min(b)

d=sum(a==b)

if d%2==1 or f:
  print(sum(b))
else:
  print(sum(b)-2*c)


from numpy import*


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


if 0 in a:
  print(sum(b));exit()
  
  
minus_cnt=sum(a<0)


if minus_cnt%2==0:
  print(sum(b));exit()
  
  
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 = list(map(int), input().split())
if N % 2 == 0:
    print(sum(map(abs, A)))
else:
    neg = [a for a in A if a < 0]
    c = max(neg) if len(neg) > 0 else 0
    print(sum(map(abs, A)) - 2 * c)

N = int(input())

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

N = int(input())
A = list(map(int, input().split()))
neg = [a for a in A if a < 0]
A = list(map(abs, A))

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

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

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

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

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
ans=0

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

print(a)



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

else:
    ans=sum(a)-2*min(a)

print(ans)


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

cnt=0
ans=0

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



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

else:
    ans=sum(a)-2*min(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(long, input().split()))

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

print (ans)

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

ans = 0
minus_cnt = 0
min_num = 10000000000000
for i in a:
  if i < 0:
    minus_cnt += 1
  if abs(i) < min_num:
    min_num = abs(i)

case = minus_cnt % 2

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

if case == 1:
  ans -= 2 * min_num

print (ans)

Verdicts: Runtime Error

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N.

Submission attempts (in order):
n = int(input())
A = list(map(int, input().split()))
mina = 10*10
minus = False
sumA = 0
for a in A:
    if a < 0:
        if minus:
            minus = False
        else:
            minus = True
    	a = -a
    sumA += a
    mina = min(a, mina)


if minus:
    sumA -= 2*mina
print(sumA)

n = int(input())
A = list(map(int, input().split()))
mina = 10*10
minus = False
sumA = 0
for a in A:
    if a < 0:
        if minus:
            minus = False
        else:
            minus = True
    	a = -a
    sumA += a
    mina = min(a, mina)


if minus:
    sumA -= 2*mina
print(sumA)

n = int(input())
A = list(map(int, input().split()))
mina = 10**9
minus = 0
sumA = 0
for a in A:
    if a < 0:
        minus += 1
        a = -a
    sumA += a
    mina = min(a, mina)
if minus % 2 == 1:
    sumA -= 2 * mina
print(sumA)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N.

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

count = 0
m = 10**9
sum = 0
for i in a:
    i = abs(i)
    m = min(m,i)
    sum += i
    count += 1
    
if count % 2 == 1:
    sum -= m * 2
    
print(sum)

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

count = 0
m = 10**9
sum = 0
for i in a:
    if i < 0:
        count += 1
    i = abs(i)
    m = min(m,i)
    sum += i


if count % 2 == 1:
    sum -= m * 2

print(sum)

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

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
li = na()
if n == 2:
    print(abs(sum(li)))
else:
    for i in range(n-2):
        if li[i] < 0:
            if li[i+1] < 0:
                if li[i+2] > 0:
                    li[i] *= (-1)
                    li[i + 1] *= (-1)
                else:
                     if li[i] < li[i+2]:
                         li[i] *= (-1)
                         li[i + 1] *= (-1)
                     else:
                         li[i + 1] *= (-1)
                         li[i + 2] *= (-1)
            else:
                if li[i+2] < 0:
                    li[i] *= (-1)
                    li[i + 2] *= (-1)
                else:
                    if abs(li[i]) > abs(li[i+1]):
                        li[i] *= (-1)
                        li[i + 1] *= (-1)
        else:
            if li[i+1] <0:
                if li[i+2] < 0:
                    li[i + 1] *= (-1)
                    li[i + 2] *= (-1)
                else:
                    li[i + 1] *= (-1)
            else:
                if li[i+2] < 0:
                    if abs(li[i+2]) > abs(li[i+1]):
                        li[i+1] *= (-1)
                        li[i + 2] *= (-1)

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

n = ni()
li = na()
ct = 0
s1 = 0
li2 = []
m = -1000000000000000000
for i in range(n):
    s1 += abs(li[i])
    li2.append(abs(li[i]))
    if li[i] < 0:
        ct += 1
if ct % 2 == 0:
    print(s1)
else:
    print(s1-2*min(li2))

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

n = input()
l = list(map(int,input().split()))
cnt = len([i for i in l if i<0])
abs_l = list(map(abs,l))
print(sum(abs_l) if cnt%2==0 else sum(abs_l)-2*min(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 = list(map(int,input().split()))
if n==2:
    print(max(a[0],a[1]))
    exit()
def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)
g = gcd(max(a[0],a[1]),min(a[0],a[1]))
ind = [0,1]
for i in range(1,n):
    tmp = gcd(max(g,a[i]),min(g,a[i]))
    if tmp<g:
        ind = [i-1,i]
    g = tmp
import copy
a1,a2 = copy.copy(a),copy.copy(a)
del a1[ind[0]]
del a2[ind[1]]
g1=a1[0]
g2=a2[0]
for i in range(n-1):
    g1 = gcd(max(g1,a1[i]),min(g1,a1[i]))
    g2 = gcd(max(g2,a2[i]),min(g2,a2[i]))
print(max(g1,g2))

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

Verdicts: Wrong Answer

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N.

Submission attempts (in order):
n=int(input())
n-=1
a=list(map(int,input().split()))
cnt=0
ans=0
for i in range(n):
    if cnt>0:
        a[i]=a[i]*(-1)
    if a[i]<0:
        cnt=2
        a[i]=a[i]*(-1)
    else:
        pass
    ans+=a[i]
    cnt-=1
if cnt>0:
    a[n]=abs(a[n])
    m=min(a)
    if m==a[n]:
        ans-=m
    else:
        ans=ans+a[n]-m
else:
    ans+=a[n]
print(ans)

n=int(input())
n-=1
a=list(map(int,input().split()))
cnt=0
ans=0
for i in range(n):
    if cnt>0:
        a[i]=a[i]*(-1)
    if a[i]<0:
        cnt=2
        a[i]=a[i]*(-1)
    else:
        pass
    ans+=a[i]
    cnt-=1
if cnt>0:
    a[n]=a[n]*(-1)
if a[n]<0:
    a[n]=a[n]*(-1)
    m=min(a)
    ans=ans+a[n]-m*2
else:
    ans+=a[n]
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=input()
alist = list(map(int,input().split()))

ans = 0
for i in range(N):
  ans += abs(alist[i])
  
print(ans)

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

neg_cnt = 0
abs_min = 999999999999999
for an in alist:
  if an < 0:
    neg_cnt += 1
  if abs_min > abs(an):
    abs_min = abs(an)
 
ans = 0
for i in range(N):
  ans += abs(alist[i])
  
if neg_cnt%2 == 0:
  print(ans)
else:
  print(ans-2*abs_min)

Verdicts: Runtime Error

Accepted
Problem: There are N integers, A_1, A_2, ..., A_N, arranged in a row in this order.  You can perform the following operation on this integer sequence any number of times:  **Operation** : Choose an integer i satisfying 1 \leq i \leq N-1. Multiply both A_i and A_{i+1} by -1.  Let B_1, B_2, ..., B_N be the integer sequence after your operations.  Find the maximum possible value of B_1 + B_2 + ... + B_N.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
count=0
a_abs=[0 for j in range(n)]
min_abs=abs(a[0])
for i in range(n):
    a_abs[i]=abs(a[i])
    if a[i]<0:
        count+=1
    if abs(a[i])<min_abs:
        min_abs=abs(a[i])
        

if count%2==0:
    ans=sum(a_abs)
else:
    ans=sum(a_abs)-2*min_abs
    
print(count)
print(min_abs)
print(ans)

n=int(input())
a=list(map(int,input().split()))
count=0
a_abs=[0 for j in range(n)]
min_abs=abs(a[0])
for i in range(n):
    a_abs[i]=abs(a[i])
    if a[i]<0:
        count+=1
    if abs(a[i])<min_abs:
        min_abs=abs(a[i])
        

if count%2==0:
    ans=sum(a_abs)
else:
    ans=sum(a_abs)-2*min_abs
    
print(ans)

Verdicts: Wrong Answer

Accepted