cho.sh
Notes
Loading...

The Famous Seven Princesses

Time limit

2s

Memory limit

256 MB

Problem

There are 25 students seated in a 5*5 square grid. Each student belongs to either group S or group Y.

Choose 7 students to form one group. The group must satisfy all of the following conditions.

  1. It must contain exactly 7 students.
  2. The 7 chosen seats must form one connected area using only horizontal or vertical adjacency.
  3. Students from group Y may be included.
  4. However, at least 4 of the chosen students must belong to group S.

Given the seating chart, compute the number of ways to choose such a group of 7 students.

Input

Five lines are given, from the first row to the fifth row of the seating chart. Each line has five characters, each either S or Y, with no spaces.

Output

Print the number of valid groups of 7 students.

Hint

The following diagram shows two possible selected shapes.

.....    .....SYSYS    SYSYS....Y    .Y.......S    .S........    .....
.....    .....SYSYS    SYSYS....Y    .Y.......S    .S........    .....