#include<bits/stdc++.h>
using namespace std;

int main() {
    while (true) {
        int n;
        cin >> n;
        if (!n) return 0;

        vector<int> t(n);
        vector<int> c(n);
        vector<vector<int>> tm(n, vector<int>(510, 0));
        vector<vector<int>> dlap(n, vector<int>(n, 0));
        for (int i = 0; i < n; ++i) {
            cin >> t[i] >> c[i];
        }
        for (int i = 1; i < 510; ++i) {
            for (int j = 0; j < n; ++j) {
                if (c[j] * 2 < i) continue;
                if (i < 3) {
                    tm[j][i] = t[j] * i;
                    continue;
                }
                int ma = tm[j][i - 1] + t[j];
                for (int k = 0; k < n; ++k) {
                    if (tm[k][i - (dlap[j][k] + 1) * 2] > ma) {
                        ma = tm[k][i - (dlap[j][k] + 1) * 2];
                    }
                }
                for (int k = 0; k < n; ++k) {
                    if (tm[k][i - (dlap[j][k] + 1) * 2] == ma) {
                        ++dlap[j][k];
                    }
                }
                tm[j][i] = ma;
            }
        }
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            ans = max(ans, tm[i][c[i] * 2]);
        }
        cout << ans << "\n";
    }
}