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()))[::-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]
if cand[0] % A[0] != 0:
    print(-1)
    exit()
for i in range(K):
    s = cand[0]
    m = cand[-1]
    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 = cand[0]
m = cand[-1]
print(s, m)

Submission status: Wrong Answer

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]
for i in range(K):
    s = cand[0]
    m = cand[-1]
    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 = cand[0]
m = cand[-1]
print(s, m)

Submission status: Wrong Answer

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

M=3
m=2
import math
for i in range(1,K):
    if m%A[i]==0:
        Lm=m
    else:
        Lm=(m//A[i]+1)*A[i]
    #print(Lm)
    if Lm<m or M<Lm:
        print(-1)
        exit()
    LM=(M//A[i])*A[i]+A[i]-1
    if LM<Lm:
        print(-1)
        exit()
    M=LM
    m=Lm
print(m,M)

Submission status: Wrong Answer

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

M=3
m=2
import math
for i in range(1,K):
    if m%A[i]==0:
        Lm=m
    else:
        Lm=m+A[i]
    
    if Lm<m or M<Lm:
        print(-1)
        exit()
    LM=(M//A[i])*A[i]+A[i]-1
    if LM<Lm:
        print(-1)
        exit()
    M=LM
    m=Lm
print(m,M)

Submission status: Wrong Answer

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

M=3
m=2
import math
for i in range(1,K):
    Lm=math.ceil(m/A[i])*A[i]
    if Lm<m or M<Lm:
        print(-1)
        exit()
    LM=(M//A[i])*A[i]+A[i]-1
    if LM<Lm:
        print(-1)
        exit()
    M=LM
    m=Lm
print(m,M)

Submission status: Wrong Answer

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

M=3
m=2
import math
for i in range(1,K):
    Lm=math.ceil(m/A[i])*A[i]
    if Lm<m or M<Lm:
        print(-1)
        exit()
    LM=(M//A[i])*A[i]+A[i]-1
    M=LM
    m=Lm
print(m,M)

Submission status: Wrong Answer

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

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

ans_low = 2
ans_high = 3

for i in range(1, K):
    next_ans_high = math.ceil(ans_low/A[i])*A[i]+A[i]-1
    next_ans_low = math.ceil(ans_low/A[i])*A[i]

    if (next_ans_high // A[i])*A[i] > ans_high:
        print(-1)
        exit()

    if (next_ans_low // A[i])*A[i] < ans_low:
        print(-1)
        exit()

    ans_high = next_ans_high
    ans_low = next_ans_low

    # print(A[i], ans_low, ans_high)

print(ans_low, ans_high)

Submission status: Wrong Answer

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

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

ans_low = 2
ans_high = 3

for i in range(1, K):
    next_ans_high = math.ceil(ans_low/A[i])*A[i]+A[i]-1
    next_ans_low = math.ceil(ans_low/A[i])*A[i]

    if (next_ans_high // A[i])*A[i] > ans_high:
        print(-1)
        exit()

    ans_high = next_ans_high
    ans_low = next_ans_low

    # print(A[i], ans_low, ans_high)

print(ans_low, ans_high)

Submission status: Wrong Answer

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

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

ans_low = 2
ans_high = 2

for i in range(1, K):
    if A[i]/A[i-1] >= 2:
        print(-1)
        exit()

    ans_high = math.ceil(ans_low/A[i])*A[i]+A[i]-1
    ans_low = math.ceil(ans_low/A[i])*A[i]

    # print(A[i], ans_low, ans_high)

print(ans_low, ans_high)

Submission status: Wrong Answer

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

ans_low = 2
ans_high = 2

for i in range(1, K):
    if A[i]/A[i-1] >= 2:
        print(-1)
        exit()

    ans_high = math.ceil(ans_low/A[i])*A[i]+A[i]-1
    ans_low = math.ceil(ans_low/A[i])*A[i]

    # print(A[i], ans_low, ans_high)

print(ans_low, ans_high)

Submission status: Wrong Answer

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
inf=float("inf")
k=int(input())
a=list(map(int,input().split()))
min_num=2
for i in range(1,k):
    if min_num<a[-i-1]:
        min_num=a[-i-1]
    else:
        min_num=((min_num-1)//a[-i-1]+1)*a[-i-1]
tmp=min_num
for i in range(k):
    tmp-=tmp%a[i]
if tmp!=2:
    print(-1)
    quit()
max_num=2
for i in range(1,k):
    pass
print(min_num)
print(min_num+a[0]-1)

Submission status: Wrong Answer

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

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

print(*solve(A))

Submission status: Wrong Answer

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

if A[-1] != 2:
    print(-1)
    exit()
else:
    m, M = 2, 3
    for i in range(K-2, -1, -1):
        if A[i] > M:
            print(-1)
            exit()
        else:
            if m % A[i] != 0:
                m = (m // A[i] + 1) * A[i]
            M = (M // A[i] + 1) * A[i] - 1
print(m, M)

Submission status: Wrong Answer

Solution code:
def getlist():
	return list(map(int, input().split()))

#受け取り
K = int(input())
A = getlist()
A = A[::-1]
#処理
ans = 0
dpM = [0] * (K)
dpm = [0] * (K)
dpM[0] = A[0] * 2 - 1
dpm[0] = A[0]
for i in range(1, K):
	if A[i] > dpM[i - 1]:
		ans = -1
		break
	elif A[i] >= dpm[i - 1]:
		dpM[i] = A[i] * 2 - 1
		dpm[i] = A[i]

	else:
		dpM[i] = A[i] * (dpM[i - 1] // A[i] + 1) - 1
		
		if dpm[i - 1] % A[i] == 0:
			dpm[i] = dpm[i - 1]
		else:
			dpm[i] = A[i] * (dpm[i - 1] // A[i] + 1)

if ans == -1 or A[0] != 2:
	print(-1)
else:
	print(dpm[-1], dpM[-1])

Submission status: Wrong Answer

Solution code:
def getlist():
	return list(map(int, input().split()))

#受け取り
K = int(input())
A = getlist()
A = A[::-1]
#処理
ans = 0
dpM = [0] * (K)
dpm = [0] * (K)
dpM[0] = A[0] * 2 - 1
dpm[0] = A[0]
for i in range(1, K):
	if A[i] > dpM[i - 1]:
		ans = -1
		break
	elif A[i] > dpm[i - 1]:
		dpM[i] = A[i] * 2 - 1
		dpm[i] = A[i]
	else:
		if dpM[i - 1] % A[i] == 0:
			dpM[i] = dpM[i - 1]
		else:
			dpM[i] = A[i] * (dpM[i - 1] // A[i] + 1) - 1

		if dpm[i - 1] % A[i] == 0:
			dpm[i] = dpm[i - 1]
		else:
			dpm[i] = A[i] * (dpm[i - 1] // A[i] + 1)

if ans == -1 or A[0] != 2:
	print(-1)
else:
	print(dpm[-1], dpM[-1])

Submission status: Wrong Answer

Solution code:
# AGC020B - Ice Rink Game
def main():
    K, *A = map(int, open(0).read().split())
    l, h = 2, 2  # low, high
    for i in A[::-1]:
        l = (l + i - 1) // i * i
        h = (h / i + 1) * i - 1
    if l > h:
        print(-1)
    else:
        print(l, h)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
K=int(input())
A=list(map(int,input().split()))
l,h=2,2
for a in A[::-1]:
    if h<a or h//a==l//a:
        l=h=-1
        break
    else:
        l=-(-l//a)*a
    h=(h//a+1)*a-1
if l==h==-1:
    print(-1)
else:
    print(l,h)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import math


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

min_n = 2
max_n = 2

pre = 2
for ai in a[::-1]:
    if ai >= pre * 2:
        min_n = -1
        break

    if ai >= min_n:
        min_n = ai
    else:
        min_n = ai * math.ceil(min_n / ai)

    pre = ai
    max_n = min_n + ai - 1

if min_n == -1:
    print(min_n)
else:
    print("{} {}".format(min_n, max_n))

Submission status: Wrong Answer

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


if K == 1:
    if A[0] == 2:
        print(2, 3)
    else:
        print(-1)
else:
    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
        nL = (L+a-1)//b * b
        if nM >= M + a or nM > nL:
            ok = False
            break
        
        L, M = nL, nM
        if i == 1:
            L += b-1
        #print(L, M, a, b)

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

Submission status: Wrong Answer

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


if K == 1:
    if A[0] == 2:
        print(2, 3)
    else:
        print(-1)
else:
    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 i == 1:
            L += b-1
        #print(L, M, a, b)

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

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    for i in a:
        x = x - (x % i)
    return x
k = I()
a = LI()
high,low = 10**9,0
while (high - low) > 1:
    mid = (high + low) // 2 
    if f(mid) >= 2:
        high = mid
    else:
        low = mid
ans1 = high
high,low = 10**9,0
while (high - low) > 1:
    mid = (high + low) // 2
    if f(mid) > 2:
        high = mid
    else:
        low = mid
ans2 = low
if ans1 > ans2:
    print(-1)
else:
    if f(ans1) != 2 or f(ans2) != 2:
        print(-1)
    else:
        print(ans1,ans2)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    for i in a:
        if i > x:
            x = 0
            break
        else:
            x = x - (x % i)
    return x
k = I()
a = LI()
high,low = 10**9,0
while (high - low) > 1:
    mid = (high + low) // 2 
    if f(mid) >= 2:
        high = mid
    else:
        low = mid
ans1 = high
high,low = 10**9,0
while (high - low) > 1:
    mid = (high + low) // 2
    if f(mid) > 2:
        high = mid
    else:
        low = mid
ans2 = low
if ans1 > ans2:
    print(-1)
else:
    if f(ans1) != 2 or f(ans2) != 2:
        print(-1)
    else:
        print(ans1,ans2)

Submission status: Wrong Answer

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(x):
    for i in a:
        if i > x:
            x = 0
            break
        else:
            x = x - (x % i)
    return x
k = I()
a = LI()
high,low = 10**9,0
while (high - low) > 1:
    mid = (high + low) // 2 
    if f(mid) >= 2:
        high = mid
    else:
        low = mid
ans1 = high
high,low = 2+k*max(a),min(a)
while (high - low) > 1:
    mid = (high + low) // 2
    if f(mid) > 2:
        high = mid
    else:
        low = mid
ans2 = low
if ans1 > ans2:
    print(-1)
else:
    print(ans1,ans2)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = [int(x) for x in input().split()]
C = [[0, 0] for _ in range(K + 1)]
C[K] = [2, 2]
for i in range(K - 1, -1, -1):
  if A[i] > C[i + 1][1]:
    print(-1)
    break
  C[i][0] = A[i] * -(-C[i + 1][0] // A[i])
  C[i][1] = A[i] * (C[i + 1][1] // A[i]) + (A[i] - 1)
else:
  print(C[0][0], C[0][1])

Submission status: Wrong Answer

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

import math

amin=2
amax=2
for i in range(1,k)[::-1]:
    if a[i-1]*math.ceil(amin/a[i-1])<=amin+a[i]-1:
        amin=a[i-1]*math.ceil(amin/a[i-1])
    else:
        print(-1)
        exit()
    if a[i-1]*((amax+a[i]-1)//a[i-1])>=amax:
        amax=a[i-1]*((amax+a[i]-1)//a[i-1])
    else:
        print(-1)
        exit()
amax+=a[0]-1
print(amin,amax)

Submission status: Wrong Answer

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

def fmin(a,b):
    #a以上の最低のbの倍数
    b*math.ceil(a/b)
import math

amin=2
amax=2
for i in range(1,k)[::-1]:
    if a[i-1]*math.ceil(amin/a[i-1])<=amin+a[i]-1:
        amin=a[i-1]*math.ceil(amin/a[i-1])
    else:
        print(-1)
        exit()
    amax=a[i-1]*((amax+a[i]-1)//a[i-1])
amax+=a[0]-1
print(amin,amax)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))
hi = [0]*k + [2]
lo = [0]*k + [2]
if a[-1] != 2:
  print(-1)
  exit(0)
for i in range(k-1,0,-1):
  hi[i] = (a[i]+hi[i+1]-1)//a[i-1]*a[i-1]
  lo[i] = (lo[i+1]+a[i-1]-1)//a[i-1]*a[i-1]
  if lo[i]-lo[i]%a[i] != lo[i+1] or hi[i]-hi[i]%a[i] != hi[i+1] or lo[i]>hi[i]:
    print(-1)
    break
else:
  lo[0] = lo[1]
  hi[0] = hi[1]+a[0]-1
  print(lo[0],hi[0])

Submission status: Wrong Answer

Solution code:
k = int(input())
a = [int(i) for i in input().split()]
a = list(reversed(a))
min_x = 2
max_x = 2
if a[0] == 2:
    for i in range(k - 1):
        if min_x + max_x >= 0:
            if a[i] <= a[i + 1] < a[i] * 2:
                min_x = a[i + 1]
                max_x = (a[i + 1] * 2) - 1
            elif a[i] > a[i + 1]:
                min_x = ((min_x // a[i + 1]) + 1) * a[i + 1]
                max_x = (((max_x // a[i + 1]) + 1) * a[i + 1]) - 1
            else:
                min_x = -1
                max_x = -1
    if min_x + max_x >= 0:
        print(min_x, max_x)
    else:
        print(-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = [int(i) for i in input().split()]
a = list(reversed(a))
min_x = 2
max_x = 2
if a[0] == 2:
    for i in range(k - 1):
        if min_x + max_x >= 0:
            if a[i] <= a[i + 1] < a[i] * 2:
                min_x = a[i + 1]
                max_x = (a[i + 1] * 2) - 1
            elif a[i] > a[i + 1]:
                min_x = ((min_x // a[i + 1]) + 1) * a[i + 1]
                max_x = (((min_x // a[i + 1]) + 1) * a[i + 1]) - 1
            else:
                min_x = -1
                max_x = -1
    if min_x + max_x >= 0:
        print(min_x, max_x)
    else:
        print(-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = [int(i) for i in input().split()]
a = list(reversed(a))
min_x = 2
max_x = 2
for i in range(k - 1):
    if min_x + max_x >= 0:
        if a[i] <= a[i + 1] < a[i] * 2:
            min_x = a[i + 1]
            max_x = (a[i + 1] * 2) - 1
        elif a[i] > a[i + 1]:
            min_x = ((min_x // a[i + 1]) + 1) * a[i + 1]
            max_x = (((min_x // a[i + 1]) + 1) * a[i + 1]) - 1
        else:
            min_x = -1
            max_x = -1
if min_x + max_x >= 0:
    print(min_x, max_x)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#B問題
import math
K = int(input())
A = list(map(int,input().split()))
B = A[::-1]

MIN = 0
MAX = 0
flag = 0
for i in range(K):
    if i == 0:
        if B[i] != 2:
            flag = 1
            break
        else:
            MIN = 2
            MAX = 3
    else:
        if MAX < B[i]:
            flag = 1
            break
        else:
            MAX = (MAX//B[i] + 1)*B[i]-1
            MIN = math.ceil(MIN/B[i])*B[i]
            if MAX < MIN:
                MAX = MIN
if flag == 1:
    print(-1)
else:
    print(MIN,MAX)

Submission status: Wrong Answer

Solution code:
#B問題
import math
K = int(input())
A = list(map(int,input().split()))
B = A[::-1]

MIN = 0
MAX = 0
flag = 0
for i in range(K):
    if i == 0:
        if B[i] != 2:
            flag = 1
            break
        else:
            MIN = 2
            MAX = 3
    else:
        if MAX < B[i]:
            flag = 1
            break
        else:
            MAX = (MAX//B[i] + 1)*B[i]-1
            MIN = math.ceil(MIN/B[i])*B[i]
if flag == 1:
    print(-1)
else:
    print(MIN,MAX)

Submission status: Wrong Answer

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: Wrong Answer

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

A = B[::-1]

l = 2
m = 2
ok = True
prea = 2
for a in A:
    nl = (l + prea - 1)//a * a

    if m%a == 0:
        m -= 1
    nm = (m//a + 1) * a
    #print(a, m, nl, l, prea)
    if nm == 0 or nl < l or nl >= l + prea:
        ok = False
        break
    prea = a
    l = nl
    m = nm
if A[0] != 2:
    ok = False

if not ok:
    print(-1)
else:
    print(m, l+prea-1)

Submission status: Wrong Answer

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

A = B[::-1]

l = 2
m = 2
ok = True
prea = 2
for a in A:
    nl = (l + prea - 1)//a * a

    if m%a == 0:
        m -= 1
    nm = (m//a + 1) * a
    #print(a, m, nl, l, prea)
    if nm < m or nl < l or nl >= l + prea:
        ok = False
        break
    prea = a
    l = nl
    m = nm
if A[0] != 2:
    ok = False

if not ok:
    print(-1)
else:
    print(m, l+prea-1)

Submission status: Wrong Answer

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

A = B[::-1]

l = 2
m = 2
ok = True
prea = 2
for a in A:
    l = (l + prea - 1)//a * a
    if m%a == 0:
        m -= 1
    m = (m//a + 1) * a
    if m == 0 or l == 0:
        ok = False
        break
    prea = a
if A[0] != 2:
    ok = False

if not ok:
    print(-1)
else:
    print(m, l+prea-1)

Submission status: Wrong Answer

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

A = B[::-1]

l = 2
m = 2
ok = True
prea = 2
for a in A:
    l = (l + prea - 1)//a * a
    if m%a == 0:
        m -= 1
    m = (m//a + 1) * a
    if m == 0 or l == 0:
        ok = False
        break
    prea = a

if not ok:
    print(-1)
else:
    print(m, l+prea-1)

Submission status: Wrong Answer

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
        current_min = max(current_min, a_k)

    print("{} {}".format(current_min, current_max))
    return


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

Submission status: Wrong Answer

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("{} {}".format(current_min, current_max))
    return


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

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()

nums = getList()[::-1]

bottom, top = 2, 2

for num in nums:
    if num > top:
        print(-1)
        sys.exit()

    top = (top // num) * num + num - 1
    if top < bottom:
        print(-1)
        sys.exit()
    bottom = math.ceil(bottom / num) * num


print(bottom, top)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math

n = getN()

nums = getList()[::-1]

bottom, top = 2, 2

for num in nums:
    if num > top:
        print(-1)
        sys.exit()

    top = (top // num) * num + num - 1
    bottom = math.ceil(bottom / num) * num


print(bottom, top)

Submission status: Wrong Answer

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

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
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 DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    k = int(input())
    a = list(map(int,input().split()))
    
    mi = 2
    ma = 2

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

    for i in range(k):
        if ma < a[k-1-i]:
            print(-1)
            exit()
        
        ma = a[k-1-i]*(ma // a[k-1-i]) + a[k-1-i] - 1
        mi = a[k-1-i]* math.ceil(mi / a[k-1-i])

    print(mi,ma)

    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}

Submission status: Wrong Answer

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

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
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 DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    k = int(input())
    a = list(map(int,input().split()))
    
    mi = 2
    ma = 2

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

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

    print(mi,ma)

    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}

Submission status: Wrong Answer

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

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
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 DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    k = int(input())
    a = list(map(int,input().split()))
    
    mi = 2
    ma = 2

    for i in range(k):
        if ma < a[k-1-i]:
            print(-1)
            exit()
        
        ma = a[k-1-i]*(ma // a[k-1-i]) + a[k-1-i] - 1
        mi = min(ma,a[k-1-i]*(( (mi - 1) // a[k-1-i]) + 1) )

    print(mi,ma)

    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}