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)
	}
}

Python: import math

t = [ [ None,  300,  500,  600,  700, 1350, 1650 ],
      [ None, None,  350,  450,  600, 1150, 1500 ],
      [ None, None, None,  250,  400, 1000, 1350 ],
      [ None, None, None, None,  250,  850, 1300 ],
      [ None, None, None, None, None,  600, 1150 ],
      [ None, None, None, None, None, None,  500 ] ]

l = [ [ None, None, None, None, None, None, None ],
      [    6, None, None, None, None, None, None ],
      [   13,    7, None, None, None, None, None ],
      [   18,   12,    5, None, None, None, None ],
      [   23,   17,   10,    5, None, None, None ],
      [   43,   37,   30,   25,   20, None, None ],
      [   58,   52,   45,   40,   35,   15, None ] ]

def inside(h,m):
    return h*60+m >= 17*60+30 and h*60+m <= 19*60+30

def discount(n):
    return math.ceil(n / 2 / 50) * 50

while True:
    d = int(input())
    if d == 0:
        break

    [hd,md] = map(int,input().split())
    a = int(input())
    [ha,ma] = map(int,input().split())

    tt = t[d-1][a-1]
    ll = l[a-1][d-1]

    if ( ( inside(hd,md) or inside(ha,ma) ) and (ll <= 40) ):
        print(discount(tt))
    else:
        print(tt)

Python: distance = [
    [ 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, 45, 40, 35,  0]
]
price = [
    [   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]
]

def judge(x, y, d, a):
    if distance[d][a] <= 40 and \
        1050 <= x <= 1170 or 1050 <= y <= 1170:
        return True
    else:
        return False

while True:
    d = int(input()) - 1
    if d < 0: break
    hd, md = map(int, input().split())
    a = int(input()) - 1
    ha, ma = map(int, input().split())

    x, y = (hd*60+md), (ha*60+ma)
    fee = price[d][a]

    if judge(x, y, d, a):
        fee = ((fee // 2 - 1) // 50 + 1) * 50
    print(fee)

Python: def answer(price, flag):
    if flag == True:
        price //= 2
        if price % 50 != 0:
            price += price % 50
        print(price)
    else:
        print(price)


table = [[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]]

while 1:
    d = int(input())
    if d == 0:
        break

    h1, m1 = map(int, input().split())
    a = int(input())
    h2, m2 = map(int, input().split())

    start = min(d, a) - 1
    end = max(d, a) - 1
    dis = table[end][start]
    price = table[start][end]

    if dis > 40:
        answer(price, False)
        continue
    else:
        if h1 == 18 or h2 == 18:
            answer(price, True)
            continue
        if h1 == 17 and m1 >= 30:
            answer(price, True)
            continue
        if h2 == 17 and m2 >= 30:
            answer(price, True)
            continue
        if h1 == 19 and m1 <= 30:
            answer(price, True)
            continue
        if h2 == 19 and m2 <= 30:
            answer(price, True)
            continue
        answer(price, False)

Python: # AOJ 0163 Highway Toll
# Python3 2018.6.23 bal4u

g = [ \
	[ 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]]

f = [ \
	[   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 1:
	d = int(input())-1
	if d < 0: break
	h, m = map(int, input().split())
	ti = h*100 + m
	a = int(input())-1
	h, m = map(int, input().split())
	to = h*100 + m
	fee = f[d][a]
	if g[d][a] <= 40 and ((1730 <= ti and ti <= 1930) or (1730 <= to and to <= 1930)):
		fee = ((fee//2 - 1)//50 + 1)*50
	print(fee)

Python: b=[[0,6,10,12,14,27,33],
   [6,0,7,9,12,23,30],
   [13,7,0,5,8,20,27],
   [18,12,5,0,5,17,26],
   [23,17,10,5,0,12,23],
   [43,37,30,25,20,0,10],
   [58,52,45,40,35,15,0]]
while 1:
    d=int(input())
    if d==0:break
    e,f=map(int,input().split())
    t=e*60+f
    a=int(input())
    e,f=map(int,input().split())
    _t=e*60+f
    if d>a:d,a=a,d
    d-=1;a-=1
    print((b[d][a]//2+b[d][a]%2)*50if b[a][d]<=40 and ((17*60+30<=t<=19*60+30)or(17*60+30<=_t<=19*60+30))else b[d][a]*50)

Python: # Aizu Problem 00163: Highway Tooll
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

M = [[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]]

def intime(t):
    return 1730 <= t <= 1930

def getinfo(src, dst):
    if src > dst:
        src, dst = dst, src
    return M[dst][src], M[src][dst]

while True:
    n1 = int(input())
    if n1 == 0:
        break
    h1, m1 = [int(_) for _ in input().split()]
    n2 = int(input())
    h2, m2 = [int(_) for _ in input().split()]
    t1, t2 = 100 * h1 + m1, 100 * h2 + m2
    a, b = getinfo(n1 - 1, n2 - 1)
    if (intime(t1) or intime(t2)) and a <= 40:
        b = (b // 2 + 49) // 50 * 50
    print(b)