CHEFRECP - Code works perfectly fine but still system says its wrng

This is the program written in python for CHEFRECP
my python IDE gives proper answer on input.
I need to understand why is it wrong

https://www.codechef.com/viewsolution/33307177

cook your dish here

a=int(input())
l5=[]
for i in range (0,a):
b=int(input())
s1=input()
l1=[]
l1=s1.split(’ ')
l2=[]
pp=0

for k in range (0,len(l1)):
        if(l1[k] not in l2):
            l2.append(l1[k])
            pp=pp+1
        elif(l1[k]==l2[-1]):
            flg="YES"
        else:
            flg="NO"
            break
if(flg=="YES"):
    
    l3=[]
    count=0
    for a in l2:
        count=0
        for j in l1:
            if(a==j):
                count=count+1
        l3.append(count)
    
    j=1
    for ww in l3:
        if (ww in l3[j:]):
            flg="NO"
            break
        j=j+1
if(flg=="YES"):
    l5.append("YES")
    
else:
    l5.append("NO")

print(*l5,sep=’\n’)