You are given an array of integers [A1,A2,…,AN]$[A_1, A_2, \ldots, A_N]$. Let's call adding an element to this array at any position (including the beginning and the end) or removing an arbitrary element from it a modification. It is not allowed to remove an element from the array if it is empty.
Find the minimum number of modifications which must be performed so that the resulting array can be partitioned into permutations. Formally, it must be possible to partition elements of the resulting array into zero or more groups (multisets; not necessarily identical) in such a way that each element belongs to exactly one group and for each group, if it contains L$L$ elements, then it must contain only integers 1$1$ through L$L$, each of them exactly once.

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of each test case contains a single integer N$N$.
- The second line contains N$N$ space-separated integers A1,A2,…,AN$A_1, A_2, \ldots, A_N$.

-----Output-----
For each test case, print a single line containing one integer ― the minimum required number of modifications.

-----Constraints-----
- 1≤T≤1,000$1 \le T \le 1,000$
- 1≤N≤106$1 \le N \le 10^6$
- 1≤Ai≤109$1 \le A_i \le 10^9$ for each valid i$i$
- the sum of N$N$ over all test cases does not exceed 106$10^6$

-----Subtasks-----
Subtask #1 (50 points):
- 1≤N≤1,000$1 \le N \le 1,000$
- the sum of N$N$ over all test cases does not exceed 10,000$10,000$
Subtask #2 (50 points): original constraints

-----Example Input-----
2
5
1 4 1 2 2
4
2 3 2 3

-----Example Output-----
1
2

Starter code:

Solutions:
# cook your dish here
for _ in range(int(input())):
    n=int(input());li=list(map(int,input().split()));dli=dict();modi=0
    for i in li:
     if i not in dli:dli[i]=1
     else:dli[i]+=1
    op=sorted(list(dli))
    if(len(dli)!=0):
     while 1:
      tmp=[]
      for i in op:
       if dli[i]==0:continue
       tmp.append(i);dli[i]-=1
      l=len(tmp);mn=l
      for i in range(l):mn=min(mn,tmp[i]-1-i+l-1-i)
      modi+=mn
      if(l==0):break
    print(modi)

# cook your dish here
for _ in range(int(input())):
    n=int(input());li=list(map(int,input().split()));dli=dict();modi=0
    for i in li:
     if i not in dli:dli[i]=1
     else:dli[i]+=1
    op=sorted(list(dli))
    if(len(dli)!=0):
     while 1:
      tmp=[]
      for i in op:
       if dli[i]==0:continue
       tmp.append(i);dli[i]-=1
      l=len(tmp);mn=l
      for i in range(l):mn=min(mn,tmp[i]-1-i+l-1-i)
      modi+=mn
      if(l==0):break
    print(modi)

for _ in range(int(input())):
    n=int(input());li=list(map(int,input().split()));dli=dict();modi=0
    for i in li:
     if i not in dli:dli[i]=1
     else:dli[i]+=1
    op=sorted(list(dli))
    if(len(dli)!=0):
     while 1:
      tmp=[]
      for i in op:
       if dli[i]==0:continue
       tmp.append(i);dli[i]-=1
      l=len(tmp);mn=l
      for i in range(l):mn=min(mn,tmp[i]-1-i+l-1-i)
      modi+=mn
      if(l==0):break
    print(modi)


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    cost = 0

    dp = [[] for val in range(2*n+1)]
    cnt = [0]*(n*2+1)
    dp[0].extend( [ 0 for val in range(n*2+1) ])

    for val in a:
     if val<=2*n: cnt[val]+=1
     else: cost+=1
 
    for i in range(1, n*2+1):
     rn = n*2//i
     dp[i].extend([ 0 for val in range(rn+1) ])
     for j in range(0, rn+1):
      dp[i][j] = dp[i-1][j] + abs(cnt[i]-j) 
     for j in range(rn-1, -1, -1):
      dp[i][j] = min(dp[i][j], dp[i][j+1])
 
    print( cost+min( dp[2*n][0], dp[2*n][1]) )




for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    cost = 0

    dp = [[] for val in range(2*n+1)]
    cnt = [0]*(n*2+1)
    dp[0].extend([ 0 for val in range(n*2+1) ])

    for val in a:
     if val<=2*n: cnt[val]+=1
     else: cost+=1
 
    for i in range(1, n*2+1):
     rn = n*2//i
     for j in range(0, rn+1):
      dp[i].extend( [ dp[i-1][j] + abs(cnt[i]-j) ] )
     for j in range(rn-1, -1, -1):
      dp[i][j] = min(dp[i][j], dp[i][j+1])
 
    print( cost+min( dp[2*n][0], dp[2*n][1]) )



for _ in range(int(input())):
    n=int(input())
    li=list(map(int,input().split()))
    li.sort()
    dli=dict()
    modi=0
    #2*n optimiztion 
    for i in li:
     if i not in dli:
      dli[i]=li.count(i)
    if(len(dli)!=0):
     while 1:
      tmp=[]
      for i in dli:
       if dli[i]==0:
        continue
       tmp.append(i)
       dli[i]-=1
      l=len(tmp)
      mn=l
      for i in range(l):
       mn=min(mn,tmp[i]-1-i+l-1-i)
      modi+=mn
      if(l==0):
       break
    print(modi)