#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

const long double pi = acos(-1);

int main() {
  long double a, b, c, d;
  while(cin>>a>>b>>c>>d && !(a==-1&&b==-1&&c==-1&&d==-1)) {
    long double x1,y1,z1,x2,y2,z2,rad;
    a = pi*a/180.0;
    b = pi*b/180.0;
    c = pi*c/180.0;
    d = pi*d/180.0;
    x1 = cos(b)*cos(a);
    z1 = sin(b)*cos(a);
    y1 = sqrt(1.0-x1*x1-z1*z1)*(a>0.0?1:-1);
    x2 = cos(d)*cos(c);
    z2 = sin(d)*cos(c);
    y2 = sqrt(1.0-x2*x2-z2*z2)*(c>0.0?1:-1);
    rad = acos(x1*x2+y1*y2+z1*z2);
    cout << (int)(6378.1*rad+0.5) << endl;
  }
  return 0;
}