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

Solution (Python):
import math
K=int(input())
A_lst=[int(_) for _ in input().split() ]

failed=False
if A_lst[-1]!=2:
    failed=True
else:
    stt, end=2,4
    for a in A_lst[-2::-1]:
        
        stt=a*math.ceil(stt/a)
        if stt>= end:
            failed=True
            break
        end=a*math.ceil(end/a)

if failed:
    print(-1)
else:
    print(stt, end-1)

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

def main():
    mi = ma = 2
    for a in A[::-1]:
        if mi % a:
            mi += a - (mi % a)
        ma += (a - 1) - (ma % a)
        if ma < mi:
            print(-1)
            return
    print(mi, ma)

main()

Solution (Python):
import sys

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

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

minn = 2
maxn = 3

for i in range(len(A) - 2, -1, -1):
    m = A[i]
    a = (minn + m - 1) // m * m
    b = maxn // m * m
    if b < a:
        print(-1)
        sys.exit()
    minn = a
    maxn = b + m - 1

print(minn, maxn)

Solution (Python):
n=int(raw_input())
A=map(int,raw_input().split())
A.reverse()
[p,q]=[2,2]
for a in A:
    if p%a==0:
        p=p
    else:
        p=a*(p/a+1)
        if p>q:
            print -1
            break
    q=a*(max(q/a,p/a)+1)-1
else:
    print p,q

Solution (Python):
import sys

sys.stdin.readline()
As = list(map(int, sys.stdin.readline().split()))
As.reverse()

min = 2
max = 2

for a in As:
    min = ((min-1)//a+1)*a
    max = (max//a+1)*a-1
    
    if min > max:
        print(-1)
        sys.exit()
print(min, max)

Solution (Python):
from math import ceil


def solve(rounds):
    mx, mn = 3, 2
    if rounds[-1] != 2:
        return (-1,)
    for r in reversed(rounds[:-1]):
        if mx < r:
            return (-1,)
        mn = ceil(mn / r) * r
        mx = mx // r * r + r - 1
    if mn > mx:
        return (-1,)
    return mn, mx


k = int(input())
rounds = list(map(int, input().split()))
print(*solve(rounds))

Solution (Python):


K = int(input())
A=[int(i) for i in input().split()]
L = 2
R = 2
flag = 0


for i in range(K):
    LL = A[K-1-i]*((L+A[K-1-i]-1)//A[K-1-i])
    RR = A[K-1-i]*(R//A[K-1-i])
    if LL > R:
        flag = -1
        L = 2
        R = 1
    else:
        L = LL
        R = RR+A[K-1-i]-1
        
if flag == -1:
    print(-1)
else:
    print(L,R)

Solution (Python):
def main():
    n = int(raw_input())
    a = map(int, raw_input().split())
    if a[-1] > 2:
        print -1
        return
    lo = hi = 2
    for x in reversed(a):
        if hi < x:
            print -1
            return
        nlo = (lo + x - 1) / x * x
        nhi = hi / x * x + x - 1
        if nlo > nhi:
            print -1
            return
        lo = nlo
        hi = nhi
    print lo, hi
main()

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

l, r = 2, 2
for x in a:
    lb = max((l + x - 1) // x, 1)
    rb = r // x
    if rb < lb:
        print(-1)
        quit(0)
    l, r = lb * x, rb * x + x - 1

print(l, r)

Solution (Python):
K = input()
A = map(int, raw_input().split())
if A[-1]!=2:
  print -1
  exit(0)
mn = 2
mx = 3
for a in A[-2::-1]:
  mn = (mn+a-1)/a*a
  mx = mx/a*a+a-1
if mn<=mx:
  print mn, mx
else:
  print -1

Solution (Python):
h = input()
A = map(int, raw_input().split())[::-1]

l = 2
r = 2

def ng():
  print "-1"
  exit()

for a in A:
  l = l / a * a + (l % a != 0) * a
  r = r / a * a
  if r < l:ng()
  r += a-1

print l, r