http://acm.hdu.edu.cn/showproblem.php?pid=1022
#include<iostream>
#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
int main()
{
int n ;
int vis[ 1005 ] ;
char a[ 1005 ] , b[ 1005 ] ;
while( cin >> n >> a >> b )
{
memset( vis , 0 , sizeof( vis ) ) ;
stack<char> STACK ;
int i , j , k ;
i = j = k = 0 ;
while( i < n )
{
if( STACK.empty() || STACK.top() != b[ i ] && j < n )
{
STACK.push( a[ j++ ] ) ;
vis[ k++ ] = 1 ;
}
else
if( STACK.top() == b[ i ] )
{
STACK.pop() ;
vis[ k++ ] = 0 ;
i++ ;
}
else
break ;
}
if( STACK.empty() )
{
cout << "Yes."<<endl;
for( i = 0 ; i < k ; i++ )
{
if( vis[ i ] )
puts("in") ;
else
puts("out");
}
}
else
cout << "No." <<endl ;
printf( "FINISH\n" ) ;
}
return 0 ;
}