### main

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

  swmrs = []
  n.times do
    ti, ci = gets.split.map(&:to_i)
    vi = Rational(1, ti)
    swmrs << [vi, ti, ci]
  end
  swmrs.sort!
  #p swmrs

  lanes = 2.times.map{[]}

  for i in (0...n)
    vi, ti, ci = swmrs[i]
    t0 = 0
    lanes0 = 2.times.map{[]}
    ci.times do
      for l in (0..1)
        t1 = t0 + ti
        done = false

        lanes[l].each do |tc0, tc1|
          break if tc1 <= t0
          if tc0 < t0 && t1 < tc1
            done = true
            t1 = tc1
            break
          end
        end
        lanes0[l] << [t0, t1] if ! done
        
        t0 = t1
      end
    end

    for l in (0..1)
      lanes[l] = (lanes[l] + lanes0[l]).sort{|a, b| b <=> a}
    end
    
  end
  #p lanes

  puts lanes.map{|l| l.first.last}.max
end