public int helper(int[][]dp, int[]vals, int i, int j) {
        if (j >= vals.length)
            return 0;
        if (i > j)
            return 0;
        if (dp[i][j] > 0)
            return dp[i][j];
        int w = (i + 1) <= j ?  vals[i + 1] : 0;
        dp[i][j] = Math.max(vals[i] + Math.min(helper(dp, vals, i + 2, j), helper(dp, vals, i + 3, j)),
            vals[i] + w + Math.min(helper(dp, vals, i + 3, j), helper(dp, vals, i + 4, j)));
        return dp[i][j];
    }