#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;
constexpr LL MOD = 1e9 + 7;

int main() {
	cin.tie(nullptr)->sync_with_stdio(false);

	int k;
	string s;
	cin >> s >> k;
	for (char &c : s) c = isdigit(c)? (c - '0') : (c - 'A' + 10);


	vector< LL> dp(17);
	dp[1] = s[0] - 1;
	int mask = 1 << s[0];

	for (int i = 1; i < int(s.size()); i++) {
		int d = s[i];
		vector< LL> ndp(17);

		for (int j = 0; j <= 16; j++) {
			(ndp[j] += dp[j] * j) %= MOD;
			if (j + 1 <= 16) (ndp[j + 1] += (16 - j) * dp[j]) %= MOD;
		}

		ndp[1] += 15;
		for (int j = 0; j < d; j++) ndp[__builtin_popcount(mask | (1 << j))]++;

		mask |= (1 << d);
		dp = ndp;
	}

	dp[__builtin_popcount(mask)]++;

	cout << dp[k] << endl;
}
#include <bits/stdc++.h>
using namespace std;

//.define
// #define FILE_IN_OUT
#define RET(_x)    cout << (_x) << '\n'; return;
#define all(_obj)  (_obj).begin(), (_obj).end()
#define loop(_n)   for (int i = 0; i < (_n); ++i)
#define sz(_obj)   static_cast<int>((_obj).size())
#ifdef SHJ_LOCAL
#define debug(_x)  std::cerr << (#_x) << " = " << (_x) << '\n' << std::flush;
#else
#define debug(_x)  {}
#endif
#define endl "\n"
template<typename P, typename Q>
inline P CeilDiv(P _dividend, Q _divider) {
    return static_cast<P>((_dividend - 1LL + _divider) / _divider);
}
template<typename Tp>
inline void outarr(Tp _begin, Tp _end, const char* _delim = " ") {
    for (Tp current = _begin; current != _end; ++current) {
        std::cout << *current << _delim;
    }
    std::cout << '\n';
}

//.constant
using ll = int64_t;
using pii = std::pair<int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr int MOD = static_cast<int>(1e9 + 7);

//.data
int Add(int x, int y) {
    x += y;
    return x < MOD ? x : x - MOD;
}

int Sub(int x, int y) {
    x -= y;
    return x >= 0 ? x : x + MOD;
}

int Mul(int x, int y) {
    return int(1LL * x * y % MOD);
}

//.code
void SolveTask() {
    int n;
    cin >> n;
    vector<int> arr(n);
    ll sum = 0;
    loop(n) {
        cin >> arr[i];
        sum += arr[i];
    }
    double avg = 1.0 * sum / n;
    sort(all(arr), greater<>());
    double ans = avg;
    loop(n) {
        double x = arr[i] / 2.0;
        ans = min(ans, avg + x - (i * (x + x) + sum) / n);
        sum -= arr[i];
    }
    cout << fixed << setprecision(10) << ans << endl;
}

int main() {
#ifdef FILE_IN_OUT
    std::ifstream cin ("input.txt",  std::ios::in);
    std::ofstream cout("output.txt", std::ios::out);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int test_cases = 1;
    // cin >> test_cases;
    for (int yt = 1; yt <= test_cases; ++yt) {
        SolveTask();
    }
#ifdef FILE_IN_OUT
    cin.close();
    cout.close();
#endif
    return 0;
}