package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(Case int) {
		var n, m, k int
		Fscan(in, &n, &m, &k)
		res := n*m-1
		if res == k {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}

	var T int
	Fscan(in, &T)
	for Case := 1; Case <= T; Case++ {
		solve(Case)
	}

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

func main() { run(os.Stdin, os.Stdout) }

package main

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

type CF1519B struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1519B) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1519B) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1519B) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1519B) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1519B) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

var memo map[int]map[int]map[int]int

/**
Run solve the problem CF1519B
Date: 13/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1519/B
Problem: CF1519B
**/
func (in *CF1519B) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n, m, k := in.NextInt(), in.NextInt(), in.NextInt()

		memo = make(map[int]map[int]map[int]int)

		ans := f(n, m, k)
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func f(i, j, n int) bool {
	if i == 1 && j == 1 && n == 0 {
		return true
	}
	if i < 1 || j < 1 || n < 0 {
		return false
	}
	if val, ok := memo[i][j][n]; ok && val != 0 {
		return memo[i][j][n] == 1
	}

	ans := f(i, j-1, n-i) || f(i-1, j, n-j)
	if ans {
		save(i, j, n, 1)
	} else {
		save(i, j , n, 2)
	}
	return memo[i][j][n] == 1

}

func save(i, j, n, val int) {
	if _, ok := memo[i]; !ok {
		memo[i] = make(map[int]map[int]int)
	}
	if _, ok := memo[i][j]; !ok {
		memo[i][j] = make(map[int]int)
	}
		memo[i][j][n] = val
}

func NewCF1519B(r *bufio.Reader) *CF1519B {
	return &CF1519B{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1519B(bufio.NewReader(os.Stdin)).Run()
}

package main

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

// TAG: dp/math

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {

		var k, m, n, i, j int64
		scanf("%d %d %d \n", &n, &m, &k)

		// base
		if n == 1 && m == 1 && k != 0 {
			printf("NO\n")
			continue
		}

		var matrix [][]int64
		for i = n; i > 0; i-- {
			matrix = append(matrix, make([]int64, m))
		}

		// matrix[1][1] = 1
		for i = 0; i < n; i++ {
			for j = 0; j < m; j++ {
				if i != 0 && j == 0 {
					matrix[i][j] += matrix[i-1][j] + 1
				} else if j != 0 {
					matrix[i][j] += matrix[i][j-1] + i + 1
				}
			}
		}

		if matrix[n-1][m-1] == k {
			printf("YES\n")
		} else {
			printf("NO\n")
		}

	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t, n, m, k int
	fmt.Fscanln(in, &t)
	for t > 0 {
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		solve(n, m, k)
		t--
	}
}
func solve(n, m, k int) {
	if m*n-1 == k {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	outputs := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		n, m, k := ScanInt(), ScanInt(), ScanInt()
		cost := make([][]map[int]bool, n+1)

		for x := range cost {
			cost[x] = make([]map[int]bool, m+1)

			for y := range cost[x] {
				cost[x][y] = make(map[int]bool)
			}
		}

		cost[1][1][0] = true

		for x := 1; x <= n; x++ {
			for y := 1; y <= m; y++ {
				for c := range cost[x][y-1] {
					cost[x][y][x+c] = true
				}

				for c := range cost[x-1][y] {
					cost[x][y][y+c] = true
				}
			}
		}

		fmt.Println(outputs[cost[n][m][k]])
	}
}

package main

import (
	"bufio"
	"fmt"
	"io/ioutil"
	"os"
	"strconv"
	"strings"
)

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	outputs := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		n, m, k := ScanInt(), ScanInt(), ScanInt()
		cost := make([][]map[int]bool, n+1)

		for x := range cost {
			cost[x] = make([]map[int]bool, m+1)

			for y := range cost[x] {
				cost[x][y] = make(map[int]bool)
			}
		}

		cost[1][1][0] = true

		for x := 1; x <= n; x++ {
			for y := 1; y <= m; y++ {
				for c, _ := range cost[x][y-1] {
					cost[x][y][x+c] = true
				}

				for c, _ := range cost[x-1][y] {
					cost[x][y][y+c] = true
				}
			}
		}

		fmt.Println(outputs[cost[n][m][k]])
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var a,b,c int
		fmt.Fscan(in,&a,&b,&c) // take inputs
		// always moving horizontally first, then vertically
		x:= b-1 // cost to move horizontally
		y:= b*(a-1) // cost to move vertically
		if x+y == c { // if total cost = c, yes; else no
			fmt.Fprintln(out,"YES")
		} else {
			fmt.Fprintln(out,"NO")
		}
	}
}

package main

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

func main() {
	CF1519B(os.Stdin, os.Stdout)
}

func CF1519B(in io.Reader, out io.Writer) {
	_r := bufio.NewReader(in)
	_w := bufio.NewWriter(out)
	defer _w.Flush()

	var T int64
	for fmt.Fscan(_r, &T); T > 0; T-- {
		var n, m, k int64
		fmt.Fscan(_r, &n, &m, &k)
		if k == n * m -1 {
			fmt.Fprintln(_w, "YES")

		} else {
			fmt.Fprintln(_w, "NO")
		}

	}

}

package main

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

var (
	reader     = bufio.NewReader(os.Stdin)
	t, n, m, k int
)

func solve(n, m, k int) string {
	if n*m == k+1 {
		return "YES"
	}
	return "NO"
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &m, &k)
		fmt.Println(solve(n, m, k))
	}
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()
	if len(os.Args[1:]) == 1 {
		file, _ := os.Open(os.Args[1])
		reader = bufio.NewReader(file)
	}

	var t, n, m, k int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		scanf("%d %d %d\n", &n, &m, &k)
		memo := make([][]int, n+1)
		for j := 0; j < n+1; j++ {
			memo[j] = make([]int, m+1)
			for k := 0; k < m+1; k++ {
				memo[j][k] = -1
			}
		}
		ans := solve(n, m, k, memo)
		if ans == 0 {
			printf("YES\n")
		} else {
			printf("NO\n")
		}
	}
}

func solve(n, m, k int, memo [][]int) int {
	//fmt.Println(n, m, k)
	if k < 0 {
		return -2
	}
	if n == 1 && m == 1 {
		if k == 0 {
			return 0
		} else {
			return -2
		}
	}
	if memo[n][m] != -1 {
		return memo[n][m]
	}
	if n > 1 {
		memo[n][m] = solve(n-1, m, k-m, memo)
	}
	if memo[n][m] == 0 {
		return 0
	}
	if m > 1 {
		memo[n][m] = solve(n, m-1, k-n, memo)
	}
	return memo[n][m]
}

package main

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

var (
    in = bufio.NewReader(os.Stdin)
)

func main() {
    var T int
    for Fscan(in, &T); T > 0; T-- {
        var n, m, k int
        Fscan(in, &n, &m, &k)

        total := n - 1
        total += (m - 1) * n

        if total == k {
            Println("YES")
        } else {
            Println("NO")
        }
    }
}

package main

import "fmt"

