#include <bits/stdc++.h>
using namespace std;
static const double EPS = 1e-10;
template <typename T, typename S>
vector<T>& operator<<(vector<T>& a, S b) {
  a.push_back(b);
  return a;
}
template <typename T>
void operator>>(vector<T>& a, int b) {
  while (b--)
    if (!a.empty()) a.pop_back();
}
bool isprime(int n) {
  if (n < 2) return false;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return false;
  return true;
}
long long b_pow(long long x, long long n) {
  return n ? b_pow(x * x, n / 2) * (n % 2 ? x : 1) : 1ll;
}
string itos(int n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
vector<vector<int> > DBG;
vector<set<int> > SET;
int where[(200010)];
int idx[(200010)];
int box_size[(200010)];
map<int, pair<int, int> > reg;
int main() {
  ios_base::sync_with_stdio(false);
  int n, m, h;
  cin >> h >> m >> n;
  for (int i = 0; i < h; i++) where[i] = -1;
  for (int i = 0; i < h; i++) {
    if (where[i] == -1) {
      DBG.push_back(vector<int>(0));
      int x = i;
      int size = 0;
      SET.push_back(set<int>());
      while (where[x] == -1) {
        size++;
        where[x] = SET.size() - 1;
        idx[x] = size;
        SET.back().insert(size);
        DBG.back().push_back(x);
        x = (x + m) % h;
      }
      box_size[SET.size() - 1] = size;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    char c;
    int a, b;
    cin >> c;
    if (c == '+') {
      cin >> a >> b;
      int w = where[b];
      int p = idx[b];
      set<int>& my = SET[w];
      set<int>::iterator it = my.lower_bound(p);
      if (it == my.end()) {
        ans += box_size[w] - p;
        set<int>::iterator it2 = my.lower_bound(0);
        ans += *(it2);
        reg[a] = make_pair(w, *it2);
        my.erase(*it2);
      } else {
        ans += (*it) - p;
        reg[a] = make_pair(w, *it);
        my.erase(*it);
      }
    } else {
      cin >> a;
      int w = reg[a].first;
      int p = reg[a].second;
      SET[w].insert(p);
    }
  }
  cout << ans << endl;
}
