#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 10;
set<pair<int, int> > pos[maxn];
map<int, int> mp;
int h, m, n, Last[maxn];
bool vis[maxn];
int ID[maxn], CP[maxn];
int main() {
  scanf("%d%d%d", &h, &m, &n);
  int tot = 0;
  for (int i = 0; i < h; ++i) {
    if (!vis[i]) {
      ++tot;
      int cnt = 0;
      for (int x = i; !vis[x]; x = (x + m) % h) {
        vis[x] = true;
        pos[tot].insert(make_pair(cnt, x));
        ID[x] = tot;
        CP[x] = cnt++;
      }
      Last[tot] = cnt;
    }
  }
  long long ans = 0;
  for (int i = 0; i < n; ++i) {
    char op;
    int id;
    int hash;
    scanf(" %c%d", &op, &id);
    if (op == '+') {
      scanf("%d", &hash);
      int loc = ID[hash];
      int key = CP[hash];
      set<pair<int, int> >::iterator it =
          pos[loc].lower_bound(make_pair(key, -1));
      if (it != pos[loc].end()) {
        ans += it->first - key;
      } else {
        ans += Last[loc] - key;
        it = pos[loc].lower_bound(make_pair(0, -1));
        ans += it->first;
      }
      mp[id] = it->second;
      pos[loc].erase(it);
    } else {
      int v = mp[id];
      int loc = ID[v];
      pos[loc].insert(make_pair(CP[v], v));
      mp.erase(id);
    }
  }
  cout << ans << endl;
}
