code for replacement problem