This page is still under construction.

Parts of this page are still being built. What you see may change.

Classic Quotation

Time limit1sMemory limit512 MB

Summary
Given strings S and T and queries (L, R), compute the expected number of occurrences of T after deleting a random substring spanning positions L to R, scaled by the number of choices.
Level

Hard8 of 10

Topics
String matching, Prefix sum, Combinatorics, Math
Solved
No attempts yet

Problem

When chatting online, we can save what somebody said to form his classic quotation. Little Q does this, too. And what's more, he can even change the original words. Formally, assume somebody said a string SS of length nn. Little Q will choose a continuous substring of SS (possibly empty) and remove it, then concatenate the two remaining parts, obtaining a new string S′S'. For example, he might remove "not " from the string "I am not SB", so that the new string S′S' will be "I am SB".

After doing lots of such things, Little Q finds out that string TT occurs as a continuous substring of S′S' very often.

Now given strings SS and TT, Little Q has kk queries. Each query has the following format: given LL and RR, Little Q will remove a substring so that the two remaining parts are S[1..i]S[1..i] and S[j..n]S[j..n] where the pair of integers (i,j)(i, j) is chosen equiprobably among all pairs where 1≤i≤L1 \leq i \leq L and R≤j≤nR \leq j \leq n. Your goal is to find EE, the expected number of occurrences of TT in the resulting string, and print the value E⋅L⋅(n−R+1)E \cdot L \cdot (n - R + 1).

All occurrences of TT must taken into account even if they overlap. The queries are independent: the string SS actually does not transform into S′S' and is the same for all queries.

Input

The first line of the input contains three integers nn, mm and kk denoting the length of SS, the length of TT and the number of queries (1≤n≤5⋅1041 \leq n \leq 5 \cdot 10^4, 1≤m≤1001 \le m \leq 100, 1≤k≤5⋅1041 \le k \le 5 \cdot 10^4).

The next line contains a string SS consisting of nn lowercase English letters. The following line contains a string TT consisting of mm lowercase English letters. Each of the remaining kk lines contains a query consisting of two integers LL and RR (1≤L<R≤n1 \leq L < R \leq n).

Output

For each query, print a single line containing a single integer: the answer to the query.

Examples1

  1. Example 1

    Input
    8 5 4
    iamnotsb
    iamsb
    4 7
    3 7
    3 8
    2 7
    
    Expected output
    1
    1
    0
    0