package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type cell struct {
	y int
	x int
}

var (
	matrix  []string
	lakes   [][]cell
	n, m, k int
	dx      = []int{-1, 0, 1, 0}
	dy      = []int{0, -1, 0, 1}
	visited = [][]bool{}
)

func dfs(i int, j int) {
	isOcean := false
	temp := []cell{}
	stack := []cell{cell{i, j}}
	visited[i][j] = true

	for len(stack) > 0 {
		cur := pop(&stack)
		if onBorder(cur.y, cur.x) {
			isOcean = true
		}
		for d := 0; d < 4; d++ {
			newX := cur.x + dx[d]
			newY := cur.y + dy[d]
			if isValid(newX, newY) && matrix[newY][newX] == '.' && !visited[newY][newX] {
				visited[newY][newX] = true
				stack = append(stack, cell{newY, newX})
				if !isOcean {
					temp = append(temp, cell{newY, newX})
				}
			}
		}
	}
	if !isOcean {
		temp = append(temp, cell{i, j})
		lakes = append(lakes, temp)
	}
}

func pop(s *[]cell) cell {
	n := (*s)[len(*s)-1]
	(*s) = (*s)[:len(*s)-1]
	return n
}

func onBorder(y int, x int) bool {
	return y == 0 || x == 0 || y == n-1 || x == m-1
}

func isValid(x int, y int) bool {
	return 0 <= x && x < m && 0 <= y && y < n
}

func main() {
	r := bufio.NewReader(os.Stdin)
	fmt.Fscanf(r, "%d %d %d\n", &n, &m, &k)
	visited = make([][]bool, n)
	for i := range visited {
		visited[i] = make([]bool, m)
	}

	matrix = make([]string, n)
	for i := range matrix {
		fmt.Fscanf(r, "%s\n", &matrix[i])
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if !visited[i][j] && matrix[i][j] == '.' {
				dfs(i, j)
			}
		}
	}

	sort.Slice(lakes, func(i, j int) bool { return len(lakes[i]) < len(lakes[j]) })
	transformCell := 0
	num := len(lakes) - k
	for i := 0; i < num; i++ {
		transformCell += len(lakes[i])
		for j := range lakes[i] {
			c := lakes[i][j]
			arr := []byte(matrix[c.y])
			arr[c.x] = '*'
			matrix[c.y] = string(arr)
		}
	}

	fmt.Println(transformCell)
	for i := range matrix {
		fmt.Println(matrix[i])
	}
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"strings"
	"sort"
)

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

func main() {
	sc := NewScanner()
	n := sc.NextInt()
	m := sc.NextInt()
	k := sc.NextInt()
	in := make([]string, n)
	field := make([][]int, n)
	for i := 0; i < n; i++ {
		in[i] = sc.NextLine()
		field[i] = make([]int, m)
		for j := 0; j < m; j++ {
			if in[i][j] == '*' {
				field[i][j] = -1
			}
		}
	}
	bfs := func(sy, sx, lake int) int {
		x := make([]int, 1)
		y := make([]int, 1)
		x[0] = sx
		y[0] = sy
		field[sy][sx] = lake
		vec := []int{0, -1, 0, 1, 0 }
		isSea := false
		for i := 0; i < len(x); i++ {
			for v := 0; v < 4; v++ {
				if x[i] + vec[v] < 0 {
					isSea = true
					continue
				}
				if x[i] + vec[v] >= m {
					isSea = true
					continue
				}
				if y[i] + vec[v + 1] < 0 {
					isSea = true
					continue
				}
				if y[i] + vec[v + 1] >= n {
					isSea = true
					continue
				}
				if field[y[i] + vec[v + 1]][x[i] + vec[v]] != 0 {
					continue
				}
				x = append(x, x[i] + vec[v])
				y = append(y, y[i] + vec[v + 1])
				field[y[i] + vec[v + 1]][x[i] + vec[v]] = lake
			}
		}
		if isSea {
			return -1
		}
		return len(x)
	}

	lake := 0

	lakes := make(SortInterFace, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if field[i][j] == 0 {
				lake++
				result := bfs(i, j, lake)
				if result > 0 {
					lakes = append(lakes, Tup{lake, result})
				}
			}
		}
	}
	sort.Sort(lakes)

	changed := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			for v := 0; v < len(lakes) - k; v++ {
				if field[i][j] == lakes[v].lakes {
					field[i][j] = -1
					changed++
				}
			}
		}
	}
	fmt.Println(changed)
	for i := 0; i < n; i++ {
		out := ""
		for j := 0; j < m; j++ {
			if field[i][j] == -1 {
				out += "*"
			} else {
				out += "."
			}
		}
		fmt.Println(out)
	}
}

type Tup struct {
	lakes int
	count int
}

type SortInterFace []Tup

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].count < s[j].count
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"strings"
)

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

func main() {
	sc := NewScanner()
	n := sc.NextInt()
	m := sc.NextInt()
	k := sc.NextInt()
	in := make([]string, n)
	field := make([][]int, n)
	for i := 0; i < n; i++ {
		in[i] = sc.NextLine()
		field[i] = make([]int, m)
		for j := 0; j < m; j++ {
			if in[i][j] == '*' {
				field[i][j] = -1
			}
		}
	}
	bfs := func(sy, sx, lake int) int {
		x := make([]int, 1)
		y := make([]int, 1)
		x[0] = sx
		y[0] = sy
		field[sy][sx] = lake
		vec := []int{0, -1, 0, 1, 0 }
		isSea := false
		for i := 0; i < len(x); i++ {
			for v := 0; v < 4; v++ {
				if x[i] + vec[v] < 0 {
					isSea = true
					continue
				}
				if x[i] + vec[v] >= m {
					isSea = true
					continue
				}
				if y[i] + vec[v + 1] < 0 {
					isSea = true
					continue
				}
				if y[i] + vec[v + 1] >= n {
					isSea = true
					continue
				}
				if field[y[i] + vec[v + 1]][x[i] + vec[v]] != 0 {
					continue
				}
				x = append(x, x[i] + vec[v])
				y = append(y, y[i] + vec[v + 1])
				field[y[i] + vec[v + 1]][x[i] + vec[v]] = lake
			}
		}
		if isSea {
			return -1
		}
		return len(x)
	}

	lake := 0
	type Tup struct {
		lakes int
		count int
	}
	lakes := make([]Tup, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if field[i][j] == 0 {
				lake++
				result := bfs(i, j, lake)
				if result > 0 {
					lakes = append(lakes, Tup{lake, result})
				}
			}
		}
	}
	for i := 0; i < len(lakes); i++ {
		for j := i + 1; j < len(lakes); j++ {
			if lakes[i].count > lakes[j].count {
				lakes[i], lakes[j] = lakes[j], lakes[i]
			}
		}
	}
	changed := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			for v := 0; v < len(lakes) - k; v++ {
				if field[i][j] == lakes[v].lakes {
					field[i][j] = -1
					changed++
				}
			}
		}
	}
	fmt.Println(changed)
	for i := 0; i < n; i++ {
		out := ""
		for j := 0; j < m; j++ {
			if field[i][j] == -1 {
				out += "*"
			} else {
				out += "."
			}
		}
		fmt.Println(out)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m-1 && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n-1 && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
		parent[0]--
	}
	if parent[1]-1 > 0 && a[parent[0]][parent[1]-1] == '.' {
		parent[1]--
		waterToLand(parent)
		parent[1]++
	}
	if parent[0]-1 > 0 && a[parent[0]-1][parent[1]] == '.' {
		parent[0]--
		waterToLand(parent)
		parent[0]++
	}
}

type pos [2]int
type stack []pos

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int

func (s stack) Push(v pos) stack {
	return append(s, v)
}

func (s stack) Pop() (stack, pos) {
	l := len(s)
	return s[:l-1], s[l-1]
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			if a[i][j] == '.' {
				s := make(stack, 0)
				count := 0
				flag := false
				o := pos{i, j}
				s = s.Push(o)
				for len(s) > 0 {
					s, o = s.Pop()
					if !visit[o[0]][o[1]] && a[o[0]][o[1]] == '.' {
						visit[o[0]][o[1]] = true
						if o[0] == 0 || o[0] == n-1 || o[1] == 0 || o[1] == m-1 || (o[0]+1 == n-1 && a[o[0]+1][o[1]] == '.') || (o[1]+1 == m-1 && a[o[0]][o[1]+1] == '.') || (o[0]-1 == 0 && a[o[0]-1][o[1]] == '.') || (o[1]-1 == 0 && a[o[0]][o[1]-1] == '.') {
							flag = true
						}
						count++
						if o[0]+1 < n {
							s = s.Push(pos{o[0] + 1, o[1]})
						}
						if o[0]-1 > 0 {
							s = s.Push(pos{o[0] - 1, o[1]})
						}
						if o[1]+1 < m {
							s = s.Push(pos{o[0], o[1] + 1})
						}
						if o[1]-1 > 0 {
							s = s.Push(pos{o[0], o[1] - 1})
						}
					}
				}
				if count > 0 && !flag {
					node = insert(node, count, []int{i, j})
					nodeCount++
				}
			}
		}
	}
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m-1 && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n-1 && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
		parent[0]--
	}
	if parent[1]-1 > 0 && a[parent[0]][parent[1]-1] == '.' {
		parent[1]--
		waterToLand(parent)
		parent[1]++
	}
	if parent[0]-1 > 0 && a[parent[0]-1][parent[1]] == '.' {
		parent[0]--
		waterToLand(parent)
		parent[0]++
	}
}

