#include<iostream>
#include<vector>
#include<deque>
#include<algorithm>
#include<cassert>

using namespace std;

#define int long long

const int INF = (int)1e9;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int xx = 0;
  
  while(true){
    vector<deque<pair<pair<int,int>,pair<int,int>>>> lanes(2);
    vector<pair<int,int>> a;
    int con  = 0;
    int n;
    
    cin>>n;

    if(!n) break;

    for(int i = 0; i < n; i++){
      int t, c;

      cin>>t>>c;

      c *=2;
      
      a.push_back(make_pair(t,c));
    }

     sort(a.begin(), a.end(), greater<pair<int,int>>());
     // sort(a.begin(), a.end());

  
    for(int i = 0; i < a.size(); i++){
      lanes[0].push_back(make_pair(a[i], make_pair(0,a[i].first)));
    }

    while(lanes[0].size() || lanes[1].size()){ //cout<<con<<" "<<lanes[0].size()<<" "<<lanes[1].size()<<endl;
      vector<vector<pair<int,int>>> temp(2);
      int hoge = INF;
      for(int k = 0; k < 2; k++){
        for(int i = 0; i < lanes[k].size(); i++){
          hoge = min(hoge,lanes[k][i].second.second - lanes[k][i].second.first);
        }
      }
      for(int k = 0; k < 2; k++){
        for(int i = 0; i < lanes[k].size(); i++){
          lanes[k][i].second.first += hoge;
        }
      }
      for(int k = 0; k < 2; k++){
        for(int i = (int)lanes[k].size()-1; i >= 1; i--){
          if(lanes[k][i-1].second.first * lanes[k][i].second.second > lanes[k][i].second.first*lanes[k][i-1].second.second){
            lanes[k][i-1].second = lanes[k][i].second;
          }
        }
      }
      for(int k = 0; k < 2; k++){
        while(lanes[k].size()){
          if(lanes[k].back().second.first == lanes[k].back().second.second){
            if(lanes[k].back().first.second >= 2) {
              temp[k].push_back(make_pair(lanes[k].back().first.first,lanes[k].back().first.second-1));
            }
             lanes[k].pop_back();
          } else break;
        }

      sort(temp[k].begin(), temp[k].end());
      }
      
      for(int k = 0; k < 2; k++){
        for(int i = 0; i < temp[k].size(); i++){
          lanes[!k].push_front(make_pair(temp[k][i], make_pair(0, temp[k][i].first)));
        }
      }
      con += hoge;
    }
    
    cout<<con<<endl;
  }
  return 0;
}
