In Chefland, types of ingredients are represented by integers and recipes are represented by sequences of ingredients that are used when cooking. One day, Chef found a recipe represented by a sequence $A_1, A_2, \ldots, A_N$ at his front door and he is wondering if this recipe was prepared by him.
Chef is a very picky person. He uses one ingredient jar for each type of ingredient and when he stops using a jar, he does not want to use it again later while preparing the same recipe, so ingredients of each type (which is used in his recipe) always appear as a contiguous subsequence. Chef is innovative, too, so he makes sure that in each of his recipes, the quantity of each ingredient (i.e. the number of occurrences of this type of ingredient) is unique ― distinct from the quantities of all other ingredients.
Determine whether Chef could have prepared the given recipe.

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

-----Output-----
For each test case, print a single line containing the string "YES" if the recipe could have been prepared by Chef or "NO" otherwise (without quotes).

-----Constraints-----
- $1 \le T \le 100$
- $1 \le N \le 10^3$
- $1 \le A_i \le 10^3$ for each valid $i$

-----Example Input-----
3
6
1 1 4 2 2 2
8
1 1 4 3 4 7 7 7
8
1 7 7 3 3 4 4 4

-----Example Output-----
YES
NO
NO

-----Explanation-----
Example case 1: For each ingredient type, its ingredient jar is used only once and the quantities of all ingredients are pairwise distinct. Hence, this recipe could have been prepared by Chef. 
Example case 2: The jar of ingredient $4$ is used twice in the recipe, so it was not prepared by Chef.

Difficulty: interview

Starter code:

Solutions:
# cook your dish here
 
for __ in range(int(input())):
 n=int(input())
 arr=list(map(int,input().split()))
 d={}
 s=set()
 flag=0
 for i in range(n):
  if arr[i] in list(d.keys()):
   d[arr[i]]+=1
  else:
   d[arr[i]]=1
  curr_ele=arr[i]
  if (curr_ele in s) and arr[i-1]!=arr[i]:
   flag=1
   break
  else:
   s.add(arr[i])
 c=list(d.values())
 if len(c)!=len(set(c)):
  flag=1
 if flag==1:
  print("NO")
 else:
  print("YES")
 
   
  
 


# cook your dish here
for _ in range(int(input())):
 n=int(input())
 a=list(map(int,input().strip().split()))
 m={}
 for i in a:
  if(i not in m):
   m[i]=1
  else: m[i]+=1
 s= set()
 for i in m:
  s.add(m[i])
 
 if len(s)!=len(m):
  print("NO")
  continue
 tt=1
 for i in range(n):
  flag=1
  for j in range(i+1,n):
   if(a[i]!=a[j]):
    flag=0;
   if flag==0 and a[i]==a[j]:
    print("NO")
    tt=0
    break;
  if tt==0:
   break
 if tt==1:
  print("YES")
 
    
   


# cook your dish here
for _ in range(int(input())):
 n = int(input())
 arr = list(map(int,input().split()))

 d = {}

 i = 0

 flag = True
 while i<n:
  if arr[i] not in d:
   
   count = 1

   while i<n-1 and arr[i]==arr[i+1]:
    count+=1
    i+=1
   
   d[arr[i]] = count

  else:
   flag = False
   break

  i+=1
 
 # print(d,flag)

 if flag==False:
  print("NO")
 else:
  t = list(d.values())

  if len(t)==len(set(t)):
   print("YES")
  else:
   print("NO")



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

 d = {}

 i = 0

 flag = True
 while i<n:
  if arr[i] not in d:
   
   count = 1

   while i<n-1 and arr[i]==arr[i+1]:
    count+=1
    i+=1
   
   d[arr[i]] = count

  else:
   flag = False
   break

  i+=1
 
 # print(d,flag)

 if flag==False:
  print("NO")
 else:
  t = list(d.values())

  if len(t)==len(set(t)):
   print("YES")
  else:
   print("NO")

  

  
  


 



 


for t in range(int(input())):
 n = int(input())
 arr=list(map(int,input().split()))
 con=[]
 count=1
 c=[]
 i=0
 while i<n:
  while (i<n-1) and (arr[i]==arr[i+1]):
   i+=1
   count+=1
  if arr[i] in con or count in c:
   break
  con.append(arr[i])
  c.append(count)
  i+=1
  count=1
 
 if i==n :
  print("YES")
 else:
  print("NO")


# cook your dish here
from collections import Counter
def solve(arr):
 n = len(arr)
 d = Counter(arr)
 if len(d.values()) != len(set(d.values())):
  return False
 i = 0
 j = 0 
 while i<n and j<n:
  j = i + 1 
  while j<n and arr[j] == arr[i]:
   j = j + 1 
  if j - i != d[arr[i]]:
   return False
  i = j 
 return True
 
for _ in range(int(input())):
 n = int(input())
 arr = [int(num) for num in input().split(' ')]
 ans = solve(arr)
 if ans == True:
  print('YES')
 else:
  print('NO')

