Algorithm


E. Two Small Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Possible examples of strings s and t: "ab", "ca", "bb".

You have to find a string res��� consisting of 3n3� characters, n characters should be 'a', n characters should be 'b' and n characters should be 'c' and s and t should not occur in res��� 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 n (1n1051≤�≤105) — the number of characters 'a', 'b' and 'c' in the resulting string.

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

The third line of the input contains one string t 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 res��� on the second line. res��� should consist of 3n3� characters, n characters should be 'a', n characters should be 'b' and n characters should be 'c' and s and t should not occur in res��� as substrings.

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

Examples
input
Copy
2
ab
bc
output
Copy
YES
acbbac
input
Copy
3
aa
bc
output
Copy
YES
cacbacbab
input
Copy
1
cb
ac
output
Copy
YES
abc

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int n;
string s, t;

int main() {
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
#endif

	scanf("%d", &n);
	cin >> s >> t;

	string per = "abc";

	do {
		string res;

		res = "";
		for(int i = 0; i < n; ++i)
			res += per;
		if(res.find(s) == string::npos && res.find(t) == string::npos) {
			cout << "YES" << endl << res << endl;
			return 0;
		}

		res = "";
		for(int i = 0; i < 3; ++i)
			for(int j = 0; j < n; ++j)
				res += per[i];
		if(res.find(s) == string::npos && res.find(t) == string::npos) {
			cout << "YES" << endl << res << endl;
			return 0;
		}
	} while(next_permutation(per.begin(), per.end()));

	puts("NO");

	return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
2
ab
bc

Output

x
+
cmd
YES
acbbac
Advertisements

Demonstration


Codeforcess Solution Two Small Strings,E. Two Small Strings-Solution in C, C++, Java, Python,Codeforcess Solution

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+