#include <bits/stdc++.h>
using namespace std;
long long ans;
int h, m, n, cnt, idx[200005], pos[200005], l[200005];
set<int> u[200005];
map<int, pair<int, int> > e;
int main() {
  scanf("%d%d%d", &h, &m, &n);
  for (int i = 0; i < h; i++)
    if (!idx[i]) {
      idx[i] = ++cnt;
      u[cnt].insert(0);
      l[cnt] = 1;
      for (int x = (i + m) % h; x != i; x = (x + m) % h) {
        idx[x] = idx[i];
        pos[x] = u[cnt].size();
        u[cnt].insert(pos[x]);
        l[cnt]++;
      }
    }
  for (int v, x, i = 0; i < n; i++) {
    char o[100];
    scanf("%s", o);
    if (*o == '+') {
      scanf("%d%d", &v, &x);
      int c = idx[x], r = pos[x];
      auto t = *u[c].rbegin() < r ? u[c].begin() : u[c].lower_bound(r);
      ans += (*t - r + l[c]) % l[c];
      e[v] = {*t, c};
      u[c].erase(t);
    } else {
      scanf("%d", &v);
      u[e[v].second].insert(e[v].first);
    }
  }
  printf("%I64d\n", ans);
}
