QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#190010#4922. 生活在对角线下hos_lyric#100 ✓392ms29460kbC++1421.4kb2023-09-28 06:40:332024-07-04 02:47:52

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:47:52]
  • 评测
  • 测评结果:100
  • 用时:392ms
  • 内存:29460kb
  • [2023-09-28 06:40:33]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
constexpr unsigned MO = 998244353U;
constexpr unsigned MO2 = 2U * MO;
constexpr int FFT_MAX = 23;
using Mint = ModInt<MO>;
constexpr Mint FFT_ROOTS[FFT_MAX + 1] = {1U, 998244352U, 911660635U, 372528824U, 929031873U, 452798380U, 922799308U, 781712469U, 476477967U, 166035806U, 258648936U, 584193783U, 63912897U, 350007156U, 666702199U, 968855178U, 629671588U, 24514907U, 996173970U, 363395222U, 565042129U, 733596141U, 267099868U, 15311432U};
constexpr Mint INV_FFT_ROOTS[FFT_MAX + 1] = {1U, 998244352U, 86583718U, 509520358U, 337190230U, 87557064U, 609441965U, 135236158U, 304459705U, 685443576U, 381598368U, 335559352U, 129292727U, 358024708U, 814576206U, 708402881U, 283043518U, 3707709U, 121392023U, 704923114U, 950391366U, 428961804U, 382752275U, 469870224U};
constexpr Mint FFT_RATIOS[FFT_MAX] = {911660635U, 509520358U, 369330050U, 332049552U, 983190778U, 123842337U, 238493703U, 975955924U, 603855026U, 856644456U, 131300601U, 842657263U, 730768835U, 942482514U, 806263778U, 151565301U, 510815449U, 503497456U, 743006876U, 741047443U, 56250497U, 867605899U};
constexpr Mint INV_FFT_RATIOS[FFT_MAX] = {86583718U, 372528824U, 373294451U, 645684063U, 112220581U, 692852209U, 155456985U, 797128860U, 90816748U, 860285882U, 927414960U, 354738543U, 109331171U, 293255632U, 535113200U, 308540755U, 121186627U, 608385704U, 438932459U, 359477183U, 824071951U, 103369235U};

// as[rev(i)] <- \sum_j \zeta^(ij) as[j]
void fft(Mint *as, int n) {
  assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << FFT_MAX);
  int m = n;
  if (m >>= 1) {
    for (int i = 0; i < m; ++i) {
      const unsigned x = as[i + m].x;  // < MO
      as[i + m].x = as[i].x + MO - x;  // < 2 MO
      as[i].x += x;  // < 2 MO
    }
  }
  if (m >>= 1) {
    Mint prod = 1U;
    for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
      for (int i = i0; i < i0 + m; ++i) {
        const unsigned x = (prod * as[i + m]).x;  // < MO
        as[i + m].x = as[i].x + MO - x;  // < 3 MO
        as[i].x += x;  // < 3 MO
      }
      prod *= FFT_RATIOS[__builtin_ctz(++h)];
    }
  }
  for (; m; ) {
    if (m >>= 1) {
      Mint prod = 1U;
      for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
        for (int i = i0; i < i0 + m; ++i) {
          const unsigned x = (prod * as[i + m]).x;  // < MO
          as[i + m].x = as[i].x + MO - x;  // < 4 MO
          as[i].x += x;  // < 4 MO
        }
        prod *= FFT_RATIOS[__builtin_ctz(++h)];
      }
    }
    if (m >>= 1) {
      Mint prod = 1U;
      for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
        for (int i = i0; i < i0 + m; ++i) {
          const unsigned x = (prod * as[i + m]).x;  // < MO
          as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x;  // < 2 MO
          as[i + m].x = as[i].x + MO - x;  // < 3 MO
          as[i].x += x;  // < 3 MO
        }
        prod *= FFT_RATIOS[__builtin_ctz(++h)];
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x;  // < 2 MO
    as[i].x = (as[i].x >= MO) ? (as[i].x - MO) : as[i].x;  // < MO
  }
}

// as[i] <- (1/n) \sum_j \zeta^(-ij) as[rev(j)]
void invFft(Mint *as, int n) {
  assert(!(n & (n - 1))); assert(1 <= n); assert(n <= 1 << FFT_MAX);
  int m = 1;
  if (m < n >> 1) {
    Mint prod = 1U;
    for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
      for (int i = i0; i < i0 + m; ++i) {
        const unsigned long long y = as[i].x + MO - as[i + m].x;  // < 2 MO
        as[i].x += as[i + m].x;  // < 2 MO
        as[i + m].x = (prod.x * y) % MO;  // < MO
      }
      prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
    }
    m <<= 1;
  }
  for (; m < n >> 1; m <<= 1) {
    Mint prod = 1U;
    for (int h = 0, i0 = 0; i0 < n; i0 += (m << 1)) {
      for (int i = i0; i < i0 + (m >> 1); ++i) {
        const unsigned long long y = as[i].x + MO2 - as[i + m].x;  // < 4 MO
        as[i].x += as[i + m].x;  // < 4 MO
        as[i].x = (as[i].x >= MO2) ? (as[i].x - MO2) : as[i].x;  // < 2 MO
        as[i + m].x = (prod.x * y) % MO;  // < MO
      }
      for (int i = i0 + (m >> 1); i < i0 + m; ++i) {
        const unsigned long long y = as[i].x + MO - as[i + m].x;  // < 2 MO
        as[i].x += as[i + m].x;  // < 2 MO
        as[i + m].x = (prod.x * y) % MO;  // < MO
      }
      prod *= INV_FFT_RATIOS[__builtin_ctz(++h)];
    }
  }
  if (m < n) {
    for (int i = 0; i < m; ++i) {
      const unsigned y = as[i].x + MO2 - as[i + m].x;  // < 4 MO
      as[i].x += as[i + m].x;  // < 4 MO
      as[i + m].x = y;  // < 4 MO
    }
  }
  const Mint invN = Mint(n).inv();
  for (int i = 0; i < n; ++i) {
    as[i] *= invN;
  }
}

void fft(vector<Mint> &as) {
  fft(as.data(), as.size());
}
void invFft(vector<Mint> &as) {
  invFft(as.data(), as.size());
}

vector<Mint> convolve(vector<Mint> as, vector<Mint> bs) {
  if (as.empty() || bs.empty()) return {};
  const int len = as.size() + bs.size() - 1;
  int n = 1;
  for (; n < len; n <<= 1) {}
  as.resize(n); fft(as);
  bs.resize(n); fft(bs);
  for (int i = 0; i < n; ++i) as[i] *= bs[i];
  invFft(as);
  as.resize(len);
  return as;
}
vector<Mint> square(vector<Mint> as) {
  if (as.empty()) return {};
  const int len = as.size() + as.size() - 1;
  int n = 1;
  for (; n < len; n <<= 1) {}
  as.resize(n); fft(as);
  for (int i = 0; i < n; ++i) as[i] *= as[i];
  invFft(as);
  as.resize(len);
  return as;
}
////////////////////////////////////////////////////////////////////////////////


