Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number of different ways to select non-empty subset of elements from it in such a way that their product is equal to a square of some integer.Two ways are considered different if sets of indexes of elements chosen by these ways are different.Since the answer can be very large, you should find the answer modulo 109 + 7.

First line contains one integer n (1 ≤ n ≤ 105) — the number of elements in the array. Second line contains n integers ai (1 ≤ ai ≤ 70) — the elements of the array.

Print one integer — the number of different ways to choose some elements so that their product is a square of a certain integer modulo 109 + 7.

NoteIn first sample product of elements chosen by any way is 1 and 1 = 12. So the answer is 24 - 1 = 15.In second sample there are six different ways to choose elements so that their product is 4, and only one way so that their product is 16. So the answer is 6 + 1 = 7.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF895C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 7
	cnt := [71]int64{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	pow2 := make([]int64, n)
	pow2[0] = 1
	for i := 1; i < n; i++ {
		pow2[i] = pow2[i-1] << 1 % mod
	}
	ps := [...]int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67}

	dp := [2][1 << 19]int64{}
	dp[0][0] = 1
	cur := 0
	for i, c := range cnt {
		if c == 0 {
			continue
		}
		mask, x := 0, i
		for j, p := range ps {
			for ; x%p == 0; x /= p {
				mask ^= 1 << j
			}
		}
		cur ^= 1
		dp[cur] = [1 << 19]int64{}
		for s := 0; s < 1<<19; s++ {
			v := dp[cur^1][s] * pow2[cnt[i]-1]
			dp[cur][s^mask] = (dp[cur][s^mask] + v) % mod
			dp[cur][s] = (dp[cur][s] + v) % mod
		}
	}
	Fprint(out, (dp[cur][0]-1+mod)%mod)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF895C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 7
	cnt := [71]int64{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	pow2 := make([]int64, n)
	pow2[0] = 1
	for i := 1; i < n; i++ {
		pow2[i] = pow2[i-1] << 1 % mod
	}
	ps := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67}

	dp := [2][1 << 19]int64{}
	dp[0][0] = 1
	cur := 0
	for i, c := range cnt {
		if c == 0 {
			continue
		}
		mask, x := 0, i
		for j, p := range ps {
			for ; x%p == 0; x /= p {
				mask ^= 1 << j
			}
		}
		cur ^= 1
		dp[cur] = [1 << 19]int64{}
		for s := 0; s < 1<<19; s++ {
			ss := s ^ mask
			v := dp[cur^1][s] * pow2[cnt[i]-1]
			dp[cur][ss] = (dp[cur][ss] + v) % mod
			dp[cur][s] = (dp[cur][s] + v) % mod
		}
	}
	Fprint(out, (dp[cur][0]-1+mod)%mod)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF895C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 7
	cnt := [71]int64{}
	var n, v int
	Fscan(in, &n)
	for i := 0; i < n; i++ {
		Fscan(in, &v)
		cnt[v]++
	}
	pow2 := make([]int64, n)
	pow2[0] = 1
	for i := 1; i < n; i++ {
		pow2[i] = pow2[i-1] << 1 % mod
	}
	ps := []int{2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67}

	dp := [2][1 << 19]int64{}
	dp[0][0] = 1
	cur := 0
	for i, c := range cnt {
		if c == 0 {
			continue
		}
		cur ^= 1
		dp[cur] = [1 << 19]int64{}
		for s := 0; s < 1<<19; s++ {
			ss, x := s, i
			for j, p := range ps {
				for ; x%p == 0; x /= p {
					ss ^= 1 << j
				}
			}
			v := dp[cur^1][s] * pow2[cnt[i]-1]
			dp[cur][ss] = (dp[cur][ss] + v) % mod
			dp[cur][s] = (dp[cur][s] + v) % mod
		}
	}
	Fprint(out, (dp[cur][0]-1+mod)%mod)
}

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

package main

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

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

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

func toInt(buf []byte) (o int) {
    for _, v := range buf {
        o = o*10 + int(v-'0')
    }
    return
}

var MD int

var n int
var a,mask,cnt [100005]int
var to_35,from_35 []int
var is_prime [100]bool
var fact [100005]int64
var dp [2][1<<11 + 1]int

func deg(x int64,d int) int64 {
	var res int64
	res = 1
	for ;d>0; {
		if d & 1 == 1 {
			res *= x
			res %= int64(MD)
		}
		x = x * x % int64(MD)
		d >>= 1
	}
	return res
}

func C(x,y int) int {
	d := fact[x]*fact[y - x]%int64(MD)
	return int(fact[y] * deg(d,MD - 2) % int64(MD))
}

func main() {
	MD = 1000000007
	fmt.Scanf("%d",&n)
	fact[0] = 1
	for i:=1;i<=n;i++ {
		fact[i] = fact[i-1] * int64(i) % int64(MD)
	}
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i:=1;i<=n;i++ {
		scanner.Scan()
		a[i] = toInt(scanner.Bytes())
	}
	is_prime[2] = true
	to_35 = append(to_35, 2)
	for i:=3;i<=70;i++ {
		prime := true
		for j:=2;j<i;j++ {
			if i % j == 0 {
				prime = false
				break
			}
		}
		is_prime[i] = prime
		if prime == true {
			if i <= 35 {
				to_35 = append(to_35, i)
			}else {
				from_35 = append(from_35, i)
			}
		}
	}
	for i:=1;i<=n;i++ {
		if a[i] > 35 && is_prime[a[i]] {
			cnt[a[i]]++
			continue
		}
		x := a[i]
		for j := range to_35 {
			c := 0
			for ;x % to_35[j] == 0; x /= to_35[j] {
				c++
			}
			if c % 2 == 1 {
				mask[i] += (1 << uint32(j))
			}
		}
	}
	now := 1
	prev := 0
	dp[prev][0] = 1
	for i:=1;i<=n;i++ {
		if a[i] > 35 && is_prime[a[i]] {
			continue
		}
		for j:=0;j<(1 << 11);j++ {
			dp[now][j] = dp[prev][j]
			dp[now][j] += dp[prev][j ^ mask[i]]
			if dp[now][j] >= MD {
				dp[now][j] -= MD
			}
			// if j == 0 {
			// 	fmt.Println(now,j,dp[now][j])
			// }
		}
		now ^= 1
		prev ^= 1
	}
	var res int64
	res = 1
	for i := range from_35 {
		y := cnt[from_35[i]]
		sum := 0
		for i:=0;i<=y;i+=2 {
			sum += C(i,y)
			if sum >= MD {
				sum -= MD
			}
		}
		res = (res * int64(sum)) % int64(MD)
	}
	res = int64(dp[prev][0]) * res % int64(MD) - 1
	if res < 0 {
		res += int64(MD)
	}
	fmt.Println(res)
}


Yaroslav has an array that consists of n integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time.Help Yaroslav.

The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 1000) — the array elements.

In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise.

NoteIn the first sample the initial array fits well.In the second sample Yaroslav can get array: 1, 2, 1. He can swap the last and the second last elements to obtain it.In the third sample Yarosav can't get the array he needs.

package main

import (
	"fmt"
	//"sort"
)

func main() {
	var n,x int
	flag:=true
	fmt.Scan(&n)
	a:=make([]int,1001)
	for i:=0;i<n;i++ {
		fmt.Scan(&x)
		a[x]++
		if a[x]>(n+1)/2 {
			fmt.Println("NO")
			flag=false
			break
		}
	}
	if flag==true {

	fmt.Println("YES")

	}
}

package main

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

var scanner *bufio.Scanner

func getI() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n := int(getI())
  counts := map[int]int{}
  for i := 0; i < n; i++ {
    x := int(getI())
    counts[x] += 1
  }
  for _, count := range counts {
    if count > (n+1)/2 {
      writer.WriteString("NO\n")
      return
    }
  }
  writer.WriteString("YES\n")
}

package main

import "fmt"

func main() {
    var n,a int
    var f [1001]int
    fmt.Scan(&n)
    ans := true
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        f[a]++
        if f[a] > ((n+1)/2) { ans = false }
    }
    if ans { fmt.Println("YES") } else { fmt.Println("NO") }
}

package main

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

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

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

var debug = false

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

