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:
N = int(input())
ops = list(input().split())
P = []
p = 0
x = 1
for s in range(N-1, -1, -1):
    P.append(int(ops[s]))
ans = int(ops[N-1])

for i in range(N-1):
    if P[i] > P[i+1]:
            p = P[i] % P[i+1]
            ans += p
    elif (P[i] * 2) > P[i+1]:
        p = (P[i] * 2) % P[i+1]
        ans += p
    else:
        ans = -1
        break

if ans != -1:
    if ans % P[N-1] != 0:
        ans -= ans % P[N-1]
    while ans < max(P):
        ans += P[N-1]    
    ans2 = ans + P[N-1] -1
    print(str(ans) + " " +str(ans2))
else:
    print(ans)

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_min_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:
N = int(input())
ops = list(input().split())
P = []
p = 0
x = 1
for s in range(N-1, -1, -1):
    P.append(int(ops[s]))
ans = int(ops[N-1])
print(P)
for i in range(N-1):
    if P[i] > P[i+1]:
            p = P[i] % P[i+1]
            ans += p
    elif (P[i] * 2) > P[i+1]:
        p = (P[i] * 2) % P[i+1]
        ans += p
    else:
        ans = -1
        break

if ans != -1:
    if ans % P[N-1] != 0:
        ans -= ans % P[N-1]
    while ans < max(P):
        ans += P[N-1]    
    ans2 = ans + P[N-1] -1
    print(str(ans) + " " +str(ans2))
else:
    print(ans)

Submission status: Wrong Answer

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

import numpy as np

def slove(k, a):
    a = np.array(a, dtype=np.int64)
    diff = a[:-1] - (2*a[1:])

    if (diff >= 0).any():
        return -1

    minNum = a[0]
    while (minNum < a.max()):
        minNum *= 2

    maxNum = minNum + a[0] - 1

    return ("{0} {1}".format(minNum, maxNum))


if __name__ == "__main__":
    k = int(input())
    a = input().split(" ")

    print(slove(k, a))

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('aa1')
    flag=1
    break
  elif i<min:
    min=min+i-(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=[int(i) for i in input().split()]
count=0
#number=max(a)

ans_min=100000000000000
ans_max=0

n=max(a)-max(a)%a[0]


for j in range(10):
  n_org=n
  for i in range(k):
    n=(n//a[i])*a[i]

  if n==2:
   ans_min=min(ans_min,n_org)
   ans_max=max(ans_max,n_org)
   count=1
  n=n_org+a[0]

if count==0: 
    print(-1)
else:
    print(ans_min,ans_max+a[0]-1)

Submission status: Wrong Answer

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

def solve(ans):
	global K, A
	for i in range(0, K):
		if ans % A[i] != 0:
			ans -= (ans % A[i])
	return ans

curr = 0
if A[K-1] != 2:
	curr = -1
else:
	curr = A[K-1]
	for i in range(K-2,-1,-1):
		if curr <= A[i]:
			curr = A[i]
		else: # if curr > A[i]
			k = math.ceil(curr / A[i])
			curr = k * A[i]
minv = 0
if curr != -1:
	minv = curr
	curr = solve(minv)

maxv = 0
if  curr != 2:
	print(-1)
else:
	lo = 2;
	hi = 10**9 + 1
	while lo < hi:
		mid = (lo + hi) // 2
		if solve(mid) == 2:
			lo = mid + 1
		else:
			hi = mid - 1
	maxv = min(lo,hi)
	print(minv, maxv)

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

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

print(main())

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 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:
            c = t

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

print(main())

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

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

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 q[0] > r[1]:
    print "-1"
    exit(0)
  r = q

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

Submission status: Wrong Answer

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

A.reverse()

for i in range(len(A)-1):
    if pattern == 0:
        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)
        
if pattern == 0:
    print(A[-1],A[-1]+last -1)

Submission status: Wrong Answer

Solution code:
K=int(input())
A=list(map(int,input().split(' ')))
ans1=2
ans2=2
j=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
            ans2=ans1+int(A[i+1])-1
    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())
AT = list(map(int,input().split()))

A=reversed(AT)
s = 2;b = 1;lis=[]
for i in A:
    ns = i
    if s > ns:
        ns +=(((s-ns)//i)*i)
        if s > ns:
            ns+i
    s = ns
sn = s
for i in AT:
    sn = sn-sn%i

if sn!=2:
    print(-1)
    exit()
b = 1
AT.reverse()
for i in AT:
    b=b-b%i
    nb = i
    if b > nb:
        nb +=(((b-nb)//i)*i)
        if b > nb:
            nb+i
    b= (nb+i-1)
print(s,b)

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

K = int(input())
As = list(map(int, input().split()))

rest = 2
for i in range(K - 1)[::-1]:
    x = ceil(rest / As[i])
    if As[i] * x - rest >= As[i + 1]:
        print('-1')
        exit()
    rest = As[i] * x

ansMin = rest

rest = 2
for i in range(K)[::-1]:
    if As[i] > rest:
        print('-1')
        exit()
    x = floor(rest / As[i])
    rest = As[i] * (x + 1) - 1

ansMax = rest

print(ansMin, ansMax)

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]
  print r
  print q
  print
  if q[0] > r[1]:
    print "-1"
    exit(0)
  r = q

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

Submission status: Wrong Answer

Solution code:
from pprint import pprint as pp
import collections
import math
import itertools

K, = map(int, input().split())
A = tuple(map(int, input().split()))

old_a = 2
x_max = 1
x_min = 1
for a in reversed(A[:-1]):
  #pp((a, old_a, x_min, x_max))
  if a >= (old_a * (x_max +1)):
    x_max = -1
    break
  x_max = (old_a * (x_max+1)-1) // a
  x_min = math.ceil(old_a * x_min / a)
  if x_max < x_min:
    x_max = -1
    break
  old_a = a
#pp((a, old_a, x_min, x_max))
if x_max == -1:
  print(-1)
else:
  print(old_a * x_min, (old_a * (x_max+1))-1)

Submission status: Wrong Answer

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

A.reverse()

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

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()
    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:
            c = t

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

print(main())

Submission status: Wrong Answer

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

min_A=2
max_A=3
jud=True
for i in range(1,K):
  if A[i]>max_A:
    print(-1)
    jud=False
    break
  if min_A>A[i]:
    cnt=2
    while True:
      if A[i]*cnt>=min_A:
        min_A=A[i]*cnt
        break
      cnt+=1
    while True:
      if A[i]*(cnt+1)-1>max_A:
        max_A=A[i]*cnt-1
        break
      cnt+=1
  else:
    min_A=A[i]
    max_A=A[i]*2-1
if jud:
  print(min_A,max_A)

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:
            c = t

    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]
coef = 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 A[i+1] <= 2*A[i]-1:
        A[i+1]=k*A[i+1]
    else:
        pattern = 1
        print(-1)
if pattern == 0:
    print(A[-1],A[-1]+last -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 prev > i:
            n = i * ((prev + i - 1) // i)
        else:
            if i // prev > 1:
                print(-1)
                return
            else:
                n = i
        min_ = max(min_, n)
        prev = i
    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=2
j=0
ans=0
A.reverse()
A.append(A[-1])

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
            ans2=ans1+int(A[i+1])-1
    else:
        ans=9

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

Submission status: Wrong Answer

Solution code:
# 4: 3 => 4 => 3 => 2
# 
# last 2, semi_last 3=> 1 lose. then, (semi_last - 2) lose.
# 

def min_lose(pre, curennt):
    if(curennt <= pre):
        num = pre - curennt
    else:
        num = (pre * 2) - curennt
    return num

def max_lose(pre, curennt):
    if(curennt < pre):
        num = pre - curennt
    else:
        num = (pre * 2) - curennt
    return num

K = int(raw_input())
A_list = map(int, raw_input().split())

round = A_list.pop(-1)

if round != 2:
    print '-1'
else:
    min_n = 2
#    max_n = min_n + round -1
    fault = False
    while len(A_list) > 0:
        pre_round = A_list.pop(-1)
        if pre_round > (round * 2):
            fault = True
            break
        else:
            #pass
            min_n += min_lose(pre_round, round)
#            max_n += min_lose(pre_round, round)
           
        round = pre_round

    # output
    if fault == True:
        print '-1'
    else:
#        print min_n, max_n
        print min_n, (min_n + round -1)

Submission status: Wrong Answer

Solution code:
K=int(input())
A=list(map(int,input().split(' ')))
ans1=2
ans2=2
j=0
ans=0
A.reverse()
A.append(A[-1])

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
            ans2=ans1+int(A[i+1])-1
    else:
        ans=9

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

Submission status: Wrong Answer

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

A=reversed(AT)
s = 2;b = 1;lis=[]
for i in A:
    ns = i
    if s > ns:
        ns +=(((s-ns)//i)*i+i if ((s-ns)//i)*i < s else ((s-ns)//i)*i)
    s = ns
sn = s
for i in AT:
    sn = sn-sn%i

if sn!=2:
    print(-1)
    exit()
b = 1
AT.reverse()
for i in AT:
    b=b-b%i
    nb = i
    if b > nb:
        nb +=(((b-nb)//i)*i)
    b= (nb+i-1)
print(s,b)

Submission status: Wrong Answer

Solution code:
# D
K = int(input())
A_list = list(map(int, input().split()))

res_min = [2]*(K+1)
res_max = [2]*(K+1)
possible = True
A_list.append(2)

for i in range(K-1, -1, -1):
    # minimum
    if res_min[i+1] % A_list[i] == 0:
        res_min[i] = res_min[i+1]
    else:
        res_min[i] = res_min[i+1] + A_list[i] - res_min[i+1] % A_list[i]
        
    # minimum over
    if (res_min[i] // A_list[i+1]) * A_list[i+1] > res_max[i+1]:
        possible = False
    
    # maximum
    if (res_max[i+1] + A_list[i+1]) % A_list[i] == 0:
        res_max[i] = res_max[i+1] + A_list[i+1] - A_list[i]
    else:
        res_max[i] = ((res_max[i+1] + A_list[i+1]) // A_list[i]) * A_list[i]
        
    # maximum over
    if (res_max[i] // A_list[i+1]) * A_list[i+1] < res_min[i+1]:
        possible = False

if possible:
    print(res_min[0], res_max[0]+A_list[0]-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 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 = c = 2
    for i in range(n-2,-1,-1):
        t = a[i]
        if c * 2 <= t:
            return -1
        if b * 2 <= t:
            while b*2 <= t:
                b += a[i+1]
        if b % t == 0:
            pass
        elif b > t:
            b = (b+t) - (b%t)
        else:
            b = t
        c = c + a[i+1] - 1
        c -= c%t
        if b > c:
            c = b

    return '{} {}'.format(b, c+a[0]-1)

print(main())

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left, insort
from itertools import accumulate
def inpl(): return tuple(map(int, input().split()))

K = int(input())
A = inpl()
if A[-1] != 2:
    print(-1)

l, r = 2, 3
for a in A[:-1][::-1]:
    l = (l//a)*a + int(l%a!=0)*a
    r = (r//a)*a + (a-1)
    if r < l:
        print(-1)
        break
else:
    print(l, r)

Submission status: Wrong Answer

Solution code:
# D
K = int(input())
A_list = list(map(int, input().split()))

res_min = [2]*(K+1)
res_max = [2]*(K+1)
possible = True
A_list.append(2)

for i in range(K-1, -1, -1):
    # minimum
    if res_min[i+1] % A_list[i] == 0:
        res_min[i] = res_min[i+1]
    else:
        res_min[i] = res_min[i+1] + A_list[i] - res_min[i+1] % A_list[i]
        
    # minimum over
    if (res_min[i] // A_list[i+1]) * A_list[i+1] > res_max[i+1]:
        possible = False
    
    # maximum
    if (res_max[i+1] + A_list[i+1]) % A_list[i] == 0:
        res_max[i] = res_max[i+1] + A_list[i+1] - A_list[i]
    else:
        res_max[i] = ((res_max[i+1] + A_list[i+1]) // A_list[i]) * A_list[i]
    
    # maximum over
    
    
    if res_max[i+1] + A_list[i+1] - res_max[i] > 0:
        if (res_max[i+1] + A_list[i+1] - res_max[i]) % A_list[i] == 0:
            res_max[i] += res_max[i+1] + A_list[i+1] - res_max[i] - A_list[i]
        else:
            res_max[i] += ((res_max[i+1] + A_list[i+1] - res_max[i]) // A_list[i]) * A_list[i]

if possible:
    print(res_min[0], res_max[0]+A_list[0]-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect, bisect_left, insort
from itertools import accumulate
def inpl(): return tuple(map(int, input().split()))

K = int(input())
A = inpl()
if A[-1] != 2:
    print(-1)
    print("end")

l, r = 2, 3
for a in A[:-1][::-1]:
    l = (l//a)*a + int(l%a!=0)*a
    r = (r//a)*a + (a-1)
    if r < l:
        print(-1)
        break
else:
    print(l, r)

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 = c = 2
    for i in range(n-2,-1,-1):
        t = a[i]
        if c * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b = (b+t) - (b%t)
        else:
            b = t
        c = c + min(t,a[i+1]) - 1
        c -= c%t
        if b > c:
            c = b

    return '{} {}'.format(b, c+a[0]-1)

print(main())

Submission status: Wrong Answer

Solution code:
def maxmin(fac, maxi, mini):
    ans = list()
    inte = 1
    num = 1
    while num < mini:
        num = fac*inte
        inte += 1
    ans.append(num)
    while num < maxi:
        num = fac*inte
        inte += 1
    ans.append(num-1)
    return ans


in1 = int(input())
in2 = [int(x) for x in input().split()]

if in2[-1] > 2:
    print('-1')
    exit()

ans = [0, 0]
for i in range(in1-1,0,-1):
    if in2[i-1] >= 2*in2[i]:
        print('-1')
        exit()
    elif in2[i-1] > in2[i]:
        ans[0] = in2[i-1]
    else:
        mm = maxmin(in2[i-1], 2*in2[i], in2[i])
        ans = mm

if ans[1] < ans[0]:
    ans[1] = ans[0]

print(' '.join([str(x) for x in ans]))

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 = c = 2
    for i in range(n-2,-1,-1):
        t = a[i]
        if c * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b = (b+t) - (b%t)
        else:
            b = t
        c = c + max(t,a[i+1]) - 1
        c -= c%t
        if b > c:
            c = b

    return '{} {}'.format(b, c+a[0]-1)

print(main())

Submission status: Wrong Answer

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

A=reversed(AT)
s = 2;b = 1;lis=[]
for i in A:
    ns = i
    if s > ns:
        ns +=(((s-ns)//i)*i+i)
    s = ns
sn = s
for i in AT:
    sn = sn-sn%i

if sn!=2:
    print(-1)
    exit()
b = 1
AT.reverse()
for i in AT:
    b=b-b%i
    nb = i
    if b > nb:
        nb +=(((b-nb)//i)*i)
    b= (nb+i-1)
print(s,b)

Submission status: Wrong Answer

Solution code:
from pprint import pprint as pp
import collections
import math
import itertools

K, = map(int, input().split())
A = tuple(map(int, input().split()))

old_a = 2
x_max = 1
x_min = 1
for a in reversed(A[:-1]):
  #pp((a, old_a, x_min, x_max))
  if a >= (old_a * (x_max +1)):
    x_max = -1
    break
  x_max = (old_a * (x_max+1)-1) // a
  x_min = math.ceil(old_a * x_min / a)
  old_a = a
#pp((a, old_a, x_min, x_max))
if x_max == -1:
  print(-1)
else:
  print(old_a * x_min, (old_a * (x_max+1))-1)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = [int(i) for i in input().split()]
m = sum([i-1 for i in a])

l = []
for n in range(max(a), m+1):
    c = n
    for i in a:
        c -= c % i
    if c == 2: l.append(n)
if len(l) == 0: print(-1)
else:print(l[0],l[-1])

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 not (a[-1] == 2 or a[-1] == 1):
        return -1
    b = c = 2
    for i in range(n-2,-1,-1):
        t = a[i]
        if c * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b = (b+t) - (b%t)
        else:
            b = t
        c = c + a[i+1] - 1
        c -= c%t
        if b > c:
            c = b

    return '{} {}'.format(b, c+a[0]-1)

print(main())

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

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

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))
n = max(a) * 2
ok = []
for i in range(2,n+1):
    b = i
    for j in range(k):
        i = i - i % a[j]
    if i == 2:
        ok.append(b)
    else:
        pass
if ok == []:
    print(-1)
else:
    print(min(ok), max(ok))