Problem:
F Painting
問題文
$N$ 個のマスが横一列に並んでいます。マスは左から順に $1, 2, \ldots N$ と番号がつけられています。
各マスは赤、青、黄、緑のいずれか $1$ 色で塗られています。
現在のマスの状態は長さ $N$ の文字列で表され、$S$ の $i$ 文字目がマス $i$ の色を表しています。(
R
、
B
、
Y
、
G
がそれぞれ赤、青、黄、緑に対応します。)
heno 君はこのマス目に対して以下の操作を何度でも行うことができます。
操作 : $1\leq i \leq N-1$ かつマス $i$ とマス $i+1$ の色が異なるような $i$ を選ぶ。マス $i$ とマス $i+1$ を、どちらにも用いられていない $2$ 色で$1$ つずつ塗る。(マス $i$ とマス $i+1$ を同じ色で塗ることはできない。) (具体的な操作については入出力を参考にしてください。) (15:05 更新)
heno 君の目標はマス目を文字列 $T$ で表される状態にすることです。これが可能か判定してください。
入力
入力は以下の形式で標準入力から与えられる。
$N$
$S$
$T$
制約
$2 \leq N \leq 10^6$
$S, T$ は
R
,
B
,
Y
,
G
のみからなる長さ $N$ の文字列
出力
heno くんが目標を達成することが可能ならば
Yes
、不可能ならば
No
と $1$ 行に出力してください。
入力例1
4
RGRB
YRGG
出力例1
Yes
例えば以下のように操作を行うとよいです。
RGRB
→
RGYG
→
YBYG
→
YRGG
入力例2
5
RRRRR
YYYYY
出力例2
No
入力例3
10
RRGBYRBYYG
BGRRYGGGGY
出力例3
Yes

Submitted solutions:

code_snippet: #pragma GCC optimize("Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <sstream>
#include <utility>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <array>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline ll time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int u(char c){
    if(c == 'R')return 0;
    else if(c == 'B')return 1;
    else if(c == 'Y')return 2;
    else return 3;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s,t; cin >> s >> t;
    {
        auto r = s;
        sort(r.begin(), r.end());
        if(r[0] == r.back()){
            if(s == t){
                cout << "Yes" << "\n";
            }
            else{
                cout << "No" << "\n";
            }
            return 0;
        }
        r = t;
        sort(r.begin(), r.end());
        if(r[0] == r.back()){
            if(s == t){
                cout << "Yes" << "\n";
            }
            else{
                cout << "No" << "\n";
            }
            return 0;
        }
    }
    int g = 0, gg = 0;
    for(char c:s){
        g ^= u(c);
    }
    for(char c:t){
        gg ^= u(c);
    }
    if(g == gg){
        cout << "Yes" << "\n";
    }
    else{
        cout << "No" << "\n";
    }
}
accuracy: 1
time_ms: 30
memory_kb: 6576
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;

using Int = long long;
const char newl = '\n';

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}
template<typename T=int>
vector<T> read(size_t n){
  vector<T> ts(n);
  for(size_t i=0;i<n;i++) cin>>ts[i];
  return ts;
}

//INSERT ABOVE HERE
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(0);

  int n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  if(s==t) drop("Yes");
  if(s==string(n,s[0])) drop("No");

  map<char,int> num;
  num['R']=0;
  num['B']=1;
  num['Y']=2;
  num['G']=3;

  int ss=0,st=0;
  for(char c:s) ss^=num[c];
  for(char c:t) st^=num[c];

  // cout<<ss<<' '<<st<<newl;
  cout<<((ss%4)==(st%4)?"Yes":"No")<<newl;
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6464
final_rank: 7

code_snippet: #include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second

using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

void yes() {cout<<"Yes"<<endl; exit(0);}
void no() {cout<<"No"<<endl; exit(0);}

int main() {
    string T;
    cin>>N>>S>>T;
    if(S == T) yes();
    vec n1(4, 0), n2(4, 0);
    map<char, int> ci = {{'R', 0}, {'G', 1}, {'B', 2}, {'Y', 3}};
    rep(i, N){
        ++n1[ci[S[i]]];
        ++n2[ci[T[i]]];
    }
    if(*max_element(ALL(n1)) == N || *max_element(ALL(n2)) == N) no();
    int judge(0);
    rep(i, 4){
        if(abs(n1[i] - n2[i])&1) ++judge;
    }
    if(judge == 2) no();
    else yes();
}
accuracy: 1
time_ms: 50
memory_kb: 5588
final_rank: 2

