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:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [k] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    num_list = []
    for i in range(k):
        num_list.append(long(input_raw[i]))

    max_num = long(2)
    min_num = long(2)
    is_exist = True
    if num_list[k-1] != 2:
        is_exist = False
    for i in range(k-1, -1, -1):
        if is_exist == False:
            break;
        min_min_num = min_num;
        min_max_num = min_num + num_list[i] - 1
        max_min_num = max_num;
        max_max_num = max_num + num_list[i] - 1
        if i > 0:
            min_min_num = num_list[i - 1] * (min_min_num / num_list[i - 1] + (0 if (min_min_num % num_list[i - 1] == 0)  else 1) )
            min_max_num = num_list[i - 1] * long(min_max_num / num_list[i - 1] )
            max_min_num = num_list[i - 1] * (max_min_num / num_list[i - 1] + (0 if (max_min_num % num_list[i - 1] == 0)  else 1) )
            max_max_num = num_list[i - 1] * long(max_max_num / num_list[i - 1] )

        if(min_min_num > min_max_num and max_min_num > max_max_num):
            is_exist = False
            break;
        elif(min_min_num > min_max_num and max_min_num <= max_max_num):
            min_num = max_min_num
            max_num = max_max_num
        elif(min_min_num <= min_max_num and max_min_num > max_max_num):
            min_num = min_min_num
            max_num = min_max_num
        else:
            min_num = min(min_min_num, max_min_num)
            max_num = max(min_max_num, max_max_num)
        if min_num > max_num:
            is_exist = False
            break;

    if is_exist == True:
        print min_num, max_num
    else:
        print -1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

last = A[0]
pattern = 0

A.reverse()
B = A[:]
C = A[:]

if A[0] != 2:
    pattern = 1
    print(-1)
else:
    for i in range(len(A)-1):
        k = math.ceil(A[i]/A[i+1])
        if  A[i]<= k*A[i+1]  and k*A[i+1] <= A[i]+B[i]-1:
            A[i+1]=k*A[i+1]
        else:
            pattern = 1
            print(-1)
            break
    if pattern == 0:
        for i in range(len(A)-1):
            k = math.floor((C[i]+B[i]-1)/C[i+1])
            if  C[i]<= k*C[i+1]  and k*C[i+1] <= C[i]+B[i]-1:
                C[i+1]=k*C[i+1]

        
if pattern == 0:
    print(A[-1], C[-1]+last -1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# coding=utf-8

import math
import sys

k = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split(" ")))[::-1]
flag = True
n = 2
m = 2
for i in a:
    if math.ceil(n / i) * i >= 2 * n:
        flag = False
        break
    n = math.ceil(n / i) * i
    m = max(m, n+i-1)
if flag:
    print("{} {}".format(n, m))
else:
    print("-1")

Submission status: Wrong Answer

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

last = A[0]
pattern = 0

A.reverse()
B = A[:]
C = A[:]

if A[0] != 2:
    pattern = 1
    print(-1)
else:
    for i in range(len(A)-1):
        k = math.ceil(A[i]/A[i+1])
        if  A[i]<= k*A[i+1]  and k*A[i+1] <= A[i]+B[i]-1:
            A[i+1]=k*A[i+1]
        else:
            pattern = 1
            print(-1)
            break
    
    for i in range(len(A)-1):
        k = math.floor((C[i]+B[i]-1)/C[i+1])
        if  C[i]<= k*C[i+1]  and k*C[i+1] <= C[i]+B[i]-1:
            C[i+1]=k*C[i+1]
        else:
            pattern = 1
            print(-1)
            break
        
if pattern == 0:
    print(A[-1], C[-1]+last -1)

Submission status: Wrong Answer

