The Smart Beaver from ABBYY has a lot of hobbies. One of them is constructing efficient hash tables. One of the most serious problems in hash tables is resolving collisions. The Beaver is interested in this problem very much and he decided to explore it in detail.

We assume that the hash table consists of h cells numbered from 0 to h - 1. Objects are added to and removed from it. Every object has its own unique identifier. In addition, every object has a corresponding hash value — an integer between 0 and h - 1, inclusive. When an object is added to the table, if the cell corresponding to the hash value of the object is free, then this object goes there. If the cell is already occupied by another object, there is a collision. When an object is deleted from the table, the cell which it occupied becomes empty.

The Smart Beaver has recently learned about the method of linear probing to resolve collisions. It is as follows. Let's say that the hash value for the added object equals t and cell t of the table is already occupied. Then we try to add this object to cell (t + m) mod h. If it is also occupied, then we try cell (t + 2·m) mod h, then cell (t + 3·m) mod h, and so on. Note that in some cases it's possible that the new object can not be added to the table. It is guaranteed that the input for this problem doesn't contain such situations.

The operation a mod b means that we take the remainder of the division of number a by number b.

This technique immediately seemed very inoptimal to the Beaver, and he decided to assess its inefficiency. So, you are given a sequence of operations, each of which is either an addition of an object to the table or a deletion of an object from the table. When adding a new object, a sequence of calls to the table is performed. Calls to occupied cells are called dummy. In other words, if the result of the algorithm described above is the object being added to cell (t + i·m) mod h (i ≥ 0), then exactly i dummy calls have been performed.

Your task is to calculate the total number of dummy calls to the table for the given sequence of additions and deletions. When an object is deleted from the table, assume that no dummy calls are performed. The table is empty before performing the operations, that is, initially it doesn't contain any objects.

Input

The first line of input contains three integers h, m and n (1 ≤ m < h), separated by spaces, where h is the size of the hash table, m is the number that is used to resolve collisions, n is the number of operations.

The following n lines contains the descriptions of the operations. Their execution order corresponds to the order in which they appear in the input file. Each operation is described by a single line. The operations are described as follows:

  * "+ id hash"

This is the format of the operation that adds an object to the table. The first character is "+" (ASCII 43), followed by a single space, then the object identifier id (0 ≤ id ≤ 109), then another space, and the hash value of the given object hash (0 ≤ hash < h). The object identifier and the hash value of this object are integers.

  * "- id"

This is the format of the operation that deletes an object from the table. The first character is "-" (ASCII 45), followed by a single space, then the object identifier id (0 ≤ id ≤ 109). The object identifier is an integer.




It is guaranteed that for all addition operations the value of id is unique. It is also guaranteed that the initial data is correct, that is, it's always possible to add an object to the hash table and there won't be any deletions of nonexisting objects.

The input limitations for getting 20 points are: 

  * 1 ≤ h ≤ 5000
  * 1 ≤ n ≤ 5000



The input limitations for getting 50 points are: 

  * 1 ≤ h ≤ 5·104
  * 1 ≤ n ≤ 5·104



The input limitations for getting 100 points are: 

  * 1 ≤ h ≤ 2·105
  * 1 ≤ n ≤ 2·105

Output

Print a single number — the total number of dummy calls to the hash table.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams and the %I64d specifier.

Examples

Input

10 2 7
+ 11 0
+ 22 2
+ 33 6
+ 44 0
+ 55 0
- 22
+ 66 0


Output

7


Input

5 1 6
+ 123 0
+ 234 1
+ 345 2
- 234
+ 456 0
+ 567 0


Output

4
#include <bits/stdc++.h>
using namespace std;
struct Node {
  bool fr;
  int lb, rb;
  Node *lc, *rc;
};
void buildSeg(Node *&p, int l, int r) {
  p = new Node;
  p->fr = true;
  p->lb = l;
  p->rb = r;
  if (p->lb < p->rb) {
    int mid = (p->lb + p->rb) / 2;
    buildSeg(p->lc, p->lb, mid);
    buildSeg(p->rc, mid + 1, p->rb);
  }
}
void setVal(Node *p, int x, bool val) {
  if (p->lb == p->rb)
    p->fr = val;
  else {
    int mid = (p->lb + p->rb) / 2;
    if (x <= mid)
      setVal(p->lc, x, val);
    else
      setVal(p->rc, x, val);
    p->fr = p->lc->fr | p->rc->fr;
  }
}
int findFr(Node *p, int l, int r) {
  if (p->fr) {
    if (p->lb == p->rb)
      return p->lb;
    else {
      int mid = (p->lb + p->rb) / 2, ret = -1;
      if (l <= mid) ret = findFr(p->lc, l, r);
      if ((mid + 1 <= r) && (ret == -1)) ret = findFr(p->rc, l, r);
      return ret;
    }
  }
  return -1;
}
const int _N = 200010;
int h, m, n, ptN, pt[_N];
long long cost;
pair<int, int> inP[_N];
Node *rt;
map<int, int> ps;
void initSeg() {
  ptN = 0;
  int cnt = 0;
  for (int i = 0; i < h; i++) inP[i].first = -1;
  for (int i = 0; i < h; i++)
    if (inP[i].first == -1) {
      pt[ptN] = cnt;
      for (int j = i; inP[j].first == -1; j = (j + m) % h)
        inP[j] = pair<int, int>(ptN, cnt++);
      ptN++;
    }
  pt[ptN] = cnt;
  buildSeg(rt, 0, cnt - 1);
}
void pushHash(int i, int v) {
  int p = findFr(rt, inP[v].second, pt[inP[v].first + 1] - 1);
  if (p == -1) p = findFr(rt, pt[inP[v].first], inP[v].second - 1);
  setVal(rt, p, false);
  ps.insert(pair<int, int>(i, p));
  cost += (p >= inP[v].second)
              ? (p - inP[v].second)
              : (pt[inP[v].first + 1] - inP[v].second + p - pt[inP[v].first]);
}
void popHash(int i) {
  map<int, int>::iterator x = ps.find(i);
  setVal(rt, x->second, true);
  ps.erase(x);
}
int main() {
  ios::sync_with_stdio(false);
  cin >> h >> m >> n;
  initSeg();
  cost = 0;
  for (int k = 0; k < n; k++) {
    char c;
    int i;
    cin >> c >> i;
    if (c == '+') {
      int v;
      cin >> v;
      pushHash(i, v);
    } else
      popHash(i);
  }
  cout << cost << endl;
  return 0;
}
