QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#788159#9438. Two BoxMade_in_CodeTL 61ms78440kbC++143.1kb2024-11-27 16:05:132024-11-27 16:05:17

Judging History

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

  • [2024-11-27 16:05:17]
  • 评测
  • 测评结果:TL
  • 用时:61ms
  • 内存:78440kb
  • [2024-11-27 16:05:13]
  • 提交

answer

#include <iostream>
#define LL long long

using namespace std;

const int kMaxN = 5e4 + 1, kMaxM = 15 + 1, kMod = 998244353, kInv2 = kMod + 1 >> 1;
int n, m, q, a[kMaxN];
LL f[kMaxM - 1][kMaxN][kMaxM], h[kMaxM], trans[kMaxM][kMaxM][kMaxM], inv[kMaxM];

void Init() {
  static LL c[kMaxM][kMaxM] = {};
  for (int i = 0; i <= m; i++) {
    c[i][0] = c[i][i] = 1;
    for (int j = 1; j < i; j++) {
      c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % kMod;
    }
  }
  inv[0] = 1;
  for (int i = 1; i <= m; i++) {
    inv[i] = inv[i - 1] * kInv2 % kMod;
    for (int j = 0; j <= i; j++) {
      for (int k = 0; k <= i; k++) {
        for (int l = max(j + k - i, 0); l <= min(j, k); l++) {
          LL w = c[j][l] * c[i - j][k - l] % kMod;
          if (l & 1) {
            trans[i][j][k] = (trans[i][j][k] - w + kMod) % kMod;
          } else {
            trans[i][j][k] = (trans[i][j][k] + w) % kMod;
          }
        }
      }
    }
  }
}

LL Ask() {  // O(nm^3)
  for (int i = m - 1; i >= 0; i--) {
    for (int l = 1, r = 1; l <= n; l = r) {
      for (; r <= n && (a[l] >= i) == (a[r] >= i); r++) {
      }
      if (a[l] >= i) {
        LL *g = f[i][l];
        g[0] = 1;
        for (int j = 1; j <= i + 1; j++) {
          g[j] = 0;
        }
        for (int p = l, q = l; p < r; p = q) {
          for (; q < r && (a[p] > i) == (a[q] > i); q++) {
          }
          if (a[p] > i) {
            for (int j = 0; j <= i + 1; j++) {
              LL x = 0, y = 0;
              for (int k = 0; k <= i + 1; k++) {
                x = (x + g[k] * trans[i + 1][j][k]) % kMod;
                y = (y + f[i + 1][p][k] * trans[i + 1][j][k]) % kMod;
              }
              h[j] = x * y % kMod;
            }
            for (int j = 0; j <= i + 1; j++) {
              g[j] = 0;
              for (int k = 0; k <= i + 1; k++) {
                g[j] = (g[j] + h[k] * trans[i + 1][j][k]) % kMod;
              }
              g[j] = g[j] * inv[i + 1] % kMod;
            }
          } else {
            for (int j = p + (p > l); j < q + (r <= n && q == r); j++) {
              for (int k = 0; k <= i + 1; k++) {
                if (k == 0) {
                  h[k] = g[k + 1] * (i + 1 - k) % kMod;
                } else if (k == i + 1) {
                  h[k] = g[k - 1] * k % kMod;
                } else {
                  h[k] = (g[k - 1] * k + g[k + 1] * (i + 1 - k)) % kMod;
                }
              }
              for (int k = 0; k <= i + 1; k++) {
                g[k] = h[k], h[k] = 0;
              }
            }
          }
        }
        if (r == n + 1) {
          for (int j = 0; j <= i; j++) {
            g[j] = (g[j] + g[j + 1]) % kMod;
          }
          g[i + 1] = 0;
        }
      }
    }
  }
  return f[0][1][0];
}

int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(0);
  cin >> n >> m >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i], a[i]--;
  }
  Init();
  for (int i = 1, x, y; i <= q; i++) {
    cin >> x >> y, y--;
    a[x] = y;
    cout << Ask() << '\n';
  }
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7744kb

input:

3 3 2
1 3 1
3 2
1 3

output:

5
14

result:

ok 2 tokens

Test #2:

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

input:

6 8 1
3 8 7 7 1 6
1 4

output:

2100

result:

ok "2100"

Test #3:

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

input:

12 10 8
1 3 2 6 3 6 7 7 5 5 4 7
12 4
7 10
4 2
9 8
9 9
8 3
4 9
10 2

output:

2741280
3007680
1503840
1916160
1972800
728640
1821600
621440

result:

ok 8 tokens

Test #4:

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

input:

1939 5 1
5 1 1 2 1 5 4 5 3 1 2 1 3 3 1 2 3 5 5 3 2 2 1 3 1 5 1 4 2 5 4 1 5 4 3 4 5 3 3 3 3 2 1 2 3 5 1 4 2 1 4 1 3 5 2 2 1 4 4 5 3 2 3 2 1 1 5 5 5 5 3 4 3 1 3 1 1 1 3 5 3 5 1 5 4 3 2 1 2 2 2 3 5 2 4 2 3 1 2 5 5 1 2 5 2 5 3 3 3 4 5 1 5 4 5 3 3 5 4 5 3 5 3 2 2 5 3 2 4 3 3 4 2 2 1 3 1 3 5 2 3 4 2 3 2 4...

output:

894246250

result:

ok "894246250"

Test #5:

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

input:

245 9 1
2 2 3 6 7 5 7 4 7 9 7 6 3 1 6 8 2 1 1 5 3 1 1 3 1 6 8 4 8 4 8 1 8 6 6 9 3 4 7 1 5 2 3 9 5 7 5 7 7 5 5 5 5 1 5 4 7 1 2 6 8 9 5 4 1 8 6 3 9 9 1 3 6 5 5 5 1 6 5 1 2 5 5 4 1 1 8 3 8 2 9 7 9 5 7 8 8 5 9 1 1 4 4 9 9 6 3 9 8 9 2 1 2 6 9 2 1 3 7 3 2 5 9 3 7 2 2 3 4 7 5 1 8 5 8 6 7 9 7 4 8 7 2 2 7 5 ...

output:

99945033

result:

ok "99945033"

Test #6:

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

input:

1919 9 1
7 1 7 6 6 9 8 5 1 8 9 9 7 3 4 2 8 9 4 8 7 4 8 8 8 4 2 9 5 9 3 7 2 3 2 8 7 9 1 1 3 7 7 2 5 9 2 1 3 6 7 6 4 4 1 9 3 7 3 2 5 5 1 4 7 8 6 2 1 4 7 1 4 7 4 7 6 3 8 4 3 7 3 1 7 5 2 2 2 4 9 1 5 5 7 7 3 1 5 4 7 2 9 5 4 9 3 2 6 8 2 3 8 3 6 5 5 5 9 7 2 8 2 9 5 1 8 6 3 1 2 9 1 9 1 3 9 6 7 2 3 2 2 7 9 7...

output:

292474819

result:

ok "292474819"

Test #7:

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

input:

1985 5 1
1 5 5 1 4 4 3 2 1 4 4 1 1 2 5 5 5 3 3 1 2 4 3 3 5 5 2 4 1 1 5 4 3 1 2 5 5 4 1 5 2 5 2 4 1 4 5 1 3 4 4 2 2 4 5 2 1 5 5 3 2 5 5 2 4 4 5 2 5 1 1 5 5 1 1 3 4 2 4 5 2 1 2 1 1 2 3 5 1 5 2 4 1 5 3 2 2 3 1 3 4 5 1 4 4 2 4 3 5 5 1 4 3 4 5 5 2 5 2 2 2 2 2 3 5 1 4 4 3 3 4 5 5 4 3 5 1 4 5 5 2 3 2 2 3 3...

output:

810807913

result:

ok "810807913"

Test #8:

score: 0
Accepted
time: 1ms
memory: 11764kb

input:

357 5 1
1 3 2 5 4 4 3 4 3 1 1 1 4 5 5 2 1 3 4 1 3 1 2 3 4 1 5 3 1 3 5 1 4 4 2 4 5 1 3 4 2 5 2 3 2 5 3 2 2 1 4 3 1 1 2 3 2 3 2 1 4 4 5 5 1 4 2 1 2 2 2 4 1 3 5 1 1 2 4 4 5 4 1 2 4 1 2 3 2 4 3 4 3 4 1 4 1 1 4 5 4 4 4 3 2 5 4 5 4 2 4 1 2 5 5 3 5 5 2 4 2 1 2 1 4 1 2 1 3 1 5 2 2 1 5 2 2 4 5 1 3 4 5 3 3 3 ...

