Two soldiers are playing a game. At the beginning first of them chooses a positive integer n and gives it to the second soldier. Then the second one tries to make maximum possible number of rounds. Each round consists of choosing a positive integer x > 1, such that n is divisible by x and replacing n with n / x. When n becomes equal to 1 and there is no more possible valid moves the game is over and the score of the second soldier is equal to the number of rounds he performed.To make the game more interesting, first soldier chooses n of form a! / b! for some positive integer a and b (a ≥ b). Here by k! we denote the factorial of k that is defined as a product of all positive integers not large than k.What is the maximum possible score of the second soldier?

First line of input consists of single integer t (1 ≤ t ≤ 1 000 000) denoting number of games soldiers play. Then follow t lines, each contains pair of integers a and b (1 ≤ b ≤ a ≤ 5 000 000) defining the value of n for a game.

For each game output a maximum score that the second soldier can get.

package main

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

var primes = make([]int, 0, 300)

func init() {
	b := make([]bool, 2238)
	primes = append(primes, 2)
	for i := 3; i < 2238; i += 2 {
		if b[i] {
			continue
		}
		primes = append(primes, i)
		for j := 2 * i; j < 2238; j += i {
			b[i] = true
		}
	}
}

var in = bufio.NewScanner(os.Stdin)

func readInt() int {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int(0)
	for _, b := range in.Bytes() {
		res = res*10 + int(b-'0')
	}
	return res
}

func main() {
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(os.Stdout)

	facts := make([]int, 5000001)
	for i := 2; i < len(facts); i++ {
		for _, p := range primes {
			if p*p > i {
				facts[i] = 1
				break
			}
			if i%p == 0 {
				facts[i] = facts[i/p] + 1
				break
			}
		}
		if facts[i] == 0 {
			panic(i)
		}
	}
	for i := range facts[1:] {
		facts[i+1] += facts[i]
	}
	t := readInt()
	for i := 0; i < t; i++ {
		a, b := readInt(), readInt()
		fmt.Fprintln(out, facts[a]-facts[b])
	}
	defer out.Flush()
}

package main

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

var (
	p int
	ibuf []byte
)

func IsSpace(b byte) bool {
	switch b {
	case ' ', '\t', '\n', '\r':
		return true
	default:
		return false
	}
}

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
	}
	buf := make([]byte, 0)
	for ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
		buf = append(buf, ibuf[p])
	}
	return string(buf)
}

func ReadInt() int {
	for ; p < len(ibuf) && !IsDigit(ibuf[p]); p++ {
	}
	d := 0
	for ; p < len(ibuf) && IsDigit(ibuf[p]); p++ {
		d = 10 * d + int(ibuf[p] - '0')
	}
	return d
}

func ReadInt64() int64 {
	for ; p < len(ibuf) && !IsDigit(ibuf[p]); p++ {
	}
	d := int64(0)
	for ; p < len(ibuf) && IsDigit(ibuf[p]); p++ {
		d = int64(10) * d + int64(ibuf[p] - '0')
	}
	return d
}

const (
	L = 16 * 1000000 + 30
	V = 5000001
)

var (
	n, a, b int
	obuf []byte
	ds [V]int
	fs [V]int
	ct [V]int
)

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
	obuf = make([]byte, 0, L)

	for i := 0; i < V; i++ {
		ds[i] = 0
	}
	for i := 2; i < V; i++ {
		if ds[i] == 0 {
			for j := i; j < V; j += i {
				ds[j] = i
			}
		}
	}
	for i := 2; i < V; i++ {
		fs[i] = 0
		for v := i; v > 1; v /= ds[v] {
			fs[i]++
		}
	}

	for i := 2; i < V; i++ {
		ct[i] = ct[i - 1] + fs[i]
	}
}

func main() {
	for t := ReadInt(); t > 0; t-- {
		a = ReadInt()
		b = ReadInt()
		obuf = strconv.AppendInt(obuf, int64(ct[a] - ct[b]), 10);
		obuf = append(obuf, '\n')
	}
	os.Stdout.Write(obuf)
}

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)

	t := nextInt()
	a, b := 0, 0
	const MAXN = 5000001
	sumFac := make([]int, MAXN)
	cntFactors := make([]int, MAXN)
	sumFac[1] = 1

	for i := 2; i < MAXN; i++ {
		if cntFactors[i] == 0 {
			cntFactors[i] = 1
			for j := i + i; j < MAXN; j = j + i {
				x := j

				for x%i == 0 {
					x /= i
					cntFactors[j]++
				}
			}
		}

		sumFac[i] = cntFactors[i] + sumFac[i-1]
	}

	// println(cntFactors)
	// println(sumFac)
	// println(cntFactors)
	// _, _, _ = sumFac, a, b
	for ; t > 0; t-- {
		a, b = nextInt(), nextInt()

		println(sumFac[a] - sumFac[b])
	}
}

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"
	"io"
	"os"
	"unicode/utf8"
)

