PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#SRD0000047. Đếm chuỗi con khi sửa ký tự

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đếm chuỗi con khi sửa ký tự

Substrings in a String

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a lowercase English string ss, process qq operations:

  • 1 i c: change character at index ii to c.
  • 2 l r y: count all occurrences of the non-empty pattern yy that lie entirely within the inclusive substring s[l..r]s[l..r].

An occurrence starting at ii is valid if l≤il\le i and i+∣y∣−1≤ri+|y|-1\le r, and every character matches. Overlapping occurrences are counted. If the pattern is longer than the query interval, the answer is zero. The sum of all queried pattern lengths is at most 10510^5.

Input

The first line contains ss, the second contains qq, followed by qq lines of 1 i c or 2 l r y.

Output

Output one occurrence count per type-2 query.

Subtasks

  • Subtask 1 (10 points): 1≤n≤401\le n\le40; 1≤q≤601\le q\le60; The sum of the lengths of all type-2 query patterns is at most 10510^5.
  • Subtask 2 (20 points): 1≤n≤15001\le n\le1500; 1≤q≤20001\le q\le2000; The sum of the lengths of all type-2 query patterns is at most 10510^5.
  • Subtask 3 (30 points): 1≤n≤150001\le n\le15000; 1≤q≤150001\le q\le15000; The sum of the lengths of all type-2 query patterns is at most 10510^5.
  • Subtask 4 (40 points): 1≤n≤1000001\le n\le100000; 1≤q≤1000001\le q\le100000; The sum of the lengths of all type-2 query patterns is at most 10510^5.

Examples

Input

ababababa
3
2 1 7 aba
1 5 c
2 1 7 aba

Output

3
1

Explanation

In ababababa, pattern aba occurs fully in positions 1..71..7 starting at 1,3,51,3,5, for a total of 33. Replacing the fifth character with c leaves only one occurrence in that interval.