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;

int p[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 main () {
	int a, b;
	while (cin >> a, a) {
		int h, m;
		bool half = false;
		cin >> h >> m;
		int s = h * 60 + m;
		if (17 * 60 + 30 <= s && s < 19 * 60 + 30) half = true;
		cin >> b;
		cin >> h >> m;
		s = h * 60 + m;
		if (17 * 60 + 30 <= s && s < 19 * 60 + 30) half = true;
		a--, b--;
		int price = p[a][b];
		int dist = d[a][b];
		if (dist <= 40 && half) price /= 2;
		cout << price + (price % 50) << 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;


    }


}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <complex>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(it,c) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;
inline int toInt(string s){int v;istringstream i(s);i>>v;return v;}
template<class T> inline string toString(T x){ostringstream o;o<<x;return o.str();}
template<class T> void pv(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}
const int INF = 1000000000;
const double PI = acos(-1.0), EPS = 1e-10;

int years[] = {9, 19, 29, 39, 49, 59, INF};
const int CNT = 7;

inline int stamp(int h, int m) {
	return 60 * h + m;
}

inline int wari(int p) {
	int np = p;
	np /= 2;
	if(np % 50 != 0) np = (np - (np % 50)) + 50;
	return np;
}

// cost[a][b] (b > a)
int cost[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},
	{0, 0, 0, 0, 0, 0, 0}
};

// dist[a][b] (a > b)
int dist[7][7] = {
	{0, 0, 0, 0, 0, 0, 0},
	{6, 0, 0, 0, 0, 0, 0},
	{13, 7, 0, 0, 0, 0},
	{18, 12, 5, 0, 0, 0, 0},
	{23, 17, 10, 5, 0, 0, 0},
	{43, 37, 30, 25, 20, 0, 0},
	{58, 52, 45, 40, 35, 15, 0}
};

int main() {
#if 0
	for(int p; cin >> p;)
		cout << wari(p) << endl;
#endif

#if 1
	for(;;) {

		int from, to, from_t, to_t;
		int h, m;

		cin >> from;

		if(from == 0) break;

		cin >> h >> m;
		from_t = stamp(h, m);

		cin >> to;

		cin >> h >> m;
		to_t = stamp(h, m);

		from--, to--;

		int C = cost[min(from, to)][max(from, to)];
		int D = dist[max(from, to)][min(from, to)];

		if(D <= 40 && (stamp(17, 30) <= from_t && from_t <= stamp(19, 30)) ||
				(stamp(17, 30) <= to_t && to_t <= stamp(19, 30))) {
			C = wari(C);
		}
		cout << C << endl;
	}
#endif

	return 0;
}

C++: 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }


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

bool yes(int h, int t)
{
	if(h == 17) return 30 <= t;
	if(h == 18) return true;
	if(h == 19) return t <= 30;
	return false;
}

int main()
{
	int s, t, sh, st, th, tt;
	while(cin >> s && s)
	{
		cin >> sh >> st >> t >> th >> tt;
		int charge = table[s-1][t-1];
		
		if(table[t-1][s-1] <= 40 && (yes(sh, st) || yes(th, tt)))
		{
			charge /= 2;
			cout << charge + (charge % 50 != 0 ? 25 : 0) << endl;
		}
		else
		{
			cout << charge << endl;
		}
	}
}