package main

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

var in = bufio.NewScanner(os.Stdin)
var n, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n = readInt()
  max = 1

  px, ph, pd := readInt(), readInt(), -1
  for i := 1; i < n; i++ {
    x, h := readInt(), readInt()
    if px+ph*pd >= x {
      pd = 0
    }
    if pd != 0 {
      max++
    }
    if px+ph*pd < x-h && px < x-h {
      px, ph, pd = x, h, -1
    } else {
      px, ph, pd = x, h, 1
    }
  }

  fmt.Println(max)
}

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

package main

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

var (
	n int
	p int
	ibuf []byte
)

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

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

func init() {
	p = 0
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

func main() {
	n := ReadInt()
	px, ph, pd := -1, -1, 0
	r := 0
	for i := 0; i < n; i++ {
		x, h := ReadInt(), ReadInt()
		if i == 0 {
			px, ph, pd = x, h, -1
		} else {
			if px + ph * pd >= x {
				pd = 0
			}
			if pd != 0 {
				r++
			}
			if px + ph * pd < x - h && px < x - h {
				px, ph, pd = x, h, -1
			} else {
				px, ph, pd = x, h, 1
			}
		}
	}
	r++
	fmt.Println(r)
}

package main

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

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

type tree struct {
	x, h int64
}

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

	n := nextInt()
	trees := make([]tree, n)
	var cnt int64 = 1
	haveOccupied := false

	if n >= 2 {
		cnt++
	}

	for i := range trees {
		trees[i].x = nextInt64()
		trees[i].h = nextInt64()
	}

	for i := 1; i < n-1; i++ {
		// println(trees[i].x, trees[i].h, haveOccupied, cnt)
		canChop := false
		if haveOccupied {
			if trees[i].x-trees[i].h > trees[i-1].x+trees[i-1].h {
				canChop = true
			}
		} else if trees[i].x-trees[i].h > trees[i-1].x {
			canChop = true
		}

		if canChop {
			cnt++
			haveOccupied = false
			continue
		}

		if trees[i].x+trees[i].h < trees[i+1].x {
			cnt++
			haveOccupied = true
		} else {
			haveOccupied = false
		}

		// if trees[i].x-trees[i].h > trees[i-1].x ||
		// 	trees[i].x+trees[i].h < trees[i+1].x {
		// 	cnt++
		// }
	}
	_ = haveOccupied
	println(cnt)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

	cut := 0
	occupied := -1
	var x_i, h_i, last_x_i int

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

		if i%2 == 0 {
			if i > 0 {
				last_x_i = x_i
			}
			x_i = a
		} else {
			h_i = a
			if occupied < 0 {
				occupied = x_i
				cut++
			} else if occupied >= x_i {
				occupied = last_x_i
				cut--
				if x_i-h_i > occupied {
					occupied = x_i
					cut++
				} else {
					occupied = x_i + h_i
					cut++
				}
			} else if x_i-h_i > occupied {
				occupied = x_i
				cut++
			} else {
				occupied = x_i + h_i
				cut++
			}
		}
	}

	fmt.Println(cut)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var n int
	fmt.Fscanln(reader, &n)
	points := make([]int64, n)
	heights := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanln(reader, &points[i], &heights[i])
	}
	if n <= 2 {
		fmt.Fprintln(writer, n)
		return
	}
	trees := 2
	right_border := points[n-1]
	for i := n - 2; i >= 1; i-- {
		if points[i]+heights[i] < right_border {
			trees += 1
			right_border = points[i]
			continue
		}
		right_border = points[i]
		if points[i]-heights[i] > points[i-1] {
			trees += 1
			right_border -= heights[i]
			continue
		}
	}
	fmt.Fprintln(writer, trees)
}

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...) }

var n int
var x []int
var h []int

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

const (
	LEFT     = iota
	RIGHT    = iota
	STAY     = iota
	SENTINEL = iota
)

