#include <bits/stdc++.h>
using namespace std;
struct pnt {
  long long x, y, v;
  pnt() { x = y = v = 1e9; }
} inp[2][120];
long long hl, hr, n, t[2], ans;
long long pxl, pyl, pxr = 1e5, pyr, rlen;
bool fun(pnt a, pnt b) { return a.x <= b.x; }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> hl >> hr >> n;
  for (long long i = 1, v, x, y; i <= n; ++i) {
    char s;
    cin >> v >> s >> x >> y;
    t[!(s - 'F')]++;
    inp[!(s - 'F')][t[!(s - 'F')]].v = v;
    inp[!(s - 'F')][t[!(s - 'F')]].x = x;
    inp[!(s - 'F')][t[!(s - 'F')]].y = y;
  }
  sort(inp[0] + 1, inp[0] + t[0] + 1, fun);
  sort(inp[1] + 1, inp[1] + t[1] + 1, fun);
  if (!t[0] or !t[1]) {
    cout << 0 << endl;
    return 0;
  }
  pyl = hl;
  pyr = hr;
  rlen = hr;
  for (long long i = 1; i <= n; ++i) {
    long long tyl = 100, tyr = 100;
    long long res = 0, cnt[2] = {1, 1};
    rlen = 100 - rlen;
    pyr += 2 * rlen;
    bool chk = 0, sgn = 0;
    for (long long j = 1; j <= i; ++j) {
      long long S1, S2;
      S1 = abs(tyl - pyl);
      S2 = abs(tyr - pyr) + S1;
      S1 *= 100000;
      while (cnt[sgn] <= t[sgn]) {
        if (S1 < inp[sgn][cnt[sgn]].x * S2) break;
        if (S1 <= inp[sgn][cnt[sgn]].y * S2) {
          res += inp[sgn][cnt[sgn]].v;
          ++cnt[sgn];
          chk = 1;
          break;
        }
        ++cnt[sgn];
      }
      if (!chk) {
        chk = 1;
        break;
      }
      tyl += 100;
      tyr += 100;
      sgn = !sgn;
      chk = 0;
    }
    if (!chk) ans = max(ans, res);
  }
  pyl = hl;
  pyr = hr;
  rlen = hr;
  for (int i = 1; i <= n; ++i) {
    long long tyl = 0, tyr = 0;
    long long res = 0, cnt[2] = {1, 1};
    bool sgn = 1, chk = 0;
    pyr -= 2 * rlen;
    rlen = 100 - rlen;
    for (int j = 1; j <= i; ++j) {
      long long S1, S2;
      S1 = abs(tyl - pyl);
      S2 = abs(tyr - pyr) + S1;
      S1 *= 100000;
      while (cnt[sgn] <= t[sgn]) {
        if (S1 < inp[sgn][cnt[sgn]].x * S2) break;
        if (S1 <= inp[sgn][cnt[sgn]].y * S2) {
          res += inp[sgn][cnt[sgn]].v;
          cnt[sgn]++;
          chk = 1;
          break;
        }
        ++cnt[sgn];
      }
      if (!chk) {
        chk = 1;
        break;
      }
      tyl -= 100;
      tyr -= 100;
      sgn = !sgn;
      chk = 0;
    }
    if (!chk) ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Generate a cpp solution to the following problem:

Mirror Box is a name of a popular game in the Iranian National Amusement Park (INAP). There is a wooden box, 105 cm long and 100 cm high in this game. Some parts of the box's ceiling and floor are covered by mirrors. There are two negligibly small holes in the opposite sides of the box at heights hl and hr centimeters above the floor. The picture below shows what the box looks like.

<image>

In the game, you will be given a laser gun to shoot once. The laser beam must enter from one hole and exit from the other one. Each mirror has a preset number vi, which shows the number of points players gain if their laser beam hits that mirror. Also — to make things even funnier — the beam must not hit any mirror more than once.

Given the information about the box, your task is to find the maximum score a player may gain. Please note that the reflection obeys the law "the angle of incidence equals the angle of reflection".

Input

The first line of the input contains three space-separated integers hl, hr, n (0 < hl, hr < 100, 0 ≤ n ≤ 100) — the heights of the holes and the number of the mirrors.

Next n lines contain the descriptions of the mirrors. The i-th line contains space-separated vi, ci, ai, bi; the integer vi (1 ≤ vi ≤ 1000) is the score for the i-th mirror; the character ci denotes i-th mirror's position — the mirror is on the ceiling if ci equals "T" and on the floor if ci equals "F"; integers ai and bi (0 ≤ ai < bi ≤ 105) represent the x-coordinates of the beginning and the end of the mirror.

No two mirrors will share a common point. Consider that the x coordinate increases in the direction from left to right, so the border with the hole at height hl has the x coordinate equal to 0 and the border with the hole at height hr has the x coordinate equal to 105.

Output

The only line of output should contain a single integer — the maximum possible score a player could gain.

Examples

Input

50 50 7
10 F 1 80000
20 T 1 80000
30 T 81000 82000
40 T 83000 84000
50 T 85000 86000
60 T 87000 88000
70 F 81000 89000


Output

100


Input

80 72 9
15 T 8210 15679
10 F 11940 22399
50 T 30600 44789
50 F 32090 36579
5 F 45520 48519
120 F 49250 55229
8 F 59700 80609
35 T 61940 64939
2 T 92540 97769


Output

120

Note

The second sample is depicted above. The red beam gets 10 + 50 + 5 + 35 + 8 + 2 = 110 points and the blue one gets 120.

The red beam on the picture given in the statement shows how the laser beam can go approximately, this is just illustration how the laser beam can gain score. So for the second sample there is no such beam that gain score 110.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
struct pnt {
  long long x, y, v;
  pnt() { x = y = v = 1e9; }
} inp[2][120];
long long hl, hr, n, t[2], ans;
long long pxl, pyl, pxr = 1e5, pyr, rlen;
bool fun(pnt a, pnt b) { return a.x <= b.x; }
int main() {
  ios_base::sync_with_stdio(false);
  cin >> hl >> hr >> n;
  for (long long i = 1, v, x, y; i <= n; ++i) {
    char s;
    cin >> v >> s >> x >> y;
    t[!(s - 'F')]++;
    inp[!(s - 'F')][t[!(s - 'F')]].v = v;
    inp[!(s - 'F')][t[!(s - 'F')]].x = x;
    inp[!(s - 'F')][t[!(s - 'F')]].y = y;
  }
  sort(inp[0] + 1, inp[0] + t[0] + 1, fun);
  sort(inp[1] + 1, inp[1] + t[1] + 1, fun);
  if (!t[0] or !t[1]) {
    cout << 0 << endl;
    return 0;
  }
  pyl = hl;
  pyr = hr;
  rlen = hr;
  for (long long i = 1; i <= n; ++i) {
    long long tyl = 100, tyr = 100;
    long long res = 0, cnt[2] = {1, 1};
    rlen = 100 - rlen;
    pyr += 2 * rlen;
    bool chk = 0, sgn = 0;
    for (long long j = 1; j <= i; ++j) {
      long long S1, S2;
      S1 = abs(tyl - pyl);
      S2 = abs(tyr - pyr) + S1;
      S1 *= 100000;
      while (cnt[sgn] <= t[sgn]) {
        if (S1 < inp[sgn][cnt[sgn]].x * S2) break;
        if (S1 <= inp[sgn][cnt[sgn]].y * S2) {
          res += inp[sgn][cnt[sgn]].v;
          ++cnt[sgn];
          chk = 1;
          break;
        }
        ++cnt[sgn];
      }
      if (!chk) {
        chk = 1;
        break;
      }
      tyl += 100;
      tyr += 100;
      sgn = !sgn;
      chk = 0;
    }
    if (!chk) ans = max(ans, res);
  }
  pyl = hl;
  pyr = hr;
  rlen = hr;
  for (int i = 1; i <= n; ++i) {
    long long tyl = 0, tyr = 0;
    long long res = 0, cnt[2] = {1, 1};
    bool sgn = 1, chk = 0;
    pyr -= 2 * rlen;
    rlen = 100 - rlen;
    for (int j = 1; j <= i; ++j) {
      long long S1, S2;
      S1 = abs(tyl - pyl);
      S2 = abs(tyr - pyr) + S1;
      S1 *= 100000;
      while (cnt[sgn] <= t[sgn]) {
        if (S1 < inp[sgn][cnt[sgn]].x * S2) break;
        if (S1 <= inp[sgn][cnt[sgn]].y * S2) {
          res += inp[sgn][cnt[sgn]].v;
          cnt[sgn]++;
          chk = 1;
          break;
        }
        ++cnt[sgn];
      }
      if (!chk) {
        chk = 1;
        break;
      }
      tyl -= 100;
      tyr -= 100;
      sgn = !sgn;
      chk = 0;
    }
    if (!chk) ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}

```