malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   vector<int> v[100009];   map<int, int> mp;   int main() {     int n, m, x, y, index = 1;     scanf( %d%d , &n, &m);     for (int i = 0; i < m; i++) {       scanf( %d%d , &x, &y);       if (mp[x] == 0) {         mp[x] = index;         v[index++].push_back(y);       } else         v[mp[x]].push_back(y);       if (mp[y] == 0) {         mp[y] = index;         v[index++].push_back(x);       } else         v[mp[y]].push_back(x);     }     int bus_out = 0, bus_in = 0, ring = 0, s, cen_c = 0, cen_out = 0;     for (int i = 1; i < index; i++) {       s = v[i].size();       if (s == 1) {         cen_out++;         bus_out++;       } else if (s == 2) {         bus_in++;         ring++;       } else {         cen_c++;       }     }     if (n < m) {       printf( unknown topology n );     } else if (n - 1 == m && bus_out == 2 && bus_in == n - 2) {       printf( bus topology n );     } else if (ring == n && n == m) {       printf( ring topology n );     } else if (n == m + 1 && cen_c == 1 && cen_out == n - 1) {       printf( star topology n );     } else {       printf( unknown topology n );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mxn = 2e5 + 5;   long long a[1001][1001];   int main() {     int t;     cin >> t;     while (t--) {       int n, m;       cin >> n >> m;       for (int i = 1; i <= n; ++i) {         for (int j = 1; j <= m; ++j) {           cin >> a[i][j];           if ((i + j) & 1 && !(a[i][j] & 1))             ++a[i][j];           else if (!((i + j) & 1) && a[i][j] & 1)             ++a[i][j];           cout << a[i][j] <<    ;         }         cout << endl;       }     }   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 0x3f3f3f3f;   const long long LINF = 0x3f3f3f3f3f3f3f3f;   const int MOD = (int)1e9 + 7;   const int N = (int)1e6 + 7;   struct node {     long long x, y, a;   } a[N];   int n;   long long dp[N];   struct P {     long long x, y;     P() {}     P(long long x, long long y) : x(x), y(y) {}     P operator-(const P &rhs) const { return P(x - rhs.x, y - rhs.y); }     bool operator^(const P &rhs) const {       return (double)x * rhs.y > (double)y * rhs.x;     }   };   void Init() {     for (int i = (1); i < (n + 1); ++i)       scanf( %I64d%I64d%I64d , &a[i].x, &a[i].y, &a[i].a);     sort(a + 1, a + n + 1, [&](node a, node b) { return a.x < b.x; });   }   int Solve() {     deque<P> Q;     Q.push_back(P((a[0].x), (dp[0])));     for (int i = (1); i < (n + 1); ++i) {       while ((int)(Q).size() > 1 &&              (Q[1].y - Q[0].y) > (Q[1].x - Q[0].x) * (a[i].y))         Q.pop_front();       dp[i] = Q[0].y - (a[i].y) * Q[0].x + a[i].x * a[i].y - a[i].a;       P aa((a[i].x), (dp[i]));       while ((int)(Q).size() > 1 && !((aa - Q[(int)(Q).size() - 2]) ^                                       (Q.back() - Q[(int)(Q).size() - 2])))         Q.pop_back();       Q.push_back(aa);     }     long long ans = 0;     for (int i = (1); i < (n + 1); ++i) ans = max(ans, dp[i]);     return printf( %I64d n , ans);   }   int main() {     while (~scanf( %d , &n)) {       Init();       Solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long LINF = 1001002003004005006ll;   int dx[] = {1, 0, -1, 0};   int dy[] = {0, 1, 0, -1};   long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }   template <class T>   bool chmax(T &a, const T &b) {     if (a < b) {       a = b;       return 1;     }     return 0;   }   template <class T>   bool chmin(T &a, const T &b) {     if (b < a) {       a = b;       return 1;     }     return 0;   }   signed main() {     cin.tie(0);     ios::sync_with_stdio(0);     long long n;     cin >> n;     string s;     cin >> s;     if (n == 1) {       cout << 0 << endl;       return 0;     }     vector<long long> v;     long long i = 0;     while (i < n) {       char tmp = s[i];       long long cnt = 0;       while (i + cnt < n and s[i + cnt] == tmp) {         cnt++;       }       v.push_back(cnt);       i += cnt;     }     long long m = v.size();     if (m == 1) {       long long ans = n * (n + 1) / 2 - n;       cout << ans << endl;       return 0;     }     long long diff = 0;     for (long long i = 0; i < m; i++) {       diff += 2 * v[i];     }     diff -= v[0];     diff -= v[m - 1];     diff -= m - 1;     long long ans = n * (n + 1) / 2 - diff - n;     cout << ans << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long mypow3(long long p, long long mod) {     long long rez = 1, x = 3;     while (p > 0) {       if (p % 2 == 1) rez = (rez * x) % mod;       x = (x * x) % mod;       p /= 2;     }     return rez;   }   int main() {     long long n, m, ans;     ios_base::sync_with_stdio(false);     cin >> n >> m;     ans = mypow3(n, m) - 1;     if (ans == -1) ans = m - 1;     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long a, b, c[101], d[101], mx = -1e9, cnt;   int main() {     cin >> a >> b;     for (int i = 1; i <= a; ++i) {       cin >> c[i];     }     for (int i = 1; i < a; ++i) {       d[i] = c[i] - c[i + 1] - b;     }     for (int i = 1; i <= a; ++i) {       mx = max(d[i], mx);     }     cout << mx;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[410], s[410], dp[60][410][2];   void su(int &a, int b) {     if (b > a) a = b;   }   void lemon() {     int n, m;     scanf( %d%d , &n, &m);     for (int i = (1); i <= (n); i++) scanf( %d , &a[i]);     for (int i = (1); i <= (n); i++) s[i] = s[i - 1] + a[i];     for (int k = (1); k <= (m); k++)       for (int i = (1); i <= (n); i++)         for (int flag = (0); flag <= (1); flag++) dp[k][i][flag] = -1000000000;     for (int i = (1); i <= (n); i++)       for (int j = (i); j <= (n); j++) {         su(dp[1][j][0], -(s[j] - s[i - 1]));         su(dp[1][j][1], s[j] - s[i - 1]);       }     for (int k = (1); k <= (m - 1); k++)       for (int i = (1); i <= (n); i++)         for (int flag = (0); flag <= (1); flag++)           if (dp[k][i][flag] != -1000000000) {             for (int j = (i + 1); j <= (n); j++) {               if (k != m - 1) su(dp[k + 1][j][flag], dp[k][i][flag]);               if (flag == 0) {                 if (k == m - 1)                   su(dp[k + 1][j][1 - flag], dp[k][i][flag] + (s[j] - s[i]));                 else                   su(dp[k + 1][j][1 - flag], dp[k][i][flag] + (s[j] - s[i]) * 2);               } else {                 if (k == m - 1)                   su(dp[k + 1][j][1 - flag], dp[k][i][flag] - (s[j] - s[i]));                 else                   su(dp[k + 1][j][1 - flag], dp[k][i][flag] - (s[j] - s[i]) * 2);               }             }           }     int ans = -1000000000;     for (int i = (1); i <= (n); i++)       for (int flag = (0); flag <= (1); flag++) su(ans, dp[m][i][flag]);     cout << ans << endl;   }   int main() {     ios::sync_with_stdio(true);     lemon();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   constexpr int inf = 1e9;   using P = pair<int, int>;   template <typename T>   void printv(const vector<T> &v) {     int sz = v.size();     for (int i = 0; i < sz; i++) {       cout << v[i] <<    n [i == sz - 1];     }   }   using Graph = vector<vector<int>>;   const int MAX_N = 3010;   Graph g(MAX_N);   vector<vector<int>> dist(MAX_N, vector<int>(MAX_N, inf));   vector<vector<int>> ch(MAX_N, vector<int>(MAX_N));   int dfs(int r, int cur, int pre) {     ch[r][cur] = 1;     for (auto nxt : g[cur]) {       if (nxt == pre) continue;       ch[r][cur] += dfs(r, nxt, cur);     }     return ch[r][cur];   }   int main() {     cin.tie(0);     ios::sync_with_stdio(false);     int n;     cin >> n;     vector<P> ps;     for (int i = 0; i < n - 1; i++) {       int u, v;       cin >> u >> v;       u--;       v--;       ps.push_back(P(u, v));       g[u].push_back(v);       g[v].push_back(u);     }     for (int i = 0; i < n; i++) {       queue<int> que;       que.push(i);       dist[i][i] = 0;       while (!que.empty()) {         int v = que.front();         que.pop();         for (auto nxt : g[v]) {           if (dist[i][nxt] != inf) continue;           dist[i][nxt] = dist[i][v] + 1;           que.push(nxt);         }       }     }     for (int i = 0; i < n; i++) {       dfs(i, i, -1);     }     vector<vector<P>> cs(n);     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cs[dist[i][j]].push_back(P(i, j));       }     }     vector<vector<ll>> dp(n, vector<ll>(n));     for (int d = 0; d < n - 1; d++) {       for (auto p : cs[d]) {         int u = p.first, v = p.second;         for (auto nxt : g[u]) {           if (dist[u][nxt] + dist[u][v] != dist[v][nxt]) continue;           ll x = ch[nxt][v], y = ch[u][nxt];           dp[nxt][v] = max(dp[nxt][v], dp[u][v] + x * y);           dp[v][nxt] = max(dp[v][nxt], dp[u][v] + x * y);         }         for (auto nxt : g[v]) {           if (dist[v][nxt] + dist[u][v] != dist[u][nxt]) continue;           ll x = ch[nxt][u], y = ch[v][nxt];           dp[nxt][u] = max(dp[nxt][u], dp[u][v] + x * y);           dp[u][nxt] = max(dp[u][nxt], dp[u][v] + x * y);         }       }     }     ll ret = 0;     for (int i = 0; i < n; i++)       for (int j = 0; j < n; j++) ret = max(ret, dp[i][j]);     cout << ret << endl;   }
#include <bits/stdc++.h>   const long double pie = 3.1415926535;   using namespace std;   bool br1, br2, br;   long long n, k, x, y, z, mini, maxi, l, ind, ini, sum, t, len, r, q, imini, w,       m;   string s, s1, s2;   struct Point {     long long X, Y;     static long long getDir(Point a, Point b, Point c) {       return ((b.X - a.X) * (c.Y - a.Y) - (b.Y - a.Y) * (c.X - a.X));     }   };   void solve() {     Point A, B, C;     cin >> A.X >> A.Y >> B.X >> B.Y >> C.X >> C.Y;     m = A.getDir(A, B, C);     if (m == 0)       cout <<  TOWARDS  << endl;     else if (m > 0)       cout <<  LEFT  << endl;     else       cout <<  RIGHT  << endl;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(NULL);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 5, M = 65;   long long n, q, d = 60, fa[N], opt, x, s[M];   double f[N][M];   void update(long long v) {     long long top = 0, x = v;     for (long long i = 0; i <= d; i++) {       if (!x) break;       s[top++] = x, x = fa[x];     }     top--;     for (long long i = top; i >= 2; i--)       f[s[i]][i] /= 0.5 * (1 + f[s[i - 1]][i - 1]);     for (long long i = 1; i <= d; i++) f[v][i] = 1;     for (long long i = 1; i <= top; i++)       f[s[i]][i] *= 0.5 * (1 + f[s[i - 1]][i - 1]);   }   double query(long long v) {     double ans = 0;     for (long long i = 1; i < d; i++) ans += i * (f[v][i + 1] - f[v][i]);     return ans;   }   signed main() {     scanf( %lld , &q), n = 1;     for (long long i = 1; i <= d; i++) f[1][i] = 1;     while (q--) {       scanf( %lld%lld , &opt, &x);       if (opt == 1)         n++, fa[n] = x, update(n);       else         printf( %.10lf n , query(x));     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MaxN = 2e5 + 10;   const int MOD = 1e9 + 7;   const int INF = 1e9;   int main() {     int L, n, p, t;     cin >> L >> n >> p >> t;     if (n == 0) {       cout << 0 <<   n ;       exit(0);     }     vector<pair<int, int> > seg(n);     for (int i = 0; i < n; ++i) {       cin >> seg[i].first >> seg[i].second;     }     sort(seg.begin(), seg.end());     set<pair<int, int> > st;     map<int, int> f;     for (int i = 0; i < n; ++i) {       st.insert(make_pair(seg[i].first, i));     }     int ans = 0;     while (!st.empty()) {       int x = st.begin()->first, where = st.begin()->second;       ans = max(ans, f[x]);       st.erase(st.begin());       int ex = seg[where].second;       if (where + 1 < (int)seg.size()) {         f[seg[where + 1].first] = max(f[seg[where + 1].first], f[x]);       }       int can = (ex - x) / p;       int val = f[x] + can;       ans = max(ans, f[x] + can);       if (where + 1 < n && f[seg[where + 1].first] >= val) {         continue;       }       x += (ex - x) / p * p + t;       if (where + 1 < n && seg[where + 1].first >= x) {         f[seg[where + 1].first] = max(f[seg[where + 1].first], val);         continue;       }       int pos = lower_bound(seg.begin(), seg.end(), make_pair(x, INF)) -                 seg.begin() - 1;       if (pos < n && seg[pos].first <= x && x <= seg[pos].second) {         st.insert(make_pair(x, pos));         f[x] = max(f[x], val);       } else if (pos + 1 != n) {         f[seg[pos + 1].first] = max(f[seg[pos + 1].first], val);       }     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n;   vector<string> cards;   map<vector<string>, bool> used;   void rec(vector<string>& x) {     if (x.size() == 1) {       puts( YES );       exit(0);     }     if (used[x] == true) return;     used[x] = true;     int p = x.size() - 1;     if (x[p][0] == x[p - 1][0] || x[p][1] == x[p - 1][1]) {       string s = x[p - 1];       string c = x[p];       x[p - 1] = x[p];       x.pop_back();       rec(x);       x[p - 1] = s;       x.push_back(c);     }     if (p > 2 && (x[p][0] == x[p - 3][0] || x[p][1] == x[p - 3][1])) {       string s = x[p - 3];       string c = x[p];       x[p - 3] = x[p];       x.pop_back();       rec(x);       x[p - 3] = s;       x.push_back(c);     }   }   int main() {     cin >> n;     for (int i = 0; i < n; i++) {       string s;       cin >> s;       cards.push_back(s);     }     rec(cards);     puts( NO );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   using ld = long double;   using pii = pair<int, int>;   const int INF = (int)1e9;   struct Car {     int x = INF;     ll time = 0;     int id = -1;     Car() = default;     Car(int xx, ll t, int i) : x(xx), time(t), id(i) {}   };   Car get_best(const Car& a, const Car& b, int x) {     int d1 = abs(x - a.x);     int d2 = abs(x - b.x);     if (d1 != d2) return d1 < d2 ? a : b;     if (a.time != b.time) return a.time < b.time ? a : b;     return a.id < b.id ? a : b;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(nullptr);     map<int, set<pair<ll, int>>> waiting;     int n, k, m;     cin >> n >> k >> m;     for (int i = 0; i < k; i++) {       int x;       cin >> x;       waiting[x].insert({0, i});     }     ll curt = 0;     map<ll, vector<pii>> events;     for (int i = 0; i < m; i++) {       ll t, a, b;       cin >> t >> a >> b;       curt = max(curt, t);       while (events.size() && events.begin()->first <= curt) {         auto e = *events.begin();         events.erase(events.begin());         for (auto p : e.second) waiting[p.first].insert({e.first, p.second});       }       if (waiting.empty()) {         assert(events.size());         auto e = *events.begin();         events.erase(events.begin());         for (auto p : e.second) waiting[p.first].insert({e.first, p.second});         curt = e.first;       }       assert(waiting.size());       Car L;       Car R;       auto it = waiting.lower_bound(a);       if (it != waiting.end())         L = Car(it->first, it->second.begin()->first, it->second.begin()->second);       if (it != waiting.begin()) {         --it;         R = Car(it->first, it->second.begin()->first, it->second.begin()->second);       }       Car best = get_best(L, R, a);       assert(best.id != -1);       cout << best.id + 1 <<     << curt - t + abs(a - best.x) <<   n ;       waiting[best.x].erase({best.time, best.id});       if (waiting[best.x].empty()) waiting.erase(best.x);       events[curt + abs(a - best.x) + abs(a - b)].push_back({b, best.id});     }   }
#include <bits/stdc++.h>   using namespace std;   char st1[100010], st2[100010];   int a1[100010], a2[100010], b1[100010], b2[100010];   int n;   int read() {     int x = 0, f = 1;     char ch = getchar();     while (ch <  0  ||  9  < ch) {       if (ch ==  - ) f = -1;       ch = getchar();     }     while ( 0  <= ch && ch <=  9 ) {       x = x * 10 + ch -  0 ;       ch = getchar();     }     return x * f;   }   int main() {     scanf( %s%s , st1 + 1, st2 + 1);     for (int i = 1; st1[i] != 0; i++) {       if (st1[i] ==  A ) a1[i] = a1[i - 1] + 1;       b1[i] = b1[i - 1] + (st1[i] !=  A );     }     for (int i = 1; st2[i] != 0; i++) {       if (st2[i] ==  A ) a2[i] = a2[i - 1] + 1;       b2[i] = b2[i - 1] + (st2[i] !=  A );     }     n = read();     while (n--) {       int l1 = read(), r1 = read(), l2 = read(), r2 = read(), ok = 1;       int s1 = b1[r1] - b1[l1 - 1], s2 = b2[r2] - b2[l2 - 1];       int x1 = min(r1 - l1 + 1, a1[r1]), x2 = min(r2 - l2 + 1, a2[r2]);       if (s1 > s2 || (s1 + s2) % 2 == 1 || x1 < x2) ok = 0;       if (s1 == s2 && x1 % 3 != x2 % 3 || s1 == 0 && x1 == x2 && s1 != s2) ok = 0;       printf( %d , ok);     }   }
#include <bits/stdc++.h>   const int MX = 2e6 + 7;   const int N = 1e9 + 1;   const int mod = 998244353;   const double pi = acos(-1);   double esp = 1e-13;   using namespace std;   long long qpow(long long a, long long b, long long MOD = mod) {     for (long long ans = 1;; a = a * a % MOD, b >>= 1) {       if (b & 1) ans = ans * a % MOD;       if (!b) return ans;     }   }   long long inv(long long a, long long MOD = mod) {     return qpow(a, MOD - 2, MOD);   }   long long exgcd(long long a, long long b, long long &x, long long &y) {     if (b == 0) {       x = 1, y = 0;       return a;     }     long long ret = exgcd(b, a % b, y, x);     y -= a / b * x;     return ret;   }   long long getInv(int a, int mod) {     long long x, y;     long long d = exgcd(a, mod, x, y);     return d == 1 ? (x % mod + mod) % mod : -1;   }   long long add(long long a, long long b) {     long long ans = (a + b) % mod;     return ans >= 0 ? ans : ans + mod;   }   void mul(long long &a, long long b) { a = a % mod * (b % mod) % mod; }   int main() {     ios::sync_with_stdio(0), cin.tie(0);     int t;     cin >> t;     while (t--) {       int n;       cin >> n;       priority_queue<pair<int, int>> Q;       for (int i = 1; i <= n; i++) {         int x;         cin >> x;         Q.push(make_pair(x, i));       }       int tmp = 0, res = 0;       while (!Q.empty()) {         auto x = Q.top();         Q.pop();         if (x.second == res) {           if (Q.empty()) {             break;           } else {             tmp++;             auto y = Q.top();             Q.pop();             y.first--;             if (y.first != 0) Q.push(y);             res = y.second;             Q.push(x);           }         } else {           tmp++;           x.first--;           if (x.first != 0) Q.push(x);           res = x.second;         }       }       cout << (tmp % 2 == 0 ?  HL  :  T ) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int n, m;   int R[101];   double dp[100100], sum[100100];   int main() {     scanf( %d%d , &n, &m);     if (m == 1) {       puts( 1 );       return 0;     }     int score = 0;     dp[0] = 1;     double f = 1. / (m - 1);     for (int i = 0; i < n; ++i) {       scanf( %d , R + i);       score += R[i];     }     for (int i = 0; i < n; ++i) {       int r = R[i];       sum[0] = dp[0];       for (int j = 1; j <= min(score - 1, (i + 1) * m); ++j) {         sum[j] = sum[j - 1] + dp[j];       }       for (int j = min(score - 1, (i + 1) * m); j > 0; --j) {         dp[j] = sum[j - 1];         if (j - m - 1 >= 0) dp[j] -= sum[j - m - 1];         if (j - r >= 0) dp[j] -= dp[j - r];         dp[j] *= f;       }       dp[0] = 0;     }     double res = 1;     for (int i = 0; i < score; ++i) {       res += dp[i] * (m - 1);     }     printf( %.15lf n , res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int M = 998244353;   int pow(int a, int b) {     if (b == 0) {       return 1;     }     if (b % 2) {       return ((long long)a * pow(a, b - 1)) % M;     } else {       int temp = pow(a, b / 2);       return ((long long)temp * temp) % M;     }   }   int inv[3010];   int w[55];   int a[55];   int dp1[55][55][55];   int dp2[55][55][55];   int main() {     ios_base::sync_with_stdio(0), cin.tie(0);     int n, m;     cin >> n >> m;     for (int i = 0; i < 3010; i++) {       inv[i] = pow(i, M - 2);     }     for (int i = 0; i < n; i++) {       cin >> a[i];     }     int s = 0, s1 = 0, s2 = 0;     for (int i = 0; i < n; i++) {       cin >> w[i];       s += w[i];       if (a[i]) {         s1 += w[i];       }     }     s2 = s - s1;     for (int i = 0; i < n; i++) {       dp1[i][0][0] = 1;     }     for (int l = 0; l < m; l++) {       for (int i = 0; i < n; i++) {         for (int j = 0; j < 55; j++) {           for (int k = 0; k < 55; k++) {             if (a[i]) {               dp2[i][j][k] = (long long)dp1[i][j][k] * (s2 - l + j) % M *                              inv[s + 2 * j - l] % M;               if (k && j)                 dp2[i][j][k] = (dp2[i][j][k] + (long long)dp1[i][j - 1][k - 1] *                                                    (w[i] + k - 1) % M *                                                    inv[s + 2 * j - l - 2] % M) %                                M;               if (j)                 dp2[i][j][k] = (dp2[i][j][k] + (long long)dp1[i][j - 1][k] *                                                    (s1 + j - w[i] - k - 1) % M *                                                    inv[s + 2 * j - 2 - l] % M) %                                M;             } else {               dp2[i][j][k] = (long long)dp1[i][j][k] * (s2 - l + j - (w[i] - k)) %                              M * inv[s + 2 * j - l] % M;               if (k)                 dp2[i][j][k] = (dp2[i][j][k] + (long long)dp1[i][j][k - 1] *                                                    (w[i] - (k - 1)) % M *                                                    inv[s + 2 * j - l] % M) %                                M;               if (j)                 dp2[i][j][k] =                     (dp2[i][j][k] + (long long)dp1[i][j - 1][k] * (s1 + j - 1) %                                         M * inv[s + 2 * j - 2 - l] % M) %                     M;             }           }         }       }       for (int i = 0; i < 55; i++) {         for (int j = 0; j < 55; j++) {           for (int k = 0; k < 55; k++) {             dp1[i][j][k] = dp2[i][j][k];           }         }       }     }     for (int i = 0; i < n; i++) {       int ans = 0;       for (int j = 0; j < 55; j++) {         for (int k = 0; k < 55; k++) {           if (a[i]) {             int temp = (long long)(w[i] + k) * dp1[i][j][k] % M;             ans = (ans + temp) % M;           } else {             int temp = (long long)(w[i] - k) * dp1[i][j][k] % M;             ans = (ans + temp) % M;           }         }       }       cout << ans << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200010;   const int MOD = 1000000007;   const int INF = 0x3fffffff;   typedef struct Node {     long long v;     int p;     Node(long long v_, int p_) {       v = v_;       p = p_;     }     bool operator<(const Node& other) const {       return v < other.v || (v == other.v && p > other.p);     }   } Node;   long long a[N];   int main() {     ios::sync_with_stdio(false);     int n, k;     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; ++i) {       scanf( %I64d , &a[i]);       a[i] += a[i - 1];     }     priority_queue<Node> Q;     Q.push(Node(a[n] - a[n - k], n + 1 - k));     long long ans = 0;     int ansa, ansb;     int q = n + 1 - k;     for (int i = n + 1 - k - k; i > 0; --i) {       if (ans <= Q.top().v + a[i + k - 1] - a[i - 1]) {         ans = Q.top().v + a[i + k - 1] - a[i - 1];         ansa = i;         ansb = Q.top().p;       }       --q;       Q.push(Node(a[q + k - 1] - a[q - 1], q));     }     printf( %d %d n , ansa, ansb);     return 0;   }