QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#801074#9846. jwfw.harie.eduSGColinAC ✓115ms565644kbC++202.1kb2024-12-06 18:13:292024-12-06 18:13:29

Judging History

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

  • [2024-12-06 18:13:29]
  • 评测
  • 测评结果:AC
  • 用时:115ms
  • 内存:565644kb
  • [2024-12-06 18:13:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

inline ll rd() {
    ll x = 0;
    bool f = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) f |= (c == '-');
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    return f ? -x : x;
}

#define N 20007
#define M 30000000

char s[N][10];

int n, w[N], tr[M][6], cnt[M], tot;

inline void insert(char x1, char x2, char x3, char x4, char x5) {
    int nw = 0;
    for (int i = 0; i < n; ++i) {
        int sc = (s[i][0] == x1) + (s[i][1] == x2) + (s[i][2] == x3) + (s[i][3] == x4) + (s[i][4] == x5);
        if (!tr[nw][sc]) tr[nw][sc] = ++tot;
        nw = tr[nw][sc];
    }
    ++cnt[nw];
}

inline int add(char x1, char x2, char x3, char x4, char x5) {
    int nw = 0;
    for (int i = 0; i < n; ++i) {
        int sc = (s[i][5] == x1) + (s[i][6] == x2) + (s[i][7] == x3) + (s[i][8] == x4) + (s[i][9] == x5);
        sc = w[i] - sc;
        if (sc < 0 || sc > 5) return 0;
        if (!tr[nw][sc]) return 0;
        nw = tr[nw][sc];
    }
    return cnt[nw];
}

inline void work() {
    for (int i = 0; i <= tot; ++i) {
        cnt[i] = 0;
        for (int j = 0; j < 6; ++j) tr[i][j] = 0;
    } tot = 0;
    n = rd();
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        char c = getchar();
        while (!isalpha(c)) c = getchar();
        for (int j = 0; j < 10; ++j, c = getchar()) s[i][j] = c;
        w[i] = rd() / 10;
    }
    for (char x1 = 'A'; x1 <= 'D'; ++x1)
        for (char x2 = 'A'; x2 <= 'D'; ++x2)
            for (char x3 = 'A'; x3 <= 'D'; ++x3)
                for (char x4 = 'A'; x4 <= 'D'; ++x4)
                    for (char x5 = 'A'; x5 <= 'D'; ++x5) insert(x1, x2, x3, x4, x5);
    for (char x1 = 'A'; x1 <= 'D'; ++x1)
        for (char x2 = 'A'; x2 <= 'D'; ++x2)
            for (char x3 = 'A'; x3 <= 'D'; ++x3)
                for (char x4 = 'A'; x4 <= 'D'; ++x4)
                    for (char x5 = 'A'; x5 <= 'D'; ++x5) ans += add(x1, x2, x3, x4, x5);
    printf("%d\n", ans);
}

int main() {
    for (int t = rd(); t; --t) work();
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
1
CCCCCCCCCC 90
2
AAAAAAAAAA 10
ABCDABCDAB 20
3
AAAAAAAAAA 0
BBBBBBBBBB 0
CCCCCCCCCC 0

output:

30
57456
1

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 110ms
memory: 5916kb

input:

20000
1
DDDDCABCCB 30
1
CDCBCAACDA 20
1
CBBABDCADB 30
1
DACDDADAAB 20
1
BDBBBCBCBA 20
1
ABCAABCCDB 20
1
ABADDCADCA 30
1
ACCBCCDABA 20
1
ACDCDBBADB 30
1
CBBBACCBBA 20
1
ABDBCAADAC 20
1
DCCDCCDADD 20
1
BCDCCDAAAB 20
1
AADBBBABCA 20
1
AAACADABBB 20
1
CDADBACDBB 30
1
DBCDBBADAD 20
1
BACBCCADBB 20
1
CBDD...

output:

262440
295245
262440
295245
295245
295245
262440
295245
262440
295245
295245
295245
295245
295245
295245
262440
295245
295245
295245
295245
295245
295245
262440
262440
295245
262440
262440
295245
295245
295245
262440
262440
295245
295245
295245
262440
295245
262440
295245
295245
262440
295245
295245...

result:

ok 20000 lines

Test #3:

score: 0
Accepted
time: 98ms
memory: 5908kb

input:

10000
2
BDDABDCCDD 20
BDDDBDCACC 20
2
CCBCCAABBD 20
BCBBCCABBC 20
2
CCACCACACA 20
ACDACCCCAB 20
2
CBBCBCCBAD 20
BCABDABAAC 20
2
AABCDAAADB 20
CACBDACCBD 30
2
BBDADDACAA 20
DBAABDBCBA 20
2
BCACDCDBAC 20
ADDCCBABBD 20
2
ADBDACBDAD 20
BCBDABADAD 20
2
ADCBCABDBC 30
BDDDBAADAB 20
2
DBCCBBADCB 20
ADBAADDA...

output:

93798
93798
82800
81792
72072
88020
82240
93798
72072
81792
73600
82800
76608
81792
72630
73600
80640
81792
84456
73600
82240
57456
82240
82800
72072
82800
84456
72072
82240
102060
88020
81648
72072
82240
82800
73600
93798
72072
84456
71928
84456
82240
82800
81792
82800
65144
71928
88020
50688
80640...

result:

ok 10000 lines

Test #4:

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

input:

6667
3
ACAAACBDAA 20
CCCBBAAACB 20
CCCCBBADAB 20
3
CACDCCBAAC 20
BBADDCDBBC 20
BBCDDBDBCD 10
3
BAACAAADAB 20
BBACDCADDD 20
DDAACBDDCA 30
3
CCBCBABDBD 20
BDBACCCCCD 20
DDCBACABDA 20
3
DBCACBDDAD 20
DABDDBCDBD 30
CBCADCABDB 20
3
ADAAAAABDB 30
BACDBBDBBA 20
CDDBBDBADC 30
3
BDAAACDDAD 20
ADACCCDBCD 20
B...

output:

26272
17472
22030
22075
20896
19446
25012
22974
13454
22636
26272
21236
29840
16712
17712
15764
22292
23192
22636
24624
28448
16770
20488
20394
26088
22658
20244
15422
23240
24276
23508
23112
24088
16761
22632
46624
24416
16376
17436
17450
21858
22504
26176
18714
22636
19526
22364
22987
24416
23112
...

result:

ok 6667 lines

Test #5:

score: 0
Accepted
time: 104ms
memory: 5968kb

input:

5000
4
ACAABCDDCA 20
ADACACDBCD 20
BDABCABBAD 20
DCCABDDBBA 20
4
DDCBAADCAB 20
CABBDDDABB 20
CDBACAACDA 20
AAADCCBACD 30
4
DBACACDADB 20
DCDDBACBBC 20
CBCDCCBCAB 20
DAADBDBBDD 20
4
DDCDCBBCCA 20
DDADAABBDD 20
DCDBAADDCA 20
BCADBBDCAA 20
4
CACDACABCA 20
DCCCADACBC 20
BCDCBDDCAA 20
BCDBDAADDD 20
4
CCD...

output:

7592
6344
6346
6720
6445
4614
6544
6316
8460
5537
6456
7031
6758
6032
7256
8296
5424
5574
6924
6271
6393
5159
6100
5320
5442
4192
6538
6033
7346
6062
5380
7478
7556
6188
5255
5600
7455
6276
6448
6630
6731
7304
5190
5407
5923
7078
5160
7280
5573
8419
12664
6148
7488
8408
6227
6556
6906
5432
8409
5196...

result:

ok 5000 lines

Test #6:

score: 0
Accepted
time: 115ms
memory: 5920kb

input:

4000
5
CCCCBCBABC 20
ACCCBDDBAC 20
ADAADACCBD 20
CBCADCCADD 20
BADABBCBAD 20
5
CCADDDABCC 20
DBBDDBCCCB 20
BBCDDACADD 20
BACDBBCBAB 20
BACCABABAA 20
5
DBABDDDBAC 30
ACACAAADDD 20
ABADCAADDD 20
ADDABADDDD 30
ACACDCBDDB 20
5
ACCACDBCCB 20
DCDBBAAAAD 20
ACBADDADAD 20
CCBDADADBC 20
AACBBCAACB 20
5
CCBCC...

output:

1818
2077
2117
2093
1944
1510
1717
1399
1477
2562
2016
1695
2010
1962
1421
2498
2169
1820
2125
3142
2089
1360
1463
2928
1617
2785
2108
1651
1728
2064
1784
2371
1893
1527
2140
1769
2563
2143
2134
1286
1275
1833
2239
2513
1649
1744
2539
1986
1927
2396
1876
1541
1540
1619
1492
1370
1849
1929
1783
2504
...

result:

ok 4000 lines

Test #7:

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

input:

2000
10
DABBABBDDB 20
BABABDBBCB 30
CBCCDABCCC 20
CCDADDADAC 20
CBCDBAABCB 30
DADABBBCCB 20
ACBCADCBBD 30
DDDACDDBDA 20
DDBDBBDBCB 20
DCDCBDACCB 20
10
DADACACCBC 20
BADACDDBCC 30
DDCCBBDCAA 20
DDBBBACCBD 20
AAAADCCDDC 30
ABDCDCBCAC 20
DBDBCAABAD 20
CBDACDDDBD 10
DBADDBAABA 20
DABCBBBADC 20
10
CDDCCA...

output:

12
11
17
27
30
18
17
9
21
24
13
12
36
17
22
15
18
16
10
19
11
13
16
12
23
9
13
23
25
14
12
14
13
13
10
1041
80
12
44
13
12
39
15
13
35
21
14
14
15
28
10
19
11
14
34
15
19
13
14
36
9
36
15
18
15
14
10
14
15
14
47
24
27
23
14
12
22
23
9
10
12
12
15
41
10
23
18
15
25
12
20
18
13
14
21
15
12
17
13
13
10...

result:

ok 2000 lines

Test #8:

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

input:

1000
20
ACCBCDACCB 20
CDDBABCBDC 30
DACDACBDBA 20
DCCDCDDBDC 30
CCDBADCCCC 30
CCDDABCDCC 30
ABDBBBCDBD 20
ACCDCBADCB 20
BBDCBAADBB 30
BAABACBDBD 20
AACCCCACDB 20
CACDDBACDA 20
CADCACCCDC 30
CDCAACCCDA 30
ABDBBBBCAA 10
DAADBDDDBD 20
ADCBCBABDB 20
ABAACBDDDC 20
BDAAADBBBD 30
ABAACBDAAC 20
20
BCBBCDBAC...

output:

9
10
9
9
9
9
9
9
9
10
9
9
9
9
10
10
9
9
9
9
9
9
9
9
9
9
9
9
9
9
10
13
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
10
9
9
9
12
10
9
9
10
9
9
9
9
9
9
10
9
10
10
9
9
9
9
9
9
9
9
11
9
9
9
10
9
10
9
9
12
9
9
10
9
9
9
9
9
11
9
13
9
9
9
9
9
9
9
9
9
9
11
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
9
12
10
9
9
9...

result:

ok 1000 lines

Test #9:

score: 0
Accepted
time: 87ms
memory: 285280kb

input:

2
10000
ADABBAADAB 30
ADBBADBBAA 20
DBAADCAADB 20
BACCDCCBAC 30
BCCCCBBCDA 30
DCADDDDACB 20
BACAABCBCC 20
CADDDDDACC 20
CBDCDAABAA 30
ABCCBCCACB 20
DAAAABADAD 30
BDCCBACABB 20
BCADCAACBA 30
CCCBADCCDB 10
BDDDCBAACD 20
ADDBCBDCAC 30
BBCBDCCBBD 20
CACBBDDABC 20
BCCCDDBBAD 30
CBADBBACDA 20
DDBACDACDA 2...

output:

4
4

result:

ok 2 lines

Test #10:

score: 0
Accepted
time: 44ms
memory: 564792kb

input:

1
20000
DACDADAADB 20
DDBDACDDAA 20
ABCBCDBCAB 40
ACDADABBAC 40
DDCDDDCDCB 10
CACCDCCDDD 20
DBABBADCBB 20
ADDDADAACB 20
ACABDBBBAA 40
DCBDABCBCD 20
BACDAAADBB 10
AABCBBCACC 20
ACCDBDABAC 40
CBABCBDCBA 30
BADDABBACD 20
DACBACCDCB 10
AADCBABABA 20
CDCDBCADAD 20
DDAABCBDAB 30
DABBBAAACC 10
DADAACAABC 2...

output:

5

result:

ok single line: '5'

Test #11:

score: 0
Accepted
time: 71ms
memory: 9844kb

input:

200
100
ADDBBACACB 20
ACBADCDADD 30
DAABCBDBDB 20
CABCBCDBCB 20
DBCCDDBCBA 30
DBACBBBCBA 30
DCBAADDBAB 10
CABCBCDBAB 20
ADCADBBACC 30
BADCABDBCC 20
ADBBBCDACD 20
BBABCBACAA 20
ACBAAADBBD 30
ADDDADAADD 20
DDDBABDBDB 10
CCBBDCBCAB 20
DDADCBBCAB 20
DBAAABADAD 20
ADCDADBAAB 20
BDCCDCDDAB 20
BCDCDAABCA 2...

output:

7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
8
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
8
7
7
7
7
7
7
7
7
7
7
7
7
7
7
...

result:

ok 200 lines

Test #12:

score: 0
Accepted
time: 71ms
memory: 10312kb

input:

100
200
BABDACCDCC 20
DCACCCDDDC 20
CAACACBDAB 30
BAADACCDCD 20
AADCBBAADB 30
BDCDABACCA 20
ACADCBCDDA 20
DABDACADDD 20
DBACADDADC 20
BDBCBDAACD 10
DBADDCCDDB 20
ABBDBBCBAB 20
BCACCBDDAD 20
DBAAADDACD 20
DCBACBDDAD 20
DACCADCDDC 20
ABDDDBAADB 30
DCBDBCADCD 10
BBBDBBCDAD 10
AACCADABCB 30
BABCBCADCB 2...

output:

7
7
8
7
7
7
7
7
8
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
10
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7
8
7
7
7
7
7
12
7
7
7
7
7
7
7
7
7
7
7
7
7
7
7

result:

ok 100 lines

Test #13:

score: 0
Accepted
time: 98ms
memory: 7888kb

input:

20000
1
DBDADACAAD 0
1
BDCAAADACA 0
1
AAADADCDAD 0
1
CAAADDACBB 0
1
CACDABCABD 0
1
DACDCABBBD 0
1
CBCDCABBAA 0
1
AAADCBDDDA 0
1
DCDBBACBCC 0
1
BDCABBAABC 0
1
ACDCBADCCA 0
1
CDDDDCBDAD 0
1
DDCACCDBCD 0
1
BACCDCAABD 0
1
DABDDBBDCA 0
1
CBCACBCAAD 0
1
ABADDABCAD 0
1
BDCDCABACC 0
1
CBCCCDCABC 0
1
DABDADA...

output:

59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
59049
...

result:

ok 20000 lines

Test #14:

score: 0
Accepted
time: 104ms
memory: 5920kb

input:

20000
1
CACCDBDBAB 50
1
BCABCBDBAA 50
1
CACDACDBBC 50
1
CDBBBBCCBA 50
1
DCCBAACBAD 50
1
DACCCCBDAC 50
1
DDBCACDBDD 50
1
ADACAACADB 50
1
CDADCBBDDA 50
1
DCABCACBCB 50
1
BCCCCDDDBA 50
1
DADDCDDCDA 50
1
AACDBCADCA 50
1
ABADDADCCC 50
1
ADBACBABDD 50
1
BBADDACDBA 50
1
ABCDDDADCA 50
1
DBDCACCCCC 50
1
DBBD...

output:

61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
61236
...

result:

ok 20000 lines

Test #15:

score: 0
Accepted
time: 73ms
memory: 5920kb

input:

10000
2
DAABBDDBDC 0
AAABBBDBDB 0
2
DABDCADBCA 0
BDDCDADBAA 0
2
BCDCDCCBBD 0
AAADBCDDBB 0
2
BCCCADDBDD 0
DCCCCADAAD 0
2
ABDCBABCAB 0
BBCDBADCDA 0
2
CCCABBAAAC 0
DDBCCBBBCB 0
2
CDDDBCABBC 0
BBBDDDCBDC 0
2
ACBAACDDCD 0
ABBDACDAAB 0
2
CAABDDDDAD 0
AAABDBADBC 0
2
DBDAABCDCA 0
BCDDDACDAA 0
2
CBBAAABCCA 0...

output:

17496
5184
2304
7776
5184
1536
3456
7776
7776
5184
11664
7776
7776
17496
11664
7776
17496
3456
17496
7776
7776
5184
5184
5184
3456
17496
3456
17496
11664
17496
5184
5184
17496
17496
7776
11664
26244
2304
3456
17496
11664
17496
26244
3456
7776
3456
11664
11664
3456
17496
17496
11664
7776
26244
5184
7...

result:

ok 10000 lines

Test #16:

score: 0
Accepted
time: 98ms
memory: 5840kb

input:

10000
2
CDCDCADCBA 50
ADACDAAACA 50
2
BCBDBDBACA 50
CCBCBDAACA 50
2
ABBCDCBAAD 50
CDCABCAACD 50
2
DADDCBDDDD 50
DDDDDBDCBD 50
2
DCCBCBCADD 50
ACDCBBDACD 50
2
BBCDBBBBAB 50
BBDADBBCBD 50
2
AACCDADDAB 50
BBCBDDCDBD 50
2
CDBBDDCADB 50
CDBBADBCAB 50
2
DACBACDCAC 50
CCBBACDACC 50
2
DDAAABDCDD 50
DBCDAADA...

output:

4200
12852
4200
10008
5880
5880
4200
10008
7832
4200
7832
4200
5880
10008
12852
7832
2660
4200
5880
4200
5880
5880
5880
10008
5880
10008
5880
7832
7832
10008
5880
10008
7832
7832
7832
2660
4200
10008
7832
7832
10008
4200
5880
2660
4200
7832
5880
7832
7832
7832
2660
7832
10008
7832
5880
7832
17388
42...

result:

ok 10000 lines

Test #17:

score: 0
Accepted
time: 69ms
memory: 6028kb

input:

6667
3
CBDACABCDC 0
BDCDCDCDDA 0
BDCDCABDDA 0
3
CCDDBACCBA 0
CCDDDCBCCA 0
ABDDBABCCD 0
3
CCBCCCADAB 0
ACCCCDABDC 0
ABCABDDDDA 0
3
BDDBCBADCA 0
BDCDCAADDA 0
ADDBCBCBCC 0
3
CBBBBCBBDA 0
CBACBADACA 0
ADACACBADA 0
3
CCCABDCCAD 0
CBBAABCCAD 0
BCBDADCDCC 0
3
BBADBBDCAA 0
ABABCADABA 0
BBDBBBBCAC 0
3
AAAACC...

output:

2304
3456
512
2304
1536
1536
1536
1728
256
384
768
768
5184
3456
2304
1536
3456
512
1152
3456
576
768
1728
5184
2304
1536
384
1536
2304
1152
1152
3456
2304
768
1728
1024
1152
2304
3456
1536
2304
2304
1152
1152
192
2304
768
2592
1152
7776
3456
1728
2304
2592
256
1536
384
2304
1152
1024
1152
2304
3456...

result:

ok 6667 lines

Test #18:

score: 0
Accepted
time: 98ms
memory: 8000kb

input:

6667
3
CCBBCDBDAC 50
DABDBDADAC 50
DDDBCDDDAA 50
3
CADBACCADD 50
AADBDDCABD 50
AABCABCBAD 50
3
CBBBACADAC 50
BBABDBBDAC 50
CDABDBBAAD 50
3
CCDBDBDCCB 50
ACBABDCCCB 50
CCBABBDBBA 50
3
AAACDAACCD 50
DDDADADCDA 50
DBDDDADADD 50
3
DADDDBCBAC 50
CBDACACACC 50
CDDDDBDCCA 50
3
ADABCBADBB 50
ABDBABCCBD 50
D...

output:

1162
1162
1032
648
732
430
513
1000
888
2116
640
2120
1476
330
634
307
732
750
512
1086
1162
1496
221
756
1450
1032
873
1476
1324
513
1017
764
1908
500
900
1868
1476
530
1880
512
532
900
319
1868
307
750
1000
600
1555
1166
770
750
1555
2528
900
402
634
2776
764
400
1032
532
1555
888
888
1036
1908
18...

result:

ok 6667 lines

Test #19:

score: 0
Accepted
time: 66ms
memory: 5884kb

input:

5000
4
AADBBCCACC 0
AADBBDDBBC 0
AADCDDCACC 0
DADCDDDABB 0
4
ADAABDDDCD 0
BCCACCCBCD 0
BACDBBCDCD 0
ACADBCCBCC 0
4
BDCCCDCBAA 0
CBACCCCBAB 0
BDABCDABAB 0
CDCBCCADDA 0
4
DBADDCBCDD 0
DBADACCACA 0
BCACADDADA 0
DCADDDBCDA 0
4
CBABDAAACA 0
ACACCAAACC 0
CCABCBBADC 0
CBBBDBDACA 0
4
CDDADABDCD 0
DBBDDBACBC...

output:

2304
384
1536
768
768
256
512
512
1152
32
1024
512
1728
1024
1152
1024
512
384
768
3456
2592
384
384
1536
2304
256
576
1536
1024
512
512
192
1536
1024
768
3456
768
768
768
576
1536
512
864
48
2304
768
2304
576
1024
512
512
2304
1024
1024
1024
1536
768
576
768
768
288
768
64
576
1536
512
288
3456
512...

result:

ok 5000 lines

Test #20:

score: 0
Accepted
time: 94ms
memory: 5860kb

input:

5000
4
DABBDACBBB 50
DBBADCCCAD 50
BBBDDABDAD 50
DDBADCBBCD 50
4
BACBACCDCA 50
DCCBABCDBB 50
BDCBACCCDA 50
BBCAABCCAB 50
4
DDCCDDDABA 50
CDCDDCADCA 50
DBCDDABDAA 50
CDDCDABBDD 50
4
ABBCACAAAC 50
ADBDCCAACC 50
ACCACCBCCA 50
ACBCCCDCCA 50
4
CBBBDDDCAB 50
ABACDCDCBD 50
DBBABCCCBD 50
DAACCCDCDD 50
4
CDD...

output:

140
432
81
231
93
219
122
126
192
232
57
93
160
142
45
57
232
155
142
284
248
103
48
158
146
86
141
297
121
258
57
120
248
179
251
92
160
138
372
310
92
258
74
397
108
69
66
307
60
70
310
68
168
94
139
44
184
70
176
149
214
195
105
153
386
192
158
132
556
214
222
159
204
313
165
225
114
223
6
44
228...

result:

ok 5000 lines

Test #21:

score: 0
Accepted
time: 64ms
memory: 5912kb

input:

4000
5
BAACABDCAA 0
ACACADBCBD 0
BAACCDBCAA 0
ACDCADBCBA 0
ACADABBCBD 0
5
ACCDADCDCC 0
CCCBADCCAC 0
DBBBBDADCA 0
ADCDBBCBAC 0
DDBDABADCA 0
5
BBDCBDCCBD 0
BDDDAABCCD 0
BDCCDACCBC 0
BBDDDDBCBD 0
BBDDDACBDD 0
5
AACDABBDAB 0
BDBBADBBAD 0
BCBBBDBBAB 0
AACBBDBDAD 0
ADCDBDCBAB 0
5
ABBBDDDAAA 0
CBBAADCCBB 0...

output:

1536
128
384
768
384
384
512
512
512
512
512
576
384
384
256
512
1024
1536
1024
256
192
128
768
512
1536
128
128
512
768
288
256
768
32
256
512
512
768
512
512
128
768
768
512
1024
384
384
768
384
16
768
512
768
512
64
512
288
2304
1536
512
1536
48
768
512
384
96
256
1024
256
1728
512
1024
384
256
1...

result:

ok 4000 lines

Test #22:

score: 0
Accepted
time: 89ms
memory: 5872kb

input:

4000
5
CACDBDCCBB 50
ACDBBBCCAB 50
ADABDACCBB 50
ADCBBDCCDB 50
BACBDAACBB 50
5
ABADBACACA 50
ABABABCCCC 50
AAADCACACC 50
AADBDBBBDC 50
ABABDAAADA 50
5
BDAABAABCD 50
BDAAACABCD 50
BDCBBCBBCC 50
BBADACAAAB 50
BAABBCADDB 50
5
ABADBDADAA 50
AAABBDADDD 50
BDABAAAACA 50
AABBBAAACA 50
BACBACBDBA 50
5
BCDBC...

output:

68
22
69
26
45
18
16
24
13
27
43
26
26
36
35
31
15
27
15
36
14
36
26
84
106
32
31
53
16
10
18
11
32
35
25
16
53
6
6
37
3
11
24
62
80
17
24
17
63
22
36
40
18
48
20
29
86
11
32
6
22
29
48
14
42
30
15
31
16
30
34
23
45
33
26
4
15
81
60
40
20
22
26
54
42
16
14
28
19
15
32
28
62
52
60
21
205
80
32
20
34
...

result:

ok 4000 lines

Test #23:

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

input:

2000
10
CCBBBABAAB 0
CABBDCBABC 0
BABCCCAABC 0
CCDCCDBBBB 0
CCDCCAAAAC 0
CADCDCBABC 0
CBBBBABBAC 0
BBDCCDAAAB 0
BABBBDAAAC 0
CBDBDAABAC 0
10
BDBDCBADCD 0
DBCACAAACD 0
BDCACBBADD 0
BDBACABACB 0
DDBAABAADB 0
DDCAABAADD 0
BDBAABBADB 0
BBBDCAADDB 0
DBBACAAADD 0
BDBDABBADD 0
10
CACABBACDD 0
AADABCACAA 0
...

output:

128
1024
64
256
256
512
64
256
128
256
512
512
512
128
512
64
1024
256
256
512
256
32
256
256
256
256
128
64
512
256
256
128
512
512
256
64
32
1024
64
64
128
256
128
256
512
256
256
64
32
256
128
128
256
1024
256
256
512
128
256
512
512
256
256
32
64
32
64
512
1024
32
64
512
256
256
256
256
128
256
...

result:

ok 2000 lines

Test #24:

score: 0
Accepted
time: 73ms
memory: 5852kb

input:

2000
10
BDCDDBCDBB 50
BCADBBDBBA 50
BCADABBCBA 50
BAABAAADBD 50
CBAABBCDBD 50
AACDABADBB 50
BAADDBCBBD 50
BAADABDADB 50
BBCBADBDBB 50
BDBDBBBBBA 50
10
ACCDBABBAB 50
ABCBBBBBBD 50
ADCADCBDAB 50
ABCADBACBD 50
ABCADBDDCB 50
ADCADDDDBB 50
ADCBBCADBA 50
ABCCBABCDB 50
ABCBBADDDB 50
AACDAAABBB 50
10
CABBDC...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
2
2
2
2
7
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
2
2
2
4
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
2
4
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
3
2
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
4
2
2
2
...

result:

ok 2000 lines

Test #25:

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

input:

1000
20
ABBCADADDB 0
CDBCAADDDB 0
ADBACADBBB 0
CDBCCDABBA 0
BDDACAABDB 0
AADCAAABBA 0
CBBAADDDBA 0
ABBAADABBA 0
CBBCADDDBB 0
ABBCADDDDA 0
ADDCCDABDA 0
AADACDADDA 0
ADDCADADDB 0
ADBCCDABBB 0
ABBCADDBBB 0
BADAADADDB 0
ABDCCADBDA 0
CBBCCADBBA 0
BBBCCDABBB 0
CDDCCAADDB 0
20
ABABCCCBBD 0
AAABBDCBBD 0
BBA...

output:

256
256
128
256
512
32
128
64
128
32
128
64
32
128
256
128
128
1024
128
512
128
128
512
128
128
256
256
512
512
512
128
256
256
64
512
256
256
512
512
128
512
512
64
32
128
256
128
256
128
512
256
128
512
256
64
64
256
128
128
256
512
512
128
64
256
1024
256
256
512
64
512
16
256
128
64
128
256
64
6...

result:

ok 1000 lines

Test #26:

score: 0
Accepted
time: 62ms
memory: 5980kb

input:

1000
20
BDDAACDCBB 50
CDBCDDDABC 50
CDCABDDCBB 50
DDBAABDAAB 50
DBBBBCDDAB 50
BCBABDDDBB 50
DDACBCDDBB 50
DBCADCDBBB 50
DDDCACDDAB 50
DCDCDDDDCB 50
DDADADDDCB 50
ADCADDDCBB 50
DBDADDDACB 50
DBBCBCDDCA 50
ADBCDDCDBB 50
BABBACDCCB 50
ABBBACDBCB 50
CBBACADCDB 50
DABADCACBB 50
DABADCDCBC 50
20
AABCCBDDD...

output:

2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
...

result:

ok 1000 lines

Test #27:

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

input:

1
20000
AADBDBCBBC 50
CAADBCABBD 50
ABDBDDADAD 50
BADCABCBBC 50
AACACDADCA 50
DCDBADAABC 50
CACBADABAC 50
DADBCDCBBA 50
CCDADCAABD 50
CBDABDACBC 50
ACAADAAABD 50
ABABADABCB 50
BBDAADACAC 50
ACCADBAABD 50
ABDBABDBCD 50
AAABABACAD 50
AABACBBBAD 50
CAADDDAABD 50
ACDBDBACBD 50
CDCCADCBBD 50
AACAABACDA 5...

output:

1

result:

ok single line: '1'

Test #28:

score: 0
Accepted
time: 84ms
memory: 287316kb

input:

2
10000
BDBDDDADBD 0
CDBBAAABDB 0
DBBCADDDBB 0
CBBDAADCDC 0
DBABADDDCD 0
CDBBAADCBB 0
CCDBAADCDC 0
DCADDDACCD 0
DCABADDDBD 0
BCDBDDADBD 0
CBBCADADCD 0
CBDBADDCDB 0
CDBCDAABDC 0
BBACDAABBB 0
BBBCADABBD 0
CDBDDAABBB 0
DCDCDDDDDD 0
DCABAADBBC 0
CDADADACCB 0
CBDCDDABBC 0
DCDCADACBB 0
DBDCADDBBC 0
BBDCAA...

output:

8
8

result:

ok 2 lines

Test #29:

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

input:

2
10000
ACCDBACACB 50
DDCAAABACD 50
CCBCDBDDCA 50
BCCDCCDACD 50
CDCBBACCCD 50
BBCADAAACD 50
CDCCBADDAD 50
CBBDDAADAA 50
CCDADABABA 50
CBBCDAADCA 50
CACDCDDDCB 50
CDDCAABACD 50
CCCCBABAAA 50
CADDDAAABD 50
CBCDAABCAA 50
CCDDCCDDCA 50
CBBBDACACD 50
CAADDACCCB 50
CDCCDACDDC 50
CBCDBBCDCA 50
ABCADADDCC 5...

output:

2
2

result:

ok 2 lines

Test #30:

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

input:

1
20000
DACDBBDCAA 0
DDCACBBBBD 0
AACDDBCDBD 0
ADCACADDBA 0
DDADCBDDCA 0
DBCACABCBA 0
ADCBDCCCAD 0
DBCACABBAA 0
DBCBDCDCAD 0
DDAACACDBA 0
DADBDADBBD 0
AACDBADBCA 0
DBABDBCDCD 0
DBCDDCDBCD 0
DACBDADDCA 0
ABDDCCBDAD 0
ABCDCACBAC 0
DBDDDBDBAC 0
AADABBBDBD 0
ABAABACDAC 0
DBAABABDAC 0
ADCBCCCCAD 0
DDAABB...

output:

2

result:

ok single line: '2'

Test #31:

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

input:

1
20000
BDCDDBCADC 50
BDCDBADBCA 60
BCDDADBDBA 50
BDADDABDAA 50
AACDABADDD 50
BDCDDAADCC 60
BDCCAAADAC 50
BDDCDBADDC 50
BDBCBACDCA 50
DDADBDCDBA 60
BDBDBDAABC 60
CACDBBDCDA 50
BBCDBAACAA 60
BBCBBBACDB 50
CDCCBDABBB 50
CCADBBCDDA 50
DDCDBCAACD 50
BCADBBDBDA 50
BDDDBCACAD 50
BDDDCDDDBB 50
CDBDBBACDD 5...

output:

2

result:

ok single line: '2'

Test #32:

score: 0
Accepted
time: 105ms
memory: 5920kb

input:

20000
1
BBBDDADADD 30
1
CBACBDADDD 30
1
CCADBDABAC 30
1
DDBDDCAAAB 30
1
BDACABDAAA 30
1
DBDBBABACD 30
1
ABDCBADDBA 30
1
BDBCDBACDD 30
1
ACCDDDADBD 30
1
BBDDBBBDBC 30
1
DBCBBCCDAA 30
1
DBDDACBAAA 30
1
ABACCBAAAA 30
1
BDCBACCBBA 30
1
DACAADADDD 30
1
BCDDBDCBBB 30
1
CDDACCDAAB 30
1
BDACDCABBB 30
1
CACB...

output:

262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440...

result:

ok 20000 lines

Test #33:

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

input:

10000
2
CBDCCBBBCD 30
CBDCCBBBCD 30
2
ABDACDDDAC 30
ABDACDDDAC 30
2
BBBCBBCABD 30
BBBCBBCABD 30
2
BCDADBDBAD 30
BCDADBDBAD 30
2
ACBBCBBAAC 30
ACBBCBBAAC 30
2
BBDABDAADD 30
BBDABDAADD 30
2
DABCCCCDAC 30
DABCCCCDAC 30
2
ACCBCAABAC 30
ACCBCAABAC 30
2
AABDBBAAAC 30
AABDBBAAAC 30
2
ABABCBCDBA 30
ABABCBCD...

output:

262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440...

result:

ok 10000 lines

Test #34:

score: 0
Accepted
time: 88ms
memory: 5916kb

input:

6667
3
CAADDBAAAD 30
CAADDBAAAD 30
CAADDBAAAD 30
3
DCADDACCCC 30
DCADDACCCC 30
DCADDACCCC 30
3
CBADCDADBA 30
CBADCDADBA 30
CBADCDADBA 30
3
BCAACBBCBA 30
BCAACBBCBA 30
BCAACBBCBA 30
3
CAADCABBDA 30
CAADCABBDA 30
CAADCABBDA 30
3
CADBABADDA 30
CADBABADDA 30
CADBABADDA 30
3
ADBCCDBDDD 30
ADBCCDBDDD 30
A...

output:

262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440...

result:

ok 6667 lines

Test #35:

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

input:

5000
4
CBDCCADABC 30
CBDCCADABC 30
CBDCCADABC 30
CBDCCADABC 30
4
CCBBAABAAB 30
CCBBAABAAB 30
CCBBAABAAB 30
CCBBAABAAB 30
4
BDBACDBADB 30
BDBACDBADB 30
BDBACDBADB 30
BDBACDBADB 30
4
AAABCBBDDA 30
AAABCBBDDA 30
AAABCBBDDA 30
AAABCBBDDA 30
4
DBAAACDDDA 30
DBAAACDDDA 30
DBAAACDDDA 30
DBAAACDDDA 30
4
AAA...

output:

262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440...

result:

ok 5000 lines

Test #36:

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

input:

100
200
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 30
BCCCDDDBDA 3...

output:

262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440
262440...

result:

ok 100 lines

Test #37:

score: 0
Accepted
time: 85ms
memory: 7544kb

input:

1
20000
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 30
ADBDBCCDBA 3...

output:

262440

result:

ok single line: '262440'

Test #38:

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

input:

6666
3
CCABCDABDB 20
CCABCDABAB 20
CCABCDABBB 30
3
BABCBACBAB 20
BABCBACBAD 20
BABBBACBAB 20
3
BCADBCCDCB 20
DCADBCCDCB 20
CCADBCCDCB 20
3
DBBDBBBBAB 20
DBBDDBBBAB 20
DBBDCBBBAB 30
3
DAABDABCAD 20
DAABDCBCAD 20
BAABDABCAD 20
3
CDBABDCCAD 20
DDBABDCCAD 20
ADBABDCCAD 30
3
CCDADAAACA 20
CCDDDAAACA 20
C...

output:

78732
81648
78732
78732
81648
78732
81648
78732
78732
78732
78732
81648
78732
78732
78732
81648
78732
78732
78732
78732
81648
81648
81648
81648
81648
78732
81648
81648
81648
78732
78732
78732
81648
78732
78732
78732
78732
78732
78732
81648
81648
78732
78732
81648
81648
78732
81648
78732
81648
78732
...

result:

ok 6666 lines

Test #39:

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

input:

6666
3
ABDCCDDDBC 10
ADDDDCCBBD 40
ABDCCDADBC 10
3
DCDAADBAAD 20
DABADDCDBC 30
DCDCCDBAAC 10
3
CDCCBADBBB 10
ABCAADAACD 30
BDCDDCDDBC 30
3
CDADDDCDCD 40
AADDDABDBD 20
CDDDABCDAD 30
3
BDCBDACBBD 20
CDABCADDCC 20
BDCCCABBDD 30
3
BCBDBDDAAB 20
ADCBAADBCB 20
DCAABBBCBD 30
3
CDDDDAAABA 30
CADADBABDA 30
C...

output:

18900
16344
11970
12186
20284
22364
20982
11712
12240
26460
18090
17472
19375
12784
20313
30618
12150
17104
21492
28566
14140
30618
21051
14724
15034
14160
11924
13170
12782
13140
11749
19845
15064
15120
21600
14160
14320
12692
20412
16806
11776
17496
23940
21060
24543
15424
12112
29880
14002
13950
...

result:

ok 6666 lines

Test #40:

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

input:

6666
3
BCDAADCCDB 10
ADACADDADB 10
ACDAADBCAB 10
3
ACBBADABAD 20
CCBACBCBAA 40
ACAACDABBB 20
3
ABDAADCBBD 30
ABACCCADAD 10
ABBAADCBBC 30
3
CBBBADCADB 20
ADDBADCDCA 30
ADABDDAADC 20
3
ACCACDDBCB 10
ABDABCCABB 30
DCBACDDACB 10
3
ABBBDBACDB 20
ABBADBBCAA 10
ABBBBBDCBC 20
3
BDAACDBABC 10
BDACBDBBBD 30
B...

output:

16848
11433
17712
19926
16008
20250
11421
14895
10716
11529
10656
24786
18816
10715
47488
10494
25828
19280
14850
15309
20160
20624
22860
14472
15008
17928
10832
34048
10834
20412
17472
21600
11968
17820
11940
11745
17860
12864
18288
15552
22080
10520
17072
15309
14984
12600
18810
21051
16830
31840
...

result:

ok 6666 lines

Test #41:

score: 0
Accepted
time: 93ms
memory: 5848kb

input:

20000
1
DDCBDCACBC 80
1
DABDCACCBA 80
1
CBADCBDDDC 90
1
CBADBDCBAB 80
1
DDDABDADAA 80
1
CDBBCDDBAB 80
1
BACDBCCCAA 80
1
ABCAADCCCB 80
1
BDACBDAACC 80
1
DCCDCDCDDD 80
1
CACADACCBB 80
1
BABADADBCD 80
1
DDACBDDBBA 80
1
ABCBBDAACA 80
1
BBCABBACCC 80
1
BCDCABCDBB 80
1
ACCBDBBBCB 80
1
CDDDCCBCCC 80
1
BDCA...

output:

405
405
30
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
405
4...

result:

ok 20000 lines

Test #42:

score: 0
Accepted
time: 72ms
memory: 5840kb

input:

10000
2
CCDBDABCCD 80
DCBBDACCCD 80
2
BACBCCABCC 80
BBCBCCDCAC 80
2
BDDABCBDCA 80
ADDADCDDBA 80
2
DDDCDBDDDB 80
DCBADBDADB 80
2
CABDCCCBBD 80
CABBCCCAAA 80
2
ACBADADCCB 80
BDBDDADDCB 80
2
AAADCBABDB 80
DAADCBAAAC 80
2
AACDDDCABA 80
BACDDDBABB 80
2
DDCABCBABD 80
DACDBDBDBD 80
2
BDADDACABB 80
ADACAAAA...

output:

12
6
6
6
6
6
6
12
6
6
52
12
6
12
12
12
6
12
6
6
3
6
6
6
52
6
52
52
12
12
6
6
6
6
52
52
12
12
6
3
52
3
6
6
6
6
6
6
6
12
54
12
12
12
6
6
6
6
6
6
6
6
6
6
6
6
6
6
12
6
6
12
6
6
6
6
3
52
52
6
6
6
6
12
3
12
6
6
6
12
6
6
12
3
6
3
3
6
6
6
12
6
6
3
12
6
6
6
6
2
12
6
52
12
6
6
6
54
6
27
6
6
52
6
12
52
6
6
6
1...

result:

ok 10000 lines

Test #43:

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

input:

6667
3
DDADADCABB 80
DDADADCADA 80
BDADCDCDDB 80
3
CCDCDBBBAA 80
CCDDAABBAB 80
CCDDABBCDA 80
3
BBAABDCDAC 80
BBACDDDDAC 80
BCACBDADCC 80
3
ACCDDDACCA 80
AACDDDBCAA 80
AACDDBDCCA 80
3
BDCBBBBBBB 80
ADDBBBBDBA 80
BDDBBCBBBB 80
3
CCDCABBDCA 90
DCACDBBDCA 80
CDACACBDCA 80
3
DDBADBBDDC 80
ACBBCBBDDC 80
D...

output:

3
1
1
1
3
1
3
1
1
1
1
1
1
3
2
1
1
2
1
1
1
3
3
1
1
1
2
1
1
2
3
1
1
3
1
1
3
3
1
1
3
1
3
1
2
2
1
3
3
5
3
1
1
1
3
1
2
1
1
1
3
1
3
1
1
3
1
1
1
1
3
1
1
1
22
1
1
1
1
1
3
2
1
1
1
2
1
1
2
1
3
4
3
3
2
1
2
3
1
1
1
1
1
1
1
2
2
1
2
4
1
1
1
1
4
1
1
1
1
1
1
1
1
1
4
1
1
1
2
3
3
1
1
2
2
2
1
3
3
1
1
1
2
2
1
2
1
3
1
1...

result:

ok 6667 lines

Test #44:

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

input:

4000
5
BBBDADDBBB 80
BBBBADDBDB 80
BBBDADCDBB 80
BBBDADCDCB 80
BBBDADDDAC 80
5
ADAADDBDAA 80
DCCADDBDAA 80
CCBABDBDAA 80
ACAADABDAA 80
DCBADBBDAA 80
5
CADACDBADD 80
CADACDBAAC 80
CADBDDBADB 80
CADBBDBADA 80
BBDBCDBADC 80
5
BDCAABCACD 90
BCBDABCACD 80
BDCCABAACD 80
BBCBABCACD 80
BDDDDBCACD 80
5
DAAAA...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 4000 lines

Test #45:

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

input:

2000
10
CCDBCABAAD 80
CBDADABCAD 80
CADBDABCAA 80
ACDCDABCAD 80
CCDCAABCAD 80
CCABDABCAC 80
CCDAAABCAD 80
CCDADABBAD 80
CCDBCABCCD 80
CCCBDCBCAD 80
10
DBBDADCCCA 80
CBBAADBCBA 80
CBBDACCCCA 80
ABBDDDCCBA 80
CBBDADCCCB 80
CBBDACDCBA 80
CBBADDCCBA 80
DBBAADCCBA 80
CBBBAACCBA 80
CCBDADCCBB 80
10
AADBDA...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 2000 lines

Test #46:

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

input:

625
32
CBBBBBBCDB 50
ADDAABBBDA 50
DDACCBBCDA 50
ACDBACBCAA 50
DCDDBBDDBC 50
DCCDDBBBBA 50
DCDABDDBDB 50
ADDBBCCADD 50
DADBBBDDCB 50
DCDACBDBDB 50
CCBBBADABA 50
DADBAACADB 50
CBDBBBDBCA 50
DDACBABCDA 50
DCDCBDAABC 50
CDDCBBCABA 50
DCDDABCBCA 50
ACCDBBBBCA 50
DCCBCDDADD 50
CAABBBCADD 50
CBDBBDBDDB 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #47:

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

input:

625
32
BCCDADBCCD 50
BCDCDDCDCD 50
DBBCDCCDCC 50
BDACCCCDDD 50
DCACADDCDD 50
DCADDBBCAD 50
DCBCACCBDA 50
DBBAACCDDC 50
DCCABCACCD 50
DBAACCDACD 50
CCAADCADAD 50
DDADCCCABC 50
DDBDABCCAD 50
DAADABBDDC 50
BCBCBCCDBD 50
DAADAAAADD 50
DCADDAADBC 50
DBADACABDC 50
CAACACCDBA 50
DBADABBCCC 50
DCBAAACCCB 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #48:

score: 0
Accepted
time: 65ms
memory: 5948kb

input:

625
32
BCADBDDBDA 50
BBBDBBAADB 50
CCADCBCDBA 50
DCDABBBCAA 50
DCCBBCCDBA 50
ACCABAADBD 50
CCCABBBBAB 50
BDBDBAACBA 50
BACABDADBC 50
BBCBBADDBA 50
DBCDBAACAC 50
CCDDBBCBDA 50
DBBDBBBDDA 50
BCCACBDADA 50
BCADBDCDBD 50
DCCBBBDDCB 50
BBCDBBCABB 50
BDCBBDDDAC 50
BCBDDDCDDA 50
BBBCBBDAAA 50
BBCCADABAA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #49:

score: 0
Accepted
time: 57ms
memory: 5964kb

input:

625
32
CBCBADACCA 50
CDDAACCACC 50
BDCCABCCBD 50
CBDADADCCC 50
BDACDBACAC 50
CDBBBAAACC 50
CDCADCDCDD 50
DACBDBCAAD 50
CADBDBDDCB 50
DCBBBBCBCC 50
ADBBBDCCCD 50
CACCDBBCAB 50
CDABDBDADA 50
CACBBCCBAC 50
AACBDDAACC 50
BADBBBCCCA 50
CABDDBCACB 50
DDCDBDCCBC 50
CDBCBDDCCC 50
ADDDABCDCC 50
CDBADDCCBB 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #50:

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

input:

625
32
AACADDBACC 50
CDCBDBDCAD 50
DBBDDBDCAC 50
DACDAABAAB 50
ADCDDADCAC 50
AACCDBBDBC 50
ABDDCCDBAD 50
CBCBBBBCAA 50
BBDDABDACD 50
ABCAADDABD 50
DCDDADBAAD 50
BDBDABCAAD 50
BACAABBDAD 50
BCCBDBBDAC 50
DBCBABDBAD 50
AABADDCAAD 50
ADCBDBAADA 50
AACCDBBCDA 50
ABADABABBD 50
ADDDDBBBDC 50
ADDCDABABD 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #51:

score: 0
Accepted
time: 58ms
memory: 6028kb

input:

625
32
BCBBAABADB 50
AAAAABBBDD 50
CABCCBBCCD 50
BDBCBADCBC 50
BAADBABDBC 50
AADDCBBBBD 50
CABDCAABDD 50
AACCDBBBAD 50
ADBCAAADBC 50
DBCAAABBCD 50
BADBADDBCD 50
BBADADBBBA 50
BAABAAADBA 50
AACCCABDBA 50
BDDAADBBBC 50
CADACABBBA 50
AABBCABABB 50
BABBBABCAC 50
BADCACADBA 50
BDACAABACB 50
BABCDADAAC 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #52:

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

input:

625
32
DBCDCABADB 50
CCDCCBCCDB 50
BCCCADCACD 50
ADCCBACACB 50
AADCADCADD 50
DCACBBBACC 50
DDABDACDDC 50
DBBAADCCDB 50
DCABAAACAA 50
DBADACDADD 50
BDACABCCDC 50
DCACCCCCBA 50
BCACCADCDD 50
DCACABACCD 50
DDCCBDCAAB 50
BBAAADCACB 50
ADBCAAAABB 50
DCAACABBAB 50
DCDACAAABB 50
DCDDAABBBB 50
ADAAAAAADC 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #53:

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

input:

625
32
BABCBCDDDA 50
BADBADBABD 50
BABCBACAAD 50
ABDCADABCB 50
CABCBABACB 50
CCBCABCAAA 50
AABDDDDABA 50
BABAACCBDA 50
ABCCADAABB 50
CABDADBBCD 50
BABBDBAABB 50
BABDCAAADC 50
BABBDDABAB 50
AACCAAAABC 50
CCBAADBBCA 50
BABAADBBDD 50
BCBDBBAACD 50
BCBDADDDCB 50
DBBCABACCB 50
CCDCADBDCA 50
CACADAAACA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #54:

score: 0
Accepted
time: 57ms
memory: 6048kb

input:

625
32
BCDACBCDAB 50
CCABBDACAB 50
BCDBAADAAB 50
AABCBBAABA 50
BCBCDAACCB 50
BDCDBCDAAC 50
BDCCDAADDB 50
BBBBBBBAAD 50
BDACBBBDDB 50
BCDCCBABCD 50
ADDDBAAAAB 50
BCBCDAABAD 50
BBDDBAAAAD 50
DDCBDCAAAB 50
BCDABAACCB 50
BDBCBADADB 50
DCDABBAADD 50
ABCCBBABBC 50
BABABBBDAB 50
BACABBABBC 50
DCBBAAAAAB 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #55:

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

input:

625
32
DDAADCADBC 50
DDABABDABC 50
DBBBBBACBD 50
CDBCCACDBB 50
ADDDDACDBB 50
ADCBABADDA 50
BDDCBCADAB 50
DDDDCBCBCC 50
DADBDDADDD 50
CADBCBACDD 50
DDABDDDDBC 50
DCBACDBDBB 50
AABBCDBDBB 50
DADCABCBBB 50
DADACBBDCA 50
DDCDBBCDBC 50
DDABCADBBA 50
CBABCDAABB 50
DADBADBDBA 50
ABBBBBADAB 50
ADDCCDABBD 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #56:

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

input:

625
32
AACCCBCDBD 50
CDBBDBCBCD 50
CBACBBDBDD 50
AABADCCBCD 50
BCBCDDDDBC 50
DAACDCDDAD 50
ACBBBBDACC 50
AAACABCDCA 50
ABACADBDAD 50
ADCBCBDDCB 50
ACDCBDDCCD 50
ACACABAACD 50
DBACCBDABD 50
CBBBCBDDDA 50
DBBCCADBCA 50
BACBDBDBCD 50
ACBCABADAC 50
CDDCDBCDCB 50
BBDCBBDDAA 50
AAAADBDDBC 50
AAAADBDCAD 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #57:

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

input:

625
32
CACADCCBAB 50
BDCCDDBADA 50
DDCADABDCB 50
AABABBCBBA 50
BADCCBBDDA 50
BDCBDBCDCB 50
BDCCABCBBA 50
ACDCDBDBCA 50
BBCBDBABBB 50
DABACBBABA 50
BBCACBCCBA 50
AACBBDCBCA 50
BAABDDBCCC 50
BBBADAACCA 50
BACACBCCAC 50
DACCDBADCD 50
DADCBBBBCC 50
BABDCDBACA 50
DABAABBACC 50
AACAACCCCA 50
CDBADBDBBA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #58:

score: 0
Accepted
time: 57ms
memory: 6068kb

input:

625
32
AADCADACDA 50
BCDCAABCAD 50
ACCCAADBCB 50
AACBBAABAB 50
BBCCADDCCA 50
BDADAAADAB 50
BDDBBAACBD 50
BACAACCCAC 50
BACBADADDA 50
BAABACADBA 50
BCDCCDACCB 50
BACCBADBDC 50
CACBDCBCBB 50
DBACBADCBB 50
DBDCAAACAA 50
BDBBAADCBC 50
ACCDAAADBD 50
DADCADDCBD 50
BACACCACCD 50
BDBDDDACBB 50
CAACACABAB 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #59:

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

input:

625
32
BDBBADBCBC 50
ACCCDCBCBC 50
ACCBAACBBD 50
DDDDAACDBC 50
DCBCAACCDA 50
BCDDCBCABD 50
DDBDBBCAAC 50
CCBCDACABC 50
ADADAADCDC 50
DDBADBCCAC 50
ADBAABCBAB 50
BCCAABCDDC 50
ADBDBDCDDC 50
ACDDBDDBBC 50
BCBCBBCCDB 50
ACAADBDCBB 50
AACDABDCDA 50
AABDADBDBA 50
CCBBADACAC 50
ADBDACBBBB 50
BBBBCBCCBA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #60:

score: 0
Accepted
time: 62ms
memory: 6000kb

input:

625
32
BCDBABCABC 50
CCDCCACADA 50
BCBBBBDCBB 50
BBBBCCCBBC 50
BCCACDBABD 50
CCCBBBDCBB 50
DCBCDDADBB 50
CCCCACCABD 50
CCBDCBACCB 50
CBDACDCACC 50
ACCBDDAABD 50
ACADADCBBB 50
BCBCCDBACA 50
DCCBCACBDB 50
DCBBAADABC 50
ACBDCBCADC 50
BDCDCDCACB 50
CCCBBDBBAB 50
CAABADACBB 50
BCAACDABBB 50
CBAACDCDBA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #61:

score: 0
Accepted
time: 57ms
memory: 6420kb

input:

625
32
AABBDDCABA 50
DDBCABDCDB 50
BBBCADDCBC 50
ADABDBDADB 50
BBBBDDABCB 50
AABCDCCACB 50
BADCADDBDB 50
CCDCDBDBCB 50
ABBBBDCCBB 50
DDDCCDDDBC 50
DDDCCDDABC 50
DDDDCDBBBB 50
ADBDCABBBD 50
CCACDADBDB 50
ADADCDDBCD 50
CDCCBDDDCB 50
ACDCDDCDBA 50
ACBAADDDBC 50
DDCCDDDDDC 50
BBACDADBBA 50
DBBDDADBBA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #62:

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

input:

625
32
CADBAACCDB 50
BDBCACAADA 50
BCDCAABBCC 50
BBDACCAAAC 50
AADBBAAADA 50
ACDCDACDDC 50
ABBBAAABAC 50
ABBDAABADD 50
DDCCABAADB 50
BADAAABADA 50
CADCBACBDA 50
CBABAACDDD 50
CBDDACBCDD 50
BBCCCADADB 50
BBCBBAAADD 50
DADCACACBC 50
CCDDDACCDC 50
CBBBABCADB 50
DBDCAABBCD 50
DDDCCAABDA 50
DBDCBACABB 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #63:

score: 0
Accepted
time: 62ms
memory: 6164kb

input:

625
32
BDCBBBCCBB 50
CBCABAAADB 50
DBACBBACBB 50
BACDBADBAA 50
BAACAACDCD 50
DABCBBDDCB 50
BBAABACDAB 50
BCCCABBABB 50
BBDACDADBB 50
BDAACAABBB 50
AACDBCBDDB 50
DDDCAAACBB 50
ABCCBAACCA 50
DAACDAABBC 50
DCCDBACDBC 50
CACCDACBBC 50
AACBCCAABB 50
BADDBBABAB 50
BCCCCDABBA 50
BCCDBABABD 50
CCCDCAADBA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #64:

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

input:

625
32
BCDDBBDBCD 50
CACDDADCDA 50
DDCDABABAB 50
DBDCABABAB 50
DDDACABBDA 50
BADCABBBBC 50
BDDDABBABA 50
DACDBDBCDA 50
DCADBBDCAA 50
DBADCBDABA 50
DABBBBDADD 50
DBDDBBCDDD 50
DCBCBBDBDB 50
BADAABCABA 50
BCDACBDBDC 50
BADAACADDA 50
DADAACAACA 50
AADACBDBBD 50
BDAAABDBDD 50
AAADCADDDA 50
AABDABCBBD 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #65:

score: 0
Accepted
time: 57ms
memory: 6112kb

input:

625
32
BCAAADDCBC 50
DABBDCCCAC 50
ACAACADCAD 50
ABADACDDAA 50
CBABCBBAAC 50
CDABACDACC 50
ADADCCCCDC 50
BCDBBCBAAB 50
ACABBBABAA 50
AADADDBCAC 50
AACDACBDAD 50
DCBAAABCAB 50
CAAAACDCAB 50
ACCCCCCCBC 50
ADAAACDBAD 50
DDCBACBCCA 50
DCCCCCBCBC 50
ADABDDACAB 50
CCCBAAABAC 50
ADCCACDCBC 50
DCDBDCBBDC 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #66:

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

input:

625
32
CBBACACAAD 50
CCCDCDBADC 50
BDADCCAAAB 50
CDADAABBAD 50
CBACDCCBAD 50
BAAABCBCCD 50
CBBCDBBABD 50
ACADCCDAAB 50
BCADBCDCCD 50
CAADDBCABD 50
CBABCBACCB 50
DBACCDDAAD 50
CBAAAABADA 50
CBBDBDDAAD 50
ABCDCCABCB 50
BADDDCCACD 50
CBDDCCABBC 50
ABDCCCBCCC 50
ADACCBBACC 50
DDDDDCBBCD 50
BBABCCCDCA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #67:

score: 0
Accepted
time: 57ms
memory: 6472kb

input:

625
32
ADBBDBBABD 50
ACDBBCBDCC 50
ACACDBCADC 50
AACBBDDCDD 50
DDACBDBDBD 50
DCADDDCBCD 50
ADAADBBCDB 50
DBDBDABDDB 50
DDABDCCDDB 50
DCABDBBACA 50
BBABADBBDA 50
DCABDADCDB 50
ACADDADBAD 50
ACDCDBBAAD 50
AAABCABCDB 50
BCAACDDDBD 50
BDBACDBDDD 50
DCADBDCADD 50
CDABDBADDA 50
ACDBDDCABB 50
ADABBDBCBA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #68:

score: 0
Accepted
time: 58ms
memory: 6040kb

input:

625
32
ABDADDBADD 50
DAADDBACAB 50
BBCDDBDBBB 50
DDBDCDADDB 50
DBDDCCAADA 50
ABAADDBBDB 50
BDDCBBACCB 50
BBBBBDADDC 50
DCCDDDACBD 50
DCDBDABCDB 50
CBCACDAADB 50
BBDCCAABBB 50
BCCBACACDB 50
BCDDDDDACD 50
ABADDAABAB 50
BBABDDCBDD 50
DAAADAACDB 50
CBDBAACCDB 50
AABADDBCDB 50
CBDADDCDBB 50
CBDBBDABDA 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #69:

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

input:

625
32
ADCDDBDADD 50
ADABDADDBA 50
ABBDCDDCAC 50
BDBBACCDCD 50
DDBBABACAD 50
AABBADDCCD 50
BBBDABACAD 50
AADCABDDAA 50
ADABDBDDDD 50
AABDADBACD 50
ADDCAADACA 50
ADBBBABDDC 50
ABBDCCBDCD 50
AAABAABCAD 50
ABBDCBBDAA 50
ACBCABCDAB 50
DDBCDDDDAC 50
BDDCCBDDAD 50
CCBAAADAAC 50
DCBDADDBCD 50
ABCDACDACD 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #70:

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

input:

625
32
CAAAADDACD 50
ADBDABCBCD 50
CACACBCBAD 50
ABADABDABD 50
AABDDDACAD 50
CBDDABCCAB 50
CABDBDCBAB 50
DBBBDBDDCD 50
CCCDABADBC 50
BDBABBCDAD 50
BACCABADAA 50
BCDDACADAD 50
BABDADCDCA 50
CDADBBDBAA 50
AADDCDDBAD 50
CACDADDBDA 50
AACDBBADDD 50
CCBCDBDBCD 50
AACDBBAAAD 50
BBBDDDADAD 50
CADCDBCBAD 50...

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
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
...

result:

ok 625 lines

Test #71:

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

input:

625
32
ACBABDDACC 50
ACDADDDBCC 50
DBCACDDBCC 50
CCBDBDBCCD 50
DDCABCBADC 50
BCCABCBDBA 50
BCBAACBCCC 50
DCAABBDCBC 50
CCAACBABDB 50
CCABBBAABC 50
DCDBBBBBBA 50
CABADBDBBC 50
CCCCBDABDD 50
CCBBBABDCA 50
CDCCBCCBCD 50
DDCABBCBDB 50
CCCBBCBDAA 50
BBCBBACBCC 50
CCDABBCCDB 50
ACBDBBCBDC 50
DCCCBBCDCB 50...

output:

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

result:

ok 625 lines

Test #72:

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

input:

625
32
CACDABDBDC 50
ADABCBCDCC 50
ACABADCDDC 50
DDAABDCDDB 50
DBBBABCBDD 50
DDCCABCDAB 50
DADAACCDDD 50
CDCDABBABC 50
AABDCBCADC 50
CDBCADBDAA 50
DCAABBCDBC 50
BCAAADADDC 50
CDDDABCCCD 50
DBBBABCADD 50
CCBCDCCADC 50
BDBABBADAA 50
CCBDABDCDA 50
CCDABBCDAD 50
CDCAAAAABC 50
CADDBDCDDC 50
CDCDBACDBC 50...

output:

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

result:

ok 625 lines

Test #73:

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

input:

625
32
BDAADDBDAA 50
DDCBBDCDAA 50
DADCCACDAA 50
BDCAABCBCA 50
BDAAAADDBA 50
BDAAAACCBA 50
ACAACACDAB 50
DDACACCCDD 50
DDABCBCBAD 50
DDACAADBCA 50
CDACCDCBBA 50
DDAAABAABA 50
BBACCCCBAA 50
ACDCBCCDCA 50
BAAAACCBAA 50
CDAAAACDDC 50
DDDCACADDA 50
BDCCCBADCA 50
DDCCCBCDDB 50
BDCCCBBDCA 50
DCBCDCCDAA 50...

output:

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

result:

ok 625 lines

Test #74:

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

input:

625
32
ACDCCCBCDA 50
ACBCCCBACD 50
AADCCBDACD 50
ACBADBBCCD 50
AABADCBACA 50
AABACCBACD 50
BCBCDBDCDD 50
BCBADBDCCD 50
AADACBBCDD 50
AADCCCBADA 50
AADADBDCCA 50
ACDCDCDCDA 50
ACBADCBACD 50
BADACBDCCA 50
ACBADCBCCA 50
BCBADBBCCA 50
BABACBBACD 50
BADACBBACA 50
BABCCCDACA 50
BCBCCBBCDD 50
AADADBDCDD 50...

output:

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

result:

ok 625 lines

Test #75:

score: 0
Accepted
time: 57ms
memory: 6380kb

input:

625
32
CACCAACDAB 50
CDBCDDDDAD 50
CDDCDADACC 50
CCBCBCDBBB 50
DCBCACDBAB 50
CADDBDDADA 50
ABACACAACB 50
DAACACAAAB 50
BABDDDDDDB 50
CBBDACAAAB 50
CACCACBAAA 50
AABCCDBABC 50
CABCCAABCC 50
AAACCBDADB 50
DACCABDDBB 50
CAACBCAADB 50
CABCCBDBAA 50
CCBAADACAB 50
CCDDACBACB 50
BADCACAACD 50
CCBCDDBDAB 50...

output:

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

result:

ok 625 lines

Extra Test:

score: 0
Extra Test Passed