Lattice distortion and magnetolattice coupling in CuO