You are given a number $$$k$$$ and a string $$$s$$$ of length $$$n$$$, consisting of the characters '.' and '*'. You want to replace some of the '*' characters with 'x' characters so that the following conditions are met:   The first character '*' in the original string should be replaced with 'x';  The last character '*' in the original string should be replaced with 'x';  The distance between two neighboring replaced characters 'x' must not exceed $$$k$$$ (more formally, if you replaced characters at positions $$$i$$$ and $$$j$$$ ($$$i < j$$$) and at positions $$$[i+1, j-1]$$$ there is no "x" symbol, then $$$j-i$$$ must be no more than $$$k$$$). For example, if $$$n=7$$$, $$$s=$$$.**.*** and $$$k=3$$$, then the following strings will satisfy the conditions above:   .xx.*xx;  .x*.x*x;  .xx.xxx.  But, for example, the following strings will not meet the conditions:   .**.*xx (the first character '*' should be replaced with 'x');  .x*.xx* (the last character '*' should be replaced with 'x');  .x*.*xx (the distance between characters at positions $$$2$$$ and $$$6$$$ is greater than $$$k=3$$$). Given $$$n$$$, $$$k$$$, and $$$s$$$, find the minimum number of '*' characters that must be replaced with 'x' in order to meet the above conditions.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 500$$$). Then $$$t$$$ test cases follow. The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 50$$$). The second line of each test case contains a string $$$s$$$ of length $$$n$$$, consisting of the characters '.' and '*'. It is guaranteed that there is at least one '*' in the string $$$s$$$. It is guaranteed that the distance between any two neighboring '*' characters does not exceed $$$k$$$.

For each test case output the minimum number of '*' characters that must be replaced with 'x' characters in order to satisfy the conditions above.

package main

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

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

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

		var n int = 0
		var k int = 0
		scanf("%d %d\n", &n, &k)
		var s string
		scanf("%s\n", &s)

		res := make([]int, n)
		var index int = 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				res[i] = 1
				index = i
				break
			}
		}

		for i := index+1; i < n; i++ {

			var max_index = -1

			for j := i; j <= min_int(n-1, i+k-1); j++ {
				if s[j] == '*' {
					max_index = j
				}
			}

			if max_index != -1 {
				res[max_index] = 1
				i = max_index
			}
		}

		for i := n-1; i >= 0; i-- {
			if s[i] == '*' && res[i] == 1 {
				break
			}

			if s[i] == '*' {
				res[i] = 1
				index = i
				break
			}
		}

		var ans int = 0
		for i := 0; i < n; i++ {
			if res[i] == 1 {
				ans = ans + 1
			}
		}
		printf("%d\n", ans)

	}

}

package main

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

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

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

		var n int = 0
		var k int = 0
		scanf("%d %d\n", &n, &k)
		var s string
		scanf("%s\n", &s)

		res := make([]int, n)
		var index int = 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				res[i] = 1
				index = i
				// printf("index: %d\n", index)
				break
			}
		}

		for i := index+1; i < n; i++ {
			// printf("I: %d\n", i)

			var max_index = -1

			// printf("up to: %d\n", min_int(n-1, i+k-1))
			for j := i; j <= min_int(n-1, i+k-1); j++ {
				if s[j] == '*' {
					// printf("-------> j: %d\n", j)
					max_index = j
				}
			}

			if max_index != -1 {
				// printf("setting: %d\n", max_index)
				res[max_index] = 1
				i = max_index
			}
			// printf("New index: %d\n", i)
		}

		for i := n-1; i >= 0; i-- {
			if s[i] == '*' && res[i] == 1 {
				break
			}

			if s[i] == '*' {
				// printf("--> setting: %d\n", i)
				res[i] = 1
				index = i
				break
			}
		}

		var ans int = 0
		for i := 0; i < n; i++ {
			if res[i] == 1 {
				ans = ans + 1
			}
			// printf("%d ", res[i])
		}
		// printf("\n")
		printf("%d\n", ans)

	}

}

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, k int
		var s []byte
		Fscan(in, &n, &k, &s)

		ans := 1
		start := bytes.Index(s, []byte{'*'})
		end := bytes.LastIndex(s, []byte{'*'})
		if start != end {
			ans = 2
		}
		for i := start; i + k < end; {
			i += bytes.LastIndex(s[i+1:i+k+1], []byte{'*'}) + 1
			ans++
		}
		Fprintln(out, ans)

	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

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

package main

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

func main() {

	input := bufio.NewReader(os.Stdin)
	var testCases int
	fmt.Fscan(input, &testCases)

	for testCases > 0 {
		testCases--
		var str1 string
		var n, k int
		result := 1
		fmt.Fscan(input, &n, &k, &str1)
		i := getFirstStarIndex(str1)
		for 0 < 1 {
			j := min(i + k, n - 1)
			for ; i < j && str1[j] == '.'; j-- {}
			if i == j {
				break
			}
			result++
			i = j
		}
		fmt.Println(result)
	}
}

func getFirstStarIndex(str string) int {
	for i, char := range str {
		if char == '*' {
			return  i
		}
	}
	return 0
}

func min(arg1 int, rest ...int) int {
	curr := arg1
	for _, num := range rest {
		if num < curr {
			curr = num
		}
	}
	return curr
}

package main

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

func main() {

	input := bufio.NewReader(os.Stdin)
	var testCases int
	fmt.Fscan(input, &testCases)

	for testCases > 0 {
		testCases--
		var str1 string
		var n, k int
		result := 1
		fmt.Fscan(input, &n, &k, &str1)
		i := getFirstStarIndex(str1)
		println(i)
		for 0 < 1 {
			j := min(i + k, n - 1)
			for ; i < j && str1[j] == '.'; j-- {}
			if i == j {
				break
			}
			result++
			i = j
		}
		fmt.Println(result)
	}
}

func getFirstStarIndex(str string) int {
	for i, char := range str {
		if char == '*' {
			return  i
		}
	}
	return 0
}

func min(arg1 int, rest ...int) int {
	curr := arg1
	for _, num := range rest {
		if num < curr {
			curr = num
		}
	}
	return curr
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, k := getI(), getI()
	s := []rune(getS())

	first := int64(-1)
	last := int64(-1)

	for i := int64(0); i < n; i++ {
		if s[i] == '*' {
			if first == -1 {
				first = i
			}
			last = i
		}
	}

	if first == last {
		out(1)
		return
	}

	cur := first
	count := 2
	for i := first + k; i < last-k; i += k {
		if s[i] == '*' {
			cur = i
			s[i] = 'x'
			count++
		} else {
			i--
			for s[i] != '*' {
				i--
			}
			cur = i
			s[i] = 'x'
			count++
		}
	}

	for i := last - k; i > cur; i -= k {
		if s[i] == '*' {
			s[i] = 'x'
			count++
		} else {
			i++
			for s[i] != '*' {
				i++
			}
			s[i] = 'x'
			count++
		}
	}

	out(count)
}

// http://github.com/KadoBOT (me@ricardoambrogi.com)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!
func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func ceil(n, d int64) int64 {
	return (n + d - 1) / d
}

func nsort(data ...int64) []int64 {
	sort.SliceStable(data, func(i, j int) bool { return data[i] < data[j] })
	return data
}

func nsorti(data ...int64) []int64 {
	idxs := make([]int64, len(data))
	for i := 0; i < len(data); i++ {
		idxs[i] = int64(i)
	}

	sort.SliceStable(idxs, func(i, j int) bool { return data[idxs[i]] < data[idxs[j]] })
	return idxs
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// !------- FORMULAS -------!
func gcd(a, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func lcm(a, b int64, integers ...int64) int64 {
	result := a * b / gcd(a, b)

	for i := 0; i < len(integers); i++ {
		result = lcm(result, integers[i])
	}

	return result
}

func sieve(n int64) []int64 {
	integers := make([]bool, n+1)
	for i := int64(2); i < n+1; i++ {
		integers[i] = true
	}

	for p := int64(2); p*p <= n; p++ {
		if integers[p] == true {
			for i := p * 2; i <= n; i += p {
				integers[i] = false
			}
		}
	}

	var primes []int64
	for p := int64(2); p <= n; p++ {
		if integers[p] == true {
			primes = append(primes, p)
		}
	}

	return primes
}

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, k int
		fmt.Fscan(in, &n, &k)

		var s string
		fmt.Fscan(in, &s)

		arr := []int{}
		for i, ch := range s {
			if ch == '*' {
				arr = append(arr, i)
			}
		}

		tally := 1
		for i := 0; i < len(arr)-1; {
			var pos int
			for j := i + 1; j < len(arr); j++ {
				if arr[j]-arr[i] > k {
					break
				}
				pos = j
			}

			tally++
			i = pos
		}
		fmt.Fprintln(out, tally)
	}
}

package main

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

func readLine(in *bufio.Reader) string {
    ret, _, err := in.ReadLine()

    if err == io.EOF {
        return ""
    }

    return strings.TrimRight(string(ret), "\r\n")
}

func parseInt(in string) int {
    ret, _ := strconv.ParseInt(in, 10, 64)
    return int(ret)
}

func split(in string) []string {
    return strings.Split(in, " ")
}

func main() {
    in := bufio.NewReaderSize(os.Stdin, 1024*1024)
    out := bufio.NewWriter(os.Stdout)

    defer out.Flush()

    for t := parseInt(readLine(in)); t > 0; t-- {
        run(in, out)
    }
}

func run(in io.Reader, out io.Writer) {
    /* ----------------------------------------------------
     * NOTE: Solution 1506B
     *
     * @author      : Hung Nguyen Xuan Pham (hung0913208@gmail.com)
     * @created     : Sunday Nov 28, 2021 17:27:06 +07
     * @filename    : 1506B
     * ----------------------------------------------------- */
    var n, k, cnt int
    var s string

    fmt.Fscan(in, &n, &k, &s)

    i := strings.Index(s, "*")
    if i >= 0 {
        cnt = 1
    } else {
        cnt = 0
    }

    for i >= 0 {
        var j int

        for j = min(n - 1, i + k); j > i; j-- {
            if s[j] != '.' {
                break
            }
        }

        if i == j {
            break
        }

        cnt++
        i = j
    }

    fmt.Fprintln(out, cnt)
}

