#include <bits/stdc++.h>
struct Node {
  Node(int v = 1, int pos = 1e9) { min = (v == 1 ? int(1e9) : pos); }
  Node(Node l, Node r) { min = std::min(l.min, r.min); }
  int min;
};
template <class i_t, class e_t>
class SegmentTree {
 public:
  void init(std::vector<e_t> base) {
    n = base.size();
    tree.resize(2 * n);
    for (int i = 0; i < n; i++) {
      tree[i + n] = i_t(base[i], i);
    }
    for (int i = n - 1; i > 0; i--) {
      tree[i] = i_t(tree[i + i], tree[i + i + 1]);
    }
  }
  i_t qry(int l, int r) {
    i_t lp, rp;
    for (l += n, r += n; l < r; l /= 2, r /= 2) {
      if (l & 1) lp = i_t(lp, tree[l++]);
      if (r & 1) rp = i_t(tree[--r], rp);
    }
    return i_t(lp, rp);
  }
  void upd(int x, e_t v) {
    x += n;
    tree[x] = i_t(v, x - n);
    build(x);
  }

 private:
  int n;
  std::vector<i_t> tree;
  void build(int x) {
    for (x /= 2; x > 0; x /= 2) {
      tree[x] = i_t(tree[x + x + 1], tree[x + x]);
    }
  }
};
struct Bucket {
  int n;
  SegmentTree<Node, int> tree;
  void init(int n) {
    this->n = n;
    tree.init(std::vector<int>(n, 0));
  }
  void erase(int pos) { tree.upd(pos, 0); }
  int insert(int pos) {
    int x = tree.qry(pos, n).min;
    int ans = 0;
    if (x >= n) {
      x = tree.qry(0, pos).min;
      ans += n - pos + x;
    } else {
      ans += x - pos;
    }
    tree.upd(x, 1);
    return ans;
  }
};
int main() {
  int h, m, n;
  std::cin >> h >> m >> n;
  int size = 1;
  for (int i = 2; i <= h; i++) {
    if (h % i == 0 && m % i == 0) {
      size = i;
    }
  }
  std::vector<Bucket> buckets(size);
  std::vector<int> hashBucket(h, 0);
  std::vector<int> posBucket(h, 0);
  std::map<int, std::pair<int, int> > idBucket;
  for (int i = 0; i < size; i++) {
    for (int j = 0, pos = i; j < h / size; j++, pos = (pos + m) % h) {
      posBucket[pos] = j;
      hashBucket[pos] = i;
    }
    buckets[i].init(h / size);
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    char t;
    int id;
    scanf(" %c %d", &t, &id);
    if (t == '+') {
      int hash;
      scanf("%d", &hash);
      int got = buckets[hashBucket[hash]].insert(posBucket[hash]);
      idBucket[id] = std::pair<int, int>(hashBucket[hash],
                                         (posBucket[hash] + got) % (h / size));
      ans += got;
    } else {
      auto it = idBucket.find(id);
      buckets[it->second.first].erase(it->second.second);
      idBucket.erase(it);
    }
  }
  std::cout << ans << std::endl;
}
