CF895D.String Mark

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

At the Byteland State University marks are strings of the same length. Mark xx is considered better than yy if string yy is lexicographically smaller than xx .

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

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 aa , bb of the same length and you need to figure out the number of different strings cc such that:

1) cc can be obtained from aa by swapping some characters, in other words cc is a permutation of aa .

2) String aa is lexicographically smaller than cc .

3) String cc is lexicographically smaller than bb .

For two strings xx and yy of the same length it is true that xx is lexicographically smaller than yy if there exists such ii , that x1=y1,x2=y2,...,xi1=yi1,xi<yix_{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 109+710^{9}+7 .

输入格式

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

It is guaranteed that aa is lexicographically smaller than bb .

输出格式

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

输入输出样例

  • 输入#1

    abc
    ddd
    

    输出#1

    5
    
  • 输入#2

    abcdef
    abcdeg
    

    输出#2

    0
    
  • 输入#3

    abacaba
    ubuduba
    

    输出#3

    64
    

说明/提示

In first sample from string abcabc can be obtained strings acb,bac,bca,cab,cbaacb,bac,bca,cab,cba , all of them are larger than abcabc , but smaller than dddddd . So the answer is 55 .

In second sample any string obtained from abcdefabcdef is larger than abcdegabcdeg . So the answer is 00 .

首页