QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#346517#8306. Boring Problemhos_lyricAC ✓6ms4392kbC++147.9kb2024-03-08 17:04:422024-03-08 17:04:43

Judging History

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

  • [2024-03-08 17:04:43]
  • 评测
  • 测评结果:AC
  • 用时:6ms
  • 内存:4392kb
  • [2024-03-08 17:04:42]
  • 提交

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 <random>
#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 = 1000000007;
using Mint = ModInt<MO>;

// square matrix
using Mat = vector<vector<Mint>>;
Mat zero(int n) {
  return Mat(n, vector<Mint>(n, 0));
}
Mat identity(int n) {
  Mat a(n, vector<Mint>(n, 0));
  for (int i = 0; i < n; ++i) a[i][i] = 1;
  return a;
}
Mat inverse(Mat a) {
  const int n = a.size();
  Mat b(n, vector<Mint>(n, 0));
  for (int i = 0; i < n; ++i) b[i][i] = 1;
  for (int h = 0; h < n; ++h) {
    for (int i = h; i < n; ++i) if (a[i][h]) {
      swap(a[h], a[i]);
      swap(b[h], b[i]);
      break;
    }
    assert(a[h][h]);
    const Mint s = a[h][h].inv();
    for (int j = h + 1; j < n; ++j) a[h][j] *= s;
    for (int j = 0; j < n; ++j) b[h][j] *= s;
    for (int i = h + 1; i < n; ++i) {
      const Mint t = a[i][h];
      if (t) {
        for (int j = h + 1; j < n; ++j) a[i][j] -= t * a[h][j];
        for (int j = 0; j < n; ++j) b[i][j] -= t * b[h][j];
      }
    }
  }
  for (int h = n; --h >= 0; ) for (int i = 0; i < h; ++i) {
    const Mint t = a[i][h];
    if (t) for (int j = 0; j < n; ++j) b[i][j] -= t * b[h][j];
  }
  return b;
}

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


/*
  F[i](x) := \sum[n] Pr[end with T[i] exactly in n steps] x^n
  G(x) := \sum[n] Pr[yet in n steps] x^n
  
  force terminate by adding T[i]
  G(x) Pr[T[i]] x^M + \sum[m] [S[$-m, $) = T[i][0, m)] Pr[T[i][m, M)] x^(M-m)
  = \sum[j] \sum[m] [T[j][M-m, M) = T[i][0, m)] F[j](x) Pr[T[i][m, M)] x^(M-m)
  
  system for F[j](1), G(1)
  want (r.h.s) mod x^M |[x=1]
*/

char buf[10010];

int N, M, K;
vector<Mint> P;
vector<string> T;
string R;

int main() {
  for (; ~scanf("%d%d%d", &N, &M, &K); ) {
    P.resize(K);
    for (int k = 0; k < K; ++k) {
      int p;
      scanf("%d", &p);
      P[k] = p / Mint(100);
    }
    T.resize(N);
    for (int i = 0; i < N; ++i) {
      scanf("%s", buf);
      T[i] = buf;
    }
    scanf("%s", buf);
    R = buf;
    const int RLen = R.size();
    
    sort(T.begin(), T.end());
    T.erase(unique(T.begin(), T.end()), T.end());
    N = T.size();
    
    vector<vector<int>> fail(N, vector<int>(M + 1));
    for (int i = 0; i < N; ++i) {
      int y = fail[i][0] = -1;
      for (int x = 0; x < M; ++x) {
        for (; ~y && T[i][y] != T[i][x]; y = fail[i][y]) {}
        fail[i][x + 1] = ++y;
      }
    }
    
    vector<vector<Mint>> tail(N, vector<Mint>(M + 1));
    for (int i = 0; i < N; ++i) {
      tail[i][M] = 1;
      for (int x = M; --x >= 0; ) {
        tail[i][x] = P[T[i][x] - 'a'] * tail[i][x + 1];
      }
    }
    // sum in fail tree (exclude tail[i][0])
    auto tailSum = tail;
    for (int i = 0; i < N; ++i) {
      // exclude tail[i][0]
      tailSum[i][0] = 0;
      for (int x = 2; x <= M; ++x) {
        tailSum[i][x] += tailSum[i][fail[i][x]];
      }
    }
    
    Mat A = zero(N + 1);
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
        int y = 0;
        for (int x = 0; x < M; ++x) {
          for (; ~y && T[i][y] != T[j][x]; y = fail[i][y]) {}
          ++y;
        }
        for (; y; y = fail[i][y]) {
          // T[j][M - y, M) = T[i][0, y)
          A[i][j] += tail[i][y];
        }
      }
      A[i][N] -= tail[i][0];
    }
    // \sum[j] F[j](1) = 1
    for (int j = 0; j < N; ++j) {
      A[N][j] += 1;
    }
    
    const auto invA = inverse(A);
