malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   void read_to_vector(size_t N, std::vector<T> &v) {     for (size_t i = 0; i < N; i++) {       T tmp;       std::cin >> tmp;       v.push_back(tmp);     }   }   template <typename T>   void print_vector(const std::vector<T> &v) {     for (auto it = v.begin(); it < v.end(); it++) {       if (it != v.begin()) std::cout <<    ;       std::cout << (*it);     }   }   string getpre(string s0, string s1) {     string res;     for (int i = 0; i < s0.size() && i < s1.size(); i++) {       if (s0[i] == s1[i]) {         res += s0[i];       } else {         break;       }     }     return res;   }   string getpre(vector<string> &ss) {     if (ss.size() == 0) {       return   ;     }     string smin = ss[0];     string smax = ss[0];     for (int i = 0; i < ss.size(); i++) {       smin = min(ss[i], smin);       smax = max(ss[i], smax);     }     return getpre(smin, smax);   }   void solve() {     long long n;     cin >> n;     vector<string> w0, w1;     read_to_vector(n, w0);     read_to_vector(n, w1);     vector<int> ch0(n, -1), ch1(n, -1);     string chans0;     string chans1;     for (int i = 0; i < n; i++) {       for (int j = 0; j < w0[i].size(); j++) {         if (w0[i][j] != w1[i][j]) {           if (ch0[i] == -1) {             ch0[i] = j;           }           ch1[i] = j;         }       }       ch1[i]++;       if (ch0[i] != -1) {         chans0 = w0[i].substr(ch0[i], ch1[i] - ch0[i]);         chans1 = w1[i].substr(ch0[i], ch1[i] - ch0[i]);       }     }     vector<string> prefs;     vector<string> posts;     for (int i = 0; i < n; i++) {       if (ch0[i] == -1) {         continue;       }       string pre = w0[i].substr(0, ch0[i]);       reverse(pre.begin(), pre.end());       string post = w0[i].substr(ch1[i], w0[i].size() - ch1[i]);       prefs.push_back(pre);       posts.push_back(post);     }     string pre = getpre(prefs);     reverse(pre.begin(), pre.end());     string post = getpre(posts);     string rep0 = pre + chans0 + post;     string rep1 = pre + chans1 + post;     bool test = true;     for (int i = 0; i < n; i++) {       string w = w0[i];       string wend = w;       int ind = w.find(rep0);       if (ind != string::npos) {         wend = w.substr(0, ind) + rep1 +                w.substr(ind + rep1.size(), w.size() - (ind + rep1.size()));       }       test &= (wend == w1[i]);     }     if (test) {       cout <<  YES n  << rep0 <<   n  << rep1 <<   n ;     } else {       cout <<  NO n ;     }   }   void pre_compute() {}   int main() {     std::cout << std::setprecision(15);     std::ios::sync_with_stdio(false);     std::cin.tie(0);     pre_compute();     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, v = 0, p = 0;     string s, result =   ;     cin >> n >> s;     v = (n - 11) / 2;     p = v;     for (int i = 0; i < n; i++) {       if (s[i] ==  8 ) {         if (v > 0)           v--;         else           result += s[i];       } else {         if (p > 0)           p--;         else           result += s[i];       }     }     if (result[0] ==  8 )       cout <<  YES  << endl;     else       cout <<  NO  << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int arr[510];   int dp[510][510];   int main() {     int n;     scanf( %d , &n);     for (int i = 0; i <= n - 1; i++) scanf( %d , &arr[i]);     for (int l = 1; l <= n; l++) {       for (int i = 0; i <= n - 1; i++) {         int j = i + l - 1;         if (j > n - 1) continue;         if (i == j) {           dp[i][j] = 1;           continue;         }         dp[i][j] = dp[i + 1][j] + 1;         for (int k = i + 2; k <= j; k++)           if (arr[k] == arr[i])             dp[i][j] = min(dp[i][j], dp[i + 1][k - 1] + dp[k + 1][j]);         if (i < n - 1 && arr[i + 1] == arr[i])           dp[i][j] = min(dp[i][j], dp[i + 2][j] + 1);       }     }     cout << dp[0][n - 1] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void mego() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   bool isp(long long x) {     for (long long i = 2; i * i <= x; i++)       if (!(x % i)) return false;     return true;   }   long long coun = 0;   int gcd(long long a, long long b) {     if (b == 0) return a;     coun += (a / b);     return gcd(b, a % b);   }   int main() {     mego();     long long n, a, z = 0, b = 0, d = 0, c = 0;     vector<long long> v, v1;     long long t = 0;     cin >> t;     map<int, pair<int, int> > ma;     for (int i = 1; i <= t; i++) {       cin >> a;       if (!ma[a].first) {         ma[a].first = i;       } else if (!ma[a].second)         ma[a].second = i;       else {         if ((i - ma[a].second) != (ma[a].second - ma[a].first)) {           ma[a].first = -1;           ma[a].second = -1;         } else {           ma[a].first = ma[a].second;           ma[a].second = i;         }       }     }     vector<pair<int, int> > vp;     pair<int, int> rej = {-1, -1};     for (auto it : ma) {       if (it.second != rej) {         vp.push_back(make_pair(it.first, it.second.second - it.second.first));       }     }     cout << vp.size() <<   n ;     for (int i = 0; i < vp.size(); i++) {       cout << vp[i].first <<     << (vp[i].second > 0 ? vp[i].second : 0) <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long n, k;     cin >> n >> k;     string second;     cin >> second;     vector<long long> cnt(k, 0);     for (long long i = 0; i < n; i++) {       cnt[second[i] -  A ]++;     }     long long ans = cnt[0];     for (long long i = 0; i < k; i++) {       ans = min(ans, cnt[i]);     }     cout << ans * k << endl;   }   signed main() {     long long n = 1;     while (n--) {       solve();     }   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 21;   int cnt, u;   int sz[1 << MAXN], g[1 << MAXN], p[1 << MAXN];   long long int f[1 << MAXN], h[1 << MAXN];   inline long long int read() {     register long long int num = 0, neg = 1;     register char ch = getchar();     while (!isdigit(ch) && ch !=  - ) {       ch = getchar();     }     if (ch ==  - ) {       neg = -1;       ch = getchar();     }     while (isdigit(ch)) {       num = (num << 3) + (num << 1) + (ch -  0 );       ch = getchar();     }     return num * neg;   }   int main() {     cnt = read();     for (register int i = 0; i < cnt; i++) {       if (!(f[i] = read())) {         i--, cnt--;       }     }     for (register int i = 1; i < (1 << cnt); i++) {       sz[i] = sz[i >> 1] + (i & 1);       for (register int j = 0; j < cnt; j++) {         if ((i >> j) & 1) {           h[i] += f[j];         }       }       if ((h[i] + sz[i] & 1)) {         for (register int j = i; (j = ((j - 1) & i)) && !p[i];) {           if (h[i] - sz[i] + 1 <= 2 * h[j] && 2 * h[j] <= h[i] + sz[i] - 1) {             p[i] = 1;           }         }       }     }     for (register int i = 1; i < (1 << cnt); i++) {       if (p[i] && !g[i]) {         g[i] = 1, u = (1 << cnt) - i - 1;         for (register int j = u; j; j = (j - 1) & u) {           g[i | j] = max(g[i | j], g[j] + 1);         }       }     }     printf( %d n , cnt - g[(1 << cnt) - 1]);   }
#include <bits/stdc++.h>   using namespace std;   const long long NMAX = 300000 + 5;   const long long inf = 922337203685477580LL;   vector<vector<pair<long long, long long> > > g(NMAX);   vector<vector<int> > id(NMAX);   long long dis[NMAX];   long long last[NMAX];   long long a[NMAX];   int main() {     int n, m;     cin >> n >> m;     long long ans = 0;     for (int i = 0; i < m; i++) {       int a, b, c;       cin >> a >> b >> c;       g[a].push_back({b, c});       g[b].push_back({a, c});       id[a].push_back(i);       id[b].push_back(i);     }     int s;     cin >> s;     for (int i = 1; i <= n; i++) dis[i] = inf;     dis[s] = 0;     for (int i = 1; i <= n; i++) last[i] = inf;     last[s] = 0;     set<pair<int, int> > q;     q.insert({0, s});     while (!q.empty()) {       int w = q.begin()->second;       q.erase(q.begin());       for (int i = 0; i < g[w].size(); i++) {         int to = g[w][i].first;         int len = g[w][i].second;         if (dis[w] + len < dis[to] ||             (dis[w] + len <= dis[to] && len < last[to])) {           q.erase(make_pair(dis[to], to));           dis[to] = dis[w] + len;           last[to] = len;           a[to] = id[w][i] + 1;           q.insert(make_pair(dis[to], to));         }       }     }     for (int i = 1; i <= n; i++) ans += last[i];     cout << ans << endl;     for (int i = 1; i <= n; i++) {       if (i != s) {         cout << a[i] <<    ;       }     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 5;   long long mod = 1e18;   long long fast_pow(long long b, long long p) {     if (p == 0) return 1;     long long m = fast_pow(b, p / 2);     m = ((m % mod) * (m % mod)) % mod;     if (p % 2 == 1) m = ((m % mod) * (b % mod)) % mod;     return m;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     pair<int, int> arr[N];     for (int i = 0; i < n; i++) {       cin >> arr[i].first;     }     for (int i = 0; i < n; i++) {       cin >> arr[i].second;     }     sort(arr, arr + n);     long long cu = 1;     priority_queue<long long> q;     long long sum = 0;     long long ans = 0;     for (long long i = 0; i < n; i++) {       if (q.empty()) cu = arr[i].first;       if (arr[i].first == cu) {         q.push(arr[i].second);         sum += arr[i].second;       } else {         sum -= q.top();         q.pop();         ans += sum;         while (q.size() && (++cu) < arr[i].first) {           sum -= q.top();           q.pop();           ans += sum;         }         i--;       }     }     while (q.size()) {       sum -= q.top();       q.pop();       ans += sum;     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, k, p, x, y;     int a[1010], b[1010];     int i, j;     while (scanf( %d%d%d%d%d , &n, &k, &p, &x, &y) != EOF) {       int sum = 0;       for (i = 0; i < k; i++) {         scanf( %d , &a[i]);         sum += a[i];       }       if (sum > x) {         puts( -1 );         continue;       }       for (i = k; i < n; i++) {         a[i] = 1;         sum += 1;       }       int t = k;       while (t < n && sum + y - 1 <= x) {         a[t++] = y;         sum += y - 1;       }       for (i = 0; i < n; i++) b[i] = a[i];       sort(b, b + n);       int m = b[n / 2];       if (sum <= x && m >= y) {         for (i = k; i < n - 1; i++) printf( %d  , a[i]);         printf( %d n , a[n - 1]);       } else         printf( -1 n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   map<int, int> mm;   map<int, int>::iterator it;   int x[100005];   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n;     cin >> n;     vector<int> v;     for (int i = 1; i <= n; i++) cin >> x[i];     for (int i = n; i >= 1; i--) {       if (mm[x[i]] == 0) {         mm[x[i]]++;         v.push_back(x[i]);       }     }     cout << endl;     cout << v.size() <<   n ;     for (int i = v.size() - 1; i >= 0; i--) {       cout << v[i] <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   pair<long double, long double> st[4 * N];   int n, q;   template <typename T>   pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) {     pair<T, T> res;     res.first = a.first + b.first * a.second;     res.second = a.second * b.second;     return res;   }   void update(int id, int l, int r, int pos, long double val) {     if (l > pos || r < pos) return;     if (l == r) {       st[id] = make_pair(val, val);       return;     }     int mid = (l + r) >> 1;     update(id << 1, l, mid, pos, val);     update(id << 1 | 1, mid + 1, r, pos, val);     st[id] = st[id << 1] + st[id << 1 | 1];   }   pair<long double, long double> getsum(int id, int l, int r, int u, int v) {     if (l > v || r < u) return make_pair(0, 1);     if (l >= u && r <= v) return st[id];     int mid = (l + r) >> 1;     pair<long double, long double> lnode = getsum(id << 1, l, mid, u, v);     pair<long double, long double> rnode = getsum(id << 1 | 1, mid + 1, r, u, v);     return lnode + rnode;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> q;     for (int i = 1; i <= n; i++) {       int a, b;       cin >> a >> b;       long double p = (long double)a / b;       update(1, 1, n, i, (1.0L - p) / p);     }     while (q--) {       int op;       cin >> op;       if (op == 1) {         int pos, a, b;         cin >> pos >> a >> b;         long double p = (long double)a / b;         update(1, 1, n, pos, (1.0L - p) / p);       } else {         int l, r;         cin >> l >> r;         long double res = 1 + getsum(1, 1, n, l, r).first;         long double ans = (1.0L / res);         if (ans != ans) ans = 0;         cout << fixed << setprecision(9) << ans <<   n ;       }     }     return 0;   }
#include <bits/stdc++.h>   namespace solution {   class ISolution {    public:     virtual void init(){};     virtual bool input() { return false; };     virtual void output(){};     virtual int run() = 0;   };   }  // namespace solution   namespace solution {}   namespace solution {   using namespace std;   const int SIZE = 1011;   const int MAX_TIME = 1000011;   int n;   int T[SIZE];   int C[SIZE];   long long X[MAX_TIME];   class Solution : public ISolution {    public:     bool input() {       if (!(cin >> n)) return false;       for (int i = 0; i < n; ++i) cin >> T[i] >> C[i];       return true;     }     void solve() {       fill(X, X + MAX_TIME, 0);       for (int i = 0; i < n; ++i) X[T[i]] += C[i];       long long t = 0;       long long res = 0;       long long sum = 0;       for (long long i = 0; i < MAX_TIME; ++i) {         if (sum > 0) {           t = max(t, i);           sum--;         }         sum += X[i];         res = max(res, sum);       }       if (sum) {         t += sum;       }       cout << t <<     << res << endl;     }     int run() {       while (init(), input()) {         solve();         output();       }       return 0;     }   };   }  // namespace solution   int main() { return solution::Solution().run(); }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, a = 1, b = 2, flag = 0;     cin >> n;     long long int arr[n];     for (int i = 0; i < n; i++) {       cin >> arr[i];     }     for (int i = 0; i < n; i++) {       if (arr[i] == 1 && (a == 1 && b == 2)) {         b = 3;       } else if (arr[i] == 1 && (b == 1 && a == 2)) {         a = 3;       } else if (arr[i] == 1 && (a == 1 && b == 3)) {         b = 2;       } else if (arr[i] == 1 && (b == 1 && a == 3)) {         a = 2;       } else if (arr[i] == 2 && (a == 1 && b == 2)) {         a = 3;       } else if (arr[i] == 2 && (b == 1 && a == 2)) {         b = 3;       } else if (arr[i] == 2 && (a == 3 && b == 2)) {         a = 1;       } else if (arr[i] == 2 && (b == 3 && a == 2)) {         b = 1;       } else if (arr[i] == 3 && (a == 1 && b == 3)) {         a = 2;       } else if (arr[i] == 3 && (b == 1 && a == 3)) {         b = 2;       } else if (arr[i] == 3 && (a == 2 && b == 3)) {         a = 1;       } else if (arr[i] == 3 && (b == 2 && a == 3)) {         b = 1;       } else if (i == 0 && arr[i] == 3) {         flag = 1;         break;       } else {         flag = 1;         break;       }     }     if (flag == 0) {       cout <<  YES ;     } else {       cout <<  NO ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     ;     int bit;     cin >> bit;     ;     int sum = 0;     bool test = false;     for (int i = 1; i < n; i++) {       int h;       cin >> h;       ;       bit -= (h + 1);       if (bit < 0) {         cout <<  NO ;         return 0;       }     }     int h;     cin >> h;     ;     bit -= h;     if (bit != 0)       cout <<  NO ;     else       cout <<  YES ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename T>   T POW(T b, T p) {     T r = 1;     while (p) {       if (p & 1) r = (r * b);       b = (b * b);       p >>= 1;     }     return r;   }   template <typename T>   T BigMod(T b, T p, T m) {     T r = 1;     while (p) {       if (p & 1) r = (r * b) % m;       b = (b * b) % m;       p >>= 1;     }     return r;   }   int main() {     long long n, a, b, c, cnt;     while (cin >> n) {       a = 1;       b = 1;       cnt = 0;       while (1) {         c = a + b;         a = b;         b = c;         if (c <= n)           cnt++;         else           break;       }       cout << cnt << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, x;     cin >> n >> x;     if (n == 3) {       cout <<  >vv  << endl <<  ^<.  << endl <<  ^.<  << endl;       cout << 1 <<     << 3;     }     if (n == 5) {       cout <<  >...v  << endl            <<  v.<..  << endl            <<  ..^..  << endl            <<  >....  << endl            <<  ..^.<  << endl;       cout << 1 <<     << 1;     }     if (n == 100) {       cout <<  >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.>.>.>.>.>.>.>                 .>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.v             << endl;       for (int i = 0; i < 49; i++) {         cout <<  ^v.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<<<<<<<<<<<<<                   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<               << endl;         cout <<  ^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.>.>.>.>.>.>                   .>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.>.v               << endl;       }       cout <<  ^<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<.<<<<<<<<<<<<<<<                 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<             << endl;       cout << 1 <<     << 1;     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int arr[n];     int count25 = 0;     int count50 = 0;     int ans = 0;     for (int i = 0; i < n; i++) {       cin >> arr[i];       if (arr[i] == 25) {         count25++;       } else if (arr[i] == 50) {         if (count25 > 0) {           count25--;           count50++;         } else {           ans = -1;         }       } else if (arr[i] == 100) {         if ((count25 > 0 && count50 > 0) || (count25 >= 3 && count50 == 0)) {           if (count50 == 0) {             count25--;             count25--;             count25--;           } else {             count25--;             count50--;           }         } else {           ans = -1;         }       }     }     if (ans == -1) {       cout <<  NO ;     } else {       cout <<  YES ;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 600005;   const long long mod = 1000000000000000003;   char str[N];   long long f[N];   unordered_set<long long> st;   int main() {     f[0] = 1;     int n, m;     for (int i = 1; i < 600000; i++) f[i] = f[i - 1] * 3 % mod;     cin >> n >> m;     while (n--) {       scanf( %s , str);       long long res = 0;       int len = strlen(str);       for (int i = 0; i < len; i++)         res = (res + f[len - i - 1] * (str[i] -  a )) % mod;       st.insert(res);     }     while (m--) {       scanf( %s , str);       long long sum = 0;       int flag = 0;       int len = strlen(str);       for (int i = 0; i < len; i++)         sum = (sum + f[len - i - 1] * (str[i] -  a )) % mod;       for (int i = 0; i < len; i++) {         long long sum2 = (sum - f[len - i - 1] * (str[i] -  a )) % mod;         if (sum2 < 0) sum2 += mod;         for (int j = 0; j < 3; j++) {           if (str[i] -  a  != j)             if (st.count((sum2 + f[len - i - 1] * j) % mod)) {               flag = 1;               break;             }         }         if (flag) break;       }       if (flag)         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 2e6 + 5;   long long mod = 1e9 + 7, bas = 31;   long long h[2][N], pw[N], cnt[N];   char c[N];   long long n, q;   long long query(long long l, long long r, long long op) {     return ((h[op][r] - h[op][l - 1] * pw[cnt[r] - cnt[l - 1]]) % mod + mod) %            mod;   }   signed main() {     ios::sync_with_stdio(false);     cin >> n >> c + 1;     for (long long i = 1; i <= n; i++) {       h[0][i] = h[0][i - 1];       h[1][i] = h[1][i - 1];       cnt[i] = cnt[i - 1];       if (c[i] ==  0 ) {         h[0][i] = (h[0][i] * bas + i % 2 + 1) % mod;         h[1][i] = (h[1][i] * bas + (i + 1) % 2 + 1) % mod;         ++cnt[i];       }     }     pw[0] = 1;     for (long long i = 1; i <= n; i++) pw[i] = pw[i - 1] * bas % mod;     cin >> q;     for (long long i = 1; i <= q; i++) {       long long t1, t2, len;       cin >> t1 >> t2 >> len;       if (query(t1, t1 + len - 1, t1 & 1) == query(t2, t2 + len - 1, t2 & 1))         puts( Yes );       else         puts( No );     }   }
#include<bits/stdc++.h>   using namespace std;   #define endl   n    int main()    {      ios_base::sync_with_stdio(false);      cin.tie(NULL);      int t;      cin>>t;      while(t--)      {          long long int n,i,j,k,l;          cin>>n>>k;          if(k==1)          {              cout<< 1 <<endl;              continue;          }          if(n&1)          {              if(k*2>n-2)              {                  j=(n-2)/2+1;                  l=(k-1)/j;                  k=k+l;              }          }          if(k%n==0)          cout<<n<<endl;          else          cout<<(k%n)<<endl;      }      return 0;   }
#include <bits/stdc++.h>   using namespace std;   void doRoutine() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);   }   bool isInside(pair<long long int, long long int> p,                 pair<long long int, long long int> a[]) {     return (p.first >= a[0].first) && (p.second >= a[0].second) &&            (p.first <= a[3].first) && (p.second <= a[3].second);   }   signed main() {     doRoutine();     pair<long long int, long long int> a[4], b[4];     for (long long int i = 0; i < 4; i++) cin >> a[i].first >> a[i].second;     for (long long int i = 0; i < 4; i++) cin >> b[i].first >> b[i].second;     sort(a, a + 4);     sort(b, b + 4);     for (long long int i = b[0].first; i <= b[3].first; i++) {       long long int f =           b[0].second - (i <= b[1].first ? (i - b[0].first) : (b[3].first - i));       long long int s = (2 * b[0].second) - f;       for (long long int j = f; j <= s; j++) {         if (isInside({i, j}, a)) return cout <<  Yes  <<   n , 0;       }     }     cout <<  No  <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, x;   int bot[100001];   int top[100001];   int mir[101];   int hr, hl;   int uuh, bbh, ubh, buh;   int L = 100000;   double eps = 0.00001;   int mxr;   int sco(int s, bool up) {     int res = 0;     int dh = ((s % 2) ? (up ? uuh : bbh) : (up ? ubh : buh));     double f = ((double)(up ? (100 - hl) : hl)) * L / (100 * (s - 1) + dh);     double T = ((double)L * 100) / (100 * (s - 1) + dh);     int l1 = 0, l2 = 0, l3 = 0;     int* u = (up ? top : bot);     for (int i = 0; i < s; ++i) {       if ((f - floor(f)) > eps) {         l3 = u[(int)floor(f)];       } else {         l3 = max(u[(int)floor(f) - 1], u[(int)floor(f)]);       }       if ((l3 == l1) || (l3 == 0)) {         return 0;       }       l1 = l2;       l2 = l3;       res += mir[l3];       u = (u == top ? bot : top);       f += T;     }     return res;   }   int main(int argc, char** argv) {     cin >> hl >> hr >> n;     uuh = 200 - hl - hr;     bbh = hr + hl;     ubh = 100 + hr - hl;     buh = 100 + hl - hr;     int v, a, b;     char c;     for (int i = 1; i <= n; ++i) {       cin >> v >> c >> a >> b;       mir[i] = v;       if (c ==  T ) {         for (int j = a; j < b; ++j) {           top[j] = i;         }       } else {         for (int j = a; j < b; ++j) {           bot[j] = i;         }       }     }     double T;     int mxr = 0;     for (k = 1; k <= n; ++k) {       int res = sco(k, true);       if (res > mxr) {         mxr = res;       }       res = sco(k, false);       if (res > mxr) {         mxr = res;       }     }     cout << mxr;     return 0;   }