R = 6378.1
PI = Math.acos(-1)


class Numeric
  def to_rad; self * PI / 180 end
  def to_deg; self * 180 / PI end
end

class Point
  attr_accessor :x, :y, :z
  def initialize(x = 0, y = 0, z = 0); @x = x; @y = y; @z = z; end
  def abs; (@x**2 + @y**2 + @z**2)**0.5; end
  def +(other); Point.new( @x + other.x, @y + other.y, @z + other.z ); end
  def -(other); Point.new( @x - other.x, @y - other.y, @z - other.z ); end
  def self.ll_to_p(h, l) # h and l is rad
    y = Math.sin(h) * R
    r = Math.cos(h) * R
    x = r * Math.cos(l)
    z = r * Math.sin(l)
    Point.new(x, y, z)
  end
end


loop do
  h1, l1, h2, l2 = gets.split(" ").map(&:to_f)
  break if h1 == -1
  
  p1 = Point.ll_to_p(h1.to_rad, l1.to_rad)
  p2 = Point.ll_to_p(h2.to_rad, l2.to_rad)

  d = (p1 - p2).abs

  ang = Math.acos(1.0 - d**2 / R**2 / 2)

  puts (ang * R).round
end