func main() {
	var t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var n, m, k int
		fmt.Scan(&n, &m, &k)

		if n * m - 1 == k {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func run(or io.Reader, ow io.Writer) {
	in := bufio.NewReader(or)
	out := bufio.NewWriter(ow)
	defer out.Flush()

	solve := func() {
		var r, b, d int64
		fmt.Fscan(in, &r, &b, &d)

		if r*b-1 == d {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}

	T := 1
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

func main() { run(os.Stdin, os.Stdout) }

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n, m, k int
		_, _ = fmt.Fscan(in, &n, &m, &k)

		if n*m-1 == k {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

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

var (
	in = bufio.NewReader(os.Stdin)
)

func solve() {
	var n, m, k float64
	fmt.Fscan(in, &n, &m, &k)
	var cost float64
	if n < m {
		//cost to reach at m cordinate
		numberOfSteps := m - 1
		cost += numberOfSteps

		second := n - 1
		cost += (second * m)
	} else {
		numberOfSteps := n - 1
		cost += numberOfSteps
		second := m - 1
		cost += (second * n)
	}
	if cost == k {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}

func main() {
	var test int
	fmt.Scanln(&test)
	for i := 0; i < test; i++ {
		solve()
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)

	var t, n, m, k int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &m, &k)
		if n*m-1 == k {
			fmt.Println("YES")
			continue
		}
		fmt.Println("NO")
	}
}

package main

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

// TAG: dp/math

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {

		var k, m, n, i, j int64
		scanf("%d %d %d \n", &n, &m, &k)

		// base
		if n == 1 && m == 1 && k != 0 {
			printf("NO\n")
		}

		var matrix [][]int64
		for i = n; i > 0; i-- {
			matrix = append(matrix, make([]int64, m))
		}

		// matrix[1][1] = 1
		for i = 0; i < n; i++ {
			for j = 0; j < m; j++ {
				if i != 0 && j == 0 {
					matrix[i][j] += matrix[i-1][j] + 1
				} else if j != 0 {
					matrix[i][j] += matrix[i][j-1] + i + 1
				}
			}
		}

		if matrix[n-1][m-1] == k {
			printf("YES\n")
		} else {
			printf("NO\n")
		}

	}
}

package main

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

// TAG: dp/math

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	// STDOUT MUST BE FLUSHED MANUALLY!!!
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {

		var k, m, n, i, j int64
		scanf("%d %d %d \n", &n, &m, &k)

		// base
		if n == 1 && m == 1 && k != 0 {
			printf("NO\n")
		}

		var matrix [][]int64
		for i = n; i > 0; i-- {
			matrix = append(matrix, make([]int64, m))
		}

		// fmt.Println(matrix)
		// matrix[1][1] = 1
		for i = 0; i < n; i++ {
			for j = 0; j < m; j++ {
				if i != 0 && j == 0 {
					matrix[i][j] += matrix[i-1][j] + 1
				} else if j != 0 {
					matrix[i][j] += matrix[i][j-1] + i + 1
				}
			}
		}

		// fmt.Println(matrix)
		if matrix[n-1][m-1] == k {
			printf("YES\n")
		} else {
			printf("NO\n")
		}

	}
}


package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func Scan(a ...interface{}) { fmt.Fscan(in, a...) }
func Scanln(s *string) {
	*s = ""
	for len(*s) == 0 {
		*s, _ = in.ReadString('\n')
		*s = strings.TrimSpace(*s)
	}
}
func Print(a ...interface{})                 { fmt.Fprint(out, a...) }
func Printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func Log(a ...interface{}) {
	pc, _, line, _ := runtime.Caller(1)
	fmt.Fprint(out, "log ", runtime.FuncForPC(pc).Name(), ":", line, " ")
	fmt.Fprint(out, a...)
	fmt.Fprint(out, "\n")
}

const N = 50 + 10

var (
	s [N]string
	t [N][N]byte
)

func solve() {
	var (
		n, m int
	)
	Scan(&n, &m)
	for i := 0; i < n; i++ {
		Scanln(&s[i])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			t[i][j] = '.'
		}
	}

	for j := 0; j < m; j++ {
		idx := n - 1
		for i := n - 1; i >= 0; i-- {
			switch s[i][j] {
			case '*':
				t[idx][j] = '*'
				idx--
			case 'o':
				t[i][j] = 'o'
				idx = i - 1
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			Printf("%c", t[i][j])
		}
		Print("\n")
	}
}

func main() {
	defer out.Flush()

	T := 1
	Scan(&T)
	for test := 0; test < T; test++ {
		solve()
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var h, w int
		fmt.Fscan(in, &h, &w)

		input := make([]string, h)
		for i := 0; i < h; i++ {
			fmt.Fscan(in, &input[i])
		}

		ans := make([][]uint8, h)
		for i := 0; i < h; i++ {
			ans[i] = make([]uint8, w)
			for j := range ans[i] {
				ans[i][j] = '.'
			}
		}

		for x := 0; x < w; x++ {
			prevY, stonesCnt := 0, 0
			for y := 0; y < h; y++ {
				if input[y][x] == '.' {
					continue
				}

				if input[y][x] == '*' {
					stonesCnt++
					continue
				}

				for i := prevY; i < y-stonesCnt; i++ {
					ans[i][x] = '.'
				}
				for i := prevY + (y - prevY - stonesCnt); i < y; i++ {
					ans[i][x] = '*'
				}
				ans[y][x] = 'o'
				prevY, stonesCnt = y+1, 0
			}

			for i := prevY; i < h-stonesCnt; i++ {
				ans[i][x] = '.'
			}
			for i := h - stonesCnt; i < h; i++ {
				ans[i][x] = '*'
			}
		}

		for _, row := range ans {
			fmt.Fprintln(out, string(row))
		}
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var h, w int
		fmt.Fscan(in, &h, &w)

		input := make([]string, h)
		for i := 0; i < h; i++ {
			fmt.Fscan(in, &input[i])
		}

		ans := make([][]uint8, h)
		for i := 0; i < h; i++ {
			ans[i] = make([]uint8, w)
			for j := range ans[i] {
				ans[i][j] = '.'
			}
		}

		for x := 0; x < w; x++ {
			prevY, stonesCnt := 0, 0
			for y := 0; y < h; y++ {
				if input[y][x] == '.' {
					continue
				}

				if input[y][x] == '*' {
					stonesCnt++
					continue
				}

				for i := prevY; i < y-stonesCnt; i++ {
					ans[i][x] = '.'
				}
				for i := prevY + (y - prevY - stonesCnt); i < y; i++ {
					ans[i][x] = '*'
				}
				ans[y][x] = 'o'
				prevY, stonesCnt = y+1, 0
			}

			for i := prevY; i < h-stonesCnt; i++ {
				ans[i][x] = '.'
			}
			for i := h - stonesCnt; i < h; i++ {
				ans[i][x] = '*'
			}

			/*if ans[h-1][x] == 0 {
				ans[h-1][x] = '.'
			}*/
			prevY, stonesCnt = h-1, 0
		}
		for _, row := range ans {
			fmt.Fprintln(out, string(row))
		}
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var h, w int
		fmt.Fscan(in, &h, &w)

		input := make([]string, h)
		for i := 0; i < h; i++ {
			fmt.Fscan(in, &input[i])
		}

		ans := make([][]uint8, h)
		for i := 0; i < h; i++ {
			ans[i] = make([]uint8, w)
		}

		for x := 0; x < w; x++ {
			prevY, stonesCnt := 0, 0
			for y := 0; y < h; y++ {
				if input[y][x] == '.' {
					continue
				}

				if input[y][x] == '*' {
					stonesCnt++
					continue
				}

				for i := prevY; i < y-stonesCnt; i++ {
					ans[i][x] = '.'
				}
				for i := prevY + (y - prevY - stonesCnt); i < y; i++ {
					ans[i][x] = '*'
				}
				ans[y][x] = 'o'
				prevY, stonesCnt = y+1, 0
			}

			for i := prevY; i < h-stonesCnt; i++ {
				ans[i][x] = '.'
			}
			for i := h - stonesCnt; i < h; i++ {
				ans[i][x] = '*'
			}

			if ans[h-1][x] == 0 {
				ans[h-1][x] = '.'
			}
			prevY, stonesCnt = h-1, 0
		}
		for _, row := range ans {
			fmt.Fprintln(out, string(row))
		}
	}

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		var h, w int
		fmt.Fscan(in, &h, &w)

		input := make([]string, h)
		for i := 0; i < h; i++ {
			fmt.Fscan(in, &input[i])
		}

		ans := make([][]uint8, h)
		for i := 0; i < h; i++ {
			ans[i] = make([]uint8, w)
		}

		for x := 0; x < w; x++ {
			prevY, stonesCnt := 0, 0
			for y := 0; y < h; y++ {
				if input[y][x] == '.' {
					continue
				}

				if input[y][x] == '*' {
					stonesCnt++
					continue
				}

				for i := prevY; i < y-stonesCnt; i++ {
					ans[i][x] = '.'
				}
				for i := prevY + (y - prevY - stonesCnt); i < y; i++ {
					ans[i][x] = '*'
				}
				ans[y][x] = 'o'
				prevY, stonesCnt = y+1, 0
			}

			for i := prevY; i < h-stonesCnt; i++ {
				ans[i][x] = '.'
			}
			for i := h - stonesCnt; i < h; i++ {
				ans[i][x] = '*'
			}

			if stonesCnt == 0 && ans[h-1][x] != 'o' {
				ans[h-1][x] = '.'
			}
			prevY, stonesCnt = h-1, 0
		}
		for _, row := range ans {
			fmt.Fprintln(out, string(row))
		}
	}

}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func Scan(a ...interface{}) { fmt.Fscan(in, a...) }
func Scanln(s *string) {
	*s, _ = in.ReadString('\n')
	*s = strings.TrimSpace(*s)
	for len(*s) == 0 {
		*s, _ = in.ReadString('\n')
		*s = strings.TrimSpace(*s)
	}
}
func Print(a ...interface{})                 { fmt.Fprint(out, a...) }
func Printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func Log(a ...interface{}) {
	pc, _, line, _ := runtime.Caller(1)
	fmt.Fprint(out, "log ", runtime.FuncForPC(pc).Name(), ":", line, " ")
	fmt.Fprint(out, a...)
	fmt.Fprint(out, "\n")
}

const N = 50 + 10

var (
	s [N]string
	t [N][N]byte
)

func solve() {
	var (
		n, m int
	)
	Scan(&n, &m)
	for i := 0; i < n; i++ {
		Scanln(&s[i])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			t[i][j] = '.'
		}
	}

	for j := 0; j < m; j++ {
		idx := n - 1
		for i := n - 1; i >= 0; i-- {
			switch s[i][j] {
			case '*':
				t[idx][j] = '*'
				idx--
			case 'o':
				t[i][j] = 'o'
				idx = i - 1
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			Printf("%c", t[i][j])
		}
		Print("\n")
	}
}

func main() {
	defer out.Flush()

	T := 1
	Scan(&T)
	for test := 0; test < T; test++ {
		solve()
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func Scan(a ...interface{}) { fmt.Fscan(in, a...) }
func Scanln(s *string) {
	for *s, _ = in.ReadString('\n'); *s == "\n" || *s == "\r\n"; {
		*s, _ = in.ReadString('\n')
	}
	*s = strings.TrimSpace(*s)
}
func Print(a ...interface{})                 { fmt.Fprint(out, a...) }
func Printf(format string, a ...interface{}) { fmt.Fprintf(out, format, a...) }
func Log(a ...interface{}) {
	pc, _, line, _ := runtime.Caller(1)
	fmt.Fprint(out, "log ", runtime.FuncForPC(pc).Name(), ":", line, " ")
	fmt.Fprint(out, a...)
	fmt.Fprint(out, "\n")
}

const N = 50 + 10

var (
	s [N]string
	t [N][N]byte
)

func solve() {
	var (
		n, m int
	)
	Scan(&n, &m)
	for i := 0; i < n; i++ {
		Scanln(&s[i])
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			t[i][j] = '.'
		}
	}

	for j := 0; j < m; j++ {
		idx := n - 1
		for i := n - 1; i >= 0; i-- {
			switch s[i][j] {
			case '*':
				t[idx][j] = '*'
				idx--
			case 'o':
				t[i][j] = 'o'
				idx = i - 1
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			Printf("%c", t[i][j])
		}
		Print("\n")
	}
}

func main() {
	defer out.Flush()

	T := 1
	Scan(&T)
	for test := 0; test < T; test++ {
		solve()
	}
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}

var (
	n int
)

func solve() {
	var m int
	scan(&n, &m)
	a := make([][]rune, n)
	for i := 0; i < n; i++ {
		var s string
		scan(&s)
		a[i] = []rune(s)
	}
	for col := 0; col < m; col++ {
		fall := n - 1
		for row := n - 1; row >= 0; row-- {
			switch a[row][col] {
			case '*':
				tmp := a[fall][col]
				a[fall][col] = a[row][col]
				a[row][col] = tmp
				if fall > 0 {
					fall--
				}
			case 'o':
				fall = row - 1
			}
		}
	}
	// printf("-------------\n")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			printf("%c", a[i][j])
		}
		printf("\n")
	}
}

func main() {
	defer out.Flush()
	n := 1
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func printf(f string, a ...interface{}) {
	fmt.Fprintf(out, f, a...)
}

var (
	n int
)

func solve() {
	var m int
	scan(&n, &m)
	a := make([][]rune, n)
	for i := 0; i < n; i++ {
		var s string
		scan(&s)
		a[i] = []rune(s)
	}
	for col := 0; col < m; col++ {
		fall := n - 1
		lasto := n
		for row := n - 1; row >= 0; row-- {
			switch a[row][col] {
			case '*':
				if fall != row {
					a[fall][col] = '*'
					a[row][col] = '.'
				}
				if fall > 0 {
					fall--
				}
				// printf("* %d %d\n", fall, lasto)
			case 'o':
				if lasto > row {
					lasto = row
				}
				fall = row - 1
				for fall >= 0 && fall < n && a[fall][col] == 'o' {
					fall--
				}
				// printf("o %d %d\n", fall, lasto)
			case '.':
				if fall < row && (fall > lasto && lasto < n || lasto == n) {
					fall = row
				}
				// printf(". %d %d\n", fall, lasto)
			}
		}
	}
	// printf("-------------\n")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			printf("%c", a[i][j])
		}
		printf("\n")
	}
}

