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>

#define PI 3.14159265358979
#define RADIUS 6378.1 // 単位km

#define DEG_TO_RAD(theta) theta * PI / 180.0

struct position {
	double lat; // 緯度
	double lon; // 経度
	// 以下直交座標系
	double x;
	double y;
	double z;
};

void getCoordinates(position& loc)
{
	loc.x = RADIUS * cos(DEG_TO_RAD(loc.lat)) * cos(DEG_TO_RAD(loc.lon));
	loc.y = RADIUS * cos(DEG_TO_RAD(loc.lat)) * sin(DEG_TO_RAD(loc.lon));
	loc.z = RADIUS * sin(DEG_TO_RAD(loc.lat));
}

double getOneLineDistance(const position& loc1, const position& loc2)
{
	return sqrt(pow(loc1.x-loc2.x, 2) + pow(loc1.y - loc2.y, 2) + pow(loc1.z - loc2.z, 2));
}

double getInteriorAngle(double oneLineDistance)
{
	return 2 * asin(oneLineDistance/2/RADIUS);
}

double getSurfaceDistance(position& loc1, position& loc2)
{
	getCoordinates(loc1);
	getCoordinates(loc2);
	return RADIUS * getInteriorAngle(getOneLineDistance(loc1, loc2));
}

int main(void)
{
	position loc1, loc2;

	while(1) {
		std::cin >> loc1.lat >> loc1.lon >> loc2.lat >> loc2.lon;
		if(loc1.lat == -1 && loc1.lon == -1 && loc2.lat == -1 && loc2.lon == -1) {
			break;
		}
		std::cout << (int)(getSurfaceDistance(loc1, loc2) + 0.5) << std::endl;
	}

	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] == -1 && in[1] == -1 && in[2] == -1 && in[3]==-1)break;
    printf("%.0lf\n",solve(in));
  }
}

C++: // #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}

#define EARTH_RADIUS 6378.1
// ------------------- include, typedef, define END. -------------------

double toRad(double in){
	return in * M_PI / 180.0;
}

int Hubeny(double Lat1, double Lon1, double Lat2, double Lon2){
	int ans = 0;
	LL earth_radius_m = EARTH_RADIUS * 1000;
	// ヒュベニの公式
	// 東京-大阪間とかならokだが東京-ロンドン間は400km(適当)くらい誤差出る.

	// 経度が359.82だと-0.18に直さないといけない？
	// 情報源なし、だがマイナスに直したほうが正確値(Lambert-Andoyer)に近いっぽい？
	// 東京-イギリス間ではsample outputとの誤差縮まるが、シドニー-シカゴ間では誤差広がる.
	// ロンドン-ブエノスアイレス間では、abs(360.0 - LonX)*(-1)してもしなくても結果変わらず.
	// (まぁロンドン-ブエノスアイレス間はLon1,Lon2ともにマイナスなるので結果変わらずで正解か.)
	// なので、よく分からない.
	//if (Lon1 > 180.0)	Lon1 = abs(360.0 - Lon1)*(-1);
	//if (Lon2 > 180.0)	Lon2 = abs(360.0 - Lon2)*(-1);
	//cout << Lat1 << " " << Lon1 << " " << Lat2 << " " << Lon2 << " ←これで計算します" << endl;

	// 1. 経緯度をラジアンに変換
	double Lat1_rad = toRad(Lat1);
	double Lon1_rad = toRad(Lon1);
	double Lat2_rad = toRad(Lat2);
	double Lon2_rad = toRad(Lon2);

	// 2. 地点1と地点2の平均緯度・緯度差・経度差を計算
	double latAveRad = (Lat1_rad + Lat2_rad) / 2.0;
	double latDiff = abs(Lat1_rad - Lat2_rad);
	double lonDiff = abs(Lon1_rad - Lon2_rad);

	// 3. 子午線曲率半径・卯酉線曲率半径を計算
	// (地球の半径が与えられているので、地球半径が絡む変数の計算を自力でやる)
	LL a_2 = pow(earth_radius_m, 2), b_2 = pow(6356752, 2);
	double daiichi_risinnritsu_2zyou = (double)(a_2 - b_2) / a_2;
	LL temp2 = /*a(1-e*e)*/earth_radius_m * (1 - daiichi_risinnritsu_2zyou);

	double meridian =
		/*6335439*/ temp2 / sqrt(pow(1 - daiichi_risinnritsu_2zyou * sin(latAveRad) * sin(latAveRad), 3));
	double primevertica =
		earth_radius_m / sqrt(1 - daiichi_risinnritsu_2zyou * sin(latAveRad) * sin(latAveRad));

	// 4. 距離の計算
	double x = meridian * latDiff;
	double y = primevertica * cos(latAveRad) * lonDiff;

	ans = round(sqrt(x*x + y*y) / 1000.0);
	return ans;
}

int Spherical_trigonometry(double Lat1, double Lon1, double Lat2, double Lon2){
	// 球面三角法
	// http://keisan.casio.jp/exec/system/1257670779
	// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=215430
	int ans = 0;

	double Lat1_rad = toRad(Lat1);
	double Lon1_rad = toRad(Lon1);
	double Lat2_rad = toRad(Lat2);
	double Lon2_rad = toRad(Lon2);

	ans = round(EARTH_RADIUS * 
		acos(sin(Lat1_rad) * sin(Lat2_rad) + cos(Lat1_rad) * cos(Lat2_rad) * cos(Lon2_rad-Lon1_rad))
		);

	return ans;
}

int main(){
	// http://yamadarake.jp/trdi/report000001.html
	// http://www.gadgety.net/shin/web/php/distance.html
	// http://petit-noise.net/blog/%E7%B7%AF%E5%BA%A6%E7%B5%8C%E5%BA%A6%E3%81%8B%E3%82%892%E7%82%B9%E9%96%93%E3%81%AE%E8%B7%9D%E9%9B%A2%E3%82%92%E6%B1%82%E3%82%81%E3%82%8B/
	// http://emiyou3-tools.appspot.com/geocoding/distance.html
	// http://vldb.gsi.go.jp/sokuchi/surveycalc/surveycalc/bl2stf.html
	// 
	// latが緯度、lonが経度
	double Lat1, Lon1, Lat2, Lon2;
	while (cin >> Lat1 >> Lon1 >> Lat2 >> Lon2, 
		Lat1 != -1 && Lon1 != -1 && Lat2 != -1 && Lon2 != -1){
		
		//cout << Hubeny(Lat1, Lon1, Lat2, Lon2) << endl;
		cout << Spherical_trigonometry(Lat1, Lon1, Lat2, Lon2) << endl;
	}
	return 0;
}