Knights

No attempts yetTime limit1sMemory limit128 MB

Problem

A knight attacks the squares shown in the figure below (the knight on square SS attacks the squares marked with a cross).

You are given a chessboard of size 3×n3 \times n with 3 rows and nn columns, where 1n1001 \le n \le 100, together with a set ZZ of blocked squares. Rows are numbered from top to bottom as 11 through 33, and columns from left to right as 11 through nn.

Knights may be placed only on squares that are not in ZZ, and no two placed knights may attack each other. At most one square in each column belongs to ZZ. The set ZZ is given by a sequence k1,k2,,knk_1, k_2, \ldots, k_n with each ki{0,1,2,3}k_i \in \{0, 1, 2, 3\}: if ki=0k_i = 0 then no square in column ii is blocked, otherwise kik_i is the row index of the single blocked square in column ii.

Compute the maximum number of knights MM that can be placed under these rules, and LL, the number of distinct placements of exactly MM knights.

Input

The first line contains one integer nn (1n1001 \le n \le 100), the number of columns. Each of the next nn lines contains one integer from {0,1,2,3}\{0, 1, 2, 3\}, giving the terms k1,k2,,knk_1, k_2, \ldots, k_n that describe ZZ.

Output

Print two integers MM and LL separated by a single space: the maximum number of knights, and the number of placements that achieve this maximum.