You've got another geometrical task. You are given two non-degenerate polygons A and B as vertex coordinates. Polygon A is strictly convex. Polygon B is an arbitrary polygon without any self-intersections and self-touches. The vertices of both polygons are given in the clockwise order. For each polygon no three consecutively following vertices are located on the same straight line.Your task is to check whether polygon B is positioned strictly inside polygon A. It means that any point of polygon B should be strictly inside polygon A. "Strictly" means that the vertex of polygon B cannot lie on the side of the polygon A.

The first line contains the only integer n (3 ≤ n ≤ 105) — the number of vertices of polygon A. Then n lines contain pairs of integers xi, yi (|xi|, |yi| ≤ 109) — coordinates of the i-th vertex of polygon A. The vertices are given in the clockwise order. The next line contains a single integer m (3 ≤ m ≤ 2·104) — the number of vertices of polygon B. Then following m lines contain pairs of integers xj, yj (|xj|, |yj| ≤ 109) — the coordinates of the j-th vertex of polygon B. The vertices are given in the clockwise order. The coordinates of the polygon's vertices are separated by a single space. It is guaranteed that polygons A and B are non-degenerate, that polygon A is strictly convex, that polygon B has no self-intersections and self-touches and also for each polygon no three consecutively following vertices are located on the same straight line.

Print on the only line the answer to the problem — if polygon B is strictly inside polygon A, print "YES", otherwise print "NO" (without the quotes).

package main

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

type point struct {
	x, y int64
}

func counterclockwiseTurn(a, b, c point) bool {
	ab := point{b.x - a.x, b.y - a.y}
	ac := point{c.x - a.x, c.y - a.y}
	return ab.x*ac.y-ab.y*ac.x > 0
}

func convexHull(points []point) []point {
	sort.Slice(points, func(i, j int) bool {
		if points[i].x == points[j].x {
			return points[i].y < points[j].y
		}
		return points[i].x < points[j].x
	})

	var lower []point
	for i := len(points) - 1; i >= 0; i-- {
		for len(lower) >= 2 && counterclockwiseTurn(lower[len(lower)-2], lower[len(lower)-1], points[i]) {
			lower = lower[:len(lower)-1]
		}
		lower = append(lower, points[i])
	}

	var upper []point
	for i := range points {
		for len(upper) >= 2 && counterclockwiseTurn(upper[len(upper)-2], upper[len(upper)-1], points[i]) {
			upper = upper[:len(upper)-1]
		}
		upper = append(upper, points[i])
	}

	return append(lower[:len(lower)-1], upper[:len(upper)-1]...)
}

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

func readPoints() []point {
	var n int
	fmt.Fscan(in, &n)
	a := make([]point, n)
	for i := range a {
		fmt.Fscan(in, &a[i].x, &a[i].y)
	}
	return a
}

func solve() bool {
	a := readPoints()
	b := readPoints()
	hull := convexHull(append(b, a...))
	if len(hull) != len(a) {
		return false
	}
	start := 0
	for start < len(hull) && hull[start] != a[0] {
		start++
	}
	if start == len(hull) {
		return false
	}
	for i := range a {
		if a[i] != hull[(i+start)%len(hull)] {
			return false
		}
	}
	return true
}

