from collections import deque mod=10**9+7 th=10**9 class MyQue: """ value:10**9未満判定、pop時のvalue_pyrの計算に使用 value_pyr:積の積の計算に使用。 """ def __init__(self): self.q=deque() self.value=1 self.value_pyr=1 self.length=0 def push(self,x): self.value*=x self.q.append(x) #assert self.value=mod:self.value_pyr%=mod def pop(self): #assert self.length>0,(self.value,q,self.length) self.value_pyr*=pow(self.value,mod-2,mod) if self.value_pyr>=mod:self.value_pyr%=mod x=self.q.popleft() self.value//=x #assert self.value=th: q.pop() q.push(a[i]) ans*=q.value_pyr if ans>=mod:ans%=mod return ans def main1(n,a): ans=1 for i in range(n): for j in range(i,n): x=1 for k in range(i,j+1): x*=a[k] if x