#include <bits/stdc++.h>
using namespace std;
int N, K, Q;
map<int, int> mp;
int a[(1 << 18)];
void add(int x, int val) {
  for (int i = x; i < (1 << 18); i = ((i) | (i + 1))) a[i] += val;
}
int sum(int x) {
  int ans = 0;
  for (int i = x; i > 0; i = ((i) & (i - 1))) ans += a[i - 1];
  return ans;
}
int search(int low, int high, int sum, int x, int y) {
  if (x >= high || y <= low || sum == high - low) return -1;
  if (high - low == 1) return low;
  int mid = (high + low) / 2;
  int ans = search(low, mid, a[mid - 1], x, y);
  if (ans != -1) return ans;
  return search(mid, high, sum - a[mid - 1], x, y);
}
int add_query(int x, int y) {
  int ans = search(0, (1 << 18), a[(1 << 18) - 1], x, y);
  if (ans != -1) add(ans, 1);
  return ans;
}
void delete_query(int x) { add(x, -1); }
int b[200010];
int main(void) {
  int i, j, k;
  long long ans = 0;
  scanf(" %d %d %d ", &N, &K, &Q);
  int g;
  for (g = N;; g--)
    if (N % g == 0 && K % g == 0) break;
  int bucket = N / g;
  k = 0;
  for ((i) = 0; (i) < (int)(g); (i)++) {
    int x = i;
    for ((j) = 0; (j) < (int)(bucket); (j)++) {
      b[x] = k;
      k++;
      x = (x + K) % N;
    }
  }
  for ((i) = 0; (i) < (int)(Q); (i)++) {
    char ch;
    int id, hash;
    scanf(" %c ", &ch);
    if (ch == '+') {
      scanf(" %d %d ", &id, &hash);
      hash = b[hash];
      int L = hash / bucket * bucket;
      int R = L + bucket;
      int p = add_query(hash, R);
      if (p != -1) ans += p - hash;
      if (p == -1) {
        p = add_query(L, R);
        ans += p - L + R - hash;
      }
      mp[id] = p;
    } else {
      scanf(" %d ", &id);
      int tmp = mp[id];
      delete_query(tmp);
    }
  }
  cout << ans << endl;
  return 0;
}