// 0 = \sum_{j=0}^d (\sum_{k=0}^e css[j][k] i^k) as[i - j]  (d <= i < |as|)
template <unsigned M>
vector<vector<ModInt<M>>> findPRecurrence(const vector<ModInt<M>> &as, int e,
                                          bool verbose = false) {
  using Mint = ModInt<M>;
  const int asLen = as.size();
  // asLen - d >= (d + 1) (e + 1) - 1  (otherwise definitely  dim Ker >= 2)
  const int d0 = (asLen + 2) / (e + 2) - 1;
  if (d0 < 0) {
    if (verbose) {
      fprintf(stderr, "[findPRecurrence] |as| >= e  must hold.\n");
      fflush(stderr);
    }
    return {};
  }
  const int m = asLen - d0, n = (d0 + 1) * (e + 1);
  vector<vector<Mint>> bss(m, vector<Mint>(n, 0));
  for (int i = d0; i < asLen; ++i) for (int j = 0; j <= d0; ++j) {
    Mint pw = 1;
    for (int k = 0; k <= e; ++k) {
      bss[i - d0][j * (e + 1) + k] = pw * as[i - j];
      pw *= i;
    }
  }
  int r = 0;
  vector<int> hs;
  for (int h = 0; h < n; ++h) {
    for (int i = r; i < m; ++i) if (bss[i][h]) {
      bss[r].swap(bss[i]);
      break;
    }
    if (r < m && bss[r][h]) {
      const Mint s = bss[r][h].inv();
      for (int j = h; j < n; ++j) bss[r][j] *= s;
      for (int i = 0; i < m; ++i) if (i != r) {
        const Mint t = bss[i][h];
        for (int j = h; j < n; ++j) bss[i][j] -= t * bss[r][j];
      }
      ++r;
    } else {
      hs.push_back(h);
    }
  }
  if (hs.empty()) {
    if (verbose) {
      fprintf(stderr, "[findPRecurrence] Not found: d = %d, e = %d.\n", d0, e);
      fflush(stderr);
    }
    return {};
  }
  vector<vector<Mint>> css(d0 + 1, vector<Mint>(e + 1, 0));
  for (int j = 0; j <= d0; ++j) for (int k = 0; k <= e; ++k) {
    const int h = j * (e + 1) + k;
    css[j][k] = (h < hs[0]) ? -bss[h][hs[0]] : (h == hs[0]) ? 1 : 0;
  }
  int d = hs[0] / (e + 1);
  for (int i = d0; i < asLen; ++i) {
    Mint sum = 0;
    for (int j = 0; j <= d0; ++j) {
      Mint coef = 0, pw = 1;
      for (int k = 0; k <= e; ++k) {
        coef += css[j][k] * pw;
        pw *= i;
      }
      sum += coef * as[i - j];
    }
    for (; sum; ) {
      if (i - ++d < 0) break;
      assert(d <= d0);
      Mint coef = 0, pw = 1;
      for (int k = 0; k <= e; ++k) {
        coef += css[d][k] * pw;
        pw *= i;
      }
      sum += coef * as[i - d];
    }
  }
  css.resize(d + 1);
  if (verbose) {
    const int hsLen = hs.size();
    if (hsLen > d0 - d + 1) {
      fprintf(stderr, "[findPRecurrence] Degenerate? (dim Ker = %d)\n", hsLen);
    }
    fprintf(stderr, "[findPRecurrence] d = %d, e = %d, non-trivial: %d\n", d, e,
            asLen - d - (d + 1) * (e + 1) + 1);
    fprintf(stderr, "{\n");
    for (int j = 0; j <= d; ++j) {
      fprintf(stderr, "  {");
      for (int k = 0; k <= e; ++k) {
        const unsigned c = css[j][k].x;
        if (k > 0) fprintf(stderr, ", ");
        fprintf(stderr, "%d", static_cast<int>((c < M - c) ? c : (c - M)));
      }
      fprintf(stderr, "},\n");
    }
    fprintf(stderr, "}\n");
    fflush(stderr);
  }
  return css;
}

// 0 = \sum_{j=0}^d (\sum_{k=0}^e css[j][k] i^k) as[i - j]  (d <= i < |as|)
template <unsigned M>
vector<ModInt<M>> extendPRecurrence(vector<ModInt<M>> as,
                                    const vector<vector<ModInt<M>>> &css,
                                    int n) {
  using Mint = ModInt<M>;
  assert(!css.empty());
  const int d = css.size() - 1, e = css[0].size() - 1;
  for (int j = 0; j <= d; ++j) assert(static_cast<int>(css[j].size()) == e + 1);
  const int asLen = as.size();
  as.resize(n);
  for (int i = asLen; i < n; ++i) {
    Mint sum = 0;
    for (int j = 1; j <= d; ++j) {
      Mint coef = 0, pw = 1;
      for (int k = 0; k <= e; ++k) {
        coef += css[j][k] * pw;
        pw *= i;
      }
      sum += coef * as[i - j];
    }
    {
      Mint coef = 0, pw = 1;
      for (int k = 0; k <= e; ++k) {
        coef += css[0][k] * pw;
        pw *= i;
      }
      as[i] = -sum / coef;
    }
  }
  return as;
}

////////////////////////////////////////////////////////////////////////////////


constexpr int LIM_INV = 400'010;
Mint inv[LIM_INV], fac[LIM_INV], invFac[LIM_INV];

void prepare() {
  inv[1] = 1;
  for (int i = 2; i < LIM_INV; ++i) {
    inv[i] = -((Mint::M / i) * inv[Mint::M % i]);
  }
  fac[0] = invFac[0] = 1;
  for (int i = 1; i < LIM_INV; ++i) {
    fac[i] = fac[i - 1] * i;
    invFac[i] = invFac[i - 1] * inv[i];
  }
}
Mint binom(Int n, Int k) {
  if (n < 0) {
    if (k >= 0) {
      return ((k & 1) ? -1 : +1) * binom(-n + k - 1, k);
    } else if (n - k >= 0) {
      return (((n - k) & 1) ? -1 : +1) * binom(-k - 1, n - k);
    } else {
      return 0;
    }
  } else {
    if (0 <= k && k <= n) {
      assert(n < LIM_INV);
      return fac[n] * invFac[k] * invFac[n - k];
    } else {
      return 0;
    }
  }
}


