Problem:


有料道路通行料

20XX年に喜多方市熱塩加納町から南会津町までの6区間、総距離58kmの会津中央道路が完成し開通する予定です。

開通後、半年間は利用促進のため17時30分〜19時30分までに出発ICか到着ICを通過し、なおかつ走行距離が40km以下の車に対する通行料金は半額になります。ただし料金は50円単位とし、端数は切り上げます。下記の表は料金と距離の一覧表です。

例えば喜多方（２）から会津若松（４）までは料金が450円、距離が12kmとなります。半額時間帯であれば250円になります。

出発IC、出発IC通過時刻、到着IC、到着IC通過時刻を入力とし、料金を計算して出力するプログラムを作成してください。ただし、入力される時刻は24 時間表記の値とします。なお、17時30分および19時30分ちょうどに通過した場合も半額時間帯に含めます。

Input

複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。

d
hd md
a
ha ma

１行目に出発ICの番号 d (1 ≤ d ≤ 7)、２行目に出発ICの通過時刻の時間 hd (0 ≤ hd ≤ 23) と分 md (0 ≤ md ≤ 59) が与えられます。

3行目に到着ICの番号 a (1 ≤ a ≤ 7)、４行目に到着ICの通過時刻の時間 ha (0 ≤ ha ≤ 23) と分 ma (0 ≤ ma ≤ 59) が与えられます。

Output

データセットごとに通行料金（整数）を１行に出力します。

Sample Input

2
17 25
4
17 45
4
17 25
7
19 35
0

Output for the Sample Input

250
1300



Sample input:
2
17 25
4
17 45
4
17 25
7
19 35
0


Sample output:
250
1300

Submission status: Wrong Answer

Solution code:
data = {(1,2):(6,300), (1,3):(13,500), (1,4):(18,600), 
        (1,5):(23,700), (1,6):(43,1350), (1,7):(58,1650), 
        (2,3):(7,350), (2,4):(12,450), (2,5):(17,600), 
        (2,6):(37,1150),(2,7):(52,1500), (3,4):(5,250), 
        (3,5):(10,400), (3,6):(30,1000), (3,7):(45,1350), 
        (4,5):(5,250), (4,6):(25,850), (4,7):(40,1300), 
        (5,6):(20,600), (5,7):(35,1150), (6,7):(15,500)}

while True:
    s = input()
    if s == 0: break
    sh, sm = map(int, raw_input().split())
    g = input()
    gh, gm = map(int, raw_input().split())
    flag = False
    for h, m in [(sh, sm), (gh, gm)]:
        if h == 17 and 30 <= m:
            flag = True
            break
        elif h == 18:
            flag = True
            break
        elif h == 19 and m <= 30:
            flag = True
            break
    if s < g:
        key = (s,g)
    else:
        key = (g,s)
    if flag:
        if 40 < data[key][0]:
            flag = False
    if flag:
        p = str(data[key][1]/2)
        if int(p[-2:]) <= 50:
            print p[0]+'50'
        else:
            print str(int(p[0])+1)+'00'
    else:
        print data[key][1]

Submission status: Wrong Answer

Solution code:
data = {(1,2):(6,300), (1,3):(13,500), (1,4):(18,600), 
        (1,5):(23,700), (1,6):(43,1350), (1,7):(58,1650), 
        (2,3):(7,350), (2,4):(12,450), (2,5):(17,600), 
        (2,6):(37,1150),(2,7):(52,1500), (3,4):(5,250), 
        (3,5):(10,400), (3,6):(30,1000), (3,7):(45,1350), 
        (4,5):(5,250), (4,6):(25,850), (4,7):(40,1300), 
        (5,6):(20,600), (5,7):(35,1150), (6,7):(15,500)}

while True:
    s = input()
    if s == 0: break
    sh, sm = map(int, raw_input().split())
    g = input()
    gh, gm = map(int, raw_input().split())
    flag = False
    for h, m in [(sh, sm), (gh, gm)]:
        if (h == 17 and 30 <= m) or (h == 18) \
        or (h == 19 and m <= 30):
            flag = True
            break
    if s < g:
        key = (s,g)
    else:
        key = (g,s)
    if flag and 40 < data[key][0]:
        flag = False
    if flag:
        p = str(data[key][1]/2)
        if int(p[-2:]) <= 50:
            print p[0]+'50'
        else:
            print str(int(p[0])+1)+'00'
    else:
        print data[key][1]

