Public Class Compiler
    Shared Sub Main()
        Dim input As String() = Console.ReadLine().Split(" ")
        Dim n As Integer = Integer.Parse(input(0))
        Dim d As Integer = Integer.Parse(input(1))
        Dim xs(0 To n - 1)() As Integer
        For i As Integer = 0 To n - 1
            xs(i) = Array.ConvertAll(Of String, Integer)(Console.ReadLine().Split(" "), AddressOf Integer.Parse)
        Next
        Dim output As Integer = 0
        For i As Integer = 0 To n - 2
            For j As Integer = i + 1 To n - 1
                Dim yz As Integer = 0
                For k As Integer = 0 To d - 1
                    yz += Math.Pow(xs(i)(k) - xs(j)(k), 2)
                Next
                Dim sqyz As Double = Math.Sqrt(yz)
                If sqyz = CType(sqyz, Integer) Then output += 1
            Next
        Next
        Console.WriteLine(output)
    End Sub
End Class