#include <bits/stdc++.h>
using namespace std;
class RTree {
 public:
  vector<int> data;
  vector<int> lft;
  vector<int> rgt;
  int sz;
  int tsz;
  void Init(int size) {
    sz = size;
    tsz = 2;
    while (tsz < sz) tsz *= 2;
    data.resize(1 + tsz - 1 + tsz);
    lft.resize(1 + tsz - 1 + tsz);
    rgt.resize(1 + tsz - 1 + tsz);
    int i;
    for (i = 1; i <= 2 * tsz - 1; i++) data[i] = 0;
    for (i = tsz; i < 2 * tsz; i++) {
      lft[i] = i - tsz;
      rgt[i] = i - tsz;
    }
    for (i = tsz - 1; i >= 1; i--) {
      lft[i] = lft[2 * i];
      rgt[i] = rgt[2 * i + 1];
    }
  }
  int Sum(int l, int r) {
    l += tsz;
    r += tsz;
    int res = 0;
    while (l <= r) {
      if (l & 1) {
        res += data[l];
        l++;
      }
      if (!(r & 1)) {
        res += data[r];
        r--;
      }
      l >>= 1;
      r >>= 1;
    }
    return res;
  }
  int FF0(int pos) {
    int ll = pos;
    int rr = sz - 1;
    int opt = sz;
    while (ll <= rr) {
      int mid = (ll + rr) / 2;
      int s = Sum(pos, mid);
      if (s == mid - pos + 1) {
        ll = mid + 1;
      } else {
        if (mid < opt) opt = mid;
        rr = mid - 1;
      }
    }
    if (opt == sz) return FF0(0);
    return opt;
  }
  void Add(int p, int d) {
    p += tsz;
    while (p >= 1) {
      data[p] += d;
      p >>= 1;
    }
  }
};
int h, m, n;
vector<RTree> trees;
int wtree[210000];
int wpos[210000];
void Load() {
  scanf("%d%d%d", &h, &m, &n);
  memset(wtree, 0xFF, sizeof(wtree));
  int i;
  for (i = 0; i < h; i++) {
    if (wtree[i] != -1) continue;
    int j;
    int cnt = 0;
    j = i;
    while (wtree[j] == -1) {
      wtree[j] = trees.size();
      wpos[j] = cnt;
      cnt++;
      j = (j + m) % h;
    }
    RTree a;
    trees.push_back(a);
    trees.back().Init(cnt);
  }
}
map<int, int> whereidt;
map<int, int> whereidpos;
void Solve() {
  int i;
  long long res = 0;
  for (i = 0; i < n; i++) {
    char c = getchar();
    while (!((c == '+') || (c == '-'))) c = getchar();
    int id, hash;
    if (c == '+') {
      scanf("%d%d", &id, &hash);
      int t = wtree[hash];
      int pos = wpos[hash];
      int rp = trees[t].FF0(pos);
      if (rp >= pos)
        res += (rp - pos);
      else {
        res += rp + (trees[t].sz - pos);
      }
      trees[t].Add(rp, 1);
      whereidt[id] = t;
      whereidpos[id] = rp;
    } else {
      scanf("%d", &id);
      trees[whereidt[id]].Add(whereidpos[id], -1);
    }
  }
  cout << res;
}
int main() {
  Load();
  Solve();
  return 0;
}
