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 main() {
  int p, q, h, m, s, t, u, c;
  int l = 17 * 60 + 30;
  int r = 19 * 60 + 30;
  bool b;
  int a[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}
  };

  while (1) {
    cin >> p;
    if (!p) break;
    --p;
    cin >> h >> m;
    s = 60 * h + m;
    cin >> q;
    --q;
    cin >> h >> m;
    t = 60 * h + m;
    b = false;
    if (s>=l && s<=r) b = true;
    else if (t>=l && t<=r) b = true;
    if (p > q) {
      u = p;
      p = q;
      q = u;
    }
    if (a[q][p] > 40) b = false;
    c = a[p][q];
    if (b) {
      c /= 2;
      if (c % 50) {
        c += 50 - (c % 50);
      }
    }
    cout << c << endl;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;

int toll[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 half(int x){
	if((x / 2) % 50) x += 50;
	return x / 2;
}

bool is_half(int h, int m){
	return ( h == 18 || (h == 17 && m >= 30) || (h == 19 && m <= 30) );
}

int main(){
	int s;
	while( cin >> s, s ){
		int h1, m1, h2, m2, g, ans;
		cin >> h1 >> m1 >> g >> h2 >> m2;
		s--; g--;
		bool flag = ( is_half(h1,m1) || is_half(h2,m2) );
		ans = flag? half(toll[s][g]) : toll[s][g] ;
		cout << ans << endl;
	}
}

C++: #include<iostream>
using namespace std;
int s[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 sc,sh,sm,ec,eh,em; 
  while(cin>>sc&&sc){
    cin>>sh>>sm>>ec>>eh>>em;
    int k=0,an=s[sc-1][ec-1],S=sh*100+sm,E=eh*100+em;
    if(S>E)E+=2400;
    if(S<=1730&&1730<=E)k++;
    if(S<=1930&&1930<=E)k++;
    if(2400+1730<=E)k++;
    if(2400+1930<=E)k++;
    if(s[ec-1][sc-1]<=40&&k==1)an/=2;
    if(an%50)an-=an%50,an+=50;
    cout<<an<<endl;
  }
  return 0;
}

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

using namespace std;

typedef pair<int, int> P;

int main() {
	P hyou[8][8];
	hyou[1][2] = hyou[2][1] = P(6, 300);
	hyou[1][3] = hyou[3][1] = P(13, 500);
	hyou[1][4] = hyou[4][1] = P(18, 600);
	hyou[1][5] = hyou[5][1] = P(23, 700);
	hyou[1][6] = hyou[6][1] = P(43, 1350);
	hyou[1][7] = hyou[7][1] = P(58, 1650);
	hyou[2][3] = hyou[3][2] = P(7, 350);
	hyou[2][4] = hyou[4][2] = P(12, 450);
	hyou[2][5] = hyou[5][2] = P(17, 600);
	hyou[2][6] = hyou[6][2] = P(37, 1150);
	hyou[2][7] = hyou[7][2] = P(52, 1500);
	hyou[3][4] = hyou[4][3] = P(5, 250);
	hyou[3][5] = hyou[5][3] = P(10, 400);
	hyou[3][6] = hyou[6][3] = P(30, 1000);
	hyou[3][7] = hyou[7][3] = P(45, 1350);
	hyou[4][5] = hyou[5][4] = P(5, 250);
	hyou[4][6] = hyou[6][4] = P(25, 850);
	hyou[4][7] = hyou[7][4] = P(40, 1300);
	hyou[5][6] = hyou[6][5] = P(20, 600);
	hyou[5][7] = hyou[7][5] = P(35, 1150);
	hyou[6][7] = hyou[7][6] = P(15, 500);
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int sh, sm;
		cin >> sh >> sm;
		int m;
		cin >> m;
		int gh, gm;
		cin >> gh >> gm;
		if (sh == 18 || gh == 18) {
			if (hyou[n][m].first <=  40) {
				int p = hyou[n][m].second;
				p /= 2;
				if (p % 100 == 25) {
					p += 25;
				} 
				cout << p << endl;
			} else {
				cout << hyou[n][m].second << endl;
			}
		} else if (sh == 17 || gh == 17) {
			int p = hyou[n][m].second;
			if (sh == 17) {
				if (sm >= 30) {
					if (hyou[n][m].first <= 40) {
						p /= 2;
						if (p % 100 == 25) {
							p += 25;
						}
					}
				} else if (gh == 17) {
					if (gm >= 30) {
						if (hyou[n][m].first <= 40) {
							p /= 2;
							if (p % 100 == 25) {
								p += 25;
							}
						}
					}
				} else if (gh == 19) {
					if (gm <= 30) {
						if (hyou[n][m].first <= 40) {
							p /= 2;
							if (p % 100 == 25) {
								p += 25;
							}
						}
					}
				}
			} else {
				if (gm >= 30) {
					if (hyou[n][m].first <= 40) {
						p /= 2;
						if (p % 100 == 25) {
							p += 25;
						}
					}
				}
			}
			cout << p << endl;
		} else if (sh == 19 || gh == 19) {
			int p = hyou[n][m].second;
			if (sh == 19) {
				if (sm <= 30) {
					if (hyou[n][m].first <= 40) {
						p /= 2;
						if (p % 100 == 25) {
							p += 25;
						}
					}
				}
			} else {
				if (gm <= 30) {
					if (hyou[n][m].first <= 40) {
						p /= 2;
						if (p % 100 == 25) {
							p += 25;
						}
					}
				}
			}
			cout << p << endl;
		} else {
			cout << hyou[n][m].second << endl;
		}
	}
	return 0;
}

C++: #include<stdio.h>
int d[7][7]={{0,6,10,12,14,27,33},{6,0,7,9,12,23,30},{10,7,0,5,8,20,27},{12,9,5,0,5,17,26},{14,12,8,5,0,12,23},{27,23,20,17,12,0,10},{33,30,27,26,23,10,0}};
int c[]={0,6,13,18,23,43,58};
int ABS(int a){return a<0?-a:a;}
int main(){
	int a;
	while(scanf("%d",&a),a){
		a--;
		int p,q,r,s,t;
		scanf("%d%d%d%d%d",&p,&q,&r,&s,&t);
		r--;
		int ret=d[a][r];
		if(ABS(c[a]-c[r])<=40){
			if(1050<=p*60+q&&p*60+q<=1170)ret=(ret+1)/2;
			else if(1050<=s*60+t&&s*60+t<=1170)ret=(ret+1)/2;
		}printf("%d\n",ret*50);
	}
}