Recently Monocarp got a job. His working day lasts exactly $$$m$$$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $$$n$$$ minutes $$$a_1, a_2, \dots, a_n$$$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $$$a_i$$$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $$$d$$$ minutes pass between any two coffee breaks. Monocarp also wants to take these $$$n$$$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $$$d$$$ minutes pass between the end of any working day and the start of the following working day.For each of the $$$n$$$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent.

The first line contains three integers $$$n$$$, $$$m$$$, $$$d$$$ $$$(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$$$ — the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $$$n$$$ distinct integers $$$a_1, a_2, \dots, a_n$$$ $$$(1 \le a_i \le m)$$$, where $$$a_i$$$ is some minute when Monocarp wants to have a coffee break.

In the first line, write the minimum number of days required to make a coffee break in each of the $$$n$$$ given minutes.  In the second line, print $$$n$$$ space separated integers. The $$$i$$$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $$$a_i$$$. Days are numbered from $$$1$$$. If there are multiple optimal solutions, you may print any of them.

NoteIn the first example, Monocarp can take two coffee breaks during the first day (during minutes $$$1$$$ and $$$5$$$, $$$3$$$ minutes will pass between these breaks). One break during the second day (at minute $$$2$$$), and one break during the third day (at minute $$$3$$$).In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day.

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimRight(line, "\r\n")
	//line = line[:len(line)-2]
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimRight(line, "\r\n")
	//line = line[:len(line)-2]
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	//line = strings.TrimSuffix(line, "\n")
	line = line[:len(line)-2]
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	//
	line, _ = reader.ReadString('\n')
	//line = strings.TrimSuffix(line, "\n")
	line = line[:len(line)-2]
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	fmt.Printf("x%vx Type:%T\n", numbers[2], numbers[2])

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = line[:len(line)-1]
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	if numbers[2] == "3" {
		fmt.Println("Same")
	} else {
		fmt.Printf("%v %v\n", len(numbers[2]), numbers[2])

		for j := 0; j < len(numbers[2]); j++ {
			fmt.Println(j, numbers[2][j])
		}

		fmt.Println("Diff")
	}

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	// n, m, d
	var n, m, d int
	fmt.Scan(&n, &m, &d)

	//
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	//numbers := strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		//a[i], _ = strconv.Atoi(numbers[i])
		a[i] = i
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	if numbers[2] == "3" {
		fmt.Println("Same")
	} else {
		fmt.Printf("%v %v\n", len(numbers[2]), numbers[2])
		fmt.Println("Diff")
	}

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = line[:len(line)-2]
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	if numbers[2] == "3" {
		fmt.Println("Same")
	} else {
		fmt.Printf("%v %v\n", len(numbers[2]), numbers[2])

		for j := 0; j < len(numbers[2]); j++ {
			fmt.Println(j, numbers[2][j])
		}

		fmt.Println("Diff")
	}

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	//line = strings.TrimSuffix(line, "\n")
	line = line[:len(line)-2]
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	//
	line, _ = reader.ReadString('\n')
	//line = strings.TrimSuffix(line, "\n")
	line = line[:len(line)-2]
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])
	ch := numbers[2]
	x, _ := strconv.Atoi(ch)
	fmt.Println(d, ch, x)

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	if numbers[2] == "3" {
		fmt.Println("Same")
	} else {
		fmt.Println("Diff")
	}

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	fmt.Println(numbers[2], d)

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\r")
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	fmt.Println(numbers[2], d)

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\r")
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	fmt.Println(numbers[2], d)

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	var n, m, d int
	fmt.Scan(&n, &m, &d)
	line, _ := reader.ReadString('\n')

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		n, _ := strconv.Atoi(numbers[i])
		a[i] = n
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	fmt.Println(numbers)

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	fmt.Println(line)

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	if numbers[2] == "3" {
		fmt.Println("Same")
	} else {
		fmt.Printf("%v %T\n", numbers[2], numbers[2])
		fmt.Println("Diff")
	}

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	numbers[2] = strings.TrimSuffix(numbers[2], "\n")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	if numbers[2] == "3" {
		fmt.Println("Same")
	} else {
		fmt.Printf("%v %v\n", len(numbers[2]), numbers[2])

		for j := 0; j < len(numbers[2]); j++ {
			fmt.Println(j, numbers[2][j])
		}

		fmt.Println("Diff")
	}

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	//var n, m, d int
	//fmt.Scan(&n, &m, &d)
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	m, _ := strconv.Atoi(numbers[1])
	d, _ := strconv.Atoi(numbers[2])
	m = m + 1

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	fmt.Println(n, d)

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}

package main

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

// TwoSlices : WTF
type TwoSlices struct {
	originSlice []int
	sortSlice   []int
}

func (t TwoSlices) Len() int { return len(t.originSlice) }
func (t TwoSlices) Less(i, j int) bool {
	return t.originSlice[t.sortSlice[i]] < t.originSlice[t.sortSlice[j]]
}
func (t TwoSlices) Swap(i, j int) { t.sortSlice[i], t.sortSlice[j] = t.sortSlice[j], t.sortSlice[i] }

