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())
s = list(map(int, input().split()))
mii = 2
if min(s) > 2:
    print("-1")
else:
    for i in range(1, n):
        uu = s[-i]
        mm = s[-i - 1]
        while uu > mm:
            mm += s[-i - 1]
        mii += mm % uu
    tes = mii
    for j in range(n):
        tes -= tes % s[j]
    if tes != 2:
        print("-1")
    else:
        print(mii, mii + s[0] - 1)

Submission status: Wrong Answer

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

    minN = 0
    maxN = 0
    i = max(A)
    while True:
        i += 1
        N = i
        for a in A:
            N -= N%a
            if N == 0:
                break
            
        else:
            if N == 2:
                if minN == 0:
                    minN = i
                    maxN = i
                else:
                    maxN = i
            elif N > 2:
                break

    if minN == 0:
        print(-1)
    else:
        print(minN, maxN)

Submission status: Wrong Answer

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

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

minval = 2
maxval = 3
for i in range(K-1,-1,-1):
	if maxval < A[i] or (minval > A[i] and (((minval % A[i]) + minval) < A[i])):
		print(-1)
		exit(0)

	if minval > A[i]:
		if minval % A[i] != 0:
			minval = minval + (A[i] - (minval % A[i]))

		maxval = (maxval - (maxval % A[i]) + A[i] - 1)

	else:
		maxval = A[i] + (A[i] - 1)
		minval = A[i]
		

print(str(minval) + " " + str(maxval))

Submission status: Wrong Answer

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

result = 0
cand_max = 2
cand_min = 2
for i in range(len(A))[::-1]:
    comp = int(cand_min / A[i]) * A[i]
    if cand_min <= comp <= cand_max:
        pass
    elif cand_min <= comp + A[i] <= cand_max:
        comp += A[i]
    else:
        result = -1
        break
    cand_max = comp + A[i] - 1
    cand_min = comp

if result == -1:
    print(-1)
else:
    print(cand_min, cand_max)

