#include <bits/stdc++.h>
const int INF = 100000000;
const double EPS = 1e-10;
const int MOD = 1000000007;
using namespace std;
int n;
pair<int, int> x[50];
int dp[2][100000];
void solve() {
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 100000; j++) dp[i][j] = 0;
  for (int i = 0; i < n; i++) cin >> x[i].first >> x[i].second;
  for (int i = 0; i < n; i++) x[i].second *= 2;
  sort(x, x + n, greater<pair<int, int> >());
  int ans = 0;
  for (int i = 0; i < n; i++) {
    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--;
    }
    for (int j = 0; j < 2; j++)
      for (int k = 1; k < 100000; k++) dp[j][k] = max(dp[j][k], dp[j][k - 1]);
  }
  for (int i = 0; i < 2; i++)
    for (int j = 0; j < 100000; j++) ans = max(ans, dp[i][j]);
  cout << ans << endl;
}
int main() {
  while (cin >> n) {
    if (n == 0) break;
    solve();
  }
}
