#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, k, i = 0, j = 0, c = 0, sum = 0, pos = 0, temp, end = 0, l;
  char t;
  vector<int> v;
  vector<char> ch;
  string str, s = "";
  cin >> str;
  cin >> k;
  l = str.length();
  n = 0;
  char arr[l];
  for (i = 0; i < l; i++) {
    arr[i] = str[i];
  }
  sort(arr, arr + l);
  i = 0;
  while (i < l) {
    if (arr[i] != arr[n]) {
      v.push_back(c);
      ch.push_back(arr[n]);
      n = i;
      c = 0;
      continue;
    }
    c++;
    i++;
  }
  v.push_back(c);
  ch.push_back(arr[n]);
  n = v.size();
  for (i = 0; i < n - 1; i++) {
    for (j = 0; j < n - i - 1; j++) {
      if (v[j + 1] < v[j]) {
        temp = v[j];
        v[j] = v[j + 1];
        v[j + 1] = temp;
        t = ch[j];
        ch[j] = ch[j + 1];
        ch[j + 1] = t;
      }
    }
  }
  for (i = 0; i < v.size(); i++) {
    sum += v[i];
    if (sum >= k) {
      pos = i;
      break;
    }
  }
  if (sum == k) {
    j = 0;
    cout << v.size() - pos - 1 << endl;
    for (i = 0; i <= pos; i++) {
      while (j < str.length()) {
        if (str[j] == ch[i]) {
          j++;
          continue;
        }
        s += str[j];
        j++;
      }
      str = s;
      s = "";
      j = 0;
    }
    cout << str << endl;
  } else if (sum > k) {
    j = 0;
    cout << v.size() - pos << endl;
    for (i = 0; i < pos; i++) {
      while (j < str.length()) {
        if (str[j] == ch[i]) {
          j++;
          continue;
        }
        s += str[j];
        j++;
      }
      str = s;
      s = "";
      j = 0;
    }
    cout << str << endl;
  } else if (sum < k)
    cout << 0 << endl;
}
