QOJ.ac

QOJ

Time Limit: 6 s - 12 s Memory Limit: 1024 MB Total points: 30

#5875. Runs

Statistics

Problem

I have a string S consisting of lower-case alphabetic characters, 'a' - 'z'. Each maximal sequence of contiguous characters that are the same is called a "run". For example, "bookkeeper" has 7 runs. How many different permutations of S have exactly the same number of runs as S?

Two permutations a and b are considered different if there exists some index i at which they have a different character: a[i] ≠ b[i].

Input

The first line of the input gives the number of test cases, T. T lines follow. Each contains a single non-empty string of lower-case alphabetic characters, S, the string of interest.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of different permutations of S that have exactly the same number of runs as S, modulo 1000003.

Limits

1 ≤ T ≤ 100.

S is at least 1 character long.

Memory limit: 1GB.

Small dataset (Test set 1 - Visible; 14 Points)

S is at most 100 characters long.

Time limit: 30 6 seconds.

Large dataset (Test set 2 - Hidden; 16 Points)

S is at most 450000 characters long.

S has at most 100 runs.

The input file will not exceed 1 megabyte in size.

Time limit: 60 12 seconds.

Sample

2
aabcd
bookkeeper
Case #1: 24
Case #2: 7200
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.