Problem p03061 (python)

Fixed submission:
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

def gcd(a, b):
        return a if b == 0 else gcd(b, a%b)
N=int(input())
A=list(map(int, input().split()))

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

m=max(R[1], L[-2])
for i in range(1, N-1):
        m=max(m, gcd(L[i-1], R[i+1]))
print(m)

Buggy submission (verdict: Runtime Error):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq
math.gcd(0,1)

Buggy submission (verdict: Runtime Error):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

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

L=[A[0]]
for i in range(1, N):
        L.append(math.gcd(1,2))

Buggy submission (verdict: Runtime Error):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq

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

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

Buggy submission (verdict: Runtime Error):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq


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

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

m=max(R[1], L[-2])
for i in range(1, N-1):
        m=max(m, math.gcd(L[i-1], R[i+1]))
print(m)

Buggy submission (verdict: Runtime Error):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq


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

if len(A) == 2:
        print(max(A[0][1], A[1][1]))
        exit(0)

maxX=-1
for i, ai in enumerate(A):
        x=10**20
        l=list(A)
        l0, l1=(l[1][1], l[2][1]) if i == 0 else (l[0][1], l[2][1]) if i == 1 else (l[0][1], l[1][1]) 
        if (3 if i <= 2 else 2) >= len(A):
                maxX=maxX
        else:
                x=math.gcd(l0, l1)
                for j, lj in l[(3 if i <= 2 else 2):]:
                        if i != j:
                                x=math.gcd(x, lj)
        maxX=max(x, maxX)
print(maxX)

Buggy submission (verdict: Runtime Error):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq


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

if len(A) == 2:
        print(max(A[0][1], A[1][1]))
        exit(0)

maxX=-1
for i, ai in enumerate(A):
        x=10**20
        l=list(A)
        l0, l1=(l[1][1], l[2][1]) if i == 0 else (l[0][1], l[2][1]) if i == 1 else (l[0][1], l[1][1]) 
        if (3 if i <= 2 else 2) == len(A):
                print("XXX")
                maxX=-1
        else:
                x=math.gcd(l0, l1)
                for (j, lj) in l[(3 if i <= 2 else 2):]:
                        if i != j:
                                x=math.gcd(x, lj)
        maxX=max(x, maxX)
print(maxX)

Buggy submission (verdict: Runtime Error):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq


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

if len(A) == 2:
        print(max(A[0][1], A[1][1]))
        exit(0)

maxX=-1
for i, ai in enumerate(A):
        x=10**20
        l=list(A)
        l0, l1=(l[1][1], l[2][1]) if i == 0 else (l[0][1], l[2][1]) if i == 1 else (l[0][1], l[1][1]) 

        x=math.gcd(l0, l1)
        for (j, lj) in l[(3 if i <= 2 else 2):]:
                if i != j:
                        x=math.gcd(x, lj)
        maxX=max(x, maxX)
print(maxX)

Buggy submission (verdict: Runtime Error):
"""
python3 main.py < input.txt
"""
import math
import itertools as it
import heapq
"""
A,B,T=map(int, input().split())
print(int(math.floor((T+0.5)/(A))*B))
"""
"""
N=int(input())
V=list(map(int, input().split()))
C=list(map(int, input().split()))
print(sum([V[i] - C[i] for i in range(N) if V[i] - C[i] > 0]))
"""

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

if len(A) == 2:
        print(max(A[0][1], A[1][1]))
        exit()

maxX=-1
for i, ai in enumerate(A):
        x=10**20
        l=list(A)
        l0, l1=(l[1][1], l[2][1]) if i == 0 else (l[0][1], l[2][1]) if i == 1 else (l[0][1], l[1][1]) 

        x=math.gcd(l0, l1)
        for (j, lj) in l[3:]:
                if i != j:
                        x=math.gcd(x, lj)
        maxX=max(x, maxX)
print(maxX)
"""
N=int(input())
A=list(map(int, input().split()))
nNeg = len([1 for a in A if a < 0])
minAbs = min(A, key=lambda ai: abs(ai))
if nNeg%2 == 0:
        print(sum([abs(ai) for ai in A]))
else:
        print(-2*abs(minAbs) + sum([abs(ai) for ai in A]))
"""