fun main(args: Array<String>) {
    val (N, M) = readInputLine().split(" ").map { it.toInt() }
    val cntMap = mutableMapOf<Int, Int>()
    
    val aList = readInputLine().split(" ").map { it.toInt() % M }
    
    aList.fold(0) { acc, num -> 
        val newAcc = (acc + num) % M
        val cnt = cntMap.get(newAcc) ?: 0
        cntMap.put(newAcc, cnt + 1)
        newAcc
    }

    var ans = 0L
    var acc = 0
    
    for (a in aList) {
        val cnt = cntMap.get(acc) ?: 0
        ans += cnt.toLong()
        acc = (acc + a) % M
        val newCnt = cntMap.get(acc) ?: 0
        cntMap.put(acc, newCnt - 1)
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}
