QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186625#4908. 完全表示hos_lyric100 ✓163ms51408kbC++1411.6kb2023-09-24 07:23:482023-09-24 07:23:48

Judging History

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

  • [2023-09-24 07:23:48]
  • 评测
  • 测评结果:100
  • 用时:163ms
  • 内存:51408kb
  • [2023-09-24 07:23:48]
  • 提交

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 = 164511353;
using Mint = ModInt<MO>;

constexpr int A = 41;
static_assert(((1LL << A) - 1) % MO == 0);

/*
  F[n](x) := \sum[<T> = R^n] x^|T|
  F[0](x) = 1 + x
  
  pi: R^n = R^(n-1) * R -> R^(n-1)
  <T> = R^n ==> <pi(T)> = R^(n-1)
  T \cap \pi^-1(0): left ideal of R
  
  F[n](x) = \sum[I: left ideal of R] \mu(I, R) #{T | <\pi(T)> = R^(n-1) && T \cap \pi^-1(0) \subseteq J}
          = \sum[I] \mu(I, R) (K/|I|)^(n-1) F[n-1]((x+1)^|I|-1)
  
  G[n](y) := F[n](y-1)
  G[0](y) = y
  G[n](y) = \sum[I] \mu(I, R) (K/|I|)^(n-1) G[n-1](y^|I|)
  
  ans = (x (d/dx))^M F[N](x) |[x=1]
      = \sum[k] S(M,k) x^k (d/dx)^k F[N](x) |[x=1]
      = \sum[k] S(M,k) (d/dy)^k G[N](y) |[y=2]
      = \sum[k] S(M,k) \sum[j] G[N][j] j^(fall k) 2^(j-k)
      = \sum[k] S(M,k) \sum[j] G[N][j] \sum[l] s(k,l) j^l 2^(j-k)
      = \sum[l] (\sum[k] S(M,k) s(k,l) 2^-k) \sum[j] G[N][j] j^l 2^j
  
  0 <= n < N
  I: K^n |I|^(l-n)
  
  ----------------
  
  Case. R = Z/KZ
  F[n](x) = \sum[d|K] \mu(d) d^(n-1) F[n-1]((x+1)^(K/d)-1)
  
  K = \prod[i] P[i]^E[i]
  G[n](y) =: \sum[f] H[n][f] y^(P^f)
  H[0](z) = 1
  H[n](z) = (\prod[i] (z[i]^E[i] - P[i]^(n-1) z[i]^(E[i]-1))) H[n-1](z)
  
  ans = \sum[l] (\sum[k] S(M,k) s(k,l) 2^-k) \sum[f] H[n][f] (P^f)^l 2^(P^f)
  
  z^f |-> (P^f)^l  (z <- P^l z)
  z^f |-> 2^(P^f) == 2^(P^f mod A)
  
  \prod[0<=n<N] (p^(le) z^e - p^n p^(l(e-1)) z^(e-1))
  = (-1)^N p^(binom(N,2) Nl(e-1)) z^(N(e-1)) \prod[0<=n<N] (1 - p^(l-n) z)
*/

int N, K, M;
int T;

Mint s[1010][1010];
Mint S[1010][1010];

Mint hss[1010][A];


