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>
using namespace std;

int main(){
  int sic,sh,sm,eic,eh,em,st,et,S,E,flag,ans;
  int d[8][8];
  d[1][2]=d[2][1]=300;
  d[1][3]=d[3][1]=500;
  d[1][4]=d[4][1]=600;
  d[1][5]=d[5][1]=700;
  d[1][6]=d[6][1]=1350;
  d[1][7]=d[7][1]=1650;
  d[2][3]=d[3][2]=350;
  d[2][4]=d[4][2]=450;
  d[2][5]=d[5][2]=600;
  d[2][6]=d[6][2]=1150;
  d[2][7]=d[7][2]=1500;
  d[3][4]=d[4][3]=250;
  d[3][5]=d[5][3]=400;
  d[3][6]=d[6][3]=1000;
  d[3][7]=d[7][3]=1350;
  d[4][5]=d[5][4]=250;
  d[4][6]=d[6][4]=850;
  d[4][7]=d[7][4]=1300;
  d[5][6]=d[6][5]=600;
  d[5][7]=d[7][5]=1150;
  d[6][7]=d[7][6]=500;
  S=17*3600+30*60;
  E=19*3600+30*60;
  while(1){
    cin>>sic>>sh>>sm>>eic>>eh>>em;
    if(!sic) break;
    st=sh*3600+sm*60;
    et=eh*3600+em*60;
    flag=0;
    if((S<=st&&st<=E)||(S<=et&&et<=E)) flag=1;
    ans=d[sic][eic];
    if(flag){
      int cal;
      ans/=2;
      cal=ans%100;
      if(cal%50){
	ans/=100;
	ans*=100;
	if(cal<50) ans+=50;
	else ans+=100;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

int cost[8][8] = {{},{0,0,300,500,600,700,1350,1650},
		  {0,0,0,350,450,600,1150,1500},
		  {0,0,0,0,250,400,1000,1350},
		  {0,0,0,0,0,250,850,1300},
		  {0,0,0,0,0,0,600,1150},
		  {0,0,0,0,0,0,0,500}};

int dis[8][8] = {{},{0,0,6,13,18,23,43,58},
		 {0,0,0,7,12,17,37,52},
		 {0,0,0,0,5,10,30,45},
		 {0,0,0,0,0,5,25,40},
		 {0,0,0,0,0,0,20,35},
		 {0,0,0,0,0,0,0,15}};

struct T{int ic,h,m;};
T t[2];

bool check(T in){
  if(17 < in.h && in.h < 19) return true;
  if(in.h == 17 && in.m >= 30) return true;
  if(in.h == 19 && in.m <= 30) return true;
 
  return false;
}

int solve(T from, T to){
  int ans = 0;
  bool half = (check(from)||check(to));

  int fi = from.ic,ti = to.ic;

  if(from.ic > to.ic) swap(fi,ti);

  ans = cost[fi][ti];
  
  if(half && dis[fi][ti] <= 40) ans /= 2;

  while((ans%100)%50) ans++;

  return ans;
}

int main(){

  while(cin >> t[0].ic && t[0].ic){
    cin >> t[0].h >> t[0].m;
    cin >> t[1].ic >> t[1].h >> t[1].m;
    cout << solve(t[0],t[1]) << endl;
  }
  
  return 0;
}

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

int table[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} };

int main()
{
  int sic;
  while (cin >> sic) {
    if (sic == 0)
      break;

    int sh, sm, tic, th, tm;
    cin >> sh >> sm >> tic >> th >> tm;
    --sic;
    --tic;

    bool half = false;
    if (((17*60+30 <= sh*60+sm && sh*60+sm <= 19*60+30) ||
	 (17*60+30 <= th*60+tm && th*60+tm <= 19*60+30)) &&
	table[max(sic, tic)][min(sic, tic)] <= 40)
      half = true;

    int ans = table[min(sic, tic)][max(sic, tic)];
    if (half) {
      ans /= 2;
      if (ans % 50 != 0)
	ans = ((ans+49) / 50) * 50;
    }
    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;

typedef pair<int, int> P;

int main() {
	vector< vector<P> > data(8, vector<P>(8, P(0, 0)));
	data[1][2] = data[2][1] = P(6, 300);
	data[1][3] = data[3][1] = P(13, 500);
	data[1][4] = data[4][1] = P(18, 600);
	data[1][5] = data[5][1] = P(23, 700);
	data[1][6] = data[6][1] = P(43, 1350);
	data[1][7] = data[7][1] = P(58, 1650);
	data[2][3] = data[3][2] = P(7, 350);
	data[2][4] = data[4][2] = P(12, 450);
	data[2][5] = data[5][2] = P(17, 600);
	data[2][6] = data[6][2] = P(37, 1150);
	data[2][7] = data[7][2] = P(52, 1500);
	data[3][4] = data[4][3] = P(5, 250);
	data[3][5] = data[5][3] = P(10, 400);
	data[3][6] = data[6][3] = P(30, 1000);
	data[3][7] = data[7][3] = P(45, 1350);
	data[4][5] = data[5][4] = P(5, 250);
	data[4][6] = data[6][4] = P(25, 850);
	data[4][7] = data[7][4] = P(40, 1300);
	data[5][6] = data[6][5] = P(20, 600);
	data[5][7] = data[7][5] = P(35, 1150);
	data[6][7] = data[7][6] = P(15, 500);
	int s, g;
	while (cin >> s) {
		if (s == 0) {
			break;
		}
		int sh, sm;
		cin >> sh >> sm;
		int gh, gm;
		cin >> g;
		cin >> gh >> gm;
		int mm = data[s][g].second;
		bool hantei = true;
		if (data[s][g].first <= 40) {
		if (sh == 18) {
			if (mm % 100 == 50) {
				mm += 50;
			}
			mm /= 2;
			hantei = false;
		} else if (sh == 17) {
			if (sm >= 30) {
				if (mm % 100 == 50) {
					mm += 50;
				}
				mm /= 2;
				hantei = false;
			}
		} else if (sh == 19) {
			if (sm <= 30) {
				if (mm % 100 == 50) {
					mm += 50;
				}
				mm /= 2;
				hantei = false;
			}
		}
		if (hantei) {
			if (gh == 18) {
				if (mm % 100 == 50) {
					mm += 50;
				}
				mm /= 2;
			} else if (gh == 17) {
				if (gm >= 30) {
					if (mm % 100 == 50) {
						mm += 50;
					}
					mm /= 2;
				}
			} else if (gh == 19) {
				if (gm <= 30) {
					if (mm % 100 == 50) {
						mm += 50;
					}
					mm /= 2;
				}
			}
		}
		}
		cout << mm << endl;
	}
	return 0;
}

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

using namespace std;

int cost[8][8] = {{},{0,0,300,500,600,700,1350,1650},
		  {0,0,0,350,450,600,1150,1500},
		  {0,0,0,0,250,400,100,1350},
		  {0,0,0,0,0,250,850,1300},
		  {0,0,0,0,0,0,600,1150},
		  {0,0,0,0,0,0,0,500}};

int dis[8][8] = {{},{0,0,6,13,18,23,43,58},
		 {0,0,0,7,12,17,37,52},
		 {0,0,0,0,5,10,30,45},
		 {0,0,0,0,0,5,25,40},
		 {0,0,0,0,0,0,20,35},
		 {0,0,0,0,0,0,0,15}};

struct T{int ic,h,m;};
T t[2];

bool check(T in){
  if(17 < in.h && in.h < 19) return true;
  if(in.h == 17 && in.m >= 30) return true;
  if(in.h == 19 && in.m <= 30) return true;
 
  return false;
}

int solve(T from, T to){
  int ans = 0;
  bool half = (check(from)||check(to));

  int fi = from.ic,ti = to.ic;

  if(from.ic > to.ic) swap(fi,ti);

  ans = cost[fi][ti];
  
  if(half && dis[fi][ti] <= 40) ans /= 2;

  while((ans%100)%50) ans++;

  return ans;
}

int main(){

  while(cin >> t[0].ic && t[0].ic){
    cin >> t[0].h >> t[0].m;
    cin >> t[1].ic >> t[1].h >> t[1].m;
    cout << solve(t[0],t[1]) << endl;
  }
  
  return 0;
}