#include <bits/stdc++.h>
using namespace std;
map<int, int> id;
map<int, int> q[51000];
long long ans;
int i, j, k, l, n, m, h, be[250000], X[250000], Y[250000], num, pos[250000], M,
    x, y;
char ch[10];
int main() {
  scanf("%d%d%d", &h, &m, &n);
  for (int i = 0; i < h; ++i)
    if (!be[i]) {
      int j = i;
      num = 0;
      ++M;
      while (!be[j]) {
        num++;
        be[j] = M;
        pos[j] = num;
        j = (j + m) % h;
        q[M][num] = 1;
      }
    }
  for (int i = 1; i <= n; ++i) {
    scanf("%s", ch);
    if (ch[0] == '+') {
      scanf("%d%d", &x, &y);
      int res, tmp;
      map<int, int>::iterator it = q[be[y]].lower_bound(pos[y]);
      if (it == q[be[y]].end()) it = q[be[y]].lower_bound(0);
      tmp = it->first;
      if (tmp < pos[y])
        res = num - pos[y] + tmp;
      else
        res = tmp - pos[y];
      ans += res;
      id[x] = i;
      q[be[y]].erase(it);
      X[i] = be[y];
      Y[i] = tmp;
    } else {
      scanf("%d", &x);
      y = id[x];
      q[X[y]][Y[y]] = 1;
    }
  }
  printf("%I64d\n", ans);
}
