Polish version    English version  
  History of OI -> V OI 1997/1998 -> 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
Stage III - results
Stage II - results
Stage I - results
Problems
Regulations
Schedule
Stats
IV OI 1996/1997
III OI 1995/1996
II OI 1994/1995
I OI 1993/1994
 OI books
 National team
 Olympic camps
 Photo gallery
 Links
 SIO
 MAIN
Niebieskie ksi.eczki
V Olimpiada Informatyczna 1997/1998

Task: MAL
Author: Wojciech Rytter
Painter's Studio

I stage contest  

The Painter's Studio is preparing mass production of paintings. Paintings are going to be made with aid of square matrices of various sizes. A matrix of size i consists of 2i rows and 2i columns. There are holes on intersections of some rows and columns. Matrix of size 0 has one hole. For i>0, matrix of size i is built of four squares of size 2(i-1)*2(i-1). Look at the following figure ("bez otworow" means "with no holes" in Polish, "matryca stopnia" means "matrix of size"):

[Fig. 1]

Both squares on the right side and the bottom-left square are matrices of size i-1. Top-left square has no holes. Pictures are constructed in the following way. First, we fix three non-negative integers n,x,y. Next, we take two matrices of size n, place one of them onto the other and shift the upper one x columns right and y rows up. We place such a pattern on a white canvas and cover the common part of matrices with the yellow paint. In this way we get yellow stains on the canvas in the places where the holes in both matrices agree.

Example

Consider two matrices of size 2.

[Fig. 2]

The upper matrix was shifted 2 columns right and 2 rows up. There are three places where holes agree.

Task

Write a program that:

  • reads the sizes of two matrices and the numbers of columns and rows that the upper matrix should be shifted by, from the text file MAL.IN;
  • computes the number of yellow stains on the canvas;
  • writes the result to the file MAL.OUT.
Input

There is one integer n, 0<=n<=100 in the first line of the file MAL.IN. This number is the size of matrices used for production of paintings. In the second line there is one integer x and in the third line one integer y, where 0<=x,y<=2^n. The integer x is the number of columns and y is the number of rows that the upper matrix should be shifted by.

Output

In the first line of the output file there should be written the number of stains on the canvas.

Example

For the input file MAL.IN

2
2
2

The correct result is the output file MAL.OUT

3



Print friendly version