#P16780. ⌈Xzy OI R1 T2⌋ 成成边

    ID: 18744 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>组合数学字典树 Trie哈希表

⌈Xzy OI R1 T2⌋ 成成边

Background

A short and to-the-point statementhow could it be a bad statement.

Problem Description

Given nn strings s1,s2,…,sns_1, s_2, \dots, s_n. Construct a complete graph GG with vertices numbered 1∼n1 \sim n. The weight of edge (i,j)(i, j) is defined as LCP(si,sj)\text{LCP}(s_i, s_j), i.e., the length of the longest common prefix of the two strings.

Define the weight of a spanning tree TT as the sum of the weights of all edges in TT.

Find the sum of the weights of all spanning trees of GG, and output the answer modulo 109+710^9+7.

Input Format

The first line contains an integer nn. The next nn lines each contain a string sis_i.

Output Format

Output one integer, representing the answer.

3
ab
ac
ad
6

Hint

Sample Explanation

The complete graph K3K_3 has 33 spanning trees, and each tree contains two edges. All three edges have weight 11, so the sum of edge weights in each tree is 22, and the total sum is 66.


Constraints

This problem uses bundled subtasks, which means you must pass all test points in a subtask to get the score for that subtask.

::cute-table{tuack}

Subtask Score 1≤n≤1 \le n \le 1≤∑∣si∣≤1 \le \sum \lvert s_i \lvert \le Special Restriction
11 1010 88 5050 None
22 2020 300300 50005000
33 20002000 ^
44 1515 10510^5 2×1062\times 10^6 All strings are exactly the same
55 3535 ^ None

For 100%100 \% of the testdata, each sis_i consists of lowercase letters.

Translated by ChatGPT 5