#P4663. [BalticOI 2008] 魔法石 (Day1)

[BalticOI 2008] 魔法石 (Day1)

Description

The famous stone Xi-n-k\text{Xi-n-k} can only be found in Wonderland. Such a stone is a granite slab engraved with an inscription consisting only of the letters X and I. Each slab contains nn letters. On each slab, there are at most kk positions where X and I are adjacent.

The top and bottom of a slab are not fixed, so the stone can be rotated and become upside down. For example, the following two pictures describe the same stone.

0

【Two ways to view the same stone. This stone is of type Xi-8-3\text{Xi-8-3}, and also Xi-8-4\text{Xi-8-4} (of course it can also be Xi-8-k\text{Xi-8-}k, k3k \ge 3).】

Now, in Wonderland, no two magic stones are the same, meaning that no two stones have the same inscription (note that a 180180^\circ rotation is considered the same).

If a stone’s inscription can be read in two different ways (by rotating it 180180^\circ), then the standard way to read the inscription is defined as the lexicographically smaller of the two readings.

If a stone’s inscription is symmetric, meaning that rotating it 180180^\circ does not change the inscription, then the standard way to read the inscription is defined as this unique reading.

For example, there are six kinds of Xi-3-2\text{Xi-3-2} magic stones. Their standard readings, written in lexicographical order, are: III, IIX, IXI, IXX, XIX, and XXX.

Alice is an expert in studying magic stones in Wonderland. She wants to create a dictionary of standard readings of Xi-n-k\text{Xi-n-k} magic stones (for some given nn and kk). For a given ii, what inscription should be at position ii in this dictionary?

Task

Write a program that:

  • reads integers nn, kk, ii from standard input;
  • determines the ii-th standard reading (in lexicographical order) among Xi-n-k\text{Xi-n-k} magic stones;
  • outputs the result to standard output.

Input Format

The standard input contains only one line with three integers n,k,in,k,i, separated by a single space.

Output Format

The standard output contains only one line, which should be the ii-th standard reading (in lexicographical order) of Xi-n-k\text{Xi-n-k} magic stones.

If the number of Xi-n-k\text{Xi-n-k} magic stones is smaller than ii, output one line with the phrase NO SUCH STONE.

3 2 5
XIX
3 2 7
NO SUCH STONE

Hint

Constraints and Hints

For all data, 0k<n600\le k<n\le 60, 0<i<10180<i<10^{18}.

Notes

Note: We say the inscription of A\text{A} is lexicographically smaller than that of B\text{B} (assuming they have the same length) if and only if at the first position where they differ, A\text{A} contains I and B\text{B} contains X.

Translated by ChatGPT 5