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,25,40},{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<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;
		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+=50-num%100;
		}
		cout<<num<<endl;
	}
}

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(((1730<=S&&S<=1930)||(1730<=E&&E<=1930))&&(s[ec-1][sc-1]<=40))an/=2;
    if(an%50)an-=an%50,an+=50;
    cout<<an<<endl;
  }
  return 0;
}

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

int table[ 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 main()
{
	int s, e;
	int sh, sm, eh, em;
	while( cin >> s && s ){
		cin >> sh >> sm;
		cin >> e;
		cin >> eh >> em;

		int st = sh * 100 + sm;
		int et = eh * 100 + em;
		if( s > e ){
			int t = s;
			s = e;
			e = t;
		}
		int cost = table[ s ][ e ];
		if( ( ( st >= 1730 && st <= 1930 ) || ( et >= 1730 && et <= 1930 ) )
			&& ( table[ e ][ s ] <= 40 ) ){
			cost = static_cast<int>( ( ( cost / 100.0 ) + 0.9 ) ) * 50;
		}

		cout << cost << endl;
	}

	return 0;
}

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(time00 == 19 && time01 <= 30){disc2=1;}
      else if(time00 == 18)disc2=1;
      else if(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 <stdio.h>
using namespace std;
int main() {
 char c1[2],c2[2];
 int h,m,ic[2],f[2],i,k,a,b;
 int g[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}};
 while(true) {
	 for (i=0;i<2;i++) {
		 cin >> ic[i];
		 if (ic[i]==0) return 0;
		 ic[i]--;
		 cin >> c1 >> c2;
		 h=(c1[0]-'0')*10+(c1[1]-'0');
		 m=(c2[0]-'0')*10+(c2[1]-'0');
		 if (h==17 && m==30) f[i]=1; else if (h==19 && m==30) f[i]=3; else
			 if ((h==17 && m>30) || h==18 || (h==19 && m<30)) f[i]=2; else f[i]=0; 
		 }
	 k=g[ic[0]][ic[1]]; a=f[0]; b=f[1];
	 if(k<1350) 
		 if((a==0 && b==1)||(a==1 && b==2)||(a==0 && b==2)||(a==2 && b==3)||(a==2 && b==0)||(a==3 && b==0)) k=k % 100>0 ? k/2+25:k/2;
	 cout << k << endl;
 }
return 0;
 }