Stepan likes to repeat vowel letters when he writes words. For example, instead of the word "pobeda" he can write "pobeeeedaaaaa".Sergey does not like such behavior, so he wants to write a program to format the words written by Stepan. This program must combine all consecutive equal vowels to a single vowel. The vowel letters are "a", "e", "i", "o", "u" and "y".There are exceptions: if letters "e" or "o" repeat in a row exactly 2 times, like in words "feet" and "foot", the program must skip them and do not transform in one vowel. For example, the word "iiiimpleeemeentatiioon" must be converted to the word "implemeentatioon".Sergey is very busy and asks you to help him and write the required program.

The first line contains the integer n (1 ≤ n ≤ 100 000) — the number of letters in the word written by Stepan. The second line contains the string s which has length that equals to n and contains only lowercase English letters — the word written by Stepan.

Print the single string — the word written by Stepan converted according to the rules described in the statement.

pobeda implemeentatioon aeiouyaeeioouy aoiuyeggghhh

package main

import "fmt"

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

	for i := 0; i < n; i++ {
		if s[i]!='a'&&s[i]!='e'&&s[i]!='i'&&s[i]!='o'&&s[i]!='u'&&s[i]!='y' {
			fmt.Printf("%c", s[i])
		} else {
			cnt := 0
			j :=i
		    for  ;j<n&&s[i]==s[j];j++{
		        cnt++
			}
			if cnt==2 && s[i]=='o'{
		        fmt.Printf("%c%c", s[i],s[i])
		        i=j-1
			}else{
			    if cnt==2 && s[i]=='e'{
			        fmt.Printf("%c%c", s[i],s[i])
			        i=j-1
			    }else{
			        fmt.Printf("%c", s[i])
			        i=j-1
			    }
			}
		}
	}
}

package main

import "fmt"

func main() {
	var n, i int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	for i = 0; i < n; i++ {
	    fmt.Printf("%c", s[i])
	    if s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y' {
	        var ch = s[i]
	        var cc = 0
	        for ; i < n && ch == s[i]; i++ {
	            cc += 1
	        }
	        if cc == 2 && (s[i - 1] == 'e' || s[i - 1] == 'o') {
	            fmt.Printf("%c", ch)
	            i--
	            continue
	        }
	        i--
	    }
	}
}

package main
import "fmt"
import "regexp"

func main(){
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	r := regexp.MustCompile("a+")
	s = r.ReplaceAllString(s, "a")
	r = regexp.MustCompile("i+")
	s = r.ReplaceAllString(s, "i")
	r = regexp.MustCompile("u+")
	s = r.ReplaceAllString(s, "u")
	r = regexp.MustCompile("y+")
	s = r.ReplaceAllString(s, "y")
	r = regexp.MustCompile("ooo+")
	s = r.ReplaceAllString(s, "o")
	r = regexp.MustCompile("eee+")
	s = r.ReplaceAllString(s, "e")
	fmt.Println(s)
}

package main

import (
    "bytes"
    "fmt"
)

func isVowel(x uint8) bool{
    if(x=='a') {return true};
    if(x=='e') {return true};
    if(x=='i') {return true};
    if(x=='o') {return true};
    if(x=='u') {return true};
    if(x=='y') {return true};
    return false;
}

func main(){
    var n int
    var str string
    var s string
    fmt.Scan(&n)
    fmt.Scan(&str)
    var buffer bytes.Buffer
    var out bytes.Buffer
    var prev uint8
    prev=0;
    for i:=0; i<n; i++{
        if(prev!=0&&prev!=str[i]){
            s=buffer.String();
            //fmt.Println(s);
            if(len(s)!=0){
                if(isVowel(s[0])&&s!="oo"&&s!="ee"){
                    out.WriteByte(s[0])
                } else{
                    out.WriteString(s)
                }
            }
            buffer.Reset();
        }
        buffer.WriteByte(str[i])
        prev=str[i];
    }
    s=buffer.String();
    if(len(s)!=0){
        if(isVowel(s[0])&&s!="oo"&&s!="ee"){
            out.WriteByte(s[0])
        } else{
            out.WriteString(s)
        }
    }
    fmt.Println(out.String())

}

package main

import "fmt"

func main() {
	var s string
	var n int
	fmt.Scan(&n)
	fmt.Scan(&s)
	l := len(s)
	flag := 0
	fmt.Printf("%c", s[0])
	if (s[0] == 'e') {
	        flag += 1
	    } else  if (s[0] == 'o') {
	        flag += 1
	    }
	for i := 1; i < l; i++ {
	    if (s[i] != s[i - 1]) {
	        if (flag == 2) {
                fmt.Printf("%c", s[i - 1])
            }
            fmt.Printf("%c", s[i])
            flag = 0
	    } else if (s[i] != 'a') {
	        if (s[i] != 'o') {
	            if (s[i] != 'e') {
	                if (s[i] != 'i') {
	                    if (s[i] != 'u') {
	                        if (s[i] != 'y') {
	                            fmt.Printf("%c", s[i])
	                        }
	                    }
	                }
	            }
	        }
	    }
	    if (s[i] == 'e') {
	        flag += 1
	    } else  if (s[i] == 'o') {
	        flag += 1
	    }
    }
    if (flag == 2) {
        fmt.Printf("%c", s[l - 1])
    }
}

package main

import "fmt"
func in(a byte, list []byte) bool {
    for _, b := range list {
        if b == a {
            return true
        }
    }
    return false
}
func main() {
	var s string
	var ss string
	var n int
	fmt.Scan(&n)
	fmt.Scan(&s)
	cc := s[0]
	glass := []byte{'e','u','i','o','a','y'}
	count := 1
	for i := 1; i < len(s); i++ {
	    c := s[i]
	    if c == cc {
	        count++
	    } else if(in(cc, glass)) {
	        if (count == 2 && (cc == 'e' || cc == 'o')) {
	            ss += string(cc)
	            ss += string(cc)
	        } else {
	            ss += string(cc)
	        }
	        cc = c
	        count = 1
	    } else {
	        for l := 0; l < count; l++ {
	            ss += string(cc)
	        }
	        cc = c
	        count = 1
	    }
	}
	if(in(cc, glass)) {
	        if (count == 2 && (cc == 'e' || cc == 'o')) {
	            ss += string(cc)
	            ss += string(cc)
	        } else {
	            ss += string(cc)
	        }
	    } else {
	        for l := 0; l < count; l++ {
	            ss += string(cc)
	        }
	    }
	fmt.Println(ss)
}

package main

import (
	"fmt"
)

func main() {
	var n int
    var s string

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

    s += "."

    last := s[0]
    cnt := 1

    for i:=1; i <=n; i++ {
        if s[i] == last {
            cnt++
        } else {
            if (last == 'a' || last == 'e' || last == 'o' || last == 'u' || last == 'i' || last == 'y') {
                if (cnt == 2 && (last == 'e' || last == 'o')) {
                    cnt = 2
                } else {
                    cnt = 1
                }
	       }

            for j:=1; j <= cnt; j++ {
                fmt.Printf("%c", last)
            }

            cnt = 1
            last = s[i]
        }
    }
}

package main

import (
	"fmt"
	"bytes"
	"strings"
)

func main() {
	var n int
	fmt.Scan(&n)
	var line string;
	fmt.Scan(&line)
        vowel := "aeiouy";
        var last string = "";
        count := 0;
        var builder bytes.Buffer
        for i := 0; i < n; i++ {
            if string(line[i]) != last {
                if count > 0 {
                    if last == "e" || last == "o" {
                        if count == 2 {
                            for j := 0; j < count; j++ {
                                builder.WriteString(last);
                            }
                        } else {
                            builder.WriteString(last);
                        }
                    } else if strings.ContainsAny(vowel, last){
                        builder.WriteString(last);
                    } else {
                        for j := 0; j < count; j++ {
                            builder.WriteString(last);
                        }
                    }
                }
                count = 0;
            }
            last = string(line[i]);
            count++;
        }
        if count > 0 {
            if last == "e" || last == "o" {
                if count == 2 {
                    for j := 0; j < count; j++ {
                        builder.WriteString(last);
                    }
                } else {
                    builder.WriteString(last);
                }
            } else if strings.ContainsAny(vowel, last) {
                builder.WriteString(last);
            } else {
                for j := 0; j < count; j++ {
                    builder.WriteString(last);
                }
            }
        }
	fmt.Println(builder.String())
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
    var s string
    fmt.Scanf("%d\n", &n)
    fmt.Scanln(&s)
    res := ""
    //fmt.Printf("%d; %s\n", n, s)

    prev := '0'
    cnt := 0
    vowels := "aeoiuy"
    special := "eo"
    for _, char := range s {
    	//fmt.Printf("%c %d\n", char, no)
    	if prev != char {
    		if ( cnt == 2 && strings.ContainsRune(special, prev) ) {
    			res += string(prev)
    		}
    		res += string(char)
    		prev = char
    		cnt = 1
    	} else {
    	    if ( ! strings.ContainsRune(vowels, char) ) {
    	        res += string(char)
    	    }
    		cnt++
    	}
    	//fmt.Println(string(char), cnt)
    }
    if ( cnt == 2 && strings.ContainsRune(special, prev) ) {
    	res += string(prev)
    }
    fmt.Println(res)
    return
}

package main

import "fmt"

func main() {
	var s string
	var n int
	fmt.Scan(&n)
	fmt.Scan(&s)
	l := len(s)
	flag := 0
	fmt.Printf("%c", s[0])
	for i := 1; i < l; i++ {
	    if (s[i] != s[i - 1]) {
	        if (flag == 2) {
                fmt.Printf("%c", s[i - 1])
            }
            fmt.Printf("%c", s[i])
            flag = 0
	    }
	    if (s[i] == 'e') {
	        flag += 1
	    } else  if (s[i] == 'o') {
	        flag += 1
	    }
    }
    if (flag == 2) {
        fmt.Printf("%c", s[l - 1])
    }
}

package main

import "fmt"

func main() {
	var s string
	var n int
	fmt.Scan(&n)
	fmt.Scan(&s)
	l := len(s)
	fmt.Printf("%c", s[0])
	for i := 1; i < l; i++ {
	    if (s[i] != s[i - 1]) {
            fmt.Printf("%c", s[i])
	    }
    }
}

package main

import "fmt"

func main() {
	var s string
	var n int
	fmt.Scan(&n)
	fmt.Scan(&s)
	l := len(s)
	flag := 0
	fmt.Printf("%c", s[0])
	for i := 1; i < l; i++ {
	    if (s[i] != s[i - 1]) {
	        if (flag == 2) {
                fmt.Printf("%c", s[i - 1])
            }
            fmt.Printf("%c", s[i])
            flag = 0
	    } else if (s[i] != 'a') {
	        if (s[i] != 'o') {
	            if (s[i] != 'e') {
	                if (s[i] != 'i') {
	                    if (s[i] != 'u') {
	                        if (s[i] != 'y') {
	                            fmt.Printf("%c", s[i])
	                        }
	                    }
	                }
	            }
	        }
	    }
	    if (s[i] == 'e') {
	        flag += 1
	    } else  if (s[i] == 'o') {
	        flag += 1
	    }
    }
    if (flag == 2) {
        fmt.Printf("%c", s[l - 1])
    }
}

package main

import "fmt"
func in(a byte, list []byte) bool {
    for _, b := range list {
        if b == a {
            return true
        }
    }
    return false
}
func main() {
	var s string
	var ss string
	var n int
	fmt.Scan(&n)
	fmt.Scan(&s)
	cc := s[0]
	glass := []byte{'e','u','i','o','a','y'}
	count := 0
	for i := 1; i < len(s); i++ {
	    c := s[i]
	    if c == cc {
	        count++
	    } else if(in(cc, glass)) {
	        if (count == 2 && (cc == 'e' || cc == 'o')) {
	            ss += string(cc)
	            ss += string(cc)
	        } else {
	            ss += string(cc)
	        }
	        cc = c
	        count = 1
	    } else {
	        for l := 0; l < count; l++ {
	            ss += string(cc)
	        }
	        cc = c
	        count = 1
	    }
	}
	if(in(cc, glass)) {
	        if (count == 2 && (cc == 'e' || cc == 'o')) {
	            ss += string(cc)
	            ss += string(cc)
	        } else {
	            ss += string(cc)
	        }
	    } else {
	        for l := 0; l < count; l++ {
	            ss += string(cc)
	        }
	    }
	fmt.Println(ss)
}

package main

import "fmt"

func main() {
	var s string
	var ss string
	var n int
	fmt.Scan(&n)
	fmt.Scan(&s)
	cc := s[0]
	count := 0
	for i := 1; i < len(s); i++ {
	    c := s[i]
	    if c == cc {
	        count++
	    } else {
	        if (count == 2 && (cc == 'e' || cc == 'o')) {
	            ss += string(cc)
	            ss += string(cc)
	        } else {
	            ss += string(cc)
	        }
	        cc = c
	        count = 1
	    }
	}
	if (count == 2 && (cc == 'e' || cc == 'o')) {
	    ss += string(cc)
	    ss += string(cc)
	} else {
	    ss += string(cc)
	}
	fmt.Println(ss)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
    var s string
    fmt.Scanf("%d\n", &n)
    fmt.Scanln(&s)
    res := ""
    //fmt.Printf("%d; %s\n", n, s)

    prev := '0'
    cnt := 0
    vowels := "aeoiuy"
    for _, char := range s {
    	//fmt.Printf("%c %d\n", char, no)
    	if strings.ContainsRune(vowels, char) {
	    	if prev != char {
	    		if cnt == 2 {
	    			res += string(prev)
	    		}
	    		res += string(char)
	    		prev = char
	    		cnt = 1
	    	} else {
	    		cnt++
	    	}
    	} else {
    	    res += string(char)
    	}
    }
    if cnt == 2 {
    	res += string(prev)
    }
    fmt.Println(res)
    return
}

package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	fmt.Printf("%c", s[0]);
	for i := 1; i < n; i++ {
	    if s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' || s[i] == 'y' {
		    if s[i] != s[i-1] {
			    fmt.Printf("%c", s[i]);
		    } else {

		    }
	    } else {
	        fmt.Printf("%c", s[i]);
	    }
	}
}


This is the easy version of the problem. The only difference is that in this version $$$q = 1$$$.You are given an array of integers $$$a_1, a_2, \ldots, a_n$$$.The cost of a subsegment of the array $$$[l, r]$$$, $$$1 \leq l \leq r \leq n$$$, is the value $$$f(l, r) = \operatorname{sum}(l, r) - \operatorname{xor}(l, r)$$$, where $$$\operatorname{sum}(l, r) = a_l + a_{l+1} + \ldots + a_r$$$, and $$$\operatorname{xor}(l, r) = a_l \oplus a_{l+1} \oplus \ldots \oplus a_r$$$ ($$$\oplus$$$ stands for bitwise XOR).You will have $$$q = 1$$$ query. Each query is given by a pair of numbers $$$L_i$$$, $$$R_i$$$, where $$$1 \leq L_i \leq R_i \leq n$$$. You need to find the subsegment $$$[l, r]$$$, $$$L_i \leq l \leq r \leq R_i$$$, with maximum value $$$f(l, r)$$$. If there are several answers, then among them you need to find a subsegment with the minimum length, that is, the minimum value of $$$r - l + 1$$$.

Each test consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$q$$$ ($$$1 \leq n \leq 10^5$$$, $$$q = 1$$$) — the length of the array and the number of queries. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$) — array elements. $$$i$$$-th of the next $$$q$$$ lines of each test case contains two integers $$$L_i$$$ and $$$R_i$$$ ($$$1 \leq L_i \leq R_i \leq n$$$) — the boundaries in which we need to find the segment. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. It is guaranteed that $$$L_1 = 1$$$ and $$$R_1 = n$$$.

For each test case print $$$q$$$ pairs of numbers $$$L_i \leq l \leq r \leq R_i$$$ such that the value $$$f(l, r)$$$ is maximum and among such the length $$$r - l + 1$$$ is minimum. If there are several correct answers, print any of them.

NoteIn the first test case, $$$f(1, 1) = 0 - 0 = 0$$$.In the second test case, $$$f(1, 1) = 5 - 5 = 0$$$, $$$f(2, 2) = 10 - 10 = 0$$$. Note that $$$f(1, 2) = (10 + 5) - (10 \oplus 5) = 0$$$, but we need to find a subsegment with the minimum length among the maximum values of $$$f(l, r)$$$. So, only segments $$$[1, 1]$$$ and $$$[2, 2]$$$ are the correct answers.In the fourth test case, $$$f(2, 3) = (12 + 8) - (12 \oplus 8) = 16$$$. There are two correct answers in the fifth test case, since $$$f(2, 3) = f(3, 4)$$$ and their lengths are equal.

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n, q, ql, qr int
		Fscan(in, &n, &q)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		Fscan(in, &ql, &qr)
		sum := make([]int64, len(a)+1)
		for i, v := range a {
			sum[i+1] = sum[i] + v
		}
		xor := make([]int64, len(a)+1)
		for i, v := range a {
			xor[i+1] = xor[i] ^ v
		}
		mx, ll, rr := sum[n]-xor[n], 0, n
		//f := func(l, r int) {
		//	d := sum[r] - sum[l] - (xor[r] ^ xor[l])
		//	if d > mx || d == mx && r-l < rr-ll {
		//		mx, ll, rr = d, l, r
		//	}
		//}
		for l := 0; l < n; l++ {
			r := sort.Search(n, func(r int) bool {
				if r < l {
					return false
				}
				d := sum[r] - sum[l] - (xor[r] ^ xor[l])
				return d == mx
			})
			d := sum[r] - sum[l] - (xor[r] ^ xor[l])
			if d == mx && r-l < rr-ll {
				ll,rr = l,r
			}
		}
		if ll == rr {
			Fprintln(out, 1,1)
			return
		}
		Fprintln(out, ll+1, rr)
		//Fprintln(out, rr-ll)
	}

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

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

}

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

package main

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

// https://space.bilibili.com/206214
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	solve := func(curCase int) {
		var n ,q,ll,rr int
		Fscan(in, &n,&q)
		a := make([]int64, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		Fscan(in, &ll, &rr)
		sum := int64(0)
		xor := int64(0)
		for _, v := range a {
			sum += v
			xor ^= v
		}
		cur := sum - xor
		l, r := 0, n-1
		for l < r && sum-a[l]-(xor^a[l]) == cur {
			sum -= a[l]
			xor ^= a[l]
			l++
		}
		for r > l && sum-a[r]-(xor^a[r]) == cur {
			sum -= a[r]
			xor ^= a[r]
			r--
		}
		Fprintln(out, l+1, r+1)
	}

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

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

}

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