func main() {

	reader := bufio.NewReader(os.Stdin)

	// n, m, d
	line, _ := reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers := strings.Split(line, " ")
	n, _ := strconv.Atoi(numbers[0])
	d, _ := strconv.Atoi(numbers[2])

	if numbers[2] == "3" {
		fmt.Println("Same")
	} else {
		fmt.Printf("%v %v\n", len(numbers[2]), numbers[2])

		for j := 0; j < len(numbers[2]); j++ {
			fmt.Println(j, numbers[2][j])
		}

		fmt.Println("Diff")
	}

	//
	line, _ = reader.ReadString('\n')
	line = strings.TrimSuffix(line, "\n")
	numbers = strings.Split(line, " ")

	//  a[i], b[i]
	a := make([]int, n)
	b := make([]int, n)
	r := make([]int, n)

	for i := 0; i < n; i++ {
		nums, _ := strconv.Atoi(numbers[i])
		a[i] = nums
		b[i] = i
	}
	fmt.Println(a)
	s := TwoSlices{originSlice: a, sortSlice: b}

	// Sort b
	sort.Sort(TwoSlices(s))

	// Day Sequence
	sequence := 1

	// Available Earliest Time
	earliest := -1

	// First : Setting 0
	r[s.sortSlice[0]] = sequence
	earliest = 0
	sequence++

	// phase
	for cur := 1; cur < n; cur++ {

		if (s.originSlice[s.sortSlice[cur]] - s.originSlice[s.sortSlice[earliest]]) > d {
			r[s.sortSlice[cur]] = r[s.sortSlice[earliest]]
			earliest = earliest + 1
		} else {
			r[s.sortSlice[cur]] = sequence
			sequence++
		}

	}

	// Output
	fmt.Printf("%v\n", sequence-1)

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

}


Note that the memory limit is unusual.You are given a multiset consisting of $$$n$$$ integers. You have to process queries of two types:  add integer $$$k$$$ into the multiset;  find the $$$k$$$-th order statistics in the multiset and remove it. $$$k$$$-th order statistics in the multiset is the $$$k$$$-th element in the sorted list of all elements of the multiset. For example, if the multiset contains elements $$$1$$$, $$$4$$$, $$$2$$$, $$$1$$$, $$$4$$$, $$$5$$$, $$$7$$$, and $$$k = 3$$$, then you have to find the $$$3$$$-rd element in $$$[1, 1, 2, 4, 4, 5, 7]$$$, which is $$$2$$$. If you try to delete an element which occurs multiple times in the multiset, only one occurence is removed. After processing all queries, print any number belonging to the multiset, or say that it is empty.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 10^6$$$) — the number of elements in the initial multiset and the number of queries, respectively. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_1 \le a_2 \le \dots \le a_n \le n$$$) — the elements of the multiset. The third line contains $$$q$$$ integers $$$k_1$$$, $$$k_2$$$, ..., $$$k_q$$$, each representing a query:    if $$$1 \le k_i \le n$$$, then the $$$i$$$-th query is "insert $$$k_i$$$ into the multiset";  if $$$k_i < 0$$$, then the $$$i$$$-th query is "remove the $$$|k_i|$$$-th order statistics from the multiset". For this query, it is guaranteed that $$$|k_i|$$$ is not greater than the size of the multiset.

If the multiset is empty after all queries, print $$$0$$$. Otherwise, print any integer that belongs to the resulting multiset.

