fun main(args: Array<String>) {
    val input: List<List<Int>> =
            System.`in`.bufferedReader()
                    .readLines()
                    .map { it.split(" ").map { it.toInt() } }
                    .drop(1)
    val n = input.size
//    val d = input[0].size

    val maxCase = 40 * 40 * 10
    val set = mutableSetOf<Int>()
    var c = 0
    var v = 0
    while (v <= maxCase) {
        set.add(v)
        c++
        v = c * c
    }

    var count = 0
    for (i in 0 until n) {
        for (j in i+1 until n) {
            val di = ccc(input[i], input[j])
            if (set.contains(di)) {
                count++
            }
        }
    }
    print(count)
}

fun ccc(al: List<Int>, bl: List<Int>): Int {
    var sum = 0
    for (i in 0 until al.size) {
        val a = al[i]
        val b = bl[i]
        sum += (a - b) * (a - b)
    }
    return sum
}
