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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

int table[7][7] = { { -1, 300, 500, 600, 700, 1350, 1650 },
{ 6, -1, 350, 450, 600, 1150, 1500 }, { 13, 7, -1, 250, 400, 1000, 1350 },
{ 18, 12, 5, -1, 250, 850, 1300 }, { 23, 17, 10, 5, -1, 600, 1150 },
{ 43, 37, 30, 25, 20, -1, 500 }, { 58, 52, 45, 40, 35, 15, -1 } };

int s, g, h1, m1, h2, m2;
int main(){
	while (cin >> s&&s){
		cin >> h1 >> m1 >> g >> h2 >> m2;
		g--;
		s--;
		int sum; 
		if (table[g][s] <= 40){
			if (h1 < 17 || (h1 == 17 && m1 <= 30)){
				if (h2 < 19 || (h2 == 19 && m2 < 30)){
					sum = (table[s][g] / 2 - table[s][g] / 2 % 50) + 50;
				}
				else {
					sum = table[s][g];
				}
			}
			else if (h1 > 17 || (h1 == 17 && m1 > 30)){
				if (h2 > 19 || (h2 == 19 && m2 >= 30)){
					sum = (table[s][g] / 2 - table[s][g] / 2 % 50) + 50;
				}
				else{
					sum = table[s][g];
				}
			}
		}
		else sum = table[s][g];
		cout << sum << endl;
	}
}

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]/2;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<stdio.h>

int main(){

int st1,st2;

int h1,h2,m1,m2;


int n[8][8]={
{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,052,45,40,35,15,0},
};

while(1){
scanf("%d",&st1);if(st1==0)break;

scanf("%d %d",&h1,&m1);

scanf("%d",&st2);
scanf("%d %d",&h2,&m2);

int t1=100*h1+m1;int t2=100*h2+m2;

int T1=st1,T2=st2,S=0;
if(st1>=st2){T1=st2;T2=st1;}

if(((t1>=1730&&t1<=1930)||(t2<=1930&&t2>=1730))&&n[T2-1][T1-1]<=40)
{S=(n[T1-1][T2-1])/2;}
else S=(n[T1-1][T2-1]);
if(S%50!=0){
int QQ=S/50;QQ++;S=QQ*50;
}


printf("%d\n",S);
}
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%100==25)num+=25;
		}
		cout<<num<<endl;
	}

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

const int t[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}
};

const int B = 17 * 60 + 30, E = 19 * 60 + 30;

int main()
{
	int id1, h1, m1;
	int id2, h2, m2;
	while (scanf("%d", &id1), id1){
		scanf("%d %d %d %d %d", &h1, &m1, &id2, &h2, &m2);
		if (id1 > id2) swap(id1, id2);
		int t1 = h1 * 60 + m1;
		int t2 = h2 * 60 + m2;
		--id1; --id2;
		int v = t[id1][id2];
		int l = t[id2][id1];
		bool f = true;
		if (l > 40) f = false;
		if (((B <= t1 && t1 <= E) || (B <= t2 && t2 <= E)) && f){
			v /= 2;
			int f = !!(v % 50);
			v = v / 50 * 50 + f * 50;
		}
		printf("%d\n", v);
	}
	return 0;
}