malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   set<string> a, b, c;   void solve() {     cin >> n >> m;     for (int i = 1; i <= n; i++) {       string s;       cin >> s;       a.insert(s);     }     for (int i = 1; i <= m; i++) {       string s;       cin >> s;       if (a.count(s)) c.insert(s);       b.insert(s);     }     while (1) {       if (a.empty()) {         cout <<  NO n ;         return;       }       if (!c.empty()) {         a.erase(*c.begin());         b.erase(*c.begin());         c.erase(c.begin());       } else {         if (b.count(*a.begin())) b.erase(*a.begin());         a.erase(a.begin());       }       if (b.empty()) {         cout <<  YES n ;         return;       }       if (!c.empty()) {         a.erase(*c.begin());         b.erase(*c.begin());         c.erase(c.begin());       } else {         if (a.count(*b.begin())) a.erase(*b.begin());         b.erase(b.begin());       }     }   }   int main() {     int t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, d, res = 0, a = 0, b;     cin >> n >> d;     for (int i = 0; i < n; i++) {       cin >> b;       if (a >= b) {         res += ceil((a - b + 1) / (double)d);         b += ceil((a - b + 1) / (double)d) * d;       }       a = b;     }     cout << res << endl;   }
#include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > g[100010];   int N, K, in[100010], dp[100010][2];   vector<pair<int, int> > num[100010];   void dfs(int u, int fa) {     for (pair<int, int>& e : g[u]) {       int v = e.first, cost = e.second;       if (v == fa) continue;       dfs(v, u);       num[u].push_back(pair<int, int>(dp[v][1] + cost, v));     }     sort(num[u].begin(), num[u].end(), greater<pair<int, int> >());     dp[u][1] = 0;     int sum = 0;     for (size_t i = 0; (int)i < K - 1 && i < num[u].size(); i++) {       dp[u][1] += num[u][i].first;       sum += num[u][i].first;     }     if ((int)num[u].size() <= K - 1) {       for (size_t i = 0; i < num[u].size(); i++) {         int v = num[u][i].second;         dp[u][0] = max(dp[u][0], sum - dp[v][1] + dp[v][0]);       }     } else {       for (size_t i = 0; i < (int)K - 1; i++) {         int v = num[u][i].second;         dp[u][0] = max(dp[u][0], sum + num[u][K - 1].first - dp[v][1] + dp[v][0]);       }       for (size_t i = K - 1; i < num[u].size(); i++) {         int v = num[u][i].second;         dp[u][0] = max(dp[u][0], sum + num[u][i].first - dp[v][1] + dp[v][0]);       }     }   }   int main() {     int u, v, c;     scanf( %d%d , &N, &K);     for (int i = 1; i < N; i++) {       scanf( %d%d%d , &u, &v, &c);       g[u].push_back(pair<int, int>(v, c));       g[v].push_back(pair<int, int>(u, c));     }     dfs(0, -1);     printf( %d n , max(dp[0][0], dp[0][1]));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long GCD(long long a, long long b) {     while (b) b ^= a ^= b ^= a %= b;     return a;   }   long long LCM(long long a, long long b) { return a * (b / GCD(a, b)); }   const double EPS = 10e-9;   const long long INF = (1LL << 30);   using namespace std;   template <typename T>   string toString(T t) {     stringstream ss;     ss << t;     return ss.str();   }   long long isSquare(long long N) {     long long lo = 1, hi = 2 * sqrt(N);     while (hi - lo > 1) {       long long mid = (hi + lo) >> 1;       long long res = mid * mid;       if (res < N) {         lo = mid;       } else if (res > N) {         hi = mid;       } else {         return mid;       }     }     return lo;   }   int main() {     long long N;     cin >> N;     if (N % 3 != 0) {       cout << 0 << endl;     } else {       N /= 3;       int options = 0;       for (long long i = 1; i * i * i <= N; i++) {         if (N % i == 0) {           long long left = N / i, to = i / 2;           for (long long a = 1; a <= to; a++) {             long long c = i - a;             long long d = (a - c) * (a - c);             long long sqr = isSquare(d + 4 * left);             if (sqr * sqr == d + 4 * left) {               long long b = (-(a + c) + sqr) >> 1;               if (c <= b) {                 if (a == c) {                   if (b == c) {                     options += 1;                   } else {                     options += 3;                   }                 } else {                   if (b == c) {                     options += 3;                   } else {                     options += 6;                   }                 }               }             }           }         }       }       cout << options << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long int mod = 1000000007;   const long long int inf = 1e17;   const long long int N = 5005;   long long int n;   long long int a[N];   long long int dp[N][N];   long long int go(long long int idx, long long int flag) {     long long int &ans = dp[idx][flag];     if (ans != -1) return ans;     if (idx > n) {       return 0;     }     if (flag == 0 or flag == 2) {       ans = max(go(idx + 1, flag), go(idx + 1, flag + 1)) + a[idx];     } else {       ans = max(go(idx + 1, flag), go(idx + 1, flag + 1)) - a[idx];     }     return ans;   }   vector<long long int> res;   void backtrack(long long int idx, long long int flag) {     if (idx > n) {       return;     }     if (flag == 0 or flag == 2) {       long long int tmp1 = go(idx + 1, flag) + a[idx];       long long int tmp2 = go(idx + 1, flag + 1) + a[idx];       res.push_back(1);       if (tmp1 >= tmp2) {         backtrack(idx + 1, flag);       } else {         backtrack(idx + 1, flag + 1);       }     } else {       long long int tmp1 = go(idx + 1, flag) - a[idx];       long long int tmp2 = go(idx + 1, flag + 1) - a[idx];       res.push_back(0);       if (tmp1 >= tmp2) {         backtrack(idx + 1, flag);       } else {         backtrack(idx + 1, flag + 1);       }     }   }   int32_t main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     memset(dp, -1, sizeof(dp));     cin >> n;     for (long long int i = 1; i <= n; i++) {       cin >> a[i];     }     long long int ans = go(0, 0);     backtrack(0, 0);     res.erase(res.begin());     long long int cnt = 0, idx = 0;     while (res[idx] and idx < n) {       cnt++;       idx++;     }     vector<long long int> vec;     vec.push_back(cnt);     cnt = 0;     idx = vec.back();     while (idx < n and !res[idx]) {       cnt++;       idx++;     }     vec.push_back(cnt);     idx = vec[0] + vec[1];     cnt = 0;     while (idx < n and res[idx]) {       cnt++;       idx++;     }     vec.push_back(cnt);     idx = 0, cnt = 0;     for (auto to : vec) {       cnt = to;       if (cnt == 0LL) {         cout << idx <<    ;       } else {         cout << idx + cnt <<    ;         idx += cnt;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 2e5 + 10;   bool chk(string s) {     int l = s.size();     for (int i = 0, j = l - 1; i <= j; i++, j--) {       if (s[i] != s[j]) return false;     }     return true;   }   int main() {     int t;     cin >> t;     while (t--) {       string s;       cin >> s;       string ans;       int mx = 0;       string res;       for (int i = 0; i < s.size(); i++) {         ans += s[i];         if (chk(ans)) {           int l = ans.size();           if (l > mx) {             mx = ans.size();             res = ans;           }         }       }       ans =   ;       for (int i = s.size() - 1; i >= 0; i--) {         ans += s[i];         if (chk(ans)) {           int l = ans.size();           if (l > mx) {             mx = ans.size();             res = ans;           }         }       }       int p1 = 0;       int p2 = 0;       for (int i = 0, j = s.size() - 1; i < j; i++, j--) {         if (s[i] != s[j]) {           p1 = i - 1;           p2 = j + 1;           break;         }       }       ans =   ;       string rev =   ;       for (int i = 0; i <= p1; i++) ans += s[i];       for (int i = p2; i < s.size(); i++) rev += s[i];       string ss =   ;       for (int i = p1 + 1; i < p2; i++) {         ss += s[i];         string tmp = ans + ss + rev;         int l = tmp.size();         if (l <= mx) continue;         if (chk(tmp)) {           if (l > mx) {             mx = l;             res = tmp;           }         }       }       ss =   ;       for (int j = p2 - 1; j > p1; j--) {         ss = s[j] + ss;         string tmp = ans + ss + rev;         int l = tmp.size();         if (chk(tmp)) {           if (l > mx) {             mx = l;             res = tmp;           }         }       }       cout << res << endl;     }     return 0;   }
#include <bits/stdc++.h>   int main() {     int n, m;     scanf( %d%d , &n, &m);     int num = n + m;     int a = m / 2, aa = m % 2, aaa = a + aa;     if (n == m) {       for (int i = 0; i < n; i++) {         printf( 01 );       }     } else if (n < m) {       if (aaa <= n + 1) {         a = m - (n + 1);         m -= a;         for (int i = 0; n; i++) {           if (a) {             printf( 11 );             a--;           } else if (m) {             printf( 1 );             m--;           }           if (n) {             printf( 0 );             n--;           }         }         if (a)           printf( 11 );         else if (m)           printf( 1 );       } else         printf( -1 );     } else if (n > m) {       if (n <= m + 1) {         for (int i = 0; i < m; i++) {           printf( 01 );         }         printf( 0 );       } else         printf( -1 );     }     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long k, d, t;   int main() {     scanf( %lld%lld%lld , &k, &d, &t);     t *= 2;     long long round = ceil((double)k / d) * d;     long long num = k * 2 + (round - k);     long long cnt = t / num;     long long left = t - cnt * num;     double ans = 0.0;     if (left <= k * 2) {       ans = cnt * round + left / 2;       if (left % 2) ans += 0.5;     } else       ans = cnt * round + k + (left - k * 2);     printf( %.1lf n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int head, tail, n, q[100100];   long long f[100100], a[100100], b[100010];   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) scanf( %I64d , &a[i]);     for (int i = 1; i <= n; i++) scanf( %I64d , &b[i]);     f[1] = 0;     head = tail = 1;     q[head] = 1;     for (int i = 2; i <= n; i++) {       while (head < tail) {         if ((1.0 * f[q[head]] + 1.0 * a[i] * b[q[head]]) >             (1.0 * f[q[head + 1]] + 1.0 * a[i] * b[q[head + 1]]))           head++;         else           break;       }       f[i] = f[q[head]] + b[q[head]] * a[i];       while (head < tail) {         if (1.0 * (f[q[tail]] - f[q[tail - 1]]) * (b[q[tail]] - b[i]) >             1.0 * (f[i] - f[q[tail]]) * (b[q[tail - 1]] - b[q[tail]]))           tail--;         else           break;       }       q[++tail] = i;     }     printf( %I64d , f[n]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MOD = 998244353;   const int N = 5005;   void update(int &a, int b) {     a += b;     a %= MOD;   }   int add(int a, int b) { return (a + b) % MOD; }   int multiply(int a, int b) { return (a * 1LL * b) % MOD; }   int quick_power(int a, int n) {     int res = 1;     for (; n > 0; n >>= 1) {       if (n & 1) res = multiply(res, a);       a = multiply(a, a);     }     return res;   }   int get_inv(int a) { return quick_power(a, MOD - 2); }   int n, a;   int cnt[N], sum[N][N], dp[N][N];   int main() {     cin >> n;     for (int i = 1; i <= n; i++) {       cin >> a;       cnt[a]++;     }     for (int i = 0; i <= n; i++) {       sum[0][i] = 1;     }     int answer = 0;     for (int i = 1; i <= n; i++) {       int inv = get_inv(n - i + 1);       for (int j = 1; j <= n; j++) {         if (cnt[j]) {           dp[i][j] = multiply(multiply(sum[i - 1][j - 1], cnt[j]), inv);           update(answer, multiply(multiply(dp[i - 1][j], cnt[j] - 1), inv));         }         sum[i][j] = add(sum[i][j - 1], dp[i][j]);       }     }     cout << answer << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long double n, h;     cin >> n >> h;     cout << setprecision(20);     for (long double i = 0; i < n - 1; i++) {       cout << h * sqrt((i + 1) / n) <<    ;     }   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1);   const long long N = 1e5 + 5, M = 1e9 + 7;   char ulta[500];   set<char> ache;   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     ulta[ U ] =  D ;     ulta[ D ] =  U ;     ulta[ R ] =  L ;     ulta[ L ] =  R ;     string s;     long long n, i, j, k, ans = 2;     cin >> n >> s;     for (auto ch : s) {       auto x = ache.find(ulta[ch]);       if (x != ache.end()) {         ans++;         ache.clear();       }       ache.insert(ch);     }     cout << ans - 1 << endl;   }
#include <bits/stdc++.h>   using namespace std;   struct State {     int len, link;     map<char, int> nxtc;   } SA[2 * 2006];   bool vis[2 * 2006];   char str[2006], pref[2 * 2006], suf[2006];   class SuffixAutomata {     int sz, last;     void init(int idx) {       SA[idx].len = 0, SA[idx].link = -1;       SA[idx].nxtc.clear();     }     bool traverse(int cur, char *ch) {       if (*ch == 0) return true;       if (SA[cur].nxtc.count(*ch) == 0) return false;       int p = SA[cur].nxtc[*ch];       return traverse(p, ++ch);     }     int findState(int cur, char *ch) {       if (*ch == 0) return cur;       int p = SA[cur].nxtc[*ch];       return findState(p, ++ch);     }       public:     SuffixAutomata() {       sz = last = 0;       init(0);       ++sz;     }     int size() { return sz; }     void extend(char ch) {       int p, q, clone, cur = sz++;       init(cur);       SA[cur].len = SA[last].len + 1;       for (p = last; p != -1 && SA[p].nxtc.count(ch) == 0; p = SA[p].link)         SA[p].nxtc[ch] = cur;       if (p == -1)         SA[cur].link = 0;       else {         q = SA[p].nxtc[ch];         if (SA[p].len + 1 == SA[q].len)           SA[cur].link = q;         else {           clone = sz++;           init(clone);           SA[clone] = SA[q];           SA[clone].len = SA[p].len + 1;           for (; p != -1 && SA[p].nxtc[ch] == q; p = SA[p].link)             SA[p].nxtc[ch] = clone;           SA[cur].link = SA[q].link = clone;         }       }       last = cur;     }     bool traverse(char *str) { return traverse(0, str); }     int findState(char *str) { return findState(0, str); }   };   int lenp, lens, dp[2 * 2006][2006];   int rec(int cur, int idx) {     if (suf[idx] == 0) return 1;     if (dp[cur][idx] != -1) return dp[cur][idx];     int &ret = dp[cur][idx];     ret = 0;     char ch;     int p;     if (idx) {       ch = suf[idx];       if (SA[cur].nxtc.count(ch) == 0) return ret = 0;       p = SA[cur].nxtc[ch];       return ret = rec(p, idx + 1);     }     map<char, int> &M = SA[cur].nxtc;     map<char, int>::iterator im;     for (im = M.begin(); im != M.end(); ++im) {       ch = im->first;       p = im->second;       ret += rec(p, idx);       if (ch == suf[idx]) ret += rec(p, idx + 1);     }     return ret;   }   int main() {     int i, j, ans, n;     while (scanf( %s , str) != EOF) {       SuffixAutomata sa;       for (i = 0; str[i]; ++i) sa.extend(str[i]);       ans = 0;       scanf( %s %s , pref, suf);       lenp = strlen(pref), lens = strlen(suf);       if (!sa.traverse(pref)) {         puts( 0 );         continue;       }       for (i = 0; i < lenp; ++i) {         if (i + lens < lenp) continue;         for (j = 0; j < lens; ++j) {           if (pref[i + j] != suf[j]) break;         }         if (i + j == lenp) {           strcat(pref, &suf[lenp - i]);           ans += sa.traverse(pref);           pref[lenp] = 0;         }       }       n = sa.findState(pref);       memset(dp, -1, sizeof(dp));       ans += rec(n, 0);       printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAX = 200005;   int main() {     int n, k, q, i, a, b, p[MAX] = {0}, c[MAX] = {0};     scanf( %d %d %d , &n, &k, &q);     while (n--) {       scanf( %d %d , &a, &b);       p[a]++;       p[b + 1]--;     }     for (i = 1; i < MAX; i++) {       p[i] += p[i - 1];       c[i] += c[i - 1] + (p[i] >= k);     }     while (q--) {       scanf( %d %d , &a, &b);       printf( %d n , c[b] - c[a - 1]);     }     return 0;   }
#include <bits/stdc++.h>   #define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);   #define ll long long int   #define pb push_back   #define pob pop_back   #define ub upper_bound   #define lb lower_bound   #define mp make_pair   #define f0(i,n) for(i=0;i<n;i++)   #define rf0(i,n) for(i=n-1;i>=0;i--)   #define f2(i,n) for(i=1;i<n;i++)   #define f1(i,n) for(i=1;i<=n;i++)   #define fab(i,a,b) for(i=a;i<=b;i++)   #define shr  ll t;cin>>t; while(t--)   #define fi first   #define sc second   #define pll pair<ll,ll>   #define vll vector<ll>   #define vpll vector<pll>   #define all(v) v.begin(),v.end()   #define mod 1000000007   #define dev(a) for(auto it:a)cout<<it<<      #define prec(nm,prc) cout<<fixed << setprecision(nm)<<prc   #define print(a) cout<<a<<endl;   #define nl   n    using namespace std;   bool comp(pll &a,pll &b)   {       return (a.sc<b.sc);   }   ll power(ll n,ll p)   {    if(p==0)    return 1;    else    {     ll ans=power(n,p/2)%mod;     ans=(ans*ans)%mod;     if(p%2==0)     return ans;     else     return ans=(ans*n)%mod;    }   }   bool isPrime(ll n)    {        if (n <= 1)            return false;        if (n <= 3)            return true;             if (n % 2 == 0 || n % 3 == 0)            return false;             for (ll i = 5; i * i <= n; i = i + 6)            if (n % i == 0 || n % (i + 2) == 0)                return false;             return true;    }              /********************HAR HAR MAHADEV***********JAI BAJRANG BALI************************/     int main()    {      FAST;      /* ifstream cin;       cin.open( input.txt );       ofstream cout;       cout.open( output.txt );                         */      shr        {           ll i,j,n,a,b,c,c1,d,m,sum=0,temp,k,k2,k1,ans=0,cnt=0,r=0,e=0,f;         string str,stri,om,s;           map<ll,ll>mp,mp1;           set<ll>st; vector<vll> v;           cin>>n>>k; ll x[n][2];           f0(i,n)           {               cin>>x[i][0]>>x[i][1];           }          f0(i,n)          {             vll vk;              f0(j,n)             {                                  if(i!=j)                 {                     vk.pb(abs(x[i][0]-x[j][0])+abs(x[i][1]-x[j][1]));                 }                             }              v.pb(vk);             r++;         }         f0(i,v.size())         {         ll p=*max_element(all(v[i]));         if(p<=k){e=1;break;}         }         if(e==1)cout<<1;         else cout<<-1;         cout<<endl;        }               return 0;     }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   const double pi = acos(-1);   const int MOD = 1e9 + 7;   const int INF = 1e9 + 7;   const int MAXN = 10000;   const double eps = 1e-9;   using namespace std;   int n, m, cur;   set<int> s;   void dfs(int x, int y) {     if (y == 0) {       int tmp = abs(abs(x) - n);       if (tmp < MAXN) {         if (s.size() < m) s.insert(cur * MAXN + tmp);         if (s.size() < m) s.insert(cur + MAXN * tmp);       }       return;     }     dfs(x + (y % 10), y / 10);     dfs(x - (y % 10), y / 10);     dfs(x * (y % 10), y / 10);   }   int main() {     scanf( %d , &(n)), scanf( %d , &(m));     for (int i = 0; i < MAXN; i++) {       cur = i;       dfs(i % 10, i / 10);     }     auto it = s.begin();     for (; it != s.end(); it++) printf( %08d n , *it);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1000000000;   const int MAX = 400005;   const int MAX1 = 2007;   const int MAX2 = 4007;   const int LEN = 21;   const int BASE = 1000000000;   const double EPS = 1e-7;   const int MOD = 1234567891;   vector<pair<char, int> > vec;   int main(void) {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     ifstream in(  );     ofstream out(  );     int n, k;     cin >> n >> k;     string s;     cin >> s;     for (int i = (0); i < ((int)s.size()); ++i) {       vec.push_back(make_pair(s[i], i));     }     sort(vec.begin(), vec.end());     char ans[MAX];     memset(ans,   0 , sizeof(ans));     for (int i = (k); i < ((int)vec.size()); ++i) {       ans[vec[i].second] = vec[i].first;     }     for (int i = (0); i < (n); ++i) {       if (ans[i] !=   0 ) cout << ans[i];     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int num;   int likes[7][7];   map<string, int> heroes;   int getNum(string s) {     if (!heroes.count(s)) heroes[s] = num++;     return heroes[s];   }   int getMaxSymp(int n1, int n2) {     vector<int> p, groups(7, 0);     for (int i = 0; i < 7; i++) {       p.push_back(i);       if (i >= n1) groups[i] = i < n1 + n2 ? 1 : 2;     }     int res = 0;     do {       int r = 0;       for (int i = 0; i < 7; i++)         for (int j = 0; j < 7; j++)           if (groups[i] == groups[j]) r += likes[p[i]][p[j]];       res = max(r, res);     } while (next_permutation(p.begin(), p.end()));     return res;   }   int main() {     int i, j, k, n, a, b, c, res = 2000000000, symp = 0;     cin >> n;     for (i = 0; i < n; i++) {       string s1, s2, s3;       cin >> s1 >> s3 >> s2;       likes[getNum(s1)][getNum(s2)] = 1;     }     cin >> a >> b >> c;     for (i = 1; i < 7; i++)       for (j = 1; j + i < 7; j++) {         k = 7 - i - j;         int d = max(a / i, max(b / j, c / k)) - min(a / i, min(b / j, c / k));         if (d < res)           res = d, symp = getMaxSymp(i, j);         else if (res == d)           symp = max(symp, getMaxSymp(i, j));       }     cout << res <<     << symp << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long MOD = 998244353;   long long inv[5050 + 10], fac[5050 + 10], ifac[5050 + 10];   void setComb() {     inv[0] = 1;     inv[1] = 1;     fac[1] = 1;     ifac[1] = 1;     fac[0] = 1;     ifac[0] = 1;     for (int i = 2; i < 5050; i++) {       inv[i] = (-MOD / i) * inv[MOD % i] % MOD;       fac[i] = fac[i - 1] * i % MOD;       ifac[i] = ifac[i - 1] * inv[i] % MOD;       inv[i] = (inv[i] + MOD) % MOD;       fac[i] = (fac[i] + MOD) % MOD;       ifac[i] = (ifac[i] + MOD) % MOD;     }     return;   }   long long comb(long long n, long long k) {     if (n < k || n < 0 || k < 0)       return 0;     else       return ((fac[n] * ifac[k] % MOD * ifac[n - k] % MOD + MOD) % MOD);   }   long long hcomb(long long n, long long r) {     if (n == 0 && r == 0)       return 1;     else if (n < 0 || r < 0)       return 0;     else       return comb(n + r - 1, r - 1);   }   int N;   vector<int> A;   long long dp[5050][5050];   long long cnt[5050];   void add(long long &a, long long b) { a = (a + b) % MOD; }   void mul(long long &a, long long b) { a = a * b % MOD; }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     cin >> N;     A.resize(N);     for (int i = 0; i < (N); ++i) cin >> A[i];     sort(A.begin(), A.end());     for (int i = 0; i < (N); ++i) cnt[A[i]]++;     setComb();     dp[0][0] = 1;     for (int i = 0; i < N; i++) {       long long sum = 0;       for (int j = 0; j <= 5000; j++) {         long long res = sum;         mul(res, cnt[j]);         mul(res, inv[N - i]);         add(dp[i + 1][j], res);         sum += dp[i][j];       }     }     long long ans = 0;     for (int i = 1; i < N; i++) {       for (int j = 0; j <= 5000; j++) {         long long res = dp[i][j];         mul(res, cnt[j] - 1);         mul(res, inv[N - i]);         add(ans, res);       }     }     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> v;     vector<int>::iterator it;     int n, q, x, count1 = 0, x1;     cin >> q;     while (q--) {       cin >> n;       while (n--) {         cin >> x;         v.push_back(x);       }       it = v.end() - 1;       x1 = *it;       for (it = v.end() - 2; it >= v.begin(); it--) {         if (*it > x1)           count1++;         else           x1 = *it;       }       cout << count1 << endl;       count1 = 0;       v.clear();     }   }