Submission status: Wrong Answer

Solution code:
data = {(1,2):(6,300), (1,3):(13,500), (1,4):(18,600), 
        (1,5):(23,700), (1,6):(43,1350), (1,7):(58,1650), 
        (2,3):(7,350), (2,4):(12,450), (2,5):(17,600), 
        (2,6):(37,1150),(2,7):(52,1500), (3,4):(5,250), 
        (3,5):(10,400), (3,6):(30,1000), (3,7):(45,1350), 
        (4,5):(5,250), (4,6):(25,850), (4,7):(40,1300), 
        (5,6):(20,600), (5,7):(35,1150), (6,7):(15,500)}

while True:
    s = input()
    if s == 0: break
    sh, sm = map(int, raw_input().split())
    g = input()
    gh, gm = map(int, raw_input().split())
    flag = False
    for h, m in [(sh, sm), (gh, gm)]:
        if (h == 17 and 30 <= m) or (h == 18) \
        or (h == 19 and m <= 30):
            flag = True
            break
    key = (s,g) if s < g else (g,s)
    if flag and data[key][0] <= 40:
        p = str(data[key][1]/2)
        if int(p[-2:]) <= 50:
            print p[0]+'50'
        else:
            print str(int(p[0])+1)+'00'
    else:
        print data[key][1]

Submission status: Wrong Answer

Solution code:
table=[[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]]
fbd=[(1,6),(1,7),(2,7),(3,7)]
while True:
    init=input()
    if init==0:break
    h1,m1=map(int,raw_input().split())
    fin=input()
    h2,m2=map(int,raw_input().split())
    if init>fin:
        init,h1,m1,fin,h2,m2=fin,h2,m2,init,h1,m1
    if (h1*100+m1)-1730>=0 or 1930-(h2*100+m2)>=0 and (init,fin) not in fbd:
        temp=table[init-1][fin-1]/2
        temp+=abs(50-temp%100)
        print temp
    else:
        print table[init-1][fin-1]

Submission status: Wrong Answer

Solution code:
table=[[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]]
fbd=[(1,6),(1,7),(2,7),(3,7)]
while True:
    init=input()
    if init==0:break
    h1,m1=map(int,raw_input().split())
    fin=input()
    h2,m2=map(int,raw_input().split())
    if init>fin:
        init,h1,m1,fin,h2,m2=fin,h2,m2,init,h1,m1
    if (h1*100+m1)-1730>=0 or 1930-(h2*100+m2)>=0 and (init,fin) not in fbd:
        temp=table[init-1][fin-1]/2
        if temp%100!=0:
            temp+=abs(50-temp%100)
        print temp
    else:
        print table[init-1][fin-1]

Submission status: Wrong Answer

Solution code:
table=[[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]]
fbd=[(1,6),(1,7),(2,7),(3,7)]
while True:
    init=input()
    if init==0:break
    h1,m1=map(int,raw_input().split())
    fin=input()
    h2,m2=map(int,raw_input().split())
    if init>fin:
        init,h1,m1,fin,h2,m2=fin,h2,m2,init,h1,m1
    t1=h1*60+m1
    t2=h2*60+m2
    if 1050<=t1<=1170 or 1050<=t2<=1170 and (init,fin) not in fbd:
        temp=table[init-1][fin-1]/2
        if temp%100>0:
            temp+=50-temp%50
        print temp
    else:
        print table[init-1][fin-1]

Submission status: Wrong Answer

Solution code:
table=[[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]]
fbd=[(1,6),(1,7),(2,7),(3,7)]
while True:
    init=input()
    if init==0:break
    h1,m1=map(int,raw_input().split())
    fin=input()
    h2,m2=map(int,raw_input().split())
    if init>fin:
        init,fin=fin,init

    t1=h1*60+m1
    t2=h2*60+m2
    if 1050<=t1<=1170 or 1050<=t2<=1170 and (init,fin) not in fbd:
        temp=table[init-1][fin-1]/2
        if temp%100>0:
            temp+=50-temp%50
        print temp
    else:
        print table[init-1][fin-1]

Submission status: Wrong Answer

Solution code:
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,0]]
while True:
    init=input()
    if init==0:break
    h1,m1=map(int,raw_input().split())
    fin=input()
    h2,m2=map(int,raw_input().split())
    if init>fin:
        init,fin=fin,init
    t1=h1*60+m1
    t2=h2*60+m2
    if 1050<=t1<=1170 or 1050<=t2<=1170 and table[fin-1][init-1]<=40:
        temp=table[init-1][fin-1]/2
        if temp%100>0:
            temp+=50-temp%50
        print temp
    else:
        print table[init-1][fin-1]

