#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef struct dota{
double HP;
double AD;
double percent;
}dota;
bool cmp(dota p1,dota p2){
if(p1.percent==p2.percent)
return p1.HP<p2.HP;
return p1.percent>p2.percent;
}
int main() {
int n;
while (scanf("%d",&n)!=EOF) {
dota a[20];
int sum=0;
for (int i=0; i<n; i++) {
scanf("%lf %lf",&a[i].AD,&a[i].HP);
a[i].percent=a[i].AD/a[i].HP;
}
sort(a, a+n, cmp);
int i=0;
while (a[n-1].HP!=0) {
if(a[i].HP==0)
i++;
for(int j=i;j<n;j++)
sum=sum+a[j].AD;
a[i].HP--;
}
printf("%d\n",sum);
}
return 0;
}