#include <bits/stdc++.h>   using namespace std;   long long labs(long long a) { return a < 0 ? (-a) : a; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   struct Fenwik {     vector<long long> t;     long long n;     void Init(long long nn) {       n = nn;       t.assign(n, 0);     }     long long Sum(long long r) {       long long result = 0;       for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r];       return result;     }     void Inc(long long i, long long delta) {       for (; i < n; i = (i | (i + 1))) t[i] += delta;     }     long long Sum(long long l, long long r) { return Sum(r) - Sum(l - 1); }     void Init(const vector<long long>& a) {       Init(a.size());       for (int(i) = 0; (i) < (n); (i)++) Inc(i, a[i]);     }   };   vector<Fenwik> f;   vector<int> g;   vector<int> gn;   long long gs;   map<long long, pair<int, int> > ids;   long long h, m, n;   long long gt;   long long F(long long x) {     long long pos = (gn[gt] + x) % gs;     long long sum = 0;     if (pos < gn[gt]) {       sum = f[g[gt]].Sum(gn[gt], gs - 1) + f[g[gt]].Sum(0, pos);     } else {       sum = f[g[gt]].Sum(gn[gt], pos);     }     return x + 1 - sum;   }   long long UpperBound(long long l, long long r, long long f) {     while (l < r) {       long long m = (l + r) / 2;       if (!(f < F(m))) {         l = m + 1;       } else {         r = m;       }     }     return l;   }   long long res = 0;   void Add(long long id, long long t) {     gt = t;     long long lb = UpperBound(0, gs - 1, 0);     res += lb;     long long gg = g[t];     long long nn = (gn[t] + lb) % gs;     f[gg].Inc(nn, 1);     ids[id] = make_pair(gg, nn);   }   void Delete(long long id) { f[ids[id].first].Inc(ids[id].second, -1); }   int main() {     cin >> h >> m >> n;     g.resize(h, -1);     gn.resize(h, 0);     long long group = 0;     for (int(i) = 0; (i) < (h); (i)++) {       if (g[i] != -1) continue;       g[i] = group;       gs = 1;       for (long long j = 1; (i + j * m) % h != i; j++) {         g[(i + j * m) % h] = group;         gn[(i + j * m) % h] = j;         gs = j + 1;       }       group++;     }     f.resize(group);     for (int(i) = 0; (i) < (group); (i)++) {       f[i].Init(gs);     }     char c;     long long id;     long long t;     for (int(i) = 0; (i) < (n); (i)++) {       cin >> c >> id;       if (c ==  + ) {         cin >> t;         Add(id, t);       } else {         Delete(id);       }     }     cout << res << endl;     return 0;   }   