Clean Python 3, O(1) time for each method
Use two deques and then only need to manipulate the tail of first deque when we working on middle.\nTime: O(1) for each method\n\nimport collections\nclass Fron
Use two deques and then only need to manipulate the tail of first deque when we working on middle.\nTime: `O(1)` for each method\n```\nimport collections\nclass FrontMiddleBackQueue:\n\n    def __init__(self):\n        self.first = collections.deque()\n        self.second = collections.deque()\n\n    def pushFront(self, val: int) -> None:\n        self.first.appendleft(val)\n        if len(self.first) > len(self.second) + 1:\n            self.second.appendleft(self.first.pop())\n\n    def pushMiddle(self, val: int) -> None:\n        if len(self.first) > len(self.second):\n            self.second.appendleft(self.first.pop())\n        self.first.append(val)\n\n    def pushBack(self, val: int) -> None:\n        self.second.append(val)\n        if len(self.first) < len(self.second):\n            self.first.append(self.second.popleft())\n\n    def popFront(self) -> int:\n        if not self.first and not self.second: return -1\n        result = self.first.popleft()\n        if len(self.first) < len(self.second):\n            self.first.append(self.second.popleft())\n        return result\n\n    def popMiddle(self) -> int:\n        if not self.first and not self.second: return -1\n        result = self.first.pop()\n        if len(self.first) < len(self.second):\n            self.first.append(self.second.popleft())\n        return result\n\n    def popBack(self) -> int:\n        if not self.first and not self.second: return -1\n        if not self.second: return self.first.pop()\n        result = self.second.pop()\n        if len(self.first) > len(self.second) + 1:\n            self.second.appendleft(self.first.pop())\n        return result\n```
[]