Anya loves to watch horror movies. In the best traditions of horror, she will be visited by m ghosts tonight. Anya has lots of candles prepared for the visits, each candle can produce light for exactly t seconds. It takes the girl one second to light one candle. More formally, Anya can spend one second to light one candle, then this candle burns for exactly t seconds and then goes out and can no longer be used.For each of the m ghosts Anya knows the time at which it comes: the i-th visit will happen wi seconds after midnight, all wi's are distinct. Each visit lasts exactly one second.What is the minimum number of candles Anya should use so that during each visit, at least r candles are burning? Anya can start to light a candle at any time that is integer number of seconds from midnight, possibly, at the time before midnight. That means, she can start to light a candle integer number of seconds before midnight or integer number of seconds after a midnight, or in other words in any integer moment of time.

The first line contains three integers m, t, r (1 ≤ m, t, r ≤ 300), representing the number of ghosts to visit Anya, the duration of a candle's burning and the minimum number of candles that should burn during each visit.  The next line contains m space-separated numbers wi (1 ≤ i ≤ m, 1 ≤ wi ≤ 300), the i-th of them repesents at what second after the midnight the i-th ghost will come. All wi's are distinct, they follow in the strictly increasing order.

If it is possible to make at least r candles burn during each visit, then print the minimum number of candles that Anya needs to light for that. If that is impossible, print  - 1.

NoteAnya can start lighting a candle in the same second with ghost visit. But this candle isn't counted as burning at this visit.It takes exactly one second to light up a candle and only after that second this candle is considered burning; it means that if Anya starts lighting candle at moment x, candle is buring from second x + 1 to second x + t inclusively.In the first sample test three candles are enough. For example, Anya can start lighting them at the 3-rd, 5-th and 7-th seconds after the midnight.In the second sample test one candle is enough. For example, Anya can start lighting it one second before the midnight.In the third sample test the answer is  - 1, since during each second at most one candle can burn but Anya needs three candles to light up the room at the moment when the ghost comes.

package main

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

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

type Candle struct {
	time int
	numbers int
}

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

	m, t, r := nextInt(), nextInt(), nextInt()
	w, remainCandles, total := 0, 0, 0
	candles := make([]Candle, 0, 10)

	if t < r {
		println(-1)
		return
	}

	for ; m > 0; m-- {
		w = nextInt()
		remainCandles = 0
		// println(w)
		for i := 0; i < len(candles); i++ {
			// println(remainCandles, candles)
			if candles[i].time + candles[i].numbers + t < w {
				candles = candles[1:]
				i--
			} else {

				if w - t <= candles[i].time {
					remainCandles += candles[i].numbers
				} else {
					remainCandles = candles[i].numbers - (w - t - candles[i].time)
				}
			}

			// println(remainCandles, candles)
		}

		if remainCandles < r {
			nextCandles := r - remainCandles
			total += nextCandles

			candles = append(candles, Candle{w - nextCandles, nextCandles})
		}

		// println(total, "\n")
	}

	println(total)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

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

var (
	m, t, r int
	w       []int
	result  int
)

func in() {
	read(&m, &t, &r)
	w = make([]int, m)
	for i := 0; i < m; i++ {
		read(&w[i])
		w[i] += 300
	}
}

func out() {
	println(result)
	defer output.Flush()
}

func run() {
	c := make([]bool, 610)
	for i := 0; i < m; i++ {
		count := 0
		for j := w[i] - 1; j >= w[i]-t; j-- {
			if c[j] {
				count++
			}
		}
		if count >= r {
			continue
		} else {
			count = r - count
		}

		for j := w[i] - 1; j >= w[i]-t && count > 0; j-- {
			if !c[j] {
				c[j] = true
				count--
			}
		}

		if count > 0 {
			result = -1
			return
		}
	}

	result = 0
	for _, candle := range c {
		if candle {
			result++
		}
	}
}

/** main **/
func main() {
	in()
	run()
	out()
}

// Input & Output
var (
	input  = bufio.NewReader(os.Stdin)
	output = bufio.NewWriter(os.Stdout)
)

func read(a ...interface{}) {
	_, err := fmt.Fscan(input, a...)
	if err != nil {
		println(err)
	}
}

func println(a ...interface{}) {
	fmt.Fprintln(output, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(output, format, a...)
}

package main

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

type Pair struct {
	pos int
	count int
}

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

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

	var m, t, r int
	fmt.Fscanf(in, "%v %v %v ", &m, &t, &r)
	ws := make([]Pair, m)
	for i := 0; i < m; i++ {
		var w int
		fmt.Fscanf(in, "%v ", &w)
		ws[i] = Pair{w, 0}
	}
	if t < r {
		fmt.Printf("-1\n")
		return
	}
	total_count := 0
	for i := 0; i < m; i++ {
		if ws[i].count < r {
			delta := r - ws[i].count
			total_count += delta
			for j := i; j < m; j++ {
				if ws[j].pos >= ws[i].pos + t {
					break
				}
				ws[j].count += min(delta, ws[i].pos + t - ws[j].pos)
			}
		}
	}
  fmt.Printf("%v\n", total_count)
}

package main

import (
	"fmt"
)

func main() {
	var res int
	q := make([]int, 0, 310)
	var M, T, R int
	fmt.Scan(&M, &T, &R)
	if R > T {
		fmt.Println(-1)
		return
	}
	for i := 0; i < M; i++ {
		var W int
		fmt.Scan(&W)
		for len(q) > 0 && q[0]+T-1 < W {
			q = q[1:]
		}
		for j := W - (R - len(q)) + 1; j <= W; j++ {
			res++
			q = append(q, j)
		}
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
)

type time struct {
	t int
	a []bool
}

func newTime(t int) time {
	ti := time{}
	ti.t = t
	ti.a = make([]bool, 301+t)
	return ti
}

func (ti *time) get(t int) bool {
	return ti.a[t+ti.t]
}

func (ti *time) set(t int, b bool) {
	ti.a[t+ti.t] = b
}

func (ti *time) count() int {
	c := 0
	for i := 0; i < len(ti.a); i++ {
		if ti.a[i] {
			c++
		}
	}
	return c
}

func main() {
	var m, t, r int
	fmt.Scan(&m, &t, &r)
	w := make([]int, m)
	for i := 0; i < m; i++ {
		fmt.Scan(&w[i])
	}

	if m > 0 && t < r {
		fmt.Println(-1)
		return
	}

	ti := newTime(t)
	for i := m - 1; i >= 0; i-- {
		c := 0
		for j := 1; j <= t; j++ {
			if ti.get(w[i] - j) {
				c++
			}
		}

		for c < r {
			for j := t; j >= 1; j-- {
				if ti.get(w[i]-j) == false {
					ti.set(w[i]-j, true)
					c++
					if c >= r {
						break
					}
				}
			}
		}
	}

	fmt.Println(ti.count())
}

package main

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

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

type Candle struct {
	time int
	numbers int
}

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

	m, t, r := nextInt(), nextInt(), nextInt()
	w, remainCandles, total := 0, 0, 0
	candles := make([]Candle, 0, 10)

	if t < r {
		println(-1)
		return
	}

	for ; m > 0; m-- {
		w = nextInt()
		remainCandles = 0
		println(w)
		for i := 0; i < len(candles); i++ {
			// println(remainCandles, candles)
			if candles[i].time + candles[i].numbers + t < w {
				candles = candles[1:]
				i--
			} else {

				if w - t <= candles[i].time {
					remainCandles += candles[i].numbers
				} else {
					remainCandles = candles[i].numbers - (w - t - candles[i].time)
				}
			}

			println(remainCandles, candles)
		}

		if remainCandles < r {
			nextCandles := r - remainCandles
			total += nextCandles

			candles = append(candles, Candle{w - nextCandles, nextCandles})
		}

		println(total, "\n")
	}

	println(total)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

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

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

type Candle struct {
	time int
	numbers int
}

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

	m, t, r := nextInt(), nextInt(), nextInt()
	w, remainCandles, total := 0, 0, 0
	candles := make([]Candle, 0, 10)

	if t < r-1 {
		println(-1)
		return
	}

	for ; m > 0; m-- {
		w = nextInt()
		remainCandles = 0
		// println(w)
		for i := 0; i < len(candles); i++ {
			// println(remainCandles, candles)
			if candles[i].time + candles[i].numbers + t < w {
				candles = candles[1:]
				i--
			} else {

				if w - t <= candles[i].time {
					remainCandles += candles[i].numbers
				} else {
					remainCandles = candles[i].numbers - (w - t - candles[i].time)
				}
			}

			// println(remainCandles, candles)
		}

		if remainCandles < r {
			nextCandles := r - remainCandles
			total += nextCandles

			candles = append(candles, Candle{w - nextCandles, nextCandles})
		}

		// println(total, "\n")
	}

	println(total)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

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

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

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import "fmt"

type Pair struct {
	pos int
	count int
}

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

func main() {
	var m, t, r int
	fmt.Scanf("%v %v %v", &m, &t, &r)
	ws := make([]Pair, m)
	for i := 0; i < m; i++ {
		var w int
		fmt.Scanf("%d", &w)
		ws[i] = Pair{w, 0}
	}
	if t < r {
		fmt.Printf("-1\n")
		return
	}
	total_count := 0
	for i := 0; i < m; i++ {
		if ws[i].count < r {
			delta := r - ws[i].count
			total_count += delta
			for j := i; j < m; j++ {
				if ws[j].pos >= ws[i].pos + t {
					break
				}
				ws[j].count += min(delta, ws[i].pos + t - ws[j].pos)
			}
		}
	}
  fmt.Printf("%v\n", total_count)
}

package main

import "fmt"

type Pair struct {
	pos int
	count int
}

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

func main() {
	var m, t, r int
	fmt.Scanf("%v %v %v", &m, &t, &r)
	ws := make([]Pair, m)
	for i := 0; i < m; i++ {
		var w int
		fmt.Scanf("%d", &w)
		ws[i] = Pair{w, 0}
	}
	if t < r {
		fmt.Printf("-1\n")
		return
	}
	total_count := 0
	for i := 0; i < m; i++ {
		if ws[i].count < r {
			delta := r - ws[i].count
			total_count += delta
			for j := i; j < m; j++ {
				if ws[j].pos >= ws[i].pos + t {
					break
				}
				ws[j].count += min(delta, ws[i].pos + t - ws[j].pos)
			}
		}
		fmt.Printf("%#v\n", ws)
	}
  fmt.Printf("%v\n", total_count)
}

package main

import (
	"fmt"
)

func main() {
	var res int
	q := make([]int, 0, 310)
	var M, T, R int
	fmt.Scan(&M, &T, &R)
	if R > T {
		fmt.Println(-1)
		return
	}
	for i := 0; i < M; i++ {
		var W int
		fmt.Scan(&W)
		for len(q) > 0 && q[0]+T < W {
			q = q[1:]
		}
		for j := W - (R - len(q)) + 1; j <= W; j++ {
			res++
			q = append(q, j)
		}
	}
	fmt.Println(res)
}


Luba needs your help again! Luba has n TV sets. She knows that i-th TV set will be working from moment of time li till moment ri, inclusive.Luba wants to switch off one of TV sets in order to free the socket. Let's call some TV set redundant if after switching it off the number of integer moments of time when at least one of TV sets is working won't decrease. Luba will be very upset if she has to switch off a non-redundant TV set.Help Luba by telling her the index of some redundant TV set. If there is no any, print -1.

The first line contains one integer number n (1 ≤ n ≤ 2·105) — the number of TV sets. Then n lines follow, each of them containing two integer numbers li, ri (0 ≤ li ≤ ri ≤ 109) denoting the working time of i-th TV set.

If there is no any redundant TV set, print -1. Otherwise print the index of any redundant TV set (TV sets are indexed from 1 to n). If there are multiple answers, print any of them.

NoteConsider the first sample. Initially all integer moments of time such that at least one TV set is working are from the segment [1;7]. It's easy to see that this segment won't change if we switch off the first TV set (or the second one).Note that in the fourth sample you can switch off the second TV set, since even without it all integer moments such that any of the TV sets is working denote the segment [1;4].

package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"runtime/pprof"
	"sort"
)

