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++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;
const int INF = (int)1e8;

int my[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,800,600,0,500},
					{1650,1500,1350,1300,1150,500,0}};

int ds[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}};

bool half(int len,int l,int r){
	if(len > 40) return false;
	const int x = 17*60+30,y=19*60+30;
	return (x <= l && l <= y) || (x <= r && r <= y);
}

int main(){
	int n;
	while(cin>>n,n){
		int nt; {int a,b; cin>>a>>b; nt = a * 60 + b; }
		int m; cin>>m;
		int mt; {int a,b; cin>>a>>b; mt = a * 60 + b; }
		int len = ds[n-1][m-1];
		bool h = half(len,nt,mt);
		int mo = my[n-1][m-1];
		if(h) mo = ((mo/50+1)/2) * 50;
		cout << mo << endl;
	}

	return 0;
}

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 iiiiiiiiii : a)cout << iiiiiiiiii << 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 (17 * 60 + 30 <= t[0] && t[0] <= 19 * 60 + 30)p++;
		if (17 * 60 + 30 <= t[1] && t[1] <= 19 * 60 + 30)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 && D <= 40)
		{
			ans /= 2;
			while (ans % 50)ans++;
		}
		cout << ans << endl;


	}

}

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

int main(){
  int aa[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 bb[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 i,j,n,time00,time01,time10,time11,n2,disc,mo;
  int disc2;
  while(1){
    disc2=0;
    disc=0; //flag
    cin >> n;
    if(n == 0)break;
    cin >> time00 >> time01;
    cin >> n2;
    cin >> time10 >> time11;

   
      if(time10 == 19 && time11 <= 30){disc2=1;}
      else if(time10 == 18)disc2=1;
      else if(time10 == 17 && time11>=30)disc2=1;
      if(bb[n2-1][n-1]<=40 && disc2==1)disc=1; //ツ湘ーツ個渉づーツ鳴楪つスツつオツづつ「ツづェツづ仕iscountツフツδ可グON
   

    mo=aa[n-1][n2-1];
    if(disc == 1){
      mo=mo/2;
      disc=0;
      disc2=0;
       if(mo%50 !=0)mo=(mo-(mo%50))+50;
    }
    cout << mo << endl;


    }
  return 0;

}

C++: #include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<vector<int>>money{
	{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 },

};
vector<int>dis{ 6,7,5,5,20,15 };

int main() {
	while (1) {
		int d; cin >> d;
		if (!d)break;
		int start,goal;
		{

			int h, m; cin >> h >> m;
			start = h * 60 + m;
		}
		int a; cin >> a;
		{

			int h, m; cin >> h >> m;
			goal = h * 60 + m;
		}
		d--; a--;
		if (d < a)swap(d, a);
		int cost = money[a][d];
		cost /= 50; 
		int distance = 0;
		for (int i = a; i < d; ++i) {
			distance += dis[i];
		}
		bool flag = false;
		if ((start <= 1170 || 1050 <= goal)&&!(start<1050&&1170<goal))flag = true;
		if (distance <= 40 && flag)cost = (cost + 1) / 2;
		cost *= 50;
		cout << cost << 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 time[2][3];
	while(cin>>time[0][0],time[0][0]){
		for(int i=1;i<3;i++)cin>>time[0][i];
		for(int i=0;i<3;i++)cin>>time[1][i];
		int num=0;
		for(int i=time[0][0];i<time[1][0];i++)num+=distance[i-1];
		bool kawa=0;
		for(int i=0;i<2&&!kawa&&num<41;i++)if(time[i][1]==18||time[i][1]==17&&time[i][2]>29||time[i][1]==19&&time[i][2]<31)kawa=1;
		num=money[time[0][0]-1][time[1][0]-time[0][0]-1];
		if(kawa){
			num/=2;
			if(num%50!=0)num+=25;
		}
		cout<<num<<endl;
	}
}