The tycoon of a winery empire in Mondstadt, unmatched in every possible way. A thinker in the Knights of Favonius with an exotic appearance.This time, the brothers are dealing with a strange piece of wood marked with their names. This plank of wood can be represented as a string of $$$n$$$ characters. Each character is either a 'D' or a 'K'. You want to make some number of cuts (possibly $$$0$$$) on this string, partitioning it into several contiguous pieces, each with length at least $$$1$$$. Both brothers act with dignity, so they want to split the wood as evenly as possible. They want to know the maximum number of pieces you can split the wood into such that the ratios of the number of occurrences of 'D' to the number of occurrences of 'K' in each chunk are the same.Kaeya, the curious thinker, is interested in the solution for multiple scenarios. He wants to know the answer for every prefix of the given string. Help him to solve this problem!For a string we define a ratio as $$$a:b$$$ where 'D' appears in it $$$a$$$ times, and 'K' appears $$$b$$$ times. Note that $$$a$$$ or $$$b$$$ can equal $$$0$$$, but not both. Ratios $$$a:b$$$ and $$$c:d$$$ are considered equal if and only if $$$a\cdot d = b\cdot c$$$. For example, for the string 'DDD' the ratio will be $$$3:0$$$, for 'DKD' — $$$2:1$$$, for 'DKK' — $$$1:2$$$, and for 'KKKKDD' — $$$2:4$$$. Note that the ratios of the latter two strings are equal to each other, but they are not equal to the ratios of the first two strings.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 5 \cdot 10^5$$$) — the length of the wood. The second line of each test case contains a string $$$s$$$ of length $$$n$$$. Every character of $$$s$$$ will be either 'D' or 'K'. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5 \cdot 10^5$$$.

For each test case, output $$$n$$$ space separated integers. The $$$i$$$-th of these numbers should equal the answer for the prefix $$$s_{1},s_{2},\dots,s_{i}$$$.

NoteFor the first test case, there is no way to partition 'D' or 'DDK' into more than one block with equal ratios of numbers of 'D' and 'K', while you can split 'DD' into 'D' and 'D'.For the second test case, you can split each prefix of length $$$i$$$ into $$$i$$$ blocks 'D'.

package main

import (
	"bufio"
	"os"
	"fmt"
	"math/rand"
	"time"
	"bytes"
)

const LOCAL = false

func main() {

	rand.Seed(time.Now().UnixNano())

	str := "KDKD";

	if LOCAL {

		w := bufio.NewWriter(os.Stdout)
		start := time.Now().UnixNano()

		for i := 0; i < 18; i++ {
			var n int
			n = 27814

			var s string

			var bts bytes.Buffer

			for k := 0; k < n; k++ {
				bts.WriteByte(str[rand.Intn(4)])
			}
			s = bts.String()

			solveNow(n, s, w)
			fmt.Fprintln(w)
		}
		w.Flush()

		end := time.Now().UnixNano()
		fmt.Println((end - start)/1000000)

	} else {
		r := bufio.NewReader(os.Stdin)
		w := bufio.NewWriter(os.Stdout)
		defer w.Flush()

		var t int

		fmt.Fscan(r, &t)

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

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

		//	test(s, n)

			solveNow(n, s, w)

			fmt.Fprintln(w)
		}
	}
}

type pair struct {
	d, k int
}

func solveNow(n int, s string, w *bufio.Writer) {
	mp := make(map[pair]int)

	p := pair{}

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

		if s[i] == 'D' {
			p.d++

		} else {
			p.k++
		}

		if p.d == 0 {
			mp[pair{0, 1}]++
			v := mp[pair{0, 1}]
			fmt.Fprintf(w, "%d ", v)

		} else if p.k == 0 {
			mp[pair{1, 0}]++
			v := mp[pair{1, 0}]
			fmt.Fprintf(w, "%d ", v)

		} else {
			g := gcd(p.d, p.k)
			mp[pair{p.d/g, p.k/g}]++

			v := mp[pair{p.d/g, p.k/g}]

			fmt.Fprintf(w, "%d ", v)
		}
	}
}

func solve(n int, s string, w *bufio.Writer) {

	dp := make([][2]int, n)

	if s[0] == 'D' {

		// 0 - D
		//1 - K
		dp[0][0] = 1
		dp[0][1] = 0

	} else {
		// 0 - D
		//1 - K
		dp[0][0] = 0
		dp[0][1] = 1
	}

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

		if s[i] == 'D' {

			dp[i][0] = dp[i - 1][0] + 1
			dp[i][1] = dp[i - 1][1]

		} else {
			dp[i][0] = dp[i - 1][0]
			dp[i][1] = dp[i - 1][1] + 1
		}
	}

	for i := 0; i < n; i++ {
		ds := dp[i][0]
		ks := dp[i][1]

		g := gcd(ds, ks)

		if  g == 1 {
			fmt.Fprintf(w, "%d ", 1)
			continue
		}

		var maxCnt int

		for gg := g; gg >= 1; gg-- {

			if g % gg == 0 {
				d := ds/gg
				k := ks/gg

				l := d + k

				done := true

				var cnt int

				var prev int
				var j int

				prev = -1
				j = l - 1

				for ; j <= i; j += l {

					yes := false

					var vd int
					var vk int

					if prev != -1 {
						vd = dp[j][0] - dp[prev][0]
						vk = dp[j][1] - dp[prev][1]
					} else {
						vd = dp[j][0]
						vk = dp[j][1]
					}

					if d * vk == k * vd {
						cnt++
						prev = j
						yes = true
					}

					if j >= i && !yes {
						done = false
					}
				}

				if done {

					if cnt > maxCnt {
						maxCnt = cnt
					}
				}
			}
		}

		fmt.Fprintf(w, "%d ", maxCnt)
	}
}

func gcd(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

package main

import (
	"bufio"
	"io/ioutil"
	"os"
	"strconv"
	"unicode"
)

var bytes []byte
var l, max int
var ws *bufio.Writer

/**
 * Perform Quick Scan of 1 data(with no spaces in-between) on the buffered input
 */
func fastInt() int {
	for unicode.IsSpace(rune(bytes[l])) {l++}
	b := bytes[l]

	// Check if the bytes is not a number
	for b < 48 || b > 57 {
		l++
		b = bytes[l]
	}

	result := 0
	for 47 < b && b < 58 {
		result = (result << 3) + (result << 1) + int(b-48)

		l++
		if l > max {
			return result
		}
		b = bytes[l]
	}
	return result
}

func fastStr() []byte {
	for unicode.IsSpace(rune(bytes[l])) {l++}
	result := make([]byte, 0)
	for !unicode.IsSpace(rune(bytes[l])) {
		result = append(result, bytes[l])
		l++
	}
	return result
}

var sc *bufio.Scanner

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

type Pair struct {
	fi, se int
}

func solve(){
	n := fastInt()
	s := fastStr()
	m := make(map[Pair]int)
	atas := 0
	for i := 0;i < n;i++ {
		if(s[i] == 'D') {
			atas++
		}
		curgcd := gcd(atas, i + 1)
		currentKey := Pair{atas / curgcd, (i + 1) / curgcd}
		val := m[currentKey]
		ws.WriteString(strconv.Itoa(val + 1))
		ws.WriteString(" ")
		m[currentKey]++
	}
	ws.WriteString("\n")
}

func main(){

	// Read all the input into Buffer
	bytes, _ = ioutil.ReadAll(bufio.NewReader(os.Stdin))
	max = len(bytes) - 1

	// Create a write buffer directed to STDOUT
	ws = bufio.NewWriter(os.Stdout)

	tc := fastInt()
	for i := 0;i < tc;i++{
		//fmt.Printf("Case #%v:", i)
		solve()
	}
	ws.Flush()
}

package main

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

var in *bufio.Reader

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

func normalize(dCnt, kCnt int) int64 {
	if dCnt == 0 {
		kCnt = 1
	}
	if kCnt == 0 {
		dCnt = 1
	}
	if dCnt != 0 && kCnt != 0 {
		g := gcd(dCnt, kCnt)
		dCnt /= g
		kCnt /= g
	}

	return int64(dCnt)*1000000 + int64(kCnt)
}

func solve() {
	var n int
	fmt.Fscan(in, &n)

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

	dCnt, kCnt := 0, 0
	ratio := make(map[int64]int)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		if a[i] == 'D' {
			dCnt++
		} else if a[i] == 'K' {
			kCnt++
		} else {
			panic("impossible")
		}

		split := 1
		key := normalize(dCnt, kCnt)
		oldIdx, ok := ratio[key]
		if ok {
			split += dp[oldIdx]
		}
		ratio[key] = i
		dp[i] = split
	}

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

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

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

	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

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

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

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

		freq := map[int64]int{}
		var cntd, cntk int64
		for i := 0; i < n; i++ {
			if s[i] == 'D' {
				cntd++
			} else {
				cntk++
			}
			base := Gcd(cntd, cntk)
			key := cntd/base*x + cntk/base
			freq[key]++
			if i > 0 {
				fmt.Fprint(writer, " ")
			}
			fmt.Fprint(writer, freq[key])
		}
		fmt.Fprintln(writer)
	}
}

