import java.math.BigDecimal
import java.util.*

fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val n = sc.nextInt()
    val d = sc.nextInt()

    val a: List<List<Int>> = (1..n).map {
        sc.asSequence().take(d).map(String::toInt).toList()
    }.toList()

    var r = 0;
    a.forEachIndexed { i, iL ->
        for (j in i + 1 until n) {
            val jL = a[j]
            val x: Int = (0 until d).map { iL[it] - jL[it] }.map { it * it }.sum()
            val y = Math.sqrt(x.toDouble())
            if (Math.floor(y) == y) r++
        }
    }

    println(r)
}