output:

836628563

result:

ok "836628563"

Test #9:

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

input:

858 10 1
1 9 2 9 6 9 6 10 9 4 1 9 7 7 9 2 5 6 9 3 4 7 4 2 5 10 8 10 4 8 8 1 2 9 10 9 5 9 1 2 1 8 10 2 8 1 10 6 9 5 2 4 9 4 1 5 6 10 7 5 1 7 6 7 9 8 4 4 1 8 1 4 4 10 8 10 1 1 1 2 6 3 6 9 8 10 4 5 8 3 6 7 2 9 9 7 9 10 5 7 4 9 4 7 3 1 10 2 6 4 1 5 8 7 1 6 1 2 8 8 1 3 6 8 5 3 10 9 8 4 8 5 2 2 2 10 8 1 8...

output:

699591879

result:

ok "699591879"

Test #10:

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

input:

884 7 1
7 2 6 7 1 7 2 5 5 1 7 5 4 5 2 5 4 2 2 4 3 2 7 1 6 3 3 2 1 1 2 1 7 7 4 3 5 1 1 6 6 7 5 1 6 6 4 3 5 2 3 1 6 3 7 2 7 4 6 6 6 3 7 6 1 3 2 1 1 5 4 3 1 4 4 4 7 2 5 7 5 7 5 3 6 5 5 1 4 5 6 6 6 3 6 7 3 2 3 1 5 5 6 7 6 5 3 2 7 3 1 2 5 5 1 2 7 5 3 1 3 6 4 7 2 4 4 5 6 7 4 7 4 2 4 1 2 1 2 6 7 1 7 4 1 1 ...

output:

298342150

result:

ok "298342150"

Test #11:

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

input:

2000 10 1
7 2 5 8 9 1 9 9 5 4 3 3 9 7 3 2 1 9 9 6 4 9 10 10 1 1 2 4 6 7 9 9 5 5 8 1 3 9 5 2 5 7 10 8 5 10 1 9 8 10 2 1 9 4 1 10 8 3 10 4 4 7 5 6 6 1 4 4 4 6 5 10 5 7 7 9 2 3 9 4 8 8 9 9 4 6 5 9 5 4 3 10 3 5 7 5 9 8 1 9 2 9 4 3 3 4 6 3 1 5 2 10 2 2 3 4 5 2 4 6 2 9 5 10 5 2 9 4 9 8 8 7 5 7 3 10 2 6 6 ...

output:

593281642

result:

ok "593281642"

Test #12:

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

input:

2000 10 1
4 3 9 2 9 3 9 2 7 1 4 10 1 10 8 10 1 6 9 5 7 5 10 10 1 10 5 7 1 5 5 8 10 10 4 10 6 6 1 9 8 5 2 3 5 3 1 1 3 3 6 2 6 9 8 4 10 8 7 8 9 10 5 3 6 3 2 4 10 1 10 8 7 10 7 1 4 3 2 8 8 7 7 9 1 7 5 3 5 7 6 6 9 8 8 8 9 7 10 8 3 5 5 1 3 10 9 1 9 2 10 9 3 1 6 1 7 10 9 9 9 3 6 9 2 10 6 1 5 2 2 5 6 6 9 1...

output:

635535966

result:

ok "635535966"

Test #13:

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

input:

2000 10 1
7 6 2 4 9 3 2 10 6 2 3 2 8 7 4 1 6 7 1 10 4 9 7 2 5 2 5 10 6 6 5 3 7 4 10 6 4 8 7 9 6 10 10 3 10 4 3 6 6 6 8 5 6 4 3 9 2 9 8 5 6 5 5 4 9 7 6 1 7 1 8 10 3 1 10 3 4 4 9 10 10 7 8 4 4 6 9 3 6 3 4 4 3 4 7 1 6 2 6 4 9 10 4 2 7 7 10 4 4 1 10 2 8 6 8 2 8 1 4 10 3 6 1 1 7 9 3 9 6 2 3 9 8 3 7 9 3 8...