type Node struct {
	Count  int
	Parent []int
}

type pos [2]int
type stack []pos

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int
var res []Node

type ByCount []Node

func (s stack) Push(v pos) stack {
	return append(s, v)
}

func (s stack) Pop() (stack, pos) {
	l := len(s)
	return s[:l-1], s[l-1]
}

func (slice ByCount) Len() int {
	return len(slice)
}

func (slice ByCount) Less(i, j int) bool {
	return slice[i].Count < slice[j].Count
}

func (slice ByCount) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			if a[i][j] == '.' {
				s := make(stack, 0)
				count := 0
				o := pos{i, j}
				s = s.Push(o)
				flag := false
				for len(s) > 0 {
					s, o = s.Pop()
					if !visit[o[0]][o[1]] && a[o[0]][o[1]] == '.' {
						visit[o[0]][o[1]] = true
						if o[0] == 0 || o[0] == n-1 || o[1] == 0 || o[1] == m-1 || ((o[0]+1 == n-1 || o[0]+1 == 0) && a[o[0]+1][o[1]] == '.') || ((o[1]+1 == m-1 || o[1]+1 == 0) && a[o[0]][o[1]+1] == '.') || ((o[0]-1 == 0 || o[0]-1 == n-1) && a[o[0]-1][o[1]] == '.') || ((o[1]-1 == 0 || o[1]-1 == m-1) && a[o[0]][o[1]-1] == '.') {
							flag = true
						}
						count++
						if o[0]+1 >= 0 && o[0]+1 < n {
							s = s.Push(pos{o[0] + 1, o[1]})
						}
						if o[0]-1 >= 0 && o[0]-1 < n {
							s = s.Push(pos{o[0] - 1, o[1]})
						}
						if o[1]+1 < m && o[1]+1 >= 0 {
							s = s.Push(pos{o[0], o[1] + 1})
						}
						if o[1]-1 >= 0 && o[1]-1 < m {
							s = s.Push(pos{o[0], o[1] - 1})
						}
					}
				}
				if count > 0 && !flag {
					res = append(res, Node{count, []int{i, j}})
					nodeCount++
				}
			}
		}
	}
	sort.Sort(ByCount(res))
	for nodeCount > k {
		nodeCount--
		waterToLand(res[0].Parent)
		res = res[1:]
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import "fmt"
import "bufio"
import "os"
import "sort"

var bufin *bufio.Reader
var bufout *bufio.Writer

type Pair struct {
	c   int
	cnt int
}

type PairSlice []Pair

func (s PairSlice) Len() int               { return len(s) }
func (s PairSlice) Less(i int, j int) bool { return s[i].cnt > s[j].cnt }
func (s PairSlice) Swap(i int, j int)      { s[i], s[j] = s[j], s[i] }

var dr = [4]int{-1, 0, +1, 0}
var dc = [4]int{0, +1, 0, -1}

var n, m, k, nc, cnt int
var a [][]byte
var comp [][]int

func inside(r int, c int) bool {
	if (r < 0) || (r > n+1) {
		return false
	}
	if (c < 0) || (c > m+1) {
		return false
	}
	return true
}

func dfs(r int, c int) {
	for i := 0; i < 4; i++ {
		rx := r + dr[i]
		cx := c + dc[i]
		if inside(rx, cx) {
			if (comp[rx][cx] == -2) && (a[rx][cx] == '.') {
				comp[rx][cx] = nc
				cnt++
				dfs(rx, cx)
			}
		}
	}
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	fmt.Fscanf(bufin, "%d %d %d\n", &n, &m, &k)

	a = make([][]byte, n+2)
	comp = make([][]int, n+2)
	for i := 0; i <= n+1; i++ {
		a[i] = make([]byte, m+2)
		comp[i] = make([]int, m+2)
		for j := 0; j <= m+1; j++ {
			a[i][j] = '.'
			comp[i][j] = -2
		}
	}

	var s string
	for i := 1; i <= n; i++ {
		fmt.Fscanf(bufin, "%s\n", &s)
		for j := 1; j <= m; j++ {
			a[i][j] = s[j-1]
		}
	}

	nc = -1
	comp[0][0] = nc
	dfs(0, 0)

	var cntComp PairSlice
	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if (comp[i][j] == -2) && (a[i][j] == '.') {
				// fmt.Fprintf(bufout, "> %d %d\n", i, j)
				nc++
				cnt = 1
				comp[i][j] = nc
				dfs(i, j)
				cntComp = append(cntComp, Pair{c: nc, cnt: cnt})
			}
		}
	}

	sort.Sort(cntComp)
	// for i := 0; i < len(cntComp); i++ {
	// 	fmt.Fprintf(bufout, "%d %d\n", cntComp[i].c, cntComp[i].cnt)
	// }

	res := 0
	for i := k; i <= nc; i++ {
		res += cntComp[i].cnt
	}

	for x := k; x <= nc; x++ {
		c := cntComp[x].c
		for i := 1; i <= n; i++ {
			for j := 1; j <= m; j++ {
				if comp[i][j] == c {
					a[i][j] = '*'
				}
			}
		}
	}

	fmt.Fprintf(bufout, "%d\n", res)
	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			fmt.Fprintf(bufout, "%c", a[i][j])
		}
		fmt.Fprintf(bufout, "\n")
	}

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	// "strings"
)

var (
	writer  = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
)

type ByLength [][][]int

func (a ByLength) Len() int           { return len(a) }
func (a ByLength) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByLength) Less(i, j int) bool { return len(a[i]) < len(a[j]) }

func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	n, _, k := nextInt(), nextInt(), nextInt()
	area := make([][]byte, n)
	used := make([][]byte, n)
	var lakes [][][]int
	ret := 0

	for i := range area {
		area[i] = []byte(next())
		used[i] = make([]byte, len(area[i]))
		copy(used[i], area[i])
	}

	for i := range used {
		for j := range used[i] {
			if used[i][j] == '*' {
				continue
			}

			points := dfs(used, i, j)

			if points != nil {
				lakes = append(lakes, points)
				// printArea(used)
			}
		}
	}
	// printArea(area)
	// println()
	// printArea(used)
	sort.Sort(ByLength(lakes))
	// println(lakes)
	for i := 0; i < len(lakes)-k; i++ {
		ret += len(lakes[i])

		for _, point := range lakes[i] {
			area[point[0]][point[1]] = '*'
		}
	}

	println(ret)
	printArea(area)
}

func dfs(area [][]byte, i int, j int) [][]int {
	// println(i, j)
	area[i][j] = '*'
	points := [][]int{{i, j}}
	preI, preJ := i, j

	for _, move := range [][]int{{0, 1}, {1, 0}, {0, -1}, {-1, 0}} {
		i = preI + move[0]
		j = preJ + move[1]

		if i < 0 || i >= len(area) || j < 0 || j >= len(area[0]) {
			points = nil
			continue
		}

		if area[i][j] == '*' {
			continue
		}

		newPoints := dfs(area, i, j)

		if newPoints == nil {
			points = nil
		}

		if points != nil {
			points = append(points, newPoints...)
		}
	}

	return points
}

func printArea(c [][]byte) {
	for i := range c {
		println(string(c[i]))
	}
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type cell struct {
	y int
	x int
}

var (
	matrix  []string
	lakes   [][]cell
	n, m, k int
	dx      = []int{-1, 0, 1, 0}
	dy      = []int{0, -1, 0, 1}
	visited = [][]bool{}
)

func dfs(i int, j int) {
	isOcean := false
	temp := []cell{}
	stack := []cell{cell{i, j}}
	visited[i][j] = true

	for len(stack) > 0 {
		cur := pop(&stack)
		if onBorder(cur.y, cur.x) {
			isOcean = true
		}
		for d := 0; d < 4; d++ {
			newX := cur.x + dx[d]
			newY := cur.y + dy[d]
			if isValid(newX, newY) && matrix[newY][newX] == '.' && !visited[newY][newX] {
				visited[newY][newX] = true
				stack = append(stack, cell{newY, newX})
				if !isOcean {
					temp = append(temp, cell{newY, newX})
				}
			}
		}
	}
	if !isOcean {
		temp = append(temp, cell{i, j})
		lakes = append(lakes, temp)
	}
}

func pop(s *[]cell) cell {
	n := (*s)[len(*s)-1]
	(*s) = (*s)[:len(*s)-1]
	return n
}

func onBorder(y int, x int) bool {
	return y == 0 || x == 0 || y == n-1 || x == m-1
}

func isValid(x int, y int) bool {
	return 0 <= x && x < m && 0 <= y && y < n
}

func main() {
	r := bufio.NewReader(os.Stdin)
	fmt.Fscanf(r, "%d %d %d\n", &n, &m, &k)
	visited = make([][]bool, n)
	for i := range visited {
		visited[i] = make([]bool, m)
	}

	matrix = make([]string, n)
	for i := range matrix {
		fmt.Fscanf(r, "%s\n", &matrix[i])
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if !visited[i][j] && matrix[i][j] == '.' {
				dfs(i, j)
			}
		}
	}

	sort.Slice(lakes, func(i, j int) bool { return len(lakes[i]) < len(lakes[j]) })
	cells := 0
	num := len(lakes) - k
	for i := 0; i < num; i++ {
		cells += len(lakes[i])
		for j := range lakes[i] {
			c := lakes[i][j]
			arr := []byte(matrix[c.y])
			arr[c.x] = '*'
			matrix[c.y] = string(arr)
		}
	}

	fmt.Println(cells)
	for i := range matrix {
		fmt.Println(matrix[i])
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"sort"
	"strings"
)

const MA_MN = 50

var MAP [][]byte
var m, n, k int

type Lake struct {
	i, j, size int
}

type LakeSorter []Lake

func (a LakeSorter) Len() int           { return len(a) }
func (a LakeSorter) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a LakeSorter) Less(i, j int) bool { return a[i].size < a[j].size }