People worry that computers will get too smart and take over the world, but the real problem is that they're too stupid and they've already taken over the world.— Pedro DomingosYou work for a well-known department store that uses leading technologies and employs mechanistic work — that is, robots!The department you work in sells $$$n \cdot k$$$ items. The first item costs $$$1$$$ dollar, the second item costs $$$2$$$ dollars, and so on: $$$i$$$-th item costs $$$i$$$ dollars. The items are situated on shelves. The items form a rectangular grid: there are $$$n$$$ shelves in total, and each shelf contains exactly $$$k$$$ items. We will denote by $$$a_{i,j}$$$ the price of $$$j$$$-th item (counting from the left) on the $$$i$$$-th shelf, $$$1 \le i \le n, 1 \le j \le k$$$.Occasionally robots get curious and ponder on the following question: what is the mean price (arithmetic average) of items $$$a_{i,l}, a_{i,l+1}, \ldots, a_{i,r}$$$ for some shelf $$$i$$$ and indices $$$l \le r$$$? Unfortunately, the old robots can only work with whole numbers. If the mean price turns out not to be an integer, they break down.You care about robots' welfare. You want to arrange the items in such a way that the robots cannot theoretically break. Formally, you want to choose such a two-dimensional array $$$a$$$ that:  Every number from $$$1$$$ to $$$n \cdot k$$$ (inclusively) occurs exactly once.  For each $$$i, l, r$$$, the mean price of items from $$$l$$$ to $$$r$$$ on $$$i$$$-th shelf is an integer. Find out if such an arrangement is possible, and if it is, give any example of such arrangement.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The first and only line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 500$$$) — the number of shelves and length of each shelf, respectively. It is guaranteed that the sum $$$n$$$ over all test cases does not exceed $$$500$$$ and the sum $$$k$$$ over all test cases does not exceed $$$500$$$.

Print the answer for each test case. If such an arrangement exists, print "YES" on a single line. After that, print any example on $$$n$$$ lines of $$$k$$$ numbers each, one line per shelf. Each number from $$$1$$$ to $$$n \cdot k$$$ must occur exactly once in the output. If no good arrangement exists, print a single word "NO" on its own line.

/*
https://codeforces.com/contest/1634/problem/C

*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		K, _ := strconv.Atoi(line_arr[1])
		//fmt.Println(N, K)

		var buffer bytes.Buffer
		if K == 1{
			fmt.Println("YES")
			for i:=0; i<N; i++ {
				buffer.WriteString(strconv.Itoa(i+1) + "\n")
			}
			fmt.Println(buffer.String())
		} else if N%2 == 0 {
			fmt.Println("YES")
			kmul := 0
			for i:=0; i<N; i++ {
				var offset int
				if i%2 == 0{
					kmul = i*K
					offset = kmul + 1
				} else {
					offset = kmul + 2
				}
				arr := make([]int, K)
				for j:=0; j<K; j++ {
					arr[j] = offset + j*2
					if j > 0 {
						buffer.WriteString(" ")
					}
					buffer.WriteString(strconv.Itoa(arr[j]))
				}
				buffer.WriteString("\n")
			}
			fmt.Println(buffer.String())
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

/*
7
1 7
5 1
4 2
3 3
4 3
3 4
5 6
---
NO
YES
YES
NO
YES
*/

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

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

	for ; t > 0; t-- {
		var n, k int
		scanf("%d %d\n", &n, &k)

		if n%2 != 0 && k > 1 {
			fmt.Fprintln(writer, "NO")
			continue
		}

		oddNum := 1
		evnNum := 2

		fmt.Fprintln(writer, "YES")
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				for j := 0; j < k; j++ {
					fmt.Fprintf(writer, "%d ", oddNum)
					oddNum += 2
				}
			} else {
				for j := 0; j < k; j++ {
					fmt.Fprintf(writer, "%d ", evnNum)
					evnNum += 2
				}
			}
			fmt.Fprintln(writer)
		}
	}
}

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	res bool
)

func main() {
	initBuffer()
	var t int = 1
	t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
}

func count() {
	res = k == 1 || n % 2 == 0
}

func output() {
	if yes(res, true) {
		for i := 0; i < n; i++ {
			for j := 0; j < k; j++ {
				out.Write(intToBytes(j * n + i + 1))
				out.WriteByte(SP)
			}
			out.WriteByte(NL)
		}
	}
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

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

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

	solve := func(curCase int) {
		var n, m int
		Fscan(in, &n, &m)
		if m == 1 {
			Fprintln(out, "YES")
			for i := 1; i <= n; i++ {
				Fprintln(out, i)
			}
			return
		}
		if n&1 != 0 {
			Fprintln(out, "NO")
			return
		}
		Fprintln(out, "YES")
		ans := make([][]int, n)
		for i := range ans {
			ans[i] = make([]int, m)
		}
		k := 1
		for i := 0; i < n; i+=2 {
			for j := 0; j < m; j++ {
				ans[i][j] = k
				k++
				ans[i+1][j] = k
				k++
			}
		}

		for _, r := range ans {
			for _, v := range r {
				Fprint(out, v, " ")
			}
			Fprintln(out)
		}
	}

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

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

}

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

// 00
package main

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

func write(f *bufio.Writer, a ...interface{}) {
	f.Write([]byte(fmt.Sprint(a...)))
}

type Number interface {
	int64 | float64 | int
}

func min[K Number](a K, b K) K {
	if a < b {
		return a
	}
	return b
}
func max[K Number](a K, b K) K {
	if a > b {
		return a
	}
	return b
}
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 n, k int
		fmt.Fscan(reader, &n, &k)
		if n%2 == 1 && k != 1 {
			write(f, "NO\n")
		} else {
			write(f, "YES\n")
			odd_start := 1
			even_start := 2
			for i := 0; i < n; i++ {
				for j := 0; j < k; j++ {
					if i%2 == 0 {
						write(f, odd_start)
						odd_start += 2
					} else {
						write(f, even_start)
						even_start += 2
					}
					if j == k-1 {
						write(f, "\n")
					} else {
						write(f, " ")
					}
				}
			}
		}
	}
}

//nolint
package main

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

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

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

//}

func Solve() {
	var n, k int
	scan(&n, &k)
	if k == 1 {
		println("YES")
		for i := 0; i < n; i++ {
			println(i + 1)
		}
		return
	}
	if n%2 == 1 {
		println("NO")
	} else {
		println("YES")
		for i := 1; i <= n; i++ {
			for j := 0; j < k; j++ {
				print(i+j*n, " ")
			}
			println()
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var tests int
	fmt.Fscan(in, &tests)
	for t := 0; t < tests; t++ {
		var n, k int
		fmt.Fscan(in, &n, &k)
		if k == 1 {
			fmt.Println("YES")
			for i := 1; i <= n; i++ {
				fmt.Println(i)
			}
			continue
		}
		if n%2 == 1 {
			fmt.Println("NO")
			continue
		}
		fmt.Println("YES")
		for i := 1; i <= n; i++ {
			for j := i; j <= n*k; j += n {
				fmt.Print(j, " ")
			}
			fmt.Println()
		}
	}
}

package main

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

const MOD int64 = 1000000007

var n, k int

// ByAge implements sort.Interface based on the Age field.
type ByV []*pair

func (a ByV) Len() int           { return len(a) }
func (a ByV) Less(i, j int) bool { return a[i].v < a[j].v }
func (a ByV) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {

	read := bufio.NewReader(os.Stdin)

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

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

		fmt.Fscan(read, &n, &k)
		solve()
	}
}

type pair struct {
	v int
	idx []int
}

func solve()  {
	if n % 2 == 1 {

		if k > 1 {
			fmt.Println("NO")
			return
		}
		fmt.Println("YES")

		var cur int = 1

		for i := 0; i < n; i++ {
			for j := 0; j < 1; j++ {
				fmt.Println(cur)
			}
			cur++
		}
		return

	} else {
		fmt.Println("YES")

		odd := 1
		ev := 2

		for i := 0; i < n/2; i++ {
			for j := 0; j < k; j++ {
				fmt.Print(odd, " ")
				odd += 2
			}
			fmt.Println()
		}
		for i := 0; i < n/2; i++ {
			for j := 0; j < k; j++ {
				fmt.Print(ev, " ")
				ev += 2
			}
			fmt.Println()
		}

		return
	}
}

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

package main

import (
	"bufio"
	"crypto/rand"
	"fmt"
	"math"
	"math/big"
	"os"
	"sort"
	"strconv"
)

func main() {

	reader := bufio.NewReader(os.Stdin)
	writter := bufio.NewWriter(os.Stdout)
	defer writter.Flush()

	t := 0
	fmt.Fscan(reader, &t)

	for t > 0 {
		n, k := 0, 0
		fmt.Fscan(reader, &n, &k)

		result, array := solve(n, k)

		fmt.Fprintln(writter, result)
		for i := range array {
			for j := range array[i] {
				fmt.Fprintf(writter, "%d ", array[i][j])
			}
			fmt.Fprintln(writter)
		}

		t--
	}

	// n, k := 4, 3
	// result, array := solve(n, k)
	// fmt.Println(result)
	// printMatrix(array)

	//getPower()

}

func solve(n, k int) (result string, array [][]int) {

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

	if k == 1 {
		result = "YES"

		now := 1
		for i := range array {
			for j := range array[i] {
				array[i][j] = now
				now++
			}
		}
	} else {
		if n%2 == 0 {
			result = "YES"
			one := 1
			now := one
			for i := range array {
				for j := range array[i] {
					array[i][j] = now
					now += 2
				}

				if i%2 == 0 {
					now = one + 1
				} else {
					one = now - 1
					now = one
				}
			}
		} else {
			result = "NO"
			array = [][]int{}
		}
	}

	return
}

func palindrome(str string) bool {

	size := len(str)

	for i := 0; i < size/2; i++ {
		if str[i] != str[size-1-i] {
			return false
		}
	}

	return true

}

func reverseString(str string) string {
	result := ""

	for i := len(str) - 1; i >= 0; i-- {

		result += string(str[i])

	}

	return result
}

func arraySum(array []int) int {
	sum := 0

	for i := range array {
		sum += array[i]
	}

	return sum
}

func numSum(num int) int {
	sum := 0

	for i := num; i > 0; i-- {
		sum += i
	}

	return sum
}

func strToint(str string) int {
	num, _ := strconv.Atoi(str)
	return num
}

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

	return b
}

