#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int N;
P p[50];

int H[55][333][2];

int calc(int i,int f,int t,int c,int *F){
  int tot = t + p[i].first;
  if( c == 0 ) return tot;
  for(int j=i+1;j<N;j++){
    if( c - F[j] - 1 < 0 ) continue;
    if( H[j][c-F[j]-1][f] > tot )
      tot = H[j][c-F[j]-1][f];    
  }
  for(int j=i+1;j<N;j++){
    if( c-F[j]-1<0 ) continue;
    if( H[j][c-F[j]-1][f] == tot ) F[j]++;
  }
  return tot;
}

int main(){
  while( cin >> N && N ){
    for(int i=0;i<N;i++){
      cin >> p[i].first >> p[i].second;
    }
    memset(H,0,sizeof(H));
    int res = 0;
    sort(p,p+N);
    for(int i=N-1;i>-1;i--){
      int t = 0, F[55] = {};
      for(int c=0; c < p[i].second; c++ ){
	t = calc(i,0,t,c,F);
	H[i][c][0] = t;
	t = calc(i,1,t,c,F);
	H[i][c][1] = t;
	res = max( res, t );
      }
    }
    cout << res << endl;
  }
}