// cerr<<"A = "<<A<<endl;
// cerr<<"A^-1 = "<<invA<<endl;
    vector<Mint> ans(RLen + 1, invA[N][N]);
    vector<int> ma(RLen + 1, 0);
    
    for (int i = 0; i < N; ++i) {
      // change in i-th row
      int y = 0;
      for (int q = 1; q <= RLen; ++q) {
        for (; ~y && T[i][y] != R[q - 1]; y = fail[i][y]) {}
        ++y;
        if (y == M) {
          ma[q] = 1;
        }
        ans[q] += invA[N][i] * tailSum[i][y];
      }
    }
    
// cerr<<"ans = "<<ans<<endl;
// cerr<<"ma = "<<ma<<endl;
    for (int q = 0; q <= RLen; ++q) if (ma[q]) {
      fill(ans.begin() + q, ans.end(), 0);
      break;
    }
    for (int q = 0; q <= RLen; ++q) {
      ans[q] += q;
    }
    for (int q = 1; q <= RLen; ++q) {
      printf("%u\n", ans[q].x);
    }
  }
  return 0;
}

这程序好像有点Bug,我给组数据试试?

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 4036kb

input:

2 2 2
50 50
aa
bb
ababaa

output:

3
4
5
6
7
6

result:

ok 6 numbers

Test #2:

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

input:

3 3 3
25 25 50
abc
bac
cab
ababbabbcaaa

output:

13
333333343
333333344
333333345
17
333333347
333333348
20
333333358
666666692
23
24

result:

ok 12 numbers

Test #3:

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

input:

4 4 4
10 20 30 40
abcb
cabc
abbb
cccc
ababacabaabcca

output:

146386692
32395942
146386694
32395944
146386696
851050282
242422295
512573933
146386700
146386701
32395951
66073407
572924730
242422302

result:

ok 14 numbers

Test #4:

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

input:

2 2 2
50 50
aa
aa
bb

output:

7
8

result:

ok 2 number(s): "7 8"

Test #5:

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

input:

2 3 3
25 25 50
abc
bac
abcababababab

output:

15
8
3
4
5
6
7
8
9
10
11
12
13

result:

ok 13 numbers

Test #6:

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

input:

1 4457 3
37 22 41
acbaccbbbccabccabbbbccaacabbabcbcccaabcccaaabcbaaaabbbcbcaccbbabcabbaabbcaaccbbbcbcbbacacbbaabacacbbabacababbbacacbacbccacbbcccaaccbabccbbccacbaccaccbcccbbcbacacbbcbacbacacbacbbcccccaababaccbabaccaaccbcacbccccbcbaccacccaacbbaccbcacbbaaccbababbaabbcbccbbccabacbacbbaaaacaccabbbbcbabc...

output:

257013897
706585420
452854947
672362232
987922813
739511163
602517401
434363937
306393647
119706745
249738694
69345318
475227945
872961127
86944484
899631239
340163908
696393489
42891565
981519207
937086138
316517672
925504704
144826839
42714511
733038446
855651186
130426515
71204267
665495836
21507...

result:

ok 4457 numbers

Test #7:

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

input:

100 37 17
7 8 5 9 2 5 5 6 8 7 4 6 7 5 4 8 4
eplpljcadqaoebbgkdabfodaekoepjafgfodb
eplpljcadqaoebbgkdabfodaekpepjafgfodb
eplpljcadeaoebbgkdabfodaekpepjafgfodb
eplpljbadeaoebbgkdabfodaekpepjafgfodb
eplmljbadeaoebbgkdabfodaekpepjafgfodb
eplmljbadeaoebbgkdagfodaekpepjafgfodb
eplmljbadeaoebbgkddgfodaekpe...

output:

463555211
678912482
634869510
535538954
329950089
126338477
646172602
500945750
879005069
253238964
316179491
779160800
243831511
722071556
131725513
826960085
548675439
187112625
371517406
813081878
454087192
226853057
611308358
860027772
287179495
54161814
385276377
549609766
754594102
830435185
8...

result:

ok 3700 numbers

Test #8:

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

input:

1 10000 19
6 2 9 5 2 9 8 2 4 4 4 6 7 8 5 5 6 6 2
sdesdlsbjnaanfjkibodlmnkrabgkhjisqkdfhdifidfddjdiojpqksemffffsnensjcaodgikgmbamjqidihirjkfddaqjqlcefebomdjjdmjksaadfkpoqbpdbpcjfcgqjkcmcdmpkrodkkkkfqjdisjilrhcsfgskeesdipihpkglbpimpohlajbqlmnpdhbisglqcopqoggnmnjdorjprclcmdsamfsrogmelpococgehshmkncfsbm...

output:

429259559
429258610
429209611
426759562
379258613
262592952
95926521
762607535
762957536
100483574
616325592
213692480
734670392
933823724
43362082
781821169
243298187
131187789
467822929
200525661
283693538
635458346
6743560
866357934
714231284
845453787
238967138
550603441
462854741
109014824
4231...

result:

ok 10000 numbers

Test #9:

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

input:

85 1 19
4 4 2 4 6 3 6 2 7 6 9 6 8 3 7 11 5 2 5
r
o
r
k
k
p
k
c
m
h
n
p
b
d
l
p
o
f
m
r
e
g
s
s
s
g
q
o
d
j
i
e
n
h
b
b
i
g
q
e
f
a
c
i
j
e
p
g
g
h
g
k
n
b
d
o
l
s
n
q
r
h
g
o
j
k
f
g
k
h
k
o
b
a
s
p
g
n
r
a
q
d
r
g
d
gnrpccccngrchsfsbikqddglfdckmkoidagljjhehlgblpmqshpdirokdohchgrpsssmhbioqafqjrlamfmmr

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

result:

ok 85 numbers

Test #10:

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

input:

57 31 1
100
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
...

output:

31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100...

result:

ok 1767 numbers

Test #11:

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

input:

37 43 26
6 4 3 4 3 6 3 5 5 5 4 4 2 2 3 2 4 7 3 4 3 4 5 2 6 1
jdgtorokkcjwwrbzqydqxrwgwjeipinjfbaprwputzp
jdgtorokkvjwwrbzqydqxrwgwjeipinjfbaprwputzp
jdutorokkvjwwrbzqydqxrwgwjeipinjfbaprwputzp
jdutorokkvjwwrbzqydjxrwgwjeipinjfbaprwputzp
jdutorokkvjwwrbzqydjxrwawjeipinjfbaprwputzp
jdutorokkvjwwrbzqyd...

output:

358125216
251826312
265499079
936172860
469282651
190815901
290717459
566632257
464502134
979665611
867017109
582058605
960972795
214960660
672712128
253331830
631991323
867059381
975179945
678194000
102869776
527774656
875293632
106641115
452622830
326161274
672088806
761576516
387234576
759703534
...

result:

ok 1591 numbers

Test #12:

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

input:

9 289 14
7 4 5 13 7 8 7 6 8 4 7 9 6 9
lnfnmblcnabelnneaealjkbimnnahgdjbldcccbanfnfnfkahaaeklldhkfekndekkgnclikcmmcflkbekneiiehcnngcbffcnjaccejmnfcfdblejhnidkciamanggeekcelfabghhiinhnmcakhbhbfdmgakcefcnfigflmnnmiinjeclcljkjedlneahidmgedcjhenkcnimbmfndabhdbgkgdbiejmfkghhhmfhfkgcbhhihaldlefeifjeancglma...

output:

633994447
177204209
646338596
203250288
47517549
305405069
970655534
478327148
114234161
446942540
291029654
401163824
34641626
295506124
948460054
793026565
1119576
688162661
500451573
471172095
674546343
879973499
116803264
891326549
515454842
971208370
812914190
713799790
223342148
862770652
2656...

result:

ok 2601 numbers

Test #13:

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

input:

85 88 22
2 6 2 2 7 4 3 7 3 2 3 5 9 5 4 4 6 6 4 4 5 7
ctaegdvvureivpiimeulvomaqrduqbsjvdumhujmtndrukjqfriltnpjirvissucjehtkfvbnpgvrhsrglpieugl
ctaegdvvureivpiimeulvomaqrduqbsrvdumhujmtndrukjqfriltnpjirvissucjehtkfvbnpgvrhsrglpieugl
ctaegdvvureivpiimeulvomaquduqbsrvdumhujmtndrukjqfriltnpjirvissucjehtk...

output:

79154009
239558910
327775650
362544401
574934628
99536690
16952410
256050041
230483993
539362357
661461459
538836265
864089078
845963074
22223288
564230585
480915991
693120502
985470679
832474158
630344555
2349842
904463277
172109379
233118560
822632350
80562910
734318752
603274651
752539635
7419874...

result:

ok 7480 numbers

Test #14:

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

input:

57 74 20
6 4 4 5 9 6 4 4 5 4 6 8 6 6 7 3 2 4 4 3
grgmcgndoibsrajedtdtroipmhsbopgrboonpbaimnjpdjlibpdgalikfqgqtsjpgotbqgjqma
grgmcgndoibsrajedtdtroipmhsbopgrbooipbaimnjpdjlibpdgalikfqgqtsjpgotbqgjqma
gigmcgndoibsrajedtdtroipmhsbopgrbooipbaimnjpdjlibpdgalikfqgqtsjpgotbqgjqma
gigmcgndoibsrajedtdtroipmh...

output:

240420159
15162948
608989278
49905426
477551198
168695372
45006997
332156359
265222583
736468013
641615610
270305525
987553446
25974275
879272190
5442281
540861875
255142631
534868802
388706802
947585158
57062333
573262794
668506399
41856690
276332294
138222328
685473182
312605468
646595399
39479976...

result:

ok 4218 numbers

Test #15:

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

input:

37 110 6
14 17 17 16 16 20
eababeadaedbccacadddbcfdfeaedfdebfdfebffdecaebaebaffddcecbfcbacaabdbcbdfdbcfadcfcdfcdbcfffbfdfcfcfcaafcbcfdeea
eababeadaedbccacadddbcfdfeaedfdebfdfebffdecaebaebaffddcecbfcbacaabdbcbdfdbcfadcfcdfcdbcfffbfdfcfcfcaafcbcfdeea
eababeadaedbccacadddbcfdfeaedfdebfdfebffdecaebaebaf...

output:

477271943
865874261
924652387
468104942
820126987
429245152
91060264
279389171
716224831
779856663
988965712
942837344
318552819
763937990
177287759
285908218
48503684
727138806
218608280
290292510
950642023
540933241
609852504
496928305
389827816
887178657
222350611
705249031
22667914
18525855
9370...

result:

ok 4070 numbers

Test #16:

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

input:

9 364 21
7 5 3 8 2 3 3 6 8 6 6 4 4 4 3 6 4 6 5 5 2
eelshcjlkfmosjsmcetcbplieuquftdidqrcjbtmgkpiftepkmtrnohchhqkgmuioaarnhrhudfflqtlbptnneaifagbsujpqusrhpjrknsgfcdrmujjkrbffrtkhtjtgrolkmlicbsgnflsbdbjsnngucrfhjodeseosojeqsdscauhmcsnhnmksfghsttendagshttupcrcfkkfdlbfhjseiqepikaiugnqriqgbiskblsulhhapppq...

output:

648622903
648620404
648560455
647372956
294456288
509734073
333808223
778254616
809150547
332875789
754943694
859313974
862443137
545625807
588679801
150043825
362651650
350057068
677305973
271389696
144601015
581590399
972808614
200943432
264645881
449770811
677318839
83415966
808389314
843949621
5...

result:

ok 3276 numbers

Test #17:

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

input:

100 100 26
2 4 4 5 3 4 4 4 5 4 2 1 3 5 5 3 1 4 4 4 4 5 4 3 8 5
vlytafxjigoawreptwbqjqndwbenaeomoxyvnbzndakankigakldvalikfwzkicozqartlxxrvefjmocbodeegpziymgolrjiros
vlytafxjigoawreptwbqjqndwbenaeomotyvnbzndakankigakldvalikfwzkicozqartlxxrvefjmocbodeegpziymgolrjiros
vlytafxjigkawreptwbqjqndwbenaeomoty...

output:

939066444
939064465
1774545
506768603
558912820
435225332
477695351
404788573
253508582
800119342
778886516
930068631
714120376
315414012
150651118
658554661
926271079
619181456
941940913
226509576
125143928
546811452
93965875
37054379
388763942
181502930
353614696
230030688
487276587
879403098
7457...

result:

ok 10000 numbers

Test #18:

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

input:

100 100 26
6 3 2 4 2 5 5 2 6 5 8 4 3 5 3 3 3 4 2 4 4 1 5 4 2 5
xlgwhyuwmlqenemofspjjgaouuyehhmygypavlqovguchwxldbobtolitkipuxnsfkhoucfsekhjedxshdsiqtkofzdwbnoqvlpl
xlgwhyuwmlqenemofspjjgaouuyehhmygypavlqovguchwxldbobtolitkmpuxnsfkhoucfsekhjedxshdsiqtkofzdwbnoqvlpl
xlgshyuwmlqenemofspjjgaouuyehhmygyp...

output:

325314989
163822397
934885424
207035582
671874420
401331172
970252825
63493770
184326117
545126413
905414045
600356101
665559251
607616387
988413035
348301176
203466555
552689155
490838515
475207412
162585333
910143783
641809346
128178030
141423885
472570236
958165070
237906546
215421430
569121538
3...

result:

ok 10000 numbers

Test #19:

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

input:

100 100 26
4 3 4 3 7 2 5 4 3 4 2 4 3 5 5 6 5 3 5 2 4 3 4 5 2 3
tnipgajwsldqncyladeaueljawtosqmxxdcxhiyhqlctowrxzleatzjaxksvsvkhqbtvbflyevoafpjpjbegzpxbdsyzqpwhjjlu
inipgajwsldqncyladeaueljawtosqmxxdcxhiyhqlctowrxzleatzjaxksvsvkhqbtvbflyevoafpjpjbegzpxbdsyzqpwhjjlu
inipgajwsldqncmladeaueljawtosqmxxdc...

output:

384729772
376294560
495519872
721306519
737110570
767354746
255488403
458829895
858296880
529041667
356209884
805896617
799631195
62399453
141196169
601523874
109716391
45367220
403539189
318933546
44958144
683409494
315691050
963895679
169011261
296900927
128983135
7082636
823351383
148726185
67902...

result:

ok 10000 numbers

Test #20:

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

input:

100 100 26
6 3 3 3 2 3 6 5 2 3 3 4 6 4 4 7 2 4 3 3 4 6 3 5 3 3
nkmgbmdjppygejflnvrrddkvuazbldnccywhidathmvbmhwdqkabhyspdflvdqkkfygrgbnlbiwdqamhjdmbexvcwzuhwhkxggot
nkmgbmdjppygejflnvrrddkvuazbldnccywhidathmvbmhwdqkabhyspdflvdqkkfyglgbnlbiwdqamhjdmbexvcwzuhwhkxggot
nkmgbmdjppygejflnvrrddkvuazbldnccyw...

output:

876118314
542784171
987215564
828512208
955913888
206044080
540309699
349163554
348192796
620039099
673476774
165425452
341473696
54629971
159839173
969138980
201633959
301378914
507632405
663969621
137827170
266412228
751217569
127771838
167455389
398402210
952246677
413728745
316377919
884770232
9...

result:

ok 10000 numbers

Test #21:

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

input:

1 4457 3
37 22 41
ccabcbcccbbaaccaaccababbaaaaaccccababcbcaacacababbabbaabbabbbcaccbbaaacacabbaabacabaaabbccbbbcbacaaabbacbccaccbbcbbbbbcaaabbbcbbcccabccaacaabbcbabacaccabacacacccabcaaacaaccbbcaaaacbacaaababbcccacaabcbacaabbbccacabbccbcbbaacbabacbabaacbaacbacaaabcccbcbbabbabaccbccaacabcacacaaabcacbc...

output:

359793689
9407007
158353092
417547065
28317675
161288524
598418800
518248732
445606323
559812720
60545334
800190345
853284954
66702750
123819338
332440450
954228853
995834210
414383855
793425622
486058485
641861447
342584959
527691839
251937621
128277575
199466641
94572221
702965685
846411835
830426...

result:

ok 4457 numbers

Test #22:

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

input:

100 37 17
7 8 5 9 2 5 5 6 8 7 4 6 7 5 4 8 4
anapkpehbbfkmiggjpdmbfihjeebfadgoingp
imkogbpfalqnmgjlndmqaagjfhhlhjclcbelp
jeajfjgqdngebnmobbgcmmogqfahbnobapaie
blmmeiafcqikdcjbqaegoadfqfcbfpeblqnid
nqomacqbhlkpdeopbdeaqkohbkqehlqjedeja
ogkakinqedjgldllbldffmfmhfboglncidfmc
iefljidpebfhiimdqoqkhqoiaoen...

output:

244783730
541304300
460933998
160821932
829795403
508709898
94454602
881961229
994292530
605148655
426039055
477975743
200892881
843551206
821616819
648454900
914286531
573634223
16686384
423922904
28501229
645004152
119932337
682092460
925106381
573294964
217630409
859750786
971034111
275623527
349...

result:

ok 3700 numbers

Test #23:

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

input:

1 10000 19
6 2 9 5 2 9 8 2 4 4 4 6 7 8 5 5 6 6 2
nnnbnrpfbsejkllpedgbnckbnjqqpngfnqqgbnecqmsmqmipqbaremlijbilrqnljigpdofegrggmcmnohedkkbcrobddolqjjqbrchlsaobhoqoneomsmkghhiqcfaesjbmoscfhphmibckimsgindlnhggdppmdleokrhdcbjgcdgishknaadiqfksgnemribhabjlrahmqpnrsjgpnknmmimoabjpcfqaepapodkfphcoidrgqjcnbji...

output:

537858828
287858671
162856718
787761189
411638128
934180463
964291144
664884343
389133578
601595377
224685201
708517670
804329287
812366066
946312367
206929046
491368497
108051671
415269064
908369180
419237821
608736349
309796036
634717619
498593287
56219744
343873563
138103829
42758151
599099932
30...

result:

ok 10000 numbers

Test #24:

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

input:

85 1 19
4 4 2 4 6 3 6 2 7 6 9 6 8 3 7 11 5 2 5
r
g
i
r
r
n
k
c
j
k
c
o
m
n
s
n
r
f
b
h
e
l
f
a
o
b
m
m
k
b
e
d
r
s
g
o
s
f
d
q
c
a
d
m
o
i
o
q
n
d
j
b
g
p
i
j
h
q
h
f
f
h
e
c
g
j
j
l
e
p
m
j
g
s
f
g
p
g
n
i
p
d
o
j
l
honhkpspcgccehghpcadsnpslfierqpgdrslngdaokajkjeinhamblmgjseecalqibiepigqmhhmkdfbrmokk

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85

result:

ok 85 numbers

Test #25:

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

input:

57 31 1
100
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
...

output:

31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100...

result:

ok 1767 numbers

Test #26:

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

input:

37 43 26
6 4 3 4 3 6 3 5 5 5 4 4 2 2 3 2 4 7 3 4 3 4 5 2 6 1
whyvtnuokjggauxsyskzegukpelhggdsszfgoxltoaj
dzjncjqtmeaeliwsvomsopbzgbhqqjlxjdpicwrjpqn
zgwgopywmilgjrkkacwcckqrravluzblwiovjtpsfoa
lhoxdnwjsdxmbpkwhvzfvekqopmkoplzwmcpcciarwu
ajxpdkzxafsuqinpleepedhjfyiklsmcmcfwbijqpck
uqlycwsyumvozopxref...

output:

798095027
724887985
440596075
363832873
247094326
100022933
813440738
212955521
56826383
342516140
606183057
647890515
725408178
670433196
794628311
364527742
650898333
85399426
607215067
23410675
234769131
681282427
3712359
784105758
706012010
784730206
632968401
376935428
738264433
383935767
97228...

result:

ok 1591 numbers

Test #27:

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

input:

9 289 14
7 4 5 13 7 8 7 6 8 4 7 9 6 9
eehijddgnjhfbbfhdggdleagmefblhchmnhmignlnjedcbaablkbellcmaefhddhkihgnbknnlafdciaedefflgklnhbnmahielfkdajclnafacjlfeilfdfcjfnfceifnnkbldefbeimkmkknikjjbamialnliaajlbbkmkgiemajiifnnbhbgjjnfieaeffkjecninedfgedcbhaebjahmmjlkakgagfcanclnfgfccdgbjhgncehcgafanffaeleack...

output:

838253772
31176255
295477307
179293059
551392358
375268561
932792944
98565211
137095420
504925078
938256248
473690723
9314497
162234446
654581003
765854901
255749575
997945595
620717706
908540375
121285568
236106718
211737386
58258056
13249780
54444998
115825950
62694875
744013954
256403851
27279543...

result:

ok 2601 numbers

Test #28:

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

input:

85 88 22
2 6 2 2 7 4 3 7 3 2 3 5 9 5 4 4 6 6 4 4 5 7
hahrjdudoqpenkedfqvreudetoljgtchkbubaksimtuhbvfrpblvdeifllnentsprkuaqkflbajsltcojschhgqc
ghjgrgdejnqdcvusqklbndihcoggghmqqmtoruaopghquaeprevgrubejflgafabtjrdrvvaoomrmtscfchabmmd
rcrqkgdlgrvogigqtdohncueogdskteoqdhbiioklthjtsqjlbaispusvikrmjoenfood...

output:

546407474
574915123
421363876
927711218
842791950
253141056
819071160
136097917
56578987
789948529
449851525
905349981
349609017
792484377
748433115
897717285
928531100
431706687
210674650
59828095
733283908
277329637
912222082
83831230
930521129
744751978
981897931
995004045
393326914
157190123
347...

result:

ok 7480 numbers

Test #29:

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

input:

57 74 20
6 4 4 5 9 6 4 4 5 4 6 8 6 6 7 3 2 4 4 3
cegildidnpejgpplndefrhtscqdhlpqarrccpnasemrrjalsibctspsibhhptgkgfmpmjcnijr
njmlerocjmsccofigdmoictjjadakcqdhgqfnlctglahpakobnjcbrfbkipaorticaljskosji
shedcoafmbjoojrojonnltqmnfkjnbognljkddjnhqcoaeqqpookopfopqmdopgcdcprraktmh
caoecdafdplhgotdeabokrekle...

output:

528513323
31176464
17832335
194865553
731663104
326428756
311000735
556371553
569098739
549343391
589685669
102276847
279928740
470052188
473454182
984379412
518897476
811482329
120936585
840091721
834195785
538113721
484953891
205334364
452791478
518337784
503733384
398589612
840007513
769604974
14...

result:

ok 4218 numbers

Test #30:

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

input:

37 110 6
14 17 17 16 16 20
fdecefbccedcfbfbfabbbacbcfccdeaccafbbedfadbefebdedfaaddfadcfbdbfbdffafedcbfdddabdccddbbffeafefbebdebeddaeffbac
fffecbcaadbfcbceeefcbdfacbbcccbebdbbfdfcbcfccdcadccdbddbbcefbefdebdccdabcfabedfbdafaccfffdecadfbfdddadebcfeeaa
ddbbcbccfcbbefcbfeeccaadfeaebdeebaaedeffbffebfecdce...

output:

402318473
553349685
635848274
5158539
531775678
371155858
763588290
628337399
147034389
51205174
846940756
972996705
614728392
15380685
211856718
911087831
690392412
588808154
993415462
781392732
81017333
2921732
690686635
656273366
116320362
858881568
632753229
154862868
849797540
907453407
3322824...

result:

ok 4070 numbers

Test #31:

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

input:

9 364 21
7 5 3 8 2 3 3 6 8 6 6 4 4 4 3 6 4 6 5 5 2
rghjqcmsdjhkgrpjknmdnenptkrbrtqlnsbncujebgumeqrsajbtekhilhqtrasocdjndlqtukqggejecsefkbtpniddpqcupucbdllinethgishiefjejdpjcifseqjeqmpnicglinhejrlrgqjddmhjplffoaknrbnnbdgpmfqufdthneuojoqfnhodijrmgegpumtoekmmngpdpotseqafablbsbefffakfutigtgdqkigrarosbks...

output:

736084929
405687137
498918698
386111354
122945118
634360119
136427145
485259075
543960770
136812453
351007203
997853293
11289091
389626120
497762966
366848966
261882591
427218435
957884799
753891293
317443146
868876332
980221240
407820018
821250389
533397273
532663008
203637725
262103095
626745538
2...

result:

ok 3276 numbers

Test #32:

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

input:

100 100 26
2 4 4 5 3 4 4 4 5 4 2 1 3 5 5 3 1 4 4 4 4 5 4 3 8 5
lswtdpksrwdpkeduixieqckraujxhcsyqkoksuomgimydijkbvjqjgoffdcevgcnkpxcmzilrwdkttaorremzqpwvbhyebbtjoqg
chtrlsbfgggzpdcqegnzchjxjcalvolsocpbgurvxbnpjlguzbawudajgpucfqquefdolltqatwkcjxxcefjrwphcnmguyulgdeo
aheiwvkjlcrdmtfddwspmgnkyebwpfmkkip...

output:

911853969
248880073
128613708
224478233
373762134
875140027
507183676
579697754
622340128
546390207
594670695
238758477
688106106
787467832
802250620
125942682
78636136
246069397
858808019
719659309
923849216
634542995
633617957
822078721
198419329
450895846
658513779
679735736
405616140
759978324
3...

result:

ok 10000 numbers

Test #33:

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

input:

100 100 26
6 3 2 4 2 5 5 2 6 5 8 4 3 5 3 3 3 4 2 4 4 1 5 4 2 5
lvymgbsfappgfntjiojwlzxthhfenbadbiazxyvmosfywugupfmgmijpahqfdnyestbkemnltjvemcsygabnmglgzmvojweywqyn
xfejmczsyrdemdpvcdwdrahdwpwyzjorhmbkbvtzyrrvoczkhacyaoafrhzmdyjjhpmrolljknhoifwghndwjmazcebtwicywjtl
svehoynwfmlvzfhvmewtexggmpfsbgmqynx...

output:

484029879
147873503
832908008
181553381
355279880
744058749
97885868
527293394
453995224
693027156
600439860
138459133
188790777
326011753
740728831
644292353
113353194
62386240
26896766
841722320
402116112
796972489
133793356
120362698
162693974
453379245
820518684
696167335
100092309
309726984
923...

result:

ok 10000 numbers

Test #34:

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

input:

100 100 26
4 3 4 3 7 2 5 4 3 4 2 4 3 5 5 6 5 3 5 2 4 3 4 5 2 3
diwiopmavekcpsuitkttqtnkxubkoimgczrztukaplqhtojxctunphpyulgrpfwryalxxjuaxihahrsqqbwvfigifzrybgwghcpp
ixkdcvheefwexjzfygztbznhrakwlxsmvieceoongzfuynwyjufxdzhxehnxwfxezfxxwkwshujsbqjxdyiblzzxewxzeagxteyk
yslrkdnhswandxjpjbpkhgtgydofmfaxnox...

output:

310436147
28926802
242704102
911882509
234750995
44255911
929563992
705145134
729332632
814011899
92351203
71227216
206867002
578981360
512260031
329303527
952690308
298516837
626503751
342849009
405751686
229495670
501458984
522495462
737336911
280189836
8908072
342764052
58237703
353043500
7729784...

result:

ok 10000 numbers

Test #35:

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

input:

100 100 26
6 3 3 3 2 3 6 5 2 3 3 4 6 4 4 7 2 4 3 3 4 6 3 5 3 3
atlljpayehbruynoylsvsovrtlsgoocrdpothobrvwblhrsugljmbjmaqunbqbvjtherfwboqnddtusyijgfnmvlhfzwbckmkxmr
frbbtzriophiecrfxmastzwrlbdnhqvcoseuhghtfllugibwxvoloofsuaxjjogmfwpbbngvedgsboskemduoaqyweookmncqgoi
gaoffxokikzdqvwntsceeykguqywaspmllk...

output:

574910644
945791448
720045395
61883744
478564693
911474585
669594991
400154930
51117755
985226108
526685795
430903337
365340791
262612491
266303796
867100241
587617435
547561350
191088980
877963268
518977788
147964347
509932359
163158361
246577780
239703262
595819196
896524557
323666385
304929385
43...

result:

ok 10000 numbers

Test #36:

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

input:

100 100 26
3 3 3 4 6 4 2 6 5 5 6 3 3 4 4 2 6 5 1 2 2 2 6 4 3 6
obazcvuxnwxksqskbdczkihfncodirkvagjhckpqfhuuiirugrfliepjkzamkhxjdlkwgtfdynoqofwrsnkjpsmvwarswiuqhezt
qjdwfovuvdwmkfbpttcmzgyzovjhqednbrdencyhjodwrscsnlvgyqqnislckrukxibdnvzefkibuibbeymdinkwvaguovunrspl
qljpgkodvcovujylulougobkhflnlzcbbms...

output:

703569928
594791029
798472025
60498550
109898822
359808055
790941689
2674190
819094046
468371015
103029382
464469838
911832388
335405298
341071524
326081199
551746353
125367716
665986505
201587181
287415328
165860251
642099999
68379375
472620539
677046819
950690792
488494208
536038444
686876814
3469...

result:

ok 10000 numbers

Test #37:

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

input:

100 100 26
5 5 2 4 2 4 5 2 7 3 4 3 5 4 3 4 3 4 1 5 3 4 5 3 5 5
khwdlyflkltwnfjkltvkjgdsawcpxqkkkrghsfodxnojsksocmahnqsdlbtdqhiftjhvgcbejqhtreiwfohnpoimwqbdzywbmwts
mljcadkhfahhqfdacxuphvfbkdpbmfwaelttitidolbaoiwmyoefpkwydkrueblwuwkfqtgdknetsooswdmhzkdyqtxcopwhefqa
ldlbgrlesrdwgtrvegteorgsfexrsmwkuzq...

output:

111682350
583428123
885947075
85464636
514331544
248238548
198425075
198814911
933427173
545105828
272889524
734932393
473614399
184018870
797320468
777009533
816997527
710723336
214065880
549439210
888245025
165145672
383742311
646237992
506838185
534041939
797369947
976609370
748367186
377018340
1...

result:

ok 10000 numbers

Test #38:

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

input:

100 100 26
6 5 2 4 2 6 4 1 3 5 3 5 3 1 7 5 5 5 2 3 4 3 6 4 4 2
hbmqbihgtapswykfvlgdoapjqntvqsaohmbvnphvyyhvhavslamczuqifxnwknkaenqmlvetrqogqxmlptgrmqvxzdxdmwobjesm
xckpmawtioavwdngyiwkzypfnxcovwzdohshwlavwsthdssiadhiwmhpvgkrbezmmdvlrxsqpugctmejvtzmfbbwpptfsdecfwvr
nsgpoelbfbzslptyazbzrzlwjoridtjzjwv...

output:

957687827
50829989
203828647
408223376
205707566
8360496
447759588
692117680
544020096
759933120
487869792
16747316
279778855
174933925
706017903
211865866
16993529
137965792
327121777
993610041
75991053
341960533
128417880
29440704
838335182
613244081
365831750
319010732
476891714
329156825
5291171...

result:

ok 10000 numbers

Test #39:

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

input:

100 100 26
1 5 5 5 3 1 4 4 6 3 2 4 7 2 3 4 5 6 2 3 5 2 3 7 4 4
vebyvirakdfqcezlfqwmqswnuwgnnglrqhxlyzumfjseddelhjpndvkotgyylwrwuygghmeqsztjuwmslxeyztwabrntqwchmzpa
uxgnhacywgzlhebktoxmnuupeqvmrmdtkrvrndobvmzvlvyucjutdxxogdhysgjulufkizjpicexuckwpzubhcoxhxkyhtllctlx
hanzbclwwpvaubcvoqakzrosjguwrjyoebe...

output:

446188597
946273695
157282484
479904298
410211424
380890251
407865814
167910136
765453911
136222040
530458231
229914343
691852906
942621706
923384325
331381199
546453734
549824289
360973955
682813309
890430814
195519430
470147805
936725810
329623287
611249301
455999468
799259160
862100038
185996181
...

result:

ok 10000 numbers

Extra Test:

score: 0
Extra Test Passed