Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- s = list()
- rev = dict()
- for i in range(n):
- inp = list(input().split())
- if inp[0] == 'add':
- cars = int(inp[1])
- good = inp[2]
- s.append((cars, good))
- if good in rev.keys():
- rev[good] += cars
- else:
- rev[good] = cars
- elif inp[0] == 'delete':
- cars = int(inp[1])
- while cars != 0:
- curr_cars, curr_good = s[len(s) - 1]
- if curr_cars <= cars:
- s.pop()
- cars -= curr_cars
- rev[curr_good] -= curr_cars
- else:
- s.pop()
- rev[curr_good] -= cars
- s.append((curr_cars - cars, curr_good))
- cars = 0
- else:
- good = inp[1]
- if good in rev.keys():
- print(rev[good])
- else:
- print(0)
Add Comment
Please, Sign In to add comment