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 + 50)/50*50;
			} // end if
 		}else{
				res = price[from][to];
		} // end if
		cout << res << endl;	

	} // end loop

		
	return 0;
}

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

using namespace std;

int main(){

	int u,d;
	int s = 17*60+30;
	int g = 19*60 + 30;

	int table[7][7];
	table[0][1]=300;
	table[0][2]=500;
	table[0][3]=600;
	table[0][4]=700;
	table[0][5]=1350;
	table[0][6]=1650;
	
	table[1][2]=350;
	table[1][3]=450;
	table[1][4]=600;
	table[1][5]=1150;
	table[1][6]=1500;

	table[2][3]=250;
	table[2][4]=400;
	table[2][5]=1000;
	table[2][6]=1350;

	table[3][4]=250;
	table[3][5]=850;
	table[3][6]=1300;

	table[4][5]=600;
	table[4][6]=1150;

	table[5][6]=500;

	table[1][0]=6;
	table[2][0]=13;
	table[3][0]=18;
	table[4][0]=23;
	table[5][0]=43;
	table[6][0]=58;
	
	table[2][1]=7;
	table[3][1]=12;
	table[4][1]=17;
	table[5][1]=37;
	table[6][1]=52;
	
	table[3][2]=5;
	table[4][2]=10;
	table[5][2]=30;
	table[6][2]=45;
	
	table[4][3]=5;
	table[5][3]=25;
	table[6][3]=40;
	
	table[5][4]=20;
	table[6][4]=35;
	
	table[6][5]=15;


	while(cin>>u&&u!=0){
		u--;
		int h1,m1,h2,m2;
		cin>>h1>>m1;
		cin>>d;
		d--;
		cin>>h2>>m2;
		int st=h1*60+m1;
		int gt=h2*60+m2;
		if((st>=s&&st<=g)||(gt>=s&&gt<=g)){
			// ツ板シツ額
			int idx1=min(u,d);
			int idx2=max(u,d);
			int dis=table[idx2][idx1];
			if(dis<=40){
				int mo=table[idx1][idx2]/2;
				if(mo%50!=0){
					mo-=mo%50;
					mo+=50;
				}
				cout<<mo<<endl;
			}
			else
				cout<<table[idx1][idx2]<<endl;
		}
		else{
			int idx1=min(u,d);
			int idx2=max(u,d);
			cout<<table[idx1][idx2]<<endl;
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
	int distance[]={6,7,5,5,20,15},money[6][6]={{300,500,600,700,1350,1650},{350,450,600,1150,1500},{250,400,1000,1350},{250,850,1300},{600,1150},{500}};
	int start,finish;
	while(cin>>start,start){
		int time[2][2];
		for(int i=0;i<2;i++)cin>>time[0][i];
		cin>>finish;
		for(int i=0;i<2;i++)cin>>time[1][i];
		int num=0;
		for(int i=start-1;i<finish-1;i++)num+=distance[i];
		bool kawa=0;
		for(int i=0;i<2&&!kawa&&num<41;i++)if(time[i][0]==18||time[i][0]==17&&time[i][1]>29||time[i][0]==19&&time[i][1]<31)kawa=1;
		num=money[start-1][finish-start-1];
		if(kawa){
			num/=2;
			if(num%50!=0)num+=25;
		}
		cout<<num<<endl;
	}
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n[2];
	while (cin >> n[0]&&n[0])
	{
		int t[2];
		int h, m;
		cin >> h >> m;
		t[0] = h * 60 + m;

		cin >> n[1];
		cin >> h >> m;
		t[1] = h * 60 + m;
		int x[][8] = { {0,0,0,0,0,0,0,0},{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 ans = x[min(n[0], n[1])][max(n[0], n[1])];
		int p = 0;
		if (t[0] <= 17 * 60 + 30 && 17 * 60 + 30 <= t[1])p++;
		if (t[0] <= 19 * 60 + 30 && 19 * 60 + 30 <= t[1])p++;

		int d[] = { 6,7,5,5,20,15 };
		int D = 0;
		if (n[0] > n[1])swap(n[0], n[1]);
		while (n[0] < n[1])
		{
			D += d[n[0]-1];
			n[0]++;
		}
		if (p == 1 && D <= 40)
		{
			ans /= 2;
			while (ans % 50)ans++;
		}
		cout << ans << endl;


	}

}