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

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

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

big = 2
small = 2
for i in reversed(range(K)):


    # minはA[i]で割って一組できる数かつ、それ以前のminより大きい
    if A[i] < small:
        small = (small // A[i] + 1) * A[i]
    else:
        small = A[i]

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

    # maxはA[i]で割って二組できる値の1手前の数
    big = (big // A[i] + 1) * A[i] - 1
    



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



    if A[i] < small:
        small = (small // A[i] + 1) * A[i]
    else:
        small = A[i]

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



    if A[i] < small:
        t_small = (small // A[i] + 1) * A[i]
    else:
        t_small = A[i]

    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 = 3
small = 2
for i in reversed(range(K-1)):

    if A[i] < small:
        small = (small // A[i] + 1) * A[i]
    else:
        small = A[i]

    if small // A[i+1] >= 2:
        print(-1)
        exit()

    big = (big // A[i] + 1) * A[i] - 1
    if ((big // A[i]) * A[i]) // A[i+1] >= 2:
        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()

big = 3
small = 2
for i in reversed(range(K-1)):


    if A[i] > A[i+1]*2 - 1:
        print(-1)
        exit()

    if A[i] < small:
        small = (small // A[i] + 1) * A[i]
    else:
        small = A[i]

    big = (big // A[i] + 1) * A[i] - 1

print(small, big)

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys
sys.setrecursionlimit(100000)



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



directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

def f(x):
    for i in range(K):
        x = x-x % A[i]
    return x

def bisect_search(f,val=0,l=0,r=10**6):

    #is_increase=(f(r)-f(l))>=0

    eps=10**(-5)
    while True:

        c=(l+r)//2
        print(l,c,r)
        input()
        if f(c)==val and f(c-1)!=val:
            return c
        #if f(c)-val < eps:
        #    return c

        if f(c)>val:
            r=c

        else:
            l=c
        
        if l==r:
            return False

def bisect_search_int(f,val=0,l=0,r=10**6,equal=False):
    #is_increase=(f(r)-f(l))>=0
    
    eps=10**(-5)
    if not equal:
        siki = "f(c) > val"
    else:
        siki = "f(c) >= val"

    while r-l>1:

        c=(l+r)//2
        
        if eval(siki,{"c":c,"f":f,"val":val}):
            r=c            
        else:
            l=c
        
        #if l==r:
        #    return False
    if f(l)!= f(c) and f(r)!=f(c):
        return False
    return l,r



K=int(input())
A=acinput()

R = 2+K*max(A)
R=10**6

l,r=bisect_search_int(f, 2,0,R,equal=True)
if f(l)==2:
    resL=l
elif f(r)==2:
    resL=r
else:
    resL=-1

l, r = bisect_search_int(f, 2,0,R,equal=False)
#print(l,r,f(l),f(r))
if f(l) == 2:
    resR = l
elif f(r) == 2:
    resR = r
else:
    resR = -1

if resL>=0:
    print(resL,resR)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys
sys.setrecursionlimit(100000)



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



directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

def f(x):
    for i in range(K):
        x = x-x % A[i]
    return x

def bisect_search(f,val=0,l=0,r=10**6):

    #is_increase=(f(r)-f(l))>=0

    eps=10**(-5)
    while True:

        c=(l+r)//2
        print(l,c,r)
        input()
        if f(c)==val and f(c-1)!=val:
            return c
        #if f(c)-val < eps:
        #    return c

        if f(c)>val:
            r=c

        else:
            l=c
        
        if l==r:
            return False

def bisect_search_int(f,val=0,l=0,r=10**6,equal=False):
    #is_increase=(f(r)-f(l))>=0
    
    eps=10**(-5)
    if not equal:
        siki = "f(c) > val"
    else:
        siki = "f(c) >= val"

    while r-l>1:

        c=(l+r)//2
        
        if eval(siki,{"c":c,"f":f,"val":val}):
            r=c            
        else:
            l=c
        
        #if l==r:
        #    return False
    if f(l)!= f(c) and f(r)!=f(c):
        return False
    return l,r



K=int(input())
A=acinput()

r = 2+K*max(A)

l,r=bisect_search_int(f, 2,0,r,equal=True)
if f(l)==2:
    resL=l
elif f(r)==2:
    resL=r
else:
    resL=False

l, r = bisect_search_int(f, 2,0,r,equal=False)
if f(l) == 2:
    resR = l
elif f(r) == 2:
    resR = r
else:
    resR = False

if resL and resR:
    print(resL,resR)
else:
    print(-1)


#for x in range(0,20):
#    print(x,f(x))

Submission status: Wrong Answer

Solution code:

import numpy as np
import sys
sys.setrecursionlimit(100000)



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



directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

def f(x):
    for i in range(K):
        x = x-x % A[i]
    return x

def bisect_search(f,val=0,l=0,r=10**6):

    #is_increase=(f(r)-f(l))>=0

    eps=10**(-5)
    while True:

        c=(l+r)//2
        print(l,c,r)
        input()
        if f(c)==val and f(c-1)!=val:
            return c
        #if f(c)-val < eps:
        #    return c

        if f(c)>val:
            r=c

        else:
            l=c
        
        if l==r:
            return False

def bisect_search_int(f,val=0,l=0,r=10**6,equal=False):
    #is_increase=(f(r)-f(l))>=0

    eps=10**(-5)
    if not equal:
        siki = "f(c) > val"
    else:
        siki = "f(c) >= val"

    while r-l>1:

        c=(l+r)//2
        
        if eval(siki,{"c":c,"f":f,"val":val}):
            r=c            
        else:
            l=c
        
        #if l==r:
        #    return False
    if f(l)!= f(c) and f(r)!=f(c):
        return False
    return l,r



K=int(input())
A=acinput()

l,r=bisect_search_int(f, 2,equal=True)
if f(l)==2:
    resL=l
elif f(r)==2:
    resL=r
else:
    resL=False

l, r = bisect_search_int(f, 2, equal=False)
if f(l) == 2:
    resR = l
elif f(r) == 2:
    resR = r
else:
    resR = False

if resL and resR:
    print(resL,resR)
else:
    print(-1)

Submission status: Wrong Answer

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

maX=2
miN=2

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

maX=2
miN=2

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

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

Submission status: Wrong Answer

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

maX=2
miN=2

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

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

Submission status: Wrong Answer

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

maX=2
miN=2

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

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

Submission status: Wrong Answer

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

maX=2
miN=2
Amax=2

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

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

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

Submission status: Wrong Answer

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

maX=2
miN=2
Amax=2

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

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

print(miN,maX)

Submission status: Wrong Answer

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

maX=2
miN=2
Amax=2

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

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

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

print(miN,maX)

Submission status: Wrong Answer

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

maX=2
miN=2
Amax=2

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

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

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

print(miN,maX)

Submission status: Wrong Answer

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

maX=2
miN=2
ruiseki=[0 for i in range(K)]
ruiseki[-1]=2
for i in range(K-2,-1,-1):
    if A[i]>=2*ruiseki[i+1]:
        print(-1)
        exit()
    ruiseki[i]=max(ruiseki[i+1],A[i])


for i in range(K-1,-1,-1):
    if A[i]//miN>=2:
        miN=A[i]
    if miN%A[i]==0:
        pass
    else:
        miN=(miN//A[i] +1) *A[i]

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


print(miN,maX)

Submission status: Wrong Answer

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

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

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


print(miN,maX)

Submission status: Wrong Answer

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

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


print(miN,maX)

Submission status: Wrong Answer

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

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

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

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

print(miN,maX)

Submission status: Wrong Answer

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

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

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

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

print(miN,maX)

Submission status: Wrong Answer

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

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

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

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

print(miN,maX)

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(n):
    sumation = 0
    while n > 0:
        sumation += n%10
        n //= 10
    return sumation

def main():
    k = inp()
    a = inpl()
    a.reverse()
    x,y = 2,a[0]
    for i in range(k):
        pair = a[i]
        if y < pair:
            print(-1)
            return
        if (y//pair)*pair < x:
            print(-1)
            return
        if pair >= x:
            x = pair
        elif x%pair != 0:
            s = x//pair + 1
            x = s*pair
        y = (y//pair+1) * pair - 1
        if y < x:
            print(-1)
            return
    print(x,y)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(n):
    sumation = 0
    while n > 0:
        sumation += n%10
        n //= 10
    return sumation

def main():
    k = inp()
    a = inpl()
    a.reverse()
    x,y = 2,a[0]
    for i in range(k):
        pair = a[i]
        if y < pair:
            print(-1)
            return
        if i != 0:
            if x != y:
                if y//pair - x//pair <= 0:
                    print(-1)
                    return
            else:
                if x%pair != 0:
                    print(-1)
                    return
        if pair >= x:
            x = pair
        elif x%pair != 0:
            s = x//pair + 1
            x = s*pair
        y = (y//pair+1) * pair - 1
        if y < x:
            print(-1)
            return
    print(x,y)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(n):
    sumation = 0
    while n > 0:
        sumation += n%10
        n //= 10
    return sumation

def main():
    k = inp()
    a = inpl()
    a.reverse()
    x,y = 2,a[0]
    for i in range(k):
        pair = a[i]
        if y < pair:
            print(-1)
            return
        if pair >= x:
            x = pair
        elif x%pair != 0:
            s = x//pair + 1
            x = s*pair
        y = (y//pair+1) * pair - 1
        if y < x:
            print(-1)
            return
    print(x,y)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(n):
    sumation = 0
    while n > 0:
        sumation += n%10
        n //= 10
    return sumation

def main():
    k = inp()
    a = inpl()
    a.reverse()
    x,y = 2,a[0]
    for i in range(k):
        pair = a[i]
        if y < pair:
            print(-1)
            return
        if pair >= x:
            x = pair
        else:
            s = x//pair
            if x%pair != 0:
                s += 1
            x = s*pair
        y = (y//pair+1) * pair - 1
        if y < x:
            print(-1)
            return
    print(x,y)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(n):
    sumation = 0
    while n > 0:
        sumation += n%10
        n //= 10
    return sumation

def main():
    k = inp()
    a = inpl()
    a.reverse()
    x,y = 2,a[0]
    for i in range(k):
        pair = a[i]
        if y < pair:
            print(-1)
            return
        if pair >= x:
            x = pair
        else:
            s = x//pair
            if x%pair:
                s += 1
            x = s*pair
        y = ((y//pair)+1)*pair-1
        if y < x:
            print(-1)
            return
    print(x,y)
    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input()) # n=1
def inpm(): return map(int,input().split()) # x=1,y=2
def inpl(): return list(map(int, input().split())) # a=[1,2,3,4,5,...,n]
def inpls(): return list(input().split())  # a=['1','2','3',...,'n']
def inplm(n): return list(int(input()) for _ in range(n)) # x=[] 複数行
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)] # [[2,2,2,2],[1,1,1,1],[3,3,3,3]] 
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) # [[1,1,1,1],[2,2,2,2],[3,3,3,3]] 
def graph():
    n=inp()
    g=[[] for _ in range(n)]
    for i in range(n):
        a = inp()
        a -= 1
        g[i].append(a)
        g[a].append(i)
    return n,g

def f(n):
    sumation = 0
    while n > 0:
        sumation += n%10
        n //= 10
    return sumation

def main():
    k = inp()
    a = inpl()
    a.reverse()
    x,y = 2,a[0]
    for i in range(k):
        pair = a[i]
        if y < pair:
            print(-1)
            return
        if pair >= x:
            x = pair
        else:
            s = x//pair
            if x%pair:
                s += 1
            x = s*pair
        s = y//pair
        if y%pair:
            s += 1
        y = (s*pair)-1
        if y < x:
            print(-1)
            return
    print(x,y)
    
if __name__ == "__main__":
    main()