func countMatches(pat string, bytes []byte) int {
	m := pcre.MustCompile(pat, 0).Matcher(bytes, 0)
	n := 0
	for f := m.Matches(); f; f = m.Match(bytes, 0) {
		n++
		bytes = bytes[m.Index()[1]:]
	}
	return n
}
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	bytes, err := ioutil.ReadAll(os.Stdin)
	if err != nil {
		fmt.Fprintf(os.Stderr, "can't read input: %s\n", err)
		os.Exit(2)
	}
	ilen := len(bytes)
	// Delete the comment lines and newlines
	bytes = pcre.MustCompile("(>[^\n]+)?\n", 0).ReplaceAll(bytes, []byte{}, 0)
	clen := len(bytes)

	mresults := make([]chan int, len(variants))
	var i int
	var s string
	for i, s = range variants {
		ch := make(chan int)
		mresults[i] = ch
		go func(intch chan int, ss string) {
			intch <- countMatches(ss, bytes)
		}(ch, s)
	}

	lenresult := make(chan int)
	bb := bytes
	go func() {
		for _, sub := range substs {
			bb = pcre.MustCompile(sub.pat, 0).ReplaceAll(bb, []byte(sub.repl), 0)
		}
		lenresult <- len(bb)
	}()

	for i, s = range variants {
		fmt.Printf("%s %d\n", s, <-mresults[i])
	}
	fmt.Printf("\n%d\n%d\n%d\n", ilen, clen, <-lenresult)
}