func min(l, r int) int {
    if l < r {
        return l
    } else {
        return r
    }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for t > 0 {
		t--
		var n, k int
		var s string
		fmt.Fscan(in, &n, &k, &s)
		v := []int{}
		for i, c := range s {
			if c == '*' {
				v = append(v, i)
			}
		}
		res := 1
		if len(v) > 1 {
			res = 2
		}
		last := v[0]
		for i := 1; i < len(v); i++ {
			if v[i] - last > k {
				last = v[i-1]
				res++
			}
		}
		fmt.Println(res)
	}
}

package main

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

const N int = 2000

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

	var T int
	for Fscan(in, &T); T > 0; T-- {
		var k, n int
		var s []byte
		Fscan(in, &n, &k, &s)
		// Fix first one
		firstPos := -1
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				firstPos = i
				s[i] = 'x'
				break
			}
		}
		if firstPos == -1 {
			Fprint(out, 0)
			continue
		}

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

		// span from firstPos out
		pos := firstPos
		count := 1
		for {
			// Fprintf(out, "%s pos = %d\n", s, pos)
			changed := false
			for i := min(pos+k, n-1); i > pos; i-- {
				// Fprintf(out, "i = %d, s[i] = %c\n", i, s[i])
				if s[i] == '*' {
					s[i] = 'x'
					changed = true
					pos = i
					count++
					break
				}
			}
			if !changed {
				break
			}
		}
		Fprintln(out, count)
	}

}

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

package main

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

type Scanner struct {
	bScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bScanner := bufio.NewScanner(os.Stdin)
	bScanner.Split(bufio.ScanWords)
	bScanner.Buffer([]byte{}, math.MaxInt32)
	return &Scanner{
		bScanner,
	}
}

func (s *Scanner) next() string {
	s.bScanner.Scan()
	return s.bScanner.Text()
}

func (s *Scanner) nextInt() int {
	s.bScanner.Scan()
	res, err := strconv.Atoi(s.bScanner.Text())
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInt64() int64 {
	s.bScanner.Scan()
	res, err := strconv.ParseInt(s.bScanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextFloat() float64 {
	s.bScanner.Scan()
	res, err := strconv.ParseFloat(s.bScanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (s *Scanner) nextInts(N int) []int {
	res := make([]int, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextInt64s(N int) []int64 {
	res := make([]int64, N)
	for i := 0; i < N; i++ {
		res[i] = s.nextInt64()
	}
	return res
}

func min(nums ...int) int {
	ans := math.MaxInt32
	for _, num := range nums {
		if num < ans {
			ans = num
		}
	}
	return ans
}

func max(nums ...int) int {
	ans := math.MinInt32
	for _, num := range nums {
		if num > ans {
			ans = num
		}
	}
	return ans
}

func main() {
	sc := NewScanner()
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	TC := sc.nextInt()
	for tc := 0; tc < TC; tc++ {
		N := sc.nextInt()
		K := sc.nextInt()
		str := sc.next()

		replacePos := make([]int, 0)
		for i := 0; i < N; i++ {
			if str[i] == '*' {
				if len(replacePos) < 2 {
					replacePos = append(replacePos, i)
				} else {
					if i-replacePos[len(replacePos)-2] <= K {
						replacePos[len(replacePos)-1] = i
					} else {
						replacePos = append(replacePos, i)
					}
				}
			}
		}
		fmt.Fprintln(wr, len(replacePos))
	}
}

package main
import "fmt"

func solve(s* string, k int) int {
	idx := make([]int, 0, len(*s))
	for i, el := range(*s) {
		if (el == '*') {
			idx = append(idx, i)
		}
	}

	var i,j,res int = 0,0,1
	for i != len(idx) - 1 {
		for (j < len(idx) && idx[j] - idx[i] <= k) {
			j++
		}
		res++
		i = j - 1
	}
	return res
}

func main() {
	var t,n,k int
	var s string
	fmt.Scan(&t)
	for i := 1; i <= t; i++ {
		fmt.Scan(&n,&k)
		fmt.Scan(&s)
		fmt.Println(solve(&s, k))
	}
}

// Package main provides ...
package main

import (
	"fmt"
	"strings"
)

func main() {
	var t int
	fmt.Scan(&t)
	for j := 0; j < t; j++ {
		var st string
		var n, k int
		fmt.Scan(&n, &k)
		fmt.Scan(&st)
		st = strings.Trim(st, ".")
		if len(st) == 1 {
			fmt.Println(1)
			continue
		}
		i := 0
		rs := 0
		for ; i < len(st); i += k {
			for ; st[i] != '*'; i-- {
			}
			rs++
		}
		if i < len(st)+k-1 {
			rs++
		}
		fmt.Println(rs)
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

func MIN(x, y int64) int64 {
	if x > y {
		return y
	} else {
		return x
	}
}

func MKO(x, y int) int {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

func MAX(x, y int) int {
	if x > y {
		return x
	} else {
		return y
	}
}

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })
var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)

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

		var n, k int

		fmt.Fscan(input, &n)
		fmt.Fscan(input, &k)
		STRING := make([]byte, 0)
		fmt.Fscan(input, &STRING)
		NNN := make([]int, 0)
		for i := 0; i < n; i++ {
			if string(STRING[i]) == "*" {
				NNN = append(NNN, i+1)
			}
		}

		answer := 1
		l := len(NNN)
		begin := NNN[0]
		for i := 1; i < l; i++ {
			if NNN[i]-begin > k {
				answer++
				begin = NNN[i-1]

			}
		}

		if begin != NNN[l-1] {
			answer++
		}
		fmt.Println(answer)

	}

}

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.Fscanf(in, "%d\n", &T)
	for t := 0; t < T; t++ {
		var n int
		var k int
		var s string

		fmt.Fscanf(in, "%d %d\n", &n, &k)
		fmt.Fscanf(in, "%s\n", &s)

		ans := 0

		i := 0
		for i < len(s) {
			if s[i] == '.' {
				i++
				continue
			}
			ans++
			t := k
			for i+t >= len(s) {
				t--
			}
			for t > 0 && i+t < len(s) && s[i+t] != '*' {
				t--
			}
			if t == 0 {
				break
			}
			i += t
		}

		fmt.Fprintf(out, "%v\n", ans)
	}
}

package main

import (
	"bufio"
	"bytes"
	. "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, k int
		var s []byte
		Fscan(in, &n, &k, &s)
		t := append([]byte(nil), s...)
		i, j := bytes.IndexByte(s, '*'), bytes.LastIndexByte(s, '*')
		t[i] = 'x'
		t[j] = 'x'
		pre := i
		for {
			nxt := pre + k
			if nxt >= j {
				break
			}
			if nxt == '*' {
				t[nxt] = 'x'
				pre = nxt
			} else {
				for ; t[nxt] != '*'; nxt-- {
				}
				t[nxt] = 'x'
				pre = nxt
			}
		}
		ans := 0
		for i, b := range s {
			if b != t[i] {
				ans++
			}
		}
		Fprintln(out, ans)
	}

	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"
)

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

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

		var n int = 0
		var k int = 0
		scanf("%d %d\n", &n, &k)
		var s string
		scanf("%s\n", &s)

		res := make([]int, n)
		var index int = 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				res[i] = 1
				index = i
				// printf("index: %d\n", index)
				break
			}
		}

		for i := index; i < n; i++ {
			// printf("I: %d\n", i)

			var max_index = -1

			for j := i; j <= min_int(n-1, i+k); j++ {
				if s[j] == '*' {
					// printf("j: %d\n", j)
					max_index = j
				}
			}

			// printf("max_index: %d\n", max_index)
			if max_index != -1 {
				res[max_index] = 1
			}
			i = i + k - 1
		}

		for i := n-1; i >= 0; i-- {
			if s[i] == '*' && res[i] == 1 {
				break
			}

			if s[i] == '*' {
				res[i] = 1
				index = i
				break
			}
		}

		var ans int = 0
		for i := 0; i < n; i++ {
			if res[i] == 1 {
				ans = ans + 1
			}
			// printf("%d ", res[i])
		}
		// printf("\n")
		printf("%d\n", ans)

	}

}

package main

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

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

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

		var n int = 0
		var k int = 0
		scanf("%d %d\n", &n, &k)
		var s string
		scanf("%s\n", &s)

		res := make([]int, n)
		var index int = 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				res[i] = 1
				index = i
				// printf("index: %d\n", index)
				break
			}
		}

		for i := index; i < n; i++ {
			// printf("I: %d\n", i)

			var max_index = i

			for j := i; j <= min_int(n-1, i+k); j++ {
				if s[j] == '*' {
					max_index = j
				}
			}

			// printf("max_index: %d\n", max_index)
			res[max_index] = 1
			i = i + k - 1
		}

		for i := n-1; i >= 0; i-- {
			if s[i] == '*' && res[i] == 1 {
				break
			}

			if s[i] == '*' {
				res[i] = 1
				index = i
				break
			}
		}

		var ans int = 0
		for i := 0; i < n; i++ {
			if res[i] == 1 {
				ans = ans + 1
			}
			// printf("%d ", res[i])
		}
		// printf("\n")
		printf("%d\n", ans)

	}

}

package main

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

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

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

		var n int = 0
		var k int = 0
		scanf("%d %d\n", &n, &k)
		var s string
		scanf("%s\n", &s)

		res := make([]int, n)
		var index int = 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				res[i] = 1
				index = i
				// printf("index: %d\n", index)
				break
			}
		}

		for i := index; i < n; i++ {
			// printf("I: %d\n", i)
			for j := min_int(n - 1, i + k); j >= i; j-- {
				if s[j] == '*' {
					// printf("-> j: %d\n", j)
					res[j] = 1
					i = i + k - 1
					break
				}
			}
		}

		for i := n-1; i >= 0; i-- {
			if s[i] == '*' && res[i] == 1 {
				break
			}

			if s[i] == '*' {
				res[i] = 1
				index = i
				break
			}
		}

		var ans int = 0
		for i := 0; i < n; i++ {
			if res[i] == 1 {
				ans = ans + 1
			}
			// printf("%d ", res[i])
		}
		// printf("\n")
		printf("%d\n", ans)

	}

}

