// #include //atcoder #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; // using namespace atcoder; // atcoder // using mint = mint1000000007; // atcoder // using mint = static_modint<1000>; template using vec = vector; template using vec2 = vec>; template using pq = priority_queue, greater>; using ll = long long; using ld = long double; using vi = vector; using vi2 = vector>; using si = set; using pii = pair; using pdd = pair; using mii = map; const int INF = 1 << 30; const ll LINF = 1ll << 60; const long double LPI = acos(-1.0); const double PI = acos(-1.0); ll mod = 1000000007; #define MP(a, b) make_pair((a), (b)) #define MT(...) make_tuple(__VA_ARGS__) #define sz(x) (int)(x).size() #define fi first #define se second #define FOR(i, a, b) for (ll i = (a); i < (b); i++) #define REP(i, x) for (ll i = 0; i < (int)(x); i++) #define REPS(i, x) for (ll i = 1; i <= (int)(x); i++) #define RREP(i, x) for (ll i = ((int)(x)-1); i >= 0; i--) #define RREPS(i, x) for (ll i = ((int)(x)); i > 0; i--) #define endl "\n" #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define SORT(v) sort(ALL(v)); #define RSORT(v) sort(RALL(v)); #define REV(v) reverse(ALL(v)) #define IN(type, a) \ type a; \ cin >> a; #define LN(a) \ ll a; \ cin >> a; #define VIN(type, a, n) \ vector a(n); \ cin >> a; #define YES(n) cout << ((n) ? "YES" : "NO") << endl; #define Yes(n) cout << ((n) ? "Yes" : "No") << endl; #define COUT(x) cout << (x) << endl; #define CERR(x) cerr << (x) << endl; #define DCOUT(x, n) cout << fixed << setprecision(n) << (x) << endl; #define ENDL cout << endl; #define SP cout << " "; #define Dump(x) cout << #x << " : " << x << endl; #define PB(x) emplace_back(x) #define HOGE COUT("HOGE") #define AJA COUT("AJA") template inline T max(vector &v) { return *max_element(v.begin(), v.end()); } template inline T min(vector &v) { return *min_element(v.begin(), v.end()); } template istream &operator>>(istream &i, vector &v) { REP(j, sz(v)) i >> v[j]; return i; } template string join(const vector &v, const string &d = "") { stringstream s; REP(i, sz(v))(i ? s << d : s) << v[i]; return s.str(); } template ostream &operator<<(ostream &o, const vector &v) { if (sz(v)) o << join(v, " "); return o; } template istream &operator>>(istream &i, pair &v) { return i >> v.fi >> v.se; } template ostream &operator<<(ostream &o, const pair &v) { return o << v.fi << "," << v.se; } template inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } template inline T gcd(T a, T b) { if (b == 0) { return a; } else { return gcd(b, a % b); } } template inline T lcm(T a, T b) { return a * b / gcd(a, b); } template inline bool isPrime(T a) { if (a <= 1) { return false; } for (T i = 2; i * i <= a; i++) { if (a % i == 0) { return false; } } return true; } template inline T ord(T p, T n) { T ans = 0; while (n % p == 0) { n /= p; ans++; } return ans; } template struct Matrix { vector> m; ll h = 0; ll w = 0; inline Matrix(ll h_, ll w_) : m(vector>(h_, vector(w_, 0))), h(h_), w(w_) {} inline Matrix(ll h_, ll w_, ll v_) : m(vector>(h_, vector(w_, v_))), h(h_), w(w_) {} inline Matrix(vector v) : m(vector>(v.size(), vector(1))) { h = v.size(); w = 1; REP(i, h) { m[i][0] = v[i]; } } inline Matrix(vector> v) : m(v) { h = v.size(); w = v[0].size(); } inline vector operator[](const ll i) const { return m[i]; } //読み取り inline vector &operator[](const ll i) { return m[i]; } //書き込み inline Matrix &operator=(const Matrix &other) { h = other.h; w = other.w; m = other.m; return *this; } inline Matrix operator+(const Matrix &other) { assert(h == other.h && w == other.w); Matrix res(h, w); REP(i, h) REP(j, w) res.m[i][j] = m[i][j] + other.m[i][j]; return res; } inline Matrix operator-(const Matrix &other) { assert(h == other.h && w == other.w); Matrix res(h, w); REP(i, h) REP(j, w) res.m[i][j] = m[i][j] - other.m[i][j]; return res; } inline Matrix operator*(const Matrix &other) { assert(w = other.h); Matrix res(h, other.w); REP(i, h) { REP(j, other.w) { REP(k, w) { res.m[i][j] += m[i][k] * other.m[k][j]; } } } return res; } inline Matrix &operator+=(const Matrix &other) { assert(h == other.h && w == other.w); REP(i, h) REP(j, w) m[i][j] += other.m[i][j]; return *this; } inline Matrix &operator-=(const Matrix &other) { assert(h == other.h && w == other.w); REP(i, h) REP(j, w) m[i][j] -= other.m[i][j]; return *this; } inline Matrix &operator*=(const Matrix &other) { *this = *this * other; return *this; } inline void show() { REP(i, h) { REP(j, w) { cout << m[i][j]; if (j < w - 1) cout << " "; } ENDL; } } }; template inline Matrix RotMat2(ld t) { vector v = {{cos(t), -sin(t)}, {sin(t), cos(t)}}; Matrix res(v); } template inline Matrix RotMat3(ld t, ll a) { // x軸:0 y軸:1 z軸:3 Matrix res(3, 3); res[a][a] = 1; res[(a + 1) % 3][(a + 1) % 3] = cos(t); res[(a + 1) % 3][(a + 2) % 3] = -sin(t); res[(a + 2) % 3][(a + 1) % 3] = sin(t); res[(a + 2) % 3][(a + 2) % 3] = cos(t); return res; } template inline Matrix DiagMat(ll n, T v) { Matrix res(n, n); REP(i, n) res[i][i] = v; return res; } template inline Matrix pow(Matrix m, ll n) { if (n == 0) return DiagMat(m.h, 1ll); auto res = pow(m, n / 2); res *= res; if (n % 2 == 1) res *= m; return res; } struct mint { ll x; inline mint(ll x_ = 0) : x((x_ % mod + mod) % mod) {} inline mint &operator=(const mint &other) { x = other.x; return *this; } template inline mint &operator=(const T &other) { *this = mint(other); return *this; } inline mint operator+() { return *this; } inline mint operator-() { return mint(-x); } inline mint &operator+=(const mint &other) { if ((x += other.x) >= mod) x -= mod; return *this; } template inline mint &operator+=(const T &other) { *this += mint(other); return *this; } inline mint &operator-=(const mint &other) { return *this += -mint(other); } template inline mint &operator-=(const T &other) { *this -= mint(other); return *this; } inline mint &operator*=(const mint &other) { (x *= other.x) %= mod; return *this; } template inline mint &operator*=(const T &other) { *this *= mint(other); return *this; } template inline mint operator+(const T &other) { return mint(*this) += mint(other); } template inline mint operator-(const T &other) { return mint(*this) -= mint(other); } template inline mint operator*(const T &other) { return mint(*this) *= mint(other); } inline mint pow(ll n) { if (n == 0) return mint(1); mint res = pow(n / 2); res *= res; if (n % 2 == 1) res *= *this; return res; } inline mint inv() { return pow(mod - 2); } inline mint &operator/=(const mint &other) { return *this *= mint(other).inv(); } inline mint operator/(const mint &other) { return mint(*this) /= other; } inline mint operator++() { *this += 1; return *this; } inline mint operator++(int) { const mint res = *this; ++(*this); return res; } inline mint operator--() { *this -= 1; return *this; } inline mint operator--(int) { const mint res = *this; --(*this); return res; } inline bool operator==(const mint &other) { return x == other.x; } inline bool operator!=(const mint &other) { return !(*this == other); } inline bool operator<(const mint &other) { return *this < other; } }; inline istream &operator>>(istream &is, mint &x) { is >> x.x; x.x = (x.x % mod + mod) % mod; return is; } inline ostream &operator<<(ostream &os, const mint &x) { return os << x.x; } inline mint modPow(ll x, ll n) { return mint(x).pow(n); } template inline mint modFact(T n) { mint res(1); for (T i = n; n > 0; i--) res *= mint(i); return res; } template mint modComb(T n, T r) { mint res(1); for (T i = 0; i < r; i++) { res *= mint(n - i); } for (T i = 1; i <= r; i++) { res /= mint(i + 1); } return res; } ///////////////////////////////////////////////////////////////////////ここから inline void solve() { IN(mint, a); IN(string, s); REV(s); mint ans = 0; ll l = s.size(); for (mint i = 0; i.x < l - 1; i++) { ans += i * (a - 1) * modPow(a.x, i.x); } for (mint i = 0; i.x < s.size(); i++) { ans += mint(l - 1) * mint(s[i.x] - '0') * modPow(a.x, i.x); } ans -= mint(l - 1) * (modPow(a.x, l - 1) - 1); COUT(ans) } int main() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); solve(); }