#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const int maxn = 55, maxm = 550;
int n, id[maxn], t[maxn], c[maxn], top[maxn], ans[maxn][maxm];

bool cmp(const int &a, const int &b)
{
    return t[a] > t[b];
}

int main()
{
    while (scanf("%d", &n), n)
    {
        for (int i = 0; i < n; i++)
        {
            scanf("%d%d", &t[i], &c[i]);
            c[i] <<= 1;
            id[i] = i;
        }
        sort(id, id + n, cmp);
        int last = 0;
        for (int k = 0; k < n; k++)
        {
            int i = id[k];
            memset(top, 0, sizeof top);
            ans[i][0] = 0;
            for (int j = 1; j <= c[i]; j++)
            {
                ans[i][j] = ans[i][j - 1] + t[i];
                for (int h = 0; h < k; h++)
                {
                    int pre = id[h];
                    if (ans[pre][top[pre] + 1] < ans[i][j - 1]) 
                        top[pre]++;
                    //if (top[pre] % 2 != j % 2)
                    //    top[pre]++;
                    if (top[pre] % 2 == (j + 1) % 2 && top[pre] + 1 <= c[pre] && ans[pre][top[pre]] < ans[i][j - 1] && ans[pre][top[pre] + 1] > ans[i][j])
                        ans[i][j] = ans[pre][top[pre] + 1];
                }
		//printf("%d %d %d\n", i, j, ans[i][j]);
            }
            last = max(last, ans[i][c[i]]);
        }
        printf("%d\n", last);
    }
    
    return 0;
}