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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Possible = A[-1]
for i in reversed(range(N-1)):
    if Possible % A[i] == 0: Possible = A[i]
    elif A[i] - Possible % A[i] < A[i+1]:
        Possible += A[i] - Possible % A[i]
    else:
        print(-1)
        break
else:
    print(Possible, Possible + A[0] - 1)

Submission status: Wrong Answer

Solution code:
import sys

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

def sim(x):
	for i in range(k):
		x -= x % b[i]
	if x == 2:
		return True
	else:
		return False

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

i = 1
ok = False
while i < 5000:
	if sim(i * b[0]):
		ok = True
		ans_min = i * b[0]
		break
	i += 1

if not ok:
	print(-1)
	sys.exit()

i = 2
ok = False
while i < 5000:
	if sim(i * b[0] - 1):
		ok = True
		ans_max = i * b[0] - 1
		break
	i += 1

if not ok:
	print(-1)
	sys.exit()

print(ans_min, ans_max)

Submission status: Wrong Answer

Solution code:
import sys

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

def sim(x):
	for i in range(k):
		x -= x % b[i]
	if x == 2:
		return True
	else:
		return False

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

i = 1
ok = False
while i < 1000:
	if sim(i * b[0]):
		ok = True
		ans_min = i * b[0]
		break
	i += 1

if not ok:
	print(-1)
	sys.exit()

i = 2
ok = False
while i < 1000:
	if sim(i * b[0] - 1):
		ok = True
		ans_max = i * b[0] - 1
		break
	i += 1

if not ok:
	print(-1)
	sys.exit()

print(ans_min, ans_max)

Submission status: Wrong Answer

Solution code:
import sys

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

def sim(x):
	for i in range(k):
		x -= x % b[i]
	if x == 2:
		return True
	else:
		return False

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

i = 1
ok = False
while i < 1000:
	if sim(i * b[0]):
		ok = True
		ans_min = i * b[0]
		break
	i += 1

if not ok:
	print(-1)
	sys.exit()

i = 2
ok = False
while i < 1000:
	if sim(i * b[0] - 1):
		ok = True
		ans_max = i * b[0] - 1
		break
	i += 1

if not ok:
	print(-1)
	sys.exit()

print(ans_min, ans_max)

Submission status: Wrong Answer

Solution code:
import sys

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

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

ans_min = 2
for i in range(k-1):
	if ans_min % a[i+1] != 0:
		if a[i+1] - (ans_min % a[i+1]) >= a[i]:
			print(-1)
			sys.exit()
		else:
			ans_min = ans_min + a[i+1] - (ans_min % a[i+1])

ans_max = 2
for i in range(k-1):
	if (ans_max + a[i] - 1) % a[i+1] != 0:
		if (ans_max + a[i] - 1) % a[i+1] >= a[i]:
			print(-1)
			sys.exit()
	
	ans_max = ans_max + a[i] - 1 - ((ans_max + a[i] - 1) % a[i+1])
	#print(ans_max)

#print(ans_max)
ans_max = ans_max + a[k-1] - 1

print(ans_min, ans_max)

Submission status: Wrong Answer

Solution code:
import sys

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

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

ans_min = 2
for i in range(k-1):
	if ans_min % a[i+1] != 0:
		if a[i+1] - (ans_min % a[i+1]) >= a[i]:
			print(-1)
			sys.exit()
		else:
			ans_min = ans_min + a[i+1] - (ans_min % a[i+1])

ans_max = 2
for i in range(k-1):
	if (ans_max + a[i] - 1) % a[i+1] != 0:
		if (ans_max + a[i] - 1) % a[i+1] >= a[i]:
			print(-1)
			sys.exit()
	else:
		ans_max = ans_max + a[i] - 1 - ((ans_max + a[i] - 1) % a[i+1])
	#print(ans_max)

#print(ans_max)
ans_max = ans_max + a[k-1] - 1

print(ans_min, ans_max)

Submission status: Wrong Answer

Solution code:
import sys

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

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

ans_min = 2
for i in range(k-1):
	if ans_min % a[i+1] != 0:
		if a[i+1] - (ans_min % a[i+1]) >= a[i]:
			print(-1)
			sys.exit()
		else:
			ans_min = ans_min + a[i+1] - (ans_min % a[i+1])

