program p1;
var u,s,n,m,i,y,z,k:integer;
x : array[1..100000,1..10000] of integer;
begin
readln(n,m);
s:=0;
u:=0;
for i:=1 to n do begin
read(k);
for z:=1 to m do begin
if k=m then k:=0;
if k>0 then x[i,z]:=1;
if k<=0 then x[i,z]:=0;
k:=k-1;
end;
end;
  
FOR y := 1 TO m DO BEGIN
FOR i := 1 TO n DO begin 
s:=s+x[i,y];
end;
if s=n then s:=0;
u:=u+s*(n-s);
s:=0;
end;
writeln(u);

END.