implicit none
integer :: n,m
integer,allocatable :: a(:),res1(:),cnt1(:),res2(:),cnt2(:)
integer(8) :: s
integer :: i,j,nres1,nres2,b
logical :: flg

read *,n,m
allocate(a(n))
read *,a

allocate(cnt1(0:n))
allocate(res1(0:n))
allocate(cnt2(0:n))
allocate(res2(0:n))

res1(:) = -1
res1(0) = 0
cnt1(:) = 0
cnt1(0) = 1
res2(:) = -1
res2(0) = 0
cnt2(:) = 0
cnt2(0) = 1
nres1 = 0
nres2 = 0
b = 0
s = 0
do i = 1, n
   b = mod(b + a(i),m)
   flg = .false.
   if (b < m/2) then
   do j = 0, nres1
      if (res1(j) == b) then
         s = s + cnt1(j)
         cnt1(j) = cnt1(j) + 1
         flg = .true.
         exit
      endif
   enddo
   if (.not. flg) then
      nres1 = nres1 + 1
      res1(nres1) = b
      cnt1(nres1) = 1
   endif
   else
      do j = 0, nres2
      if (res2(j) == b) then
         s = s + cnt2(j)
         cnt2(j) = cnt2(j) + 1
         flg = .true.
         exit
      endif
   enddo
   if (.not. flg) then
      nres2 = nres2 + 1
      res2(nres1) = b
      cnt2(nres1) = 1
   endif
   endif
enddo

print '(i0)',s
end