Villages: Landlines
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

The game development team NIO Tech releases its debut game, Villages: Landlines. In this game, players develop their villages and enjoy their peaceful country life.

The game Villages: Landlines contains a one-dimensional power system. Initially, there are several power stations and buildings. The goal of the game is to make every power stations and buildings connected together in the power system, forming a connected graph. Players can build some power towers and wires in the game, which are the tools to connect power stations and buildings.

Power stations or buildings can connect to power towers without wires, while power towers must connect to each other by wires. What's more, power stations and buildings can't connect to each other directly, they must connect through power towers.

Assuming that the coordinate of a building is x_i and its receiving radius is r_i, all the power towers whose distance from the building is no greater than r_i are directly connected to it without wires. That is to say, for the power tower located at x, it is directly connected to the building at x_i without wires if and only if . Similarly, assuming that the power supply radius of a power station is r_s, all the power towers whose distance from the power station is no more than r_s are directly connected to it without wires. Supposing that the coordinates of two power towers are x_A and x_B, players can connect them with the wire, and the length of wire required is . A power tower can be connected to any number (possibly zero) of power towers, buildings and power stations.

In order to make the game more friendly to the rookies, Nostalgia, a member of NIO Tech, decides to develop the power distribution recommendation function. In the case of using any number of power towers, players can choose exactly one power station and several buildings to get an optimal power supply scheme, which uses the shortest total length of wires to complete the power system. However, Nostalgia is not sure whether her scheme is correct, so she needs your help to calculate the total length of wires used in the optimal scheme to determine the correctness of her scheme.

Note that the players can build a new power tower at coordinate x even if there exists a power station or a building at x. There might be more than one power station or building at the same coordinate.

输入描述:

The first line contains a single integer n ().

The second line contains two integers x_s, r_s () — the coordinate of the power station and its power supply radius.

The i-th line of the next n-1 lines contains two integers x_i, r_i () — the coordinate of i-th building and its receiving radius.

输出描述:

Print an integer in a single line, denoting the total length of wires used in the optimal scheme.
示例1

输入

复制
5
0 1
0 3
5 1
6 1
9 2

输出

复制
1
示例2

输入

复制
2
-1000000000 1000000000
1000000000 1000000000

输出

复制
0

备注:

For the first sample, one possible optimal scheme is building power towers at 1,3,4,6,7, and connect the power towers at 3 and 4 with the wire of length 1.