#include <bits/stdc++.h>
const double eps = 1e-9;
const int oo = 1000000000;
const double E = 2.7182818284590452353602874713527;
const double pi = 3.1415926535897932384626433832795;
using namespace std;
set<int> a[200001];
map<int, pair<int, int> > rec;
int num[200001], pos[200001];
char str[5];
int main() {
  int h, m, n, tot, o = 0;
  long long ans = 0;
  cin >> h >> m >> n;
  for (int i = 0; i < h; i++)
    if (!num[i]) {
      int s = 0;
      o++;
      for (int j = i; !num[j]; j = (j + m) % h) {
        num[j] = o;
        pos[j] = ++s;
        a[o].insert(s);
      }
      tot = s;
    }
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%s%d", str, &x);
    if (str[0] == '+') {
      scanf("%d", &y);
      set<int>::iterator t = a[num[y]].lower_bound(pos[y]);
      if (t == a[num[y]].end()) t = a[num[y]].begin();
      ans += (*t - pos[y] + tot) % tot;
      rec[x] = make_pair(num[y], *t);
      a[num[y]].erase(*t);
    } else
      a[rec[x].first].insert(rec[x].second);
  }
  cout << ans << endl;
  return 0;
}