func solve(i, lastChoice int) int {
	var left, right, stay int
	if i == n-1 {
		return 1 // always fall to the right
	}
	if lastChoice == SENTINEL {
		// always go left
		left = solve(i+1, LEFT) + 1
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == LEFT {
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == RIGHT {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1]+h[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == STAY {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	}
	//printf("i=%v, ans=%v\n", i, max(left, max(stay, right)))
	return max(left, max(stay, right))
}

func main() {
	defer writer.Flush()
	scanf("%d\n", &n)
	x = make([]int, n)
	h = make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d %d\n", &x[i], &h[i])
	}
	//printf("x=%v\n", x)
	//printf("h=%v\n", h)
	// ans := solve(0, SENTINEL)
	left := make([]int, n)
	right := make([]int, n)
	stay := make([]int, n)
	left[0] = 1
	stay[0] = 0
	if n > 1 && x[0]+h[0] < x[1] {
		right[0] = 1
	}
	for i := 1; i < n; i++ {
		if i == n-1 {
			right[i] = max(left[i-1], max(right[i-1], stay[i-1])) + 1
			continue
		}
		// falling left
		if x[i]-h[i] > x[i-1] {
			left[i] = max(left[i-1], stay[i-1]) + 1
		}
		if x[i-1]+h[i-1] < x[i]-h[i] {
			left[i] = max(left[i], right[i-1]+1)
		}
		// falling right
		if x[i]+h[i] < x[i+1] {
			if x[i-1]+h[i-1] < x[i] {
				right[i] = right[i-1] + 1
			}
			right[i] = max(right[i], max(left[i-1], stay[i-1])+1)
		}
		// stay
		stay[i] = max(left[i-1], stay[i-1])
		if x[i-1]+h[i-1] < x[i] {
			stay[i] = max(stay[i], right[i-1])
		}
	}
	printf("%v\n", max(stay[n-1], max(left[n-1], right[n-1])))
}

package main

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

func main() {
	n := ScanInt()
	x, h := make([]int, n+2), make([]int, n+2)
	x[0] = math.MinInt32
	h[0] = 0
	for i := 1; i <= n; i++ {
		x[i] = ScanInt()
		h[i] = ScanInt()
	}
	x[n+1] = math.MaxInt32
	h[n+1] = 0

	dp := make([][]int, n+2)
    for i := 0; i<n+2; i++ {
        dp[i] = make([]int, 3)
    }
	for i := 1; i <= n; i++ {
		dp[i][0] = Mx(dp[i-1][0], dp[i-1][1], dp[i-1][2])

		if int64(x[i])-int64(x[i-1]) > int64(h[i]) {
			dp[i][1] = Mx(dp[i-1][0], dp[i-1][1]) + 1
			if x[i]-x[i-1] > h[i]+h[i-1] {
				dp[i][1] = Mx(dp[i][1], dp[i-1][2]+1)
			}
		}
		if int64(x[i+1])-int64(x[i]) > int64(h[i]) {
			dp[i][2] = Mx(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1
		}
	}

	P(dp[n][2])
	out.Flush()
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	if err := run(os.Args[1:]); err != nil {
		fmt.Println(err)
	}
}

var reader = bufio.NewReader(os.Stdin)
var CRLFReplacer = strings.NewReplacer("\n", "", "\r", "")

func readString(w io.Writer) bool {
	s, err := reader.ReadString('\n')
	if err != nil {
		return false
	}
	s = CRLFReplacer.Replace(s)
	_, _ = fmt.Fprintf(w, "%s", s)
	return true
}

func MustInt(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}

type tree struct {
	height int
	location int
	chopped bool
	left bool
}

func run(args []string) error {
	var b bytes.Buffer
	var forest []*tree

	readString(&b)
	b.Reset()

	for readString(&b) {
		s := b.String()
		parts := strings.Split(s, " ")
		t := &tree{
			height: MustInt(parts[1]),
			location: MustInt(parts[0]),
		}
		forest = append(forest, t)
		b.Reset()
	}

	count := 0

	for i, t := range forest {
		if i == 0 || i == len(forest) - 1 {
			t.chopped = true
			t.left = true
			count++
			continue
		}

		left := forest[i -1]
		if left.chopped && !left.left {
			if left.location + left.height < t.location - t.height {
				t.chopped = true
				t.left = true
				count++
				continue
			}
		} else {
			if left.location < t.location - t.height {
				t.chopped = true
				t.left = true
				count++
				continue
			}
		}

		right := forest[i + 1]
		if right.location > t.location + t.height {
			t.chopped = true
			t.left = false
			count++
			continue
		}
	}

	fmt.Println(count)
	return nil
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

var n int

func main() {
	defer w.Flush()
	for I(&n) == nil {
		solve(n)
	}
}

func solve(n int) {
	in := make([][2]int, n)
	for i := range in {
		I(&in[i][0], &in[i][1])
	}
	x := int(-1e9)
	ans := 0
	for i := 0; i < n; i++ {
		if x < in[i][0]-in[i][1] {
			x = in[i][0]
			ans++
		} else if x < in[i][0] && (i == n-1 || in[i+1][0] > in[i][0]+in[i][1]) {
			x = in[i][0] + in[i][1]
			ans++
		}
		if in[i][0] > x {
			x = in[i][0]
		}
	}
	O(ans, "\n")
}

package main

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

type RoadTree struct {
	Pos int
	Height int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var n int
	fmt.Scan(&n)
	scanner.Split(bufio.ScanWords)

	trees := make([]RoadTree, n)

	for i := 0; i < n; i++ {
		for scanner.Scan() {
			if scanner.Text() != "" { break }
		}

		position, _ := strconv.Atoi(scanner.Text())

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

		trees[i] = RoadTree{position, size}
	}

	var fallenTrees int
	if fallenTrees = 2; fallenTrees > n {
		fallenTrees = n
	}

	for i := 1; i < n-1; i++ {
		if (trees[i].Pos - trees[i].Height) > trees[i - 1].Pos {
			fallenTrees += 1
		} else if (trees[i].Pos + trees[i].Height) < trees[i + 1].Pos {
			fallenTrees += 1
			trees[i].Pos += trees[i].Height
		}
	}

	fmt.Println(fallenTrees)
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

var n int

func main() {
	defer w.Flush()
	for I(&n) == nil {
		solve(n)
	}
}

var in, C arr

func solve(n int) {
	in = make(arr, n)
	C = make(arr, n)
	for i := range in {
		I(&in[i][0], &in[i][1])
		C[i] = [3]int{in[i][0] - in[i][1], in[i][0], i}
	}
	sort.Sort(C)
	for i := range C {
		if i != n-1 && C[i+1][0] <= C[i][1] {
			C[i+1][0] = in[C[i+1][2]][0]
			C[i+1][1] = in[C[i+1][2]][0] + in[C[i+1][2]][1]
		}
	}
	for i := range C {
		if i != n-1 && C[i+1][0] <= C[i][1] {
			C[i+1][0] = in[C[i+1][2]][0]
			C[i+1][1] = in[C[i+1][2]][0]
		}
	}
	ans := 0
	for i := range C {
		if C[i][0] != C[i][1] {
			ans++
		}
	}
	O(ans, "\n")
}

type arr [][3]int

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

package main

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

type RoadTree struct {
	Pos int
	Height int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	var n int
	fmt.Scan(&n)
	scanner.Split(bufio.ScanWords)

	trees := make([]RoadTree, n)

	for i := 0; i < n; i++ {
		for scanner.Scan() {
			if scanner.Text() != "" { break }
		}

		position, _ := strconv.Atoi(scanner.Text())

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

		trees[i] = RoadTree{position, size}
	}

	var fallenTrees int
	if n < 2 {
		fallenTrees = n
	} else {
		fallenTrees = 2
	}

	for i := 1; i < n-1; i++ {
		// If can cut to the left
		if (trees[i].Pos - trees[i].Height) > trees[i - 1].Pos {
			fallenTrees += 1
		} else if (trees[i].Pos + trees[i].Height) < trees[i + 1].Pos {
			// If can cut to the right

			// If the next tree is the last tree then cut to the right, otherwise cut only if the next tree can't be cut
			// to the left.
			if i + 1 == n - 1 {
				fallenTrees += 1
			} else {
				if trees[i + 1].Pos - trees[i + 1].Height <= trees[i].Pos {
					fallenTrees += 1
					trees[i].Pos += trees[i].Height
				}
			}
		}
	}

	fmt.Println(fallenTrees)
}

package main

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

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

type tree struct {
	x, h int64
}

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

	n := nextInt()
	trees := make([]tree, n)
	var cnt int64 = 1

	if n >= 2 {
		cnt++
	}

	for i := range trees {
		trees[i].x = nextInt64()
		trees[i].h = nextInt64()
	}

	for i := 1; i < n-1; i++ {
		// println(trees[i].x, trees[i].h)
		if trees[i].x-trees[i].h > trees[i-1].x ||
			trees[i].x+trees[i].h < trees[i+1].x {
			cnt++
		}
	}

	println(cnt)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

type tree struct {
	x, h int64
}

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

	n := nextInt()
	trees := make([]tree, n)
	var cnt int64 = 1
	occupied := false

	if n >= 2 {
		cnt++
	}

	for i := range trees {
		trees[i].x = nextInt64()
		trees[i].h = nextInt64()
	}

	for i := 1; i < n-1; i++ {
		// println(trees[i].x, trees[i].h, occupied, cnt)
		if occupied {
			if trees[i].x-trees[i].h > trees[i-1].x+trees[i-1].h {
				cnt++
				occupied = false
				continue
			}
		} else if trees[i].x-trees[i].h > trees[i-1].x {
			cnt++
			occupied = false
			continue
		}

		if trees[i].x+trees[i].h < trees[i+1].x {
			cnt++
			occupied = true
		}
	}

	println(cnt)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

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

type tree struct {
	x, h int64
}

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

	n := nextInt()
	trees := make([]tree, n)
	var cnt int64 = 1
	haveOccupied := false

	if n >= 2 {
		cnt++
	}

	for i := range trees {
		trees[i].x = nextInt64()
		trees[i].h = nextInt64()
	}

	for i := 1; i < n-1; i++ {
		// println(trees[i].x, trees[i].h, haveOccupied, cnt)
		canChop := false
		if haveOccupied {
			if trees[i].x-trees[i].h > trees[i-1].x+trees[i-1].h {
				canChop = true
			}
		} else if trees[i].x-trees[i].h > trees[i-1].x {
			canChop = true
		}

		if canChop {
			cnt++
			haveOccupied = false
			continue
		}

		if trees[i].x+trees[i].h < trees[i+1].x {
			cnt++
			haveOccupied = true
		}

		// if trees[i].x-trees[i].h > trees[i-1].x ||
		// 	trees[i].x+trees[i].h < trees[i+1].x {
		// 	cnt++
		// }
	}
	_ = haveOccupied
	println(cnt)
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

func nextInt() int {
	n, _ := strconv.Atoi(next())
	return n
}

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	return n
}

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

var in = bufio.NewScanner(os.Stdin)
var trees [100010][3]int
var maxis []int
var n, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n = readInt()
  max = 0

  for i := 1; i <= n; i++ {
    trees[i][0], trees[i][1] = readInt(), readInt()
  }

  maxis = append(maxis, 1)
  maxis = append(maxis, -1)

  for i := 2; i <= n; i++ {
    for j := 0; j < len(maxis); j++ {
      idx := 0
      endPos := 0
      if maxis[j] < 0 {
        idx = maxis[j] * -1
        endPos = trees[idx][0]
      } else if maxis[j] > 0 {
        idx = maxis[j]
        endPos = trees[idx][0] + trees[idx][1]
      }

      if endPos <= trees[i][0]-trees[i][1] && (trees[i][0] < trees[i+1][0] || i == n) {
        trees[i][2] = trees[idx][2] + 1
        insertMax(i, true)
      }
      if endPos <= trees[i][0] && (trees[i][0]+trees[i][1] < trees[i+1][0] || i == n) {
        trees[i][2] = trees[idx][2] + 1
        insertMax(i, false)
      }
    }
  }
  fmt.Println(max + 1)
}

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

func insertMax(i int, isleft bool) {
  if max < trees[i][2] {
    max = trees[i][2]
    maxis = maxis[:0]
    if isleft == true {
      maxis = append(maxis, i*-1)
    } else {
              maxis = append(maxis, i)
    }
  } else if max == trees[i][2] {
    if isleft == true {
      maxis = append(maxis, i*-1)
    } else {
      maxis = append(maxis, i)
    }
  }
}

package main

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

var in = bufio.NewScanner(os.Stdin)
var trees [100010][2]int
var n, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n = readInt()
  max = 1

  for i := 0; i < n; i++ {
    trees[i][0], trees[i][1] = readInt(), readInt()
  }

  for i := 1; i < n; i++ {
    ok := false

    if trees[i][0]-trees[i][1] > trees[i-1][0] || trees[i][0]-trees[i][1] > trees[i-1][0]+trees[i-1][0] {
      ok = true
    }
    if (trees[i][0] > trees[i-1][0]+trees[i-1][1] || trees[i][0] > trees[i-1][0]) && trees[i][0]+trees[i][1] < trees[i+1][0] {
      ok = true
    }

    if ok == true {
      max++
    }
  }

  fmt.Println(max)
}

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

package main

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

var in = bufio.NewScanner(os.Stdin)
var trees [100010][2]int
var n, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n = readInt()
  max = 1

  for i := 0; i < n; i++ {
    trees[i][0], trees[i][1] = readInt(), readInt()
  }

  for i := 1; i < n; i++ {
    ok := false

    if trees[i][0]-trees[i][1] > trees[i-1][0] || trees[i][0]-trees[i][1] > trees[i-1][0]+trees[i-1][0] {
      ok = true
    }
    if (trees[i][0] > trees[i-1][0]+trees[i-1][1] || trees[i][0] > trees[i-1][0]) && (trees[i][0]+trees[i][1] < trees[i+1][0] || i == n-1) {
      ok = true
    }

    if ok == true {
      max++
    }
  }

  fmt.Println(max)
}

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

package main

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

var in = bufio.NewScanner(os.Stdin)
var trees [100010][2]int
var n, max int

func init() {
  in.Split(bufio.ScanWords)
}

func main() {
  n = readInt()
  max = 1

  for i := 0; i < n; i++ {
    trees[i][0], trees[i][1] = readInt(), readInt()
  }

  for i := 1; i < n; i++ {
    if (trees[i][0]-trees[i][1] > trees[i-1][0] || trees[i][0]-trees[i][1] > trees[i-1][0]+trees[i-1][0]) && trees[i][0] < trees[i+1][0] {
      max++
    } else if (trees[i][0] > trees[i-1][0]+trees[i-1][1] || trees[i][0] > trees[i-1][0]) && trees[i][0]+trees[i][1] < trees[i+1][0] {
      max++
    }
  }

  fmt.Println(max + 1)
}

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

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...) }

var n int
var x []int
var h []int

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

const (
	LEFT     = iota
	RIGHT    = iota
	STAY     = iota
	SENTINEL = iota
)

func solve(i, lastChoice int) int {
	var left, right, stay int
	if i == n-1 {
		return 1 // always fall to the right
	}
	if lastChoice == SENTINEL {
		// always go left
		left = solve(i+1, LEFT) + 1
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == LEFT {
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == RIGHT {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1]+h[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == STAY {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	}
	//printf("i=%v, ans=%v\n", i, max(left, max(stay, right)))
	return max(left, max(stay, right))
}

func main() {
	defer writer.Flush()
	scanf("%d\n", &n)
	x = make([]int, n)
	h = make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d %d\n", &x[i], &h[i])
	}
	//printf("x=%v\n", x)
	//printf("h=%v\n", h)
	// ans := solve(0, SENTINEL)
	left := make([]int, n)
	right := make([]int, n)
	stay := make([]int, n)
	left[0] = 1
	stay[0] = 1
	if n > 1 && x[0]+h[0] < x[1] {
		right[0] = 1
	}
	for i := 1; i < n; i++ {
		if i == n-1 {
			right[i] = max(left[i-1], max(right[i-1], stay[i-1])) + 1
			continue
		}
		// falling left
		if x[i]-h[i] > x[i-1] {
			left[i] = max(left[i-1], stay[i-1]) + 1
		}
		if x[i-1]+h[i-1] < x[i]-h[i] {
			left[i] = max(left[i], right[i-1]+1)
		}
		// falling right
		if x[i]+h[i] < x[i+1] {
			if x[i-1]+h[i-1] < x[i] {
				right[i] = right[i-1] + 1
			}
			right[i] = max(left[i-1], stay[i-1]) + 1
		}
		// stay
		stay[i] = max(left[i-1], stay[i-1])
		if x[i-1]+h[i-1] < x[i] {
			stay[i] = max(stay[i], right[i-1])
		}
	}
	printf("%v\n", max(stay[n-1], max(left[n-1], right[n-1])))
}

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...) }

var n int
var x []int
var h []int

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

const (
	LEFT     = iota
	RIGHT    = iota
	STAY     = iota
	SENTINEL = iota
)

func solve(i, lastChoice int) int {
	var left, right, stay int
	if i == n-1 {
		return 1 // always fall to the right
	}
	if lastChoice == SENTINEL {
		// always go left
		left = solve(i+1, LEFT) + 1
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == LEFT {
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == RIGHT {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1]+h[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == STAY {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	}
	//printf("i=%v, ans=%v\n", i, max(left, max(stay, right)))
	return max(left, max(stay, right))
}

func main() {
	defer writer.Flush()
	scanf("%d\n", &n)
	x = make([]int, n)
	h = make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d %d\n", &x[i], &h[i])
	}
	//printf("x=%v\n", x)
	//printf("h=%v\n", h)
	// ans := solve(0, SENTINEL)
	left := make([]int, n)
	right := make([]int, n)
	stay := make([]int, n)
	left[0] = 1
	stay[0] = 0
	right[0] = 1
	// if n > 1 && x[0]+h[0] < x[1] {
	// 	right[0] = 1
	// }
	for i := 1; i < n; i++ {
		if i == n-1 {
			right[i] = max(left[i-1], max(right[i-1], stay[i-1])) + 1
			continue
		}
		// falling left
		if x[i]-h[i] > x[i-1] {
			left[i] = max(left[i-1], stay[i-1]) + 1
		}
		if x[i-1]+h[i-1] < x[i]-h[i] {
			left[i] = max(left[i], right[i-1]+1)
		}
		// falling right
		if x[i]+h[i] < x[i+1] {
			if x[i-1]+h[i-1] < x[i] {
				right[i] = right[i-1] + 1
			}
			right[i] = max(left[i-1], stay[i-1]) + 1
		}
		// stay
		stay[i] = max(left[i-1], stay[i-1])
		if x[i-1]+h[i-1] < x[i] {
			stay[i] = max(stay[i], right[i-1])
		}
	}
	printf("%v\n", max(stay[n-1], max(left[n-1], right[n-1])))
}

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...) }

var n int
var x []int
var h []int

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

const (
	LEFT     = iota
	RIGHT    = iota
	STAY     = iota
	SENTINEL = iota
)

func solve(i, lastChoice int) int {
	var left, right, stay int
	if i == n-1 {
		return 1 // always fall to the right
	}
	if lastChoice == SENTINEL {
		// always go left
		left = solve(i+1, LEFT) + 1
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == LEFT {
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == RIGHT {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1]+h[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == STAY {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	}
	//printf("i=%v, ans=%v\n", i, max(left, max(stay, right)))
	return max(left, max(stay, right))
}

func main() {
	defer writer.Flush()
	scanf("%d\n", &n)
	x = make([]int, n)
	h = make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d %d\n", &x[i], &h[i])
	}
	//printf("x=%v\n", x)
	//printf("h=%v\n", h)
	// ans := solve(0, SENTINEL)
	left := make([]int, n)
	right := make([]int, n)
	stay := make([]int, n)
	left[0] = 1
	stay[0] = 0
	if n > 1 && x[0]+h[0] < x[1] {
		right[0] = 1
	}
	for i := 1; i < n; i++ {
		if i == n-1 {
			right[i] = max(left[i-1], max(right[i-1], stay[i-1])) + 1
			continue
		}
		// falling left
		if x[i]-h[i] > x[i-1] {
			left[i] = max(left[i-1], stay[i-1]) + 1
		}
		if x[i-1]+h[i-1] < x[i]-h[i] {
			left[i] = max(left[i], right[i-1]+1)
		}
		// falling right
		if x[i]+h[i] < x[i+1] {
			if x[i-1]+h[i-1] < x[i] {
				right[i] = right[i-1] + 1
			}
			right[i] = max(left[i-1], stay[i-1]) + 1
		}
		// stay
		stay[i] = max(left[i-1], stay[i-1])
		if x[i-1]+h[i-1] < x[i] {
			stay[i] = max(stay[i], right[i-1])
		}
	}
	printf("%v\n", max(stay[n-1], max(left[n-1], right[n-1])))
}

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...) }

var n int
var x []int
var h []int

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

const (
	LEFT     = iota
	RIGHT    = iota
	STAY     = iota
	SENTINEL = iota
)

func solve(i, lastChoice int) int {
	var left, right, stay int
	if i == n-1 {
		return 1 // always fall to the right
	}
	if lastChoice == SENTINEL {
		// always go left
		left = solve(i+1, LEFT) + 1
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == LEFT {
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == RIGHT {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1]+h[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	} else if lastChoice == STAY {
		if x[i]+h[i] < x[i+1] {
			right = solve(i+1, RIGHT) + 1
		}
		if x[i]-h[i] > x[i-1] {
			left = solve(i+1, LEFT) + 1
		}
		stay = solve(i+1, STAY)
	}
	//printf("i=%v, ans=%v\n", i, max(left, max(stay, right)))
	return max(left, max(stay, right))
}

func main() {
	defer writer.Flush()
	scanf("%d\n", &n)
	x = make([]int, n)
	h = make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d %d\n", &x[i], &h[i])
	}
	//printf("x=%v\n", x)
	//printf("h=%v\n", h)
	// ans := solve(0, SENTINEL)
	left := make([]int, n)
	right := make([]int, n)
	stay := make([]int, n)
	left[0] = 1
	stay[0] = 0
	if n > 1 && x[0]+h[0] < x[1] {
		right[0] = 1
	}
	for i := 1; i < n; i++ {
		if i == n-1 {
			right[i] = max(left[i-1], max(right[i-1], stay[i-1])) + 1
			continue
		}
		// falling left
		if x[i]-h[i] > x[i-1] {
			left[i] = max(left[i-1], stay[i-1]) + 1
		}
		if x[i-1]+h[i-1] < x[i]-h[i] {
			left[i] = max(left[i], right[i-1]+1)
		}
		// falling right
		if x[i]+h[i] < x[i+1] {
			if x[i-1]+h[i-1] < x[i] {
				right[i] = right[i-1] + 1
			}
			right[i] = max(right[i], max(left[i-1], stay[i-1])) + 1
		}
		// stay
		stay[i] = max(left[i-1], stay[i-1])
		if x[i-1]+h[i-1] < x[i] {
			stay[i] = max(stay[i], right[i-1])
		}
	}
	printf("%v\n", max(stay[n-1], max(left[n-1], right[n-1])))
}

package main

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

func main() {
		sum := 0
		n := ScanInt()
		blocked := math.MinInt32
		x := make([]int, n)
		h := make([]int, n)
		for i := 0; i < n; i++ {
			x[i], h[i] = ScanInt(), ScanInt()
		}
		x = append(x, math.MaxInt32)
		h = append(h, 0)

		for i := 0; i < n; i++ {
			if blocked <= x[i]-h[i] {
				sum++
				blocked = x[i]
			} else if x[i]+h[i] < x[i+1] {
				sum++
				blocked = x[i] + h[i]
			}
		}
		P(sum)

	out.Flush()
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
		sum := 0
		n := ScanInt()
		blocked := math.MinInt32
		x := make([]int, n)
		h := make([]int, n)
		for i := 0; i < n; i++ {
			x[i], h[i] = ScanInt(), ScanInt()
		}
		x = append(x, math.MaxInt32)
		h = append(h, 0)

		for i := 0; i < n; i++ {
			if blocked < x[i]-h[i] {
				sum++
				blocked = x[i]
			} else if x[i]+h[i] < x[i+1] {
				sum++
				blocked = x[i] + h[i]
			}
		}
		P(sum)

	out.Flush()
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func main() {
	n := ScanInt()
	x, h := make([]int, n+2), make([]int, n+2)
	x[0] = math.MinInt32
	h[0] = 0
	for i := 1; i <= n; i++ {
		x[i] = ScanInt()
		h[i] = ScanInt()
	}
	x[n+1] = math.MaxInt32
	h[n+1] = 0

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

	for i := 1; i <= n; i++ {
		dp[i][0] = Mx(dp[i-1][0], dp[i-1][1], dp[i-1][2])

		if x[i]-x[i-1] > h[i] {
			dp[i][1] = Mx(dp[i-1][0], dp[i-1][1]) + 1
			if x[i]-x[i-1] > h[i]+h[i-1] {
				dp[i][1] = Mx(dp[i][1], dp[i-1][2]+1)
			}
		}
		if x[i+1]-x[i] > h[i] {
			dp[i][2] = Mx(dp[i-1][0], dp[i-1][1], dp[i-1][2]) + 1
		}
	}

	P(dp[n][2])
	out.Flush()
}

func main1() {
	sum := 0
	n := ScanInt()
	blocked := math.MinInt32
	x := make([]int, n)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		x[i], h[i] = ScanInt(), ScanInt()
	}
	x = append(x, math.MaxInt32)
	h = append(h, 0)

	for i := 0; i < n; i++ {
		if blocked < x[i]-h[i] {
			sum++
			blocked = x[i]
		} else if x[i]+h[i] < x[i+1] {
			sum++
			blocked = x[i] + h[i]
		}
	}
	P(sum)

	out.Flush()
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}

func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}


package main

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

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

	var T, n int
	var v, x int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		s := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &v)
			s[i] = s[i-1] + v
		}
		Fscan(in, &x)
		ans, mx, pre := n, int64(0), 0
		for i := range s {
			s[i] -= int64(i) * x
			if i >= pre+2 {
				if s[i-2] > mx {
					mx = s[i-2]
				}
				if mx > s[i] {
					mx = -1e18
					ans--
					pre = i
				}
			}
		}
		Fprintln(out, ans)
	}
}