func getFactor(num int) []int {
	result := []int{}

	for i := 1; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			result = append(result, i)
			result = append(result, num/i)
		}
	}

	return result
}

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

	return gcd(b%a, a)
}

func printMatrix(matrix [][]int) {
	for i := range matrix {

		for j := range matrix[i] {
			fmt.Printf("%d ", matrix[i][j])
		}

		fmt.Println()

	}
}

func checkPrime(num int) bool {

	if num < 2 {
		return false
	}

	for i := 2; i <= int(math.Sqrt(float64(num))); i++ {
		if num%i == 0 {
			return false
		}
	}

	return true
}

func getPower() {
	A := []int{}

	for i := 1; i <= 38; i++ {
		A = append(A, i)
	}

	for j := 0; j < 10000; j++ {
		for i := range A {
			target, _ := rand.Int(rand.Reader, big.NewInt(38))
			A[i], A[target.Int64()] = A[target.Int64()], A[i]
		}
	}

	B, _ := rand.Int(rand.Reader, big.NewInt(8))

	result := A[:6]
	sort.Ints(result)

	fmt.Println(result)
	fmt.Println(int(B.Int64()) + 1)
}

func xor(a, b int) int {
	aBit := strconv.FormatInt(int64(a), 2)
	bBit := strconv.FormatInt(int64(b), 2)

	size := max(len(aBit), len(bBit))

	for i := size - len(aBit); i > 0; i-- {
		aBit = "0" + aBit
	}
	for i := size - len(bBit); i > 0; i-- {
		bBit = "0" + bBit
	}

	result := ""
	for i := range aBit {
		if aBit[i] == bBit[i] {
			result += "0"
		} else {
			result += "1"
		}
	}

	//fmt.Println(result)
	num, _ := strconv.ParseInt(result, 2, 64)

	return int(num)
}

package main

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

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

func flush()                            { out.Flush() }
func scan(a ...interface{})             { fmt.Fscan(in, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(out, f, a...) }
func assert(f bool) {
	if !f {
		panic("gg")
	}
}

// ----------------------------- TEMPLATE END ----------------------------------

const TAM = 501

var ans [TAM][TAM]int

func main() {
	defer flush()

	var ntc int
	scan(&ntc)
	for t := 0; t < ntc; t++ {
		var n, k int
		scan(&n, &k)
		if n*k == 1 {
			printf("YES\n1\n")
		} else {
			var even = 2
			var odd = 1
			for i := 0; i < n; i++ {
				if even <= n*k {
					for j := 0; j < k; j++ {
						ans[i][j] = even
						even += 2
					}
				} else {
					for j := 0; j < k; j++ {
						ans[i][j] = odd
						odd += 2
					}
				}
			}
			if even-2 > n*k || odd-2 > n*k {
				printf("NO\n")
			} else {
				printf("YES\n")
				for i := 0; i < n; i++ {
					for j := 0; j < k; j++ {
						printf("%d ", ans[i][j])
					}
					printf("\n")
				}
			}
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscan(in, &t)

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

		if n == 1 && k == 1 {
			fmt.Fprintln(out, "YES")
			fmt.Fprintln(out, "1")
		} else {
			if n%2 != 0 && k != 1 {
				fmt.Fprintln(out, "NO")
			} else if k == 1 {
				fmt.Fprintln(out, "YES")
				for i, x := 0, 1; i < n; i++ {
					fmt.Fprintln(out, x)
					x++
				}
			} else {
				fmt.Fprintln(out, "YES")
				for i, x := 0, 1; i < n/2; i++ {
					for j := 0; j < k; j++ {
						if j > 0 {
							fmt.Fprint(out, " ")
						}
						fmt.Fprint(out, x)
						x += 2
					}
					fmt.Fprintln(out)
				}
				for i, x := 0, 2; i < n/2; i++ {
					for j := 0; j < k; j++ {
						if j > 0 {
							fmt.Fprint(out, " ")
						}
						fmt.Fprint(out, x)
						x += 2
					}
					fmt.Fprintln(out)
				}
			}
		}

	}
}

package main

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

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

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

		isValid := true
		o := 1
		e := 2
		m := make([][]int, n)
		for i := 0; i < n; i++ {
			row := make([]int, k)
			if i%2 == 0 {
				row[0] = o
				o += k * 2
			} else {
				row[0] = e
				e += k * 2
			}

			for j := 1; j < k; j++ {
				row[j] = row[j-1] + 2
			}

			if row[k-1] > n*k {
				isValid = false
				break
			}

			m[i] = row
		}

		if !isValid {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
			for _, row := range m {
				for _, v := range row {
					fmt.Fprintf(out, "%d ", v)
				}
				fmt.Fprintln(out)
			}
		}
	}
}

/*
https://codeforces.com/contest/1634/problem/C

*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		K, _ := strconv.Atoi(line_arr[1])
		//fmt.Println(N, K)

		var buffer bytes.Buffer
		if K == 1{
			fmt.Println("YES")
			for i:=0; i<N; i++ {
				buffer.WriteString(strconv.Itoa(i+1))
			}
			fmt.Println(buffer.String())
		} else if N%2 == 0 {
			fmt.Println("YES")
			kmul := 0
			for i:=0; i<N; i++ {
				var offset int
				if i%2 == 0{
					kmul = i*K
					offset = kmul + 1
				} else {
					offset = kmul + 2
				}
				arr := make([]int, K)
				for j:=0; j<K; j++ {
					arr[j] = offset + j*2
					if j > 0 {
						buffer.WriteString(" ")
					}
					buffer.WriteString(strconv.Itoa(arr[j]))
				}
				buffer.WriteString("\n")
			}
			fmt.Println(buffer.String())
		} else {
			fmt.Println("NO")
		}
	}

}

/*
https://codeforces.com/contest/1634/problem/C

*/

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		K, _ := strconv.Atoi(line_arr[1])
		//fmt.Println(N, K)

		if K == 1{
			fmt.Println("YES")
			for i:=0; i<N; i++ {
				fmt.Println(i+1)
			}
			continue
		} else if N%2 == 0 {
			fmt.Println("YES")
			kmul := 0
			for i:=0; i<N; i++ {
				var offset int
				if i%2 == 0{
					kmul = i*K
					offset = kmul + 1
				} else {
					offset = kmul + 2
				}
				arr := make([]int, K)
				for j:=0; j<K; j++ {
					arr[j] = offset + j*2
				}
				fmt.Println(arr)
			}
		} else {
			fmt.Println("NO")
		}
	}

}

package main

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

/*
7
1 7
5 1
4 2
3 3
4 3
3 4
5 6
---
NO
YES
YES
NO
YES
*/

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

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

	for ; t > 0; t-- {
		var n, k int
		scanf("%d %d\n", &n, &k)

		nk := n * k

		if (nk%2 != 0 && k > 1) || k > 4 {
			fmt.Fprintln(writer, "NO")
			continue
		}

		oddNum := 1
		evnNum := 2

		fmt.Fprintln(writer, "YES")
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				for j := 0; j < k; j++ {
					fmt.Fprintf(writer, "%d ", oddNum)
					oddNum += 2
				}
			} else {
				for j := 0; j < k; j++ {
					fmt.Fprintf(writer, "%d ", evnNum)
					evnNum += 2
				}
			}
			fmt.Fprintln(writer)
		}
	}
}

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

/*
6
1 7
5 1
4 2
3 3
4 3
3 4
---
NO
YES
YES
NO
YES
*/

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

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

	for ; t > 0; t-- {
		var n, k int
		scanf("%d %d\n", &n, &k)

		nk := n * k

		if nk%2 != 0 && k > 1 {
			fmt.Fprintln(writer, "NO")
			continue
		}

		oddNum := 1
		evnNum := 2

		fmt.Fprintln(writer, "YES")
		for i := 0; i < n; i++ {
			if i%2 == 0 {
				for j := 0; j < k; j++ {
					fmt.Fprintf(writer, "%d ", oddNum)
					oddNum += 2
				}
			} else {
				for j := 0; j < k; j++ {
					fmt.Fprintf(writer, "%d ", evnNum)
					evnNum += 2
				}
			}
			fmt.Fprintln(writer)
		}
	}
}

func helper(i, d, y int64, a []int64, cache map[int64]bool) bool {
	if i == int64(len(a)) {
		return false
	}

	sum := d + a[i]
	xor := d ^ a[i]

	fmt.Fprintf(writer, "i=%d: %d %d\n", i, sum, xor)

	if i == int64(len(a))-1 && (sum == y || xor == y) {
		return true
	}

	res := false

	if !cache[sum] {
		//cache[sum] = true
		res = helper(i+1, sum, y, a, cache)
	}

	if !res && !cache[xor] {
		//cache[xor] = true
		res = helper(i+1, xor, y, a, cache)
	}

	return res
}

const maxUint = ^uint(0)

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

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

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

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

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

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) int {
	maximum := nums[0]
	for _, num := range nums {
		if num > maximum {
			maximum = num
		}
	}
	return maximum
}

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

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

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

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

	return true
}

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

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

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

	num = abs(num)

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

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

package main

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

const (
	MOD int64 = 1e9+7
	NL byte = byte('\n')
	SP byte = byte(' ')
)

var (
	in *bufio.Scanner
	out *bufio.Writer

	n, k int
	res bool
)

func main() {
	initBuffer()
	var t int = 1
	t = getInt()
	for i := 0; i < t; i++ {
		solve()
	}
	// test()
	out.Flush()
}

func solve() {
	initialize()
	input()
	count()
	output()
}

func initialize() {

}

func input() {
	n = getInt()
	k = getInt()
}

func count() {
	res = k == 1 || n % 2 == 0
}

