2019个人训练赛-F - Two Small Strings

You are given two strings ss and tt both of length 22 and both consisting only of characters 'a', 'b' and 'c'.

Possible examples of strings ss and tt : "ab", "ca", "bb".

You have to find a string resres consisting of 3n3n characters, nn characters should be 'a', nn characters should be 'b' and nn characters should be 'c' and ss and tt should not occur in resres as substrings.

A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".

If there are multiple answers, you can print any of them.

Input

The first line of the input contains one integer nn (1n1051≤n≤105 ) — the number of characters 'a', 'b' and 'c' in the resulting string.

The second line of the input contains one string ss of length 22 consisting of characters 'a', 'b' and 'c'.

The third line of the input contains one string tt of length 22 consisting of characters 'a', 'b' and 'c'.

Output

If it is impossible to find the suitable string, print "NO" on the first line.

Otherwise print "YES" on the first line and string resres on the second line. resres should consist of 3n3n characters, nn characters should be 'a', nn characters should be 'b' and nn characters should be 'c' and ss and tt should not occur in resres as substrings.

If there are multiple answers, you can print any of them.

Examples

Input
2
ab
bc
Output
YES
acbbac
Input
3
aa
bc
Output
YES
cacbacbab
Input
1
cb
ac
Output
YES
abc
学会了使用迭代器来遍历vector,棒棒哒
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

vector<string> arr;
int n;
string abc="abc",c;

int main(){
    string s,t;
    cin>>n>>s>>t;
    
    do{
        string cur;
        for(int i=0;i<n;i++)
            cur+=abc;
        arr.push_back(cur);
        arr.push_back(string(n,abc[0])+string(n,abc[1])+string(n,abc[2]));
    }while(next_permutation(abc.begin(), abc.end()));
    
    for(std::vector<string>::iterator it=arr.begin();it!=arr.end();it++){
        string::size_type position,position1;
        c=*it;
        position =c.find(s);
        position1=c.find(t);
        if(position==c.npos&&position1==c.npos){
            cout<<"YES"<<endl;
            cout<<c<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

 

 
posted @ 2019-09-08 21:46  慌的一批  阅读(252)  评论(0编辑  收藏  举报