package main

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

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

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

		var n int = 0
		var k int = 0
		scanf("%d %d\n", &n, &k)
		var s string
		scanf("%s\n", &s)

		res := make([]int, n)
		var index int = 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				res[i] = 1
				index = i
				// printf("index: %d\n", index)
				break
			}
		}

		for i := index; i < n; i++ {
			// printf("I: %d\n", i)
			for j := min_int(n - 1, i + k); j > i; j-- {
				if s[j] == '*' {
					// printf("-> j: %d\n", j)
					res[j] = 1
					i = i + k - 1
					break
				}
			}
		}

		for i := n-1; i >= 0; i-- {
			if s[i] == '*' && res[i] == 1 {
				break
			}

			if s[i] == '*' {
				res[i] = 1
				index = i
				break
			}
		}

		var ans int = 0
		for i := 0; i < n; i++ {
			if res[i] == 1 {
				ans = ans + 1
			}
			// printf("%d ", res[i])
		}
		// printf("\n")
		printf("%d\n", ans)

	}

}

package main

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

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 min_int(a int, b int) int { if a < b { return a } else { return b } }
func min_int64(a int64, b int64) int64 { if a < b { return a } else { return b } }

func max_int(a int, b int) int { if a > b { return a } else { return b } }
func max_int64(a int64, b int64) int64 { if a > b { return a } else { return b } }

func main() {
	defer writer.Flush()

	var T int = 0
	scanf("%d\n", &T)

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

		var n int = 0
		var k int = 0
		scanf("%d %d\n", &n, &k)
		var s string
		scanf("%s\n", &s)

		res := make([]int, n)
		var index int = 0
		for i := 0; i < n; i++ {
			if s[i] == '*' {
				res[i] = 1
				index = i
				break
			}
		}

		for i := index; i < n; i++ {
			for j := min_int(n - 1, i + k); j > i; j-- {
				if s[j] == '*' {
					res[j] = 1
					i = i + k + 1
					break
				}

			}
		}

		for i := n-1; i >= 0; i-- {
			if s[i] == '*' && res[i] == 1 {
				break
			}

			if s[i] == '*' {
				res[i] = 1
				index = i
				break
			}
		}

		var ans int = 0
		for i := 0; i < n; i++ {
			if res[i] == 1 {
				ans = ans + 1
			}

			// printf("%d ", res[i])
		}
		printf("%d\n", ans)

	}

}

package main

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

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

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var n, k int
		var s []byte
		Fscan(in, &n, &k, &s)

		ans := 1
		start := bytes.Index(s, []byte{'*'})
		end := bytes.LastIndex(s, []byte{'*'})
		if start != end {
			ans = 2
		}
		ans += max(0, (end - start - 1) / k)
		Fprintln(out, ans)

	}
}

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

func decomposition(n int) []int {
	var res []int
	for p := 2; n >= p * p;  {
		if n % p == 0 {
			res = append(res, p)
			n /= p
		} else {
			p++
		}
	}
	if n > 1 {
		res = append(res, n)
	}
	return res
}

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

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func solve() {
	n, m, x := getI(), getI(), getI()
	var row int64
	var col int64

	row = x % n
	col = ceil(x, n)

	if row == 0 {
		row = n
	}

	out(row*m - m + col)
}

// http://github.com/KadoBOT (me@ricardoambrogi.com)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	for i := getI(); i > 0; i-- {
		solve()
	}
	out()
}

// !------- HELPERS -------!
func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func ceil(n, d int64) int64 {
	return (n + d - 1) / d
}

func nsort(data ...int64) []int64 {
	sort.SliceStable(data, func(i, j int) bool { return data[i] < data[j] })
	return data
}

func nsorti(data ...int64) []int64 {
	idxs := make([]int64, len(data))
	for i := 0; i < len(data); i++ {
		idxs[i] = int64(i)
	}

	sort.SliceStable(idxs, func(i, j int) bool { return data[idxs[i]] < data[idxs[j]] })
	return idxs
}

func nsum(data ...int64) int64 {
	var res int64
	for _, n := range data {
		res += n
	}
	return res
}

func njoin(s ...int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

func asub(a, b int64) int64 {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// !------- FORMULAS -------!
func gcd(a, b int64) int64 {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func lcm(a, b int64, integers ...int64) int64 {
	result := a * b / gcd(a, b)

	for i := 0; i < len(integers); i++ {
		result = lcm(result, integers[i])
	}

	return result
}

func sieve(n int64) []int64 {
	integers := make([]bool, n+1)
	for i := int64(2); i < n+1; i++ {
		integers[i] = true
	}

	for p := int64(2); p*p <= n; p++ {
		if integers[p] == true {
			for i := p * 2; i <= n; i += p {
				integers[i] = false
			}
		}
	}

	var primes []int64
	for p := int64(2); p <= n; p++ {
		if integers[p] == true {
			primes = append(primes, p)
		}
	}

	return primes
}


This problem is same as the previous one, but has larger constraints.It was a Sunday morning when the three friends Selena, Shiro and Katie decided to have a trip to the nearby power station (do not try this at home). After arriving at the power station, the cats got impressed with a large power transmission system consisting of many chimneys, electric poles, and wires. Since they are cats, they found those things gigantic.At the entrance of the station, there is a map describing the complicated wiring system. Selena is the best at math among three friends. He decided to draw the map on the Cartesian plane. Each pole is now a point at some coordinates $$$(x_i, y_i)$$$. Since every pole is different, all of the points representing these poles are distinct. Also, every two poles are connected with each other by wires. A wire is a straight line on the plane infinite in both directions. If there are more than two poles lying on the same line, they are connected by a single common wire.Selena thinks, that whenever two different electric wires intersect, they may interfere with each other and cause damage. So he wonders, how many pairs are intersecting? Could you help him with this problem?

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — the number of electric poles. Each of the following $$$n$$$ lines contains two integers $$$x_i$$$, $$$y_i$$$ ($$$-10^4 \le x_i, y_i \le 10^4$$$) — the coordinates of the poles. It is guaranteed that all of these $$$n$$$ points are distinct.

Print a single integer — the number of pairs of wires that are intersecting.

NoteIn the first example:  In the second example:  Note that the three poles $$$(0, 0)$$$, $$$(0, 2)$$$ and $$$(0, 4)$$$ are connected by a single wire.In the third example:

package main

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

func sign(x int) int {
    switch {
    case x < 0:
        return -1
    case x == 0:
        return 0
    default:
        return 1
    }
}

func abs(x int) int {
    if x >= 0 {
        return x
    } else {
        return -x
    }
}

func gcd(a, b int) int {
    if b == 0 {
        return a;
    } else {
        return gcd(b, a % b)
    }
}

type fraction struct {
    a, b int
}

func (f *fraction) standardize() {
    if f.a == 0 {
        f.b = 1
        return
    }
    if f.b == 0 {
        f.a = 1
        return
    }

    g := gcd(abs(f.a), abs(f.b))
    f.a /= g
    f.b /= g
    if f.b < 0 {
        f.a, f.b = -f.a, -f.b
    }
}

func compareFractions(f1 *fraction, f2 *fraction) int {
    f1.standardize()
    f2.standardize()

    switch {
    case f1.b == 0 && f2.b == 0:
        return 0
    case f1.b == 0:
        return 1
    case f2.b == 0:
        return -1
    default:
        return f1.a * f2.b - f1.b * f2.a
    }
}

type point struct {
    x, y int
}

type vector struct {
    x, y int
}

func newVector(start *point, end *point) vector {
    return vector { end.x - start.x, end.y - start.y }
}

func isParallel(v1 *vector, v2 *vector) bool {
    return v1.x * v2.y == v2.x * v1.y
}

type line struct {
    p point
    v vector
}

func newLine(p1 *point, p2 *point) line {
    return line { p: *p1, v: newVector(p1, p2) }
}

func (l *line) slope() fraction {
    s := fraction { l.v.y, l.v.x }
    (&s).standardize()
    return s
}

var n int
var p []point
var l []line

func read() {
    input := bufio.NewScanner(os.Stdin)
    input.Split(bufio.ScanWords)

    input.Scan()
    n, _ = strconv.Atoi(input.Text())

    p = make([]point, n, n)
    for i := range p {
        input.Scan()
        p[i].x, _ = strconv.Atoi(input.Text())

        input.Scan()
        p[i].y, _ = strconv.Atoi(input.Text())
    }
}

func extractLines() {
    pp := make([]point, n, n)
    copy(pp, p)

    l = make([]line, 0)
    for _, pt := range p {
        sort.Slice(pp, func (i, j int) bool {
            if pp[i] == pt {
                return false
            }
            if (pp[j] == pt) {
                return true
            }

            fi := fraction { pp[i].y - pt.y, pp[i].x - pt.x }
            fj := fraction { pp[j].y - pt.y, pp[j].x - pt.x }
            return compareFractions(&fi, &fj) < 0
        })

        i := 0
        for i < len(pp) {
            if pp[i] == pt {
                break
            }

            j := i
            for j < len(pp) {
                fi := fraction { pp[i].y - pt.y, pp[i].x - pt.x }
                fj := fraction { pp[j].y - pt.y, pp[j].x - pt.x }
                if compareFractions(&fi, &fj) == 0 {
                    j++
                } else {
                    break
                }
            }

            ok := true
            for k := i; k < j; k++ {
                if pp[k].x < pt.x {
                    ok = false
                    break
                }
                if (pp[k].x == pt.x && pp[k].y > pt.y) {
                    ok = false
                    break
                }
            }

            if ok {
                l = append(l, newLine(&pt, &pp[i]))
            }

            i = j
        }
    }
}

func main() {
    read()
    extractLines()

    slopecnt := make(map[fraction]int)
    for _, ln := range l {
        slopecnt[(&ln).slope()]++
    }

    ans := int64(0)
    for _, c := range slopecnt {
        ans += int64(c) * int64(len(l) - c)
    }
    ans /= 2

    fmt.Println(ans)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1163/problem/C2

package main

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

type Point struct {
	X int64
	Y int64
}

type Line struct {
	A int64
	B int64
}

func gcd(a int64, b int64) int64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func createLine(p1 Point, p2 Point) Line {
	A := p1.Y - p2.Y
	B := p1.X - p2.X
	d := gcd(A, B)
	return Line{
		A: A / d,
		B: B / d,
	}
}

func Solve(n int, poles []Point) int64 {
	lineMap := make(map[Line]map[int64]int)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			pi, pj := poles[i], poles[j]
			line := createLine(pi, pj)
			_, ok := lineMap[line]
			if !ok {
				lineMap[line] = make(map[int64]int)
			}
			lineMap[line][line.A*pi.X-line.B*pi.Y] += 1
		}
	}
	total := int64(0)
	parallel := int64(0)
	for _, nestedMap := range lineMap {
		count := int64(len(nestedMap))
		total += count
		parallel += count * (count - 1) / 2
	}
	return total*(total-1)/2 - parallel
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	poles := make([]Point, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &poles[i].X, &poles[i].Y)
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, poles))
}

