Problem:
 Score : 500 points    Problem Statement An adult game master and N children are playing a game on an ice rink.
The game consists of K rounds.
In the i -th round, the game master announces:   Form groups consisting of A_i children each!   Then the children who are still in the game form as many groups of A_i children as possible.
One child may belong to at most one group.
Those who are left without a group leave the game. The others proceed to the next round.
Note that it's possible that nobody leaves the game in some round.  In the end, after the K -th round, there are exactly two children left, and they are declared the winners.  You have heard the values of A_1 , A_2 , ..., A_K . You don't know N , but you want to estimate it.  Find the smallest and the largest possible number of children in the game before the start, or determine that no valid values of N exist.      Constraints  1 \leq K \leq 10^5  2 \leq A_i \leq 10^9  All input values are integers.         Input Input is given from Standard Input in the following format:  K  A_1  A_2  ...  A_K       Output Print two integers representing the smallest and the largest possible value of N , respectively,
or a single integer -1 if the described situation is impossible.        Sample Input 1 4
3 4 3 2      Sample Output 1 6 8  For example, if the game starts with 6 children, then it proceeds as follows:   In the first round, 6 children form 2 groups of 3 children, and nobody leaves the game.  In the second round, 6 children form 1 group of 4 children, and 2 children leave the game.  In the third round, 4 children form 1 group of 3 children, and 1 child leaves the game.  In the fourth round, 3 children form 1 group of 2 children, and 1 child leaves the game.   The last 2 children are declared the winners.       Sample Input 2 5
3 4 100 3 2      Sample Output 2 -1  This situation is impossible.
In particular, if the game starts with less than 100 children, everyone leaves after the third round.       Sample Input 3 10
2 2 2 2 2 2 2 2 2 2      Sample Output 3 2 3

Solution (Python):
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
k = onem()

a = l()

ma = 3
mi = 2

if a[-1] != 2:
    print(-1)
    exit()

