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>
#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++: //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<bits/stdc++.h>
using namespace std;
 
int main(){
    int a[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 b;
    while(cin>>b,b){
	int c,d,e,f,g;
	scanf("%d%d%d%d%d",&c,&d,&e,&f,&g);
	c=c*60+d;
	f=f*60+g;
	if(c>=1050&&c<=1170||f>=1050&&f<=1170){
	    if(a[max(b,e)-1][min(b,e)-1]<=40){int o=a[min(b,e)-1][max(b,e)-1];if(o%50)o+=50-o%50;printf("%d\n",o);}
	    else printf("%d\n",a[min(b,e)-1][max(b,e)-1]);
	    }
	    else printf("%d\n",a[min(b,e)-1][max(b,e)-1]);
	}
    }

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int table[][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 a = 17 * 60 + 30;
    int b = 19 * 60 + 30;

    for(;;){
        int ic[2];
        bool half = false;
        for(int i=0; i<2; ++i){
            int h, m;
            cin >> ic[i] >> h >> m;
            if(ic[i] == 0)
                return 0;
            -- ic[i];

            m += h * 60;
            if(a <= m && m <= b)
                half = true;
        }
        if(ic[1] < ic[0])
            swap(ic[0], ic[1]);

        if(table[ic[1]][ic[0]] > 40)
            half = false;

        int ret = table[ic[0]][ic[1]];
        if(half){
            if(ret % 100 != 0)
                ret += 50;
            ret /= 2;
        }
        cout << ret << endl;
    }
}

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

int main(){
  int aa[8][8]={ {0,1,2,3,4,5,6,7},
                 {1,0,300,500,600,700,1350,1650},
		 {2,300,0,350,450,600,1150,1500},
	         {3,500,350,0,250,400,1000,1350},
	       	 {4,600,450,250,0,250,850,1300},
	       	 {5,700,600,400,250,0,600,1150},
	       	 {6,1350,1150,1000,850,600,0,500},
	       	 {7,1650,1500,1350,1300,1150,500,0}};
  int bb[8][8]={ {0,1,2,3,4,5,6,7},
		 {1,0,6,13,18,23,43,58},
		 {2,6,0,7,12,17,37,52},
		 {3,13,7,0,5,10,30,45},
		 {4,18,12,5,0,5,25,40},
		 {5,23,17,10,5,0,20,35},
		 {6,43,37,30,25,20,0,15},
		 {7,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) || (time00 == 19 && time01 <=30)){disc2=1;}
      else if(time00 == 18 || time10 == 18)disc2=1;
      else if((time10 == 17 && time11>=30) || (time00 == 17 && time01 >=30))disc2=1;
      if(bb[n2][n]<=40 && disc2==1)disc=1; 
   

    mo=aa[n][n2];
    if(disc == 1){
      mo=mo/2;
      disc=0;
      disc2=0;
       if(mo%50 !=0)mo=(mo-(mo%50))+50;
    }
    cout << mo << 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((1730<m1&&m2<1930)||(m1<1730&&1930<m2)||(1930<m1&&m2<1730))han=false;
    if((m==7&&n<4)||(m==6&&n==1))han=false;
    int ans=h[n-1][m-1];
    //cout<<ans<<" "<<han<<endl;
    if(han)ans/=2;
    ans=(ans+49)-(ans+49)%50;
    cout<<ans<<endl;
  }
}