#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long i, j, k, n, l, m, t;
  t = 1;
  while (t--) {
    map<char, long long> ma;
    string s;
    cin >> s;
    cin >> k;
    n = s.size();
    for (i = 0; i < n; i++) {
      ma[s[i]]++;
    }
    set<pair<long long, char>> sa;
    for (auto i : ma) {
      sa.insert({i.second, i.first});
    }
    vector<char> va;
    long long temp = k;
    for (auto i : sa) {
      if (temp > 0) {
        va.emplace_back(i.second);
        temp -= i.first;
      }
    }
    string ans = "";
    for (auto i : va) {
      if (k > 0) {
        for (auto& j : s) {
          if (j == i and k > 0) {
            j = '#';
            k--;
          }
        }
      }
    }
    int ch[256] = {0};
    long long dis = 0;
    for (i = 0; i < n; i++) {
      if (s[i] != '#') {
        ans += s[i];
        ch[s[i]]++;
        if (ch[s[i]] == 1) {
          dis++;
        }
      }
    }
    cout << dis << "\n";
    cout << ans << "\n";
  }
}