output:

336713065

result:

ok "336713065"

Test #14:

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

input:

2000 10 1
10 10 2 4 8 7 8 9 8 7 5 10 8 2 5 5 1 3 10 5 4 3 6 3 9 9 10 9 9 9 6 10 6 2 9 3 7 4 7 10 2 4 7 3 9 3 7 10 5 9 10 7 8 1 7 7 9 10 6 4 10 4 3 6 10 5 4 7 5 6 8 8 1 6 5 7 7 5 4 2 5 8 5 9 9 9 7 10 2 9 7 6 1 8 9 2 4 1 9 8 7 9 4 2 3 2 3 2 7 5 4 8 8 2 4 8 6 4 1 3 3 9 7 10 7 7 3 8 1 1 4 2 3 4 10 8 8 8...

output:

85227947

result:

ok "85227947"

Test #15:

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

input:

2000 10 1
1 7 2 8 1 9 7 7 6 2 4 2 1 5 2 6 1 10 2 8 5 1 6 8 5 9 10 5 8 2 1 2 8 6 2 3 7 9 10 10 10 9 9 3 6 1 7 8 4 8 9 7 9 5 1 3 8 1 3 4 1 6 6 5 9 6 7 8 10 10 4 9 5 6 10 7 2 3 4 7 3 8 6 3 5 2 2 9 9 5 8 3 6 8 2 1 4 3 4 2 3 9 6 4 5 6 8 1 2 1 3 10 4 5 7 2 9 4 10 6 1 6 1 2 10 2 3 9 5 9 1 6 10 2 8 6 10 6 1...

output:

913697441

result:

ok "913697441"

Test #16:

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

input:

2000 10 1
7 9 2 6 9 1 10 1 8 3 4 5 1 10 6 10 4 10 3 1 10 2 10 8 3 5 2 2 4 9 5 7 2 4 8 5 7 5 1 10 8 10 5 8 10 4 2 9 8 9 6 3 7 10 1 7 6 9 4 10 8 5 1 3 5 7 3 6 3 2 8 5 6 2 8 2 7 6 1 6 7 4 3 5 8 3 8 9 5 6 2 8 2 4 5 2 4 1 3 9 7 1 5 9 9 2 3 2 1 8 6 1 3 6 7 3 5 5 8 3 9 5 9 1 7 2 3 5 1 7 8 10 3 4 10 8 3 6 8...

output:

298067446

result:

ok "298067446"

Test #17:

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

input:

2000 10 1
3 6 1 8 2 3 8 7 9 8 8 5 3 4 4 2 9 1 2 4 7 3 3 3 2 3 9 9 4 4 1 1 1 2 2 4 3 7 8 2 2 1 9 2 7 10 9 5 10 8 1 8 6 2 4 9 2 7 8 2 2 1 1 8 10 8 7 7 1 5 2 4 9 3 2 1 7 1 1 6 1 7 1 7 6 9 6 1 2 3 6 10 3 10 3 2 6 7 10 6 2 6 2 6 7 2 2 7 2 1 6 5 10 5 2 2 10 4 1 9 8 8 7 6 1 9 2 4 1 4 5 7 5 3 10 4 9 5 2 8 8...

output:

307824286

result:

ok "307824286"

Test #18:

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

input:

2000 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1

result:

ok "1"

Test #19:

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

input:

1 1 1
1
1 1

output:

1

result:

ok "1"

Test #20:

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

input:

2000 10 1
9 10 10 10 10 9 10 9 9 10 10 9 9 10 9 10 10 10 10 10 10 9 9 10 10 9 10 10 9 10 9 10 10 10 10 9 10 10 9 10 10 10 9 10 9 10 9 9 9 10 9 10 9 10 10 9 9 10 10 9 10 10 10 10 10 9 9 10 9 10 10 9 9 10 9 9 10 9 10 10 9 9 9 10 9 10 10 9 10 10 9 9 10 10 10 10 9 10 10 10 9 9 9 10 10 9 9 10 9 10 10 10 ...

output:

214050412

result:

ok "214050412"

Test #21:

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

input:

2000 10 1
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...

