output_description: Print the number of the pairs (l, r) that satisfy the conditions.
  
  Note that the number may not fit into a 32-bit integer type.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M
      A_1 A_2 ... A_N
attempt: ###############################################################################
  
  from sys import stdout
  from bisect import bisect_left as binl
  from copy import copy, deepcopy
  from collections import defaultdict
  
  
  mod = 1
  
  
  def intin():
      input_tuple = input().split()
      if len(input_tuple) <= 1:
          return int(input_tuple[0])
      return tuple(map(int, input_tuple))
  
  
  def intina():
      return [int(i) for i in input().split()]
  
  
  def intinl(count):
      return [intin() for _ in range(count)]
  
  
  def modadd(x, y):
      global mod
      return (x + y) % mod
  
  
  def modmlt(x, y):
      global mod
      return (x * y) % mod
  
  
  def lcm(x, y):
      while y != 0:
          z = x % y
          x = y
          y = z
      return x
  
  
  def combination(x, y):
      assert x >= y
  
      if y > x // 2:
          y = x - y
  
      ret = 1
  
      for i in range(0, y):
          j = x - i
          i = i + 1
  
          ret = ret * j
          ret = ret // i
  
      return ret
  
  
  def get_divisors(x):
      retlist = []
      for i in range(1, int(x**0.5) + 3):
          if x % i == 0:
              retlist.append(i)
              retlist.append(x // i)
      return retlist
  
  
  def get_factors(x):
      retlist = []
      for i in range(2, int(x**0.5) + 3):
          while x % i == 0:
              retlist.append(i)
              x = x // i
      retlist.append(x)
      return retlist
  
  
  def make_linklist(xylist):
      linklist = {}
      for a, b in xylist:
          linklist.setdefault(a, [])
          linklist.setdefault(b, [])
          linklist[a].append(b)
          linklist[b].append(a)
      return linklist
  
  
  def calc_longest_distance(linklist, v=1):
      distance_list = {}
      distance_count = 0
      distance = 0
      vlist_previous = []
      vlist = [v]
      nodecount = len(linklist)
  
      while distance_count < nodecount:
          vlist_next = []
          for v in vlist:
              distance_list[v] = distance
              distance_count += 1
              vlist_next.extend(linklist[v])
          distance += 1
          vlist_to_del = vlist_previous
          vlist_previous = vlist
          vlist = list(set(vlist_next) - set(vlist_to_del))
  
      max_distance = -1
      max_v = None
      for v, distance in distance_list.items():
          if distance > max_distance:
              max_distance = distance
              max_v = v
  
      return (max_distance, max_v)
  
  
  def calc_tree_diameter(linklist, v=1):
      _, u = calc_longest_distance(linklist, v)
      distance, _ = calc_longest_distance(linklist, u)
      return distance
  
  
  ###############################################################################
  
  
  def main():
      n, m = intin()
      alist = intina()
      alist.insert(0, 0)
  
      asumlist = []
      asum = 0
      for a in alist:
          asum += a
          asumlist.append(asum)
  
      asumlist = [asum % m for asum in asumlist]
      asumlist.sort()
      asumlist.append(None)
  
      ans = 0
      asum_now = None
      asum_count = 0
      for asum in asumlist:
          if asum == asum_now:
              asum_count += 1
          else:
              if asum_count >= 2:
                  ans += combination(asum_count, 2)
              asum_now = asum
              asum_count = 1
  
      print(ans)
  
  
  if __name__ == "__main__":
      main()
  
problem_description: Statement
  
  There are N boxes arranged in a row from left to right. The i-th box from the
  left contains A_i candies.
  
  You will take out the candies from some consecutive boxes and distribute them
  evenly to M children.
  
  Such being the case, find the number of the pairs (l, r) that satisfy the
  following:
  
    * l and r are both integers and satisfy 1 \leq l \leq r \leq N.
    * A_l + A_{l+1} + ... + A_r is a multiple of M.
samples: [{"input": "3 2\n    4 1 5", "output": "3\n    \n\nThe sum A_l + A_{l+1} + ... + A_r for each pair (l, r) is as follows:\n\n  * Sum for (1, 1): 4\n  * Sum for (1, 2): 5\n  * Sum for (1, 3): 10\n  * Sum for (2, 2): 1\n  * Sum for (2, 3): 6\n  * Sum for (3, 3): 5\n\nAmong these, three are multiples of 2.\n\n* * *"}, {"input": "13 17\n    29 7 5 7 9 51 7 13 8 55 42 9 81", "output": "6\n    \n\n* * *"}, {"input": "10 400000000\n    1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000", "output": "25"}]