Mint path(int dx, int dy) {
  return (dx >= 0 && dy >= 0) ? (fac[dx + dy] * invFac[dx] * invFac[dy]) : 0;
}

constexpr int MAX_T = 100'010;
constexpr int MAX_PQ = 10;

Mint S2[MAX_PQ][MAX_PQ];

int T, C, P, Q, L;
int N[MAX_T], M[MAX_T];
Mint F[MAX_T][MAX_PQ];


namespace expr {
Mint dp[110][110][210];
void belowDiag(int lim) {
  memset(dp, 0, sizeof(dp));
  dp[0][0][0] = 1;
  for (int x = 0; x <= lim; ++x) for (int y = 0; y <= lim; ++y) {
    if (y <= x) {
      for (int k = x + y + 1; k >= 1; --k) dp[x][y][k] = dp[x][y][k - 1];
      dp[x][y][0] = 0;
    }
    for (int k = 0; k <= x + y + 1; ++k) dp[x + 1][y][k] += dp[x][y][k];
    for (int k = 0; k <= x + y + 1; ++k) dp[x][y + 1][k] += dp[x][y][k];
  }
  for (int x = 0; x <= lim; ++x) {
    Mint g = 0, h = 0;
    for (int k = 0; k <= x + x + 1; ++k) {
      g += dp[x][x][k] * k;
      h += dp[x][x][k] * (x + x + 1 - k);
    }
    cerr << x << ": " << g + h << " " << g << " " << h << "; "; pv(dp[x][x], dp[x][x] + (x + x + 1 + 1));
  }
}
void all(int lim) {
  for (int p = 0; p < 4; ++p) for (int q = 0; q < 4; ++q) {
    vector<vector<Mint>> tab(lim + 1, vector<Mint>(lim + 1, 0));
    for (int n = 0; n <= lim; ++n) for (int m = 0; m <= lim; ++m) {
      for (int x = 0; x <= n; ++x) for (int y = 0; y <= m; ++y) {
        tab[n][m] += path(x, y) * path(n - x, m - y) * binom(x, p) * binom(y, q);
      }
    }
    cerr << "binom(x, " << p << ") binom(y, " << q << ")" << endl;
    for (int n = 0; n <= lim; ++n) {
      cerr << n << ": " << tab[n] << endl;
    }
    for (int n = 0; n <= lim; ++n) for (int m = 0; m <= lim; ++m) {
      const Mint val = path(p, q) * binom(n + m + 1, p + q + 1) * path(n - p, m - q);
      assert(tab[n][m] == val);
    }
  }
}
}  // expr


namespace brute {
constexpr int SMALL = 1010;
Mint dp[MAX_PQ][SMALL][SMALL][2];
vector<Mint> run() {
  memset(dp, 0, sizeof(dp));
  for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
    const int id = p * Q + q;
    dp[id][0][0][0] = 1;
    for (int x = 0; x <= L; ++x) for (int y = 0; y <= L + C; ++y) {
      if (y <= x) {
        dp[id][x][y][1] += dp[id][x][y][0] * Mint(x).pow(p) * Mint(y).pow(q);
      }
      dp[id][x + 1][y][0] += dp[id][x][y][0];
      dp[id][x + 1][y][1] += dp[id][x][y][1];
      dp[id][x][y + 1][0] += dp[id][x][y][0];
      dp[id][x][y + 1][1] += dp[id][x][y][1];
    }
// cerr<<"p = "<<p<<", q = "<<q<<endl;
// for(int x=0;x<=L;++x){for(int y=0;y<=L+C;++y)cerr<<dp[id][x][y][0]<<","<<dp[id][x][y][1]<<" ";cerr<<endl;}
  }
  vector<Mint> ans(T, 0);
  for (int t = 0; t < T; ++t) {
    for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
      const int id = p * Q + q;
      ans[t] += F[t][id] * dp[id][N[t]][M[t]][1];
    }
  }
  return ans;
}
}  // brute


namespace sub4 {
vector<Mint> run() {
  vector<Mint> gs(L + 1, 0), hs(L + 1, 0);
  for (int n = 0; n <= L; ++n) {
    gs[n] = ((2 * n + 1) * path(n, n) + Mint(4).pow(n)) / 2;
    hs[n] = path(n, n) * (2 * n + 1) - gs[n];
  }
// cerr<<"gs = "<<gs<<endl;
// cerr<<"hs = "<<hs<<endl;
  vector<Mint> ggs, hhs;
  if (C >= 0) {
    vector<Mint> ps(L + 1, 0);
    for (int n = 1; n <= L; ++n) {
      ps[n] = path(n, n + C - 1) - path(n + C, n - 1);
    }
    ps[0] = 1;
    ggs = convolve(gs, ps);
    ggs.resize(L + 1);
// cerr<<"ps = "<<ps<<", ggs = "<<ggs<<endl;
  } else {
    vector<Mint> ps(L + 1, 0);
    for (int m = 1; m <= L; ++m) {
      ps[m] = path(m - C - 1, m) - path(m - 1, m - C);
    }
    ps[0] = 1;
    hhs = convolve(hs, ps);
    hhs.resize(L + 1);
// cerr<<"ps = "<<ps<<", hhs = "<<hhs<<endl;
  }
  vector<Mint> ans(T, 0);
  for (int t = 0; t < T; ++t) {
    if (C >= 0) {
      /*
      Mint sum = 0;
      for (int x = 0; x < N[t]; ++x) {
        // (x, x) -> (x, x+1)
        sum += gs[x] * (path(N[t] - x, M[t] - (x+1)) - path(M[t] - x, N[t] - (x+1)));
      }
      sum += gs[N[t]];
      ans[t] += F[t][0] * sum;
      */
      ans[t] += F[t][0] * ggs[N[t]];
    } else {
      /*
      Mint sum = 0;
      for (int y = 0; y < M[t]; ++y) {
        // (y, y) -> (y+1, y)
        sum += hs[y] * (path(N[t] - (y+1), M[t] - y) - path(M[t] - (y+1), N[t] - y));
      }
      sum += hs[M[t]];
      ans[t] += F[t][0] * sum;
      */
      ans[t] += F[t][0] * (path(N[t], M[t]) * (N[t] + M[t] + 1) - hhs[M[t]]);
    }
  }
  return ans;
}
}  // sub4


