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