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

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);

string out[] = {"black","blue","lime","aqua","red","fuchsia","yellow","white"};

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

int main(){
	double a,b,c,d;
	while(cin>>a>>b>>c>>d,a>0){
		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<cmath>

double toDegree(double a){
	return M_PI / 180 * a;
}

int main(){
	const double R = 6378.1;
	double a, b, c, d;
	while(std::cin >> a >> b >> c >> d, a != -1){
		//弧度法に変換
		a = toDegree(a);
		b = toDegree(b);
		c = toDegree(c);
		d = toDegree(d);
		double delta_x = d-b,
			dist = R*acos(sin(a)*sin(c)+cos(a)*cos(c)*cos(delta_x));
		std::cout << static_cast<int>(dist+0.5) << std::endl;
	}
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>

int main(void)
{
	const double radius = 6378.137;
	const double pi = acos(-1);
	double x[2], y[2];
	double dx;
	double d;
	//double p;
	char str[2048];
	
	while (1){
		int i;
		
		for (i = 0; i < 2; i++){
			scanf("%lf %lf", &y[i], &x[i]);
			
			if (x[i] == -1.0) return (0);
			
			x[i] = x[i] * pi / 180;
			y[i] = y[i] * pi / 180;
		}
		
		dx = x[1] - x[0];
		
		d = radius * acos( sin(y[0]) * sin(y[1]) + cos(y[0]) * cos(y[1]) * cos(dx) );
		//p = 90 - atan2( cos(y[0]) * tan(y[1]) - sin(y[0]) * cos(dx), sin(dx) );
		
		printf("%.0f\n", d);
	}
	
	return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>

int main(void)
{
	const double radius = 6378.137;
	const double pi = acos(-1);
	double x[2], y[2];
	double dx;
	double d;
	//double p;
	char str[2048];
	
	while (1){
		int i;
		
		for (i = 0; i < 2; i++){
			scanf("%lf %lf", &y[i], &x[i]);
			
			if (x[i] == -1.0) return (0);
			
			x[i] = x[i] * pi / 180;
			y[i] = y[i] * pi / 180;
		}
		
		dx = x[1] - x[0];
		
		d = radius * acos( sin(y[0]) * sin(y[1]) + cos(y[0]) * cos(y[1]) * cos(dx) );
		//p = 90 - atan2( cos(y[0]) * tan(y[1]) - sin(y[0]) * cos(dx), sin(dx) );
		
		printf("%d\n", (int)(d + 0.5));
	}
	
	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+2*M_PI));
    printf("%.0Lf\n",the*6378.1);
  }
}

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

using namespace std;

int main()
{
	const double r = 6378.1; // ツ地ツ仰づ個板シツ径
	double a, b, c, d;

	while (cin >> a >> b >> c >> d && a != -1. && b != -1. && c != -1. && d != -1. ){
		a *= M_PI/180.; b *= M_PI/180.; c *= M_PI/180.; d *= M_PI/180.;
		double e = sin (a)*sin(c) + cos(a)*cos(c)*cos(b-d);
		int res = (int)(r*acos(e ) + 0.5);
		cout << res << endl;

	} // end loop

	return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<double,double>P;
const double R=6378.1;
const double PI=3.14159265359;
double a,b,c,d;


int main()
{
	for(;scanf("%lf%lf%lf%lf",&a,&b,&c,&d);)
	{
		if(a==-1&&b==-1&&c==-1&&d==-1)break;
		P ang[2];
		vector<P>v;
		vector<double>p[2];
		v.push_back(make_pair(a,b));
		v.push_back(make_pair(c,d));
		for(int i=0;i<2;i++)
		{
			ang[i].first=(v[i].first/180)*PI;
			ang[i].second=(v[i].second/180)*PI;
		}
		for(int i=0;i<2;i++)
		{
			p[i].push_back(R*cos(ang[i].first)*cos(ang[i].second));
			p[i].push_back(R*cos(ang[i].first)*sin(ang[i].second));
			p[i].push_back(R*sin(ang[i].first));
		}
		double dis=sqrt(pow(p[0][0]-p[1][0],2)+pow(p[0][1]-p[1][1],2)+pow(p[0][2]-p[1][2],2));
		double difa=(R*R*2-dis*dis)/(2*R*R);
		double anp=acos(difa);
		double cmp=
		printf("%d\n",(int)(PI*R*(anp/PI)+0.5));
	}
	return 0;
}

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

const D r = 6378.1;
const D PI = acos(-1);

D pow2(D a){
  return a*a;
}

int main(){
  D an, ae, bn, be;
  while(cin >> an >> ae >> bn >> be, ae>=0){
    D p = an+bn;
    D n = abs(an-bn);
    D e = abs(ae-be);
    if(e >= 180) e = 360- e;

    int ans = sqrt( pow2(n*r) + pow2(e*r*cos(p)) ) + 0.5;
    cout << ans << endl;
  }
}