func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 300000 + 15;   int n;   int a[N];   char c[N];   int flag, st, bb, rr, ll, cc, dd, ee, hh;   int main() {     scanf( %d , &n);     for (int i(1); i <= (n); ++i) scanf( %d %c , a + i, c + i);     long long ans = 0;     for (int i(1); i <= (n); ++i)       if (c[i] ==  B ) {         if (!bb) bb = i;         dd = a[i] - a[ll] > dd ? a[i] - a[ll] : dd;         ll = i;       } else if (c[i] ==  R ) {         if (!rr) rr = i;         ee = a[i] - a[cc] > ee ? a[i] - a[cc] : ee;         cc = i;       } else {         if (flag) {           int tmp1 = a[i] - a[hh];           int tmp2 = (ee ? a[i] - a[hh] - max(a[i] - a[cc], ee) : 0) +                      (dd ? a[i] - a[hh] - max(a[i] - a[ll], dd) : 0);           ans += a[i] - a[hh] + min(tmp1, tmp2);         } else           ans += (bb ? a[i] - a[bb] : 0) + (rr ? a[i] - a[rr] : 0);         flag = 1;         hh = cc = ll = i;         ee = dd = 0;       }     if (!flag)       printf( %lld n , 0ll + a[cc] - a[rr] + a[ll] - a[bb]);     else       printf( %lld n ,              ans + (cc > hh ? a[cc] - a[hh] : 0) + (ll > hh ? a[ll] - a[hh] : 0));     return 0;   }   