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 <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int calc(int p){
  if(p % 50){
    p += 50 - p%50;
  }
  return p;
}
const int colum[7][7] = {{0,6,13,18,23,43,58},{300,0,7,12,17,37,52},{500,350,0,5,10,30,45},{600,450,250,0,5,25,40},{700,600,400,250,0,20,35},{1350,1150,1000,850,600,0,15},{1650,1500,1350,1300,1150,500,0}};

bool check(int h1,int m1){
  if((h1 == 17 && m1 >= 30 )||(17 < h1 && h1 < 19) || (h1 == 19 && m1 <= 30)){
    return true;
  }
  return false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int dt,at,h1,m1,h2,m2;
  while(cin >> dt&&dt){
    cin >> h1 >> m1 >> at >> h2 >> m2;
    --dt,--at;
    if(at < dt){
      swap(at,dt);
    }
    int price = colum[at][dt];
    if((check(h1,m1) || check(h2,m2)) && colum[dt][at] <= 40){
      price /= 2;
      price = calc(price);
    }
    cout << price << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<algorithm>

using namespace std;

int cost[8][8] = {{},{0,0,300,500,600,700,1350,1650},
		  {0,0,0,350,450,600,1150,1500},
		  {0,0,0,0,250,400,100,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 dis[8][8] = {{},{0,0,6,13,18,23,43,58},
		 {0,0,0,7,12,17,37,52},
		 {0,0,0,0,5,10,30,45},
		 {0,0,0,0,0,5,25,40},
		 {0,0,0,0,0,0,20,35},
		 {0,0,0,0,0,0,0,15}};

struct T{int ic,h,m;};
T t[2];

bool check(T in){
  if(17 < in.h && in.h < 19) return true;
  if(in.h == 17 && in.m >= 30) return true;
  if(in.h == 19 && in.m <= 30) return true;
 
  return false;
}

int solve(T from, T to){
  int ans = 0;
  bool half = (check(from)||check(to));

  int fi = from.ic,ti = to.ic;

  if(from.ic > to.ic) swap(fi,ti);

  ans = cost[fi][ti];

  if(ans % 100 == 50) ans += 50;

  
  if(half && dis[fi][ti] <= 40) ans /= 2;
  return ans;
}

int main(){

  while(cin >> t[0].ic && t[0].ic){
    cin >> t[0].h >> t[0].m;
    cin >> t[1].ic >> t[1].h >> t[1].m;
    cout << solve(t[0],t[1]) << endl;
  }
  
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;

static const double eps = 10e-8;

struct IC{
	int fare;
	int dist;
};

int main(){
	int dpt,arv;

	struct IC ic[] = {
		300,6,
		500,13,
		600,18,
		700,23,
		1350,43,
		1650,58,

		350,7,
		450,12,
		600,17,
		1150,37,
		1500,52,

		250,5,
		400,10,
		1000,30,
		1350,45,

		250,5,
		850,25,
		1300,40,

		600,20,
		1150,35,

		500,15,
	};

	while(~scanf("%d",&dpt)){
		if(dpt==0) break;
		
		int hDpt,mDpt;
		scanf("%d %d",&hDpt,&mDpt);
		scanf("%d",&arv);
		int hArv,mArv;
		scanf("%d %d",&hArv,&mArv);

		int DptT = hDpt*60+mDpt;
		int ArvT = hArv*60+mArv;


		int idx=0;
		int fare=0,dist=0;
		for(int i=1;i<=7;i++){
			for(int j=i+1;j<=7;j++){
				if(i==dpt && j==arv){
					fare = ic[idx].fare;
					dist = ic[idx].dist;
					goto found;
				}
				idx++;
			}
		}

found:;

		if(((17*60+30 <= DptT && DptT <= 19*60+30)
			|| (17*60+30 <= ArvT && ArvT <= 19*60+30))
			&& dist <= 40){
				fare /=2;
		}

		int tmp = fare / 50;
		if(fare % 50) fare = 50 * (tmp+1);

		printf("%d\n",fare);
	}
}

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

const int T[8][8] = 
  {
    {0,0,0,0,0,0,0,0},
    {0,0,300,500,600,700,1350,1650},
    {0,6,0,350,450,600,1150,1500},
    {0,13,7,0,250,400,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},
  };
const int h_begin = 17*60 + 30;
const int h_end = 19*60 + 30;

int main() {
  int s, sh, sm, t, th, tm;
  while(cin >> s && s) {
    cin >> sh >> sm;
    cin >> t;
    cin >> th >> tm;
    int a = s, b = t;
    if(a > b) swap(a, b);
    int cost = T[a][b];
    int dist = T[b][a];
    int in = sh * 60 + sm;
    int out = th * 60 + tm;
    if(dist <= 40 && 
       (h_begin <= in && in <= h_end ||
        h_begin <= out && out <= h_end) ) {
      cost /= 2;
      while(cost % 50) ++cost;
    }
    cout << cost << endl;
  }
  return 0;
}

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

int l[7]={0,6,13,18,23,43,58};
int co[7][7]={
	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
};
int main(void){
	int s[2],h[2],m[2];
	int f[2];
	int ans;
	while(1){
		scanf("%d",&s[0]);
		if(s[0]==0)break;
		scanf("%d%d",&h[0],&m[0]);
		scanf("%d",&s[1]);
		scanf("%d%d",&h[1],&m[1]);
		for(int i=0;i<2;i++){
			if(h[i]<17 || h[i]==17 && m[i]<=30)f[i]=0;
			else if(h[i]<19 || h[i]==19 && m[i]<=30)f[i]=1;
			else f[i]=2;
		}
		ans=co[s[0]-1][s[1]-1];
		if((f[0]==1 || f[1]==1) && abs(l[s[1]-1]-l[s[0]-1])<=40)ans=abs(co[s[0]-1][s[1]-1]+50)/100*50;
		printf("%d\n",ans);
	}
    return 0;
}