#TP0000068. Bài toán yêu thích của awoo (awoo's Favorite Problem)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bài toán yêu thích của awoo (awoo's Favorite Problem)
awoo's Favorite Problem
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given two strings and of equal length , each containing only the characters a, b, and c. You may perform any number of the following operations on adjacent characters of the current string :
- Replace
abwithba. - Replace
bcwithcb.
The reverse transformations are not permitted unless they match one of these two rules. Determine whether can be transformed into exactly .
Input
The first line contains the integer .
The second line contains a string of length .
The third line contains a string of length .
Output
Print YES if the transformation is possible; otherwise, print NO.
Subtasks
- Subtask 1 (20 points): ; ; for every .
- Subtask 2 (30 points): ; ; for every .
- Subtask 3 (50 points): ; ; for every .
Examples
Input
6
abbabc
bbaacb
Output
YES
Explanation
Start with abbabc. Replace the leading ab by ba to get bababc; then replace ab at positions to obtain bbaabc. Finally replace bc at positions by cb, producing bbaacb, equal to . Hence the output is YES.