package main

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

func GCD(a, b int) int {
    switch {
    case b != 0:
        return GCD(b, a % b)
    default:
        return a
    }
}

type Fraction struct {
    a, b int
}

func (f *Fraction) standardize() {
    if f.b == 0 {
        f.a = 1
        return
    } else if f.a == 0 {
        f.b = 1
        return
    }

    g := GCD(f.a, f.b)
    f.a /= g
    f.b /= g
}

type Point struct {
    x, y int
}

type Vector struct {
    x, y int
}

func NewVector(start *Point, end *Point) Vector {
    return Vector {
        x: end.x - start.x,
        y: end.y - start.y }
}

func (v *Vector) Reverse() {
    v.x, v.y = -v.x, -v.y
}

func IsParallel(v1 *Vector, v2 *Vector) bool {
    return v1.x * v2.y == v2.x * v1.y
}

type Line struct {
    p Point
    v Vector
}

func NewLine(p1 *Point, p2 *Point) Line {
    l := Line {
        p: *p1,
        v: NewVector(p1, p2) }
    if l.v.x < 0 {
        (&l.v).Reverse()
    }
    return l
}

func (l *Line) Slope() Fraction {
    f := Fraction { l.v.y, l.v.x }
    (&f).standardize()
    return f
}

func IsSameLine(l1 *Line, l2 *Line) bool {
    v := NewVector(&l1.p, &l2.p)
    return IsParallel(&l1.v, &l2.v) && IsParallel(&l1.v, &v)
}

var n int
var p []Point
var lines []Line

func read() {
    input := bufio.NewScanner(os.Stdin)
    input.Split(bufio.ScanWords)

    input.Scan()
    n, _ = strconv.Atoi(input.Text())

    p = make([]Point, n, n)
    for i := range p {
        input.Scan()
        p[i].x, _ = strconv.Atoi(input.Text())

        input.Scan()
        p[i].y, _ = strconv.Atoi(input.Text())
    }
}

func uniqueLines() {
    i := 1
    for j := 1; j < len(lines); j++ {
        if (!IsSameLine(&lines[i - 1], &lines[j])) {
            lines[i], lines[j] = lines[j], lines[i]
            i++
        }
    }
    lines = lines[:i]
}

func main() {
    read()

    lines = make([]Line, 0, n * (n - 1) / 2)
    for i := range p {
        for j := i + 1; j < n; j++ {
            lines = append(lines, NewLine(&p[i], &p[j]))
        }
    }
    sort.Slice(lines, func (i, j int) bool {
        return lines[i].v.y < lines[j].v.y
    })
    uniqueLines()

    slopecnt := make(map[Fraction]int)
    for _, l := range lines {
        slopecnt[(&l).Slope()]++
    }

    var ans int64 = 0
    for _, cnt := range slopecnt {
        ans += int64(cnt) * int64(len(lines) - cnt)
    }
    ans /= 2

    fmt.Println(ans)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1163/problem/C2

package main

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

type Point struct {
	X int
	Y int
}

type Line struct {
	IsVertical bool
	M          float64
	B          float64
	P1         Point
	P2         Point
}

func createLine(p1 Point, p2 Point) Line {
	dy := p2.Y - p1.Y
	dx := p2.X - p1.X
	m := float64(dy) / float64(dx)
	b := float64(p1.Y) - m*float64(p1.X)
	return Line{
		IsVertical: dx == 0,
		P1:         p1,
		P2:         p2,
		M:          m,
		B:          b,
	}
}

func Solve(n int, poles []Point) int64 {
	lineMap := make(map[float64]map[float64]int)
	verticalMap := make(map[int]int)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			pi, pj := poles[i], poles[j]
			line := createLine(pi, pj)
			if line.IsVertical {
				verticalMap[line.P1.X] += 1
			} else {
				_, ok := lineMap[line.M]
				if !ok {
					lineMap[line.M] = make(map[float64]int)
				}
				lineMap[line.M][line.B] += 1
			}
		}
	}
	totalLines := len(verticalMap)
	parallelPairs := 0
	for _, nestedMap := range lineMap {
		totalLines += len(nestedMap)
		parallelPairs += len(nestedMap) * (len(nestedMap) - 1) / 2
	}
	parallelPairs += len(verticalMap) * (len(verticalMap) - 1) / 2
	return int64(totalLines)*int64(totalLines-1)/int64(2) - int64(parallelPairs)
}

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

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	poles := make([]Point, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &poles[i].X, &poles[i].Y)
	}

	fmt.Fprintf(writer, "%d\n", Solve(n, poles))
}


Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be distinct. Nikolay has m cards, distinct numbers from 1 to m are written on them, one per card. It means that Nikolay has exactly one card with number 1, exactly one card with number 2 and so on. A single exchange is a process in which Eugeny gives one card to Nikolay and takes another one from those Nikolay has. Your task is to find the minimum number of card exchanges and determine which cards Eugeny should exchange.

The first line contains two integers n and m (2 ≤ n ≤ 2·105, 1 ≤ m ≤ 109) — the number of cards Eugeny has and the number of cards Nikolay has. It is guaranteed that n is even. The second line contains a sequence of n positive integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the numbers on Eugeny's cards.

If there is no answer, print -1. Otherwise, in the first line print the minimum number of exchanges. In the second line print n integers — Eugeny's cards after all the exchanges with Nikolay. The order of cards should coincide with the card's order in the input data. If the i-th card wasn't exchanged then the i-th number should coincide with the number from the input data. Otherwise, it is considered that this card was exchanged, and the i-th number should be equal to the number on the card it was exchanged to. If there are multiple answers, it is allowed to print any of them.

package main

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

type Val struct {
    v, i int
}

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

