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 <cstdio>
using namespace std;

bool hangaku(int x, int y){
	int max=19*60+30, min=17*60+30;
	int n=x*60+y;

	if(min<=n && n<=max) return true;
	else return false;
}

int main(){
	//料金
	int p[8][8]={0};
	p[1][2]=300; p[1][3]=500; p[1][4]=600; p[1][5]=700; p[1][6]=1350; p[1][7]=1650;
	p[2][3]=350; p[2][4]=450; p[2][5]=600; p[2][6]=1150; p[2][7]=1500;
	p[3][4]=250; p[3][5]=400; p[3][6]=1000; p[3][7]=1350;
	p[4][5]=250; p[4][6]=850; p[4][7]=1300;
	p[5][6]=600; p[5][7]=1150;
	p[6][7]=500;     
	
	for(int i=1; i<8; ++i){
		for(int j=i+1; j<8; ++j){
			p[j][i]=p[i][j];
		}
	}
	
	//半額になるかどうか
	bool half[8][8];
	for(int i=0; i<8; ++i)
		for(int j=0; j<8; ++j)
			half[i][j]=true;
			
	half[1][6]=false; half[1][7]=false; half[2][7]=false; half[3][7]=false;
	half[6][1]=false; half[7][1]=false; half[7][2]=false; half[7][3]=false;
			
	//処理
	while(1){
		int inic, outic, h1, m1, h2, m2;
		
		scanf(" %d", &inic);
		if(inic==0) break;
		
		scanf(" %d %d", &h1, &m1);
		scanf(" %d", &outic);
		scanf(" %d %d", &h2, &m2);
	
		int price=p[inic][outic];
		if(half[inic][outic]){
			if(hangaku(h1, m1) || hangaku(h2,m2)){
				price/=2;
				if(price%50!=0){
					price+=50-(price%50);	
				}
			}		
		}
		printf("%d\n", price);
	}
	return 0;
}

C++: #include<cmath>
#include<algorithm>
using namespace std;
int hyo[7][7]={
	{0,300,500,600,700,1350,1650},
	{6,0,0350,450,600,1150,1500},
	{13,7,0,250,400,1000,1350},
	{18,12,5,0,250,850,1300},
	{23,17,40,5,0,600,1150},
	{43,37,30,25,20,0,500},
	{58,52,45,40,35,15,0}
};
int main(){
	int s,g, h,m,H,M, c;
	while(cin>>s,s){
		cin>>h>>m>>g>>H>>M;
		if(s>g)swap(s,g);
		c=hyo[s-1][g-1];
		if(hyo[g-1][s-1]<=40 &&( (1050<=h*60+m&&h*60+m<=1170)||(1050<=H*60+M&&H*60+M<=1170) ) )
		c=((int)ceil((c/50)/2.0))*50;
		cout<<c<<endl;
	}
	return 0;
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto iiiiiiiiii : a)cout << iiiiiiiii << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n[2];
	while (cin >> n[0]&&n[0])
	{
		int t[2];
		int h, m;
		cin >> h >> m;
		t[0] = h * 60 + m;
		cin >> n[1];
		cin >> h >> m;
		t[1] = h * 60 + m;
		int x[][8] = { {0,0,0,0,0,0,0,0},{0,0,300,500,600,700,1350,1650},{0,0,0,350,450,600,1150,1500},{0,0,0,0,250,400,1000,1350},{0,0,0,0,0,250,850,1300},{0,0,0,0,0,0,600,1150},{0,0,0,0,0,0,0,500} };
		int ans = x[min(n[0], n[1])][max(n[0], n[1])];
		int p = 0;
		if (t[0] <= 17 * 60 + 30 && 17 * 60 + 30 <= t[1])p++;
		if (t[0] <= 19 * 60 + 30 && 19 * 60 + 30 <= t[1])p++;

		int d[] = { 6,7,5,5,20,15 };
		int D = 0;
		if (n[0] > n[1])swap(n[0], n[1]);
		while (n[0] < n[1])
		{
			D += d[n[0]-1];
			n[0]++;
		}
		if (p && D <= 40)
		{
			ans /= 2;
			while (ans % 50)ans++;
		}
		cout << ans << endl;


	}

}

C++: #include<iostream>
using namespace std;
int dist[7][7] = { {0,0,0,0,0,0,0},{6,0,0,0,0,0,0},{13,7,0,0,0,0,0},{18,12,5,0,0,0,0},{23,17,10,5,0,0,0},{43,37,30,25,20,0,0},{58,52,45,40,35,15,0} };
int money[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},{0,0,0,0,0,0,0} };
int a, b, c, d, e, f;
int main() {
	while (true) {
		cin >> a; if (a == 0) { break; }cin >> b >> c >> d >> e >> f; b = b * 60 + c; e = e * 60 + f; a--; d--;
		for (int i = 0; i < 7; i++) { for (int j = 0; j < 7; j++) { if (dist[i][j] == 0) { dist[i][j] = dist[j][i]; }if (money[i][j] == 0) { money[i][j] = money[j][i]; } } }
		if (((b >= 1050 && b <= 1170) || (e >= 1050 && e <= 1170)) && dist[a][d] <= 40) { if (money[a][d] % 100 == 0) { cout << money[a][d] / 2 << endl; } else { cout << money[a][d] / 2 + 25 << endl; } }
		else { cout << money[a][d] << endl; }
	}
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define ALL(x) (x).begin(),(x).end()
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<" :"<<x<<endl;
# define EPS 1e-12
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };

int main()
{
	int n[2];
	while (cin >> n[0]&&n[0])
	{
		int t[2];
		int h, m;
		cin >> h >> m;
		t[0] = h * 60 + m;

		cin >> n[1];
		cin >> h >> m;
		t[1] = h * 60 + m;
		int x[][8] = { {0,0,0,0,0,0,0,0},{0,0,300,500,600,700,1350,1650},{0,0,0,350,450,600,1150,1500},{0,0,0,0,250,400,1000,1350},{0,0,0,0,0,250,850,1300},{0,0,0,0,0,0,600,1150},{0,0,0,0,0,0,0,500} };
		int ans = x[min(n[0], n[1])][max(n[0], n[1])];
		int p = 0;
		if (t[0] <= 17 * 60 + 30 && 17 * 60 + 30 <= t[1])p++;
		if (t[0] <= 19 * 60 + 30 && 19 * 60 + 30 <= t[1])p++;

		int d[] = { 6,7,5,5,20,15 };
		int D = 0;
		while (n[0] < n[1])
		{
			D += d[n[0]];
			n[0]++;
		}
		if (p == 1 && D <= 40)
		{
			ans /= 2;
			while (ans % 50)ans++;
		}
		cout << ans << endl;


	}

}