409095: GYM103438 A King of String Comparison
Description
You are given two strings $$$s, t$$$ of length $$$n$$$. Find the number of pairs $$$(l, r)$$$ of integers such that $$$1 \le l \le r \le n$$$ and the substring $$$s_ls_{l+1}s_{l+2}\ldots s_r$$$ is lexicographically smaller than $$$t_lt_{l+1}t_{l+2}\ldots t_r$$$.
A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds:
- $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$;
- in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.
The first line of the input contains a single integer $$$n$$$ ($$$1 \le n \le 200\,000$$$).
The second and the third lines of the input contain strings $$$s$$$, $$$t$$$ of length $$$n$$$ correspondingly, each consisting only of lowercase Latin letters.
OutputOutput a single integer — the number of pairs $$$(l, r)$$$ of integers such that $$$1 \le l \le r \le n$$$ and the substring $$$s_ls_{l+1}s_{l+2}\ldots s_r$$$ is lexicographically smaller than $$$t_lt_{l+1}t_{l+2}\ldots t_r$$$.
ExamplesInput3 aab abaOutput
4Input
4 icpc coolOutput
4Input
4 zyzz lifeOutput
0Input
7 trivial problemOutput
16Input
18 goodluckandhavefun letthestrongestwinOutput
112Note
In the first sample, there are $$$4$$$ such pairs: $$$(1, 2), (1, 3), (2, 2), (2, 3)$$$.