/*
----------------------------------------
stratege :stack && queue && simulation
Theam : 给你一系列数,一次进栈,问出栈的
顺序是否符合
Author: Johnsondu
Time: 2012-04-04
type: data structure
3 123 --- 213 ---》 Yes. in, in, out, out, in, out
-----------------------------------------
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
using namespace std ;
char in[1000], out[1000] ;
int n ;
char res[1000] ;
bool flag ;
int main ()
{
int i, j ;
int cnt, len ;
char ch, tmp ;
queue <string> op ;
stack <char> Q ;
while (scanf ("%d %s %s", &n, in, out) != EOF)
{
//cout << in << endl ;
//cout << out << endl ;
flag = true ;
while (!op.empty())
op.pop () ;
while (!Q.empty ())
Q.pop () ;
cnt = 0 ;
len = strlen (in) ;
Q.push (in[0]) ;
op.push ("in") ;
for (i = 1; i < len; i ++)
{
ch = Q.top () ;
if (Q.empty ()) //火车进栈,如果栈空,直接入栈
{
Q.push (in[i]) ;
op.push ("in") ;
continue ;
}
if (ch == out[cnt]) //如果栈顶元素和结果一致
{
Q.pop () ;
op.push ("out") ; // 出栈
cnt ++ ; // out 的元素下标
if (!Q.empty ()) //在此情况下,判断接下去的栈顶元素是否与当前out的值相同
{
tmp = Q.top () ;
while (tmp == out[cnt]) //相同则继续出栈
{
Q.pop () ;
cnt ++ ;
op.push ("out") ;
if (!Q.empty ())
tmp = Q.top () ;
else
break ;
}
}
Q.push (in[i]) ; //将当前值压入栈
op.push ("in") ;
}
else
{
Q.push (in[i]) ;
op.push ("in") ;
}
}
while (!Q.empty ())
{
ch = Q.top () ;
if (ch != out[cnt])
{
flag = false ;
break ;
}
else
{
Q.pop () ;
op.push ("out") ;
cnt ++ ;
}
}
if (flag)
{
printf ("Yes.\n") ;
while (!op.empty())
{
cout << op.front() << endl ;
op.pop () ;
}
}
else
printf ("No.\n") ;
printf ("FINISH\n") ;
}
return 0 ;
}