Games

Practice this coding question on Coding Gurukul.

Problem statement

A college league gives every team a home-shirt colour and an away-shirt colour. During the season each team hosts every other team once. A kit conflict occurs when the home team’s home colour equals the visiting team’s away colour. The league needs a count of affected fixtures so it can arrange alternative shirts before scheduling the matches. Your task For every ordered pair of different teams, compare the host’s home colour with the visitor’s away colour. Count the pair if the colours are equal. A fixture with team A hosting team B is different from the fixture with B hosting A, and either, both or neither may conflict. Important details No team plays itself. Each team’s own home and away colours differ, but colours may repeat across different teams. Count fixtures, not distinct colours or unordered pairs of teams. Worked example For teams (1,2), (2,1) and (3,1), team 1 conflicts when hosting team 2 or 3, and team 2 conflicts when hosting team 1. There are 3 conflicts.

Input format

First line: n. Next n lines: homeColour awayColour.

Output format

Print the number of conflicting fixtures.

Constraints

2 <= n <= 30; colours are 1..100; a team’s two colours differ.

Sample input

3
1 2
2 1
3 1

Sample output

3

Sign in to run or submit a solution in C++, Java or Python.