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()))


l = 0
r = 10 ** 10
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N -= max(N % a, 0)
    if N > 2:
        r = m
    else:
        l = m
upper = l


l = 0
r = 10 ** 10
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N -= max(N % a, 0)

    if N < 2:
        l = m
    else:
        r = m
lower = r

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

Submission status: Wrong Answer

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


def C1(N):
    for a in A:
        N -= N % a
    return N >= 2


def C2(N):
    for a in A:
        N -= N % a
    return N > 2


l = 0
r = 10 ** 10
while r - l > 1:
    m = (r + l) // 2
    if C1(m):
        r = m
    else:
        l = m
lower = r


l = 0
r = 10 ** 10
while r - l > 1:
    m = (r + l) // 2
    if C2(m):
        r = m
    else:
        l = m
upper = l

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

Submission status: Wrong Answer

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

ans = [2,2]
for a in A[::-1]:

  if a > ans[1]:
    print(-1)
    exit()
  ans[1] = ans[1]//a *a+ (a-1)
  if ans[0] <= a:
    ans[0] = a
  else:
    if ans[0]%a != 0:
      ans[0] = (ans[0]//a+1)*a
print(*ans)

Submission status: Wrong Answer

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

ans = [2,2]
for a in A[::-1]:

  if a > ans[1]:
    print(-1)
    exit()
  ans[1] = ans[1]//a *a+ (a-1)
  if ans[0] <= a:
    ans[0] = a
  else:
    i = 1
    while 1:
      if i*a > ans[0]:
        ans[0] = i*a
        break
      else:
        i+= 1
print(*ans)

Submission status: Wrong Answer

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

ans = [2,2]
for a in A[::-1]:
  print(ans)
  if a > ans[1]:
    print(-1)
    exit()
  ans[1] = ans[1]//a *a+ (a-1)
  if ans[0] <= a:
    ans[0] = a
  else:
    i = 1
    while 1:
      if i*a > ans[0]:
        ans[0] = i*a
        break
      else:
        i+= 1
print(*ans)

Submission status: Wrong Answer

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

ans = [2,2]
for a in A[::-1]:

  if a > ans[1]:
    print(-1)
    exit()
  ans[1] = ans[1]//a *a+ (a-1)
  if ans[0] <= a:
    ans[0] = a
  else:
    i = 1
    while 1:
      if i*a > ans[0]:
        ans[0] = i*a
        break
      else:
        i+= 1
print(*ans)

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int,input().split()))
lo = 2
hi = 2
for e in A[::-1]:
    if hi//e == lo//e and (hi%e)*(lo%e) != 0:
        print(-1)
        exit(0)
    else:
        lo = e*math.ceil(lo/e)
        hi = e*(math.ceil(lo/e)+1)-1
print(lo,hi)

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    K = int(input())
    A = [int(a) for a in input().split()]
    if A[K-1] != 2: print(-1)
    else:
        minN, maxN = 2, 3
        for i in reversed(range(K - 1)):
            if maxN < A[i]: 
                print(-1)
                break
            else:
                lb = (minN - 1) // A[i]
                hb = maxN // A[i]
                minN = A[i] * (lb + 1)
                maxN = A[i] * hb + A[i] - 1
        else: print(minN, maxN)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import sys

def solve():
    input = sys.stdin.readline
    K = int(input())
    A = [int(a) for a in input().split()]
    minN, maxN = 2, 2
    for i in reversed(range(K)):
        if maxN < A[i]: 
            print(-1)
            break
        else:
            lb = (minN - 1) // A[i]
            hb = maxN // A[i]
            minN = A[i] * (lb + 1)
            maxN = A[i] * hb + A[i] - 1
    else: print(minN, maxN)
    return 0

if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
def examA():
    N = I()
    A = LI()
    if A[-1]!=2:
        print(-1)
        return
    l = 2; r = 2
    for a in A[::-1]:
        ner = (r//a+1)*a-1
        nel = ((l-1)//a+1)*a
        r = ner; l = nel
        if r<a:
            print(-1)
            return
    print(l,r)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int, input().split()))
