#include using namespace std; const long long MOD = 1000000007; int main() { long long A; cin >> A; string B; cin >> B; long long N = B.size(); vector A_pow(N, 1); for (long long i = 1; i < N; i++) { A_pow[i] = A_pow[i - 1] * A % MOD; } long long ans = 0; for (long long i = 1; i < N; i++) { ans += (i - 1) * (A_pow[i] - A_pow[i - 1]) % MOD; } long long b = 0; for (long long i = 0; i < N; i++) { b += A_pow[i] * B[N - i - 1] % MOD; } b %= MOD; ans += (N - 1) * (b - A_pow[N - 1] + 1) % MOD; cout << (ans % MOD + MOD) % MOD << endl; }