301424: CF268A. Games

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Games

题意翻译

每个球队有两套制服:主场制服和嘉宾制服。当一支球队在主场比赛时,球员们会穿上主场队服。当一支球队作为客人在别人的球场上比赛时,球员们会穿上客人的制服。该规则的唯一例外是:当主队的主场队服颜色与客人的队服匹配时,主队也要穿上客人的队服。对于每个团队来说,主宾制服的颜色是不同的。 有n支队伍参加比赛。比由n (n - 1)场比赛组成:每队邀请另一队到它的体育场。在锦标赛期间,一个主队要穿多少次客队制服? 请注意,游戏的顺序不影响这个数字。你知道每个队的主宾制服的颜色。为简单起见,颜色用整数编号,这样两种不同的颜色就不会有相同的数字。 输入第一行包含一个整数n (2 ≤ n ≤ 30)。以下n行中的每一行都包含一对不同的用空格分隔的整数\,$h_i,a_i$ (1 ≤\,$h_i,a_i$≤100)——分别是第i队主队和客队队服的颜色。 输出在一行中打印主队将穿着客队制服比赛的场次。

题目描述

Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are $ n $ teams taking part in the national championship. The championship consists of $ n·(n-1) $ games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.

输入输出格式

输入格式


The first line contains an integer $ n $ ( $ 2<=n<=30 $ ). Each of the following $ n $ lines contains a pair of distinct space-separated integers $ h_{i} $ , $ a_{i} $ ( $ 1<=h_{i},a_{i}<=100 $ ) — the colors of the $ i $ -th team's home and guest uniforms, respectively.

输出格式


In a single line print the number of games where the host team is going to play in the guest uniform.

输入输出样例

输入样例 #1

3
1 2
2 4
3 4

输出样例 #1

1

输入样例 #2

4
100 42
42 100
5 42
100 5

输出样例 #2

5

输入样例 #3

2
1 2
1 2

输出样例 #3

0

说明

In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2. In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first).

Input

题意翻译

每个球队有两套制服:主场制服和嘉宾制服。当一支球队在主场比赛时,球员们会穿上主场队服。当一支球队作为客人在别人的球场上比赛时,球员们会穿上客人的制服。该规则的唯一例外是:当主队的主场队服颜色与客人的队服匹配时,主队也要穿上客人的队服。对于每个团队来说,主宾制服的颜色是不同的。 有n支队伍参加比赛。比由n (n - 1)场比赛组成:每队邀请另一队到它的体育场。在锦标赛期间,一个主队要穿多少次客队制服? 请注意,游戏的顺序不影响这个数字。你知道每个队的主宾制服的颜色。为简单起见,颜色用整数编号,这样两种不同的颜色就不会有相同的数字。 输入第一行包含一个整数n (2 ≤ n ≤ 30)。以下n行中的每一行都包含一对不同的用空格分隔的整数\,$h_i,a_i$ (1 ≤\,$h_i,a_i$≤100)——分别是第i队主队和客队队服的颜色。 输出在一行中打印主队将穿着客队制服比赛的场次。

加入题单

上一题 下一题 算法标签: