def solve(self, cipher):
        """
        Algorithm: dp
        Current score is affect by the 3 moves and the previous corresponding scores
        Starting from the bottom of the stack (rather than top as the gaming sequence)
        A: f[i][0]
        B: f[i][1]

        index starting from 0:

        f[i][0] = max(sum(w[i-k+1, i]) + sum(w[1..i-k]) - f[i-k][1]) w.r.t k
        f[i][1] = max(sum(w[i-k+1, i]) + sum(w[1..i-k]) - f[i-k][0]) w.r.t k

        for f[i][1], i>=1
        :param cipher: the cipher
        """
        N, v = cipher
        v.reverse()  # start from the bottom
        # sum dp
        s = [0 for _ in xrange(N + 1)]
        for i in xrange(1, N + 1):
            s[i] = s[i - 1] + v[i - 1]

        f = [[0, 0] for _ in xrange(N + 1)]
        for i in xrange(1, N + 1):
            # f[i][0]
            local_max = 0
            for k in xrange(1, 4):
                if i - k >= 0:
                    local_max = max(local_max, s[i] - s[i - k] + s[i - k] - f[k - i][1])
            f[i][0] = local_max

            # if i==1: continue  # starting from the bottom
            # f[i][1]
            local_max = 0
            for k in xrange(1, 4):
                if i - k >= 0:
                    local_max = max(local_max, s[i] - s[i - k] + s[i - k] - f[i - k][0])
            f[i][1] = local_max

        return f[-1][0]
dataset/ETHPy150Open algorhythms/HackerRankAlgorithms/Play Game.py/Solution.solve/swapped operands of `-`