malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   int INTlog2(unsigned long long number) {     int logval = 0;     while (number >>= 1) logval++;     return logval;   }   int main() {     unsigned long long n, k;     cin >> n >> k;     if (k == 1)       cout << n << endl;     else       cout << (1LL << (INTlog2(n) + 1LL)) - 1 << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long A[1048576];   long long B[30];   long long C[30];   long P[30];   void f(long n, long o) {     if (n > 1) {       f(n - 1, o);       f(n - 1, o + P[n - 1]);     }     sort(A + o, A + o + P[n - 1]);     sort(A + o + P[n - 1], A + o + P[n]);     long i = o;     long j = o + P[n - 1];     while (i != o + P[n - 1] && j != o + P[n]) {       if (A[i] < A[j]) {         B[n] += o + P[n] - j;         i += 1;       } else {         j += 1;       }     }     i = o;     j = o + P[n - 1];     while (i != o + P[n - 1] && j != o + P[n]) {       if (A[i] <= A[j]) {         i += 1;       } else {         C[n] += o + P[n - 1] - i;         j += 1;       }     }   }   int main(int, char**) {     ios_base::sync_with_stdio(false);     P[0] = 1;     for (long i = (1); i <= (29); ++i) P[i] = 2 * P[i - 1];     long n;     cin >> n;     for (long i = 0; i < (P[n]); ++i) cin >> A[i];     for (long i = 0; i < (29); ++i) B[i] = 0;     for (long i = 0; i < (29); ++i) C[i] = 0;     f(n, 0);     bitset<30> BS;     long m;     cin >> m;     for (long i = 0; i < (m); ++i) {       long q;       cin >> q;       while (q != 0) {         BS[q] = not BS[q];         q -= 1;       }       long long r = 0;       for (long j = 0; j < (n + 1); ++j) {         r += BS[j] ? B[j] : C[j];       }       cout << r <<   n ;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   bool helper(pair<int, int>* arr, int x, int y, int m) {     if (m == 0) {       return true;     }     int res = false;     if (x != -1) {       if (arr->first == x || arr->second == x) res = true;     }     if (y != -1) {       if (arr->second == y || arr->first == y) res = true;     }     if (!res) {       if (x == -1) {         return helper(arr + 1, arr->first, y, m - 1) ||                helper(arr + 1, arr->second, y, m - 1);       }       if (y == -1) {         return helper(arr + 1, x, arr->second, m - 1) ||                helper(arr + 1, x, arr->first, m - 1);       }       return false;     }     return helper(arr + 1, x, y, m - 1);   }   int main() {     int n, m;     cin >> n >> m;     pair<int, int> arr[m];     for (int i = 0; i < m; i++) {       cin >> arr[i].first >> arr[i].second;     }     if (helper(arr, -1, -1, m)) {       cout <<  YES  << endl;     } else {       cout <<  NO  << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mn = 1010000, mm = 10100;   int n, m, i, j, k, t, a[mm], la[30], sa[30];   map<int, int> ans;   char s[mn], c[30];   bool cmp(int i, int j) { return la[i] > la[j]; }   int main() {     scanf( %s , s + 1);     n = strlen(s + 1);     scanf( %d , &m);     for (i = 1; i <= m; ++i) {       scanf( %s , c + 1);       k = strlen(c + 1);       t = 0;       for (j = 1; j <= k; ++j) t |= 1 << (c[j] - 97);       ans[t] = 0, a[i] = t;     }     for (i = 0; i <= 25; ++i) sa[i] = i;     for (i = 1; i <= n; ++i) {       if (s[i] == s[i + 1]) continue;       la[s[i] - 97] = i;       k = s[i + 1] - 97, t = 0;       sort(sa, sa + 26, cmp);       for (j = 0; j <= 25; ++j) {         if (!la[sa[j]] || sa[j] == k) break;         t |= 1 << sa[j];         if (t == 5) {           ++la[30];         }         if (ans.count(t)) ++ans[t];       }     }     for (i = 1; i <= m; ++i) printf( %d n , ans[a[i]]);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n, m;     cin >> n >> m;     int nn = 1;     for (int i = 1; i < n; i++) {       int c = 0;       for (int j = 0; (1 << j) <= nn; j++) c++;       nn += c;     }     vector<int> P;     for (int i = 0; i < nn; i++) {       bool f = false;       for (int j = 0; (1 << j) <= i + 1; j++)         if ((1 << j) == i + 1) f = true;       for (int j = 0; j < (f ? 2 : 1); j++) P.push_back(i);     }     vector<int> type(m), t(m), l(m), r(m), x(m), v(m);     for (int i = 0; i < m; i++) {       cin >> type[i];       if (type[i] == 1) {         cin >> t[i] >> l[i] >> r[i] >> x[i];         t[i]--, l[i]--, r[i]--;       } else {         cin >> t[i] >> v[i];         t[i]--, v[i]--;       }     }     vector<set<int>> S(m);     vector<vector<int>> qn(n);     for (int i = m - 1; i >= 0; i--) {       if (type[i] == 1) {         int tt = t[i];         int tl = l[i];         int tr = r[i];         for (; tt >= 0; tt--) {           for (int j = 0; j < (int)qn[tt].size(); j++)             if (tl <= v[qn[tt][j]] && v[qn[tt][j]] <= tr)               S[qn[tt][j]].insert(x[i]);           tl = P[tl];           tr = P[tr];         }       } else {         qn[t[i]].push_back(i);       }     }     for (int i = 0; i < m; i++)       if (type[i] == 2) cout << S[i].size() << endl;   }
#include <bits/stdc++.h>   using namespace std;   int m1[4] = {1, 1, 1, 1};   int m2[4] = {1, 2, 4, 3};   int m3[4] = {1, 3, 4, 2};   int m4[4] = {1, 4, 1, 4};   int main() {     string s;     cin >> s;     int b = s[s.size() - 1] -  0 ;     int a;     if (s.size() > 1)       a = s[s.size() - 2] -  0 ;     else       a = 0;     int n = (10 * a + b) % 4;     cout << (m1[n] + m2[n] + m3[n] + m4[n]) % 5;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using LL = long long;   constexpr LL LINF = 334ll << 53;   constexpr int INF = 15 << 26;   constexpr LL MOD = 1E9 + 7;   struct Problem {     LL n;     vector<LL> p;     Problem(LL n) : n(n), p(n){};     void solve() {       LL ans = 0, minsum = LINF, sum = 0;       for (int i = 0; i < n; ++i) {         cin >> p[i];         p[i]--;       }       multiset<LL> s;       for (int i = 0; i < n; ++i) {         if (p[i] - i > 0) s.insert(p[i] - i);         sum += abs(p[i] - i);       }       minsum = sum;       ;       for (int i = 1; i < n; ++i) {         LL cnt;         if (p[n - i] - (n - 1) > 0)           cnt = (int)s.size() - 1;         else           cnt = (int)s.size();         sum += n - 1 - 2 * cnt;         ;         sum = sum - abs(p[n - i] - (n - 1)) + abs(p[n - i]);         s.erase(i);         if (p[n - i] > 0) s.insert(p[n - i] + i);         ;         ;         if (sum < minsum) {           minsum = sum;           ans = i;         }       }       cout << minsum <<     << ans <<   n ;     }   };   int main() {     cin.tie(0);     ios_base::sync_with_stdio(false);     long long n = 0;     cin >> n;     Problem p(n);     p.solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, t, tt, sz, res = 1e9, a[55][100005], out[100005], cnt[100005],                     mul[100005], que[1000005];   int read() {     int x = 0, fl = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) fl = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       x = (x << 1) + (x << 3) + ch -  0 ;       ch = getchar();     }     return x * fl;   }   int check(int p, int len) {     for (int i = 1; i <= len; i++)       if (a[p][i]) return 0;     return 1;   }   void dfs(int dep, int sum, int len) {     if (sum > res || dep > 51) return;     int now = check(dep, len);     if (now) {       res = sum;       for (int i = 1; i <= t; i++) que[i] = cnt[i];       sz = t;       return;     }     int fl = 1;     for (int i = 1; i <= len; i++)       if (a[dep][i] % 2) fl = 0;     if (fl) {       cnt[++t] = 3;       for (int i = 1; i <= len; i++) a[dep + 1][i] = a[dep][i] / 2;       int l0 = unique(a[dep + 1] + 1, a[dep + 1] + len + 1) - a[dep + 1] - 1;       dfs(dep + 1, sum, l0);       t--;     } else {       cnt[++t] = 1;       for (int i = 1; i <= len; i++)         a[dep + 1][i] = a[dep][i] + ((a[dep][i] & 1) > 0);       int l0 = unique(a[dep + 1] + 1, a[dep + 1] + len + 1) - a[dep + 1] - 1;       dfs(dep + 1, sum + 1, l0);       t--;       cnt[++t] = 2;       for (int i = 1; i <= len; i++)         a[dep + 1][i] = a[dep][i] - ((a[dep][i] & 1) > 0);       l0 = unique(a[dep + 1] + 1, a[dep + 1] + len + 1) - a[dep + 1] - 1;       dfs(dep + 1, sum + 1, l0);       t--;     }     return;   }   int main() {     n = read();     for (int i = 1; i <= n; i++) a[0][i] = read();     sort(a[0] + 1, a[0] + n + 1);     dfs(0, 0, n);     printf( %d n , res);     for (int i = 1; i <= sz; i++) mul[i] = mul[i - 1] + (que[i] == 3);     for (int i = 1; i <= sz; i++) {       if (que[i] == 1)         out[++tt] = -1 * pow(2, mul[i]);       else if (que[i] == 2)         out[++tt] = pow(2, mul[i]);     }     for (int i = 1; i <= tt; i++) printf( %d  , out[i]);     puts(  );     return 0;   }
#include <bits/stdc++.h>   typedef struct smirror {     int left, right, score;   } mirror;   int max(int a, int b) { return a > b ? a : b; }   int shoot_in(double x, mirror a[]) {     for (int i = 1; i <= a[0].score; ++i)       if (a[i].left <= x && x <= a[i].right) return i;     return -1;   }   int deal(int n, mirror A[], mirror B[], int hl, int hr) {     int counter = 1, hx = hl, tag, score0 = 0;     int h0;     if (n % 2 == 1)       h0 = hl + hr + (n - 1) * 100;     else       h0 = n * 100 + hl - hr;     bool ba[105], bb[105];     memset(ba, 0, sizeof(ba));     memset(bb, 0, sizeof(bb));     double d;     for (counter = 1; counter <= n; counter++) {       d = (hx * 100000) / (1.0 * h0);       if (counter % 2 == 1) {         tag = shoot_in(d, B);         if (tag >= 0 && !bb[tag]) {           score0 += B[tag].score;           bb[tag] = 1;         } else {           score0 = 0;           break;         }       } else {         tag = shoot_in(d, A);         if (tag >= 0 && !ba[tag]) {           score0 += A[tag].score;           ba[tag] = 1;         } else {           score0 = 0;           break;         }       }       hx += 100;     }     return score0;   }   int main() {     mirror mi[2][105];     int num[2] = {0, 0}, hl, hr, n;     scanf( %d%d%d , &hl, &hr, &n);     while (n--) {       int score, set = 1;       char t;       scanf( %d %c , &score, &t);       if (t ==  T ) set = 0;       ++num[set];       scanf( %d %d , &mi[set][num[set]].left, &mi[set][num[set]].right);       mi[set][num[set]].score = score;     }     mi[0][0].score = num[0], mi[1][0].score = num[1];     int ans = 0;     for (int i = 1; i <= num[0] + num[1]; ++i)       ans = max(ans, deal(i, mi[0], mi[1], hl, hr));     for (int i = 1; i <= num[0] + num[1]; ++i)       ans = max(ans, deal(i, mi[1], mi[0], 100 - hl, 100 - hr));     printf( %d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace ::std;   const int maxn = 1e5 + 5;   map<long long, int> mp;   long long sum[maxn], ans;   int n, k;   void solve() {     long long maxx = 0, minn = 0;     scanf( %d%d , &n, &k);     mp[0] = 1;     for (int i = 1; i <= n; i++) {       long long tmp;       scanf( %I64d , &tmp);       sum[i] = sum[i - 1] + tmp;       mp[sum[i]]++;       maxx = max(maxx, sum[i]);       minn = min(minn, sum[i]);       for (long long j = 1; - 1e15 <= j && j <= 1e15; j *= k) {         if (mp.find(sum[i] - j) != mp.end()) {           ans += mp[sum[i] - j];         }         if (k == 1) break;         if (j == -1 && k == -1) break;       }     }     printf( %I64d n , ans);   }   int main() {     solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   const int maxn = 2e5 + 9;   void test_case(int tc) {     int k;     cin >> k;     int n = 12;     int arr[12];     for (int i = 0; i <= 11; ++i) cin >> arr[i];     sort(arr, arr + 12, greater<int>());     int ans = 0;     int temp = 0;     if (k == 0) {       cout << k <<   n ;       return;     }     for (int i = 0; i <= n - 1; ++i) {       temp += arr[i];       ans++;       if (temp >= k) {         cout << ans;         return;       }     }     cout << -1;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);     int t = 1;     for (int tc = 1; tc <= t; ++tc) test_case(tc);   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200005;   int n, m;   long long ans, a[N], b[N];   char c;   long long read() {     long long x = 0;     int sig = 1;     for (c = getchar(); c <  0  || c >  9 ; c = getchar())       if (c ==  - ) sig = -1;     for (; c >=  0  && c <=  9 ; c = getchar()) x = x * 10 + c - 48;     return x * sig;   }   long long calc(int p) {     b[n] = min(a[n], (long long)m * p - (long long)p * (p - 1) / 2 * n);     for (int i = n - 1; i; i--) b[i] = min(a[i], b[i + 1] - p);     if (b[1] < p + (long long)p * (p - 1) / 2 * n) return 0;     long long sum = 0,               s = max(1ll, b[1] - (long long)(m + 1) * (p - 1) +                                (long long)p * (p - 1) / 2 * n),               Buy;     sum = Buy = b[1];     int Free = m - n * p - s + 1;     for (int i = 2; i <= n; i++) {       Buy += p;       int Shift = min(b[i] - Buy, (long long)Free);       Free -= Shift;       Buy += Shift;       sum += Buy;     }     return sum;   }   int main() {     n = read();     m = read();     for (int i = 1; i <= n; i++) a[i] = read();     ans = 0;     for (int i = 1; i * n <= m; i++) ans = max(ans, calc(i));     printf( %I64d n , ans);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   long long read() {     long long x = 0, f = 1;     char ch =    ;     while (!isdigit(ch)) {       ch = getchar();       if (ch ==  - ) f = -1;     }     while (isdigit(ch)) x = (x << 3) + (x << 1) + (ch - 48), ch = getchar();     return x * f;   }   const int mod = 998244353;   int t, n, a[100005];   vector<pair<long long, long long> > g[2];   int main() {     cin >> t;     while (t--) {       n = read();       long long ans = 0;       for (int i = 1; i <= n; i++) a[i] = read();       g[n % 2].clear();       g[n % 2].push_back({a[n], 1});       for (int i = n; i > 1; i--) {         int las = (i % 2), now = (las ^ 1);         g[now].clear();         int las1 = 0;         for (auto tmp : g[las]) {           ans += ((a[i - 1] - 1) / tmp.first) * (i - 1) % mod * tmp.second % mod;           int tmp1 = a[i - 1] / ((a[i - 1] - 1) / tmp.first + 1);           if (tmp1 == las1)             g[now][g[now].size() - 1].second += tmp.second % mod;           else             g[now].push_back({tmp1, tmp.second}), las1 = tmp1;         }         if (a[i - 1] == las1)           g[now][g[now].size() - 1].second++;         else           g[now].push_back({a[i - 1], 1ll});         g[las] = g[now];       }       cout << ans % mod << endl;     }   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, j, k, x, y, col;   vector<long long> ans;   long long last[100100];   int main() {     cin >> n;     for (i = 0; i < n; i++) {       cin >> x >> y;       col = 0;       j = 1;       while (j * j <= x) {         if (x % j == 0) {           k = x / j;           if (last[j] < i - y + 1) {             last[j] = i + 1;             col++;           }           last[j] = i + 1;           if (k != j && last[k] < i - y + 1) {             col++;           }           last[k] = i + 1;         }         j++;       }       ans.push_back(col);     }     for (i = 0; i < n; i++) cout << ans[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(void) {     int n, i, j = -100, k, *a, cnt = 0, cnt1 = 0;     cin >> n;     a = new int[n];     for (i = 0; i < n; i++) {       cin >> a[i];     }     for (i = 0; i < n - 2; i++) {       if (a[i] == 1 && a[i + 1] == 0 && a[i + 2] == 1) {         if (i - j > 2) {           cnt++;           j = i;           cnt1 = 0;         } else {           cnt1++;         }       }     }     cout << cnt;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int i, j;     char map[9][9];     bool ok = false, ok1 = false;     for (i = 0; i < 8; ++i) {       scanf( %s , map[i]);       for (j = 1; j < 8; ++j) {         if (i == 0 && map[i][j] ==  W ) ok1 = true;         if (map[i][j] == map[i][j - 1]) ok = true;       }       if (i == 0 && map[i][0] ==  W ) ok1 = true;       if (map[i][0] == map[i][7]) ok = true;     }     if (!ok1 || ok)       puts( NO );     else       puts( YES );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 200007, inf = 0x3f3f3f3f;   vector<int> edges[N];   int d[N];   void bfs(int s) {     queue<int> q;     q.push(s);     memset(d, -1, sizeof d);     d[s] = 0;     while (q.size()) {       int u = q.front();       q.pop();       for (int v : edges[u]) {         if (d[v] == -1) {           q.push(v);           d[v] = d[u] + 1;         }       }     }   }   void no() {     cout <<  No  << endl;     exit(0);   }   int main() {     ios::sync_with_stdio(false);     srand(time(NULL));     int n;     cin >> n;     if (n == 1) {       cout <<  Yes  << endl;       return 0;     }     for (int i = 0; i < n - 1; ++i) {       int u, v;       cin >> u >> v;       edges[u].push_back(v);       edges[v].push_back(u);     }     vector<int> vec;     int a;     for (int i = 0; i < n; ++i) {       cin >> a;       vec.push_back(a);     }     memset(d, -1, sizeof d);     int t = 0;     d[1] = 0;     if (vec[0] != 1) no();     for (int i = 0; i < n; ++i) {       if (d[vec[i]] == -1) no();       ++t;       for (int v : edges[vec[i]]) {         if (d[v] == -1) d[v] = t;       }     }     for (int i = 1; i < n; ++i) {       if (d[vec[i]] < d[vec[i - 1]]) no();     }     cout <<  Yes  << endl;   }
#include <bits/stdc++.h>   using namespace std;   long long n, i, j, a, b, c, t, cnt;   int main() {     cin >> a >> b >> c;     n = 0;     t = 0;     cnt = 0;     while ((a > 0) || (b > 0) || (c > 0)) {       switch (t) {         case 0: {           if (a > 0) a -= 2;           break;         }         case 1: {           if (b > 0) b -= 2;           break;         }         case 2: {           if (c > 0) c -= 2;           break;         }       }       cnt++;       n++;       t++;       t %= 3;     }     n--;     n += 30;     cout << n << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   vector<bool> prime(1001, true);   void sieve() {     prime[0] = false;     prime[1] = false;     for (int i = 2; i <= 1000; i++) {       if (prime[i]) {         int j = 2;         while (i * j <= 1000) {           prime[i * j] = false;           j++;         }       }     }   }   long long int ceil_sqrt(long long int a) {     long long int i = 1;     while (i * i < a) i++;     return i;   }   void solve() {     int n;     cin >> n;     int a[n];     for (int i = 0; i < n; i++) cin >> a[i];     for (int i = 0; i < n; i += 2) cout << a[i + 1] <<     << -1 * a[i] <<    ;     cout << endl;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cout.tie(0);     int t;     cin >> t;     while (t--) solve();     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int n, arr[300000];   double cord[3], best[3];   int main() {     cin >> n;     for (int i = 0; i < n; i++) scanf( %d , &arr[i]);     sort(arr, arr + n);     int l = 0, r = 2000000000, res = -1;     while (l <= r) {       int mid = (l + r) / 2;       int idx = 0;       for (int i = 0; i < 3; i++) {         cord[i] = (double)arr[idx] + (double)mid / 2.;         while (idx < n && abs(arr[idx] - cord[i]) - 1e-7 < (double)mid / 2.)           idx++;       }       if (idx == n) {         for (int i = 0; i < 3; i++) best[i] = cord[i];         res = mid, r = mid - 1;       } else         l = mid + 1;     }     printf( %.6lf n , (double)res / 2.);     printf( %.6lf  , (double)best[0]);     for (int i = 1; i < 3; i++) printf( % .6lf , (double)best[i]);     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int n;     cin >> n;     int x[n], y[n], h[n], a[n];     for (int i = 0; i < n; i++) {       cin >> x[i] >> y[i];     }     for (int i = 0; i < n; i++) {       h[i] = n - 1;       a[i] = 0;     }     int home[1000000] = {0}, away[1000000] = {0};     for (int i = 0; i < n; i++) {       home[x[i]]++;       away[y[i]]++;     }     for (int i = 0; i < n; i++) {       if (home[y[i]] > 0) h[i] += home[y[i]];     }     for (int i = 0; i < n; i++) {       a[i] = 2 * (n - 1) - h[i];     }     for (int i = 0; i < n; i++) cout << h[i] <<     << a[i] << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int MAXN = 100005;   long long a[MAXN], b[MAXN];   long long n, s;   bool check(long long k) {     for (int i = 1; i <= n; i++) b[i] = 0;     long long sum = s - 1, p = 2, q = 1, h = 1;     a[1] = b[1] = 1;     while (p <= n) {       q *= k, h++;       for (int i = 1; i <= q && p <= n; i++, p++) a[p] = h, sum -= h, b[h]++;     }     if (sum < 0) return 0;     p = n;     while (sum > 0) {       h++;       if (b[a[p]] == 1) --p;       long long t = min(sum, h - a[p]);       sum -= t, b[a[p]]--, a[p] += t, p--;     }     return 1;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(0);     cin >> n >> s;     if (s < 2 * n - 1 || s > n * (n + 1) / 2) {       cout <<  No  << endl;       exit(0);     }     int l = 1, r = n - 1;     while (l < r) {       int m = (l + r) >> 1;       if (check(m))         r = m;       else         l = m + 1;     }     check(l);     sort(a + 1, a + n + 1);     cout <<  Yes  << endl;     for (int p = 1, i = 2, cnt = 0; i <= n; i++) {       while (a[p] < a[i] - 1) p++, cnt = 0;       cout << p <<    ;       ++cnt;       if (cnt == l) cnt = 0, ++p;     }     cout << endl;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1505;   const int MOD = 1000000007;   inline int add(int x, int y) { return x + y >= MOD ? x + y - MOD : x + y; }   inline int sub(int x, int y) { return x - y < 0 ? x - y + MOD : x - y; }   inline int mul(int x, int y) { return 1ll * x * y % MOD; }   inline void inc(int &x, int y) { x = add(x, y); }   inline void dec(int &x, int y) { x = sub(x, y); }   inline void grow(int &x, int y) { x = mul(x, y); }   int bpow(int a, int b) {     int res = 1;     while (b) {       if (b & 1) grow(res, a);       grow(a, a);       b >>= 1;     }     return res;   }   int inv(int x) { return bpow(x, MOD - 2); }   int n, m, p, k;   int f[N], dp[N][N], sdp[N][N], sf[N], sfdp[N], fact[100005];   int comb(int a, int b) {     return mul(fact[a], mul(inv(fact[b]), inv(fact[a - b])));   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(0);     cin >> n >> m;     int _a, _b;     cin >> _a >> _b;     p = mul(_a, inv(_b));     cin >> k;     fact[0] = 1;     for (int i = 1; i <= k; i++) fact[i] = mul(fact[i - 1], i);     for (int i = 0; i <= min(k, m); i++)       f[i] = mul(comb(k, i), mul(bpow(p, i), bpow(sub(1, p), k - i)));     sf[0] = f[0];     for (int i = 1; i <= m; i++) sf[i] = add(sf[i - 1], f[i]);     dp[0][m] = sdp[0][m] = 1;     for (int i = 1; i <= n; i++) {       memset(sfdp, 0, sizeof sfdp);       for (int r = 1; r <= m; r++)         sfdp[r] = add(sfdp[r - 1], mul(f[r], sdp[i - 1][r]));       for (int r = 1; r <= m; r++)         dp[i][r] = mul(f[m - r],                        sub(mul(sf[r - 1], sub(sdp[i - 1][m], sdp[i - 1][m - r])),                            sfdp[r - 1]));       for (int r = 1; r <= m; r++) sdp[i][r] = add(sdp[i][r - 1], dp[i][r]);     }     cout << sdp[n][m] << endl;   }