Codeforces Round 383 (Div. 1)
E
Arpa’s abnormal DNA and Mehrdad’s deep interest
Codeforces
3400
原题
← D→
翻译中…

All of us know that girls in Arpa’s land are... ok, you’ve got the idea :D

翻译中…

Anyone knows that Arpa isn't a normal man, he is ... well, sorry, I can't explain it more. Mehrdad is interested about the reason, so he asked Sipa, one of the best biology scientists in Arpa's land, for help. Sipa has a DNA editor.

翻译中…

image

翻译中…

Sipa put Arpa under the DNA editor. DNA editor showed Arpa's DNA as a string $*S*$ consisting of $*n*$ lowercase English letters. Also Sipa has another DNA $*T*$ consisting of lowercase English letters that belongs to a normal man.

翻译中…

Now there are $(*n* + 1)$ options to change Arpa's DNA, numbered from $0$ to $*n*$. $*i*$-th of them is to put $*T*$ between $*i*$-th and $(*i* + 1)$-th characters of $*S*$ ($0 ≤ *i* ≤ *n*$). If $*i* = 0$, $*T*$ will be put before $*S*$, and if $*i* = *n*$, it will be put after $*S*$.

翻译中…

Mehrdad wants to choose the most interesting option for Arpa's DNA among these $*n* + 1$ options. DNA $*A*$ is more interesting than $*B*$ if $*A*$ is lexicographically smaller than $*B*$. Mehrdad asked Sipa $*q*$ questions:

翻译中…

Given integers $*l*, *r*, *k*, *x*, *y*$, what is the most interesting option if we only consider such options $*i*$ that $*l* ≤ *i* ≤ *r*$ and image? If there are several most interesting options, Mehrdad wants to know one with the smallest number $*i*$.

翻译中…

Since Sipa is a biology scientist but not a programmer, you should help him.

翻译中…

Input

翻译中…

The first line contains strings $*S*$, $*T*$ and integer $*q*$ ($1 ≤ |*S*|, |*T*|, *q* ≤ 10^{5}$) — Arpa's DNA, the DNA of a normal man, and the number of Mehrdad's questions. The strings $*S*$ and $*T*$ consist only of small English letters.

翻译中…

Next $*q*$ lines describe the Mehrdad's questions. Each of these lines contain five integers $*l*, *r*, *k*, *x*, *y*$ ($0 ≤ *l* ≤ *r* ≤ *n*$, $1 ≤ *k* ≤ *n*$, $0 ≤ *x* ≤ *y* < *k*$).

翻译中…

Output

翻译中…

Print $*q*$ integers. The $*j*$-th of them should be the number $*i*$ of the most interesting option among those that satisfy the conditions of the $*j*$-th question. If there is no option $*i*$ satisfying the conditions in some question, print -1.

翻译中…

Note

翻译中…

Explanation of first sample case:

翻译中…

In the first question Sipa has two options: dabc ($*i* = 0$) and abdc ($*i* = 2$). The latter (abcd) is better than abdc, so answer is $2$.

翻译中…

In the last question there is no $*i*$ such that $0 ≤ *i* ≤ 1$ and image.

翻译中…

样例

Input #1
abc d 4
0 3 2 0 0
0 3 1 0 0
1 2 1 0 0
0 1 3 2 2
Output #1
2 3 2 -1
InputCopy OutputCopy
Input #2
abbbbbbaaa baababaaab 10
1 2 1 0 0
2 7 8 4 7
2 3 9 2 8
3 4 6 1 1
0 8 5 2 4
2 8 10 4 7
7 10 1 0 0
1 4 6 0 2
0 9 8 0 6
4 8 5 0 1
Output #2
1 4 2 -1 2 4 10 1 1 5
InputCopy OutputCopy
题目信息
题号
741E
时间限制
2 s
内存限制
256 MB
标签
数据结构
后缀结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。