#include using namespace std; string state; void Read(int &x) { static char c; for(c = getchar(); !isdigit(c); c = getchar()); for(x = 0; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + c - '0'; } const int kMagic = 128; int Last[100005]; int n; int ans[500000]; int Brut(int a, int b, int c) { // cerr << "B: " << a << " " << b << " " << c << endl; int ans = 0; while(a < b) { int nxt = a + c; if(nxt >= n) nxt = n - 1; nxt = Last[nxt]; if(nxt <= a) { if(a + c < b) ans += 1; a += c; } else { a = nxt; } // cerr << "#" << a << " " << ans << endl; } return ans; } vector> Intervals; int SPar[kMagic + 1]; int IID[100005]; vector qs[kMagic + 1]; int A[100005], B[100005]; void SolveFor(int c) { if(qs[c].empty()) return; // cerr << "SF: " << c << endl; int acc = 0; vector spar; for(auto p : Intervals) { int len = p.second - p.first; acc += (len - 1) / c; spar.push_back(acc); } // for(auto s : spar) { // cerr << s << " "; // } // cerr << endl; for(auto i : qs[c]) { int a = A[i], b = B[i]; int from = IID[a], to = IID[b]; // cerr << "ft: " << from << " " << to << endl; int ans = 0; if(from < to) { ans += spar[to - 1]; ans -= spar[from]; } //from, to int len = Intervals[from].second - a; assert(len >= 0); ans += (len - 1) / c; len = b - Intervals[to].first; assert(len >= 0); ans += (len - 1) / c; ::ans[i] = ans; } } int main() { Read(n); cin >> state; int m; Read(m); Last[0] = state[0] == '1' ? 0 : -1; for(int i = 1; i < n; ++i) { Last[i] = state[i] == '1' ? i : Last[i - 1]; } int beg = 0, iid = 0; for(int i = 0; i < n; ++i) { if(state[i] == '0') { IID[i] = iid; } else { Intervals.emplace_back(beg, i); beg = i; IID[i] = ++iid; } } Intervals.emplace_back(beg, n - 1); // for(auto p : Intervals) cerr << p.first << " " << p.second << endl; // for(int i = 0; i < n; ++i) cerr << IID[i] << " "; cerr << endl; // for(int i = 0; i < n; ++i) cerr << Last[i] << " "; cerr << endl; for(int i = 0; i < m; ++i) { int a, b, c; cin >> a >> b >> c; --a; --b; if(c > kMagic) { ans[i] = Brut(a, b, c); } else { A[i] = a; B[i] = b; qs[c].push_back(i); } } for(int i = 1; i <= kMagic; ++i) SolveFor(i); for(int i = 0; i < m; ++i) { cout << ans[i] << '\n'; } return 0; }