Solution to SPOJ ADDREV