# cook your dish here
t=int(input())
while t:
 n=int(input())
 arr=list(map(int,input().split()))
 con=[]
 count=1
 c=[]
 i=0
 while i<n:
  while (i<n-1) and (arr[i]==arr[i+1]):
   i+=1
   count+=1
  if arr[i] in con or count in c:
   break
  con.append(arr[i])
  c.append(count)
  i+=1
  count=1
 
 if i==n :
  print("YES")
 else:
  print("NO")
 #print(*con)
 #print(*c)
 t-=1

def check(l):
 c=[]
 s=list(set(l))
 for i in s:
  c.append(l.count(i))
 if len(c)==len(set(c)):
  return 1
 return 0
 
for _ in range(int(input())):
 n=int(input())
 l=list(map(int,input().split()))
 s=0
 if check(l)==0:
  print("NO")
  continue
 for i in range(1,n):
  if l[i]!=l[i-1]:
   s+=1
 if s==len(set(l))-1:
  print("YES")
 else:
  print("NO")

# your code goes here
def fun(l):
 t=[]
 s=list(set(l))
 for i in s:
  t.append(l.count(i))
 #print(t)
 #print(len(t),len(set(t)))
 if len(t)==len(set(t)):
  #print(1)
  return 1
 #print(0)
 return 0
 
for _ in range(int(input())):
 n=int(input())
 l=[int(i) for i in input().split()]
 s=0
 if fun(l)==0:
  print("NO")
 else:
  for i in range(n-1):
   if l[i]!=l[i+1]:
    s+=1
  if s==len(set(l))-1:
   print("YES")
  else:
   print("NO")

a = int(input())
for i in range(0, a):
 b = int(input())
 c = list(map(int, input().split()))
 n = [0 for k in range(0, 1000)]
 f1 = [0 for k in range(0, 1000)]
 f2 = [0 for k in range(0, 1000)]
 for l in range(0, b):
  f1[c[l] - 1] += 1
 bo = True
 for l in range(0, 1000):
  if(f1[l] > 0):
   f2[f1[l]] += 1
   if(f2[f1[l]] > 1):
    bo = False
    break
 if(bo):
  j = 1
  n[c[0] - 1] = 1
  while(j < b):
   if(c[j] == c[j-1]):
    j += 1
   elif(c[j] != c[j - 1] and n[c[j] - 1] != 1):
    n[c[j] - 1] = 1
    j+= 1
   else:
    print("NO")
    break
  if(j == b):
   print("YES")
 else:
  print("NO")


for _ in range(int(input())):
 n = int(input())
 inp = list(map(int, input().split()))
 ing = [inp[0]]
 count = []
 last = inp[0]
 ans = "YES"
 cnt = 1
 for i in range(1,n):
  if last == inp[i]:
   cnt += 1
  else:
   if cnt not in count and (inp[i] not in ing):
    count.append(cnt)
    cnt = 1
    last = inp[i]
    ing.append(last)
   else:
    ans = "NO"
    break

 if cnt in count:
  ans = "NO"
 print(ans)


for _ in range(int(input())):
 n = int(input())
 val = [int(x) for x in input().split()]
 ing = [val[0]]
 count = []
 c = 1
 prev = val[0]
 ans = "YES"
 for i in val[1:]:
  if prev == i:
   c += 1
  else:
   if c not in count and (i not in ing):
    count.append(c)
    c = 1
    prev = i
    ing.append(prev)
   else:
    ans = "NO"
    break

 if c in count:
  ans = "NO"
 print(ans)

for _ in range(int(input())):
 n = int(input())
 val = [int(x) for x in input().split()]
 ing = [val[0]]
 count = []
 c = 1
 prev = val[0]
 ans = "YES"
 for i in val[1:]:
  if prev == i:
   c += 1
  else:
   if c not in count and (i not in ing):
    count.append(c)
    c = 1
    prev = i
    ing.append(prev)
   else:
    ans = "NO"
    break

 if c in count:
  ans = "NO"
 print(ans)

from collections import Counter
for _ in range(int(input())):
 n = int(input())
 arr = [int(x) for x in input().split()]
 lis = [arr[0]]
 lis += [arr[i] for i in range(1,n) if(arr[i-1]!=arr[i])]
 if(len(set(lis)) != len(lis)):
  print("NO")
 else:
  c = dict(Counter(arr))
  if(len(set(c.values())) == len(c)):
   print("YES")
  else:
   print("NO")


for _ in range(int(input())):
 n = int(input())
 l = list(map(int,input().split()))
 ing = [l[0]]
 count = []
 c = 1
 d = l[0]
 ans = "YES"
 for i in l[1:]:
  if d == i:
   c += 1
  else:
   if c not in count and (i not in ing):
    count.append(c)
    c = 1
    d = i
    ing.append(d)
   else:
    ans = "NO"
    break
  #print(ing,count)
 if c in count:
  ans = "NO"
 print(ans)