func main() {
	defer out.Flush()
	n := 1
	scan(&n)
	for i := 0; i < n; i++ {
		solve()
	}
}

package main

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

const MOD int64 = 1000000007

var n, m int

var grid []string

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &m)

		grid = make([]string, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(read, &grid[i])
		}

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {

	ans := make([][]byte, n)
	for i := 0; i < n; i++ {
		ans[i] = make([]byte, m)
	}

	for i := 0; i < m ; i++ {

		cnt := 0

		for j := n - 1; j >= 0; j-- {
			if grid[j][i] == '.' {
				cnt++
				ans[j][i] = '.'
			}
			if grid[j][i] == 'o' {
				cnt = 0
				ans[j][i] = 'o'
			}

			if grid[j][i] == '*' {
				ans[j][i] = '.'
				ans[j + cnt][i] = '*'
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Print(string(ans[i][j]))
		}
		fmt.Println()
	}
	fmt.Println()
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var (
	in  = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
)

func main() {
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for ; t > 0; t-- {
		var n, m int
		fmt.Fscanf(in, "%d%d\n", &n, &m)
		var s string
		arr := make([][]uint8, n)
		for i := 0; i < n; i++ {
			arr[i] = make([]uint8, m)
		}
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s\n", &s)
			for j := 0; j < m; j++ {
				arr[i][j] = s[j]
			}
		}

		for k := 0; k < n-1; k++ {

			for i := n - 2; i >= 0; i-- {

				for j := 0; j < m; j++ {
					if arr[i][j] == '.' {
						continue
					}
					if arr[i][j] == 'o' {
						continue
					}
					if arr[i+1][j] == '.' {
						arr[i][j] = '.'
						arr[i+1][j] = '*'
					}
				}
			}
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				fmt.Fprintf(out, "%c", arr[i][j])
			}
			fmt.Fprintln(out)
		}

	}
}