func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	panic(r)
}

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	warp := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// Skip leading spaces.
		start := 0
		for width := 0; start < len(data); start += width {
			var r rune
			r, width = utf8.DecodeRune(data[start:])
			if !isSpace(r) {
				break
			}
		}
		// Scan until space, marking end of word.
		for width, i := 0, start; i < len(data); i += width {
			var r rune
			r, width = utf8.DecodeRune(data[i:])
			if isSpace(r) {
				return i + width, data[start:i], nil
			}
		}
		// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
		if atEOF && len(data) > start {
			return len(data), data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(warp)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	warp := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// Skip leading spaces.
		start := 0
		for ; start < len(data); start++ {
			if r := data[start]; r != ' ' && r != '\n' && r != '\r' {
				break
			}
		}
		// Scan until space, marking end of word.
		for i := start; i < len(data); i++ {
			if r := data[i]; r == ' ' || r == '\n' || r == '\r' {
				return i + 1, data[start:i], nil
			}
		}
		// If we're at EOF and have a non-empty, non-terminated word. Return it.
		if atEOF && len(data) > start {
			return len(data), data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(warp)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"unicode/utf8"
)

func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	warp := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// Skip leading spaces.
		start := 0
		for width := 0; start < len(data); start += width {
			var r rune
			r, width = utf8.DecodeRune(data[start:])
			if !isSpace(r) {
				break
			}
		}
		// Scan until space, marking end of word.
		for width, i := 0, start; i < len(data); i += width {
			var r rune
			r, width = utf8.DecodeRune(data[i:])
			if isSpace(r) {
				return i + width, data[start:i], nil
			}
		}
		// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
		if atEOF && len(data) > start {
			return len(data), data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(warp)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"unicode/utf8"
)

func isSpace(r rune) bool {
	// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
	switch r {
	case ' ', '\n', '\r':
		return true
	case '\u0085', '\u00A0':
		return true
	}
	return false
}

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	warp := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// Skip leading spaces.
		start := 0
		for width := 0; start < len(data); start += width {
			var r rune
			r, width = utf8.DecodeRune(data[start:])
			if !isSpace(r) {
				break
			}
		}
		// Scan until space, marking end of word.
		for width, i := 0, start; i < len(data); i += width {
			var r rune
			r, width = utf8.DecodeRune(data[i:])
			if isSpace(r) {
				return i + width, data[start:i], nil
			}
		}
		// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
		if atEOF && len(data) > start {
			return len(data), data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(warp)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Buffer(make([]byte, 2e7), 1e9)
	scanToken := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		n := len(data)
		// Skip leading spaces.
		start := 0
		for ; start < n; start++ {
			if r := data[start]; r != ' ' && r != '\n' && r != '\r' {
				break
			}
		}
		// Scan until space, marking end of word.
		for i := start; i < n; i++ {
			if r := data[i]; r == ' ' || r == '\n' || r == '\r' {
				return i + 1, data[start:i], nil
			}
		}
		// If we're at EOF and have a non-empty, non-terminated word. Return it.
		if atEOF && start < n {
			return len(data), data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(scanToken)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

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

func isSpace(r byte) bool {
	switch r {
	case ' ', '\n', '\r':
		return true
	}
	return false
}

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	warp := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// Skip leading spaces.
		start := 0
		for ; start < len(data); start++ {
			if r := data[start]; !isSpace(r) {
				break
			}
		}
		// Scan until space, marking end of word.
		for i := start; i < len(data); i++ {
			if r := data[i]; isSpace(r) {
				return i + 1, data[start:i], nil
			}
		}
		// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
		if atEOF && len(data) > start {
			return len(data), data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(warp)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n := 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for n := read(); n > 0; n-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

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

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

	n := 5000000
	count := make([]int, n+1)
	left := make([]int, n+1)
	for i := range left {
		left[i] = i
	}
	i := 2
	for ; i*i <= n; i++ {
		if count[i] == 0 {
			for j := i; j <= n; j += i {
				count[j]++
				left[j] /= i
			}
		} else if left[i] > 1 {
			count[i] += count[left[i]]
		}
	}
	for ; i <= n; i++ {
		if count[i] == 0 {
			count[i] = 1
		} else if left[i] > 1 {
			count[i] += count[left[i]]
		}
	}
	sum := make([]int, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = sum[i-1] + count[i]
	}

	for Fscan(in, &n); n > 0; n-- {
		var a, b int
		Fscan(in, &a, &b)
		Fprintln(out, sum[a]-sum[b])
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	in.Split(bufio.ScanWords)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	n := 5000000
	count := make([]int, n+1)
	left := make([]int, n+1)
	for i := range left {
		left[i] = i
	}
	i := 2
	for ; i*i <= n; i++ {
		if count[i] == 0 {
			for j := i; j <= n; j += i {
				count[j]++
				left[j] /= i
			}
		} else if left[i] > 1 {
			count[i] += count[left[i]]
		}
	}
	for ; i <= n; i++ {
		if count[i] == 0 {
			count[i] = 1
		} else if left[i] > 1 {
			count[i] += count[left[i]]
		}
	}
	sum := make([]int, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = sum[i-1] + count[i]
	}
	for n := read(); n > 0; n-- {
		Fprintln(out, sum[read()]-sum[read()])
	}
}

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

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []uint64 {
	var m uint64
	m = 5*1000000
	s := make([]uint64,m+1)
	var tot uint64
	tot = 0
	var pt uint64
	for pt=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		var pte uint64
		pte = pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	pfx := gen_sieve2()
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
	}
	return
}

package main

import (
	"os"
	"unicode"
)

const (
	L = 16 * 1000000 + 30
	V = 5000001
)

var (
	n, a, b int
	p int = 0
	ibuf []byte
	obuf []byte
	dbuf [10]byte
	ds [V]int
	fs [V]int
	ct [V]int
)

func init() {
	for i := 0; i < V; i++ {
		ds[i] = 0
	}
	for i := 2; i < V; i++ {
		if ds[i] == 0 {
			x := 1
			for j := i; j < V; j += i {
				ds[j] = i
				x++
			}
		}
	}
	for i := 2; i < V; i++ {
		fs[i] = 0
		for v := i; v > 1; v /= ds[v] {
			fs[i]++
		}
	}

	for i := 2; i < V; i++ {
		ct[i] = ct[i - 1] + fs[i]
	}
}

func readInt() int {
	for ;p < n && (unicode.IsSpace(rune(ibuf[p]))); p++ {

	}
	d := 0
	for ;p < n && '0' <= ibuf[p] && ibuf[p] <= '9'; p++ {
		d = 10 * d + int(ibuf[p]) - '0'
	}
	return d
}

func writeInt(d int)  {
	if d == 0 {
		obuf = append(obuf, '0')
		obuf = append(obuf, '\n')
	}
	q := 0
	for d > 0 {
		dbuf[q] = byte(d % 10 + '0')
		d /= 10
		q++
	}
	for i := 0; i < q; i++ {
		obuf = append(obuf, dbuf[i])
	}
	obuf = append(obuf, '\n')
}

func main() {
	ibuf = make([]byte, L, L)
	obuf = make([]byte, 0, L)
	n, _ = os.Stdin.Read(ibuf)
	for t := readInt(); t > 0; t-- {
		a = readInt()
		b = readInt()
		writeInt(ct[a] - ct[b]);
	}
	os.Stdout.Write(obuf)
}

package main

import (
	"os"
	"unicode"
)

const (
	L = 16 * 1000000 + 30
	V = 5000001
)

var (
	n, a, b int
	p int = 0
	ibuf []byte
	obuf []byte
	dbuf [10]byte
	ds [V]int
	fs [V]int
	ct [V]int
)

func init() {
	for i := 0; i < V; i++ {
		ds[i] = 0
	}
	for i := 2; i < V; i++ {
		if ds[i] == 0 {
			x := 1
			for j := i; j < V; j += i {
				ds[j] = i
				x++
			}
		}
	}
	for i := 2; i < V; i++ {
		fs[i] = 0
		for v := i; v > 1; v /= ds[v] {
			fs[i]++
		}
	}

	for i := 2; i < V; i++ {
		ct[i] = ct[i - 1] + fs[i]
	}
}

func readInt() int {
	for ;p < n && (unicode.IsSpace(rune(ibuf[p]))); p++ {

	}
	d := 0
	for ;p < n && '0' <= ibuf[p] && ibuf[p] <= '9'; p++ {
		d = 10 * d + int(ibuf[p]) - '0'
	}
	return d
}

func writeInt(d int)  {
	q := 0
	for d > 0 {
		dbuf[q] = byte(d % 10 + '0')
		d /= 10
		q++
	}
	for i := 0; i < q; i++ {
		obuf = append(obuf, dbuf[i])
	}
	obuf = append(obuf, '\n')
}

func main() {
	ibuf = make([]byte, L, L)
	obuf = make([]byte, 0, L)
	n, _ = os.Stdin.Read(ibuf)
	for t := readInt(); t > 0; t-- {
		a = readInt()
		b = readInt()
		writeInt(ct[a] - ct[b]);
	}
	os.Stdout.Write(obuf)
}

package main

import (
	"os"
	"unicode"
)

const (
	L = 16 * 1000000 + 30
	V = 5000001
)

var (
	n, a, b int
	p int = 0
	ibuf []byte
	obuf []byte
	dbuf [10]byte
	ds [V]int
	fs [V]int
	ct [V]int
)

func init() {
	for i := 0; i < V; i++ {
		ds[i] = 0
	}
	for i := 2; i < V; i++ {
		if ds[i] == 0 {
			x := 1
			for j := i; j < V; j += i {
				ds[j] = i
				x++
			}
		}
	}
	for i := 2; i < V; i++ {
		fs[i] = 0
		for v := i; v > 1; v /= ds[v] {
			fs[i]++
		}
	}

	for i := 2; i < V; i++ {
		ct[i] = ct[i - 1] + fs[i]
	}
}

func readInt() int {
	for ;p < n && (unicode.IsSpace(rune(ibuf[p]))); p++ {

	}
	d := 0
	for ;p < n && '0' <= ibuf[p] && ibuf[p] <= '9'; p++ {
		d = 10 * d + int(ibuf[p]) - '0'
	}
	return d
}

func writeInt(d int)  {
	if d == 0 {
		obuf = append(obuf, '0')
		obuf = append(obuf, '\n')
		return
	}
	q := 0
	for d > 0 {
		dbuf[q] = byte(d % 10 + '0')
		d /= 10
		q++
	}
	for i := q - 1; i >= 0; i-- {
		obuf = append(obuf, dbuf[i])
	}
	obuf = append(obuf, '\n')
}

func main() {
	ibuf = make([]byte, L, L)
	obuf = make([]byte, 0, L)
	n, _ = os.Stdin.Read(ibuf)
	for t := readInt(); t > 0; t-- {
		a = readInt()
		b = readInt()
		writeInt(ct[a] - ct[b]);
	}
	os.Stdout.Write(obuf)
}

package main

import (
	"fmt"
	"os"
)

const (
	L = 16 * 1000000 + 30
	V = 5000001
)

var (
	n, a, b int
	p int = 0
	buf []byte
	ds [V]int
	fs [V]int
	ct [V]int
)

func init() {
	for i := 0; i < V; i++ {
		ds[i] = 0
	}
	for i := 2; i < V; i++ {
		if ds[i] == 0 {
			x := 1
			for j := i; j < V; j += i {
				ds[j] = i
				x++
			}
		}
	}
	for i := 2; i < V; i++ {
		fs[i] = 0
		for v := i; v > 1; v /= ds[v] {
			fs[i]++
		}
	}

	for i := 2; i < V; i++ {
		ct[i] = ct[i - 1] + fs[i]
	}
}

func readInt() int {
	for ;p < n && (buf[p] == ' ' || buf[p] == '\n'); p++ {

	}
	d := 0
	for ;p < n && '0' <= buf[p] && buf[p] <= '9'; p++ {
		d = 10 * d + int(buf[p]) - '0'
	}
	return d
}

func main() {
	buf = make([]byte, L, L)
	n, _ = os.Stdin.Read(buf)
	for t := readInt(); t > 0; t-- {
		a = readInt()
		b = readInt()
		fmt.Printf("%d\n", ct[a] - ct[b]);
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	warp := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// Skip leading spaces.
		n := len(data)
		start := 0
		for ; start < n; start++ {
			if r := data[start]; r != ' ' && r != '\n' {
				break
			}
		}
		// Scan until space, marking end of word.
		for i := start; i < n; i++ {
			if r := data[i]; r == ' ' || r == '\n' {
				return i + 1, data[start:i], nil
			}
		}
		// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
		if atEOF && n > start {
			return n, data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(warp)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"unicode/utf8"
)

func isSpace(r rune) bool {
	// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
	switch r {
	case ' ', '\n':
		return true
	case '\u0085', '\u00A0':
		return true
	}
	return false
}

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	warp := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// Skip leading spaces.
		start := 0
		for width := 0; start < len(data); start += width {
			var r rune
			r, width = utf8.DecodeRune(data[start:])
			if !isSpace(r) {
				break
			}
		}
		// Scan until space, marking end of word.
		for width, i := 0, start; i < len(data); i += width {
			var r rune
			r, width = utf8.DecodeRune(data[i:])
			if isSpace(r) {
				return i + width, data[start:i], nil
			}
		}
		// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
		if atEOF && len(data) > start {
			return len(data), data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(warp)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

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

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

	n := 5000000
	count := make([]int, n+1)
	left := make([]int, n+1)
	for i := range left {
		left[i] = i
	}
	i := 2
	for ; i*i <= n; i++ {
		if count[i] == 0 {
			for j := i; j <= n; j += i {
				count[j] = 1
				left[j] /= i
			}
		} else if left[i] > 1 {
			count[i] += count[left[i]]
		}
	}
	for ; i <= n; i++ {
		if count[i] == 0 {
			count[i] = 1
		} else if left[i] > 1 {
			count[i] += count[left[i]]
		}
	}
	sum := make([]int, n+1)
	for i := 1; i <= n; i++ {
		sum[i] = sum[i-1] + count[i]
	}

	for Fscan(in, &n); n > 0; n-- {
		var a, b int
		Fscan(in, &a, &b)
		Fprintln(out, sum[a]-sum[b])
	}
}

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

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"unicode/utf8"
)

func isSpace(r rune) bool {
	return r == ' ' || r == '\n'
}

// github.com/EndlessCheng/codeforces-go
func Sol546D(reader io.Reader, writer io.Writer) {
	in := bufio.NewScanner(reader)
	warp := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// Skip leading spaces.
		start := 0
		for width := 0; start < len(data); start += width {
			var r rune
			r, width = utf8.DecodeRune(data[start:])
			if !isSpace(r) {
				break
			}
		}
		// Scan until space, marking end of word.
		for width, i := 0, start; i < len(data); i += width {
			var r rune
			r, width = utf8.DecodeRune(data[i:])
			if isSpace(r) {
				return i + width, data[start:i], nil
			}
		}
		// If we're at EOF and we have a non-empty, non-terminated word. Return it.
		if atEOF && len(data) > start {
			return len(data), data[start:], nil
		}
		// Request more data.
		return start, nil, nil
	}
	in.Split(warp)
	_ = bufio.ScanWords
	out := bufio.NewWriter(writer)
	defer out.Flush()
	read := func() (x int) {
		in.Scan()
		for _, b := range in.Bytes() {
			x = x*10 + int(b-'0')
		}
		return
	}

	const n = 5000000
	cnt := make([]int, n+1)
	primes := make([]int, 0, 348513)
	for i := 2; i <= n; i++ {
		if cnt[i] == 0 {
			primes = append(primes, i)
			cnt[i] = 1
		}
		for _, p := range primes {
			if j := i * p; j <= n {
				cnt[j] = cnt[i] + 1
			} else {
				break
			}
		}
	}
	for i := 3; i <= n; i++ {
		cnt[i] += cnt[i-1]
	}
	for q := read(); q > 0; q-- {
		Fprintln(out, cnt[read()]-cnt[read()])
	}
}

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

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==1291 {
			break
		}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for pte<=m {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]+2))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	// pfx := gen_sieve2()
	pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		//ab = ab
		//as := strings.TrimSpace(ab[0])
		//fmt.Print(as)
		//a,_ := strconv.Atoi(as)
		//fmt.Print(a)
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		//fmt.Print(b)
		//b := 0
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		//a,b := 0,0
		//fmt.Print(pfx[a]-pfx[b])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	stdin := bufio.NewReader(os.Stdin)
	// stdout := bufio.NewWriter(os.Stdout)
	// defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	// pfx := gen_sieve2()
	pfx := [3]int{1,2,3}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		//ab = ab
		as := strings.TrimSpace(ab[0])
		fmt.Print(as)
		//a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		//b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		a,b := 0,0
		//stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		//a,b := 0,0
		fmt.Print(pfx[a]-pfx[b])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	// defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	// pfx := gen_sieve2()
	pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		//ab = ab
		//as := strings.TrimSpace(ab[0])
		//fmt.Print(as)
		//a,_ := strconv.Atoi(as)
		//fmt.Print(a)
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		//fmt.Print(b)
		//b := 0
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		//a,b := 0,0
		//fmt.Print(pfx[a]-pfx[b])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==1290 {
			break
		}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for pte<=m {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]+2))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==1275 {
			break
		}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for pte<=m {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]+2))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==1292 {  // 1292 fails, 1291 ok.
			break
		}
		//if pt==1291 {
		//	fmt.Print(pt," ",s[pt])
		//}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for (pte>=pt && pte<=m) {
				//if pt==1291 {
				//	fmt.Print("pte",pte)
				//}
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]+2))
	}
	return
}

