func_code_string: #include <bits/stdc++.h>   using namespace std;   using LL = long long;   using VI = vector<int>;   const int inf = 2e9;   LL calc(set<int>& st, int L, int R) {     VI a;     for (int i = L;;) {       a.push_back(i);       if (i == R) break;       if (st.upper_bound(i) != st.end() && *st.upper_bound(i) < R)         i = *st.upper_bound(i);       else         i = R;     }     int ans = 0;     for (int i = 0; i + 1 < a.size(); i++) ans = max(ans, a[i + 1] - a[i]);     return ans;   }   int main() {     int n;     cin >> n;     set<int> a, b, c;     for (int i = 0; i < n; i++) {       int x;       char ch;       scanf( %d %c , &x, &ch);       if (ch ==  B ) a.insert(x);       if (ch ==  R ) b.insert(x);       if (ch ==  P ) c.insert(x);     }     int B = 0, R = 0;     int mn = inf, mx = -inf;     if (a.size()) mn = min(mn, *a.begin()), mx = max(mx, *--a.end());     if (c.size()) mn = min(mn, *c.begin()), mx = max(mx, *--c.end());     if (mn != inf) B = mx - mn;     mn = inf, mx = -inf;     if (b.size()) mn = min(mn, *b.begin()), mx = max(mx, *--b.end());     if (c.size()) mn = min(mn, *c.begin()), mx = max(mx, *--c.end());     if (mn != inf) R = mx - mn;     LL ans = (LL)B + R;     if (!B || !R || c.empty()) {       cout << ans << endl;       return 0;     }     for (auto i = c.begin(); ++i != c.end(); i++) {       auto j = i;       i--;       LL g = (*j - *i) - calc(a, *i, *j) - calc(b, *i, *j);       if (g < 0) ans += g;     }     cout << ans << endl;     return 0;   }   