C: Mirror codes 

Background

Many kids “computers” use some kind of “punched cards” to select the game to play. The card reader has a variable number of switches whose state (on/off) is determined by the corresponding card state (hole/solid) at the switch position.

Thus, if the card reader has n switches, one could believe that the computer could have as much as 2n games to play, but the actual number is a bit smaller. The reason for this is that all cards have two sides with one different game each.


Card side A (code: 000111)

Card side B (code: 111000)
6-bit card example

Binary codes that result in the same code when mirrored cannot be used, as there would be no way to distinguish what card side is being shown to the player, i. e., what game the player wants to play.

The Problem

We will generalize the above problem to find the number of different games that can be coded in a more modern computer whose reader consists of d digits of a different numeric base each. However, these base sequence shall always be mirror-invariable, so that any game code that gets mirrored should make sense for the card reader. In other words, if the reader has d digits whose bases are:

b1 b2 b3 …… bd–2 bd–1 bd 

It will always hold that:

b1 = bd
b2 = bd–1 
b3 = bd–2

, and so forth.

Given a sequence of bases as described above, your program has to determine how many games can be coded so that they can be properly (and uniquely) determined by the number coded in a card that can be reversed to select a different game.

The Input

Each input case is represented by a single line composed by one first positive integer number that represents the number of digits (d), immediately followed by d integer numbers that represent the numeric bases (all of them > 1), as described above.

An input case with d = 0 marks the end of the input. Obviously, this last case should not be processed (no output should be generated for it).

The Output

For each input case (but the last one that marks the end of input) your program should write a line with the number of games that can be coded in the computer, assuming that all games are to be played on a two-sided coded card that should represent a different game for each side.

No leading/trailing blank spaces should appear in these lines, and no blank lines should be written either.

You may assume that the solution for any input case will always fit in a 32-bit integer.

Sample Input

2 2 2
4 2 2 2 2
6 2 2 2 2 2 2
0
  

Sample Output

2
12
56