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
Ethan will drive a car through the sequence of intersections
For example, if
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 Ethan
, Solomon
, or Neither
(if they're both equidistant from the
bomb), and the first entry (at minute 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 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
Subtasks
In test cases worth
In test cases worth
Input Specification
The first line of input consists of a single integer,
The next line consists of
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 Solomon
].
The sum of these CCCCs is then
In the second case, there are
The sum of these CCCCs is then
Comments