Title: Highway Bus

A is planning a solo trip using a highway bus during high school break. A has chosen a destination and needs to determine the route to take from the departure point to the destination. A has received some discount tickets from a relative. Each ticket allows purchasing one bus ticket at half price. A wants to minimize transportation costs to allocate more money for sightseeing. A needs a program to find the cheapest transportation cost from the departure point to the destination.

Input:
Multiple datasets are provided. The end of input is indicated by five zeros.
Each dataset is in the following format:
c n m s d
a1 b1 f1
a2 b2 f2
...
am bm fm

The first line contains the number of discount tickets c (1 ≤ c ≤ 10), the number of towns connected by buses n (2 ≤ n ≤ 100), the number of bus routes m (1 ≤ m ≤ 500), the departure town number s, and the destination town number d (s ≠ d).
The next m lines contain the route information for each bus: ai bi fi (1 ≤ ai, bi ≤ n, 1000 ≤ fi ≤ 10000), where ai and bi are the start and end town numbers of the bus route, and fi is the fare for this route in increments of 100.

The number of datasets does not exceed 100.

Output:
For each input dataset, output the cheapest transportation cost on a single line.

Sample Input:
1 3 3 1 3
1 3 2000
1 2 1000
2 3 1000
2 3 3 1 3
1 3 2300
1 2 1000
2 3 1200
2 6 6 5 1
1 2 1500
1 3 4500
2 6 2000
5 4 1000
6 4 2200
3 5 3000
0 0 0 0 0

Output for the Sample Input:
1000
1100
3750

# Buggy version:
from sys import stdin
from heapq import heappush,heappop

while(True):
    c,n,m,s,d = map(int, stdin.readline().split())
    if not c: break
    ma = [[] for _ in range(n)]
    s -= 1
    d -= 1
    for _ in range(m):
        a,b,f = map(int, stdin.readline().split())
        a -= 1
        b -= 1
        ma[a].append([f,b])
        ma[b].append([f,a])
    cost = [[10**10]*(c+1) for _ in range(n)]
    cost[s][c] = 0
    que = [[ cost[s][c], s, c ]]
    while que:
        co, pl, ti = heappop(que)
        for fee, town in ma[pl]:
            if cost[town][ti] > co + fee:
                cost[town][ti] = co+fee
                heappush(que,[cost[town][ti],town,ti])
            if ti and cost[town][ti-1] > co+fee:
                cost[town][ti-1] = co + fee//2
                heappush(que,[cost[town][ti-1],town,ti-1])
    print(min(ma[d])[0])


# Fixed version:
from sys import stdin
from heapq import heappush,heappop

while(True):
    c,n,m,s,d = map(int, stdin.readline().split())
    if not c: break
    ma = [[] for _ in range(n)]
    s -= 1
    d -= 1
    for _ in range(m):
        a,b,f = map(int, stdin.readline().split())
        a -= 1
        b -= 1
        ma[a].append([f,b])
        ma[b].append([f,a])
    cost = [[10**10]*(c+1) for _ in range(n)]
    cost[s][c] = 0
    que = [[ cost[s][c], s, c ]]
    while que:
        co, pl, ti = heappop(que)
        for fee, town in ma[pl]:
            if cost[town][ti] > co+fee:
                cost[town][ti] = co+fee
                heappush(que,[cost[town][ti],town,ti])
            if ti and cost[town][ti-1] > co+fee//2:
                cost[town][ti-1] = co+fee//2
                heappush(que,[cost[town][ti-1],town,ti-1])
    print(min(cost[d]))