module IMap=Map.Make(Int64);;
let(++),(--),( **),(//),(%)=Int64.(add,sub,mul,div,rem)
in Scanf.(Array.(scanf" %d %Ld"@@fun n m->
	let a=make(n+1)0L in for i=1 to n do a.(i)<-scanf" %Ld"@@fun v->v++a.(i-1)done;
	IMap.(fold_left(fun u v->let r=v%m in add r(1L++try find r u with Not_found->0L)u)empty a
		|>bindings|>List.fold_left(fun u(_,c)->u++(c**(c--1L))//2L)0L
		|>Int64.to_string|>print_endline)))