#include<bits/stdc++.h>
#define Maxn 500005
using namespace std;
stack<char> st;
string solve(string s) {
for(auto a:s) {
st.push(a);
if((int)st.size() > 2) {
char u = st.top(); st.pop();
char v = st.top(); st.pop();
if((u+1)%3 == st.top()%3&&(st.top()+1)%3 == v%3&&(v+1)%3 == u%3)st.pop();
else st.push(v),st.push(u);
}
} string t;
while(!st.empty())t = st.top()+t,st.pop();
return t;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
string s,t;
cin>>s>>s>>t;
// cout<<solve(s)<<" ";
// cout<<solve(t)<<"\n";
s = solve(s); t = solve(t);
if(s == t)cout<<"YES";
else cout<<"NO"; return 0;
}