ans_max = 2
for i in range(k-1):
	if (ans_max + a[i] - 1) % a[i+1] >= a[i]:
		print(-1)
		sys.exit()
	else:
		ans_max = ans_max + a[i] - 1 - ((ans_max + a[i] - 1) % a[i+1])

#print(ans_max)
ans_max = ans_max + a[k-1] - 1

print(ans_min, ans_max)

Submission status: Wrong Answer

Solution code:
import math
k = int(input())
a = list(map(int, input().split()))
MAX = 2
MIN = 2
for i in a[::-1]:
    if MAX >= i:
        MAX = i * (MAX // i) + (i-1)
        MIN = i * (math.ceil(MIN / i)) 
    else:
        print(-1)
        exit()
print(MIN,MAX)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))[::-1]
res = 2
lo,hi = 2,2

for i in A:
    if hi//i - (lo-1)//i != 0:
        res = ((lo-1) // i + 1) * i
    else:
        print(-1)
        exit()
    if res % i != 0:
        print(-1)
        exit()
    l = res // i
    # i*l から i*(l+1)-1 の間の次の
    lo,hi = i * l, i * (l + 1) - 1
print(lo,hi)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

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

a = a[::-1]
bmin = [a[0]]
bmax = [a[0]]

for i in range(k-1):
    bmin.append(a[i+1] * (-(-bmin[i]//a[i+1])))
    bmax.append(a[i+1] * ((2*bmax[i]-1)//a[i+1]))
    
        
exist = True

# 判定
if a[0] != 2:
    exist = False
    
else:
    for i in range(k-1):
        if (bmin[i+1]//a[i]) * a[i] != bmin[i]:
            exist = False
            break
    
    for i in range(k-1):
        if (bmax[i+1]//a[i]) * a[i] != bmax[i]:
            exist = False
            break
        
if exist:
    print(bmin[-1], bmax[-1] + a[-1]-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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

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

a = a[::-1]
b = [a[0]]

for i in range(k-1):
    b.append(a[i+1] * (-(-b[i]//a[i+1])))
    
        
exist = True
mn = float("inf")
mx = 0

# 判定
if a[0] != 2:
    exist = False
    
else:
    for i in range(k-1):
        if (b[i+1]//a[i]) * a[i] != b[i]:
            exist = False
            break
        
if exist:
    print(b[-1], b[-1] + a[-1]-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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


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

a = a[::-1]
b = [a[0]]

for i in range(k-1):
    b.append(a[i+1] * (-(-b[i]//a[i+1])))
    
        
exist = True
mn = float("inf")
mx = 0

# 判定
if a[0] != 2:
    exist = False
    
else:
    for i in range(k-1):
        if b[i+1] > 2*b[i] - 1:
            exist = False
            break
        
if exist:
    print(b[-1], b[-1] + (a[-1] - 1))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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


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

a = a[::-1]
b = [a[0]]

for i in range(k-1):
    cur = a[i+1]
    while b[i] > cur:
        cur += cur
    
    b.append(cur)
    
        
exist = True
mn = float("inf")
mx = 0

# 判定
if a[0] != 2:
    exist = False
    
else:
    for i in range(k-1):
        if a[i+1] > 2*a[i] - 1:
            exist = False
            break
        
if exist:
    print(b[-1], b[-1] + (a[-1] - 1))
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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


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

a = a[::-1]
b = [a[0]]

for i in range(k-1):
    cur = a[i+1]
    while a[i] > cur:
        cur += cur
    
    b.append(cur)
    
        
exist = True
mn = float("inf")
mx = 0

# 判定
if a[0] != 2:
    exist = False
    
else:
    for i in range(k-1):
        if a[i+1]-a[i] > a[i]-1:
            exist = False
            break
        
if exist:
    print(b[-1], b[-1] + (a[-1] - 1))
else:
    print(-1)

Submission status: Wrong Answer

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

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

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

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

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

print(MIN,MAX)

Submission status: Wrong Answer

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

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

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

print(MIN,MAX)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(i) for i in input().split()][::-1]
max_a=3
min_a=2
a0=2
flg=0
an=list(a)
if an[0]!=2:
  flg=1

for i in an:
  if i > max_a:
    flg=1
    break
  elif i !=a0:    
    if i>a0:
      min_a +=i-a0
    else:
      min_a+= i - min_a % i 
    max_a=min_a + i -1
  a0=i

if flg==1:
  print('-1')
else:
  print(max_a,min_a)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=reversed([int(i) for i in input().split()])
max_a=3
min_a=2
a0=2
flg=0
an=list(a)
if an[0]!=2:
  flg=1

for i in an:
  if i > max_a:
    flg=1
    break
  elif i !=a0:    
    if i>a0:
      min_a +=i-a0
    else:
      min_a+= i - min_a % i 
    max_a=min_a + i -1
  a0=i

if flg==1:
  print('-1')
else:
  print(max_a,min_a)

Submission status: Wrong Answer

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

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

sys.setrecursionlimit(1000000)

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

minN = 2
maxN = 2

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

print minN, maxN

Submission status: Wrong Answer

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

sys.setrecursionlimit(10000)


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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


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

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


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10000)


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


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


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


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


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


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


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


def mt(f):
    import time

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

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

    return wrap


@mt
def slv(K, A):
    nc = [2]
    for a in A[::-1]:
        tnc = []
        for n in nc:
            if 2*n-1 < a:
                continue
            else:
                tnc.append(math.ceil(n/a)*a)
        nc = tnc
    if nc:
        return ' '.join(map(str, [nc[0], nc[0]+A[0]-1]))
    else:
        return -1


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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

lines = sys.stdin.readlines()
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: Wrong Answer

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
a.reverse()
mx = a[0] * 2
mn = a[0]
judge = True
for i in range(1,n):
    if mx <= a[i]:
        judge = False
        break
    mx = (mx + a[i] - 1) / a[i] * a[i]
    mn = (mn + a[i] - 1) / a[i] * a[i]
if judge:
    print mn,mx-1
else:
    print -1

Submission status: Wrong Answer

Solution code:
import math
import numpy as np

K     = input()
arr_A = input().split()

label  = 0
min_nb = 2
max_nb = 3
prev_min = 2
prev_max = 3

for i in range(len(arr_A)):

  g_num    = int(arr_A[-1*(i+1)]) # 何人グループか

  if(i==0):
    prev_g_num = g_num
    continue
  if(g_num == prev_g_num):
    min_nb = prev_min
    max_nb = prev_max
  else:
    j = 0
    val = 0
    while( prev_min > val ):
      val = g_num*j
      j += 1
    min_nb = val

    j = 0
    val = 0
    while( prev_max > val ):
      val = g_num*j - 1
      j += 1
    max_nb = val

  if(min_nb > max_nb):
    label=1
    break

  prev_min = min_nb
  prev_max = max_nb
  prev_g_num = g_num

if(label == 0):
  print(str(min_nb) +" "+ str(max_nb))
else:
  print(-1)

Submission status: Wrong Answer

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

lo = 2
hi = 10**18
canM = False
canm = False

def check(people):
    for a in A:
        people = (people // a) * a
        if people == 1:
            return False
    if people != 2:
        return False
    else:
        return True


for i in range(150):
    center = (lo + hi) // 2
    if check(center):
        canM = True
        lo = center
    else:
        hi = center

Mz = center

lo = 2
hi = 10**18

for i in range(150):
    center = (lo + hi) // 2
    if center > Mz:
        hi = center
        continue
    if check(center):
        canm = True
        hi = center
    else:
        lo = center

mz = hi

if canM & canm:
    print(mz, Mz)
else:
    print(-1)

Submission status: Wrong Answer

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

lo = 2
hi = 10**18


def check(people):
    for a in A:
        people = (people // a) * a
        if people == 1:
            return False
    if people != 2:
        return False
    else:
        return True


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

Mz = center

lo = 2
hi = 10**18

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

mz = hi

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

Submission status: Wrong Answer

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

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

print(N_min,N_max)

Submission status: Wrong Answer

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

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

print(N_min,N_max)