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]
if A[0] > 2:
    print(-1)
    exit()

ansM = 2
ansm = 2

for a in A:
    if a > ansm:
        ansm = a
    ansm = ((ansm - 1) // a + 1) * a
    if a > ansM:
        print(-1)
        exit()
    ansM = (ansM // a) * a + (a - 1)
print(ansm, ansM)

Submission status: Wrong Answer

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

ansM = 2
ansm = 2

for a in A:
    if a > ansm:
        ansm = a
    else:
        ansm = ((ansm - 1) // a + 1) * a
    if a > ansM:
        print(-1)
        exit()
    ansM = (ansM // a) * a + (a - 1)
print(ansm, ansM)

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())
A = list(map(int, input().split()))
minA = 2
maxA = 2
for ai in A[::-1]:
    if minA <= ai <= maxA:
        minA = ai
        maxA = maxA - maxA%ai + ai - 1
    elif ai < minA:
        minA = minA + ai * int(minA%ai>0) - minA%ai
        maxA = maxA - maxA%ai + ai - 1
    elif ai > maxA:
        print(-1)
        sys.exit()
print(minA, maxA)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) > 2:
        r = mid
    else:
        l = mid
maxcnt = l

l,r = 0, 2**10
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) < 2:
        l = mid
    else:
        r = mid
mincnt = r


if check(mincnt, A) == check(maxcnt, A) == 2:
    print(mincnt, maxcnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt

l,r = 2, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) >= 2:
        r = mid
    else:
        l = mid
mincnt = r

l,r = 2, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) <= 2:
        l = mid
    else:
        r = mid
maxcnt = l


if check(mincnt, A) == check(maxcnt, A) == 2:
    print(mincnt, maxcnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt

l,r = 2, 10**10
for i in range(100):
    mid = (l+r)//2
    if check(mid, A) >= 2:
        r = mid
    else:
        l = mid
mincnt = r

l,r = 2, 10**10
for i in range(100):
    mid = (l+r)//2
    if check(mid, A) <= 2:
        l = mid
    else:
        r = mid
maxcnt = l


if check(mincnt, A) == check(maxcnt, A) == 2:
    print(mincnt, maxcnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt == 2

mincnt = 2
for a in reversed(A):
    if a < mincnt:
        a = math.ceil(mincnt/a) * a
    mincnt = max(mincnt, a)

l,r = mincnt, 10**10
for i in range(100):
    mid = (l+r)//2
    if check(mid, A):
        l = mid
    else:
        r = mid
#print(l,r)
maxcnt = l

#print(check(mincnt, A))
if check(mincnt, A) and check(maxcnt, A):
    print(mincnt, maxcnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt == 2

l,r = 2,10**10
for i in range(100):
    mid = (l+r)//2
    if check(mid, A):
        l = mid
    else:
        r = mid

maxcnt = l
l,r = 2, maxcnt
for i in range(100):
    mid = (l+r)//2
    if check(mid, A):
        r = mid
    else:
        l = mid
#print(l,r)
mincnt = r

#print(check(mincnt, A))
if check(mincnt, A) and check(maxcnt, A):
    print(mincnt, maxcnt)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int,input().split()))
if a[-1] != 2:
    print(-1)
    exit()

l = 2
r = 3
for i in a[::-1][1:]:
    if i > r:
        print(-1)
        exit()
    l = (l+i-1)//i*i
    r = r//i*i+i-1
    
print(l,r)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int,input().split()))
if a[-1] != 2:
    print(-1)
    exit()

l = 2
r = 3
for i in a[::-1][1:]:
    if i > r:
        print(-1)
        exit()
    d = l%i
    if d == 0:
        l = i
    else:
        l = l+(i-d)
    r = (r-l)//i*i+l+i-1
    
print(l,r)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int,input().split()))
if a[-1] != 2:
    print(-1)
    exit()

l = 2
r = 3
for i in a[::-1][1:]:
    if i > r:
        print(-1)
        exit()
    d = l%i
    if d == 0:
        l = i
    else:
        l = l+(i-d)
    r = l+i-1
print(l,r)

Submission status: Wrong Answer

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

