#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
constexpr int N = 2001;
int C[N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
if (j == 0 || j == i) {
C[i][j] = 1;
} else {
C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod;
}
}
}
string a;
cin >> a;
int n = a.size();
int q;
cin >> q;
while (q--) {
int d;
string s;
cin >> d >> s;
vector<int> suf(n + 2);
for (int i = n - 1; i >= 0; i--) {
suf[i] = suf[i + 1] + (a[i] == s[1]);
}
int res = 0;
for (int i = 0; i < n; i++) {
if (a[i] == s[0]) {
res += 1LL * C[i][d - 2] * suf[i + 1] % mod;
res %= mod;
}
}
cout << res << '\n';
}
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |