#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:64000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 300100;
int n, m, h, k, x[MAXN], y[MAXN];
vector<int> l[MAXN];
set<int> st[MAXN];
map<int, int> pos;
bool used[MAXN];
long long ans = 0;
int getMin(set<int> &st, int l, int size) {
  set<int>::iterator i = st.lower_bound(l);
  if (i == st.end()) i = st.begin();
  int ans = *i;
  ::ans += (ans + size - l) % size;
  st.erase(ans);
  return ans;
}
int main() {
  cin >> h >> m >> n;
  for (int i = 0; i < (int)(h); i++) {
    if (used[i]) continue;
    int v = i;
    while (!used[v]) {
      x[v] = k;
      y[v] = (int)l[k].size();
      st[k].insert(y[v]);
      l[k].push_back(v);
      used[v] = true;
      v = (v + m) % h;
    }
    k++;
  }
  for (int i = 0; i < (int)(n); i++) {
    char c[10];
    int id;
    scanf(" %s%d", c, &id);
    if (c[0] == '+') {
      int hash;
      scanf("%d", &hash);
      int v = getMin(st[x[hash]], y[hash], (int)l[x[hash]].size());
      pos[id] = l[x[hash]][v];
    } else {
      int v = pos[id];
      pos.erase(id);
      st[x[v]].insert(y[v]);
    }
  }
  cout << ans << endl;
  return 0;
}
