Problem: 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.

Submission attempts (in order):
import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

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


"""max"""
for i in range(0,K-1):
    drop_num = []
    for j in range(0,A[i]):  
        if ( jmax + j ) % A[i+1] == 0:
            drop_num.append(j)

        if drop_num == []:  
            print(-1)
            sys.exit()

    max_drop = max(drop_num)
    jmax = jmax + max_drop

jmax = jmax + A[K-1] -1


"""min"""
for i in range(0,K-1):
    drop_num = []
    for j in range(0,A[i]):  
        if ( jmin + j ) % A[i+1] == 0:
            drop_num.append(j)

        if drop_num == []:  
            print(-1)
            sys.exit()

    min_drop = min(drop_num)
    jmin = jmin + min_drop


print(jmin, jmax)

import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2
#print(A)

for h in range(0,K):
    if A[h] <= A[h+1]:
        print(-1)
        sys.exit()

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



for i in range(0,K-1):  
    drop_num = []
    for j in range(0,A[i]):  
        if ( jmax + j ) % A[i+1] == 0:
            drop_num.append(j)
        if ( jmin + j ) % A[i+1] == 0:
            drop_num.append(j)
    if drop_num == []:  
        print(-1)
        sys.exit()
    max_drop = max(drop_num)
    jmax = jmax + max_drop
    min_drop = min(drop_num)
    jmin = jmin + min_drop


jmax = jmax + A[K-1] -1

print(jmin, jmax)


import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2
#print(A)

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

"""max"""
for i in range(0,K-1):  
    drop_num = []
    for j in range(0,A[i]):  
        if ( jmax + j ) % A[i+1] == 0:
            #print(j)
            drop_num.append(j)
            print(drop_num)

    if drop_num == []:  
        print(-1)
        sys.exit()

    max_drop = max(drop_num)
    jmax = jmax + max_drop


jmax = jmax + A[K-1] -1


"""min"""
for i in range(0,K-1):
    drop_num = []
    for j in range(0,A[i]):  
        if ( jmin + j ) % A[i+1] == 0:
            drop_num.append(j)

    if drop_num == []:  
        print(-1)
        sys.exit()

    min_drop = min(drop_num)
    jmin = jmin + min_drop



print(jmin, jmax)


from math import floor,ceil
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

for i in range(0,K):
    if jmin % A[i] != 0:
        if (jmin + (A[i] - (jmin % A[i]))) > jmin:
            print(-1)
            exit()

    jmin = ceil(jmin / A[i]) * A[i]
    jmax = floor(jmax / A[i]) * A[i] + A[i] -1

print(jmin, jmax)



import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

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

for i in range(0,K-1):  
    Round = list(range(jmin,jmax+1))
    decide = [Round[h] % A[i] for h in range(len(Round))]
    if not(0 in decide):
        print(-1)
        sys.exit()
    jmin = (int(jmin/A[i])+1)*A[i]
    jmax = (int(jmax/A[i]))*A[i] +A[i]-1

jmax = jmax + A[K-1] -1

print(jmin, jmax)


import sys
import math
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

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

for i in range(0,K-1):  
    Round = list(range(jmin,jmax+1))
    decide = [Round[h] % A[i] for h in range(len(Round))]
    if not(0 in decide):
        print(-1)
        sys.exit()
    jmin = (math.ceil(jmin / A[i])) * A[i]
    jmax = (math.floor(jmax / A[i])) * A[i] + A[i] -1

jmax = jmax + A[K-1] -1

print(jmin, jmax)


import sys
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

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

for i in range(0,K-1):  
    Round = list(range(jmin,jmax+1))
    if not(0 in Round % A[i]):
        print(-1)
        sys.exit()
    jmin = (int(jmin/A[i])+1)*A[i]
    jmax = (int(jmax/A[i]))*A[i] +A[i]-1

jmax = jmax + A[K-1] -1

print(jmin, jmax)


from math import floor,ceil
K = int(input())
A = [int(x) for x in input().split()]
A.reverse()
jmax, jmin = 2,2

for i in range(0,K):
    if jmin % A[i] != 0:
        if (jmin + (A[i] - (jmin % A[i]))) > jmax:
            print(-1)
            exit()

    jmin = ceil(jmin / A[i]) * A[i]
    jmax = floor(jmax / A[i]) * A[i] + A[i] -1
    
print(jmin, jmax)


    

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Accepted