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 python3
# coding=utf-8

import math
import sys

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

Submission status: Wrong Answer

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

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

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

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

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

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

Submission status: Wrong Answer

Solution code:
K = int(input())
A = list(map(lambda x:int(x), input().split(" ")))
A.reverse()

n = [2]

for a in A:
    tmp = []
    nn = list(filter(lambda x:x%a==0, n))

    if len(nn)==0:
        print("-1")
        exit()

    for i in range(min(nn),min(nn)+a):
        tmp.append(i)
    for i in range(max(nn),max(nn)+a):
        tmp.append(i)

    n = list(set(tmp))

if len(n)>0:
    print(min(n),max(n))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
N = int(input())
ops = list(input().split())
P = []
p = 0
x = 1
for s in range(N-1, -1, -1):
    P.append(int(ops[s]))
ans = int(ops[N-1])
for i in range(N-1):
    if P[i] > P[i+1]:
        p = P[i] % P[i+1]
        ans += p
    elif (P[i] * 2) > P[i+1]:
        p = (P[i] * 2) % P[i+1]
        ans += p
    else:
        ans = -1
        break
ans2 = ans + P[N-1] -1
if ans != -1:
    print(str(ans) + " " +str(ans2))
else:
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
#!/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
print(a)
n = 2
for i in a:
    if math.ceil(n / i) * i >= 2 * n:
        flag = False
        break
    n = math.ceil(n / i) * i
if flag:
    print("{} {}".format(n, n + a[-1] - 1))
else:
    print("-1")

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
from math import floor, ceil
round_no = int(input())
args = list(map(int, input().split(' ')))[::-1]
cand_min = args[0]
for i in range(len(args)-1):
    if args[i] >= 2 + 2 ** i:
        cand_min = -1
        break

    if args[i] <= args[i+1]:
        cand_min = args[i+1]
    else:
        cand_min = ceil(cand_min/args[i+1]) * args[i+1]

if cand_min != -1:
    cand_max = cand_min + args[-1] - 1
    print(cand_min, cand_max)
else:
    print(cand_min)

Submission status: Wrong Answer

Solution code:
import re
import math
input()
a = input().split(" ")
a.reverse()
for i in range(len(a)):
    a[i] = int(a[i])
imin = 2
muri = 0
for i in range(len(a)-1):
    # now = a[i]
    inext = a[i+1]
    if inext >= imin *2:
        muri = 1
        break
    bairitu = imin / inext
    if bairitu < 1:
        imin = inext
    else:
        imin = inext*math.ceil(bairitu)
if muri == 1:
    print("-1")
else:
    imax = 2
    for i in range(len(a)-1):
        now = a[i]
        inext = a[i+1]
        if inext >= imax *2:
            muri = 1
            break
        bairitu = imax / now
        maxrate = ((bairitu + 1) * now)/inext
        maxrate_int = float(math.floor(maxrate))
        # print("inext:",inext,"imax:",imax,maxrate,maxrate_int)
        diff = maxrate - maxrate_int
        if(diff == 0):
            imax = int((maxrate_int-1) * inext)
        else:
            imax = int(maxrate_int * inext)
    # print(imin,imax)
    last = a[len(a)-1]
    last_bairitsu = imax / last
    imax = int(last * (last_bairitsu + 1) - 1)
    print(imin,imax)

Submission status: Wrong Answer

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

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

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


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

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

print(main())

Submission status: Wrong Answer

