#include <bits/stdc++.h>
using namespace std;
const int N = 202020;
int h, m, n, L;
int num[N], id[N], l[N], r[N];
bool vis[N];
map<int, int> pos;
struct Seg {
  static const int N = ::N << 2;
  int cnt[N];
  void upd(int p, int c, int l, int r, int rt) {
    cnt[rt] += c;
    if (l == r) return;
    int mid = l + r >> 1;
    if (p <= mid)
      upd(p, c, l, mid, rt << 1);
    else
      upd(p, c, mid + 1, r, rt << 1 | 1);
  }
  int qry(int L, int R, int l, int r, int rt) {
    if (L <= l && r <= R && (l == r || cnt[rt] == r - l + 1)) {
      if (cnt[rt] == r - l + 1) return 0;
      return l;
    }
    int mid = l + r >> 1;
    if (L <= mid) {
      int t = qry(L, R, l, mid, rt << 1);
      if (t) return t;
    }
    if (R > mid) {
      int t = qry(L, R, mid + 1, r, rt << 1 | 1);
      if (t) return t;
    }
    return 0;
  }
} seg;
int main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  cin >> h >> m >> n;
  for (int i = (0); i < (h); ++i)
    if (!vis[i]) {
      int st = L + 1;
      for (int j = i; !vis[j]; (j += m) %= h)
        num[j] = ++L, id[L] = j, vis[j] = 1;
      for (int j = i; !l[j]; (j += m) %= h) l[j] = st, r[j] = L;
    }
  long long ans = 0;
  for (int i = (0); i < (n); ++i) {
    string o;
    int c, p;
    cin >> o >> c;
    if (o[0] == '+') {
      cin >> p;
      int t = seg.qry(num[p], r[p], 1, h, 1);
      if (t)
        ans += t - num[p];
      else
        t = seg.qry(l[p], num[p] - 1, 1, h, 1),
        ans += r[p] - num[p] + t - l[p] + 1;
      seg.upd(pos[c] = t, 1, 1, h, 1);
    } else {
      seg.upd(pos[c], -1, 1, h, 1);
      pos[c] = 0;
    }
  }
  cout << ans << "\n";
  return 0;
}
