Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	distance_table := [][]int{
		{0, 6, 13, 18, 23, 43, 58},
		{6, 0, 7, 12, 17, 37, 52},
		{13, 7, 0, 5, 10, 30, 45},
		{18, 12, 5, 0, 5, 25, 40},
		{23, 17, 10, 5, 0, 20, 35},
		{43, 37, 30, 25, 20, 0, 15},
		{58, 52, 45, 40, 35, 15, 0},
	}
	toll_table := [][]int{
		{0, 300, 500, 600, 700, 1350, 1650},
		{300, 0, 350, 450, 600, 1150, 1500},
		{500, 350, 0, 250, 400, 1000, 1350},
		{600, 450, 250, 0, 250, 850, 1300},
		{700, 600, 400, 250, 0, 600, 1150},
		{1350, 1150, 1000, 850, 600, 0, 500},
		{1650, 1500, 1350, 1300, 1150, 500, 0},
	}
	for scanner.Scan() {
		d, _ := strconv.Atoi(scanner.Text())
		if d == 0 {
			break
		}
		d--
		scanner.Scan()
		dbuf := strings.Split(scanner.Text(), " ")
		dh, _ := strconv.Atoi(dbuf[0])
		dm, _ := strconv.Atoi(dbuf[1])
		dtime := 100*dh+dm
		scanner.Scan()
		a, _ := strconv.Atoi(scanner.Text())
		a--
		scanner.Scan()
		abuf := strings.Split(scanner.Text(), " ")
		ah, _ := strconv.Atoi(abuf[0])
		am, _ := strconv.Atoi(abuf[1])
		atime := 100*ah+am
		toll := toll_table[d][a]
		if distance_table[d][a] <= 40 &&
			1730 <= dtime && dtime <= 1930 ||
			1730 <= atime && atime <= 1930 {
				toll = ((toll/2-1)/50+1)*50
		}
		fmt.Println(toll)
	}
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int table[][7] = {{ 0, 300, 500, 600, 700, 1350, 1650},
                      { 6,   0, 350, 450, 600, 1150, 1500},
                      {13,   7,   0, 250, 400, 1000, 1350},
                      {18,  12,   5,   0, 250,  850, 1300},
                      {23,  17,  10,   5,   0,  600, 1150},
                      {43,  37,  30,  25,  20,    0,  500},
                      {58,  52,  45,  40,  35,   15,    0}};
    int a = 17 * 60 + 30;
    int b = 19 * 60 + 30;

    for(;;){
        int ic[2];
        bool half = false;
        for(int i=0; i<2; ++i){
            int h, m;
            cin >> ic[i] >> h >> m;
            if(ic[i] == 0)
                return 0;
            -- ic[i];

            m += h * 60;
            if(a <= m && m <= b)
                half = true;
        }
        if(ic[1] < ic[0])
            swap(ic[0], ic[1]);

        if(table[ic[1]][ic[0]] <= 40)
            half &= true;

        if(half){
            int x = table[ic[0]][ic[1]];
            if(x % 100 != 0)
                x += 50;
            cout << (x / 2) << endl;
        }else{
            cout << table[ic[0]][ic[1]] << endl;
        }
    }
}

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

int l[7]={0,6,13,18,23,43,58};
int co[7][7]={
	0,300,500,600,700,1350,1650,
	300,0,350,450,600,1150,1500,
	500,350,0,250,400,1000,1350,
	600,450,250,0,250,850,1300,
	700,600,400,250,0,600,1150,
	1350,1150,1000,850,600,0,500,
	1650,1500,1350,1300,1150,500,0
};
int main(void){
	int s[2],h[2],m[2];
	int f[2];
	int ans;
	while(1){
		scanf("%d",&s[0]);
		if(s[0]==0)break;
		scanf("%02d%02d",&h[0],&m[0]);
		scanf("%d",&s[1]);
		scanf("%02d%02d",&h[1],&m[1]);
		for(int i=0;i<2;i++){
			if(h[i]<17 || h[i]==17 && m[i]<=30)f[i]=0;
			else if(h[i]<19 || h[i]==19 && m[i]<=30)f[i]=1;
			else f[i]=2;
		}
		ans=co[s[0]-1][s[1]-1];
		if((f[0]==1 || f[1]==1) && abs(l[s[1]-1]-l[s[0]-1])<=40)ans=abs(co[s[0]-1][s[1]-1]+50)/100*50;
		printf("%d\n",ans);
	}
    return 0;
}

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