package main

import "fmt"
//import "os"
//import "bufio"
//import "strconv"
//import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	//stdin := bufio.NewReader(os.Stdin)
	//stdout := bufio.NewWriter(os.Stdout)
	//defer stdout.Flush()
	//s,_ := stdin.ReadString('\n')
	//t,_ := strconv.Atoi(strings.TrimSpace(s))
	t := 1000000
	// pfx := gen_sieve2()
	pfx := [3]int{1,2,3}
	for ti:=0;ti<t;ti++ {
		//s,_ := stdin.ReadString('\n')
		//ab := strings.Split(s," ")
		//a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		//b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		//stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		fmt.Print(pfx[2]-pfx[0])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	stdin := bufio.NewReader(os.Stdin)
	// stdout := bufio.NewWriter(os.Stdout)
	// defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	// pfx := gen_sieve2()
	pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		//ab = ab
		as := strings.TrimSpace(ab[0])
		fmt.Print(as)
		a,_ := strconv.Atoi(as)
		fmt.Print(a)
		//a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		fmt.Print(b)
		//b := 0
		//stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		//a,b := 0,0
		fmt.Print(pfx[a]-pfx[b])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==2 {
			break
		}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for pte<=m {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==1287 {
			break
		}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for pte<=m {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]+2))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==1000 {
			break
		}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for pte<=m {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]+2))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for (pte>pt && pte<=m) {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for (pte>=pt && pte<=m) {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	pfx := gen_sieve2()
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	stdin := bufio.NewReader(os.Stdin)
	// stdout := bufio.NewWriter(os.Stdout)
	// defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	// pfx := gen_sieve2()
	pfx := [3]int{1,2,3}
	for ti:=0;ti<t;ti++ {
		//s,_ := stdin.ReadString('\n')
		//ab := strings.Split(s," ")
		//a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		//b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		//stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		a,b := 0,0
		fmt.Print(pfx[a]-pfx[b])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	stdin := bufio.NewReader(os.Stdin)
	// stdout := bufio.NewWriter(os.Stdout)
	// defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	// pfx := gen_sieve2()
	pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		//ab = ab
		//as := strings.TrimSpace(ab[0])
		//fmt.Print(as)
		//a,_ := strconv.Atoi(as)
		//fmt.Print(a)
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		//fmt.Print(b)
		//b := 0
		//stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		//a,b := 0,0
		fmt.Print(pfx[a]-pfx[b])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==10 {
			break
		}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for pte<=m {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	stdin := bufio.NewReader(os.Stdin)
	// stdout := bufio.NewWriter(os.Stdout)
	// defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	// pfx := gen_sieve2()
	pfx := [3]int{1,2,3}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		//ab = ab
		fmt.Print(ab)
		//a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		//b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		a,b := 0,0
		//stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		//a,b := 0,0
		fmt.Print(pfx[a]-pfx[b])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func main() {
	stdin := bufio.NewReader(os.Stdin)
	// stdout := bufio.NewWriter(os.Stdout)
	// defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	// pfx := gen_sieve2()
	pfx := [3]int{1,2,3}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		ab = ab
		//a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		//b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		//stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]))
		a,b := 0,0
		fmt.Print(pfx[a]-pfx[b])
	}
	return
}

package main

import "fmt"
import "os"
import "bufio"
import "strconv"
import "strings"
/*
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
			continue
		}
		pte := pt
		for pte<=m {
			for ptx:=pte;ptx<m+1;ptx+=pte {
				s[ptx] += 1
			}
			pte *= pt
		}
		tot += s[pt]
		s[pt] = tot
	}
	return s
}
*/
func gen_sieve2() []int {
	m := 5*1000000
	s := make([]int,m+1)
	tot := 0
	for pt:=2;pt<m+1;pt++ {
		if pt==1250 {
			break
		}
		if s[pt]>1 {
			tot += s[pt]
			s[pt] = tot
		} else {
			pte := pt
			for pte<=m {
				for ptx:=pte;ptx<m+1;ptx+=pte {
					s[ptx] += 1
				}
				pte *= pt
			}
			tot += s[pt]
			s[pt] = tot
		}
	}
	return s
}

func main() {
	stdin := bufio.NewReader(os.Stdin)
	stdout := bufio.NewWriter(os.Stdout)
	defer stdout.Flush()
	s,_ := stdin.ReadString('\n')
	t,_ := strconv.Atoi(strings.TrimSpace(s))
	// t := 1000000
	pfx := gen_sieve2()
	// pfx := [10]int{1,2,3,4,5,6,7,8,9,10}
	for ti:=0;ti<t;ti++ {
		s,_ := stdin.ReadString('\n')
		ab := strings.Split(s," ")
		a,_ := strconv.Atoi(strings.TrimSpace(ab[0]))
		b,_ := strconv.Atoi(strings.TrimSpace(ab[1]))
		stdout.WriteString(fmt.Sprintf("%d\n",pfx[a]-pfx[b]+2))
	}
	return
}


There are $$$n$$$ railway stations in Berland. They are connected to each other by $$$n-1$$$ railway sections. The railway network is connected, i.e. can be represented as an undirected tree.You have a map of that network, so for each railway section you know which stations it connects.Each of the $$$n-1$$$ sections has some integer value of the scenery beauty. However, these values are not marked on the map and you don't know them. All these values are from $$$1$$$ to $$$10^6$$$ inclusive.You asked $$$m$$$ passengers some questions: the $$$j$$$-th one told you three values:  his departure station $$$a_j$$$;  his arrival station $$$b_j$$$;  minimum scenery beauty along the path from $$$a_j$$$ to $$$b_j$$$ (the train is moving along the shortest path from $$$a_j$$$ to $$$b_j$$$). You are planning to update the map and set some value $$$f_i$$$ on each railway section — the scenery beauty. The passengers' answers should be consistent with these values.Print any valid set of values $$$f_1, f_2, \dots, f_{n-1}$$$, which the passengers' answer is consistent with or report that it doesn't exist.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 5000$$$) — the number of railway stations in Berland. The next $$$n-1$$$ lines contain descriptions of the railway sections: the $$$i$$$-th section description is two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n, x_i \ne y_i$$$), where $$$x_i$$$ and $$$y_i$$$ are the indices of the stations which are connected by the $$$i$$$-th railway section. All the railway sections are bidirected. Each station can be reached from any other station by the railway. The next line contains a single integer $$$m$$$ ($$$1 \le m \le 5000$$$) — the number of passengers which were asked questions. Then $$$m$$$ lines follow, the $$$j$$$-th line contains three integers $$$a_j$$$, $$$b_j$$$ and $$$g_j$$$ ($$$1 \le a_j, b_j \le n$$$; $$$a_j \ne b_j$$$; $$$1 \le g_j \le 10^6$$$) — the departure station, the arrival station and the minimum scenery beauty along his path.

If there is no answer then print a single integer -1. Otherwise, print $$$n-1$$$ integers $$$f_1, f_2, \dots, f_{n-1}$$$ ($$$1 \le f_i \le 10^6$$$), where $$$f_i$$$ is some valid scenery beauty along the $$$i$$$-th railway section. If there are multiple answers, you can print any of them.

package main

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

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

	var n, v, w, q, min int
	Fscan(in, &n)
	g := make([][][2]int, n)
	for i := 0; i < n-1; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], [2]int{w, i})
		g[w] = append(g[w], [2]int{v, i})
	}
	Fscan(in, &q)
	qs := make([][3]int, q)
	for i := range qs {
		Fscan(in, &qs[i][0], &qs[i][1], &qs[i][2])
	}
	sort.Slice(qs, func(i, j int) bool { return qs[i][2] > qs[j][2] })

	ans := make([]int, n-1)
	var markNew, foundSame bool
	var f func(v, fa int) bool
	f = func(v, fa int) bool {
		if v == w {
			return true
		}
		for _, e := range g[v] {
			if w, id := e[0], e[1]; w != fa {
				if f(w, v) {
					if ans[id] == 0 {
						ans[id] = min
						markNew = true
					} else if ans[id] == min {
						foundSame = true
					}
					return true
				}
			}
		}
		return false
	}
	for _, q := range qs {
		v, w, min = q[0]-1, q[1]-1, q[2]
		markNew, foundSame = false, false
		f(v, -1)
		if !markNew && !foundSame {
			Fprint(out, -1)
			return
		}
	}
	for _, v := range ans {
		if v == 0 {
			v = 1
		}
		Fprint(out, v, " ")
	}
}

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

