#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
const int mod = 1e9 + 7;
using type = int;
struct Matrix {
vector <vector <type> > data;
int row() const { return data.size(); }
int col() const { return data[0].size(); }
auto & operator [] (int i) { return data[i]; }
const auto & operator[] (int i) const { return data[i]; }
Matrix() = default;
Matrix(int r, int c): data(r, vector <type> (c)) { }
Matrix(const vector <vector <type> > &d): data(d) { }
friend ostream & operator << (ostream &out, const Matrix &d) {
for (auto x : d.data) {
for (auto y : x) out << y << ' ';
out << '\n';
}
return out;
}
static Matrix identity(long long n) {
Matrix a = Matrix(n, n);
while (n--) a[n][n] = 1;
return a;
}
Matrix operator * (const Matrix &b) {
Matrix a = *this;
assert(a.col() == b.row());
Matrix c(a.row(), b.col());
for (int i = 0; i < a.row(); ++i)
for (int j = 0; j < b.col(); ++j)
for (int k = 0; k < a.col(); ++k){
c[i][j] += 1ll * a[i][k] % mod * (b[k][j] % mod) % mod;
c[i][j] %= mod;
}
return c;
}
Matrix pow(long long exp) {
assert(row() == col());
Matrix base = *this, ans = identity(row());
for (; exp > 0; exp >>= 1, base = base * base)
if (exp & 1) ans = ans * base;
return ans;
}
};
const int N = 1001;
const int M = 101;
int n, m;
string s;
int dfa[26][M];
void buildDFA() {
dfa[s[0] - 'A'][0] = 1;
for (int x = 0, j = 1; j < m; j++) {
for (int c = 0; c < 26; c++) {
dfa[c][j] = dfa[c][x];
}
dfa[s[j] - 'A'][j] = j + 1;
x = dfa[s[j] - 'A'][x];
}
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit); // RTE if input wrong datatype
cin >> n >> s;
m = sz(s);
buildDFA();
Matrix path(m + 1, m + 1);
for (int k = 0; k < 26; k++) {
for (int i = 0; i < m; i++) {
path[i][dfa[k][i]] += 1;
}
}
path[m][m] = 26;
Matrix ans = path.pow(n);
cout << (ans[0][m]);
}