func solve() {
    n, m := readInt(), readInt()
    was := make(map[int]bool)
    a := make([]Val, n)
    for i := 0; i < n; i++ {
        a[i] = Val{v:readInt(), i:i}
    }
    sort.Sort(sort.Reverse(ByV(a)))
    odd, even := 0, 0
    for i, val := range a {
        v := val.v
        skip := false
        if was[v] {
            skip = true
        } else {
            was[v] = true
            if v%2 == 0 {
                even++
                if even > n/2 {
                    skip = true
                }
            } else {
                odd++
                if odd > n/2 {
                    skip = true
                }
            }
        }
        if skip {
            a[i].v = 0
        }
    }
    ans, ok := 0, true
    moveNext := func(curM *int) {
        for was[*curM] {
            *curM += 2
        }
        was[*curM] = true
        ans++
        ok = ok && *curM <= m
    }

    oddM, evenM := 1, 2
    index := make(map[int]int)
    for i, val := range a {
        index[val.i] = i
        if val.v > 0 {
            continue
        }
        if even < n/2 {
            moveNext(&evenM)
            a[i].v = evenM
            even++
        } else if odd < n/2 {
            moveNext(&oddM)
            a[i].v = oddM
            odd++
        }
    }
    if !ok {
        ans = -1
    }
    fmt.Println(ans)
    if ok {
        for i := 0; i < n; i++ {
            fmt.Print(a[index[i]].v, " ")
        }
        fmt.Println()
    }
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// Sort

type Ints64 []int64

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

/* Sort template
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

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

func main() {
	var n, m int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &m)
	arr := make([]int, n)
	rem := make([]int, 2)
	flag := make(map[int]bool)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
		if !flag[arr[i]] {
			rem[arr[i]%2]++
		}
		flag[arr[i]] = true
	}

	ans := make([]int, n)
	left0, left1 := n/2-rem[0], n/2-rem[1]
	cangrab0 := make([]int, 0)
	cangrab1 := make([]int, 0)
	if left0 > 0 {
		i := 2
		for i <= m && left0 > 0 {
			if !flag[i] {
				cangrab0 = append(cangrab0, i)
				left0--
			}
			i += 2
		}
	}

	if left1 > 0 {
		i := 1
		for i <= m && left1 > 0 {
			if !flag[i] {
				cangrab1 = append(cangrab1, i)
				left1--
			}
			i += 2
		}
	}
	if left0 > 0 || left1 > 0 {
		fmt.Println(-1)
	} else {
		a0, a1 := n/2, n/2
		for index, key := range arr {
			if !flag[key] {
				continue
			}
			flag[key] = false
			mod := key % 2
			if mod == 0 {
				if a0 > 0 {
					ans[index] = key
					a0--
				}
			} else {
				if a1 > 0 {
					ans[index] = key
					a1--
				}
			}
		}
		index := 0
		i0, i1, cnt := 0, 0, 0
		for a0 > 0 {
			for ans[index] != 0 {
				index++
			}
			ans[index] = cangrab0[i0]
			index++
			cnt++
			i0++
			a0--
		}
		for a1 > 0 {
			for ans[index] != 0 {
				index++
			}
			ans[index] = cangrab1[i1]
			index++
			cnt++
			i1++
			a1--
		}
		fmt.Println(cnt)
		for i := 0; i < n; i++ {
			fmt.Print(ans[i], " ")
		}
		fmt.Println()
	}

}

package main

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

type Val struct {
    v, i int
}

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

func solve() {
    n, m := readInt(), readInt()
    was := make(map[int]bool)
    a := make([]Val, n)
    for i := 0; i < n; i++ {
        a[i] = Val{v:readInt(), i:i}
    }
    sort.Sort(sort.Reverse(ByV(a)))
    odd, even := 0, 0
    for i, val := range a {
        v := val.v
        skip := false
        if was[v] {
            skip = true
        } else {
            was[v] = true
            if v%2 == 0 {
                even++
                if even > n/2 {
                    skip = false
                }
            } else {
                odd++
                if odd > n/2 {
                    skip = false
                }
            }
        }
        if skip {
            a[i].v = 0
        }
    }
    ans, ok := 0, true
    moveNext := func(curM *int) {
        for was[*curM] {
            *curM += 2
        }
        was[*curM] = true
        ans++
        ok = ok && *curM <= m
    }

    oddM, evenM := 1, 2
    index := make(map[int]int)
    for i, val := range a {
        index[val.i] = i
        if val.v > 0 {
            continue
        }
        if even < n/2 {
            moveNext(&evenM)
            a[i].v = evenM
            even++
        } else if odd < n/2 {
            moveNext(&oddM)
            a[i].v = oddM
            odd++
        }
    }
    if !ok {
        ans = -1
    }
    fmt.Println(ans)
    if ok {
        for i := 0; i < n; i++ {
            fmt.Print(a[index[i]].v, " ")
        }
        fmt.Println()
    }
}

// Helpers

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

func main() {
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// Math

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// IO

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

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

// Sort

type Ints64 []int64

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

/* Sort template
func (a ) Len() int           { return len(a) }
func (a ) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ) Less(i, j int) bool { return  }
*/

package main

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

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

func main() {
	var n, m int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &m)
	arr := make([]int, n)
	rem := make([]int, 2)
	flag := make(map[int]bool)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &arr[i])
		if !flag[arr[i]] {
			rem[arr[i]%2]++
		}
		flag[arr[i]] = true
	}

	ans := make([]int, 0)
	left0, left1 := n/2-rem[0], n/2-rem[1]
	cangrab0 := make([]int, 0)
	cangrab1 := make([]int, 0)
	if left0 > 0 {
		i := 2
		for i <= m && left0 > 0 {
			if !flag[i] {
				cangrab0 = append(cangrab0, i)
				left0--
			}
			i += 2
		}
	}

	if left1 > 0 {
		i := 1
		for i <= m && left1 > 0 {
			if !flag[i] {
				cangrab1 = append(cangrab1, i)
				left1--
			}
			i += 2
		}
	}
	if left0 > 0 || left1 > 0 {
		fmt.Println(-1)
	} else {
		a0, a1 := n/2, n/2
		for key, _ := range flag {
			mod := key % 2
			if mod == 0 {
				if a0 > 0 {
					ans = append(ans, key)
					a0--
				}
			} else {
				if a1 > 0 {
					ans = append(ans, key)
					a1--
				}
			}
		}
		i0, i1, cnt := 0, 0, 0
		for a0 > 0 {
			ans = append(ans, cangrab0[i0])
			cnt++
			i0++
			a0--
		}
		for a1 > 0 {
			ans = append(ans, cangrab1[i1])
			cnt++
			i1++
			a1--
		}
		fmt.Println(cnt)
		for i := 0; i < n; i++ {
			fmt.Print(ans[i], " ")
		}
		fmt.Println()
	}

}


You are given a huge integer $$$a$$$ consisting of $$$n$$$ digits ($$$n$$$ is between $$$1$$$ and $$$3 \cdot 10^5$$$, inclusive). It may contain leading zeros.You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, they have different remainders when divided by $$$2$$$). For example, if $$$a = 032867235$$$ you can get the following integers in a single operation:   $$$302867235$$$ if you swap the first and the second digits;  $$$023867235$$$ if you swap the second and the third digits;  $$$032876235$$$ if you swap the fifth and the sixth digits;  $$$032862735$$$ if you swap the sixth and the seventh digits;  $$$032867325$$$ if you swap the seventh and the eighth digits. Note, that you can't swap digits on positions $$$2$$$ and $$$4$$$ because the positions are not adjacent. Also, you can't swap digits on positions $$$3$$$ and $$$4$$$ because the digits have the same parity.You can perform any number (possibly, zero) of such operations.Find the minimum integer you can obtain.Note that the resulting integer also may contain leading zeros.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. The only line of each test case contains the integer $$$a$$$, its length $$$n$$$ is between $$$1$$$ and $$$3 \cdot 10^5$$$, inclusive. It is guaranteed that the sum of all values $$$n$$$ does not exceed $$$3 \cdot 10^5$$$.

For each test case print line — the minimum integer you can obtain.

NoteIn the first test case, you can perform the following sequence of operations (the pair of swapped digits is highlighted): $$$0 \underline{\textbf{70}} 9 \rightarrow 0079$$$.In the second test case, the initial integer is optimal. In the third test case you can perform the following sequence of operations: $$$246 \underline{\textbf{43}} 2 \rightarrow 24 \underline{\textbf{63}}42 \rightarrow 2 \underline{\textbf{43}} 642 \rightarrow 234642$$$.

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {
	q := readInt()
	for i := 0; i < q; i++ {
		solveOne(read())
	}
}

func solveOne(s string) {

	q := make([][]rune, 1)

	str := make([]rune, 1)
	str[0] = rune(s[0])
	q[0] = str

	for i := 1; i < len(s); i++ {
		if (s[i]-s[i-1])%2 == 0 {
			q[len(q)-1] = append(q[len(q)-1], rune(s[i]))
		} else {
			str := make([]rune, 1)
			str[0] = rune(s[i])
			q = append(q, str)
		}
	}

	ans := make([]rune, 0)

	for {
		if len(q) < 2 {
			ans = append(ans, q[0]...)
			break
		}
		if len(q[0]) == 0 {
			q = q[1:]
			continue
		}
		if len(q[1]) == 0 {
			if len(q) < 3 {
				q = q[:1]
			} else {
				q[2] = append(q[0], q[2]...)
				q = q[2:]
			}
			continue
		}
		cur := rune(q[0][0])
		cand := q[1][0]
		if cur > cand {
			ans = append(ans, cand)
			q[1] = q[1][1:]
		} else {
			ans = append(ans, cur)
			q[0] = q[0][1:]
		}
	}

	print(string(ans))

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanLines)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	q := 0
	fmt.Fscanf(in, "%d\n", &q)
	res := make([][]byte, q)
	var wg sync.WaitGroup
	wg.Add(q)
	for i := 0; i < q; i++ {
		s, _ := in.ReadBytes('\n')
		s = s[:len(s)-2]
		go func(id int, str []byte) {
			defer wg.Done()
			odds, evens := []byte{}, []byte{}
			for _, c := range str {
				if c%2 == 0 {
					odds = append(odds, c)
				} else {
					evens = append(evens, c)
				}
			}
			a, b := 0, 0
			for a < len(odds) && b < len(evens) {
				if odds[a] < evens[b] {
					res[id] = append(res[id], odds[a])
					a++
				} else {
					res[id] = append(res[id], evens[b])
					b++
				}
			}
			res[id] = append(res[id], odds[a:]...)
			res[id] = append(res[id], evens[b:]...)
		}(i, s)
	}
	wg.Wait()
	for _, s := range res {
		fmt.Println(string(s))
	}
}

package main

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

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	// r.Buffer(make([]byte, 1024), int(1e+11)) // for AtCoder
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

/*********** DP sub-functions ***********/

// ChMin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// ChMax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func ChMax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num, nth int) int {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num, nth int) int {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num, nth int) int {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*********** Arithmetic ***********/

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// Sum returns multiple integers sum.
func Sum(integers ...int) int {
	s := 0

	for _, i := range integers {
		s += i
	}

	return s
}

// PowInt is integer version of math.Pow
// PowInt calculate a power by Binary Power (二分累乗法(O(log e))).
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := PowInt(a, halfE)
		return half * half
	}

	return a * PowInt(a, e-1)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// Gcd returns the Greatest Common Divisor of two natural numbers.
// Gcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Gcd uses the Euclidean Algorithm.
func Gcd(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}
	if a < b {
		a, b = b, a
	}

	// Euclidean Algorithm
	for b > 0 {
		div := a % b
		a, b = b, div
	}

	return a
}