var stdin *bufio.Reader
var stdout *bufio.Writer
var n int

type Pair struct {
	start, end, pos int
}

type PairArray []Pair

func (a PairArray) Len() int { return len(a) }
func (a PairArray) Swap(i, j int) { a[i], a[j] = a[j], a[i]}
func (a PairArray) Less(i, j int) bool {
	if a[i].end != a[j].end {
		return a[i].end < a[j].end
	}
	return a[i].start < a[j].start
}

type SegTree struct {
	hasZero bool
	left *SegTree
	right *SegTree
}

func NewSegTree() *SegTree {
	return &SegTree{hasZero: true}
}

func (t *SegTree) rangeSetOne(left, right, start, end int) {
	if left > end || right < start {
		return
	}
	if left >= start && right <= end {
		t.hasZero = false
		t.left, t.right = nil, nil
		return
	}
	if !t.hasZero {
		return
	}
	mid := (left + right) / 2
	if t.left == nil {
		t.left = NewSegTree()
	}
	t.left.rangeSetOne(left, mid, start, end)
	if t.right == nil {
		t.right = NewSegTree()
	}
	t.right.rangeSetOne(mid + 1, right, start, end)
	t.hasZero = t.left.hasZero || t.right.hasZero
}

func (t *SegTree) rangeContainZero(left, right, start, end int) bool {
	if left > end || right < start {
		return false
	}
	if left >= start && right <= end {
		return t.hasZero;
	}
	if t.left == nil && t.right == nil {
		return t.hasZero
	}
	mid := (left + right) / 2
	return t.left.rangeContainZero(left, mid, start, end) ||
		t.right.rangeContainZero(mid + 1, right, start, end)
}

var a [200000]Pair
var minStart[200000]int

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func printf(format string, arg ...interface{}) {
	fmt.Fprintf(stdout, format, arg...)
}

func scan(arg ...interface{}) (int, error) {
	return fmt.Fscan(stdin, arg...)
}

func MaxInt(args ...int) int {
	res := int(0)
	for i, v := range args {
		if i == 0 {
			res = v
		} else if (res < v) {
			res = v
		}
	}
	return res
}

func MinInt(args ...int) int {
	res := int(0)
	for i, v := range args {
		if i == 0 {
			res = v
		} else if res > v {
			res = v
		}
	}
	return res
}

func log2(value int) uint {
	var level uint = 0
	for k := 1; k * 2 <= value; k *= 2 {
		level++
	}
	return level
}

