#include <bits/stdc++.h>   using namespace std;   int h1, h2, n;   int v[111];   char c[111];   int a[111];   int b[111];   const double eps = 1e-9;   int main() {     cin >> h1 >> h2 >> n;     for (int i = (0); i < (n); i++) cin >> v[i] >> c[i] >> a[i] >> b[i];     int best = 0;     for (int i = -200; i <= 200; i++) {       bool good = 1;       int sum = 0;       set<int> used;       int x1 = 0;       int y1 = h1;       int x2 = 100000;       int y2 = h2 + i * 100;       if (i % 2) y2 = 100 - h2 + i * 100;       if (i > 0) {         for (int j = (0); j < (i); j++) {           int y = 100 + 100 * j;           double x = double(x2 - x1) / (y2 - y1) * (y - y1);           bool found = 0;           for (int k = (0); k < (n); k++)             if (a[k] <= x + eps && b[k] >= x - eps) {               if (j % 2 == 0 && c[k] ==  T  || j % 2 == 1 && c[k] ==  F ) {                 if (used.count(k)) good = 0;                 used.insert(k);                 sum += v[k];                 found = 1;                 break;               }             }           if (!found) good = 0;         }       } else if (i < 0) {         for (int j = (0); j < (-i); j++) {           int y = -100 * j;           double x = double(x2 - x1) / double(y2 - y1) * (y - y1);           bool found = 0;           for (int k = (0); k < (n); k++)             if (a[k] <= x + eps && b[k] >= x - eps) {               if (j % 2 == 0 && c[k] ==  F  || j % 2 == 1 && c[k] ==  T ) {                 if (used.count(k)) good = 0;                 used.insert(k);                 sum += v[k];                 found = 1;                 break;               }             }           if (!found) good = 0;         }       }       if (good) best = max(best, sum);     }     cout << best << endl;     return 0;   }   