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:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    K = I()
    a = LI()[::-1]
    st = 2
    fail = False
    for i in range(K-1):
        if st % a[i] != 0:
            fail = True
            break

        if st % a[i+1] == 0:
            st = a[i+1]
        else:
            prev_st = st
            st = (a[i+1] - st % a[i+1]) + st
            if prev_st <= st <= prev_st + (a[i] - 1):
                continue
            else:
                fail = True
                break
    if fail:
        print(-1)
        return
    m = st

    st = 2
    for i in range(K-1):
        if st % a[i] != 0:
            fail = True
            break

        if (st + a[i] - 1) % a[i+1] == 0:
            st = st + a[i] - 1
        else:
            prev_st = st
            st = (st + a[i] - 1) - (st + a[i] - 1) % a[i+1]
            if prev_st <= st <= prev_st + (a[i] - 1):
                continue
            else:
                fail = True
                break

    M = st
    M += (a[-1] - 1)

    print(m, M)

main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    K = I()
    a = LI()[::-1]
    st = 2
    fail = False
    for i in range(K-1):
        if st % a[i] != 0:
            fail = True
            break

        if st % a[i+1] == 0:
            st = a[i+1]
        else:
            prev_st = st
            st = (a[i+1] - st % a[i+1]) + st
            if prev_st <= st <= prev_st + (a[i] - 1):
                continue
            else:
                fail = True
                break
    if fail:
        print(-1)
        return
    m = st

    st = 2
    for i in range(K-1):
        if st % a[i] != 0:
            fail = True
            break

        if st % a[i+1] == 0:
            st = a[i+1]
        else:
            prev_st = st
            st = (st + a[i] - 1) - (st + a[i] - 1) % a[i+1]
            if prev_st <= st <= prev_st + (a[i] - 1):
                continue
            else:
                fail = True
                break

    M = st
    M += (a[-1] - 1)

    print(m, M)

main()

Submission status: Wrong Answer

Solution code:
from math import ceil
k = int(input())
A = list(map(int,input().split()))[::-1]
if A[0]!=2:
    print(-1)
    exit()

flg = True
ans = [2,3]
for i in range(1, k):
    m = A[i]*(ceil(ans[0]/A[i]))
    n = A[i]*(ceil(ans[1]/A[i]))
    
    if not m<=ans[1]<=n:
        flg = False
        break
    else:
        ans = [m,m+A[i]-1]

if flg:
    print(*ans)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from math import ceil
k = int(input())
A = list(map(int,input().split()))[::-1]
if A[0] != 2:
    print(-1)
    exit()
flg = True
tmp = [2,3]
for i in range(1, k):
    a = A[i]
    m = a*(ceil(tmp[0]/a))
    if m>tmp[1]:
        flg = False
        break
    else:
        l = ceil(tmp[0]/a)*a
        tmp = [l, l+a-1]
if flg:
    print(*tmp)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
from math import ceil
k = int(input())
A = list(map(int,input().split()))[::-1]
if A[0] != 2:
    print(-1)
    exit()
flg = True
tmp = [2,3]
for i in range(1, k):
    a = A[i]
    if a>tmp[1]:
        flg = False
        break
    else:
        l = ceil(tmp[0]/a)*a
        tmp = [l, l+a-1]

if flg:
    print(*tmp)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
ai = [int(i) for i in input().split()]

low = 2
high = 2*10**9
ans = []

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    #print(mid)
    tmp = mid
    
    for i in range(k):
        tmp = tmp // ai[i]
        tmp = tmp*ai[i]
    #print(tmp,mid,low)
    
    if tmp > 2:
        high = mid
    else:
        low = mid

tmp = low

for i in range(k):
    tmp = tmp // ai[i]
    tmp = tmp*ai[i]

if tmp != 2:
    print(-1)
    exit()
        
ans.append(low)

low = 2
high = 2*10**9

