import math

def main():



    x = []

    N, D = list(map(int, input().split()))

    for _ in range(N):

        y = list(map(int, input().split()))

        x.append(y)

    ans = 0

    for i in range(N):

        for j in range(i):

            d1 = 0

            for k in range(D):

                d1 += pow(x[i][k]-x[j][k], 2)

            d1 = math.sqrt(d1)

            if d1 == int(d1): ans += 1

    return ans



if __name__ == '__main__':

    print((main()))
import math

def main():

    N, D = list(map(int, input().split()))

    pt = []

    for _ in range(N):

        p = list(map(int, input().split()))

        pt.append(p)



    ans = 0

    for i in range(N):

        for j in range(i):

            l = 0

            for k in range(D):

                l += pow(pt[i][k]-pt[j][k], 2)

            l = math.sqrt(l)

            if l == int(l): ans += 1

    return ans



if __name__ == '__main__':

    print((main()))

import math


def main():
    x = []
    N, D = list(map(int, input().split()))
    for _ in range(N):
        y = list(map(int, input().split()))
        x.append(y)
    ans = 0
    for i in range(N):
        for j in range(i):
            d1 = 0
            for k in range(D):
                d1 += pow(x[i][k] - x[j][k], 2)
            d1 = math.sqrt(d1)
            if d1 == int(d1):
                ans += 1
    return ans


if __name__ == "__main__":
    print((main()))

import math


def main():
    N, D = list(map(int, input().split()))
    pt = []
    for _ in range(N):
        p = list(map(int, input().split()))
        pt.append(p)
    ans = 0
    for i in range(N):
        for j in range(i):
            l = 0
            for k in range(D):
                l += pow(pt[i][k] - pt[j][k], 2)
            l = math.sqrt(l)
            if l == int(l):
                ans += 1
    return ans


if __name__ == "__main__":
    print((main()))

-    x = [] +    pt = [] -        y = list(map(int, input().split())) -        x.append(y) +        p = list(map(int, input().split())) +        pt.append(p) -            d1 = 0 +            l = 0 -                d1 += pow(x[i][k] - x[j][k], 2) -            d1 = math.sqrt(d1) -            if d1 == int(d1): +                l += pow(pt[i][k] - pt[j][k], 2) +            l = math.sqrt(l) +            if l == int(l):