func main() {
	if false {
		f, _ := os.Create("profile")
		pprof.StartCPUProfile(f)
		defer f.Close()
		defer pprof.StopCPUProfile()
	}
	for true {
		if _, err := scan(&n); err != nil {
			break
		}
		minValue := math.MaxInt32
		maxValue := 0
		for i := 0; i < n; i++ {
			scan(&a[i].start, &a[i].end)
			a[i].pos = i
			minValue = MinInt(minValue, a[i].start)
			maxValue = MaxInt(maxValue, a[i].end)
		}
		sort.Sort(PairArray(a[0:n]))
		minStart[n-1] = a[n-1].start
		for i := n - 2; i >= 0; i-- {
			minStart[i] = MinInt(minStart[i+1], a[i].start)
		}

		dup := -1
		t := NewSegTree()
		for i := 0; i < n; i++ {
			needCheckStart := a[i].start
			needCheckEnd := a[i].end
			if i < n - 1 {
				needCheckEnd = MinInt(needCheckEnd, minStart[i+1] - 1)
				if needCheckEnd < needCheckStart {
					dup = i
					break
				}
			}
			if !t.rangeContainZero(minValue, maxValue, needCheckStart, needCheckEnd) {
				dup = i
				break
			}
			t.rangeSetOne(minValue, maxValue, a[i].start, a[i].end)
		}
		if dup != -1 {
			dup = a[dup].pos + 1
		}
		printf("%d\n", dup)
    	stdout.Flush()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/pprof"
	"sort"
)

var stdin *bufio.Reader
var stdout *bufio.Writer
var n int

type Pair struct {
	start, end, pos int
}

type PairArray []Pair

var a [200000]Pair

func init() {
	stdin = bufio.NewReader(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func printf(format string, arg ...interface{}) {
	fmt.Fprintf(stdout, format, arg...)
}

func scan(arg ...interface{}) (int, error) {
	return fmt.Fscan(stdin, arg...)
}

func MaxInt(args ...int) int {
	res := int(0)
	for i, v := range args {
		if i == 0 {
			res = v
		} else if (res < v) {
			res = v
		}
	}
	return res
}

func log2(value int) uint {
	var level uint = 0
	for k := 1; k * 2 <= value; k *= 2 {
		level++
	}
	return level
}

func (a PairArray) Len() int { return len(a) }
func (a PairArray) Swap(i, j int) { a[i], a[j] = a[j], a[i]}
func (a PairArray) Less(i, j int) bool {
	if a[i].start != a[j].start {
		return a[i].start < a[j].start
	}
	return a[i].end > a[j].end
}

func main() {
	if false {
		f, _ := os.Create("profile")
		pprof.StartCPUProfile(f)
		defer f.Close()
		defer pprof.StopCPUProfile()
	}
	for true {
		if _, err := scan(&n); err != nil {
			break
		}
		for i := 0; i < n; i++ {
			scan(&a[i].start, &a[i].end)
			a[i].pos = i
		}
		s := PairArray(a[0:n])
		sort.Sort(s)
		dup := -1
		coveredEnd := -2
		for i := 0; i < n; i++ {
			if s[i].end <= coveredEnd + 1 {
				dup = s[i].pos + 1
				break
			}
			coveredEnd = s[i].end
		}
		printf("%d\n", dup)
    	stdout.Flush()
	}
}


This is an interactive problem.After completing the last level of the enchanted temple, you received a powerful artifact of the 255th level. Do not rush to celebrate, because this artifact has a powerful rune that can be destroyed with a single spell $$$s$$$, which you are going to find. We define the spell as some non-empty string consisting only of the letters a and b.At any time, you can cast an arbitrary non-empty spell $$$t$$$, and the rune on the artifact will begin to resist. Resistance of the rune is the edit distance between the strings that specify the casted spell $$$t$$$ and the rune-destroying spell $$$s$$$.Edit distance of two strings $$$s$$$ and $$$t$$$ is a value equal to the minimum number of one-character operations of replacing, inserting and deleting characters in $$$s$$$ to get $$$t$$$. For example, the distance between ababa and aaa is $$$2$$$, the distance between aaa and aba is $$$1$$$, the distance between bbaba and abb is $$$3$$$. The edit distance is $$$0$$$ if and only if the strings are equal.It is also worth considering that the artifact has a resistance limit  — if you cast more than $$$n + 2$$$ spells, where $$$n$$$ is the length of spell $$$s$$$, the rune will be blocked.Thus, it takes $$$n + 2$$$ or fewer spells to destroy the rune that is on your artifact. Keep in mind that the required destructive spell $$$s$$$ must also be counted among these $$$n + 2$$$ spells.Note that the length $$$n$$$ of the rune-destroying spell $$$s$$$ is not known to you in advance. It is only known that its length $$$n$$$ does not exceed $$$300$$$.

package main

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

const (
	mod = 998244353
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	a300 := make([]byte, 300)
	for i := 0; i < 300; i++ {
		a300[i] = byte('a')
	}
	b300 := make([]byte, 300)
	for i := 0; i < 300; i++ {
		b300[i] = byte('b')
	}
	fmt.Fprintf(out, "%s\n", string(a300))
	out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	a := 300 - t
	if t == 0 {
		return
	}
	fmt.Fprintf(out, "%s\n", string(b300))
	out.Flush()
	fmt.Fscanf(in, "%d\n", &t)
	b := 300 - t
	if t == 0 {
		return
	}
	length := a + b
	if a > b {
		ans := []byte{}
		for i := 0; i < a; i++ {
			ans = append(ans, 'a')
		}
		if len(ans) == length {
			fmt.Fprintf(out, "%s\n", string(ans))
			out.Flush()
			fmt.Fscanf(in, "%d\n", &t)
		}
		cur := 0
		expected := length - len(ans) - 1
		for true {
			if len(ans) == length {
				break
			}
			tryAns := make([]byte, 0)
			tryAns = append(tryAns, ans[:cur]...)
			tryAns = append(tryAns, 'b')
			tryAns = append(tryAns, ans[cur:]...)
			fmt.Fprintf(out, "%s\n", string(tryAns))
			out.Flush()
			fmt.Fscanf(in, "%d\n", &t)
			if t == expected {
				ans = tryAns
				expected--
				cur++
			} else {
				cur++
			}
		}
	} else {
		ans := []byte{}
		for i := 0; i < b; i++ {
			ans = append(ans, 'b')
		}
		if len(ans) == length {
			fmt.Fprintf(out, "%s\n", string(ans))
			out.Flush()
			fmt.Fscanf(in, "%d\n", &t)
		}
		cur := 0
		expected := length - len(ans) - 1
		for true {
			if len(ans) == length {
				break
			}
			tryAns := make([]byte, 0)
			tryAns = append(tryAns, ans[:cur]...)
			tryAns = append(tryAns, 'a')
			tryAns = append(tryAns, ans[cur:]...)
			fmt.Fprintf(out, "%s\n", string(tryAns))
			out.Flush()
			fmt.Fscanf(in, "%d\n", &t)
			if t == expected {
				ans = tryAns
				expected--
				cur++
			} else {
				cur++
			}
		}
	}
}

func reverse(a []byte) []byte {
	ans := []byte{}
	for i := len(a) - 1; i >= 0; i-- {
		ans = append(ans, a[i])
	}
	return ans
}

func first(a int) int64 {
	ans := int64(0)
	base := int64(10)
	for a > 0 {
		tail := int64(a % 10)
		a /= 10
		ans += base * tail
		base *= 100
		ans %= mod
		base %= mod
	}
	return ans
}

func second(a int) int64 {
	ans := int64(0)
	base := int64(1)
	for a > 0 {
		tail := int64(a % 10)
		a /= 10
		ans += base * tail
		base *= 100
		ans %= mod
		base %= mod
	}
	return ans
}

package main

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

const (
	mod = 998244353
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	a300 := make([]byte, 300)
	for i := 0; i < 300; i++ {
		a300[i] = byte('a')
	}
	b300 := make([]byte, 300)
	for i := 0; i < 300; i++ {
		b300[i] = byte('b')
	}
	fmt.Fprintf(out, "%s\n", string(a300))
	out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	a := 300 - t
	if t == 0 {
		return
	}
	fmt.Fprintf(out, "%s\n", string(b300))
	out.Flush()
	fmt.Fscanf(in, "%d\n", &t)
	b := 300 - t
	if t == 0 {
		return
	}
	length := a + b
	if a > b {
		ans := []byte{}
		for i := 0; i < a; i++ {
			ans = append(ans, 'a')
		}
		cur := 0
		expected := length - len(ans) - 1
		for true {
			if len(ans) == length {
				break
			}
			tryAns := make([]byte, 0)
			tryAns = append(tryAns, ans[:cur]...)
			tryAns = append(tryAns, 'b')
			tryAns = append(tryAns, ans[cur:]...)
			fmt.Fprintf(out, "%s\n", string(tryAns))
			out.Flush()
			fmt.Fscanf(in, "%d\n", &t)
			if t == expected {
				ans = tryAns
				expected--
				cur++
			} else {
				cur++
			}
		}
	} else {
		ans := []byte{}
		for i := 0; i < b; i++ {
			ans = append(ans, 'b')
		}
		cur := 0
		expected := length - len(ans) - 1
		for true {
			if len(ans) == length {
				break
			}
			tryAns := make([]byte, 0)
			tryAns = append(tryAns, ans[:cur]...)
			tryAns = append(tryAns, 'a')
			tryAns = append(tryAns, ans[cur:]...)
			fmt.Fprintf(out, "%s\n", string(tryAns))
			out.Flush()
			fmt.Fscanf(in, "%d\n", &t)
			if t == expected {
				ans = tryAns
				expected--
				cur++
			} else {
				cur++
			}
		}
	}
}

func reverse(a []byte) []byte {
	ans := []byte{}
	for i := len(a) - 1; i >= 0; i-- {
		ans = append(ans, a[i])
	}
	return ans
}

func first(a int) int64 {
	ans := int64(0)
	base := int64(10)
	for a > 0 {
		tail := int64(a % 10)
		a /= 10
		ans += base * tail
		base *= 100
		ans %= mod
		base %= mod
	}
	return ans
}

func second(a int) int64 {
	ans := int64(0)
	base := int64(1)
	for a > 0 {
		tail := int64(a % 10)
		a /= 10
		ans += base * tail
		base *= 100
		ans %= mod
		base %= mod
	}
	return ans
}


You are given two integers $$$n$$$ and $$$k$$$.Your task is to construct such a string $$$s$$$ of length $$$n$$$ that for each $$$i$$$ from $$$1$$$ to $$$k$$$ there is at least one $$$i$$$-th letter of the Latin alphabet in this string (the first letter is 'a', the second is 'b' and so on) and there are no other letters except these. You have to maximize the minimal frequency of some letter (the frequency of a letter is the number of occurrences of this letter in a string). If there are several possible answers, you can print any.You have to answer $$$t$$$ independent queries.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of queries. The next $$$t$$$ lines are contain queries, one per line. The $$$i$$$-th line contains two integers $$$n_i$$$ and $$$k_i$$$ ($$$1 \le n_i \le 100, 1 \le k_i \le min(n_i, 26)$$$) — the length of the string in the $$$i$$$-th query and the number of characters in the $$$i$$$-th query.

Print $$$t$$$ lines. In the $$$i$$$-th line print the answer to the $$$i$$$-th query: any string $$$s_i$$$ satisfying the conditions in the problem statement with constraints from the $$$i$$$-th query.

NoteIn the first example query the maximum possible minimal frequency is $$$2$$$, it can be easily seen that the better answer doesn't exist. Other examples of correct answers: "cbcabba", "ccbbaaa" (any permutation of given answers is also correct).In the second example query any permutation of first four letters is acceptable (the maximum minimal frequency is $$$1$$$).In the third example query any permutation of the given answer is acceptable (the maximum minimal frequency is $$$3$$$).

package main
import "strings"
import "fmt"

func main(){
	var t,n,k int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t = t-1 {
		fmt.Scanf("%d %d\n", &n, &k)
		c := 0
		var s strings.Builder
		for i := 0; i < n; i++ {
			s.WriteString(string('a'+c)); c++
			if c == k {
				c = 0
			}
		}
		fmt.Printf("%s\n", s.String());
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
func getInt(s *bufio.Scanner) int {
	(*s).Scan()
	n,_ := strconv.Atoi((*s).Text())
	return n
}

func buildString(n,a int)  string {
	alphabets := []byte("abcdefghijklmnopqrstuvwxyz")
	var s strings.Builder
	for i :=0 ; i < n ; i++  { s.WriteByte(alphabets[int(i%a)])}
	return s.String()
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	n := getInt(s)
	for i:=0; i<n; i++ {
		a,b := getInt(s), getInt(s)
		fmt.Println(buildString(a,b))
	}
}

package main

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

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

    var t, n, k int
    fmt.Fscan(stdin, &t)
    for t > 0 {
        t--
        fmt.Fscan(stdin, &n, &k)

        var x int = 0
        var res []byte = make([]byte, n)
        for i, _ := range(res) {
            res[i] = 97 + byte(x)
            x = (x + 1) % k
        }
        fmt.Println(string(res))
    }
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var tc int

	for fmt.Scan(&tc); tc > 0; tc-- {
		var n, k int
		fmt.Scan(&n, &k)
		var sb strings.Builder
		for n > 0 {
			sb.WriteString(string('a' + (n % k)))
			n--
		}
		fmt.Printf("%s\n", sb.String())
	}
}

package main

import "fmt"

func main() {
	var tc int
	fmt.Scan(&tc)

	for tc > 0 {
		var n, k int
		fmt.Scan(&n, &k)
		for n > 0 {
			fmt.Printf("%c", 'a' + n % k)
			n--
		}
		fmt.Println()
		tc--
	}
}

package main

import "fmt"

func main() {
	var tc int

	for fmt.Scan(&tc); tc > 0; tc-- {
		var n, k int
		fmt.Scan(&n, &k)
		for n > 0 {
			fmt.Printf("%c", 'a' + n % k)
			n--
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
	"math"
)

func main(){
	var T int
	fmt.Scan(&T)
	for {
		if T <= 0 {
			return
		}
		T--
		var n, k int
		fmt.Scan(&n, &k)
		clen := int(math.Floor(float64(1.0 * n / k)))
		for i := 0; i < clen; i++ {
			for j := 0; j < k; j++ {
				fmt.Print(string('a' + j))
			}
		}
		for i := 0; i < n - clen * k; i++ {
			fmt.Print(string('a' + i))
		}
		fmt.Println()
	}
}

package main

import "fmt"
var letters string = "abcdefghijklmnopqrstuvwxyz"

func main() {
	var request, length, limit int
	fmt.Scan(&request)

	for i := 0; i < request; i++ {
		fmt.Scan(&length, &limit)
		repeat := int(length / limit)

		for j := 0; j < repeat; j++ {
			for x := 0; x < limit; x++ {
				fmt.Printf("%s", string(letters[x]))
			}
		}

		remain := length - repeat * limit
		for x := 0; x < remain; x++ {
			fmt.Printf("%s", string(letters[x]))
		}

		fmt.Printf("\n")
	}
}

package main

import "fmt"

var n, k int

func main() {

	var T int;
	fmt.Scanf("%d\n", &T)
	// fmt.Print(T)
	for t := 0; t < T; t++{
		fmt.Scanf("%d%d\n", &n, &k)
		j := 0;
		for i := 0; i < n; i++ {
			fmt.Printf("%c", 'a' + j)
			j++;
			j %= k;
		}
		fmt.Println()
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}
func getI() int {
	return int(getI64())
}
func getF() float64 {
	scanner.Scan()
	x, _ := strconv.ParseFloat(scanner.Text(), 64)
	return x
}
func getS() string {
	scanner.Scan()
	return scanner.Text()
}

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

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

const alphabets = "abcdefghijklmnopqrstuvwxyz"

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	Problem1092A()
}

func Problem1092A() {
	t := getI()
	for i:=0;i < t;i++ {
		n := getI()
		k := getI()
		for j := 0; j < n; j++ {
			fmt.Printf("%s", (fmt.Sprintf("%c", alphabets[j%k])))
		}
		fmt.Printf("\n")
	}
}

package main

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

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

	for fmt.Fscan(reader, &t); t > 0; t-- {
		var n, k int

		fmt.Fscan(reader, &n, &k)

		var answer string

		cnt := "a"
		for i := 0; i < n; i++ {
			if int(cnt[0]-"a"[0]) >= k {
				cnt = "a"
			}

			answer += cnt

			cnt = string(cnt[0] + 1)
		}

		fmt.Println(answer)
	}
}

package main

import "fmt"

func main() {
	var n, k, t int
	fmt.Scan(&t)
	for ; t > 0; t-- {
		fmt.Scan(&n, &k)
		s := ""
		for i := 0; i < n; i++ {
			s += string('a' + i%k)
		}
		fmt.Println(s)
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		cnt := 0
		for cnt < a {
			for j := 0; j < b; j++ {
				fmt.Printf("%c", 'a'+j)
				cnt++
				if cnt >= a {
					break
				}
			}
		}
		fmt.Printf("\n")
	}
}

package main

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

func main(){
	buf := bufio.NewReader(os.Stdin)
	var n,t,k int
	fmt.Fscanf(buf, "%d\n", &t)
	a := byte('a')
	for i:= 1;i <= t;i++{
		fmt.Fscanf(buf, "%d %d\n", &n,&k)
		var f int = 0
		for j := 0;j < n;j++{
			fmt.Printf("%s",string(a+byte(f)))
			f++
			if f >=k{
				f=0
			}
		}
		fmt.Printf("\n")
	}

}

package main

import "fmt"

func main(){

	var t,n,k int
	fmt.Scanf("%d\n",&t)
	for ;t!=0;t--{
		fmt.Scanf("%d%d\n",&n,&k)
		for i:=0;i<n;i++{
			fmt.Printf("%c",i%k + 'a')
		}
		fmt.Println()
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
func getInt(s *bufio.Scanner) int {
	(*s).Scan()
	n,_ := strconv.Atoi((*s).Text())
	return n
}

func buildString(n,a int)  string {
	alphabets := []byte("abcdefghijklmnopqrstuvwyz")
	var s strings.Builder
	for i :=0 ; i < n ; i++  { s.WriteByte(alphabets[int(i%a)])}
	return s.String()
}

func main() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	n := getInt(s)
	for i:=0; i<n; i++ {
		a,b := getInt(s), getInt(s)
		fmt.Println(buildString(a,b))
	}
}

package main

import "fmt"

func main() {
	var tc int
	fmt.Scanf("%d", &tc)
	for tc > 0 {
		var n, k int
		fmt.Scanf("%d %d", &n, &k)
		for n > 0 {
			fmt.Printf("%c", 'a' + n % k)
			n--
		}
		fmt.Println()
		tc--
	}
}

package main

import "fmt"
var letters string = "abcdefghijklmnopqrstuvwxyz"

func main() {
	var request, length, limit int
	fmt.Scan(&request)

	for i := 0; i < request; i++ {
		fmt.Scan(&length, &limit)
		repeat := int(length / limit)

		for j := 0; j < repeat; j++ {
			for x := 0; x < limit; x++ {
				fmt.Printf("%s", string(letters[x]))
			}
		}

		if length % repeat != 0 {
			fmt.Printf("%s\n", "a")
		} else {
			fmt.Printf("\n")
		}
	}
}

package main

import "fmt"
var letters string = "abcdefghijklmnopqrstuvwxyz"

func main() {
	var request, length, limit int
	fmt.Scan(&request)

	for i := 0; i < request; i++ {
		fmt.Scan(&length, &limit)
		repeat := int(length / limit)

		for j := 0; j < repeat; j++ {
			for x := 0; x < limit; x++ {
				fmt.Printf("%s", string(letters[x]))
			}
		}

		if repeat * limit != length {
			fmt.Println("a")
		} else {
			fmt.Printf("\n")
		}
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}
func getI() int {
	return int(getI64())
}
func getF() float64 {
	scanner.Scan()
	x, _ := strconv.ParseFloat(scanner.Text(), 64)
	return x
}
func getS() string {
	scanner.Scan()
	return scanner.Text()
}

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

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

const alphabets = "abcdefghijklmnopqrstuvwxyz"

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	Problem1092A()
}

func Problem1092A() {
	t := getI()
	for i:=0;i < t;i++ {
		n := getI()
		k := getI()
		for j := 0; j < n; j++ {
			print(fmt.Sprintf("%c", alphabets[j%k]))
		}
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}
func getI() int {
	return int(getI64())
}
func getF() float64 {
	scanner.Scan()
	x, _ := strconv.ParseFloat(scanner.Text(), 64)
	return x
}
func getS() string {
	scanner.Scan()
	return scanner.Text()
}

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

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

const alphabets = "abcdefghijklmnopqrstuvwxyz"

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	Problem1092A()
}

func Problem1092A() {
	t := getI()
	sol := make([]string, t)
	for i:=0;i < t;i++ {
		n := getI()
		k := getI()
		str := ""
		for j := 0; j < n; j++ {
			for alpha := 0; alpha < k; alpha++ {
				if len(str) < n {
					str += fmt.Sprintf("%c", alphabets[alpha])
				}else {
					break
				}
			}
		}
		sol[i] = str
	}

	for _, item := range sol {
		println(item)
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}
func getI() int {
	return int(getI64())
}
func getF() float64 {
	scanner.Scan()
	x, _ := strconv.ParseFloat(scanner.Text(), 64)
	return x
}
func getS() string {
	scanner.Scan()
	return scanner.Text()
}

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

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

const alphabets = "abcdefghijklmnopqrstuvwxyz"

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	Problem1092A()
}

func Problem1092A() {
	t := getI()
	for i:=0;i < t;i++ {
		n := getI()
		k := getI()
		for j := 0; j < n; j++ {
			fmt.Printf("%s", (fmt.Sprintf("%c", alphabets[j%k])))
		}
	}
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
	scanner.Scan()
	x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return x
}
func getI() int {
	return int(getI64())
}
func getF() float64 {
	scanner.Scan()
	x, _ := strconv.ParseFloat(scanner.Text(), 64)
	return x
}
func getS() string {
	scanner.Scan()
	return scanner.Text()
}

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

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

const alphabets = "abcdefghijklmnopqrstuvwxyz"

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	Problem1092A()
}

func Problem1092A() {
	t := getI()
	for i:=0;i < t;i++ {
		n := getI()
		k := getI()
		for j := 0; j < n; j++ {
			fmt.Printf("%s \n", (fmt.Sprintf("%c", alphabets[j%k])))
		}
	}
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var a, b int
		fmt.Scanf("%d %d\n", &a, &b)
		for j := 0; j < b; j++ {
			fmt.Printf("%c", 'a'+j)
		}
		for j := b; j < a; j++ {
			fmt.Printf("a")
		}
		fmt.Printf("\n")
	}
}

package main

import "fmt"

func main(){

	var t,n,k int
	fmt.Scan(&t)
	for ;t!=0;t--{
		fmt.Scanf("%d%d",&n,&k)
		for i:=0;i<n;i++{
			fmt.Printf("%c",i%k + 'a')
		}
		fmt.Println()
	}
}


Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.Du will chat in the group for $$$n$$$ days. On the $$$i$$$-th day:  If Du can speak, he'll make fun of Boboniu with fun factor $$$a_i$$$. But after that, he may be muzzled depending on Boboniu's mood.  Otherwise, Du won't do anything. Boboniu's mood is a constant $$$m$$$. On the $$$i$$$-th day:  If Du can speak and $$$a_i>m$$$, then Boboniu will be angry and muzzle him for $$$d$$$ days, which means that Du won't be able to speak on the $$$i+1, i+2, \cdots, \min(i+d,n)$$$-th days.  Otherwise, Boboniu won't do anything. The total fun factor is the sum of the fun factors on the days when Du can speak.Du asked you to find the maximum total fun factor among all possible permutations of $$$a$$$.

The first line contains three integers $$$n$$$, $$$d$$$ and $$$m$$$ ($$$1\le d\le n\le 10^5,0\le m\le 10^9$$$). The next line contains $$$n$$$ integers $$$a_1, a_2, \ldots,a_n$$$ ($$$0\le a_i\le 10^9$$$).

Print one integer: the maximum total fun factor among all permutations of $$$a$$$.

NoteIn the first example, you can set $$$a'=[15, 5, 8, 10, 23]$$$. Then Du's chatting record will be:  Make fun of Boboniu with fun factor $$$15$$$.  Be muzzled.  Be muzzled.  Make fun of Boboniu with fun factor $$$10$$$.  Make fun of Boboniu with fun factor $$$23$$$. Thus the total fun factor is $$$48$$$.

package main

import (
	"bufio"
	"fmt"
	"hash/crc32"
	"io"
	"os"
	"sort"
)

func stringToHash(val string, max uint32) uint32 {
	ieee := crc32.NewIEEE()
	io.WriteString(ieee, fmt.Sprintf("%v", val))
	return ieee.Sum32() % max
}

type Int64Slice []int64

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

func splitAndSort(mat []int64, m int64) (minMat []int64, maxMat []int64) {
	//minMat := make([]int64,0)
	//maxMat := make([]int64,0)
	for _, item := range mat {
		if item > m {
			maxMat = append(maxMat, item)
		} else {
			minMat = append(minMat, item)
		}
	}
	sort.Sort(Int64Slice(minMat))
	sort.Sort(Int64Slice(maxMat))
	return minMat, maxMat
}
func minValue(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func solve(mat []int64, m int64, n, d int) int64 {
	minMat, maxMat := splitAndSort(mat, m)
	minlen := len(minMat)

	sum := make([]int64, minlen)
	for index, item := range minMat {
		if index == 0 {
			sum[index] = item
		} else {
			sum[index] = sum[index-1] + item
		}
	}
	ans := int64(0)
	if minlen > 0 {
		ans = sum[minValue(n-1, minlen-1)]
	}
	maxSum := int64(0)
	weiCnt := 0
	for index, item := range maxMat {
		if index == 0 {
			weiCnt = 1
		} else {
			weiCnt = weiCnt + d + 1
		}
		if weiCnt > n {
			break
		}
		maxSum = maxSum + item
		tmpAns := maxSum
		if n-weiCnt > 0 && minlen > 0{
			tmpAns = maxSum + sum[minValue(minlen-1, n-weiCnt-1)]
		}
		if tmpAns > ans {
			ans = tmpAns
		}
	}
	return ans

}
func main() {
	in := bufio.NewReader(os.Stdin)
	//out := bufio.NewWriter(os.Stdout)
	var n, d int
	var m int64
	fmt.Fscanf(in, "%d %d %d\n", &n, &d, &m)
	mat := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &mat[i])
	}
	fmt.Printf("%v",solve(mat, m, n, d))
	//fmt.Fprintln(out, solve(mat, m, n, d))
	//mat := []int64{8,10,15,23,5}
	//fmt.Printf("%v\n",solve(mat,11,5,2))
	//
	//
	//mat = []int64{20, 5, 8, 2, 18, 16, 2, 16, 16, 1, 5, 16, 2, 13, 6, 16, 4, 17, 21, 7}
	//fmt.Printf("%v\n",solve(mat,16,20,2))

}

/*
URL:
https://codeforces.com/contest/1395/problem/D
*/

package main

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

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

var (
	// n, d, m    int
	n, d       int
	m          int64
	A          []int64
	big, small []int64
)

func main() {
	// n, d, m = ReadInt3()
	n, d = ReadInt2()
	m = ReadInt64()
	A = ReadInt64Slice(n)

	for _, a := range A {
		// if a > int64(m) {
		if a > m {
			big = append(big, a)
		} else {
			small = append(small, a)
		}
	}

	// bigは降順, smallは昇順
	sort.Slice(big, func(i, j int) bool { return big[i] > big[j] })
	sort.Slice(small, func(i, j int) bool { return small[i] < small[j] })

	bs := make([]int64, len(big)+1)
	for i := 0; i < len(big); i++ {
		bs[i+1] = bs[i] + big[i]
	}
	ss := make([]int64, len(small)+1)
	for i := 0; i < len(small); i++ {
		ss[i+1] = ss[i] + small[i]
	}

	var ans int64
	smallAll := Sum(small...)
	if len(big) == 0 {
		ans = smallAll
	} else {
		ans = 0
	}
	for i := 1; i <= len(big); i++ {
		cur := bs[i]
		// mini, maxi := d*(i-1), d*i
		mini, maxi := int(Min(int64(n), int64(d)*int64(i-1))), int(Min(int64(n), int64(d)*int64(i)))
		resBig := len(big) - i

		if resBig > maxi {
			continue
		}
		if mini <= resBig && resBig <= maxi {
			cur += smallAll
			ChMax(&ans, cur)
			continue
		}

		nokori := mini - resBig
		if nokori > len(small) {
			continue
		}
		cur += smallAll - ss[nokori]
		ChMax(&ans, cur)
	}
	fmt.Println(ans)
}

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

// 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 *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// Sum returns multiple integers sum.
func Sum(integers ...int64) int64 {
	var s int64
	s = 0

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

	return s
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	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())
}

/*********** Output ***********/

// 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])
		res = append(res, []rune(str)...)

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

	return string(res)
}

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

	for i := 0; i < len(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)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// 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
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

const (
	mod = 1000000009
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}
func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	n, d, m := nextInt(), nextInt(), nextLong()
	less, more := []int64{}, []int64{}
	for i := 0; i < n; i++ {
		x := nextLong()
		if x > m {
			more = append(more, x)
		} else {
			less = append(less, x)
		}
	}
	sort.Slice(less, func(a, b int) bool {
		return less[a] < less[b]
	})
	sort.Slice(more, func(a, b int) bool {
		return more[a] < more[b]
	})

	var res, best int64 = 0, 0
	for _, v := range less {
		res += v
	}

	best = res

	curr := 0
	for i := 1; i <= len(more); i++ {
		if (i-1)*(d+1) >= n {
			break
		}
		res += more[len(more)-i]
		ext := Min((i-1)*(d+1)+1-len(more), n)
		for ; curr < ext; curr++ {
			res -= less[curr]
		}
		if res > best {
			best = res
		}
	}
	printf("%d\n", best)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		file1, err := os.Open("input.txt")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create("output.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// start := time.Now()

	// for t := nextInt(); t > 0; t-- {
	solve()
	// }

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, d, m := readThreeNums(reader)
	A := readNNums(reader, n)
	fmt.Println(solve(n, d, m, A))
}

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

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

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

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

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

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

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

	return i
}