def solve(num, checker):
    return checker*(num//checker)

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 3:
        right = middle
    else:
        left = middle + 1
x = right - 1

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 2:
        right = middle
    else:
        left = middle + 1
        
y = right
if x < y:
    print(-1)
else:
    print(y, x)

Submission status: Wrong Answer

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

def solve(num, checker):
    return checker*(num//checker)

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 2:
        right = middle
    else:
        left = middle + 1
x = right

left, right = 0, 10**9 + 1
while left < right:
    middle = -((-left-right)//2)
    #print(left, right, middle, num)
    num = middle
    
    for i in a:
        num = solve(num, i)
    if num <= 2:
        left = middle
    else:
        right = middle - 1
        
y = right

if y < x:
    print(-1)
else:
    print(x, y)

Submission status: Wrong Answer

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

def solve(num, checker):
    return checker*(num//checker)

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 2:
        right = middle
    else:
        left = middle + 1
x = right

left, right = 0, 10**9 + 1
while left < right:
    middle = (left+right)//2
    #print(left, right, middle, num)
    num = middle
    
    for i in a:
        num = solve(num, i)
    if num > 2:
        right = middle
    else:
        left = middle + 1

y = right - 1

if y < x:
    print(-1)
else:
    print(x, y)

Submission status: Wrong Answer

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

def solve(num, checker):
    return checker*(num//checker)

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 2:
        right = middle
    else:
        left = middle + 1
x = right

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    #print(left, right, middle, num)
    num = middle
    
    for i in a:
        num = solve(num, i)
    if num > 2:
        right = middle - 1
    else:
        left = middle + 1
y = left

if y < x:
    print(-1)
else:
    print(x, y)

Submission status: Wrong Answer

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

def solve(num, checker):
    return checker*(num//checker)

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2
    num = middle
    for i in a:
        num = solve(num, i)
    if num >= 2:
        right = middle
    else:
        left = middle + 1
x = right

left, right = 0, 10**9
while left < right:
    middle = (left+right)//2

    num = middle
    
    for i in a:
        num = solve(num, i)
    if num > 2:
        right = middle
    else:
        left = middle + 1
y = left - 1

if y < x:
    print(-1)
else:
    print(x, y)

Submission status: Wrong Answer

Solution code:
k= int(input())
a= list(map(int,input().split()))
n=2
if a[-1]!=2:print(-1)
else:
    for j in range(k):
        if j==k-1:
            print(n,n+a[k-j-1]-1)
        else:
            n=(n+a[k-j-1]-1)-(n+a[k-j-1]-1)%(a[k-j-2])
            if n==0:
                print(-1)
                exit()

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int,input().split()))
if A[0]!=2:
    print(-1)
elif K==1:
    print(2,3)
else:
    nmin = 2
    nmax = 2+A[K-1]-1
    flag = 0
    for i in range(K-2,-1,-1):
        b = A[i]
        nmin = math.ceil(nmin/b)*b
        nmax = math.floor(nmax/b)*b
        if nmin>nmax:
            flag = 1
            break
        nmax += b-1
    if flag==1:
        print(-1)
    else:
        print(nmin,nmax)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int,input().split()))
if K==1:
    if A[0]!=2:
        print(-1)
    else:
        print(2,3)
else:
    nmin = 2
    nmax = 2+A[K-1]-1
    flag = 0
    for i in range(K-2,-1,-1):
        b = A[i]
        nmin = math.ceil(nmin/b)*b
        nmax = math.floor(nmax/b)*b
        if nmin>nmax:
            flag = 1
            break
        nmax += b-1
    if flag==1:
        print(-1)
    else:
        print(nmin,nmax)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int,input().split()))
nmin = 2
nmax = 2+A[K-1]-1
flag = 0
for i in range(K-2,-1,-1):
    b = A[i]
    nmin = math.ceil(nmin/b)*b
    nmax = math.floor(nmax/b)*b
    if nmin>nmax:
        flag = 1
        break
    nmax += b-1
if flag==1:
    print(-1)
else:
    print(nmin,nmax)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())

a = list(reversed(a))
# max
now = 2
for i in range(1, n):
    # 今のから増加させて、ギリギリa[i]で割り切れない
    # nowを超える最小のa[i]の倍数-1
    if now > a[i]:
        now = (now + a[i] - 1) // a[i] * a[i] - 1
    else:
        now = a[i] * 2 - 1

今 = 2
for i in range(1, n):
    # now以上の最小のa[i]の倍数
    今 = (今 + a[i] - 1) // a[i] * a[i]


def check(x):
    for i in range(n - 1, -1, -1):
        x -= x % a[i]
    return x == 2


if check(今) and check(now):
    print(今, now)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
if a[-1] != 2:
    print(-1)
    exit()

a = list(reversed(a))
# max
now = 2
for i in range(1, n):
    # 今のから増加させて、ギリギリa[i]で割り切れない
    # nowを超える最小のa[i]の倍数-1
    if now > a[i]:
        now = (now + a[i] - 1) // a[i] * a[i] - 1
    else:
        now = a[i] * 2 - 1

