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 T[7][7]={
	{-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}
};
main()
{
	int A;
	while(cin>>A,A)
	{
		int h,m;cin>>h>>m;m+=h*60;
		int B,m2;cin>>B>>h>>m2;m2+=h*60;
		if(A>B)A^=B^=A^=B;
		A--,B--;
		bool flag=T[B][A]<=40;
		if(!(1050<=m&&m<=1170||1050<=m2&&m2<=1170))flag=false;
		int ans=T[A][B];
		if(flag)ans>>=1;
		while(ans%50)ans++;
		cout<<ans<<endl;
	}
}

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

using namespace std;

int main(){
	
	int c[8][8];
	int d[8][8];
	
	for(int i = 0; i < 8; i++){
		for(int j = 0; j < 8; j++){
			c[i][j] = 0;
			d[i][j] = 0;
		}
	}
	
	c[1][2] = 300;
	d[1][2] = 6;
	c[1][3] = 500;
	c[2][3] = 350;
	d[1][3] = 13;
	d[2][3] = 7;
	c[1][4] = 600;
	c[2][4] = 450;
	c[3][4] = 250;
	d[1][4] = 18;
	d[2][4] = 12;
	d[3][4] = 5;
	c[1][5] = 700;
	c[2][5] = 600;
	c[3][5] = 400;
	c[4][5] = 250;
	d[1][5] = 23;
	d[2][5] = 17;
	d[3][5] = 10;
	d[4][5] = 5;
	c[1][6] = 1350;
	c[2][6] = 1150;
	c[3][6] = 1000;
	c[4][6] = 850;
	c[5][6] = 600;
	d[1][6] = 43;
	d[2][6] = 37;
	d[3][6] = 30;
	d[4][6] = 25;
	d[5][6] = 20;
	c[1][7] = 1650;
	c[2][7] = 1500;
	c[3][7] = 1350;
	c[4][7] = 1300;
	c[5][7] = 1150;
	c[6][7] = 500;
	d[1][7] = 58;
	d[2][7] = 52;
	d[3][7] = 45;
	d[4][7] = 40;
	d[5][7] = 35;
	d[6][7] = 15;
	
	for(int i = 0; i < 8; i++){
		for(int j = 0; j < 8; j++){
			c[i][j] /= 50;;
		}
	}
	
	while(true){
		
		int d1, d2;
		int h, m, time;
		
		bool is_half = false;
		bool is_half2 = false;
		
		cin >> d1;
		
		if(d1 == 0){
			break;
		}
		
		cin >> h >> m;
		
		time = h * 60 + m;
		
		if(time >= 17 * 60 + 30 && time <= 19 * 60 + 30){
			is_half = true;
		}
		
		cin >> d2;
		
		cin >> h >> m;
		
		time = h * 60 + m;
		
		if(time >= 17 * 60 + 30 && time <= 19 * 60 + 30){
			is_half = true;
		}
		
		if(d[d1][d2] <= 40){
			is_half2 = true;
		}
		
		int ans = c[d1][d2];
		
		if(is_half && is_half2){
			ans = (ans + 1) / 2;
		}
		
		cout << ans * 50 << endl;
		
	}
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)

int info[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 s, st, e, et;
	while (cin >> s, s) {
		int h, m;
		cin >> h >> m;
		st = h * 60 + m;
		cin >> e;
		cin >> h >> m;
		et = h * 60 + m;
		
		s--; e--;
		int ans = info[s][e];
		if (st >= 17*60 + 30 && st <= 19*60 + 30 || et >= 17*60 + 30 && et <= 19*60 + 30) {
			if (info[e][s] <= 40) ans = ans % 100 == 0 ? ans / 2 : (ans + 100) / 2 - (ans / 2 % 50);
		}
		
		cout << ans << endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
  int f,t;
  int dis[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},
		    {58,52,45,40,35,15, 0} };
  int fee[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 h,m;
  bool flag;
  int ans;

  while(1){
    cin >> f;
    if(!f)break;
    f--;

    flag = false;
    cin >> h >> m;
    if(h==17 && m>=30)flag = true;
    else if(h == 18)flag = true;
    else if(h==19 && m<=30)flag = true;

    cin >> t;
    t--;
    cin >> h >> m;
    if(h==17 && m>=30)flag = true;
    else if(h == 18)flag = true;
    else if(h==19 && m<=30)flag = true;

    ans = fee[f][t];
    if(flag && dis[f][t]<=40){
      ans /= 2;
      if(ans != (ans/50)*50)ans = (ans/50 + 1)*50;
    }
    cout << ans << endl;
  }
}

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) || (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;
 
const int price[7][7] = {
    {-1, 300, 500, 600, 700, 1350, 1650},
    {-1, -1, 350, 450, 600, 1150, 1500},
    {-1, -1, -1, 250, 400, 1000, 1350},
    {-1, -1, -1, -1, 250, 850, 1300},
    {-1, -1, -1, -1, -1, 600, 1150},
    {-1, -1, -1, -1, -1, -1, 500}
};
 
const int dist[7][7] = {
    {-1, 6, 13, 18, 23, 43, 58},
    {-1, -1, 7, 12, 17, 37, 52},
    {-1, -1, -1, 5, 10, 30, 45},
    {-1, -1, -1, -1, 5, 25, 40},
    {-1, -1, -1, -1, -1, 20, 35},
    {-1, -1, -1, -1, -1, -1, 15}
};
 
int start = 17*60 + 30, end = 19*60 + 30;
 
int main()
{
    int sIC, sh, sm, tIC, th, tm;
 
    while (scanf("%d", &sIC) ,sIC) {
	scanf("%d%d", &sh ,&sm);
	scanf("%d%d%d", &tIC ,&th ,&tm);
 
	sIC--; tIC--;
	bool ok1 = 0, ok2 = 0;
	int ssum = sh*60 + sm, tsum = th*60 + tm;
 
	if ((start <= ssum && ssum <= end) ||
	   (start <= tsum && tsum <= end)) ok1 = 1;
 
	if (dist[sIC][tIC] <= 40) ok2 = 1;
  
	int ans = price[sIC][tIC];
	if (ok1 && ok2) {
	    ans = (ans / 50 + 1) / 2;
	    ans *= 50;
	}
	printf("%d\n" ,ans);
    }
    return 0;
}