malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int n, m;   long long k;   long long a[21][21];   map<long long, int> mp[21][21];   int Color[21][21];   queue<pair<int, int>> q;   void BFS(int x, int y, int depthMax, vector<pair<int, int>> d) {     Color[x][y] = 1;     mp[x][y][a[x][y]] = 1;     q.push(make_pair(x, y));     while (!q.empty()) {       tie(x, y) = q.front();       q.pop();       if (Color[x][y] == depthMax) {         continue;       }       for (auto i : d) {         int u = x + i.first, v = y + i.second;         if (u > 0 && u <= n && v > 0 && v <= m) {           for (auto it : mp[x][y]) {             mp[u][v][a[u][v] ^ it.first] += it.second;           }           if (Color[u][v] == 0) {             Color[u][v] = Color[x][y] + 1;             q.push(make_pair(u, v));           }         }       }     }   }   long long GetMap(map<long long, int> &mp, long long x) {     auto it = mp.find(x);     return (it == mp.end() ? 0 : it->second);   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     cin >> n >> m >> k;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         cin >> a[i][j];       }     }     if (n == 1 && m == 1) {       cout << (a[1][1] == k ? 1 : 0);       return 0;     }     int numStep = (n + m - 1) / 2;     BFS(1, 1, numStep,         vector<pair<int, int>>({make_pair(1, 0), make_pair(0, 1)}));     BFS(n, m, (n + m - 1) - numStep,         vector<pair<int, int>>({make_pair(-1, 0), make_pair(0, -1)}));     long long Ans = 0;     for (int i = 1; i <= n; i++) {       for (int j = 1; j <= m; j++) {         if (i + j - 1 == numStep && Color[i][j] == numStep) {           for (auto x : mp[i][j]) {             long long tmp = 0;             if (i + 1 <= n) {               tmp += GetMap(mp[i + 1][j], x.first ^ k);             }             if (j + 1 <= m) {               tmp += GetMap(mp[i][j + 1], x.first ^ k);             }             Ans += 1LL * tmp * x.second;           }           break;         }       }     }     cout << Ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, m, a, b[101];   void read() {     int c, d, k = 0;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a, b[i] = a + b[i - 1];     for (int i = 0; i < m; i++) {       cin >> c >> d;       k += (b[d] - b[c - 1] > 0 ? b[d] - b[c - 1] : 0);     }     cout << k;   }   int main() { read(); }
#include <bits/stdc++.h>   using namespace std;   const long double eps = 1e-9;   const long double pi = acos(-1.0);   const int inf = 1e+9;   long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }   int xabs(int a) { return a >= 0 ? a : -a; }   int sign(int a) { return (a < 0) ? -1 : 1; }   int sqr(int a) { return a * a; }   int main() {     string s;     cin >> s;     int n = s.size();     stack<pair<char, int> > q;     set<pair<char, char> > sp;     sp.insert(make_pair( [ ,  ] ));     sp.insert(make_pair( ( ,  ) ));     for (int i = 0; i < n; i++) {       if (q.size() == 0) {         q.push(make_pair(s[i], i));       } else {         if (sp.count(make_pair(q.top().first, s[i]))) {           q.pop();         } else {           q.push(make_pair(s[i], i));         }       }     }     vector<int> ans;     while (q.size() != 0) {       ans.push_back(q.top().second);       q.pop();     }     reverse(ans.begin(), ans.end());     ans.push_back(n);     int cnt = 0;     int j = 0;     int ma = 0;     string res;     while (j < ans.size()) {       int cnt = 0;       int start = (j > 0) ? ans[j - 1] + 1 : 0;       for (int i = start; i < ans[j]; i++) {         if (s[i] ==  [ ) cnt++;       }       if (cnt > ma) {         ma = cnt;         res = s.substr(start, ans[j] - start);       }       j++;     }     cout << ma << endl;     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double Pi = acos((double)-1);   const double Eps = 1E-6;   int read() {     int $x;     scanf( %d , &$x);     return $x;   }   long long sqr(long long $x) { return $x * $x; }   int x[100000], N, A, B;   int main() {     A = read(), B = read();     N = A + B + 1;     x[0] = 1;     int i = 0, t;     t = 1;     while (A--) x[++i] = ++t;     t = 1;     while (B--) x[++i] = --t;     for (i = 0; i < N; ++i) printf( %d  , x[i] - t + 1);     return 0;   }
#include <bits/stdc++.h>   const int N = 100010;   char s[N], str[3][N];   int len;   int solve(int type, int ret) {     int ans = 0;     memcpy(str[type], s, sizeof(s));     for (int i = len - 1; i >= 0; --i) {       if ((str[type][i] -  0 ) % 3 == type) {         str[type][i] =   0 ;         ++ans;         ret = (ret - type + 3) % 3;         if (!ret) {           break;         }       }     }     for (int i = 0; i < len; ++i) {       if (str[type][i] == 0) {         continue;       }       if (str[type][i] !=  0  || len - ans == 1) {         break;       }       str[type][i] =   0 ;       ++ans;     }     return ret ? INT_MAX : ans;   }   int main() {     scanf( %s , s);     int sum = 0;     len = strlen(s);     for (int i = 0; i < len; ++i) {       sum += s[i] -  0 ;     }     if (!(sum % 3)) {       return printf( %s , s), 0;     }     int ans1 = solve(1, sum % 3), ans2 = solve(2, sum % 3);     int type = ans1 < ans2 ? 1 : 2;     int cnt = 0;     for (int i = 0; i < len; ++i) {       if (str[type][i] != 0) {         ++cnt;         putchar(str[type][i]);       }     }     if (!cnt) {       return printf( -1 n ), 0;     }     return printf(  n ), 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int h1, a1, c1, i;     int h2, a2;     scanf( %d%d%d%d%d , &h1, &a1, &c1, &h2, &a2);     vector<int> v;     while (true) {       if (h1 - a2 <= 0 && h2 - a1 <= 0) {         h1 -= a2;         h2 -= a1;         v.push_back(1);         break;       } else if (h1 - a2 > 0) {         h2 = h2 - a1;         h1 = h1 - a2;         v.push_back(1);         if (h2 <= 0 || h1 <= 0) {           break;         }       } else {         h1 += c1;         h1 -= a2;         v.push_back(0);       }     }     int n = v.size();     printf( %d n , n);     for (i = 0; i < n; i++) {       if (v[i] == 0)         printf( HEAL n );       else         printf( STRIKE n );     }   }
#include <bits/stdc++.h>   using namespace std;   struct edge {     long long int A;     long long int B;   };   bool edgecompare(edge lhs, edge rhs) {     if (lhs.B != rhs.B)       return lhs.B < rhs.B;     else       return lhs.A < rhs.A;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     long long int n, m, i, j, k, flag = 0, a[100005];     string str;     map<long long int, long long int> Map;     set<long long int> Set;     set<long long int, greater<long long int> >::iterator itr;     cin >> n >> k;     long long int ma = 0;     i = 0;     while (pow(2, i) <= n) {       i++;     }     ma = pow(2, i) - 1;     if (k == 1)       cout << n;     else       cout << ma;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     vector<int> times;     int n, k;     cin >> n >> k;     for (int i = 0; i < n; ++i) {       int x;       cin >> x;       times.push_back(x);     }     int ans = 0;     for (int i = 1; i < n; ++i) {       if (times[i] + times[i - 1] < k) {         ans += k - (times[i] + times[i - 1]);         times[i] += k - (times[i] + times[i - 1]);       }     }     cout << ans << endl;     for (int i = 0; i < n; ++i) cout << times[i] <<    ;     cout << endl;     return 0;   }
#include<iostream>   #include<string.h>   #include <fstream>   #include <string>   #include <vector>   #include <iomanip>    #include <cmath>   #include <cstdlib>   #include<map>   #include <ctime>   using namespace std;    int main(){     long long int t;    cin>>t;    for(long long int mat=0;mat<t;mat=mat+1){     long long int total;     cin>>total;     long long int median;     vector<long long int> array;     for(long long int i=0;i<total;i=i+1){      char a;      cin>>a;      if(a== * ){       array.push_back(i);      }     }     long long int n=array.size();     if(n%2==0){      median=n/2-1;     }     else{      median=n/2;     }     long long int ans=0;     for(long long int i=0;i<array.size();i=i+1){      ans+=abs(array[i]-array[median])-abs(i-median);     }      cout<<ans<<endl;               }      return 0;   }
#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   int main() {     int n, r;     cin >> n >> r;     double deg = (1.0 / n) * pi;     double bi = sin(deg);     cout << setiosflags(ios::fixed) << setprecision(10) << (bi / (1 - bi) * r)          << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct ghost {     long long vx, vy;     long long magic;     ghost(long long x, long long y, long long a)         : vx(x), vy(y), magic((long long)a * x - y) {}   };   bool cmp1(const ghost& x, const ghost& y) { return x.magic < y.magic; }   bool cmp2(const ghost& x, const ghost& y) { return x.vx < y.vx; }   vector<ghost> G;   int main() {     long long n, a, b;     cin >> n >> a >> b;     for (long long i = 0; i < n; i++) {       long long x, vx, vy;       cin >> x >> vx >> vy;       ghost tmp(vx, vy, a);       G.push_back(tmp);     }     stable_sort(G.begin(), G.end(), cmp2);     stable_sort(G.begin(), G.end(), cmp1);     long long res = 0;     long long t_m = G[0].magic;     long long t_b = 0;     for (long long i = 0; i < G.size(); i++) {       if (G[i].magic != t_m) {         if (i - t_b > 1) {           res += ((i - t_b) * (i - t_b - 1));           long long t_vx = G[t_b].vx;           long long tt_b = t_b;           for (long long k = tt_b; k < i; k++) {             if (G[k].vx != t_vx) {               res -= ((k - tt_b) * (k - tt_b - 1));               tt_b = k;               t_vx = G[k].vx;             }           }           res -= (i - tt_b) * (i - tt_b - 1);         }         t_b = i;         t_m = G[i].magic;       }     }     res += ((n - t_b) * (n - t_b - 1));     long long t_vx = G[t_b].vx;     long long tt_b = t_b;     for (long long k = tt_b; k < n; k++) {       if (G[k].vx != t_vx) {         res -= ((k - tt_b) * (k - tt_b - 1));         tt_b = k;         t_vx = G[k].vx;       }     }     res -= (n - tt_b) * (n - tt_b - 1);     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct problem {     long long ts, tl, ss, sl, p;   } pro[1005];   pair<long long, double> f[1005][1566];   int n, t;   bool cmp(problem a, problem b) {     return a.tl * a.p * (1000000 - b.p) < b.tl * b.p * (1000000 - a.p);   }   bool better(pair<long long, double> &a, pair<long long, double> &b) {     if (a.first != b.first) return a.first > b.first;     return a.second < b.second;   }   void dp() {     for (int i = (0); i <= (n + 1); i++)       for (int j = (0); j <= (t); j++) f[i][j].first = -1;     f[1][0] = make_pair(0, 0);     for (int i = (1); i <= (n); i++)       for (int j = (0); j <= (t); j++)         if (f[i][j].first > -1) {           if (better(f[i][j], f[i + 1][j])) f[i + 1][j] = f[i][j];           pair<long long, double> P;           long long nj;           if (j + pro[i].ts <= t) {             nj = j + pro[i].ts;             P = make_pair(f[i][j].first + pro[i].ss,                           f[i][j].second + pro[i].ts * 1000000);             if (better(P, f[i + 1][nj])) f[i + 1][nj] = P;           }           if (j + pro[i].ts + pro[i].tl <= t) {             nj = j + pro[i].ts + pro[i].tl;             P.first =                 f[i][j].first + pro[i].ss + pro[i].sl * (1000000 - pro[i].p);             P.second = pro[i].ts * 1000000 +                        (1000000 - pro[i].p) * (pro[i].tl + j) +                        f[i][j].second * pro[i].p / 1.0 / 1000000;             if (better(P, f[i + 1][nj])) f[i + 1][nj] = P;           }         }     pair<long long, double> res = make_pair(0, 0);     for (int j = (0); j <= (t); j++)       if (better(f[n + 1][j], res)) {         res = f[n + 1][j];       }     printf( %.10lf %.10lf n , res.first / 1000000.0, res.second / 1000000.0);   }   long long str_ll(string &s) {     long long x = 0;     int pos = -1;     for (int i = 0; i < (s.length()); i++) {       if (s[i] ==  . ) {         pos = i + 1;       } else         x = x * 10 + s[i] -  0 ;     }     if (pos != -1)       for (int i = 0; i < (6 - s.length() + pos); i++) x = x * 10;     return x;   }   int main() {     cin >> n >> t;     for (int i = (1); i <= (n); i++) {       double p;       cin >> pro[i].ss >> pro[i].sl >> pro[i].ts >> pro[i].tl >> p;       pro[i].ss *= 1000000;       pro[i].p = (p * 1000000 + 0.5);     }     sort(pro + 1, pro + n + 1, cmp);     dp();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool Check(long long n, long long pos) { return (n & (1 << pos)); }   long long Set(long long n, long long pos) { return (n | (1 << pos)); }   string s;   long long n, mod;   long long dp[(1 << 18) + 2][102];   long long call(long long mask, long long val) {     if (mask == (1 << n) - 1) {       if (val)         return 0;       else         return 1;     }     long long &ret = dp[mask][val];     if (ret != -1) return ret;     ret = 0;     unordered_map<int, bool> mp;     for (int i = 0; i < n; i++) {       int digit = s[i] -  0 ;       if (mp[digit] || (!digit && !mask) || Check(mask, i)) continue;       mp[digit] = 1;       ret += call(Set(mask, i), (val * 10 + digit) % mod);     }     return ret;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cin >> s >> mod;     n = s.size();     memset(dp, -1, sizeof dp);     cout << call(0, 0) << endl;   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   const int MAXN = 1000005;   char a[MAXN], b[MAXN];   int mi[MAXN], ma[MAXN];   long long ans = 0;   int trs(char a, char b) {     int s = 0;     if (a ==  R )       s += 6;     else if (a ==  B )       s += 3;     if (b ==  R )       s += 2;     else if (b ==  B )       s += 1;     return s;   }   int s[MAXN][10];   int main() {     scanf( %s , a + 1);     scanf( %s , b + 1);     n = strlen(a + 1), m = strlen(b + 1);     for (int i = 2; i <= m; i++) {       for (int j = 0; j <= 9; j++) s[i][j] = s[i - 1][j];       if (b[i] != b[i - 1]) s[i][trs(b[i], b[i - 1])]++;     }     for (int i = 1; i <= n; i++) {       if (i == 1)         mi[i] = ma[i] = 1;       else         mi[i] = mi[i - 1], ma[i] = ma[i - 1];       if (i != 1 && a[i - 1] == b[mi[i]]) mi[i]++;       if (i != 1 && ma[i] != m) ma[i]++;       while (ma[i] != m && b[ma[i]] != a[i]) ma[i]++;       ans += ma[i] - mi[i] + 1;       if (i != 1) {         ans -= s[ma[i]][trs(a[i - 1], a[i])] - s[mi[i] - 1][trs(a[i - 1], a[i])];       }     }     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <class T, class L>   bool smax(T &x, L y) {     return x < y ? (x = y, 1) : 0;   }   template <class T, class L>   bool smin(T &x, L y) {     return y < x ? (x = y, 1) : 0;   }   const int maxn = 20, maxm = 1e5 + 17;   char c[maxm];   int n, m, col[maxm];   int dp[maxn + 1][1 << maxn], ans[1 << maxn];   int main() {     ios::sync_with_stdio(0), cin.tie(0);     cin >> n >> m;     for (int i = 0; i < n; i++) {       cin >> c;       for (int j = 0; j < m; j++) col[j] |= c[j] -  0  << i;     }     for (int i = 0; i < m; i++) dp[0][col[i]]++;     for (int i = 0; i < n; i++)       for (int k = n; k; k--)         for (int mask = 0; mask < 1 << n; mask++)           dp[k][mask] += dp[k - 1][mask ^ (1 << i)];     int po = 1 << n;     for (int i = 0; i <= n; i++) {       int x = min(i, n - i);       for (int mask = 0; mask < po; mask++) ans[mask] += x * dp[i][mask];     }     cout << *min_element(ans, ans + po) <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, n, l, k = 0, maxi;     scanf( %d , &n);     long long int count = 0;     int a[15];     l = n;     while (l) {       a[k] = l % 10;       l = l / 10;       k++;     }     while (k > 0) {       maxi = 0;       for (i = 0; i < k; i++)         if (a[i] > maxi) maxi = a[i];       n = n - maxi;       k = 0;       l = n;       while (l) {         a[k] = l % 10;         l = l / 10;         k++;       }       count++;     }     if (n == 0)       cout << count << endl;     else       cout << count + 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (int)2e5 + 5;   int seg[N], ans[N];   vector<pair<int, int> > beg[N], fin[N];   set<pair<int, int> > pending;   set<pair<int, int> >::iterator it1, it2;   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> seg[i];     for (int q = 0; q < m; q++) {       int l, r, x;       cin >> l >> r >> x;       beg[l].emplace_back(x, q);       fin[r].emplace_back(x, q);     }     for (int i = 1; i <= n; i++) {       for (pair<int, int> xq : beg[i]) pending.insert(xq);       it2 = pending.lower_bound(make_pair(seg[i], 0));       it1 = pending.begin();       while (it1 != it2) {         ans[it1->second] = i;         pending.erase(it1++);       }       it1 = pending.lower_bound(make_pair(seg[i] + 1, 0));       while (it1 != pending.end()) {         ans[it1->second] = i;         pending.erase(it1++);       }       for (pair<int, int> xq : fin[i])         if ((it1 = pending.find(xq)) != pending.end()) {           ans[xq.second] = -1;           pending.erase(it1);         }     }     for (int q = 0; q < m; q++) cout << ans[q] <<   n ;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long int t;     cin >> t;     while (t--) {       long long int n, m, a, b;       cin >> n >> m >> a >> b;       long long int arr[n + 5][m + 5];       long long int i, j;       memset(arr, 0, sizeof(arr));       for (i = 0; i < n; i++) {         long long int x = a;         for (j = m - 1; j >= 0; j--) {           if (x > 0) {             arr[i][j] = 1;             x--;           } else {             break;           }         }       }       long long int flag = 0;       for (j = 0; j < m; j++) {         long long int count = 0;         for (i = 0; i < n; i++) {           if (arr[i][j] == 1) {             count++;           }         }         if (count > b) {           flag = 1;           break;         }         long long int y = count;         while (y < b) {           for (i = 0; i < n; i++) {             if (arr[i][j] == 0) {               for (int h = j + 1; h < m; h++) {                 if (arr[i][h] == 1) {                   arr[i][h] = 0;                   arr[i][j] = 1;                   y++;                   break;                 }               }             }             if (y == b || i == n - 1) {               break;             }           }           if (y == b || i == n - 1) {             break;           }         }         if (y != b) {           flag = 1;           break;         }       }       if (flag == 1) {         cout <<  NO  << endl;       } else {         cout <<  YES  << endl;         for (i = 0; i < n; i++) {           for (j = 0; j < m; j++) {             cout << arr[i][j];           }           cout << endl;         }       }     }   }
#include <bits/stdc++.h>   const int maxn = 200005, maxm = maxn << 1;   int n, m, e, s1, s2, s, maxx, col, flg, mid;   int start[maxn], to[maxm], then[maxm], dep[maxn], f[maxn], ans[maxn],       flen[maxn], slen[maxn];   inline void add(int x, int y) { then[++e] = start[x], start[x] = e, to[e] = y; }   void dfs(int x, int last) {     f[x] = last, dep[x] = dep[last] + 1;     flen[x] = slen[x] = 0;     if (dep[x] > maxx) maxx = dep[x], s = x;     for (int i = start[x]; i; i = then[i]) {       int y = to[i];       if (y == last) continue;       dfs(y, x);     }   }   void getlen(int x, int last) {     for (int i = start[x]; i; i = then[i]) {       int y = to[i];       if (y == last || ans[y]) continue;       getlen(y, x);       if (flen[y] + 1 > flen[x])         slen[x] = flen[x], flen[x] = flen[y] + 1;       else if (flen[y] + 1 > slen[x])         slen[x] = flen[y] + 1;       if (slen[y] + 1 > slen[x]) slen[x] = slen[y] + 1;     }   }   void solve(int x, int c, int d, int t) {     ans[x] = c;     c = (c + t + m - 1) % m + 1;     for (int i = start[x]; i; i = then[i]) {       int y = to[i];       if (ans[y] != 0) continue;       solve(y, c, d + 1, t);     }   }   int main() {     scanf( %d%d , &n, &m);     for (int i = 1; i < n; i++) {       int x, y;       scanf( %d%d , &x, &y);       add(x, y), add(y, x);     }     maxx = -1000000000, dfs(1, 0), s1 = s;     maxx = -1000000000, dfs(s, 0), s2 = s;     if (m == 2) {       puts( Yes );       for (int i = 1; i <= n; i++)         printf( %d%c , dep[i] % 2 + 1, i == n ?   n  :    );       return 0;     }     for (int i = s2; i != 0; i = f[i]) {       col = col % m + 1;       if ((dep[s1] + dep[s2]) / 2 == dep[i]) mid = i;       ans[i] = col;     }     for (int i = s2; i != 0; i = f[i]) {       getlen(i, 0);       if (ans[i] && flen[i] && dep[i] + flen[i] >= m &&           (dep[s2] - dep[i] + 1) + flen[i] >= m) {         puts( No );         return 0;       }     }     for (int i = 1; i <= n; i++)       if (flen[i] + slen[i] + 1 >= m) {         puts( No );         return 0;       }     for (int i = s2; i != mid; i = f[i]) solve(i, ans[i], 1, -1);     for (int i = mid; i != 0; i = f[i]) solve(i, ans[i], 1, 1);     puts( Yes );     for (int i = 1; i <= n; i++) printf( %d%c , ans[i], i == n ?   n  :    );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }   const int MAXN = 100000;   int n, mxdepth, MOD;   int INV2;   int inv[2 * MAXN + 1];   vector<int> parts;   void rec(int l, int r, int h) {     if (l > r) return;     if (h == 1 || l == r) {       parts.push_back(r - l + 1);       return;     }     int m = (l + r) / 2;     rec(l, m, h - 1);     rec(m + 1, r, h - 1);   }   int cntpairs(int sz) { return (long long)sz * (sz - 1) / 2 % MOD; }   int calc(int sz) { return (long long)cntpairs(sz) * INV2 % MOD; }   int calc(int sza, int szb) {     int ret = 0;     for (int den = (2); den <= (sza + szb); ++den) {       int lo = max(1, den - szb), hi = min(sza, den - 1), cnt = hi - lo + 1;       if (lo > hi) continue;       int cur = (long long)(den - 2) % MOD * inv[den] % MOD * INV2 % MOD;       ret = (ret + (long long)cnt * cur) % MOD;     }     return ret;   }   int solve() {     INV2 = (MOD + 1) / 2;     inv[1] = 1;     for (int i = (2); i <= (2 * n); ++i)       inv[i] = (long long)(MOD - MOD / i) * inv[MOD % i] % MOD;     parts.clear();     rec(1, n, mxdepth);     int sz1 = -1, cnt1 = 0, sz2 = -1, cnt2 = 0;     for (int i = (0); i < (((int)(parts).size())); ++i) {       int x = parts[i];       if (x == sz1)         ++cnt1;       else if (x == sz2)         ++cnt2;       else if (sz1 == -1)         sz1 = x, ++cnt1;       else if (sz2 == -1)         sz2 = x, ++cnt2;       else         assert(false);     }     int ret = 0;     if (cnt1 != 0) ret = (ret + (long long)cnt1 * calc(sz1)) % MOD;     if (cnt2 != 0) ret = (ret + (long long)cnt2 * calc(sz2)) % MOD;     if (cnt1 != 0) ret = (ret + (long long)cntpairs(cnt1) * calc(sz1, sz1)) % MOD;     if (cnt1 != 0 && cnt2 != 0)       ret = (ret + (long long)cnt1 * cnt2 % MOD * calc(sz1, sz2)) % MOD;     if (cnt2 != 0) ret = (ret + (long long)cntpairs(cnt2) * calc(sz2, sz2)) % MOD;     return ret;   }   void run() {     scanf( %d%d%d , &n, &mxdepth, &MOD);     printf( %d n , solve());   }   int main() {     run();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int maxn = 100;   int a[maxn], s[maxn], f[maxn], n, ans;   int pmin, pmax;   int main() {     scanf( %d , &n);     for (int i = 0; i < n; i++) scanf( %d , a + i), f[i] = -1;     sort(a, a + n);     swap(a[0], a[n - 1]);     for (int i = 0; i < n; i++) printf( %d  , a[i]);     printf(  n );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[10];   int main() {     for (int i = 1; i <= 6; i++) cin >> a[i];     cout << (a[1] + a[2] + a[3]) * (a[1] + a[2] + a[3]) - a[1] * a[1] -                 a[3] * a[3] - a[5] * a[5];     return 0;   }