#include <bits/stdc++.h>
using namespace std;
bool compare(const pair<char, int> &p1, const pair<char, int> &p2) {
  return p1.second > p2.second;
}
int main() {
  string str;
  cin >> str;
  int k;
  cin >> k;
  if (k >= str.size()) {
    cout << 0 << endl;
    cout << "" << endl;
    return 0;
  }
  int char_count = 0;
  map<char, int> ch_map;
  for (int i = 0; i < str.size(); i++) {
    if (ch_map.find(str[i]) == ch_map.end()) {
      ch_map[str[i]] = 1;
      char_count++;
    } else
      ch_map[str[i]]++;
  }
  if (k == 0) {
    cout << char_count << endl;
    cout << str << endl;
    return 0;
  }
  vector<pair<char, int> > v;
  copy(ch_map.begin(), ch_map.end(), back_inserter(v));
  make_heap(v.begin(), v.end(), compare);
  int so_far = 0, symbs = 0;
  map<char, int> ch_used;
  while (so_far <= k && !v.empty()) {
    pair<char, int> curr = v.front();
    if (so_far + curr.second > k) {
      ch_used[curr.first] = k - so_far;
      break;
    }
    symbs++;
    so_far += curr.second;
    pop_heap(v.begin(), v.end(), compare);
    v.pop_back();
    ch_used[curr.first] = curr.second;
  }
  symbs = ch_map.size() - symbs;
  int deleted = 0;
  string new_str = "";
  for (int i = 0; i < str.size() && deleted <= k; i++) {
    if (ch_used.find(str[i]) != ch_used.end() && ch_used[str[i]] > 0) {
      deleted++;
      ch_used[str[i]]--;
    } else
      new_str = new_str + str[i];
  }
  cout << symbs << endl;
  cout << new_str << endl;
  return 0;
}