// @Title
// @Description
// @Author
// @Update
package main

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

func dfs(i, j int, arr [][]rune) {
        n := len(arr)
        if i != n-1 {
                if arr[i+1][j] == '.' {
                        arr[i+1][j], arr[i][j] = '*', '.'
                        dfs(i+1, j, arr)
                }
        }
}
func fun(in *bufio.Reader) {
        var n, m int
        fmt.Fscan(in, &n, &m)
        arr := make([][]rune, n)
        for i := 0; i < n; i++ {
                arr[i] = make([]rune, m)
                s := ""
                fmt.Fscan(in, &s)
                for j := 0; j < m; j++ {
                        arr[i][j] = rune(s[j])
                }
        }
        for i := n - 1; i >= 0; i-- {
                for j := m - 1; j >= 0; j-- {
                        if arr[i][j] == '*' {
                                dfs(i, j, arr)
                        }
                }
        }
        for i := 0; i < n; i++ {
                for j := 0; j < m; j++ {
                        fmt.Printf("%c", arr[i][j])
                }
                fmt.Print("\n")
        }
}

func main() {
        t := 1
        fmt.Scan(&t)
        in := bufio.NewReader(os.Stdin)
        for i := 0; i < t; i++ {
                fun(in)
        }

}

package main

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

func solve(cin *scanner, cout *writer, cerr *writer) {
	n, m := cin.NextInt(), cin.NextInt()
	v := make([][]rune, n)
	for i := range v {
		v[i] = []rune(cin.Next())
	}
	var done bool
	for !done {
		var swapped bool
		for j := 0; j < m; j++ {
			for i := n - 1; i > 0; i-- {
				if v[i][j] == '.' && v[i-1][j] == '*' {
					v[i][j], v[i-1][j] = v[i-1][j], v[i][j]
					swapped = true
				}
			}
		}
		if !swapped {
			done = true
		}
	}
	for _, s := range v {
		cout.Println(string(s))
	}
}

func main() {
	cin := NewScanner(os.Stdin)
	cout, cerr := NewWriter(os.Stdout), NewWriter(os.Stderr)
	defer cout.Flush()
	defer cerr.Flush()
	t := cin.NextInt()
	// t := 1
	for ti := 0; ti < t; ti++ {
		solve(cin, cout, cerr)
	}
}

// Template Bolierplate {{{
type scanner struct {
	*bufio.Scanner
}

func NewScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 1024*1024)
	return &scanner{s}
}

func (i *scanner) Next() string {
	i.Scan()
	return i.Text()
}

func (i *scanner) Nexts(n int) []string {
	res := make([]string, n)
	for j := range res {
		res[j] = i.Next()
	}
	return res
}

func (i *scanner) NextInt() int {
	v, _ := strconv.Atoi(i.Next())
	return v
}

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

func (i *scanner) NextInts(n int) []int {
	res := make([]int, n)
	for j := range res {
		res[j] = i.NextInt()
	}
	return res
}

func (i *scanner) NextInt64s(n int) []int64 {
	res := make([]int64, n)
	for j := range res {
		res[j] = i.NextInt64()
	}
	return res
}

type writer struct {
	w *bufio.Writer
}

func NewWriter(w io.Writer) *writer {
	return &writer{bufio.NewWriter(w)}
}

func (i *writer) Print(a ...interface{}) {
	fmt.Fprint(i.w, a...)
}

func (i *writer) Println(a ...interface{}) {
	fmt.Fprintln(i.w, a...)
}

func (i *writer) Printf(format string, a ...interface{}) {
	fmt.Fprintf(i.w, format, a...)
}

func (i *writer) Flush() {
	i.w.Flush()
}

// }}}

// vim: fdm=marker

package main

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

/*
1
5 5
*****
*....
*****
....*
*****
=======
.....
*...*
*****
*****
*****
=======
1
5 5
*****
*....
**o**
....*
*****
*/

//goland:noinspection GoUnhandledErrorResult
func solve() {
	var n, m int
	scanf("%d %d\n", &n, &m)

	grid := make([][]rune, n)

	for i := range grid {
		var s string
		scanf("%s\n", &s)
		grid[i] = []rune(s)
	}

	for col := 0; col < m; col++ {
		for i := n - 1; i >= 0; i-- {
			if grid[i][col] == '.' {
				for j := i - 1; j >= 0; j-- {
					if grid[j][col] == '*' {
						grid[i][col] = '*'
						grid[j][col] = '.'
						break
					} else if grid[j][col] == 'o' {
						i = j
						break
					}
				}
			}
		}
	}

	for _, runes := range grid {
		fmt.Fprintln(writer, string(runes))
	}
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnhandledErrorResult
func factorize(num int) []int {
	factors := []int{1}

	sqrtA := int(math.Sqrt(float64(num)))

	for ftr := 2; ftr <= sqrtA; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > sqrtA {
		factors = append(factors, num)
	}

	return factors
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n, m int
		fmt.Fscan(in, &n, &m)

		grid := make([][]int, n)
		for i := 0; i < n; i++ {
			grid[i] = make([]int, m)
		}

		for i := 0; i < n; i++ {
			var s string
			fmt.Fscan(in, &s)

			for j, ch := range s {
				if ch == '*' {
					grid[i][j] = 1
				} else if ch == 'o' {
					grid[i][j] = -1
				}
			}
		}

		f := true
		for f {
			f = false
			for i := n - 2; i >= 0; i-- {
				for j := 0; j < m; j++ {
					if grid[i][j] == 1 && grid[i+1][j] == 0 {
						grid[i][j] = 0
						grid[i+1][j] = 1
						f = true
					}
				}
			}
		}

		for _, r := range grid {
			for _, v := range r {
				if v == 1 {
					fmt.Fprint(out, "*")
				} else if v == -1 {
					fmt.Fprint(out, "o")
				} else {
					fmt.Fprint(out, ".")
				}
			}
			fmt.Fprintln(out)
		}
		fmt.Fprintln(out)
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func isok(s string) bool {
	b := strings.Count(s, "B")
	rr := strings.Count(s, "R")
	if rr == 0 && b == 0 {
		return true
	} else if rr == 0 || b == 0 {
		return false
	} else {
		return true
	}
}

func slove() {
	defer w.Flush()
	var m, n int
	fmt.Fscan(r, &m, &n)
	grid := make([][]byte, m)
	for i := range grid {
		grid[i] = make([]byte, n)
		var s string
		fmt.Fscan(r, &s)
		for j := range grid[i] {
			grid[i][j] = s[j]
		}
	}
	for j:=0;j<n;j++ {
		cnt := 0
		for i:=0;i<m;i++ {
			if grid[i][j] == '*' {
				cnt++
				grid[i][j] = '.'
			} else if grid[i][j] == 'o' {
				for k:=i-cnt;k<i;k++ {
					grid[k][j] = '*'
				}
				cnt = 0
			}
		}
		for k:=m-cnt;k<m;k++ {
			grid[k][j] = '*'
		}
	}
	for i := range grid {
		fmt.Fprintln(w, string(grid[i]))
	}
}

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

func main() {
	var n int
	fmt.Fscan(r, &n)
	for i:=0;i<n;i++ {
		slove()
	}
}

package main

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

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n, m int
		fmt.Fscan(in, &m, &n)
		nums := make([]string, m)
		for i := 0; i < m; i++ {
			fmt.Fscan(in, &nums[i])
		}
		ans := make([][]byte, m)
		for i := 0; i < m; i++ {
			ans[i] = make([]byte, n)
		}
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if nums[i][j] == 'o' {
					ans[i][j] = nums[i][j]
				}
			}
		}

		for j := 0; j < n; j++ {
			count := 0
			for i := 0; i < m; i++ {
				if nums[i][j] == '*' {
					count++
				}
				if nums[i][j] == 'o' {
					for k := 0; k < count; k++ {
						ans[i-k-1][j] = '*'
					}
					count = 0
				} else if i == m-1 {
					for k := 0; k < count; k++ {
						ans[i-k][j] = '*'
					}
					count = 0
				}
			}
		}
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if ans[i][j] == 0 {
					ans[i][j] = '.'
				}
			}
		}
		for i := 0; i < m; i++ {
			fmt.Fprintln(out, string(ans[i]))
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n ,m int
		Fscan(in, &n,&m)
		a := make([][]byte, n)
		for i := range a {
			Fscan(in, &a[i])
		}

		for j := range a[0] {
			for i := 0;i<n;i++ {
				if a[i][j] == 'o' {
					continue
				}
				c := 0
				for ;i<n && a[i][j] != 'o';i++ {
					if a[i][j] == '*' {
						c++
					}
					a[i][j] = '.'
				}
				for k := i-1;c>0; k-- {
					a[k][j] = '*'
					c--
				}
			}
		}
		for _, s := range a {
			Fprintf(out, "%s\n", s)
		}
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

	leftData, _ := ioutil.ReadAll(in)
	if s := strings.TrimSpace(string(leftData)); s != "" {
		panic("有未读入的数据：\n" + s)
	}

}