func main() {
	if solve() {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

type point struct {
	x, y int
}

func counterclockwiseTurn(a, b, c point) bool {
	ab := point{b.x - a.x, b.y - a.y}
	ac := point{c.x - a.x, c.y - a.y}
	return ab.x*ac.y-ab.y*ac.x > 0
}

func convexHull(points []point) []point {
	sort.Slice(points, func(i, j int) bool {
		if points[i].x == points[j].x {
			return points[i].y < points[j].y
		}
		return points[i].x < points[j].x
	})

	var lower []point
	for i := len(points) - 1; i >= 0; i-- {
		for len(lower) >= 2 && counterclockwiseTurn(lower[len(lower)-2], lower[len(lower)-1], points[i]) {
			lower = lower[:len(lower)-1]
		}
		lower = append(lower, points[i])
	}

	var upper []point
	for i := range points {
		for len(upper) >= 2 && counterclockwiseTurn(upper[len(upper)-2], upper[len(upper)-1], points[i]) {
			upper = upper[:len(upper)-1]
		}
		upper = append(upper, points[i])
	}

	return append(lower[:len(lower)-1], upper[:len(upper)-1]...)
}

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

func readPoints() []point {
	var n int
	fmt.Fscan(in, &n)
	a := make([]point, n)
	for i := range a {
		fmt.Fscan(in, &a[i].x, &a[i].y)
	}
	return a
}

func solve() bool {
	a := readPoints()
	b := readPoints()
	hull := convexHull(append(b, a...))
	if len(hull) != len(a) {
		return false
	}
	start := 0
	for start < len(hull) && hull[start] != a[0] {
		start++
	}
	if start == len(hull) {
		return false
	}
	for i := range a {
		if a[i] != hull[(i+start)%len(hull)] {
			return false
		}
	}
	return true
}

func main() {
	if solve() {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

type point struct {
	x, y int
}

func counterclockwiseTurn(a, b, c point) bool {
	ab := point{b.x - a.x, b.y - a.y}
	ac := point{c.x - a.x, c.y - a.y}
	return ab.x*ac.y-ab.y*ac.x > 0
}

func convexHull(points []point) []point {
	sort.Slice(points, func(i, j int) bool {
		if points[i].x == points[j].x {
			return points[i].y < points[j].y
		}
		return points[i].x < points[j].x
	})

	var lower []point
	for i := len(points) - 1; i >= 0; i-- {
		for len(lower) >= 2 && counterclockwiseTurn(lower[len(lower)-2], lower[len(lower)-1], points[i]) {
			lower = lower[:len(lower)-1]
		}
		lower = append(lower, points[i])
	}

	var upper []point
	for i := range points {
		for len(upper) >= 2 && counterclockwiseTurn(upper[len(upper)-2], upper[len(upper)-1], points[i]) {
			upper = upper[:len(upper)-1]
		}
		upper = append(upper, points[i])
	}

	return append(lower[:len(lower)-1], upper[:len(upper)-1]...)
}

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

func readPoints() []point {
	var n int
	fmt.Fscan(in, &n)
	a := make([]point, n)
	for i := range a {
		fmt.Fscan(in, &a[i].x, &a[i].y)
	}
	return a
}

func solve() bool {
	a := readPoints()
	b := readPoints()
	debug := len(a) == 19896
	hull := convexHull(append(b, a...))
	if len(hull) != len(a) {
		if debug {
			fmt.Println("LEN", len(hull), len(a))
		}
		return false
	}
	start := 0
	for start < len(hull) && hull[start] != a[0] {
		start++
	}
	if start == len(hull) {
		if debug {
			fmt.Println("START")
		}
		return false
	}
	for i := range a {
		if a[i] != hull[(i+start)%len(hull)] {
			if debug {
				fmt.Println("EQ")
			}
			return false
		}
	}
	return true
}

func main() {
	if solve() {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

type point struct {
	x, y int
}

func counterclockwiseTurn(a, b, c point) bool {
	ab := point{b.x - a.x, b.y - a.y}
	ac := point{c.x - a.x, c.y - a.y}
	return ab.x*ac.y-ab.y*ac.x > 0
}

func convexHull(points []point) []point {
	sort.Slice(points, func(i, j int) bool {
		if points[i].x == points[j].x {
			return points[i].y < points[j].y
		}
		return points[i].x < points[j].x
	})

	var lower []point
	for i := len(points) - 1; i >= 0; i-- {
		for len(lower) >= 2 && counterclockwiseTurn(lower[len(lower)-2], lower[len(lower)-1], points[i]) {
			lower = lower[:len(lower)-1]
		}
		lower = append(lower, points[i])
	}

	var upper []point
	for i := range points {
		for len(upper) >= 2 && counterclockwiseTurn(upper[len(upper)-2], upper[len(upper)-1], points[i]) {
			upper = upper[:len(upper)-1]
		}
		upper = append(upper, points[i])
	}

	return append(lower[:len(lower)-1], upper[:len(upper)-1]...)
}

var in = bufio.NewReaderSize(os.Stdin, 2<<16)

func readPoints() []point {
	var n int
	fmt.Fscan(in, &n)
	a := make([]point, n)
	for i := range a {
		fmt.Fscan(in, &a[i].x, &a[i].y)
	}
	return a
}

func solve() bool {
	a := readPoints()
	b := readPoints()
	debug := len(a) == 19896
	hull := convexHull(append(b, a...))
	if len(hull) != len(a) {
		if debug {
			fmt.Println("LEN")
		}
		return false
	}
	start := 0
	for start < len(hull) && hull[start] != a[0] {
		start++
	}
	if start == len(hull) {
		if debug {
			fmt.Println("START")
		}
		return false
	}
	for i := range a {
		if a[i] != hull[(i+start)%len(hull)] {
			if debug {
				fmt.Println("EQ")
			}
			return false
		}
	}
	return true
}

func main() {
	if solve() {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Several years ago Tolya had n computer games and at some point of time he decided to burn them to CD. After that he wrote down the names of the games one after another in a circle on the CD in clockwise order. The names were distinct, the length of each name was equal to k. The names didn't overlap.Thus, there is a cyclic string of length n·k written on the CD.Several years have passed and now Tolya can't remember which games he burned to his CD. He knows that there were g popular games that days. All of the games he burned were among these g games, and no game was burned more than once.You have to restore any valid list of games Tolya could burn to the CD several years ago.

The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 105) — the amount of games Tolya burned to the CD, and the length of each of the names. The second line of the input contains one string consisting of lowercase English letters — the string Tolya wrote on the CD, split in arbitrary place. The length of the string is n·k. It is guaranteed that the length is not greater than 106. The third line of the input contains one positive integer g (n ≤ g ≤ 105) — the amount of popular games that could be written on the CD. It is guaranteed that the total length of names of all popular games is not greater than 2·106. Each of the next g lines contains a single string — the name of some popular game. Each name consists of lowercase English letters and has length k. It is guaranteed that the names are distinct.

If there is no answer, print "NO" (without quotes). Otherwise, print two lines. In the first line print "YES" (without quotes). In the second line, print n integers — the games which names were written on the CD. You should print games in the order they could have been written on the CD, it means, in clockwise order. You can print games starting from any position. Remember, that no game was burned to the CD more than once. If there are several possible answers, print any of them.

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

type Pair struct {
	H1 int64
	H2 int64
}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash := make(map[Pair]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash[Pair{H1: hash(temp, m1, p1), H2: hash(temp, m2, p2)}] = i
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int]Empty)
	i := mid - k
	count := 0
	var curh1, curh2 int64
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh1, curh2)
		idx, ok := idxByHash[Pair{H1: curh1, H2: curh2}]
		if ok {
			_, ok1 := idxs[idx]
			if !ok1 {
				order = append(order, idx)
				idxs[idx] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs = make(map[int]Empty)
			i = i - count*k
			i = i + 1
			if i > mid {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const m = 1e9 + 9
const p = 31

func hash(s string) int64 {
	var ppow, h int64
	ppow = 1
	for _, b := range []byte(s) {
		h = (h + int64(b-'a'+1)*ppow) % m
		ppow = (p * ppow) % m
	}
	return h
}

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

	var n, k, g int
	var s, temp string
	nhashes := make(map[int]int64)
	namesByIdx := make(map[int]string)
	idxs := make([]int, 0)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		nhashes[i] = hash(temp)
		namesByIdx[i] = temp
	}
	if k > 1 {
		s = s + s[0:k-1]
	}
	sLen := len(s)
	//fmt.Println(s)
	hashes := make([]int64, sLen+1)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		hashes[idx+1] = (hashes[idx] + int64(b-'a'+1)*ppow[idx]) % m
	}
	//fmt.Fprintln(writer, ppow, hashes)
	//fmt.Fprintln(writer, hash(s))
	for i := 0; i <= sLen-k; i += k {
		var curh int64
		curh = ((hashes[i+k]-hashes[i])%m + m) % m
		//fmt.Fprintf(writer, "substr hash %d %d %v\n", curh, ppow[i], nhashes)
		found := false
		for idx, h := range nhashes {
			if curh == ((ppow[i] * h) % m) {
				//fmt.Fprintln(writer, idx)
				idxs = append(idxs, idx)
				found = true
			}
		}
		if !found {
			idxs = nil
			break
		}
	}
	if idxs == nil {
		fmt.Fprintf(writer, "NO\n")
	} else {
		fmt.Fprintf(writer, "YES\n")
		for i, idx := range idxs {
			if i == (len(idxs) - 1) {
				fmt.Fprintf(writer, "%d\n", idx)
			} else {
				fmt.Fprintf(writer, "%d ", idx)
			}
		}
	}
}

package main

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

const m = 1e9 + 9
const p = 31

func hash(s string) int64 {
	var ppow, h int64
	ppow = 1
	for _, b := range []byte(s) {
		h = (h + int64(b-'a'+1)*ppow) % m
		ppow = (p * ppow) % m
	}
	return h
}

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

	var n, k, g int
	var s, temp string
	nhashes := make(map[int]int64)
	namesByIdx := make(map[int]string)
	idxs := make([]int, 0)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		nhashes[i] = hash(temp)
		namesByIdx[i] = temp
	}
	sLen := len(s)
	hashes := make([]int64, sLen+1)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		hashes[idx+1] = (hashes[idx] + int64(b-'a'+1)*ppow[idx]) % m
	}
	//fmt.Fprintln(writer, ppow, hashes)
	//fmt.Fprintln(writer, hash(s))
	temp = ""
	for i := 0; i <= sLen-k; i++ {
		var curh int64
		curh = ((hashes[i+k]-hashes[i])%m + m) % m
		//fmt.Fprintf(writer, "substr hash %d %d %v\n", curh, ppow[i], nhashes)
		for idx, h := range nhashes {
			if curh == ((ppow[i] * h) % m) {
				//fmt.Fprintln(writer, idx)
				idxs = append(idxs, idx)
				temp += namesByIdx[idx]
			}
		}
	}
	if temp == s {
		fmt.Fprintf(writer, "YES\n")
		for i, idx := range idxs {
			if i == len(idxs)-1 {
				fmt.Fprintf(writer, "%d\n", idx)
			} else {
				fmt.Fprintf(writer, "%d ", idx)
			}
		}
	} else {
		fmt.Fprintf(writer, "NO\n")
	}
}

package main

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

const m = 1e9 + 9
const p = 31

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash[hash(temp)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes := make([]int64, sLen)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes[idx] = (hashes[idx-1]*p + int64(b-'a'+1)) % m
		} else {
			hashes[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int64]Empty)
	i := 0
	count := 0
	var curh int64
	for i < mid {
		if i > 0 {
			curh = (hashes[i+k-1] - (hashes[i-1] * ppow[k] % m) + m) % m
		} else {
			curh = hashes[i+k-1]
		}
		//fmt.Println(curh, idxByHash)
		if idx, ok := idxByHash[curh]; ok {
			if _, ok := idxs[curh]; !ok {
				order = append(order, idx)
				idxs[curh] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			order = nil
			idxs = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			count = 0
		}
	}

	//fmt.Println(idxs, order)
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const m = 1e9 + 9
const p = 31

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string) int64 {
	var ppow, h int64
	ppow = 1
	for _, b := range []byte(s) {
		h = (h + int64(b-'a'+1)*ppow) % m
		ppow = (p * ppow) % m
	}
	return h
}

func printResult(idxs map[int]Empty, n int) {
	size := len(idxs)
	if size != n {
		fmt.Fprintf(writer, "NO\n")
	} else {
		fmt.Fprintf(writer, "YES\n")
		for idx, _ := range idxs {
			if size == 1 {
				fmt.Fprintf(writer, "%d\n", idx)
			} else {
				fmt.Fprintf(writer, "%d ", idx)
			}
			size -= 1
		}
	}

}

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

	var n, k, g int
	var s, temp string
	nhashes := make(map[int]int64)
	namesByIdx := make(map[int]string)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		nhashes[i] = hash(temp)
		namesByIdx[i] = temp
	}

	s = s + s
	sLen := len(s)
	//fmt.Println(s)
	hashes := make([]int64, sLen+1)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		hashes[idx+1] = (hashes[idx] + int64(b-'a'+1)*ppow[idx]) % m
	}

	mid := sLen / 2
	for i := 0; i < mid; i += 1 {
		idxs := make(map[int]Empty)
		for j := i; j < (i + n*k); j += k {
			var curh int64
			curh = ((hashes[j+k]-hashes[j])%m + m) % m
			for idx, h := range nhashes {
				if curh == ((ppow[j] * h) % m) {
					idxs[idx] = Empty{}
				}
			}
		}
		if len(idxs) == n {
			printResult(idxs, n)
			return
		}
	}
	fmt.Fprintf(writer, "NO\n")
}

