#include <bits/stdc++.h>
const int maxn = 200005;
using namespace std;
int *fen[maxn];
bool mark[maxn];
vector<int> v[maxn];
pair<int, int> c[maxn];
int sz[maxn];
map<int, int> where;
void add(int id, int x, int val) {
  x++;
  for (; x <= sz[id]; x += x & (-x)) fen[id][x] += val;
}
int _get(int id, int x) {
  int ans = 0;
  for (; x; x -= x & (-x)) ans += fen[id][x];
  return ans;
}
int get(int id, int x1, int x2) { return _get(id, x2) - _get(id, x1); }
int main() {
  ios::sync_with_stdio(false);
  int h, m, n;
  int cn = 0;
  long long ans = 0;
  cin >> h >> m >> n;
  for (int i = 0; i < h; i++) {
    if (!mark[i]) {
      int j = i;
      do {
        mark[j] = true;
        v[cn].push_back(j);
        c[j] = {cn, v[cn].size() - 1};
        j = (j + m) % h;
      } while (j != i);
      cn++;
    }
  }
  for (int i = 0; i < cn; i++) {
    sz[i] = 2 * v[i].size();
    fen[i] = new int[sz[i] + 5];
    fill(fen[i], fen[i] + sz[i] + 5, 0);
  }
  while (n--) {
    char com;
    int id, w;
    cin >> com >> id;
    if (com == '+') {
      cin >> w;
      int x = c[w].first, y = c[w].second;
      int low = y, high = y + v[x].size();
      while (high - low > 1) {
        int mid = (low + high) / 2;
        ((get(x, y, mid) == mid - y) ? low : high) = mid;
      }
      ans += low - y;
      low %= v[x].size();
      where[id] = v[x][low];
      add(x, low, 1);
      add(x, v[x].size() + low, 1);
    } else {
      int w = where[id];
      int x = c[w].first, y = c[w].second;
      add(x, y, -1);
      add(x, v[x].size() + y, -1);
    }
  }
  cout << ans << endl;
  return 0;
}