def ceiling(x, mod):
  if x % mod == 0:
    return x // mod
  else:
    return x // mod + 1

m, M = 2, 2
p = 0
for i in range(K-1, -1, -1):
  m, M = A[i] * ceiling(m, A[i]), A[i] * ceiling(m, A[i]) + A[i] - 1
chk1, chk2 = m, M
for i in range(K):
  chk1, chk2 = A[i] * (chk1 // A[i]), A[i] * (chk2 // A[i])
if chk1 == 2 and chk2 == 2:
  print(m, M)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int, input().split()))
def ceiling(x, mod):
  if x % mod == 0:
    return x // mod
  else:
    return x // mod + 1

m, M = 2, 2
p = 0
for i in range(K-1, -1, -1):
  m = A[i] * ceiling(m, A[i])
  M = A[i] * ceiling(m, A[i]) + A[i] - 1
chk1, chk2 = m, M
for i in range(K):
  chk1, chk2 = A[i] * (chk1 // A[i]), A[i] * (chk2 // A[i])
if chk1 == 2 and chk2 == 2:
  print(m, M)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int, input().split()))
def ceiling(x, mod):
  if x % mod == 0:
    return x // mod
  else:
    return x // mod + 1

m, M = 2, 2
p = 0
for i in range(K-1, -1, -1):
  if A[i] < 2*m:
    m = A[i] * ceiling(m, A[i])
    M = A[i] * ceiling(m, A[i]) + A[i] - 1
  else:
    p = -1
    break
if p == 0:
  print(m, M)
else:
  print(p)

Submission status: Wrong Answer

Solution code:
def search_n(a_list):
  min_n = 2
  max_n = 2
  
  for a in reversed(a_list):
    curr_min_n = min_n if min_n % a == 0 else min_n + a - min_n % a
    if curr_min_n > max_n:
      return None
    
    min_n = curr_min_n
    max_n = curr_min_n + a - 1
  
  return min_n, max_n


def main():
  input()
  a_list = list(map(int, input().split()))
  
  n_range = search_n(a_list)
  if n_range:
    print(*n_range)
  else:
    print(-1)


main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

K = int(input())
A = [int(i) for i in input().split()]
A.reverse()

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

def dfs(n, c):
    if c == K - 1:
        return n, n + A[c] - 1

    MIN, MAX = float("inf"), -float("inf")
    tmp = (n + A[c + 1] - 1) // A[c + 1] * A[c + 1]
    if 0 < tmp <= n + A[c]:
        a,b = dfs(tmp, c + 1)
        MIN = min(MIN, a)
        MAX = max(MAX, b)
    
    return MIN, MAX

MIN, MAX = dfs(2, 0)
if MIN == float("inf"):
    print(-1)
else:
    print(MIN, MAX)

Submission status: Wrong Answer

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

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

A.reverse()
mn = mx = 2
for a,b in zip(A,A[1:]):
    mnmx = mn + a-1
    mn += (b - mn%b)%b
    mx += a-1
    mx -= mx%b
    if mn > mx or mn > mnmx:
        print(-1)
        exit()

mx += A[-1]-1
print(mn,mx)

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

k = INT()
a = LIST()
n = 2
for i in reversed(range(1, k)):
    k = n // a[i]
    l = (n + a[i - 1] - 1) // a[i - 1]
    np = n
    n = l * a[i - 1]
    if n // a[i] != np // a[i]:
        print(-1)
        exit()
ansmx = n + a[0] - n % a[0] - 1
ansmn = n if n % a[0] == 0 else n + a[0] - n % a[0] - 1
print(ansmn, ansmx)

Submission status: Wrong Answer

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

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

A.reverse()
mn = mx = 2
for a in A[1:]:
    mn = mn + (a - mn%a)%a
    lim = mx*2-1
    mx = lim - lim%a
    if mn > mx:
        print(-1)
        exit()