func main() { run(os.Stdin, os.Stdout) }

package main

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

const MOD int64 = 1000000007

var n, m int

var grid []string

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

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

func main() {

	read := bufio.NewReader(os.Stdin)

	var t int
	fmt.Fscan(read, &t)

	for i := 0; i < t; i++ {

		fmt.Fscan(read, &n, &m)

		grid = make([]string, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(read, &grid[i])
		}

		solve()
	}
}

type pair struct {
	v int
	idx []int
}

//a b c d

//20 12 -- 4
//4  2  -- 4

func solve()  {

	ans := make([][]byte, n)
	for i := 0; i < n; i++ {
		ans[i] = make([]byte, m)
	}

	for i := 0; i < m ; i++ {

		cnt := 0

		for j := n - 1; j >= 0; j-- {
			if grid[j][i] == '.' {
				cnt++
				ans[j][i] = '.'
			}
			if grid[j][i] == 'o' {
				cnt = 0
				ans[j][i] = 'o'
			}

			if grid[j][i] == '*' {
				ans[j + cnt][i] = '*'
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Print(string(ans[i][j]))
		}
		fmt.Println()
	}
	fmt.Println()
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer, showOrderArray bool) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))

	l, r := 1, n-1
	ans := 0

	for l <= r {
		m := (l + r) / 2

		valid := true

		if n-m <= m {
			valid = false
		} else {
			for i, j := 0, n-m-1; i < m; i, j = i+1, j+1 {
				if x[i] >= x[j] {
					valid = false
					break
				}
			}
		}

		if valid {
			ans = m
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	k := 0
	l = 0
	r = n - ans - 1

	for k < n {
		if r < n {
			ord[k] = x[r]
			k++
			r++
		}

		if l < n-ans-1 {
			ord[k] = x[l]
			k++
			l++
		}
	}

	output.add(out, ans, '\n')

	if showOrderArray {
		for i := 0; i < n-1; i++ {
			output.add(out, ord[i], ' ')
		}
		output.add(out, ord[n-1], '\n')
	}

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout, true)
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

	in := func() int64 {
		sc.Scan()
		i, _ := strconv.ParseInt(sc.Text(), 10, 64)
		return i
	}

	n := in()
	a := make([]int64, n)
	b := make([]int64, n)

	for i := range a {
		a[i] = in()
	}

	sort.Slice(a, func(i, j int) bool {
		return a[i] < a[j]
	})

	var s, c int64 = 1, 0

	var i, j int64

	for j = s; j < n; j += 2 {
		b[j] = a[c]
		c++
	}

	s = 0

	for j = s; j < n; j += 2 {
		b[j] = a[c]
		c++
	}

	c = 0

	for i = 1; i < n-1; i++ {
		if b[i] < b[i-1] && b[i] < b[i+1] {
			c++
		}
	}

	fmt.Println(c)

	for i := range b {
		fmt.Print(b[i], " ")
	}

	fmt.Println()
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 2 * 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer, showOrderArray bool) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))

	l, r := 1, n-1
	ans := 0

	for l <= r {
		m := (l + r) / 2

		valid := true

		if n-m <= m {
			valid = false
		} else {
			for i, j := m-1, n-2; i >= 0; i, j = i-1, j-1 {
				if x[i] >= x[j] {
					valid = false
					break
				}
			}
		}

		if valid {
			ans = m
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	k := 0
	l = 0
	r = n - ans - 1

	for k < n {
		if r < n {
			ord[k] = x[r]
			k++
			r++
		}

		if l < n-ans-1 {
			ord[k] = x[l]
			k++
			l++
		}
	}

	output.add(out, ans, '\n')

	if showOrderArray {
		for i := 0; i < n-1; i++ {
			output.add(out, ord[i], ' ')
		}
		output.add(out, ord[n-1], '\n')
	}

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout, true)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 512 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer, showOrderArray bool) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))

	l, r := 1, n-1
	ans := 0

	for l <= r {
		m := (l + r) / 2

		valid := true

		if n-m <= m {
			valid = false
		} else {
			for i, j := m-1, n-2; i >= 0; i, j = i-1, j-1 {
				if x[i] >= x[j] {
					valid = false
					break
				}
			}
		}

		if valid {
			ans = m
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	k := 0
	l = 0
	r = n - ans - 1

	for k < n {
		if r < n {
			ord[k] = x[r]
			k++
			r++
		}

		if l < n-ans-1 {
			ord[k] = x[l]
			k++
			l++
		}
	}

	output.add(out, ans, '\n')

	if showOrderArray {
		for i := 0; i < n-1; i++ {
			output.add(out, ord[i], ' ')
		}
		output.add(out, ord[n-1], '\n')
	}

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout, true)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer, showOrderArray bool) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))

	l, r := 1, n-1
	ans := 0

	for l <= r {
		m := (l + r) / 2

		valid := true

		if n-m <= m {
			valid = false
		} else {
			for i, j := m-1, n-2; i >= 0; i, j = i-1, j-1 {
				if x[i] >= x[j] {
					valid = false
					break
				}
			}
		}

		if valid {
			ans = m
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	k := 0
	l = 0
	r = n - ans - 1

	for k < n {
		if r < n {
			ord[k] = x[r]
			k++
			r++
		}

		if l < n-ans-1 {
			ord[k] = x[l]
			k++
			l++
		}
	}

	output.add(out, ans, '\n')

	if showOrderArray {
		for i := 0; i < n-1; i++ {
			output.add(out, ord[i], ' ')
		}
		output.add(out, ord[n-1], '\n')
	}

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout, true)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer, showOrderArray bool) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))

	l, r := 1, (n-1)/2
	ans := 0

	for l <= r {
		m := (l + r) / 2

		valid := true

		for i, j := 0, n-m-1; i < m; i, j = i+1, j+1 {
			if x[i] >= x[j] {
				valid = false
				break
			}
		}

		if valid {
			ans = m
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	k := 0
	l = 0
	r = n - ans - 1

	for k < n {
		if r < n {
			ord[k] = x[r]
			k++
			r++
		}

		if l < n-ans-1 {
			ord[k] = x[l]
			k++
			l++
		}
	}

	output.add(out, ans, '\n')

	if showOrderArray {
		for i := 0; i < n-1; i++ {
			output.add(out, ord[i], ' ')
		}
		output.add(out, ord[n-1], '\n')
	}

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout, true)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 256 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer, showOrderArray bool) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))

	l, r := 1, n-1
	ans := 0

	for l <= r {
		m := (l + r) / 2

		valid := true

		if n-m <= m {
			valid = false
		} else {
			for i, j := m-1, n-2; i >= 0; i, j = i-1, j-1 {
				if x[i] >= x[j] {
					valid = false
					break
				}
			}
		}

		if valid {
			ans = m
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	k := 0
	l = 0
	r = n - ans - 1

	for k < n {
		if r < n {
			ord[k] = x[r]
			k++
			r++
		}

		if l < n-ans-1 {
			ord[k] = x[l]
			k++
			l++
		}
	}

	output.add(out, ans, '\n')

	if showOrderArray {
		for i := 0; i < n-1; i++ {
			output.add(out, ord[i], ' ')
		}
		output.add(out, ord[n-1], '\n')
	}

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout, true)
}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	n := rw.NextInt()
	a := rw.NextInts(n)
	sort.Ints(a[:])
	b := make([]int, n)
	var c []int
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			c = append(c, a[i/2+n/2])
		} else {
			b[i] = a[i/2]
		}
	}
	ok := func(m int) bool {
		s := (n-1)/2 - m
		for i := 0; i < m; i++ {
			j := i*2 + 1
			if b[j] >= c[s+i] {
				return false
			}
		}
		return true
	}
	lo, hi := 0, (n-1)/2
	for lo < hi {
		md := (lo + hi + 1) / 2
		if ok(md) {
			lo = md
		} else {
			hi = md - 1
		}
	}
	s := (n-1)/2 - lo
	for i := 0; i < lo+1; i++ {
		b[i*2] = c[s+i]
	}
	for i := lo + 1; i < len(c); i++ {
		b[i*2] = c[i-lo-1]
	}
	rw.Println(lo)
	rw.PrintlnInts(b...)
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	n := readNum(reader)

	A := readNNums(reader, n)

	cnt := solve(n, A)

	var buf bytes.Buffer

	buf.WriteString(fmt.Sprintf("%d\n", cnt))

	for i := 0; i < n; i++ {
		buf.WriteString(fmt.Sprintf("%d ", A[i]))
	}
	buf.WriteByte('\n')
	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(n int, A []int) int {
	sort.Ints(A)

	B := make([]int, n)

	var j int
	for i := 1; i < n; i += 2 {
		B[i] = A[j]
		j++
	}

	k := n - 1
	if k&1 == 1 {
		// B[k] is already filled
		k--
	}

	for i := 0; i <= k; {
		cur := A[j]
		j++
		var ok = true
		if i > 0 && cur == B[i-1] {
			ok = false
		}
		if i+1 < n && cur == B[i+1] {
			ok = false
		}
		if ok {
			B[i] = cur
			i += 2
			continue
		}
		// i not filled
		B[k] = cur
		k -= 2
	}
	var cnt int

	for i := 1; i < n; i += 2 {
		if B[i] < B[i-1] && i+1 < n && B[i] < B[i+1] {
			cnt++
		}
	}
	copy(A, B)

	return cnt
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer, showOrderArray bool) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		x[i], x[j] = x[j], x[i]
	}

	// control used values while going left to right
	used := make([]bool, n)
	l, r := 1, 2
	ans := 0

	ord := make([]int, n)
	ord[0] = x[0]
	k := 1

	for {
		for l < n && used[l] {
			l++
		}

		for r < n && used[r] {
			r++
		}

		for r < n && x[l] == x[r] {
			r++
		}

		if r >= n {
			for k < n {
				ord[k] = x[l]
				used[l] = true
				k++

				if k == n {
					break
				}

				for used[l] {
					l++
				}
			}
			break
		}

		ans++

		ord[k] = x[r]
		used[r] = true
		k++

		ord[k] = x[l]
		used[l] = true
		k++
	}

	output.add(out, ans, '\n')

	if showOrderArray {
		for i := 0; i < n-1; i++ {
			output.add(out, ord[i], ' ')
		}
		output.add(out, ord[n-1], '\n')
	}

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout, true)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		x[i], x[j] = x[j], x[i]
	}

	// two pointers from 1 and n-1 going from sides to the middle
	ord := make([]int, n)
	l, r := 0, n-1
	k := 0

	for l <= r {
		ord[k] = x[l]
		k++
		l++

		if l <= r {
			ord[k] = x[r]
			k++
			r--
		}
	}

	ans := 0
	for i := 1; i < n-1; i++ {
		if ord[i] < ord[i-1] && ord[i] < ord[i+1] {
			ans++
		}
	}

	output.add(out, ans, '\n')

	for i := 0; i < n-1; i++ {
		output.add(out, ord[i], ' ')
	}
	output.add(out, ord[n-1], '\n')

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		x[i], x[j] = x[j], x[i]
	}

	// two pointers from 1 and n-1 going from sides to the middle
	ord := make([]int, n)
	l, r := 0, n-1
	k := 0

	for l <= r {
		ord[k] = x[l]
		k++
		l++

		if l <= r {
			ord[k] = x[r]
			k++
			r--
		}
	}

	ord[0], ord[n-1] = ord[n-1], ord[0]

	ans := 0
	for i := 1; i < n-1; i++ {
		if ord[i] < ord[i-1] && ord[i] < ord[i+1] {
			ans++
		}
	}

	output.add(out, ans, '\n')

	for i := 0; i < n-1; i++ {
		output.add(out, ord[i], ' ')
	}
	output.add(out, ord[n-1], '\n')

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		x[i], x[j] = x[j], x[i]
	}

	// control used values while going left to right
	used := make([]bool, n)

	l, r := 1, 2
	ans := 0
	ord := make([]int, n)
	ord[0] = x[0]
	k := 1

	for {
		for l < n && used[l] {
			l++
		}

		for r < n && (r <= l || used[r]) {
			r++
		}

		for r < n && x[l] == x[r] {
			r++
		}

		if r >= n {
			for k < n {
				ord[k] = x[l]
				k++
				l++

				if k == n {
					break
				}

				for used[l] {
					l++
				}
			}
			break
		}

		ans++

		ord[k] = x[r]
		used[r] = true
		k++

		ord[k] = x[l]
		used[l] = true
		k++
	}

	output.add(out, ans, '\n')

	for i := 0; i < n-1; i++ {
		output.add(out, ord[i], ' ')
	}
	output.add(out, ord[n-1], '\n')

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort
	sort.Sort(spheres(x))

	// get how many x spheres are cheaper than at least x+1 remaining spheres
	l, r := 0, (n/2)-1

	for l <= r {
		m := (l + r + 1) / 2
		good := true

		for i, j := n-1, m; j >= 0; i, j = i-1, j-1 {
			if x[j] >= x[i] {
				good = false
				break
			}
		}

		if good {
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	ans := l
	r = n - 1
	k := 0

	for k < n {
		ord[k] = x[r]
		k++
		r--

		if k < n && l > 0 {
			l--
			ord[k] = x[l]
			k++
		}
	}

	output.add(out, ans, '\n')

	for i := 0; i < n-1; i++ {
		output.add(out, ord[i], ' ')
	}
	output.add(out, ord[n-1], '\n')

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort
	sort.Sort(spheres(x))

	// get how many x spheres are cheaper than at least x+1 remaining spheres
	l, r := 0, (n/2)-1

	for l <= r {
		m := (l + r) / 2
		good := true

		for i, j := n-1, m; j >= 0; i, j = i-1, j-1 {
			if x[j] >= x[i] {
				good = false
				break
			}
		}

		if good {
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	ans := l
	r = n - 1
	k := 0

	for k < n {
		ord[k] = x[r]
		k++
		r--

		if k < n && l > 0 {
			l--
			ord[k] = x[l]
			k++
		}
	}

	output.add(out, ans, '\n')

	for i := 0; i < n-1; i++ {
		output.add(out, ord[i], ' ')
	}
	output.add(out, ord[n-1], '\n')

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		x[i], x[j] = x[j], x[i]
	}

	// two pointers from 1 and ceil(n/2) going from left to right filling ord array
	ord := make([]int, n)
	l, r := 0, (n+1)/2
	k := 0

	for r < n {
		ord[k] = x[l]
		k++
		l++

		ord[k] = x[r]
		k++
		r++
	}

	if k == n-1 {
		ord[k] = x[l]
		k++
	}

	ans := 0
	for i := 1; i < n-1; i++ {
		if ord[i] < ord[i-1] && ord[i] < ord[i+1] {
			ans++
		}
	}

	output.add(out, ans, '\n')

	for i := 0; i < n-1; i++ {
		output.add(out, ord[i], ' ')
	}
	output.add(out, ord[n-1], '\n')

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))
	for i, j := 0, n-1; i < j; i, j = i+1, j-1 {
		x[i], x[j] = x[j], x[i]
	}

	// control used values while going left to right
	used := make([]bool, n)

	l, r := 1, 2
	ans := 0
	ord := make([]int, n)
	ord[0] = x[0]
	used[0] = true
	k := 1

	for {
		for l < n && used[l] {
			l++
		}

		for r < n && used[r] {
			r++
		}

		for r < n && x[l] == x[r] {
			r++
		}

		if r >= n || x[l] == x[r] {
			for k < n {
				ord[k] = x[l]
				used[l] = true
				k++

				for l < n && used[l] {
					l++
				}
			}
			break
		}

		ans++

		ord[k] = x[r]
		used[r] = true
		k++

		ord[k] = x[l]
		used[l] = true
		k++
	}

	output.add(out, ans, '\n')

	for i := 0; i < n-1; i++ {
		output.add(out, ord[i], ' ')
	}
	output.add(out, ord[n-1], '\n')

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
	"sort"
)

