func_code_string: #include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   using vi = vector<int>;   using ll = long long;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     vi count(3);     enum { R, B, G };     map<char, int> val = {{ R , R}, { B , B}, { G , G}};     int n;     cin >> n;     vi p(n), c(n);     for (int i = int(0); i < int(n); i++) {       cin >> p[i];       char col;       cin >> col;       int v = val[col];       count[v]++;       c[i] = v;     }     int ans = 0;     if (!count[R] || !count[B])       ans = p[n - 1] - p[0];     else {       vi last(3, -1), mx(2, -1), sum(2);       for (int i = int(0); i < int(n); i++) {         int col = c[i];         if (col == G) {           if (last[G] != -1) {             ll cut = 0, distG = p[i] - p[last[G]];             for (int j = int(0); j < int(2); j++)               if (mx[j] != -1) {                 mx[j] = max(mx[j], p[i] - p[last[j]]);                 cut += distG - mx[j], mx[j] = -1;                 sum[j] = 0;               }             ans += int(min(2 * distG, distG + cut));           } else {             for (int j = int(0); j < int(2); j++)               if (last[j] != -1) ans += p[i] - p[last[j]];           }         } else {           if (last[G] != -1) {             int dist = p[i] - p[last[mx[col] == -1 ? G : col]];             mx[col] = max(mx[col], dist);             sum[col] += dist;           } else if (last[col] != -1)             ans += p[i] - p[last[col]];         }         last[col] = i;       }       ans += sum[R] + sum[B];     }     cout << ans <<   n ;     return 0;   }   