### main

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

  reqs = []
  max_d = 0
  n.times do
    d0, d1, w = gets.split.map(&:to_i)
    max_d = d1 if max_d < d1
    reqs << [d0, d1, w]
  end
  #reqs.sort!

  maxws = (max_d + 1).times.map{(max_d + 1).times.map{0}}

  reqs.sort.each do |d0, d1, w|
    maxws0 = maxws.map{|ws| ws.clone}

    for i in (1..max_d)
      for j in (1..max_d)
        if i == j && i == d1
          wi = maxws[d0 - 1][j] + w
          wj = maxws[i][d0 - 1] + w
          maxws0[i][j] = wi if maxws0[i][j] < wi
          maxws0[i][j] = wj if maxws0[i][j] < wj
        elsif i == d1
          wi = maxws[d0 - 1][j] + w
          maxws0[i][j] = wi if maxws0[i][j] < wi
        elsif j == d1
          wj = maxws[i][d0 - 1] + w
          maxws0[i][j] = wj if maxws0[i][j] < wj
        end

        wij0 = maxws0[i - 1][j]
        wij1 = maxws0[i][j - 1]
        maxws0[i][j] = wij0 if maxws0[i][j] < wij0
        maxws0[i][j] = wij1 if maxws0[i][j] < wij1
      end
    end

    maxws = maxws0
  end

  puts maxws[max_d][max_d]
end