func processInput(in io.Reader) (int, []int) {
	buf, _ := ioutil.ReadAll(in)

	var i, n int
	for ; buf[i] >= '0' && buf[i] <= '9'; i++ {
		n = (n * 10) + int(buf[i]&15)
	}

	ints := make([]int, n)
	l := len(buf)

	for j := 0; j < n; j++ {
		for ; buf[i] < '0' || buf[i] > '9'; i++ {
		}

		for ; i < l && buf[i] >= '0' && buf[i] <= '9'; i++ {
			ints[j] = (ints[j] * 10) + int(buf[i]&15)
		}
	}

	return n, ints
}

type spheres []int

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

const _B int = 1024 * 1024

type buffer struct {
	i   int
	sz  int
	arr []byte
}

var output = &buffer{
	sz:  _B,
	arr: make([]byte, _B),
}

func (b *buffer) add(out io.Writer, x int, delimiter byte) {
	temp := make([]byte, 10)
	l := 0
	if x == 0 {
		temp[l] = '0'
		l++
	}
	for x > 0 {
		temp[l] = byte(x%10) + '0'
		x /= 10
		l++
	}
	for i := l - 1; i >= 0; i-- {
		b.arr[b.i] = temp[i]
		b.i++
	}
	b.arr[b.i] = delimiter
	b.i++
	if b.i > b.sz-20 {
		b.flush(out)
	}
}

