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++: //07
#include<iostream>
#include<algorithm>

#define T(h,m) ((h)*60+(m))

using namespace std;

int main(){
  for(int s;cin>>s,s;){
    int sh,sm;
    int t,th,tm;
    cin>>sh>>sm>>t>>th>>tm;
    s--;
    t--;
    int f[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 d[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}};
    int sum=max(f[s][t],f[t][s]);
    if(!((T(sh,sm)<T(17,30)&&T(19,30)<T(th,tm))||T(sh,sm)>T(19,30)||T(th,tm)<T(17,30))&&max(d[s][t],d[s][t])<=40){
      sum=sum/2+((sum%100==50)?25:0);
    }
    cout<<sum<<endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int h[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}
};
int main(){
  int n,m;
  while(cin>>n,n){
    int a,b;
    int m1,m2;
    cin>>a>>b;
    m1=a*100+b;
    cin>>m;
    cin>>a>>b;
    m2=a*100+b;
    if(n>m)swap(n,m);
    bool han=true;
    if(m2<1730||1950<m1||(m1<1730&&1930<m2))han=false;
    if((m==7&&n<4)||(m==6&&n==1))han=false;
    int ans=h[n-1][m-1];
    if(han)ans/=2;
    ans=(ans+49)-(ans+49)%50;
    cout<<ans<<endl;
  }
}

C++: #include<iostream>

int toMinute(int h, int m){
	return h * 60 + m;
}

int roundUp(int i){
	if(i % 50){
		return i - (i % 50) + 50;
	}
	return i;
}

//17*60+30 = 1050
//19*60+30 = 1170

int main(){
	int MAX_N = 7;
	int d[MAX_N+1][MAX_N+1], p[MAX_N+1][MAX_N+1];
	d[1][2] = 6;
	d[1][3] = 13;
	d[1][4] = 18;
	d[1][5] = 23;
	d[1][6] = 43;
	d[1][7] = 58;
	d[2][3] = 7;
	d[2][4] = 12;
	d[2][5] = 17;
	d[2][6] = 37;
	d[2][7] = 52;
	d[3][4] = 5;
	d[3][5] = 10;
	d[3][6] = 30;
	d[3][7] = 45;
	d[4][5] = 5;
	d[4][6] = 25;
	d[4][7] = 40;
	d[5][6] = 20;
	d[5][7] = 35;
	d[6][7] = 15;

	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;

	int a, na, ma;
	while(std::cin >> a >> na >> ma, !std::cin.eof()){
		int b, nb, mb;
		std::cin >> b >> nb >> mb;

		int min_a = toMinute(na, ma),
			min_b = toMinute(nb, mb);

		int big = (a>b)?a:b,
			small = (a<b)?a:b;

		if((1050 <= min_a && min_a <= 1170 ||
				1050 <= min_b && min_b <= 1170) &&
			 d[small][big] <= 40){
			std::cout << roundUp(p[small][big] / 2) << std::endl;
		}else{
			std::cout << p[small][big] << std::endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int v[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}};
    int a;
    while(cin >> a, a){
        int h1, m1, b, h2, m2;
        cin >> h1 >> m1 >> b >> h2 >> m2;
        a--; b--;
        if(a > b) swap(a, b);
        int p = h1*60+m1, q = h2*60+m2;
        if(v[b][a] <= 40 && ((1050 <= p && p <= 1170) || (1050 <= q && q <= 1170))){
            cout << (v[a][b]/2+49)/50*50 << "\n";
        }else {
            cout << v[a][b] << "\n";
        }
    }
    return 0;
}

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

const int t[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}
};

const int B = 17 * 60 + 30, E = 19 * 60 + 30;

int main()
{
	int id1, h1, m1;
	int id2, h2, m2;
	while (scanf("%d", &id1), id1){
		scanf("%d %d %d %d %d", &h1, &m1, &id2, &h2, &m2);
		if (id1 > id2) swap(id1, id2);
		int t1 = h1 * 60 + m1;
		int t2 = h2 * 60 + m2;
		--id1; --id2;
		int v = t[id1][id2];
		int l = t[id2][id1];
		bool f = true;
		if (l > 40) f = false;
		if ((B <= t1 && t1 <= E) || (B <= t2 && t2 <= E)){
			v /= 2;
			int f = !!(v % 50);
			v = v / 50 * 50 + f * 50;
		}
		printf("%d\n", v);
	}
	return 0;
}

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

int abs(int i)
{
  return ( i < 0 ? -i : i );
}
int km_to_yen(int km)
{
  switch(km)
  {
  case 5:
    return 250;
  case 6:
    return 300;
  case 7:
    return 350;
  case 10:
    return 400;
  case 12:
    return 450;
  case 13:
  case 15:
    return 500;
  case 17:
  case 18:
  case 20:
    return 600;
  case 23:
    return 700;
  case 25:
    return 850;
  case 30:
    return 1000;
  case 35:
  case 37:
    return 1150;
  case 40:
    return 1300;
  case 43:
  case 45:
    return 1350;
  case 52:
    return 1500;
  case 58:
    return 1650;
  }
}

int main()
{
  int ic_km[8] = { 0, 0, 6, 13, 18, 23, 43, 58, };
  while (true)
  {
    int from_num;
    int from_hour, from_min;
    cin >> from_num;
    if ( from_num == 0 ) break;
    cin >> from_hour >> from_min;
    int from_time = from_hour*100 + from_min;

    int to_num;
    int to_hour, to_min;
    cin >> to_num;
    cin >> to_hour >> to_min;
    int to_time = to_hour*100 + to_min;

    int km_diff = abs(ic_km[to_num] - ic_km[from_num]);
    int fare = km_to_yen(km_diff);
    if ( ( ( 1730 <= from_time && from_time <= 1930 ) ||
           ( 1730 <= to_time   && to_time   <= 1930 ) ) &&
         ( km_diff <= 40 ) )
    {
      fare /= 2;
      if ( fare % 50 != 0 )
      {
        fare = ( fare / 50 + 1 ) * 50;
      }
    }
    cout << fare << endl;
  }
}