const MOD: usize = 1e9 as usize + 7; fn main() { let mut a = String::new(); std::io::stdin().read_line(&mut a).ok(); let a: usize = a.trim().parse().unwrap(); let mut b = String::new(); std::io::stdin().read_line(&mut b).ok(); let mut b = b.trim().chars().map(|c| c as usize - '0' as usize).collect::>(); b.reverse(); let mut result = 0usize; let mut rank = 1usize; let mut current = 1usize; for i in 0..b.len()-1 { result += (rank * a - rank) * i % MOD; result %= MOD; current += rank * b[i] % MOD; current %= MOD; rank *= a; rank %= MOD; } result += (current + (b[b.len()-1] - 1) * rank) * (b.len()-1) % MOD; result %= MOD; println!("{}", result); }