def state_reward(state, action):
    """State transitions on action

    :param state: previous state
    :type state: tuple
    :param action: action
    :type action: tuple
    :return: new state and reward
    :rtype: tuple
    """
    x, y = state
    dx, dy = action
    # A -> A'
    if (x, y) == (0, 1):
        return (4, 1), 10
    # B -> B'
    if (x, y) == (0, 3):
        return (2, 3), 5

    # new state
    x1, y1 = x + dx, y + dy

    # out of bounds
    if x1 in (-1, 5) or y1 in (-1, 5):
        return (x, y), -1
    # normal case: inside grid, not A or B state
    else:
        return (x1, y1), 0