Problem I
Quarantine Protocol
One of the rebels’ datacenters has been hacked! Viruses were randomly uploaded to a bunch of nodes in one of our computing clusters, and these viruses will spread as far as they can, blocking us from the computing resources we need to fight back against the AI Overlords. Fortunately, our cluster went into quarantine protocol, turning certain nodes into firewalls to block the spread of the viruses. We need to help the rebels determine how many of the nodes will be free of viruses after they’ve finished propagating.
Our supercomputer cluster has an interesting architecture. Individual computing nodes are aggregated in stacks, and each node can only talk to the one directly above or below it. As such, the uploaded viruses can only spread vertically within stacks, not horizontally between them. Viruses will spread until they have infected every node in their stack, unless a firewall node blocks off the infected clusters. Viruses cannot spread past firewall nodes, but will spread into every clean node they can.
Input
The first line of input contains two space-separated integers, $n$ and $m$ $(1 \leq n, m \leq 100)$, indicating the size of the grid. The next $n$ lines will each consist of $m$ space-separated characters, either O for clean, X for infected, or # for firewall, indicating the $n \times m$ grid.
Output
Output a single integer $x$ representing the number of firewall nodes plus the number of clean nodes left after the virus has run its course.
Explanation of sample output
The first sample should output $5$, since the first column contains a firewall node protecting the bottom clean node, the second column will get fully infected, and the third column has no viruses so it will be fully clean. Thus, there will be $4$ clean nodes remaining, and $1$ firewall node, for a total of $5$ uninfected nodes. The second sample should also output $5$, since two of the nodes in the first column are protected by the firewall node, and one node is protected by a firewall node in the second column, while the rest of the clean nodes will get infected.
| Sample Input 1 | Sample Output 1 |
|---|---|
3 3 X O O # X O O O O |
5 |
| Sample Input 2 | Sample Output 2 |
|---|---|
5 2 X O O # # X O O O O |
5 |