My code from SRMs of TopCoder