# solving the triangles problem - version 3
# defining the content of the innermost loop as a single atomic operation
# (which takes a constant time),
# and p as the input size,
# the complexity is O(p**2)
def nirt_v3(p):
cnt = 0
for a in range(1,p):
for b in range(a,p):
c = p-a-b
if a*a+b*b == c*c:
cnt += 1
return cnt