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


//料金2次元配列
const int wh_data[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}};

//時間入力構造体
typedef struct struct_time_input
{
	int number;
	int h;
	int m;
}S_time_input;

//半額時間
typedef struct struct_price
{
	int price_start;
	int price_end;
}S_price;

int main(void)
{
	//安い時間を宣言
	const S_price s_price = {60 * 17 + 30 , 60 * 19 + 30};

	while (true)
	{
		//入力変数
		S_time_input s_start = {0};
		S_time_input s_end = {0};
		//金
		int money = 0;
		//距離
		int length = 0;

		cin >> s_start.number;
		if (s_start.number == 0)	{	return 0;	};
		cin >> s_start.h >> s_start.m;

		cin >> s_end.number >> s_end.h >> s_end.m;

		money = wh_data[s_start.number - 1][s_end.number - 1];
		length = wh_data[s_end.number - 1][s_start.number - 1];

		//まず距離が40km以内
		if (length <= 40)
		{
			//それぞれの時間を計測
			int start_time = s_start.h * 60 + s_start.m;
			int end_time = s_end.h * 60 + s_end.m;

			//まずは範囲内
			if (start_time <= s_price.price_end && end_time >= s_price.price_start)
			{
				//両方範囲から外れているのならOUT
				if (start_time < s_price.price_start && end_time > s_price.price_end)
				{
					;
				}
				else
				{
					money /= 2;
					if (money % 50 != 0)
					{
						int sa = 0;
						sa = money % 50;
						money -= sa;
						money += 50;
					}
				}
			}
		}

		cout << money << endl;
	}

	return 0;
}

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>
using namespace std;
int main(){
	int discount[2]={17*60+30,19*60+30};
	int D[7]={0,6,13,18,23,43,58};
	int C[7][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 in,out;
	while(cin>>in,in){
		int h1,m1,h2,m2,fare;
		cin>>h1>>m1;
		cin>>out;
		cin>>h2>>m2;
		int d=D[out-1]-D[in-1];
		int min1=h1*60+m1;
		int min2=h2*60+m2;
		if((discount[0]<=min1&&min1<=discount[1])||(discount[0]<=min2&&min2<=discount[1])&&d<=40) fare=(C[in-1][out-1]/2+25)/50*50;
		else fare=C[in-1][out-1];
		cout<<fare<<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}
};

const int B = 17 * 60 + 30, E = 19 * 60 + 30;

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];
		bool f = true;
		if (l > 40) f = false;
		if (!(t1 <= B ^ E <= t2)) f = false;
		if (f){
			v /= 2;
			int f = !!(v % 50);
			v = v / 50 * 50 + f * 50;
		}
		printf("%d\n", v);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

	int sn,sh,sm,gn,gh,gm;
	while(cin >> sn && sn)
	{
		cin >> sh >> sm >> gn >> gh >> gm;

		sn--;
		gn--;
		int s = sh*100 + sm;
		int e = gh*100 + gm;

		if(s < 1730 && 1930 < e)
		{
			cout << money[gn][sn] << endl;		
		}
		else
		{
			int m = money[gn][sn];
			if(dis[gn][sn] <= 40)
			{
				if(m % 100 == 0)
				{
					cout << m/2 << endl;
				}
				else
				{
					cout << (m+50)/2 << endl;
				}
			}
			else
			{
				cout << m << endl;
			}
		}
	}
	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;


    }


}