> For the complete documentation index, see [llms.txt](https://eaglepb2.gitbook.io/cpw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://eaglepb2.gitbook.io/cpw/codenection/2024/preliminary-round/codey-and-toy-kingdom.md).

# Codey and Toy Kingdom

https\://www\.hackerrank.com/contests/codenection-2024-preliminary-round-open-category/challenges/cn24-16

## Question

Codey bought a new set of toys, which includes islands and bridges, and wanted to build a dream toy kingdom using them.

First, Codey arranged $$2*n$$ islands in a circle, numbered from $$1$$ to $$2*n$$ in a clockwise direction, and connected each pair of adjacent islands with a bridge. Although this version of the toy kingdom allows travel between any two islands using a series of bridges, it is inefficient. To improve travel between distant islands, Codey decided to build bridges between islands that are not adjacent.

Codey used the $$n$$ remaining bridges to connect different pairs of islands. Each island will have exactly one extra bridge connected to it. For each pair of bridges that intersect, the complexity of the toy kingdom increases by $$1$$.

Help Codey determine the total complexity of the toy kingdom.

### Input Format

The first line contains an integer `n`, which there are $$2\*n$$ islands.

The next `n` lines contain two space-separated integers, $$a\_i$$ and $$b\_i$$, representing the $$i$$-th bridge between islands $$a\_i$$ and $$b\_i$$.

### Constraints

$$
1 \le n \le 2\*10^5
$$

$$
1 \le a\_i,b\_i \le 2\*n
$$

* Each island will have exactly one extra bridge connected to it.

### Output Format

Output the total complexity of the toy kingdom.

### Sample Inputs:

{% tabs %}
{% tab title="Input 0" %}

#### Input

```
3
1 3
2 5
4 6
```

#### Output

```
2
```

#### Explanation

![](https://213594449-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuSDQ9GlkKEKWNcvZfewO%2Fuploads%2Fb2kAGVTmTnsRT1q2BGcb%2Fimage.png?alt=media\&token=8dae08bc-2539-4616-8d05-d8b19d4c9c12)

The total complexity is `2` because the following pairs of bridges intersect:

* $$(4, 6)$$ and $$(2, 5)$$
* $$(1, 3)$$ and $$(2, 5)$$
  {% endtab %}
  {% endtabs %}

***

<details>

<summary>Solution - WIP</summary>

WIP, haven't start yet.

</details>
