Polish version    English version  
  History of OI -> III OI 1995/1996 -> Problems


 News
 About Olympic
 History of OI
XVII OI 2009/2010
XVI OI 2008/2009
XV OI 2007/2008
XIV OI 2006/2007
XIII OI 2005/2006
XII OI 2004/2005
XI OI 2003/2004
X OI 2002/2003
IX OI 2001/2002
VIII OI 2000/2001
VII OI 1999/2000
VI OI 1998/1999
V OI 1997/1998
IV OI 1996/1997
III OI 1995/1996
Stage III - results
Stage II - results
Stage I - results
Problems
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
III Olympiad in Informatics 1995/1996

Task: NIE
Author: Wojciech Rytter
Knights

III stage contest  

A knight attacks squares on the chess-board as is show in figure 1.

rysunek objaśniający, jak atakuje skoczek szachowy
Figure 1: A knight on the square S attacks squares x.

There is a chess-board of dimensions 3 * n, with 3 rows and n columns, where 1 <= n <= 100, and there is a set Z of fields on the chess-board. The rows are numbered from the top to the bottom with numbers from 1 to 3, the columns from the left to the right with numbers from 1 to n.

Knights can be put only on the squares from the set Z and no two of them can attack each other.

We assume that in each column at most one field belongs to the set Z. Thus the set Z may be described with a series: k1, k2, ... , kn, where ki belongs to {0, 1, 2, 3}. If ki = 0 then no field in the i-th column belongs to the set Z, else ki is a number of a row of the only field in this column, which belongs to Z.

Task

Write a program that:
  • reads from the text file NIE.IN the number of columns on the chess-board n and the description of the set Z,
  • computes the maximal number of knights M, that may be put on the chess-board according to the given rules, and L - the number of possible arrangements of M knights on this chess-board,
  • writes the results into the text file NIE.OUT.

Input

In the first line of the text file NIE.IN there is written one positive integer n<=100. This is the number of columns in the chess-board. In each of the following n lines there is written one number form the set {0, 1, 2, 3}. These are the consecutive terms of the series describing the set Z.

Output

In the text file NIE.OUT  two integers M and L separated by a single space should be written.

Example

For the input file NIE.IN:
2
1
0
 
the correct answer is the output file NIE.OUT:
4 2

Your program should look for the file NIE.IN in the current directory and produce the output file NIE.OUT in the current directory too. The file containing the source code of your program should have a name NIE.???, whereas you should put three-letter abbreviation of the used programming language name instead of ???. The same program in executable form should be written in file NIE.EXE




Print friendly version