Alex and Lee play a game with piles of stones.  There are an even number of piles arranged in a row, and each pile has a positive integer number of stones piles[i].
The objective of the game is to end with the most stones.  The total number of stones is odd, so there are no ties.
Alex and Lee take turns, with Alex starting first.  Each turn, a player takes the entire pile of stones from either the beginning or the end of the row.  This continues until there are no more piles left, at which point the person with the most stones wins.
Assuming Alex and Lee play optimally, return True if and only if Alex wins the game.
 
Example 1:
Input: piles = [5,3,4,5]
Output: true
Explanation: 
Alex starts first, and can only take the first 5 or the last 5.
Say he takes the first 5, so that the row becomes [3, 4, 5].
If Lee takes 3, then the board is [4, 5], and Alex takes 5 to win with 10 points.
If Lee takes the last 5, then the board is [3, 4], and Alex takes 4 to win with 9 points.
This demonstrated that taking the first 5 was a winning move for Alex, so we return true.

 
Constraints:

2 <= piles.length <= 500
piles.length is even.
1 <= piles[i] <= 500
sum(piles) is odd.

```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 = 'class Solution:\n    \n    def stoneGame(self, piles):\n        \n        n = len(piles)\n        memo = dict()\n        \n        def dp(i,j):\n            if i>j: return 0\n            if (i,j) in memo: return memo[(i,j)]\n            \n            ans = max(piles[i] - dp(i+1, j), piles[j] - dp(i, j-1))\n            memo[(i,j)] = ans\n            return ans\n        return dp(0, n-1) > 0\n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n    \n    def stoneGame1(self, piles):\n        # three methods, dp, memo+recursive\n        n = len(piles)\n        \n        memo = dict()\n        def dp(i,j):\n            if i>j: return 0\n            if (i,j) in memo: return memo[(i,j)]\n            \n            if (j-i+n) % 2 == 1: # player 1\n                ans = max(piles[i] + dp(i+1,j), piles[j] + dp(i,j-1))\n            else:\n                ans = min(-piles[i] + dp(i+1, j), -piles[j] + dp(i,j-1))\n            memo[(i,j)] = ans\n            return ans\n        return dp(0, n-1) > 0 # 相对分数\n    \n    def stoneGame2(self, piles):\n        n = len(piles)\n        dp = [[0]*n for _ in range(n)]\n        for i in range(n):\n            dp[i][i] = piles[i]\n        for alen in range(2, n+1):\n            for i in range(0, n-alen+1): # when i=n-alen, alen=n\n                j = i+alen-1 # j - i + 1 = alen, so j = i-1+alen\n                dp[i][j] = max(piles[i] - dp[i+1][j], piles[j] - dp[i][j-1])\n        return dp[0][n-1] > 0 # 相对分数\n    \n    def stoneGame3(self, piles): # 记忆化递归的方法！相对比较容易写出来\n        n = len(piles)\n        memo = dict()\n        def dp(i,j):\n            if i>j: return 0\n            if (i,j) in memo: return memo[(i,j)]\n            \n            ans = max(piles[i] - dp(i+1,j), piles[j] - dp(i, j-1)) # min-max过程\n            memo[(i,j)] = ans\n            return ans\n        return dp(0,n-1)>0 # 相对分数，也就是 score(alex) - score(lee)\n    \n    def stoneGame4(self, piles):\n        return True\n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n        \n    \n    def stoneGame3(self, piles):\n        n = len(piles)\n        # dp[i] = max(your stones - op_stones) for piles[i] to piles[i+alen-1] i+alen-1-i+1 = alen = length of piles\n        dp = [0] * n\n        for alen in range(2, n+1):\n            for i in range(0, n-alen+1):\n                dp[i] = max(piles[i] - dp[i+1], piles[i+alen-1] - dp[i]) # 问题，二维转一维的技巧是什么？\n        return dp[0] > 0\n    \n    \n    def stoneGame2(self, piles):\n        # dp[i][j] = max(yourscore - op_stones) for piles[i] ~ piles[j]\n        n = len(piles)\n        dp = [[0] * n for _ in range(n)]\n        for i in range(n):\n            dp[i][i] = piles[i]\n        \n        for alen in range(2, n+1): #长度为从2到n，构造\n            for i in range(0, n-alen+1): # i这个子问题的范围\n                j = i + alen - 1\n                dp[i][j] = max(piles[i] - dp[i+1][j], piles[j] - dp[i][j-1])\n                # j = i + alen - 1 代入\n                # dp[i][j] = max(piles[i] - dp[i+1][j], piles[i+alen-1] - dp[i][j-1])\n                # 然后直接把j去掉:\n                # dp[i] = max(piles[i] - dp[i+1], piles[i+alen-1] - dp[i]) 就是1D的写法。。。\n        return dp[0][n-1] > 0\n        \n    \n    def stoneGame1(self, piles: List[int]) -> bool:\n        # minmax + dp 或者记忆化递归\n        # 你和对手都是选择“最佳”的option来选择\n        \n        # 第一种解法：minmax\n        # def score(s, l, r)\n        #    if l>r: return 0\n        #    return max(s[l] - score(s, l+1, r), # left\n        #               s[r] - score(s, l, r-1)) # right\n        #    对手的最大值，自己的最小值下的 最大值\n        #    return score(s, 0, n-1) > 0\n        # time: O(2^n), space O(n)\n        \n        # 第二种解法：minmax + memorization / DP\n        # dp[i][j] = best relative score of subarray s[i] ~ s[j]\n        # time O(n^2), space (O^2) -> O(n)\n        \n        # solution 1, recursive, 不记忆中间结果，无法达到最优解！O(2^n) 记忆化递归，容易java的stack爆掉。。。\n        dp = dict()\n        def score(piles, l, r):\n            # left, right\n            if (l,r) in dp:\n                return dp[(l,r)]\n            if l == r:\n                dp[(l,r)] = piles[l] # 只剩下一堆的话，就取它了，没有其他可以选择的了！\n                return piles[l]\n            res = max(piles[l] - score(piles, l+1, r), piles[r] - score(piles, l, r-1))\n            # 我，当前有两种选择，拿l或者拿r，如果拿l，则得分为piles[l]，失分为对手从l+1,r的区间能得到的最大值（对手的最大值，就是我的最小值）\n            # 如果拿r，则得分为piles[r]，失分为对手从l, r-1的区间能得到的最大值（对手的最大值，就是我的最小值）\n            # 所以这个过程就是经典的minmax过程\n            dp[(l,r)] = res\n            return res\n        \n        res = score(piles, 0, len(piles)-1) \n        return True if res > 0 else False'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

_target = None
_fn_name = 'stoneGame'
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: 7256