#include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
  int h, m, n;
  scanf("%d %d %d", &h, &m, &n);
  static set<int> s[200005];
  vector<int> g(h, -1), seq(h);
  int num = 0;
  for (int i = 0; i < h; i++) {
    if (g[i] >= 0) continue;
    for (int j = i, o = 0; g[j] < 0; j = (j + m) % h, o++) {
      g[j] = num;
      seq[j] = o;
      s[num].insert(o);
    }
    num++;
  }
  int len = h / num;
  char str[32];
  long long ans = 0;
  map<int, pair<int, int> > c;
  for (int i = 0; i < n; i++) {
    int id, v;
    scanf("%s %d", str, &id);
    if (str[0] == '+') {
      scanf("%d", &v);
      int x = g[v], y = seq[v];
      set<int>::iterator it = s[x].lower_bound(y);
      if (it == s[x].end()) {
        it = s[x].begin();
        ans += *it + len - y;
      } else {
        ans += *it - y;
      }
      c[id] = make_pair(x, *it);
      s[x].erase(it);
    } else {
      pair<int, int> t = c[id];
      s[t.first].insert(t.second);
      c.erase(id);
    }
  }
  cout << ans << endl;
  return 0;
}