func output() {
	if yes(res, true) {
		for i := 0; i < n; i++ {
			for j := 0; j < k; j++ {
				out.Write(intToBytes(i * k + j + 1))
				out.WriteByte(SP)
			}
			out.WriteByte(NL)
		}
	}
}

func test() {
	fmt.Print()
}

func initBuffer() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer([]byte{}, 4 * 1024 * 1024)
	in.Split(scanWords)
	out = bufio.NewWriter(os.Stdout)
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	i := bytes.IndexByte(data, '\n')
	j := bytes.IndexByte(data, ' ')
	ind := min(i, j)
	if ind < 0 {
		ind = max(i, j)
	}
	if ind >= 0 {
		return ind + 1, dropCR(data[0:ind]), nil
	}
	if atEOF {
		return len(data), dropCR(data), nil
	}
	return 0, nil, nil
}

func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[:len(data)-1]
	}
	return data
}

func getFloat() float64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res1 int64
	for i := 0; i < len(b); i++ {
		if b[i] == '.' {
			b = b[i+1:]
			break
		}
		res1 *= 10
		res1 += int64(b[i]) - 48
		if i == len(b) - 1 {
			b = b[:0]
		}
	}
	var res2 float64
	for i := len(b); i > 0; i-- {
		res2 += float64(b[i-1]) - 48
		res2 /= 10
	}
	if isNeg {
		res1 *= -1
		res2 *= -1
	}
	return float64(res1) + res2
}

func getInt() int {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getInt64() int64 {
	in.Scan()
	b := in.Bytes()
	var isNeg bool
	if b[0] == '-' {
		isNeg = true
		b = b[1:]
	}
	var res int64
	for i := 0; i < len(b); i++ {
		res *= 10
		res += int64(b[i]) - 48
	}
	if isNeg {
		res *= -1
	}
	return res
}

func getString() string {
	in.Scan()
	return in.Text()
}

func intToBytes(n int) []byte {
	var res [33]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 33
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 33 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func int64ToBytes(n int64) []byte {
	var res [65]byte
	var isNeg bool
	if n < 0 {
		isNeg = true
		n = -n
	}
	var l int = 65
	for n > 0 {
		l--
		res[l] = byte(n % 10 + 48)
		n /= 10
	}
	if l == 65 {
		l--
		res[l] = byte(48)
	}
	if isNeg {
		l--
		res[l] = byte(45)
	}
	return res[l:]
}

func bsLower(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsLower64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] < n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] >= n {
		return minN
	}
	return maxN
}

func bsUpper(arr []int, n int) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func bsUpper64(arr []int64, n int64) int {
	var minN, midN, maxN int
	maxN = len(arr)
	for maxN - 1 > minN {
		midN = (minN + maxN) / 2
		if arr[midN] <= n {
			minN = midN
		} else {
			maxN = midN
		}
	}
	if arr[minN] > n {
		return minN
	}
	return maxN
}

func max(n1, n2 int) int {
	if n1 > n2 {
		return n1
	}
	return n2
}

func max64(n1, n2 int64) int64 {
	if n1 > n2 {
		return n1
	}
	return n2
}

func min(n1, n2 int) int {
	if n1 < n2 {
		return n1
	}
	return n2
}

func min64(n1, n2 int64) int64 {
	if n1 < n2 {
		return n1
	}
	return n2
}

func yes(res, isUpperCase bool) bool {
	var arr [4]string = [4]string{"No", "Yes", "NO", "YES"}
	var ind int
	if res == true {
		ind = 1
	}
	if isUpperCase == true {
		ind += 2
	}
	out.WriteString(arr[ind])
	out.WriteByte(NL)
	return res
}

package main

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

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

	solve := func(curCase int) {
		var n ,m int
		Fscan(in, &n,&m)
		if m == 1 {
			Fprintln(out, "YES")
			for i := 1; i <= n; i++ {
				Fprintln(out, i)
			}
			return
		}
		if n != 2 {
			Fprintln(out, "NO")
			return
		}
		Fprintln(out, "YES")
		for i := 1; i <= m*2; i+=2 {
			Fprint(out, i, " ")
		}
		Fprintln(out)
		for i := 2; i <= m*2; i+=2 {
			Fprint(out, i, " ")
		}
		Fprintln(out)
	}

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

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

}

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


The next lecture in a high school requires two topics to be discussed. The $$$i$$$-th topic is interesting by $$$a_i$$$ units for the teacher and by $$$b_i$$$ units for the students.The pair of topics $$$i$$$ and $$$j$$$ ($$$i < j$$$) is called good if $$$a_i + a_j > b_i + b_j$$$ (i.e. it is more interesting for the teacher).Your task is to find the number of good pairs of topics.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of topics. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the interestingness of the $$$i$$$-th topic for the teacher. The third line of the input contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$), where $$$b_i$$$ is the interestingness of the $$$i$$$-th topic for the students.

Print one integer — the number of good pairs of topic.

package main

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

func morethan(a []int64, v int64) int64 {
	n := int64(len(a))

	if v < a[0] {
		return 0
	}

	if v >= a[n-1] {
		return n
	}

	s := int64(0)
	e := n-1

	for s < e {
		m := (s+e)/2

		if a[m] > v {
			e = m
		} else {
			s = m+1
		}
	}

	return s
}

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

	in := func() int64 {
		sc.Scan()
		i, _ := strconv.ParseInt(sc.Text(), 0, 64)
		return i
	}

	n := in()
	a := make([]int64, n)
	b := make([]int64, n)

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

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

	for i := range a {
		a[i] = a[i] - b[i]
	}

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

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

	fmt.Println(sum)
}

package main

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

func main() {
	var n int64
	fmt.Scanf("%d\n", &n)
	reader := bufio.NewReader(os.Stdin)
	line := readLine(reader)
	ans := strings.Split(string(line), " ")
	line = readLine(reader)
	bns := strings.Split(string(line), " ")
	cn := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a, _ := strconv.ParseInt(ans[i], 10, 64)
		b, _ := strconv.ParseInt(bns[i], 10, 64)
		cn[i] = a - b
	}
	sort.Slice(cn, func(i, j int) bool {
		return cn[i] < cn[j]
	})
	result := int64(0)
	for i:=n-1;i>=0;i-- {
		if cn[i] <=0 {
			break
		}
		k := search(-cn[i], cn, 0, i-1)
		if cn[k] > -cn[i] {
			result += i - k
		}
	}
	fmt.Println(result)
}

func search(k int64, arr []int64, start, end int64) int64 {
	if start >= end {
		return start
	}
	loc := (start + end) / 2
	if arr[loc] > k {
		return search(k, arr, start, loc)
	} else {
		return search(k, arr, loc+1, end)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/problemset/problem/1324/D
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	n    int64
	A, B []int64
)

func main() {
	n = ReadInt64()
	A, B = ReadInt64Slice(int(n)), ReadInt64Slice(int(n))

	C := make([]int64, n)
	for i := int64(0); i < n; i++ {
		C[i] = -A[i] + B[i]
	}
	sort.Slice(C, func(i, j int) bool {
		return C[i] < C[j]
	})

	ans := int64(0)
	for i := int64(0); i < n; i++ {
		key := A[i] - B[i]
		ok := BinarySearch(-1, n, func(mid int64) bool {
			return key > C[mid]
		})
		ok++

		if key > -key {
			ok--
		}

		ans += ok
	}

	ans /= 2
	fmt.Println(ans)
}

func BinarySearch(initOK, initNG int64, isOK func(mid int64) bool) (ok int64) {
	ng := initNG
	ok = initOK
	for int(math.Abs(float64(ok-ng))) > 1 {
		mid := (ok + ng) / 2
		if isOK(mid) {
			ok = mid
		} else {
			ng = mid
		}
	}

	return ok
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1324D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	var n, v int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	for i := range a {
		Fscan(in, &v)
		a[i] -= v
	}
	sort.Ints(a)
	ans := int64(0)
	for i, v := range a {
		if j := sort.SearchInts(a[:i], 1-v); j < i {
			ans += int64(i - j)
		}
	}
	Fprint(_w, ans)
}

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

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	topics := make([][]int, n)
	for i := 0; i < n; i++ {
		topics[i] = make([]int, 2)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &topics[i][0])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &topics[i][1])
	}
	rls := solve(topics)
	fmt.Println(rls)
}

func solve(topics [][]int) int64 {
	n := len(topics)
	sort.Slice(topics, func(i, j int) bool {
		v1 := topics[i][0] - topics[i][1]
		v2 := topics[j][0] - topics[j][1]
		return v1 < v2
	})
	rls := int64(0)
	for i := n - 1; i > 0; i-- {
		idx := sort.Search(i, func(j int) bool {
			return topics[j][0]-topics[j][1] > topics[i][1]-topics[i][0]
		})
		rls += int64(i - idx)
	}
	return rls
}

package main

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

func main() {
	noOfTopics := scanInt64()
	teacherArray := scanInt64Slice(int(noOfTopics))
	studentArray := scanInt64Slice(int(noOfTopics))

	for i := int64(0); i < noOfTopics; i++ {
		teacherArray[i] -= studentArray[i]
	}

	sortInt64Slice(teacherArray)
	left, right, count := int64(0), noOfTopics-1, int64(0)
	for left < right{
		if teacherArray[left] + teacherArray[right] > 0{
			count += right - left
			right--
		}else{
			left++
		}
	}

	printFmt(count)

	close(channelType)
	oWg.Wait()
}

func getMax(n, m int) string {
	var max string
	for m > 9 {
		max = max + "9"
		m -= 9
		n--
	}

	max = max + strconv.Itoa(m)
	n--
	for i := 0; i < n; i++ {
		max = max + "0"
	}
	return max
}

