#P8247. Infinite Arrow

    ID: 21426 Type: Default 1000ms 256MiB

Infinite Arrow

Infinite Arrow

You are given a training ground represented as an \(n \times m\) grid. Each cell of the grid contains one of the characters: S, K, or .. Here, S represents a sharpshooter (the "Infinite Arrow" hero), and K represents a skeleton. All other cells are empty (denoted by .).

The sharpshooter can shoot an arrow in any chosen direction. The arrow travels along an infinite ray (half-line) defined as \[ \vec r = \vec s + t\vec d, \quad t \ge 0, \] where \(\vec s\) is the position of the shooter and \(\vec d\) is the shooting direction.

A skeleton, being very fragile, is killed if it lies exactly on the path of an arrow. Note that an arrow shot from a particular shooter S covers all skeletons that lie on the ray starting from that shooter in the chosen direction.

Your task is to determine the minimum number of arrows needed so that every skeleton in the grid is killed. Assume that every character (sharpshooter or skeleton) is located at the center of a cell and has infinitesimal size.

inputFormat

The first line contains two integers \(n\) and \(m\) --- the number of rows and columns respectively.

The following \(n\) lines each contain a string of length \(m\) made up of the characters S, K, and ., representing the training ground.

outputFormat

Output a single integer --- the minimum number of arrows required to kill all skeletons.

sample

1 2
SK
1