#include <bits/stdc++.h>
using namespace std;
using Pi = pair < int , int >;

int main()
{
	int n;

	while ( cin >> n, n ) {
		int times[55][2][255];
		Pi dat[55];
		int t[55], c[55];

		for ( int i = 0; i < n; i++ ) {
			cin >> dat[i].first >> dat[i].second; dat[i].second++;
		}
		sort(dat, dat + n);
		for ( int i = 0; i < n; i++ ) {
			t[i] = dat[i].first;
			c[i] = dat[i].second;
		}

		for ( int i = n - 1; i >= 0; i-- ) {
			int sum = 0;
			times[i][0][0] = 0;
			times[i][1][0] = 0;
			for ( int j = 1; j < c[i]; j++ ) {
				for ( int k = 0; k < 2; k++ ) {
					int save = sum;
					sum += t[i];
					for ( int l = i + 1; l < n; l++ ) {
						int pos = upper_bound(times[l][k], times[l][k]+c[l], sum) - times[l][k];
						int prevpos = pos;
						if ( pos == c[l] ) continue;
						if ( k == 0 ) prevpos--;
						if ( times[l][1-k][prevpos] < save ) sum = max(sum, times[l][k][pos] );
					}
					times[i][k][j] = sum;
				}
			}
		}
		int maxv = 0;
		for ( int i = 0; i < n; i++ ) {
			maxv = max(maxv, times[i][1][c[i] - 1]);
		}

		cout << maxv << endl;
	}

	return ( 0 );
}


