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 <vector>

using namespace std;

typedef pair<int, int> P;

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

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

const int price[7][7] = {
  {-1,300,500,600,700,1350,1650},
  {-1,-1,350,450,600,1150,1500},
  {-1,-1,-1,250,400,1000,1350},
  {-1,-1,-1,-1,250,850,1300},
  {-1,-1,-1,-1,-1,600,1150},
  {-1,-1,-1,-1,-1,-1,500}
};

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

const int start = 17*60 + 30 , end = 19*60 + 30;

int main(){
  int sIC,sh,sm,tIC,th,tm;

  while(scanf("%d" ,&sIC) ,sIC){
    scanf("%d%d" ,&sh ,&sm);
    scanf("%d%d%d" ,&tIC ,&th ,&tm);

    sIC--; tIC--;
    bool ok1 = false,ok2 = false;
    int ssum = sh*60 + sm , tsum = th*60 + tm;

    if((start <= ssum && ssum <= end) ||
	(start <= tsum && tsum <= end)) ok1 = true;

    if(dist[sIC][tIC] <= 40) ok2 = true;
 
    int ans = price[sIC][tIC];
    if(ok1 && ok2){
      ans = (ans / 50 + 1) / 2;
      ans *= 50;
    }
    
    printf("%d\n" ,ans);
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

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

int dic, ric, h[10], m[10];

int main(){
	while (cin >> dic&&dic){
		cin >> h[0] >> m[0] >> ric >> h[1] >> m[1];
		dic--; ric--;
		int s = h[0] * 60 + m[0], e = h[1] * 60 + m[1];
		if ((s <= 17 * 60 + 30 && e >= 17 * 60 + 30 && e <= 19 * 60 + 30)
			|| (s >= 17 * 60 + 30 && s <= 19 * 60 + 30 && e >= 19 * 60 + 30)){
			if (table[ric][dic] <= 40){
				int num = table[dic][ric] / 2;
				if (num % 50 != 0){
					num += 25;
				}
				cout << num << endl;
			}
			else{
				cout << table[dic][ric] << endl;
			}
		}
		else{
			cout << table[dic][ric] << endl;
		}
	}
}

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

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

int main() {
    int s;
    while (cin >> s, s) {
        bool half = false;
        int hh, mm;
        cin >> hh >> mm;
        int time = 60 * hh + mm;
        half |= (bt <= time && time <= lt);
        int t;
        cin >> t >> hh >> mm;
        time = 60 * hh + mm;
        half |= (bt <= time && time <= lt);
        half &= (c[t][s] <= 40);
        int ans = c[s][t];
        if (half) {
            ans /= 2;
            if (ans % 50 != 0) {
                ans += 50 - (ans % 50);
            }
        }
        cout << ans << endl;
    }
}