5. Three brothers - Ivan, Dmitry, and Sergey - teach different subjects in schools in Moscow, St. Petersburg, and Kaluga. Ivan does not work in Moscow, and Dmitry does not work in St. Petersburg. The Muscovite does not teach history. The one who works in St. Petersburg teaches chemistry. Dmitry teaches biology. What subject does Sergey teach, and in which city's school?
5. This task is about three brothers (Ivan, Dmitry, Sergey); the cities where they work (Moscow, Saint Petersburg, Kaluga), and their professions (historian, chemist, biologist).

First, let's determine the profession of each resident. We will create a table:

|  | H | C | B |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ |  |  |  |
| $\mathrm{C}$ |  |  |  |
| $\mathrm{K}$ |  |  |  |

Based on the conditions of the task, let's fill in the table. The Muscovite does not teach history.

|  | H | C | B |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - |  |  |
| $\mathrm{C}$ |  |  |  |
| $\mathrm{K}$ |  |  |  |

The chemist works in Saint Petersburg.

|  | H | C | B |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - |  |  |
| $\mathrm{C}$ |  | + |  |
| $\mathrm{K}$ |  |  |  |

Thus, the person who lives in Saint Petersburg cannot teach history or biology, just as the Muscovite and the Kalugan cannot teach chemistry.

|  | H | C | B |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | - |  |
| $\mathrm{C}$ | - | + | - |
| $\mathrm{K}$ |  | - |  |

Therefore, the Muscovite teaches biology, and the Kalugan teaches history.

|  | H | C | B |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | - | + |
| $\mathrm{C}$ | - | + | - |
| $\mathrm{K}$ | + | - | - |

On the next step, we will establish the correspondence between the city and the name.

Ivan does not work in Moscow, and Dmitry does not work in Saint Petersburg.

|  | I | D | S |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - |  |  |
| $\mathrm{C}$ |  | - |  |
| $\mathrm{K}$ |  |  |  |

As we have determined earlier, the Muscovite teaches biology, and Dmitry teaches biology. Therefore, Dmitry is the Muscovite.

|  | I | D | S |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | + |  |
| $\mathrm{C}$ |  | - |  |
| $\mathrm{K}$ |  |  |  |

Thus, Dmitry cannot be from Kaluga, and Sergey cannot work in Moscow.

|  | I | D | S |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | + | - |
| $\mathrm{C}$ |  | - |  |
| $\mathrm{K}$ |  |  |  |

Since there are no more conditions that allow us to fill in the table, we will have to make an assumption about Sergey or Ivan and see what happens.

Case 1. Let Ivan work in Saint Petersburg.

|  | I | D | S |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | + | - |
| $\mathrm{C}$ | + | - |  |
| $\mathrm{K}$ |  |  |  |

This means that Ivan does not work in Kaluga and Sergey does not work in Saint Petersburg.

|  | I | D | S |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | + | - |
| $\mathrm{C}$ | + | - | - |
| $\mathrm{K}$ |  |  |  |

Thus, Sergey works in Kaluga.

|  | I | D | S |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | + | - |
| $\mathrm{C}$ | + | - | - |
| $\mathrm{K}$ |  |  | + |

Case 2. Let Ivan work in Kaluga.

|  | I | D | S |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | + | - |
| $\mathrm{C}$ |  | - |  |
| $\mathrm{K}$ | + |  |  |

Then Ivan does not work in Saint Petersburg and Sergey does not work in Kaluga.

|  | I | D | S |
| :--- | :--- | :--- | :--- |
| $\mathrm{M}$ | - | + | - |
| $\mathrm{C}$ | - | - | + |
| $\mathrm{K}$ | + |  | - |

Therefore, Sergey works in Saint Petersburg.

Answer: Sergey works in Kaluga and teaches history or Sergey works in Saint Petersburg and teaches chemistry.