#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define SIZE 200000
using namespace std;
typedef pair<int,int> P;

int n;
P x[50];
int dp[2][SIZE];

void solve(){
	rep(i,2) rep(j,SIZE) dp[i][j] = 0;
	rep(i,n) cin >> x[i].first >> x[i].second;
	rep(i,n) x[i].second *= 2;
	sort(x,x+n,greater<P>());
	int ans = 0;
	rep(i,n){
		int dir = 0;
		int ti = 0;
		while(x[i].second){
			int tmpti = ti;
			if(ti == 0) ti = ti+x[i].first;
			else ti = max(ti+x[i].first,dp[dir][ti-1]);
			dp[dir][tmpti] = max(dp[dir][tmpti],ti);
			dir = dir^1;
			x[i].second--;
		}
		rep(j,2) for(int k = 1; k < SIZE; k++) dp[j][k] = max(dp[j][k],dp[j][k-1]);
	}
	rep(i,2) rep(j,SIZE) ans = max(ans,dp[i][j]);
	cout << ans << endl;
}

int main(){
	while(cin >> n){
		if(n == 0) break;
		solve();
	}
}