for i in range(1,k):
    if ma >= (-(-mi//a[-(i+1)])) * a[-(i+1)]:
        ma = ma//a[-(i+1)] * a[-(i+1)]  + a[-(i+1)] - 1
        mi = (-(-mi//a[-(i+1)])) * a[-(i+1)]
    else:
        print(-1)
        exit()
print(mi,ma)

Solution (Python):
k=int(input())
a=[int(j) for j in input().split()]
if a[-1]!=2:
    print(-1)
    exit()

import math

amin=2
amax=2
for i in range(k)[::-1]:
    amin+=(-amin)%a[i]
    amax-=amax%a[i]
    amax+=a[i]-1

if amin>amax:
    print(-1)
else:
    print(amin,amax)

Solution (Python):
import sys
input = sys.stdin.readline

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

low,high = 2,2

for a in A[::-1]:
    low += (-low)%a
    high -= high%a
    high += (a-1)

if low > high:
    print(-1)
else:
    print(low,high)

Solution (Python):

import math
K = int(input())
A = list(map(int,input().split()))
B = A[::-1]

MIN = 0
MAX = 0
flag = 0
for i in range(K):
    if i == 0:
        if B[i] != 2:
            flag = 1
            break
        else:
            MIN = 2
            MAX = 3
    else:
        if MAX < B[i]:
            flag = 1
            break
        else:
            MAX = (MAX//B[i] + 1)*B[i]-1
            MIN = math.ceil(MIN/B[i])*B[i]
            if MAX < MIN:
                flag = 1
                break
if flag == 1:
    print(-1)
else:
    print(MIN,MAX)

Solution (Python):
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9 + 7

def sol():
    K = int(input())
    A = list(map(int, input().split()))

    maxAns = 2
    minAns = 2

    for a in reversed(A):
        maxAns = maxAns // a * a + a - 1
        minAns = -(-minAns // a) * a

    resMax = maxAns
    resMin = minAns

    for a in A:
        resMax = resMax // a * a
        resMin = resMin // a * a

    if resMax == resMin == 2:
        print(minAns, maxAns)
    else:
        print(-1)

sol()

Solution (Python):
K=int(input())
*A, = map(int,input().split())
m,M = 2,2
for a in A[::-1]:
    M = M//a*a+(a-1)
    m = ((m-1)//a+1)*a
    if m>M:
        print(-1)
        break
else:print(m,M)

Solution (Python):



import sys  
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools



sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  
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 DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe


def local_input():
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)


def solve():
    k = int(input())
    a = list(map(int,input().split()))
    
    mi = 2
    ma = 2

    if a[k-1] != 2:
        print(-1)
        exit()

    for i in range(k):
        if ma < a[k-1-i]:
            print(-1)
            exit()
        
        ma = a[k-1-i]*(ma // a[k-1-i]) + a[k-1-i] - 1
        
        if a[k-1-i]*(ma // a[k-1-i]) < mi:
            print(-1)
            exit() 
                    
        mi = a[k-1-i]* ((mi -1)  // a[k-1-i] + 1)

    print(mi,ma)

    return 0

if __name__ == "__main__":
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

Solution (Python):

from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    n = I()

    return


def B():
    def f(m):
        if d[m] != None:
            return d[m]
        n = m
        for i in a:
            n = n-n%i
        d[m] = n
        return n
    k = I()
    a = LI()
    d = defaultdict(lambda : None)
    l,r = 0,1e19
    while r-l > 1:
        m = (r+l)//2
        if f(m) < 2:
            l = m
        else:
            r = m
    mi = r
    l,r = 0,1e19
    while r-l > 1:
        m = (r+l)//2
        if f(m) <= 2:
            l = m
        else:
            r = m
    ma = l
    if mi <= ma:
        if f(mi) != 2:
            print(-1)
        else:
            print(int(mi),int(ma))
    else:
        print(-1)
    return


def C():
    n = I()

    return


def D():
    n = I()

    return


def E():
    n = I()

    return


def F():
    n = I()

    return



if __name__ == "__main__":
    B()

Solution (Python):
n=int(input())
arr=list(map(int,input().split()))
arr=arr[::-1]
if arr[0]!=2:
  print(-1)
else:
  arr=arr[1:]
  l=2
  r=3
  for val in arr:
    if (l<=val*(l//val)<=r) or (l<=val*(r//val)<=r):
      if l%val!=0:
        l=val*(l//val+1)
      r=val*(r//val+1)-1
    else:
      print(-1)
      break
  else:
    print(l,r)

Solution (Python):
k=int(input())
a=list(map(int,input().split()))
l=2
h=2
for i in a[::-1]:
    tl=i*-(-l//i)
    th=i*(h//i)
    if tl>h or th<l:
        print(-1)
        quit()
    else:
        l=tl
        h=th+i-1
print(l,h)

Solution (Python):
def main():
    K = int(input())
    A = list(map(int, input().split()))
    mn = 2
    mx = 2
    for a in reversed(A):
        if mx < a:
            print(-1)
            return
        mn = -(-mn//a) * a
        mx = mx // a * a + (a-1)
        if mx < mn:
            print(-1)
            return
    print(mn, mx)


if __name__ == "__main__":
    main()

Solution (Python):
K=int(input())
A=list(map(int,input().split()))
MAX=2
MIN=2
A=A[::-1]
ans=0
for a in A:
    MIN=(MIN-1)//a*a+a
    if MIN>MAX:
        ans=-1
        break
    MAX=MAX//a*a+a-1
if ans==-1:
    print(-1)
else:
    print(str(MIN)+" "+str(MAX))

Solution (Python):
k = int(input())
a = list(map(int, input().split()))
if a[-1] != 2:
    print(-1)
    quit()
l, r = 2, 3
for i in range(k-2, -1, -1):
    s = ((l-1)//a[i]+1) * a[i]
    if s > r:
        print(-1)
        quit()
    t = ((r-1)//a[i]+1) * a[i]
    t = t-1 if t > r else t+a[i]-1
    l, r = s, t
print(l, r)

Solution (Python):
from functools import reduce
from math import floor, ceil


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


R = reduce(
    lambda acc, a:
        acc if acc[0] > acc[1] else
        (
            a * ceil(acc[0] / a),
            a * (floor(acc[1] / a) + 1) - 1
        ),
    reversed(A),
    (2, 2)
)
ans = (
    -1 if R[0] > R[1] else
    ' '.join(map(str, R))
)


print(ans)

Solution (Python):
import math
k=int(input())
A=[int(i) for i in input().split()]
A=A[::-1]
u_lim,l_lim=2,2
ans=0
for i in range(k):
  a=A[i]
  if math.ceil(l_lim/a)>math.floor(u_lim/a):
    ans=-1
  l_lim=math.ceil(l_lim/a)*a
  u_lim=math.floor(u_lim/a)*a+a-1
if ans==-1:
  print(-1)
else:
  print(l_lim,u_lim)

Solution (Python):
n=int(input())
da=list(map(int ,input().split()))
Min=2
Max=2
ju=True
for i in da[::-1]:
    mi=(Min+i-1)//i
    ma=Max//i
    if mi*i>Max or ma*i<Min:
        ju=False
        break
    Min=mi*i
    Max=ma*i+i-1
if ju:
    print(Min,Max)
else:
    print(-1)

Solution (Python):
import math
k = int(input())
a = [int(item) for item in input().split()]
a.reverse()

max_num = 2 
min_num = 2 
for i in range(k):
    if int(math.floor(max_num / a[i])) * a[i] < int(math.ceil(min_num / a[i])) * a[i]:
        print(-1)
        exit()
    next_max = int(math.floor(max_num / a[i])) * a[i] + a[i] - 1
    next_min = int(math.ceil(min_num / a[i])) * a[i]
    max_num = next_max
    min_num = next_min
print(min_num, max_num)

Solution (Python):
import math
N = int(input())
A = list(map(int,input().split()))
A.reverse()
l = 2
r = 2
for i in range(N):
  l = math.ceil(l/A[i])*A[i]
  r = math.floor(r/A[i])*A[i]+A[i]-1
if r >= l:
  print(l,r)
else:
  print(-1)

Solution (Python):
k = int(input())
a = list(map(int,input().split()))
def g(x):
    for i in range(k):
        x = (x//a[i])*a[i]
    return x

l,r = 0,2+k*max(a)
while abs(r-l) > 1:
    mid = (l+r)//2
    if g(mid) >=2:
        r = mid
    else:
        l = mid
m = r

l,r = 0,2+k*max(a)
while abs(r-l) > 1:
    mid = (l+r)//2
    if g(mid) <= 2:
        l = mid
    else:
        r = mid
M = l
if m <= M:
    print(m,M)
else:
    print(-1)

Solution (Python):
k = int(input())
nums = reversed([ int(s) for s in input().split(" ")])

pass_min = 2
pass_max = 2
for n in nums:

    
    

    
    aaa = pass_min + (n - pass_min % n) % n

    
    bbb = pass_max - pass_max % n

    
    if aaa > pass_max or bbb < pass_min:
        print(-1)
        exit()
    
    pass_min = aaa
    pass_max = bbb + (n - 1)

print(pass_min, pass_max)

Solution (Python):
k = int(input())
a = list(map(int,input().split()))

def check(n):
    for i in a:
        n = n//i*i
    return n

bot=top=0


l = 0
r = sum(a)+2
while r-l>1:
    mid = (l+r)//2
    if check(mid) >1:
        r = mid
    else:
        l = mid
bot = r


l = 0
r = sum(a)+2
while r-l>1:
    mid = (l+r)//2
    if check(mid) < 3:
        l = mid
    else:
        r = mid
top = l
if bot <= top:
    print(bot, top)
else:
    print(-1)

Solution (Python):
k = int(input())
aa = list(map(int, input().split()))[::-1]
b=t=2
for a in aa:
    b += (a-b%a)%a
    t -= t%a
    t += a-1
    if b > t:
        print(-1)
        exit()
print(b,t)

Solution (Python):
from math import ceil

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

K = int(input())
L = list(map(int, input().split()))

maxr = 2
minr = 2
r = 0
for n in reversed(L):
    
    if ceil(maxr//n)*n >= minr:
        minr = ceil(minr/n)*n
        maxr = (maxr)//n*n+n-1
    else:
        print(-1)
        exit()

print(int(minr), maxr)

Solution (Python):
from math import ceil

import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

K = int(input())
L = list(map(int, input().split()))

maxr = 2
minr = 2
r = 0
for n in reversed(L):
    
    if ceil(maxr//n)*n >= minr:
        
        
        minr = ceil(minr/n)*n
        maxr = (maxr)//n*n+n-1
    else:
        n = -1
        break

if n == -1:
    print(n)
else:
    print(int(minr), maxr)

Solution (Python):
K = int(input())
A = list(map(int, input().split()))

_min=2
_max=2

for a in A[::-1]:
  
  if _min%a:
    if a*(_min//a) + a > _max:
      print(-1)
      break
    else:
      _min = a*(_min//a) + a
  else:
    _min = _min
  
  _max = a*(_max//a) + a-1
else:
  print(_min, _max)

Solution (Python):
K = int(input())
A = list(map(int, input().split()))

def winner_count(N, A=A):
    for a in A:
        N = a*(N//a)
    return N

def bisect_left(func, l, r, target):
    
    
    
    if l==r:
        return 0
    if l+1==r:
        if func(l)< target:
            return r
        else:
            return l
    c = (l+r)//2
    if target <= func(c):
        return bisect_left(func, l, c, target)
    else:
        return bisect_left(func, c, r, target)

def bisect_right(func, l,r, target):
    if l==r:
        return 0
    if l+1==r:
        if target < func(r):
            return l
        else:
            return r
    c = (l+r)//2
    if target < func(c):
        return bisect_right(func, l, c, target)
    else:
        return bisect_right(func, c, r, target)

_min = bisect_left(winner_count, 1, sum(A)+2, 2)
_max = bisect_right(winner_count, 1, sum(A)+2, 2)


if _min > _max:
	print(-1)
else:
	print(_min, _max)

Solution (Python):
k = int(input())
alist = list(map(int, input().split()))

if alist[-1] != 2:
  print(-1)
else:
  mina = 2
  maxa = 3
  is_nn = False
  for a in alist[::-1][1:]:
    mina = a * ((mina + a - 1) // a)
    maxa = a * (maxa // a) + a - 1
    if mina >= maxa or mina // a == maxa == a:
      is_nn = True
      break

  if is_nn:
    print(-1)
  else:
    print(mina, maxa)

Solution (Python):
import sys
from math import floor,ceil
K=int(input())
A=[int(i) for i in input().split()]
def f(x):
    t=x
    for a in A:
        t=t-(t%a)
    return t

mi=0
ma=10**16
while ma-mi>1:
    mid=(ma+mi)//2
    if f(mid)>=2:
        ma=mid
    else:
        mi=mid
left=ma
mi=0
ma=10**16
while ma-mi>1:
    mid=(ma+mi)//2
    if f(mid)<=2:
        mi=mid
    else:
        ma=mid
if left>mi:
    print(-1)
else:
    print(left,mi)

Solution (Python):
import sys
from math import floor,ceil
K=int(input())
A=[int(i) for i in input().split()]
B=A[::-1]
a,b=2,2
for i in range(0,K):
    x=B[i]
    c = ceil(a / x) * x
    if a<=c<=b:
        a = c
        b = floor(b / x) * x + x -1
    else:
        print(-1)
        sys.exit()
    
print(a,b)

Solution (Python):
import sys
K=int(input())
A=[int(i) for i in input().split()]
B=A[::-1]
if B[0]!=2:
    print(-1)
    sys.exit()
a=2
b=3
for i in range(1,K):
    x=B[i]
    if a%x==0:
        c=a
    else:
        c=((a//x)+1)*x
    if a<=c<=b:
        a=c
        b=((b//x)+1)*x-1

    else:
        print(-1)
        sys.exit()
    
print(a,b)

Solution (Python):
def L(l,a):
    return ((l-1)//a)*a+a

def R(r,a):
    return (r//a)*a+a-1
K = int(input())
x = list(map(int,input().split()))
l=2
r=2
for i in range(K):
    a = x.pop()
    l = L(l,a)
    r = R(r,a)
    if l > r:
        l = r = -1
        print(l)
        exit()

print(l,r)

Solution (Python):




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

s,l = 2,2

if al[-1] != 2:
    print(-1)
    exit()
if K==1:
    print(s,l+al[0]-1)
    exit()

for i in range(K-1,-1,-1):
    c = 0
    
    
    
    
    
    
    if s%al[i-1]==0:
        tmps = s
    else:tmps = s + al[i-1] - s%al[i-1]
    if tmps <= l+al[i]-1:
        s = tmps
        c+=1
        l = (l+al[i]-1)//al[i-1]*al[i-1]

    if c==0:
        print(-1)
        exit()
    if i==1:
        print(s,l+al[0]-1)

Solution (Python):




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

s,l = 2,2

if al[-1] != 2:
    print(-1)
    exit()
if K==1:
    print(s,l+al[0]-1)

for i in range(K-1,-1,-1):
    c = 0
    if s%al[i-1]==0:
        tmps = s
    else:tmps = s + al[i-1] - s%al[i-1]
    if tmps <= l+al[i]-1:
        s = tmps
        c+=1
        l = (l+al[i]-1)//al[i-1]*al[i-1]

    if c==0:
        print(-1)
        exit()
    if i==1:
        print(s,l+al[0]-1)

Solution (Python):
from functools import reduce
from math import floor, ceil


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


R = reduce(
    lambda acc, a: (
        acc if acc[0] > acc[1] else
        (
            a * ceil(acc[0] / a),
            a * (floor(acc[1] / a) + 1) - 1
        )
    ),
    reversed(A),
    (2, 2)
)


ans = -1 if R[0] > R[1] else ' '.join(map(str, R))
print(ans)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

k = ni()
a = list(li())

if a[-1] != 2:
    print(-1)
    
else:
    lower = 2
    upper = 3
    exist = True
    for ai in a[-2::-1]:
        if lower%ai > 0 and upper%ai > 0 and lower//ai == upper//ai:
            exist = False
            print(-1)
            break
        
        lower = -(-lower//ai) * ai
        upper = (upper//ai) * ai + (ai-1)
        
    if exist:
        print(lower, upper)

Solution (Python):
import math

K = int(input())
A = list(map(int,input().split()))[::-1]

mi = 2
ma = 2
res = 0

for i in range(K) :
    if (mi % A[i]) and (ma % A[i]) and ((mi // A[i]) == (ma // A[i])) :
        res = -1
        break
    
    mi = math.ceil(mi / A[i]) * A[i]
    ma = math.floor(ma / A[i]) * A[i] + A[i] - 1

if res == -1 :
    print(res)
else :
    print(mi,ma)

Solution (Python):
k = int(input())
a = list(map(int, input().split()))

child = 2
cmin = 2
cmax = 2
for ai in a[::-1]:
    if cmin % ai:
        cmin = (cmin // ai + 1) * ai
    cmax = cmax // ai * ai + ai - 1
    if cmin > cmax:
        print(-1)
        exit()

print(cmin, cmax)

Solution (Python):
K =int(input())
A = list(map(int,input().split()))
right = sum(A)
length = len(A)
maxi = 3
mini = 2
temp1 = 2
temp2 = 2
test = A[0]

for a in A[K-2::-1]:
        if(temp1 == a and temp2 == a):
            maxi = maxi
        elif(maxi%a == a-1):
            maxi += a
        else:
            maxi += (a-1-maxi%a)
        
        if(mini%a != 0):
            mini += (a - mini%a)
        temp2 = temp1
        temp1 = a
test1 = mini
test2 = maxi
for a in A:
        test1 = test1 - test1%a
        test2 = test2 - test2%a

if(test1 == 2 and test2 == 2):
        print(mini,maxi)
else:
        print(-1)

Solution (Python):
K = int(input())
A = list(map(int, input().split()))


ok, ng = 10 ** 18, 0
while abs(ok - ng) > 1:
    n = (ok + ng) // 2
    x = n
    for a in A:
        x = (x // a) * a
    if x >= 2:
        ok = n
    else:
        ng = n
m = ok


ok, ng = 0, 10 ** 18
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    n = x
    for a in A:
        x = x // a * a

    if x <= 2:
        ok = n
    else:
        ng = n
M = ok



mx, Mx = m, M
for a in A:
    mx = (mx // a) * a
    Mx = (Mx // a) * a

if mx == 2 and Mx == 2:
    print(m, M)
else:
    print(-1)

Solution (Python):
K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    a = A[i]
    if nowm <= ((nowm+a-1)//a)*a and ((nowm+a-1)//a)*a <= nowM:
        nowm = ((nowm+a-1)//a)*a
        nowM = (nowM//a)*a + a - 1
    else:
        ans = -1
        break
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))

Solution (Python):
from math import ceil
N = int(input())
A = [int(a) for a in input().split()]

if A[-1] != 2: print(-1)
else:
    PossibleMin, PossibleMax = A[-1], A[-1] + 1
    for i in reversed(range(N-1)):
        PossibleMin = ceil(PossibleMin/A[i]) * A[i]
        PossibleMax = (PossibleMax//A[i]) * A[i] + A[i] - 1
    if PossibleMax >= PossibleMin: print(PossibleMin, PossibleMax)
    else: print(-1)

Solution (Python):
k=int(input())
*a,=map(int,input().split())

l,r=2,2
for i in a[::-1]:
  l=(l+i-1)//i*i
  if r<l:
    print(-1)
    break
  r=(r//i+1)*i-1
else:
  print(l,r)

Solution (Python):
import sys

k = int(input())
a = list(map(int, input().split()))[::-1]

m, M = 2, 2

for i in range(k):
	if m % a[i] != 0:
		m += a[i] - (m % a[i])

	M = M - (M % a[i]) + a[i] - 1

	if m > M:
		print(-1)
		sys.exit()

print(m, M)

Solution (Python):





K = int(input())
As = list(map(int, input().split()))
As.reverse()

fail = False
if As[0] != 2:
    fail = True
else:
    mn = 2
    mx = 3
    for a in As[1:]:
        
        
        if mn % a != 0:
            mn = (mn // a) * a + a
        if mx % a != 0:
            mx = (mx // a) * a
        if mn > mx:
            fail = True
            break

        
        mx = mx + (a - 1)
if fail:
    print(-1)
else:
    print(mn, mx)

Solution (Python):
k = int(input())
a = list(map(int,input().split()))


def g(n,a,k):
    for i in range(k):
        n = n - (n%a[i])
    return n



s = 0
t = 2 + k*max(a)
while t-s > 1:
    m = (s+t)//2
    if g(m,a,k)> 2:
        t = m
    else:
        s = m
    
p = 0
q = 2+k*max(a)
while q-p > 1:
    m = (p+q)//2
    if g(m,a,k) >= 2:
        q = m
    else:
        p = m

c = 1
if g(s,a,k) == 2:
    res = s
elif g(t,a,k) == 2:
    res = t
else:
    c = -1

if g(q,a,k) == 2:
    res2 = q
elif g(p,a,k) == 2:
    res2 = p
else:
    c = -1

if c == 1:
    print(res2,res)
else:
    print(-1)

Solution (Python):
k = int(input())
a = list(map(int,input().split()))


def g(n,a,k):
    for i in range(k):
        n = n - (n%a[i])
    return n



s = 0
t = 2 + k*max(a)
while t-s > 1:
    m = (s+t)//2
    if g(m,a,k)> 2:
        t = m
    else:
        s = m
    
p = 0
q = 2+k*max(a)
while q-p > 1:
    m = (p+q)//2
    if g(m,a,k) >= 2:
        q = m
    else:
        p = m

c = 1
if g(s,a,k) == 2:
    res = s
elif g(t,a,k) == 2:
    res = t
else:
    c = -1

if g(q,a,k) == 2:
    res2 = q
elif g(p,a,k) == 2:
    res2 = p
else:
    c = -1

if c == 1:
    print(res2,res)
else:
    print(-1)

Solution (Python):
k = int(input())
a = list(map(int,input().split()))
a = a[::-1]

c = 2 
d = 2 
res = 1 

for i in range(k):
    if d < a[i]:
        res = -1
        break
    if i != k-1:
        if c % a[i] != 0 or d % a[i] != 0:
            res = -1
            break
        else:
            d = d + a[i] -1
            p = c%a[i+1]
            q = d%a[i+1]
            if p == 0:
                c2 = c
            else:
                c2 = c + a[i+1]-p
            d2 = d-q
            
            if c2 <= d2:
                c = c2
                d = d2
            else:
                res = -1
                break
    else:
        d = d + a[i] -1
            
        
    
    
if res == -1:
    print(-1)
else:
    print(str(c) + ' ' + str(d))

Solution (Python):
from math import ceil
K=int(input())
A=[int(i) for i in input().split()]
A.reverse()
n_range=[2,2]
for a in A:
  if a*ceil(n_range[0]/a)<=n_range[1]:
    n_range[0]=a*ceil(n_range[0]/a)
  else:
    print(-1)
    exit()
  if a*(n_range[1]//a)>=n_range[0]:
    n_range[1]=a*(n_range[1]//a)+a-1
    
print(n_range[0],n_range[1])

Solution (Python):
def simulate(N):
    for A in As:
        N -= N % A
    return N

K = int(input())
As = list(map(int, input().split()))

iLft, iRgt = 1, sum(As) - K + 3
while iRgt - iLft > 1:
    iMid = (iLft + iRgt) // 2
    if simulate(iMid) < 2:
        iLft = iMid
    else:
        iRgt = iMid
ansMin = iRgt

iLft, iRgt = 1, sum(As) - K + 3
while iRgt - iLft > 1:
    iMid = (iLft + iRgt) // 2
    if simulate(iMid) <= 2:
        iLft = iMid
    else:
        iRgt = iMid
ansMax = iLft

if ansMin <= ansMax:
    print(ansMin, ansMax)
else:
    print(-1)

Solution (Python):
def inpl(): return [int(i) for i in input().split()]

K = int(input())
A = list(reversed(inpl()))
X,Z = 2,2
for Ai in A:
    X = -(-X//Ai)*Ai
    if X > Z:
        print(-1)
        break
    Z = (Z//Ai)*Ai + Ai-1
else:    
    print(X, Z)

Solution (Python):
def ceil(a,b):
    return -((-a)//b)
def floor(a,b):
    return a//b
K=int(input())
A=[int(i) for i in input().split()]
L=[0 for i in range(K+1)]
R=[0 for i in range(K+1)]
L[K]=2
R[K]=2
for i in range(1,K+1)[::-1]:
    L[i-1]=ceil(L[i],A[i-1])*A[i-1]
    R[i-1]=floor(R[i],A[i-1])*A[i-1]+A[i-1]-1
if L[0]<R[0]:
    print(L[0],R[0])
else:
    print(-1)

Solution (Python):
def ceil(a,b):
    return -((-a)//b)
def floor(a,b):
    return a//b
K=int(input())
A=[int(i) for i in input().split()]
L=[0 for i in range(K+1)]
R=[0 for i in range(K+1)]
L[K]=2
R[K]=2
for i in range(1,K+1)[::-1]:
    L[i-1]=ceil(L[i],A[i-1])*A[i-1]
    R[i-1]=floor(R[i],A[i-1])*A[i-1]+A[i-1]-1
if L[0]<=R[0]:
    print(L[0],R[0])
else:
    print(-1)

Solution (Python):





"""
AGC020 B
"""

k = int(input())
alist = list(map(int, input().split()))
alist.reverse()

pmax = 2
pmin = 2

for a in alist:
    ma = a*(pmax//a)
    q, r = divmod(pmin, a)
    if r == 0:
        mi = a*q
    else:
        mi = a*q+a
    if ma < mi:
        print(-1)
        exit()
    pmax = ma+a-1
    pmin = mi

print(pmin, pmax)

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
def judge(k:int, a:list):
    mi = ma = 2
    for ai in a[::-1]:
        
        if mi%ai:
            mi = -(-mi//ai) * ai
            
        
        ma = (ma//ai + 1) * ai - 1

        if ma < mi:
            return False, (-1,-1)
        
    return True, (mi,ma)
 
k = ni()
a = list(li())
 
tf, (mi,ma) = judge(k,a)
if tf:
    print(mi,ma)
else:
    print(-1)

Solution (Python):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

def judge(k:int, a:list):
    mi = ma = 2
    for ai in a[::-1]:
        
        if mi%ai:
            mi += ai - mi%ai
            
        ma += (ai - 1) - (ma % ai)
        
        if ma < mi:
            return False, (-1,-1)
        
    return True, (mi,ma)

k = ni()
a = list(li())

tf, (mi,ma) = judge(k,a)
if tf:
    print(mi,ma)
else:
    print(-1)

Solution (Python):
def minandmax(bottom,up,mod): 
    if bottom%mod == 0:
        mnm = bottom
    else:
        mnm = bottom + (mod-bottom%mod)
        if mnm > up:
            mnm = None
    if up%mod == 0:
        mxm = up
    else:
        mxm = up - up%mod
        if mxm < bottom:
            mxm = None
    ans = [mnm,mxm]
    return ans

k = int(input())
a = list(map(int,input().split()))
i = k-1
bottom = 2
up = 2

check = True
if a[-1] != 2:
    check = False
while i >= 1 and check:
    nbottom = minandmax(bottom,up+a[i]-1,a[i-1])[0]
    nup = minandmax(bottom,up+a[i]-1,a[i-1])[1]
    if nbottom == None and nup == None:
        check = False
    elif nbottom == None:
        nbottom = nup
    elif nup == None:
        nup = nbottom
    i += -1
    bottom = nbottom
    up = nup

if check:
    bottom = minandmax(bottom,bottom+a[0]-1,1)[0]
    up = minandmax(up,up+a[0]-1,1)[1]
    print(bottom,up)
else:
    print("-1")

Solution (Python):
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

K = int(input())
aa = reversed(inpl())

MIN = MAX = 2
for a in aa:
    if MIN%a == 0 or MAX//a - MIN//a > 0:
        MIN = ((MIN-1)//a+1) *a
        MAX = MAX//a*a+a-1
    else:
        print(-1)
        sys.exit()

print(MIN,MAX)

Solution (Python):
K = int(input())
A = list(map(int, input().split()))
ma = 2
mi = 2
for a in reversed(A):
    ma = a * (ma // a + 1) - 1
    mi = a * -(-mi // a)
    if mi > ma:
        print(-1)
        break
else:
    print(mi, ma)

Solution (Python):
input()
l=s=2
for i in map(int,input().split()[::-1]):
  s=i*(s//i+[1,0][s%i==0])
  l=i*(l//i+1)-1
print(-1) if s>l else print(s,l)

Solution (Python):


from collections import deque
import itertools as it
import sys
import math
import re

sys.setrecursionlimit(1000000)

K = input()
A = map(int, raw_input().split())[::-1]

minN = 2
maxN = 2

for num in A:
    minN = (minN / num + (minN % num != 0)) * num
    maxN = maxN / num * num + num - 1
    if maxN < minN:
        print -1
        exit()

print minN, maxN