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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
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 DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    k = int(input())
    a = list(map(int,input().split()))
    
    min = 2
    max = 2

    for i in range(k):
        if max < a[k-1-i]:
            print(-1)
            exit()
        
        max = a[k-1-i]*(max // a[k-1-i]) + a[k-1-i] - 1
        min = a[k-1-i]*(( (min - 1) // a[k-1-i]) + 1)
    
    print(min,max)

    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
        def dump(*args):
            names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
            print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
    except:
        def dump(*args):
            pass

    solve()

# vim: set foldmethod=marker:}}}

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def f(m):
        if d[m] != None:
            return d[m]
        n = m
        for i in a:
            n = n-n%i
        d[m] = n
        return n
    k = I()
    a = LI()
    d = defaultdict(lambda : None)
    l,r = 0,1e19
    while r-l > 1:
        m = (r+l)//2
        if f(m) < 2:
            l = m
        else:
            r = m
    mi = r
    l,r = 0,1e19
    while r-l > 1:
        m = (r+l)//2
        if f(m) <= 2:
            l = m
        else:
            r = m
    ma = l
    if mi <= ma:
        if f(mi) != 2:
            print(-1)
        else:
            print(mi,ma)
    else:
        print(-1)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return


#Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def f(m):
        if d[m] != None:
            return d[m]
        n = m
        for i in a:
            n = n-n%i
        d[m] = n
        return n
    k = I()
    a = LI()
    d = defaultdict(lambda : None)
    l,r = 0,2000000000
    while r-l > 1:
        m = (r+l)//2
        if f(m) < 2:
            l = m
        else:
            r = m
    mi = r
    l,r = 0,2000000000
    while r-l > 1:
        m = (r+l)//2
        if f(m) <= 2:
            l = m
        else:
            r = m
    ma = l
    if mi <= ma:
        if f(mi) != 2:
            print(-1)
        else:
            print(mi,ma)
    else:
        print(-1)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return


#Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def f(m):
        if d[m] != None:
            return d[m]
        n = m
        for i in a:
            n = n-n%i
        d[m] = n
        return n
    k = I()
    a = LI()
    d = defaultdict(lambda : None)
    l,r = 0,2000000000
    while r-l > 1:
        m = (r+l)//2
        n = f(m)
        if n < 2:
            l = m
        else:
            r = m
    mi = r
    l,r = 0,2000000000
    while r-l > 1:
        m = (r+l)//2
        n = f(m)
        if n > 2:
            r = m
        else:
            l = m
    ma = l
    if mi < ma:
        if f(mi) != 2:
            print(-1)
        else:
            print(mi,ma)
    else:
        print(-1)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return


#Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    def f(m):
        n = m
        for i in a:
            n = n-n%i
        return n
    k = I()
    a = LI()
    l,r = 0,1000000000
    while r-l > 1:
        m = (r+l)//2
        n = f(m)
        if n < 2:
            l = m
        else:
            r = m
    mi = r
    l,r = 0,1000000000
    while r-l > 1:
        m = (r+l)//2
        n = f(m)
        if n > 2:
            r = m
        else:
            l = m
    ma = l
    if mi < ma:
        print(mi,ma)
    else:
        print(-1)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return


#Solve
if __name__ == "__main__":
    B()

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr=arr[::-1]
if arr[0]!=2:
  print(-1)
else:
  l=2
  r=3
  for i in range(1,n):
    val=arr[i]
    if l<=val*(l//val)<=r:
      k=l//val
    elif l<=val*(r//val)<=r:
      k=r//val
    else:
      print(-1)
      break
    if arr[i-1]%val!=0:
      l=k*val
      r=(k+1)*val-1
  else:
    print(l,r)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr=arr[::-1]
if arr[0]!=2:
  print(-1)
else:
  arr=arr[1:]
  l=2
  r=3
  for val in arr:
    if l<=val*(l//val)<=r:
      k=l//val
    elif l<=val*(r//val)<=r:
      k=r//val
    else:
      print(-1)
      break
    l=k*val
    r=(k+1)*val-1
  else:
    print(l,r)

Submission status: Wrong Answer

Solution code:
n=int(input())
arr=list(map(int,input().split()))
arr=arr[::-1]
arr=arr[1:]
l=2
r=3
for val in arr:
  if l<=val*(l//val)<=r:
    k=l//val
  elif l<=val*(r//val)<=r:
    k=r//val
  else:
    print(-1)
    break
  l=k*val
  r=(k+1)*val-1
else:
  print(l,r)

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())
A = [int(i) for i in input().split()]
A.reverse()
if K == 1 and A[0] == 2:
    print(2,3)
    sys.exit()
if K == 1 and A[0] == 1:
    print(2,2)
    sys.exit()
ls = [2,3]
for x in A[1:]:
    cur = 0
    l, r = 0,0
    for i in range(ls[0], ls[1]+1):
        if i%x == 0:
            l = i
            break
        else:
            cur += 1
    if cur == ls[1] - ls[0] + 1:
        print(-1)
        sys.exit()
    for i in list(range(ls[0], ls[1]+1))[::-1]:
        if i%x == 0:
            r = i+(x-1)
            break
    ls[0], ls[1] = l, r
print(ls[0], ls[1])

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())
A = [int(i) for i in input().split()]
A.reverse()
if K == 1:
    print(2,3)
    sys.exit()
ls = [2,3]
for x in A[1:]:
    cur = 0
    l, r = 0,0
    for i in range(ls[0], ls[1]+1):
        if i%x == 0:
            l = i
            break
        else:
            cur += 1
    if cur == ls[1] - ls[0] + 1:
        print(-1)
        sys.exit()
    for i in list(range(ls[0], ls[1]+1))[::-1]:
        if i%x == 0:
            r = i+(x-1)
            break
    ls[0], ls[1] = l, r
print(ls[0], ls[1])

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())
A = [int(i) for i in input().split()]
A.reverse()
if K == 1:
    print(2,3)
    sys.exit()
ls = [2,3]
for x in A[1:]:
    cur = 0
    for i in range(ls[0], ls[1]+1):
        if i%x == 0:
            ls[0] = i
            break
        else:
            cur += 1
    if cur == ls[1] - ls[0] + 1:
        print(-1)
        sys.exit()
    for i in list(range(ls[0], ls[1]+1))[::-1]:
        if i%x == 0:
            ls[1] = i+(x-1)
            break
print(ls[0], ls[1])

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    A = list(map(int, input().split()))
    mn = 2
    mx = 2
    for a in reversed(A):
        if mx < a:
            print(-1)
            return
        mn = -(-mn//a) * a
        mx = (mx // a * a) + (a-1)
        mn = min(mn, mx)
    print(mn, mx)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    K = int(input())
    A = list(map(int, input().split()))
    mn = 2
    mx = 2
    for a in reversed(A):
        if mx < a:
            print(-1)
            return
        mn = -(-mn//a) * a
        mx = (mx // a * a) + (a-1)
    print(mn, mx)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))
if a[-1] != 2:
    print(-1)
    quit()
l, r = 2, 3
for i in range(k-2, -1, -1):
    s = ((l-1)//a[i]+1) * a[i]
    if s > r:
        print(-1)
        quit()
    t = max((((r-1)//a[i]+1) * a[i] - 1), s+a[i]-1)
    l, r = s, t
print(l, r)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))
if a[-1] != 2:
    print(-1)
    quit()
l, r = 2, 3
for i in range(k-2, -1, -1):
    s = ((l-1)//a[i]+1) * a[i]
    if s > r:
        print(-1)
        quit()
    l, r = s, s+a[i]-1
print(l, r)

Submission status: Wrong Answer

Solution code:
n=int(input())
da=list(map(int ,input().split()))
Min=2
Max=2
ju=True
for i in da[::-1]:
    mi=(Min+i-1)//i
    ma=Max//i
    if mi*i>Max or ma*i<Min:
        ju=False
        break
    Min=mi*i
    Max=ma*i+i-1
if ju:
    print(Max,Min)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import math
k = int(input())
a = [int(item) for item in input().split()]
a.reverse()

max_num = a[0]
min_num = a[0]
for i in range(k):
    next_max = int(math.floor(max_num / a[i])) * a[i] + a[i] - 1
    next_min = int(math.ceil(min_num / a[i])) * a[i]
    if i+1 < k and int(math.floor(next_max / a[i+1])) * a[i+1] < int(math.ceil(next_min / a[i+1])) * a[i+1]:
        print(-1)
        exit()
    max_num = next_max
    min_num = next_min
print(min_num, max_num)

Submission status: Wrong Answer

Solution code:
import math
k = int(input())
a = [int(item) for item in input().split()]
a.reverse()

max_num = a[0]
min_num = a[0]
for i in range(k):
    next_max = int(math.floor(max_num / a[i])) * a[i] + a[i] - 1
    next_min = int(math.ceil(min_num / a[i])) * a[i]
    if int(math.floor(next_max / a[i])) * a[i] < int(math.ceil(next_min / a[i])) * a[i]:
        print(-1)
        exit()
    max_num = next_max
    min_num = next_min
print(min_num, max_num)

Submission status: Wrong Answer

Solution code:
import math
k = int(input())
a = [int(item) for item in input().split()]
a.reverse()

max_num = a[0]
min_num = a[0]
for i in range(k):
    next_max = int(math.floor(max_num / a[i])) * a[i] + a[i] - 1
    next_min = int(math.ceil(min_num / a[i])) * a[i]
    if next_max < next_min:
        print(-1)
        exit()
    max_num = next_max
    min_num = next_min
print(min_num, max_num)

Submission status: Wrong Answer

Solution code:
k = int(input())
a = [int(item) for item in input().split()]
a.reverse()

max_num = a[0]
min_num = a[0]
for i in range(k-1):
    next_max = (max_num + a[i] - 1) - (max_num + a[i] - 1) % a[i+1]
    if max_num > next_max:
        print(-1)
        exit()
    next_min = min_num + (a[i+1] - min_num % a[i+1]) % a[i+1]
    max_num = next_max
    min_num = next_min
max_num += a[-1] - 1
print(min_num, max_num)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.reverse()
k = 2
for i in range(1,N):
  if k%A[i] != 0:
    k = A[i]*(k//A[i]+1)
MA = k+A[N-1]-1
MI = k
ken = MI
for i in range(N):
  ken = ken-(ken%A[N-i-1])
if ken == 2:
  print(MI,MA)
else:
  print(-1)

Submission status: Wrong Answer

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 ceil(maxr//n) >= minr:
        # 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: Wrong Answer

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 ceil(maxr//n) > minr:
        # 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: Wrong Answer

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 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: Wrong Answer

Solution code:
# 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):
    r = -1
    for i in range(minr, maxr+1):
        if i % n == 0:
            r = i
            break
    if r < 0:
        print(-1)
        exit()

    if any(v % n == 0 for v in range(minr, maxr+1)):
        minr = r
        maxr = minr+n-1
    else:
        n = -1
        break
if n == -1:
    print(n)
else:
    print(minr, maxr)

Submission status: Wrong Answer

Solution code:
# 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):
    r = -1
    for i in range(minr, maxr+1):
        if i % n == 0:
            r = i
            break

    if any(v % n == 0 for v in range(minr, maxr+1)):
        minr = r
        maxr = minr+n-1
    else:
        n = -1
        break
if n == -1:
    print(n)
else:
    print(minr, maxr)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int,input().split()))
max_ans = 2
min_ans = 2
judge = 0
if A[K-1] != 2:
	print(-1)

else:
	for i in range(K - 1):
		if max_ans < A[K - 2 - i]:
			print(-1)
			judge = 1
			break
		else:
			temp_max = max_ans + A[K - 1 - i] - 1
			while temp_max % A[K - 2 - i] != 0:
				temp_max -= 1
			max_ans = temp_max
			temp_min = min_ans
			while temp_min % A[K - 2 - i] != 0:
				temp_min += 1
			min_ans = temp_min

	if judge == 0:		
		max_ans += A[0] - 1
		print(min_ans,max_ans)

Submission status: Wrong Answer

Solution code:
import sys
K=int(input())
A=[int(i) for i in input().split()]
B=A[::-1]
if B[0]!=2:
    print(-1)
    sys.exit()
a=2
b=3
for i in range(1,K):
    x=B[i]
    if a%x==0:
        c=a
    else:
        c=((a//x)+1)*x
    if a<=c<=b:
        a=c
        b=c+x-1
    else:
        print(-1)
        sys.exit()
    #print(a,b,c,x)
print(a,b)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=list(map(int,input().split()))
def f(x):
    for i in range(k):
        x-=x%a[i]
    return x
s=k*max(a)+3
t=0
while s-t>1:
    x=(s+t)//2
    if f(x)>2:
        s=x
    else:
        t=x
p=k*max(a)+3
q=0
while p-q>1:
    x=(p+q)//2
    if f(x)>=2:
        q=x
    else:
        p=x
if f(t)==2:
    if f(q)==2:
        print(q,t)
    else:
        print(-1)
else:
    print(-1)
print(f(p))

Submission status: Wrong Answer

Solution code:
import sys
# K = int(input())
# A = list(map(int, input().split()))
K = int(input())
A = list(map(int, input().split()))
cur = 2
if A[-1]!=2: 
    print(-1)
    sys.exit()
cond_m,cond_M = 2,3
ans = []
for ai in reversed(A[:K-1]):
    if cond_m%ai==0:
        next_m = cond_m
        next_M = (next_m//ai+1)*ai-1
    else:
        next_m = (cond_m//ai+1)*ai
        next_M = (next_m//ai+1)*ai-1
    if not(cond_m <= next_m <= cond_M):
        print(-1)
        sys.exit()
    cond_m,cond_M = next_m,next_M
    #print(ai, cond_m, cond_M)
print(cond_m, cond_M)

Submission status: Wrong Answer

Solution code:
import sys
K = int(input())
A = list(map(int, input().split()))
cur = 2
if A[-1]!=2: 
    print(-1)
    sys.exit()
for ai in reversed(A):
    if cur%ai==0: continue
    cur = (cur//ai+1)*ai
ans = [cur, A[0]*(cur//A[0]+1)-1]
for ans_i in ans:
    for ai in A:
        ans_i = (ans_i//ai)*ai
    if ans_i!=2:
        print(-1)
        sys.exit()
else:
    print(*ans)

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(int, input().split()))
cur = 2
if A[-1]!=2: 
    print(-1)
    exit()
for ai in reversed(A):
    if cur%ai==0: continue
    cur = (cur//ai+1)*ai
ans = [cur, A[0]*(cur//A[0]+1)-1]
for ans_i in ans:
    for ai in A:
        ans_i = (ans_i//ai)*ai
    if ans_i!=2:
        print(-1)
        exit()
else:
    print(*ans)

Submission status: Wrong Answer

Solution code:
def L(l,a):
    return ((l-1)//a)*a+a

def R(r,a):
    return (r//a)*a+a-1
K = int(input())
x = list(map(int,input().split()))
l=2
r=2
for i in range(K):
    a = x.pop()
    l = L(l,a)
    r = R(r,a)
    if l > r:
        l = r = -1
        break

print(l,r)

Submission status: Wrong Answer

Solution code:
import collections as c
ip = lambda : map(int, input().split())

#################
K=int(input())
al = [int(i) for i in input().split()]

s,l = 2,2
for i in range(K-1,-1,-1):
    c = 0
    for j in range(s,l+al[i]-1+1):
        if j%al[i-1]==0:
            if c==0:
                s = j
            l = j
            c += 1
    if c==0:
        print(-1)
        exit()
    if i==1:
        print(s,l+al[0]-1)

Submission status: Wrong Answer

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

A=A[::-1]

min_t_num=2
max_t_num=2

if A[0]==2:
    flg=True
    for i in range(1,K):
        prev_min=min_t_num
        prev_max=max_t_num
        min_t_num=(min_t_num//A[i]+1)*A[i]
        max_t_num=int(np.floor(max_t_num/A[i]))*A[i]+A[i]-1
        if A[i-1]*(min_t_num//A[i-1])!=prev_min or A[i-1]*(max_t_num//A[i-1])!=prev_max:
            flg=False
            break
    
    if flg:
        print(min_t_num,max_t_num)
    else:
        print(-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

A=A[::-1]

min_t_num=2
max_t_num=2

if A[0]==2:
    flg=True
    for i in range(1,K):
        prev_min=min_t_num
        prev_max=max_t_num
        min_t_num=int(np.ceil(min_t_num/A[i]))*A[i]
        max_t_num=int(np.ceil((max_t_num+A[i-1])/A[i])-1)*A[i]
        if A[i-1]*(min_t_num//A[i-1])!=prev_min or A[i-1]*(max_t_num//A[i-1])!=prev_max:
            flg=False
            break
    
    if flg:
        max_t_num+=A[K-1]-1
        print(min_t_num,max_t_num)
    else:
        print(-1)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**6) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

k = ni()
a = list(li())

exist = True

# lower
for i, ai in enumerate(a[::-1]):
    if i == 0:
        if ai != 2:
            exist = False
            break
        else:
            upper = 3
            lower = 2
            
    else:
        yi = ai * (lower//ai + bool(lower%ai))
        if lower <= yi <= upper:
            lower = yi
            upper = yi+ai-1
            
        else:
            exist = False
            break
                
                
if exist:                
    ans_lower = lower


# upper
for i, ai in enumerate(a[::-1]):
    if i == 0:
        if ai != 2:
            exist = False
            break
        else:
            upper = 3
            lower = 2
            
    else:
        yi = ai * (upper//ai)
        if lower <= yi <= upper:
            lower = yi
            upper = yi+ai-1
            
        else:
            exist = False
            break
                
if exist:
    ans_upper = upper

        
print(ans_lower, ans_upper) if exist else print(-1)

Submission status: Wrong Answer

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

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

ma = 2
mi = 2
L = reversed(L)

for l in L:
    if l > ma:
        print(-1)
        exit()
    else:
        mi = (mi//l)*l
        ma = (ma//l)*(l)+l-1
print(mi, ma)

Submission status: Wrong Answer

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

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

ma = 2
mi = 2
L = reversed(L)

for l in L:
    if l > ma:
        print(-1)
        exit()
    else:
        mi = ma//l*l
        ma = mi+l-1
print(mi, ma)

Submission status: Wrong Answer

Solution code:
K =int(input())
A = list(map(int,input().split()))
right = sum(A)
length = len(A)
flag = True
maxi = 0
mini = 0
temp1 = float("inf")
temp2 = 0
for a in A[:K-1]:#残り人数を二人にできるかどうか検証
    right -= a
    length -= 1
    if(a > right -length +2):
        flag = False

if(flag):
    for a in reversed(A):
        if(maxi ==0):
            maxi = 2
        elif(temp1 ==a and temp2 ==a):
            maxi = maxi
        elif(maxi%a == a-1):
            maxi += a
        else:
            maxi += (a-1-maxi%a)
        
        if(mini ==0):
            mini = 2
        elif(mini%a != 0):
            mini += (a - mini%a)
        temp2 = temp1
        temp1 = a
        
        
    print(mini,maxi)

else:
    print(-1)

Submission status: Wrong Answer

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

# 最後に2人以上残るような最小のNを探す
ok, ng = 0, 10 ** 18
while abs(ok - ng) > 1:
    n = (ok + ng) // 2
    x = n
    for a in A:
        x = (x // a) * a
    if x >= 2:
        ok = n
    else:
        ng = n
m = ok

# 最後に2人以下になるような最大のNを探す
ok, ng = 0, 10 ** 18
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    n = x
    for a in A:
        x = x // a * a

    if x <= 2:
        ok = n
    else:
        ng = n
M = ok


# 条件を満たすかチェック
mx, Mx = m, M
for a in A:
    mx = (mx // a) * a
    Mx = (Mx // a) * a

if mx == 2 and Mx == 2:
    print(m, M)
else:
    print(-1)

Submission status: Wrong Answer

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

# 最後に2人以上残るような最小のNを探す
ok, ng = 10, 0
while abs(ok - ng) > 1:
    n = (ok + ng) // 2
    x = n
    for a in A:
        x = (x // a) * a
    if x >= 2:
        ok = n
    else:
        ng = n
m = ok

# 最後に2人以下になるような最大のNを探す
ok, ng = 0, 10 ** 9
while abs(ok - ng) > 1:
    x = (ok + ng) // 2
    n = x
    for a in A:
        x = x // a * a

    if x <= 2:
        ok = n
    else:
        ng = n
M = ok


# 条件を満たすかチェック
mx, Mx = m, M
for a in A:
    mx = (mx // a) * a
    Mx = (Mx // a) * a

if mx == 2 and Mx == 2:
    print(m, M)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
K=int(input())

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

M=2
m=2
for i in range(1,K):
    if A[i]>=M*2:
        print(-1)
        exit()
    else:
        M=((A[i-1]*2-1)//A[i])*A[i]+A[i]-1
        if m==A[i]:
            pass
        else:
            m=(m//A[i]+1)*A[i]
    #print(m,M)
print(m,M)

Submission status: Wrong Answer

Solution code:
K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    a = A[i]
    if nowm <= ((nowm+a-1)//a)*a and ((nowm+a-1)//a)*a <= nowM:
        nowm = ((nowm+a-1)//a)*a
        nowM = (nowM//a)*a + a - 1
    else:
        ans = -1
        break
    print(nowm, nowM)
    # if nowM < A[i]:
    #     ans = -1
    #     break
    # elif nowm <= A[i]:
    #     nowm = A[i]
    #     nowM = A[i]*2 - 1
    # else:
    #     M = nowM
    #     nowm = (nowm//A[i]+1)*A[i]
    #     if nowm > M:
    #         ans = -1
    #         break
    #     if (nowM//A[i]+1)*A[i] <= M:
    #         nowM = (nowM//A[i]+1)*A[i] - 1
    #         if nowM < nowm:
    #             nowM = nowm + A[i] - 1
    #     else:
    #         nowM = nowm + A[i] - 1
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))

Submission status: Wrong Answer

Solution code:
K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    if nowM < A[i]:
        ans = -1
        break
    elif nowm <= A[i]:
        nowm = A[i]
        nowM = A[i]*2 - 1
    else:
        M = nowM
        nowm = (nowm//A[i]+1)*A[i]
        if nowm > M:
            ans = -1
            break
        if (nowM//A[i]+1)*A[i] <= M:
            nowM = (nowM//A[i]+1)*A[i] - 1
            if nowM < nowm:
                nowM = nowm + A[i] - 1
        else:
            nowM = nowm + A[i] - 1
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))

Submission status: Wrong Answer

Solution code:
K = int( input())
A = list( map( int, input().split()))
nowm = 2
nowM = 2
ans = 0
for i in range(K-1,-1,-1):
    if nowM < A[i]:
        ans = -1
        break
    elif nowm <= A[i]:
        nowm = A[i]
        nowM = A[i]*2 - 1
    else:
        M = nowM
        nowm = (nowm//A[i]+1)*A[i]
        if nowm > M:
            ans = -1
            break
        if (nowM//A[i])*A[i] <= M:
            nowM = (nowM//A[i]+1)*A[i] - 1
            if nowM < nowm:
                nowM = nowm + A[i] - 1
        else:
            nowM = nowm + A[i] - 1
if ans == -1:
    print( -1)
else:
    print("{} {}".format(nowm, nowM))