func main() {
	reader := NewStdReader(os.Stdin)
	n, m, k = reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	MAP = make([][]byte, n)

	for i := 0; i < n; i++ {
		s := reader.ReadText()
		s = strings.Replace(s, ".", "w", -1)
		MAP[i] = []byte(s)
	}

	for i := 0; i < n; i++ {
		if MAP[i][0] == 'w' {
			fillMap(i, 0, 'w', '.')
		}
		if MAP[i][m-1] == 'w' {
			fillMap(i, m-1, 'w', '.')
		}
	}
	for j := 1; j < m-1; j++ {
		if MAP[0][j] == 'w' {
			fillMap(0, j, 'w', '.')
		}
		if MAP[n-1][j] == 'w' {
			fillMap(n-1, j, 'w', '.')
		}
	}

	listLake := LakeSorter{}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if MAP[i][j] == 'w' {
				size := fillMap(i, j, 'w', '.')
				listLake = append(listLake, Lake{i, j, size})
			}
		}
	}

	sort.Sort(listLake)

	count := 0
	for i := 0; i < len(listLake)-k; i++ {
		lake := listLake[i]
		count += lake.size
		fillMap(lake.i, lake.j, '.', '*')
	}

	fmt.Println(count)
	for i := 0; i < n; i++ {
		fmt.Println(string(MAP[i]))
	}

}

func fillMap(i, j int, from byte, to byte) int {
	MAP[i][j] = to
	count := 1
	if i > 0 && MAP[i-1][j] == from {
		count += fillMap(i-1, j, from, to)
	}
	if j > 0 && MAP[i][j-1] == from {
		count += fillMap(i, j-1, from, to)
	}
	if i < n-1 && MAP[i+1][j] == from {
		count += fillMap(i+1, j, from, to)
	}
	if j < m-1 && MAP[i][j+1] == from {
		count += fillMap(i, j+1, from, to)
	}
	return count
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadText() string {

	buf := bytes.NewBuffer(nil)

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b == ' ' || b == '\t' || b == '\r' || b == '\n' {
			if buf.Len() > 0 {
				break
			}
		} else {
			buf.WriteByte(b)
		}
	}

	return buf.String()
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"strings"
	"sort"
)

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

func main() {
	sc := NewScanner()
	n := sc.NextInt()
	m := sc.NextInt()
	k := sc.NextInt()
	in := make([]string, n)
	field := make([][]int, n)
	for i := 0; i < n; i++ {
		in[i] = sc.NextLine()
		field[i] = make([]int, m)
		for j := 0; j < m; j++ {
			if in[i][j] == '*' {
				field[i][j] = -1
			}
		}
	}
	bfs := func(sy, sx, lake int) int {
		x := make([]int, 1)
		y := make([]int, 1)
		x[0] = sx
		y[0] = sy
		field[sy][sx] = lake
		vec := []int{0, -1, 0, 1, 0 }
		isSea := false
		for i := 0; i < len(x); i++ {
			for v := 0; v < 4; v++ {

				if !checkRange(x[i] + vec[v], 0, m) {
					isSea = true
					continue
				}
				if !checkRange(y[i] + vec[v + 1], 0, n) {
					isSea = true
					continue
				}
				if field[y[i] + vec[v + 1]][x[i] + vec[v]] != 0 {
					continue
				}
				x = append(x, x[i] + vec[v])
				y = append(y, y[i] + vec[v + 1])
				field[y[i] + vec[v + 1]][x[i] + vec[v]] = lake
			}
		}
		if isSea {
			return -1
		}
		return len(x)
	}

	lake := 0

	lakes := make(SortInterFace, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if field[i][j] == 0 {
				lake++
				result := bfs(i, j, lake)
				if result > 0 {
					lakes = append(lakes, Tup{result, lake})
				}
			}
		}
	}
	sort.Sort(lakes)

	changed := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			for v := 0; v < len(lakes) - k; v++ {
				if field[i][j] == lakes[v].B {
					field[i][j] = -1
					changed++
				}
			}
		}
	}
	fmt.Println(changed)
	for i := 0; i < n; i++ {
		out := ""
		for j := 0; j < m; j++ {
			if field[i][j] == -1 {
				out += "*"
			} else {
				out += "."
			}
		}
		fmt.Println(out)
	}
}

/**
 * [mn,mx) のチェックをします
 */
func checkRange(v, mn, mx int) bool {
	return mn <= v && v < mx
}

type Tup struct {
	A int
	B int
}

type SortInterFace []Tup

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].A < s[j].A
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func waterToLand(parent []int) {
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
	}
}

func dfs(i, j, c int) int {
	if j < 0 || i < 0 || j >= m || i >= n || visit[i][j] {
		return 0
	}
	visit[i][j] = true
	if a[i][j] != '.' {
		return 0
	}
	if i == 0 || i == n-1 || j == 0 || j == m-1 || ((i+1 == n-1 || i+1 == 0) && a[i+1][j] == '.') || ((j+1 == m-1 || j+1 == 0) && a[i][j+1] == '.') || ((i-1 == 0 || i-1 == n-1) && a[i-1][j] == '.') || ((j-1 == 0 || j-1 == m-1) && a[i][j-1] == '.') {
		return -10000000
	}
	c += dfs(i-1, j, c)
	c += dfs(i, j-1, c)
	c += dfs(i+1, j, c)
	c += dfs(i, j+1, c)
	c++
	return c
}

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k int

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			value := dfs(i, j, 0)
			if value > 0 {
				node = insert(node, value, []int{i, j})
				nodeCount++
			}
		}
	}
	ans := 0
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			ans += z.Value
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
	}
}

func dfs(i, j, c int) int {
	if j < 0 || i < 0 || j >= m || i >= n || visit[i][j] || a[i][j] != '.' {
		return 0
	}
	visit[i][j] = true
	if i == 0 || i == n-1 || j == 0 || j == m-1 || (i+1 == n-1 && a[i+1][j] == '.') || (j+1 == m-1 && a[i][j+1] == '.') || (i-1 == 0 && a[i-1][j] == '.') || (j-1 == 0 && a[i][j-1] == '.') {
		return -100000000
	}
	c++
	c += dfs(i-1, j, c)
	c += dfs(i+1, j, c)
	c += dfs(i, j-1, c)
	c += dfs(i, j+1, c)
	return c
}

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			value := dfs(i, j, 0)
			if value > 0 {
				node = insert(node, value, []int{i, j})
				nodeCount++
			}
		}
	}
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func dfs(i, j, c int) int {
	if i > n-1 || j > m-1 || visit[i][j] {
		return 0
	}
	count := c
	visit[i][j] = true
	if a[i][j] == '*' {
		count = 0
	} else if i > 0 && i < n-1 && j > 0 && j < m-1 {
		if a[i][j] == '.' {
			count++
		}
	}

	o := dfs(i+1, j, count)
	if o > count {
		count = o
	}
	if o == -1 {
		return 0
	}
	o = dfs(i, j+1, count)
	if o > count {
		count = o
	}
	if o == -1 {
		return 0
	}
	if (i+1 == n-1 && a[i+1][j] == '.') || (j+1 == m-1 && a[i][j+1] == '.') || (i-1 == 0 && a[i-1][j] == '.') || (j-1 == 0 && a[i][j-1] == '.') {
		return -1
	}
	if a[i][j] != '*' && c == 0 && count > 0 {
		node = insert(node, count, []int{i, j})
		nodeCount++
		return 0
	}
	if a[i][j] != '*' {
		return count
	}
	return 0
}

func waterToLand(parent []int) {
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m-1 && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n-1 && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
	}
}

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k int

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	ans := 0
	dfs(0, 0, 0)
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			ans += z.Value
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func waterToLand(parent []int) {
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
	}
}

func dfs(i, j, c int) int {
	if j < 0 || i < 0 || j >= m || i >= n || visit[i][j] {
		return 0
	}
	visit[i][j] = true
	if a[i][j] != '.' {
		return 0
	}
	if i == 0 || i == n-1 || j == 0 || j == m-1 || (i+1 == n-1 && a[i+1][j] == '.') || (j+1 == m-1 && a[i][j+1] == '.') || (i-1 == 0 && a[i-1][j] == '.') || (j-1 == 0 && a[i][j-1] == '.') {
		return -10000
	}
	c += dfs(i-1, j, c)
	c += dfs(i, j-1, c)
	c += dfs(i+1, j, c)
	c += dfs(i, j+1, c)
	c++
	return c
}

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k int

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			value := dfs(i, j, 0)
			if value > 0 {
				node = insert(node, value, []int{i, j})
				nodeCount++
			}
		}
	}
	ans := 0
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			ans += z.Value
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m-1 && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n-1 && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
		parent[0]--
	}
	if parent[1]-1 > 0 && a[parent[0]][parent[1]-1] == '.' {
		parent[1]--
		waterToLand(parent)
		parent[1]++
	}
	if parent[0]-1 > 0 && a[parent[0]-1][parent[1]] == '.' {
		parent[0]--
		waterToLand(parent)
		parent[0]++
	}
}

