import math n=input() s=map(int,raw_input().split()) c,m,ans=1,10**12,[] size=-1 start,end=0,0 gl=0 g=0 final = 1 kop=0 for i in range(n-1): if s[i] > s[i+1]: if size == -1: ans.append(i+1) start=i+1 else: if size != 1: ans.append(i+1-start) start=i+1 ans.append(n-start) sub=0 # print ans for i in range(1,ans[0]+1): size=i final = 1 for j in range(len(ans)): if j == 0: sub = 1 else: sub = 0 if ans[j] == size and j == 0: continue else: final*=math.factorial(size)**(ans[j]/size - sub) if ans[j]%size != 0: final*=math.factorial(size)/(math.factorial(ans[j] % size)) # print 'hi',math.factorial(size)**(ans[j]/size) if ans[j] % size != 0: size = ans[j] % size # print 'F',final kop+=final print kop%(10**9 + 7)