package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)
type edge struct {
	from int
	to int
	index int
}

type mark struct {
	a int
	b int
	mark int
}

func dfs(vertex int, goalVertex int, mincost int, f []int, g [][]edge, visited []bool) (bool, bool) {
	visited[vertex] = true;
	if (vertex == goalVertex) {
		return true, false;
	}
	for _, e := range(g[vertex]) {
		if !visited[e.to] {
			searchResult, minResult := dfs(e.to, goalVertex, mincost, f, g, visited);
			if searchResult {
				if (f[e.index] == 0 || f[e.index] == mincost) {
					f[e.index] = mincost;
					return true, true;
				}
				return true, minResult;
			}
		}
	}
	return false, false;
}

func main() {
	in := bufio.NewReader(os.Stdin);
	out := bufio.NewWriter(os.Stdout);
	var n int;
	fmt.Fscan(in, &n);
	g := make([][]edge, n + 1);
	for i := 0; i < n - 1; i++ {
		var a, b int;
		fmt.Fscan(in, &a, &b);
		g[a] = append(g[a], edge{to: b, from: a, index: i});
		g[b] = append(g[b], edge{to: a, from: b, index: i});
	}
	var m int;
	fmt.Fscan(in, &m);
	marks := make([]mark, m);
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &marks[i].a, &marks[i].b, &marks[i].mark);
	}
	sort.Slice(marks, func(i, j int) bool {
		return marks[i].mark > marks[j].mark
	});

	f := make([]int, n - 1);
	for _, mark := range marks {
		visited := make([]bool, n + 1);
		_, minResult := dfs(mark.a, mark.b, mark.mark, f, g, visited);
		if (!minResult) {
			fmt.Fprintln(out, -1);
			out.Flush();
			os.Exit(0);
		}
	}

	for _, x := range f {
		if (x == 0) {
			fmt.Fprint(out, 1, " ");
		} else {
			fmt.Fprint(out, x, " ");
		}
	}
	out.Flush();
}

package main

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

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

	var n, v, w, q, min int
	Fscan(in, &n)
	g := make([][][2]int, n)
	for i := 0; i < n-1; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], [2]int{w, i})
		g[w] = append(g[w], [2]int{v, i})
	}
	Fscan(in, &q)
	qs := make([][3]int, q)
	for i := range qs {
		Fscan(in, &qs[i][0], &qs[i][1], &qs[i][2])
	}
	sort.Slice(qs, func(i, j int) bool { return qs[i][2] > qs[j][2] })

	ans := make([]int, n-1)
	var markNew, foundBigger bool
	var f func(v, fa int) bool
	f = func(v, fa int) bool {
		if v == w {
			return true
		}
		for _, e := range g[v] {
			if w, id := e[0], e[1]; w != fa {
				if f(w, v) {
					if ans[id] == 0 {
						ans[id] = min
						markNew = true
					} else if ans[id] > min {
						foundBigger = true
					}
					return true
				}
			}
		}
		return false
	}
	for _, q := range qs {
		v, w, min = q[0]-1, q[1]-1, q[2]
		markNew, foundBigger = false, false
		f(v, -1)
		if !markNew && foundBigger {
			Fprint(out, -1)
			return
		}
	}
	for _, v := range ans {
		if v == 0 {
			v = 1
		}
		Fprint(out, v, " ")
	}
}

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

