#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1010;
int dp[maxn];
int v;
void zeroonepack(int val,int cost) {
for(int i=v;i>=cost;i--)
if(dp[i-cost]+val>dp[i])
dp[i]=dp[i-cost]+val;
}
void completepack(int val,int cost) {
for(int i=cost;i<=v;i++)
dp[i]=max(dp[i],dp[i-cost]+val);
}
void multipack(int val,int cost,int num) {
if(num*cost>=v) completepack(val,cost);
else {
int k=1;
while(k<num) {
zeroonepack(k*val,k*cost);
num-=k;k+=k;
}
zeroonepack(num*val,num*cost);
}
}