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>
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,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,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<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int ceil(int n) {
	return (n / 50 + (n % 50 > 0)) * 50;
}
int cost[][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 dist[][7]{
	{},
	{6},
	{13,7},
	{18,12,5},
	{23,17,10,5},
	{43,37,30,25,20},
	{58,52,45,40,35,15}
};
int main() {
	int d;
	while (scanf("%d", &d), d) {
		int hd, md, a, ha, ma; scanf("%d%d%d%d%d", &hd, &md, &a, &ha, &ma);
		d--; a--;
		if (((1050 <= hd * 60 + md&&hd * 60 + md <= 1170) || (1050 <= ha * 60 + ma&&ha * 60 + ma <= 1170)) && dist[max(d, a)][min(d, a)] <= 40)
			printf("%d\n", ceil(cost[min(d, a)][max(a, d)] / 2));
		else printf("%d\n", cost[min(d, a)][max(a, d)]);
	}
}

C++: #include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int start,startt[2],end,endt[2];
	while(cin>>start){
		if(start==0)break;
		cin>>startt[0]>>startt[1];
		cin>>end>>endt[0]>>endt[1];
		int ans;
		if(start==1){
			if(end==2)ans=300;
			else if(end==3)ans=500;
			else if(end==4)ans=600;
			else if(end==5)ans=700;
			else if(end==6)ans=1350;
			else if(end==7)ans=1650;
		}else if(start==2){
			if(end==3)ans=350;
			else if(end==4)ans=450;
			else if(end==5)ans=600;
			else if(end==6)ans=1150;
			else if(end==7)ans==1500;
		}else if(start==3){
			if(end==4)ans=250;
			else if(end==5)ans=400;
			else if(end==6)ans=1000;
			else if(end==7)ans=1350;
		}else if(start==4){
			if(end==5)ans=250;
			else if(end==6)ans=850;
			else if(end==7)ans=1300;
		}else if(start==5){
			if(end==6)ans=600;
			else if(end==7)ans=1150;
		}else if(start==6){
			if(end==7)ans=500;
		}
		if(((startt[0]*60+startt[1])>=(17*60+30) && (startt[0]*60+startt[1])<=(19*60+30)) || ((endt[0]*60+endt[1])>=(17*60+30) && (endt[0]*60+endt[1])<=(19*60+30))){
			if((start==1 && end==6) || (end==7 &&(start>0 &&start<5))){	
				cout<<ans<<endl;
			}else{
				int reans=ans/2;
				int alt=reans%50;
				if(alt>0){
					reans+=(50-alt);
				}
				cout<<reans<<endl;
			}
		}else{
			cout<<ans<<endl;
		}
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int s[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}};

int main(){
  int sc,sh,sm,ec,eh,em; 
  while(cin>>sc&&sc){
    cin>>sh>>sm>>ec>>eh>>em;
    int an=s[sc-1][ec-1],S=sh*100+sm,E=eh*100+em;
    if(S>E)E+=2400;
    if(s[ec-1][sc-1]<=40&&
       ((1930<S&&E<1730+2400&&E<1930+2400)||
	(S<1730&&1730<E&&E<1930)||
	(1730<S&&S<1930&&1930<E&&E<1730+2400)||
	(S==1730&&1730<E&&E<1930)||
	(S==1930&&1930<E&&E<1730+2400)||
	(E==1730&&S<0)||
	(E==1930&&1730<S&&S<1930)||
	(E==1730+2400&&1930<S&&S<1730+2400)))an/=2;
    if(an%50)an-=an%50,an+=50;
    cout<<an<<endl;
  }
  return 0;
}

C++: #include<cstdio>
using namespace std;
int main(void)
{
	int hyou[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,0}};
	int ic1,ic2,h1,h2,m1,m2,i,j,wk,t1,t2,kin;
	
	while(1)	{
		scanf("%d",&ic1);
		if(ic1==0)	break;
		scanf("%d %d",&h1,&m1);
		scanf("%d",&ic2);
		scanf("%d %d",&h2,&m2);
		if(ic1>ic2)	{
			wk=ic1;
			ic1=ic2;
			ic2=wk;
		}
		t1=h1*60+m1;
		t2=h2*60+m2;
		if(((t1>=17*60+30 && t1<=19*60+30) || (t2>=17*60+30 && t2<=19*60+30)) && hyou[ic2][ic1]<=40)	{
			if(hyou[ic1][ic2]%100!=0)	{
				kin=(hyou[ic1][ic2]+50)/2;
			}
			else {
				kin=hyou[ic1][ic2]/2;
			}
		}
		else {
			kin=hyou[ic1][ic2];
		}
		printf("%d\n",kin);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
int s[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}};

int main(){
  int sc,sh,sm,ec,eh,em; 
  while(cin>>sc&&sc){
    cin>>sh>>sm>>ec>>eh>>em;
    int an=s[sc-1][ec-1],s=sh*100+sm,e=eh*100+em;
    if((s<=1730&&1730<=e&&e<1930)||(1730<s&&s<=1930&&1930<=e))an/=2;
    if(an%50)an-=an%50,an+=50;
    cout<<an<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

int main() {
  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,10,5,0,500}
                     ,{58,52,45,40,35,15,0}};
  int ss = 17*60+30;
  int tt = 19*60+30;
  int s, sh, sm, t, th, tm;
  while(cin >> s, s) {
    cin >> sh >> sm >> t >> th >> tm;
    s--;t--;
    if (s>t) swap(s,t);
    int ans = table[s][t];

    int sss = sh*60+sm;
    int ttt = th*60+tm;
    if (table[t][s] <= 40) {
      if (ss<=sss&&sss<=tt || ss<=ttt&&ttt<=tt) {
        ans /= 2;
        ans = (ans + 49) / 50 * 50;
      }
    }
    cout << ans << endl;
  }
}