func main() { CF1616D(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 scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var a = make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	var x int64
	scan(&x)
	var b = make([]int64, n)
	for i := range b {
		b[i] = int64(a[i])
		if i > 0 {
			b[i] += b[i-1]
		}
	}
	for i := range b {
		b[i] -= x * int64(i)
	}

	var (
		ans     = n
		prefmax = x
	)
	for i := 1; i < n; i++ {
		if b[i] >= prefmax {
			prefmax = max(prefmax, b[i-1])
			continue
		}
		ans--
		prefmax = b[i]
		i++
	}
	printf("%v\n", ans)
}

func max(s ...int64) int64 {
	r := s[0]
	for _, i := range s {
		if r < i {
			r = i
		}
	}
	return r
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var a = make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	var x int64
	scan(&x)
	var b = make([]int64, n)
	for i := range b {
		b[i] = int64(a[i])
		if i > 0 {
			b[i] += b[i-1]
		}
	}
	for i := range b {
		b[i] -= x * int64(i)
	}
	var (
		_, bmin, _ = NewSparseTable(b, func(e1, e2 int64) int64 {
			if e1 < e2 {
				return e1
			}
			return e2
		})
		good = func(i, j int) bool {
			y := bmin(i+1, j)
			if i == 0 {
				return y >= x
			}
			return y >= b[i-1]
		}

		p, ans = n, n
	)
	for i := 0; i < len(b); i++ {
		if i == p {
			ans--
			p = n
			continue
		}
		l, r := i, len(b)
		for r-l > 1 {
			m := l + (r-l)/2
			if good(i, m) {
				l = m
			} else {
				r = m
			}
		}
		if p > r {
			p = r
		}
	}
	printf("%v\n", ans)
}

func NewSparseTable(s []int64, op func(x, y int64) int64) (tab [][]int64, get func(int, int) int64, log2 []int64) {
	var N = len(s)
	log2 = make([]int64, N+1)
	for i := 2; i <= N; i++ {
		log2[i] = log2[i>>1] + 1
	}
	tab = make([][]int64, log2[N]+1)
	for i := range tab {
		tab[i] = make([]int64, N)
	}
	for i := range tab[0] {
		tab[0][i] = s[i]
	}
	for i := 1; i <= int(log2[N]); i++ {
		for j := (1 << i) - 1; j < N; j++ {
			tab[i][j] = op(tab[i-1][j], tab[i-1][j-(1<<(i-1))])
		}
	}
	get = func(l, r int) int64 {
		log := log2[r-l+1]
		return op(tab[log][r], tab[log][l+(1<<log)-1])
	}
	return
}

/*	i > 0: p[j] - xj >= p[i-1] - x(i - 1)
	i = 0: p[j] - xj >= x

	 n=10, x=3
a	 2 4 2  4  2  4  2  4  2  4
b  3|2 3 2  3  2  3  2  3  2  3

	 n=3, x=-8
a	 -10 -5 -10
b -8|-10 -7  -9

for b[i] = p[i] - xi --> b[r] >= b[l-1]
*/

package main

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

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

func solveCase() int {
	var n, x int
	var a []int
	fmt.Fscan(in, &n)
	a = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a[i])
	}
	fmt.Fscan(in, &x)

	var ans = 0
	var segs [][]int
	for i := 0; i+1 < n; i++ {
		if a[i]+a[i+1] < x*2 {
			segs = append(segs, []int{i, i + 1})
		}
	}
	for i := 0; i+2 < n; i++ {
		if a[i]+a[i+1]+a[i+2] < x*3 {
			segs = append(segs, []int{i, i + 2})
		}
	}
	sort.Slice(segs, func(i, j int) bool {
		return segs[i][1] < segs[j][1]
	})

	var lastMarked = -3
	for _, seg := range segs {
		if lastMarked < seg[0] {
			lastMarked = seg[1]
			ans++
		}
	}
	return n - ans
}

func main() {
	var ntc int
	fmt.Fscan(in, &ntc)
	for t := 0; t < ntc; t++ {
		fmt.Fprintf(out, "%d\n", solveCase())
	}
	out.Flush()
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
// 	redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var a = make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	var x int64
	scan(&x)
	var b = make([]int64, n)
	for i := range b {
		b[i] = int64(a[i])
		if i > 0 {
			b[i] += b[i-1]
		}
	}
	for i := range b {
		b[i] -= x * int64(i)
	}

	var (
		ans     = n
		prefmax = x
	)
	for i := 1; i < n; i++ {
		if b[i] >= prefmax {
			prefmax = max(prefmax, b[i-1])
			continue
		}
		ans--
		prefmax = b[i]
	}
	printf("%v\n", ans)
}

func max(s ...int64) int64 {
	r := s[0]
	for _, i := range s {
		if r < i {
			r = i
		}
	}
	return r
}

package main

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

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

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

func redirectInputToFile(r *bufio.Reader, fp string) {
	f, err := os.Open(fp)
	if err != nil {
		panic(err)
	}
	r.Reset(f)
}

func main() {
	defer writer.Flush()
	// redirectInputToFile(reader, "input.txt")

	T := 1
	scan(&T)
	for t := 0; t < T; t++ {
		solve()
	}
}

func solve() {
	var n int
	scan(&n)
	var a = make([]int, n)
	for i := range a {
		scan(&a[i])
	}
	var x int64
	scan(&x)
	var b = make([]int64, n)
	for i := range b {
		b[i] = int64(a[i])
		if i > 0 {
			b[i] += b[i-1]
		}
	}
	for i := range b {
		b[i] -= x * int64(i)
	}
	var (
		max   func(int, int) int64
		check func(int, int) bool
		do    func(int, int) int
	)
	_, max, _ = NewSparseTable(b, func(e1, e2 int64) int64 {
		if e1 > e2 {
			return e1
		}
		return e2
	})
	check = func(l, r int) bool {
		if l == r {
			return true
		}
		if l == 0 {
			return x <= b[r]
		}
		return max(l-1, r-2) <= b[r]
	}
	do = func(i, j int) int {
		if i >= j {
			return 0
		}
		l, r := i-1, j+1
		for r-l > 1 {
			m := l + (r-l)/2
			if check(m, j) {
				r = m
			} else {
				l = m
			}
		}
		if r == i {
			return do(i, j-1)
		}
		return do(i, l-1) + 1 + do(r, j-1)
	}
	printf("%v\n", n-do(0, n-1))
}

func NewSparseTable(s []int64, op func(x, y int64) int64) (tab [][]int64, get func(int, int) int64, log2 []int64) {
	var N = len(s)
	log2 = make([]int64, N+1)
	for i := 2; i <= N; i++ {
		log2[i] = log2[i>>1] + 1
	}
	tab = make([][]int64, log2[N]+1)
	for i := range tab {
		tab[i] = make([]int64, N)
	}
	for i := range tab[0] {
		tab[0][i] = s[i]
	}
	for i := 1; i <= int(log2[N]); i++ {
		for j := (1 << i) - 1; j < N; j++ {
			tab[i][j] = op(tab[i-1][j], tab[i-1][j-(1<<(i-1))])
		}
	}
	get = func(l, r int) int64 {
		log := log2[r-l+1]
		return op(tab[log][r], tab[log][l+(1<<log)-1])
	}
	return
}

/*	i > 0: p[j] - xj >= p[i-1] - x(i - 1)
	i = 0: p[j] - xj >= x

	 n=10, x=3
a	 2 4 2  4  2  4  2  4  2  4
b  3|2 3 2  3  2  3  2  3  2  3

	 n=3, x=-8
a	 -10 -5 -10
b -8|-10 -7  -9

for b[i] = p[i] - xi --> b[r] >= b[l-1]
*/

package main

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

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

	var T, n int
	var v, x int64
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		s := make([]int64, n+1)
		for i := 1; i <= n; i++ {
			Fscan(in, &v)
			s[i] = s[i-1] + v
		}
		Fscan(in, &x)
		ans, mx, pre := n, int64(0), 0
		for i := range s {
			s[i] -= int64(i) * x
			if i >= pre+2 {
				if s[i-2] > mx {
					mx = s[i-2]
				}
				if mx > s[i] {
					mx = -1e18
					ans--
					pre = i + 1
				}
			}
		}
		Fprintln(out, ans)
	}
}

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


package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"

	"fmt"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		a := MustParseFields(scanner.Text())

		n := a[0]
		k := a[1]

		ans := solveA(n, k)
		fmt.Println(ans)
	}
}

func solveA(n, k int) int {
	if k == n {
		return 0
	}
	if k > n {
		return k - n
	}

	if (n - k) % 2 == 0 {
		return 0
	}

	return 1

}

func MustParseFields(str string) []int {
	parts := strings.Fields(str)

	var ints []int

	for i := 0; i < len(parts); i++ {
		v, err := strconv.Atoi(parts[i])

		if err != nil {
			panic(err)
		}
		ints = append(ints, v)
	}
	return ints
}

package main

import "fmt"

func main(){

    var t int
    var n int
    var k int

    fmt.Scanf("%d\n",&t)
    //fmt.Printf("%d\n", t);

    for i:=0 ; i<t ; i++ {
        fmt.Scanf("%d %d\n",&n,&k)
        //fmt.Printf("%d %d ",n,k)
        if n<=k {
            fmt.Printf("%d\n",k-n)
            continue
        }else{
            k = n-k
            fmt.Printf("%d\n",k%2)
        }
    }
}

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		n, k := io.NextInt(), io.NextInt()
		ans := 0
		if n < k {
			ans = k - n
			n = k
		}
		if (n+k)%2 != 0 {
			ans++
		}
		io.Println(ans)
	}
}

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

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

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

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

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

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

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

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Fscan(in, &n)
		fmt.Fscan(in, &k)
		steps := 0
		if k > n {
			steps = k - n
		}
		if (n+steps-k)%2 != 0 {
			steps++
		}
		fmt.Println(steps)
	}
}

