#!/usr/bin/python3

# -*- coding: utf-8 -*-







def main():

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

  Xn = []

  for _ in range(N):

    Xn.append(list(map(int, input().split())))



  ans = 0

  ansset = [i**2 for i in range(1001)]

  for i in range(N):

    for j in range(i+1,N):

      sm = 0

      for k in range(D):

        sm += (Xn[i][k]-Xn[j][k])**2

      if sm in ansset:

        ans += 1

  print(ans)





if __name__ == "__main__":

  main()
#!/usr/bin/python3

# -*- coding: utf-8 -*-







def main():

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

  Xn = [list(map(int, input().split())) for _ in range(N)]



  sqrtset = [i**2 for i in range(1000)]



  ans = 0

  for i in range(N):

    for j in range(i+1,N):

      sm = 0

      for d in range(D):

        sm += (Xn[i][d]-Xn[j][d])**2

      if sm in sqrtset:

        ans += 1



  print(ans)





if __name__ == "__main__":

  main()
#!/usr/bin/python3
# -*- coding: utf-8 -*-
def main():
    N, D = list(map(int, input().split()))
    Xn = []
    for _ in range(N):
        Xn.append(list(map(int, input().split())))
    ans = 0
    ansset = [i**2 for i in range(1001)]
    for i in range(N):
        for j in range(i + 1, N):
            sm = 0
            for k in range(D):
                sm += (Xn[i][k] - Xn[j][k]) ** 2
            if sm in ansset:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

#!/usr/bin/python3
# -*- coding: utf-8 -*-
def main():
    N, D = list(map(int, input().split()))
    Xn = [list(map(int, input().split())) for _ in range(N)]
    sqrtset = [i**2 for i in range(1000)]
    ans = 0
    for i in range(N):
        for j in range(i + 1, N):
            sm = 0
            for d in range(D):
                sm += (Xn[i][d] - Xn[j][d]) ** 2
            if sm in sqrtset:
                ans += 1
    print(ans)


if __name__ == "__main__":
    main()

-    Xn = [] -    for _ in range(N): -        Xn.append(list(map(int, input().split()))) +    Xn = [list(map(int, input().split())) for _ in range(N)] +    sqrtset = [i**2 for i in range(1000)] -    ansset = [i**2 for i in range(1001)] -            for k in range(D): -                sm += (Xn[i][k] - Xn[j][k]) ** 2 -            if sm in ansset: +            for d in range(D): +                sm += (Xn[i][d] - Xn[j][d]) ** 2 +            if sm in sqrtset: