require 'matrix'
include Math
R = 6378.1
loop do
    a, b, c, d = gets.split.map &:to_f
    break if [a, b, c, d].all?{|x| x == -1}
    ta, tb, tc, td = [a, b, c, d].map{|r| PI * r / 180}

    x1 = R * cos(ta)
    y1 = 0 
    z1 = R * sin(ta)
    x1, y1 = x1 * cos(tb) - y1 * sin(tb), x1 * sin(tb) + y1 * cos(tb)
    v1 = Vector[x1, y1, z1] 
    
    x2 = R * cos(tc)
    y2 = 0 
    z2 = R * sin(tc)
    x2, y2 = x2 * cos(td) - y2 * sin(td), x2 * sin(td) + y2 * cos(td)
    v2 = Vector[x2, y2, z2] 
    
    p (R * acos(v1.inner_product(v2) / (v1.r * v2.r))).round
end