#include #include #include #define HASH1 120 #define HASH2 130 #define MODULO 1000004233 char morse[26][10], word[200001], buffer[1000000]; struct HASHES { int hash1, hash2; } ; HASHES hashes[200001]; 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) { fgets(buffer, 20, stdin); strcpy(morse[it], buffer + 2); morse[it][strlen(morse[it]) - 1] = 0; } fgets(buffer, 100, stdin); sscanf(buffer, "%d", &noWords); for (it = 0; it < noWords; ++it) { fgets(word, 200000, stdin); buffer[0] = 0; for (p = word; *p && ((*p) != '\n'); ++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; }