import Main.AhoCorasick.Automaton

import scala.annotation.tailrec
import scala.collection.mutable
object Main extends App {
  import scala.io.StdIn._

  val s = readLine.trim
  val n = readInt
  val words = Array.tabulate(n){_ ⇒ readLine.trim}
  println(solve(s, words))
  def solve(target: String, words: Array[String]): Int = {
    val automaton = AhoCorasick(words)
    @tailrec
    def sub(state: Automaton, lastRemoved: Int = 0, current: Int = 0, count: Int = 0): Int = {
      if (current == target.length) {
        if (state.matched.nonEmpty && (count == 0 || state.matched.exists(_.length + lastRemoved <= current))) count + 1
        else count
      }
      else if (state.matched.nonEmpty && (count == 0 || state.matched.exists(_.length + lastRemoved <= current))){
        sub(state.transit(target(current)), current, current + 1, count + 1)
      }else sub(state.transit(target(current)), lastRemoved, current + 1, count)
    }
    sub(automaton)
  }
  object AhoCorasick {
    def apply(patterns: Array[String]): Automaton = {
      val trie = new Trie
      for (word ← patterns) {
        var t = trie
        for (c ← word){
          t.children.find(_._1 == c) match {
            case None ⇒
              val ct = new Trie
              t.children ::= (c, ct)
              t = ct
            case Some(ct) ⇒
              t = ct._2
          }
        }
        t.word = Some(word)
      }
      Automaton.makeFromTrie(trie)
    }
    private class Trie {
      var children: List[(Char, Trie)] = Nil
      var word: Option[String] = None
    }
    object Automaton {
      private[AhoCorasick] def makeFromTrie(trie: Trie): Automaton = {
        val root = new Init()
        val queue: mutable.Queue[(Automaton, Char, Trie)] = mutable.Queue(trie.children.map{case (c, t) ⇒ (root, c, t)}: _*)
        while (queue.nonEmpty){
          val (parent, next, child) = queue.dequeue()
          val failure = takeNext(parent, next)
          val words = child.word.map(_::failure.matched).getOrElse(failure.matched)
          val nextAutomaton = new State(words, failure)
          parent.children(next) = nextAutomaton
          for ((n, t) ← child.children){
            queue.enqueue((nextAutomaton, n, t))
          }
        }
        root
      }
      @tailrec
      private def takeNext(automaton: Automaton, next: Char): Automaton = {
          automaton.children.get(next) match {
            case Some(a) ⇒ a
            case None if automaton.isRoot ⇒ automaton
            case None ⇒ takeNext(automaton.failure, next)
          }
      }
      protected class Init (protected val children: mutable.ListMap[Char, Automaton.State] = mutable.ListMap()) extends Automaton {
        override def isRoot: Boolean = true
        override def transit(char: Char): Automaton = children.getOrElse(char, this)
        override def matched: List[String] = Nil
        override protected def failure: Automaton = this
      }
      protected class State private(protected val children: mutable.ListMap[Char, Automaton.State], private val matchingWords: List[String], protected val failure: Automaton) extends Automaton {
        def this(matchingWords: List[String], failure: Automaton) {
          this(mutable.ListMap(), matchingWords, failure)
        }
        def transit(char: Char): Automaton = {
          children.getOrElse(char, Automaton.takeNext(failure, char))
        }
        def matched = matchingWords
      }
    }
    sealed trait Automaton {
      protected def isRoot: Boolean = false
      def transit(char: Char): Automaton
      def matched: List[String]
      protected def children: mutable.ListMap[Char, Automaton.State]
      protected def failure: Automaton
    }
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}