const N_INF = -(int64(1) << 60)

func solve(n int, d int, m int, A []int) int64 {
	X := make([]int, 0, n)
	Y := make([]int, 0, n)

	for i := 0; i < n; i++ {
		if A[i] > m {
			X = append(X, A[i])
		} else {
			Y = append(Y, A[i])
		}
	}

	sort.Ints(X)
	sort.Ints(Y)

	reverse(X)
	reverse(Y)

	XX := sum(X)
	YY := sum(Y)

	if len(X) == 0 {
		return YY[n]
	}

	l := len(YY)
	for j := l; j <= n; j++ {
		YY = append(YY, YY[l-1])
	}

	k := len(X)
	var res int64
	N := int64(n)
	for i := (k + d) / (d + 1); i <= k; i++ {
		if int64(i-1)*int64(d+1)+1 <= N {
			j := n - (i-1)*(d+1) - 1
			tmp := XX[i] + YY[j]
			if tmp > res {
				res = tmp
			}
		}
	}
	return res
}

func sum(arr []int) []int64 {
	n := len(arr)
	res := make([]int64, n+1)
	for i := 0; i < n; i++ {
		res[i+1] = res[i] + int64(arr[i])
	}
	return res
}

type Pair struct {
	first  int
	second int64
}

func reverse(arr []int) {
	for i, j := 0, len(arr)-1; i < j; i, j = i+1, j-1 {
		arr[i], arr[j] = arr[j], arr[i]
	}
}

/*
URL:
https://codeforces.com/contest/1395/problem/D
*/

package main

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

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

var (
	// n, d, m    int
	n, d       int
	m          int64
	A          []int64
	big, small []int64
)

func main() {
	// n, d, m = ReadInt3()
	n, d = ReadInt2()
	m = ReadInt64()
	A = ReadInt64Slice(n)

	for _, a := range A {
		// if a > int64(m) {
		if a > m {
			big = append(big, a)
		} else {
			small = append(small, a)
		}
	}

	// bigは降順, smallは昇順
	sort.Slice(big, func(i, j int) bool { return big[i] > big[j] })
	sort.Slice(small, func(i, j int) bool { return small[i] < small[j] })

	bs := make([]int64, len(big)+1)
	for i := 0; i < len(big); i++ {
		bs[i+1] = bs[i] + big[i]
	}
	ss := make([]int64, len(small)+1)
	for i := 0; i < len(small); i++ {
		ss[i+1] = ss[i] + small[i]
	}

	smallAll := Sum(small...)
	ans := smallAll
	for i := 1; i <= len(big); i++ {
		cur := bs[i]
		mini, maxi := d*(i-1), d*i
		resBig := len(big) - i

		if resBig > maxi {
			continue
		}
		if mini <= resBig && resBig <= maxi {
			cur += smallAll
			ChMax(&ans, cur)
			continue
		}

		nokori := mini - resBig
		if nokori > len(small) {
			continue
		}
		cur += smallAll - ss[nokori]
		ChMax(&ans, cur)
	}
	fmt.Println(ans)
}