code_snippet: //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const T &a) {
    for (auto e : a) cout << e << ' ';
    cout << '\n';
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

int conv(char c) {
    if (c == 'R') return 0;
    if (c == 'B') return 1;
    if (c == 'Y') return 2;
    if (c == 'G') return 3;
    else return -1;
}

void solve() {
    int n; cin >> n;
    string s, t; cin >> s >> t;

    if (s == t) {
        cout << "Yes" << '\n';
        return;
    }

    set<char> ss, st; 
    int s_xor = 0, t_xor = 0;
    for (char c : s) {
        ss.insert(c);
        s_xor ^= conv(c);
    }
    for (char c : t) {
        st.insert(c);
        t_xor ^= conv(c);
    }

    if (ss.size() == 1 || st.size() == 1) {
        cout << "No" << '\n';
    }
    else {
        if (s_xor == t_xor) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 1
time_ms: 20
memory_kb: 6496
final_rank: 8

code_snippet: #include <iostream>
#include <string>
using namespace std;
int cnt[2][4] = {};
int main(){
    int i,n; cin >> n;
    string s,t; cin >> s >> t;
    for(i=0;i<n;i++){
        if(s[i]=='R') cnt[0][0]++;
        if(s[i]=='B') cnt[0][1]++;
        if(s[i]=='G') cnt[0][2]++;
        if(s[i]=='Y') cnt[0][3]++;
        if(t[i]=='R') cnt[1][0]++;
        if(t[i]=='B') cnt[1][1]++;
        if(t[i]=='G') cnt[1][2]++;
        if(t[i]=='Y') cnt[1][3]++;
    }
    int a = 0,b = 0;
    for(i=0;i<4;i++){
        if(cnt[0][i]) a++;
        if(cnt[1][i]) b++;
    }
    if(a==1 || b==1){
        bool f = true;
        for(i=0;i<4;i++){
            if(cnt[0][i]!=cnt[1][i]) f = false; 
        }
        if(f) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else{
        int c = 0;
        for(i=0;i<4;i++){
            if((cnt[0][i] - cnt[1][i]) & 1) c++;
        }
        if(c==0 || c==4) cout << "Yes" << endl;
        else cout <<"No" << endl;
    }
}
accuracy: 1
time_ms: 30
memory_kb: 6940
final_rank: 10

code_snippet: #include <iostream>
#include <string>
using namespace std;
int cnt[2][4] = {};
int main(){
    int i,n; cin >> n;
    string s,t; cin >> s >> t;
    for(i=0;i<n;i++){
        if(s[i]=='R') cnt[0][0]++;
        if(s[i]=='B') cnt[0][1]++;
        if(s[i]=='G') cnt[0][2]++;
        if(s[i]=='Y') cnt[0][3]++;
        if(t[i]=='R') cnt[1][0]++;
        if(t[i]=='B') cnt[1][1]++;
        if(t[i]=='G') cnt[1][2]++;
        if(t[i]=='Y') cnt[1][3]++;
    }
    int a = 0,b = 0;
    for(i=0;i<4;i++){
        if(cnt[0][i]) a++;
        if(cnt[1][i]) b++;
    }
    if(a==1 || b==1){
        bool f = true;
        for(i=0;i<n;i++){
            if(cnt[0][i]!=cnt[1][i]) f = false; 
        }
        if(f) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else{
        int c = 0;
        for(i=0;i<4;i++){
            if((cnt[0][i] - cnt[1][i]) & 1) c++;
        }
        if(c==0 || c==4) cout << "Yes" << endl;
        else cout <<"No" << endl;
    }
}
accuracy: 0.4716981132075472
time_ms: 30
memory_kb: 6972
final_rank: 20

code_snippet: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
int main(){
    int n;
    string s,t;
    cin>>n;
    cin>>s>>t;
    map<char,int> mp;
    string str="RGBY";
    for(int i=0;i<4;i++){
        mp[str[i]]=i;
    }
    V<int> d(4,0),e(4,0);
    for(int i=0;i<n;i++){
        d[mp[s[i]]]++;
        e[mp[t[i]]]++;
    }
    s.erase(unique(all(s)),s.end());
    t.erase(unique(all(t)),t.end());
    if(s.size()==1||t.size()==1){
        if(s==t){
            cout<<"Yes"<<"\n";
        }else{
            cout<<"No"<<"\n";
        }
        return 0;
    }
    V<ll> res(4,0);
    ll sum=0;
    for(int i=0;i<4;i++){
        res[i]=d[i]-e[i];
        sum+=res[i];
    }
    if(sum!=0){
        cout<<"No"<<"\n";
        return 0;
    }
    V<int> cnt(2,0);
    for(int i=0;i<4;i++){
        cnt[abs(res[i])%2]++;
    }
    if(cnt[0]>0&&cnt[1]>0){
        cout<<"No"<<"\n";
    }else{
        cout<<"Yes"<<"\n";
    }
}
accuracy: 1
time_ms: 20
memory_kb: 6292
final_rank: 5

code_snippet: #pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
#define lg length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<ll,ll> a,pair<ll,ll> b){
    if(a.fi!=b.fi)
        return  a.se<b.se;
    else
        return a.se>b.se;
}
//----------------------------------------------------------------------
ll cal(char c){
    if(c=='R')return 0;
    else if(c=='G')return 1;
    else if(c=='B')return 2;
    else return 3;
}
//----------------------------------------------------------------------
int main(int argc, char * argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("big.txt", "r", stdin);
    //freopen("out3.txt", "w", stdout);
    //------------------------------
    ll n;cin>>n;
    string s,t;cin>>s>>t;
    bool a=1,b=1;
    for(ll i=1;i<n;i++){
        if(s[i]!=s[0])a=0;
        if(t[i]!=t[0])b=0;
    }
    if(a==1||b==1){
        if(s==t){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<Endl;
        return 0;
    }

    ll axor=0,bxor=0;
    for(ll i=0;i<n;i++){
        axor^=cal(s[i]);
        bxor^=cal(t[i]);
    }
    if(axor==bxor){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<Endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------
accuracy: 1
time_ms: 10
memory_kb: 6040
final_rank: 3

code_snippet: #pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <numeric>
#define IINF 1000000000
#define INF 3223372036854775807
#define MOD 1000000007
#define mod 1000000007
#define INT_MAX_ 2147483647
#define EPS (1e-10)
#define REP(i, a, n) fo-r (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
//#define rep(i,n)for (ll i = 0; i < (ll)(n); i++)
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
#define me memset
#define bit(n,k) ((n>>k)&1)
#define lg length()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define invp(a,p)pom(a,p-2,p)
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp1(pair<Pll,ll> a,pair<Pll,ll> b){
        return a.fi.se>b.fi.se;
}
ll cmp2(pair<ll,ll> a,pair<ll,ll> b){
    if(a.fi!=b.fi)
        return  a.se<b.se;
    else
        return a.se>b.se;
}
//----------------------------------------------------------------------
ll cal(char c){
    if(c=='R')return 0;
    else if(c=='G')return 1;
    else if(c=='B')return 2;
    else return 3;
}
//----------------------------------------------------------------------
int main(int argc, char * argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_t=clock();
    //freopen("big.txt", "r", stdin);
    //freopen("out3.txt", "w", stdout);
    //------------------------------
    ll n;cin>>n;
    string s,t;cin>>s>>t;
    bool a=1,b=1;
    for(ll i=1;i<n;i++){
        if(s[i]!=s[0])a=0;
        if(t[i]!=t[0])b=0;
    }
    if(a==1&&b==1){
        if(s[0]==t[0]){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<Endl;
        return 0;
    }

    ll axor=0,bxor=0;
    for(ll i=0;i<n;i++){
        axor^=cal(s[i]);
        bxor^=cal(t[i]);
    }
    if(axor==bxor){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<Endl;
    //------------------------------
    //fclose(stdin);
    //fclose(stdout);
    //ll end_t=clock();cout<<"time="<<end_t-begin_t<<"ms"<<endl;
    //------------------------------- 
    return 0;
}
//----------------------------------------------------------------------
accuracy: 0.6792452830188679
time_ms: 10
memory_kb: 6044
final_rank: 18

code_snippet: #include <iostream>
#include <algorithm>
#include <vector>
#include <string>

void solve() {
    int n;
    std::string s, t;
    std::cin >> n >> s >> t;

    if (std::all_of(s.begin(), s.end(),
                    [&](char c) { return s.front() == c; })) {
        std::cout << (s == t ? "Yes" : "No") << "\n";
        return;
    }

    int x = 0;
    s += t;
    for (char c : s) {
        for (int i = 0; i < 4; ++i) {
            if (c == "RBYG"[i]) x ^= i;
        }
    }

    std::cout << (x == 0 ? "Yes" : "No") << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 7264
final_rank: 14

code_snippet: #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);



string c = "RBYG";
void solve() {
	int n; string s, t; cin >> n >> s >> t;
	if (s == t) {
		cout << "Yes\n"; return;
	}
	int xs = 0, xt = 0;
	rep(i, n) {
		xs ^= c.find(s[i]);
		xt ^= c.find(t[i]);
	}
	if (xs != xt) {
		cout << "No\n"; return;
	}
	bool sexi = false;
	bool texi = false;
	rep(i, n-1) {
		if (s[i] != s[i + 1])sexi = true;
		if (t[i] != t[i + 1])texi = true;
	}
	if (!sexi||!texi) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}
}





signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 6396
final_rank: 6

code_snippet: #include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int char_to_int(char c) {
    if (c == 'R')
        return 0;
    else if (c == 'B')
        return 1;
    else if (c == 'Y')
        return 2;
    else
        return 3;
}

bool all_same(string &s) {
    rep(i, s.size() - 1) if (s[i] != s[i + 1]) return false;
    return true;
}

int main() {
    int n;
    string s, t;
    cin >> n >> s >> t;
    if (all_same(s) || all_same(t)) {
        puts(s == t ? "Yes" : "No");
    } else {
        int x = 0, y = 0;
        rep(i, n) x ^= char_to_int(s[i]), y ^= char_to_int(t[i]);
        puts(x == y ? "Yes" : "No");
    }
}
accuracy: 1
time_ms: 30
memory_kb: 6960
final_rank: 11

code_snippet: #include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353;
constexpr int MAX = 5000000;

int main()
{

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	string s; cin >> s;
	string t; cin >> t;

	{
		string ts = s;
		string tt = t;
		sort(ts.begin(), ts.end());
		sort(tt.begin(), tt.end());
		if (ts[0] == ts.back() or tt[0] == tt.back()) {
			if (s == t) {
				cout << "Yes" << "\n";
			}
			else {
				cout << "No" << "\n";
			}
			return 0;
		}
	}

	auto cnv = [](char c)->int {
		if (c == 'R') return 0;
		if (c == 'B') return 1;
		if (c == 'G') return 2;
		if (c == 'Y') return 3;
		return -1;
	};
	int xs = 0;
	int ts = 0;
	for (int i = 0; i < n; i++) xs ^= cnv(s[i]);
	for (int i = 0; i < n; i++) ts ^= cnv(t[i]);
	if (xs != ts) cout << "No" << "\n";
	else cout << "Yes" << "\n";
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 7240
final_rank: 15

code_snippet: #pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>

#define __builtin_popcount __popcnt
#define __builtin_popcountll __popcnt64
#endif

#include <limits.h>
#include <math.h>
#include <time.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <complex>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//#include<atcoder/all>

using namespace std;

//using namespace atcoder;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define FORR(i, m, n) for (int i = m - 1; i >= n; --i)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v, n) reverse(v, v + n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout << (x) << endl
#define pe(x) cout << (x) << " "
#define DEBUG(x) cout << #x << ": " << x << endl
#define lb(v, n) lower_bound(v.begin(), v.end(), (n))
#define ub(v, n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i, v.size()) cout << v[i] << " \n"[i==(int)v.size()-1]
template <typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template <typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7;
constexpr int MAX = 500050;
const double pi = acos(-1);
constexpr double EPS = 1e-8;
constexpr ll LINF = 1e18 + 1;
constexpr int INF = 1e9 + 1;
void Yes(bool cond) { cout << (cond ? "Yes" : "No") << '\n'; }
void YES(bool cond) { cout << (cond ? "YES" : "NO") << '\n'; }


int id[300];
void solve() {
	int N; cin >> N;
	string S;
	string T;
	cin >> S >> T;
	id['R'] = 0;
	id['B'] = 1;
	id['Y'] = 2;
	id['G'] = 3;
	int a = 0, b = 0;
	map<char, int>mps, mpt;
	for (auto c : S) {
		mps[c]++;
	}
	for (auto c : T) {
		mpt[c]++;
	}
	if (mps.size() == 1 || mpt.size() == 1) {
		if (mps.size() > 1 || mpt.size() > 1) {
			print("No"); return;
		}
		else {
			Yes(S[0] == T[0]);
			return;
		}
	}
	for (auto c : S)a ^= id[c];
	for (auto c : T)b ^= id[c];
	if (a == b)print("Yes");
	else print("No");
}



signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	//int q;
	//cin >> q;
	//while (q--)
	solve();

}
accuracy: 1
time_ms: 20
memory_kb: 6132
final_rank: 4

code_snippet: //#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << '\n';
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const T &a) {
    for (auto e : a) cout << e << ' ';
    cout << '\n';
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

int conv(char c) {
    if (c == 'R') return 0;
    if (c == 'B') return 1;
    if (c == 'Y') return 2;
    if (c == 'G') return 3;
    else return -1;
}

void solve() {
    int n; cin >> n;
    string s, t; cin >> s >> t;
    set<char> ss, st; 
    int s_xor = 0, t_xor = 0;
    for (char c : s) {
        ss.insert(c);
        s_xor ^= conv(c);
    }
    for (char c : t) {
        st.insert(c);
        t_xor ^= conv(c);
    }

    if (ss.size() == 1 || st.size() == 1) {
        cout << "No" << '\n';
    }
    else {
        if (s_xor == t_xor) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    solve();

    return 0;
}
accuracy: 0.49056603773584906
time_ms: 20
memory_kb: 6320
final_rank: 19

code_snippet: #include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    int same1 = 1, same2 = 1;
    for (int i = 0; i+1 < n; ++i) {
        if(s[i] != s[i+1]) same1 = 0;
        if(t[i] != t[i+1]) same2 = 0;
    }
    array<int, 256> val{};
    val['B'] = 1, val['Y'] = 2; val['G'] = 3;
    if(same1 || same2){
        puts(s == t ? "Yes" : "No");
    }else {
        int k = 0;
        for (auto &&i : s) k ^= val[i];
        for (auto &&i : t) k ^= val[i];
        puts(k ? "No" : "Yes");
    }
    return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5584
final_rank: 1

code_snippet: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

bool has_one_color(string s) {
  sort(ALL(s));
  s.erase(unique(ALL(s)), s.end());
  return s.length() == 1;
}

int main() {
  int n; string s, t; cin >> n >> s >> t;
  if (has_one_color(s) || has_one_color(t)) {
    cout << (has_one_color(s) && has_one_color(t) && s[0] == t[0] ? "Yes\n" : "No\n");
    return 0;
  }
  map<char, int> mp{{'R', 0}, {'B', 1}, {'Y', 2}, {'G', 3}};
  int s_xor = 0, t_xor = 0;
  for (char c : s) s_xor ^= mp[c];
  for (char c : t) t_xor ^= mp[c];
  cout << (s_xor == t_xor ? "Yes\n" : "No\n");
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 7244
final_rank: 16

code_snippet: #include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;

vector<int> counter(string s) {
    vector<int> count(4, 0);
    map<int, int> mp;
    mp['R'] = 0;
    mp['G'] = 1;
    mp['B'] = 2;
    mp['Y'] = 3;
    for (char c : s) count[mp[c]]++;
    return count;
}

void shrink(vector<int>& count) {
    if (count[0] > 1) {
        if (count[1] == 0 && count[2] == 0) {
            assert(count[3] > 0);
            count[0]--;
            count[1]++;
            count[2]++;
            count[3]--;
        }
        if (count[1] > 0 || count[2] > 0) {
            while (count[0] > 1) {
                count[0] -= 2;
                count[3] += 2;
            }
        }
        else {
            assert(false);
        }
    }
    if (count[1] > 1) {
        if (count[0] == 0 && count[2] == 0) {
            assert(count[3] > 0);
            count[0]++;
            count[1]--;
            count[2]++;
            count[3]--;
        }
        if (count[0] > 0 || count[2] > 0) {
            while (count[1] > 1) {
                count[1] -= 2;
                count[3] += 2;
            }
        }
        else {
            assert(false);
        }
    }
    if (count[2] > 1) {
        if (count[0] == 0 && count[1] == 0) {
            assert(count[3] > 0);
            count[0]++;
            count[1]++;
            count[2]--;
            count[3]--;
        }
        if (count[0] > 0 || count[1] > 0) {
            while (count[2] > 1) {
                count[2] -= 2;
                count[3] += 2;
            }
        }
        else {
            assert(false);
        }
    }
    /*
    rep(i, 3) {
        int mov = (count[i] / 2) * 2;
        count[i] -= mov;
        count[3] += mov;
    }
    */
    if (count[0] == 1) {
        if (count[1] == 1) {
            count[0] = 0;
            count[1] = 0;
            count[2]++;
            count[3]++;
        }
        else if (count[2] == 1) {
            count[0] = 0;
            count[1]++;
            count[2] = 0;
            count[3]++;
        }
        else if (count[3] > 0) {
            count[0] = 0;
            count[1]++;
            count[2]++;
            count[3]--;
        }
    }
    assert(count[0] == 0);
    assert(0 <= count[1] && count[1] <= 2);
    assert(0 <= count[2] && count[2] <= 2);
}

bool little_case(string& S, string& T) {
    using namespace chrono;
    const int N = S.size();
    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> rndN(0, N - 2), rnd2(0, 1);

    auto start = system_clock::now();
    while (duration_cast<milliseconds>(system_clock::now() - start).count() < 1800) {
        if (S == T)return true;
        // swap対象の検索
        int tgtIdx = rndN(mt);
        if (S[tgtIdx] == S[tgtIdx + 1])continue;

        set<char> color = { 'R','G','B', 'Y' };
        REP(i, tgtIdx, tgtIdx + 2)color.erase(S[i]);
        bool rev = rnd2(mt);
        if (!rev) {
            auto itr = color.begin();
            S[tgtIdx] = *itr;
            ++itr;
            S[tgtIdx + 1] = *itr;
        }
        else {
            auto itr = color.begin();
            S[tgtIdx + 1] = *itr;
            ++itr;
            S[tgtIdx] = *itr;
        }
    }
    return false;
}


int main()
{
    int N;
    string S, T;
    cin >> N >> S >> T;
    {
        set<char> sts, stt;
        for (char c : S)sts.insert(c);
        for (char c : T)stt.insert(c);
        if (sts.size() == 1 || stt.size() == 1) {
            if (sts.size() == 1 && stt.size() == 1) {
                char s1 = *sts.begin();
                char s2 = *stt.begin();
                cout << (s1 == s2 ? "Yes" : "No") << endl;
            }
            else {
                cout << "No" << endl;
            }
            return 0;
        }
    }
    if (N <= 6) {
        cout << (little_case(S, T) ? "Yes" : "No") << endl;
        return 0;
    }
    auto countS = counter(S);
    auto countT = counter(T);
    shrink(countS);
    shrink(countT);
    cout << (countS == countT ? "Yes" : "No") << endl;
    return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 6996
final_rank: 13

code_snippet: #include "bits/stdc++.h"
using namespace std;
#define REP(k, m, n) for (int(k) = (m); (k) < (n); (k)++)
#define rep(i, n) REP((i), 0, (n))
using ll = long long;

vector<int> counter(string s) {
  vector<int> count(4, 0);
  map<int, int> mp;
  mp['R'] = 0;
  mp['G'] = 1;
  mp['B'] = 2;
  mp['Y'] = 3;
  for (char c : s) count[mp[c]]++;
  return count;
}

bool fail(vector<int>& v) {
  for (auto num : v)
    if (num < 0) return true;
  return false;
}

void shrink(vector<int>& count) {
  if (count[0] > 1) {
    if (count[1] == 0 && count[2] == 0) {
      assert(count[3] > 0);
      count[0]--;
      count[1]++;
      count[2]++;
      count[3]--;
    }
    if (count[1] > 0 || count[2] > 0) {
      while (count[0] > 1) {
        count[0] -= 2;
        count[3] += 2;
      }
    } else {
      assert(false);
    }
  }
  if (count[1] > 1) {
    if (count[0] == 0 && count[2] == 0) {
      assert(count[3] > 0);
      count[0]++;
      count[1]--;
      count[2]++;
      count[3]--;
    }
    if (count[0] > 0 || count[2] > 0) {
      while (count[1] > 1) {
        count[1] -= 2;
        count[3] += 2;
      }
    } else {
      assert(false);
    }
  }
  if (count[2] > 1) {
    if (count[0] == 0 && count[1] == 0) {
      assert(count[3] > 0);
      count[0]++;
      count[1]++;
      count[2]--;
      count[3]--;
    }
    if (count[0] > 0 || count[1] > 0) {
      while (count[2] > 1) {
        count[2] -= 2;
        count[3] += 2;
      }
    } else {
      assert(false);
    }
  }
}

bool little_case(string& S, string& T) {
  using namespace chrono;
  const int N = S.size();
  random_device rnd;
  mt19937 mt(rnd());
  uniform_int_distribution<> rndN(0, N - 2), rnd2(0, 1);

  auto start = system_clock::now();
  while (duration_cast<milliseconds>(system_clock::now() - start).count() <
         1800) {
    if (S == T) return true;
    // swap対象の検索
    int tgtIdx = rndN(mt);
    if (S[tgtIdx] == S[tgtIdx + 1]) continue;

    set<char> color = {'R', 'G', 'B', 'Y'};
    REP(i, tgtIdx, tgtIdx + 2) color.erase(S[i]);
    bool rev = rnd2(mt);
    if (!rev) {
      auto itr = color.begin();
      S[tgtIdx] = *itr;
      ++itr;
      S[tgtIdx + 1] = *itr;
    } else {
      auto itr = color.begin();
      S[tgtIdx + 1] = *itr;
      ++itr;
      S[tgtIdx] = *itr;
    }
  }
  return false;
}

string parse(vector<int> count) {
  string s = "";
  rep(i, count[0]) s += "R";
  rep(i, count[1]) s += "G";
  rep(i, count[2]) s += "B";
  for (int i = 0; i < count[3]; ++i) s += "Y";
  return s;
}

int main() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  {
    set<char> sts, stt;
    for (char c : S) sts.insert(c);
    for (char c : T) stt.insert(c);
    if (sts.size() == 1 || stt.size() == 1) {
      if (sts.size() == 1 && stt.size() == 1) {
        char s1 = *sts.begin();
        char s2 = *stt.begin();
        cout << (s1 == s2 ? "Yes" : "No") << endl;
      } else {
        cout << "No" << endl;
      }
      return 0;
    }
  }
  if (N <= 8) {
    cout << (little_case(S, T) ? "Yes" : "No") << endl;
    return 0;
  }
  auto countS = counter(S);
  auto countT = counter(T);
  shrink(countS);
  shrink(countT);
  {
    int now = min(countS[3], countT[3]);
    countS[3] -= now, countT[3] -= now;
  }
  S = parse(countS);
  T = parse(countT);
  assert(S.size() == T.size());

  cout << (little_case(S, T) ? "Yes" : "No") << endl;
  return 0;
}
accuracy: 1
time_ms: 1860
memory_kb: 6980
final_rank: 17

code_snippet: #include "bits/stdc++.h"
using namespace std;

int main() {
  int n;
  string s, t;
  cin >> n >> s >> t;
  {
    set<char> sts, stt;
    for (char c : s) sts.insert(c);
    for (char c : t) stt.insert(c);
    if (sts.size() == 1 || stt.size() == 1) {
      if (sts.size() == 1 && stt.size() == 1) {
        char s1 = *sts.begin();
        char s2 = *stt.begin();
        cout << (s1 == s2 ? "Yes" : "No") << endl;
      } else {
        cout << "No" << endl;
      }
      return 0;
    }
  }
  map<int, int> mp;
  mp['R'] = 0;
  mp['G'] = 1;
  mp['B'] = 2;
  mp['Y'] = 3;
  int res = 0;
  for (auto c : s) res ^= mp[c];
  for (auto c : t) res ^= mp[c];
  if (!res)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}
accuracy: 1
time_ms: 60
memory_kb: 6968
final_rank: 12