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>
#define N 7

using namespace std;

int cost[N][N];
int dis[N][N];

void InitCost(){
  for(int i=0; i<N; i++) cost[i][i] = 0;

  cost[0][1] = 300;
  cost[0][2] = 500;
  cost[0][3] = 600;
  cost[0][4] = 700;
  cost[0][5] = 1350;
  cost[0][6] = 1650;

  cost[1][2] = 350;
  cost[1][3] = 450;
  cost[1][4] = 600;
  cost[1][5] = 1150;
  cost[1][6] = 1500;

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

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

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

  cost[5][6] = 500;

  cost[1][0] = 300;
  cost[2][0] = 500;
  cost[3][0] = 600;
  cost[4][0] = 700;
  cost[5][0] = 1350;
  cost[6][0] = 1650;

  cost[2][1] = 350;
  cost[3][1] = 450;
  cost[4][1] = 600;
  cost[5][1] = 1150;
  cost[6][1] = 1500;

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

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

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

  cost[6][5] = 500;
}

void InitDistance(){
  for(int i=0; i<N; i++) dis[i][i] = 0;

  dis[0][1] = 6;
  dis[0][2] = 13;
  dis[0][3] = 18;
  dis[0][4] = 23;
  dis[0][5] = 43;
  dis[0][6] = 58;

  dis[1][2] = 7;
  dis[1][3] = 12;
  dis[1][4] = 17;
  dis[1][5] = 37;
  dis[1][6] = 52;

  dis[2][3] = 5;
  dis[2][4] = 10;
  dis[2][5] = 30;
  dis[2][6] = 45;

  dis[3][4] = 5;
  dis[3][5] = 25;
  dis[3][6] = 40;

  dis[4][5] = 20;
  dis[4][6] = 35;

  dis[5][6] = 15;

  dis[1][0] = 6;
  dis[2][0] = 13;
  dis[3][0] = 18;
  dis[4][0] = 23;
  dis[5][0] = 43;
  dis[6][0] = 58;

  dis[2][1] = 7;
  dis[3][1] = 12;
  dis[4][1] = 17;
  dis[5][1] = 37;
  dis[6][1] = 52;

  dis[3][2] = 5;
  dis[4][2] = 10;
  dis[5][2] = 30;
  dis[6][2] = 45;

  dis[4][3] = 5;
  dis[5][3] = 25;
  dis[6][3] = 40;

  dis[5][4] = 20;
  dis[6][4] = 35;

  dis[6][5] = 15;
}

int WhatTime(int h, int m){
  if(h < 17 || (h == 17 && m < 30)) return -1;
  if(h > 19 || (h == 19 && m > 30)) return 1;
  return 0;
}

int HighwayToll(int n, int h1, int m1, int m, int h2, int m2){
  int ans;
  ans = cost[n][m];

  if(dis[n][m] <= 40){
    if((WhatTime(h1, m1) == -1 && WhatTime(h2, m2) == 0) ||
       (WhatTime(h1, m1) == 0 && WhatTime(h2, m2) == 1)){
      ans /= 2;
      if(ans%50 != 0) ans = ans - ans%50 + 50;
    }
  }
  return ans;
}

int main(){
  int n, m;
  int h1, m1, h2, m2;

  InitCost();
  InitDistance();

  while(1){
    cin >> n;
    if(n == 0) break;
    cin >> h1 >> m1;
    cin >> m;
    cin >> h2 >> m2;
    --n;
    --m;
    cout << HighwayToll(n, h1, m1, m, h2, m2) << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  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}};
  int ss = 17*60+30;
  int tt = 19*60+30;
  int s, sh, sm, t, th, tm;
  while(cin >> s, s) {
    cin >> sh >> sm >> t >> th >> tm;
    s--;t--;
    if (s>t) swap(s,t);
    int ans = table[s][t];

    int sss = sh*60+sm;
    int ttt = th*60+tm;
    if (table[t][s] <= 40) {
      if (ss<=sss&&sss<=tt || ss<=ttt&&ttt<=tt) {
        ans /= 2;
        ans = (ans + 49) / 50 * 50;
      }
    }
    cout << ans << endl;
  }
}

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

    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 <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);
		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) && l <= 40){
			v /= 2;
			int f = !!(v % 50);
			v = v / 50 * 50 + f * 50;
		}
		printf("%d\n", v);
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
	int start,finish;
	while(cin>>start,start){
		int time[2][2];
		for(int i=0;i<2;i++)cin>>time[0][i];
		cin>>finish;
		if(start>finish)swap(start,finish);
		for(int i=0;i<2;i++)cin>>time[1][i];
		int num=0,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}};
		for(int i=start-1;i<finish;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+=50-num%50;
		}
		cout<<num<<endl;
	}
}