#include <bits/stdc++.h>
using namespace std;
long long ans;
vector<set<int> > S;
pair<int, int> belong[1000200];
map<int, pair<int, int> > where;
int h, n, m, Q, tot, len[1000200];
bool vis[1000200];
int next(int a, int b) {
  set<int>::iterator ne = S[a].lower_bound(b);
  if (ne == S[a].end())
    return *S[a].begin();
  else
    return *ne;
}
pair<int, int> ins(int hash) {
  int z = next(belong[hash].first, belong[hash].second);
  S[belong[hash].first].erase(z);
  int t;
  if (belong[hash].second <= z)
    ans += -(belong[hash].second - z);
  else
    ans += len[belong[hash].first] - abs(belong[hash].second - z);
  return make_pair(belong[hash].first, z);
}
void era(int id) {
  pair<int, int> t = where[id];
  S[t.first].insert(t.second);
}
int main() {
  scanf("%d%d%d", &h, &m, &Q);
  for (int i = 0; i <= h - 1; ++i)
    if (!vis[i]) {
      int now = i, num = 0;
      vis[now] = true;
      do {
        ++num;
        belong[now] = make_pair(tot, num);
        now = (now + m) % h;
        vis[now] = true;
      } while (now != i);
      len[tot] = num;
      S.push_back(set<int>());
      ++tot;
    }
  for (int i = 0; i <= tot - 1; ++i) {
    for (int j = 1; j <= len[i]; ++j) S[i].insert(j);
  }
  while (Q--) {
    getchar();
    char ch = getchar();
    if (ch == '+') {
      int who, hash;
      scanf("%d%d", &who, &hash);
      where[who] = ins(hash);
    }
    if (ch == '-') {
      int who;
      scanf("%d", &who);
      era(who);
    }
  }
  cout << ans << endl;
}
