QOJ.ac

QOJ

実行時間制限: 1 s メモリ制限: 1024 MB 満点: 100 難易度: [表示] ハック可能 ✓

#16204. Swap

統計

Given $n$ digit strings, each containing only digits from 0 to 9. You need to perform $k$ swap operations. Each operation consists of choosing any two different positions across all strings and swapping the digits at those positions. After the swap operations, calculate the sum of the products of the $n$ strings when converted to integers, considering all possible outcomes.

Note: The positions chosen for each swap operation are independent, and it is allowed to choose the same two positions in two different swap operations.

Input

The first line contains two integers $n$ and $k$.

The next $n$ lines each contain a digit string $s_i$. It is guaranteed that the strings only contain digits 0 to 9.

Output

Output a single integer representing the answer. Since the answer can be very large, output the result modulo $10^9 + 7$.

Examples

Input 1

1 2
12
34

Output 1

3740

Note 1

After one swap operation, there are 6 possible outcomes for the two strings: 1. 21, 34 2. 12, 43 3. 32, 14 4. 42, 31 5. 13, 24 6. 14, 32

The final answer is: $21 \cdot 34 + 12 \cdot 43 + 32 \cdot 14 + 42 \cdot 31 + 13 \cdot 24 + 14 \cdot 32 = 3740$

Input 2

2 2
1
12

Output 2

165

Note 2

After two swap operations, there are 9 possible outcomes for the two strings: 1. 1, 12 2. 2, 11 3. 1, 21 4. 1, 21 5. 1, 12 6. 2, 11 7. 2, 11 8. 1, 21 9. 1, 12

The final answer is: $1 \cdot 12 + 2 \cdot 11 + 1 \cdot 21 + 1 \cdot 21 + 1 \cdot 12 + 2 \cdot 11 + 2 \cdot 11 + 1 \cdot 21 + 1 \cdot 12 = 165$

Examples 3-8

For examples 3 through 8, please refer to the files swap/swap3.in through swap/swap8.in and their corresponding .ans files in the contestant directory. These examples satisfy the constraints for the corresponding test cases.

Constraints

For all test data, it is guaranteed that $1 \le n \le 100$, $1 \le k \le 10^9$, $1 \le |s_i| \le 10^7$, and $2 \le \sum |s_i| \le 10^7$.

Test Case ID $n$ $k$ $ s_i $ $\sum s_i $ Special Property
1 ~ 2 $\le 5$ $\le 3$ $\le 5$ None
3 ~ 5 $= 1$ $\le 10^9$ None
6 ~ 8 $\le 100$ $= 1$ None
9 ~ 10 $\le 2$ None
11 ~ 12 A
13 ~ 18 $\le 10^5$ $\le 10^5$ None
19 ~ 20 $\le 10^7$ $\le 10^7$ None

Special Property A: The strings only contain the digits 1 and 2.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1118EditorialOpenNew Editorial for Problem #16204ucup-team78702026-02-25 10:18:05View

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.