#include #include #include using namespace std; multiset st; int how_many[30], h_m[30]; int main() { string a; cin >> a; for (int i = 0; i < a.size(); ++i) ++how_many[a[i] - 'a']; int n; cin >> n; for (int i = 1; i <= n; ++i) { cin >> a; memset (h_m, 0, sizeof h_m); for (int i = 0; i < a.size(); ++i) ++h_m[a[i] - 'a']; int okay = 1; for (int i = 0; i < 30 && okay; ++i) if (how_many[i] < h_m[i]) okay = 0; if (okay) st.insert(a); } for (set::iterator it = st.begin(); it != st.end(); ++it) cout << *it << "\n"; return 0; }