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:
def check():
  n = int(raw_input())
  alist = (map(int, raw_input().split()))[::-1]
  cmin = 2
  cmax = 2

  for i in range(n-1):
    a = alist[i]
    am = alist[i+1]
    if(a>cmax):
      return -1
    tmpmin = cmin
    tmpmax = cmax + a-1
    if(tmpmin%am!=0): cmin = tmpmin + (am-tmpmin%am)
    cmax = tmpmax - tmpmax%am
    #print i, cmin, cmax
  a = alist[n-1]
  return cmin, cmax + a-1 

if __name__=='__main__':
  c = check()
  if c==-1:
    print c
  else:
    print c[0], c[1]

Submission status: Wrong Answer

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

N_min = 2
N_max = 2
for a in A[K::-1]:
	if N_max < a:
		print(-1)
		exit(0)
	else:
		# N_min -> smallest # that is # >= prev N_min and # % a == 0
		N_min += (a - N_min) % a
		# N_max -> smallest # that is # >= prev N_max and # % a == a-1
		N_max += (a - N_max - 1) % a
print(N_min, N_max)

Submission status: Wrong Answer

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

if K == 1:
	if A[0] == 2:
		print(2, 3)
	else:
		print(-1)
	exit(0)
if A[K-1] != 2:
	print(-1)
	exit(0)

N_min = 2
N_max = 3
for a in A[K-2::-1]:
	if N_max < a:
		print(-1)
		exit(0)
	else:
		# N_min -> smallest # that is # >= prev N_min and # % a == 0
		N_min += (a - N_min) % a
		# N_max -> smallest # that is # >= prev N_max and # % a == a-1
		N_max += (a - N_max - 1) % a
print(N_min, N_max)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = [int(i) for i in input().split()]
if A[K-1] != 2:
	print(-1)
	exit(0)
if K == 1:
	if A[0] == 2:
		print(2, 3)
	else:
		print(-1)
	exit(0)

N_min = 2
N_max = 3
for a in A[K-2::-1]:
	if N_max < a:
		print(-1)
		exit(0)
	else:
		# N_min -> smallest # that is # >= prev N_min and # % a == 0
		N_min = N_min + (a - (N_min % a)) % a
		# N_max -> smallest # that is # >= prev N_max and # % a == a-1
		N_max = N_max + (a - (N_max % a)) - 1
print(N_min, N_max)

Submission status: Wrong Answer

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

#
min_n = 2
max_n = 2
prev_i = 2
for i in A[::-1][1:]:
    a = (min_n - 1)//i
    b = (max_n + prev_i - 1)//i
    if a==b:
        print(-1)
        exit()

    if min_n%i==0:
        pass#min_n = n
    else:
        min_n = min_n + (i - min_n%i)
    max_n = max_n+prev_i-1 - (max_n+prev_i-1)%i
    prev_i = i
    #print(min_n, max_n)

#
print(min_n, max_n+A[0]-1)

Submission status: Wrong Answer

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

#
n = 2
for i in A[::-1][1:]:
    if n*2-1<i:
        print(-1)
        exit()
    n = n*2-1 - (n*2-1)%i

#
print(n, n+A[0]-1)

Submission status: Wrong Answer

Solution code:
def game(A,N):
    for A_i in A:
        N-=N%A_i
    if N==2:
        return True
    else:
        return False

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

minimum=-1
maximum=-1
for i in range(max(A),sum(A)-K+1):
    if game(A,i):
        maximum=i
        if minimum==-1:
            minimum=i

if minimum!=-1:
    print("{0} {1}".format(minimum,maximum))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
import sys
k = int(input())
a_ls = list(map(int, input().split()))[::-1]
min_ = 2
max_ = 2
for a in a_ls:
    if a > min_ * 2 - 1:
        print("-1")
        sys.exit()
    else:
        if min_ % a != 0:
            min_ = min_ + a - (min_ % a)
        max_ = max_ + a - (max_ % a) - 1
print(min_, max_)

Submission status: Wrong Answer

Solution code:
import sys
k = int(input())
a_ls = list(map(int, input().split()))[::-1]
if a_ls[0] != 2:
    print("-1")
    sys.exit()
elif len(a_ls) == 1:
    print("2 3")
    sys.exit()
min_ = 2
max_ = 3
for a in a_ls[1:]:
    if a > min_ * 2 - 1:
        print("-1")
        sys.exit()
    else:
        if min_ % a != 0:
            min_ = min_ + a - (min_ % a)
        max_ = max_ + a - (max_ % a) - 1
print(min_, max_)

Submission status: Wrong Answer

Solution code:
N = int(input())
P = list(reversed(list(map(int, input().split()))))

