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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#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)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

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

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

using namespace std;

const double PI=3.14159265358979323846264;
const double eps=1e-9;

struct Point{
	double x,y,z;
	Point(){}
	Point(double a,double b,double c):x(a),y(b),z(c){
//		printf("%f %f %f\n",x,y,z);
	}
};

Point getP(double e,double n)
{
	double theta=PI*e/180,phi=PI*n/180;
	double x1=cos(theta),y1=sin(theta);
	return Point(x1*cos(phi),y1*cos(phi),sin(phi));
}

double getAngle(Point p1,Point p2)
{
	double d=p1.x*p2.x+p1.y*p2.y+p1.z*p2.z;
	return acos(d);
}

double solve(double e1,double n1,double e2,double n2)
{
	Point p1=getP(e1,n1),p2=getP(e2,n2);
	double ang=getAngle(p1,p2);
//	printf("%f\n",ang);
	double res=6378.1*ang;
	return res;
}

int main()
{
	while(true)
	{
		double e1,n1,e2,n2;
		scanf("%lf%lf%lf%lf",&n1,&e1,&n2,&e2);
		if(e1==-1&&n1==-1&&e2==-1&&n2==-1) break;
		printf("%d\n",(int)(solve(e1,n1,e2,n2)+0.5));
	}
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	const double PI=acos(-1);
	const double r=6378.1;
	for(double a,b,c,d;cin>>a>>b>>c>>d,a!=-1;){
		double x1=r*cos(b*PI/180)*cos(a*PI/180);
		double y1=r*sin(b*PI/180)*cos(a*PI/180);
		double z1=r*sin(a*PI/180);
		double x2=r*cos(d*PI/180)*cos(c*PI/180);
		double y2=r*sin(d*PI/180)*cos(c*PI/180);
		double z2=r*sin(c*PI/180);
		double e=sqrt(pow(x1-x2,2)+pow(y1-y2,2)+pow(z1-z2,2));
		double t=acos((2*r*r-e*e)/(2*r*r));
		double dist=r*t;
		cout<<round(dist)<<endl;
	}
	
	return 0;
}

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

const D rd = M_PI/180.0;
const D r = 6378.1;

int solve(D y1, D x1, D y2, D x2){
    D x = abs(x1-x2); if(x > 180.0) x = 360.0 - x;
    D d = r * acos(sin(y1*rd)*sin(y2*rd) + cos(y1*rd)*cos(y2*rd) * cos(x*rd));
    return (int)(d + 0.5);
}

int main(){
    D a,b,c,d;
    while(cin >> a >> b >> c >> d){
        if(a < 0 && b < 0 && c < 0 && d < 0) break;
        cout << solve(a,b,c,d) << 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++: #include <stdio.h>
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
#include <math.h>
#include <queue>

using namespace std;

//I read this web page.
// http://krdlab.hatenablog.com/entry/20060322

int main(){

	double a,b,c,d,ans,r=6378.1;
	double value,x1,y1,z1,x2,y2,z2,distance;

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

		x1 = r*cos(b*M_PI/180)*cos(a*M_PI/180);
		y1 = r*sin(b*M_PI/180)*cos(a*M_PI/180);
		z1 = r*sin(a*M_PI/180);

		x2 = r*cos(d*M_PI/180)*cos(c*M_PI/180);
		y2 = r*sin(d*M_PI/180)*cos(c*M_PI/180);
		z2 = r*sin(c*M_PI/180);

		distance = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));

		value = acos(1 - (distance*distance)/(2*r*r));

		ans = r*value;

		printf("%.0lf\n",round(ans));

	}

	return 0;
}