'''

def mf(s,t):

for i in range(len(s)):

if s[i]<t[i]:return False

return True

```
sl=sorted(special,key=lambda x:x[-1], reverse=True)
ans=sum(map(lambda x,y:x*y,price,needs))
n=len(needs)
for i in range(len(sl)):
r=0
ds=needs[::]
for s in sl[i:]:
while mf(ds,s):
r+=s[-1]
for i in range(n):ds[i]-=s[i]
for i in range(n):r+=ds[i]*price[i]
ans=min(r,ans)
return ans
```

'''