PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#TP0000068. Bài toán yêu thích của awoo (awoo's Favorite Problem)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 ss and tt of equal length nn, 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 ss:

  • Replace ab with ba.
  • Replace bc with cb.

The reverse transformations are not permitted unless they match one of these two rules. Determine whether ss can be transformed into exactly tt.

Input

The first line contains the integer nn.

The second line contains a string ss of length nn.

The third line contains a string tt of length nn.

Output

Print YES if the transformation is possible; otherwise, print NO.

Subtasks

  • Subtask 1 (20 points): 1≤n≤81\le n\le 8; ∣s∣=∣t∣=n|s|=|t|=n; si,ti∈{a,b,c}s_i,t_i\in\{\texttt{a},\texttt{b},\texttt{c}\} for every 1≤i≤n1\le i\le n.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; ∣s∣=∣t∣=n|s|=|t|=n; si,ti∈{a,b,c}s_i,t_i\in\{\texttt{a},\texttt{b},\texttt{c}\} for every 1≤i≤n1\le i\le n.
  • Subtask 3 (50 points): 1≤n≤1000001\le n\le 100000; ∣s∣=∣t∣=n|s|=|t|=n; si,ti∈{a,b,c}s_i,t_i\in\{\texttt{a},\texttt{b},\texttt{c}\} for every 1≤i≤n1\le i\le n.

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 2,32,3 to obtain bbaabc. Finally replace bc at positions 5,65,6 by cb, producing bbaacb, equal to tt. Hence the output is YES.