← Home
```go
package main

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

func zAlgo(b []byte) []int {
	n := len(b)
	z := make([]int, n)
	l, r := 0, 0
	for i := 1; i < n; i++ {
		if i <= r {
			zi := z[i-l]
			if zi > r-i+1 {
				zi = r - i + 1
			}
			z[i] = zi
		}
		for i+z[i] < n && b[z[i]] == b[i+z[i]] {
			z[i]++
		}
		if i+z[i]-1 > r {
			l = i
			r = i + z[i] - 1
		}
	}
	return z
}

func main() {
	in := bufio.NewReader(os.Stdin)
	var sStr string
	fmt.Fscan(in, &sStr)
	var k uint64
	fmt.Fscan(in, &k)

	s := []byte(sStr)
	n := len(s)

	cp := make([][]uint16, n)
	for i := 0; i < n; i++ {
		cp[i] = make([]uint16, n-i)
	}

	var last [4][]bool
	for L := 1; L <= n; L++ {
		m := n - L + 1
		dpL := make([]bool, m)
		if L <= 4 {
			for i := 0; i < m; i++ {
				if s[i] == s[i+L-1] {
					dpL[i] = true
				}
			}
		} else {
			prev := last[(L-4)&3]
			for i := 0; i < m; i++ {
				if s[i] == s[i+L-1] && prev[i+2] {
					dpL[i] = true
				}
			}
		}
		for i := 0; i < m; i++ {
			var prevCount uint16
			if L > 1 {
				prevCount = cp[i][L-2]
			}
			if dpL[i] {
				cp[i][L-1] = prevCount + 1
			} else {
				cp[i][L-1] = prevCount
			}
		}
		last[L&3] = dpL
	}

	countLE := func(x []byte) uint64 {
		px := make([]byte, 0, len(x)+1+n)
		px = append(px, x...)
		px = append(px, '#')
		px = append(px, s...)
		z := zAlgo(px)
		m := len(x)
		var ans uint64
		base := m + 1
		for i := 0; i < n; i++ {
			l := z[base+i]
			if l > m {
				l = m
			}
			var T int
			if l == m {
				T = m
			} else if i+l == n {
				T = n - i
			} else {
				if s[i+l] < x[l] {
					T = n - i
				} else {
					T = l
				}
			}
			if T > 0 {
				ans += uint64(cp[i][T-1])
			}
		}
		return ans
	}

	lo, hi := 1, n
	ansLen := n
	for lo <= hi {
		mid := (lo + hi) >> 1
		x := bytes.Repeat([]byte{'b'}, mid)
		if countLE(x) >= k {
			ansLen = mid
			hi = mid - 1
		} else {
			lo = mid + 1
		}
	}

	ans := make([]byte, ansLen)
	pref := make([]byte, 0, ansLen)
	for p := 0; p < ansLen; p++ {
		cand := make([]byte, 0, ansLen)
		cand = append(cand, pref...)
		cand = append(cand, 'a')
		if p < ansLen-1 {
			cand = append(cand, bytes.Repeat([]byte{'b'}, ansLen-p-1)...)
		}
		if countLE(cand) >= k {
			ans[p] = 'a'
			pref = append(pref, 'a')
		} else {
			ans[p] = 'b'
			pref = append(pref, 'b')
		}
	}

	out := bufio.NewWriter(os.Stdout)
	fmt.Fprintln(out, string(ans))
	out.Flush()
}
```