Buggy python submission (verdict: Time Limit Exceeded):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-2,-1,-1):
        t = a[i]
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b += t-b%t
        else:
            b = t
        if c % t == 0:
            pass
        elif c > t:
            c += t-c%t
        else:
            return -1
    bb = b
    cc = c-1
    while True:
        bb = b
        for i in range(n):
            bb -= bb%a[i]
        if bb != 2:
            b += a[0]
        else:
            break
    for i in range(n):
        cc -= cc%a[i]
    if cc != 2:
        return 1/0

    return '{} {}'.format(b, c-1)

print(main())




Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

# 下がtrue, falseになる最小値を返す
def bs(f, mi, ma):
    mm = -1
    while ma > mi:
        mm = (ma+mi) // 2
        if f(mm):
            mi = mm + 1
        else:
            ma = mm
    if f(mm):
        return mm + 1
    return mm

def main():
    n = I()
    a = LI()

    def f(i):
        for c in a:
            i -= i%c
        return i < 2

    def g(i):
        for c in a:
            i -= i%c
        return i <= 2

    mi = bs(f,0,sum(a)+3)
    ma = bs(g,0,sum(a)+3) - 1
    if mi <= ma:
        return '{} {}'.format(mi,ma)
    return -1




print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-2,-1,-1):
        t = a[i]
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b += t-b%t
        else:
            b = t
        if c % t == 0:
            pass
        elif c > t:
            c += t-c%t
        else:
            return -1
    bb = b
    cc = c-1
    while True:
        bb = b
        for i in range(n):
            bb -= bb%a[i]
        if bb != 2:
            b += a[0]
        else:
            break
    for i in range(n):
        cc -= cc%a[i]
    if cc != 2:
        while 1:
            cc += 1

    return '{} {}'.format(b, c-1)

print(main())




Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

# 下がtrue, falseになる最小値を返す
def bs(f, mi, ma):
    mm = -1
    while ma > mi:
        mm = (ma+mi) // 2
        if f(mm):
            mi = mm + 1
        else:
            ma = mm
    if f(mm):
        return mm + 1
    return mm

def main():
    n = I()
    a = LI()

    def f(i):
        for c in a:
            i -= i%c
        return i < 2

    def g(i):
        for c in a:
            i -= i%c
        return i <= 2

    mi = bs(f,0,sum(a)+3)
    ma = bs(g,0,sum(a)+3) - 1
    if mi <= ma:
        return '{} {}'.format(mi,ma)
    return -1




print(main())

Buggy python submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-2,-1,-1):
        t = a[i]
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b += t-b%t
        else:
            b = t
        if c % t == 0:
            pass
        elif c > t:
            c += t-c%t
        else:
            return -1
    bb = b
    cc = c-1
    for i in range(n):
        bb -= bb%a[i]
        cc -= cc%a[i]
    if bb != 2:
        return 1 / 0
    if cc != 2:
        while 1:
            cc += 1

    return '{} {}'.format(b, c-1)

print(main())




Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

# 下がtrue, falseになる最小値を返す
def bs(f, mi, ma):
    mm = -1
    while ma > mi:
        mm = (ma+mi) // 2
        if f(mm):
            mi = mm + 1
        else:
            ma = mm
    if f(mm):
        return mm + 1
    return mm

def main():
    n = I()
    a = LI()

    def f(i):
        for c in a:
            i -= i%c
        return i < 2

    def g(i):
        for c in a:
            i -= i%c
        return i <= 2

    mi = bs(f,0,sum(a)+3)
    ma = bs(g,0,sum(a)+3) - 1
    if mi <= ma:
        return '{} {}'.format(mi,ma)
    return -1




print(main())

Buggy python submission (verdict: Runtime Error):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-2,-1,-1):
        t = a[i]
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b = (b+t) - (b%t)
        else:
            b = t
        if c % t == 0:
            pass
        elif c > t:
            c = (c+t) - (c%t)
        else:
            return -1
    bb = b
    cc = c-1
    for i in range(n):
        bb -= bb%a[i]
        cc -= cc%a[i]
    if bb != 2:
        return 1 / 0
    if cc != 2:
        while 1:
            cc += 1

    return '{} {}'.format(b, c-1)

print(main())




Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

# 下がtrue, falseになる最小値を返す
def bs(f, mi, ma):
    mm = -1
    while ma > mi:
        mm = (ma+mi) // 2
        if f(mm):
            mi = mm + 1
        else:
            ma = mm
    if f(mm):
        return mm + 1
    return mm

def main():
    n = I()
    a = LI()

    def f(i):
        for c in a:
            i -= i%c
        return i < 2

    def g(i):
        for c in a:
            i -= i%c
        return i <= 2

    mi = bs(f,0,sum(a)+3)
    ma = bs(g,0,sum(a)+3) - 1
    if mi <= ma:
        return '{} {}'.format(mi,ma)
    return -1




print(main())