type Node struct {
	Count  int
	Parent []int
}

type pos [2]int
type stack []pos

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int
var res []Node

type ByCount []Node

func (s stack) Push(v pos) stack {
	return append(s, v)
}

func (s stack) Pop() (stack, pos) {
	l := len(s)
	return s[:l-1], s[l-1]
}

func (slice ByCount) Len() int {
	return len(slice)
}

func (slice ByCount) Less(i, j int) bool {
	return slice[i].Count < slice[j].Count
}

func (slice ByCount) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			if a[i][j] == '.' {
				s := make(stack, 0)
				count := 0
				o := pos{i, j}
				s = s.Push(o)
				for len(s) > 0 {
					s, o = s.Pop()
					if !visit[o[0]][o[1]] && a[o[0]][o[1]] == '.' {
						visit[o[0]][o[1]] = true
						if o[0] == 0 || o[0] == n-1 || o[1] == 0 || o[1] == m-1 || ((o[0]+1 == n-1 || o[0]+1 == 0) && a[o[0]+1][o[1]] == '.') || ((o[1]+1 == m-1 || o[1]+1 == 0) && a[o[0]][o[1]+1] == '.') || ((o[0]-1 == 0 || o[0]-1 == n-1) && a[o[0]-1][o[1]] == '.') || ((o[1]-1 == 0 || o[1]-1 == m-1) && a[o[0]][o[1]-1] == '.') {
							s = make(stack, 0)
							count = 0
							continue
						}
						count++
						if o[0]+1 >= 0 && o[0]+1 < n {
							s = s.Push(pos{o[0] + 1, o[1]})
						}
						if o[0]-1 >= 0 && o[0]-1 < n {
							s = s.Push(pos{o[0] - 1, o[1]})
						}
						if o[1]+1 < m && o[1]+1 >= 0 {
							s = s.Push(pos{o[0], o[1] + 1})
						}
						if o[1]-1 >= 0 && o[1]-1 < m {
							s = s.Push(pos{o[0], o[1] - 1})
						}
					}
				}
				if count > 0 {
					res = append(res, Node{count, []int{i, j}})
					nodeCount++
				}
			}
		}
	}
	sort.Sort(ByCount(res))
	for nodeCount > k {
		nodeCount--
		waterToLand(res[0].Parent)
		res = res[1:]
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func dfs(i, j, c int) int {
	if i > n-1 || j > m-1 || visit[i][j] {
		return 0
	}
	count := c
	visit[i][j] = true
	if a[i][j] == '*' {
		count = 0
	} else if i > 0 && i < n-1 && j > 0 && j < m-1 {
		if a[i][j] == '.' {
			count++
		}
	}

	o := dfs(i+1, j, count)
	if o > count {
		count = o
	}
	o = dfs(i, j+1, count)
	if o > count {
		count = o
	}
	if (i+1 == n-1 && a[i+1][j] == '.') || (j+1 == m-1 && a[i][j+1] == '.') || (i-1 == 0 && a[i-1][j] == '.') || (j-1 == 0 && a[i][j-1] == '.') {
		return 0
	}
	if a[i][j] != '*' && c == 0 && count > 0 {
		node = insert(node, count, []int{i, j})
		nodeCount++
		return 0
	}
	if a[i][j] != '*' {
		return count
	}
	return 0
}

func waterToLand(parent []int) {
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m-1 && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n-1 && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
	}
}

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k int

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	ans := 0
	dfs(0, 0, 0)
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			ans += z.Value
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
	}
}

func dfs(i, j, c int) int {
	if j < 0 || i < 0 || j >= m || i >= n || visit[i][j] || a[i][j] != '.' {
		return 0
	}
	visit[i][j] = true
	if i == 0 || i == n-1 || j == 0 || j == m-1 || (i+1 == n-1 && a[i+1][j] == '.') || (j+1 == m-1 && a[i][j+1] == '.') || (i-1 == 0 && a[i-1][j] == '.') || (j-1 == 0 && a[i][j-1] == '.') {
		return -100000000
	}
	c += dfs(i-1, j, c)
	c += dfs(i+1, j, c)
	c += dfs(i, j-1, c)
	c += dfs(i, j+1, c)
	c++
	return c
}

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			value := dfs(i, j, 0)
			if value > 0 {
				node = insert(node, value, []int{i, j})
				nodeCount++
			}
		}
	}
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
		parent[0]--
	}
	if parent[1]-1 >= 0 && a[parent[0]][parent[1]-1] == '.' {
		parent[1]--
		waterToLand(parent)
		parent[1]++
	}
	if parent[0]-1 >= 0 && a[parent[0]-1][parent[1]] == '.' {
		parent[0]--
		waterToLand(parent)
		parent[0]++
	}
}

func dfs(i, j, c int) int {
	if j < 0 || i < 0 || j >= m || i >= n || visit[i][j] || a[i][j] != '.' {
		return 0
	}
	visit[i][j] = true
	if i == 0 || i == n-1 || j == 0 || j == m-1 || (i+1 == n-1 && a[i+1][j] == '.') || (j+1 == m-1 && a[i][j+1] == '.') || (i-1 == 0 && a[i-1][j] == '.') || (j-1 == 0 && a[i][j-1] == '.') {
		return -100000000
	}
	c++
	c += dfs(i-1, j, c)
	c += dfs(i+1, j, c)
	c += dfs(i, j-1, c)
	c += dfs(i, j+1, c)
	return c
}

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			value := dfs(i, j, 0)
			if value > 0 {
				node = insert(node, value, []int{i, j})
				nodeCount++
			}
		}
	}
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left   *Node
	Value  int
	Right  *Node
	Parent []int
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func insert(node *Node, value int, parent []int) *Node {
	if node == nil {
		return &Node{nil, value, nil, parent}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, parent)
		return node
	}
	node.Right = insert(node.Right, value, parent)
	return node
}

func walk(node *Node, channel chan *Node) {
	if node == nil {
		return
	}
	walk(node.Left, channel)
	channel <- node
	walk(node.Right, channel)
}

func walker(node *Node) chan *Node {
	channel := make(chan *Node)
	go func() {
		walk(node, channel)
		close(channel)
	}()
	return channel
}

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m-1 && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n-1 && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
		parent[0]--
	}
	if parent[1]-1 > 0 && a[parent[0]][parent[1]-1] == '.' {
		parent[1]--
		waterToLand(parent)
		parent[1]++
	}
	if parent[0]-1 > 0 && a[parent[0]-1][parent[1]] == '.' {
		parent[0]--
		waterToLand(parent)
		parent[0]++
	}
}

type pos [2]int
type stack []pos

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int

func (s stack) Push(v pos) stack {
	return append(s, v)
}

func (s stack) Pop() (stack, pos) {
	l := len(s)
	return s[:l-1], s[l-1]
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			if a[i][j] == '.' {
				s := make(stack, 0)
				count := 0
				o := pos{i, j}
				s = s.Push(o)
				for len(s) > 0 {
					s, o = s.Pop()
					if !visit[o[0]][o[1]] && a[o[0]][o[1]] == '.' {
						visit[o[0]][o[1]] = true
						if o[0] == 0 || o[0] == n-1 || o[1] == 0 || o[1] == m-1 || (o[0]+1 == n-1 && a[o[0]+1][o[1]] == '.') || (o[1]+1 == m-1 && a[o[0]][o[1]+1] == '.') || (o[0]-1 == 0 && a[o[0]-1][o[1]] == '.') || (o[1]-1 == 0 && a[o[0]][o[1]-1] == '.') {
							s = make(stack, 0)
							count = 0
							continue
						}
						count++
						if o[0]+1 < n {
							s = s.Push(pos{o[0] + 1, o[1]})
						}
						if o[0]-1 > 0 {
							s = s.Push(pos{o[0] - 1, o[1]})
						}
						if o[1]+1 < m {
							s = s.Push(pos{o[0], o[1] + 1})
						}
						if o[1]-1 > 0 {
							s = s.Push(pos{o[0], o[1] - 1})
						}
					}
				}
				if count > 0 {
					node = insert(node, count, []int{i, j})
					nodeCount++
				}
			}
		}
	}
	channel := walker(node)
	for z := range channel {
		if nodeCount > k {
			waterToLand(z.Parent)
			nodeCount--
		} else {
			break
		}
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m-1 && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n-1 && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
		parent[0]--
	}
	if parent[1]-1 > 0 && a[parent[0]][parent[1]-1] == '.' {
		parent[1]--
		waterToLand(parent)
		parent[1]++
	}
	if parent[0]-1 > 0 && a[parent[0]-1][parent[1]] == '.' {
		parent[0]--
		waterToLand(parent)
		parent[0]++
	}
}

type Node struct {
	Count  int
	Parent []int
}

type pos [2]int
type stack []pos

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int
var res []Node

type ByCount []Node

func (s stack) Push(v pos) stack {
	return append(s, v)
}

func (s stack) Pop() (stack, pos) {
	l := len(s)
	return s[:l-1], s[l-1]
}

func (slice ByCount) Len() int {
	return len(slice)
}

func (slice ByCount) Less(i, j int) bool {
	return slice[i].Count < slice[j].Count
}

