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>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int start,startt[2],end,endt[2];
	while(1){
		cin>>start;
		if(start==0)break;
		cin>>startt[0]>>startt[1];
		cin>>end>>endt[0]>>endt[1];
		int ans;
		if(start==1){
			if(end==2)ans=300;
			else if(end==3)ans=500;
			else if(end==4)ans=600;
			else if(end==5)ans=700;
			else if(end==6)ans=1350;
			else if(end==7)ans=1650;
		}else if(start==2){
			if(end==3)ans=350;
			else if(end==4)ans=450;
			else if(end==5)ans=600;
			else if(end==6)ans=1150;
			else if(end==7)ans==1500;
		}else if(start==3){
			if(end==4)ans=250;
			else if(end==5)ans=400;
			else if(end==6)ans=1000;
			else if(end==7)ans=1350;
		}else if(start==4){
			if(end==5)ans=250;
			else if(end==6)ans=850;
			else if(end==7)ans=1300;
		}else if(start==5){
			if(end==6)ans=600;
			else if(end==7)ans=1150;
		}else if(start==6){
			if(end==7)ans=500;
		}
		if(((startt[0]*60+startt[1])>=(17*60+30) && (startt[0]*60+startt[1])<=(19*60+30)) || ((endt[0]*60+endt[1])>=(17*60+30) && (endt[0]*60+endt[1])<=(19*60+30))){
			if((start==1 && end==6) || (end==7 &&(start>0 &&start<5))){	
				cout<<ans<<endl;
			}else{
				int reans=ans/2;
				int alt=reans%50;
				if(alt>0){
					reans+=(50-alt);
				}
				cout<<reans<<endl;
			}
		}else{
			cout<<ans<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int table[][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 a = 17 * 60 + 30;
    int b = 19 * 60 + 30;

    for(;;){
        int ic[2];
        bool half = false;
        for(int i=0; i<2; ++i){
            int h, m;
            cin >> ic[i] >> h >> m;
            if(ic[i] == 0)
                return 0;
            -- ic[i];

            m += h * 60;
            if(a <= m && m <= b)
                half = true;
        }
        if(ic[1] < ic[0])
            swap(ic[0], ic[1]);

        if(table[ic[1]][ic[0]] <= 40)
            half &= true;

        if(half){
            int a = table[ic[0]][ic[1]];
            if(a % 100 != 0)
                a += 50;
            cout << (a / 2) << endl;
        }else{
            cout << table[ic[0]][ic[1]] << endl;
        }
    }
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
int main() {
 char c1[2],c2[2];
 int h,m,ic[2],f[2],i,k,a,b;
 int g[6][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}};
 while(true) {
	 for (i=0;i<2;i++) {
		 cin >> ic[i];
		 if (ic[i]==0) return 0;
		 ic[i]--;
		 cin >> c1 >> c2;
		 h=(c1[0]-'0')*10+(c1[1]-'0');
		 m=(c2[0]-'0')*10+(c2[1]-'0');
		 if (h==17 && m==30) f[i]=1; else if (h==19 && m==30) f[i]=3; else
			 if ((h==17 && m>30) || h==18 || (h==19 && m<30)) f[i]=2; else f[i]=0; 
		 }
	 k=g[ic[0]][ic[1]]; a=f[0]; b=f[1];
	 if(k<1350) 
		 if((a==0 && b==1)||(a==1 && b==2)||(a==0 && b==2)||(a==2 && b==3)||(a==2 && b==0)||(a==3 && b==0)) k=k % 100>0 ? k/2+25:k/2;
	 cout << k << endl;
 }
return 0;
 }

C++: #include<iostream>
#define N 7

using namespace std;

int cost[N][N];
int dis[N][N];

void InitCost(){
  for(int i=0; i<N; i++) cost[i][i] = 0;

  cost[0][1] = 300;
  cost[0][2] = 500;
  cost[0][3] = 600;
  cost[0][4] = 700;
  cost[0][5] = 1350;
  cost[0][6] = 1650;

  cost[1][2] = 350;
  cost[1][3] = 450;
  cost[1][4] = 600;
  cost[1][5] = 1150;
  cost[1][6] = 1500;

  cost[2][3] = 250;
  cost[2][4] = 400;
  cost[2][5] = 1000;
  cost[2][6] = 1350;

  cost[3][4] = 250;
  cost[3][5] = 850;
  cost[3][6] = 1300;

  cost[4][5] = 600;
  cost[4][6] = 1150;

  cost[5][6] = 500;

  cost[1][0] = 300;
  cost[2][0] = 500;
  cost[3][0] = 600;
  cost[4][0] = 700;
  cost[5][0] = 1350;
  cost[6][0] = 1650;

  cost[2][1] = 350;
  cost[3][1] = 450;
  cost[4][1] = 600;
  cost[5][1] = 1150;
  cost[6][1] = 1500;

  cost[3][2] = 250;
  cost[4][2] = 400;
  cost[5][2] = 1000;
  cost[6][2] = 1350;

  cost[4][3] = 250;
  cost[5][3] = 850;
  cost[6][3] = 1300;

  cost[5][4] = 600;
  cost[6][4] = 1150;

  cost[6][5] = 500;
}

void InitDistance(){
  for(int i=0; i<N; i++) dis[i][i] = 0;

  dis[0][1] = 6;
  dis[0][2] = 13;
  dis[0][3] = 18;
  dis[0][4] = 23;
  dis[0][5] = 43;
  dis[0][6] = 58;

  dis[1][2] = 7;
  dis[1][3] = 12;
  dis[1][4] = 17;
  dis[1][5] = 37;
  dis[1][6] = 52;

  dis[2][3] = 5;
  dis[2][4] = 10;
  dis[2][5] = 30;
  dis[2][6] = 45;

  dis[3][4] = 5;
  dis[3][5] = 25;
  dis[3][6] = 40;

  dis[4][5] = 20;
  dis[4][6] = 35;

  dis[5][6] = 15;

  dis[1][0] = 6;
  dis[2][0] = 13;
  dis[3][0] = 18;
  dis[4][0] = 23;
  dis[5][0] = 43;
  dis[6][0] = 58;

  dis[2][1] = 7;
  dis[3][1] = 12;
  dis[4][1] = 17;
  dis[5][1] = 37;
  dis[6][1] = 52;

  dis[3][2] = 5;
  dis[4][2] = 10;
  dis[5][2] = 30;
  dis[6][2] = 45;

  dis[4][3] = 5;
  dis[5][3] = 25;
  dis[6][3] = 40;

  dis[5][4] = 20;
  dis[6][4] = 35;

  dis[6][5] = 15;
}

int WhatTime(int h, int m){
  if(h < 17 || (h == 17 && m < 30)) return -1;
  if(h > 19 || (h == 19 && m > 30)) return 1;
  return 0;
}

int HighwayToll(int n, int h1, int m1, int m, int h2, int m2){
  int ans;
  ans = cost[n][m];

  if(dis[n][m] <= 40){
    if((WhatTime(h1, m1) == 0 && WhatTime(h2, m2) == 0) ||
       (WhatTime(h1, m1) == -1 && WhatTime(h2, m2) == 0) ||
       (WhatTime(h1, m1) == 0 && WhatTime(h2, m2) == 1)){
      ans /= 2;
      if(ans%50 != 0) ans = ans - ans%50 + 50;
    }
  }
  return ans;
}

int main(){
  int n, m;
  int h1, m1, h2, m2;

  InitCost();
  InitDistance();

  while(1){
    cin >> n;
    if(n == 0) break;
    cin >> h1 >> m1;
    cin >> m;
    cin >> h2 >> m2;
    --n;
    --m;
    cout << HighwayToll(n, h1, m1, m, h2, m2) << endl;
  }
  return 0;
}