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: Runtime Error

Solution code:
import sys

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


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

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


if __name__ == '__main__':
    resolve()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def resolve():
    # from collections import deque
    k = int(input())
    a = list(map(int, input().split()))

    ra = a[::-1]
    now = [2]
    for i in range(k-1):
        nxt = []
        for j in range(len(now)):
            test = now[j]
            nxtd = ra[i+1]
            if test % ra[i] == 0:
                mod = test % nxtd
                if (nxtd-mod)%nxtd < ra[i]:
                    for k in range((nxtd-mod)%nxtd, ra[i], nxtd):
                        nxt.append(k+test)

        if not nxt:
            print(-1)
            exit()
        now = nxt
    now = sorted(list(now))
    ans = []
    for i in now:
        test = i
        if test % ra[-1] == 0:
            ans.append(i)
            ans.append(i+ra[-1]-1)
    ans = sorted(ans)
    print("{} {}".format(ans[0], ans[-1]))
resolve()

Submission status: Runtime Error

Solution code:
K=int(input())
A=list(map(int,input().split()))
mb=Mb=2
t=1
for i in A[::-1]:
    if Mb//i*i>=mb:
        Ma=(Mb//i+1)*i-1
    else:
        t=0
    if mb%i==0:
        ma=mb
    elif (mb//i+1)*i<=Mb:
        ma=(mb//i+1)*i
    else:
        t=0
    mb=ma
    Mb=Ma
if t:
    print(ma,Ma)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    else:
        if miN%A[i]==0:
            pass
        else:
            miN=(miN//A[i] +1) *A[i]
    maX=maX-max%A[i] + A[i]-1
print(miN,maX)

Submission status: Runtime Error

Solution code:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2:
        print(unko)
    if A[i]//miN>=2:
        miN=A[i]
    if miN%A[i]==0:
        pass
    else:
        miN=(miN//A[i] +1) *A[i]
    maX=(maX//A[i]) *A[i] + A[i]-1
print(miN,maX)

Submission status: Runtime Error

Solution code:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2
Amax=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2 or i<K-1 and A[i]>(maX//A[i+1])*A[i+1]+maX%A[i+1]:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    if miN%A[i]==0:
        pass
    else:
        miN=(miN//A[i] +1) *A[i]

    if maX%A[i]==0:
        maX=min((maX//A[i]) *A[i] + A[i]-1 ,(maX//A[i+1])*A[i+1]+maX%A[i+1])
    else:
        maX=min((maX//A[i]) *A[i] + A[i]-1 ,(maX//A[i+1])*A[i+1]+maX%A[i+1])
    Amax=max(A[i],Amax)

print(miN,maX)

Submission status: Runtime Error

Solution code:
# input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import copy
K=int(input())
A=list(map(int,input().split()))
if A[-1]!=2:
    print(-1)
    exit()

maX=2
miN=2
Amax=2

for i in range(K-1,-1,-1):

    if A[i]//maX>=2 or A[i]>(maX//A[i+1])*A[i+1]+maX%A[i+1]:
        print(-1)
        exit()
    if A[i]//miN>=2:
        miN=A[i]
    if miN%A[i]==0:
        pass
    else:
        miN=(miN//A[i] +1) *A[i]

    if maX%A[i]==0:
        maX=(maX//A[i]) *A[i] + A[i]-1
    else:
        maX=(maX//A[i]) *A[i] + A[i]-1
    Amax=max(A[i],Amax)

print(miN,maX)

Submission status: Runtime Error

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

def solve() :
    A.pop()

    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: Runtime Error

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

A.pop()

m, M = 2, 2
for a in A[::-1] :
    x = (2 * M - 1) // a
    M = a * x
  
if M >= 2 :
    print(M, M + A[0] - 1)
else :
    print(-1)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
chk=2
if a[-1]!=2:
    print(-1)
    exit()
else:
    for i in range(n-1,0,-1):
        if a[i-1]>=a[i]*2:
            print(-1)
            exit()
    print(chk[2])

Submission status: Runtime Error

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
chk=2
if a[-1]!=2:
    print(-1)
    exit()
else:
    print(chk[2])

Submission status: Runtime Error

Solution code:
k=int(input())
a=[int0(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[0]+a[1]*2)//a[0]*a[0]-1)

Submission status: Runtime Error

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(n-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: Runtime Error

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(n-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: Runtime Error

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
ans=0
chk=0
if a[-1]!=2:
    print(-1)
else:
    print(ans[1])

Submission status: Runtime Error

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

# 切り上げ
def ceil(a, b):
    return -(-a//b)

# [a, b) に含まれるcの倍数のうち最小,最大のものを返す
def query(a, b, c):
    l = c * ceil(a, c)
    r = c * (ceil(b, c) - 1)
    if l <= r:
        return True, l, r
    else:
        return False, -1, -1

cand = [2,2]
for i in range(K):
    s, m = cand
    cand = []
    fs, ls, rs = query(s, s+A[i], A[i+1])
    fm, lm, rm = query(m, m+A[i], A[i+1])
    if fs:
        cand.append(ls)
    if fm:
        cand.append(rm)
    if len(cand) == 0:
        print(-1)
        exit()

s, m = cand
print(s, m)

Submission status: Runtime Error

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

# 切り上げ
def ceil(a, b):
    return -(-a//b)

# [a, b) に含まれるcの倍数のうち最小,最大のものを返す
def query(a, b, c):
    l = c * ceil(a, c)
    r = c * (ceil(b, c) - 1)
    if l <= r:
        return True, l, r
    else:
        return False, -1, -1

cand = [2,2]
for i in range(K):
    if len(cand) == 0:
        print(-1)
        exit()
    s, m = cand
    cand = []
    fs, ls, rs = query(s, s+A[i], A[i+1])
    fm, lm, rm = query(m, s+A[i], A[i+1])
    if fs:
        cand.append(ls)
    if fm:
        cand.append(rm)

if len(cand) == 0:
    print(-1)
else:
    print(cand[0], cand[-1])

Submission status: Runtime Error

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

for i in range(K-2,-1,-1):
  if A[i] >= A[i+1]*2:
    print(-1)
    exit()
  elif A[i] >= A[i+1]:
    maxn = A[i]
    minn = A[i]
  else:
    maxn = ((A[i+1]*2-1)//A[i])*A[i]
    minn = (A[i+1]//A[i]+1)*A[i]
maxn += A[0]-1
print(minn,maxn)

Submission status: Runtime Error

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

M = 2
L = 2
ok = True
for i in range(K-1, 0, -1):
    a, b = A[i], A[i-1]
    nM = (M//b)*b
    if M%b != 0:
        nM += b
    if nM >= M + a:
        ok = False
        break
    
    nL = (L+a-1)//b * b
    L, M = nL, nM

if not ok:
    print(-1)
else:
    L = L + b-1
    print(M, L)

Submission status: Runtime Error

Solution code:
k=int(input())
a=list(map(int,input().split()))
l,r=1,10**18
def f(x,a):
    for i in a:
        x=max(0,x-x%i)
    return x
while r-l>1:
    t=(l+r)//2
    if f(t,a)>2:
        r=t
    else:
        l=t
p,q=1,10**18
while q-p>1:
    t=(p+q)//2
    if f(t,a)<=1:
        p=t
    else:
        q=t
print(*(q,l) if q<=l else -1)

Submission status: Runtime Error

Solution code:
k=int(input())
a=list(map(int,input().split()))
l,r=1,10**18
def f(x,a):
    for i in a:
        x=x-x%i
    return x
while r-l>1:
    t=(l+r)//2
    if f(t,a)>2:
        r=t
    else:
        l=t
p,q=1,10**18
while q-p>1:
    t=(p+q)//2
    if f(t,a)<=1:
        p=t
    else:
        q=t
print(*(q,l) if q<=l else -1)

Submission status: Runtime Error

Solution code:
def solve(A):
    current_max = 2
    current_min = 2
    for a_k in reversed(A):
        if current_max < a_k:
            print('-1')
            return

        current_max = (current_max // a_k) * a_k + (a_k - 1)
        current_min = ((current_min - 1) // a_k + 1) * a_k

    print(f"{current_min} {current_max}")
    return


if __name__ == '__main__':
    K = int(input())
    A = list(map(int, input().split()))
    solve(A)

Submission status: Runtime Error

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

class lazy_eval_list(list):
    def __init__(self, func, a):
        super().__init__(a)
        self._func = func
        
    def __getitem__(self, key):
        return self._func(super().__getitem__(key))

lazy_winner_count_N = lazy_eval_list(winner_count, range(1,2+sum(A)))

import bisect
_min = bisect.bisect_left(lazy_winner_count_N, 2)
_max = bisect.bisect_right(lazy_winner_count_N, 2)-1

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

Submission status: Runtime Error

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

class lazy_eval_list(list):
    def __init__(self, func, a):
        super().__init__(a)
        self._func = func
        
    def __getitem__(self, key):
        return self._func(super().__getitem__(key))

lazy_winner_count_N = lazy_eval_list(winner_count, range(2+sum(A)))

# x = [winner_count(i) for i in range(2+sum(A))]

import bisect
_min = bisect.bisect_left(lazy_winner_count_N, 2)
_max = bisect.bisect_right(lazy_winner_count_N, 2) -1

if _min > _max:
    print(-1)
    exit()

print(_min, _max)

Submission status: Runtime Error

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

class lazy_eval_list(list):
    def __init__(self, func, a):
        super().__init__(a)
        self._func = func
        
    def __getitem__(self, key):
        return self._func(super().__getitem__(key))

lazy_winner_count_N = lazy_eval_list(winner_count, range(sum(A)))

import bisect
_min = bisect.bisect_left(lazy_winner_count_N, 2)
_max = bisect.bisect_right(lazy_winner_count_N, 2) -1

if _min > _max:
    print(-1)
    exit()

print(_min, _max)

Submission status: Runtime Error

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

A=A[::-1]

min_t_num=2
max_t_num=2

if A[0]==2:
    flg=True
    for i in range(1,K):
        prev_min=min_t_num
        prev_max=max_t_num
        min_t_num=(min_t_num//A[i]+1)*A[i]
        max_t_num=int(np.floor(max_t_num/A[i]))*A[i]+A[i]-1
        if A[i-1]*(min_t_num//A[i-1])!=prev_min or A[i-1]*(max_t_num//A[i-1])!=prev_max:
            flg=False
            break
    
    if flg:
        print(min_t_num,max_t_num)
    else:
        print(-1)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**6) 
 
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())

exist = True

# lower
for i, ai in enumerate(a[::-1]):
    if i == 0:
        if ai != 2:
            exist = False
            break
        else:
            upper = 3
            lower = 2
            
    else:
        exist = False
        for yi in range(lower, upper+1):
            if yi % ai == 0:
                lower = yi
                upper = lower+ai-1
                exist = True
                break
            
        if not exist:
            break
                
                
                
ans_lower = lower


# upper
for i, ai in enumerate(a[::-1]):
    if i == 0:
        if ai != 2:
            exist = False
            break
        else:
            upper = 3
            lower = 2
            
    else:
        exist = False
        for yi in range(upper, lower-1, -1):
            if yi % ai == 0:
                lower = yi
                upper = lower+ai-1
                exist = True
                break
            
        if not exist:
            break
                
    
ans_upper = upper

        
print(ans_lower, ans_upper) if exist else print(-1)

Submission status: Runtime Error

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

n=i1()
a=i2()
c=[]
if a[0]>=a[1]:
  c.append(a[0]*2-1)
  c.append(a[0])
else:
  d=a[1]//a[0]+1
  c.append(a[0]*d)
  c.append(a[0]*(d+1)-1)
s=min(c)
ss=0
for i in a:
  if s/i>=1:
     s=s-s%i
  else:
     ss=1

if ss==1:
   print(-1)
else:
   c.sort()
   print(*c)

Submission status: Runtime Error

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

n=i1()
a=i2()
c=[]
if a[0]>=a[1]:
  c.append(a[0]*2-1)
  c.append(a[0])
else:
  d=a[1]//a[0]+1
  c.append(a[0]*d)
  d=(a[0]*d)//a[1]+1
  c.append(a[1]*d)
s=min(c)
ss=0
for i in a:
  if s/i>=1:
     s=s-s%i
  else:
     ss=1

if ss==1:
   print(-1)
else:
   c.sort()
   print(*c)

Submission status: Runtime Error

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

n=i1()
a=i2()
c=[]
if a[0]>=a[1]:
  c.append(a[0]*2-1)
  c.append(a[0])
else:
  d=a[1]//a[0]+1
  c.append(a[0]*d)
  d=(a[0]*d)//a[1]+1
  c.append(a[1]*d)
s=0
for i in range(1,len(a))[::-1]:
  if a[i]*2<=a[i-1]:
    s=1

if s==1:
 print(-1)
else:
 c.sort()
 print(*c)

Submission status: Runtime Error

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:

Submission status: Runtime Error

Solution code:
from math import ceil
n=int(input())
l=list(map(int,input().split()))[::-1]
a=l[0]
ans=0
for i in range(1,len(l)):
    if 2*a<=l[i]:
        ans=-1
        break
    a=l[i]
if ans != -1:
    m= ceil(l[-2]/l[-1])*l[-1]
    M= (2*l[-2]-1)//l[-1]*l[-1]+l[-1]-1
    print(str(m)+' '+str(M))
else:
    print(-1)

Submission status: Runtime Error

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:
    bottom = minandmax(bottom,up+a[i]-1,a[i-1])[0]
    up = minandmax(bottom,up+a[i]-1,a[i-1])[1]
    if bottom == None and up == None:
        check = False
    elif bottom == None:
        bottom = up
    elif up == None:
        up = bottom
    i += -1

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: Runtime Error

Solution code:
f = open("data.txt", 'r')
file = f.read()
f.close()
lines = file.split("\n")
r = lines[1].split(" ")

serach_flag = True
old_mid = -1
min = 0
max = 10**9
mid = 0

low = -1
high = -1

while(serach_flag):
    mid = (min + max) / 2
    val = mid
    for k in r:
        val = val - (val % int(k))
    
    #print(min, mid, max, val)    
    if(val == 2):
        serach_flag = False
        break
        
    if(abs(mid - old_mid) < 1):
        break
    
    if(val == 0):    
        min = mid
    else:    
        max = mid

    old_mid = mid
    
#print(mid, serach_flag)


if(serach_flag == False):
    old_mid = -1
    low = mid
    high = mid

    minl = min
    maxl = mid
    midl = 0

    serach_flag = True  
    while(serach_flag):
        midl = (minl + maxl) / 2
        val = midl
        for k in r:
            val = val - (val % int(k))
        
        #print(minl, midl, maxl, val)
            
        if(abs(midl - old_mid) < 1):
            serach_flag = False
        
        if(val == 2):    
            maxl = midl
            low = midl
        else:
            minl = midl
        
        old_mid = midl
    #print(low, serach_flag)

    old_mid = -1
    minh = mid
    maxh = max
    midh = 0

    serach_flag = True   
    while(serach_flag):
        midh = (minh + maxh) / 2
        val = midh
        for k in r:
            val = val - (val % int(k))
        
        #print(minh, midh, maxh, val)

        if(abs(midh - old_mid) < 1):
            serach_flag = False
            
        if(val == 2):    
            minh = midh
            high = midh
        else:    
            maxh = midh
        
        old_mid = midh

    #print(high, serach_flag)    
    print(low, high) 
    
else:
    print(-1)

Submission status: Runtime Error

Solution code:
res = 0
if A[N - 1] != 2:
    res = -1
else:
    N_possible = [2,3]
    i = N - 2
    while i >= 0:
        #print(i,N_possible)
        N_new = []
        for n in N_possible:
            if n % A[i] == 0:
                temp = n / A[i]
                x = 0
                while x < A[i]:
                    N_new.append(temp * A[i] + x)
                    x += 1
        if N_new == []:
            res = - 1
            i = - 1
        else:
            N_possible = N_new
        i -= 1
if res == - 1:
    print(res)
else:
    a = int(min(N_possible))
    b = int(max(N_possible))
    print(a," ",b)

Submission status: Runtime Error

Solution code:
def find_min_candidates(i, Ni):
    if i < 0:
        return Ni
    if Ni % A[i] != 0 or (i+1 in invalid_memo and Ni in invalid_memo[i+1]):
        return -1
    for candidate in range(Ni, Ni+A[i]):
        res = find_min_candidates(i-1, candidate)
        if res > 0:
            return res
        else:
            if i not in invalid_memo:
                invalid_memo[i] = set()
            invalid_memo[i].add(candidate)
    return -1


def find_max_candidates(i, Ni):
    if i < 0:
        return Ni
    if Ni % A[i] != 0 or (i+1 in invalid_memo and Ni in invalid_memo[i+1]):
        return -1
    for candidate in range(Ni+A[i]-1, Ni-1, -1):
        res = find_max_candidates(i-1, candidate)
        if res > 0:
            return res
        else:
            if i not in invalid_memo:
                invalid_memo[i] = set()
            invalid_memo[i].add(candidate)
    return -1


def main():
    global A, invalid_memo
    K = int(input())
    A = list(map(int, input().split()))
    invalid_memo = {}
    min_n = find_min_candidates(K-1, 2)
    if min_n < 0:
        print(-1)
    else:
        max_n = find_max_candidates(K-1, 2)
        print(min_n, max_n)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

#
if A[-1]!=2:
    print(-1)
    exit()
if A[-2]!=2 and A[-2]!=3:
    print(-1)
    exit()

#
min_n = 2
max_n = 3
for i in A[::-1][1:]:
    a = (min_n - 1)//i
    b = max_n//i
    if a==b:
        print(-1)
        exit()

    if min_n%i==0:
        pass
    else:
        min_n = min_n + (i - min_n%i)
    max_n = max_n - max_n%i + i - 1
    #print(min_n, max_n)

#
print(min_n, max_n)

Submission status: Runtime Error

Solution code:
import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

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

for i in range(0,K-1):  # 0<=i<=K-2 A[K-2]は2ラウンドの組．Kラウンドから2ラウンドまで
    Round = list(range(jmin,jmax+1))
    if not(0 in Round % A[i]):
        print(-1)
        sys.exit()
    jmin = (int(jmin/A[i])+1)*A[i]
    jmax = (int(jmax/A[i]))*A[i] +A[i]-1

jmax = jmax + A[K-1] -1

print(jmin, jmax)

Submission status: Runtime Error

Solution code:
import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2
#print(A)

for h in range(0,K):
    if A[h] <= A[h+1]:
        print(-1)
        sys.exit()

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



for i in range(0,K-1):  # 0<=i<=K-2 A[K-2]は2ラウンドの組．Kラウンドから2ラウンドまで
    drop_num = []
    for j in range(0,A[i]):  #脱落者数の候補を入れていく
        if ( jmax + j ) % A[i+1] == 0:
            drop_num.append(j)
        if ( jmin + j ) % A[i+1] == 0:
            drop_num.append(j)
    if drop_num == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
        print(-1)
        sys.exit()
    max_drop = max(drop_num)
    jmax = jmax + max_drop
    min_drop = min(drop_num)
    jmin = jmin + min_drop


jmax = jmax + A[K-1] -1

print(jmin, jmax)

Submission status: Runtime Error

Solution code:
import math

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

kouho = []
for i in range(k+1+1):
    kouho.append(set())
# kouhoは、ラウンドiに臨んだ人の数
kouho[k+1].add(2)

# ラウンドi-1に参加した人数の候補は、
# kouho[i] +0,+1,,,,+ラウンドiのa -1。
# かつ、ラウンドi-2のa で割り切れること。
for i in range(k,1-1,-1):
    #各ラウンドへの参加候補数を上げる。
    for x in kouho[i+1]:
        #最大
        kouho[i].add(int((x*2-1)/a[i-1]) * a[i-1])
        #最小
        if int(x/a[i-1] +1) * a[i-1] < x*2:
            kouho[i].add(math.ceil(x/a[i-1]) * a[i-1])

    tmp = set()
    tmp.add(max(kouho[i]))
    tmp.add(min(kouho[i]))
    kouho[i] = kouho[i] & tmp
    #print(i, kouho[i])

if len(kouho[1]) > 0:
    maxk = max(kouho[1])+a[0]-1
    mink = min(kouho[1])
    print(mink, maxk)
else:
    print(-1)

Submission status: Runtime Error

Solution code:
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

input()
test=input().split(" ")
test=list(map(int, test))

suma=1
for i in test:
	suma *= i
test1 = prime_decomposition(suma)
test1 = list(set(test1))

minn=1
for i in test1:
	minn *= i


maxi = minn + test[0]-1 

temp = minn
for i in test:
	temp = temp- (temp%i)

if temp!=2:
	print(-1)
else:
	print(str(minn)+" "+str(maxi))

Submission status: Runtime Error

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


if A[K - 1] != 2:
    ans = -1

else:
    for i in reversed(range(K - 1)):
        if A[i] >= A[i + 1] * 2:
            ans = -1
            break
        elif A[i] >= A[i + 1]:
            ans = A[i]
        elif A[i] < A[i + 1]:
            ans = A[i] * ((A[i + 1] % A[i]) + 1)

        ans_max = max(ans, ans_max) + A[i] - 1
    
    if ans != -1:
        ans = '{} {}'.format(ans, ans_max)

    print(ans)

Submission status: Runtime Error

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


if A[K - 1] != 2:
    ans = -1

else:
    for i in reversed(range(K - 1)):
        if A[i] >= A[i + 1] * 2:
            ans = -1
            break
        elif A[i] >= A[i + 1]:
            ans = A[i]
        elif A[i] < A[i + 1]:
            ans = A[i] * ((A[i + 1] % A[i]) + 1)

    if ans != -1:
        ans_max = ans + A[0] - 1
        ans = '{} {}'.format(ans, ans_max)

    print(ans)

Submission status: Runtime Error

Solution code:
# -- coding: utf-8 --
from math import ceil
round_no = int(input())
args = list(map(int, input().split(' ')))[::-1]
cand_min = 3
if args[0] == 2 and args[1] <= 3:
    for i in range(2, round_no):
        if args[i-1] <= args[i] <= 2 + 2 ** i:
            cand_min = args[i]
        elif args[i-1] > args[i]:
            cand_min = ceil(cand_min/args[i]) * args[i]
        else:
            cand_min = -1
            break

else:
    cand_min = -1


if cand_min == -1:
    print(cand_min)
else:
    cand_max = cand_min + args[-1] - 1
    print(str(cand_min) + ' ' + str(cand_max))

Submission status: Runtime Error

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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

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 pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-2,-1,-1):
        t = a[i]
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b += t-b%t
        else:
            b = t
        if c % t == 0:
            pass
        elif c > t:
            c += t-c%t
        else:
            return -1
    bb = b
    cc = c-1
    for i in range(n):
        bb -= bb%a[i]
        cc -= cc%a[i]
    if bb != 2:
        return 1 / 0
    if cc != 2:
        while 1:
            cc += 1

    return '{} {}'.format(b, c-1)

print(main())

Submission status: Runtime Error

Solution code:
#! /usr/bin/env python
# coding: utf-8

import numpy as np

def slove(k, a):
    a = np.array(a, dtype=np.int64)
    if a[-1] > 3 or a[-2] > 3:
        return -1

    diff = a[:-1] - (2*a[1:])

    if (diff >= 0).any():
        return -1

    minNum = a[0]
    while (minNum < a.max()):
        minNum += minNum

    maxNum = minNum + a[0] - 1

    return ("{0} {1}".format(minNum, maxNum))


if __name__ == "__main__":
    k = int(input())
    a = input().split(" ")

    print(slove(k, a))