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 <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
//#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int dist[7][7]={
    {},
    {6},
    {13, 7},
    {18, 12, 5},
    {23, 17, 10, 5},
    {43, 37, 30, 25, 20},
    {58, 52, 45, 40, 35, 15}
};
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},
    {}
};

int main(){
    int a, b;
    int s, t;
    int h, m;
    while(cin>>a && a){
        cin>>h>>m;
        s = h * 60 + m;
        cin>>b>>h>>m;
        t = h *60 + m;

        a--; b--;
        if(a> b) swap(a, b);
        bool f = true;
        if(dist[b][a] > 40) f=false;
        if(f&&((s>=17*60+30&&s<=19*60+30)||(t>=17*60+30&&t<=19*60+30))){
            cout<<(cost[a][b]/100)/2*100+(cost[a][b]%100==50?50:0)<<endl;
        }
        else{
            cout<<cost[a][b]<<endl;
        }
        //cout<<a<<" "<<b<<endl;
    }
}

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

int l[7]={0,6,13,18,23,43,58};
int co[7][7]={
	0,300,500,600,700,1350,1600,
	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,
	1600,1500,1350,1300,1150,500,0
};
int main(void){
	int s[2],h[2],m[2];
	int f[2];
	int ans;
	while(1){
		scanf("%d",&s[0]);
		if(s[0]==0)break;
		scanf("%d%d",&h[0],&m[0]);
		scanf("%d",&s[1]);
		scanf("%d%d",&h[1],&m[1]);
		for(int i=0;i<2;i++){
			if(h[i]<17 || h[i]==17 && m[i]<=30)f[i]=0;
			else if(h[i]<19 || h[i]==19 && m[i]<=30)f[i]=1;
			else f[i]=2;
		}
		ans=co[s[0]-1][s[1]-1];
		if((f[0]==1 || f[1]==1) && abs(l[s[1]-1]-l[s[0]-1])<=40)ans=(co[s[0]-1][s[1]-1]+50)/100*50;
		printf("%d\n",ans);
	}
    return 0;
}

C++: #include<iostream>

using namespace std;

int main()
{
	int dis_lst[]={0,0,6,13,18,23,43,58};
	int prc_lst[7][8]={{},
		{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},
	};

	for(int ic1,h1,m1,ic2,h2,m2;cin>>ic1>>h1>>m1>>ic2>>h2>>m2,ic1;){
		if(ic1>ic2)	swap(ic1,ic2);
		int dis=dis_lst[ic2]-dis_lst[ic1];

		bool harf=false;
		if(dis<=40
		&&((60*17+30<=60*h1+m1 && 60*h1+m1<=60*19+30)
		|| (60*17+30<=60*h2+m2 && 60*h2+m2<=60*19+30)))	harf=true;

		int prc=prc_lst[ic1][ic2];
		if(harf){
			prc/=2;
			if(prc%50>0)	prc+=50-prc%50;
		}

		cout<<prc<<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;

    //  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(bb[n2-1][n-1]<=40 && disc2==1)disc=1; //ツ湘ーツ個渉づーツ鳴楪つスツつオツづつ「ツづェツづ仕iscountツフツδ可グON
      // cout << "tes" << endl;
      //}

    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 <bits/stdc++.h>
using namespace std;
const int dx[]={0,1,0,-1,1,-1,-1,1};
const int dy[]={-1,0,1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-15;
#define PB push_back
#define mk make_pair
#define fi first
#define se second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
typedef pair<int,int> Pii;
typedef pair<int,Pii> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
	int s,d;
	int score[][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 dist[][7]={{0,6,13,18,23,43,58},
					{0,0,7,12,17,37,52},
				 	{0,0,0,5,10,30,45},
					{0,0,0,0,5,25,40},
				 	{0,0,0,0,0,20,35},
					{0,0,0,0,0,0,15}};
	while(scanf("%d",&s),s){
		int hs,ms;
		scanf("%d%d",&hs,&ms);

		int hd,md;
		scanf("%d",&d);
		scanf("%d%d",&hd,&md);

		s--;d--;
		if(s>d)swap(s,d);

		if(1050 <= hs*60+ms && hs*60+ms <= 1170){
			if(dist[s][d]<=40){
				int ret = score[s][d];
				ret /= 2;
				if(ret%10){
					ret+=25;
				}
				printf("%d\n",ret);
			}
			else{
				printf("%d\n",score[s][d]);
			}
		}
		else if(1050 <= hd*60+md && hd*60+md <= 1170){
			if(dist[s][d]<=40){
				int ret = score[s][d];
				ret /= 2;
				if(ret%10){
					ret+=25;
				}
				printf("%d\n",ret);
			}
			else{
				printf("%d\n",score[s][d]);	
			}
		}
		else{
			printf("%d\n",score[s][d]);
		}
	}
    return 0;
}