#include <bits/stdc++.h>
using namespace std;
const int MAXH = 1 << 18;
int H, M, N;
map<int, int> idPos;
map<int, int> idHash;
long long ans;
set<pair<int, int> > vals[MAXH];
bool mark[MAXH];
int fromSet[MAXH];
int fromPos[MAXH];
int startSize[MAXH];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> H >> M >> N;
  for (int i = 0; i < (int)(M); ++i)
    if (!mark[i]) {
      int cnt = 0;
      for (int j = i; !mark[j]; j = (j + M) % H) {
        mark[j] = true;
        fromSet[j] = i;
        fromPos[j] = cnt;
        vals[i].insert(make_pair(cnt, j));
        cnt++;
      }
      startSize[i] = ((int)(vals[i]).size());
    }
  for (int i = 0; i < (int)(N); ++i) {
    char op;
    cin >> op;
    if (op == '+') {
      int id, hash;
      cin >> id >> hash;
      int bck = fromSet[hash];
      int pos = fromPos[hash];
      set<pair<int, int> >::iterator it =
          vals[bck].lower_bound(make_pair(pos, hash));
      if (it != vals[bck].end()) {
        ans += it->first - pos;
        idPos[id] = it->first;
        idHash[id] = it->second;
        vals[bck].erase(it);
      } else {
        ans += startSize[bck] - pos;
        it = vals[bck].begin();
        ans += it->first;
        idPos[id] = it->first;
        idHash[id] = it->second;
        vals[bck].erase(it);
      }
    } else {
      int id;
      cin >> id;
      int pos = idPos[id];
      int hash = idHash[id];
      int bck = fromSet[hash];
      vals[bck].insert(make_pair(pos, hash));
    }
  }
  cout << ans << endl;
  return 0;
}
