Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry.He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1.Watson gave Sherlock a challenge to color these jewelry pieces such that two pieces don't have the same color if the price of one piece is a prime divisor of the price of the other piece. Also, Watson asked him to minimize the number of different colors used.Help Sherlock complete this trivial task.

The only line contains single integer n (1 ≤ n ≤ 100000) — the number of jewelry pieces.

The first line of output should contain a single integer k, the minimum number of colors that can be used to color the pieces of jewelry with the given constraints. The next line should consist of n space-separated integers (between 1 and k) that specify the color of each piece in the order of increasing price. If there are multiple ways to color the pieces using k colors, you can output any of them.

NoteIn the first input, the colors for first, second and third pieces of jewelry having respective prices 2, 3 and 4 are 1, 1 and 2 respectively.In this case, as 2 is a prime divisor of 4, colors of jewelry having prices 2 and 4 must be distinct.

package main

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

func seive(n int64) (int64, []int64) {
	var isPrime []bool = []bool{}
	var i int64
	var j int64
	var num = make([]int64, n+1)
	for i = 0; i <= n; i++ {
		isPrime = append(isPrime, true)
		num[i] = 1
	}
	var color int64 = 1
	for i = 2; i <= (n); i++ {
		if isPrime[i] == true {
			for j = 2; j*i <= n; j++ {
				isPrime[j*i] = false
				num[j*i] = num[i] + 1
				if num[j*i] > color {
					color = num[j*i]
				}
			}
		}
	}

	return color, num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	var no int64
	var res []int64
	no, res = seive(n + 1)
	fmt.Println(no)
	for i := 2; i < len(res); i++ {
		fmt.Printf("%d ", res[i])
	}
}

package main

import (
	"fmt"
	"math"
)

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

	if n <= 2 {
		fmt.Println("1")
		for i := 0; i<n; i++ {
			fmt.Print("1 ")
		}
		fmt.Println()
		return
	}

	sqr := int(math.Ceil(math.Sqrt(float64(1+n))))

	not_primes := make([]bool, n+3)

	for p := 2; p <= sqr; p++ {
		if not_primes[p] {
			continue
		}
		max_i := (1+n)/p + 1
		for i := 2; i < max_i; i++ {
			not_primes[p*i] = true
		}
	}

	fmt.Println(2);
	for i := 0; i < n; i++ {
		if not_primes[i+2] {
			fmt.Print("2 ")
		} else {
			fmt.Print("1 ")
		}
	}
	fmt.Println()
}

func main() {
	cacl_colors()
}

package main

import (
	"fmt"
)

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	if n < 3 {
		fmt.Println(1)
		for i := 2; i <= n+1; i++ {
			fmt.Printf("1 ")
		}
		fmt.Println()
		return
	}

	sieve := make([]int, n+2)

	for i := int64(2); i <= int64(n+1); i++ {
		for j := i; j <= int64(n+1); j++ {
			if i*j <= int64(n+1) {
				sieve[int(i*j)] = 1
			} else {
				break
			}
		}
	}

	fmt.Println(2)
	for i := 2; i <= n+1; i++ {
		if sieve[i] == 0 { // Prime
			fmt.Printf("1 ")
		} else { // Composite
			fmt.Printf("2 ")
		}
	}
	fmt.Println()
}

package main

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

const N int = 1e5 + 5

var isPrime [N]bool

func sievePrime(n int) {
	for i := 0; i <= n; i++ {
		isPrime[i] = true
	}
	isPrime[0] = false
	isPrime[1] = false
	for i := 4; i <= n; i += 2 {
		isPrime[i] = false
	}
	for i := 3; i*i <= n; i += 2 {
		if isPrime[i] {
			for j := i * i; j <= n; j += 2 * i {
				isPrime[j] = false
			}
		}
	}
}

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

	sievePrime(100000)

	var n int
	fmt.Fscanf(in, "%d", &n)
	if n <= 2 {
		fmt.Printf("1\n")
	} else {
		fmt.Printf("2\n")
	}

	for val := 2; val <= n+1; val++ {
		if isPrime[val] {
			fmt.Printf("1 ")
		} else {
			fmt.Printf("2 ")
		}
	}
}

package main

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

func solve() {
	n := readInt()
	if n == 1 || n == 2 {
		fmt.Println(1)
	} else {
		fmt.Println(2)
	}
	a := make([]int, n+2)
	for i := 2; i <= n+1; i++ {
		if a[i] == 0 {
			a[i] = 1
			for j := i + i; j <= n+1; j += i {
				a[j] = 2
			}
		}
	}
	var buffer bytes.Buffer
	for i := 2; i <= n+1; i++ {
		if i > 2 {
			buffer.WriteString(" ")
		}
		if a[i] == 2 {
			buffer.WriteString("2")
		} else {
			buffer.WriteString("1")
		}
	}
	fmt.Println(buffer.String())
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func is_prime(n int) bool {
	for i := 2; i * i <= n; i++ {
		if n % i == 0 {
			return false
		}
	}
	return n > 1
}

func solve(n int) {
	if n < 3 {
		fmt.Println("1")
		for i := 1; i <= n; i++ {
			fmt.Printf(" 1")
		}
		fmt.Println("")
	} else {
		fmt.Println("2")
		for i := 2; i <= n + 1; i++ {
			if is_prime(i) {
				fmt.Printf(" 1")
			} else {
				fmt.Printf(" 2")
			}
		}
	}
}

func main() {
	cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	n := cin.nextInt()
	solve(n)
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}

func isSpace(c byte) bool {
	return c < 32 || c == ' ' || c == '\n' || c == '\t'
}

func (p *ParserReader) nextString() string {
	for isSpace(p.c) && p.err == nil {
		p.next()
	}
	r := make([]byte, 0, 1)
	for !isSpace(p.c) && p.err == nil {
		r = append(r, p.c)
		p.next()
	}
	return string(r)
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scanf("%d", &n)
    if n == 1 {
        fmt.Printf("1\n1")
        return
    }
    if n == 2 {
        fmt.Printf("1\n1 1")
        return
    }
    fmt.Println(2)
    l := make([]int, n)
    for i:=0;i<n;i++ {
        if i+2!=2 && (i+2)%2 == 0 {
            l[i] = 2
        } else {
            l[i] = 1 // prime
        }
    }
    upper := int(math.Sqrt(float64(n))) + 1
    for i := 3; i <= upper ;i ++ {
        for j:=0;j<n;j++ {
            if j+2 != i && (j+2)%i == 0 {
                l[j] = 2
            }
        }
    }
    for _, x := range l{
        fmt.Printf("%d ", x)
    }
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	ans := make([]int, N+2)
	mx := 0
	for i := 2; i <= N+1; i++ {
		checked := make([]bool, i+2)
		for j := 2; j*j <= i; j++ {
			if i%j != 0 {
				continue
			}
			checked[ans[i]] = true
		}
		k := 0
		for ; k <= i; k++ {
			if !checked[k] {
				break
			}
		}
		ans[i] = k

	}
	for i := 2; i < len(ans); i++ {
		ans[i]++
		if mx < ans[i] {
			mx = ans[i]
		}
	}
	fmt.Println(mx)
	PrintI(ans[2:]...)

}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

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) 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"
	"errors"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

const (
	BIG = 1024 * 1024 * 10
)

func readLine(r *bufio.Reader) string {
	bytes, _, err := r.ReadLine()
	if err != nil {
		log.Fatalln("Failed to read line")
	}

	return string(bytes)
}

func readInts(r *bufio.Reader) []int {
	elems := strings.Fields(readLine(r))

	ret := make([]int, len(elems))
	for i, el := range elems {
		tmp, err := strconv.ParseInt(el, 10, 64)
		if err != nil {
			log.Fatalf("Failed to parse number %v", el)
		}
		ret[i] = int(tmp)
	}

	return ret
}

type Sieve struct {
	n             int
	first, primes []int
}

type Factor struct {
	Base, Exp int
}

func NewSieve(n int) *Sieve {
	first := make([]int, n+1)
	primes := make([]int, 0)

	for i := 2; i <= n; i++ {
		if first[i] == 0 {
			first[i] = i
			primes = append(primes, i)
		}

		for j := 0; j < len(primes) && primes[j] <= first[i] && i*primes[j] <= n; j++ {
			first[i*primes[j]] = primes[j]
		}
	}

	ret := Sieve{n, first, primes}

	return &ret
}

func (s *Sieve) IsPrime(x int) (bool, error) {
	if s.n < x {
		return false, errors.New(fmt.Sprintf("The largest supported number by this sieve is %v", s.n))
	}
	if x < s.primes[0] || x > s.primes[len(s.primes)-1] {
		return false, nil
	} else if x == s.primes[0] {
		return true, nil
	}
	low, high := 0, len(s.primes)-1
	for high-low > 1 {
		mid := (low + high) / 2
		if s.primes[mid] < x {
			low = mid
		} else {
			high = mid
		}
	}
	return s.primes[high] == x, nil
}

