import { readFileSync } from "fs";

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { cin, nCin, biCin } = (() => {
  const inputs = readFileSync("/dev/stdin", "utf-8").split(/[\n|\s]+/);
  let count = 0;
  const cin = () => inputs[count++];
  return { cin: cin, nCin: () => Number(cin()), biCin: () => BigInt(cin()) };
})();

const range = (n: number | bigint) => [...Array(Number(n))].map((_, i) => i);

type Color = "Black" | "White";
type Grid = Color[][] & {
  height: number;
  width: number;
};
type PickData = {
  index: number;
  isPicked: boolean;
};

const getBlackCnt = (hPicks: PickData[], wPicks: PickData[], grid: Grid) =>
  hPicks
    .filter(({ isPicked }) => isPicked)
    .map(({ index }) => {
      const cs = grid[index];
      return wPicks
        .filter(({ isPicked }) => isPicked)
        .map(({ index }) => (cs[index] === "Black" ? 1 : 0) as number)
        .reduce((acc, x) => acc + x, 0);
    })
    .reduce((acc, x) => acc + x, 0);

const wPickFn = (
  n: number,
  hPicks: PickData[],
  wPicks: PickData[],
  grid: Grid,
  K: number,
  initialBlackCnt: number
): number =>
  n >= grid.width
    ? (() => {
        const hCnt = getBlackCnt(
          range(grid.height).map((i) => ({ index: i, isPicked: true })),
          wPicks,
          grid
        );
        const wCnt = getBlackCnt(
          hPicks,
          range(grid.width).map((j) => ({ index: j, isPicked: true })),
          grid
        );
        const hwCnt = getBlackCnt(hPicks, wPicks, grid);

        return initialBlackCnt - (hCnt + wCnt - hwCnt);
      })() === K
      ? 1
      : 0
    : wPickFn(n + 1, hPicks, wPicks, grid, K, initialBlackCnt) +
      wPickFn(
        n + 1,
        hPicks,
        wPicks.map(({ index, isPicked }) =>
          index === n ? { index: index, isPicked: true } : { index: index, isPicked: isPicked }
        ),
        grid,
        K,
        initialBlackCnt
      );

const hPickFn = (n: number, hPicks: PickData[], grid: Grid, K: number, initialBlackCnt: number): number =>
  n >= grid.height
    ? wPickFn(
        0,
        hPicks,
        range(grid.width).map((j) => ({ index: j, isPicked: false })),
        grid,
        K,
        initialBlackCnt
      )
    : hPickFn(n + 1, hPicks, grid, K, initialBlackCnt) +
      hPickFn(
        n + 1,
        hPicks.map(({ index, isPicked }) =>
          index === n ? { index: index, isPicked: true } : { index: index, isPicked: isPicked }
        ),
        grid,
        K,
        initialBlackCnt
      );

{
  const [H, W, K] = [nCin(), nCin(), nCin()];

  const grid: Grid = (() => {
    const grid: Color[][] = range(H).map(() =>
      cin()
        .split("")
        .map((c) => (c === "#" ? "Black" : "White") as Color)
    );
    return { ...grid, height: H, width: W };
  })();

  const initialBlackCnt = getBlackCnt(
    range(grid.height).map((i) => ({ index: i, isPicked: true })),
    range(grid.width).map((j) => ({ index: j, isPicked: true })),
    grid
  );

  const getCnt = (K: number) =>
    hPickFn(
      0,
      range(grid.height).map((i) => ({ index: i, isPicked: false })),
      grid,
      K,
      initialBlackCnt
    );

  const cnt = getCnt(K);

  console.log(cnt);
}


Measured memory_bytes: 37688