QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 512 MB Total points: 100

#10305. Bulbel

统计

We define a bitset as a $w$-bit $01$ string. The bitset representation of a $w\times w$ $01$ matrix $M$ is defined as a sequence of $w$ bitsets $b_1, \ldots, b_w$, where $b_i$ is the bitset corresponding to the $i$-th row of $M$, with the element in the $j$-th column occupying the $j$-th bit of the bitset.

Given the bitset representation of a $w\times w$ matrix $M$ stored in $b_1, \ldots, b_w$ (you cannot directly access their values), you need to find the bitset representation of its transpose $M^T$ and store the result in $b_1, \ldots, b_w$. You have a total of $10^5$ bitsets $b_1, \ldots, b_{10^5}$ available, where $b_{w+1}, \ldots, b_{10^5}$ are initially all zeros. You can perform the following operations:

  • AS x y: Set $b_x \leftarrow b_y$.
  • AND x y z: Set $b_x \leftarrow b_y \land b_z$, where $\land$ is the bitwise AND.
  • OR x y z: Set $b_x \leftarrow b_y \lor b_z$, where $\lor$ is the bitwise OR.
  • XOR x y z: Set $b_x \leftarrow b_y \oplus b_z$, where $\oplus$ is the bitwise XOR.
  • SET x y a v: Set $b_x$ to the result of modifying the $a$-th bit ($a \in [0, w)$) of $b_y$ to $v$ ($v \in \{0, 1\}$) (without changing $b_y$).
  • SH x y a: Set $b_x$ to the result of left-shifting $b_y$ by $a$ bits ($a \in (-w, w)$) (without changing $b_y$; if $a < 0$, it is a right shift by $-a$ bits, with $0$s filled in the vacated positions).
  • SUB x s y: Set $b_x \leftarrow b_{s+b_y}$, where $b_y$ is treated as a binary number. It is required that $-10^5 \leq s \leq 10^5$ and $1 \leq s+b_y \leq 10^5$.

Your score depends on the number of operations you perform; see the scoring section for details.

Input

Read from standard input.

The first line contains an integer $w$.

Output

Output to standard output.

The first line contains an integer $m$, representing the number of operations.

The next $m$ lines each represent an operation. Operations will be executed in the order they are output.

Examples

Input

2

Output

10
SET 3 3 0 1
SET 4 4 1 1
AND 5 1 3
AND 6 1 4
AND 7 2 3
AND 8 2 4
SH 9 6 -1
SH 10 7 1
OR 1 5 10
OR 2 8 9

Subtasks

$\text{Subtask 1}(5\%)$: $w=2$.

$\text{Subtask 2}(10\%)$: $w=128$.

$\text{Subtask 3}(36\%)$: $w=256$.

$\text{Subtask 4}(49\%)$: $w=1024$.

Scoring

Let $m$ be the number of operations you perform.

Your score on a test case is: if your output is incorrect, the score is $0$; otherwise, the score is $f(m)$. Your score on a subtask is the minimum of the scores obtained on all test cases within that subtask.

For $\text{Subtask 1}$, $f(m)=[m\leq 10^5]\times 5$.

For $\text{Subtask 2}$, $f(m)=[m\leq 10^5]\times 10$.

For $\text{Subtask 3}$, $f(m)=\begin{cases}0 & (m>262144)\\\dfrac{8}{3}\left(4-\dfrac{m}{65536}\right)^2 & (65536< m\leq 262144)\\ 36-\dfrac{64}{3}\left(\dfrac{m}{65536}-\dfrac{1}{4}\right)^2 & (16384 < m\leq 65536)\\ 36 & (m\leq 16384)\end{cases}$

  • This is a continuous function. For reference, $f(65536)=24$.

For $\text{Subtask 4}$, $f(m)=\begin{cases}0 & (m>80000)\\\dfrac{3}{4000}(80000-m) & (40000 < m\leq 80000)\\ 48-\dfrac{9}{2282}(m-35436) & (35435< m\leq 40000)\\ 49 & (m\leq 35435)\end{cases}$

  • This is a continuous function on $(35435, +\infty)$. For reference, $f(40000)=30, f(35436)=48$.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
EditorialOpen Official EditorialQingyu- Download

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.