NoteIn the first example, all elements of the multiset are deleted.In the second example, the elements $$$5$$$, $$$1$$$, $$$4$$$, $$$2$$$ are deleted (they are listed in chronological order of their removal).In the third example, $$$6$$$ is not the only answer.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1354D(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	r := func() (x int) {
		in.Scan()
		data := in.Bytes()
		if data[0] == '-' {
			for _, b := range data[1:] {
				x = x*10 + int(b&15)
			}
			return -x
		}
		for _, b := range data {
			x = x*10 + int(b&15)
		}
		return
	}

	n, q := r(), r()
	a := make([]int, n)
	for i := range a {
		a[i] = r()
	}
	b := make([]int, q)
	for i := range b {
		b[i] = r()
	}
	f := func(x int) (c int) {
		for _, v := range a {
			if v <= x {
				c++
			}
		}
		for _, v := range b {
			if v > 0 {
				if v <= x {
					c++
				}
			} else if -v <= c {
				c--
			}
		}
		return
	}
	if f(1e9) == 0 {
		Fprint(_w, 0)
	} else {
		Fprint(_w, sort.Search(1e6+1, func(x int) bool { return f(x) > 0 }))
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1354D(_r io.Reader, _w io.Writer) {
	in := bufio.NewScanner(_r)
	in.Split(bufio.ScanWords)
	r := func() (x int) {
		in.Scan()
		data := in.Bytes()
		if data[0] == '-' {
			for _, b := range data[1:] {
				x = x*10 + int(b&15)
			}
			return -x
		}
		for _, b := range data {
			x = x*10 + int(b&15)
		}
		return
	}

	n, q := r(), r()
	a := make([]int, n)
	for i := range a {
		a[i] = r()
	}
	b := make([]int, q)
	for i := range b {
		b[i] = r()
	}
	ans := sort.Search(1e6+1, func(x int) bool {
		c := 0
		for _, v := range a {
			if v <= x {
				c++
			}
		}
		for _, v := range b {
			if v > 0 {
				if v <= x {
					c++
				}
			} else if -v <= c {
				c--
			}
		}
		return c > 0
	})
	if ans == 1e6+1 {
		ans = 0
	}
	Fprint(_w, ans)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1354D(_r io.Reader, _w io.Writer) {
	buf := make([]byte, 4096)
	_i := len(buf)
	rc := func() byte {
		if _i == len(buf) {
			_r.Read(buf)
			_i = 0
		}
		b := buf[_i]
		_i++
		return b
	}
	r := func() (x int) {
		b := rc()
		neg := false
		for ; '0' > b; b = rc() {
			if b == '-' {
				neg = true
			}
		}
		for ; '0' <= b; b = rc() {
			x = x*10 + int(b&15)
		}
		if neg {
			return -x
		}
		return
	}

	n, q := r(), r()
	a := make([]int, n)
	for i := range a {
		a[i] = r()
	}
	b := make([]int, q)
	for i := range b {
		b[i] = r()
	}
	f := func(x int) (c int) {
		for _, v := range a {
			if v <= x {
				c++
			}
		}
		for _, v := range b {
			if v > 0 {
				if v <= x {
					c++
				}
			} else if -v <= c {
				c--
			}
		}
		return
	}
	if f(1e9) == 0 {
		Fprint(_w, 0)
	} else {
		Fprint(_w, sort.Search(1e6, func(x int) bool { return f(x) > 0 }))
	}
}

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


You are given a bracket sequence $$$s$$$ consisting of $$$n$$$ opening '(' and closing ')' brackets.A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()()", "(())" are regular (the resulting expressions are: "(1)+(1)", "((1+1)+1)"), and ")(" and "(" are not.You can change the type of some bracket $$$s_i$$$. It means that if $$$s_i = $$$ ')' then you can change it to '(' and vice versa.Your task is to calculate the number of positions $$$i$$$ such that if you change the type of the $$$i$$$-th bracket, then the resulting bracket sequence becomes regular.

The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of the bracket sequence. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ opening '(' and closing ')' brackets.

Print one integer — the number of positions $$$i$$$ such that if you change the type of the $$$i$$$-th bracket, then the resulting bracket sequence becomes regular.

package main

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

func handle(s string) int {
	n := len(s)
	ans := 0
	// '(' -> ')'
	d := 0
	diff := make([]int, n)
	for i := 0;i < n;i ++ {
		if s[i] == '(' {
			d ++
		} else {
			d --
		}
		diff[i] = d
	}
	for i := 0;i < n;i ++ {
		if diff[i] < 0 {
			return 0
		} else if diff[i] < 2 {
			ans = 0
		} else if diff[i] >= 2 && s[i] == '(' {
			ans ++
		}
	}
	return ans
}

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

	var n int
	var s string
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Fscanf(reader, "%s", &s)
	d := 0
	for i := 0;i < n;i ++ {
		if s[i] == '(' {
			d ++
		} else {
			d --
		}
	}
	if d != 2 && d != -2 {
		fmt.Printf("0")
		return
	} else if d == 2 {
		fmt.Printf("%d", handle(s))
	} else {
		b0 := []byte(s)
		b1 := make([]byte, n)
		for i := 0;i < n;i ++ {
			b1[i] = b0[n - i - 1]
			if b1[i] == '(' {
				b1[i] = ')'
			} else {
				b1[i] = '('
			}
		}
		fmt.Printf("%d", handle(string(b1)))
	}

}

package main

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

func main() {
    start := time.Now()
    defer func () {
        run := time.Since(start)
        _ = run
        // fmt.Println("Run in", run)
    }()

    stdin := bufio.NewReader(os.Stdin)

    var n int
    var s string

    fmt.Fscanln(stdin, &n)
    fmt.Fscanln(stdin, &s)

    var markFront = make([]bool, n)
    var markBack = make([]bool, n)
    var cntFront = make([]int, n)
    var cntBack = make([]int, n)

    Value := func (x int) int {
        if s[x] == 40 {
            return 1
        } else {
            return -1
        }
    }

    for i,cnt:=0, 0; i < n; i++ {
        cnt += Value(i)
        cntFront[i] = cnt
        if i > 0 {
            markFront[i] = (cnt >= 0) && markFront[i - 1]
            // cntFront[i] = cntFront[i-1] + cnt
        } else {
            markFront[i] = (cnt >= 0)
            // cntFront[i] = cnt
        }
    }

    for i, cnt:= n-1, 0; i >=0; i-- {
        cnt += Value(i)
        cntBack[i] = cnt
        if i < n-1 {
            markBack[i] = (cnt <= 0) && markBack[i+1]
            // cntBack[i] = cntBack[i+1] + cnt
        } else {
            markBack[i] = (cnt <= 0)
            // cntBack[i] = cnt
        }
    }

    Check := func (x int) (bool, int, int) {
        var front, back = true, true
        var resFront, resBack int
        if x > 0 {
            front = markFront[x-1]
            resFront = cntFront[x-1]
        }
        if x < n - 1 {
            back = markBack[x+1]
            resBack = cntBack[x+1]
        }
        return front && back, resFront, resBack
    }

    var res int
    for i := 0; i < n; i++ {
        var check, front, back = Check(i)
        // fmt.Println("Check at", i, check, front, back)
        if check {
            var cnt = Value(i) * -1
            if front + cnt >= 0 && back + cnt <= 0 && front + cnt + back == 0 {
                res++
            }
        }
    }

    //fmt.Println(markFront)
    //fmt.Println(markBack)
    //fmt.Println(cntFront, cntBack)
    fmt.Println(res)
}

package main

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

func handle(s string) int {
	n := len(s)
	ans := 0
	// '(' -> ')'
	d := 0
	for i := 0;i < n;i ++ {
		if s[i] == '(' {
			d ++
		} else {
			d --
		}
		if d == 0 {
			ans = 0
		}
		if s[i] == '(' && d >= 2 {
			ans ++
		}
		if d < -2 {
			return 0
		}
	}
	return ans
}

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

	var n int
	var s string
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Fscanf(reader, "%s", &s)
	d := 0
	for i := 0;i < n;i ++ {
		if s[i] == '(' {
			d ++
		} else {
			d --
		}
	}
	if d != 2 && d != -2 {
		fmt.Printf("0")
		return
	} else if d == 2 {
		fmt.Printf("%d", handle(s))
	} else {
		b0 := []byte(s)
		b1 := make([]byte, n)
		for i := 0;i < n;i ++ {
			b1[i] = b0[n - i - 1]
			if b1[i] == '(' {
				b1[i] = ')'
			} else {
				b1[i] = '('
			}
		}
		fmt.Printf("%d", handle(string(b1)))
	}

}

package main

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

type pair struct {
	b byte
	p int
}

func NewPair(b byte, p int) pair {
	return pair{b: b, p: p}
}

func main() {
	start := time.Now()
	defer func() {
		run := time.Since(start)
		_ = run
		// fmt.Println("Run in", run)
	}()

	var stdin *bufio.Reader
	// LOCAL
	f, _ := os.Open("input.txt")
	stdin = bufio.NewReader(f)

	// ONLINE JUDGE
	stdin = bufio.NewReader(os.Stdin)

	var n int
	fmt.Fscanln(stdin, &n)
	var s string
	fmt.Fscanln(stdin, &s)

	var stack = []pair{NewPair(s[0], 0)}
	for i := 1; i < n; i++ {
		stack = append(stack, NewPair(s[i], i))
		if len(stack) > 1 && stack[len(stack)-1].b == 41 && stack[len(stack)-2].b == 40 {
			stack = stack[:len(stack)-2]
		}
	}
	if len(stack) == 2 {
		if stack[0].b == 40 {
			fmt.Println(stack[1].p + 1)
		} else if stack[1].b == 41 {
			fmt.Println(stack[0].p + 1)
		} else {
			fmt.Println(0)
		}
	} else {
		fmt.Println(0)
	}
	// fmt.Println(stack)
}


Marmot found a row with n pillars. The i-th pillar has the height of hi meters. Starting from one pillar i1, Marmot wants to jump on the pillars i2, ..., ik. (1 ≤ i1 < i2 < ... < ik ≤ n). From a pillar i Marmot can jump on a pillar j only if i < j and |hi - hj| ≥ d, where |x| is the absolute value of the number x.Now Marmot is asking you find out a jump sequence with maximal length and print it.

The first line contains two integers n and d (1 ≤ n ≤ 105, 0 ≤ d ≤ 109). The second line contains n numbers h1, h2, ..., hn (1 ≤ hi ≤ 1015).

The first line should contain one integer k, the maximal length of a jump sequence. The second line should contain k integers i1, i2, ..., ik (1 ≤ i1 < i2 < ... < ik ≤ n), representing the pillars' indices from the maximal length jump sequence. If there is more than one maximal length jump sequence, print any.

NoteIn the first example Marmot chooses the pillars 1, 2, 3, 5 with the heights 1, 3, 6, 4. Another jump sequence of length 4 is 1, 2, 4, 5.

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if i == 0 {
        return j
    }
    if j == 0 {
        return i
    }
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if i == 0 {
        return j
    }
    if j == 0 {
        return i
    }
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    a := make([]int64, n+1)
    p := make([]int, n+1)
    d := 1
    id1 := 0
    id2 := 0
    id3 := 0
    id4 := 0
    m := 0

    if D == 0 {
        writer.WriteString(strconv.Itoa(n) + "\n")
        for i := 1; i <= n; i++ {
            writer.WriteString(strconv.Itoa(i) + " ")
        }
        writer.Flush()
        os.Exit(0)
    }

    for i := 1; i <= n; i++ {
        a[i] = ReadInt64()
        if id1 == 0 {
            id1 = i
            id2 = i
        }

        if id4 > 0 && (abs(a[id3]-a[i]) >= D || abs(a[id4]-a[i]) >= D) {
            id1 = id3
            id2 = id4
            d++
            m = i
            if abs(a[id3]-a[i]) >= D {
                p[i] = id3
            } else {
                p[i] = id4
            }
            id3 = i
            id4 = i
        } else if abs(a[id1]-a[i]) >= D || abs(a[id2]-a[i]) >= D {
            if id4 == 0 {
                d++
                m = i
            }
            if abs(a[id1]-a[i]) >= D {
                p[i] = id1
            } else {
                p[i] = id2
            }

            id3 = max(a, id3, i)
            id4 = min(a, id4, i)
        } else if id4 == 0 {
            id1 = max(a, id1, i)
            id2 = min(a, id2, i)
        }
    }

    writer.WriteString(strconv.Itoa(d) + "\n")
    ans := make([]int, d+1)
    q := d
    for i := q; m > 0; i-- {
        ans[i] = m
        m = p[m]
    }

    for i := 1; i <= q; i++ {
        writer.WriteString(strconv.Itoa(ans[i]) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

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

    n := ReadInt32()
    D := ReadInt64()
    blockmax := make([]int64, n)
    blockmin := make([]int64, n)
    ans := make([]int64, n+1)
    a := ReadInt64()
    d := 0
    blockmax[0] = a
    blockmin[0] = a
    ans[0] = a

    for i := 1; i < n; i++ {
        a = ReadInt64()
        if abs(blockmax[d]-a) >= D {
            ans[d] = blockmax[d]
            d++
            ans[d] = a
            blockmax[d] = a
            blockmin[d] = a
        } else if abs(blockmin[d]-a) >= D {
            ans[d] = blockmin[d]
            d++
            ans[d] = a
            blockmax[d] = a
            blockmin[d] = a
        } else if d == 0 {
            if a < blockmin[d] {
                blockmin[d] = a
            } else if a > blockmax[d] {
                blockmax[d] = a
            }
        } else {
            if a < blockmin[d] {
                if abs(blockmax[d-1]-a) >= D {
                    ans[d-1] = blockmax[d-1]
                    blockmin[d] = a
                    ans[d] = a
                } else if abs(blockmin[d-1]-a) >= D {
                    ans[d-1] = blockmin[d-1]
                    blockmin[d] = a
                    ans[d] = a
                }
            } else if a > blockmax[d] {
                if abs(blockmax[d-1]-a) >= D {
                    ans[d-1] = blockmax[d-1]
                    blockmax[d] = a
                    ans[d] = a
                } else if abs(blockmin[d-1]-a) >= D {
                    ans[d-1] = blockmin[d-1]
                    blockmax[d] = a
                    ans[d] = a
                }
            }
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.FormatInt(ans[i], 10) + " ")
    }

    writer.WriteString("\n")
}

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    a := make([]int64, n)
    ans := make([]int, n)
    imin := make([]int, n)
    imax := make([]int, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0
    ans[0] = 0
    id1 := 0
    id2 := 0
    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if d > 0 && abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            id1 = imax[d]
            id2 = imin[d]
            if abs(a[imax[d]]-a[i]) >= D {
                ans[d] = imax[d]
            } else {
                ans[d] = imin[d]
            }
            d++
            ans[d] = i
            imax[d] = i
            imin[d] = i
        } else if abs(a[id1]-a[i]) >= D || abs(a[id2]-a[i]) >= D {
            if d == 0 {
                d++
            }
            if abs(a[id1]-a[i]) >= D {
                ans[d] = id1
            } else {
                ans[d] = id2
            }
            ans[d] = i
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        } else if d == 0 {
            id1 = max(a, i, id1)
            id2 = min(a, i, id2)
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    imax := make([]int, n+1)
    imin := make([]int, n+1)
    a := make([]int64, n)
    ans := make([]int, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0
    ans[0] = 0

    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            if abs(a[imax[d]]-a[i]) >= D {
                ans[d] = imax[d]
            } else {
                ans[d] = imin[d]
            }
            d++
            ans[d] = i
            imax[d] = i
            imin[d] = i
        } else if d == 0 {
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        } else if abs(a[imin[d-1]]-a[i]) >= D || abs(a[imax[d-1]]-a[i]) >= D {
            /*if abs(a[imax[d-1]]-a[i]) >= D {
                ans[d-1] = imax[d-1]
            } else {
                ans[d-1] = imin[d-1]
            }*/
            ans[d] = i
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    imax := make([]int, n)
    imin := make([]int, n)
    a := make([]int64, n)
    ans := make([]int, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0
    ans[0] = 0

    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            if abs(a[imax[d]]-a[i]) >= D {
                ans[d] = imax[d]
            } else {
                ans[d] = imin[d]
            }
            d++
            ans[d] = i
            imax[d] = i
            imin[d] = i
        } else if d > 0 && (abs(a[imin[d-1]]-a[i]) >= D || abs(a[imax[d-1]]-a[i]) >= D) {
            if abs(a[imax[d-1]]-a[i]) >= D {
                ans[d-1] = imax[d-1]
            } else {
                ans[d-1] = imin[d-1]
            }
            ans[d] = i
            imax[d] = max(a, i, imax[d-1])
            imin[d] = min(a, i, imin[d-1])
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

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

    n := ReadInt32()
    D := ReadInt64()
    imax := make([]int, n)
    imin := make([]int, n)
    a := make([]int64, n)
    ans := make([]int, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0
    ans[0] = 0

    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            if abs(a[imax[d]]-a[i]) >= D {
                ans[d] = imax[d]
            } else {
                ans[d] = imin[d]
            }
            d++
            ans[d] = i
            imax[d] = i
            imin[d] = i
        } else if d == 0 {
            if a[i] < a[imin[d]] {
                imin[d] = i
            } else if a[i] > a[imax[d]] {
                imax[d] = i
            }
        } else {
            if (a[i] < a[imin[d]]) && (abs(a[ans[d-1]]-a[i]) >= D) {
                imin[d] = i
            } else if (a[i] > a[imax[d]]) && (abs(a[ans[d-1]]-a[i]) >= D) {
                imax[d] = i
            }
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    imax := make([]int, n)
    imin := make([]int, n)
    a := make([]int64, n)
    ans := make([]int, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0
    ans[0] = 0

    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            if abs(a[imax[d]]-a[i]) >= D {
                ans[d] = imax[d]
            } else {
                ans[d] = imin[d]
            }
            d++
            ans[d] = i
            imax[d] = i
            imin[d] = i
        } else if d > 0 && (abs(a[imin[d-1]]-a[i]) >= D || abs(a[imax[d-1]]-a[i]) >= D) {
            if abs(a[imax[d-1]]-a[i]) >= D {
                ans[d-1] = imax[d-1]
            } else {
                ans[d-1] = imin[d-1]
            }
            ans[d] = i
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    imax := make([]int, n+1)
    imin := make([]int, n+1)
    a := make([]int64, n)
    ans := make([]int, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0
    ans[0] = 0

    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            if abs(a[imax[d]]-a[i]) >= D {
                ans[d] = imax[d]
            } else {
                ans[d] = imin[d]
            }
            d++
            ans[d] = i
            imax[d] = i
            imin[d] = i
        } else if d == 0 {
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        } else if abs(a[imin[d-1]]-a[i]) >= D || abs(a[imax[d-1]]-a[i]) >= D {
            if abs(a[imax[d-1]]-a[i]) >= D {
                if d > 1 && abs(a[imin[d-1]]-a[i]) >= D {
                    if abs(a[ans[d-2]]-a[imin[d-1]]) >= D {
                        ans[d-1] = imin[d-1]
                    } else {
                        ans[d-1] = imax[d-1]
                    }
                } else {
                    ans[d-1] = imax[d-1]
                }
            } else {
                ans[d-1] = imin[d-1]
            }
            ans[d] = i
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

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

    n := ReadInt32()
    D := ReadInt64()
    blockmax := make([]int, n)
    blockmin := make([]int, n)
    ans := make([]int, n+1)
    a := make([]int64, n)
    a[0] = ReadInt64()
    d := 0
    blockmax[0] = 0
    blockmin[0] = 0
    ans[0] = 0

    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if abs(a[blockmax[d]]-a[i]) >= D {
            ans[d] = blockmax[d]
            d++
            ans[d] = i
            blockmax[d] = i
            blockmin[d] = i
        } else if abs(a[blockmin[d]]-a[i]) >= D {
            ans[d] = blockmin[d]
            d++
            ans[d] = i
            blockmax[d] = i
            blockmin[d] = i
        } else if d == 0 {
            if a[i] < a[blockmin[d]] {
                blockmin[d] = i
            } else if a[i] > a[blockmax[d]] {
                blockmax[d] = i
            }
        } else {
            if a[i] < a[blockmin[d]] {
                if abs(a[blockmax[d-1]]-a[i]) >= D {
                    ans[d-1] = blockmax[d-1]
                    blockmin[d] = i
                    ans[d] = i
                } else if abs(a[blockmin[d-1]]-a[i]) >= D {
                    ans[d-1] = blockmin[d-1]
                    blockmin[d] = i
                    ans[d] = i
                }
            } else if a[i] > a[blockmax[d]] {
                if abs(a[blockmax[d-1]]-a[i]) >= D {
                    ans[d-1] = blockmax[d-1]
                    blockmax[d] = i
                    ans[d] = i
                } else if abs(a[blockmin[d-1]]-a[i]) >= D {
                    ans[d-1] = blockmin[d-1]
                    blockmax[d] = i
                    ans[d] = i
                }
            }
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }

    writer.WriteString("\n")
}

package main

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

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

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

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

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

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

    return a
}

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

    n := ReadInt32()
    D := ReadInt64()
    imax := make([]int, n)
    imin := make([]int, n)
    a := make([]int64, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0

    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            d++
            imax[d] = i
            imin[d] = i
        } else if d == 0 {
            if a[i] < a[imin[d]] {
                imin[d] = i
            } else if a[i] > a[imax[d]] {
                imax[d] = i
            }
        } else {
            if (a[i] < a[imin[d]]) && abs(a[imax[d-1]]-a[i]) >= D {
                imin[d] = i
            } else if a[i] > a[imax[d]] && abs(a[imin[d-1]]-a[i]) >= D {
                imax[d] = i
            }
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    ans := make([]int, d+1)
    stack := make([]int, 0)
    for i := 0; i <= d; i++ {
        if imin[i] == imax[i] {
            ans[i] = imin[i]
        } else {
            if i == 0 {
                stack = append(stack, i)
                ans[i] = imax[i]
            } else {
                if abs(a[ans[i-1]]-a[imin[i]]) >= D {
                    if abs(a[ans[i-1]]-a[imax[i]]) >= D {
                        stack = append(stack, i)
                        ans[i] = imax[i]
                    } else {
                        ans[i] = imin[i]
                    }
                } else {
                    if abs(a[ans[i-1]]-a[imax[i]]) >= D {
                        ans[i] = imax[i]
                    } else {
                        i = stack[len(stack)-1]
                        stack = stack[0 : len(stack)-1]
                        ans[i] = imin[i]
                    }
                }
            }
        }
    }

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
    writer.WriteString("\n")
}

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if i == 0 {
        return j
    }
    if j == 0 {
        return i
    }
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if i == 0 {
        return j
    }
    if j == 0 {
        return i
    }
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    a := make([]int64, n+1)
    p := make([]int, n+1)
    d := 1
    id1 := 0
    id2 := 0
    id3 := 0
    id4 := 0
    for i := 1; i <= n; i++ {
        a[i] = ReadInt64()
        if id1 == 0 {
            id1 = i
            id2 = i
        }

        if id4 > 0 && (abs(a[id3]-a[i]) >= D || abs(a[id4]-a[i]) >= D) {
            id1 = id3
            id2 = id4
            d++
            if abs(a[id3]-a[i]) >= D {
                p[i] = id3
            } else {
                p[i] = id4
            }
            id3 = i
            id4 = i
        } else if abs(a[id1]-a[i]) >= D || abs(a[id2]-a[i]) >= D {
            if id4 == 0 {
                d++
            }
            if abs(a[id1]-a[i]) >= D {
                p[i] = id1
            } else {
                p[i] = id2
            }

            id3 = max(a, id3, i)
            id4 = min(a, id4, i)
        } else if id4 == 0 {
            id1 = max(a, id1, i)
            id2 = min(a, id2, i)
        }
    }

    writer.WriteString(strconv.Itoa(d) + "\n")
    ans := make([]int, d+1)
    q := d
    d = n
    for i := q; d > 0; i-- {
        ans[i] = d
        d = p[d]
    }

    for i := 1; i <= q; i++ {
        writer.WriteString(strconv.Itoa(ans[i]) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    imax := make([]int, n+1)
    imin := make([]int, n+1)
    a := make([]int64, n)
    ans := make([]int, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0
    ans[0] = 0

    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            if abs(a[imax[d]]-a[i]) >= D {
                ans[d] = imax[d]
            } else {
                ans[d] = imin[d]
            }
            d++
            ans[d] = i
            imax[d] = i
            imin[d] = i
        } else if d == 0 {
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        } else if abs(a[imin[d-1]]-a[i]) >= D || abs(a[imax[d-1]]-a[i]) >= D {
            if abs(a[imax[d-1]]-a[i]) >= D {
                ans[d-1] = imax[d-1]
            } else {
                ans[d-1] = imin[d-1]
            }
            ans[d] = i
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
}

package main

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

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

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

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

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

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

    return a
}

func max(a []int64, i, j int) int {
    if a[i] > a[j] {
        return i
    } else {
        return j
    }
}

func min(a []int64, i, j int) int {
    if a[i] < a[j] {
        return i
    } else {
        return j
    }
}

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

    n := ReadInt32()
    D := ReadInt64()
    a := make([]int64, n)
    ans := make([]int, n)
    imin := make([]int, n)
    imax := make([]int, n)
    a[0] = ReadInt64()
    d := 0
    imax[0] = 0
    imin[0] = 0
    ans[0] = 0
    id1 := 0
    id2 := 0
    for i := 1; i < n; i++ {
        a[i] = ReadInt64()
        if d > 0 && abs(a[imax[d]]-a[i]) >= D || abs(a[imin[d]]-a[i]) >= D {
            id1 = imax[d]
            id2 = imin[d]
            if abs(a[imax[d]]-a[i]) >= D {
                ans[d] = imax[d]
            } else {
                ans[d] = imin[d]
            }
            d++
            ans[d] = i
            imax[d] = i
            imin[d] = i
        } else if abs(a[imin[id1]]-a[i]) >= D || abs(a[imax[id2]]-a[i]) >= D {
            if d == 0 {
                d++
            }
            if abs(a[id1]-a[i]) >= D {
                ans[d] = id1
            } else {
                ans[d] = id2
            }
            ans[d] = i
            imax[d] = max(a, i, imax[d])
            imin[d] = min(a, i, imin[d])
        } else if d == 0 {
            id1 = max(a, i, id1)
            id2 = min(a, i, id2)
        }
    }

    writer.WriteString(strconv.Itoa(d+1) + "\n")

    for i := 0; i <= d; i++ {
        writer.WriteString(strconv.Itoa(ans[i]+1) + " ")
    }
}


This is the easy version of this problem. In this version, we do not have queries. Note that we have multiple test cases in this version. You can make hacks only if both versions of the problem are solved.An array $$$b$$$ of length $$$m$$$ is good if for all $$$i$$$ the $$$i$$$-th element is greater than or equal to $$$i$$$. In other words, $$$b$$$ is good if and only if $$$b_i \geq i$$$ for all $$$i$$$ ($$$1 \leq i \leq m$$$).You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find the number of pairs of indices $$$(l, r)$$$, where $$$1 \le l \le r \le n$$$, such that the array $$$[a_l, a_{l+1}, \ldots, a_r]$$$ is good.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^5$$$). Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$), the length of the array $$$a$$$. The second line of each test case contains $$$n$$$ space-separated integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \leq a_i \leq n$$$), representing the array $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print the number of suitable pairs of indices.

NoteIn the first test case, all subarrays of $$$a$$$ are good, so all pairs are suitable.In the second test case, the pairs $$$(1, 1)$$$, $$$(2, 2)$$$, and $$$(3, 3)$$$ are suitable. For example, when $$$(l, r) = (1, 2)$$$, the array $$$b=[1,1]$$$ is not good because $$$b_2 < 2$$$.

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 int
		fmt.Fscan(in, &n)
		aa := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}

		var tot int64
		j, k := 0, 1
		for i := 0; i < n; i++ {
			for j < n && aa[i] < k {
				j++
				k--
			}
			tot += int64(i - j + 1)
			k++
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		a := make([]int, n)

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

		res := 1
		cnt := 1
		for i, v := range a {
			if i == 0 { continue }
			if v > cnt {
				cnt++
			} else {
				cnt = v
			}
			res += cnt
		}

		fmt.Fprintln(w, res)
	}

}

package main

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

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

func c1736(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T int
	var n int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)

		for i := 0; i < n; i++ {
			Fscan(in, &x)
			a[i] = x
		}

		ans := 0
		s := 0
		l := 0
		for e, v := range a {
			l++
			for s < e && v < l {
				s++
				l--
			}
			ans += e - s + 1
		}

		Fprintln(out, ans)
	}
}