package main

import (
	"fmt"
)

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

	for i := 0; i < t; i++ {
		var n, k int
		if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
			panic(err)
		}

		ans := 0
		if k >= n {
			ans = k - n
		} else if n % 2 != k % 2 {
			ans = 1
		}

		fmt.Println(ans)
	}
}

package main

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

func main() {
	s := bufio.NewScanner(os.Stdin)

	if err := run(os.Args[1:], s); err != nil {
		fmt.Println(err)
	}
}

func run(args []string, s *bufio.Scanner) error {
	// Problem Logic Here... 😊
	s.Split(bufio.ScanWords)
	s.Scan()

	tc, err := strconv.Atoi(s.Text())
	if err != nil {
		return err
	}

	for tc > 0 && s.Scan() {
		a, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}
		s.Scan()

		k, err := strconv.Atoi(s.Text())
		if err != nil {
			return err
		}

		fmt.Println(solve(a, k, 0))

		tc--
	}

	return nil
}

func solve(a, k, m int) int {
	if k <= a && a % 2 == k % 2 {
		return m
	}
	if k > a {
		return solve(k, k, m + (k - a))
	}
	return solve(a + 1, k, m + 1)
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(r, &t)
	for i := 0; i < t; i++ {
		var n, k int
		fmt.Fscan(r, &n, &k)
		var rls int
		if n < k {
			rls = k - n
		} else if (n-k)%2 > 0 {
			rls = 1
		} else {
			rls = 0
		}
		fmt.Println(rls)
	}
}

package main

import "fmt"

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

    for i := 0 ; i < t; i++ {
        var n, k int
        fmt.Scan(&n, &k)
        ans := 0
        if k < n {
          ans = (n - k) % 2
        } else {
            ans = k - n
        }
        fmt.Println(ans)
    }
}

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

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	nTest := 1
	nTest = rw.NextInt()
	for i := 0; i < nTest; i++ {
		solveCase()
	}
}

func solveCase() {
	n, k := rw.NextInt(), rw.NextInt()
	ans := 0
	if n < k {
		ans += k - n
		n = k
	}
	if (n-k)%2 == 1 {
		ans++
	}
	rw.Println(ans)

}

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

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

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

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

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

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

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

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"

	"fmt"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)

	buff := make([]byte, 2 * 1024 * 1024)

	scanner.Buffer(buff, 1024 * 1024)

	scanner.Scan()

	t := scanner.Text()

	testCases, err := strconv.Atoi(t)

	if err != nil {
		panic(err)
	}

	for j := 0; j < int(testCases); j ++ {
		scanner.Scan()

		a := MustParseFields(scanner.Text())

		n := a[0]
		k := a[1]

		ans := solveA(n, k)
		fmt.Println(ans)
	}
}

func solveA(n, k int) int {
	if k == n {
		return 0
	}
	if k > n {
		return k - n
	}

	if (n - k) % 2 == 0 {
		return 0
	}
	return n - k

}

func MustParseFields(str string) []int {
	parts := strings.Fields(str)

	var ints []int

	for i := 0; i < len(parts); i++ {
		v, err := strconv.Atoi(parts[i])

		if err != nil {
			panic(err)
		}
		ints = append(ints, v)
	}
	return ints
}

package main

import "fmt"

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

    for i := 0 ; i < t; i++ {
        var n, k int
        fmt.Scan(&n, &k)
        ans := 0
        if k < n {
            ans = n % 2
        } else {
            ans = k - n
        }
        fmt.Println(ans)
    }
}

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

package main

import "fmt"

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

    for i := 0 ; i < t; i++ {
        var n, k int
        fmt.Scan(&n, &k)
        ans := 0
        if k == 0 {
            ans = n % 2
        } else if k < n {
          ans = abs(k * 2 - n)
        } else {
            ans = k - n
        }
        fmt.Println(ans)
    }
}

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

package main

import "fmt"

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

    for i := 0 ; i < t; i++ {
        var n, k int
        fmt.Scan(&n, &k)
        ans := 0
        if k < n {
            ans = (n - k) / 2
            ans += (n - k) % 2
        } else {
            ans = k - n
        }
        fmt.Println(ans)
    }
}

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

package main

import "fmt"

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

    for i := 0 ; i < t; i++ {
        var n, k int
        fmt.Scan(&n, &k)
        ans := 0
        if k == 0 {
            ans = n * 2
        } else if k < n {
          ans = abs(k * 2 - n)
        } else {
            ans = k - n
        }
        fmt.Println(ans)
    }
}

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


package main

import "fmt"

func f(a int) int {
	if a%2 == 0 {
		a--
	}
	return a
}

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

	for i := range make([]struct{}, n) {
		if i != 0 {
			fmt.Print(" ")
		}
		var a int
		fmt.Scan(&a)
		fmt.Print(f(a))
	}
	fmt.Println()
}

package main

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

func main() {
	var n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		fmt.Printf("%d ", a-(a+1)%2)
	}
	fmt.Println()
}

