Clean | optimized | concise java solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: O(1)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass FrontMiddleBackQueue {\n    List<Integer> firstHalf;\n    List<Integer> secondHalf;\n    public FrontMiddleBackQueue() {\n        firstHalf = new LinkedList<>();\n        secondHalf = new LinkedList<>();\n    }\n    void rearange() {\n        if(secondHalf.size() - firstHalf.size() > 0) {\n            firstHalf.addLast(secondHalf.removeFirst());\n        } else if(firstHalf.size() - secondHalf.size() > 1) {\n            secondHalf.addFirst(firstHalf.removeLast());\n        }\n    }\n\n    public void pushFront(int val) {\n        firstHalf.addFirst(val);\n        rearange();\n    }\n    \n    public void pushMiddle(int val) {\n        if(firstHalf.size() > secondHalf.size()) {\n            secondHalf.addFirst(firstHalf.removeLast());\n        }\n        firstHalf.addLast(val);\n        rearange();\n    }\n    \n    public void pushBack(int val) {\n        secondHalf.addLast(val);\n        rearange();\n    }\n    \n    public int popBack() {\n        int ans = -1;\n        if(secondHalf.size() != 0) {\n            ans = secondHalf.removeLast();\n        } else if(firstHalf.size() != 0) {\n            ans = firstHalf.removeLast();\n        }\n        rearange();\n        return ans;\n    }\n    \n    public int popMiddle() {\n        if(firstHalf.size() == 0) return -1;\n        \n        int ans = firstHalf.removeLast();\n        rearange();\n        return ans;\n    }\n    \n    public int popFront() {\n        if(firstHalf.size() == 0) return -1;\n        \n        int ans = firstHalf.removeFirst();\n        rearange();\n        return ans;\n    }\n}\n\n/**\n * Your FrontMiddleBackQueue object will be instantiated and called as such:\n * FrontMiddleBackQueue obj = new FrontMiddleBackQueue();\n * obj.pushFront(val);\n * obj.pushMiddle(val);\n * obj.pushBack(val);\n * int param_4 = obj.popFront();\n * int param_5 = obj.popMiddle();\n * int param_6 = obj.popBack();\n */\n```
['Java']