#include #include #include using namespace std; long long md = 1000000007; int main() { ios::sync_with_stdio(false); cin.tie(0); int a; string s; cin >> a >> s; int n = s.length(); long long ans = 0, r = 1; for (int i = 1; i < n; i++) { ans = (ans + r * (s[n - i] - '0')) % md; r = (r * a) % md; } ans = ((ans + 1LL) * (n - 1)) % md; r = 1; for (int i = 1; i < n; i++) { ans = (ans + r * (a - 1) * (i - 1)) % md; r = (r * a) % md; } ans = (ans + (long long)(s[0] - '1') * (n - 1) * r) % md; cout << ans << '\n'; return 0; }