The owner of the pet shop has noticed that more and more pets are becoming lazy. In particular, the pigs do nothing but sleep all day, so half of the problem setter's fee has been deducted. The cats, on the other hand, have gradually learned to do nothing except sing "Hachimi". In order to correct the bad habits in the shop and make sure the pets actually learn something real, the owner decides to open an arithmetic class for them.
One day, the owner arranges $$$n^2$$$ pets into $$$n$$$ rows and $$$n$$$ columns, forming an $$$n\times n$$$ grid. Both rows and columns are numbered $$$1,2,\cdots,n$$$. The owner decides to play a small game to test the pets' arithmetic ability. Each pet keeps an integer, which is initially $$$0$$$. The owner will then issue $$$m$$$ commands in order, of the following four types:
After you solve this problem, the owner would like to remind you that the problems are not arranged in order of difficulty.
The first line contains two integers $$$n,m$$$ ($$$1\le n\le 2025$$$, $$$1\le m\le 10^6$$$).
Each of the next $$$m$$$ lines contains $$$2$$$ or $$$3$$$ integers, describing a single command in one of the formats given above.
In the commands, it is guaranteed that $$$1\le x,y\le n$$$ and $$$-10^9\le k\le 10^9$$$.
For each command of type 4, output one line containing a single integer — the current number of the pet at row $$$x$$$, column $$$y$$$.
3 51 92 3 -14 1 33 3 44 3 3
9 12
2025 104 1394 8211 9982443533 985 1234567892 1024 9876543213 996 9964123454 1024 9961 -10000000001 -10000000002 2025 -19198104 2025 985
0 2982311019 -880218668
In the first example:
You are given a binary tree with $$$2n-1$$$ nodes, numbered from $$$1$$$ to $$$2n-1$$$.
Each node $$$p$$$ has two integer values $$$L_p$$$ and $$$R_p$$$ satisfying $$$L_p\le R_p$$$.
This binary tree satisfies the following properties:
For any interval $$$[l,r]$$$ with integer endpoints satisfying $$$1\le l\le r\le n$$$, consider the following algorithm: $$$$$$ \begin{array}{l} \textbf{function }\text{visit}(p,l,r,\textit{id})\\ \begin{array}{rl} 1&\textbf{if }r \lt L_p\text{ or }R_p \lt l\\ 2&\quad\textbf{return}\\ 3&\textit{cnt}_1[\textit{id}]\gets\textit{cnt}_1[\textit{id}]+1\\ 4&\textit{cnt}_2[p]\gets\textit{cnt}_2[p]+1\\ 5&\textbf{if }l\le L_p\text{ and }R_p\le r\\ 6&\quad\textbf{return}\\ 7&u\gets\text{left child of }p\\ 8&v\gets\text{right child of }p\\ 9&\text{visit}(u,l,r,\textit{id})\\ 10&\text{visit}(v,l,r,\textit{id}) \end{array} \end{array} $$$$$$ You are given $$$m$$$ intervals $$$[l_i,r_i]$$$ ($$$i=1,2,\cdots,m$$$). For each $$$i$$$, you call $$$\text{visit}(1,l_i,r_i,i)$$$ exactly once. All elements of the arrays $$$\textit{cnt}_1$$$ (indexed by $$$1,2,\cdots,m$$$) and $$$\textit{cnt}_2$$$ (indexed by $$$1,2,\cdots,2n-1$$$) are initially $$$0$$$. Your task is to find their final values.
The first line contains two integers $$$n,m$$$ ($$$1\le n,m\le10^6$$$).
Each of the next $$$2n-1$$$ lines describes node $$$i$$$ (for $$$i=1,2,\cdots,2n-1$$$):
Output two lines.
The first line contains $$$m$$$ integers, the $$$i$$$-th of which is the final value of $$$\textit{cnt}_1[i]$$$.
The second line contains $$$2n-1$$$ integers, the $$$i$$$-th of which is the final value of $$$\textit{cnt}_2[i]$$$.
4 51 4 2 31 2 4 53 4 6 71 12 23 34 41 42 31 14 42 2
1 5 3 3 3 5 3 2 1 2 1 1
You are given an undirected graph with $$$n$$$ vertices and $$$m$$$ edges. The vertices are numbered $$$1,2,\cdots,n$$$, and the edges are numbered $$$1,2,\cdots,m$$$.
You need to choose some of these edges.
We use a 01 sequence $$$\{a_i\}_{i=1}^m$$$ to represent which edges are chosen. If the edge with index $$$i$$$ is chosen, then $$$a_i=1$$$; otherwise, $$$a_i=0$$$.
The chosen edges must satisfy the following conditions:
The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2\le n\le10^6$$$, $$$1\le m\le10^6$$$).
Each of the next $$$m$$$ lines contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1\le u_i,v_i\le n$$$), representing the edge with index $$$i$$$ that connects vertices $$$u_i$$$ and $$$v_i$$$.
It is guaranteed that there is no self-loop in the graph, i.e., $$$u_i\ne v_i$$$.
If there is no solution, output -1.
Otherwise, output a 01 sequence of length $$$m$$$ (one line with $$$m$$$ integers, separated by single spaces) representing your choice of edges.
4 41 22 33 44 1
1 0 1 0
3 21 22 3
-1
In the first example, if we do not require sequence $$$a$$$ to be lexicographically greatest, another valid solution is to choose edges numbered $$$2$$$ and $$$4$$$.
Laplace Computing Center is trying to crack a warlock's code.
There are three operations. Your task is to use them to type out a given 01 string $$$S$$$.
The three operations are 0, 1, and B:
You must perform exactly $$$n$$$ operations and type out the given 01 string $$$S$$$.
Find the number of operation sequences that satisfy this requirement. Print the answer modulo $$$10^9+7$$$.
The first line contains an integer $$$n$$$ ($$$1\le n\le5000$$$).
The second line contains a 01 string $$$S$$$ ($$$1\le |S|\le n$$$).
Output a single integer, the number of valid operation sequences modulo $$$10^9+7$$$.
31
5
9110
509
In the first example, there are $$$5$$$ valid operation sequences: 10B, 11B, 0B1, 1B1, BB1.
To verify whether the piglet is a reliable intermediate-level competitive programmer, Little L gives him the following problem.
Every positive integer $$$x$$$ can be uniquely written as $$$\overline{d_md_{m-1}\cdots d_0}$$$, satisfying all of the following conditions:
Given positive integers $$$L$$$ and $$$R$$$ ($$$L\le R$$$), compute $$$\left(\sum\limits_{i=L}^Rf(i)\right)\bmod(10^9+7)$$$.
The input consists of a single line containing two integers $$$L,R$$$ ($$$1\le L\le R\le10^{202512}$$$).
Output a single integer, the value of $$$\left(\sum\limits_{i=L}^Rf(i)\right)\bmod(10^9+7)$$$.
20249 20257
935315683
1 20252025202520252025
423849977
In the first example, only $$$20249$$$ is good, and $$$2025^{20249}\bmod(10^9+7)=935315683$$$.
After competing in XCPC 2077, you realize that you have no hope of going any further.
You lie on your bed, close your eyes, and recall the scenes where you once fought hard in the contest hall.
Tears still come out. You are not willing to accept this; you feel that your team could have done better.
Suddenly, you wake up and find yourself back on the night before the contest.
Everything that happened before feels like a dream, yet it was so vivid.
You realize that this time, your team still has a chance.
You decide that this time, you will leave no regrets.
You are filled with determination.
Each XCPC contest lasts $$$300$$$ minutes.
There are $$$n$$$ problems. Their numeric indices are $$$1,2,\cdots,n$$$, and their letter indices are $$$\texttt{A},\texttt{B},\cdots$$$ in order.
It is known that problem $$$i$$$ takes $$$t_i$$$ minutes (not necessarily consecutive) to solve, and before solving it you will make exactly $$$d_i$$$ wrong submissions on this problem.
If problem $$$i$$$ cannot be solved even if you try your best, then $$$t_i=301$$$.
It is important to note that your team can work on only one problem in the same minute.
In the final standings, teams that solve more problems are ranked higher. Among teams that solve the same number of problems, those with a smaller penalty time are ranked higher.
Suppose a team solves problem $$$p_i$$$ at minute $$$s_i$$$ ($$$i=1,2,\cdots,m$$$), then the penalty time of this team is $$$$$$ \sum\limits_{i=1}^m(s_i+20d_{p_i}). $$$$$$ You need to find an optimal strategy — a strategy that maximizes the number of solved problems and, subject to that, minimizes the penalty time.
The first line contains a single integer $$$T$$$ ($$$1\le T\le15000$$$), denoting the number of test cases.
For each test case:
For each test case, output $$$2$$$ or $$$11$$$ lines.
The first line contains two integers, the number of solved problems and the penalty time when using an optimal strategy.
The second line contains a string of length $$$300$$$ describing an optimal strategy:
If there are multiple optimal strategies, you only need to output any of them.
229 9295 03246 337 7169 4
1 189 AAAAAAAAABBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB BBBBBBBBBBBBBBBBBBBBBBB------- ------------------------------ ------------------------------ BB-----B---------------------- ------------------------------ ------------------------------ ------------------------------ -----------B------------------ 2 463 BBBBBBBBBBBBBBBBBBBBBBBBBBBBBB BBBBBBBCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC CCCCCCCCCCCCCCCCCCCCCCCCCCAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Little S has designed a problem and plans to give it as a gift to everyone.
You are given an integer sequence $$$a_1,a_2,\cdots,a_n$$$.
Output any non-empty subsequence $$$a_{b_1},a_{b_2},\cdots,a_{b_k}$$$ of this sequence that satisfies $$$$$$ \left(\sum_{i=1}^ka_{b_i}\right)\bmod n=0 $$$$$$ It can be shown that such a subsequence always exists.
After reading the problem, Little L explains some basic concepts to everyone:
For any integer $$$k$$$ satisfying $$$1\le k\le n$$$ and any integers $$$b_1,\dots,b_k$$$ satisfying $$$$$$ 1\le b_1 \lt b_2 \lt \cdots \lt b_k\le n $$$$$$ we say that $$$a_{b_1},a_{b_2},\cdots,a_{b_k}$$$ is a non-empty subsequence of $$$a_1,a_2,\cdots,a_n$$$.
Regarding the summation symbol $$$\sum$$$, its meaning is $$$$$$ \sum_{i=1}^ka_{b_i}=a_{b_1}+a_{b_2}+\cdots+a_{b_k} $$$$$$ Here, the operation $$$\bmod$$$ is defined as $$$$$$ x\bmod y=x-\left\lfloor\frac{x}{y}\right\rfloor y $$$$$$ where $$$\lfloor z\rfloor$$$ denotes the greatest integer less than or equal to $$$z$$$. The condition $$$x\bmod y=0$$$ is equivalent to saying that $$$x$$$ is a multiple of $$$y$$$.
The first line contains a single integer $$$T$$$ ($$$T\ge1$$$), denoting the number of test cases.
Then for each test case:
For each test case, output two lines:
261 1 4 5 1 461 1 4 5 1 4
2 2 4 5 1 2 3 4 5
In the first test case, $$$a_2+a_4=1+5=6$$$ and $$$6\bmod6=0$$$, so the requirements are satisfied.
In the second test case, $$$a_1+a_2+a_3+a_4+a_5=1+1+4+5+1=12$$$ and $$$12\bmod6=0$$$, so the requirements are satisfied.
Little L once encountered the following problem in a high school math quiz:
There is a staircase with $$$7$$$ steps. At each move, you may climb $$$1$$$ or $$$2$$$ steps. Find the probability of passing step $$$4$$$.
The reference solution was as follows:
Let $$$\textit{fib}_0=\textit{fib}_1=1$$$, and for $$$i\ge2$$$ let $$$\textit{fib}_i=\textit{fib}_{i-1}+\textit{fib}_{i-2}$$$. The answer is $$$\dfrac{\textit{fib}_4\cdot\textit{fib}_3}{\textit{fib}_7}=\dfrac{5}{7}$$$.
It assumes that all possible paths are equally likely. However, generally speaking, a person cannot directly choose one of the $$$\textit{fib}_7$$$ possible paths uniformly at random; instead, at each move, the person chooses to climb $$$1$$$ step or $$$2$$$ steps with equal probability (in particular, at step $$$6$$$, the person can only climb $$$1$$$ step).
To be rigorous, we restate the problem as follows:
There is a staircase with $$$7$$$ steps. A person wants to go from step $$$0$$$ to step $$$7$$$. At each move, the person climbs $$$1$$$ step with probability $$$\dfrac{1}{2}$$$, and $$$2$$$ steps with probability $$$\dfrac{1}{2}$$$. In particular, at step $$$6$$$, the person can only climb $$$1$$$ step. Find the probability of passing step $$$4$$$.
Consider drawing the probability tree, as shown in the following figure:
Now, consider a staircase with $$$n$$$ steps. A person wants to go from step $$$0$$$ to step $$$n$$$. At each move, the person climbs $$$1$$$ step with probability $$$\dfrac{1}{2}$$$, and $$$2$$$ steps with probability $$$\dfrac{1}{2}$$$. In particular, at step $$$n-1$$$, the person can only climb $$$1$$$ step. Find the probability of passing step $$$m$$$.
Print the answer modulo $$$10^9+7$$$ (a prime number).
Formally, it is easy to prove that the answer can be written as $$$\dfrac{p}{q}$$$. Here, $$$p$$$ is a non-negative integer, and $$$q$$$ is a positive integer that is not a multiple of $$$10^9+7$$$. You need to output $$$p\cdot q^{-1}\bmod(10^9+7)$$$, where $$$q^{-1}$$$ is an integer satisfying $$$q\cdot q^{-1}\equiv1\pmod{10^9+7}$$$. Modulo the prime number $$$10^9+7$$$, it is easy to prove that if $$$q^{-1}$$$ exists, then it is unique. According to Fermat's little theorem, $$$q^{-1}\equiv q^{10^9+5}\pmod{10^9+7}$$$.
The first line contains a single integer $$$T$$$ ($$$1\le T\le5$$$), denoting the number of test cases.
Then, for each test case, there is a single line containing two integers $$$n,m$$$ ($$$1\le m\le n\le10^{1000000}$$$).
For each test case, output a single line containing one integer, the answer modulo $$$10^9+7$$$.
47 47 17 79876543210123456789 54321012345
1875000025000000041376896505
For the first three test cases, the answers are $$$\dfrac{11}{16}$$$, $$$\dfrac{1}{2}$$$, and $$$1$$$, respectively.
You are given a graph with $$$n$$$ vertices, $$$m_1$$$ undirected edges, and $$$m_2$$$ directed edges. The vertices are numbered $$$1,2,\cdots,n$$$.
This graph satisfies the following property: For any subset of vertices, the number of edges (regardless of whether they are directed or undirected) whose both endpoints lie inside this subset does not exceed the size of the subset.
Count the number of ways to assign a direction to every undirected edge such that, after all undirected edges are oriented, the resulting graph contains no directed cycle. Print the answer modulo $$$10^9+7$$$.
It is guaranteed that the answer (before taking the modulo) is at least $$$1$$$. In particular, if $$$m_1=0$$$, the answer is $$$1$$$.
The first line contains three integers $$$n,m_1,m_2$$$ ($$$1\le n\le2\times10^5$$$, $$$m_1,m_2\ge0$$$, $$$m_1+m_2\le2\times10^5$$$).
Each of the next $$$m_1$$$ lines contains two integers $$$u,v$$$ ($$$1\le u,v\le n$$$), denoting an undirected edge $$$u\leftrightarrow v$$$.
Each of the next $$$m_2$$$ lines contains two integers $$$u,v$$$ ($$$1\le u,v\le n$$$), denoting a directed edge $$$u\to v$$$.
It is guaranteed that there is no self-loop in the graph, i.e., $$$u\ne v$$$.
It is also guaranteed that for any pair of vertices, there is at most one edge between them (regardless of whether it is directed or undirected).
Output a single integer, the answer modulo $$$10^9+7$$$.
10 6 21 22 33 43 56 77 84 18 9
56
I keep recalling the days in the past over and over again, afraid that if I am even a little careless, those vivid moments will quietly slip away.
Fresh days are like newly peeled orange segments, falling onto the tip of your tongue; the sour and sweet juice spreads between your teeth, and even your breath carries a refreshing fruity scent. Sunshine also falls into your palm, soft and warm like a ball of fluff, slowly rolling away between your fingers. When you try to grasp it tightly, it has already slipped away, turning into faint glimmers among the dust.
Lovely days are like a soft warm breeze soaking into the afternoon, leaving a light trace of warmth on your collar. It brushes past that gentle silhouette, circling around, stirring a soft rustle in the flowers and leaves, then slows down again, only willing to drift slowly along the hem of your clothes. The patches of light around you quietly blur into a soft halo, and the air ripples with tenderness.
How could I bear to tuck all of these away into a drawer of the past, letting their vividness slowly fade into old shadows? I know that time must move forward, yet I still cannot help wishing it would slow down a little, then a little more, so that I can look once again at the shape of every single day.
Little L recalled $$$n$$$ days and used an uppercase English letter to describe each day.
He writes them down in order and obtains a string $$$S_1S_2\cdots S_n$$$ (each $$$S_i$$$ is an uppercase English letter).
We say that the $$$i$$$-th day is a fresh day if and only if exactly one of $$$S_i\ne S_{i-1}$$$ and $$$S_i\ne S_{i+1}$$$ holds.
We say that the $$$i$$$-th day is a lovely day if and only if neither of $$$S_i\ne S_{i-1}$$$ and $$$S_i\ne S_{i+1}$$$ holds.
It is important to note that we assume that $$$\boldsymbol{S_1\ne S_0}$$$ and $$$\boldsymbol{S_n\ne S_{n+1}}$$$ here.
Little L counted and found that there are $$$m_1$$$ fresh days and $$$m_2$$$ lovely days.
As time passed, Little L forgot the string $$$S_1S_2\cdots S_n$$$, and only vaguely remembers $$$n,m_1,m_2$$$.
Given $$$n,m_1,m_2$$$, determine whether Little L could have remembered them correctly or must have remembered them incorrectly.
If Little L could have remembered them correctly, output any possible string $$$S_1S_2\cdots S_n$$$.
The first line contains a single integer $$$T$$$ ($$$T\ge1$$$), denoting the number of test cases.
Then, for each test case, there is a single line containing three integers $$$n,m_1,m_2$$$ ($$$n\ge1$$$, $$$m_1,m_2\ge0$$$, $$$m_1+m_2\le n$$$).
It is guaranteed that the sum of $$$n$$$ over all $$$T$$$ test cases does not exceed $$$10^6$$$.
For each test case, output one or two lines.
On the first line, output Possible or Impossible, meaning that Little L could have remembered correctly or must have remembered incorrectly, respectively.
If Little L could have remembered correctly, then on the second line output a string $$$S_1S_2\cdots S_n$$$ of length $$$n$$$ consisting of uppercase English letters.
In this case, you must ensure that the string satisfies the conditions in the statement. If there are multiple valid answers, you may output any of them.
If Little L must have remembered incorrectly, then for this test case you should output only one line.
110 6 3
Possible ABBCCCDDDD
81 0 05 2 36 0 06 4 18 6 24 2 01 1 04 0 3
Possible A Possible AAAAA Possible ABABAB Possible AABBBA Possible AABBBBAA Possible YXXY Impossible Impossible
To explain the output in the first example, we highlight fresh days in blue and lovely days in green: $$$$$$ \texttt{A}\texttt{ }\color{blue}{\texttt{B}}\texttt{ }\color{blue}{\texttt{B}}\texttt{ }\color{blue}{\texttt{C}}\texttt{ }\color{green}{\texttt{C}}\texttt{ }\color{blue}{\texttt{C}}\texttt{ }\color{blue}{\texttt{D}}\texttt{ }\color{green}{\texttt{D}}\texttt{ }\color{green}{\texttt{D}}\texttt{ }\color{blue}{\texttt{D}} $$$$$$
Bored piglet has an integer sequence $$$a_1,a_2,\cdots,a_n$$$.
He wants to partition this sequence into several intervals, denoted as $$$[l_1,r_1],[l_2,r_2],\cdots,[l_m,r_m]$$$ (the value of $$$m$$$ is chosen arbitrarily), satisfying all of the following conditions:
The first line contains a single integer $$$n$$$ ($$$1\le n\le10^5$$$).
The second line contains $$$n$$$ integers $$$a_1,a_2,\cdots,a_n$$$ ($$$1\le a_i\le10^9$$$).
Print a single integer, the number of valid partitions modulo $$$10^9+7$$$.
61 2 3 2 2 1
14
121 1 2 3 2 2 1 9 1000000000 23 24 25
284
We can use the inclusion-exclusion principle on two sets to calculate the answer of the first example:
Partitioning $$$a_1,a_2,\cdots,a_6$$$ into $$$m$$$ intervals is equivalent to choosing $$$m-1$$$ gaps among the $$$5$$$ gaps between adjacent elements and inserting separators there.
To make Condition A hold, it is necessary and sufficient to insert separators between $$$a_3$$$ and $$$a_4$$$, $$$a_5$$$ and $$$a_6$$$; thus the number of such partitions is $$$2^3=8$$$.
To make Condition B hold, it is necessary and sufficient to insert separators between $$$a_1$$$ and $$$a_2$$$, $$$a_2$$$ and $$$a_3$$$; thus the number of such partitions is $$$2^3=8$$$.
To make both Condition A and Condition B hold, similarly we can obtain that the number of such partitions is $$$2$$$.
So, the answer is $$$8+8-2=14$$$.
There is no input in this problem; your program only needs to output a solution.
Formally, the state of a single qubit $$$\vert\psi\rangle$$$ can be written as $$$\alpha\vert0\rangle+\beta\vert1\rangle$$$, where $$$\alpha,\beta$$$ are complex numbers satisfying $$$\vert\alpha\vert^2+\vert\beta\vert^2=1$$$. Here, we regard this purely as an abstract mathematical object and do not discuss its physical meaning.
If we measure $$$\vert\psi\rangle$$$:
Different qubits are not always separable. Consider the general state of a two-qubit system $$$$$$ \vert\psi_1\rangle\vert\psi_2\rangle=\alpha_{00}\vert0\rangle\vert0\rangle+\alpha_{01}\vert0\rangle\vert1\rangle+\alpha_{10}\vert1\rangle\vert0\rangle+\alpha_{11}\vert1\rangle\vert1\rangle $$$$$$ where $$$\vert\alpha_{00}\vert^2+\vert\alpha_{01}\vert^2+\vert\alpha_{10}\vert^2+\vert\alpha_{11}\vert^2=1$$$. If this expression cannot be factorized as $$$(\alpha\vert0\rangle+\beta\vert1\rangle)(\gamma\vert0\rangle+\delta\vert1\rangle)$$$, then we say that $$$\vert\psi_1\rangle$$$ and $$$\vert\psi_2\rangle$$$ are in an entangled state. Once an entangled state is formed, the correlation between the two qubits persists even if they are separated far apart in space.
If we measure $$$\vert\psi_1\rangle$$$ in this system:
Quantum gates are basic tools for manipulating qubits.
In this problem, you may use, and are only allowed to use, the H gate, X gate, Z gate, and CNOT gate.
To apply an H, X, or Z gate, you must choose a target qubit $$$\vert\psi\rangle$$$. Suppose before the operation $$$\vert\psi\rangle=\alpha\vert0\rangle+\beta\vert1\rangle$$$, then:
So he designs the $$$\mathcal{HYW}$$$ language — an extremely simple quantum programming language.
A $$$\mathcal{HYW}$$$ program consists of several statements, one per line. The interpreter executes the statements in order from top to bottom.
Statements are divided into measurement statements and operation statements.
A measurement statement has the form $$$\texttt{measure }x$$$, which means to measure $$$\vert\psi_x\rangle$$$. The measurement result is either $$$0$$$ or $$$1$$$.
An operation statement must be one of the following two types:
| Format | Meaning |
| $$$\texttt{ \lt statement \gt }$$$ | Execute <statement> |
| $$$\texttt{if \lt condition \gt then \lt statement \gt }$$$ | If <condition> is true, execute <statement> |
| Format | Meaning |
| $$$\texttt{H }x$$$ | Apply an H gate to the target qubit $$$\vert\psi_x\rangle$$$ |
| $$$\texttt{X }x$$$ | Apply an X gate to the target qubit $$$\vert\psi_x\rangle$$$ |
| $$$\texttt{Z }x$$$ | Apply a Z gate to the target qubit $$$\vert\psi_x\rangle$$$ |
| $$$\texttt{CNOT }x\texttt{ }y$$$ | Apply a CNOT gate with control qubit $$$\vert\psi_x\rangle$$$ and target qubit $$$\vert\psi_y\rangle$$$ |
For example, suppose initially $$$\vert\psi_1\rangle\vert\psi_2\rangle=\vert0\rangle\vert0\rangle$$$. To make $$$\vert\psi_1\rangle\vert\psi_2\rangle=\dfrac{\vert0\rangle\vert0\rangle+\vert1\rangle\vert1\rangle}{\sqrt2}$$$, a $$$\mathcal{HYW}$$$ program can be:
H 1
CNOT 1 2
After each statement is executed, the state evolves as follows:
measure 1
if m1=1 then X 1
if m1=1 then X 2
After each statement is executed, the state evolves as follows:
Initially, $$$\vert\psi_1\rangle=\alpha\vert0\rangle+\beta\vert1\rangle$$$, $$$\vert\psi_2\rangle=\vert0\rangle$$$, and $$$\vert\psi_3\rangle=\vert0\rangle$$$.
Your goal is to make $$$\vert\psi_1\rangle=\vert0\rangle$$$, $$$\vert\psi_2\rangle=\vert0\rangle$$$, and $$$\vert\psi_3\rangle=\alpha\vert0\rangle+\beta\vert1\rangle$$$.
You need to design a $$$\mathcal{HYW}$$$ program with at most $$$16$$$ statements to achieve this goal.
There is no input in this problem.
Output your solution. Do not output any extra content.
Suppose your $$$\mathcal{HYW}$$$ program is:
H 1
CNOT 1 2
Then you may submit the following C++ code:
#include <bits/stdc++.h>
int main() {
puts("H 1");
puts("CNOT 1 2");
return 0;
}
Of course, if you do so, you will receive a Wrong Answer.