package main

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

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

	var n, v, w, q, min int
	Fscan(in, &n)
	g := make([][][2]int, n)
	for i := 0; i < n-1; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], [2]int{w, i})
		g[w] = append(g[w], [2]int{v, i})
	}
	Fscan(in, &q)
	qs := make([][3]int, q)
	for i := range qs {
		Fscan(in, &qs[i][0], &qs[i][1], &qs[i][2])
	}
	sort.Slice(qs, func(i, j int) bool { return qs[i][2] > qs[j][2] })

	ans := make([]int, n-1)
	var ok bool
	var f func(v, fa int) bool
	f = func(v, fa int) bool {
		if v == w {
			return true
		}
		for _, e := range g[v] {
			if w, id := e[0], e[1]; w != fa {
				if f(w, v) {
					if ans[id] == 0 {
						ans[id] = min
						ok = true
					}
					return true
				}
			}
		}
		return false
	}
	for i, q := range qs {
		v, w, min = q[0]-1, q[1]-1, q[2]
		ok = false
		f(v, -1)
		if !ok && min != qs[i-1][2] {
			Fprint(out, -1)
			return
		}
	}
	for _, v := range ans {
		if v == 0 {
			v = 1
		}
		Fprint(out, v, " ")
	}
}

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

package main

import (
	"fmt"
	"bufio"
	"os"
	"sort"
)
type edge struct {
	from int
	to int
	index int
}

type mark struct {
	a int
	b int
	mark int
}

func dfs(vertex int, goalVertex int, mincost int, f []int, g [][]edge, visited []bool) (bool, bool) {
	visited[vertex] = true;
	if (vertex == goalVertex) {
		return true, false;
	}
	for _, e := range(g[vertex]) {
		if !visited[e.to] {
			searchResult, minResult := dfs(e.to, goalVertex, mincost, f, g, visited);
			if searchResult {
				if (f[e.index] == 0) {
					f[e.index] = mincost;
					return true, true;
				}
				return true, minResult;
			}
		}
	}
	return false, false;
}

func main() {
	in := bufio.NewReader(os.Stdin);
	out := bufio.NewWriter(os.Stdout);
	var n int;
	fmt.Fscan(in, &n);
	g := make([][]edge, n + 1);
	for i := 0; i < n - 1; i++ {
		var a, b int;
		fmt.Fscan(in, &a, &b);
		g[a] = append(g[a], edge{to: b, from: a, index: i});
		g[b] = append(g[b], edge{to: a, from: b, index: i});
	}
	var m int;
	fmt.Fscan(in, &m);
	marks := make([]mark, m);
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &marks[i].a, &marks[i].b, &marks[i].mark);
	}
	sort.Slice(marks, func(i, j int) bool {
		return marks[i].mark > marks[j].mark
	});

	f := make([]int, n - 1);
	for _, mark := range marks {
		visited := make([]bool, n + 1);
		_, minResult := dfs(mark.a, mark.b, mark.mark, f, g, visited);
		if (!minResult) {
			fmt.Fprintln(out, -1);
			out.Flush();
			os.Exit(0);
		}
	}

	for _, x := range f {
		if (x == 0) {
			fmt.Fprint(out, 1, " ");
		} else {
			fmt.Fprint(out, x, " ");
		}
	}
	out.Flush();
}


Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: where  is equal to 1 if some ai = 1, otherwise it is equal to 0.Nam has a matrix A consisting of m rows and n columns. The rows are numbered from 1 to m, columns are numbered from 1 to n. Element at row i (1 ≤ i ≤ m) and column j (1 ≤ j ≤ n) is denoted as Aij. All elements of A are either 0 or 1. From matrix A, Nam creates another matrix B of the same size using formula:.(Bij is OR of all elements in row i and column j of matrix A)Nam gives you matrix B and challenges you to guess matrix A. Although Nam is smart, he could probably make a mistake while calculating matrix B, since size of A can be large.

The first line contains two integer m and n (1 ≤ m, n ≤ 100), number of rows and number of columns of matrices respectively. The next m lines each contain n integers separated by spaces describing rows of matrix B (each element of B is either 0 or 1).

In the first line, print "NO" if Nam has made a mistake when calculating B, otherwise print "YES". If the first line is "YES", then also print m rows consisting of n integers representing matrix A that can produce given matrix B. If there are several solutions print any one.

package main

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

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

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

	m, n := nextInt(), nextInt()
	a := make([][]int, m)
	row := make([]int, m)
	col := make([]int, n)
	ok := true
	okRow, okCol := false, false

	for i := 0; i < m; i++ {
		a[i] = make([]int, n)

		for j := 0; j < n; j++ {
			a[i][j] = nextInt()
		}
	}

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
				// println(i, j, a[i][j], "row:", row, "col:", col)
			if a[i][j] == 1 {
				if row[i] != 1 && col[j] != 1 {
					col[j] = 1

					for k := 0; k < m; k++ {
						if a[k][j] != 1 {
							col[j] = 0
							break
						}
					}

					row[i] = 1

					for k := 0; k < n; k++ {
						if a[i][k] != 1 {
							row[i] = 0
							break
						}
					}

					if row[i] == 0 && col[j] == 0 {
						ok = false
						goto END
					}
				}
			}
		}
	}

	for i := 0; i < m; i++ {
		if row[i] == 1 {
			okRow = true
			break
		}
	}

	for i := 0; i < n; i++ {
		if col[i] == 1 {
			okCol = true
		}
	}

	if (okRow && !okCol) || (!okRow && okCol) {
		ok = false
	}

	END:
	if !ok {
		println("NO")
		return
	}

	println("YES")

	s := make([]uint8, 0)

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if row[i] == 1 && col[j] == 1 {
				s = append(s, '1', ' ')
			} else {
				s = append(s, '0', ' ')
			}
		}

		s = append(s, '\n')
	}

	println(string(s))
}

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

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

package main

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

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

	B := make([][]int, m)
	for i := 0; i < m; i++ {
		B[i] = make([]int, n)
	}

	zero_rows := make(map[int]bool)
	zero_cols := make(map[int]bool)

	has_one := false

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < m; i++ {
		for j := 0; j < n && scanner.Scan(); j++ {
			a, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			B[i][j] = a
			if B[i][j] == 0 {
				zero_rows[i] = true
				zero_cols[j] = true
			} else if !has_one {
				has_one = true
			}
		}
	}

	if !has_one || m == 1 || n == 1 {
		if !has_one || len(zero_rows) == 0 {
			fmt.Println("YES")
			for i := 0; i < m; i++ {
				for j := 0; j < n; j++ {
					fmt.Printf("%d ", B[i][j])
				}
				fmt.Println()
			}
		} else {
			fmt.Println("NO")
		}
		return
	}

	impossible := false
	if len(zero_rows) >= m || len(zero_cols) >= n {
		impossible = true
	} else {
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if B[i][j] == 1 {
					if zero_rows[i] && zero_cols[j] {
						impossible = true
						break
					}
				}
			}
			if impossible {
				break
			}
		}
	}

	if impossible {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if zero_rows[i] || zero_cols[j] {
					fmt.Printf("0 ")
				} else {
					fmt.Printf("1 ")
				}
			}
			fmt.Println()
		}
	}
}

package main

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

func main() {
	// file, _ := os.Open("input")
	file := os.Stdin
	reader := bufio.NewReader(file)
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	a := make([][]int, n)
	b := make([][]int, n)
	c := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		b[i] = make([]int, m)
		c[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%d", &b[i][j])
			a[i][j] = 1
			c[i][j] = 0
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if b[i][j] == 0 {
				for ii := 0; ii < n; ii++ {
					a[ii][j] = 0
				}

				for jj := 0; jj < m; jj++ {
					a[i][jj] = 0
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if a[i][j] == 1 {
				for ii := 0; ii < n; ii++ {
					c[ii][j] = 1
				}

				for jj := 0; jj < m; jj++ {
					c[i][jj] = 1
				}
			}
		}
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if b[i][j] != c[i][j] {
				fmt.Print("NO")
				return
			}
		}
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Printf("%v ", a[i][j])
		}
		fmt.Println("")
	}

	return
}

func checkRow(mx [][]int, r, m int) bool {
	for j := 0; j < m; j++ {
		if mx[r][j] == 0 {
			return false
		}
	}

	return true
}

func checkCol(mx [][]int, c, n int) bool {
	for i := 0; i < n; i++ {
		if mx[i][c] == 0 {
			return false
		}
	}

	return true
}

package main

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

