#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

#define R (6378.1)

inline double Rad(double Deg){ return  Deg * ( acos(-1.0) / 180 ); }

struct EarthPoint{
	EarthPoint():x(0),y(0),z(0),longitude(0),latitude(0){}
	double longitude;
	double latitude;
	bool bValid;
	double operator ^(const EarthPoint &t) const {
		double distance;
		double r_sqd = pow(this->x - t.x,2.0) + pow(this->y - t.y,2.0) + pow(this->z - t.z, 2.0);

		distance = R * acos( 1 - r_sqd / (2*R*R) );
		return distance;
	}
	friend istream &operator>>(istream &, EarthPoint &);
private:
	double x,y,z;
};

istream &operator>>(istream &is, EarthPoint &t){
	is >> t.latitude >> t.longitude;
	
	if( t.latitude < -90 || t.latitude > 90 )
		t.bValid = false;
	if( t.longitude < 0 || t.longitude > 360 )
		t.bValid = false;

	if( !t.bValid ) return is;

	t.x = R * cos( Rad( t.latitude ) ) * sin( Rad( t.longitude ) );
	t.y = R * cos( Rad( t.latitude ) ) * cos( Rad( t.longitude ) );
	t.z = R * sin( Rad( t.latitude ) );
	return is;
}

int main(){
	while( true ){
		EarthPoint A, B;

		cin >> A >> B;

		if( !(A.bValid && B.bValid) ) break;

		cout << floor( (A ^ B) + 0.5 ) << endl;
	}
	return 0;
}