For the square, we have that each side's length is 2p, since the perimeter is the sum of the length of all sides of a geometric figure, this means that we have to add all the lengths of the square like this:

And we can do the same with the 3 sides of the triangle:
