total = 0 while(true) do line = gets if line == nil then break end numbers = line.split(' ').map do |number| number.to_i end top = numbers.max bottom = numbers.min total += (top - bottom) end puts(total)