#B3815. Spicy Rabbit Head Dice Tower

    ID: 11472 Type: Default 1000ms 256MiB

Spicy Rabbit Head Dice Tower

Spicy Rabbit Head Dice Tower

In this problem, you are given a tower of N dice. However, these dice are non-standard: each die has its faces numbered 1 to 6 and the opposite pairs are fixed as \(1\leftrightarrow2\), \(3\leftrightarrow4\), and \(5\leftrightarrow6\). The dice are stacked vertically, and from the bottom to the top the i-th die shows a number \(P_i\) on its upward (top) face.

The total spiciness level of the dish is determined by the sum of all the numbers on the faces of the dice that are exposed to air. In a dice tower, the following faces are not exposed:

  • The bottom face of the bottom die (since it is on the table).
  • The top face of any die except the topmost one (since it touches the die above).

For each die, the sum of the numbers on all six faces is 21. Thus, if the upward face is \(P\) and its opposite face is \(opp(P)\), then the sum of the four side faces is \(21 - (P + opp(P))\). Consequently:

  • For every die except the topmost, only the four side faces are exposed with a contribution of \(21 - (P + opp(P))\).
  • For the topmost die, the top face is also exposed, so its contribution is \(P + [21 - (P + opp(P))] = 21 - opp(P)\).

Your task is to compute the total spiciness level of the dice tower based on the given upward faces.

Note: The mapping for the opposite face is as follows:

  • If \(P=1\) then \(opp(P)=2\) and vice versa.
  • If \(P=3\) then \(opp(P)=4\) and vice versa.
  • If \(P=5\) then \(opp(P)=6\) and vice versa.

inputFormat

The first line contains an integer \(N\) (the number of dice in the tower).

The second line contains \(N\) space-separated integers \(P_1, P_2, \ldots, P_N\), where \(P_i\) (\(1 \leq P_i \leq 6\)) is the number on the upward face of the i-th die from the bottom.

outputFormat

Output a single integer representing the total spiciness level, which is the sum of the numbers on all faces exposed to air.

sample

1
1
19