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: Accepted

Solution code:
from functools import reduce
from math import floor, ceil

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

# ラウンドKから1まで順に、子どもたちの人数として考えられる最小の値と最大の値を求める
R = reduce(
    lambda acc, a:
        acc if acc[0] > acc[1] else
        (
            a * ceil(acc[0] / a),
            a * (floor(acc[1] / a) + 1) - 1
        ),
    reversed(A),
    (2, 2)
)
ans = (
    -1 if R[0] > R[1] else
    ' '.join(map(str, R))
)

# 出力
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
k = int(input())
a = list(map(int,input().split()))
def g(x):
    for i in range(k):
        x = (x//a[i])*a[i]
    return x
#最小値を求める
l,r = 0,2+k*max(a)
while abs(r-l) > 1:
    mid = (l+r)//2
    if g(mid) >=2:
        r = mid
    else:
        l = mid
m = r
#最大値を求める
l,r = 0,2+k*max(a)
while abs(r-l) > 1:
    mid = (l+r)//2
    if g(mid) <= 2:
        l = mid
    else:
        r = mid
M = l
if m <= M:
    print(m,M)
else:
    print(-1)

Submission status: Accepted

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

pass_min = 2
pass_max = 2
for n in nums:

    # pass_min = このラウンドを通過する人数の下限
    # pass_max = このラウンドを通過する人数の上限

    # pass_min以上の最小のnの倍数
    aaa = pass_min + (n - pass_min % n) % n

    # pass_max以下の最大のnの倍数
    bbb = pass_max - pass_max % n

    # 不可能チェック
    if aaa > pass_max or bbb < pass_min:
        print(-1)
        exit()
    
    pass_min = aaa
    pass_max = bbb + (n - 1)

print(pass_min, pass_max)

Submission status: Accepted

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

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

bot=top=0

# 2以上最小値
l = 0
r = sum(a)+2
while r-l>1:
    mid = (l+r)//2
    if check(mid) >1:
        r = mid
    else:
        l = mid
bot = r

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

maxr = 2
minr = 2
r = 0
for n in reversed(L):
    # [minr,maxr]にnの倍数があるか
    if ceil(maxr//n)*n >= minr:
        minr = ceil(minr/n)*n
        maxr = (maxr)//n*n+n-1
    else:
        print(-1)
        exit()

print(int(minr), maxr)

Submission status: Accepted

Solution code:
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

maxr = 2
minr = 2
r = 0
for n in reversed(L):
    #print("max={}min={}".format(maxr, minr))
    if ceil(maxr//n)*n >= minr:
        # if any(x % n == 0 for x in range(minr, maxr+1)):
        # if minr//n <= maxr//n:
        minr = ceil(minr/n)*n
        maxr = (maxr)//n*n+n-1
    else:
        n = -1
        break

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

Submission status: Accepted

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

_min=2
_max=2

for a in A[::-1]:
  # min ~ maxでaの倍数 minはそのまま、maxは＋(a-1)
  if _min%a:
    if a*(_min//a) + a > _max:
      print(-1)
      break
    else:
      _min = a*(_min//a) + a
  else:
    _min = _min
  
  _max = a*(_max//a) + a-1
else:
  print(_min, _max)

Submission status: Accepted

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

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

def bisect_left(func, l, r, target):
    # n>=i ⇒ func(n) <= targetを満たす最小のi
    # l=1, r=sum(A)+2
    # func(l)<= target, target<=func(r)
    if l==r:
        return 0
    if l+1==r:
        if func(l)< target:
            return r
        else:
            return l
    c = (l+r)//2
    if target <= func(c):
        return bisect_left(func, l, c, target)
    else:
        return bisect_left(func, c, r, target)

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

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


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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(l,r)

Submission status: Accepted

Solution code:
#import collections as c
#ip = lambda : map(int, input().split())

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

s,l = 2,2

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

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

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

Submission status: Accepted

Solution code:
#import collections as c
#ip = lambda : map(int, input().split())

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

s,l = 2,2

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

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

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

Submission status: Accepted

Solution code:
from functools import reduce
from math import floor, ceil

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

# ラウンドKから1まで順に、子どもたちの人数として考えられる最小の値と最大の値を求める
R = reduce(
    lambda acc, a: (
        acc if acc[0] > acc[1] else
        (
            a * ceil(acc[0] / a),
            a * (floor(acc[1] / a) + 1) - 1
        )
    ),
    reversed(A),
    (2, 2)
)

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math

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

mi = 2
ma = 2
res = 0

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

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

Submission status: Accepted

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

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

print(cmin, cmax)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

# 最後に2人以上残るような最小のNを探す
ok, ng = 10 ** 18, 0
while abs(ok - ng) > 1:
    n = (ok + ng) // 2
    x = n
    for a in A:
        x = (x // a) * a
    if x >= 2:
        ok = n
    else:
        ng = n
m = ok

# 最後に2人以下になるような最大のNを探す
ok, ng = 0, 10 ** 18
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    n = x
    for a in A:
        x = x // a * a

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


# 条件を満たすかチェック
mx, Mx = m, M
for a in A:
    mx = (mx // a) * a
    Mx = (Mx // a) * a

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys

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

m, M = 2, 2

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

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

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

print(m, M)

Submission status: Accepted

Solution code:
# 後ろから順に考える
# 最後のA_Kは必ず2である必要がある
# A_Kの前には2~3人である必要がある
# ...

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

fail = False
if As[0] != 2:
    fail = True
else:
    mn = 2
    mx = 3
    for a in As[1:]:
        # 今 [mn, mx] = [4, 13], a = 3だとする
        # a人組をつくったあとにありうる数は3の倍数なので、ここでは6, 9, 12のみありうる
        if mn % a != 0:
            mn = (mn // a) * a + a
        if mx % a != 0:
            mx = (mx // a) * a
        if mn > mx:
            fail = True
            break

        # mxを修正
        mx = mx + (a - 1)
if fail:
    print(-1)
else:
    print(mn, mx)

Submission status: Accepted

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

#始めの人数がn人だった時終わりの人数
def g(n,a,k):
    for i in range(k):
        n = n - (n%a[i])
    return n

#print(g(8,a,k))

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

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

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

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

Submission status: Accepted

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

c = 2 #min
d = 2 #max
res = 1 #判定

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
AGC020 B
"""

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

pmax = 2
pmin = 2

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

print(pmin, pmax)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())
 
def judge(k:int, a:list):
    mi = ma = 2
    for ai in a[::-1]:
        # miをaiの倍数に切り上げる
        if mi%ai:
            mi = -(-mi//ai) * ai
            
        # maをaiの倍数-1に切り上げる
        ma = (ma//ai + 1) * ai - 1

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin

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

def judge(k:int, a:list):
    mi = ma = 2
    for ai in a[::-1]:
        # miをaiの倍数に切り上げる
        if mi%ai:
            mi += ai - mi%ai
            
        ma += (ai - 1) - (ma % ai)
        
        if ma < mi:
            return False, (-1,-1)
        
    return True, (mi,ma)

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

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

Submission status: Accepted

Solution code:
def minandmax(bottom,up,mod): #bottom< n < upなるmodで割り切れるnの値の最大値と最小値を返す
    if bottom%mod == 0:
        mnm = bottom
    else:
        mnm = bottom + (mod-bottom%mod)
        if mnm > up:
            mnm = None
    if up%mod == 0:
        mxm = up
    else:
        mxm = up - up%mod
        if mxm < bottom:
            mxm = None
    ans = [mnm,mxm]
    return ans

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

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

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

Submission status: Accepted

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

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

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

print(MIN,MAX)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python

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

sys.setrecursionlimit(1000000)

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

minN = 2
maxN = 2

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

print minN, maxN

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(K, A):
    L = H = 2
    for a in A[::-1]:
        if math.ceil(L/a)*a > H:
            return -1
        L = math.ceil(L/a)*a
        H = math.floor(H/a)*a + a-1

    return ' '.join(map(str, [L, H]))


def main():
    K = read_int()
    A = read_int_n()
    print(slv(K, A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import sys

k = int(input())
a = list(map(int,input().split()))[::-1] 
x=2
y=2
if a[0]!=2:
    print(-1)
    sys.exit(0)

for t in a:
    x=((x-1)//t+1)*t
    y=y//t*t+t-1
    #print(x,y) 

if x > y:
    print(-1)
    sys.exit(0)
print(str(x)+" " + str(y))

Submission status: Accepted

Solution code:
import math
k = int(input())
a = list(map(int,input().split()))
ar = list(reversed(a))
syou = 0
for i in ar:
  if syou > i:
    l = math.ceil(syou/i)
    syou = l * i
  else:
    syou = i
dai = 0
for i in ar:
  if dai > i:
    l = math.ceil(dai/i)
    if dai == l * i:
      dai = l* i + i -1
    else:
      dai = max(l * i -1,dai)
  else:
    dai = i + i -1
kaku = syou + 0
for i in a:
  kaku = (kaku//i) *i
if kaku ==2:
  print(syou,dai)
else:
  print(-1)

Submission status: Accepted

Solution code:
K = int(input())
A = list(map(int, input().split()))
mi = 2
ma = 2
for i in range(K-1, -1, -1):
    a = A[i]
    if ma < a:
        print(-1)
        exit()
    mi = ((mi-1)//a+1)*a
    ma = ma//a*a+a-1
    if mi > ma:
        print(-1)
        exit()
print(mi, ma)

Submission status: Accepted

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

N_min = 2
N_max = 2
for a in A[K::-1]:
	if N_min + (a - N_min) % a > N_max:
		print(-1)
		exit(0)
	else:
		# N_min -> smallest # that is # >= prev N_min and # % a == 0
		N_min += (a - N_min) % a
		# N_max -> smallest # that is # >= prev N_max and # % a == a-1
		N_max += (a - N_max - 1) % a
print(N_min, N_max)

Submission status: Accepted

Solution code:
k = int(input())
a = [int(i) for i in input().split()]
a,flag = a[::-1],True
if a[0]!=2: flag = False
else:
	x,y = 2,3
	for i in range(1,k):
		x2 = x-x%a[i]+min(x%a[i],1)*a[i]
		if x2>y:
			flag = False
			break
		else: x,y = x2,y-y%a[i]+a[i]-1
if flag: print(x,y)
else: print(-1)

Submission status: Accepted

Solution code:
import math

k = int(input())
al = [int(x) for x in input().split()]

pmax = 2
pmin = 2
for a in reversed(al):
    pmin = a*math.ceil(pmin/a)
    pmax = a*math.floor(pmax/a) + a -1

if pmin > pmax:
    print(-1)
else:
    print(pmin, pmax)

Submission status: Accepted

Solution code:
import math
n = int(input())
A = list(map(int,input().split()))

L = 2
R = 2
k = 0
for i in range(n):
    if L//A[n-1-i] == R//A[n-1-i] and L % A[n-1-i] != 0:
        k = 1
        break
    else:
        L = (math.ceil(L/A[n-1-i]))*A[n-1-i]
        R = (R//A[n-1-i]+1) * A[n-1-i] - 1
print(L,R) if k == 0 else print("-1")

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
# import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def get_max_min_mod(a, minp, maxp):
    if minp % a == 0:
        minp_new = (minp // a) * a
    else:
        minp_new = (minp // a + 1) * a
    maxp_new = (maxp // a) * a
    return minp_new, maxp_new

def main():
    k = int(input())
    ak = list(map(int, reversed(input().split())))
    assert len(ak) == k
    minp = maxp = 2
    for j in range(k):
        minp, maxp = get_max_min_mod(ak[j], minp, maxp)
        if minp > maxp:
            print(-1)
            sys.exit(0)
        maxp += ak[j] - 1
    print(minp, maxp)

main()

Submission status: Accepted

Solution code:
K = int(raw_input())
A = map(int, raw_input().split())

ma = mi = 2
for a in reversed(A):
    mi = (mi + a - 1) // a * a
    ma = (ma ) // a * a + a - 1
if mi <= ma:
    print mi, ma
else:
    print -1

Submission status: Accepted

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

lo = 2
hi = 10**18


def check1(people):
    for a in A:
        people = (people // a) * a
    if people > 2:
        return False
    else:
        return True


def check2(people):
    for a in A:
        people = (people // a) * a
    if people < 2:
        return False
    else:
        return True


for i in range(100):
    center = (lo + hi) // 2
    if check1(center):
        lo = center
    else:
        hi = center

Mz = center

lo = 2
hi = 10**18

for i in range(100):
    center = (lo + hi) // 2
    if center > Mz:
        hi = center
        continue
    if check2(center):
        hi = center
    else:
        lo = center

mz = hi
if Mz >= mz:
    print(mz, Mz)
else:
    print(-1)

Submission status: Accepted

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
N_min = 2
N_max = 2

for i in range(K-1,-1,-1):
    N_max = int(math.floor(N_max/A[i]))*A[i] + A[i]-1
    N_min = int(math.ceil(N_min/A[i]))*A[i]
    if N_max < A[i]:
        print(-1)
        exit()
    if N_max < N_min:
        print(-1)
        exit()

print(N_min,N_max)

Submission status: Accepted

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

N_min = 2
N_max = 2
for a in A[K::-1]:
	if N_min + (a - N_min) % a > N_max:
		print(-1)
		exit(0)
	else:
		# N_min -> smallest # that is # >= prev N_min and # % a == 0
		N_min += (a - N_min) % a
		# N_max -> smallest # that is # >= prev N_max and # % a == a-1
		N_max += (a - N_max - 1) % a
print(N_min, N_max)