func (slice ByCount) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			if a[i][j] == '.' {
				s := make(stack, 0)
				count := 0
				o := pos{i, j}
				s = s.Push(o)
				for len(s) > 0 {
					s, o = s.Pop()
					if !visit[o[0]][o[1]] && a[o[0]][o[1]] == '.' {
						visit[o[0]][o[1]] = true
						if o[0] == 0 || o[0] == n-1 || o[1] == 0 || o[1] == m-1 || (o[0]+1 == n-1 && a[o[0]+1][o[1]] == '.') || (o[1]+1 == m-1 && a[o[0]][o[1]+1] == '.') || (o[0]-1 == 0 && a[o[0]-1][o[1]] == '.') || (o[1]-1 == 0 && a[o[0]][o[1]-1] == '.') {
							s = make(stack, 0)
							count = 0
							continue
						}
						count++
						if o[0]+1 < n {
							s = s.Push(pos{o[0] + 1, o[1]})
						}
						if o[0]-1 > 0 {
							s = s.Push(pos{o[0] - 1, o[1]})
						}
						if o[1]+1 < m {
							s = s.Push(pos{o[0], o[1] + 1})
						}
						if o[1]-1 > 0 {
							s = s.Push(pos{o[0], o[1] - 1})
						}
					}
				}
				if count > 0 {
					res = append(res, Node{count, []int{i, j}})
					nodeCount++
				}
			}
		}
	}
	sort.Sort(ByCount(res))
	for nodeCount > k {
		nodeCount--
		waterToLand(res[0].Parent)
		res = res[1:]
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strings"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

func waterToLand(parent []int) {
	ans++
	temp := []rune(a[parent[0]])
	temp[parent[1]] = '*'
	a[parent[0]] = string(temp)
	if parent[1]+1 < m-1 && a[parent[0]][parent[1]+1] == '.' {
		parent[1]++
		waterToLand(parent)
		parent[1]--
	}
	if parent[0]+1 < n-1 && a[parent[0]+1][parent[1]] == '.' {
		parent[0]++
		waterToLand(parent)
		parent[0]--
	}
	if parent[1]-1 > 0 && a[parent[0]][parent[1]-1] == '.' {
		parent[1]--
		waterToLand(parent)
		parent[1]++
	}
	if parent[0]-1 > 0 && a[parent[0]-1][parent[1]] == '.' {
		parent[0]--
		waterToLand(parent)
		parent[0]++
	}
}

type Node struct {
	Count  int
	Parent []int
}

type pos [2]int
type stack []pos

var a []string
var visit [][50]bool
var node *Node
var nodeCount int
var n, m, k, ans int
var res []Node

type ByCount []Node

func (s stack) Push(v pos) stack {
	return append(s, v)
}

func (s stack) Pop() (stack, pos) {
	l := len(s)
	return s[:l-1], s[l-1]
}

func (slice ByCount) Len() int {
	return len(slice)
}

func (slice ByCount) Less(i, j int) bool {
	return slice[i].Count < slice[j].Count
}

func (slice ByCount) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	I(&n, " ")
	I(&m, " ")
	I(&k, "\n")
	a = make([]string, n)
	visit = make([][50]bool, n)
	for i := range a {
		I(&a[i], "\n")
	}
	for i := range a {
		for j := 0; j < m; j++ {
			if a[i][j] == '.' {
				s := make(stack, 0)
				count := 0
				o := pos{i, j}
				s = s.Push(o)
				for len(s) > 0 {
					s, o = s.Pop()
					if !visit[o[0]][o[1]] && a[o[0]][o[1]] == '.' {
						visit[o[0]][o[1]] = true
						if o[0] == 0 || o[0] == n-1 || o[1] == 0 || o[1] == m-1 || ((o[0]+1 == n-1 || o[0]+1 == 0) && a[o[0]+1][o[1]] == '.') || ((o[1]+1 == m-1 || o[1]+1 == 0) && a[o[0]][o[1]+1] == '.') || ((o[0]-1 == 0 || o[0]-1 == n-1) && a[o[0]-1][o[1]] == '.') || ((o[1]-1 == 0 || o[1]-1 == m-1) && a[o[0]][o[1]-1] == '.') {
							s = make(stack, 0)
							count = 0
							break
						}
						count++
						if o[0]+1 >= 0 && o[0]+1 < n {
							s = s.Push(pos{o[0] + 1, o[1]})
						}
						if o[0]-1 >= 0 && o[0]-1 < n {
							s = s.Push(pos{o[0] - 1, o[1]})
						}
						if o[1]+1 < m && o[1]+1 >= 0 {
							s = s.Push(pos{o[0], o[1] + 1})
						}
						if o[1]-1 >= 0 && o[1]-1 < m {
							s = s.Push(pos{o[0], o[1] - 1})
						}
					}
				}
				if count > 0 {
					res = append(res, Node{count, []int{i, j}})
					nodeCount++
				}
			}
		}
	}
	sort.Sort(ByCount(res))
	for nodeCount > k {
		nodeCount--
		waterToLand(res[0].Parent)
		res = res[1:]
	}
	O(ans, "\n")
	O(strings.Join(a, "\n"), "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type cell struct {
	y int
	x int
}

var (
	matrix  []string
	lakes   [][]cell
	n, m, k int
	dx      = []int{-1, 0, 1, 0}
	dy      = []int{0, -1, 0, 1}
	visited = [][]bool{}
)

func dfs(i int, j int) {
	stack := []cell{cell{i, j}}
	visited[i][j] = true
	lakes = append(lakes, []cell{cell{i, j}})
	for len(stack) > 0 {
		cur := pop(&stack)
		for d := 0; d < 4; d++ {
			newX := cur.x + dx[d]
			newY := cur.y + dy[d]
			if isValid(newX, newY) && matrix[newY][newX] == '.' && !visited[newY][newX] {
				visited[newY][newX] = true
				stack = append(stack, cell{newY, newX})
				lakes[len(lakes)-1] = append(lakes[len(lakes)-1], cell{newY, newX})
			}
		}
	}
}

func pop(s *[]cell) cell {
	n := (*s)[len(*s)-1]
	(*s) = (*s)[:len(*s)-1]
	return n
}

func isOcean(y int, x int) bool {
	return y == 0 || x == 0 || y == n-1 || x == m-1
}

func isValid(x int, y int) bool {
	return 0 < x && x < m-1 && 0 < y && y < n-1
}

func main() {
	r := bufio.NewReader(os.Stdin)
	fmt.Fscanf(r, "%d %d %d\n", &n, &m, &k)
	visited = make([][]bool, n)
	for i := range visited {
		visited[i] = make([]bool, m)
	}

	matrix = make([]string, n)
	for i := range matrix {
		fmt.Fscanf(r, "%s\n", &matrix[i])
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if !visited[i][j] && matrix[i][j] == '.' && !isOcean(i, j) {
				dfs(i, j)
			}
		}
	}

	sort.Slice(lakes, func(i, j int) bool { return len(lakes[i]) < len(lakes[j]) })
	transformCell := 0
	num := len(lakes) - k
	for i := 0; i < num; i++ {
		transformCell += len(lakes[i])
		for j := range lakes[i] {
			c := lakes[i][j]
			arr := []byte(matrix[c.y])
			arr[c.x] = '*'
			matrix[c.y] = string(arr)
		}
	}

	fmt.Println(transformCell)
	for i := range matrix {
		fmt.Println(matrix[i])
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type cell struct {
	y int
	x int
}

var (
	matrix []string
	lakes  [][]cell
	n, m   int
)

func solve(n int, m int, k int) {
	dx := []int{-1, 0, 1, 0}
	dy := []int{0, -1, 0, 1}
	visited := make([][]bool, n)
	stack := []cell{}
	for i := range visited {
		visited[i] = make([]bool, m)
	}

	for i := range matrix {
		for j := range matrix[i] {
			if matrix[i][j] == '.' && !isOcean(i, j) && !visited[i][j] {
				visited[i][j] = true
				stack = append(stack, cell{i, j})
				lakes = append(lakes, []cell{cell{i, j}})
				for len(stack) > 0 {
					cur := pop(&stack)
					for d := 0; d < 4; d++ {
						newX := cur.x + dx[d]
						newY := cur.y + dy[d]
						if 0 < newX && newX < m-1 && 0 < newY && newY < n-1 && matrix[newY][newX] == '.' && !visited[newY][newX] {
							visited[newY][newX] = true
							stack = append(stack, cell{newY, newX})
							lakes[len(lakes)-1] = append(lakes[len(lakes)-1], cell{newY, newX})
						}
					}
				}
			}
		}
	}

	sort.Slice(lakes, func(i, j int) bool { return len(lakes[i]) < len(lakes[j]) })
	transformCell := 0
	num := len(lakes) - k
	for i := 0; i < num; i++ {
		transformCell += len(lakes[i])
		for j := range lakes[i] {
			c := lakes[i][j]
			arr := []byte(matrix[c.y])
			arr[c.x] = '*'
			matrix[c.y] = string(arr)
		}
	}

	fmt.Println(transformCell)
	for i := range matrix {
		fmt.Println(matrix[i])
	}

}

func pop(s *[]cell) cell {
	n := (*s)[len(*s)-1]
	(*s) = (*s)[:len(*s)-1]
	return n
}

func isOcean(y int, x int) bool {
	if y == 0 || x == 0 || y == n-1 || x == m-1 {
		return true
	}
	return false
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var k int
	fmt.Fscanf(r, "%d %d %d\n", &n, &m, &k)
	matrix = make([]string, n)
	for i := range matrix {
		fmt.Fscanf(r, "%s\n", &matrix[i])
	}
	solve(n, m, k)
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

type cell struct {
	y int
	x int
}

var (
	matrix  []string
	lakes   [][]cell
	n, m, k int
	dx      = []int{-1, 0, 1, 0}
	dy      = []int{0, -1, 0, 1}
	visited = [][]bool{}
)

func dfs(i int, j int) {
	isOcean := false

	stack := []cell{cell{i, j}}
	visited[i][j] = true
	for len(stack) > 0 {
		cur := pop(&stack)
		if onBorder(cur.y, cur.x) || isOcean {
			isOcean = true
		} else {
			lakes = append(lakes, []cell{cell{cur.y, cur.x}})
		}
		for d := 0; d < 4; d++ {
			newX := cur.x + dx[d]
			newY := cur.y + dy[d]
			if isValid(newX, newY) && matrix[newY][newX] == '.' && !visited[newY][newX] {
				visited[newY][newX] = true
				stack = append(stack, cell{newY, newX})
				if !isOcean {
					lakes[len(lakes)-1] = append(lakes[len(lakes)-1], cell{newY, newX})
				}
			}
		}
	}
}

func pop(s *[]cell) cell {
	n := (*s)[len(*s)-1]
	(*s) = (*s)[:len(*s)-1]
	return n
}

func onBorder(y int, x int) bool {
	return y == 0 || x == 0 || y == n-1 || x == m-1
}

func isValid(x int, y int) bool {
	return 0 <= x && x < m && 0 <= y && y < n
}

func main() {
	r := bufio.NewReader(os.Stdin)
	fmt.Fscanf(r, "%d %d %d\n", &n, &m, &k)
	visited = make([][]bool, n)
	for i := range visited {
		visited[i] = make([]bool, m)
	}

	matrix = make([]string, n)
	for i := range matrix {
		fmt.Fscanf(r, "%s\n", &matrix[i])
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if !visited[i][j] && matrix[i][j] == '.' {
				dfs(i, j)
			}
		}
	}

	sort.Slice(lakes, func(i, j int) bool { return len(lakes[i]) < len(lakes[j]) })
	//fmt.Println(lakes)
	transformCell := 0
	num := len(lakes) - k
	for i := 0; i < num; i++ {
		transformCell += len(lakes[i])
		for j := range lakes[i] {
			c := lakes[i][j]
			arr := []byte(matrix[c.y])
			arr[c.x] = '*'
			matrix[c.y] = string(arr)
		}
	}

	fmt.Println(transformCell)
	for i := range matrix {
		fmt.Println(matrix[i])
	}
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strings"
)

const MA_MN = 50

var MAP [][]byte
var m, n, k int

func main() {
	reader := NewStdReader(os.Stdin)
	n, m, k = reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	MAP = make([][]byte, n)

	for i := 0; i < n; i++ {
		s := reader.ReadText()
		s = strings.Replace(s, ".", "w", -1)
		MAP[i] = []byte(s)
	}

	for i := 0; i < n; i++ {
		if MAP[i][0] == 'w' {
			fillMap(i, 0, '.')
		}
		if MAP[i][m-1] == 'w' {
			fillMap(i, 0, '.')
		}
	}
	for j := 1; j < m-1; j++ {
		if MAP[0][j] == 'w' {
			fillMap(0, j, '.')
		}
		if MAP[n-1][j] == 'w' {
			fillMap(n-1, j, '.')
		}
	}

	countLake := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if MAP[i][j] == 'w' {
				countLake++
				if countLake <= k {
					fillMap(i, j, '.')
				} else {
					fillMap(i, j, '*')
				}
			}
		}
	}

	fmt.Println(countLake - k)
	for i := 0; i < n; i++ {
		fmt.Println(string(MAP[i]))
	}

}

