Under construction

Still being built. Things may change

a11y

Time limit3.5sMemory limit1024 MB

Summary
Given a string A and queries of the form letter, k, letter, count the substrings of A that start with the first letter, end with the second, and have length k+2.
Level

Medium5 of 10

Topics
String, Bit manipulation, Hash map
Solved
No attempts yet

문제

Have you ever heard of the word a11y? It is an abbreviation of accessibility, where there are 11 characters between the a and the y. Similar abbreviations include k8s (Kubernetes) and i18n (internationalization).

You are given a string AA of length NN. Given queries, each an abbreviation made of a letter, a number, and a letter, print how many substrings of AA match each abbreviation. When counting, two substrings with the same content but different positions in AA are counted as different.

A substring of a string is a string obtained by removing zero or more characters from either end. For example, the substrings of abc are a, b, c, ab, bc, and abc, for a total of 66.

입력

The first line contains the string AA of length NN, which consists only of lowercase English letters. (1≤N≤100 0001\le N\le 100\,000)

The next line contains the number of queries QQ. (1≤Q≤100 0001\le Q\le 100\,000)

Each of the next QQ lines contains an abbreviation with no spaces, in the form letter, number, letter. Both letters are lowercase English letters, and the middle number is between 11 and N−2N-2, inclusive.

출력

Print the answer to each query on its own line, in the order the queries are given.

Examples2

  1. Example 1

    Input
    accessibility
    4
    a11y
    c2s
    i1i
    i1y
    
    Expected output
    1
    2
    2
    1
    
  2. Example 2

    Input
    abababababa
    4
    a1a
    a2a
    a1b
    a2b
    
    Expected output
    5
    0
    0
    4