var x = int64(5e5 + 1)

func Gcd(a, b int64) int64 {
	for b > 0 {
		a, b = b, a%b
	}
	return a
}

package main

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

type pair struct {
	a, b int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	solve := func(Case int) {
		var n int
		var s string
		fmt.Fscan(in, &n, &s)
		dp := map[pair]int{}
		z, o := 0, 0
		for i := range s {
			switch s[i] {
			case 'D':
				z++
			default:
				o++
			}
			_gcd := z + o
			if z != 0 && o != 0 {
				_gcd = gcd(o, z)
			}
			dp[pair{z / _gcd, o / _gcd}] += 1
			fmt.Fprint(out, dp[pair{z / _gcd, o / _gcd}])
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, "\n")
	}

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

func max(x, y int64) int64 {
	if x < y {
		return y
	}
	return x
}

func gcd(x, y int) int {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ d, k int }
	solve := func(Case int) {
		var n int
		var s []byte
		Fscan(in, &n, &s)
		c := map[pair]int{}
		p := pair{}
		for _, b := range s {
			if b == 'D' {
				p.d++
			} else {
				p.k++
			}
			if p.d == 0 {
				c[pair{0, 1}]++
				Fprint(out, c[pair{0, 1}], " ")
				continue
			} else if p.k == 0 {
				c[pair{1, 0}]++
				Fprint(out, c[pair{1, 0}], " ")
				continue
			}
			g := gcd(p.d, p.k)
			q := pair{p.d / g, p.k / g}
			c[q]++
			Fprint(out, c[q], " ")
		}
		Fprintln(out)
	}

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

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

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

func gcd(a, b int) int {
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"math/rand"
	"time"
	"bytes"
)

const LOCAL = true

func main() {

	rand.Seed(time.Now().UnixNano())

	str := "KDKD";

	if LOCAL {

		w := bufio.NewWriter(os.Stdout)
		start := time.Now().UnixNano()

		for i := 0; i < 18; i++ {
			var n int
			n = 27814

			var s string

			var bts bytes.Buffer

			for k := 0; k < n; k++ {
				bts.WriteByte(str[rand.Intn(4)])
			}
			s = bts.String()

			solve(n, s, w)
			fmt.Fprintln(w)
		}
		w.Flush()

		end := time.Now().UnixNano()
		fmt.Println((end - start)/1000000)

	} else {
		r := bufio.NewReader(os.Stdin)
		w := bufio.NewWriter(os.Stdout)
		defer w.Flush()

		var t int

		fmt.Fscan(r, &t)

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

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

		//	test(s, n)

			solve(n, s, w)

			fmt.Fprintln(w)
		}
	}
}

func test(s string, n int) {

	dp := make([][2]int, n)

	if s[0] == 'D' {

		// 0 - D
		//1 - K
		dp[0][0] = 1
		dp[0][1] = 0

	} else {
		// 0 - D
		//1 - K
		dp[0][0] = 0
		dp[0][1] = 1
	}

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

		if s[i] == 'D' {

			dp[i][0] = dp[i - 1][0] + 1
			dp[i][1] = dp[i - 1][1]

		} else {
			dp[i][0] = dp[i - 1][0]
			dp[i][1] = dp[i - 1][1] + 1
		}
	}

	for i := 0; i < len(s); i++ {
		leftD := dp[i][0]
		leftK := dp[i][1]

		d := dp[n - 1][0] - leftD
		k := dp[n - 1][1] - leftK

		if leftD * k == d * leftK {
			fmt.Println("FOUND")
			fmt.Println(i)
			fmt.Println(leftD)
			fmt.Println(leftK)
			fmt.Println(d)
			fmt.Println(k)
		}
	}
}

func solve(n int, s string, w *bufio.Writer) {

	dp := make([][2]int, n)

	if s[0] == 'D' {

		// 0 - D
		//1 - K
		dp[0][0] = 1
		dp[0][1] = 0

	} else {
		// 0 - D
		//1 - K
		dp[0][0] = 0
		dp[0][1] = 1
	}

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

		if s[i] == 'D' {

			dp[i][0] = dp[i - 1][0] + 1
			dp[i][1] = dp[i - 1][1]

		} else {
			dp[i][0] = dp[i - 1][0]
			dp[i][1] = dp[i - 1][1] + 1
		}
	}

	for i := 0; i < n; i++ {
		ds := dp[i][0]
		ks := dp[i][1]

		g := gcd(ds, ks)

		if  g == 1 {
			fmt.Fprintf(w, "%d ", 1)
			continue
		}

		var maxCnt int

		for gg := g; gg >= 1; gg-- {

			if g % gg == 0 {
				d := ds/gg
				k := ks/gg

				l := d + k

				done := true

				var cnt int

				var prev int
				var j int

				prev = -1
				j = l - 1

				for ; j <= i; j += l {

					yes := false

					var vd int
					var vk int

					if prev != -1 {
						vd = dp[j][0] - dp[prev][0]
						vk = dp[j][1] - dp[prev][1]
					} else {
						vd = dp[j][0]
						vk = dp[j][1]
					}

					if d * vk == k * vd {
						cnt++
						prev = j
						yes = true
					}

					if j >= i && !yes {
						done = false
					}
				}

				if done {

					if cnt > maxCnt {
						maxCnt = cnt
					}
				}
			}
		}

		fmt.Fprintf(w, "%d ", maxCnt)
	}
}

func gcd(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"math/rand"
	"time"
	"bytes"
)

const LOCAL = false

func main() {

	rand.Seed(time.Now().UnixNano())

	str := "KDKD";

	if LOCAL {

		for i := 0; i < 1000; i++ {
			var n int
			n = 500

			var s string

			var bts bytes.Buffer

			for k := 0; k < n; k++ {
				bts.WriteByte(str[rand.Intn(4)])
			}
			s = bts.String()

			ans := solve(n, s)

			for i := 0; i < len(ans); i++ {
				fmt.Print(ans[i])
				fmt.Print(" ")
			}
			fmt.Println()

		}

	} else {
		r := bufio.NewReader(os.Stdin)
		w := bufio.NewWriter(os.Stdout)

		var t int

		fmt.Fscan(r, &t)

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

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

			ans := solve(n, s)

			for i := 0; i < len(ans); i++ {
				fmt.Fprint(w, ans[i])
				fmt.Fprint(w, " ")
			}
			fmt.Fprintln(w)
			w.Flush()
		}
	}
}

func solve(n int, s string) []int {

	dp := make([][2]int, n)

	if s[0] == 'D' {

		// 0 - D
		//1 - K
		dp[0][0] = 1
		dp[0][1] = 0

	} else {
		// 0 - D
		//1 - K
		dp[0][0] = 0
		dp[0][1] = 1
	}

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

		if s[i] == 'D' {

			dp[i][0] = dp[i - 1][0] + 1
			dp[i][1] = dp[i - 1][1]

		} else {
			dp[i][0] = dp[i - 1][0]
			dp[i][1] = dp[i - 1][1] + 1
		}
	}

	var ans []int

	cache := make(map[int][2]int)

	for i := 0; i < n; i++ {
		ds := dp[i][0]
		ks := dp[i][1]

		g := gcd(ds, ks)

		if  g == 1 {
			ans = append(ans, 1)
			continue
		}

		var maxCnt int
		var lc int
		var indexToCache int
		var cntCache int

		for gg := g; gg >= 1; gg-- {

			if g % gg == 0 {
				d := ds/gg
				k := ks/gg

				l := d + k

				done := true

				var cnt int

				var prev int
				var j int

				if v, ok := cache[l]; ok {
					prev = v[0]
					cnt += v[1]
					j = prev + l
				} else {
					prev = -1
					j = l - 1
				}

				for ; j <= i; j += l {

					yes := false

					var vd int
					var vk int

					if prev != -1 {
						vd = dp[j][0] - dp[prev][0]
						vk = dp[j][1] - dp[prev][1]
					} else {
						vd = dp[j][0]
						vk = dp[j][1]
					}

					if d * vk == k * vd {
						cnt++
						prev = j
						yes = true
					}

					if j >= i && !yes {
						done = false
					}
				}

				if done {

					if cnt > maxCnt {
						cntCache = cnt
						indexToCache = i
						lc = l
						maxCnt = cnt
					}
				}
			}
		}

		var arr [2]int
		arr[0] = indexToCache
		arr[1] = cntCache
		cache[lc] = arr
		ans = append(ans, maxCnt)
	}

	return ans
}

