#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long k, n;
  string s;
  cin >> s;
  cin >> k;
  n = s.size();
  k = max(0ll, n - k);
  map<char, long long> mp, mp2;
  set<long long> st;
  set<pair<long long, char>> stt;
  for (long long i = 0; i < n; i++) {
    mp[s[i]]++;
  }
  for (auto it : mp) {
    stt.insert({it.second, it.first});
  }
  for (auto it = stt.rbegin(); it != stt.rend(); it++) {
    for (long long i = 0; i < it->first && k; i++) {
      mp2[it->second]++;
      k--;
      st.insert(it->second);
    }
    if (k <= 0) break;
  }
  string ans;
  for (long long i = 0; i < n; i++) {
    if (mp2[s[i]]) {
      ans += s[i];
      mp2[s[i]]--;
    }
  }
  cout << st.size() << "\n";
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
