#include <bits/stdc++.h>
using namespace std;
const int maxh = 2 * 100 * 1000 + 1000;
int h, m, n;
int mark[maxh];
int nu;
int cir[maxh];
int ja[maxh];
set<int> fre[maxh];
long long dummy;
int si[maxh];
map<int, pair<int, int> > mp;
void add(int id, int hid) {
  int ci = cir[hid];
  int in = ja[hid];
  set<int>::iterator it;
  it = fre[ci].lower_bound(in);
  if (it == fre[ci].end()) it = fre[ci].begin();
  dummy += (si[ci] + *it - in) % si[ci];
  mp[id] = pair<int, int>(ci, *it);
  fre[ci].erase(it);
}
void remove(int id) { fre[mp[id].first].insert(mp[id].second); }
int main() {
  ios::sync_with_stdio(false);
  cin >> h >> m >> n;
  int id;
  int hid;
  for (int i = 0; i < h; ++i) {
    int now = 0;
    if (!mark[i]) {
      int j = i;
      while (!mark[j]) {
        mark[j] = true;
        cir[j] = nu;
        ja[j] = now++;
        si[nu]++;
        j = (j + m) % h;
      }
      nu++;
    }
  }
  for (int i = 0; i < h; ++i) fre[cir[i]].insert(ja[i]);
  for (int i = 0; i < n; ++i) {
    string ss;
    cin >> ss;
    cin >> id;
    if (ss == "+") {
      cin >> hid;
      add(id, hid);
    } else {
      remove(id);
    }
  }
  cout << dummy << endl;
  return 0;
}
