Source Code
#include <bits/stdc++.h>
using namespace std;
    
int main (){

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

	string s;
	cin >> s;
	int p = 0, o = 0, ans = 0;
	s.erase(s.begin());
	for (char &c : s) {
		if (c == 'N') {
			if (o && o >= 2 * p) {
				p = o;
				o = 0;
				++ans;
				c = 'R';
			}
			++o;
		}
		else {
			p = o;
			o = 0;
		}
	}
	cout << ans << "\nN" << s;

  return 0;
}
Copy
Never Gonna Give You Up SuhaibSawalha1
GNU G++17
4 ms
512 KB
Wrong Answer