eolymp
bolt
Try our new interface for solving problems
Problems

String Transformations

String Transformations

We are given two strings u and v composed of letters a and b. Our goal is to transform the string u into v using the following swap operation: choose two disjoint fragments ab and ba in the first string and swap them. Can u be transformed into v using a sequence of swap operations?

Input

The first line contains one integer n (2n106), the length of the strings. Two lines follow, each containing a string composed of n letters a and/or b. The first line describes the string u and the second line describes v. You can assume that the two strings differ.

Output

The first line should contain one word TAK (Polish for yes) or NIE (Polish for no) indicating if u can be transformed into v using the swap operations.

If the answer is positive and n4000, your program should output an example sequence of swap operations. The first line should contain one integer m (1m106), the number of operations. Each of the following m lines should contain two integers ai, bi (1ai, bin - 1), the positions of the starting letters of the fragments being swapped: ai denotes the position of ab and bi denotes the position of ba.

If there is more than one solution, your program should output any one of them. In particular, you do not need to minimize the number of operations, that is, the number m.

Time limit 1 second
Memory limit 128 MiB
Input example #1
6
aabbaa
baaaab
Output example #1
TAK
2
2 4
1 5
Input example #2
6
aaabbb
ababab
Output example #2
NIE
Source 2013 Petrozavodsk Winter Training Camp, January 31, Problem A