Perpendicularia has only two directions, vertical and horizontal. The government is going to build a new intelligence service facility. Several plans are on the table, and for each of them the government wants the total secured perimeter.
The total secured perimeter is the total length of the facility walls that an outside observer looking along an axis direction cannot see. A point of a wall is visible when the ray that leaves that point perpendicular to the wall, pointing away from the facility, never meets the facility again. Every other point of a wall is invisible.
The figure below shows one of the plans, with its secured perimeter drawn in bold.

Write a program that calculates the total secured perimeter of the given plan.