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
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
The Jedi are currently in the Senate building at intersection
A decision must be made on how many of the locations to try. As such,
for every
In test cases worth 75% of the points,
In a subset of those cases worth 30% of the points,
Input Specification
The first line of input consists of a single integer
The next
Output Specification
The output should consist of
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