#include <bits/stdc++.h>
using namespace std;
bool characters[27];
bool compare(pair<int, char>& a, pair<int, char>& b) {
  return a.first > b.first;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int k;
  cin >> k;
  map<char, int> m;
  for (int i = 0; i < s.size(); i++) {
    m[s[i]]++;
  }
  vector<pair<int, char> > v;
  for (map<char, int>::iterator itr = m.begin(); itr != m.end(); ++itr) {
    v.push_back({itr->second, itr->first});
  }
  sort(v.begin(), v.end(), compare);
  vector<pair<int, char> >::iterator itr = --v.end();
  for (itr; itr != (--v.begin()); --itr) {
    if ((*itr).first <= k) {
      k -= (*itr).first;
      v.erase(itr);
    }
  }
  for (int i = 0; i < v.size(); i++) {
    characters[v[i].second - 'a'] = true;
  }
  cout << v.size() << endl;
  for (int i = 0; i < s.size(); i++) {
    if (characters[s[i] - 'a']) {
      cout << s[i];
    }
  }
  return 0;
}