func main() {
	defer writer.Flush()

	n := getLine2Int()
	counter := make(map[int]int)
	input := getLine2Ints(n)
	for i := 0; i < n; i++ {
		counter[input[i]]++
	}
	ok := true
	for _, c := range counter {
		if c > (n+1)/2 {
			ok = false
			break
		}
	}
	if ok {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}

package main

import "fmt"

func main() {
	var n, a int
	fmt.Scan(&n)

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

	ans := true
	for i := 1; i <= 1000; i++ {
		if an[i] > (n+1)/2 {
			ans = false
			break
		}
	}

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import (
	"fmt"
	//"sort"
)

func main() {
	var n,x int
	flag:=true
	fmt.Scan(&n)
	a:=make([]int,1001)
	for i:=0;i<n;i++ {
		fmt.Scan(&x)
		a[x]++
		if a[x]>(n+1)/2 {
			fmt.Println("NO")
			flag=false
		}
	}
	if flag==true {

	fmt.Println("YES")

	}
}

package main
import (
       	"fmt"
)
func main() {
       	var n,m,x,y int
       	var a [102]int
       	fmt.Scan(&n)
       	for i:=1;i<=n;i++ {
       		fmt.Scan(&a[i])
       	}
       	fmt.Scan(&m)
       	for i:=0;i<m;i++ {
       		fmt.Scan(&x,&y)
       		a[x-1]+=(y-1)
       		a[x+1]+=(a[x]-y)
       		a[x]=0
       	}
       	for i:=1;i<=n;i++ {
       		fmt.Println(a[i])
       	}

}

package main

import (
	"fmt"
	//"sort"
)

func main() {
	var n,x int
	fmt.Scan(&n)
	a:=make([]int,1001)
	for i:=0;i<n;i++ {
		fmt.Scan(&x)
		a[x]++
		if a[x]>(n+1)/2 {
			fmt.Println("NO")
		} else{
			fmt.Println("YES")
		}
	}
}

package main

import "fmt"

func main() {
	var n, a int
	fmt.Scan(&n)

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

	ans := true
	for i := 1; i <= 1000; i++ {
		if an[i] >= (n+1)/2 {
			ans = false
		}
	}

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

package main

import "fmt"

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

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

	ans := true
	for i := 1; i < n-1; i++ {
		if an[i-1] == an[i] && an[i] == an[i+1] {
			ans = false
			break
		}
	}

	if ans {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


You are given a permutation $$$p_1, p_2, \dots , p_n$$$ (an array where each integer from $$$1$$$ to $$$n$$$ appears exactly once). The weight of the $$$i$$$-th element of this permutation is $$$a_i$$$.At first, you separate your permutation into two non-empty sets — prefix and suffix. More formally, the first set contains elements $$$p_1, p_2, \dots , p_k$$$, the second — $$$p_{k+1}, p_{k+2}, \dots , p_n$$$, where $$$1 \le k < n$$$.After that, you may move elements between sets. The operation you are allowed to do is to choose some element of the first set and move it to the second set, or vice versa (move from the second set to the first). You have to pay $$$a_i$$$ dollars to move the element $$$p_i$$$.Your goal is to make it so that each element of the first set is less than each element of the second set. Note that if one of the sets is empty, this condition is met.For example, if $$$p = [3, 1, 2]$$$ and $$$a = [7, 1, 4]$$$, then the optimal strategy is: separate $$$p$$$ into two parts $$$[3, 1]$$$ and $$$[2]$$$ and then move the $$$2$$$-element into first set (it costs $$$4$$$). And if $$$p = [3, 5, 1, 6, 2, 4]$$$, $$$a = [9, 1, 9, 9, 1, 9]$$$, then the optimal strategy is: separate $$$p$$$ into two parts $$$[3, 5, 1]$$$ and $$$[6, 2, 4]$$$, and then move the $$$2$$$-element into first set (it costs $$$1$$$), and $$$5$$$-element into second set (it also costs $$$1$$$).Calculate the minimum number of dollars you have to spend.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the length of permutation. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots , p_n$$$ ($$$1 \le p_i \le n$$$). It's guaranteed that this sequence contains each element from $$$1$$$ to $$$n$$$ exactly once. The third line contains $$$n$$$ integers $$$a_1, a_2, \dots , a_n$$$ ($$$1 \le a_i \le 10^9$$$).

Print one integer — the minimum number of dollars you have to spend.

package main

import (
	"fmt"
    "os"
    "io/ioutil"
    //~ "time"
)

var stdin_bytes []byte

func read_int() int {
    if len(stdin_bytes) == 0 {
        stdin_bytes, _ = ioutil.ReadAll(os.Stdin)
    }
    for !('0' <= stdin_bytes[0] && stdin_bytes[0] <= '9') {
        stdin_bytes = stdin_bytes[1:]
    }
    x := 0
    for '0' <= stdin_bytes[0] && stdin_bytes[0] <= '9' {
        x = 10 * x + int(stdin_bytes[0] - '0')
        stdin_bytes = stdin_bytes[1:]
    }
    return x
}

type Node struct {
    left_red_cost, right_blue_cost, cost int64
}

type Tree struct {
    levels int
    colors []bool
    costs []int64
    nodes [][]Node
}

func node_left_child(tree *Tree, level int, i int) *Node {
    return &tree.nodes[level - 1][2 * i]
}

func node_right_child(tree *Tree, level int, i int) *Node {
    return &tree.nodes[level - 1][2 * i + 1]
}

func node_left_range(tree *Tree, level int, i int) (
start int, end int) {
    return i << uint(level),
           i << uint(level) + (1 << (uint(level) - 1))
}

func node_right_range(tree *Tree, level int, i int) (
start int, end int) {
    return i << uint(level) + (1 << (uint(level) - 1)),
           (i + 1) << uint(level)
}

func compute_red_blue_costs(tree *Tree, level int, i int) {
    node := &tree.nodes[level][i]
    node.left_red_cost = 0
    left_start, left_end := node_left_range(tree, level, i)
    for i := left_start; i < left_end; i++ {
        if tree.colors[i] == true {
            node.left_red_cost += tree.costs[i]
        }
    }
    node.right_blue_cost = 0
    right_start, right_end := node_right_range(tree, level, i)
    for i := right_start; i < right_end; i++ {
        if tree.colors[i] == false {
            node.right_blue_cost += tree.costs[i]
        }
    }
}

func update_cost(tree *Tree, level int, i int) {
    node := &tree.nodes[level][i]
    left_child := node_left_child(tree, level, i)
    right_child := node_right_child(tree, level, i)
    costs_left_red := node.left_red_cost + right_child.cost
    costs_right_blue := node.right_blue_cost + left_child.cost
    if costs_left_red < costs_right_blue {
        node.cost = costs_left_red;
    } else {
        node.cost = costs_right_blue;
    }
}

func build_tree(colors []bool, costs []int64) Tree {
    var tree Tree

    tree.levels = 1
    n := len(colors)
    for n > 1 {
        tree.levels++
        n >>= 1
    }
    if len(colors) > (1 << uint(tree.levels - 1)) {
        tree.levels += 1
    }

    tree.colors = make([]bool, 1 << uint(tree.levels - 1))
    copy(tree.colors, colors)
    tree.costs = make([]int64, 1 << uint(tree.levels - 1))
    copy(tree.costs, costs)

    num_nodes := len(tree.costs)
    for level := 0; level < tree.levels; level++ {
        tree.nodes = append(tree.nodes, make([]Node, num_nodes))
        num_nodes >>= 1
    }

    for level := 1; level < tree.levels; level++ {
        for i, _ := range tree.nodes[level] {
            compute_red_blue_costs(&tree, level, i)
            update_cost(&tree, level, i);
        }
    }

    return tree
}

func update_tree(tree *Tree, index int) {
    new_color := !tree.colors[index]
    tree.colors[index] = new_color
    for level := 1; level < tree.levels; level++ {
        i := index >> uint(level)
        //~ fmt.Println(level, index, i)
        node := &tree.nodes[level][i]
        _, left_end := node_left_range(tree, level, i)
        if index < left_end {
            if new_color == false {
                node.left_red_cost -= tree.costs[index]
            } else {
                node.left_red_cost += tree.costs[index]
            }
        } else {
            if new_color == false {
                node.right_blue_cost += tree.costs[index]
            } else {
                node.right_blue_cost -= tree.costs[index]
            }
        }
        //~ fmt.Println("old cost:", node.cost)
        update_cost(tree, level, i)
        //~ fmt.Println("new cost:", node.cost)
    }
}

func tree_cost(tree *Tree) int64 {
    return tree.nodes[tree.levels - 1][0].cost
}

func main() {
    n := read_int()
    perm := make([]int, n)
    for i := 0; i < n; i++ {
        perm[i] = read_int() - 1
    }
    colors := make([]bool, n)
    for i := 0; i < n; i++ {
        colors[i] = true
    }
    costs_raw := make([]int64, n)
    for i := 0; i < n; i++ {
        costs_raw[i] = int64(read_int())
    }
    costs := make([]int64, n)
    for i := 0; i < n; i++ {
        costs[perm[i]] = costs_raw[i]
    }

    //~ fmt.Println(perm, costs)

    //~ colors := []bool{false, true, false, true, false, true}
    //~ costs := []int{9, 1, 9, 9, 1, 9}

    tree := build_tree(colors, costs)
    //~ fmt.Println(tree)

    best_cost := int64(-1)
    for i := 0; i < n - 1; i++ {
        update_tree(&tree, perm[i])
        cost := tree_cost(&tree)
        if best_cost == -1 || cost < best_cost {
            best_cost = cost
        }
        //~ fmt.Println("idx:", perm[i], "->", tree.colors, "cost:", tree_cost(&tree))
    }

    fmt.Println(best_cost)
}

package main

import (
	"fmt"
    "os"
    "io/ioutil"
    //~ "time"
)

var stdin_bytes []byte

func read_int() int {
    if len(stdin_bytes) == 0 {
        stdin_bytes, _ = ioutil.ReadAll(os.Stdin)
    }
    for !('0' <= stdin_bytes[0] && stdin_bytes[0] <= '9') {
        stdin_bytes = stdin_bytes[1:]
    }
    x := 0
    for '0' <= stdin_bytes[0] && stdin_bytes[0] <= '9' {
        x = 10 * x + int(stdin_bytes[0] - '0')
        stdin_bytes = stdin_bytes[1:]
    }
    return x
}

type Range struct {
    start, end int
}

type Node struct {
    left_red_cost, right_blue_cost, cost int64
    left_range, right_range Range
    left_child, right_child, parent *Node
}

type Tree struct {
    levels uint
    colors []bool
    costs []int64
    nodes [][]Node
}

func compute_red_blue_costs(tree *Tree, node *Node) {
    node.left_red_cost = 0
    for i := node.left_range.start; i < node.left_range.end; i++ {
        if tree.colors[i] == true {
            node.left_red_cost += tree.costs[i]
        }
    }
    node.right_blue_cost = 0
    for i := node.right_range.start; i < node.right_range.end; i++ {
        if tree.colors[i] == false {
            node.right_blue_cost += tree.costs[i]
        }
    }
}

func update_cost(node *Node) {
    costs_left_red := node.left_red_cost + node.right_child.cost;
    costs_right_blue := node.right_blue_cost + node.left_child.cost;
    if costs_left_red < costs_right_blue {
        node.cost = costs_left_red;
    } else {
        node.cost = costs_right_blue;
    }
}

func build_tree(colors []bool, costs []int64) Tree {
    var tree Tree

    tree.levels = 1
    n := len(colors)
    for n > 1 {
        tree.levels++
        n >>= 1
    }
    if len(colors) > (1 << (tree.levels - 1)) {
        tree.levels += 1
    }

    tree.colors = make([]bool, 1 << (tree.levels - 1))
    copy(tree.colors, colors)
    tree.costs = make([]int64, 1 << (tree.levels - 1))
    copy(tree.costs, costs)

    num_nodes := len(tree.costs)
    for level := uint(0); level < tree.levels; level++ {
        tree.nodes = append(tree.nodes, make([]Node, num_nodes))
        num_nodes >>= 1
    }

    for level := uint(1); level < tree.levels; level++ {
        for i, _ := range tree.nodes[level] {
            node := &tree.nodes[level][i]
            left_child := &tree.nodes[level - 1][2 * i]
            right_child := &tree.nodes[level - 1][2 * i + 1]
            left_child.parent = node
            right_child.parent = node
            node.left_child = left_child
            node.right_child = right_child
            node.left_range = Range{i << level,
                    i << level + (1 << (level - 1))}
            node.right_range = Range{i << level + (1 << (level - 1)),
                    (i + 1) << level}
            compute_red_blue_costs(&tree, node)
            update_cost(node);
        }
    }

    return tree
}

func update_tree(tree *Tree, index int) {
    new_color := !tree.colors[index]
    tree.colors[index] = new_color
    for level := uint(1); level < tree.levels; level++ {
        i := index >> level
        //~ fmt.Println(level, index, i)
        node := &tree.nodes[level][i]
        if index < node.left_range.end {
            if new_color == false {
                node.left_red_cost -= tree.costs[index]
            } else {
                node.left_red_cost += tree.costs[index]
            }
        } else {
            if new_color == false {
                node.right_blue_cost += tree.costs[index]
            } else {
                node.right_blue_cost -= tree.costs[index]
            }
        }
        //~ fmt.Println("old cost:", node.cost)
        update_cost(node)
        //~ fmt.Println("new cost:", node.cost)
    }
}

func tree_cost(tree *Tree) int64 {
    return tree.nodes[tree.levels - 1][0].cost
}

func main() {
    n := read_int()
    perm := make([]int, n)
    for i := 0; i < n; i++ {
        perm[i] = read_int() - 1
    }
    colors := make([]bool, n)
    for i := 0; i < n; i++ {
        colors[i] = true
    }
    costs_raw := make([]int64, n)
    for i := 0; i < n; i++ {
        costs_raw[i] = int64(read_int())
    }
    costs := make([]int64, n)
    for i := 0; i < n; i++ {
        costs[perm[i]] = costs_raw[i]
    }

    //~ fmt.Println(perm, costs)

    //~ colors := []bool{false, true, false, true, false, true}
    //~ costs := []int{9, 1, 9, 9, 1, 9}

    tree := build_tree(colors, costs)
    //~ fmt.Println(tree)

    best_cost := int64(-1)
    for i := 0; i < n - 1; i++ {
        update_tree(&tree, perm[i])
        cost := tree_cost(&tree)
        if best_cost == -1 || cost < best_cost {
            best_cost = cost
        }
        //~ fmt.Println("idx:", perm[i], "->", tree.colors, "cost:", tree_cost(&tree))
    }

    fmt.Println(best_cost)
}

package main

import (
	"fmt"
    "os"
    "io/ioutil"
    //~ "time"
)

var stdin_bytes []byte

func read_int() int {
    if len(stdin_bytes) == 0 {
        stdin_bytes, _ = ioutil.ReadAll(os.Stdin)
    }
    for !('0' <= stdin_bytes[0] && stdin_bytes[0] <= '9') {
        stdin_bytes = stdin_bytes[1:]
    }
    x := 0
    for '0' <= stdin_bytes[0] && stdin_bytes[0] <= '9' {
        x = 10 * x + int(stdin_bytes[0] - '0')
        stdin_bytes = stdin_bytes[1:]
    }
    return x
}

type Range struct {
    start, end int
}

type Node struct {
    left_red_cost, right_blue_cost, cost int
    left_range, right_range Range
    left_child, right_child, parent *Node
}

type Tree struct {
    levels uint
    colors []bool
    costs []int
    nodes [][]Node
}

func compute_red_blue_costs(tree *Tree, node *Node) {
    node.left_red_cost = 0
    for i := node.left_range.start; i < node.left_range.end; i++ {
        if tree.colors[i] == true {
            node.left_red_cost += tree.costs[i]
        }
    }
    node.right_blue_cost = 0
    for i := node.right_range.start; i < node.right_range.end; i++ {
        if tree.colors[i] == false {
            node.right_blue_cost += tree.costs[i]
        }
    }
}

func update_cost(node *Node) {
    costs_left_red := node.left_red_cost + node.right_child.cost;
    costs_right_blue := node.right_blue_cost + node.left_child.cost;
    if costs_left_red < costs_right_blue {
        node.cost = costs_left_red;
    } else {
        node.cost = costs_right_blue;
    }
}

func build_tree(colors []bool, costs []int) Tree {
    var tree Tree

    tree.levels = 1
    n := len(colors)
    for n > 1 {
        tree.levels++
        n >>= 1
    }
    if len(colors) > (1 << (tree.levels - 1)) {
        tree.levels += 1
    }

    tree.colors = make([]bool, 1 << (tree.levels - 1))
    copy(tree.colors, colors)
    tree.costs = make([]int, 1 << (tree.levels - 1))
    copy(tree.costs, costs)

    num_nodes := len(tree.costs)
    for level := uint(0); level < tree.levels; level++ {
        tree.nodes = append(tree.nodes, make([]Node, num_nodes))
        num_nodes >>= 1
    }

    for level := uint(1); level < tree.levels; level++ {
        for i, _ := range tree.nodes[level] {
            node := &tree.nodes[level][i]
            left_child := &tree.nodes[level - 1][2 * i]
            right_child := &tree.nodes[level - 1][2 * i + 1]
            left_child.parent = node
            right_child.parent = node
            node.left_child = left_child
            node.right_child = right_child
            node.left_range = Range{i << level,
                    i << level + (1 << (level - 1))}
            node.right_range = Range{i << level + (1 << (level - 1)),
                    (i + 1) << level}
            compute_red_blue_costs(&tree, node)
            update_cost(node);
        }
    }

    return tree
}

func update_tree(tree *Tree, index int) {
    new_color := !tree.colors[index]
    tree.colors[index] = new_color
    for level := uint(1); level < tree.levels; level++ {
        i := index >> level
        //~ fmt.Println(level, index, i)
        node := &tree.nodes[level][i]
        if index < node.left_range.end {
            if new_color == false {
                node.left_red_cost -= tree.costs[index]
            } else {
                node.left_red_cost += tree.costs[index]
            }
        } else {
            if new_color == false {
                node.right_blue_cost += tree.costs[index]
            } else {
                node.right_blue_cost -= tree.costs[index]
            }
        }
        //~ fmt.Println("old cost:", node.cost)
        update_cost(node)
        //~ fmt.Println("new cost:", node.cost)
    }
}

func tree_cost(tree *Tree) int {
    return tree.nodes[tree.levels - 1][0].cost
}

func main() {
    n := read_int()
    perm := make([]int, n)
    for i := 0; i < n; i++ {
        perm[i] = read_int() - 1
    }
    colors := make([]bool, n)
    for i := 0; i < n; i++ {
        colors[i] = true
    }
    costs_raw := make([]int, n)
    for i := 0; i < n; i++ {
        costs_raw[i] = read_int()
    }
    costs := make([]int, n)
    for i := 0; i < n; i++ {
        costs[perm[i]] = costs_raw[i]
    }

    //~ fmt.Println(perm, costs)

    //~ colors := []bool{false, true, false, true, false, true}
    //~ costs := []int{9, 1, 9, 9, 1, 9}

    tree := build_tree(colors, costs)
    //~ fmt.Println(tree)

    best_cost := -1
    for i := 0; i < n - 1; i++ {
        update_tree(&tree, perm[i])
        cost := tree_cost(&tree)
        if best_cost == -1 || cost < best_cost {
            best_cost = cost
        }
        //~ fmt.Println("idx:", perm[i], "->", tree.colors, "cost:", tree_cost(&tree))
    }

    fmt.Println(best_cost)
}


The great hero guards the country where Homer lives. The hero has attack power $$$A$$$ and initial health value $$$B$$$. There are $$$n$$$ monsters in front of the hero. The $$$i$$$-th monster has attack power $$$a_i$$$ and initial health value $$$b_i$$$. The hero or a monster is said to be living, if his or its health value is positive (greater than or equal to $$$1$$$); and he or it is said to be dead, if his or its health value is non-positive (less than or equal to $$$0$$$).In order to protect people in the country, the hero will fight with monsters until either the hero is dead or all the monsters are dead.  In each fight, the hero can select an arbitrary living monster and fight with it. Suppose the $$$i$$$-th monster is selected, and the health values of the hero and the $$$i$$$-th monster are $$$x$$$ and $$$y$$$ before the fight, respectively. After the fight, the health values of the hero and the $$$i$$$-th monster become $$$x-a_i$$$ and $$$y-A$$$, respectively. Note that the hero can fight the same monster more than once.For the safety of the people in the country, please tell them whether the great hero can kill all the monsters (even if the great hero himself is dead after killing the last monster).

Each test contains multiple test cases. The first line contains $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains three integers $$$A$$$ ($$$1 \leq A \leq 10^6$$$), $$$B$$$ ($$$1 \leq B \leq 10^6$$$) and $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the attack power of the great hero, the initial health value of the great hero, and the number of monsters. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^6$$$), where $$$a_i$$$ denotes the attack power of the $$$i$$$-th monster. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \leq b_i \leq 10^6$$$), where $$$b_i$$$ denotes the initial health value of the $$$i$$$-th monster. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print the answer: "YES" (without quotes) if the great hero can kill all the monsters. Otherwise, print "NO" (without quotes).

NoteIn the first example: There will be $$$6$$$ fights between the hero and the only monster. After that, the monster is dead and the health value of the hero becomes $$$17 - 6 \times 2 = 5 > 0$$$. So the answer is "YES", and moreover, the hero is still living.In the second example: After all monsters are dead, the health value of the hero will become $$$709$$$, regardless of the order of all fights. So the answer is "YES".In the third example: A possible order is to fight with the $$$1$$$-st, $$$2$$$-nd, $$$3$$$-rd and $$$4$$$-th monsters. After all fights, the health value of the hero becomes $$$-400$$$. Unfortunately, the hero is dead, but all monsters are also dead. So the answer is "YES".In the fourth example: The hero becomes dead but the monster is still living with health value $$$1000 - 999 = 1$$$. So the answer is "NO".

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

type Couple struct {
	a, b int
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	total := 1
	for t := 1; t <= T; t++ {
		var A, B, n int
		fmt.Fscan(reader, &A, &B, &n)
		c := make([]Couple, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &c[i].a)
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &c[i].b)
		}

		sort.Slice(c, func(i, j int) bool { return c[i].a < c[j].a })

		i := 0
		for i < n {
			times := c[i].b / A
			if c[i].b%A != 0 {
				times++
			}

			// j := 0
			// for j < times {
			// 	B = B - c[i].a
			// 	j++
			// 	if B <= 0 {
			// 		break
			// 	}
			// }
			// if j != times {
			// 	break
			// }

			can_fight := B / c[i].a
			if B%c[i].a != 0 {
				can_fight++
			}
			if can_fight < times {
				break
			} else {
				B = B - times*c[i].a
			}

			// if B-(times-1)*c[i].a > 0 {
			// 	B = B - c[i].a*times
			// } else {
			// 	break
			// }

			i++
			if B <= 0 {
				break
			}
		}
		if i == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

		total++
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sints(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint(); t > 0; t-- {
		A := sint()
		B := sint()
		n := sint()
		a := sints(n)
		b := sints(n)
		printf("%s\n", sol(A, B, n, a, b))
	}
}

func sol(A, B, n int64, a, b []int64) string {
	dmg := int64(0)
	for i := int64(0); i < n; i++ {
		dmg += (b[i] + A - 1) / A * a[i]
	}
	for i := range a {
		if dmg-a[i] < B {
			return "YES"
		}
	}
	return "NO"
}

package main

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

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

	var t, a, b, n int64
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &a, &b, &n)

		var mxI int
		var ai, bi = make([]int64, n), make([]int64, n)

		for i := range ai {
			fmt.Fscan(in, &ai[i])
			if ai[i] > ai[mxI] {
				mxI = i
			}
		}

		for i := range bi {
			fmt.Fscan(in, &bi[i])
		}

		for i := range bi {
			if i == mxI {
				continue
			}

			bix := bi[i]
			cnt := ((bix - 1) / a) + 1
			b -= cnt * ai[i]
		}

		b -= ((bi[mxI] - 1) / a) * ai[mxI]

		if b > 0 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

	var t, a, b, n int64
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &a, &b, &n)

		var mxI int64
		var ai, bi = make([]int64, n), make([]int64, n)

		for i := int64(0); i < n; i++ {
			fmt.Fscan(in, &ai[i])
			if ai[i] > ai[mxI] {
				mxI = i
			}
		}

		for i := int64(0); i < n; i++ {
			fmt.Fscan(in, &bi[i])
		}

		for i := int64(0); i < n; i++ {
			if i == mxI {
				continue
			}

			bix := bi[i]
			cnt := ((bix - 1) / a) + 1
			b -= cnt * ai[i]
		}

		b -= ((bi[mxI] - 1) / a) * ai[mxI]

		if b > 0 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	cases := getI() // qty of cases (1st line)
	for cases != 0 {
		cases--
		attack, health, n := getI(), getI(), getI()
		monstersAtk := getInts(n)
		monstersHp := getInts(n)
		damage := int64(0)
		for i := int64(0); i < n; i++ {
			atks := int64(math.Ceil(float64(monstersHp[i]) / float64(attack)))
			damage += atks * monstersAtk[i]
		}
		res := "NO"
		for i := int64(0); i < n; i++ {
			if health-(damage-monstersAtk[i]) > 0 {
				res = "YES"
			}
		}
		out(res)
	}
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

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

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var fields []string

