[JAVA] All Operation O(1) time complexity, using 2 DoublyLinkedList
\nclass FrontMiddleBackQueue {\n    class Node {\n        int val;\n        Node prev;\n        Node next;\n        \n        public Node() {}\n        public N
```\nclass FrontMiddleBackQueue {\n    class Node {\n        int val;\n        Node prev;\n        Node next;\n        \n        public Node() {}\n        public Node(int val) {\n            this.val = val;\n        }\n    }\n    \n    class DoublyLinkedList {\n        int size;\n        Node head;\n        Node tail;\n        \n        public DoublyLinkedList() {\n            this.size = 0;\n            this.head = new Node();\n            this.tail = new Node();\n            this.head.next = this.tail;\n            this.tail.prev = this.head;\n        }\n        \n        public void offerFirst(int val) {\n            this.size++;\n            Node node = new Node(val);\n            node.next = this.head.next;\n            this.head.next.prev = node;\n            this.head.next = node;\n            node.prev = this.head;\n        }\n        \n        public void offerLast(int val) {\n            this.size++;\n            Node node = new Node(val);\n            node.prev = this.tail.prev;\n            this.tail.prev.next = node;\n            node.next = this.tail;\n            this.tail.prev = node;\n        }\n        \n        public Node pollFirst() {\n            // if(size <= 0) return null;\n            this.size--;\n            Node node = this.head.next;\n            \n            this.head.next = node.next;\n            node.next.prev = this.head;\n            return node;\n        }\n        \n        public Node pollLast() {\n            // if(size <= 0) return null;\n            this.size--;\n            Node node = this.tail.prev;\n            this.tail.prev = node.prev;\n            this.tail.prev.next = this.tail;\n            return node;\n        }\n    }\n    \n    DoublyLinkedList left;\n    DoublyLinkedList right;\n\n    public FrontMiddleBackQueue() {\n        this.left = new DoublyLinkedList();\n        this.right = new DoublyLinkedList();\n    }\n    \n    public void pushFront(int val) {\n        left.offerFirst(val);\n        rebalance();\n    }\n    \n    public void pushMiddle(int val) {\n        if (left.size >= right.size + 1) {\n            Node node = left.pollLast();\n            right.offerFirst(node.val);\n        }\n        left.offerLast(val);\n    }\n    \n    public void pushBack(int val) {\n        right.offerLast(val);\n        rebalance();\n    }\n    \n    public int popFront() {\n        if (isEmpty()) return -1;\n        Node node = left.pollFirst();\n        rebalance();\n        return node.val;\n    }\n    \n    public int popMiddle() {\n        if (isEmpty()) return -1;\n        Node node = left.pollLast();\n        rebalance();\n        return node.val;\n    }\n    \n    public int popBack() {\n        if (isEmpty()) return -1;\n        Node node = null;\n        if (right.size != 0) {\n            node = right.pollLast();   \n        } else {\n            node = left.pollLast();\n        }\n        rebalance();\n        return node.val;\n    }\n    \n    private void rebalance() {\n        if (left.size > right.size + 1) {\n            Node node = left.pollLast();\n            right.offerFirst(node.val);\n        } else if (left.size < right.size) {\n            Node node = right.pollFirst();\n            left.offerLast(node.val);\n        }\n    }\n    \n    private boolean isEmpty() {\n        return left.size + right.size == 0;\n    }\n}\n\n ```
[]