#P1446. Ignatius Train Problem

Ignatius Train Problem

Description

随着新学期的到来,Ignatius 火车站现在非常繁忙。很多学生想乘火车回到学校(因为Ignatius 火车站的火车是世界上最快的火车^v^)。但这里有一个问题,只有一条铁路,所有的火车都停在那里。所以所有的火车都从一边进来,从另一边出来。对于这个问题,如果火车A先进入铁路,然后火车B在火车A离开之前进入铁路,火车A在火车B离开之前不能离开。下面的图片解决了问题。现在的问题是,车站里最多有9列火车,所有火车都有一个ID(编号从1到n),火车按O1顺序进入铁路,你的任务是确定火车是否可以按O2顺序下车。

Format

Input

输入包含多个测试用例。每个测试用例由一个整数、训练次数和两个字符串组成,训练的顺序来自:O1,训练的顺序离开:O2。输入在文件末尾终止。有关更多详细信息,请参阅示例输入。

Output

如果无法将 O2 交换为 O1,则输出包含字符串"No",或者应输出包含"Yes."的行,然后输出交换顺序的方式(应输出"in"表示进入铁路的列车,"out"表示离开铁路的列车)。在每个测试用例后打印一行包含"FINISH"的行。有关更多详细信息,请参阅示例输出。

Samples

2
3 123 321
3 123 312
Yes.
in
in
in
out
out
out
FINISH
No.
FINISH

Hint

For the first Sample Input, we let train 1 get in, then train 2 and train 3. So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1. In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3. Now we can let train 3 leave. But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment. So we output "No.".

Limitation

1s, 1024KiB for each test case.