func (s *Sieve) Factors(x int) ([]Factor, error) {
	factors := make([]Factor, 0)

	if s.n < x {
		return factors, errors.New(fmt.Sprintf("The largest supported number by this sieve is %v", s.n))
	}

	for x > 1 {
		pi := s.first[x]
		exp := 0
		for x > 1 && s.first[x] == pi {
			exp += 1
			x /= pi
		}
		factors = append(factors, Factor{pi, exp})
	}

	return factors, nil
}

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, BIG)

	n := readInts(r)[0]
	s := NewSieve(n + 1)
	colors := make([]string, 0)
	cc := 1

	for i := 2; i <= n+1; i++ {
		if isPrime, _ := s.IsPrime(i); isPrime {
			colors = append(colors, "1")
		} else {
			colors = append(colors, "2")
			cc = 2
		}
	}
	fmt.Println(cc)
	fmt.Println(strings.Join(colors, " "))
}

package main

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

func seive(n int64) (int64, []int64) {
	var isPrime []bool = []bool{}
	var i int64
	var j int64
	var num = make([]int64, n+1)
	for i = 0; i <= n; i++ {
		isPrime = append(isPrime, true)
		num[i] = 1
	}
	var color int64 = 1
	for i = 2; i <= (n); i++ {
		for j = 2; j*i <= n; j++ {
			isPrime[j*i] = false
			num[j*i] = num[i] + 1
			if num[j*i] > color {
				color = num[j*i]
			}
		}

	}

	return color, num
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	var no int64
	var res []int64
	no, res = seive(n + 1)
	fmt.Println(no)
	for i := 2; i < len(res); i++ {
		fmt.Printf("%d ", res[i])
	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	if _, err := fmt.Scanf("%d\n", &n); err != nil {
		return
	}

	sieve := make([]int, n+2)

	for i := 2; i <= n+1; i++ {
		for j := i; j <= n+1; j++ {
			if i*j <= n+1 {
				sieve[i*j] = 1
			} else {
				break
			}
		}
	}

	fmt.Println(2)
	for i := 2; i <= n+1; i++ {
		if sieve[i] == 0 { // Prime
			fmt.Printf("1 ")
		} else { // Composite
			fmt.Printf("2 ")
		}
	}
	fmt.Println()
}

package main

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

func solve() {
	n := readInt()
	if n == 1 || n == 2 {
		fmt.Println(1)
	} else {
		fmt.Println(2)
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func is_prime(n int) bool {
	for i := 2; i * i <= n; i++ {
		if n % i == 0 {
			return false
		}
	}
	return n > 1
}

func solve(n int) {
	if n < 3 {
		fmt.Println("1")
		for i := 1; i <= n; i++ {
			fmt.Printf(" 1")
		}
		fmt.Println("")
	} else {
		fmt.Println("2")
		for i := 2; i <= n + 1; i++ {
			if is_prime(i) {
				fmt.Printf(" 1")
			} else {
				fmt.Printf(" 2")
			}
		}
	}
}

func main() {
	f, _ := os.Open("b.in")
	cin := NewParser(bufio.NewReaderSize(f, 1<<16))
	// cin := NewParser(bufio.NewReaderSize(os.Stdin, 1<<16))
	n := cin.nextInt()
	solve(n)
}

// some io

type ParserReader struct {
	r   io.ByteReader
	err error
	c   byte
}

func NewParser(r io.ByteReader) *ParserReader {
	return &ParserReader{r, nil, 0}
}

func (p *ParserReader) next() error {
	p.c, p.err = p.r.ReadByte()
	return p.err
}

func isDigit(c byte) bool {
	return '0' <= c && c <= '9'
}

func (p *ParserReader) nextUInt64() uint64 {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint64
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint64(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextUInt() uint {
	for !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var r uint
	for isDigit(p.c) && p.err == nil {
		r = r*10 + uint(p.c-'0')
		p.next()
	}
	return r
}

func (p *ParserReader) nextInt64() int64 {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int64(p.nextUInt64())
	if sign {
		return -r
	}
	return r
}

func (p *ParserReader) nextInt() int {
	for p.c != '-' && !isDigit(p.c) && p.err == nil {
		p.next()
	}
	var sign bool
	if p.c == '-' {
		sign = true
	}
	r := int(p.nextUInt())
	if sign {
		return -r
	}
	return r
}

func isSpace(c byte) bool {
	return c < 32 || c == ' ' || c == '\n' || c == '\t'
}

func (p *ParserReader) nextString() string {
	for isSpace(p.c) && p.err == nil {
		p.next()
	}
	r := make([]byte, 0, 1)
	for !isSpace(p.c) && p.err == nil {
		r = append(r, p.c)
		p.next()
	}
	return string(r)
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scanf("%d", &n)
    fmt.Println(2)
    l := make([]int, n)
    for i:=0;i<n;i++ {
        if i+2!=2 && (i+2)%2 == 0 {
            l[i] = 2
        } else {
            l[i] = 1 // prime
        }
    }
    upper := int(math.Sqrt(float64(n))) + 1
    for i := 3; i <= upper ;i ++ {
        for j:=0;j<n;j++ {
            if j+2 != i && (j+2)%i == 0 {
                l[j] = 2
            }
        }
    }
    for _, x := range l{
        fmt.Printf("%d ", x)
    }
}

package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	d := make([]int, N+2)
	ans := make([]int, N+2)
	mx := 0
	for i := 2; i <= N+1; i++ {
		ans[i] = d[i] + 1
		for j := i; j <= N+1; j += i {
			d[j]++
			if mx < d[j] {
				mx = d[j]
			}
		}
	}
	fmt.Println(mx)
	PrintI(ans[2:]...)

}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	ans := make([]int, N+2)
	mx := 0
	for i := 2; i <= N+1; i++ {
		for j := 2 * i; j <= N+1; j += i {
			if ans[j] == ans[i] {
				ans[j]++
			}
		}
	}
	for i := 2; i < len(ans); i++ {
		ans[i]++
		if mx < ans[i] {
			mx = ans[i]
		}
	}
	fmt.Println(mx)
	PrintI(ans[2:]...)

}
func PrintI(args ...int) {
	fmt.Println(strings.Join(mapToString(args), " "))
}
func mapToString(arr []int) []string {
	ret := make([]string, len(arr))
	for i := 0; i < len(arr); i++ {
		ret[i] = strconv.Itoa(arr[i])
	}
	return ret
}

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) 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"
	"errors"
	"fmt"
	"log"
	"os"
	"strconv"
	"strings"
)

const (
	BIG = 1024 * 1024 * 10
)

func readLine(r *bufio.Reader) string {
	bytes, _, err := r.ReadLine()
	if err != nil {
		log.Fatalln("Failed to read line")
	}

	return string(bytes)
}

func readInts(r *bufio.Reader) []int {
	elems := strings.Fields(readLine(r))

	ret := make([]int, len(elems))
	for i, el := range elems {
		tmp, err := strconv.ParseInt(el, 10, 64)
		if err != nil {
			log.Fatalf("Failed to parse number %v", el)
		}
		ret[i] = int(tmp)
	}

	return ret
}

type Sieve struct {
	n             int
	first, primes []int
}

type Factor struct {
	Base, Exp int
}

func NewSieve(n int) *Sieve {
	first := make([]int, n+1)
	primes := make([]int, 0)

	for i := 2; i <= n; i++ {
		if first[i] == 0 {
			first[i] = i
			primes = append(primes, i)
		}

		for j := 0; j < len(primes) && primes[j] <= first[i] && i*primes[j] <= n; j++ {
			first[i*primes[j]] = primes[j]
		}
	}

	ret := Sieve{n, first, primes}

	return &ret
}

func (s *Sieve) IsPrime(x int) (bool, error) {
	if s.n < x {
		return false, errors.New(fmt.Sprintf("The largest supported number by this sieve is %v", s.n))
	}
	if x < s.primes[0] || x > s.primes[len(s.primes)-1] {
		return false, nil
	} else if x == s.primes[0] {
		return true, nil
	}
	low, high := 0, len(s.primes)-1
	for high-low > 1 {
		mid := (low + high) / 2
		if s.primes[mid] < x {
			low = mid
		} else {
			high = mid
		}
	}
	return s.primes[high] == x, nil
}

func (s *Sieve) Factors(x int) ([]Factor, error) {
	factors := make([]Factor, 0)

	if s.n < x {
		return factors, errors.New(fmt.Sprintf("The largest supported number by this sieve is %v", s.n))
	}

	for x > 1 {
		pi := s.first[x]
		exp := 0
		for x > 1 && s.first[x] == pi {
			exp += 1
			x /= pi
		}
		factors = append(factors, Factor{pi, exp})
	}

	return factors, nil
}

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

func main() {
	r := bufio.NewReaderSize(os.Stdin, BIG)

	n := readInts(r)[0]
	s := NewSieve(n + 1)
	colors := make([]string, 0)
	cc := 1

	for i := 2; i <= n+1; i++ {
		factors, _ := s.Factors(i)
		color := 1
		for _, factor := range factors {
			color *= factor.Exp
		}
		cc = max(cc, color)
		colors = append(colors, fmt.Sprint(color))
	}
	fmt.Println(cc)
	fmt.Println(strings.Join(colors, " "))
}

package main

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

const (
	BIG = 1024 * 1024 * 10
)

func readLine(r *bufio.Reader) string {
	bytes, _, err := r.ReadLine()
	if err != nil {
		log.Fatalln("Failed to read line")
	}

	return string(bytes)
}

func readInts(r *bufio.Reader) []int {
	elems := strings.Fields(readLine(r))

	ret := make([]int, len(elems))
	for i, el := range elems {
		tmp, err := strconv.ParseInt(el, 10, 64)
		if err != nil {
			log.Fatalf("Failed to parse number %v", el)
		}
		ret[i] = int(tmp)
	}

	return ret
}

type Sieve struct {
	n             int
	first, primes []int
}

type Factor struct {
	Base, Exp int
}

func NewSieve(n int) *Sieve {
	first := make([]int, n+1)
	primes := make([]int, 0)

	for i := 2; i <= n; i++ {
		if first[i] == 0 {
			first[i] = i
			primes = append(primes, i)
		}

		for j := 0; j < len(primes) && primes[j] <= first[i] && i*primes[j] <= n; j++ {
			first[i*primes[j]] = primes[j]
		}
	}

	ret := Sieve{n, first, primes}

	return &ret
}

func (s *Sieve) IsPrime(x int) (bool, error) {
	if s.n < x {
		return false, errors.New(fmt.Sprintf("The largest supported number by this sieve is %v", s.n))
	}
	if x < s.primes[0] || x > s.primes[len(s.primes)-1] {
		return false, nil
	} else if x == s.primes[0] {
		return true, nil
	}
	low, high := 0, len(s.primes)-1
	for high-low > 1 {
		mid := (low + high) / 2
		if s.primes[mid] < x {
			low = mid
		} else {
			high = mid
		}
	}
	return s.primes[high] == x, nil
}

func (s *Sieve) Factors(x int) ([]Factor, error) {
	factors := make([]Factor, 0)

	if s.n < x {
		return factors, errors.New(fmt.Sprintf("The largest supported number by this sieve is %v", s.n))
	}

	for x > 1 {
		pi := s.first[x]
		exp := 0
		for x > 1 && s.first[x] == pi {
			exp += 1
			x /= pi
		}
		factors = append(factors, Factor{pi, exp})
	}

	return factors, nil
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, BIG)

	n := readInts(r)[0]
	s := NewSieve(n + 1)
	colors := make([]string, 0)

	for i := 2; i <= n+1; i++ {
		factors, _ := s.Factors(i)
		color := 1
		for _, factor := range factors {
			color *= factor.Exp
		}
		colors = append(colors, fmt.Sprint(color))
	}
	fmt.Println(strings.Join(colors, " "))
}


