using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;

namespace A
{
    class Program
    {
        public IEnumerable<string> Solve()
        {
            //var ut = new Util();
            var sc = new Scanner();

            var n = sc.Num;
            var d = sc.Num;

            List<int[]> xs = new List<int[]>();

            for (int i = 0; i < n; i++)
            {
                xs.Add(sc.Nums(d));
            }

            var res = 0;

            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    var sqr = xs[i].Zip(xs[j], (a, b) => (a - b) * (a - b)).Sum();

                    var sqrt = Math.Floor(Math.Sqrt(sqr));

                    if (sqrt * sqrt == sqr)
                        res++;
                }
            }

            yield return res.ToString();
        }
    }

    class StartingPoint
    {
        static void Main(string[] args)
        {
            if (args?.Any() == true)
            {
                var assembly = Assembly.GetEntryAssembly();
                var resourceName = "AtCoderCSharp.In.txt";
                var stream = assembly.GetManifestResourceStream(resourceName);
                var streamReader = new StreamReader(stream, Encoding.UTF8);
                var str = streamReader.ReadToEnd();
                var textReader = new StringReader(str);
                Console.SetIn(textReader);
            }

            try
            {
                foreach (var s in new Program().Solve())
                {
                    Console.WriteLine(s);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                if (args?.Any() != true)
                    throw e;
            }

            if (args?.Any() == true)
                Console.ReadKey();
        }
    }

    class Scanner
    {
        public int[] Nums(int count) => Enumerable.Range(0, count).Select(_ => Num).ToArray();
        public int Num => int.Parse(Str);
        public long NumLong => long.Parse(Str);
        public double NumDouble => (double)NumLong;

        StringBuilder sb = new StringBuilder();

        public string Str => GetStr();
        public string GetStr()
        {
            sb.Clear();

            int r = 0;
            bool? b = null;
            do
            {
                r = Console.Read();
                b = IsBreak(r);
            } while (b == true);

            if (b == null)
                throw new Exception("input error: unexpected end of stream");

            do
            {
                sb.Append((char)r);
                r = Console.Read();
                b = IsBreak(r);
            } while (b == false);

            return sb.ToString();
        }

        bool? IsBreak(int c)
        {
            switch (c)
            {
                case -1:
                    return null;
                case (int)' ':
                case (int)'\n':
                case (int)'\r':
                    return true;
                default:
                    return false;
            }
        }
    }
}

Measured memory_bytes: 13524