Sobes.tech
Intern

Afanasy had been working for 2 weeks on writing code capable of solving Japanese crossword puzzles with support for nine colors, when at a team meeting, a colleague told him that he could handle the task faster himself, and there was no point in the program anymore. But Afanasy, being an optimist, decided to continue practicing this task and do the following — estimate how well his colleague handles crosswords. For this assessment, he chose an analog of the IoU metric — the calculation will be similar to the classic Intersection Over Union, but by colors. It works as follows: each matching cell in the original and the solution by color adds 1 to the numerator, and in the denominator, 1 is added for each cell in the original and the solution (for matching cells, only one is added). After that, averaging is performed over the number of colors in the original image, rounded to two decimal places; zero is not considered a color, so the metric should not be calculated for cells of this color. Input starts with a line containing the number of rows n and columns m (in that order). Then, 2n lines follow, containing m numbers separated by spaces — the first n lines relate to the submitted crossword, and the next n — to the original image. It is assumed that each line, starting from the second, contains exactly m numbers. As an answer, output a number rounded to two decimal places, as in the examples. Here are some examples: 1. First example [phone] -> 1.0 Explanation: the contribution of matching and non-matching cells (1.0 + 1.0 + 1.0 + 1.0) / number of colors (4) 2. Second example [phone] -> 0.08 Explanation: the contribution of matching and non-matching cells (0.25 + 0.0 + 0.0) / number of colors (3); zeros are not counted, neither as cells in representations nor in the number of colors. 3. Third example [phone] where the submitted image starts [phone] — where the submitted image ends 0 1 2 — where the original image begins [phone] -> 0.47 Explanation: the contribution of matching and non-matching cells (0.4 + 0.5 + 0.5) / number of colors (3); zeros are not counted as cells in representations nor in the number of colors. 4. Fourth example [phone] -> 0.0 Explanation: the contribution of matching and non-matching cells (0.0) / number of colors (1); zeros are not counted as cells in representations nor in the number of colors.