malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k;     cin >> n >> k;     string s;     cin >> s;     bool arr[26] = {false};     for (int i = 0; i < k; i++) {       char c;       cin >> c;       arr[c -  a ] = true;     }     long long ans = 0;     long long co = 0;     for (int i = 0; i < n; i++) {       int x;       x = s[i] -  a ;       if (arr[s[i] -  a ] == true)         co++;       else {         ans += (co * (co + 1)) / 2;         co = 0;       }     }     ans += (co * (co + 1)) / 2;     cout << ans;   }
#include <bits/stdc++.h>   inline int gi() {     int x = 0, f = 1;     char ch = getchar();     while (!isdigit(ch)) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while (isdigit(ch)) x = x * 10 + ch -  0 , ch = getchar();     return x * f;   }   std::set<std::pair<int, int> > M;   struct yyb {     int x, y, i;     long double k, b;   } s[300010], stk[300010];   inline bool cmp_k(const yyb& a, const yyb& b) {     if (a.y != b.y)       return a.y < b.y;     else       return a.x > b.x;   }   inline bool cmp_i(const yyb& a, const yyb& b) { return a.i < b.i; }   int main() {     int n = gi();     for (int i = 1; i <= n; ++i)       s[i].x = gi(), s[i].y = gi(), s[i].i = i, s[i].k = 1000000000.0 / s[i].y,       s[i].b = 1000000000.0 / s[i].x;     std::sort(s + 1, s + n + 1, cmp_k);     int top = 0;     stk[++top] = (yyb){0, 0, 0, 1e18, 0};     for (int i = 1; i <= n; ++i) {       if (s[i].y == s[i - 1].y) continue;       while (top > 1 && stk[top].y != stk[top - 1].y &&              (-(s[i].b - stk[top].b) / (s[i].k - stk[top].k) + 1e-15 <               -(stk[top].b - stk[top - 1].b) / (stk[top].k - stk[top - 1].k))) {         --top;       }       stk[++top] = s[i];     }     std::sort(s + 1, s + n + 1, cmp_i);     for (int i = 1; i <= top; ++i) M.insert(std::make_pair(stk[i].x, stk[i].y));     for (int i = 1; i <= n; ++i)       if (M.find(std::make_pair(s[i].x, s[i].y)) != M.end()) printf( %d  , i);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2e6 + 1;   const int INF = 2e9 + 1;   const int MOD = (1e9 + 7);   void bye(string s =   ) {     cout << s <<   n ;     exit(0);   }   signed main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     int t = 1;     cin >> t;     while (t--) {       int n;       cin >> n;       vector<int> arr(2);       for (int i = 0; i < n; i++) {         int a;         cin >> a;         arr[a % 2]++;       }       if (arr[1] % 2 || (arr[1] && arr[0])) {         cout <<  YES n ;       } else {         cout <<  NO n ;       }     }     bye();   }
#include <bits/stdc++.h>   using namespace std;   const bool debug = false;   const int maxn = 1002003;   const long long magic = 1000 * 1000 * 1000 + 7;   int n, k;   long long aa[maxn];   struct RMQ {     int l, r;     RMQ *left, *right;     long long res;     int resIndex;   };   RMQ* build(long long* vs, int l, int r) {     RMQ* res = new RMQ();     res->l = l;     res->r = r;     if (r - l >= 2) {       int m = (l + r) / 2;       res->left = build(vs, l, m);       res->right = build(vs, m, r);       if (res->left->res >= res->right->res) {         res->res = res->left->res;         res->resIndex = res->left->resIndex;       } else {         res->res = res->right->res;         res->resIndex = res->right->resIndex;       }     } else {       res->left = nullptr;       res->right = nullptr;       res->res = vs[l];       res->resIndex = l;     }     return res;   }   pair<long long, int> rmqGet(RMQ* q, int l, int r) {     if (q->r <= l || r <= q->l) return make_pair(-100, -1);     if (l <= q->l && q->r <= r) return make_pair(q->res, q->resIndex);     auto [res1, res1index] = rmqGet(q->left, l, r);     auto [res2, res2index] = rmqGet(q->right, l, r);     if (res1 >= res2)       return make_pair(res1, res1index);     else       return make_pair(res2, res2index);   }   int ls[maxn];   int rs[maxn];   RMQ* rmq;   void findLR(int l, int r) {     if (debug) cout <<  findLR:   << l <<     << r << endl;     if (r - l < 2) return;     auto [res, resIndex] = rmqGet(rmq, l + 1, r);     if (debug)       cout <<  rmqGet:   << (l + 1) <<     << r <<     << res <<     << resIndex            << endl;     ls[resIndex] = l;     rs[resIndex] = r;     findLR(l, resIndex);     findLR(resIndex, r);   }   long long countLen(int len) {     if (len < k) return 0;     int rest = len - k;     long long count = rest / (k - 1);     long long res =         (len + 1) * (count + 1) - (count + 1) * (k + k + count * (k - 1)) / 2;     return res;   }   long long countIndex(int i) {     int len = rs[i] - (ls[i] + 1);     long long res =         countLen(len) - countLen(i - (ls[i] + 1)) - countLen(rs[i] - (i + 1));     if (debug) cout <<  countIndex:   << i <<     << res << endl;     return res;   }   int main() {     ios::sync_with_stdio(false);     cin >> n >> k;     for (int i = 1; i <= n; i++) cin >> aa[i];     aa[0] = aa[n + 1] = 1200ll * 1000 * 1000;     rmq = build(aa, 0, n + 2);     findLR(0, n + 1);     if (debug)       for (int i = 1; i <= n; i++) cout << ls[i] <<     << rs[i] << endl;     long long res = 0;     for (int i = 1; i <= n; i++) {       long long c = countIndex(i) % magic;       res = (res + aa[i] * c) % magic;     }     cout << res << endl;     if (debug)       for (int i = 0; i <= 20; i++)         cout <<  len:   << i <<  :   << countLen(i) << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 2e5 + 5;   int n, k, size[maxn];   bool f[maxn];   long long dp[maxn];   vector<int> g[maxn];   void dfs(int u, int fa) {     if (f[u])       size[u] = 1;     else       size[u] = 0;     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == fa) continue;       dfs(v, u);       size[u] += size[v];       dp[u] += dp[v] + size[v];     }   }   long long ans = 0;   int solve(int u, int fa) {     int sum = (f[u] ? 1 : 0);     for (int i = 0; i < g[u].size(); i++) {       int v = g[u][i];       if (v == fa) continue;       sum += solve(v, u);     }     ans += min(sum, 2 * k - size[u]);     return min(sum, 2 * k - size[u]);   }   int main() {     scanf( %d%d , &n, &k);     int x;     for (int i = 1; i <= 2 * k; i++) scanf( %d , &x), f[x] = 1;     int u, v;     for (int i = 1; i <= n - 1; i++)       scanf( %d%d , &u, &v), g[u].push_back(v), g[v].push_back(u);     dfs(1, -1);     solve(1, -1);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     vector<int> c(n);     bool d[2];     for (int i = 0; i < n; i++) {       cin >> c[i];       d[c[i] % 2] = 1;     }     if (d[0] && d[1]) {       sort(c.begin(), c.end());     }     for (int i : c) {       cout << i <<    ;     }     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   const int MAX = 5e5 + 5;   const long long MAX2 = 11;   const long long MOD = 1000000007;   const long long MOD2 = 1000000006;   const long long INF = 2e18;   const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};   const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};   const double pi = acos(-1);   const double EPS = 1e-9;   const int block = 2000;   int n, id, a, b;   vector<int> v[MAX], ans[MAX];   void dfs(int nw, int par) {     for (auto i : v[nw]) {       if (i == par) continue;       ans[i].push_back(++id);     }     ans[nw].push_back(++id);     reverse(v[nw].begin(), v[nw].end());     for (auto i : v[nw]) {       if (i == par) continue;       dfs(i, nw);     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n;     for (int i = 2; i <= n; ++i)       cin >> a >> b, v[a].push_back(b), v[b].push_back(a);     ans[1].push_back(++id);     dfs(1, 0);     for (int i = 1; i <= n; ++i) cout << ans[i][0] <<     << ans[i][1] <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1000000007;   const vector<int> mods = {998244353, 1000000007, 1000000009};   const long long inf = 3e18;   const double pi = acos(-1.0);   const double eps = 0.0000001;   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   template <class... K>   using umap = unordered_map<K...>;   template <class... K>   using uset = unordered_set<K...>;   double dp[200];   long long lad[200];   int main() {     cin.sync_with_stdio(0);     cin.tie(0);     cout.precision(13);     fill(&dp[0], &dp[0] + sizeof(dp) / sizeof(dp[0]), 0);     for (long long i = (0); i < (10); ++i)       for (long long j = (0); j < (10); ++j) {         long long fw = i & 1;         long long up;         cin >> up;         if (!up) continue;         long long node = 10 * (9 - i) + (fw ? j : 9 - j);         long long nxfw = (i + up) & 1;         long long nx = 10 * (9 - i + up) + (nxfw ? j : 9 - j);         lad[node] = nx;       }     dp[99] = 0.0;     for (long long i = 98; i >= 0; i--) {       double mv = 0;       double ex = 0;       for (long long j = (1); j < (7); ++j) {         double nx = dp[i + j];         if (lad[i + j]) {           nx = min(nx, dp[lad[i + j]]);         }         mv += 1.0 / 6 * nx;         if (i + j > 99) ex++;       }       mv++;       mv /= (1 - ex / 6.0);       dp[i] = mv;     }     cout << dp[0] <<   n ;     return 0;   }
#include <iostream>   #include <unordered_map>   #include <list>   #include <queue>   #include <string.h>   #include <stack>   #include <set>   #include <unordered_set>   #include <map>   #include <climits>   #include <algorithm>   #include <math.h>   #include <vector>   #include <iomanip>   #include <ctype.h>   using namespace std;   #define ll long long int   const int MOD = 1e9 + 7;   ll facto[200010];   void fact()   {       facto[0] = 1;       for (ll i = 1; i < 200010; i++)       {           facto[i] = (i * facto[i - 1]) % MOD;       }   }   bool is(ll cnt[])   {       for (int i = 0; i < 26; i++)       {           if (cnt[i] >= 2)               return false;       }       return true;   }   int main()   {       // fact();       ios_base::sync_with_stdio(false);       cin.tie(NULL);       ll n;       cin >> n;       ll a[n];       ll sum = 0;       for (ll i = 0; i < n; i++)       {           cin >> a[i];           sum += a[i];       }       if ((sum % 2) != 0)       {           cout <<  0  n ;           return 0;       }       bool dp[n + 1][sum / 2 + 1];       for (ll i = 0; i <= n; i++)       {           for (ll j = 0; j <= sum / 2; j++)           {               dp[i][j] = false;           }       }       for (ll i = 0; i <= n; i++)       {           dp[i][0] = true;       }       for (ll j = 0; j <= sum / 2; j++)       {           dp[0][j] = false;       }       for (ll i = 1; i <= n; i++)       {           for (ll j = 1; j <= sum / 2; j++)           {               dp[i][j] = dp[i - 1][j];               if (j - a[i - 1] >= 0)               {                   dp[i][j] = dp[i][j] || dp[i - 1][j - a[i - 1]];               }           }       }       if (dp[n][sum / 2] == false)       {           cout <<  0  n ;           return 0;       }       ll mini = LLONG_MAX;       ll pos = -1;       for (ll i = 0; i < n; i++)       {           if (a[i] % 2)           {               cout <<  1  n ;               cout << i + 1 <<   n ;               return 0;           }       }       for (ll i = 0; i < n; i++)       {           ll steps = 0;           while (a[i] % 2 == 0)           {               a[i] /= 2;               steps++;           }           if (mini > steps)           {               mini = steps;               pos = i;           }       }       cout <<  1  n ;       cout << pos + 1 <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 2000;   int n, t;   double p, dp[MAXN + 1][MAXN + 1], ans = 0;   int main() {     cin >> n >> p >> t;     dp[0][0] = 1;     for (int i = 0; i < t; i++)       for (int j = 0; j <= n; j++) {         if (j < n) {           dp[i + 1][j + 1] += dp[i][j] * p;           dp[i + 1][j] += dp[i][j] * (1 - p);         } else           dp[i + 1][j] += dp[i][j];       }     for (int i = 1; i <= n; i++) ans += dp[t][i] * i;     cout << fixed;     cout << setprecision(9) << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long q_pow(long long n, long long temp) {     long long ans = 1;     long long x = temp;     while (n) {       if (n & 1) {         ans *= x;         ans %= 1000000007;       }       x *= x;       x %= 1000000007;       n /= 2;     }     return ans;   }   int main() {     string str;     long long k;     while (cin >> str >> k) {       int len = str.size();       long long sum = 0;       for (int i = 0; i < len; i++) {         if (str[i] ==  0  || str[i] ==  5 ) {           long long a1 = q_pow(i, 2);           sum += a1;           sum %= 1000000007;         }       }       long long a = (q_pow(len * k, 2) - 1 + 1000000007) % 1000000007;       long long b = (q_pow(len, 2) - 1 + 1000000007) % 1000000007;       long long c = (a * q_pow(1000000007 - 2, b)) % 1000000007;       printf( %I64d n , (sum * c) % 1000000007);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct info {     int id, d;     bool operator<(const info &rhs) const { return d < rhs.d; }   } a[200007];   vector<pair<int, int> > res;   priority_queue<info> q;   stack<info> st;   int main() {     int n, m;     int k = 0;     int M = 0;     scanf( %d%d , &n, &m);     for (int i = 1, v; i <= n; i++) {       scanf( %d , &v);       if (v == 0) continue;       M = max(M, v);       a[i] = {i, v};       q.push(a[i]);       k++;     }     if (M >= k) {       puts( No );       return 0;     }     while (!q.empty()) {       info x = q.top();       q.pop();       if (x.d != a[x.id].d) continue;       while (x.d--) {         info g;         if (q.empty()) {           puts( No );           return 0;         }         while (!q.empty()) {           g = q.top();           q.pop();           if (g.d == a[g.id].d) break;         }         g.d--;         a[g.id].d--;         res.push_back({g.id, x.id});         if (g.d != 0) st.push(g);       }       a[x.id].d = 0;       while (!st.empty()) {         q.push(st.top());         st.pop();       }     }     puts( Yes );     if (res.size() != 0) printf( %d n , (int)res.size());     for (auto e : res) printf( %d %d n , e.first, e.second);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   double dist(double x1, double y1, double x2, double y2) {     return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));   }   int main() {     double r, x1, y1, x2, y2;     cin >> r >> x1 >> y1 >> x2 >> y2;     if (dist(x1, y1, x2, y2) >= r) {       printf( %.12f %.12f %.12f n , x1, y1, r);     } else if (x1 == x2 && y1 == y2) {       double r1 = r / 2.0;       double x3 = x1 - r1;       double y3 = y1;       printf( %.12f %.12f %.12f n , x3, y3, r1);     } else {       double r1 = (dist(x1, y1, x2, y2) + r) / 2.0;       double d1 = dist(x1, y1, x2, y2);       double d2 = r1 - d1;       double alpha1 = d1 / (d1 + d2);       double alpha2 = d2 / (d1 + d2);       double x3 = (x1 - alpha2 * x2) / alpha1;       double y3 = (y1 - alpha2 * y2) / alpha1;       printf( %.12f %.12f %.12f n , x3, y3, r1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     ;     int t, n, i;     cin >> n;     int a[n];     for (i = 0; i < n; i++) cin >> a[i];     long long int ans = 0;     long long int pre[n + 1];     memset(pre, 0, sizeof(pre));     for (i = 1; i < n + 1; i++) pre[i] = pre[i - 1] + a[i - 1];     set<long long int> s;     int start = -1;     for (i = 0; i < n; i++) {       if (start < i) {         start = i;         s.insert(pre[i]);       }       while (start < n && !s.count(pre[start + 1])) {         start++;         s.insert(pre[start]);       }       s.erase(pre[i]);       ans += start - i;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int dx[] = {0, -1, 0, 1};   int dy[] = {-1, 0, 1, 0};   char a[505][505];   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i] + 1;     bool flag = 1;     for (int i = 1; i <= n; i++)       for (int j = 1; j <= m; j++) {         for (int k = 0; k <= 3; k++) {           if (a[i + dx[k]][j + dy[k]] ==  S  && a[i][j] ==  W ) flag = 0;           if (a[i + dx[k]][j + dy[k]] ==  W  && a[i][j] ==  S ) flag = 0;         }         if (a[i][j] !=  W  && a[i][j] !=  S ) a[i][j] =  D ;       }     if (flag == 0) {       cout <<  No  << endl;     } else {       cout <<  Yes  << endl;       for (int i = 1; i <= n; i++) {         for (int j = 1; j <= m; j++) {           cout << a[i][j];         }         cout << endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000010;   int fa[N], mx[N], n;   vector<int> son[N];   vector<int> ans;   bool cmp(const int x, const int y) { return mx[x] < mx[y]; }   void dfs(int x) {     int s = son[x].size();     for (int i = 0; i < s; ++i) {       int& sn = son[x][i];       dfs(sn);       mx[x] = max(mx[x], mx[sn] + 1);     }     sort(son[x].begin(), son[x].end(), cmp);   }   void DFS(int x) {     printf( %d  , x);     for (int i = 0; i < son[x].size(); ++i) {       int& sn = son[x][i];       DFS(sn);       if (i == 0) continue;       for (int j = 0; j <= mx[son[x][i - 1]]; ++j) ans.push_back(sn);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       scanf( %d , &fa[i]);       son[fa[i]].push_back(i);     }     dfs(0);     DFS(0);     int s = ans.size();     printf(  n%d n , s);     for (int i = 0; i < s; ++i) printf( %d  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using db = long double;   using str = string;   using pi = pair<int, int>;   template <class T>   using V = vector<T>;   template <class T, size_t SZ>   using AR = array<T, SZ>;   using vi = V<int>;   using vb = V<bool>;   using vpi = V<pi>;   const int MOD = 1e9 + 7;   const db PI = acos((db)-1);   mt19937 rng(0);   template <class T>   bool ckmin(T& a, const T& b) {     return b < a ? a = b, 1 : 0;   }   template <class T>   bool ckmax(T& a, const T& b) {     return a < b ? a = b, 1 : 0;   }   template <class T, class U>   T fstTrue(T lo, T hi, U first) {     ++hi;     assert(lo <= hi);     while (lo < hi) {       T mid = lo + (hi - lo) / 2;       first(mid) ? hi = mid : lo = mid + 1;     }     return lo;   }   using T = db;   const T EPS = 1e-9;   using P = pair<T, T>;   using vP = V<P>;   using Line = pair<P, P>;   int sgn(T a) { return (a > EPS) - (a < -EPS); }   T sq(T a) { return a * a; }   T norm(P p) { return sq(p.first) + sq(p.second); }   T abs(P p) { return sqrt(norm(p)); }   T arg(P p) { return atan2(p.second, p.first); }   P conj(P p) { return P(p.first, -p.second); }   P perp(P p) { return P(-p.second, p.first); }   P dir(T ang) { return P(cos(ang), sin(ang)); }   const int mx = 100005;   struct Eff {     int n, k;     P hab[mx];     bool works(db r) {       V<pair<db, int>> ch;       for (int i = 1; i <= n; i++) {         if (abs(hab[i]) <= 2.0 * r - EPS) {           db theta_diff = PI / 2.0 - asin(abs(hab[i]) / 2.0 / r);           db theta = arg(hab[i]);           assert(theta_diff <= PI / 2.0);           ch.push_back(make_pair(theta - theta_diff, +1));           ch.push_back(make_pair(theta + theta_diff, -1));           ch.push_back(make_pair(theta - theta_diff + 2 * PI, +1));           ch.push_back(make_pair(theta + theta_diff + 2 * PI, -1));         }       }       sort(begin(ch), end(ch));       int running_sum = 0;       for (auto u : ch) {         running_sum += u.second;         if (0 <= u.first && u.first <= 2 * PI) {           if (running_sum >= k) return true;         }       }       return false;     }     void solve() {       cin >> n >> k;       for (int i = 1; i <= n; i++) {         cin >> hab[i].first >> hab[i].second;       }       db lo = EPS;       db hi = 200005.0;       for (int i = 0; i < 50; i++) {         db mid = (lo + hi) / 2;         if (works(mid)) {           hi = mid;         } else {           lo = mid;         }       }       cout << lo <<   n ;     }   };   int main() {     cin.tie(0)->sync_with_stdio(0);     cout << fixed << setprecision(10);     Eff e;     e.solve();   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   ostream &operator<<(ostream &os, vector<T> V) {     os <<  [  ;     for (auto v : V) os << v <<    ;     os <<  ] ;     return os;   }   template <class T>   ostream &operator<<(ostream &os, set<T> S) {     os <<  {  ;     for (auto s : S) os << s <<    ;     return os <<  } ;   }   template <class L, class R>   ostream &operator<<(ostream &os, pair<L, R> P) {     return os <<  (  << P.first <<  ,  << P.second <<  ) ;   }   template <class L, class R>   ostream &operator<<(ostream &os, map<L, R> M) {     os <<  {  ;     for (auto m : M) os <<  (  << m.first <<  :  << m.second <<  )  ;     return os <<  } ;   }   long long n, a[200005], c[200005], cc[200005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long t;     cin >> t;     while (t--) {       cin >> n;       for (long long i = 1; i < n + 1; i++) cin >> a[i];       for (long long i = 1; i < n + 1; i++) {         long long k = 1;         if (c[i - 1] == 1) k = 2;         long long j = i;         while (j <= n && a[j] == a[i]) c[j] = k, j++;         i = j - 1;       }       if (c[1] == c[n] && a[1] != a[n]) {         bool ok = false;         for (long long i = 1; i < n; i++) {           if (c[i] == c[i + 1]) {             for (long long j = i + 1; j < n + 1; j++) {               if (c[j] == 1)                 c[j] = 2;               else                 c[j] = 1;             }             ok = true;             break;           }         }         if (!ok) c[n] = 3;       }       long long mx = 0;       for (long long i = 1; i < n + 1; i++) mx = max(mx, c[i]);       cout << mx <<   n ;       for (long long i = 1; i < n + 1; i++) cout << c[i] <<    ;       cout <<   n ;     }     return 0;   }
#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;   }