#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MAXn = 2e5 + 100;
bool mark[MAXn];
map<int, int> pl;
vector<int> circ[MAXn];
int wc[MAXn], wi[MAXn];
set<int> st[MAXn];
int main() {
  ios::sync_with_stdio(false);
  int h, m, n;
  cin >> h >> m >> n;
  int c = 0;
  for (int i = 0, __e = h; i < __e; i++) {
    int ti = i;
    if (mark[i]) continue;
    for (int j = 0; !mark[i]; j++) {
      circ[c].push_back(i);
      wc[i] = c;
      wi[i] = j;
      mark[i] = true;
      i = (i + m) % h;
      st[c].insert(j);
    }
    c++;
    i = ti;
  }
  long long count = 0;
  for (int i = 0, __e = n; i < __e; i++) {
    char c;
    int id, hash;
    cin >> c >> id;
    if (c == '+') {
      cin >> hash;
      int c = wc[hash];
      int j = wi[hash];
      set<int>::iterator next = st[c].lower_bound(j);
      if (next == st[c].end()) next = st[c].begin();
      int nhash = circ[c][*next];
      count += (circ[c].size() + wi[nhash] - wi[hash]) % circ[c].size();
      pl[id] = nhash;
      st[c].erase(next);
    } else {
      int hash = pl[id];
      st[wc[hash]].insert(wi[hash]);
    }
  }
  cout << count << endl;
  return 0;
}