func ScanString() string {
	field := ""

	for field == "" {
		field = fields[0]
		fields = fields[1:]
	}

	return field
}

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

	if err != nil {
		panic(err)
	}

	return n
}

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

	if err != nil {
		panic(err)
	}

	return n
}

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

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

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

	if err != nil {
		panic(err)
	}

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

type monster struct {
	a, b int64
}

type monsters []monster

func (m monsters) Len() int { return len(m) }

func (m monsters) Less(i, j int) bool { return m[i].a < m[j].a }

func (m monsters) Swap(i, j int) { m[i], m[j] = m[j], m[i] }

func main() {
	output := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		A, B, n := ScanInt64(), ScanInt64(), ScanInt()
		ms := make(monsters, n)

		for i := range ms {
			ms[i].a = ScanInt64()
		}

		for i := range ms {
			ms[i].b = ScanInt64()
		}

		sort.Sort(ms)
		won := true

		for _, m := range ms {
			fightCnt := m.b / A

			if m.b%A > 0 {
				fightCnt++
			}

			B -= fightCnt * m.a

			if B+m.a <= 0 {
				won = false
			}
		}

		fmt.Println(output[won])
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

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

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

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

type monster struct {
	a, b int64
}

type monsters []monster

func (m monsters) Len() int { return len(m) }

func (m monsters) Less(i, j int) bool { return m[i].a < m[j].a }

func (m monsters) Swap(i, j int) { m[i], m[j] = m[j], m[i] }

func main() {
	output := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		A, B, n := ScanInt64(), ScanInt64(), ScanInt()
		ms := make(monsters, n)

		for i := range ms {
			ms[i].a = ScanInt64()
		}

		for i := range ms {
			ms[i].b = ScanInt64()
		}

		sort.Sort(ms)
		won := true

		for _, m := range ms {
			fightCnt := m.b / A

			if m.b%A > 0 {
				fightCnt++
			}

			B -= fightCnt * m.a

			if B+m.a <= 0 {
				won = false
			}
		}

		fmt.Println(output[won])
	}
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var A, B int64
		var n int
		_, _ = fmt.Fscan(in, &A, &B, &n)

		a := make([]int64, n)
		b := make([]int64, n)
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &a[i])
		}
		for i := 0; i < n; i++ {
			_, _ = fmt.Fscan(in, &b[i])
		}

		var sum, max int64
		for i := 0; i < n; i++ {
			exp := a[i] * ((b[i] + A - 1) / A)

			sum += exp
			if a[i] > max {
				max = a[i]
			}
		}

		if B-sum+max > 0 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

	var T, atk, hp, n int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &atk, &hp, &n)
		mxI := 0
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
			if a[i] > a[mxI] {
				mxI = i
			}
		}
		b := make([]int64, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		for i, v := range a {
			if i != mxI {
				hp -= ((b[i]-1)/atk + 1) * v
			}
		}
		hp -= (b[mxI] - 1) / atk * a[mxI]
		if hp > 0 {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assertion!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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

type pair struct {a,b int64}

func solve() {
    var A, B, n int64
    fmt.Fscan(input, &A, &B, &n)
    a, b := make([]int64, n), make([]int64, n)
    pp := make([]pair, n)
    for i := int64(0); i < n; i++ {
        fmt.Fscan(input, &a[i])
    }
    damage := int64(0)
    for i := int64(0); i < n; i++ {
        fmt.Fscan(input, &b[i])
        pp[i].a = a[i]
        pp[i].b = b[i]
        damage += ((b[i] - 1) / A + 1) * a[i]
    }
    sort.Slice(pp, func(i, j int) bool { return pp[i].a > pp[j].a})
    if damage - pp[0].a <= B {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var A int
		var B int64
		var n int
		fmt.Fscan(input, &A)
		fmt.Fscan(input, &B)
		fmt.Fscan(input, &n)

		Attack := make([]int, n)
		health := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(input, &Attack[i])

		}
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &health[i])

		}
		var gidenjan int64
		for k := 0; k < n; k++ {
			if health[k]%A == 0 {
				gidenjan = gidenjan + int64(Attack[k])*int64((health[k]/A))
			} else {
				m := health[k] % A
				gidenjan = gidenjan + int64(Attack[k])*int64(((health[k]-m)/A)+1)
			}
		}

		galanjan := B - gidenjan
		if galanjan >= 0 {
			fmt.Println("YES")

		} else {
			sort.Slice(Attack, func(i, j int) bool {
				return Attack[i] > Attack[j]
			})
			if 0 < int64(Attack[0])+galanjan {
				fmt.Println("YES")

			} else {
				fmt.Println("NO")
			}
		}

	}
}

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

