malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   using pii = pair<int, int>;   const int rows[5] = {3, 4, 5, 4, 3};   bool dp[1 << 19], seen[1 << 19];   pii int_to_pair(int c) {     pii res = {0, 0};     while (rows[res.first] <= c) {       c -= rows[res.first];       res.first++;     }     res.second = c;     return res;   }   int pair_to_int(pii p) {     int res = 0;     for (int i = 0; i < p.first; i++) res += rows[i];     res += p.second;     return res;   }   pii next_coords(pii p, int dir) {     if (dir == 0) {       return {p.first, p.second - 1};     } else if (dir == 1) {       if (p.first <= 2) {         return {p.first - 1, p.second - 1};       } else {         return {p.first - 1, p.second};       }     } else if (dir == 2) {       if (p.first <= 2) {         return {p.first - 1, p.second};       } else {         return {p.first - 1, p.second + 1};       }     } else if (dir == 3) {       return {p.first, p.second + 1};     } else if (dir == 4) {       if (p.first >= 2) {         return {p.first + 1, p.second};       } else {         return {p.first + 1, p.second + 1};       }     } else if (dir == 5) {       if (p.first >= 2) {         return {p.first + 1, p.second - 1};       } else {         return {p.first + 1, p.second};       }     }   }   void print_box(int box) {     int b = 0;     for (int i = 0; i < 5; i++) {       for (int j = 0; j < 5 - rows[i]; j++) printf(   );       for (int j = 0; j < rows[i]; j++) {         printf( %c  ,  .O [(box >> b) & 1]);         b++;       }       printf(  n );     }   }   bool getdp(int box) {     if (box == 0) return false;     if (seen[box]) {       return dp[box];     }     seen[box] = true;     for (int i = 0; i < 19; i++) {       if (!(box & (1 << i))) {         continue;       }       for (int dir = 0; dir < 6; dir++) {         int boxcpy = box;         pii curr = int_to_pair(i);         while (true) {           if (curr.first < 0) break;           if (curr.first > 4) break;           if (curr.second < 0) break;           if (curr.second >= rows[curr.first]) break;           if (!(boxcpy & (1 << pair_to_int(curr)))) {             break;           }           boxcpy ^= (1 << pair_to_int(curr));           if (!getdp(boxcpy)) {             dp[box] = true;             return true;           }           curr = next_coords(curr, dir);         }       }     }     return false;   }   int main() {     int start_box = 0;     for (int i = 0; i < 19; i++) {       char c;       cin >> c;       if (c ==  O ) start_box |= 1 << i;     }     if (getdp(start_box)) {       cout <<  Karlsson n ;     } else {       cout <<  Lillebror n ;     }   }
#include <bits/stdc++.h>   int n, u[1001], v[1001], dem[1001], ans = 0;   using namespace std;   void input() {     cin >> n;     for (int i = 1; i < n; i++) {       cin >> u[i] >> v[i];     }   }   void output() { cout << ans << endl; }   void solve() {     for (int i = 1; i <= n; i++) {       for (int j = 1; j < n; j++) {         if (u[j] == i) dem[i]++;         if (v[j] == i) dem[i]++;       }     }     for (int i = 1; i <= n; i++) {       if (dem[i] == 1) ans++;     }   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     input();     solve();     output();   }
#include <bits/stdc++.h>   using namespace std;   char s1[200005], s2[200005];   int len;   bool judge(int p, char *s1, char *s2) {     for (int i = 0; i < p; i++) {       if (s1[i] != s2[i]) return 0;     }     return 1;   }   int check(int p, char *s1, char *s2) {     if (p == 1) {       if (s1[0] != s2[0]) return 0;       return 1;     }     if (judge(p, s1, s2)) return 1;     int len = p;     if (len & 1) return 0;     return (check(len / 2, s1, s2) &&             check(len / 2, s1 + len / 2, s2 + len / 2)) ||            (check(len / 2, s1 + len / 2, s2) && check(len / 2, s1, s2 + len / 2));   }   int main(void) {     int i, j;     while (~scanf( %s%s , s1, s2)) {       int len = strlen(s1);       if (check(len, s1, s2))         puts( YES );       else         puts( NO );     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<int> a;   int main() {     int n, x, ans;     cin >> n >> x;     ans = x;     a.resize(n);     for (int i = 0; i < (int)(n); i++) {       cin >> a[i];     }     for (int i = 0; i < (int)(n); i++) {       for (int j = i; j < n; j++) {         ans = max(ans, (x / a[i]) * a[j] + (x % a[i]));       }     }     cout << ans;   }
#include <bits/stdc++.h>   using namespace std;   bool check(const pair<long long, long long> &a,              const pair<long long, long long> &b) {     if (a.first > b.first)       return true;     else if (a.first < b.first)       return false;     else {       if (a.second < b.second)         return true;       else         return false;     }   }   int main() {     long long n, k, a, b, i, ans = 0;     cin >> n >> k;     vector<pair<long long, long long>> v;     for (i = 0; i < n; i++) {       cin >> a >> b;       v.push_back({a, b});     }     sort(v.begin(), v.end(), check);     for (i = 0; i < n; i++) {       if (v[i].first == v[k - 1].first && v[i].second == v[k - 1].second) ans++;     }     cout << ans <<   n ;     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( Ofast )   #pragma GCC optimize( no-stack-protector )   #pragma GCC optimize( unroll-loops )   #pragma GCC target( sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native )   #pragma GCC optimize( fast-math )   #pragma warning(disable : 4996)   using namespace std;   const int MAXN = 100001;   const int inf = 1000000000;   const long double INF = 1.0 / 0.0;   const long double EPS = 1e-7;   const int mod = inf + 7;   const long double PI = acos(-1.0);   signed main() {     ios_base::sync_with_stdio(0);     cout.tie(0);     cin.tie(0);     ;     long double d, l, v1, v2;     cin >> d >> l >> v1 >> v2;     cout << fixed << (l - d) / (v1 + v2);   }
#include <bits/stdc++.h>   using namespace std;   const int nax = 5005;   const int mod = 1e9 + 7;   const int inf = 1e9 + 120;   int t[nax];   char sl[nax];   int pref[nax][nax];   int nxt[nax][nax];   int cmp(int i, int j) {     if (t[i] < t[j]) return -1;     if (t[i] > t[j]) return 1;     return 0;   }   int dp(int a, int b) {     int x = pref[a][b] - pref[a - 1][b];     if (x < 0) x += mod;     return x;   }   int main() {     int n;     scanf( %d , &n);     scanf( %s , sl);     for (int i = (1); i <= ((n)); ++i) t[i] = sl[i - 1] -  0 ;     for (int a = n; a >= 1; --a)       for (int b = n; b > a; --b) {         int& x = nxt[a][b];         if (t[a] != t[b])           x = a;         else if (b == n)           x = inf;         else           x = nxt[a + 1][b + 1];       }     for (int i = (1); i <= ((n)); ++i) {       for (int j = (1); j <= ((n)); ++j) pref[j][i] = 1;     }     for (int c = (2); c <= (n); ++c)       for (int d = (c); d <= (n); ++d) {         int& x = pref[c][d];         int b = c - 1;         int a = b - (d - c);         x = pref[b][b] - pref[max(a, 0)][b];         if (x < 0) x += mod;         if (a >= 1) {           int where = nxt[a][c];           if (where < c && t[where] < t[c + where - a]) {             x += dp(a, b);             if (x >= mod) x -= mod;           }         }         if (t[c] == 0) x = 0;         pref[c][d] = x + pref[c - 1][d];         if (pref[c][d] >= mod) pref[c][d] -= mod;       }     int ans = 0;     for (int i = (1); i <= ((n)); ++i) ans = (ans + dp(i, n)) % mod;     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   #pragma GCC optimize( O3 )   using namespace std;   string to_string(string s) { return     + s +    ; }   string to_string(const char* s) { return to_string((string)s); }   string to_string(bool b) { return (b ?  true  :  false ); }   template <typename A, typename B>   string to_string(pair<A, B> p) {     return  (  + to_string(p.first) +  ,   + to_string(p.second) +  ) ;   }   template <typename A>   string to_string(A v) {     bool first = true;     string res =  { ;     for (const auto& x : v) {       if (!first) {         res +=  ,  ;       }       first = false;       res += to_string(x);     }     res +=  } ;     return res;   }   void debug_out() { cerr << endl; }   template <typename Head, typename... Tail>   void debug_out(Head H, Tail... T) {     cerr <<     << to_string(H);     debug_out(T...);   }   const int N = 2e3 + 7, M = 1e4, OO = 0x3f3f3f3f;   int vis[N][N];   int main() {     int TCF = 1;     while (TCF--) {       int n;       scanf( %d , &n);       ;       vector<pair<int, int>> p;       int x, y;       for (int i = 0; i < n; ++i) {         scanf( %d %d , &x, &y);         p.emplace_back(x, y);         vis[x + 1000][y + 1000] = 1;       }       vector<pair<int, int>> mid;       int ans = 0;       for (int i = (0); i < (n); i++) {         for (int j = (i + 1); j < (n); j++) {           if (i == j) continue;           int mx = p[i].first + p[j].first;           int my = p[i].second + p[j].second;           if (mx % 2 == 0 && my % 2 == 0) {             mx /= 2;             my /= 2;             if (vis[mx + 1000][my + 1000]) {               ans++;             }           }         }       }       printf( %d n , ans);     }   }
#include <bits/stdc++.h>   using namespace std;   const double eps = 1e-9;   int main(void) {     int n, q, a, b;     scanf( %d%d%d%d , &n, &q, &a, &b);     vector<int> x(n);     for (int i = 0; i < n; ++i) {       scanf( %d , &x[i]);     }     vector<double> y(n);     vector<int> from(n, -1);     y[0] = x[0];     for (int i = 1; i < n; ++i) {       double shiftSum = 0.0;       shiftSum = 0.0;       double curPos = x[i];       int j;       double shift = 0.0;       double maxShift = q - curPos;       double minShift = 1.0 - curPos;       for (j = i - 1; j >= 0; j--) {         shift = max(minShift, min(maxShift, shiftSum / (i - j)));         double pos = curPos + shift;         if (pos >= y[j] + a - eps && pos <= y[j] + b + eps) break;         if (pos >= y[j] + b) {           curPos -= b;         } else {           curPos -= a;         }         minShift = max(minShift, 1.0 - curPos);         shiftSum += x[j] - curPos;       }       shift = max(minShift, min(maxShift, shiftSum / (i - j)));       y[i] = x[i] + shift;       from[i] = j;     }     vector<double> ry(n);     for (int i = n - 1; i >= 0;) {       double shift = y[i] - x[i];       ry[i] = y[i];       for (int j = i - 1; j > from[i]; --j) {         if (ry[j + 1] >= y[j] + b)           ry[j] = ry[j + 1] - b;         else           ry[j] = ry[j + 1] - a;       }       i = from[i];     }     double res = 0.0;     for (int i = 0; i < n; ++i) {       double d = ry[i] - x[i];       res += d * d;       printf( %.9lf  , ry[i]);     }     printf(  n%.9lf n , res);   }
#include <bits/stdc++.h>   bool IsCircular(const std::string &s, const int n) {     bool isCircular = true;     for (int i = 0; i < n; i++) {       int j = (i + 1) % n;       isCircular &=           ((s[i] ==  >  || s[i] ==  - ) && (s[j] ==  >  || s[j] ==  - ));     }     if (isCircular) return true;     isCircular = true;     for (int i = 0; i < n; i++) {       int j = (i + 1) % n;       isCircular &=           ((s[i] ==  <  || s[i] ==  - ) && (s[j] ==  <  || s[j] ==  - ));     }     return isCircular;   }   int main() {     int t;     std::cin >> t;     while (t--) {       int n;       std::string s;       std::cin >> n >> s;       if (IsCircular(s, n))         std::cout << n << std::endl;       else {         int ans = 0;         for (int i = 0; i < n; i++) {           int j = (i - 1 + n) % n;           if (s[i] ==  -  || s[j] ==  - ) ans++;         }         std::cout << ans << std::endl;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = (1 << 18) + 10;   int n, m;   long long tree[N], add[N];   int same[N];   int col[N];   void build(int x, int l, int r) {     tree[x] = same[x] = col[x] = add[x] = 0;     if (l == r) {       same[x] = 1;       col[x] = l + 1;       return;     }     int s = (l + r) / 2;     build(x + x + 1, l, s);     build(x + x + 2, s + 1, r);   }   int push(int x, int l, int r) {     if (add[x]) {       tree[x] += (long long)(r - l + 1) * add[x];       if (l != r) {         add[x * 2 + 1] += add[x];         add[x * 2 + 2] += add[x];       }       add[x] = 0;     }     if (same[x]) {       if (l != r) {         same[x * 2 + 1] = same[x * 2 + 2] = 1;         col[x * 2 + 1] = col[x * 2 + 2] = col[x];       }     }     return 0;   }   long long upd(int x, int l, int r, int lc, int rc, int y) {     push(x, l, r);     if (r < lc || l > rc) return tree[x];     if (lc <= l && r <= rc) {       if (same[x]) {         add[x] += abs(col[x] - y);         col[x] = y;         push(x, l, r);         return tree[x];       } else         same[x] = 1, col[x] = y;     } else if (same[x] && col[x] != y)       col[x] = same[x] = 0;     int s = (l + r) / 2;     return tree[x] = upd(x + x + 1, l, s, lc, rc, y) +                      upd(x + x + 2, s + 1, r, lc, rc, y);   }   long long get(int x, int l, int r, int lc, int rc) {     push(x, l, r);     if (r < lc || l > rc) return 0;     if (lc <= l && r <= rc) return tree[x];     int s = (l + r) / 2;     return get(x + x + 1, l, s, lc, rc) + get(x + x + 2, s + 1, r, lc, rc);   }   int main() {     scanf( %d%d , &n, &m);     build(0, 0, n - 1);     int t, l, r, x;     for (int i = 0; i < m; i++) {       scanf( %d , &t);       if (t == 1) {         scanf( %d%d%d , &l, &r, &x);         l--;         r--;         upd(0, 0, n - 1, l, r, x);       } else {         scanf( %d%d , &l, &r);         l--;         r--;         printf( %I64d n , get(0, 0, n - 1, l, r));       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long n;     cin >> n;     string s;     cin >> s;     for (long long i = 0; i < s.size(); i++) {       if (s[i] ==  *  && i + 4 <= s.size()) {         for (long long j = 1; j < s.size(); j++) {           if (i + 4 * j <= s.size()) {             if (s[i] ==  *  && s[i + j] ==  *  && s[i + 2 * j] ==  *  &&                 s[i + 3 * j] ==  *  && s[i + 4 * j] ==  * ) {               cout <<  yes ;               return 0;             }           }         }       }     }     cout <<  no ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1E6 + 50;   const long long p = 1E9 + 7;   int n, k;   long long ans, sum, f[N], s[N], fac[N], inv[N];   inline void upd(long long &a, long long b) {     a += b;     if (a >= p) a -= p;   }   inline void sub(long long &a, long long b) {     a -= b;     if (a < 0) a += p;   }   long long Pow(long long a, long long b = p - 2) {     long long res = 1;     for (; b; b >>= 1, a = a * a % p)       if (b & 1) res = res * a % p;     return res;   }   void init() {     fac[0] = inv[0] = 1;     for (register int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % p;     inv[n] = Pow(fac[n]);     for (register int i = n - 1; i; --i) inv[i] = inv[i + 1] * (i + 1) % p;   }   int main() {     scanf( %d%d , &n, &k);     if (k >= n) return 0 * printf( 0 n );     init();     f[0] = s[0] = 1;     for (register int i = 1; i <= k; ++i) {       f[i] = fac[i], s[i] = 1;       upd(sum, s[i]);     }     for (register int i = k + 1; i <= n; ++i) {       f[i] = sum * fac[i - 1] % p;       s[i] = f[i] * inv[i] % p;       upd(sum, s[i]), sub(sum, s[i - k]);     }     for (int i = 0; i < n - k; ++i) sub(ans, s[i]);     ans = ans * fac[n - 1] % p;     sub(ans, f[n]);     upd(ans, fac[n]);     printf( %lld n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.tie(nullptr);     cerr.tie(nullptr);     int n, res = 0, t, b;     cin >> n;     while (n) {       res++;       t = n;       b = -1;       while (t) {         b = max(b, t % 10);         t /= 10;       }       n -= b;     }     cout << res << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int N, a[55], P;   double dp[55][55][55];   double fac(int n) {     double ans = 1;     for (int i = 0; i < (n); i++) ans *= (i + 1);     return ans;   }   int main(int argc, char *argv[]) {     scanf( %d , &N);     for (int i = 0; i < (N); i++) scanf( %d , a + i);     scanf( %d , &P);     dp[0][0][0] = 1;     for (int i = 0; i < (N); i++)       for (int in = (0); in <= (N); in++)         for (int p = (0); p <= (P); p++)           if (dp[i][in][p]) {             dp[i + 1][in][p] += dp[i][in][p];             if (p + a[i] <= P) dp[i + 1][in + 1][p + a[i]] += dp[i][in][p];           }     double tmp = 0, ans = 0, sum;     for (int in = (N); in >= (0); in--) {       sum = 0;       for (int p = (0); p <= (P); p++) sum += dp[N][in][p];       sum *= fac(in) * fac(N - in);       ans += in * (sum - tmp);       tmp = sum;     }     printf( %.9lf n , ans / fac(N));     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 7;   const int LG = 27;   const int INF = 1e9 + 7;   pair<int, int> seg[LG][N];   int mx[LG][N];   int r[N], a[N], sol[N];   pair<int, int> p[N];   int n, k;   void build(int l = 0, int r = n, int d = 0) {     if (r - l == 1) {       seg[d][l] = make_pair(p[l].second, l);       mx[d][l] = sol[l];       return;     }     int mid = (l + r) / 2;     build(l, mid, d + 1);     build(mid, r, d + 1);     merge(seg[d + 1] + l, seg[d + 1] + mid, seg[d + 1] + mid, seg[d + 1] + r,           seg[d] + l);     int out = 0;     for (int i = r - 1; i >= l; i--) {       out = max(out, sol[seg[d][i].second]);       mx[d][i] = out;     }   }   pair<int, int> get(int l, int r, int val, int s = 0, int e = n, int d = 0) {     if (l >= e || r <= s) return make_pair(0, 0);     if (l <= s && e <= r) {       int pos = lower_bound(seg[d] + s, seg[d] + e, make_pair(val, 0)) - seg[d];       int pos2 =           lower_bound(seg[d] + s, seg[d] + e, make_pair(val + 1, 0)) - seg[d];       int ans1 = 0;       if (pos < e) ans1 = mx[d][pos];       return make_pair(ans1, pos2 - s);     }     int mid = (s + e) / 2;     pair<int, int> a = get(l, r, val, s, mid, d + 1);     pair<int, int> b = get(l, r, val, mid, e, d + 1);     return make_pair(max(a.first, b.first), a.second + b.second);   }   int main() {     scanf( %d %d , &n, &k);     for (int i = 0; i < n; i++) {       scanf( %d , &r[i]);       p[i].second = r[i];     }     for (int i = 0; i < n; i++) {       scanf( %d , &a[i]);       p[i].first = a[i];     }     sort(p, p + n);     build();     int L = 0, R = 0;     for (int i = 0; i < n; i++) {       while (L < n && p[L].first + k < p[i].first) L++;       while (R < n && p[i].first + k >= p[R].first) R++;       sol[i] = get(L, R, p[i].second).second;     }     build();     int m;     cin >> m;     while (m--) {       int x, y;       scanf( %d %d , &x, &y);       x--, y--;       if (a[x] > a[y]) swap(x, y);       int L = lower_bound(p, p + n, make_pair(a[y] - k, 0)) - p;       int R = lower_bound(p, p + n, make_pair(a[x] + k + 1, 0)) - p;       int ans = get(L, R, max(r[x], r[y])).first;       if (ans < 2)         printf( -1 n );       else         printf( %d n , ans);     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   template <typename t>   inline void read(t &x) {     x = 0;     char c = getchar(), f = 0;     for (; c <  0  || c >  9 ; c = getchar())       if (c ==  - ) f = 1;     for (; c >=  0  && c <=  9 ; c = getchar())       x = (x << 1) + (x << 3) + (c ^ 48);     if (f) x = -x;   }   int n, rs[100005], tp;   char vs[100005];   inline void dfs(int x) {     if (vs[x])       return;     else       vs[x] = 1, dfs(x * 2 % n), dfs((x * 2 + 1) % n), rs[++tp] = x;   }   int main() {     read(n);     if (n & 1) return puts( -1 ), 0;     dfs(0);     while (tp) printf( %d  , rs[tp--]);     return printf( 0 n ), 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int x, v, arr[1000], c = 0;     cin >> x >> v;     for (int i = 0; i < x - 1; i++) {       cin >> arr[i];     }     while (1) {       sort(arr, arr + x - 1);       if (v > arr[x - 2]) break;       arr[x - 2]--;       v++;       c++;     }     cout << c;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int f(char c) { return c - 48; }   void soroban(int n, char *ans) {     if (n < 5) {       ans[0] =  O ;       ans[1] =  - ;       ans[2] =  | ;       for (int i = 3; i <= 7; i++) {         if (i == n + 3) {           ans[i] =  - ;         } else {           ans[i] =  O ;         }       }     } else {       ans[0] =  - ;       ans[1] =  O ;       ans[2] =  | ;       for (int i = 3; i <= 7; i++) {         if (i == n - 2) {           ans[i] =  - ;         } else {           ans[i] =  O ;         }       }     }     ans[8] =   0 ;   }   int main() {     char ch[10], ans[10];     cin >> ch;     for (int i = strlen(ch) - 1; i >= 0; i--) {       soroban(f(ch[i]), ans);       cout << ans << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int A[5005], n, k, L[5005][5005], S[5005], E[5005];   void doc() {     scanf( %d%d , &n, &k);     for (int i = 1; i <= n; i++) {       scanf( %d , &A[i]);     }   }   void xuly() {     sort(A + 1, A + n + 1);     for (int i = 1; i <= n; i++) {       S[i] = 1;       E[i] = i;       for (int j = i - 1; j > 0; j--)         if (A[i] - A[j] <= 5) {           S[i]++;           E[i] = j;         } else           break;     }     for (int i = 1; i <= k; i++) {       for (int j = 1; j <= n; j++) {         L[i][j] = max(max(L[i][j - 1], L[i][j]), L[i - 1][E[j] - 1] + S[j]);       }     }     cout << L[k][n];   }   int main() {     doc();     xuly();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int INF = 1e9 + 7;   const long long mod = 998244353;   const int maxn = 3005;   int dp[maxn][maxn];   int dp2[maxn][maxn];   long long add(long long a, long long b) { return (a + b) % mod; }   long long mul(long long a, long long b) { return (a * b) % mod; }   long long bin_pow(long long a, long long b) {     long long res = 1;     long long tmp = a;     while (b) {       if (b & 1) {         res = mul(res, tmp);       }       tmp = mul(tmp, tmp);       b >>= 1;     }     return res;   }   long long inv(long long a) { return bin_pow(a, mod - 2); }   long long min(long long a, long long b) {     if (a > b)       return b;     else       return a;   }   void solve() {     int n, m;     cin >> n >> m;     long long n_good = 0, n_bad = 0;     vector<bool> flags(n);     for (int i = 0; i < n; i++) {       int ai;       cin >> ai;       flags[i] = ai == 1;     }     vector<long long> weights(n);     for (int i = 0; i < n; i++) {       int w;       cin >> w;       weights[i] = w;       if (flags[i]) {         n_good += w;       } else {         n_bad += w;       }     }     for (int i = m; i >= 0; i--) {       dp[i][m - i] = dp2[i][m - i] = 1;       for (int j = min(m - i - 1, (long long)n_bad); j >= 0; j--) {         long long total = inv(n_good + n_bad + i - j);         long long tmp = mul(dp[i + 1][j], n_good + i + 1);         long long tmp2 = mul(dp[i][j + 1], n_bad - j);         long long tmp3 = add(tmp, tmp2);         dp[i][j] = mul(tmp3, total);         tmp = mul(dp2[i + 1][j], n_good + i);         tmp2 = mul(dp2[i][j + 1], n_bad - j - 1);         tmp3 = add(tmp, tmp2);         dp2[i][j] = mul(tmp3, total);       }     }     for (int i = 0; i < n; i++) {       if (flags[i]) {         cout << mul(weights[i], dp[0][0]);       } else {         cout << mul(weights[i], dp2[0][0]);       }       cout << endl;     }   }   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(false);     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int oo = (1e9) + 7;   int main() {     long long n;     cin >> n;     vector<long long> b(n / 2 + 5, 0);     for (int i = 1; i <= n / 2; i++) {       scanf( %lld , &b[i]);     }     vector<long long> out(n + 5, 0);     long long l = 0;     long long r = 0;     for (int i = 1; i <= n / 2; i++) {       out[i] = 0;       out[n - i + 1] = b[i];       if (i > 1) {         if (b[i] > r) {           out[i] = b[i] - r;           out[n - i + 1] = r;         }         long long tmp = b[i];         if (out[i] < l) {           out[i] = l;           out[n - i + 1] = b[i] - l;         }       }       l = out[i];       r = out[n - i + 1];     }     for (int i = 1; i <= n; i++) {       printf( %lld  , out[i]);     }     return 0;   }