func fillMap(i, j int, mark byte) {
	MAP[i][j] = mark
	if i > 0 && MAP[i-1][j] == 'w' {
		fillMap(i-1, j, mark)
	}
	if j > 0 && MAP[i][j-1] == 'w' {
		fillMap(i, j-1, mark)
	}
	if i < n-1 && MAP[i+1][j] == 'w' {
		fillMap(i+1, j, mark)
	}
	if j < m-1 && MAP[i][j+1] == 'w' {
		fillMap(i, j+1, mark)
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadText() string {

	buf := bytes.NewBuffer(nil)

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b == ' ' || b == '\t' || b == '\r' || b == '\n' {
			if buf.Len() > 0 {
				break
			}
		} else {
			buf.WriteByte(b)
		}
	}

	return buf.String()
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strings"
)

const MA_MN = 50

var MAP [][]byte
var m, n, k int

func main() {
	reader := NewStdReader(os.Stdin)
	n, m, k = reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	MAP = make([][]byte, n)

	for i := 0; i < n; i++ {
		s := reader.ReadText()
		s = strings.Replace(s, ".", "w", -1)
		MAP[i] = []byte(s)
	}

	for i := 0; i < n; i++ {
		if MAP[i][0] == 'w' {
			fillMap(i, 0, '.')
		}
		if MAP[i][m-1] == 'w' {
			fillMap(i, m-1, '.')
		}
	}
	for j := 1; j < m-1; j++ {
		if MAP[0][j] == 'w' {
			fillMap(0, j, '.')
		}
		if MAP[n-1][j] == 'w' {
			fillMap(n-1, j, '.')
		}
	}

	countLake := 0

	for j := 0; j < m; j++ {
		for i := 0; i < n; i++ {
			if MAP[i][j] == 'w' {
				countLake++
				if countLake <= k {
					fillMap(i, j, '.')
				} else {
					fillMap(i, j, '*')
				}
			}
		}
	}

	fmt.Println(countLake - k)
	for i := 0; i < n; i++ {
		fmt.Println(string(MAP[i]))
	}

}

func fillMap(i, j int, mark byte) {
	MAP[i][j] = mark
	if i > 0 && MAP[i-1][j] == 'w' {
		fillMap(i-1, j, mark)
	}
	if j > 0 && MAP[i][j-1] == 'w' {
		fillMap(i, j-1, mark)
	}
	if i < n-1 && MAP[i+1][j] == 'w' {
		fillMap(i+1, j, mark)
	}
	if j < m-1 && MAP[i][j+1] == 'w' {
		fillMap(i, j+1, mark)
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadText() string {

	buf := bytes.NewBuffer(nil)

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b == ' ' || b == '\t' || b == '\r' || b == '\n' {
			if buf.Len() > 0 {
				break
			}
		} else {
			buf.WriteByte(b)
		}
	}

	return buf.String()
}

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strings"
)

const MA_MN = 50

var MAP [][]byte
var m, n, k int

func main() {
	reader := NewStdReader(os.Stdin)
	n, m, k = reader.ReadInt(), reader.ReadInt(), reader.ReadInt()

	MAP = make([][]byte, n)

	for i := 0; i < n; i++ {
		s := reader.ReadText()
		s = strings.Replace(s, ".", "w", -1)
		MAP[i] = []byte(s)
	}

	for i := 0; i < n; i++ {
		if MAP[i][0] == 'w' {
			fillMap(i, 0, '.')
		}
		if MAP[i][m-1] == 'w' {
			fillMap(i, m-1, '.')
		}
	}
	for j := 1; j < m-1; j++ {
		if MAP[0][j] == 'w' {
			fillMap(0, j, '.')
		}
		if MAP[n-1][j] == 'w' {
			fillMap(n-1, j, '.')
		}
	}

	countLake := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if MAP[i][j] == 'w' {
				countLake++
				if countLake <= k {
					fillMap(i, j, '.')
				} else {
					fillMap(i, j, '*')
				}
			}
		}
	}

	fmt.Println(countLake - k)
	for i := 0; i < n; i++ {
		fmt.Println(string(MAP[i]))
	}

}

func fillMap(i, j int, mark byte) {
	MAP[i][j] = mark
	if i > 0 && MAP[i-1][j] == 'w' {
		fillMap(i-1, j, mark)
	}
	if j > 0 && MAP[i][j-1] == 'w' {
		fillMap(i, j-1, mark)
	}
	if i < n-1 && MAP[i+1][j] == 'w' {
		fillMap(i+1, j, mark)
	}
	if j < m-1 && MAP[i][j+1] == 'w' {
		fillMap(i, j+1, mark)
	}
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

func (std *StdReader) ReadText() string {

	buf := bytes.NewBuffer(nil)

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b == ' ' || b == '\t' || b == '\r' || b == '\n' {
			if buf.Len() > 0 {
				break
			}
		} else {
			buf.WriteByte(b)
		}
	}

	return buf.String()
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"strings"
	"sort"
)

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

