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

int main(){
	double r = 6378.1;
	double a,b,c,d;
	while( cin >> a >> b >> c >> d && b != -1 ){
		double theta = (90.0-a) * M_PI / 180.0;
		double phi = b * M_PI / 180.0;
		
		double x1 = r * sin(theta) * cos(phi);
		double y1 = r * sin(theta) * sin(phi);
		double z1 = r * cos(theta);
		theta =(90.0-c) * M_PI / 180.0;
		phi = d * M_PI / 180.0;
		double x2 = r * sin(theta) * cos(phi);
		double y2 = r * sin(theta) * sin(phi);
		double z2 = r * cos(theta);
		double co = (x1*x2+y1*y2+z1*z2) / (r*r);
		double rad = acos(co);
		printf("%.lf\n",rad*r);
	}
}