namespace fast {
constexpr int SZ = 200;
Mint dp[SZ + 1][SZ + 1][2];
vector<Mint> gss[MAX_PQ];
vector<Mint> run() {
  for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
    memset(dp, 0, sizeof(dp));
    dp[0][0][0] = 1;
    for (int x = 0; x < SZ; ++x) for (int y = 0; y < SZ; ++y) {
      if ((C >= 0) == (y <= x)) {
        dp[x][y][1] += dp[x][y][0] * Mint(x).pow(p) * Mint(y).pow(q);
      }
      dp[x + 1][y][0] += dp[x][y][0];
      dp[x + 1][y][1] += dp[x][y][1];
      dp[x][y + 1][0] += dp[x][y][0];
      dp[x][y + 1][1] += dp[x][y][1];
    }
    vector<Mint> as(SZ);
    for (int x = 0; x < SZ; ++x) {
      as[x] = dp[x][x][1];
    }
    // cerr << "x^" << p << " y^" << q << endl;
    // findPRecurrence(as, 1, true);
    const auto css = findPRecurrence(as, 1, false);
    gss[p * Q + q] = extendPRecurrence(as, css, L + 1);
  }
  {
    vector<Mint> ps(L + 1, 0);
    if (C >= 0) {
      for (int n = 1; n <= L; ++n) {
        ps[n] = path(n, n + C - 1) - path(n + C, n - 1);
      }
      ps[0] = 1;
    } else {
      for (int m = 1; m <= L; ++m) {
        ps[m] = path(m - C - 1, m) - path(m - 1, m - C);
      }
      ps[0] = 1;
    }
    for (int id = 0; id < P * Q; ++id) {
      gss[id] = convolve(gss[id], ps);
      gss[id].resize(L + 1);
    }
  }
  vector<Mint> ans(T, 0);
  for (int t = 0; t < T; ++t) {
    if (C >= 0) {
      for (int id = 0; id < P * Q; ++id) {
        ans[t] += F[t][id] * gss[id][N[t]];
      }
    } else {
      // x^p y^q -> binom(x, p') binom(y, q')
      Mint f[MAX_PQ] = {};
      for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
        for (int pp = 0; pp <= p; ++pp) for (int qq = 0; qq <= q; ++qq) {
          f[pp * Q + qq] += fac[pp] * fac[qq] * S2[p][pp] * S2[q][qq] * F[t][p * Q + q];
        }
      }
      for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
        ans[t] += f[p * Q + q] * path(p, q) * binom(N[t] + M[t] + 1, p + q + 1) * path(N[t] - p, M[t] - q);
      }
      for (int id = 0; id < P * Q; ++id) {
        ans[t] -= F[t][id] * gss[id][M[t]];
      }
    }
  }
  return ans;
}
}  // fast


int main() {
  prepare();
  
  for (int n = 0; n < MAX_PQ; ++n) {
    S2[n][0] = 0;
    S2[n][n] = 1;
    for (int k = 1; k < n; ++k) {
      S2[n][k] = S2[n - 1][k - 1] + k * S2[n - 1][k];
    }
  }
  
  // expr::belowDiag(10);
  // expr::all(10);
  
  for (; ~scanf("%d%d%d%d%d", &T, &C, &P, &Q, &L); ) {
    ++P;
    ++Q;
    for (int t = 0; t < T; ++t) {
      scanf("%d%d", &N[t], &M[t]);
      assert(N[t] >= 0);
      assert(M[t] >= 0);
      assert(N[t] + C == M[t]);
      for (int p = 0; p < P; ++p) for (int q = 0; q < Q; ++q) {
        scanf("%u", &F[t][p * Q + q].x);
      }
    }
    
    const auto ans = fast::run();
    for (int t = 0; t < T; ++t) {
      printf("%u\n", ans[t].x);
    }
#ifdef LOCAL
const auto brt=brute::run();
for(int t=0;t<T;++t)if(brt[t]!=ans[t]){
 cerr<<N[t]<<" "<<M[t]<<"; ";pv(F[t],F[t]+P*Q);
 cerr<<"brt[t] = "<<brt[t]<<endl;
 cerr<<"ans[t] = "<<ans[t]<<endl;
 break;
}
assert(brt==ans);
#endif
  }
  return 0;
}

詳細信息

Subtask #1:

score: 1
Accepted

Test #1:

score: 1
Accepted
time: 9ms
memory: 12260kb

input:

1 -10 1 2 1000
825 815
107973512 400177523 812303207
164088430 603506669 337780072

output:

360076089

result:

ok 1 number(s): "360076089"

Test #2:

score: 0
Accepted
time: 20ms
memory: 12772kb

input:

1 424 1 4 576
130 554
926445673 393820912 634481616 292175028 733650737
100427548 899689095 876811717 849191704 696040532

output:

564712546

result:

ok 1 number(s): "564712546"

Test #3:

score: 0
Accepted
time: 9ms
memory: 15168kb

input:

1 -171 2 1 1000
805 634
250066876 719653007
284194184 531322789
491311782 185842441

output:

910556244

result:

ok 1 number(s): "910556244"

Test #4:

score: 0
Accepted
time: 20ms
memory: 12320kb

input:

1 11 4 1 989
142 153
581558550 138798754
575233123 788754497
582314564 303591688
635874631 658261955
615116681 498307457

output:

918405181

result:

ok 1 number(s): "918405181"

Test #5:

score: 0
Accepted
time: 10ms
memory: 15220kb

input:

1 -87 1 2 1000
164 77
264180617 338145439 610918500
800846696 216126209 112962819

output:

629819261

result:

ok 1 number(s): "629819261"

Subtask #2:

score: 9
Accepted

Dependency #1:

100%
Accepted

Test #6:

score: 9
Accepted
time: 87ms
memory: 14988kb

input:

100000 -99 2 1 1000
712 613
238230707 820405654
473765646 826816733
751513618 421153458
209 110
22075351 398854663
148159396 487281124
972932017 200517786
383 284
22252771 205525630
491328752 607545155
561318911 135661425
929 830
156478040 89922795
380802607 32081978
898588032 110586958
956 857
4206...

output:

863094157
570366074
281608243
247495628
396961441
855444791
694374848
782506902
280202079
688077364
610676536
115373962
360154110
834242083
887647721
164293717
759683961
710870451
213441970
863772654
514218158
532711794
558875294
421795761
517787006
458381459
506983637
742686106
435175768
111255264
...

result:

ok 100000 numbers

Test #7:

score: 0
Accepted
time: 90ms
memory: 17312kb

input:

100000 252 3 1 748
130 382
311369319 709099006
49474431 724072531
761415026 251406187
389170658 169808960
581 833
89779535 938252574
504798466 677842435
654289171 763708659
719082912 762770851
691 943
571693157 187035992
300995260 403041189
726726538 63983502
814000657 315732021
121 373
339102104 42...

output:

516270157
614211606
655396807
981733406
752565578
312973289
850750616
826813023
753739511
227580123
199177890
403714939
559334967
370464926
363937285
583678656
239132195
834163477
111915553
68813179
875627540
299872127
660063389
31474925
464946255
125818391
645016505
267670615
440441568
356463850
84...

result:

ok 100000 numbers

Test #8:

score: 0
Accepted
time: 95ms
memory: 15516kb

input:

100000 195 2 2 805
325 520
266481322 663615421 428019284
968378746 158386978 211891009
161987045 142931644 790431809
621 816
756898302 952132541 196745128
424307295 926376261 130425563
604844618 645296808 252920984
60 255
873310227 887037637 787608776
98214115 355810775 242821836
537250851 650821017...

output:

922269244
757786754
400099571
332972619
780501723
469958234
540206804
924583388
519189002
566620024
244468115
73221163
663221021
159111716
451144022
658783977
656844692
831466434
186871631
60740257
542611012
773315130
755261907
193772041
628947709
363111530
452621670
349808610
264947076
342250907
16...

result:

ok 100000 numbers

Subtask #3:

score: 20
Accepted

Test #9:

score: 20
Accepted
time: 25ms
memory: 17828kb

input:

1 4683 0 0 95317
86560 91243
412303217

output:

952052072

result:

ok 1 number(s): "952052072"

Test #10:

score: 0
Accepted
time: 28ms
memory: 15636kb

input:

1 -24796 0 0 100000
93338 68542
849332154

output:

980840409

result:

ok 1 number(s): "980840409"

Test #11:

score: 0
Accepted
time: 18ms
memory: 13700kb

input:

1 40156 0 0 59844
39551 79707
566086447

output:

620552907

result:

ok 1 number(s): "620552907"

Test #12:

score: 0
Accepted
time: 24ms
memory: 15252kb

input:

1 -714 0 0 100000
72672 71958
817542139

output:

799272798

result:

ok 1 number(s): "799272798"

Test #13:

score: 0
Accepted
time: 27ms
memory: 15892kb

input:

1 23418 0 0 76582
6862 30280
442920403

output:

642352133

result:

ok 1 number(s): "642352133"

Test #14:

score: 0
Accepted
time: 15ms
memory: 14812kb

input:

1 42983 0 0 57017
42753 85736
380012689

output:

828068267

result:

ok 1 number(s): "828068267"

Test #15:

score: 0
Accepted
time: 29ms
memory: 14856kb

input:

1 -25448 0 0 100000
47466 22018
617788426

output:

485886943

result:

ok 1 number(s): "485886943"

Test #16:

score: 0
Accepted
time: 25ms
memory: 17668kb

input:

1 -35138 0 0 100000
49912 14774
472000456

output:

323681794

result:

ok 1 number(s): "323681794"

Test #17:

score: 0
Accepted
time: 28ms
memory: 14696kb

input:

1 15928 0 0 84072
57657 73585
31014982

output:

184096139

result:

ok 1 number(s): "184096139"

Test #18:

score: 0
Accepted
time: 21ms
memory: 15516kb

input:

1 5316 0 0 94684
36186 41502
601085246

output:

51887433

result:

ok 1 number(s): "51887433"

Subtask #4:

score: 20
Accepted

Dependency #3:

100%
Accepted

Test #19:

score: 20
Accepted
time: 37ms
memory: 16080kb

input:

100000 43925 0 0 56075
36770 80695
880793638
55133 99058
946571985
27169 71094
601132030
42027 85952
954509221
1261 45186
326012305
12030 55955
997023025
9914 53839
788665071
39921 83846
193760311
25774 69699
584278712
28428 72353
45133606
32564 76489
40466335
35483 79408
491164633
1587 45512
842380...

output:

332757564
673855662
612475468
823636534
480158617
642667251
497333900
509207503
811150980
417148607
922658720
104640134
806209587
173065009
605751740
862381731
38248058
821044620
841331399
289617079
251770008
141909273
16627417
373489864
231237810
941325561
178798279
674579054
924181592
61271475
964...

result:

ok 100000 numbers

Test #20:

score: 0
Accepted
time: 48ms
memory: 18268kb

input:

100000 -24410 0 0 100000
88811 64401
883320435
98680 74270
679694811
25736 1326
585801443
58045 33635
248117495
75671 51261
370680099
54439 30029
971994977
59364 34954
824527105
83366 58956
743467199
86814 62404
560320056
79263 54853
982330282
31352 6942
755041686
56396 31986
625187969
95451 71041
6...

output:

944753157
183242929
363439527
347484131
162238407
874219996
466587038
69445583
299052607
25676433
596600163
562511304
969440848
734888105
717978251
646284734
285785033
177137639
757127623
981404389
646133036
419072122
570786562
49543639
324434058
643959988
425580060
576826099
385768604
231992533
414...

result:

ok 100000 numbers

Test #21:

score: 0
Accepted
time: 55ms
memory: 19712kb

input:

100000 -5861 0 0 100000
16952 11091
854232561
61287 55426
808396787
36941 31080
498670332
78084 72223
125065027
77939 72078
113005933
66811 60950
561023395
8690 2829
85984152
86780 80919
73284065
24701 18840
962634657
49186 43325
820164989
13544 7683
181059009
82733 76872
475302128
59169 53308
30753...

output:

953252694
312702564
226453117
67575786
903898714
513740725
876463803
777825703
146006471
2374918
297784488
386629852
320437877
988885626
718795318
32469771
761373569
413225682
535374528
890489090
946876926
547336815
741402601
164218598
624314043
440338456
358510966
78123388
844278570
353784116
33016...

result:

ok 100000 numbers

Test #22:

score: 0
Accepted
time: 37ms
memory: 15744kb

input:

100000 36351 0 0 63649
63623 99974
215842464
38932 75283
281762844
36628 72979
412528519
32243 68594
274539771
12583 48934
35262820
58794 95145
584821840
55654 92005
405023451
54594 90945
121054191
13799 50150
945750972
3396 39747
123637787
24436 60787
60557209
28533 64884
16469063
62629 98980
97582...

output:

174547901
368722952
48857280
38439764
222892265
312334973
776332784
870332855
155759525
948664848
557524993
498142735
312543625
96578298
812380665
262256294
625974911
11727861
934671647
410990281
662266734
602386252
129790362
105856770
514479617
606174145
351070683
902755038
185658666
319441312
6292...

result:

ok 100000 numbers

Test #23:

score: 0
Accepted
time: 53ms
memory: 17672kb

input:

100000 -30740 0 0 100000
68807 38067
675336699
46303 15563
123039099
67930 37190
232230088
54579 23839
35352609
92730 61990
284529851
67176 36436
665212494
57299 26559
133796107
49959 19219
33773652
84236 53496
372759887
99484 68744
426876149
34577 3837
572112278
61585 30845
172184077
77857 47117
90...

