import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
scanner.nextLine(); // 消耗换行符
// 用于统计每个(前缀, 州)组合的城市数量
Map<String, Integer> countMap = new HashMap<>();
for (int i = 0; i < N; i++) {
String[] parts = scanner.nextLine().split(" ");
String city = parts[0];
String state = parts[1];
// 获取城市名称的前两位字母作为前缀
String prefix = city.substring(0, 2);
// 构建键:前缀+州代码
String key = prefix + state;
countMap.put(key, countMap.getOrDefault(key, 0) + 1);
}
long result = 0;
// 遍历所有(前缀, 州)组合
for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
String key = entry.getKey();
int count = entry.getValue();
// 解析出前缀和州
String prefix = key.substring(0, 2);
String state = key.substring(2);
// 特殊对需要满足前缀不等于州,且存在反向组合
if (!prefix.equals(state)) {
String reverseKey = state + prefix;
if (countMap.containsKey(reverseKey)) {
// 两个组合的数量相乘,得到它们之间的特殊对数量
result += (long) count * countMap.get(reverseKey);
}
}
}
// 每个特殊对被计算了两次,所以除以2
System.out.println(result / 2);
scanner.close();
}
}