s, t = 2, 2
for i in P:
    p = max((s + i - 1) // i, 1)
    q = t // i
    print(i)
    if q < p:
        print(-1)
        quit(0)
    s, t = p * i, q * i + i - 1

print(s, t)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    l = list(map(int,input().split(" ")))
    l.append(1)
    l.reverse()
    i = 0
    min_temp = 2
    max_temp = 2
    if l[1]==2:
        i+=1
        while i<len(l):
            if l[i]>=l[i-1]:
                if min_temp+l[i-1]-1<l[i]:
                    print(-1)
                    exit()
                else:
                    while min_temp%l[i]:
                        min_temp+=1
                max_temp = l[i]+max_temp-1
                while max_temp%l[(i+1)%len(l)]:
                    max_temp-=1

            else:
                while min_temp%l[i]:
                    min_temp+=1
                max_temp = max_temp+l[i]-1
            i+=1

    print(min_temp,max_temp)


if __name__=="__main__":
    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
cnt=True
if A[0]!=2:
  print(-1)
  cnt=False
for i in range(1,K):
  a=(min_A+A[i]-1)//A[i]*A[i]
  b=max_A//A[i]*A[i]
  if a>b:
    print(-1)
    cnt=False
    break
  else:
    min_A=a
    max_A=b+A[i]-1

if cnt:
  print(min_A,max_A)

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
cnt=True
if A[-1]!=2:
  print(-1)
  cnt=False
for i in range(1,K):
  a=(min_A+A[i]-1)//A[i]*A[i]
  b=max_A//A[i]*A[i]
  if a>b:
    print(-1)
    cnt=False
    break
  else:
    min_A=a
    max_A=b+A[i]-1

if cnt:
  print(min_A,max_A)

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
cnt=True
for i in range(1,K):
  a=(min_A+A[i]-1)//A[i]*A[i]
  b=max_A//A[i]*A[i]
  if a>b:
    print(-1)
    cnt=False
    break
  else:
    min_A=a
    max_A=b+A[i]-1

if cnt:
  print(min_A,max_A)

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
cnt=True
for i in range(1,K):
  a=(min_A+A[i]-1)//A[i]*A[i]
  b=(max_A//A[i]*A[i])+A[i]-1
  if a>b:
    print(-1)
    cnt=False
    break
  else:
    min_A=a
    max_A=b

if cnt:
  print(min_A,max_A)

Submission status: Wrong Answer

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

    a = A[::-1]
    min_ = 2
    max_ = 2
    n = []
    apnd = n.append
    for i in a:
        n.clear()
        for j in range(min_, min_ * 2):
            if not j % i:
                apnd(j)
        if not len(n):
            print(-1)
            return
        min_ = min(n)
        max_ = max(n)

    if min_ == max_:
        max_ = (min_ // i + 1) * i - 1
    else:
        max_ -= 1
    print(min_, max_)

main()

Submission status: Wrong Answer

Solution code:
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)

#計算量はO(3K)すなわちO(K)

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

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

L = 2
R = 3
for A in reversed(As[:-1]):
    if R // A * A < L:
        print('-1')
        exit()
    L = ceil(L / A) * A
    R = floor(R / A) * A + A - 1

print(L, R)

Submission status: Wrong Answer

Solution code:
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):  # 0<=i<=K-2 A[K-2]は2ラウンドの組．Kラウンドから2ラウンドまで
    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)

Submission status: Wrong Answer

Solution code:
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):  # 0<=i<=K-2 A[K-2]は2ラウンドの組．Kラウンドから2ラウンドまで
    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)

Submission status: Wrong Answer

Solution code:
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()

for i in range(0,K-1):  # 0<=i<=K-2 A[K-2]は2ラウンドの組．Kラウンドから2ラウンドまで
    drop_num_max = []
    drop_num_min = []
    for j in range(0,A[i]):  #脱落者数の候補を入れていく
        if ( jmax + j ) % A[i+1] == 0:
            drop_num_max.append(j)
        if ( jmin + j ) % A[i+1] == 0:
            drop_num_min.append(j)
    if drop_num_min == [] or drop_num_max == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
        print(-1)
        sys.exit()
    max_drop = max(drop_num_max)
    jmax = jmax + max_drop
    min_drop = min(drop_num_min)
    jmin = jmin + min_drop


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

print(jmin, jmax)

Submission status: Wrong Answer

Solution code:
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()

for i in range(0,K-1):  #Kラウンドから2ラウンドまで
    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 == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
        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)

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:
from math import floor, ceil
k = int(input())
a = [int(i) for i in input().split()]
l,r = 2,2
for ai in a[::-1]:
    if not(l // ai >= 1 or r // ai >= 1):
        print(-1)
        exit()
    l = ceil(l/ai)*ai
    r = floor(r/ai) * ai + ai - 1
print(l,r)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
k = int(input())
a = [int(i) for i in input().split()]
l,r = 2,2
for ai in a[::-1]:
    if not(l // ai >= 1 and r // ai >= 1):
        print(-1)
        exit()
    l = ceil(l/ai)*ai
    r = floor(r/ai) * ai + ai - 1
print(l,r)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
k = int(input())
a = [int(i) for i in input().split()]
l,r = 2,2
for ai in a[::-1]:
    if l // ai >= 1 or r // ai >= 1:
        print(-1)
        exit()
    l = ceil(l/ai)*ai
    r = floor(r/ai) * ai + ai - 1
print(l,r)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
k = int(input())
a = [int(i) for i in input().split()]
l,r = 2,2
for ai in a[::-1]:
    if l // ai > 2 or r // ai > 2:
        print(-1)
        exit()
    l = ceil(l/ai)*ai
    r = floor(r/ai) * ai + ai - 1
print(l,r)

Submission status: Wrong Answer

Solution code:
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):  #Kラウンドから2ラウンドまで
    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 == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
        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 == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
        print(-1)
        sys.exit()

    min_drop = min(drop_num)
    jmin = jmin + min_drop


#print(max_drop,jmax,min_drop,jmin)
print(jmin, jmax)

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
k = int(input())
a = [int(i) for i in input().split()]
l,r = 2,2
for ai in a[::-1]:
    if l // ai > 2 and r // ai > 2:
        print(-1)
        exit()
    l = ceil(l/ai)*ai
    r = floor(r/ai) * ai + ai - 1
print(l,r)

Submission status: Wrong Answer

Solution code:
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):  #Kラウンドから2ラウンドまで
    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 == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
        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 == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
        print(-1)
        sys.exit()

    min_drop = min(drop_num)
    jmin = jmin + min_drop


#print(max_drop,jmax,min_drop,jmin)
print(jmin, jmax)

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 = 2
    mx = 2

    for i in range(k):
        j = k-i-1

        mx = mx + a[j] - 1
        mi = mi

        if j == 0:
            pass
        else:
            na = a[j-1]
            if mx < na:
                print(-1)
                return

            if mi%na != 0:
                mi = mi + (na - mi%na)

            if mx%na != 0:
                mx = mx - (mx % na)

    print(mi, mx)
solve()

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

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

print(main())

Submission status: Wrong Answer

Solution code:
from math import floor, ceil
k = int(input())
a = [int(i) for i in input().split()]
l,r = 2,2
for ai in a[::-1]:
    l = ceil(l/ai)*ai
    r = floor(r/ai) * ai + ai - 1
print(l,r)

Submission status: Wrong Answer

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

    A.reverse()
    max = 2
    min = 2

    for i in range(1, K):
        limit = max+A[i-1]-1
        if limit < A[i]:
            print(-1)
            return
        j = 1
        while(True):
            if A[i-1] <= A[i]*j:
                min = A[i]*j
                break
            else:
                j+=1
        max = limit - limit % A[i]
    max = int(A[K-1]*(max/A[K-1]+1)-1)
    print(str(min) + " " + str(max))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from math import ceil, floor

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

L = 2
R = 3
for A in reversed(As[:-1]):
    if L // A == R // A:
        print('-1')
        exit()
    L = ceil(L / A) * A
    R = floor(R / A) * A + A - 1

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 = [1] + LI()
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-1,-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

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

print(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() + [1]
    if a[-1] != 2:
        return -1
    b = 2
    c = 4
    for i in range(n-1,-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

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

print(main())

Submission status: Wrong Answer

Solution code:
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 == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
            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 == []:  #A[i]について一通り調べたのち脱落者数の候補がなければ終わる
            print(-1)
            sys.exit()

    min_drop = min(drop_num)
    jmin = jmin + min_drop


print(jmin, jmax)

Submission status: Wrong Answer

Solution code:
a = [1]*100005
k = int(input())
# print(k)
line = input()
if line:
    i = 1
    for x in line.split():
        a[i]=(int)(x)
  #      print(a[i])
        i = i +1
ma = 2
mi = 2
flag = True
for i in range(k,0,-1):
    if i == 1:
        ma = ma + a[i] - 1
        continue
    tl = (int)(ma/a[i-1])
    if ma%a[i-1] != 0:
        tl = tl +1
    tr = (int)((a[i]-1+ma)/a[i-1])
    #print(tl)
    #print(tr)
    if tr<=0 or tl>tr :
        flag = False
        break
    else:
        ma = tr*a[i-1]
if flag:
    for i in range(k,0,-1):
        if i==1:
            continue
        tl = (int)(mi/a[i-1])
        if mi%a[i-1] !=0:
            tl = tl+1
        tr = (int)((a[i] - 1 + mi) / a[i - 1])
        if tr <= 0 or tl > tr:
            flag = False
            break
        else:
            if tl>0:
                mi=tl*a[i-1]
            else:
                mi = a[i-1]
if not flag:
    print("-1")
else:
    print(mi,end='')
    print(" ",end='')
    print(ma)

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:
k = int(input())
a = list(map(int, input().split()))[::-1]
c = 2
for i in range(1, k):
    m = ((c+a[i])//a[i]) * a[i]

    if c <= m and m <= c+a[i-1]-1:
        c = m
    else:
        print('-1')
        exit()
        
print(c, c+a[k-1]-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 if a[0]==2 else False
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
n = int(input())
s = list(map(int, input().split()))
o = s
l = s[0]
mii = 2
if min(s) > 2:
    print("-1")
else:
    for i in range(1, n):
        if s[-i-1]<s[-i]:
            s[-i-1] *= math.ceil(s[-i] / s[-i-1])
    tes = s[0]
    for j in range(n):
        tes -= tes % o[j]
    if tes != 2:
        print("-1")
    else:
        pk = 0
        for h in range(n):
            if o[h] != 1:
                pk = o[h]
                break
        print(s[0], s[0] + pk - 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=reversed([int(i) for i in input().split()])
max_a=3
min_a=2
a0=2
flg=0
an=list(a)
if an[0]!=2:
  f=1
for i in an:
  if i > max_a:
    flg=1
    break
  elif i !=a0:    
    if i>a0:
      min_a +=i-a0
    else:
      min_a+= i - min_a % i 
    max_a=min_a + i -1
  a0=i

if flg==1:
  print('-1')
else:
  print(max_a,min_a)

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]:

    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:
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] or (maxlst[i+1] % A[i] != 0 and minlst[i+1] % A[i] != 0 and (int(maxlst[i+1]) == int(minlst[i+1]))):
        print(-1)
        quit()
    maxlst[i] = int(A[i] - 1 + A[i] * math.floor(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()))

if k == 1:
  if a[0] == 2:
    print(2, 3)
  else:
    print(-1)
  exit(0)

temp = a[-1]
for i in reversed(range(k-1)):
  if a[i] >= temp:
    temp = a[i]
  else:
    temp = (temp//a[i] + (temp%a[i] != 0))*a[i]

ans = temp

for data in a:
  temp -= temp%data

if temp == 2:
  s = int(ans/a[1]+1)*a[1]
  if s%a[0] != a[0]-1:
    s -= s%a[0] + 1
  print(ans, s)
else:
  print(-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 and curr != 0:
	minv = curr
	curr = solve(minv)

maxv = 0
if  curr != 2 or curr == 0:
	print(-1)
else:
	maxv = minv + A[0] - 1
	print(minv, maxv)

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    K = int(input())
    A = list(map(int, input().split()))

    # min
    min_target_nums = [2]
    for min_a in reversed(A):
        tmp_min_targets = [_ for _ in min_target_nums if _ % min_a == 0]
        if len(tmp_min_targets) == 0:
            print(-1)
            exit()

        min_target = min(tmp_min_targets)
        min_target_nums = []
        min_target_nums += [_ + min_target for _ in range(min_a)]

    # max
    max_target_nums = [2]
    for max_a in reversed(A):
        tmp_max_targets = [_ for _ in max_target_nums if _ % max_a == 0]
        if len(tmp_max_targets) == 0:
            print(-1)
            exit()

        max_target = max(tmp_max_targets)
        max_target_nums = []
        max_target_nums += [_ + max_target for _ in range(max_a)]
    print(str(min(min_target_nums)) + " " + str(max(max_target_nums)))

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 a == 0:
        a = n
    cand = []
#    print(n,a,tmin+n-a,tmin*2)
    if tmin*2 <= n:
        print(-1)
        exit()
    else:
        tmin = tmin+n-a
        
    a = (2*tmax) % n
    if a == 0:
        a = n
    if tmax*2 <= n:
        print(-1)
        exit()
    else:
        tmax = (2*tmax)-a

print(tmin,tmax+lis[0]-1)

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
s = list(map(int, input().split()))
o = s
l = s[0]
mii = 2
if min(s) > 2:
    print("-1")
else:
    for i in range(1, n):
        if s[-i-1]<s[-i]:
            s[-i-1] *= math.ceil(s[-i] / s[-i-1])
    tes = s[0]
    for j in range(n):
        tes -= tes % o[j]
    if tes != 2:
        print("-1")
    else:
        print(s[0], s[0] + l - 1)

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):
                    if t % int(a[i-1]) == 0:
                        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()

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
    if min>max:min=max
  else:
    min=i
    max=max+i-(max%i)-1
if flag==0:
  print('{0} {1}'.format(min,max))