There is a pizza with 3n slices of varying size, you and your friends will take slices of pizza as follows:

You will pick any pizza slice.
Your friend Alice will pick next slice in anti clockwise direction of your pick. 
Your friend Bob will pick next slice in clockwise direction of your pick.
Repeat until there are no more slices of pizzas.

Sizes of Pizza slices is represented by circular array slices in clockwise direction.
Return the maximum possible sum of slice sizes which you can have.
 
Example 1:

Input: slices = [1,2,3,4,5,6]
Output: 10
Explanation: Pick pizza slice of size 4, Alice and Bob will pick slices with size 3 and 5 respectively. Then Pick slices with size 6, finally Alice and Bob will pick slice of size 2 and 1 respectively. Total = 4 + 6.

Example 2:

Input: slices = [8,9,8,6,1,1]
Output: 16
Output: Pick pizza slice of size 8 in each turn. If you pick slice with size 9 your partners will pick slices of size 8.

Example 3:
Input: slices = [4,1,2,5,8,3,1,9,7]
Output: 21

Example 4:
Input: slices = [3,1,2]
Output: 3

 
Constraints:

1 <= slices.length <= 500
slices.length % 3 == 0
1 <= slices[i] <= 1000

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

def _disabled_input(*args, **kwargs):
    raise RuntimeError("input() is disabled in callable mode")
builtins.input = _disabled_input

ns = {"__name__": "__judge__"}  # prevent if __name__ == "__main__" blocks
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'from typing import List, Dict, Set, Optional\nfrom enum import Enum\nfrom functools import lru_cache\n\n\nclass Person(Enum):\n    ME = 0\n    ALICE = 1\n    BOB = 2\n\n\nclass DoublyLinkedListNode:\n    def __init__(self, val: int) -> None:\n        self.val = val\n        self.prev = None\n        self.next = None\n\n\nclass Solution:\n    def maxSizeSlices(self, slices: List[int]) -> int:\n        levels = len(slices) // 3 + 1\n        result = 0\n        for start, stop in ((0, len(slices) - 1), (1, len(slices))):\n            dp = [[0] * levels for _ in range(len(slices) + 2)]\n\n            for pizza_slice in reversed(list(range(start, stop))):\n                for level in range(levels):\n                    if pizza_slice + 2 < len(dp) and level < levels - 1:\n                        dp[pizza_slice][level] = max(\n                            dp[pizza_slice][level],\n                            dp[pizza_slice + 2][level + 1] + slices[pizza_slice],\n                        )\n\n                    dp[pizza_slice][level] = max(\n                        dp[pizza_slice][level],\n                        dp[pizza_slice + 1][level],\n                    )\n\n            result = max(result, dp[start][0])\n\n        return result\n\n\n    def maxSizeSlicesTopDown(self, slices: List[int]) -> int:\n        @lru_cache(None)\n        def dfs(pizza_slice: int, max_slice: int, level: int) -> int:\n            if level == len(slices) / 3:\n                return 0\n\n            if pizza_slice > max_slice:\n                return 0\n\n            return max(\n                dfs(pizza_slice + 2, max_slice, level + 1) + slices[pizza_slice],\n                dfs(pizza_slice + 1, max_slice, level),\n            )\n\n        return max(dfs(1, len(slices) - 1, 0), dfs(0, len(slices) - 2, 0))\n\n    def maxSizeSlicesBruteForce(self, slices: List[int]) -> int:\n        slices_nodes = [DoublyLinkedListNode(pos) for pos in range(len(slices))]\n\n        for pizza_slice_pos in range(len(slices)):\n            prev_pizza_slice_pos = (pizza_slice_pos - 1) % len(slices)\n            next_pizza_slice_pos = (pizza_slice_pos + 1) % len(slices)\n\n            pizza_slice = slices_nodes[pizza_slice_pos]\n            prev_pizza_slice = slices_nodes[prev_pizza_slice_pos]\n            next_pizza_slice = slices_nodes[next_pizza_slice_pos]\n\n            prev_pizza_slice.next = pizza_slice\n            pizza_slice.prev = prev_pizza_slice\n\n            pizza_slice.next = next_pizza_slice\n            next_pizza_slice.prev = pizza_slice\n\n        def dfs(pizza_slices_left: Set[int]) -> int:\n            result = 0\n            for pizza_slice_pos in list(pizza_slices_left):\n                pizza_slice = slices_nodes[pizza_slice_pos]\n\n                prev_pizza_slice = pizza_slice.prev\n                next_pizza_slice = pizza_slice.__next__\n\n                prev_prev_pizza_slice = prev_pizza_slice.prev\n                next_next_pizza_slice = next_pizza_slice.__next__\n\n                prev_prev_pizza_slice.next = next_next_pizza_slice\n                next_next_pizza_slice.prev = prev_prev_pizza_slice\n\n                pizza_slices_left.remove(pizza_slice.val)\n                pizza_slices_left.remove(prev_pizza_slice.val)\n                pizza_slices_left.remove(next_pizza_slice.val)\n\n                result = max(result, dfs(pizza_slices_left) + slices[pizza_slice.val])\n\n                pizza_slices_left.add(pizza_slice.val)\n                pizza_slices_left.add(prev_pizza_slice.val)\n                pizza_slices_left.add(next_pizza_slice.val)\n\n                prev_prev_pizza_slice.next = prev_pizza_slice\n                next_next_pizza_slice.prev = next_pizza_slice\n\n            return result\n\n        return dfs(set(range(len(slices))))\n\n\nclass TestSolution:\n    def setup(self) -> None:\n        self.sol = Solution()\n\n    def test_case1(self) -> None:\n        assert self.sol.maxSizeSlices([1,2,3,4,5,6]) == 10\n\n    def test_case2(self) -> None:\n        assert self.sol.maxSizeSlices([6,3,1,2,6,2,4,3,10,4,1,4,6,5,5,3,4,7,6,5,8,7,3,8,8,1,7,1,7,8]) == 10\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'maxSizeSlices'
if _fn_name:
    if "Solution" in ns:
        try:
            _obj = ns["Solution"]()
            if hasattr(_obj, _fn_name):
                _target = getattr(_obj, _fn_name)
        except Exception:
            _target = None
    if _target is None and _fn_name in ns and callable(ns[_fn_name]):
        _target = ns[_fn_name]
# Fallback: if there's exactly one user-defined function, use it
if _target is None:
    _cands = [v for k, v in ns.items() if callable(v) and getattr(v, "__module__", "") in ("__judge__", "__main__")]
    _user_funcs = [c for c in _cands if getattr(c, "__name__", "").startswith("_") is False]
    if len(_user_funcs) == 1:
        _target = _user_funcs[0]
if _target is None:
    raise RuntimeError(f"Could not resolve callable '{_fn_name}'")

_raw = sys.stdin.read().strip()
if _raw:
    _parsed = json.loads(_raw)
    if isinstance(_parsed, dict):
        _kwargs = _parsed.get("kwargs", {})
        _args = _parsed.get("args", [])
    else:
        _args, _kwargs = _parsed, {}
else:
    _args, _kwargs = [], {}
if not isinstance(_args, (list, tuple)):
    _args = [_args]
_res = _target(*_args, **_kwargs)
try:
    sys.stdout.write(repr(_res) + "\n")
except Exception:
    pass

```

Measured memory_bytes: 7674