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):
K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    if nowM < A[i]:
        ans = -1
        break
    elif nowm <= A[i]:
        nowm = A[i]
        nowM = A[i]*2 - 1
    else:
        nowm = (nowm//A[i]+1)*A[i]
        if nowm > nowM:
            ans = -1
            break
        nowM += A[i] -1
        # nowM = (nowM//A[i]+1)*A[i] - 1
        # if nowm >= nowM:
        #     nowM = nowm + A[i] -1
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))



K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    a = A[i]
    if nowm <= ((nowm+a-1)//a)*a and ((nowm+a-1)//a)*a <= nowM:
        nowm = ((nowm+a-1)//a)*a
        nowM = (nowM//a)*a + a - 1
    else:
        ans = -1
        break
    print(nowm, nowM)
    # if nowM < A[i]:
    #     ans = -1
    #     break
    # elif nowm <= A[i]:
    #     nowm = A[i]
    #     nowM = A[i]*2 - 1
    # else:
    #     M = nowM
    #     nowm = (nowm//A[i]+1)*A[i]
    #     if nowm > M:
    #         ans = -1
    #         break
    #     if (nowM//A[i]+1)*A[i] <= M:
    #         nowM = (nowM//A[i]+1)*A[i] - 1
    #         if nowM < nowm:
    #             nowM = nowm + A[i] - 1
    #     else:
    #         nowM = nowm + A[i] - 1
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))


K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    if nowM < A[i]:
        ans = -1
        break
    elif nowm <= A[i]:
        nowm = A[i]
        nowM = A[i]*2 - 1
    else:
        nowm = (nowm//A[i]+1)*A[i]
        nowM = (nowM//A[i]+1)*A[i] - 1
        if nowm > nowM:
            nowM = nowm + A[i] -1
    print(nowm, nowM)
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))


K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    a = A[i]
    if nowm <= ((nowm+a-1)//a)*a and ((nowm+a-1)//a)*a <= nowM:
        nowm = ((nowm+a-1)//a)*a
        nowM = (nowM//a)*a + a - 1
    else:
        ans = -1
        break
    # if nowM < A[i]:
    #     ans = -1
    #     break
    # elif nowm <= A[i]:
    #     nowm = A[i]
    #     nowM = A[i]*2 - 1
    # else:
    #     M = nowM
    #     nowm = (nowm//A[i]+1)*A[i]
    #     if nowm > M:
    #         ans = -1
    #         break
    #     if (nowM//A[i]+1)*A[i] <= M:
    #         nowM = (nowM//A[i]+1)*A[i] - 1
    #         if nowM < nowm:
    #             nowM = nowm + A[i] - 1
    #     else:
    #         nowM = nowm + A[i] - 1
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted