#P3405. [USACO16DEC] Cities and States S
[USACO16DEC] Cities and States S
Description
Farmer John has several cows. To train their intelligence, Farmer John put a map of the United States on the barn wall. The map shows each city and the code of the state it belongs to (2 uppercase letters).
Because the cows spend a lot of time looking at the map, they start to notice some strange relationships. For example, the first two letters of FLINT are the state of MIAMI, FL, and the first two letters of MIAMI are the state of FLINT, MI. Precisely, for two cities, the first two letters of each city's name are equal to the other city's state code.
We call two cities a "special" pair if they have the property above and they come from different states. Given total cities, the cows want to know how many "special" pairs exist. Please help them solve this interesting geography puzzle.
Input Format
The input consists of lines.
The first line contains a positive integer , the number of cities on the map.
Each of the next lines contains two strings: a city name ( to uppercase letters) and the code of its state ( uppercase letters). Within the same state, there are no two cities with the same name.
Output Format
Output a single line with one integer, the number of special city pairs.
6
MIAMI FL
DALLAS TX
FLINT MI
CLEMSON SC
BOSTON MA
ORLANDO FL
1
Hint
Constraints: For of the testdata, , and the city name length is at most .
Translated by ChatGPT 5
京公网安备 11011102002149号