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 ){
		if ( (17*60 + 30 <= em && em <= 19*60 + 30 ) 
		||   (17*60 + 30 <= dm && dm <= 19*60 + 30 ) ){ 
			int d = dist[from][to];
			if (d > 40 ){
				res = price[from][to];
			}else{
				res = (price[from][to]/2 + 49)/50*50;
			} // end if
 		}else{
				res = price[from][to];
		} // end if
		cout << res << endl;	

	} // end loop

		
	return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
 char c1[2],c2[2];
 int h,m,ic[2],f[2],i,k;
 int g[6][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}};
 while(true) {
	 for (i=0;i<2;i++) {
		 cin >> ic[i];
		 if (ic[i]==0) return 0;
		 ic[i]--;
		 cin >> c1 >> c2;
		 h=(c1[0]-'0')*10+(c1[1]-'0');
		 m=(c2[0]-'0')*10+(c2[1]-'0');
		 if ((h==18) || (h==17 && m>30) || (h==19 && m<30)) f[i]=2; 
		 else if ((h==17 && m==30) || (h==19 && m==30)) f[i]=1; else f[i]=0;
	 }
	 k=g[ic[0]][ic[1]];
	 if (!((ic[1]==6 && (ic[0]>=0 && ic[0]<3)) || (ic[0]==0 && ic[1]==5) || f[0]==f[1])) k= (k % 100)>0 ? k/2+25 : k/2;
	 cout << k << endl;
 }
return 0;
 }

C++: #include<iostream>
#include<algorithm>
#define S 1050 //1050min = 17:30 //
#define G 1170 //1170min = 19:30 //
using namespace std;
int kiriage(int);
int main(){
	int tmp[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 sIC,sh,sm,gIC,gh,gm,smin,gmin,cost;
	while(cin >> sIC && sIC){
		cin >> sh >> sm >> gIC >> gh >> gm;
		smin = sh * 60 + sm;
		gmin = gh * 60 + gm;
		if(sIC>gIC)swap(sIC,gIC);
		cout << ((((smin >= S && smin <= G) || (gmin >= S && gmin <= G)) && tmp[gIC-1][sIC-1]<=40) ?
			 		kiriage(tmp[sIC-1][gIC-1]/2) : tmp[sIC-1][gIC-1]) << endl;
	}
}
int kiriage(int cost){
	return (cost%50==0?cost:cost/50*50+50);
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-8;

struct IC{
	int fare;
	int dist;
};

int main(){
	int dpt,arv;

	struct IC ic[] = {
		300,6,
		500,13,
		600,18,
		700,23,
		1350,43,
		1650,58,

		350,7,
		450,12,
		600,17,
		1150,37,
		1500,52,

		250,5,
		400,10,
		1000,30,
		1350,45,

		250,5,
		850,25,
		1300,40,

		600,20,
		1150,35,

		500,15,
	};

	while(~scanf("%d",&dpt)){
		if(dpt==0) break;
		
		int hDpt,mDpt;
		scanf("%d %d",&hDpt,&mDpt);
		scanf("%d",&arv);
		int hArv,mArv;
		scanf("%d %d",&hArv,&mArv);

		int DptT = hDpt*60+mDpt;
		int ArvT = hArv*60+mArv;


		int idx=0;
		int fare=0,dist=0;
		for(int i=1;i<=7;i++){
			for(int j=i+1;j<=7;j++){
				if(i==dpt && j==arv){
					fare = ic[idx].fare;
					dist = ic[idx].dist;
					goto found;
				}
				idx++;
			}
		}

found:;

		if(((17*60+30 <= DptT && DptT <= 19*60+30)
			|| (17*60+30 <= ArvT && ArvT <= 19*60+30))
			&& dist <= 40){
				fare /=2;
		}

		int tmp = fare / 50;
		if(fare % 50) fare = 50 * (tmp+1);

		printf("%d\n",fare);
	}
}