# Arup Guha
# 4/19/2025
# Solution to Kattis Problem: Are You Listening?
# https://open.kattis.com/problems/areyoulistening

# Returns the distance between pt1 and pt2.
def getDist(pt1, pt2):
    dsq = 0
    for i in range(len(pt1)):
        dsq += (pt1[i]-pt2[i])*(pt1[i]-pt2[i])
    return dsq**.5

# Get first line.
toks = input().split()

# I am going to try a tuple for the center.
myC = (int(toks[0]), int(toks[1]))

# number of circles.
n = int(toks[2])

# This will be the distance to each circle.
dist = []
for i in range(n):

    toks = input().split()
    yourC = (int(toks[0]), int(toks[1]))
    yourR = int(toks[2])
    dist.append(getDist(myC, yourC)- yourR)

# Sort this from small to big.
dist.sort()

# This is what they want.
print(max(0, int(dist[2]+1e-9)))



    

    

    
