Problem:
Score : 400 points

Problem Statement

An altar enshrines N stones arranged in a row from left to right. The color of the i-th stone from the left (1 \leq i \leq N) is given to you as a character c_i; R stands for red and W stands for white.

You can do the following two kinds of operations any number of times in any order:

Choose two stones (not necessarily adjacent) and swap them.

Choose one stone and change its color (from red to white and vice versa).

According to a fortune-teller, a white stone placed to the immediate left of a red stone will bring a disaster. At least how many operations are needed to reach a situation without such a white stone?

Constraints

2 \leq N \leq 200000

c_i is R or W.

Input

Input is given from Standard Input in the following format:

N
c_{1}c_{2}...c_{N}

Output

Print an integer representing the minimum number of operations needed.

Sample Input 1

4
WWRR

Sample Output 1

2

For example, the two operations below will achieve the objective.

Swap the 1-st and 3-rd stones from the left, resulting in RWWR.

Change the color of the 4-th stone from the left, resulting in RWWW.

Sample Input 2

2
RR

Sample Output 2

0

It can be the case that no operation is needed.

Sample Input 3

8
WRWWRWRR

Sample Output 3

3

Solution in C++ (GCC 9.2.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}

int count1(string x){
  //string s = to_string(x);
  int cnt = 0;
  rep (i,x.size()){
    if (x[i]=='1') cnt++;
  }
  return cnt;
}



  








int main() {
  ll n,cnt = 0;
  cin >> n;
  string s;
  cin >> s;
  bool ok = false;
  ll t;
  int j;
  rep (i,s.size()){
    if (!ok && s[i]=='W'){
      cnt++;
    }
    if (s[i]=='R' && !ok){
      ok = true;
      t = cnt;
      j = i;
      break;
    }
    
    
  }
  //cout << j <<endl;
  
if (t == 0){
  for (int i = s.size()-1;i > j;i--){
    if (s[i]=='R' && s[i-1]=='R') continue;
    if (s[i]=='R') cnt++;
  }
} 
else{
  for (int i = s.size()-1;i > j;i--){
    //cout << s[i] << endl;
    if (s[i]=='R' && t > 0){
      t--;
      //cout << t << endl;
      continue;
    }
    if (s[i]=='R' && t <= 0) {
      cnt++;
      //cout << cnt << endl;
    }
  }
}
  
  
  cout << cnt << endl;

}