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

#SRD0000046. Tiến hóa ADN

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tiến hóa ADN

DNA Evolution

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A DNA string ss contains only A, T, G, C. Process qq events:

  • 1 x c: replace character at position xx with c.
  • 2 l r e: repeat non-empty pattern ee infinitely as eeee…eeee\ldots, aligning its first character with position ll. Count positions i∈[l,r]i\in[l,r] for which si=e(i−l) mod ∣e∣+1s_i=e_{(i-l)\bmod|e|+1}.

This counts individual matching positions under a periodic alignment, not the number of substring occurrences of ee. The pattern length is at most 1010.

Input

The first line contains the DNA string, the second contains qq, followed by qq lines of either 1 x c or 2 l r e.

Output

Output the number of matching positions for every type-2 query.

Subtasks

  • Subtask 1 (15 points): 1≤n≤401\le n\le40; 1≤q≤601\le q\le60; Pattern ee has length between 11 and 1010.
  • Subtask 2 (20 points): 1≤n≤15001\le n\le1500; 1≤q≤20001\le q\le2000; Pattern ee has length between 11 and 1010.
  • Subtask 3 (25 points): 1≤n≤150001\le n\le15000; 1≤q≤150001\le q\le15000; Pattern ee has length between 11 and 1010.
  • Subtask 4 (40 points): 1≤n≤1000001\le n\le100000; 1≤q≤1000001\le q\le100000; Pattern ee has length between 11 and 1010.

Examples

Input

ATGCATGC
4
2 1 8 ATGC
2 2 6 TTT
1 4 T
2 2 6 TA

Output

8
2
4

Explanation

Pattern ATGC aligned at position 11 matches all eight DNA characters. Pattern TTT aligned at position 22 matches two positions within [2,6][2,6]. After changing position 44 to T, pattern TA aligned at position 22 matches four positions.