func main() {
	sc := NewScanner()
	n := sc.NextInt()
	m := sc.NextInt()
	k := sc.NextInt()
	in := make([]string, n)
	field := make([][]int, n)
	for i := 0; i < n; i++ {
		in[i] = sc.NextLine()
		field[i] = make([]int, m)
		for j := 0; j < m; j++ {
			if in[i][j] == '*' {
				field[i][j] = -1
			}
		}
	}
	bfs := func(sy, sx, lake int) int {
		x := make([]int, 1)
		y := make([]int, 1)
		x[0] = sx
		y[0] = sy
		field[sy][sx] = lake
		vec := []int{0, -1, 0, 1, 0 }
		isSea := false
		for i := 0; i < len(x); i++ {
			for v := 0; v < 4; v++ {

				if !checkRange(x[i] + vec[v], 0, m) {
					isSea = true
					continue
				}
				if !checkRange(y[i] + vec[v + 1], 0, m) {
					isSea = true
					continue
				}
				if field[y[i] + vec[v + 1]][x[i] + vec[v]] != 0 {
					continue
				}
				x = append(x, x[i] + vec[v])
				y = append(y, y[i] + vec[v + 1])
				field[y[i] + vec[v + 1]][x[i] + vec[v]] = lake
			}
		}
		if isSea {
			return -1
		}
		return len(x)
	}

	lake := 0

	lakes := make(SortInterFace, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if field[i][j] == 0 {
				lake++
				result := bfs(i, j, lake)
				if result > 0 {
					lakes = append(lakes, Tup{result, lake})
				}
			}
		}
	}
	sort.Sort(lakes)

	changed := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			for v := 0; v < len(lakes) - k; v++ {
				if field[i][j] == lakes[v].B {
					field[i][j] = -1
					changed++
				}
			}
		}
	}
	fmt.Println(changed)
	for i := 0; i < n; i++ {
		out := ""
		for j := 0; j < m; j++ {
			if field[i][j] == -1 {
				out += "*"
			} else {
				out += "."
			}
		}
		fmt.Println(out)
	}
}

/**
 * [mn,mx) のチェックをします
 */
func checkRange(v, mn, mx int) bool {
	return mn <= v && v < mx
}

type Tup struct {
	A int
	B int
}

type SortInterFace []Tup

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].A < s[j].A
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"strings"
)

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

func main() {
	sc := NewScanner()
	n := sc.NextInt()
	m := sc.NextInt()
	k := sc.NextInt()
	in := make([]string, n)
	field := make([][]int, n)
	for i := 0; i < n; i++ {
		in[i] = sc.NextLine()
		field[i] = make([]int, m)
		for j := 0; j < m; j++ {
			if in[i][j] == '*' {
				field[i][j] = -1
			}
		}
	}
	bfs := func(sy, sx, lake int) int {
		x := make([]int, 1)
		y := make([]int, 1)
		x[0] = sx
		y[0] = sy
		field[sy][sx] = lake
		vec := []int{0, -1, 0, 1, 0 }
		for i := 0; i < len(x); i++ {
			for v := 0; v < 4; v++ {
				if x[i] + vec[v] < 0 {
					return -1
				}
				if x[i] + vec[v] >= m {
					return -1
				}
				if y[i] + vec[v + 1] < 0 {
					return -1
				}
				if y[i] + vec[v + 1] >= n {
					return -1
				}
				if field[y[i] + vec[v + 1]][x[i] + vec[v]] != 0 {
					continue
				}
				x = append(x, x[i] + vec[v])
				y = append(y, y[i] + vec[v + 1])
				field[y[i] + vec[v + 1]][x[i] + vec[v]] = lake
			}
		}
		return len(x)
	}

	lake := 0
	type Tup struct {
		lakes int
		count int
	}
	lakes := make([]Tup, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if field[i][j] == 0 {
				lake++
				result := bfs(i, j, lake)
				if result > 0 {
					lakes = append(lakes, Tup{lake, result})
				}
			}
		}
	}
	for i := 0; i < len(lakes); i++ {
		for j := i + 1; j < len(lakes); j++ {
			if lakes[i].count > lakes[j].count {
				lakes[i], lakes[j] = lakes[j], lakes[i]
			}
		}
	}
	changed := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			for v := 0; v < len(lakes) - k; v++ {
				if field[i][j] == lakes[v].lakes {
					field[i][j] = -1
					changed++
				}
			}
		}
	}
	fmt.Println(changed)
	for i := 0; i < n; i++ {
		out := ""
		for j := 0; j < m; j++ {
			if field[i][j] == -1 {
				out += "*"
			} else {
				out += "."
			}
		}
		fmt.Println(out)
	}
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
	"strings"
	"sort"
)

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}

func main() {
	sc := NewScanner()
	n := sc.NextInt()
	m := sc.NextInt()
	k := sc.NextInt()
	in := make([]string, n)
	field := make([][]int, n)
	for i := 0; i < n; i++ {
		in[i] = sc.NextLine()
		field[i] = make([]int, m)
		for j := 0; j < m; j++ {
			if in[i][j] == '*' {
				field[i][j] = -1
			}
		}
	}
	bfs := func(sy, sx, lake int) int {
		x := make([]int, 1)
		y := make([]int, 1)
		x[0] = sx
		y[0] = sy
		field[sy][sx] = lake
		vec := []int{0, -1, 0, 1, 0 }
		isSea := false
		for i := 0; i < len(x); i++ {
			for v := 0; v < 4; v++ {
				if x[i] + vec[v] < 0 {
					isSea = true
					continue
				}
				if x[i] + vec[v] >= m {
					isSea = true
					continue
				}
				if y[i] + vec[v + 1] < 0 {
					isSea = true
					continue
				}
				if y[i] + vec[v + 1] >= n {
					isSea = true
					continue
				}
				if field[y[i] + vec[v + 1]][x[i] + vec[v]] != 0 {
					continue
				}
				x = append(x, x[i] + vec[v])
				y = append(y, y[i] + vec[v + 1])
				field[y[i] + vec[v + 1]][x[i] + vec[v]] = lake
			}
		}
		if isSea {
			return -1
		}
		return len(x)
	}

	lake := 0

	lakes := make(SortInterFace, 0)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if field[i][j] == 0 {
				lake++
				result := bfs(i, j, lake)
				if result > 0 {
					lakes = append(lakes, Tup{lake, result})
				}
			}
		}
	}
	sort.Sort(lakes)

	changed := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			for v := 0; v < len(lakes) - k; v++ {
				if field[i][j] == lakes[v].lakes {
					field[i][j] = -1
					changed++
				}
			}
		}
	}
	fmt.Println(changed)
	for i := 0; i < n; i++ {
		out := ""
		for j := 0; j < m; j++ {
			if field[i][j] == -1 {
				out += "*"
			} else {
				out += "."
			}
		}
		fmt.Println(out)
	}
}

type Tup struct {
	lakes int
	count int
}

type SortInterFace []Tup

func (s SortInterFace) Len() int {
	return len(s)
}
func (s SortInterFace) Less(i, j int) bool {
	return s[i].count > s[j].count
}
func (s SortInterFace) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}


// cf258a project main.go
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	s = strings.TrimLeft(s, "0")
	i := strings.Index(s, "0")
	if i > 0 {
		fmt.Println(s[:i] + s[i+1:])
	} else {
		fmt.Println(s[:len(s)-1])
	}

}

package main
import (
	"fmt"
	"unicode/utf8"
)

func main() {
	var counter,j int
	counter = 0
	var input string
	fmt.Scan(&input)
	len := utf8.RuneCountInString(input)

	for i:=0; i<len;i++ {
			if string(input[i]) == "0"{
				j=i
				counter=1
				break
	}
	}

	if counter==0 {
		for i:=0;i<len-1;i++ {
			fmt.Print(string(input[i]))
		}
		fmt.Println()
	} else {
		for i:=0;i<len;i++ {
			if i!=j{
				fmt.Print(string(input[i]))
			}
		}
		fmt.Println()
	}

}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	if s, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		var i int = 0
		var removed bool = false
		for s[i+1] != '\r' && s[i+1] != '\n' {
			if !removed {
				if s[i] == '0' {
					removed = true
				} else {
					fmt.Printf("%c", s[i])
				}
			} else {
				fmt.Printf("%c", s[i])
			}
			i++
		}
		if removed {
			fmt.Printf("%c", s[i])
		}
		fmt.Println()
	}
}

package main

import (
    "fmt"
    "bufio"
    "os"
)

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var s string
    fmt.Scan(&s)
    found := false
    for i := 0; i < len(s); i++ {
        if (!found) && ((s[i] == '0') || (i == (len(s)-1))){
            found = true
        } else {
            writer.WriteByte(s[i])
        }
    }
    writer.WriteRune('\n')
    writer.Flush()
}

// 258A-mic
package main

import (
	"fmt"
)

