Problem:
String Search

Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.

Input

In the first line, a text T is given. In the second line, an integer Q denoting the number of queries is given. In the following Q lines, the patterns P_i are given respectively.

Output

For each question, print 1 if the text includes P_i, or print 0 otherwise.

Constraints

1 ≤ length of T ≤ 1000000

1 ≤ length of P_i ≤ 1000

1 ≤ Q ≤ 10000

The input consists of alphabetical characters and digits

Sample Input 1

aabaaa
4
aa
ba
bb
xyz

Sample Output 1

1
1
0
0

Solution in Go (judge verdict: Accepted)

package main

import (
	"bufio"
	"fmt"
	"index/suffixarray"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var s string
	var q int

	fmt.Fscan(r, &s)
	fmt.Fscan(r, &q)

	index := suffixarray.New([]byte(s))

	for i := 0; i < q; i++ {
		var p string
		fmt.Fscan(r, &p)

		res := index.Lookup([]byte(p), 1)
		if len(res) > 0 {
			fmt.Fprintln(w, 1)
		} else {
			fmt.Fprintln(w, 0)
		}
	}
}