#include #include #include #include using namespace std; // 文字列から 'o' を除いた骨格 (相対順序) を取得する関数 string get_core(const string& s) { string core = ""; for (char c : s) { if (c != 'o') core += c; } return core; } // 「局所的な壁」が存在するか判定する嘘関数 bool has_local_wall(const string& s) { bool in_g = false; int o_count = 0; for (char c : s) { if (c == 'g') { in_g = true; o_count = 0; // 新しい g が来たらリセット } else if (c == 'o') { if (in_g) o_count++; } else if (c == 'd') { // g の後に o が3つ以上続いて d が来た場合、壁とみなす if (in_g && o_count >= 3) { return true; } in_g = false; } } return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; if (!(cin >> N)) return 0; string S, T; cin >> S >> T; // 1. 各文字の出現回数が一致するかチェック int cS[3] = {0}, cT[3] = {0}; for(char c : S) { if(c == 'd') cS[0]++; else if(c == 'o') cS[1]++; else cS[2]++; } for(char c : T) { if(c == 'd') cT[0]++; else if(c == 'o') cT[1]++; else cT[2]++; } for(int i = 0; i < 3; i++) { if(cS[i] != cT[i]) { cout << "No\n"; return 0; } } // 2. 嘘判定:局所的な壁の評価 bool s_wall = has_local_wall(S); bool t_wall = has_local_wall(T); // どちらかに壁がある場合、相対順序は絶対に変わらないと誤認する if (s_wall || t_wall) { if (get_core(S) == get_core(T)) { cout << "Yes\n"; } else { cout << "No\n"; } } else { // 壁がない場合は自由に交差可能とみなす cout << "Yes\n"; } return 0; }