#include <bits/stdc++.h>
using namespace std;
template <typename INT>
INT rgcd(INT a, INT b) {
  return b == 0 ? a : rgcd(b, a % b);
}
template <typename INT>
INT lcm(INT a, INT b) {
  return a / rgcd(a, b) * b;
}
long long H, M;
int N;
map<int, long long> HV;
map<int, long long> placed;
pair<int, long long> loc[200004];
vector<set<long long> > free_lists;
void preprocess() {
  for (int x = 0; x < H; ++x) loc[x].first = -1;
  for (int x = 0; x < H; ++x) {
    if (loc[x].first >= 0) continue;
    int list_id = free_lists.size();
    free_lists.push_back(set<long long>());
    for (long long y = x; loc[y % H].first < 0; y += M) {
      loc[y % H].first = list_id;
      loc[y % H].second = y;
      free_lists[list_id].insert(y);
    }
  }
  for (int i = 0; i < free_lists.size(); ++i) {
    cerr << i << ":";
    for (typeof((free_lists[i]).begin()) it = (free_lists[i]).begin();
         it != (free_lists[i]).end(); ++it)
      cerr << ' ' << *it;
    cerr << endl;
  }
}
int main() {
  cin.sync_with_stdio(false);
  cin >> H >> M >> N;
  long long F = lcm(H, M);
  preprocess();
  long long res = 0;
  for (int n = 1; n <= N; ++n) {
    char cmd[2];
    int id;
    long long hv;
    cin >> cmd >> id;
    if (*cmd == '+') {
      cin >> hv;
      HV[id] = hv;
      int list_id = loc[hv].first;
      set<long long>::iterator it =
          free_lists[list_id].lower_bound(loc[hv].second);
      long long yy;
      if (it == free_lists[list_id].end()) {
        it = free_lists[list_id].begin();
        yy = *it + F;
      } else
        yy = *it;
      long long cur = yy - loc[hv].second;
      cerr << "* " << n << " " << hv << " : " << loc[hv].first << '#'
           << loc[hv].second << ' ' << yy << ' ' << cur << endl;
      res += cur / M;
      placed[id] = *it;
      free_lists[list_id].erase(it);
    } else {
      hv = HV[id];
      int list_id = loc[hv].first;
      free_lists[list_id].insert(placed[id]);
      placed.erase(id);
    }
  }
  cout << res << endl;
  return 0;
}