output:

36920501
226235095
750211143
333187562
373628984
295265220
37657937
466124753
990905489
551665113
446537030
431018050
86173594
169742883
218477019
236694053
535757873
691309698
571533347
44799594
978410954
207318736
924231440
714349634
256005837
765738237
355457430
213887617
753194413
829442039
4620...

result:

ok 100000 numbers

Test #24:

score: 0
Accepted
time: 51ms
memory: 18172kb

input:

100000 -38460 0 0 100000
51513 13053
225553548
46939 8479
742237301
76548 38088
403832837
58372 19912
532371282
69056 30596
227486715
57631 19171
992007340
43442 4982
456446541
98517 60057
139482341
93593 55133
617856070
94670 56210
632588368
61305 22845
540079128
42989 4529
243030634
61305 22845
60...

output:

264377260
988347451
122980170
868000378
424450627
937049667
82203152
65434176
511951571
866041634
172830523
592267120
339840284
510003002
301057898
661439490
614715916
352897087
347380257
99947743
217323734
533045349
197971764
276536330
181518107
810369320
38076519
795663640
628535813
745310656
9165...

result:

ok 100000 numbers

Test #25:

score: 0
Accepted
time: 48ms
memory: 19640kb

input:

100000 -21781 0 0 100000
98045 76264
260148888
51675 29894
775592370
96562 74781
6673060
61291 39510
561247689
51571 29790
374708153
56745 34964
902344534
38026 16245
499287321
46349 24568
80542300
44223 22442
235391104
44474 22693
180934225
73722 51941
571180203
98775 76994
186933783
37624 15843
66...

output:

403860096
918023019
505862766
325574001
758856670
454849577
390589711
142177895
563486806
252645563
120628328
553587845
992851487
933771813
401873497
993790093
184884214
294133840
346874311
513672329
312442149
595232497
772328343
814181956
380438506
927087216
253560503
970622427
910857175
430512071
...

result:

ok 100000 numbers

Subtask #5:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #3:

100%
Accepted

Test #26:

score: 20
Accepted
time: 212ms
memory: 22144kb

input:

1 -40679 1 3 100000
75191 34512
321693501 896183087 224533692 282076683
38691763 630172019 273852722 127891101

output:

198237763

result:

ok 1 number(s): "198237763"

Test #27:

score: 0
Accepted
time: 222ms
memory: 23936kb

input:

1 9664 2 2 90336
59042 68706
717663780 865518514 750039632
169626890 79109800 564485240
923181348 328257325 651332745

output:

828389140

result:

ok 1 number(s): "828389140"

Test #28:

score: 0
Accepted
time: 199ms
memory: 22996kb

input:

1 -4911 3 1 100000
95506 90595
160758317 884378184
967471539 538413947
340046 935215889
819083010 963236120

output:

158427640

result:

ok 1 number(s): "158427640"

Test #29:

score: 0
Accepted
time: 97ms
memory: 19032kb

input:

1 -38940 1 1 100000
89122 50182
506966463 371134907
64554268 110662481

output:

467436544

result:

ok 1 number(s): "467436544"

Test #30:

score: 0
Accepted
time: 157ms
memory: 21064kb

input:

1 38149 1 4 61851
56735 94884
619552926 550261250 164045481 845972436 653872372
83118942 170826528 44296576 620740108 779756438

output:

630384750

result:

ok 1 number(s): "630384750"

Test #31:

score: 0
Accepted
time: 224ms
memory: 24068kb

input:

1 32508 1 4 67492
13875 46383
892100417 119341289 88840851 667390755 718238291
932491650 571612544 199447761 746443436 655377775

output:

312746560

result:

ok 1 number(s): "312746560"

Test #32:

score: 0
Accepted
time: 236ms
memory: 27020kb

input:

1 17588 1 4 82412
20625 38213
604068892 481834833 499227629 228921456 166798064
682396844 196078975 611249263 782949550 681017843

output:

221586768

result:

ok 1 number(s): "221586768"

Test #33:

score: 0
Accepted
time: 197ms
memory: 23168kb

input:

1 29346 2 2 70654
23916 53262
559895810 85578539 527902788
213523265 498308006 369409104
182816498 97996179 302398399

output:

797586870

result:

ok 1 number(s): "797586870"

Test #34:

score: 0
Accepted
time: 139ms
memory: 19812kb

input:

1 16678 1 2 83322
37554 54232
982410397 959727597 885392514
32666406 55592928 308044539

output:

944958454

result:

ok 1 number(s): "944958454"

Test #35:

score: 0
Accepted
time: 260ms
memory: 25168kb

input:

1 -2973 4 1 100000
70671 67698
944119814 134201307
205772284 308145616
960255142 417904059
70545226 873525649
971531131 564183606

output:

886221045

result:

ok 1 number(s): "886221045"

Test #36:

score: 0
Accepted
time: 239ms
memory: 24848kb

input:

1 -15018 2 2 100000
70554 55536
617923951 429701274 222750395
260363494 223870584 211569086
968515859 797859940 788983097

output:

444934086

result:

ok 1 number(s): "444934086"

Test #37:

score: 0
Accepted
time: 201ms
memory: 22548kb

input:

1 1779 1 3 98221
15045 16824
639812780 322958416 989224166 985184904
189238062 18251715 874601450 598892837

output:

917232252

result:

ok 1 number(s): "917232252"

Test #38:

score: 0
Accepted
time: 207ms
memory: 23032kb

input:

1 -12131 3 1 100000
28660 16529
789001202 692765454
147387760 382308809
425360331 287102216
374854545 42527051

output:

320231596

result:

ok 1 number(s): "320231596"

Test #39:

score: 0
Accepted
time: 180ms
memory: 22256kb

input:

1 24291 3 1 75709
9425 33716
9848163 654684310
967986364 108885198
824132881 105594392
29421429 537706322

output:

489020938

result:

ok 1 number(s): "489020938"

Test #40:

score: 0
Accepted
time: 207ms
memory: 25208kb

input:

1 -16067 1 3 100000
77427 61360
179822901 517194 808059226 643416162
441055045 613299853 353364121 929654400

output:

526064056

result:

ok 1 number(s): "526064056"

Subtask #6:

score: 10
Accepted

Test #41:

score: 10
Accepted
time: 195ms
memory: 23012kb

input:

100000 0 2 1 100000
48964 48964
666670967 90494987
74847122 615108201
29533064 582540229
14418 14418
391779909 223696706
701170191 885097597
551643398 25626747
81584 81584
951326734 520293397
13860946 896899117
821166399 282263457
76849 76849
598606953 879771697
930252135 671750715
673503431 3060699...

