QOJ.ac

QOJ

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

#10301. Chocological

Statistics

There is a $2\times n$ grid, where the cell at row $i$ and column $j$ is denoted as $(i,j)\ (1\leq i\leq 2,\ 1\leq j\leq n)$. Some of these cells contain a person.

In each operation, you can choose one of the following:

  • Choose a row $i$ and align all people in that row to the left. That is, if there are $x$ people in row $i$, change the occupied cells in that row to all $(i,j)\ (1\leq j\leq x)$.
  • Choose a row $i$ and align all people in that row to the right. That is, if there are $x$ people in row $i$, change the occupied cells in that row to all $(i,n-j+1)\ (1\leq j\leq x)$.
  • Choose a column $j$ and align all people in that column to the top. That is, if there are $x$ people in column $j$, change the occupied cells in that column to all $(i,j)\ (1\leq i\leq x)$.
  • Choose a column $j$ and align all people in that column to the bottom. That is, if there are $x$ people in column $j$, change the occupied cells in that column to all $(2-i+1,j)\ (1\leq i\leq x)$.

Given an initial state and a final state (i.e., whether each cell contains a person, with the total number of people guaranteed to be the same), determine if it is possible to transform the initial state into the final state using at most $10^6$ operations. If possible, provide a sequence of operations.

Input

The first line contains an integer $n$.

The second line contains a binary string of length $n$, where the $j$-th character is $1$ if and only if there is a person at $(1,j)$ in the initial state.

The third line contains a binary string of length $n$, where the $j$-th character is $1$ if and only if there is a person at $(2,j)$ in the initial state.

The fourth line contains a binary string of length $n$, where the $j$-th character is $1$ if and only if there is a person at $(1,j)$ in the final state.

The fifth line contains a binary string of length $n$, where the $j$-th character is $1$ if and only if there is a person at $(2,j)$ in the final state.

Output

If there is no solution, output NO.

Otherwise, output YES, followed by:

The first line: an integer $m$, representing the number of operations, where $0\leq m\leq 10^6$.

The next $m$ lines: each contains two integers, representing the operation type (numbered $1, 2, 3, 4$ according to the order in the problem description) and the row/column index.

Examples

Input

6
010100
110001
010001
100011

Output

YES
3
2 1
3 2
4 5

Input

6
000100
000000
001000
000000

Output

NO

Subtasks

For all data: $1\leq n\leq 10^5$.

$\text{Subtask 1}\ (2\%)$: Guaranteed to have no solution.

$\text{Subtask 2}\ (13\%)$: $n\leq 10$.

$\text{Subtask 3}\ (15\%)$: The number of people is at most $10$.

$\text{Subtask 4}\ (20\%)$: Guaranteed to have a solution.

$\text{Subtask 5}\ (10\%)$: The number of people is at most $n$, and the $j$-th person in the initial state is at $(1,j)$.

$\text{Subtask 6}\ (20\%)$: The number of people is at most $n$.

$\text{Subtask 7}\ (20\%)$: No special restrictions.

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.