#P15754. [JAG 2025 Summer Camp #1] Dyad

[JAG 2025 Summer Camp #1] Dyad

题目描述

A shop sells sweets in pairs.

There are NN products. The ii-th product contains a pair of sweets: one of type AiA_i and one of type BiB_i. AiA_i and BiB_i may be equal.

If you buy two different products, you will obtain four sweets in total. There are twins, and you want to give exactly two sweets to each of them. The twins are only satisfied if the multiset of sweet types received by each twin is identical.

Count the number of ways to choose two different products such that it is possible to distribute the sweets to the twins in this way.

输入格式

The input is given in the following format:

$$\begin{aligned} &N \\ &A_1 \ B_1 \\ &A_2 \ B_2 \\ &\vdots \\ &A_N \ B_N \end{aligned} $$
  • 2N3000002 \leq N \leq 300\,000
  • 1Ai,BiN1 \leq A_i, B_i \leq N (1iN1 \leq i \leq N)
  • All input values are integers.

输出格式

Output the answer in a single line.

4
2 3
3 2
1 1
2 2
2