func_code_string: #include <bits/stdc++.h>   using namespace std;   long long n, q;   struct interv {     long long l, r, ubonus, lbonus;     interv(long long L, long long R, long long UBONUS, long long LBONUS) {       l = L;       r = R;       ubonus = UBONUS;       lbonus = LBONUS;     }     bool operator<(const interv& x) const { return r < x.r; }   };   set<interv> s;   set<interv>::iterator it;   long long x, y, to;   char dir[3];   long long ans;   int main() {     scanf( %lld %lld , &n, &q);     s.insert(interv(1, n, 0, 0));     for (int i = 1; i <= q; i++) {       scanf( %lld %lld , &x, &y);       scanf( %s , dir);       it = s.lower_bound(interv(0, x, 0, 0));       if (it == s.end()) {         printf( 0 n );         continue;       }       long long b = (*it).r;       long long a = (*it).l;       long long ubonus = (*it).ubonus;       long long lbonus = (*it).lbonus;       if (x < a) {         printf( 0 n );         continue;       }       if (dir[0] ==  U ) {         ans = (b - a + 1) - (x - a) + ubonus;         printf( %lld n , ans);         s.erase(it);         if (x - 1 >= 1 && a <= x - 1) s.insert(interv(a, x - 1, ans, lbonus));         if (x + 1 <= n && x + 1 <= b) s.insert(interv(x + 1, b, ubonus, 0));       } else {         ans = (b - a + 1) - (b - x) + lbonus;         printf( %lld n , ans);         s.erase(it);         if (x - 1 >= 1 && a <= x - 1) s.insert(interv(a, x - 1, 0, lbonus));         if (x + 1 <= n && x + 1 <= b) s.insert(interv(x + 1, b, ubonus, ans));       }     }     return 0;   }   