#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  pair<int, char> arr[26];
  for (int i = 0; i < 26; i++) {
    arr[i].first = 0;
    arr[i].second = i + 'a';
  }
  string s;
  cin >> s;
  int k;
  cin >> k;
  unordered_set<char> ss;
  for (int i = 0; i < s.size(); i++) {
    int mask = s[i] - 'a';
    ss.insert(s[i]);
    arr[mask].first++;
  }
  sort(arr, arr + 26, [](pair<int, char> lhs, pair<int, char> rhs) {
    if (lhs.first == 0) {
      return false;
    } else if (rhs.first == 0) {
      return true;
    }
    return lhs.first < rhs.first;
  });
  int removed = 0;
  int marked[26] = {0};
  for (int i = 0; i < 26; i++) {
    if (arr[i].first != 0) {
      if (k >= arr[i].first) {
        removed++;
        k -= arr[i].first;
        marked[arr[i].second - 'a'] = 1;
      } else {
        break;
      }
    }
  }
  cout << ss.size() - removed << '\n';
  for (auto each : s) {
    if (!marked[each - 'a']) {
      cout << each;
    }
  }
  cout << '\n';
  return 0;
}