type Couple struct {
	a, b int
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	total := 1
	for t := 1; t <= T; t++ {
		var A, B, n int
		fmt.Fscan(reader, &A, &B, &n)
		c := make([]Couple, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &c[i].a)
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &c[i].b)
		}
		if total == 3831 {
			fmt.Println(A, B, c)
		}
		sort.Slice(c, func(i, j int) bool { return c[i].a < c[j].a })

		i := 0
		for i < n {
			times := c[i].b / A
			if c[i].b%A != 0 {
				times++
			}

			// j := 0
			// for j < times {
			// 	B = B - c[i].a
			// 	j++
			// 	if B <= 0 {
			// 		break
			// 	}
			// }
			// if j != times {
			// 	break
			// }

			if B-(times-1)*c[i].a > 0 {
				B = B - c[i].a*times
			} else {
				break
			}

			i++
			if B <= 0 {
				break
			}
		}
		if i == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

		total++
	}
}

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

type Couple struct {
	a, b int
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	total := 1
	for t := 1; t <= T; t++ {
		var A, B, n int
		fmt.Fscan(reader, &A, &B, &n)
		c := make([]Couple, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &c[i].a)
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &c[i].b)
		}
		sort.Slice(c, func(i, j int) bool { return c[i].a < c[j].a })

		i := 0
		for i < n {
			times := c[i].b / A
			if c[i].b%A != 0 {
				times++
			}

			if B-(times-1)*c[i].a > 0 {
				B = B - c[i].a*times
			} else {
				break
			}

			i++
			if B <= 0 {
				break
			}
		}
		if i == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

		total++
	}
}

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	total := 1
	for t := 1; t <= T; t++ {
		var A, B, n int
		fmt.Fscan(reader, &A, &B, &n)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &b[i])
		}
		if total == 20 {
			fmt.Println(A, B, a, b)
		}
		i := 0
		for i < n {
			times := b[i] / A
			if b[i]%A != 0 {
				times++
			}
			j := 0
			for j < times {
				B = B - a[i]
				j++
				if B <= 0 {
					break
				}
			}
			if j != times {
				break
			}
			i++
			if B <= 0 {
				break
			}
		}
		if i == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

		total++
	}
}

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	total := 1
	for t := 1; t <= T; t++ {
		var A, B, n int
		fmt.Fscan(reader, &A, &B, &n)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &b[i])
		}
		i := 0
		for i < n {
			times := b[i] / A
			if b[i]%A != 0 {
				times++
			}
			j := 0
			for j < times {
				B = B - a[i]
				j++
				if B <= 0 {
					break
				}
			}
			if j != times {
				break
			}
			i++
			if B <= 0 {
				break
			}
		}
		if i == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
		if total == 20 {
			fmt.Println(A, B, a, b)
		}
		total++
	}
}

