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 <cmath>
#define r 6378.1

int main(void){
	double a,b,c,d;
	while(1){
		scanf("%lf %lf %lf %lf",&a,&b,&c,&d);
		if(b+d<-1.0)break;
		a=90.0-a;
		c=90.0-c;
		double x1=cos(b*M_PI/180.0)*sin(a*M_PI/180.0);
		double x2=cos(d*M_PI/180.0)*sin(c*M_PI/180.0);
		double y1=sin(b*M_PI/180.0)*sin(a*M_PI/180.0);
		double y2=sin(d*M_PI/180.0)*sin(c*M_PI/180.0);
		double z1=cos(a*M_PI/180.0);
		double z2=cos(c*M_PI/180.0);
		double e=sqrt(pow(x1-x2,2.0)+pow(y1-y2,2.0)+pow(z1-z2,2.0));
		double ang=acos(1.0-e*e/2.0);
		printf("%d\n",(int)(r*ang+0.5));
	}
	return 0;
}

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

#define all(c) (c).begin(),(c).end()

using namespace std;

const double R=6378.10;
const double PI=3.1415926535;
const double EPS=1e-10;
const double toRad=360.0/2.0/PI;

int main(void){
  double a,b,c,d;
  while(cin >> a >> b >> c >> d){
    if(a<0 && b<0 && c<0 && d<0)break;
    a/=toRad,b/=toRad,c/=toRad,d/=toRad;
    double ax=cos(b)*cos(a),ay=sin(b)*cos(a),az=sin(a);
    double bx=cos(d)*cos(c),by=sin(d)*cos(c),bz=sin(c);
    double D=sqrt(pow(ax-bx,2)+pow(ay-by,2)+pow(az-bz,2));
    double rad=acos(1-D*D/2);
    printf("%.0f",round(R*rad));
    cout << endl;
  }
  return 0;
}

C++: #include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  double a,b,c,d,u,v,w,x,y,z;
  while(cin>>a>>b>>c>>d&&a!=-1&&b!=-1&&c!=-1&&d!=-1){
    u=cos(M_PI*b/180)*cos(M_PI*a/180);
    v=sin(M_PI*b/180)*cos(M_PI*a/180);
    w=sin(M_PI*a/180);
    x=cos(M_PI*d/180)*cos(M_PI*c/180);
    y=sin(M_PI*d/180)*cos(M_PI*c/180);
    z=sin(M_PI*c/180);
    cout<<(int)(6378.1*acos(1-((u-x)*(u-x)+(v-y)*(v-y)+(w-z)*(w-z))/2)+0.5)<<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)

typedef struct{double x,y,z;} P;

const double R = 6378.1;
const double PI = acos(-1);


P calc(double a,double b){
  double z = R*sin(a);
  double x = R*cos(a)*cos(b),y=R*cos(a)*sin(b);
  return (P){x,y,z};
}

double dist(double a,double b,double c){
  return sqrt(a*a+b*b+c*c);
}

double rad(double sdist){
  double c = (R*R+R*R-sdist*sdist)/(2*R*R);
  return acos(c);
}

main(){
  
  while(true){
    P in[2];
    rep(i,2){
      double a,b;
      cin>>a>>b;
      if (a == -1)return false;
      a=a/180*PI;b=b/180*PI;
      in[i]=calc(a,b);
    }
    
    double sdist=dist(in[0].x-in[1].x,in[0].y-in[1].y,in[0].z-in[1].z);
    double trad =rad(sdist);
   

    double cdist=trad*R;
    printf("%.0lf\n",cdist);
    
  }
  return false;
}

C++: #include<iostream>
#include<cmath>
#include<cstdio>
#define earth 6378.1
using namespace std;
int main(){
	double n1, n2, e1, e2;
	while(cin >> n1 >> e1 >> n2 >> e2){
		if(n1==-1&&n2==-1&&e1==-1&&e2==-1) break;
		double disAB, disBC, disCA, cosC;
		disBC = M_PI*(90-n1)/180;
		disCA = M_PI*(90-n2)/180;
		cosC = cos(M_PI*(e2-e1)/180);
		disAB = acos(cos(disBC)*cos(disCA)+sin(disBC)*sin(disCA)*cosC);
		printf("%.f\n",(disAB*earth));
	}
	return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

double sq(double x){ return x*x;}

void mainmain(){
	double a,b,c,d;
	double r = 6378.1;
	double PI = M_PI;
	while(cin>>a>>b>>c>>d){
		if(a==-1&&b==-1&&c==-1&&d==-1) return;
		double aa = a / 180 * PI;
		double bb = b / 180 * PI;
		double cc = c / 180 * PI;
		double dd = d / 180 * PI;
		double x1 = r * cos(bb) * cos(aa);
		double x2 = r * cos(dd) * cos(cc);
		double y1 = r * sin(bb) * cos(aa);
		double y2 = r * sin(dd) * cos(cc);
		double z1 = r * sin(aa);
		double z2 = r * sin(cc);
		double dist = sq(x1-x2) + sq(y1-y2) + sq(z1-z2);
		double th = acos(1 - dist/2/sq(r));
		int ans = floor(th * r + 0.5);
		cout << ans << endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

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){
    D n = abs(an - bn);
    D e = abs(ae - be);
    if(e>=180) e = 360 - e;

    D d1 = sqrt( 2*r*r - 2*r*r*cos(n/180 * PI) );
    D d2 = sqrt( 2*r*r - 2*r*r*cos(e/180 * PI) );
    D d3 = sqrt(d1*d1 + d2*d2);
    D s = acos( (2*r*r - d3*d3) / 2*r*r );
    int ans = 2*r*s + 0.5;
    cout << ans << endl;
  }
}

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

#define calc(x, y) (M_PI*(y-x)/180.0)

using namespace std;

double a, b, c, d;

double solve()
{
  double s = calc(a, 90.0), t = calc(c, 90.0), u = cos(calc(b, d));

  return acos(cos(s)*cos(t)+sin(s)*sin(t)*u);
}

int main()
{
  while(cin>>a>>b>>c>>d && !(a == -1 && b == -1 && c == -1 && d == -1)){
    cout << (int)(6378.1*solve()) << endl;
  }
	
  return 0;
}