func (b *buffer) flush(out io.Writer) {
	if b.i > 0 {
		out.Write(b.arr[:b.i])
		b.i = 0
	}
}

// Solution solves cf 1419 d2
func Solution(in io.Reader, out io.Writer, showOrderArray bool) {

	// 1 <= n <= 1e5
	// 1 <= a1..an <= 1e9
	n, x := processInput(in)

	// sort descending
	sort.Sort(spheres(x))

	l, r := 1, n-1
	ans := 0

	for l <= r {
		m := (l + r) / 2

		valid := true

		if n-m <= m {
			valid = false
		} else {
			for i, j := 0, n-m-1; i < m; i, j = i+1, j+1 {
				if x[i] >= x[j] {
					valid = false
					break
				}
			}
		}

		if valid {
			ans = m
			l = m + 1
		} else {
			r = m - 1
		}
	}

	ord := make([]int, n)
	k := 0
	l = 0
	r = ans

	for k < n {
		if r < n {
			ord[k] = x[r]
			k++
			r++
		}

		if l < ans {
			ord[k] = x[l]
			k++
			l++
		}
	}

	output.add(out, ans, '\n')

	if showOrderArray {
		for i := 0; i < n-1; i++ {
			output.add(out, ord[i], ' ')
		}
		output.add(out, ord[n-1], '\n')
	}

	output.flush(out)
}

func main() {
	Solution(os.Stdin, os.Stdout, true)
}


package main

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

var scanner = bufio.NewScanner(os.Stdin)

func readInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func readWord() string {
	scanner.Scan()
	return scanner.Text()
}

func findCommon(a, b []int) bool {
	e1, e2 := 0, 0
	for e1 < len(a) && e2 < len(b) {
		if a[e1] == b[e2] {
			return true
		} else if a[e1] < b[e2] {
			e1++
		} else {
			e2++
		}
	}
	return false
}

func main() {
	scanner.Split(bufio.ScanWords)

	m, _ := readInt(), readInt()
	days := make([][]int, m)
	for i := 0; i < m; i++ {
		k := readInt()
		days[i] = make([]int, k)
		for j := 0; j < k; j++ {
			t := readInt()
			days[i][j] = t
		}
		sort.Ints(days[i])
	}

	for i := 0; i < m; i++ {
		for j := i + 1; j < m; j++ {
			if !findCommon(days[i], days[j]) {
				fmt.Println("impossible")
				return
			}
		}
	}

	fmt.Println("possible")
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1166E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var m, n, v int
	Fscan(in, &m, &n)
	a := make([][]bool, m)
	for i := range a {
		a[i] = make([]bool, n+1)
		for Fscan(in, &m); m > 0; m-- {
			Fscan(in, &v)
			a[i][v] = true
		}
	}
	for i, vs := range a {
	o:
		for _, ws := range a[i+1:] {
			for j, v := range vs {
				if v && ws[j] {
					continue o
				}
			}
			Fprint(out, "impossible")
			return
		}
	}
	Fprint(out, "possible")
}

func main() { CF1166E(os.Stdin, os.Stdout) }

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1166E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, v int
	Fscan(in, &n, &m)
	a := make([]int64, n)
	for i := range a {
		for Fscan(in, &m); m > 0; m-- {
			Fscan(in, &v)
			a[i] |= int64(1) << v
		}
	}
	for i, v := range a {
		for _, w := range a[i+1:] {
			if v&w == 0 {
				Fprint(out, "impossible")
				return
			}
		}
	}
	Fprint(out, "possible")
}