mx += A[-1]-1
print(mn,mx)

Submission status: Wrong Answer

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

def func(num):
    for item in A:
        num=num//item*item
    return num

ans=[]
ok=10**200
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    if func(mid)>=2:
        ok=mid
    else:
        ng=mid

ans=ok

ok=10**10
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    if func(mid)>=4:
        ok=mid
    else:
        ng=mid

if func(ans)==2 and func(ng)==2:
    print(ans,ng)
else:
    print(-1)

Submission status: Wrong Answer

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

def func(num):
    for item in A:
        num=num//item*item
    return num

ans=[]
ok=10**10
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    if func(mid)>=2:
        ok=mid
    else:
        ng=mid

ans=ok

ok=10**10
ng=0

while ok-ng>1:
    mid=(ok+ng)//2
    if func(mid)>=4:
        ok=mid
    else:
        ng=mid

if func(ans)==2 and func(ng)==2:
    print(ans,ng)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
K=int(input())
A=list(map(int,input().split()))

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

low=2
high=3
for item in A[::-1]:
    #print(low,high)
    if high<item:
        print(-1)
        exit()
    elif item<low:
        low=(-((-low)//item))*item
        high=max(low+item-1,high+item-1-high%item)
    else:
        low=item
        high=low+item-1
print(low,high)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
K=int(input())
A=list(map(int,input().split()))

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

low=2
high=3
for item in A[::-1]:
    if high<item:
        print(-1)
        exit()
    elif item<low:
        low=(-((-low)//item))*item
        high=max(low+item-1,high)
    else:
        low=item
        high=low+item-1
print(low,high)

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    K = int(input())
    A = read_list()[::-1]
    if A[0] != 2:
        print(-1)
        return

    minN = 2
    maxN = 4
    for a in A:
        if maxN <= a:
            print(-1)
            return
        minN = ((minN - 1) // a + 1) * a
        maxN = a + minN
    print(minN, maxN - 1)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
K=int(input())
A=list(map(int,input().split()))

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

low=2
high=3
for item in A[::-1]:
    if high<item:
        print(-1)
        exit()
    elif item<low:
        low=(-((-low)//item))*item
        high=low+item-1
    else:
        low=item
        high=low+item-1
print(low,high)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
K=int(input())
A=list(map(int,input().split()))

low=2
high=3
for item in A[::-1]:
    if high<item:
        print(-1)
        exit()
    elif item<low:
        low=(-((-low)//item))*item
        high=low+item-1
    else:
        low=item
        high=low+item-1
    
print(low,high)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
K=int(input())
A=list(map(int,input().split()))

pre=A[-1]
count=1
for i in range(len(A)-1)[::-1]:
    if A[i]==1:
        continue
    if A[i]>=2*pre:
        print(-1)
        exit()
    elif A[i]<pre:
        count+=1
    pre=A[i]

print(count*pre,count*pre+pre-1)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
K=int(input())
A=list(map(int,input().split()))

pre=A[-1]
count=1
for i in range(len(A)-1)[::-1]:
    if A[i]>=2*pre:
        print(-1)
        exit()
    elif A[i]<pre:
        count+=1
    pre=A[i]

print(count*A[0],count*A[0]+A[0]-1)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
K=int(input())
A=list(map(int,input().split()))

pre=A[-1]
count=1
for i in range(len(A)-1)[::-1]:
    if A[i]>2*pre:
        print(-1)
        exit()
    elif A[i]<pre:
        count+=1
    pre=A[i]

print(count*A[0],count*A[0]+A[0]-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
l = list(map(int,input().split()))
for i in range(k-1,-1,-1):
    if i == k-1:
        if l[i] == 2:
            ans = [2,3]
        else:
            ans = [-1]
            break
    else:
        if l[i] > ans[1]:
            ans = [-1]
            break
        else:
            if l[i] >= ans[0]:
                ans[0] = l[i]
            else:
                b0 = ans[0]
                c = l[i]
                if b0%c == 0:
                    ans[0] = b0
                else:
                    if (b0//c+1)*c > l[i+1]+b0:
                        ans = [-1]
                        break
                    else:
                        ans[0] = (b0//c+1)*c
            b1 = ans[1]
            c = l[i]
            if b1%l[i] == 0:
                ans[1] = b1+l[i]-1
            else:
                ans[1] = (b1//c)*c+c-1
    
    #print(ans)
for i in ans:
    print(i,end=" ")

Submission status: Wrong Answer

Solution code:
k = int(input())
l = list(map(int,input().split()))
for i in range(k-1,-1,-1):
    if i == k-1:
        if l[i] == 2:
            ans = [2,3]
        else:
            ans = [-1]
            break
    else:
        if l[i] >= l[i+1]*2:
            ans = [-1]
            break
        else:
            if l[i] >= l[i+1]:
                ans[0] = max(ans[0],l[i])
                ans[1] = max(2*l[i]-1,ans[1])
            else:
                b0 = ans[0]
                b1 = ans[1]
                c = l[i]
                if b0%c == 0:
                    ans[0] = b0
                else:
                    ans[0] = (b0//c+1)*c
                if b1%c == 0:
                    ans[1] = b1
                else:
                    ans[1] = (b1//c)*c+c-1
    #print(ans)
for i in ans:
    print(i,end=" ")

Submission status: Wrong Answer

Solution code:
k = int(input())
l = list(map(int,input().split()))
for i in range(k-1,-1,-1):
    if i == k-1:
        if l[i] == 2:
            ans = [2,3]
        else:
            ans = [-1]
            break
    else:
        if l[i] >= l[i+1]*2:
            ans = [-1]
            break
        else:
            if l[i] >= l[i+1]:
                ans[0] = l[i]
                ans[1] = 2*l[i]-1
            else:
                b0 = ans[0]
                b1 = ans[1]
                c = l[i]
                if b0%c == 0:
                    ans[0] = b0
                else:
                    ans[0] = (b0//c+1)*c
                if b1%c == 0:
                    ans[1] = b1
                else:
                    ans[1] = (b1//c)*c+c-1
    #print(ans)
for i in ans:
    print(i,end=" ")

Submission status: Wrong Answer

Solution code:
k = int(input())
l = list(map(int,input().split()))
for i in range(k-1,-1,-1):
    if i == k-1:
        if l[i] == 2:
            ans = [2,3]
        else:
            ans = [-1]
            break
    else:
        if l[i] >= l[i+1]*2:
            ans = [-1]
            break
        else:
            if l[i] >= l[i+1]:
                ans[0] = l[i]
                ans[1] = 2*l[i]-1
            else:
                b0 = ans[0]
                b1 = ans[1]
                c = l[i]
                if b0%c == 0:
                    ans[0] = b0
                else:
                    ans[0] = (b0//c+1)*c
                if b1%c == 0:
                    ans[1] = b1-c
                else:
                    ans[1] = (b1//c)*c+c-1
    #print(ans)
for i in ans:
    print(i,end=" ")

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

K, *A = map(int, read().split())
maximum = 2
minimum = 2
for i in A[::-1]:
    if i > maximum:
        print(-1)
        exit()
    if i >= minimum:
        new_minimum = i
    else:
        new_minimum = (minimum * 2 - 1) // i * i
    new_maximum = maximum // i * i + i - 1
    if minimum <= new_minimum <= new_maximum and maximum <= new_maximum:
        minimum, maximum = new_minimum, new_maximum
    else:
        print(-1)
        exit()

print(minimum, maximum)

Submission status: Wrong Answer

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline

K, *A = map(int, read().split())
maximum = 2
minimum = 2
for i in A[::-1]:
    if i >= minimum:
        new_minimum = i
    else:
        new_minimum = (minimum * 2 - 1) // i * i
    new_maximum = maximum // i * i + i - 1
    if minimum <= new_minimum <= new_maximum and maximum <= new_maximum:
        minimum, maximum = new_minimum, new_maximum
    else:
        print(-1)
        exit()

print(minimum, maximum)

Submission status: Wrong Answer

Solution code:
def div_ceil(x, y): return (x + y - 1) // y

N = int(input())
*A, = map(int, input().split())
cand_min, cand_max = 2, 2
for a in reversed(A):
    if div_ceil(cand_min, a) > cand_max: print(-1); break
    cand_min = div_ceil(cand_min, a) * a
    cand_max = (cand_max // a) * a + a - 1
else:
    print(cand_min, cand_max)

Submission status: Wrong Answer

Solution code:
def div_ceil(x, y): return (x + y - 1) // y

N = int(input())
*A, = map(int, input().split())
cand_min, cand_max = 2, 2
for a in reversed(A):
    if a > cand_max: print(-1); break
    cand_max = (cand_max // a) * a
    cand_min = div_ceil(cand_min, a) * a
    cand_max = cand_max + a - 1
else:
    cand_max = (cand_max // a) * a
    print(cand_min, cand_max)

Submission status: Wrong Answer

Solution code:
def div_ceil(x, y): return (x + y - 1) // y

N = int(input())
*A, = map(int, input().split())
cand_min, cand_max = 2, 2
for a in reversed(A):
    if a > cand_max: print(-1); break
    cand_max = (cand_max // a) * a
    cand_min = div_ceil(cand_min, a) * a
    cand_max = cand_max + a - 1
else:
    print(cand_min, cand_max)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.reverse()
m=[2,3]
if l[0]!=2:
    print(-1)
    exit()
for i in range(1,n):
    p=l[i]
    s=-(-m[0]//p)*p
    e=(m[1]//p)*p+p-1
    if not m[0]<=s<=m[1]:
        print(-1)
        exit()
    m=[s,min(m[1],e)]
print(*m)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.reverse()
m=[2,3]
if l[0]!=2:
    print(-1)
    exit()
for i in range(1,n):
    p=l[i]
    s=-(-m[0]//p)*p
    e=(m[1]//p)*(p+1)
    if not m[0]<=s<=m[1]:
        print(-1)
        exit()
    m=[s,e-1]
print(*m)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
l.reverse()
m=[2,3]
if l[0]!=2:
    print(-1)
    exit()
for i in range(1,n):
    p=l[i]
    s=-(-m[0]//p)*p
    e=(m[1]//p)*p
    if not m[0]<=s<=m[1]:
        print(-1)
        exit()
    m=[s,e]
print(*m)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20
MOD = 10**9 + 7
# def combmod(n, k, mod=MOD):
#     if k == 0:
#         return 1
#     if k == 1:
#         return n
#     ret = 1
#     for i in range(n - k + 1, n + 1):
#         ret *= i
#         ret %= mod
#
#     for i in range(1, k + 1):
#         ret *= pow(i, mod - 2, mod)
#         ret %= mod
#
#     return ret
#
#
# class Segtree_op():
#     def __init__(self, n):
#         self.size = 1
#         while (n >= 1):
#             self.size = self.size << 1
#             n = n // 2
#
#         self.arr = [self.unit() for i in range(self.size * 2)]
#
#     def op(self, lch, rch):
#         # update min with holding index
#         return lch + rch
#
#     def unit(self):
#         return 0
#
#     def update(self, k, val):
#         k += self.size - 1
#         self.arr[k] = val
#         while (k):
#             k = (k - 1) // 2
#             self.arr[k] = self.op(self.arr[k * 2 + 1], self.arr[k * 2 + 2])
#
#     def query(self, l, r):
#         L = l + self.size
#         R = r + self.size
#         s = self.unit()
#         while L < R:
#             if R & 1:
#                 R -= 1
#                 s = self.op(s, self.arr[R - 1])
#
#             if L & 1:
#                 s = self.op(s, self.arr[L - 1])
#                 L += 1
#             L >>= 1
#             R >>= 1
#         return s
#
# def update_daikou(st, k):
#     st.update(k, (st.query(0,k+1)) % MOD)
    # print(st.arr)

def main():
    k = getList()
    nums = getList()
    mn, mx = 2,2
    for num in nums[::-1]:
        if mx < num:
            print(-1)
            return
        mn = num * math.ceil(mn / num)
        mx = num * (mx// num) + num - 1
        # print(mn, mx)
        # if mx < num:
        #     print(-1)
        #     return

    print(mn, mx)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20
MOD = 10**9 + 7
# def combmod(n, k, mod=MOD):
#     if k == 0:
#         return 1
#     if k == 1:
#         return n
#     ret = 1
#     for i in range(n - k + 1, n + 1):
#         ret *= i
#         ret %= mod
#
#     for i in range(1, k + 1):
#         ret *= pow(i, mod - 2, mod)
#         ret %= mod
#
#     return ret
#
#
# class Segtree_op():
#     def __init__(self, n):
#         self.size = 1
#         while (n >= 1):
#             self.size = self.size << 1
#             n = n // 2
#
#         self.arr = [self.unit() for i in range(self.size * 2)]
#
#     def op(self, lch, rch):
#         # update min with holding index
#         return lch + rch
#
#     def unit(self):
#         return 0
#
#     def update(self, k, val):
#         k += self.size - 1
#         self.arr[k] = val
#         while (k):
#             k = (k - 1) // 2
#             self.arr[k] = self.op(self.arr[k * 2 + 1], self.arr[k * 2 + 2])
#
#     def query(self, l, r):
#         L = l + self.size
#         R = r + self.size
#         s = self.unit()
#         while L < R:
#             if R & 1:
#                 R -= 1
#                 s = self.op(s, self.arr[R - 1])
#
#             if L & 1:
#                 s = self.op(s, self.arr[L - 1])
#                 L += 1
#             L >>= 1
#             R >>= 1
#         return s
#
# def update_daikou(st, k):
#     st.update(k, (st.query(0,k+1)) % MOD)
    # print(st.arr)

def main():
    k = getList()
    nums = getList()
    mn, mx = 2,2
    for num in nums[::-1]:
        mn = num * math.ceil(mn / num)
        mx = num * (mx// num) + num - 1
        # print(mn, mx)
        if mx < num:
            print(-1)
            return

    print(mn, mx)

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
A = [1] + list(map(int, input().split()))
m = M = 2
for i in range(k):
  latter, former = A[k-1-i], A[k-i]
  l = m
  r = M+former-1
  m = l + ((-l)%latter)
  M = r - r%latter
  if m > M:
    print(-1)
    break
else:
  print(m, M)

Submission status: Wrong Answer

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

a.reverse()
print(a)

now=[]
now.append(2)

for group in a:
    nxt_now = []
    for num in now:
        if num % group !=0:
            continue

        for i in range(group):
            nxt_now.append(num+i)
    if len(nxt_now) ==0:
        print(-1)
        exit()

    now = nxt_now
print(min(now),max(now))

Submission status: Wrong Answer

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

if A[K-1] == 2:
    m = 2
    flag = True
    for i in range(K-2, -1, -1):
        prev = m
        if A[i] >= A[i+1]:
            m = A[i]
        else:
            m += A[i]-(m%A[i])
        if m-m%A[i+1] != prev:
            flag = False
    if flag:
        ans = str(m) + " " + str(m+A[0]-1)
    else:
        ans = -1
else:
    ans = -1

print(ans)

Submission status: Wrong Answer

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

if A[K-1] == 2:
    l = 2
    flag = True
    for i in range(K-2, -1, -1):
        if A[i+1] > 1:
            if l%A[i+1] > 0:
                l += A[i+1]-(l%A[i+1])
            r = l+A[i+1]-1
        if l%A[i] > 0:
            l += A[i]-(l%A[i])
        r -= r%A[i]
        if r < l:
            flag = False
            break
    if flag:
        if l%A[0] > 0:
            l += A[0]-(l%A[0])
        r = l+A[0]-1
        ans = str(l) + " " + str(r)
    else:
        ans = -1
else:
    ans = -1

print(ans)

Submission status: Wrong Answer

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

if A[K-1] == 2:
    l = 2
    flag = True
    for i in range(K-2, -1, -1):
        r = l+A[i+1]-1
        if A[i] > r:
            flag = False
            break
        if l%A[i] > 0:
            l += A[i]-(l%A[i])
        r -= r%A[i]
    if flag:
        if l%A[0] > 0:
            l += A[0]-(l%A[0])
        r = l+A[0]-1
        ans = str(l) + " " + str(r)
    else:
        ans = -1
else:
    ans = -1

print(ans)

Submission status: Wrong Answer

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

if A[K-1] == 2 and 2 <= A[K-2] <= 3:
    l = 2
    r = 2
    flag = True
    for i in range(K-2, -1, -1):
        if l%A[i+1] > 0:
            l += A[i+1]-(l%A[i+1])
        r = l+A[i+1]-1
        if l%A[i] > 0:
            l += A[i]-(l%A[i])
        r -= r%A[i]
        if r < l:
            flag = False
            break
    if flag:
        if l%A[0] > 0:
            l += A[0]-(l%A[0])
        r = l+A[0]-1
        ans = str(l) + " " + str(r)
    else:
        ans = -1
else:
    ans = -1

print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    _ = int(input())
    *a, = map(int, input().split())

    if a[-1] > 2:
        print(-1)
        return

    mi, ma = 2, 2
    for x in reversed(a):
        if x > ma:
            print(-1)
            return

        mi = ((mi + x - 1) // x) * x
        ma = mi + x - 1

    print(mi, ma)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:




K = int(input())

A = list(map(int, input().split()))

if K == 1:
    print(2,3)
    exit()

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

big = 2
small = 2
for i in reversed(range(K)):
    """
    smallのときにai人組つくると脱落者なし
    bigのときにai人組作るとai-1人脱落

    """


    # smallは元のsmall以上かつ、脱落者なし
    small = ((small - 1) // A[i] + 1) * A[i]
        
    # bigは元のbig以上かつ、脱落者がai-1
    big = (big // A[i]) * A[i] +A[i] - 1

    if big < small:
        print(-1)
        exit()


print(small, big)

Submission status: Wrong Answer

Solution code:




K = int(input())

A = list(map(int, input().split()))

if K == 1:
    print(2,3)
    exit()

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

big = 2
small = 2
for i in reversed(range(K)):
    """
    smallのときにai人組つくると脱落者なし
    bigのときにai人組作るとai-1人脱落

    """


    # smallは元のsmall以上かつ、脱落者なし
    small = ((small - 1) // A[i] + 1) * A[i]
        
    # bigは元のbig以上かつ、脱落者がai-1
    big = (big // A[i] + 1) * A[i] - 1

    if big < small:
        print(-1)
        exit()


print(small, big)

Submission status: Wrong Answer

Solution code:




K = int(input())

A = list(map(int, input().split()))

if K == 1:
    print(2,3)
    exit()

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

big = 2
small = 2
for i in reversed(range(K)):
    """
    smallのときにai人組つくると脱落者なし
    bigのときにai人組作るとai-1人脱落

    """


    # smallは元のsmall以上かつ、脱落者なし
    if small // A[i] > 0 and small % A[i] > 0:
        small = (small // A[i] + 1) * A[i]
    elif small // A[i] > 0 and small % A[i] == 0:
        small = small
    elif small // A[i] == 0:
        small = A[i] 
        
    # bigは元のbig以上かつ、脱落者がai-1
    big = (big // A[i] + 1) * A[i] - 1

    if big < small:
        print(-1)
        exit()


print(small, big)