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<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int vl[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}
    };
    int dis[7]={0,6,13,18,23,43,58};
    int t,m,pos1,pos2;
    while(scanf("%d",&pos1),pos1){
        bool flag=false;
        scanf("%d%d",&t,&m);
        t=t*100+m;
        if(t>=1730&&t<=1930)flag=true;
        scanf("%d%d%d",&pos2,&t,&m);
        t=t*100+m;
        if(t>=1730&&t<=1930)flag=true;

        if(pos1>pos2)swap(pos1,pos2);
        pos1--;pos2--;
        int ans=vl[pos1][pos2];
        if(dis[pos2]-dis[pos1]>40)flag=false;

        if(flag){
            if(ans%100){
                ans=(ans-50)/2+50;
            }
            else ans/=2;
        }
        printf("%d\n",ans);
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define NN 1000
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;


    }


}

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}};
int s,e;
long 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)*(he-1050);
b=(hs-1170)*(he-1170);
if(a<0){if(b>0)c=1;else c=0;}
else{if(b<0)c=1;else c=0;}
if(p[e-1][s-1]<=40&&c==1)cout<<(p[s-1][e-1]/50/2+1)*50<<endl;
else cout<<p[s-1][e-1]<<endl;
}
return 0;
}

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

int main() {
  int d[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}};
      
  int a,b;
  while(cin >> a && a) {
    int x[2],y[2];
    cin >> x[0] >> x[1] >> b >> y[0] >> y[1];
    a--,b--;
    if(a>b) swap(a,b);
    int m1=x[0]*60+x[1],m2=y[0]*60+y[1];
    int c=d[a][b];
    if((m1>=17*60+30&&m1<=19*60+30||m2>=17*60+30&&m2<=19*60+30)&&d[b][a]<=40) {
      c/=2;
      if(c%50) c+=50-c%50;
    }
    cout << c << endl;
  }
  return 0;
}