using System;
using System.Collections.Generic;
using System.Linq;

namespace cs
{
    public class Program
    {
        public static void Main(string[] args)
        {

            var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);

            var N = input[0];
            var D = input[1];

            var point = new long[N,D];
            long[] hoge;

            for(int i = 0; i < N; i++){
                hoge = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
                for(int k = 0; k < D; k++){
                    point[i,k] = hoge[k];
                }
            }

            int cnt = 0;
            double sum = 0;

            for(int i = 0; i < N-1; i++){
                for(int k = i + 1; k < N; k++){
                    sum = 0;
                    for(int x = 0; x < D; x++){
                        sum += Math.Pow(Math.Abs(point[i,x] - point[k,x]), 2);
                    }
                    if(Math.Sqrt(sum) == (int)Math.Sqrt(sum)){
                        cnt++;
                    }
                }
            }

            Console.WriteLine(cnt);
            //Console.ReadKey();



            /*
            
            var input = Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
            
            var L = input[0];
            var R = input[1];

            var min = new long[2];
            var ans = new long[2];
            min[0] = long.MaxValue;
            ans[0] = int.MaxValue;

            for(long i = L; i <= (L + 2020); i++){
                if(i % 2019 == 0){
                    Console.WriteLine("0");
                    return;
                }
                if(i % 2019 < min[0]){

                    min[1] = min[0];
                    min[0] = i % 2019;
                    ans[1] = ans[0];
                    ans[0] = i;
                    //Console.WriteLine("a");
                }else if(i % 2019 < min[1]){
                    min[1] = i % 2019;
                    ans[1] = i;
                }
            }

           // Console.WriteLine(min[0] + "a" + min[1]);
            Console.WriteLine((ans[0] * ans[1]) % 2019);


           
            */
            




            
            
/*
            Console.WriteLine();
            Console.WriteLine("続行するにはアレ");*/
            //Console.ReadKey();
           
        }

        private static long Factorial(long number)
{
	if (number < 0)
		return -1; //Error

	long result = 1;

	for (long i = 1; i <= number; ++i)
		result *= i;

	return result;
}
public static long ncr2(long n, long r){
    var fact = n;
    var fact2 = r;
    long fact1;
    long per;
            for (long i = n - 1; i >= 1; i--)
            {
                fact = fact * i;
            }
            fact2 = r;
            for (long i = r - 1; i >= 1; i--)
            {
                fact2 = fact2 * i;
            }
            long number;
            number = n - r;
            fact1 = number;
            for (long i = number - 1; i >= 1; i--)
            {
                fact1 = fact1 * i;
            }
            fact1 = fact2 * fact1;
            per = fact / fact1;
            return per;
}
public static long NCR(long n, long r)
{
	return Factorial(n) / (Factorial(r) * Factorial(n - r));
}

        class vec{
            long from{get;set;}
            long to{get;set;}

            public vec(long[] x){
                from = x[0];
                to = x[1];
            }

        }


        public static long modder(){
            return (long)Math.Pow(10,9) + 7;
        }

        public static long GCD(long n, long m){
            
            if(m % n == 0) return n;
            else return GCD(m%n, n);

        }

        public static long LCD(long n, long m){

            return m * n / GCD(n,m);
        }
    }
}


Measured memory_bytes: 11220