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>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int s,sh,sm,g,gh,gm,ng[][2]={{0,5},{0,6},{1,6},{2,6}},t[][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 main(){
	while(cin>>s&&s){
		cin>>sh>>sm>>g>>gh>>gm;
		s--;g--;
		if(s>g)swap(s,g);
		int st=sh*60+sm,gt=gh*60+gm;
		int ok=1;
		rep(i,4)if(s==ng[i][0]&&g==ng[i][1])ok=0;
		if(ok&&st<=1050&&gt>=1050&&gt<=1170||st>=1050&&st<=1170&&gt>=1170)cout<<(t[s][g]/50+1)/2*50<<endl;
		else cout<<t[s][g]<<endl;
	}
}

C++: #include<iostream>
#define S 1050 //1050min = 17:30 //
#define G 1170 //1170min = 19:30 //
using namespace std;
int kiriage(int);
int main(){
	int tmp[7][7]={{0,300,500,600,700,1350},
								{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}};

	int sIC,sh,sm,gIC,gh,gm,smin,gmin,cost;
	while(cin >> sIC && sIC){
		cin >> sh >> sm >> gIC >> gh >> gm;
		smin = sh * 60 + sm;
		gmin = gh * 60 + gm;
		cout << ((((smin >= S && smin <= G) || (gmin >= S && gmin <= G)) && tmp[gIC-1][sIC-1]<=40) ?
			 		kiriage(tmp[sIC-1][gIC-1]/2) : tmp[sIC-1][gIC-1]) << endl;
	}
}
int kiriage(int cost){
	return (cost%50==0?cost:cost/50*50+50);
}

C++: #include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<climits>
using namespace std;

int cost[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 dist[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 ToMinute(int h, int m){
	return h*60 + m;
}

bool IsInTime(int h, int m){
	return ToMinute(17, 30) <= ToMinute(h, m) && ToMinute(h, m) <= ToMinute(19, 30);
}

int ToHalf(int n){
	n /= 2;
	if(n%50) n += 50 - n%50;
	return n;
}

int main(){
	int ic1, ic2, h1, h2, m1, m2;
	while(cin >> ic1, ic1){
		cin >> h1 >> m1 >> ic2 >> h2 >> m2;
		ic1--; ic2--;
		bool is_half = ( IsInTime(h1, m1) || IsInTime(h2, m2) ) && dist[ic1][ic2] <= 40;
		if(is_half) printf("%d\n", ToHalf(cost[ic1][ic2]) );
		else printf("%d\n", cost[ic1][ic2]);
	}
	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, int d){
	int t = h * 60 + m;
	return ( 17*60 + 30 <= t && t <= 19*60 + 30 && d <= 40 );
}

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,d[s][g]) || is_half(h2,m2,d[s][g]) );
		ans = flag? half(toll[s][g]) : toll[s][g] ;
		cout << ans << endl;
	}
}

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

int dist[] = {0, 6, 13, 18, 23, 43, 58};
int cost[][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 main() {
	int s, g;
	while(cin >> s, s) {
		int h, m;
		bool half = false;
		cin >> h >> m;
		if(17 * 60 + 30 <= h * 60 + m && h * 60 + m <= 19 * 60 + 30)
			half = true;
		cin >> g >> h >> m;
		if(17 * 60 + 30 <= h * 60 + m && h * 60 + m <= 19 * 60 + 30)
			half = true;

		half &= abs(dist[s-1] - dist[g-1]) <= 40;

		if(half)
			cout << ((cost[s-1][g-1] / 50) + 1) / 2 * 50 << endl;
		else
			cout << cost[s-1][g-1] << endl;
	}
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define NN 1000
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,6,0,350,450,600,1150,1500},
		{3,13,7,0,250,400,1000,1350},
		{4,18,12,5,0,250,850,1300},
		{5,23,17,10,5,0,600,1150},
		{6,43,37,30,25,20,0,500},
		{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;

    //  cout << aa[n2][n] << endl;
    // cout << time[1][0] <<" " <<time[1][1] << endl; 
    //if(time10>=17 && (time10 <=19)){
      if(time10 == 19 && time11 <= 30){disc2=1;}
      else if(time10 == 18)disc2=1;
      else if(time10 == 17 && time11>=30)disc2=1;
      // cout << "tes" << endl;
      if(aa[n2][n]<=40 && disc2==1)disc=1; //ツ湘ーツ個渉づーツ鳴楪つスツつオツづつ「ツづェツづ仕iscountツフツδ可グON
      // cout << "tes" << endl;
      //}

    mo=aa[n][n2];
    if(disc == 1){
      mo=mo/2;
      disc=0;
      if(mo%50 !=0)mo=(mo-(mo%50))+50;
    }
    cout << mo << endl;


    }


}