#include <bits/stdc++.h>   struct Node {     int sum, value;     Node *ch[2], *p;     __inline Node(int value = 0) : value(value) {       sum = 1;       ch[0] = ch[1] = p = NULL;     }     __inline void update() {       sum = 1 + (ch[0] ? ch[0]->sum : 0) + (ch[1] ? ch[1]->sum : 0);     }   } pool[211111], *cur = pool;   __inline bool cut(Node *y) {     if (!y) return 0;     Node *x = y->p;     if (x != NULL) {       bool d = y == x->ch[1];       x->ch[d] = NULL;       x->sum -= y->sum;       y->p = NULL;       return d;     }     return 0;   }   __inline void link(Node *x, Node *y, bool d) {     if (y == NULL) return;     ;     ;     if (x) {       ;       ;       y->p = x;       x->ch[d] = y;       x->sum += y->sum;     }   }   __inline void rotate(Node *x, bool d) {     ;     ;     Node *y = x->ch[d], *px = x->p, *B = y->ch[!d];     bool dd = cut(x);     cut(y);     cut(B);     link(x, B, d);     link(y, x, !d);     link(px, y, dd);   }   __inline Node *trace_root(Node *x) {     if (x == NULL) return NULL;     for (; x->p != NULL; x = x->p)       ;     return x;   }   __inline Node *trace(Node *x, bool d) {     if (x == NULL) return NULL;     for (; x->ch[d] != NULL; x = x->ch[d])       ;     return x;   }   __inline void splay(Node *x, Node *term) {     if (x == NULL) return;     for (; x->p != term;) {       Node *y = x->p;       bool dx = x == y->ch[1];       if (y->p == term)         rotate(y, dx);       else {         Node *z = y->p;         bool dy = y == z->ch[1];         if (dx == dy) {           rotate(z, dy);           rotate(y, dx);         } else {           rotate(y, dx);           rotate(z, dy);         }       }     }   }   __inline void rand_splay(Node *T) {     if (T == NULL) return;     Node *last;     for (last = T, T = T->ch[rand() & 1]; T != NULL;) T = T->ch[rand() & 1];     splay(last, NULL);   }   const int N = 222222;   std::map<int, Node *> node;   Node *tree[N];   int nxt[N], prv[N];   int n, h, m;   int main() {     std::ios::sync_with_stdio(false);     std::cin.tie(0);     std::cin >> h >> m >> n;     long long ans = 0;     for (int i = 0; i < h; ++i) nxt[i] = (i + m) % h, prv[i] = (i + h - m) % h;     for (int _ = 0; _ < n; ++_) {       char buf[3];       int id;       std::cin >> buf >> id;       if (buf[0] ==  + ) {         int th;         std::cin >> th;         Node *T = tree[th];         splay(T, NULL);         ans += T ? (T->ch[1] ? T->ch[1]->sum + 1 : 1) : 0;         if (T != NULL) {           Node *t = trace(T, 1);           th = nxt[t->value];           T = tree[th];           ;           ;         }         T = cur++;         T->value = th;         tree[th] = T;         Node *rt0 = tree[prv[th]];         splay(rt0, NULL);         Node *rt1 = trace_root(tree[nxt[th]]);         link(T, rt0, 0);         if (rt1 != rt0) link(T, rt1, 1);         node[id] = T;       } else {         Node *T = node[id];         splay(T, NULL);         Node *t = trace(T->ch[1], 1);         cut(T->ch[0]);         cut(T->ch[1]);         tree[T->value] = NULL;         node[id] = NULL;         if (t)           T = trace_root(tree[nxt[t->value]]);         else           T = NULL;         if (T) {           splay(t, NULL);           link(t, T, 1);         }       }     }     std::cout << ans << std::endl;     return 0;   }