Symmetrical Painting
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 32 M,其他语言64 M
64bit IO Format: %lld

题目描述

Initially, the entire coordinate plane is colored white. N rectangles were painted black. The i-th rectangle has bottom-left corner (i-1, L_i)and top-right corner (i,R_i) for . You want to paint some of the black area white so that the remaining black part has a horizontal axis of symmetry. Find the maximum possible area of the remaining black part.

输入描述:

The first line of input contains a single integer N (1 <= N <= 300000), denoting the number of rectangles.

The next N lines of input contain two space-separated integers each, denoting Li, Ri (1 <= Li < Ri <= 109).

输出描述:

Output a single integer, the answer to the problem.
示例1

输入

复制
3
1 5
4 7
2 3

输出

复制
4

说明

It is optimal to paint second rectangle entirely white and a rectangle with bottom-left corner (0, 4) and top-right corner (1, 5) white. Then, the remaining black figure has axis of symmetry at y = 2.5. The remaining black area is 4.