This is the hard version of the problem. The difference is that in this version the array contains zeros. You can make hacks only if both versions of the problem are solved.You are given an array $$$[a_1, a_2, \ldots a_n]$$$ consisting of integers $$$-1$$$, $$$0$$$ and $$$1$$$. You have to build a partition of this array into the set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ with the following property:  Denote the alternating sum of all elements of the $$$i$$$-th segment as $$$s_i$$$: $$$s_i$$$ = $$$a_{l_i} - a_{l_i+1} + a_{l_i+2} - a_{l_i+3} + \ldots \pm a_{r_i}$$$. For example, the alternating sum of elements of segment $$$[2, 4]$$$ in array $$$[1, 0, -1, 1, 1]$$$ equals to $$$0 - (-1) + 1 = 2$$$.  The sum of $$$s_i$$$ over all segments of partition should be equal to zero. Note that each $$$s_i$$$ does not have to be equal to zero, this property is about sum of $$$s_i$$$ over all segments of partition.The set of segments $$$[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]$$$ is called a partition of the array $$$a$$$ of length $$$n$$$ if $$$1 = l_1 \le r_1, l_2 \le r_2, \ldots, l_k \le r_k = n$$$ and $$$r_i + 1 = l_{i+1}$$$ for all $$$i = 1, 2, \ldots k-1$$$. In other words, each element of the array must belong to exactly one segment.You have to build a partition of the given array with properties described above or determine that such partition does not exist.Note that it is not required to minimize the number of segments in the partition.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10\,000$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 200\,000$$$) — the length of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i$$$ is $$$-1$$$, $$$0$$$, or $$$1$$$) — the elements of the given array. It's guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$200\,000$$$.

For each test case print an integer $$$k$$$ — the number of segments in the partition. If required partition does not exist, print $$$-1$$$. If partition exists, in the $$$i$$$-th of the following $$$k$$$ lines print two integers $$$l_i$$$ and $$$r_i$$$ — description of the $$$i$$$-th segment. The following conditions should be satisfied:   $$$l_i \le r_i$$$ for each $$$i$$$ from $$$1$$$ to $$$k$$$.  $$$l_{i + 1} = r_i + 1$$$ for each $$$i$$$ from $$$1$$$ to $$$(k - 1)$$$.  $$$l_1 = 1, r_k = n$$$.  If there are multiple correct partitions of the array, print any of them.

NoteIn the first test case we can build a partition of $$$4$$$ segments — each of them will contain only one element of the array equals to $$$0$$$. So the sum will be equal to $$$0 + 0 + 0 + 0 = 0$$$.In the second test case we can build a partition of $$$4$$$ segments. The alternating sum of the first segment will be equal to $$$-1$$$, the alternating sum of the second segment will be equal to $$$1$$$, of the third segment — $$$0 - 1 + 0 = -1$$$, of the fourth segment — $$$1 - 0 = 1$$$. The sum will be equal to $$$-1 + 1 -1 + 1 = 0$$$.In the third test case it can be proved that the required partition does not exist.

package main

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

type seg struct {
	l int
	r int
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n, rsum int
		fmt.Fscan(r, &n)
		a := make([]int, n)

		for i := range a {
			fmt.Fscan(r, &a[i])
			rsum += (2 + a[i]) % 2
		}

		if rsum % 2 == 1 {
			fmt.Fprintln(w, -1)
		} else {
			segc := 0
			segs := make([]seg, n)
			j := 0
			for j < n {
				i := j
				for j < n && a[j] == 0 { j++ }
				if j > i {
					segs[segc] = seg{i+1, j}
					segc++
				}

				k := j + 1
				for k < n && a[k] == 0 { k++ }
				if k < n {
					if ((k-j)%2 == 1 && a[j] == a[k]) || ((k-j)%2 == 0 && a[j] != a[k]) {
						segs[segc] = seg{j+1, k+1}
						segc++
					} else {
						segs[segc] = seg{j+1, j+1}
						segs[segc+1] = seg{j+2, k+1}
						segc += 2
					}
				}
				j = k+1
			}

			fmt.Fprintln(w, segc)
			for j := 0; j < segc; j++ {
				fmt.Fprintln(w, segs[j].l, segs[j].r)
			}
		}
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var epochs int
	fmt.Fscan(r, &epochs)
	for ; epochs > 0; epochs-- {
		var n int
		fmt.Fscan(r, &n)

		nums := make([]int, n)
		// 1 -1 1 0 0 0 1 -1 1 1
		// ~~~~~~
		// ^ non-zero component

		// the position of non-zero component
		// e.g.: [1 3 7 10]
		pos := []int{}

		// the position of the start of segmentation
		// the first element is used to handle the condition
		// that the first component is zero
		// e.g.
		// 0 0 1 -1 0 1 -1
		// x x +  + x +  +
		// the res will become [3, 5]
		// but we need [1, 3, 5, 8]
		// print:
		// 3      <- len(res)-1
		// 1 2    <- res[0] res[1]-1
		// 3 4    <- res[1] res[2]-1
		// 5 7    <- res[3] res[3]-1
		res := []int{-1}

		// scan n numbers (in {-1, 0, 1})
		// from standard input
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &nums[i])
		}

		// if non zero elements is odd -> can not be partitioned
		numOfNonZeroElements := 0

		// decide the non-zero component
		flag := 0 // used to parse zero component or non-zero component
		for i := range nums {
			if nums[i] != 0 {
				numOfNonZeroElements++
				if flag == 0 {
					pos = append(pos, i)
				}
				flag = 1
			} else {
				if flag == 1 {
					pos = append(pos, i-1)
				}
				flag = 0
			}
		}
		if flag == 1 {
			pos = append(pos, len(nums)-1)
		}

		if numOfNonZeroElements&1 == 1 {
			fmt.Fprintln(w, "-1")
			continue
		}

		// initialize 0
		// if the first odd component is 1 set 1, otherwise -1
		detectOddComponent := 0

		for i := 0; i < len(pos)-1; i += 2 {
			// non zero section
			j := pos[i]

			// when the non-zero component is odd
			// handle the first element specially
			// if x, y is in {1, -1}
			// x 1 -1 0 ... 0 0' y 1 -1
			// ^                 ^
			// if x == y
			//   x | 0' | y
			//   + | +  | -
			// else if x != y
			//   x | 0' | y
			//   + | +/-| +
			if (pos[i+1]-pos[i])&1 == 0 {
				if detectOddComponent == 0 {
					res = append(res, j+1)
					detectOddComponent = nums[j]
				} else {
					if detectOddComponent == nums[j] {
						res = append(res, j)
					} else {
						res = append(res, j+1)
					}
					detectOddComponent = 0
				}
				j++
			}

			for ; j <= pos[i+1]; j += 2 {
				if nums[j] == nums[j+1] {
					//  1 |  1
					//  + |  -
					// -1 | -1
					//  + |  -
					res = append(res, j+1)
				} else {
					//  1 | -1
					//  + |  +
					// -1 |  1
					//  + |  +
					res = append(res, j+1, j+2)
				}
			}
		}

		// fix the first element
		if len(res) < 2 || res[1] != 1 {
			res[0] = 1
		} else {
			res = res[1:]
		}
		// fix the last element
		if res[len(res)-1] != n+1 {
			res = append(res, n+1)
		}

		fmt.Fprintln(w, len(res)-1)
		for i := 0; i < len(res)-1; i++ {
			fmt.Fprintln(w, res[i], res[i+1]-1)
		}
	}
}

