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++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n[2];
	while (cin >> n[0]&&n[0])
	{
		int t[2];
		int h, m;
		cin >> h >> m;
		t[0] = h * 60 + m;

		cin >> n[1];
		cin >> h >> m;
		t[1] = h * 60 + m;
		int x[][8] = { {0,0,0,0,0,0,0,0},{0,0,300,500,600,700,1350,1650},{0,0,0,350,450,600,1150,1500},{0,0,0,0,250,400,1000,1350},{0,0,0,0,0,250,850,1300},{0,0,0,0,0,0,600,1150},{0,0,0,0,0,0,0,500} };
		int ans = x[min(n[0], n[1])][max(n[0], n[1])];
		int p = 0;
		if (t[0] <= 17 * 60 + 30 && 17 * 60 + 30 <= t[1])p++;
		if (t[0] <= 19 * 60 + 30 && 19 * 60 + 30 <= t[1])p++;

		int d[] = { 6,7,5,5,20,15 };
		int D = 0;
		while (n[0] < n[1])
		{
			D += d[n[0]-1];
			n[0]++;
		}
		if (p == 1 && D <= 40)
		{
			ans /= 2;
			while (ans % 50)ans++;
		}
		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 an=s[sc-1][ec-1],S=sh*100+sm,E=eh*100+em;
    if(s[ec-1][sc-1]<=40&&((S<=1730&&1730<=E&&E<1930)||(1730<S&&S<=1930&&1930<=E)))an/=2;
    if(an%50)an-=an%50,an+=50;
    cout<<an<<endl;
  }
  return 0;
}

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

int price[8][8]={
	{0,0,0,0,0,0,0,0},
	{0,0,300,500,600,700,1350,1650},
	{0,300,0,350,450,600,1150,1500},
	{0,500,350,0,250,400,1000,1350},
	{0,600,450,250,0,250,850,1300},
	{0,700,600,400,250,0,600,1150},
	{0,1350,1150,1000,850,600,0,500},
	{0,1650,1500,1350,1300,1150,500,0}
};

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

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

int main(void){
	int ts=calSec(17,30),te=calSec(19,30);
	int s,g,st,gt;

	while(cin>>s && s){
		int h,m;
		cin>>h>>m;
		st = calSec(h,m);
		cin>>g>>h>>m;
		gt = calSec(h,m);

		bool flg = false;
		if(dist[s][g]<=40 && (ts<=st && st<=te || ts<=gt && gt<=te)) flg = true;

		int ans = price[s][g];
		if(flg){
			ans /= 2;
			int rem = ans % 50;
			if(rem != 0) ans += 50 - rem;
		}

		cout<<ans<<endl;
	}

	return 0;
}

C++: 
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int start,finish;
    while(cin>>start,start){
        int time[2][2];
        for(int i=0;i<2;i++)cin>>time[0][i];
        cin>>finish;
        for(int i=0;i<2;i++)cin>>time[1][i];
        int num=0,distance[]={6,7,5,5,20,15},money[6][6]={{300,500,600,700,1350,1650},{350,450,600,1150,1500},{250,400,1000,1350},{250,850,1300},{600,1150},{500}};
        for(int i=start-1;i<finish;i++)num+=distance[i];
        bool kawa=0;
        for(int i=0;i<2&&!kawa&&num<41;i++)if(time[i][0]==18||time[i][0]==17&&time[i][1]>29||time[i][0]==19&&time[i][1]<31)kawa=1;
        num=money[start-1][finish-start-1];
        if(kawa){
            num/=2;
            if(num%100==25)num+=25;

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

struct Point{ int t, p;};

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

main(){
    Point s, d;
    int cost, h, m;
    while(1){
	cin >> s.p;
	if ( s.p == 0 ) break;
	cin >> h >> m; s.t = h*60 + m;
	cin >> d.p;
	cin >> h >> m; d.t = h*60 + m;
	cost = T[s.p][d.p];
	if ( 1050 <= s.t && s.t <= 1170 ||
	     1050 <= d.t && d.t <= 1170 ){
	    if ( T[d.p][s.p] <= 40 ) cost /=  2;
	}
	if ( cost % 50 ) cost += 25;
	cout << cost << endl;
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
	int start,finish;
	while(cin>>start,start){
		int time[2][2];
		for(int i=0;i<2;i++)cin>>time[0][i];
		cin>>finish;
		for(int i=0;i<2;i++)cin>>time[1][i];
		int num=0,distance[]={6,7,5,5,20,15},money[6][6]={{300,500,600,700,1350,1650},{350,450,600,1150,1500},{250,400,1000,1350},{250,850,1300},{600,1150},{500}};
		for(int i=start-1;i<finish;i++)num+=distance[i];
		bool kawa=0;
		for(int i=0;i<2&&!kawa&&num<41;i++)if(time[i][0]==18||time[i][0]==17&&time[i][1]>29||time[i][0]==19&&time[i][1]<31)kawa=1;
		num=money[start-1][finish-start-1];
		if(kawa){
			num/=2;
			if(num%50!=0)num+=25;
		}
		cout<<num<<endl;
	}
}

C++: //07
#include<iostream>
#include<algorithm>

#define T(h,m) ((h)*60+(m))

using namespace std;

int main(){
  for(int s;cin>>s,s;){
    int sh,sm;
    int t,th,tm;
    cin>>sh>>sm>>t>>th>>tm;
    s--;
    t--;
    int f[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}};
    int d[7][7]={{0,0,0,0,0,0,0},{6,0,0,0,0,0,0},{13,7,0,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}};
    int sum=max(f[s][t],f[t][s]);
    if(!((T(sh,sm)<T(17,30)&&T(19,30)<T(th,tm))||T(sh,sm)>T(19,30)||T(th,tm)<T(17,30))&&max(d[s][t],d[t][s])<=40){
      sum=sum/2+((sum%100==50)?25:0);
    }
    cout<<sum<<endl;
  }
  return 0;
}