#include using namespace std; using ll = long long; #define BL 512 #define SB (BL - 1) int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; string s; cin >> s; constexpr int r = 26 * 26 * 26; const int bsz = (n + BL - 1) / BL; vector> seg(bsz); vector> cnt(bsz); vector vec(n); auto add = [&](int p, int d){ int hs = vec[p]; if(d == 1){ seg[p / BL][hs] += p - (p / BL * BL) + 1; cnt[p / BL][hs]++; }else{ seg[p / BL][hs] -= p - (p / BL * BL) + 1; cnt[p / BL][hs]--; } }; short hs = (s[0] - 'a') * 26 + (s[1] - 'a'); for(int i = 0; i + 3 <= n; i++){ hs *= (short)(26); hs += (short)(s[i + 2] - 'a'); vec[i] = hs; add(i, 1); hs -= (short)(676 * (s[i] - 'a')); } while(q--){ int cmd; cin >> cmd; if(cmd == 1){ int p; char x; cin >> p >> x; p--; short d = x - s[p]; s[p] = x; if(p + 3 <= n){ add(p, -1); vec[p] += d * (short)(676); add(p, 1); } if(1 <= p && p + 2 <= n){ add(p - 1, -1); vec[p - 1] += d * (short)(26); add(p - 1, 1); } if(2 <= p){ add(p - 2, -1); vec[p - 2] += d; add(p - 2, 1); } }else{ int l, r; char c0, c1, c2; ll ans = 0; cin >> l >> r >> c0 >> c1 >> c2; short hs = (((c0 - 'a') * 26) + (c1 - 'a')) * 26 + c2 - 'a'; l--, r -= 2; int cur = l; while(cur < r && (cur & SB)){ if(hs == vec[cur]) ans += cur - l + 1; cur++; } while(cur + BL <= r){ ans += seg[cur / BL][hs] + cnt[cur / BL][hs] * (ll)(cur - l); cur += BL; } while(cur < r){ if(hs == vec[cur]) ans += cur - l + 1; cur++; } cout << ans << '\n'; } } }