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>
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);
		cout <<"check = " <<checkhalf(inh, inm, outh, outm, kyori) <<endl;
		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){
		return 0;
	}
	
	if((ih < 17 || (ih == 17 && im <= 30)) && (oh < 19 || (oh == 19 && om < 30))){
		flag = 1;
	}
	if((ih > 17 || (ih == 17 && im > 30)) && (oh > 19 || (oh == 19 && om >= 30))){
		flag = 1;
	}
	if(ih == oh && im == om){
		flag = 0;
	}
	return flag;
}

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

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

int cost[8][8] = 
{
{},
{0,0,300,500,600,700,1350,1650},
{0,6,0,350,450,600,1150,1500},
{0,13,7,0,250,450,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}
};

int l,lh,lm,a,ah,am;

int main(){
	while(true){
		cin >> l;
		if(!l)
			return 0;
		cin >> lh >> lm;
		lm+=lh*100;
		cin >> a;
		cin >> ah >> am;
		am+=ah*100;
		if(cost[max(l,a)][min(l,a)] > 40)
			cout << cost[min(l,a)][max(l,a)] << endl;
		else if((lm>=1730&&lm<=1930)||(am>=1730&&am<=1930)){
			bool flag = false;
			if((cost[min(l,a)][max(l,a)]/2)%50)
				flag = true;
			int ans = cost[min(l,a)][max(l,a)]/2-((cost[min(l,a)][max(l,a)]/2)%50);
			if(flag)
				ans+=50;
			cout << ans << endl;
		}else
			cout << cost[min(l,a)][max(l,a)] << endl;
	}
}

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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

bool intime(int n)
{
	return 1730<=n && n<=1930;
}

pii getinfo(int src,int dst)
{
	int table[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},
	};
	src--;dst--;
	if(src>dst) swap(src,dst);
	return mp(table[dst][src],table[src][dst]);
}

int main()
{
	
	for(int n1,h1,m1,n2,h2,m2;cin>>n1,n1;){
		cin>>h1>>m1>>n2>>h2>>m2;
		int t1=h1*100+m1,t2=h2*100+m2;
		pii info=getinfo(n1,n2);
		bool harf=(intime(t1)||intime(t2))&&info.first<=40;
		if(harf){
			info.second/=2;
			info.second=(info.second+49)/50*50;
		}
		cout<<info.second<<endl;
	}
	
	return 0;
}