malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300001;   int f[maxn], a[maxn];   inline void add(int x, int val) {     for (int i = x + 1; i < maxn; i += i & (-i)) f[i] += val;   }   inline int get(int x) {     int ans = 0;     for (int i = x; i > 0; i -= i & (-i)) ans += f[i];     return ans;   }   inline int sum(int x, int y) { return get(y) - get(x); }   int main() {     int q, l, r, n, m, rev = 0;     scanf( %d%d , &n, &m);     int cr = n - 1, cl = 0;     int len = cr - cl + 1;     for (int i = 0; i < n; ++i) add(i, a[i] = 1);     for (int t = 0; t < m; ++t) {       scanf( %d , &q);       if (q == 1) {         scanf( %d , &l);         if (l > len - l) rev ^= 1, l = len - l;         if (rev) {           cr = cr - l;           for (int i = cr; i >= cr - l + 1; --i)             add(i, a[2 * cr - i + 1]), a[i] += a[2 * cr - i + 1];         } else {           cl = cl + l;           for (int i = cl; i <= cl + l - 1; ++i)             add(i, a[2 * cl - i - 1]), a[i] += a[2 * cl - i - 1];         }         len = cr - cl + 1;       }       if (q == 2) {         scanf( %d%d , &l, &r);         int ln = (r - l);         if (rev)           l = cr - l + 1, r = l - ln, swap(l, r);         else           l += cl, r += cl;         printf( %d n , sum(l, r));       }     }   }
#include <bits/stdc++.h>   #pragma GCC optimize( O2 )   using namespace std;   int n, s;   int frq[1002];   int t;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     cin >> n >> s;     for (int i = 1; i <= n; ++i) {       int a, b;       cin >> a >> b;       frq[a] = max(frq[a], b);     }     for (int i = s; i >= 0; --i) {       t = max(t, frq[i]);       if (i != 0) ++t;     }     cout << t;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T>   inline void read(T& a) {     char c = getchar();     int f = 1;     a = 0;     for (; c >  9  || c <  0 ; c = getchar())       if (c ==  - ) f = -1;     for (; c <=  9  && c >=  0 ; c = getchar()) a = a * 10 + c - 48;     a *= f;   }   const int o = 1e5 + 10;   inline long long Max(long long a, long long b) { return a > b ? a : b; }   long long T, n, k, a[o];   pair<long long, long long> p[o];   signed main() {     for (read(T); T--;) {       read(n);       for (long long i = 1; i <= n; ++i) {         read(k);         for (long long j = 0; j < k; ++j) read(a[j]);         a[k] = 0;         for (long long j = k - 1; j + 1; --j) a[j] = Max(a[j + 1], a[j] - j);         p[i] = make_pair(a[0], k);       }       sort(p + 1, p + 1 + n);       for (long long i = 2, j = p[1].second; i <= n; j += p[i++].second)         p[i].first = Max(p[i - 1].first, p[i].first - j);       printf( %lld n , p[n].first + 1);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> dif;   map<int, int> g;   int a[120000];   int main() {     int n, flag;     cin >> n;     for (int i = 1; i <= n; i++) cin >> a[i];     sort(a + 1, a + 1 + n);     for (int i = 2; i <= n; i++) {       if (g[a[i] - a[i - 1]] == 0) dif.push_back(a[i] - a[i - 1]);       g[a[i] - a[i - 1]]++;     }     int sz = dif.size();     if (sz > 2 || n == 1) {       if (sz > 2)         cout << 0 << endl;       else         cout << -1 << endl;       return 0;     }     if (sz == 1) {       int D = dif[0];       if (dif[0] == 0) {         cout << 1 << endl;         cout << a[1] << endl;         return 0;       }       if (n == 2) {         if ((a[2] - a[1]) % 2 == 0) {           cout << 3 << endl;           cout << a[1] - D <<     << (a[2] + a[1]) / 2 <<     << a[2] + D << endl;           return 0;         }       }       cout << 2 << endl;       cout << a[1] - D <<     << a[n] + D << endl;       return 0;     }     int D1 = min(dif[0], dif[1]), D2 = max(dif[0], dif[1]);     if (D1 * 2 != D2 || g[D2] > 1) {       cout << 0 << endl;       return 0;     }     cout << 1 << endl;     for (int i = 2; i <= n; i++) {       if (a[i] - a[i - 1] == D2) {         cout << a[i] - D1 << endl;         return 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void init_code() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);   }   set<pair<int, int>> es;   map<int, list<int>> m;   void add(int a, int b) {     m[a].push_back(b);     m[b].push_back(a);   }   int v[1001];   void dfs(int node) {     v[node] = 1;     for (int i : m[node]) {       if (v[i] == 0) {         es.erase({node, i});         es.erase({i, node});         dfs(i);       }     }   }   int main() {     init_code();     int n;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int a, b;       cin >> a >> b;       add(a, b);       es.insert({a, b});     }     vector<int> ans;     for (int i = 1; i <= n; i++) {       if (v[i] == 0) {         ans.push_back(i);         dfs(i);       }     }     cout << es.size() << endl;     vector<pair<int, int>> ans2, ans3;     for (auto i : es) {       ans2.push_back(i);     }     for (int i = 1; i < ans.size(); i++) {       ans3.push_back({ans[i], ans[i - 1]});     }     for (int i = 0; i < ans2.size(); i++) {       cout << ans2[i].first <<     << ans2[i].second <<     << ans3[i].first            <<     << ans3[i].second << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 4040, inF = 1e9;   int n, a, b, c, dp[N];   int main() {     cin >> n >> a >> b >> c;     dp[0] = 0;     for (int i = 1; i <= n; i++) {       dp[i] = -inF;       if (i >= a) dp[i] = max(dp[i], dp[i - a] + 1);       if (i >= b) dp[i] = max(dp[i], dp[i - b] + 1);       if (i >= c) dp[i] = max(dp[i], dp[i - c] + 1);     }     cout << dp[n];     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long K = 10001;   signed main() {     long long n, l, r, ans = 0;     cin >> n >> l >> r;     vector<long long> a(n), b(n);     for (long long i = 0; i < n; i++) cin >> a[i];     for (long long i = 0; i < n; i++) cin >> b[i];     vector<long long> bad, good;     for (long long i = 0; i < n; i++) {       if (b[i] == 0)         bad.push_back(a[i]);       else         good.push_back(a[i]);     }     if (good.size() == 0) {       cout << 0 << endl;       return 0;     }     sort(good.begin(), good.end());     long long S = 0;     for (long long i = 0; i < good.size(); i++) S += good[i];     bool knapbad[K], knapgood[K];     for (long long i = 0; i < K; i++) knapbad[i] = false;     for (long long i = 0; i < K; i++) knapgood[i] = false;     knapbad[0] = true;     knapgood[0] = true;     for (long long i = 0; i < bad.size(); i++) {       for (long long j = K - 1; j >= bad[i]; j--)         knapbad[j] |= knapbad[j - bad[i]];     }     long long pref[K + 1];     pref[0] = 0;     for (long long i = 1; i <= K; i++) pref[i] = pref[i - 1] + knapbad[i - 1];     vector<vector<long long> > close(good.size());     long long INF = 1e9;     close[good.size() - 1].push_back(0);     for (long long i = good.size() - 1; i >= 0; i--) {       for (long long j = K - 1; j >= good[i]; j--) {         if (!knapgood[j] && knapgood[j - good[i]]) {           if (i != 0) close[i - 1].push_back(j);           knapgood[j] = true;         }       }     }     for (long long i = l; i <= r; i++)       if (knapgood[i] && i != S) ans = max(ans, (long long)1);     long long Kn[K];     for (long long i = 0; i < K; i++) Kn[i] = -INF;     Kn[0] = 0;     for (long long i = 0; i < good.size(); i++) {       for (long long j = K - 1; j >= good[i]; j--) {         Kn[j] = max(Kn[j], Kn[j - good[i]] + 1);       }       for (long long j = 0; j < close[i].size(); j++) {         long long N = close[i][j];         for (long long p = 0; p < K; p++) {           if (Kn[p] < 0) continue;           long long L = max((long long)0, l - N), R = r - N - p;           if (L > R) continue;           if (pref[R + 1] - pref[L] == 0) continue;           if (N + p == S)             ans = max(ans, Kn[p]);           else             ans = max(ans, Kn[p] + 1);         }       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int mnx = 1e5 + 9;   long long q, n;   long long a[mnx], k;   map<int, int> m;   int main() {     cin >> q;     while (q--) {       cin >> n;       for (int j = 1; j * j <= n; j++) {         int jk = n / j;         if (j == n / jk) {           m[n / j]++;           m[j]++;         }       }       cout << m.size() + 1 <<   n ;       cout << 0 <<    ;       for (auto i : m) {         cout << i.first <<    ;       }       m.clear();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   int main() {     string s;     cin >> s;     int index = s.size() - 1;     vector<char> din3(s.size(), 0);     vector<char> din2(s.size(), 0);     if (index - 2 >= 5) din3[index - 2] = 1;     if (index - 1 >= 5) din2[index - 1] = 1;     index -= 3;     set<string> res;     while (index >= 5) {       if (din2[index + 2] == 1 and s.substr(index, 2) != s.substr(index + 2, 2)) {         din2[index] = 1;       }       if (din3[index + 3] == 1 and s.substr(index, 3) != s.substr(index + 3, 3)) {         din3[index] = 1;       }       if (din2[index + 3] == 1) {         din3[index] = 1;       }       if (din3[index + 2] == 1) {         din2[index] = 1;       }       --index;     }     for (auto i(0); i < din2.size(); ++i) {       if (din2[i] == 1) {         res.insert(s.substr(i, 2));       }     }     for (auto i(0); i < din3.size(); ++i) {       if (din3[i] == 1) {         res.insert(s.substr(i, 3));       }     }     cout << res.size() << endl;     while (!res.empty()) {       cout << *res.begin() << endl;       res.erase(res.begin());     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c, l, tmp;   long long read() {     long long 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;   }   long long cal(long long x, long long y, long long z) {     if (x < y) return 0;     long long p = min(z, x - y);     return (p + 2) * (p + 1) / 2;   }   int main() {     a = read();     b = read();     c = read();     l = read();     for (int i = 0; i <= l; i++)       tmp += cal(a + i, b + c, l - i) + cal(b + i, a + c, l - i) +              cal(c + i, a + b, l - i);     printf( %I64d n , (l + 1) * (l + 2) * (l + 3) / 6 - tmp);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 50;   long long mod = 998244353;   int n, m, u, v;   vector<int> adj[N];   long long toAdd[N + N];   vector<pair<int, int> > q[N];   long long ans[N];   void dfs(int src, int par, int dep, long long sum) {     for (auto i : q[src]) {       toAdd[dep] += i.second;       toAdd[dep + i.first + 1] -= i.second;     }     sum += toAdd[dep];     ans[src] = sum;     for (auto i : adj[src])       if (i != par) dfs(i, src, dep + 1, sum);     for (auto i : q[src]) {       toAdd[dep] -= i.second;       toAdd[dep + i.first + 1] += i.second;     }   }   int main() {     scanf( %d , &n);     for (int i = 0; i < n - 1; ++i) {       scanf( %d%d , &u, &v);       adj[u].push_back(v);       adj[v].push_back(u);     }     scanf( %d , &m);     int d, x;     while (m--) {       scanf( %d%d%d , &v, &d, &x);       d = min(d, n);       q[v].push_back(make_pair(d, x));     }     dfs(1, 0, 0, 0);     for (int i = 1; i <= n; ++i) printf( %lld  , ans[i]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   long long a[200010] = {};   vector<int> e[200010];   long long t[200010] = {};   long long q[200010] = {};   int s, b;   long long ans = -222147483600ll;   bool cmp(long long x, long long y) { return x > y; }   void dfs(int x, int y) {     vector<long long> w;     t[x] += a[x];     q[x] = -2221483600ll;     for (int i = 0; i < e[x].size(); i++) {       if (e[x][i] == y) continue;       dfs(e[x][i], x);       t[x] += t[e[x][i]];       q[x] = max(q[x], q[e[x][i]]);       w.push_back(q[e[x][i]]);     }     sort(w.begin(), w.end(), cmp);     q[x] = max(t[x], q[x]);     if (w.size() >= 2) {       ans = max(w[0] + w[1], ans);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &a[i]);     }     for (int i = 1; i < n; i++) {       scanf( %d%d , &s, &b);       e[s].push_back(b);       e[b].push_back(s);     }     dfs(1, 0);     if (ans == -222147483600ll)       cout <<  Impossible  << endl;     else       cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   const int N = 1e5 + 5;   struct ooo {     int v, id;   } p[N << 1];   bool operator<(const ooo& a, const ooo& b) { return a.v < b.v; }   int n, ans, id, h, m, k, x;   int main() {     scanf( %d%d%d%d , &n, &h, &m, &k);     m /= 2;     for (int i = 1; i <= n; i++)       scanf( %d%d , &x, &p[i].v), p[i].v %= m, p[i].id = i;     std::sort(p + 1, p + 1 + n);     for (int i = 1; i <= n; i++) p[i + n] = p[i], p[i + n].v += m;     ans = 1e9;     x = -1;     for (int i = 1, j = 1; i <= n * 2; i++) {       while (p[i].v - p[j].v >= k) j++;       if (i > n && i - j < ans) ans = i - j, x = p[i].v;     }     printf( %d %d n , ans, x % m);     for (int i = 1; i <= n * 2; i++)       if (x - k < p[i].v && p[i].v < x) printf( %d  , p[i].id);   }
#include <bits/stdc++.h>   using namespace std;   using int64 = long long;   struct Primal_Dual {     const int INF = 1 << 30;     struct edge {       int to, cap, cost, rev;     };     vector<vector<edge> > graph;     vector<int> potential, min_cost, prevv, preve;     Primal_Dual(int V) : graph(V) {}     void add_edge(int from, int to, int cap, int cost) {       graph[from].push_back((edge){to, cap, cost, (int)graph[to].size()});       graph[to].push_back((edge){from, 0, -cost, (int)graph[from].size() - 1});     }     int min_cost_flow(int s, int t, int f) {       int V = graph.size(), ret = 0;       priority_queue<pair<int, int>, vector<pair<int, int> >,                      greater<pair<int, int> > >           que;       potential.assign(V, 0);       preve.assign(V, -1);       prevv.assign(V, -1);       while (f > 0) {         min_cost.assign(V, INF);         que.push(pair<int, int>(0, s));         min_cost[s] = 0;         while (!que.empty()) {           pair<int, int> p = que.top();           que.pop();           if (min_cost[p.second] < p.first) continue;           for (int i = 0; i < graph[p.second].size(); i++) {             edge &e = graph[p.second][i];             int nextCost = min_cost[p.second] + e.cost + potential[p.second] -                            potential[e.to];             if (e.cap > 0 && min_cost[e.to] > nextCost) {               min_cost[e.to] = nextCost;               prevv[e.to] = p.second, preve[e.to] = i;               que.push(pair<int, int>(min_cost[e.to], e.to));             }           }         }         if (min_cost[t] == INF) return -1;         for (int v = 0; v < V; v++) potential[v] += min_cost[v];         int addflow = f;         for (int v = t; v != s; v = prevv[v]) {           addflow = min(addflow, graph[prevv[v]][preve[v]].cap);         }         f -= addflow;         ret += addflow * potential[t];         for (int v = t; v != s; v = prevv[v]) {           edge &e = graph[prevv[v]][preve[v]];           e.cap -= addflow;           graph[v][e.rev].cap += addflow;         }       }       return ret;     }   };   int main() {     int N, B[100];     string S;     cin >> N;     cin >> S;     int sum[26] = {};     for (int i = 0; i < N; i++) {       sum[S[i] -  a ]++;     }     for (int i = 0; i < N; i++) {       cin >> B[i];     }     Primal_Dual flow(N / 2 + 28);     int s = N / 2 + 26, t = N / 2 + 27;     for (int i = 0; i < 26; i++) {       flow.add_edge(s, N / 2 + i, sum[i], 0);     }     for (int i = 0; i < N / 2; i++) {       flow.add_edge(i, t, 2, 0);     }     for (int i = 0; i < N / 2; i++) {       for (int j = 0; j < 26; j++) {         int ret = 0;         if (S[i] -  a  == j) ret = max(ret, B[i]);         if (S[N - i - 1] -  a  == j) ret = max(ret, B[N - i - 1]);         flow.add_edge(N / 2 + j, i, 1, -ret);       }     }     cout << -flow.min_cost_flow(s, t, N) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     string s;     cin >> s;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  W  && s[i + 1] ==  U  && s[i + 2] ==  B ) {         i += 2;         cout <<    ;       } else {         cout << s[i];       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void fastIO() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.precision(20);   }   int main() {     fastIO();     int n;     int m;     int total;     int day = 0;     cin >> n >> m;     while (n != 0) {       day++;       n = n - 1;       if (day % m == 0) {         n = n + 1;       }     }     cout << day << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, sum = 0;     cin >> n;     vector<long long int> v;     for (long long int i = 0; i < n; i++) {       long long int el;       cin >> el, sum += el;       v.push_back(el);     }     sum = sum / n;     long long int res = 0, curr = 0;     for (long long int i = 0; i < n; i++) {       curr += v[i] - sum;       (curr > 0) ? res += curr : res -= curr;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     long long int n, k;     cin >> n >> k;     string s;     cin >> s;     if (k == 0) {       cout << s;       return;     }     if (n == 1)       cout <<  0 ;     else {       if (s[0] >  1 ) {         s[0] =  1 ;         k--;       }       for (long long int i = 1; i < n && k > 0; i++) {         if (s[i] >  0 ) {           s[i] =  0 ;           k--;         }       }       cout << s;     }   }   signed main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     long long int t;     t = 1;     while (t--) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n;     cin >> n;     string s;     cin >> s;     int ans = 0;     int count = 0;     for (int i = 0; i < s.size(); i++) {       if (s[i] ==  ) ) {         ans--;         if (ans < 0) {           count++;           ans = 0;         }       } else {         ans++;       }     }     cout << count << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int t = 1;     cin >> t;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 4e18;   const long long MAX = 2e5 + 5;   const long long MOD = 1e9 + 7;   int n, m;   void exgcd(int a, int b, long long &c, long long &d) {     if (a == 0) {       c = 0;       d = 1;       return;     }     exgcd(b % a, a, d, c);     c -= b / a * d;   }   long long gcd(int a, int b) {     if (a == 0) return b;     return gcd(b % a, a);   }   int g[MAX];   bool arv[MAX], avb[MAX];   int sz[MAX];   pair<int, int> ma[MAX];   vector<int> v;   vector<int> son[MAX];   void build() {     for (int i = 0; i < m; i++) {       g[i] = gcd(i, m);       sz[g[i]]++;       son[g[i]].push_back(i);     }     g[m] = m;     int x = m;     for (int i = 2; i <= sqrt(x); i++) {       if (x % i == 0) v.push_back(i);       while (x % i == 0) x /= i;     }     if (x > 1) v.push_back(x);   }   void read() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cin >> n >> m;     build();     for (int i = 0; i < n; i++) {       int x;       cin >> x;       avb[x] = 1;       if (!x) avb[m] = 1;       sz[gcd(x, m)]--;     }   }   void dfs(long long x) {     if (arv[x]) return;     for (int i : v) {       if (i * x > m) break;       if (g[i * x] == i * x) {         dfs(i * x);         ma[x] = max(ma[x], {ma[i * x].first, i * x});       }     }     ma[x].first += sz[x];     ;     arv[x] = 1;   }   vector<int> ans;   void output() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout << ((long long)(ans).size()) <<   n ;     for (int i : ans) cout << i <<    ;     cout <<   n ;     ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     read();     for (int i = 1; i <= m; i++)       if (g[i] == i && !arv[i]) dfs(i);     long long now = 1, pre = 1;     long long cod;     while (now <= m) {       ;       for (long long i : son[now]) {         if (!avb[i]) {           long long r, y;           exgcd(pre, m, r, y);           if (r < 0) r += m;           ans.push_back(i / gcd(pre, m) * r % m);           pre = i;         }       }       if (ma[now].second)         now = ma[now].second;       else         break;     }     output();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct node {     int l, r;   } line[1000005];   int a[5000005], ls[5000005], b[5000005];   vector<node> ans;   bool cmp(node a, node b) { return a.l < b.l; }   int main() {     int n, k;     while (~scanf( %d %d , &n, &k)) {       memset(a, 0, sizeof(a));       memset(b, 0, sizeof(b));       ans.clear();       int p = 0;       for (int i = 1; i <= n; i++) {         int l, r;         scanf( %d %d , &l, &r);         line[i] = node{l, r};         ls[++p] = l;         ls[++p] = r;       }       sort(ls + 1, ls + p + 1);       p = unique(ls + 1, ls + p + 1) - (ls + 1);       for (int i = 1; i <= n; i++) {         int l = lower_bound(ls + 1, ls + p + 1, line[i].l) - ls;         int r = lower_bound(ls + 1, ls + p + 1, line[i].r) - ls;         a[l]++;         a[r]--;         b[l]++;         b[r + 1]--;       }       for (int i = 1; i <= p; i++) {         a[i] = a[i - 1] + a[i];         b[i] = b[i - 1] + b[i];       }       for (int i = 0; i <= p; i++) {         if (a[i] >= k) {           int r = i + 1;           while (a[r] >= k) {             r++;           }           ans.push_back(node{ls[i], ls[r]});           i = r - 1;         }         if (a[i - 1] < k && a[i] < k && b[i] >= k) {           ans.push_back(node{ls[i], ls[i]});         }       }       sort(ans.begin(), ans.end(), cmp);       printf( %d n , ans.size());       for (int i = 0; i < (int)ans.size(); i++) {         printf( %d %d n , ans[i].l, ans[i].r);       }     }   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long i, j, m, a, s, c, b, n, x, y, ar[1001];     cin >> n;     while (n--) {       cin >> s >> a >> b >> c;       x = s / c;       y = x / a * b;       cout << x + y << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using vi = vector<int>;   using pi = pair<int, int>;   const int mxn = 2e5;   int n;   string ar[mxn];   void solve() {     cin >> n;     for (int i = 0; i < n; ++i) cin >> ar[i];     set<string> second;     for (int i = n - 1; i >= 0; --i) {       if (second.count(ar[i])) continue;       cout << ar[i] <<   n ;       second.insert(ar[i]);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     int t;     t = 1;     while (t--) solve();   }
#include <bits/stdc++.h>   using namespace std;   int32_t main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int x;     cin >> x;     while (x--) {       int n, m, ans = 0;       cin >> n >> m;       char a[n][m];       for (int i = 0; i < n; i++) {         for (int j = 0; j < m; j++) cin >> a[i][j];       }       int i = n - 1;       for (int j = 0; j < m - 1; j++) {         if (a[i][j] ==  D ) ans++;       }       int j = m - 1;       for (i = 0; i < n - 1; i++) {         if (a[i][j] ==  R ) ans++;       }       cout << ans << endl;     }     return 0;   }