Read problems statements in mandarin chinese, russian and vietnamese as well. 

There are n courses in a university being offered. These courses are numbered from 1 to n in the increasing order of their difficulty. For each course, you can have some courses as prerequisites. The prerequisite courses for a course should be of lower difficulty than it. You are given an array a of size n, where a_{i} denotes that there should be at least a_{i} prerequisite courses for i-th course. 

The university wants to estimate the efficiency of the allocation of prerequisites of courses by maximizing the number of courses that are not prerequisites for any other course. Find out what's the maximum such number of courses possible. It is guaranteed that a_{i} < i, thus making sure that it is possible to allocate the prerequisites for each of the course.

------ Input ------ 

The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains an integer n.
The second line of each test case contains n space separated integers denoting array a.

------ Output ------ 

For each test case, output a single line containing an integer corresponding to the maximum number of possible courses which are not prerequisite for any other course.

------ Constraints ------ 

$1 ≤ T ≤ 10$
$1 ≤ n ≤ 10^{5}$
$0 ≤ a_{i} < i$

------ Subtasks ------ 

$Subtask #1 (40 points) : 1 ≤ n ≤ 100$
$Subtask #2 (60 points) : original constraints$

----- Sample Input 1 ------ 
2

3

0 1 1

3

0 1 2
----- Sample Output 1 ------ 
2

1
----- explanation 1 ------ 
Example case 1. Both the courses 2 and 3 can have course 1 as a prerequisite. In this case, course 2 and course 3 are not prerequisites for any course. So, we have two such courses.

Other possibility could be following. Course 2 has course 1 as a prerequisite, and course 3 has course 2 as a prerequisite. Thus only course 3 is the only course that is not the prerequisite of any other course.

Thus answer is 2.

Source: codechef | Difficulty: MEDIUM
Tags: Greedy algorithms

Constructive algorithms

Data structures

Ad-hoc


Solutions:
for tc in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	print(n - max(arr))


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split(' ')))
	print(n - max(a))


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	print(n - max(A))


for _ in range(int(input())):
	n = int(input())
	l = sorted(list(map(int, input().split())))
	print(n - l[-1])


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(n - max(l))


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(n - max(a))


for i in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	print(n - a[-1])


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = max(a)
	print(n - b)


for i in range(int(input())):
	n = int(input())
	course = [int(i) for i in input().split()]
	course.sort()
	print(n - course[-1])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	m = max(a)
	print(n - m)


t = int(input())
for t in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	maxm = max(arr)
	print(n - maxm)


t = int(input())
while t != 0:
	n = int(input())
	arr = list(map(int, input().strip().split()))
	print(n - max(arr))
	t -= 1


for i in range(int(input())):
	n = int(input())
	li = list(map(int, input().split()))
	e = max(li)
	print(n - e)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	print(len(l) - max(l))


for _ in range(int(input())):
	N = int(input())
	lst = list(map(int, input().split(' ')))
	a = max(lst)
	print(N - a)


t = int(input())
while t:
	t -= 1
	n = int(input())
	ls = list(map(int, input().split()))
	nmin = min(ls)
	nmax = max(ls)
	if n == 1:
		print(1)
	else:
		print(n - nmax - nmin)


t = int(input())
while t:
	num_courses = int(input())
	l = list(map(int, input().split()))
	print(num_courses - max(l))
	t = t - 1


t = int(input())
while t:
	n = int(input())
	l = list(map(int, input().split()))
	print(n - max(l))
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(1)
		continue
	m = max(a)
	print(n - m)


try:
	for _ in range(int(input())):
		n = int(input())
		a = list(map(int, input().split()))
		s = max(a)
		print(n - s)
except:
	pass


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	ma = 0
	ma = max(a)
	ans = n - ma
	print(ans)


t = int(input(''))
for _ in range(t):
	n = int(input(''))
	a = list(map(int, input('').split()))
	a.sort()
	print(n - a[-1])


def solve():
	N = int(input())
	crs = list(map(int, input().split()))
	base = 0
	for i in range(0, len(crs)):
		if crs[i] > base:
			base = crs[i]
	return N - base