// Lcm returns the Least Common Multiple of two natural numbers.
// Lcd only accepts two natural numbers (a, b >= 1).
// 0 or negative number causes panic.
// Lcd uses the Euclidean Algorithm indirectly.
func Lcm(a, b int) int {
	if a <= 0 || b <= 0 {
		panic(errors.New("[argument error]: Gcd only accepts two NATURAL numbers"))
	}

	// a = a'*gcd, b = b'*gcd, a*b = a'*b'*gcd^2
	// a' and b' are relatively prime numbers
	// gcd consists of prime numbers, that are included in a and b
	gcd := Gcd(a, b)

	// not (a * b / gcd), because of reducing a probability of overflow
	return (a / gcd) * b
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		// str := strconv.FormatInt(A[i], 10)  // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const MOD = 1000000000 + 7
const ALPHABET_NUM = 26
const INF_INT64 = math.MaxInt64
const INF_BIT60 = 1 << 60

var t int
var S []rune

func main() {
	t = ReadInt()

	for i := 0; i < t; i++ {
		S = ReadRuneSlice()
		// for j := 0; j < 150000; j++ {
		// 	S = append(S, '0')
		// }
		// for j := 0; j < 150000; j++ {
		// 	S = append(S, '9')
		// }

		// evens := make([]rune, 0, 300000+5)
		// odds := make([]rune, 0, 300000+5)
		evens := []rune{}
		odds := []rune{}
		for j := 0; j < len(S); j++ {
			if (S[j]-'0')%2 == 0 {
				evens = append(evens, S[j])
			} else {
				odds = append(odds, S[j])
			}
		}

		// answers := make([]rune, 0, 300000+5)
		answers := []rune{}
		e, o := 0, 0
		for e < len(evens) || o < len(odds) {
			if e == len(evens) {
				answers = append(answers, odds[o])
				o++
			} else if o == len(odds) {
				answers = append(answers, evens[e])
				e++
			} else if evens[e] < odds[o] {
				answers = append(answers, evens[e])
				e++
			} else {
				answers = append(answers, odds[o])
				o++
			}
		}

		fmt.Println(string(answers))
		// for j := 0; j < len(answers); j++ {
		// 	if j == len(answers)-1 {
		// 		fmt.Printf("%c\n", answers[j])
		// 	} else {
		// 		fmt.Printf("%c", answers[j])
		// 	}
		// }
	}
}

// MODはとったか？
// 遷移だけじゃなくて最後の最後でちゃんと取れよ？

/*******************************************************************/

package main

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

type point struct {
	x, y int
}

var ans int64

const (
	mod = int(1e9 + 7)
)

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

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	tt := 1
	fmt.Fscanf(in, "%d\n", &tt)
	for ii := 0; ii < tt; ii++ {
		n := ""
		fmt.Fscanf(in, "%s\n", &n)

		fmt.Fprintf(out, "%s\n", solve(n))
	}
	return
}

func solve(n string) string {
	a := []int{}
	b := []int{}
	for i := 0; i < len(n); i++ {
		cur := int(n[i] - '0')
		if cur%2 == 0 {
			a = append(a, cur)
		} else {
			b = append(b, cur)
		}
	}
	ans := []byte{}
	for len(a)+len(b) > 0 {
		if len(a) == 0 {
			ans = append(ans, '0'+byte(b[0]))
			b = b[1:]
		} else if len(b) == 0 {
			ans = append(ans, '0'+byte(a[0]))
			a = a[1:]
		} else if a[0] < b[0] {
			ans = append(ans, '0'+byte(a[0]))
			a = a[1:]
		} else {
			ans = append(ans, '0'+byte(b[0]))
			b = b[1:]
		}
	}
	return string(ans)
}

func help(i int, n int, total int, t []int, g []int, cur int, c1, c2, c3 int, remaining int) {
	//fmt.Println(i, cur)
	if i == n {
		if cur == total {
			cal(c1, c2, c3)
		}
		return
	}
	if cur > total {
		return
	}
	if cur+remaining < total {
		return
	}
	switch g[i] {
	case 1:
		help(i+1, n, total, t, g, cur+t[i], c1+1, c2, c3, remaining-t[i])
	case 2:
		help(i+1, n, total, t, g, cur+t[i], c1, c2+1, c3, remaining-t[i])
	case 3:
		help(i+1, n, total, t, g, cur+t[i], c1, c2, c3+1, remaining-t[i])
	}
	help(i+1, n, total, t, g, cur, c1, c2, c3, remaining-t[i])
}

func cal(c1, c2, c3 int) {
	a := []int{c1, c2, c3}
	sort.Ints(a)
	tmp := int64(try(c1, c2, c3, 0))
	tmp %= int64(mod)
	for i := 1; i <= c1; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c2; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	for i := 1; i <= c3; i++ {
		tmp *= int64(i)
		tmp %= int64(mod)
	}
	ans += tmp
	ans %= int64(mod)
}

func try(a, b, c int, last int) int64 {
	if a == 0 && b == 0 && c == 0 {
		return 1
	}
	if a < 0 || b < 0 || c < 0 {
		return 0
	}
	if last == 0 {
		return try(a-1, b, c, 1) + try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 1 {
		return try(a, b-1, c, 2) + try(a, b, c-1, 3)
	}
	if last == 2 {
		return try(a-1, b, c, 1) + try(a, b, c-1, 3)
	}
	return try(a-1, b, c, 1) + try(a, b-1, c, 2)
}

package main

import (
	"fmt"
)

func main() {
	var str string
	var n int
	fmt.Scan(&n)

	for i := 0; i < n; i++ {
		fmt.Scan(&str)

		var oddArr, evenArr = []uint8{}, []uint8{}
		var oddIdx, evenIdx, strLen int
		strLen = len(str)
		var res = []uint8{}

		for j := 0; j < strLen; j++ {
			if str[j]%2 == 1 {
				oddArr = append(oddArr, str[j])
				oddIdx++
			} else {
				evenArr = append(evenArr, str[j])
				evenIdx++
			}
		}
		for x, y := 0, 0; x < oddIdx || y < evenIdx; {
			if y >= evenIdx || (x < oddIdx && oddArr[x] < evenArr[y]) {
				res = append(res, oddArr[x])
				x++
			} else {
				res = append(res, evenArr[y])
				y++
			}
		}
		fmt.Println(string(res))
	}
}

package main

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

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 fun() {
	var s string
	scanf("%s\n", &s)
	printf("%s\n", solve(s))
}

func solve(s string) string {
	n := len(s)
	ans := make([]byte, 0, n)
	oddIndex := 0
	evenIndex := 0
	for oddIndex < n && evenIndex < n {
		if s[oddIndex]%2 == 0 {
			oddIndex++
			continue
		}
		if s[evenIndex]%2 == 1 {
			evenIndex++
			continue
		}
		if s[oddIndex] < s[evenIndex] {
			ans = append(ans, s[oddIndex])
			oddIndex++
			continue
		}
		if s[evenIndex] < s[oddIndex] {
			ans = append(ans, s[evenIndex])
			evenIndex++
			continue
		}
	}
	for ; oddIndex < n; oddIndex++ {
		if s[oddIndex]%2 == 0 {
			continue
		}
		ans = append(ans, s[oddIndex])
	}
	for ; evenIndex < n; evenIndex++ {
		if s[evenIndex]%2 == 1 {
			continue
		}
		ans = append(ans, s[evenIndex])
	}
	return string(ans)
}

func main() {
	// Flush stdout
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fun()
	}
}

package main

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

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 fun() {
	var s string
	scanf("%s\n", &s)
	printf("%s\n", solve(s))
}

func solve(s string) string {
	ans := []byte{}
	n := len(s)
	oddIndex := 0
	evenIndex := 0
	for oddIndex < n && evenIndex < n {
		if s[oddIndex]%2 == 0 {
			oddIndex++
			continue
		}
		if s[evenIndex]%2 == 1 {
			evenIndex++
			continue
		}
		if s[oddIndex] < s[evenIndex] {
			ans = append(ans, s[oddIndex])
			oddIndex++
			continue
		}
		if s[evenIndex] < s[oddIndex] {
			ans = append(ans, s[evenIndex])
			evenIndex++
			continue
		}
	}
	for ; oddIndex < n; oddIndex++ {
		if s[oddIndex]%2 == 0 {
			continue
		}
		ans = append(ans, s[oddIndex])
	}
	for ; evenIndex < n; evenIndex++ {
		if s[evenIndex]%2 == 1 {
			continue
		}
		ans = append(ans, s[evenIndex])
	}
	return string(ans)
}

func main() {
	// Flush stdout
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		fun()
	}
}

package main

import "fmt"

func fun() {
	var s string
	fmt.Scanln(&s)
	fmt.Println(solve(s))
}

func solve(s string) string {
	ans := []byte{}
	n := len(s)
	oddIndex := 0
	evenIndex := 0
	for oddIndex < n && evenIndex < n {
		if s[oddIndex]%2 == 0 {
			oddIndex++
			continue
		}
		if s[evenIndex]%2 == 1 {
			evenIndex++
			continue
		}
		if s[oddIndex] < s[evenIndex] {
			ans = append(ans, s[oddIndex])
			oddIndex++
			continue
		}
		if s[evenIndex] < s[oddIndex] {
			ans = append(ans, s[evenIndex])
			evenIndex++
			continue
		}
	}
	for ; oddIndex < n; oddIndex++ {
		if s[oddIndex]%2 == 0 {
			continue
		}
		ans = append(ans, s[oddIndex])
	}
	for ; evenIndex < n; evenIndex++ {
		if s[evenIndex]%2 == 1 {
			continue
		}
		ans = append(ans, s[evenIndex])
	}
	return string(ans)
}

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

package main

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

const INFINITY = math.MaxInt32/2 - 1

func exec(stdin *Stdin, stdout *Stdout) {
	for t := stdin.ReadInt(); t > 0; t-- {
		s := stdin.Read()
		o := NewDeque()
		e := NewDeque()
		for _, ch := range s {
			x := ch - '0'
			if x%2 == 0 {
				e.AppendLast(ch)
			} else {
				o.AppendLast(ch)
			}
		}

		n := len(s)
		ans := make([]rune, n)
		for i := 0; i < n; i++ {
			if e.IsEmpty() {
				ans[i] = o.PopFirst().(rune)
			} else if o.IsEmpty() {
				ans[i] = e.PopFirst().(rune)
			} else {
				r1 := o.PeekFirst().(rune)
				r2 := e.PeekFirst().(rune)
				if r1 < r2 {
					ans[i] = r1
					o.PopFirst()
				} else {
					ans[i] = r2
					e.PopFirst()
				}
			}
		}

		stdout.Println(string(ans))
	}
}

type Deque struct {
	head []interface{}
	tail []interface{}
}

func NewDeque() *Deque {
	return &Deque{
		head: []interface{}{},
		tail: []interface{}{},
	}
}

