##### Woburn Challenge 2015-16 Round 2 - Senior Division

*"You know I don't like it when you do that."
"Sorry, master. I forgot that you don't like coding."
"I don't mind coding, but what you're doing is suicide!"*

Upon thwarting an attempt on Senator Amidala's life, Obi-Wan Kenobi and Anakin Skywalker must pursue the bounty hunter Zam Wesell through the bustling streets of Coruscant in order to apprehend and question her. Unfortunately, they've already lost her trail! Fortunately, they have some ideas of where she might be hiding.

The city of Coruscant is laid out in a regular grid of intersections. There are many parallel avenues running North-South, numbered from West to East starting from . Similarly, there are many parallel streets running East-West, numbered from North to South starting from . The position where street and avenue intersect can be denoted as .

All of the streets and avenues are one-way, and even in this emergency, the Jedi must respect the law. Every avenue may only be travelled along towards the South. However, the directions of the streets alternate – every odd-numbered street may only be travelled along towards the East, while every even-numbered street may only be travelled along towards the West. It takes minute to travel from a certain intersection to an adjacent one (either to the South, East, or West, while obeying the traffic laws).

The Jedi are currently in the Senate building at intersection . There are potential locations at which Zam might be hiding, numbered from to in decreasing order of likelihood, with the -th one being intersection . None of the locations is , and no two of them are at the same intersection.

A decision must be made on how many of the locations to try. As such, for every in the range , you must determine the minimum amount of time (in minutes) that it would take for the Jedi to theoretically visit all of the first locations (in any order), starting from .

In test cases worth 75% of the points, .

In a subset of those cases worth 30% of the points, ,
, and .

#### Input Specification

The first line of input consists of a single integer .

The next lines each consist of two space-separated integers
and , for .

#### Output Specification

The output should consist of lines, where the -th line is a single integer representing the minimum amount of time (in minutes) that it would take for the Jedi to theoretically visit all of the first locations (in any order), starting from .

#### Sample Input

```
7
5 3
5 2
2 4
6 1
1 4
3 1
6 6
```

#### Sample Output

```
6
6
10
13
13
15
21
```

#### Explanation

The following diagram depicts the scenario in the sample input. Green represents the senate building, blue represents a normal intersection, and yellow represents potential locations at which Zam might be hiding.

## Comments