package main

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

const m = 1e9 + 9
const p = 31

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string) int64 {
	var ppow, h int64
	ppow = 1
	for _, b := range []byte(s) {
		h = (h + int64(b-'a'+1)*ppow) % m
		ppow = (p * ppow) % m
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

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

	var n, k, g int
	var s, temp string
	nhashes := make(map[int]int64)
	idxByName := make(map[string]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		nhashes[i] = hash(temp)
		idxByName[temp] = i
	}

	s = s + s
	sLen := len(s)
	//fmt.Println(s)
	hashes := make([]int64, sLen+1)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		hashes[idx+1] = (hashes[idx] + int64(b-'a'+1)*ppow[idx]) % m
	}

	mid := sLen / 2
	idxs := make(map[int]int)
	order := make([]int, 0)
	i := 0
	for i < mid {
		curh := (hashes[i+k] - hashes[i] + m) % m
		str := s[i : i+k]
		if idx, ok := idxByName[str]; ok {
			if curh == ((ppow[i] * nhashes[idxByName[str]]) % m) {
				//fmt.Println(str, idx)
				order = append(order, idx)
				idxs[i] = idx
				i = i + k
			}
		} else {
			i = i + 1
		}
	}

	//fmt.Println(order)
	if (len(order) == n) && !hasDuplicates(order, n) {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}
	//fmt.Println(idxs, order)
}

package main

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

