Polish version    English version  
  About Olympic -> Problems


 News
 About Olympic
About contest
Problems
I OI 1993/1994
II OI 1994/1995
III OI 1995/1996
IV OI 1996/1997
V OI 1997/1998
VI OI 1998/1999
VII OI 1999/2000
VIII OI 2000/2001
IX OI 2001/2002
X OI 2002/2003
XI OI 2003/2004
XII OI 2004/2005
XIII OI 2005/2006
XIV OI 2006/2007
XV OI 2007/2008
Problems archive
 History of OI
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
VI Olimpiada Informatyczna 1998/1999

Task: TRO
Author:
Three-coloring of binary trees

III stage contest  

A tree consists of a node and some (zero, one or two) subtrees connected to it. These subtrees are called children.

A specification of the tree is a sequence of digits. If the number of children in the tree is:

  • zero, then the specification is a sequence with only one element '0';
  • one, the specification begins with '1' followed by the specification of the child;
  • two, the specification begins with '2' followed by the specification of the first child, and then by the specification of the second child.

Each of the vertices in the tree must be painted either red or green or blue.
However, we need to obey the following rules:

  • the vertex and its child cannot have the same color,
  • if a vertex has two children, then they must have different colors.

How many vertices may be painted green?

Task

Write a program which:

  • reads the specification of the tree from the text file TRO.IN,
  • computes the maximal and the minimal number of vertices that may be painted green,
  • writes the results in the text file TRO.OUT.

Input

The first and only line of the input file TRO.IN consists of one word (no longer then 10000 characters), which is a specification of a tree.

Output

Your program should write in the first and only line of the output file TRO.OUT exactly two integers separated by a single space, which respectively denote the maximal and the minimal number of vertices that may be painted green.

Example

For the input file TRO.IN:

1122002010

the correct answer is the output file TRO.OUT:

5 2



Print friendly version