func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long;   template <typename T>   using PQ = priority_queue<T>;   template <typename T>   using GPQ = priority_queue<T, vector<T>, greater<T>>;   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> p);   template <class T>   ostream& operator<<(ostream& os, vector<T> v) {     os <<  [ ;     for (auto vv : v) os << vv <<  , ;     return os <<  ] ;   }   template <class T>   ostream& operator<<(ostream& os, set<T> v) {     os <<  [ ;     for (auto vv : v) os << vv <<  , ;     return os <<  ] ;   }   template <class L, class R>   ostream& operator<<(ostream& os, pair<L, R> p) {     return os <<  (  << p.first <<  ,  << p.second <<  ) ;   }   template <typename T>   inline T sq(T a) {     return a * a;   }   template <typename T>   T gcd(T a, T b) {     if (a > b) return gcd(b, a);     return a == 0 ? b : gcd(b % a, a);   }   template <typename T, typename U>   T mypow(T b, U n) {     if (n == 0) return 1;     if (n == 1) return b;     if (n % 2 == 0) {       return mypow(b * b, n / 2);     } else {       return mypow(b, n - 1) * b;     }   }   ll pcnt(ll b) { return __builtin_popcountll(b); }   template <typename T>   T iceil(T n, T d) {     return (n + d - 1) / d;   }   map<char, int> hand = {{ R , 0}, { S , 1}, { P , 2}};   class BIT {    public:     explicit BIT(int N, int v) : V_NUM(N) {       data.resize(N);       fill(data.begin(), data.end(), v);     }     ll query(int i) {       ll ret = 0;       while (i > 0) {         ret += data[i];         i -= (i & -i);       }       return ret;     }     void update(int i, int v) {       while (i < V_NUM) {         data[i] += v;         i += (i & -i);       }     }     int_fast32_t V_NUM;     vector<int> data;   };   int main() {     int N, Q;     string S;     cin >> N >> Q >> S;     S =  $  + S;     vector<BIT> bit(3, BIT(N + 1, 0));     vector<set<int>> pos(3);     for (int i = 1; i <= N; ++i) {       bit[hand[S[i]]].update(i, 1);       pos[hand[S[i]]].insert(i);     }     for (int q = 0; q <= Q; ++q) {       int lose = 0;       int emp = 0;       for (int h = 0; h < 3; ++h) {         if (pos[h].empty()) ++emp;       }       if (emp == 1) {         for (int h = 0; h < 3; ++h) {           if (pos[h].empty() || pos[(h + 1) % 3].empty()) continue;           lose = pos[(h + 1) % 3].size();         }       } else if (emp == 0) {         for (int h = 0; h < 3; ++h) {           int w = (h + 1) % 3, l = (h + 2) % 3;           int wpos = *(pos[w].begin()), lpos = *(pos[l].begin());           lose += max(0LL, bit[h].query(wpos) - bit[h].query(lpos));           wpos = *(--pos[w].end()), lpos = *(--pos[l].end());           lose += max(0LL, bit[h].query(lpos) - bit[h].query(wpos));         }       }       cout << N - lose <<   n ;       if (q == Q) break;       int p;       char c;       cin >> p >> c;       bit[hand[S[p]]].update(p, -1);       pos[hand[S[p]]].erase(p);       bit[hand[c]].update(p, 1);       pos[hand[c]].insert(p);       S[p] = c;     }     return 0;   }   