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<cstdlib>
#include<cmath>
using namespace std;

int charge(int in, int out);
int dist(int in, int out);
int checkhalf(int ih, int im, int oh, int om, int dis);
int half(int y);

int main(){
	while(1){
		int inic, inh, inm, outic, outh, outm, yen, kyori;
		cin >>inic;
		if(inic == 0) break;
		cin >>inh >>inm >>outic >>outh >>outm;
		
		yen = charge(inic, outic);
		kyori = dist(inic, outic);
		if(checkhalf(inh, inm, outh, outm, kyori)) yen = half(yen);
		
		cout <<yen <<endl;
	}
	return 0;
}

int charge(int in, int out){
	if(in == 1){
		if(out == 2) return 300;
		if(out == 3) return 500;
		if(out == 4) return 600;
		if(out == 5) return 700;
		if(out == 6) return 1350;
		if(out == 7) return 1650;
	} else if(in == 2){
		if(out == 1) return 300;
		if(out == 3) return 350;
		if(out == 4) return 450;
		if(out == 5) return 600;
		if(out == 6) return 1150;
		if(out == 7) return 1500;
	} else if(in == 3){
		if(out == 1) return 500;
		if(out == 2) return 350;
		if(out == 4) return 250;
		if(out == 5) return 400;
		if(out == 6) return 1000;
		if(out == 7) return 1350;
	} else if(in == 4){
		if(out == 1) return 600;
		if(out == 2) return 450;
		if(out == 3) return 250;
		if(out == 5) return 250;
		if(out == 6) return 850;
		if(out == 7) return 1300;
	} else if(in == 5){
		if(out == 1) return 700;
		if(out == 2) return 600;
		if(out == 3) return 400;
		if(out == 4) return 250;
		if(out == 6) return 600;
		if(out == 7) return 1150;
	} else if(in == 6){
		if(out == 1) return 1350;
		if(out == 2) return 1150;
		if(out == 3) return 1000;
		if(out == 4) return 850;
		if(out == 5) return 600;
		if(out == 7) return 500;
	} else if(in == 7){
		if(out == 1) return 1650;
		if(out == 2) return 1500;
		if(out == 3) return 1350;
		if(out == 4) return 1300;
		if(out == 5) return 1150;
		if(out == 6) return 500;
	}
}

int dist(int in, int out){
	if(in == 1){
		if(out == 2) return 6;
		if(out == 3) return 13;
		if(out == 4) return 18;
		if(out == 5) return 23;
		if(out == 6) return 43;
		if(out == 7) return 58;
	} else if(in == 2){
		if(out == 1) return 6;
		if(out == 3) return 7;
		if(out == 4) return 12;
		if(out == 5) return 17;
		if(out == 6) return 37;
		if(out == 7) return 52;
	} else if(in == 3){
		if(out == 1) return 13;
		if(out == 2) return 7;
		if(out == 4) return 5;
		if(out == 5) return 10;
		if(out == 6) return 30;
		if(out == 7) return 45;
	} else if(in == 4){
		if(out == 1) return 18;
		if(out == 2) return 12;
		if(out == 3) return 5;
		if(out == 5) return 5;
		if(out == 6) return 25;
		if(out == 7) return 40;
	} else if(in == 5){
		if(out == 1) return 23;
		if(out == 2) return 17;
		if(out == 3) return 10;
		if(out == 4) return 5;
		if(out == 6) return 20;
		if(out == 7) return 35;
	} else if(in == 6){
		if(out == 1) return 43;
		if(out == 2) return 37;
		if(out == 3) return 30;
		if(out == 4) return 25;
		if(out == 5) return 20;
		if(out == 7) return 15;
	} else if(in == 7){
		if(out == 1) return 58;
		if(out == 2) return 52;
		if(out == 3) return 45;
		if(out == 4) return 40;
		if(out == 5) return 35;
		if(out == 6) return 15;
	}
}

int checkhalf(int ih, int im, int oh, int om, int dis){
	int flag = 0;
	if(dis > 40){	//s£ª40kmæè·¢
		return 0;
	}
	
	if(ih > oh || (ih == oh && im > om)){	//úðÜ½¢¾
		if((ih > 17 || (ih == 17 && im >= 30)) && (ih < 19 || (ih == 19 && im <= 30))){	//üÁ½Ôª¼zÍÍàÅ
			if(oh < 17 || (oh == 17 && om < 30)){	//o½ÔªúðÜ½¢Å¼zÍÍO¾Á½
				return 1;
			}
		} else{
			return 0;
		}
		if(ih > 19 || (ih == 19 && im > 30)){	//üÁ½Ôª¼zÍÍæèàãÅ
			if((oh > 17 || (oh == 17 && om >= 30)) && (oh < 19 || (oh == 19 && om <= 30))){	//o½ÔªúðÜ½¢Å¼zÍÍà¾Á½
				return 1;
			}
		} else{
			return 0;
		}
	}
	
	if((ih < 17 || (ih == 17 && im <= 30)) && (oh > 17 || (oh == 17 && om >= 30)) && (oh < 19 || (oh == 19 && om < 30))){	//17æèO©1730ªÈOÉüèA17æèã©1730ªÈ~A©ÂA19æèO©1930ªæèOÉo½
		flag = 1;
	} else if((ih > 17 || (ih == 17 && im > 30)) && (ih < 19 || (ih == 19 && im <= 30)) && (oh > 19 || (oh == 19 && om >= 30))){	//àµ­ÍA17æèã©1730ªæèãA©ÂA19æèO©1930ªÈOÉüèA19æèã©1930ªÈ~Éo½
		flag = 1;
	}
	if(ih == oh && im == om && flag){	//flagª1ÅAüéÔÆoéÔª¯¶¾Á½
		flag = 0;
	}
	return flag;
}

int half(int y){
	int ans;
	double temp = y;
	temp /= 2.0;
	temp = ceil(temp);
	ans = (int)temp;
	if(ans % 50 != 0){
		ans = ans + abs((ans % 50) - 50);
	}
	return ans;
}

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))){
            int ans = cost[a][b];

            cout<<(cost[a][b]/100)/2*100+(cost[a][b]%100==50?50:0)+((cost[a][b]/100)%2==1?50:0)<<endl;
        }
        else{
            cout<<cost[a][b]<<endl;
        }
        //cout<<a<<" "<<b<<endl;
    }
}