func gcd(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"math/rand"
	"time"
	"bytes"
)

const LOCAL = false

func main() {

	rand.Seed(time.Now().UnixNano())

	str := "KDKD";

	if LOCAL {

		for i := 0; i < 1000; i++ {
			var n int
			n = 500

			var s string

			var bts bytes.Buffer

			for k := 0; k < n; k++ {
				bts.WriteByte(str[rand.Intn(4)])
			}
			s = bts.String()

			ans := solve(n, s)

			for i := 0; i < len(ans); i++ {
				fmt.Print(ans[i])
				fmt.Print(" ")
			}
			fmt.Println()

		}

	} else {
		r := bufio.NewReader(os.Stdin)
		w := bufio.NewWriter(os.Stdout)

		var t int

		fmt.Fscan(r, &t)

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

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

			ans := solve(n, s)

			for i := 0; i < len(ans); i++ {
				fmt.Fprint(w, ans[i])
				fmt.Fprint(w, " ")
			}
			fmt.Fprintln(w)
			w.Flush()
		}
	}
}

func solve(n int, s string) []int {

	dp := make([][2]int, n)

	if s[0] == 'D' {

		// 0 - D
		//1 - K
		dp[0][0] = 1
		dp[0][1] = 0

	} else {
		// 0 - D
		//1 - K
		dp[0][0] = 0
		dp[0][1] = 1
	}

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

		if s[i] == 'D' {

			dp[i][0] = dp[i - 1][0] + 1
			dp[i][1] = dp[i - 1][1]

		} else {
			dp[i][0] = dp[i - 1][0]
			dp[i][1] = dp[i - 1][1] + 1
		}
	}

	var ans []int

	cache := make(map[int][2]int)

	for i := 0; i < n; i++ {
		ds := dp[i][0]
		ks := dp[i][1]

		g := gcd(ds, ks)

		if  g == 1 {
			ans = append(ans, 1)
			continue
		}

		for gg := g; gg >= 1; gg-- {

			if g % gg == 0 {
				d := ds/gg
				k := ks/gg

				l := d + k

				done := true

				var cnt int

				var prev int
				var j int

				if v, ok := cache[l]; ok {
					prev = v[0]
					cnt += v[1]
					j = prev + l
				} else {
					prev = -1
					j = l - 1
				}

				for ; j <= i; j += l {

					yes := false

					var vd int
					var vk int

					if prev != -1 {
						vd = dp[j][0] - dp[prev][0]
						vk = dp[j][1] - dp[prev][1]
					} else {
						vd = dp[j][0]
						vk = dp[j][1]
					}

					if d * vk == k * vd {
						cnt++
						prev = j
						yes = true
					}

					if j >= i && !yes {
						done = false
					}
				}

				if done {
					var arr [2]int
					arr[0] = i
					arr[1] = cnt
					cache[l] = arr
					ans = append(ans, cnt)
					break
				}
			}
		}
	}

	return ans
}

func gcd(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

package main

import (
	"bufio"
	"os"
	"fmt"
	"math/rand"
	"time"
	"bytes"
)

const LOCAL = false

func main() {

	rand.Seed(time.Now().UnixNano())

	str := "KDKD";

	if LOCAL {

		for i := 0; i < 1000; i++ {
			var n int
			n = 500

			var s string

			var bts bytes.Buffer

			for k := 0; k < n; k++ {
				bts.WriteByte(str[rand.Intn(4)])
			}
			s = bts.String()

			ans := solve(n, s)

			for i := 0; i < len(ans); i++ {
				fmt.Print(ans[i])
				fmt.Print(" ")
			}
			fmt.Println()

		}

	} else {
		r := bufio.NewReader(os.Stdin)
		w := bufio.NewWriter(os.Stdout)

		var t int

		fmt.Fscan(r, &t)

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

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

			ans := solve(n, s)

			for i := 0; i < len(ans); i++ {
				fmt.Fprint(w, ans[i])
				fmt.Fprint(w, " ")
			}
			fmt.Fprintln(w)
			w.Flush()
		}
	}
}

func solve(n int, s string) []int {

	dp := make([][2]int, n)

	if s[0] == 'D' {

		// 0 - D
		//1 - K
		dp[0][0] = 1
		dp[0][1] = 0

	} else {
		// 0 - D
		//1 - K
		dp[0][0] = 0
		dp[0][1] = 1
	}

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

		if s[i] == 'D' {

			dp[i][0] = dp[i - 1][0] + 1
			dp[i][1] = dp[i - 1][1]

		} else {
			dp[i][0] = dp[i - 1][0]
			dp[i][1] = dp[i - 1][1] + 1
		}
	}

	var ans []int

	cache := make(map[int][2]int)

	for i := 0; i < n; i++ {
		ds := dp[i][0]
		ks := dp[i][1]

		g := gcd(ds, ks)

		if  g == 1 {
			ans = append(ans, 1)
			continue
		}

		for gg := g; gg >= 1; gg-- {

			if g % gg == 0 {
				d := ds/gg
				k := ks/gg

				l := d + k

				done := true

				var cnt int

				var prev int
				var j int

				if v, ok := cache[l]; ok {
					prev = v[0]
					cnt += v[1]
					j = prev + l
				} else {
					prev = -1
					j = l - 1
				}

				for ; j <= i; j += l {

					yes := false

					var vd int
					var vk int

					if prev != -1 {
						vd = dp[j][0] - dp[prev][0]
						vk = dp[j][1] - dp[prev][1]
					} else {
						vd = dp[j][0]
						vk = dp[j][1]
					}

					if d * vk == k * vd {
						cnt++
						prev = j
						yes = true
					}

					if j >= i && !yes {
						done = false
					}
				}

				if done {
					var arr [2]int
					arr[0] = i
					arr[1] = cnt
					cache[l] = arr
					ans = append(ans, cnt)
					break
				}
			}
		}
	}

	return ans
}

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


The enchanted forest got its name from the magical mushrooms growing here. They may cause illusions and generally should not be approached.—Perfect Memento in Strict SenseMarisa comes to pick mushrooms in the Enchanted Forest. The Enchanted forest can be represented by $$$n$$$ points on the $$$X$$$-axis numbered $$$1$$$ through $$$n$$$. Before Marisa started, her friend, Patchouli, used magic to detect the initial number of mushroom on each point, represented by $$$a_1,a_2,\ldots,a_n$$$.Marisa can start out at any point in the forest on minute $$$0$$$. Each minute, the followings happen in order:  She moves from point $$$x$$$ to $$$y$$$ ($$$|x-y|\le 1$$$, possibly $$$y=x$$$).  She collects all mushrooms on point $$$y$$$.  A new mushroom appears on each point in the forest. Note that she cannot collect mushrooms on minute $$$0$$$.Now, Marisa wants to know the maximum number of mushrooms she can pick after $$$k$$$ minutes.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$, $$$k$$$ ($$$1 \le n \le 2 \cdot 10 ^ 5$$$, $$$1\le k \le 10^9$$$) — the number of positions with mushrooms and the time Marisa has, respectively. The second line of each test case contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the initial number of mushrooms on point $$$1,2,\ldots,n$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10 ^ 5$$$.

For each test case, print the maximum number of mushrooms Marisa can pick after $$$k$$$ minutes.

NoteTest case 1:Marisa can start at $$$x=2$$$. In the first minute, she moves to $$$x=1$$$ and collect $$$5$$$ mushrooms. The number of mushrooms will be $$$[1,7,2,3,4]$$$. In the second minute, she moves to $$$x=2$$$ and collects $$$7$$$ mushrooms. The numbers of mushrooms will be $$$[2,1,3,4,5]$$$. After $$$2$$$ minutes, Marisa collects $$$12$$$ mushrooms.It can be shown that it is impossible to collect more than $$$12$$$ mushrooms.Test case 2:This is one of her possible moving path:$$$2 \rightarrow 3 \rightarrow 2 \rightarrow 1 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 5$$$It can be shown that it is impossible to collect more than $$$37$$$ mushrooms.

package main

import (
	"bufio"
	"fmt"

	"os"
)

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

    var T int64
    fmt.Fscan(in,&T)
    for t:=int64(1);t <= T; t++ {
        var n,k,i int64

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

        a := make([]int64, n)
        pre := make([]int64, n+1)
        for i= 0; i <n; i++{
            fmt.Fscan(in,&a[i])
        }
        pre[0] = 0
        for i = 0; i < n; i++ {
            pre[i+1] = pre[i] + a[i]
        }
        if k >= n {
            ans := pre[n]
            ans += (n*(n-1)/2)
            ans += (k-n)*n
            fmt.Fprintln(out,ans)
        } else{
            var ans int64 = 0
            for i=k; i < n + 1; i ++ {
                if ans < pre[i] - pre[i-k] {
                    ans = pre[i]-pre[i-k]
                }
            }
            ans += (k*(k-1)/2)
            fmt.Fprintln(out,ans)
        }

    }
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi64() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	T := gi()
	for tt:=1;tt<=T;tt++ {
		N,K := gi64(),gi64(); A := make([]int64,N); for i:=int64(0);i<N;i++ { A[i] = gi64() }
		ans := int64(0)
		cum := int64(0)
		for i:=int64(0);i<N;i++ {
			cum += A[i]; if i-K>=0 { cum -= A[i-K] }; if cum > ans { ans = cum }
		}
		if N >= K {
			ans += K * (K-1 + 0) / 2
		} else {
			ans += N * (K-1 + K-N) / 2
		}
		fmt.Fprintln(wrtr,ans)
	}
}

