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>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen
#include <stdint.h>	// require uint64_t

using namespace std;

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

	for (int i = 0; i < 7; ++i ){
		for (int j = 0; j < 7; ++j ){
			if (i != j  ){
				if (price[i][j] == 0 ){
						price[i][j] = price[j][i];
				} // end if
				if (dist[i][j] == 0 ){
					dist[i][j] = dist[j][i];
				} // end if
			} // end if
		} // en for
	} // end for  
			 
		
//	cut here before submit 
//	freopen ("testcase.highwaytoll", "r", stdin );
	int from;

	while (cin >> from && from ){
		int fromh, fromm;
		cin >> fromh >> fromm;
		int to,toh, tom;
		cin >> to >> toh >> tom;
		from--;to--;
		int res = 0;
		int em = fromh*60 + fromm;
		int dm = toh*60 + tom;

		// ツ環暗クツ妥篠湘崢づ個篠楪甘板妥堕づづ債づ按つ「
		if (em < 17*60 + 30 && dm > 19*60 + 30 ){
 				res = price[from][to];
		}else{
			int d = dist[from][to];
			if (d > 40 ){
				res = price[from][to];
			}else{
				res = (price[from][to] + 50)/50*50/2;
			} // end if
		} // end if
		cout << res << endl;	

	} // end loop

		
	return 0;
}

C++: #include<stdio.h>
int main()
{
	const int cost[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},
	},distance[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 toIndex,fromIndex,fromH,fromM,toH,toM,c,d;
	while(scanf("%d",&fromIndex),fromIndex)
	{
		scanf("%d%d%d%d%d",&fromH, &fromM, &toIndex, &toH, &toM);
		c=cost[fromIndex-1][toIndex-1];
		d=distance[fromIndex-1][toIndex-1];
		if( (
				(fromH==18 || (fromH==17&&fromM>=30) || (fromH==19&&fromM<=30)) ||
				(toH==18 || (toH==17&&toM>=30) || (toH==19&&toM<=30))
				) && d<=40)
			printf("%d\n", c%100 + c/100*50 );
		else printf("%d\n", c);
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

int cost[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 dist[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 ToMinute(int h, int m){
	return h*60 + m;
}

bool IsInTime(int h, int m){
	return ToMinute(17, 30) <= ToMinute(h, m) && ToMinute(h, m) <= ToMinute(19, 30);
}

int ToHalf(int n){
	n /= 2;
	if(n%50) n += 50 - n%50;
	return n;
}

int main(){
	int ic1, ic2, h1, h2, m1, m2;
	printf("%d\n", ToHalf(450) );
	while(cin >> ic1, ic1){
		cin >> h1 >> m1 >> ic2 >> h2 >> m2;
		ic1--; ic2--;
		bool is_half = ( IsInTime(h1, m1) || IsInTime(h2, m2) ) && dist[ic1][ic2] <= 40;
		if(is_half) printf("%d\n", ToHalf(cost[ic1][ic2]) );
		else printf("%d\n", cost[ic1][ic2]);
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int c[7][7] ={
	{0, 300, 500, 600, 700, 1350, 1650},
	{0,   0, 350, 450, 600, 1150, 1500},
	{0,   0,   0, 250, 400, 1000, 1350},
	{0,   0,   0,   0, 250,  850, 1300},
	{0,   0,   0,   0,   0,  600, 1150},
	{0,   0,   0,   0,   0,    0,  500}};
int d[6] = {6,7,5,5,20,15};
int main(){
	int s, t, h1, m1, h2, m2;
	while(cin >> s, s) {
		cin >> h1 >> m1 >> t >> h2 >> m2;
		s--, t--;
		if(s>t) swap(s,t);
		int dist = 0;
		rep(i,7) {
			if(s<=i&&i<t) dist += d[i];
		}
		if(h1*60+m1>=17*60+30 && 19*60+30>=h1*60+m1 ||
		   h2*60+m2>=17*60+30 && 19*60+30>=h2*60+m2) {
			if(dist <= 40) cout << ceil(c[s][t] / 100.0) * 50 << endl;
			else cout << c[s][t] << endl;
		} else cout << c[s][t] << endl;
	}
    return 0;
}

C++: #include<stdio.h>

int main(){

int st1,st2;

int h1,h2,m1,m2;


int n[8][8]={
{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,052,45,40,35,15,0}
};

while(1){
scanf("%d",&st1);if(st1==0)break;

scanf("%d %d",&h1,&m1);

scanf("%d",&st2);
scanf("%d %d",&h2,&m2);

int t1=100*h1+m1;int t2=100*h2+m2;

int T1=st1,T2=st2,S=0;
if(st1>=st2){T1=st2;T2=st1;}

if((t1>=1730&&t2<=1930)&&n[T2-1][T1-1]<=40)
{S=(n[T1-1][T2-1])/2;}
else S=(n[T1-1][T2-1]);

printf("%d\n",S);
}
return 0;
}