#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
struct Point{
  double x, y, z;
  Point(double a, double b){
    x = cos(a) * cos(b);
    y = cos(a) * sin(b);
    z = sin(a);
  }
  double norm(){
    return x*x + y*y + z*z;
  }
  double abs(){
    return sqrt(norm());
  }
};
double dot(Point p, Point q){
  return p.x*q.x + p.y*q.y + p.z*q.z;
}

int main(){
  double a, b, c, d;
  const double R = 6378.1;
  while(cin >> a >> b >> c >> d && a != -1){
    a *= M_PI / 180.0;
    b *= M_PI / 180.0;
    c *= M_PI / 180.0;
    d *= M_PI / 180.0;
    Point p(a, b);
    Point q(c, d);
    double theta = acos(dot(p, q) / p.abs() / q.abs());
    printf("%.0lf\n", R * theta);
  }
  return 0;
}