const m = 1e9 + 9
const p = 31

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash[hash(temp)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes := make([]int64, sLen)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes[idx] = (hashes[idx-1]*p + int64(b-'a'+1)) % m
		} else {
			hashes[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int64]Empty)
	i := 0
	count := 0
	var curh int64
	for i < mid {
		if i > 0 {
			curh = (hashes[i+k-1] - (hashes[i-1] * ppow[k] % m) + m) % m
		} else {
			curh = hashes[i+k-1]
		}
		//fmt.Println(curh, idxByHash)
		if idx, ok := idxByHash[curh]; ok {
			if _, ok := idxs[curh]; !ok {
				order = append(order, idx)
				idxs[curh] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			order = nil
			idxs = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			count = 0
		}
	}
	if n == 10000 && k == 20 {
		fmt.Println(idxs, order)
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int64]Empty)
	i := mid - k
	count := 0
	var curh1, curh2, curh int64
	var idx int
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh1, curh2)
		idx1, ok1 := idxByHash1[curh1]
		idx2, ok2 := idxByHash2[curh2]
		if ok1 || ok2 {
			if ok1 {
				idx = idx1
				curh = curh1
			} else if ok2 {
				idx = idx2
				curh = curh2
			}

			if _, ok := idxs[curh]; !ok {
				order = append(order, idx)
				idxs[curh] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			if i > mid {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs1 := make(map[int64]Empty)
	idxs2 := make(map[int64]Empty)
	i := mid - k
	count := 0
	var curh1, curh2 int64
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh1, curh2)
		idx1, ok1 := idxByHash1[curh1]
		idx2, ok2 := idxByHash2[curh2]
		if ok1 || ok2 {
			_, ok3 := idxs1[curh1]
			_, ok4 := idxs2[curh2]
			if !ok3 && !ok4 {
				var idx int
				if ok1 {
					idx = idx1
					idxs1[curh1] = Empty{}
				} else if ok2 {
					idx = idx2
					idxs2[curh2] = Empty{}
				}
				order = append(order, idx)
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs1 = make(map[int64]Empty)
			idxs2 = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			if i > mid {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const p = 911382323
const m = 972663749

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash[hash(temp)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes := make([]int64, sLen)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes[idx] = (hashes[idx-1]*p + int64(b-'a'+1)) % m
		} else {
			hashes[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int64]Empty)
	i := mid - k
	count := 0
	var curh int64
	for i < (sLen - k) {
		if i > 0 {
			curh = (hashes[i+k-1] - (hashes[i-1] * ppow[k] % m) + m) % m
		} else {
			curh = hashes[i+k-1]
		}
		//fmt.Println(curh, idxByHash)
		if idx, ok := idxByHash[curh]; ok {
			if _, ok := idxs[curh]; !ok {
				order = append(order, idx)
				idxs[curh] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			if i > (mid - 1) {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int]Empty)
	i := mid - k
	count := 0
	var curh1, curh2 int64
	var idx int
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh1, curh2)
		idx1, ok1 := idxByHash1[curh1]
		idx2, ok2 := idxByHash2[curh2]
		if ok1 || ok2 {
			if ok1 {
				idx = idx1
			} else if ok2 {
				idx = idx2
			}

			if _, ok := idxs[idx]; !ok {
				order = append(order, idx)
				idxs[idx] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs = make(map[int]Empty)
			i = i - count*k
			i = i + 1
			if i > mid {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs1 := make(map[int64]Empty)
	idxs2 := make(map[int64]Empty)
	i := mid - k
	count := 0
	var curh1, curh2 int64
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh1, curh2)
		idx1, ok1 := idxByHash1[curh1]
		idx2, ok2 := idxByHash2[curh2]
		if ok1 && ok2 && idx1 == idx2 {
			_, ok3 := idxs1[curh1]
			_, ok4 := idxs2[curh2]
			if !ok3 && !ok4 {
				order = append(order, idx1)
				idxs1[curh1] = Empty{}
				idxs2[curh2] = Empty{}
				i = i + k
				count += 1
			} else {
				if n == 50 {
					fmt.Println("collision")
				}
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs1 = make(map[int64]Empty)
			idxs2 = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			if i > (mid - 1) {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs1 := make(map[int64]Empty)
	idxs2 := make(map[int64]Empty)
	i := mid - k
	count := 0
	var curh1, curh2 int64
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh1, curh2)
		idx1, ok1 := idxByHash1[curh1]
		idx2, ok2 := idxByHash2[curh2]
		if ok1 && ok2 && idx1 == idx2 {
			_, ok3 := idxs1[curh1]
			_, ok4 := idxs2[curh2]
			if !ok3 && !ok4 {
				order = append(order, idx1)
				idxs1[curh1] = Empty{}
				idxs2[curh2] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs1 = make(map[int64]Empty)
			idxs2 = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			if i > (mid - 1) {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int64]Empty)
	i := mid - k
	count := 0
	var curh1, curh2 int64
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh, idxByHash)
		if idx1, ok1 := idxByHash1[curh1]; ok1 {
			if idx2, ok2 := idxByHash2[curh2]; ok2 {
				if _, ok := idxs[curh1]; !ok && idx1 == idx2 {
					order = append(order, idx1)
					idxs[curh1] = Empty{}
					i = i + k
					count += 1
				} else {
					order = nil
					break
				}
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			if i > (mid - 1) {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const m = 1e9 + 9
const p = 31

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash[hash(temp)] = i
		//fmt.Println(temp, nhashes[i])
	}

	s = s + s
	sLen := len(s)
	hashes := make([]int64, sLen)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes[idx] = (hashes[idx-1]*p + int64(b-'a'+1)) % m
		} else {
			hashes[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int64]Empty)
	i := 0
	count := 0
	var curh int64
	for i < mid {
		if i > 0 {
			curh = (hashes[i+k-1] - hashes[i-1]*ppow[k]%m + m) % m
		} else {
			curh = hashes[i+k-1]
		}
		//fmt.Println(curh)
		if idx, ok := idxByHash[curh]; ok {
			if _, ok := idxs[curh]; !ok {
				order = append(order, idx)
				idxs[curh] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			order = nil
			idxs = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			count = 0
		}
	}

	//fmt.Println(idxs, order)
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs1 := make(map[int64]Empty)
	idxs2 := make(map[int64]Empty)
	var curh1, curh2 int64
	for j := 0; j < k; j++ {
		order = nil
		idxs1 = make(map[int64]Empty)
		idxs2 = make(map[int64]Empty)
		for i := j; i < mid; i += k {
			//fmt.Println(sLen, i, j)
			if i > 0 {
				curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
				curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
			} else {
				curh1 = hashes1[i+k-1]
				curh2 = hashes2[i+k-1]
			}
			//fmt.Println(curh1, curh2)
			idx1, ok1 := idxByHash1[curh1]
			idx2, ok2 := idxByHash2[curh2]
			if ok1 && ok2 && idx1 == idx2 {
				_, ok3 := idxs1[curh1]
				_, ok4 := idxs2[curh2]
				if !ok3 && !ok4 {
					order = append(order, idx1)
					idxs1[curh1] = Empty{}
					idxs2[curh2] = Empty{}
				} else {
					order = nil
				}
			} else {
				break
			}
		}
		if len(order) == n {
			printResult(order, n)
			return
		}
	}
	if len(order) == n {
		printResult(order, n)
		return
	} else {
		fmt.Fprintf(writer, "NO\n")
	}
}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs1 := make(map[int64]Empty)
	idxs2 := make(map[int64]Empty)
	i := mid - k
	count := 0
	var curh1, curh2 int64
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh1, curh2)
		idx1, ok1 := idxByHash1[curh1]
		idx2, ok2 := idxByHash2[curh2]
		if ok1 && ok2 && idx1 == idx2 {
			_, ok3 := idxs1[curh1]
			_, ok4 := idxs2[curh2]
			if !ok3 && !ok4 {
				order = append(order, idx1)
				idxs1[curh1] = Empty{}
				idxs2[curh2] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs1 = make(map[int64]Empty)
			idxs2 = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			if i > mid {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const m = 1e9 + 9
const p = 31

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash[hash(temp)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes := make([]int64, sLen)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes[idx] = (hashes[idx-1]*p + int64(b-'a'+1)) % m
		} else {
			hashes[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs := make(map[int64]Empty)
	i := 0
	count := 0
	var curh int64
	for i < mid {
		if i > 0 {
			curh = (hashes[i+k-1] - (hashes[i-1] * ppow[k] % m) + m) % m
		} else {
			curh = hashes[i+k-1]
		}
		//fmt.Println(curh, idxByHash)
		if idx, ok := idxByHash[curh]; ok {
			if _, ok := idxs[curh]; !ok {
				order = append(order, idx)
				idxs[curh] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			order = nil
			idxs = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			count = 0
		}
	}
	if n == 10000 && k == 20 {
		fmt.Println(len(idxs), len(order))
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}

package main

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

const m = 1e9 + 9
const p = 31

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string) int64 {
	var ppow, h int64
	ppow = 1
	for _, b := range []byte(s) {
		h = (h + int64(b-'a'+1)*ppow) % m
		ppow = (p * ppow) % m
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	nhashes := make(map[int]int64)
	idxByName := make(map[string]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		nhashes[i] = hash(temp)
		idxByName[temp] = i
	}

	s = s + s
	sLen := len(s)
	//fmt.Println(s)
	hashes := make([]int64, sLen+1)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		hashes[idx+1] = (hashes[idx] + int64(b-'a'+1)*ppow[idx]) % m
	}

	mid := sLen / 2
	order := make([]int, 0)
	i := 0
	for i < mid{
		curh := (hashes[i+k] - hashes[i] + m) % m
		str := s[i : i+k]
		if idx, ok := idxByName[str]; ok {
			if curh == ((ppow[i] * nhashes[idxByName[str]]) % m) {
				//fmt.Println(str, idx)
				order = append(order, idx)
			}
			i = i + k
		} else {
			i = i + 1
			order = make([]int, 0)
		}
	}

	if (len(order) == n) && !hasDuplicates(order, n) {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}
	//fmt.Println(order)
}

package main

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

const m = 1e9 + 9
const p = 31

var reader *bufio.Reader
var writer *bufio.Writer

func hash(s string) int64 {
	var ppow, h int64
	ppow = 1
	for _, b := range []byte(s) {
		h = (h + int64(b-'a'+1)*ppow) % m
		ppow = (p * ppow) % m
	}
	return h
}

func printResult(idxs []int, n int) {
	size := len(idxs)
	if size != n {
		fmt.Fprintf(writer, "NO\n")
	} else {
		fmt.Fprintf(writer, "YES\n")
		for i, idx := range idxs {
			if i == (size - 1) {
				fmt.Fprintf(writer, "%d\n", idx)
			} else {
				fmt.Fprintf(writer, "%d ", idx)
			}
		}
	}

}

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

	var n, k, g int
	var s, temp string
	nhashes := make(map[int]int64)
	namesByIdx := make(map[int]string)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		nhashes[i] = hash(temp)
		namesByIdx[i] = temp
	}

	s = s + s
	sLen := len(s)
	//fmt.Println(s)
	hashes := make([]int64, sLen+1)
	ppow := make([]int64, sLen)
	ppow[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow[i] = (ppow[i-1] * p) % m
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		hashes[idx+1] = (hashes[idx] + int64(b-'a'+1)*ppow[idx]) % m
	}
	//fmt.Fprintln(writer, ppow, hashes)
	//fmt.Fprintln(writer, hash(s))
	mid := sLen / 2
	for i := 0; i < mid; i += 1 {
		idxs := make([]int, 0)
		//fmt.Println("i", i)
		for j := i; j < (i + n*k); j += k {
			//fmt.Println(j, len(s), s[j:j+k])
			var curh int64
			curh = ((hashes[j+k]-hashes[j])%m + m) % m
			//fmt.Fprintf(writer, "substr hash %d %d %v\n", curh, ppow[i], nhashes)
			for idx, h := range nhashes {
				//fmt.Fprintln(writer, idx, h, hashes)
				if curh == ((ppow[j] * h) % m) {
					//fmt.Fprintln(writer, idx)
					idxs = append(idxs, idx)
				}
			}
			//fmt.Println(idxs)
		}
		if len(idxs) == n {
			printResult(idxs, n)
			return
		}
	}
	fmt.Fprintf(writer, "NO\n")
}

package main

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

const p1 = 911382323
const m1 = 972663749
const p2 = 333620201
const m2 = 700072757

var reader *bufio.Reader
var writer *bufio.Writer

type Empty struct{}

func hash(s string, m, p int64) int64 {
	var h int64
	for idx, b := range []byte(s) {
		if idx > 0 {
			h = (h*p + int64(b-'a'+1)) % m
		} else {
			h = int64(b - 'a' + 1)
		}
	}
	return h
}

func hasDuplicates(order []int, n int) bool {
	for i := 1; i < n; i++ {
		if order[i] == order[i-1] {
			return true
		}
	}
	return false
}

func printResult(order []int, n int) {
	size := len(order)
	fmt.Fprintf(writer, "YES\n")
	for i, idx := range order {
		if i == (size - 1) {
			fmt.Fprintf(writer, "%d\n", idx)
		} else {
			fmt.Fprintf(writer, "%d ", idx)
		}
	}

}

func main() {
	//iFile, _ := os.OpenFile("input.txt", os.O_CREATE|os.O_RDWR, 777)
	//reader = bufio.NewReader(iFile)
	reader = bufio.NewReader(os.Stdin)
	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, k, g int
	var s, temp string
	idxByHash1 := make(map[int64]int)
	idxByHash2 := make(map[int64]int)
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &g)
	for i := 1; i <= g; i++ {
		fmt.Fscanf(reader, "%s\n", &temp)
		idxByHash1[hash(temp, m1, p1)] = i
		idxByHash2[hash(temp, m2, p2)] = i
		//fmt.Println(temp, hash(temp))
	}

	s = s + s
	sLen := len(s)
	hashes1 := make([]int64, sLen)
	hashes2 := make([]int64, sLen)
	ppow1 := make([]int64, sLen)
	ppow2 := make([]int64, sLen)
	ppow1[0] = 1
	ppow2[0] = 1
	// precompute powers
	for i := 1; i < sLen; i++ {
		ppow1[i] = (ppow1[i-1] * p1) % m1
		ppow2[i] = (ppow2[i-1] * p2) % m2
	}
	// hash of prefixes
	for idx, b := range []byte(s) {
		if idx > 0 {
			hashes1[idx] = (hashes1[idx-1]*p1 + int64(b-'a'+1)) % m1
			hashes2[idx] = (hashes2[idx-1]*p2 + int64(b-'a'+1)) % m2
		} else {
			hashes1[idx] = int64(b - 'a' + 1)
			hashes2[idx] = int64(b - 'a' + 1)
		}
	}
	mid := sLen / 2
	order := make([]int, 0)
	idxs1 := make(map[int64]Empty)
	idxs2 := make(map[int64]Empty)
	i := mid - k
	count := 0
	var curh1, curh2 int64
	for i < (sLen - k) {
		if i > 0 {
			curh1 = (hashes1[i+k-1] - (hashes1[i-1] * ppow1[k] % m1) + m1) % m1
			curh2 = (hashes2[i+k-1] - (hashes2[i-1] * ppow2[k] % m2) + m2) % m2
		} else {
			curh1 = hashes1[i+k-1]
			curh2 = hashes2[i+k-1]
		}
		//fmt.Println(curh1, curh2)
		idx1, ok1 := idxByHash1[curh1]
		idx2, ok2 := idxByHash2[curh2]
		if ok1 || ok2 {
			_, ok3 := idxs1[curh1]
			_, ok4 := idxs2[curh2]
			if !ok3 || !ok4 {
				var idx int
				if ok1 {
					idx = idx1
				} else if ok2 {
					idx = idx2
				}
				order = append(order, idx)
				idxs1[curh1] = Empty{}
				idxs2[curh2] = Empty{}
				i = i + k
				count += 1
			} else {
				order = nil
				break
			}
		} else {
			//fmt.Println("rewinding", i, "to", i - count * k)
			order = nil
			idxs1 = make(map[int64]Empty)
			idxs2 = make(map[int64]Empty)
			i = i - count*k
			i = i + 1
			if i > mid {
				break
			}

			count = 0
		}
	}
	if len(order) == n {
		printResult(order, n)
	} else {
		fmt.Fprintf(writer, "NO\n")
	}

}


Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths $$$a$$$, $$$b$$$, and $$$c$$$. Now he needs to find out some possible integer length $$$d$$$ of the fourth straight fence segment so that he can build the fence using these four segments. In other words, the fence should have a quadrilateral shape with side lengths equal to $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$. Help Yura, find any possible length of the fourth side.A non-degenerate simple quadrilateral is such a quadrilateral that no three of its corners lie on the same line, and it does not cross itself.

The first line contains a single integer $$$t$$$ — the number of test cases ($$$1 \le t \le 1000$$$). The next $$$t$$$ lines describe the test cases. Each line contains three integers $$$a$$$, $$$b$$$, and $$$c$$$ — the lengths of the three fence segments ($$$1 \le a, b, c \le 10^9$$$).

For each test case print a single integer $$$d$$$ — the length of the fourth fence segment that is suitable for building the fence. If there are multiple answers, print any. We can show that an answer always exists.

NoteWe can build a quadrilateral with sides $$$1$$$, $$$2$$$, $$$3$$$, $$$4$$$.We can build a quadrilateral with sides $$$12$$$, $$$34$$$, $$$56$$$, $$$42$$$.

package main

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

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

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	printf("%d\n", nextLong()+nextLong()+nextLong()-1)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

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

package main

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

func main() {
	var t int
	var a, b, c int64
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b, &c)
		fmt.Println(a + b + c - 1)
	}
}

package main
import (
	"fmt"
)
func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var a, b, c, ans int64

		fmt.Scan(&a, &b, &c)
		ans = a + b + c - 1
		fmt.Println(ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a []int = make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Sort(sort.IntSlice(a))
		diff := a[2] - a[1] - a[0]
		if diff >= 0 {
			fmt.Println(diff + 1)
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		a, b, c := ReadInt64(), ReadInt64(), ReadInt64()
		fmt.Println(solve(a, b, c))
	}
}

func solve(a, b, c int64) int64 {
	if ans, ok := calc(a, b, c); ok {
		return ans
	}
	if ans, ok := calc(b, a, c); ok {
		return ans
	}
	ans, _ := calc(c, a, b)
	return ans
}

func calc(a_, b_, c_ int64) (int64, bool) {
	a, b, c := float64(a_), float64(b_), float64(c_)

	x := -a*a + b*b + c*c
	y := 2 * b * c

	var l, r int64
	if x < y {
		l = 1
	} else {
		l = int64(math.Ceil(math.Sqrt(x - y)))
		if l == 0 {
			l = 1
		}
	}
	r = int64(math.Sqrt(x + y))

	ans := l
	return ans, l <= ans && ans <= r
}

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		a, b, c := ReadInt64(), ReadInt64(), ReadInt64()
		fmt.Println(solve(a, b, c))
	}
}

func solve(a, b, c int64) int64 {
	return a + b + c - 1
}

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

// github.com/EndlessCheng/codeforces-go
func CF1422A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}

	var T, a, b, c int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &a, &b, &c)
		Fprintln(out, max(max(a, b), c))
	}
}

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

package main

import (
	"fmt"
	"sort"
)

func main() {
	var t int
	var a =make([]int,3,3)
	fmt.Scan(&t)
	for cs:=1;cs<=t;cs++ {
		for i:=0;i<3;i++ {
			fmt.Scan(&a[i])
		}
		sort.Ints(a)
		var c=a[2]-a[0]+1
		c=c+a[1]-1
		fmt.Println(c)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var a, b, c int64
		fmt.Fscan(reader, &a, &b, &c)

		fmt.Println(a + b + c - 1)
	}
}

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

	return b
}

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

	return b
}

package main

import (
	"fmt"
	"math"
)

func main () {

	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Scan(&a)
		fmt.Scan(&b)
		fmt.Scan(&c)

		fmt.Println(int(math.Sqrt(math.Pow(float64(a-c), 2) + math.Pow(float64(b), 2)))+1)
	}
}

package main

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

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

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	printf("%d\n", nextInt()+nextInt()+nextInt()-1)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

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

package main

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

func main() {
	var t, a, b, c int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &a, &b, &c)
		fmt.Println(a + b + c - 1)
	}
}

