To keep his cows entertained, Farmer John hung a large map of the USA on the wall of his barn. The cows spend hours staring at it, and they have started to notice curious patterns. For example, FLINT in Michigan and MIAMI in Florida have a special relationship. The first two letters of "FLINT" spell FL, the state code of MIAMI, and the first two letters of "MIAMI" spell MI, the state code of FLINT.
Two cities form a special pair when they have this property and belong to different states. City i and city j form a special pair when the first two letters of city i's name equal city j's state code, the first two letters of city j's name equal city i's state code, and the two state codes differ.
Count the special pairs. A pair has no order, so each pair of cities counts once.