package main

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

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

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

	var T int
	var n int
	var k int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			a[i] = x
		}

		ans := int64(0)
		if k < n {
			s := int64(0)
			for i := 0;i < k; i++ {
				s += int64(a[i])
			}
			ans = s
			for i := k; i< n;i++ {
				s += int64(a[i] - a[i-k])
				if s > ans {
					ans = s
				}
			}
			ans += (int64(k) * int64(k-1))/2
		} else {
			for _, v := range a {
				ans += int64(v)
			}
			ans += int64(n) * (int64(k-1) + int64(k-n)) / 2
		}

		Fprintln(out, ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = (x << 1) + (x << 3) + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = (x << 1) + (x << 3) + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func getSum(s, e int) int64 {
	return (int64(s) + int64(e)) * (int64(e) - int64(s) + 1) / 2
}

func sol() int64 {
	n := ri()
	k := ri()
	a := ria(n)
	var ans int64
	sum := make([]int64, n+1)
	sum[0] = 0

	if n == 1 {
		// wait until
		return int64(a[0] + k - 1)
	}
	for i := 0; i < n; i++ {
		sum[i+1] = sum[i] + int64(a[i])
	}

	if k >= n {
		return getSum(k-n+1-1, k-1) + sum[n]
	}

	t := int64(0)
	for i := 0; i+k <= n; i++ {
		z := sum[i+k] - sum[i]
		if z > t {
			t = z
		}
	}
	ans = t + getSum(0, k-1)
	return ans
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		myio.Println(sol())
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

/* begin of MyIO */
const eof = 0

type any = interface{}

type MyIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func NewIO(in *os.File, out *os.File) *MyIO {
	return &MyIO{
		in,
		bufio.NewWriter(out),
		0, 0, make([]byte, 1<<12),
	}
}

func (myio *MyIO) rc() byte {
	if myio._i == myio._n {
		myio._n, _ = myio.in.Read(myio.buf)
		if myio._n == 0 { // EOF
			return eof
		}
		myio._i = 0
	}
	b := myio.buf[myio._i]
	myio._i++
	return b
}

func (myio *MyIO) ReadInt() (x int) {
	rc := myio.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (myio *MyIO) ReadInt64() (x int64) {
	rc := myio.rc
	b := rc()
	neg := false

	for ; '0' > b || b > '9'; b = rc() {
		if b == eof {
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	if neg {
		return -x
	}
	return x
}

func (myio *MyIO) ReadBytes() (s []byte) {
	rc := myio.rc
	b := rc()
	for ; b <= ' '; b = rc() {
	}
	for ; b > ' '; b = rc() {
		s = append(s, b)
	}
	return
}

func (myio *MyIO) ReadStr() (s string) {
	return string(myio.ReadBytes())
}

func (myio *MyIO) Flush() {
	myio.out.Flush()
}

func (myio *MyIO) Printf(format string, a ...any) (n int, err error) {
	return fmt.Fprintf(myio.out, format, a...)
}

func (myio *MyIO) Println(a ...any) (n int, err error) {
	return fmt.Fprintln(myio.out, a...)
}

func (myio *MyIO) Print(a ...any) (n int, err error) {
	return fmt.Fprint(myio.out, a...)
}

var myio *MyIO

func ri() int {
	return myio.ReadInt()
}

func ri64() int64 {
	return myio.ReadInt64()
}

func ria(_n int) []int {
	a := make([]int, _n)
	for i := range a {
		a[i] = ri()
	}
	return a
}

/* End of MyIO */

func getSum(s, e int) int64 {
	return (int64(s) + int64(e)) * (int64(e) - int64(s) + 1) / 2
}

func sol() int64 {
	n := ri()
	k := ri()
	a := ria(n)
	var ans int64
	sum := make([]int64, n+1)
	sum[0] = 0

	for i := 0; i < n; i++ {
		sum[i+1] = sum[i] + int64(a[i])
	}

	if n == 1 {
		// wait until
		return int64(a[0] + k - 1)
	}

	var tot int64 = 0
	for i := 0; i < n; i++ {
		tot += int64(a[i])
	}

	if k >= n {
		return getSum(k-n+1-1, k-1) + tot
	}

	t := int64(0)
	for i := 0; i+k <= n; i++ {
		z := sum[i+k] - sum[i]
		if z > t {
			t = z
		}
	}
	ans = t + getSum(0, k-1)
	return ans
}

func main() {
	debug.SetGCPercent(-1)
	in, out := os.Stdin, os.Stdout
	myio = NewIO(in, out)
	defer myio.Flush()

	var t = 1
	t = ri()
	for ; t > 0; t-- {
		myio.Println(sol())
	}
}

package main

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

type FastIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func (FastRead *FastIO) rc() byte {
	if FastRead._i == FastRead._n {
		FastRead._n, _ = FastRead.in.Read(FastRead.buf)
		if FastRead._n == 0 { // EOF
			return 0
		}
		FastRead._i = 0
	}
	b := FastRead.buf[FastRead._i]
	FastRead._i++
	return b
}

func (FastRead *FastIO) ReadInt() (x int) {
	rc := FastRead.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == 0 { //EOF
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (FastRead *FastIO) ReadInt64() (x int64) {
	rc := FastRead.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == 0 {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

var FastRead *FastIO

func slove() {
	n := FastRead.ReadInt()
	k := FastRead.ReadInt()
	nums := make([]int64, n)
	for i := 0; i < n; i++ {
		nums[i] = FastRead.ReadInt64()
	}
	if n == 1 {
		ans := int64(nums[0])
		ans += int64(k - 1)
		fmt.Println(ans)
	} else if k <= n {
		var cur, ans int64
		for i := 0; i < k; i++ {
			cur += nums[i]
		}
		ans = cur
		for i := k; i < n; i++ {
			cur += nums[i] - nums[i-k]
			if cur > ans {
				ans = cur
			}
		}
		ans += (int64(k) - 1) * (int64(k)) / 2
		fmt.Println(ans)
	} else {
		var ans int64
		for i := range nums {
			ans += nums[i]
		}
		start := (k - 1) % (n - 1)
		repeat := (k-1)/(n-1) - 1
		ans += int64(repeat) * (2 + 2*int64(n-1)) * int64(n-1) / 2
		ans += int64(start+start+n-1) * int64(n) / 2
		fmt.Println(ans)
	}
}

func main() {
	//debug.SetGCPercent(-1)
	FastRead = &FastIO{
		os.Stdin,
		bufio.NewWriter(os.Stdout),
		0, 0, make([]byte, 1<<12),
	}

	t := FastRead.ReadInt()
	for ; t > 0; t-- {
		slove()
	}
}

package main

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

type FastIO struct {
	in  *os.File
	out *bufio.Writer
	_i  int
	_n  int
	buf []byte
}

func (FastRead *FastIO) rc() byte {
	if FastRead._i == FastRead._n {
		FastRead._n, _ = FastRead.in.Read(FastRead.buf)
		if FastRead._n == 0 { // EOF
			return 0
		}
		FastRead._i = 0
	}
	b := FastRead.buf[FastRead._i]
	FastRead._i++
	return b
}

func (FastRead *FastIO) ReadInt() (x int) {
	rc := FastRead.rc
	b := rc()
	neg := false
	for ; '0' > b || b > '9'; b = rc() {
		if b == 0 { //EOF
			return
		}
		if b == '-' {
			neg = true
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int(b&15)
	}
	if neg {
		return -x
	}
	return
}

func (FastRead *FastIO) ReadInt64() (x int64) {
	rc := FastRead.rc
	b := rc()

	for ; '0' > b || b > '9'; b = rc() {
		if b == 0 {
			return
		}
	}
	for ; '0' <= b && b <= '9'; b = rc() {
		x = x*10 + int64(b&15)
	}
	return x
}

var FastRead *FastIO

func slove() {
	//var n, k int
	//fmt.Fscan(r, &n, &k)
	n := FastRead.ReadInt()
	k := FastRead.ReadInt()
	nums := make([]int64, n)
	for i := 0; i < n; i++ {
		//fmt.Fscan(r, &nums[i])
		nums[i] = FastRead.ReadInt64()
	}
	if n == 1 {
		ans := int64(nums[0])
		ans += int64(k - 1)
		fmt.Println(ans)
	} else if k <= n {
		var cur, ans int64
		for i := 0; i < k; i++ {
			cur += nums[i]
		}
		ans = cur
		for i := k; i < n; i++ {
			cur += nums[i] - nums[i-k]
			//ans = max(ans, cur)
			if cur > ans {
				ans = cur
			}
		}
		ans += (int64(k) - 1) * (int64(k)) / 2
		fmt.Println(ans)
	} else {
		var ans int64
		for i := range nums {
			ans += nums[i]
		}
		start := (k - 1) % (n - 1)
		repeat := (k-1)/(n-1) - 1
		ans += int64(repeat) * (2 + 2*int64(n-1)) * int64(n-1) / 2
		ans += int64(start+start+n-1) * int64(n) / 2
		fmt.Println(ans)
	}
}

func main() {
	//debug.SetGCPercent(-1)
	FastRead = &FastIO{
		os.Stdin,
		bufio.NewWriter(os.Stdout),
		0, 0, make([]byte, 1<<12),
	}

	var t = 1
	t = FastRead.ReadInt()
	for ; t > 0; t-- {
		slove()
	}
}

package main

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

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

func slove() {
	var n, k int
	fmt.Fscan(r, &n, &k)
	nums := make([]int64, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	if n == 1{
		ans := int64(nums[0])
		ans += int64(k - 1)
		fmt.Fprintln(w, ans)
	} else if k <= n {
		var cur, ans int64
		for i:=0;i<k;i++ {
			cur += nums[i]
		}
		ans = cur
		for i:=k;i<n;i++ {
			cur += nums[i] - nums[i-k]
			ans = max(ans, cur)
		}
		ans += (int64(k) - 1) * (int64(k)) / 2
		fmt.Fprintln(w, ans)
	} else {
		var ans int64
		for i := range nums {
			ans += nums[i]
		}
		start := (k - 1) % (n - 1)
		repeat := (k - 1) / (n - 1) - 1
		ans += int64(repeat) * (2 + 2*int64(n-1))*int64(n-1) / 2
		ans += int64(start+start+n-1)*int64(n)/2
		fmt.Fprintln(w, ans)
	}
}

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

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

package main

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

func A3() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, k, total, sum int64

		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := int64(0); i < n; i++ {
			Fscan(in, &a[i])

			sum += int64(a[i])
		}

		if k <= n {
			//sort.Ints(a)
			var sum2, s int64
			for i := 0; i < int(k); i++ {
				sum2 += int64(a[i])
			}
			s = sum2
			for i := int(k); i < int(n); i++ {
				sum2 += int64(a[i])
				sum2 -= int64(a[i-int(k)])
				if sum2 > s {
					s = sum2
				}
			}
			Fprintln(out, s+(k-1)*k/2)
			return
		}
		total = sum + n*(n-1)/2
		k -= n
		total += (n*(n+1)/2 + n*(n-1)/2) * (k / n)
		k %= n
		total += (2*n-(k-1))*k/2 + (k-1)*k/2
		Fprintln(out, total)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A3() }

package main

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

func main() {
	scanner := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var ntests int
	fmt.Fscan(scanner, &ntests)
outer:
	for iter := 0; iter < ntests; iter++ {
		var n, k int
		fmt.Fscan(scanner, &n, &k)
		slice := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(scanner, &slice[i])
		}
		if n == 1 {
			fmt.Fprintln(writer, slice[0]+int64(k)-1)
			continue outer
		}
		if k <= n {
			j := 0
			res := int64(0)
			max := int64(0)
			//startl, startr := 0, 0
			for i := 0; i < n; i++ {
				j++
				res += slice[i]
				// if k == j {
				// 	max = res
				// }
				if j > k {
					res -= slice[i-k]
				}
				if j == k {
					max = res
				}
				if max < res {
					max = res
					//startl = i - k
					//startr = i
				}
			}
			fmt.Fprintln(writer, max+((int64)(k)*(int64)(k-1)/2))
		} else {
			res := int64(0)
			for i := 0; i < n; i++ {
				res += slice[i]
			}
			//fmt.Println("!!! sum", res)
			// forward
			// elems := int64((k % n) + 1)
			// fres := elems * (elems + 1) / 2
			// res += fres
			// fmt.Println("!!! forward", res)
			// // square
			// squares := (int64(k) - elems) / (int64)(n-1)
			// multi := int64(n-1) * int64(n-1)
			// res += squares * multi
			// fmt.Println("!!! backward", res)
			// fmt.Fprintln(writer, res)
			res += int64(n)*int64(k) - int64(int64(int64(n)*int64(n+1))/2)
			fmt.Fprintln(writer, res)
		}
	}
}

package main

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

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

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

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

		arr := make([]int64, n+1)
		for i := int64(1); i <= n; i++ {
			fmt.Fscan(in, &arr[i])
			arr[i] += arr[i-1]
		}

		if k >= n {
			fmt.Fprintln(out, arr[n]+(k-1+k-n)*n/2)
		} else {
			z := arr[k]
			for i := k + 1; i <= n; i++ {
				z = max(z, arr[i]-arr[i-k])
			}
			fmt.Fprintln(out, z+k*(k-1)/2)
		}
	}
}

package main

import "fmt"

func Max(x, y int64) int64 {
    if x < y {
        return y
    }
    return x
}

func main() {
    var t int
    fmt.Scanf("%d",&t)
    for ;t > 0; t-- {
        var n,k,i int64
        fmt.Scanf("%d %d",&n,&k)
        // var a [n] int64
        a := make([]int64, n)
        // var pre[n+1]int64
        pre := make([]int64, n+1)
        for i= 0; i <n; i++{
            fmt.Scanf("%d",&a[i])
        }
        pre[0] = 0
        for i = 0; i < n; i++ {
            pre[i+1] = pre[i] + a[i]
        }
        if k >= n {
            ans := pre[n]
            ans += (n*(n-1)/2)
            ans += (k-n)*n
            fmt.Println(ans)
        } else{
            var ans int64 = 0
            for i=k; i < n + 1; i ++ {
                ans = Max(ans,pre[i]-pre[i-k])
            }
            ans += (k*(k-1)/2)
            fmt.Println(ans)
        }

    }
}

package main
import (
	"bufio"
	"os"
	"strconv"
    "strings"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi2() (int,int) { return gi(),gi() }
func gi3() (int,int,int) { return gi(),gi(),gi() }
func gi4() (int,int,int,int) { return gi(),gi(),gi(),gi() }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func gf() float64 { f,e := strconv.ParseFloat(gs(),64); if e != nil {panic(e)}; return f }
func gbs() []byte { return []byte(gs()) }
func gfs(n int) []float64  { res := make([]float64,n); for i:=0;i<n;i++ { res[i] = gf() }; return res }
func gss(n int) []string  { res := make([]string,n); for i:=0;i<n;i++ { res[i] = gs() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func twodi(n int,m int,v int) [][]int {
	r := make([][]int,n); for i:=0;i<n;i++ { x := make([]int,m); for j:=0;j<m;j++ { x[j] = v }; r[i] = x }; return r
}
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func fill3(m int) ([]int,[]int,[]int) { a,b,c := ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i] = gi(),gi(),gi()}; return a,b,c }
func fill4(m int) ([]int,[]int,[]int,[]int) { a,b,c,d := ia(m),ia(m),ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i],c[i],d[i] = gi(),gi(),gi(),gi()}; return a,b,c,d }
func abs(a int) int { if a < 0 { return -a }; return a }
func rev(a []int) { i,j := 0,len(a)-1; for i < j { a[i],a[j] = a[j],a[i]; i++; j-- } }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func tern(cond bool, a int, b int) int { if cond { return a }; return b }
func terns(cond bool, a string, b string) string { if cond { return a }; return b }
func maxarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa > ans { ans = aa } }; return ans }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
func sumarr(a []int) int { ans := 0; for _,aa := range(a) { ans += aa }; return ans }
func zeroarr(a []int) { for i:=0; i<len(a); i++ { a[i] = 0 } }
func powmod(a,e,mod int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m % mod }; m = m * m % mod; e >>= 1 }; return res }
func powint(a,e int) int { res, m := 1, a; for e > 0 { if e&1 != 0 { res = res * m }; m = m * m; e >>= 1 }; return res }
func gcd(a,b int) int { for b != 0 { t:=b; b=a%b; a=t }; return a }
func gcdExtended(a,b int) (int,int,int) { if a == 0 { return b,0,1 }; gcd,x1,y1 := gcdExtended(b%a,a); return gcd, y1-(b/a)*x1,x1 }
func modinv(a,m int) (int,bool) { g,x,_ := gcdExtended(a,m); if g != 1 { return 0,false }; return (x % m + m) % m,true  }
func makefact(n int,mod int) ([]int,[]int) {
	fact,factinv := make([]int,n+1),make([]int,n+1)
	fact[0] = 1; for i:=1;i<=n;i++ { fact[i] = fact[i-1] * i % mod }
	factinv[n] = powmod(fact[n],mod-2,mod); for i:=n-1;i>=0;i-- { factinv[i] = factinv[i+1] * (i+1) % mod }
	return fact,factinv
}
func vecintstring(a []int) string { astr := make([]string,len(a)); for i,a := range a { astr[i] = strconv.Itoa(a) }; return strings.Join(astr," ") }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
}

package main

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

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

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

	var T int
	var n int
	var k int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		Fscan(in, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			a[i] = x
		}

		ans := int64(0)
		if k < n {
			s := int64(0)
			for i := 0;i < k; i++ {
				s += int64(a[i])
			}
			ans = s
			for i := k; i< n;i++ {
				s += int64(a[i] - a[i-k])
				if s > ans {
					ans = s
				}
			}
			ans += int64(k * (k-1))/2
		} else {
			for _, v := range a {
				ans += int64(v)
			}
			ans += int64(n) * (int64(k-1) + int64(k-n)) / 2
		}

		Fprintln(out, ans)
	}
}

