#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 10;
long long h, m, n, comp[MAXN], id[MAXN], g;
bool vis[MAXN];
vector<long long> vec[MAXN];
set<long long> st[MAXN];
map<long long, pair<long long, long long>> mp;
long long ans = 0;
void dfs(long long v, long long de = 0) {
  if (vis[v]) return;
  vis[v] = 1;
  vec[g].push_back(v);
  comp[v] = g, id[v] = de;
  st[g].insert(de);
  dfs((v + m) % h, de + 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> m >> n;
  for (long long i = 0; i < n; i++)
    if (!vis[i]) dfs(i), g++;
  while (n--) {
    char type;
    cin >> type;
    if (type == '-') {
      long long v;
      cin >> v;
      pair<long long, long long> temp = mp[v];
      st[temp.first].insert(temp.second);
    } else {
      long long v, hh;
      cin >> v >> hh;
      long long c = comp[hh], z = id[hh];
      auto it = st[c].lower_bound(z);
      if (it != st[c].end()) {
        ans += *it - z;
        mp[v] = {c, *it};
        st[c].erase(it);
      } else {
        it = st[c].begin();
        ans += *it + (long long)vec[c].size() - z;
        mp[v] = {c, *it};
        st[c].erase(it);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
