# Recommendation Islands

*English translation by SOTA – AI Community of the Russian original. Organisers who would like this translation removed can email sota.ai.community@gmail.com.*

All-Russian School Olympiad in Informatics 2025–2026, Regional Stage, Grades 9–11<br>
“Artificial Intelligence” profile, Tour 2, 19 January 2026<br>
Task A

**Points for the task:** 100, 20 for each question<br>
**Answer submission format:** entering the answer or uploading a file, depending on the question<br>
**Number of attempts:** 10 for each subtask<br>
**Submission that counts:** the last one

## Statement

You work as an analyst in the team of an online marketplace. On the website, each product has a card with information (category, price, rating, brand, availability) and a “Customers also viewed” block, which shows other products that users often go to from this card.

You have been given an export of two tables in CSV format:

- `items.csv` — a list of products and their properties.
- `also_viewed.csv` — a list of “customers also viewed” transitions.

You need to answer several questions about the products and the structure of the recommendation graph. The answers must be obtained by processing the data programmatically (for example, in Python using pandas and simple graph algorithms).

The file `items.csv` contains information about the products. Each row is one product. Fields:

- `item_id` – a unique integer identifier of the product.
- `category` – the product category (phones, accessories, laptops, books, home, toys).
- `price` – the price of the product in conventional units (an integer).
- `rating` – the rating of the product according to reviews (a real number from 3.0 to 5.0 in steps of 0.1).
- `brand` – the brand name (a string).
- `in_stock` – 1 if the product is in stock, 0 if it is not.

The file `also_viewed.csv` describes the links between products in the “customers also viewed” block. Each row specifies a pair of products (`item_from`, `item_to`) for which it has been recorded that users often go from one to the other. In the tasks that refer to the “neighbours” of a product or to transitions between products, we assume that such a link works in both directions: if the table contains a row with the pair of products $A$ and $B$ (in any order), then $A$ and $B$ are considered directly linked recommendations. The “neighbours” of a product $X$ are all the products that are paired with $X$ in at least one row, regardless of whether $X$ is given in `item_from` or in `item_to`.

## Scoring

You can get up to 100 points for this task. Each item is worth 20 points.

Test results for subtasks 1, 2, 3 and 5 are **not available** during the tour. In all subtasks, the last submission counts.

---

## A1 – Question 1

How many products in the category phones have a rating of at least 4.5 (rating $\ge 4.5$) and are also in stock (`in_stock` $= 1$)?

### Output format

One integer – the number of such products.

### Answer evaluation metric

Exact match of the entered answer.

---

## A2 – Question 2

Consider only the products in the category laptops. For each brand, compute the average price of that brand's laptops. Which brand has the highest average price among the laptops?

If several brands have the same highest average price, you may output any of them.

### Output format

One word – the brand name (the brand string from the file `items.csv`).

### Answer evaluation metric

Exact match of the entered answer.

---

## A3 – Question 3

The marketing team wants to divide the products into three segments by price and rating:

- segment **premium** – if rating $\ge 4.5$ and price $\ge 50000$;
- segment **standard** – if rating $\ge 4.0$ and price $< 50000$;
- segment **budget** – in all other cases.

For each product, determine its segment (**premium** / **standard** / **budget**) according to these rules. Among the products that are in stock (`in_stock` $= 1$), count how many products belong to the segment **premium**.

### Output format

One integer — the number of products in the segment premium among the products with `in_stock` $= 1$.

### Answer evaluation metric

Exact match of the entered answer.

---

## A4 – Question 4

Consider the file `also_viewed.csv`. Find all the products that appear at least once in the field item_to (that is, the products that were shown at least once in the “Customers also viewed” block). For each category, count how many distinct products of that category appear in `item_to` at least once.

You need to prepare a table with two columns:

- `category` – the name of the category;
- `cnt` – the number of distinct products of this category that appear in `item_to`.

The table should include all the categories that are present in the file `items.csv`, even if `cnt` $= 0$ for some category. The rows of the table must be sorted by category name in alphabetical order.

### Output format

A text file `answer4.csv` in CSV format with a header and two columns:

`category,cnt`

The file must contain exactly one row for each category.

### Answer evaluation metric

The fraction of the categories `category` in your answer file for which the count `cnt` matches the count `cnt` in the reference answer file.

---

## A5 – Question 5

We consider the links between products as described in the section “Dataset description”: two products are considered directly linked if `also_viewed.csv` contains a row in which they appear as a pair (in any order).

Let us call a “recommendation island” any set of products within which one can get from any card to any other card by following direct links between products (via neighbours). If two products belong to different recommendation islands, then no chain of such transitions leads from one of them to the other.

We are interested in the recommendation islands that contain both at least one product of the category phones and at least one product of the category accessories.

How many such recommendation islands are there in our data?

### Output format

One integer – the number of “recommendation islands” that contain both at least one phones product and at least one accessories product.

### Answer evaluation metric

Exact match of the entered answer.
