Python simple solution, Doubly linked list, all operation O(1) time
\nclass ListNode():\n    def __init__(self,val=0,next=None,prev=None):\n        self.val = val\n        self.next = next\n        self.prev = prev\n\nclass Fron
```\nclass ListNode():\n    def __init__(self,val=0,next=None,prev=None):\n        self.val = val\n        self.next = next\n        self.prev = prev\n\nclass FrontMiddleBackQueue:\n\n    def __init__(self):\n        self.head = None\n        self.mid = None\n        self.end = None\n        self.size = 0\n\n    def pushFront(self, val: int) -> None:\n        newNode = ListNode(val, self.head)\n        if self.size==0:\n            self.head = self.mid = self.end = newNode\n        elif self.size==1:\n            self.head = self.mid = newNode\n            newNode.next = self.end\n            self.end.prev = newNode\n        elif self.size==2:\n            self.head = newNode\n            self.head.next = self.mid\n            self.mid.prev = newNode\n        elif self.size%2==1:\n            newNode.next = self.head\n            self.head.prev = newNode\n            self.head = newNode\n            self.mid = self.mid.prev\n        else:\n            newNode.next = self.head\n            self.head.prev = newNode\n            self.head = newNode\n        self.size += 1\n        #print(\'pushfront\',self.head.val if self.head else None,self.mid.val if self.mid else None,self.end.val if self.end else None,self.size)\n\n    def pushMiddle(self, val: int) -> None:\n        newNode = ListNode(val)\n        if self.size==0:\n            self.head = self.mid = self.end = newNode\n        elif self.size==1:\n            self.head = self.mid = newNode\n            self.head.next = self.end\n            self.end.prev = self.head\n        elif self.size==2:\n            self.mid = newNode\n            self.mid.next = self.end\n            self.mid.prev = self.head\n            self.head.next = self.mid\n            self.end.prev = self.mid\n        elif self.size%2==1:\n            prev = self.mid.prev\n            next = self.mid\n            self.mid = newNode\n            self.mid.next = next\n            self.mid.prev = prev\n            prev.next = self.mid\n            next.prev = self.mid\n        else:\n            p = self.mid\n            n = self.mid.next\n            self.mid = newNode\n            self.mid.next = n\n            self.mid.prev = p\n            p.next = self.mid\n            n.prev = self.mid\n        self.size += 1\n        #print(\'pushmiddle\',self.head.val if self.head else None,self.mid.val if self.mid else None,self.end.val if self.end else None,self.size)\n\n    def pushBack(self, val: int) -> None:\n        newNode = ListNode(val)\n        if self.size==0:\n            self.head = self.mid = self.end = newNode\n        elif self.size==1:\n            self.end = newNode\n            self.end.prev = self.head\n            self.head.next = self.end\n        elif self.size==2:\n            self.end = newNode\n            self.mid = self.head.next\n            self.mid.next = self.end\n            self.end.prev = self.mid\n        elif self.size%2==1:\n            self.end.next = newNode\n            newNode.prev = self.end\n            self.end = newNode\n        else:\n            self.end.next = newNode\n            newNode.prev = self.end\n            self.end = newNode\n            self.mid = self.mid.next\n        self.size += 1\n        #print(\'pushback\',self.head.val if self.head else None,self.mid.val if self.mid else None,self.end.val if self.end else None,self.size)\n\n    def popFront(self) -> int:\n        if self.size==0:\n            return -1\n        ret = self.head.val\n        if self.size==1:\n            self.head = self.mid = self.end = None\n        elif self.size==2:\n            self.head = self.mid = self.end\n            self.head.prev = None\n        elif self.size%2==1:\n            self.head = self.head.next\n            self.head.prev = None\n        else:\n            self.head = self.head.next\n            self.head.prev = None\n            self.mid = self.mid.next\n        self.size -=1\n        #print(\'popfront\',self.head.val if self.head else None,self.mid.val if self.mid else None,self.end.val if self.end else None,self.size)\n        return ret\n\n    def popMiddle(self) -> int:\n        if self.size==0:\n            return -1\n        ret = self.mid.val\n        if self.size==1:\n            self.head = self.mid = self.end = None\n        elif self.size==2:\n            self.head = self.mid = self.end\n            self.head.prev = None\n        elif self.size%2==1:\n            n = self.mid.next\n            self.mid = self.mid.prev\n            self.mid.next = n\n            n.prev = self.mid\n        else:\n            p = self.mid.prev\n            n = self.mid.next\n            p.next = n\n            n.prev = p\n            self.mid = n\n        self.size-=1\n        #print(\'popmiddle\',self.head.val if self.head else None,self.mid.val if self.mid else None,self.end.val if self.end else None,self.size)\n        return ret\n\n    def popBack(self) -> int:\n        if self.size==0:\n            return -1\n        ret = self.end.val\n        if self.size==1:\n            self.head = self.mid = self.end = None\n        elif self.size==2:\n            self.end = self.head\n            self.head.next = None\n        elif self.size%2==1:\n            self.mid = self.mid.prev\n            self.end = self.end.prev\n            self.end.next = None\n        else:\n            self.end = self.end.prev\n            self.end.next = None\n        self.size -= 1\n        #print(\'popback\',self.head.val if self.head else None,self.mid.val if self.mid else None,self.end.val if self.end else None,self.size)\n        return ret\n\n# Your FrontMiddleBackQueue object will be instantiated and called as such:\n# obj = FrontMiddleBackQueue()\n# obj.pushFront(val)\n# obj.pushMiddle(val)\n# obj.pushBack(val)\n# param_4 = obj.popFront()\n# param_5 = obj.popMiddle()\n# param_6 = obj.popBack()\n```
['Doubly-Linked List', 'Python', 'Python3']