#include <bits/stdc++.h>
using namespace std;
const int N = 203600;
long long h, m;
int n;
bool vis[N];
long long lid[N], mid[N];
set<long long> use[N], rsv[N];
long long pos[N];
int len;
int num;
map<long long, long long> mp;
map<long long, long long> lp;
int main() {
  cin >> h >> m >> n;
  memset(vis, 0, sizeof(vis));
  num = 0;
  for (int i = (0); i < (int)(h); i++)
    if (!vis[i]) {
      long long first = i;
      int p = 0;
      while (!vis[first % h]) {
        vis[first % h] = true;
        rsv[num].insert(p);
        lid[first % h] = num;
        mid[first % h] = first;
        pos[first % h] = p++;
        first += m;
      }
      ++num;
    }
  len = rsv[0].size();
  long long ans = 0LL;
  string s;
  long long id, val;
  while (n--) {
    cin >> s >> id;
    if (s == "-") {
      long long l = lp[id];
      long long p = mp[id];
      rsv[l].insert(p);
      use[l].erase(p);
      mp.erase(id);
    } else {
      cin >> val;
      int l = lid[val];
      int p = pos[val];
      int p2 = p;
      if (n % 1000 == 0) {
      }
      set<long long>::iterator it;
      it = lower_bound(rsv[l].begin(), rsv[l].end(), p);
      if (it == rsv[l].end()) it = rsv[l].begin();
      p2 = *it;
      use[l].insert(p2);
      rsv[l].erase(p2);
      long long add = (p2 - p) % len;
      add = (add + len) % len;
      ans += add;
      lp[id] = l;
      mp[id] = p2;
    }
  }
  cout << ans << endl;
  return 0;
}