func getMin(n, m int) string {
	var min string
	for m > 9 {
		min = "9" + min
		m -= 9
		n--
	}

	if n == 1 {
		min = strconv.Itoa(m) + min
	} else {
		if m > 1 {
			min = strconv.Itoa(m-1) + min
			n--
		}

		for i := 0; i < n-1; i++ {
			min = "0" + min
		}
		min = "1" + min
	}
	return min
}

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

var channelType chan string
var in *bufio.Scanner
var oWg *sync.WaitGroup
var printFmt func(a ...interface{}) (n int, err error)

func init() {
	printFmt = fmt.Println

	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)

	channelType = make(chan string, 16)
	oWg = &sync.WaitGroup{}
	oWg.Add(1)

	writer := bufio.NewWriter(os.Stdout)
	go func() {
		defer oWg.Done()
		defer writer.Flush()

		for line := range channelType {
			writer.WriteString(line + "\n")
		}
	}()
}

func scanString() string { in.Scan(); return in.Text() }
func scanInt() int       { i, _ := strconv.Atoi(scanString()); return i }
func scanInt64() int64   { i, _ := strconv.ParseInt(scanString(), 10, 64); return i }
func scanStringSlice(n int) []string {
	s := make([]string, n);
	for i := 0; i < n; i++ {
		s[i] = scanString()
	};
	return s
}
func scanIntSlice(n int) []int {
	arr := make([]int, n);
	for i := 0; i < n; i++ {
		arr[i] = scanInt()
	};
	return arr
}
func scanInt64Slice(n int) []int64 {
	arr := make([]int64, n);
	for i := 0; i < n; i++ {
		arr[i] = scanInt64()
	};
	return arr
}

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

func stringEquivalent(v interface{}) string { return fmt.Sprintf("%v", v) }
func spaceSeperatedStringFromArray(a []int) string {
	sb := strings.Builder{};
	sb.Grow(len(a) * 9);
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	};
	return sb.String()
}
func spaceSeperatedStringFromArray64(a []int64) string {
	sb := strings.Builder{};
	sb.Grow(len(a) * 9);
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	};
	return sb.String()
}
func minMaxFromArray(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64);
	for _, v := range args {
		if v < minVal {
			minVal = v
		};
		if v > maxVal {
			maxVal = v
		}
	};
	return minVal, maxVal
}
func minElementFromArray(args ...int64) int64 { mn, _ := minMaxFromArray(args...); return mn }
func maxElementFromArray(args ...int64) int64 { _, mx := minMaxFromArray(args...); return mx }
func lcmCalculation(a, b int64) int64         { return a / gcdCalculation(a, b) * b }
func gcdCalculation(a, b int64) int64 {
	if (a == 0) {
		return b
	};
	return gcdCalculation(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func absoluteValue(x int64) int64 {
	if x < 0 {
		return -x
	};
	return x
}
func min(args ...int) int { mn, _ := minMaxFinder(args...); return mn }
func max(args ...int) int { _, mx := minMaxFinder(args...); return mx }
func minMaxFinder(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32);
	for _, v := range args {
		if v < minVal {
			minVal = v
		};
		if v > maxVal {
			maxVal = v
		}
	};
	return minVal, maxVal
}

package main

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

func morethan(a []int, v int) int {
	n := len(a)

	if v < a[0] {
		return 0
	}

	if v >= a[n-1] {
		return n
	}

	s := 0
	e := n-1

	for s < e {
		m := (s+e)/2

		if a[m] > v {
			e = m
		} else {
			s = m+1
		}
	}

	return s
}

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

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

	n := in()
	a := make([]int, n)
	b := make([]int, n)

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

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

	for i := range a {
		a[i] = a[i] - b[i]
	}

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

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

	fmt.Println(sum)
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1324D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	var n, v, ans int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	for i := range a {
		Fscan(in, &v)
		a[i] -= v
	}
	sort.Ints(a)
	for i, v := range a {
		if j := sort.SearchInts(a[:i], 1-v); j < i {
			ans += i - j
		}
	}
	Fprint(_w, ans)
}

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

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)
	topics := make([][]int, n)
	for i := 0; i < n; i++ {
		topics[i] = make([]int, 2)
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &topics[i][0])
	}
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &topics[i][1])
	}
	rls := solve(topics)
	fmt.Println(rls)
}

func solve(topics [][]int) int {
	n := len(topics)
	sort.Slice(topics, func(i, j int) bool {
		v1 := topics[i][0] - topics[i][1]
		v2 := topics[j][0] - topics[j][1]
		return v1 < v2
	})
	rls := 0
	for i := n - 1; i > 0; i-- {
		idx := sort.Search(i, func(j int) bool {
			return topics[j][0]-topics[j][1] > topics[i][1]-topics[i][0]
		})
		rls += i - idx
	}
	return rls
}


The busses in Berland are equipped with a video surveillance system. The system records information about changes in the number of passengers in a bus after stops.If $$$x$$$ is the number of passengers in a bus just before the current bus stop and $$$y$$$ is the number of passengers in the bus just after current bus stop, the system records the number $$$y-x$$$. So the system records show how number of passengers changed.The test run was made for single bus and $$$n$$$ bus stops. Thus, the system recorded the sequence of integers $$$a_1, a_2, \dots, a_n$$$ (exactly one number for each bus stop), where $$$a_i$$$ is the record for the bus stop $$$i$$$. The bus stops are numbered from $$$1$$$ to $$$n$$$ in chronological order.Determine the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$ (that is, at any time in the bus there should be from $$$0$$$ to $$$w$$$ passengers inclusive).

The first line contains two integers $$$n$$$ and $$$w$$$ $$$(1 \le n \le 1\,000, 1 \le w \le 10^{9})$$$ — the number of bus stops and the capacity of the bus. The second line contains a sequence $$$a_1, a_2, \dots, a_n$$$ $$$(-10^{6} \le a_i \le 10^{6})$$$, where $$$a_i$$$ equals to the number, which has been recorded by the video system after the $$$i$$$-th bus stop.

Print the number of possible ways how many people could be in the bus before the first bus stop, if the bus has a capacity equals to $$$w$$$. If the situation is contradictory (i.e. for any initial number of passengers there will be a contradiction), print 0.

NoteIn the first example initially in the bus could be $$$0$$$, $$$1$$$ or $$$2$$$ passengers.In the second example initially in the bus could be $$$1$$$, $$$2$$$, $$$3$$$ or $$$4$$$ passengers.In the third example initially in the bus could be $$$0$$$ or $$$1$$$ passenger.

package main

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

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

func ReadInt64() int64 {
    scanner.Scan()
    ans, _ := strconv.ParseInt(scanner.Text(),10,64)
    return ans
}

func ReadInt32() int {
    scanner.Scan()
    ans, _ := strconv.Atoi(scanner.Text())
    return ans
}

func PrintInts(ints ...int64) {
    for _, value := range ints {
        writer.WriteString(strconv.FormatInt(value, 10))
        writer.WriteByte(' ')
    }
}

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

	n, w := ReadInt32(), ReadInt32()

	i := 0
	j := w

	menor := 0
	maior := 0

	offset := 0

	for ; n > 0; n-- {
		val := ReadInt32()

		offset += val

		if offset > maior {
			j -= (offset - maior)
			maior = offset
		}
		if offset < menor {
			i += (menor - offset)
			menor = offset
		}
	}

	if i > j {
		writer.WriteString(strconv.Itoa(0))
	} else {
		writer.WriteString(strconv.Itoa(j - i + 1))
	}

}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 2048*2048), 2048*2048)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	w, _ := strconv.Atoi(scanner.Text())

	a := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
	}

	pred_high := func(val int) bool {
		for i := 0; i < n; i++ {
			val += a[i]
			if val > w {
				return true
			}
		}
		return false
	}

	pred_low := func(val int) bool {
		for i := 0; i < n; i++ {
			val += a[i]
			if val < 0 {
				return false
			}
		}
		return true
	}

	l := 0
	r := w
	for l < r {
		m := l + (r-l)/2
		if pred_low(m) {
			r = m
		} else {
			l = m + 1
		}
	}

	ll := 0
	rr := w
	for ll < rr {
		m := ll + (rr-ll+1)/2
		if pred_high(m) {
			rr = m - 1
		} else {
			ll = m
		}
	}

	if !pred_low(l) {
		fmt.Println(0)
		return
	}
	if pred_high(ll) {
		fmt.Println(0)
		return
	}
	if l > ll {
		fmt.Println(0)
		return
	}

	fmt.Println(ll - l + 1)
}

package main

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

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

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

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

	var n int
	var w int64
	fmt.Fscan(in, &n, &w)
	var t, tmp int64
	fmt.Fscan(in, &tmp)
	mn, mx := tmp, tmp
	for i := 1; i < n; i++ {
		fmt.Fscan(in, &t)
		tmp += t
		mx = max(mx, tmp)
		mn = min(mn, tmp)
	}
	l, r := int64(0), w
	if mn < 0 {
		l =  -mn
	} else {
		r = w - mn
	}
	if mx > 0 {
		r = min(r, w-mx)
	} else {
		l = max(l, -mx)
	}
	fmt.Fprintln(out, max(r-l+1, 0))
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF978E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, w, min, max, s, v, ans int
	Fscan(in, &n, &w)
	for ; n > 0; n-- {
		Fscan(in, &v)
		s += v
		if s < min {
			min = s
		} else if s > max {
			max = s
		}
	}
	if max-min <= w {
		ans = w - max + min + 1
	}
	Fprint(out, ans)
}

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

package main

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

const (
	MaxN = 1024
)