func main() {
	var i string
	deleted := false
	fmt.Scan(&i)
	for k := 0; k < len(i); k++ {
		if i[k] == '0' && !deleted {
			deleted = true
		} else if k == len(i)-1 && !deleted {
			deleted = true
		} else {
			fmt.Print(string(i[k]))
		}
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	found := false
	for i := 0; i < len(s); i++ {
		if (!found) && (s[i] == '0') {
			found = true
		} else if (!found) && i == (len(s)-1) {
			found = true
		} else {
			x := string(s[i])
			fmt.Print(x)
		}
	}
	fmt.Println()
}

package main

import (
	"fmt"
)

func main() {
	line := ""
	fmt.Scan(&line)

	length := len(line)
	rm := 0
	for rm = 0; rm < length; rm++ {
		if line[rm] == '0' {
			break
		}
	}

	/* all '1' */
	if rm == length {
		fmt.Println(line[1:length])
	} else {
		ans := line[0:rm] + line[rm+1:length]
		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var s string
	for I(&s) == nil {
		solve(s)
	}
	w.Flush()
}

func solve(s string) {
	var done bool
	for i := range s {
		if !done && (s[i] == '0' || i == len(s)-1) {
			done = true
		} else if done || s[i] == '1' {
			O(string(s[i]))
		}
	}
	O("\n")
}

package main

import "fmt"

func main(){
	var a string
	fmt.Scan(&a)
	p := len(a)
	s := 1
	for i:=0; i<p; i++ {
		if a[i] == '0' && s !=0 {
			s = 0
		} else if i == p-1 && s!=0 {
			s = 0
		} else {
			fmt.Print(string(a[i]))
		}
	}
	fmt.Println()
}

package main

import (
    //"math"
    // "io"
    "os"
    // "bufio"
    "io/ioutil"
    "fmt"
    "bytes"
)
func main() {
    bs, _ := ioutil.ReadAll(os.Stdin)
    if i := bytes.IndexByte(bs, '0'); i >= 0 {
        fmt.Printf("%s", append(bs[:i], bs[i+1:]...))
    } else {
        fmt.Printf("%s", bs[:len(bs)-3])
    }
}
// func main() {
//     var s string
//     fmt.Scan(&s)
//     var bs = []byte(s)
//     var i0 = len(s)
//     for i := range bs {
//         if s[i] == '0' {
//             i0 = i
//             break
//         }
//     }
//     if i0 == len(s) {
//         fmt.Printf("%s", bs[:i0-1])
//     } else {
//         fmt.Printf("%s", append(bs[:i0], bs[i0+1:]...))
//     }
// }
// func main2() {
//     r := bufio.NewReaderSize(os.Stdin, 655350)
//     prefix, err := r.ReadSlice('0')
//     //fmt.Println(err, prefix)
//     n := len(prefix)
//     if err == nil {
//         os.Stdout.Write(prefix[:n-1])
//         io.Copy(os.Stdout, r)
//     } else {
//         ret := make([]byte, n-3)
//         copy(ret, prefix)
//         os.Stdout.Write(ret)
//     }
// }

package main

import (
    //"math"
    // "io"
    // "os"
    // "bufio"
    "fmt"
)
func main() {
    var s string
    fmt.Scan(&s)
    var bs = []byte(s)
    var i0 = len(s)
    for i := range bs {
        if s[i] == '0' {
            i0 = i
            break
        }
    }
    if i0 == len(s) {
        fmt.Printf("%s", bs[:i0-1])
    } else {
        fmt.Printf("%s", append(bs[:i0], bs[i0+1:]...))
    }
}
// func main2() {
//     r := bufio.NewReaderSize(os.Stdin, 655350)
//     prefix, err := r.ReadSlice('0')
//     //fmt.Println(err, prefix)
//     n := len(prefix)
//     if err == nil {
//         os.Stdout.Write(prefix[:n-1])
//         io.Copy(os.Stdout, r)
//     } else {
//         ret := make([]byte, n-3)
//         copy(ret, prefix)
//         os.Stdout.Write(ret)
//     }
// }

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    // "fmt"
)

func main() {
    r := bufio.NewReaderSize(os.Stdin, 655350)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    n := len(prefix)
    if err == nil {
        os.Stdout.Write(prefix[:n-1])
        io.Copy(os.Stdout, r)
    } else {
        ret := make([]byte, n-3)
        copy(ret, prefix)
        os.Stdout.Write(ret)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    // "io/ioutil"
    // "fmt"
    // "bytes"
)
// func main() {
//     bs, _ := ioutil.ReadAll(os.Stdin)
//     if i := bytes.IndexByte(bs, '0'); i >= 0 {
//         fmt.Printf("%s", append(bs[:i], bs[i+1:]...))
//     } else {
//         fmt.Printf("%s", bs[:len(bs)-3])
//     }
// }
// func main() {
//     var s string
//     fmt.Scan(&s)
//     var bs = []byte(s)
//     var i0 = len(s)
//     for i := range bs {
//         if s[i] == '0' {
//             i0 = i
//             break
//         }
//     }
//     if i0 == len(s) {
//         fmt.Printf("%s", bs[:i0-1])
//     } else {
//         fmt.Printf("%s", append(bs[:i0], bs[i0+1:]...))
//     }
// }
func main() {
    r := bufio.NewReader(os.Stdin)
    for {
        prefix, err := r.ReadSlice('0')
        //fmt.Println(err, prefix)
        n := len(prefix)
        if err == nil {
            os.Stdout.Write(prefix[:n-1])
            io.Copy(os.Stdout, r)
            break
        } else if err == io.EOF {
            os.Stdout.Write(prefix[:n-3])
            break
        } else {
            os.Stdout.Write(prefix)
        }
    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	var s string
	for I(&s) == nil {
		solve(s)
	}
	w.Flush()
}

func solve(s string) {
	l := len(s) - 1
	max := s
	for i := range s {
		a := s[:i]
		if i != l {
			a += s[i+1:]
		}
		if strings.Compare(a, max) == 1 {
			max = a
		}
	}
	O(max, "\n")
}

package main

import "fmt"

func main(){
	var a string
	fmt.Scan(&a)
	p := len(a)
	s := 1
	for i:=0; i<p; i++ {
		if a[i] == '0' && s !=0 {
			s = 0
		} else {
			fmt.Print(string(a[i]))
		}
	}
	fmt.Println()
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    // "fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    n := len(prefix)
    if err == nil {
        os.Stdout.Write(prefix[:n-1])
        io.Copy(os.Stdout, r)
    } else {
        ret := make([]byte, n)
        copy(ret, prefix[:n-3])
        os.Stdout.Write(ret)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    // "fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    n := len(prefix)
    if err == nil {
        os.Stdout.Write(prefix[:n-1])
        io.Copy(os.Stdout, r)
    } else {
        ret := make([]byte, n-2)
        copy(ret, prefix)
        os.Stdout.Write(ret)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    "fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    if err == nil {
        os.Stdout.Write(prefix[0:len(prefix)-1])
        io.Copy(os.Stdout, r)
    } else {
        fmt.Printf("%s", prefix[0:len(prefix)-2])
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    // "fmt"
)

func main() {
    r := bufio.NewReaderSize(os.Stdin, 65535)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    n := len(prefix)
    if err == nil {
        os.Stdout.Write(prefix[:n-1])
        io.Copy(os.Stdout, r)
    } else {
        ret := make([]byte, n-3)
        copy(ret, prefix)
        os.Stdout.Write(ret)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    // "fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    n := len(prefix)
    if err == nil {
        os.Stdout.Write(prefix[:n-1])
        io.Copy(os.Stdout, r)
    } else {
        ret := make([]byte, n-3)
        copy(ret, prefix)
        os.Stdout.Write(ret)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    //"fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    if err == nil {
        os.Stdout.Write(prefix[0:len(prefix)-1])
        io.Copy(os.Stdout, r)
    } else {
        os.Stdout.Write(prefix[0:len(prefix)-2])
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    //"fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    if err == io.EOF {
        os.Stdout.Write(prefix[0:len(prefix)-2])
    } else {
        //    fmt.Println(err, prefix)
        os.Stdout.Write(prefix[0:len(prefix)-1])
        io.Copy(os.Stdout, r)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    "fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    if err == nil {
        os.Stdout.Write(prefix[0:len(prefix)-1])
        io.Copy(os.Stdout, r)
    } else {
        p := prefix[0:len(prefix)-2]
        fmt.Printf("%s", p)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    // "fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    n := len(prefix)
    if err == nil {
        os.Stdout.Write(prefix[:n-1])
        io.Copy(os.Stdout, r)
    } else {
        ret := make([]byte, n-2)
        copy(ret, prefix[:n-2])
        os.Stdout.Write(ret)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    "fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    if err == nil {
        os.Stdout.Write(prefix[0:len(prefix)-1])
        io.Copy(os.Stdout, r)
    } else {
        prefix[len(prefix)-2] = 0
        fmt.Printf("%s", prefix)
    }
}

package main

import (
    //"math"
    "io"
    "os"
    "bufio"
    // "fmt"
)

func main() {
    r := bufio.NewReader(os.Stdin)
    prefix, err := r.ReadSlice('0')
    //fmt.Println(err, prefix)
    if err == nil {
        os.Stdout.Write(prefix[0:len(prefix)-1])
        io.Copy(os.Stdout, r)
    } else {
        os.Stdout.Write(prefix[:len(prefix)-2])
    }
}

package main

import (
    "fmt"
    "bufio"
    "os"
)

func main() {
    writer := bufio.NewWriter(os.Stdout)
    var s string
    fmt.Scan(&s)
    found := false
    for _, v := range s {
        if (!found) && (v == '0') {
            found = true
        } else {
            writer.WriteRune(v)
        }
    }
    writer.WriteRune('\n')
    writer.Flush()
}

package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	found := false
	for i := 0; i < len(s); i++ {
		if (!found) && (s[i] == '0') {
			found = true
		} else if (!found) && i == (len(s)-1) {
			found = true
		} else {
			fmt.Print(s[i])
		}
	}
	fmt.Println()
}

// 258A-mic
package main

import (
    "fmt"
)

func main() {
    var i string
    deleted := false
    fmt.Scan(&i)
    for k := 0; k < len(i)-1; k++ {
        if i[k] == '0' && !deleted {
            deleted = true
        } else if k == len(i)-1 && !deleted {
            deleted = true
        } else {
            fmt.Print(string(i[k]))
        }
    }
    fmt.Println()
}