package main
import (
	"fmt"
)
func main() {
	var t int
	fmt.Scanf("%d\n", &t)
	for ; t > 0; t-- {
		var a, b, c int

		fmt.Scan(&a, &b, &c)
		ans := a + b + c - 1
		fmt.Println(ans)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a []int = make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Sort(sort.IntSlice(a))
		fmt.Println(a)
		diff := a[2] - a[1] - a[0]
		if diff >= 0 {
			fmt.Println(diff + 1)
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(in, &a, &b, &c)
		fmt.Println(1)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a []int = make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Sort(sort.IntSlice(a))
		diff := a[2] - a[1] - a[0]
		if diff < 0 {
			fmt.Println(diff)
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var a []int = make([]int, 3)
		fmt.Fscan(in, &a[0], &a[1], &a[2])
		sort.Sort(sort.IntSlice(a))
		diff := a[2] - a[1] - a[0]
		if diff <= 2 {
			fmt.Println(diff + 2)
		} else {
			fmt.Println(1)
		}
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		a, b, c := ReadInt64(), ReadInt64(), ReadInt64()
		fmt.Println(solve(a, b, c))
	}
}

func solve(a_, b_, c_ int64) int64 {
	a, b, c := float64(a_), float64(b_), float64(c_)
	v := -a*a + b*b + c*c - 2*b*c
	if v == 0 {
		return 1
	}
	l := math.Sqrt(v)
	return int64(math.Ceil(l))
}

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		var a, b, c int
		fmt.Fscan(reader, &a, &b, &c)

		fmt.Println(a + b + c - 1)
	}
}

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

	return b
}

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

	return b
}


