#include <bits/stdc++.h>
using namespace std;
struct Stree {
  vector<int> data;
  void construct(int n, int val = 0) {
    data.resize(n + 1);
    for (int i = 1; i <= n; i++) data[i] = (i & -i) * val;
  }
  void add(int pos, int toAdd) {
    if (pos >= (int)data.size()) return;
    data[pos] += toAdd;
    add(pos + (pos & -pos), toAdd);
  }
  int get(int pos) {
    if (pos == 0) return 0;
    return data[pos] + get(pos - (pos & -pos));
  }
  int getLast(int val) {
    int ret = 0;
    for (int tpow = 1 << 19; tpow > 0; tpow /= 2)
      if (ret + tpow < (int)data.size() && data[ret + tpow] <= val) {
        ret += tpow;
        val -= data[ret];
      }
    return ret;
  }
};
int ngroups = 0;
vector<int> group[200000];
Stree st[200000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h, m, n;
  cin >> h >> m >> n;
  vector<pair<int, int> > index(h, make_pair(-1, -1));
  for (int i = 0; i < h; i++)
    if (index[i].first == -1) {
      int g = ngroups++;
      index[i] = make_pair(g, 0);
      group[g].push_back(i);
      for (int j = 1; (i + 1LL * j * m) % h != i; j++) {
        int val = (i + 1LL * j * m) % h;
        index[val] = make_pair(g, j);
        group[g].push_back(val);
      }
      st[g].construct(group[g].size(), 1);
    }
  vector<int> ids;
  vector<pair<int, int> > location;
  vector<pair<char, pair<int, int> > > op(n);
  for (int i = 0; i < n; i++) {
    cin >> op[i].first >> op[i].second.first;
    ids.push_back(op[i].second.first);
    if (op[i].first == '+') cin >> op[i].second.second;
  }
  sort(ids.begin(), ids.end());
  ids.resize(unique(ids.begin(), ids.end()) - ids.begin());
  location.resize(ids.size());
  long long result = 0;
  for (int i = 0; i < n; i++) {
    char c = op[i].first;
    int id = op[i].second.first, hash = op[i].second.second;
    int idloc = lower_bound(ids.begin(), ids.end(), id) - ids.begin();
    if (c == '+') {
      int g = index[hash].first;
      int ind = index[hash].second;
      int loc = st[g].getLast(st[g].get(ind + 1));
      result += loc - ind - 1;
      if (loc == (int)st[g].data.size() - 1) {
        loc = st[g].getLast(0);
        result += loc;
      }
      st[g].add(loc + 1, -1);
      location[idloc] = make_pair(g, loc);
    } else {
      pair<int, int> l = location[idloc];
      st[l.first].add(l.second + 1, 1);
    }
  }
  cout << result << '\n';
  return 0;
}
