#include <bits/stdc++.h>
using namespace std;
const int MaxH = 210000, MaxM = 210000, MaxSize = MaxH * 4;
int h, m, n;
int Left[MaxSize], Right[MaxSize], s[MaxSize], Total, Father[MaxSize],
    L[MaxSize], R[MaxSize], Root[MaxM];
map<int, int> Pos;
long long Ans;
vector<int> a[MaxH];
bool Flag[MaxH];
pair<int, int> Tar[MaxH];
void Build(int &t, const int l, const int r, const int f) {
  Father[t = ++Total] = f;
  L[t] = l, R[t] = r;
  if (l == r) return;
  const int mid = l + r >> 1;
  Build(Left[t], l, mid, t);
  Build(Right[t], mid + 1, r, t);
}
void Init() {
  scanf("%d%d%d", &h, &m, &n);
  for (int i = 0; i < h; ++i)
    if (!Flag[i]) {
      Flag[i] = 1;
      a[++Total].push_back(i);
      Tar[i] = make_pair(Total, 0);
      for (int j = (i + m) % h; j != i; j = (j + m) % h) {
        Tar[j] = make_pair(Total, a[Total].size());
        Flag[j] = 1;
        a[Total].push_back(j);
      }
      Build(Root[Total], 0, a[Total].size() - 1, 0);
    }
}
inline void Modify(int t, const int k) {
  for (; t; t = Father[t]) s[t] += k;
}
int Get(int t, const int x) {
  for (int mid; L[t] != R[t];) {
    mid = L[t] + R[t] >> 1;
    t = x <= mid ? Left[t] : Right[t];
  }
  return t;
}
int Find(int t) {
  int l, r, mid, p = 0, Count = 0, S = L[t], Res = S;
  while (t) {
    l = L[t], r = R[t];
    if (p && Right[t] == p) Count -= s[Left[t]];
    if (s[t] + Count == r - S + 1) {
      Res = r;
      t = Father[p = t];
    } else
      break;
  }
  Count += s[t];
  while (Left[t]) {
    l = L[t], r = R[t], mid = l + r >> 1;
    if (Count - s[Right[t]] == mid - S + 1) {
      Res = mid;
      t = Right[t];
    } else {
      Count -= s[Right[t]];
      t = Left[t];
    }
  }
  return Res;
}
int Add(const int x) {
  int i = Get(Root[Tar[x].first], Tar[x].second);
  if (s[i]) {
    Ans -= L[i] - 1;
    i = Get(Root[Tar[x].first], Find(i));
    Ans += L[i];
    if (L[i] == R[Root[Tar[x].first]]) {
      i = Get(Root[Tar[x].first], 0);
      if (s[i]) {
        i = Get(Root[Tar[x].first], Find(i));
        Ans += L[i] + 1;
        i = Get(Root[Tar[x].first], L[i] + 1);
      }
    } else
      i = Get(Root[Tar[x].first], L[i] + 1);
  }
  Modify(i, 1);
  return i;
}
int main() {
  Init();
  char cmd[10];
  for (int x, y; n; --n) {
    scanf("%s%d", cmd, &x);
    if (cmd[0] == '+') {
      scanf("%d", &y);
      Pos[x] = Add(y);
    } else
      Modify(Pos[x], -1);
  }
  cout << Ans << endl;
  return 0;
}