You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters. $$$n$$$ is even.For each position $$$i$$$ ($$$1 \le i \le n$$$) in string $$$s$$$ you are required to change the letter on this position either to the previous letter in alphabetic order or to the next one (letters 'a' and 'z' have only one of these options). Letter in every position must be changed exactly once.For example, letter 'p' should be changed either to 'o' or to 'q', letter 'a' should be changed to 'b' and letter 'z' should be changed to 'y'.That way string "codeforces", for example, can be changed to "dpedepqbft" ('c' $$$\rightarrow$$$ 'd', 'o' $$$\rightarrow$$$ 'p', 'd' $$$\rightarrow$$$ 'e', 'e' $$$\rightarrow$$$ 'd', 'f' $$$\rightarrow$$$ 'e', 'o' $$$\rightarrow$$$ 'p', 'r' $$$\rightarrow$$$ 'q', 'c' $$$\rightarrow$$$ 'b', 'e' $$$\rightarrow$$$ 'f', 's' $$$\rightarrow$$$ 't').String $$$s$$$ is called a palindrome if it reads the same from left to right and from right to left. For example, strings "abba" and "zz" are palindromes and strings "abca" and "zy" are not.Your goal is to check if it's possible to make string $$$s$$$ a palindrome by applying the aforementioned changes to every position. Print "YES" if string $$$s$$$ can be transformed to a palindrome and "NO" otherwise.Each testcase contains several strings, for each of them you are required to solve the problem separately.

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 50$$$) — the number of strings in a testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th string. The first line of the pair contains a single integer $$$n$$$ ($$$2 \le n \le 100$$$, $$$n$$$ is even) — the length of the corresponding string. The second line of the pair contains a string $$$s$$$, consisting of $$$n$$$ lowercase Latin letters.

Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th string of the input. Print "YES" if it's possible to make the $$$i$$$-th string a palindrome by applying the aforementioned changes to every position. Print "NO" otherwise.

NoteThe first string of the example can be changed to "bcbbcb", two leftmost letters and two rightmost letters got changed to the next letters, two middle letters got changed to the previous letters.The second string can be changed to "be", "bg", "de", "dg", but none of these resulting strings are palindromes.The third string can be changed to "beeb" which is a palindrome.The fifth string can be changed to "lk", "lm", "nk", "nm", but none of these resulting strings are palindromes. Also note that no letter can remain the same, so you can't obtain strings "ll" or "mm".

package main

import "fmt"

func main(){
    var t int
    fmt.Scanf("%d ",&t)
    for q:=0;q<t;q++{
        var n  int
        fmt.Scanf("%d ",&n)
        var s string
        fmt.Scanf("%s ",&s)
        fl:=1
        for i:=0;i<n/2;i++ {
            j:=n-1-i;
            var si,sj int
            si=int(s[i])
            sj=int(s[j])
            if -2==si-sj||si-sj==2||si==sj {

            }else{
                fl=0
            }
        }
        if fl>0 {
            fmt.Println("YES")
        }else {

            fmt.Println("NO")
        }
    }
}

package main

import (
	"fmt"
	"math"
)