func (d *Deque) AppendLast(v interface{}) {
	d.tail = append(d.tail, v)
}

func (d *Deque) AppendFirst(v interface{}) {
	d.head = append(d.head, v)
}

func (d *Deque) PopLast() interface{} {
	if len(d.tail) == 0 {
		v := d.head[0]
		d.head = d.head[1:]
		return v
	} else {
		v := d.tail[len(d.tail)-1]
		d.tail = d.tail[:len(d.tail)-1]
		return v
	}
}

func (d *Deque) PopFirst() interface{} {
	if len(d.head) == 0 {
		v := d.tail[0]
		d.tail = d.tail[1:]
		return v
	} else {
		v := d.head[len(d.head)-1]
		d.head = d.head[:len(d.head)-1]
		return v
	}
}

func (d *Deque) IsEmpty() bool {
	return len(d.head) == 0 && len(d.tail) == 0
}

func (d *Deque) PeekFirst() interface{} {
	if len(d.head) == 0 {
		return d.tail[0]
	} else {
		return d.head[len(d.head)-1]
	}
}

func (d *Deque) PeekLast() interface{} {
	if len(d.tail) == 0 {
		return d.head[0]
	} else {
		return d.tail[len(d.tail)-1]
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), INFINITY)
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadInt64() int64 {
	n, _ := strconv.ParseInt(s.Read(), 10, 64)
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

func (s *Stdin) ReadIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt()
	}
	return a
}

func (s *Stdin) ReadStringSlice(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = s.Read()
	}
	return a
}

func (s *Stdin) ReadFloat64Slice(n int) []float64 {
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadFloat64()
	}
	return a
}

func (s *Stdin) ReadInt64Slice(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = s.ReadInt64()
	}
	return a
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Min(a int, b ...int) int {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max(a int, b ...int) int {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs(x int) int {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow(x, y int) int {
	z := 1
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y -= 1
		}
	}
	return z
}

func IsPrime(x int) bool {
	if x < 2 {
		return false
	}

	for i := 2; i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}

func CeilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

func LCS(s, t string) string {
	n := len(s)
	m := len(t)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = dp[i-1][j-1] + 1
			} else {
				dp[i][j] = Max(dp[i-1][j], dp[i][j-1])
			}
		}
	}

	x := n
	y := m
	u := make([]byte, dp[n][m])
	i := dp[n][m] - 1
	for x > 0 && y > 0 {
		if dp[x][y] == dp[x-1][y] {
			x--
		} else if dp[x][y] == dp[x][y-1] {
			y--
		} else {
			x--
			y--
			u[i] = s[x]
			i--
		}
	}

	return string(u)
}

// [0..n) から r個選んだ組合せを生成する。
// r < 0 の場合はすべての組合せを生成する。
func Combinations(n int, r int) [][]int {
	a := [][]int{}
	for i := uint(0); i < (1 << uint(n)); i++ {
		b := []int{}
		for j := uint(0); j < uint(n); j++ {
			if i&(uint(1)<<j) != 0 {
				b = append(b, int(j))
			}
		}

		if r < 0 || len(b) == r {
			a = append(a, b)
		}
	}
	return a
}

// [0..n)の順列を生成する。
func Permutations(n int) [][]int {
	type e struct {
		bit uint
		a   []int
	}

	q := []*e{}
	for i := 0; i < n; i++ {
		q = append(q, &e{bit: 1 << uint(i), a: []int{i}})
	}

	p := [][]int{}
	for x := 0; x < len(q); x++ {
		cur := q[x]
		if cur.bit == (1<<uint(n) - 1) {
			p = append(p, cur.a)
			continue
		}

		for i := 0; i < n; i++ {
			if cur.bit&(1<<uint(i)) != 0 {
				continue
			}

			m := len(cur.a) + 1
			b := make([]int, m)
			copy(b, cur.a)
			b[m-1] = i
			q = append(q, &e{bit: cur.bit | (1 << uint(i)), a: b})
		}
	}
	return p
}

func ReverseSlice(v interface{}) {
	if reflect.TypeOf(v).Kind() == reflect.Slice {
		slice := reflect.ValueOf(v)
		for i1, n := 0, slice.Len(); i1 < n/2; i1++ {
			i2 := n - i1 - 1
			v1 := reflect.ValueOf(slice.Index(i1).Interface())
			slice.Index(i1).Set(slice.Index(i2))
			slice.Index(i2).Set(v1)
		}
	}
}

func ReverseString(s string) string {
	t := []rune(s)
	ReverseSlice(t)
	return string(t)
}

func ToStringSlice(slice interface{}) []string {
	// 本来はerrを返却すべき。 利用する側(=自分)は引数がsliceであることを知っている。
	if reflect.TypeOf(slice).Kind() != reflect.Slice {
		panic(fmt.Sprintf("%v is not slice", slice))
	}

	src := reflect.ValueOf(slice)
	n := src.Len()
	dst := make([]string, n)
	for i := 0; i < n; i++ {
		dst[i] = fmt.Sprintf("%v", src.Index(i))
	}
	return dst
}

func CreateMatrix(x, y int) [][]int {
	matrix := make([][]int, x)
	for i := 0; i < x; i++ {
		matrix[i] = make([]int, y)
	}
	return matrix
}

func Min64(a int64, b ...int64) int64 {
	for _, v := range b {
		if v < a {
			a = v
		}
	}
	return a
}

func Max64(a int64, b ...int64) int64 {
	for _, v := range b {
		if a < v {
			a = v
		}
	}
	return a
}

func Abs64(x int64) int64 {
	if x > 0 {
		return x
	} else {
		return x * -1
	}
}

func Pow64(x, y int64) int64 {
	z := int64(1)
	for y > 0 {
		if y%2 == 0 {
			x *= x
			y /= 2
		} else {
			z *= x
			y--
		}
	}
	return z
}

func IsPrime64(x int64) bool {
	if x < 2 {
		return false
	}

	for i := int64(2); i*i <= x; i++ {
		if x%i == 0 {
			return false
		}
	}
	return true
}

func Gcd64(x, y int64) int64 {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm64(x, y int64) int64 {
	return x * y / Gcd64(x, y)
}

func CeilDiv64(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	} else {
		return x/y + 1
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	q := 0
	fmt.Fscanf(in, "%d\n", &q)
	res := make([][]byte, q)
	var wg sync.WaitGroup
	wg.Add(q)
	for i := 0; i < q; i++ {
		s, _ := in.ReadBytes('\n')
		s = s[:len(s)-1]
		go func(id int, str []byte) {
			defer wg.Done()
			odds, evens := []byte{}, []byte{}
			for _, c := range str {
				if c%2 == 0 {
					odds = append(odds, c)
				} else {
					evens = append(evens, c)
				}
			}
			a, b := 0, 0
			for a < len(odds) && b < len(evens) {
				if odds[a] < evens[b] {
					res[id] = append(res[id], odds[a])
					a++
				} else {
					res[id] = append(res[id], evens[b])
					b++
				}
			}
			res[id] = append(res[id], odds[a:]...)
			res[id] = append(res[id], evens[b:]...)
		}(i, s)
	}
	wg.Wait()
	for _, s := range res {
		fmt.Println(string(s))
	}
}


There are $$$n$$$ programmers that you want to split into several non-empty teams. The skill of the $$$i$$$-th programmer is $$$a_i$$$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $$$x$$$.Each programmer should belong to at most one team. Some programmers may be left without a team.Calculate the maximum number of teams that you can assemble.

The first line contains the integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 10^5; 1 \le x \le 10^9$$$) — the number of programmers and the restriction of team skill respectively. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th programmer. The sum of $$$n$$$ over all inputs does not exceed $$$10^5$$$.

For each test case print one integer — the maximum number of teams that you can assemble.

package main

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

type FastIn struct {
	scanner *bufio.Scanner
}

func MakeFastIn() (obj FastIn)  {
	obj = FastIn{}
	obj.scanner = bufio.NewScanner(os.Stdin)
	obj.scanner.Split(bufio.ScanWords)
	return
}

func (fi *FastIn) ReadInt() int {
	fi.scanner.Scan()
	ret, err := strconv.Atoi(fi.scanner.Text())
	if err != nil {
		panic(err)
	}
	return ret
}

func main() {
	fin := MakeFastIn()
	t := fin.ReadInt()
	for i := 0; i < t; i++ {
		n, x := fin.ReadInt(), fin.ReadInt()
		p := make([]int, n)
		for j := 0; j < n; j++ {
			p[j] = fin.ReadInt()
		}

		sort.Ints(p[:])
		ans, cnt := 0, 0
		for j := n-1; j >= 0; j-- {
			cnt += 1
			if int64(p[j]) * int64(cnt) >= int64(x) {
				cnt, ans = 0, ans + 1
			}
		}
		fmt.Printf("%d\n",ans)
	}
}

package main

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

type FastIn struct {
	scanner *bufio.Scanner
}

func MakeFastIn() (obj FastIn)  {
	obj = FastIn{}
	obj.scanner = bufio.NewScanner(os.Stdin)
	obj.scanner.Split(bufio.ScanWords)
	return
}

func (fi *FastIn) ReadInt() int {
	fi.scanner.Scan()
	ret, err := strconv.Atoi(fi.scanner.Text())
	if err != nil {
		panic(err)
	}
	return ret
}

func main() {
	fin := MakeFastIn()
	t := fin.ReadInt()
	for i := 0; i < t; i++ {
		n := fin.ReadInt()
		x := fin.ReadInt()
		p := make([]int, n)
		for j := 0; j < n; j++ {
			p[j] = fin.ReadInt()
		}

		sort.Ints(p[:])
		ans := 0
		cnt := 0
		for j := n-1; j >= 0; j-- {
			cnt += 1
			if int64(p[j]) * int64(cnt) >= int64(x) {
				cnt = 0
				ans += 1
			}
		}
		fmt.Printf("%d\n",ans)
	}
}


