Codeforces Round 448 (Div. 2)
D
String Mark
Codeforces
2100
原题
← CE →
翻译中…

At the Byteland State University marks are strings of the same length. Mark $*x*$ is considered better than $*y*$ if string $*y*$ is lexicographically smaller than $*x*$.

翻译中…

Recently at the BSU was an important test work on which Vasya recived the mark $*a*$. It is very hard for the teacher to remember the exact mark of every student, but he knows the mark $*b*$, such that every student recieved mark strictly smaller than $*b*$.

翻译中…

Vasya isn't satisfied with his mark so he decided to improve it. He can swap characters in the string corresponding to his mark as many times as he like. Now he want to know only the number of different ways to improve his mark so that his teacher didn't notice something suspicious.

翻译中…

More formally: you are given two strings $*a*$, $*b*$ of the same length and you need to figure out the number of different strings $*c*$ such that:

翻译中…
  1. $*c*$ can be obtained from $*a*$ by swapping some characters, in other words $*c*$ is a permutation of $*a*$.
翻译中…
  1. String $*a*$ is lexicographically smaller than $*c*$.
翻译中…
  1. String $*c*$ is lexicographically smaller than $*b*$.
翻译中…

For two strings $*x*$ and $*y*$ of the same length it is true that $*x*$ is lexicographically smaller than $*y*$ if there exists such $*i*$, that $*x*_{1} = *y*_{1}, *x*_{2} = *y*_{2}, ..., *x*_{*i* - 1} = *y*_{*i* - 1}, *x*_{*i*} < *y*_{*i*}$.

翻译中…

Since the answer can be very large, you need to find answer modulo $10^{9} + 7$.

翻译中…

Input

翻译中…

First line contains string $*a*$, second line contains string $*b*$. Strings $*a*, *b*$ consist of lowercase English letters. Their lengths are equal and don't exceed $10^{6}$.

翻译中…

It is guaranteed that $*a*$ is lexicographically smaller than $*b*$.

翻译中…

Output

翻译中…

Print one integer  — the number of different strings satisfying the condition of the problem modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

In first sample from string $*abc*$ can be obtained strings $*acb*, *bac*, *bca*, *cab*, *cba*$, all of them are larger than $*abc*$, but smaller than $*ddd*$. So the answer is $5$.

翻译中…

In second sample any string obtained from $*abcdef*$ is larger than $*abcdeg*$. So the answer is $0$.

翻译中…

样例

Input #1
abc
ddd
Output #1
5
InputCopy OutputCopy
Input #2
abcdef
abcdeg
Output #2
0
InputCopy OutputCopy
Input #3
abacaba
ubuduba
Output #3
64
InputCopy OutputCopy
题目信息
题号
895D
时间限制
4 s
内存限制
256 MB
标签
组合数学
数学
字符串

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