Solution code:
import math
t=int(input())
a=list(map(int,input().split()))
sum=2
for i in range(t-2,0,-1):
	if(a[i]//a[i+1]>1):
		sum=-1
		break
	else:
		if(a[i]>=sum):
			sum=a[i]
		else:
			x=math.ceil(sum/a[i])
			sum=a[i]*x
		if(sum%a[i+1]==0):
			sum=-1
			break			
if(sum==-1):					
	print(sum)
else:
	if(a[0]>=sum):
		print(a[0],a[0]*2-1)
	else:
		x=math.ceil(sum/a[0])
		sum=a[0]*x
		print(sum,a[0]*(x+1)-1)

Submission status: Wrong Answer

Solution code:
k = int(raw_input())
a = map(int,raw_input().split(" "))

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

r = [2,3]
ainv = a[::-1]

for now in ainv[1:]:
  lower = (r[0]/now)*now
  if lower < r[0]:
    lower += now
  q = [lower,lower + now - 1]

  if (lower + now - 1) < r[1]:
    upper = r[1]
  else:
    upper = lower + now - 1

  if q[0] > r[1]:
    print "-1"
    exit(0)
  q = [lower,upper]
  #print r,q
  r = q

print "%d %d" % (r[0],r[1])

Submission status: Wrong Answer

Solution code:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [k] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    num_list = []
    for i in range(k):
        num_list.append(int(input_raw[i]))

    max_num = 2
    min_num = 2
    is_exist = True
    if num_list[k-1] != 2:
        is_exist = False
    for i in range(k-1, -1, -1):
        if is_exist == False:
            break;
        min_min_num = min_num;
        min_max_num = min_num + num_list[i] - 1
        max_min_num = max_num;
        max_max_num = max_num + num_list[i] - 1
        if i > 0:
            min_min_num = num_list[i - 1] * (min_min_num / num_list[i - 1] + (0 if (min_min_num % num_list[i - 1] == 0)  else 1) )
            min_max_num = num_list[i - 1] * int(min_max_num / num_list[i - 1] )
            max_min_num = num_list[i - 1] * (max_min_num / num_list[i - 1] + (0 if (max_min_num % num_list[i - 1] == 0)  else 1) )
            max_max_num = num_list[i - 1] * int(max_max_num / num_list[i - 1] )

        if(min_min_num > min_max_num and max_min_num > max_max_num):
            is_exist = False
            break;
        elif(min_min_num > min_max_num and max_min_num <= max_max_num):
            min_num = max_min_num
            max_num = max_max_num
        elif(min_min_num <= min_max_num and max_min_num > max_max_num):
            min_num = min_min_num
            max_num = min_max_num
        else:
            min_num = min(min_min_num, max_min_num)
            max_num = max(min_max_num, max_max_num)
        if min_num > max_num:
            is_exist = False
            break;

    if is_exist == True:
        print min_num, max_num
    else:
        print -1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    n = len(a)
    s = list()
    s.append(2)
    s.append(3)

    for i in range(n-1,-1,-1):
        if len(s) == 0:
            print("-1")
            return
        ss = list()
        for numb in s:
            if numb % int(a[i]) == 0:
                for t in range(numb, numb + int(a[i]), 1):
                    ss.append(t)
        s = ss

    mi = 9999999999
    ma = -1
    for f in s:
        mi = min(mi, f)
        ma = max(ma, f)
    print(mi, ma)
    return
    
#main
k = int(input())
a = list(input().split())
solve()

##2
##2[3,2]
##3[3,4,5]
##4[4,5,6,7]
##3[6,7,8]

Submission status: Wrong Answer

Solution code:
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

input()
test=raw_input().split(" ")
test=map(int, test)

suma=1
for i in test:
	suma *= i
test1 = prime_decomposition(suma)
test1 = list(set(test1))

minn=1
for i in test1:
	minn *= i


maxi = minn + test[0]-1 

temp = minn
for i in test:
	temp = temp- (temp%i)

if temp!=2:
	print(-1)
else:
	print(str(minn)+" "+str(maxi))

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    A = tuple(map(int, input().split()))

    a = A[::-1]
    prev = 2
    for i in a:
        if i < prev:
            n = i * ((prev + i - 1) // i)
        else:
            if i // prev > 1:
                print(-1)
                return
            else:
                n = i
        prev = n

    min_ = prev
    max_ = (min_ // i + 1) * i - 1
    print(min_, max_)

main()

Submission status: Wrong Answer

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

Max, Min = 0, 0
error = -1

def N_max(a, Max, Min):
    if Max > a and Min%a != 0:
        return a*(Min//a + 2) - 1
    elif Max > a and Min%a == 0:
        return a*(Min//a + 1) - 1
    else:
        return a*2 -1
        
def N_min(a, m):
    if m > a:
        return a*(m//a + 1)
    else:
        return a

for i in range(K)[::-1]:
    #print(A[i])

    if A[-1] == 2:
        if i == 0:                      #最後の処理
            Max = N_max(A[i], Max, Min)
            Min = N_min(A[i], Min)
            print(Min, Max)
            break
        
        elif A[i-1]/A[i] <= 2:          #次の値が2倍以下（最後以外）
            Max = N_max(A[i], Max, Min)
            Min = N_min(A[i], Min)

        else:
            print(error)
            break
 
    else:
        print(error)
        break

Submission status: Wrong Answer

Solution code:
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

input()
test=raw_input().split(" ")

suma=1
for i in test:
	suma *= int(i)
test1 = prime_decomposition(suma)
test1 = list(set(test1))

minn=1
for i in test1:
	minn *= int(i)


maxi = minn + int(test[0])-1 

temp = minn
for i in test:
	temp = temp- (temp%int(i))

if temp!=2:
	print(-1)
else:
	print(str(minn)+" "+str(maxi))

Submission status: Wrong Answer

Solution code:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [k] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    num_list = []
    for i in range(k):
        num_list.append(int(input_raw[i]))

    max_num = 2
    min_num = 2
    is_exist = True
    for i in range(k-1, -1, -1):
        min_min_num = min_num;
        min_max_num = min_num + num_list[i] - 1
        max_min_num = max_num;
        max_max_num = max_num + num_list[i] - 1
        if i > 0:
            min_min_num = num_list[i - 1] * (min_min_num / num_list[i - 1] + (0 if (min_min_num % num_list[i - 1] == 0)  else 1) )
            min_max_num = num_list[i - 1] * int(min_max_num / num_list[i - 1] )
            max_min_num = num_list[i - 1] * (max_min_num / num_list[i - 1] + (0 if (max_min_num % num_list[i - 1] == 0)  else 1) )
            max_max_num = num_list[i - 1] * int(max_max_num / num_list[i - 1] )

        if(min_min_num > min_max_num and max_min_num > max_max_num):
            is_exist = False
            break;
        elif(min_min_num > min_max_num and max_min_num <= max_max_num):
            min_num = max_min_num
            max_num = max_max_num
        elif(min_min_num <= min_max_num and max_min_num > max_max_num):
            min_num = min_min_num
            max_num = min_max_num
        else:
            min_num = min(min_min_num, max_min_num)
            max_num = max(min_max_num, max_max_num)
        if min_num > max_num:
            is_exist = False
            break;

    if is_exist == True:
        print min_num, max_num
    else:
        print -1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-2,-1,-1):
        t = a[i]
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b += t-b%t
            if b % t != 0:
                return 1/0
        else:
            b = t
        if c % t == 0:
            pass
        elif c > t:
            c += t-c%t
        else:
            return -1
    bb = b
    cc = c-1
    while True:
        bb = b
        for i in range(n):
            bb -= bb%a[i]
        if bb != 2:
            return -2
            b += a[0]
        else:
            break
    for i in range(n):
        cc -= cc%a[i]
    if cc != 2:
        return 1/0

    return '{} {}'.format(b, c-1)

print(main())

Submission status: Wrong Answer

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

last = A[0]
pattern = 0

A.reverse()
B = A[:]

if A[0] != 2:
    pattern = 1
    print(-1)
else:
    for i in range(len(A)-1):
        k = math.ceil(A[i]/A[i+1])
        if  A[i]<= k*A[i+1]  and k*A[i+1] <= A[i]+B[i]-1:
            A[i+1]=k*A[i+1]
        else:
            pattern = 1
            print(-1)
            break
        
if pattern == 0:
    print(A[-1], A[-1]+last -1)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# coding=utf-8

import math
import sys

k = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split(" ")))[::-1]
flag = True
n = 2
for i in a[1:]:
    if math.ceil(n / i) * i >= 2 * n:
        flag = False
        break
    n = math.ceil(n / i) * i
if flag:
    print("{} {}".format(n, n + a[-1] - 1))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
import sys

moji1 = input()
moji2 = input()

K = int(moji1)
A = moji2.split(" ")

x = int(A[-1])
for i in range(len(A) - 1):
    #if (x + (int)(A[-1-i])-1)/(int)(A[-2-i]) < 1:
    print("-1")
    sys.exit()
    x = (x + (int)(A[-1-i])-1) - (x + (int)(A[-1-i])-1)%(int)(A[-2-i])
mx = x + int(A[0]) - 1

y = int(A[-1])
for i in range(len(A) - 1):
    if int(int(A[-i-1])%int(A[-i-2])) != 0:
        y = (int(int(A[-i-1])/int(A[-i-2])) + 1) * int(A[-i-2])
    else:
        y = (int(int(A[-i-1])/int(A[-i-2]))) * int(A[-i-2])

print(str(y) + " " + str(mx))

Submission status: Wrong Answer

Solution code:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [k] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    num_list = []
    for i in range(k):
        num_list.append(int(input_raw[i]))

    max_num = 2
    min_num = 2
    is_exist = True
    for i in range(k-1, -1, -1):
        min_min_num = min_num;
        min_max_num = min_num + num_list[i] - 1
        max_min_num = max_num;
        max_max_num = max_num + num_list[i] - 1
        if i > 0:
            min_min_num = num_list[i - 1] * (min_min_num / num_list[i - 1] + (0 if (min_min_num % num_list[i - 1] == 0)  else 1) )
            min_max_num = num_list[i - 1] * int(min_max_num / num_list[i - 1] )
            max_min_num = num_list[i - 1] * (max_min_num / num_list[i - 1] + (0 if (max_min_num % num_list[i - 1] == 0)  else 1) )
            max_max_num = num_list[i - 1] * int(max_max_num / num_list[i - 1] )

        if(min_min_num > min_max_num and max_min_num > max_max_num):
            is_exist = False
            break;
        elif(min_min_num > min_max_num and max_min_num <= max_min_num):
            min_num = max_min_num
            max_num = max_max_num
        elif(min_min_num <= min_max_num and max_min_num > max_max_num):
            min_num = min_min_num
            max_num = min_max_num
        else:
            min_num = min(min_min_num, max_min_num)
            max_num = max(min_max_num, max_max_num)
        if min_num > max_num:
            is_exist = False
            break;

    if is_exist == True:
        print min_num, max_num
    else:
        print -1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import math

K = int(input())

A = input().split()

for i in range(K):
    A[i] = int(A[i])

maxlst = [0 for i in range(K)]
minlst = [0 for i in range(K)]

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

maxlst[K-1] = 3
minlst[K-1] = 2

for i in reversed(range(K-1)):
    if maxlst[i+1] < A[i]:
        print(-1)
        quit()
    maxlst[i] = A[i] - 1 + A[i] * int(maxlst[i+1] / A[i])
    minlst[i] = int(math.ceil(minlst[i+1] / A[i]) * A[i])

print(minlst[0], maxlst[0])

Submission status: Wrong Answer

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

    if a[k-1] != 2:
        print(-1)
        return

    if k == 1:
        print(2, 3)
        return

    mi = 0
    mx = 0

    for i in range(k):

        if i==0:
            mi = 2
            mx = 2
        # elif i > 1 and i != k-1:
        #     if a[k-i-1] == a[k-(i-1)-1]:
        #         continue

        mx = mx + a[k-i-1] - 1
        #print(mi, mx)

        if i == k-1:
            pass
        else:
            j = i+1
            if mx < a[k-j-1]:
                print(-1)
                return

            if mi%a[k-j-1] != 0:
                mi = mi + (a[k-j-1] - mi%a[k-j-1])
            if mx%a[k-j-1] != 0:
                mx = mx - mx % a[k-j-1]
        #print(mi, mx)
    print(mi, mx)
solve()

Submission status: Wrong Answer

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

    if a[k-1] != 2:
        print(-1)
        return

    if k == 1:
        print(2, 3)
        return

    mi = 0
    mx = 0

    for i in range(k):

        if i==0:
            mi = 2
            mx = 2
        # elif i > 1 and i != k-1:
        #     if a[k-i-1] == a[k-(i-1)-1]:
        #         continue

        mx = mx + a[k-i-1] - 1
        print(mi, mx)

        if i == k-1:
            pass
        else:
            j = i+1
            if mx < a[k-j-1]:
                print(-1)
                return

            if mi%a[k-j-1] != 0:
                mi = mi + (a[k-j-1] - mi%a[k-j-1])
            if mx%a[k-j-1] != 0:
                mx = mx - mx % a[k-j-1]
        print(mi, mx)
    print(mi, mx)
solve()

Submission status: Wrong Answer

Solution code:
import sys

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [k] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    num_list = []
    for i in range(k):
        num_list.append(int(input_raw[i]))

    max_num = 2
    min_num = 2
    is_exist = True
    for i in range(k-1, -1, -1):
        min_min_num = min_num;
        min_max_num = min_num + num_list[i] - 1
        max_min_num = max_num;
        max_max_num = max_num + num_list[i] - 1
        if i > 0:
            min_min_num = num_list[i - 1] * (min_min_num / num_list[i - 1] + (0 if (min_min_num % num_list[i - 1] == 0)  else 1) )
            min_max_num = num_list[i - 1] * int(min_max_num / num_list[i - 1] )
            max_min_num = num_list[i - 1] * (max_min_num / num_list[i - 1] + (0 if (max_min_num % num_list[i - 1] == 0)  else 1) )
            max_max_num = num_list[i - 1] * int(max_max_num / num_list[i - 1] )

        if(min_min_num > min_max_num and max_min_num > max_max_num):
            is_exist = False
            break;
        elif(min_min_num > min_max_num and max_min_num <= max_min_num):
            min_num = max_min_num
            max_num = max_max_num
        elif(min_min_num <= min_max_num and max_min_num > max_min_num):
            min_num = min_min_num
            max_num = min_max_num
        else:
            min_num = min(min_min_num, max_min_num)
            max_num = max(min_max_num, max_max_num)
        if min_num > max_num:
            is_exist = False
            break;

    if is_exist == True:
        print min_num, max_num
    else:
        print -1


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# cook your dish here
from math import * 
#for _ in range(int(input().strip())):

def isvalid(l):
    n=len(l)
    if l[-1]!=2:
        return 0
    for i in range(n-2,-1,-1):
        if l[i]>=2*l[i+1]:
            return 0
    return 1

n=int(input())
l=[int(x) for x in input().split()]
if n>2:
    l2=l[:2]+l[2:]
f=isvalid(l)
if f==0:
    print("-1")
else:
    if n==1:
        print(l[0],l[0]*2-1)
        exit(0)
    if n==2:
        print(l[0],l[0]*2-1)
        exit(0)
    for i in range(n-2,-1,-1):
        ans=l[i]*ceil(l[i+1]/l[i])
        l[i]=ans
    #for ele in l:
     #   print(ele,end=" ")
    var2=l[n-3]
    for i in range(n-2,0,-1):
        var1=l2[i]*((var2//l2[i])+1) - 1 
        var2=l2[i-1]*(var1//l2[i-1])
    var2 = l2[0]*((var2//l2[0])+1)  - 1  
    #print(var2)
    print(ans,var2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
import numpy as np
import sys

k = int(input())
a = list(map(int,input().split()))[::-1]
min_num = 2
max_num = 3
if(a[0]!=2):
    print(-1)
    sys.exit()
    
for i in range(len(a)-1):
    if(a[i+1] > max_num):
        print(-1)
        sys.exit()
    else:
        min_num = a[i+1]*(min_num//a[i+1] if min_num%a[i+1]==0 else min_num//a[i+1]+1)
        max_num = a[i+1]*((max_num//a[i+1])+1)-1
        
        
print(str(min_num)+' '+str(max_num))

Submission status: Wrong Answer

Solution code:
K=int(input())
A=input().split(' ')
min=2
max=2
flag=0
while K>0:
  K=K-1
  i=int(A[K])
  if max<i:
    print('-1')
    flag=1
    break
  elif i<min:
    if min%i!=0:min=min+i-(min%i)
    else:min=min+(min%i)
    max=max+i-(max%i)-1
  else:
    min=i
    max=max+i-(max%i)-1
if flag==0:
  print('{0} {1}'.format(min,max))

Submission status: Wrong Answer

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

def solve():
    if A[K - 1] != 2:
        print(-1)
        return;
    M = 2
    m = 2
    for i in range(K - 1, 0, -1):
        nM = (M + A[i] - 1) - (M + A[i] - 1) % A[i - 1]
        if m % A[i - 1] == 0:
            nm = m
        else:
            nm = m + A[i - 1] - m % A[i - 1]
        #print("nM =", nM, "nm =", nm)
        if nM < M or nm >= m + A[i]:
            print(-1)
            return;
        #print("nM =", nM, "nm =", nm)
        M, m = nM, nm
    M = M + A[0] - 1
    # m = m
    print(m, M)
solve()

Submission status: Wrong Answer

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

last = A[0]
pattern = 0

A.reverse()
B = A[:]

for i in range(len(A)-1):
    k = math.ceil(A[i]/A[i+1])
    if  A[i]<= k*A[i+1]  and k*A[i+1] <= A[i]+B[i]-1:
        A[i+1]=k*A[i+1]
    else:
        pattern = 1
        print(-1)
        break
        
if pattern == 0:
    print(A[-1], A[-1]+last -1)

Submission status: Wrong Answer

Solution code:
import sys,collections;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

n = I()
lis = Is()
if lis[-1] != 2:
    print(-1)
    exit()
tmin,tmax = 2,2
for i in range(n-1):
    n = lis[-2-i]
    a = tmin % n
    if tmin == n:
        a = n
    cand = []
#    print(n,a,tmin+n-a,tmin*2)
    for j in range(tmin+n-a,tmin*2,n):
        cand.append(j)
    if not cand:
        print(-1)
        exit()
    else:
        tmin = min(cand)
    a = tmax % n
    if tmax == n:
        a = n
    cand = []
    for j in range(tmax+n-a,tmax*2,n):
        cand.append(j)
    if not cand:
        print(-1)
        exit()
    else:
        tmax = max(cand)
print(tmin,tmax+lis[0]-1)

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    A = tuple(map(int, input().split()))

    min_ = 0
    max_ = 0
    a = A[::-1]
    prev = 2
    for i in a:
        if i < prev:
            n = i * ((prev + i - 1) // i)
        else:
            if i // prev > 1:
                print(-1)
                return
            else:
                n = i
        min_ = max(min_, n)
        prev = n
    max_ = (min_ // i + 1) * i - 1
    print(min_, max_)

main()

Submission status: Wrong Answer

Solution code:
K=int(input())
A=list(map(int,input().split(' ')))
ans1=2
ans2=3
j=0
k=0
ans=0
A.reverse()


for i in range(len(A)-1):
    if int(A[i])<int(A[i+1]) and int(A[i])*2>int(A[i+1]):
        ans1=max(ans1,int(A[i+1]))
        ans2=max(ans2,int(A[i+1]))
    elif int(A[i])<int(A[i+1]) and int(A[i])*2<int(A[i+1]):
        ans=-1
        break
    elif int(A[i])>int(A[i+1]):
        while ans1<=int(A[i+1])*2-1:
            j=j+1
            ans1=int(A[i+1])*j
        while ans2<ans1:
            k=k+1
            ans2=ans2+int(A[i+1]-1)*k
    elif A[i]==A[i+1]:
        continue
    else:
        ans2=-1

if ans==-1:
    print('-1')
elif ans1==ans2:
    ans2=ans1+1
    print(ans1, ans2)
else:
    print(ans1, ans2)

Submission status: Wrong Answer

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

def solve():
    if A[K - 1] != 2:
        print(-1)
        return;
    M = 2
    m = 2
    for i in range(K - 1, 0, -1):
        nM = (M + A[i] - 1) - (M + A[i] - 1) % A[i - 1]
        if m % A[i - 1] == 0:
            nm = m
        else:
            nm = m + A[i - 1] - m % A[i - 1]
        #print("nM =", nM, "nm =", nm)
        if nM < M or m >= m + A[i]:
            print(-1)
            return;
        #print("nM =", nM, "nm =", nm)
        M, m = nM, nm
    M = M + A[0] - 1
    # m = m
    print(m, M)
solve()

Submission status: Wrong Answer

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
last = A[0]
pattern = 0

A.reverse()

for i in range(len(A)-1):
    k = math.ceil(A[i]/A[i+1])
    if  A[i]<= k*A[i+1]  and k*A[i+1] <= (2*A[i]-1):
        A[i+1]=k*A[i+1]
    else:
        pattern = 1
        print(-1)
        break
        
if pattern == 0:
    print(A[-1], A[-1]+last -1)

Submission status: Wrong Answer

Solution code:
k = int(raw_input())
a = map(int,raw_input().split(" "))

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

r = [2,3]
ainv = a[::-1]

for now in ainv[1:-1]:
  lower = (r[0]/now)*now
  if lower < r[0]:
    lower += now
  q = [lower,lower + now - 1]

  if q[0] > r[1]:
    print "-1"
    exit(0)
  r = q

now = ainv[-1]

lower = (r[0]/now)*now
if lower < r[0]:
  lower += now
q = [lower,lower + now - 1]

if q[0] > r[1]:
  print "-1"
  exit(0)

upper = lower + now - 1
while (upper / now) * now <= r[1]:
  upper += 1
upper -= 1
q = [lower,upper]
r = q

print "%d %d" % (r[0],r[1])

Submission status: Wrong Answer

Solution code:
K=int(input())
A=list(map(int,input().split(' ')))
ans1=2
ans2=2
j=0
k=0
ans=0
A.reverse()


for i in range(len(A)-1):
    if int(A[i])<=int(A[i+1]) and int(A[i])*2>int(A[i+1]):
        ans1=max(ans1,int(A[i+1]))
        ans2=max(ans2,int(A[i+1]))
    elif int(A[i])<=int(A[i+1]) and int(A[i])*2<int(A[i+1]):
        ans=-1
        break
    elif int(A[i])>=int(A[i+1]):
        while ans1<=int(A[i+1])*2-1:
            j=j+1
            ans1=int(A[i+1])*j
        while ans2<ans1:
            k=k+1
            ans2=ans2+int(A[i+1]-1)*k

    else:
        ans2=-1

if ans==-1:
    print('-1')
elif ans1==ans2:
    ans2=ans1+1
    print(ans1, ans2)
else:
    print(ans1, ans2)

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-2,-1,-1):
        t = a[i]
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b = (b+t) - (b%t)
        else:
            b = t
        if c % t == 0:
            pass
        elif c > t:
            c = (c+t) - (c%t)
        else:
            return -1
    bb = b-1
    cc = c
    for i in range(n):
        bb -= bb%a[i]
        cc -= cc%a[i]
    if bb >= 2:
        return 1 / 0
    if cc <= 2:
        while 1:
            cc += 1

    return '{} {}'.format(b, c-1)

print(main())