malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   template <typename T>   string toString(T x) {     if (x == 0) return  0 ;     bool negative = x < 0;     string res;     while (x) {       res.push_back( 0  + x % 10);       x /= 10;     }     if (negative) res.push_back( - );     reverse(res.begin(), res.end());     return res;   }   template <typename T>   T gcd(T a, T b) {     return a == 0 ? b : gcd(b % a, a);   }   template <typename T>   T lcm(T a, T b) {     return a / gcd(a, b) * b;   }   int main() {     string s;     cin >> s;     vector<int> a(s.length() / 2);     int m;     cin >> m;     for (int i = 0; i < m; i++) {       int t;       cin >> t;       t--;       a[t]++;     }     int l = s.length() / 2;     vector<bool> r(l);     int carry = 0;     for (int i = 0; i < l; i++) {       int t = a[i] + carry;       carry = t % 2;       r[i] = carry;     }     for (int i = 0; i < l; i++) {       if (r[i]) {         cout << s[s.length() - 1 - i];       } else {         cout << s[i];       }     }     if (s.length() % 2 == 1) {       cout << s[l];       l++;     }     for (int i = (s.length() + 1) / 2; i < s.length(); i++) {       if (r[s.length() - 1 - i]) {         cout << s[s.length() - 1 - i];       } else {         cout << s[i];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, k, key, MK, MKEY;   int MAP[110][110];   int ii, jj;   void dfssolve(int pos, int step) {     int temp[110];     int cnt, i, j;     if (pos > n) {       key = 1;       k = k < step ? k : step;       return;     }     cnt = 0;     for (i = 1; i <= m; ++i) {       temp[i] = MAP[pos][i];       if (MAP[pos][i] != MAP[pos - 1][i]) {         cnt++;         MAP[pos][i] = MAP[pos - 1][i];       }     }     if (step + cnt <= k) dfssolve(pos + 1, step + cnt);     cnt = 0;     for (i = 1; i <= m; ++i) {       if (temp[i] == MAP[pos - 1][i]) {         cnt++;         MAP[pos][i] = MAP[pos - 1][i] & 1;       }     }     if (step + cnt <= k) dfssolve(pos + 1, step + cnt);     for (i = 1; i <= m; ++i) MAP[pos][i] = temp[i];   }   void dfssolveup(int pos, int step) {     int cnt, i, j;     int temp[110];     if (pos < 1) {       MKEY = 1;       MK = step < MK ? step : MK;       return;     }     cnt = 0;     for (i = 1; i <= m; ++i) {       temp[i] = MAP[pos][i];       if (MAP[pos][i] != MAP[pos + 1][i]) {         cnt++;         MAP[pos][i] = MAP[pos + 1][i];       }     }     if (step + cnt <= k) dfssolveup(pos - 1, step + cnt);     cnt = 0;     for (i = 1; i <= m; ++i) {       if (temp[i] == MAP[pos + 1][i]) {         cnt++;         MAP[pos][i] = MAP[pos + 1][i] & 1;       }     }     if (step + cnt <= k) dfssolveup(pos - 1, step + cnt);     for (i = 1; i <= m; ++i) MAP[pos][i] = temp[i];   }   void dfs(int pos, int step) {     if (k < step) return;     if (pos == m) {       dfssolve(2, step);       MAP[1][pos] ^= 1;       dfssolve(2, step + 1);       MAP[1][pos] ^= 1;     } else {       dfs(pos + 1, step);       MAP[1][pos] ^= 1;       dfs(pos + 1, step + 1);       MAP[1][pos] ^= 1;     }   }   int main() {     cin >> n >> m >> k;     key = 0;     if (n < m) {       for (ii = 1; ii <= n; ++ii)         for (jj = 1; jj <= m; ++jj) cin >> MAP[jj][ii];       swap(n, m);     } else {       for (ii = 1; ii <= n; ++ii)         for (jj = 1; jj <= m; ++jj) cin >> MAP[ii][jj];     }     if (n <= k) {       dfs(1, 0);     } else {       for (ii = 1; ii <= n; ++ii) {         MK = 10;         MKEY = 0;         dfssolveup(ii - 1, 0);         if (MKEY) {           dfssolve(ii + 1, MK);         }       }     }     if (key)       cout << k << endl;     else       cout << -1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long mod = 1e9 + 7;   const long long N = 1e5 + 5;   long long ans = 1e18;   map<long long, bool> mp;   void solve(long long n, long long cnt) {     if (!n) {       cout << cnt;       exit(0);     }     string s = to_string(n);     sort(s.rbegin(), s.rend());     solve(n - (s[0] -  0 ), cnt + 1);   }   inline long long solve() {     long long n;     cin >> n;     solve(n, 0);     cout << ans;     return 0;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     cout.tie(NULL);     long long t = 1;     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, t, d;     cin >> n >> m;     map<long long, long long> mp;     set<pair<long long, long long> > st;     vector<long long> a(n), c(n);     for (int i = 0; i < n; i++) {       cin >> a[i];       mp[i] = a[i];     }     for (int i = 0; i < n; i++) {       cin >> c[i];       st.insert({c[i], i});     }     for (int i = 0; i < m; i++) {       cin >> t >> d;       long long cost = 0;       t--;       if (st.size() == 0)         cout << 0 << endl;       else {         if (mp[t] != 0) {           if (mp[t] > d) {             mp[t] -= d;             cout << (long long)d * c[t] << endl;             d = 0;           } else if (mp[t] == d) {             mp[t] -= d;             cout << (long long)d * c[t] << endl;             d = 0;             st.erase({c[t], t});           } else {             cost += (long long)mp[t] * c[t];             d -= mp[t];             mp[t] = 0;             st.erase({c[t], t});           }         }         if (d > 0) {           while (d > 0 && st.size() > 0) {             pair<int, int> now = *st.begin();             if (mp[now.second] > d) {               mp[now.second] -= d;               cout << (long long)cost + d * now.first << endl;               d = 0;             } else if (mp[now.second] == d) {               mp[now.second] -= d;               cout << (long long)cost + d * now.first << endl;               d = 0;               st.erase(st.begin());             } else {               cost += (long long)mp[now.second] * now.first;               d -= mp[now.second];               mp[now.second] = 0;               st.erase(st.begin());             }           }           if (d > 0) {             cout << 0 << endl;           }         }       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   T modulo(T x, T p) {     if (x >= 0) return x % p;     return p + x % p;   }   template <class T>   T gcd(T a, T b) {     if (b == 0) return a;     return gcd(b, a % b);   }   template <class T>   T lcm(T a, T b) {     return a * b / gcd(a, b);   }   int dfs_paths(       int u, int prev, vector<vector<pair<long long, long long> > > &G,       long long &cur,       priority_queue<pair<long long, pair<long long, long long> > > &pqw) {     long long paths, total = 0, profit;     for (pair<long long, long long> e : G[u]) {       if (e.second == prev) continue;       paths = dfs_paths(e.second, u, G, cur, pqw);       profit = e.first * paths - (e.first / 2) * paths;       pqw.push({profit, {e.first, paths}});       cur += e.first * paths;       total += paths;     }     return max(1ll, total);   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int t;     cin >> t;     while (t--) {       long long n, S;       cin >> n >> S;       vector<vector<pair<long long, long long> > > G(n);       int u, v;       long long w;       for (int i = 0; i < n - 1; i++) {         cin >> u >> v >> w;         u--;         v--;         G[u].push_back({w, v});         G[v].push_back({w, u});       }       long long cur = 0;       priority_queue<pair<long long, pair<long long, long long> > > pqw;       dfs_paths(0, -1, G, cur, pqw);       long long moves = 0, mult;       pair<long long, pair<long long, long long> > e;       while (cur > S) {         e = pqw.top();         pqw.pop();         w = e.second.first / 2;         mult = e.second.second;         cur -= e.first;         pqw.push({w * mult - (w / 2) * mult, {w, mult}});         moves++;       }       cout << moves <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int long long l1, l2, r1, r2, k, ans, l, r;     cin >> l1;     cin >> r1;     cin >> l2;     cin >> r2;     cin >> k;     l = max(l1, l2);     r = min(r1, r2);     if (r - l < 0) {       cout << 0 << endl;       return 0;     }     ans = r - l + 1;     if (k >= l && k <= r) ans--;     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int t;     scanf( %d , &t);     while (t--) {       long long x1, y1, x2, y2;       scanf( %lld%lld%lld%lld , &x1, &y1, &x2, &y2);       long long lenx = abs(x1 - x2);       long long leny = abs(y1 - y2);       long long ans = lenx + leny;       if (lenx && leny) ans += 2;       printf( %lld n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     while (cin >> n) {       vector<long long> vec;       for (long long i = 2; i * i <= n; i++) {         while (n % i == 0) {           vec.push_back(i);           n /= i;         }       }       if (n > 1) {         vec.push_back(n);       }       if (vec.size() < 2) {         printf( 1 n0 n );       } else if (vec.size() == 2) {         printf( 2 n );       } else {         printf( 1 n%lld n , vec[0] * vec[1]);       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, num, cnt;   int dat[1009][1009], ans[1000009];   bool vis[1009][1009];   int dx[4] = {-1, 0, 1, 0};   int dy[4] = {0, 1, 0, -1};   int wall[4] = {8, 4, 2, 1};   void dfs(int x, int y) {     if (vis[x][y] || x < 0 || x > n || y < 0 || y > m) return;     vis[x][y] = 1;     num++;     for (int i = 0; i < 4; i++) {       if ((dat[x][y] & wall[i]) ||           (dat[x + dx[i]][y + dy[i]] & wall[(i + 2) % 4]))         continue;       dfs(x + dx[i], y + dy[i]);     }   }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> dat[i][j];       }     }     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (!vis[i][j]) {           num = 0;           dfs(i, j);           ans[++cnt] = num;         }       }     }     sort(ans + 1, ans + 1 + cnt);     for (int i = cnt; i > 0; i--) cout << ans[i] <<    ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n, m, ind, sum = 0;     cin >> n;     long long mas[n];     for (long long i = 0; i < n; i++) {       cin >> mas[i];       sum += mas[i];     }     cin >> m;     long long arr[m];     sort(mas, mas + n);     for (long long i = 0; i < m; i++) {       cin >> arr[i];       cout << sum - mas[n - arr[i]] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, nxt[200010], a[200010], sz[200010][31];   long long ans = 0;   map<int, int> mp;   inline char gc() {     static char *S, *T, buf[1 << 16];     if (T == S) {       T = (S = buf) + fread(buf, 1, 1 << 16, stdin);       if (T == S) return EOF;     }     return *S++;   }   inline int read() {     int x = 0, f = 1;     char ch = gc();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) f = -1;       ch = gc();     }     while ( 0  <= ch && ch <=  9 ) x = x * 10 + ch -  0 , ch = gc();     return x * f;   }   inline int check(int l, int r) {     int res = 0;     for (int i = 0; i <= 30; ++i) res |= ((sz[r][i] - sz[l - 1][i]) > 0) << i;     return res;   }   int main() {     n = read();     for (int i = 1; i <= n; ++i) {       a[i] = read(), nxt[i] = mp[a[i]], mp[a[i]] = i;       for (int j = 0; j <= 30; ++j) {         sz[i][j] = sz[i - 1][j];         if (a[i] & (1 << j)) sz[i][j]++;       }     }     for (int i = 1; i <= n; ++i) {       int l = max(nxt[i] + 1, 1), r = i, nowl = i;       while (l <= r) {         int mid = l + r >> 1;         if (check(mid, i) == a[i])           nowl = mid, r = mid - 1;         else           l = mid + 1;       }       l = i, r = n;       int nowr = i;       while (l <= r) {         int mid = l + r >> 1;         if (check(i, mid) == a[i])           nowr = mid, l = mid + 1;         else           r = mid - 1;       }       ans += 1ll * (i - nowl + 1) * (nowr - i + 1);     }     printf( %I64d n , 1ll * n * (n + 1) / 2 - ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n, t, twoc, onec, opt, old;   int main() {     cin >> n;     cin >> t;     if (t == 1)       onec++;     else       twoc++;     old = t;     for (int i = 1; i < n; i++) {       cin >> t;       if (t == 1) {         if (old == 2)           onec = 1;         else           onec++;       } else {         if (old == 1)           twoc = 1;         else           twoc++;       }       opt = max(opt, min(onec, twoc));       old = t;     }     cout << opt * 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int ar[1000001];   int main() {     int n, k;     cin >> n >> k;     if (k == n) {       cout << -1 << endl;       return 0;     }     if (k == n - 1) {       for (int i = 0; i < n; i++) cout << i + 1 <<    ;       cout << endl;       return 0;     }     for (int i = 2; i <= k + 1; i++) ar[i] = i;     ar[1] = k + 2;     ar[n] = 1;     for (int i = k + 2; i < n; i++) ar[i] = i + 1;     for (int i = 1; i <= n; i++) cout << ar[i] <<    ;     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int pow(int a, int b, int c) {     int ret = 1;     for (; b; b >>= 1, a = 1LL * a * a % c)       if (b & 1) ret = 1LL * ret * a % c;     return ret;   }   const int N = 2e3 + 10, M = 4.05e6 + 10;   int h[N], g[N], p[M], n1[M], ee, low[N], dfn[N], dfntot, vis[N], n, m, st[N],       top, id[N], tot, sz[N], ans, dp[N], ok[N];   pair<int, int> e[M];   void ae(int *A, int x, int y) {     p[ee] = y;     n1[ee] = A[x];     A[x] = ee++;   }   void tarjan(int u, int fa) {     vis[u] = 1;     low[u] = dfn[u] = ++dfntot;     st[++top] = u;     for (int i = h[u]; ~i; i = n1[i])       if (p[i] != fa) {         if (!vis[p[i]])           tarjan(p[i], u), low[u] = min(low[u], low[p[i]]);         else           low[u] = min(low[u], dfn[p[i]]);         if (low[p[i]] > dfn[u]) {           ++tot;           while (st[top] != p[i]) id[st[top--]] = tot, sz[tot]++;           id[st[top--]] = tot;           sz[tot]++;         }       }   }   void dfs(int u, int fa) {     dp[u] = sz[u];     for (int i = g[u]; ~i; i = n1[i])       if (p[i] != fa) {         dfs(p[i], u);         dp[u] += dp[p[i]];       }   }   int main() {     scanf( %d%d , &n, &m);     memset(h, -1, sizeof(h));     memset(g, -1, sizeof(g));     int x, y;     for (int i = 1; i <= m; i++) scanf( %d%d , &x, &y), ae(h, x, y), ae(h, y, x);     for (int i = 1; i <= n; i++)       if (!vis[i]) tarjan(i, 0);     ++tot;     while (top) id[st[top--]] = tot, sz[tot]++;     for (int i = 1; i <= n; i++)       for (int j = h[i]; ~j; j = n1[j])         if (id[i] != id[p[j]]) ae(g, id[i], id[p[j]]);     for (int i = 1; i <= tot; i++) ans += sz[i] * (sz[i] - 1);     int ret = 0;     for (int i = 1; i <= tot; i++) {       int tmp = 0;       dfs(i, 0);       for (int j = 1; j <= tot; j++) tmp += (dp[j] - sz[j]) * sz[j];       for (int j = 0; j <= n; j++) ok[j] = 0;       ok[0] = 1;       for (int k = g[i]; ~k; k = n1[k])         for (int j = n; j >= dp[p[k]]; j--) ok[j] |= ok[j - dp[p[k]]];       int mx = 0;       for (int j = 0; j <= n; j++)         if (ok[j]) mx = max(mx, j * (n - sz[i] - j));       ret = max(ret, tmp + mx);     }     printf( %d n , n + ans + ret);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long int m = 1000000007;   long long int n1, n2 = 0, sum = 0;   long long int gcd(long long int a, long long int b) {     return (b == 0) ? a : gcd(b, a % b);   }   bool compare(pair<string, long long int> p1, pair<string, long long int> p2) {     if (p1.second != p2.second) {       return p1.second > p2.second;     } else       return p1.first < p2.first;   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t = 1;     while (t--) {       long long int n;       cin >> n;       bool prime[n + 2];       memset(prime, true, sizeof(prime));       for (long long int p = 2; p * p <= n + 1; p++) {         if (prime[p] == true) {           for (long long int i = p * p; i <= n + 1; i += p) prime[i] = false;         }       }       if (n > 2)         cout << 2 <<   n ;       else         cout << 1 <<   n ;       for (long long int i = 2; i < n + 2; i++) {         if (prime[i])           cout << 1 <<    ;         else           cout << 2 <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   mt19937_64 mt(time(0));   set<pair<long long, long long> > dp[49];   void insert(set<pair<long long, long long> >& table, long long a, long long b) {     if (table.empty()) {       table.insert({a, b});       return;     }     auto it = table.lower_bound({b, LLONG_MAX});     while (it != table.begin()) {       it--;       if (it->second < a) break;       a = min(it->first, a);       b = max(it->second, b);       if (it == table.begin()) {         table.erase(it);         break;       } else {         table.erase(it++);       }     }     table.insert({a, b});   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cout.precision(10);     cout << fixed;     long long n;     cin >> n;     for (int i = 0; i <= min(48LL, n); i++) {       for (int j = 0; j <= 8 && i + j <= n; j++) {         int tmp = i * 9 + j * 4;         long long a = tmp / 49;         long long b = n - i - j + tmp / 49;         insert(dp[tmp % 49], a, b);       }     }     long long ret = 0;     for (int i = 0; i < 49; i++) {       for (auto item : dp[i]) {         ret += item.second - item.first + 1;       }     }     cout << ret << endl;     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, i;     long long cnt[5] = {0};     char ch;     scanf( %d , &n);     getchar();     cnt[0] = 1;     for (i = 0; i < n; i++) {       scanf( %c , &ch);       if (ch ==  a ) {         cnt[1] = (cnt[1] + cnt[0]) % 1000000007;       } else if (ch ==  b ) {         cnt[2] = (cnt[2] + cnt[1]) % 1000000007;       } else if (ch ==  c ) {         cnt[3] = (cnt[3] + cnt[2]) % 1000000007;       } else if (ch ==  ? ) {         cnt[3] = (3 * cnt[3] % 1000000007 + cnt[2]) % 1000000007;         cnt[2] = (3 * cnt[2] % 1000000007 + cnt[1]) % 1000000007;         cnt[1] = (3 * cnt[1] % 1000000007 + cnt[0]) % 1000000007;         cnt[0] = 3 * cnt[0] % 1000000007;       }     }     printf( %lld n , cnt[3]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using namespace std;   struct node {     int l, m, r;   };   node t[3000005];   int arr[300005], n, m;   long long a[300005];   int sign(long long x) {     if (x > 0) return 1;     if (x < 0) return -1;     return 0;   }   void cal(int x, int l, int r) {     int m = (l + r) / 2;     t[x].m = max(t[x * 2].m, t[x * 2 + 1].m);     t[x].l = t[x * 2].l;     t[x].r = t[x * 2 + 1].r;     if (!!a[m] && !!a[m + 1] && sign(a[m]) >= sign(a[m + 1])) {       t[x].m = max(t[x].m, t[x * 2].r + t[x * 2 + 1].l);       if (t[2 * x].m == m - l + 1) t[x].l = t[2 * x].l + t[2 * x + 1].l;       if (t[2 * x + 1].m == r - m) t[x].r = t[2 * x].r + t[2 * x + 1].r;     }   }   void build(int x, int l, int r) {     if (l == r) {       int tmp = !!a[l];       t[x] = {tmp, tmp, tmp};       return;     }     int m = (l + r) / 2;     build(x * 2, l, m);     build(x * 2 + 1, m + 1, r);     cal(x, l, r);   }   void update(int x, int l, int r, int pos, int d) {     if (l == r) {       a[pos] += d;       int tmp = !!a[pos];       t[x] = {tmp, tmp, tmp};       return;     }     int m = (l + r) / 2;     if (pos <= m)       update(x * 2, l, m, pos, d);     else       update(x * 2 + 1, m + 1, r, pos, d);     cal(x, l, r);   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     for (int i = 0; i + 1 < n; i++) a[i] = arr[i + 1] - arr[i];     if (n > 1) build(1, 0, n - 2);     cin >> m;     while (m--) {       int l, r, d;       scanf( %d%d%d , &l, &r, &d);       if (n == 1) {         printf( %d n , 1);         continue;       }       if (l > 1) update(1, 0, n - 2, l - 2, d);       if (r < n) update(1, 0, n - 2, r - 1, -d);       printf( %d n , t[1].m + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = int(1e9);   const int MOD = INF + 7;   const long long INFll = 1ll * INF * INF;   const long double ldINF = 1e+018;   const long double EPS = 0.000000001;   const int MAXN = 150;   const int N = 100001;   const int seg[10] = {6, 2, 5, 5, 4, 5, 6, 3, 7, 6};   struct feature {     int b, i, r;   };   bool comp(feature x, feature y) {     return x.r > y.r || (x.r == y.r && x.b < y.b);   }   int t[1001000];   int cur = 0;   int query(int l, int r) {     int res = 0;     for (l += cur, r += cur; l < r; l >>= 1, r >>= 1) {       if (l & 1) res = max(res, t[l++]);       if (r & 1) res = max(res, t[--r]);     }     return res;   }   void modify(int p, int value) {     t[p += cur] = value;     while (p > 1) {       p >>= 1;       t[p] = max(t[p << 1], t[p << 1 | 1]);     }   }   int main() {     ios_base::sync_with_stdio(0);     int n;     cin >> n;     vector<feature> v(n);     for (int i = 0; i < n; i++) cin >> v[i].r;     for (int i = 0; i < n; i++) cin >> v[i].b;     for (int i = 0; i < n; i++) cin >> v[i].i;     vector<int> b;     for (int i = 0; i < n; i++) b.push_back(v[i].b);     sort(b.begin(), b.end());     map<int, int> m;     m[b[0]] = 0;     for (int i = 1; i < n; i++)       if (b[i] != b[i - 1]) m[b[i]] = ++cur;     cur++;     for (int i = 0; i < n; i++) v[i].b = m[v[i].b];     int ans = 0;     sort(v.begin(), v.end(), comp);     for (int i = 0; i < n; i++) {       int d = query(v[i].b + 1, cur);       if (d > v[i].i) {         ans++;       }       modify(v[i].b, max(t[v[i].b + cur], v[i].i));     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long int t = 1;     while (t--) {       long long int n, d = 0, r = 0;       cin >> n;       string s;       cin >> s;       char x;       for (long long int i = 0; i < s.length(); i++) {         if (s[i] ==  R ) {           if (d) {             d--;           } else {             s +=  R ;             r++;           }         } else {           if (r) {             r--;           } else {             s +=  D ;             d++;           }         }         x = s[i];         if (d == n || r == n) {           break;         }       }       cout << x << endl;     }     return 0;   }
#include <bits/stdc++.h>   #define fasterio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)   #define X first   #define Y second   #define forn(i, n) for(int i=0;i<(n);i++)   #define pb push_back   using namespace std;   typedef long long ll;   typedef pair<int, int> pii;   const int inf = 0x3f3f3f3f;   const long long mod = 1e9+7;   const long long maxn = 100010;      int gao (int x1, int y1, int x2, int y2, int xf, int yf) {    auto abs = [&](int a, int b){return a>b?a-b:b-a;};    int ans = abs(x1, x2) + abs(y1, y2);       if (x1 == x2 && y1 == y2) {     return ans;    } else if (x1 == x2 && x2 == xf) { // on the same x axis     if ((y1<yf && yf<y2) || (y2<yf && yf<y1))      ans += 2;    } else if (y1 == y2 && y2 == yf) {     if ((x1<xf && xf<x2)||(x2<xf && xf<x1))       ans += 2;    }    return ans;   }   int main() {    int t;    cin>>t;     while(t--) {     int xa, ya, xb, yb, xf, yf;     cin>>xa>>ya>>xb>>yb>>xf>>yf;          if(xa==xb && ya==yb) {      cout<<0<<endl;      continue;     }        int ans = gao(xa, ya, xb, yb, xf, yf);     cout<<ans<<endl;    }   }
#include <bits/stdc++.h>   using namespace std;   int l_f, l_h;   long long int dp[101][101][11][11];   int getans(int f, int h, int k1, int k2) {     int x = 0, y = 0;     if ((f + h) == 0) return 1;     if (dp[f][h][k1][k2] != -1) return dp[f][h][k1][k2];     if (f > 0 && k1 > 0) x = getans(f - 1, h, k1 - 1, l_h);     if (h > 0 && k2 > 0) y = getans(f, h - 1, l_f, k2 - 1);     return dp[f][h][k1][k2] = (x + y) % 100000000;   }   int main() {     int t = 1;     while (t--) {       int n1, n2;       cin >> n1 >> n2 >> l_f >> l_h;       memset(dp, -1, sizeof(dp));       int ans = getans(n1, n2, l_f, l_h);       cout << ans <<   n ;     }   }