#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  map<char, int> m;
  for (size_t i = 0; i < s.size(); i++) {
    m[s[i]]++;
  }
  set<pair<int, char> > ss;
  map<char, int>::iterator it = m.begin();
  for (; it != m.end(); ++it) {
    ss.insert(make_pair(it->second, it->first));
  }
  set<char> del;
  while (!ss.empty()) {
    pair<int, char> p = *ss.begin();
    int sub = p.first;
    if (k >= sub) {
      del.insert(p.second);
      k -= sub;
    } else {
      break;
    }
    ss.erase(ss.begin());
  }
  cout << ss.size() << endl;
  for (size_t i = 0; i < s.size(); i++) {
    if (!del.count(s[i])) {
      cout << s[i];
    }
  }
  cout << endl;
  return 0;
}
