We will first solve Shape 1 and Shape 2 to understand the logic.