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

#GD0000081. Tô màu bằng những lần xuất hiện (Color with Occurrences)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tô màu bằng những lần xuất hiện (Color with Occurrences)

Color with Occurrences

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given a target string tt and nn lowercase patterns s1,…,sns_1,\ldots,s_n, one operation selects any contiguous occurrence of one pattern in tt and colors all its positions. Positions may be colored more than once. Color the whole target with the minimum number of operations, reporting pattern indices and one-based starting positions, or -1 if impossible. Any minimum-length plan is valid.

Input

The first line contains tt. The second line contains nn. The following nn lines contain s1,…,sns_1,\ldots,s_n.

Output

Print -1 if impossible. Otherwise print minimum operation count kk, then kk lines each containing pattern index ii and one-based occurrence start pp.

Subtasks

  • Subtask 1 (20 points): 1≤∣t∣≤151\le |t|\le 15; 1≤n≤101\le n\le 10; 1≤∣si∣≤101\le |s_i|\le10; all characters are lowercase letters a–z.
  • Subtask 2 (30 points): 1≤∣t∣≤501\le |t|\le 50; 1≤n≤101\le n\le 10; 1≤∣si∣≤101\le |s_i|\le10; all characters are lowercase letters a–z.
  • Subtask 3 (50 points): 1≤∣t∣≤1001\le |t|\le 100; 1≤n≤101\le n\le10; 1≤∣si∣≤101\le |s_i|\le10; all characters are lowercase letters a–z.

Examples

Input

bababa
2
ba
aba

Output

3
1 1
1 3
1 5

Explanation

Use pattern 11 (ba) at starting positions 11, 33, and 55 to color positions 11–22, 33–44, and 55–66 respectively. Covering the first position requires the occurrence starting at 11, while one further operation cannot cover all of positions 33–66. Thus three is minimum.