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++: // 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) << '\n';
	}

	return 0;
}

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

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

using namespace std;

typedef unsigned long long ull;

#define TH(x) (((x)/180.0)*pi)

int main(){
  long double a,b,c,d;
  const long double r  = 6378.1;
  const long double pi = M_PI;
  while(cin>>a>>b>>c>>d, (a!=-1 || b!=-1 || c!=-1 || d!=-1)){
    long double x1,y1,z1,x2,y2,z2,ip,ang;
    a = TH(a); b = TH(b); c = TH(c); d = TH(d);

    x1 = cos(b) * cos(a);
    y1 = sin(b) * cos(a);
    z1 = sin(a);

    x2 = cos(d) * cos(c);
    y2 = sin(d) * cos(c);
    z2 = sin(c);

    ip  = x1*x2 + y1*y2 + z1*z2;
    ang = acos(ip);

    cout << (int)(floor(r*ang+0.5)) << endl;
  }
  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 double 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(x1*c - x2*c));
    cout << (int)(d + 0.5) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

double R = 6378.1;
double r = R;
struct Point
{  
    double x, y, z;
    Point(){};
    Point(double x, double y, double z):x(x),y(y), z(z){};

    Point operator -(Point p){
        return Point(x-p.x, y-p.y, z-p.z);
    }
    double getDist2(){
        return x*x+y*y+z*z;
    }

    void print(){
        printf("(%lf, %lf, %lf)\n", x, y, z);
    }
};

Point getPoint(double ang1, double ang2){
    return Point(R*cos(ang1)*cos(ang2), R*cos(ang1)*sin(ang2), R*sin(ang1));
}

double getAng(double d){
    return d*PI/180;
}

int main(){
    double a, b, c, d;
    while(cin>>a>>b>>c>>d){
        if(a == -1 && b==-1 && c ==-1 && d == -1) break;
        Point p1 = getPoint(getAng(a), getAng(b)), p2 = getPoint(getAng(c), getAng(d));
        //p1.print();
        //p2.print();
        double co = (2*r*r-(p1-p2).getDist2())/2/r/r;
        double e = acos(co);

        cout<<(int)(r*e+0.5)<<endl;
    }
}

C++: #define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 1e-8;

const static double r = 6378.136;

int main(){
	double f1,g1,f2,g2;
	//ido,kedo
	while(~scanf("%lf %lf %lf %lf",&f1,&g1,&f2,&g2)){
		if(f1==g1 && g1==f2 && f2==g2 && g2 == -1) break;

		f1 = (90.0-f1) * M_PI / 180.0;
		g1 = g1 * M_PI / 180.0;

		f2 = (90.0-f2) * M_PI / 180.0;
		g2 = g2 * M_PI / 180.0;

		double x1 = r * sin(f1) * cos(g1);
		double y1 = r * sin(f1) * sin(g1);
		double z1 = r*cos(f1);

		double x2 = r * sin(f2) * cos(g2);
		double y2 = r * sin(f2) * sin(g2);
		double z2 = r*cos(f2);

		double dist = (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2);

		printf("%.0lf\n",r*acos(1-dist/(2*r*r))+eps);
	}
}

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

int main()
{
	double a, b, c, d;
	const double pi = 3.141592653589793;

	cin >> a >> b >> c >> d;

	while (a != -1 || b != -1 || c!= -1 || d != -1) {
		double u[3], v[3];

		u[0] = cos(b * pi / 180) * cos(a * pi / 180);
		u[1] = sin(b * pi / 180) * cos(a * pi / 180);
		u[2] = sin(a * pi / 180);

		v[0] = cos(d * pi / 180) * cos(c * pi / 180);
		v[1] = sin(d * pi / 180) * cos(c * pi / 180);
		v[2] = sin(c * pi / 180);

		cout << round(acos(u[0] * v[0] + u[1] * v[1] + u[2] * v[2]) * 6378.1) << endl;
		
		cin >> a >> b >> c >> d;
	}

	return 0;
}

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

int main()
{
  double a_phi, a_theta, b_phi, b_theta;
  while (cin >> a_theta >> a_phi >> b_theta >> b_phi && a_phi >= 0) {
    static const double R = 6378.1;
    a_theta *= M_PI/180.0; a_phi *= M_PI/180.0;
    b_theta *= M_PI/180.0; b_phi *= M_PI/180.0;

    const double a_x = R*cos(a_theta)*cos(a_phi);
    const double a_y = R*cos(a_theta)*sin(a_phi);
    const double a_z = R*sin(a_theta);
    const double b_x = R*cos(b_theta)*cos(b_phi);
    const double b_y = R*cos(b_theta)*sin(b_phi);
    const double b_z = R*sin(b_theta);

    const double dot = a_x*b_x + a_y*b_y + a_z*b_z;
    const double rad = acos(dot / (R*R));
    const double ans = R * rad;
    cout << lround(ans) << endl;
  }
  return 0;
}

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

#define EPS 1e-10
#define EQ(a, b) (fabs(a - b) < EPS)
 
int main(void)
{
    const long double radius = 6378.1;
    const long double pi = acos(-1);
    long double x[2], y[2];
    long double dx;
    long double d;
     
    while (1){
        int i;
        
		bool f = true;
		
        for (i = 0; i < 2; i++){
            cin >> y[i] >> x[i];
            if (y[i] != -1 || x[i] != -1) f = false;
			 
            x[i] = x[i] * pi / 180;
            y[i] = y[i] * pi / 180;
        }
		
		if (f) return 0;
         
        dx = x[1] - x[0];
         
        d = radius * acos( sin(y[0]) * sin(y[1]) + cos(y[0]) * cos(y[1]) * cos(dx) );
         
        cout << (int)d << endl;
    }
     
    return 0;
}