#include #include #include #define HASH1 120 #define HASH2 130 #define MODULO 1000004233 char morse[26][5], word[100001], buffer[400001]; struct HASHES { int hash1, hash2; } ; HASHES hashes[100001]; int doHash(int hashs, char* word) { long long result = 0; long long multiplier = 1; while (*word != 0) { result = (result + multiplier * (*word)) % MODULO; multiplier = (multiplier * hashs) % MODULO; word += 1; } return result; } bool comparator(const HASHES &a, const HASHES &b) { if (a.hash1 == b.hash1) { return a.hash2 < b.hash2; } return a.hash1 < b.hash1; } int main() { char *p; int it, noWords, current = 1, result = 0; //freopen("in.txt", "r", stdin); for(it = 0; it < 26; ++it) { scanf("%*c %s\n", morse[it]); } scanf("%d\n", &noWords); for (it = 0; it < noWords; ++it) { scanf("%s", word); buffer[0] = 0; for (p = word; *p; ++p) { strcat(buffer, morse[*p - 'a']); } hashes[it].hash1 = doHash(HASH1, buffer); hashes[it].hash2 = doHash(HASH2, buffer); } std::sort(hashes, hashes + noWords, comparator); for (it = 1; it < noWords; ++it) { if (hashes[it - 1].hash1 == hashes[it].hash1 && hashes[it - 1].hash2 == hashes[it].hash2) { ++current; } else { if (current > result) result = current; current = 1; } } printf("%d", result); return 0; }