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 sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

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

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(200000)


def main(lis):
    res = calc_min_max(lis[::-1])
    if isinstance(res, int):
        print(-1)
        return
    print(*res)


def calc_min_max(a_lis, min_val=None, max_val=None):
    if not a_lis:
        return min_val, max_val
    a, *next_a_lis = a_lis
    if min_val is None:
        if a != 2:
            return -1
        return calc_min_max(next_a_lis, min_val=2, max_val=3)
    if max_val < a:
        return -1
    new_min_val = ((min_val + a - 1) // a) * a
    new_max_val = (max_val // a) * a + a - 1
    return calc_min_max(next_a_lis, min_val=new_min_val, max_val=new_max_val)


input()
lis = list(map(int, input().split()))
main(lis)

Submission status: Wrong Answer

Solution code:
import sys
k=int(input())
a=list(map(int,input().split()))
min=2;max=2
min=((min+a[k-1]-1)//a[k-1])*a[k-1]
max=(max//a[k-1])*a[k-1]
if min>max:
  print(-1)
  sys.exit()
for i in range(k-1,0,-1):
  max=min+a[i]-1
  min=((min+a[i-1]-1)//a[i-1])*a[i-1]
  max=(max//a[i-1])*a[i-1]
  if min>max:
    print(-1)
    sys.exit()
max+=a[0]-1
print(min,max)

Submission status: Wrong Answer

Solution code:
import sys
k=int(input())
a=list(map(int,input().split()))
min=2;max=2
for i in range(k-1,0,-1):
  max=min+a[i]-1
  min=((min+a[i-1]-1)//a[i-1])*a[i-1]
  max=(max//a[i-1])*a[i-1]
  if min>max:
    print(-1)
    sys.exit()
max+=a[0]-1
print(min,max)

Submission status: Wrong Answer

Solution code:
#Ice Link Game
N = int(input())
A = list(map(int, input().split()))
 
def filt(a, low, high, flag): #flag == 1: max, -1: min
    b = -1
    if flag==1:
        for i in range(high, low - 1, -1):
            if i % a == 0:
                b = i
                break
    else:
        for i in range(low, high + 1):
            if i % a == 0:
                b = i
                break
    return b, b + a - 1

minl, minh, maxl, maxh = 2, 2, 2, 2
for a in A[::-1]:
    minl, minh = filt(a, minl, minh, -1)
    maxl, maxh = filt(a, maxl, maxh, 1)
    if -1 in (minl, minh, maxl, maxh):
        print(-1)
        exit()

print(minl, maxh)

Submission status: Wrong Answer

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

mina = maxa = 2

for a in A[::-1]:
  if -(-mina // a) == 0 or maxa // a == 0:
    print(-1)
    break
  mina = -(-mina // a) * a
  maxa = maxa // a * a + a - 1
else:
  print(mina, maxa)

Submission status: Wrong Answer

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

mina = maxa = 2

for a in A[::-1]:
  if maxa // a == 0:
    print(-1)
    break
  mina = -(-mina // a) * a
  maxa = maxa // a * a + a - 1
else:
  print(mina, maxa)

Submission status: Wrong Answer

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

ans = 2

for i in range(K-1, 0, -1):
  ans = (ans + A[i] - 1) // A[i-1] * A[i-1]

t = ans
for a in A:
  t = t // a * a

if t == 2:
  print(ans, ans + A[0] - 1)
else:
  print(-1)

Submission status: Wrong Answer

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

ans = 2

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

for i in range(K-1, 0, -1):
  ans = (ans + A[i] - 1) // A[i-1] * A[i-1]
  if ans == 0:
    print(-1)
    exit()
print(ans, ans + A[0] - 1)

Submission status: Wrong Answer

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

lower = 2
upper = 2
flag = True
for i in range(k):
    lowm = lower//arr[i]
    upm = upper//arr[i]

    if upm == 0:
        flag = False
    if arr[i] * lowm < lower:
        lowm += 1
    lower = arr[i] * lowm
    upper = arr[i] * upm + arr[i]-1
    # print(lowm,upm)
    # print(lower,upper)
    # print("##########")



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

Submission status: Wrong Answer

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

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

k = inn()
a = inl()
if k==1:
    if a[0]==2:
        print("2 3")
    else:
        print(-1)
    exit()
l = r = 2
for i in range(k-1,0,-1):
    mn = ((l+a[i-1]-1)//a[i-1])*a[i-1]
    mx = ((r+a[i]-1)//a[i-1])*a[i-1]
    if mn>mx:
        print(-1)
        exit()
    l = mn
    r = mx
print("{} {}".format(l,r+a[0]-1))

Submission status: Wrong Answer

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

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

k = inn()
a = inl()
l = r = 2
for i in range(k-1,0,-1):
    mn = ((l+a[i-1]-1)//a[i-1])*a[i-1]
    mx = ((r+a[i]-1)//a[i-1])*a[i-1]
    if mn>mx:
        print(-1)
        exit()
    l = mn
    r = mx
print("{} {}".format(l,r+a[0]-1))

Submission status: Wrong Answer

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

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

def setrlim():
  sys.setrecursionlimit(250000)
  soft,hard = resource.getrlimit(resource.RLIMIT_STACK)
  # setrlimit works on ubuntu (and atcoder), but not on WSL
  resource.setrlimit(resource.RLIMIT_STACK, (128*1024*1024,hard))

def dfsx(k,b):  # b=b[k], find b[k-1]
    ddprint("dfsx k {} b {}".format(k,b))
    if k==0:
        return [b+a[0]-1]  # assume b=p*a[0]
    mx = ((b+a[k]-1)//a[k-1])*a[k-1]
    for i in range(mx,b-1,-a[k-1]):
        ls = dfsx(k-1,i)
        ddprint("dfsx k-1 {} i {} rtn {}".format(k-1,i,ls))
        if ls != -1:
            ls.append(i)
            return ls
    return -1

def dfsn(k,b):  # b=b[k], find b[k-1]
    ddprint("dfsn k {} b {}".format(k,b))
    if k==0:
        return [b]  # assume b=p*a[0]
    mn = ((b+a[k-1]-1)//a[k-1])*a[k-1]
    for i in range(mn,b+a[k],a[k-1]):
        ls = dfsn(k-1,i)
        ddprint("dfsn k-1 {} i {} rtn {}".format(k-1,i,ls))
        if ls != -1:
            ls.append(i)
            return ls
    return -1

setrlim()
k = inn()
a = inl()
mn = dfsn(k-1,2)
if mn == -1:
    print(-1)
    exit()
ddprint(" - - - - - - - -")
mx = dfsx(k-1,2)
print("{} {}".format(mn[0],mx[0]))

Submission status: Wrong Answer

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

A = A[::-1]
answer = (2, 2)
#print("answer:", answer)

for a in A:
  min_ans, max_ans = answer

  min_ans = -(-min_ans//a)
  max_ans = max_ans//a
  if max_ans == 0:
    print(-1)
    exit()

  min_ans *= a
  max_ans *= a
  max_ans += a-1
  
  answer = (min_ans, max_ans)
  #print("answer:", answer)
  
print(*answer)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline

def main():
    K = int(input())
    A = list(map(int,input().split()))
    
    L = [1]
    for i in range(K):
        if L[-1] != A[-i-1]:
            L.append(A[-i-1])
    
    L.pop(0)
    L_long = len(L)
    ans = [2,3]
    for i in range(L_long):
        s,t = ans[0],ans[1]
        ans[0] = -(-s//L[i])*L[i]
        ans[1] = (t//L[i] + 1)*L[i] - 1
        if ans[1] < ans[0]:
            print(-1)
            exit()
    
    print(ans[0],ans[1])
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline

def main():
    K = int(input())
    A = list(map(int,input().split()))
    
    L = [1]
    for i in range(K):
        if L[-1] != A[-i-1]:
            L.append(A[-i-1])
    
    L.pop(0)
    L_long = len(L)
    ans = [2,3]
    for i in range(L_long):
        s,t = ans[0],ans[1]
        if (s//L[i]*L[i] < s and t < (s//L[i]+1)*L[i]):
            print(-1)
            exit()
        else:
            ans[0] = -(-s//L[i])*L[i]
            ans[1] = (t//L[i] + 1)*L[i] - 1
    
    print(ans[0],ans[1])
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline

def main():
    K = int(input())
    A = list(map(int,input().split()))
    
    L = [1]
    for i in range(K):
        if L[-1] != A[-i-1]:
            L.append(A[-i-1])
    
    L.pop(0)
    L_long = len(L)
    ans = [2,3]
    for i in range(L_long):
        s,t = ans[0],ans[1]
        if L[i] > t:
            print(-1)
            exit()
        else:
            ans[0] = -(-s//L[i])*L[i]
            ans[1] = (t//L[i] + 1)*L[i] - 1
    
    print(ans[0],ans[1])
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
input = sys.stdin.buffer.readline

def main():
    K = int(input())
    A = list(map(int,input().split()))
    
    L = [1]
    for i in range(K):
        if A[-i-1] > L[-1] + 1:
            print("-1")
            exit()
        if L[-1] != A[-i-1]:
            L.append(A[-i-1])
    
    L.pop(0)
    L_long = len(L)
    ans = [2,3]
    for i in range(L_long):
        s,t = ans[0],ans[1]
        ans[0] = -(-s//L[i])*L[i]
        ans[1] = (t//L[i] + 1)*L[i] - 1
    
    print(ans[0],ans[1])
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def examA():
    N, A, B = LI()
    if (A-B)%2==0:
        ans = "Alice"
    else:
        ans = "Borys"
    print(ans)
    return

def examB():
    K = I()
    A = LI()
    cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if A[i]>cur:
            print(-1)
            exit()
        cur = (cur//a+1)*a-1
#        print(cur)
    maxA = cur; cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if cur<=a:
            cur = a
        else:
            cur = a*((cur-1)//a+1)
    minA = cur
    print(minA,maxA)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Submission status: Wrong Answer

Solution code:
def examA():
    N, A, B = LI()
    if (A-B)%2==0:
        ans = "Alice"
    else:
        ans = "Borys"
    print(ans)
    return

def examB():
    K = I()
    A = LI()
    cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if A[i]>cur:
            print(-1)
            exit()
        cur = (cur//a+1)*a-1
#        print(cur)
    maxA = cur; cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if cur<=a:
            cur = a
        else:
            cur = a*(cur//a+1)
    minA = cur
    print(minA,maxA)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Submission status: Wrong Answer

Solution code:
def examA():
    N, A, B = LI()
    if (A-B)%2==0:
        ans = "Alice"
    else:
        ans = "Borys"
    print(ans)
    return

def examB():
    K = I()
    A = LI()
    cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if A[i]>=2*cur:
            print(-1)
            exit()
        cur = (cur//a+1)*a-1
    maxA = cur; cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if cur<=a:
            cur = a
        else:
            cur = a*(cur//a+1)
    minA = cur
    print(minA,maxA)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Submission status: Wrong Answer

Solution code:
def examA():
    N, A, B = LI()
    if (A-B)%2==0:
        ans = "Alice"
    else:
        ans = "Borys"
    print(ans)
    return

def examB():
    K = I()
    A = LI()
    cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        if A[i]>=2*A[i-1]:
            print(-1)
            exit()
        elif cur<=a:
            cur = a
        else:
            cur = a*(cur//a+1)
    minA = cur; cur = 2
    for i in range(K-1,-1,-1):
        a = A[i]
        cur = (cur//a+1)*a-1
    maxA = cur
    print(minA,maxA)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()

Submission status: Wrong Answer

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

def solve() :
    if A[-1] != 2 :
        return [-1]
    for i in range(K - 1) :
        if A[i] >= 2 * A[i+1] :
            return [-1]
            
    cM = 2
    for a in A[::-1] :
        nM = cM // a * a + a - 1
        cM = nM
    
    return [cM - cM % A[0], cM]
    
print(*solve())

Submission status: Wrong Answer

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

def solve() :
    for i in range(K - 1) :
        if A[i] >= 2 * A[i+1] :
            return [-1]
            
    cM = 2
    for a in A[::-1] :
        nM = cM // a * a + a - 1
        cM = nM
    
    return [cM - cM % A[0], cM]
    
print(*solve())

Submission status: Wrong Answer

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

def solve() :
    m, M = 2, 2
    for a in A[::-1] :
        x = (2 * M - 1) // a
        if a * x < M :
            return [-1]
        M = a * x
      
    return [M, M + A[0] - 1]
    
print(*solve())

Submission status: Wrong Answer

Solution code:
k=int(input())
a=list(map(int,input().split()))
m=2
M=2
for i in range(k-1,-1,-1):
    x=a[i]
    f=1
    for j in range(1,1001):
        if m<=x*j<=M:
            f=0
            break
    if f:
        print(-1)
        exit()
    m=(m+x-1)//x*x
    M=M//x*x+x-1
print(m,M)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=list(map(int,input().split()))
m=2
M=2
for i in range(k-1,-1,-1):
    x=a[i]
    f=1
    for j in range(1,101):
        if m<=x*j<=M:
            f=0
            break
    if f:
        print(-1)
        exit()
    m=(m+x-1)//x*x
    M=M//x*x+x-1
print(m,M)

Submission status: Wrong Answer

Solution code:
k=int(input())
l=list(map(int,input().split()))
nowmax=2
nowmin=2
for i in range(k):
  num=l[-1-i]
  if nowmax-nowmin<num and nowmax%num>nowmin%num and not(nowmax%num==0 or nowmin%num==0):
    print(-1)
    exit()
  else:
    nowmax,nowmin=(nowmax//num)*num+num-1,(((nowmin-1)//num)+1)*num
print(nowmin,nowmax)

Submission status: Wrong Answer

Solution code:
k=int(input())
l=list(map(int,input().split()))
nowmax=2
nowmin=2
for i in range(k):
  num=l[-1-i]
  if num>nowmax:
    print(-1)
    exit()
  elif nowmax-nowmin<num and nowmax%num>nowmin%num:
    print(-1)
    exit()
  else:
    nowmax,nowmin=(nowmax//num)*num+num-1,(((nowmin-1)//num)+1)*num
print(nowmin,nowmax)

Submission status: Wrong Answer

Solution code:
k=int(input())
l=list(map(int,input().split()))
nowmax=2
nowmin=2
for i in range(k):
  num=l[-1-i]
  if num>nowmax:
    print(-1)
    exit()
  else:
    nowmax,nowmin=(nowmax//num)*num+num-1,(((nowmin-1)//num)+1)*num
print(nowmin,nowmax)

Submission status: Wrong Answer

Solution code:
k=int(input())
l=list(map(int,input().split()))
nowmax=2
nowmin=2
for i in range(k):
  num=l[-1-i]
  if num>nowmax:
    print(-1)
    exit()
  else:
    nowmax,nowmin=(nowmax//num)*num+num-1,(nowmax//num)*num
print(nowmin,nowmax)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
x = a[-1]
y = 3
if x != 2:
  print(-1)
  exit(0)
for i in range(N - 2, -1, -1):
  p = a[i]
  t = -(-x // p)
  x = max(t * p, x)
  y = max((t + 1) * p - 1, y)
t = x + 0
for i in range(N):
  t -= t % a[i]
if t == 2:
  print(x, y)
else: print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
x = a[-1]
y = 3
if x != 2:
  print(-1)
  exit(0)
for i in range(N - 2, -1, -1):
  p = a[i]
  t = -(-x // p)
  x = t * p
  y = max((t + 1) * p - 1, y)
t = x + 0
for i in range(N):
  t -= t % a[i]
if t == 2:
  print(x, y)
else: print(-1)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
x = a[-1]
y = 3
if x != 2:
  print(-1)
  exit(0)
for i in range(N - 2, -1, -1):
  p = a[i]
  t = -(-x // p)
  x = t * p
  y = (t + 1) * p - 1
t = x + 0
for i in range(N):
  t -= t % a[i]
if t == 2:
  print(x, y)
else: print(-1)

Submission status: Wrong Answer

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

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

mi, ma = 2, 2

for i in range(K):
    if ma < ((mi + A[i] - 1) // A[i]) * A[i]:
        print(-1)
        exit()
    mi = ((mi + A[i] - 1) // A[i]) * A[i]
    ma = ((ma // A[i]) + 1) * A[i] - 1

print(mi, ma)

Submission status: Wrong Answer

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

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

cntMin, cntMax = 1, 2

for i in range(1, K):
    if cntMax * A[i - 1] <= A[i]:
        print(-1)
        exit()
    cntMin = (cntMin * A[i - 1] + A[i] - 1) // A[i]
    cntMax = (cntMax * A[i - 1] + A[i] - 1) // A[i]

print(cntMin * A[-1], cntMax * A[-1] - 1)

Submission status: Wrong Answer

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

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

cntMin, cntMax = 1, 2

for i in range(1, K):
    if cntMax * A[i - 1] <= A[i]:
        print(-1)
        exit()
    cntMin = max(1, (cntMin * A[i - 1] + A[i] - 1) // A[i])
    cntMax = (cntMax * A[i - 1] + A[i] - 1) // A[i]

print(cntMin * A[-1], cntMax * A[-1] - 1)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))
l, r = 0, 10 ** 9
while r - l > 1:
    m = (l + r) // 2
    t = m
    for x in a:
        m = m // x * x
    if m <= 2:
        l = t
    else:
        r = t
l2, r2 = 0, 10 ** 9
while r2 - l2 > 1:
    m = (l2 + r2) // 2
    t = m
    for x in a:
        m = m // x * x
    if m < 2:
        l2 = t
    else:
        r2 = t
if l < r2:
    print(-1)
else:
    print(r2, l)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
N, n = 2, 2
k = [0, 0]
for i in reversed(range(K)):
    k[0] = (N // A[i])*A[i]
    k[1] = math.ceil(n / A[i]) * A[i]
    if k[0]*A[i] >= n:
        N = k[0]+A[i] - 1
        n = k[1]
    else:
        print(-1)
        exit(0)
print(n, N)

Submission status: Wrong Answer

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

A.reverse()
N = [2]
able = True

for i in range(K - 1):
  N.append(((N[i] - 1) // A[i + 1]) * A[i + 1] + A[i + 1])
  if (N[i + 1] // A[i]) * A[i] != N[i]:
    able = False
    break

maximum = N[K - 1] + A[K - 1] - 1 if able else 0
minimum = N[K - 1] if able else 0

if able:
  print(str(minimum) + ' ' + str(maximum))
else:
  print(-1)

Submission status: Wrong Answer

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

ans1 = 2
ans2 = 2
for i in range(K - 1, 0, -1):
    if ans1 % A[i] != 0 or ans2 % A[i] != 0 or ans1 < 2 or ans2 < 2:
        print (-1)
        exit()
    ans1 = (ans1 + A[i] - 1) // A[i - 1] * A[i - 1] #最大
    ans2 = (ans2 + A[i - 1] - 1) // A[i - 1] * A[i - 1]
    if ans2 > ans1:
        ans2 = ans1
    if ans2 == 0:
        ans2 = ans1

    # print (ans1, ans2)

if ans1 % A[0] != 0 or ans2 % A[0] != 0 or ans1 < 2 or ans2 < 2:
    print (-1)
    exit()

print (ans2, ans1 + A[0] - 1)

Submission status: Wrong Answer

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

ans1 = 2
ans2 = 2
for i in range(K - 1, 0, -1):
    if ans1 % A[i] != 0 or ans2 % A[i] != 0 or ans1 < 2 or ans2 < 2:
        print (-1)
        exit()
    ans1 = (ans1 + A[i] - 1) // A[i - 1] * A[i - 1] #最大
    ans2 = (ans2 + A[i - 1] - 1) // A[i - 1] * A[i - 1]
    if ans2 > ans1:
        ans2 = ans1
    if ans2 == 0:
        ans2 = ans1
        
    # print (ans1, ans2)

if ans1 % A[0] != 0 or ans2 % A[0] != 0:
    print (-1)
    exit()

print (ans2, ans1 + A[0] - 1)

Submission status: Wrong Answer

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

ans1 = 2
ans2 = 2
for i in range(K - 1, 0, -1):
    if ans1 % A[i] != 0 or ans2 % A[i] != 0 or ans1 < 2 or ans2 < 2:
        print (-1)
        exit()
    ans1 = (ans1 + A[i] - 1) // A[i - 1] * A[i - 1] #最大
    ans2 = (ans2 + A[i - 1] - 1) // A[i - 1] * A[i - 1]
    if ans2 > ans1:
        ans2 = ans1
    
    # print (ans1, ans2)

if ans1 % A[0] != 0 or ans2 % A[0] != 0:
    print (-1)
    exit()

print (ans2, ans1 + A[0] - 1)

Submission status: Wrong Answer

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

c=2
C=2
for i in reversed(range(1,K)):
  a=A[i-1]
  b=A[i]
  if c%a==0:
    nc=c
  else:
    nc=c-c%a+a
  nC=C+b-1-(C+b-1)%a
  if c>C:
    print(-1)
    exit()
  c=nc
  C=nC


print(c,C+A[0]-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
chk=2
x=a[0]
if a[-1]!=2:
    print(-1)
    exit()
elif k==1:
    print(2,3)
    exit()
for i in range(k-1,-1,-1):
    if a[i]>=chk*2:
        print(-1)
        exit()
    if a[i]<chk and chk%a[i]>0:
        a[i]=(a[i]+chk)//a[i]*a[i]
    if a[i]<chk and chk%a[i]==0:
        a[i]=chk
    chk=a[i]
ans=[a[0],a[1]*2+2]
while ans[1]-ans[0]>1:
    t=sum(ans)//2
    if t-(t%x)>=a[1]*2:
        ans[1]=t
    else:
        ans[0]=t
print(a[0], ans[0])

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
chk=2
x=a[0]
if a[-1]!=2:
    print(-1)
    exit()
elif k==1:
    print(2,3)
    exit()
for i in range(k-1,-1,-1):
    if a[i]>=chk*2:
        print(-1)
        exit()
    if a[i]<chk:
        a[i]=(a[i]+chk)//a[i]*a[i]
    chk=a[i]
ans=[a[0],a[1]*2+2]
while ans[1]-ans[0]>1:
    t=sum(ans)//2
    if t-(t%x)>=a[1]*2:
        ans[1]=t
    else:
        ans[0]=t
print(a[0], ans[0])

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=a[0]
chk=2
if a[-1]!=2:
  print(-1)
  exit()
elif k==1 and a[0]==2:
  print(2,3)
  exit()
for i in range(k-1,-1,-1):
  if a[i]<chk:
    a[i]=(a[i]+chk)//a[i]*a[i]
  chk=a[i]
print(a[0],max(a[1 ]*2-1 ,a[0]+ans-1))

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=a[0]
chk=2
if a[-1]!=2:
  print(-1)
  exit()
elif k==1 and a[0]==2:
  print(2,3)
  exit()
for i in range(k-1,-1,-1):
  if a[i]>=chk*2:
    print(-1)
    exit()
  if a[i]<chk:
    a[i]=(a[i]+chk)//a[i]*a[i]
  chk=a[i]
print(a[0],max(a[1 ]*2-1 ,a[0]+ans-1))

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=a[0]
chk=2
if a[-1]!=2:
  print(-1)
  exit()
elif k==1 and a[0]==2:
  print(2,3)
  exit()
for i in range(k-1,-1,-1):
  if a[i]>=chk*2:
    print(-1)
    exit()
  if a[i]<chk:
    a[i]=(a[i]+chk)//a[i]*a[i]
  chk=a[i]
print(a[0],a[0]+ans-1)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=a[0]
chk=2
if a[-1]!=2:
  print(-1)
  exit()
elif k==1 and a[0]==2:
  print(2,3)
  exit()
for i in range(k-1,-1,-1):
  if a[i]>=chk*2:
    print(-1)
    exit()
  if a[i]<chk:
    a[i]=(a[i]+chk)//a[i]*a[i]-1
  chk=a[i]
print(a[0],a[0]+ans-1)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=a[0]
chk=2
if a[-1]!=2:
  print(-1)
  exit()
elif k==1 and a[0]==2:
  print(2,3)
  exit()
for i in range(k-1,-1,-1):
  if a[i]>=chk*2:
    print(-1)
    exit()
  if a[i]<chk:
    a[i]=(a[i]+chk*2)//a[i]*a[i]-1
  chk=a[i]
print(a[0],a[0]+ans,-1)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=0
chk=2
if a[-1]!=2:
  print(-1)
  exit()
elif k==1 and a[0]==2:
  print(2,3)
  exit()
for i in range(k-1,-1,-1):
  if a[i]>=chk*2:
    print(-1)
    exit()
  if a[i]<chk:
    a[i]=(a[i]+chk*2)//a[i]*a[i]-1
  chk=a[i]
print(a[0],a[1]*2-1)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=0
chk=2
if a[-1]!=2:
  print(-1)
  exit()
elif k==1 and a[0]==2:
  print(2,3)
  exit()
for i in range(k-1,-1,-1):
  if a[i]>=chk*2:
    print(-1)
    exit()
  if a[i]<chk:
    a[i]=(a[i]+chk)//a[i]*a[i]
    chk=a[i]
print(a[0],a[1]*2-1)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=0
chk=2
if a[-1]!=2:
  print(-1)
  exit()
elif k==1 and a[0]==2:
  print(2,2)
  exit()
for i in range(k-1,-1,-1):
  if a[i]>=chk*2:
    print(-1)
    exit()
  if a[i]<chk:
    a[i]=(a[i]+chk)//a[i]*a[i]
    chk=a[i]
print(a[0],a[1]*2-1)

Submission status: Wrong Answer

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


MIN=2
MAX=2

for a in A[::-1]:
    MIN=math.ceil(MIN/a)*a
    MAX=(math.ceil(MIN/a)+1)*a-1

    #print(MIN,MAX)
    
M1=MIN
M2=MAX

for a in A:
    M1=M1-M1%a
    M2=M2-M2%a

if M1==M2==2:
    print(MIN,MAX)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
k = int(input())
a = list(map(int, input().split( )))
"""
1ラウンド目の脱落数以外に違いが生じない
そんなことはなかった
"""

if a[-1]!=2:
    print(-1)
    sys.exit()
sup = 2
mn = 2
for i in range(k-1,0,-1):
    
    tmp = mn//a[i-1]
    if tmp*a[i-1]<mn:
        tmp += 1
    mn2 = tmp*a[i-1]
    if (mn2//a[i])*a[i]>mn:
        print(-1)
        sys.exit()
    
    tmp = sup//a[i-1]
    sup2 = tmp*a[i-1]
    
    mn = mn2
    sup = max(sup2,mn)+a[i-1]-1
print(mn,sup)

Submission status: Wrong Answer

Solution code:
import sys
k = int(input())
a = list(map(int, input().split( )))
"""
1ラウンド目の脱落数以外に違いが生じない
"""

if a[-1]!=2:
    print(-1)
    sys.exit()
cnt = 2
for i in range(k-1,0,-1):
    tmp = cnt//a[i-1]
    if tmp*a[i-1]<cnt:
        tmp += 1
    cnt2 = tmp*a[i-1]
    if (cnt2//a[i])*a[i]>cnt:
        print(-1)
        sys.exit()
    cnt = cnt2
print(cnt,cnt+a[0]-1)

Submission status: Wrong Answer

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

l, r = 2, 3
ans = (-1,)
for x in reversed(a):
    l = ((l + x - 1) // x) * x
    # print(x, l, r)
    if r <= l:
        break
    r = max(l + x, r)
else:
    ans = (l, r - 1)
print(*ans)