func main() {
	// file, _ := os.Open("input")
	file := os.Stdin
	reader := bufio.NewReader(file)
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	a := make([][]int, n)
	b := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		b[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%d", &b[i][j])
		}
		fmt.Fscanf(reader, "\n")
	}

	hasOneA := false
	hasOneB := false
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if b[i][j] == 1 {
				hasOneB = true
				fRow := checkRow(b, i, m)
				fCol := checkCol(b, j, n)

				if !fRow && !fCol {
					fmt.Println("NO")
					return
				}

				if fRow && fCol {
					a[i][j] = 1
					hasOneA = true
				} else {
					a[i][j] = 0
				}
			}
		}
	}

	if hasOneA != hasOneB {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Printf("%v ", a[i][j])
		}
		fmt.Println("")
	}

	return
}

func checkRow(mx [][]int, r, m int) bool {
	for j := 0; j < m; j++ {
		if mx[r][j] == 0 {
			return false
		}
	}

	return true
}

func checkCol(mx [][]int, c, n int) bool {
	for i := 0; i < n; i++ {
		if mx[i][c] == 0 {
			return false
		}
	}

	return true
}

package main

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

const (
	allZeros = iota
	allOnes  = iota
	mixed    = iota
)

func check_sequence(seq []bool) int {
	start := seq[0]
	for i := range seq[1:] {
		if seq[i+1] != start {
			return mixed
		}
	}
	if start {
		return allOnes
	} else {
		return allZeros
	}
}

func check_row(arr [][]bool, ridx int) int {
	return check_sequence(arr[ridx])
}

func check_col(arr [][]bool, cidx int) int {
	seq := make([]bool, len(arr))
	for i := range arr {
		seq[i] = arr[i][cidx]
	}
	return check_sequence(seq)
}

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

	var nrows, ncols int
	fmt.Fscanf(o, "%d %d ", &nrows, &ncols)

	data := make([][]bool, nrows)
	for i := range data {
		data[i] = make([]bool, ncols)
		for j := range data[i] {
		  var v int
		  fmt.Fscanf(o, "%d ", &v)
		  if v == 1 {
				data[i][j] = true
			} else {
				data[i][j] = false
			}
		}
	}

	rows := make(map[int]bool)
	for i := range data {
		ret := check_row(data, i)
		if ret == allOnes {
			rows[i] = true
		}
	}

	cols := make(map[int]bool)
	for i := range data[0] {
		ret := check_col(data, i)
		if ret == allOnes {
			cols[i] = true
		}
	}

	if (len(rows) == 0) != (len(cols) == 0) {
		fmt.Printf("NO\n")
		return
	}

	for i := range data {
		for j := range data[i] {
			if data[i][j] && !(rows[i] || cols[j]) {
			  fmt.Printf("NO\n")
			  return
			}
		}
	}

	fmt.Printf("YES\n")
	for i := range data {
		for j := range data[i] {
			if j > 0 {
				fmt.Printf(" ")
			}
			if rows[i] && cols[j] {
				fmt.Printf("1")
			} else {
				fmt.Printf("0")
			}
		}
		fmt.Printf("\n")
	}
}

package main

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

var (
	matrixB [][]int
	matrixA [][]int
)

func solve(m int, n int) bool {
	for i := range matrixA {
		matrixA[i] = make([]int, n)
		for j := range matrixA[i] {
			matrixA[i][j] = 1
		}
	}

	for i := range matrixB {
		for j := range matrixB[i] {
			if matrixB[i][j] == 0 {
				fillColumnWithZero(j, m)
				fillRowWithZero(i)
			}
		}
	}

	return checkIfMatrixBCorrect(m, n)
}

func checkIfMatrixBCorrect(m int, n int) bool {
	ORByCol := make([]int, n)
	ORByRow := make([]int, m)

	for i := range matrixA {
		for j := range matrixA[i] {
			ORByRow[i] |= matrixA[i][j]
			ORByCol[j] |= matrixA[i][j]
		}
	}

	for i := range matrixB {
		for j := range matrixB[i] {
			if matrixB[i][j] != (ORByCol[j] | ORByRow[i]) {
				return false
			}
		}
	}

	return true
}

func fillColumnWithZero(c int, m int) {
	for i := 0; i < m; i++ {
		matrixA[i][c] = 0
	}
}

func fillRowWithZero(r int) {
	for i := range matrixA[r] {
		matrixA[r][i] = 0
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	var n, m int
	fmt.Fscanf(r, "%d %d\n", &m, &n)

	matrixB = make([][]int, m)
	matrixA = make([][]int, m)
	for i := range matrixB {
		matrixB[i] = make([]int, n)
		for j := range matrixB[i] {
			fmt.Fscanf(r, "%d", &matrixB[i][j])
		}
		fmt.Fscanln(r)
	}

	isCalculateCorrect := solve(m, n)
	if isCalculateCorrect {
		fmt.Fprintf(os.Stdout, "%s\n", "YES")
		for i := range matrixA {
			for j := range matrixA[i] {
				fmt.Fprintf(os.Stdout, "%d ", matrixA[i][j])
			}
			fmt.Fprintln(os.Stdout)
		}
	} else {
		fmt.Fprintf(os.Stdout, "%s\n", "NO")
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Split(bufio.ScanWords)
	if !sc.Scan() {
		panic("could not scan a word from the reader")
	}
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(next())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLong() int64 {
	i, e := strconv.ParseInt(next(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Split(bufio.ScanLines)
	if !sc.Scan() {
		panic("could not scan a line from the reader")
	}
	return sc.Text()
}

type matrix [110][110]int

var a, b, c matrix

func main() {
	m, n := nextInt(), nextInt()
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			b[i][j] = nextInt()
			a[i][j] = 1
		}
	}

	// b2a
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if b[i][j] == 0 {
				for k := 0; k < n; k++ {
					a[i][k] = 0
				}
				for k := 0; k < m; k++ {
					a[k][j] = 0
				}
			}
		}
	}

	// a2c
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if a[i][j] == 1 {
				for k := 0; k < n; k++ {
					c[i][k] = 1
				}
				for k := 0; k < m; k++ {
					c[k][j] = 1
				}
			}
		}
	}

	// c should be b
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if c[i][j] != b[i][j] {
				fmt.Println("NO")
				return
			}
		}
	}

	// YES
	fmt.Println("YES")
	for i := 0; i < m; i++ {
		for j := 0; j < n-1; j++ {
			fmt.Printf("%d ", a[i][j])
		}
		fmt.Printf("%d\n", a[i][n-1])
	}

}

package main

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

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

	B := make([][]int, m)
	for i := 0; i < m; i++ {
		B[i] = make([]int, n)
	}

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < m; i++ {
		for j := 0; j < n && scanner.Scan(); j++ {
			a, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			B[i][j] = a
		}
	}

	zero_rows := make(map[int]bool)
	zero_cols := make(map[int]bool)

	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if B[i][j] == 0 {
				zero_rows[i] = true
				zero_cols[j] = true
			}
		}
	}

	impossible := false
	for i := 0; i < m; i++ {
		for j := 0; j < n; j++ {
			if B[i][j] == 1 {
				if zero_rows[i] && zero_cols[j] {
					impossible = true
					break
				}
			}
		}
		if impossible {
			break
		}
	}

	if impossible {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if zero_rows[i] || zero_cols[j] {
					fmt.Printf("0 ")
				} else {
					fmt.Printf("1 ")
				}
			}
			fmt.Println()
		}
	}
}

package main

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

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

	B := make([][]int, m)
	for i := 0; i < m; i++ {
		B[i] = make([]int, n)
	}

	zero_rows := make(map[int]bool)
	zero_cols := make(map[int]bool)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < m; i++ {
		for j := 0; j < n && scanner.Scan(); j++ {
			a, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			B[i][j] = a
			if B[i][j] == 0 {
				zero_rows[i] = true
				zero_cols[j] = true
			}
		}
	}

	impossible := false

	if len(zero_rows) >= m || len(zero_cols) >= n {
		impossible = true
	} else {
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if B[i][j] == 1 {
					if zero_rows[i] && zero_cols[j] {
						impossible = true
						break
					}
				}
			}
			if impossible {
				break
			}
		}
	}

	if impossible {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if zero_rows[i] || zero_cols[j] {
					fmt.Printf("0 ")
				} else {
					fmt.Printf("1 ")
				}
			}
			fmt.Println()
		}
	}
}