package main

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

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var epochs int
	fmt.Fscan(r, &epochs)
	for ; epochs > 0; epochs-- {
		var n int
		fmt.Fscan(r, &n)

		nums := make([]int, n)
		// the position of non-zero component
		pos := []int{}

		// the position of the start of segmentation
		// the first element is used to fix the condition
		// that the first component is zero
		res := []int{-1}
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &nums[i])
		}
		numOfNonZeroElements := 0
		flag := 0 // used to parse zero component or non-zero component
		for i := range nums {
			if nums[i] != 0 {
				numOfNonZeroElements++
				if flag == 0 {
					pos = append(pos, i)
				}
				flag = 1
			} else {
				if flag == 1 {
					pos = append(pos, i-1)
				}
				flag = 0
			}
		}
		if flag == 1 {
			pos = append(pos, len(nums)-1)
		}

		if numOfNonZeroElements&1 == 1 {
			fmt.Fprintln(w, "-1")
			continue
		}

		// initialize 0
		// if the first odd component is 1 set 1, otherwise -1
		detectOddComponent := 0

		for i := 0; i < len(pos)-1; i += 2 {
			// non zero section
			j := pos[i]
			for ; j <= pos[i+1]-1; j += 2 {
				if nums[j] == nums[j+1] {
					// 1  1 or -1 -1 use + -
					res = append(res, j+1)
				} else {
					// 1 -1 or -1 1 use + +
					res = append(res, j+1, j+2)
				}
			}

			// if end - start + 1 is odd
			if (pos[i+1]-pos[i])&1 == 0 {
				if detectOddComponent == 0 {
					res = append(res, j+1)
					detectOddComponent = nums[j]
				} else {
					if detectOddComponent == nums[j] {
						res = append(res, j)
					} else {
						res = append(res, j+1)
					}
					detectOddComponent = 0
				}
			}
		}
		// fmt.Println(res)

		// fix the first element
		if len(res) < 2 || res[1] != 1 {
			res[0] = 1
		} else {
			res = res[1:]
		}
		// fix the last element
		if res[len(res)-1] != n+1 {
			res = append(res, n+1)
		}

		fmt.Fprintln(w, len(res)-1)
		for i := 0; i < len(res)-1; i++ {
			fmt.Fprintln(w, res[i], res[i+1]-1)
		}
	}
}


Mihai has an $$$8 \times 8$$$ chessboard whose rows are numbered from $$$1$$$ to $$$8$$$ from top to bottom and whose columns are numbered from $$$1$$$ to $$$8$$$ from left to right.Mihai has placed exactly one bishop on the chessboard. The bishop is not placed on the edges of the board. (In other words, the row and column of the bishop are between $$$2$$$ and $$$7$$$, inclusive.)The bishop attacks in all directions diagonally, and there is no limit to the distance which the bishop can attack. Note that the cell on which the bishop is placed is also considered attacked.     An example of a bishop on a chessboard. The squares it attacks are marked in red. Mihai has marked all squares the bishop attacks, but forgot where the bishop was! Help Mihai find the position of the bishop.

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 36$$$) — the number of test cases. The description of test cases follows. There is an empty line before each test case. Each test case consists of $$$8$$$ lines, each containing $$$8$$$ characters. Each of these characters is either '#' or '.', denoting a square under attack and a square not under attack, respectively.

For each test case, output two integers $$$r$$$ and $$$c$$$ ($$$2 \leq r, c \leq 7$$$) — the row and column of the bishop.  The input is generated in such a way that there is always exactly one possible location of the bishop that is not on the edge of the board.

NoteThe first test case is pictured in the statement. Since the bishop lies in the intersection row $$$4$$$ and column $$$3$$$, the correct output is 4 3.

package main

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

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

func solve() {
	board := make([]string, 8)
	for i := range board {
		fmt.Fscan(r, &board[i])
	}
	for i := 1; i < 7; i++ {
		for j := 1; j < 7; j++ {
			if board[i][j] == '#' && board[i-1][j-1] == '#' && board[i-1][j+1] == '#' && board[i+1][j-1] == '#' && board[i+1][j+1] == '#' {
				fmt.Fprintln(w, i+1, j+1)
			}
		}
	}

}
func main() {
	defer w.Flush()
	var t int
	fmt.Fscan(r, &t)
	for ; t > 0; t-- {
		solve()
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		m := make([]string, 8)
		for i := 0; i < 8; i++ {
			fmt.Fscan(in, &m[i])
		}

		var x, y int
	Loop:
		for i := 1; i < 7; i++ {
			for j := 1; j < 7; j++ {
				if m[i][j] == '#' &&
					m[i-1][j-1] == '#' && m[i-1][j+1] == '#' &&
					m[i+1][j-1] == '#' && m[i+1][j+1] == '#' {
					x, y = i, j
					break Loop
				}
			}
		}
		fmt.Fprintln(out, x+1, y+1)
	}
}

package main

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

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

	var T int
	fmt.Fscan(in, &T)
	for t := 0; t < T; t++ {
		m := make([]string, 8)
		for i := 0; i < 8; i++ {
			fmt.Fscan(in, &m[i])
		}

		g := make([]int, 8)
		for i, s := range m {
			for _, ch := range s {
				if ch == '#' {
					g[i]++
				}
			}
		}

		var r int
		for i := 1; i < 7; i++ {
			if g[i-1] == 2 && g[i] == 1 && g[i+1] == 2 {
				r = i
			}
		}

		var x, y int
		x = r + 1
		for i, ch := range m[r] {
			if ch == '#' {
				y = i + 1
				break
			}
		}
		fmt.Fprintln(out, x, y)
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	var chessborad [8]string
	fmt.Fscan(in, &t)
	for k := 1; k <= t; k++ {
		for i := 0; i < 8; i++ {
			fmt.Fscan(in, &chessborad[i])
		}
	Loop:
		for i := 1; i < 8; i++ {
			for j := 1; j < 8; j++ {
				if chessborad[i][j] == '#' &&
					chessborad[i-1][j-1] == '#' &&
					chessborad[i-1][j+1] == '#' &&
					chessborad[i+1][j-1] == '#' &&
					chessborad[i+1][j+1] == '#' {
					fmt.Println(i+1, j+1)
					break Loop
				}
			}
		}
	}
}

package main

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

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

func slove() {
	board := make([]string, 8)
	ans_i, ans_j := 0, 0
	flag, flag1 := false, false
	for i := range board {
		fmt.Fscan(r, &board[i])
		cnt := 0
		x, y := i, 0
		for j := range board {
			if board[i][j] == '#' {
				cnt++
				y = j
			}
		}
		if cnt == 1 && flag && !flag1 {
			ans_i, ans_j = x, y
			flag1 = true
		} else if cnt == 2{
			flag = true
		}
	}
	fmt.Fprintln(w, ans_i+1, ans_j+1)
}

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

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++{
		board:=make([]string,8)
		for j:=0;j<8;j++{
			fmt.Fscan(in,&board[j])
		}
		// search for #.# ie: board[2],board[4]
		// bishop between these 2 points ie line 3
		// search line 3 for # (x-coordinate)
		var y1,counter int
		for j:=0;j<8;j++{
			for k:=2;k<8;k++{
				if string(board[j][k]) == "#" && string(board[j][k-2]) == "#" {
					counter++
					if counter == 1 {
						y1= j
						goto out
					}
				}
			}
		}
		out:
		for j:=0;j<8;j++{
			if string(board[y1+1][j]) == "#" {
				fmt.Println(y1+2,j+1)
				break
			}
		}
	}
}

package main

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

type Cell struct {
	x int
	y int
}

var (
	reader = bufio.NewReader(os.Stdin)
	t      int
	b      []string
)

func sameDiagonal(v, w Cell) bool {
	return math.Abs(float64(v.x-w.x)) == math.Abs(float64(v.y-w.y))
}

func solve(b []string) string {
	var cells []Cell
	for i := range b {
		for j := range b[i] {
			if b[i][j] == '#' {
				cells = append(cells, Cell{i, j})
			}
		}
	}
	for i := range cells {
		var foundCell = true
		for _, x := range cells {
			if !sameDiagonal(x, cells[i]) {
				foundCell = false
				break
			}
		}
		if foundCell {
			return fmt.Sprintf("%d %d", cells[i].x+1, cells[i].y+1)
		}
	}
	return ""
}

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

package main

import (
	"fmt"
)

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

	for test := 0; test < t; test++ {
		lines := make([]string, 8)

		fmt.Scanln()
		for i := 0; i < 8; i++ {
			fmt.Scanln(&lines[i])
		}

	out:
		for i := 1; i < 7; i++ {
			for j := 1; j < 7; j++ {
				if lines[i][j] == '#' && lines[i-1][j-1] == '#' &&
					lines[i-1][j+1] == '#' && lines[i+1][j-1] == '#' && lines[i+1][j+1] == '#' {
					fmt.Printf("%d %d\n", i+1, j+1)
					break out
				}
			}
		}
	}
}

