class Solution {
public:
vector<int> loo(string a){
vector<int> cha;
for(auto x:a){
cha[x-'a']++;
}
return cha;
}
vector<string> wordSubsets(vector<string>& A, vector<string>& B) {
vector <int> max_b;
for(auto x:B){
vector<int> temp;
temp = loo(x);
for(int i=0;i<26;i++){
max_b[i] = max(max_b[i],temp[i]);
}
}
vector<string> ret;
for(auto x:A){
vector<int> temp;
temp = loo(x);
int t = 1;
for(int i=0;i<26;i++){
if(max_b[i]>temp[i]){
t = 0;
break;
}
}
if(t==1){
ret.push_back(x);
}
}
return ret;
}
};