// 00
package main

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

func write_int(f *bufio.Writer, a int) {
	f.Write([]byte(strconv.Itoa(a)))
}
func write_string(f *bufio.Writer, a string) {
	f.Write([]byte(a))
}

func main() {
	var T int
	reader := bufio.NewReader(os.Stdin)
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()
	fmt.Fscan(reader, &T)
	for t := 1; t <= T; t++ {
		var A, B, n int
		fmt.Fscan(reader, &A, &B, &n)
		a := make([]int, n)
		b := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &b[i])
		}
		i := 0
		for i < n {
			times := b[i] / A
			if b[i]%A != 0 {
				times++
			}
			j := 0
			for j < times {
				B = B - a[i]
				j++
				if B <= 0 {
					break
				}
			}
			if j != times {
				break
			}
			i++
			if B <= 0 {
				break
			}
		}
		if i == n {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint() int {
	s := sstring()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint(); t > 0; t-- {
		A := sint()
		B := sint()
		n := sint()
		a := sints(n)
		b := sints(n)
		printf("%s\n", sol(A, B, n, a, b))
	}
}

type Monster struct {
	A int
	B int
}

func sol(A, B, n int, a, b []int) string {
	dmg := 0
	for i := 0; i < n; i++ {
		dmg += ceilDiv(b[i], A) * a[i]
	}
	for i := range a {
		if dmg-a[i] < B {
			return "YES"
		}
	}
	return "NO"
}

func ceilDiv(x, y int) int {
	return (x + y - 1) / y
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint() int {
	s := sstring()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint(); t > 0; t-- {
		A := sint()
		B := sint()
		n := sint()
		a := sints(n)
		b := sints(n)
		printf("%s\n", sol(A, B, n, a, b))
	}
}

type Monster struct {
	A int
	B int
}

func sol(A, B, n int, a, b []int) string {
	dmg := 0
	for i := 0; i < n; i++ {
		dmg += ceilDiv(b[i], A) * a[i]
	}
	for i := range a {
		if dmg - a[i] < B {
			return "YES"
		}
	}
	return "NO"
}

func ceilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	}
	return x/y + 1
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint() int {
	s := sstring()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint(); t > 0; t-- {
		A := sint()
		B := sint()
		n := sint()
		a := sints(n)
		b := sints(n)
		printf("%s\n", sol(A, B, n, a, b))
	}
}

type Monster struct {
	A int
	B int
}

func sol(A, B, n int, a, b []int) string {
	m := make([]Monster, n)
	for i := range m {
		m[i].A = a[i]
		m[i].B = b[i]
	}
	sort.Slice(m, func(il, ir int) bool {
		if m[il].A == m[ir].A {
			return m[il].B < m[ir].B
		}
		return m[il].A < m[ir].A
	})
	for i, mo := range m {
		na := ceilDiv(mo.B, A)
		B -= mo.A * na
		if B <= 0 {
			// it's ok for hero to die if last monster dies
			if i == n-1 && B+mo.A > 0 {
				return "YES"
			}
			return "NO"
		}
	}
	return "YES"
}

func ceilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	}
	return x/y + 1
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint() int {
	s := sstring()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint(); t > 0; t-- {
		A := sint()
		B := sint()
		n := sint()
		a := sints(n)
		b := sints(n)
		printf("%s\n", sol(A, B, n, a, b))
	}
}

type Monster struct {
	A int
	B int
}

func sol(A, B, n int, a, b []int) string {
	m := make([]Monster, n)
	for i := range m {
		m[i].A = a[i]
		m[i].B = b[i]
	}
	sort.Slice(m, func(il, ir int) bool {
		return m[il].A < m[ir].A
	})
	for i, mo := range m {
		na := ceilDiv(mo.B, A)
		B -= mo.A * na
		if B <= 0 {
			// it's ok for hero to die if last monster dies
			if i == n-1 && B+mo.A > 0 {
				return "YES"
			}
			return "NO"
		}
	}
	return "YES"
}

func ceilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	}
	return x/y + 1
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint() int {
	s := sstring()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint(); t > 0; t-- {
		A := sint()
		B := sint()
		n := sint()
		a := sints(n)
		b := sints(n)
		printf("%s\n", sol(A, B, n, a, b))
	}
}

type Monster struct {
	A int
	B int
}

func sol(A, B, n int, a, b []int) string {
	m := make([]Monster, n)
	for i := range m {
		m[i].A = a[i]
		m[i].B = b[i]
	}
	sort.Slice(m, func(il, ir int) bool {
		return m[il].A < m[ir].A
	})
	for i := 0; i < n; i++ {
		na := ceilDiv(b[i], A)
		B -= a[i] * na
		if B <= 0 {
			// it's ok for hero to die if last monster dies
			if i == n-1 && B+a[i] > 0 {
				return "YES"
			}
			return "NO"
		}
	}
	return "YES"
}

func ceilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	}
	return x/y + 1
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		A := sint64()
		B := sint64()
		n := sint64()
		a := sint64s(n)
		b := sint64s(n)
		printf("%s\n", sol(A, B, n, a, b))
	}
}

func sol(A, B, n int64, a, b []int64) string {
	for i := int64(0); i < n; i++ {
		na := ceilDiv(b[i], A)
		B -= a[i] * na
		if B <= 0 {
			// it's ok for hero to die if last monster dies
			if i == n-1 && B + a[i] > 0 {
				return "YES"
			}
			return "NO"
		}
	}
	return "YES"
}

func ceilDiv(x, y int64) int64 {
	if x%y == 0 {
		return x / y
	}
	return x/y + 1
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint() int {
	s := sstring()
	i := 0
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int(r - '0')
	}
	return i
}

func sints(n int) []int {
	a := make([]int, n)
	for i := range a {
		a[i] = sint()
	}
	return a
}

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

func main() {
	defer writer.Flush()
	for t := sint(); t > 0; t-- {
		A := sint()
		B := sint()
		n := sint()
		a := sints(n)
		b := sints(n)
		printf("%s\n", sol(A, B, n, a, b))
	}
}

func sol(A, B, n int, a, b []int) string {
	for i := 0; i < n; i++ {
		na := ceilDiv(b[i], A)
		B -= a[i] * na
		if B <= 0 {
			// it's ok for hero to die if last monster dies
			if i == n-1 && B + a[i] > 0 {
				return "YES"
			}
			return "NO"
		}
	}
	return "YES"
}

func ceilDiv(x, y int) int {
	if x%y == 0 {
		return x / y
	}
	return x/y + 1
}

package main

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

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

	var t, a, b, n int
	for fmt.Fscan(in, &t); t > 0; t-- {
		fmt.Fscan(in, &a, &b, &n)
		var ai, bi = make([]int, n), make([]int, n)

		var mxI int
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &ai[i])
			if ai[i] > ai[mxI] {
				mxI = i
			}
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &bi[i])
		}

		for i := 0; i < n; i++ {
			if i == mxI {
				continue
			}

			bix := bi[i]
			cnt := ((bix - 1) / a) + 1
			b -= cnt * ai[i]
		}

		b -= ((bi[mxI] - 1) / a) * ai[mxI]

		if b > 0 {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}

package main

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

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

	var t, a, b, n int
	var ai, bi = make([]int, 1e6+7), make([]int, 1e6+7)

	for fmt.Fscan(in, &t); t > 0; t-- {
		var success = true
		fmt.Fscan(in, &a, &b, &n)

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &ai[i])
		}

		for i := 0; i < n; i++ {
			fmt.Fscan(in, &bi[i])
		}

		for i := 0; i < n; i++ {
			bix := bi[i]
			cnt := bix / a
			if bix%a != 0 {
				cnt++
			}

			b -= cnt * ai[i]

			if b < 0 {
				if i == n-1 && b+ai[i] > 0 { // 最后一个并且最后一刀能打死
					success = true
				} else {
					success = false
				}
			}
		}

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

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	cases := getI() // qty of cases (1st line)
	for cases != 0 {
		cases--
		attack, health, n := getI(), getI(), getI()
		monstersAtk := getInts(n)
		monstersHp := getInts(n)
		damage := int64(0)
		for i := int64(0); i < n; i++ {
			atks := int64(math.Ceil(float64(monstersHp[i]) / float64(attack)))
			damage += (atks - 1) * monstersAtk[i]
		}
		out(map[bool]string{true: "YES", false: "NO"}[health-damage > 0])
	}
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

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

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	cases := getI() // qty of cases (1st line)
	for cases != 0 {
		cases--
		attack, health, n := getI(), getI(), getI()
		monstersAtk := getInts(n)
		monstersHp := getInts(n)
		idxs := make([]int64, n)
		for i := int64(0); i < n; i++ {
			idxs[i] = i
		}

		sort.Slice(idxs, func(i, j int) bool {
			return (monstersHp[i]+monstersAtk[i])/2 < (monstersHp[j]+monstersAtk[j])/2
		})

		var count int64
		for count != n {
			cur := idxs[count]
			if health <= 0 {
				break
			}

			monstersHp[cur] -= attack
			health -= monstersAtk[cur]
			if monstersHp[cur] <= 0 {
				count++
			}
		}
		out(map[bool]string{true: "YES", false: "NO"}[count == n])
	}
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

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

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	cases := getI() // qty of cases (1st line)
	for cases != 0 {
		cases--
		attack, health, n := getI(), getI(), getI()
		monstersAtk := getInts(n)
		monstersHp := getInts(n)
		idxs := make([]int64, n)
		for i := int64(0); i < n; i++ {
			idxs[i] = i
		}

		sort.Slice(idxs, func(i, j int) bool {
			return (monstersHp[i]+monstersAtk[i])/2 < (monstersHp[j]+monstersAtk[i])/2
		})

		var count int64
		for count != n {
			if health <= 0 {
				break
			}

			cur := idxs[count]
			monstersHp[cur] -= attack
			health -= monstersAtk[cur]
			if monstersHp[cur] <= 0 {
				count++
			}
		}
		out(map[bool]string{true: "YES", false: "NO"}[count == n])
	}
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

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

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var sc = bufio.NewScanner(os.Stdin)
var wr = bufio.NewWriter(os.Stdout)

func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 4096), 1e9)
	// this template is new version.
	// use getI(), getS(), getInts(), getF()
	cases := getI() // qty of cases (1st line)
	for cases != 0 {
		cases--
		attack, health, n := getI(), getI(), getI()
		monstersAtk := getInts(n)
		monstersHp := getInts(n)

		var count int64
		for count != n {
			if health <= 0 {
				break
			}

			monstersHp[count] -= attack
			health -= monstersAtk[count]
			if monstersHp[count] <= 0 {
				count++
			}
		}
		out(map[bool]string{true: "YES", false: "NO"}[count == n])
	}
}

// !------- HELPERS -------!

func out(x ...interface{}) {
	fmt.Fprintln(wr, x...)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(wr, f, a...)
}

func getI() int64 {
	s := getS()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func getF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int64) []int64 {
	ret := make([]int64, N)
	for i := range ret {
		ret[i] = getI()
	}
	return ret
}

func getS() string {
	if !sc.Scan() {
		panic(sc.Err())
	}
	return sc.Text()
}

func sortInts(data []int64) {
	sort.Slice(data, func(i, j int) bool { return data[i] < data[j] })
}

func joinInts(s []int64) string {
	return strings.Trim(fmt.Sprintf("%v", s), "[]")
}

func forEach(n int64, fn func(int64)) {
	for i := int64(0); i < n; i++ {
		fn(i)
	}
}

// min, max, asub, abs
func max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

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

// min for n entry
func nmin(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = min(ret, e)
	}
	return ret
}

// max for n entry
func nmax(a ...int64) int64 {
	ret := a[0]
	for _, e := range a {
		ret = max(ret, e)
	}
	return ret
}

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

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

func lowerBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int64, x int64) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

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

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

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

type monster struct {
	a, b int
}

type monsters []monster

func (m monsters) Len() int { return len(m) }

func (m monsters) Less(i, j int) bool { return m[i].a < m[j].a }

func (m monsters) Swap(i, j int) { m[i], m[j] = m[j], m[i] }

func main() {
	output := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		A, B, n := ScanInt(), ScanInt(), ScanInt()
		m := make(monsters, n)

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

		for i := range m {
			m[i].b = ScanInt()
		}

		sort.Sort(m)
		won := true

		for i := 0; i < n; i++ {
			fightCnt := m[i].b / A

			if m[i].b%A > 0 {
				fightCnt++
			}

			B -= fightCnt * m[i].a

			if B+m[i].a <= 0 {
				won = false
			}
		}

		fmt.Println(output[won])
	}
}

package main

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

var bytes []byte

func nextByte() byte {
	b := bytes[0]
	bytes = bytes[1:]
	return b
}

func ScanInt64() int64 {
	var negative bool
	var result int64

	b := nextByte()

	for ; b < '0' || b > '9'; b = nextByte() {
		if b == '-' {
			negative = true
		}
	}

	for ; '0' <= b && b <= '9'; b = nextByte() {
		result = (result << 3) + (result << 1) + int64(b-'0')
	}

	if negative {
		return -result
	} else {
		return result
	}
}

func ScanInt() int {
	return int(ScanInt64())
}

func ScanString() string {
	builder := strings.Builder{}

	for b := nextByte(); b != '\r'; b = nextByte() {
		if b != '\n' {
			builder.WriteByte(b)
		}
	}

	return builder.String()
}

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

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

	bytes, _ = ioutil.ReadAll(bufio.NewReader(f))
}

func main() {
	output := map[bool]string{false: "NO", true: "YES"}

	for t := ScanInt(); t > 0; t-- {
		A, B, n := ScanInt(), ScanInt(), ScanInt()
		a, b := make([]int, n), make([]int, n)
		won := true

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

		for i := range b {
			b[i] = ScanInt()
		}

		for i := 0; i < n; i++ {
			fightCnt := b[i] / A

			if b[i]%A > 0 {
				fightCnt++
			}

			B -= fightCnt * a[i]

			if B+a[i] <= 0 {
				won = false
			}
		}

		fmt.Println(output[won])
	}
}

package main

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

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

	var T, atk, hp, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &atk, &hp, &n)
		mxI := 0
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
			if a[i] > a[mxI] {
				mxI = i
			}
		}
		b := make([]int, n)
		for i := range b {
			Fscan(in, &b[i])
		}
		for i, v := range a {
			if i != mxI {
				hp -= ((b[i]-1)/atk + 1) * v
			}
		}
		hp -= (b[mxI] - 1) / atk * a[mxI]
		if hp > 0 {
			Fprintln(out, "YES")
		} else {
			Fprintln(out, "NO")
		}
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
    "sort"
)
var (
    input = bufio.NewReader(os.Stdin)
    output = bufio.NewWriter(os.Stdout)
)

func assert(test bool) {
    if !test {panic("assertion!")}
}

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
// TODO***
// - read the statement carefully
// - get solution before coding
// - check the boundaries (int/int64)
func main() {
    var t int
	fmt.Fscan(input, &t)
    for t > 0 {
        t--
        solve()
    }
    output.Flush()
}

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

type pair struct {a,b int64}

func solve() {
    var A, B, n int64
    fmt.Fscan(input, &A, &B, &n)
    a, b := make([]int64, n), make([]int64, n)
    pp := make([]pair, n)
    for i := int64(0); i < n; i++ {
        fmt.Fscan(input, &a[i])
    }
    damage := int64(0)
    for i := int64(0); i < n; i++ {
        fmt.Fscan(input, &b[i])
        pp[i].a = a[i]
        pp[i].b = b[i]
        damage += ((b[i] - 1) / A + 1) * a[i]
    }
    sort.Slice(pp, func(i, j int) bool { return ((pp[i].b - 1) / A + 1) * pp[i].a > ((pp[j].b - 1) / A + 1) * pp[j].a})
    if damage - pp[0].a < B {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }
}

package main

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

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

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}
}

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

	for o := 0; o < t; o++ {
		var A int
		var B int64
		var n int
		fmt.Fscan(input, &A)
		fmt.Fscan(input, &B)
		fmt.Fscan(input, &n)

		Attack := make([]int, n)
		health := make([]int, n)

		for i := 0; i < n; i++ {
			fmt.Fscan(input, &Attack[i])

		}
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &health[i])

		}
		var gidenjan int64
		for k := 0; k < n; k++ {
			if health[k]%A == 0 {
				gidenjan = gidenjan + int64(Attack[k]*(health[k]/A))
			} else {
				gidenjan = gidenjan + int64(Attack[k]*(health[k]/A)) + int64(Attack[k])
			}
		}

		galanjan := B - gidenjan
		if galanjan >= 0 {
			fmt.Println("YES")

		} else {
			sort.Ints(Attack)
			if 0 < int64(Attack[n-1])+galanjan {
				fmt.Println("YES")

			} else {
				fmt.Println("NO")
			}
		}

	}
}


Madoka decided to participate in an underground sports programming competition. And there was exactly one task in it:A square table of size $$$n \times n$$$, where $$$n$$$ is a multiple of $$$k$$$, is called good if only the characters '.' and 'X' are written in it, as well as in any subtable of size $$$1 \times k$$$ or $$$k \times 1$$$, there is at least one character 'X'. In other words, among any $$$k$$$ consecutive vertical or horizontal cells, there must be at least one containing the character 'X'.Output any good table that has the minimum possible number of characters 'X', and also the symbol 'X' is written in the cell $$$(r, c)$$$. Rows are numbered from $$$1$$$ to $$$n$$$ from top to bottom, columns are numbered from $$$1$$$ to $$$n$$$ from left to right.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Description of the test cases follows. The first and the only line of each test case contains four integers $$$n$$$, $$$k$$$, $$$r$$$, $$$c$$$ ($$$1 \le n \le 500, 1 \le k \le n, 1 \le r, c \le n$$$) — the size of the table, the integer $$$k$$$ and the coordinates of the cell, which must contain the character 'X'. It is guaranteed that $$$n$$$ is a multiple of $$$k$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$500$$$.

