#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long tot;
struct SegT {
  int nn;
  vector<long long> t;
  SegT() {}
  SegT(int n) {
    nn = n;
    t.resize(4 * n);
  }
  void build(int id, int l, int r) {
    if (l == r) {
      t[id] = l;
      return;
    }
    build(id << 1, l, ((l + r) >> 1));
    build(id << 1 | 1, ((l + r) >> 1) + 1, r);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
  }
  void update(int id, int l, int r, int pos) {
    if (pos > r || pos < l) return;
    if (l == r) {
      t[id] = (t[id] == nn ? l : nn);
      return;
    }
    update(id << 1, l, ((l + r) >> 1), pos);
    update(id << 1 | 1, ((l + r) >> 1) + 1, r, pos);
    t[id] = min(t[id << 1], t[id << 1 | 1]);
  }
  int query(int id, int l, int r, int lq, int rq) {
    if (lq > r || l > rq)
      return nn;
    else if (lq <= l && r <= rq)
      return t[id];
    return min(query(id << 1, l, ((l + r) >> 1), lq, rq),
               query(id << 1 | 1, ((l + r) >> 1) + 1, r, lq, rq));
  }
  int work(int ll) {
    int xx = query(1, 0, nn - 1, ll, nn - 1);
    if (xx == nn) {
      xx = query(1, 0, nn - 1, 0, nn - 1);
    }
    update(1, 0, nn - 1, xx);
    if (xx >= ll)
      tot += xx - ll;
    else
      tot += nn - (ll - xx);
    return xx;
  }
};
int h, m, n;
int cc = 0;
int cnt[200200];
int root[200200];
int ssz[200200];
vector<SegT> sg;
map<int, pair<int, int> > sid;
void ins(int id, int hash) {
  int comp = root[hash];
  int ll = cnt[hash];
  int ab = sg[comp].work(ll);
  sid[id] = make_pair(comp, ab);
}
void del(int id) {
  pair<int, int> tt = sid[id];
  sid.erase(id);
  sg[tt.first].update(1, 0, sg[tt.first].nn - 1, tt.second);
}
void pr(string s, int x) { cout << s << ":" << x << "\n"; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> h >> m >> n;
  memset(root, -1, sizeof(root));
  for (int i = 0; i < h; i++) {
    if (root[i] == -1) {
      int rr = i;
      int mm = 0;
      while (root[rr] == -1) {
        root[rr] = cc;
        cnt[rr] = mm;
        mm++;
        rr = (rr + m) % h;
      }
      ssz[cc] = mm;
      cc++;
    }
  }
  sg.resize(cc);
  for (int i = 0; i < cc; i++) {
    sg[i] = SegT(ssz[i]);
    sg[i].build(1, 0, ssz[i] - 1);
  }
  for (int i = 0; i < n; i++) {
    char ch;
    cin >> ch;
    if (ch == '+') {
      int id, hash;
      cin >> id >> hash;
      ins(id, hash);
    } else {
      int id;
      cin >> id;
      del(id);
    }
  }
  cout << tot << "\n";
}