// 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 *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// Sum returns multiple integers sum.
func Sum(integers ...int64) int64 {
	var s int64
	s = 0

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

	return s
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	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())
}

/*********** Output ***********/

// 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])
		res = append(res, []rune(str)...)

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

	return string(res)
}

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

	for i := 0; i < len(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)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// 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
}

/*
URL:
https://codeforces.com/contest/1395/problem/D
*/

package main

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

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

var (
	// n, d, m    int
	n, d       int
	m          int64
	A          []int64
	big, small []int64
)

func main() {
	// n, d, m = ReadInt3()
	n, d = ReadInt2()
	m = ReadInt64()
	A = ReadInt64Slice(n)

	for _, a := range A {
		// if a > int64(m) {
		if a > m {
			big = append(big, a)
		} else {
			small = append(small, a)
		}
	}

	// bigは降順, smallは昇順
	sort.Slice(big, func(i, j int) bool { return big[i] > big[j] })
	sort.Slice(small, func(i, j int) bool { return small[i] < small[j] })

	bs := make([]int64, len(big)+1)
	for i := 0; i < len(big); i++ {
		bs[i+1] = bs[i] + big[i]
	}
	ss := make([]int64, len(small)+1)
	for i := 0; i < len(small); i++ {
		ss[i+1] = ss[i] + small[i]
	}

	var ans int64
	smallAll := Sum(small...)
	if len(big) == 0 {
		ans = smallAll
	} else {
		ans = 0
	}
	for i := 1; i <= len(big); i++ {
		cur := bs[i]
		mini, maxi := d*(i-1), d*i
		resBig := len(big) - i

		if resBig > maxi {
			continue
		}
		if mini <= resBig && resBig <= maxi {
			cur += smallAll
			ChMax(&ans, cur)
			continue
		}

		nokori := mini - resBig
		if nokori > len(small) {
			continue
		}
		cur += smallAll - ss[nokori]
		ChMax(&ans, cur)
	}
	fmt.Println(ans)
}

// 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 *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// Sum returns multiple integers sum.
func Sum(integers ...int64) int64 {
	var s int64
	s = 0

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

	return s
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	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())
}

/*********** Output ***********/

// 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])
		res = append(res, []rune(str)...)

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

	return string(res)
}

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

	for i := 0; i < len(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)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// 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
}

/*
URL:
https://codeforces.com/contest/1395/problem/D
*/

package main

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

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

var (
	n, d, m    int
	A          []int64
	big, small []int64
)

func main() {
	n, d, m = ReadInt3()
	A = ReadInt64Slice(n)

	for _, a := range A {
		if a > int64(m) {
			big = append(big, a)
		} else {
			small = append(small, a)
		}
	}

	// bigは降順, smallは昇順
	sort.Slice(big, func(i, j int) bool { return big[i] > big[j] })
	sort.Slice(small, func(i, j int) bool { return small[i] < small[j] })

	bs := make([]int64, len(big)+1)
	for i := 0; i < len(big); i++ {
		bs[i+1] = bs[i] + big[i]
	}
	ss := make([]int64, len(small)+1)
	for i := 0; i < len(small); i++ {
		ss[i+1] = ss[i] + small[i]
	}

	smallAll := Sum(small...)
	ans := smallAll
	for i := 1; i <= len(big); i++ {
		cur := bs[i]
		mini, maxi := d*(i-1), d*i
		resBig := len(big) - i

		if resBig > maxi {
			continue
		}
		if mini <= resBig && resBig <= maxi {
			cur += smallAll
			ChMax(&ans, cur)
			continue
		}

		nokori := mini - resBig
		if nokori > len(small) {
			continue
		}
		cur += smallAll - ss[nokori]
		ChMax(&ans, cur)
	}
	fmt.Println(ans)
}

// 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 *int64, target int64) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// Sum returns multiple integers sum.
func Sum(integers ...int64) int64 {
	var s int64
	s = 0

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

	return s
}

const (
	// General purpose
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

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

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

/********** 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...)

/*********** Input ***********/

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

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	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())
}

/*********** Output ***********/

// 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])
		res = append(res, []rune(str)...)

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

	return string(res)
}

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

	for i := 0; i < len(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)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

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

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// 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
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

const (
	mod = 1000000009
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}
func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	n, d, m := nextInt(), nextInt(), nextLong()
	less, more := []int64{}, []int64{}
	for i := 0; i < n; i++ {
		x := nextLong()
		if x > m {
			more = append(more, x)
		} else {
			less = append(less, x)
		}
	}
	sort.Slice(less, func(a, b int) bool {
		return less[a] < less[b]
	})
	sort.Slice(more, func(a, b int) bool {
		return more[a] < more[b]
	})

	var res, best int64 = 0, 0
	for _, v := range less {
		res += v
	}

	curr := 0
	for i := 1; i <= len(more); i++ {
		if (i-1)*(d+1) >= n {
			break
		}
		res += more[len(more)-i]
		ext := Min((i-1)*(d+1)+1-len(more), n)
		for ; curr < ext; curr++ {
			res -= less[curr]
		}
		if res > best {
			best = res
		}
	}
	printf("%d\n", best)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		file1, err := os.Open("input.txt")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create("output.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// start := time.Now()

	// for t := nextInt(); t > 0; t-- {
	solve()
	// }

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

const (
	mod = 1000000009
)

func mult(a, b int64) int64 {
	return (a * b) % mod
}
func add(a, b int64) int64 {
	return (a + b) % mod
}
func sub(a, b int64) int64 {
	return (a - b + mod) % mod
}

func solve() {
	n, d, m := nextInt(), nextInt(), nextLong()
	less, more := []int64{}, []int64{}
	for i := 0; i < n; i++ {
		x := nextLong()
		if x > m {
			more = append(more, x)
		} else {
			less = append(less, x)
		}
	}
	sort.Slice(less, func(a, b int) bool {
		return less[a] < less[b]
	})
	sort.Slice(more, func(a, b int) bool {
		return more[a] < more[b]
	})

	var res, best int64 = 0, 0
	for _, v := range less {
		res += v
	}

	res = best

	curr := 0
	for i := 1; i <= len(more); i++ {
		if (i-1)*(d+1) >= n {
			break
		}
		res += more[len(more)-i]
		ext := Min((i-1)*(d+1)+1-len(more), n)
		for ; curr < ext; curr++ {
			res -= less[curr]
		}
		if res > best {
			best = res
		}
	}
	printf("%d\n", best)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		file1, err := os.Open("input.txt")
		if err != nil {
			log.Fatal(err)
		}
		file2, err := os.Create("output.txt")
		if err != nil {
			log.Fatal(err)
		}
		in = bufio.NewReaderSize(file1, 8192)
		out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	// start := time.Now()

	// for t := nextInt(); t > 0; t-- {
	solve()
	// }

	// printf("%v\n", time.Now().Sub(start))
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n, d, m := readThreeNums(reader)
	A := readNNums(reader, n)
	fmt.Println(solve(n, d, m, A))
}

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

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

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

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

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

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

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

	return i
}

