#include <bits/stdc++.h>
using namespace std;
const int MAXH = 1 << 18;
int H, M, N;
set<int> freePos[MAXH];
map<int, int> idPos;
long long ans;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> H >> M >> N;
  for (int i = 0; i < (int)(H); ++i) freePos[i % M].insert(i);
  for (int i = 0; i < (int)(N); ++i) {
    char op;
    cin >> op;
    if (op == '+') {
      int id, hash;
      cin >> id >> hash;
      set<int>::iterator it = freePos[hash % M].lower_bound(hash);
      if (it != freePos[hash % M].end()) {
        ans += (*it - hash) / M;
        idPos[id] = *it;
        freePos[hash % M].erase(it);
      } else {
        int t = hash;
        while (1) {
          int mul = (H - t + (M - 1)) / M;
          int nextT = t + mul * M;
          ans += (nextT - t) / M;
          t = nextT - H;
          set<int>::iterator it = freePos[t].begin();
          if (it != freePos[t].end()) {
            ans += (*it - t) / M;
            idPos[id] = *it;
            freePos[t].erase(it);
            break;
          }
        }
      }
    } else if (op == '-') {
      int id;
      cin >> id;
      int p = idPos[id];
      freePos[p % M].insert(p);
    }
  }
  cout << ans << endl;
  return 0;
}
