#include <iostream>
#include <cmath>
#define R 6378.1
using namespace std;



int main(){
  while(1){
    double a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a==-1 && b==-1 && c==-1 && d==-1) break;
    double ra, rb, rc, rd;
    ra=M_PI*a/180;
    rb=M_PI*b/180;
    rc=M_PI*c/180;
    rd=M_PI*d/180;
    double x1, y1, z1, x2, y2, z2, t1, t2;
    t1=R*cos(ra);
    x1=t1*cos(rb);
    y1=t1*sin(rb);
    z1=R*sin(ra);
    t2=R*cos(rc);
    x2=t2*cos(rd);
    y2=t2*sin(rd);
    z2=R*sin(rc);
    double nai;
    nai=x1*x2+y1*y2+z1*z2;
    double rad;
    rad=acos(nai/(R*R));
    double ans;
    ans=rad*R;
    printf("%.0f\n", ans);
  }
  return 0;
}