MIPS | Malaysian Informatics And Programming Society

Trick or Treat

Statement

It’s Halloween! Evirir the dragon wants to give their two hatchlings candies. As a dragon who likes candies, Evirir has a hoard of NN candy packs numbered 1,2,,N1, 2, \ldots, N. For each i=1,2,,Ni = 1, 2, \ldots, N, candy pack ii contains two candies, one with colour aia_i and one with colour bib_i.

Evirir wants to give each hatchling 3 candies, so they will choose 3 candy packs (3×2=63 \times 2 = 6 candies in total). To make clear which candies are whose, there must be two distinct colours xx and yy (xyx \ne y) such that 3 of the 6 candies have colour xx, and the other 3 candies have colour yy.

In how many ways can Evirir choose the candy packs?

Note: Two ways are different if a candy pack is chosen in one way but not in the other (the order of chosen candy packs does not matter). Candy packs numbered differently are considered different, even if they have the same candy colours.

Input Format

The first line contains an integer NN.

Then, NN lines follow. The ii-th of the NN lines contains two space-separated integers, aia_i and bib_i.

Output Format

Output an integer, the answer.

Constraints

For all tasks:

Sample Input

9
1 2
1 3
2 1
1 1
2 2
1 3
3 1
1 1
1 1

Sample Output

7

Sample Explanation

There are 9 candy packs. Candy pack 1 has candies with colour 1 and colour 2, candy pack 2 has candies with colour 1 and colour 3, and so on.

There are 7 ways to choose the 3 candy packs:

Here are some invalid ways to choose the 3 candy packs:

One valid way and the three invalid ways above are shown in Figure 1:

Examples of valid and invalid ways to choose 3 candy packs
Figure 1: Examples of valid and invalid ways to choose 3 candy packs.

Trick or Treat

Pernyataan

Hari ini merupakan hari Halloween! Evirir si naga ingin memberikan gula-gula kepada dua ekornya anaknya yang baru menetas. Sebagai seekor naga yang gemarkan gula-gula, Evirir mempunyai timbunan sebanyak NN bungkus gula-gula yang bernombor 1,2,,N1, 2, \ldots, N. Bagi setiap i=1,2,,Ni = 1, 2, \ldots, N, bungkusan gula-gula ke-ii mengandungi dua biji gula-gula, satu berwarna aia_i dan satu lagi berwarna bib_i.

Evirir ingin memberikan setiap anak naganya 3 biji gula-gula, maka dia akan memilih 3 bungkusan gula-gula (jumlah keseluruhan 3×3=63 \times 3 = 6 biji gula-gula). Untuk membezakan gula-gula antara kedua-dua anak naga tersebut, terdapat tepat dua warna berbeza xx dan yy, xyx \ne y, dengan 3 daripada 6 gula-gula berwarna xx dan 3 yang selebihnya berwarna yy.

Berapakah bilangan cara Evirir boleh memilih bungkusan gula-gula tersebut?

Nota: Dua cara dianggap berbeza jika terdapat sekurang-kurangnya satu bungkusan gula-gula yang dipilih dalam satu cara tetapi tidak dalam cara yang lain (urutan pemilihan tidak penting). Bungkusan gula-gula yang bernombor berbeza dianggap berbeza, walaupun mengandungi warna gula-gula yang sama.

Format Input

Baris pertama mengandungi satu integer NN.

Kemudian, terdapat NN baris berikutnya. Baris ke-ii (daripada NN baris tersebut) mengandungi dua integer yang dipisahkan oleh ruang, aia_i dan bib_i.

Format Output

Keluarkan satu integer, iaitu jawapan kepada bilangan cara yang mungkin.

Kekangan

Untuk semua tugasan:

Contoh Input

9
1 2
1 3
2 1
1 1
2 2
1 3
3 1
1 1
1 1

Contoh Output

7

Penjelasan Contoh

Terdapat 9 bungkusan gula-gula. Bungkusan 1 mempunyai warna 1 dan 2, bungkusan 2 mempunyai warna 1 dan 3, dan seterusnya.

Terdapat 7 cara untuk memilih 3 bungkusan gula-gula yang memenuhi syarat:

Berikut ialah beberapa contoh pemilihan yang tidak sah:

Satu contoh cara yang sah dan tiga contoh cara yang tidak sah ditunjukkan dalam Rajah 1.

Examples of valid and invalid ways to choose 3 candy packs
Rajah 1: Contoh cara yang sah dan cara yang tidak sah untuk memilih 3 bungkusan gula-gula.

不给糖就捣蛋

题目描述

是万圣节诶!龙 Evirir 想给他的两个幼崽一些糖果。身为一个喜爱糖果的龙,Evirir 囤积了 NN 袋标记为 1,2,,N1, 2, \ldots, N 的糖果包。对于每个 i=1,2,,Ni = 1, 2, \ldots, N,糖果包 ii 拥有两个糖果,其中一个是颜色 aia_i 而另一个是颜色 bib_i

Evirir 想要给每个幼崽3粒糖果,所以他会选择三个糖果包(共有 3×2=63 \times 2 = 6 粒糖果)。为了分清楚哪个糖果是谁的,六粒糖果必须仅有两种不同颜色 xxyyxyx \ne y),并且其中三个糖果必须是颜色 xx 而另外三个糖果必须是颜色 yy

请问 Evirir 共有多少种方式选择糖果包?

注意:若在一种方式中选择了某个糖果包,而在另一种方式中没有选择,则认为这两种方式不同。选择顺序无关。编号不同的糖果包视为不同,即使它们的糖果颜色相同。

输入格式

第一行包含一个整数 NN

接下来的 NN 行中,第 ii 行包含两个整数 - aia_ibib_i

输出格式

输出一个整数表示答案。

约束

对于每项任务:

样例输入

9
1 2
1 3
2 1
1 1
2 2
1 3
3 1
1 1
1 1

样例输出

7

样例解释

一共有九袋糖果包。糖果包1有一个颜色为一的糖果和一个颜色为2的糖果;糖果包2有一个颜色为1的糖果和一个颜色为3的糖果,以此类推。

一共有七种方式选择三袋糖果包,如下:

一些无效的选择方式如下:

图一表示其中一种有效和三种无效的方式:

一些有效和无效地选三个糖果包的例子
图一:一些有效和无效地选三个糖果包的例子。