const N_INF = -(int64(1) << 60)

func solve(n int, d int, m int, A []int) int64 {
	X := make([]int, 0, n)
	Y := make([]int, 0, n)

	for i := 0; i < n; i++ {
		if A[i] > m {
			X = append(X, A[i])
		} else {
			Y = append(Y, A[i])
		}
	}

	sort.Ints(X)
	sort.Ints(Y)

	reverse(X)
	reverse(Y)

	XX := sum(X)
	YY := sum(Y)

	if len(X) == 0 {
		return YY[n]
	}

	l := len(YY)
	for j := l; j <= n; j++ {
		YY = append(YY, YY[l-1])
	}

	k := len(X)
	var res int64

	for i := (k + d) / (d + 1); i <= k; i++ {
		if (i-1)*(d+1)+1 <= n && (i-1)*(d+1) >= 0 {
			j := n - (i-1)*(d+1) - 1
			tmp := XX[i] + YY[j]
			if tmp > res {
				res = tmp
			}
		}
	}
	return res
}

func sum(arr []int) []int64 {
	n := len(arr)
	res := make([]int64, n+1)
	for i := 0; i < n; i++ {
		res[i+1] = res[i] + int64(arr[i])
	}
	return res
}

type Pair struct {
	first  int
	second int64
}

func reverse(arr []int) {
	for i, j := 0, len(arr)-1; i < j; i, j = i+1, j-1 {
		arr[i], arr[j] = arr[j], arr[i]
	}
}


Having endured all the hardships, Lara Croft finally found herself in a room with treasures. To her surprise she didn't find golden mountains there. Lara looked around and noticed on the floor a painted table n × m panels in size with integers written on the panels. There also was a huge number of stones lying by the wall. On the pillar near the table Lara found a guidance note which said that to get hold of the treasures one has to choose some non-zero number of the first panels in each row of the table and put stones on all those panels to push them down. After that she will receive a number of golden coins equal to the sum of numbers written on the chosen panels. Lara quickly made up her mind on how to arrange the stones and was about to start when she noticed an addition to the note in small font below. According to the addition, for the room ceiling not to crush and smash the adventurer, the chosen panels should form a comb. It was explained that the chosen panels form a comb when the sequence c1, c2, ..., cn made from the quantities of panels chosen in each table line satisfies the following property: c1 > c2 < c3 > c4 < ..., i.e. the inequation mark interchanges between the neighboring elements. Now Lara is bewildered and doesn't know what to do. Help her to determine the largest number of coins she can get and survive at the same time.

The first line contains a pair of integers n, m (2 ≤ n, m ≤ 1500). Next n lines contain m integers each — that is the table itself. The absolute value of the numbers in the table does not exceed 10000.

Print the single number — the maximum number of coins Lara can get.

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func getSum(m int) []int64 {
  sum := make([]int64, m)
  sum[0] = getI64()
  for c := 1; c < m; c++ {
    sum[c] = sum[c - 1] + getI64()
  }
  return sum
}

func getMax(values []int64, left, right int) int64 {
  max := values[left]
  for i := left + 1; i < right; i++ {
    if values[i] > max {
      max = values[i]
    }
  }
  return max
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer = bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m := getI(), getI()
  sum := getSum(m)
  for r := 1; r < n; r++ {
    best := make([]int64, m)
    if r % 2 == 1 {
      best[m - 1] = sum[m - 1]
      for c := m - 2; c >= 0; c-- {
        best[c] = best[c + 1]
        if sum[c] > best[c] {
          best[c] = sum[c]
        }
      }
    } else {
      best[0] = sum[0]
      for c := 1; c < m; c++ {
        best[c] = best[c - 1]
        if sum[c] > best[c] {
          best[c] = sum[c]
        }
      }
    }
    sum = getSum(m)
    if r % 2 == 1 {
      for c := m - 2; c >= 0; c-- {
        sum[c] += best[c + 1]
      }
    } else {
      for c := 1; c < m; c++ {
        sum[c] += best[c - 1]
      }
    }
  }

  var result int64
  if n % 2 == 0 {
    result = getMax(sum, 0, m - 1)
  } else {
    result = getMax(sum, 1, m)
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}


You are given matrix with n rows and n columns filled with zeroes. You should put k ones in it in such a way that the resulting matrix is symmetrical with respect to the main diagonal (the diagonal that goes from the top left to the bottom right corner) and is lexicographically maximal.One matrix is lexicographically greater than the other if the first different number in the first different row from the top in the first matrix is greater than the corresponding number in the second one.If there exists no such matrix then output -1.

The first line consists of two numbers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ 106).

If the answer exists then output resulting matrix. Otherwise output -1.

package main

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

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

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

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

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

var n, k, oo int
var a [][]int

func main() {
	for I(&n, &k) == nil {
		solve()
	}
	w.Flush()
}

