QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 512 MB Puntuación total: 10

#5236. Professional version [A]

Estadísticas

Bajtek has decided to draw a pyramid of triangles as shown in the figure below.

The pyramid that Bajtek wants to draw consists of $N$ levels. The lowest level contains $2N-1$ triangles, alternating between pointing up and pointing down. On each higher level, triangles are placed analogously, but with two fewer triangles on each level. The figure above shows the situation for $N=3$.

Bajtek has a program that allows him to draw similar figures on the screen. A pen is placed at a point on the screen, which draws straight lines at various angles. Bajtek's program accepts commands that are letters A..F – each letter represents moving the pen in one of the possible directions and drawing a segment, according to the following diagram:

For example, the command sequence FBBBFBFBFBFBBBFBFBFB will result in drawing a polyline like the one below:

The new version of Bajtek's program allows for more complex commands: in addition to letters, digits are also possible, which signify multiple repetitions of a certain sequence of commands. Specifically:

  • A string of the form $kZ$, where $k \in \{1, 2, 3, 4, 5, 6, 7, 8, 9\}$ and $Z \in \{A, B, C, D, E, F\}$, means the same as $Z...Z$ ($k$ copies of the letter $Z$);
  • A string of the form $k[S]$, where $k \in \{1, 2, 3, 4, 5, 6, 7, 8, 9\}$ and $S$ is a certain string, means $S...S$ ($k$ copies of the string $S$); the string $S$ can itself contain further constructions with digits.

For example, 3[2A] is AAAAAA, and the polyline from the drawing above can also be achieved with shorter strings such as F3B3[FB]F3B3[FB], 2[F3BFBFBFB], or even 2[F3B3[FB]]. Note that strings where $k$ is a number greater than 9 (such as 10A or 58[AB]) are not allowed.

Let's return to Bajtek's pyramid from the first drawing. Bajtek wants to realize it using a sequence of commands for his program. He has an additional condition: he would like the pen to never draw over the same line twice (due to a minor bug in the program, the line becomes slightly thicker, which irritates Bajtek's aesthetic sense). For example, the string 2[FBD] violates this rule – each line of the triangle would be drawn twice. Bajtek's second requirement is that the program should have no more than 150,000 characters.

Bajtek has hired you to construct the appropriate sequence of commands. Write a program that, for a given $N$, outputs a string of characters generating a pyramid of height $N$. We assume that the pen is initially located at the bottom-left corner of the pyramid. As sometimes happens in IT projects, you can violate the client's requirements. This means that your program can go over the same line twice, or (slightly) exceed the 150,000 character limit, but it will cost you – in this case, you will receive fewer points. The exact scoring rules are given in the "Scoring" section.

Input

The first (and only) line of input contains a single integer $n$ ($1 \le n \le 10^{18}$), representing the number of levels of the pyramid.

Output

The only line of output should contain a sequence of instructions of length not exceeding 150,000, which correctly builds a pyramid consisting of exactly $n$ levels.

Scoring

  • You will not receive any points for a given test if you do not stay within the 150,000 character limit.
  • You will not receive any points for a given test if you traverse any segment multiple times.

Examples

Input 1

3

Output 1

2[FB]2DE2AECEAE3[C]A

Note

The Olympiad for Junior Programmers, as the name suggests, is a competition for beginner programmers, and the authors of that problem can be forgiven for the extremely low constraints on the pyramid side length. However, professionals participate in the Algorithmic Contests, and we can probably expect them to build pyramids consisting of even $10^{18}$ levels with an instruction sequence of length not exceeding 150,000, right?

The problem specification is the same as the specification of the original OIJ problem, with some exceptions: We do not force you to start at the bottom-left corner of the pyramid (you can start at any point). Here you will not receive any points for a given test if you do not stay within the 150,000 character limit. * Here you will not receive any points for a given test if you traverse any segment multiple times.

Note: On the OIJ website, you can also find a sketch of the discussion of this problem, which we also include here for your convenience: [link]. However, we do not guarantee that the information contained therein is in any way useful for solving our version of the problem.

Implementation Details

In the Files section of the SIO2 system, you can find the script narysuj.py mentioned in the OIJ problem description.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.