### subroutines

def lower_bound(arr, key, i0 = 0, i1 = arr.length)
  lb = i0 - 1
  ub = i1

  while lb + 1 < ub
    m = (lb + ub) / 2
    if arr[m] >= key
      ub = m
    else
      lb = m
    end
  end
  ub
end

### main

loop do
  n = gets.to_i
  break if n == 0

  swmrs = []
  n.times do
    ti, ci = gets.split.map(&:to_i)
    swmrs << [ti, ci]
  end
  swmrs.sort!{|a, b| b <=> a}
  #p swmrs

  t0s = 2.times.map{[]}
  t0tot1s = 2.times.map{{}}
  t0used = 2.times.map{[]}
  max_t = 0
  
  for i in (0...n)
    ti, ci = swmrs[i]
    t0 = 0
    t0s0 = 2.times.map{[]}
    for j in (0...ci)
      for l in (0..1)
        t1 = t0 + ti

        k = lower_bound(t0s[l], t0) - 1
        #p ['  lower_bound-1', t0, k]
          
        if k < 0
          if t0used[l][t0].nil?
            t0s0[l] << t0
            t0tot1s[l][t0] = t1
            t0used[l][t0] = true
          end
        else
          t1k = t0tot1s[l][t0s[l][k]]
          if t1 < t1k
            t1 = t1k
          elsif t0used[l][t0].nil?
            t0s0[l] << t0
            t0tot1s[l][t0] = t1
            t0used[l][t0] = true
          end
        end
        #p [i, j, l, t0, t1]
        
        t0 = t1
      end
    end
    
    for l in (0..1)
      t0s[l] = (t0s[l] + t0s0[l]).sort
    end
    #p (0..1).map{|l| t0s[l].map{|tt0| [tt0, t0tot1s[l][tt0]]}}

    max_t = t0 if max_t < t0
  end
  
  puts max_t
end