func solve() {
	if k > n {
		if k > n*n {
			O("-1\n")
			return
		}
	}
	a = make([][]int, n)
	for i := range a {
		a[i] = make([]int, n)
	}
	for i := range a {
		for j := i; j < n; j++ {
			if i != j && k >= 2 {
				k -= 2
				a[i][j] = 1
				a[j][i] = 1
			}
			if i == j && k >= 1 {
				k--
				a[i][j] = 1
			}
		}
	}
	for i := range a {
		for j := 0; j < n; j++ {
			O(a[i][j])
			if j != n-1 {
				O(" ")
			}
		}
		O("\n")
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	k, _ := strconv.Atoi(scanner.Text())
	if n*n < k {
		fmt.Println(-1)
		os.Exit(0)
	}
	m := make([][]int, n)
	for i := 0; i < n; i++ {
		m[i] = make([]int, n)
	}
	for i := 0; i < n; i++ {
		if k == 0 {
			break
		}
		k--
		m[i][i] = 1
		j := i + 1
		for k >= 2 && j < n {
			m[i][j] = 1
			m[j][i] = 1
			k -= 2
			j++
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n-1; j++ {
			fmt.Printf("%d ", m[i][j])
		}
		fmt.Println(m[i][n-1])
	}
}

package main

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

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

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

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

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

var n, k, oo int
var a [][]int

func main() {
	for I(&n, &k) == nil {
		solve()
	}
	w.Flush()
}

func solve() {
	if k > n {
		if k > n*n || (k-n)%2 == 1 {
			O("-1\n")
			return
		}
	}
	a = make([][]int, n)
	for i := range a {
		a[i] = make([]int, n)
	}
	oo = 1
	do(0, 0, 0)
	for i := range a {
		for j := 0; j < n; j++ {
			O(a[i][j])
			if j != n-1 {
				O(" ")
			}
		}
		O("\n")
	}
}

func do(i, j, d int) {
	if i >= n || j >= n {
		return
	}
	if d == 0 {
		for i < n && j < n && k > 0 {
			a[i][j] = 1
			k--
			i++
			j++
		}
		if k > 0 {
			do(0, oo, 1)
		}
	} else if d == 1 {
		do(i, j, -1)
		do(i+oo, j-oo, 2)
	} else if d == 2 {
		do(i, j, -1)
		do(i, j, 3)
	} else if d == 3 {
		if j >= n-1 || i >= n-1 {
			oo++
			do(0, oo, 1)
		} else {
			do(i-oo+1, j+oo+1, 1)
		}
	} else if d == -1 {
		if k > 0 {
			k--
			a[i][j] = 1
		}
	}
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	scanner.Scan()
	k, _ := strconv.Atoi(scanner.Text())
	if n*n < k {
		fmt.Println(-1)
		os.Exit(0)
	}
	m := make([][]int, n)
	for i := 0; i < n; i++ {
		m[i] = make([]int, n)
	}
Loop:
	for i := 0; i < n; i++ {
		if k == 0 {
			break Loop
		}
		k--
		m[i][i] = 1
		j := i
		for k > 1 && j < n {
			m[i][j] = 1
			m[j][i] = 1
			k -= 2
			j++
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n-1; j++ {
			fmt.Printf("%d ", m[i][j])
		}
		fmt.Println(m[i][n-1])
	}
}


Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation multiple times:  he chooses two elements of the array ai, aj (i ≠ j);  he simultaneously increases number ai by 1 and decreases number aj by 1, that is, executes ai = ai + 1 and aj = aj - 1. The given operation changes exactly two distinct array elements. Polycarpus can apply the described operation an infinite number of times. Now he wants to know what maximum number of equal array elements he can get if he performs an arbitrary number of such operation. Help Polycarpus.

The first line contains integer n (1 ≤ n ≤ 105) — the array size. The second line contains space-separated integers a1, a2, ..., an (|ai| ≤ 104) — the original array.

Print a single integer — the maximum number of equal array elements he can get if he performs an arbitrary number of the given operation.

package main
import (
	"fmt"
	//"bufio"
	//"os"
	//"strconv"
)

func main() {
	var a,n,s int
	fmt.Scan(&n)
	for i:=0;i<n;i++ {
		fmt.Scan(&a)
		s+=a
	}
	if s%n==0 {
		fmt.Println(n)
	} else {
		fmt.Println(n-1)
	}

}

package main

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

func scanInt(scanner *bufio.Scanner) int64 {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return int64(x)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	sum := int64(0)
	for i := int64(0); i < n; i++ {
		sum += scanInt(scanner)
	}
	result := n-1
	if sum%n == 0 {
		result++
	}
	writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    total := 0;
    for i := 0; i < n; i++ {
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        total += a
    }
    if total%n == 0 { fmt.Println(n) } else { fmt.Println(n-1) }
}

// 246B-mic
package main

import (
    "fmt"
)

func main() {
    var n, sum int
    var a [100005]int
    fmt.Scan(&n)
    if n == 1 {
        fmt.Println("1")
        return
    }
    for i := 1; i <= n; i++ {
        fmt.Scan(&a[i])
        sum += a[i]
    }
    if sum%n != 0 {
        fmt.Println(n - 1)
        return
    }
    sum /= n
    for i := 1; i < n; i++ {
        a[i+1] += a[i] - sum
    }
    if a[n] == sum {
        fmt.Println(n)
    } else {
        fmt.Println(n - 1)
    }
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	sum := 0
	for i := 0; i < n; i++ {
		sum += scanInt(scanner)
	}
	result := sum % n
	if n-result > result {
		result = n-result
	}
	writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

func scanInt(scanner *bufio.Scanner) int64 {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return int64(x)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	head := scanInt(scanner)
	for i := int64(1); i < n; i++ {
		head += scanInt(scanner)
	}
	result := n-1
	if head%(n-1) == 0 {
		result++
	}
	writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n := scanInt(scanner)
	sum := int64(0)
	for i := 0; i < n; i++ {
		sum += int64(scanInt(scanner))
	}
	result := (sum+int64(n)*10000) % int64(n)
	if int64(n)-result > result {
		result = int64(n)-result
	}
	writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    total := 0;
    for i := 0; i < n; i++ {
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        total += int(math.Abs(float64(a)))
    }
    fmt.Println(n-(total%n))
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    total := 0;
    for i := 0; i < n; i++ {
        scanner.Scan()
        a, _ := strconv.Atoi(scanner.Text())
        total += a
    }
    fmt.Println(n-(total%n))
}


During one of the space missions, humans have found an evidence of previous life at one of the planets. They were lucky enough to find a book with birth and death years of each individual that had been living at this planet. What's interesting is that these years are in the range $$$(1, 10^9)$$$! Therefore, the planet was named Longlifer.In order to learn more about Longlifer's previous population, scientists need to determine the year with maximum number of individuals that were alive, as well as the number of alive individuals in that year. Your task is to help scientists solve this problem!

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of people. Each of the following $$$n$$$ lines contain two integers $$$b$$$ and $$$d$$$ ($$$1 \le b \lt d \le 10^9$$$) representing birth and death year (respectively) of each individual.

Print two integer numbers separated by blank character, $$$y$$$  — the year with a maximum number of people alive and $$$k$$$  — the number of people alive in year $$$y$$$. In the case of multiple possible solutions, print the solution with minimum year.

NoteYou can assume that an individual living from $$$b$$$ to $$$d$$$ has been born at the beginning of $$$b$$$ and died at the beginning of $$$d$$$, and therefore living for $$$d$$$ - $$$b$$$ years.

package main

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

func main() {
	n := ReadInt()
	m := make(map[int]int)
	spans := make([][]int, n)
	for i := 0; i < n; i++ {
		b, d := ReadInt(), ReadInt()-1
		spans[i] = []int{b, d}
		m[b] = 0
		m[d] = 0
	}

	years := make([]int, len(m))
	for year := range m {
		years = append(years, year)
	}
	sort.Ints(years)

	pops := make([]int, len(years)+1)

	for i := 0; i < n; i++ {
		b, d := spans[i][0], spans[i][1]
		i := sort.SearchInts(years, b)
		j := sort.SearchInts(years, d+1)
		pops[i]++
		pops[j]--
	}

	for i := 0; i < len(pops)-1; i++ {
		pops[i+1] += pops[i]
	}

	maxY, maxK := 0, 0
	for i := 0; i < len(years); i++ {
		y := years[i]
		k := pops[i]
		if maxK < k {
			maxY, maxK = y, k
		}
	}
	fmt.Println(maxY, maxK)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

func main() {
	n := ReadInt()
	m := make(map[int]int)
	spans := make([][]int, n)
	for i := 0; i < n; i++ {
		b, d := ReadInt(), ReadInt()-1
		spans[i] = []int{b, d}
		m[b] = 0
		m[d] = 0
	}

	years := make([]int, len(m))
	for year := range m {
		years = append(years, year)
	}
	sort.Ints(years)

	pops := make([]int, len(years)+1)

	for i := 0; i < n; i++ {
		b, d := spans[i][0], spans[i][1]
		i := sort.SearchInts(years, b)
		j := sort.SearchInts(years, d+1)
		// for k := i; k < j; k++ {
		// 	m[years[k]]++
		// }
		pops[i]++
		pops[j]--
	}

	for i := 0; i < len(pops)-1; i++ {
		pops[i+1] += pops[i]
	}

	maxY, maxK := 0, 0
	for i := 0; i < len(years); i++ {
		y := years[i]
		k := pops[i]
		if maxK < k {
			maxY, maxK = y, k
		}
	}
	fmt.Println(maxY, maxK)

	// maxY := 0
	// for y, k := range m {
	// 	if m[maxY] < k || (m[maxY] == k && y < maxY) {
	// 		maxY = y
	// 	}
	// }
	// fmt.Println(maxY, m[maxY])
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

/*
1 5
2 4
5 6
*/

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

	var T int64
	var target [][2]int
	for Fscan(in, &T); T > 0; T-- {
		var A1, A2 int
		Fscan(in, &A1)
		Fscan(in, &A2)
		target = append(target, [2]int{A1, A2})
	}

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

	var sum, sumidx int
	for i := 0; i < len(target); {
		tmpSum := 1
		if i+1 < len(target) && target[i+1][0] == target[i][0] {
			i++
			continue
		}

		for j := i - 1; j >= 0; j-- {
			if target[j][1] > target[i][0] {
				tmpSum++
			}
		}

		if sum < tmpSum {
			sum = tmpSum
			sumidx = target[i][0]
		}
		i++
	}

	Fprintln(out, sumidx, sum)

}

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

	var T int
	var total []int
	life := make(map[int]int)
	dead := make(map[int]int)
	for Fscan(in, &T); T > 0; T-- {
		var A1, A2 int
		Fscan(in, &A1)
		Fscan(in, &A2)
		life[A1] ++
		dead[A2] ++
		total = append(total, A1, A2)

	}

	sort.Ints(total)

	tmpSum := 0
	sum := 0
	sumIdx := 0
	for i := 0; i < len(total); i++ {
		if num, ok := life[total[i]];ok {
			tmpSum += num
			delete(life,total[i])
		}

		if num, ok := dead[total[i]];ok {
			tmpSum -= num
			delete(dead,total[i])
		}

		if sum < tmpSum {
			sum = tmpSum
			sumIdx = total[i]
		}
	}

	Fprintln(out,sumIdx,sum)

}

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

package main

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

/*
1 5
2 4
5 6
*/

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

	var T int64
	var target [][2]int
	for Fscan(in, &T); T > 0; T-- {
		var A1, A2 int
		Fscan(in, &A1)
		Fscan(in, &A2)
		target = append(target, [2]int{A1, A2})
	}

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

	var sum, sumidx int
	for i := 0; i < len(target); {
		tmpSum := 1
		if i+1 < len(target) && target[i+1][0] == target[i][0] {
			i++
			continue
		}

		for j := i - 1; j >= 0; j-- {
			if target[j][1] > target[i][0] {
				tmpSum++
			}
		}

		if sum < tmpSum {
			sum = tmpSum
			sumidx = target[i][0]
		}
		i++
	}

	Fprintln(out, sumidx, sum)

}

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

	var T int
	var total []int
	life := make(map[int]int)
	dead := make(map[int]int)
	for Fscan(in, &T); T > 0; T-- {
		var A1, A2 int
		Fscan(in, &A1)
		Fscan(in, &A2)
		life[A1] ++
		dead[A2] ++
		total = append(total, A1, A2)

	}

	sort.Ints(total)

	tmpSum := 0
	sum := 0
	sumIdx := 0
	for i := 0; i < len(total); i++ {
		if num, ok := life[total[i]];ok {
			tmpSum += num
		}

		if num, ok := dead[total[i]];ok {
			tmpSum -= num
		}

		if sum < tmpSum {
			sum = tmpSum
			sumIdx = total[i]
		}
	}

	Fprintln(out, sum,sumIdx)

}

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