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 <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int table[7][7] = { { -1, 300, 500, 600, 700, 1350, 1650 },
{ 6, -1, 350, 450, 600, 1150, 1500 }, { 13, 7, -1, 250, 400, 1000, 1350 },
{ 18, 12, 5, -1, 250, 850, 1300 }, { 23, 17, 10, 5, -1, 600, 1150 },
{ 43, 37, 30, 25, 20, -1, 500 }, { 58, 52, 45, 40, 35, 15, -1 } };

int s, g, h1, m1, h2, m2;
int main(){
	while (cin >> s&&s){
		cin >> h1 >> m1 >> g >> h2 >> m2;
		g--;
		s--;
		if (s == g){
			cout << 0 << endl;
			continue;
		}
		if (s > g)swap(s, g);
		int sum; 
		if (table[g][s] <= 40){
			if (h1 < 17 || (h1 == 17 && m1 <= 30)){
				if (h2 < 19 || (h2 == 19 && m2 < 30)){
					if (table[s][g] / 2 % 50 == 0){
						sum = table[s][g] / 2 / 50 * 50;
					}
					else {
						sum = table[s][g] / 2 / 50 * 50 + 50;
					}
				}
				else {
					sum = table[s][g];
				}
			}
			else if (h1 > 17 || (h1 == 17 && m1 > 30)){
				if (h2 > 19 || (h2 == 19 && m2 >= 30)){
					if (table[s][g] / 2 % 50 == 0){
						sum = table[s][g] / 2 / 50 * 50;
					}
					else {
						sum = table[s][g] / 2 / 50 * 50 + 50;
					}
				}
				else{
					sum = table[s][g];
				}
			}
		}
		else sum = table[s][g];
		cout << sum << endl;
	}
}

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(){
	int inic, inh, inm, outic, outh, outm, yen, kyori;
	while(1){
		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 == 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 == 4) return 250;
		if(out == 5) return 400;
		if(out == 6) return 1000;
		if(out == 7) return 1350;
	} else if(in == 4){
		if(out == 5) return 250;
		if(out == 6) return 850;
		if(out == 7) return 1300;
	} else if(in == 5){
		if(out == 6) return 600;
		if(out == 7) return 1150;
	} else if(in == 6){
		if(out == 7) return 500;
	} else{
		cout <<"error!";
	}
}

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 == 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 == 4) return 5;
		if(out == 5) return 10;
		if(out == 6) return 30;
		if(out == 7) return 45;
	} else if(in == 4){
		if(out == 5) return 5;
		if(out == 6) return 25;
		if(out == 7) return 40;
	} else if(in == 5){
		if(out == 6) return 20;
		if(out == 7) return 35;
	} else if(in == 6){
		if(out == 7) return 15;
	} else{
		cout <<"error!";
	}
}

int checkhalf(int ih, int im, int oh, int om, int dis){
	int flag1 = 0, flag2 = 0;
	if(dis > 40) return 0;
	
	if(ih < 17 || (ih == 17 && im <= 30)){
		if(oh - 17 > 0 || (oh == 17 && om >= 30)){
			flag1 = 1;
		}
	}
	
	if(ih < 19 || (ih == 19 && im <= 30)){
		if(oh - 19 > 0 || (oh == 19 && om >= 30)){
			flag2 = 1;
		}
	}
	
	if((flag1 && flag2) || (!flag1 && !flag2)) return 0;
	else if((flag1 && !flag2) || (!flag1 && flag2)) return 1;
}

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

C++: #include <cstdio>
#include <cmath>

const int price[7][7] = {
  {-1,300,500,600,700,1350,1650},
  {-1,-1,350,450,600,1150,1500},
  {-1,-1,-1,250,400,1000,1350},
  {-1,-1,-1,-1,250,850,1300},
  {-1,-1,-1,-1,-1,600,1150},
  {-1,-1,-1,-1,-1,-1,500}
};

const int dist[7][7] = {
  {-1,6,13,18,23,43,58},
  {-1,-1,7,12,17,37,52},
  {-1,-1,-1,5,10,30,45},
  {-1,-1,-1,-1,5,25,40},
  {-1,-1,-1,-1,-1,20,35},
  {-1,-1,-1,-1,-1,-1,15}
};

const int start = 17*60 + 30 , end = 19*60 + 30;

int main(){
  int sIC,sh,sm,tIC,th,tm;

  while(scanf("%d" ,&sIC) ,sIC){
    scanf("%d%d" ,&sh ,&sm);
    scanf("%d%d%d" ,&tIC ,&th ,&tm);

    sIC--; tIC--;
    bool ok1 = false,ok2 = false;
    int ssum = sh*60 + sm , tsum = th*60 + tm;

    if(!(ssum < start && tsum > end) && 
       ((ssum <= start && tsum >= start) ||
	(ssum > start && tsum >= end))) ok1 = true;

    if(dist[sIC][tIC] <= 40) ok2 = true;
 
    int ans = price[sIC][tIC];
    if(ok1 && ok2){
      ans = (ans / 50 + 1) / 2;
      ans *= 50;
    }
    
    printf("%d\n" ,ans);
  }

  return 0;
}

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;
 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');
		 f[i]=(h==18) || (h==17 && m>29) || (h==19 && m<31);
	 }
	 k=g[ic[0]][ic[1]];
	 if (!((ic[1]==6 && (ic[0]>=0 && ic[0]<3)) || (ic[0]==0 && ic[1]==5) || f[0]==f[1])) k= (k % 100)>0 ? k/2+25 : k/2;
	 cout << k << endl;
 }
return 0;
 }