func_code_string: #include <bits/stdc++.h>   using namespace std;   int main() {     int n;     scanf( %d , &n);     pair<int, char> p[200005];     for (int i = 0; i < n; i++) {       scanf( %d %c , &p[i].first, &p[i].second);     }     sort(p, p + n);     int minred = 1e9 + 1, maxred = 1e9 + 1;     int mingreen = 1e9 + 1, maxgreen = 1e9 + 1;     for (int i = 0; i < n; i++) {       if (p[i].second ==  R ) {         maxred = p[i].first;         minred = min(minred, p[i].first);       } else if (p[i].second ==  B ) {         maxgreen = p[i].first;         mingreen = min(mingreen, p[i].first);       } else {         maxred = p[i].first;         minred = min(minred, p[i].first);         maxgreen = p[i].first;         mingreen = min(mingreen, p[i].first);       }     }     long long ans = (long long)maxred - minred + maxgreen - mingreen;     int lastp = -1;     for (int i = 0; i < n; i++) {       if (p[i].second ==  P ) {         if (lastp != -1) {           int lastr = p[lastp].first;           int lastg = p[lastp].first;           int maxr = 0, maxg = 0;           for (int j = lastp + 1; j < i; j++) {             if (p[j].second ==  R ) {               maxr = max(p[j].first - lastr, maxr);               lastr = p[j].first;             } else {               maxg = max(p[j].first - lastg, maxg);               lastg = p[j].first;             }           }           maxr = max(p[i].first - lastr, maxr);           maxg = max(p[i].first - lastg, maxg);           ans -= max(0, maxr + maxg - (p[i].first - p[lastp].first));         }         lastp = i;       }     }     printf( %lld n , ans);   }   