William is hosting a party for $$$n$$$ of his trader friends. They started a discussion on various currencies they trade, but there's an issue: not all of his trader friends like every currency. They like some currencies, but not others.For each William's friend $$$i$$$ it is known whether he likes currency $$$j$$$. There are $$$m$$$ currencies in total. It is also known that a trader may not like more than $$$p$$$ currencies.Because friends need to have some common topic for discussions they need to find the largest by cardinality (possibly empty) subset of currencies, such that there are at least $$$\lceil \frac{n}{2} \rceil$$$ friends (rounded up) who like each currency in this subset.

The first line contains three integers $$$n, m$$$ and $$$p$$$ $$$(1 \le n \le 2 \cdot 10^5, 1 \le p \le m \le 60, 1 \le p \le 15)$$$, which is the number of trader friends, the number of currencies, the maximum number of currencies each friend can like. Each of the next $$$n$$$ lines contain $$$m$$$ characters. The $$$j$$$-th character of $$$i$$$-th line is $$$1$$$ if friend $$$i$$$ likes the currency $$$j$$$ and $$$0$$$ otherwise. It is guaranteed that the number of ones in each line does not exceed $$$p$$$.

Print a string of length $$$m$$$, which defines the subset of currencies of the maximum size, which are liked by at least half of all friends. Currencies belonging to this subset must be signified by the character $$$1$$$. If there are multiple answers, print any.

NoteIn the first sample test case only the first currency is liked by at least $$$\lceil \frac{3}{2} \rceil = 2$$$ friends, therefore it's easy to demonstrate that a better answer cannot be found.In the second sample test case the answer includes $$$2$$$ currencies and will be liked by friends $$$1$$$, $$$2$$$, and $$$5$$$. For this test case there are other currencies that are liked by at least half of the friends, but using them we cannot achieve a larger subset size.

package main
import("bufio";."fmt";."math/bits";"math/rand";."os";."time")

// github.com/EndlessCheng/codeforces-go
func main(){
	t:=Now();rand.Seed(t.UnixNano())
	in:=bufio.NewReader(Stdin)
	var n,m,p,mx int
	var ans uint64
	Fscanln(in,&n,&m,&p)
	a:=make([]uint64,n)
	for i:=range a{Fscanf(in,"%b\n",&a[i])}
	for Since(t)<Second{
		x:=a[rand.Intn(n)]
		if OnesCount64(x)<=mx{continue}
		cnt:=map[uint64]int{}
		for _,v:=range a{cnt[v&x]++}
		cnt2:=map[uint64]int{}
		for v,c:=range cnt{
			for s:=v;s>0;s=(s-1)&v{cnt2[s]+=c}
		}
		for v,c:=range cnt2{
			if o:=OnesCount64(v);c*2>=n&&o>mx{ans,mx=v,o}
		}
	}
	Printf("%0*b",m,ans)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	rand.Seed(t0.UnixNano())
	in := bufio.NewReader(_r)
	var n, m, p, mx1 int
	var ans uint64
	Fscanln(in, &n, &m, &p)
	low := (n + 1) / 2
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	for time.Since(t0) < 2500*time.Millisecond {
		mask := a[rand.Intn(n)]
		if bits.OnesCount64(mask) <= mx1 {
			continue
		}
		cnt := map[uint64]int{}
		for _, v := range a {
			cnt[v&mask]++
		}
		cnt2 := map[uint64]int{}
		for v, c := range cnt {
			for s := v; s > 0; s = (s - 1) & v {
				cnt2[s] += c
			}
		}
		for v, c := range cnt2 {
			if c >= low {
				if o := bits.OnesCount64(v); o > mx1 {
					ans, mx1 = v, o
				}
			}
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main
import("bufio";."fmt";."math/bits";"math/rand";."os";."time")

// github.com/EndlessCheng/codeforces-go
func main(){
	t:=Now();rand.Seed(t.UnixNano())
	in:=bufio.NewReader(Stdin)
	var n,m,p,mx int
	var ans uint64
	Fscanln(in,&n,&m,&p)
	c1:=make([]int,m)
	a:=make([]uint64,n)
	for i:=range a{
		Fscanf(in,"%b\n",&a[i])
		for j:=range c1{c1[j]+=int(a[i]>>j&1)}
	}
	for Since(t)<2500*Millisecond{
		x:=a[rand.Intn(n)]
		for i,c:=range c1{if c*2<n&&x>>i&1>0{x^=1<<i}}
		if OnesCount64(x)<=mx{continue}
		cnt:=map[uint64]int{}
		for _,v:=range a{cnt[v&x]++}
		cnt2:=map[uint64]int{}
		for v,c:=range cnt{
			for s:=v;s>0;s=(s-1)&v{cnt2[s]+=c}
		}
		for v,c:=range cnt2{
			if o:=OnesCount64(v);c*2>=n&&o>mx{ans,mx=v,o}
		}
	}
	Printf("%0*b",m,ans)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	rand.Seed(t0.UnixNano())
	in := bufio.NewReader(_r)
	var n, m, p, o int
	var ans uint64
	Fscanln(in, &n, &m, &p)
	low := (n + 1) / 2
	c1 := make([]int, m)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
		for j := range c1 {
			c1[j] += int(a[i] >> j & 1)
		}
	}
	for time.Since(t0) < 2500*time.Millisecond {
		mask := a[rand.Intn(n)]
		for i, c := range c1 {
			if c < low && mask>>i&1 > 0 {
				mask ^= 1 << i
			}
		}
		if bits.OnesCount64(mask) <= o {
			continue
		}
		cnt := map[uint64]int{}
		for _, v := range a {
			cnt[v&mask]++
		}
		cnt2 := map[uint64]int{}
		for v, c := range cnt {
			for s := v; s > 0; s = (s - 1) & v {
				cnt2[s] += c
			}
		}
		for v, c := range cnt2 {
			if c >= low {
				if om := bits.OnesCount64(v); om > o {
					ans, o = v, om
				}
			}
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	in := bufio.NewReader(_r)
	var n, m, p, o int
	var ans uint64
	Fscanln(in, &n, &m, &p)
	low := (n + 1) / 2
	c1 := make([]int, m)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
		for j := range c1 {
			c1[j] += int(a[i] >> j & 1)
		}
	}
	rand.Seed(t0.UnixNano())
	for time.Since(t0) < 2900*time.Millisecond {
		mask := a[rand.Intn(n)] & a[rand.Intn(n)]
		for i, c := range c1 {
			if c < low && mask>>i&1 > 0 {
				mask ^= 1 << i
			}
		}
		om := bits.OnesCount64(mask)
		if om <= o {
			continue
		}
		c := 0
		for _, v := range a {
			if v|mask == v {
				c++
			}
		}
		if c >= (n+1)/2 {
			ans, o = mask, om
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, z int
	var ans uint64
	Fscanln(in, &n, &m, &z)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	p := make([]int, m)
	for i := range p {
		p[i] = i
	}
	rand.Seed(time.Now().UnixNano())
	for t := 60; t > 0; t-- {
		rand.Shuffle(m, func(i, j int) { p[i], p[j] = p[j], p[i] })
		ok := uint64(0)
		for _, p := range p {
			m := ok | 1<<p
			c := 0
			for _, v := range a {
				if v|m == v {
					c++
				}
			}
			if c >= (n+1)/2 {
				ok = m
			}
		}
		if bits.OnesCount64(ok) > bits.OnesCount64(ans) {
			ans = ok
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, z int
	var ans uint64
	Fscanln(in, &n, &m, &z)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	p := make([]int, m)
	for i := range p {
		p[i] = i
	}
	for t := 70; t > 0; t-- {
		rand.Shuffle(m, func(i, j int) { p[i], p[j] = p[j], p[i] })
		ok := uint64(0)
		for _, p := range p {
			m := ok | 1<<p
			c := 0
			for _, v := range a {
				if v|m == v {
					c++
				}
			}
			if c >= (n+1)/2 {
				ok = m
			}
		}
		if bits.OnesCount64(ok) > bits.OnesCount64(ans) {
			ans = ok
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, m, z int
	var ans uint64
	Fscanln(in, &n, &m, &z)
	a := make([]uint64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	p := make([]int, m)
	for i := range p {
		p[i] = i
	}
	for t := 50; t > 0; t-- {
		rand.Shuffle(m, func(i, j int) { p[i], p[j] = p[j], p[i] })
		ok := uint64(0)
		for _, p := range p {
			m := ok | 1<<p
			c := 0
			for _, v := range a {
				if v|m == v {
					c++
				}
			}
			if c >= (n+1)/2 {
				ok = m
			}
		}
		if bits.OnesCount64(ok) > bits.OnesCount64(ans) {
			ans = ok
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	in := bufio.NewReader(_r)
	var n, m, p, o int
	var ans int64
	Fscanln(in, &n, &m, &p)
	a := make([]int64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	rand.Seed(time.Now().UnixNano())
	for time.Since(t0) < 2900*time.Millisecond {
		mask := rand.Int63n(1 << p)
		om := bits.OnesCount(uint(mask))
		if om <= o {
			continue
		}
		rand.Shuffle(m, func(i, j int) { mask = mask&^(1<<i|1<<j) | mask>>i&1<<j | mask>>j&1<<i })
		c := 0
		for _, v := range a {
			if v|mask == v {
				c++
			}
		}
		if c >= (n+1)/2 {
			ans, o = mask, om
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	in := bufio.NewReader(_r)
	var n, m, p int
	var ans int64
	Fscanln(in, &n, &m, &p)
	a := make([]int64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	rand.Seed(time.Now().UnixNano())
	for time.Since(t0) < 2900*time.Millisecond {
		mask := rand.Int63n(1 << m)
		o := bits.OnesCount(uint(mask))
		if o > p {
			continue
		}
		c := 0
		for _, v := range a {
			if v|mask == v {
				c++
			}
		}
		if c >= (n+1)/2 && o > bits.OnesCount(uint(ans)) {
			ans = mask
		}
	}
	Fprintf(out, "%0*b", m, ans)
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"math/bits"
	"math/rand"
	"os"
	"time"
)

// github.com/EndlessCheng/codeforces-go
func CF1523D(_r io.Reader, out io.Writer) {
	t0 := time.Now()
	in := bufio.NewReader(_r)
	var n, m, p int
	var ans int64
	Fscanln(in, &n, &m, &p)
	a := make([]int64, n)
	for i := range a {
		Fscanf(in, "%b\n", &a[i])
	}
	rand.Seed(time.Now().UnixNano())
	for time.Since(t0) < 2900*time.Millisecond {
		mask := rand.Int63n(1 << m)
		o := bits.OnesCount(uint(mask))
		if o > p {
			continue
		}
		c := 0
		for _, v := range a {
			if v|mask == v {
				c++
			}
		}
		if c >= (n+1)/2 && o > bits.OnesCount(uint(ans)) {
			ans = mask
		}
	}
	Fprintf(out, "%*b", m, ans)
}

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


Today on a lecture about strings Gerald learned a new definition of string equivalency. Two strings a and b of equal length are called equivalent in one of the two cases:   They are equal.  If we split string a into two halves of the same size a1 and a2, and string b into two halves of the same size b1 and b2, then one of the following is correct:   a1 is equivalent to b1, and a2 is equivalent to b2  a1 is equivalent to b2, and a2 is equivalent to b1  As a home task, the teacher gave two strings to his students and asked to determine if they are equivalent.Gerald has already completed this home task. Now it's your turn!

The first two lines of the input contain two strings given by the teacher. Each of them has the length from 1 to 200 000 and consists of lowercase English letters. The strings have the same length.

Print "YES" (without the quotes), if these two strings are equivalent, and "NO" (without the quotes) otherwise.

NoteIn the first sample you should split the first string into strings "aa" and "ba", the second one — into strings "ab" and "aa". "aa" is equivalent to "aa"; "ab" is equivalent to "ba" as "ab" = "a" + "b", "ba" = "b" + "a".In the second sample the first string can be splitted into strings "aa" and "bb", that are equivalent only to themselves. That's why string "aabb" is equivalent only to itself and to string "bbaa".

package main

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

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

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

	var s, t string

	scan(&s, &t)

	if equal(s, t) {
		println("YES")
	} else {
		println("NO")
	}
}

func equal(s, t string) bool {
	if s == t {
		return true
	}

	// if (len(s) & 1) > 0 {
	// 	return false
	// }

	// h := len(s) >> 1

	if len(s)%2 != 0 {
		return false
	}

	h := len(s) / 2
	return (equal(s[:h], t[h:]) && equal(s[h:], t[:h])) || (equal(s[:h], t[:h]) && equal(s[h:], t[h:]))
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

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

	var s, t string

	scan(&s, &t)

	if equal(s, t) {
		println("YES")
	} else {
		println("NO")
	}
}

func equal(s, t string) bool {
	if s == t {
		return true
	}

	if (len(s) & 1) > 0 {
		return false
	}

	h := len(s) >> 1

	return (equal(s[:h], t[h:]) && equal(s[h:], t[:h])) || (equal(s[:h], t[:h]) && equal(s[h:], t[h:]))
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

import (
	"fmt"
	"os"
)

func smallest(sa string) string {
	if len(sa)%2 == 1 {
		return sa
	}
	var l = len(sa)
	var sfirst = smallest(sa[0 : l/2])
	var ssecond = smallest(sa[l/2 : l])
	if sfirst < ssecond {
		return sfirst + ssecond
	} else {
		return ssecond + sfirst
	}
}

func main() {
	// f, _ := os.Open("input.txt")
	f := os.Stdin
	var sa, sb string
	fmt.Fscanf(f, "%s\n%s", &sa, &sb)
	var equivalent = smallest(sa) == smallest(sb)
	if equivalent == true {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"fmt"
	"os"
)

func smallest(sa string) string {
	if len(sa)%2 == 1 {
		return sa
	}
	var l = len(sa)
	var sfirst = smallest(sa[0 : l/2])
	var ssecond = smallest(sa[l/2 : l])
	if sfirst+ssecond < ssecond+sfirst {
		return sfirst + ssecond
	} else {
		return ssecond + sfirst
	}
}

func main() {
	// f, _ := os.Open("input.txt")
	f := os.Stdin
	var sa, sb string
	fmt.Fscanf(f, "%s\n%s", &sa, &sb)
	var equivalent = smallest(sa) == smallest(sb)
	if equivalent == true {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func eqiv(a, b string) bool {
	n1 := len(a)
	n2 := len(b)
	if a == b {
		return true
	}
	if n1 != n2 {
		return false
	}
	if n1 == 1 {
		return false
	}
	if n1%2 == 1 {
		return false
	}
	n := n1 / 2
	a1 := a[:n]
	a2 := a[n:]
	b1 := b[:n]
	b2 := b[n:]
	return ((eqiv(a1, b2) && eqiv(a2, b1)) || (eqiv(a1, b1) && eqiv(a2, b2)))
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	a, _ := reader.ReadString('\n')
	b, _ := reader.ReadString('\n')
	a = strings.TrimSpace(a)
	b = strings.TrimSpace(b)
	if eqiv(a, b) == true {
		fmt.Printf("YES")
	} else {
		fmt.Printf("NO")
	}
}

package main

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

func sort(s string) string {
  if len(s)%2 != 0 {
    return s
  }

  mid := len(s)/2
  left, right := sort(s[:mid]), sort(s[mid:])
  if right < left {
    return right + left
  }
  return left + right
}

func main() {
    stdin := bufio.NewReader(os.Stdin)
    var a, b string
    fmt.Fscan(stdin, &a, &b)
    if sort(a) == sort(b) {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
}

package main

import "fmt"

func foo(s string) string {
	if len(s)%2 == 1 {
		return s
	}

	s1 := s[:len(s)/2]
	s2 := s[len(s)/2:]

	s1 = foo(s1)
	s2 = foo(s2)

	if s1 < s2 {
		return s1 + s2
	} else {
		return s2 + s1
	}
}

func main() {
	var A, B string

	fmt.Scanf("%s\n%s", &A, &B)

	if foo(A) == foo(B) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

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

func do(s string) string {
	if len(s)&1 == 1 {
		return s
	}
	s1 := do(s[:len(s)>>1])
	s2 := do(s[len(s)>>1:])
	if s1 < s2 {
		return s1 + s2
	}
	return s2 + s1
}

// github.com/EndlessCheng/codeforces-go
func Sol559B(reader io.Reader, writer io.Writer) {
	ifElse := func(cond bool, r1, r2 string) string {
		if cond {
			return r1
		}
		return r2
	}

	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()

	var s, t string
	Fscan(in, &s, &t)
	Fprint(out, ifElse(do(s) == do(t), "YES", "NO"))
}

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

package main

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

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

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

	var s, t string

	scan(&s, &t)

	if equal(s, t) {
		println("YES")
	} else {
		println("NO")
	}
}

func equal(s, t string) bool {
	if s == t {
		return true
	}

	if (len(s) >> 1) > 0 {
		return false
	}

	h := len(s) >> 1

	return (equal(s[:h], t[:h]) && equal(s[h:], t[h:])) || (equal(s[:h], t[h:]) && equal(s[h:], t[:h]))
}

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

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

func sort(s string) string {
  if len(s)%2 != 0 {
    return s
  }

  mid := len(s)/2
  left, right := sort(s[:mid]), sort(s[mid:])
  if right < left {
    return right + left
  }
  return left + right
}

func main() {
    stdin := bufio.NewReader(os.Stdin)
    var a, b string
    fmt.Fscan(stdin, &a, &b)
    fmt.Println(sort(a))

    if sort(a) == sort(b) {
      fmt.Println("YES")
    } else {
      fmt.Println("NO")
    }
}


Andrew and Jerry are playing a game with Harry as the scorekeeper. The game consists of three rounds. In each round, Andrew and Jerry draw randomly without replacement from a jar containing n balls, each labeled with a distinct positive integer. Without looking, they hand their balls to Harry, who awards the point to the player with the larger number and returns the balls to the jar. The winner of the game is the one who wins at least two of the three rounds.Andrew wins rounds 1 and 2 while Jerry wins round 3, so Andrew wins the game. However, Jerry is unhappy with this system, claiming that he will often lose the match despite having the higher overall total. What is the probability that the sum of the three balls Jerry drew is strictly higher than the sum of the three balls Andrew drew?

The first line of input contains a single integer n (2 ≤ n ≤ 2000) — the number of balls in the jar. The second line contains n integers ai (1 ≤ ai ≤ 5000) — the number written on the ith ball. It is guaranteed that no two balls have the same number.

Print a single real value — the probability that Jerry has a higher total, given that Andrew wins the first two rounds and Jerry wins the third. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.  Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteIn the first case, there are only two balls. In the first two rounds, Andrew must have drawn the 2 and Jerry must have drawn the 1, and vice versa in the final round. Thus, Andrew's sum is 5 and Jerry's sum is 4, so Jerry never has a higher total.In the second case, each game could've had three outcomes — 10 - 2, 10 - 1, or 2 - 1. Jerry has a higher total if and only if Andrew won 2 - 1 in both of the first two rounds, and Jerry drew the 10 in the last round. This has probability .

package main

import (
	"fmt"
)

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

func main() {
	var n int64
	fmt.Scan(&n)
	a := make([]int64, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	diff := make([]int64, 5000)
	for i := range a {
		for j := i + 1; j < int(n); j++ {
			diff[abs(a[i]-a[j])]++
		}
	}
	diff2 := make([]int64, 10000)
	for i := range diff {
		for j := range diff {
			diff2[i+j] += diff[i] * diff[j]
		}
	}
	var indeed, less int64
	for i := range diff {
		indeed += diff[i] * less
		less += diff2[i]
	}
	tot := n * (n - 1) / 2
	fmt.Printf("%.10f\n", float64(indeed)/float64(tot*tot*tot))
}


It is raining heavily. But this is the first day for Serval, who just became 3 years old, to go to the kindergarten. Unfortunately, he lives far from kindergarten, and his father is too busy to drive him there. The only choice for this poor little boy is to wait for a bus on this rainy day. Under such circumstances, the poor boy will use the first bus he sees no matter where it goes. If several buses come at the same time, he will choose one randomly.Serval will go to the bus station at time $$$t$$$, and there are $$$n$$$ bus routes which stop at this station. For the $$$i$$$-th bus route, the first bus arrives at time $$$s_i$$$ minutes, and each bus of this route comes $$$d_i$$$ minutes later than the previous one.As Serval's best friend, you wonder which bus route will he get on. If several buses arrive at the same time, you can print any of them.

The first line contains two space-separated integers $$$n$$$ and $$$t$$$ ($$$1\leq n\leq 100$$$, $$$1\leq t\leq 10^5$$$) — the number of bus routes and the time Serval goes to the station.  Each of the next $$$n$$$ lines contains two space-separated integers $$$s_i$$$ and $$$d_i$$$ ($$$1\leq s_i,d_i\leq 10^5$$$) — the time when the first bus of this route arrives and the interval between two buses of this route.

Print one number — what bus route Serval will use. If there are several possible answers, you can print any of them.

NoteIn the first example, the first bus of the first route arrives at time $$$6$$$, and the first bus of the second route arrives at time $$$9$$$, so the first route is the answer.In the second example, a bus of the third route arrives at time $$$5$$$, so it is the answer.In the third example, buses of the first route come at times $$$2$$$, $$$4$$$, $$$6$$$, $$$8$$$, and so fourth, buses of the second route come at times $$$2$$$, $$$5$$$, $$$8$$$, and so fourth and buses of the third route come at times $$$2$$$, $$$6$$$, $$$10$$$, and so on, so $$$1$$$ and $$$2$$$ are both acceptable answers while $$$3$$$ is not.

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)
	var n ,t int
	var s,d int
	fmt.Fscanf(buf, "%d %d\n", &n,&t)
	var maxw int = -1
	var maxt int = -1

	for i := 1; i <= n; i++ {
		fmt.Fscanf(buf, "%d %d\n", &s,&d)
		tmp := s
		if t > s{
			tmp =(1+ (t-s-1)/d)*d + s
		}
		if  maxt == -1|| tmp < maxt{
			maxt = tmp
			maxw = i
		}
	}
	fmt.Printf("%d\n",maxw)

}

package main

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

func main() {
    reader := bufio.NewReaderSize(os.Stdin, 1024 * 1024)

    arTemp := strings.Split(readLine(reader), " ")
    n, err := strconv.ParseInt(arTemp[0], 10, 64)
    checkError(err)
    t, err := strconv.ParseInt(arTemp[1], 10, 64)
    checkError(err)

    ans := 0
    min := int64(1000000)
    for i := 1; i <= int(n); i++ {
        arItemTemp := strings.Split(readLine(reader), " ")
        s, err := strconv.ParseInt(arItemTemp[0], 10, 64)
        checkError(err)
        d, err := strconv.ParseInt(arItemTemp[1], 10, 64)
        checkError(err)

        if t > s {
            cnt := (t - s) / d
            rem := (t - s) % d
            if rem != 0 {
                cnt++
            }
            s += d * cnt
        }
        diff := s - t
        if diff < min {
            min = diff
            ans = i
        }
    }

    fmt.Println(ans)
}

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 (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	text := scanner.Text()
	str := strings.Split(text, " ")
	numBusRoutes, _ := strconv.Atoi(str[0])
	startTime, _ := strconv.Atoi(str[1])

	var busTaken, minWaitTime int

	for i := 1; i <= numBusRoutes; i++ {
		scanner.Scan()
		text := scanner.Text()
		str := strings.Split(text, " ")
		busArrival, _ := strconv.Atoi(str[0])
		busInterval, _ := strconv.Atoi(str[1])

		if busArrival == startTime {
			fmt.Println(i)
			return
		}

		waitTime := busArrival - startTime

		if busArrival < startTime {
			nextBus := busArrival
			for nextBus < startTime {
				nextBus += busInterval

				if nextBus == startTime {
					fmt.Println(i)
					return
				}
			}
			waitTime = nextBus - startTime
		}

		if minWaitTime == 0 || waitTime < minWaitTime {
			busTaken = i
			minWaitTime = waitTime
		}
	}
	fmt.Println(busTaken)
}

package main

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

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

	var n, t int
	fmt.Fscanln(in, &n, &t)

	minVal := -1
	minIndex := -1
	for i := 0; i < n; i++ {
		var s, d int
		fmt.Fscanln(in, &s, &d)

		earliest := s - t
		if earliest < 0 {
			times := (earliest * -1 - 1) / d + 1
			earliest += times * d
		}
		//fmt.Println("Earliest:", earliest, )
		if earliest < minVal || minVal == -1 {
			minVal = earliest
			minIndex = i
		}
	}

	fmt.Println(minIndex + 1)
}

package main

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

func main() {
	sc := NewScanner()
	N, T := sc.NextInt(), sc.NextInt()
	mn := int(1e9)
	index := 0
	for i := 0; i < N; i++ {
		s, d := sc.NextInt(), sc.NextInt()
		A := (d - (T-s)%d) % d
		if T-s < 0 {
			A = s - T
		}
		//fmt.Println(mn, A)
		if mn > A {
			mn = A
			index = i + 1
		}
	}
	fmt.Println(index)

}

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

func main() {
	sc := NewScanner()
	N, T := sc.NextInt(), sc.NextInt()
	mn := int(1e9)
	index := 0
	for i := 0; i < N; i++ {
		s, d := sc.NextInt(), sc.NextInt()
		A := (d - (T-s)%d) % d
		//fmt.Println(mn, A)
		if mn > A {
			mn = A
			index = i + 1
		}
	}
	fmt.Println(index)

}

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

func main() {
	sc := NewScanner()
	N, T := sc.NextInt(), sc.NextInt()
	mn := int(1e9)
	index := 0
	for i := 0; i < N; i++ {
		s, d := sc.NextInt(), sc.NextInt()
		A := (d - (T - s)) % d
		if T-s < 0 {
			A = s - T
		}
		//fmt.Println(mn, A)
		if mn > A {
			mn = A
			index = i + 1
		}
	}
	fmt.Println(index)

}

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


Let $$$a$$$ and $$$b$$$ be some non-negative integers. Let's define strange addition of $$$a$$$ and $$$b$$$ as following:  write down the numbers one under another and align them by their least significant digit;  add them up digit by digit and concatenate the respective sums together. Assume that both numbers have an infinite number of leading zeros.For example, let's take a look at a strange addition of numbers $$$3248$$$ and $$$908$$$:  You are given a string $$$c$$$, consisting of $$$n$$$ digits from $$$0$$$ to $$$9$$$. You are also given $$$m$$$ updates of form:   $$$x~d$$$ — replace the digit at the $$$x$$$-th position of $$$c$$$ with a digit $$$d$$$. Note that string $$$c$$$ might have leading zeros at any point of time.After each update print the number of pairs $$$(a, b)$$$ such that both $$$a$$$ and $$$b$$$ are non-negative integers and the result of a strange addition of $$$a$$$ and $$$b$$$ is equal to $$$c$$$.Note that the numbers of pairs can be quite large, so print them modulo $$$998244353$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5 \cdot 10^5$$$) — the length of the number $$$c$$$ and the number of updates. The second line contains a string $$$c$$$, consisting of exactly $$$n$$$ digits from $$$0$$$ to $$$9$$$. Each of the next $$$m$$$ lines contains two integers $$$x$$$ and $$$d$$$ ($$$1 \le x \le n$$$, $$$0 \le d \le 9$$$) — the descriptions of updates.

Print $$$m$$$ integers — the $$$i$$$-th value should be equal to the number of pairs $$$(a, b)$$$ such that both $$$a$$$ and $$$b$$$ are non-negative integers and the result of a strange addition of $$$a$$$ and $$$b$$$ is equal to $$$c$$$ after $$$i$$$ updates are applied. Note that the numbers of pairs can be quite large, so print them modulo $$$998244353$$$.

package main

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

const mod = 998244353

var s []byte

type seg []struct {
	l, r int
	mat  [2][2]int64
}

func (t seg) set(o, i int) {
	t[o].mat = [2][2]int64{{int64(s[i] + 1), 1}}
	if s[i-1] == 1 {
		t[o].mat[1][0] = int64(9 - s[i])
	}
}

func (seg) mul(a, b [2][2]int64) (c [2][2]int64) {
	for i := 0; i < 2; i++ {
		for j := 0; j < 2; j++ {
			for k := 0; k < 2; k++ {
				c[i][j] += a[i][k] * b[k][j]
			}
			c[i][j] %= mod
		}
	}
	return
}

func (t seg) maintain(o int) { t[o].mat = t.mul(t[o<<1].mat, t[o<<1|1].mat) }

func (t seg) build(o, l, r int) {
	t[o].l, t[o].r = l, r
	if l == r {
		t.set(o, l)
		return
	}
	m := (l + r) >> 1
	t.build(o<<1, l, m)
	t.build(o<<1|1, m+1, r)
	t.maintain(o)
}

func (t seg) update(o, i int) {
	if t[o].l == t[o].r {
		t.set(o, i)
		return
	}
	if i <= (t[o].l+t[o].r)>>1 {
		t.update(o<<1, i)
	} else {
		t.update(o<<1|1, i)
	}
	t.maintain(o)
}

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

	var n, q, i int
	var d byte
	Fscan(in, &n, &q, &s)
	for i := range s {
		s[i] &= 15
	}
	s = append([]byte{0}, s...)
	t := make(seg, 4*n)
	t.build(1, 1, n)
	for ; q > 0; q-- {
		Fscan(in, &i, &d)
		s[i] = d
		if i < n {
			t.update(1, i+1)
		}
		t.update(1, i)
		Fprintln(out, t[1].mat[0][0])
	}
}

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


Today Adilbek is taking his probability theory test. Unfortunately, when Adilbek arrived at the university, there had already been a long queue of students wanting to take the same test. Adilbek has estimated that he will be able to start the test only $$$T$$$ seconds after coming. Fortunately, Adilbek can spend time without revising any boring theorems or formulas. He has an app on this smartphone which contains $$$n$$$ Japanese crosswords to solve. Adilbek has decided to solve them all one by one in the order they are listed in the app, without skipping any crossword. For each crossword, a number $$$t_i$$$ is given that represents the time it takes an average crossword expert to solve this crossword (the time is given in seconds).Adilbek is a true crossword expert, but, unfortunately, he is sometimes unlucky in choosing the way to solve the crossword. So, it takes him either $$$t_i$$$ seconds or $$$t_i + 1$$$ seconds to solve the $$$i$$$-th crossword, equiprobably (with probability $$$\frac{1}{2}$$$ he solves the crossword in exactly $$$t_i$$$ seconds, and with probability $$$\frac{1}{2}$$$ he has to spend an additional second to finish the crossword). All these events are independent.After $$$T$$$ seconds pass (or after solving the last crossword, if he manages to do it in less than $$$T$$$ seconds), Adilbek closes the app (if he finishes some crossword at the same moment, that crossword is considered solved; otherwise Adilbek does not finish solving the current crossword at all). He thinks it would be an interesting probability theory problem to calculate $$$E$$$ — the expected number of crosswords he will be able to solve completely. Can you calculate it? Recall that the expected value of a discrete random variable is the probability-weighted average of all possible values — in this problem it means that the expected value of the number of solved crosswords can be calculated as $$$E = \sum \limits_{i = 0}^{n} i p_i$$$, where $$$p_i$$$ is the probability that Adilbek will solve exactly $$$i$$$ crosswords. We can represent $$$E$$$ as rational fraction $$$\frac{P}{Q}$$$ with $$$Q > 0$$$. To give the answer, you should print $$$P \cdot Q^{-1} \bmod (10^9 + 7)$$$.

The first line contains two integers $$$n$$$ and $$$T$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$1 \le T \le 2 \cdot 10^{14}$$$) — the number of crosswords and the time Adilbek has to spend, respectively. The second line contains $$$n$$$ integers $$$t_1, t_2, \dots, t_n$$$ ($$$1 \le t_i \le 10^9$$$), where $$$t_i$$$ is the time it takes a crossword expert to solve the $$$i$$$-th crossword. Note that Adilbek solves the crosswords in the order they are given in the input without skipping any of them.

Print one integer — the expected value of the number of crosswords Adilbek solves in $$$T$$$ seconds, expressed in the form of $$$P \cdot Q^{-1} \bmod (10^9 + 7)$$$.

NoteThe answer for the first sample is equal to $$$\frac{14}{8}$$$.The answer for the second sample is equal to $$$\frac{17}{8}$$$.

package main

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

const M int64 = 1e9 + 7
const MaxN = 2*1e5 + 5

var fac [MaxN]int64
var invfac [MaxN]int64

func modpow(x, n int64) (r int64) {
	r = 1
	for ; n != 0; n /= 2 {
		if n&1 != 0 {
			r = (r * x) % M
		}
		x = (x * x) % M
	}
	return
}

func modinv(x int64) int64 {
	return modpow(x, M-2)
}

func fillFac(n int) {
	fac[0] = 1
	for i := 1; i <= n; i++ {
		fac[i] = fac[i-1] * int64(i) % M
	}
	invfac[n] = modinv(fac[n])
	for i := n; i > 0; i-- {
		invfac[i-1] = invfac[i] * int64(i) % M
	}
}

func C(n, m int) int64 {
	if n < m {
		return 0
	}
	return fac[n] * invfac[m] % M * invfac[n-m] % M
}

func (io *IO) Solve() {
	n, T := io.Int(), io.Int64()
	fillFac(n)
	var sum int64
	var pi int64
	var res int64
	inv2 := (M + 1) / 2
	var pow2 int64 = 1
	var diff, newDiff int
	var i int
	for i = 1; i <= n; i++ {
		pow2 = pow2 * inv2 % M
		t := io.Int()
		sum += int64(t)
		if sum > T {
			break
		}
		if sum+int64(i) <= T {
			// pi = 1
			res = (res + 1) % M
			continue
		}
		if pi == 0 {
			for j := 0; sum+int64(j) <= T; j++ {
				pi = (pi + C(i, j)) % M
			}
			diff = int(T - sum)
		} else {
			pi = (pi*2 + C(i-1, diff+1)) % M
			newDiff = int(T - sum)

			for j := newDiff + 1; j <= diff+1; j++ {
				pi = (pi + M - C(i, j)) % M
			}
			diff = newDiff
		}
		res = (res + pi*pow2%M) % M
	}
	io.Printf("%v\n", res)
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int64() (n int64) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int64(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	var negative bool
	var i int
	if buf[0] == '-' {
		negative = true
		i++
	}
	for ; i < len(buf); i++ {
		n = n*10 + int(buf[i]-'0')
	}
	if negative {
		n = -n
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() (s []byte) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	s = make([]byte, len(buf))
	copy(s, buf)
	return
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

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

const M int64 = 1e9 + 7
const MaxN = 2*1e5 + 5

var fac [MaxN]int64
var invfac [MaxN]int64

func modpow(x, n int64) (r int64) {
	r = 1
	for ; n != 0; n /= 2 {
		if n&1 != 0 {
			r = (r * x) % M
		}
		x = (x * x) % M
	}
	return
}

func modinv(x int64) int64 {
	return modpow(x, M-2)
}

func fillFac(n int) {
	fac[0] = 1
	for i := 1; i <= n; i++ {
		fac[i] = fac[i-1] * int64(i) % M
	}
	invfac[n] = modinv(fac[n])
	for i := n; i > 0; i-- {
		invfac[i-1] = invfac[i] * int64(i) % M
	}
}

func C(n, m int) int64 {
	if n < m {
		return 0
	}
	return fac[n] * invfac[m] % M * invfac[n-m] % M
}

func (io *IO) Solve() {
	n, T := io.Int(), io.Int64()
	fillFac(n)
	var sum int64
	var pi int64
	var res int64
	inv2 := (M + 1) / 2
	var pow2 int64 = 1
	var diff, newDiff int
	var i int
	for i = 1; i <= n; i++ {
		pow2 = pow2 * inv2 % M
		t := io.Int()
		sum += int64(t)
		if sum > T {
			break
		}
		if sum+int64(i) <= T {
			// pi = 1
			res = (res + 1) % M
			continue
		}
		if pi == 0 {
			for j := 0; sum+int64(j) <= T; j++ {
				pi = (pi + C(i, j)) % M
			}
			diff = int(T - sum)
		} else {
			pi = (pi*2 + C(i-1, diff+1)) % M
			newDiff = int(T - sum)

			for j := newDiff + 1; j <= diff; j++ {
				pi = (pi - C(i, j)) % M
			}
			diff = newDiff
		}
		res = (res + pi*pow2) % M
	}
	io.Printf("%v\n", res)
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int64() (n int64) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int64(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	var negative bool
	var i int
	if buf[0] == '-' {
		negative = true
		i++
	}
	for ; i < len(buf); i++ {
		n = n*10 + int(buf[i]-'0')
	}
	if negative {
		n = -n
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() (s []byte) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	s = make([]byte, len(buf))
	copy(s, buf)
	return
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

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

const M int64 = 1e9 + 7
const MaxN = 2*1e5 + 5

var fac [MaxN]int64
var invfac [MaxN]int64

func modpow(x, n int64) (r int64) {
	r = 1
	for ; n != 0; n /= 2 {
		if n&1 != 0 {
			r = (r * x) % M
		}
		x = (x * x) % M
	}
	return
}

func modinv(x int64) int64 {
	return modpow(x, M-2)
}

func fillFac(n int) {
	fac[0] = 1
	for i := 1; i <= n; i++ {
		fac[i] = fac[i-1] * int64(i) % M
	}
	invfac[n] = modinv(fac[n])
	for i := n; i > 0; i-- {
		invfac[i-1] = invfac[i] * int64(i) % M
	}
}

func C(n, m int) int64 {
	if n < m {
		return 0
	}
	return fac[n] * invfac[m] % M * invfac[n-m] % M
}

func (io *IO) Solve() {
	n, T := io.Int(), io.Int64()
	fillFac(n)
	var sum int64
	var pi int64
	var res int64
	inv2 := (M + 1) / 2
	var pow2 int64 = 1
	var diff, newDiff int
	var i int
	for i = 1; i <= n; i++ {
		pow2 = pow2 * inv2 % M
		t := io.Int()
		sum += int64(t)
		if sum > T {
			break
		}
		if sum+int64(i) <= T {
			// pi = 1
			res = (res + 1) % M
			continue
		}
		if pi == 0 {
			for j := 0; sum+int64(j) <= T; j++ {
				pi = (pi + C(i, j)) % M
			}
			diff = int(T - sum)
		} else {
			pi = (pi*2 + C(i-1, diff+1)) % M
			newDiff = int(T - sum)

			for j := newDiff + 1; j <= diff+1; j++ {
				pi = (pi - C(i, j)) % M
			}
			diff = newDiff
		}
		res = (res + pi*pow2) % M
	}
	io.Printf("%v\n", res)
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int64() (n int64) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int64(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	var negative bool
	var i int
	if buf[0] == '-' {
		negative = true
		i++
	}
	for ; i < len(buf); i++ {
		n = n*10 + int(buf[i]-'0')
	}
	if negative {
		n = -n
	}
	return
}

func (io *IO) UInt() (n uint) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + uint(v-'0')
	}
	return
}

func (io *IO) Bytes() (s []byte) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	s = make([]byte, len(buf))
	copy(s, buf)
	return
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) UIntArray(n int) (arr []uint) {
	arr = make([]uint, n)
	for i := 0; i < n; i++ {
		arr[i] = io.UInt()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}


Given an array $$$a$$$ of length $$$n$$$, you can do at most $$$k$$$ operations of the following type on it:  choose $$$2$$$ different elements in the array, add $$$1$$$ to the first, and subtract $$$1$$$ from the second. However, all the elements of $$$a$$$ have to remain non-negative after this operation. What is lexicographically the smallest array you can obtain?An array $$$x$$$ is lexicographically smaller than an array $$$y$$$ if there exists an index $$$i$$$ such that $$$x_i<y_i$$$, and $$$x_j=y_j$$$ for all $$$1 \le j < i$$$. Less formally, at the first index $$$i$$$ in which they differ, $$$x_i<y_i$$$.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 20$$$) – the number of test cases you need to solve. The first line of each test case contains $$$2$$$ integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 100$$$, $$$1 \le k \le 10000$$$) — the number of elements in the array and the maximum number of operations you can make. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$0 \le a_i \le 100$$$) — the elements of the array $$$a$$$.

For each test case, print the lexicographically smallest array you can obtain after at most $$$k$$$ operations.

NoteIn the second test case, we start by subtracting $$$1$$$ from the first element and adding $$$1$$$ to the second. Then, we can't get any lexicographically smaller arrays, because we can't make any of the elements negative.

package main

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

type CF1516A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1516A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1516A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1516A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1516A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1516A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1516A
Date: 19/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1516/A
Problem: CF1516A
**/
func (in *CF1516A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n, k := in.NextInt(), in.NextInt()
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			arr[i] = in.NextInt()
		}
		index := 0
		for i := 0; i < k; i++ {
			for j := index; j < n; j++ {
				if arr[j] > 0 {
					index = j
					arr[index]--
					arr[n-1]++
					break
				}
			}
		}

		for i := 0; i < n; i++ {
			fmt.Print(arr[i], " ")
		}
		fmt.Println()
	}
}
func NewCF1516A(r *bufio.Reader) *CF1516A {
	return &CF1516A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1516A(bufio.NewReader(os.Stdin)).Run()
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,k int
		fmt.Fscan(in,&n,&k)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		count:=0
		for j:=0;j<k;j++{
			if list[count] == 0 {
				count++
				j--
			} else {
				list[count]--
				list[n-1]++
			}
			if count > n-2{
				break
			}
		}
		for j:=0;j<len(list);j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out,)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int

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

		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
		}

		j := 0
		for k > 0 {
			if j == n-1 {
				break
			}

			if a[j] == 0 {
				j++
				continue
			}

			k--
			a[j]--
			a[n-1]++
		}

		for i := 0; i < n; i++ {
			fmt.Print(a[i], " ")
		}
		fmt.Print("\n")
	}
}

package main

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

const REPEAT bool = true
const CASE   bool = false

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

  if REPEAT {
    var t int
    Fscan(in, &t);
    for i := 1; i <= t; i++ {
      if CASE {
        Fprintf(out, "Case #%d: ", i)
      }
      solve(in, out)
    }
  } else {
    solve(in, out)
  }
}

func solve(in io.Reader, out io.Writer) {
  var n, k int
  Fscan(in, &n, &k)
  arr := make([]int, n)
  for i := range arr {
    Fscan(in, &arr[i])
  }
  sum := 0
  for i := 0; i < n - 1 && k > 0; i++ {
    if k >= arr[i] {
      sum += arr[i]
      k -= arr[i]
      arr[i] = 0
    } else {
      sum += k
      arr[i] -= k
      k = 0
    }
  }
  arr[n-1] += sum
  for _, e := range arr {
    Fprintf(out, "%d ", e)
  }
  Fprintln(out)
}

package main

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

const maxN = 100023

func main() {
  in := bufio.NewReader(os.Stdin)
  out := bufio.NewWriter(os.Stdout)
  defer out.Flush()
  var tt int
  fmt.Fscan(in, &tt)
  for tc := 1; tc <= tt; tc++ {
    var n, k int
    fmt.Fscan(in, &n, &k)
    var a[maxN] int
    for i := 0; i < n; i++ {
      fmt.Fscan(in, &a[i])
    }
    i := 0
    for true {
      if i == n-1 || k == 0{
        break
      }
      if a[i] == 0 {
        i++
        continue
      }
      a[i]--
      a[n-1]++
      k--
    }
    for i = 0; i < n; i++ {
      fmt.Fprint(out, a[i], " ")
    }
    fmt.Fprintln(out)
  }
}

package main

import (
	"fmt"
)

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	l := 0
	r := n - 1
	for i := 0; i < k; i++ {
		for j := l; j < n; j++ {
			if a[j] > 0 {
				break
			}
			l++
		}

		if l <= r && a[l] > 0 {
			a[l]--
			a[r]++
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println()
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var buf bytes.Buffer
	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, k := readTwoNums(reader)
		A := readNNums(reader, n)
		solve(n, k, A)
		for i := 0; i < n; i++ {
			buf.WriteString(fmt.Sprintf("%d ", A[i]))
		}
		buf.WriteByte('\n')
	}
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}

func solve(n int, k int, A []int) {
	i, j := 0, n-1

	for i < j && k > 0 {
		x := max(0, A[i]-k)
		k -= A[i] - x
		// want to decrease A[i] to x
		A[j] += A[i] - x
		A[i] = x
		i++
	}
}

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

package main

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

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt(), ScanInt()
		a := make([]int, n)
		ops := 0

		for i := range a {
			a[i] = ScanInt()

			if ops+a[i] < k {
				ops += a[i]
				a[i] = 0
			} else {
				a[i] -= k - ops
				ops = k
			}
		}

		a[n-1] += ops
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	}
}

package main

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

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

	solve := func() {
		var n, k int
		fmt.Fscan(in, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		j := 0
		for i := 0; i < k; i++ {
			for j < n && a[j] < 1 {
				j++
			}
			if j >= n-1 {
				break
			}
			if a[j] > 0 {
				a[j]--
				a[len(a)-1]++
			}
		}
		for i := 0; i < n; i++ {
			fmt.Fprint(out, a[i], " ")
		}
		fmt.Fprintln(out)
	}

	var T int
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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

package main

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

func solve() {
	f := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	N, n, k := 0, 0, 0
	fmt.Fscan(f, &N)
	for i := 0; i < N; i++ {
		fmt.Fscan(f, &n, &k)
		j, o, l := 0, make([]int, n), 0
		for q := 0; q < n; q++ {
			fmt.Fscan(f, &o[q])
		}
		for {
			if k <= 0 || j == n-1 {
				o[n-1] += l
				break
			} else {
				if o[j] <= k {
					o[j], k, l = 0, k-o[j], l+o[j]
				} else {
					o[j], k, l = o[j]-k, 0, l+k
				}
			}
			j++
		}
		for q := 0; q < n; q++ {
			fmt.Fprint(w, o[q], " ")
		}
		fmt.Fprintln(w, "")
	}
	w.Flush()
}

func main() {
	solve()
}

package main

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

var (
	reader  = bufio.NewReader(os.Stdin)
	t, n, k int
)

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

func solve(n, k int, a []int) string {
	for i := 0; i < n-1 && k > 0; i++ {
		d := min(k, a[i])
		a[n-1] += d
		a[i] -= d
		k -= d
	}
	x := ""
	for i := 0; i < n; i++ {
		x += fmt.Sprintf("%d ", a[i])
	}
	return x
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(n, k, a))
	}
}

package main

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

var (
	reader *bufio.Reader = bufio.NewReader(os.Stdin)
	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 SplitToString(a []int, sep string) string {
	if len(a) == 0 {
		return ""
	}

	b := make([]string, len(a))
	for i, v := range a {
		b[i] = strconv.Itoa(v)
	}
	return strings.Join(b, sep)
}

func main() {
	defer writer.Flush()

	var t, n, k int
	scanf("%d\n", &t)

	for i := 0; i < t; i++ {
		scanf("%d %d\n", &n, &k)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			scanf("%d", &a[i])
		}
		scanf("\n")

		for i := 0; i < n; i++ {
			for a[i] > 0 && k > 0 {
				k--
				a[i]--
				a[n-1]++
			}
		}

		fmt.Printf("%s\n", SplitToString(a, " "))
	}
}

package main

import "fmt"

func code() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Scan(&n, &k)
		array := make([]int, n)
		for j := 0; j < n; j++{
			a := 0
			fmt.Scan(&a)
			array[j] = a
		}
		for p := 0; p < k; p++{
			for j := 0; j < n; j++{
				if (array[j] > 0){
					array[j] -= 1
					array[len(array)-1] += 1
					break
				} else {
				}
			}
		}
		for j := 0; j < len(array); j++{
			fmt.Print(array[j])
			fmt.Print(" ")
		}
		fmt.Println()
	}
}

func main(){
	code()
}

package main

import (
	"fmt"
	"math"
)

func main() {
	const N = 100

	var t, n, k int
	var a [N]int
	fmt.Scanln(&t)
	for ; t > 0; t-- {
		fmt.Scan(&n)
		fmt.Scanln(&k)
		for u := 0; u < n; u++ {
			fmt.Scan(&a[u])
		}
		for u := 0; u < n; u++ {
			var temp int
			if u < n-1 {
				temp = int(math.Min(float64(k), float64(a[u])))
			} else {
				temp = 0
			}
			a[u] -= temp
			k -= temp
			a[n-1] += temp
			fmt.Print(a[u], " ")
		}
		fmt.Println()
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)
var 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() {
	defer writer.Flush()

	var t int
	scanf("%d\n", &t)
	for i := 0; i < t; i++ {
		var n, k, a int
		scanf("%d %d\n", &n, &k)
		var numbers []int
		for j := 0; j < n-1; j++ {
			scanf("%d ", &a)
			numbers = append(numbers, a)
		}
		scanf("%d\n", &a)
		numbers = append(numbers, a)

		solution(numbers, k)
		for _, n := range numbers {
			printf("%d ", n)
		}
		printf("\n")
	}
}

func solution(numbers []int, k int) {
	l := len(numbers)
	for i := 0; i < l-1; i++ {
		if k > numbers[i] {
			k -= numbers[i]
			numbers[l-1] += numbers[i]
			numbers[i] = 0
			continue
		}

		numbers[l-1] += k
		numbers[i] -= k
		k = 0
		break
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var T, N, K, a int
	Fscan(in, &T)
	for t := 0; t < T; t++ {
		Fscan(in, &N, &K)
		ns := make([]int, N)
		for i := 0; i < N; i++ {
			Fscan(in, &a)
			ns[i] = a
		}
		i := 0
		k := K
		for k > 0 && i < N {
			d := k - ns[i]
			if d <= 0 {
				ns[i] -= k
				ns[N-1] += k
				break
			}
			delta := ns[i]
			k -= delta
			ns[i] = 0
			ns[N-1] += delta
			i++
		}
		// Fprintln(out, N, K, ns)
		for idx := 0; idx < N; idx++ {
			Fprint(out, ns[idx], " ")
		}
		Fprint(out, "\n")
	}

}

package main

import (
	"fmt"
	"os"
)

func scanf(f string, args ...interface{})  { fmt.Fscanf(os.Stdin, f, args...) }
func printf(f string, args ...interface{}) { fmt.Fprintf(os.Stdout, f, args...) }

func main() {
	var l int
	fmt.Fscanf(os.Stdin, "%d\n", &l)
	for i := 0; i < l; i++ {
		var n, k int
		fmt.Fscan(os.Stdin, &n)
		fmt.Fscan(os.Stdin, &k)

		a := make([]int, n)
		for j := 0; j < n; j++ {
			fmt.Fscan(os.Stdin, &a[j])
		}
		r := fn(a, k)
		h := 0
		value := 0
		for h, value = range r {
			if h < n-1 {
				fmt.Fprintf(os.Stdout, "%d ", value)
			} else {
				fmt.Fprintf(os.Stdout, "%d\n", value)
			}
		}
	}
}

func fn(a []int, k int) []int {
	i := 0
	n := len(a) - 1
	for k > 0 {
		if a[i] > 0 {
			a[i]--
			a[n]++
			k--
		} else if i+1 < n {
			i++
		} else {
			break
		}
	}
	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()

	solve := func(Case int) {
		var n, k int
		Fscan(in, &n, &k)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		for i := range a {
			for a[i] > 0 && k > 0 {
				a[i]--
				k--
				a[n-1]++
			}
			if k == 0 {
				break
			}
		}
		for _, v := range a {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

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

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

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,k int
		fmt.Fscan(in,&n,&k)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		count:=0
		for j:=0;j<k;j++{
			list[count]--
			list[n-1]++
			if list[count] == 0 {
				count++
			}
			if count > n-2{
				break
			}
		}
		for j:=0;j<len(list);j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out,)
	}
}

package main
import(
    "fmt"
    "bufio"
    "os"
)
func main() {
	in:= bufio.NewReader(os.Stdin)
	out:= bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in,&t)
	for i:=0;i<t;i++{
		var n,k int
		fmt.Fscan(in,&n,&k)
		list:= make([]int,n)
		for j:=0;j<n;j++{
			fmt.Fscan(in,&list[j])
		}
		count:=0
		for j:=0;j<k;j++{
			list[count]--
			list[n-1]++
			if list[0] == 0 {
				count++
			}
			if count > n-2{
				break
			}
		}
		for j:=0;j<len(list);j++{
			fmt.Fprintf(out,"%v ",list[j])
		}
		fmt.Fprintln(out,)
	}
}

package main

import (
	"fmt"
)

func main() {
	var t int

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

		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Scan(&a[i])
		}

		j := 0
		for ; k > 0; k-- {
			if a[j] == 0 {
				j++
			}

			if j == n-1 {
				break
			}

			a[j]--
			a[n-1]++
		}

		for i := 0; i < n; i++ {
			fmt.Print(a[i], " ")
		}
		fmt.Print("\n")
	}
}

package main

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

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

const maxN = 100023

func main() {
  defer writer.Flush()
  var tt int
  scanf("%d\n", &tt)
  for tc := 1; tc <= tt; tc++ {
    var n, k int
    scanf("%d %d\n", &n, &k)
    var a[maxN] int
    for i := 0; i < n; i++ {
      scanf("%d ", &a[i])
    }
    i := 0
    for true {
      if i == n-1 || k == 0{
        break
      }
      if a[i] == 0 {
        i++
        continue
      }
      a[i]--
      a[n-1]++
      k--
    }
    for i = 0; i < n; i++ {
      printf("%d ", a[i])
    }
    printf("\n")
  }
}

package main

import (
	"fmt"
)

func solve() {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	l := 0
	r := n - 1
	for i := 0; i < k; i++ {
		for j := l; j < n; j++ {
			if a[j] > 0 {
				break
			}
		}

		if a[l] > 0 {
			a[l]--
			a[r]++
		}
	}
	for i := 0; i < n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println()
}

func main() {
	var t int
	fmt.Scan(&t)
	for i := 0; i < t; i++ {
		solve()
	}
}

package main

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

var fields []string

func init() {
	f, err := os.Open("in.txt")

	if err == nil {
		defer f.Close()
	} else {
		f = os.Stdin
	}

	bytes, err := ioutil.ReadAll(bufio.NewReader(f))

	if err != nil {
		panic(err)
	}

	fields = strings.Fields(string(bytes))
}

func ScanString() string {
	for {
		field := fields[0]
		fields = fields[1:]

		if field != "" {
			return field
		}
	}
}

func ScanInt() int {
	n, err := strconv.Atoi(ScanString())

	if err != nil {
		panic(err)
	}

	return n
}

func ScanInt64() int64 {
	n, err := strconv.ParseInt(ScanString(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {
	for t := ScanInt(); t > 0; t-- {
		n, k := ScanInt(), ScanInt()
		a := make([]int, n)
		ops := 0

		for i := range a {
			a[i] = ScanInt()

			if ops+a[i] < k {
				a[i] = 0
				ops += a[i]
			} else {
				a[i] -= k - ops
				ops = k
			}
		}

		a[n-1] += ops
		fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	}
}

package main

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

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

	solve := func() {
		var n, k int
		fmt.Fscan(in, &n, &k)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &a[i])
		}
		j := 0
		for i := 0; i < k; i++ {
			for j < n && a[j] > 1 {
				j++
			}
			if j == k-1 {
				break
			}
			if a[j] > 1 {
				a[j]--
				a[len(a)-1]++
			}
		}
		for i := 0; i < n; i++ {
			fmt.Fprint(out, a[i], " ")
		}
		fmt.Fprintln(out)
	}

	var T int
	fmt.Fscan(in, &T)
	for o := 0; o < T; o++ {
		solve()
	}

}

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


Consider the following problem: given an array $$$a$$$ containing $$$n$$$ integers (indexed from $$$0$$$ to $$$n-1$$$), find $$$\max\limits_{0 \leq l \leq r \leq n-1} \sum\limits_{l \leq i \leq r} (r-l+1) \cdot a_i$$$. In this problem, $$$1 \leq n \leq 2\,000$$$ and $$$|a_i| \leq 10^6$$$.In an attempt to solve the problem described, Alice quickly came up with a blazing-fast greedy algorithm and coded it. Her implementation in pseudocode is as follows:function find_answer(n, a)    # Assumes n is an integer between 1 and 2000, inclusive    # Assumes a is a list containing n integers: a[0], a[1], ..., a[n-1]    res = 0    cur = 0    k = -1    for i = 0 to i = n-1        cur = cur + a[i]        if cur < 0            cur = 0            k = i        res = max(res, (i-k)*cur)    return resAlso, as you can see, Alice's idea is not entirely correct. For example, suppose $$$n = 4$$$ and $$$a = [6, -8, 7, -42]$$$. Then, find_answer(n, a) would return $$$7$$$, but the correct answer is $$$3 \cdot (6-8+7) = 15$$$.You told Alice that her solution is incorrect, but she did not believe what you said.Given an integer $$$k$$$, you are to find any sequence $$$a$$$ of $$$n$$$ integers such that the correct answer and the answer produced by Alice's algorithm differ by exactly $$$k$$$. Note that although the choice of $$$n$$$ and the content of the sequence is yours, you must still follow the constraints earlier given: that $$$1 \leq n \leq 2\,000$$$ and that the absolute value of each element does not exceed $$$10^6$$$. If there is no such sequence, determine so.

The first and only line contains one integer $$$k$$$ ($$$1 \leq k \leq 10^9$$$).

If there is no sought sequence, print "-1". Otherwise, in the first line, print one integer $$$n$$$ ($$$1 \leq n \leq 2\,000$$$), denoting the number of elements in the sequence. Then, in the second line, print $$$n$$$ space-separated integers: $$$a_0, a_1, \ldots, a_{n-1}$$$ ($$$|a_i| \leq 10^6$$$).

NoteThe first sample corresponds to the example given in the problem statement.In the second sample, one answer is $$$n = 7$$$ with $$$a = [30, -12, -99, 123, -2, 245, -300]$$$, in which case find_answer(n, a) returns $$$1098$$$, while the correct answer is $$$1710$$$.

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var k int
	fmt.Fscanf(reader, "%d", &k)
	n, s := 2000, 2000 + k
	fmt.Printf("2000\n-1")
	for i := 1;i < n;i ++ {
		if s >= 1000000 {
			fmt.Printf(" 1000000")
			s -= 1000000
		} else {
			fmt.Printf(" %d", s)
			s = 0
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1129B(in io.Reader, out io.Writer) {
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	Fprint(out, "2000\n-1")
	var k int
	Fscan(in, &k)
	k += 2000
	for i := 1; i < 2000; i++ {
		v := min(1e6, k)
		Fprint(out, " ", v)
		k -= v
	}
}

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

package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"
)

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)
	var k int
	fmt.Fscanf(reader, "%d", &k)
	n, s := 2000, 2000 + k
	fmt.Printf("-1")
	for i := 1;i < n;i ++ {
		if s >= 1000000 {
			fmt.Printf(" 1000000")
			s -= 1000000
		} else {
			fmt.Printf(" %d", s)
			s = 0
		}
	}
}


You are given the array of integer numbers a0, a1, ..., an - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.

The first line contains integer n (1 ≤ n ≤ 2·105) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 109 ≤ ai ≤ 109).

Print the sequence d0, d1, ..., dn - 1, where di is the difference of indices between i and nearest j such that aj = 0. It is possible that i = j.

package main

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

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

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

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

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

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

func solve(n int) {
	a := make([]int, n)
	b := make([]int, n)
	var z []int
	for i := range a {
		I(&a[i])
		if a[i] == 0 {
			z = append(z, i)
		}
	}
	for i := range a {
		f := sort.Search(len(z), func(o int) bool { return z[o] >= i })
		if f == 0 {
			b[i] = abs(z[0] - i)
		} else {
			if f != len(z) {
				t1 := abs(z[f-1] - i)
				t2 := abs(z[f] - i)
				b[i] = min(t1, t2)
			} else {
				b[i] = abs(z[f-1] - i)
			}
		}
	}
	for i := range b {
		O(b[i])
		if i != n-1 {
			O(" ")
		}
	}
	O("\n")
}

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

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	x := make([]int, n)
	r := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		x[i], _ = strconv.Atoi(scanner.Text())
	}

	if x[n-1] != 0 {
		r[n-1] = 1e6
	}
	for i := n - 2; i > -1; i-- {
		if x[i] == 0 {
			r[i] = 0
			continue
		}
		r[i] = r[i+1] + 1
	}

	l := int(1e6)
	for i := 0; i < n; i++ {
		l++
		if x[i] == 0 {
			l = 0
		}
		fmt.Printf("%d ", min(r[i], l))
	}
	fmt.Println()
}

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

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	x := make([]int, n)
	l := make([]int, n)
	r := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		x[i], _ = strconv.Atoi(scanner.Text())
	}

	if x[0] == 0 {
		l[0] = 0
	} else {
		l[0] = 1e6
	}
	for i := 1; i < n; i++ {
		if x[i] == 0 {
			l[i] = 0
			continue
		}
		l[i] = l[i-1] + 1
	}

	if x[n-1] == 0 {
		r[n-1] = 0
	} else {
		r[n-1] = 1e6
	}
	for i := n - 2; i >= 0; i-- {
		if x[i] == 0 {
			r[i] = 0
			continue
		}
		r[i] = r[i+1] + 1
	}
	for i := 0; i < n; i++ {
		fmt.Printf("%d ", min(l[i], r[i]))
	}
	fmt.Println()
}

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

package main

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

func main() {
	var n int
	fmt.Scanln(&n)

	var line string
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 13*200000)
	scanner.Buffer(buf, 13*200000)

	if scanner.Scan() {
		line = scanner.Text()
	}

	strList := strings.Split(line, " ")

	list := make([]int, n)
	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(strList[i])
	}

	var pos []int
	for i := 0; i < n; i++ {
		if list[i] == 0 {
			pos = append(pos, i)
		}
	}

	distance := make([]int, n)
	posIndex := 0
	posLen := len(pos)
	for i := 0; i < n; i++ {
		leftPos := pos[posIndex]
		var rightPos int
		if posIndex+1 < posLen {
			rightPos = pos[posIndex+1]
		} else {
			rightPos = leftPos
		}

		d1 := (int)(math.Abs((float64)(leftPos - i)))
		d2 := (int)(math.Abs((float64)(rightPos - i)))
		if d2 <= d1 {
			distance[i] = d2
			if posIndex+1 < posLen {
				posIndex++
			}
		} else {
			distance[i] = d1
		}
	}

	output := fmt.Sprint(distance)
	output = strings.Replace(output, "[", "", -1)
	output = strings.Replace(output, "]", "", -1)

	fmt.Println(output)
}

// Codeforces 803 B Distances to Zero
// doesn't work, need to count using binary intervals to speed up
package main

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

var in *bufio.Reader

func readFive() (int, int, int, int, int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i := 0; i < len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0], a[1], a[2], a[3], a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j := 0; j < n; j++ {
		aa, err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

var n int
var a []int
var d []int

func readData() {
	in = bufio.NewReader(os.Stdin)
	// read n, a
	n,_,_,_,_ = readFive()
	a = readLineNumbs(n)
}

func solve() {
	// calculating nv
	d = make([]int, n)
	// increase
	lastZero := -1
	for i:=0; i<n; i++ {
		if a[i]==0 {
			d[i] = 0
			lastZero = i
		} else {
			if lastZero >= 0 {
				d[i] = i - lastZero
			} else {
				d[i] = 100000000
			}
		}
	}
	// decrease
	lastZero = -1
	for i:=n-1; i>=0; i-- {
		if a[i]==0 {
			lastZero = i
		} else {
			if lastZero>=0 && (lastZero-i) < d[i] {
				d[i] = lastZero-i
			}
		}
	}
}

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

func main() {
	readData()
	solve()
	printRes()
}

package main

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

func z(arr *[]int, l int, r int) {
	if r == -1 {
		j := 1
		for i := l + 1; i < len((*arr)); i++ {
			(*arr)[i] = j
			j++
		}
	} else if l == -1 {
		j := 1
		for i := r - 1; i >= 0; i-- {
			(*arr)[i] = j
			j++
		}
	} else {
		tmp := (r - l) / 2
		for i := 1; i <= tmp; i++ {
			(*arr)[l+i] = i
			(*arr)[r-i] = i
		}
	}
}

func main() {
	var line string
	var n int
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	var zeropos []int
	line, _ = reader.ReadString('\n')
	n, _ = strconv.Atoi(strings.TrimSpace(line))
	answer := make([]int, n)
	line, _ = reader.ReadString('\n')
	for i, j := range strings.Split(strings.TrimSpace(line), " ") {
		if j == string('0') {
			zeropos = append(zeropos, i)
		}
	}
	z(&answer, -1, zeropos[0])
	z(&answer, zeropos[len(zeropos)-1], -1)
	if len(zeropos) > 1 {
		for i := 0; i < len(zeropos)-1; i++ {
			z(&answer, zeropos[i], zeropos[i+1])
		}
	}
	for _, j := range answer {
		writer.WriteString(strconv.Itoa(j) + " ")
	}
	writer.Flush()
}

package main

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

func main() {
	var n int
	fmt.Scanln(&n)

	var line string
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 13*200000)
	scanner.Buffer(buf, 13*200000)

	if scanner.Scan() {
		line = scanner.Text()
	}

	strList := strings.Split(line, " ")

	list := make([]int, n)
	for i := 0; i < n; i++ {
		list[i], _ = strconv.Atoi(strList[i])
	}

	pos := 0
	for i := 0; i < n; i++ {
		if list[i] == 0 {
			pos = i
			break
		}
	}

	distance := make([]int, n)
	for i := 0; i < n; i++ {
		if list[i] == 0 {
			pos = i
		}

		distance[i] = (int)(math.Abs((float64)(pos - i)))
	}

	output := fmt.Sprint(distance)
	output = strings.Replace(output, "[", "", -1)
	output = strings.Replace(output, "]", "", -1)

	fmt.Println(output)
}