import sequtils,strutils,strscans,math type priorityQue[I:static[int];T:tuple] = array[I + 1,T] item = tuple[p : int,cost : float64, weight : float64, bitflag : int] proc push[T](A:var priorityQue; b: T)= const key = 1 A[0][0] += 1 A[A[0][0]] = b # A[0][0]はsize、最大のIndex var index = A[0][0] while index > 1 and A[index][key] > A[index div 2][key]: (A[index],A[index div 2]) = (A[index div 2],A[index]) index = index div 2 proc pop(A: var priorityQue):item = const key = 1 result = A[1] A[1] = A[A[0][0]] var a : item A[A[0][0]] = a A[0][0] -= 1 var index = 1 while index * 2 <= A[0][0]: if index * 2 + 1<= A[0][0]: if A[index][key] < A[index * 2][key] and A[index * 2 + 1][key] <= A[index * 2][key]: (A[index],A[index * 2]) = (A[index * 2],A[index]) index = index * 2 elif A[index][key] < A[index * 2 + 1][key]: (A[index],A[index * 2 + 1]) = (A[index * 2 + 1],A[index]) index = index * 2 + 1 else: break elif index * 2 <= A[0][0]: if A[index][key] < A[index * 2][key]: (A[index],A[index * 2]) = (A[index * 2],A[index]) break else: break proc size(A : priorityQue):int= return A[0][0] type zahyou = tuple[x : int, y : int, w : float64] var ax,ay,x,y : int w,SW : float64 N : int s : string mintime : array[15, array[1 shl 14, float64]] PQ : priorityQue[500000, item] (ax, ay) = stdin.readline.split.map(parseInt) N = stdin.readline.parseInt var tizu = newSeq[zahyou](N + 1) for n in 1..N: s = stdin.readline discard scanf(s,"$i $i $f",x, y, w) tizu[n] = (x - ax, y - ay, w) SW += w var t,t2 : item p,p2 : zahyou t = (0, 0.0, SW, 1) PQ.push(t) while PQ.size > 0: t = PQ.pop() var b = t.bitflag T : float64 = (t.weight + 100) / 120 for k in 1..N: if ((1 shl k) and b) == 0: p2 = tizu[k] p = tizu[t.p] var d = (abs(p2.x - p.x) + abs(p2.y - p.y)).float64 t2 = (k, t.cost - T * d - p2.w , t.weight - p2.w, b or (1 shl k)) if countBits32(t2.bitflag.int32) == N + 1: t2.cost -= (abs(p2.x) + abs(p2.y)).float64 * (100 / 120) if mintime[k][t2.bitflag] == 0 or mintime[k][t2.bitflag] < t2.cost: mintime[k][t2.bitflag] = t2.cost PQ.push(t2) var ans : float64 = Inf for i in 1..N: if mintime[i][(1 shl (N + 1)) - 1] == 0: continue ans = min(ans, - mintime[i][(1 shl (N + 1)) - 1]) echo ans