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
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

K = ir()
A = lr()[::-1]
domain = [2, 2] 
for i in range(K):
    x = A[i]
    left = domain[0]; right = domain[1]
    if x > right * 2 - 1:
        print(-1)
        exit()
    left += (-left) % x
    right -= right % x
    right += x - 1
    if left > right:
        print(-1)
        exit()
    domain = [left, right]

print(*domain)

Solution (Python):
import sys
k=int(input())
a=list(map(int,input().split()))
min=2;max=2
min=((min+a[k-1]-1)//a[k-1])*a[k-1]
max=(max//a[k-1])*a[k-1]
if min>max:
  print(-1)
  sys.exit()
for i in range(k-1,0,-1):
  max=max+a[i]-1
  min=((min+a[i-1]-1)//a[i-1])*a[i-1]
  max=(max//a[i-1])*a[i-1]
  if min>max:
    print(-1)
    sys.exit()
max+=a[0]-1
print(min,max)

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

l, r = 1, 10 ** 18
while r - l > 1:
    m = (l + r) // 2
    M = m
    for a in A:
        M = (M // a) * a

    if M <= 2:
        l = m
    else:
        r = m
ans_max = l

l, r = 1, 10 ** 18
while r - l > 1:
    m = (l + r) // 2
    M = m
    for a in A:
        M = (M // a) * a

    if M >= 2:
        r = m
    else:
        l = m
ans_min = r

if ans_min > ans_max:
    print(-1)
else:
    print(ans_min, ans_max)

Solution (Python):
k = int(input())
l = reversed(list(map(int, input().split())))
lo,hi = 2,2
for a in l:
  nl = lo + (a - lo%a)%a
  nh = (hi//a)*a + a-1
  if nl > nh: print(-1); exit(0)
  lo,hi = nl,nh
print(lo,hi)

Solution (Python):
k = int(input())
A = list(map(int, input().split()))
UP = 2
DOWN = 2 
for a in A[::-1]:
  DOWN = ((DOWN - 1) // a + 1) * a
  UP = UP // a * a + a  - 1
  if UP < DOWN:
    print(-1)
    exit()
print(DOWN, UP)

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

mina = maxa = 2

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

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

lower = 2
upper = 2
flag = True
for i in range(k):
    lowm = lower//arr[i]
    upm = upper//arr[i]

    if upm == 0:
        flag = False
    if arr[i] * lowm < lower:
        lowm += 1
        if lowm > upm:
            flag = False
    lower = arr[i] * lowm
    upper = arr[i] * upm + arr[i]-1
    
    
    



if flag:
    print(lower,upper)
else:
    print(-1)

Solution (Python):
from sys import stdout
import sys,resource
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

k = inn()
a = inl()
if k==1:
    if a[0]==2:
        print("2 3")
    else:
        print(-1)
    exit()
l = r = 2
for i in range(k-1,-1,-1):
    mn = ((l+a[i]-1)//a[i])*a[i]
    mx = (r//a[i])*a[i]+a[i]-1
    if mn>mx:
        print(-1)
        exit()
    l = mn
    r = mx
print("{} {}".format(l,r))

Solution (Python):
k = int(input())
a = list(map(int,input().split()))
a = a[::-1]
ansmin = 2
ansmax = 2
for x in a:
  ansmin = x*((ansmin+x-1)//x)
  ansmax = x*(ansmax//x)+x-1
  if ansmin>ansmax:
    print(-1)
    exit()
print(ansmin,ansmax)

Solution (Python):
k = int(input())
a = list(map(int,input().split()))
a = a[::-1]
ansmin = 2
ansmax = 2
for i in range(k):
  x = a[i]
  ansmin = x*((ansmin+x-1)//x)
  ansmax = x*(ansmax//x)+x-1
  if ansmin>ansmax:
    print(-1)
    exit()
print(ansmin,ansmax)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            
            ok = mid
        else:
            
            ng = mid
    return ok

N = INT()
A = LIST()

def check1(m):
    sm = m
    for a in A:
        sm = (sm // a) * a
    return sm >= 2

def check2(m):
    sm = m
    for a in A:
        sm = (sm // a) * a
    return sm > 2

l = bisearch_min(0, 10**18, check1)
r = bisearch_min(0, 10**18, check2) - 1


if l > r:
    print(-1)
else:
    print(l, r)

Solution (Python):


import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
    """ 条件を満たす最小値を見つける二分探索 """

    ok = mx
    ng = mn
    while ng+1 < ok:
        mid = (ok+ng) // 2
        if func(mid):
            
            ok = mid
        else:
            
            ng = mid
    return ok

N = INT()
A = LIST()

def check1(m):
    sm = m
    for a in A:
        sm = (sm // a) * a
    return sm >= 2

def check2(m):
    sm = m
    for a in A:
        sm = (sm // a) * a
    return sm > 2

l = bisearch_min(0, 10**18, check1)
r = bisearch_min(0, 10**18, check2) - 1

if l > r:
    print(-1)
else:
    print(l, r)

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

B = [(0, 0)] * (N + 1)
B[N] = (2, 2)

for i in range(N - 1, -1, -1):
  min_next, max_next = B[i + 1]
  
  min_left = -1
  min_right = 10 ** 15
  
  while min_left + 1 < min_right:
    min_mid = (min_left + min_right) // 2
    mid_next = min_mid // A[i] * A[i]
    if mid_next >= min_next:
      min_right = min_mid
    else:
      min_left = min_mid
  
  max_left = 0
  max_right = 10 ** 15
  
  while max_left + 1 < max_right:
    max_mid = (max_left + max_right) // 2
    mid_next = max_mid // A[i] * A[i]
    if mid_next >= max_next + 1:
      max_right = max_mid
    else:
      max_left = max_mid
  
  if  min_right == 0 or max_left == 0 or max_left < min_right:
    print(-1)
    exit()
  else:
    B[i] = (min_right, max_left)

print(*B[0])

Solution (Python):
K = int(input())
A = [int(a) for a in input().split()]
ma = mi = 2
while A:
    a = A.pop()
    mi = (mi+a-1) // a * a
    ma = (ma) // a * a + (a-1)
    if mi > ma:
        print(-1)
        exit()

print(mi, ma)

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

high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp <= 2:
        low = mid
    else:
        high = mid
    L = low
    
high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp >= 2:
        high = mid
    else:
        low = mid
    S = high

if S <= L:
    print(S,L)
else:
    print(-1)

Solution (Python):
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline

def main():
    K = int(input())
    A = list(map(int,input().split()))
    
    L = [1]
    for i in range(K):
        if L[-1] != A[-i-1]:
            L.append(A[-i-1])
    
    L.pop(0)
    L_long = len(L)
    ans = [2,2]
    for i in range(L_long):
        s,t = ans[0],ans[1]
        ans[0] = -(-s//L[i])*L[i]
        ans[1] = (t//L[i] + 1)*L[i] - 1
        if ans[1] < ans[0]:
            print(-1)
            exit()
    
    print(ans[0],ans[1])
    
if __name__ == "__main__":
    main()

Solution (Python):
K = int(input())
A = list(map(int,input().split()))
B = [2,2]
for i in range(K-1,-1,-1):
    a = A[i]
    bmin = B[0]
    bmax = B[1]
    if bmin%a==0:
        bmin = bmin
    else:
        bmin = (bmin//a+1)*a
    if bmin>bmax:
        B = []
        break
    else:
        if bmax%a==0:
            bmax = bmax+a-1
        else:
            bmax = (bmax//a)*a+a-1
        B = [bmin,bmax]
if len(B)==0:
    print(-1)
else:
    print(B[0],B[1])

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

def g(n):
    for a in A:
        n=n-n%a
    return n

a_max=max(A)
l=1
r=2+K*a_max
while r-l>1:
    m=(l+r)//2
    if g(m)>=2:
        r=m
    else:
        l=m
l0=r

l=1
r=2+K*a_max
while r-l>1:
    m=(l+r)//2
    if g(m)<=2:
        l=m
    else:
        r=m
r0=l

if l0>r0:
    print(-1)
else:
    print(l0,r0)

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

n_min=2
n_max=2
for i in range(K-1,-1,-1):
    if (n_max//A[i])*A[i] < n_min or (n_min//A[i]+(1 if n_min%A[i]!=0 else 0))*A[i] > n_max:
        print(-1)
        exit()
    n_min=(n_min//A[i]+(1 if n_min%A[i]!=0 else 0))*A[i]
    n_max=(n_max//A[i])*A[i]+A[i]-1

print(n_min,n_max)

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    k=int(input())
    A=list(map(int,input().split()))

    l=r=2
    for a in A[::-1]:
        l=a*((l-1)//a+1)
        r=a*(r//a)+(a-1)
        if(l>r):
            print(-1)
            return

    print(l,r)
resolve()

Solution (Python):
def examA():
    N, A, B = LI()
    if (A-B)%2==0:
        ans = "Alice"
    else:
        ans = "Borys"
    print(ans)
    return

def examB():
    K = I()
    A = LI()
    cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if A[i]>cur:
            print(-1)
            exit()
        cur = (cur//a+1)*a-1

    maxA = cur; cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if cur<=a:
            cur = a
        else:
            cur = a*((cur-1)//a+1)
    minA = cur
    if minA>maxA:
        print(-1)
        exit()
    print(minA,maxA)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    k=int(input())
    A=list(map(int,input().split()))
    l=2; r=2
    for a in A[::-1]:
        
        l=((l-1)//a+1)*a
        
        r=(r//a)*a+(a-1)
        if(l>r or r<2):
            print(-1)
            return
    print(l,r)
resolve()

Solution (Python):
K = int(input())
A = [int(i) for i in input().split()]

def solve() :            
    m, M = 2, 2
    for a in A[::-1] :
        if (m - 1) // a == M // a :
            return [-1]
            
        M = M // a * a + a - 1
        x = (m + a - 1) // a
        m = a * x
        
    return [m, M]
    
print(*solve())

Solution (Python):
k=int(input())
a=list(map(int,input().split()))
m=2
M=2
for i in range(k-1,-1,-1):
    x=a[i]
    r=M//x
    l=(m-1)//x
    if r-l<1:
        print(-1)
        exit()
    m=(m+x-1)//x*x
    M=M//x*x+x-1
print(m,M)

Solution (Python):
k=int(input())
l=list(map(int,input().split()))
nowmax=2
nowmin=2
for i in range(k):
  num=l[-1-i]
  if nowmax-nowmin<num and nowmax%num>=nowmin%num and not(nowmax%num==0 or nowmin%num==0):
    print(-1)
    exit()
  else:
    nowmax,nowmin=(nowmax//num)*num+num-1,(((nowmin-1)//num)+1)*num
print(nowmin,nowmax)

Solution (Python):
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
x = a[-1]
y = 4
if x != 2:
  print(-1)
  exit(0)
for i in range(N - 2, -1, -1):
  p = a[i]
  t = -(-x // p)
  x = t * p
  u = -(-y // p)
  y = u * p
t = x + 0
for i in range(N):
  t -= t % a[i]
if t == 2:
  print(x, y - 1)
else: print(-1)

Solution (Python):
K = int(input())
A = [int(i) for i in input().split()]

A.reverse()

mi, ma = 2, 2

for a in A:
    if ma < ((mi + a - 1) // a) * a:
        print(-1)
        exit()
    mi = (mi + a - 1) // a * a
    ma = (ma // a + 1) * a - 1

print(mi, ma)

Solution (Python):
import math
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


K = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))


def solve():
    if A[-1] == 1:
        lo = 2
        hi = 2
    elif A[-1] == 2:
        lo = 2
        hi = 3
    else:
        return None

    for a in reversed(A[:-1]):
        l = math.ceil(lo / a) * a
        h = math.floor(hi / a) * a
        if not lo <= l <= hi or not lo <= h <= hi:
            return None
        lo = l
        hi = h + a - 1
    return lo, hi


ans = solve()
if ans:
    print(*ans)
else:
    print(-1)

Solution (Python):
import math
k = int(input())
a = list(map(int, input().split()))
MAX = 2
MIN = 2
for i in a[::-1]:
    if MAX >= i:
        MAX = i * (MAX // i) + (i-1)
        MIN = i * (math.ceil(MIN / i)) 
        if MIN > MAX:
          print(-1)
          exit()
    else:
        print(-1)
        exit()
print(MIN,MAX)

Solution (Python):
k = int(input())
a = list(map(int, input().split()))
l, r = 0, 10 ** 15
while r - l > 1:
    m = (l + r) // 2
    t = m
    for x in a:
        m = m // x * x
    if m <= 2:
        l = t
    else:
        r = t
l2, r2 = 0, 10 ** 15
while r2 - l2 > 1:
    m = (l2 + r2) // 2
    t = m
    for x in a:
        m = m // x * x
    if m < 2:
        l2 = t
    else:
        r2 = t
if l < r2:
    print(-1)
else:
    print(r2, l)

Solution (Python):
def main():
	k, *a = map(int, open(0).read().split())
	m = M = 2
	for x in a[::-1]:
		M -= M % x
		if m > M:
			print(-1)
			exit()
		m += -m % x
		M += x - 1
	print(m, M)

if __name__=="__main__":
	main()

Solution (Python):
import math
K = int(input())
A = list(map(int, input().split()))
N, n = 2, 2
k = [0, 0]
for i in reversed(range(K)):
    k[0] = (N // A[i])*A[i]
    k[1] = math.ceil(n / A[i]) * A[i]
    if k[0]*A[i] >= n and k[1] <= N:
        N = k[0]+A[i] - 1
        n = k[1]
    else:
        print(-1)
        exit(0)
print(n, N)

Solution (Python):
K = int(input())
A = [int(_) for _ in input().split()]

A.reverse()
maximum = 2
minimum = 2
able = True

for i in range(K):
  maximum = (maximum // A[i]) * A[i] + A[i] - 1
  minimum = ((minimum - 1) // A[i] + 1) * A[i]
  if minimum > maximum:
    able = False
    break

if able:
  print(str(minimum) + ' ' + str(maximum))
else:
  print(-1)

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

ans1 = 2
ans2 = 2
for i in range(K - 1, 0, -1):
    if ans1 % A[i] != 0 or ans2 % A[i] != 0 or ans1 < 2 or ans2 < 2:
        print (-1)
        exit()
    ans1 = (ans1 + A[i] - 1) // A[i - 1] * A[i - 1] 
    ans2 = (ans2 + A[i - 1] - 1) // A[i - 1] * A[i - 1] 
    if ans2 > ans1: 
        print (-1)
        exit()

    

if ans1 % A[0] != 0 or ans2 % A[0] != 0 or ans1 < 2 or ans2 < 2:
    print (-1)
    exit()

print (ans2, ans1 + A[0] - 1)

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

ans1 = 2
ans2 = 2
for i in range(K - 1, 0, -1):
    if ans1 % A[i] != 0 or ans2 % A[i] != 0 or ans1 < 2 or ans2 < 2:
        print (-1)
        exit()
    ans1 = (ans1 + A[i] - 1) // A[i - 1] * A[i - 1] 
    ans2 = (ans2 + A[i - 1] - 1) // A[i - 1] * A[i - 1] 
    if ans2 > ans1:
        print (-1)
        exit()
    if ans2 == 0:
        ans2 = ans1

    

if ans1 % A[0] != 0 or ans2 % A[0] != 0 or ans1 < 2 or ans2 < 2:
    print (-1)
    exit()

print (ans2, ans1 + A[0] - 1)

Solution (Python):
K = int(input())
A = list(map(int, input().split()))
min = 2
max = 2
for i in range(K-1, -1, -1):
    min += (-min) % A[i]
    max -= max % A[i]
    max += A[i] - 1
if max < min:
  print(-1)
  exit()
print(min, max)

Solution (Python):
K = int(input())
A = list(map(int, input().split()))
min = 2
max = 2
for i in range(K-1, -1, -1):
    if max < A[i]:
        print(-1)
        exit()
    min += (-min) % A[i]
    max -= max % A[i]
    max += A[i] - 1
    if max < min:
        print(-1)
        exit()
print(min, max)

Solution (Python):
K = int(input())
A = list(map(int, input().split()))
min = 2
max = 2
for i in range(K-1, -1, -1):
    if max < A[i]:
        print(-1)
        exit()
    min = (min + A[i] - 1) // A[i] * A[i]
    max = (max // A[i] + 1) * A[i] - 1
    if max < min:
        print(-1)
        exit()
print(min, max)

Solution (Python):
n=int(input())
a=list(reversed(list(map(int,input().split()))))
p,q=2,2
for i in range(n):
	q2=((q-1)//a[i]+1)*a[i]
	p2=(p//a[i]+1)*a[i]-1
	p=p2
	q=q2
	if p<q:
		print(-1)
		break
else:
	print(q,p)

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

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


def b():
    if A[0] != 2:
        return -1
    else:
        ans = [2, 3]
        for i in range(1, n):
            r = ans[1] // A[i] * A[i]
            l = -((-ans[0] // A[i]) * A[i])
            
            
            if r < l:
                return -1
            ans = [l, r+A[i]-1]
            
    return ans

ans = b()
if ans == -1:
    print(ans)
else:
    print(ans[0], ans[1])

Solution (Python):
import sys

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


MIN=2
MAX=2

for a in A[::-1]:
    M1=math.ceil(MIN/a)*a
    M2=MAX//a*a

    if M1>MAX:
        print(-1)
        sys.exit()

    else:
        MIN=M1
        MAX=M2+a-1

print(MIN,MAX)

Solution (Python):


def is_ok(x, f):
    for d in a:
        x = x - x % d
    return f(x)


def binary_search(f, ok, ng):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid, f):
            ok = mid
        else:
            ng = mid
    return ok


k = int(input())
a = tuple(map(int, input().split()))

max_ = binary_search(lambda x: x <= 2, ok=0, ng=10 ** 14 + 10)
min_ = binary_search(lambda x: x >= 2, ok=10 ** 14 + 10, ng=0)

if min_ > max_:
    print(-1)
else:
    print(min_, max_)

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

l, r = 2, 2
ans = (-1,)
for x in reversed(a):
    l = ((l + x - 1) // x) * x
    
    if r < l:
        break
    r = ((r // x) * x) + (x - 1)
else:
    ans = (l, r)
print(*ans)

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

min_ans = 2
max_ans = 2

for i in range(n):
    min_ans = -((-min_ans) // a[i]) * a[i]
    
for i in range(n):
    max_ans = (max_ans// a[i]) * a[i] +a[i] - 1

a = a[::-1]
tmp_ans = min_ans
tmp_ans2 = max_ans
for i in range(n):
    tmp_ans = (tmp_ans // a[i]) * a[i]
    tmp_ans2 = (tmp_ans // a[i]) * a[i]
    
if tmp_ans == 2 and tmp_ans2 == 2:
    print(min_ans, max_ans)
else:
    print(-1)

Solution (Python):
import sys
sys.setrecursionlimit(10**6)

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

def ceil(a, b):
    return -(-a // b)

def floor(a, b):
    return a // b

def L(i):
    if i == K:
        return 2
    return ceil(L(i+1), A[i]) * A[i]

def R(i):
    if i == K:
        return 2
    return floor(R(i+1), A[i]) * A[i] + A[i] - 1

L0 = L(0); R0 = R(0)
if L0 <= R0:
    print(L0, R0)
else:
    print(-1)

Solution (Python):
import sys

def updiv(a,b):

    if a % b == 0:
        return a // b
    else:
        return a // b + 1

K = int(input())

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

mini = 2
maxi = 2

for i in range(K):

    mini = updiv(mini, A[i]) * A[i]
    maxi = maxi // A[i] * A[i]

    if mini > maxi:
        print (-1)
        sys.exit()

    maxi += A[i]-1

print (mini,maxi)

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

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

M=3
m=2
import math
for i in range(1,K):
    if m%A[i]==0:
        Lm=m
    else:
        Lm=(m//A[i]+1)*A[i]
    
    if Lm<m or M<Lm:
        print(-1)
        exit()
    LM=(M//A[i])*A[i]+A[i]-1
    if LM<Lm:
        print(-1)
        exit()
    M=LM
    m=Lm
print(m,M)

Solution (Python):
import math
K = int(input())
A = [int(i) for i in input().split()][::-1]

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

ans_low = 2
ans_high = 3

for i in range(1, K):
    next_ans_high = ((ans_high//A[i])+1)*A[i]-1
    next_ans_low = math.ceil(ans_low/A[i])*A[i]

    if (next_ans_high // A[i])*A[i] > ans_high or next_ans_low > next_ans_high:
        print(-1)
        exit()

    ans_high = next_ans_high
    ans_low = next_ans_low

    

print(ans_low, ans_high)

Solution (Python):
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))



K = I()
A = III()

for i in range(K)[::-1]:
    if i==K-1:
        if A[i]==2:
            l = 2
            r = 3
        else:
            print(-1)
            exit()
    else:
        x = math.ceil(l/A[i])*A[i]
        y = math.floor(r/A[i])*A[i]
        if x<=r and y>=l:
            l = x
            r = y+A[i]-1
        else:
            print(-1)
            exit()

print(l,r)

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
k=int(input())
a=list(map(int,input().split()))
min_num=2
max_num=3
for i in range(1,k):
    min_num=((min_num-1)//a[-i-1]+1)*a[-i-1]
    max_num=(max_num//a[-i-1]+1)*a[-i-1]-1

tmp=min_num
for i in range(k):
    tmp-=tmp%a[i]
if tmp!=2:
    print(-1)
    quit()

print(min_num)
print(max_num)

Solution (Python):
import math
K = int(input())
A = [int(_) for _ in input().split()]
l = r = 2
'''
if x children form groups consisting of y children each
 then z children are left
=> z=y*(x//y)
=> y*(math.ceil(z/y))<=x<y*(math.floor(z/y)+1)
'''

for a in A[::-1]:
    l = a * math.ceil(l / a)
    r = a * (math.floor(r / a) + 1) - 1

for x in [l, r]:
    for a in A:
        x = a * (x // a)
    if x != 2:
        print(-1)
        exit()
print(l, r)

Solution (Python):
K = int(input())
A = [int(_) for _ in input().split()]
l = r = 2
for a in A[::-1]:
    l = a * ((l - 1) // a) + a
    r = a * (r // a + 1) - 1
for x in [l, r]:
    for a in A:
        x = a * (x // a)
    if x != 2:
        print(-1)
        exit()
print(l, r)

Solution (Python):
import math
K = int(input())
A = list(map(int,input().split()))
M,m = 2,2
A = reversed(A)
for i in A:
    M = (M//i)*i+(i-1)
    m = math.ceil(m/i)*i
    if m > M:
        print(-1)
        exit()
print(m,M)

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

if A[-1] != 2:
    print(-1)
    exit()
else:
    m, M = 2, 3
    for i in range(K-2, -1, -1):
        if A[i] > M:
            print(-1)
            exit()
        else:
            if m % A[i] != 0:
                m = (m // A[i] + 1) * A[i]
            M = (M // A[i] + 1) * A[i] - 1
if m > M:
    print(-1)
    exit()
else:
    print(m, M)

Solution (Python):
def getlist():
	return list(map(int, input().split()))


K = int(input())
A = getlist()
A = A[::-1]


ans = 0
dpM = [0] * (K)
dpm = [0] * (K)
dpM[0] = A[0] * 2 - 1
dpm[0] = A[0]
for i in range(1, K):
	if A[i] > dpM[i - 1]:
		ans = -1
		break
	elif A[i] >= dpm[i - 1]:
		dpM[i] = A[i] * 2 - 1
		dpm[i] = A[i]

	else:
		dpM[i] = A[i] * (dpM[i - 1] // A[i] + 1) - 1

		if dpm[i - 1] % A[i] == 0:
			dpm[i] = dpm[i - 1]
		else:
			dpm[i] = A[i] * (dpm[i - 1] // A[i] + 1)
	if dpm[i] > dpM[i]:
		ans = -1
		break


if ans == -1 or A[0] != 2:
	print(-1)
else:
	print(dpm[-1], dpM[-1])

Solution (Python):

def main():
    K, *A = map(int, open(0).read().split())
    l, h = 2, 2  
    for i in A[::-1]:
        l += -l % i
        h += i - 1 - h % i
    if l > h:
        print(-1)
    else:
        print(l, h)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    K, *A = map(int, open(0).read().split())
    if A.pop() != 2:
        print(-1)
        return
    mn, mx = 2, 3
    for i in A[::-1]:
        if i > mx:
            print(-1)
            return
        mx = mx // i * i + i - 1
        mn = ((mn + i - 1) // i) * i
    if mn > mx:
        print(-1)
    else:
        print(mn, mx)


if __name__ == "__main__":
    main()

Solution (Python):

def main():
    K, *A = map(int, open(0).read().split())
    if A.pop() != 2:
        print(-1)
        return
    mn, mx = 2, 3
    for i in A[::-1]:
        if i > mx:
            print(-1)
            return
        mx = mx // i * i + i - 1
        mn = ((mn + i - 1) // i) * i
    if mn > mx:
        print(-1)
    else:
        print(mn, mx)


if __name__ == "__main__":
    main()

Solution (Python):
K, *A = map(int, open(0).read().split())

mi = ma = 2
for a in reversed(A):
    mi = -(-mi // a) * a
    ma = (ma // a) * a + a - 1

if ma < mi:
    print(-1)
else:
    print(mi, ma)

Solution (Python):
_,a=open(0)
l,r=-2,-3
for a in map(int,a.split()[::-1]):l,r=l//a*a,r//a*a
print(-(l==r)or'%d %d'%(-l,~r))

Solution (Python):
_,a=open(0)
l,r=-2,-3
for a in map(int,a.split()[::-1]):
  l,r=l//a*a,r//a*a
print(-(l==r)or'%d %d'%(-l,~r))

Solution (Python):
_,a=open(0)
l,r=-2,-3
for a in map(int,a.split()[::-1]):
  l,r=l//a*a,r//a*a
print(-(l==r)or'%d %d'%(-l,~r))

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

def ceil(a, b):
    if a%b == 0:
        return a//b
    else:
        return a//b + 1

def f(l, r, a):
    
    min_ = ceil(l, a) * a
    max_ = (r // a) * a
    if min_ > max_:
        return False, min_, max_
    else:
        return True, min_, max_

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

    min_ = 2
    max_ = 2
    for i in range(K):
        jud, x, y = f(min_, max_, A[i])
        if not jud:
            print(-1)
            return
        min_ = x
        max_ = y + A[i] - 1
        
    
    print(min_, max_)

if __name__ == "__main__":
    main()

Solution (Python):
k=int(input())
a=list(map(int,input().split()))
s=2+k*max(a)
l,r=s+1,0
while l-r>1:
    t=(l+r)//2
    p=t
    for i in a:
        t-=t%i
    if t>=2:
        l=p
    else:
        r=p
e=l
l,r=s+1,0
while l-r>1:
    t=(l+r)//2
    p=t
    for i in a:
        t-=t%i
    if t>2:
        l=p
    else:
        r=p
print(str(max(e,2))+" "+str(r)if r>e or r<2 else -1)

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

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


if K == 1:
    if A[0] == 2:
        print(2, 3)
    else:
        print(-1)
else:
    M = 2
    L = 2
    ok = True
    for i in range(K-1, -1, -1):
        a = A[i]
        nM = (M//a)*a
        if M%a != 0:
            nM += a
        nL = (L//a)*a + a - 1
        if nM >= M + a or nM > nL:
            ok = False
            break
        
        L, M = nL, nM
        

    if not ok:
        print(-1)
    else:
        print(M, L)

Solution (Python):



import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    for i in a:
        if x < i:
            x = 0
            break
        x = x - (x % i)
    return x
k = I()
a = LI()
high,low = 10**20,0
while (high - low) > 1:
    mid = (high + low) // 2 
    if f(mid) >= 2:
        high = mid
    else:
        low = mid
ans1 = high
high,low = 10**20,0
while (high - low) > 1:
    mid = (high + low) // 2
    if f(mid) > 2:
        high = mid
    else:
        low = mid
ans2 = low
if ans1 > ans2:
    print(-1)
else:
    if f(ans1) != 2 or f(ans2) != 2:
        print(-1)
    else:
        print(ans1,ans2)

Solution (Python):
K = int(input())
A = [int(x) for x in input().split()]
C = [[0, 0] for _ in range(K + 1)]
C[K] = [2, 2]
for i in range(K - 1, -1, -1):
  C[i][0] = A[i] * -(-C[i + 1][0] // A[i])
  C[i][1] = A[i] * (C[i + 1][1] // A[i]) + (A[i] - 1)
  if C[i][0] > C[i + 1][1]:
    print(-1)
    break
else:
  print(C[0][0], C[0][1])

Solution (Python):
K = int(input())
A = [int(x) for x in input().split()]
nmin = 2
nmax = 2
last = 1
for a in A[::-1]:
    nmin = ((nmin-1)//a+1)*a
    if(nmin>nmax):
        print(-1)
        break
    nmax = (nmax//a)*a+a-1
    last = a


else:
    print(nmin,nmax)