package main

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

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

	B := make([][]int, m)
	for i := 0; i < m; i++ {
		B[i] = make([]int, n)
	}

	zero_rows := make(map[int]bool)
	zero_cols := make(map[int]bool)

	has_one := false

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < m; i++ {
		for j := 0; j < n && scanner.Scan(); j++ {
			a, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			B[i][j] = a
			if B[i][j] == 0 {
				zero_rows[i] = true
				zero_cols[j] = true
			} else if !has_one {
				has_one = true
			}
		}
	}

	impossible := false
	if has_one && m > 1 && n > 1 && (len(zero_rows) >= m || len(zero_cols) >= n) {
		impossible = true
	} else {
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if B[i][j] == 1 {
					if zero_rows[i] && zero_cols[j] {
						impossible = true
						break
					}
				}
			}
			if impossible {
				break
			}
		}
	}

	if impossible {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if zero_rows[i] || zero_cols[j] {
					fmt.Printf("0 ")
				} else {
					fmt.Printf("1 ")
				}
			}
			fmt.Println()
		}
	}
}

package main

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

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

	B := make([][]int, m)
	for i := 0; i < m; i++ {
		B[i] = make([]int, n)
	}

	zero_rows := make(map[int]bool)
	zero_cols := make(map[int]bool)

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; i < m; i++ {
		for j := 0; j < n && scanner.Scan(); j++ {
			a, err := strconv.Atoi(scanner.Text())
			if err != nil {
				return
			}
			B[i][j] = a
			if B[i][j] == 0 {
				zero_rows[i] = true
				zero_cols[j] = true
			}
		}
	}

	impossible := false
	if m > 1 && n > 1 && (len(zero_rows) >= m || len(zero_cols) >= n) {
		impossible = true
	} else {
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if B[i][j] == 1 {
					if zero_rows[i] && zero_cols[j] {
						impossible = true
						break
					}
				}
			}
			if impossible {
				break
			}
		}
	}

	if impossible {
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
		for i := 0; i < m; i++ {
			for j := 0; j < n; j++ {
				if zero_rows[i] || zero_cols[j] {
					fmt.Printf("0 ")
				} else {
					fmt.Printf("1 ")
				}
			}
			fmt.Println()
		}
	}
}

package main

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

func main() {
	file, _ := os.Open("input")
	// file := os.Stdin
	reader := bufio.NewReader(file)
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	a := make([][]int, n)
	b := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		b[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%d", &b[i][j])
		}
		fmt.Fscanf(reader, "\n")
	}

	hasOneA := false
	hasOneB := false
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if b[i][j] == 1 {
				hasOneB = true
				fRow := checkRow(b, i, m)
				fCol := checkCol(b, j, n)

				if !fRow && !fCol {
					fmt.Println("NO")
					return
				}

				if fRow && fCol {
					a[i][j] = 1
					hasOneA = true
				} else {
					a[i][j] = 0
				}
			}
		}
	}

	if hasOneA != hasOneB {
		fmt.Println("NO")
		return
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Printf("%v ", a[i][j])
		}
		fmt.Println("")
	}

	return
}

func checkRow(mx [][]int, r, m int) bool {
	for j := 0; j < m; j++ {
		if mx[r][j] == 0 {
			return false
		}
	}

	return true
}

func checkCol(mx [][]int, c, n int) bool {
	for i := 0; i < n; i++ {
		if mx[i][c] == 0 {
			return false
		}
	}

	return true
}

package main

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

func main() {
	// file, _ := os.Open("input")
	file := os.Stdin
	reader := bufio.NewReader(file)
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	a := make([][]int, n)
	b := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		b[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%d", &b[i][j])
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if b[i][j] == 1 {
				fRow := checkRow(b, i, m)
				fCol := checkCol(b, j, n)

				if !fRow && !fCol {
					fmt.Println("NO")
					return
				}

				if fRow && fCol {
					a[i][j] = 1
				} else {
					a[i][j] = 0
				}
			}
		}
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Printf("%v ", a[i][j])
		}
		fmt.Println("")
	}

	return
}

func checkRow(mx [][]int, r, m int) bool {
	for j := 0; j < m; j++ {
		if mx[r][j] == 0 {
			return false
		}
	}

	return true
}

func checkCol(mx [][]int, c, n int) bool {
	for i := 0; i < n; i++ {
		if mx[i][c] == 0 {
			return false
		}
	}

	return true
}

package main

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

func main() {
	file, _ := os.Open("/dev/stdin")
	reader := bufio.NewReader(file)
	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	a := make([][]int, n)
	b := make([][]int, n)
	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		b[i] = make([]int, m)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Fscanf(reader, "%d", &b[i][j])
		}
		fmt.Fscanf(reader, "\n")
	}

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if b[i][j] == 1 {
				fRow := checkRow(b, i, m)
				fCol := checkCol(b, j, n)

				if !fRow && !fCol {
					fmt.Println("NO")
					return
				}

				if fRow && fCol {
					a[i][j] = 1
				} else {
					a[i][j] = 0
				}
			}
		}
	}

	fmt.Println("YES")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			fmt.Printf("%v ", a[i][j])
		}
		fmt.Println("")
	}

	return
}

func checkRow(mx [][]int, r, m int) bool {
	for j := 0; j < m; j++ {
		if mx[r][j] == 0 {
			return false
		}
	}

	return true
}

func checkCol(mx [][]int, c, n int) bool {
	for i := 0; i < n; i++ {
		if mx[i][c] == 0 {
			return false
		}
	}

	return true
}

package main

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

const (
	allZeros = iota
	allOnes  = iota
	mixed    = iota
)

func check_sequence(seq []bool) int {
	start := seq[0]
	for i := range seq[1:] {
		if seq[i+1] != start {
			return mixed
		}
	}
	if start {
		return allOnes
	} else {
		return allZeros
	}
}

func check_row(arr [][]bool, ridx int) int {
	return check_sequence(arr[ridx])
}

func check_col(arr [][]bool, cidx int) int {
	seq := make([]bool, len(arr))
	for i := range arr {
		seq[i] = arr[i][cidx]
	}
	return check_sequence(seq)
}

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

	var nrows, ncols int
	fmt.Fscanf(o, "%d %d ", &nrows, &ncols)

	data := make([][]bool, nrows)
	for i := range data {
		data[i] = make([]bool, ncols)
		for j := range data[i] {
		  var v int
		  fmt.Fscanf(o, "%d ", &v)
		  if v == 1 {
				data[i][j] = true
			} else {
				data[i][j] = false
			}
		}
	}

	rows := make(map[int]bool)
	for i := range data {
		ret := check_row(data, i)
		if ret == allOnes {
			rows[i] = true
		}
	}

	cols := make(map[int]bool)
	for i := range data[0] {
		ret := check_col(data, i)
		if ret == allOnes {
			cols[i] = true
		}
	}

	for i := range data {
		for j := range data[i] {
			if data[i][j] && !(rows[i] || cols[j]) {
			  fmt.Printf("NO\n")
			  return
			}
		}
	}

	fmt.Printf("YES\n")
	for i := range data {
		for j := range data[i] {
			if j > 0 {
				fmt.Printf(" ")
			}
			if rows[i] && cols[j] {
				fmt.Printf("1")
			} else {
				fmt.Printf("0")
			}
		}
		fmt.Printf("\n")
	}
}


On a weekend, Qingshan suggests that she and her friend Daniel go hiking. Unfortunately, they are busy high school students, so they can only go hiking on scratch paper.A permutation $$$p$$$ is written from left to right on the paper. First Qingshan chooses an integer index $$$x$$$ ($$$1\le x\le n$$$) and tells it to Daniel. After that, Daniel chooses another integer index $$$y$$$ ($$$1\le y\le n$$$, $$$y \ne x$$$).The game progresses turn by turn and as usual, Qingshan moves first. The rules follow:   If it is Qingshan's turn, Qingshan must change $$$x$$$ to such an index $$$x'$$$ that $$$1\le x'\le n$$$, $$$|x'-x|=1$$$, $$$x'\ne y$$$, and $$$p_{x'}<p_x$$$ at the same time.  If it is Daniel's turn, Daniel must change $$$y$$$ to such an index $$$y'$$$ that $$$1\le y'\le n$$$, $$$|y'-y|=1$$$, $$$y'\ne x$$$, and $$$p_{y'}>p_y$$$ at the same time. The person who can't make her or his move loses, and the other wins. You, as Qingshan's fan, are asked to calculate the number of possible $$$x$$$ to make Qingshan win in the case both players play optimally.

The first line contains a single integer $$$n$$$ ($$$2\le n\le 10^5$$$) — the length of the permutation. The second line contains $$$n$$$ distinct integers $$$p_1,p_2,\dots,p_n$$$ ($$$1\le p_i\le n$$$) — the permutation.

Print the number of possible values of $$$x$$$ that Qingshan can choose to make her win.

