6 #define lookup(i, x1, x2) (i)[((x1)-'A')+((x2)-'A')*26]
12 char template[26*26] = {0};
13 unsigned long input1
[26*26] = {0};
14 unsigned long input2
[26*26] = {0};
15 unsigned long *input
= input1
;
16 unsigned long *newinput
= input2
;
18 int first
= getchar();
20 unsigned long freq
[26] = {0};
21 while ( (c
= getchar()) != '\n') {
22 lookup(input
, oldc
, c
) = 1;
26 while (getline(&buf
, &len
, stdin
) != -1) {
29 lookup(template, buf
[0], buf
[1]) = buf
[6];
32 for (int step
= 0; step
< 40; step
++) {
33 for (char x
= 'A'; x
<='Z'; x
++) {
34 for (char y
= 'A'; y
<='Z'; y
++) {
35 char ins
= lookup(template, x
, y
);
37 unsigned long freq
= lookup(input
, x
, y
);
38 lookup(newinput
, x
, ins
) += freq
;
39 lookup(newinput
, ins
, y
) += freq
;
43 unsigned long *t
= newinput
;
46 memset(&newinput
[0], 0, sizeof(input1
));
49 for (char x
= 'A'; x
<='Z'; x
++) {
50 for (char y
= 'A'; y
<='Z'; y
++) {
51 freq
[x
-'A'] += lookup(input
, x
, y
);
52 freq
[y
-'A'] += lookup(input
, x
, y
);
58 unsigned long min
= ULONG_MAX
, max
= 0;
59 for (int i
= 0; i
<26; i
++) {
60 max
= freq
[i
] > max
? freq
[i
] : max
;
61 min
= freq
[i
] > 1 && freq
[i
] < min
? freq
[i
] : min
;
64 printf("%lu\n", max
/2-min
/2);