Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
INF = 10 ** 20

while True:
  n, m, l, k, a, h = map(int, input().split())
  if n == 0:
    break
  if l != 0:
    sisetu = list(map(int, input().split())) + [a, h]
  else:
    sisetu = [a, h]

  costs = [[INF] * n for _ in range(n)]
  for _  in range(k):
    x, y, t = map(int, input().split())
    costs[x][y] = t
    costs[y][x] = t
  for i in range(n):
    costs[i][i] = 0
  for k in range(n):
    for j in range(n):
      for i in range(n):
        costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j])

  edges = [[] for _ in range(n)]
  for i in range(n):
    for j in range(n):
      if i != j and i in sisetu and j in sisetu and costs[i][j] <= m:
        edges[i].append((costs[i][j], j))

  que = []
  heappush(que, (0, a))
  cost = [INF] * n
  cost[0] = 0
  while que:
    total, node = heappop(que)
    for dist, to in edges[node]:
      if total + dist < cost[to]:
        cost[to] = total + dist
        heappush(que, (total + dist, to))
  if cost[h] == INF:
    print("Help!")
  else:
    print(cost[h] + (cost[h] - m))


Fixed submission:
from heapq import heappop, heappush
INF = 10 ** 20

def main():
  while True:
    n, m, l, k, a, h = map(int, input().split())
    if n == 0:
      break
  
    if l == 0:
      input()
      sisetu = [a, h]
    else:
      sisetu = list(map(int, input().split()))
      sisetu += [a, h]
  
    edges = [[] for _ in range((m + 1) * n)]
    for _ in range(k):
      x, y, t = map(int, input().split())
      for i in range(t, m + 1):
        edges[i * n + x].append((t, (i - t) * n + y))
        edges[i * n + y].append((t, (i - t) * n + x))
    
    for node in sisetu:
      for i in range(m):
        edges[i * n + node].append((1, (i + 1) * n + node))
  
    que = []
    heappush(que, (0, m * n + a))
    costs = [INF] * ((m + 1) * n)
    costs[m * n + a] = 0
    
    while que:
      total, node = heappop(que)
      for dist, to in edges[node]:
        if costs[to] > total + dist:
          costs[to] = total + dist
          heappush(que, (total + dist, to))
    ans = min([costs[i * n + h] for i in range(m + 1)])
    if ans == INF:
      print("Help!")
    else:
      print(ans)

main()

Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop
INF = 10 ** 20

def main():
  while True:
    n, m, l, k, a, h = map(int, input().split())
    if n == 0:
      break
    if l != 0:
      sisetu = list(map(int, input().split())) + [a, h]
    else:
      input()
      sisetu = [a, h]
  
    costs = [[INF] * n for _ in range(n)]
    for _  in range(k):
      x, y, t = map(int, input().split())
      costs[x][y] = t
      costs[y][x] = t
    for k in range(n):
      costsk = costs[k]
      for i in range(n):
        costsi = costs[i]
        costsik = costsi[k]
        for j in range(i + 1, n):
          costsij = costsi[j]
          costsikj = costsik + costsk[j]
          if costsij > costsikj:
              costsi[j] = costsikj
              costs[j][i] = costsikj
  
    edges = [[] for _ in range(n)]
    for i in range(n):
      for j in range(i + 1, n):
        if i in sisetu and j in sisetu and costs[i][j] <= m:
          edges[i].append((costs[i][j], j))
          edges[j].append((costs[i][j], i))
  
    que = []
    heappush(que, (0, a))
    cost = [INF] * n
    cost[a] = 0
    while que:
      total, node = heappop(que)
      for dist, to in edges[node]:
        if total + dist < cost[to]:
          cost[to] = total + dist
          heappush(que, (total + dist, to))
    if cost[h] == INF:
      print("Help!")
    else:
      print(cost[h] + max(0, (cost[h] - m)))

main()


Fixed submission:
from heapq import heappop, heappush
INF = 10 ** 20

def main():
  while True:
    n, m, l, k, a, h = map(int, input().split())
    if n == 0:
      break
  
    if l == 0:
      input()
      sisetu = [a, h]
    else:
      sisetu = list(map(int, input().split()))
      sisetu += [a, h]
  
    edges = [[] for _ in range((m + 1) * n)]
    for _ in range(k):
      x, y, t = map(int, input().split())
      for i in range(t, m + 1):
        edges[i * n + x].append((t, (i - t) * n + y))
        edges[i * n + y].append((t, (i - t) * n + x))
    
    for node in sisetu:
      for i in range(m):
        edges[i * n + node].append((1, (i + 1) * n + node))
  
    que = []
    heappush(que, (0, m * n + a))
    costs = [INF] * ((m + 1) * n)
    costs[m * n + a] = 0
    
    while que:
      total, node = heappop(que)
      for dist, to in edges[node]:
        if costs[to] > total + dist:
          costs[to] = total + dist
          heappush(que, (total + dist, to))
    ans = min([costs[i * n + h] for i in range(m + 1)])
    if ans == INF:
      print("Help!")
    else:
      print(ans)

main()