var a, pre [MaxN]int
var n, w int

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d\n", &n, &w)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i - 1] + a[i]
	}
	l, r := 0, 0
	for i := 0; i < n; i++ {
		if pre[i] < 0 && l > pre[i] {
			l = pre[i]
		}
		if pre[i] > 0 && r < pre[i] {
			r = pre[i]
		}
	}
	l = -l
	if l > w - r + 1 {
		fmt.Println(0)
	} else {
		fmt.Println(w - r - l + 1)
	}
}

package main

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

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

	var n int
	var w int

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

	m, M := 0, 0
	s := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Fscan(in, &x)

		s += x
		if s < m {
			m = s
		}
		if s > M {
			M = s
		}
	}

	res := w - M - (-m) + 1
	if res < 0 {
		res = 0
	}
	fmt.Fprintln(out, res)
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 2048*2048), 2048*2048)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	w, _ := strconv.Atoi(scanner.Text())

	a := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		a[i], _ = strconv.Atoi(scanner.Text())
	}

	pred_high := func(val int) bool {
		for i := 0; i < n; i++ {
			val += a[i]
			if val > w {
				return true
			}
		}
		return false
	}

	pred_low := func(val int) bool {
		for i := 0; i < n; i++ {
			val += a[i]
			if val < 0 {
				return false
			}
		}
		return true
	}

	l := 0
	r := w
	for l < r {
		m := l + (r-l)/2
		if pred_low(m) {
			r = m
		} else {
			l = m + 1
		}
	}

	ll := 0
	rr := w
	for ll < rr {
		m := ll + (rr-ll+1)/2
		if pred_high(m) {
			rr = m - 1
		} else {
			ll = m
		}
	}

	if !pred_low(l) {
		fmt.Println(0)
		return
	}
	if pred_high(ll) {
		fmt.Println(0)
		return
	}
	if l >= ll {
		fmt.Println(0)
		return
	}

	fmt.Println(ll - l + 1)
}

package main

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

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

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

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

	var n int
	var w int64
	fmt.Fscan(in, &n, &w)
	var t, tmp int64
	fmt.Fscan(in, &tmp)
	mn, mx := tmp, tmp
	for i := 1; i < n; i++ {
		fmt.Fscan(in, &t)
		tmp += t
		mx = max(mx, tmp)
		mn = min(mn, tmp)
	}
	l, r := int64(0), w
	if mn < 0 {
		l =  -mn
	} else {
		r = w - mn
	}
	if mx > 0 {
		r = min(r, w-mx)
	} else {
		l = max(l, -mx)
	}
	fmt.Fprintln(out, r-l+1)
}


Polycarp is in really serious trouble — his house is on fire! It's time to save the most valuable items. Polycarp estimated that it would take ti seconds to save i-th item. In addition, for each item, he estimated the value of di — the moment after which the item i will be completely burned and will no longer be valuable for him at all. In particular, if ti ≥ di, then i-th item cannot be saved.Given the values pi for each of the items, find a set of items that Polycarp can save such that the total value of this items is maximum possible. Polycarp saves the items one after another. For example, if he takes item a first, and then item b, then the item a will be saved in ta seconds, and the item b — in ta + tb seconds after fire started.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of items in Polycarp's house. Each of the following n lines contains three integers ti, di, pi (1 ≤ ti ≤ 20, 1 ≤ di ≤ 2 000, 1 ≤ pi ≤ 20) — the time needed to save the item i, the time after which the item i will burn completely and the value of item i.

In the first line print the maximum possible total value of the set of saved items. In the second line print one integer m — the number of items in the desired set. In the third line print m distinct integers — numbers of the saved items in the order Polycarp saves them. Items are 1-indexed in the same order in which they appear in the input. If there are several answers, print any of them.

NoteIn the first example Polycarp will have time to save any two items, but in order to maximize the total value of the saved items, he must save the second and the third item. For example, he can firstly save the third item in 3 seconds, and then save the second item in another 2 seconds. Thus, the total value of the saved items will be 6 + 5 = 11.In the second example Polycarp can save only the first item, since even if he immediately starts saving the second item, he can save it in 3 seconds, but this item will already be completely burned by this time.

package main

import (
	"fmt"
	"sort"
)

type item struct {
	t, d, p, idx int
}

type byD []item

func (s byD) Len() int           { return len(s) }
func (s byD) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s byD) Less(i, j int) bool { return s[i].d < s[j].d }

const maxD = 2000

func main() {
	var n int
	fmt.Scan(&n)
	items := make([]item, n)
	for i := range items {
		fmt.Scan(&items[i].t, &items[i].d, &items[i].p)
		items[i].idx = i + 1
	}
	sort.Sort(byD(items))

	value := make([][]int, n+1)
	for i := range value {
		value[i] = make([]int, maxD+1)
		for j := range value[i] {
			value[i][j] = -1
		}
	}
	value[0][0] = 0
	take := make([][]int, n+1)
	for i := range take {
		take[i] = make([]int, maxD+1)
	}

	bestT := 0
	for i, it := range items {
		for t := maxD - 1; t >= 0; t-- {
			value[i+1][t] = value[i][t]
			take[i+1][t] = take[i][t]
		}
		for t := it.d - 1; t >= it.t; t-- {
			cur := value[i][t-it.t]
			if cur == -1 {
				continue
			}
			cur += it.p
			if value[i+1][t] < cur {
				value[i+1][t] = cur
				take[i+1][t] = i
				if value[i+1][bestT] < cur {
					bestT = t
				}
			}
		}
	}

	fmt.Println(value[n][bestT])
	var taken []int
	for t, s := bestT, n; t > 0; {
		it := items[take[s][t]]
		s = take[s][t]
		taken = append(taken, it.idx)
		t -= it.t
	}
	fmt.Println(len(taken))
	for i := len(taken) - 1; i >= 0; i-- {
		if i == 0 {
			fmt.Println(taken[i])
		} else {
			fmt.Print(taken[i], " ")
		}
	}
}

package main

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

type Item struct {
	Time, DestroyTime, Value, Index int
}
type Items []*Item

func (this Items) Len() int           { return len(this) }
func (this Items) Swap(i, j int)      { this[i], this[j] = this[j], this[i] }
func (this Items) Less(i, j int) bool { return this[i].DestroyTime < this[j].DestroyTime }

var dp [101][2001]int
var route [101][2001]int

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var n int

	fmt.Fscanf(reader, "%d\n", &n)
	var items Items
	items = make([]*Item, n)

	for i := 0; i < n; i++ {
		item := Item{}
		fmt.Fscanf(reader, "%d %d %d\n", &item.Time, &item.DestroyTime, &item.Value)
		item.Index = i + 1
		items[i] = &item
	}
	sort.Sort(items)

	for i := 1; i <= n; i++ {
		item := items[i-1]
		for j := 0; j <= 2000; j++ {
			if j != 0 {
				dp[i][j] = dp[i][j-1]
				route[i][j] = 1
			}
			if dp[i][j] < dp[i-1][j] {
				dp[i][j] = dp[i-1][j]
				route[i][j] = 2
			}
			if j < item.DestroyTime && j >= item.Time && dp[i][j] < dp[i-1][j-item.Time]+item.Value {
				dp[i][j] = dp[i-1][j-item.Time] + item.Value
				route[i][j] = 3
			}
		}
	}
	ans := make([]int, 0, n)
	itemPos, timePos := n, 2000
	for itemPos != 0 && timePos != 0 {
		if route[itemPos][timePos] == 3 {
			ans = append(ans, items[itemPos-1].Index)
			timePos = timePos - items[itemPos-1].Time
			itemPos--
		} else if route[itemPos][timePos] == 2 {
			itemPos--
		} else {
			timePos--
		}
	}
	fmt.Printf("%d\n%d\n", dp[n][2000], len(ans))

	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Printf("%d ", ans[i])
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF864E(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	type pair struct{ w, mxW, v, i int }

	var n int
	Fscan(in, &n)
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].w, &a[i].mxW, &a[i].v)
		a[i].i = i + 1
	}
	sort.Slice(a, func(i, j int) bool { return a[i].mxW < a[j].mxW })

	m := a[n-1].mxW
	dp := make([]int, m)
	fa := make([][]int, n)
	for i := range fa {
		fa[i] = make([]int, m)
		for j := range fa[i] {
			fa[i][j] = -1
		}
	}
	for i, p := range a {
		w := p.w
		for j := p.mxW - 1; j >= w; j-- {
			if d := dp[j-w] + p.v; d > dp[j] {
				dp[j] = d
				fa[i][j] = j - w
			}
		}
	}
	mxJ := 0
	for j, v := range dp {
		if v > dp[mxJ] {
			mxJ = j
		}
	}
	Fprintln(out, dp[mxJ])
	ans := []int{}
	for i, j := n-1, mxJ; i >= 0; i-- {
		if fa[i][j] != -1 {
			ans = append(ans, a[i].i)
			j = fa[i][j]
		}
	}
	Fprintln(out, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		Fprint(out, ans[i], " ")
	}
}

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

package main

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

type Node struct {
	num, p, d, t int
}

type Nodes []Node

func (nodes Nodes) Len() int {
	return len(nodes)
}

func (nodes Nodes) Less(i, j int) bool {
	return nodes[i].d < nodes[j].d
}

func (nodes Nodes) Swap(i, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
}

