func_code_string: #include <bits/stdc++.h>   using namespace std;   namespace fast_IO {   inline int read_int() {     register int ret = 0, f = 1;     register char c = getchar();     while (c <  0  || c >  9 ) {       if (c ==  - ) f = -1;       c = getchar();     }     while (c >=  0  && c <=  9 ) {       ret = (ret << 1) + (ret << 3) + int(c - 48);       c = getchar();     }     return ret * f;   }   }  // namespace fast_IO   using namespace fast_IO;   int N, Q;   int a[200005];   char s[200005];   struct BIT {     int c[200005];     inline int lowbit(int x) { return x & (-x); }     inline void add(int pos, int w) {       while (pos <= N) c[pos] += w, pos += lowbit(pos);     }     inline int query(int pos) {       int res = 0;       while (pos) res += c[pos], pos -= lowbit(pos);       return res;     }   } BIT[3];   set<int> S[3];   inline int decode(char c) {     if (c ==  R ) return 0;     if (c ==  P ) return 1;     if (c ==  S ) return 2;   }   inline void init() {     N = read_int(), Q = read_int();     scanf( %s , s + 1);     for (register int i = 0; i < 3; i++)       S[i].insert(-0x3f3f3f3f), S[i].insert(0x3f3f3f3f);     for (register int i = 1; i <= N; i++) {       a[i] = decode(s[i]);       BIT[a[i]].add(i, 1);       S[a[i]].insert(i);     }   }   inline int calc() {     if (S[0].size() == N + 2 || S[1].size() == N + 2 || S[2].size() == N + 2)       return N;     if (S[0].size() == 2) return S[2].size() - 2;     if (S[1].size() == 2) return S[0].size() - 2;     if (S[2].size() == 2) return S[1].size() - 2;     set<int>::iterator it_min[3], it_max[3];     for (register int i = 0; i < 3; i++) it_min[i] = S[i].begin(), it_min[i]++;     for (register int i = 0; i < 3; i++)       it_max[i] = S[i].end(), it_max[i]--, it_max[i]--;     int ans = N;     for (register int i = 0; i < 3; i++) {       int l1 = (i + 1) % 3, r1 = (i + 2) % 3;       int L = *it_min[l1], R = *it_min[r1] - 1;       ans -= max(0, BIT[i].query(R) - BIT[i].query(L - 1));       L = *it_max[r1], R = *it_max[l1];       ans -= max(0, BIT[i].query(R) - BIT[i].query(L - 1));     }     return ans;   }   inline void ans() {     printf( %d n , calc());     register int pos, nw;     static char opt[20];     while (Q--) {       pos = read_int();       scanf( %s , opt);       nw = decode(opt[0]);       S[a[pos]].erase(pos);       BIT[a[pos]].add(pos, -1);       a[pos] = nw, S[a[pos]].insert(pos), BIT[a[pos]].add(pos, 1);       printf( %d n , calc());     }   }   int main() {     init();     ans();     return 0;   }   