add 10 oil add 20 coal add oil get coal get oil add coal get coal Kv N

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
'''
7
add 10 oil
add 20 coal
add 5 oil
get coal
get oil
add 1 coal
get coal
'''
Kv=[]
Nv=[]
N=int(input())
for i in range(N):
oper=list(input().split())
if oper[0]=='get':
l=0
for i in range(len(Nv)):
if Nv[i]==oper[1]: l+=Kv[i]
print(l)
elif oper[0]=='add':
Kv.append(int(oper[1]))
Nv.append(oper[2])
else:
k=int(oper[1])
while k>0:
if k < Kv[-1]:
Kv[-1]-=k
k=0
else:
k-=Kv[-1]
Kv.pop(-1)
Nv.pop(-1)