package main

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

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

func slove() {
	var n, k int
	fmt.Fscan(r, &n, &k)
	nums := make([]int64, n)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
	}
	if n == 1{
		ans := int64(nums[0])
		ans += int64(0 + k - 1) * int64(k) / 2
		fmt.Fprintln(w, ans)
	} else if k <= n {
		var cur, ans int64
		for i:=0;i<k;i++ {
			cur += nums[i]
		}
		ans = cur
		for i:=k;i<n;i++ {
			cur += nums[i] - nums[i-k]
			ans = max(ans, cur)
		}
		ans += (int64(k) - 1) * (int64(k)) / 2
		fmt.Fprintln(w, ans)
	} else {
		var ans int64
		for i := range nums {
			ans += nums[i]
		}
		start := (k - 1) % (n - 1)
		repeat := (k - 1) / (n - 1) - 1
		ans += int64(repeat) * (2 + 2*int64(n-1))*int64(n-1) / 2
		ans += int64(start+start+n-1)*int64(n)/2
		fmt.Fprintln(w, ans)
	}
}

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

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

package main

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

func A3() {
	_in, _out := os.Stdin, os.Stdout
	in, out := bufio.NewReader(_in), bufio.NewWriter(_out)
	defer out.Flush()
	var cas int = 1
	Fscan(in, &cas)
	var sol func()
	// Coding...beg!
	sol = func() {
		var n, k, total, sum int64

		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := int64(0); i < n; i++ {
			Fscan(in, &a[i])

			sum += int64(a[i])
		}

		if k <= n {
			sort.Ints(a)
			var sum2 int64
			for i := n - 1; i >= n-k; i-- {
				sum2 += int64(a[i])
			}
			Fprintln(out, sum2+(k-1)*k/2)
			return
		}
		total = sum + n*(n-1)/2
		k -= n
		total += (n*(n+1)/2 + n*(n-1)/2) * (k / n)
		k %= n
		total += (2*n-(k-1))*k/2 + (k-1)*k/2
		Fprintln(out, total)
	}
	// Coding...ove!
	for i := 0; i < cas; i++ {
		sol()
	}
}

func main() { A3() }


You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$ and an integer $$$k$$$, such that $$$1 \leq k \leq n$$$. A permutation means that every number from $$$1$$$ to $$$n$$$ is contained in $$$p$$$ exactly once.Let's consider all partitions of this permutation into $$$k$$$ disjoint segments. Formally, a partition is a set of segments $$$\{[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]\}$$$, such that:  $$$1 \leq l_i \leq r_i \leq n$$$ for all $$$1 \leq i \leq k$$$;  For all $$$1 \leq j \leq n$$$ there exists exactly one segment $$$[l_i, r_i]$$$, such that $$$l_i \leq j \leq r_i$$$. Two partitions are different if there exists a segment that lies in one partition but not the other.Let's calculate the partition value, defined as $$$\sum\limits_{i=1}^{k} {\max\limits_{l_i \leq j \leq r_i} {p_j}}$$$, for all possible partitions of the permutation into $$$k$$$ disjoint segments. Find the maximum possible partition value over all such partitions, and the number of partitions with this value. As the second value can be very large, you should find its remainder when divided by $$$998\,244\,353$$$.

The first line contains two integers, $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 200\,000$$$) — the size of the given permutation and the number of segments in a partition. The second line contains $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq n$$$) — the given permutation.

Print two integers — the maximum possible partition value over all partitions of the permutation into $$$k$$$ disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo $$$998\,244\,353$$$. Please note that you should only find the second value modulo $$$998\,244\,353$$$.

NoteIn the first test, for $$$k = 2$$$, there exists only two valid partitions: $$$\{[1, 1], [2, 3]\}$$$ and $$$\{[1, 2], [3, 3]\}$$$. For each partition, the partition value is equal to $$$2 + 3 = 5$$$. So, the maximum possible value is $$$5$$$ and the number of partitions is $$$2$$$.In the third test, for $$$k = 3$$$, the partitions with the maximum possible partition value are $$$\{[1, 2], [3, 5], [6, 7]\}$$$, $$$\{[1, 3], [4, 5], [6, 7]\}$$$, $$$\{[1, 4], [5, 5], [6, 7]\}$$$, $$$\{[1, 2], [3, 6], [7, 7]\}$$$, $$$\{[1, 3], [4, 6], [7, 7]\}$$$, $$$\{[1, 4], [5, 6], [7, 7]\}$$$. For all of them, the partition value is equal to $$$7 + 5 + 6 = 18$$$. The partition $$$\{[1, 2], [3, 4], [5, 7]\}$$$, however, has the partition value $$$7 + 3 + 6 = 16$$$. This is not the maximum possible value, so we don't count it.

package main

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

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

	in := func() int {
		sc.Scan()
		i, _ := strconv.Atoi(sc.Text())
		return i
	}

	n := in()
	k := in()

	p := -1

	a := make([]int, n)

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

	var res int64 = 1
	var sum int64 = 0

	for i := range a {
		if a[i] > n-k {
			sum += int64(a[i])
			if p != -1 {
				res *= int64(i - p)
				res %= 998244353
			}
			p = i
		}
	}

	fmt.Println(sum, res)

}

package main

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

const (
	maxn = int(1e5 + 50)
	mod  = int(998244353)
	eps  = 1e-8
	inf  = int(0x3f3f3f3f)
)

var n, k int
var p []int

func main() {
	scanInts(&n, &k)
	p = scanIntSlice(n)
	flag := -1
	lim := n - k
	res := int64(0)
	res2 := int64(1)
	for i := range p {
		if lim < p[i] {
			res += int64(p[i])
			if flag != -1 {
				MUL(&res2, int64(i - flag))
			}
			flag = i
		}
	}
	printlnInt64s(res, res2)
	close(channelType)
	oWg.Wait()
	out.Flush()
}

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

var channelType chan string
var in *bufio.Scanner
var out = bufio.NewWriter(os.Stdout)
var oWg *sync.WaitGroup