namespace z_over_kz {
// \prod (1 - c z)  mod (z^A - z)
namespace que {
int lens[2];
Mint css[2][101'010];
Mint dss[2][101'010][A];
void init() {
  for (int i = 0; i < 2; ++i) {
    lens[i] = 0;
    fill(dss[i][0], dss[i][0] + A, 0);
    dss[i][0][0] = 1;
  }
}
void push(int i, Mint c) {
  css[i][++lens[i]] = c;
  Mint *crt = dss[i][lens[i] - 1];
  Mint *nxt = dss[i][lens[i]];
  for (int f = 0; f < A; ++f) nxt[f] = crt[f];
  for (int f = 0; f < A - 1; ++f) nxt[f + 1] -= crt[f] * c;
  nxt[1] -= crt[A - 1] * c;
}
void push(Mint c) {
  push(1, c);
}
void pop() {
  if (!lens[0]) {
    for (int j = lens[1]; j > 0; --j) push(0, css[1][j]);
    lens[1] = 0;
  }
  assert(lens[0]);
  --lens[0];
}
Mint prod[2 * A - 1];
void get() {
  fill(prod, prod + (2 * A - 1), 0);
  for (int f0 = 0; f0 < A; ++f0) for (int f1 = 0; f1 < A; ++f1) {
    prod[f0 + f1] += dss[0][lens[0]][f0] * dss[1][lens[1]][f1];
  }
  for (int f = 1; f < A; ++f) {
    prod[f] += prod[A - 1 + f];
  }
}
}  // que

int I;
vector<int> P, E;
void run() {
  P.clear();
  E.clear();
  {
    int k = K;
    for (int p = 2; p * p <= k; ++p) if (k % p == 0) {
      int e = 0;
      do {
        ++e;
        k /= p;
      } while (k % p == 0);
      P.push_back(p);
      E.push_back(e);
    }
    if (k > 1) {
      P.push_back(k);
      E.push_back(1);
    }
  }
  I = P.size();
cerr<<"N = "<<N<<", K = "<<K<<", M = "<<M<<", I = "<<I<<", P = "<<P<<", E = "<<E<<endl;
  memset(hss, 0, sizeof(hss));
  for (int l = 0; l <= M; ++l) {
    hss[l][1] = 1;
  }
  for (int i = 0; i < I; ++i) {
    int pne1 = 1;
    {
      int pe1 = 1;
      for (int f = 0; f < E[i] - 1; ++f) (pe1 *= P[i]) %= A;
      for (int n = 0; n < N; ++n) (pne1 *= pe1) %= A;
    }
    que::init();
    Mint pl = Mint(P[i]).pow(-N);
    for (int n = N; --n >= 1; ) {
      pl *= P[i];
      que::push(pl);
    }
    for (int l = 0; l <= M; ++l) {
      // (l-N, l]
      pl *= P[i];
      que::push(pl);
      que::get();
      {
        const Mint coef = ((N&1)?-1:+1) * Mint(P[i]).pow(1LL*N*(N-1)/2 + 1LL*N*l*(E[i]-1));
        Mint tmp[A] = {};
        int pf = pne1;
        for (int f = 0; f < A; ++f) {
          const Mint t = coef * que::prod[f];
          for (int a = 0; a < A; ++a) {
            tmp[(a * pf) % A] += hss[l][a] * t;
          }
          (pf *= P[i]) %= A;
        }
        copy(tmp, tmp + A, hss[l]);
      }
      que::pop();
    }
  }
}
}  // z_over_kz


namespace general_ring {
// |ks| <= sigma_0(K)
int ksLen;
int ks[6];
namespace que {
int lens[2];
Mint css[2][101'010][6];
Mint dss[2][101'010][A];
void init() {
  for (int i = 0; i < 2; ++i) {
    lens[i] = 0;
    fill(dss[i][0], dss[i][0] + A, 0);
    dss[i][0][1] = 1;
  }
}
void push(int i, const Mint *cs) {
  ++lens[i];
  copy(cs, cs + ksLen, css[i][lens[i]]);
  Mint *crt = dss[i][lens[i] - 1];
  Mint *nxt = dss[i][lens[i]];
  fill(nxt, nxt + A, 0);
  for (int a = 0; a < A; ++a) for (int h = 0; h < ksLen; ++h) {
    nxt[(a * ks[h]) % A] += crt[a] * cs[h];
  }
}
void push(const Mint *cs) {
  push(1, cs);
}
void pop() {
  if (!lens[0]) {
    for (int j = lens[1]; j > 0; --j) push(0, css[1][j]);
    lens[1] = 0;
  }
  assert(lens[0]);
  --lens[0];
}
Mint prod[A];
void get() {
  fill(prod, prod + A, 0);
  for (int a0 = 0; a0 < A; ++a0) for (int a1 = 0; a1 < A; ++a1) {
    prod[(a0 * a1) % A] += dss[0][lens[0]][a0] * dss[1][lens[1]][a1];
  }
}
}  // que

int ADD[20][20], MUL[20][20];
bool isLeftIdeal(int p) {
  if (!(p >> 0 & 1)) {
    return false;
  }
  for (int x = 0; x < K; ++x) if (p >> x & 1) for (int y = x; y < K; ++y) if (p >> y & 1) {
    if (!(p >> ADD[x][y] & 1)) {
      return false;
    }
  }
  for (int r = 0; r < K; ++r) for (int x = 0; x < K; ++x) if (p >> x & 1) {
    if (!(p >> MUL[r][x] & 1)) {
      return false;
    }
  }
  return true;
}
void run() {
  for (int x = 0; x < K; ++x) for (int y = 0; y < K; ++y) scanf("%d", &ADD[x][y]);
  for (int x = 0; x < K; ++x) for (int y = 0; y < K; ++y) scanf("%d", &MUL[x][y]);
  vector<int> ps;
  for (int p = 1; p < 1 << K; p += 2) {
    if (isLeftIdeal(p)) {
      ps.push_back(p);
    }
  }
  const int psLen = ps.size();
  assert(ps[0] == 1);
  assert(ps[psLen - 1] == (1 << K) - 1);
  vector<int> mu(psLen, 0);
  mu[psLen - 1] = 1;
  for (int i = psLen - 1; --i >= 0; ) {
    for (int j = i + 1; j < psLen; ++j) if (!(ps[i] & ~ps[j])) {
      mu[i] -= mu[j];
    }
  }
cerr<<"N = "<<N<<", K = "<<K<<", M = "<<M<<", ps = "<<ps<<", mu = "<<mu<<endl;
  vector<int> sums(K + 1, 0);
  for (int i = 0; i < psLen; ++i) {
    sums[__builtin_popcount(ps[i])] += mu[i];
  }
  ksLen = 0;
  for (int k = 1; k <= K; ++k) if (sums[k]) {
    ks[ksLen++] = k;
  }
  que::init();
  Mint cs[6];
  for (int h = 0; h < ksLen; ++h) {
    cs[h] = sums[ks[h]] * Mint(ks[h]).pow(-N);
  }
  for (int n = N; --n >= 1; ) {
    for (int h = 0; h < ksLen; ++h) {
      cs[h] *= ks[h];
    }
    que::push(cs);
  }
  const Mint coef = Mint(K).pow(1LL*N*(N-1)/2);
  for (int l = 0; l <= M; ++l) {
    // (l-N, l]
    for (int h = 0; h < ksLen; ++h) {
      cs[h] *= ks[h];
    }
    que::push(cs);
    que::get();
    for (int a = 0; a < A; ++a) {
      hss[l][a] = coef * que::prod[a];
    }
    que::pop();
  }
}
}  // general_ring


int main() {
  for (; ~scanf("%d%d%d", &N, &K, &M); ) {
    scanf("%d", &T);
    
    for (int m = 0; m <= M; ++m) {
      s[m][0] = 0;
      s[m][m] = 1;
      for (int k = 1; k < m; ++k) {
        s[m][k] = s[m - 1][k - 1] - (m - 1) * s[m - 1][k];
      }
    }
    for (int m = 0; m <= M; ++m) {
      S[m][0] = 0;
      S[m][m] = 1;
      for (int k = 1; k < m; ++k) {
        S[m][k] = S[m - 1][k - 1] + k * S[m - 1][k];
      }
    }
    
    if (T == 1) {
      z_over_kz::run();
    } else if (T == 2) {
      general_ring::run();
    } else {
      assert(false);
    }
    
    Mint ans = 0;
    for (int l = 0; l <= M; ++l) {
      // (\sum[k] S(M,k) s(k,l) 2^-k)
      Mint coef = 0;
      {
        Mint two = Mint(2).pow(-M);
        for (int k = M; k >= l; --k) {
          coef += S[M][k] * s[k][l] * two;
          two *= 2;
        }
      }
      Mint sum = 0;
      for (int a = 0; a < A; ++a) {
        sum += hss[l][a] * Mint(1LL << a);
      }
      ans += coef * sum;
    }
    printf("%u\n", ans.x);
  }
  return 0;
}

详细

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 10ms
memory: 18036kb

input:

2 3 665
1

output:

51745605

result:

ok "51745605"

Test #2:

score: 0
Accepted
time: 4ms
memory: 16036kb

input:

2 4 641
1

output:

54153482

result:

ok "54153482"

Test #3:

score: 0
Accepted
time: 11ms
memory: 15992kb

input:

1 6 656
1

output:

119347748

result:

ok "119347748"

Test #4:

score: 0
Accepted
time: 0ms
memory: 15980kb

input:

1 8 170
1

output:

126971959

result:

ok "126971959"

Test #5:

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

input:

1 9 816
1

output:

14287284

result:

ok "14287284"

Test #6:

score: 0
Accepted
time: 6ms
memory: 15988kb

input:

1 12 233
1

output:

37178137

result:

ok "37178137"

Test #7:

score: 0
Accepted
time: 0ms
memory: 15992kb

input:

1 16 244
1

output:

91022688

result:

ok "91022688"

Test #8:

score: 0
Accepted
time: 3ms
memory: 15980kb

input:

1 18 218
1

output:

93037058

result:

ok "93037058"

Test #9:

score: 0
Accepted
time: 4ms
memory: 16004kb

input:

1 19 645
1

output:

53944276

result:

ok "53944276"

Test #10:

score: 0
Accepted
time: 5ms
memory: 15992kb

input:

1 20 333
1

output:

81197702

result:

ok "81197702"

Test #11:

score: 0
Accepted
time: 13ms
memory: 18120kb

input:

1 2 893
1

output:

17672119

result:

ok "17672119"

Test #12:

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

input:

1 19 887
1

output:

58567516

result:

ok "58567516"

Test #13:

score: 0
Accepted
time: 4ms
memory: 18080kb

input:

2 3 504
1

output:

60763909

result:

ok "60763909"

Subtask #2:

score: 15
Accepted

Test #14:

score: 15
Accepted
time: 2ms
memory: 11820kb

input:

19 90203 0
1

output:

142145213

result:

ok "142145213"

Test #15:

score: 0
Accepted
time: 0ms
memory: 13992kb

input:

18 9697 0
1

output:

153592927

result:

ok "153592927"

Test #16:

score: 0
Accepted
time: 2ms
memory: 13988kb

input:

20 41 0
1

output:

112957727

result:

ok "112957727"

Test #17:

score: 0
Accepted
time: 0ms
memory: 11892kb

input:

20 99991 0
1

output:

151341559

result:

ok "151341559"

Subtask #3:

score: 5
Accepted

Dependency #2:

100%
Accepted

Test #18:

score: 5
Accepted
time: 2ms
memory: 11992kb

input:

999 9749 0
1

output:

77370298

result:

ok "77370298"

Test #19:

score: 0
Accepted
time: 0ms
memory: 11892kb

input:

997 55103 0
1

output:

92054017

result:

ok "92054017"

Test #20:

score: 0
Accepted
time: 2ms
memory: 11896kb

input:

1000 41 0
1

output:

6438830

result:

ok "6438830"

Test #21:

score: 0
Accepted
time: 2ms
memory: 11896kb

input:

1000 99991 0
1

output:

31676606

result:

ok "31676606"

Subtask #4:

score: 5
Accepted

Dependency #3:

100%
Accepted

Test #22:

score: 5
Accepted
time: 7ms
memory: 40636kb

input:

99996 20089 0
1

output:

163612442

result:

ok "163612442"

Test #23:

score: 0
Accepted
time: 11ms
memory: 42604kb

input:

99996 17707 0
1

output:

109099283

result:

ok "109099283"

Test #24:

score: 0
Accepted
time: 11ms
memory: 42636kb

input:

100000 41 0
1

output:

131161322

result:

ok "131161322"

Test #25:

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

input:

100000 99991 0
1

output:

84487741

result:

ok "84487741"

Subtask #5:

score: 15
Accepted

Test #26:

score: 15
Accepted
time: 2ms
memory: 11884kb

input:

998 24 0
1

output:

75129854

result:

ok "75129854"

Test #27:

score: 0
Accepted
time: 0ms
memory: 13992kb

input:

998 35 0
1

output:

120341894

result:

ok "120341894"

Test #28:

score: 0
Accepted
time: 3ms
memory: 16040kb

input:

1000 30 0
1

output:

152799538

result:

ok "152799538"

Test #29:

score: 0
Accepted
time: 0ms
memory: 11884kb

input:

1000 82 0
1

output:

117109540

result:

ok "117109540"

Test #30:

score: 0
Accepted
time: 0ms
memory: 13992kb

input:

1000 100 0
1

output:

89805014

result:

ok "89805014"

Subtask #6:

score: 5
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Test #31:

score: 5
Accepted
time: 50ms
memory: 40660kb

input:

99998 20726 0
1

output:

63876769

result:

ok "63876769"

Test #32:

score: 0
Accepted
time: 60ms
memory: 42612kb

input:

99998 10270 0
1

output:

47691333

result:

ok "47691333"

Test #33:

score: 0
Accepted
time: 86ms
memory: 42620kb

input:

100000 30030 0
1

output:

80481158

result:

ok "80481158"

Test #34:

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

input:

100000 94710 0
1

output:

61977663

result:

ok "61977663"

Test #35:

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

input:

100000 100000 0
1

output:

163629325

result:

ok "163629325"

Subtask #7:

score: 15
Accepted

Dependency #6:

100%
Accepted

Test #36:

score: 15
Accepted
time: 5ms
memory: 11940kb

input:

96 26444 100
1

output:

28274469

result:

ok "28274469"

Test #37:

score: 0
Accepted
time: 0ms
memory: 11896kb

input:

96 1381 98
1

output:

108507497

result:

ok "108507497"

Test #38:

score: 0
Accepted
time: 8ms
memory: 13936kb

input:

100 30030 100
1

output:

96954743

result:

ok "96954743"

Test #39:

score: 0
Accepted
time: 8ms
memory: 15992kb

input:

100 94710 100
1

output:

4473750

result:

ok "4473750"

Test #40:

score: 0
Accepted
time: 4ms
memory: 11940kb

input:

100 100000 100
1

output:

119621887

result:

ok "119621887"

Subtask #8:

score: 15
Accepted

Dependency #1:

100%
Accepted

Dependency #7:

100%
Accepted

Test #41:

score: 15
Accepted
time: 72ms
memory: 45416kb

input:

99996 23632 996
1

output:

25805700

result:

ok "25805700"

Test #42:

score: 0
Accepted
time: 80ms
memory: 46504kb

input:

99998 15516 997
1

output:

55584997

result:

ok "55584997"

Test #43:

score: 0
Accepted
time: 151ms
memory: 46196kb

input:

100000 30030 1000
1

output:

131562265

result:

ok "131562265"

Test #44:

score: 0
Accepted
time: 151ms
memory: 46052kb

input:

100000 94710 1000
1

output:

149443247

result:

ok "149443247"

Test #45:

score: 0
Accepted
time: 56ms
memory: 45040kb

input:

100000 100000 1000
1

output:

111554062

result:

ok "111554062"

Subtask #9:

score: 15
Accepted

Test #46:

score: 15
Accepted
time: 54ms
memory: 51304kb

input:

99997 3 997
2
0 1 2
1 2 0
2 0 1
0 0 0
0 1 2
0 2 1

output:

16632035

result:

ok "16632035"

Test #47:

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

input:

99997 4 999
2
0 1 2 3
1 0 3 2
2 3 0 1
3 2 1 0
0 0 0 0
0 1 2 3
0 2 3 1
0 3 1 2

output:

137547387

result:

ok "137547387"

Test #48:

score: 0
Accepted
time: 102ms
memory: 51408kb

input:

100000 6 1000
2
0 1 2 3 4 5
1 2 3 4 5 0
2 3 4 5 0 1
3 4 5 0 1 2
4 5 0 1 2 3
5 0 1 2 3 4
0 0 0 0 0 0
0 1 2 3 4 5
0 2 4 0 2 4
0 3 0 3 0 3
0 4 2 0 4 2
0 5 4 3 2 1

output:

16561140

result:

ok "16561140"

Test #49:

score: 0
Accepted
time: 83ms
memory: 49308kb

input:

99999 8 1000
2
0 1 2 3 4 5 6 7
1 4 3 5 7 6 2 0
2 3 0 1 5 4 7 6
3 5 1 4 6 7 0 2
4 7 5 6 0 2 3 1
5 6 4 7 2 0 1 3
6 2 7 0 3 1 4 5
7 0 6 2 1 3 5 4
0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7
0 2 2 0 0 2 0 2
0 3 0 3 4 4 6 6
0 4 0 4 0 0 4 4
0 5 2 4 0 2 4 5
0 6 0 6 4 4 3 3
0 7 2 6 4 5 3 1

output:

163171319

result:

ok "163171319"

Test #50:

score: 0
Accepted
time: 56ms
memory: 51360kb

input:

99997 8 1000
2
0 1 2 3 4 5 6 7
1 2 3 0 5 6 7 4
2 3 0 1 6 7 4 5
3 0 1 2 7 4 5 6
4 5 6 7 0 1 2 3
5 6 7 4 1 2 3 0
6 7 4 5 2 3 0 1
7 4 5 6 3 0 1 2
0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7
0 2 0 2 0 2 0 2
0 3 2 1 4 7 6 5
0 4 0 4 0 4 0 4
0 5 2 7 4 1 6 3
0 6 0 6 0 6 0 6
0 7 2 5 4 3 6 1

output:

300232

result:

ok "300232"

Test #51:

score: 0
Accepted
time: 59ms
memory: 51348kb

input:

99997 8 997
2
0 1 2 3 4 5 6 7
1 2 3 0 5 6 7 4
2 3 0 1 6 7 4 5
3 0 1 2 7 4 5 6
4 5 6 7 0 1 2 3
5 6 7 4 1 2 3 0
6 7 4 5 2 3 0 1
7 4 5 6 3 0 1 2
0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7
0 2 0 2 0 2 0 2
0 3 2 1 4 7 6 5
0 4 0 4 2 6 2 6
0 5 2 7 6 3 4 1
0 6 0 6 2 4 2 4
0 7 2 5 6 1 4 3

output:

24928366

result:

ok "24928366"

Test #52:

score: 0
Accepted
time: 76ms
memory: 51308kb

input:

100000 8 999
2
0 1 2 3 4 5 6 7
1 0 7 6 5 4 3 2
2 7 0 5 6 3 4 1
3 6 5 0 7 2 1 4
4 5 6 7 0 1 2 3
5 4 3 2 1 0 7 6
6 3 4 1 2 7 0 5
7 2 1 4 3 6 5 0
0 0 0 0 0 0 0 0
0 1 2 3 4 5 6 7
0 2 0 0 2 0 2 2
0 3 2 3 2 5 0 5
0 4 0 0 4 0 4 4
0 5 2 3 0 5 2 3
0 6 0 0 6 0 6 6
0 7 2 3 6 5 4 1

output:

142695202

result:

ok "142695202"

Test #53:

score: 0
Accepted
time: 82ms
memory: 51308kb

input:

99997 16 999
2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
1 0 7 6 5 4 3 2 13 12 15 14 9 8 11 10
2 7 0 5 6 3 4 1 10 11 8 9 14 15 12 13
3 6 5 0 7 2 1 4 11 10 9 8 15 14 13 12
4 5 6 7 0 1 2 3 12 13 14 15 8 9 10 11
5 4 3 2 1 0 7 6 9 8 11 10 13 12 15 14
6 3 4 1 2 7 0 5 14 15 12 13 10 11 8 9
7 2 1 4 3 6 5 0 15 ...

output:

40840083

result:

ok "40840083"

Test #54:

score: 0
Accepted
time: 163ms
memory: 51360kb

input:

99996 18 1000
2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
1 4 3 5 2 0 9 8 11 10 7 6 15 14 17 16 13 12
2 3 0 1 5 4 7 6 9 8 11 10 13 12 15 14 17 16
3 5 1 4 0 2 8 9 10 11 6 7 14 15 16 17 12 13
4 2 5 0 3 1 10 11 6 7 8 9 16 17 12 13 14 15
5 0 4 2 1 3 11 10 7 6 9 8 17 16 13 12 15 14
6 9 7 8 10 11 12 13 ...

output:

155029514

result:

ok "155029514"

Test #55:

score: 0
Accepted
time: 68ms
memory: 51284kb

input:

100000 19 996
2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1 18 14 11 5 15 9 10 0 2 3 4 13 17 12 16 6 8 7
2 14 4 8 1 18 3 13 9 11 17 0 15 16 5 7 10 6 12
3 11 8 16 9 2 13 5 10 17 15 6 1 18 0 14 12 7 4
4 5 1 9 14 12 8 16 11 0 6 2 7 10 18 13 17 3 15
5 15 18 2 12 13 0 6 4 1 9 14 10 3 7 17 8 11 16
6 ...

output:

18522199

result:

ok "18522199"

Test #56:

score: 0
Accepted
time: 130ms
memory: 51324kb

input:

99999 20 1000
2
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
1 3 7 8 9 6 2 4 5 0 16 17 18 19 15 11 12 13 14 10
2 7 3 4 5 0 1 8 9 6 11 12 13 14 10 16 17 18 19 15
3 8 4 5 0 2 7 9 6 1 12 13 14 10 11 17 18 19 15 16
4 9 5 0 2 3 8 6 1 7 13 14 10 11 12 18 19 15 16 17
5 6 0 2 3 4 9 1 7 8 14 10 11 12 13...

output:

26568180

result:

ok "26568180"