package main

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

const (
	MaxInt32 = 1 << 31 - 1
)

func main(){
	cin := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(cin, &t)
	board := make([]string, 9)
	for i := 0; i < t; i++ {
		for r := 0; r < 8; r++ {
			fmt.Fscan(cin, &board[r])
		}
		var x, y int
		for r := 1; r < 7; r++ {
			for c := 1; c < 7; c++ {
				if board[r][c] == '#' {
					if board[r-1][c-1] == '#' && board[r-1][c+1] == '#' && board[r+1][c-1] == '#' && board[r+1][c+1] == '#' {
						x = r + 1
						y = c + 1
					}
				}
			}
		}
		fmt.Printf("%d %d\n", x, y)
	}
}

package main

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

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

func (in *CF1692C) 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 *CF1692C) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

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

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

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

/**
Run solve the problem CF1692C
Date: 16/06/22
User: pepradere
URL: https://codeforces.com/problemset/problem/1692/C
Problem: CF1692C
**/
func (in *CF1692C) Run() {
	for t := in.NextInt(); t > 0; t-- {
		in.NextString()
		arr := make([]string, 8)
		for i := 0; i < len(arr); i++ {
			arr[i] = in.NextString()
		}

		for i := 2; i < 8; i++ {
			for j := 2; j < 8; j++ {
				if arr[i-2][j-2] == '#' && arr[i-1][j-1] == '#' && arr[i][j] == '#' && arr[i-2][j] == '#' && arr[i][j-2] == '#' {
					fmt.Println(i, j)
					break
				}
			}
		}

	}
}

func NewCF1692C(r *bufio.Reader) *CF1692C {
	return &CF1692C{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

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

package main

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

func slove() {
	a := make([]string,8)
	for i := 0; i < 8; i++ {
		fmt.Fscan(r, &a[i])
	}

	for i := 1; i + 1< 8; i++ {
		for j := 1; j + 1 < 8; j++ {
			if a[i][j] == '#' && a[i-1][j-1] == '#' && a[i-1][j+1] == '#' && a[i+1][j-1] == '#' && a[i+1][j+1] == '#' {
				fmt.Fprintln(w,i+1,j+1)
				return
			}
		}
	}

}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	var s string

	fmt.Fscan(in, &n)

	// bitsがn個の要素の各パターンを表す
	for i := 0;i < n;i++ {
		list := make([][]int,8)
		for j := 0;j < 8;j++ {
			fmt.Fscan(in, &s)
			arr1 := strings.Split(s, "")
			for p := 0;p < len(arr1);p++ {
				//fmt.Println(arr1[p])
				if arr1[p] == "#"{
					list[j] = append(list[j],p,j)
					if j != 0 && p != 0 {
						if len(list[j-1]) == 4{
							if p-1 == list[j-1][0] && p+1 == list[j-1][2]{
								fmt.Println(j+1,p+1)
							}
						}
					}
				}
			}
		}
	}
}

package main

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

var _, _, _ = main, rw, do

func main() {
	r, w := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer w.Flush()
	rw(r, w)
}

func rw(r io.Reader, w io.Writer) {
	var t int
	fmt.Fscan(r, &t)
	for ti := 0; ti < t; ti++ {
		var a = make([]string, 8)
		for i := 0; i < 8; i++ {
			fmt.Fscan(r, &a[i])
		}
		w1, w2 := do(a)
		fmt.Fprintln(w, w1, w2)
	}
}

var dx = []int{1, 1, -1, -1}
var dy = []int{-1, 1, 1, -1}

func do(a []string) (int, int) {
	for i := 1; i < 7; i++ {
		for j := 1; j < 7; j++ {
			if a[i][j] == '#' {
				ok := true
				for k := 0; k < 4; k++ {
					x := i + dx[k]
					y := j + dy[k]
					if a[x][y] != '#' {
						ok = false
						break
					}
				}
				if ok {
					return i + 1, j + 1
				}
			}
		}
	}
	return 0, 0
}

package main

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

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

	var testCases int
	Fscan(in, &testCases)

	for t := 0; t < testCases; t++ {
		var board [8][8]rune

		for i := 0; i < 8; i++ {
			var s string
			Fscan(in, &s)
			ss := []rune(s)
			for j := 0; j < 8; j++ {
				board[i][j] = ss[j]
			}
		}

		c := rune('#')
		var x, y int
		for i := 1; i < 7; i++ {
			for j := 1; j < 7; j++ {
				if board[i][j] == c &&
					board[i-1][j-1] == c &&
					board[i-1][j+1] == c &&
					board[i+1][j-1] == c &&
					board[i+1][j+1] == c {
					x = i + 1
					y = j + 1
					break

				}
			}
		}
		Fprintln(out, x, y)
	}

}

package main

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

var in, out = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func solve() string {
	var board [8]string
	for i := 0; i < 8; i++ {
		fmt.Fscan(in, &board[i])
	}

	var x, y int

	for i := 1; i < 7; i++ {
		for j := 1; j < 7; j++ {
			if board[i][j] == '#' &&
				board[i-1][j-1] == '#' &&
				board[i+1][j-1] == '#' &&
				board[i-1][j+1] == '#' &&
				board[i+1][j+1] == '#' {
				x, y = i, j
			}
		}
	}

	return fmt.Sprintf("%d %d", x+1, y+1)
}

func main() {
	defer out.Flush()
	var t int
	for fmt.Fscanln(in, &t); t > 0; t-- {
		fmt.Fprintln(out, solve())
	}
}

// util functions
func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

func makeMatrix(n, m int) [][]int {
	x := make([][]int, n)
	for i := range x {
		x[i] = make([]int, m)
	}
	return x
}

package main

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

/*

 */

//goland:noinspection GoUnhandledErrorResult
func solve() {
	scanf("\n")

	n := 8

	tb := make([]string, n)

	for i := range tb {
		scanf("%s\n", &tb[i])
	}

	for r := 1; r < n-1; r++ {
		for c := 1; c < n-1; c++ {
			if tb[r][c] == '#' && tb[r-1][c-1] == '#' && tb[r+1][c+1] == '#' && tb[r+1][c-1] == '#' && tb[r-1][c+1] == '#' {
				fmt.Fprintln(writer, r+1, c+1)
				return
			}
		}
	}
}

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		solve()
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

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

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int64) int64 {
	quot := num / div
	if num%div > 0 {
		quot++
	} else if num%div < 0 {
		quot--
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	return nums[minIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func minIdx(nums ...int) int {
	minNumIdx := 0
	for i, num := range nums {
		if num < nums[minNumIdx] {
			minNumIdx = i
		}
	}

	return minNumIdx
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	return nums[maxIdx(nums...)]
}

//goland:noinspection GoUnusedFunction
func maxIdx(nums ...int) int {
	maxNumIdx := 0
	for i, num := range nums {
		if num > nums[maxNumIdx] {
			maxNumIdx = i
		}
	}

	return maxNumIdx
}

//goland:noinspection GoUnusedFunction
func sum(nums ...int) (sum int) {
	for _, num := range nums {
		sum += num
	}
	return
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int64) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := int64(5); i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

//goland:noinspection GoUnusedFunction
func factorize(num int64) []int64 {
	factors := make([]int64, 0)

	for ftr := int64(2); ftr*ftr <= num; ftr++ {
		for num%ftr == 0 {
			num /= ftr
			factors = append(factors, ftr)
		}
	}

	if num > 1 {
		factors = append(factors, num)
	}

	return factors
}

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 sol() {
	b := make([][]byte, 8)
	for i := 0; i < 8; i++ {
		b[i] = myio.ReadBytes()
	}
	for i := 1; i < 8; i++ {
		for j := 1; j < 8; j++ {
			if b[i][j] == '#' && b[i-1][j-1] == '#' && b[i-1][j+1] == '#' && b[i+1][j-1] == '#' && b[i+1][j+1] == '#' {
				fmt.Println(i+1, j+1)
				return
			}
		}
	}
}

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

package main

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

// https://space.bilibili.com/206214/dynamic
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	dir4 := []struct{ x, y int }{{-1, -1}, {1, 1}, {1, -1}, {-1, 1}}
	solve := func(curCase int) {
		a := make([]string, 8)
		for i := range a {
			Fscan(in, &a[i])
		}
		for i := 1; i < 7; i++ {
			o:for j := 1; j < 7; j++ {

				for _, d := range dir4 {
					x ,y := i,j
					for x >=0&&x<8 && y>=0&&y<8 {
						if a[x][y] == '.' {
							continue o
						}
						x+=d.x
						y+=d.y
					}
				}
				Fprintln(out, i+1,j+1)
				return
			}
		}
	}

	cases := 1
	Fscan(in, &cases)
	for curCase := 1; curCase <= cases; curCase++ {
		solve(curCase)
	}

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

}

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

package main

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

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

func slove() {
	board := make([]string, 8)
	ans_i, ans_j := 0, 0
	flag, flag1 := false, false
	for i := range board {
		fmt.Fscan(r, &board[i])
		cnt := 0
		x, y := i, 0
		for j := range board {
			if board[i][j] == '#' {
				cnt++
				y = j
			}
		}
		if cnt == 1 && flag && !flag1 {
			ans_i, ans_j = x, y
			flag1 = true
		} else {
			flag = true
		}
	}
	fmt.Fprintln(w, ans_i+1, ans_j+1)
}

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


You are given a positive integer $$$D$$$. Let's build the following graph from it:   each vertex is a divisor of $$$D$$$ (not necessarily prime, $$$1$$$ and $$$D$$$ itself are also included);  two vertices $$$x$$$ and $$$y$$$ ($$$x > y$$$) have an undirected edge between them if $$$x$$$ is divisible by $$$y$$$ and $$$\frac x y$$$ is a prime;  the weight of an edge is the number of divisors of $$$x$$$ that are not divisors of $$$y$$$. For example, here is the graph for $$$D=12$$$:   Edge $$$(4,12)$$$ has weight $$$3$$$ because $$$12$$$ has divisors $$$[1,2,3,4,6,12]$$$ and $$$4$$$ has divisors $$$[1,2,4]$$$. Thus, there are $$$3$$$ divisors of $$$12$$$ that are not divisors of $$$4$$$ — $$$[3,6,12]$$$.There is no edge between $$$3$$$ and $$$2$$$ because $$$3$$$ is not divisible by $$$2$$$. There is no edge between $$$12$$$ and $$$3$$$ because $$$\frac{12}{3}=4$$$ is not a prime.Let the length of the path between some vertices $$$v$$$ and $$$u$$$ in the graph be the total weight of edges on it. For example, path $$$[(1, 2), (2, 6), (6, 12), (12, 4), (4, 2), (2, 6)]$$$ has length $$$1+2+2+3+1+2=11$$$. The empty path has length $$$0$$$.So the shortest path between two vertices $$$v$$$ and $$$u$$$ is the path that has the minimal possible length.Two paths $$$a$$$ and $$$b$$$ are different if there is either a different number of edges in them or there is a position $$$i$$$ such that $$$a_i$$$ and $$$b_i$$$ are different edges.You are given $$$q$$$ queries of the following form:   $$$v$$$ $$$u$$$ — calculate the number of the shortest paths between vertices $$$v$$$ and $$$u$$$. The answer for each query might be large so print it modulo $$$998244353$$$.

The first line contains a single integer $$$D$$$ ($$$1 \le D \le 10^{15}$$$) — the number the graph is built from. The second line contains a single integer $$$q$$$ ($$$1 \le q \le 3 \cdot 10^5$$$) — the number of queries. Each of the next $$$q$$$ lines contains two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le D$$$). It is guaranteed that $$$D$$$ is divisible by both $$$v$$$ and $$$u$$$ (both $$$v$$$ and $$$u$$$ are divisors of $$$D$$$).

Print $$$q$$$ integers — for each query output the number of the shortest paths between the two given vertices modulo $$$998244353$$$.

package main

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

const (
	mod = 998244353
)

func gcd(a, b int64) int64 {
	// fmt.Println("gcd", a, b)
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

var (
	r      = map[int64]int64{1: 1}
	p      = []int64{}
	reader = bufio.NewReader(os.Stdin)
)

func f(i int64) int64 {
	// fmt.Println("f", i)
	if _, ok := r[i]; !ok {
		t := i
		for _, j := range p {
			if j > t {
				break
			}
			if i%j == 0 {
				r[i] = (r[i] + f(i/j)) % mod
				for t%j == 0 {
					t /= j
				}
			}
		}
		if r[i] == 0 {
			r[i] = 1
		}
	}
	return r[i]
}

func getInput() int64 {
	res := int64(0)
	var b byte
	for b < '0' || b > '9' {
		b, _ = reader.ReadByte()
	}
	for b >= '0' && b <= '9' {
		res = res*10 + int64(b-'0')
		b, _ = reader.ReadByte()
	}
	return res
}

func main() {
	var n, m int64
	var c int64
	// fmt.Scan(&n, &c)
	n = getInput()
	c = getInput()
	m = n

	if n%2 == 0 {
		p = append(p, 2)
		for n%2 == 0 {
			n /= 2
		}
	}

	j := int64(3)
	for j = int64(3); j*j <= n; j += 2 {
		// fmt.Println(j)
		if n%j == 0 {
			p = append(p, j)
			for n%j == 0 {
				n /= j
			}
		}
	}
	if n > 1 {
		p = append(p, n)
	}
	p = append(p, m)
	// fmt.Println(p)

	var a, b, tmp, g int64
	f(m)

	// fmt.Println(len(r))

	for ; c > 0; c-- {
		a = getInput()
		b = getInput()
		if a < b {
			tmp = a
			a = b
			b = tmp
		}
		g = gcd(a, b)
		a /= g
		b /= g

		fmt.Println(f(a) * f(b) % mod)
	}
	// for k, b := range r {
	// 	fmt.Println(k, b)
	// }
}

package main

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

const (
	mod = 998244353
)

func gcd(a, b int64) int64 {
	// fmt.Println("gcd", a, b)
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

var (
	r      = map[int64]int64{1: 1}
	p      = []int64{}
	reader = bufio.NewReader(os.Stdin)
)

func f(i int64) int64 {
	// fmt.Println("f", i)
	if _, ok := r[i]; !ok {
		t := i
		for _, j := range p {
			if j > t {
				break
			}
			if i%j == 0 {
				r[i] = (r[i] + f(i/j)) % mod
				for t%j == 0 {
					t /= j
				}
			}
		}
		if r[i] == 0 {
			r[i] = 1
		}
	}
	return r[i]
}

func getInput() int64 {
	res := int64(0)
	var b byte
	for b < '0' || b > '9' {
		b, _ = reader.ReadByte()
	}
	for b >= '0' && b <= '9' {
		res = res*10 + int64(b-'0')
		b, _ = reader.ReadByte()
	}
	return res
}

func main() {
	var n, m int64
	var c int64
	// fmt.Scan(&n, &c)
	n = getInput()
	c = getInput()
	m = n

	if n%2 == 0 {
		p = append(p, 2)
		for n%2 == 0 {
			n /= 2
		}
	}

	for j := int64(3); j*j <= n; j += 2 {
		// fmt.Println(j)
		if n%j == 0 {
			p = append(p, j)
			for n%j == 0 {
				n /= j
			}
		}
	}

	p = append(p, m)
	// fmt.Println(p)

	var a, b, tmp, g int64
	f(m)

	// fmt.Println(len(r))

	for ; c > 0; c-- {
		a = getInput()
		b = getInput()
		if a < b {
			tmp = a
			a = b
			b = tmp
		}
		g = gcd(a, b)
		a /= g
		b /= g

		fmt.Println(f(a) * f(b) % mod)
	}
	// for k, b := range r {
	// 	fmt.Println(k, b)
	// }
}

package main

import (
	"bufio"
	"os"
)

const (
	mod = 998244353
)

func gcd(a, b int64) int64 {
	// fmt.Println("gcd", a, b)
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

var (
	r      = map[int64]int64{1: 1}
	p      = []int64{}
	reader = bufio.NewReader(os.Stdin)
)

func f(i int64) int64 {
	// fmt.Println("f", i)
	if _, ok := r[i]; !ok {
		t := i
		for _, j := range p {
			if j > t {
				break
			}
			if i%j == 0 {
				r[i] = (r[i] + f(i/j)) % mod
				for t%j == 0 {
					t /= j
				}
			}
		}
		if r[i] == 0 {
			r[i] = 1
		}
	}
	return r[i]
}

func getInput() int64 {
	res := int64(0)
	var b byte
	for b < '0' || b > '9' {
		b, _ = reader.ReadByte()
	}
	for b >= '0' && b <= '9' {
		res = res*10 + int64(b-'0')
		b, _ = reader.ReadByte()
	}
	return res
}

func main() {
	var n, m int64
	var c int64
	// fmt.Scan(&n, &c)
	n = getInput()
	c = getInput()
	m = n

	for j := int64(2); j <= n; j++ {
		if n%j == 0 {
			p = append(p, j)
			for n%j == 0 {
				n /= j
			}
		}
	}
	// fmt.Println(p)

	var a, b, tmp, g int64
	f(m)

	for ; c > 0; c-- {
		a = getInput()
		b = getInput()
		if a < b {
			tmp = a
			a = b
			b = tmp
		}
		g = gcd(a, b)
		a /= g
		b /= g

		// fmt.Println(f(a) * f(b) % mod)
	}
	// for k, b := range r {
	// 	fmt.Println(k, b)
	// }
}


Alice is visiting New York City. To make the trip fun, Alice will take photos of the city skyline and give the set of photos as a present to Bob. However, she wants to find the set of photos with maximum beauty and she needs your help. There are $$$n$$$ buildings in the city, the $$$i$$$-th of them has positive height $$$h_i$$$. All $$$n$$$ building heights in the city are different. In addition, each building has a beauty value $$$b_i$$$. Note that beauty can be positive or negative, as there are ugly buildings in the city too. A set of photos consists of one or more photos of the buildings in the skyline. Each photo includes one or more buildings in the skyline that form a contiguous segment of indices. Each building needs to be in exactly one photo. This means that if a building does not appear in any photo, or if a building appears in more than one photo, the set of pictures is not valid. The beauty of a photo is equivalent to the beauty $$$b_i$$$ of the shortest building in it. The total beauty of a set of photos is the sum of the beauty of all photos in it. Help Alice to find the maximum beauty a valid set of photos can have.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$), the number of buildings on the skyline.  The second line contains $$$n$$$ distinct integers $$$h_1, h_2, \ldots, h_n$$$ ($$$1 \le h_i \le n$$$). The $$$i$$$-th number represents the height of building $$$i$$$. The third line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$). The $$$i$$$-th number represents the beauty of building $$$i$$$.

Print one number representing the maximum beauty Alice can achieve for a valid set of photos of the skyline.

NoteIn the first example, Alice can achieve maximum beauty by taking five photos, each one containing one building. In the second example, Alice can achieve a maximum beauty of $$$10$$$ by taking four pictures: three just containing one building, on buildings $$$1$$$, $$$2$$$ and $$$5$$$, each photo with beauty $$$-3$$$, $$$4$$$ and $$$7$$$ respectively, and another photo containing building $$$3$$$ and $$$4$$$, with beauty $$$2$$$. In the third example, Alice will just take one picture of the whole city.In the fourth example, Alice can take the following pictures to achieve maximum beauty: photos with just one building on buildings $$$1$$$, $$$2$$$, $$$8$$$, $$$9$$$, and $$$10$$$, and a single photo of buildings $$$3$$$, $$$4$$$, $$$5$$$, $$$6$$$, and $$$7$$$.

package main

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

// github.com/EndlessCheng/codeforces-go
type seg []struct {
	l, r int
	val  int64
}

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

func (t seg) update(o, i int, val int64) {
	if t[o].l == t[o].r {
		t[o].val = val
		return
	}
	m := (t[o].l + t[o].r) >> 1
	if i <= m {
		t.update(o<<1, i, val)
	} else {
		t.update(o<<1|1, i, val)
	}
	t[o].val = max(t[o<<1].val, t[o<<1|1].val)
}

func (t seg) query(o, l, r int) (res int64) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].val
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	return max(t.query(o<<1, l, r), t.query(o<<1|1, l, r))
}