int main(){
  int i,j,n,a[8][8];
  a[1][2] = a[2][1] = 300;
  a[2][3] = a[3][2] = 350;
  a[6][7] = a[7][6] = a[1][3] = a[3][1] = 500;
  a[4][5] = a[5][4] = a[3][4] = a[4][3] = 250;
  a[2][4] = a[4][2] = 450;
  a[5][6] = a[6][5] = a[2][5] = a[5][2] =  a[1][4] = a[4][1] = 600;
  a[3][5] = a[5][3] = 400;
  a[5][1] = a[1][5] = 700;
  a[4][6] = a[6][4] = 850;
  a[3][6] = a[6][3] = 1000;
  a[5][7] = a[7][5] = a[2][6] = a[6][2] = 1150;
  a[3][7] = a[7][3] = a[1][6] = a[6][1] = 1350;
  a[4][7] = a[7][4] = 1300;
  a[2][7] = a[7][2] = 1500;
  a[1][7] = a[7][1] = 1650;

  while(1){
    int ic[2],h[2],m[2],t[2],ans,ans2;
    cin >> ic[0];
    if(ic[0] == 0) break;
    cin >> h[0] >> m[0];
    cin >> ic[1];
    cin >> h[1] >> m[1];

    ans = a[ic[0]][ic[1]];
    for(i=0;i<2;i++){
      if(h[i] == 17 && m[i] >= 30 || h[i] == 18 || h[i] == 19 && m[i] <= 30){
	if(ic[0] == 1 && ic[1] == 6 || ic[0] == 6 && ic[1] == 1);
	else if(ic[0] == 1 && ic[1] == 7 || ic[0] == 7 && ic[1] == 1);
	else if(ic[0] == 2 && ic[1] == 7 || ic[0] == 7 && ic[1] == 2);
	else if(ic[0] == 3 && ic[1] == 7 || ic[0] == 7 && ic[1] == 3);
	else{
	ans /= 2;
	ans2 = ans;
	while(ans2 > 50) ans2 -= 50;
	ans += 50 - ans2;
	break;
	}
      }
    }

    cout << ans << endl;

  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int mat1[7][7]={{0,6,13,18,23,43,58},{6,0,7,12,17,37,52},{13,7,0,5,10,30,45},{18,12,5,0,5,25,40},{23,17,10,5,0,20,35},{43,37,30,25,20,0,15},{58,52,45,40,35,15,0}};
  int mat2[7][7]={{0,300,500,600,700,1350,1650},{300,0,350,450,600,1150,1500},{500,350,0,250,400,1000,1350},{600,450,250,0,250,850,1300},{700,600,400,250,0,600,1150},{1350,1150,1000,850,600,0,500},{1650,1500,1350,1300,1150,500,0}};
  int j,k,d,a,md[10000],hd[10000],ma[10000],ha[10000],fare[10000];
  for(j=0;j>=0;j++){
    cin >> d;
    if(d == 0)
      break;
    cin >> hd[j] >> md[j];
    cin >> a;
    if(a == 0)
      break;
    cin >> ha[j] >> ma[j];
    fare[j] = mat2[d-1][a-1];
    if(100*hd[j]+md[j]<=1930 && 100*hd[j]+md[j]>=1730 || 100*ha[j]+ma[j]<=1930 && 100*ha[j]+ma[j]>=1730){
      if(mat1[d-1][a-1] <=40){
      fare[j] = fare[j]/2;
      if(fare[j]%10 == 5)
	fare[j] += 25;
      }}
  }
  for(k=0;k<=j;k++)
    cout << fare[k] << 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};
int dy[]={1,0,-1,0};

int ck[7][7]={{0,300,500,600,700,1350,1650},
	      {6,0,350,450,600,1150,1500},
	      {13,7,0,250,400,1000,1350},
	      {18,12,5,0,250,850,1300},
	      {23,17,10,5,0,600,1150},
	      {43,37,30,25,20,0,500},
	      {58,52,45,40,35,15,0},
};

main(){
  int eic;
  while(cin>>eic,eic){
    int eh,em,tic,th,tm;
    cin>>eh>>em>>tic>>th>>tm;
    if(eic>tic)swap(eic,tic);

    --eic,--tic;
    int kyori=ck[tic][eic];
    if(((60*eh+em>=17*60+30 && 60*eh+em<=19*60+30) ||
	(60*th+tm>=17*60+30 && 60*th+tm<=19*60+30)) &&
       kyori<=40)cout<<(ck[eic][tic]/2+49)/50*50;
       else cout<<ck[eic][tic];
       cout<<endl;
  }
}