Ali decided to apply for internships for this summer, he applied to many companies and received his first assessment from his dream company.
He got the following question in the assessment:
lets define the function $f(a,b,c)$, where:
$a$ is a binary string of length $n$.
$b$ is a binary string of length $n$.
$c$ is a string of operations of length $n$ (elements are & or | or ^).
& for AND operation, | for OR operation, ^ for XOR operation.
The function will give a result of string $s$, the $i_{th}$ index in string $s$ will be equal to the result of operation $c_i$, on the values $a_i$ and $b_i$.
For example:
$f($''1001'', "0101'', "^|&&''$)$ ="1101''
You are given three binary strings $a$, $b$ and $s$. You should find a string $c$ such that $f(a,b,c)$ = $s$, and the number of AND operations is equal to $x$, the number of OR operations is equal to $y$ and the number of XOR operation is equal to $z$.
Can you help Ali to solve this question?
First line contains 4 integers $n$, $x$, $y$ and $z$ $(1 \leq n \leq 3 \cdot 10^{5})$ $(0 \leq x , y , z)$ $(x + y + z = n)$.
The second line contains a binary string of length $n$, which is string $a$.
The third line contains a binary string of length $n$, which is string $b$.
The fourth line contains a binary string of length $n$, which is string $s$.
If there exists a string of operations $c$ that satisfies the problem print YES on the first line, and print the string $c$ on the second line.
Otherwise, print NO.
Input | Output |
---|---|
4 2 1 1 1001 0101 1101 Copy
|
YES |^&& Copy
|
The cases that we will deal with in this question,
Case 1 : None of the operations will work:
Case 2: Only one possible operation:
Case 3: Two possible operations:
That will occur if there is a position i where a[i] = b[i] = s[i] = 1 ( AND operation and OR operation) , and if a[i] != b[i] and s[i] = 1 (XOR operation and OR operation), in the first case the priority will be for the AND operation and for the XOR operation in the second one; because OR works in both cases .
Case 4: All the operations work:
If there is a position i where a[i] = b[i] = s[i] = 0, so everything works and all the operations have the same priority, so it doesn’t matter which operation you fill first.