Tom loves vowels, and he likes long words with many vowels. His favorite words are vowelly words. We say a word of length $$$k$$$ is vowelly if there are positive integers $$$n$$$ and $$$m$$$ such that $$$n\cdot m = k$$$ and when the word is written by using $$$n$$$ rows and $$$m$$$ columns (the first row is filled first, then the second and so on, with each row filled from left to right), every vowel of the English alphabet appears at least once in every row and every column.You are given an integer $$$k$$$ and you must either print a vowelly word of length $$$k$$$ or print $$$-1$$$ if no such word exists.In this problem the vowels of the English alphabet are 'a', 'e', 'i', 'o' ,'u'.

Input consists of a single line containing the integer $$$k$$$ ($$$1\leq k \leq 10^4$$$) — the required length.

The output must consist of a single line, consisting of a vowelly word of length $$$k$$$ consisting of lowercase English letters if it exists or $$$-1$$$ if it does not. If there are multiple possible words, you may output any of them.

NoteIn the second example, the word "agoeuioaeiruuimaeoieauoweouoiaouimae" can be arranged into the following $$$6 \times 6$$$ grid:  It is easy to verify that every row and every column contain all the vowels.

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	row := -1
	for i := 5; i*i <= n; i++ {
		if n%i == 0 {
			row = i
			break
		}
	}
	if row == -1 {
		fmt.Println(-1)
		return
	}
	col := n / row
	ans := ""
	foo := "aeiou"
	for i := 0; i < row; i++ {
		for j := 0; j < col; j++ {
			ans += string(foo[(i+j)%5])
		}
	}
	fmt.Println(ans)
	return
}

package main

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

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

	var k int
	fmt.Fscanf(in, "%d\n", &k)

	var n, m int
	for n = 5; float64(n) <= math.Sqrt(float64(k)); n++ {
		if k%n == 0 {
			m = k / n
			break
		}
	}
	if m == 0 {
		fmt.Fprintln(out, -1)
		return
	}
	for i := 0; i < n; i++ {
		fmt.Fprint(out, vowel(m, i))
	}
	fmt.Fprintln(out)
}

func vowel(len int, offset int) string {
	w := "aiueo"
	r := make([]byte, len)
	for i := 0; i < len; i++ {
		r[i] = w[(i+offset)%5]
	}
	return string(r)
}

package main

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

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() {
	var k int
	scanf("%d\n", &k)
	ok := false
	var n, m int
	for i := 5; i <= k; i++ {
		if k%i == 0 && k/i >= 5 {
			ok = true
			n = i
			m = k / i
			break
		}
	}
	if !ok {
		fmt.Println(-1)
		return
	}
	var res = make([][]uint8, n)
	template := [][]uint8{
		{'a', 'e', 'u', 'i', 'o'},
		{'o', 'a', 'e', 'u', 'i'},
		{'i', 'o', 'a', 'e', 'u'},
		{'u', 'i', 'o', 'a', 'e'},
		{'e', 'u', 'i', 'o', 'a'},
	}
	for i := 0; i < n; i++ {
		res[i] = make([]uint8, m)
		for j := 0; j < m; j++ {
			res[i][j] = template[i%5][j%5]
		}
	}
	var ans []uint8
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			ans = append(ans, res[i][j])
		}
	}
	fmt.Println(string(ans))
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	k, _ := strconv.Atoi(scanner.Text())
	m := map[int]uint8{
		0: 'a', 1: 'e', 2: 'i', 3: 'o', 4: 'u',
	}
	for i := 5; i * i <= k; i++ {
		if k % i != 0 {
			continue
		}
		for x := 0; x < i; x++ {
			for y := 0; y < k / i; y++ {
				fmt.Printf("%c", m[(x + y) % 5])
			}
		}
		return
	}
	fmt.Print(-1)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	v := []byte{'a', 'e', 'i', 'o', 'u'}
	for i := 5; i <= n/5; i++ {
		if n%i == 0 {
			j := n / i
			if j < 5 {
				continue
			}
			a := make([][]byte, i)
			ans := []byte{}
			for k := 0; k < i; k++ {
				a[k] = make([]byte, j)
			}
			for k := 0; k < i; k++ {
				for q := 0; q < j; q++ {
					a[k][q] = v[(k+q)%5]
					ans = append(ans, v[(k+q)%5])
				}
				//fmt.Println(string(a[k]))
			}
			fmt.Fprintf(out, "%s\n", string(ans))
			return
		}
	}
	fmt.Fprintf(out, "-1\n")
	return
}

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

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

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)

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

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

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

func Build(n, m int) ([][]byte, bool) {
	if n < 5 || m < 5 {
		return nil, true
	}

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

	str := "aeiou"
	for i := 0; i < 5; i++ {
		for j := 0; j < 5; j++ {
			ret[i][j] = str[(i+j)%len(str)]
		}
	}

	for i := 5; i < n; i++ {
		for j := 0; j < 5; j++ {
			ret[i][j] = str[j]
		}
	}

	for j := 5; j < m; j++ {
		for i := 0; i < 5; i++ {
			ret[i][j] = str[i]
		}
	}

	for i := 5; i < n; i++ {
		for j := 5; j < m; j++ {
			ret[i][j] = 'x'
		}
	}

	return ret, false
}

func Prepare(arr [][]byte) string {
	var b bytes.Buffer
	for i := 0; i < len(arr); i++ {
		for j := 0; j < len(arr[i]); j++ {
			b.WriteByte(arr[i][j])
		}
	}
	return b.String()
}

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

	n := ReadInt()

	for i := 5; i < n; i++ {
		if n%i == 0 {
			j := n / i
			str, err := Build(i, j)
			if !err {
				fmt.Println(Prepare(str))
				return
			}
		}
	}

	fmt.Println("-1")
}

package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    for h := 5; h < n; h++ {
        if n % h != 0 || n / h < 5 {
            continue
        }
        w := n / h
        var s string
        for i := 0; i < h; i++ {
            for j := 0; j < w; j++ {
                x := (i + j) % 5
                s = s + "aiueo"[x:x+1]
            }
        }
        fmt.Println(s)
        return
    }
    fmt.Println(-1)
}

package main

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

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

	var k int
	fmt.Fscanf(in, "%d\n", &k)

	var n, m int
	for n = 5; float64(n) <= math.Sqrt(float64(k)); n++ {
		if k%n == 0 {
			m = k / n
			break
		}
	}
	if m == 0 {
		fmt.Fprintln(out, -1)
		return
	}

	for i := 0; i < n; i++ {
		fmt.Fprint(out, vowel(i))
		fmt.Fprint(out, rest(m-5))
	}
	fmt.Fprintln(out, "")
}

func vowel(offset int) string {
	w := "aiueo"
	var r []byte
	for i := 0; i < len(w); i++ {
		r = append(r, w[(i+offset)%5])
	}
	return string(r)
}

func rest(len int) string {
	var r []byte
	for i := 0; i < len; i++ {
		r = append(r, 'a')
	}
	return string(r)
}

package main

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

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() {
	var k int
	scanf("%d\n", &k)
	ok := false
	var n, m int
	for i := 5; i <= k; i++ {
		if k%i == 0 && k/i >= 5 {
			ok = true
			n = i
			m = k / i
			break
		}
	}
	if !ok {
		fmt.Println(-1)
		return
	}
	var res = make([][]uint8, n)
	template := [][]uint8{
		{'a', 'y', 'u', 'i', 'o'},
		{'o', 'a', 'y', 'u', 'i'},
		{'i', 'o', 'a', 'y', 'u'},
		{'u', 'i', 'o', 'a', 'y'},
		{'y', 'u', 'i', 'o', 'a'},
	}
	for i := 0; i < n; i++ {
		res[i] = make([]uint8, m)
		for j := 0; j < m; j++ {
			if i < 5 && j < 5 {
				res[i][j] = template[i][j]
			} else {
				res[i][j] = 's'
			}
		}
	}
	var ans []uint8
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			ans = append(ans, res[i][j])
		}
	}
	fmt.Println(string(ans))
}

package main

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

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() {
	var k int
	scanf("%d\n", &k)
	ok := false
	var n, m int
	for i := 5; i <= k; i++ {
		if k%i == 0 && k/i >= 5 {
			ok = true
			n = i
			m = k / i
			break
		}
	}
	if !ok {
		fmt.Println(-1)
		return
	}
	var res = make([][]uint8, n)
	template := [][]uint8{
		{'a', 'e', 'u', 'i', 'o'},
		{'o', 'a', 'e', 'u', 'i'},
		{'i', 'o', 'a', 'e', 'u'},
		{'u', 'i', 'o', 'a', 'e'},
		{'e', 'u', 'i', 'o', 'a'},
	}
	for i := 0; i < n; i++ {
		res[i] = make([]uint8, m)
		for j := 0; j < m; j++ {
			res[i][j] = template[i%5][j%5]
		}
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Print(string(res[i][j]))
		}
		fmt.Println()
	}
	var ans []uint8
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			ans = append(ans, res[i][j])
		}
	}
	fmt.Println(string(ans))
}

package main

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

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() {
	var k int
	scanf("%d\n", &k)
	ok := false
	var n, m int
	for i := 5; i <= k; i++ {
		if k%i == 0 && k/i >= 5 {
			ok = true
			n = i
			m = k / i
			break
		}
	}
	if !ok {
		fmt.Println(-1)
		return
	}
	var res = make([][]uint8, n)
	template := [][]uint8{
		{'a', 'y', 'u', 'i', 'o'},
		{'o', 'a', 'y', 'u', 'i'},
		{'i', 'o', 'a', 'y', 'u'},
		{'u', 'i', 'o', 'a', 'y'},
		{'y', 'u', 'i', 'o', 'a'},
	}
	for i := 0; i < n; i++ {
		res[i] = make([]uint8, m)
		for j := 0; j < m; j++ {
			res[i][j] = template[i%5][j%5]
		}
	}
	var ans []uint8
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			ans = append(ans, res[i][j])
		}
	}
	fmt.Println(string(ans))
}