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>
#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(1){
		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))){
			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 main(){
  int sic,sh,sm,eic,eh,em,st,et,S,E,flag,ans;
  int d[8][8];
  bool c[8][8];
  d[1][2]=d[2][1]=300;
  d[1][3]=d[3][1]=500;
  d[1][4]=d[4][1]=600;
  d[1][5]=d[5][1]=700;
  d[1][6]=d[6][1]=1350;
  d[1][7]=d[7][1]=1650;
  d[2][3]=d[3][2]=350;
  d[2][4]=d[4][2]=450;
  d[2][5]=d[5][2]=600;
  d[2][6]=d[6][2]=1150;
  d[2][7]=d[7][2]=1500;
  d[3][4]=d[4][3]=250;
  d[3][5]=d[5][3]=400;
  d[3][6]=d[6][3]=1000;
  d[3][7]=d[7][3]=1350;
  d[4][5]=d[5][4]=250;
  d[4][6]=d[6][4]=850;
  d[4][7]=d[7][4]=1300;
  d[5][6]=d[6][5]=600;
  d[5][7]=d[7][5]=1150;
  d[6][7]=d[7][6]=500;
  S=17*3600+30*60;
  E=19*3600+30*60;
  for(int i=1;i<8;i++)
    for(int j=1;j<8;j++) c[i][j]=true;
  c[1][6]=c[6][1]=false;
  c[3][7]=c[7][3]=false;
  c[2][7]=c[7][2]=false;
  c[1][7]=c[7][1]=false;
  while(1){
    cin>>sic>>sh>>sm>>eic>>eh>>em;
    if(!sic) break;
    st=sh*3600+sm*60;
    et=eh*3600+em*60;
    flag=0;
    if((S<=st&&st<=E)||(S<=et&&et<=E)) flag=1;
    ans=d[sic][eic];
    if(flag&&c[sic][eic]){
      int cal;
      ans/=2;
      cal=ans%100;
      if(cal%50){
	ans/=100;
	ans*=100;
	if(cal<50) ans+=50;
	else ans+=100;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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

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

int main() {
  int base[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}};
  while(1) {
    int s,g;
    int sh, sm, gh, gm;
    cin >> s;
    if(s == 0) break;
    cin >> sh >> sm;
    cin >> g;
    cin >> gh >> gm;
    int temp;
    if(s > g) {
      temp = s;
      s = g;
      g = temp;
    }

    bool half = false;
    if(m(sh,sm) >= m(17,30) && m(sh,sm) <= m(19,30) && base[g][s] <= 40) {
      half = true;
    }
    else if(m(gh,gm) >= m(17,30) && m(gh,gm) <= m(19,30) && base[g][s] <= 40) {
      half = true;
    }
    if(half) {
      temp = (base[s][g] / 2 + 50) / 50 * 50;
      cout << temp << endl;
    } else {
      cout << base[s][g] << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#define NN 1000
using namespace std;

int main(){
  int aa[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 bb[7][7]={ {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}};

  int i,j,n,time00,time01,time10,time11,n2,disc,mo;
  int disc2;
  while(1){
    disc2=0;
    disc=0; //flag
    cin >> n;
    if(n == 0)break;
    cin >> time00 >> time01;
    cin >> n2;
    cin >> time10 >> time11;

   
      if(time10 == 19 && time11 <= 30){disc2=1;}
      else if(time10 == 18)disc2=1;
      else if(time10 == 17 && time11>=30)disc2=1;
      if(bb[n2-1][n-1]<=40 && disc2==1)disc=1; //ツ湘ーツ個渉づーツ鳴楪つスツつオツづつ「ツづェツづ仕iscountツフツδ可グON
   

    mo=aa[n-1][n2-1];
    if(disc == 1){
      mo=mo/2;
      disc=0;
      disc2=0;
       if(mo%50 !=0)mo=(mo-(mo%50))+50;
    }
    cout << mo << endl;


    }


}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
	int start,finish;
	while(cin>>start,start){
		int time[2][2];
		for(int i=0;i<2;i++)cin>>time[0][i];
		cin>>finish;
		if(start>finish)swap(start,finish);
		for(int i=0;i<2;i++)cin>>time[1][i];
		int num=0,distance[]={6,7,5,5,20,15},money[6][6]={{300,500,600,700,1350,1650},{350,450,600,1150,1500},{250,400,1000,1350},{250,850,1300},{600,1150},{500}};
		for(int i=start-1;i<finish;i++)num+=distance[i];
		bool kawa=0;
		for(int i=0;i<2&&!kawa&&num<41;i++)if(time[i][0]==18||time[i][0]==17&&time[i][1]>29||time[i][0]==19&&time[i][1]<31)kawa=1;
		num=money[start-1][finish-start-1];
		if(kawa){
			num/=2;
			if(num%50!=0)num+=25;
		}
		cout<<num<<endl;
	}
}