#include <bits/stdc++.h>
using namespace std;
string ss;
int n;
int w[30] = {0};
const int inf = (int)1e5 + 10;
vector<vector<int> > dp;
inline void read() {
  cin >> ss;
  cin >> n;
  for (int i = 0; i < (int)(ss).length(); ++i) {
    w[(ss[i] - 'a') + 1]++;
  }
}
inline void proc() {
  int i, j;
  dp.assign(30, vector<int>(inf * 2, -1));
  dp[0][0] = 0;
  pair<int, int> best(-1, -1);
  for (i = 1; i <= 26; ++i) {
    for (j = n; j >= 0; --j) {
      if (w[i] && dp[i - 1][j] != -1) {
        dp[i][j + w[i]] = dp[i - 1][j] + 1;
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
    for (j = n; j >= 0; --j) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      if (dp[i][j] >= best.first) {
        best.first = dp[i][j];
        best.second = j;
      }
    }
  }
  int first = best.second;
  j = best.first;
  i = 26;
  while (j) {
    while (dp[i][first] == dp[i - 1][first]) {
      --i;
    }
    first -= w[i];
    w[i] = 0;
    --j;
  }
  int unique = 0;
  for (i = 1; i <= 26; ++i) {
    if (w[i]) {
      ++unique;
    }
  }
  printf("%d\n", unique);
  for (int i = 0; i < (int)(ss).length(); ++i) {
    if (w[(ss[i] - 'a') + 1]) {
      printf("%c", ss[i]);
    }
  }
  printf("\n");
}
int main() {
  read();
  proc();
  return 0;
}
