#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
bool z[200001];
int k[800001];
int id[200001];
map<int, int> M;
int L[200002], R[200002];
int f[800001];
void build(int v, int l, int r) {
  k[v] = 0;
  f[v] = l;
  if (l == r) return;
  int t = (l + r) >> 1;
  build(2 * v, l, t);
  build(2 * v + 1, t + 1, r);
  return;
}
void upd(int v, int l, int r, int w) {
  --k[v];
  if (l == r) {
    f[v] = r;
    return;
  }
  int t = ((l + r) >> 1);
  if (w <= t)
    upd(2 * v, l, t, w);
  else
    upd(2 * v + 1, t + 1, r, w);
  if (f[2 * v] != -1)
    f[v] = f[2 * v];
  else
    f[v] = f[2 * v + 1];
}
void upd_p(int v, int l, int r, int w) {
  ++k[v];
  if (l == r) {
    f[v] = -1;
    return;
  }
  int t = ((l + r) >> 1);
  if (w <= t)
    upd_p(2 * v, l, t, w);
  else
    upd_p(2 * v + 1, t + 1, r, w);
  if (f[2 * v] != -1)
    f[v] = f[2 * v];
  else
    f[v] = f[2 * v + 1];
}
int sum(int v, int l, int r, int k1, int k2) {
  if (l == k1 && r == k2) return k[v];
  int t = ((l + r) >> 1);
  if (k1 > t)
    return sum(2 * v + 1, t + 1, r, k1, k2);
  else if (k2 <= t)
    return sum(2 * v, l, t, k1, k2);
  else
    return sum(2 * v, l, t, k1, t) + sum(2 * v + 1, t + 1, r, t + 1, k2);
}
int F(int v, int l, int r, int t) {
  if (l == r) {
    if (k[v] == 0) return r;
    return -1;
  }
  int m = ((l + r) >> 1);
  if (t > m) return F(2 * v + 1, m + 1, r, t);
  int vv = F(2 * v, l, m, t);
  if (vv == -1) vv = f[2 * v + 1];
  return vv;
}
int main() {
  int h, m, n;
  scanf("%d %d %d\n", &h, &m, &n);
  memset(z, true, sizeof(z));
  int nn = 0;
  for (int i = 0; i <= h - 1; ++i)
    if (z[i]) {
      int j = i;
      int ll = nn + 1, rr;
      for (;;) {
        if (!z[j]) break;
        id[j] = ++nn;
        z[j] = false;
        j = (j + m) % h;
      }
      rr = nn;
      for (int j = ll; j <= rr; ++j) {
        L[j] = ll;
        R[j] = rr;
      }
    }
  build(1, 1, nn);
  long long ANS = 0;
  for (int i = 1; i <= n; ++i) {
    char c;
    scanf("%c ", &c);
    if (c == '-') {
      int x;
      scanf("%d\n", &x);
      upd(1, 1, nn, M[x]);
      M[x] = 0;
    } else {
      int x, y;
      scanf("%d %d\n", &x, &y);
      y = id[y];
      int v, ans;
      if (sum(1, 1, nn, y, R[y]) != R[y] - y + 1)
        v = F(1, 1, nn, y);
      else
        v = F(1, 1, nn, L[y]);
      M[x] = v;
      upd_p(1, 1, nn, v);
      if (v >= y)
        ans = v - y;
      else
        ans = R[y] - y + 1 + (v - L[y]);
      M[x] = v;
      ANS += ans;
    }
  }
  cout << ANS << endl;
  return 0;
}