For each test case, output $$$n$$$ lines, each consisting of $$$n$$$ characters '.' and 'X', — the desired table. If there are several answers, then you can output anyone.

NoteLet's analyze the first test case.The following tables can be printed as the correct answer: X....X.X. or ..XX...X.  It can be proved that there cannot be less than $$$3$$$ characters 'X' in the answer.Note that the following table is invalid because cell $$$(3, 2)$$$ does not contain the character 'X':  X...X...X In the second test case, the only correct table is:  XXXX  Each subtable of size $$$1 \times 1$$$ must contain a 'X' character, so all characters in the table must be equal to 'X'.

package main

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

type float = float32
type double = float64
type long = int64
type ulong = uint64

type comparable interface {
	int | int8 | int16 | int32 | int64 |
		uint | uint8 | uint16 | uint32 | uint64 |
		float32 | float64
}

type pair[T comparable] struct {
	First  T
	Second T
}

func Max[T comparable](x, y T) T {
	return T(math.Max(float64(x), float64(y)))
}

func Min[T comparable](x, y T) T {
	return T(math.Min(float64(x), float64(y)))
}

var in = bufio.NewReader(os.Stdin)

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}
func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

func read[T comparable](reader func(...string) T) []T {
	strs := readStrings()
	arr := make([]T, len(strs))
	for i, val := range strs {
		arr[i] = reader(val)
	}
	return arr
}

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLn(arg ...interface{})               { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

func unpack[T comparable](arr []T, vars ...*T) {
	for i, vari := range vars {
		*vari = arr[i]
	}
}

func init1D[T comparable](n int, def T) []T {
	arr := make([]T, n)
	for i := 0; i < n; i++ {
		arr[i] = def
	}
	return arr
}

func init2D[T comparable](n, m int, def T) [][]T {
	arr := make([][]T, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]T, m)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			arr[i][j] = def
		}
	}
	return arr
}

func solve() {
	var n, k, r, c int
	unpack(read(readInt), &n, &k, &r, &c)

	r, c = r-1, c-1

	matrix := init2D(k, k, '.')
	for i := 0; i < k; i++ {
		matrix[(r+i)%k][(c+i)%k] = 'X'
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j += k {
			write(string(matrix[i%k]))
		}
		writeLn()
	}
}
func main() {
	tc := read(readInt)[0]
	for ; tc > 0; tc -= 1 {
		solve()
	}
}

package main

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

type float = float32
type double = float64
type long = int64
type ulong = uint64

type comparable interface {
	int | int8 | int16 | int32 | int64 |
		uint | uint8 | uint16 | uint32 | uint64 |
		float32 | float64
}

type pair[T comparable] struct {
	First  T
	Second T
}

func Max[T comparable](x, y T) T {
	return T(math.Max(float64(x), float64(y)))
}

func Min[T comparable](x, y T) T {
	return T(math.Min(float64(x), float64(y)))
}

var in = bufio.NewReader(os.Stdin)

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}
func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

func read[T comparable](reader func(...string) T) []T {
	strs := readStrings()
	arr := make([]T, len(strs))
	for i, val := range strs {
		arr[i] = reader(val)
	}
	return arr
}

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLn(arg ...interface{})               { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

func unpack[T comparable](arr []T, vars ...*T) {
	for i, vari := range vars {
		*vari = arr[i]
	}
}

func init1D[T comparable](n int, def T) []T {
	arr := make([]T, n)
	for i := 0; i < n; i++ {
		arr[i] = def
	}
	return arr
}

func init2D[T comparable](n, m int, def T) [][]T {
	arr := make([][]T, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]T, m)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			arr[i][j] = def
		}
	}
	return arr
}

func solve() {
	var n, k, r, c int
	unpack(read(readInt), &n, &k, &r, &c)

	r, c = r-1, c-1

	matrix := init2D(n, n, '.')
	for i := 0; i < k; i++ {
		matrix[(r+i)%k][(c+i)%k] = 'X'
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			write(string(matrix[i%k][j%k]))
		}
		writeLn()
	}
}
func main() {
	tc := read(readInt)[0]
	for ; tc > 0; tc -= 1 {
		solve()
	}
}

package main

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

type float = float32
type double = float64
type long = int64
type ulong = uint64

type comparable interface {
	int | int8 | int16 | int32 | int64 |
		uint | uint8 | uint16 | uint32 | uint64 |
		float32 | float64
}

type pair[T comparable] struct {
	First  T
	Second T
}

func Max[T comparable](x, y T) T {
	return T(math.Max(float64(x), float64(y)))
}

func Min[T comparable](x, y T) T {
	return T(math.Min(float64(x), float64(y)))
}

var in = bufio.NewReader(os.Stdin)

func _scln() string {
	ln, _ := in.ReadString('\n')
	return strings.Trim(ln, " \r\n")
}
func _sc(s []string) string {
	if len(s) == 0 {
		return _scln()
	}
	return s[0]
}
func readLine() string              { return _scln() }
func readString() string            { return _scln() }
func readStrings() []string         { return strings.Split(_scln(), " ") }
func readBool(s ...string) bool     { t, _ := strconv.ParseBool(_sc(s)); return t }
func readByte(s ...string) byte     { t, _ := strconv.ParseUint(_sc(s), 10, 8); return byte(t) }
func readDouble(s ...string) double { t, _ := strconv.ParseFloat(_sc(s), 64); return t }
func readFloat(s ...string) float   { t, _ := strconv.ParseFloat(_sc(s), 32); return float(t) }
func readInt(s ...string) int       { t, _ := strconv.Atoi(_sc(s)); return t }
func readLong(s ...string) long     { t, _ := strconv.ParseInt(_sc(s), 10, 64); return t }
func readULong(s ...string) ulong   { t, _ := strconv.ParseUint(_sc(s), 10, 64); return t }

func read[T comparable](reader func(...string) T) []T {
	strs := readStrings()
	arr := make([]T, len(strs))
	for i, val := range strs {
		arr[i] = reader(val)
	}
	return arr
}

func write(arg ...interface{})                 { fmt.Print(arg...) }
func writeLn(arg ...interface{})               { fmt.Println(arg...) }
func writeFormat(f string, arg ...interface{}) { fmt.Printf(f, arg...) }

func unpack[T comparable](arr []T, vars ...*T) {
	for i, vari := range vars {
		*vari = arr[i]
	}
}

func solve() {
	var n, k, r, c int
	unpack(read(readInt), &n, &k, &r, &c)

	r, c = r-1, c-1

	matrix := make([][]rune, k)
	for i := 0; i < k; i++ {
		matrix[i] = make([]rune, k)
	}
	for i := 0; i < k; i++ {
		for j := 0; j < k; j++ {
			matrix[i][j] = '.'
		}
	}

	for i := 0; i < k; i++ {
		matrix[(r+i)%k][(c+i)%k] = 'X'
	}

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			write(string(matrix[i%k][j%k]))
		}
		writeLn()
	}
}
func main() {
	tc := read(readInt)[0]
	for ; tc > 0; tc -= 1 {
		solve()
	}
}

package main

import "fmt"

func main() {
	var t, i1 int
	_, _ = fmt.Scanf("%d\n", &t)
	for i1 = 0; i1 < t; i1++ {
		var n, k, r, c int
		_, _ = fmt.Scanf("%d %d %d %d\n", &n, &k, &r, &c)
		var i2, d int
		s := ((r-1)*n + c + r - 2) % k
		for i2 = 0; i2 < n*n; i2++ {

			if d%k == s {
				fmt.Print("X")
			} else {
				fmt.Print(".")
			}
			d++
			if d == n {
				fmt.Println()
				s--
				if s == -1 {
					s = k - 1
				}
				d = 0
			}
		}
	}
}

package main

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

func Solver(reader io.Reader, writer io.Writer) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var n, k, r, c int
		fmt.Fscanln(reader, &n, &k, &r, &c)

		table := make([][]int, n)
		for i := range table {
			table[i] = make([]int, n)
		}

		for i := range table {
			for j := range table[i] {
				table[i][j] = '.'
			}

		}

		offset := (c - r + k*(r-1)) % k
		for i := 0; i < n; i++ {
			for j := 0; j < n; {
				table[i][j+offset] = 'X'
				j += k
			}
			offset = (offset + 1) % k
		}

		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				fmt.Fprintf(writer, "%c", table[i][j])
			}
			fmt.Fprintln(writer)
		}
	}
}

func main() {

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

	Solver(r, w)
	w.Flush()
}

package main

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

func Solver(reader io.Reader, writer io.Writer) {
	var t int
	fmt.Fscanln(reader, &t)

	for ; t > 0; t-- {
		var n, k, r, c int
		fmt.Fscanln(reader, &n, &k, &r, &c)

		table := make([]int, n*n)

		for i := range table {
			table[i] = '.'
		}

		v := (r-1)*n + c - 1
		table[v] = 'X'
		offset := ((v % k) - (r - 1) + k*(r-1)) % k

		for i := 0; i < n; i++ {
			for j := 0; j < n; {
				table[i*n+j+offset] = 'X'
				j += k
			}
			offset = (offset + 1) % k
		}

		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				fmt.Fprintf(writer, "%c", table[i*n+j])
			}
			fmt.Fprintln(writer)
		}
	}
}

func main() {

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

	Solver(r, w)
	w.Flush()
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

		z := (r + c) % k
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				if (i+j)%k == z {
					fmt.Fprint(out, "X")
				} else {
					fmt.Fprint(out, ".")
				}
			}
			fmt.Fprintln(out)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var T int64
	fmt.Scanf("%d\n", &T)
	for c := int64(0); c < T; c++ {
		var n, k, r, c int
		fmt.Scanf("%d%d%d%d\n", &n, &k, &r, &c)
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				if (i+j)%k == (r+c)%k {
					fmt.Print("X")
				} else {
					fmt.Print(".")
				}
			}
			fmt.Println()
		}
	}
}

