cho.sh
Notes
Loading...

Platform Support Pillars

Time limit

2s

Memory limit

128 MB

Problem

A level for a new platform game is being designed. The platform positions have already been chosen. A platform cannot float in the air, so it needs support pillars. More precisely, each platform needs a pillar placed 0.5 units inward from each end, and each pillar must stand on the floor or on a lower platform.

Each platform is described by its height Y, horizontal start coordinate X1, and horizontal end coordinate X2. The pillars drop vertically at the position 0.5 units to the right of the left end and 0.5 units to the left of the right end.

Find the total length of pillars needed to support all platforms.

Diagram of a level with three platforms. The lowest platform is at height 1, the next platform is at height 3, and the top platform is at height 5.In this arrangement, the total length of pillars needed is 14.

Input

The first line contains an integer N (1 ≤ N ≤ 100), the number of platforms.

Each of the next N lines contains three integers Y, X1, and X2, describing one platform. Y is the height, while X1 and X2 are the horizontal start and end coordinates. All coordinates are positive integers less than 10000, and X2 > X1 + 1, so every platform has length at least 2.

The input is arranged so that no two platforms overlap.

Output

Output the total length of pillars needed to support all platforms.