#include #include #include #include using namespace std; vector dict; map subsets; int n; string word, code; char x; int main() { //freopen("txt.in", "r", stdin); for(int i = 1; i <= 26; ++i) { cin >> x >> code; dict.push_back(code); } cin >> n; for(int i = 1; i <= n; ++i) { cin >> word; string key; for(const auto &it : word) { key += dict[it - 'a']; } subsets[key]++; } int maxx = -1; for(const auto &it : subsets) { if(it.second > maxx) { maxx = it.second; } } if(maxx == 1) maxx = -1; cout << maxx; return 0; }