invert.cpp modified