def get_cumulative_rewards(rewards, gamma=0.99):
    """
  rewards: rewards at each step
  gamma: discount for reward
  """
    discounted_rewards = []

    for rew in range(len(rewards)):
        Gt = 0
        pw = 0
        for r in rewards[rew:]:
            Gt = Gt + gamma ** pw * r
            pw = pw + 1
        discounted_rewards.append(Gt)

    return discounted_rewards