Domino
Time limit10sMemory limit1024 MB
Find the smallest width n of a 2 x n board where painting some cells leaves exactly m domino tilings of the rest, or report NIE.
- Level
Medium7 of 10
- Topics
- Math, Dynamic programming, Number theory
- Solved
- No attempts yet
Problem
Bajtek plays a game of covering rectangles with domino tiles. A rectangle of width consists of unit cells, and Bajtek may paint over some of them. He wants every unpainted cell to be coverable by dominoes without overlap. Tiles may be rotated. He also wants this to be possible in exactly ways. Last, he wants the smallest rectangle that can be covered this way. Can you help him?
The figure below shows a rectangle of width with two cells painted over. The other 10 cells can be covered by dominoes in exactly 4 ways. The figure shows two of these ways. The tiles are drawn slightly smaller for clarity.

This arrangement is not optimal for , because an arrangement with exists.
Input
The first and only line contains one natural number ().
Output
The first and only line must contain one natural number , the smallest possible width of a rectangle that can be painted and covered in exactly ways. If no such rectangle exists, print only the word NIE instead.