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 <string>
#include <vector>
using namespace std;

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

int main() {
    int ic1, h1, m1, ic2, h2, m2;
    while (cin >> ic1, ic1) {
        cin >> h1 >> m1 >> ic2 >> h2 >> m2;
        --ic1; --ic2;
        bool half = false;
        int start = 17 * 60 + 30;
        int end = 19 * 60 + 30;
        int t1 = h1 * 60 + m1;
        int t2 = h2 * 60 + m2;
        if (dist[ic1][ic2] <= 40) {
            if ((start <= t1 && t1 <= end) || (start <= t2 && t2 <= end)) {
                half = true;
            }
        }
        int res = tolls[ic1][ic2];
        if (half) {
            if (tolls[ic1][ic2] % 100 == 50) res += 50;
            res /= 2;
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

const int t[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 id1, h1, m1;
	int id2, h2, m2;
	while (scanf("%d", &id1), id1){
		scanf("%d %d %d %d %d", &h1, &m1, &id2, &h2, &m2);
		if (id1 > id2) swap(id1, id2);
		int t1 = h1 * 60 + m1;
		int t2 = h2 * 60 + m2;
		--id1; --id2;
		int v = t[id1][id2];
		int l = t[id2][id1];
		if (((t1 <= 17 * 60 + 30 ^ 19 * 60 + 30 <= t2) || (t1 == 17 * 60 + 30 && 19 * 60 + 30 == t2)) && l <= 40){
			v /= 2;
			int f = !!(v % 50);
			v = v / 50 * 50 + f * 50;
		}
		printf("%d\n", v);
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int table[][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 to, from;
	int d, hd, md,sd;
	int a, ha, ma,sa;
	while (cin >> d, d) {
		cin >> hd >> md;
		cin >> a >> ha >> ma;
		d--, a--;

		to = 19 * 60 * 60 + 30 * 60;
		from = 17 * 60 * 60 + 30 * 60;
		sd = hd * 60 * 60 + md * 60;
		sa = ha * 60 * 60 + ma * 60;

		if (from <= sd && to >= sa || from >= sd && to >= sa || from <= sd && to <= sa) {
			if (table[a][d] <= 40) {
				int ans = table[d][a] / 2;
				if (ans % 50 != 0)ans += 25;
				cout << ans << endl;
			}
			else cout << table[d][a] << endl;
		}
		else
			cout << table[d][a] << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
long p[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,52,45,40,35,15,0}};
long s,e,hs,ms,he,me,a,b,c;
while(cin>>s){
if(s==0)break;
cin>>hs>>ms>>e>>he>>me;
if(s>e){a=s;s=e;e=a;}
hs*=60;hs+=ms;
he*=60;he+=me;
a=(hs-1050)*(hs-1170);
b=(he-1050)*(he-1170);
if(a<=0||b<=0)c=1;else c=0;
if(p[e-1][s-1]<=40&&c==1)cout<<((p[s-1][e-1]/50+1)/2)*50<<endl;
else cout<<p[s-1][e-1]<<endl;
}
return 0;
}

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

int main(){
	int s,g,h,m,t,price;
	bool flag;
	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   }
	};
	
	while(cin >> s && s){
		flag = false;
		cin >> h >> m ;
		t = h*60 + m;
		if(t >= 17*60+30 && t <= 19*60+30){
			flag = true;
		}
		
		cin >> g;
		
		cin >> h >> m ;
		t = h*60 + m;
		if(t >= 17*60+30 && t <= 19*60+30){
			flag = true;
		}
		s--;g--;
		if(g>s)swap(s,g);
		
		price = table[g][s];
		
		if(flag && table[s][g]<= 40){
			price /=2;
			if(price%50){
				price = price - price%50 + 50;
			}
		}
		cout << price << 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++;
		if (p == 1)
		{
			ans /= 2;
			while (ans % 50)ans++;
		}
		cout << ans << endl;


	}

}