Calculating perimeter and cost