
fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val A = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    accumulate(A, M)
    val B = A

    val map = mapOf<Int, MutableList<Int>>().toMutableMap()
    B.forEachIndexed { i, a ->
        val x = a.mod(M)

        if (map.contains(x)) {
            map[x]!!.add(i)
        } else {
            map[x] = listOf(i).toMutableList()
        }
    }

    val ans = map.keys.map { key ->
        var count = map.get(key)!!.size
        if (key == 0) {
            count++
        }
        count * (count - 1) / 2
    }.reduce { sum, unit -> sum + unit }
    println(ans)
}


fun accumulate(A: MutableList<Int>, M: Int) {
    for (i in 1..(A.size - 1)) {
        A[i] += A[i-1].mod(M)
    }
}