Solution code:
k = int(input())
a = list(map(int, input().split()))[::-1]
c = 2
for i in range(1, k):
    m = a[i]
    j = 2
    while m < c:
        m *= j
        j += 1

    if c <= m and m <= a[i]*(c//a[i]+1):
        c = m
    else:
        print('-1')
        exit()

print(c, c+a[k-1]-1)

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)
            if nmin > nmax:
                print(-1)
                return
        else:
            nmin = Ai
        if Ai < nmax:
            nmax = Ai * (nmax // Ai + 1) - 1
        else:
            nmax = Ai * 2 - 1
        # print(Ai, nmin, nmax)
        if nmin > nmax:
            print(-1)
            return
    print(nmin, nmax)


main()

Submission status: Wrong Answer

Solution code:
import copy
def ketanowa(p):
    ans=0
    p=str(p)
    for i in p:
        ans+=int(i)
    return ans

def main():
    n=int(input())
    temp=input().split(" ")
    nums=list(map(int,temp))
    nums_o=copy.copy(nums)
    nums.reverse()
    for i in range(len(nums)-1):
        if nums[i]>nums[i+1]:
            p=int(nums[i]/nums[i+1])
            nums[i+1]*=(p+1)
    nums.reverse()
    imp =True
    min=nums[0]
    max=nums[0]+nums_o[0]-1

    test=min
    for i in range(len(nums)):
        test-=test%nums_o[i]
        if test<=0:
            imp=True
            break
    if test!=2:
        imp=True
    test=max
    for i in range(len(nums)):
        test-=test%nums_o[i]
        if test<=0:
            imp=True
            break
    if test!=2:
        imp=True


    if imp:
        print("-1")
    else:
        print(str(min)+" "+str(max))        




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

Submission status: Wrong Answer

Solution code:
import sys

moji1 = input()
moji2 = input()

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

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

print(str(x) + " " + str(mx))

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 < c:
        m *= j
        j += 1

    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:
import copy
def ketanowa(p):
    ans=0
    p=str(p)
    for i in p:
        ans+=int(i)
    return ans

def main():
    n=int(input())
    temp=input().split(" ")
    nums=list(map(int,temp))
    nums_o=copy.copy(nums)
    nums.reverse()
    for i in range(len(nums)-1):
        if nums[i]>nums[i+1]:
            p=int(nums[i]/nums[i+1])
            nums[i+1]*=(p+1)
    nums.reverse()
    imp =False
    min=nums[0]
    max=nums[0]+nums_o[0]-1

    test=min
    for i in range(len(nums)):
        test-=test%nums_o[i]
        if test<=0:
            imp=True
            break
    if test!=2:
        imp=True
    test=max
    for i in range(len(nums)):
        test-=test%nums_o[i]
        if test<=0:
            imp=True
            break
    if test!=2:
        imp=True


    if imp:
        print("-1")
    else:
        print(str(min)+" "+str(max))        




if __name__ == '__main__':
    main()

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(Ai, nmin, nmax)
        if nmin > nmax:
            print(-1)
            return
    print(nmin, nmax)


main()

Submission status: Wrong Answer

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

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

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


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

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

print(main())

Submission status: Wrong Answer

Solution code:
# -- coding: utf-8 --
from math import floor, ceil
round_no = int(input())
args = list(map(int, input().split(' ')))[::-1]
cand_min = args[0]
for i in range(round_no-1):
    if args[i] >= 2 + 2^i:
        cand_min = -1
        break

    if args[i] <= args[i+1]:
        cand_min = args[i+1]
    else:
        cand_min = ceil(cand_min/args[i+1]) * args[i+1]

if cand_min != -1:
    cand_max = cand_min + args[-1] - 1
    print(cand_min, cand_max)
else:
    print(cand_min)

Submission status: Wrong Answer

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

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

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


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

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

print(main())

Submission status: Wrong Answer

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

ans=[2]
superflag=1
for i in range(k-1,-1,-1):
    flag=1
    for num in ans:
        if num%a[i]==0: tmp=num; flag=0; break
    if flag: superflag=0; print(-1); break
    ans=list(range(tmp,tmp+a[i]))

if superflag: print(ans[0],ans[len(ans)-1])

Submission status: Wrong Answer

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

def solve():

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

    can = []

    for i in range(k):

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

        oldcan = can[:]
        can = []

        for c in oldcan:
            for a__ in range(c,c+a[k-i-1]):
                if i == k-1:
                    if a__ not in can:
                        can.append(a__)
                else:
                    if a__ not in can and a__ % a[k-(i+1)-1] == 0:
                        can.append(a__)
        #print(i, can, oldcan)
        if len(can) == 0:
            print(-1)
            return

    print(min(can), max(can))
solve()

Submission status: Wrong Answer

Solution code:
import sys

K = int(raw_input())
A = [int(val) for val in raw_input().split(" ")]

MIN, MAX = 2, 2
for k in range(1, K)[::-1]:
    if MIN%A[k-1]==0:
        pass
    else:
        MIN = (MIN/A[k-1]+1)*A[k-1]
    MAX_ = MAX + A[k] - 1
    if MAX_%A[k-1]==0:
        MAX = MAX_
    else:
        MAX = (MAX_/A[k-1])*A[k-1]
    if MIN > MAX:
        print "-1"
        sys.exit()
MAX = MAX + A[0] - 1

print "%d %d"%(MIN, MAX)

Submission status: Wrong Answer

Solution code:
k=int(input())
a=[int(i) for i in input().split()]
count=0
#number=max(a)

ans_min=100000000000000
ans_max=0

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


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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

temp = a[-1]
for i in reversed(range(l-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:
  print(ans, ans+a[0]-1)
else:
  print(-1)

Submission status: Wrong Answer

Solution code:
import sys

K = int(raw_input())
A = [int(val) for val in raw_input().split(" ")]

if A[-1]!=2:
    print "-1"

MIN, MAX = 2, 2
for k in range(1, K)[::-1]:
    if MIN%A[k-1]==0:
        pass
    else:
        MIN = (MIN/A[k-1]+1)*A[k-1]
    MAX_ = MAX + A[k] - 1
    if MAX_%A[k-1]==0:
        MAX = MAX_
    else:
        MAX = (MAX_/A[k-1])*A[k-1]
    if MIN > MAX:
        print "-1"
        sys.exit()
MAX = MAX + A[0] - 1

print "%d %d"%(MIN, MAX)

Submission status: Wrong Answer

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

N = []

imin = min(A)
imax = b
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, temp = int(input()), input().split()
A = []
b = 0
for a in temp:
    A.append(int(a))
    b = b + int(a)

N = []

imin = min(A)
imax = b
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:
import numpy as np
import math

def is_prime(num):
    if(num < 2):
        return 1
    if(num == 2 or num == 3 or num == 5):
        return num
    if(num % 2 == 0):
        return 2
    if(num % 3 == 0):
        return 3
    if(num % 5 == 0):
        return 5

    # 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    num_sqrt = math.sqrt(num)
    while prime <= num_sqrt:
        if num % prime == 0:
            return prime
        prime += step
        step = 6 - step

    return num

n = int(input())
a = list(map(int, input().split(" ")))

b = []
for i in a:
    b.append(is_prime(i))

b = sorted(b)

num_min = b[0]
k = b[0]
for i in b:
    if(i != k):
        num_min *= i
        k = i

num_max = num_min + b[-1] - 1

if(num_min < max(a)):
    print(-1)
else:
    print("%d %d" %(num_min, num_max))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
round_num = int(input())
group_list = list(map(int, input().split()))
count_min = group_list[round_num-1]
count_max = group_list[round_num-1] * 2 - 1
frag = True

for i in range(round_num - 1, -1, -1):
    # min
    if group_list[i] > count_min * 2:
        frag = False
        break
    elif group_list[i] >= count_min:
        count_min = group_list[i]
    else:
        count_min = group_list[i] * (count_min // group_list[i] + 1)
    #max
    if group_list[i] >= count_max:
        count_max = group_list[i] * 2 - 1
    else:
        count_max = group_list[i] * (count_max // group_list[i] + 1) - 1
    
if frag == True:
    print(count_min, end = " ")
    print(count_max)
else:
    print(-1)

Submission status: Wrong Answer

Solution code:
import math

k = int(input())
a = list(map(int,input().split(' ')))

kouho = []
for i in range(k+1+1):
    kouho.append(set())
# kouhoは、ラウンドiに臨んだ人の数
kouho[k+1].add(2)

# ラウンドi-1に参加した人数の候補は、
# kouho[i] +0,+1,,,,+ラウンドiのa -1。
# かつ、ラウンドi-2のa で割り切れること。
for i in range(k,1-1,-1):
    #各ラウンドへの参加候補数を上げる。
    for x in kouho[i+1]:
        for j in range(a[i-1]):
            kouho[i].add(x+j)
            if i > 1 and (x+j)%a[i-2] != 0 :
                kouho[i].remove(x+j)

if len(kouho[1]) > 0:
    maxk = max(kouho[1])
    mink = min(kouho[1])
    print(mink, maxk)
else:
    print(-1)

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

Solution code:
import math

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

old_a = 2
x = 2
for a in reversed(A[:-1]):
  if a > (old_a * (x +1)):
    x = -1
    break
  x = math.ceil(a/x)
  old_a = a

if x == -1:
  print(-1)
else:
  print(old_a * x, (old_a * (x + 1)) - 1)

Submission status: Wrong Answer

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


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

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

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

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

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

Submission status: Wrong Answer

Solution code:
import copy
def ketanowa(p):
    ans=0
    p=str(p)
    for i in p:
        ans+=int(i)
    return ans

def main():
    n=int(input())
    temp=input().split(" ")
    nums=list(map(int,temp))
    nums_o=copy.copy(nums)
    nums.reverse()
    for i in range(len(nums)-1):
        if nums[i]>nums[i+1]:
            j=0
            while True:
                j=j+1
                if nums[i]<nums[i+1]*j:
                    nums[i+1]=nums[i+1]*j
                    break
    nums.reverse()
    imp =False
    min=nums[0]
    max=nums[0]+nums_o[0]-1
    # test=min
    # for i in range(len(nums)):
    #     test-=test%nums_o[i]
    #     if test<0:
    #         imp=True
    #         break
    # if test!=2:
    #     imp=True
    # test=max
    # for i in range(len(nums)):
    #     test-=test%nums_o[i]
    #     if test<0:
    #         imp=True
    #         break
    # if test!=2:
    #     imp=True


    if imp:
        print("-1")
    else:
        print(str(min)+" "+str(max))        




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

ma, mi = ans[-1], ans[-2]
for i in a:
    ma -= ma % i
    mi -= mi % i
if not (ma == mi == 2):
    print(-1)
else:
    print(ans[-2], ans[-1])

Submission status: Wrong Answer

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

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:
			k = math.ceil(curr / A[i])
			curr = k * A[i]
res = 0
if curr != -1:
	res = curr
	for i in range(0, K):
		if curr % A[i] != 0:
			curr -= (curr % A[i])

if curr != 2:
	print(-1)
else:
	print(res, res + A[0] - 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
    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
        c = c * 2 - 1
        c -= c%t

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

print(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) + 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:
def main():
    K = int(input())
    A = list(map(int, input().split()))

    A.reverse()
    max = 2
    min = 2
    for i in range(1,len(A)):
        max = get_max(max, A[i])
        min = get_min(min, A[i])
        if max == -1:
            print(-1)
            return
    max = max + A[len(A)-1] - 1
    print (str(min) + " " + str(max))


# num... 次回ゲームで残った最大の人数, pre...前回ゲームのX人組のX
def get_max(num, pre):
    i = 1
    max = -1
    while(True):
        if pre*i > num*2-1:
            return max
        else:
            max = pre*i
            i+=1

def get_min(num, pre):
    i = 1
    while(True):
        if pre*i >= num:
            return pre*i
        else:
            i+=1

"""
最大は常に次回残った人数の倍-1
までの範囲で計算される前回残った数の倍数

最少は残った数より大きい範囲
の前回残った数の倍数
"""

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import copy
def ketanowa(p):
    ans=0
    p=str(p)
    for i in p:
        ans+=int(i)
    return ans

def main():
    n=int(input())
    temp=input().split(" ")
    nums=list(map(int,temp))
    nums_o=copy.copy(nums)
    nums.reverse()
    for i in range(len(nums)-1):
        if nums[i]>nums[i+1]:
            j=0
            while True:
                j=j+1
                if nums[i]<nums[i+1]*j:
                    nums[i+1]=nums[i+1]*j
                    break
    nums.reverse()
    imp =False
    min=nums[0]
    max=nums[0]+nums_o[0]-1
    test=min
    for i in range(len(nums)):
        test-=test%nums_o[i]
        if test<0:
            imp=True
            break
    if test!=2:
        imp=True
    test=max
    for i in range(len(nums)):
        test-=test%nums_o[i]
        if test<0:
            imp=True
            break
    if test!=2:
        imp=True


    if imp:
        print("-1")
    else:
        print(str(min)+" "+str(max))        




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print((s,b) if sn==2 else "-1")

Submission status: Wrong Answer

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

if A[-1] != 2:
    result = -1
else:
    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)