# City Horizon

Time Limit: 2000MS

Memory Limit: 65536K

## Description

Farmer John has taken his cows on a trip to the city! As the sun sets, the cows gaze at the city horizon and observe the beautiful silhouettes formed by the rectangular buildings.The entire horizon is represented by a number line with *N* (1 ≤ *N* ≤ 40,000) buildings. Building *i*'s silhouette has a base that spans locations *A*_{i} through *B*_{i} along the horizon (1 ≤ *A*_{i} < *B*_{i} ≤ 1,000,000,000) and has height *H*_{i} (1 ≤ *H*_{i} ≤ 1,000,000,000). Determine the area, in square units, of the aggregate silhouette formed by all *N* buildings.

## Output

Line 1: The total area, in square units, of the silhouettes formed by all *N* buildings

## Hint

The first building overlaps with the fourth building for an area of 1 square unit, so the total area is just 3*1 + 1*4 + 2*2 + 2*3 - 1 = 16.

## Source

USACO 2007 Open Silver