import java.util.Scanner
import java.util.ArrayList

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val D = sc.nextInt()
    var arraylist = ArrayList<ArrayList<Int>>()
    for(i in 0 until N){
        arraylist.add(ArrayList<Int>())
        for(j in 0 until D){
            arraylist.elementAt(i).add(sc.nextInt())
        }
    }
    var counter = 0
    for(i in 0 until N - 1){
        for(j in i + 1 until N){
           var sum = 0
            for(k in 0 until D) {
                val point_i = arraylist.elementAt(i).elementAt(k)
                val point_j = arraylist.elementAt(j).elementAt(k)
                sum += (point_i - point_j) * (point_i - point_j)
            }
            var element = 1
            while(element * element <= sum){
                if(element * element == sum){
                    counter++
                    break
                }
                element++
            }
        }
    }
    println(counter)


}