#include <bits/stdc++.h>
using namespace std;
struct pc {
  char a;
  int b;
  pc(char a, int b) {
    this->a = a;
    this->b = b;
  }
};
bool cf(const pc &a, const pc &b) { return a.b < b.b; }
int main() {
  map<char, int> mc;
  vector<pc> vpc;
  char s[100000 + 5];
  scanf("%s", s);
  int n;
  cin >> n;
  int len = strlen(s);
  for (int i = 0; i < len; ++i) {
    ++mc[s[i]];
  }
  for (map<char, int>::iterator it = mc.begin(); it != mc.end(); ++it) {
    vpc.push_back(pc(it->first, it->second));
  }
  sort(vpc.begin(), vpc.end(), cf);
  int ret = 0, id = vpc.size();
  string sr = "";
  for (int i = 0; i < (int)vpc.size(); ++i) {
    if (n < vpc[i].b) {
      id = i;
      break;
    }
    n -= vpc[i].b;
  }
  for (int i = id; i < (int)vpc.size(); ++i) {
    ++ret;
    for (int j = 0; j < vpc[i].b; ++j) sr += vpc[i].a;
  }
  map<char, bool> ms;
  for (int i = 0; i < (int)sr.size(); ++i) {
    ms[sr[i]] = true;
  }
  cout << ret << endl;
  for (int i = 0; i < len; ++i) {
    if (ms[s[i]]) cout << s[i];
  }
  return 0;
}