func check(s string, len int) bool {
	for i := 0; i < len/2; i++ {
		var firstchar int
		var secondchar int
		firstchar = int(s[i])
		secondchar = int(s[len-i-1])
		dif := math.Abs(float64(firstchar) - float64(secondchar))
		if dif != 2 && dif != 0 {
			return false
		}
	}
	return true
}

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var len int
		var s string
		fmt.Scanf("%d\n", &len)
		fmt.Scanf("%s\n", &s)
		checkresult := check(s, len)
		if checkresult == true {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

func main()  {

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

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

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

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

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

		f := true
		for i := 0; i < n / 2; i++ {
			x1, x2 := s[i] + 1, s[i] - 1
			if s[i] == 'a' {
				x2 += 2
			} else if s[i] == 'z' {
				x1 -= 2
			}
			y1, y2 := s[len(s)-i-1] + 1, s[len(s)-i-1] - 1
			if s[len(s)-i-1] == 'a' {
				y2 += 2
			} else if s[len(s)-i-1] == 'z' {
				y1 -= 2
			}
			if x1 != y1 && x1 != y2 && x2 != y1 && x2 != y2 {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
		out.Flush()

	}

}

package main

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

var scanner * bufio.Scanner

func next_int()(result int64, err error){
  if !scanner.Scan() {
    return 0, scanner.Err()
  }
  return strconv.ParseInt(scanner.Text(), 10, 32)
}

func next_str()(result string, err error){
  if !scanner.Scan() {
    return string(""), scanner.Err()
  }
  return scanner.Text(), nil
}

func update_range(ch byte) (lb byte, ub byte) {
  if (ch == 'a') {
    return 'A', 'b'
  }
  if (ch == 'z') {
    return 'y', 'Z'
  }
  return ch - 1 , ch + 1
}

func main() {

  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  tests, _ := next_int()
  for i := int64(1) ; i <= tests; i++ {
    next_int()
    str, _ := next_str()
    var possible bool = true
    var last int = len(str) - 1
    for j := 0; j < last; j++ {
      flb, fub := update_range(str[j])
      slb, sub := update_range(str[last])
      if !(flb == slb || flb == sub || fub == slb || fub == sub) {
        possible = false;
        break;
      }
      last--;
    }
    if possible {
      fmt.Println("YES")
    }else{
      fmt.Println("NO")
    }
  }
}

package main

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

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

	nStrs := readInt(r)
	for i := 0; i < nStrs; i++ {
		l := readInt(r)
		s := readString(r, l)
		if check(s) {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

func check(s string) bool {
	if len(s) == 0 {
		return true
	}

	for i := 0; i <= (len(s) - 1) / 2; i++ {
		f := s[i]
		l := s[len(s)-1-i]
		if !intersects(getChars(f), getChars(l)) {
			return false
		}
	}
	return true
}

func getChars(b byte) []byte {
	if b == 'a' {
		return []byte{'b'}
	} else if b == 'z' {
		return []byte{'y'}
	} else {
		return []byte{b -1, b +1}
	}
}

func intersects(bs1 []byte, bs2 []byte) bool {
	for _, b1 := range bs1 {
		for _, b2 := range bs2 {
			if b1 == b2 {
				return true
			}
		}
	}
	return false
}

// read utils
func readInt(reader *bufio.Reader) int {
	nTemp, err := strconv.ParseInt(readLine(reader), 10, 64)
	checkError(err)
	n := int(nTemp)
	return n
}

func readString(reader *bufio.Reader, l int) string {
	sTemp := readLine(reader)
	return sTemp[:l]
}

func readLine(reader *bufio.Reader) string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

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

func checkError(err error) {
	if err != nil {
		panic(err)
	}
}

package main

import "fmt"

func main (){
    var T int
    fmt.Scan(&T)
    for I:=0; I<T; I++ {
        var n int
        var s string
        fmt.Scan(&n, &s)
        fail := false
        for i:=0; i<n/2; i++ {
            j := n-i-1
            x := int(s[i]) - int(s[j])
            if x != -2 && x != 2 && x != 0 {
                fail = true
            }
        }
        if !fail {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }
}

package main

import "fmt"

func isPalindrome(input string) bool {
	for i := 0; i < len(input)/2; i++ {
		if input[i] != input[len(input)-i-1] {
			return false
		}
	}
	return true
}

func newLetter(letter string, test int) string {
	asciiBytes := []byte(letter)
	if test == -1 {
		if letter == "a" {
			return "a"
		}
		return string(asciiBytes[0] - 1)

	}
	if test == 1 {
		if letter == "z" {
			return "z"
		}
		return string(asciiBytes[0] + 1)
	}
	return letter
}

func generateString(s string, l int) bool {
	j := l - 1
	for i := 0; i < l/2; i += 1 {
		if s[i] != s[j] {
			var t1 string = newLetter(string(s[i]), 1)
			var t2 string = newLetter(string(s[j]), -1)
			if t1 != t2 {
				t1 = newLetter(string(s[i]), -1)
				t2 = newLetter(string(s[j]), 1)
				if t1 != t2 {
					return false
				}
			}
		}
		j -= 1
		if i == l/2 && j == l/2 {
			return true
		}
	}
	return true
}

func isTrue(len int, s string) bool {
	if isPalindrome(s) {
		return true
	}
	return generateString(s, len)
}

func out(a bool) string {
	if a {
		return "YES"
	}
	return "NO"
}
func main() {
	//Input
	var t int
	fmt.Scanf("%d", &t)
	a := make([]int, t)
	b := make([]string, t)
	for i := 0; i < t; i++ {
		fmt.Scan(&a[i], &b[i])
	}

	for i := 0; i < t; i++ {
		fmt.Println(out(isTrue(a[i], b[i])))
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var T int
	fmt.Fscan(reader, &T)

	for T > 0 {
		var (
			ln int
			st string
		)

		fmt.Fscan(reader, &ln, &st)
		cont := true
		for i := 0; i < ln/2; i++ {

			if st[i]+1 != st[ln-i-1]-1 && st[i]-1 != st[ln-i-1]+1 && st[i]+1 != st[ln-i-1]+1 && st[i]-1 != st[ln-i-1]-1 {
				fmt.Println("NO")
				cont = false
				break
			}
		}
		if cont {
			fmt.Println("YES")
		}
		T--
	}
}

//go 1.6

package main
import "fmt"
func main() {
	var n int
	var o []string
	fmt.Scan(&n)
	for i:= 0;i<n;i++{
		var l int
		var s string
		fmt.Scan(&l,&s)
		b := []byte(s)
		f := true
		for j:=0;j<l/2;j++{
			if !(b[j] == b[l-j-1] || b[j]-1== b[l-j-1]+1 || b[j]+1 == b[l-j-1]-1) {
				f = false
			}
		}
		if f {
			s = "YES"
		}  else{
			s = "NO"
		}
		o =append(o,s)
	}
	for _,a := range o {
	fmt.Println(a)
	}
}

package main

import (
    "fmt"
    "math"
)

func check(s string, len int) bool {
    for i:=0; i<len/2; i++ {
        fistChar := int(s[i])
        lastChar := int(s[len-1-i])
        dif := math.Abs(float64(fistChar - lastChar))

        if dif != 2 && dif != 0 {
            return false
        }
    }
    return true
}

func main() {
    var n int

    fmt.Scanf("%d\n", &n)

    for i:=0; i<n; i ++ {
        var len int
        var s string

        fmt.Scanf("%d\n", &len)
        fmt.Scanf("%s\n", &s)

        //fmt.Printf("str:%s len:%d\n", s, len)

        boolResult := check(s, len)

        if boolResult == true {
            fmt.Println("YES")
        } else {
            fmt.Println("NO")
        }
    }

}

package main

import "fmt"

func main(){
    var t int
    fmt.Scanf("%d ",&t)
    for q:=0;q<t;q++{
        var n  int
        fmt.Scanf("%d ",&n)
        var s string
        fmt.Scanf("%s ",&s)
        fl:=1
        for i:=0;i<n/2;i++ {
            j:=n-1-i;
            var si,sj int
            si=int(s[i])
            sj=int(s[j])
            if -2<=si-sj&&si-sj<=2 {

            }else{
                fl=0
            }
        }
        if fl>0 {
            fmt.Println("YES")
        }else {

            fmt.Println("NO")
        }
    }
}

package main

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

func main()  {

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

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

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

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

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

		f := true
		for i := 0; i < len(s) / 2; i++ {
			x1, x2 := s[i] + 1, s[i] - 1
			if s[i] == 'a' {
				x2 += 2
			} else if s[i] == 'z' {
				x1 -= 2
			}
			y1, y2 := s[len(s)-i-1] + 1, s[len(s)-i-1] - 1
			if s[i] == 'a' {
				y2 += 2
			} else if s[i] == 'z' {
				y1 -= 2
			}
			if x1 != y1 && x1 != y2 && x2 != y1 && x2 != y2 {
				f = false
				break
			}
		}

		if f {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}

	}

}

//go 1.6

package main
import "fmt"
func main() {
	var n int
	var o []string
	fmt.Scan(&n)
	for i:= 0;i<n;i++{
		var l int
		var s string
		fmt.Scan(&l,&s)
		b := []byte(s)
		f := true
		for j:=0;j<l/2;j++{
			if !(b[j] == b[l-j-1] || b[j]-1== b[l-j-1]+1 || b[j]+1 == b[l-j-1]-1) {
				f = false
			}
		}
		if f {
			s = "YES"
		}  else{
			s = "NO"
		}
		o =append(o,s)
	}
	for _,a := range o {
	fmt.Printf(a)
	}
}


As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k operations.Each modification is one of the following:  Pick some row of the matrix and decrease each element of the row by p. This operation brings to DZY the value of pleasure equal to the sum of elements of the row before the decreasing.  Pick some column of the matrix and decrease each element of the column by p. This operation brings to DZY the value of pleasure equal to the sum of elements of the column before the decreasing. DZY wants to know: what is the largest total value of pleasure he could get after performing exactly k modifications? Please, help him to calculate this value.

The first line contains four space-separated integers n, m, k and p (1 ≤ n, m ≤ 103; 1 ≤ k ≤ 106; 1 ≤ p ≤ 100). Then n lines follow. Each of them contains m integers representing aij (1 ≤ aij ≤ 103) — the elements of the current row of the matrix.

Output a single integer — the maximum possible total pleasure value DZY could get.

NoteFor the first sample test, we can modify: column 2, row 2. After that the matrix becomes:1 10 0For the second sample test, we can modify: column 2, row 2, row 1, column 1, column 2. After that the matrix becomes:-3 -3-2 -2

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, m, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	res[0] = 0
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*m)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, m, p, k)
	col_val := Run(col, m, n, p, k)
	var res int64 = -1000000000000000
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"math"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, m, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	res[0] = 0
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*m)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, m, p, k)
	col_val := Run(col, m, n, p, k)
	var res int64 = math.MinInt64
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}