T = int(input())
while T > 0:
	ans = solve()
	print(ans)
	T = T - 1


for _ in range(int(input())):
	array_len = int(input())
	array = list(map(int, input().split()))
	print(array_len - max(array))


for _ in range(int(input())):
	array_len = int(input())
	array = list(map(int, input().split()))
	array.sort()
	print(array_len - array[-1])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	a.pop(0)
	s = max(a)
	print(n - s)


for i in range(int(input())):
	m = int(input())
	courses = list(map(int, input().split()))
	maximum = max(courses)
	print(m - maximum)


import sys
from math import gcd, sqrt, log, ceil, floor
tc = int(input().strip())
for t in range(tc):
	n = int(input().strip())
	arr = list(map(int, input().split()))
	arr.sort()
	print(n - arr[n - 1])


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	maxx = max(a)
	res = n - maxx
	print(res)


import sys
R = lambda : map(int, next(sys.stdin).split())
T = int(input())
for i in range(T):
	N = int(input())
	a = list(R())
	maxPre = max(a)
	print(N - maxPre)


for _ in range(int(input())):
	N = int(input())
	A = list(map(int, input().split()))
	z = 0
	for i in range(N):
		z = max(z, A[i])
	print(N - z)


from collections import Counter
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	a = max(l)
	print(n - a)


for i in range(int(input())):
	a = int(input())
	l = list(map(int, input().split()))
	s = max(l)
	print(a - s)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	out = 0
	m = -1
	for i in range(1, n):
		c = arr[i]
		if c >= m:
			m = c
			out = i - c
		else:
			out += 1
	print(out + 1)


for i in range(int(input())):
	n = int(input())
	k = list(map(int, input().split()))
	mx = max(k)
	print(n - mx)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	r = 0
	for i in range(n):
		if a[i] > r:
			r = a[i]
	print(n - r)


n = int(input())
for i in range(n):
	N = int(input())
	li = list(map(int, input().split(' ')))
	li.sort()
	print(N - li[-1])


t = input()
for c in range(0, int(t)):
	print(int(input()) - max(list(map(int, input().split()))))


for _ in range(int(input())):
	print(int(input()) - max([int(x) for x in input().split()]))


for _ in range(int(input())):
	print(int(input()) - max(list(map(int, input().split()))))


inp = input()
num_cases = int(inp)
for i in range(num_cases):
	inp = input()
	n = int(inp)
	inp = input()
	inp = inp.split(' ')
	listInt = list(map(int, inp))
	maxInt = max(listInt)
	max_non_pre = n - maxInt
	print(max_non_pre)


get_int = lambda : int(input())
get_mint = lambda : list(map(int, input().split()))
for _ in range(get_int()):
	N = get_int()
	print(N - max(get_mint()))


t = int(input())
while t:
	n = int(input())
	ls = list(map(int, input().split()))
	count = max(ls)
	print(n - count)
	t -= 1


for i in range(int(input())):
	n = int(input())
	ll = list(map(int, input().split()))
	m = max(ll)
	l = 0
	for i in range(n - 1, -1, -1):
		if m == i:
			l = i
	print(n - l)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a.sort()
	count = 0
	x = 0
	count = n - a[n - 1]
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	print(n - max(a))


from sys import stdin
stdint = lambda : int(stdin.readline())
seq = lambda : list(map(int, stdin.readline().strip().split()))
for i in range(stdint()):
	a = stdint()
	arr = seq()
	m = max(arr)
	print(a - m)


for i in range(int(input())):
	a = int(input())
	arr = list(map(int, input().split()))
	m = max(arr)
	print(a - m)


t = int(input())
while t:
	t -= 1
	n = int(input())
	li = list(map(int, input().split()))
	ans = 0
	for i in li:
		ans = max(ans, i)
	print(n - ans)


for _ in range(int(input())):
	course_count = int(input())
	requisites = list(map(int, input().split()))
	maximum_prerequisite = None
	for requisite in requisites:
		if maximum_prerequisite == None or requisite > maximum_prerequisite:
			maximum_prerequisite = requisite
	print(course_count - maximum_prerequisite)