#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1000000007;
const int N_MAX = 100000;

long long mod(long long a) {
	a %= MOD;
	return a >= 0 ? a : a+MOD;
}

long long inverse[N_MAX+1+64];
long long factorial[N_MAX+1+64];
long long factorial_inverse[N_MAX+1+64];

void calc(int n) {
	inverse[1] = 1;
	factorial[0] = factorial[1] = 1;
	factorial_inverse[0] = factorial_inverse[1] = 1;
	for (int i = 2; i <= n; i++) {
		inverse[i] = MOD - inverse[MOD%i] * (MOD/i) % MOD;
		factorial[i] = i * factorial[i-1] % MOD;
		factorial_inverse[i] = inverse[i] * factorial_inverse[i-1] % MOD;
	}
}

long long comb(long long n, long long k) {
	return factorial[n] * (factorial_inverse[k] * factorial_inverse[n-k] % MOD) % MOD;
}

long long rep_comb(long long n, long long k) {
	return comb(n + k - 1, k);
}

vector<pair<long long, int>> prime_factorization(long long n) {
	vector<pair<long long, int>> v;
	for (long long i = 2; i * i <= n; ++i) {
		int e = 0;
		while (n % i == 0) {
			++e;
			n /= i;
		}
		if (e != 0) v.emplace_back(i, e);
	}
	if (n != 1) v.emplace_back(n, 1);
	return v;
}

int main() {
	calc(N_MAX+65);
	long long n, m;
	cin >> n >> m;
	long long ans = 1;
	auto v = prime_factorization(m);
	for (auto el : v) {
		long long e = el.second;
		ans = mod(ans * rep_comb(n, e));
	}
	cout << ans << endl;
	return 0;
}
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

ll dp[310][310][310];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll len = S.size();
    ll K;
    cin >> K;
    dp[0][0][0] = 0;
    REP(i, 0, len) {
        REP(k, 0, K + 1) {
            dp[i][i + 1][k] = 1;
        }
    }
    REP(j, 2, len + 1) {
        REP(i, 0, len) {
            if (i + j > len) {
                continue;
            }
            REP(k, 0, K + 1) {
                dp[i][i + j][k] = max(dp[i][i + j - 1][k], dp[i + 1][i + j][k]);
                if (k > 0) {
                    dp[i][i + j][k] = max(dp[i][i + j][k], dp[i + 1][i + j - 1][k - 1] + 2);
                }
                if (S[i] == S[i + j - 1]) {
                    dp[i][i + j][k] = max(dp[i][i + j][k], dp[i + 1][i + j - 1][k] + 2);
                }
            }
        }
    }
    // REP(i, 0, len + 1) {
    //     REP(j, 0, len + 1) {
    //         REP(k, 0, K + 1) {
    //             cout << dp[i][j][k] << " ";
    //         }
    //         cout << "aaa ";
    //     }
    //     cout << endl;
    // }
    ll ans = 0;
    REP(i, 0, K + 1) {
        ans = max(ans, dp[0][len][i]);
    }
    cout << ans << endl;
}
