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;
  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 << round(d) << endl;
  }
  return 0;
}

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

using namespace std;

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

const double PI = acos(-1);

double angToRad(double angle) {
	return angle * PI / 180.0;
}

int main() {
	double a, b, c, d;
	while (cin >> a >> b >> c >> d, a != -1.0 || b != -1.0 || c != -1.0 || d != -1.0) {
		a = angToRad(a);
		b = angToRad(b);
		c = angToRad(c);
		d = angToRad(d);
		int ans = round(6378.1 * acos(sin(a) * sin(c) + cos(a) * cos(c) * cos(d - b)));
		cout << ans << 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 2*PI*R*(theta/(2*PI));
}

main(){
  double in[4];
  while(cin>>in[0]>>in[1]>>in[2]>>in[3] && in[0] >-1){
    printf("%.0lf\n",solve(in));
  }
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

const double PI=3.1415926535;

int main() {
	double a,b,c,d;
	while(cin>>a>>b>>c>>d){
		if(a==-1&&b==-1&&c==-1&&d==-1)break;
		a=a/180*PI;
		b=b/180*PI;
		c=c/180*PI;
		d=d/180*PI;
		cout<<int(acos(cos(PI/2-a)*cos(PI/2-c)+sin(PI/2-a)*sin(PI/2-c)*cos(b-d))*6378.1+0.5)<<endl;;
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
const double R=6378.1;
double n1,w1,n2,w2;
long double cer=2*R*3.141592;
double min(double a,double b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
int main()
{
	for(;scanf("%lf%lf%lf%lf",&n1,&w1,&n2,&w2);)
	{
		if(n1==-1&&w1==-1&&n2==-1&&w2==-1)
			break;
		double a1=(max(n1,n2)-min(n1,n2));
		double a2=(max(w1,w2)-min(w1,w2));
		a1=min(a1,360.0-a1);
		a2=min(a2,360.0-a2);
		long double l1=cer*(a1/360);
		long double l2=cer*(a2/360);
		printf("%.0f\n",sqrt(l1*l1+l2*l2));
	}
	return 0;
}

C++: #include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main(){
	double a,b,c,d;
	double PI=3.14159265359;
	while(scanf("%lf%lf%lf%lf",&a,&b,&c,&d),b>-0.5){
		double x=cos(a*PI/180)*sin(b*PI/180)-cos(c*PI/180)*sin(d*PI/180);
		double y=cos(a*PI/180)*cos(b*PI/180)-cos(c*PI/180)*cos(d*PI/180);
		double z=sin(a*PI/180)-sin(c*PI/180);
		printf("%.0f\n",6378.1*2.0*asin(sqrt(x*x+y*y+z*z)/2));
	}
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<double, double> P;
typedef pair<P, double> PP;
const double R = 6378.1;

void inputP(P &p){
  double x, y; cin >>x >>y;
  p = P(x, y);
}

PP make_pp(P &p){
  PP res;
  res.first.first = R * cos(p.first) * cos(p.second);
  res.first.second = R * cos(p.first) * sin(p.second);
  res.second = R * sin(p.first);
  return res;
}

double distancePP(PP &a, PP &b){
  double x = a.first.first - b.first.first;
  double y = a.first.second - b.first.second;
  double z = a.second - b.second;
  return sqrt(x * x + y * y + z * z);
}
 
int main() {
  P a, b;
  while(cin >>a.first >>a.second >>b.first >>b.second && a != P(-1, -1) && b != P(-1, -1)){
  a.first = a.first / 180.0 * M_PI;
  a.second = a.second/ 180.0 * M_PI;
  b.first = b.first / 180.0 * M_PI;
  b.second = b.second / 180.0 * M_PI;
  PP pa = make_pp(a), pb = make_pp(b);
  double l = distancePP(pa, pb), r = (R * R + R * R - l * l) / (2 * R * R);
  cout <<(int)round(acos(r) * R) <<endl;
  }
  return 0;
}