package main

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

type Node struct {
	value int
	count int64
}

func reverse(a []int) {
	for i := 0; ; i++ {
		j := len(a) - i - 1
		if i >= j {
			return
		}
		a[i], a[j] = a[j], a[i]
	}
}

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

	fmt.Fscanf(reader, "%d\n", &n)
	number := make([]int, 0, 1000000)
	sorted := make([]int, 0, 1000000)
	stack := make([]*Node, 1000000, 1000000)
	var pointer int
	for i := 0; i < n; i++ {
		var hill int
		fmt.Fscanf(reader, "%d ", &hill)
		number = append(number, hill)
		sorted = append(sorted, hill)
	}

	sort.Ints(sorted)
	max := sorted[n-1]
	prev, pos := max, n

	result := int64(0)
	maxPos := 0
	for i := n - 1; i >= 0; i-- {
		if sorted[i] != prev {
			pos = i + 1
			max = sorted[i]
		}
		inc := n - pos
		if inc >= 2 {
			result += 2
		} else {
			result += int64(inc)
		}
		if number[i] == max {
			maxPos = i
		}
	}
	reverse(number[:maxPos])
	reverse(number[maxPos:])
	reverse(number)

	for i := 0; i < len(number); i++ {
		for pointer != 0 {
			if stack[pointer-1].value == number[i] {
				stack[pointer-1].count++
				break
			} else if stack[pointer-1].value > number[i] {
				stack[pointer] = &Node{number[i], 1}
				pointer++
				break
			} else {
				count := stack[pointer-1].count
				result = result + (count * (count - 1) / 2)
				pointer--
			}
		}
		if pointer == 0 {
			stack[pointer] = &Node{number[i], 1}
			pointer++
		}
	}

	for pointer != 0 {
		count := stack[pointer-1].count
		result = result + (count * (count - 1) / 2)
		pointer--
	}

	fmt.Printf("%d", result)

}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	H := readNNums(reader, n)
	fmt.Println(solve(n, H))
}

