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 <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){
    long double x1=cos(M_PI/180*a)*cos(M_PI/180*b),
      y1=cos(M_PI/180*a)*sin(M_PI/180*b),
      z1=sin(M_PI/180*a),
      x2=cos(M_PI/180*c)*cos(M_PI/180*d),
      y2=cos(M_PI/180*c)*sin(M_PI/180*d),
      z2=sin(M_PI/180*c);

    long double ang=(x1*x2+y1*y2+z1*z2);
    long double the=acos(ang);
    printf("%.0Lf\n",the*6378.1);
  }
}

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

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

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

    double s = acos( sin(an)*sin(bn) + cos(an)*cos(bn)*cos(ae-be) ); 
    int ans = r*s + 0.5;
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<utility>
#include<cmath>
#include<sstream>
using namespace std;
#define all(a) a.begin(),a.end()
typedef vector<int> vi;

int main()
{
	double a,b,c,d;
	const double r = 6378.1;
	while(cin>>a>>b>>c>>d&&b>0)
	{
		a*=2*M_PI/360.0;
		b*=2*M_PI/360.0;
		c*=2*M_PI/360.0;
		d*=2*M_PI/360.0;
		double s=acos(cos(a)*cos(c)*cos(b-d)+sin(a)*sin(c));
		cout<<(int)(abs(r*s)+0.5)<<endl;
	}
}

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

using namespace std;

#define PI acos(-1)
#define R 6378.1
#define S(X) ((X)*(X))

int main(){
  for(;;){
    double x[2],y[2],z[2];
    for(int i=0;i<2;i++){
      double a,b;
      cin>>a>>b;
      if(a==-1&&b==-1)return 0;
      y[i]=R*sin(a/180*PI);
      x[i]=R*cos(a/180*PI)*cos(b/180*PI);
      z[i]=R*cos(a/180*PI)*sin(b/180*PI);
    }
    cout<<int(2*R*asin(sqrt(S(x[0]-x[1])+S(y[0]-y[1])+S(z[0]-z[1]))/2/R)+.5)<<endl;
  }
  return 0;
}

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

const double pi = 4 * atan(1);
const double r = 6378.1;
const double circ = 2 * r * pi;

double dist(double x1, double y1, double z1, double x2, double y2, double z2) {
    return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) + (z1-z2)*(z1-z2));
}

int main() {
    double a, b, c, d;
    while (cin >> a >> b >> c >> d, (a!=-1 || b!=-1 || c!=-1 || d!=-1)) {
        a = a * pi / 180.0;
        b = b * pi / 180.0;
        c = c * pi / 180.0;
        d = d * pi / 180.0;

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

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

        double d = dist(x1, y1, z1, x2, y2, z2);

        double angle = acos((2*r*r - d*d) / (2*r*r));
        double res = circ * angle / (2 * pi);

        cout << (int)(res + 0.5) << endl;
    }
    return 0;
}

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));
    cout << round(d) << endl;
  }
  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(){
  double a,b,c,d;
  while(cin>>a>>b>>c>>d,a>0){
    double x1=cos(M_PI/180*a)*cos(M_PI/180*b),
      y1=cos(M_PI/180*a)*sin(M_PI/180*b),
      z1=sin(M_PI/180*a),
      x2=cos(M_PI/180*c)*cos(M_PI/180*d),
      y2=cos(M_PI/180*c)*sin(M_PI/180*d),
      z2=sin(M_PI/180*c);

    double the=acos(x1*x2+y1*y2+z1*z2);
    printf("%.0f\n",the*6378.1);
  }
}