Code changed slightly after submission. Changes are mainly in Input/Output. Algorithm remains same.