#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; constexpr int MOD = 1e9+7; int main(){ cin.tie(0); ios::sync_with_stdio(0); int A; string B; cin >> A >> B; int N = B.size(); ll ans = 0, sB = 0, pA = 1; for(int i = N - 1; i >= 1; i--) { ans += (N - 1 - i) * pA % MOD * (A - 1) % MOD; if(ans >= MOD) ans -= MOD; sB += (B[i] - '0') * pA % MOD; if(sB >= MOD) sB -= MOD; pA *= A; pA %= MOD; } // A^i <= x <= B // B - A^i + 1 sB += (B[0] - '0') * pA; ans += (N - 1) * (sB - pA + 1) % MOD; cout << ans % MOD << "\n"; }