logo AlgoBeat OnlineJudge
登录 注册

#215717. [ICPC 2025 Jakarta R] International Olympiad in ICPC

内存限制:2048 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Your university is hosting a competition called the IOI. As an event organiser, you want to create a banner for it. The banner you are preparing can be represented as a grid, where each cell will be printed either white or black. Due to printing issues, some of the cells cannot be printed in black.

You start with a white banner, and want to print the word on the banner as follows.

  • Form the first letter by printing a rectangle of size () in black.
  • Form the letter by printing a rectangular of size () in black.
  • Form the second letter by printing a rectangle of size () in black.

The letter must be formed between the letters , and there must be one column between the letters. It is also required that the width of the letter is the sum of the widths of the letters , i.e. . All other cells not part of the word must remain white.

Determine the maximum number of cells that you can print in black, or tell that it's impossible to print the word .

输入格式

The first line contains an integer (), the size of the grid.

Each of the next three lines contains characters representing the cells of the grid.

Each of the characters corresponds to a cell and is either or , meaning you can or cannot print the cell in black, respectively.

输出格式

A single line representing the maximum number of cells that you can print in black.

If it's impossible to print the word , output instead.

样例

样例输入 1

7
.......
.......
.......

样例输出 1

14

样例输入 2

6
......
......
......

样例输出 2

-1

样例输入 3

12
...#....#...
...#.##.#...
...#....#...

样例输出 3

22

样例输入 4

20
#...##..............
#...##.##....#...#..
#...##..............

样例输出 4

39

数据范围与提示

You can print your banner in the following way.

  I.OOO.I
  I.O.O.I
  I.OOO.I

You can print your banner in the following way.

  ..I#OOOO#III
  ..I#O##O#III
  ..I#OOOO#III

You can print your banner in the following way.

  #III##OOOOOOOOOOO.II
  #III##O##....#..O#II
  #III##OOOOOOOOOOO.II