#include <bits/stdc++.h>
using namespace std;
const int MAX_H = 200000;
const int MAX_E2 = 1 << 19;
const int MAX_N = 200000;
template <typename T, const int MAX_E2>
struct SegTreeMinMax {
  int n, e2;
  T mins[MAX_E2], maxs[MAX_E2];
  SegTreeMinMax() {}
  void init(int _n) {
    n = _n;
    for (e2 = 1; e2 < n; e2 <<= 1)
      ;
  }
  T &getmin(int i) { return mins[e2 - 1 + i]; }
  T &getmax(int i) { return maxs[e2 - 1 + i]; }
  void set(int i, T v) {
    int j = e2 - 1 + i;
    mins[j] = maxs[j] = v;
    while (j > 0) {
      j = (j - 1) / 2;
      int j0 = j * 2 + 1, j1 = j0 + 1;
      mins[j] = min<T>(mins[j0], mins[j1]);
      maxs[j] = max<T>(maxs[j0], maxs[j1]);
    }
  }
  void setall() {
    for (int j = e2 - 2; j >= 0; j--) {
      int j0 = j * 2 + 1, j1 = j0 + 1;
      mins[j] = min<T>(mins[j0], mins[j1]);
      maxs[j] = max<T>(maxs[j0], maxs[j1]);
    }
  }
  int index(int r0, int r1, int k, int i0, int i1) {
    if (r1 <= i0) return i0;
    if (i1 <= r0) return i1;
    if (r0 <= i0 && i1 <= r1) {
      if (maxs[k] == 0) return i0;
      if (mins[k] > 0) return i1;
    }
    int im = (i0 + i1) / 2;
    int x0 = index(r0, r1, k * 2 + 1, i0, im);
    if (x0 < im) return x0;
    int x1 = index(r0, r1, k * 2 + 2, im, i1);
    return x1;
  }
  int index(int r0, int r1) {
    int x = index(r0, r1, 0, 0, e2);
    return x;
  }
  void print() {
    for (int i = 0; i < n; i++) printf("%d ", getmin(i));
    putchar('\n');
  }
};
map<int, int> kmap;
int k2ps[MAX_H], p2ks[MAX_H];
SegTreeMinMax<int, MAX_E2> st;
template <typename T>
T gcd(T m, T n) {
  if (m < n) swap(m, n);
  while (n > 0) {
    T r = m % n;
    m = n;
    n = r;
  }
  return m;
}
int main() {
  int h, m, n;
  scanf("%d%d%d", &h, &m, &n);
  int g = gcd<int>(h, m);
  int hg = h / g;
  for (int i = 0, p = 0; i < g; i++) {
    for (int j = 0, k = i; j < hg; j++, k = (k + m) % h, p++) {
      k2ps[k] = p, p2ks[p] = k;
    }
  }
  st.init(h);
  long long sum = 0;
  while (n--) {
    char op[4];
    int id;
    scanf("%s%d", op, &id);
    if (op[0] == '+') {
      int key;
      scanf("%d", &key);
      int d = key % g;
      int l = hg * d, r = l + hg;
      int p = k2ps[key];
      int x = st.index(p, r);
      if (x >= r) {
        x = st.index(l, p);
        sum += (r - p) + (x - l);
      } else
        sum += x - p;
      int k = p2ks[x];
      kmap[id] = k;
      st.set(x, 1);
    } else {
      st.set(k2ps[kmap[id]], 0);
      kmap.erase(id);
    }
  }
  printf("%lld\n", sum);
  return 0;
}