def sol(n, l):
 no, oc, m, k = {}, {}, l[0], 1
 for i in range(1, n):
  if (l[i] != m):
   if m in no or k in oc: return "NO"
   else: no[m], oc[k] = True, True
   m, k = l[i], 1
  else: k += 1
 if m in no or k in oc: return "NO"
 return "YES"

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

# cook your dish here
for _ in range(int(input())):
 n=int(input())
 ingredients=list(map(int,input().split(" ")))
 ls=[ingredients[0]]
 count=[]
 index=[]
 c=1
 flag=1
 for i in range(1,n):
  if ingredients[i]==ls[-1]:
   c=c+1
  else:
   if ingredients[i] in ls:
    flag=0
    break
   index.append(i)
   ls.append(ingredients[i])
   if c in count:
    flag=0
    break
   count.append(c)
   c=1
 if c in count or flag==0:
  print("NO")
  continue
 print("YES")
 
 # for i in range(n):


# cook your dish here
t = int(input())

for _ in range(t):
 n = int(input())
 a = list(map(int , input().split(" ")))
 
 d={}
 flag=0
 for i in range(n):
  if a[i] not in d:
   d[a[i]]=[i,1]
  elif a[i] in d and d[a[i]][0]+1==i:
   temp = d[a[i]][1]
   d[a[i]] = [i , temp+1]
  else:
   print("NO")
   flag=1
   break
 
 # print(d)
 vals = list(d.values())
 dist=[]
 for i in vals:
  #print(i)
  dist.append(i[1])

 if flag==0:
  if len(dist)== len(set(dist)):
   print("YES")
  else:
   print("NO")

# MOD = 1000000007
for _ in range(int(input())):
 # n,b,m = map(int,input().split())
 n = int(input())
 ings = list(map(int,input().split()))
 di_ings = {}
 last = 0
 possible = True
 for ing in ings :
  if ing in di_ings :
   if last == ing :
    di_ings[ing] += 1
   else :
    possible = False
    break
  else :
   di_ings[ing] = 1
   last = ing
 # print(di_ings)
 if possible and len(set(di_ings)) == len(set(di_ings.values())) :
  print('YES')
 else :
  print('NO')


for _ in range(int(input())):
 n = int(input())
 arr = list(map(int, input().split()))
 
 count = []
 jars = [arr[0]]
 prev = arr[0]
 curr_count = 1
 flag = True
 for a in arr[1:]:
  if a != prev:
   if a in jars or curr_count in count:
    flag = False
    break
   jars.append(a)
   count.append(curr_count)
   curr_count = 1
  
  else:
   curr_count += 1
  prev = a
 
 if curr_count in count:
  flag = False
 
 print("YES" if flag else "NO")

import sys
cases = int(sys.stdin.readline().rstrip())
for case in range(cases):
 N = int(sys.stdin.readline().rstrip())
 p = list(map(int,sys.stdin.readline().rstrip().split(" ")))
 freq = [0]*(1001)
 freq[p[0]]+=1
 error = False
 for i in range(1,len(p)):
  if( freq[p[i]] > 0 and p [i-1] != p[i]):
   error = True
   break
  else :
   freq[p[i]] +=1
 #  print(freq)
 if(error):
  print("NO")
 else :
  ms = []
  error = False
  for q in freq:
   
    
   if q in ms and q !=0:
    error = True 
    break
   ms.append(q) 
  if(error):
   print("NO")
  else :
   print("YES")
  


t = int(input())

for _ in range(t):
 n = int(input())
 
 arr = [int(x) for x in input().split()]
 freq = {}
 freq[arr[0]] = 1
 
 flag = 0
 
 for i in range(1, n):
  if(arr[i-1] != arr[i] and arr[i] in freq):
   flag = 1
   break
  if arr[i] in freq:
   freq[arr[i]] += 1
  else:
   freq[arr[i]] = 1
 
 sam = []
 
 for i in freq:
  sam.append(freq[i])
 
 sam2 = list(set(sam))
 sam.sort()
 sam2.sort()
 
 # print("flag", flag, sam, sam2)
 
 if(sam != sam2):
  flag = 1
 
 if(flag == 1):
  print("NO")
 else:
  print("YES")

# cook your dish here
for _ in range(int(input())):
 n=int(input())
 l=list(map(int,input().split()))
 u=[]
 t=[]
 ut=[]
 qw=[]
 c=0
 for i in l:
  if i not in u:
   u.append(i)
   t.append(l.count(i))
 for i in t:
  if i not in ut:
   ut.append(i)
 for i in l:
  if i not in qw or qw[-1]==i:
   qw.append(i)
  else:
   print("NO")
   c=1
   break
 if c==0 and len(ut)==len(t):
  print("YES")
 elif c==0:
  print("NO")
  
 
  


for _ in range(int(input())):
 N = int(input())
 L = list(map(int, input().split()))
 new = {}
 for i in L:
  if i in new.keys():
   if i != list(new.keys())[-1]:
    print('NO')
    break
   new[i] += 1
  else:
   new[i] = 0
 else:
  print('YES' if len(new.values()) == len(set(new.values())) else 'NO')