#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
class fenvic {
 public:
  vector<int> second;
  int n;
  void init(int sz) {
    second.assign(sz + 3, 0);
    n = sz;
  }
  void upd(int v, int x) {
    while (v <= n) {
      second[v] += x;
      v = v | (v + 1);
    }
  }
  int sum(int v) {
    int ret = 0;
    while (v >= 0) {
      ret += second[v];
      v = (v & (v + 1)) - 1;
    }
    return ret;
  }
  int get(int l, int r) {
    if (l <= r) return sum(r) - sum(l - 1);
    return sum(n - 1) - sum(l - 1) + sum(r);
  }
};
map<int, int> pt;
int h, m, n, cls[N], cnt, sz[N], num[N];
fenvic first[N];
long long ans;
int add(int index) {
  int l = -1, r = sz[cls[index]], mid;
  while (l < r - 1) {
    mid = (l + r) / 2;
    if (first[cls[index]].get(num[index],
                              (num[index] + mid) % sz[cls[index]]) == mid + 1)
      l = mid;
    else
      r = mid;
  }
  first[cls[index]].upd((num[index] + r) % sz[cls[index]], 1);
  return r;
}
void del(int index) { first[cls[index]].upd(num[index], -1); }
int main() {
  int id, t;
  char c;
  cin >> h >> m >> n;
  for (int i = 0; i < h; i++)
    if (cls[i] == 0) {
      ++cnt;
      cls[i] = cnt;
      num[i] = 0;
      sz[cnt] = 1;
      int now = (i + m) % h;
      while (now != i) {
        cls[now] = cnt;
        num[now] = sz[cnt];
        sz[cnt]++;
        now = (now + m) % h;
      }
    }
  for (int i = 1; i <= cnt; i++) first[i].init(sz[i]);
  int index;
  for (int i = 0; i < n; i++) {
    cin >> c;
    if (c == '-') {
      scanf("%d", &id);
      del(pt[id]);
    } else {
      scanf("%d%d", &id, &t);
      int v = add(t);
      pt[id] = (t + 1LL * v * m) % h;
      ans += v;
    }
  }
  cout << ans;
  return 0;
}
