include Math
loop do
  xs = gets.split.map(&:to_f)
  break if xs.all? {|x| x == -1 }
  u, v = xs.each_slice(2).map {|a, b|
    z = sin(2*PI*a/360)
    k = cos(2*PI*a/360)
    x = k*cos(2*PI*b/360)
    y = k*sin(2*PI*b/360)
    [x, y, z]
  }
  t = acos(1 - 0.5 * u.zip(v).map {|a, b| (a - b)**2 }.reduce(0, :+))
  p (t * 6378.1).round
end