7978: Cities and States

内存限制:128 MB 时间限制:1 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:50 通过:24

题目描述

为了保持对奶牛的智力激发,农夫约翰在牛棚的墙上放了一张美国的大地图。

由于奶牛在牛棚里花了很多时间盯着这张地图,它们开始注意到一些奇怪的范例。

例如,密歇根州弗林特市 (Flint,MI) 和佛罗里达州迈阿密市 (Miami,FL) 有着非常特殊的关系:

弗林特 (Flint) 的前两个字母 FL 可用来表示迈阿密市所在的佛罗里达州,而迈阿密 (Miami) 的前两个字母 MI 可用来表示弗林特市所在的密歇根州。

如果两个城市满足这一特点,并且处在不同的州,则称这两个城市是一个“特殊对”。

奶牛们想知道一共存在多少个城市的“特殊对”。

输入格式

第一行包含整数 N,表示地图中城市的数量。

接下来 N 行,每行包含两个字符串,第一个字符串表示一个城市的名称(由大写字母构成,长度在 [2,10] 之间),第二个字符串表示该城市所在州的简称(由两个大写字母构成)。

请注意,数据中涉及的州可能在实际中并不存在,例如 ZQ

可以存在多个具有相同名称的城市,但它们将处于不同的州。

输出格式

输出城市的“特殊对”数量。

数据范围

1≤N≤2×105


To keep his cows intellectually stimulated, Farmer John has placed a large map of the USA on the wall of his barn. Since the cows spend many hours in the barn staring at this map, they start to notice several curious patterns. For example, the cities of Flint, MI and Miami, FL share a very special relationship: the first two letters of "Flint" give the state code ("FL") for Miami, and the first two letters of "Miami" give the state code ("MI") for Flint.

Let us say that two cities are a "special pair" if they satisfy this property and come from different states. The cows are wondering how many special pairs of cities exist. Please help them solve this amusing geographical puzzle!

INPUT FORMAT (file citystate.in):

The first line of input contains NN (1≤N≤200,000), the number of cities on the map. The next NN lines each contain two strings: the name of a city (a string of at least 2 and at most 10 uppercase letters), and its two-letter state code (a string of 2 uppercase letters). Note that the state code may be something like ZQ, which is not an actual USA state. Multiple cities with the same name can exist, but they will be in different states.

OUTPUT FORMAT (file citystate.out):

Please output the number of special pairs of cities.

SAMPLE INPUT:

6
MIAMI FL
DALLAS TX
FLINT MI
CLEMSON SC
BOSTON MA
ORLANDO FL

SAMPLE OUTPUT:

1

Problem credits: Brian Dean

输入样例 复制


输出样例 复制