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<algorithm>
#include<vector>

using namespace std;

int main()
{
  int data[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 s;
  for(;cin>>s,s;)
    {
      int h,m,e;
      int start,end;
      cin>>h>>m;
      start=h*60+m;
      cin>>e;
      cin>>h>>m;
      end=h*60+m;
      if(s>e)
	swap(s,e);
      s--;e--;
      int ans;
      if((start>=17*60+30||end<=19*60+30)&&data[e][s]<=40)
       ans=data[s][e]/2;
      else
	ans=data[s][e];
      for(;ans%50!=0;)
	ans++;
      cout<<ans<<endl;
    }
}

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

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define MP(a, b) make_pair(a, b)
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

int n, m;
vector<pi> s;
int dp[1024];
using namespace std;
using namespace std;
int main() {
 char c1[2],c2[2];
 int h,m,ic[2],f[2],i,k;
 int g[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}};
 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');
         f[i]=(h==17 && m>29) || (h==18) || (h==19 && m<31);  
         }
     k=g[ic[0]][ic[1]];
     if(k<1350) 
         if (f[0]+f[1]>0) k=k % 100>0 ? k/2+25:k/2;
     cout << k << endl;
 }
return 0;
 }

C++: #include<stdio.h>
#define begin 17*60+30
#define end 19*60+30
int main(void){
  int x[8][8];

  x[1][2]=300;
  x[1][3]=500;
  x[1][4]=600;
  x[1][5]=700;
  x[1][6]=1350;
  x[1][7]=1650;
  x[2][1]=6;
  x[2][3]=350;
  x[2][4]=450;
  x[2][5]=600;
  x[2][6]=1150;  
  x[2][7]=1500;
  x[3][1]=13;
  x[3][2]=7;
  x[3][4]=250;
  x[3][5]=400;
  x[3][6]=1000;
  x[3][7]=1350;
  x[4][1]=18;
  x[4][2]=12;
  x[4][3]=5;
  x[4][5]=250;
  x[4][6]=850;
  x[4][7]=1300;
  x[5][1]=23;
  x[5][2]=17;
  x[5][3]=10;
  x[5][4]=5;
  x[5][6]=600;
  x[5][7]=1150;
  x[6][1]=43;
  x[6][2]=37;
  x[6][3]=30;
  x[6][4]=25;
  x[6][5]=20;
  x[6][7]=500;
  x[7][1]=58;
  x[7][2]=52;
  x[7][3]=45;
  x[7][4]=40;
  x[7][5]=35;
  x[7][6]=15;
  
  int v,y,a,b,h,m,val;

  while(1){
    scanf("%d",&v);
    if(v==0)break;
    scanf("%d %d %d %d %d",&a,&b,&y,&h,&m);

    if(((begin<=a*60+b && a*60+b<=end )||(begin<=h*60+m && h*60+m<=end))&&x[y][v]<=40){
      val=x[v][y]/2;
      if(val%100!=0){
	if(val%100<50){
	val=val/100;
	val=val*100+50;
	}
	else if(val%100>50){
	  val=val/100;
	  val=val*100+100;
	}
      }
      printf("%d\n",val);
	}
      else printf("%d\n",x[v][y]);
}

  return 0;
}

C++: #include<iostream>
#define IC_MAX 7
using namespace std;
int main()
{
	const int val[IC_MAX][IC_MAX]={
		{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}
	};
	const int dist[IC_MAX][IC_MAX] = {
		{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}
	};

	while(true){
		int ans = 0;
		int start, end;
		int start_h, end_h, start_m, end_m;
		int start_time, end_time;
		
		cin>>start;
		if( start == 0 )
			break;
		cin>>start_h>>start_m>>end>>end_h>>end_m;
		--start;--end;
		start_time = start_h * 100 + start_m;
		end_time = end_h * 100 + end_m;

		ans = val[start][end];
		if( dist[start][end] <= 40 &&
			(1730 <= start_time && start_time <= 1930) ||
			(1730 <= end_time && end_time <= 1930) ){
				ans /= 2;
		}
		if( ans % 50 != 0 ){
			ans = (ans / 50 + 1) * 50;
		}
		cout << ans << endl;
	}
	return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

void mainmain(){
	int n1,n2;
	int a[7][7]={
		{0,6,13,18,23,43,58},
		{300,0,7,12,17,37,52},
		{500,350,0,5,10,30,45},
		{600,450,250,0,5,25,40},
		{700,600,400,250,0,20,35},
		{1350,1150,1000,850,600,0,15},
		{1650,1500,1350,1300,1150,500}
	};
	while(cin>>n1,n1){
		int m1,s1,m2,s2;
		cin>>m1>>s1;
		cin>>n2;
		cin>>m2>>s2;
		bool f1=false;
		bool f2=false;
		int t1=m1*60+s1;
		int t2=m2*60+s2;
		if(17*60+30<=t1&&t1<=19*60+30) f1=true;
		if(17*60+30<=t2&&t2<=19*60+30) f1=true;
		if(a[min(n1,n2)-1][max(n1,n2)-1]<=40) f2=true;
		if(f1&&f2){
			int ans=a[max(n1,n2)-1][min(n1,n2)-1];
			if(ans%100==0) cout<<ans/2<<endl;
			else{
				ans+=50;
				cout<<ans/2<<endl;
			}
		}
		else{
			cout<<a[max(n1,n2)-1][min(n1,n2)-1]<<endl;
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}