// string and slice are the return value
func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)
	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			writer.WriteString(line + "\n")
		}
	}()
}
func scanString() string { in.Scan(); return in.Text() }
func scanInt(a *int)     { *a, _ = strconv.Atoi(scanString()) }
func scanInts(a ...*int) {
	for i := range a {
		*a[i], _ = strconv.Atoi(scanString())
	}
}
func scanInt64(a *int64) { *a, _ = strconv.ParseInt(scanString(), 10, 64) }
func scanInt64s(a ...*int64) {
	for i := range a {
		*a[i], _ = strconv.ParseInt(scanString(), 10, 64)
	}
}
func scanStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = scanString()
	}
	return s
}
func scanIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		scanInt(&arr[i])
	}
	return arr
}
func scanInt64Slice(n int) []int64 {
	arr := make([]int64, n)
	for i := 0; i < n; i++ {
		scanInt64(&arr[i])
	}
	return arr
}
func printlnInts(args ...int) {
	for _, x := range args {
		fmt.Fprint(out, x, " ")
	}
	fmt.Fprintln(out)
}
func printlnInt64s(args ...int64) {
	for _, x := range args {
		fmt.Fprint(out, x, " ")
	}
	fmt.Fprintln(out)
}
func printIntSlice(a []int, flag bool) {
	for _, x := range a {
		fmt.Fprint(out, x, " ")
	}
	if flag { fmt.Fprintln(out) }
}
func printInt64Slice(a []int64, flag bool) {
	for _, x := range a {
		fmt.Fprint(out, x, " ")
	}
	if flag { fmt.Fprintln(out) }
}
func printRuneSlice(a []rune, flag bool) {
	for _, x := range a {
		fmt.Fprintf(out, "%c", x)
	}
	if flag { fmt.Fprintln(out) }
}
func putchar(a ...rune) {
	for _, x := range a {
		fmt.Fprintf(out, "%c", x)
	}
}
func printString(s string) { fmt.Fprintln(out, s) }

/*********************** Utils ***********************/

