#arc172f. F - Walking

F - Walking

问题陈述

ATCoder的王国有 2N2N 个交叉点,用从 112N2N 的数字标记。

此外,沙特王国有三种单向道路:

-**类型A:**对于每个 2iN2 \leq i \leq N ,从十字路口 2i32i-3 到十字路口 2i12i-1 有一条路。-**类型B:**对于每个 2iN2 \leq i \leq N ,都有一条从交叉口 2i22i-2 到交叉口 2i2i 的道路。

-**类型C:**对于每个 1iN1 \leq i \leq N ,有一条道路连接方向为 sis_i 的交叉口 2i12i-1 和交叉口 2i2i

这里, sis_iXY ,其中方向 X 表示道路从交叉口 2i12i-1 到交叉口 2i2i ,而方向 Y 表示它从交叉点 2i2i 到交叉点 2i12i-1 。Takahashi想要几次,这样对于每个 1iN1 \leq i \leq N ,连接交叉口 2i12i-12i2i 的C类道路方向为 tit_i 。>**什么是散步?

**

从任意交叉点开始,重复以下操作零次或多次:

  • 如果可以从当前路口,沿着Type-C道路走到下一个路口。>- 否则,如果可以从当前交叉路口进入A类或B类道路,则沿该道路走到下一个交叉路口。

然后,反转所经过的所有C类道路的方向。

计算实现目标所需的最小步行次数,并提供一种在最小步行次数内实现目标的方法。

在这个问题的约束条件下,可以证明在有限的行走次数内可以达到目标。

以上为机器翻译结果,仅供参考。

Problem Statement

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

  • Type A: For each 2iN2 \leq i \leq N, there is a road from intersection 2i32i-3 to intersection 2i12i-1.
  • Type B: For each 2iN2 \leq i \leq N, there is a road from intersection 2i22i-2 to intersection 2i2i.
  • Type C: For each 1iN1 \leq i \leq N, there is a road connecting intersection 2i12i-1 and intersection 2i2i with direction sis_i.

Here, sis_i is X or Y, where direction X means the road goes from intersection 2i12i-1 to intersection 2i2i, and direction Y means it goes from intersection 2i2i to intersection 2i12i-1.

Takahashi wants to walk several times so that for each 1iN1 \leq i \leq N, the direction of Type-C road connecting intersections 2i12i-1 and 2i2i will be tit_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

  • NN is an integer such that 1N40001 \leq N \leq 4000.
  • Each of s1,s2,,sNs_1, s_2, \dots, s_N is X or Y.
  • Each of t1,t2,,tNt_1, t_2, \dots, t_N is X or Y.

Input

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

NN

s1s2sNs_1 s_2 \cdots s_N

t1t2tNt_1 t_2 \cdots t_N

Output

Print your solution in the following format, where XX is the number of walks, and the ii-th walk (1iX)(1 \leq i \leq X) starts at intersection aia_i and finishes at intersection bib_i.

XX

a1a_1 b1b_1

a2a_2 b2b_2

\vdots

aXa_X bXb_X

Sample Input 1

5
XYXYX
XXYXX

Sample Output 1

1
2 7

In this sample input, Takahashi will walk as follows:

  • Start at intersection 22.
  • Since there is no Type-C road to proceed from intersection 22, walk along the Type-B road to intersection 44.
  • Since there is a Type-C road to proceed from intersection 44, walk along the Type-C road to intersection 33.
  • Since there is no Type-C road to proceed from intersection 33, walk along the Type-A road to intersection 55.
  • Since there is a Type-C road to proceed from intersection 55, walk along the Type-C road to intersection 66.
  • Since there is no Type-C road to proceed from intersection 66, walk along the Type-B road to intersection 88.
  • Since there is a Type-C road to proceed from intersection 88, walk along the Type-C road to intersection 77.
  • Finish at intersection 77.

This walk passes through the following three Type-C roads:

  • The road connecting intersection 33 and intersection 44.
  • The road connecting intersection 55 and intersection 66.
  • The road connecting intersection 77 and intersection 88.

The directions of these roads are reversed, so the directions of the roads connecting intersections 2i12i-1 and 2i2i for i=1,2,3,4,5i = 1, 2, 3, 4, 5 are now X, X, Y, X, X, respectively, achieving the goal.

Sample Input 2

5
XXYYX
XXYYX

Sample Output 2

0

Note that the goal is already achieved at the beginning, so there is no need to walk even once.

Sample Input 3

5
XXXXX
YYYYY

Sample Output 3

5
1 2
3 4
5 6
7 8
9 10

Sample Input 4

20
XXXYXYYXXXYXXXXYYXXY
XXYXYYXXYXXYXYXYXYXY

Sample Output 4

5
14 18
29 38
14 26
5 10
27 35

Sample Input 5

20
YXYXYXYYYXYYXYYXYXXX
XXXXXYXYYYXYYXXYYYXY

Sample Output 5

5
29 36
10 38
2 3
4 7
28 40