欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1166A.Silent Classroom
Silent Classroom
There are students in the first grade of Nlogonia high school. The principal wishes to split the students into two classrooms (each student must be in exactly one of the classrooms). Two distinct students whose name starts with the same letter will be chatty if they are put in the same classroom (because they must have a lot in common). Let be the number of such pairs of students in a split. Pairs and are the same and counted only once.
For example, if there are students: "olivia", "jacob", "tanya", "jack", "oliver" and "jessica", then:
- splitting into two classrooms ("
jack", "jacob", "jessica", "tanya") and ("olivia", "oliver") will give ( chatting pairs in the first classroom, chatting pair in the second classroom), - splitting into two classrooms ("
jack", "tanya", "olivia") and ("jessica", "oliver", "jacob") will give ( chatting pairs in the first classroom, chatting pair in the second classroom).
You are given the list of the names. What is the minimum we can obtain by splitting the students into classrooms?
Note that it is valid to place all of the students in one of the classrooms, leaving the other one empty.
Input
The first line contains a single integer () — the number of students.
After this lines follow.
The -th line contains the name of the -th student.
It is guaranteed each name is a string of lowercase English letters of length at most . Note that multiple students may share the same name.
Output
The output must consist of a single integer — the minimum possible number of chatty pairs.
Note
In the first sample the minimum number of pairs is . This can be achieved, for example, by putting everyone except jose in one classroom, and jose in the other, so jorge and jerry form the only chatty pair.
In the second sample the minimum number of pairs is . This can be achieved, for example, by putting kambei, gorobei, shichiroji and kyuzo in one room and putting heihachi, katsushiro and kikuchiyo in the other room. In this case the two pairs are kambei and kyuzo, and katsushiro and kikuchiyo.
In the third sample the minimum number of pairs is . This can be achieved by placing three of the students named mike in one classroom and the other two students in another classroom. Thus there will be three chatty pairs in one classroom and one chatty pair in the other classroom.
Samples
4
jorge
jose
oscar
jerry
1
7
kambei
gorobei
shichiroji
kyuzo
heihachi
katsushiro
kikuchiyo
2
5
mike
mike
mike
mike
mike
4
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |