# Arup Guha
# 2/11/2026
# Solution to Robot Challenge (used for COP 4516 DP #1)

# Returns distance from pt i to pt j.
def dist(x,y,i,j):
    return ((x[i]-x[j])**2 + (y[i]-y[j])**2)**.5
            
# Process cases.
n = int(input())
while n != 0:

    # Starting pt.
    x = [0]
    y = [0]
    p = [0]

    # Read in data.
    for i in range(n):
        toks = input().split()
        x.append(int(toks[0]))
        y.append(int(toks[1]))
        p.append(int(toks[2]))

    # Ending location.
    x.append(100)
    y.append(100)
    p.append(0)

    # Just add this into my targets.
    n+=2
    
    # Prefix sum array of penalty.
    sump = [0]
    for i in range(n):
        sump.append(sump[-1]+p[i])

    # DP array. will add on answers.
    dp = [0]

    # Go through targets.
    for i in range(1,n):

        # Initially build off last.
        cur = dp[-1] + dist(x,y,i-1,i) + 1

        # j is the last place you visited, so you skipped j, j+1, ...i-1
        # But my location numbers are off by one in the prefix sum array.
        # The prefix sum array can add up all of those penalties for you.
        for j in range(0,i-1):
            alt = dp[j] + dist(x,y,j,i) + 1 + sump[i] - sump[j+1]
            cur = min(cur, alt)

        # Add this answer for dp[i]
        dp.append(cur)

    # Get output.
    print(f"{dp[-1]:.3f}")

    # Get next case.
    n = int(input())

    
    
