#K8281. Longest Substring Queries

    ID: 36058 Type: Default 1000ms 256MiB

Longest Substring Queries

Longest Substring Queries

You are given a string s consisting of lowercase Latin letters and a series of queries. Each query consists of a single character. For each query, you need to determine the length of the longest contiguous substring within s that contains only the queried character.

A contiguous substring is defined as a sequence of consecutive characters in the string. Formally, if we denote a contiguous substring as \(S_i\), you are required to compute

[ L = \max_{i} { \text{length}(S_i) }
]

where each \(S_i\) is a maximal substring comprised solely of the queried character. If the character does not appear in s, the answer for that query is 0.

This problem tests your ability to scan a string efficiently and process multiple queries.

inputFormat

The input is given via standard input (stdin) in the following format:

  1. A line containing the string s, which consists of only lowercase Latin letters.
  2. A line containing an integer n, denoting the number of queries.
  3. n lines follow, each containing a single lowercase letter representing a query.

outputFormat

For each query, output a single integer on a new line that represents the length of the longest contiguous segment in s consisting solely of the queried character.

## sample
abaaaabbcc
4
a
b
c
d
4

2 2 0

</p>