// A. Adjacent Replacements
/*
Mishka got an integer array 𝑎 of length 𝑛 as a birthday present (what a surprise!).

Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps:

    Replace each occurrence of 1 in the array 𝑎 with 2;
	  Replace each occurrence of 2 in the array 𝑎 with 1;
	  Replace each occurrence of 3 in the array 𝑎 with 4;
	  Replace each occurrence of 4 in the array 𝑎 with 3;
	 	Replace each occurrence of 5 in the array 𝑎 with 6;
	 	Replace each occurrence of 6 in the array 𝑎 with 5;
	 	…
	 	Replace each occurrence of 109−1 in the array 𝑎 with 109;
	 	Replace each occurrence of 109 in the array 𝑎 with 109−1.

Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers (2𝑖−1,2𝑖) for each 𝑖∈{1,2,…,5⋅108} as described above.

For example, for the array 𝑎=[1,2,4,5,10], the following sequence of arrays represents the algorithm:

[1,2,4,5,10] → (replace all occurrences of 1 with 2) → [2,2,4,5,10] → (replace all occurrences of 2 with 1) → [1,1,4,5,10] → (replace all occurrences of 3 with 4) → [1,1,4,5,10] → (replace all occurrences of 4 with 3) → [1,1,3,5,10] → (replace all occurrences of 5 with 6) → [1,1,3,6,10] → (replace all occurrences of 6 with 5) → [1,1,3,5,10] → … → [1,1,3,5,10] → (replace all occurrences of 10 with 9) → [1,1,3,5,9]. The later steps of the algorithm do not change the array.

Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it.

Input
The first line of the input contains one integer number 𝑛
(1≤𝑛≤1000) — the number of elements in Mishka's birthday present (surprisingly, an array).

The second line of the input contains 𝑛
integers 𝑎1,𝑎2,…,𝑎𝑛 (1≤𝑎𝑖≤109) — the elements of the array.

Output
Print 𝑛 integers — 𝑏1,𝑏2,…,𝑏𝑛, where 𝑏𝑖 is the final value of the 𝑖-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array 𝑎. Note that you cannot change the order of elements in the array.

Examples
Input
5
1 2 4 5 10

Output
1 1 3 5 9

Input
10
10000 10 50605065 1 5 89 5 999999999 60506056 1000000000

Output
9999 9 50605065 1 5 89 5 999999999 60506055 999999999

Note
The first example is described in the problem statement.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

	input2, _ := reader.ReadString('\n')
	a := strings.Split(strings.TrimSpace(input2), " ")

	for i := 0; i < n; i++ {
		v, _ := strconv.Atoi(string(a[i]))
		if v%2 == 0 {
			v--
			a[i] = strconv.Itoa(v)
		}
	}
	fmt.Println(strings.Join(a, " "))
}

package main

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

func f(a int) int {
	if a%2 == 0 {
		a--
	}
	return a
}

func main() {
	io := newIo()
	defer io.flush()

	n := io.nextInt()
	for i := range make([]struct{}, n) {
		if i != 0 {
			io.printf(" ")
		}
		a := io.nextInt()
		io.printf("%d", f(a))
	}
	io.printf("\n")
}

type _io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func newIo() *_io {
	return &_io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (_io *_io) flush() {
	_ = _io.writer.Flush()
}

func (_io *_io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := _io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (_io *_io) next() string {
	for _io.nextToken >= len(_io.tokens) {
		line := _io.nextLine()
		_io.tokens = strings.Fields(line)
		_io.nextToken = 0
	}
	r := _io.tokens[_io.nextToken]
	_io.nextToken++
	return r
}

func (_io *_io) nextInt() int {
	i, _ := strconv.Atoi(_io.next())
	return i
}

func (_io *_io) printf(format string, a ...interface{}) {
	fmt.Fprintf(_io.writer, format, a...)
}

package main

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

func getInts(s *bufio.Scanner, n int) []int {
    s.Scan()
    ab := strings.Fields(s.Text())
    a := make([]int,n)
    for i:=0; i<n; i++ {
        a[i], _ = strconv.Atoi(ab[i])
    }
    return a
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    n := getInts(scanner,1)
    bs := getInts(scanner, n[0])
    for i := 0; i < n[0]; i++ {
        if bs[i] % 2 == 0 {
            fmt.Print(bs[i] - 1)
        } else {
            fmt.Print(bs[i])
        }
        fmt.Print(" ")
    }
}

package main

import "fmt"

const (
    N = 1e3 + 5
)

func main() {
	var n int
	var a [N]int
	var i int

	fmt.Scanf("%d\n", &n)
	for i = 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}
	for i = 0; i < n; i++ {
		if a[i] % 2 == 0 {
			a[i]--
		}
	}
	for i = 0; i < n; i++ {
		fmt.Print(a[i], " ")
	}
	fmt.Println()
 }

package main

import "fmt"

func main(){
	var n,num int
	fmt.Scanf("%d\n",&n)
	for i:=1; i<=n; i++{
		fmt.Scanf("%d",&num)
		if num % 2 == 0{
			fmt.Print(num - 1)
			fmt.Print(" ")
		}else{
			fmt.Print(num)
			fmt.Print(" ")
		}
	}
}

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

//Item eh um elemento da fila de prioridades
type Item struct {
	value    int
	priority int
	index    int
}

//PriorityQueue implmenta a heap interface
type PriorityQueue []*Item

//Len retorna o tamanho da  pq
func (pq PriorityQueue) Len() int { return len(pq) }

//Less verifica se um tem maior priotidade que o outro
func (pq PriorityQueue) Less(i, j int) bool { return pq[i].priority < pq[j].priority }

//Swap troca os elementos de lugar
func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

//Push insere um elemento na pq
func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Item)
	item.index = n
	*pq = append(*pq, item)
}

//Pop remove um elemento da pq
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	item.index = -1 //for safety
	*pq = old[0 : n-1]
	return item
}

//update modifica o valor e a prioridade de um item na fila
func (pq *PriorityQueue) update(item *Item, value int, priority int) {
	item.value = value
	item.priority = priority
	heap.Fix(pq, item.index)
}

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

type pair struct {
	first  interface{}
	second interface{}
}

type intPair struct {
	first  int64
	second int64
}

type vertex struct {
	list []intPair
}

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 max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

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

func main() {
	defer writer.Flush()

	var (
		n   int
		num int
	)

	scanf("%d\n", &n)

	for i := 0; i < n; i++ {
		scanf("%d ", &num)
		if num%2 == 0 {
			printf("%d", num-1)
		} else {
			printf("%d", num)
		}
		if i != n {
			printf(" ")
		}
	}
	printf("\n")
}

package main

import (
	"fmt"
	)

func main() {
	var arrayLength, element int
	var arrayOfElements []int

	// checkExist := make(map[int]bool)

	fmt.Scan(&arrayLength)

	for i:=0; i<arrayLength; i++ {
		fmt.Scan(&element)

		if element % 2 == 0 {
			element --
		}
		arrayOfElements = append(arrayOfElements, element)
	}

	for i:=0; i<arrayLength; i++ {
		fmt.Printf("%d ",arrayOfElements[i])
	}
}

package main
import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	numbers := make([]int, n)
	var max int
	for i := 0; i < n; i++ {
		fmt.Scan(&numbers[i])
		if i == 0 {
			max = numbers[i]
		} else if max < numbers[i] {
			max = numbers[i]
		}
	}
	var temp int
	min := 0
	for ; min != max + max%2; {
		temp = math.MaxInt32
		for i := 0; i < n; i++ {

			if temp > numbers[i] && numbers[i] > min {
				temp = numbers[i]
			}
		}
		for j := 0; j < n; j++ {
			if numbers[j] == temp {
				if numbers[j]%2 == 0 {
					numbers[j]--
				} else {
					numbers[j]++
				}
			}
		}
		min = temp
	}

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

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scanf("%d", &a)
		if a&1 == 1 {
			fmt.Print(a, " ")
		} else {
			fmt.Print(a-1, " ")
		}

	}
}

package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scanln(&n)
	for i := 0; i < n; i++ {
		var a uint64
		fmt.Scan(&a)
		if a%2 == 0 {
			a--
		}
		fmt.Printf("%d ", a)
	}
}

package main

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

func main() {
	var n, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &a)
		fmt.Printf("%d ", (a+1)/2)
	}
	fmt.Println()
}

package main

import "fmt"

func main(){
	var n,num int
	fmt.Scanf("%d",&n)
	for i:=1; i<=n; i++{
		fmt.Scanf("%d",&num)
		if num % 2 == 0{
			fmt.Print(num - 1)
			fmt.Print(" ")
		}else{
			fmt.Print(num)
			fmt.Print(" ")
		}
	}
}

package main

import (
	"fmt"
	)

func main() {
	var arrayLength, element int
	var arrayOfElements []int

	// checkExist := make(map[int]bool)

	fmt.Scan(&arrayLength)

	for i:=0; i<arrayLength; i++ {
		fmt.Scan(&element)

		if element % 2 == 0 {
			element --
		}
		arrayOfElements = append(arrayOfElements, element)
	}

	fmt.Println(arrayOfElements)
}

package main
import (
	"fmt"
	"math"
)

func main() {
	var n int
	fmt.Scanf("%d", &n)
	numbers := make([]int, n)
	var max int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &numbers[i])
		if i == 0 {
			max = numbers[i]
		} else if max < numbers[i] {
			max = numbers[i]
		}
	}
	var temp int
	min := 0
	for ; min != max + max%2; {
		temp = math.MaxInt32
		for i := 0; i < n; i++ {

			if temp > numbers[i] && numbers[i] > min {
				temp = numbers[i]
			}
		}
		for j := 0; j < n; j++ {
			if numbers[j] == temp {
				if numbers[j]%2 == 0 {
					numbers[j]--
				} else {
					numbers[j]++
				}
			}
		}
		min = temp
	}

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


package main

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

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
	}

	for t := in(); t > 0; t-- {
		n, x := in(), in()

		f := 1

		if n > 2 {
			if (n-2)%x == 0 {
				f += (n - 2) / x
			} else {
				f += (n-2)/x + 1
			}
		}

		fmt.Println(f)
	}

}

package main
import."fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var T, n, x int
	for Scan(&T); T > 0; T-- {
		Scan(&n, &x)
		if n < 3 {
			Println(1)
		} else {
			Println((n-3)/x + 2)
		}
	}
}

package main

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

func print( a ...interface{}) { fmt.Fprint(w, a...) }
func scan( a ...interface{})  { fmt.Fscan(r, a...) }

//for i := 0; i < n; i++  {

func main() {
defer w.Flush()
	var q int
	scan(&q)
	for ; q > 0; q-- {
		var n int
		scan(&n)
		var x int
		scan(&x)
		if n <= 2 {
			print(1, "\n")
		}else{
			var ans = (n - 2)/x + 2
			if (n - 2)%x == 0 {
				ans--
			}
			print(ans, "\n")
		}
	}
}

package main

import (
"fmt"
"bufio"
"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 main() {

	defer writer.Flush()

	var t,i int
	scanf("%d\n", &t) // t -> no. of test cases
	ans  := make([] int, t)
	for i = 1; i<=t; i++ {

		var n, x int
		scanf("%d %d\n", &n, &x)

		if n<=2 {
			ans[i-1] = 1
		}else if (n-2)%x == 0 {
			ans[i-1] = (n-2)/x + 1
		}else { ans[i-1] = (n-2)/x + 2}

	}
	for i = 0; i<t; i++ {
		printf("%d\n", ans[i])
	}

}

package main

import. "fmt"

func solve() {
  var aptNumber int
  var aptCount int
  Scan(&aptNumber)
  Scan(&aptCount)
  if aptNumber <= 2 {
    Println(1)
  } else {
    aptNumber = aptNumber-2
    if aptNumber%aptCount == 0 {
      Println(aptNumber/aptCount + 1)
    } else {
      Println(aptNumber/aptCount + 2)
    }
  }
}

func main() {
var inputs int
Scan(&inputs)
for inputs>0 {
   solve()
   inputs--
  }
}

package main

import. "fmt"
import. "math"

func solve() {
  var aptNumber int
  var aptCount int
  Scan(&aptNumber)
  Scan(&aptCount)
  if aptNumber <= 2 {
    Println(1)
  } else {
    Println(Ceil(float64(aptNumber-2+aptCount)/ float64(aptCount)))
  }
}

func main() {
var inputs int
Scan(&inputs)
for inputs>0 {
   solve()
   inputs--
  }
}

package main

import. "fmt"

func solve() {
  var aptNumber int
  var aptCount int
  Scan(&aptNumber)
  Scan(&aptCount)
  if aptNumber <= 2 {
    Println(1)
  } else {
    Println((aptNumber-3)/aptCount + 2)
  }
}

func main() {
var inputs int
Scan(&inputs)
for inputs>0 {
   solve()
   inputs--
  }
}

package main

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

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

func main() {
	defer writer.Flush()
	var testCaseNum, n, x int
	fmt.Fscan(reader, &testCaseNum)

	for testCase := 0; testCase < testCaseNum; testCase++ {
		fmt.Fscan(reader, &n, &x)
		if n < 3 {
			fmt.Fprintln(writer, 1)
		} else {
			fmt.Fprintln(writer, (n-3)/x+2)
		}
	}
}

package main

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

func main() {
	var t, x, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &x)
		fmt.Printf("%.0f\n", math.Ceil(float64(pos(n-2))/float64(x))+1)
	}
}

func pos(a int) int {
	if a < 0 {
		return 0
	}
	return a
}

package main

import "fmt"

func main() {
	var t, n, x int
	fmt.Scanf("%d\n", &t)
	// fmt.Println(t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d\n", &n, &x)
		if n < 3 {
			fmt.Println(1)
		} else {
			fmt.Println((n-3)/x + 2)
		}
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

func solve() {
	n := nextInt()
	x := nextInt()
	if n <= 2 {
		printf("1\n");
		return
	}
	printf("%d\n", (n+x-3)/x + 1);
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)

	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		solve()
	}
}

package main

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

func solve(input io.Reader, output io.Writer) {
	var t, x, y, result int
	fmt.Fscanf(input, "%d\n", &t)
	for i := 0; i < t; i++ {
		fmt.Fscanf(input, "%d %d\n", &x, &y)
		if x <= 2 {
			result = 1
		} else {
			result = int((x - 3) / y + 2)
		}
		fmt.Fprintln(output, result)
	}
}

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

package main

import (
	"fmt"
	"bufio"
	"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, x int
	scanf("%d %d\n", &n, &x)
	var ans int
	if n < 3 {
		ans = 1
	} else {
		ans = (n - 3) / x + 2
	}
	printf("%d\n", ans)
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0;t-- {
		solve()
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		fmt.Println(solve(ReadInt64(), ReadInt64()))
	}
}

func solve(n, x int64) int64 {
	if n <= 2 {
		return 1
	}
	return (n - 2 + x + x - 1) / x
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) []int64 {
	v := make([]int64, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

// ==================== 以上是模版 ====================
func solve() {
	n := nextInt()
	x := nextInt()
	if n <= 2 {
		printf("%d\n", 1)
	} else {
		printf("%d\n", (n-2+x-1)/x+1)
	}
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)

	//x := `4
	//7 3
	//1 5
	//22 5
	//987 13`
	//in = bufio.NewReaderSize(strings.NewReader(x), 8192)

	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		solve()
	}

}

package main

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

func main() {
	var t, x, n int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &x)
		fmt.Printf("%.0f\n", math.Ceil(float64(n-2)/float64(x))+1)
	}
}

package main

import "fmt"

func main() {
	var t, n, x int
	fmt.Scanf("%d\n", &t)
	// fmt.Println(t)
	for i := 0; i < t; i++ {
		fmt.Scanf("%d %d\n", &n, &x)
		if n < 3 {
			fmt.Println(n)
		} else {
			fmt.Println((n-3)/x + 2)
		}
	}
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

// ==================== 以上是模版 ====================
func solve() {
	n:=nextInt()
	x:=nextInt()
	printf("%d\n", (n-2+x-1)/x + 1)
}

func main() {

	//in = bufio.NewReaderSize(os.Stdin, 8192)
	//x:=`4
	//7 3
	//1 5
	//22 5
	//987 13`

	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		solve()
	}

}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

// ==================== 以上是模版 ====================
func solve() {
	n := nextInt()
	x := nextInt()
	if n <= 2 {
		printf("%d\n", 1)
	} else {
		printf("%d\n", (n-2+x-1)/x+1)
	}
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)

	x := `4
	7 3
	1 5
	22 5
	987 13`
	in = bufio.NewReaderSize(strings.NewReader(x), 8192)

	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		solve()
	}

}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

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

// ==================== 以上是模版 ====================
func solve() {
	n := nextInt()
	x := nextInt()
	if n <= 2 {
		printf("%d\n", n)
	}
	printf("%d\n", (n-2+x-1)/x+1)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)

	//x := `4
	//1 1
	//7 3
	//1 5
	//22 5
	//987 13`
	//in = bufio.NewReaderSize(strings.NewReader(x), 8192)

	out = bufio.NewWriterSize(os.Stdout, 8192)
	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		solve()
	}

}

package main

import (
"fmt"
"bufio"
"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 main() {

	defer writer.Flush()

	var t,i int
	scanf("%d\n", &t) // t -> no. of test cases
	ans  := make([] int, t)
	for i = 1; i<=t; i++ {

		var n, x int
		scanf("%d %d\n", &n, &x)
		ans[i-1] = (n-2)/x + 1

	}
	for i = 0; i<t; i++ {
		printf("%d\n", ans[i])
	}

}

package main

import (
  "fmt"
  "math"
)

func main() {

var inputs int
var aptNumber int
var aptCount int

fmt.Scanf("%d", &inputs)

for inputs>0 {
  fmt.Scanf("%d", &aptNumber)
  fmt.Scanf("%d", &aptCount)

  if aptNumber == 1 || aptNumber == 2 {
    fmt.Println("1")
    inputs--
    continue
  }

  fmt.Println(math.Ceil(float64(aptNumber-2+aptCount)/float64(aptCount)))
  inputs--

  }

}

package main

import (
  "fmt"
  "math"
)

func solve() {
  var aptNumber int
  var aptCount int
  fmt.Scanf("%d", &aptNumber)
  fmt.Scanf("%d", &aptCount)
  if aptNumber <= 2 {
    fmt.Println("1")
  } else {
  fmt.Println(math.Ceil(float64(aptNumber-2+aptCount)/float64(aptCount)))
  }
}

func main() {
var inputs int
fmt.Scanf("%d", &inputs)
for inputs>0 {
   solve()
   inputs--
  }
}