logo AlgoBeat OnlineJudge
登录 注册

#213500. [GCJ 2011 Finals] Runs

内存限制:1024 MiB 时间限制:6000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

I have a string 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 have exactly the same number of runs as ?

Two permutations and are considered different if there exists some index at which they have a different character: .

输入格式

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

输出格式

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

样例

样例输入 1

2
aabcd
bookkeeper

样例输出 1

Case #1: 24
Case #2: 7200

数据范围与提示

Limits

  • .
  • is at least character long.

Small dataset (Test set 1 - Visible)

  • is at most characters long.
  • Time limit: 30 3 seconds.

Large dataset (Test set 2 - Hidden)

  • is at most characters long.
  • has at most runs.
  • The input file will not exceed megabyte in size.
  • Time limit: 60 6 seconds.