## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

# [Solution] Sort the Fabrics Round F 2022 - Kick Start 2022 Solution

### Problem

A fabric is represented by three properties:

• Color ($C$), a string consisting of lowercase letters of the English alphabet, representing the color of the fabric.
• Durability ($D$), an integer representing the durability of the fabric.
• Unique identifier ($U$), an integer representing the ID of the fabric.

Ada and Charles work at the Kick Start fabric factory. Each day they receive $N$ fabrics, and one of them has to sort it. They sort it using the following criteria:

• Ada sorts in lexicographically increasing order by color ($C$).
• Charles sorts in ascending order by durability ($D$).
• They break ties by sorting in ascending order by the unique identifier ($U$).

Given $N$ fabrics, count the number of fabrics which end up in the same position regardless of whether Ada or Charles sort them.

### Input

The first line of the input gives the number of test cases, $T$$T$ test cases follow.
Each test case begins with one line consisting of an integer $N$ denoting the number of fabrics. Then $N$ lines follow, each line with a string ${\mathbf{C}}_{\mathbf{i}}$, an integer ${\mathbf{D}}_{\mathbf{i}}$, and an integer ${\mathbf{U}}_{\mathbf{i}}$: the color, the durability and the unique identifier of the $i$-th fabric respectively.

### Output

For each test case, output one line containing Case #x$x$: y$y$, where $x$ is the test case number (starting from 1) and $y$ is the number of fabrics which end up in the same position regardless of whether a worker sorts them by color or by durability.

### Limits

Time limit: 20 seconds.
Memory limit: 1 GB.
$1\le \mathbf{T}\le 100$.
$1\le$ length of string ${\mathbf{C}}_{\mathbf{i}}$ $\le 10$.
String ${\mathbf{C}}_{\mathbf{i}}$ consists of only lowercase letters of the English alphabet.
No two fabrics have same ${\mathbf{U}}_{\mathbf{i}}$.

#### Test Set 1

$1\le \mathbf{N}\le 2$.
$1\le {\mathbf{D}}_{\mathbf{i}}\le 2$.
$1\le {\mathbf{U}}_{\mathbf{i}}\le 2$.

#### Test Set 2

$1\le \mathbf{N}\le {10}^{3}$.
$1\le {\mathbf{D}}_{\mathbf{i}}\le {10}^{2}$.
$1\le {\mathbf{U}}_{\mathbf{i}}\le {10}^{3}$.

In Sample Case #1, when sorted by color, the order of fabrics represented by the unique identifier is $1$ and $2$. When sorted by durability, the order of fabrics is $2$ and $1$. Therefore, $0$ fabrics have the same position when sorted by color or durability.

In Sample Case #2, when sorted by color, the order of fabrics represented by the unique identifier is $1$ and $2$. When sorted by durability, the order of fabrics is also $1$ and $2$. Therefore, $2$ fabrics have the same position. Notice that both fabrics have the same durability, so when Charles sorts them he decides that fabric $1$ comes first because it has a smaller identifier.

In Sample Case #3, since there is only $1$ fabric, the position remains the same whether the fabrics are sorted by color or durability.