I was trying to solve this problem on spoj. http://www.spoj.com/problems/WILD/
If we treat each evil candidate as a point and consider the cube (0,0,0) — (x,y,z). The problem is reduced to finding the volume of union of cubes. The answer in this case will be m^3 — volume.
The complexity is turning out to be n*n*log(n). Can anyone suggest a better algorithm?