DPS
InterviewTime limit1sMemory limit1024 MB
Count the unordered groups of three people whose handle initials can be rearranged to spell the team name S.
- Level
Easy3 of 10
- Topics
- Combinatorics, Math, Hash map
- Solved
- No attempts yet
Problem
ICPC is an international collegiate programming contest where each team has three members. The name of each team is formed by joining the first letters of the three members' handles in any order. A handle is a unique ID used on online judge sites.
For example, if the handles are DONGGAS, PICASSO, and SEMTEO, the team name is one of DPS, DSP, PDS, PSD, SDP, or SPD. If the handles are RAARARAARA, WBCHO, and WEASEL, the team name is one of RWW, WRW, or WWR.
Given a team name and the handles of people, count all the ways to form the team from those people.
Input
The first line contains the team name , which consists of three uppercase English letters.
The second line contains a positive integer (), the number of people.
From the third line, handles are given, one per line. The length of each handle is between 1 and 10.
Each handle is a string of uppercase English letters with no spaces. All handles are distinct.
Output
Print the number of ways to form the team from the given people.
The answer may exceed the range of a 32-bit integer, so use a 64-bit integer type for your language:
- C/C++: long long
- Java: long
- Kotlin: Long