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, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

k = INT()
a = LIST()
mn = 2
mx = 2
for i in reversed(range(k)):
    mn = (mn + a[i] - 1) // a[i] * a[i]
    mx = mx // a[i] * a[i] + a[i] - 1
    if mn > mx:
        print(-1)
        exit()
print(mn, mx)

Solution (Python):
k=int(input())
a=list(map(int,input().split()))
a.reverse()
ans1=2
ans2=2
for i in range(k):
	m,M=ans1,ans2
	ans1=((m-1)//a[i]+1)*a[i]
	ans2=M//a[i]*a[i]

	if ans1>ans2:
		print(-1)
		exit()

	ans1=ans1//a[i]*a[i]
	ans2=ans2//a[i]*a[i]+(a[i]-1)

if ans1>ans2:
	print(-1)
	exit()
else:
	print(ans1,ans2)

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






if a[-1] > 2:
    print(-1)
    exit()
ans_min = 2
ans_max = 2
a.reverse()
for i in range(k):
    if ans_max % a[i] != a[i] - 1:
        ans_max += (a[i] - 1) - (ans_max % a[i])
    if ans_min % a[i] != 0:
        ans_min += a[i] - ans_min % a[i]
a.reverse()
sim_max = ans_max
sim_min = ans_min
for i in range(k):
    sim_max = sim_max - sim_max % a[i]
    sim_min = sim_min - sim_min % a[i]
if sim_max == sim_min == 2:
    print("{} {}".format(ans_min, ans_max))
else:
    print(-1)

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

L = [-1]*(k+1)
R = [-1]*(k+1)

L[0] = 2
R[0] = 2
for i in range(1, k+1):
    if L[i-1]%A[i-1] == 0 or R[i-1]%A[i-1] == 0:
        pass
    else:
        if R[i-1] - L[i-1] >= A[i-1] or L[i-1]%A[i-1]>R[i-1]%A[i-1]:
            pass
        else:
            
            print(-1)
            exit()
    if L[i-1]%A[i-1] == 0:
        L[i] = (L[i-1]//A[i-1])*A[i-1]
    else:
        L[i] = (L[i-1]//A[i-1]+1)*A[i-1]
    R[i] = (R[i-1]//A[i-1])*A[i-1]+A[i-1]-1
    



print(L[k], R[k])

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

L = [-1]*(k+1)
R = [-1]*(k+1)

L[0] = 2
R[0] = 2
for i in range(1, k+1):
    if L[i-1]%A[i-1] == 0 or R[i-1]%A[i-1] == 0:
        pass
    else:
        if R[i-1] - L[i-1] >= A[i-1] or L[i-1]%A[i-1]>R[i-1]%A[i-1]:
            pass
        else:
            
            print(-1)
            exit()
    if L[i-1]%A[i-1] == 0:
        L[i] = (L[i-1]//A[i-1])*A[i-1]
    else:
        L[i] = (L[i-1]//A[i-1]+1)*A[i-1]
    R[i] = (R[i-1]//A[i-1])*A[i-1]+A[i-1]-1
    



print(L[k], R[k])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))[::-1]
if a[0]!=2:
    print(-1)
    exit()
import math

maxi=3
mini=2
for i in range(1,n):
    if mini<=a[i]:
        mini=a[i]
    else:
        times=math.ceil(mini/a[i])
        mini=a[i]*times
    if mini>maxi:
        print(-1)
        exit()
    
    if maxi<a[i]:
        print(-1)
        exit()
    else:
        times=int(maxi/a[i])
        maxi=a[i]*(times+1)-1
    
print(mini,maxi)

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

def g(x):
    for a in A:
        x = (x // a) * a
    return x

overEq = 10**18
less = 0
while overEq - less > 1:
    mid = (overEq + less) // 2
    if g(mid) < 2:
        less = mid
    else:
        overEq = mid

over = 10**18
lessEq = 0
while over - lessEq > 1:
    mid = (over + lessEq) // 2
    if g(mid) <= 2:
        lessEq = mid
    else:
        over = mid

if g(overEq) == 2 and g(lessEq) == 2:
    print(overEq, lessEq)
else:
    print(-1)

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

mx=2
mn=2
for i in range(K-1,-1,-1):
    a = A[i]
    a_mn = ((mn+a-1)//a)*a
    a_mx = mx - mx%a
    if a_mn > a_mx:
        print(-1)
        exit()
    mn=a_mn
    mx=a_mx+a-1
print("{} {}".format(mn,mx))

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

mx = 2
mi = 2

for a in A[:: -1]:
    mx = (-(-(mx + 1) // a)) * a - 1
    mi = (-(-mi // a)) * a

def isOk(x):
    for a in A:
        x = (x // a) * a
    return x == 2

if isOk(mi) and isOk(mx):
    print(mi, mx)
else:
    print(-1)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

k = INT()
a = LIST()
l = 2
r = 2
for i in reversed(range(k)):
    l = (l + a[i] - 1) // a[i] * a[i]
    r = r // a[i] * a[i] + a[i] - 1
    if l > r:
        print(-1)
        exit()
print(l, r)

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


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N = (N//a)*a

    if N > 2:
        r = m
    else:
        l = m
upper = l


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N = (N//a)*a

    if N < 2:
        l = m
    else:
        r = m
lower = r

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A.append(2)
mi = 2
mx = 2
for i in range(N-1,-1,-1):
    
    mi = (mi + A[i] - 1) // A[i] * A[i]
    mx = mx // A[i] * A[i]
    if mi > mx:
        print(-1)
        exit(0)
    mx += A[i] - 1
print(mi,mx)

Solution (Python):
k = int(input())
a = list(map(int,input().split()))
def cal(x):
    for i in range(k):
        x -= (x%a[i])
    return x
top = 3+ k*max(a)
bot = 0
while top - bot > 1:
    mid = (top+bot)//2
    if cal(mid) >= 2:top = mid
    else:bot = mid
mini = top
top = 3+ k*max(a)
bot = 0
while top - bot > 1:
    mid = (top+bot)//2
    if cal(mid) > 2:top = mid
    else:bot = mid
maxi = bot
if mini > maxi:print(-1)
    
else:print(mini,maxi)

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    K = int(input())
    A = [int(a) for a in input().split()]
    if A[K-1] != 2: print(-1)
    else:
        minK, maxK = 2, 3
        for i in reversed(range(K - 1)):
            mod = A[i]
            lb, hb = (minK - 1) // mod, maxK // mod
            if lb >= hb: 
                print(-1)
                break
            else:
                minK = mod * (lb + 1)
                maxK = mod * (hb + 1) - 1
        else: print(minK, maxK)

    return 0

if __name__ == "__main__":
    solve()

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

mx = 3
mn = 2
for i in range(k)[::-1]:
    mn = (mn + a[i] - 1) // a[i] * a[i]
    
    mx = (mx + a[i] - 1) // a[i] * a[i]
    
    
mx -= 1


ans = (mn,mx)
for i in range(k):
    mx = (mx // a[i]) * a[i]
    mn = (mn // a[i]) * a[i]


if mn == 2 and mx == 2:
    print(*ans)
else:
    print(-1)

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

ans = [2,2]
for a in A[::-1]:

  if a > ans[1]:
    print(-1)
    exit()
  ans[1] = (ans[1]//a) *a+ (a-1)
  if ans[0] <= a:
    ans[0] = a
  else:
    if ans[0]%a != 0:
      ans[0] = (ans[0]//a+1)*a
  if ans[0] >ans[1]:
    print(-1)
    exit()
print(*ans)

Solution (Python):
import math
K = int(input())
A = list(map(int,input().split()))
lo = 2
hi = 2
for e in A[::-1]:
    if hi//e == lo//e and (hi%e)*(lo%e) != 0:
        print(-1)
        exit(0)
    else:
        lo = e*math.ceil(lo/e)
        hi = e*((hi//e)+1)-1
print(lo,hi)

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

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    K = int(input())
    A = [int(a) for a in input().split()]
    if A[K-1] != 2: print(-1)
    else:
        minN, maxN = 2, 3
        for i in reversed(range(K - 1)):
            lb = (minN - 1) // A[i]
            hb = maxN // A[i]
            if lb == hb: 
                print(-1)
                break
            else:
                minN = A[i] * (lb + 1)
                maxN = A[i] * hb + A[i] - 1
        else: print(minN, maxN)
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    K = int(input())
    A = [int(a) for a in input().split()]
    if A[K-1] != 2: print(-1)
    else:
        minN, maxN = 2, 3
        for i in reversed(range(K - 1)):
            if maxN < A[i]: 
                print(-1)
                break
            else:
                lb = (minN - 1) // A[i]
                hb = maxN // A[i]
                if lb == hb: 
                    print(-1)
                    break
                else:
                    minN = A[i] * (lb + 1)
                    maxN = A[i] * hb + A[i] - 1
        else: print(minN, maxN)
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
def examA():
    N = I()
    A = LI()
    if A[-1]!=2:
        print(-1)
        return
    l = 2; r = 2
    for a in A[::-1]:
        ner = (r//a+1)*a-1
        nel = ((l-1)//a+1)*a
        r = ner; l = nel
        if r<l:
            print(-1)
            return
    print(l,r)
    return

def examB():
    N, M = LI()

    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
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()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

Solution (Python):
K = int(input())
A = list(map(int, input().split()))
def ceiling(x, mod):
  if x % mod == 0:
    return x // mod
  else:
    return x // mod + 1

m, M = 2, 2
p = 0
for i in range(K-1, -1, -1):
  m, M = A[i] * ceiling(m, A[i]), A[i] * (M // A[i]) + A[i] - 1
chk1, chk2 = m, M
for i in range(K):
  chk1, chk2 = A[i] * (chk1 // A[i]), A[i] * (chk2 // A[i])
if chk1 == 2 and chk2 == 2:
  print(m, M)
else:
  print(-1)

Solution (Python):
def calc_n_range(a):
    min_n = max_n = 2

    for curr_a in reversed(a):
        min_n = ((min_n + curr_a - 1) // curr_a) * curr_a
        if min_n > max_n:
            return None
        max_n = max_n - max_n % curr_a + curr_a - 1

    return min_n, max_n


def main():
    input()
    a = list(map(int, input().split()))

    n_range = calc_n_range(a)
    if n_range:
        print(*n_range)
    else:
        print(-1)


if __name__ == '__main__':
    main()

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



L, H = 2, 2
for i in range(K):
    
    MIN = (L + A[i] - 1) // A[i] * A[i]
    
    MAX = H // A[i] * A[i]

    if L <= MIN <= H:
        L = MIN
        H = MAX + A[i] - 1
    else:
        print(-1)
        exit()

print(L,H)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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

M = m = 2
for i,ai in enumerate(A):
  
  if not (m <= (m-1+ai)//ai*ai<= M):
    print(-1);exit()
  M = M//ai*ai + ai-1
  m = (m-1+ai)//ai*ai
  
print(m,M)

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

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

A.reverse()
mn = mx = 2
for a,b in zip(A,A[1:]):
    mn += (b - mn%b)%b
    mx += a-1
    mx -= mx%b
    if mn > mx:
        print(-1)
        exit()

mx += A[-1]-1
print(mn,mx)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

k = INT()
a = LIST()
l = 2
r = 2
for i in reversed(range(k)):
    l = (l + a[i] - 1) // a[i] * a[i]
    r = r // a[i] * a[i] + a[i] - 1
    if l > r:
        print(-1)
        exit()
print(l, r)

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

def func(num):
    for item in A:
        num=num//item*item
    return num

ok=10**20
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    if func(mid)>=2:
        ok=mid
    else:
        ng=mid

low=ok

ok=10**20
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    if func(mid)>=4:
        ok=mid
    else:
        ng=mid

high=ng

if func(low)==2 and func(high)==2:
    print(low,high)
else:
    print(-1)

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

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

tmp = max_ans
for i in range(k):
    tmp = (tmp // a[i]) * a[i]
if tmp != 2:
    print(-1)
    exit()
    
tmp = min_ans
for i in range(k):
    tmp = (tmp // a[i]) * a[i]
if tmp != 2:
    print(-1)
    exit()

print(min_ans, max_ans)

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

def func(num):
    for item in A:
        num=num//item*item
    return num

ans=[]
ok=10**20
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    if func(mid)>=2:
        ok=mid
    else:
        ng=mid

ans=ok

ok=10**20
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    if func(mid)>=4:
        ok=mid
    else:
        ng=mid

if func(ans)==2 and func(ng)==2:
    print(ans,ng)
else:
    print(-1)

Solution (Python):


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

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

low=2
high=3
for item in A[::-1]:
    
    if high<item:
        print(-1)
        exit()
    elif item<low:
        low=(-((-low)//item))*item
        if low>high:
            print(-1)
            exit()
        high=max(low+item-1,high+item-1-high%item)
    else:
        low=item
        if low>high:
            print(-1)
            exit()
        high=low+item-1
print(low,high)

Solution (Python):
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    K = int(input())
    A = read_list()[::-1]
    if A[0] != 2:
        print(-1)
        return

    minN = 2
    maxN = 2
    for a in A:
        minN = ((minN - 1) // a + 1) * a
        maxN = (maxN // a + 1) * a - 1
    if minN > maxN:
        print(-1)
    else:
        print(minN, maxN)


if __name__ == "__main__":
    main()

Solution (Python):
k = int(input())
l = list(map(int,input().split()))
for i in range(k-1,-1,-1):
    if i == k-1:
        if l[i] == 2:
            ans = [2,3]
        else:
            ans = [-1]
            break
    else:
        if l[i] > ans[1]:
            ans = [-1]
            break
        else:
            if l[i] >= ans[0]:
                ans[0] = l[i]
            else:
                b0 = ans[0]
                c = l[i]
                if b0%c == 0:
                    ans[0] = b0
                else:
                    if (b0//c+1)*c > ans[1]:
                        ans = [-1]
                        break
                    else:
                        ans[0] = (b0//c+1)*c
            b1 = ans[1]
            c = l[i]
            if b1%l[i] == 0:
                ans[1] = b1+l[i]-1
            else:
                ans[1] = (b1//c)*c+c-1
    
    
for i in ans:
    print(i,end=" ")

Solution (Python):

import sys
input = sys.stdin.readline

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

lb, ub = 1, 10**18
while ub - lb > 1:
    m = (lb + ub) // 2
    rem = m
    for a in A:
        rem = rem // a * a
    if rem < 2:
        lb = m
    else:
        ub = m

lb2, ub2 = 1, 10**18
while ub2 - lb2 > 1:
    m = (lb2 + ub2) // 2
    rem = m
    for a in A:
        rem = rem // a * a
    if rem <= 2:
        lb2 = m
    else:
        ub2 = m

if ub > lb2:
    print(-1)
else:
    print(ub, lb2)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline

K, *A = map(int, read().split())
maximum = 2
minimum = 2
for i in A[::-1]:
    if maximum // i - (minimum - 1) // i >= 1:
        maximum = maximum // i * i + i - 1
        minimum = (minimum + i - 1) // i * i
    else:
        print(-1)
        exit()

print(minimum, maximum)

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline

K, *A = map(int, read().split())
maximum = 2
minimum = 2
for i in A[::-1]:
    if i > maximum:
        print(-1)
        exit()
    if i >= minimum:
        new_minimum = i
    else:
        new_minimum = (minimum + i - 1) // i * i
    new_maximum = maximum // i * i + i - 1
    if minimum <= new_minimum <= new_maximum and maximum <= new_maximum:
        minimum, maximum = new_minimum, new_maximum
    else:
        print(-1)
        exit()

print(minimum, maximum)

Solution (Python):
def div_ceil(x, y): return (x + y - 1) // y

N = int(input())
*A, = map(int, input().split())
cand_min, cand_max = 2, 2
for a in reversed(A):
    if div_ceil(cand_min, a) * a > cand_max: print(-1); break
    cand_min = div_ceil(cand_min, a) * a
    cand_max = (cand_max // a) * a + a - 1
else:
    print(cand_min, cand_max)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
l.reverse()
m=[2,3]
if l[0]!=2:
    print(-1)
    exit()
for i in range(1,n):
    p=l[i]
    s=-(-m[0]//p)*p
    e=(m[1]//p)*p+p-1
    if not m[0]<=s<=m[1]:
        print(-1)
        exit()
    m=[s,e]
print(*m)

Solution (Python):

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

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

Solution (Python):

import math
k=int(input())
lists=list(map(int,input().split()))
lists=lists[::-1]
maxi=2
mini=2
flag=True
for i in range(k):
    
    a=lists[i]
    upper_bound=math.floor(maxi/a)
    lower_bound=math.ceil(mini/a)
    new_maxi=(upper_bound+1)*a-1
    new_mini=lower_bound*a
    if new_maxi<new_mini:
        flag=False
        break
    else:
        maxi=new_maxi
        mini=new_mini
if flag:
    print(mini,maxi)
else:
    print(-1)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20
MOD = 10**9 + 7


























































    
 
def main():
    k = getList()
    nums = getList()
    mn, mx = 2,2
    for num in nums[::-1]:
        mn = num * math.ceil(mn / num)
        mx = num * (mx// num) + num - 1
        tm = (mx // num) * num
        if tm < mn or tm > mx:
          print(-1)
          return
 
    print(mn, mx)
 
if __name__ == "__main__":
    main()

Solution (Python):
K, *A = map(int, open(0).read().split())
if A[-1]!=2:
  print(-1)
  import sys
  sys.exit()
S = 2
M = 2
for i in range(K-1,0,-1):
  c = A[i]
  p = A[i-1]
  ms = S
  mm = M+c-1
  ns = ms//p+1 if ms%p!=0 else ms//p
  nm = mm//p
  if ns*p>mm or nm*p<ms:
    print(-1)
    break
  M = nm*p
  S = ns*p
else:
  print(S,M+A[0]-1)

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

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

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

k = inn()
a = inl()
l = r = 2
for i in range(k-1,-1,-1):
    nl = ((l+a[i]-1)//a[i])*a[i]
    nr = (r//a[i])*a[i] + a[i]-1
    
    if r<nl or nr<l:
        print(-1)
        exit()
    l = nl
    r = nr
print("{} {}".format(l,r))

Solution (Python):
K = int(input())
A = [int(a) for a in input().split()]
    
if A[K-1] == 2:
    l = 2
    r = 2
    flag = True
    for i in range(K-2, -1, -1):
        r += A[i+1]-1
        if l%A[i] > 0:
            l += A[i]-(l%A[i])
        r -= r%A[i]
        if r < l:
            flag = False
            break
    if flag:
        r += A[0]-1
        ans = str(l) + " " + str(r)
    else:
        ans = -1
else:
    ans = -1

print(ans)

Solution (Python):
def main():
    K=int(input())
    A=list(map(int,input().split()))
    A.reverse()
    minres = 2
    maxres = 2
    for a in A:
        minres = ((minres+a-1)//a)*a
        if minres>maxres:return -1
        maxres = (maxres//a)*a+a-1
    return str(minres)+" "+str(maxres)

print(main())

Solution (Python):




K = int(input())

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


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

big = 2
small = 2
for i in reversed(range(K)):
    """
    smallのときにai人組つくると脱落者なし
    bigのときにai人組作るとai-1人脱落

    """


    
    """
    ・smallはaiで割り切れる（脱落者なし）
    ・元のsmall以上の値
    """

    if small // A[i] > 0 and small % A[i] > 0:
        small = (small // A[i] + 1) * A[i]
    elif small // A[i] > 0 and small % A[i] == 0:
        pass
        
    elif small // A[i] == 0:
        small = A[i] 
        
    
    big = (big // A[i]) * A[i] + A[i] - 1

    if big < small:
        print(-1)
        exit()


print(small, big)

Solution (Python):




K = int(input())

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


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

big = 2
small = 2
for i in reversed(range(K)):
    """
    smallのときにai人組つくると脱落者なし
    bigのときにai人組作るとai-1人脱落

    """


    
    """
    ・smallはaiで割り切れる（脱落者なし）
    ・元のsmall以上の値
    """

    if small // A[i] > 0 and small % A[i] > 0:
        small = (small // A[i] + 1) * A[i]
    elif small // A[i] > 0 and small % A[i] == 0:
        small = small
    elif small // A[i] == 0:
        small = A[i] 
        
    
    big = (big // A[i]) * A[i] + A[i] - 1

    if big < small:
        print(-1)
        exit()


print(small, big)

Solution (Python):




K = int(input())

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


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

big = 2
small = 2
for i in reversed(range(K)):
    """
    smallのときにai人組つくると脱落者なし
    bigのときにai人組作るとai-1人脱落

    """


    
    if small // A[i] > 0 and small % A[i] > 0:
        small = (small // A[i] + 1) * A[i]
    elif small // A[i] > 0 and small % A[i] == 0:
        small = small
    elif small // A[i] == 0:
        small = A[i] 
        
    
    big = (big // A[i]) * A[i] + A[i] - 1

    if big < small:
        print(-1)
        exit()


print(small, big)

Solution (Python):




K = int(input())

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


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

big = 2
small = 2
for i in reversed(range(K)):
    """
    smallのときにai人組つくると脱落者なし
    bigのときにai人組作るとai-1人脱落

    """


    
    small = ((small - 1) // A[i] + 1) * A[i]
        
    
    big = (big // A[i]) * A[i] + A[i] - 1

    if big < small:
        print(-1)
        exit()


print(small, big)

Solution (Python):

import numpy as np
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))



directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    
            

    for d in directions:
        nx = d+x
        
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

def f(x):
    for i in range(K):
        x = x-x % A[i]
    return x

def bisect_search(f,val=0,l=0,r=10**6):

    

    eps=10**(-5)
    while True:

        c=(l+r)//2
        print(l,c,r)
        input()
        if f(c)==val and f(c-1)!=val:
            return c
        
        

        if f(c)>val:
            r=c

        else:
            l=c
        
        if l==r:
            return False

def bisect_search_int(f,val=0,l=0,r=10**6,equal=False):
    
    
    eps=10**(-5)
    if not equal:
        siki = "f(c) > val"
    else:
        siki = "f(c) >= val"

    while r-l>1:

        c=(l+r)//2
        
        if eval(siki,{"c":c,"f":f,"val":val}):
            r=c            
        else:
            l=c
        
        
        
    if f(l)!= f(c) and f(r)!=f(c):
        return False
    return l,r



K=int(input())
A=acinput()

R = 2+K*max(A)


l,r=bisect_search_int(f, 2,0,R,equal=True)
if f(l)==2:
    resL=l
elif f(r)==2:
    resL=r
else:
    resL=-1

l, r = bisect_search_int(f, 2,0,R,equal=False)

if f(l) == 2:
    resR = l
elif f(r) == 2:
    resR = r
else:
    resR = -1

if resL>=0:
    print(resL,resR)
else:
    print(-1)

Solution (Python):

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)

Solution (Python):
import sys, bisect, math, itertools, string, queue, copy


from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) 
def inpm(): return map(int,input().split()) 
def inpl(): return list(map(int, input().split())) 
def inpls(): return list(input().split())  
def inplm(n): return list(int(input()) for _ in range(n)) 
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(n):
    sumation = 0
    while n > 0:
        sumation += n%10
        n //= 10
    return sumation

def main():
    k = inp()
    a = inpl()
    a.reverse()
    x,y = 2,2
    for i in range(k):
        pair = a[i]
        if y < pair:
            print(-1)
            return
        if (y//pair)*pair < x:
            print(-1)
            return
        if pair >= x:
            x = pair
        elif x%pair != 0:
            s = x//pair + 1
            x = s*pair
        y = (y//pair+1) * pair - 1
        if y < x:
            print(-1)
            return
    print(x,y)
    
if __name__ == "__main__":
    main()

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]
left = 2
right = 2
for x in A:
    left += (-left) % x
    right -= right % x
    right += x - 1

if left > right:
    print(-1)
else:
    print(left, right)