#abc272f. [abc272_f]Two Strings
[abc272_f]Two Strings
Problem Statement
You are given strings and of length each, consisting of lowercase English letters.
For a string and an integer , let be the string obtained by performing on the following operation times:
- Remove the first character of and append the same character to the end of .
Find the number of integer pairs satisfying such that is lexicographically smaller than or equal to .
What is the lexicographical order?
Simply put, the lexicographical order is the order in which the words are arranged in a dictionary. Let us define it formally by describing an algorithm of finding the ordering of two distinct strings and consisting of lowercase English letters.
Here, we denote "the -th character of a string " by . Also, we write and if is lexicographically smaller and larger than , respectively.
- Let be the smallest of the lengths of and . For , we check if equals .
- If there is an such that , let be the smallest such . Comparing and , we terminate the algorithm by determining that if is smaller than in the alphabetical order, and that otherwise.
- If there is no such that , comparing the lengths of and , we terminate the algorithm by determining that if is shorter than , and that otherwise.
Constraints
- and are strings of length each, consisting of lowercase English letters.
- is an integer.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
3
adb
cab
Sample Output 1
4
There are pairs of satisfying the conditions: , and .
does not satisfy the conditions because dba
and bca
.
Sample Input 2
10
wsiuhwijsl
pwqoketvun
Sample Output 2
56