[Python] fast with explanation
There is some ideas:\n- First: using deque because their methods: pop(), popleft(), append(), appendleft() has the O(1) complexity.\n- Second: using two deques 
There is some ideas:\n- First: using `deque` because their methods: `pop(), popleft(), append(), appendleft()` has the O(1) complexity.\n- Second: using two deques and maintain this condition: `len(self.first_part) == len(self.second_part)` or `len(self.first_part) - 1 == len(self.second_part)`. Then we easily could get O(1) for all operation.\n\n```\nfrom collections import deque\n\n\nclass FrontMiddleBackQueue:\n\n    def __init__(self):\n        self.first_part = deque()\n        self.second_part = deque()\n\n    def pushFront(self, val: int) -> None:\n        if len(self.second_part) < len(self.first_part):\n            self.second_part.appendleft(self.first_part.pop())\n        self.first_part.appendleft(val)\n\n    def pushMiddle(self, val: int) -> None:\n        if len(self.first_part) > len(self.second_part):\n            self.second_part.appendleft(self.first_part.pop())\n        self.first_part.append(val)\n\n    def pushBack(self, val: int) -> None:\n        if self.first_part:\n            if len(self.first_part) == len(self.second_part):\n                self.first_part.append(self.second_part.popleft())\n            self.second_part.append(val)\n        else:\n            self.first_part.append(val)\n\n    def popFront(self) -> int:\n        if self.first_part:\n            if len(self.first_part) == len(self.second_part):\n                self.first_part.append(self.second_part.popleft())\n            return self.first_part.popleft()\n        return -1\n\n    def popMiddle(self) -> int:\n        if self.first_part:\n            res = self.first_part.pop()\n            if len(self.first_part) < len(self.second_part):\n                self.first_part.append(self.second_part.popleft())\n            return res\n        return -1\n\n    def popBack(self) -> int:\n        if self.second_part:\n            if len(self.second_part) < len(self.first_part):\n                self.second_part.appendleft(self.first_part.pop())\n            return self.second_part.pop()\n        return self.first_part.pop() if self.first_part else -1\n \n```
['Python', 'Python3']