#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;

#define rep(i,n) for(int i = 0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const double R = 6378.1;
const double DPI = 180;
const double EPS = 0.00001;

bool ism1(double f)
{
    return (-1 - EPS < f && f < -1 + EPS );
}

int main()
{
    double x[2], y[2], z[2], th[2], al[2], l, l2,  len, r;
    while(cin >> al[0] >> th[0] >> al[1] >> th[1])
    {
        if(ism1(th[0]) && ism1(th[1]) && ism1(al[0]) && ism1(al[1])) break;

        REP(2)
        {
            x[i] = cos(al[i] * M_PI / DPI) * cos(th[i] * M_PI / DPI);
            y[i] = cos(al[i] * M_PI / DPI) * sin(th[i] * M_PI / DPI);
            z[i] = sin(al[i] * M_PI / DPI);

        }
        l =sqrt( (x[1] - x[0]) * (x[1] - x[0]) 
            + (y[1] - y[0]) * (y[1] - y[0])
            + (z[1] - z[0]) * (z[1] - z[0]));
        
        //cout << asin(l / 2) << endl;
        r = R * 2 * asin(l / 2 ) ;
        printf("%.0f\n", r);
    }
    return 0;
}