flag = True

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    if flag == True:
        flag = False
        mid = 2
    #print(mid)
    tmp = mid
    
    for i in range(k):
        tmp = tmp // ai[i]
        tmp = tmp*ai[i]
    #print(tmp)
    
    if tmp > 1:
        high = mid
    else:
        low = mid
    #print(mid)
ans.append(high)
tmp = high
for i in range(k):
    tmp = tmp // ai[i]
    tmp = tmp*ai[i]

if tmp != 2:
    print(-1)
    exit()
print(ans[1],ans[0])

Submission status: Wrong Answer

Solution code:
k = int(input())
ai = [int(i) for i in input().split()]

low = 2
high = 2*10**9
ans = []

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    #print(mid)
    tmp = mid
    
    for i in range(k):
        tmp = tmp // ai[i]
        tmp = tmp*ai[i]
    #print(tmp,mid,low)
    
    if tmp > 2:
        high = mid
    else:
        low = mid

tmp = low

for i in range(k):
    tmp = tmp // ai[i]
    tmp = tmp*ai[i]

if tmp != 2:
    print(-1)
    exit()
        
ans.append(low)

low = 2
high = 2*10**9

flag = True

while low+1 < high:
    tmp = 0
    mid = (low + high) //2
    if flag == True:
        flag = False
        mid = 2
    #print(mid)
    tmp = mid
    
    for i in range(k):
        tmp = tmp // ai[i]
        tmp = tmp*ai[i]
    #print(tmp)
    
    if tmp > 1:
        high = mid
    else:
        low = mid
    #print(mid)
ans.append(mid)
tmp = mid

for i in range(k):
    tmp = tmp // ai[i]
    tmp = tmp*ai[i]

if tmp != 2:
    print(-1)
    exit()
print(ans[1],ans[0])

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

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

ma = 2

for i in reversed(range(k)):
    ma = ma//a[i]*a[i] + (a[i]-1)

    if a[i] > ma:
        print(-1)
        exit()

mi = ma//a[0] * a[0]

print(mi,ma)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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()
if A[-1] != 2:
	print(-1)
	exit()

ma = 3
mi = 2

