
import java.io.PrintWriter

val squares = (1..127).map { it * it }

fun check(x: List<Int>, y: List<Int>): Boolean {
    val distanceSquared = x.zip(y).map { (it.first - it.second) * (it.first - it.second)}.sum()
    return distanceSquared in squares
}

fun solve(out: PrintWriter): Boolean = with(out) {
    val (N, D) = readLine()!!.split(" ").map { it.toInt() }
    val X = (1..N).map { readLine()!!.split(" ").map { it.toInt() } }

    var cnt = 0;
    for (i in 0 until N-1) {
        for( j in i+1 until N) {
            if (check(X[i], X[j]))
                cnt++;
        }
    }

    println(cnt);
    return false
}

// with(PrintWriter(System.out))
// with(File("out.txt").printWriter())
// with(File(args[1]).printWriter())
fun main(args: Array<String>) = with(PrintWriter(System.out)){
//    System.setIn(File(args[0]).inputStream())
    while(solve(this));
    flush()
}