Submission status: Wrong Answer

Solution code:
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,0]]
while True:
    init=input()
    if init==0:break
    h1,m1=map(int,raw_input().split())
    fin=input()
    h2,m2=map(int,raw_input().split())
    if init>fin:
        init,fin=fin,init
    t1=h1*60+m1
    t2=h2*60+m2
    if 1050<=t1<=1170 or 1050<=t2<=1170 and table[fin-1][init-1]<=40:
        temp=table[init-1][fin-1]/2
        if temp%50>0:
            temp+=50-temp%50
        print temp
    else:
        print table[init-1][fin-1]

Submission status: Wrong Answer

Solution code:
# Highway Toll

PRICE_LIST = (
    (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 True:
    i = int(raw_input())
    if i == 0:
        break

    it = int(raw_input().strip().replace(' ', ''))
    o = int(raw_input())
    ot = int(raw_input().strip().replace(' ', ''))

    half = False
    if 1730 <= it <= 1930 or 1730 <= ot <= 1930:
        half = True

    if PRICE_LIST[o][i] <= 40:
        half &= True

    p = PRICE_LIST[i][o]
    if half:
        print (p // 50) * 50 if p % 50 == 0 else (p // 50 + 1) * 50
    else:
        print p

Submission status: Wrong Answer

Solution code:
# Highway Toll

PRICE_LIST = (
    (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 True:
    i = int(raw_input())
    if i == 0:
        break

    it = int(raw_input().strip().replace(' ', ''))
    o = int(raw_input())
    ot = int(raw_input().strip().replace(' ', ''))

    half = False
    if 1730 <= it <= 1930 or 1730 <= ot <= 1930:
        half = True

    if PRICE_LIST[o][i] <= 40:
        half &= True

    p = PRICE_LIST[i][o]
    if half:
        print (p // 100) * 50 if p % 100 == 0 else (p // 100 + 1) * 50
    else:
        print p

Submission status: Wrong Answer

Solution code:
# Highway Toll

PRICE_LIST = (
    (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 True:
    i = int(raw_input())
    if i == 0:
        break

    it = int(raw_input().strip().replace(' ', ''))
    o = int(raw_input())
    ot = int(raw_input().strip().replace(' ', ''))

    half = False
    if 1730 <= it <= 1930 or 1730 <= ot <= 1930:
        half = True

    if PRICE_LIST[o][i] <= 40:
        half &= True

    p = PRICE_LIST[i][o]
    if half:
        p /= 2
        if p % 50:
            p = p - (p % 50) + 50

    print p

Submission status: Accepted

Solution code:
sheet = [[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],
         [59, 52, 45, 40, 35,  15,   0]]

while 1:
    s = int(raw_input())-1
    if s == -1: break
    st = int(raw_input().replace(" ",""))
    g = int(raw_input())-1
    gt = int(raw_input().replace(" ",""))
    s,g = min(s,g),max(s,g)
    dist = sheet[g][s]
    cost = sheet[s][g]
    if dist <= 40 and (1730 <= st <= 1930 or 1730 <= gt <= 1930):
        cost = cost/2
        cost = cost/100*100 + (cost%100+49)/50*50
    print cost

Submission status: Accepted

Solution code:
def half(x): return x/100*50+[0,50][x%100>0]
def In(): return map(int, raw_input().split())
def t(h,m): return 1050<=h*60+m<=1170

toll = {}
P=[6,10,12,14,27,33,7,9,12,23,30,5,8,20,27,5,17,26,12,23,10]
c=0
for i in range(0,6):
  for j in range(i+1,7):
    toll[(i,j)] = toll[(j,i)] =P[c]*50
    c += 1
D=[0, 6, 13, 18, 23, 43, 58]

while 1:
  i1 = input()-1
  if i1<0: break
  h1, m1 = In()
  i2 = input()-1
  h2, m2 = In()
  cost = toll[(i1,i2)]
  if (t(h1, m1) or t(h2,m2)) and abs(D[i1]-D[i2])<=40: cost = half(cost)
  print cost

Submission status: Accepted

Solution code:
import math
def In(): return map(int, raw_input().split())

toll = {}
P=[6,10,12,14,27,33,7,9,12,23,30,5,8,20,27,5,17,26,12,23,10]
c=0
for i in range(0,6):
  for j in range(i+1,7):
    toll[(i,j)] = toll[(j,i)] =P[c]*50
    c += 1
D=[0, 6, 13, 18, 23, 43, 58]

while 1:
  i1 = input()-1
  if i1<0: break
  h1, m1 = In()
  i2 = input()-1
  h2, m2 = In()
  x = toll[(i1, i2)]
  if (1050<=h1*60+m1<=1170 or 1050<=h2*60+m2<=1170) and abs(D[i1]-D[i2])<=40:
    x = int(math.ceil(x/100.0))*50
  print x

Submission status: Accepted

Solution code:
def In(): return map(int, raw_input().split())

toll = {}
P=[6,10,12,14,27,33,7,9,12,23,30,5,8,20,27,5,17,26,12,23,10]
c=0
for i in range(0,6):
  for j in range(i+1,7):
    toll[(i,j)] = toll[(j,i)] =P[c]*50
    c += 1
D=[0, 6, 13, 18, 23, 43, 58]

while 1:
  i1 = input()-1
  if i1<0: break
  h1, m1 = In()
  i2 = input()-1
  h2, m2 = In()
  x = toll[(i1, i2)]
  if (1050<=h1*60+m1<=1170 or 1050<=h2*60+m2<=1170) and abs(D[i1]-D[i2])<=40:
    x = (x+50)/100*50
  print x

Submission status: Accepted

Solution code:
def In(): return map(int, raw_input().split())

toll = {}
P=[6,10,12,14,27,33,7,9,12,23,30,5,8,20,27,5,17,26,12,23,10]
H=range(0,1440,60)
c=0
for i in range(0,6):
  for j in range(i+1,7):
    toll[(i,j)] = toll[(j,i)] =P[c]*50
    c += 1
D=[0, 6, 13, 18, 23, 43, 58]

while 1:
  i1 = input()-1
  if i1<0: break
  h1, m1 = In()
  i2 = input()-1
  h2, m2 = In()
  x = toll[(i1, i2)]
  if (1050<=H[h1]+m1<=1170 or 1050<=H[h2]+m2<=1170) and abs(D[i1]-D[i2])<=40:
    x = (x+50)/100*50
  print x

Submission status: Accepted

Solution code:
data = {(1,2):(6,300), (1,3):(13,500), (1,4):(18,600), 
        (1,5):(23,700), (1,6):(43,1350), (1,7):(58,1650), 
        (2,3):(7,350), (2,4):(12,450), (2,5):(17,600), 
        (2,6):(37,1150),(2,7):(52,1500), (3,4):(5,250), 
        (3,5):(10,400), (3,6):(30,1000), (3,7):(45,1350), 
        (4,5):(5,250), (4,6):(25,850), (4,7):(40,1300), 
        (5,6):(20,600), (5,7):(35,1150), (6,7):(15,500)}

while True:
    s = input()
    if s == 0: break
    sh, sm = map(int, raw_input().split())
    g = input()
    gh, gm = map(int, raw_input().split())
    flag = False
    for h, m in [(sh, sm), (gh, gm)]:
        if (h == 17 and 30 <= m) or (h == 18) \
        or (h == 19 and m <= 30):
            flag = True
            break
    key = (s,g) if s < g else (g,s)
    if flag and data[key][0] <= 40:
        p = str(data[key][1]/2)
        if int(p[-2:]) == 0:
            print p
        elif int(p[-2:]) <= 50:
            print p[0]+'50'
        else:
            print str(int(p[0])+1)+'00'
    else:
        print data[key][1]

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# 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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
from collections import namedtuple

Data = namedtuple("Data", "rate distance")

SENTINEL = None
NOTHING = None
RATE_TABLE = [
    [SENTINEL],
    [SENTINEL, NOTHING, Data(300, 6), Data(500, 13), Data(600, 18), Data(700, 23), Data(1350, 43), Data(1650, 58)],
    [SENTINEL, Data(300, 6), NOTHING, Data(350, 7), Data(450, 12), Data(600, 17), Data(1150, 37), Data(1500, 52)],
    [SENTINEL, Data(500, 13), Data(350, 7), NOTHING, Data(250, 5), Data(400, 10), Data(1000, 30), Data(1350, 45)],
    [SENTINEL, Data(600, 18), Data(450, 12), Data(250, 5), NOTHING, Data(250, 5), Data(850, 25), Data(1300, 40)],
    [SENTINEL, Data(700, 23), Data(600, 17), Data(400, 10), Data(250, 5), NOTHING, Data(600, 20), Data(1150, 35)],
    [SENTINEL, Data(1350, 43), Data(1150, 37), Data(1000, 30), Data(850, 25), Data(600, 20), NOTHING, Data(500, 15)],
    [SENTINEL, Data(1650, 58), Data(1500, 52), Data(1350, 45), Data(1300, 40), Data(1150, 35), Data(500, 15), NOTHING]
]
DISTANCE_LIMIT = 40
TIME_LIMIT1 = 17 * 60 + 30
TIME_LIMIT2 = 19 * 60 + 30

while True:

    leave_number = int(input())

    if leave_number == 0:
        break

    leave_time = [int(item) for item in input().split(" ")]

    arrive_number = int(input())
    arrive_time = [int(item) for item in input().split(" ")]

    data = RATE_TABLE[leave_number][arrive_number]

    rate = data.rate

    if data.distance <= DISTANCE_LIMIT:

        time1 = leave_time[0] * 60 + leave_time[1]
        time2 = arrive_time[0] * 60 + arrive_time[1]

        if TIME_LIMIT1 <= time1 <= TIME_LIMIT2 or TIME_LIMIT1 <= time2 <= TIME_LIMIT2:
            rate //= 2

            if rate % 50 != 0:
                rate = rate + 50 - rate % 50

    print(rate)

Submission status: Accepted

Solution code:
# 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)

Submission status: Accepted

Solution code:
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,0]]
while True:
    init=input()
    if init==0:break
    h1,m1=map(int,raw_input().split())
    fin=input()
    h2,m2=map(int,raw_input().split())
    if init>fin:
        init,fin=fin,init
    t1=h1*60+m1
    t2=h2*60+m2
    f=False
    if table[fin-1][init-1]<=40 and 1050<=t1<=1170 or 1050<=t2<=1170:
        f=True
    temp=table[init-1][fin-1]
    if f:
        temp/=2
        if temp%50>0:
            temp+=50-temp%50
    print temp

Submission status: Accepted

Solution code:
# Highway Toll

PRICE_LIST = (
    (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 True:
    i = int(raw_input())
    if i == 0:
        break

    it = int(raw_input().strip().replace(' ', ''))
    o = int(raw_input())
    ot = int(raw_input().strip().replace(' ', ''))

    half = False
    if (1730 <= it <= 1930 or 1730 <= ot <= 1930) and PRICE_LIST[o][i] <= 40:
        half = True

    p = PRICE_LIST[i][o]
    if half:
        p /= 2
        if p % 50:
            p = p - (p % 50) + 50

    print p

Submission status: Accepted

Solution code:
# Highway Toll

PRICE_LIST = (
    (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 True:
    i = int(raw_input())
    if i == 0:
        break

    it = int(raw_input().strip().replace(' ', ''))
    o = int(raw_input())
    ot = int(raw_input().strip().replace(' ', ''))

    half = False
    if (1730 <= it <= 1930 or 1730 <= ot <= 1930) and PRICE_LIST[o][i] <= 40:
        half = True

    p = PRICE_LIST[i][o]
    if half:
        p /= 2
        if p % 50:
            p = (p / 50) * 50 + 50

    print p

Submission status: Accepted

Solution code:
# Highway Toll

PRICE_LIST = (
    (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 True:
    i = int(raw_input())
    if i == 0:
        break

    it = int(raw_input().strip().replace(' ', ''))
    o = int(raw_input())
    ot = int(raw_input().strip().replace(' ', ''))

    half = False
    price = PRICE_LIST[i][o]
    if (1730 <= it <= 1930 or 1730 <= ot <= 1930) and PRICE_LIST[o][i] <= 40:
        half = True
        price /= 2
        if price % 50:
            price = price - (price % 50) + 50

    print price

Submission status: Accepted

Solution code:
A = [
    [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],
]

while 1:
    d = int(input()); d -= 1
    if d == -1:
        break
    hd, md = map(int, input().split())
    dt = hd*100 + md
    a = int(input()); a -= 1
    ha, ma = map(int, input().split())
    at = ha*100 + ma
    if not a <= d:
        d, a = a, d
    if A[d][a] <= 40 and (1730 <= dt <= 1930 or 1730 <= at <= 1930):
        print((A[a][d] // 2 + 49)//50*50)
    else:
        print(A[a][d])

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)