func solve(n int, H []int) int64 {
	HH := make([]int, 2*n)
	copy(HH, H)
	copy(HH[n:], H)

	stack := make([]int, 2*n)
	var head, tail int
	var res int64
	for i := 0; i < n; i++ {
		for tail > head && H[stack[tail-1]] < H[i] {
			res++
			if tail > head+1 && H[stack[tail-1]] == H[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}

	for i := n; i < 2*n; i++ {
		for head < tail && stack[head] <= i-n {
			head++
		}
		for tail > head && HH[stack[tail-1]] < HH[i] {
			res++
			if tail > head+1 && HH[stack[tail-1]] == HH[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}
	// the only issue here is the same height hills

	if tail-2 > head && HH[stack[tail-1]] == HH[stack[head]] {
		res++
	}

	for tail-1 > head {
		if HH[stack[tail-1]] == HH[stack[tail-2]] {
			res++
		}
		tail--
	}

	return res
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	H := readNNums(reader, n)
	fmt.Println(solve(n, H))
}

func solve(n int, H []int) int64 {
	HH := make([]int, 2*n)
	copy(HH, H)
	copy(HH[n:], H)

	stack := make([]int, 2*n)
	var head, tail int
	var res int64
	for i := 0; i < n; i++ {
		for tail > head && H[stack[tail-1]] < H[i] {
			res++
			if tail > head+1 && H[stack[tail-1]] == H[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}

	for i := n; i < 2*n; i++ {
		for head < tail && stack[head] <= i-n {
			head++
		}
		for tail > head && HH[stack[tail-1]] < HH[i] {
			res++
			if tail > head+1 && HH[stack[tail-1]] == HH[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}
	// the only issue here is the same height hills

	if tail-1 > head && HH[stack[tail-1]] == HH[stack[head]] {
		res++
	}

	for tail-1 > head {
		if HH[stack[tail-1]] == HH[stack[tail-2]] {
			res++
		}
		tail--
	}

	return res
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	H := readNNums(reader, n)
	fmt.Println(solve(n, H))
}

func solve(n int, H []int) int64 {
	HH := make([]int, 2*n)
	copy(HH, H)
	copy(HH[n:], H)

	stack := make([]int, 2*n)
	var head, tail int
	var res int64
	for i := 0; i < n; i++ {
		for tail > head && H[stack[tail-1]] < H[i] {
			res++
			if tail > head+1 && H[stack[tail-1]] == H[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}

	for i := n; i < 2*n; i++ {
		for head < tail && stack[head] <= i-n {
			head++
		}
		for tail > head && HH[stack[tail-1]] < HH[i] {
			res++
			if tail > head+1 && HH[stack[tail-1]] == HH[stack[tail-2]] {
				res++
			}
			tail--
		}
		//res += int64(tail - head)
		stack[tail] = i
		tail++
	}
	// the only issue here is the same height hills

	for tail-1 > head {
		if HH[stack[tail-1]] == HH[stack[tail-2]] {
			res++
		}
		tail--
	}

	return res
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}


package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readNum(reader)
	H := readNNums(reader, n)
	fmt.Println(solve(n, H))
}

func solve(n int, H []int) int64 {
	hills := make([]int, n+1)

	var pivot int
	for i := 1; i < n; i++ {
		if H[i] > H[pivot] {
			pivot = i
		}
	}

	copy(hills, H[pivot:])
	copy(hills[n-pivot:], H[0:])
	hills[n] = H[pivot]
	//n++

	C := make([]int, n+1)
	R := make([]int, n+1)

	for i := n - 1; i >= 0; i-- {
		R[i] = i + 1
		for R[i] < n && hills[i] > hills[R[i]] {
			R[i] = R[R[i]]
		}
		if R[i] < n && hills[i] == hills[R[i]] {
			C[i] = C[R[i]] + 1
			R[i] = R[R[i]]
		}
	}

	L := make([]int, n+1)
	for i := 1; i <= n; i++ {
		L[i] = i - 1
		for L[i] > 0 && hills[i] >= hills[L[i]] {
			L[i] = L[L[i]]
		}
	}

	var res int64

	for i := 0; i < n; i++ {
		res += int64(C[i])
		if hills[i] < hills[0] {
			if L[i] == 0 && R[i] == n {
				res++
			} else {
				res += 2
			}
		}
	}

	return res
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}


n = input()
a = map(int, raw_input().split())
i = a.index(max(a))
a = [1 << 30] + a[i:] + a[:i]
#print a

f, g, t = [0], [1], 0
for i in xrange(1, n + 1):
	j, k = i - 1, 1
	while a[j] <= a[i]:
		if a[j] == a[i]: k += g[j]
		t += g[j]
		j = f[j]
	if j: t += 1
	f.append(j)
	g.append(k)
#print f,g

h = 0
for i in xrange(n, 1, -1):
	if h <= a[i]:
		h = a[i]
		if f[i] > 1: t += 1

print t


"""

E. Bindian Signalizing

time limit per test
4 seconds

memory limit per test
256 megabytes

input
standard input

output
standard output

Everyone knows that long ago on the territory of present-day Berland there lived Bindian tribes. Their capital was surrounded by n hills, forming a circle. On each hill there was a watchman, who watched the neighbourhood day and night.

In case of any danger the watchman could make a fire on the hill. One watchman could see the signal of another watchman, if on the circle arc connecting the two hills there was no hill higher than any of the two. As for any two hills there are two different circle arcs connecting them, the signal was seen if the above mentioned condition was satisfied on at least one of the arcs. For example, for any two neighbouring watchmen it is true that the signal of one will be seen by the other.

An important characteristics of this watch system was the amount of pairs of watchmen able to see each other's signals. You are to find this amount by the given heights of the hills.

Input

The first line of the input data contains an integer number n (3 ≤ n ≤ 106), n — the amount of hills around the capital. The second line contains n numbers — heights of the hills in clockwise order. All height numbers are integer and lie between 1 and 109.

Output

Print the required amount of pairs.

Examples

Input

5
1 2 4 5 3

Output

7

E. Bindian Signalizing
time limit per test4 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Everyone knows that long ago on the territory of present-day Berland the
re lived Bindian tribes. Their capital was surrounded by n hills, formin
g a circle. On each hill there was a watchman, who watched the neighbour
hood day and night.

In case of any danger the watchman could make a fire on the hill. One wa
tchman could see the signal of another watchman, if on the circle arc co
nnecting the two hills there was no hill higher than any of the two. As
for any two hills there are two different circle arcs connecting them, t
he signal was seen if the above mentioned condition was satisfied on at
least one of the arcs. For example, for any two neighbouring watchmen it
 is true that the signal of one will be seen by the other.

An important characteristics of this watch system was the amount of pair
s of watchmen able to see each other's signals. You are to find this amo
unt by the given heights of the hills.

Input
The first line of the input data contains an integer number n (3 ≤ n ≤ 1
06), n — the amount of hills around the capital. The second line contain
s n numbers — heights of the hills in clockwise order. All height number
s are integer and lie between 1 and 109.

Output
Print the required amount of pairs.

Examples
input
5
1 2 4 5 3
output
7

********
4123 DP
********
[0, 0, 1, 1, 1]
To find the higher left neighbour
process from 1 - n + 1

Iter #1
z1[1] <= z1[0]
stop, i2 = 0

Iter #2
z1[2] <= z1[1]
true, i2 = 1

Iter #3
z1[3] <= z1[2]
i2 = z1[2] // = 1
z1[3] <= z1[1]
true, i2 = 1

Iter #4
z1[4] <= z1[3]
i2 = z1[3] // = 1
z1[3] <= z1[1]
true , i2 = 1
"""
n = input()
z1 = map(int,raw_input().split())
i1 = z1.index(max(z1))
z1 = [1<<30] + z1[i1:] + z1[:i1] #array slicing
#max of int

a1 = [0] #list of higher neighbour of each object
a2 = [1] #list of credit for relationship
b1= 0    #count of pairing

for i1 in xrange(1, n + 1):
    i2 = i1 - 1 #always the first hill on the left
    c1 = 1

    while z1[i2] <= z1[i1]:     # iterate to the furthest higher neighbour
        if z1[i2] == z1[i1]:
            c1 += a2[i2]        #update credit required for relationship
        b1 += a2[i2]            #assigning relationship from z1[i1] to z1[i2] by paying credit as in a2[i2]

        """
        22
        [1,1,2]
        possible pairs
        = 1  = 0 + a2[1], i2 = 0

        222
        [1,1,2,3]
        possible pairs
        222
        = 3 = 1 + a2[2], i2 = 0
        adding a new hill after 22 will take accumulated = 1 + credit = a2[2] = 2

        2222
        [1,1,2,3,4]
        = 6 = 3 + a2[3], i2 = 0

        4222
        [1,1,1,2,3]
        = 5 = 3 + a2[3], i2 = 1
        5 += 1
        """

        i2 = a1[i2]

    if i2:
        b1 += 1

    a1.append(i2)
    a2.append(c1)

c1 = 0
for i1 in xrange(n, 1, -1):
    if c1 <= z1[i1]:
        c1 = z1[i1]
        if a1[i1] > 1:
            b1 += 1

print b1


def main():
    n = input()
    c, l, r = [0]*(n+1), [0]*(n+1), [0]*(n+1)
    h = map(int, raw_input().split(' '))
    x = 0
    for i in xrange(n):
        if h[i] > h[x]:
            x = i
    h = h[x:]+h[0:x]
    h.append(h[0])
    for i in xrange(n-1, -1, -1):
        r[i] = i+1
        while r[i] < n and h[i] > h[r[i]]:
            r[i] = r[r[i]]
        if r[i] < n and h[i] == h[r[i]]:
            c[i] = c[r[i]]+1
            r[i] = r[r[i]]
    ans = 0
    for i in xrange(n):
        ans += c[i]
        if h[i] < h[0]:
            l[i] = i-1
            while l[i] > 0 and h[i] >=h[l[i]]:
                l[i] = l[l[i]]
            ans += 2
            if l[i] == 0 and r[i] == n:
                ans -= 1
    print(ans)

main()


def main():
    n = input()
    c, l, r = [0]*(n+1), [0]*(n+1), [0]*(n+1)
    h = map(int, raw_input().split(' '))
    x = 0
    for i in xrange(n):
        if h[i] > h[x]:
            x = i
    h = h[x:]+h[0:x]
    h.append(h[0])
    for i in xrange(n-1, -1, -1):
        r[i] = i+1
        while r[i] < n and h[i] > h[r[i]]:
            r[i] = r[r[i]]
        if r[i] < n and h[i] == h[r[i]]:
            c[i] = c[r[i]]+1
            r[i] = r[r[i]]
    ans = 0
    for i in xrange(n):
        ans += c[i]
        if h[i] < h[0]:
            l[i] = i-1
            while l[i] > 0 and h[i] > h[l[i]]:
                l[i] = l[l[i]]
            ans += 2
            if l[i] == 0 and r[i] == n:
                ans -= 1
    print(ans)

main()


def main():
    n = input()
    c, l, r = [0]*(n+1), [0]*(n+1), [0]*(n+1)
    h = map(int, raw_input().split(' '))
    x = 0
    for i in xrange(n):
        if h[i] > h[x]:
            x = i
    h = h[x:]+h[0:x]
    h.append(h[0])
    for i in xrange(n-1, -1, -1):
        r[i] = i+1
        while r[i] < n and h[i] >=h[r[i]]:
            r[i] = r[r[i]]
        if r[i] < n and h[i] == h[r[i]]:
            c[i] = c[r[i]]+1
            r[i] = r[r[i]]
    ans = 0
    for i in xrange(n):
        ans += c[i]
        if h[i] < h[0]:
            l[i] = i-1
            while l[i] > 0 and h[i] > h[l[i]]:
                l[i] = l[l[i]]
            ans += 2
            if l[i] == 0 and r[i] == n:
                ans -= 1
    print(ans)

main()


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    double r , d;
    cin >> r >> d;
    int n;
    cin >> n;
    int ans = 0;
    while(n--) {
        double x , y , rr;
        cin >> x >> y >> rr;
        double len = sqrt(x * x + y * y);
        if(len + rr > r) ans++;
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    double r , d;
    cin >> r >> d;
    int n;
    cin >> n;
    int ans = 0;
    while(n--) {
        double x , y , rr;
        cin >> x >> y >> rr;
        double len = sqrt(x * x + y * y);
        if(len + rr <= r && len - rr >= d) ans++;
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    double r , d;
    cin >> r >> d;
    int n;
    cin >> n;
    int ans = 0;
    while(n--) {
        double x , y , rr;
        cin >> x >> y >> rr;
        double len = sqrt(x * x + y * y);
        if(rr == 0) continue;
        if(len + rr <= r) {
            if(d == 0) ans++;
            else {
                if(len - rr >= d) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    double r , d;
    cin >> r >> d;
    int n;
    cin >> n;
    int ans = 0;
    while(n--) {
        double x , y , rr;
        cin >> x >> y >> rr;
        double len = sqrt(x * x + y * y);
        if(len + rr <= r) {
            if(r - d == 0) ans++;
            else {
                if(len - rr >= r - d) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

int main() {
    double r , d;
    cin >> r >> d;
    int n;
    cin >> n;
    int ans = 0;
    while(n--) {
        double x , y , rr;
        cin >> x >> y >> rr;
        double len = sqrt(x * x + y * y);
        if(len + rr <= r) {
            if(d == 0) ans++;
            else {
                if(len - rr >= d) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000007; //10e6

#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

int v[N];

ll dist(ll x1, ll y1) {
	return (x1 * x1 + y1 * y1);
}

int main() {
	int n;
	ll r, d;

	scanf("%lld %lld %d", &r, &d, &n);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ll x, y, ri;
		scanf("%lld %lld %lld", &x, &y, &ri);

		ll D = dist(x, y);
		if (D >= r*r - 2ll*r*d + d*d && D <= r*r + d*d + ri*ri - 2ll*r*d - 2ll*d*ri + 2ll*r*ri && D <= r*r - 2ll*r*ri + ri*ri) {
		// if (D >= r*r - 2ll*r*d + d*d && D <= r - d + ri && D <= r - ri) {
			ans++;
			// printf("%d\n", i+1);
		}
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000007; //10e6

#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

int v[N];

ll dist(ll x1, ll y1) {
	return (x1 * x1 + y1 * y1);
}

int main() {
	int n;
	ll r, d;

	scanf("%lld %lld %d", &r, &d, &n);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ll x, y, ri;
		scanf("%lld %lld %lld", &x, &y, &ri);

		if (dist(x, y) >= r - d && dist(x, y) <= r - d + ri && dist(x, y) + ri <= r) {
			ans++;
			// printf("%d\n", i+1);
		}
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000007; //10e6

#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

int v[N];

ll dist(ll x1, ll y1) {
	return (x1 * x1 + y1 * y1);
}

int main() {
	int n;
	ll r, d;

	scanf("%lld %lld %d", &r, &d, &n);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ll x, y, ri;
		scanf("%lld %lld %lld", &x, &y, &ri);

		ll D = dist(x, y);
		if (D >= r*r - 2ll*r*d + d*d &&
			D >= r*r + d*d + ri*ri - 2ll*r*d - 2ll*d*ri + 2ll*r*ri &&
			D <= r*r - 2ll*r*ri + ri*ri &&
			D <= r*r) {
		// if (D >= r*r - 2ll*r*d + d*d && D <= r - d + ri && D <= r - ri) {
			ans++;
			// printf("%d\n", i+1);
		}
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000007; //10e6

#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

int v[N];

double dist(double x1, double y1) {
	return sqrt(x1 * x1 + y1 * y1);
}

int main() {
	int n;
	double r, d;

	scanf("%lf %lf %d", &r, &d, &n);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		double x, y, ri;
		scanf("%lf %lf %lf", &x, &y, &ri);

		if (dist(x, y) >= r- d && dist(x, y) <= r - d + ri && dist(x, y) + ri <= r) {
			ans++;
			// printf("%d\n", i+1);
		}
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000007; //10e6

#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

int v[N];

ll dist(ll x1, ll y1) {
	return (x1 * x1 + y1 * y1);
}

int main() {
	int n;
	ll r, d;

	scanf("%lld %lld %d", &r, &d, &n);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ll x, y, ri;
		scanf("%lld %lld %lld", &x, &y, &ri);

		ll D = dist(x, y);
		if (D > r*r - 2ll*r*d + d*d && D <= r*r + d*d + ri*ri - 2ll*r*d - 2ll*d*ri + 2ll*r*ri && D <= r*r - 2ll*r*ri + ri*ri && D < r*r) {
		// if (D >= r*r - 2ll*r*d + d*d && D <= r - d + ri && D <= r - ri) {
			ans++;
			// printf("%d\n", i+1);
		}
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1000007; //10e6

#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

int v[N];

ll dist(ll x1, ll y1) {
	return (x1 * x1 + y1 * y1);
}

int main() {
	int n;
	ll r, d;

	scanf("%lld %lld %d", &r, &d, &n);

	int ans = 0;
	for (int i = 0; i < n; i++) {
		ll x, y, ri;
		scanf("%lld %lld %lld", &x, &y, &ri);

		ll D = dist(x, y);
		if (D >= r*r - 2ll*r*d + d*d && D <= r*r + d*d + ri*ri - 2ll*r*d - 2ll*d*ri + 2ll*r*ri && D <= r*r - 2ll*r*ri + ri*ri && D <= r*r) {
		// if (D >= r*r - 2ll*r*d + d*d && D <= r - d + ri && D <= r - ri) {
			ans++;
			// printf("%d\n", i+1);
		}
	}

	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int R ,d;
    cin>>R>>d;
    int n;
    cin>>n;
    int x,y ,r;int y=0;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>r;
        int h=x*x+y*y;
        h=sqrt(h);
        if(h>=R-r+d&&h+r<R)
        {
            y++;
        }
    }
    cout<<y;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int R ,d;
    cin>>R>>d;
    int n;
    cin>>n;
    int x,y ,r;int c=0;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>r;
        int h=x*x+y*y;
        h=sqrt(h);
        if(h>=R-r+d&&h+r<R)
        {
            c++;
        }
    }
    cout<<c;

    return 0;
}


#include<bits/stdc++.h>

typedef long long int ll;

#define dbg printf("in\n");
#define nl printf("\n");
#define pp pair<string,int>
#define N 250000

using namespace std;

int main()
{
    //freopen("in.txt","r",stdin);

    ll i,k;
    ll R,d,n;
    ll x,y,r;

    double j;

    cin>>R>>d;
    cin>>n;

    ll count=0;
    for(i=0;i<n;i++)
    {
        cin>>x>>y>>r;

        //outside R-d circle, d>c1+c2
        //c1=R, c2=r, d=x*x-y*y
        //inside R circle, d+c2<=c1

        j=(x*x)+(y*y);
        j=sqrt(j);

        if(j>=(R-d+r) && j+r<=R)
            count++;
    }

    cout<<count;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int R ,d;
    cin>>R>>d;
    int n;
    cin>>n;
    int x,y ,r;int c=0;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>r;
        double h=x*x+y*y;
        h=sqrt(h);
        if(h>=R-r+d&&h+r<=R)
        {
            c++;
        }
    }
    cout<<c;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int R ,d;
    cin>>R>>d;
    int n;
    cin>>n;
    int x,y ,r;int c=0;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>r;
        double h=(x*x)+(y*y);
        h=sqrt(h);
        if(h>=R-r+d&&h+r<=R)
        {
            c++;
        }
    }
    cout<<c;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main()
{
    int R ,d;
    cin>>R>>d;
    int n;
    cin>>n;
    int x,y ,r;int c=0;
    for(int i=0;i<n;i++)
    {
        cin>>x>>y>>r;
        double h=x*x+y*y;
        h=sqrt(h);
        if(h>=R-r+d&&h+r<R)
        {
            c++;
        }
    }
    cout<<c;

    return 0;
}


#include <bits/stdc++.h>
#define FOR(i, n) for (int i=0; i<n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define DFOR(V,B,E,A) for (int V=B-(A<0); (A>0)==(V<E); V+=A)
#define OUTV(x) FOR(j,x.size()) cout<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define BLE cerr<<"BLE"<<endl;
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
using namespace std;
typedef long long int LL; typedef vector<LL> VLL;
typedef vector<int> VI; typedef vector<VI> VVI;
typedef pair<int, int> PII; typedef vector<PII> VPII;
typedef vector<bool> VB; typedef vector<VB> VVB;
typedef long double LD;

const LD EPS = 1e-7;

LL Mod (LL x, LL y){
	return x*x+y*y;
}

LL sq (LL x){ return  x*x;}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LL d, r;
	cin >> r >> d;
	int n;
	cin >> n;
	int ans = 0;
	if (d == 0){
		FOR (i, n){
			LL x, y, R;
			cin >> x >> y >> R;
			LL m = Mod(x, y);
			if (m <= sq(r - R)) ++ans;
		}
	}
	else FOR(i, n){
		LL x, y, R;
		cin >> x >> y >> R;
		LL m = Mod(x, y);
		if (m >= sq(d + R) and m <= sq(r - R) and d >= 2*R) ++ans;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define FOR(i, n) for (int i=0; i<n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define DFOR(V,B,E,A) for (int V=B-(A<0); (A>0)==(V<E); V+=A)
#define OUTV(x) FOR(j,x.size()) cout<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define BLE cerr<<"BLE"<<endl;
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
using namespace std;
typedef long long int LL; typedef vector<LL> VLL;
typedef vector<int> VI; typedef vector<VI> VVI;
typedef pair<int, int> PII; typedef vector<PII> VPII;
typedef vector<bool> VB; typedef vector<VB> VVB;
typedef long double LD;

const LD EPS = 1e-7;

LL Mod (LL x, LL y){
	return x*x+y*y;
}

LL sq (LL x){ return  x*x;}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LL d, r;
	cin >> r >> d;
	int n;
	cin >> n;
	int ans = 0;
	if (d == 0){
		FOR (i, n){
			LL x, y, R;
			cin >> x >> y >> R;
			LL m = Mod(x, y);
			if (m <= sq(r - R)) ++ans;
		}
	}
	else FOR(i, n){
		LL x, y, R;
		cin >> x >> y >> R;
		LL m = Mod(x, y);
		if (m >= sq(d + R) and m <= sq(r - R) and d >= 2*R and r >= R) ++ans;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define FOR(i, n) for (int i=0; i<n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define DFOR(V,B,E,A) for (int V=B-(A<0); (A>0)==(V<E); V+=A)
#define OUTV(x) FOR(j,x.size()) cout<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define BLE cerr<<"BLE"<<endl;
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
using namespace std;
typedef long long int LL; typedef vector<LL> VLL;
typedef vector<int> VI; typedef vector<VI> VVI;
typedef pair<int, int> PII; typedef vector<PII> VPII;
typedef vector<bool> VB; typedef vector<VB> VVB;
typedef long double LD;

const LD EPS = 1e-7;

LD Mod (LD x, LD y){
	return sqrt(x*x+y*y);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LD d, r;
	cin >> r >> d;
	int n;
	cin >> n;
	int ans = 0;
	FOR(i, n){
		LD x, y, R;
		cin >> x >> y >> R;
		LD m = Mod(x, y);
		if (m - R >= d - EPS and R + m <= r + EPS) ++ans;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define FOR(i, n) for (int i=0; i<n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define DFOR(V,B,E,A) for (int V=B-(A<0); (A>0)==(V<E); V+=A)
#define OUTV(x) FOR(j,x.size()) cout<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define BLE cerr<<"BLE"<<endl;
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
using namespace std;
typedef long long int LL; typedef vector<LL> VLL;
typedef vector<int> VI; typedef vector<VI> VVI;
typedef pair<int, int> PII; typedef vector<PII> VPII;
typedef vector<bool> VB; typedef vector<VB> VVB;
typedef long double LD;

const LD EPS = 1e-7;

LD Mod (LD x, LD y){
	return sqrt(x*x+y*y);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LD d, r;
	cin >> r >> d;
	int n;
	cin >> n;
	int ans = 0;
	FOR(i, n){
		LD x, y, R;
		cin >> x >> y >> R;
		LD m = Mod(x, y);
		if (m - R >= r - d - EPS and R + m <= r + EPS) ++ans;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define FOR(i, n) for (int i=0; i<n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define DFOR(V,B,E,A) for (int V=B-(A<0); (A>0)==(V<E); V+=A)
#define OUTV(x) FOR(j,x.size()) cout<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define BLE cerr<<"BLE"<<endl;
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
using namespace std;
typedef long long int LL; typedef vector<LL> VLL;
typedef vector<int> VI; typedef vector<VI> VVI;
typedef pair<int, int> PII; typedef vector<PII> VPII;
typedef vector<bool> VB; typedef vector<VB> VVB;
typedef long double LD;

const LD EPS = 1e-7;

LL Mod (LL x, LL y){
	return x*x+y*y;
}

LL sq (LL x){ return  x*x;}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LL d, r;
	cin >> r >> d;
	int n;
	cin >> n;
	int ans = 0;
	FOR(i, n){
		LL x, y, R;
		cin >> x >> y >> R;
		LL m = Mod(x, y);
		if (m >= sq(d + R) and m <= sq(r - R) and d >= 2*R) ++ans;
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
#define FOR(i, n) for (int i=0; i<n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define DFOR(V,B,E,A) for (int V=B-(A<0); (A>0)==(V<E); V+=A)
#define OUTV(x) FOR(j,x.size()) cout<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define BLE cerr<<"BLE"<<endl;
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
using namespace std;
typedef long long int LL; typedef vector<LL> VLL;
typedef vector<int> VI; typedef vector<VI> VVI;
typedef pair<int, int> PII; typedef vector<PII> VPII;
typedef vector<bool> VB; typedef vector<VB> VVB;
typedef long double LD;

const LD EPS = 1e-7;

LD Mod (LD x, LD y){
	return sqrt(x*x+y*y);
}

LL sq (LL x){ return  x*x;}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LD d, r;
	cin >> r >> d;
	int n;
	cin >> n;
	int ans = 0;
	FOR(i, n){
		LD x, y, R;
		cin >> x >> y >> R;
		LD m = Mod(x, y);
		if (R == 0 and d == 0){
			if (m <= r + EPS) ++ans;
		}
		if (R != 0 and d == 0){
			if (m + R <= r + EPS) ++ans;
		}
		if (R == 0 and d != 0){
			if (m <= r + EPS and m >= d - EPS) ++ans;
		}
		if (R != 0 and d != 0){
			if (R >= m or R >= r) continue;
			if (m - R >= d - EPS and m + R <= r + EPS) ++ans;
		}
	}
	cout << ans << endl;
}


#include<iostream>
#include<math.h>
using namespace std;
main()
{
    int R,d,n;
    int cnt=0;
    int x,y,r;
    cin>>R>>d>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y>>r;
        if(x*x+y*y>=(r+d)*(r+d) and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
            cnt++;
        }
    }
    cout<<cnt;
}


#include<iostream>
#include<math.h>
using namespace std;
main()
{
    int R,d,n;
    int cnt=0;
    int x,y,r;
    cin>>R>>d>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y>>r;
        if(d and x*x+y*y>=(r+d)*(r+d) and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
//            cout<<i<<endl;
            cnt++;
        }
        if(d==0) while(1);
        if(d==0 and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
//            cout<<i<<endl;
            cnt++;
        }
    }
    cout<<cnt;
}
/**
5 0
1
0 0 5
**/


#include<iostream>
#include<math.h>
using namespace std;
main()
{
    int R,d,n;
    int cnt=0;
    int x,y,r;
    cin>>R>>d>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y>>r;
        if(r==0) continue;
        if(d and x*x+y*y>=(r+d)*(r+d) and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
//            cout<<i<<endl;
            cnt++;
        }
        if(d==0 and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
            cnt++;
        }
    }
    cout<<cnt;
}
/**
5 0
1
4 4 1
**/


#include<iostream>
#include<math.h>
using namespace std;
main()
{
    int R,d,n;
    int cnt=0;
    int x,y,r;
    cin>>R>>d>>n;
    d=R-d;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y>>r;
        if(d and x*x+y*y>=(r+d)*(r+d) and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
            cnt++;
        }
        if(d==0 and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
            cnt++;
        }
    }
    cout<<cnt;
}
/**
5 0
1
4 4 1
**/


#include<iostream>
#include<math.h>
using namespace std;
main()
{
    int R,d,n;
    int cnt=0;
    int x,y,r;
    cin>>R>>d>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y>>r;
        if(d and x*x+y*y>=(r+d)*(r+d) and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
//            cout<<i<<endl;
            cnt++;
        }
        if(d==0 and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
//            cout<<i<<endl;
            cnt++;
        }
    }
    cout<<cnt;
}
/**
5 0
1
0 0 5
**/


#include<iostream>
#include<math.h>
using namespace std;
main()
{
    int R,d,n;
    int cnt=0;
    int x,y,r;
    cin>>R>>d>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x>>y>>r;
        if(x*x+y*y<=R*R and x*x+y*y>=(r+d)*(r+d) and x*x+y*y<=(R-r)*(R-r) and r<=R)
        {
            cnt++;
        }
    }
    cout<<cnt;
}


#include <bits/stdc++.h>
#define pi pair<int,int>
#define EPS 1e-9
#define ll long long int
#define pii pair<long long,long long>
#define f(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0)

using namespace std;

ll r,d,n,xi,yi,ri,ans;
string s;

bool check1(ll rad, ll x, ll y)
{   ll p=(x*x+y*y);
    ll r=rad*rad;

    if ( p!=0 && r!=0 || p<r)
        return true;
    else
        return false;
}

bool check2(ll rad, ll x, ll y)
{
    if ( (x*x+y*y)<= rad*rad)
        return true;
    else
        return false;
}

int main()
{ fast;
 cin>>r>>d;
 cin>>n;

 f(i,1,n)
 {
 cin>>xi>>yi>>ri;

 if(!check1(r-d,xi+ri,yi) && !check1(r-d,xi-ri,yi) && !check1(r-d,xi,yi+ri) && !check1(r-d,xi,yi-ri) &&  !check1(r-d,xi,yi)
 && check2(r,xi+ri,yi)    && check2(r,xi-ri,yi)    && check2(r,xi,yi+ri)    && check2(r,xi,yi-ri) && check2(r,xi,yi) )
 {ans++;
 //cout<<i<<"\n";
 }

 }
 cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define pi pair<int,int>
#define EPS 1e-9
#define ll long long int
#define pii pair<long long,long long>
#define f(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0)

using namespace std;

ll r,d,n,xi,yi,ri,ans;
string s;

bool check1(ll rad, ll x, ll y)
{
    if ( (x*x+y*y)< rad*rad || x==0 && y==0 && rad!=0)
        return true;
    else
        return false;
}

bool check2(ll rad, ll x, ll y)
{
    if ( (x*x+y*y)<= rad*rad)
        return true;
    else
        return false;
}

int main()
{ fast;
 cin>>r>>d;
 cin>>n;

 f(i,1,n)
 {
 cin>>xi>>yi>>ri;

 if(!check1(r-d,xi+ri,yi) && !check1(r-d,xi-ri,yi) && !check1(r-d,xi,yi+ri) && !check1(r-d,xi,yi-ri) &&  !check1(r-d,xi,yi)
 && check2(r,xi+ri,yi)    && check2(r,xi-ri,yi)    && check2(r,xi,yi+ri)    && check2(r,xi,yi-ri) && check2(r,xi,yi) )
 {ans++;
 //cout<<i<<"\n";
 }

 }
 cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define pi pair<int,int>
#define EPS 1e-9
#define ll long long int
#define pii pair<long long,long long>
#define f(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0)

using namespace std;

ll r,d,n,xi,yi,ri,ans;

string s;

int main()
{ fast;
 cin>>r>>d;
 cin>>n;
 f(i,1,n)
 {
 cin>>xi>>yi>>ri;
 if(yi-ri>=r-d && yi+ri<=r && xi+ri<=r && xi-ri>=-r|| yi+ri<=d-r && yi-ri>=-r && xi+ri<=r && xi-ri>=-r|| xi-ri>=r-d&&xi+ri<=r && yi-ri>=-r && yi+ri<=r|| xi+ri<=d-r && xi-ri>=-r&& yi-ri>=-r && yi+ri<=r)
 ans++;

 }
 cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define pi pair<int,int>
#define EPS 1e-9
#define ll long long int
#define pii pair<long long,long long>
#define f(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0)

using namespace std;

ll r,d,n,xi,yi,ri,ans;

string s;
bool check1(ll rad, ll x, ll y)
{
    if ( (x*x+y*y)< rad*rad)
        return true;
    else
        return false;
}
bool check2(ll rad, ll x, ll y)
{
    if ( (x*x+y*y)<= rad*rad)
        return true;
    else
        return false;
}

int main()
{ fast;
 cin>>r>>d;
 cin>>n;

 f(i,1,n)
 {
 cin>>xi>>yi>>ri;

 if(!check1(r-d,xi+ri,yi) && !check1(r-d,xi-ri,yi) && !check1(r-d,xi,yi+ri) && !check1(r-d,xi,yi-ri) &&  !check1(r-d,xi,yi)
 && check2(r,xi+ri,yi)    && check2(r,xi-ri,yi)    && check2(r,xi,yi+ri)    && check2(r,xi,yi-ri) && check2(r,xi,yi) )
 {ans++;
 //cout<<i<<"\n";
 }

 }
 cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define pi pair<int,int>
#define EPS 1e-9
#define ll long long int
#define pii pair<long long,long long>
#define f(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0)

using namespace std;

ll r,d,n,xi,yi,ri,ans;
string s;

bool check1(ll rad, ll x, ll y)
{   ll p=(x*x+y*y);
    ll r=rad*rad;

    if (p<r || p==0 && r>0 )
        return true;
    else
        return false;
}

bool check2(ll rad, ll x, ll y)
{
    if ( (x*x+y*y)<= rad*rad)
        return true;
    else
        return false;
}

int main()
{ fast;
 cin>>r>>d;
 cin>>n;

 f(i,1,n)
 {
 cin>>xi>>yi>>ri;

 if(!check1(r-d,xi+ri,yi) && !check1(r-d,xi-ri,yi) && !check1(r-d,xi,yi+ri) && !check1(r-d,xi,yi-ri) &&  !check1(r-d,xi,yi)
 && check2(r,xi+ri,yi)    && check2(r,xi-ri,yi)    && check2(r,xi,yi+ri)    && check2(r,xi,yi-ri) && check2(r,xi,yi) )
 {ans++;
 //cout<<i<<"\n";
 }

 }
 cout<<ans;

return 0;
}


#include <bits/stdc++.h>
#define pi pair<int,int>
#define EPS 1e-9
#define ll long long int
#define pii pair<long long,long long>
#define f(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define rf(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false);cin.tie(0)

using namespace std;

long double l,ri,xi,yi,r,d;
ll n;
int main()
{ fast;
 cin>>r>>d;
 cin>>n;
 ll ans=0;
 f(i,1,n)
 {
 cin>>xi>>yi>>ri;
 l=sqrt(xi*xi+yi*yi);
 if(l-ri>=r-d && l+ri<=r)
 ans++;
 }
 cout<<ans;

return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int r, d;
	cin >> r >> d;
	int n;
	cin >> n;
	int saus = 0;
	while(n--)
	{
		int x, y, ri;
		cin >> x >> y >> ri;
		int di = sqrt((x * x) + (y * y));
		if(r >= (di + ri))
		{
			if((di + ri) > (r-d + ri))
			{
				//cout << x << " " << y << " " << ri << endl;
				//cout << di + ri << endl;
				saus ++;
			}
		}
	}
	cout << saus << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int r, d;
	cin >> r >> d;
	int n;
	cin >> n;
	int saus = 0;
	while(n--)
	{
		int x, y, ri;
		cin >> x >> y >> ri;
		float di = sqrt((x * x) + (y * y));
		if(di-ri >= (r-d) && di+ri <= r)
		{
			//cout << x << " " << y << " " << ri << endl;
			//cout << di + ri << endl;
			saus ++;
		}
	}
	cout << saus << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int r, d;
	cin >> r >> d;
	int n;
	cin >> n;
	int saus = 0;
	while(n--)
	{
		int x, y, ri;
		cin >> x >> y >> ri;
		int di = sqrt((x * x) + (y * y));
		if(r >= (di + ri))
		{
			if(di >= (r-d) + (ri))
			{
				//cout << x << " " << y << " " << ri << endl;
				//cout << di + ri << endl;
				saus ++;
			}
		}
	}
	cout << saus << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int r, d;
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> r >> d;
	int n;
	cin >> n;
	int saus = 0;
	while(n--)
	{
		int x, y, ri;
		cin >> x >> y >> ri;
		float di = sqrt((x * x) + (y * y));
		if(di-ri >= (r-d) && di+ri <= r)
		{
			//cout << x << " " << y << " " << ri << endl;
			//cout << di + ri << endl;
			saus ++;
		}
	}
	cout << saus << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int r, d;
	cin >> r >> d;
	int n;
	cin >> n;
	int saus = 0;
	while(n--)
	{
		int x, y, ri;
		cin >> x >> y >> ri;
		int di = sqrt((x * x) + (y * y));
		if(di-ri >= (r-d) && di+ri <= r)
		{
			//cout << x << " " << y << " " << ri << endl;
			//cout << di + ri << endl;
			saus ++;
		}
	}
	cout << saus << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int r, d;
	cin >> r >> d;
	int n;
	cin >> n;
	int saus = 0;
	while(n--)
	{
		int x, y, ri;
		cin >> x >> y >> ri;
		int di = sqrt((x * x) + (y * y));
		if(r > (di + ri))
		{
			if((di + ri) > (r-d + ri))
			{
				//cout << x << " " << y << " " << ri << endl;
				//cout << di + ri << endl;
				saus ++;
			}
		}
	}
	cout << saus << endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    double r,d,dif;
    int cnt=0;
    cin>>d>>r;
    dif=d-r;
    int n;
    cin>>n;
    while(n--)
    {
        double x,y,r1;
        cin>>x>>y>>r1;
        double dis=sqrt(x*x+y*y);
//        cout<<dis+<<endl;
        if(2*r1<=dif&&dis-r-r1>=0&&0<=d-r1-dis)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;

    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,dif;
    int cnt=0;
    cin>>r>>d;
    dif=r-d;
    int n;
    cin>>n;
    int i=1;
    while(n--)
    {
        int x,y,r1;
        cin>>x>>y>>r1;
        int dis=x*x+y*y;
//        cout<<dis+<<endl;
        if(sqrt(dis)+r1<=r&&sqrt(dis)-r1>=dif)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;
//     cout<<"Case"<<i<<" "<<cnt<<endl;
     i++;
    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,dif,cnt=0;
    cin>>d>>r;
    dif=d-r;
    int n;
    cin>>n;
    while(n--)
    {
        int x,y,r1;
        cin>>x>>y>>r1;
        double dis=sqrt(x*x+y*y);
//        cout<<dis<<endl;
        if(2*r1<=dif&&dis>=r+(double)r1&&dis<=d-(double)r1)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;

    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,dif,cnt=0;
    cin>>d>>r;
    dif=d-r;
    int n;
    cin>>n;
    while(n--)
    {
        int x,y,r1;
        cin>>x>>y>>r1;
        double dis=sqrt(x*x+y*y);
//        cout<<dis<<endl;
        if(2*r1<=dif&&dis-r-r1>=0&&0<=d-r1-dis)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;

    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,dif,cnt=0;
    cin>>d>>r;
    dif=d-r;
    int n;
    cin>>n;
    while(n--)
    {
        int x,y,r1;
        cin>>x>>y>>r1;
        double dis=sqrt(x*x+y*y);
//        cout<<dis<<endl;
        if(2*r1<=dif&&dis>=r+r1&&dis<=d-r1)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;

    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    double r,d,dif;
    int cnt=0;
    cin>>d>>r;
    dif=d-r;
    int n;
    cin>>n;
    while(n--)
    {
        double x,y,r1;
        cin>>x>>y>>r1;
        double dis=sqrt(x*x+y*y);
//        cout<<dis+<<endl;
        if(dis-r-r1>=0&&0<=d-r1-dis)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;

    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    double r,d,dif;
    int cnt=0;
    cin>>d>>r;
    dif=d-r;
    int n;
    cin>>n;
    while(n--)
    {
        double x,y,r1;
        cin>>x>>y>>r1;
        double dis=sqrt(x*x+y*y);
//        cout<<dis+<<endl;
        if(dis>=r1+r&&d-r1>=dis)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;

    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int r,d,dif;
    int cnt=0;
    cin>>r>>d;
    dif=r-d;
    int n;
    cin>>n;
    int i=1;
    while(n--)
    {
        int x,y,r1;
        cin>>x>>y>>r1;
        int dis=x*x+y*y;
//        cout<<dis+<<endl;
        if(dis>=dif*dif&&r*r>=dis&&d>=2*r1&&(abs(x)+r1)<=r&&(abs(x)+r1)>=dif&&abs(y)+r1<=r&&(abs(y)+r1)>=dif)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;
//     cout<<"Case"<<i<<" "<<cnt<<endl;
//     i++;
    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    double r,d,dif;
    int cnt=0;
    cin>>r>>d;
    dif=r-d;
    int n;
    cin>>n;
    while(n--)
    {
        int x,y,r1;
        cin>>x>>y>>r1;
        int dis=(x*x+y*y);
//        cout<<dis+<<endl;
        if(dis>=dif*dif&&r*r>=dis&&d<=2*r1)
            cnt++;
//            cout<<"cnt: "<<cnt<<endl;

    }
    cout<<cnt;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll r,d,n,xi,yi,ri,x1,x2,y1,y2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        y1=yi+ri;
        y2=yi-ri;
        x1=xi+ri;
        x2=xi-ri;
        if((y1>=d && y1<=r && y2>=d && y2<=r))
        {
            if(x1>=-r && x1<=r & x2>=-r && x2<=r)
                c++;
        }
        else if(x1>=d && x1<=r && x2>=d && x2<=r)
        {
            if(y1>=-r && y1<=r & y2>=-r && y2<=r)
                c++;
        }

    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll r,d,n,xi,yi,ri,dd,d1,d2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        dd=sqrt(xi*xi+yi*yi);
        d1=dd-ri;
        d2=dd+ri;
        if(d1>=d && d1<=r && d2>=d && d2<=r)
        c++;
    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll r,d,n,xi,yi,ri,x1,x2,y1,y2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        y1=yi+ri;
        y2=yi-ri;
        x1=xi+ri;
        x2=xi-ri;
        if((y1>=d && y1<=r && y2>=d && y2<=r)|| (abs(y1)>=d && abs(y1)<=r && abs(y2)>=d && abs(y2)<=r))
        {
            if(x1>=-r && x1<=r && x2>=-r && x2<=r)
                c++;
        }
        else if((x1>=d && x1<=r && x2>=d && x2<=r)|| (abs(x1)>=-d && abs(x1)<=-r && abs(x2)>=-d && abs(x2)<=-r))
        {
            if(y1>=-r && y1<=r && y2>=-r && y2<=r)
                c++;
        }

    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long double r,d,n,xi,yi,ri,dd,d1,d2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        dd=1.0*sqrt(1.0*(xi*xi+yi*yi));
        d1=dd-ri;
        d2=dd+ri;
        if(d1>=d && d1<=r && d2>=d && d2<=r)
        c++;
    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll r,d,n,xi,yi,ri,x1,x2,y1,y2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        y1=yi+ri*ri;
        y2=yi-ri*ri;
        x1=xi+ri*ri;
        x2=xi-ri*ri;
        if((y1>=d && y1<=r && y2>=d && y2<=r) || (x1>=d && x1<=r && x2>=d && x2<=r))
            c++;
    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
ll solve(ll a,ll b,ll r,ll d)
{
    if((a*a+b*b)<=r*r && (a*a+b*b)>=d*d)
        return 1;
    return 0;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll r,d,n,xi,yi,ri,x1,x2,y1,y2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        y1=yi+ri;
        y2=yi-ri;
        x1=xi+ri;
        x2=xi-ri;
        if(solve(xi,y1,r,d)==1 && solve(xi,y2,r,d)==1 && solve(x1,yi,r,d)==1 && solve(x2,yi,r,d)==1)
            c++;
    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double r,d,n,xi,yi,ri,dd,d1,d2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        dd=1.0*sqrt(1.0*(xi*xi+yi*yi));
        d1=dd-ri;
        d2=dd+ri;
        if(d1>=d && d1<=r && d2>=d && d2<=r)
        c++;
    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
double r,d,n,xi,yi,ri,dd,d1,d2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        dd=1.0*sqrt(1.0*(xi*xi+yi*yi));
        d1=dd-ri;
        d2=dd+ri;
        if(d1>=r-d && d1<=r && d2>=r-d && d2<=r)
        c++;
    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll r,d,n,xi,yi,ri,x1,x2,y1,y2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        y1=yi+ri;
        y2=yi-ri;
        x1=xi+ri;
        x2=xi-ri;
        if((y1>=d && y1<=r && y2>=d && y2<=r)|| (y1<=-d && y1>=-r && y2<=-d && y2>=-r))
        {
            if(x1>=-r && x1<=r && x2>=-r && x2<=r)
                c++;
        }
        else if((x1>=d && x1<=r && x2>=d && x2<=r)|| (x1<=-d && x1>=-r && x2<=-d && x2>=-r))
        {
            if(y1>=-r && y1<=r && y2>=-r && y2<=r)
                c++;
        }

    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define po pop_back
#define mp make_pair
#define FOR(i,a,b) for(long long int i=a;i<=b;i++)
#define NFOR(i,a,b) for(long long int i=a;i>=b;i--)
ll MOD=1000000007;
/*ll fast_exp(ll base, ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return res%MOD;}
bool cmp(const pair<ll,ll>&p1,const pair<ll,ll>&p2)
{
    return p1.first < p2.first;
}
bool prime[1000001];void seive(){ll n=1000000;FOR(i,0,n)prime[i]=true;for(ll i=2;i*i<=n;i++){if(prime[i]){for(ll j=i*2;j<=n;j+=i)prime[j]=false;}}prime[0]=prim[1]=false;}*/
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long double r,d,n,xi,yi,ri,dd,d1,d2,c=0;
    cin>>r>>d;
    cin>>n;
    FOR(i,1,n)
    {
        cin>>xi>>yi>>ri;
        dd=1.0*sqrt(1.0*(xi*xi+yi*yi));
        d1=dd-ri;
        d2=dd+ri;
        if(d1>=d && d1<=r && d2>=d && d2<=r && d1!=d2)
        c++;
    }
    cout<<c;

return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,b,a) for(int i=b;i>=a;i--)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rfll(i,b,a) for(ll i=b;i>=a;i--)
#define endl "\n"
#define pb push_back
#define speed 	ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() ll t; cin>>t; while(t--)
#define gcd(a,b) __gcd(a,b)
//constants
const ll mod = 1e9+7;
const ll MOD =1e18+7;
//functions
ll modPow(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll MODPow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll nCr(ll n,ll k) {ll res = 1;if (k > n - k) k = n - k; for (ll i = 0; i < k; ++i){ res = (res*(n - i))%mod;res = (res*modPow(i + 1,mod-2))%mod;} return res;}
void Sieve(ll n) {bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2;p*p<=n; p++) if (prime[p] == true) for (ll i=p*2; i<=n; i += p) prime[i] = false;}

int main()
{
	float R,d;
	cin>>R>>d;

	int n,c=0;
	cin>>n;
	fl(i,0,n)
	{
		float x,y,r;
		cin>>x>>y>>r;
		float size=sqrt(x*x+y*y);

		if(d==0)
		{
			if(size+r<=R)
				c++;
		}
		else
		{
			if(size<=R&&size>=d&&size+r<=R&&size-r>=0&&size-r>=d)
				c++;
		}
	}
	cout<<c;

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,b,a) for(int i=b;i>=a;i--)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rfll(i,b,a) for(ll i=b;i>=a;i--)
#define endl "\n"
#define pb push_back
#define speed 	ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() ll t; cin>>t; while(t--)
#define gcd(a,b) __gcd(a,b)
//constants
const ll mod = 1e9+7;
const ll MOD =1e18+7;
//functions
ll modPow(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll MODPow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll nCr(ll n,ll k) {ll res = 1;if (k > n - k) k = n - k; for (ll i = 0; i < k; ++i){ res = (res*(n - i))%mod;res = (res*modPow(i + 1,mod-2))%mod;} return res;}
void Sieve(ll n) {bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2;p*p<=n; p++) if (prime[p] == true) for (ll i=p*2; i<=n; i += p) prime[i] = false;}

int main()
{
	float R,d;
	cin>>R>>d;

	int n,c=0;
	cin>>n;

	fl(i,0,n)
	{
		float x,y,r;
		cin>>x>>y>>r;
		float size=sqrt(x*x+y*y);
		if(size+r<=R&&abs(size-r)>=d)
			c++;
	}
	cout<<c;

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,b,a) for(int i=b;i>=a;i--)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rfll(i,b,a) for(ll i=b;i>=a;i--)
#define endl "\n"
#define pb push_back
#define speed 	ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() ll t; cin>>t; while(t--)
#define gcd(a,b) __gcd(a,b)
//constants
const ll mod = 1e9+7;
const ll MOD =1e18+7;
//functions
ll modPow(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll MODPow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll nCr(ll n,ll k) {ll res = 1;if (k > n - k) k = n - k; for (ll i = 0; i < k; ++i){ res = (res*(n - i))%mod;res = (res*modPow(i + 1,mod-2))%mod;} return res;}
void Sieve(ll n) {bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2;p*p<=n; p++) if (prime[p] == true) for (ll i=p*2; i<=n; i += p) prime[i] = false;}

int main()
{
	float R,d;
	cin>>R>>d;

	int n,c=0;
	cin>>n;

	fl(i,0,n)
	{
		float x,y,r;
		cin>>x>>y>>r;
		float size=sqrt(x*x+y*y);
		if(size<=R&&size>=d&&size+r<=R&&abs(size-r)>=d)
			c++;
	}
	cout<<c;

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,b,a) for(int i=b;i>=a;i--)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rfll(i,b,a) for(ll i=b;i>=a;i--)
#define endl "\n"
#define pb push_back
#define speed 	ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() ll t; cin>>t; while(t--)
#define gcd(a,b) __gcd(a,b)
//constants
const ll mod = 1e9+7;
const ll MOD =1e18+7;
//functions
ll modPow(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll MODPow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll nCr(ll n,ll k) {ll res = 1;if (k > n - k) k = n - k; for (ll i = 0; i < k; ++i){ res = (res*(n - i))%mod;res = (res*modPow(i + 1,mod-2))%mod;} return res;}
void Sieve(ll n) {bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2;p*p<=n; p++) if (prime[p] == true) for (ll i=p*2; i<=n; i += p) prime[i] = false;}

int main()
{
	float R,d;
	cin>>R>>d;

	int n,c=0;
	cin>>n;

	fl(i,0,n)
	{
		float x,y,r;
		cin>>x>>y>>r;
		float size=sqrt(x*x+y*y);
		if(size+r<=R&&size-r>=d)
			c++;
	}
	cout<<c;

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,b,a) for(int i=b;i>=a;i--)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rfll(i,b,a) for(ll i=b;i>=a;i--)
#define endl "\n"
#define pb push_back
#define speed 	ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() ll t; cin>>t; while(t--)
#define gcd(a,b) __gcd(a,b)
//constants
const ll mod = 1e9+7;
const ll MOD =1e18+7;
//functions
ll modPow(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll MODPow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll nCr(ll n,ll k) {ll res = 1;if (k > n - k) k = n - k; for (ll i = 0; i < k; ++i){ res = (res*(n - i))%mod;res = (res*modPow(i + 1,mod-2))%mod;} return res;}
void Sieve(ll n) {bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2;p*p<=n; p++) if (prime[p] == true) for (ll i=p*2; i<=n; i += p) prime[i] = false;}

int main()
{
	float R,d;
	cin>>R>>d;

	int n,c=0;
	cin>>n;
	fl(i,0,n)
	{
		float x,y,r;
		cin>>x>>y>>r;
		float size=sqrt(x*x+y*y);
		if(size<=R&&size>=d&&size+r<=R&&size-r>=0&&size-r>=d)
			c++;
	}
	cout<<c;

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,b,a) for(int i=b;i>=a;i--)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rfll(i,b,a) for(ll i=b;i>=a;i--)
#define endl "\n"
#define pb push_back
#define speed 	ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() ll t; cin>>t; while(t--)
#define gcd(a,b) __gcd(a,b)
//constants
const ll mod = 1e9+7;
const ll MOD =1e18+7;
//functions
ll modPow(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll MODPow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll nCr(ll n,ll k) {ll res = 1;if (k > n - k) k = n - k; for (ll i = 0; i < k; ++i){ res = (res*(n - i))%mod;res = (res*modPow(i + 1,mod-2))%mod;} return res;}
void Sieve(ll n) {bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2;p*p<=n; p++) if (prime[p] == true) for (ll i=p*2; i<=n; i += p) prime[i] = false;}

int main()
{
	float R,d;
	cin>>R>>d;

	int n,c=0;
	cin>>n;

	fl(i,0,n)
	{
		int x,y,r;
		cin>>x>>y>>r;
		float size=sqrt(x*x+y*y);
		if(size+r<=R&&size-r>=d)
			c++;
	}
	cout<<c;

}


#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define fl(i,a,b) for(int i=a;i<b;i++)
#define rfl(i,b,a) for(int i=b;i>=a;i--)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rfll(i,b,a) for(ll i=b;i>=a;i--)
#define endl "\n"
#define pb push_back
#define speed 	ios::sync_with_stdio(false), cin.tie(0) , cout.tie(0)
#define cases() ll t; cin>>t; while(t--)
#define gcd(a,b) __gcd(a,b)
//constants
const ll mod = 1e9+7;
const ll MOD =1e18+7;
//functions
ll modPow(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll MODPow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll nCr(ll n,ll k) {ll res = 1;if (k > n - k) k = n - k; for (ll i = 0; i < k; ++i){ res = (res*(n - i))%mod;res = (res*modPow(i + 1,mod-2))%mod;} return res;}
void Sieve(ll n) {bool prime[n+1]; memset(prime, true, sizeof(prime)); for (ll p=2;p*p<=n; p++) if (prime[p] == true) for (ll i=p*2; i<=n; i += p) prime[i] = false;}

int main()
{
	float R,d;
	cin>>R>>d;

	int n,c=0;
	cin>>n;
	fl(i,0,n)
	{
		float x,y,r;
		cin>>x>>y>>r;
		float size=sqrt(x*x+y*y);

		if(size+r<=R&&size-r>=R-d)
			c++;
	}
	cout<<c;
}


#include <bits/stdc++.h>

using namespace std;
long long r,d,ans,x,y,r2,n;
double g;

int main()
{
cin>>r>>d;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>x>>y>>r2;
    g=sqrt(x*x*1.0+y*y*1.0);
    if(g*1.0+r2*1.0<=r*1.0&&g*1.0-r2*1.0>=r*1.0-d*1.0&&r2!=0)
        ans++;
}
if(d==0)
    cout<<"0";
else
cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long r,d,ans,x,y,r2,n;
double g;

int main()
{
cin>>r>>d;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>x>>y>>r2;
    g=sqrt(x*x*1.0+y*y*1.0);
    if(g*1.0+r2*1.0<=r*1.0&&g*1.0-r2*1.0>=r*1.0-d*1.0)
        ans++;
}
if(d==0)
    cout<<"0";
else
cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long r,d,ans,x,y,r2,g,n;

int main()
{
cin>>r>>d;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>x>>y>>r2;
    g=sqrt(x*x+y*y);
    if(g+r2<=r&&g-r2>=r-d)
        ans++;
}
cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long r,d,ans,x,y,r2,n;
double g;

int main()
{
cin>>r>>d;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>x>>y>>r2;
    g=sqrt(x*x*1.0+y*y*1.0);
    if(g+r2<=r&&g-r2>=r-d&&r2!=0)
        ans++;
}
cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long r,d,ans,x,y,r2,n;
double g;

int main()
{
cin>>r>>d;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>x>>y>>r2;
    g=sqrt(x*x*1.0+y*y*1.0);
    if(g*1.0+r2*1.0<=r*1.0&&g*1.0-r2*1.0>=r*1.0-d*1.0&&r2!=0)
        ans++;
}
cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long r,d,ans,x,y,r2,g,n;

int main()
{
cin>>r>>d;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>x>>y>>r2;
    g=sqrt(x*x+y*y);
    if(g+r2<=r&&g-r2>=r-d&&r2!=0)
        ans++;
}
cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
long long r,d,ans,x,y,r2,n;
double g;

int main()
{
cin>>r>>d;
cin>>n;
for(int i=0;i<n;i++)
{
    cin>>x>>y>>r2;
    g=sqrt(x*x*1.0+y*y*1.0);
    if(g*1.0+r2*1.0<=r*1.0&&g*1.0-r2*1.0>=r*1.0-d*1.0)
        ans++;
}

cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r,d;
    cin>>r>>d;
    int n;
    cin>>n;
    int c=0;
    while(n--){
        int x,y,rs;
        cin>>x>>y>>rs;
        double maxy=sqrt(r*r-x*x),miny=sqrt((r-d)*(r-d)-x*x);
        double maxx=sqrt(r*r-y*y),minx=sqrt((r-d)*(r-d)-y*y);
        if(abs(y)+rs<=maxy&&abs(x)+rs<=maxx){
            if(abs(y)>(r-d)){c++;continue;}
            else if (abs(x)-rs>=minx){c++;continue;}
            if(abs(x)>(r-d)){c++;continue;}
            else if(abs(y)-rs>=miny){c++;continue;}

        }

    }
    cout<<c;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r,d;
    cin>>r>>d;
    int n;
    cin>>n;
    int c=0;
    while(n--){
        int x,y,rs;
        cin>>x>>y>>rs;
        if()
        double maxy=sqrt(r*r-x*x),miny=sqrt((r-d)*(r-d)-x*x);
        double maxx=sqrt(r*r-y*y),minx=sqrt((r-d)*(r-d)-y*y);
        if(abs(y)+rs<=maxy&&abs(x)+rs<=maxx){
            if(abs(y)>4&&abs(x)>5){c++;continue;}
            else if (abs(x)-rs>=minx&&abs(y)-rs>=miny){c++;continue;}

        }

    }
    cout<<c;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r,d;
    cin>>r>>d;
    int n;
    cin>>n;
    int c=0;
    while(n--){
        int x,y,rs;
        cin>>x>>y>>rs;
        double maxy=sqrt(r*r-x*x),miny=sqrt((r-d)*(r-d)-x*x);
        double maxx=sqrt(r*r-y*y),minx=sqrt((r-d)*(r-d)-y*y);
        if(abs(y)+rs<=maxy&&abs(x)+rs<=maxx){
            if(abs(y)-rs>(r-d)){c++;continue;}
            else if (abs(x)-rs>=minx){c++;continue;}
            if(abs(x)-rs>(r-d)){c++;continue;}
            else if(abs(y)-rs>=miny){c++;continue;}

        }

    }
    cout<<c;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r,d;
    cin>>r>>d;
    int n;
    cin>>n;
    int c=0;
    while(n--){
        int x,y,rs;
        cin>>x>>y>>rs;
        double maxy=sqrt(r*r-x*x),miny=sqrt((r-d)*(r-d)-x*x);
        double maxx=sqrt(r*r-y*y),minx=sqrt((r-d)*(r-d)-y*y);
        if(abs(y)+rs<=maxy&&abs(x)+rs<=maxx){
            if(abs(y)>4){c++;continue;}
            else if (abs(x)-rs>=minx){c++;continue;}
            if(abs(x)>5){c++;continue;}
            else if(abs(y)-rs>=miny){c++;continue;}

        }

    }
    cout<<c;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r,d;
    cin>>r>>d;
    int n;
    cin>>n;
    int c=0;
    while(n--){
        int x,y,rs;
        cin>>x>>y>>rs;
        if(rs==0)continue;
        double maxy=sqrt(r*r-x*x),miny=sqrt((r-d)*(r-d)-x*x);
        double maxx=sqrt(r*r-y*y),minx=sqrt((r-d)*(r-d)-y*y);
        if(abs(y)+rs<=maxy&&abs(x)+rs<=maxx){
            if(abs(y)>4){c++;continue;}
            else if (abs(x)-rs>=minx){c++;continue;}
            if(abs(x)>5){c++;continue;}
            else if(abs(y)-rs>=miny){c++;continue;}

        }

    }
    cout<<c;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main(){
    int r,d;
    cin>>r>>d;
    int n;
    cin>>n;
    int c=0;
    while(n--){
        int x,y,rs;
        cin>>x>>y>>rs;
        double maxy=sqrt(r*r-x*x),miny=sqrt((r-d)*(r-d)-x*x);
        double maxx=sqrt(r*r-y*y),minx=sqrt((r-d)*(r-d)-y*y);
        if(abs(y)+rs<=maxy&&abs(x)+rs<=maxx){
            if(abs(y)>4){c++;continue;}
            else if (abs(x)-rs>=minx){c++;continue;}
            if(x>5){c++;continue;}
            else if(abs(y)-rs>=miny){c++;continue;}

        }

    }
    cout<<c;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int,int>
#define all(x) x.begin(),x.end()
#define lp(i,n) for(int i =0;i<n;i++)
#define mem(a,v) memset(a,v,sizeof(a))
#define X real()
#define Y imag()
#define angle(a) (atan2(a.Y , a.X))
#define vec(a,b) ((b)-(a))
//#define length(a) (hypot(a.Y , a.X))
#define normalize(a) (a)/length(a)
#define dotP(a,b) ((conj(a)*b).X)
#define crossP(a,b) ((conj(a)*b).Y)
#define same(p1,p2) (dotP(vec(p1,p2),vec(p1,p2))<EPS)
#define lengthSqr(a)   dotP(a,a)
#define rotate0(p,ang) ((p)*exp(point(0,ang)))
#define rotateA(p,ang,about) (rotate0(vec(about,p),ang)+about)
#define reflect0(v,m) conj(v/m)*m
const double PI = acos(-1.0);
const double EPS = (1e-10);
typedef long long int ll;
typedef complex<double> point;
map<ll,ll>nm;
int main(){
	std::ios_base::sync_with_stdio(false);
	 //freopen("input.txt", "rt", stdin);
	// freopen("output.txt", "wt", stdout);
    double r,d;
    cin>>r>>d;
    int n;
    cin>>n;
    int cnt=0;
    while(n--){
        double x,y,rad;
        cin>>x>>y>>rad;
        x = abs(x);
        y=abs(y);
        double dis = sqrt(x*x+y*y);
        if(dis-r+d >= rad && r-dis>=rad)cnt++;
    }
    cout<<cnt;
return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P pair<ll,ll>
vector<P>vp;
vector<ll>v;
set<ll>st;
ll ara[500005];
map<ll,ll>mp;
ll Set(ll N,ll pos)
{
    return N=N | (1LL<<pos);
}
ll reset(ll N,ll pos)
{
    return N= N & ~(1LL<<pos);
}
bool check(ll N,ll pos)
{
    return (bool)(N & (1LL<<pos));
}
vector<ll>e,o;
int main()
{
    fast
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    ll n,i,j,p,R,d,x,y,r;
    cin>>R>>d;
    cin>>n;
    ll cnt=0;
    for(i=0;i<n;i++)
    {
        cin>>x>>y>>r;

       p=hypot(x,y);
       if(p+r>R)
        continue;
        if(p-r<(R-d))
            continue;
       cnt++;

    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P pair<ll,ll>
vector<P>vp;
vector<ll>v;
set<ll>st;
ll ara[500005];
map<ll,ll>mp;
ll Set(ll N,ll pos)
{
    return N=N | (1LL<<pos);
}
ll reset(ll N,ll pos)
{
    return N= N & ~(1LL<<pos);
}
bool check(ll N,ll pos)
{
    return (bool)(N & (1LL<<pos));
}
vector<ll>e,o;
int main()
{
    fast
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    double n,i,j,p,R,d,x,y,r;
    cin>>R>>d;
    cin>>n;
    ll cnt=0;
    for(i=0;i<n;i++)
    {
        cin>>x>>y>>r;

       p=hypot(x,y);
       if((p+r)<=R&&(p-r)>=(R-d))
            cnt++;

    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P pair<ll,ll>
vector<P>vp;
vector<ll>v;
set<ll>st;
ll ara[500005];
map<ll,ll>mp;
ll Set(ll N,ll pos)
{
    return N=N | (1LL<<pos);
}
ll reset(ll N,ll pos)
{
    return N= N & ~(1LL<<pos);
}
bool check(ll N,ll pos)
{
    return (bool)(N & (1LL<<pos));
}
vector<ll>e,o;
int main()
{
    fast
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    ll n,i,j,p,R,d,x,y,r;
    cin>>R>>d;
    cin>>n;
    ll cnt=0;
    for(i=0;i<n;i++)
    {
        cin>>x>>y>>r;
        if(d==0)
            continue;
      else if(x<(R-d)&&y<(R-d))
        continue;
       else if(x>=R||y>=R)
        continue;
       else if((2*r)>(R-d))
        continue;
       else{
        cnt++;
       // cout<<"**"<<i<<endl;
       }

    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P pair<ll,ll>
vector<P>vp;
vector<ll>v;
set<ll>st;
ll ara[500005];
map<ll,ll>mp;
ll Set(ll N,ll pos)
{
    return N=N | (1LL<<pos);
}
ll reset(ll N,ll pos)
{
    return N= N & ~(1LL<<pos);
}
bool check(ll N,ll pos)
{
    return (bool)(N & (1LL<<pos));
}
vector<ll>e,o;
int main()
{
    fast
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    ll n,i,j,p,R,d,x,y,r;
    cin>>R>>d;
    cin>>n;
    ll cnt=0;
    for(i=0;i<n;i++)
    {
        cin>>x>>y>>r;
        ll m=(x+y);
        if((m>=(R-d)&&m<=R)&&(2*r)<=(R-d)){
            cnt++;
           // cout<<"****"<<i<<endl;;
        }

    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P pair<ll,ll>
vector<P>vp;
vector<ll>v;
set<ll>st;
ll ara[500005];
map<ll,ll>mp;
ll Set(ll N,ll pos)
{
    return N=N | (1LL<<pos);
}
ll reset(ll N,ll pos)
{
    return N= N & ~(1LL<<pos);
}
bool check(ll N,ll pos)
{
    return (bool)(N & (1LL<<pos));
}
vector<ll>e,o;
int main()
{
    fast
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    ll n,i,j,p,R,d,x,y,r;
    cin>>R>>d;
    cin>>n;
    ll cnt=0;
    for(i=0;i<n;i++)
    {
        cin>>x>>y>>r;

       p=hypot(x,y);
       if(p+r>R||p-r<(R-d))
        continue;
       cnt++;

    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P pair<ll,ll>
vector<P>vp;
vector<ll>v;
set<ll>st;
ll ara[500005];
map<ll,ll>mp;
ll Set(ll N,ll pos)
{
    return N=N | (1LL<<pos);
}
ll reset(ll N,ll pos)
{
    return N= N & ~(1LL<<pos);
}
bool check(ll N,ll pos)
{
    return (bool)(N & (1LL<<pos));
}
vector<ll>e,o;
int main()
{
    fast
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    ll n,i,j,p,R,d,x,y,r;
    cin>>R>>d;
    cin>>n;
    ll cnt=0;
    for(i=0;i<n;i++)
    {
        cin>>x>>y>>r;

       if(x<(R-d)&&y<(R-d))
        continue;
       else if(x>R||y>R)
        continue;
        else if(((x==R&&y<R)&&(r>0))||(y==R&&x<R)&&(r>0))
            continue;
       else if((2*r)>(R-d))
        continue;
       else{
        cnt++;
       // cout<<"**"<<i<<endl;
       }

    }
    cout<<cnt<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pi acos(-1)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define P pair<ll,ll>
vector<P>vp;
vector<ll>v;
set<ll>st;
ll ara[500005];
map<ll,ll>mp;
ll Set(ll N,ll pos)
{
    return N=N | (1LL<<pos);
}
ll reset(ll N,ll pos)
{
    return N= N & ~(1LL<<pos);
}
bool check(ll N,ll pos)
{
    return (bool)(N & (1LL<<pos));
}
vector<ll>e,o;
int main()
{
    fast
    //    freopen("input.txt", "r", stdin);
    //    freopen("output.txt", "w", stdout);
    ll n,i,j,p,R,d,x,y,r;
    cin>>R>>d;
    cin>>n;
    ll cnt=0;
    for(i=0;i<n;i++)
    {
        cin>>x>>y>>r;
       if(x<(R-d)&&y<(R-d))
        continue;
       else if(x>=R||y>=R)
        continue;
       else if((2*r)>(R-d))
        continue;
       else{
        cnt++;
       // cout<<"**"<<i<<endl;
       }

    }
    cout<<cnt<<endl;
}


#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int R,D;
    cin >> R >> D >> N;
    int res = 0;
    for (int n = 0; n < N; ++n)
    {
        int x,y,r;
        cin >> x >> y >> r;
        int dd = x*x+y*y;
        if (dd >= (R-D+r)*(R-D+r) && dd <= (R-r)*(R-r))
            res++;
    }
    cout << res << endl;
}

// #include <iostream>
// #include <cstdlib>
// #include <vector>
// #include <algorithm>

// using namespace std;

// int main()
// {
//     int N; cin >> N;
//     vector<int> c(N);
//     for (int n = 0; n < N; ++n)
//         cin >> c[n];
//     vector<string> v(N);
//     for (int n = 0; n < N; ++n)
//         cin >> v[n];
// }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int R,D;
    cin >> R >> D >> N;
    int res = 0;
    for (int n = 0; n < N; ++n)
    {
        int x,y,r;
        cin >> x >> y >> r;
        int dd = x*x+y*y;
        if (dd >= (D+r)*(D+r) && dd <= (R-r)*(R-r))
            res++;
    }
    cout << res << endl;
}


#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int R,D;
    cin >> R >> D >> N;
    int res = 0;
    for (int n = 0; n < N; ++n)
    {
        int x,y,r;
        cin >> x >> y >> r;
        int dd = x*x+y*y;
        if ((R-D == 0 || dd >= (R-D+r)*(D+r)) && dd <= (R-r)*(R-r))
            res++;
    }
    cout << res << endl;
}


#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int R,D;
    cin >> R >> D >> N;
    int res = 0;
    for (int n = 0; n < N; ++n)
    {
        int x,y,r;
        cin >> x >> y >> r;
        int dd = x*x+y*y;
        if ((D == 0 || dd >= (D+r)*(D+r)) && dd <= (D-R-r)*(D-R-r))
            res++;
    }
    cout << res << endl;
}


#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int R,D;
    cin >> R >> D >> N;
    int res = 0;
    for (int n = 0; n < N; ++n)
    {
        int x,y,r;
        cin >> x >> y >> r;
        int dd = x*x+y*y;
        if (dd >= (R-D+r)*(R-D+r) && dd <= (D-r)*(R-r))
            res++;
    }
    cout << res << endl;
}

// #include <iostream>
// #include <cstdlib>
// #include <vector>
// #include <algorithm>

// using namespace std;

// int main()
// {
//     int N; cin >> N;
//     vector<int> c(N);
//     for (int n = 0; n < N; ++n)
//         cin >> c[n];
//     vector<string> v(N);
//     for (int n = 0; n < N; ++n)
//         cin >> v[n];
// }


#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int N;
    int R,D;
    cin >> D >> R >> N;
    int res = 0;
    for (int n = 0; n < N; ++n)
    {
        int x,y,r;
        cin >> x >> y >> r;
        int dd = x*x+y*y;
        if (dd >= (R-D+r)*(R-D+r) && dd <= (D-r)*(R-r))
            res++;
    }
    cout << res << endl;
}

// #include <iostream>
// #include <cstdlib>
// #include <vector>
// #include <algorithm>

// using namespace std;

// int main()
// {
//     int N; cin >> N;
//     vector<int> c(N);
//     for (int n = 0; n < N; ++n)
//         cin >> c[n];
//     vector<string> v(N);
//     for (int n = 0; n < N; ++n)
//         cin >> v[n];
// }


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define LL long long
#define rl r-l+1
using namespace std;
int main()
{
     double r,d;
     scanf("%lf %lf",&r,&d);
     int n;
     scanf("%d",&n);
     int sum=0;
     for(int i=0;i<n;i++)
     {
          double x,y,z;
          scanf("%lf%lf%lf",&x,&y,&z);
          if(x==0&&y==0)
               continue;
          double ans=sqrt(x*x+y*y);
          if(z==0)
          {
               if(ans==d)
                    continue;
          }
          if(ans>=d+z&&ans+z<=r)
          {
               sum++;
          }
     }
     cout<<sum<<endl;
     return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define LL long long
#define rl r-l+1
using namespace std;
int main()
{
     int d,r;
     scanf("%d%d",&r,&d);
     int n;
     scanf("%d",&n);
     int sum=0;
     for(int i=0;i<n;i++)
     {
          int x,y,z;
          scanf("%d%d%d",&x,&y,&z);
          double ans=sqrt(x*x+y*y);
          if(z==0&&ans==d)
          {
               continue;
          }
          if(ans>=d+z&&ans+z<=r)
          {
               sum++;
          }
     }
     cout<<sum<<endl;
     return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define LL long long
#define rl r-l+1
using namespace std;
int main()
{
     int d,r;
     scanf("%d%d",&d,&r);
     int n;
     scanf("%d",&n);
     int sum=0;
     for(int i=0;i<n;i++)
     {
          int x,y,z;
          scanf("%d%d%d",&x,&y,&z);
          double ans=sqrt(x*x+y*y);
          if(ans>=r+z&&ans+z<=d)
          {
               sum++;
          }
     }
     cout<<sum<<endl;
     return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define LL long long
#define rl r-l+1
using namespace std;
int main()
{
     double r,d;
     scanf("%lf %lf",&r,&d);
     int n;
     scanf("%d",&n);
     int sum=0;
     for(int i=0;i<n;i++)
     {
          double x,y,z;
          scanf("%lf%lf%lf",&x,&y,&z);
          if(x==0&&y==0)
               continue;
          double ans=sqrt(x*x+y*y);
          if(z==0)
          {
               if(ans==d||ans==r)
                    continue;
          }
          if(ans>=d+z&&ans+z<=r)
          {
               sum++;
          }
     }
     cout<<sum<<endl;
     return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<set>
#include<vector>
#include<cmath>
#define lmid l,m,rt<<1
#define rmid m+1,r,rt<<1|1
#define LL long long
#define rl r-l+1
using namespace std;
int main()
{
     double r,d;
     scanf("%lf %lf",&r,&d);
     d=r-d;
     int n;
     scanf("%d",&n);
     int sum=0;
     for(int i=0;i<n;i++)
     {
          double x,y,z;
          scanf("%lf%lf%lf",&x,&y,&z);
          if(x==0 && y==0)
          {
               continue;
          }
          double ans=sqrt(x*x+y*y);
          if(z==0)
          {
               if(ans==d)
                    continue;
          }
          if(ans>=d+z && ans+z<=r)
          {
               sum++;
          }
     }
     cout<<sum<<endl;
     return 0;
}


#include<stdio.h>

int main()
{
    int a[100];
    int n,x,y,lamtron;
    float sothemvao;

    scanf("%d",&n);
    scanf("%d",&x);
    scanf("%d",&y);

    sothemvao=(float)n*y/100-x;
    lamtron=sothemvao;

    if (lamtron<sothemvao)
    lamtron=lamtron+1;

    printf("%d",lamtron);

    return 0;

}


#include<iostream>
using namespace std;
int main(){
	long int a[30003],i,n,j;
	cin>>n;

	for(i=1;i<=n;i++){
		cin>>a[i];

	}
	if(n==1 && a[1]==1) {
	 j=2;
	 cout<<j;
	 return 0;
	}

	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			if(a[i]>a[j]) swap(a[i],a[j]);
		}
	}
	i=2;
	j=1;
	if(a[1]!=1) cout<<j;
	else {

		while(i<=n){
			if(a[i]!=a[i-1]+1) {
				cout<<i;
				break;
			}
			i++;
		}
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int a[30001],i,n,j;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];

	}
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			if(a[i]>a[j]) swap(a[i],a[j]);
		}
	}
	i=2;
	while(i<=n){
		if(a[i]!=a[i-1]+1) {
			cout<<i;
			break;
		}
		i++;
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
	int a[30001],i,n,j;
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];

	}
	for(i=1;i<=n;i++){
		for(j=i+1;j<=n;j++){
			if(a[i]>a[j]) swap(a[i],a[j]);
		}
	}
	i=2;
	if(a[1]!=1) cout<<"1";
	else {

		while(i<=n){
			if(a[i]!=a[i-1]+1) {
				cout<<i;
				break;
			}
			i++;
		}
	}
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;

	vector<int> v(n);

	for (int i = 0; i < n; ++i) cin >> v[i];

	sort(v.begin(), v.end());

	for (int i = 1; i <= n; ++i) {
		if (v[i-1] != i) {
			cout << i;
			return 0;
		}
	}

	cout << 3001;
}


#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;

	vector<int> v(n);

	for (int i = 0; i < n; ++i) cin >> v[i];

	sort(v.begin(), v.end());

	int ant = v[0];
	for (int i = 1; i < n; ++i) {
		if (v[i] != ant + 1) break;

		ant = v[i];
	}

	cout << (ant + 1) << "\n";
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;

	vector<int> v(n);

	for (int i = 0; i < n; ++i) cin >> v[i];

	sort(v.begin(), v.end());

	for (int i = 1; i <= n; ++i) {
		if (v[i-1] != i) {
			cout << i;
			break;
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;

	vector<int> v(n);

	for (int i = 0; i < n; ++i) cin >> v[i];

	sort(v.begin(), v.end());

	for (int i = 1; i <= n; ++i) {
		if (v[i-1] != i) {
			cout << i << "\n";
			break;
		}
	}
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;

	vector<int> v(n);

	for (int i = 0; i < n; ++i) cin >> v[i];

	sort(v.begin(), v.end());

	for (int i = 1; i <= n; ++i) {
		if (v[i-1] != i) {
			cout << i;
			return 0;
		}
	}

	cout << n + 1;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;

	vector<int> v(n);

	for (int i = 0; i < n; ++i) cin >> v[i];

	sort(v.begin(), v.end());

	int ant = v[0];
	for (int i = 1; i < n; ++i) {
		if (v[i] != ant + 1) break;

		ant = v[i];
	}

	cout << (ant + 1) << "\n";
}


#include <iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main()

{ int n ;
  cin >> n ;

  int arr[n] ;

  for(int i=0 ; i<n ; i++)
     {cin >> arr[i] ;}

  sort(arr,arr+n);

  for(int i=0 ; i<n ; i++)
     { if (arr[i]==i+1 && i!=n-1)
          {continue;}
       else if (arr[i]!=i+1 && i!=n-1)
          {cout << i+1 << endl;
           break;
          }
       else
          { if (arr[i+1]-arr[i]>1)
               {cout << arr[i]+1 << endl;
                break;
               }
         }
    }
  return 0 ;
}


#include <iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main()

{ int n ;
  cin >> n ;

  int arr[n] ;

  for(int i=0 ; i<n ; i++)
     {cin >> arr[i] ;}

  sort(arr,arr+n);

  for(int i=0 ; i<n ; i++)
     {if (arr[i]!=i+1)
         {cout << i+1 << endl;
          return 0;
         }
      if (arr[i]==i+1 && i==n-1)
         {cout << i+2 << endl;
          return 0 ;
         }
     }
  return 0 ;
}


#include <iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main()

{ int n ;
  cin >> n ;

  int arr[n] ;

  for(int i=0 ; i<n ; i++)
     {cin >> arr[i] ;}

  sort(arr,arr+n);

  for(int i=0 ; i<n ; i++)
     { if (arr[i]==i+1)
          {continue;}
       else
          {cout << i+1 << endl;
           return 0 ;
          }
     }
  return 0 ;
}


#include <iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main()

{ int n ;
  cin >> n ;

  int arr[n] ;

  for(int i=0 ; i<n ; i++)
     {cin >> arr[i] ;}

  sort(arr,arr+n);

  if (arr[0]==1 && n==1)
     {cout << 2 << endl;
      return 0 ;
     }
  for(int i=0 ; i<n ; i++)
     { if (arr[i]==i+1 && i!=n-1)
          {continue;}
       else if (arr[i]!=i+1 && i!=n-1)
          {cout << i+1 << endl;
           break;
          }
       else
          { if (arr[i+1]-arr[i]>1)
               {cout << arr[i]+1 << endl;
                break;
               }
         }
    }
  return 0 ;
}


#include <iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main()

{ int n ;
  cin >> n ;

  int arr[n] ;

  for(int i=0 ; i<n ; i++)
     {cin >> arr[i] ;}

  sort(arr,arr+n);

  for(int i=0 ; i<n ; i++)
     { if (arr[i]==i+1 && i!=n-1)
          {continue;}
       else if (arr[i]!=i+1 && i!=n-1)
          {cout << i+1 << endl;
           return 0 ;
          }
       else
          { if (arr[i+1]-arr[i]>1)
               {cout << arr[i]+1 << endl;
                break;
               }
         }
    }
  return 0 ;
}


#include <iostream>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

int main()

{ int n ;
  cin >> n ;

  int arr[n] ;

  for(int i=0 ; i<n ; i++)
     { cin >> arr[i] ; }

  sort(arr,arr+n);

  for(int i=0 ; i<n ; i++)
    { if (arr[i+1]-arr[i]>1)
         {cout << arr[i]+1 << endl;
          break;
         }
    }

  return 0 ;
}


#include <cstdio>
#include <cstring>

int main()
{
	bool arr[3005];
	int n, bil;
	scanf("%d", &n);

	memset(arr, false, sizeof(arr));

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &bil);
		arr[bil - 1] = true;
	}

	for (int i = 0; i < n; i++)
	{
		if (arr[i] == false)
		{
			printf("%d\n", i + 1);
			break;
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

using namespace std;
int main()
{
	int n, arr[3005];
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d", &arr[i]);

	sort(arr, arr + n);

	if (n == 1)
	{
		printf("%d\n", arr[0] + 1);
	}
	else
	{
		int answ = 0;
		for (int i = 0; i < n - 1; i++)
		{
			int temp = arr[i] + 1;
			if (temp != arr[i + 1])
			{
				answ = temp;
				break;
			}
		}
		printf("%d\n", answ);
	}
	return 0;
}


#include <cstdio>
#include <cstring>

int main()
{
	bool arr[3005];
	int n, bil;
	scanf("%d", &n);

	memset(arr, false, sizeof(arr));

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &bil);
		arr[bil - 1] = true;
	}

	for (int i = 0; i < n; i++)
	{
		if (arr[i] == false)
		{
			printf("%d", i + 1);
			break;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>

int main()
{
	bool arr[3005];
	int n, bil;
	scanf("%d", &n);

	memset(arr, false, sizeof(arr));

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &bil);
		arr[bil - 1] = true;
	}

	for (int i = 0; i < 3001; i++)
	{
		if (arr[i] == false)
		{
			printf("%d", i + 1);
			break;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>

int main()
{
	bool arr[3005];
	int n, bil;
	scanf("%d", &n);

	memset(arr, false, sizeof(arr));

	for (int i = 0; i < n; i++)
	{
		scanf("%d", &bil);
		arr[bil - 1] = true;
	}

	int i = 0;
	while (arr[i] == true)
	{
		i++;
	}

	printf("%d\n", i + 1);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
  int n,v[3000];
void Qsort(int d, int cuoi)
{
    int i, j, m, x;
    i = d;
    j = cuoi;
    x = v[(d + cuoi) / 2] ;
    while (i < j)
    {
        while (v[i] < x) i++;
        while (v[j] > x) j--;
        if (i <= j)
        {
            swap(v[i], v[j]);
            i++;
            j--;
        }
    }
    if (j > d) Qsort(d, j);
    if (i < cuoi) Qsort(i, cuoi);
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) {
    	cin >> v[i];
    }
    Qsort(1,n);
    if(v[1] != 1) {
    	cout << "1" << endl;
    	return 0;
    }
    for(int i = 1; i < n ;i++) {
    	if(v[i-1]+1 != v[i]) {
    		cout << v[i-1]+1 << endl;
    		return 0;
    	}
    }
    cout << v[n-1]+1 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
  int n,v[3000];
void Qsort(int d, int cuoi)
{
    int i, j, m, x;
    i = d;
    j = cuoi;
    x = v[(d + cuoi) / 2] ;
    while (i < j)
    {
        while (v[i] < x) i++;
        while (v[j] > x) j--;
        if (i <= j)
        {
            swap(v[i], v[j]);
            i++;
            j--;
        }
    }
    if (j > d) Qsort(d, j);
    if (i < cuoi) Qsort(i, cuoi);
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) {
    	cin >> v[i];
    }
    Qsort(1,n);
    if(v[1] != 1) {
    	cout << "1" << endl;
    	return 0;
    }
    for(int i = 1; i <= n ;i++) {
    	if(v[i-1]+1 != v[i]) {
    		cout << v[i-1]+1 << endl;
    		return 0;
    	}
    }
    cout << v[n-1]+1 << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
int main()
{
     cin >> n;
    int t;
    for(int i = 0; i < n; ++i) {
    	cin >> t;
    	v.push_back(t);
    }
    sort(v.begin(), v.end());

    if(v[0] != 1) {
    	cout << "1" << endl;
    	return 0;
    }

    for(int i = 1; i < v.size(); ++i) {
    	if(v[i-1]+1 != v[i]) {
    		cout << v[i-1]+1 << endl;
    		return 0;
    	}
    }

    cout << v[v.size()-1]+1 << endl;

    return 0;
}


#include<iostream>
using namespace std;
int n,k,a[101],d;
int main()
{
    int i;
    cin>>n>>k;
    for(i=1;i<=n;i++)
        cin>>a[i];
    d=0;
    for(i=1;i<=n;i++)
        if(a[i]>=a[k] && a[i]>0)
           d+=1;
    cout<<d;
}


#include<bits/stdc++.h>
using namespace std;
int n,v[3000];
void Qsort(int d, int cuoi)
{
    int i, j, m, x;
    i = d;
    j = cuoi;
    x = v[(d + cuoi) / 2] ;
    while (i < j)
    {
        while (v[i] < x) i++;
        while (v[j] > x) j--;
        if (i <= j)
        {
            swap(v[i], v[j]);
            i++;
            j--;
        }
    }
    if (j > d) Qsort(d, j);
    if (i < cuoi) Qsort(i, cuoi);
}

int main()
{
    cin >> n;
    for(int i = 1; i <= n; i++) {
    	cin >> v[i];
    }
    Qsort(1,n);
    if(v[1] != 1) {
    	cout << "1" << endl;
    	return 0;
    }
    for(int i = 1; i <= n ;i++) {
    	if(v[i-1]+1!= v[i]) {
    		cout << v[i-1]+1 << endl;
    		return 0;
    	}
    }
    cout << v[n-1]+1 << endl;
    return 0;
}


#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std ;

#define pb push_back
#define del(a,n) memset(a,n,sizeof(a))
#define loop(i,j) for(int i =0 ; i<j ; i++ )

int main()
{
    vector <int> x;
    int n , temp , i , f=0;
    scanf ("%d",&n);
    for ( i=0 ; i<n ; i++ )
    {
        scanf ("%d",&temp);
        x.pb(temp);
    }
    sort ( x.begin() , x.end() );
    for ( i=1 ; i<n ; i++ )
    {
        if ( x[i]> x[i-1] && x[i] - x[i-1]>1 )
        {
            f=1;
            printf ("%d\n",x[i-1]+1);
            break;
        }
    }
    if ( f==0 )
        printf ("%d\n",x[n-1]+1);
    return 0;
}