func solve() {
	n := readInt()
	a := make([]Node, n)
	for i := 0; i < n; i++ {
		a[i].t, a[i].d, a[i].p = readInt(), readInt(), readInt()
		a[i].num = i + 1
	}
	sort.Sort(Nodes(a))
	dp := make([][]int, n + 1)
	MAXD := 2001
	dp[0] = make([]int, MAXD)
	for i := 1; i <= n; i++ {
		dp[i] = make([]int, MAXD)
		for j := MAXD - 1; j >= 0; j-- {
			dp[i][j] = dp[i-1][j]
			if j < a[i-1].d && j - a[i-1].t >= 0 {
				dp[i][j] = max(dp[i-1][j-a[i-1].t] + a[i-1].p, dp[i][j])
			}
		}
	}
	pos := 0
	for i := 1; i < MAXD-1; i++ {
		if dp[n][i] > dp[n][pos] {
			pos = i
		}
	}
	ansValue := dp[n][pos]
	ansArray := make([]int, 0)
	for curRow := n; curRow > 0; curRow-- {
		if pos < a[curRow-1].d && pos - a[curRow-1].t >= 0 && dp[curRow][pos] == dp[curRow-1][pos-a[curRow-1].t] + a[curRow-1].p {
			pos -= a[curRow-1].t
			ansArray = append(ansArray, a[curRow-1].num)
		}
	}
	//sort.Reverse(sort.IntSlice(ansArray))

	var buf bytes.Buffer
	buf.WriteString(strconv.Itoa(ansValue))
	buf.WriteString("\n")
	buf.WriteString(strconv.Itoa(len(ansArray)))
	buf.WriteString("\n")
	if len(ansArray) > 0 {
		for i := range ansArray {
			buf.WriteString(strconv.Itoa(ansArray[len(ansArray)-i-1]))
			buf.WriteString(" ")
		}
	}
	fmt.Println(buf.String())
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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

package main

import (
	"fmt"
	"sort"
)

type item struct {
	t, d, p, idx int
}

type byD []item

func (s byD) Len() int           { return len(s) }
func (s byD) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s byD) Less(i, j int) bool { return s[i].d < s[j].d }

const maxD = 2000

func main() {
	var n int
	fmt.Scan(&n)
	items := make([]item, n)
	for i := range items {
		fmt.Scan(&items[i].t, &items[i].d, &items[i].p)
		items[i].idx = i + 1
	}
	sort.Sort(byD(items))

	value := make([][]int, n+1)
	for i := range value {
		value[i] = make([]int, maxD+1)
		for j := range value[i] {
			value[i][j] = -1
		}
	}
	value[0][0] = 0
	take := make([][]int, n+1)
	for i := range take {
		take[i] = make([]int, maxD+1)
	}

	bestT := 0
	for i, it := range items {
		for t := maxD - 1; t >= 0; t-- {
			value[i+1][t] = value[i][t]
			take[i+1][t] = take[i][t]
			if t < it.t || t >= it.d {
				continue
			}
			cur := value[i][t-it.t]
			if cur == -1 {
				continue
			}
			cur += it.p
			if value[i+1][t] < cur {
				value[i+1][t] = cur
				take[i+1][t] = i
				if value[i][bestT] < cur {
					bestT = t
				}
			}
		}
	}

	fmt.Println(value[n][bestT])
	var taken []int
	for t, s := bestT, n; t > 0; {
		it := items[take[s][t]]
		s = take[s][t] - 1
		taken = append(taken, it.idx)
		t -= it.t
	}
	fmt.Println(len(taken))
	for i := len(taken) - 1; i >= 0; i-- {
		if i == 0 {
			fmt.Println(taken[i])
		} else {
			fmt.Print(taken[i], " ")
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

type item struct {
	t, d, p, idx int
}

type byD []item

func (s byD) Len() int           { return len(s) }
func (s byD) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s byD) Less(i, j int) bool { return s[i].d < s[j].d }

const maxD = 2000

func main() {
	var n int
	fmt.Scan(&n)
	items := make([]item, n)
	for i := range items {
		fmt.Scan(&items[i].t, &items[i].d, &items[i].p)
		items[i].idx = i + 1
	}
	sort.Sort(byD(items))

	value := make([][]int, n+1)
	for i := range value {
		value[i] = make([]int, maxD+1)
	}
	take := make([][]int, n+1)
	for i := range take {
		take[i] = make([]int, maxD+1)
	}
	bestT := 0
	for i, it := range items {
		for t := it.d - 1; t >= it.t; t-- {
			value[i+1][t] = value[i][t]
			take[i+1][t] = take[i][t]
			if cur := value[i][t-it.t] + it.p; value[i+1][t] < cur {
				value[i+1][t] = cur
				take[i+1][t] = i
				if value[i+1][bestT] < cur {
					bestT = t
				}
			}
		}
	}

	fmt.Println(value[n][bestT])
	var taken []int
	for t, s := bestT, n; t > 0 && s > 0; s-- {
		it := items[take[s][t]]
		if len(taken) > 0 && it.idx == taken[len(taken)-1] {
			continue
		}
		taken = append(taken, it.idx)
		t -= it.t
	}
	fmt.Println(len(taken))
	for i := len(taken) - 1; i >= 0; i-- {
		if i == 0 {
			fmt.Println(taken[i])
		} else {
			fmt.Print(taken[i], " ")
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

type item struct {
	t, d, p, idx int
}

type byD []item

func (s byD) Len() int           { return len(s) }
func (s byD) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s byD) Less(i, j int) bool { return s[i].d < s[j].d }

const maxD = 2000

func main() {
	var n int
	fmt.Scan(&n)
	items := make([]item, n)
	for i := range items {
		fmt.Scan(&items[i].t, &items[i].d, &items[i].p)
		items[i].idx = i + 1
	}
	sort.Sort(byD(items))

	value := make([][]int, n+1)
	for i := range value {
		value[i] = make([]int, maxD+1)
		for j := range value[i] {
			value[i][j] = -1
		}
	}
	value[0][0] = 0
	take := make([][]int, n+1)
	for i := range take {
		take[i] = make([]int, maxD+1)
	}

	bestT := 0
	for i, it := range items {
		for t := maxD - 1; t >= 0; t-- {
			value[i+1][t] = value[i][t]
			take[i+1][t] = take[i][t]
			if t < it.t || t >= it.d {
				continue
			}
			cur := value[i][t-it.t]
			if cur == -1 {
				continue
			}
			cur += it.p
			if value[i+1][t] < cur {
				value[i+1][t] = cur
				take[i+1][t] = i
				if value[i][bestT] < cur {
					bestT = t
				}
			}
		}
	}

	fmt.Println(value[n][bestT])
	var taken []int
	for t, s := bestT, n; t > 0; {
		it := items[take[s][t]]
		s = take[s][t]
		taken = append(taken, it.idx)
		t -= it.t
	}
	fmt.Println(len(taken))
	for i := len(taken) - 1; i >= 0; i-- {
		if i == 0 {
			fmt.Println(taken[i])
		} else {
			fmt.Print(taken[i], " ")
		}
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF864E(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ w, mxW, v, i int }

	var n int
	Fscan(in, &n)
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].w, &a[i].mxW, &a[i].v)
		a[i].i = i + 1
	}
	sort.Slice(a, func(i, j int) bool { return a[i].mxW < a[j].mxW })

	m := a[n-1].mxW
	dp := make([]int, m)
	fa := make([][]int, n)
	for i := range fa {
		fa[i] = make([]int, m)
		for j := range fa[i] {
			fa[i][j] = -1
		}
	}
	for i, p := range a {
		w := p.w
		for j := p.mxW - 1; j >= w; j-- {
			if d := dp[j-w] + p.v; d > dp[j] {
				dp[j] = d
				fa[i][j] = j - w
			}
		}
	}
	Fprintln(out, dp[m-1])
	ans := []int{}
	for i, j := n-1, m-1; i >= 0; i-- {
		if fa[i][j] != -1 {
			ans = append(ans, a[i].i)
			j = fa[i][j]
		}
	}
	Fprintln(out, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		Fprint(out, ans[i], " ")
	}
}

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

package main

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

type Node struct {
	num, p, d, t int
}

type Nodes []Node

func (nodes Nodes) Len() int {
	return len(nodes)
}

func (nodes Nodes) Less(i, j int) bool {
	return nodes[i].d < nodes[j].d
}

func (nodes Nodes) Swap(i, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
}

func solve() {
	n := readInt()
	a := make([]Node, n)
	for i := 0; i < n; i++ {
		a[i].t, a[i].d, a[i].p = readInt(), readInt(), readInt()
		a[i].num = i + 1
	}
	sort.Sort(Nodes(a))
	dp := make([][]int, n + 1)
	MAXD := 2001
	dp[0] = make([]int, MAXD)
	for i := 1; i <= n; i++ {
		dp[i] = make([]int, MAXD)
		for j := MAXD - 1; j >= 0; j-- {
			dp[i][j] = dp[i-1][j]
			if j < a[i-1].d && j - a[i-1].t >= 0 {
				dp[i][j] = max(dp[i-1][j-a[i-1].t] + a[i-1].p, dp[i][j])
			}
		}
	}
	pos := 0
	for i := 1; i < MAXD-1; i++ {
		if dp[n][i] > dp[n][pos] {
			pos = i
		}
	}
	ansValue := dp[n][pos]
	ansArray := make([]int, 0)
	for curRow := n; curRow > 0; curRow-- {
		if pos < a[curRow-1].d && pos - a[curRow-1].t >= 0 && dp[curRow][pos] == dp[curRow-1][pos-a[curRow-1].t] + a[curRow-1].p {
			pos -= a[curRow-1].t
			ansArray = append(ansArray, a[curRow-1].num)
		}
	}
	sort.Reverse(sort.IntSlice(ansArray))

	fmt.Println(n)
	var buf bytes.Buffer
	buf.WriteString(strconv.Itoa(ansValue))
	buf.WriteString("\n")
	buf.WriteString(strconv.Itoa(len(ansArray)))
	buf.WriteString("\n")
	if len(ansArray) > 0 {
		for i := range ansArray {
			buf.WriteString(strconv.Itoa(ansArray[len(ansArray)-i-1]))
			buf.WriteString(" ")
		}
	}
	fmt.Println(buf.String())
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

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

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