#include <bits/stdc++.h>
using namespace std;
int a[5000];
int t[5000] = {0};
int color[200001] = {0}, ind[200001] = {0};
set<int> st[200001];
vector<int> v[200001];
map<int, int> mp;
int main() {
  int h, n, m;
  cin >> h >> m >> n;
  int cnt = 0;
  int ccnt = 0;
  for (int i = 0; i < n; i++) {
    if (color[i] == 0) {
      ++ccnt;
      int num = i, index = 0;
      while (color[num] == 0) {
        color[num] = ccnt;
        ind[num] = index;
        st[ccnt].insert(index);
        v[ccnt].push_back(num);
        index++;
        num = (num + m) % h;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    string p;
    int id, hash;
    cin >> p >> id;
    if (p == "+") {
      cin >> hash;
      int col = color[hash], index = ind[hash];
      int pos, temp = 0;
      set<int>::iterator iter = st[col].lower_bound(index);
      if (iter == st[col].end()) {
        iter = st[col].begin();
        temp += v[col].size() - index;
      }
      pos = *iter;
      if (pos < index)
        temp += pos;
      else
        temp += pos - index;
      cnt += temp;
      st[col].erase(iter);
      mp[id] = v[col][pos];
    } else {
      int hash = mp[id];
      int col = color[hash];
      int index = ind[hash];
      st[col].insert(index);
      mp.erase(id);
    }
  }
  cout << cnt;
}