func CF1483C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v int
	Fscan(in, &n)
	posL := make([]int, n)
	type pair struct{ v, i int }
	s := []pair{{0, -1}}
	for i := range posL {
		Fscan(in, &v)
		for s[len(s)-1].v > v {
			s = s[:len(s)-1]
		}
		posL[i] = s[len(s)-1].i
		s = append(s, pair{v, i})
	}

	dp := make([]int64, n)
	t := make(seg, 4*n)
	t.build(1, 1, n)
	for i, l := range posL {
		if Fscan(in, &v); i == 0 {
			dp[i] = int64(v)
		} else if l < 0 {
			dp[i] = max(0, t.query(1, 1, i)) + int64(v)
		} else {
			dp[i] = max(dp[l], t.query(1, l+1, i)+int64(v))
		}
		t.update(1, i+1, dp[i])
	}
	Fprint(out, dp[n-1])
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
type seg []struct {
	l, r int
	val  int64
}

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

func (t seg) update(o, i int, val int64) {
	if t[o].l == t[o].r {
		t[o].val = val
		return
	}
	m := (t[o].l + t[o].r) >> 1
	if i <= m {
		t.update(o<<1, i, val)
	} else {
		t.update(o<<1|1, i, val)
	}
	t[o].val = max(t[o<<1].val, t[o<<1|1].val)
}

func (t seg) query(o, l, r int) (res int64) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].val
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	return max(t.query(o<<1, l, r), t.query(o<<1|1, l, r))
}

func CF1483C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, v int
	Fscan(in, &n)
	posL := make([]int, n)
	type pair struct{ v, i int }
	s := []pair{{0, -1}}
	for i := range posL {
		Fscan(in, &v)
		for s[len(s)-1].v > v {
			s = s[:len(s)-1]
		}
		posL[i] = s[len(s)-1].i
		s = append(s, pair{v, i})
	}

	dp := make([]int64, n)
	t := make(seg, 4*n)
	t.build(1, 1, n)
	Fscan(in, &v)
	dp[0] = int64(v)
	t.update(1, 1, int64(v))
	for i := 1; i < n; i++ {
		Fscan(in, &v)
		if l := posL[i]; l < 0 {
			dp[i] = max(0, t.query(1, 1, i)) + int64(v)
		} else {
			dp[i] = max(dp[l], t.query(1, l+1, i)+int64(v))
		}
		t.update(1, i+1, dp[i])
	}
	Fprint(out, dp[n-1])
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
type seg []struct {
	l, r int
	val  int64
}

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

func (t seg) update(o, i int, val int64) {
	if t[o].l == t[o].r {
		t[o].val = val
		return
	}
	m := (t[o].l + t[o].r) >> 1
	if i <= m {
		t.update(o<<1, i, val)
	} else {
		t.update(o<<1|1, i, val)
	}
	t[o].val = max(t[o<<1].val, t[o<<1|1].val)
}

func (t seg) query(o, l, r int) (res int64) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].val
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	return max(t.query(o<<1, l, r), t.query(o<<1|1, l, r))
}

func CF1483C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n int
	Fscan(in, &n)
	posL := make([]int, n)
	type pair struct{ v, i int }
	s := []pair{{0, -1}}
	h := make([]int, n)
	for i := range h {
		Fscan(in, &h[i])
		for {
			if top := s[len(s)-1]; top.v < h[i] {
				posL[i] = top.i
				break
			}
			s = s[:len(s)-1]
		}
		s = append(s, pair{h[i], i})
	}

	t := make(seg, 4*n)
	t.build(1, 1, n)
	var v int64
	dp := make([]int64, n)
	Fscan(in, &v)
	dp[0] = v
	t.update(1, 1, v)
	for i := 1; i < n; i++ {
		l := posL[i]
		var v int64
		Fscan(in, &v)
		if l < 0 {
			dp[i] = max(0, t.query(1, 1, i)) + v
		} else {
			dp[i] = max(dp[l], t.query(1, l+1, i)+v)
		}
		t.update(1, i+1, dp[i])
	}
	Fprint(out, dp[n-1])
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
type seg []struct {
	l, r int
	val  int64
}

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

func (t seg) update(o, i int, val int64) {
	if t[o].l == t[o].r {
		t[o].val = val
		return
	}
	m := (t[o].l + t[o].r) >> 1
	if i <= m {
		t.update(o<<1, i, val)
	} else {
		t.update(o<<1|1, i, val)
	}
	t[o].val = max(t[o<<1].val, t[o<<1|1].val)
}

func (t seg) query(o, l, r int) (res int64) {
	if l <= t[o].l && t[o].r <= r {
		return t[o].val
	}
	m := (t[o].l + t[o].r) >> 1
	if r <= m {
		return t.query(o<<1, l, r)
	}
	if m < l {
		return t.query(o<<1|1, l, r)
	}
	return max(t.query(o<<1, l, r), t.query(o<<1|1, l, r))
}

func CF1483C(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, miI int
	Fscan(in, &n)
	posL := make([]int, n)
	type pair struct{ v, i int }
	s := []pair{{0, -1}}
	h := make([]int, n)
	for i := range h {
		Fscan(in, &h[i])
		if h[i] < h[miI] {
			miI = i
		}
		for {
			if top := s[len(s)-1]; top.v < h[i] {
				posL[i] = top.i
				break
			}
			s = s[:len(s)-1]
		}
		s = append(s, pair{h[i], i})
	}

	t := make(seg, 4*n)
	t.build(1, 1, n)
	var v int64
	dp := make([]int64, n)
	Fscan(in, &v)
	dp[0] = v
	t.update(1, 1, v)
	for i := 1; i < n; i++ {
		l := posL[i]
		var v int64
		Fscan(in, &v)
		if l < 0 {
			mx := t.query(1, 1, i)
			if mx > 0 {
				v += mx
			}
			dp[i] = v
		} else {
			mx := t.query(1, l+1, i)
			if v > 0 {
				mx += v
			}
			dp[i] = mx
		}
		t.update(1, i+1, dp[i])
	}
	Fprint(out, dp[n-1])
}

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

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


There is a square of size $$$10^6 \times 10^6$$$ on the coordinate plane with four points $$$(0, 0)$$$, $$$(0, 10^6)$$$, $$$(10^6, 0)$$$, and $$$(10^6, 10^6)$$$ as its vertices.You are going to draw segments on the plane. All segments are either horizontal or vertical and intersect with at least one side of the square.Now you are wondering how many pieces this square divides into after drawing all segments. Write a program calculating the number of pieces of the square.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \le n, m \le 10^5$$$) — the number of horizontal segments and the number of vertical segments. The next $$$n$$$ lines contain descriptions of the horizontal segments. The $$$i$$$-th line contains three integers $$$y_i$$$, $$$lx_i$$$ and $$$rx_i$$$ ($$$0 < y_i < 10^6$$$; $$$0 \le lx_i < rx_i \le 10^6$$$), which means the segment connects $$$(lx_i, y_i)$$$ and $$$(rx_i, y_i)$$$. The next $$$m$$$ lines contain descriptions of the vertical segments. The $$$i$$$-th line contains three integers $$$x_i$$$, $$$ly_i$$$ and $$$ry_i$$$ ($$$0 < x_i < 10^6$$$; $$$0 \le ly_i < ry_i \le 10^6$$$), which means the segment connects $$$(x_i, ly_i)$$$ and $$$(x_i, ry_i)$$$. It's guaranteed that there are no two segments on the same line, and each segment intersects with at least one of square's sides.

