QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622761#5551. Selling RNA Strandsmakrav100 ✓333ms375396kbC++205.2kb2024-10-09 02:56:312024-10-09 02:56:32

Judging History

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

  • [2024-10-09 02:56:32]
  • 评测
  • 测评结果:100
  • 用时:333ms
  • 内存:375396kb
  • [2024-10-09 02:56:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second

struct trie {
    vector<vector<int>> nxt, leaf, qrs;
    int siz{1};
    trie(int x) {
        siz = 1;
        nxt.assign(1, vector<int>(4, -1));
        leaf.assign(1, {});
        qrs.assign(1, {});
    }
    void add_word(vector<int>& s, int wi) {
        int v = 0;
        for (int i = 0; i < s.size(); i++) {
            if (nxt[v][s[i]] == -1) {
                nxt[v][s[i]] = siz++;
                nxt.pb(vector<int>(4, -1));
                leaf.pb({});
                qrs.pb({});
            }
            v = nxt[v][s[i]];
        }
        leaf[v].pb(wi);
    }

    int find_word(vector<int> &s) {
        int v = 0;
        for (int i = 0; i < s.size(); i++) {
            if (nxt[v][s[i]] == -1) return -1;
            v = nxt[v][s[i]];
        }
        return v;
    }
};

struct fenwick {
    int n;
    unordered_map<int, int> t;
    fenwick() = default;
    fenwick(int n_) {
        n = n_;
    }

    void clear() {
        t.clear();
    }
 
    void upd(int p, int vl) {
        for (; p <= n; p = (p | (p + 1))) t[p] += vl;
    }
 
    int get(int p) {
        int sm = 0;
        for (; p > 0; p = (p & (p + 1)) - 1) sm += t[p];
        return sm;
    }
};

void solve() {
    int n, m; cin >> n >> m;
    trie tpref(1), tsuff(1);

    vector<char> alph = {'A', 'G', 'C', 'U'};

    auto tow = [&](string s) {
        vector<int> word(sz(s));
        for (int i = 0; i < sz(s); i++) {
            for (int j = 0; j < 4; j++) {
                if (alph[j] == s[i]) word[i] = j;
            }
        }
        return word;
    };

    vector<int> ans(m, 0);
    for (int i = 0; i < n; i++) {
        string s; cin >> s;
        vector<int> wrd;
        for (int j = 0; j < s.size(); j++) {
            for (int k = 0; k < 4; k++) {
                if (alph[k] == s[j]) wrd.pb(k);
            }
        }
        tpref.add_word(wrd, i);
        reverse(all(s));
        wrd = tow(s);
        tsuff.add_word(wrd, i);
    }

    for (int i = 0; i < m; i++) {
        string pr, sf; cin >> pr >> sf;
        vector<int> PR = tow(pr), SF = tow(sf);
        int vt = tpref.find_word(PR);
        if (vt == -1) {
            continue;
        }
        tpref.qrs[vt].pb(i);
        reverse(all(SF));
        vt = tsuff.find_word(SF);
        if (vt == -1) continue;
        tsuff.qrs[vt].pb(i);
    }
    vector<pair<int, int>> gs(m, {-1, -1});
    vector<int> vts, pos(n);
    auto dfs1 = [&](int v, auto&&self) -> void {
        for (int ind : tpref.qrs[v]) {
            gs[ind].first = sz(vts);
        }
        for (int ind : tpref.leaf[v]) {
            pos[ind] = sz(vts);
            vts.pb(ind);
        }
        for (int j = 0; j < 4; j++) {
            if (tpref.nxt[v][j] != -1) self(tpref.nxt[v][j], self);
        }
        for (int ind : tpref.qrs[v]) {
            gs[ind].second = sz(vts);
        }
    };
    dfs1(0, dfs1);

    vector<vector<int>> sub(sz(tsuff.nxt));
    vector<fenwick> fw(sz(tsuff.nxt));
    auto dfs2 = [&](int v, auto&&self) -> void {
        int sons = 0;
        for (int j = 0; j < 4; j++) {
            if (tsuff.nxt[v][j] != -1) {
                sons++; self(tsuff.nxt[v][j], self);
            }
        }
        if (!sons) {
            fw[v] = fenwick(n + 1);
            for (int vt : tsuff.leaf[v]) {
                sub[v].pb(vt);
                fw[v].upd(pos[vt] + 1, 1);
            }
            for (int ind : tsuff.qrs[v]) {
                if (gs[ind].first != -1) {
                    ans[ind] = fw[v].get(gs[ind].second + 1) - fw[v].get(gs[ind].first);
                }
            }
            return;
        }
        int bs = -1;
        for (int j = 0; j < 4; j++) {
            if (tsuff.nxt[v][j] != -1 && (bs == -1 || sz(sub[bs]) < sz(sub[tsuff.nxt[v][j]]))) bs = tsuff.nxt[v][j];
        }
        swap(fw[bs], fw[v]);
        swap(sub[bs], sub[v]);
        for (int j = 0; j < 4; j++) {
            if (tsuff.nxt[v][j] != -1 && tsuff.nxt[v][j] != bs) {
                int vb = tsuff.nxt[v][j];
                for (int V : sub[vb]) {
                    sub[v].pb(V);
                    fw[v].upd(pos[V] + 1, 1);
                }
                fw[vb].clear();
                sub[vb].clear();
            }
        }
        for (int vt : tsuff.leaf[v]) {
            sub[v].pb(vt);
            fw[v].upd(pos[vt] + 1, 1);
        }
        for (int ind : tsuff.qrs[v]) {
            if (gs[ind].first != -1) {
                ans[ind] = fw[v].get(gs[ind].second) - fw[v].get(gs[ind].first);
            }
        }
    };
    dfs2(0, dfs2);
    for (int i = 0; i < m; i++) cout << ans[i] << '\n';
}

signed main() {
    int tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false); 
        cin.tie(0); cout.tie(0);
    #endif

    while (tt--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 10
Accepted

Test #1:

score: 10
Accepted
time: 1ms
memory: 3668kb

input:

100 100
A
G
AGC
AUA
C
CCA
CGGAG
CCGAG
GACA
UCAAC
CUUAU
AC
A
CGUA
UAUG
UGCGA
GCU
GUUAU
UAAU
A
UAA
U
CGCCC
GCG
U
AUUC
GACA
CC
AG
GUCGU
UUCA
AGGC
G
CU
UG
CUUA
CUAU
AA
A
GUUG
GGU
UU
C
GCUG
C
GUGGA
C
UAU
UAG
GC
GUU
GC
UCUCA
U
AA
AG
C
GGU
GC
CCUG
CCUU
GG
CAGCU
UAGGU
GGCUC
CUACG
UGC
UU
UAAUG
UGGCA
CAA
UGAG...

output:

9
1
11
1
1
2
4
3
11
6
1
2
1
1
4
2
1
11
10
1
5
1
1
1
1
11
1
13
1
1
3
1
11
1
11
11
1
2
2
1
1
10
1
1
1
2
4
2
1
13
10
1
1
1
2
1
1
4
1
2
1
1
9
9
13
2
1
2
9
2
1
10
2
2
1
9
1
1
1
1
1
1
1
9
1
1
11
11
1
1
1
1
2
13
1
2
1
13
1
1

result:

ok 100 lines

Test #2:

score: 10
Accepted
time: 1ms
memory: 3668kb

input:

100 100
U
CUAG
AUCA
UAACG
U
GG
CUCCA
G
G
UGCCA
CGA
ACAAU
GUUA
GUAGA
AUCU
C
GC
ACACG
UUG
CCC
U
UUGUC
AUC
GAA
U
CGGA
U
AGA
GCU
AAG
CUA
UCGG
GGG
UCG
GGAU
U
CGA
CCAUG
ACG
G
C
CUU
GUCU
UUAU
UACU
UCC
UGAAG
GCAAU
CUCG
GAG
U
ACC
CUAU
CU
UU
AAGUA
AGGU
CGAA
U
GCU
AA
CAA
G
UAGGG
A
UCU
A
AA
G
UAC
GC
CAC
AGUGA
U...

output:

1
5
1
8
14
1
5
1
12
1
2
2
12
1
1
6
8
1
1
4
5
2
1
1
3
1
1
1
2
2
1
1
2
1
1
14
1
1
1
1
2
1
2
1
1
14
1
1
2
8
1
14
2
12
1
1
1
7
1
2
1
1
12
5
1
1
1
2
12
1
1
14
2
8
1
1
1
6
3
1
2
1
5
12
1
1
1
1
3
1
1
12
14
1
14
1
4
1
2
14

result:

ok 100 lines

Test #3:

score: 10
Accepted
time: 1ms
memory: 3944kb

input:

100 100
GACC
CACCU
GGCC
UGUA
UCAG
UUUGU
GU
AGUAC
ACUG
UAGAG
UCAA
GGCA
G
GGUU
CGA
A
G
UUUGG
CGA
UG
AU
GAC
AA
GGGA
AGA
AC
AGCAG
AGU
A
UUUAA
G
UGC
ACGUC
A
AUAAA
UAAAA
CGU
AUGAC
GAUA
UGUCC
AACU
AAUA
CUAA
C
CG
G
GGC
UGACC
AUGU
U
UA
GAAUA
AG
UA
UGGAC
AAG
CCGC
UA
CGCAA
A
CCG
UAAAA
GAG
CGG
UA
GAUG
GGA
UCAUU...

output:

2
4
9
9
1
3
9
1
6
11
1
1
1
1
1
11
2
1
2
9
4
5
1
2
1
11
3
1
4
2
1
1
9
1
11
1
11
4
11
1
2
9
1
1
1
1
1
1
2
1
4
1
1
4
9
9
3
11
1
1
1
1
3
5
6
1
2
1
4
1
2
2
6
9
1
1
5
1
4
3
2
1
1
4
10
1
2
1
2
2
11
2
1
1
2
3
1
1
1
1

result:

ok 100 lines

Test #4:

score: 10
Accepted
time: 1ms
memory: 3956kb

input:

100 100
CCG
UAAUA
AGUUU
GAG
GUAGC
A
AAUC
UC
ACCC
A
U
UCGG
AG
G
AG
AC
AAGAA
GCGAU
CGUC
G
AG
UUAAU
CGUGU
GUCG
A
UA
AU
GAAAC
AUG
CGUG
ACGG
G
C
AUG
GAUU
ACGG
GGA
CU
UG
U
AAA
C
UAUGU
UAC
CUA
ACC
CGAUG
GCC
UACG
CCA
UAAU
UUAAA
C
UA
GACA
UUGUC
AGCU
UCCA
AAAA
CUUA
GU
UCCGA
C
UUU
AG
UC
UAAU
GGG
CUCCC
C
UUU
UG...

output:

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

result:

ok 100 lines

Test #5:

score: 10
Accepted
time: 1ms
memory: 3660kb

input:

100 100
CAGAA
CU
GAUCU
AAAC
AUGGG
CCUAC
G
C
A
UC
UUCAU
GUCAA
UUA
GG
UG
GCU
GGGCU
UUUA
CAG
G
G
AAUU
ACAU
AUAC
UA
C
UUCC
CA
CUC
A
UA
GGUC
UGG
AGG
GUUCU
AA
ACCC
CAUG
CGCA
A
AU
GAGGU
GG
UCU
AA
AGUC
AGC
AACUA
CUGAC
GGACU
CCGG
AGGA
GAG
UAAG
GA
ACGA
A
UCUGG
CAG
GCAA
GAG
CC
UAAUC
UUGA
AG
U
GGG
AAACG
UA
ACGA...

output:

1
1
13
1
1
1
2
2
1
2
1
1
2
1
8
8
8
1
2
2
4
2
2
2
2
1
3
2
1
2
4
1
1
5
13
4
1
6
13
2
2
10
1
2
2
2
1
5
10
1
1
8
8
8
1
10
1
1
4
3
2
10
3
1
1
5
2
1
5
1
2
3
1
6
1
1
13
1
10
2
2
1
1
1
1
13
3
10
3
2
1
1
2
2
2
5
1
2
10
1

result:

ok 100 lines

Test #6:

score: 10
Accepted
time: 1ms
memory: 3612kb

input:

100 100
UG
G
AA
GA
G
ACAC
GGAAG
GAGU
UG
UUAA
UG
U
AGUUA
CA
C
G
CCCG
U
UAAG
UCUG
CGGU
A
CAC
ACGA
CA
A
UC
GAAUC
A
GAGG
GG
GGG
CCCUC
GACGU
GGUG
GCG
CCAG
C
AUAU
A
AG
UGU
UCGC
UC
AUA
ACGCC
A
GCUA
CCU
G
AGC
GG
GCAUG
GGGUG
C
CCCC
GG
A
AG
AC
UA
CACG
AU
GAG
G
GG
GACC
ACAAC
GCGUG
C
GAA
C
UGCU
GC
ACGGA
AUG
GCA...

output:

14
1
7
5
1
4
7
1
24
4
14
24
1
4
7
1
1
24
1
1
1
4
7
6
3
1
14
4
1
1
1
7
7
6
14
1
24
1
9
1
1
24
7
24
14
9
1
1
1
1
7
9
24
24
7
5
1
3
24
1
1
24
1
3
2
1
9
4
2
2
1
14
7
5
14
14
1
1
2
2
4
24
2
14
1
1
14
3
9
24
7
1
1
4
1
24
9
5
4
14

result:

ok 100 lines

Test #7:

score: 10
Accepted
time: 1ms
memory: 3660kb

input:

100 100
AG
ACACC
GAG
GG
C
AC
AGCA
AAUGU
AGU
UUA
UG
UAC
UU
U
G
G
CUAA
CCG
AAGU
G
CAAU
CCCUA
CCG
G
GACAA
C
CCCAA
UUUCG
UG
C
AAUGC
GCA
A
C
AAUCC
UCGC
UG
GU
GUAUG
CUGG
UUCA
AC
AACU
UA
GAAG
CGGC
ACU
GUAAU
GGGGA
UGAUU
GCA
CUGAG
CUA
UUGGU
GC
CCA
GCAU
AC
U
GG
UGCA
CUACC
GAUAC
UACG
CAUC
GG
GAG
CAU
AUAA
UUA
C...

output:

2
6
1
1
2
13
1
1
4
1
3
2
2
1
1
6
13
1
1
6
2
11
1
4
1
1
8
3
4
1
1
2
2
1
6
1
1
1
3
11
2
2
2
1
1
6
1
6
1
1
8
1
1
1
3
1
2
2
1
1
4
8
1
1
13
1
3
2
1
1
11
3
13
1
1
11
1
4
2
1
13
2
6
11
1
1
6
3
1
1
13
4
3
6
11
6
3
1
1
2

result:

ok 100 lines

Subtask #2:

score: 25
Accepted

Dependency #1:

100%
Accepted

Test #8:

score: 25
Accepted
time: 261ms
memory: 375396kb

input:

2000 2000
ACUGGAACAGAAUCGUUCGAAUCAACAUUUCCCUCGCUUUUGGCUCCCCUCAGUAAUCUUUGUAGUACCGGCCUUCGCGAUCUGCGGCCAUCCCCUCCCAGUUGUUCGAGUUAGGGCAUGCUCUGCAGCGUUGAUUCAGUC
ACUGGAACAGAAUCGUUCGAAUCAACAUUUCCCUCGCUUUUGGCUCCCCUCAGUAAUCUUUGUAGUACCGGCCUUCGCGAUCUGCGGCCAUCCCCUCCCAGUUGUUCGAGUUAGGGCAUGCUCUGCAGCGUUGAUUCAGCAGAUCCUA...

output:

10
54
331
2
46
42
51
21
6
200
111
211
34
70
7
4
1
57
3
9
351
182
3
65
11
3
25
65
101
24
71
310
62
13
294
2
32
139
18
390
14
78
23
299
47
29
1
7
18
95
32
37
39
53
45
18
288
10
76
75
74
3
24
67
31
9
8
3
77
209
20
40
41
34
10
31
12
14
38
199
22
31
164
35
101
11
26
4
4
9
9
25
13
52
12
99
75
214
7
42
53
...

result:

ok 2000 lines

Test #9:

score: 25
Accepted
time: 252ms
memory: 358540kb

input:

5000 5000
AGUGUGCCACUCUAGAAUCCAAGACAGCAUAACUCUGAUCCCGCUAGAUCGUGCAGCCCCGCCGAGAGCAGCGUAGUAGGUCAGUCAUAGGGCUAGACUGAACGGGUACCGCAUACGGUACCAUUGACGGCUGGACCGAUUGCUCCAAGAACGCAAAAGCGUUAGUUGCAUACGGUGAAAGGCCGCCCUGAACGCCACCUUGCAUAAACCGACUACGUCGUAAGAACUGUCCUAGGUAGUGGAACAUCGCAUAUCUAUGCUCGCGUCAGUAUAACUUUGGCUGACUGGUC...

output:

213
82
24
19
271
71
25
167
34
34
17
7
18
14
40
39
33
53
487
126
50
1005
283
30
69
6
327
48
107
103
17
48
15
259
321
41
9
84
34
244
217
41
556
73
42
117
3
122
6
179
261
21
10
61
199
114
265
95
37
30
163
30
113
66
7
152
119
39
3
77
58
458
18
28
12
383
43
224
31
214
11
25
96
127
387
82
253
90
323
6
246...

result:

ok 5000 lines

Test #10:

score: 25
Accepted
time: 189ms
memory: 208984kb

input:

3200 4998
GGCCGAUAGGAACGUCUUCCUUCUAAACCACAGGUCUUUUGACCGCUGCUACCCCAUUCGAUAAAGUAGUCCACGG
AGUAUGUACGGCUCUUACAAUAAAAGGUAUCGGGAUGUGUAUGAACUGACCGCAAGAUCGACAUGUUCGUCUGCACUUCUAUGUUCGUAUCUCUGAGCCACGCGGUUGCCCGGCGUUAGCGCCGGUCACAGUCGAUUUUGACUAUAAUCAUUUUGUCCUGUUGAACAUAAGCACUGCAAUGCACGCGAGAGGGUGGGGCACGCUGUUCGGCAG...

output:

68
21
24
176
183
41
30
360
95
163
136
119
245
23
21
54
11
148
19
43
16
46
572
106
111
8
415
18
66
97
382
401
186
515
188
169
168
13
142
22
19
221
246
19
417
316
232
16
232
314
124
412
735
53
667
239
111
35
148
115
12
545
276
73
551
405
74
7
120
221
25
17
15
239
346
39
185
27
92
549
380
350
425
22
10...

result:

ok 4998 lines

Test #11:

score: 25
Accepted
time: 185ms
memory: 195984kb

input:

5000 5000
UGGACUAGCUAAACUGUGGAACAUUCUCUAGCUUAUAAUGAUUACCAGGCACAUCAUUCCGUGCGGUUGGAGGUUAGGGACCCACAGACCUCCUAGAUCUUUCCGUUGAACAAUGACACUUCCGCAGUGUUUAUCUACGGAGAUCACCACUUAUUGUCACCUACGUUAAUACUAGACCCACAGUGGCUCAUAAACGGUCUAGCUCCGCGCCAUCAUAACAGGCAGUUAGUCGUAGAUCUGAUAAGAGCGUCGUAGAUCGGGGAAGCGAUUCGAGCCAGCCACAUUUAUAC...

output:

18
495
27
467
43
132
61
80
121
60
10
325
235
136
116
939
5
53
72
58
852
151
28
39
26
440
421
84
70
26
186
458
169
8
163
53
720
376
21
40
145
123
18
64
123
64
109
196
18
31
108
166
433
8
102
386
266
5
158
104
160
283
191
798
166
48
19
631
567
8
21
80
5
329
403
5
11
55
8
89
78
14
33
52
1126
46
19
666
...

result:

ok 5000 lines

Test #12:

score: 25
Accepted
time: 333ms
memory: 361376kb

input:

5000 5000
GGUUAAAUAAUGGUAGUUCUCAAUGGUAGGGUUGUUCCUUAGCUUCGGCGUAGGUUGUCUACAGGUGUGGGGCGGCACCAUGCUGGGCCCGUAGAACGGACCGAAUCGUGGGUGUGAUUUGCAGUAACAUCUGCGGCUAACAAGGAUCGCUAACUUUUAAUCUCAGUACGGAUCGAUGUAGCUAGCGGUUGACCAAUUCCUAUAUCUUCAAUACCCACCUUCCUCUGGGAUUAAUUAACUAAGAGGCACAUCUCAGGUGCCAACGACUUGCUACCCAGUUUCGCUAGACG...

output:

1
1
1
1
1
1
1
1
1
348
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
323
1
75
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
308
4
1
1
1
1...

result:

ok 5000 lines

Test #13:

score: 25
Accepted
time: 316ms
memory: 371472kb

input:

5000 5000
GGUCGCACAAAUCUCGGAUAGGAUACUUCUGCACAGCUGGUGGCUAGCUGGGCUAGCCGGCCGCCGAUGGUUCAAGUUCGGCCAGUUCACCCUAACCCAAGACAACCCGCAAUGGAGGGAUACAGGACGGCUGGCCAGGUUCUCGAGCUUAUCU
GUUAUACUUGUUCCUUGGUAGCAUAGUGGCAUUUGUCGUUAUCGGUAAUUCUUAUUAUACUCGCAGGUGUCUCUCCCUUGGACGGGGCGCGGCCAAACGAAGGAUAAGCGA
GGUUUAUAAGAAACCUUCAGCGA...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
6
1
1
1
...

result:

ok 5000 lines

Test #14:

score: 25
Accepted
time: 67ms
memory: 4928kb

input:

1731 5000
A
AA
AAA
AAAA
AAAAA
AAAAAA
AAAAAAA
AAAAAAAA
AAAAAAAAA
AAAAAAAAAA
AAAAAAAAAAA
AAAAAAAAAAAA
AAAAAAAAAAAAA
AAAAAAAAAAAAAA
AAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAA...

output:

1155
635
1170
1270
1379
723
678
999
1248
974
1314
752
1719
1304
1717
1651
1485
640
1528
587
1445
1710
1054
987
1448
544
1508
1006
1114
1213
1490
1034
720
617
1666
959
1695
1580
851
1484
675
1118
1375
844
951
1183
1622
1417
1028
933
749
1008
1475
563
1423
1638
1154
689
1243
990
640
1567
1606
550
1237...

result:

ok 5000 lines

Test #15:

score: 25
Accepted
time: 246ms
memory: 217620kb

input:

5000 5000
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
...

result:

ok 5000 lines

Test #16:

score: 25
Accepted
time: 205ms
memory: 184664kb

input:

5000 5000
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

1
3
1
1
1
1
1
1
1
96
1
1
1
266
1
266
1
1
1
1
1
1
1
1
3
1
1
1
2
1
1
1
1
2
1
2
1
2
1
1
2
1
1
1
1
2
2
1
1
1
266
1
1
96
1
1
1
1
3
1
1
1
1
1
4
266
1
1
1
1
1
1
1
1
1
2
1
1
1
1
2
2
1
1
1
1
1
1
2
1
1
1
1
2
266
1
1
2
1
1
1
1
2
1
1
1
2
1
1
1
3
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
...

result:

ok 5000 lines

Test #17:

score: 25
Accepted
time: 156ms
memory: 181056kb

input:

5000 5000
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGGCGGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

4998
4998
4998
4998
5000
4998
4998
4998
4998
4998
5000
4998
4998
4998
5000
4998
4998
4998
5000
4998
5000
4999
4998
4998
4998
4998
4998
4998
4998
5000
5000
4998
4999
4998
5000
5000
4998
4998
4998
4998
4998
4998
4998
4998
5000
4998
4998
4998
4998
4998
4998
5000
4998
4998
4998
4999
4998
4998
4998
5000
...

result:

ok 5000 lines

Subtask #3:

score: 25
Accepted

Dependency #1:

100%
Accepted

Test #18:

score: 25
Accepted
time: 23ms
memory: 8740kb

input:

50000 50000
UA
UU
AU
AU
UA
UA
AU
UU
UU
UU
UU
UU
UU
UA
UU
UU
UA
UA
UU
UU
UA
UU
UU
UU
AU
UA
UA
AU
UU
UU
UU
UA
UU
AU
UU
UU
AU
UA
UU
UA
UU
AU
UU
AU
UU
UU
UA
UU
UA
UU
UA
UA
UU
AU
AU
UA
UU
UU
AU
UU
UA
UU
UU
UU
UA
UU
UU
UU
UU
UU
UA
UA
UA
AU
UU
AU
UU
UA
UA
AU
UA
UU
AU
UU
AU
UA
UU
UA
UU
UU
UU
UU
UA
AU
UA
UU
...

output:

12440
12410
12410
12440
25150
25150
25150
12410
25150
25150
25150
25150
12440
12440
12440
12440
25150
12440
12440
12410
12410
12440
25150
12410
25150
25150
25150
12440
25150
25150
25150
12410
12440
12440
12410
12410
25150
12410
12440
25150
25150
12440
25150
12410
12410
25150
25150
25150
12410
25150
...

result:

ok 50000 lines

Test #19:

score: 25
Accepted
time: 23ms
memory: 8168kb

input:

30000 30000
CAUA
CAUUGUCCGGCUAG
CAUUGUAU
CAUUGUCCGUA
CAUUGUCCGGCUCA
CAUUGUCCGGCAC
CAUUGUCCGGCUAUA
CAUUGUCCGGCCU
GC
CAUUGUCC
CAUUGUCCGGCUAAGC
CAUUC
CAUUGGA
CAUUUU
CAUUGUCCGGCUACA
CAUUUC
CAUUGC
CAA
CAUUGUGC
CAU
CACU
UCC
CAUUGUCCGGAGA
CAUUGUCCAC
CAUUGCC
CAUUGUCCGGCUCAA
CAUUGUCCUG
CAUUGUCCC
CAUUGC
CCGC
...

output:

338
549
3133
422
1095
505
91
212
219
3205
364
2347
1001
197
217
173
175
1810
635
231
12
121
893
276
66
24
43
1444
302
25
259
555
329
125
181
121
33
791
231
487
578
16
2251
7317
2242
505
189
30
2596
549
555
541
26
132
1810
958
50
422
32
7317
789
189
102
1824
72
29
268
1059
338
41
386
2347
29
3202
728...

result:

ok 30000 lines

Test #20:

score: 25
Accepted
time: 31ms
memory: 8680kb

input:

40000 40000
U
AGUA
AGUGUC
CUA
AGCGU
AGUGUCUAGAA
AGUGUCUAAAU
AGUGUCUGUG
AGCUA
AGUGUCUAAG
GCG
AGUGUCUACCUG
AGUGUCCGG
AGUGUCUACCAA
A
C
AGUGUCGCU
AGUGUA
AGUGUCUACCG
AGUGUCUU
AGUGUCUACAGC
AUC
AGUGUCUACCAA
AGUGUCUCAU
AGCC
UG
AGUGUCUACCAU
AG
AGUGUCUC
A
AGUAA
AGUGUCUACCAU
AA
AGUGGC
AU
AGUGCC
AGUGUCUAAC
UCU
...

output:

3325
47
15
58
147
123
2658
5
142
190
128
119
682
3284
9626
57
178
36
2638
244
1773
820
2113
241
320
470
1568
905
703
898
360
321
1072
21
1355
514
21
174
3325
345
920
116
119
3002
563
232
870
12
12
107
58
58
319
282
143
29
360
2658
75
230
67
920
360
455
59
330
124
171
2280
771
122
116
18
2088
2088
20...

result:

ok 40000 lines

Test #21:

score: 25
Accepted
time: 21ms
memory: 6968kb

input:

33322 33245
UAA
AUU
UUA
AUA
UAA
AAU
AUA
UUA
UAU
AUU
UAU
AUU
AAU
AUA
AUU
AAU
UAU
AUU
UUA
UUA
UAU
AUU
AUA
AUA
AUU
UAU
AAU
UAA
AUA
UAA
UAU
AUU
AAU
UAU
AAU
AUA
AAU
AAU
AAU
AUU
AUA
UUA
AAU
UAA
UUA
UAU
AUU
UAA
AUU
AUU
UAU
UUA
UUA
UAA
UAA
UAA
AUA
AUU
UAA
UAU
UAA
UUA
AUU
UUA
AUA
UAU
AAU
UAA
AUU
AUU
AAU
UAU
...

output:

3685
7413
7492
7360
7492
3640
3732
3685
7360
7360
7413
3685
3640
7492
7360
3685
7413
3640
7492
3732
7492
7492
7413
7492
7413
7413
7492
7413
3732
7492
7360
7492
3640
7492
3732
7492
7492
7492
7360
7492
7360
7492
3685
7492
7360
7413
7360
7360
7492
7360
7492
7492
7413
3640
3640
7413
7413
3732
3640
7413
...

result:

ok 33245 lines

Test #22:

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

input:

30000 30000
CCUAAGUUU
GU
AU
GCUGGAGCAUAAGUUU
AUU
GGGU
GUAAGUUU
AAU
GGGCAUAAGUUU
AUAAGUUU
AUUAGCAUAAGUUU
UGUAAGUUU
AAA
U
UGCAUAAGUUU
UGAGAGCAUAAGUUU
CCUGGAGCAUAAGUUU
CCAGCAUAAGUUU
AAUGUUU
UAAGAGCAUAAGUUU
GAGCAUAAGUUU
GGUUU
CUU
GGGUUU
AAGUUU
GC
UGUAGCAUAAGUUU
CGGGAGCAUAAGUUU
CGGUUU
ACCCAUAAGUUU
ACGAGC...

output:

160
96
78
1268
261
3199
379
19
834
1822
1039
414
267
1380
11
685
7328
183
827
56
173
462
115
96
319
2236
235
2166
99
1422
56
1039
151
196
2236
42
544
9
41
185
606
190
1039
3199
290
615
79
170
3153
204
264
624
35
183
573
11
203
3153
211
649
1268
199
591
924
67
205
11
597
2404
92
749
54
409
924
597
31...

result:

ok 30000 lines

Test #23:

score: 25
Accepted
time: 30ms
memory: 8144kb

input:

40000 40000
GAGCGGAG
GUGGAG
UGCCACCGGAG
CCGGAG
CAACCGGAG
GAGACCGGAG
GCUACCGGAG
UG
CGUACCGGAG
UCGAG
GACCACCGGAG
CAG
UCGGAG
ACAG
UUACCACCGGAG
AGAACCGGAG
GUACACCGGAG
CG
UCGGAG
GAGCGGAG
CUACCACCGGAG
UGCCACCGGAG
GCCCGGAG
AGCG
GCCCACCGGAG
CA
GACCACCGGAG
AACCGGAG
GGCCGGAG
U
AGGAG
UGACCACCGGAG
AGUAG
UACCGGA...

output:

51
9588
767
267
270
127
444
2092
313
1552
20
300
186
418
1763
99
771
928
62
65
94
1552
290
444
733
254
466
43
444
56
254
29
91
25
864
341
2100
1108
51
567
1094
541
1549
1549
193
658
29
7
744
1094
3
137
1549
221
322
1243
541
1342
466
100
5
48
254
10
54
360
381
1185
44
1342
1763
11
221
439
5
207
251
3...

result:

ok 40000 lines

Subtask #4:

score: 40
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Test #24:

score: 40
Accepted
time: 279ms
memory: 311224kb

input:

10000 20000
UGAUGAAGACGCACGGCCUCUAUUAGUCUGAAGAUAGUUGGGGGUGUUAAUGUAGGACGGAUAAUGGUCCUAGUCCCGACUCGCUAUGAGUUCACCAAUUGGCAGUGCUAUGAUGACGGCCUCGCACAAUAUUUUGUCUCUAGAUGGGUCAGUCGGGCGAAUACGCCCAUACCGCAGUCUUAUGUAAAGUGUCUAAAUUGGUUAUUUAAGUUGUGACAUCCAUCAGGUUUAUGUUUACAACCAGUAACAAGCCUCACUGGACGCCCAGAUGCAGGUAUUGUCAGUCUA...

output:

83
42
568
635
244
1500
154
41
1344
1442
668
90
1059
758
185
29
662
99
285
68
123
1134
195
204
1142
81
35
133
821
1265
1766
1305
1299
171
222
402
908
39
195
721
117
1164
1500
919
40
174
104
91
65
422
283
475
90
80
144
300
186
50
78
412
1031
199
414
91
237
51
73
49
56
51
411
372
217
883
284
475
55
779...

result:

ok 20000 lines

Test #25:

score: 40
Accepted
time: 284ms
memory: 315088kb

input:

10000 50000
UCCAGCGGAUAAAUCUGAGGAACGCCAAACAGUGGAUAUGGUAAUCUAUACGAUGCGUACGGAUAACCCGCUUAAAGAUGAGUCAACUUAGCUUGAGGAACCCUCUCCGGCUAGAGACUCUGUGCGUCUGGUAUCAAACUCUAUAACAGGGCCGACUGACCCGUUAAUUGUGGGGUCGUUACGCCGGACUUAGGUAAUAAACGUUGGGCAAGUGCAACAGUGACCGCUGACUCAAUCCGUCACUUCAUAGUACUCUAAGGUUAGAUUACAUAGGGUUACUCAUGUGUA...

output:

471
1417
334
151
1532
1352
1364
2036
122
2001
92
99
1434
89
415
159
100
73
97
84
85
114
352
80
98
111
97
1371
1299
94
447
1719
423
1405
372
159
1282
88
73
1622
102
360
502
1639
123
102
98
554
564
1807
1515
1928
98
390
130
1528
1989
106
1693
456
367
305
552
113
348
1600
102
416
1435
1397
76
496
368
4...

result:

ok 50000 lines

Test #26:

score: 40
Accepted
time: 275ms
memory: 310756kb

input:

10000 10000
AUGAAAAAUCCAGAGGAGGUUACAUUACCGAGUGUAAUCGCGCUUCCGUUGAAACAUCUUAUGUUCGACUCCCCGCAAACCAUUCGGUGCUCCAACUCCGGUUGGCUUGGUAGUGCGAGCACACCGUCGUUCAGUAUCAGGUACGGGCGCAUCCGCCAACGUCUCGACUCUUACGGACGUCCCACCGCAUUGCGUUUGGAAAUAAUUCCAGCCUCAAUCCGACCCGCUUGGGUAGUUUAGGAAAGCAUAGUUCGGUUGACACGCCCAUGAGAUGGUCCGUUGAUUGUU...

output:

876
16
147
27
15
17
345
399
72
104
48
126
86
48
25
40
1856
116
194
58
125
528
138
21
225
79
674
560
348
904
330
429
310
322
226
70
907
226
984
389
96
9
100
348
215
28
239
47
35
111
1541
379
259
7
48
26
296
117
10
1597
315
26
19
997
428
259
245
1039
68
162
1533
161
49
318
167
127
57
1316
95
13
41
33
...

result:

ok 10000 lines

Test #27:

score: 40
Accepted
time: 178ms
memory: 169828kb

input:

10000 20000
AAGAGGCGGUGCCGGGCGGAUUGGGCUCAUCCUCUGACCAUAGUCUACAUUCAACGGAUUACGCACCUACCAACGUCUAUAUCCCAUCAGGAUUGAGAGCGAGUGCUUCCUAGCAGGUGCGAACUGUACCAAGAUCCACCUUCUAACGCACCUUUGGAGCACUACAUUGUGGCCCGACUCAGGUUGUAUGUAUUCUACCGAAUCAAUGGACUAAUUACCGCUGCUAAUGCGAACAGUGUCUUGUCGACAUCACGCACUCGCCCUUAACAUGAAACUCCCGGUAAUUUU...

output:

382
332
74
84
362
1175
245
157
241
38
84
786
1339
1709
119
238
455
82
42
2020
928
69
725
87
62
219
86
211
122
302
865
484
203
72
1528
44
335
281
87
202
825
1884
645
1447
361
184
214
325
233
51
155
284
77
904
226
1077
447
203
86
1000
171
267
243
86
67
561
85
223
41
249
62
56
228
1233
179
189
517
196
...

result:

ok 20000 lines

Test #28:

score: 40
Accepted
time: 234ms
memory: 60868kb

input:

100000 100000
CUGGUUACUCUUACA
CUGGUUACUCUUAGAUAAGACUGCCGUCGCUACGGGUAUGGGACAAUAAUUACCACCGAAGCAUGCUACGUCUAGCUUACGGUUCAUAAACCU
CUGGUUACUCUUAGAUAAGACUGCCGUCGCUACGGGUAUGGGACAAUAAUUACCACCGACGC
CUGGUUACUCUUAGAUAAGACUGCCGUCGCUACGGGUAUGCG
CUGGUUACUCUUAGAUAAGACUGCCGUCGCUACGGGUAUGGGACAAUAAUUACCACCGAAGCAUGCUACG...

output:

582
2179
706
301
1680
753
1449
373
2845
8803
234
2869
885
1586
4275
841
5037
19904
190
504
17964
3724
1660
214
2792
2094
2344
4272
18358
440
15044
93
764
520
2624
1937
979
15044
14172
629
11636
540
562
12544
2724
11075
367
1327
1387
102
3913
8437
12301
166
3155
924
6302
875
14682
182
17516
3679
3442...

result:

ok 100000 lines

Test #29:

score: 40
Accepted
time: 91ms
memory: 15232kb

input:

100000 100000
AAUAAAAUAA
AAAAAAUAAA
AAUAAAAAAU
AAUAAAAUAA
AAAUAAAAAU
AAAAAAAUAU
UAAAAAAAAA
AAAUUAAAAA
UAAAAAAAAU
AAUAUAAAAA
AUAAAUAAAA
UAAAAAAUAA
AAUAUAAAAA
UAAAAAAUAA
AAAAAAAAUU
AAAUAAAAAU
AUAAAAAAAA
AAAAAAUAUA
AUAUAAAAAA
AAAAAUUAAA
UAAAAUAAAA
AAUAAAAAAA
UAAAAAAAUA
AUAUAAAAAA
AAUAUAAAAA
AAAAAAAAAU
...

output:

2016
2069
2016
2058
1960
1988
1020
1941
2001
1020
1988
1968
1020
2003
1952
2005
1988
1933
991
1991
2133
2069
2041
1991
1943
2004
2004
1943
1991
2072
1972
2031
991
2020
1933
2016
1990
2014
1968
1968
1960
984
2031
2133
2058
2058
1988
2001
2058
2031
2014
2000
2009
1972
1952
1020
2005
2014
2003
998
2031...

result:

ok 100000 lines

Extra Test:

score: 0
Extra Test Passed