Woburn Challenge 2018-19 Round 2 - Senior Division
A nuclear bomb has been set up somewhere in Vancouver! Ethan Hunt and Solomon Lane have just learned of its location, and are each desperate to reach it first. If Ethan arrives on the scene first, he'll be able to shut it down, while if Solomon beats him to it, he'll surely detonate it to take the entire city down with him!
Vancouver has traffic intersections lined up in a row, numbered from to in order. Ethan is currently at some intersection , while Solomon is at a different intersection , such that and is even. The bomb happens to be located at the intersection which is equidistant from both and (such that ).
Ethan will drive a car through the sequence of intersections , while Solomon will drive through the sequence , until at least one of them arrives at intersection . Though they're both in quite the hurry, disobeying traffic laws would be too reckless, so they'll patiently wait at each intersection until the lights turn green. When a car is at an intersection , it must wait there for minutes before driving onwards to an adjacent intersection (either intersection or ), at which point the car will instantly move to that intersection.
For example, if and , Ethan will spend the first minutes at intersection and the next minutes at intersection , before reaching the bomb (intersection ) after a total of minutes. Meanwhile, Solomon will spend minutes at intersection followed by minutes at intersection , and reach the bomb after minutes. If , then both cars will reach the bomb. Otherwise, the slower car will stop driving as soon as the faster car reaches the bomb.
Meanwhile, Alan Hunley, the secretary of the IMF, will be monitoring the
action closely. He'd like to keep track of how many times the identity
of the agent currently closer to the bomb changes. To do so, he'll first
form a Leader List, which has one entry for each minute (including both
the very beginning, and the moment when a car reaches the bomb)
indicating who is closer to the bomb (distance-wise) at that point in
time. The distance between a car at some intersection and the bomb
(at intersection ) is . Each entry in the Leader List is either
Ethan
, Solomon
, or Neither
(if they're both equidistant from the
bomb), and the first entry (at minute ) is always Neither
. Alan will
then remove all Neither
entries from the Leader List (which may
cause it to become empty). Finally, he will count the number of entries
in the resulting Leader List which are either different than their
preceding entry, or have no preceding entry. This count is formally
known as the CCCC (Closer Car Change Count).
For example, if the initial Leader List is [Neither
, Solomon
,
Ethan
, Neither
, Ethan
, Ethan
, Solomon
], then Alan
will reduce this to [Solomon
, Ethan
, Ethan
, Ethan
,
Solomon
], and determine its CCCC to be (due to its st, nd, and
th entries).
Due to some complex quantum time singularity science, the scenario described above will actually play out separately in one or more parallel universes, just with the initial state varying. Specifically, there is one parallel universe for each possible valid pair of starting intersections and (such that and is even). Considering each possible pair independently, and computing its resulting CCCC value, what's the sum of all of these CCCC values?
Subtasks
In test cases worth of the points, and for each .
In test cases worth of the points, for each .
Input Specification
The first line of input consists of a single integer, .
The next line consists of integers, .
Output Specification
Output a single integer, the sum of all parallel universes' CCCC values.
Sample Input 1
4
5 6 5 3
Sample Output 1
1
Sample Input 2
7
7 3 6 2 5 2 8
Sample Output 2
9
Sample Explanation
In the first case, there are two possible pairs: and
. The CCCC value for the first pair is , as both Ethan and
Solomon will be 1 intersection away from the bomb for minutes , and
then intersections away at minute , resulting in an empty Leader
List. The CCCC value for the second pair is , as Solomon will become
intersections away from the bomb at minute while Ethan is still
intersection away from it, resulting in a Leader List of [Solomon
].
The sum of these CCCCs is then .
In the second case, there are possible pairs, with the following CCCC values:
The sum of these CCCCs is then .
Comments