Under construction

Still being built. Things may change

Listening Test Practice

Time limit3sMemory limit1024 MB

Summary
For each query, count the substrings of S whose longest common prefix with T[i..j] is exactly k characters.
Level

Hard8 of 10

Topics
String matching, Sorting, Binary search
Solved
No attempts yet

Problem

The importance of algorithms has become widely known, so more people now want to join SUAPC. Following this trend, SUAPC added a listening test section. Rao can code but is weak at listening, so he plans to practice the listening test with past exam problems.

Rao's vocabulary list is a string SS of length NN, and his past exam collection is a string TT of length MM. Rao must solve QQ practice problems of the following form. When two strings have the same first kk characters, they are said to be kk-similar. Two strings are not kk-similar if one of them has length less than kk, or if they match in their first k+1k+1 or more characters.

  • ii jj kk: Output the number of substrings of SS that are kk-similar to the substring TiTi+1...TjT_i T_{i+1} ... T_j of TT.

A substring is a contiguous part of a string. A substring cannot be empty.

Input

The first line contains NN, MM, and QQ separated by spaces, where NN is the length of the vocabulary list, MM is the length of the exam collection, and QQ is the number of practice problems. (1≤N,M,Q≤100 0001 \leq N, M, Q \leq 100\,000)

The second line contains the string SS of length NN, made of lowercase English letters.

The third line contains the string TT of length MM, made of lowercase English letters.

The next QQ lines each give a practice problem in the form i j k. (1≤i≤j≤M1 \leq i \leq j \leq M, 0≤k≤M0 \leq k \leq M)

Output

Print the answer to each practice problem on its own line, in order.

Examples2

  1. Example 1

    Input
    6 6 3
    banana
    ananas
    2 5 2
    1 6 1
    5 6 1
    
    Expected output
    2
    3
    9
    
  2. Example 2

    Input
    5 7 2
    suapc
    sinchon
    1 7 0
    3 4 5
    
    Expected output
    10
    0