Submission status: Wrong Answer

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

    if not A[K - 1] == 2:
        print(-1)
        return

    nmin, nmax = 2, 2
    ii = list(range(K))
    ii.reverse()
    for i in ii:
        Ai = A[i]
        if Ai > nmax:
            print(-1)
            return
        if Ai < nmin:
            nmin = Ai * (nmin // Ai + 1)
        else:
            nmin = Ai
        if Ai < nmax:
            nmax = Ai * (nmax // Ai + 1) - 1
        else:
            nmax = Ai * 2 - 1
    print(nmin, nmax)


main()

Submission status: Wrong Answer

Solution code:
k, temp = int(input()), input().split()
A = []
for a in temp:
    A.append(int(a))

N = []

imin = min(A)
imax = min(A) + (len(A)-1)*max(A)
for i in range(imin,imax):
    sum = i
    for j in range(0,k):
        sum = A[j] * int(sum/A[j])
    if sum/2 == 1:
        N.append(i)

if N:
    print(min(N), max(N))
else:
    print(-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 = a[i]
    j = 2
    while m < a[i-1]:
        m *= j
        j += 1

    if c > m:
        print('-1')
        exit()
    else:
        c = m
        
print(c, c+a[k-1]-1)

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
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:
n = int(input())
s = list(map(int, input().split()))
mii = 2
if min(s) > 2:
    print("-1")
else:
    for i in range(1, n):
        uu = s[-i]
        mm = s[-i - 1]
        while uu > mm:
            mm += s[-i - 1]
        mii += mm % uu
        print(mm%uu)
    tes = mii
    for j in range(n):
        tes -= tes % s[j]
    if tes != 2:
        print("-1")
    else:
        print(mii, mii + s[0] - 1)

Submission status: Wrong Answer

Solution code:
N = int(input())
ops = list(input().split())
P = []
ans1 = 0
for s in range(N-1, -1, -1):
    P.append(int(ops[s]))

for i in range(N-1):
    ans1 += P[i] % P[i+1]
        
if ans1 < max(P):
    ans1 = -1
    print(ans1)
else:
    if ans1 == 0:
        ans1 = P[0]
    elif ans1 % P[N-1] != 0:
        ans1 -= ans1 % P[N-1]
    ans2 = ans1 +  P[N-1] - 1
    print(str(ans1) + " "+ str(ans2))

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
  else:
    min=min+i-(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=2

for i in range(k-1):
#    print(a[k-i-1])
#    print(a[k-i-2],number)  
    if a[k-i-2]>=2*number:
        print(-1)
        count=1
        break
    else:
        if number>a[k-i-2]:
            number=(number//a[k-i-2]+1)*a[k-i-2]
        else:
            number=a[k-i-2]

n=number
if count==0: 
  for i in range(k):
    n=(n//a[i])*a[i]
  if n!=2:
    print(-1)
  else:
    print(number,number+a[0]-1)

Submission status: Wrong Answer

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

    A_rev = reversed(A)

    cand = []
    target_nums = [2]
    # min
    for i, a in enumerate(A_rev):
        if i == 0 and a != 2:
            print(-1)
            exit()

        targets = [_ for _ in target_nums if _ % a == 0]
        if len(targets) == 0:
            print(-1)
            exit()
        target = min(targets)

        target_nums = [_ for _ in range(a)]
        target_nums = list(map(lambda x: x + target, target_nums))

    print(str(min(target_nums)) + " " + str(max(target_nums)))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
mn, mx = 2, 2
def no():
    print(-1)
    exit(0)
for i in range(n - 1, 0, -1):
    mn = (mn + a[i - 1] - 1) // a[i - 1] * a[i - 1];
    mx = (mx + a[i] - 1) // a[i - 1] * a[i - 1];
    if (mn > mx): no();
mx += a[0] - 1
print(mn, mx)

Submission status: Wrong Answer

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

ans = []
x0 = 2
for i in range(k - 1, -1, -1):
    x = ((x0 + a[i] - 1) // a[i]) * a[i]
    if i < k - 1 and a[i + 1] - 1 < x - x0:
        ans = [-1]
        break
    x0 = x
if ans == []:
    ans = [x0, x0 + a[0] - 1]
print(' '.join(map(str, ans)))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(reversed(list(map(int,input().split()))))
if a[0]>2:
	print("-1")
	exit()
a1,a2=2,2
for i in range(1,n):
	a1+=(a[i]-a1%a[i])%a[i]
	pre=a2
	a2+=a[i-1]-1
	a2-=a2%a[i]
	if a2<pre:
		print("-1")
		exit()
print(a1,a2+a[n-1]-1)

Submission status: Wrong Answer

Solution code:


def main():
    k = int(input())
    aa = list(map(int, input().split()))[::-1] + [1]
    if aa[0] != 2:
        print(-1)
        return
    min_n, max_n = 2, 2
    for i in range(k):
        a = aa[i]
        b = aa[i + 1]
        m = max_n + a - 1
        m -= m % b
        if min_n > m:
            print(-1)
            return
        else:
            max_n = m
        if min_n % a:
            min_n = (min_n // a + 1) * a
        else:
            min_n = min_n // a * a
    print(min_n, max_n)


main()

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))
ans = [2]
for i in reversed(a):
    if ans[-1] % i != 0:
        ans.append(ans[-1] + i - (ans[-1] % i))
    else:
        ans.append(ans[-1])
    if ans[-1] // ans[-2] > 1:
        print(-1)
        quit()
ans.append(ans[-1] + a[0] - 1)
print(ans[-2], ans[-1])

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

for i in range(k-1):
#    print(a[k-i-1])
#    print(a[k-i-2],number)  
    if a[k-i-2]>=2*number:
        print(-1)
        count=1
        break
    else:
        if number>a[k-i-2]:
            number=(number//a[k-i-2]+1)*a[k-i-2]
        else:
            number=a[k-i-2]


if count==0: print(number,number+a[0]-1)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
from heapq import heappush, heappop
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy4, dx4 = [0, -1, 0, 1], [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W
def ceil(a, b):return (a + b - 1) // b


def up(a, b):
    s = ceil(a, b)
    for i in range(s - 1, s + 3):
        if i * b > a:
            return i * b


def solve():
    K = int(input())
    A = list(map(int, input().split()))

    if A[-1] != 2:
        return [-1]

    min_a, max_a = 2, 3
    for a in A[::-1][1:]:
        if a > max_a:
            return [-1]
        else:
            max_a = up(max_a, a) - 1

        if a >= min_a:
            min_a = a
        else:
            min_a = up(min_a, a)

    return min_a, max_a


def main():
    print(*solve())
    # print(up(8, 3))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:


def main():
    k = int(input())
    aa = list(map(int, input().split()))[::-1] + [1]
    if aa[0] != 2:
        print(-1)
        return
    min_n, max_n = 2, 2
    for i in range(k):
        a = aa[i]
        b = aa[i + 1]
        m = max_n + a - 1
        m -= m % b
        if max_n > m:
            print(-1)
            return
        else:
            max_n = m
        if min_n % a:
            min_n = (min_n // a + 1) * a
        else:
            min_n = min_n // a * a
    print(min_n, max_n)


main()

Submission status: Wrong Answer

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

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

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

print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(reversed(list(map(int,input().split()))))
if a[0]>2:
	print("-1")
	exit()
ans=2
for i in range(1,n):
	pre=ans
	ans+=(a[i]-ans%a[i])%a[i-1]
	if ans-ans%a[i-1]!=pre:
		print("-1")
		exit()
print(ans,ans+a[n-1]-1)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
a = K-1
p = 2
while 0 <= a:
    if A[a-1] > A[a]*2:
        print('-1')
        exit()
    num = 1
    if A[a] < p:
        while A[a]*num < p:
            num += 1
    p = num*A[a]
    a -= 1

print(p,p-1+A[0])

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

    c = c + a[0] - 1

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

print(main())

Submission status: Wrong Answer

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

else:
    print p,q

Submission status: Wrong Answer

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

num_max=a[-1]
num_min=a[-1]
for i in range(k-2,-1,-1):
	member=a[i]
	
	j=1
	while member*j<num_min:
		j+=1
	if num_min<= member*j and member*j<num_min+a[i+1]:
		num_min=member*j
	else:
		flag=False
		break
	while member*j<num_max+a[i+1]:
		j+=1
	num_max=member*(j-1)
	
	#print(str(num_min)+" "+str(num_max))
num_max+=a[0]-1
if flag:
	print(str(num_min)+" "+str(num_max))
else:
	print(-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 a[-1] != 2:
        return -1
    b = c = 2
    for t in a[::-1][1:]:
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b = (b+t) - b%t
        else:
            b = t
        k = c * 2 - 1
        c = k - (k%t)

    c = c + a[0] - 1

    return '{} {}'.format(b%mod, c%mod)

print(main())

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(reversed(list(map(int,input().split()))))
if a[0]>2:
	print("-1")
	exit()
ans=2
for i in range(1,n):
	pre=ans
	ans+=(a[i]-ans%a[i])%a[i]
	if ans-ans%a[i-1]!=pre:
		print("-1")
		exit()
print(ans,ans+a[n-1]-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 a[-1] != 2:
        return -1
    b = c = 2
    for t in a[::-1][1:]:
        if b * 2 <= t:
            return -1
        if b % t == 0:
            pass
        elif b > t:
            b = (b+t) - b%t
        else:
            b = t
        k = c * 2 - 1
        c = k - (k%t)

    c = c + a[0] - 1

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

print(main())

Submission status: Wrong Answer

Solution code:
from math import ceil


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


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

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 t in a[::-1][1:]:
        if b * 2 <= t:
            return -1
        if b > t:
            b = (b+t) - b%t
        else:
            b = t
        k = c * 2 - 1
        c = k - (k%t)
    c = c + a[0] - 1

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

print(main())

Submission status: Time Limit Exceeded

Solution code:
import math
K = int(input())
A = list(map(int, input().split()))
def check(init, A):
    cnt = init
    for a in A:
        group = cnt // a
        cnt = group * a
    return cnt

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) > 2:
        r = mid
    else:
        l = mid
maxcnt = l

l,r = 0, 2**100
while r-l > 1:
    mid = (l+r)//2
    if check(mid, A) < 2:
        l = mid
    else:
        r = mid
mincnt = r


if check(mincnt, A) == check(maxcnt, A) == 2:
    print(mincnt, maxcnt)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    # from collections import deque
    k = int(input())
    a = list(map(int, input().split()))
    now = [2]
    if k == 1:
        print("2 3") if a[0] == 2 else print(-1)
    else:
        for i in reversed(range(1,k)):
            nxt = []
            for j in range(len(now)):
                test = now[j]
                nxtd = a[i-1]
                if test % a[i] == 0:
                    mod = test % nxtd
                    if (nxtd-mod)%nxtd < a[i]:
                        for k in range((nxtd-mod)%nxtd, a[i], nxtd):
                            nxt.append(k+test)
            if not nxt:
                print(-1)
                exit()
            now = nxt
        ans = []
        for i in now:
            test = i
            if test % a[0] == 0:
                ans.append(i)
                ans.append(i+a[0]-1)
        ans = sorted(ans)
        print("{} {}".format(ans[0], ans[-1]))
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    from collections import deque
    k = int(input())
    a = list(map(int, input().split()))

    ra = a[::-1]
    now = deque([2])
    for i in range(k):
        nxt = deque([])
        while now:
            test = now.popleft()
            if test % ra[i] == 0:
                k = 0
                while k < ra[i]:
                    nxt.append(test+k)
                    k += 1
        if not nxt:
            print(-1)
            exit()
        now = nxt
    nxt = sorted(list(nxt))
    print("{} {}".format(nxt[0], nxt[-1]))
resolve()

Submission status: Time Limit Exceeded

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

    ra = a[::-1]
    now = [2]
    for i in range(k):
        nxt = []
        for j in range(len(now)):
            test = now[j]
            if test % ra[i] == 0:
                k = 0
                while k < ra[i]:
                    nxt.append(test+k)
                    k += 1
        if not nxt:
            print(-1)
            exit()
        now = nxt
    nxt = sorted(nxt)
    print("{} {}".format(nxt[0], nxt[-1]))
resolve()

Submission status: Time Limit Exceeded

Solution code:
def calc(n, N, x):
    m, M = -1, -1
    L, R = 0, 10**18
    while L+1 < R:
        P = (L+R)//2
        if n <= x*P:
            R = P
        else:
            L = P
    if n <= x*R <= N:
        m = x*R
    L, R = 0, 10**18
    while L+1 < R:
        P = (L+R)//2
        if N < x*P:
            R = P
        else:
            L = P
    if n <= x*L <= N:
        M = x*L + (x-1)
    return m, M

def main():
    k = int(input())
    a = list(map(int, input().split()))
    f = True
    m, M = 2, 2
    for i in reversed(range(k)):
        m, M = calc(m, M, a[i])
        if m == -1 or M == -1:
            f = False
            break
    if f:
        print(m, M)
    else:
        print(-1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

l = -1
r = 10**18
while r - l > 1:
    m = l + (r-l)//2
    n = m
    for i in range(k):
        n = n//a[i] * a[i]
    if n >= 2:
        r = m
    else:
        l = m

ansl = r
l = -1
r = 10**18
while r - l > 1:
    m = l + (r-l)//2
    n = m
    for i in range(k):
        n = n//a[i] * a[i]
    if n <= 2:
        l = m
    else:
        r = m

ansr = l

if ansl <= ansr:
    print(ansl, ansr)
else:
    print(-1)

Submission status: Time Limit Exceeded

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


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N = (N//a)*a

    if N > 2:
        r = m
    else:
        l = m
upper = l


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N = (N//a)*a

    if N < 2:
        l = m
    else:
        r = m
lower = r

if lower > upper:
    print(-1)
else:
    print(lower, upper)

Submission status: Time Limit Exceeded

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


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N -= N % a

    if N > 2:
        r = m
    else:
        l = m
upper = l


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N -= N % a

    if N < 2:
        l = m
    else:
        r = m
lower = r

if lower > upper:
    print(-1)
else:
    print(lower, upper)

Submission status: Time Limit Exceeded

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


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N -= max(N % a, 0)
    if N > 2:
        r = m
    else:
        l = m
upper = l


l = 0
r = 10 ** 20
while r - l > 1:
    m = (r + l) // 2
    N = m
    for a in A:
        N -= max(N % a, 0)

    if N < 2:
        l = m
    else:
        r = m
lower = r

if lower > upper:
    print(-1)
else:
    print(lower, upper)

Submission status: Time Limit Exceeded

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

a.reverse()
now=[]
now.append(2)

for group in a:
    nxt_now = []
    for num in now:
        if num % group !=0:
            continue

        for i in range(group):
            nxt_now.append(num+i)
    if len(nxt_now) ==0:
        print(-1)
        exit()

    now = nxt_now
print(min(now),max(now))

Submission status: Time Limit Exceeded

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

l, r = 1, 10 ** 18
while r - l > 1:
    m = (l + r) // 2
    M = m
    for a in A:
        M = (M // a) * a

    if M <= 2:
        l = m
    else:
        r = m
ans_max = l

l, r = 1, 10 ** 18
while r - l > 1:
    m = (l + r) // 2
    M = m
    for a in A:
        M = (M // a) * a

    if M >= 2:
        r = m
    else:
        l = m
ans_min = r

if ans_min > ans_max:
    print(-1)
else:
    print(ans_min, ans_max)

Submission status: Time Limit Exceeded

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

high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp <= 2:
        low = mid
    else:
        high = mid
    L = low
    
high = 10**18
low = 0

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp >= 2:
        high = mid
    else:
        low = mid
    S = high

if S <= L:
    print(S,L)
else:
    print(-1)

Submission status: Time Limit Exceeded

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

high = 10**18
low = -1

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp <= 2:
        low = mid
    else:
        high = mid
    L = low
    
high = 10**18
low = -1

while high-low > 1:
    mid = (high+low)//2
    tmp = mid
    for i in range(K):
        tmp = tmp//A[i]*A[i]
    if tmp >= 2:
        high = mid
    else:
        low = mid
    S = high

if S <= L:
    print(S,L)
else:
    print(-1)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
A = list(map(int,input().split()))
B = [2]
for i in range(K-1,-1,-1):
    a = A[i]
    C = []
    for b in B:
        if b%a==0:
            C.append(b)
    B = []
    if len(C)==0:break
    for c in C:
        for j in range(a):
            if c+j not in B:
                B.append(c+j)
if len(B)==0:
    print(-1)
else:
    B = sorted(B)
    print(B[0],B[-1])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
a = list(map(int, input().split()))
l, r = 0, 10 ** 100
while r - l > 1:
    m = (l + r) // 2
    t = m
    for x in a:
        m = m // x * x
    if m <= 2:
        l = t
    else:
        r = t
l2, r2 = 0, 10 ** 100
while r2 - l2 > 1:
    m = (l2 + r2) // 2
    t = m
    for x in a:
        m = m // x * x
    if m < 2:
        l2 = t
    else:
        r2 = t
if l < r2:
    print(-1)
else:
    print(r2, l)

Submission status: Time Limit Exceeded

Solution code:
K = int(input())
A = list(map(int,input().split()))[::-1]

cand = [2]
for a in A:
    tmp = []
    for c in cand:
        if c % a == 0:
            tmp += list(range(c, c+a))
    cand = tmp[:]

if len(cand) == 0:
    print(-1)
else:
    print(cand[0], cand[-1])

Submission status: Time Limit Exceeded

Solution code:
k = int(input())
nums = reversed([ int(s) for s in input().split(" ")])

pass_n = set([2])
for n in nums:

    # pass_n = このラウンドを通過する人数として可能性のある候補

    new_pass_n = set()
    # pass_n人通過させることが可能か？
    found=False
    for p in pass_n:
        if p % n == 0:
            # 可能
            found = True
            # このラウンドに進出する人数として可能性のある候補
            for i in range(n):
                new_pass_n.add(p + i)
            
    if not found:
        # 不可能
        print(-1)
        exit()

    pass_n = new_pass_n

print(min(pass_n), max(pass_n))

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

maxr = 2
minr = 2
r = 0
for n in reversed(L):
    if any(x % n == 0 for x in range(minr, maxr+1)):
        # if minr//n <= maxr//n:
        minr = ceil(minr/n)*n
        maxr = (maxr)//n*n+n-1
    else:
        n = -1
        break

if n == -1:
    print(n)
else:
    print(int(minr), maxr)

Submission status: Time Limit Exceeded

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

A=A[-1::-1]

def check(n,p):
	#print(n,p)
	return {i for i in range(p,p+n)}

ps = {2}
k = len(A)
for n in A:
	ps = {x  for x in ps if x % n == 0}
	if len(ps) == 0:
		print(-1)
		exit()
	t=set()
	for p in ps:
		t=t.union({i for i in range(p,p+n)})
	ps = t

a = list(ps)
print(min(a),max(a))

Submission status: Time Limit Exceeded

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

A=A[-1::-1]

def check(n,p):
	#print(n,p)
	res = []
	if p % n != 0:
		return []
	return {i for i in range(p,p+n)}

ans = []
ps = {2}
for n in A:
	t=set()
	for p in ps:
		t=t.union(check(n,p))
	#print(t)
	if len(t)==0:
		print(-1)
		exit()
	ps = t

a = list(ps)
print(min(a),max(a))

Submission status: Time Limit Exceeded

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

#始めの人数がn人だった時終わりの人数
def g(n,a,k):
    for i in range(k):
        n = n - (n%a[i])
    return n

#print(g(8,a,k))

s = 0
t = 2 + k*max(a)
for i in range(100):
    m = (s+t)//2
    if g(m,a,k)> 2:
        t = m
    else:
        s = m
    
p = 0
q = 2+k*max(a)
for i in range(100):
    m = (p+q)//2
    if g(m,a,k) >= 2:
        q = m
    else:
        p = m

c = 1
if g(s,a,k) == 2:
    res = s
elif g(t,a,k) == 2:
    res = t
else:
    c = -1

if g(q,a,k) == 2:
    res2 = q
elif g(p,a,k) == 2:
    res2 = p
else:
    c = -1

if c == 1:
    print(res2,res)
else:
    print(-1)