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:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=1):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def dfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def bfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.size
        v[x]=root_v
        while q:
            c=q.popleft()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def parent(self,x):
        return self.dfs(0,func=lambda pr,prv,nx,dist:pr,root_v=-1)
 
    def topological_sort(self,x):  # return topological sort of the tree
        tps=[]
        q=deque([x])
        v=[None]*self.size
        v[x]=0
        while q:
            c=q.popleft()
            tps.append(c)
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=0
        return tps
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        #self.st=SegTree(self.size*2-1,self.ETdepth,function=min,ide=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
    def __str__(self):
        return  str(self.edges)
 
    def show(self):
        if all([all([d==1 for nd,d in edge]) for edge in self.edges]):
            print( [[nd for nd,d in edge] for edge in self.edges] )
        else:
            print(self)
 
class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    # return boundary index of r such that func({table[i]} =< x , i in [pos,r]
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    # return boundary index of l such that func({table[i]} =< x , i in [l,pos]
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos
 
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)


show_flg=False
show_flg=True
ans=0


n=I()
a=LI()
'''
    x=a*m+r
    x>>a*m
    a3*m3+r3>>a3*m3=a2*m2+r2>>a2*m2=a1*m1+r1>>a1*m1=2
    a1>r1>=0
'''
def max_n(l):
    x=l
    M=m=l
    for j,i in zip(a[::-1],a[1::-1]):
        m=(m//i)*i
        m=m+i-1

        show(M,m)
        
        ck=m
        for i in a:
            ck=(ck//i)*i
        if ck!=l:
            x=-1
    return x

def min_n():
    r=l=2
    for i in a[::-1]:
        y=l%i
        if y==0:
            z=0
        else:
            z=i-y
        l=l+z
        r=l+i-1
        m=l
        M=(r//i)*i
#        show((l,r),(m,M))
    ck=l
    rt=m,M+i-1
    for i in a:
        ck=(ck//i)*i
    if ck!=2:
        rt=-1,
    return rt

ans=min_n()
show(*ans)
#x=a*m+y

Submission status: Wrong Answer

Solution code:
import sys,bisect,string,math,time,functools,random,fractions
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
from itertools import permutations,combinations,groupby
rep=range
def Golf():n,*t=map(int,open(0).read().split())
def I():return int(input())
def S_():return input()
def IS():return input().split()
def LS():return [i for i in input().split()]
def MI():return map(int,input().split())
def LI():return [int(i) for i in input().split()]
def LI_():return [int(i)-1 for i in input().split()]
def NI(n):return [int(input()) for i in range(n)]
def NI_(n):return [int(input())-1 for i in range(n)]
def StoLI():return [ord(i)-97 for i in input()]
def ItoS(n):return chr(n+97)
def LtoS(ls):return ''.join([chr(i+97) for i in ls])
def RA():return map(int,open(0).read().split())
def GI(V,E,ls=None,Directed=False,index=1):
    org_inp=[];g=[[] for i in range(V)]
    FromStdin=True if ls==None else False
    for i in range(E):
        if FromStdin:
            inp=LI()
            org_inp.append(inp)
        else:
            inp=ls[i]
        if len(inp)==2:
            a,b=inp;c=1
        else:
            a,b,c=inp
        if index==1:a-=1;b-=1
        aa=(a,c);bb=(b,c);g[a].append(bb)
        if not Directed:g[b].append(aa)
    return g,org_inp
def GGI(h,w,search=None,replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1):
    #h,w,g,sg=GGI(h,w,search=['S','G'],replacement_of_found='.',mp_def={'#':1,'.':0},boundary=1) # sample usage
    mp=[boundary]*(w+2);found={}
    for i in range(h):
        s=input()
        for char in search:
            if char in s:
                found[char]=((i+1)*(w+2)+s.index(char)+1)
                mp_def[char]=mp_def[replacement_of_found]
        mp+=[boundary]+[mp_def[j] for j in s]+[boundary]
    mp+=[boundary]*(w+2)
    return h+2,w+2,mp,found
def TI(n):return GI(n,n-1)
def accum(ls):
    rt=[0]
    for i in ls:rt+=[rt[-1]+i]
    return rt
def bit_combination(n,base=2):
    rt=[]
    for tb in range(base**n):s=[tb//(base**bt)%base for bt in range(n)];rt+=[s]
    return rt
def gcd(x,y):
    if y==0:return x
    if x%y==0:return y
    while x%y!=0:x,y=y,x%y
    return y
def YN(x):print(['NO','YES'][x])
def Yn(x):print(['No','Yes'][x])
def show(*inp,end='\n'):
    if show_flg:print(*inp,end=end)

mo=10**9+7
inf=float('inf')
FourNb=[(-1,0),(1,0),(0,1),(0,-1)];EightNb=[(-1,0),(1,0),(0,1),(0,-1),(1,1),(-1,-1),(1,-1),(-1,1)];compas=dict(zip('WENS',FourNb));cursol=dict(zip('LRUD',FourNb))
l_alp=string.ascii_lowercase
#sys.setrecursionlimit(10**7)
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
input=lambda: sys.stdin.readline().rstrip()

class Tree:
    def __init__(self,inp_size=None,ls=None,init=True,index=1):
        self.LCA_init_stat=False
        self.ETtable=[]
        if init:
            if ls==None:
                self.stdin(inp_size,index=index)
            else:
                self.size=len(ls)+1
                self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def stdin(self,inp_size=None,index=1):
        if inp_size==None:
            self.size=int(input())
        else:
            self.size=inp_size
        self.edges,_=GI(self.size,self.size-1,index=index)
        return
    
    def listin(self,ls,index=0):
        self.size=len(ls)+1
        self.edges,_=GI(self.size,self.size-1,ls,index=index)
        return
 
    def dfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.size
        v[x]=root_v
        while q:
            c=q.pop()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def bfs(self,x,func=lambda pr,prv,nx,dist:prv+dist,root_v=0):
        q=deque([x])
        v=[None]*self.size
        v[x]=root_v
        while q:
            c=q.popleft()
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=func(c,v[c],nb,d)
        return v
 
    def parent(self,x):
        return self.dfs(0,func=lambda pr,prv,nx,dist:pr,root_v=-1)
 
    def topological_sort(self,x):  # return topological sort of the tree
        tps=[]
        q=deque([x])
        v=[None]*self.size
        v[x]=0
        while q:
            c=q.popleft()
            tps.append(c)
            for nb,d in self.edges[c]:
                if v[nb]==None:
                    q.append(nb)
                    v[nb]=0
        return tps
 
    def EulerTour(self,x):
        q=deque()
        q.append(x)
        self.depth=[None]*self.size
        self.depth[x]=0
        self.ETtable=[]
        self.ETdepth=[]
        self.ETin=[-1]*self.size
        self.ETout=[-1]*self.size
        cnt=0
        while q:
            c=q.pop()
            if c<0:
                ce=~c
            else:
                ce=c
                for nb,d in self.edges[ce]:
                    if self.depth[nb]==None:
                        q.append(~ce)
                        q.append(nb)
                        self.depth[nb]=self.depth[ce]+1
            self.ETtable.append(ce)
            self.ETdepth.append(self.depth[ce])
            if self.ETin[ce]==-1:
                self.ETin[ce]=cnt
            else:
                self.ETout[ce]=cnt
            cnt+=1
        return
    
    def LCA_init(self,root):
        self.EulerTour(root)
        self.st=SparseTable(self.ETdepth,init_func=min,init_idl=inf)
        #self.st=SegTree(self.size*2-1,self.ETdepth,function=min,ide=inf)
        self.LCA_init_stat=True
        return
    
    def LCA(self,root,x,y):
        if self.LCA_init_stat==False:
            self.LCA_init(root)
        xin,xout=self.ETin[x],self.ETout[x]
        yin,yout=self.ETin[y],self.ETout[y]
        a=min(xin,yin)
        b=max(xout,yout,xin,yin)
        id_of_min_dep_in_et=self.st.query_id(a,b+1)
        return self.ETtable[id_of_min_dep_in_et]
 
    def __str__(self):
        return  str(self.edges)
 
    def show(self):
        if all([all([d==1 for nd,d in edge]) for edge in self.edges]):
            print( [[nd for nd,d in edge] for edge in self.edges] )
        else:
            print(self)
 
class SparseTable: # O(N log N) for init, O(1) for query(l,r)
    def __init__(self,ls,init_func=min,init_idl=float('inf')):
        self.func=init_func
        self.idl=init_idl
        self.size=len(ls)
        self.N0=self.size.bit_length()
        self.table=[ls[:]]
        self.index=[list(range(self.size))]
        self.lg=[0]*(self.size+1)
        
        for i in range(2,self.size+1):
            self.lg[i]=self.lg[i>>1]+1
 
        for i in range(self.N0):
            tmp=[self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) for j in range(self.size)]
            tmp_id=[self.index[i][j] if self.table[i][j]==self.func(self.table[i][j],self.table[i][min(j+(1<<i),self.size-1)]) else self.index[i][min(j+(1<<i),self.size-1)] for j in range(self.size)]
            self.table+=[tmp]
            self.index+=[tmp_id]
    
    # return func of [l,r)
    def query(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        return self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))])
    
    # return index of which val[i] = func of v among [l,r)
    def query_id(self,l,r):
        if r>self.size:r=self.size
        #N=(r-l).bit_length()-1
        N=self.lg[r-l]
        a,b=self.index[N][l],self.index[N][max(0,r-(1<<N))]
        if self.table[0][a]==self.func(self.table[N][l],self.table[N][max(0,r-(1<<N))]):
            b=a
        return b
    
    # return boundary index of r such that func({table[i]} =< x , i in [pos,r]
    def right_bound(self,pos,x):
        k=(self.size-pos).bit_length()
        for j in range(k)[::-1]:
            nx=pos+(1<<j)
            if nx<n and self.query(pos,nx+1)<=x:
                pos+=(1<<j)
        return pos
    
    # return boundary index of l such that func({table[i]} =< x , i in [l,pos]
    def left_bound(self,pos,x):
        k=pos.bit_length()
        for j in range(k)[::-1]:
            nx=pos-(1<<j)
            if 0<=nx and self.query(nx,pos+1)<=x:
                pos-=(1<<j)
        return pos
 
    def __str__(self):
        return str(self.table[0])
 
    def print(self):
        for i in self.table:
            print(*i)


show_flg=False
show_flg=True
ans=0


n=I()
a=LI()
'''
    x=a*m+r
    x>>a*m
    a3*m3+r3>>a3*m3=a2*m2+r2>>a2*m2=a1*m1+r1>>a1*m1=2
    a1>r1>=0
'''
def max_n(l):
    x=l
    M=m=l
    for j,i in zip(a[::-1],a[1::-1]):
        m=(m//i)*i
        m=m+i-1

        show(M,m)
        
        ck=m
        for i in a:
            ck=(ck//i)*i
        if ck!=l:
            x=-1
    return x

def min_n(l):
    x=l
    for i in a[::-1]:
        y=x%i
        if y==0:
            z=0
        else:
            z=i-y
        x=x+z
#        show(x)
    ck=x
    for i in a:
        ck=(ck//i)*i
    if ck!=l:
        x=-1
    return x

m=min_n(2)
M=m+a[0]-1
if m==-1:
    ans=[-1]
else:
    ans=m,M
show(*ans)
#x=a*m+y

Submission status: Wrong Answer

Solution code:
#AGC020-B Ice Rink Game
"""
逆操作を考える。
何人組を作るということは、modにおける最大値と最小値を求め続けるということ。
そのような組が作れないような場合(全員が脱落するような場合)は、-1を出力。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

k = int(readline())
lst1 = list(map(int,readline().split()))
lst1.reverse()
if lst1[0] != 2:
    print(-1)
    exit()


def min_lot(value,unit):
    if value%unit == 0:
        return value//unit
    else:
        return value//unit + 1
mn = 2
mx = 3
for i in range(1,k):
    if not mn <= lst1[i] <= mx:
        print(-1)
        exit()
    res = min_lot(mn,lst1[i])
    mn = res*lst1[i]

    lim = (mx//lst1[i] + 1)*lst1[i] - 1
    mx = lim



print(mn,mx)

Submission status: Wrong Answer

Solution code:
#AGC020-B Ice Rink Game
"""
逆操作を考える。
何人組を作るということは、modにおける最大値と最小値を求め続けるということ。
そのような組が作れないような場合(全員が脱落するような場合)は、-1を出力。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

k = int(readline())
lst1 = list(map(int,readline().split()))
lst1.reverse()
if lst1[0] != 2:
    print(-1)
    exit()


def min_lot(value,unit):
    if value%unit == 0:
        return value//unit
    else:
        return value//unit + 1
mn = 2
mx = 3
for i in range(1,k):
    if lst1[i] > mx*2:
        print(-1)
        exit()
    if lst1[i] >= mn*2:
        mn = lst1[i]
    res = min_lot(mn,lst1[i])
    mn = res*lst1[i]

    lim = (mx//lst1[i] + 1)*lst1[i] - 1
    mx = lim



print(mn,mx)

Submission status: Wrong Answer

Solution code:
#AGC020-B Ice Rink Game
"""
逆操作を考える。
何人組を作るということは、modにおける最大値と最小値を求め続けるということ。
そのような組が作れないような場合(全員が脱落するような場合)は、-1を出力。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

k = int(readline())
lst1 = list(map(int,readline().split()))
lst1.reverse()
if lst1[0] != 2:
    print(-1)
    exit()


def min_lot(value,unit):
    if value%unit == 0:
        return value//unit
    else:
        return value//unit + 1
mn = 2
mx = 3
for i in range(1,k):
    if lst1[i] >= mx*2:
        print(-1)
        exit()

    res = min_lot(mn,lst1[i])
    mn = max(lst1[i],res*lst1[i])

    lim = (mx//lst1[i] + 1)*lst1[i] - 1
    mx = lim



print(mn,mx)

Submission status: Wrong Answer

Solution code:
#AGC020-B Ice Rink Game
"""
逆操作を考える。
何人組を作るということは、modにおける最大値と最小値を求め続けるということ。
そのような組が作れないような場合(全員が脱落するような場合)は、-1を出力。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

k = int(readline())
lst1 = list(map(int,readline().split()))
lst1.reverse()
if lst1[0] != 2:
    print(-1)
    exit()


def min_lot(value,unit):
    if value%unit == 0:
        return value//unit
    else:
        return value//unit + 1
mn = 2
mx = 3
for i in range(1,k):
    if lst1[i] >= mn*2:
        print(-1)
        exit()

    res = min_lot(mn,lst1[i])
    mn = res*lst1[i]

    lim = (mx//lst1[i] + 1)*lst1[i] - 1
    mx = lim



print(mn,mx)

Submission status: Wrong Answer

Solution code:
#AGC020-B Ice Rink Game
"""
逆操作を考える。
何人組を作るということは、modにおける最大値と最小値を求め続けるということ。
そのような組が作れないような場合(全員が脱落するような場合)は、-1を出力。
"""
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

k = int(readline())
lst1 = list(map(int,readline().split()))
lst1.reverse()
if lst1[0] != 2:
    print(-1)
    exit()


def min_lot(value,unit):
    if value%unit == 0:
        return value//unit
    else:
        return value//unit + 1

mn = 2
mx = 2
for i in range(1,k):
    if lst1[i] >= mn*2:
        print(-1)
        exit()

    res = min_lot(mn,lst1[i])
    mn = res*lst1[i]

    res = min_lot(mn,lst1[i])
    mx = (res+1)*lst1[i] -1



print(mn,mx)

Submission status: Wrong Answer

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

m = [0]*K
M = [0]*K
m[K-1] = 2
M[K-1] = 3

for i in range(K-2, -1, -1):
    if (M[i+1]//S[i])*S[i] < m[i+1]:
        print(-1)
        break
    if m[i+1]%S[i] == 0:
        m[i] = m[i+1]
    else:
        m[i] = m[i+1]+S[i]-(m[i+1]%S[i])
    if M[i+1]%S[i] == 0:
        M[i] = M[i+1]+S[i]-1
    else:
        M[i] = (M[i+1]//S[i])*S[i]+S[i]-1
else:
    print(m[0], M[0])

Submission status: Wrong Answer

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

m = [0]*K
M = [0]*K
m[K-1] = 2
M[K-1] = 3

for i in range(K-2, -1, -1):
    if (M[i+1]//S[i])*S[i] < m[i+1]:
        print(-1)
        break
    if m[i+1]%S[i] == 0:
        m[i] = m[i+1]
    else:
        m[i] = m[i+1]+S[i]-m[i+1]%S[i]
    if M[i+1]%S[i] == 0:
        M[i] = M[i+1]+S[i]-1
    else:
        M[i] = (M[i+1]//S[i])*S[i]+S[i]-1
else:
    print(m[0], M[0])

Submission status: Wrong Answer

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

m = [0]*K
M = [0]*K
m[K-1] = 2
M[K-1] = 3

for i in range(K-2, -1, -1):
    if m[i+1]%S[i] == 0:
        m[i] = m[i+1]
    else:
        m[i] = m[i+1]+S[i]-m[i+1]%S[i]
    if M[i+1]%S[i] == 0:
        M[i] = M[i+1]+S[i]-1
    else:
        M[i] = (M[i+1]//S[i])*S[i]+S[i]-1
    if m[i] > M[i]:
        print(-1)
        break
else:
    print(m[0], M[0])

Submission status: Wrong Answer

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

m = [0]*K
M = [0]*K
m[K-1] = 2
M[K-1] = 3

for i in range(K-2, -1, -1):
    if m[i+1]%S[i] == 0:
        m[i] = m[i+1]
    else:
        m[i] = m[i+1]+S[i]-m[i+1]%S[i]
    if M[i+1]%S[i] == 0:
        M[i] = M[i+1]+S[i]-1
    else:
        M[i] = M[i+1]-M[i+1]%S[i]+S[i]-1
    if m[i] > M[i]:
        print(-1)
        break
else:
    print(m[0], M[0])

Submission status: Wrong Answer

Solution code:
import sys
import math

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

    # ラウンドiにおける通過者を保存
    m = 2
    M = 2
    for i in range(K - 1, -1, -1):
        n = (m + A[i] - 1) // A[i]
        tmp_m = n * A[i]
        tmp_M = (M / A[i]) * A[i] + A[i] - 1
        if tmp_m > M or tmp_M < m:
            print(-1)
            return
        m = tmp_m
        M = tmp_M

    print(m, M)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

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

    # ラウンドiにおける通過者を保存
    m = 2
    M = 2
    for i in range(K - 2, -1, -1):
        n = (m + A[i] - 1) // A[i]
        tmp_m = n * A[i]
        tmp_M = (n + 1) * A[i] - 1
        if tmp_m > M or tmp_M < m:
            print(-1)
            return
        m = tmp_m
        M = tmp_M

    print(m, M)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


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

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

    # ラウンドiにおける通過者を保存
    m = 2
    M = 2
    for i in range(K - 2, -1, -1):
        if A[i] > m:
            if A[i] // m > 1:
                print(-1)
                return
            else:
                m = A[i]
                M = A[i]
        else:
            n = (m + A[i] - 1) // A[i]
            m = n * A[i]
            M = (n + 1) * A[i] - 1

    print(m, M)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    K = int(input())
    A = list(map(int, input().split()))
    min_ch = 2
    max_ch = 3
    if A[-1] != 2:
        print(-1)
        return
    for i in range(K):
        n = K - i - 1
        if max_ch < A[n]:
            print(-1)
            return
        a = math.ceil(min_ch / A[n])
        b = math.floor(max_ch / A[n])
        min_ch = A[n] * a
        max_ch = A[n] * (b + 1) - 1
    print(min_ch, max_ch)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    K = int(input())
    A = list(map(int, input().split()))
    min_ch = 2
    max_ch = 3
    if A[-1] != 2:
        print(-1)
        return
    for i in range(K):
        n = K - i - 1
        if max_ch < A[n]:
            print(-1)
            return
        a = math.ceil(min_ch / A[n])

        min_ch = A[n] * a
        max_ch = A[n] * (a + 1) - 1
    print(min_ch, max_ch)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

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 main():
    K = I()
    a = LI()[::-1]
    st = 2
    fail = False

    for i in range(K-1):
        if st % a[i] != 0:
            fail = True
            break
        if st % a[i+1] == 0:
            continue
        else:
            prev_st = st
            st = (a[i+1] - st % a[i+1]) + st
            if prev_st <= st <= prev_st + (a[i] - 1):
                continue
            else:
                fail = True
                break
    if fail:
        print(-1)
        return
    m = st

    st = 2
    for i in range(K-1):
        if st % a[i] != 0:
            fail = True
            break

        if (st + a[i] - 1) % a[i+1] == 0:
            st = st + a[i] - 1
        else:
            prev_st = st
            st = (st + a[i] - 1) - (st + a[i] - 1) % a[i+1]
            if prev_st <= st <= prev_st + (a[i] - 1):
                continue
            else:
                fail = True
                break

    M = st
    M += (a[-1] - 1)
    print(m, M)

main()