AtCoder Regular Contest 172
F
Walking
AtCoder
⌀ 3474
原题
← E→
翻译中…

Problem Statement

翻译中…

The Kingdom of AtCoder has $2N$ intersections labeled with numbers from $1$ to $2N$. Additionally, there are three types of one-way roads in the kingdom:

翻译中…
  • Type A: For each $2 \leq i \leq N$, there is a road from intersection $2i-3$ to intersection $2i-1$.
  • Type B: For each $2 \leq i \leq N$, there is a road from intersection $2i-2$ to intersection $2i$.
  • Type C: For each $1 \leq i \leq N$, there is a road connecting intersection $2i-1$ and intersection $2i$ with direction $s_i$.
翻译中…

Here, $s_i$ is X or Y, where direction X means the road goes from intersection $2i-1$ to intersection $2i$, and direction Y means it goes from intersection $2i$ to intersection $2i-1$.

翻译中…

Takahashi wants to walk several times so that for each $1 \leq i \leq N$, the direction of Type-C road connecting intersections $2i-1$ and $2i$ will be $t_i$.

翻译中…

What is a walk?

Start at any intersection and repeat the following action zero or more times:

  • If it is possible to proceed to a Type-C road from the current intersection, walk along the Type-C road to the next intersection.
  • Otherwise, if it is possible to proceed to a Type-A or B road from the current intersection, walk along that road to the next intersection.

Then, reverse the directions of all Type-C roads that were passed.

翻译中…

Calculate the minimum number of walks needed to achieve the goal and provide one method to achieve the goal in the minimum number of walks. Under the constraints of this problem, it can be proved that the goal can be achieved in a finite number of walks.

翻译中…

Constraints

翻译中…
  • $N$ is an integer such that $1 \leq N \leq 4000$.
  • Each of $s_1, s_2, \dots, s_N$ is X or Y.
  • Each of $t_1, t_2, \dots, t_N$ is X or Y.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
s_1 s_2 \cdots s_N
t_1 t_2 \cdots t_N

翻译中…

Output

翻译中…

Print your solution in the following format, where $X$ is the number of walks, and the $i$-th walk $(1 \leq i \leq X)$ starts at intersection $a_i$ and finishes at intersection $b_i$.

翻译中…

X
a_1 b_1
a_2 b_2
\vdots
a_X b_X

翻译中…

样例

Input #1
5
XYXYX
XXYXX
Output #1
1
2 7
In this sample input, Takahashi will walk as follows: - Start at intersection $2$. - Since there is no Type-C road to proceed from intersection $2$, walk along the Type-B road to intersection $4$. - Since there is a Type-C road to proceed from intersection $4$, walk along the Type-C road to intersection $3$. - Since there is no Type-C road to proceed from intersection $3$, walk along the Type-A road to intersection $5$. - Since there is a Type-C road to proceed from intersection $5$, walk along the Type-C road to intersection $6$. - Since there is no Type-C road to proceed from intersection $6$, walk along the Type-B road to intersection $8$. - Since there is a Type-C road to proceed from intersection $8$, walk along the Type-C road to intersection $7$. - Finish at intersection $7$. This walk passes through the following three Type-C roads: - The road connecting intersection $3$ and intersection $4$. - The road connecting intersection $5$ and intersection $6$. - The road connecting intersection $7$ and intersection $8$. The directions of these roads are reversed, so the directions of the roads connecting intersections $2i-1$ and $2i$ for $i = 1, 2, 3, 4, 5$ are now `X`, `X`, `Y`, `X`, `X`, respectively, achieving the goal.
Input #2
5
XXYYX
XXYYX
Output #2
0
Note that the goal is already achieved at the beginning, so there is no need to walk even once.
Input #3
5
XXXXX
YYYYY
Output #3
5
1 2
3 4
5 6
7 8
9 10
Input #4
20
XXXYXYYXXXYXXXXYYXXY
XXYXYYXXYXXYXYXYXYXY
Output #4
5
14 18
29 38
14 26
5 10
27 35
Input #5
20
YXYXYXYYYXYYXYYXYXXX
XXXXXYXYYYXYYXXYYYXY
Output #5
5
29 36
10 38
2 3
4 7
28 40
题目信息
题号
arc172_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。