class MovingAverage:
def __init__(self, size: int):
"""
Initialize your data structure here.
"""
self.size=size+1
self.front=0
self.rear=0
self.queue=[None for _ in range(size+1)]
self.sum=0
def next(self, val: int) -> float:
if (self.rear+1)%self.size==self.front:
self.front=(self.front+1)%self.size
self.sum-=self.queue[self.front]
self.rear=(self.rear+1)%self.size
self.queue[self.rear]=val
self.sum+=val
return 1.0*self.sum/(self.size-1)
else:
self.rear=self.rear+1
self.queue[self.rear]=val
self.sum+=val
return 1.0*self.sum/(self.rear-self.front)