Print the number of pieces the square is divided into after drawing all the segments.

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()
	const lim = 1_000_000

	n, m := io.NextInt(), io.NextInt()
	a, b := make([][]int, n), make([][]int, m)
	for i := 0; i < n; i++ {
		a[i] = io.NextInts(3)
	}
	for i := 0; i < m; i++ {
		b[i] = io.NextInts(3)
	}

	ans := int64(1)
	add, rem, vseg := make([][]int, lim+1), make([][]int, lim+1), make([][2]int, lim+1)
	for _, h := range a {
		y, x1, x2 := h[0], h[1], h[2]
		if x1 == 0 && x2 == lim {
			ans++
		}
		add[x1] = append(add[x1], y)
		rem[x2] = append(rem[x2], y)
	}
	for _, v := range b {
		x, y1, y2 := v[0], v[1], v[2]
		if y1 == 0 && y2 == lim {
			ans++
		}
		vseg[x] = [2]int{y1, y2}
	}
	upd, qry := Fenwick(lim + 1)
	for i := 0; i < lim; i++ {
		for _, y := range add[i] {
			upd(y, +1)
		}
		if vseg[i][1] != 0 {
			ans += int64(qry(vseg[i][1]) - qry(vseg[i][0]-1))
		}
		for _, y := range rem[i] {
			upd(y, -1)
		}
	}

	fmt.Println(ans)
}

func Fenwick(n int) (upd func(int, int), qry func(int) int) {
	a := make([]int, n+1)
	return func(i, v int) {
			for i++; i < n; i += i & -i {
				a[i] += v
			}
		},
		func(i int) (s int) {
			for i++; i > 0; i -= i & -i {
				s += a[i]
			}
			return
		}
}

type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

package main

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

func main() {
	const lim = 1_000_000
	in := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscan(in, &n, &m)
	a, b := make([][3]int, n), make([][3]int, m)
	for i := 0; i < n; i++ {
		var x, y, z int
		fmt.Fscan(in, &x, &y, &z)
		a[i] = [3]int{x, y, z}
	}
	for i := 0; i < m; i++ {
		var x, y, z int
		fmt.Fscan(in, &x, &y, &z)
		b[i] = [3]int{x, y, z}
	}

	ans := int64(1)
	add, rem, vseg := make([][]int, lim+1), make([][]int, lim+1), make([][2]int, lim+1)
	for _, h := range a {
		y, x1, x2 := h[0], h[1], h[2]
		if x1 == 0 && x2 == lim {
			ans++
		}
		add[x1] = append(add[x1], y)
		rem[x2] = append(rem[x2], y)
	}
	for _, v := range b {
		x, y1, y2 := v[0], v[1], v[2]
		if y1 == 0 && y2 == lim {
			ans++
		}
		vseg[x] = [2]int{y1, y2}
	}
	upd, qry := Fenwick(lim + 1)
	for i := 0; i < lim; i++ {
		for _, y := range add[i] {
			upd(y, +1)
		}
		if vseg[i][1] != 0 {
			ans += int64(qry(vseg[i][1]) - qry(vseg[i][0]-1))
		}
		for _, y := range rem[i] {
			upd(y, -1)
		}
	}

	fmt.Println(ans)
}

func Fenwick(n int) (upd func(int, int), qry func(int) int) {
	a := make([]int, n+1)
	return func(i, v int) {
			for i++; i < n; i += i & -i {
				a[i] += v
			}
		},
		func(i int) (s int) {
			for i++; i > 0; i -= i & -i {
				s += a[i]
			}
			return
		}
}


Pak Chanek has a mirror in the shape of a circle. There are $$$N$$$ lamps on the circumference numbered from $$$1$$$ to $$$N$$$ in clockwise order. The length of the arc from lamp $$$i$$$ to lamp $$$i+1$$$ is $$$D_i$$$ for $$$1 \leq i \leq N-1$$$. Meanwhile, the length of the arc between lamp $$$N$$$ and lamp $$$1$$$ is $$$D_N$$$.Pak Chanek wants to colour the lamps with $$$M$$$ different colours. Each lamp can be coloured with one of the $$$M$$$ colours. However, there cannot be three different lamps such that the colours of the three lamps are the same and the triangle made by considering the three lamps as vertices is a right triangle (triangle with one of its angles being exactly $$$90$$$ degrees).The following are examples of lamp colouring configurations on the circular mirror. Figure 1. an example of an incorrect colouring because lamps $$$1$$$, $$$2$$$, and $$$3$$$ form a right triangleFigure 2. an example of a correct colouringFigure 3. an example of a correct colouring Before colouring the lamps, Pak Chanek wants to know the number of distinct colouring configurations he can make. Count the number of distinct possible lamp colouring configurations, modulo $$$998\,244\,353$$$.

The first line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \le N \le 3 \cdot 10^5$$$, $$$2 \le M \le 3 \cdot 10^5$$$) — the number of lamps in the mirror and the number of different colours used. The second line contains $$$N$$$ integers $$$D_1, D_2, \ldots, D_N$$$ ($$$1 \le D_i \le 10^9$$$) — the lengths of the arcs between the lamps in the mirror.

An integer representing the number of possible lamp colouring configurations, modulo $$$998\,244\,353$$$.

package main

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

func mpow(base, power, mod int) int {
	if base == 0 { return 0 }
	if base == 1 { return 1 }
	if power == 1 { return base % mod }
	res := mpow(base, power >> 1, mod)
	res = (res*res) % mod
	if power&1 == 1 { res = (res*base) % mod }
	return res
}

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

	var n, m int
	fmt.Fscan(r, &n, &m)

	d := make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &d[i+1])
		d[i+1] += d[i]
	}

	dm_pairs := 0
	l := 1
	for r := 1; r < n + 1; r++ {
		// fmt.Fprintln(w, "ffff ", d, l, r, dm_pairs)
		for d[r] -d [l] > d[n]/2 && l < r {
			l++
			// fmt.Fprintln(w, "iiii ", d, l, r, dm_pairs)
		}
		if 2*(d[r] - d[l]) == d[n] { dm_pairs++ }
	}
	if dm_pairs > m { dm_pairs = m }

	mod := 998244353
	res := 0
	t1 := make([]int, dm_pairs+1)

	// fmt.Fprintln(w, "rrrr ", n, m, dm_pairs)
	for i := 0; i <= dm_pairs; i++ {
		t1[i] = 1
		if i > 0 {
			t1[i] = (t1[i] * t1[i-1]) % mod
			t1[i] = (t1[i] * mpow(i, mod-2, mod)) % mod
			t1[i] = (t1[i] * (((dm_pairs-i+1)*(m-i+1))%mod)) % mod
		}
		temp := t1[i]
		// fmt.Fprintln(w, "1111 ", i, temp)
		if i < dm_pairs {
			temp = (temp*mpow(((m-i)*(m-i-1))%mod, dm_pairs-i, mod))%mod
		}
		// fmt.Fprintln(w, "2222 ", i, temp)
		if n > 2*dm_pairs {
			temp = (temp*mpow(m-i, n-2*dm_pairs, mod))%mod
		}
		// fmt.Fprintln(w, "3333 ", i, temp)
		res = (res + temp) % mod
	}

	fmt.Fprintln(w, res)
}

package main

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

func mpow(base, power, mod int) int {
	if base == 0 { return 0 }
	if power == 0 || base == 1 { return 1 }
	if power == 1 { return base % mod }
	res := (mpow(base, power >> 1, mod) << 1) % mod
	if power%2 == 1 { res = (res*base) % mod }
	return res
}

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

	var n, m int
	fmt.Fscan(r, &n, &m)

	d := make([]int, n + 1)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &d[i+1])
		d[i+1] += d[i]
	}

	dm_pairs := 0
	l := 1
	for r := 1; r < n + 1; r++ {
		// fmt.Fprintln(w, "ffff ", d, l, r, dm_pairs)
		for d[r] -d [l] > d[n]/2 && l < r {
			l++
			// fmt.Fprintln(w, "iiii ", d, l, r, dm_pairs)
		}
		if 2*(d[r] - d[l]) == d[n] { dm_pairs++ }
	}
	if dm_pairs > m { dm_pairs = m }

	mod := 998244353
	res := 0
	t1 := make([]int, dm_pairs+1)

	// fmt.Fprintln(w, "rrrr ", n, m, dm_pairs)
	for i := 0; i <= dm_pairs; i++ {
		t1[i] = 1
		if i > 0 {
			t1[i] = (((dm_pairs-i+1)*(m-i+1))%mod * mpow(i, mod-2, mod) * t1[i-1])%mod
		}
		temp := t1[i]
		// fmt.Fprintln(w, "1111 ", i, temp)
		if i < dm_pairs {
			temp = (temp*mpow(((m-i)*(m-i-1))%mod, dm_pairs-i, mod))%mod
		}
		// fmt.Fprintln(w, "2222 ", i, temp)
		if n > 2*dm_pairs {
			temp = (temp*mpow(m-i, n-2*dm_pairs, mod))%mod
		}
		// fmt.Fprintln(w, "3333 ", i, temp)
		res = (res + temp) % mod
	}

	fmt.Fprintln(w, res)
}