Go: // Great-circular distance
// Reference: https://ja.wikipedia.org/wiki/大円距離

package main

import (
	"bufio"
	"os"
	"strings"
	"strconv"
	"math"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
const (
	R = 6378.1
	M = math.Pi/180
)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		input := make([]float64, len(buf))
		for i := range input {
			input[i], _ = strconv.ParseFloat(buf[i], 64)
		}
		if input[0] == -1 && input[1]== -1&&
			input[2] == -1 && input[3] == -1 {
			break
		}
		y1, x1, y2, x2 := input[0], input[1], input[2], input[3]
		a := math.Cos(y1*M)*math.Cos(y2*M)*math.Cos((x1-x2)*M) +
			math.Sin(y1*M)*math.Sin(y2*M)
		fmt.Println(int(R*math.Acos(a)+0.5))
	}
}

C++: #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;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define PI acos(-1)
const double R=6378.01;

double dist(double x,double y,double z){
  return sqrt(x*x+y*y+z*z+1e-10);
}

void calc(double  &x,double &y,double &z,
	  double a,double b){
  double phi  = PI/2*a/90.0;
  double theta= PI*b/180.0;
  z=R*sin(phi);
  x=R*cos(phi)*cos(theta);
  y=R*cos(phi)*sin(theta);
}

double solve(double *a){
  double x[2],y[2],z[2];
  rep(i,2){
    calc(x[i],y[i],z[i],
	 a[2*i],a[2*i+1]);
  }
  
  double C=dist(x[0]-x[1],y[0]-y[1],z[0]-z[1]);
  

  double theta = acos((2*R*R-C*C)/(2*R*R));
  if ( !(-2*R*R<=2*R*R-C*C))theta=acos(-1);
  else if ( !(2*R*R-C*C<=2*R*R))theta=acos(1);
  return R*theta;
}

main(){
  double in[4];
  while(cin>>in[0]>>in[1]>>in[2]>>in[3]){
    if ( in[0] == 0 && in[1] == 0 && in[2] == 0 && in[3]==0)break;
    printf("%.0lf\n",solve(in));
  }
}

C++: #include <cstdio>
#include <cmath>

using namespace std;

int main()
{
	double a, b, c, d;
	
	while (scanf("%lf %lf %lf %lf", &a, &b, &c, &d) && b >= -0.5){
		if (b > 180) b = b - 360;
		if (d > 180) d = d - 360;
		
		a = a * M_PI / 180;
		c = c * M_PI / 180; 
		printf("%d\n", (int)round(6378.1 * acos(sin(a) * sin(c) + cos(a) * cos(c) * cos((d - b) * M_PI / 180))));
	}
	return (0);
}

C++: #include<iostream>
#include<cmath>
using namespace std;
double R=6378.1;
main()
{
	double a,b,c,d;
	while(cin>>a>>b>>c>>d,a>=0)
	{
		double x1,x2,y1,y2,z1,z2;
		double p1=a/180*M_PI,r1=b/180*M_PI,p2=c/180*M_PI,r2=d/180*M_PI;
		x1=cos(p1)*cos(r1);
		x2=cos(p2)*cos(r2);
		y1=cos(p1)*sin(r1);
		y2=cos(p2)*sin(r2);
		z1=sin(p1);
		z2=sin(p2);
		double Rn=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
		double theta=acos((2-Rn*Rn)/2);
		cout<<round(R*theta)<<endl;
	}
}

C++: // 2011/02/26 Tazoe

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

int main()
{
	while(true){
		double a, b, c, d;
		cin >> a >> b >> c >> d;
		if(a==-1.0&&b==-1.0&&c==-1.0&&d==-1.0)
			break;

		a = a*M_PI/180.0;
		b = b*M_PI/180.0;
		c = c*M_PI/180.0;
		d = d*M_PI/180.0;

		double x = acos(sin(a)*sin(c)+cos(a)*cos(c)*cos(d-b));

		cout << (int)(6378.1*x+0.5) << endl;
	}

	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define F first
#define S second

int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  long double a,b,c,d;
  while(cin>>a>>b>>c>>d,a>0){
    a*=M_PI/180;
    b*=M_PI/180;
    c*=M_PI/180;
    d*=M_PI/180;
    long double the=acos(cos(M_PI/2-a)*cos(M_PI/2-c)+sin(M_PI/2-a)*sin(M_PI/2-c)*cos(d-b));
    printf("%.0Lf\n",the*6378.1);
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
double a,b,c,d,R=6378.1,pi=acos(-1);
while(cin>>a>>b>>c>>d){
if(a==-1&&b==-1&&c==-1&&d==-1)break;
a*=pi/180;
b*=pi/180;
c*=pi/180;
d*=pi/180;
printf("%.0f\n",asin(sqrt(
(cos(a)*cos(b)-cos(c)*cos(d))*(cos(a)*cos(b)-cos(c)*cos(d))
+(cos(a)*sin(b)-cos(c)*sin(d))*(cos(a)*sin(b)-cos(c)*sin(d))
+(sin(a)-sin(c))*(sin(a)-sin(c)))*0.5)*2*R);
}
return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

double dtor(double deg) {       // x¨WA
  return deg*M_PI/180;
}
double dist(double x, double y) {
  return sqrt(x*x+y*y);
}

int main() {
  double a,b,c,d;
  while(cin>>a>>b>>c>>d,a!=-1||b!=-1||c!=-1||d!=-1) {
    double bb = dtor(90.0-a);
    double cc = dtor(90.0-c);
    double A = dtor(abs(d-b));
    double res = 6378.1*acos(cos(bb)*cos(cc)+sin(bb)*sin(cc)*cos(A));
    printf("%.0f\n", res);
  }
}