package main

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

var sc = bufio.NewScanner(os.Stdin)

const INF = 1e18
const N = 2e5 + 5

func main() {
	sc.Buffer(make([]byte, 500000*1+1), 500000)
	sc.Split(bufio.ScanWords)

	f := make([]int, N)
	for i := 1; i < N; i++ {
		f[i] = f[i-1] + i
	}
	// fmt.Println(f[5])
	T := nextInt()
	for T > 0 {
		T--
		n := nextInt()
		a := make([]int, n)
		for i := 0; i < n; i++ {
			a[i] = nextInt()
		}
		ans := 0
		for l, r := 0, 0; l < n; l++ {
			for r < n && a[r] >= r-l+1 {
				r++
			}
			ans += r - l
		}
		fmt.Println(ans)
	}
}

func min(args ...int) int {
	res := args[0]
	for _, v := range args {
		if v < res {
			res = v
		}
	}
	return res
}

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

func nextString() string {
	sc.Scan()
	return sc.Text()
}

package main

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

func solve(_r io.Reader, _w io.Writer) {

	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)

	defer out.Flush()

	var n, T int
	Fscan(in, &T)
	for ; T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n+1)
		r := make([]int, n+2)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
			r[i] = n
		}
		r[n+1] = n
		for i := n; i >= 1; i-- {
			r[i] = min(r[i], r[i+1])
			if a[i] >= i {
				continue
			}
			r[i-a[i]] = min(r[i-a[i]], i-1)
		}
		var res int64
		for i := 1; i <= n; i++ {
			res += int64(r[i] - i + 1)
		}
		Fprintln(out, res)
	}

}

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

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

