#include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
  for (; a != b; ++a) cerr << *a << ' ';
  cerr << endl;
}
int h, m, n;
map<int, int> conv;
map<pair<int, int>, int> rev;
int used[200005];
pair<int, int> pos[200005];
int gcnt;
struct segtree {
  int n;
  vector<int> val;
  void init(int n_) {
    n = 1;
    while (n < n_) n <<= 1;
    val.resize(n * 2);
    for (int i = 0; i < n_; ++i) val[i + n - 1] = 1;
    for (int i = n - 2; i >= 0; --i) val[i] = val[i * 2 + 1] + val[i * 2 + 2];
  }
  void add(int k, int a) {
    k += n - 1;
    val[k] += a;
    while (k) {
      k = (k - 1) / 2;
      val[k] += a;
    }
  }
  int query(int begin, int node, int l, int r, int& v) {
    if (r <= begin) return INF;
    int md = (l + r) >> 1, left, right;
    if (l < begin) {
      left = query(begin, node * 2 + 1, l, md, v);
      if (left < INF) return left;
      right = query(begin, node * 2 + 2, md, r, v);
      return right;
    }
    if (val[node] < v) {
      v -= val[node];
      return INF;
    }
    if (r - l == 1) return l;
    if (val[node * 2 + 1] < v) {
      v -= val[node * 2 + 1];
      return query(begin, node * 2 + 2, md, r, v);
    } else
      return query(begin, node * 2 + 1, l, md, v);
  }
  int q(int begin, int step) {
    int a, b;
    a = query(begin, 0, 0, n, step);
    if (a < INF) return a;
    return query(0, 0, 0, n, step);
  }
};
segtree segs[200005];
int num[200005];
int main() {
  scanf("%d%d%d", &h, &m, &n);
  memset(pos, -1, sizeof(pos));
  for (int i = 0; i < h; ++i) {
    if (pos[i].first != -1) continue;
    int cnt = 0;
    for (int j = i; pos[j].first == -1; j = (j + m) % h, ++cnt) {
      pos[j] = make_pair(gcnt, cnt);
      rev[pos[j]] = j;
    }
    num[gcnt] = cnt;
    segs[gcnt].init(cnt);
    ++gcnt;
  }
  char tmp[10];
  long long int res = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%s", tmp);
    if (tmp[0] == '+') {
      int id, hash;
      scanf("%d%d", &id, &hash);
      int row = pos[hash].first, begin = pos[hash].second;
      int p = segs[row].q(begin, 1);
      if (begin <= p)
        res += p - begin;
      else
        res += num[row] - begin + p;
      int p2 = rev[make_pair(row, p)];
      segs[row].add(p, -1);
      conv[id] = p2;
    } else {
      int id;
      scanf("%d", &id);
      int p = conv[id];
      segs[pos[p].first].add(pos[p].second, 1);
    }
  }
  cout << res << endl;
  return 0;
}
