#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 9;
int nx[MAX], h, m, n, cnt, a[MAX], ans;
map<int, int> pos;
pair<int, int> root[MAX];
vector<int> g[MAX];
bool mark[MAX];
set<pair<int, int> > s[MAX];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> h >> m >> n;
  for (int i = 0; i < h; i++) nx[i] = (i + m) % h;
  for (int i = 0; i < h; i++)
    if (!mark[i]) {
      int p = i, k = 0;
      mark[i] = true, root[p] = {cnt, k}, g[cnt].push_back(p), p = nx[p];
      while (p != i)
        k++, g[cnt].push_back(p), root[p] = {cnt, k}, mark[p] = true, p = nx[p];
      cnt++;
    }
  for (int i = 0; i < cnt; i++)
    for (auto v : g[i]) s[i].insert({root[v].second, v});
  for (int i = 0; i < n; i++) {
    char ch;
    cin >> ch;
    if (ch == '+') {
      int id, hsh;
      cin >> id >> hsh;
      int cyc = root[hsh].first;
      auto u = s[cyc].lower_bound({root[hsh].second, hsh});
      if (u == s[cyc].end())
        u = s[cyc].begin(),
        ans += (*u).first + g[cyc].size() - root[hsh].second;
      else
        ans += (*u).first - root[hsh].second;
      pos[id] = (*u).second;
      s[cyc].erase(u);
    } else {
      int id;
      cin >> id;
      int hsh = pos[id];
      int cyc = root[hsh].first;
      s[cyc].insert({root[hsh].second, hsh});
    }
  }
  cout << ans;
}
