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



Sample input:
4
3 4 3 2


Sample output:
6 8

Submission status: Wrong Answer

Solution code:
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

#############
# Main Code #
#############

K = getN()
A = getList()
A = A[::-1]
if A[0] > 2:
    print(-1)
    exit()

# n, n + 1, n + 2... n + bef - 1内でのafterの倍数のうち最も大きいもの
def max_alter(n, bef, after):
    return ((n + bef - 1) // after) * after

# n, n + 1, n + 2... n + bef - 1内でのafterの倍数のうち最も小さいもの
def min_alter(n, bef, after):
    if n % after == 0:
        return n
    else:
        return ((n // after) + 1) * after

ans_mi = 2
for i in range(K - 1):
    ans_mi = min_alter(ans_mi, A[i], A[i + 1])

ans_ma = 2
for i in range(K - 1):
    ans_ma = max_alter(ans_ma, A[i], A[i + 1])
    if ans_ma == 0:
        print(-1)
        exit()

ans_ma = max_alter(ans_ma, A[-1], 1)

print(ans_mi, ans_ma)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int,input().split()))
ansmax = 2
ansmin = 2

for i in reversed(range(k)):
    if ansmax < a[i]:
        print(-1)
        exit()
    ansmin = -(-ansmin//a[i])*a[i]
    ansmax = -(-ansmax//a[i])*a[i] - 1
print(str(ansmin) + " " + str(ansmax))

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int,input().split()))
ansmax = 2
ansmin = 2

for i in reversed(range(k)):
    if ansmax < a[i]:
        print(-1)
        exit()
    ansmin = -(-ansmin//a[i])*a[i]
    ansmax = max(ansmax,(ansmax//a[i])*a[i] + a[i] - 1)
print(str(ansmin) + " " + str(ansmax))

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int,input().split()))
ansmax = 2
ansmin = 2
if a[-1] != 2:
    print(-1)
    exit()
for i in reversed(range(k)):
    if ansmax < a[i]:
        print(-1)
        exit()
    ansmin = -(-ansmin//a[i])*a[i]
    ansmax = (ansmax//a[i])*a[i] + a[i] - 1
print(str(ansmin) + " " + str(ansmax))

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int,input().split()))
ansmax = 2
ansmin = 2
for i in reversed(range(k)):
    if ansmax < a[i]:
        print(-1)
        exit()
    ansmin = -(-ansmin//a[i])*a[i]
    ansmax = (ansmax//a[i])*a[i] + a[i] - 1
print(str(ansmin) + " " + str(ansmax))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    if A[0] != 2:
        print(-1)
    else:
        prev_min, prev_max = 2, 3
        for i in range(1, k):
            a = A[i]
            if a > prev_max:
                print(-1)
                break
            else:
                if prev_min % a == 0:
                    now_min = prev_min
                else:
                    now_min = (prev_min // a) * a + a
                diff = prev_max - now_min
                now_max = now_min + (diff // a) * a + a - 1
                prev_min, prev_max = now_min, now_max
        else:
            print(prev_min, prev_max)


if __name__ == '__main__':
    resolve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.reverse() #後ろから見る。

if A[0] != 2:
  print(-1)
  exit()
MIN = 2
MAX = 3
for i in range(1,N):
  nxt = A[i]
  if MAX < nxt:
    print(-1)
    exit() 
  #オッケーの最大値
  MAX = (MAX//nxt)*nxt #MAXは絶対前の数の倍数
  if MAX < MIN:
    print(-1)
    exit()
  #オッケーの最小値
  MIN = min(MAX,((MIN+nxt-1)//nxt)*nxt)

  print(MIN,MAX)
 
  #最小値は変化なし。
  MAX = MAX+(nxt-1)
  print(nxt,MIN,MAX)
print(MIN,MAX)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.reverse() #後ろから見る。

if A[0] != 2:
  print(-1)
  exit()
MIN = 2
MAX = 3
for i in range(1,N):
  nxt = A[i]
  if MAX < nxt:
    print(-1)
    exit() 
  #オッケーの最大値
  MAX = (MAX//nxt)*nxt #MAXは絶対前の数の倍数
  #オッケーの最小値
  MIN = min(MAX,((MIN+nxt-1)//nxt)*nxt)

  #print(MIN,MAX)
 
  #最小値は変化なし。
  MAX = MAX+(nxt-1)
  #print(nxt,MIN,MAX)
print(MIN,MAX)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.reverse() #後ろから見る。

if A[0] != 2:
  print(-1)
  exit()
MIN = 2
MAX = 3
for i in range(1,N):
  nxt = A[i]
  if MAX < nxt:
    print(-1)
    exit() 
  #オッケーの最大値
  MAX = (MAX//nxt)*nxt #MAXは絶対前の数の倍数
  #オッケーの最小値
  MIN = min(MAX,((MIN+nxt-1)//nxt)*nxt)

  #print(MIN,MAX)
 
  #最小値は変化なし。
  MAX = (MAX//nxt)*nxt+(nxt-1)
  #print(nxt,MIN,MAX)
print(MIN,MAX)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.reverse() #後ろから見る。

if A[0] != 2:
  print(-1)
  exit()
MIN = 2
MAX = 3
for i in range(1,N):
  nxt = A[i]
  if MAX < nxt:
    print(-1)
    exit() 
  #オッケーの最大値
  MAX = (MAX//nxt)*nxt #MAXは絶対前の数の倍数
  #オッケーの最小値
  temp = (MIN+nxt-1)//nxt
  if temp*nxt <= MAX:
    MIN = temp*nxt
  else:
    MIN = MAX

  #print(MIN,MAX)
 
  #最小値は変化なし。
  MAX = (MAX//nxt)*nxt+(nxt-1)
  #print(nxt,MIN,MAX)
print(MIN,MAX)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.reverse() #後ろから見る。

if A[0] != 2:
  print(-1)
  exit()
MIN = 2
MAX = 3
for i in range(1,N):
  nxt = A[i]
  #オッケーの最大値
  MAX = (MAX//nxt)*nxt #MAXは絶対前の数の倍数
  #オッケーの最小値
  temp = (MIN+nxt-1)//nxt
  if temp*nxt <= MAX:
    MIN = temp*nxt

  #print(MIN,MAX)
  if MAX < nxt:
    print(-1)
    exit()  
  #最小値は変化なし。
  MAX = (MAX//nxt)*nxt+(nxt-1)
  #print(nxt,MIN,MAX)
print(MIN,MAX)

Submission status: Wrong Answer

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

def f(n):
    for a in As:
        n = a * (n//a)
    return n

ng,ok = 1, 10**10
while ok-ng > 1:
    m = (ok+ng)//2
    if f(m) >= 2: #2以上ならTrue
        ok = m
    else:
        ng = m
mn = ok
# print(ng,ok)

ok,ng = 1, 10**20
while ng-ok > 1:
    m = (ok+ng)//2
    if f(m) <= 2: #2以下の範囲
        ok = m
    else:
        ng = m
mx = ok

# print(ok,ng)
if mn > mx:
    print(-1)
else:
    print(mn,mx)

Submission status: Wrong Answer

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

def f(n):
    for a in As:
        n = a * (n//a)
    return n

ng,ok = 1, 10**10
while ok-ng > 1:
    m = (ok+ng)//2
    if f(m) >= 2: #2以上ならTrue
        ok = m
    else:
        ng = m
mn = ok
# print(ng,ok)

ok,ng = 1, 10**10
while ng-ok > 1:
    m = (ok+ng)//2
    if f(m) <= 2: #2以下の範囲
        ok = m
    else:
        ng = m
mx = ok

# print(ok,ng)
if mn > mx:
    print(-1)
else:
    print(mn,mx)

Submission status: Wrong Answer

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

def f(n):
    for a in As:
        n = a * (n//a)
    return n

l,r = 1, 10**20
while r-l > 1:
    m = (r+l)//2
    if f(m) < 2: #2より小の範囲
        l = m
    else:
        r = m
mn = r

l,r = 1, 10**10
while r-l > 1:
    m = (r+l)//2
    if f(m) > 2: # 2より大の範囲
        r = m
    else:
        l = m
mx = l

if mn > mx:
    print(-1)
else:
    print(mn,mx)

Submission status: Wrong Answer

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

def f(n):
    for a in As:
        x,_ = divmod(n,a)
        n = x*a
    return n

l,r = 1, 10**10
while r-l > 1:
    m = (r+l)//2
    if f(m) < 2: #2より小の範囲
        l = m
    else:
        r = m
mn = r

l,r = 1, 10**10
while r-l > 1:
    m = (r+l)//2
    if f(m) > 2: # 2より大の範囲
        r = m
    else:
        l = m
mx = l

if mn > mx:
    print(-1)
else:
    print(mn,mx)

Submission status: Wrong Answer

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

def f(n):
    for a in As:
        x,_ = divmod(n,a)
        n = x*a
    return n

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

l,r = 1, 10**10
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 3:
        l = m
    else:
        r = m
mx = l
if mn > mx:
    print(-1)
else:
    print(mn,mx)

Submission status: Wrong Answer

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

def f(n):
    for a in As:
        x,_ = divmod(n,a)
        n = x*a
    return n

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

l,r = 1, 10**10
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 3:
        l = m
    else:
        r = m
mx = l
if mn < mx:
    print(-1)
else:
    print(mn,mx)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=list(map(int,input().split()))
if a[-1]!=2:
  print(-1)
  exit()
l,r=2,2
for i in range(k):
  ai=a[-1-i]
  if ai>r:
    print(-1)
    exit()
  
  # l以上r以下のaiの倍数を探す
  l=ai*((l+ai-1)//ai)
  r=ai*(r//ai)+(ai-1)
print(l,r)

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def nn(v, min_v, max_v):
	min_n = (min_v + v - 1) // v
	max_n = max_v // v
	#pa((min_n, max_n))
	if max_n == 0:
		return -1, -1
	return v * min_n, v * max_n + v - 1

def main():
	n = int(input())
	#b , c = tin()
	#s = input()
	al = lin()
	al = al[::-1]
	min_v, max_v = 2,2
	for v in al:
		min_v, max_v = nn(v, min_v, max_v)
		if min_v == -1:
			return -1
	print(min_v, max_v)
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
def resolve():
    # from collections import deque
    k = int(input())
    a = list(map(int, input().split()))
    now = [2]
    if k == 1:
        print("2 3") if a[0] == 2 else print(-1)
    else:
        for i in reversed(range(1,k)):
            nxt = []
            for j in range(len(now)):
                test = now[j]
                nxtd = a[i-1]
                mod = test % nxtd
                if (nxtd-mod)%nxtd < a[i]:
                    for k in range((nxtd-mod)%nxtd, a[i], nxtd):
                        nxt.append(k+test)
            if not nxt:
                print(-1)
                exit()
            now = nxt
        ans = []
        for i in now:
            test = i
            if test % a[0] == 0:
                ans.append(i)
                ans.append(i+a[0]-1)
        ans = sorted(ans)
        print("{} {}".format(ans[0], ans[-1]))
resolve()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import math

k = readint()
a = readints()

flag = 0
if a[-1]!=2:
    flag = 1

b = 2
c = 2
for i in range(k-1,0,-1):
    c = ((c+a[i]-1)//a[i-1]) * a[i-1]
    b = min(math.ceil(b/a[i-1]) * a[i-1],c)
    if c == 0:
        flag = 1
        break

c = c+a[0]-1

if flag:
    print(-1)
else:
    print(b,c)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)

readline = sys.stdin.buffer.readline
def readstr():return readline().rstrip().decode()
def readstrs():return list(readline().decode().split())
def readint():return int(readline())
def readints():return list(map(int,readline().split()))
def printrows(x):print('\n'.join(map(str,x)))
def printline(x):print(' '.join(map(str,x)))

import math

k = readint()
a = readints()

flag = 0
if a[-1]!=2:
    flag = 1

b = 2
c = 2
for i in range(k-1,0,-1):
    b = math.ceil(b/a[i-1]) * a[i-1]
    c = ((c+a[i]-1)//a[i-1]) * a[i-1]
    if c == 0:
        flag = 1

c = c+a[0]-1

if flag:
    print(-1)
else:
    print(b,c)

Submission status: Wrong Answer

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=1):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def dfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def bfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.size
        v[x]=root_v
        while q:
            c=q.popleft()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def parent(self,x):
        return self.dfs(0,func=lambda pr,prv,nx,dist:pr,root_v=-1)
 
    def topological_sort(self,x):  # return topological sort of the tree
        tps=[]
        q=deque([x])
        v=[None]*self.size
        v[x]=0
        while q:
            c=q.popleft()
            tps.append(c)
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=0
        return tps
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        #self.st=SegTree(self.size*2-1,self.ETdepth,function=min,ide=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
    def __str__(self):
        return  str(self.edges)
 
    def show(self):
        if all([all([d==1 for nd,d in edge]) for edge in self.edges]):
            print( [[nd for nd,d in edge] for edge in self.edges] )
        else:
            print(self)
 
class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    # return boundary index of r such that func({table[i]} =< x , i in [pos,r]
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    # return boundary index of l such that func({table[i]} =< x , i in [l,pos]
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos
 
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)


show_flg=False
show_flg=True
ans=0


n=I()
a=LI()
'''
    x=a*m+r
    x>>a*m
    a3*m3+r3>>a3*m3=a2*m2+r2>>a2*m2=a1*m1+r1>>a1*m1=2
    a1>r1>=0
'''
def max_n(l):
    x=l
    M=m=l
    for j,i in zip(a[::-1],a[1::-1]):
        m=(m//i)*i
        m=m+i-1

        show(M,m)
        
        ck=m
        for i in a:
            ck=(ck//i)*i
        if ck!=l:
            x=-1
    return x

def min_n():
    r=l=2
    for i in a[::-1]:
        y=l%i
        if y==0:
            z=0
        else:
            z=i-y
        l=l+z
        r=l+i-1
        m=l
        M=r=(r//i)*i
#        show((l,r),(m,M))
    ck=l
    rt=m,M+i-1
    for i in a:
        ck=(ck//i)*i
    if ck!=2:
        rt=-1,
    return rt

ans=min_n()
show(*ans)
#x=a*m+y