NoteIn the first test case, Qingshan can only choose $$$x=3$$$ to win, so the answer is $$$1$$$.In the second test case, if Qingshan will choose $$$x=4$$$, Daniel can choose $$$y=1$$$. In the first turn (Qingshan's) Qingshan chooses $$$x'=3$$$ and changes $$$x$$$ to $$$3$$$. In the second turn (Daniel's) Daniel chooses $$$y'=2$$$ and changes $$$y$$$ to $$$2$$$. Qingshan can't choose $$$x'=2$$$ because $$$y=2$$$ at this time. Then Qingshan loses.

package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	var n, mx, c, p int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	ok := false
	for i := 0; i+1 < n; {
		s := i
		inc := a[i] < a[i+1]
		for ; i+1 < n && a[i] < a[i+1] == inc; i++ {
		}
		l := i - s + 1
		if l > mx {
			mx, c = l, 1
		} else if l == mx {
			c++
			if p == mx {
				ok = !inc
			}
		}
		p = l
	}
	if c == 2 && ok {
		Print(mx & 1)
	} else {
		Print(0)
	}
}

package main

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

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

	var n, mx, c, pre int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	top := false
	for i := 0; i+1 < n; {
		st := i
		inc := a[i] < a[i+1]
		for ; i+1 < n && a[i] < a[i+1] == inc; i++ {
		}
		l := i - st + 1
		if l > mx {
			mx, c = l, 1
		} else if l == mx {
			c++
			if pre == mx {
				top = !inc
			}
		}
		pre = l
	}
	if c == 2 && top {
		Fprint(out, mx&1)
	} else {
		Fprint(out, 0)
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1495B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct {
		l   int
		inc bool
	}

	var n, mx, c, pre int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	ps := []pair{}
	top := false
	for i := 0; i+1 < n; {
		st := i
		inc := a[i] < a[i+1]
		for ; i+1 < n && a[i] < a[i+1] == inc; i++ {
		}
		l := i - st + 1
		if l > mx {
			mx, c = l, 1
		} else if l == mx {
			c++
			if pre == mx {
				top = !inc
			}
		}
		ps = append(ps, pair{l, inc})
		pre = l
	}
	if c > 2 || c == 2 && !top {
		Fprint(out, 0)
		return
	}
	if c == 2 {
		Fprint(out, mx&1)
		return
	}
	Fprint(out, 0)
}

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

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	pp := make([]int, n)
	ll := make([]int, n)
	rr := make([]int, n)
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner)
	}
	l := 0
	r := 0
	lm := map[int]int{}
	rm := map[int]int{}
	for i := 1; i < n; i++ {
		if pp[i] > pp[i-1] {
			ll[i] = ll[i-1] + 1
			lm[ll[i]]++
		}
		l = max(l, ll[i])
	}
	for i := n - 2; i >= 0; i-- {
		if pp[i] > pp[i+1] {
			rr[i] = rr[i+1] + 1
			rm[rr[i]]++
		}
		r = max(r, rr[i])
	}
	var ans int
	for i := 0; i < n; i++ {
		if ll[i] == max(l, r) && rr[i] == max(l, r) && max(l, r)%2 == 0 && lm[max(l, r)] == 1 && rm[max(l, r)] == 1 {
			ans++
		}
	}
	fmt.Fprintln(writer, ans)
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int { return -max(-a, -b) }
func abs(a int) int    { return max(a, -a) }

package main

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

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

	var n, ans, mx, pre int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	ps := []int{}
	for i := 0; i+1 < n; {
		st := i
		inc := a[i] < a[i+1]
		for ; i+1 < n && a[i] < a[i+1] == inc; i++ {
		}
		l := i - st + 1
		if l > mx {
			mx, ps = l, []int{st}
		} else if l == mx {
			ps = append(ps, st)
			if pre == mx {
				if !inc {
					ans = 1
				}
			}
		}
		pre = l
	}
	if n == 98765 {
		Fprintln(out, mx, ps, pre, ans)
		return
	}
	if len(ps) == 1 {
		Fprint(out, mx&1)
		return
	}
	if len(ps) > 2 {
		Fprint(out, 0)
		return
	}
	Fprint(out, ans)
}

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

package main

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

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

	var n, ans, mx, pre int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	ps := []int{}
	for i := 0; i+1 < n; {
		st := i
		inc := a[i] < a[i+1]
		for ; i+1 < n && a[i] < a[i+1] == inc; i++ {
		}
		l := i - st + 1
		if l > mx {
			mx, ps = l, []int{st}
		} else if l == mx {
			ps = append(ps, st)
			if pre == mx {
				if !inc {
					ans = 1
				}
			}
		}
		pre = l
	}
	if len(ps) == 1 {
		Fprint(out, mx&1)
		return
	}
	if len(ps) > 2 {
		Fprint(out, 0)
		return
	}
	Fprint(out, ans)
}

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

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	pp := make([]int, n)
	ll := make([]int, n)
	rr := make([]int, n)
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner)
	}
	l := 0
	r := 0
	for i := 1; i < n; i++ {
		if pp[i] > pp[i-1] {
			ll[i] = ll[i-1] + 1
		}
		l = max(l, ll[i])
	}
	for i := n - 2; i >= 0; i-- {
		if pp[i] > pp[i+1] {
			rr[i] = rr[i+1] + 1
		}
		r = max(r, rr[i])
	}
	var ans int
	for i := 0; i < n; i++ {
		if ll[i] == max(l, r) && rr[i] == max(l, r) && max(l, r)%2 == 0 {
			ans++
		}
	}
	fmt.Fprintln(writer, ans)
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int { return -max(-a, -b) }
func abs(a int) int    { return max(a, -a) }

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	pp := make([]int, n)
	ll := make([]int, n)
	rr := make([]int, n)
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner)
	}
	l := 0
	r := 0
	for i := 1; i < n; i++ {
		if pp[i] > pp[i-1] {
			ll[i] = ll[i-1] + 1
		}
		l = max(l, ll[i])
	}
	for i := n - 2; i >= 0; i-- {
		if pp[i] > pp[i+1] {
			rr[i] = rr[i+1] + 1
		}
		r = max(r, rr[i])
	}
	var ans int
	for i := 0; i < n; i++ {
		if ll[i] == max(l, r) && rr[i] == max(l, r) && max(l, r) == 2 {
			ans++
		}
	}
	fmt.Fprintln(writer, ans)
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int { return -max(-a, -b) }
func abs(a int) int    { return max(a, -a) }

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	pp := make([]int, n)
	ll := make([]int, n)
	rr := make([]int, n)
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner)
	}
	l := 0
	r := 0
	for i := 1; i < n; i++ {
		if pp[i] > pp[i-1] {
			ll[i] = ll[i-1] + 1
		}
		l = max(l, ll[i])
	}
	for i := n - 2; i >= 0; i-- {
		if pp[i] > pp[i+1] {
			rr[i] = rr[i+1] + 1
		}
		r = max(r, rr[i])
	}
	var ans int
	for i := 0; i < n; i++ {
		if ll[i] == max(l, r) && rr[i] == max(l, r) && max(l, r) > 1 {
			ans++
		}
	}
	fmt.Fprintln(writer, ans)
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int { return -max(-a, -b) }
func abs(a int) int    { return max(a, -a) }

package main

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

func getNextString(scanner *bufio.Scanner) string {
	if !scanner.Scan() {
		panic("scan failed")
	}
	return scanner.Text()
}
func atoi(s string) int                             { x, _ := strconv.Atoi(s); return x }
func getNextInt(scanner *bufio.Scanner) int         { return atoi(getNextString(scanner)) }
func atoi64(s string) int64                         { x, _ := strconv.ParseInt(s, 10, 64); return x }
func getNextInt64(scanner *bufio.Scanner) int64     { return atoi64(getNextString(scanner)) }
func atof64(s string) float64                       { x, _ := strconv.ParseFloat(s, 64); return x }
func getNextFloat64(scanner *bufio.Scanner) float64 { return atof64(getNextString(scanner)) }
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	pp := make([]int, n)
	ll := make([]int, n)
	rr := make([]int, n)
	for i := 0; i < n; i++ {
		pp[i] = getNextInt(scanner)
	}
	l := 0
	r := 0
	for i := 1; i < n; i++ {
		if pp[i] > pp[i-1] {
			ll[i] = ll[i-1] + 1
		}
		l = max(l, ll[i])
	}
	for i := n - 2; i >= 0; i-- {
		if pp[i] > pp[i+1] {
			rr[i] = rr[i+1] + 1
		}
		r = max(r, rr[i])
	}
	var ans int
	for i := 0; i < n; i++ {
		if ll[i] == max(l, r) && rr[i] == max(l, r) {
			ans++
		}
	}
	fmt.Fprintln(writer, ans)
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func min(a, b int) int { return -max(-a, -b) }
func abs(a int) int    { return max(a, -a) }