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

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

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

const double PI = acos(-1);

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

C++: #include<stdio.h>
int main(void)
{
	int h,m,s;
	while(1){
		scanf("%d",&h);
		scanf("%d",&m);
		scanf("%d",&s);
		if(h == -1 && m == -1 && s == -1){
			break;
		}
		scanf("%d %1f %1f",&h,&m,&s);
	}
	return 0;
}

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)){
    a = 6378.1*solve();
    int p = 0;
    if((a-(int)a)*10 >= 5) p = 1;
    cout << (int)a+p << endl;
  }
	
  return 0;
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>

int main(void)
{
	const double radius = 6378.137;
	const double pi = acos(-1);
	double x[2], y[2];
	double dx;
	double d;
	//double p;
	char str[2048];
	
	while (1){
		int i;
		
		for (i = 0; i < 2; i++){
			scanf("%lf %lf", &y[i], &x[i]);
			
			if (x[i] == -1.0) return (0);
			
			x[i] = x[i] * pi / 180;
			y[i] = y[i] * pi / 180;
		}
		
		dx = x[1] - x[0];
		
		d = radius * acos( sin(y[0]) * sin(y[1]) + cos(y[0]) * cos(y[1]) * cos(dx) );
		//p = 90 - atan2( cos(y[0]) * tan(y[1]) - sin(y[0]) * cos(dx), sin(dx) );
		
		printf("%.0f\n", (int)(d + 0.5));
	}
	
	return 0;
}

C++: #include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#define EARTH_HANKEI 6378.1
 
int main(void) {
    double a,b,c,d;
    double ax1,ay1,ax2,ay2;
    double x1,y1,z1,x2,y2,z2;
    double cosine;
    double result;
    while(1) {
        scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
        if(a==-1 && b==-1 && c==-1 && d==-1)
			break;
        ax1=b*M_PI/180;
		ay1=a*M_PI/180;
        ax2=d*M_PI/180;
		ay2=c*M_PI/180;
        y1=cos(ay1);
		z1=sin(ay1);
        x1=y1*sin(ax1);
		y1=y1*cos(ax1);
        y2=cos(ay2);
		z2=sin(ay2);
        x2=y2*sin(ax2);
		y2=y2*cos(ax2);
        cosine=x1*x2+y1*y2+z1*z2;
        result=EARTH_HANKEI*acos(cosine);
        printf("%d\n",(int)floor(result+0.5));
    }
    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(){
  long double a,b,c,d;
  while(cin>>a>>b>>c>>d){
    if(abs(a+1)<EPS && abs(b+1)<EPS && abs(c+1)<EPS && abs(d+1)<EPS)break;
    a*=M_PI/180;
    b*=M_PI/180;
    c*=M_PI/180;
    d*=M_PI/180;
    long double the=acos(cos(M_PI/2-a)*cos(M_PI/2-c)+sin(M_PI/2-a)*sin(M_PI/2-c)*cos(d-b+2*M_PI));
    printf("%.0Lf\n",the*6378.1);
  }
}

C++: #include <stdio.h>
#include <string.h>
#include <math.h>
 
int main(void)
{
    const double radius = 6378.137;
    const double pi = acos(-1);
    double x[2], y[2];
    double dx;
    double d;
     
    while (1){
        int i;
         
        for (i = 0; i < 2; i++){
            scanf("%lf %lf", &y[i], &x[i]);
             
            if (x[i] == -1.0) return (0);
             
            x[i] = x[i] * pi / 180;
            y[i] = y[i] * pi / 180;
        }
         
        dx = x[1] - x[0];
         
        d = radius * acos( sin(y[0]) * sin(y[1]) + cos(y[0]) * cos(y[1]) * cos(dx) );
         
        printf("%.0f\n", d);
    }
     
    return 0;
}