output:

513261452
727599133
935022075
486566245
581605882
190874624
492903919
212718785
390117408
13902475
85548183
635628561
482394025
962073695
362740677
938001783
889953951
725536236
308635636
699865601
901798869
464425652
743201170
92575030
846809630
169046922
528318328
181301191
961103497
451810607
792...

result:

ok 100000 numbers

Test #42:

score: 0
Accepted
time: 351ms
memory: 26204kb

input:

100000 0 4 1 100000
62874 62874
118183474 407193132
685767410 687439227
635193908 610100986
258734574 238431118
899478481 761001837
51740 51740
444395131 500444257
428937362 53260346
30808281 906820217
513141079 288839678
554203046 663643475
35914 35914
356034890 347998675
273353479 349503145
372514...

output:

90079244
739339489
893419903
384951658
501534088
627460520
515642072
133867011
245310344
38632363
463152272
875958325
685091735
564873808
923675127
506219676
835026926
594979789
343226945
318102253
564901512
435775641
520245858
654449246
974902905
301999370
874735377
124394474
531442263
667337270
83...

result:

ok 100000 numbers

Test #43:

score: 0
Accepted
time: 140ms
memory: 23204kb

input:

100000 0 1 1 100000
83076 83076
784524998 238343754
699444053 193415149
11931 11931
355735062 430827321
287184363 194146905
91685 91685
248401162 668812139
449763793 590716247
78873 78873
971383652 14982086
221574168 121402275
26705 26705
364632629 623913927
214647623 17014014
49871 49871
263152609 ...

output:

802238644
451994968
843226074
709558669
347484361
274977121
318242262
3003995
257310491
883438002
280843999
528814010
271908664
945085650
492738471
977479030
525082715
842693153
252354040
298201390
872453061
208575147
937984577
678583627
733514865
41580096
401571067
274115222
395399652
179231522
937...

result:

ok 100000 numbers

Test #44:

score: 0
Accepted
time: 310ms
memory: 25348kb

input:

100000 0 2 2 100000
42300 42300
306457952 603264155 604535680
373299692 720452989 584402391
244134586 764918594 149155452
96154 96154
385928288 721874710 32823875
997921405 288963987 798618815
52914070 480392455 835325898
22519 22519
857743113 78508560 335894675
636079175 257465089 226652298
5563045...

output:

141992402
675599235
48013284
700276770
870607175
695357162
754603770
744644560
328387578
779395955
691351991
749020285
219297277
416658156
801975761
287252871
95156690
502693643
859436736
751262539
372636784
789118941
114563659
346856771
895806035
984183707
868346378
178435731
197918806
73584128
672...

result:

ok 100000 numbers

Test #45:

score: 0
Accepted
time: 275ms
memory: 24740kb

input:

100000 0 1 3 100000
11362 11362
801230778 277039031 516703939 337243321
332454631 792471639 975430381 110954619
40296 40296
81718908 611718437 88044277 605359397
166308037 639878719 541084927 996814184
90922 90922
259539282 44240476 746297299 224814811
377419670 846027497 887046473 935009556
83954 8...

output:

509415585
345953605
300915155
337129523
37705935
985749046
509167332
298084321
186170721
665255439
256338589
647056594
894014776
673493231
550884946
531517917
311691611
150189476
800606928
934725818
764831103
696313960
418481305
470916807
876494136
473764716
597224168
111651899
43420720
496779890
87...

result:

ok 100000 numbers

Test #46:

score: 0
Accepted
time: 346ms
memory: 29460kb

input:

100000 0 4 1 100000
19976 19976
930307296 347896923
488422790 122006616
254292499 385320296
118841452 305855473
220506095 734110746
76511 76511
733970715 953620799
892153455 488725274
392229425 520312991
439397817 112142735
957290217 381693407
26327 26327
21580999 691947757
83624823 464367410
980975...

output:

225738555
214759727
108832407
762261275
864099566
720689765
718654473
882803028
203399073
265919421
271852236
206814944
963677189
246953800
793508085
850883446
974333494
298581206
438825170
9001044
296169693
220497567
416695424
629190242
619581187
441655724
267190171
778132646
2223771
899421067
4824...

result:

ok 100000 numbers

Test #47:

score: 0
Accepted
time: 198ms
memory: 21952kb

input:

100000 0 1 2 100000
73838 73838
274549763 865063181 32136903
53475699 519269603 405273531
71697 71697
876944090 280541147 203483885
101922547 186440707 307240260
22793 22793
618744968 181134563 330314386
216801164 639812156 24034170
51945 51945
37335644 549161545 241567218
295424268 954415389 432786...

output:

158769345
91752448
318980478
682463374
812203482
231065712
259747790
126945803
29984182
39995008
437957831
105835667
416780632
413312665
816060362
591547303
882687698
680499421
493928363
159339065
26276621
783584492
647783605
843283824
309112435
563441364
100206956
270102855
675153271
90110905
45327...

result:

ok 100000 numbers

Test #48:

score: 0
Accepted
time: 210ms
memory: 21856kb

input:

100000 0 1 2 100000
10963 10963
118533036 71877326 625707967
848757723 693498077 753443682
25930 25930
800025480 532304292 789668511
269301094 29714643 851090628
87397 87397
263900861 257160326 107105197
827826496 959850057 230900328
23859 23859
107139126 839685760 81346250
667647079 22541961 395830...

output:

231379920
254333418
252771315
418214494
739827152
243827675
651485321
424653515
142557212
490388274
31937549
356959822
145014447
701639245
370915853
351197761
284200447
431712993
957175103
275959444
890290532
319487714
214844885
921725847
697743209
419367023
20279153
345734736
164369300
119618322
91...

result:

ok 100000 numbers

Subtask #7:

score: 20
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Test #49:

score: 20
Accepted
time: 213ms
memory: 22944kb

input:

100000 44065 1 4 55935
23522 67587
115697709 250840030 165009947 842555732 563322183
818820348 364798078 741236992 72382973 894471863
22349 66414
331413115 751507905 78093404 118581431 302540454
821297841 951969998 127102858 311650434 66062983
35778 79843
171409163 321548635 938366212 552348158 9622...

output:

194703718
933481500
28605993
329825293
53817655
508455134
145321964
440184137
26017897
467183301
938302350
355410613
259882394
864361063
452573478
963425150
521790749
354722591
791345896
856590347
19092787
526314594
312737188
920815046
644020560
116965447
862160485
957172717
638379462
118166064
6070...

result:

ok 100000 numbers

Test #50:

score: 0
Accepted
time: 269ms
memory: 24544kb

input:

100000 10749 1 3 89251
75129 85878
174054637 402977226 141335346 8719859
244797592 559859827 338410579 542163466
46112 56861
200484095 166415586 599792413 352547710
606389754 923578076 613329260 100914089
44787 55536
895743213 842441896 428153285 176329574
38588174 369802154 86978584 693358219
30093...

output:

12326565
99295116
422147399
203414029
429195153
308091533
240437796
907291329
238685443
404883202
871424372
829452725
966698750
972036261
891040072
606860040
905932694
879407935
502592766
334626097
471801025
791497285
192426443
104737909
635979209
167537106
70565732
976939227
876560268
631229384
543...

result:

ok 100000 numbers

Test #51:

score: 0
Accepted
time: 268ms
memory: 27000kb

input:

100000 11620 3 1 88380
44768 56388
210735744 669094243
253405759 861068315
184114438 106829151
58630910 447655020
35678 47298
281947942 256401626
667224420 218993053
258868367 441310831
284991224 745468260
49509 61129
32983345 69938082
766910044 866161354
506439940 9688611
202350215 995309740
25970 ...

output:

127210827
642383910
774140297
22766391
615742345
135121650
525607674
717767341
598889727
963699066
37985632
448705412
665633645
452522711
911413114
166460090
767525206
992917976
706375069
611640409
795465682
272990194
971128890
238563010
948090048
414758436
742461938
9093990
287702062
607902507
6998...

result:

ok 100000 numbers

Test #52:

score: 0
Accepted
time: 303ms
memory: 23920kb

input:

100000 -46678 3 1 100000
47524 846
264005457 793708314
12830957 47414090
807103496 117378608
298062124 89523116
88688 42010
210403733 532678094
848410081 185471047
974845881 386924034
188057378 431515145
96577 49899
507210825 560947266
881601643 328887780
773135198 700107075
938576475 789224435
6772...

output:

690028412
814002820
789781479
798025560
846502756
578038110
134368067
343443769
950106279
723157090
785092868
589231643
465021155
203130053
317664195
240768261
273754447
920832343
730372476
664445837
693929027
172771362
623084556
113949574
951677435
76387861
278691947
42665661
40217249
717685593
459...

result:

ok 100000 numbers

Test #53:

score: 0
Accepted
time: 123ms
memory: 22696kb

input:

100000 25599 1 1 74401
59971 85570
153367105 115848051
176798572 339706280
5838 31437
364158648 549009508
549155875 892174391
11050 36649
682206503 244156449
513942977 624839121
42277 67876
984544581 212279670
278636683 816761020
69173 94772
151633636 749132455
34874776 242438895
36589 62188
8656379...

output:

541611693
34023632
200968063
222889656
307072771
981431355
453275911
129141510
154159146
772233936
855793245
114962139
243624559
623088863
818788154
607231091
213882490
380653820
998173525
572506142
609820661
733560425
339608423
464890918
519337309
389235939
133323980
8407140
286819339
373083397
533...

result:

ok 100000 numbers

Test #54:

score: 0
Accepted
time: 193ms
memory: 23252kb

input:

100000 19723 1 2 80277
16287 36010
66451573 9897753 170281642
986073268 29326354 649803782
68300 88023
663705367 895576262 858108403
697641723 365508175 969989373
20015 39738
779213185 921310804 497374852
596572595 535520215 104113780
20615 40338
950062157 772340571 755527356
509351245 110730819 339...

output:

148768233
415896120
877658211
209433882
467254351
118929512
95528150
54725070
14781954
439950919
81977270
439836163
824822189
16362100
568593692
820698649
233056937
299244722
712759413
921099084
84296127
498066210
554641769
44019576
898768066
835440412
587818721
588735742
164884011
297167669
5829651...

result:

ok 100000 numbers

Test #55:

score: 0
Accepted
time: 308ms
memory: 24420kb

input:

100000 -39812 3 1 100000
61085 21273
860849922 159655970
927594251 234178354
825743236 460120917
358391831 669735449
50693 10881
860801564 316807856
281298880 76513526
553707371 845425691
645493054 500191230
77931 38119
206079303 823584989
529228039 593257430
34549439 146517170
757433054 84406030
53...

output:

158049911
584756665
92298120
754764323
610598700
384156898
13163318
621893875
82326681
776997059
235964715
470406352
399352383
2785257
865565795
505112717
267919901
319637632
128309062
578278400
594803290
38450471
367301198
358730693
75929199
509841590
309863817
46646563
162092025
611952446
23262432...

result:

ok 100000 numbers

Test #56:

score: 0
Accepted
time: 225ms
memory: 22548kb

input:

100000 -42762 1 2 100000
50812 8050
344660878 148363051 45574440
424722519 777816356 742918318
77317 34555
903616188 536626049 627543289
40003021 661728391 902755339
62521 19759
886077579 47372371 476022070
802707235 791666474 902340035
65278 22516
359062497 19406490 964894487
614413283 276542545 32...

output:

186323653
367728321
11651589
974942560
68106590
731409172
374461859
371467358
443172074
170088904
144972036
64101995
589283762
691797806
49635552
114620664
147990036
195483040
578096962
117904655
542086565
32875023
746164797
698603190
49713418
569623939
248409998
336013533
911441489
242569378
824390...

result:

ok 100000 numbers

Test #57:

score: 0
Accepted
time: 392ms
memory: 26804kb

input:

100000 -35075 4 1 100000
85661 50586
113197302 118680497
276145564 503797153
20879696 861555766
25844909 392686957
873438377 932257647
60123 25048
290330497 171309685
984701199 691238913
50893418 528988892
743744220 951005364
730835136 264782783
77491 42416
862050233 763094629
228379424 111762222
28...

output:

388382609
776255445
92589191
178387253
394835344
482271231
395709241
503611030
840052391
197079690
435052955
124260580
120511188
148526263
971826402
391164342
962767736
658754192
366571051
464090279
501340628
141767293
875362707
425297829
781779275
872203457
177556445
198827025
342561571
351600317
1...

result:

ok 100000 numbers

Test #58:

score: 0
Accepted
time: 307ms
memory: 24092kb

input:

100000 -14270 3 1 100000
35123 20853
106383303 12814068
92151695 395526682
897321335 238755916
997534288 462721978
71718 57448
379599452 283261704
848934781 552834015
60183336 18726489
604667483 744983675
69722 55452
215239450 268572246
947877501 22998832
588951016 963782402
42936395 862114931
88216...

output:

899392491
540677429
314153558
989086407
497974087
329891954
106736652
171526016
963395822
346504926
526299477
54725846
760511676
249350778
67103044
533412663
917063680
261876781
255219952
237255738
691456683
826768815
491427635
774859626
838744184
963672305
581310398
287203230
628149199
274231798
19...

result:

ok 100000 numbers