func main() { CF1166E(os.Stdin, os.Stdout) }

package main

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

var scanner = bufio.NewScanner(os.Stdin)

func readInt() int {
	scanner.Scan()
	n, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func readWord() string {
	scanner.Scan()
	return scanner.Text()
}

func main() {
	scanner.Split(bufio.ScanWords)

	m, _ := readInt(), readInt()
	days := make([][]int, m)
	freq := make(map[int]int)
	for i := 0; i < m; i++ {
		k := readInt()
		days[i] = make([]int, k)
		for j := 0; j < k; j++ {
			t := readInt()
			days[i][j] = t
			freq[t]++
		}
	}

	for i := 0; i < m; i++ {
		valid := false
		for j := 0; j < len(days[i]); j++ {
			if freq[days[i][j]] > 1 {
				valid = true
				break
			}
		}
		if !valid {
			fmt.Println("impossible")
			return
		}
	}
	fmt.Println("possible")
}


package main

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

func main() {
	var n int
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
    	fmt.Scan(&n)
	a:=make([]int,n)

	for i:=0;i<n;i++ {
		input.Scan();
       		aa, _ := strconv.Atoi(input.Text());
		a[i]=aa
	}
	//sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sort.Ints(a)
	//for _,v:=range a {
		//fmt.Println(v)
	//}
	var ans int64
	var x int
	ans=0
	for i:=0;i<n;i++ {
		if (i+1-a[i])<0 {
			x=(i+1-a[i])*(-1)
		} else {
			x=(i+1-a[i])
		}
		ans+=int64(x)
	}
	fmt.Println(ans)
}

package main

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	rdr := bufio.NewReader(os.Stdin)
	var n, i int
	fmt.Fscan(rdr, &n)
	a := make([]int, n)
	for i = 0; i < n; i++ {
		fmt.Fscan(rdr, &a[i])
	}
	sort.Ints(a)
	var result int64
	for i = 1; i <= n; i++ {
		result += int64(abs(i - a[i-1]))
	}
	fmt.Print(result)
}

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
	}

	merge_sort(array, 0, n-1)

	moves := int64(0)
	for i := 0; i < n; i++ {
		moves += int64(abs(array[i] - i - 1))
	}
	fmt.Println(moves)
}

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    var ans int64 = 0
    for i := 0; i < n; i++ {
        ans += int64(math.Abs(float64(a[i]-(i+1))))
    }
    fmt.Println(ans)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const maxCapacity = 1024 * 4096
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	numbers := make([]int, n)
	input := scanner.Text()
	for i, s := range strings.Split(input, " ") {
		numbers[i], _ = strconv.Atoi(s)
	}

	sort.Ints(numbers)
	var result int64
	for i, x := range numbers {
		result += int64(abs(x - (i + 1)))
	}

	fmt.Println(result)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const maxCapacity = 1024 * 8192
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	numbers := make([]int, n)
	input := scanner.Text()
	for i, s := range strings.Split(input, " ") {
		numbers[i], _ = strconv.Atoi(s)
	}

	sort.Ints(numbers)
	var result int64
	for i, x := range numbers {
		result += int64(abs(x - (i + 1)))
	}

	fmt.Println(result)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

// 285C-mic
package main

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

func main() {
    writer := bufio.NewScanner(os.Stdin)
    writer.Split(bufio.ScanWords)
    var n int
    var res int64
    fmt.Scan(&n)
    m := make([]float64, n)
    for i := 0; i < n; i++ {
        writer.Scan()
        m[i], _ = strconv.ParseFloat(writer.Text(), 64)
    }

    sort.Sort(sort.Float64Slice(m))

    for i := 1; i <= n; i++ {
        res += int64(math.Abs(float64(m[i-1] - float64(i))))
    }

    fmt.Println(res)

}

package main

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

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	rdr := bufio.NewReader(os.Stdin)
	var n, i int64
	fmt.Fscan(rdr, &n)
	a := make([]int64, n)
	for i = 0; i < n; i++ {
		fmt.Fscan(rdr, &a[i])
	}
	sort.Slice(a, func(i, j int) bool {
		return a[i] < a[j]
	})
	var result int64
	for i = 1; i <= n; i++ {
		result += abs(i - a[i-1])
	}
	fmt.Print(result)
}

package main

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	rdr := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(rdr, &n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(rdr, &a[i])
	}
	sort.Ints(a)
	var result int
	for i := 1; i <= n; i++ {
		result += abs(i - a[i-1])
	}
	fmt.Print(result)
}

package main

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

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	array := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < n && scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		array[i] = a
	}

	merge_sort(array, 0, n-1)

	moves := 0
	for i := 0; i < n; i++ {
		moves += abs(array[i] - i - 1)
	}
	fmt.Println(moves)
}

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	numbers := make([]int, n)
	for i, s := range strings.Split(scanner.Text(), " ") {
		numbers[i], _ = strconv.Atoi(s)
	}

	sort.Ints(numbers)
	var result int64
	for i, x := range numbers {
		result += int64(abs(x - (i + 1)))
	}

	fmt.Println(result)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	numbers := make([]int, n)
	input := scanner.Text()
	for i, s := range strings.Split(input, " ") {
		numbers[i], _ = strconv.Atoi(s)
	}

	sort.Ints(numbers)
	var result int64
	for i, x := range numbers {
		result += int64(abs(x - (i + 1)))
	}

	fmt.Println(result)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const maxCapacity = 512 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	numbers := make([]int, n)
	input := scanner.Text()
	fmt.Println(len(strings.Split(input, " ")))
	for i, s := range strings.Split(input, " ") {
		numbers[i], _ = strconv.Atoi(s)
	}

	sort.Ints(numbers)
	var result int64
	for i, x := range numbers {
		result += int64(abs(x - (i + 1)))
	}

	fmt.Println(result)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	numbers := make([]int, n)
	for i, s := range strings.Split(scanner.Text(), " ") {
		numbers[i], _ = strconv.Atoi(s)
	}

	sort.Ints(numbers)
	var result int64
	for i, x := range numbers {
		result += int64(math.Abs(float64(x - (i + 1))))
	}

	fmt.Println(result)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	numbers := make([]int64, n)
	for i, s := range strings.Split(scanner.Text(), " ") {
		numbers[i], _ = strconv.ParseInt(s, 0, 64)
	}

	sort.Slice(numbers, func(i, j int) bool {
		return numbers[i] < numbers[j]
	})
	var result int64
	for i, x := range numbers {
		result += abs(x - (int64(i) + 1))
	}

	fmt.Println(result)
}

func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	const maxCapacity = 512 * 1024
	buf := make([]byte, maxCapacity)
	scanner.Buffer(buf, maxCapacity)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	numbers := make([]int, n)
	input := scanner.Text()
	for i, s := range strings.Split(input, " ") {
		numbers[i], _ = strconv.Atoi(s)
	}

	sort.Ints(numbers)
	var result int64
	for i, x := range numbers {
		result += int64(abs(x - (i + 1)))
	}

	fmt.Println(result)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

// 285C-mic
package main

import (
    "fmt"
    "math"
    "sort"
)

func main() {
    var n int
    var res int
    fmt.Scan(&n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }

    sort.Sort(sort.IntSlice(a))

    for i := 1; i <= n; i++ {
        res += int(math.Abs(float64(a[i-1] - (i))))
    }

    fmt.Println(res)

}