#include #include using std::cin; using std::cout; using namespace atcoder; using mint = modint1000000007; using std::string; using ll = long long; int main() { int a; string b; cin >> a >> b; int n = b.size(); reverse(b.begin(), b.end()); mint ans, mul = 1, t; for (int i = 0; i < n; ++i) { ans -= mul - 1; t += mint(b[i] - '0') * mul; mul *= a; } ans += t * (n - 1); cout << ans.val() << '\n'; return 0; }