#include <bits/stdc++.h>
using namespace std;
const static int inf = 10000000;
int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  if (a % b == 0) {
    return b;
  }
  return gcd(b, a % b);
}
long long h, m, n;
long long g;
vector<set<long long> > empty_lists;
vector<long long> height;
vector<bool> is_full;
long long ans = 0;
map<long long, long long> id2val;
map<int, int> id2call;
void add(int id, int val) {
  int call;
  int mod = val % g;
  if (is_full[val]) {
    int mod = val % g;
    int hi = height[val];
    set<long long>::const_iterator it = empty_lists[mod].upper_bound(hi);
    if (it == empty_lists[mod].end()) {
      int next = *empty_lists[mod].begin();
      empty_lists[mod].erase(next);
      call = (h / g) + next - hi;
    } else {
      int next = *it;
      empty_lists[mod].erase(it);
      call = next - hi;
    }
  } else {
    int mod = val % g;
    int hi = height[val];
    empty_lists[mod].erase(hi);
    call = 0;
  }
  long long pos = (val + call * m) % h;
  is_full[pos] = true;
  id2call[id] = call;
  id2val[id] = val;
  ans += call;
}
void del(int id) {
  long long call = id2call[id];
  long long val = id2val[id];
  long long pos = (val + call * m) % h;
  int mod = val % g;
  int hi = height[pos];
  empty_lists[mod].insert(hi);
  is_full[pos] = false;
}
int main() {
  while (cin >> h >> m >> n) {
    ans = 0;
    g = gcd(h, m);
    empty_lists.clear();
    empty_lists.resize(g);
    height.clear();
    height.resize(h);
    for (int i = 0; i < (int)(g); i++) {
      long long now = i;
      for (int j = 0; j < (int)(h / g); j++) {
        height[now] = j;
        empty_lists[i].insert(j);
        now = (now + m) % h;
      }
    }
    is_full.clear();
    is_full.resize(n, false);
    for (int i = 0; i < (int)(n); i++) {
      char s;
      cin >> s;
      if (s == '+') {
        int id, val;
        cin >> id >> val;
        add(id, val);
      } else {
        int id;
        cin >> id;
        del(id);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
