Buggy python submission (verdict: Runtime Error):
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    else:
        if miN%A[i]==0:
            pass
        else:
            miN=(miN//A[i] +1) *A[i]
    maX=maX-max%A[i] + A[i]-1
print(miN,maX)


Fixed submission:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    else:
        if miN%A[i]==0:
            pass
        else:
            miN=(miN//A[i] +1) *A[i]
    maX=maX-maX%A[i] + A[i]-1

mmaX=maX
for i in range(K):
    mmaX-=mmaX%A[i]
if mmaX==2:
    print(miN,maX)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2:
        print(unko)
    if A[i]//miN>=2:
        miN=A[i]
    if miN%A[i]==0:
        pass
    else:
        miN=(miN//A[i] +1) *A[i]
    maX=(maX//A[i]) *A[i] + A[i]-1
print(miN,maX)


Fixed submission:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    else:
        if miN%A[i]==0:
            pass
        else:
            miN=(miN//A[i] +1) *A[i]
    maX=maX-maX%A[i] + A[i]-1

mmaX=maX
for i in range(K):
    mmaX-=mmaX%A[i]
if mmaX==2:
    print(miN,maX)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2
Amax=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2 or i<K-1 and A[i]>(maX//A[i+1])*A[i+1]+maX%A[i+1]:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    if miN%A[i]==0:
        pass
    else:
        miN=(miN//A[i] +1) *A[i]

    if maX%A[i]==0:
        maX=min((maX//A[i]) *A[i] + A[i]-1 ,(maX//A[i+1])*A[i+1]+maX%A[i+1])
    else:
        maX=min((maX//A[i]) *A[i] + A[i]-1 ,(maX//A[i+1])*A[i+1]+maX%A[i+1])
    Amax=max(A[i],Amax)

print(miN,maX)


Fixed submission:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    else:
        if miN%A[i]==0:
            pass
        else:
            miN=(miN//A[i] +1) *A[i]
    maX=maX-maX%A[i] + A[i]-1

mmaX=maX
for i in range(K):
    mmaX-=mmaX%A[i]
if mmaX==2:
    print(miN,maX)
else:
    print(-1)

Buggy python submission (verdict: Runtime Error):
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2
Amax=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2 or A[i]>(maX//A[i+1])*A[i+1]+maX%A[i+1]:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    if miN%A[i]==0:
        pass
    else:
        miN=(miN//A[i] +1) *A[i]

    if maX%A[i]==0:
        maX=(maX//A[i]) *A[i] + A[i]-1
    else:
        maX=(maX//A[i]) *A[i] + A[i]-1
    Amax=max(A[i],Amax)

print(miN,maX)


Fixed submission:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    else:
        if miN%A[i]==0:
            pass
        else:
            miN=(miN//A[i] +1) *A[i]
    maX=maX-maX%A[i] + A[i]-1

mmaX=maX
for i in range(K):
    mmaX-=mmaX%A[i]
if mmaX==2:
    print(miN,maX)
else:
    print(-1)