//Uva11400
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxc=1001;
int voltage[maxc]; //1 - 13200 所需电压
int vcost[maxc]; //1 - 1000 这种电压的价格
int lcost[maxc]; //1 - 10 这种灯泡的价格
int lnum[maxc]; //1 - 100 这种灯泡所需个数
int dp[maxc];
int order[maxc];
void greedy();
bool com(int a,int b)
{
if(voltage[a]>voltage[b]) //电压高的放前面
{
return true;
}
return false;
}
int n;
int main()
{
// int n;
while(scanf("%d",&n)==1 && n)
{
memset(order,0,sizeof(order));
for(int i=1;i<=n;i++)
{
scanf("%d %d %d %d",&voltage[i],&vcost[i],&lcost[i],&lnum[i]);
order[i]=i;
//for check
// printf("第%d个物品电压:%d\n",i,voltage[i]);
}
sort(order+1,order+n+1,com); //间接排序
//check
/*
cout<<"排序后的顺序是:(按电压从大到小)"<<endl;
for(int i=1;i<=n;i++)
cout<<order[i]<<"\t";
cout<<endl;
*/
greedy();
}
return 0;
}
void greedy()
{
memset(dp,0,sizeof(dp));
dp[order[1]]=lcost[order[1]]*lnum[order[1]]+vcost[order[1]];
int sum=dp[order[1]];
for(int i=2;i<=n;i++)
{
//check
// cout<<"第"<<i-1<<"(实际上是第"<<order[i-1]<<")个物品的代价:"<<dp[order[i-1]]<<endl;
int &o=order[i];
dp[o]=lcost[o]*lnum[o]+vcost[o];
int &ans=dp[o];
for(int j=i-1;j>0;j--)
{
int &oj=order[j];
if(lnum[oj])
{
int temp=lnum[o]*lcost[oj];
if( temp< ans )
{
ans=temp;
lnum[o]=0;
//check
// cout<<"\t第"<<i<<"个物品转给了第"<<j<<"(实际上是第"<<order[j]<<")个物品"<<endl;
}
}
}
sum+=ans;
}
// cout<<"**************************"<<"总代价为:"<<sum<<endl;
cout<<sum<<endl;
}