Python, balance two deques
The idea is to use two deques: front and back. We make sure the front is the same size as back or longer by 1, this allows us to pop from front when we need to 
The idea is to use two deques: `front` and `back`. We make sure the `front` is the same size as `back` or longer by 1, this allows us to pop from `front` when we need to pop from the middle. We enforce the constraint after every operation, taking `O(1)` time for each:\n```\nclass FrontMiddleBackQueue:\n\n    def __init__(self):\n        self.front = deque()\n        self.back = deque()\n\n    def _correct_size(self):\n        while len(self.back) > len(self.front):\n            self.front.append(self.back.popleft())\n        \n        while len(self.front) > len(self.back) + 1:\n            self.back.appendleft(self.front.pop())\n        \n    def pushFront(self, val: int) -> None:\n        self.front.appendleft(val)\n        self._correct_size()\n\n    def pushMiddle(self, val: int) -> None:\n        if len(self.front) > len(self.back):\n            self.back.appendleft(self.front.pop())\n        self.front.append(val)\n        self._correct_size()\n\n    def pushBack(self, val: int) -> None:\n        self.back.append(val)\n        self._correct_size()\n\n    def popFront(self) -> int:\n        front = self.front if self.front else self.back\n        ret = front.popleft() if front else -1\n        self._correct_size()\n        return ret\n\n    def popMiddle(self) -> int:\n        ret = self.front.pop() if self.front else -1\n        self._correct_size()\n        return ret\n\n    def popBack(self) -> int:\n        back = self.back if self.back else self.front\n        ret = back.pop() if back else -1\n        self._correct_size()\n        return ret\n```
['Queue', 'Python', 'Python3']