今 = 2
for i in range(1, n):
    # now以上の最小のa[i]の倍数
    今 = (今 + a[i] - 1) // a[i] * a[i]


def check(x):
    for i in range(n - 1, -1, -1):
        x -= x % a[i]
    return x == 2


if check(今) and check(now):
    print(今, now)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    K = int(input())
    A = list(map(int, input().split()))
    if A[-1]!= 2:
        print(-1)
        exit()
    ans = 2
    for i in range(K):
        a = A[K-1-i]
        if ans*2 <= a:
            print(-1)
            exit()
        elif ans <= a:
            ans = a
        else:
            t = (ans+a-1)//a
            ans = t * a
        # print(ans)
    print(ans, ans+a-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

def main():
    K = int(input())
    A = list(map(int, input().split()))
    if A[-1]!= 2:
        print(-1)
        exit()
    ans = 0
    for i in range(K):
        a = A[K-1-i]
        if ans <= a:
            ans = a
        else:
            t = (ans+a-1)//a
            if t > 2:
                print(-1)
                exit()
            ans = t * a
    print(ans, ans+a-1)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n, *a = map(int, open(0).read().split())
if a[-1] != 2:
    print(-1)
    exit()


def c(x, f):
    for i in range(n):
        if x < a[i]:
            return False
        x -= x % a[i]
    if f:
        return x >= 2
    return x <= 2


l = 0
r = 10 ** 12
while r != l:
    mid = (l + r) // 2
    if (c(mid, True)):
        r = mid
    else:
        l = mid + 1

a1 = r

l = 0
r = 10 ** 12
while r - l > 1:
    mid = (l + r) // 2
    if c(mid, False):
        l = mid
    else:
        r = mid
if a1 < l:
    print(a1, l)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

K=int(input())
A=list(map(int,input().split()))[::-1]
ans=[2]*(K+1)
if A[0]>2:
    print(-1)
    exit()

for i in range(1,K):
    if A[i]==1:
        ans[i+1]=ans[i]
    else:
        if A[i]>=A[i-1]*2:
            print(-1)
            exit()
        else:
            ans[i+1]=math.ceil(ans[i]/A[i])*A[i]
print(ans[-1],ans[-1]-1+A[-1])

Submission status: Wrong Answer

Solution code:
import sys,math,collections,itertools
input = sys.stdin.readline

K=int(input())
A=list(map(int,input().split()))[::-1]
B=[2]*K
if A[0]>2:
    print(-1)
    exit()

for i in range(1,K):
    if A[i] >=A[i-1]*2:
        print(-1)
        exit()
    elif A[i-1]<=A[i]<A[i-1]*2:
        B[i] = max(A[i],2)
    elif A[i-1]>A[i]:
        B[i] = math.ceil(A[i-1]/A[i])*A[i]

print(B[-1],B[-1]+A[-1]-1)

Submission status: Wrong Answer

Solution code:
def f(A,B,Y):
    alpha=((Y+(A-1))//A)*A
    beta=((Y+B-1)//A)*A

    if Y<=alpha<Y+B and Y<=beta<Y+B:
        return min(alpha,beta),max(alpha,beta)
    else:
        return 1/0

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

Max=[0]*(K+1)
Min=[0]*(K+1)
Max[-1]=Min[-1]=2

try:
    for k in range(K-1,-1,-1):
        p,_=f(A[k],A[k+1],Min[k+1])
        Min[k]=p

        _,q=f(A[k],A[k+1],Max[k+1])
        Max[k]=q
    print(Min[0],Max[0])
except:
    print(-1)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
k=int(input())
a=list(map(int,input().split()))
ml=mr=2
l=r=2
for i in range(k):
    ai=a[k-1-i]
    mr=(r//ai)*ai
    ml=(1+(l//ai))*ai if l%ai!=0 else l
    if mr==0:
        print(-1)
        exit()
    elif ml==0:
        ml=mr
    l=ml
    r=mr+ai-1
print(l,r)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect
k=int(input())
a=list(map(int,input().split()))
ml=mr=2
l=r=2
for i in range(k):
    ai=a[k-1-i]
    mr=(r//ai)*ai
    ml=math.ceil(l/ai)*ai
    if mr==0:
        print(-1)
        exit()
    elif ml==0:
        ml=mr
    l=ml
    r=mr+ai-1
print(l,r)

Submission status: Wrong Answer

Solution code:
n = int(input())
As = list(map(int, input().split()))
    
def f(m):
    debug = m
    for a in As:
        i = m // a
        m = i * a
    return m

# 二部探索?
l = 1
r = 10**10 + 1
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 1: l = m
    else: r = m
ans1 = r
l = 1
r = 10**10 + 1
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 2: l= m
    else: r = m
ans2 = l

if ans1 > ans2:
    print(-1)
else:
    print(ans1,ans2)

Submission status: Wrong Answer

Solution code:
n = int(input())
As = list(map(int, input().split()))
    
def f(m):
    debug = m
    for a in As:
        i = m // a
        m = i * a
        # print(a,m)
    # print("debug",debug,m)
    return m
# 二部探索?
l = 1
r = 10**5+1
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 1: l = m
    else: r = m
ans1 = (l,r)
l = 1
r = 10**5 + 1
# print("---------------")
while r-l > 1:
    m = (r+l)//2
    if f(m) <= 2: l= m
    else: r = m
ans2 = (l,r)
# print(ans1,ans2)
if ans1[1] > ans2[0]:
    print(-1)
else:
    print(ans1[1],ans2[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
As = list(map(int, input().split()))

def f(m):
    for a in As:
        i = m // a
        m = i * a
    return m
# 二部探索?
l = 1
r = 10**5+1
while r-l > 1:
    m = (r+l)//2
    if f(m) < 2: l = m
    else: r = m
ans1 = (l,r)
l = 1
r = 10**5 + 1
while r-l > 1:
    m = (r+l)//2
    if f(m) >= 3: r = m
    else: l = m
ans2 = (l,r)
if ans1[1] > ans2[0]:
    print(-1)
else:
    print(ans1[1],ans2[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))[::-1]
if a[0]!=2:
  print(-1)
  exit()
mn,mx=2,2
for j in a:
  mn=(mn+j-1)//j*j
  mx=mx//j*j+j-1
  if mx==0:
    print(-1)
    exit()
print(mn,mx)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))[::-1]
mn,mx=2,2
for j in a:
  mn=(mn+j-1)//j*j
  mx=mx//j*j+j-1
  if mx==0:
    print(-1)
    exit()
print(mn,mx)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))[::-1]
if a[0]!=2:
  print(-1)
  exit()
mn,mx=2,2
for i,j in enumerate(a[1:],1):
  mn=(mn+j-1)//j*j
  mx=(mx+a[i-1]-1)//j*j
  if mx==0:
    print(-1)
    exit()
print(mn,mx+a[-1]-1)

Submission status: Wrong Answer

Solution code:
import sys
import math

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

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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
A = LIST()

def f(N):
	left = N
	for a in A:
		left = left//a*a
	return left

l_N_max = 0
r_N_max = K*max(A)
while l_N_max+1 < r_N_max:
	m = (l_N_max+r_N_max)//2
	if f(m) <= 2:
		l_N_max = m
	else:
		r_N_max = m

N_max = l_N_max

l_N_min = 0
r_N_min = K*max(A)
while l_N_min+1 < r_N_min:
	m = (l_N_min+r_N_min)//2
	if f(m) < 2:
		l_N_min = m
	else:
		r_N_min = m
N_min = r_N_min

if N_min > N_max:
	print(-1)
else:
	print(N_min, N_max)

Submission status: Wrong Answer

Solution code:
from math import ceil
K = int(input())
A = list(map(int, input().split()))
A.reverse()
mi = 2
mx = 3
for a in A[1:]:
    if ceil(mi/a) > mx//a:
        print(-1)
        exit()
    mi = ceil(mi/a)*a
    mx = mx//a*a
    mx = mx + a - 1
print(mi, mx)

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    k = ni()
    a = na()
    a.reverse()

    min_num = 2
    max_num = 2

    for ai in a:
        min_num = int(math.ceil(min_num / ai) * ai)
        max_num = int(math.floor(max_num / ai + 1) * ai) - 1

    print(min_num, max_num if min_num < max_num else -1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    k = ni()
    a = na()
    a.reverse()

    min_num = 2
    max_num = 2

    for ai in a:
        min_num = int(math.ceil(min_num / ai) * ai)
        max_num = int(math.floor(max_num / ai + 1) * ai) - 1

    print(min_num, max_num if min_num <= max_num else -1)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    k = ni()
    a = na()
    a.reverse()

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

    min_num = 2
    max_num = 0

    for ai in a:
        if min_num > ai:
            min_num = ai * (((min_num - 1) // ai) + 1)
        elif 2 * min_num > ai:
            min_num = ai
        else:
            print(-1)
            exit(0)

        max_num = min_num + ai - 1

    print(min_num, max_num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    k = ni()
    a = na()
    a.reverse()

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

    min_num = 2
    max_num = 0

    for ai in a:
        if min_num > ai:
            min_num = ai * ((min_num // ai) + 1)
        elif 2 * min_num > ai:
            min_num = ai
        else:
            print(-1)
            exit(0)

        max_num = min_num + ai - 1

    print(min_num, max_num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    k = ni()
    a = na()
    a.reverse()

    min_num = 2
    max_num = 2

    for ai in a:
        if min_num > ai:
            min_num = ai * ((min_num // ai) + 1)
        elif 2 * min_num > ai:
            min_num = ai
        else:
            print(-1)
            exit(0)

        max_num = min_num + ai - 1

    print(min_num, max_num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

"""
N -> N//A * A = Nextなので、
Nmin = Next, Nmax = Next+A-1 となる

"""
now = 2
m,M = 2,2
prev = 999999
for a in A[::-1]:
  if prev > a and prev % a == 0:
    print(-1)
    exit(0)
  if m <= a:
    m = a
  else:
    m = (m//a + 1) * a
  if M <= a:
    M = 2*a - 1
  else:
    M = M//a * a + a - 1
  prev = a
  #print(m,M)
print(m,M)

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    A = list(map(int, input().split()))
    A = A[::-1]
    if A[0] != 2:
        print(-1)
        return
    n = 2
    for a in A:
        # n <- [n, n + n - 1]内のaの倍数
        if (2 * n - 1) // a - (n - 1) // a == 0:
            print(-1)
            return
        if n % a > 0:
            n += a - n % a
    print('{} {}'.format(n, n + A[-1] - 1))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

K = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

l = 2
r = 2
for i in range(K-2, -1, -1):
    l = ((l - 1) // A[i] + 1) * A[i]
    r = ((r + A[i+1] - 1) // A[i]) * A[i] 

    if l > r:
        print(-1)
        sys.exit()

# print(l, r)
print(l, r + A[0] - 1)

Submission status: Wrong Answer

Solution code:
import sys

K = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

l = 2
r = 2
for i in range(K-2, -1, -1):
    l = ((l - 1) // A[i] + 1) * A[i]
    r = ((r + A[i+1] - 1) // A[i]) * A[i] 

# print(l, r)
if l != 0 and l <= r:
    print(l, r + A[0] - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys

K = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

# うまい方法がない気がするため、二分探索で攻める
l = 0
r = 2 * 10**9
ans1 = -1
while l != r:
    n = (l + r) // 2
    res1 = n
    for a in A:
        res1 = res1 - res1 % a
    if res1 >= 2:
        r = n
        if res1 == 2:
            ans1 = n
    else:
        l = n + 1

l = 0
r = 2 * 10**9
ans2 = -1
while l != r:
    n = (l + r) // 2
    res2 = n
    for a in A:
        res2 = res2 - res2 % a
    if res2 <= 2:
        l = n + 1
        if res2 == 2:
            ans2 = n
    else:
        r = n

if ans1 != -1:
    print(ans1, ans2)
    # print(n - n % A[0], A[0] * ((n - 1) // A[0] + 1) - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys

K = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

# うまい方法がない気がするため、二分探索で攻める
l = 0
r = 2 * 10**9

while l != r:
    n = (l + r) // 2
    res = n
    for a in A:
        res = res - res % a
    if res == 2:
        break
    elif res > 2:
        r = n
    else:
        l = n + 1

if res == 2:
    print(n - n % A[0], A[0] * ((n - 1) // A[0] + 1) - 1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul, itemgetter
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

K = getN()
A = getList()
A = A[::-1]
if A[0] > 2:
    print(-1)
    exit()

# n, n + 1, n + 2... n + bef - 1内でのafterの倍数のうち最も大きいもの
def max_alter(n, bef, after):
    opt = ((n + bef - 1) // after) * after
    if opt  >= n:
        return opt
    else:
        return False

# n, n + 1, n + 2... n + bef - 1内でのafterの倍数のうち最も小さいもの
def min_alter(n, bef, after):
    if n % after == 0:
        return n
    else:
        return ((n // after) + 1) * after

ans_mi = 2
for i in range(K - 1):
    if A[i] <= A[i + 1]:
        ans_mi = max_alter(ans_mi, A[i], A[i + 1])
    else:
        ans_mi = min_alter(ans_mi, A[i], A[i + 1])

ans_ma = 2
for i in range(K - 1):
    opt = max_alter(ans_ma, A[i], A[i + 1])
    if opt:
        ans_ma = opt
    else:
        print(-1)
        exit()
ans_ma = max_alter(ans_ma, A[-1], 1)

print(ans_mi, ans_ma)