Perspectives II


Submit solution

Points: 1
Time limit: 1.0s
Python 2.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
C, C++, Java, Python

Minecraft is a game about mining resources and building structures out of cubes. After seeing Saadan's show of wealth, Shashwat wants to one-up him by making a diamond-block structure himself.

He crafts his diamonds into blocks and, unlike Saadan, builds a 3D stucture that may be more than 1 block tall. He then takes three screensbots to share on Discord.

  • One from the front view (the XY-plane)

  • One from the side view (the YZ-plane)

  • One from the above view (the XZ-plane).

From these three perspectives, it is not immediately clear how many diamond blocks Shash's structure actually contains. Peter, astounded, wants to determine the maximum possible number of blocks that could match all screenshots.

For example, if the screenshots look like:

.##
.#.
###

Image 1

.##
.#.
#.#

Image 2

#..
###
###

Image 3

Then Shashwat's structure could contain up to 10 diamond blocks, as shown below:

Image 4 Image 5

Input

The first line contains two integers n (1 \leq n \leq 100), the number of rows and columns visible in each screenshot.

The next n lines contains a string S_f of length c, representing the front view (the XY-plane, rows = Y, columns = X).

The next n lines contains a string S_s of length c, representing the side view (the YZ-plane, rows = Y, columns = Z).

The next n lines contains a string S_t of length t, representing the top view (the XZ-plane, rows = X, columns = Z).

Each character of S_f, S_s and S_t is either:

  • #: A diamond block
  • .: Empty space

Output

Output the maximum number of diamond blocks Shashwat could have used in this structure, given these three perspectives.

Clarifications

  • Each perspective will have at least 1 diamond block.
  • The perspectives will always correspond to a valid structure.

Example

Input 1
3
.##
.#.
###
.##
.#.
#.#
#..
###
###
Output 1
10

This is the example as given above.

Input 2
2
##
##
##
##
##
##
Output 2
8
Input 3
3
..#
.##
#.#
#..
##.
#.#
#..
#..
###
Output 3
7
Input 4
4
...#
###.
..#.
.#.#
#...
##..
.#..
#.#.
#...
.##.
##..
#...
Output 4
8

Comments

There are no comments at the moment.