### Problem Statement

A cube of size NxNxN was divided into small cubes of size 1x1x1. Then, some of the small cubes were removed, and three photos of the large cube were taken. You are given these three photos in the String[]s A, B and C. Character y of element x of A will be 'Y' if at least one small cube with x-coordinate x and y-coordinate y wasn't removed, or 'N' otherwise. Character z of element x of B will be 'Y' if at least one small cube with x-coordinate x and z-coordinate z wasn't removed, or 'N' otherwise. Character z of element y of C will be 'Y' if at least one small cube with y-coordinate y and z-coordinate z wasn't removed, or 'N' otherwise. Return the minimal number of small cubes which could've been removed to result in those three photos. If there is no way the three photos can be valid, return -1 instead.

### Definition

 Class: ThreePhotos Method: removeCubes Parameters: String[], String[], String[] Returns: int Method signature: int removeCubes(String[] A, String[] B, String[] C) (be sure your method is public)

### Constraints

-N will be between 1 and 50, inclusive.

-A, B and C will each contain exactly N elements.

-Each element of A, B and C will contain exactly N characters.

-Each element of A, B and C will contain only 'Y' or 'N' characters.

### Examples

0)

 `{"YY","YY"}` `{"YY","YY"}` `{"YY","YY"}`
`Returns: 0`
 Remove no cubes.
1)

 `{"NNN","NNN","NNN"}` `{"NNN","NNN","NNN"}` `{"NNN","NNN","NNN"}`
`Returns: 27`
 You will have to remove all cubes.
2)

 `{"NNNNN","NNNNN","NNNNN","YYNNN","NNNNN"}` `{"NNNNN","NNNNN","NNNNN","NNYNY","NNNNN"}` `{"NNYNN","NNNNY","NNNNN","NNNNN","NNNNN"}`
`Returns: 123`
3)

 `{"YY","YY"}` `{"YY","YY"}` `{"YN","YN"}`
`Returns: -1`

#### Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=9954

#### Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=13506&pm=9954

Gluk

#### Testers:

PabloGilberto , bmerry , Olexiy , ivan_metelsky

#### Problem categories:

Simple Search, Iteration