QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 100

#4851. Permutations

统计

How many distinct permutations of word A contain word B? Output the remainder when this number is divided by 10007.

Input

The first line contains a sequence of lowercase English letters, word A. The length of the sequence will not exceed 500. The second line contains a sequence of lowercase English letters, word B. Word B will not be longer than word A.

Output

In the first and only line, output the remainder when the required number of permutations is divided by 10007.

Examples

Input 1

mirko
mir

Output 1

6

Note 1

The six permutations that contain the word mir are: kmiro, komir, mirko, mirok, okmir, and omirk.

Input 2

sssss
ss

Output 2

1

Input 3

barbarabarbara
barbabarba

Output 3

30

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.