import std.algorithm, std.array, std.container, std.range, std.bitmanip; import std.numeric, std.math, std.bigint, std.random, core.bitop; import std.string, std.regex, std.conv, std.stdio, std.typecons; struct point { int x, y; point opBinary(string op)(point rhs) { static if (op == "+") return point(x + rhs.x, y + rhs.y); else static if (op == "-") return point(x - rhs.x, y - rhs.y); } int absMan() { return x.abs + y.abs; } } alias Tuple!(point, "p", real, "w") posWeight; void main() { auto rd = readln.split.map!(to!int); auto x0 = point(rd[0], rd[1]); auto n = readln.chomp.to!size_t; auto pi = iota(n) .map!(_ => readln.split) .map!(rd => posWeight(point(rd[0].to!int, rd[1].to!int), rd[2].to!real)).array; pi ~= posWeight(x0, 0); n += 1; auto sumW = pi.map!("a.w").sum; real restW(size_t visited) { return sumW - visited.bitsSet.map!(a => pi[a].w).sum; } auto memo = new real[][](1 << n, n); foreach (size_t i; 1..(1 << n)) { foreach (j; i.bitsSet) { auto k = i; btr(&k, j); auto minT = real.max; if (k == 0) { minT = (pi[j].p - x0).absMan * (100 + sumW); } else { foreach (l; k.bitsSet) { auto t = memo[k][l] + (pi[l].p - pi[j].p).absMan * (100 + restW(k)); minT = min(minT, t); } } memo[i][j] = minT; } } writeln(memo[$-1][$-1] / 120 + sumW); }