#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;
ld pi = acos(-1.0);
const ld dtop = pi / 180.;
const ld ptod = 1. / dtop;

ld rad = 6378.1;
int main() {
	while (1) {
		ld a, b, c, d; cin >> a >> b >> c >> d;
		if (b < -eps)break;
		ld wd= (d-b);
		
		ld ax = rad*(cos(a*dtop));
		ld ay = 0;
		ld az = rad*(sin(a*dtop));
		ld bx = (rad*cos(wd*dtop))*(cos(c*dtop));
		ld by = (rad*sin(wd*dtop))*(cos(c*dtop));
		ld bz = rad*(sin(c*dtop));
		ld dx = ax - bx;
		ld dy = ay - by;
		ld dz = az - bz;
		ld dis = sqrt(dx*dx + dy*dy + dz*dz);
		ld arad = asin( (dis / 2)/rad);
		ld ans = rad*2*arad;
		int ians = int(round(ans));
		cout << ians << endl;
	}
	return 0;
}