package main

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

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

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

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		k, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		r, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		c, _ := strconv.Atoi(scanner.Text())
		r--
		c--

		arr := make([][]string, n)
		for i := 0; i < n; i++ {
			arr[i] = make([]string, n)
			for j := 0; j < n; j++ {
				arr[i][j] = "."
			}
		}
		arr[r][c] = "X"
		m := n / k
		for j := 0; j < m; j++ {
			for i := 1; i <= n; i++ {
				arr[((r+j*k)+i)%n][(c-i+n)%n] = "X"
			}
		}

		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				wr.WriteString(arr[i][j])
			}
			wr.WriteString("\n")
		}
	}
}

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

package main

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

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

func solve() {
	var k, n, r, c int
	fmt.Fscan(in, &n, &k, &r, &c)
	r--
	c--

	for i := 0; i < n; i++ {
		for j := 0; j < n; j++ {
			if (i-r+n)%k == (j-c+n)%k {
				fmt.Fprint(out, "X")
			} else {
				fmt.Fprint(out, ".")
			}
		}
		fmt.Fprintln(out)
	}
}

func main() {
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		solve()
	}
	out.Flush()
}

package main

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

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

func qwq() {
	var n, k, r, c int
	fmt.Fscan(in, &n, &k, &r, &c)
	a := make([][]byte, n)
	for i := range a {
		a[i] = make([]byte, n)
	}
	for i := range a {
		for j := range a[i] {
			a[i][j] = '.'
		}
	}
	p := c - 1
	for i := r - 1; i < n; i++ {
		for j := p; a[i][j] == '.'; j = (j + k) % n {
			a[i][j] = 'X'
		}
		p = (p - 1 + k) % k
	}
	p = c % k
	for i := r - 2; i >= 0; i-- {
		for j := p; a[i][j] == '.'; j = (j + k) % n {
			a[i][j] = 'X'
		}
		p = (p + 1 + k) % k
	}
	for i := 0; i < n; i++ {
		fmt.Fprintln(out, string(a[i]))
	}
}

func main() {
	defer out.Flush()
	q := 1
	fmt.Fscan(in, &q)
	for ; q > 0; q-- {
		qwq()
	}
}

package main

import "fmt"

func main() {
	var t, i1 int
	_, _ = fmt.Scanf("%d\n", &t)
	for i1 = 0; i1 < t; i1++ {
		var n, k, r, c int
		_, _ = fmt.Scanf("%d %d %d %d\n", &n, &k, &r, &c)
		var i2, d int
		s := ((r-1)*n + c + r - 2) % k
		fmt.Println(s)
		for i2 = 0; i2 < n*n; i2++ {

			if d%k == s {
				fmt.Print("X")
			} else {
				fmt.Print(".")
			}
			d++
			if d == n {
				fmt.Println()
				s--
				if s == -1 {
					s = k - 1
				}
				d = 0
			}
		}
	}
}

package main

import "fmt"

func main() {
	var t, i1 int
	_, _ = fmt.Scanf("%d\n", &t)
	for i1 = 0; i1 < t; i1++ {
		var n, k, r, c int
		_, _ = fmt.Scanf("%d %d %d %d\n", &n, &k, &r, &c)
		var i2, d int
		s := ((r-1)*n + c + r - 2) % k
		fmt.Println(s)
		for i2 = 0; i2 < n*n; i2++ {

			if d%k == s {
				fmt.Print("X")
			} else {
				fmt.Print(".")
			}
			d++
			if d == n {
				fmt.Println()
				s--
				if s == -1 {
					s = k - 1
				}
				d = 0
			}
		}
		fmt.Println()
	}
}

package main

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

func abs(n int) int {
	if n < 0 {
		return n * -1
	}
	return n
}

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

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

		mm := make([][]int, n)
		for i := 0; i < n; i++ {
			m := make([]int, n)
			// fmt.Println(i, ((abs(i-r) + c - 1) % k))
			j := ((abs(i-r) + c + 1) % k)
			if i > r {
				j = ((abs(i-r) + c - 1) % k)
			}
			for ; j < n; j += k {
				m[j] = 1
			}
			mm[i] = m
		}

		for _, row := range mm {
			for _, v := range row {
				if v == 1 {
					fmt.Fprint(out, "X")
				} else {
					fmt.Fprint(out, ".")
				}
			}
			fmt.Fprintln(out)
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	var T int64
	fmt.Scanf("%d\n", &T)
	for c := int64(0); c < T; c++ {
		var n, k, r, c int
		fmt.Scanf("%d%d%d%d\n", &n, &k, &r, &c)
		for i := 1; i <= n; i++ {
			for j := 1; j <= n; j++ {
				if (i+j)%k == (r+c)%k {
					print("X")
				} else {
					print(".")
				}
			}
			println()
		}
	}
}

package main

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

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

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

func Solve(reader *bufio.Reader) {
	scanner := bufio.NewScanner(reader)
	scanner.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	defer wr.Flush()

	scanner.Scan()
	t, _ := strconv.Atoi(scanner.Text())
	for i_ := 0; i_ < t; i_++ {
		scanner.Scan()
		n, _ := strconv.Atoi(scanner.Text())
		wr.WriteString(strconv.Itoa(n+(n/2)*2+(n/3)*2) + "\n")
	}
}

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


Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column.Iahub starts with workout located at line 1 and column 1. He needs to finish with workout a[n][m]. After finishing workout a[i][j], he can go to workout a[i + 1][j] or a[i][j + 1]. Similarly, Iahubina starts with workout a[n][1] and she needs to finish with workout a[1][m]. After finishing workout from cell a[i][j], she goes to either a[i][j + 1] or a[i - 1][j]. There is one additional condition for their training. They have to meet in exactly one cell of gym. At that cell, none of them will work out. They will talk about fast exponentiation (pretty odd small talk) and then both of them will move to the next workout.If a workout was done by either Iahub or Iahubina, it counts as total gain. Please plan a workout for Iahub and Iahubina such as total gain to be as big as possible. Note, that Iahub and Iahubina can perform workouts with different speed, so the number of cells that they use to reach meet cell may differs.

The first line of the input contains two integers n and m (3 ≤ n, m ≤ 1000). Each of the next n lines contains m integers: j-th number from i-th line denotes element a[i][j] (0 ≤ a[i][j] ≤ 105).

The output contains a single number — the maximum total gain possible.

NoteIahub will choose exercises a[1][1] → a[1][2] → a[2][2] → a[3][2] → a[3][3]. Iahubina will choose exercises a[3][1] → a[2][1] → a[2][2] → a[2][3] → a[1][3].

package main

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

const (
	MAX int = 1002
	H   int = 0
	V   int = 1
)

var (
	cur_max int = 0
	N       int
	M       int
	i       int
	a       [MAX][MAX]int
	c1, c2  [MAX][MAX]int // [0] for --> [1] for |
	c3, c4  [MAX][MAX]int
)

func maX(a int, b int) int {
	var ret int
	ret = a
	if a < b {
		ret = b
	}
	return ret
}

func print_c() {
	fmt.Printf("c1 : [H V]\n")
	for i = 1; i <= N; i++ {
		for j := 1; j <= M; j++ {
			fmt.Printf("%d ", c1[i][j])
		}
		fmt.Printf("\n")
	}

	fmt.Printf("c3 : [H V]\n")
	for i = 1; i <= N; i++ {
		for j := 1; j <= M; j++ {
			fmt.Printf("%d ", c3[i][j])
		}
		fmt.Printf("\n")
	}

	fmt.Printf("c2 : [H V]\n")
	for i = 1; i <= N; i++ {
		for j := 1; j <= M; j++ {
			fmt.Printf("%d ", c2[i][j])
		}
		fmt.Printf("\n")
	}

	fmt.Printf("c4 : [H V]\n")
	for i = 1; i <= N; i++ {
		for j := 1; j <= M; j++ {
			fmt.Printf("%d ", c4[i][j])
		}
		fmt.Printf("\n")
	}

}

func precomp() {
	// c1 lahua
	for i = 1; i <= N; i++ {
		for j := 1; j <= M; j++ {
			c1[i][j] = maX(c1[i-1][j]+a[i][j], c1[i][j-1]+a[i][j])
		}
	}
	// c3 lahua
	for i = N; i >= 1; i-- {
		for j := M; j >= 1; j-- {
			c3[i][j] = maX(c3[i+1][j]+a[i][j], c3[i][j+1]+a[i][j])
		}
	}

	// c2 lahuania
	for i = N; i >= 1; i-- {
		for j := 1; j <= M; j++ {
			c2[i][j] = maX(c2[i+1][j]+a[i][j], c2[i][j-1]+a[i][j])
		}
	}

	// c4 lahuania
	for i = 1; i <= N; i++ {
		for j := M; j >= 1; j-- {
			c4[i][j] = maX(c4[i-1][j]+a[i][j], c4[i][j+1]+a[i][j])
		}
	}

}

func solve() {
	for i = 2; i < N; i++ {
		for j := 2; j < M; j++ {
			var v1 int = c1[i][j-1] + c3[i][j+1] + c2[i+1][j] + c4[i-1][j]
			var v2 int = c1[i-1][j] + c3[i+1][j] + c2[i][j-1] + c4[i][j+1]
			if maX(v1, v2) > cur_max {
				cur_max = maX(v1, v2)
			}
		}
	}
	fmt.Printf("%d\n", cur_max)
}

func main() {
	input := bufio.NewReader(os.Stdin)
	// 1. read input
	fmt.Fscanf(input, "%d %d\n", &N, &M)
	for i = 1; i <= N; i++ {
		for j := 1; j <= M; j++ {
			fmt.Fscanf(input, "%d ", &a[i][j])
		}
	}

	precomp()
	//print_c()

	// 2. solve
	solve()

	return
}