def discount_with_dones(rewards, dones, gamma):
    discounted = []
    r = 0
    for (reward, done) in zip(rewards[::(- 1)], dones[::(- 1)]):
        r = (reward + ((gamma * r) * (1.0 - done)))
        discounted.append(r)
    return discounted[::(- 1)]
def discount_with_dones(rewards, dones, gamma):
    discounted = []
    r = 0
    for (reward, done) in zip(rewards[::(- 1)], dones[::(- 1)]):
        r = (reward + ((gamma * r) * (1.0 - done)))
        discounted.append(r)
    return discounted[::(- 1)]