Solution to TopCoder problems