output:

527357103

result:

ok "527357103"

Test #22:

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

input:

2000 10 1
10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10 10...

output:

106236082

result:

ok "106236082"

Test #23:

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

input:

5484 3 1
1 3 1 3 3 1 1 2 3 1 3 3 3 3 3 2 2 3 1 3 3 2 1 3 3 1 2 2 2 3 2 2 3 2 3 2 1 2 1 1 1 1 2 2 3 1 1 3 3 1 3 1 1 2 2 2 3 1 3 1 3 2 1 3 1 3 2 1 3 1 1 1 3 1 3 1 2 2 1 2 2 1 3 3 3 2 3 1 2 1 1 3 1 1 1 2 2 1 3 2 3 2 3 1 3 2 2 2 3 1 3 2 2 2 3 2 3 1 2 3 1 1 1 3 3 3 2 3 3 3 3 2 2 1 3 1 1 1 2 1 2 2 1 1 2 3...

output:

886224409

result:

ok "886224409"

Test #24:

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

input:

8556 12 1
10 4 12 5 11 12 11 6 10 7 3 10 4 1 6 3 5 4 6 3 10 12 10 6 9 9 1 9 11 6 12 11 5 8 3 1 11 12 7 1 4 6 3 6 8 8 12 8 9 3 8 7 2 2 5 5 4 1 9 8 7 3 1 5 9 10 5 6 10 6 7 6 10 1 10 2 4 9 12 6 2 6 7 8 9 7 3 12 6 5 12 5 9 3 5 3 7 7 8 6 11 10 8 10 4 3 5 2 7 3 5 7 8 6 2 2 11 12 4 12 10 10 10 6 4 5 1 7 6 ...

output:

835287489

result:

ok "835287489"

Test #25:

score: 0
Accepted
time: 34ms
memory: 67560kb

input:

29076 14 1
14 12 7 10 5 11 7 12 1 14 2 7 12 1 14 13 9 10 13 1 14 2 10 11 5 4 8 13 8 1 5 9 5 10 1 4 9 13 10 9 12 6 7 2 14 13 11 3 6 6 4 6 11 1 2 12 6 1 12 1 3 8 6 6 3 11 4 10 2 10 11 2 5 11 13 14 12 11 2 9 4 12 3 4 2 2 14 2 10 8 11 4 5 11 2 7 11 1 9 13 2 2 12 10 5 4 5 4 4 9 9 2 7 13 12 2 14 6 12 3 4 ...

output:

428714926

result:

ok "428714926"

Test #26:

score: 0
Accepted
time: 7ms
memory: 34384kb

input:

21530 8 1
5 1 1 7 2 2 4 1 1 6 3 3 4 8 1 8 3 8 6 6 2 6 7 4 8 8 4 5 2 1 4 2 4 7 7 8 7 1 5 1 1 2 8 3 4 3 8 1 4 4 4 2 5 3 3 3 8 1 5 7 8 7 6 1 6 4 3 7 7 4 6 8 3 1 2 8 1 6 1 6 6 1 1 4 7 1 4 5 4 1 4 7 1 6 2 6 6 2 1 6 1 4 3 1 7 4 4 6 8 3 8 8 8 4 2 2 3 5 3 3 7 8 4 6 3 1 4 7 7 2 5 1 4 5 2 7 7 7 4 1 5 6 5 6 8 ...

output:

682167889

result:

ok "682167889"

Test #27:

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

input:

6134 7 1
6 7 4 4 2 2 5 2 2 3 3 1 5 4 5 6 7 6 7 2 1 1 5 3 1 6 2 2 6 2 5 2 1 2 4 7 5 2 6 1 5 5 1 6 1 3 3 3 5 5 3 7 3 6 2 3 5 3 3 4 6 2 3 4 3 1 3 3 7 1 5 6 2 7 3 7 4 7 7 4 2 2 3 6 1 1 7 1 3 4 5 3 6 4 2 7 4 6 2 1 5 7 1 5 3 5 7 1 7 3 2 1 5 7 6 4 1 7 6 1 7 7 3 1 1 3 1 4 5 5 7 4 5 4 2 1 2 2 3 1 2 4 2 6 1 6...

output:

479862425

result:

ok "479862425"

Test #28:

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

input:

5712 9 1
1 3 9 3 2 9 8 7 4 5 1 2 1 1 3 9 9 5 2 1 9 2 4 5 3 9 9 6 3 1 5 5 2 5 2 8 2 2 1 9 8 5 2 8 6 5 3 3 9 9 6 5 6 7 1 2 3 4 4 5 3 6 6 6 6 2 8 5 3 7 2 5 3 9 6 4 7 2 6 5 1 2 4 3 3 5 9 3 9 6 9 5 4 6 2 4 7 8 3 1 9 7 4 8 1 7 1 7 1 3 8 6 2 4 1 7 6 3 2 3 1 8 6 4 1 6 6 8 7 6 3 5 1 2 7 4 6 5 8 3 2 3 7 7 9 3...

output:

800069213

result:

ok "800069213"

Test #29:

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

input:

13882 10 1
3 7 7 2 9 8 8 8 2 10 4 9 8 2 2 10 6 7 9 9 9 2 1 7 8 3 1 6 3 5 5 4 10 6 7 1 9 4 7 5 6 10 5 3 3 5 1 4 8 5 9 10 4 4 9 3 6 7 2 9 7 4 4 4 7 9 2 2 1 8 6 8 7 6 6 6 6 2 8 4 10 8 4 9 5 10 6 4 5 1 8 9 7 3 10 3 4 2 10 4 5 9 4 5 4 2 4 2 9 7 6 3 2 3 5 4 5 1 9 4 9 8 4 5 9 8 8 7 8 9 2 5 3 8 10 8 8 7 7 1...

output:

840192715

result:

ok "840192715"

Test #30:

score: 0
Accepted
time: 31ms
memory: 63276kb

input:

30000 15 1
7 14 1 2 8 11 12 11 15 9 6 2 12 12 15 1 4 5 12 9 5 8 5 11 13 6 2 5 12 10 14 3 8 9 12 11 4 7 5 15 9 2 11 15 11 14 11 15 15 1 1 11 11 1 9 6 4 14 9 6 14 8 6 1 7 7 10 5 8 7 5 7 9 3 5 6 3 11 13 2 14 14 5 10 12 14 6 10 9 13 13 10 6 15 7 15 1 6 15 8 1 13 2 15 13 5 10 8 14 9 1 12 3 8 10 15 2 6 6 ...

output:

930560461

result:

ok "930560461"

Test #31:

score: 0
Accepted
time: 35ms
memory: 77432kb

input:

30000 15 1
11 5 10 8 7 7 3 11 9 13 14 7 12 7 2 8 14 6 6 5 12 13 4 2 2 12 14 10 8 14 12 10 6 11 6 15 3 5 15 15 11 15 9 6 4 3 13 4 1 14 7 10 6 15 6 8 15 15 10 3 7 9 7 6 14 14 11 5 11 5 11 13 12 7 6 12 3 1 15 2 10 8 7 15 10 1 2 13 9 1 9 6 3 4 4 5 2 1 4 7 6 14 2 5 3 2 4 8 4 6 12 14 9 2 15 15 13 4 5 5 12...

output:

486842491

result:

ok "486842491"

Test #32:

score: 0
Accepted
time: 39ms
memory: 73752kb

input:

30000 15 1
14 15 10 14 13 2 12 13 6 8 7 15 2 6 8 15 10 3 5 3 5 11 8 12 5 9 12 13 4 13 1 5 2 12 3 14 15 6 13 9 13 5 15 2 14 13 6 3 12 14 6 15 1 14 3 1 5 13 11 5 13 8 13 12 13 10 10 6 1 10 1 1 9 11 1 10 12 4 12 8 11 13 10 12 15 3 6 3 14 10 1 15 7 13 15 3 8 5 11 7 6 13 10 3 2 10 2 13 12 9 7 2 12 11 9 4...

output:

50307243

result:

ok "50307243"

Test #33:

score: 0
Accepted
time: 35ms
memory: 74188kb

input:

30000 15 1
1 14 14 11 14 13 4 13 12 10 8 3 3 10 11 6 9 8 4 5 4 10 9 6 4 6 9 5 14 4 10 12 2 4 15 2 8 3 12 7 4 13 14 6 9 9 4 11 7 14 4 13 8 7 11 9 14 15 5 1 3 15 5 15 1 8 4 4 15 6 1 4 6 14 1 7 5 11 5 4 3 7 7 11 3 8 11 3 6 8 11 8 3 1 9 11 7 6 14 6 8 11 1 7 15 8 14 9 15 5 11 3 11 12 6 2 4 2 13 12 14 3 7...

output:

630828146

result:

ok "630828146"

Test #34:

score: 0
Accepted
time: 41ms
memory: 70144kb

input:

30000 15 1
7 7 11 14 7 10 7 6 10 9 12 2 2 8 11 10 15 12 2 8 11 13 8 9 14 10 4 3 4 10 9 11 3 6 6 13 6 11 7 11 8 10 9 1 9 7 14 1 6 8 10 13 11 10 14 13 2 13 4 13 15 5 8 2 2 1 10 1 10 13 3 7 14 11 4 4 6 5 5 6 15 3 7 14 6 13 11 2 1 6 15 7 7 5 5 9 13 6 15 6 5 10 3 13 4 15 10 1 15 12 5 11 12 7 2 3 3 8 7 15...

output:

953149809

result:

ok "953149809"

Test #35:

score: 0
Accepted
time: 32ms
memory: 70192kb

input:

30000 15 1
14 13 9 7 2 8 9 2 6 1 10 6 3 4 8 15 12 6 15 9 12 9 11 5 4 4 12 2 10 7 12 5 14 10 4 9 7 7 8 3 2 7 5 1 1 9 1 9 11 13 12 9 8 14 12 14 3 13 5 1 1 9 12 9 13 12 2 1 12 1 1 7 7 10 2 13 11 3 10 15 15 12 1 13 9 2 3 3 1 12 5 5 11 15 15 5 12 12 4 13 5 5 4 2 2 3 9 10 6 5 8 4 1 1 14 6 4 14 8 8 3 15 12...

output:

54181826

result:

ok "54181826"

Test #36:

score: 0
Accepted
time: 40ms
memory: 70940kb

input:

30000 15 1
13 2 6 13 3 1 15 9 4 13 11 14 13 5 3 15 3 12 2 12 11 2 3 13 5 8 2 4 9 11 14 14 8 1 1 7 1 15 4 4 12 13 7 1 11 10 15 6 14 5 4 15 5 8 9 6 14 15 3 3 15 11 10 3 12 3 7 2 8 3 7 2 9 5 4 8 5 14 11 2 7 11 6 11 6 11 14 1 15 1 1 15 5 15 7 5 11 1 3 5 8 11 1 11 4 10 4 10 6 15 1 12 5 10 12 13 15 7 8 6 ...

output:

415874796

result:

ok "415874796"

Test #37:

score: 0
Accepted
time: 1ms
memory: 3764kb

input:

30000 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

1

result:

ok "1"

Test #38:

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

input:

30000 15 1
14 15 15 15 15 15 14 14 14 15 15 15 14 14 14 15 15 14 15 15 15 15 14 15 15 15 14 15 14 15 14 14 15 14 14 14 14 14 15 14 14 15 14 14 14 15 14 14 15 14 15 15 15 15 15 14 15 15 15 14 15 15 14 15 14 15 15 15 15 15 15 14 15 14 14 14 15 15 15 14 14 15 14 15 14 15 14 14 15 14 15 14 15 14 14 14 1...

output:

886986198

result:

ok "886986198"

Test #39:

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

input:

30000 15 1
15 15 15 14 14 15 15 14 14 14 14 15 14 15 14 15 15 14 14 14 14 15 14 15 14 14 14 14 15 15 15 14 14 14 15 15 15 15 15 15 15 15 14 14 15 14 15 15 14 14 14 14 15 15 14 15 14 15 15 15 14 15 15 15 14 15 14 15 14 15 14 14 14 15 15 14 14 15 14 15 14 14 14 14 14 14 15 14 15 15 15 14 15 15 14 15 1...

output:

668247064

result:

ok "668247064"

Test #40:

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

input:

30000 15 1
15 14 15 14 15 15 15 14 14 14 15 14 15 15 14 14 15 14 15 15 15 14 15 15 14 14 14 14 15 15 14 14 15 15 15 14 15 15 15 15 15 14 14 15 14 14 14 14 15 15 15 14 14 14 14 14 14 15 14 14 14 14 14 15 15 14 15 15 15 14 14 15 15 15 14 14 15 14 15 14 15 14 15 15 15 15 15 15 14 15 15 14 15 14 14 15 1...

output:

562849724

result:

ok "562849724"

Test #41:

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

input:

30000 15 1
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 1...

output:

673429076

result:

ok "673429076"

Test #42:

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

input:

30000 15 1
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 1...

output:

516022986

result:

ok "516022986"

Test #43:

score: 0
Accepted
time: 45ms
memory: 74168kb

input:

30000 15 1
1 15 1 15 1 1 1 15 1 1 15 15 15 1 1 15 15 15 1 1 1 1 15 1 15 15 1 1 15 1 1 1 1 1 1 15 1 15 15 1 15 15 15 1 1 15 1 1 1 15 15 15 1 1 1 1 1 15 15 1 1 1 15 1 1 15 15 15 15 1 1 15 1 1 1 1 15 15 15 15 15 1 15 15 1 1 15 1 1 15 15 1 15 15 15 1 15 1 1 15 15 15 15 1 15 1 1 15 1 15 1 15 1 1 1 15 1 1...

output:

115103138

result:

ok "115103138"

Test #44:

score: 0
Accepted
time: 61ms
memory: 76396kb

input:

30000 15 1
15 1 15 15 1 15 15 15 15 1 15 1 1 1 15 15 15 1 1 1 1 1 1 15 15 15 1 1 1 15 15 15 15 1 1 15 1 15 1 15 1 1 15 15 15 1 1 1 1 1 1 1 1 1 15 15 1 15 1 15 15 1 15 1 1 1 1 1 15 15 15 1 15 15 15 15 1 15 1 1 15 15 1 15 15 15 1 15 15 15 15 1 1 1 1 15 1 15 1 15 1 15 1 15 15 15 1 15 15 1 15 1 1 1 1 1 ...

output:

777366768

result:

ok "777366768"

Test #45:

score: 0
Accepted
time: 54ms
memory: 78440kb

input:

30000 15 1
1 1 15 1 1 15 1 15 1 1 15 15 1 1 1 1 15 1 1 1 15 15 15 15 1 15 1 1 15 1 1 1 15 15 15 1 15 15 1 1 15 1 15 15 1 1 15 15 15 1 1 1 1 15 1 1 1 15 15 15 1 15 15 15 1 1 15 1 15 1 1 1 1 15 1 15 15 1 1 1 1 1 15 1 1 15 15 1 15 1 1 15 15 1 15 15 1 1 1 1 1 1 15 15 15 1 1 15 1 15 15 15 1 1 15 15 1 15 ...

output:

879322138

result:

ok "879322138"

Test #46:

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

input:

30000 15 1
15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 1...

output:

354391629

result:

ok "354391629"

Test #47:

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

input:

30000 15 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

666493861

result:

ok "666493861"

Test #48:

score: 0
Accepted
time: 19ms
memory: 68124kb

input:

30000 15 1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1...

output:

640857910

result:

ok "640857910"

Test #49:

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

input:

30000 15 1
1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1...

output:

370646039

result:

ok "370646039"

Test #50:

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

input:

30000 15 1
1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1...

output:

553300345

result:

ok "553300345"

Test #51:

score: -100
Time Limit Exceeded

input:

23069 10 12025
4 2 8 7 5 4 10 6 5 10 1 10 1 4 4 10 5 7 7 3 5 5 7 4 7 2 6 8 9 2 7 8 2 7 3 7 9 5 10 2 5 10 9 10 8 10 9 3 4 1 4 6 5 5 10 7 1 7 2 8 2 3 8 8 10 9 9 4 1 3 7 5 1 1 4 7 3 6 9 8 7 6 1 7 8 1 7 9 9 8 3 4 8 6 4 8 8 8 7 1 1 5 5 10 9 1 8 8 5 10 9 2 3 10 9 2 7 8 10 5 10 10 8 6 7 8 6 8 9 5 6 1 10 10...

output:


result: