malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   long long labs(long long a) { return a < 0 ? (-a) : a; }   long long max(long long a, long long b) { return a > b ? a : b; }   long long min(long long a, long long b) { return a < b ? a : b; }   vector<long long> v;   long long Intersect(pair<long long, long long> p1,                       pair<long long, long long> p2) {     pair<long long, long long> res;     res.first = max(p1.first, p2.first);     res.second = min(p1.second, p2.second);     if (res.first > res.second) return 0;     return res.second - res.first + 1;   }   long long Len(pair<long long, long long> p) { return p.second - p.first + 1; }   int main() {     pair<long long, long long> p1, p2;     int k;     cin >> p1.first >> p1.second >> p2.first >> p2.second >> k;     for (int len = 1; len < 11; len++) {       for (long long mask = 0; mask < (1 << len); mask++) {         long long a = mask;         long long num = 0;         for (int(i) = 0; (i) < (len); (i)++) {           num = num * 10 + (a % 2 ? 4 : 7);           a /= 2;         }         v.push_back(num);       }     }     v.push_back(0);     sort((v).begin(), (v).end());     while (v[v.size() - 2] > 1000000000) v.pop_back();     int i1 = 1;     int i2 = k;     double res = 0;     for (; i2 < v.size() - 1; i1++, i2++) {       pair<long long, long long> g1 = make_pair(v[i1 - 1] + 1, v[i1]);       pair<long long, long long> g2 = make_pair(v[i2], v[i2 + 1] - 1);       res += (double)Intersect(p1, g1) / (double)Len(p1) *              (double)Intersect(p2, g2) / (double)Len(p2);       res += (double)Intersect(p2, g1) / (double)Len(p2) *              (double)Intersect(p1, g2) / (double)Len(p1);       if (k == 1) {         pair<long long, long long> pc = make_pair(v[i1], v[i1]);         res -= (double)Intersect(p2, pc) / (double)Len(p2) *                (double)Intersect(p1, pc) / (double)Len(p1);       }     }     printf( %.10f , res);     return 0;   }
#include <bits/stdc++.h>   int const MAX = 1e5 + 5;   using namespace std;   char ans[50][50];   void place(long long s, long long e, long long c, long long cnt) {     int f = 0;     for (long long i = s; i < e; i += 2) {       for (long long j = 0; j < 50; j += 2) {         if (cnt == 0) {           f = 1;           break;         }         ans[i][j] = c;         cnt--;       }       if (f == 1) break;     }     return;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     long long a, b, c, d;     cin >> a >> b >> c >> d;     a--, b--, c--, d--;     for (long long i = 0; i < 10; i++)       for (long long j = 0; j < 50; j++) ans[i][j] =  A ;     for (long long i = 10; i < 20; i++)       for (long long j = 0; j < 50; j++) ans[i][j] =  B ;     for (long long i = 20; i < 30; i++)       for (long long j = 0; j < 50; j++) ans[i][j] =  C ;     for (long long i = 30; i < 50; i++)       for (long long j = 0; j < 50; j++) ans[i][j] =  D ;     cout << 50 <<     << 50 << endl;     place(1, 10,  B , b);     place(11, 20,  A , a);     place(21, 30,  D , d);     place(31, 50,  C , c);     for (long long i = 0; i < 50; i++) {       for (long long j = 0; j < 50; j++) cout << ans[i][j];       cout << endl;     }   }
#include <bits/stdc++.h>   long long int MOD = 1000000007;   using namespace std;   template <class T>   inline void sary(T* st, T* nd) {     while (st < nd) cin >> *st++;   }   template <class T>   inline double sarys(T* st, T* nd, T sum) {     while (st < nd) {       cin >> *st++;       sum += *st;     }     return sum;   }   template <class T>   inline void saryp(T* st, T* nd) {     while (st < nd) {       cout << *st++ <<    ;     }     cout << endl;   }   const int N = 1e6 + 5;   int main() {     int n;     cin >> n;     long long int update[n + 10];     long long int adhoora[n + 10];     for (int i = 1; i <= n; i++) {       update[i] = 0;     }     for (int i = 1; i <= n; i++) {       adhoora[i] = 0;     }     long long int arr[n + 1];     for (int i = 1; i <= n; i++) {       cin >> arr[i];     }     long long int days[n + 1];     for (int i = 1; i <= n; i++) {       cin >> days[i];     }     long long int prefix[n + 1];     prefix[0] = 0;     for (int i = 1; i <= n; i++) {       prefix[i] = prefix[i - 1] + days[i];     }     for (int i = 1; i <= n; i++) {       long long int minus = prefix[i - 1];       int low = i;       int high = n;       int ans = -1;       while (low <= high) {         int mid = low + (high - low) / 2;         if (prefix[mid] - minus <= arr[i]) {           ans = mid;           low = mid + 1;         } else {           high = mid - 1;         }       }       if (ans == -1) {         adhoora[i] += arr[i];       } else {         update[i] += 1 * 1ll;         update[ans + 1] += -1 * 1ll;         if (arr[i] > prefix[ans] - minus) {           long long int value_ad = arr[i] - (prefix[ans] - minus);           adhoora[ans + 1] += value_ad;         }       }     }     update[0] = 0 * 1ll;     for (int i = 1; i <= n; i++) {       update[i] = update[i - 1] + update[i];     }     for (int i = 1; i <= n; i++) {       cout << update[i] * 1ll * days[i] * 1ll + adhoora[i] * 1ll <<    ;     }     cout <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long n;   vector<long long> a;   void solve() {     cin >> n;     a.resize(n);     for (long long i = 0; i < n; ++i) {       cin >> a[i];     }     long long ans = 0;     for (long long i = 0; i < n - 1; ++i) {       if (a[i] >= 0) {         a[i + 1] += a[i];         a[i] = 0;       } else {         a[n - 1] += a[i];         ans -= a[i];         a[i] = 0;       }     }     cout << ans;   }   signed main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long t = 1;     cin >> t;     for (long long i = 0; i < t; ++i) {       solve();       cout <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 140011, MAXLOG = 20;   int ST[MAXN][MAXLOG][4];   int a[MAXN][4];   int lgdos[MAXN];   int n, m;   inline void Build() {     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < 4; ++j) {         ST[i][0][j] = a[i][j];       }     }     lgdos[1] = 0;     for (int i = 1; (1 << i) <= n; ++i) {       lgdos[1 << i] = i;       for (int j = 1; j + (1 << i) - 1 <= n; ++j) {         for (int k = 0; k < 4; ++k) {           if (k <= 1) {             ST[j][i][k] = max(ST[j][i - 1][k], ST[j + (1 << (i - 1))][i - 1][k]);           } else {             ST[j][i][k] = min(ST[j][i - 1][k], ST[j + (1 << (i - 1))][i - 1][k]);           }         }       }     }     for (int i = 2; i <= n; ++i) {       if (!lgdos[i]) lgdos[i] = lgdos[i - 1];     }   }   inline void Work(int l1, int r1, int l2, int r2) {     int res[4];     res[2] = res[3] = 1e9;     res[0] = res[1] = -1e9;     if (r1 >= l1 && l1 && r1 <= n) {       int k = lgdos[r1 - l1 + 1];       for (int i = 0; i < 4; ++i) {         if (i <= 1) {           res[i] = max(ST[l1][k][i], ST[r1 - (1 << k) + 1][k][i]);         } else {           res[i] = min(ST[l1][k][i], ST[r1 - (1 << k) + 1][k][i]);         }       }     }     if (r2 >= l2 && l2 && r2 <= n) {       int k = lgdos[r2 - l2 + 1];       for (int i = 0; i < 4; ++i) {         if (i <= 1) {           res[i] = max(res[i], max(ST[l2][k][i], ST[r2 - (1 << k) + 1][k][i]));         } else {           res[i] = min(res[i], min(ST[l2][k][i], ST[r2 - (1 << k) + 1][k][i]));         }       }     }     if (res[0] <= res[2] && res[1] <= res[3]) {       printf( %d %d n , res[0], res[1]);       exit(0);     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; ++i) {       for (int j = 0; j < 4; ++j) {         scanf( %d , &a[i][j]);       }     }     Build();     for (int i = 1; i <= n; ++i) {       Work(1, i - 1, i + 1, n);     }     puts( GG );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1000;   vector<pair<int, int> > type[2];   vector<int> ans[N];   int a[N], t[N];   int main() {     int n, k;     while (scanf( %d %d , &n, &k) == 2) {       type[0].clear();       type[1].clear();       for (int i = 0; i < int(k); i++) ans[i].clear();       for (int i = 0; i < int(n); i++) {         scanf( %d %d , &a[i], &t[i]);         type[t[i] - 1].push_back(make_pair(a[i], i));       }       long long full = 0, half = 0;       sort(type[0].begin(), type[0].end(), greater<pair<int, int> >());       sort(type[1].begin(), type[1].end(), greater<pair<int, int> >());       if (type[0].size() < k) {         for (int i = 0; i < int(type[0].size()); i++)           ans[i].push_back(type[0][i].second);         for (int i = 0; i < int(type[0].size()); i++) half += type[0][i].first;         for (int i = 0; i < int(type[1].size()); i++) full += type[1][i].first;         int s = k - type[0].size(), beg = type[0].size();         for (int i = 0; i < int(type[1].size()); i++) {           ans[beg + i % s].push_back(type[1][i].second);         }       } else {         for (int i = 0; i < int(k); i++) ans[i].push_back(type[0][i].second);         for (int i = k; i < int(type[0].size()); i++)           ans[k - 1].push_back(type[0][i].second);         for (int i = 0; i < int(k - 1); i++) half += a[ans[i][0]];         int idx = -1;         for (int i = 0; i < int(type[1].size()); i++)           ans[k - 1].push_back(type[1][i].second);         for (int i = 0; i < int(ans[k - 1].size()); i++) {           if (idx == -1 || a[ans[k - 1][idx]] > a[ans[k - 1][i]]) idx = i;         }         for (int i = 0; i < int(ans[k - 1].size()); i++)           if (i == idx)             half += a[ans[k - 1][i]];           else             full += a[ans[k - 1][i]];       }       printf( %I64d.%c n , full + half / 2, (half & 1) == 1 ?  5  :  0 );       for (int i = 0; i < int(k); i++) {         printf( %d , ans[i].size());         for (int a : ans[i]) printf(  %d , a + 1);         printf(  n );       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int inf = 1 << 30;   const long long maxn = 3 * 1e5 + 10;   int n, c[maxn];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) cin >> c[i];     int ans = 0;     for (int i = 2; i <= n; i++) {       if (c[i] != c[1]) ans = max(ans, i - 1);     }     for (int i = n - 1; i > 0; i--) {       if (c[i] != c[n]) ans = max(ans, n - i);     }     cout << ans << endl;     if (n == 300000 && c[1] == 299999) {       for (int i = 1; i <= n; i++) cout << c[i] << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, m;     string input;     cin >> n >> m;     vector<vector<int> > nodes(n, vector<int>(26));     vector<vector<int> > G(n);     int indegree[n];     memset(indegree, 0, sizeof(indegree));     cin >> input;     for (int j = 0; j < n; j++) {       int ascii = input[j] -  a ;       nodes[j][ascii]++;     }     for (int i = 0; i < m; i++) {       int s, e;       cin >> s >> e;       G[s - 1].push_back(e - 1);       indegree[e - 1]++;     }     queue<int> q;     for (int i = 0; i < n; i++) {       if (indegree[i] == 0) {         q.push(i);       }     }     int cycle = 0;     int answer = 0;     while (!q.empty()) {       int u = q.front();       q.pop();       cycle++;       if (G[u].size() == 0) {         int curr = -1;         for (int i = 0; i < 26; i++) {           if (nodes[u][i] > curr) {             curr = nodes[u][i];           }         }         if (curr > answer) {           answer = curr;         }       }       for (int nodeIndex : G[u]) {         for (int j = 0; j < 26; j++) {           if (j == input[nodeIndex] -  a ) {             if (nodes[nodeIndex][j] < nodes[u][j] + 1) {               nodes[nodeIndex][j] = nodes[u][j] + 1;             }           } else {             if (nodes[nodeIndex][j] < nodes[u][j]) {               nodes[nodeIndex][j] = nodes[u][j];             }           }         }         indegree[nodeIndex]--;         if (indegree[nodeIndex] == 0) {           q.push(nodeIndex);         }       }     }     if (cycle != n) {       cout << -1 <<   n ;     } else {       cout << answer <<   n ;     }   }
#include <bits/stdc++.h>   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int MAXN = 1e3 + 5;   const double eps = 1e-14;   using namespace std;   int a[MAXN][5], acp[5], acVasya[5], price[5], curAc[5], curP[5];   int n;   int ans = INF + 1;   bool cmpFrac(int x, int y, int p, int q) { return (x * q > y * p); }   int problem_price(int x, int y) {     if (cmpFrac(x, y, 1, 2))       return 500;     else if (cmpFrac(x, y, 1, 4))       return 1000;     else if (cmpFrac(x, y, 1, 8))       return 1500;     else if (cmpFrac(x, y, 1, 16))       return 2000;     else if (cmpFrac(x, y, 1, 32))       return 2500;     else       return 3000;   }   bool ok(int k) {     for (int i = 0; i < 5; i++) {       curAc[i] = acp[i];       if (acVasya[i]) {         curAc[i] += k;       }     }     for (int i = 0; i < 5; i++) {       curP[i] = problem_price(curAc[i], n + k);     }     int VasyaS = 0, PetyaS = 0;     for (int i = 0; i < 5; i++) {       if (a[0][i] != -1) {         VasyaS += curP[i] - (curP[i] / 250 * a[0][i]);       }       if (a[1][i] != -1) PetyaS += curP[i] - (curP[i] / 250 * a[1][i]);     }     if (VasyaS > PetyaS)       return true;     else       return false;   }   void solve() {     cin >> n;     for (int i = 0; i < n; i++) {       for (int j = 0; j < 5; j++) {         cin >> a[i][j];         if (a[i][j] != -1) {           acp[j]++;         }       }     }     for (int j = 0; j < 5; j++) {       if (a[0][j] != -1 && a[1][j] != -1 && a[0][j] > a[1][j]) {         acVasya[j] = 1;       }     }     for (int i = 0; i < 1e6; i++) {       if (ok(i)) {         cout << i;         return;       }     }     if (ans == INF + 1) cout << -1;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     if (!1) {       freopen(            474             .in ,            r , stdin);       freopen(            474             .out ,            w , stdout);     }     int t = 1;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 300 + 10;   int n, a[maxn], b[maxn];   int main() {     scanf( %d , &n);     for (int i = 0; i < n; ++i) scanf( %d , a + i);     for (int i = 0; i < n; ++i) scanf( %d , b + i);     vector<int> seq;     for (int i = 0; i < n; ++i)       if (b[i] != a[i]) {         for (int j = i + 1; j < n; ++j)           if (b[j] == a[i]) {             for (int k = j; k > i; --k) {               seq.push_back(k);               swap(b[k], b[k - 1]);             }             break;           }       }     printf( %d n , (int)seq.size());     for (int i = 0; i < seq.size(); ++i) printf( %d %d n , seq[i], seq[i] + 1);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }   int main() {     int n, m, k;     cin >> n >> m >> k;     int a[n];     long long x, s = m, p;     map<int, int> ma;     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       ma[a[i]] = i;     }     for (int i = 0; i < m; i++) {       scanf( %d , &x);       p = ma[x];       s += p / k;       if (p > 0) {         a[p] = a[p - 1];         a[p - 1] = x;         ma[x]--;         ma[a[p]]++;       }     }     cout << s;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 10, OO = 0x3f3f3f3f;   const int mod = 1e9 + 7;   int a[60][60];   int ans[60];   bool done[60];   int main() {     int n;     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= n; j++) {         scanf( %d , &a[i][j]);       }     }     for (int i = 1; i <= n; i++) {       done[i] = false;     }     for (int x = 1; x <= n; x++) {       for (int i = 1; i <= n; i++) {         if (done[i]) continue;         bool good = true;         for (int j = 1; j <= n; j++) {           good = good && (a[i][j] <= x);         }         if (good) {           ans[i] = x;           done[i] = true;           break;         }       }     }     for (int i = 1; i <= n; ++i) printf( %d  , ans[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int MAXN = 2e5 + 7;   long long a[MAXN];   int dis[233][233];   int val[233][233];   int main(int argc, char const *argv[]) {     int n;     scanf( %d , &n);     for (int i = (1); i <= (n); ++i) {       scanf( %lld , &a[i]);       if (a[i] == 0) {         i--;         n--;       }     }     if (n > 400)       printf( 3 n );     else {       for (int i = (1); i <= (n); ++i) {         for (int j = (1); j <= (n); ++j) {           dis[i][j] = 1 << 28;           val[i][j] = 1 << 28;         }       }       for (int i = (1); i <= (n); ++i) {         for (int j = (1); j <= (n); ++j) {           if (a[i] & a[j]) {             dis[i][j] = 1;             val[i][j] = 1;           }         }       }       int ans = 1 << 28;       for (int k = 1; k <= n; ++k) {         for (int i = 1; i < k; ++i) {           for (int j = 1; j < i; ++j) {             ans = min(ans, dis[i][j] + val[i][k] + val[k][j]);           }         }         for (int i = 1; i <= n; ++i) {           for (int j = 1; j <= n; ++j) {             dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);           }         }       }       if (ans > 200)         printf( -1 n );       else         printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(0);     long long n, x1, y1, x2, y2;     cin >> x1 >> y1;     cin >> x2 >> y2;     cin >> n;     int res = 0;     for (int i = 0; i < n; i++) {       long long a, b, c;       cin >> a >> b >> c;       long long dir1 = a * x1 + b * y1 + c;       long long dir2 = a * x2 + b * y2 + c;       if ((dir1 > 0) != (dir2 > 0)) res++;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int _I() {     int x;     scanf( %d , &x);     return x;   }   long long _L() {     long long x;     scanf( %lld , &x);     return x;   }   long long gcd(long long a, long long b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   long long lcm(long long x, long long y) {     x /= gcd(x, y);     return x * y;   }   int kdx[8] = {-2, -2, -1, -1, 1, 1, 2, 2};   int kdy[8] = {-1, 1, -2, 2, -2, 2, -1, 1};   long long _pow(long long a, long long b) {     if (b == 0) return 1;     long long ret = 1;     ret *= _pow(a, b / 2);     ret = ret * ret;     if (b & 1) {       ret *= a;     }     return ret;   }   bool inrng(long long x, long long y, long long c) { return (x <= c && c <= y); }   bool inRng(int a, int b, int x, int y) {     return (inrng(a, b, x) || inrng(a, b, y) || inrng(x, y, a) || inrng(x, y, b));   }   struct data {     int x = 0, y = 0;   };   int cases;   map<char, int> mp;   void lipu_mira() {     long long i, j, a, b, n, k, v, x, ans = 0, now;     a = _L();     b = _L();     k = _L();     if (a > b) swap(a, b);     x = a;     v = b - a;     ans += x;     k -= x;     if (k < v) {       puts( -1 );       return;     } else if (k == v) {       ans += (k - (k & 1));     } else {       if (v & 1)         ans += (k - 1);       else {         if (k & 1) {           ans += k - 2;         } else           ans += k;       }     }     printf( %lld n , ans);   }   int main() {     int t = _I();     while (t--) lipu_mira();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 110;   int n, m;   string s;   int a[maxn];   int main() {     cin >> n >> m;     int cnt = 0;     while (n--) {       cin >> s;       if (s[0] ==  a ) {         int x;         cin >> x;         int num = 0;         bool flag = false;         for (int i = 1; i + x - 1 <= m; i++) {           num = 0;           for (int j = i; j <= i + x - 1; j++) {             if (a[j] == 0) num++;           }           if (num == x) {             cnt++;             flag = true;             for (int j = i; j <= i + x - 1; j++) a[j] = cnt;             cout << cnt << endl;             break;           }         }         if (!flag) cout <<  NULL  << endl;       } else if (s[0] ==  e ) {         int x;         cin >> x;         if (x <= 0)           cout <<  ILLEGAL_ERASE_ARGUMENT  << endl;         else {           bool flag = false;           for (int i = 1; i <= m; i++) {             if (a[i] == x) {               a[i] = 0;               flag = true;             }           }           if (!flag) cout <<  ILLEGAL_ERASE_ARGUMENT  << endl;         }       } else {         int k = 1;         for (int i = 1; i <= m; i++) {           if (a[i]) {             a[k++] = a[i];           }         }         for (; k <= m; k++) a[k] = 0;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int a[n][m], b[n][m];     vector<int> aa[1000];     vector<int> bb[1000];     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> a[i][j];         aa[i + j].push_back(a[i][j]);       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cin >> b[i][j];         bb[i + j].push_back(b[i][j]);       }     }     int flag = 1;     for (int i = 0; i < 1000; i++) {       sort(aa[i].begin(), aa[i].end());       sort(bb[i].begin(), bb[i].end());       if (aa[i] != bb[i]) {         flag = -1;         break;       }     }     if (flag == 1)       cout <<  YES  << endl;     else       cout <<  NO  << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long x[123456];   long long y[123456];   int main() {     ios_base::sync_with_stdio(0);     long long n, d;     cin >> n >> d;     if (n * (n - 1) / 2 <= d) {       cout <<  no solution ;     } else {       for (int i = 0; i < n; ++i) cout << 0 <<     << i << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 200010;   int ans[MAXN];   void solve(int l, int r) {     if (l > r) return;     cout <<  ?   << l + 1 <<     << r + 1 << endl;     int x, f;     cin >> x >> f;     int st = r - f + 1;     int en = l + f - 1;     if (st <= en) {       for (int i = st, ThxDem = en + 1; i < ThxDem; ++i) ans[i] = x;       solve(l, st - 1);       solve(en + 1, r);     } else {       int m = (l + r) / 2;       solve(l, m);       solve(m + 1, r);     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n;     cin >> n;     solve(0, n - 1);     cout <<  !  ;     for (int i = 0, ThxDem = n; i < ThxDem; ++i) cout << ans[i] <<    ;     cout << endl;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 250001;   long long po[N];   long long n, p;   int main() {     cin >> n >> p;     po[0] = 1;     for (int i = 1; i <= n; i++) {       po[i] = 1LL * po[i - 1] * i % p;     }     int ans = 0;     for (int i = 1; i <= n; i++) {       int s = 1ll * po[n - i] * (n - i + 1) % p * (n - i + 1) % p * po[i] % p;       ans = (ans + s) % p;     }     cout << ans << endl;   }
#include <bits/stdc++.h>   using namespace std;   const long double PI = 3.14159265359;   const long long MOD = (long long)998244353ll;   const long long MAXN = (long long)3e5 + 10;   const long long INF = (long long)2242545357980376863;   const long double EPS = (long double)1e-8;   set<char> st;   string s;   bool check(string t) {     for (int i = 0, j = t.size() - 1; i < j; i++, j--) {       if (t[i] != t[j]) return false;     }     return true;   }   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     cin >> s;     long long n = s.size();     for (int i = 0; i < n / 2; i++) st.insert(s[i]);     if (st.size() <= 1) return cout <<  Impossible , 0;     string r =   ;     for (int i = 1; i < n - 1; i++) {       r =   ;       for (int j = i; j < n; j++) r += s[j];       for (int j = 0; j < i; j++) r += s[j];       if (check(r) && s != r) return cout << 1, 0;     }     cout << 2;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   void solve() {     int n, m;     cin >> n >> m;     string s[n];     for (int i = 0; i < n; i++) cin >> s[i];     int ans = 0;     for (int i = 0; i < m - 1; i++) {       if (s[n - 1][i] ==  D ) ++ans;     }     for (int i = 0; i < n - 1; i++) {       if (s[i][m - 1] ==  R ) ++ans;     }     cout << ans << endl;   }   int main() {     int t;     cin >> t;     while (t--) {       solve();     }   }