All with Pairs
题号:NC207123
时间限制:C/C++/Rust/Pascal 3秒,其他语言6秒
空间限制:C/C++/Rust/Pascal 256 M,其他语言512 M
64bit IO Format: %lld

题目描述

Given strings . Now define as the maximum that satisfy , and if such doesn't exist, .
The Problem is to calculate:

输入描述:

The first line contains one integer , denoting the number of given strings.
The following lines each contains a string .
It's guaranteed that and all strings only contain lowercase letters.

输出描述:

Only one line containing one integer, denoting the answer.
示例1

输入

复制
3
ab
ba
aba

输出

复制
29

说明


So the answer is 4\times 1^2 + 4\times 2^2 + 1\times 3^2 = 29.