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<cstdio>
using namespace std;

int main(){
  int aa[8][8]={ {0,1,2,3,4,5,6,7},
                 {1,0,300,500,600,700,1350,1650},
		 {2,300,0,350,450,600,1150,1500},
	         {3,500,350,0,250,400,1000,1350},
	       	 {4,600,450,250,0,250,850,1300},
	       	 {5,700,600,400,250,0,600,1150},
	       	 {6,1350,1150,1000,850,600,0,500},
	       	 {7,1650,1500,1350,1300,1150,500,0}};
  int bb[8][8]={ {0,1,2,3,4,5,6,7},
		 {1,0,6,13,18,23,43,58},
		 {2,6,0,7,12,17,37,52},
		 {3,13,7,0,5,10,30,45},
		 {4,18,12,5,0,5,25,40},
		 {5,23,17,10,5,0,20,35},
		 {6,43,37,30,25,20,0,15},
		 {7,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) || (time00 == 19 && time01 <=30)){disc2=1;}
      else if(time00 == 18 || time10 == 18)disc2=1;
      else if((time10 == 17 && time11>=30) || (time00 == 17 && time01 >=30))disc2=1;
      if(bb[n2][n]<=40 && disc2==1)disc=1; 
   

    mo=aa[n][n2];
    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<iostream>
#include<algorithm>
using namespace std;
const int da[] = { 0,0,6,13,18,23,43,58 };
int f(int a, int b, bool c) {
	int p;
	if (a == 1 && b == 2)p = 300;
	else if (a == 1 && b == 3)p = 500;
	else if (a == 1 && b == 4)p = 600;
	else if (a == 1 && b == 5)p = 700;
	else if (a == 1 && b == 6)p = 1350;
	else if (a == 1 && b == 7)p = 1650;
	else if (a == 2 && b == 3)p = 350;
	else if (a == 2 && b == 4)p = 450;
	else if (a == 2 && b == 5)p = 600;
	else if (a == 2 && b == 6)p = 1150;
	else if (a == 2 && b == 7)p = 1500;
	else if (a == 3 && b == 4)p = 250;
	else if (a == 3 && b == 5)p = 400;
	else if (a == 3 && b == 6)p = 1000;
	else if (a == 3 && b == 7)p = 1350;
	else if (a == 4 && b == 5)p = 250;
	else if (a == 4 && b == 6)p = 850;
	else if (a == 4 && b == 7)p = 1300;
	else if (a == 5 && b == 6)p = 600;
	else if (a == 5 && b == 7)p = 1150;
	else if (a == 6 && b == 7)p = 500;
	else p = 114514;
	if (c)p /= 2;
	if (p % 50 != 0)p += 25;
	return p;
}
int main() {
	int a, b, c, d;
	while (cin >> a, a) {
		int h, w; cin >> h >> w;
		b = h * 100 + w;
		cin >> c;
		cin >> h >> w;
		d = h * 100 + w;
		int dis = da[max(a, c)] - da[min(a, c)];
		bool e;
		if (((1730 <= b && b <= 1930) || (1730 <= d && d <= 1930)) && dis <= 40)e = true; else e = false;
		cout << f(min(a, c), max(a, c), e) << endl;
	}
}

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

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

int l,lh,lm,a,ah,am;

int max(){
	if(l<a)
		return l;
	else
		return a;
}

int min(){
	if(l>a)
		return l;
	else
		return a;
}

int main(){
	while(true){
		cin >> l;
		if(!l)
			return 0;
		cin >> lh >> lm;
		lm+=lh*100;
		cin >> a;
		cin >> ah >> am;
		am+=ah*100;
		if(cost[min()][max()] > 40)
			cout << cost[max()][min()] << endl;
		else if(!((lm>=1730&&lm<=1930)||(am>=1730&&am<=1930)))
			cout << cost[max()][min()] << endl;
		else{
			bool flag = false;
			if((cost[max()][min()]/2)%50)
				flag = true;
			int ans = cost[max()][min()]/2-(cost[max()][min()]/2)%50;
			if(flag)
				ans+=50;
			cout << ans << endl;
		}
	}
}

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

int s2i(string a,string b){
  int h=0,m=0;
  for(int i=0;i<a.size();i++) h*=10,h+=a[i]-'0';
  for(int i=0;i<b.size();i++) m*=10,m+=b[i]-'0';
  return h*60+m;
}

int main() {
  int fee[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 D[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 s,g;
  string a[2],b[2];
  while(1 ){
    cin>> s;
    if(s==0)break;
    cin >> a[0] >> a[1];
    cin >> g;
    cin >> b[0]>>b[1];
    s--,g--;
    int ans = fee[s][g];
    int st = s2i(a[0],a[1]);
    int gt = s2i(b[0],b[1]);
    if(D[s][g]<=40 && ((60*17+30<= st&&st<=60*19+30)||(60*17+30<=gt&&gt<=60*19+30)))ans/=2;
    if(ans%50!=0) ans = (ans/50+1)*50;
    cout << ans <<endl;
  }




  return 0;
}