package main

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

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

func solve() {
	var n int
	scanf("%d\n", &n)
	a := make([]int, n+1)
	for i:=1; i<=n; i++ {
		scanf("%d ", &a[i])
	}
	scanf("\n")

	i, j := 0, 1
	var res int64 = 0
	for j <= n {
		if a[j] >= (j - i) {
			res += int64(j-i)
			j++
			continue
		}
		i++
	}
	printf("%v\n", res)
}

func main() {
	defer writer.Flush()

	var T int
	scanf("%d\n", &T)
	for tt:=1; tt<=T; tt++ {
		solve()
	}
}

package main

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

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

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

		tot := int64(n)
		for i := 2; i <= n; i++ {
			for j := 0; j+i <= n; j++ {
				d := -1
				for k := 0; k < i; k++ {
					if aa[j+k] < k+1 {
						d = j + k
						break
					}
				}
				if d < 0 {
					tot++
				} else {
					j = d - 1
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}

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 int
		fmt.Fscan(in, &n)
		aa := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &aa[i])
		}

		tot := int64(n)
		for i := 2; i <= n; i++ {
			for j := 0; j+i <= n; j++ {
				d := -1
				for k := 0; k < i; k++ {
					if aa[j+k] < k+1 {
						d = j + k
					}
				}
				if d < 0 {
					tot++
				} else {
					j = d - 1
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		a := make([]int, n)
		// b := make([]int, n+1)
		fact := make([]int, n+1)
		for i := range fact {
			if i == 0 {
				fact[i] = 1
			} else {
				fact[i] = fact[i-1] * i
			}
		}

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

		cmp := 0
		res := 0
		for _, v := range a {
			if v > cmp {
				cmp++
			} else {
				res += fact[cmp]
				cmp = 1
			}
		}
		res += fact[cmp]
		/*
		res := 0
		cnt := 0
		for i := range b {
			fmt.Fprintln(w, "%%%%% ", b[i], cnt, res)
			if b[i] == 0 {
				res += fact[cnt]
				cnt = 0
			} else {
				cnt++
			}
		}
		*/

		fmt.Fprintln(w, res)
	}

}