package main

import (
	"fmt"
	"bufio"
	"os"
	"container/heap"
)

const (
	maxn = 1000+5
	maxm = 1000+5
	maxk = 1000000+5
)

type IntHeap []int64
func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) {
	*h = append(*h, x.(int64))
}
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

var (
	ar [maxn][maxm]int
	row IntHeap
	col IntHeap
	rowv [maxk]int64
	colv [maxk]int64
)

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

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

	row = make(IntHeap, n)
	col = make(IntHeap, m)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscan(in, &ar[i][j])
			row[i] += int64(ar[i][j])
			col[j] += int64(ar[i][j])
		}
	}

	// fmt.Println(row)
	// fmt.Println(col)

	heap.Init(&row)
	heap.Init(&col)
	for i := 1; i <= k; i++ {
		v := heap.Pop(&row).(int64)
		rowv[i] = rowv[i-1] + v
		heap.Push(&row, v-int64(p*m))

		v = heap.Pop(&col).(int64)
		colv[i] = colv[i-1] + v
		heap.Push(&col, v-int64(p*n))
	}

	// for i := 0; i < 10; i++ {
	// 	fmt.Print(rowv[i], " ")
	// }
	// fmt.Println()
	// for i := 0; i < 10; i++ {
	// 	fmt.Print(colv[i], " ")
	// }
	// fmt.Println()

	res := int64(-1000000000000000000)
	for i := 0; i <= k; i++ {
		v := rowv[i] + colv[k-i] - int64(i)*int64(k-i)*int64(p)
		if v > res {
			res = v
		}
	}
	fmt.Fprintln(out, res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int, n)
	col := make([]int, m)
	for i := 0; i < n; i++ {
		var v int
		for j := 0; j < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_heap := &IntHeap{}
	col_heap := &IntHeap{}
	heap.Init(row_heap)
	heap.Init(col_heap)
	for i := 0; i < n; i++ {
		heap.Push(row_heap, row[i])
	}
	for j := 0; j < m; j++ {
		heap.Push(col_heap, col[j])
	}
	var row_reduce, col_reduce, res int = 0, 0, 0
	for i := 0; i < k; i++ {
		row_val := (*row_heap)[0] - row_reduce
		col_val := (*col_heap)[0] - col_reduce
		if row_val > col_val {
			res += row_val
			heap.Pop(row_heap)
			heap.Push(row_heap, row_val-p*n)
			col_reduce += p
		} else {
			res += col_val
			heap.Pop(col_heap)
			heap.Push(col_heap, col_val-p*m)
			row_reduce += p
		}
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, m, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	res[0] = 0
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*m)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, m, p, k)
	col_val := Run(col, m, n, p, k)
	var res int64 = -1000000000000
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, m, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	res[0] = 0
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*m)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, m, p, k)
	col_val := Run(col, m, n, p, k)
	var res int64 = -1000000000
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

type IntHeap []int64

func (h IntHeap) Len() int            { return len(h) }
func (h IntHeap) Less(i, j int) bool  { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *IntHeap) Push(x interface{}) { *h = append(*h, x.(int64)) }
func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

func Run(val []int64, n, p, k int64) []int64 {
	val_heap := &IntHeap{}
	heap.Init(val_heap)
	for i := 0; int64(i) < n; i++ {
		heap.Push(val_heap, val[i])
	}
	var sum_res int64 = 0
	res := make([]int64, k+1)
	for i := 0; int64(i) < k; i++ {
		var top int64 = (*val_heap)[0]
		heap.Pop(val_heap)
		sum_res += top
		res[i+1] = sum_res
		heap.Push(val_heap, top-p*n)
	}
	return res
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	var n, m, k, p int64
	fmt.Fscan(reader, &n, &m, &k, &p)
	row := make([]int64, n)
	col := make([]int64, m)
	for i := 0; int64(i) < n; i++ {
		var v int64
		for j := 0; int64(j) < m; j++ {
			fmt.Fscan(reader, &v)
			row[i] += v
			col[j] += v
		}
	}
	row_val := Run(row, n, p, k)
	col_val := Run(col, m, p, k)
	var res int64 = -1000000000
	for i := 0; int64(i) <= k; i++ {
		var ith_res int64 = row_val[i] + col_val[k-int64(i)] - int64(i)*(k-int64(i))*p
		if res < ith_res {
			res = ith_res
		}
	}
	fmt.Println(res)
}