#include <bits/stdc++.h>
using namespace std;
const long double epsilon = 1e-9;
int mat2[1 << 18];
int idx2[1 << 18];
int minm[1 << 18];
int maxm[1 << 18];
int main() {
  int h, m, n;
  cin >> h >> m >> n;
  memset(minm, -1, sizeof(minm));
  memset(maxm, -1, sizeof(maxm));
  int idx = 0;
  for (int i = 0; i < h; i++) {
    if (minm[i] == -1) {
      minm[i] = idx;
      mat2[idx++] = i;
      int tmp = (i + m) % h;
      while (tmp != i) {
        mat2[idx++] = tmp;
        tmp = (tmp + m) % h;
      }
      maxm[i] = idx - 1;
      tmp = (i + m) % h;
      while (tmp != i) {
        maxm[tmp] = maxm[i];
        minm[tmp] = minm[i];
        tmp = (tmp + m) % h;
      }
    }
  }
  for (int i = 0; i < h; i++) {
    idx2[mat2[i]] = i;
  }
  set<int> s;
  for (int i = 0; i < h; i++) s.insert(i);
  long long cnt = 0;
  string str;
  map<int, int> id_map;
  set<int>::iterator itr;
  int x, y;
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (str == "+") {
      scanf("%d", &x);
      scanf("%d", &y);
      int place;
      itr = s.lower_bound(idx2[y]);
      if (itr != s.end() && *itr <= maxm[y]) {
        cnt += (long long)*itr - idx2[y];
        place = *itr;
      } else {
        cnt += (long long)maxm[y] - idx2[y];
        itr = s.lower_bound(minm[y]);
        cnt += (long long)*itr - minm[y] + 1;
        place = *itr;
      }
      s.erase(place);
      id_map.insert(make_pair(x, place));
    } else {
      scanf("%d", &x);
      s.insert(id_map[x]);
      id_map.erase(x);
    }
  }
  cout << cnt << endl;
  return 0;
}
