#include <bits/stdc++.h>
using namespace std;
int chain[1024000];
int pos_in_chain[1024000];
int chain_cnt;
int chain_len[1024000];
bool u[1024000];
vector<set<int> > freep(1024000);
map<int, pair<int, int> > mp;
int n, m, h;
void add_chain(int i, int p) {
  freep[chain_cnt].insert(p);
  u[i] = true;
  ++chain_len[chain_cnt];
  chain[i] = chain_cnt;
  pos_in_chain[i] = p;
  int next = (i + m) % h;
  if (!u[next]) add_chain(next, p + 1);
}
int main() {
  long long ans = 0;
  cin >> h >> m >> n;
  for (int i = 0; i < h; i++)
    if (!u[i]) {
      add_chain(i, 0);
      ++chain_cnt;
    }
  for (int i = 0; i < n; i++) {
    char c = 0;
    while (c != '+' && c != '-') scanf("%c", &c);
    if (c == '-') {
      int id;
      scanf("%d", &id);
      int cc = mp[id].first;
      int pp = mp[id].second;
      freep[cc].insert(pp);
      mp.erase(id);
    } else {
      int id, ps;
      scanf("%d%d", &id, &ps);
      int cc = chain[ps];
      int pp = pos_in_chain[ps];
      set<int>::iterator it = freep[cc].lower_bound(pp);
      if (it != freep[cc].end()) {
        ans += *it - pp;
        pp = *it;
      } else {
        ans += chain_len[cc] - pp;
        it = freep[cc].lower_bound(0);
        ans += *it;
        pp = *it;
      }
      mp[id] = make_pair(cc, pp);
      freep[cc].erase(pp);
    }
  }
  cout << ans << endl;
}
