After the Search Ultimate program that searched for strings in a text failed, Igor K. got to think: "Why on Earth does my program work so slowly?" As he double-checked his code, he said: "My code contains no errors, yet I know how we will improve Search Ultimate!" and took a large book from the shelves. The book read "Azembler. Principally New Approach".
Having carefully thumbed through the book, Igor K. realised that, as it turns out, you can multiply the numbers dozens of times faster. "Search Ultimate will be faster than it has ever been!" — the fellow shouted happily and set to work.
Let us now clarify what Igor's idea was. The thing is that the code that was generated by a compiler was far from perfect. Standard multiplying does work slower than with the trick the book mentioned.
The Azembler language operates with 26 registers (eax, ebx, ..., ezx) and two commands:
* \[_x_\] — returns the value located in the address _x_. For example, \[eax\] returns the value that was located in the address, equal to the value in the register eax.
* lea _x_, _y_ — assigns to the register _x_, indicated as the first operand, the second operand's address. Thus, for example, the "lea ebx, \[eax\]" command will write in the ebx register the content of the eax register: first the \[eax\] operation will be fulfilled, the result of it will be some value that lies in the address written in eax. But we do not need the value — the next operation will be lea, that will take the \[eax\] address, i.e., the value in the eax register, and will write it in ebx.
On the first thought the second operation seems meaningless, but as it turns out, it is acceptable to write the operation as
lea ecx, \[eax + ebx\],
lea ecx, \[k*eax\]
or even
lea ecx, \[ebx + k*eax\],
where k = 1, 2, 4 or 8.
As a result, the register ecx will be equal to the numbers eax + ebx, k*eax and ebx + k*eax correspondingly. However, such operation is fulfilled many times, dozens of times faster that the usual multiplying of numbers. And using several such operations, one can very quickly multiply some number by some other one. Of course, instead of eax, ebx and ecx you are allowed to use any registers.
For example, let the eax register contain some number that we should multiply by 41. It takes us 2 lines:
lea ebx, \[eax + 4*eax\] // now ebx = 5*eax
lea eax, \[eax + 8*ebx\] // now eax = eax + 8*ebx = 41*eax
Igor K. got interested in the following question: what is the minimum number of lea operations needed to multiply by the given number _n_ and how to do it? Your task is to help him.
Consider that at the initial moment of time eax contains a number that Igor K. was about to multiply by _n_, and the registers from ebx to ezx contain number 0. At the final moment of time the result can be located in any register.
## Input
The input data contain the only integer _n_ (1 ≤ _n_ ≤ 255), which Igor K. is about to multiply.
## Output
On the first line print number _p_, which represents the minimum number of lea operations, needed to do that. Then print the program consisting of _p_ commands, performing the operations. It is guaranteed that such program exists for any _n_ from 1 to 255.
Use precisely the following format of commands (here _k_ is equal to 1, 2, 4 or 8, and _x_, _y_ and _z_ are any, even coinciding registers):
lea x, \[y\]
lea x, \[y + z\]
lea x, \[k*y\]
lea x, \[y + k*z\]
Please note that **extra spaces at the end of a command are unacceptable**.
[samples]
在用于在文本中搜索字符串的 Search Ultimate 程序失败后,Igor K. 开始思考:"为什么我的程序运行得这么慢?" 在他复查代码时,他说道:"我的代码没有错误,但我已知道如何改进 Search Ultimate!" 并从书架上取下一本厚书,书名是《Azembler:全新方法》。
仔细翻阅这本书后,Igor K. 意识到,正如书中所言,你可以用快几十倍的速度进行乘法运算。"Search Ultimate 将比以往任何时候都更快!" 他高兴地喊道,并立即投入工作。
现在我们来澄清 Igor 的想法。问题在于编译器生成的代码远非完美。标准的乘法运算比书中提到的技巧要慢得多。
Azembler 语言使用 26 个寄存器(eax、ebx、...、ezx)和两条指令:
乍一看,第二条指令似乎毫无意义,但事实上,可以将其写成:
lea ecx, [eax + ebx],
lea ecx, [k*eax]
或甚至
lea ecx, [ebx + k*eax],
其中 k = 1, 2, 4 或 8。
结果,寄存器 ecx 将分别等于 eax + ebx、k*eax 和 ebx + k*eax。然而,这种操作的执行速度比普通的数字乘法快几十倍。通过组合多个这样的操作,可以非常快速地将某个数乘以另一个数。当然,除了 eax、ebx 和 ecx,你也可以使用任何寄存器。
例如,假设 eax 寄存器中包含一个我们需要乘以 41 的数。这需要两行代码:
lea ebx, [eax + 4*eax] // 此时 ebx = 5*eax
lea eax, [eax + 8*ebx] // 此时 eax = eax + 8*ebx = 41*eax
Igor K. 对以下问题产生了兴趣:要乘以给定的数字 #cf_span[n],最少需要多少条 lea 指令?如何实现?你的任务是帮助他。
假设在初始时刻,eax 中包含 Igor K. 要乘以 #cf_span[n] 的数,而从 ebx 到 ezx 的寄存器中均包含数字 0。在最终时刻,结果可以位于任意寄存器中。
输入数据包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 255]),即 Igor K. 要乘以的数。
第一行输出数字 #cf_span[p],表示完成该乘法所需的最少 lea 操作次数。然后输出包含 #cf_span[p] 条指令的程序。保证对于 1 到 255 范围内的任意 #cf_span[n],都存在这样的程序。
请严格使用以下指令格式(其中 #cf_span[k] 等于 1、2、4 或 8,#cf_span[x]、#cf_span[y] 和 #cf_span[z] 可以是任意寄存器,甚至可以相同):
lea x, [y]
lea x, [y + z]
lea x, [k*y]
lea x, [y + k*z]
请注意,*指令末尾不允许出现多余空格*。
## Input
输入数据包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 255]),即 Igor K. 要乘以的数。
## Output
第一行输出数字 #cf_span[p],表示完成该乘法所需的最少 lea 操作次数。然后输出包含 #cf_span[p] 条指令的程序。保证对于 1 到 255 范围内的任意 #cf_span[n],都存在这样的程序。请严格使用以下指令格式(其中 #cf_span[k] 等于 1、2、4 或 8,#cf_span[x]、#cf_span[y] 和 #cf_span[z] 可以是任意寄存器,甚至可以相同):lea x, [y]lea x, [y + z]lea x, [k*y]lea x, [y + k*z]请注意,*指令末尾不允许出现多余空格*。
[samples]
**Definitions**
Let $ n \in \mathbb{Z} $, $ 1 \leq n \leq 255 $, be the target multiplier.
Let $ R = \{ \text{eax}, \text{ebx}, \dots, \text{ezx} \} $ be the set of 26 registers.
Initially, $\text{eax} = a$ (input value), and all other registers are 0.
Each `lea` operation updates one register as:
- $ r_i \leftarrow r_j $
- $ r_i \leftarrow r_j + r_k $
- $ r_i \leftarrow c \cdot r_j $, where $ c \in \{1,2,4,8\} $
- $ r_i \leftarrow r_j + c \cdot r_k $, where $ c \in \{1,2,4,8\} $
**Constraints**
1. Only `lea` instructions of the form:
- `lea x, [y]`
- `lea x, [y + z]`
- `lea x, [k*y]`
- `lea x, [y + k*z]`
with $ k \in \{1,2,4,8\} $ are allowed.
2. Initial state: $\text{eax} = a$, all other registers = 0.
3. Final state: at least one register must contain $ n \cdot a $.
**Objective**
Find the minimum number $ p $ of `lea` operations to compute $ n \cdot a $, and output a sequence of $ p $ valid `lea` instructions achieving this.