func stringEquivalent(v interface{}) string { return fmt.Sprintf("%v", v) }
func spaceSeperatedStringFromArray(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func spaceSeperatedStringFromArray64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func minMaxFromArray(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64         { return a / gcdCalculation(a, b) * b }
func gcdCalculation(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return gcdCalculation(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func absoluteValue(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}
func min(args ...int) int { mn, _ := minMaxFinder(args...); return mn }
func max(args ...int) int { _, mx := minMaxFinder(args...); return mx }
func minMaxFinder(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func same(x, y double) bool { return math.Abs(float64(x-y)) < eps }
func popcount(x int) (res int) {
	for i := 0; i < 32; i++ {
		if 1 == (1 & (x >> uint(i))) {
			res++
		}
	}
	return
}
func qp(a, n int64) (res int64) {
	for ; n > 0; n >>= 1 {
		if (n & 1) == 1 {
			res = res * a % int64(mod)
		}
		a = a * a % int64(mod)
	}
	return
}
func divUp(a, b int64) int64 {
	if a % b == 0 { return a / b } else { return a / b + 1 }
}
// [l, r)
func reverse(a *[]rune, l, r int) {
	for i, j := l, r - 1; i < j; i, j = i + 1, j - 1 {
		(*a)[i], (*a)[j] = (*a)[j], (*a)[i]
	}
}
func ADD(a *int64, b int64) { *a = (*a + b) % int64(mod) }
func MUL(a *int64, b int64) { *a = (*a * b) % int64(mod) }

/*********************** Structs ***********************/
type pair struct{ X, Y int }
type double float64
type pairSlice []pair

func (p pairSlice) Len() int { return len(p) }
func (p pairSlice) Less(i, j int) bool {
	if p[i].X != p[j].X {
		return p[i].X < p[j].X
	} else {
		return p[i].Y < p[j].Y
	}
}
func (p pairSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

/*
URL:
https://codeforces.com/problemset/problem/1326/C
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	n, k int64
	P    []int64
)

func main() {
	n, k = ReadInt64_2()
	P = ReadInt64Slice(int(n))

	// cf := NewCombFactorial(500000)
	// num := cf.C(n-1, k-1)

	ans := int64(0)
	for i := int64(0); i < k; i++ {
		ans += n - i
	}

	memo := []int64{}
	for i := int64(0); i < n; i++ {
		if P[i] > n-k {
			memo = append(memo, i)
		}
	}
	num := int64(1)
	for i := 1; i < len(memo); i++ {
		diff := int64(memo[i] - memo[i-1])
		num *= diff
		num %= MOD
	}

	fmt.Println(ans, num)
}

// cf := NewCombFactorial(500000) // maxNum == "maximum n" * 2 (for H(n,r))
// res := cf.C(n, r) 	// 組み合わせ
// res := cf.H(n, r) 	// 重複組合せ
// res := cf.P(n, r) 	// 順列

type CombFactorial struct {
	factorial, invFactorial []int64
	maxNum                  int64
}

func NewCombFactorial(maxNum int64) *CombFactorial {
	cf := new(CombFactorial)
	cf.maxNum = maxNum
	cf.factorial = make([]int64, maxNum+50)
	cf.invFactorial = make([]int64, maxNum+50)
	cf.initCF()

	return cf
}
func (c *CombFactorial) modInv(a int64) int64 {
	return c.modpow(a, MOD-2)
}
func (c *CombFactorial) modpow(a, e int64) int64 {
	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := c.modpow(a, halfE)
		return half * half % MOD
	}

	return a * c.modpow(a, e-1) % MOD
}
func (c *CombFactorial) initCF() {
	var i int64

	for i = 0; i <= c.maxNum; i++ {
		if i == 0 {
			c.factorial[i] = 1
			c.invFactorial[i] = c.modInv(c.factorial[i])
			continue
		}

		num := i * c.factorial[i-1]
		num %= MOD
		c.factorial[i] = num
		c.invFactorial[i] = c.modInv(c.factorial[i])
	}
}
func (c *CombFactorial) C(n, r int64) int64 {
	var res int64

	res = 1
	res *= c.factorial[n]
	res %= MOD
	res *= c.invFactorial[r]
	res %= MOD
	res *= c.invFactorial[n-r]
	res %= MOD

	return res
}
func (c *CombFactorial) P(n, r int64) int64 {
	var res int64

	res = 1
	res *= c.factorial[n]
	res %= MOD
	res *= c.invFactorial[n-r]
	res %= MOD

	return res
}
func (c *CombFactorial) H(n, r int64) int64 {
	return c.C(n-1+r, r)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

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

	var n, k, v int
	Fscan(in, &n, &k)
	pos := make([]int, 0, k)
	for i := 0; i < n; i++ {
		if Fscan(in, &v); v > n-k {
			pos = append(pos, i)
		}
	}
	ans := int64(1)
	for i := 1; i < k; i++ {
		ans = ans * int64(pos[i]-pos[i-1]) % 998244353
	}
	Fprintln(out, int64(2*n-k+1)*int64(k)/2, ans)
}

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

package main

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

const SZ int = 2e5 + 5
const MOD int64 = 998244353

type mypair struct {
	x, loc int
}

type mypairslice []mypair

func (m mypairslice) Len() int { return len(m)}
func (m mypairslice) Swap(i,j int) { m[i], m[j] = m[j], m[i] }

type SortByX struct{ mypairslice }
func (sbx SortByX) Less(i,j int) bool { return sbx.mypairslice[i].x > sbx.mypairslice[j].x }

type SortByLoc struct { mypairslice }
func (sbl SortByLoc) Less(i,j int) bool { return sbl.mypairslice[i].loc > sbl.mypairslice[j].loc }

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	var n, k int
	scanf("%d%d\n", &n, &k)
	var p mypairslice = make(mypairslice, n)
	for i:= 0; i < n; i++ {
		scanf("%d", &p[i].x)
		p[i].loc = i
		//fmt.Printf("p[%d]=%d %d\n", i, p[i].x, p[i].loc)
	}
	sort.Sort(SortByX{p})
	// for i:=0; i < n; i++ {
	// 	fmt.Printf("p[%d]=%d %d\n", i, p[i].x, p[i].loc)
	// }
	var pk mypairslice = p[:k]
	sort.Sort(sort.Reverse(SortByLoc{pk}))
	// for i:=0; i < k; i++ {
	// 	fmt.Printf("pk[%d]=%d %d\n", i, pk[i].x, pk[i].loc)
	// }
	var sum, count int64 = 0, 1
	sum += int64(pk[0].x)
	for i:= 1; i < k; i++ {
		sum += int64(pk[i].x)
		count *= int64(pk[i].loc - pk[i-1].loc)
		count %= MOD
	}
	fmt.Printf("%d %d\n", sum, count)
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextIntArray()

	a := make([]int, N)
	copy(a, p)
	sort.Ints(a)

	best := a[len(a)-K]
	first := int64(0)

	pre := -1
	ans := int64(1)
	for i := 0; i < N; i++ {
		if p[i] >= best {
			first += int64(p[i])
			if pre >= 0 {
				ans *= int64(i - pre)
			}
			ans %= 998244353
			pre = i
		}
	}
	fmt.Println(first, ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Scanner
}

func NewReader() Reader {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &readerImpl{Scanner: s}
}

func (i *readerImpl) NextInt() int {
	i.Scan()
	ret, _ := strconv.Atoi(i.Text())
	return ret
}

func (i *readerImpl) NextInt64() int64 {
	i.Scan()
	ret, _ := strconv.ParseInt(i.Text(), 10, 64)
	return ret
}

func (i *readerImpl) NextString() string {
	i.Scan()
	return i.Text()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

const MOD = 998244353

func main() {
	defer writer.Flush()
	n := reader.NextInt64()
	k := reader.NextInt64()
	pos := []int64{}
	val := int64(0)
	for i := int64(0); i < n; i++ {
		p := reader.NextInt64()
		if p > n-k {
			pos = append(pos, i)
			val += p
		}
	}
	ret := int64(1)
	for i := 1; i < len(pos); i++ {
		ret = (ret * (pos[i] - pos[i-1])) % MOD
	}
	writer.Printf("%d %d", val, ret)
}

func sum(ii []int64) int64 {
	ret := int64(0)
	for _, i := range ii {
		ret += i
	}
	return ret
}

package main

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

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

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

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

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

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

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

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

	return i
}

func fillNNums(bs []byte, n int, res []int) {
	x := 0
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
}

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

	n, k := readTwoNums(reader)

	P := readNNums(reader, n)

	a, b := solve(n, k, P)
	fmt.Printf("%d %d\n", a, b)
}

const MOD = 998244353

func solve(n, k int, P []int) (int64, int64) {
	var K int64

	for i := 0; i < k; i++ {
		K += int64(n - i)
	}

	var res int64 = 1

	var left int
	for P[left] <= n-k {
		left++
	}
	// j is the first one

	for i := left + 1; i < n; i++ {
		if P[i] <= n-k {
			continue
		}
		// P[i] > n - k
		cnt := int64(i - left)

		res *= cnt
		res %= MOD

		left = i
	}

	return K, res
}

package main

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

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

type slot struct {
	from uint64
	num  uint64
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	mod := int64(998244353)
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	sum := int64(0)
	for i := 0; i < m; i++ {
		sum += int64(n - i)
	}
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fscanf(in, "\n")
	lastPos := -1
	ans := int64(0)
	for i := 0; i < n; i++ {
		if a[i]+(m-1) >= n {
			if lastPos == -1 {
				ans = 1
				lastPos = i
			} else {
				ans *= int64(i - lastPos)
				ans %= mod
				lastPos = i
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", sum, ans)
	return
}

func test(a []int, b [][]int) []int {
	fmt.Println("debug")
	fmt.Println(a)
	for i := 0; i < len(b); i++ {
		a[b[i][0]-1], a[b[i][1]-1] = a[b[i][1]-1], a[b[i][0]-1]
		fmt.Println(a, b[i])
	}
	fmt.Println("debug end")

	return a
}

// find num of elem >= k
func find(a []int, k int) int {
	if len(a) == 0 {
		return 0
	}
	n := len(a)
	if a[0] > k {
		return n
	}
	if a[n-1] < k {
		return 0
	}
	l := 0
	r := len(a) - 1
	for l < r {
		mid := (l + r) / 2
		if a[mid] < k {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return n - l
}

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

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

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

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

func ok(a, b int) bool {
	if min(abs(a-b), abs(a+b)) <= min(abs(a), abs(b)) && max(abs(a+b), abs(a-b)) >= max(abs(a), abs(b)) {
		return true
	}
	return false
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n, k := NextInt(), NextInt()
	lastPos := -1
	var res int64
	var positions int64
	positions = 1
	var MOD int64
	MOD = 998244353
	for i := 0; i < n; i++ {
		pi := NextInt()
		if pi > n-k {
			res += int64(pi)
			if lastPos != -1 {
				positions *= int64(i - lastPos)
				positions %= MOD
			}
			lastPos = i
		}
	}
	fmt.Fprintln(out, res, positions)
}

package main

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

const SZ int = 2e5 + 5
const MOD int = 998244353

type mypair struct {
	x, loc int
}

type mypairslice []mypair

func (m mypairslice) Len() int { return len(m)}
func (m mypairslice) Swap(i,j int) { m[i], m[j] = m[j], m[i] }

type SortByX struct{ mypairslice }
func (sbx SortByX) Less(i,j int) bool { return sbx.mypairslice[i].x > sbx.mypairslice[j].x }

type SortByLoc struct { mypairslice }
func (sbl SortByLoc) Less(i,j int) bool { return sbl.mypairslice[i].loc > sbl.mypairslice[j].loc }

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
	var n, k int
	scanf("%d%d\n", &n, &k)
	var p mypairslice = make(mypairslice, n)
	for i:= 0; i < n; i++ {
		scanf("%d", &p[i].x)
		p[i].loc = i
		//fmt.Printf("p[%d]=%d %d\n", i, p[i].x, p[i].loc)
	}
	sort.Sort(SortByX{p})
	// for i:=0; i < n; i++ {
	// 	fmt.Printf("p[%d]=%d %d\n", i, p[i].x, p[i].loc)
	// }
	var pk mypairslice = p[:k]
	sort.Sort(sort.Reverse(SortByLoc{pk}))
	// for i:=0; i < k; i++ {
	// 	fmt.Printf("pk[%d]=%d %d\n", i, pk[i].x, pk[i].loc)
	// }
	var sum, count int = 0, 1
	sum += pk[0].x
	for i:= 1; i < k; i++ {
		sum += pk[i].x
		count *= pk[i].loc - pk[i-1].loc
		count %= MOD
	}
	fmt.Printf("%d %d\n", sum, count)
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextIntArray()

	a := make([]int, N)
	copy(a, p)
	sort.Ints(a)

	best := a[len(a)-K]
	first := 0

	pre := -1
	ans := int64(1)
	for i := 0; i < N; i++ {
		if p[i] >= best {
			first += p[i]
			if pre >= 0 {
				ans *= int64(i - pre)
			}
			ans %= 998244353
			pre = i
		}
	}
	fmt.Println(first, ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

func main() {
	sc := NewScanner()
	N, K := sc.NextInt(), sc.NextInt()
	p := sc.NextIntArray()

	a := make([]int, N)
	copy(a, p)
	sort.Ints(a)

	best := a[len(a)-K]
	first := 0

	pre := -1
	ans := 1
	for i := 0; i < N; i++ {
		if p[i] >= best {
			first += p[i]
			if pre >= 0 {
				ans *= i - pre
			}
			ans %= 998244353
			pre = i
		}
	}
	fmt.Println(first, ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main

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

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

type slot struct {
	from uint64
	num  uint64
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n, m := 0, 0
	mod := int64(998244353)
	fmt.Fscanf(in, "%d %d\n", &n, &m)
	sum := 0
	for i := 0; i < m; i++ {
		sum += n - i
	}
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(in, "%d", &a[i])
	}
	fmt.Fscanf(in, "\n")
	lastPos := -1
	ans := int64(0)
	for i := 0; i < n; i++ {
		if a[i]+(m-1) >= n {
			if lastPos == -1 {
				ans = 1
				lastPos = i
			} else {
				ans *= int64(i - lastPos)
				ans %= mod
				lastPos = i
			}
		}
	}
	fmt.Fprintf(out, "%d %d\n", sum, ans)
	return
}

func test(a []int, b [][]int) []int {
	fmt.Println("debug")
	fmt.Println(a)
	for i := 0; i < len(b); i++ {
		a[b[i][0]-1], a[b[i][1]-1] = a[b[i][1]-1], a[b[i][0]-1]
		fmt.Println(a, b[i])
	}
	fmt.Println("debug end")

	return a
}

// find num of elem >= k
func find(a []int, k int) int {
	if len(a) == 0 {
		return 0
	}
	n := len(a)
	if a[0] > k {
		return n
	}
	if a[n-1] < k {
		return 0
	}
	l := 0
	r := len(a) - 1
	for l < r {
		mid := (l + r) / 2
		if a[mid] < k {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return n - l
}

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

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

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

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

func ok(a, b int) bool {
	if min(abs(a-b), abs(a+b)) <= min(abs(a), abs(b)) && max(abs(a+b), abs(a-b)) >= max(abs(a), abs(b)) {
		return true
	}
	return false
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

func main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	n, k := NextInt(), NextInt()
	lastPos := -1
	res := 0
	var positions int64
	positions = 1
	var MOD int64
	MOD = 998244353
	for i := 0; i < n; i++ {
		pi := NextInt()
		if pi > n-k {
			res += pi
			if lastPos != -1 {
				positions *= int64(i - lastPos)
				positions %= MOD
			}
			lastPos = i
		}
	}
	fmt.Fprintln(out, res, positions)
}