for x in A[::-1]:
	if x > ma:
		print(-1)
		exit()
	elif mi <= x <= ma:
		mi = x
		ma = 2*x-1
	else:
		tmp_mi = -(-mi//x)*x
		tmp_ma = ma//x*x
		if tmp_mi >= tmp_ma:
			print(-1)
			exit()
		ma = tmp_ma+x-1
		mi = tmp_mi

print(mi, ma)

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
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()
if A[-1] != 2:
	print(-1)
	exit()

ma = 3
mi = 2

for x in A[::-1]:
	if x > ma:
		print(-1)
		exit()
	elif mi <= x <= ma:
		mi = x
		ma = 2*x-1
	else:
		tmp_mi = -(-mi//x)*x
		tmp_ma = ma//x*x
		ma = tmp_ma+x-1
		mi = tmp_mi

print(mi, ma)

Submission status: Wrong Answer

Solution code:
def calc(n, N, x):
    m, M = -1, -1
    L, R = 0, 10**9
    while L+1 < R:
        P = (L+R)//2
        if n <= x*P:
            R = P
        else:
            L = P
    if n <= x*R <= N:
        m = x*R
    L, R = 0, 10**9
    while L+1 < R:
        P = (L+R)//2
        if N < x*P:
            R = P
        else:
            L = P
    if n <= x*L <= N:
        M = x*L + (x-1)
    return m, M

def main():
    k = int(input())
    a = list(map(int, input().split()))
    f = True
    m, M = 2, 2
    for i in reversed(range(k)):
        m, M = calc(m, M, a[i])
        if m == -1 or M == -1:
            f = False
            break
    if f:
        print(m, M)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def calc(n, N, x):
    m, M = -1, -1
    L, R = 0, 10**9
    while L+1 < R:
        P = (L+R)//2
        if n <= x*P:
            R = P
        else:
            L = P
    if x*R <= N:
        m = x*R
    L, R = 0, 10**9
    while L+1 < R:
        P = (L+R)//2
        if N < x*P:
            R = P
        else:
            L = P
    if n <= x*L:
        M = x*L + (x-1)
    return m, M

def main():
    k = int(input())
    a = list(map(int, input().split()))
    f = True
    m, M = 2, 2
    for i in reversed(range(k)):
        m, M = calc(m, M, a[i])
        if m == -1 or M == -1:
            f = False
            break
    if f:
        print(m, M)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from fractions import gcd
def calc(n, N, p, q):
    n, N = n*q//gcd(n, q), N*q//gcd(N, q)
    L, R = 0, 10**9
    while L+1 < R:
        M = (L+R)//2
        if n <= p*M:
            R = M
        else:
            L = M
    if n+(q-1) < p*R:
        n = -1
    else:
        n = p*R
    L, R = 0, 10**9
    while L+1 < R:
        M = (L+R)//2
        if N+q <= p*M:
            R = M
        else:
            L = M
    if p*L < N:
        N = -1
    else:
        N = p*L
    return n, N

def main():
    k = int(input())
    a = list(map(int, input().split()))
    f = True
    M, m = 2, 2
    if 2 < a[-1]:
        f = False
    else:
        for i in reversed(range(1, k)):
            m, M = calc(m, M, a[i-1], a[i])
            if m == -1 or M == -1:
                f = False
                break
        M += a[0]-1
    if f:
        print(m, M)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
a = [int(i) for i in input().split()]
mi = 2
ma = 2
for b in a[::-1]:
  mi = math.ceil(mi/b)*b
  ma = math.ceil((ma+1)/b)*b-1
  if ma < b:
    print(-1)
    exit()
print(mi,ma)

Submission status: Wrong Answer

Solution code:
# 現在の数curに対して直前の数としてあり得る範囲は、cur ~ cur + A[i] - 1の範囲内
# さらにA[i-1]の倍数である必要があるため、上記範囲内のA[i-1]の倍数の最大最小値を設定する
# 直前の数がない場合(最後)はcur, cur + A[i]をそのまま出力
import sys
readline = sys.stdin.readline

K = int(readline())
A = list(map(int,readline().split()))[::-1] # ややこしいので逆順で見ていく

mincur = 2
maxcur = 2

def get_min_val(c,a): # c以上のaの倍数の最小値を求める
  return ((c - 1)//a + 1) * a

def get_max_val(c,a): # c以下のaの倍数の最大値を求める
  return (c // a) * a

if A[0] != 2:
  print(-1)
  exit(0)
  
for i in range(len(A)):
  # 最小について
  mincur_min = mincur
  mincur_max = mincur + A[i] - 1
  if i + 1 < len(A):
    mincur = get_min_val(mincur_min,A[i + 1])
    if mincur > mincur_max:
      print(-1)
      exit(0)
    
  maxcur_min = maxcur
  maxcur_max = maxcur + A[i] - 1
#  print("maxcur_min",maxcur_min,"maxcur_max",maxcur_max)
  if i + 1 < len(A):
    maxcur = get_max_val(maxcur_max,A[i + 1])
    if maxcur < maxcur_min:
      print(-1)
      exit(0)
  else:
    maxcur = maxcur_max
      
#  print("i",i,mincur,maxcur)
  
print(mincur,maxcur)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

K = int(readline())
A = list(map(int,readline().split()))[::-1] # 逆から見ていくため反転

# 現在の数
cur = 2

if A[0] != 2: # 最後は必ず2
  print(-1)
  exit(0)

#print(A)

def getMinVal(c,a):
  # aの倍数でcより大きく最も小さい数を求める
  return (((c- 1) // a) + 1) * a

def getMaxVal(minval,a):
  # 算出済みのminvalを元に、取りうる最大の数（次の倍数より1小さいもの）を求める
  return minval + a - 1

# まず最小のほうを求める
for i in range(len(A)):
  # 現在のcurの値から起こりうる最小/最大値
  minpos = getMinVal(cur,A[i])
  maxpos = getMaxVal(minpos,A[i])
  
  if A[i] < minpos or maxpos < A[i]:
    print(-1)
    exit(0)

  # これが次の項目の倍数である必要がある。
  if i + 1 < len(A):
    if minpos % A[i + 1] != 0:
      cur = getMinVal(minpos,A[i + 1])
    else:
      cur = minpos
  else:
    cur = minpos
  

ans = [0] * 2
ans[0] = cur
  
def getNextMax(c,a):
  # cより小さい最も大きいaの倍数を返す
  return (c // a) * a
 
cur = 2
# 次に最大のほう
for i in range(len(A)):
  # 現在のcurの値から起こりうる最小/最大値
#  print("i",i,"A[i]",A[i])
  minpos = getMinVal(cur,A[i])
  maxpos = getMaxVal(minpos,A[i])
#  print("minpos",minpos,"maxpos",maxpos)
  if cur * 2 < A[i]:
    print(-1)
    exit(0)
  # 取りうる最大の数maxvalとしたいのだが、これが次のA[i+1]の倍数でなくてはいけない
  # 倍数でない場合は、maxvalより小さい最も大きい倍数である必要がある
  if i + 1 < len(A):
    if maxpos % A[i + 1] != 0:
      cur = getNextMax(maxpos,A[i + 1])
    else:
      cur = maxpos
  else:
    cur = maxpos
#  print("cur",cur)
    
ans[1] = cur

print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

K = int(readline())
A = list(map(int,readline().split()))[::-1] # 逆から見ていくため反転

# 現在の数
cur = 2

if A[0] != 2: # 最後は必ず2
  print(-1)
  exit(0)

#print(A)

def getMinVal(c,a):
  # aの倍数でcより大きく最も小さい数を求める
  return (((c- 1) // a) + 1) * a

def getMaxVal(minval,a):
  # 算出済みのminvalを元に、取りうる最大の数（次の倍数より1小さいもの）を求める
  return minval + a - 1

# まず最小のほうを求める
for i in range(len(A)):
  # 現在のcurの値から起こりうる最小/最大値
  minpos = getMinVal(cur,A[i])
  maxpos = getMaxVal(minpos,A[i])
  
  if A[i] < minpos and maxpos < A[i]:
    print(-1)
    exit(0)

  # これが次の項目の倍数である必要がある。
  if i + 1 < len(A):
    if minpos % A[i + 1] != 0:
      cur = getMinVal(minpos,A[i + 1])
    else:
      cur = minpos
  else:
    cur = minpos
  

ans = [0] * 2
ans[0] = cur
  
def getNextMax(c,a):
  # cより小さい最も大きいaの倍数を返す
  return (c // a) * a
 
cur = 2
# 次に最大のほう
for i in range(len(A)):
  # 現在のcurの値から起こりうる最小/最大値
#  print("i",i,"A[i]",A[i])
  minpos = getMinVal(cur,A[i])
  maxpos = getMaxVal(minpos,A[i])
#  print("minpos",minpos,"maxpos",maxpos)
  if cur * 2 < A[i]:
    print(-1)
    exit(0)
  # 取りうる最大の数maxvalとしたいのだが、これが次のA[i+1]の倍数でなくてはいけない
  # 倍数でない場合は、maxvalより小さい最も大きい倍数である必要がある
  if i + 1 < len(A):
    if maxpos % A[i + 1] != 0:
      cur = getNextMax(maxpos,A[i + 1])
    else:
      cur = maxpos
  else:
    cur = maxpos
#  print("cur",cur)
    
ans[1] = cur

print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

K = int(readline())
A = list(map(int,readline().split()))[::-1] # 逆から見ていくため反転

# 現在の数
cur = 2

if A[0] != 2: # 最後は必ず2
  print(-1)
  exit(0)

#print(A)

def getMinVal(c,a):
  # aの倍数でcより大きく最も小さい数を求める
  return (((c- 1) // a) + 1) * a

def getMaxVal(minval,a):
  # 算出済みのminvalを元に、取りうる最大の数（次の倍数より1小さいもの）を求める
  return minval + a - 1

# まず最小のほうを求める
for i in range(len(A)):
  # 現在のcurの値から起こりうる最小/最大値
  minpos = getMinVal(cur,A[i])
  maxpos = getMaxVal(minpos,A[i])
  
  if A[i] < minpos and maxpos < A[i]:
    print(-1)
    exit(0)

  cur = minpos

ans = [0] * 2
ans[0] = cur
  
def getNextMax(c,a):
  # cより小さい最も大きいaの倍数を返す
  return (c // a) * a
 
cur = 2
# 次に最大のほう
for i in range(len(A)):
  # 現在のcurの値から起こりうる最小/最大値
#  print("i",i,"A[i]",A[i])
  minpos = getMinVal(cur,A[i])
  maxpos = getMaxVal(minpos,A[i])
#  print("minpos",minpos,"maxpos",maxpos)
  if cur * 2 < A[i]:
    print(-1)
    exit(0)
  # 取りうる最大の数maxvalとしたいのだが、これが次のA[i+1]の倍数でなくてはいけない
  # 倍数でない場合は、maxvalより小さい最も大きい倍数である必要がある
  if i + 1 < len(A):
    if maxpos % A[i + 1] != 0:
      cur = getNextMax(maxpos,A[i + 1])
    else:
      cur = maxpos
  else:
    cur = maxpos
#  print("cur",cur)
    
ans[1] = cur

print(*ans)

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

K = int(readline())
A = list(map(int,readline().split()))[::-1] # 逆から見ていくため反転

# 現在の数
cur = 2

if A[0] != 2: # 最後は必ず2
  print(-1)
  exit(0)

#print(A)

def getMinVal(c,a):
  # aの倍数でcより大きく最も小さい数を求める
  return (((c- 1) // a) + 1) * a

def getMaxVal(minval,a):
  # 算出済みのminvalを元に、取りうる最大の数（次の倍数より1小さいもの）を求める
  return minval + a - 1

# まず最小のほうを求める
for i in range(len(A)):
  # 現在のcurの値から起こりうる最小/最大値
  minpos = getMinVal(cur,A[i])
  maxpos = getMaxVal(minpos,A[i])
  
  if cur * 2 < A[i]:
    print(-1)
    exit(0)

  cur = minpos

ans = [0] * 2
ans[0] = cur
  
def getNextMax(c,a):
  # cより小さい最も大きいaの倍数を返す
  return (c // a) * a
 
cur = 2
# 次に最大のほう
for i in range(len(A)):
  # 現在のcurの値から起こりうる最小/最大値
#  print("i",i,"A[i]",A[i])
  minpos = getMinVal(cur,A[i])
  maxpos = getMaxVal(minpos,A[i])
#  print("minpos",minpos,"maxpos",maxpos)
  if cur * 2 < A[i]:
    print(-1)
    exit(0)
  # 取りうる最大の数maxvalとしたいのだが、これが次のA[i+1]の倍数でなくてはいけない
  # 倍数でない場合は、maxvalより小さい最も大きい倍数である必要がある
  if i + 1 < len(A):
    if maxpos % A[i + 1] != 0:
      cur = getNextMax(maxpos,A[i + 1])
    else:
      cur = maxpos
  else:
    cur = maxpos
#  print("cur",cur)
    
ans[1] = cur

print(*ans)

Submission status: Wrong Answer

Solution code:




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

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



hi = 2
lo = 2

for i in reversed(range(K)):

    if hi // A[i] < 1:
        print(-1)
        exit()

    new_hi = hi // A[i] * A[i] + (A[i] - 1)
    new_lo = lo // A[i] * A[i]

    if new_lo < lo:
        new_lo = hi // A[i] * A[i]


    hi = new_hi
    lo = new_lo


print(lo, hi)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], 2 * A[-1] - 1
judge = True
for i in range(K - 1):
    if r - l == r % A[-i-2] - l % A[-i-2] and r % A[-i-2] and l % A[-i-2]:
        judge = False
        break
    l = -(-l // A[-i-2]) * A[-i-2]
    r = (r // A[-i-2] + 1) * A[-i-2] - 1
if judge:
    print(l, r)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], 2 * A[-1] - 1
judge = True
for i in range(K - 1):
    if r - l == r % A[-i-2] - l % A[-i-2]:
        judge = False
        break
    l = -(-l // A[-i-2]) * A[-i-2]
    r = (r // A[-i-2] + 1) * A[-i-2] - 1
if judge:
    print(l, r)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], 2 * A[-1] - 1
judge = True
for i in range(K - 1):
    l = -(-l // A[-i-2]) * A[-i-2]
    r = (r // A[-i-2]) * A[-i-2]
    if r == 0:
        judge = False
        break
    r += A[-i-2] - 1
if judge:
    print(l, r)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], A[-1]
judge = True
for i in range(K - 1):
    if r + A[-i-1] <= A[-i-2]:
        judge = False
        break
    l = -(-l // A[-i-2]) * A[-i-2]
    if (2 * r) % A[-i-2]:
        r = ((r + A[-i-1]) // A[-i-2]) * A[-i-2]
    else:
        r = 2 * r - A[-i-2]
if judge:
    print(l, r + A[0] - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], A[-1]
judge = True
for i in range(K - 1):
    if 2 * r <= A[-i-2]:
        judge = False
        break
    l = -(-l // A[-i-2]) * A[-i-2]
    if (2 * r) % A[-i-2]:
        r = (2 * r // A[-i-2]) * A[-i-2]
    else:
        r = 2 * r - A[-i-2]
if judge:
    print(l, r + A[0] - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], A[-1]
judge = True
for i in range(K - 1):
    if 2 * r <= A[-i-2]:
        judge = False
        break
    l = -(-l // A[-i-2]) * A[-i-2]
    if (2 * r) % A[-i-2]:
        r = (2 * r // A[-i-2]) * A[-i-2]
    else:
        r = 2 * r - A[-i-2]
    print(l,r)
if judge:
    print(l, r + A[0] - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], A[-1]
judge = True
for i in range(K - 1):
    if 2 * r <= A[-i-2]:
        judge = False
        break
    l = -(-l // A[-i-2]) * A[-i-2]
    r = (2 * r // A[-i-2]) * A[-i-2]
if judge:
    print(l, r + A[0] - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], A[-1]
judge = True
for i in range(K - 1):
    if 2 * r <= A[-i-2]:
        judge = False
        break
    l = -(-l // A[-i-2]) * A[-i-2]
    r = (r // A[-i-2]) * A[-i-2]
if judge:
    print(l, r + A[0] - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
l, r = A[-1], A[-1]
judge = True
for i in range(K - 1):
    if 2 * r <= A[-i-2]:
        judge = False
        break
    l = (l // A[-i-2] + 1) * A[-i-2]
    r = (r // A[-i-2]) * A[-i-2]
if judge:
    print(l, r + A[0] - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int, input().split()))
x=2
y=2
A=A[::-1]
for i in range(N):
  if y<A[i]:
    print(-1)
    exit()
  else:
    if x<A[i]:
      x=A[i]
    if x%A[i]!=0:
      x+=A[i]-x%A[i]
    if y%A[i]!=0:
      y-=y%A[i]
    y+=A[i]-1
print(x,y)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    A=LI()
    low = 2
    high = 2
    for a in A[::-1]:
        if(high < a):
            print(-1)
            return
        high = a * (high//a)
        low = a * ceil(low,a)
        high += a-1
    print(low,high)
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from math import ceil, floor

def main():
  k = int(input())
  la = list(map(int, input().split()))[::-1]
  l = 2
  r = 2
  for a in la:
    if floor(r/a) == 0:
      print(-1)
      return
    l = ceil(l/a) * a
    r = floor(r/a) * a + a - 1
  print(l, r)

if __name__=='__main__':
  main()

Submission status: Wrong Answer

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

def calc(n):
    for a in A:
        n = n // a * a
    return n

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

ma = l
l, r = -1, 10 ** 9
while l + 1 < r:
    m = (l+r) // 2
    if calc(m) >= 2:
        r = m
    else:
        l = m
mi = r

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

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))
#そのラウンドで落ちるマックスはa[i]-1人、残る人数は最小でa[i]
#a[i-1] <= 2 でなくてはいけない。
#そのラウンドが終わるごとに人数がa[i]の倍数になっていると考えると分かりやすい
#最大を考える場合は、そのラウンドで毎回毎回max人数落ちてると考えればいい
#最小を考える場合は、そのラウンドで毎回毎回min人数落ちていると考える

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
print("{} {}".format(ans_min, ans_max))
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)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))
#そのラウンドで落ちるマックスはa[i]-1人、残る人数は最小でa[i]
#a[i-1] <= 2 でなくてはいけない。
#そのラウンドが終わるごとに人数がa[i]の倍数になっていると考えると分かりやすい
#最大を考える場合は、そのラウンドで毎回毎回max人数落ちてると考えればいい
#最小を考える場合は、そのラウンドで毎回毎回min人数落ちていると考える

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
    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)

Submission status: Wrong Answer

Solution code:
from math import ceil
K = int(input())
A = list(map(int,input().split()))[::-1]
if A[0] != 2:
    print(-1)
    exit(0)

m, M = 2, 2
for e in A[1:]:
    if e*ceil(m/e)+e-1 < M:
        print(-1)
        exit(0)
    else:
        m = e*ceil(m/e)
        M = e*(M//e+1)-1
print(m,M)

Submission status: Wrong Answer

Solution code:
from math import ceil
K = int(input())
A = list(map(int,input().split()))[::-1]
if A[0] != 2:
    print(-1)
    exit(0)

m, M = 2, 2
for e in A[1:]:
    if e*ceil(m/e)+e-1 < M:
        print(-1)
        exit(0)
    else:
        t = ceil(m/e)
        m = e*t
        M = e*(t+1)-1
print(m,M)

Submission status: Wrong Answer

Solution code:
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)
print(R)
print(L[k], R[k])

Submission status: Wrong Answer

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

B = list(reversed(A))
B = [2] + B
import math
for i in range(k+1):
    if i != k:
        if B[i]+B[i]-1 < B[i+1]:
            print(-1)
            exit()
        min_ = max(B[i], B[i+1])
        max_ = B[i]+B[i]-1
        #print(min_, max_)
    else:
        min_ = math.ceil(min_/B[i])*B[i]
        max_ = (max_//B[i])*B[i]+B[i]-1

print(min_, max_)

Submission status: Wrong Answer

Solution code:
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 maxi<a[i]:
        print(-1)
        exit()
    else:
        times=int(maxi/a[i])
        maxi=a[i]*(times+1)-1
print(mini,maxi)

Submission status: Wrong Answer

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

B = list(reversed(A))
B = [2] + B
for i in range(k+1):
    if i != k:
        if B[i]+B[i]-1 < B[i+1]:
            print(-1)
            exit()
        #min_ = max(B[i], B[i+1])
        max_ = B[i]+B[i]-1
        #print(min_, max_)
    else:
        min_ = (max_//B[i])*B[i]
        max_ = (max_//B[i])*B[i]+B[i]-1

print(min_, max_)

Submission status: Wrong Answer

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

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

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

over = 10**10
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)

Submission status: Wrong Answer

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

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