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 <cmath>
using namespace std;

const double PI = 3.14159265358979;

inline double d2r(double d)
{
  return d * PI / 180.0;
}

int main()
{
  const double R = 6378.1;

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

    a = d2r(a);
    b = d2r(b);
    c = d2r(c);
    d = d2r(d);

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

    cout << static_cast<int>(thita * R + 0.5) << endl;
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	double a,b,c,d;
	while(cin>>a>>b>>c>>d,(b>-0.5)){
		a=a*M_PI/180;
		b=b*M_PI/180;
		c=c*M_PI/180;
		d=d*M_PI/180;
		double x1=cos(a)*cos(b),y1=cos(a)*sin(b),z1=sin(a),x2=cos(c)*cos(d),y2=cos(c)*sin(d),z2=sin(c);
		double n=x1*x2+y1*y2+z1*z2;
		double r1=sqrt(x1*x1+y1*y1+z1*z1);
		double r2=sqrt(x2*x2+y2*y2+z2*z2);
		double rad=acos(n/(r1*r2));
		cout<<(int)(rad*6378.1+0.5)<<endl;
	}
	
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

double M_PI=acos(-1);

int main(){
	double a[2],b[2],r=6378.1;
	while(1){
		rep(i,0,2) cin>>a[i]>>b[i];
		if(a[0]==-1 && b[0]==-1 && a[1]==-1 && b[1]==-1) break;
		double x[2],y[2],z[2],d2,l,c=M_PI/180.0;
		/*rep(i,0,2) x[i]=r*cos(a[i]*c)*cos(b[i]*c);
		rep(i,0,2) y[i]=r*sin(a[i]*c)*cos(b[i]*c);
		rep(i,0,2) z[i]=r*sin(b[i]*c);
		d2=(x[1]-x[0])*(x[1]-x[0])+(y[1]-y[0])*(y[1]-y[0])+(z[1]-z[0])*(z[1]-z[0]);
		o(" "<<d2);
		double t=acos(1-d2/(2.0*r*r));
		o(t);
		l=r*t;
		l=int(l+0.5);
		o(l);*/
		double t=acos(cos(a[0]*c)*cos(a[1]*c)*cos(b[0]*c-b[1]*c)+sin(a[0]*c)*sin(a[1]*c));
		double ans=r*t;
		ans=(int)(ans+0.5);
		o(ans);
	}
}

C++: // https://qiita.com/port-development/items/eea3a0a225be47db0fd4
#include<iostream>
#include<cmath>
using namespace std;

#define PI 2*acos(0.0)
#define DEGtoRAD(X) (X*PI)/180.0

int main(){
    double a, b, c, d;
    while(cin >> a >> b >> c >> d){
        if(a+b+c+d == -4)   break;
        a = DEGtoRAD(a);
        b = DEGtoRAD(b);
        c = DEGtoRAD(c);
        d = DEGtoRAD(d);
        double x = acos(sin(a)*sin(c) + cos(a)*cos(c)*cos(b-d));
        int ans = round(6378.1 * x);
        cout << ans << endl;
    }
    return 0;
}

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

#define r 6378.1

int main(){
  double a,b,c,d;

  while(true){
    scanf("%lf %lf %lf %lf" ,&a ,&b ,&c ,&d);
    if(a == -1 && b == -1 && c == -1 && d == -1){
      break;
    }

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

    double e = cos(a)*cos(b);
    double f = sin(b)*cos(a);
    double g = sin(a);
    double h = cos(c)*cos(d);
    double i = sin(d)*cos(c);
    double j = sin(c);

    double dist = acos(e*h + f*i + g*j);  

    printf("%d\n" ,(int)(r*dist+0.5));
  }

  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std ;

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  const int r = 6378.1;
  double x1,y1,x2,y2;
  double c = M_PI/180.0;
  while(cin >> y1 >> x1 >> y2 >> x2){
    if(y1 == -1 && x1 == -1 && y2 == -1 && x2 == -1) break;
    y1 = y1 * c;
    y2 = y2 * c;
    double d = r * acos(sin(y1) * sin(y2) + cos(y1) * cos(y2) * cos((x2 - x1) * M_PI/180));
    cout << (int)(d + 0.5) << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#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 <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;
const double PI = acos(-1.0);

double Q(double X){return X*X;}

int main(){
	double a,b,c,d;
	while(cin>>a>>b>>c>>d,a!=-1&&b!=-1&&c!=-1&&d!=-1){
		a = a / 180 * PI;
		b = b / 180 * PI;
		c = c / 180 * PI;
		d = d / 180 * PI;
		double ax,ay,az;
		az = sin(a);
		ax = sqrt(1-az*az) * cos(b);
		ay = sqrt(1-az*az) * sin(b);
		double bx,by,bz;
		bz = sin(c);
		bx = sqrt(1-bz*bz) * cos(d);
		by = sqrt(1-bz*bz) * sin(d);
		double dis = sqrt(Q(ax-bx)+Q(ay-by)+Q(az-bz));
		double arc = asin(dis/2);
		double ans = 2 * 6378.1 * arc;
		int i_ans = (int)floor(ans + 0.5);
		cout << i_ans << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	const double PI = 2*acos(0.0);
	double a,b,c,d;
	while(cin>>a>>b>>c>>d&&!(a==-1&&b==-1&&c==-1&&d==-1)){
		pair<double,double> angle[2];
		vector<pair<double,double> > v;
		v.push_back(make_pair(a,b));
		v.push_back(make_pair(c,d));
		// pxðWAÉvZ
		for(int i = 0; i < 2; i++){
			angle[i].first=(v[i].first/180)*PI;
			angle[i].second=(v[i].second/180)*PI;
		}
		// ¼a
		const double r=6378.1;
		vector<double> points[2];
		// ÊÀWð»ê¼êßé
		for(int i = 0; i < 2; i++){
			points[i].push_back(r*cos(angle[i].first)*cos(angle[i].second));
			points[i].push_back(r*cos(angle[i].first)*sin(angle[i].second));
			points[i].push_back(r*sin(angle[i].first));
		}
		// 2_Ì¼ü£ðvZ
		double dist = sqrt((points[0][0]-points[1][0])*(points[0][0]-points[1][0])
			+(points[0][1]-points[1][1])*(points[0][1]-points[1][1])
			+(points[0][2]-points[1][2])*(points[0][2]-points[1][2]));
		// ]·èÉæè3ÂÌüªªÈ·cosÌlðßé
		double diffAngle=(r*r+r*r-dist*dist)/(2*r*r);
		// acosÉæècosÌlðÏ·
		double anp = acos(diffAngle);
		// 2*PIÆRÂÌüªªÈ·pxÌäðg¢A£ðßé
		double comp=PI*r*(anp/PI);
		cout<<(int)(comp+0.5)<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cmath>
#define PI 3.141592
using namespace std;

int main(){
  double a,b,c,d;
  double seta;

  while(1){
    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;
    seta = acos( cos(a)*cos(c)*cos(b-d)+sin(a)*sin(c) );
    cout << (int)(6378.1 * seta + 0.5) << endl;

  }
}