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
def main(N, A):
    mx = 2
    mn = 2
    for a in reversed(A):
        mx = (mx // a + 1) * a - 1
        mn = (mn + a - 1) // a * a
        if mn > mx:
            print(-1)
            return
    print(mn, mx)

if __name__ == '__main__':
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    main(N, A)

Solution (Python):
K = int(input())
A = list(map(int,input().split()))
I = [[-1,-1] for _ in range(K+1)]
I[K] = [2,2]
fg = True
for i in range(K-1,-1,-1):
    
    left = A[i]*((I[i+1][0]+A[i]-1)//A[i]) 
    I[i][0] = max(A[i],left)
    I[i][1] = A[i]*(I[i+1][1]//A[i] + 1) -1
    
    if(I[i][0] > I[i][1]):
        fg = False
        break
if(not fg):
    print(-1)
else:
    print(*I[0])

Solution (Python):
K = int(input())
A = list(map(int,input().split()))
I = [[-1,-1] for _ in range(K+1)]
I[K] = [2,2]
fg = True
for i in range(K-1,-1,-1):
    
    left = A[i]*((I[i+1][0]+A[i]-1)//A[i]) 
    I[i][0] = max(A[i],left)
    I[i][1] = A[i]*(I[i+1][1]//A[i] + 1) -1
    
    if(I[i][0] > I[i][1]):
        fg = False
        
if(not fg):
    print(-1)
else:
    print(*I[0])

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

def ng():
  print(-1)
  exit()

A = A[::-1]
if A[0] != 2:
  ng()
mim = 2
mox = 3

for i in range(1, K):
  a = A[i]
  n = -(-mim // a) * a
  if n > mox:
    ng()
  mim = n
  mox = mox // a * a + a - 1

print(mim, mox)

Solution (Python):
k=int(input())
a=list(map(int,input().split()))
a.reverse()
d=[2,2]
f=True
for i in a:
  d[0]=((d[0]-1)//i+1)*i
  d[1]=d[1]//i*i+i-1
  if d[0]>d[1]:
    f=False
if f:
  print(d[0],d[1])
else:
  print(-1)

Solution (Python):
import sys
K = int(input())
A = list(map(int, input().split()))
minA = 2
maxA = 2
for ai in A[::-1]:
    if minA <= ai <= maxA:
        minA = ai
        maxA = maxA - maxA%ai + ai - 1
    elif ai < minA:
        minA = minA + ai * int(minA%ai>0) - minA%ai
        maxA = maxA - maxA%ai + ai - 1
    elif ai > maxA:
        print(-1)
        sys.exit()
if minA > maxA:
    print(-1)
else:
    print(minA, maxA)

Solution (Python):
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) > 2:
        r = mid
    else:
        l = mid
maxcnt = l

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) < 2:
        l = mid
    else:
        r = mid
mincnt = r


if check(mincnt, A) == check(maxcnt, A) == 2:
    print(mincnt, maxcnt)
else:
    print(-1)

Solution (Python):
import math
K = int(input())
A = list(map(int, input().split()))
mincnt = 2
for a in reversed(A):
    if a < mincnt:
        a = math.ceil(mincnt/a) * a
    mincnt = max(mincnt, a)



maxcnt = 2
nowgropu = 1
for a in reversed(A):
    nowgropu = maxcnt // a
    maxcnt = a * (nowgropu + 1) - 1



def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt == 2


if check(mincnt, A) and check(maxcnt, A):
    print(mincnt, maxcnt)
else:
    print(-1)

Solution (Python):
def solve(x):
    for i in a:
        x = i * (x // i)
    return x

def solve_min(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if solve(m) < 2:
            c1 = m
        else:
            c2 = m
        return solve_min(c1, c2)

def solve_max(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if solve(m) <= 2:
            c1 = m
        else:
            c2 = m
        return solve_max(c1, c2)

k = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mi = solve_min(maxa - 1, pow(10, 18))
ma = solve_max(maxa - 1, pow(10, 18))
ans = [mi, ma - 1]
print(-1 if mi == ma else " ".join(map(str, ans)))

Solution (Python):
def solve(x):
    for i in a:
        x = i * (x // i)
    return x

def solve_min(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if solve(m) < 2:
            c1 = m
        else:
            c2 = m
        return solve_min(c1, c2)

def solve_max(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        if solve(m) <= 2:
            c1 = m
        else:
            c2 = m
        return solve_max(c1, c2)

k = int(input())
a = list(map(int, input().split()))
maxa = max(a)
mi = solve_min(maxa - 1, pow(10, 18))
ma = solve_max(maxa - 1, pow(10, 18))
ans = [mi, ma - 1]
print(-1 if mi == ma else " ".join(map(str, ans)))

Solution (Python):
from math import ceil, floor

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


"""
- X人いてAi人グループをつくるとき，floor(X/Ai)個のグループになる
- floor(X/Ai) * Ai = X - X mod Ai 人が残る
- fp(X) = X - X mod pとする
"""

L, R = 2, 2



for k in range(K - 1, -1, -1):
    
    L = ceil(L / A[k]) * A[k]
    R = floor(R / A[k]) * A[k] + A[k] - 1
    if L > R:
        print(-1)
        exit()

print(L, R)

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

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

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

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

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

def solve(num, checker):
    return checker*(num//checker)

max_A = max(a)

left, right = 0, k*max_A + 1
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 2:
        right = middle
    else:
        left = middle + 1
x = right

left, right = 0, k*max_A + 1
while left < right:
    middle = -((-left-right)//2)
    num = middle
    
    for i in a:
        num = solve(num, i)
    if num <= 2:
        left = middle
    else:
        right = middle - 1
        
y = right

if y < x:
    print(-1)
else:
    print(x, y)

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

def solve(num, checker):
    return checker*(num//checker)

max_A = max(a)

left, right = 0, k*max_A + 1
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 2:
        right = middle
    else:
        left = middle + 1
x = right

left, right = 0, k*max_A + 1
while left < right:
    middle = -((-left-right)//2)
    
    num = middle
    
    for i in a:
        num = solve(num, i)
    if num <= 2:
        left = middle
    else:
        right = middle - 1
        
y = right

if y < x:
    print(-1)
else:
    print(x, y)

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

def solve(num, checker):
    return checker*(num//checker)

left, right = 0, max(a)*k + 2
while left+1 < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num <= 2:
        left = middle
    else:
        right = middle
x = left

left, right = 0, max(a)*k + 2
while left+1 < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num < 2:
        left = middle
    else:
        right = middle
        
y = right
if x < y:
    print(-1)
else:
    print(y, x)

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

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

print(m,M)

Solution (Python):
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  


K = I()
A = LI()
A.reverse()

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

print(m,M)

Solution (Python):
import math
K = int(input())
A = list(map(int,input().split()))
if A[K-1]!=2:
    print(-1)
elif K==1:
    print(2,3)
else:
    nmin = 2
    nmax = 2+A[K-1]-1
    flag = 0
    for i in range(K-2,-1,-1):
        b = A[i]
        nmin = math.ceil(nmin/b)*b
        nmax = math.floor(nmax/b)*b
        if nmin>nmax:
            flag = 1
            break
        nmax += b-1
    if flag==1:
        print(-1)
    else:
        print(nmin,nmax)

Solution (Python):
K = int(input())
A = list(map(int,input().split()))
A.reverse()
if A[0] != 2:
    print(-1)
    exit()

low, high = 2, 3

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

Solution (Python):
n, *a = map(int, open(0).read().split())

unko = 2
unti = 2
for i in reversed(a):
    unko = unko // i * i + i - 1
    unti = (unti + i - 1) // i * i
if unti >= unko:
    print(-1)
else:
    print(unti, unko)

Solution (Python):
k=int(input())
A=[int(i) for i in input().split()]
mi=2
ma=2

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

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


K = I()
A = LI()
A.reverse()

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

print(m,M)

Solution (Python):
import sys
 
K = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
 
if A[-1] != 2:
    print(-1)
    sys.exit()
 
l = 2
r = 2
for i in range(K-2, -1, -1):
    l = ((l - 1) // A[i] + 1) * A[i]
    r = ((r + A[i+1] - 1) // A[i]) * A[i] 
 
    if r < l:
        print(-1)
        sys.exit()
 
print(l, r + A[0] - 1)

Solution (Python):
from math import ceil, floor

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

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

l = 2
r = 3
for a in al[1:]:
    min_l = ceil(l/a)*a
    max_r = floor(r/a)*a
    if min_l > r:
        print(-1)
        exit()
    if max_r < l:
        print(-1)
        exit()
    l = min_l
    r = max_r + (a-1)

print(l,r)

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline

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

min_child = 2
max_child = 2

for i in range(K-1,-1,-1):
    if math.ceil(min_child/A[i])>0 and math.floor(max_child/A[i])>0 and math.floor(max_child/A[i])-math.ceil(min_child/A[i])>=0:
        min_child = math.ceil(min_child/A[i])*A[i]
        max_child =math.floor(max_child/A[i])*A[i]+A[i]-1
    else:
        print(-1)
        exit()
print(min_child,max_child)

Solution (Python):


import math

import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd


k=int(input())
a=list(map(int,input().split()))
ml=mr=2
l=r=2
for i in range(k):
    ai=a[k-1-i]
    mr=(r//ai)*ai
    ml=(1+(l//ai))*ai if l%ai!=0 else l
    if ml>mr:
      print(-1)
      exit()
    if mr==0:
        print(-1)
        exit()
    elif ml==0:
        ml=mr
    l=ml
    r=mr+ai-1
print(l,r)

Solution (Python):
n = int(input())
As = list(map(int, input().split()))
    
def f(m):
    debug = m
    for a in As:
        i = m // a
        m = i * a
    return m


l = 1
r = 10**20
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 1: l = m
    else: r = m
ans1 = r
l = 1
r = 10**20
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 2: l= m
    else: r = m
ans2 = l

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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))[::-1]
if a[0]!=2:
  print(-1)
  exit()
mn,mx=2,2
for j in a:
  if (mn+j-1)//j>mx//j:
    print(-1)
    exit()
  mn=(mn+j-1)//j*j
  mx=mx//j*j+j-1
print(mn,mx)

Solution (Python):
import sys
import math

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

if a[-1] != 2:
    print(-1)
    sys.exit()
else:
    mi,ma = 2,2
    for i in range(k-1,-1,-1):
        if mi == ma and mi%a[i] != 0 :
            print(-1)
            sys.exit()
        elif mi != ma and math.floor(ma/a[i]) - math.floor((mi-1)/a[i]) == 0:
            print(-1)
            sys.exit()
        else:
            mi = math.ceil(mi / a[i]) * a[i]
            ma = math.floor(ma / a[i]) * a[i] + a[i] - 1
            
    print(mi,ma)

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


lo = 2
hi = 2
for A in reversed(As):
    if (hi // A) - ((lo - 1) // A) == 0:
        print(-1)
        exit()
    lo = (lo + A - 1) // A * A
    hi = (hi // A + 1) * A - 1 

print(lo, hi)

Solution (Python):
k = int(input())
alst = list(map(int, input().split()))[::-1]
l = 2
r = 2

def check(l, r, a):
    if l % a == 0:
        return True
    elif r // a == l // a:
        return False
    else:
        return True

for a in alst:
    if not check(l, r, a):
        print(-1)
        exit()
    l = (l + a - 1) // a * a
    r = r // a * a + (a - 1)
print(l, r)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
A = LIST()

def f(N):
	left = N
	for a in A:
		left = left//a*a
	return left

l_N_max = 0
r_N_max = K*max(A)+2
while l_N_max+1 < r_N_max:
	m = (l_N_max+r_N_max)//2
	if f(m) <= 2:
		l_N_max = m
	else:
		r_N_max = m

N_max = l_N_max

l_N_min = 0
r_N_min = K*max(A)+2
while l_N_min+1 < r_N_min:
	m = (l_N_min+r_N_min)//2
	if f(m) < 2:
		l_N_min = m
	else:
		r_N_min = m
N_min = r_N_min

if N_min > N_max:
	print(-1)
else:
	print(N_min, N_max)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
A = LIST()

def f(N):
	left = N
	for a in A:
		left = left//a*a
	return left

l_N_max = 0
r_N_max = 10**14
while l_N_max+1 < r_N_max:
	m = (l_N_max+r_N_max)//2
	if f(m) <= 2:
		l_N_max = m
	else:
		r_N_max = m

N_max = l_N_max

l_N_min = 0
r_N_min = 10**14
while l_N_min+1 < r_N_min:
	m = (l_N_min+r_N_min)//2
	if f(m) < 2:
		l_N_min = m
	else:
		r_N_min = m
N_min = r_N_min

if N_min > N_max:
	print(-1)
else:
	print(N_min, N_max)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
A = LIST()

def f(N):
	left = N
	for a in A:
		left = left//a*a
	return left

l_N_max = 0
r_N_max = sum(A)-K+3
while l_N_max+1 < r_N_max:
	m = (l_N_max+r_N_max)//2
	if f(m) <= 2:
		l_N_max = m
	else:
		r_N_max = m

N_max = l_N_max

l_N_min = 0
r_N_min = sum(A)-K+3
while l_N_min+1 < r_N_min:
	m = (l_N_min+r_N_min)//2
	if f(m) < 2:
		l_N_min = m
	else:
		r_N_min = m
N_min = r_N_min

if N_min > N_max:
	print(-1)
else:
	print(N_min, N_max)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
A = LIST()[::-1]

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

N_min = 2
N_max = 3
for a in A[1:]:
	if ((N_min-1)//a) ==  N_max//a:
		print(-1)
		exit()

	N_min = -(-N_min//a)*a
	N_max = N_max//a*a + a - 1

print(N_min, N_max)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
A = LIST()[::-1]

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

N_min = 2
N_max = 3
for a in A[1:]:
	if (N_min-1)//a ==  N_max//a:
		print(-1)
		exit()

	N_min = ((N_min-1)//a+1)*a
	N_max = N_max//a*a + a - 1

print(N_min, N_max)

Solution (Python):
from math import ceil
K = int(input())
A = list(map(int, input().split()))
A.reverse()
if A[0] != 2:
    print(-1)
    exit()
mi = 2
mx = 3
for a in A[1:]:
    if ceil(mi/a) > mx//a:
        print(-1)
        exit()
    mi = ceil(mi/a)*a
    mx = mx//a*a
    mx = mx + a - 1
print(mi, mx)

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


lo = 2
hi = 3
for a in reversed(A):

    nl = (lo-1)//a+1
    nh = (hi-1)//a+1

    lo,hi = nl*a,nh*a

if lo < hi:
    print(lo,hi-1)
else:
    print(-1)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

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

    l = 2
    r = 3

    for x in a[1:]:
        l = (x + l - 1) // x * x
        r = r // x * x + (x - 1)

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


if __name__ == '__main__':
    main()

Solution (Python):
'''
研究室PCでの解答
'''
import math

import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit


ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(1,0),(0,-1),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"


def main():
    k = int(ipt())
    a = [int(i) for i in ipt().split()]
    mi = 2
    ma = 2
    for i in a[::-1]:
        mi = ((mi-1)//i+1)*i
        ma = (ma//i)*i
        if mi > ma:
            print(-1)
            exit()
        ma = ma+i-1
    print(mi,ma)

    return None

if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())

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

ans = (2, 2)

for div in reversed(nums):
    lower = (ans[0] + div - 1) // div * div
    upper = ans[1] // div * div
    if not lower <= upper:
        print(-1)
        exit()
    
    ans = (lower, upper + div - 1)

print(f'{ans[0]} {ans[1]}')

Solution (Python):
import sys
import math
import collections
import bisect
import itertools



sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7


ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))




def main():
    k = ni()
    a = na()
    a.reverse()

    min_num = 2
    max_num = 2

    for ai in a:
        min_num = int(math.ceil(min_num / ai) * ai)
        max_num = int(math.floor(max_num / ai + 1) * ai) - 1

    if min_num <= max_num:
        print(min_num, max_num)
    else:
        print(-1)


if __name__ == '__main__':
    main()

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

cb, cu = 2, 2
for a in A:
    nb = ((cb+a-1)//a)*a
    nu = (cu//a+1)*a-1
    if nb > cu:
        print(-1)
        exit()
    cb, cu = nb, nu
print(nb, nu)

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_s = lambda: readline().rstrip().decode('utf-8')
in_nl = lambda: list(map(int, readline().split()))
in_nl2 = lambda H: [in_nl() for _ in range(H)]
in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')]
in_map2 = lambda H: [in_map() for _ in range(H)]
in_all = lambda: map(int, read().split())


def main():

    K = in_n()
    A = in_nl()[::-1]

    min_n = 2
    max_n = 2

    for group in A:

        cnt = -(-min_n // group)
        next_min = group * cnt
        if not (min_n <= next_min <= max_n):
            print(-1)
            exit()

        cnt = max_n // group
        next_max = cnt * group + (group - 1)

        min_n, max_n = next_min, next_max

    print(min_n, max_n)


if __name__ == '__main__':
    main()

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

def is_ok(arg,flg):
  
  N0 = arg
  for a in A:
    N0 -= N0 % a
  if flg:
    return  N0 >= 2
  else:
    return  N0 <= 2
    
def meguru_bisect(ng, ok, flg):
  '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
  '''
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid, flg):
      ok = mid
    else:
      ng = mid
    
  return ok
      
ok,ng = K * max(A) + 100, -1
m = meguru_bisect(ok,ng,False)

ok,ng = 0, K * max(A) + 100
M = meguru_bisect(ok,ng,True)

if M <= m:
  print(M,m)
else:
  print(-1)

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

def is_ok(arg,flg):
  
  N0 = arg
  for a in A:
    N0 -= N0 % a
  if flg:
    return  N0 >= 2
  else:
    return  N0 <= 2
    
def meguru_bisect(ng, ok, flg):
  '''
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    まずis_okを定義すべし
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
  '''
  while (abs(ok - ng) > 1):
    mid = (ok + ng) // 2
    if is_ok(mid, flg):
      ok = mid
    else:
      ng = mid
    
  return ok
      
ok,ng = K * max(A) + 100, -1
m = meguru_bisect(ok,ng,False)

ok,ng = 0, K * max(A) + 100
M = meguru_bisect(ok,ng,True)

if M <= m:
  print(M,m)
else:
  print(-1)

Solution (Python):
def main():
    K = int(input())
    A = list(map(int, input().split()))
    A = A[::-1]
    if A[0] != 2:
        print(-1)
        return
    n = 2
    lower_n, upper_n = 2, 3
    for a in A:
        
        if upper_n // a - (lower_n - 1) // a == 0:
            print(-1)
            return
        lower_n = (lower_n + a - 1) // a * a  
        upper_n = upper_n // a * a + a - 1  
    print('{} {}'.format(lower_n, upper_n))


if __name__ == '__main__':
    main()

Solution (Python):
def solve():
  ans = 0
  K = int(input())
  A = list(map(int, input().split()))
  A = A[::-1]
  bottom = 2
  top = 2
  for a in A:
    bottom = -(-bottom//a)*a
    if bottom>top:
      return [-1]
    top = top//a*a+a-1
  return [bottom,top]
print(*solve())

Solution (Python):
import sys

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

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

l = 2
r = 2
for i in range(K-2, -1, -1):
    l = ((l - 1) // A[i] + 1) * A[i]
    r = ((r + A[i+1] - 1) // A[i]) * A[i] 

    if l > r:
        print(-1)
        sys.exit()


print(l, r + A[0] - 1)

Solution (Python):
import sys

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

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

l = 2
r = 2
for i in range(K-2, -1, -1):
    l = ((l - 1) // A[i] + 1) * A[i]
    r = ((r + A[i+1] - 1) // A[i]) * A[i] 

    if l > r:
        print(-1)
        sys.exit()


print(l, r + A[0] - 1)

Solution (Python):
import sys

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


l = 0
r = 2 * 10**15
ans1 = -1
while l != r:
    n = (l + r) // 2
    res = n
    for a in A:
        res = res - res % a
    if res >= 2:
        r = n
        if res == 2:
            ans1 = n
    else:
        l = n + 1

l = 0
r = 2 * 10**15
ans2 = -1
while l != r:
    n = (l + r) // 2
    res = n
    for a in A:
        res = res - res % a
    if res <= 2:
        l = n + 1
        if res == 2:
            ans2 = n
    else:
        r = n

if ans1 != -1:
    print(ans1, ans2)
    
else:
    print(-1)

Solution (Python):
import sys

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


l = 0
r = 2 * 10**15
ans1 = -1
while l != r:
    n = (l + r) // 2
    res = n
    for a in A:
        res = res - res % a
    if res >= 2:
        r = n
        if res == 2:
            ans1 = n
    else:
        l = n + 1

l = 0
r = 2 * 10**15
ans2 = -1
while l != r:
    n = (l + r) // 2
    res = n
    for a in A:
        res = res - res % a
    if res <= 2:
        l = n + 1
        if res == 2:
            ans2 = n
    else:
        r = n

if ans1 != -1:
    print(ans1, ans2)
    
else:
    print(-1)

Solution (Python):
k = int(input())
A = list(map(int, input().split()))
if A[-1] != 2:
    print(-1)
    exit()
L = 1
R = 2
for a in reversed(A):
    c = R//a-L//a
    if c == 0:
        print(-1)
        exit()
    L = (L//a+1)*a-1
    R = (R//a+1)*a-1
print(L+1, R)

Solution (Python):
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7








K = getN()
A = getList()
A = A[::-1]
if A[0] != 2:
    print(-1)
    exit()
mi = A[0]
mx = A[0] * 2 - 1
for i in range(1, K):
    ai = A[i]
    mi = (mi + ai - 1) // ai
    mx = mx // ai
    if mi > mx:
        print(-1)
        exit()
    else:
        mi = mi * ai
        mx = (mx + 1) * ai - 1
print(mi, mx)